Import of the contiki-2.x development code from the SICS internal CVS server
This commit is contained in:
parent
9eb477f8f5
commit
c2ae514a13
2 changed files with 282 additions and 0 deletions
208
platform/esb/loader/loader-arch.c
Normal file
208
platform/esb/loader/loader-arch.c
Normal file
|
@ -0,0 +1,208 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: loader-arch.c,v 1.1 2006/06/21 13:39:11 nifi Exp $
|
||||
*/
|
||||
#include "contiki-esb.h"
|
||||
#include "loader-arch.h"
|
||||
#include "dev/eeprom.h"
|
||||
#include "dev/flash.h"
|
||||
|
||||
void *loader_arch_codeaddr, *loader_arch_dataaddr;
|
||||
|
||||
|
||||
#define FLASHADDR ((char *)0x8000)
|
||||
#define DATAADDR ((char *)0x900)
|
||||
#define READSIZE 0x10
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
void
|
||||
loader_arch_load(unsigned short startaddr)
|
||||
{
|
||||
unsigned short tmp;
|
||||
unsigned short codelen, datalen, sumlen;
|
||||
int i, j;
|
||||
unsigned short ptr;
|
||||
unsigned short *flashptr;
|
||||
void (* init)(void *);
|
||||
unsigned char tmpdata[READSIZE];
|
||||
unsigned char sum;
|
||||
|
||||
/* Read the magic word and version number from the first four bytes
|
||||
in EEPROM. */
|
||||
eeprom_read(startaddr, (char *)&tmp, 2);
|
||||
if(tmp != HTONS(LOADER_ARCH_MAGIC)) {
|
||||
beep_beep(60000);
|
||||
return;
|
||||
}
|
||||
|
||||
eeprom_read(startaddr + 2, (char *)&tmp, 2);
|
||||
if(tmp != HTONS(LOADER_ARCH_VERSION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
startaddr += 4;
|
||||
|
||||
/* Read the total lenghth that the checksum covers. */
|
||||
eeprom_read(startaddr, (char *)&sumlen, 2);
|
||||
|
||||
sumlen = htons(sumlen);
|
||||
|
||||
sum = 0;
|
||||
|
||||
for(i = 0; sumlen - i > READSIZE; i += READSIZE) {
|
||||
eeprom_read(startaddr + 2 + i, tmpdata, READSIZE);
|
||||
|
||||
for(j = 0; j < READSIZE; ++j) {
|
||||
sum += tmpdata[j];
|
||||
if(sum < tmpdata[j]) {
|
||||
++sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(sumlen - i > 0) {
|
||||
eeprom_read(startaddr + 2 + i, tmpdata, READSIZE);
|
||||
|
||||
for(j = 0; j < sumlen - i; ++j) {
|
||||
sum += tmpdata[j];
|
||||
if(sum < tmpdata[j]) {
|
||||
++sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If the checksum was wrong, we beep. The number of beeps indicate
|
||||
the numerival value of the calculated checksum. */
|
||||
if(sum != 0xff) {
|
||||
leds_red(LEDS_ON);
|
||||
|
||||
for(i = 0; i < (sum >> 4); ++i) {
|
||||
beep_beep(200);
|
||||
for(j = 0; j < 2; ++j) {
|
||||
clock_delay(60000);
|
||||
}
|
||||
}
|
||||
|
||||
for(j = 0; j < 8; ++j) {
|
||||
clock_delay(60000);
|
||||
}
|
||||
|
||||
for(i = 0; i < (sum & 0x0f); ++i) {
|
||||
beep_beep(200);
|
||||
for(j = 0; j < 2; ++j) {
|
||||
clock_delay(60000);
|
||||
}
|
||||
}
|
||||
|
||||
leds_red(LEDS_OFF);
|
||||
|
||||
return;
|
||||
|
||||
} else {
|
||||
leds_green(LEDS_ON);
|
||||
for(i = 0; i < 4; ++i) {
|
||||
beep_beep(200);
|
||||
for(j = 0; j < 2; ++j) {
|
||||
clock_delay(60000);
|
||||
}
|
||||
}
|
||||
leds_green(LEDS_OFF);
|
||||
}
|
||||
|
||||
|
||||
leds_yellow(LEDS_ON);
|
||||
startaddr += 2;
|
||||
|
||||
/* Read the size of the code segment from the next two bytes in EEPROM. */
|
||||
eeprom_read(startaddr, (char *)&codelen, 2);
|
||||
/* Convert from network byte order to host byte order. */
|
||||
codelen = htons(codelen);
|
||||
|
||||
|
||||
/* Flash program code into ROM. We use the available space in the
|
||||
program's data memory to temporarily store the code before
|
||||
flashing it into ROM. */
|
||||
flash_setup();
|
||||
|
||||
flashptr = (unsigned short *)FLASHADDR;
|
||||
for(ptr = startaddr + 2; ptr < startaddr + 2 + codelen; ptr += READSIZE) {
|
||||
|
||||
/* Read data from EEPROM into RAM. */
|
||||
eeprom_read(ptr, DATAADDR, READSIZE);
|
||||
|
||||
/* Clear flash page on 512 byte boundary. */
|
||||
if((((unsigned short)flashptr) & 0x01ff) == 0) {
|
||||
flash_clear(flashptr);
|
||||
}
|
||||
|
||||
/* Burn data from RAM into flash ROM. Flash is burned one 16-bit
|
||||
word at a time, so we need to be careful when incrementing
|
||||
pointers. The flashptr is already a short pointer, so
|
||||
incrementing it by one will actually increment the address by
|
||||
two. */
|
||||
for(i = 0; i < READSIZE / 2; ++i) {
|
||||
flash_write(flashptr, ((unsigned short *)DATAADDR)[i]);
|
||||
++flashptr;
|
||||
}
|
||||
}
|
||||
|
||||
flash_done();
|
||||
|
||||
leds_yellow(LEDS_OFF);
|
||||
|
||||
leds_green(LEDS_ON);
|
||||
|
||||
/* Read the size of the code segment from the first two bytes in EEPROM. */
|
||||
eeprom_read(startaddr + 2 + codelen, (char *)&datalen, 2);
|
||||
|
||||
/* Convert from network byte order to host byte order. */
|
||||
datalen = htons(datalen);
|
||||
|
||||
if(datalen > 0) {
|
||||
/* Read the contents of the data memory into RAM. */
|
||||
eeprom_read(startaddr + 2 + codelen + 2, DATAADDR, datalen);
|
||||
}
|
||||
|
||||
for(i = 0; i < 4; ++i) {
|
||||
beep_beep(2000);
|
||||
clock_delay(20000);
|
||||
}
|
||||
|
||||
leds_green(LEDS_OFF);
|
||||
|
||||
/* Execute the loaded program. */
|
||||
init = ((void (*)(void *))FLASHADDR);
|
||||
init((void *)0);
|
||||
}
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
void
|
||||
loader_arch_free(void *code, void *data)
|
||||
{
|
||||
}
|
||||
/*----------------------------------------------------------------------------------*/
|
74
platform/esb/loader/loader-arch.h
Normal file
74
platform/esb/loader/loader-arch.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: loader-arch.h,v 1.1 2006/06/21 13:39:11 nifi Exp $
|
||||
*/
|
||||
#ifndef __LOADER_ARCH_H__
|
||||
#define __LOADER_ARCH_H__
|
||||
|
||||
/**
|
||||
* Load a program from EEPROM.
|
||||
*
|
||||
* This function loads a program from EEPROM into the flash ROM (code) and RAM (data).
|
||||
*
|
||||
* \param code The address of the first byte of code in the EEPROM.
|
||||
*
|
||||
* \param codelen The length of the code.
|
||||
*
|
||||
* \param data The address of the first byte of data in the EEPROM.
|
||||
*
|
||||
* \param datalen The length of the data.
|
||||
*
|
||||
*/
|
||||
void loader_arch_load(unsigned short startaddr);
|
||||
|
||||
/**
|
||||
* Unload a program.
|
||||
*
|
||||
* This function should not be called directly, but accessed through
|
||||
* the macro LOADER_UNLOAD(). The function unloads a program from both
|
||||
* RAM and ROM.
|
||||
*
|
||||
* \param codeaddr A pointer to the first byte of program code.
|
||||
*
|
||||
* \param dataaddr A pointer to the first byte of program data.
|
||||
*/
|
||||
void loader_arch_free(void *codeaddr, void *dataaddr);
|
||||
|
||||
extern void *loader_arch_codeaddr, *loader_arch_dataaddr;
|
||||
|
||||
#ifndef LOADER_UNLOAD
|
||||
#define LOADER_UNLOAD() loader_arch_free(&loader_arch_codeaddr, &loader_arch_dataaddr)
|
||||
#endif
|
||||
|
||||
#define LOADER_ARCH_MAGIC 0x373a
|
||||
#define LOADER_ARCH_VERSION 0x0001
|
||||
|
||||
#endif /* __LOADER_ARCH_H__ */
|
Loading…
Reference in a new issue