/**************************************************************************** * * NAME: vUnclaimedInterrupt * * DESCRIPTION: * Catches any unexpected interrupts * * RETURNS: * void * ****************************************************************************/ PUBLIC void vUnclaimedInterrupt(void) { DBG_vPrintf(TRACE_EXCEPTION, "Unclaimed interrupt\n"); DBG_vDumpStack(); #if HALT_ON_EXCEPTION while (1); #else vAHI_SwReset(); #endif }
uint8 commitCodeUpdate(uint8* inMsg, uint8* outMsg) { uint32 sectorSize; int rxbat=u16ReadADC(E_AHI_ADC_SRC_VOLT);//3838 4096 = 2.4*1.5 =3.6v rxbat=rxbat*360/4096; uint8 copyBuf[256]; uint32 maxUpload; #ifdef JN5148 sectorSize=0x10000; maxUpload=sectorSize; #else sectorSize=0x8000; maxUpload=2*sectorSize; #endif if(rxbat<300 ) { outMsg[0]=0x95;//fail outMsg[1]=3; return 2; } if(codeUpdateLength>maxUpload) { outMsg[0]=0x95;//fail outMsg[1]=2; return 2; } if(codeUpdateCrc!=inMsg[1]) { outMsg[0]=0x95;//fail outMsg[1]=1; return 2; } #ifdef JN5148 //copy flash sector 1 to sector 0 bAHI_FlashEraseSector(0); uint32 addr=0; while(addr<codeUpdateLength) { bAHI_FullFlashRead(addr+sectorSize,256,copyBuf); bAHI_FullFlashProgram(addr,256,copyBuf); addr+=256; } #endif vAHI_SwReset(); return 0; }
/**************************************************************************** * * NAME: vHandleSerialInput * * DESCRIPTION: * * PARAMETERS: Name RW Usage * * RETURNS: * * NOTES: ****************************************************************************/ PRIVATE void vHandleSerialInput() { // handle UART command while (!SERIAL_bRxQueueEmpty(sSerPort.u8SerialPort)) { int16 i16Char; i16Char = SERIAL_i16RxChar(sSerPort.u8SerialPort); // process if (i16Char >=0 && i16Char <= 0xFF) { uint8 u8res = u8ParseSerCmd(&sSerCmd, (uint8)i16Char); if (u8res == E_SERCMD_VERBOSE) { vfPrintf(&sSerStream, "\n\rVERBOSE MODE = %s", bSerCmd_VerboseMode ? "ON" : "OFF"); continue; } if (!bSerCmd_VerboseMode) continue; switch (i16Char) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': sAppData.sFlash.sData.u8Layer = i16Char - '0'; if (bFlash_Write(&sAppData.sFlash, FLASH_SECTOR_NUMBER - 1, 0)) { V_PRINTF( LB "Flash Saved (Router Layer #%d)... RESETTING", sAppData.sFlash.sData.u8Layer); vWait(100000); vAHI_SwReset(); } else { V_PRINTF( LB "Failed to save flash..."); } break; case 'i': // info _C { tsToCoNet_NwkLyTr_Context *pc = (tsToCoNet_NwkLyTr_Context *)(sAppData.pContextNwk); V_PRINTF( LB "Info: la=%d ty=%d ro=%02x st=%02x", pc->sInfo.u8Layer, pc->sInfo.u8NwkTypeId, pc->sInfo.u8Role, pc->sInfo.u8State); V_PRINTF( LB "Parent: %08x", pc->u32AddrHigherLayer); V_PRINTF( LB "LostParent: %d", pc->u8Ct_LostParent); V_PRINTF( LB "SecRescan: %d, SecRelocate: %d", pc->u8Ct_Second_To_Rescan, pc->u8Ct_Second_To_Relocate); } break; case '>': sToCoNet_AppContext.u8Channel++; if (sToCoNet_AppContext.u8Channel > 25) sToCoNet_AppContext.u8Channel = 0; ToCoNet_vRfConfig(); V_PRINTF( LB"channel set to %d.", sToCoNet_AppContext.u8Channel); break; case '<': sToCoNet_AppContext.u8Channel--; if (sToCoNet_AppContext.u8Channel < 11) sToCoNet_AppContext.u8Channel = 25; ToCoNet_vRfConfig(); V_PRINTF( LB"channel set to %d.", sToCoNet_AppContext.u8Channel); break; case 't': SPRINTF_vRewind(); vfPrintf(SPRINTF_Stream, "TEST FROM ROUTER(#%08X)", ToCoNet_u32GetSerial()); bTransmitToParent(sAppData.pContextNwk, SPRINTF_pu8GetBuff(), SPRINTF_u16Length()); break; case 'd': case 'D': _C { static uint8 u8DgbLvl; u8DgbLvl++; if(u8DgbLvl > 10) u8DgbLvl = 0; ToCoNet_vDebugLevel(u8DgbLvl); V_PRINTF( LB"set NwkCode debug level to %d.", u8DgbLvl); } break; default: break; } } }
/**************************************************************************** * * NAME: Device_vException * * DESCRIPTION: * ****************************************************************************/ PUBLIC WEAK void Device_vException(uint32 u32HeapAddr, uint32 u32Vector, uint32 u32Code) { /* Reset */ vAHI_SwReset(); }
static void appcall(void *p) { static struct bl_appstate s = { IDLE, 0x00, 0x00, false }; clock_time_t time = clock_time(); msg_t *msg = uip_appdata, *smsg = uip_sappdata; if(uip_connected()) { s.state = IDLE; s.reset_req = false; s.write_addr = 0; s.write_len = 0; s.msg_len = 0; GDB2_PUTS(" conn "); } if(uip_closed() || uip_aborted() || uip_timedout()) { uip_close(); if(s.reset_req && uip_closed()) vAHI_SwReset(); /* at this point the system RESETS */ s.state = IDLE; GDB2_PUTS(" close\n"); } if(uip_acked()) { if (s.state==SENDING) { s.msg_len = 0; s.state = IDLE; }; GDB2_PUTS("bootloader: acked\n"); } if(uip_newdata()) { if (s.state == FLASHING) { bAHI_FullFlashProgram(s.write_addr, uip_datalen(), (uint8_t*) msg); s.write_addr += uip_datalen(); if(s.write_addr >= s.write_len) { GDB2_PUTS("bootloader: write done\n"); s.write_len = 0; s.state = SENDING; smsg->type = RSP_FLASH_PROG2; smsg->len = MSG_SIZEOF(smsg->asFlashWrite2Rsp); smsg->asFlashWrite2Rsp = OK; } } else if(s.state != SENDING) { s.msg_len += uip_datalen(); if(s.msg_len == msg->len) { GDB2_PUTS("bootloader: send\n"); s.msg_len = 0; s.state = SENDING; switch(msg->type) { case REQ_FLASH_ERASE: smsg->asFlashEraseRsp = bAHI_FlashEraseSector(0) ? OK : NOT_SUPPORTED; smsg->asFlashEraseRsp = bAHI_FlashEraseSector(1) ? OK|smsg->asFlashEraseRsp : NOT_SUPPORTED; smsg->asFlashEraseRsp = bAHI_FlashEraseSector(2) ? OK|smsg->asFlashEraseRsp : NOT_SUPPORTED; smsg->asFlashEraseRsp = bAHI_FlashEraseSector(3) ? OK|smsg->asFlashEraseRsp : NOT_SUPPORTED; smsg->asFlashEraseRsp = OK; smsg->type = RSP_FLASH_ERASE; smsg->len = MSG_SIZEOF(smsg->asFlashEraseRsp); break; case REQ_FLASH_PROGR: smsg->asProgramRsp = bAHI_FullFlashProgram(msg->asProgramReq.addr, msg->len-MSG_HDR_SIZE-sizeof(msg->asProgramReq.addr), msg->asProgramReq.data) ? OK : NOT_SUPPORTED; smsg->type = RSP_FLASH_PROGR; smsg->len = MSG_SIZEOF(smsg->asProgramRsp); break; case REQ_FLASH_READ: smsg->type = RSP_FLASH_READ; smsg->len = MIN(MSG_SIZEOF(smsg->asReadRsp), MSG_HDR_SIZE+(sizeof(smsg->asReadRsp)-sizeof(smsg->asReadRsp.data)) +msg->asReadReq.len); smsg->asReadRsp.status = bAHI_FullFlashRead(msg->asReadReq.addr, MIN(sizeof(smsg->asReadRsp.data), msg->asReadReq.len), smsg->asReadRsp.data) ? OK : NOT_SUPPORTED; break; case REQ_SECTOR_ERASE: smsg->asSelectRsp = OK; smsg->asSectorRsp = bAHI_FlashEraseSector(msg->asSectorReq) ? OK : NOT_SUPPORTED; smsg->type = RSP_SECTOR_ERASE; smsg->len = MSG_SIZEOF(smsg->asSectorRsp); break; case REQ_SR_WRITE: smsg->asSRRsp = NOT_SUPPORTED; smsg->type = RSP_SR_WRITE; smsg->len = MSG_SIZEOF(smsg->asSRRsp); break; case REQ_RAM_WRITE: memcpy((uint32_t*) smsg->asRamWriteReq.addr, smsg->asRamWriteReq.data, smsg->len-MSG_HDR_SIZE); smsg->asRamWriteRsp = OK; smsg->type = RSP_RAM_WRITE; smsg->len = MSG_SIZEOF(smsg->asRamWriteRsp); break; case REQ_RAM_READ: smsg->type = RSP_RAM_READ; smsg->len = MIN(MSG_SIZEOF(smsg->asRamReadRsp), MSG_HDR_SIZE+ (sizeof(smsg->asRamReadRsp)-sizeof(smsg->asRamReadRsp.data))+msg->asRamReadReq.len); memcpy(smsg->asRamReadRsp.data, (uint32_t*) msg->asRamReadReq.addr, MIN(sizeof(smsg->asRamReadRsp.data), msg->asRamReadReq.len)); break; case REQ_RUN: s.reset_req = true; smsg->asRunRsp = OK; smsg->type = RSP_RUN; smsg->len = MSG_SIZEOF(msg->asRunReq); break; case REQ_FLASH_ID: smsg->asFlashIdRsp.status = OK; smsg->asFlashIdRsp.manufacturer = smsg->asFlashIdRsp.device = 0x10; smsg->type = RSP_FLASH_ID; smsg->len = MSG_SIZEOF(smsg->asFlashIdRsp); break; case REQ_FLASH_SELECT: smsg->asSelectRsp = bAHI_FlashInit(msg->asSelectReq.flashtype, (tSPIflashFncTable*) msg->asSelectReq.addr) ? OK : NOT_SUPPORTED; smsg->type = RSP_FLASH_SELECT; smsg->len = MSG_SIZEOF(smsg->asSelectRsp); break; case REQ_FLASH_PROG2: GDB2_PUTS("bootloader: flashing started\n"); s.state = FLASHING; s.write_addr = 0x00000000; s.write_len = msg->asFlashWrite2.len; break; default: smsg->asSRRsp = NOT_SUPPORTED; smsg->type = RSP_SR_WRITE; smsg->len = MSG_SIZEOF(smsg->asSRRsp); } } } } if(uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll()) { if(s.state==SENDING) uip_send(smsg, smsg->len); } /* this is odd but needed to get tcp throughput rate in sync with flash * write rate, otherwise rtt is calculated as the rtt of small packets which * is too fast when writing to the flash has started, therefore limiting * the overall throughput of the bootloader protocol. */ time = clock_time() - time; if (time < CLOCK_SECOND/12) clock_delay(CLOCK_SECOND/12 - time); }