1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-23 16:25:26 +03:00

Add ZeroFArray Macro and make use of it in some parts

This commit is contained in:
JuliooCesarMDM 2022-10-04 17:18:01 -03:00
parent c30025b9fc
commit 59d81d6f6f
8 changed files with 13 additions and 12 deletions

View file

@ -22,6 +22,7 @@
#define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0])) #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
#define ARRAYEND(x) (&(x)[ARRAYLEN(x)]) #define ARRAYEND(x) (&(x)[ARRAYLEN(x)])
#define ZERO_FARRAY(a) memset(a, 0, sizeof(a))
#define CONST_CAST(type, value) ((type)(value)) #define CONST_CAST(type, value) ((type)(value))
@ -92,9 +93,9 @@ static inline int32_t cmp32(uint32_t a, uint32_t b) { return a-b; }
#ifdef UNIT_TEST #ifdef UNIT_TEST
// Call memcpy when building unittest - this is easier that asm symbol name mangling (symbols start with _underscore on win32) // Call memcpy when building unittest - this is easier that asm symbol name mangling (symbols start with _underscore on win32)
#include <string.h> #include <string.h>
static inline void memcpy_fn ( void * destination, const void * source, size_t num ) { memcpy(destination, source, num); }; static inline void memcpy_fn(void *destination, const void *source, size_t num) { memcpy(destination, source, num); };
#else #else
void * memcpy_fn ( void * destination, const void * source, size_t num ) asm("memcpy"); void *memcpy_fn(void *destination, const void *source, size_t num) asm("memcpy");
#endif #endif
#if __GNUC__ > 6 #if __GNUC__ > 6

View file

@ -41,7 +41,7 @@ int config_streamer_impl_write_word(config_streamer_t *c, config_streamer_buffer
} }
if (c->address == (uintptr_t)&eepromData[0]) { if (c->address == (uintptr_t)&eepromData[0]) {
memset(eepromData, 0, sizeof(eepromData)); ZERO_FARRAY(eepromData);
} }
config_streamer_buffer_align_type_t *destAddr = (config_streamer_buffer_align_type_t *)c->address; config_streamer_buffer_align_type_t *destAddr = (config_streamer_buffer_align_type_t *)c->address;

View file

@ -261,7 +261,7 @@ static pwmOutputPort_t * motorConfigDshot(const timerHardware_t * timerHardware,
// Configure timer DMA // Configure timer DMA
if (timerPWMConfigChannelDMA(port->tch, port->dmaBuffer, sizeof(port->dmaBuffer[0]), DSHOT_DMA_BUFFER_SIZE)) { if (timerPWMConfigChannelDMA(port->tch, port->dmaBuffer, sizeof(port->dmaBuffer[0]), DSHOT_DMA_BUFFER_SIZE)) {
// Only mark as DSHOT channel if DMA was set successfully // Only mark as DSHOT channel if DMA was set successfully
memset(port->dmaBuffer, 0, sizeof(port->dmaBuffer)); ZERO_FARRAY(port->dmaBuffer);
port->configured = true; port->configured = true;
} }

View file

@ -4059,7 +4059,7 @@ void cliProcess(void)
bufferIndex = 0; bufferIndex = 0;
} }
memset(cliBuffer, 0, sizeof(cliBuffer)); ZERO_FARRAY(cliBuffer);
// 'exit' will reset this flag, so we don't need to print prompt again // 'exit' will reset this flag, so we don't need to print prompt again
if (!cliMode) if (!cliMode)

View file

@ -350,7 +350,7 @@ void initActiveBoxIds(void)
void packBoxModeFlags(boxBitmask_t * mspBoxModeFlags) void packBoxModeFlags(boxBitmask_t * mspBoxModeFlags)
{ {
uint8_t activeBoxes[CHECKBOX_ITEM_COUNT]; uint8_t activeBoxes[CHECKBOX_ITEM_COUNT];
memset(activeBoxes, 0, sizeof(activeBoxes)); ZERO_FARRAY(activeBoxes);
// Serialize the flags in the order we delivered them, ignoring BOXNAMES and BOXINDEXES // Serialize the flags in the order we delivered them, ignoring BOXNAMES and BOXINDEXES
// Requires new Multiwii protocol version to fix // Requires new Multiwii protocol version to fix

View file

@ -203,7 +203,7 @@ static void vtxProtoSend(uint8_t cmd, const uint8_t * data)
memcpy(vtxState.sendPkt.data, data, sizeof(vtxState.sendPkt.data)); memcpy(vtxState.sendPkt.data, data, sizeof(vtxState.sendPkt.data));
} }
else { else {
memset(vtxState.sendPkt.data, 0, sizeof(vtxState.sendPkt.data)); ZERO_FARRAY(vtxState.sendPkt.data);
} }
vtxState.sendPkt.checksum = vtxCalcChecksum(&vtxState.sendPkt); vtxState.sendPkt.checksum = vtxCalcChecksum(&vtxState.sendPkt);

View file

@ -346,7 +346,7 @@ static void sendSMS(void)
uint16_t avgSpeed = lrintf(10 * calculateAverageSpeed()); uint16_t avgSpeed = lrintf(10 * calculateAverageSpeed());
uint32_t now = millis(); uint32_t now = millis();
memset(pluscode_url, 0, sizeof(pluscode_url)); ZERO_FARRAY(pluscode_url);
if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) { if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) {
groundSpeed = gpsSol.groundSpeed / 100; groundSpeed = gpsSol.groundSpeed / 100;

View file

@ -10,7 +10,7 @@ extern "C" {
TEST(BitArrayTest, TestGetSet) TEST(BitArrayTest, TestGetSet)
{ {
BITARRAY_DECLARE(p, 32); BITARRAY_DECLARE(p, 32);
memset(p, 0, sizeof(p)); ZERO_FARRAY(p);
bitArraySet(p, 14); bitArraySet(p, 14);
EXPECT_EQ(bitArrayGet(p, 14), true); EXPECT_EQ(bitArrayGet(p, 14), true);
@ -25,7 +25,7 @@ TEST(BitArrayTest, TestGetSet)
TEST(BitArrayTest, TestClr) TEST(BitArrayTest, TestClr)
{ {
BITARRAY_DECLARE(p, 32); BITARRAY_DECLARE(p, 32);
memset(p, 0, sizeof(p)); ZERO_FARRAY(p);
bitArraySet(p, 31); bitArraySet(p, 31);
EXPECT_EQ(bitArrayGet(p, 31), true); EXPECT_EQ(bitArrayGet(p, 31), true);
@ -37,8 +37,8 @@ TEST(BitArrayTest, TestClr)
TEST(BitArrayTest, TestFind) TEST(BitArrayTest, TestFind)
{ {
BITARRAY_DECLARE(p, 32*4); BITARRAY_DECLARE(p, 32 * 4);
memset(p, 0, sizeof(p)); ZERO_FARRAY(p);
EXPECT_EQ(bitArrayFindFirstSet(p, 0, sizeof(p)), -1); EXPECT_EQ(bitArrayFindFirstSet(p, 0, sizeof(p)), -1);