-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.c
117 lines (102 loc) · 2.39 KB
/
timer.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* timer.c
*
* Created on: 10.07.2012
*****************************************************************************
* MCmega - Firmware for the Motorola MC micro radio
* to use it as an Amateur-Radio transceiver
*
* Copyright (C) 2013 Felix Erckenbrecht, DG1YFE
*
* ( AVR port of "MC70"
* Copyright (C) 2004 - 2013 Felix Erckenbrecht, DG1YFE)
*
* This file is part of MCmega.
*
* MCmega is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MCmega is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MCmega. If not, see <http://www.gnu.org/licenses/>.
*
****************************************************************************
*/
#include <stdint.h>
#include <stdlib.h>
#include "FreeRTOS.h"
#include "task.h"
#include "macros.h"
#include "regmem.h"
#include "io.h"
#include "menu.h"
#include "subs.h"
#include "int.h"
#include "audio.h"
/*
* Initialisiert Software Timer
*/
void s_timer_init()
{
// do not decrease LCD timer in ISR
int_lcd_timer_dec = 0;
s_tick_ms = tick_ms;
next_hms = 100;
}
/*
* Update of software timers
*/
void s_timer_update()
{
signed int tickdiff;
tickdiff = tick_ms - s_tick_ms;
if(tickdiff)
{
s_tick_ms += tickdiff;
// decrement LCD timer, if timer is >0
if(lcd_timer)
{ // decrement and saturate at 0
lcd_timer = (lcd_timer > tickdiff) ? lcd_timer - tickdiff : 0;
}
if(ui_timer)
{
ui_timer = (ui_timer > tickdiff) ? ui_timer - tickdiff : 0;
}
if(sql_timer)
{
sql_timer = (sql_timer > tickdiff) ? sql_timer - tickdiff : 0;
}
next_hms -= (int8_t) tickdiff;
// decrement 100 ms timer
if(next_hms<=0)
{
next_hms += 100;
tick_hms++;
if(m_timer)
m_timer--;
if(pll_timer)
pll_timer--;
// decrement tone timer if > 0
if(tone_timer)
{
tone_timer--;
// stop tone output if 0 was reached
if(!tone_timer)
{
tone_stop_sel();
ui_ptt_req = 0;
}
}
}
}
}
void wait_ms(unsigned int ticks)
{
vTaskDelay(ticks);
}