Uint32 main(void) { //GPIO and SCI are still setup from Sci_Boot() //Setup sysctl and pll DisableDog(); IntOsc1Sel(); InitPll(DSP28_PLLCR,DSP28_DIVSEL); InitFlash(); DELAY_US(100); // ApplicationPtr = (void(*)(void))SCI_Boot(); // // if(ApplicationPtr) // ApplicationPtr(); return SCI_Boot(); // asm(" .ref _ExitBoot"); // asm(" BF _ExitBoot,UNC"); // return 0; }
// // SCI_GetFunction - This function first initializes SCIA and performs // an autobaud lock. It contains a while loop waiting on // commands from the host. It processes each // command and sends a response except for Run and // Reset commands. On Run the kernel exits and branches // to the Entry Point. On Reset, the kernel exits the // while loop and does a WatchDog Time-out. // Uint32 SCI_GetFunction(Uint32 BootMode) { Uint32 EntryAddr; Uint16 command; Uint16 data[10]; // 16*10 = 128 + 32 Uint16 length; // // read CCNF0 register to check if SCI is enabled or not // if((DevCfgRegs.DC8.bit.SCI_A != 0x01)) { return 0xFFFFFFFF; } // // Assign GetWordData to the SCI-A version of the // function. GetWordData is a pointer to a function. // GetWordData = SCIA_GetWordData; // // Initialize the SCI-A port for communications // with the host. // SCIA_Init(BootMode); SCIA_AutobaudLock(); command = SCI_GetPacket(&length, data); while(command != RESET_CPU1) { // //Reset the statusCode. // statusCode.status = NO_ERROR; statusCode.address = 0x12345678; checksum = 0; // // CPU1_UNLOCK_Z1 // if(command == CPU1_UNLOCK_Z1) { Uint32 password0 = (Uint32)data[0] | ((Uint32)data[1] << 16); Uint32 password1 = (Uint32)data[2] | ((Uint32)data[3] << 16); Uint32 password2 = (Uint32)data[4] | ((Uint32)data[5] << 16); Uint32 password3 = (Uint32)data[6] | ((Uint32)data[7] << 16); // // Unlock the device // DcsmZ1Regs.Z1_CSMKEY0 = password0; DcsmZ1Regs.Z1_CSMKEY1 = password1; DcsmZ1Regs.Z1_CSMKEY2 = password2; DcsmZ1Regs.Z1_CSMKEY3 = password3; if(DcsmZ1Regs.Z1_CR.bit.UNSECURE == 0) //0 = Locked { statusCode.status = UNLOCK_ERROR; } } // // CPU1_UNLOCK_Z2 // else if(command == CPU1_UNLOCK_Z2) { Uint32 password0 = (Uint32)data[0] | ((Uint32)data[1] << 16); Uint32 password1 = (Uint32)data[2] | ((Uint32)data[3] << 16); Uint32 password2 = (Uint32)data[4] | ((Uint32)data[5] << 16); Uint32 password3 = (Uint32)data[6] | ((Uint32)data[7] << 16); // //Unlock the device // DcsmZ2Regs.Z2_CSMKEY0 = password0; DcsmZ2Regs.Z2_CSMKEY1 = password1; DcsmZ2Regs.Z2_CSMKEY2 = password2; DcsmZ2Regs.Z2_CSMKEY3 = password3; if(DcsmZ2Regs.Z2_CR.bit.UNSECURE == 0) //0 = Locked { statusCode.status = UNLOCK_ERROR; } } // // DFU_CPU1 // else if(command == DFU_CPU1) { EntryAddr = SCI_Boot(BootMode); //loads application into CPU1 FLASH if(statusCode.status == NO_ERROR) { statusCode.address = EntryAddr; } } // // ERASE_CPU1 // else if(command == ERASE_CPU1) { Uint32 sectors = (Uint32)(((Uint32)data[1] << 16) | (Uint32)data[0]); Shared_Erase(sectors); } // // VERIFY_CPU1 // else if(command == VERIFY_CPU1) { VerifyData(); } // // RUN_CPU1 // else if(command == RUN_CPU1) { EntryAddr = (Uint32)(((Uint32)data[1] << 16) | (Uint32)data[0]); return(EntryAddr); } // // COMMAND_ERROR // else { statusCode.status = COMMAND_ERROR; } // // Send the packet and if NAK send again. // while(SCI_SendPacket(command, statusCode.status, 6, (Uint16*)&statusCode.address)){} // // Get next Packet // command = SCI_GetPacket(&length, data); //get next packet } // // Reset with WatchDog Timeout // EALLOW; WdRegs.SCSR.all = 0; //enable WDRST WdRegs.WDCR.all = 0x28; //enable WD EDIS; while(1){} }