📄 xnpm.nc
字号:
//if at end - clear bMissingCapsules flag and exit if( pEEB[POS_STYPE] == SREC_S9 ) { bCIDMissing = FALSE; wCIDMissing = 0; wCIDMissingPrevious = 1; //wrap around so next REQ will check again DoneEveryCapsules = TRUE; bCommandOK = CMD_STATE_DONE; // if(bAckMessage) //no response if at end... // fNPXSendStatus(); sSYSState = SYS_GETDONE; //we are finished#ifdef PLATFORM_MICA2DOT call Leds.redOn(); //turn on => Program is loaded and OK#endif call Leds.greenOn(); //diagnostic post NPX_STATEMACHINE();//fetch srec from eeprom flash break; } wCapsuleNo = wCID+1; //advance to next CID wEE_LineR = wEEProgStart+ (wCapsuleNo<<1); //2 lines per srec // wEE_LineR = wEE_LineR+2; //advance to next srec locaction sSYSState = SYS_GETNEXTCID; bEELineReadPending = TRUE; //main state machine handles posting task and busy retries post NPX_STATEMACHINE();//store srec to eeprom or other operation } break; } //switch return( 1 ); } /************************************************************************* fProcessMissingCapsule Location of a missing capsule Set flags for future request to network *************************************************************************/ void fProcessMissingCapsule(uint16_t wlPID, uint16_t wlCIDMissing){ uint16_t wPacketTime; bCIDMissing = TRUE; wCIDMissing = wlCIDMissing; wCIDMissingPrevious = wCIDMissing; //forces next scan to verify it has been fixed if( bAckMessage ) { //xmit request if network allows it //introduce a random delay before TXing the request - in multiples of Packet time //8MHz CPU clock =>256 instructions per packet time at 38.4KBaud // call Leds.redOn(); //diagnostic wCIDMissing = call Random.rand(); //should be multiples of Packet Time wTXReqDelay = (wCIDMissing & 0x000f) +1; wPacketTime = DELAY_PACKETTIME; while (wTXReqDelay ) { while(wPacketTime) wPacketTime--; wPacketTime = DELAY_PACKETTIME; wTXReqDelay--; } //call Leds.redOff(); //diagnostic fReqMissingCapsule(wlPID,wlCIDMissing); //tx request } sSYSMState = SYSM_UPDATE; //allow random srec updates in this mote sSYSState = SYS_GETDONE; //we are finished for this scan post NPX_STATEMACHINE();// return; } /************************************************************************* fDownLoadAbort Abort and return to idle state *************************************************************************/ void fDownLoadAbort(){ sSYSState = SYS_DL_ABORT; sSYSMState = SYS_IDLE; post NPX_STATEMACHINE(); return; } /************************************************************************* fSendStatus Build a Status TOS message and Send it to Generic Com if RF not busy *************************************************************************/ void fNPXSendStatus() { uint8_t i; //ptrmsg->data[0] = 32; //NESC's TOS MEssage Length ptrmsg->data[TS_CMD] = CMD_DOWNLOAD_STATUS; ptrmsg->data[TS_SUBCMD] = TOS_LOCAL_ADDRESS; // lsbye of moteid ptrmsg->data[TS_PID] = wProgramID; //who I am ptrmsg->data[TS_PID+1] = wProgramID>>8; //msg id ptrmsg->data[TS_CAPSULEID] = wCapsuleNo; //reserved- extended msg type ptrmsg->data[TS_CAPSULEID+1] = wCapsuleNo>>8; //reserved- extended msg type ptrmsg->data[TS_MSGDATA] = cCommand; //reserved- extended msg type ptrmsg->data[TS_MSGDATA+1] = bCommandOK; //Last command recevied/processed for (i=8;i<20;i++ ) { ptrmsg->data[i] = i; //fill } TOSMsgType = MSG_COMMAND; //command response message is xmitting if( bTOSMsgBusy == FALSE ){ bTOSMsgBusy = call SendMsg.send(TOS_LOCAL_ADDRESS, DATA_LENGTH29,ptrmsg); } return; } //fStatus /************************************************************************* fSendPIDStatus Build a Status TOS message and Send it to Generic Com if RF not busy *************************************************************************/ void fNPXSendPIDStatus(uint16_t wlPID) { uint8_t i; //ptrmsg->data[0] = 32; //NESC's TOS MEssage Length ptrmsg->data[TS_CMD] = CMD_GET_PIDSTATUS; ptrmsg->data[TS_SUBCMD] = TOS_LOCAL_ADDRESS; // lsbye of moteid ptrmsg->data[TS_PID] = wlPID; //who I am ptrmsg->data[TS_PID+1] = wlPID>>8; //msg id ptrmsg->data[TS_CAPSULEID] = 0; //reserved- extended msg type ptrmsg->data[TS_CAPSULEID+1] = 0; //reserved- extended msg type ptrmsg->data[TS_MSGDATA] = cCommand; //reserved- extended msg type ptrmsg->data[TS_MSGDATA+1] = bCommandOK; //Last command recevied/processed for (i=8;i<20;i++ ) { ptrmsg->data[i] = i; //fill } TOSMsgType = MSG_COMMAND; //command response message is xmitting if( bTOSMsgBusy == FALSE ){ bTOSMsgBusy = call SendMsg.send(TOS_LOCAL_ADDRESS, DATA_LENGTH29,ptrmsg); } return; } //fPIDStatus /************************************************************************* fNPXInSystemProgramExec Execute ISP using specfied ProgID *************************************************************************/ void fNPXInSystemProgramExec(TOS_MsgPtr msgptr){ uint16_t *wptr; wptr = (uint16_t *)&(msgptr->data[TS_PID]); wProgramID = *wptr++; EE_PageW = EE_PAGE_START; wEEProgStart = EE_PageW<<4;//the starting point in EEFlash //check EEFLASH to verify this programID is present fNPXGetEEProgID(wEEProgStart); //check valid progid and invoke ISP //EEProgID invokes ISP if all ok return; }//fNPXInSystemProgramExec /************************************************************************* fReqMissingCapsule Request a missing capsule *************************************************************************/ void fReqMissingCapsule(uint16_t wlPID, uint16_t wlCIDMissing) { uint8_t i; if( bCIDMissing ) bCommandOK = CMD_STATE_REQCID; else bCommandOK = CMD_STATE_DONE; //no CID requested if (bTOSMsgBusy) return; wlCIDMissing--; //Network wants CID 0 based on return but 1 on xmit ptrmsg->data[TS_CMD] = CMD_REQ_CIDMISSING; ptrmsg->data[TS_SUBCMD] = TOS_LOCAL_ADDRESS; // lsbye of moteid ptrmsg->data[TS_PID] = wlPID; //who I am... or want to be.... ptrmsg->data[TS_PID+1] = wlPID>>8; //msg id ptrmsg->data[TS_CAPSULEID] = wlCIDMissing; //e ptrmsg->data[TS_CAPSULEID+1] = wlCIDMissing>>8; //pe ptrmsg->data[TS_MSGDATA] = cCommand; ptrmsg->data[TS_MSGDATA+1] = bCommandOK; for (i=8;i<20;i++ ) { ptrmsg->data[i] = i; //fill } wlCIDMissing++; //restore to 1 based TOSMsgType = MSG_COMMAND; //command response message is xmitting if( bTOSMsgBusy == FALSE ){ bTOSMsgBusy = call SendMsg.send(TOS_LOCAL_ADDRESS, DATA_LENGTH29,ptrmsg); } return; } //fmissingcid /************************************************************************* fDownloadComplete Request a missing capsule *************************************************************************/ void fDownloadComplete(uint16_t wlPID) { uint8_t i; bCommandOK = CMD_STATE_DONE; //no CID requested if (bTOSMsgBusy) return; ptrmsg->data[TS_CMD] = CMD_QUERY_COMPLETE; ptrmsg->data[TS_SUBCMD] = TOS_LOCAL_ADDRESS; // lsbye of moteid ptrmsg->data[TS_PID] = wlPID; //who I am... or want to be.... ptrmsg->data[TS_PID+1] = wlPID>>8; //msg id ptrmsg->data[TS_CAPSULEID] = 0; // not used ptrmsg->data[TS_CAPSULEID+1] = 0; // not used ptrmsg->data[TS_MSGDATA] = cCommand; ptrmsg->data[TS_MSGDATA+1] = bCommandOK; for (i=8;i<20;i++ ) { ptrmsg->data[i] = i; //fill } TOSMsgType = MSG_COMMAND; //command response message is xmitting if( bTOSMsgBusy == FALSE ){ bTOSMsgBusy = call SendMsg.send(TOS_LOCAL_ADDRESS, DATA_LENGTH29,ptrmsg); } return; } // fDownloadComplete /************************************************************************* fNPXSRECParse Got a code capsule containing 1 srec from radio [0]:commandid [1.2]:program id [3:4]:nofcapsules (srecords) Computes destination EEFlash address based on SREC address and stores in EEFlash. Does NOT respond to Host - this used during Broadcast downloads. Accepts non-contiguous srecs. If bEEPROMBusy we abort because EEBuf is not available NOTE 1. Changes sSYSState if last/S9 record Copies into a local buffer for passing to EEFLASH driver. The source buffer (TOSMsg) is not available after function returns because TOS reuses it. *************************************************************************/ uint8_t fNPXSRECParse(TOS_MsgPtr msgptr) { uint8_t i,j; //uint16_t wTemp; //uint8_t cTemp; uint8_t cLen; uint8_t cSRecType; uint8_t bSRecValid; //uint8_t bFini = FALSE; //uint16_t *wptr; uint8_t cCheckSum; bSRecValid = TRUE; //assume we can parse the sREC //Verify Checksum cLen = msgptr->data[TS_LEN]; //get nof bytes in srec cCheckSum = 0; for (j=TS_LEN;j<TS_LEN+cLen;j++ ) cCheckSum = cCheckSum + msgptr->data[j]; cCheckSum = ~cCheckSum; if( cCheckSum != (uint8_t)msgptr->data[j]) //j is sitting at srec checksum return(FALSE); //bad so ignore if( bEEPROMBusy ) return(FALSE); //busy so ignore cSRecType = msgptr->data[TS_TYPE]; switch ( cSRecType ) { case SREC_S1: /*--------------------------------------------------------------------------- Build S1 in binary format-2byte address field S11300700C9463000C9463000C9463000C94630070 S11300800C9463000C9463000C94630011241FBE51 S1130090CFEFD0E1DEBFCDBF11E0A0E0B1E0EAEEEA ----------------------------------------------------------------------------*/ // TOS_CALL_COMMAND(RED_LED_TOGGLE)(); //diag ELBuff[POS_PID] = wProgramID; ELBuff[POS_PID+1] = wProgramID>>8; ELBuff[POS_CID] = msgptr->data[TS_CAPSULEID]; ELBuff[POS_CID+1] = msgptr->data[TS_CAPSULEID+1]; //Build an SREC Format ELBuff[POS_STYPE] = SREC_S1; ELBuff[POS_SNOFB] = cLen = msgptr->data[TS_LEN]; //get nof bytes in srec ELBuff[POS_S1_ADDR] = msgptr->data[TS1_ADDR_LSB]; //lsbyte of address ELBuff[POS_S1_ADDR+1] = msgptr->data[TS1_ADDR_MSB]; //mostbyte of address //fill the buffer with data section of the SRec w/ lsbyte first cLen = (cLen - 3); //nof Instructions (bytes) for (i=POS_S1_I0,j=TS_INSTR0_MSB;i<POS_S1_I0+cLen;i++,j++ ) { ELBuff[i] = msgptr->data[j]; //get lsbyte // ELBuff[i+1] = msgptr->data[j]; //get msbyte } //place holder for binary computed checksum - i is sitting at correct position ELBuff[i] = 0x77; //diag-indicates stored via SRECStore //fill rest of buffer for (j=i+1;j<32;j++) ELBuff[j] = j; //fillbytes break; //SRec S1 case SREC_S9: //s9 contains boot address - and is last record of sfile // S9030000FC ELBuff[POS_PID] = wProgramID; ELBuff[POS_PID+1] = wProgramID>>8; //Store CapsuleID ELBuff[POS_CID] = msgptr->data[TS_CAPSULEID]; ELBuff[POS_CID+1] = msgptr->data[TS_CAPSULEID+1]; //Build an SREC Format ELBuff[POS_STYPE] = SREC_S9; //srec9 only has 2byte address ELBuff[POS_SNOFB] = cLen = msgptr->data[TS_LEN]; //get nof bytes in srec ELBuff[POS_S1_ADDR] = msgptr->data[TS1_ADDR_LSB]; //lsbyte of address ELBuff[POS_S1_ADDR+1] = msgptr->data[TS1_ADDR_MSB]; //midsbyte of address // bFini = TRUE; / break; default: bSRecValid = FALSE; //unrecognized sREC break; //unknown SRec type }//switch srectype return(bSRecValid); }//fNPXSRECParse /************************************************************************* fSysVarInit Init all VARS to defaults *************************************************************************/ void fNPXSysVarInit() {#ifdef JTAG TOS_LOCAL_ADDRESS = TOS_LOCAL; //local address set in client#endif sSYSState = SYS_IDLE; // sSYSState = SYS_BEACON; // post NPX_STATEMACHINE();//store srec to eepromn //Netprogramming stuff cCommand = 0; //current command bCommandOK = FALSE; //current command processed ok wCapsuleNo = 0; //code capsule number wNofCapsules = 0; //expected number of capsules wEEProgStart = 0; bEEWriteEnabled = 0; //no EEFLASH after init EE_PageW = EE_PAGE_START; wEEProgStart = EE_PageW<<4; wLastEEPage = EEPROM_NOFPAGES-1; //maxnof lines in EEPROM bEEPROMBusy = 0; //EPROM available to write bEELineWritePending = FALSE; bELBuffAWE = TRUE; //BufferA or B selected for write enable bELBuffFull = FALSE; //EEPROM buffer is full and should be flushed cLineinPage = 0; //reset the line count TOSMsgType = MSG_IDLE; itest = 240; btest = 0; //0:no test pattern //Init message parameters pNETTOSMsg = &NETTOSMsg; //rx buffer ptrmsg = &msg; //init pointer to tx buffer bTOSMsgBusy = 0; //no message pending bNXPMsgBusy = FALSE; itest = TOS_LOCAL_ADDRESS; return; }//fSysVarInit } //end implementation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -