Apply spacing, const to some HAL code

This commit is contained in:
Scott Lahteine 2017-08-24 12:18:54 -05:00
parent fa9ff6be6e
commit 2af62a5d8d
14 changed files with 191 additions and 252 deletions

View file

@ -112,15 +112,15 @@ extern "C" {
#define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B) #define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B)
#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B) #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
//void HAL_timer_start (uint8_t timer_num, uint32_t frequency); //void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
#define HAL_timer_start(timer_num,frequency) #define HAL_timer_start(timer_num,frequency)
//void HAL_timer_set_count (uint8_t timer_num, uint16_t count); //void HAL_timer_set_count(const uint8_t timer_num, const uint16_t count);
#define HAL_timer_set_count(timer, count) timer = (count) #define HAL_timer_set_count(timer, count) timer = (count)
#define HAL_timer_get_current_count(timer) timer #define HAL_timer_get_current_count(timer) timer
//void HAL_timer_isr_prologue (uint8_t timer_num); //void HAL_timer_isr_prologue(const uint8_t timer_num);
#define HAL_timer_isr_prologue(timer_num) #define HAL_timer_isr_prologue(timer_num)
#define HAL_STEP_TIMER_ISR ISR(TIMER1_COMPA_vect) #define HAL_STEP_TIMER_ISR ISR(TIMER1_COMPA_vect)

View file

@ -92,7 +92,7 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
*/ */
void HAL_timer_start (uint8_t timer_num, uint32_t frequency) { void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
Tc *tc = TimerConfig[timer_num].pTimerRegs; Tc *tc = TimerConfig[timer_num].pTimerRegs;
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id; IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
uint32_t channel = TimerConfig[timer_num].channel; uint32_t channel = TimerConfig[timer_num].channel;
@ -112,23 +112,23 @@ void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
NVIC_EnableIRQ(irq); NVIC_EnableIRQ(irq);
} }
void HAL_timer_enable_interrupt (uint8_t timer_num) { void HAL_timer_enable_interrupt(const uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig[timer_num]; const tTimerConfig *pConfig = &TimerConfig[timer_num];
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER = TC_IER_CPCS; pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER = TC_IER_CPCS;
} }
void HAL_timer_disable_interrupt (uint8_t timer_num) { void HAL_timer_disable_interrupt(const uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig[timer_num]; const tTimerConfig *pConfig = &TimerConfig[timer_num];
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IDR = TC_IDR_CPCS; pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IDR = TC_IDR_CPCS;
} }
#if 0 #if 0
void HAL_timer_set_count (uint8_t timer_num, uint32_t count) { void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
const tTimerConfig *pConfig = &TimerConfig[timer_num]; const tTimerConfig *pConfig = &TimerConfig[timer_num];
TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count); TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count);
} }
void HAL_timer_isr_prologue (uint8_t timer_num) { void HAL_timer_isr_prologue(const uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig[timer_num]; const tTimerConfig *pConfig = &TimerConfig[timer_num];
TC_GetStatus(pConfig->pTimerRegs, pConfig->channel); TC_GetStatus(pConfig->pTimerRegs, pConfig->channel);
} }

View file

