Statistics
| Branch: | Tag: | Revision:

root / tidsense / tidsense.c @ 172:8c8328364b9d

History | View | Annotate | Download (1.6 kB)

1
#include <config.h>
2
3
#include <avr/io.h>
4
#include <avr/interrupt.h>
5
#include <avr/sleep.h>
6
#include <util/delay.h>
7
8
#include <string.h>
9
#include <stdlib.h>
10
11
#include "debug.h"
12
#include "sysclock.h"
13
#include "board.h"
14
#include "sensors.h"
15
#include "nv.h"
16
#include "audio.h"
17
#include "node.h"
18
#include "network.h"
19
#include "command.h"
20
#include "ota.h"
21
#include "assoc.h"
22
#include "event.h"
23
#include "scheduler.h"
24
25
#include <sys.h>
26
27
#include "tidsense.h"
28
29
bool receive_flag = false;
30
31
void app_watchdog_task(void *data) {
32
    if(!receive_flag) {
33
        app_reboot();
34
    }
35
    receive_flag = false;
36
}
37
38
void app_reboot(void) {
39
    CCP = CCP_IOREG_gc;
40
    RST.CTRL = RST_SWRST_bm;
41
}
42
43
void app_handle_ack(uint8_t ack_status) {
44
    //debugf("ack: %d\n", ack_status);
45
    switch(ack_status) {
46
        case ACK_SLEEP: break;
47
        case ACK_IDLE: sched_set_awake_timer(10); break;
48
        case ACK_RESET: app_reboot(); break;
49
    }
50
    receive_flag = true;
51
}   
52
53
void app_handle_error(uint8_t error) {
54
    
55
}
56
57
static inline void setup(void) {
58
    sysclock_setup();
59
    nv_setup();
60
    
61
    sched_setup();
62
    board_setup();
63
    network_setup();
64
    command_setup();
65
    ota_setup();
66
            
67
    //audio_setup();
68
69
    if(nv_has_feature(FEATURE_REPEATER)) {
70
        sched_enable_sleep(false);
71
    }
72
73
    assoc_setup();
74
    event_setup();
75
    event_create(EVENT_RESET, RST.STATUS, EVENT_INFO);
76
    sched_task_create(app_watchdog_task, NULL, 86400, 0, SCHED_ENABLED);
77
}
78
79
80
static inline void loop(void) {
81
    sched_main();
82
    SYS_TaskHandler();
83
}
84
85
int main(void) {
86
    setup();
87
    for(;;) loop();
88
    return 1;
89
}
90