Skip to content

Commit

Permalink
Merge pull request openwsn-berkeley#204 from changtengfei/develop
Browse files Browse the repository at this point in the history
FW-415. Fix.
  • Loading branch information
twatteyne committed Jul 2, 2015
2 parents 86015df + 5e9826b commit 72098d8
Show file tree
Hide file tree
Showing 38 changed files with 15,858 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ settings
*.pyd
*.pyc
/build
/images
/.sconsign.dblite
*.map
*.lst
Expand Down
6 changes: 6 additions & 0 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ if env['cryptoengine']:
env.Append(CPPDEFINES = {'CRYPTO_ENGINE_SCONS' : env['cryptoengine']})
if env['l2_security']==1:
env.Append(CPPDEFINES = 'L2_SECURITY_ACTIVE')
if env['goldenImage']=='sniffer':
env.Append(CPPDEFINES = 'GOLDEN_IMAGE_SNIFFER')
else:
if env['goldenImage']=='root':
env.Append(CPPDEFINES = 'GOLDEN_IMAGE_ROOT')


if env['toolchain']=='mspgcc':

Expand Down
12 changes: 11 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ project:
(dummy_crypto_engine, firmware_crypto_engine,
board_crypto_engine).
l2_security Use hop-by-hop encryption and authentication.
goldenImage sniffer, root or none(default)
Common variables:
verbose Print each complete compile/link command.
Expand Down Expand Up @@ -133,7 +134,8 @@ command_line_options = {
'debug': ['0','1'],
'noadaptivesync': ['0','1'],
'cryptoengine': ['', 'dummy_crypto_engine', 'firmware_crypto_engine', 'board_crypto_engine'],
'l2_security': ['0','1']
'l2_security': ['0','1'],
'goldenImage': ['none','root','sniffer'],
}

