Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2010, Loughborough University - Computer Science 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the Contiki operating system. 00030 */ 00031 00032 /** 00033 * \file 00034 * Header file for the Disco server 00035 * (embedded part of the DISCOBALL project) 00036 * 00037 * \author 00038 * George Oikonomou - <oikonomou@users.sourceforge.net> 00039 */ 00040 00041 #ifndef DISCO_H_ 00042 #define DISCO_H_ 00043 00044 #include "contiki.h" 00045 #include "contiki-net.h" 00046 /*---------------------------------------------------------------------------*/ 00047 #define DISCO_UDP_PORT 60002 00048 #define DISCO_DESCRIPTORS_LOC /* In external Flash */ 00049 00050 #define DATA_CHUNK_LEN 64 00051 00052 /* Intervals - Timeouts */ 00053 #define DISCO_TIMEOUT_PREPARE (CLOCK_SECOND / 2) 00054 #define DISCO_TIMEOUT_ABORT (CLOCK_SECOND * 10) 00055 #define DISCO_TIMEOUT_REBOOT CLOCK_SECOND 00056 00057 /* Disco State Machine */ 00058 #define DISCO_STATE_LISTENING 0x00 /* Waiting for a transaction to start */ 00059 #define DISCO_STATE_PREPARING 0x01 /* Erasing Sectors */ 00060 #define DISCO_STATE_READY 0x02 00061 #define DISCO_STATE_REBOOTING 0x03 /* Reboot to BooTTY and copy new image */ 00062 00063 /* Instructions */ 00064 #define DISCO_CMD_INIT 0x00 /* Prepare flash area for writes */ 00065 #define DISCO_CMD_SWITCH 0x01 /* Copy image from ext. to int. flash */ 00066 #define DISCO_CMD_WRITE 0x02 /* Write Image to Ext Flash */ 00067 #define DISCO_CMD_DONE 0x03 /* All Done */ 00068 00069 /* Error Codes */ 00070 #define DISCO_ERR_GENERIC 0xFF /* Generic Error */ 00071 #define DISCO_ERR_BAD_LEN 0xFE /* Incorrect Length */ 00072 #define DISCO_ERR_NOT_READY 0xFD /* Not Initialised */ 00073 #define DISCO_ERR_BAD_OFFSET 0xFC /* Bad Offset */ 00074 #define DISCO_ERR_PROTECTED 0xFB /* Target sector is protected */ 00075 #define DISCO_ERR_INIT_DONE 0xFA /* Already Initialized */ 00076 00077 /* Message Sizes */ 00078 #define DISCO_FLEN_CMD 1 00079 #define DISCO_FLEN_IMG 1 00080 #define DISCO_FLEN_ADDR 3 00081 #define DISCO_FLEN_DATA 64 00082 00083 /* Request Lengths */ 00084 #define DISCO_LEN_INIT (DISCO_FLEN_CMD + DISCO_FLEN_IMG) 00085 #define DISCO_LEN_DONE DISCO_FLEN_CMD 00086 #define DISCO_LEN_WRITE (DISCO_FLEN_CMD + DISCO_FLEN_ADDR + DISCO_FLEN_DATA) 00087 #define DISCO_LEN_SWITCH (DISCO_FLEN_CMD + DISCO_FLEN_IMG) 00088 00089 /* Response Lengths */ 00090 #define DISCO_RESPONSE_NONE 0 00091 #define DISCO_RESP_LEN_ERR DISCO_FLEN_CMD 00092 #define DISCO_RESP_LEN_INIT DISCO_FLEN_CMD 00093 #define DISCO_RESP_LEN_DONE DISCO_FLEN_CMD 00094 #define DISCO_RESP_LEN_WRITE (DISCO_FLEN_CMD + DISCO_FLEN_ADDR) 00095 #define DISCO_RESP_LEN_SWITCH (DISCO_FLEN_CMD + DISCO_FLEN_IMG) 00096 00097 /* Tell BooTTy! what to do after we jump: 00098 * BOOTY_CMD 00099 * [7:5]: Command 00100 * [5:4]: Reserved 00101 * [4:0]: Image number 00102 */ 00103 #define BOOTTY_CMD_LOCATION 0xFEFF 00104 00105 #define BOOTTY_CMD_JUMP_TO_APP 0x80 00106 #define BOOTTY_CMD_COPY_IMAGE 0x40 00107 00108 #define SECTOR_UNPROTECTED 0 00109 #define SECTOR_PROTECTED 1 00110 /*---------------------------------------------------------------------------*/ 00111 PROCESS_NAME(disco_process); 00112 /*---------------------------------------------------------------------------*/ 00113 struct disco_request_pdu { 00114 uint8_t cmd; 00115 uint8_t addr[3]; 00116 uint8_t data[DATA_CHUNK_LEN]; 00117 }; 00118 00119 struct disco_response_pdu { 00120 uint8_t status; 00121 uint8_t addr[3]; 00122 }; 00123 00124 struct disco_seed { 00125 uip_ipaddr_t addr; 00126 uint16_t port; 00127 }; 00128 /*---------------------------------------------------------------------------*/ 00129 #endif /* DISCO_H_ */