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,21 +112,21 @@ extern "C" {
#define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B)
#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
//void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
#define HAL_timer_start (timer_num,frequency)
//void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
#define HAL_timer_start(timer_num,frequency)
//void HAL_timer_set_count (uint8_t timer_num, uint16_t count);
#define HAL_timer_set_count(timer,count) timer = (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_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_STEP_TIMER_ISR ISR(TIMER1_COMPA_vect)
#define HAL_TEMP_TIMER_ISR ISR(TIMER0_COMPB_vect)
#define HAL_ENABLE_ISRs() do { cli(); if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
#define HAL_ENABLE_ISRs() do { cli(); if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
// ADC
#ifdef DIDR2

View File

@ -96,19 +96,19 @@ static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t
// Interrupt handlers for Arduino
#if ENABLED(_useTimer1)
SIGNAL (TIMER1_COMPA_vect) { handle_interrupts(_timer1, &TCNT1, &OCR1A); }
SIGNAL(TIMER1_COMPA_vect) { handle_interrupts(_timer1, &TCNT1, &OCR1A); }
#endif
#if ENABLED(_useTimer3)
SIGNAL (TIMER3_COMPA_vect) { handle_interrupts(_timer3, &TCNT3, &OCR3A); }
SIGNAL(TIMER3_COMPA_vect) { handle_interrupts(_timer3, &TCNT3, &OCR3A); }
#endif
#if ENABLED(_useTimer4)
SIGNAL (TIMER4_COMPA_vect) { handle_interrupts(_timer4, &TCNT4, &OCR4A); }
SIGNAL(TIMER4_COMPA_vect) { handle_interrupts(_timer4, &TCNT4, &OCR4A); }
#endif
#if ENABLED(_useTimer5)
SIGNAL (TIMER5_COMPA_vect) { handle_interrupts(_timer5, &TCNT5, &OCR5A); }
SIGNAL(TIMER5_COMPA_vect) { handle_interrupts(_timer5, &TCNT5, &OCR5A); }
#endif
#else // WIRING

View File

@ -112,7 +112,7 @@ int freeMemory() {
// ADC
// --------------------------------------------------------------------------
void HAL_adc_start_conversion (uint8_t adc_pin) {
void HAL_adc_start_conversion(uint8_t adc_pin) {
HAL_adc_result = analogRead(adc_pin);
}

View File

@ -92,18 +92,18 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
*/
void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
Tc *tc = TimerConfig [timer_num].pTimerRegs;
IRQn_Type irq = TimerConfig [timer_num].IRQ_Id;
uint32_t channel = TimerConfig [timer_num].channel;
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
Tc *tc = TimerConfig[timer_num].pTimerRegs;
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
uint32_t channel = TimerConfig[timer_num].channel;
pmc_set_writeprotect(false);
pmc_enable_periph_clk((uint32_t)irq);
NVIC_SetPriority (irq, TimerConfig [timer_num].priority);
NVIC_SetPriority(irq, TimerConfig [timer_num].priority);
TC_Configure (tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK1);
TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK1);
TC_SetRC(tc, channel, VARIANT_MCK/2/frequency);
TC_SetRC(tc, channel, VARIANT_MCK / 2 / frequency);
TC_Start(tc, channel);
// enable interrupt on RC compare
@ -112,25 +112,25 @@ void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
NVIC_EnableIRQ(irq);
}
void HAL_timer_enable_interrupt (uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig [timer_num];
pConfig->pTimerRegs->TC_CHANNEL [pConfig->channel].TC_IER = TC_IER_CPCS;
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig[timer_num];
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER = TC_IER_CPCS;
}
void HAL_timer_disable_interrupt (uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig [timer_num];
pConfig->pTimerRegs->TC_CHANNEL [pConfig->channel].TC_IDR = TC_IDR_CPCS;
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig[timer_num];
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IDR = TC_IDR_CPCS;
}
#if 0
void HAL_timer_set_count (uint8_t timer_num, uint32_t count) {
const tTimerConfig *pConfig = &TimerConfig [timer_num];
TC_SetRC (pConfig->pTimerRegs, pConfig->channel, count);
void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
const tTimerConfig *pConfig = &TimerConfig[timer_num];
TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count);
}
void HAL_timer_isr_prologue (uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig [timer_num];
TC_GetStatus (pConfig->pTimerRegs, pConfig->channel);
void HAL_timer_isr_prologue(const uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig[timer_num];
TC_GetStatus(pConfig->pTimerRegs, pConfig->channel);
}
#endif

View File

@ -53,14 +53,14 @@
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
#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 ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_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 DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_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 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_TEMP_TIMER_ISR void TC4_Handler()
@ -85,29 +85,29 @@ extern const tTimerConfig TimerConfig[];
// 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];
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];
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];
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
}
void HAL_timer_enable_interrupt(uint8_t timer_num);
void HAL_timer_disable_interrupt(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 (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];
// Reading the status register clears the interrupt flag
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_SR;

View File

@ -32,62 +32,53 @@
#include "HAL_timers.h"
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_SC->PCONP |= (0x1 << 0x2); // power on timer1
SBI(LPC_SC->PCONP, 2); // power on timer1
LPC_TIM1->PR = ((HAL_TIMER_RATE / 1000000) - 1);
}
void HAL_timer_start(uint8_t timer_num, uint32_t frequency) {
switch(timer_num) {
case 0:
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->TCR = (1 << 0); // enable
break;
case 1:
LPC_TIM1->MCR = 3;
LPC_TIM1->MR0 = (uint32_t)(HAL_TEMP_TIMER_RATE / frequency);;
LPC_TIM1->TCR = (1 << 0);
break;
default:
return;
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
switch (timer_num) {
case 0:
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->TCR = _BV(0); // enable
break;
case 1:
LPC_TIM1->MCR = 3;
LPC_TIM1->MR0 = (uint32_t)(HAL_TEMP_TIMER_RATE / frequency);;
LPC_TIM1->TCR = _BV(0);
break;
default: break;
}
}
void HAL_timer_enable_interrupt (uint8_t timer_num) {
switch(timer_num) {
case 0:
NVIC_EnableIRQ(TIMER0_IRQn); // Enable interrupt handler
NVIC_SetPriority(TIMER0_IRQn, NVIC_EncodePriority(0, 1, 0));
break;
case 1:
NVIC_EnableIRQ(TIMER1_IRQn);
NVIC_SetPriority(TIMER1_IRQn, NVIC_EncodePriority(0, 2, 0));
break;
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
case 0:
NVIC_EnableIRQ(TIMER0_IRQn); // Enable interrupt handler
NVIC_SetPriority(TIMER0_IRQn, NVIC_EncodePriority(0, 1, 0));
break;
case 1:
NVIC_EnableIRQ(TIMER1_IRQn);
NVIC_SetPriority(TIMER1_IRQn, NVIC_EncodePriority(0, 2, 0));
break;
}
}
void HAL_timer_disable_interrupt (uint8_t timer_num) {
switch(timer_num) {
case 0:
NVIC_DisableIRQ(TIMER0_IRQn); // disable interrupt handler
break;
case 1:
NVIC_DisableIRQ(TIMER1_IRQn);
break;
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
case 0: NVIC_DisableIRQ(TIMER0_IRQn); break; // disable interrupt handler
case 1: NVIC_DisableIRQ(TIMER1_IRQn); break;
}
}
void HAL_timer_isr_prologue (uint8_t timer_num) {
switch(timer_num) {
case 0:
LPC_TIM0->IR |= 1; //Clear the Interrupt
break;
case 1:
LPC_TIM1->IR |= 1;
break;
void HAL_timer_isr_prologue(const uint8_t timer_num) {
switch (timer_num) {
case 0: SBI(LPC_TIM0->IR, 0); break; // Clear the Interrupt
case 1: SBI(LPC_TIM1->IR, 0); break;
}
}

View File

@ -53,14 +53,13 @@
#define HAL_TEMP_TIMER_RATE 1000000
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
#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 ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_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 DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_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 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_TEMP_TIMER_ISR extern "C" void TIMER1_IRQHandler(void)
@ -75,47 +74,34 @@
// --------------------------------------------------------------------------
// Public functions
// --------------------------------------------------------------------------
void HAL_timer_init (void);
void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
void HAL_timer_init(void);
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) {
switch(timer_num) {
case 0:
LPC_TIM0->MR0 = count;
break;
case 1:
LPC_TIM1->MR0 = count;
break;
default:
return;
static FORCE_INLINE void HAL_timer_set_count(const uint8_t timer_num, const HAL_TIMER_TYPE count) {
switch (timer_num) {
case 0: LPC_TIM0->MR0 = count; break;
case 1: LPC_TIM1->MR0 = count; break;
}
}
static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count (uint8_t timer_num) {
switch(timer_num) {
case 0:
return LPC_TIM0->MR0;
case 1:
return LPC_TIM1->MR0;
default:
return 0;
static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count(const uint8_t timer_num) {
switch (timer_num) {
case 0: return LPC_TIM0->MR0;
case 1: return LPC_TIM1->MR0;
}
return 0;
}
static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_current_count(uint8_t timer_num) {
switch(timer_num) {
case 0:
return LPC_TIM0->TC;
case 1:
return LPC_TIM1->TC;
default:
return 0;
static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_current_count(const uint8_t timer_num) {
switch (timer_num) {
case 0: return LPC_TIM0->TC;
case 1: return LPC_TIM1->TC;
}
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

View File

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

View File

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

View File

@ -23,7 +23,6 @@
* Description: HAL for Teensy 3.5 and Teensy 3.6
*/
#ifndef _HAL_TEENSY_H
#define _HAL_TEENSY_H
@ -64,8 +63,6 @@
#define HAL_SERVO_LIB libServo
//#define _BV(bit) (1 << (bit))
#ifndef analogInputToDigitalPin
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
#endif
@ -73,7 +70,6 @@
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
#define CRITICAL_SECTION_END SREG = _sreg;
// On AVR this is in math.h?
#define square(x) ((x)*(x))
@ -96,12 +92,12 @@
#define RST_BACKUP 64
/** clear reset reason */
void HAL_clear_reset_source (void);
void HAL_clear_reset_source(void);
/** 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" {
int freeMemory(void);
@ -124,21 +120,21 @@ void HAL_adc_init();
#define HAL_ANALOG_SELECT(pin) NOOP;
void HAL_adc_start_conversion (uint8_t adc_pin);
void HAL_adc_start_conversion(uint8_t adc_pin);
uint16_t HAL_adc_get_result(void);
/*
uint16_t HAL_getAdcReading(uint8_t chan);
uint16_t HAL_getAdcReading(uint8_t chan);
void HAL_startAdcConversion(uint8_t chan);
uint8_t HAL_pinToAdcChannel(int pin);
void HAL_startAdcConversion(uint8_t chan);
uint8_t HAL_pinToAdcChannel(int pin);
uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
//uint16_t HAL_getAdcSuperSample(uint8_t chan);
uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
//uint16_t HAL_getAdcSuperSample(uint8_t chan);
void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan);
void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan);
*/
// --------------------------------------------------------------------------
@ -146,4 +142,3 @@ void HAL_enable_AdcFreerun(void);
// --------------------------------------------------------------------------
#endif // _HAL_TEENSY_H

View File

@ -30,65 +30,55 @@
#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) {
case 0:
FTM0_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN;
FTM0_SC = 0x00; // Set this to zero before changing the modulus
FTM0_CNT = 0x0000; // Reset the count to zero
FTM0_MOD = 0xFFFF; // max modulus = 65535
FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value
FTM0_SC = (FTM_SC_CLKS(0b1)&FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS)&FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8
FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
break;
case 1:
FTM1_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN; // Disable write protection, Enable FTM1
FTM1_SC = 0x00; // Set this to zero before changing the modulus
FTM1_CNT = 0x0000; // Reset the count to zero
FTM1_MOD = 0xFFFF; // max modulus = 65535
FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535
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;
break;
default:
break;
case 0:
FTM0_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN;
FTM0_SC = 0x00; // Set this to zero before changing the modulus
FTM0_CNT = 0x0000; // Reset the count to zero
FTM0_MOD = 0xFFFF; // max modulus = 65535
FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value
FTM0_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8
FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
break;
case 1:
FTM1_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN; // Disable write protection, Enable FTM1
FTM1_SC = 0x00; // Set this to zero before changing the modulus
FTM1_CNT = 0x0000; // Reset the count to zero
FTM1_MOD = 0xFFFF; // max modulus = 65535
FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535
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;
break;
}
}
void HAL_timer_enable_interrupt (uint8_t timer_num)
{
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
switch(timer_num) {
case 0: NVIC_ENABLE_IRQ(IRQ_FTM0); break;
case 1: NVIC_ENABLE_IRQ(IRQ_FTM1); break;
default:
break;
case 0: NVIC_ENABLE_IRQ(IRQ_FTM0); break;
case 1: NVIC_ENABLE_IRQ(IRQ_FTM1); break;
}
}
void HAL_timer_disable_interrupt (uint8_t timer_num)
{
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
case 0: NVIC_DISABLE_IRQ(IRQ_FTM0); break;
case 1: NVIC_DISABLE_IRQ(IRQ_FTM1); break;
default:
break;
case 0: NVIC_DISABLE_IRQ(IRQ_FTM0); break;
case 1: NVIC_DISABLE_IRQ(IRQ_FTM1); break;
}
}
void HAL_timer_isr_prologue(uint8_t timer_num) {
void HAL_timer_isr_prologue(const uint8_t timer_num) {
switch(timer_num) {
case 0:
FTM0_CNT = 0x0000;
FTM0_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
FTM0_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
break;
case 1:
FTM1_CNT = 0x0000;
FTM1_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
FTM1_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
break;
default:
break;
case 0:
FTM0_CNT = 0x0000;
FTM0_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
FTM0_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
break;
case 1:
FTM1_CNT = 0x0000;
FTM1_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
FTM1_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
break;
}
}

View File

@ -52,8 +52,8 @@
#define FTM0_TIMER_PRESCALE_BITS 0b011
#define FTM1_TIMER_PRESCALE_BITS 0b010
#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 FTM0_TIMER_RATE (F_BUS / FTM0_TIMER_PRESCALE) // 60MHz / 8 = 7500kHz
#define FTM1_TIMER_RATE (F_BUS / FTM1_TIMER_PRESCALE) // 60MHz / 4 = 15MHz
#define STEPPER_TIMER STEP_TIMER_NUM // Alias?
#define STEPPER_TIMER_PRESCALE 0 // Not defined anywhere else!
@ -64,46 +64,45 @@
#define TEMP_TIMER_FREQUENCY 1000
#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 ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt (TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt (TEMP_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 ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
#define HAL_STEP_TIMER_ISR extern "C" void ftm0_isr(void) //void TC3_Handler()
#define HAL_TEMP_TIMER_ISR extern "C" void ftm1_isr(void) //void TC4_Handler()
#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) {
case 0: FTM0_C0V = count; break;
case 1: FTM1_C0V = count; break;
default: break;
case 0: FTM0_C0V = count; break;
case 1: FTM1_C0V = count; 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) {
case 0: return FTM0_C0V;
case 1: return FTM1_C0V;
default: return 0;
case 0: return FTM0_C0V;
case 1: return FTM1_C0V;
}
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) {
case 0: return FTM0_CNT;
case 1: return FTM1_CNT;
default: return 0;
case 0: return FTM0_CNT;
case 1: return FTM1_CNT;
}
return 0;
}
void HAL_timer_enable_interrupt (uint8_t timer_num);
void HAL_timer_disable_interrupt (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(uint8_t timer_num);
void HAL_timer_isr_prologue(const uint8_t timer_num);
#endif // _HAL_TIMERS_TEENSY_H

View File

@ -1155,7 +1155,7 @@ void Stepper::init() {
TCNT1 = 0;
#else
// Init Stepper ISR to 122 Hz for quick starting
HAL_timer_start (STEP_TIMER_NUM, 122);
HAL_timer_start(STEP_TIMER_NUM, 122);
#endif
ENABLE_STEPPER_DRIVER_INTERRUPT();

View File

@ -1081,8 +1081,8 @@ void Temperature::init() {
OCR0B = 128;
SBI(TIMSK0, OCIE0B);
#else
HAL_timer_start (TEMP_TIMER_NUM, TEMP_TIMER_FREQUENCY);
HAL_timer_enable_interrupt (TEMP_TIMER_NUM);
HAL_timer_start(TEMP_TIMER_NUM, TEMP_TIMER_FREQUENCY);
HAL_timer_enable_interrupt(TEMP_TIMER_NUM);
#endif
#if HAS_AUTO_FAN_0
@ -1594,7 +1594,7 @@ void Temperature::set_current_temp_raw() {
* - For ENDSTOP_INTERRUPTS_FEATURE check endstops if flagged
*/
HAL_TEMP_TIMER_ISR {
HAL_timer_isr_prologue (TEMP_TIMER_NUM);
HAL_timer_isr_prologue(TEMP_TIMER_NUM);
Temperature::isr();
}