-
Notifications
You must be signed in to change notification settings - Fork 18
/
sch.c
59 lines (48 loc) · 1.64 KB
/
sch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Task scheduler to execute tasks at a cyclic predefined time */
#include "sch.h"
#include <stdint.h>
#include <avr/io.h>
#include "adm.h"
#include "uib.h"
#include "uif.h"
/* Timer 1 Config Register Configuration */
/* 16,5 Mhz /16384 = 1007 Hz, it's almost 1kHz so it's fine */
#define sch_cfg_r TCCR1
#define sch_CTC (0x00u) /* [7] Clear timer/counter on compare match */
#define sch_PWM (0x00u) /* [6] Pulse width modulator enable (disabled) */
#define sch_CP (0x00u) /* [5:4] Comparator output, (disconnected from OC1A) */
#define sch_PR (0x0Fu) /* [3:0] CS13:10 = 0x0F */
/* Timer 1 Control Register */
#define sch_ctrl_r GTCCR
#define sch_value (0x00u) /* [7:0] Default value, all features disabled */
/* Timer 1 Counter Register */
#define sch_timer TCNT1
uint8_t sch_lastTimerVal;
uint8_t sch_tick; /* incremented each 1ms */
/* Private Functions */
static void sch_Task_10ms(void){
ADM_Task();
UIB_Task();
UIF_Task(); /* UIF must be called in the same task as UIB task or higher period */
}
/* Public Functions */
/* Here configure the timer to be used */
void SCH_Init(void){
sch_cfg_r = (sch_CTC) | (sch_PWM) | (sch_CP) | (sch_PR);
sch_ctrl_r = (sch_value);
sch_lastTimerVal = 0u;
sch_tick = 0u; /* incremented each 1ms */
}
/* Cyclic Task where the different tasks are executed */
void SCH_Task(void){
uint8_t sch_timer_temp = sch_timer;
if(sch_lastTimerVal != sch_timer_temp)
{
sch_tick++;
sch_lastTimerVal = sch_timer_temp;
if( (sch_tick % 10) == 0 )
{
sch_Task_10ms();
}
}
}