1 |
hedin |
15 |
/*********************************************************************
|
2 |
|
|
*
|
3 |
|
|
* Reboot Module
|
4 |
|
|
* Module for Microchip TCP/IP Stack
|
5 |
|
|
* -Remotely resets the PIC
|
6 |
|
|
* -Reference: None yet. Hopefully AN833 in the future.
|
7 |
|
|
*
|
8 |
|
|
*********************************************************************
|
9 |
|
|
* FileName: Reboot.c
|
10 |
|
|
* Dependencies: TCPIP.h
|
11 |
|
|
* Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F
|
12 |
|
|
* Complier: Microchip C18 v3.10 or higher
|
13 |
|
|
* Microchip C30 v2.04 or higher
|
14 |
|
|
* Company: Microchip Technology, Inc.
|
15 |
|
|
*
|
16 |
|
|
* Software License Agreement
|
17 |
|
|
*
|
18 |
|
|
* Copyright © 2002-2007 Microchip Technology Inc. All rights
|
19 |
|
|
* reserved.
|
20 |
|
|
*
|
21 |
|
|
* Microchip licenses to you the right to use, modify, copy, and
|
22 |
|
|
* distribute:
|
23 |
|
|
* (i) the Software when embedded on a Microchip microcontroller or
|
24 |
|
|
* digital signal controller product (“Device”) which is
|
25 |
|
|
* integrated into Licensee’s product; or
|
26 |
|
|
* (ii) ONLY the Software driver source files ENC28J60.c and
|
27 |
|
|
* ENC28J60.h ported to a non-Microchip device used in
|
28 |
|
|
* conjunction with a Microchip ethernet controller for the
|
29 |
|
|
* sole purpose of interfacing with the ethernet controller.
|
30 |
|
|
*
|
31 |
|
|
* You should refer to the license agreement accompanying this
|
32 |
|
|
* Software for additional information regarding your rights and
|
33 |
|
|
* obligations.
|
34 |
|
|
*
|
35 |
|
|
* THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT
|
36 |
|
|
* WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
|
37 |
|
|
* LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
|
38 |
|
|
* PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
39 |
|
|
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
40 |
|
|
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
|
41 |
|
|
* PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
|
42 |
|
|
* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
|
43 |
|
|
* THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
|
44 |
|
|
* SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
|
45 |
|
|
* (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
|
46 |
|
|
*
|
47 |
|
|
*
|
48 |
|
|
* Author Date Comment
|
49 |
|
|
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
50 |
|
|
* Howard Schlunder 02/22/07 Original
|
51 |
|
|
********************************************************************/
|
52 |
|
|
#define __REBOOT_C
|
53 |
|
|
|
54 |
|
|
#include "TCPIP Stack/TCPIP.h"
|
55 |
|
|
#if defined(STACK_USE_REBOOT_SERVER)
|
56 |
|
|
|
57 |
|
|
#define REBOOT_PORT 30304 //UDP
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
/*********************************************************************
|
61 |
|
|
* Function: void RebootTask(void)
|
62 |
|
|
*
|
63 |
|
|
* PreCondition: Stack is initialized()
|
64 |
|
|
*
|
65 |
|
|
* Input: None
|
66 |
|
|
*
|
67 |
|
|
* Output: None
|
68 |
|
|
*
|
69 |
|
|
* Side Effects: None
|
70 |
|
|
*
|
71 |
|
|
* Overview: Checks for incomming traffic on port 30304.
|
72 |
|
|
* Resets the PIC if a 'R' is received.
|
73 |
|
|
*
|
74 |
|
|
* Note: This module is primarily for use with the
|
75 |
|
|
* Ethernet bootloader. By resetting, the Ethernet
|
76 |
|
|
* bootloader can take control for a second and let
|
77 |
|
|
* a firmware upgrade take place.
|
78 |
|
|
********************************************************************/
|
79 |
|
|
void RebootTask(void)
|
80 |
|
|
{
|
81 |
|
|
static UDP_SOCKET MySocket = INVALID_UDP_SOCKET;
|
82 |
|
|
BYTE i;
|
83 |
|
|
|
84 |
|
|
if(MySocket == INVALID_UDP_SOCKET)
|
85 |
|
|
MySocket = UDPOpen(REBOOT_PORT, NULL, INVALID_UDP_PORT);
|
86 |
|
|
|
87 |
|
|
if(MySocket == INVALID_UDP_SOCKET)
|
88 |
|
|
return;
|
89 |
|
|
|
90 |
|
|
// Do nothing if no data is waiting
|
91 |
|
|
if(!UDPIsGetReady(MySocket))
|
92 |
|
|
return;
|
93 |
|
|
|
94 |
|
|
// See if this is a valid packet specifing that we should reboot
|
95 |
|
|
UDPGet(&i);
|
96 |
|
|
if(i != 0x00)
|
97 |
|
|
return;
|
98 |
|
|
|
99 |
|
|
Reset();
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
#endif //#if defined(STACK_USE_REBOOT_SERVER)
|