--- trunk/PIC/Demo trimmet/TFTPcDemo.c 2007/05/16 09:24:33 92 +++ trunk/PIC/Demo trimmet/TFTPcDemo.c 2007/05/25 16:00:14 102 @@ -1,92 +1,25 @@ -/********************************************************************* - * - * TFTP Client Demo App for Microchip TCP/IP Stack - * - ********************************************************************* - * FileName: TFTPcDemo.c - * Dependencies: tftpc.h - * stacktsk.h - * xlcd.h - * tick.h - * Processor: PIC18 - * Complier: MCC18 v1.00.50 or higher - * HITECH PICC-18 V8.10PL1 or higher - * Company: Microchip Technology, Inc. - * - * Software License Agreement - * - * The software supplied herewith by Microchip Technology Incorporated - * (the “Company”) for its PICmicro® Microcontroller is intended and - * supplied to you, the Company’s customer, for use solely and - * exclusively on Microchip PICmicro Microcontroller products. The - * software is owned by the Company and/or its supplier, and is - * protected under applicable copyright laws. All rights are reserved. - * Any use in violation of the foregoing restrictions may subject the - * user to criminal sanctions under applicable laws, as well as to - * civil liability for the breach of the terms and conditions of this - * license. - * - * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, - * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED - * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, - * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR - * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. - * - * Author Date Comment - *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * Nilesh Rajbharti 8/7/03 Original (Rev 1.0) - * - * - * This demo application demonstartes Microchip TFTP client module usage - * See TFTPDemo(), TFTPWrite() and TFTPRead() for actual implementation. - * - * This application monitors RB5 switch. On first push it - * writes 'tftpwr.bin' file to server. tftpwr.bin file is made up of - * first 16KB of program memory. - * On second push, it reads 'tftprd.txt' file from server. - * - * Server IP address is set in "Board Setup" mode using Hyperterminal. - * - * It displays rotating '-' to indicate command in progress. - * 'Y' to indicate success - * 'N' for failure - * 'T' for timeout - * 'E' for error. - * - * - * If running this applicaton on PICDEM.net use - * HS Oscillator - * Debug disabled - * Low Voltage Disabled - * Watchdog timer disabled - ********************************************************************/ -/* - * Following define uniquely deines this file as main - * entry/application In whole project, there should only be one such - * definition and application file must define AppConfig variable as - * described below. - */ #define THIS_IS_STACK_APPLICATION #include "stacktsk.h" #include "dhcp.h" -#include "xlcd.h" #include "tick.h" #include "delay.h" #include "udp.h" #include "arp.h" #include "arptsk.h" +#include "tcp.h" +bit bIsDhcpUp = 0; +char netlevel = 0; // All TFTP command statuts display will be done on first line of LCD. -#define TFTP_COMMAND_DISPLAY_LINE 0 +//#define TFTP_COMMAND_DISPLAY_LINE 0 // Result will be displayed at y = 15. #define TFTP_COMMAND_RESULT_POSITION 15 -#define STARTUP_MSG "G1_Build_0x00" +/*#define STARTUP_MSG "G1_Build_0x00" ROM char StartupMsg[] = STARTUP_MSG; @@ -97,8 +30,8 @@ ROM char SetupMsg[] = "Board Setup..."; // 1234567890123456 -ROM char blankLCDLine[] = " "; - +//ROM char blankLCDLine[] = " "; +*/ /* * This is used by other stack elements. * Main application must define this and initialize it with @@ -134,19 +67,200 @@ */ static void InitAppConfig(void); static void InitializeBoard(void); -static void DisplayIPValue(IP_ADDR *IPVal, BOOL bToLCD); static void SetConfig(void); +/***************************** + Enummerations + ****************************/ +typedef enum _NetworkState +{ + off, + DhcpIsBound, + ArpIsTxReady, + ArpIsResolved, + SockOpening, + SockOpen, + TcpReadyToSend, + TcpSend, + HelloDone, + StregkodeDone, + SockClosing, + SockClosed +} NetworkState; + +/***************************** + GLOBAL INIT + ****************************/ +NODE_INFO rnode; +NetworkState state; +TCP_SOCKET tsock1; + + +/***************************** + network funktions + ****************************/ +int net_INT = 13, i; +char *net_CHAR = "1234567890123"; + + +void network_init(void) +{ + state = off; +} + + +void network_worker(void) +{ + TickGet(); + StackTask(); +} + +void network_wait(unsigned char n) +{ + int i; + for (i=0; i0) - { - UDPPut( rnode.MACAddr.v[0] ); - UDPPut( rnode.MACAddr.v[1] ); - UDPPut( rnode.MACAddr.v[2] ); - UDPPut( rnode.MACAddr.v[3] ); - UDPPut( rnode.MACAddr.v[4] ); - UDPPut( rnode.MACAddr.v[5] ); - UDPPut('D'); - UDPPut('a'); - UDPPut('w'); - UDPPut(0); - UDPFlush(); - datagrams_to_send--; - } - } + a = network_send_hello( 0x01 ); + a = network_send_scan_frame( stregkode, antal ); + a = network_send_goodbye(); } } -#if defined(MCHP_C18) - #pragma interrupt HighISR save=section(".tmpdata") - void HighISR(void) -#elif defined(HITECH_C18) - #if defined(STACK_USE_SLIP) - extern void MACISR(void); - #endif - void interrupt HighISR(void) -#endif +void interrupt HighISR(void) { TickUpdate(); -/* -#if defined(STACK_USE_SLIP) - MACISR(); -#endif -*/ } #if defined(MCHP_C18) @@ -326,51 +350,6 @@ #pragma code /* return to default code section */ #endif -static void DisplayIPValue(IP_ADDR *IPVal, BOOL bToLCD) -{ - char IPDigit[8]; - - if ( bToLCD ) - { - /* - * Erase second line. - */ - XLCDGoto(1, 0); - XLCDPutROMString(blankLCDLine); - - } - - /* - * Rewrite the second line. - */ - XLCDGoto(1, 0); - - itoa(IPVal->v[0], IPDigit); - if ( bToLCD ) - { - XLCDPutString(IPDigit); - XLCDPut('.'); - } - - itoa(IPVal->v[1], IPDigit); - if ( bToLCD ) - { - XLCDPutString(IPDigit); - XLCDPut('.'); - } - - itoa(IPVal->v[2], IPDigit); - if ( bToLCD ) - { - XLCDPutString(IPDigit); - XLCDPut('.'); - } - - itoa(IPVal->v[3], IPDigit); - if ( bToLCD ) - XLCDPutString(IPDigit); -} - /********************************************************************* * Function: void InitializeBoard(void) * @@ -398,7 +377,7 @@ /* * LCD is enabled using RA5. */ - PORTA_RA5 = 0; // Disable LCD. +// PORTA_RA5 = 0; // Disable LCD. /* * Turn off the LED's. @@ -412,10 +391,6 @@ */ INTCON2_RBPU = 0; - XLCDInit(); - XLCDGoto(0, 0); - XLCDPutROMString(StartupMsg); - T0CON = 0; INTCON_GIEH = 1; INTCON_GIEL = 1; @@ -499,21 +474,3 @@ return (byteIndex == 3); } - -void XLCDDelay15ms(void) -{ - DelayMs(15); -} -void XLCDDelay4ms(void) -{ - DelayMs(4); -} - -void XLCDDelay100us(void) -{ - INTCON_GIEH = 0; - Delay10us(1); - INTCON_GIEH = 1; -} - -