//********************************************* static void restart_to_other_type(void) { NLME_InitNV(); NLME_SetDefaultNV(); osal_nv_write( ZCD_NV_LOGICAL_TYPE, 0, sizeof(zgDeviceLogicalType), &zgDeviceLogicalType); SystemReset(); }
void task_system_loop() { wdt_reset(); //task switching outside interrupt if (new_task != actual_task) { DEBUG("Switching task %d to %d\n", actual_task, new_task); if (actual_task != NO_TASK) { task_stop_array[actual_task](); //XXX: this will guarantee that task switched from the powerdown task will be vanilla if (new_task == TASK_POWERDOWN) SystemReset(); } actual_task = new_task; task_init_array[actual_task](); } //check USB and send IRQ if (usb_state != USB_CONNECTED) { usb_state = USB_CONNECTED; task_irqh(TASK_IRQ_USB, &usb_state); } buttons_step(); if (powerdown_lock.Active() == false) { battery_step(); } }
/********************************************************************* * @fn OTA_ProcSysAppMsg * * @brief Handles sys app messages from the server application. * * @param pMsg - The message from the server. * * @return none */ void OTA_ProcSysAppMsg(mtSysAppMsg_t *pMsg) { uint8 cmd; if (pMsg == NULL) return; cmd = *pMsg->appData++; switch(cmd) { case OTA_APP_READ_ATTRIBUTE_REQ: OTA_ProcessSysApp_ReadAttrReq(pMsg->appData); break; case OTA_APP_IMAGE_NOTIFY_REQ: OTA_ProcessSysApp_ImageNotifyReq(pMsg->appData); break; case OTA_APP_DISCOVERY_REQ: OTA_ProcessSysApp_DiscoveryReq(pMsg->appData); break; case OTA_APP_JOIN_REQ: OTA_ProcessSysApp_JoinReq(pMsg->appData); break; case OTA_APP_LEAVE_REQ: // Simulate a leave by rebooting the dongle SystemReset(); default: break; } }
void TIMER2_isr(void) { unsigned long foo; // Timer for 3219 keep alive response will reset the board since the DOCSIS side has stopped responding // This loop should set off watchdog if DOCSIS ALIVE not received every few seconds timer2counter += 1; if (watchdogbypass == 0) { if (timer2counter == 254) { //This should be about 8 seconds before reset is fired off printf("\r\n"); printf("\r\n************************************************\n"); printf("\r\n*** DOCSIS ALIVE NOT RECEIVED..resetting CMC ***\n"); printf("\r\n************************************************\n"); printf("\r\n"); Timeout3219 = 1; disable_interrupts(INT_TIMER2); //disable timer2 interrupt for 3219 watchdog timer2counter = 0; foo = RandReadI2C(EEPROM_ADDR,WatchdogResets,0); WriteI2C(EEPROM_ADDR,WatchdogResets,foo+1,0); SystemReset(1); } } clear_interrupt(INT_TIMER2); }
void EXT1_isr(void) { // This will reset the system printf("\r\n!!Push Button Reset!!\n"); SystemReset(0); clear_interrupt(INT_EXT1); //clear external interrupt flag enable_interrupts(INT_EXT1); //re-enable interrupt }
CommandStatusIdType CommandExecReset(char* OutMessage) { USB_Detach(); USB_Disable(); SystemReset(); return COMMAND_INFO_OK_ID; }
static void reboot_zigbee(uint8*buf) { uint8 opera_bit; uint8 tmp[4]; opera_bit = buf[1]; switch(opera_bit) { case 0x01://表示清空 NV_RESTORE 保存的内容,然后系统重启 SystemReset(); break; case 0x02://表示清空 NV_RESTORE 保存的内容,将网关设置为“协调器”,然后系统重启 set_coordi(); SystemReset(); break; case 0x03://表示清空 NV_RESTORE 保存的内容,将网关设置为“路由”,然后系统重启 set_router(); SystemReset(); break; case 0x04://表示写模块panid;后面跟panid参数; //04 A8 04 yy xx // 长度 命令 写指令 panid高字节 panid低字节 break; case 0x05: //03 95 yy xx tmp[0] = 0x03; tmp[1] = 0x95; tmp[2] = HI_UINT16(_NIB.nwkPanId); tmp[3] = LO_UINT16(_NIB.nwkPanId); HalUARTWrite(SER_PORT,tmp, 4); break; default:break; } }
void KeyListened(void) { unsigned char sta = KeyStaSwitch(KeyScan()); switch (sta) { case KEY_STA_DOWN : { Lock315Assoc(); } break; case KEY_STA_LHOLD : { SystemReset(); } break; } }
/************************************************************************************************** * @fn MT_SysReset * * @brief Reset the device. * @param typID: 0=reset, 1=serial bootloader * * @return None *************************************************************************************************/ void MT_SysReset(uint8 *pBuf) { if (pBuf[MT_RPC_POS_DAT0] == 0) { SystemReset(); } #if !(defined(HAL_BOARD_F2618) || defined(HAL_BOARD_F5438) || defined(HAL_BOARD_LM3S)) else { SystemResetSoft(); // Especially useful for CC2531 to not break comm with USB Host. } #endif }
void OS_reboot(char flash) { #ifdef FEATURE_OAD_HEADER if (flash) { short zero = 0; uint16 addr = OAD_IMG_B_PAGE * (HAL_FLASH_PAGE_SIZE / HAL_FLASH_WORD_SIZE); HalFlashWrite(addr, (uint8*)&zero, sizeof(zero)); } #else VOID flash; #endif SystemReset(); }
/********************************************************************* * @fn restore_factory_setting * * @brief Restore the device to factory settings. * * @param none * * @return none * *********************************************************************/ void restore_factory_setting( void) { uint8 startOptions; NLME_InitNV(); NLME_SetDefaultNV(); zgWriteStartupOptions( ZG_STARTUP_SET,ZCD_STARTOPT_DEFAULT_NETWORK_STATE ); startOptions = ZCD_STARTOPT_CLEAR_STATE | ZCD_STARTOPT_CLEAR_CONFIG; osal_nv_write(ZCD_NV_STARTUP_OPTION, 0, sizeof(uint8),&startOptions); SystemReset(); }
/************************************************************************************************** * @fn znpBasicCfg * * @brief Process the Conglomerate Basic Configuration command. * * input parameters * * @param pBuf - Pointer to the MT buffer containing the conglomerated configuration. * * output parameters * * None. * * @return None. */ static void znpBasicCfg(uint8 *pBuf) { uint32 t32 = osal_build_uint32( &pBuf[0], 4 ); if (MT_PeriodicMsgRate != t32) { MT_PeriodicMsgRate = t32; (void)osal_start_reload_timer(MT_TaskID, MT_PERIODIC_MSG_EVENT, t32); } t32 = osal_build_uint32( &pBuf[4], 4 ); if (osal_memcmp(&zgDefaultChannelList, &t32, 4) == FALSE) { (void)osal_nv_write(ZCD_NV_CHANLIST, 0, 4, &t32); } uint16 t16 = osal_build_uint16( &pBuf[8] ); if (osal_memcmp(&zgConfigPANID, &t16, 2) == FALSE) { (void)osal_nv_write(ZCD_NV_PANID, 0, 2, &t16); } if (zgDeviceLogicalType != pBuf[10]) { (void)osal_nv_write(ZCD_NV_LOGICAL_TYPE, 0, 1, pBuf+10); } if (pBuf[11] & MT_ZNP_CMD_DISC_RESET_NWK) { pBuf[0] = ZCD_STARTOPT_DEFAULT_NETWORK_STATE; (void)osal_nv_write(ZCD_NV_STARTUP_OPTION, 0, 1, pBuf); #if defined CC2531ZNP SystemResetSoft(); #else SystemReset(); #endif } else if (pBuf[11] & MT_ZNP_CMD_DISC_ZDO_START) { if (devState == DEV_HOLD) { ZDOInitDevice(0); } } }
/********************************************************************* * @fn zclSampleSw_ProcessOTAMsgs * * @brief Called to process callbacks from the ZCL OTA. * * @param none * * @return none */ static void zclSampleSw_ProcessOTAMsgs( zclOTA_CallbackMsg_t* pMsg ) { uint8 RxOnIdle; switch(pMsg->ota_event) { case ZCL_OTA_START_CALLBACK: if (pMsg->hdr.status == ZSuccess) { // Speed up the poll rate RxOnIdle = TRUE; ZMacSetReq( ZMacRxOnIdle, &RxOnIdle ); NLME_SetPollRate( 2000 ); } break; case ZCL_OTA_DL_COMPLETE_CALLBACK: if (pMsg->hdr.status == ZSuccess) { // Reset the CRC Shadow and reboot. The bootloader will see the // CRC shadow has been cleared and switch to the new image HalOTAInvRC(); SystemReset(); } else { // slow the poll rate back down. RxOnIdle = FALSE; ZMacSetReq( ZMacRxOnIdle, &RxOnIdle ); NLME_SetPollRate(DEVICE_POLL_RATE); } break; default: break; } }
virtual void LevelShutdownPreEntity() { SystemReset(); }
void _main_Process(void) { u8 *fname; USART_InitTypeDef USART_InitStruct; u8 temp;u16 recvLenth=0;u32 savelenth=0; KEY_Press kp=KEY_none;char ssid[30]={"SP400-"};char buf[20]={0}; if(isAppExist) printf("|OK|--Boot to Application\n"); else printf("|OK|--Load new ver from SD\n"); printf("| <|--Load factory ver from SD"); printf("| >|--Update form PC\n"); printf("******************************"); kp=readKey(); if(kp==KEY_ok) { if( isAppExist)JumpToApplication(AppProgramAddr); else { Frimware=f_open(&f_bin,"new.bin",FA_OPEN_EXISTING); f_close(&f_bin); if(Frimware==FR_OK) { clearAppVersion(); printf("Firmware Loading......\n"); printf("%d Bytes to load\n",WriteFlashFromFile("new.bin")); printf("Jump To Application\n"); JumpToApplication(AppProgramAddr); } else { printf("Can not found file\n"); } } } else if(kp==KEY_left) { Frimware=f_open(&f_bin,"factory.bin",FA_OPEN_EXISTING); f_close(&f_bin); if(Frimware==FR_OK) { clearAppVersion(); printf("Firmware Loading......\n"); printf("%d Bytes to load\n",WriteFlashFromFile("factory.bin")); printf("Jump To Application\n"); JumpToApplication(AppProgramAddr); } else { printf("Can not found file\n"); } } else if(kp==KEY_right) { printf("Starting Wifi...\n"); EMW_HAL_InitWithDefault(); EMW_Get_Config(&wifi_paraG); memset(wifi_paraG.wifi_ssid,0,sizeof(wifi_paraG.wifi_ssid)); sprintf(buf,"%d",Bp.serialNum); strcat(ssid,buf); strcat(wifi_paraG.wifi_ssid,ssid); wifi_paraG.use_dhcp=1; EMW_Set_Config(&wifi_paraG); EMW_Set_Mode(DTU_mode); printf("WIFI Network: %s Created\n",wifi_paraG.wifi_ssid); rut=ReciveFile2SD(fname); SysTick->CTRL=0; if(rut) { clearAppVersion(); printf("Firmware Loading......\n"); if(isFactory) { printf("%d Bytes to load\n",WriteFlashFromFile("factory.bin")); } else { printf("%d Bytes to load\n",WriteFlashFromFile("new.bin")); } printf("Jump To Application\n"); JumpToApplication(AppProgramAddr); } else { SystemReset(); } } while(1); }
void app_sys_reboot(void) { app_sys_reboot_pre(); SystemReset(); }
/****************************************************************************** * @fn zb_SystemReset * * @brief The zb_SystemReset function reboots the ZigBee device. The * zb_SystemReset function can be called after a call to * zb_WriteConfiguration to restart Z-Stack with the updated * configuration. * * @param none * * @return none */ void zb_SystemReset ( void ) { SystemReset(); }
void _reentrant USBInsertionMonitorTask(void) { USHORT usStatus; BOOL bInserted = FALSE; WORD i,j; WORD iWaitCount; // Check for USB disconnect while(1) { usb_device_get_status(USB_STATUS_CONNECTION,&usStatus); switch(usStatus) { case USB_CONNECTED: bInserted=TRUE; break; default: if(bInserted)//if we've been inserted, and now we're not, lets shut down { // #ifdef DEVICE_3410 // 3410 still has power when removed from usb. #ifdef CHKDSK UsbMscCheckDiskAll(); #endif // #endif // TODO - put this back in later if needed // Clear the display // ClearDisplay(); // We need to immediately pull Write Protect low to protect the NANDs and // to reset the Renesas part (same line). HW_GPFLASH_CSR1R.B.WP0 = 0; // We need to clean up any media transactions that may be hanging // As best we can :) // stmp4770 and stmp4795, Remove drive flush on USB disconnect for NAND devices. // Drive flush still necessary for MMC media, to properly close multi-writes // that may be pending between SCSI commands. for(i=0;i<g_wUsbMscNumDevices;i++) { for(j=0;j<UsbMscDevice[i].wNumLunsSupported;j++) { if(UsbMscDevice[i].Lun[j].bMediaIsRemovable == TRUE) { DriveFlush(UsbMscDevice[i].Lun[j].wFileSystemDriveNumber); } } } //Do not leave. Wait for 5V to be removed. //Monitor D+/- and reset if it returns. HW_USBCSR.B.PLUGGEDIN_EN = 1; iWaitCount = 0; //ensure 5V Disconnect IRQ is enabled SysSetIrqLevel(HW_SR_IM_L2_SETMASK); while(HW_USBCSR.B.VBUSSENSE) { //if USB is plugged-in. Break loop and reset to return to USBMSC. if(HW_USBCSR.B.PLUGGEDIN) { break; } //wait a bit SysWait(200); if(iWaitCount > 10) { break; // if we waited a couple secs, time to break } else { iWaitCount++; //increment wait count } } SysWait(200); // Shut down SystemShutdown(); // Reset the device SystemReset(); } } SysWait(USB_WATCH_CALL_BACK_DELAY); } }
/*************************************************************************************************** *FunctionName: activityInput *Description: 界面输入 *Input: *Output: *Return: *Author: xsx *Date: 2016年12月21日09:00:59 ***************************************************************************************************/ static void activityInput(unsigned char *pbuf , unsigned short len) { if(S_SysSetPageBuffer) { /*命令*/ S_SysSetPageBuffer->lcdinput[0] = pbuf[4]; S_SysSetPageBuffer->lcdinput[0] = (S_SysSetPageBuffer->lcdinput[0]<<8) + pbuf[5]; //基本信息 if(S_SysSetPageBuffer->lcdinput[0] == 0x1900) { startActivity(createDeviceInfoActivity, NULL); } //操作人管理 else if(S_SysSetPageBuffer->lcdinput[0] == 0x1901) { startActivity(createUserManagerActivity, NULL); } //网络设置 else if(S_SysSetPageBuffer->lcdinput[0] == 0x1902) { startActivity(createNetPreActivity, NULL); } //数据管理 else if(S_SysSetPageBuffer->lcdinput[0] == 0x1903) { startActivity(createRecordActivity, NULL); } //关于按键第一次按下 else if(S_SysSetPageBuffer->lcdinput[0] == 0x1909) { S_SysSetPageBuffer->pressCnt = 0; } //关于按键持续按下 else if(S_SysSetPageBuffer->lcdinput[0] == 0x190A) { S_SysSetPageBuffer->pressCnt++; } //关于按键松开 else if(S_SysSetPageBuffer->lcdinput[0] == 0x190B) { //如果是长按就输入密码进入隐藏功能 if(S_SysSetPageBuffer->pressCnt > 10) SendKeyCode(4); //短按则进入关于界面 else startActivity(createAboutUsActivity, NULL); } //隐藏密码的厂家功能 else if(S_SysSetPageBuffer->lcdinput[0] == 0x1910) { if(GetBufLen(&pbuf[7] , 2*pbuf[6]) == 6) { if(pdPASS == CheckStrIsSame(&pbuf[7], TestPassWord, 6)) { startActivity(createReTestActivity, NULL); } else if(pdPASS == CheckStrIsSame(&pbuf[7], CheckQRPassWord, 6)) { startActivity(createCheckQRActivity, NULL); } else if(pdPASS == CheckStrIsSame(&pbuf[7], AdjLedPassWord, 6)) { startActivity(createAdjustLedActivity, NULL); } else if(pdPASS == CheckStrIsSame(&pbuf[7], FactoryResetPassWord, 6)) { if(My_Pass == SystemReset()) SendKeyCode(2); else SendKeyCode(1); } else if(pdPASS == CheckStrIsSame(&pbuf[7], ChangeValueShowTypePassWord, 6)) { setIsShowRealValue(TRUE); SendKeyCode(2); } else if(pdPASS == CheckStrIsSame(&pbuf[7], UnlockLCDPassWord, 6)) { unLockLCDOneTime(); SendKeyCode(2); } /*else if(pdPASS == CheckStrIsSame(&pbuf[7], EnableUSBPassWord, 6)) { USBD_Init(&USB_OTG_dev,USB_OTG_FS_CORE_ID,&USR_desc,&USBD_MSC_cb,&USR_cb); }*/ else SendKeyCode(1); } else SendKeyCode(1); } //其他设置 else if(S_SysSetPageBuffer->lcdinput[0] == 0x1904) { startActivity(createOtherSetActivity, NULL); } //返回 else if(S_SysSetPageBuffer->lcdinput[0] == 0x1906) { backToFatherActivity(); } } }
void Serial_callBack(uint8 port, uint8 event) { char theMessageData[] = "Hello"; zAddrType_t dstAddr; zAddrType_t ZAddr; afAddrType_t myaddr; // use for p2p char pbuf[3]; char pbuf1[3]; uint16 cmd; uint8 buff[128]; uint8 readBytes = 0; uint16 short_ddr; uint16 panid; uint8 *ieeeAddr; uint16 *p1; byte cnt = 0; uint8 yy1; uint8 yy2; uint8 i; byte nr; uint16 devlist[ NWK_MAX_DEVICES + 1]; associated_devices_t *adp; // delete devices //short_ddr = GenericApp_DstAddr.addr.shortAddr; uint8 startOptions; uint8 logicalType; logicalType = (uint8)ZDO_Config_Node_Descriptor.LogicalType; readBytes = HalUARTRead(SER_PORT, buff, 127); if (readBytes > 0) { //HalUARTWrite( SER_PORT, "DataRead: ",10); // HalUARTWrite( SER_PORT, buff, readBytes); if(readBytes == 4) { if(buff[0] == 'p' && buff[1] == 'i' && buff[2]=='n' && buff[3] == 'g') { UART_Send_String( "pong", 4 ); } } if( readBytes == 1) { yy1 = 1; if(buff[0]== 's') { /// short address short_ddr = _NIB.nwkDevAddress; UART_Send_String( (uint8*)&short_ddr, 2); } if(buff[0] == 'p') { /// pan id panid = _NIB.nwkPanId; UART_Send_String( (uint8*)&panid, 2); } if(buff[0] == 'c')/// channel { yy2 = _NIB.nwkLogicalChannel; UART_Send_String( (uint8*)&yy2, 1); } if(buff[0] =='m') // mac address { ieeeAddr = NLME_GetExtAddr(); UART_Send_String( ieeeAddr, 8); } if( buff[0] ==0xc0) // coordinator { set_coordi(); return; } if( buff[0] ==0xe0) // router { set_router(); return; } if(buff[0] == 0xCA) { // 使命的招唤 // read self AssociatedDevList for(i=0;i< NWK_MAX_DEVICES; i++) { nr = AssociatedDevList[ i ].nodeRelation; if(nr > 0 && nr < 5) //CHILD_RFD CHILD_RFD_RX_IDLE CHILD_FFD CHILD_FFD_RX_IDLE //if( nr != 0XFF) { // myaddr.addrMode = (afAddrMode_t)Addr16Bit; // myaddr.endPoint = GENERICAPP_ENDPOINT; // if( AssociatedDevList[ i ].shortAddr != 0x0000) // { //if( AssocIsChild( AssociatedDevList[ i ].shortAddr ) != 1 || AssociatedDevList[ i ].age > NWK_ROUTE_AGE_LIMIT) //if( AssocIsChild( AssociatedDevList[ i ].shortAddr ) == 1 && AssociatedDevList[ i ].age > NWK_ROUTE_AGE_LIMIT ) // { // myaddr.addr.shortAddr = AssociatedDevList[ i ].shortAddr; /* if ( AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID,(byte)osal_strlen( theMessageData ) + 1, (byte *)&theMessageData, &GenericApp_TransID, AF_ACK_REQUEST, AF_DEFAULT_RADIUS ) != afStatus_SUCCESS ) { uprint("delete asso"); */ // delete_asso( AssociatedDevList[ i ]. addrIdx); // } // else // { devlist[yy1] = AssociatedDevList[ i ].shortAddr; yy1++; // } // } }//else {break;} } devlist[0] = BUILD_UINT16(0xce, AssocCount(1, 4) ); UART_Send_String( (uint8*)&devlist[0], yy1*2); //p1 = AssocMakeList( &cnt ); //UART_Send_String( (uint8*)p1, AssocCount(1, 4)*2); //osal_mem_free(p1); return; } } #if defined( ZDO_COORDINATOR ) // only coordinator can have this function if(readBytes == 3) { if( buff[0] == 0xCA || buff[0] == 0x6d) { // CA xx xx ,send CA to a node ,with it's short address ///uprint("it's CA "); short_ddr = BUILD_UINT16( buff[1], buff[2] ); myaddr.addrMode = (afAddrMode_t)Addr16Bit; myaddr.endPoint = GENERICAPP_ENDPOINT; myaddr.addr.shortAddr = short_ddr; if ( AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, 1, (byte *)&buff, &GenericApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) != afStatus_SUCCESS ) { AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, 1, (byte *)&buff, &GenericApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); // send twice only, if it is still not ok, f**k it } return; } } #endif if( readBytes >= 2) { if( buff[0] == 'e' && buff[1] == '#') { uprint("EndDevice match"); HalLedSet ( HAL_LED_1, HAL_LED_MODE_OFF ); dstAddr.addrMode = Addr16Bit; dstAddr.addr.shortAddr = 0x0000; // Coordinator ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(), GenericApp_epDesc.endPoint, GENERICAPP_PROFID, GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList, GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList, FALSE ); } if( buff[0] == 'r' && buff[1] == '#') { uprint("Router Device match"); HalLedSet ( HAL_LED_1, HAL_LED_MODE_FLASH ); dstAddr.addrMode = AddrBroadcast; dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR; ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR, GENERICAPP_PROFID, GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList, GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList, FALSE ); } if(readBytes == 6) { if(buff[0] == 'p' && buff[1]==':') // pan id { strncpy(pbuf, &buff[2],2); pbuf[2] = '\0'; strncpy(pbuf1, &buff[4],2); pbuf1[2] = '\0'; set_panid( BUILD_UINT16( strtol(pbuf1,NULL,16),strtol(pbuf,NULL,16) )); if(_NIB.nwkPanId == 0xffff) { zgWriteStartupOptions (ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE); SystemReset(); } //SystemResetSoft(); } if(buff[0] == 's' && buff[1]==':') // short address { /* strncpy(pbuf, &buff[2],2); pbuf[2] = '\0'; strncpy(pbuf1, &buff[4],2); pbuf1[2] = '\0'; _NIB.nwkDevAddress = BUILD_UINT16( strtol(pbuf1,NULL,16),strtol(pbuf,NULL,16)); */ } } cmd = BUILD_UINT16(buff[ 1 + 1], buff[1]); if( ( buff[ 0 ] == CPT_SOP) && (cmd == SYS_PING_REQUEST) ) { sysPingReqRcvd(); return; } if( readBytes == 2) { if( buff[0] == 0xcc ) { if( buff[1] > 0x0a && buff[1] < 0x1b ) { _NIB.nwkLogicalChannel = buff[1]; NLME_UpdateNV(0x01); ZMacSetReq( ZMacChannel, &buff[1]); osal_nv_item_init( ZCD_NV_CHANLIST, sizeof(zgDefaultChannelList), &zgDefaultChannelList); if( buff[1] == 0x0b) { zgDefaultChannelList = 0x00000800; } if (buff[1] == 0x0c ) { zgDefaultChannelList = 0x00001000; } if (buff[1] == 0x0d ) { zgDefaultChannelList = 0x00002000; } if (buff[1] == 0x0e ) { zgDefaultChannelList = 0x00004000; } if (buff[1] == 0x0f ) { zgDefaultChannelList = 0x00008000; } if (buff[1] == 0x10 ) { zgDefaultChannelList = 0x00010000; } if (buff[1] == 0x11 ) { zgDefaultChannelList = 0x00020000; } if (buff[1] == 0x12 ) { zgDefaultChannelList = 0x00040000; } if (buff[1] == 0x13 ) { zgDefaultChannelList = 0x00080000; } if (buff[1] == 0x14 ) { zgDefaultChannelList = 0x00100000; } if (buff[1] == 0x15 ) { zgDefaultChannelList = 0x00200000; } if (buff[1] == 0x16 ) { zgDefaultChannelList = 0x00400000; } if (buff[1] == 0x17 ) { zgDefaultChannelList = 0x00800000; } if (buff[1] == 0x18 ) { zgDefaultChannelList = 0x01000000; } if (buff[1] == 0x19 ) { zgDefaultChannelList = 0x02000000; } if (buff[1] == 0x1a ) { zgDefaultChannelList = 0x04000000; } osal_nv_write( ZCD_NV_CHANLIST, 0 ,sizeof(zgDefaultChannelList), &zgDefaultChannelList); UART_Send_String( (uint8*)&zgDefaultChannelList, sizeof(zgDefaultChannelList) ); /* _NIB.nwkLogicalChannel = buff[1]; NLME_UpdateNV(0x01); if( osal_nv_write(ZCD_NV_CHANLIST, 0, osal_nv_item_len( ZCD_NV_CHANLIST ), &tmp32) != ZSUCCESS) { uprint("change channel to nv failed"); } */ /* _NIB.nwkLogicalChannel = buff[1]; ZMacSetReq( ZMacChannel, &buff[1]); ZDApp_NwkStateUpdateCB(); _NIB.nwkTotalTransmissions = 0; nwkTransmissionFailures( TRUE ); */ } } }// readBytes==2 ser_process( buff,readBytes );// 中讯威易的协议最小也是2 字节 }//if( readBytes >= 2) AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, readBytes, (byte *)&buff, &GenericApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); } //if (readBytes > 0) }
uint8_t MQTTS_Poll(uint8_t wakeup) { if(vMQTTS.pfCnt) { vMQTTS.pfCnt--; return MQTTS_POLL_STAT_NOP; } switch(vMQTTS.Status) { #ifndef GATEWAY case MQTTS_STATUS_SEARCHGW: #ifndef ASLEEP vMQTTS.pfCnt = POLL_TMR_FREQ - 1; if(vMQTTS.Tretry) { vMQTTS.Tretry--; break; } vMQTTS.Tretry = MQTTS_DEF_TSGW - 1; if(vMQTTS.Nretry) vMQTTS.Nretry--; else SystemReset(); #else // ASLEEP if(vMQTTS.Tretry) { vMQTTS.Tretry--; if(vMQTTS.Tretry == (MQTTS_DEF_TSGW - 2)) { return MQTTS_POLL_STAT_ASLEEP; // ASLeep } else if(vMQTTS.Tretry == 0) { if(vMQTTS.Nretry) { vMQTTS.Nretry--; vMQTTS.pfCnt = POLL_TMR_FREQ - 1; return MQTTS_POLL_STAT_AWAKE; // WakeUp } // Not found many times SystemReset(); } break; } vMQTTS.pfCnt = POLL_TMR_FREQ - 1; vMQTTS.Tretry = MQTTS_DEF_TSGW - 1; #endif // ASLEEP mqtts_send_search_gw(); break; #endif // GATEWAY case MQTTS_STATUS_OFFLINE: // Connect to Broker vMQTTS.pfCnt = POLL_TMR_FREQ - 1; if(vMQTTS.Tretry) { vMQTTS.Tretry--; break; } if(vMQTTS.Nretry) vMQTTS.Nretry--; else { #ifdef GATEWAY SystemReset(); #else // NODE vMQTTS.Nretry = MQTTS_DEF_NRETRY; vMQTTS.Status = MQTTS_STATUS_SEARCHGW; break; #endif // GATEWAY } vMQTTS.Tretry = MQTTS_DEF_TCONNECT - 1; mqtts_send_connect(); break; case MQTTS_STATUS_CONNECT: vMQTTS.pfCnt = POLL_TMR_FREQ - 1; if(vMQTTS.Tretry) { vMQTTS.Tretry--; break; } if(vMQTTS.Nretry) vMQTTS.Nretry--; else { MQTTS_Disconnect(); break; } if(vMQTTS.fTail == vMQTTS.fHead) // Send Ping { if(wakeup == 0) mqtts_send_ping(); } else { MQ_t * pBuf; pBuf = mqAssert(); if(pBuf != NULL) // no memory { memcpy(pBuf, vMQTTS.fBuf[vMQTTS.fTail], sizeof(MQ_t)); MQTTS_Push(pBuf); } vMQTTS.pfCnt = POLL_TMR_FREQ_FAST; } break; #ifdef ASLEEP case MQTTS_STATUS_POST_CONNECT: { vMQTTS.pfCnt = (POLL_TMR_FREQ - 1); MQ_t * pBuf; pBuf = mqAssert(); if(pBuf != NULL) // no memory { // Send disconnect pBuf->mq.Length = MQTTS_SIZEOF_MSG_DISCONNECTL; pBuf->mq.MsgType = MQTTS_MSGTYP_DISCONNECT; pBuf->mq.m.disconnect.Duration = SWAPWORD(vMQTTS.Tasleep); MQTTS_Push(pBuf); } } if(vMQTTS.Nretry) { vMQTTS.Nretry--; break; } case MQTTS_STATUS_PRE_ASLEEP: vMQTTS.Status = MQTTS_STATUS_ASLEEP; vMQTTS.Tretry = vMQTTS.Tasleep; return MQTTS_POLL_STAT_ASLEEP; case MQTTS_STATUS_ASLEEP: if(vMQTTS.Tretry) { vMQTTS.Tretry--; break; } vMQTTS.pfCnt = POLL_TMR_FREQ - 1; vMQTTS.Status = MQTTS_STATUS_AWAKE; vMQTTS.Nretry = MQTTS_DEF_NRETRY; return MQTTS_POLL_STAT_AWAKE; case MQTTS_STATUS_AWAKE: vMQTTS.pfCnt = POLL_TMR_FREQ - 1; if(vMQTTS.Nretry) { vMQTTS.Nretry--; mqtts_send_ping(); } else MQTTS_Disconnect(); break; case MQTTS_STATUS_POST_AWAKE: if(wakeup != 0) { vMQTTS.Status = MQTTS_STATUS_OFFLINE; break; } vMQTTS.pfCnt = POLL_TMR_FREQ - 1; vMQTTS.Status = MQTTS_STATUS_PRE_ASLEEP; break; #endif // ASLEEP } return MQTTS_POLL_STAT_NOP; }
void eventReset(osal_event_hdr_t * hdrEvent) { SystemReset(); }
void ssp2_isr(void) { int state; state = i2c_isr_state(I2C_Slave); if((state==0) || (state== 0x80)) //I2C address byte read and ignore i2c_read(I2C_Slave); if(state==1){ //if state == 1 then this is the word address (Host Command written) rcv_buffer[state - 1] = i2c_read(I2C_Slave); switch(rcv_buffer[0]){ case 0x01: //Hard reset of board. Power cycle all except CMC microController { printf("\r\n3715 I2C Hard Reset 0x%x\n", rcv_buffer[0]); SystemReset(1); break; } case 0x02: //Back end reset of 3219 and 3218 { printf("\r\n3715 I2C Reset Back End 0x%x\n", rcv_buffer[0]); output_low(RST3219n); delay_ms(200); output_high(RST3219n); break; } default: //Host issued command that doesn't exist..do nothing { break; } } } if(state >= 0x80){ if (I2CReadEnable) { //This is disabled at the moment. 3715 not supporting clock stretching so read function not working. switch(rcv_buffer[0]){ case 0xA1: //Master asking for status data...write out status byte LSB first (2 bytes) { i2c_write(I2C_Slave, ((StatByte >> ((state-0x80)*8)) & 0xff)); break; } case 0xA2: //Master asking for temp data...write out status byte LSB first (7 bytes) { i2c_write(I2C_Slave,temp_buffer[state-0x80]); //This will write out 7 bytes. Temp format is signed 8 bits break; } case 0xA3: //Master asking for voltage data...write out status byte LSB first (13 bytes) { i2c_write(I2C_Slave,voltage_buffer[state-0x80]); //This will write out 13 bytes. Voltage format is .02V/LSB break; } case 0xA4: //Master asking for current data...write out status byte LSB first (13 bytes) { i2c_write(I2C_Slave,current_buffer[state-0x80]); //This will write out 13 bytes of the voltage across the lower fet. break; //User must know RDSon to calculate current..very low accuracy } default: { i2c_write(I2C_Slave, 0x00); //default response. Host asked for command that doesn't exist break; } } } else printf("\r\nI2C read from micro disabled"); }
void MtpSuspendService(BOOL bSetup, BYTE btDirection, BYTE _USB_MEM * pbtBuffer, WORD wLength,WORD wPrivateData) { USHORT uStatus; BOOL bLowPowerUsbStickyBitReadResult; if( usb_get_current_limit() > 100 ) { usb_device_get_status(USB_STATUS,&uStatus); if(uStatus == USB_STATE_ADDRESSED) { //If we're being suspended in the addressed state, that means we've likely asked for more current than allowed by the host //we're going to set a sticky bit (which we'll use when we reset to determine if we've been shutdown for too much //current requested), and then reset the part. // 8/19/04 - add one bit so that we have a counter - we want to try 500mA twice before failing. if( ReadStickyBit((volatile _X WORD *) &HW_RTC_PERSISTENT1, HW_RTC_PERSISTANT1_LOW_POWER2_USB_BITPOS, &bLowPowerUsbStickyBitReadResult) != SUCCESS ) { DebugBuildAssert(FALSE); // halts only in DEBUG builds. } // if 2nd try flag is set, we've failed the 2nd time, now drop down into 100mA mode. if (bLowPowerUsbStickyBitReadResult) { // Clear 2nd try flag if ( ClearStickyBit((volatile _X WORD *)&HW_RTC_PERSISTENT1, HW_RTC_PERSISTANT1_LOW_POWER2_USB_BITPOS) != SUCCESS) { DebugBuildAssert(FALSE); // halts only in DEBUG build, vanishes in RETAIL build. } // Set the 100mA flag. if( SetStickyBit((volatile _X WORD *)&HW_RTC_PERSISTENT1, HW_RTC_PERSISTANT1_LOW_POWER_USB_BITPOS) != SUCCESS ) { DebugBuildAssert(0); // halts only if DEBUG build. } } else { //set the 2nd try sticky bit. if( SetStickyBit((volatile _X WORD *)&HW_RTC_PERSISTENT1, HW_RTC_PERSISTANT1_LOW_POWER2_USB_BITPOS) != SUCCESS ) { DebugBuildAssert(0); // halts only if DEBUG build. } } usb_device_shutdown(); for(uStatus =0; uStatus<10000; uStatus++) _nop(); //reset the part SystemReset(); } else { //DebugBuildAssert(FALSE); //! } } //Turn off LRADC HW_BATT_CTRL.B.PWD = 1; #ifdef DCDC_POWER_TRANSFER //If using hand-off code, leave the DCDC circuitry on. HW_VDD5V_PWR_CHARGE.B.DCANA_LP = FALSE; HW_DCDC_TBR.B.DCDC2_STOPCLK = FALSE; HW_DCDC_TBR.B.DCDC1_STOPCLK = FALSE; #else //If not using hand-off code, turn off circuitry. HW_VDD5V_PWR_CHARGE.B.DCANA_LP = TRUE; //Turn off some unused circuitry in the dcdc converter HW_DCDC_TBR.B.DCDC2_STOPCLK = TRUE; //Turn off DCDC#2 HW_DCDC_TBR.B.DCDC1_STOPCLK = TRUE; //Turn off DCDC#1 #endif HW_DCDC_TBR.B.DCDC_ANA_BGR_BIAS = TRUE; //Switch over to the Vbg bias voltage HW_REF_CTRL.B.PWRDWNS = TRUE; // Turn down the self bias circuit HW_REF_CTRL.B.BIASC=1; // drops bias currents HW_REF_CTRL.B.LOW_PWR=1; // and some more. HW_FLCR2.B.CLKOFF = 1; // Turns Off clock to flash module HW_GPFLASH_CSR0R.B.CLK_DISABLE = 1; // Turns OFF GPFLASH HW_DCDC_VDDD.B.BROWNOUT_ENABLE = 0; // Disable the brownout HW_DCDC_VDDD.B.VOLTAGE_LEVEL=0x0a; //Set core to 1.34 volts #ifdef BATTERY_CHARGE BatteryChargeDisableCharging(FALSE); #endif }
// Function Description: // Inputs: no parameters // Returns: no register returns // Notes: void _reentrant UserInterfaceTask(void) { USHORT usStatus; //int iTransferRate; WORD State=SCSI_IDLE; //Message Msg; int iDelay = HALF_SEC_UPDATE_RATE; BOOL bNeedToReEnable = FALSE; int Write_State_Persisten_Time = WRITE_STATE_PERSISTENT_TIME; int i; for (i=10;i< USER_INTERFACE_STACK_SIZE;i++ ) { g_UserInterfaceStack[i]=0xc0ffee; } Init5VSense(); USBLCDDisplayInit(); SysWait(250); while(1) { #if (NUM_REMOVABLE_MEDIA == 1) // Wait until we have decided whether device is in MTP vs. MSC mode // Media detection uses different code for the two modes if(g_MtpArbitrationDone) { if(MTPDetected) { MtpCheckExternalMedia(); } else { ScsiInsertionRemovalCode(); } } #endif usb_device_get_status(USB_STATUS, &usStatus); if(usStatus == USB_STATE_SUSPENDED) { SysWait(UPDATE_RATE); } else { SysPostMessage(2,LCD_END_FRAME); SysWait(UPDATE_RATE); SysPostMessage(2,LCD_BEGIN_FRAME); USBLCDCheckForTransfers(); if(g_bServiceDCDC) { ServiceDCDC(); //Service DCDC converter } #ifdef BATTERY_CHARGE // For 3500 Battery Monitoring must be done only during battery charging // The rest of the time the system operates from USB +5V // and battery monitoring does not make any sense. // Also, battery brownout always triggered if sys operates w/ no battery. //Only charge if we're in high usb current mode. March 11 2005 addition if(usb_get_current_limit() <= 100) //mA { BatteryChargeDisableCharging(TRUE); // until next stmp bootup } else { if(usStatus != USB_STATE_CONFIGURED) { if(bNeedToReEnable == FALSE) { BatteryChargeDisableCharging(FALSE); bNeedToReEnable = TRUE; } } else { if(bNeedToReEnable == TRUE) { BatteryChargeEnableCharging(); bNeedToReEnable = FALSE; } BatteryChargeStateMachine(); } } #endif #if defined(BATTERY_CHARGE) // I only want to update the Battery icon once per 1/2 second // but always check and average battery level. USBLCDCheckBatteryLevel(); #endif if (iDelay-- <= 0) { #if defined(BATTERY_CHARGE) USBLCDDisplayBatteryLevel(); #endif USBLCDCheckDBStoreDirty(); iDelay = HALF_SEC_UPDATE_RATE; } // g_wActivityState - This global is set by other code to indicate the state of the // system. // Can be set by SCSI code, or MTP code (depending on the connection) // Modification added for MTP/MSC system // In MTP/MSC, MSC uses overlays thus we need to be careful yielding to the kernel for display updates. // This can not be done in the middle of a multi write sequence. // The code was modified and uses the same technique as a monostable device. Each time scsi write is entered // the global g_wActivityStateMultiWrite is set to SCSI_WRITING. This will trigger the monostable for // WRITE_STATE_PERSISTENT_TIME miliseconds. If a new scsi write command arrives prior WRITE_STATE_PERSISTENT_TIME // expires, the new scsi write command re-starts the monostable for a new full WRITE_STATE_PERSISTENT_TIME ms. // Once the monostable time expires without no new SCSI write commands, the state will switch to IDLE and display // will return to the READY state. // The display task has a chance to run everytime a new SCSI write command arrives. There is no display refresh // during mutltiwrites. if((g_wActivityStateMultiWrite == SCSI_WRITING) || (Write_State_Persisten_Time < WRITE_STATE_PERSISTENT_TIME)) { if(g_wActivityStateMultiWrite == SCSI_WRITING) { g_wActivityStateMultiWrite = SCSI_IDLE; Write_State_Persisten_Time = 0; if(State != SCSI_WRITING) { State = SCSI_WRITING; USBLCDWriting(); } } else { Write_State_Persisten_Time += UPDATE_RATE; } } else { if(State!= g_wActivityState ) { State = g_wActivityState; switch(State) { case SCSI_IDLE: USBLCDIdle(); break; case SCSI_READING: USBLCDReading(); break; case SCSI_WRITING: USBLCDWriting(); break; default : USBLCDIdle(); } } } } // end else !suspended { USHORT usStatus; // fixes 8777 (0 or 2 usb unplug tries out of 20 would not // boot player & mtp was still running due to rare irq loss) usb_device_get_status(USB_STATUS_CONNECTION,&usStatus); //we could just check the usb 5v bit instead of calling this. if( usStatus == USB_DISCONNECTED ) { // Restart the MTP device and re-enumerate //DebugBuildAssert(0); //During JLN verification, this hit & the reset started player. StorFlush(); // flush the database first SystemShutdown();// we could use pragma asm to jump to the missed isr instead which resets also. SystemReset(); } } // Update the count if it is not disabled( negative means disabled). if (g_StoreWatchDogCount >= 0) { g_StoreWatchDogCount++; } } // while(1) } // void _reentrant UserInterfaceTask(void)