void os_error (U32 err_code) { /* This function is called when a runtime error is detected. Parameter */ /* 'err_code' holds the runtime error code (defined in RTL.H). */ switch (err_code) { case OS_ERR_STK_OVF: TRACE_FATAL("Stack Overflow \n"); case OS_ERR_FIFO_OVF: TRACE_FATAL("FIFO Overflow \n"); case OS_ERR_MBX_OVF: TRACE_FATAL("Mailbox Overflow \n"); } /* HERE: include optional code to be executed on runtime error. */ for (;;); }
esint8 if_initInterface(hwInterface* file, eint8* opts) { unsigned int value; file->pMedia = (Media *)opts; if(file->pMedia->blockSize > SECTOR_SIZE_DISK) { TRACE_FATAL("EFSL sector size < %d!\n\r", SECTOR_SIZE_DISK); return -1; } if (file->pMedia->blockSize >= SECTOR_SIZE_DISK) file->sectorCount = file->pMedia->size * (file->pMedia->blockSize / SECTOR_SIZE_DISK); else file->sectorCount = file->pMedia->size / (SECTOR_SIZE_DISK / file->pMedia->blockSize); return(0); }
/* main ***********************************************************************/ int main(void) { CO_NMT_reset_cmd_t reset = CO_RESET_NOT; InitCanLeds(); DBGU_Configure(115200); TRACE_INFO_WP("\n\rCanOpenNode %s (%s %s)\n\r", cVer, __DATE__, __TIME__); /* Configure Timer interrupt function for execution every 1 millisecond */ if (SysTick_Config(SysTick_1ms)) TRACE_FATAL("SysTick_Config\n\r"); initTimer(getTimer_us); /* Todo: initialize EEPROM */ /* Todo: Loading COD */ TRACE_INFO("Loading COD\n\r"); /* Verify, if OD structures have proper alignment of initial values */ TRACE_DEBUG("Checking COD in RAM (size=%d)\n\r", &CO_OD_RAM.LastWord - &CO_OD_RAM.FirstWord); if (CO_OD_RAM.FirstWord != CO_OD_RAM.LastWord) TRACE_FATAL("Err COD in RAM\n\r"); TRACE_DEBUG("Checking COD in EEPROM (size=%d)\n\r", &CO_OD_EEPROM.LastWord - &CO_OD_EEPROM.FirstWord); if (CO_OD_EEPROM.FirstWord != CO_OD_EEPROM.LastWord) TRACE_FATAL("Err COD in EEPROM\n\r"); TRACE_DEBUG("Checking COD in ROM (size=%d)\n\r", &CO_OD_ROM.LastWord - &CO_OD_ROM.FirstWord); if (CO_OD_ROM.FirstWord != CO_OD_ROM.LastWord) TRACE_FATAL("Err COD in ROM\n\r"); /* increase variable each startup. Variable is stored in eeprom. */ OD_powerOnCounter++; TRACE_INFO("CO power-on (BTR=%dk Node=0x%x)\n\r", CO_OD_ROM.CANBitRate, CO_OD_ROM.CANNodeID); ttimer tprof; while (reset != CO_RESET_APP) { /* CANopen communication reset - initialize CANopen objects *******************/ static uint32_t timer1msPrevious; CO_ReturnError_t err; /* disable timer interrupts, turn on red LED */ canTimerOff = 1; CanLedsSet(eCoLed_Red); /* initialize CANopen */ err = CO_init(); if (err) { TRACE_FATAL("CO_init\n\r"); /* CO_errorReport(CO->em, CO_EM_MEMORY_ALLOCATION_ERROR, CO_EMC_SOFTWARE_INTERNAL, err); */ } /* start Timer */ canTimerOff = 0; reset = CO_RESET_NOT; timer1msPrevious = CO_timer1ms; TRACE_INFO("CO (re)start\n\r"); while (reset == CO_RESET_NOT) { saveTime(&tprof); /* loop for normal program execution ******************************************/ uint32_t timer1msDiff; timer1msDiff = CO_timer1ms - timer1msPrevious; timer1msPrevious = CO_timer1ms; ClearWDT(); /* CANopen process */ reset = CO_process(CO, timer1msDiff); CanLedsSet((LED_GREEN_RUN(CO->NMT)>0 ? eCoLed_Green : 0) | (LED_RED_ERROR(CO->NMT)>0 ? eCoLed_Red : 0)); ClearWDT(); /* (not implemented) eeprom_process(&eeprom); */ uint32_t t = getTime_us(&tprof); OD_performance[ODA_performance_mainCycleTime] = t; if (t > OD_performance[ODA_performance_mainCycleMaxTime]) OD_performance[ODA_performance_mainCycleMaxTime] = t; } /* while (reset != 0) */ } /* while (reset != 2) */ /* program exit ***************************************************************/ /* save variables to eeprom */ CO_DISABLE_INTERRUPTS(); CanLedsSet(eCoLed_None); /* (not implemented) eeprom_saveAll(&eeprom); */ CanLedsSet(eCoLed_Red); /* delete CANopen object from memory */ CO_delete(); /* reset - by WD */ return 0; }
void HardFault_Handler(void) { TRACE_FATAL("HardFault\n\r"); }
/** * Configure the TC0 and DACC for audio output. * \param sampleRate Audio sample rate. * \param nbChannels Number of audio channels. * \param mck MCK frequence. */ static void ConfigureAudioPlay(uint32_t sampleRate, uint8_t nbChannels, uint32_t mck) { uint32_t div = 2; uint32_t tcclks = TC_CMR_TCCLKS_TIMER_CLOCK1; uint32_t freq = sampleRate * nbChannels; double ra, rc; /* Enable TC0 Peripheral */ PMC_EnablePeripheral(ID_TC0); { uint32_t divs[5] = {2, 8, 32, 128,BOARD_MCK / 32768}; uint8_t i = 0; divs[4] = mck/32768; /* Minimize DIV & Maxmize RC for better waveform */ while(freq < ((mck / divs[i]) / 65536)) { ++ i; if (i == 5) { TRACE_FATAL("Cann't find TC0 divisor!\n\r"); } } div = divs[i]; tcclks = i; } /* Configure TC for tioa output: 48M -> 48K*2 */ TC_Configure(TC0,0, tcclks /*MCK/2*/ | TC_CMR_ACPC_SET | TC_CMR_WAVE | TC_CMR_ACPA_CLEAR | TC_CMR_CPCTRG); /* 50% duty ,freq frequency*/ ra = (((double)mck/div)/(freq*2) + 0.5 ); rc = (((double)mck/div)/(freq) + 0.99); TC0->TC_CHANNEL[0].TC_RA = (uint32_t)ra; TC0->TC_CHANNEL[0].TC_RC = (uint32_t)ra*2; defaultRA = (uint32_t)ra; printf("-I- MCK %dKHz, Div %d(%x), RA: %d*.01(%x), RC: %d*.01(%x)\n\r", (int)mck/1000, (int)div, (unsigned int)div, (int)(ra*100), (int)ra, (int)(rc*100), (int)rc); /* Initialize DACC with HW as trigger */ DACC_Initialize( DACC, ID_DACC, 1, 1, 0, /* DACC_MR_WORD_HALF */ 0, BOARD_MCK, 8, CHANNEL_R, 1, 16); /* channel number is in the first 4 significant bits*/ DACC->DACC_MR |= DACC_MR_TAG; /* disable PDC for DAC */ DACC->DACC_PTCR = DACC_PTCR_TXTDIS; /* Mute */ AudioPlayEnable(0); /* Enable DACC ISR */ NVIC_EnableIRQ(DACC_IRQn); }