-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_rtos.c
316 lines (234 loc) · 6.43 KB
/
main_rtos.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/****************************************************************************
*
* Copyright (C) 2014, Jon Magnuson <my.name at google's mail service>
* All Rights Reserved.
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
****************************************************************************/
/* Standard includes. */
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
/* Platform includes. */
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/udma.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
/* FreeRTOS kernel includes. */
#include "FreeRTOS.h"
#include "semphr.h"
#include "task.h"
/* Application includes. */
#include "third_party/fatfs/src/ff.h"
#include "third_party/fatfs/src/diskio.h"
#include "sd_util.h"
#define RED_LED GPIO_PIN_1
#define BLUE_LED GPIO_PIN_2
#define GREEN_LED GPIO_PIN_3
#if 0 &&/*defined(ccs) || */defined ( __TMS470__ )
#include "arm_atomic.h"
#endif
/* Size of memcpy buffer */
#define MEM_BUFFER_SIZE 1024
typedef struct TaskParameters_t
{
SemaphoreHandle_t *pcSemaphores;
SD_Struct *sdParams;
uint32_t buffer[MEM_BUFFER_SIZE]; // dst buffer
} TaskParameters;
/* Application task prototypes. */
void prvProducerTask(void *pvParameters);
void prvConsumerTask(void *pvParameters);
void prvWriteTask(void *pvParameters);
/* FreeRTOS function/hook prototypes. */
void vApplicationMallocFailedHook(void);
void vApplicationIdleHook(void);
void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName);
void vApplicationTickHook(void);
static void
ConfigureUART0(void)
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(0, 115200, 16000000);
}
static void
ConfigureuDMA()
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
ROM_uDMAEnable();
//ROM_uDMAControlBaseSet(ui8ControlTable);
}
static void
ConfigureSPI(void)
{
// all this happens in power_on()...
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_SSI0);
}
void ConfigureLED()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RED_LED | BLUE_LED | GREEN_LED);
}
static SemaphoreHandle_t isrSemaphore;
static void set_udma_txfer_done(int status)
{
if (status == 0)
{
/* Success */
xSemaphoreGive(isrSemaphore);
}
else
{
/* Failed */
while (1)
{}
}
}
int main_rtos(void)
{
/* Variable declarations */
static TaskParameters taskParams = {NULL, NULL, NULL};
static SemaphoreHandle_t pcSemaphores[2] = {NULL, NULL};
static SD_Struct sd_params = {
NULL,
NULL,
NULL,
NULL,
"/",
"00000.log"
};
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
ConfigureLED();
ConfigureUART0();
ConfigureuDMA();
ConfigureSPI();
pcSemaphores[0] = xSemaphoreCreateBinary();
pcSemaphores[1] = xSemaphoreCreateBinary();
taskParams.pcSemaphores = &pcSemaphores[0];
if (pcSemaphores[0] == NULL || pcSemaphores[1] == NULL)
{
return 1;
}
static uint32_t task_result = NULL;
if (task_result =
xTaskCreate(
prvWriteTask,
(portCHAR *) "prvWriteTask",
configMINIMAL_STACK_SIZE,
(void *) &taskParams,
(tskIDLE_PRIORITY + 1),
NULL
)
!= pdTRUE)
{
/* Task not created. Stop here for debug. */
while (1)
{}
}
vTaskStartScheduler();
for (;;)
{}
return 0;
}
void prvWriteTask(void *pvParameters)
{
static SD_Struct sd_params = {
NULL,
NULL,
NULL,
NULL,
"00000.log",
"/"
};
unsigned char *file_write_buffer = (uint32_t *) (((TaskParameters *) pvParameters)->buffer);
uint32_t i = 0;
unsigned short bytesWritten = 0;
FRESULT fresult = FR_OK;
for (; i < DATA_BUFFER_SIZE_DIV2; i++)
{
file_write_buffer[i] = (unsigned char) (i & 0xFF);
}
if ((fresult = ConfigureSD(&sd_params)) != FR_OK)
{
while (1)
{}
}
fresult = f_write(&sd_params.g_sFileObject, file_write_buffer, MEM_BUFFER_SIZE, &bytesWritten);
if (fresult != FR_OK)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);
while (1)
{}
}
f_sync(&sd_params.g_sFileObject);
f_close(&sd_params.g_sFileObject);
f_mount(0, NULL);
while (1)
{
vTaskDelay(500 / portTICK_RATE_MS);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, ~ROM_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1));
}
}
/*-----------------------------------------------------------*/
void vApplicationMallocFailedHook(void)
{
}
/*-----------------------------------------------------------*/
void vApplicationIdleHook(void)
{
static unsigned int led_once = 1;
if (led_once)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, (GPIO_PIN_2));
led_once = 0;
}Nop();
}
/*-----------------------------------------------------------*/
void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName)
{
(void) pcTaskName;
(void) pxTask;
}
/*-----------------------------------------------------------*/
void vApplicationTickHook(void)
{
static unsigned int fatfs_timer = 10;
fatfs_timer--;
if (fatfs_timer == 0)
{
disk_timerproc();
fatfs_timer = 10;
}
}
/*-----------------------------------------------------------*/
void vAssertCalled(unsigned long ulLine, const char *const pcFileName)
{
}