-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
117 lines (105 loc) · 3.61 KB
/
main.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
117
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include "eeprom.h"
#include "main.h"
#include "menu.h"
#include "rtc.h"
#include "vcp.h"
/* Äëÿ ïîäñ÷åòà âðåìåíè è òàéìàóòîâ */
static int sys_tick_ms = 0;
static void hw_init_all(void);
static void all_task_error(void);
/**
* Çàïóñêàåì âñå çàäà÷è, â òîì ÷èñëå è îæèäàþùèå
*/
int main(void)
{
hw_init_all();
led_create_task();
rtc_create_task(); /* Çàäà÷à äëÿ RTC - ìîæíî áóäåò ïåðåíåñòè â Idle èëè äðóãîå ìåñòî */
menu_create_task(); /* Èíèöèàëèçàöèÿ çàäà÷è äëÿ ìåíþ è êëàâèàòóðû */
sensor_create_task(); /* Èíèöèàëèçàöèÿ çàäà÷è äëÿ ñåíñîðîâ */
#if 1
vcp_create_task(); /* Âèðòóàëüíûé êîì ïîðò - ïîêà îáû÷íûé COM ïîðò */
#else
com_create_task(); /* Âèðòóàëüíûé êîì ïîðò - ïîêà îáû÷íûé COM ïîðò */
#endif
vTaskStartScheduler(); /* Òåïåðü âûçûâàåì ñòàðò ïëàíèðîâùèêà */
all_task_error(); /* Åñëè ó íàñ áóäåò ïðîáëåìà ñî ñòåêîì âî âðåìÿ çàïóñêà-ïîïàäåì ñþäà */
return 0;
}
/**
* Íàñòðàèâàåì ïåðèôåðèþ
*/
static void hw_init_all(void)
{
status_init_first();
timer2_init();
eeprom_init(); /* Init eeprom - ïðè ïðàâèëüíîì ÷òåíèè ñðàçó óáðàòü ñòàòóñ "íåò êîíñòàíò" */
}
/**
* Ìîðãàåì âñåìè ëàìïàìè
*/
static void all_task_error(void)
{
while (1) {
led_toggle(LED3);
led_toggle(LED4);
led_toggle(LED5);
led_toggle(LED6);
for (volatile int i = 0; i < 0x80000; i++);
}
}
/* Decrement the TimingDelay variable */
void vApplicationTickHook(void)
{
sys_tick_ms++;
KeypadScan();
}
/* vApplicationMallocFailedHook() will only be called if
* configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
* function that will get called if a call to pvPortMalloc() fails.
* pvPortMalloc() is called internally by the kernel whenever a task, queue,
* timer or semaphore is created. It is also called by various parts of the
* demo application. If heap_1.c or heap_2.c are used, then the size of the
* heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
* FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
* to query the size of free heap space that remains (although it does not
* provide information on how the remaining heap might be fragmented). */
void vApplicationMallocFailedHook(void)
{
taskDISABLE_INTERRUPTS();
for (;;);
}
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
* to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
* task. It is essential that code added to this hook function never attempts
* to block in any way (for example, call xQueueReceive() with a block time
* specified, or call vTaskDelay()). If the application makes use of the
* vTaskDelete() API function (as this demo application does) then it is also
* important that vApplicationIdleHook() is permitted to return to its calling
* function, because it is the responsibility of the idle task to clean up
* memory allocated by the kernel to any task that has since been deleted. */
void vApplicationIdleHook(void)
{
}
/* Run time stack overflow checking is performed if
* configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
* function is called if a stack overflow is detected.
*/
void vApplicationStackOverflowHook(xTaskHandle pxTask, signed char *pcTaskName)
{
(void) pcTaskName;
(void) pxTask;
taskDISABLE_INTERRUPTS();
for (;;);
}
/**
* ×èñëî ìèëëèñåêóíä
*/
int get_sys_ticks(void)
{
return sys_tick_ms;
}