forked from promovicz/rtos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
231 lines (174 loc) · 4.88 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
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
/*
LPCUSB, an USB device driver for LPC microcontrollers
Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Minimal implementation of a USB serial port, using the CDC class.
This example application simply echoes everything it receives right back
to the host.
Windows:
Extract the usbser.sys file from .cab file in C:\WINDOWS\Driver Cache\i386
and store it somewhere (C:\temp is a good place) along with the usbser.inf
file. Then plug in the LPC214x and direct windows to the usbser driver.
Windows then creates an extra COMx port that you can open in a terminal
program, like hyperterminal.
Linux:
The device should be recognised automatically by the cdc_acm driver,
which creates a /dev/ttyACMx device file that acts just like a regular
serial port.
*/
#include <string.h>
#include <stdio.h>
#include <sys/ucontext.h>
#include <core/defines.h>
#include <core/tty.h>
#include <core/cli.h>
#include <core/timer.h>
#include <core/system.h>
#include <board/logomatic/board.h>
#include <platform/lpc21/vic.h>
#include <platform/lpc21/pll.h>
#include <platform/lpc21/ssp.h>
#include <platform/lpc21/eint.h>
#include <platform/lpc21/uart.h>
#include <platform/lpc21/gpio.h>
#include <platform/lpc21/timer.h>
#include <platform/lpc21/pinsel.h>
#include <platform/lpc21/spi.h>
#include <platform/lpc21/wdt.h>
#include <posix/control.h>
#include "serial_fifo.h"
#include <sensor/scp.h>
#include <sensor/nmea.h>
#include <sys/mman.h>
#define INTV_STOP 0
#define INTV_USB 1
#define INTV_UART0 2
#define INTV_UART1 3
#define INTV_TIMER0 4
#define INTV_TIMER1 5
#define INTV_SCP_DRDY 6
#define CE_NRF 25
#define CSEL_NRF 28
#define CSEL_SCP 20
#define CSEL_MMC 29
void csel_scp(bool_t yeah)
{
gpio_pin_set(CSEL_SCP, yeah ? 0 : 1);
}
void csel_mmc(bool_t yeah)
{
gpio_pin_set(CSEL_MMC, yeah ? 0 : 1);
}
static interrupt_handler void DefIntHandler(void)
{
vic_ack();
}
static interrupt_handler void USBIntHandler(void)
{
USBHwISR();
vic_ack();
}
int icount[2];
int consirq = 0;
struct tty tser;
struct cli c;
int u0 = -1, u1 = -1;
int hit = 0;
int bang = 0;
ucontext_t ou;
ucontext_t nmea_context;
uint8_t nmea_stack[1024];
void nmea_main (void)
{
char buf[64];
int r;
nmea_init();
while(1) {
r = read(u0, &buf, sizeof(buf));
if(r > 0) {
nmea_process(&buf[0], r);
}
swapcontext(&nmea_context, &ou);
}
}
ucontext_t rimu_context;
uint8_t rimu_stack[1024];
void rimu_main (void)
{
uint8_t buf[64];
int r;
{
uint8_t cmd_raw = '4';
write(u1, &cmd_raw, 1);
}
while(1) {
r = read(u1, &buf, sizeof(buf));
if(r > 0) {
}
swapcontext(&rimu_context, &ou);
}
}
void rimu_proc_init (void)
{
rimu_context.uc_stack.ss_sp = &rimu_stack;
rimu_context.uc_stack.ss_size = sizeof(rimu_stack);
rimu_context.uc_link = NULL;
makecontext(&rimu_context, &rimu_main, 0);
}
void nmea_proc_init (void)
{
nmea_context.uc_stack.ss_sp = &nmea_stack;
nmea_context.uc_stack.ss_size = sizeof(nmea_stack);
nmea_context.uc_link = NULL;
makecontext(&nmea_context, &nmea_main, 0);
}
int main (void)
{
system_init();
device_open("vcom", O_RDONLY);
device_open("vcom", O_WRONLY);
device_open("vcom", O_WRONLY);
tty_init(&tser);
cli_init(&c, &tser);
u0 = device_open("uart0", O_RDWR);
u1 = device_open("uart1", O_RDWR);
nmea_proc_init();
rimu_proc_init();
int i;
uint8_t chr;
char buf[64];
int res;
while (1) {
system_kick();
if(read(0, &chr, 1)) {
tty_feed(&tser, chr);
}
fflush(stdout);
swapcontext(&ou, &nmea_context);
fflush(stdout);
swapcontext(&ou, &rimu_context);
fflush(stdout);
system_idle();
}
return 0;
}