@ -60,7 +60,7 @@
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM) #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0) #define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
//
#define HAL_STEP_TIMER_ISR void TC3_Handler() #define HAL_STEP_TIMER_ISR void TC3_Handler()
#define HAL_TEMP_TIMER_ISR void TC4_Handler() #define HAL_TEMP_TIMER_ISR void TC4_Handler()
@ -85,29 +85,29 @@ extern const tTimerConfig TimerConfig[];
// Public functions // Public functions
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
void HAL_timer_start (uint8_t timer_num, uint32_t frequency); void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
static FORCE_INLINE void HAL_timer_set_count (uint8_t timer_num, uint32_t count) { static FORCE_INLINE void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
const tTimerConfig *pConfig = &TimerConfig[timer_num]; const tTimerConfig *pConfig = &TimerConfig[timer_num];
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count; pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
} }
static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count (uint8_t timer_num) { static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count(const uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig[timer_num]; const tTimerConfig *pConfig = &TimerConfig[timer_num];
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC; return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
} }
static FORCE_INLINE uint32_t HAL_timer_get_current_count(uint8_t timer_num) { static FORCE_INLINE uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig[timer_num]; const tTimerConfig *pConfig = &TimerConfig[timer_num];
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV; return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
} }
void HAL_timer_enable_interrupt(uint8_t timer_num); void HAL_timer_enable_interrupt(const uint8_t timer_num);
void HAL_timer_disable_interrupt(uint8_t timer_num); void HAL_timer_disable_interrupt(const uint8_t timer_num);
//void HAL_timer_isr_prologue (uint8_t timer_num); //void HAL_timer_isr_prologue(const uint8_t timer_num);
static FORCE_INLINE void HAL_timer_isr_prologue(uint8_t timer_num) { static FORCE_INLINE void HAL_timer_isr_prologue(const uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig[timer_num]; const tTimerConfig *pConfig = &TimerConfig[timer_num];
// Reading the status register clears the interrupt flag // Reading the status register clears the interrupt flag
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_SR; pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_SR;

View file

@ -32,31 +32,30 @@
#include "HAL_timers.h" #include "HAL_timers.h"
void HAL_timer_init(void) { void HAL_timer_init(void) {
LPC_SC->PCONP |= (0x1 << 0x1); // power on timer0 SBI(LPC_SC->PCONP, 1); // power on timer0
LPC_TIM0->PR = ((HAL_TIMER_RATE / HAL_STEPPER_TIMER_RATE) - 1); // Use prescaler to set frequency if needed LPC_TIM0->PR = ((HAL_TIMER_RATE / HAL_STEPPER_TIMER_RATE) - 1); // Use prescaler to set frequency if needed
LPC_SC->PCONP |= (0x1 << 0x2); // power on timer1 SBI(LPC_SC->PCONP, 2); // power on timer1
LPC_TIM1->PR = ((HAL_TIMER_RATE / 1000000) - 1); LPC_TIM1->PR = ((HAL_TIMER_RATE / 1000000) - 1);
} }
void HAL_timer_start(uint8_t timer_num, uint32_t frequency) { void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
switch (timer_num) { switch (timer_num) {
case 0: case 0:
LPC_TIM0->MCR = 3; // Match on MR0, reset on MR0 LPC_TIM0->MCR = 3; // Match on MR0, reset on MR0
LPC_TIM0->MR0 = (uint32_t)(HAL_STEPPER_TIMER_RATE / frequency); // Match value (period) to set frequency LPC_TIM0->MR0 = (uint32_t)(HAL_STEPPER_TIMER_RATE / frequency); // Match value (period) to set frequency
LPC_TIM0->TCR = (1 << 0); // enable LPC_TIM0->TCR = _BV(0); // enable
break; break;
case 1: case 1:
LPC_TIM1->MCR = 3; LPC_TIM1->MCR = 3;
LPC_TIM1->MR0 = (uint32_t)(HAL_TEMP_TIMER_RATE / frequency);; LPC_TIM1->MR0 = (uint32_t)(HAL_TEMP_TIMER_RATE / frequency);;
LPC_TIM1->TCR = (1 << 0); LPC_TIM1->TCR = _BV(0);
break; break;
default: default: break;
return;
} }
} }
void HAL_timer_enable_interrupt (uint8_t timer_num) { void HAL_timer_enable_interrupt(const uint8_t timer_num) {
switch (timer_num) { switch (timer_num) {
case 0: case 0:
NVIC_EnableIRQ(TIMER0_IRQn); // Enable interrupt handler NVIC_EnableIRQ(TIMER0_IRQn); // Enable interrupt handler
@ -69,25 +68,17 @@ void HAL_timer_enable_interrupt (uint8_t timer_num) {
} }
} }
void HAL_timer_disable_interrupt (uint8_t timer_num) { void HAL_timer_disable_interrupt(const uint8_t timer_num) {
switch (timer_num) { switch (timer_num) {
case 0: case 0: NVIC_DisableIRQ(TIMER0_IRQn); break; // disable interrupt handler
NVIC_DisableIRQ(TIMER0_IRQn); // disable interrupt handler case 1: NVIC_DisableIRQ(TIMER1_IRQn); break;
break;
case 1:
NVIC_DisableIRQ(TIMER1_IRQn);
break;
} }
} }
void HAL_timer_isr_prologue (uint8_t timer_num) { void HAL_timer_isr_prologue(const uint8_t timer_num) {
switch (timer_num) { switch (timer_num) {
case 0: case 0: SBI(LPC_TIM0->IR, 0); break; // Clear the Interrupt
LPC_TIM0->IR |= 1; //Clear the Interrupt case 1: SBI(LPC_TIM1->IR, 0); break;
break;
case 1:
LPC_TIM1->IR |= 1;
break;
} }
} }

View file

@ -55,12 +55,11 @@
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM) #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM) #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0) #define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
//
#define HAL_STEP_TIMER_ISR extern "C" void TIMER0_IRQHandler(void) #define HAL_STEP_TIMER_ISR extern "C" void TIMER0_IRQHandler(void)
#define HAL_TEMP_TIMER_ISR extern "C" void TIMER1_IRQHandler(void) #define HAL_TEMP_TIMER_ISR extern "C" void TIMER1_IRQHandler(void)
@ -76,46 +75,33 @@
// Public functions // Public functions
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
void HAL_timer_init(void); void HAL_timer_init(void);
void HAL_timer_start (uint8_t timer_num, uint32_t frequency); void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
static FORCE_INLINE void HAL_timer_set_count (uint8_t timer_num, HAL_TIMER_TYPE count) { static FORCE_INLINE void HAL_timer_set_count(const uint8_t timer_num, const HAL_TIMER_TYPE count) {
switch (timer_num) { switch (timer_num) {
case 0: case 0: LPC_TIM0->MR0 = count; break;
LPC_TIM0->MR0 = count; case 1: LPC_TIM1->MR0 = count; break;
break;
case 1:
LPC_TIM1->MR0 = count;
break;
default:
return;
} }
} }
static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count (uint8_t timer_num) { static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count(const uint8_t timer_num) {
switch (timer_num) { switch (timer_num) {
case 0: case 0: return LPC_TIM0->MR0;
return LPC_TIM0->MR0; case 1: return LPC_TIM1->MR0;
case 1: }
return LPC_TIM1->MR0;
default:
return 0; return 0;
} }
}
static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_current_count(uint8_t timer_num) { static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_current_count(const uint8_t timer_num) {
switch (timer_num) { switch (timer_num) {
case 0: case 0: return LPC_TIM0->TC;
return LPC_TIM0->TC; case 1: return LPC_TIM1->TC;
case 1: }
return LPC_TIM1->TC;
default:
return 0; return 0;
} }
}
void HAL_timer_enable_interrupt(uint8_t timer_num);
void HAL_timer_disable_interrupt(uint8_t timer_num);
void HAL_timer_isr_prologue (uint8_t timer_num);
void HAL_timer_enable_interrupt(const uint8_t timer_num);
void HAL_timer_disable_interrupt(const uint8_t timer_num);
void HAL_timer_isr_prologue(const uint8_t timer_num);
#endif // _HAL_TIMERS_DUE_H #endif // _HAL_TIMERS_DUE_H

View file

@ -39,7 +39,7 @@ void HAL_clear_reset_source(void) {
} }
uint8_t HAL_get_reset_source(void) { uint8_t HAL_get_reset_source(void) {
if(WDT_ReadTimeOutFlag() & 1) return RST_WATCHDOG; if (TEST(WDT_ReadTimeOutFlag(), 0)) return RST_WATCHDOG;
return RST_POWER_ON; return RST_POWER_ON;
} }
@ -50,4 +50,4 @@ void watchdog_reset() {
#endif // USE_WATCHDOG #endif // USE_WATCHDOG
#endif #endif // TARGET_LPC1768

View file

@ -31,7 +31,6 @@
uint16_t HAL_adc_result; uint16_t HAL_adc_result;
static const uint8_t pin2sc1a[] = { static const uint8_t pin2sc1a[] = {
5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 3, 19+128, 14+128, 15+128, // 0-13 -> A0-A13 5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 3, 19+128, 14+128, 15+128, // 0-13 -> A0-A13
5, 14, 8, 9, 13, 12, 6, 7, 15, 4, // 14-23 are A0-A9 5, 14, 8, 9, 13, 12, 6, 7, 15, 4, // 14-23 are A0-A9
@ -50,45 +49,31 @@ static const uint8_t pin2sc1a[] = {
/* /*
// disable interrupts // disable interrupts
void cli(void) void cli(void) { noInterrupts(); }
{
noInterrupts();
}
// enable interrupts // enable interrupts
void sei(void) void sei(void) { interrupts(); }
{
interrupts();
}
*/ */
void HAL_adc_init() { void HAL_adc_init() {
analog_init(); analog_init();
while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
NVIC_ENABLE_IRQ(IRQ_FTM1); NVIC_ENABLE_IRQ(IRQ_FTM1);
} }
void HAL_clear_reset_source (void) void HAL_clear_reset_source(void) { }
{ }
uint8_t HAL_get_reset_source (void) uint8_t HAL_get_reset_source(void) {
{ switch (RCM_SRS0) {
switch ( RCM_SRS0 )
{
case 128: return RST_POWER_ON; break; case 128: return RST_POWER_ON; break;
case 64: return RST_EXTERNAL; break; case 64: return RST_EXTERNAL; break;
case 32: return RST_WATCHDOG; break; case 32: return RST_WATCHDOG; break;
// case 8: return RST_LOSS_OF_LOCK; break; // case 8: return RST_LOSS_OF_LOCK; break;
// case 4: return RST_LOSS_OF_CLOCK; break; // case 4: return RST_LOSS_OF_CLOCK; break;
// case 2: return RST_LOW_VOLTAGE; break; // case 2: return RST_LOW_VOLTAGE; break;
default: }
return 0; return 0;
} }
}
void _delay_ms (int delay_ms)
{
delay (delay_ms);
}
extern "C" { extern "C" {
extern char __bss_end; extern char __bss_end;
@ -105,15 +90,8 @@ extern "C" {
} }
} }
void HAL_adc_start_conversion (uint8_t adc_pin) void HAL_adc_start_conversion(const uint8_t adc_pin) { ADC0_SC1A = pin2sc1a[adc_pin]; }
{
ADC0_SC1A = pin2sc1a[adc_pin];
}
uint16_t HAL_adc_get_result(void) uint16_t HAL_adc_get_result(void) { return ADC0_RA; }
{
return ADC0_RA;
}
#endif // __MK64FX512__ || __MK66FX1M0__ #endif // __MK64FX512__ || __MK66FX1M0__

View file

@ -23,7 +23,6 @@
* Description: HAL for Teensy 3.5 and Teensy 3.6 * Description: HAL for Teensy 3.5 and Teensy 3.6
*/ */
#ifndef _HAL_TEENSY_H #ifndef _HAL_TEENSY_H
#define _HAL_TEENSY_H #define _HAL_TEENSY_H
@ -64,8 +63,6 @@
#define HAL_SERVO_LIB libServo #define HAL_SERVO_LIB libServo
//#define _BV(bit) (1 << (bit))
#ifndef analogInputToDigitalPin #ifndef analogInputToDigitalPin
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1) #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
#endif #endif
@ -73,7 +70,6 @@
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli(); #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
#define CRITICAL_SECTION_END SREG = _sreg; #define CRITICAL_SECTION_END SREG = _sreg;
// On AVR this is in math.h? // On AVR this is in math.h?
#define square(x) ((x)*(x)) #define square(x) ((x)*(x))
@ -101,7 +97,7 @@ void HAL_clear_reset_source (void);
/** reset reason */ /** reset reason */
uint8_t HAL_get_reset_source(void); uint8_t HAL_get_reset_source(void);
void _delay_ms(int delay); FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
extern "C" { extern "C" {
int freeMemory(void); int freeMemory(void);
@ -146,4 +142,3 @@ void HAL_enable_AdcFreerun(void);
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#endif // _HAL_TEENSY_H #endif // _HAL_TEENSY_H

View file

@ -30,7 +30,7 @@
#include "HAL_timers_Teensy.h" #include "HAL_timers_Teensy.h"
void HAL_timer_start (uint8_t timer_num, uint32_t frequency) { void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
switch (timer_num) { switch (timer_num) {
case 0: case 0:
FTM0_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN; FTM0_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN;
@ -50,32 +50,24 @@ void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
FTM1_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM1_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 4 FTM1_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM1_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 4
FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA; FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
break; break;
default:
break;
} }
} }
void HAL_timer_enable_interrupt (uint8_t timer_num) void HAL_timer_enable_interrupt(const uint8_t timer_num) {
{
switch(timer_num) { switch(timer_num) {
case 0: NVIC_ENABLE_IRQ(IRQ_FTM0); break; case 0: NVIC_ENABLE_IRQ(IRQ_FTM0); break;
case 1: NVIC_ENABLE_IRQ(IRQ_FTM1); break; case 1: NVIC_ENABLE_IRQ(IRQ_FTM1); break;
default:
break;
} }
} }
void HAL_timer_disable_interrupt (uint8_t timer_num) void HAL_timer_disable_interrupt(const uint8_t timer_num) {
{
switch (timer_num) { switch (timer_num) {
case 0: NVIC_DISABLE_IRQ(IRQ_FTM0); break; case 0: NVIC_DISABLE_IRQ(IRQ_FTM0); break;
case 1: NVIC_DISABLE_IRQ(IRQ_FTM1); break; case 1: NVIC_DISABLE_IRQ(IRQ_FTM1); break;
default:
break;
} }
} }
void HAL_timer_isr_prologue(uint8_t timer_num) { void HAL_timer_isr_prologue(const uint8_t timer_num) {
switch(timer_num) { switch(timer_num) {
case 0: case 0:
FTM0_CNT = 0x0000; FTM0_CNT = 0x0000;
@ -87,8 +79,6 @@ void HAL_timer_isr_prologue(uint8_t timer_num) {
FTM1_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag FTM1_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
FTM1_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag FTM1_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
break; break;
default:
break;
} }
} }

View file

@ -52,8 +52,8 @@
#define FTM0_TIMER_PRESCALE_BITS 0b011 #define FTM0_TIMER_PRESCALE_BITS 0b011
#define FTM1_TIMER_PRESCALE_BITS 0b010 #define FTM1_TIMER_PRESCALE_BITS 0b010
#define FTM0_TIMER_RATE F_BUS/FTM0_TIMER_PRESCALE // 60MHz / 8 = 7500kHz #define FTM0_TIMER_RATE (F_BUS / FTM0_TIMER_PRESCALE) // 60MHz / 8 = 7500kHz
#define FTM1_TIMER_RATE F_BUS/FTM1_TIMER_PRESCALE // 60MHz / 4 = 15MHz #define FTM1_TIMER_RATE (F_BUS / FTM1_TIMER_PRESCALE) // 60MHz / 4 = 15MHz
#define STEPPER_TIMER STEP_TIMER_NUM // Alias? #define STEPPER_TIMER STEP_TIMER_NUM // Alias?
#define STEPPER_TIMER_PRESCALE 0 // Not defined anywhere else! #define STEPPER_TIMER_PRESCALE 0 // Not defined anywhere else!
@ -74,36 +74,35 @@
#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0) #define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
void HAL_timer_start (uint8_t timer_num, uint32_t frequency); void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
static FORCE_INLINE void HAL_timer_set_count (uint8_t timer_num, uint32_t count) { static FORCE_INLINE void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
switch(timer_num) { switch(timer_num) {
case 0: FTM0_C0V = count; break; case 0: FTM0_C0V = count; break;
case 1: FTM1_C0V = count; break; case 1: FTM1_C0V = count; break;
default: break;
} }
} }
static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count (uint8_t timer_num) { static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count(const uint8_t timer_num) {
switch(timer_num) { switch(timer_num) {
case 0: return FTM0_C0V; case 0: return FTM0_C0V;
case 1: return FTM1_C0V; case 1: return FTM1_C0V;
default: return 0;
} }
return 0;
} }
static FORCE_INLINE uint32_t HAL_timer_get_current_count(uint8_t timer_num) { static FORCE_INLINE uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
switch(timer_num) { switch(timer_num) {
case 0: return FTM0_CNT; case 0: return FTM0_CNT;
case 1: return FTM1_CNT; case 1: return FTM1_CNT;
default: return 0;
} }
return 0;
} }
void HAL_timer_enable_interrupt (uint8_t timer_num); void HAL_timer_enable_interrupt(const uint8_t timer_num);
void HAL_timer_disable_interrupt (uint8_t timer_num); void HAL_timer_disable_interrupt(const uint8_t timer_num);
void HAL_timer_isr_prologue(uint8_t timer_num); void HAL_timer_isr_prologue(const uint8_t timer_num);
#endif // _HAL_TIMERS_TEENSY_H #endif // _HAL_TIMERS_TEENSY_H