Skip to content

Commit 3a10097

Browse files
authored
Merge pull request #449 from openwsn-berkeley/develop_FW-782
FW-782. Update msf implementation
2 parents 9b524b9 + f37b5fa commit 3a10097

File tree

20 files changed

+473
-299
lines changed

20 files changed

+473
-299
lines changed

drivers/common/openserial.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ void openserial_init(void) {
9999
openserial_vars.outputBufIdxW = 0;
100100
openserial_vars.fBusyFlushing = FALSE;
101101

102-
openserial_vars.debugPrint_timerId = opentimers_create(TIMER_GENERAL_PURPOSE);
102+
openserial_vars.reset_timerId = opentimers_create(TIMER_GENERAL_PURPOSE);
103+
openserial_vars.debugPrint_timerId = opentimers_create(TIMER_GENERAL_PURPOSE);
103104
opentimers_scheduleIn(
104105
openserial_vars.debugPrint_timerId,
105106
DEBUGPRINT_PERIOD,
@@ -189,17 +190,15 @@ owerror_t openserial_printCritical(
189190
errorparameter_t arg1,
190191
errorparameter_t arg2
191192
) {
192-
opentimers_id_t id;
193193
uint32_t reference;
194194

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

198198
// schedule for the mote to reboot in 10s
199-
id = opentimers_create(TIMER_GENERAL_PURPOSE);
200199
reference = opentimers_getValue();
201200
opentimers_scheduleAbsolute(
202-
id, // timerId
201+
openserial_vars.reset_timerId, // timerId
203202
10000, // duration
204203
reference, // reference
205204
TIME_MS, // timetype

drivers/common/openserial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ typedef struct {
101101
uint8_t ctsStateChanged;
102102
uint8_t debugPrintCounter;
103103
openserial_rsvpt* registeredCmd;
104+
uint8_t reset_timerId;
104105
uint8_t debugPrint_timerId;
105106
// input
106107
uint8_t inputBuf[SERIAL_INPUT_BUFFER_SIZE];

drivers/common/opentimers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//=========================== define ==========================================
2020

2121
/// Maximum number of timers that can run concurrently
22-
#define MAX_NUM_TIMERS 10
22+
#define MAX_NUM_TIMERS 15
2323
#define MAX_TICKS_IN_SINGLE_CLOCK (uint32_t)(((PORT_TIMER_WIDTH)0xFFFFFFFF)>>1)
2424
#define ERROR_NO_AVAILABLE_ENTRIES 255
2525
#define MAX_DURATION_ISR 33 // 33@32768Hz = 1ms

inc/opendefs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
static const uint8_t infoStackName[] = "OpenWSN ";
2323
#define OPENWSN_VERSION_MAJOR 1
24-
#define OPENWSN_VERSION_MINOR 21
25-
#define OPENWSN_VERSION_PATCH 4
24+
#define OPENWSN_VERSION_MINOR 22
25+
#define OPENWSN_VERSION_PATCH 0
2626

2727
#ifndef TRUE
2828
#define TRUE 1

openapps/cjoin/cjoin.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ void cjoin_task_cb(void) {
210210
// init the security context only here in order to use the latest joinKey
211211
// that may be set over the serial
212212
// cjoin_init_security_context();
213-
214213
cjoin_sendJoinRequest(joinProxy);
215214

216215
return;
@@ -249,6 +248,7 @@ owerror_t cjoin_sendJoinRequest(open_addr_t* joinProxy) {
249248
);
250249
return E_FAIL;
251250
}
251+
252252
// take ownership over that packet
253253
pkt->creator = COMPONENT_CJOIN;
254254
pkt->owner = COMPONENT_CJOIN;
@@ -292,7 +292,6 @@ owerror_t cjoin_sendJoinRequest(open_addr_t* joinProxy) {
292292
payload_len = cojp_cbor_encode_join_request_object(tmp, &join_request);
293293
packetfunctions_reserveHeaderSize(pkt, payload_len);
294294
memcpy(pkt->payload, tmp, payload_len);
295-
296295
// send
297296
outcome = opencoap_send(
298297
pkt,
@@ -310,7 +309,7 @@ owerror_t cjoin_sendJoinRequest(open_addr_t* joinProxy) {
310309
return E_FAIL;
311310
}
312311

313-
return E_SUCCESS;
312+
return E_SUCCESS;
314313
}
315314

316315
bool cjoin_getIsJoined(void) {

openstack/02a-MAClow/IEEE802154E.c

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -952,39 +952,36 @@ port_INLINE void activity_ti1ORri1(void) {
952952
// check whether we can send
953953
if (schedule_getOkToSend()) {
954954
if (packetfunctions_isBroadcastMulticast(&neighbor)==FALSE){
955-
// this is a dedicated cell
956-
ieee154e_vars.dataToSend = openqueue_macGetDedicatedPacket(&neighbor);
957-
// update numcellpassed and numcellused on dedicated cell
958-
if (ieee154e_vars.dataToSend!=NULL) {
959-
msf_updateCellsUsed(&neighbor);
955+
956+
if (schedule_getShared()){
957+
// this is an autonomous TxRx cell (unicast)
958+
ieee154e_vars.dataToSend = openqueue_macGet6PandJoinPacket(&neighbor);
959+
} else {
960+
// this is a managed Tx cell
961+
ieee154e_vars.dataToSend = openqueue_macGetNonJoinIPv6Packet(&neighbor);
962+
963+
if (ieee154e_vars.dataToSend == NULL){
964+
ieee154e_vars.dataToSend = openqueue_macGetKaPacket(&neighbor);
965+
}
966+
967+
// update numcellpassed and numcellused on managed Tx cell
968+
if (ieee154e_vars.dataToSend!=NULL) {
969+
msf_updateCellsUsed(&neighbor);
970+
}
971+
msf_updateCellsPassed(&neighbor);
960972
}
961-
msf_updateCellsPassed(&neighbor);
962973
} else {
963-
// this is minimal cell
964-
ieee154e_vars.dataToSend = openqueue_macGetDataPacket(&neighbor);
965-
if ((ieee154e_vars.dataToSend==NULL) && (cellType==CELLTYPE_TXRX)) {
966-
couldSendEB=TRUE;
967-
// look for an EB packet in the queue
968-
ieee154e_vars.dataToSend = openqueue_macGetEBPacket();
969-
} else {
970-
// there is a packet to send
971-
if (
972-
schedule_hasDedicatedCellToNeighbor(&ieee154e_vars.dataToSend->l2_nextORpreviousHop)
973-
) {
974-
// allow sixtop response with SEQNUM_ERR return code send on minimal cell
975-
if (
976-
ieee154e_vars.dataToSend->creator!=COMPONENT_SIXTOP_RES ||
977-
ieee154e_vars.dataToSend->l2_sixtop_returnCode != IANA_6TOP_RC_SEQNUM_ERR
978-
) {
979-
// leave the packet to be sent on dedicated cell and pick up a broadcast packet.
980-
ieee154e_vars.dataToSend = openqueue_macGetDIOPacket();
981-
if (ieee154e_vars.dataToSend==NULL){
982-
couldSendEB=TRUE;
983-
// look for an EB packet in the queue
984-
ieee154e_vars.dataToSend = openqueue_macGetEBPacket();
985-
}
986-
}
974+
if (schedule_getShared()) {
975+
// this is minimal cell
976+
ieee154e_vars.dataToSend = openqueue_macGetDIOPacket();
977+
if (ieee154e_vars.dataToSend==NULL){
978+
couldSendEB=TRUE;
979+
// look for an EB packet in the queue
980+
ieee154e_vars.dataToSend = openqueue_macGetEBPacket();
987981
}
982+
} else {
983+
// this is autonomous TXRX cell (anycast)
984+
ieee154e_vars.dataToSend = openqueue_macGetDownStreamPacket(&neighbor);
988985
}
989986
}
990987
}
@@ -1920,7 +1917,7 @@ port_INLINE void activity_ri5(PORT_TIMER_WIDTH capturedTime) {
19201917
} else {
19211918
// synchronize to the received packet if I'm not a DAGroot and this is my preferred parent
19221919
// or in case I'm in the middle of the join process when parent is not yet selected
1923-
// or in case I don't have a dedicated cell to my parent yet
1920+
// or in case I don't have an autonomous Tx cell cell to my parent yet
19241921
if (
19251922
idmanager_getIsDAGroot() == FALSE &&
19261923
(
@@ -1929,7 +1926,7 @@ port_INLINE void activity_ri5(PORT_TIMER_WIDTH capturedTime) {
19291926
icmpv6rpl_getPreferredParentEui64(&addressToWrite) == FALSE ||
19301927
(
19311928
icmpv6rpl_getPreferredParentEui64(&addressToWrite) &&
1932-
schedule_hasDedicatedCellToNeighbor(&addressToWrite)== FALSE
1929+
schedule_hasManagedTxCellToNeighbor(&addressToWrite)== FALSE
19331930
)
19341931
)
19351932
) {

openstack/02a-MAClow/IEEE802154E.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ static const uint8_t ebIEsBytestream[] = {
4242
#define TX_POWER 31 // 1=-25dBm, 31=0dBm (max value)
4343
#define RESYNCHRONIZATIONGUARD 5 // in 32kHz ticks. min distance to the end of the slot to successfully synchronize
4444
#define US_PER_TICK 30 // number of us per 32kHz clock tick
45-
#define MAXKAPERIOD 1000 // in slots: 2000@15ms per slot -> ~30 seconds. Max value used by adaptive synchronization.
46-
#define DESYNCTIMEOUT 2333 // in slots: 2333@15ms per slot -> ~35 seconds. A larger DESYNCTIMEOUT is needed if using a larger KATIMEOUT.
45+
#define MAXKAPERIOD 1000 // in slots: 1500@20ms per slot -> ~30 seconds. Max value used by adaptive synchronization.
46+
#define DESYNCTIMEOUT 1750 // in slots: 1750@20ms per slot -> ~35 seconds. A larger DESYNCTIMEOUT is needed if using a larger KATIMEOUT.
4747
#define LIMITLARGETIMECORRECTION 5 // threshold number of ticks to declare a timeCorrection "large"
4848
#define LENGTH_IEEE154_MAX 128 // max length of a valid radio packet
4949
#define DUTY_CYCLE_WINDOW_LIMIT (0xFFFFFFFF>>1) // limit of the dutycycle window

openstack/02b-MAChigh/msf.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "idmanager.h"
1010
#include "icmpv6rpl.h"
1111
#include "IEEE802154E.h"
12+
#include "openqueue.h"
1213

1314
//=========================== definition =====================================
1415

@@ -37,6 +38,9 @@ void msf_housekeeping(void);
3738
//=========================== public ==========================================
3839

3940
void msf_init(void) {
41+
42+
open_addr_t temp_neighbor;
43+
4044
memset(&msf_vars,0,sizeof(msf_vars_t));
4145
msf_vars.numAppPacketsPerSlotFrame = 0;
4246
sixtop_setSFcallback(
@@ -45,6 +49,17 @@ void msf_init(void) {
4549
(sixtop_sf_translatemetadata)msf_translateMetadata,
4650
(sixtop_sf_handle_callback)msf_handleRCError
4751
);
52+
53+
memset(&temp_neighbor,0,sizeof(temp_neighbor));
54+
temp_neighbor.type = ADDR_ANYCAST;
55+
schedule_addActiveSlot(
56+
msf_hashFunction_getSlotoffset(256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+idmanager_getMyID(ADDR_64B)->addr_64b[7]), // slot offset
57+
CELLTYPE_TXRX, // type of slot
58+
FALSE, // shared?
59+
msf_hashFunction_getChanneloffset(256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+idmanager_getMyID(ADDR_64B)->addr_64b[7]), // channel offset
60+
&temp_neighbor // neighbor
61+
);
62+
4863
msf_vars.housekeepingTimerId = opentimers_create(TIMER_GENERAL_PURPOSE);
4964
msf_vars.housekeepingPeriod = HOUSEKEEPING_PERIOD;
5065
opentimers_scheduleIn(
@@ -89,7 +104,7 @@ void msf_updateCellsUsed(open_addr_t* neighbor){
89104

90105
void msf_trigger6pClear(open_addr_t* neighbor){
91106

92-
if (schedule_hasDedicatedCellToNeighbor(neighbor)>0){
107+
if (schedule_hasManagedTxCellToNeighbor(neighbor)){
93108
sixtop_request(
94109
IANA_6TOP_CMD_CLEAR, // code
95110
neighbor, // neighbor
@@ -171,6 +186,8 @@ void msf_timer_housekeeping_cb(opentimers_id_t id){
171186
opentimers_updateDuration(msf_vars.housekeepingTimerId, newDuration);
172187
}
173188

189+
//=========================== tasks ============================================
190+
174191
void msf_timer_housekeeping_task(void){
175192

176193
msf_housekeeping();
@@ -257,8 +274,8 @@ void msf_trigger6pDelete(void){
257274
return;
258275
}
259276

260-
if (schedule_getNumberOfDedicatedCells(&neighbor)<=1){
261-
// at least one dedicated cell presents
277+
if (schedule_getNumberOfManagedTxCells(&neighbor)<=1){
278+
// at least one managed Tx cell presents
262279
return;
263280
}
264281

@@ -356,7 +373,8 @@ void msf_housekeeping(void){
356373
if (foundNeighbor==FALSE) {
357374
return;
358375
}
359-
if (schedule_getNumberOfDedicatedCells(&parentNeighbor)==0){
376+
377+
if (schedule_getNumberOfManagedTxCells(&parentNeighbor)==0){
360378
msf_trigger6pAdd();
361379
return;
362380
}
@@ -387,4 +405,15 @@ void msf_housekeeping(void){
387405
0 // list command maximum celllist (not used)
388406
);
389407
}
408+
}
409+
410+
uint16_t msf_hashFunction_getSlotoffset(uint16_t moteId){
411+
412+
return SCHEDULE_MINIMAL_6TISCH_ACTIVE_CELLS + \
413+
(moteId%(SLOTFRAME_LENGTH-SCHEDULE_MINIMAL_6TISCH_ACTIVE_CELLS));
414+
}
415+
416+
uint8_t msf_hashFunction_getChanneloffset(uint16_t moteId){
417+
418+
return moteId%NUM_CHANNELS;
390419
}

openstack/02b-MAChigh/msf.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//=========================== define ==========================================
1414

1515
#define IANA_6TISCH_SFID_MSF 0
16-
#define CELLOPTIONS_MSF CELLOPTIONS_TX | CELLOPTIONS_RX | CELLOPTIONS_SHARED
16+
#define CELLOPTIONS_MSF CELLOPTIONS_TX
1717
#define NUMCELLS_MSF 1
1818

1919
#define MAX_NUMCELLS 16
@@ -60,6 +60,9 @@ void msf_updateCellsPassed(open_addr_t* neighbor);
6060
void msf_updateCellsUsed(open_addr_t* neighbor);
6161
// called by icmpv6rpl, where parent changed
6262
void msf_trigger6pClear(open_addr_t* neighbor);
63+
64+
uint16_t msf_hashFunction_getSlotoffset(uint16_t moteId);
65+
uint8_t msf_hashFunction_getChanneloffset(uint16_t moteId);
6366
/**
6467
\}
6568
\}

0 commit comments

Comments
 (0)