mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
rf22: Static analysis fixes
A few small fixes for the rf22 to satisfy klocwork. * Converted malloc's to new's to be more C++'ish and since malloc return were not checked. * Initialize data, buf, and _lastInterruptFlags * Up'ed RF22_MAX_MESSAGE_LEN to 64. Reason: void RF22::sendNextFragment() { if (_txBufSentIndex < _bufLen) { // Some left to send? uint8_t len = _bufLen - _txBufSentIndex; // But dont send too much if (len > (RF22_FIFO_SIZE - RF22_TXFFAEM_THRESHOLD - 1)) len = (RF22_FIFO_SIZE - RF22_TXFFAEM_THRESHOLD - 1); spiBurstWrite(RF22_REG_7F_FIFO_ACCESS, _buf + _txBufSentIndex, len); _txBufSentIndex += len; } } RF22_FIFO_SIZE = 64 RF22_TXFFAEM_THRESHOLD = 4 RF22_MAX_MESSAGE_LEN = 50 _buf[RF22_MAX_MESSAGE_LEN] Length of _buf *was* 50, so if the 'But dont send too much' above was to happen, the length is set to 63, which overruns _buf[RF22_MAX_MESSAGE_LEN] Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
parent
51a181a14f
commit
65fc70a31a
@ -187,7 +187,7 @@ uint8_t RF22::init()
|
|||||||
// C++ level interrupt handler for this instance
|
// C++ level interrupt handler for this instance
|
||||||
void RF22::handleInterrupt()
|
void RF22::handleInterrupt()
|
||||||
{
|
{
|
||||||
uint8_t _lastInterruptFlags[2];
|
uint8_t _lastInterruptFlags[2] = {};
|
||||||
// Read the interrupt flags which clears the interrupt
|
// Read the interrupt flags which clears the interrupt
|
||||||
spiBurstRead(RF22_REG_03_INTERRUPT_STATUS1, _lastInterruptFlags, 2);
|
spiBurstRead(RF22_REG_03_INTERRUPT_STATUS1, _lastInterruptFlags, 2);
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ void RF22::reset()
|
|||||||
|
|
||||||
uint8_t RF22::spiRead(uint8_t reg)
|
uint8_t RF22::spiRead(uint8_t reg)
|
||||||
{
|
{
|
||||||
uint8_t data;
|
uint8_t data = 0;
|
||||||
spiBurstRead (reg, &data, 1);
|
spiBurstRead (reg, &data, 1);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -294,52 +294,42 @@ void RF22::spiWrite(uint8_t reg, uint8_t val)
|
|||||||
|
|
||||||
void RF22::spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len)
|
void RF22::spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len)
|
||||||
{
|
{
|
||||||
uint8_t *request;
|
uint8_t *request = new uint8_t[len + 1]();
|
||||||
uint8_t *response;
|
uint8_t *response = new uint8_t[len + 1]();
|
||||||
|
|
||||||
request = (uint8_t *) malloc(sizeof(uint8_t) * (len + 1));
|
|
||||||
response = (uint8_t *) malloc(sizeof(uint8_t) * (len + 1));
|
|
||||||
memset(request, 0x00, len + 1);
|
|
||||||
memset(response, 0x00, len + 1);
|
|
||||||
|
|
||||||
request[0] = reg & ~RF22_SPI_WRITE_MASK;
|
request[0] = reg & ~RF22_SPI_WRITE_MASK;
|
||||||
memcpy (&request[1], dest, len);
|
memcpy (&request[1], dest, len);
|
||||||
|
|
||||||
mraa_gpio_write(_cs, 0x1);
|
mraa_gpio_write(_cs, 0x1);
|
||||||
mraa_gpio_write(_cs, 0x0);
|
mraa_gpio_write(_cs, 0x0);
|
||||||
usleep(100);
|
usleep(100);
|
||||||
mraa_spi_transfer_buf(_spi, request, response, len + 1);
|
mraa_spi_transfer_buf(_spi, request, response, len + 1);
|
||||||
usleep(100);
|
usleep(100);
|
||||||
mraa_gpio_write(_cs, 0x1);
|
mraa_gpio_write(_cs, 0x1);
|
||||||
|
|
||||||
memcpy (dest, &response[1], len);
|
memcpy (dest, &response[1], len);
|
||||||
|
|
||||||
free (request);
|
delete[] request;
|
||||||
free (response);
|
delete[] response;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RF22::spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len)
|
void RF22::spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len)
|
||||||
{
|
{
|
||||||
uint8_t *request;
|
uint8_t *request = new uint8_t[len + 1]();
|
||||||
uint8_t *response;
|
uint8_t *response = new uint8_t[len + 1]();
|
||||||
|
|
||||||
request = (uint8_t *) malloc(sizeof(uint8_t) * (len + 1));
|
|
||||||
response = (uint8_t *) malloc(sizeof(uint8_t) * (len + 1));
|
|
||||||
memset(request, 0x00, len + 1);
|
|
||||||
memset(response, 0x00, len + 1);
|
|
||||||
|
|
||||||
request[0] = reg | RF22_SPI_WRITE_MASK;
|
request[0] = reg | RF22_SPI_WRITE_MASK;
|
||||||
memcpy (&request[1], src, len);
|
memcpy (&request[1], src, len);
|
||||||
|
|
||||||
mraa_gpio_write(_cs, 0x1);
|
mraa_gpio_write(_cs, 0x1);
|
||||||
mraa_gpio_write(_cs, 0x0);
|
mraa_gpio_write(_cs, 0x0);
|
||||||
usleep(100);
|
usleep(100);
|
||||||
mraa_spi_transfer_buf(_spi, request, response, len + 1);
|
mraa_spi_transfer_buf(_spi, request, response, len + 1);
|
||||||
usleep(100);
|
usleep(100);
|
||||||
mraa_gpio_write(_cs, 0x1);
|
mraa_gpio_write(_cs, 0x1);
|
||||||
|
|
||||||
free (request);
|
delete[] request;
|
||||||
free (response);
|
delete[] response;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t RF22::statusRead()
|
uint8_t RF22::statusRead()
|
||||||
@ -373,7 +363,7 @@ uint8_t RF22::temperatureRead(uint8_t tsrange, uint8_t tvoffs)
|
|||||||
|
|
||||||
uint16_t RF22::wutRead()
|
uint16_t RF22::wutRead()
|
||||||
{
|
{
|
||||||
uint8_t buf[2];
|
uint8_t buf[2] = {};
|
||||||
spiBurstRead(RF22_REG_17_WAKEUP_TIMER_VALUE1, buf, 2);
|
spiBurstRead(RF22_REG_17_WAKEUP_TIMER_VALUE1, buf, 2);
|
||||||
return ((uint16_t)buf[0] << 8) | buf[1]; // Dont rely on byte order
|
return ((uint16_t)buf[0] << 8) | buf[1]; // Dont rely on byte order
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
// Can be pre-defined to a smaller size (to save SRAM) prior to including this header
|
// Can be pre-defined to a smaller size (to save SRAM) prior to including this header
|
||||||
#ifndef RF22_MAX_MESSAGE_LEN
|
#ifndef RF22_MAX_MESSAGE_LEN
|
||||||
//#define RF22_MAX_MESSAGE_LEN 255
|
//#define RF22_MAX_MESSAGE_LEN 255
|
||||||
#define RF22_MAX_MESSAGE_LEN 50
|
#define RF22_MAX_MESSAGE_LEN 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Max number of octets the RF22 Rx and Tx FIFOs can hold
|
// Max number of octets the RF22 Rx and Tx FIFOs can hold
|
||||||
|
Loading…
x
Reference in New Issue
Block a user