/[H8]/trunk/PIC/Demo trimmet/TFTPcDemo.c
ViewVC logotype

Annotation of /trunk/PIC/Demo trimmet/TFTPcDemo.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 106 - (hide annotations) (download)
Mon May 28 08:26:29 2007 UTC (16 years, 11 months ago) by hedin
File MIME type: text/plain
File size: 6711 byte(s)
Refactored network module to seperate files.

Done some cleanup in the main module

(Done by Torben)
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 91
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     // Defines the IP add. on the server machine
98     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     TickUpdate();
150     }
151    
152    
153 hedin 106
154 hedin 91 /*********************************************************************
155     * Function: void InitializeBoard(void)
156     *
157     * PreCondition: None
158     *
159     * Input: None
160     *
161     * Output: None
162     *
163     * Side Effects: None
164     *
165     * Overview: Initialize board specific hardware.
166     *
167     * Note: None
168     ********************************************************************/
169     static void InitializeBoard(void)
170     {
171     /*
172     * Setup for PORTA.RA0 as analog input while rests
173     * as digital i/o lines.
174     */
175     ADCON1 = 0b10001110; // RA0 as analog input, Right justified
176     TRISA = 0x03;
177    
178     /*
179     * LCD is enabled using RA5.
180     */
181 hedin 96 // PORTA_RA5 = 0; // Disable LCD.
182 hedin 91
183     /*
184     * Turn off the LED's.
185     */
186     LATA2 = 1;
187     LATA3 = 1;
188    
189     /*
190     * External data EEPROM needs pull-ups, so enable internal
191     * pull-ups.
192     */
193     INTCON2_RBPU = 0;
194    
195     T0CON = 0;
196     INTCON_GIEH = 1;
197     INTCON_GIEL = 1;
198    
199     }
200    
201     /*********************************************************************
202     * Function: void InitAppConfig(void)
203     *
204     * PreCondition: MPFSInit() is already called.
205     *
206     * Input: None
207     *
208     * Output: Write/Read non-volatile config variables.
209     *
210     * Side Effects: None
211     *
212     * Overview: None
213     *
214     * Note: None
215     ********************************************************************/
216     static void InitAppConfig(void)
217     {
218     /*
219     * Load default configuration into RAM.
220     */
221     AppConfig.MyIPAddr.v[0] = MY_DEFAULT_IP_ADDR_BYTE1;
222     AppConfig.MyIPAddr.v[1] = MY_DEFAULT_IP_ADDR_BYTE2;
223     AppConfig.MyIPAddr.v[2] = MY_DEFAULT_IP_ADDR_BYTE3;
224     AppConfig.MyIPAddr.v[3] = MY_DEFAULT_IP_ADDR_BYTE4;
225    
226     AppConfig.MyMask.v[0] = MY_DEFAULT_MASK_BYTE1;
227     AppConfig.MyMask.v[1] = MY_DEFAULT_MASK_BYTE2;
228     AppConfig.MyMask.v[2] = MY_DEFAULT_MASK_BYTE3;
229     AppConfig.MyMask.v[3] = MY_DEFAULT_MASK_BYTE4;
230    
231     AppConfig.MyGateway.v[0] = MY_DEFAULT_GATE_BYTE1;
232     AppConfig.MyGateway.v[1] = MY_DEFAULT_GATE_BYTE2;
233     AppConfig.MyGateway.v[2] = MY_DEFAULT_GATE_BYTE3;
234     AppConfig.MyGateway.v[3] = MY_DEFAULT_GATE_BYTE4;
235    
236     AppConfig.MyMACAddr.v[0] = MY_DEFAULT_MAC_BYTE1;
237     AppConfig.MyMACAddr.v[1] = MY_DEFAULT_MAC_BYTE2;
238     AppConfig.MyMACAddr.v[2] = MY_DEFAULT_MAC_BYTE3;
239     AppConfig.MyMACAddr.v[3] = MY_DEFAULT_MAC_BYTE4;
240     AppConfig.MyMACAddr.v[4] = MY_DEFAULT_MAC_BYTE5;
241     AppConfig.MyMACAddr.v[5] = MY_DEFAULT_MAC_BYTE6;
242    
243     #if defined(STACK_USE_DHCP)
244     AppConfig.Flags.bIsDHCPEnabled = TRUE;
245     #else
246     AppConfig.Flags.bIsDHCPEnabled = FALSE;
247     #endif
248     }
249    
250     BOOL StringToIPAddress(char *str, IP_ADDR *buffer)
251     {
252     BYTE v;
253     char *temp;
254     BYTE byteIndex;
255    
256     temp = str;
257     byteIndex = 0;
258    
259     while( v = *str )
260     {
261     if ( v == '.' )
262     {
263     *str++ = '\0';
264     buffer->v[byteIndex++] = atoi(temp);
265     temp = str;
266     }
267     else if ( v < '0' || v > '9' )
268     return FALSE;
269    
270     str++;
271     }
272    
273     buffer->v[byteIndex] = atoi(temp);
274    
275     return (byteIndex == 3);
276     }
277    

  ViewVC Help
Powered by ViewVC 1.1.20