1 |
hedin |
91 |
#define THIS_IS_STACK_APPLICATION
|
2 |
|
|
|
3 |
|
|
#include "stacktsk.h"
|
4 |
|
|
#include "tick.h"
|
5 |
|
|
#include "delay.h"
|
6 |
hedin |
106 |
#include "network.h"
|
7 |
hedin |
109 |
#include "barcode.h"
|
8 |
hedin |
105 |
#include <string.h>
|
9 |
|
|
|
10 |
hedin |
91 |
|
11 |
|
|
/*
|
12 |
|
|
* This is used by other stack elements.
|
13 |
|
|
* Main application must define this and initialize it with
|
14 |
|
|
* proper values.
|
15 |
|
|
*/
|
16 |
|
|
APP_CONFIG AppConfig;
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
BYTE myDHCPBindCount = 0;
|
20 |
|
|
#if defined(STACK_USE_DHCP)
|
21 |
|
|
extern BYTE DHCPBindCount;
|
22 |
|
|
#else
|
23 |
|
|
/*
|
24 |
|
|
* If DHCP is not enabled, force DHCP update.
|
25 |
|
|
*/
|
26 |
|
|
BYTE DHCPBindCount = 1;
|
27 |
|
|
#endif
|
28 |
|
|
|
29 |
|
|
/*
|
30 |
|
|
* Set configuration fuses for HITECH compiler.
|
31 |
|
|
* For MCC18 compiler, separately linked config.asm file
|
32 |
|
|
* will set the correct fuses.
|
33 |
|
|
*/
|
34 |
|
|
#if defined(HITECH_C18)
|
35 |
|
|
__CONFIG(1, UNPROTECT & HS);
|
36 |
|
|
__CONFIG(2, PWRTEN & BORDIS & WDTDIS);
|
37 |
|
|
#endif
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
/*
|
41 |
|
|
* Private helper functions.
|
42 |
|
|
* These may or may not be present in all applications.
|
43 |
|
|
*/
|
44 |
|
|
static void InitAppConfig(void);
|
45 |
|
|
static void InitializeBoard(void);
|
46 |
|
|
static void SetConfig(void);
|
47 |
|
|
|
48 |
hedin |
96 |
|
49 |
|
|
|
50 |
hedin |
91 |
void main(void)
|
51 |
|
|
{
|
52 |
|
|
// Tick to blink SYSTEM led.
|
53 |
|
|
static TICK t = 0;
|
54 |
hedin |
102 |
|
55 |
hedin |
91 |
|
56 |
hedin |
93 |
TICK tick;
|
57 |
|
|
TICK lastTick;
|
58 |
|
|
TICK diffTicks;
|
59 |
hedin |
91 |
|
60 |
|
|
/*
|
61 |
|
|
* Initialize any application specific hardware.
|
62 |
|
|
*/
|
63 |
|
|
InitializeBoard();
|
64 |
|
|
|
65 |
|
|
/*
|
66 |
|
|
* Initialize all stack related components.
|
67 |
|
|
* Following steps must be performed for all applications using
|
68 |
|
|
* PICmicro TCP/IP Stack.
|
69 |
|
|
*/
|
70 |
|
|
TickInit();
|
71 |
|
|
|
72 |
|
|
/*
|
73 |
|
|
* Initialize Stack and application related NV variables.
|
74 |
|
|
*/
|
75 |
|
|
InitAppConfig();
|
76 |
|
|
|
77 |
|
|
StackInit();
|
78 |
hedin |
96 |
|
79 |
|
|
network_init();
|
80 |
hedin |
91 |
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
/*
|
84 |
|
|
* Once all items are initialized, go into infinite loop and let
|
85 |
|
|
* stack items execute their tasks.
|
86 |
|
|
* If application needs to perform its own task, it should be
|
87 |
|
|
* done at the end of while loop.
|
88 |
|
|
* Note that this is a "co-operative mult-tasking" mechanism
|
89 |
|
|
* where every task performs its tasks (whether all in one shot
|
90 |
|
|
* or part of it) and returns so that other tasks can do their
|
91 |
|
|
* job.
|
92 |
|
|
* If a task needs very long time to do its job, it must broken
|
93 |
|
|
* down into smaller pieces so that other tasks can have CPU time.
|
94 |
|
|
*/
|
95 |
|
|
|
96 |
|
|
|
97 |
hedin |
108 |
// Defines the IP add. on the server machine (rnode is defined in network.h)
|
98 |
hedin |
91 |
rnode.IPAddr.v[0] = 192;
|
99 |
|
|
rnode.IPAddr.v[1] = 168;
|
100 |
|
|
rnode.IPAddr.v[2] = 1;
|
101 |
|
|
rnode.IPAddr.v[3] = 20;
|
102 |
|
|
|
103 |
|
|
while(1)
|
104 |
|
|
{
|
105 |
|
|
/*
|
106 |
|
|
* Blink SYSTEM LED every second.
|
107 |
|
|
*/
|
108 |
|
|
if ( TickGetDiff(TickGet(), t) >= TICK_SECOND/2 )
|
109 |
|
|
{
|
110 |
|
|
t = TickGet();
|
111 |
|
|
LATA4 ^= 1;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
/*
|
115 |
|
|
* This task performs normal stack task including checking
|
116 |
|
|
* for incoming packet, type of packet and calling
|
117 |
|
|
* appropriate stack entity to process it.
|
118 |
|
|
*/
|
119 |
|
|
StackTask();
|
120 |
|
|
|
121 |
|
|
/*
|
122 |
|
|
* For DHCP information, display how many times we have renewed the IP
|
123 |
|
|
* configuration since last reset.
|
124 |
|
|
*/
|
125 |
hedin |
102 |
|
126 |
hedin |
105 |
|
127 |
|
|
network_send_hello( 0x01 );
|
128 |
|
|
|
129 |
|
|
strncpy(global_network_char, "12345678", 8);
|
130 |
|
|
network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8
|
131 |
|
|
|
132 |
|
|
strncpy(global_network_char, "87654444", 8);
|
133 |
|
|
network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8
|
134 |
|
|
|
135 |
|
|
network_send_calc_total();
|
136 |
|
|
|
137 |
|
|
network_send_cash_payed(50000);
|
138 |
|
|
|
139 |
|
|
network_send_cancel_last();
|
140 |
|
|
|
141 |
|
|
network_send_cancel_all();
|
142 |
|
|
|
143 |
|
|
network_send_goodbye();
|
144 |
hedin |
91 |
}
|
145 |
|
|
}
|
146 |
|
|
|
147 |
hedin |
102 |
void interrupt HighISR(void)
|
148 |
hedin |
91 |
{
|
149 |
hedin |
109 |
if (RCIF == 1)
|
150 |
|
|
barcode_interrupt();
|
151 |
|
|
else
|
152 |
|
|
TickUpdate();
|
153 |
hedin |
91 |
}
|
154 |
|
|
|
155 |
|
|
|
156 |
hedin |
106 |
|
157 |
hedin |
91 |
/*********************************************************************
|
158 |
|
|
* Function: void InitializeBoard(void)
|
159 |
|
|
*
|
160 |
|
|
* PreCondition: None
|
161 |
|
|
*
|
162 |
|
|
* Input: None
|
163 |
|
|
*
|
164 |
|
|
* Output: None
|
165 |
|
|
*
|
166 |
|
|
* Side Effects: None
|
167 |
|
|
*
|
168 |
|
|
* Overview: Initialize board specific hardware.
|
169 |
|
|
*
|
170 |
|
|
* Note: None
|
171 |
|
|
********************************************************************/
|
172 |
|
|
static void InitializeBoard(void)
|
173 |
|
|
{
|
174 |
|
|
/*
|
175 |
|
|
* Setup for PORTA.RA0 as analog input while rests
|
176 |
|
|
* as digital i/o lines.
|
177 |
|
|
*/
|
178 |
|
|
ADCON1 = 0b10001110; // RA0 as analog input, Right justified
|
179 |
|
|
TRISA = 0x03;
|
180 |
|
|
|
181 |
|
|
/*
|
182 |
|
|
* LCD is enabled using RA5.
|
183 |
|
|
*/
|
184 |
hedin |
96 |
// PORTA_RA5 = 0; // Disable LCD.
|
185 |
hedin |
91 |
|
186 |
|
|
/*
|
187 |
|
|
* Turn off the LED's.
|
188 |
|
|
*/
|
189 |
|
|
LATA2 = 1;
|
190 |
|
|
LATA3 = 1;
|
191 |
|
|
|
192 |
|
|
/*
|
193 |
|
|
* External data EEPROM needs pull-ups, so enable internal
|
194 |
|
|
* pull-ups.
|
195 |
|
|
*/
|
196 |
|
|
INTCON2_RBPU = 0;
|
197 |
|
|
|
198 |
|
|
T0CON = 0;
|
199 |
|
|
INTCON_GIEH = 1;
|
200 |
|
|
INTCON_GIEL = 1;
|
201 |
|
|
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
/*********************************************************************
|
205 |
|
|
* Function: void InitAppConfig(void)
|
206 |
|
|
*
|
207 |
|
|
* PreCondition: MPFSInit() is already called.
|
208 |
|
|
*
|
209 |
|
|
* Input: None
|
210 |
|
|
*
|
211 |
|
|
* Output: Write/Read non-volatile config variables.
|
212 |
|
|
*
|
213 |
|
|
* Side Effects: None
|
214 |
|
|
*
|
215 |
|
|
* Overview: None
|
216 |
|
|
*
|
217 |
|
|
* Note: None
|
218 |
|
|
********************************************************************/
|
219 |
|
|
static void InitAppConfig(void)
|
220 |
|
|
{
|
221 |
|
|
/*
|
222 |
|
|
* Load default configuration into RAM.
|
223 |
|
|
*/
|
224 |
|
|
AppConfig.MyIPAddr.v[0] = MY_DEFAULT_IP_ADDR_BYTE1;
|
225 |
|
|
AppConfig.MyIPAddr.v[1] = MY_DEFAULT_IP_ADDR_BYTE2;
|
226 |
|
|
AppConfig.MyIPAddr.v[2] = MY_DEFAULT_IP_ADDR_BYTE3;
|
227 |
|
|
AppConfig.MyIPAddr.v[3] = MY_DEFAULT_IP_ADDR_BYTE4;
|
228 |
|
|
|
229 |
|
|
AppConfig.MyMask.v[0] = MY_DEFAULT_MASK_BYTE1;
|
230 |
|
|
AppConfig.MyMask.v[1] = MY_DEFAULT_MASK_BYTE2;
|
231 |
|
|
AppConfig.MyMask.v[2] = MY_DEFAULT_MASK_BYTE3;
|
232 |
|
|
AppConfig.MyMask.v[3] = MY_DEFAULT_MASK_BYTE4;
|
233 |
|
|
|
234 |
|
|
AppConfig.MyGateway.v[0] = MY_DEFAULT_GATE_BYTE1;
|
235 |
|
|
AppConfig.MyGateway.v[1] = MY_DEFAULT_GATE_BYTE2;
|
236 |
|
|
AppConfig.MyGateway.v[2] = MY_DEFAULT_GATE_BYTE3;
|
237 |
|
|
AppConfig.MyGateway.v[3] = MY_DEFAULT_GATE_BYTE4;
|
238 |
|
|
|
239 |
|
|
AppConfig.MyMACAddr.v[0] = MY_DEFAULT_MAC_BYTE1;
|
240 |
|
|
AppConfig.MyMACAddr.v[1] = MY_DEFAULT_MAC_BYTE2;
|
241 |
|
|
AppConfig.MyMACAddr.v[2] = MY_DEFAULT_MAC_BYTE3;
|
242 |
|
|
AppConfig.MyMACAddr.v[3] = MY_DEFAULT_MAC_BYTE4;
|
243 |
|
|
AppConfig.MyMACAddr.v[4] = MY_DEFAULT_MAC_BYTE5;
|
244 |
|
|
AppConfig.MyMACAddr.v[5] = MY_DEFAULT_MAC_BYTE6;
|
245 |
|
|
|
246 |
|
|
#if defined(STACK_USE_DHCP)
|
247 |
|
|
AppConfig.Flags.bIsDHCPEnabled = TRUE;
|
248 |
|
|
#else
|
249 |
|
|
AppConfig.Flags.bIsDHCPEnabled = FALSE;
|
250 |
|
|
#endif
|
251 |
|
|
}
|
252 |
|
|
|
253 |
|
|
BOOL StringToIPAddress(char *str, IP_ADDR *buffer)
|
254 |
|
|
{
|
255 |
|
|
BYTE v;
|
256 |
|
|
char *temp;
|
257 |
|
|
BYTE byteIndex;
|
258 |
|
|
|
259 |
|
|
temp = str;
|
260 |
|
|
byteIndex = 0;
|
261 |
|
|
|
262 |
|
|
while( v = *str )
|
263 |
|
|
{
|
264 |
|
|
if ( v == '.' )
|
265 |
|
|
{
|
266 |
|
|
*str++ = '\0';
|
267 |
|
|
buffer->v[byteIndex++] = atoi(temp);
|
268 |
|
|
temp = str;
|
269 |
|
|
}
|
270 |
|
|
else if ( v < '0' || v > '9' )
|
271 |
|
|
return FALSE;
|
272 |
|
|
|
273 |
|
|
str++;
|
274 |
|
|
}
|
275 |
|
|
|
276 |
|
|
buffer->v[byteIndex] = atoi(temp);
|
277 |
|
|
|
278 |
|
|
return (byteIndex == 3);
|
279 |
|
|
}
|
280 |
|
|
|