def validate_option(key, value, env):
Expand Down Expand Up @@ -278,6 +280,14 @@ command_line_vars.AddVariables(
validate_option, # validator
int, # converter
),
# create an golden image for interop testing
(
'goldenImage', # key
'', # help
command_line_options['goldenImage'][0], # default
validate_option, # validator
None, # converter
),
(
'apps', # key
'comma-separated list of user applications', # help
Expand Down
22 changes: 20 additions & 2 deletions bsp/boards/OpenMote-CC2538/board_info.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Author: Xavier Vilajosana (xvilajosana@eecs.berkeley.edu)
* Pere Tuset (peretuset@openmote.com)
* Modified: Tengfei Chang (tengfei.chang@eecs.berkeley.edu)
* Date: July 2013
* Description: CC2538-specific board information bsp module.
*/
Expand Down Expand Up @@ -57,7 +58,23 @@
#define PORT_PIN_RADIO_RESET_LOW() // nothing

//===== IEEE802154E timing

#ifdef GOLDEN_IMAGE_ROOT
// time-slot related
#define PORT_TsSlotDuration 328 // counter counts one extra count, see datasheet
// execution speed related
#define PORT_maxTxDataPrepare 10 // 305us (measured 82us)
#define PORT_maxRxAckPrepare 10 // 305us (measured 83us)
#define PORT_maxRxDataPrepare 4 // 122us (measured 22us)
#define PORT_maxTxAckPrepare 10 // 122us (measured 94us)
// radio speed related
#ifdef L2_SECURITY_ACTIVE
#define PORT_delayTx 7 // 366us (measured xxxus)
#else
#define PORT_delayTx 12 // 366us (measured xxxus)
#endif
#define PORT_delayRx 0 // 0us (can not measure)
// radio watchdog
#else
// time-slot related
#define PORT_TsSlotDuration 492 // counter counts one extra count, see datasheet
// execution speed related
Expand All @@ -66,9 +83,10 @@
#define PORT_maxRxDataPrepare 33 // 1007us (measured 84us)
#define PORT_maxTxAckPrepare 22 // 305us (measured 219us)
// radio speed related
#define PORT_delayTx 7 // 214us (measured 219us)
#define PORT_delayTx 12 // 214us (measured 219us)
#define PORT_delayRx 0 // 0us (can not measure)
// radio watchdog
#endif

//===== adaptive_sync accuracy

Expand Down
2 changes: 1 addition & 1 deletion bsp/boards/OpenMote-CC2538/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "gpio.h"
#include "source/i2c.h"
#include "source/i2c_lib.h"
#include "ioc.h"
#include "sys_ctrl.h"

Expand Down
6 changes: 3 additions & 3 deletions bsp/boards/OpenMote-CC2538/sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ callbackRead_cbt sensors_getCallbackRead(uint8_t sensorType) {
case SENSOR_LIGHT:
return &max44009_read_light;
case SENSOR_XACCELERATION:
return &adxl346_read_x;
return (callbackRead_cbt)&adxl346_read_x;
case SENSOR_YACCELERATION:
return &adxl346_read_y;
return (callbackRead_cbt)&adxl346_read_y;
case SENSOR_ZACCELERATION:
return &adxl346_read_z;
return (callbackRead_cbt)&adxl346_read_z;
case SENSOR_ADCTEMPERATURE:
return &adc_sens_read_temperature;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include <headers/hw_memmap.h>
#include <headers/hw_sys_ctrl.h>
#include "debug.h"
#include "i2c.h"
#include "i2c_lib.h"
#include "interrupt.h"

//*****************************************************************************
Expand Down
File renamed without changes.
15 changes: 14 additions & 1 deletion bsp/boards/python/board_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,19 @@
#define PORT_PIN_RADIO_RESET_LOW() // nothing

//===== IEEE802154E timing

#ifdef GOLDEN_IMAGE_ROOT
// time-slot related
#define PORT_TsSlotDuration 328 // counter counts one extra count, see datasheet
// execution speed related
#define PORT_maxTxDataPrepare 10 // 305us (measured 82us)
#define PORT_maxRxAckPrepare 10 // 305us (measured 83us)
#define PORT_maxRxDataPrepare 4 // 122us (measured 22us)
#define PORT_maxTxAckPrepare 4 // 122us (measured 94us)
// radio speed related
#define PORT_delayTx 7 // 366us (measured xxxus)
#define PORT_delayRx 0 // 0us (can not measure)
// radio watchdog
#else
// time-slot related
#define PORT_TsSlotDuration 491 // counter counts one extra count, see datasheet
// execution speed related
Expand All @@ -56,6 +68,7 @@
#define PORT_delayTx 7 // 214us (measured 219us)
#define PORT_delayRx 0 // 0us (can not measure)
// radio watchdog
#endif

//===== adaptive_sync accuracy

Expand Down
140 changes: 140 additions & 0 deletions drivers/common/openserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "uart.h"
#include "opentimers.h"
#include "openhdlc.h"
#include "schedule.h"
#include "icmpv6rpl.h"

//=========================== variables =======================================

Expand All @@ -37,6 +39,8 @@ void openserial_board_reset_cb(
opentimer_id_t id
);

void openserial_goldenImageCommands();

// HDLC output
void outputHdlcOpen(void);
void outputHdlcWrite(uint8_t b);
Expand Down Expand Up @@ -158,6 +162,27 @@ owerror_t openserial_printData(uint8_t* buffer, uint8_t length) {
return E_SUCCESS;
}

owerror_t openserial_printPacket(uint8_t* buffer, uint8_t length, uint8_t channel) {
uint8_t i;
INTERRUPT_DECLARATION();

DISABLE_INTERRUPTS();
openserial_vars.outputBufFilled = TRUE;
outputHdlcOpen();
outputHdlcWrite(SERFRAME_MOTE2PC_SNIFFED_PACKET);
outputHdlcWrite(idmanager_getMyID(ADDR_16B)->addr_16b[1]);
outputHdlcWrite(idmanager_getMyID(ADDR_16B)->addr_16b[0]);
for (i=0;i<length;i++){
outputHdlcWrite(buffer[i]);
}
outputHdlcWrite(channel);
outputHdlcClose();

ENABLE_INTERRUPTS();

return E_SUCCESS;
}

owerror_t openserial_printInfo(uint8_t calling_component, uint8_t error_code,
errorparameter_t arg1,
errorparameter_t arg2) {
Expand Down Expand Up @@ -398,6 +423,10 @@ void openserial_stop() {
//echo function must reset input buffer after reading the data.
openserial_echo(&openserial_vars.inputBuf[1],inputBufFill-1);
break;
case SERFRAME_PC2MOTE_COMMAND_GD:
// golden image command
openserial_goldenImageCommands();
break;
default:
openserial_printError(COMPONENT_OPENSERIAL,ERR_UNSUPPORTED_COMMAND,
(errorparameter_t)cmdByte,
Expand All @@ -416,6 +445,117 @@ void openserial_stop() {
ENABLE_INTERRUPTS();
}

void openserial_goldenImageCommands(){
uint8_t input_buffer[7];
uint8_t numDataBytes;
uint8_t version;
uint8_t type;
uint8_t commandId;
uint8_t commandLen;
uint8_t comandParam_8;
uint16_t comandParam_16;

numDataBytes = openserial_getNumDataBytes();
//copying the buffer
openserial_getInputBuffer(&(input_buffer[0]),numDataBytes);
version = openserial_vars.inputBuf[1];
type = openserial_vars.inputBuf[2];
if (version != GOLDEN_IMAGE_VERSION) {
// the version of command is wrong
// log this info and return
return;
}

#ifdef GOLDEN_IMAGE_ROOT
if ( type != GD_TYPE_ROOT ){
// image type is wrong
return;
}
#endif
#ifdef GOLDEN_IMAGE_SNIFFER
if (type != GD_TYPE_SNIFFER) {
// image type is wrong
return;
}
#endif
commandId = openserial_vars.inputBuf[3];
commandLen = openserial_vars.inputBuf[4];

if (commandLen>2 || commandLen == 0) {
// the max command Len is 2, except ping commands
return;
} else {
if (commandLen == 1) {
comandParam_8 = openserial_vars.inputBuf[5];
} else {
// commandLen == 2
comandParam_16 = (openserial_vars.inputBuf[5] & 0x00ff) | \
((openserial_vars.inputBuf[6]<<8) & 0xff00);
}
}

switch(commandId) {
case COMMAND_SET_EBPERIOD:
sixtop_setEBPeriod(comandParam_8); // one byte, in seconds
break;
case COMMAND_SET_CHANNEL:
#ifdef GOLDEN_IMAGE_ROOT
// this is dagroot image
ieee154e_setSingleChannel(comandParam_8); // one byte
#endif
#ifdef GOLDEN_IMAGE_SNIFFER
// this is sniffer image
sniffer_setListeningChannel(comandParam_8); // one byte
#endif
break;
case COMMAND_SET_KAPERIOD: // two bytes, in slots
sixtop_setKaPeriod(comandParam_16);
break;
case COMMAND_SET_DIOPERIOD: // two bytes, in mili-seconds
icmpv6rpl_setDIOPeriod(comandParam_16);
break;
case COMMAND_SET_DAOPERIOD: // two bytes, in mili-seconds
icmpv6rpl_setDAOPeriod(comandParam_16);
break;
case COMMAND_PING_MOTE:
// this should not happen
break;
case COMMAND_SET_DAGRANK: // two bytes
neighbors_setMyDAGrank(comandParam_16);
break;
case COMMAND_SET_SECURITY_STATUS: // one byte
if (comandParam_8 ==1) {
ieee154e_setIsSecurityEnabled(TRUE);
} else {
if (comandParam_8 == 0) {
ieee154e_setIsSecurityEnabled(FALSE);
} else {
// security only can be 1 or 0
break;
}
}
break;
case COMMAND_SET_FRAMELENGTH: // two bytes
schedule_setFrameLength(comandParam_16);
break;
case COMMAND_SET_ACK_STATUS:
if (comandParam_8 == 1) {
ieee154e_setIsAckEnabled(TRUE);
} else {
if (comandParam_8 == 0) {
ieee154e_setIsAckEnabled(FALSE);
} else {
// ack reply
break;
}
}
break;
default:
// wrong command ID
break;
}
}

/**
\brief Trigger this module to print status information, over serial.
Expand Down
17 changes: 17 additions & 0 deletions drivers/common/openserial.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,30 @@ enum {
#define SERFRAME_MOTE2PC_ERROR ((uint8_t)'E')
#define SERFRAME_MOTE2PC_CRITICAL ((uint8_t)'C')
#define SERFRAME_MOTE2PC_REQUEST ((uint8_t)'R')
#define SERFRAME_MOTE2PC_SNIFFED_PACKET ((uint8_t)'P')

// frames sent PC->mote
#define SERFRAME_PC2MOTE_SETROOT ((uint8_t)'R')
#define SERFRAME_PC2MOTE_DATA ((uint8_t)'D')
#define SERFRAME_PC2MOTE_TRIGGERSERIALECHO ((uint8_t)'S')
#define SERFRAME_PC2MOTE_COMMAND_GD ((uint8_t)'G')

//=========================== typedef =========================================

enum {
COMMAND_SET_EBPERIOD = 0,
COMMAND_SET_CHANNEL = 1,
COMMAND_SET_KAPERIOD = 2,
COMMAND_SET_DIOPERIOD = 3,
COMMAND_SET_DAOPERIOD = 4,
COMMAND_PING_MOTE = 5,
COMMAND_SET_DAGRANK = 6,
COMMAND_SET_SECURITY_STATUS = 7,
COMMAND_SET_FRAMELENGTH = 8,
COMMAND_SET_ACK_STATUS = 9,
COMMAND_MAX = 10,
};

//=========================== module variables ================================

typedef struct {
Expand Down Expand Up @@ -93,6 +109,7 @@ owerror_t openserial_printCritical(uint8_t calling_component, uint8_t error_code
errorparameter_t arg1,
errorparameter_t arg2);
owerror_t openserial_printData(uint8_t* buffer, uint8_t length);
owerror_t openserial_printPacket(uint8_t* buffer, uint8_t length, uint8_t channel);
uint8_t openserial_getNumDataBytes(void);
uint8_t openserial_getInputBuffer(uint8_t* bufferToWrite, uint8_t maxNumBytes);
void openserial_startInput(void);
Expand Down
Binary file added images/GD_ROOT.bin
Binary file not shown.
Binary file added images/GD_ROOT_SEC.bin
Binary file not shown.
Binary file added images/GD_SNIFFER.bin
Binary file not shown.
Loading

0 comments on commit 72098d8

Please sign in to comment.