-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmain.c
110 lines (87 loc) · 2.45 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
#define USE_STDPERIPH_DRIVER
#include "stm32f10x.h"
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include <string.h>
/* Filesystem includes */
#include "filesystem.h"
#include "fio.h"
extern const char _sromfs;
static void setup_hardware();
volatile xSemaphoreHandle serial_tx_wait_sem = NULL;
/* IRQ handler to handle USART2 interruptss (both transmit and receive
* interrupts). */
void USART2_IRQHandler()
{
static signed portBASE_TYPE xHigherPriorityTaskWoken;
/* If this interrupt is for a transmit... */
if (USART_GetITStatus(USART2, USART_IT_TXE) != RESET) {
/* "give" the serial_tx_wait_sem semaphore to notfiy processes
* that the buffer has a spot free for the next byte.
*/
xSemaphoreGiveFromISR(serial_tx_wait_sem, &xHigherPriorityTaskWoken);
/* Diables the transmit interrupt. */
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
/* If this interrupt is for a receive... */
}
else {
/* Only transmit and receive interrupts should be enabled.
* If this is another type of interrupt, freeze.
*/
while(1);
}
if (xHigherPriorityTaskWoken) {
taskYIELD();
}
}
void send_byte(char ch)
{
/* Wait until the RS232 port can receive another byte (this semaphore
* is "given" by the RS232 port interrupt when the buffer has room for
* another byte.
*/
while (!xSemaphoreTake(serial_tx_wait_sem, portMAX_DELAY));
/* Send the byte and enable the transmit interrupt (it is disabled by
* the interrupt).
*/
USART_SendData(USART2, ch);
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
}
void read_romfs_task(void *pvParameters)
{
char buf[128];
size_t count;
int fd = fs_open("/romfs/test.txt", 0, O_RDONLY);
do {
//Read from /romfs/test.txt to buffer
count = fio_read(fd, buf, sizeof(buf));
//Write buffer to fd 1 (stdout, through uart)
fio_write(1, buf, count);
} while (count);
while (1);
}
int main()
{
init_rs232();
enable_rs232_interrupts();
enable_rs232();
fs_init();
fio_init();
register_romfs("romfs", &_sromfs);
/* Create the queue used by the serial task. Messages for write to
* the RS232. */
vSemaphoreCreateBinary(serial_tx_wait_sem);
/* Create a task to output text read from romfs. */
xTaskCreate(read_romfs_task,
(signed portCHAR *) "Read romfs",
512 /* stack size */, NULL, tskIDLE_PRIORITY + 2, NULL);
/* Start running the tasks. */
vTaskStartScheduler();
return 0;
}
void vApplicationTickHook()
{
}