mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 10:24:26 +01:00
Outsourced timer and external interupt initialization
Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
parent
133a8729ac
commit
7b659a832e
@ -16,11 +16,30 @@
|
|||||||
static volatile enum {LOCKED, UNLOCKED} state = LOCKED;
|
static volatile enum {LOCKED, UNLOCKED} state = LOCKED;
|
||||||
static volatile bool schnapper = false;
|
static volatile bool schnapper = false;
|
||||||
|
|
||||||
|
static inline void timer_init(void)
|
||||||
|
{
|
||||||
|
// Config the timer
|
||||||
|
// The 16bit Timer1 is used for resetting the lock state,
|
||||||
|
// if the UART stops receiving the unlock command
|
||||||
|
TIMSK |= (1<<TOIE1);
|
||||||
|
TIFR |= (1<<TOV1);
|
||||||
|
TCCR1A = 0;
|
||||||
|
TCCR1B = (1<<CS12);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void reset_timeout(void)
|
static inline void reset_timeout(void)
|
||||||
{
|
{
|
||||||
TCNT1 = 0;
|
TCNT1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void extint_init(void)
|
||||||
|
{
|
||||||
|
// Configure external interrupts
|
||||||
|
// External interrupts are used for Button Unlock an Lock
|
||||||
|
MCUCR = (1<<ISC11)|(1<<ISC01);
|
||||||
|
GIMSK |= (1<<INT0)|(1<<INT1);
|
||||||
|
}
|
||||||
|
|
||||||
void uart_handler(const unsigned char c)
|
void uart_handler(const unsigned char c)
|
||||||
{
|
{
|
||||||
char retval = c;
|
char retval = c;
|
||||||
@ -105,29 +124,26 @@ out:
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
// Disable all interrupts
|
||||||
cli();
|
cli();
|
||||||
|
// Init IO
|
||||||
io_init();
|
io_init();
|
||||||
|
|
||||||
// Wait a bit to settle down
|
// Wait a bit to settle down
|
||||||
_delay_ms(1000);
|
_delay_ms(1000);
|
||||||
|
|
||||||
|
// Init Uart
|
||||||
uart_init();
|
uart_init();
|
||||||
uart_set_recv_handler(uart_handler);
|
uart_set_recv_handler(uart_handler);
|
||||||
|
|
||||||
// Config the timer
|
// Init Timer
|
||||||
// The 16bit Timer1 is used for resetting the lock state,
|
timer_init();
|
||||||
// if the UART stops receiving the unlock command
|
|
||||||
TIMSK |= (1<<TOIE1);
|
|
||||||
TIFR |= (1<<TOV1);
|
|
||||||
TCCR1A = 0;
|
|
||||||
TCCR1B = (1<<CS12);
|
|
||||||
|
|
||||||
reset_timeout();
|
reset_timeout();
|
||||||
|
|
||||||
// Configure external interrupts
|
// Init external interrupts
|
||||||
// External interrupts are used for Button Unlock an Lock
|
extint_init();
|
||||||
MCUCR = (1<<ISC11)|(1<<ISC01);
|
|
||||||
GIMSK |= (1<<INT0)|(1<<INT1);
|
|
||||||
|
|
||||||
|
// Enable all interrupts
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
Loading…
Reference in New Issue
Block a user