Be more consistent with the packet format definition.

Free perf counters in ~PX4IO_serial
This commit is contained in:
px4dev
2013-07-05 18:36:00 -07:00
parent 1f7f7862ce
commit 46a4a44321
2 changed files with 17 additions and 11 deletions
+12 -6
View File
@@ -69,7 +69,7 @@
#include "interface.h" #include "interface.h"
const unsigned max_rw_regs = 32; // by agreement w/IO #define PKT_MAX_REGS 32 // by agreement w/IO
#pragma pack(push, 1) #pragma pack(push, 1)
struct IOPacket { struct IOPacket {
@@ -77,7 +77,7 @@ struct IOPacket {
uint8_t crc; uint8_t crc;
uint8_t page; uint8_t page;
uint8_t offset; uint8_t offset;
uint16_t regs[max_rw_regs]; uint16_t regs[PKT_MAX_REGS];
}; };
#pragma pack(pop) #pragma pack(pop)
@@ -268,6 +268,12 @@ PX4IO_serial::~PX4IO_serial()
sem_destroy(&_completion_semaphore); sem_destroy(&_completion_semaphore);
sem_destroy(&_bus_semaphore); sem_destroy(&_bus_semaphore);
perf_free(_perf_dmasetup);
perf_free(_perf_timeouts);
perf_free(_perf_errors);
perf_free(_perf_txns);
perf_free(_perf_crcerrs);
if (g_interface == this) if (g_interface == this)
g_interface = nullptr; g_interface = nullptr;
} }
@@ -334,7 +340,7 @@ PX4IO_serial::test(unsigned mode)
int int
PX4IO_serial::set_reg(uint8_t page, uint8_t offset, const uint16_t *values, unsigned num_values) PX4IO_serial::set_reg(uint8_t page, uint8_t offset, const uint16_t *values, unsigned num_values)
{ {
if (num_values > max_rw_regs) if (num_values > PKT_MAX_REGS)
return -EINVAL; return -EINVAL;
sem_wait(&_bus_semaphore); sem_wait(&_bus_semaphore);
@@ -343,7 +349,7 @@ PX4IO_serial::set_reg(uint8_t page, uint8_t offset, const uint16_t *values, unsi
_dma_buffer.page = page; _dma_buffer.page = page;
_dma_buffer.offset = offset; _dma_buffer.offset = offset;
memcpy((void *)&_dma_buffer.regs[0], (void *)values, (2 * num_values)); memcpy((void *)&_dma_buffer.regs[0], (void *)values, (2 * num_values));
for (unsigned i = num_values; i < max_rw_regs; i++) for (unsigned i = num_values; i < PKT_MAX_REGS; i++)
_dma_buffer.regs[i] = 0x55aa; _dma_buffer.regs[i] = 0x55aa;
/* XXX implement check byte */ /* XXX implement check byte */
@@ -358,7 +364,7 @@ PX4IO_serial::set_reg(uint8_t page, uint8_t offset, const uint16_t *values, unsi
int int
PX4IO_serial::get_reg(uint8_t page, uint8_t offset, uint16_t *values, unsigned num_values) PX4IO_serial::get_reg(uint8_t page, uint8_t offset, uint16_t *values, unsigned num_values)
{ {
if (num_values > max_rw_regs) if (num_values > PKT_MAX_REGS)
return -EINVAL; return -EINVAL;
sem_wait(&_bus_semaphore); sem_wait(&_bus_semaphore);
@@ -422,7 +428,7 @@ PX4IO_serial::_wait_complete()
_tx_dma, _tx_dma,
PX4IO_SERIAL_BASE + STM32_USART_DR_OFFSET, PX4IO_SERIAL_BASE + STM32_USART_DR_OFFSET,
reinterpret_cast<uint32_t>(&_dma_buffer), reinterpret_cast<uint32_t>(&_dma_buffer),
sizeof(_dma_buffer), /* XXX should be tx_length */ sizeof(_dma_buffer), /* XXX should be PKT_LENGTH() */
DMA_SCR_DIR_M2P | DMA_SCR_DIR_M2P |
DMA_SCR_MINC | DMA_SCR_MINC |
DMA_SCR_PSIZE_8BITS | DMA_SCR_PSIZE_8BITS |
+5 -5
View File
@@ -77,7 +77,7 @@ static void dma_reset(void);
/* if we spend this many ticks idle, reset the DMA */ /* if we spend this many ticks idle, reset the DMA */
static unsigned idle_ticks; static unsigned idle_ticks;
#define MAX_RW_REGS 32 // by agreement w/FMU #define PKT_MAX_REGS 32 // by agreement w/FMU
#pragma pack(push, 1) #pragma pack(push, 1)
struct IOPacket { struct IOPacket {
@@ -85,7 +85,7 @@ struct IOPacket {
uint8_t crc; uint8_t crc;
uint8_t page; uint8_t page;
uint8_t offset; uint8_t offset;
uint16_t regs[MAX_RW_REGS]; uint16_t regs[PKT_MAX_REGS];
}; };
#pragma pack(pop) #pragma pack(pop)
@@ -231,8 +231,8 @@ rx_dma_callback(DMA_HANDLE handle, uint8_t status, void *arg)
count = 0; count = 0;
/* constrain reply to packet size */ /* constrain reply to packet size */
if (count > MAX_RW_REGS) if (count > PKT_MAX_REGS)
count = MAX_RW_REGS; count = PKT_MAX_REGS;
/* copy reply registers into DMA buffer */ /* copy reply registers into DMA buffer */
memcpy((void *)&dma_packet.regs[0], registers, count); memcpy((void *)&dma_packet.regs[0], registers, count);
@@ -251,7 +251,7 @@ rx_dma_callback(DMA_HANDLE handle, uint8_t status, void *arg)
tx_dma, tx_dma,
(uint32_t)&rDR, (uint32_t)&rDR,
(uint32_t)&dma_packet, (uint32_t)&dma_packet,
sizeof(dma_packet), /* XXX cut back to actual transmit size */ sizeof(dma_packet), /* XXX should be PKT_LENGTH() */
DMA_CCR_DIR | DMA_CCR_DIR |
DMA_CCR_MINC | DMA_CCR_MINC |
DMA_CCR_PSIZE_8BITS | DMA_CCR_PSIZE_8BITS |