⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xnpm.nc

📁 传感器网络中的嵌入式操作系统源代码
💻 NC
📖 第 1 页 / 共 5 页
字号:
	bNXPMsgBusy = FALSE;	break;      case SYS_ISP_REQ:	wptr = (uint16_t *)&(pNETTOSMsg->data[TS_PID]);	wProgramID = *wptr++;	EE_PageW = EE_PAGE_START;	wEEProgStart = EE_PageW<<4;//the starting point in EEFlash	//check EEFLASH Capsule #1 (2lines per capsule)to verify this programID is present	wEE_LineR = wEEProgStart+2;	//Capsule#0 is legacy/expansion-future	bEELineReadPending = TRUE;	//statemachine handles retries etc	cNextState = SYS_ISP_REQ1;		bRePost = TRUE;	break;      case SYS_ISP_REQ1:      case SYS_GETNEXTCID:	   //have read 1st half of srec from FLASH	if( bEELineReadPending ){#ifdef PLATFORM_MICA2DOT	  call Leds.redOn();	   //led off during read/missing capsule check, ON at end if ok#endif	  call Leds.yellowOn();       	  call EEPROMRead.read(wEE_LineR, (uint8_t*)&ELBuff );	}	//if fail do what? - go idle?	break;      case SYS_ACK: //send ack to network if required and then go idle	if(bAckMessage ) //acknowledge to network	  fNPXSendStatus();	bNXPMsgBusy = FALSE;	call Leds.redOff();           //diagnostic 	cNextState = SYS_IDLE;	break;	      case SYS_GETDONE:	call Leds.yellowOff();       	//	sSYSMState = SYS_IDLE;		//no ack and leaves LED ON	cNextState = SYS_IDLE;	bNXPMsgBusy = FALSE;	break;      case SYS_BEACON:	//	call Leds.redOn();           //diagnostic 	//	fNPXSendStatus();	if( !bTOSMsgBusy )	  fProcessMissingCapsule(wProgramID, wCapsuleNo);	bRePost = TRUE;	//re-execute NPX_STATEMACHINE	//	call Leds.redOff();           //diagnostic 	break;      default:	break;      }	//switch    // update state    sSYSState = cNextState; //this updates BEFORE any new tasks start    if( bRePost )      post NPX_STATEMACHINE(); //try again    return;  }//TASK NXP Statemachine	  /*****************************************************************************     receive()     - message from newtork  ******************************************************************************/  event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr msgptr) {    uint16_t *wptr;    uint8_t cNextState;    TOS_MsgPtr pPrevious;    //Filter for correct GROUP_ID and MOTEID for GSK compatibility    if (msgptr->group != TOS_AM_GROUP) return msgptr;    if ((msgptr->addr != TOS_BCAST_ADDR) && (msgptr->addr != TOS_LOCAL_ADDRESS) )return msgptr;    if (bTOSMsgBusy) return msgptr;    if (bNXPMsgBusy) return msgptr;    //call Leds.yellowOff();    call Leds.greenOff();           //leds off    call Leds.redOn();           //diagnostic - turns off at exit of statemachine SYS_ACK    bNXPMsgBusy = TRUE;    pPrevious = pNETTOSMsg;	//save ptr to previous buffer    pNETTOSMsg = msgptr;	  //point to new buffer    cNextState = sSYSState; //statemachine updates    // -------LOCAL COMMANDS addressed to this specific node    if( (msgptr->addr == TOS_LOCAL_ADDRESS) )      {	cCommand = msgptr->data[TS_CMD]; //save the netprog command ID	cSubCommand = msgptr->data[TS_SUBCMD]; //save the  command ID	bCommandOK= CMD_STATE_UKNOWN;	 //default we don't recognize it	bBCASTMsg = FALSE;	bAckMessage = TRUE;	switch (cCommand)	     //was [4]	  {	  case CMD_RST:	 //REBOOT	    xnp_reboot();	    break;	  case CMD_DOWNLOAD_STATUS:	    bCommandOK= CMD_STATE_DONE;	 //status command req reqognized	    cNextState = SYS_ACK;	    break;	  case CMD_STATUS:	//Get node status	    bCommandOK= CMD_STATE_DONE;	 //status command req reqognized	    cNextState = SYS_ACK;	    break; 				  case CMD_START_DOWNLOAD: //Header info for a code download	    //		    fNPXStartDownload(pNETTOSMsg);	    cNextState = SYS_DL_START;	    break;	  case CMD_DOWNLOADING:	    if(sSYSMState==SYSM_DOWNLOAD)	      cNextState = SYS_DL_SRECWRITE;	    else if (sSYSMState == SYSM_UPDATE)	      cNextState = SYS_UP_SRECWRITE;	    else cNextState = SYS_ACK; //ignore	    break;	  case CMD_DOWNLOAD_COMPLETE:	    cNextState = SYS_DL_END;	    break;	  case CMD_ISP_EXEC:	    cNextState = SYS_ISP_REQ;	    break;	  case CMD_GET_CIDMISSING:	    //			wptr = &(pNETTOSMsg->data[TS_PID]);	//tests are done in statemachine	    //			wProgramID = *wptr;	    cNextState = SYS_REQ_CIDMISSING;	    break;	  case CMD_GET_PIDSTATUS:	    fNPXGetProgramID(pNETTOSMsg);	    bNXPMsgBusy = FALSE;	    call Leds.redOff();           //diagnostic - turns off at exit 	    break;	  default:	    //			call Leds.yellowOn(); 	    cNextState = SYS_ACK;	    break; //invalid command	  }//switch command	sSYSState = cNextState;	post NPX_STATEMACHINE(); //try again	return pPrevious;	//TOS LOCAL COmmand exit  - return original buffer??      } // if TOS_LOCAL_ADDRESS    // -------TOS_BCAST_ADDR COMMANDS addressed to this specific node    if( (msgptr->addr == TOS_BCAST_ADDR) )      {	cCommand = msgptr->data[TS_CMD]; //save the  command ID	cSubCommand = msgptr->data[TS_SUBCMD]; //save the  command ID	bCommandOK= CMD_STATE_UKNOWN;	 //default we don't recognize it	bBCASTMsg = TRUE;	bAckMessage = FALSE;  //bydefault no message acknowledment	switch (cCommand)	     //was [4]	  {	  case CMD_START_DOWNLOAD: //Header info for a code downloaf	    if( cSubCommand == TOS_LOCAL_ADDRESS )	      bAckMessage = TRUE; //acknowledge broadcast message	    DoneEveryCapsules = FALSE;	    cNextState = SYS_DL_START;	    break;	  case CMD_DOWNLOADING:	    if( cSubCommand == TOS_LOCAL_ADDRESS )	      bAckMessage = TRUE; //acknowledge broadcast message	    if(sSYSMState==SYSM_DOWNLOAD)	      cNextState = SYS_DL_SRECWRITE;	    else if (sSYSMState == SYSM_UPDATE)	      cNextState = SYS_UP_SRECWRITE;	    else 	      cNextState = SYS_ACK;	    break;	  case CMD_DOWNLOAD_COMPLETE:	    if( cSubCommand == TOS_LOCAL_ADDRESS )	      bAckMessage = TRUE; //acknowledge broadcast message	    cNextState = SYS_DL_END;	    break;	  case CMD_ISP_EXEC:	    cNextState = SYS_ISP_REQ;	    break;	  case CMD_GET_PIDSTATUS:	    fNPXGetProgramID(pNETTOSMsg);	    bNXPMsgBusy = FALSE;	    call Leds.redOff();           //diagnostic - turns off at exit 	    break;	  case CMD_GET_CIDMISSING:	    wptr = (uint16_t*)(&(msgptr->data[TS_PID]));	    if( (cSubCommand == TOS_LOCAL_ADDRESS) || (!cSubCommand) ){ //for this mote or all motes (subC==0)	      bAckMessage = TRUE; //acknowledge broadcast message	    }	    if( wProgramID != *wptr)	      bAckMessage = FALSE; //keep quiet if incorrect ProgramID - but call statemachine for cleanup	    // added so that the PC side gets reply.	    // reply to PC side if finished scan of EEPROM 	    // and the query is destined to this mote  	    if (DoneEveryCapsules &&			(cSubCommand == TOS_LOCAL_ADDRESS) ) {	      fDownloadComplete(wProgramID);	    } else {	      cNextState = SYS_REQ_CIDMISSING;	    }	    break;	  default:	    cNextState = SYS_ACK;            break; //invalid command	  }//switch command	sSYSState = cNextState;	post NPX_STATEMACHINE(); //try again	return msgptr;	//TOS broadcast COmmand exit  - return original buffer??      } // if TOS_BCAST    sSYSState = cNextState;    return pPrevious;  }//NPX_TOSMsg_Rx  /*****************************************************************************    SendDone    TOS Message Sent  *****************************************************************************/  event result_t SendMsg.sendDone(TOS_MsgPtr msg_rcv, bool success) {        bTOSMsgBusy = 0;            //broadcast message complete    ptrmsg = msg_rcv;               //hold onto the buffer for next message    switch( TOSMsgType )  {    default:      TOSMsgType = MSG_IDLE;              //command message complete      break;    }    return(1);	  }//MSG_SEND_DONE  /*****************************************************************************     writeDone     - EEPROM finished writing a line of data to eprom buffer     If buffer is full, execute EEPROM command to flush buffer into ROM     Note that during this flush, line writing can continue by writing into alternate     buffer.     bEEPROMBusy is NOT set during FLUSH operation.     Need to add EEPROM_GetStatus to check EEPROM is idle before doing FLUSH     A flush of 256byte page takes 20mSec + some overhead      20msec/256bytes = 78uSec/byte or ~100Kbit/sec  *****************************************************************************/  event result_t EEPROMWrite.writeDone(uint8_t *buf){    uint8_t cRet;    if(bEELine1 )	{  //write 2nd line out-still busy      bEELine1 = FALSE;      cRet = call EEPROMWrite.write(wEE_LineW, (uint8_t*)&ELBuff[ELBUFF_SIZE/2]);      //wEE_LineW++;	 //EELine now maintained by SREC Parser      return( TRUE );    }      bEEPROMBusy=0;    post NPX_STATEMACHINE(); //execute the NPX Statemachine for next state    return( TRUE) ;   }  /*****************************************************************************     endWriteDone()     -  finished use of  eeprom for writing - release resource  *****************************************************************************/  event result_t EEPROMWrite.endWriteDone(result_t success){    bEEWriteContinuous = FALSE;    bEEWriteEnabled = 0;          //disable writing    post NPX_STATEMACHINE(); //execute the NPX Statemachine for next state    return(success);	 //1=success  }  /******************************************************************************   * NPX_SET_IDS   * -Check to see if Mote_Id and Group_Id are in Atmega eeprom. If so, use them   * -If values returned have 0xff byte values then eeprom was erased and    *  never written. Default to original values stored in Atmega code space.   * -If values returned <>0xff then assume the Mote_Id and Group_Id were    *  stored in eeprom during net reprogramming.   ******************************************************************************/  command result_t Xnp.NPX_SET_IDS(){    uint8_t  cTemp;    uint16_t wTemp;    uint32_t ts;    call TS.get_timestamp(&ts);    if((cTemp=eeprom_read_byte ((uint8_t *)AVREEPROM_GROUPID_ADDR)) != 0xFF )      TOS_AM_GROUP = cTemp;    if((wTemp=eeprom_read_word ((uint16_t *)AVREEPROM_LOCALID_ADDR)) != 0xFFFF )      atomic TOS_LOCAL_ADDRESS = wTemp;#ifdef JTAG    atomic TOS_LOCAL_ADDRESS = TOS_LOCAL;               //Jtag debug#endif    return SUCCESS;  }  /******************************************************************************   ******************************************************************************/  command uint16_t XnpConfig.getProgramID()    {      return eeprom_read_word( (uint16_t*)AVREEPROM_PID_ADDR );    }  command void XnpConfig.saveGroupID()    {      eeprom_write_byte((uint8_t*)(AVREEPROM_GROUPID_ADDR), TOS_AM_GROUP);    }  /******************************************************************************    NPX_SENDSTATUS    Client can send a status message to Network - diagnostic  ******************************************************************************/  command result_t Xnp.NPX_SENDSTATUS(uint16_t wAck ) {    uint8_t bRet;    wCapsuleNo = wAck; //code capsule number    fNPXSendStatus();    return(1);  }//send  /*****************************************************************************    NPX_ISP_REQ    -Allows application to invoke In System Programming    Caller must supply Program ID and its inverse.    If these do compare function returns - avoids inadvertent call/jump  ******************************************************************************/  command result_t Xnp.NPX_ISP_REQ(uint16_t wProgID, uint16_t wEEPageStart, uint16_t nwProgID){    if( wProgID != ~nwProgID )      return(FALSE);    wEEProgStart = wEEPageStart<<4;	  //translate to line number    wProgramID = wProgID;    fNPXGetEEProgID(wEEProgStart); //check valid progid and invoke ISP    return(SUCCESS);  //not quite correct - wait for result of GetEEProgID  }  /*************************************************************************    fStartDownload    Get header info for upcoming code download    Signal CLient application for Request

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -