Skip to content

Commit

Permalink
Merge pull request #449 from openwsn-berkeley/develop_FW-782
Browse files Browse the repository at this point in the history
FW-782. Update msf implementation
  • Loading branch information
changtengfei authored Nov 8, 2018
2 parents 9b524b9 + f37b5fa commit 3a10097
Show file tree
Hide file tree
Showing 20 changed files with 473 additions and 299 deletions.
7 changes: 3 additions & 4 deletions drivers/common/openserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ void openserial_init(void) {
openserial_vars.outputBufIdxW = 0;
openserial_vars.fBusyFlushing = FALSE;

openserial_vars.debugPrint_timerId = opentimers_create(TIMER_GENERAL_PURPOSE);
openserial_vars.reset_timerId = opentimers_create(TIMER_GENERAL_PURPOSE);
openserial_vars.debugPrint_timerId = opentimers_create(TIMER_GENERAL_PURPOSE);
opentimers_scheduleIn(
openserial_vars.debugPrint_timerId,
DEBUGPRINT_PERIOD,
Expand Down Expand Up @@ -189,17 +190,15 @@ owerror_t openserial_printCritical(
errorparameter_t arg1,
errorparameter_t arg2
) {
opentimers_id_t id;
uint32_t reference;

// blink error LED, this is serious
leds_error_blink();

// schedule for the mote to reboot in 10s
id = opentimers_create(TIMER_GENERAL_PURPOSE);
reference = opentimers_getValue();
opentimers_scheduleAbsolute(
id, // timerId
openserial_vars.reset_timerId, // timerId
10000, // duration
reference, // reference
TIME_MS, // timetype
Expand Down
1 change: 1 addition & 0 deletions drivers/common/openserial.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ typedef struct {
uint8_t ctsStateChanged;
uint8_t debugPrintCounter;
openserial_rsvpt* registeredCmd;
uint8_t reset_timerId;
uint8_t debugPrint_timerId;
// input
uint8_t inputBuf[SERIAL_INPUT_BUFFER_SIZE];
Expand Down
2 changes: 1 addition & 1 deletion drivers/common/opentimers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//=========================== define ==========================================

/// Maximum number of timers that can run concurrently
#define MAX_NUM_TIMERS 10
#define MAX_NUM_TIMERS 15
#define MAX_TICKS_IN_SINGLE_CLOCK (uint32_t)(((PORT_TIMER_WIDTH)0xFFFFFFFF)>>1)
#define ERROR_NO_AVAILABLE_ENTRIES 255
#define MAX_DURATION_ISR 33 // 33@32768Hz = 1ms
Expand Down
4 changes: 2 additions & 2 deletions inc/opendefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

static const uint8_t infoStackName[] = "OpenWSN ";
#define OPENWSN_VERSION_MAJOR 1
#define OPENWSN_VERSION_MINOR 21
#define OPENWSN_VERSION_PATCH 4
#define OPENWSN_VERSION_MINOR 22
#define OPENWSN_VERSION_PATCH 0

#ifndef TRUE
#define TRUE 1
Expand Down
5 changes: 2 additions & 3 deletions openapps/cjoin/cjoin.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ void cjoin_task_cb(void) {
// init the security context only here in order to use the latest joinKey
// that may be set over the serial
// cjoin_init_security_context();

cjoin_sendJoinRequest(joinProxy);

return;
Expand Down Expand Up @@ -249,6 +248,7 @@ owerror_t cjoin_sendJoinRequest(open_addr_t* joinProxy) {
);
return E_FAIL;
}

// take ownership over that packet
pkt->creator = COMPONENT_CJOIN;
pkt->owner = COMPONENT_CJOIN;
Expand Down Expand Up @@ -292,7 +292,6 @@ owerror_t cjoin_sendJoinRequest(open_addr_t* joinProxy) {
payload_len = cojp_cbor_encode_join_request_object(tmp, &join_request);
packetfunctions_reserveHeaderSize(pkt, payload_len);
memcpy(pkt->payload, tmp, payload_len);

// send
outcome = opencoap_send(
pkt,
Expand All @@ -310,7 +309,7 @@ owerror_t cjoin_sendJoinRequest(open_addr_t* joinProxy) {
return E_FAIL;
}

return E_SUCCESS;
return E_SUCCESS;
}

bool cjoin_getIsJoined(void) {
Expand Down
61 changes: 29 additions & 32 deletions openstack/02a-MAClow/IEEE802154E.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,39 +952,36 @@ port_INLINE void activity_ti1ORri1(void) {
// check whether we can send
if (schedule_getOkToSend()) {
if (packetfunctions_isBroadcastMulticast(&neighbor)==FALSE){
// this is a dedicated cell
ieee154e_vars.dataToSend = openqueue_macGetDedicatedPacket(&neighbor);
// update numcellpassed and numcellused on dedicated cell
if (ieee154e_vars.dataToSend!=NULL) {
msf_updateCellsUsed(&neighbor);

if (schedule_getShared()){
// this is an autonomous TxRx cell (unicast)
ieee154e_vars.dataToSend = openqueue_macGet6PandJoinPacket(&neighbor);
} else {
// this is a managed Tx cell
ieee154e_vars.dataToSend = openqueue_macGetNonJoinIPv6Packet(&neighbor);

if (ieee154e_vars.dataToSend == NULL){
ieee154e_vars.dataToSend = openqueue_macGetKaPacket(&neighbor);
}

// update numcellpassed and numcellused on managed Tx cell
if (ieee154e_vars.dataToSend!=NULL) {
msf_updateCellsUsed(&neighbor);
}
msf_updateCellsPassed(&neighbor);
}
msf_updateCellsPassed(&neighbor);
} else {
// this is minimal cell
ieee154e_vars.dataToSend = openqueue_macGetDataPacket(&neighbor);
if ((ieee154e_vars.dataToSend==NULL) && (cellType==CELLTYPE_TXRX)) {
couldSendEB=TRUE;
// look for an EB packet in the queue
ieee154e_vars.dataToSend = openqueue_macGetEBPacket();
} else {
// there is a packet to send
if (
schedule_hasDedicatedCellToNeighbor(&ieee154e_vars.dataToSend->l2_nextORpreviousHop)
) {
// allow sixtop response with SEQNUM_ERR return code send on minimal cell
if (
ieee154e_vars.dataToSend->creator!=COMPONENT_SIXTOP_RES ||
ieee154e_vars.dataToSend->l2_sixtop_returnCode != IANA_6TOP_RC_SEQNUM_ERR
) {
// leave the packet to be sent on dedicated cell and pick up a broadcast packet.
ieee154e_vars.dataToSend = openqueue_macGetDIOPacket();
if (ieee154e_vars.dataToSend==NULL){
couldSendEB=TRUE;
// look for an EB packet in the queue
ieee154e_vars.dataToSend = openqueue_macGetEBPacket();
}
}
if (schedule_getShared()) {
// this is minimal cell
ieee154e_vars.dataToSend = openqueue_macGetDIOPacket();
if (ieee154e_vars.dataToSend==NULL){
couldSendEB=TRUE;
// look for an EB packet in the queue
ieee154e_vars.dataToSend = openqueue_macGetEBPacket();
}
} else {
// this is autonomous TXRX cell (anycast)
ieee154e_vars.dataToSend = openqueue_macGetDownStreamPacket(&neighbor);
}
}
}
Expand Down Expand Up @@ -1920,7 +1917,7 @@ port_INLINE void activity_ri5(PORT_TIMER_WIDTH capturedTime) {
} else {
// synchronize to the received packet if I'm not a DAGroot and this is my preferred parent
// or in case I'm in the middle of the join process when parent is not yet selected
// or in case I don't have a dedicated cell to my parent yet
// or in case I don't have an autonomous Tx cell cell to my parent yet
if (
idmanager_getIsDAGroot() == FALSE &&
(
Expand All @@ -1929,7 +1926,7 @@ port_INLINE void activity_ri5(PORT_TIMER_WIDTH capturedTime) {
icmpv6rpl_getPreferredParentEui64(&addressToWrite) == FALSE ||
(
icmpv6rpl_getPreferredParentEui64(&addressToWrite) &&
schedule_hasDedicatedCellToNeighbor(&addressToWrite)== FALSE
schedule_hasManagedTxCellToNeighbor(&addressToWrite)== FALSE
)
)
) {
Expand Down
4 changes: 2 additions & 2 deletions openstack/02a-MAClow/IEEE802154E.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ static const uint8_t ebIEsBytestream[] = {
#define TX_POWER 31 // 1=-25dBm, 31=0dBm (max value)
#define RESYNCHRONIZATIONGUARD 5 // in 32kHz ticks. min distance to the end of the slot to successfully synchronize
#define US_PER_TICK 30 // number of us per 32kHz clock tick
#define MAXKAPERIOD 1000 // in slots: 2000@15ms per slot -> ~30 seconds. Max value used by adaptive synchronization.
#define DESYNCTIMEOUT 2333 // in slots: 2333@15ms per slot -> ~35 seconds. A larger DESYNCTIMEOUT is needed if using a larger KATIMEOUT.
#define MAXKAPERIOD 1000 // in slots: 1500@20ms per slot -> ~30 seconds. Max value used by adaptive synchronization.
#define DESYNCTIMEOUT 1750 // in slots: 1750@20ms per slot -> ~35 seconds. A larger DESYNCTIMEOUT is needed if using a larger KATIMEOUT.
#define LIMITLARGETIMECORRECTION 5 // threshold number of ticks to declare a timeCorrection "large"
#define LENGTH_IEEE154_MAX 128 // max length of a valid radio packet
#define DUTY_CYCLE_WINDOW_LIMIT (0xFFFFFFFF>>1) // limit of the dutycycle window
Expand Down
37 changes: 33 additions & 4 deletions openstack/02b-MAChigh/msf.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "idmanager.h"
#include "icmpv6rpl.h"
#include "IEEE802154E.h"
#include "openqueue.h"

//=========================== definition =====================================

Expand Down Expand Up @@ -37,6 +38,9 @@ void msf_housekeeping(void);
//=========================== public ==========================================

void msf_init(void) {

open_addr_t temp_neighbor;

memset(&msf_vars,0,sizeof(msf_vars_t));
msf_vars.numAppPacketsPerSlotFrame = 0;
sixtop_setSFcallback(
Expand All @@ -45,6 +49,17 @@ void msf_init(void) {
(sixtop_sf_translatemetadata)msf_translateMetadata,
(sixtop_sf_handle_callback)msf_handleRCError
);

memset(&temp_neighbor,0,sizeof(temp_neighbor));
temp_neighbor.type = ADDR_ANYCAST;
schedule_addActiveSlot(
msf_hashFunction_getSlotoffset(256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+idmanager_getMyID(ADDR_64B)->addr_64b[7]), // slot offset
CELLTYPE_TXRX, // type of slot
FALSE, // shared?
msf_hashFunction_getChanneloffset(256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+idmanager_getMyID(ADDR_64B)->addr_64b[7]), // channel offset
&temp_neighbor // neighbor
);

msf_vars.housekeepingTimerId = opentimers_create(TIMER_GENERAL_PURPOSE);
msf_vars.housekeepingPeriod = HOUSEKEEPING_PERIOD;
opentimers_scheduleIn(
Expand Down Expand Up @@ -89,7 +104,7 @@ void msf_updateCellsUsed(open_addr_t* neighbor){

void msf_trigger6pClear(open_addr_t* neighbor){

if (schedule_hasDedicatedCellToNeighbor(neighbor)>0){
if (schedule_hasManagedTxCellToNeighbor(neighbor)){
sixtop_request(
IANA_6TOP_CMD_CLEAR, // code
neighbor, // neighbor
Expand Down Expand Up @@ -171,6 +186,8 @@ void msf_timer_housekeeping_cb(opentimers_id_t id){
opentimers_updateDuration(msf_vars.housekeepingTimerId, newDuration);
}

//=========================== tasks ============================================

void msf_timer_housekeeping_task(void){

msf_housekeeping();
Expand Down Expand Up @@ -257,8 +274,8 @@ void msf_trigger6pDelete(void){
return;
}

if (schedule_getNumberOfDedicatedCells(&neighbor)<=1){
// at least one dedicated cell presents
if (schedule_getNumberOfManagedTxCells(&neighbor)<=1){
// at least one managed Tx cell presents
return;
}

Expand Down Expand Up @@ -356,7 +373,8 @@ void msf_housekeeping(void){
if (foundNeighbor==FALSE) {
return;
}
if (schedule_getNumberOfDedicatedCells(&parentNeighbor)==0){

if (schedule_getNumberOfManagedTxCells(&parentNeighbor)==0){
msf_trigger6pAdd();
return;
}
Expand Down Expand Up @@ -387,4 +405,15 @@ void msf_housekeeping(void){
0 // list command maximum celllist (not used)
);
}
}

uint16_t msf_hashFunction_getSlotoffset(uint16_t moteId){

return SCHEDULE_MINIMAL_6TISCH_ACTIVE_CELLS + \
(moteId%(SLOTFRAME_LENGTH-SCHEDULE_MINIMAL_6TISCH_ACTIVE_CELLS));
}

uint8_t msf_hashFunction_getChanneloffset(uint16_t moteId){

return moteId%NUM_CHANNELS;
}
5 changes: 4 additions & 1 deletion openstack/02b-MAChigh/msf.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//=========================== define ==========================================

#define IANA_6TISCH_SFID_MSF 0
#define CELLOPTIONS_MSF CELLOPTIONS_TX | CELLOPTIONS_RX | CELLOPTIONS_SHARED
#define CELLOPTIONS_MSF CELLOPTIONS_TX
#define NUMCELLS_MSF 1

#define MAX_NUMCELLS 16
Expand Down Expand Up @@ -60,6 +60,9 @@ void msf_updateCellsPassed(open_addr_t* neighbor);
void msf_updateCellsUsed(open_addr_t* neighbor);
// called by icmpv6rpl, where parent changed
void msf_trigger6pClear(open_addr_t* neighbor);

uint16_t msf_hashFunction_getSlotoffset(uint16_t moteId);
uint8_t msf_hashFunction_getChanneloffset(uint16_t moteId);
/**
\}
\}
Expand Down
Loading

0 comments on commit 3a10097

Please sign in to comment.