forked from microbuilder/LPC1343CodeBase
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
246 lines (210 loc) · 6.14 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/**************************************************************************/
/*!
@file main.c
@author K. Townsend (microBuilder.eu)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2011, microBuilder SARL
All rights reserved.
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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.
*/
/**************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "projectconfig.h"
#include "sysinit.h"
#include "core/uart/uart.h"
#include "core/gpio/gpio.h"
#include "core/systick/systick.h"
#ifdef CFG_INTERFACE
#include "core/cmd/cmd.h"
#endif
#include "core/usbcdc/cdcuser.h"
/*
* Pin connection:
*
* DB25 GPIO Dir Name
* 1 1.1 in -Strobe
* 2 2.0 in Data0
* 3 2.1 in Data1
* 4 2.2 in Data2
* 5 2.3 in Data3
* 6 2.4 in Data4
* 7 2.5 in Data5
* 8 2.6 in Data6
* 9 2.7 in Data7
* 10 0.11 out -Ack 'd'
* 11 0.10 out Busy 'c'
* 12 0.9 out PaperEnd 'b'
* 13 0.8 out SelectStatus 'a'
* 14 3.0 in AutoFeed
* 15 3.1 out -Error 'e'
* 16 3.2 in -Initialize
* 17 3.3 in -Select
* 18-25 - - GND
*/
static void
sts(void)
{
int j, i;
char s[64];
j = 0;
s[j++] = 's';
s[j++] = '0' + gpioGetValue(1, 1);
s[j++] = ' ';
for (i = 7; i >- 0; i--)
s[j++] = '0' + gpioGetValue(2, i);
s[j++] = ' ';
s[j++] = 'a';
s[j++] = '0' + gpioGetValue(3, 0);
s[j++] = ' ';
s[j++] = 'i';
s[j++] = '0' + gpioGetValue(3, 2);
s[j++] = ' ';
s[j++] = 's';
s[j++] = '0' + gpioGetValue(3, 3);
s[j++] = ' ';
s[j++] = ' ';
s[j++] = 's';
s[j++] = '0' + gpioGetValue(0, 8);
s[j++] = ' ';
s[j++] = 'p';
s[j++] = '0' + gpioGetValue(0, 9);
s[j++] = ' ';
s[j++] = 'b';
s[j++] = '0' + gpioGetValue(0, 10);
s[j++] = ' ';
s[j++] = 'a';
s[j++] = '0' + gpioGetValue(0, 11);
s[j++] = ' ';
s[j++] = 'e';
s[j++] = '0' + gpioGetValue(3, 1);
s[j++] = '\0';
puts(s);
puts("\r\n");
}
static int8_t got_prn;
void
PIOINT1_IRQHandler(void)
{
int i;
i = gpioIntStatus(1, 1);
if (i) {
gpioSetValue(0,10,1);
got_prn = GPIO_GPIO2DATA;
gpioIntClear(1, 1);
}
}
static void
prt(void)
{
int i, j;
printf("\r\nHello World\r\n");
gpioSetDir(1, 1, gpioDirection_Input);
for (i = 0; i < 8; i++)
gpioSetDir(2, i, gpioDirection_Input);
gpioSetDir(0, 8, gpioDirection_Output);
gpioSetDir(0, 9, gpioDirection_Output);
gpioSetDir(0, 10, gpioDirection_Output);
IOCON_JTAG_TCK_PIO0_10 = 0
| IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO
| IOCON_JTAG_TDI_PIO0_11_ADMODE_DIGITAL;
IOCON_JTAG_TDI_PIO0_11 = 0
| IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO
| IOCON_JTAG_TDI_PIO0_11_ADMODE_DIGITAL;
gpioSetDir(0, 11, gpioDirection_Output);
gpioSetDir(3, 0, gpioDirection_Input);
gpioSetDir(3, 1, gpioDirection_Output);
gpioSetDir(3, 2, gpioDirection_Input);
gpioSetDir(3, 3, gpioDirection_Input);
gpioSetInterrupt(1, // Port
1, // Pin
gpioInterruptSense_Edge, // Edge/Level Sensitive
gpioInterruptEdge_Single, // Single/Double Edge
gpioInterruptEvent_ActiveLow); // Rising/Falling
gpioIntEnable(1, 1);
gpioSetValue(0,11,1);
gpioSetValue(0,10,0);
gpioSetValue(0,9,0);
while (1) {
j = CDC_getchar();
switch (j) {
case 's': gpioSetValue(0,8,0); sts(); break;
case 'S': gpioSetValue(0,8,1); sts(); break;
case 'p': gpioSetValue(0,9,0); sts(); break;
case 'P': gpioSetValue(0,9,1); sts(); break;
case 'b': gpioSetValue(0,10,0); sts(); break;
case 'B': gpioSetValue(0,10,1); sts(); break;
case 'a': gpioSetValue(0,11,0); sts(); break;
case 'A': gpioSetValue(0,11,1); sts(); break;
case 'e': gpioSetValue(3,1,0); sts(); break;
case 'E': gpioSetValue(3,1,1); sts(); break;
case 'x':
while (1)
CDC_putchar('x');
break;
case '?':
sts();
break;
}
if (gpioGetValue(0, 10)) {
CDC_putchar(got_prn);
for (j = 0; j < 2; j++)
gpioSetValue(0,11,0);
gpioSetValue(0,11,1);
gpioSetValue(0,10,0);
}
}
}
/**************************************************************************/
/*!
Main program entry point. After reset, normal code execution will
begin here.
*/
/**************************************************************************/
int
main(void)
{
// Configure cpu and mandatory peripherals
systemInit();
uint32_t currentSecond, lastSecond;
currentSecond = lastSecond = 0;
// uartInit(115200);
prt();
while (1)
{
// Toggle LED once per second
currentSecond = systickGetSecondsActive();
if (currentSecond != lastSecond)
{
lastSecond = currentSecond;
gpioSetValue(CFG_LED_PORT, CFG_LED_PIN, !(gpioGetValue(CFG_LED_PORT, CFG_LED_PIN)));
uartSendByte('*');
}
// Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h
#ifdef CFG_INTERFACE
cmdPoll();
#endif
}
return 0;
}