From 95910b32fa2a4b43f8ab9a0c0c0bdb8d2560bb6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Tue, 15 Oct 2013 13:20:49 +0200 Subject: [PATCH] task scheduler and handlers implemented (basics) --- src/main.c | 138 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 108 insertions(+), 30 deletions(-) diff --git a/src/main.c b/src/main.c index ef17547..4a80470 100644 --- a/src/main.c +++ b/src/main.c @@ -18,19 +18,33 @@ volatile uint8_t input_i = 0; /* user input index */ volatile uint8_t pwr_ok; /* is power ok */ volatile uint8_t fan; /* fan signal state, to measure tachometer */ volatile uint8_t timer2_ovf = 0; /* to measure fan speed using timer 2 */ -static const uint16_t TIMER2_PRESCALE[8] = {0,1,8,32,64,128,256,1024}; /* timer 2 CS2[2:0] values */ +uint16_t TIMER2_PRESCALE[8] = {0,1,8,32,64,128,256,1024}; /* timer 2 CS2[2:0] values */ volatile uint16_t tachometer = 0; /* the tachometer time (from timer) */ volatile uint8_t ir; /* IR signal state, to measure IR code */ -static const uint16_t TIMER1_PRESCALE[8] = {0,1,8,64,256,1024,0,0}; /* timer 1 CS1[2:0] values */ +uint16_t TIMER1_PRESCALE[8] = {0,1,8,64,256,1024,0,0}; /* timer 1 CS1[2:0] values */ volatile uint16_t ir_tick; /* number of counter ticks per millisecond */ volatile uint8_t pulse = 0; /* pulse index within the burst */ #define PULSE_MAX 128 /* maximum number of pulses to save */ uint16_t burst[PULSE_MAX]; /* pulse times forming a burst (from timer) */ +/* channel variables */ +#define LEVELS 10 /* the number of PWM levels */ +uint8_t ch_tick = 0; /* the tick counter for the channel PWM */ +#define OUTPUTS_1 5 /* the number of outputs for channel 1 */ +#define OUTPUTS_2 5 /* the number of outputs for channel 2 */ +volatile uint8_t* PORTS_1[OUTPUTS_1] = {&PORTC,&PORTC,&PORTC,&PORTC,&PORTC}; /* channel 1 output ports */ +volatile uint8_t* PORTS_2[OUTPUTS_2] = {&PORTD,&PORTD,&PORTD,&PORTD,&PORTD}; /* channel 2 output ports */ +uint8_t BITS_1[OUTPUTS_1] = {PC0,PC1,PC2,PC3,PC4}; /* channel 1 output bits */ +uint8_t BITS_2[OUTPUTS_2] = {PD2,PD3,PD4,PD5,PD7}; /* channel 2 output bits */ +uint8_t ch_1[OUTPUTS_1]; /* the level value for the channel 1 outputs */ +uint8_t ch_2[OUTPUTS_2]; /* the level value for the channel 2 outputs */ + /* flags, set in the interrupts and handled in the main program */ -volatile bool input_flag = false; -volatile bool power_flag = false; -volatile bool ir_flag = false; +volatile bool uart_flag = false; /* an incoming activity on the UART */ +volatile bool power_flag = false; /* a change in the power or fan */ +volatile bool ir_flag = false; /* to process a burst */ +volatile bool pwm_flag = false; /* to trigger a PWM tick */ +volatile bool channel_flag = false; /* indicate a change in the channel PWM values */ /* UART receive interrupt */ ISR(USART_RX_vect) { @@ -39,7 +53,7 @@ ISR(USART_RX_vect) { if (input_i