//-------------------------------------------------------------------------------------- //-- Funcion de Inicialización // void MTS_Init (void) { // Las direcciones son WORD, que ya están grabada en EEPROM con formato LSB:MSB // eeprom_read_buffer(EE_ADDR_DNP_SLAVE, (UINT8 *)&MTS_wRemoteAddr, 2); // eeprom_read_buffer(EE_ADDR_DNP_MASTER, (UINT8 *)&MTS_wLocalAddr, 2); SCIA_Init(); // Driver de comunicación serie (SCI1) MTS_CmdIdx = 0x00; // Iniciar un timer para enviar comando.. MTS_WaitAnswerTimerId = TMR_SetTimer ( TMR_MTS_RESETLINKWAIT , PROC_MTS, 0x00, FALSE); }
Uint32 SCI_Boot() { Uint32 EntryAddr; // Asign GetWordData to the SCI-A version of the // function. GetOnlyWordData is a pointer to a function. // This version doesn't send echo back each character. GetOnlyWordData = SCIA_GetOnlyWordData; SCIA_Init(); SCIA_AutobaudLock(); checksum = 0; // If the KeyValue was invalid, abort the load // and return the flash entry point. if (SCIA_GetOnlyWordData() != 0x08AA) return FLASH_ENTRY_POINT; ReadReservedFn(); EntryAddr = GetLongData(); CopyData(); return EntryAddr; }
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // MAIN CODE - starts here //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void main(void) { //================================================================================= // INITIALISATION - General //================================================================================= //-------------------------------- FRAMEWORK -------------------------------------- DeviceInit(); // Device Life support & GPIO SCIA_Init(); // Initalize the Serial Comms A peripheral // Only used if running from FLASH // Note that the variable FLASH is defined by the compiler with -d FLASH // (see TwoChannelBuck.pjt file) #ifdef FLASH // Copy time critical code and Flash setup code to RAM // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart // symbols are created by the linker. Refer to the linker files. MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); // Call Flash Initialization to setup flash waitstates // This function must reside in RAM InitFlash(); // Call the flash wrapper init function #endif //(FLASH) // Timing sync for background loops // Timer period definitions found in PeripheralHeaderIncludes.h CpuTimer0Regs.PRD.all = mSec1; // A tasks CpuTimer1Regs.PRD.all = mSec50; // B tasks CpuTimer2Regs.PRD.all = mSec100; // C tasks // Tasks State-machine init Alpha_State_Ptr = &A0; A_Task_Ptr = &A1; B_Task_Ptr = &B1; C_Task_Ptr = &C1; BlinkStatePtr = 0; VTimer0[0] = 0; VTimer1[0] = 0; VTimer2[0] = 0; CommsOKflg = 0; SerialCommsTimer = 0; HRmode = 1; // Default to HR mode enabled LED_TaskPtr = 0; // ---------------------------------- USER ----------------------------------------- // put common initialization/variable definitions here Gui_LEDPrd = 1000; //Default to 1 blink every second (Q0) temp_LEDDelay = 0; //================================================================================= // INITIALISATION - GUI connections //================================================================================= // Use this section only if you plan to "Instrument" your application using the // Microsoft C# freeware GUI Template provided by TI //"Set" variables //--------------------------------------- // assign GUI variable Textboxes to desired "setable" parameter addresses //varSetTxtList[0] = &Var1; // assign GUI Buttons to desired flag addresses //varSetBtnList[0] = &Var2; // assign GUI Sliders to desired "setable" parameter addresses varSetSldrList[0] = &Gui_LEDPrd; //"Get" variables //--------------------------------------- // assign a GUI "getable" parameter address //varGetList[0] = &Var3; // assign a GUI "getable" parameter array address // only need to set initial position of array, program will run through it // based on the array length specified in the GUI //arrayGetList[0] = &Var4[0]; //================================================================================== // INITIALISATION - Peripherals used for support //================================================================================== // ---------------------------------- USER ----------------------------------------- // Put peripheral initialisation here //================================================================================== // INITIALISATION - BUILD OPTIONS - NOTE: select via ProjectSettings.h //================================================================================== // ---------------------------------- USER ----------------------------------------- // Put build specific initialisation here //================================================================================= // BACKGROUND (BG) LOOP //================================================================================= //--------------------------------- FRAMEWORK ------------------------------------- for(;;) //infinite loop { // State machine entry & exit point //=========================================================== (*Alpha_State_Ptr)(); // jump to an Alpha state (A0,B0,...) //=========================================================== } } //END MAIN CODE
// // 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){} }