fast integer: uint_fast8_t and uint_fast16_t for some vars.
This will decrease the flash size and should increase performance. In some cases this will increase the used ram slightly. In total this path costs 28 bytes RAM and saves 88 bytes of Flash on a STM32. AVRs are not affected by this commit.
This commit is contained in:
parent
dcd67e402a
commit
9033d86877
|
|
@ -78,7 +78,7 @@ void init_analog() {
|
|||
// subt line is to keep compiler happy
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) \
|
||||
if (NUM_TEMP_SENSORS) { \
|
||||
uint8_t subt = (pin ## _ADC >= 10) ? 10 : 0; \
|
||||
uint32_t subt = (pin ## _ADC >= 10) ? 10 : 0; \
|
||||
if (pin ## _ADC >= 10) { \
|
||||
ADC1->SMPR1 |= (uint32_t)0x06 << (3 * ((pin ## _ADC) - subt)); \
|
||||
} else { \
|
||||
|
|
@ -186,8 +186,8 @@ uint16_t analog_read(uint8_t index) {
|
|||
if (NUM_TEMP_SENSORS > 0) {
|
||||
uint16_t r = 0;
|
||||
uint16_t temp;
|
||||
uint16_t max_temp = 0;
|
||||
uint16_t min_temp = 0xffff;
|
||||
uint32_t max_temp = 0;
|
||||
uint32_t min_temp = UINT32_MAX;
|
||||
|
||||
for (uint8_t i = 0; i < OVERSAMPLE; i++) {
|
||||
temp = adc_buffer[i][index];
|
||||
|
|
|
|||
12
clock.c
12
clock.c
|
|
@ -30,16 +30,16 @@
|
|||
Every time our clock fires we increment this,
|
||||
so we know when 10ms/250ms/1s has elapsed.
|
||||
*/
|
||||
static uint8_t clock_counter_10ms = 0;
|
||||
static uint8_t clock_counter_250ms = 0;
|
||||
static uint8_t clock_counter_1s = 0;
|
||||
static uint_fast8_t clock_counter_10ms = 0;
|
||||
static uint_fast8_t clock_counter_250ms = 0;
|
||||
static uint_fast8_t clock_counter_1s = 0;
|
||||
|
||||
/**
|
||||
Flags to tell clock() when above have elapsed.
|
||||
*/
|
||||
static volatile uint8_t clock_flag_10ms = 0;
|
||||
static volatile uint8_t clock_flag_250ms = 0;
|
||||
static volatile uint8_t clock_flag_1s = 0;
|
||||
static volatile uint_fast8_t clock_flag_10ms = 0;
|
||||
static volatile uint_fast8_t clock_flag_250ms = 0;
|
||||
static volatile uint_fast8_t clock_flag_1s = 0;
|
||||
|
||||
|
||||
/** Advance our clock by a tick.
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@
|
|||
is used both in and out of interrupts, but is only written outside of
|
||||
interrupts.
|
||||
*/
|
||||
static uint8_t mb_head = 0;
|
||||
static uint_fast8_t mb_head = 0;
|
||||
|
||||
/// movebuffer tail pointer. Points to the currently executing move
|
||||
/// this variable is read/written both in and out of interrupts.
|
||||
uint8_t mb_tail = 0;
|
||||
uint_fast8_t mb_tail = 0;
|
||||
|
||||
/// move buffer.
|
||||
/// holds move queue
|
||||
|
|
@ -46,7 +46,7 @@ DDA *mb_tail_dda;
|
|||
#define MB_NEXT(x) ((x) < MOVEBUFFER_SIZE - 1 ? (x) + 1 : 0)
|
||||
|
||||
/// check if the queue is completely full
|
||||
uint8_t queue_full() {
|
||||
uint_fast8_t queue_full() {
|
||||
MEMORY_BARRIER();
|
||||
return MB_NEXT(mb_head) == mb_tail;
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ void enqueue_home(TARGET *t, uint8_t endstop_check, uint8_t endstop_stop_cond) {
|
|||
while (queue_full())
|
||||
delay_us(100);
|
||||
|
||||
uint8_t h = MB_NEXT(mb_head);
|
||||
uint_fast8_t h = MB_NEXT(mb_head);
|
||||
|
||||
DDA* new_movebuffer = &(movebuffer[h]);
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
// this is the ringbuffer that holds the current and pending moves.
|
||||
extern uint8_t mb_tail;
|
||||
extern uint_fast8_t mb_tail;
|
||||
extern DDA movebuffer[MOVEBUFFER_SIZE];
|
||||
extern DDA *mb_tail_dda;
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ extern DDA *mb_tail_dda;
|
|||
*/
|
||||
|
||||
// queue status methods
|
||||
uint8_t queue_full(void);
|
||||
uint_fast8_t queue_full(void);
|
||||
|
||||
// take one step
|
||||
void queue_step(void);
|
||||
|
|
|
|||
8
temp.c
8
temp.c
|
|
@ -75,12 +75,12 @@ static const temp_sensor_definition_t temp_sensors[NUM_TEMP_SENSORS] =
|
|||
|
||||
/// this struct holds the runtime sensor data- read temperatures, targets, etc
|
||||
static struct {
|
||||
uint16_t last_read_temp; ///< last received reading
|
||||
uint16_t target_temp; ///< manipulate attached heater to attempt to achieve this value
|
||||
uint_fast16_t last_read_temp; ///< last received reading
|
||||
uint_fast16_t target_temp; ///< manipulate attached heater to attempt to achieve this value
|
||||
|
||||
uint16_t temp_residency; ///< how long have we been close to target temperature in temp ticks?
|
||||
uint_fast16_t temp_residency; ///< how long have we been close to target temperature in temp ticks?
|
||||
|
||||
uint8_t active; ///< State machine tracker for readers that need it.
|
||||
uint_fast8_t active; ///< State machine tracker for readers that need it.
|
||||
} temp_sensors_runtime[NUM_TEMP_SENSORS];
|
||||
|
||||
/** \def TEMP_EWMA
|
||||
|
|
|
|||
Loading…
Reference in New Issue