-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
103 lines (80 loc) · 1.99 KB
/
main.cpp
File metadata and controls
103 lines (80 loc) · 1.99 KB
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
/*
*/
#include <avr/io.h>
#include <avr/builtins.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <util/delay.h>
#include "timer1.h"
#include "discr_io.h"
#include "uart0.h"
#include "command.h"
#include <scmRTOS.h>
#include "alarm.h"
typedef OS::process<OS::pr1, 500> TCommandTask;
TCommandTask CommandTask;
OS::channel<TAlarmMessage, ALARM_MSG_BOX_CAPACITY> AlarmMessageBox;
//îáúÿâëÿåì ïðîöåññ îáðàáîòêè àëàðìîâ
typedef OS::process<OS::pr0, 500> TAlarmTask;
TAlarmTask AlarmTask;
namespace OS
{
template<> OS_PROCESS void TAlarmTask::exec()
{
for(;;)
{
TAlarmMessage msg;
//òóò ìû óñíåì äî ïîëó÷åíèÿ àâàðèéíîãî ñîîáùåíèÿ
AlarmMessageBox.pop(msg);
//ïîëó÷èëè ñîîáùåíèå, òåïåðü îáðàáîòàåì åãî
if (TAlarmMessage::DI_ALARAM == msg.src)
{
if (msg.state == 1)
printf_P(PSTR("\r\nAlarm: raised\r\n"));
else
printf_P(PSTR("\r\nAlarm: failed\r\n"));
}
}
}// TAlarmTask::exec()
}// namespace OS
namespace OS
{
template<> OS_PROCESS void TCommandTask::exec()
{
for(;;)
{
process_command();
}
}//TCommandTask::exec()
}// namespace OS
void user_timer_ISR()
{
discr_io_ISR();
}
void init_hw()
{
//îòêëþ÷àåì ïðåðûâàíèÿ êîíòðîëëåðà äëÿ ñïîêîéíîé íàñòðîéêè ïåðèôåðèè
__builtin_avr_cli();
MCUCR |= ( 1 << IVCE );
MCUCR &= ~(( 1 << IVSEL ) | (1 << IVCE)); // ... 2.Within four cycles, write the desired value to IVSEL while writing a zero to IVCE.
TIMER0_CS_REG = (1 << CS01) | (1 << CS00); // clk/64
UNLOCK_SYSTEM_TIMER();
//íàñòðàèâàåì îáðàáîòêó âõîäíûõ ñèãíàëîâ êîíòðîëëåðîì
init_discr_io();
//èíèöèàëèçèðóåì òàéìåð
timer1_init();
//íàñòðîéêà UART0
init_uart0();
//âêëþ÷àåì ïðåðûâàíèÿ êîíòðîëëåðà
//__builtin_avr_sei();
}
OS_PROCESS int main(void)
{
//íàñòðàèâàåì æåëåçî
init_hw();
printf_P(PSTR("\r\nStarted...\r\n"));
OS::run();
}