Skip to content

Commit 7a5ecd8

Browse files
authored
Boards: MISRA fixes (speeduino#1340)
1 parent e79fa2f commit 7a5ecd8

File tree

8 files changed

+28
-27
lines changed

8 files changed

+28
-27
lines changed

speeduino/board_avr2560.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,21 @@ uint16_t freeRam(void)
107107
int currentVal;
108108
uint16_t v;
109109

110-
if(__brkval == 0) { currentVal = (int) &__heap_start; }
111-
else { currentVal = (int) __brkval; }
110+
if(__brkval == NULL) {
111+
currentVal = (int) &__heap_start;
112+
} else {
113+
currentVal = (int) __brkval;
114+
}
112115

113116
//Old version:
114117
//return (uint16_t) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
115-
/* cppcheck-suppress misra-c2012-11.4 ; DEVIATION(D3) */
116-
return (uint16_t) &v - currentVal; //cppcheck-suppress misra-c2012-11.4
118+
return (uint16_t) &v - currentVal; // cppcheck-suppress [misra-c2012-11.4, misra-c2012-10.4]
117119
}
118120

119121
void doSystemReset(void) { return; }
120122
void jumpToBootloader(void) { return; }
121123

122-
uint8_t getSystemTemp()
124+
uint8_t getSystemTemp(void)
123125
{
124126
//AVR2560 has no internal temperature monitoring, just return 0.
125127
return 0;

speeduino/board_same51.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ static inline void IGN8_TIMER_DISABLE(void) { TCC2->INTENSET.bit.MC1 = 0x0; }
140140

141141
#define MAX_TIMER_PERIOD 139808 // 2.13333333uS * 65535
142142
#define MAX_TIMER_PERIOD_SLOW 139808
143-
#define uS_TO_TIMER_COMPARE(uS) ((uS * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed.
143+
#define uS_TO_TIMER_COMPARE(uS) (((uS) * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed.
144144
//Hack compatibility with AVR timers that run at different speeds
145-
#define uS_TO_TIMER_COMPARE_SLOW(uS) ((uS * 15) >> 5)
145+
#define uS_TO_TIMER_COMPARE_SLOW(uS) (((uS) * 15) >> 5)
146146

147147
/*
148148
***********************************************************************************************************

speeduino/board_stm32_official.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ STM32RTC& rtc = STM32RTC::getInstance();
389389
#endif
390390
#endif //End core<=1.8
391391

392-
uint8_t getSystemTemp()
392+
uint8_t getSystemTemp(void)
393393
{
394394
//stm32F4xx does have an internal temperature sensor, but needs to be implemented
395395
return 0;

speeduino/board_stm32_official.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
//#define FRAM_AS_EEPROM /*Use FRAM like FM25xxx, MB85RSxxx or any SPI compatible */
4848

4949
#ifndef word
50-
#define word(h, l) ((h << 8) | l) //word() function not defined for this platform in the main library
50+
#define word(h, l) (((h) << 8) | (l)) //word() function not defined for this platform in the main library
5151
#endif
5252

5353
#if defined(ARDUINO_BLUEPILL_F103C8) || defined(ARDUINO_BLUEPILL_F103CB) \

speeduino/board_teensy35.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
#include <InternalTemperature.h>
1010
#include RTC_LIB_H
1111

12-
/*
13-
//These are declared locally in comms_CAN now due to this issue: https://github.com/tonton81/FlexCAN_T4/issues/67
14-
#if defined(__MK64FX512__) // use for Teensy 3.5 only
15-
FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
16-
#elif defined(__MK66FX1M0__) // use for Teensy 3.6 only
17-
FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
18-
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can1;
19-
#endif
20-
*/
12+
//These are declared locally in comms_CAN now due to this issue: https://github.com/tonton81/FlexCAN_T4/issues/67
13+
// #if defined(__MK64FX512__) // use for Teensy 3.5 only
14+
// FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
15+
// #elif defined(__MK66FX1M0__) // use for Teensy 3.6 only
16+
// FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
17+
// FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can1;
18+
// #endif
19+
2120

2221
void initBoard(uint32_t baudRate)
2322
{
@@ -423,7 +422,7 @@ static time_t getTeensy3Time()
423422
void doSystemReset() { return; }
424423
void jumpToBootloader() { return; }
425424

426-
uint8_t getSystemTemp()
425+
uint8_t getSystemTemp(void)
427426
{
428427
return trunc(InternalTemperature.readTemperatureC());
429428
}

speeduino/board_teensy35.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static inline void IGN7_TIMER_DISABLE(void) {FTM3_C6SC &= ~FTM_CSC_CHIE;}
112112
static inline void IGN8_TIMER_DISABLE(void) {FTM3_C7SC &= ~FTM_CSC_CHIE;}
113113

114114
#define MAX_TIMER_PERIOD 139808UL // 2.13333333uS * 65535
115-
#define uS_TO_TIMER_COMPARE(uS) ((uS * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed.
115+
#define uS_TO_TIMER_COMPARE(uS) (((uS) * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed.
116116

117117
/*
118118
***********************************************************************************************************

speeduino/board_teensy41.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void serialBegin()
2626
{
2727
uint32_t elapsed = systick_millis_count - millis_begin;
2828
//Wait up to 100ms for this.
29-
if (elapsed > 100) break;
29+
if (elapsed > 100) { break; }
3030
yield();
3131
}
3232
}
@@ -378,7 +378,7 @@ static void setPinHysteresis(uint8_t pin)
378378
*(p->mux) = 5 | 0x10;
379379
}
380380

381-
uint8_t getSystemTemp()
381+
uint8_t getSystemTemp(void)
382382
{
383383
return trunc(InternalTemperature.readTemperatureC());
384384
}

speeduino/board_teensy41.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,23 @@ static inline void IGN8_TIMER_DISABLE(void) {TMR4_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN
121121
#if F_CPU == 600000000
122122
//Bus Clock is 150Mhz @ 600 Mhz CPU.
123123
#define MAX_TIMER_PERIOD 55923UL //Time per tick = 0.8533333
124-
#define uS_TO_TIMER_COMPARE(uS) ((uS * 75UL) >> 6) //Converts a given number of uS into the required number of timer ticks until that time has passed.
124+
#define uS_TO_TIMER_COMPARE(uS) (((uS) * 75UL) >> 6) //Converts a given number of uS into the required number of timer ticks until that time has passed.
125125
#elif F_CPU == 528000000
126126
//Bus Clock is 132Mhz @ 528 Mhz CPU.
127127
#define MAX_TIMER_PERIOD 63549UL //Time per tick = 0.96969696
128-
#define uS_TO_TIMER_COMPARE(uS) ((uS * 66UL) >> 6) //Converts a given number of uS into the required number of timer ticks until that time has passed.
128+
#define uS_TO_TIMER_COMPARE(uS) (((uS) * 66UL) >> 6) //Converts a given number of uS into the required number of timer ticks until that time has passed.
129129
#elif F_CPU == 450000000
130130
//Bus Clock is 150Mhz @ 450 Mhz CPU.
131131
#define MAX_TIMER_PERIOD 55923UL //Time per tick = 0.8533333
132-
#define uS_TO_TIMER_COMPARE(uS) ((uS * 75UL) >> 6) //Converts a given number of uS into the required number of timer ticks until that time has passed.
132+
#define uS_TO_TIMER_COMPARE(uS) (((uS) * 75UL) >> 6) //Converts a given number of uS into the required number of timer ticks until that time has passed.
133133
#elif F_CPU == 396000000
134134
//Bus Clock is 132Mhz @ 396 Mhz CPU.
135135
#define MAX_TIMER_PERIOD 63549UL //Time per tick = 0.96969696
136-
#define uS_TO_TIMER_COMPARE(uS) ((uS * 66UL) >> 6) //Converts a given number of uS into the required number of timer ticks until that time has passed.
136+
#define uS_TO_TIMER_COMPARE(uS) (((uS) * 66UL) >> 6) //Converts a given number of uS into the required number of timer ticks until that time has passed.
137137
#elif F_CPU == 150000000
138138
//Bus Clock is 75Mhz @ 150 Mhz CPU.
139139
#define MAX_TIMER_PERIOD 111846UL //Time per tick = 1.706666
140-
#define uS_TO_TIMER_COMPARE(uS) ((uS * 75UL) >> 7) //Converts a given number of uS into the required number of timer ticks until that time has passed.
140+
#define uS_TO_TIMER_COMPARE(uS) (((uS) * 75UL) >> 7) //Converts a given number of uS into the required number of timer ticks until that time has passed.
141141
#else
142142
#error Unsupported CPU frequency.
143143
#endif

0 commit comments

Comments
 (0)