Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(void) {
- Uint16 i;
- Uint32 j;
- // Disable Interrupts
- IntMasterDisable();
- // Sets up PLL, M3 running at 75MHz and C28 running at 150MHz
- // SysCtlClockSet(0x8007 000F)
- // 20MHZ x 15 = 300MHZ/2 (PLL has a defualt built in divide by 2)
- // sysctl_div_1 = 1 => output from PLL = 150MHZ
- // M3 divider = 2 => clkc to M3 = 75 MHZ
- // XCLKOUT divider = 4 => XCLKOUT = 37.5 MHZ
- // C28 divder = 1 = > clck to C28 = 150 MHZ
- HWREG(SYSCTL_MWRALLOW) = 0xA5A5A5A5;
- SysCtlClockConfigSet(SYSCTL_USE_PLL | (SYSCTL_SPLLIMULT_M & 0xF) |\
- SYSCTL_SYSDIV_1 | SYSCTL_M3SSDIV_2 |\
- SYSCTL_XCLKDIV_4);
- // Copy stuff from flash to RAM
- memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
- // Init M3 flash and leave flash pump
- FlashInit();
- FlashLeavePump();
- // M3 EALLOW
- HWREG(SYSCTL_MWRALLOW) = 0xA5A5A5A5;
- SysCtlPeripheralDisable(SYSCTL_PERIPH_WDOG1);
- SysCtlPeripheralDisable(SYSCTL_PERIPH_WDOG0);
- // Give Shared RAM block 1 to C28 (C28 will put its programming status in this block)
- RAMMReqSharedMemAccess(S1_ACCESS,1);
- // Now clocking and memory are set up, so we can start C28
- IPCMtoCBootControlSystem(CBROM_MTOC_BOOTMODE_BOOT_FROM_FLASH);
- // Wait a little for C28 to boot up (not necessary, i think, but let it be)
- j = 100000;
- while (j > 0)
- j--;
- // Prepare data for programming for C28
- // "flashData" structure resides in RAM S0 block, which is dedicated to M3
- for (i = 0; i < 1024; i++){
- flashData.dataBuffer[i] = i;
- }
- flashData.numOfWords = 1024;
- flashData.flashAddress = 0x00128000; // Sector F
- // Now set a command for Erasing C28 flash sector
- flashData.cmd = M3_CMD_ERASE_FLASH;
- flashData.sectorMask = SECTOR_F_MASK;
- // By setting IPC_FLAG 10, we tell C28 that all needed data is prepared, command issued (M3_CMD_ERASE_FLASH)
- // and it can perform this command
- IPCMtoCFlagSet(IPC_FLAG10);
- // Now we should wait for acknowledge of this flag
- while (IPCMtoCFlagBusy(IPC_CTOMIPCSTS_IPC10) == 1){};
- // By setting IPC_FLAG 11, C28 will tell us, that it had performed operation
- while (IPCCtoMFlagBusy(IPC_CTOMIPCSTS_IPC11) == 0){};
- IPCCtoMFlagAcknowledge(IPC_CTOMIPCSTS_IPC11);
- // Now when flash is erased, we can program it with our block
- flashData.cmd = M3_CMD_FLASH_DATA;
- IPCMtoCFlagSet(IPC_FLAG10);
- while (IPCMtoCFlagBusy(IPC_CTOMIPCSTS_IPC10) == 1){};
- while (IPCCtoMFlagBusy(IPC_CTOMIPCSTS_IPC11) == 0){};
- IPCCtoMFlagAcknowledge(IPC_CTOMIPCSTS_IPC11);
- while (1){
- IPCMtoCFlagBusy(IPC_CTOMIPCSTS_IPC11) == 0;
- IPCMtoCFlagSet(IPC_FLAG12);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment