00001 /*----------------------------------------------------------------------------*/ 00012 /*----------------------------------------------------------------------------*/ 00013 00014 #include <Environment.h> 00015 #include <string.h> 00016 #include <flash_memory.h> 00017 #include <timedef.h> 00018 #include <display_info.h> 00019 #include <stdlib.h> 00020 #include <cc2420.h> 00021 #include <hal_wait.h> 00022 #include <serial.h> 00023 #include <controller.h> 00024 00025 //############################################################################# 00026 // USER DEFINE 00027 //############################################################################# 00028 00029 #define SIZE_DATA_BUFFER 116 // size of a data packet payload 00030 #define SIZE_SOFT_BUFFER 512 // size of bootloader's soft buffer 00031 #define ERROR_THRESHOLD 5 // number of error accepted during packet receiving 00032 #define NB_SOFT_REQ 5 // number of soft request during one check_on_line function execution 00033 #define NB_REPROG_TRY 5 // number of time we try to update before return to old program 00034 00035 //***************Defined constant for MAC Layer******************************** 00036 #define DONT_MEMORISE_ADRESS 0 // parameter for MAC recept function 00037 #define MEMORISE_ADRESS 1 // parameter for MAC recept function 00038 #define SEND_UNICAST 0 // parameter for MAC send function 00039 #define SEND_BROADCAST 1 // parameter for MAC send function 00040 #define BROADCAST_ID 0xFFFF // MAC adress for broadcast message 00041 00042 #define WAIT_ANSWER_SERVER 180 // waiting time on a MAC_recept for server 00043 #define WAIT_ANSWER_CLIENT 250 // waiting time on a MAC_recept for bootloader 00044 00045 #define TYPE_ACK 1 // id of different kind of messages 00046 #define TYPE_REQ_SOFT_VERS 2 // id of different kind of messages 00047 #define TYPE_PROGAM_INFO 3 // id of different kind of messages 00048 #define TYPE_REQ_PCKT 4 // id of different kind of messages 00049 #define TYPE_DATA 5 // id of different kind of messages 00050 #define TYPE_ORDER_REPROG 6 // id of different kind of messages 00051 //***************************************************************************** 00052 00053 //*******************ID of RF channel used************************************* 00054 #define CHANNEL_REPROG 20 // channel for fast data packet transmission 00055 #define CHANNEL_EXPLOITATION 18 // channel for powwow transmission 00056 //***************************************************************************** 00057 00058 //****************************************************************************** 00059 // These constant represents all the IT adress of embedded node software for base 00060 // They have to be updated every time you recompile embedded node software for base 00061 // put 0xFFFF for unused IT ( consequently they don't have any handler ) 00062 #ifdef BASE 00063 #define IT_DACDMA 0xFFFF 00064 #define IT_PORT2 0xFFFF 00065 #define IT_USART1TX 0xFFFF 00066 #define IT_USART1RX 0xFFFF 00067 #define IT_PORT1 0xFFFF 00068 #define IT_TIMERA1 0xFFFF 00069 #define IT_TIMERA0 0xFFFF 00070 #define IT_ADC12 0xFFFF 00071 #define IT_USART0TX 0xFFFF 00072 #define IT_USART0RX 0xFFFF 00073 #define IT_WDT 0xFFFF 00074 #define IT_COMPA 0xFFFF 00075 #define IT_TIMERB1 0xFFFF 00076 #define IT_TIMERB0 0x7690 00077 #define IT_NMI 0xFFFF 00078 #endif 00079 //****************************************************************************** 00080 00081 //*********Powwow node software informations(updade if you recompile it)************* 00082 #define CONST_ADDR 0x4000 // start adress of powwow software for node 00083 #define START_ADDR 0x4300 // start adress of powwow software for node 00084 #define END_ADDR 0x8000 // end adress of powwow software for node 00085 #define VERSION_CODE 0x01 // put 0xFFFF if base doesn't have embedded software for reprogram nodes 00086 //****************************************************************************** 00087 00088 //*******Bootloader software information (updade if you recompile it)*********** 00089 #define BOOT_START_ADDR 0x2590 // start adress of bootloader software (for node only) 00090 #define BOOT_TIMER_IT_ADDR 0x3430 // IT adress of bootloader (for node only) 00091 //****************************************************************************** 00092 00093 #define TEMPO_ORDER_REPROG 2000 // time between two order reprog request : 20 sec 00094 #define TEMPO_PURGE_SEND_BUFFER 12000 // time between two sending buffer clean : 120 sec 00095 00096 //############################################################################# 00097 // STRUCTURE 00098 //############################################################################# 00099 00100 //---------data structure for MAC header-------------- 00101 00102 typedef struct{ 00103 00104 UINT16 type : 8; // type of MPDU transmited 00105 UINT16 lenght: 8; // lenght of MPDU 00106 00107 UINT16 source_id; // dynamic identifier for client device 00108 UINT16 dest_id; // dynamic identifier for server device 00109 00110 } MESSAGE_HEADER; 00111 00112 //-------data structure for MPDU--------------------- 00113 00114 typedef struct { 00115 00116 // IT's handler adress of new program 00117 UINT16 dma_dac; 00118 UINT16 port2; 00119 UINT16 usart1_tx; 00120 UINT16 usart1_rx; 00121 UINT16 port1; 00122 UINT16 timer_A1; 00123 UINT16 timer_A0; 00124 UINT16 adc12; 00125 UINT16 usart0_tx; 00126 UINT16 usart0_rx; 00127 UINT16 wdt; 00128 UINT16 comparatorA; 00129 UINT16 timerB1; 00130 UINT16 timerB0; 00131 UINT16 nmi; 00132 UINT16 reset; 00133 00134 UINT16 start_addr; //redondante voir pour jarter 00135 00136 UINT16 end_addr; // new program end adress 00137 UINT16 version; // new program version 00138 00139 UINT16 auto_crc; // for cc2420 crc 00140 00141 } MEMORY_INFO_STRUCT; 00142 00143 typedef struct{ 00144 00145 UINT16 version; // current version of node code (set to 0xFFFF if none) 00146 UINT16 channel; // channel to use for download operation 00147 00148 UINT16 auto_crc; // for cc2420 crc 00149 00150 }SOFT_INFO; 00151 00152 typedef struct{ 00153 00154 UINT16 id; // id of required packet 00155 00156 UINT16 auto_crc; // for cc2420 crc 00157 00158 }REQ_PACKET; 00159 00160 typedef struct{ 00161 00162 UINT16 id; // id of data packet 00163 char data[SIZE_DATA_BUFFER]; // soft data 00164 00165 UINT16 auto_crc; // for cc2420 crc 00166 00167 }DATA_PACKET; 00168 00169 typedef struct{ 00170 00171 UINT16 auto_crc; // for cc2420 crc 00172 00173 }JUST_CRC; 00174 00175 //############################################################################# 00176 // EXTERN GLOBALS 00177 //############################################################################# 00178 00179 extern MEMORY_INFO_STRUCT *ptr_info_prog; // adress to information memory (seg A) 00180 extern char *ptr_interrupt_vector; // adress to interrupt vector 00181 extern UINT16 buffer_phy[64]; // buffer for physical layer 00182 00183 extern MESSAGE_HEADER *mes; // point to message header on physical layer buffer 00184 extern char *mpdu; // point to mpdu on physical layer buffer 00185 00186 extern UINT16 our_id,his_id; // our_id : id of current device, his_id : id of the device we are speaking 00187 00188 extern unsigned int Deadline_order_reprog; 00189 00190 #ifdef BASE 00191 00192 extern const UINT16 dacdma; 00193 extern const UINT16 port2; 00194 extern const UINT16 usart1tx; 00195 extern const UINT16 usart1rx; 00196 extern const UINT16 port1; 00197 extern const UINT16 timerA1; 00198 extern const UINT16 timerA0; 00199 extern const UINT16 adc12; 00200 extern const UINT16 usart0tx; 00201 extern const UINT16 usart0rx; 00202 extern const UINT16 wdt; 00203 extern const UINT16 comparatorA; 00204 extern const UINT16 timerB1; 00205 extern const UINT16 timerB0; 00206 extern const UINT16 nmi; 00207 extern const UINT16 reset; 00208 00209 #endif 00210 00211 //############################################################################# 00212 // PROTOTYPE FUNCTIONS 00213 //############################################################################# 00214 00215 void write_interrupt_vector(UINT16,UINT16); 00216 void erase_interrupt_vector(void); 00217 void write_start_end_adress(void); 00218 00219 int MAC_recept(char *, UINT8 *,UINT16 , UINT8); 00220 int MAC_send(char * , UINT8 , UINT8); 00221 void copy_interrupt_vector(void); 00222 void try_perform_update(void); 00223 void serveur_reprog(void); 00224 int check_online_code_version( void );