diff --git a/src/main.c b/src/main.c index 549d82f..dd4b4fa 100644 --- a/src/main.c +++ b/src/main.c @@ -10,22 +10,37 @@ #include "uart.h" /* global variables */ -volatile uint8_t pwr_ok; -volatile uint8_t fan; -volatile uint16_t tachometer = 0; -volatile uint8_t timer2_ovf = 0; +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 */ +volatile uint16_t tachometer = 0; /* the tachometer time (from timer) */ +volatile uint8_t ir; /* IR signal state, to measure IR code */ +volatile uint8_t pulse_i = 1; /* pulse index */ +# define PULSE_MAX 64 /* maximum number of pulses to save */ +volatile uint16_t pulse[PULSE_MAX]; /* pulse times (from timer) */ -const uint16_t TIMER2_PRESCALE[8] = {0,1,8,32,64,128,256,1024}; -/* PWR_OK interrupt */ +/* power ok interrupt */ ISR(PCINT0_vect) { /* PCI0 Interrupt Vector for PCINT[7:0] */ if (pwr_ok!=(PINB&(1<0) { /* save pulse, except the first */ + pulse[pulse_i-1] = TCNT1; + pulse[pulse_i] = 0; + } + if (pulse_i0) { + pulse_i = 0; + OCR0A = ~OCR0A; } } @@ -59,9 +82,21 @@ static void ioinit(void) PCICR |= (1<0) { OCR0A--; } - printf("decreasing LED: %d\n",OCR0A); + printf("decreasing LED: %u\n",OCR0A); break; case '+': if (OCR0A<0xff) { OCR0A++; } - printf("increasing LED: %d\n",OCR0A); + printf("increasing LED: %u\n",OCR0A); break; case 't': if (tachometer) { uint16_t prescale = TIMER2_PRESCALE[TCCR2B&((1<