-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
201 lines (165 loc) · 5.74 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/****************************************************************************
*
* Copyright (c) 2017, Michael Becker ([email protected])
*
* This file is part of the FreeRTOS Add-ons project.
*
* Source Code:
* https://github.com/michaelbecker/freertos-addons
*
* Project Page:
* http://michaelbecker.github.io/freertos-addons/
*
* On-line Documentation:
* http://michaelbecker.github.io/freertos-addons/docs/html/index.html
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so,subject to the
* following conditions:
*
* + The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* + Credit is appreciated, but not required, if you find this project
* useful enough to include in your application, product, device, etc.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
***************************************************************************/
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "SIM/GUI.h"
#include "SIM/HAL.h"
#include "SIM/SoC.h"
/**
* Specify a struct to send information to different threads.
*/
struct thread_parameters {
int id;
int sleep_period;
};
void PORT_A_ISR(void) {
NVIC_IntClear(NVIC_PORTA_IRQ_NUM);
printf("IRQ 1\n");
}
void PORT_B_ISR(void) {
NVIC_IntClear(NVIC_PORTB_IRQ_NUM);
printf("IRQ 2\n");
}
int cmp = 0;
/**
* For this example, we only create one task function and
* pass it in slightly different parameters to change how it
* runs.
*
* In the real world, there is almost always a single one-to-one
* correspondence between a task function and a task. Most embedded
* systems don't run multiple copies of a task.
*/
void example_thread(void *parameters) {
struct thread_parameters *my_parameters;
my_parameters = (struct thread_parameters*) parameters;
printf("Thread #%d starting...\n", my_parameters->id);
GPIO_IntEnable (BUTTON_1_PORT, BUTTON_1_PIN);
GPIO_IntEnable (BUTTON_2_PORT, BUTTON_2_PIN);
GPIO_PinCfg(LED_1_PORT, LED_1_PIN, true);
GPIO_PinCfg(LED_2_PORT, LED_2_PIN, true);
GPIO_PinSet(LED_1_PORT, LED_1_PIN);
GPIO_PinSet(LED_2_PORT, LED_2_PIN);
while (1) {
vTaskDelay(my_parameters->sleep_period);
printf("Thread #%d running\n", my_parameters->id);
if (my_parameters->id == 1) {
GPIO_PinToggle(LED_1_PORT, LED_1_PIN);
GPIO_IntDisable(LED_1_PORT, LED_1_PIN);
} else if (my_parameters->id == 2) {
GPIO_PinToggle(LED_2_PORT, LED_2_PIN);
HAL_Trace('A');
TIMER_PrescalerSet(8);
TIMER_SetTOP(8000);
TIMER_SetCMP(cmp);
cmp = cmp + 1000;
if (cmp > 8000) {
cmp = 0;
}
} else if (my_parameters->id == 3) {
}
}
configASSERT(!"CANNOT EXIT FROM A TASK");
}
int main(void) {
BaseType_t rc;
const uint16_t stack_depth = 1000;
/**
* We are passing pointers to these structs for the tasks to use.
* Note that the storage for these is actually on the main() stack.
* Usually this is a "bad" idea, passing pointers from one task
* callstack to another task, however in this case we know that
* main() will effectively be blocked forever unless we actually
* choose to exit from FreeRTOS, so as long as we aren't too clever
* and try and reclaim this stack memory, this works ok.
*/
struct thread_parameters p1 = { 1, 1000 };
struct thread_parameters p2 = { 2, 2009 };
struct thread_parameters p3 = { 3, 3017 };
printf("Simple test for FreeRTOS Linux port.\n");
/* Create GUI */
gui_create();
SoC_Init();
rc = xTaskCreate(example_thread, "Task1", stack_depth, &p1, 1, NULL);
/**
* Make sure out task was created.
*/
configASSERT(rc == pdPASS);
rc = xTaskCreate(example_thread, "Task2", stack_depth, &p2, 2, NULL);
/**
* Make sure out task was created.
*/
configASSERT(rc == pdPASS);
rc = xTaskCreate(example_thread, "Task3", stack_depth, &p3, 3, NULL);
/**
* Make sure out task was created.
*/
configASSERT(rc == pdPASS);
TIMER_PrescalerSet(8);
TIMER_SetTOP(8000);
TIMER_SetCMP(7000);
/**
* Start FreeRTOS here.
*/
vTaskStartScheduler();
/**
* We shouldn't ever get here unless someone calls
* vTaskEndScheduler(). Note that there appears to be a
* bug in the Linux FreeRTOS simulator that crashes when
* this is called.
*/
printf("Scheduler ended!\n");
return 0;
}
void vAssertCalled(unsigned long ulLine, const char *const pcFileName) {
printf("ASSERT: %s : %d\n", pcFileName, (int) ulLine);
while (1)
;
}
unsigned long ulGetRunTimeCounterValue(void) {
return 0;
}
void vConfigureTimerForRunTimeStats(void) {
return;
}
void vApplicationMallocFailedHook(void) {
printf("Malloc Failed!!!\n");
while (1)
;
}