/***************************************************************************************************** * Function: main() * * Description: what I can say about it, it just the tipical main * * Caveats: *****************************************************************************************************/ void main(void) { /*Disable interrupts to start the MCU configuration*/ DisableInterrupts; /* Intilialize the interupt vector base address for default location */ Init_Interrupt_Vector(); Mcu_Init(); DDRA =0x0F; DDRB =0x0F; EnableInterrupts; SchM_Init(SchM_TaskConfigInitial); SchM_Start(); for(;;) { /* Call the scheduler */ SchM_Background(); /* feeds the dog */ _FEED_COP(); } /* loop forever */ /* please make sure that you never leave main */ }
void EcuM_Callout_DriverInitListOne(void) { Det_Init(); Dem_PreInit(); Mcu_Init(&McuModuleConfiguration_0); Mcu_AdditionalInit(); Mcl_Init(NULL_PTR); Port_Init(NULL_PTR); Adc_Init(NULL_PTR); Dio_Init(NULL_PTR); Gpt_Init(NULL_PTR); Pwm_Init(NULL_PTR); Icu_Init(NULL_PTR); Spi_Init(NULL_PTR); SpiCtrl_Init(); SwGpt_Init(); pIcomInstBle = ICOM_Create(); ICOMChannelStatus_Init(pIcomInstBle); ICOMChannelDiag_Init(pIcomInstBle); ExtFlashSpiCtrlInit(SpiConf_SpiChannel_Spi_NVM_Command,\ SpiConf_SpiSequence_Spi_Seq_NVM,\ SpiConf_SpiJob_Spi_Job_NVM); CC254xCDD_Init(pIcomInstBle, DioConf_DioChannel_B6_SPI_SRDY_CU_LPCPU,\ SpiConf_SpiChannel_Spi_TICC2540_Command_8,\ SpiConf_SpiSequence_Spi_Seq_Ble_Exchange); /* ******************************************************************* * Wdg must be the latest in the initialization sequence * otherwise the function call Spi_SetAsyncMode(SPI_INTERRUPT_MODE) * returns a negative response when initializing the CC254xCDD_Init *********************************************************************/ Wdg_Init(NULL_PTR); WdgM_Init(NULL_PTR); WdgM_SetMode(1U,0U); }
/** * Part of STARTUP I * * @param ConfigPtr */ void EcuM_AL_DriverInitOne(const EcuM_ConfigType *ConfigPtr) { (void)ConfigPtr; #if defined(USE_MCU) Mcu_Init(ConfigPtr->McuConfig); /* Set up default clock (Mcu_InitClock requires initRun==1) */ /* Ignoring return value */ (void) Mcu_InitClock(ConfigPtr->McuConfig->McuDefaultClockSettings); // Wait for PLL to sync. while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) { ; } Mcu_DistributePllClock(); #endif #if defined(USE_DEM) // Preinitialize DEM NO_DRIVER(Dem_PreInit(ConfigPtr->DemConfig)); #endif #if defined(USE_PORT) // Setup Port Port_Init(ConfigPtr->PortConfig); #endif #if defined(USE_DIO) // Setup Dio Dio_Init(ConfigPtr->DioCfg); #endif #if defined(USE_GPT) // Setup the GPT Gpt_Init(ConfigPtr->GptConfig); #endif // Setup watchdog #if defined(USE_WDG) Wdg_Init(ConfigPtr->WdgConfig); #endif #if defined(USE_WDGM) NO_DRIVER(WdgM_Init(ConfigPtr->WdgMConfig)); #endif #if defined(USE_DMA) // Setup DMA Dma_Init(ConfigPtr->DmaConfig); #endif #if defined(USE_ADC) // Setup ADC Adc_Init(ConfigPtr->AdcConfig); #endif #if defined(USE_BSWM) // Setup BSWM - not supporting configustructure for BswM BswM_Init(NULL); #endif // Setup ICU #if defined(USE_ICU) Icu_Init(ConfigPtr->IcuConfig); #endif // Setup PWM #if defined(USE_PWM) // Setup PWM Pwm_Init(ConfigPtr->PwmConfig); #endif // Setup OCU #if defined(USE_OCU) Ocu_Init(ConfigPtr->OcuConfig); #endif #if defined(CFG_SHELL) SHELL_Init(); #endif }
/***************************************************************************** * * @name Init_Sys * * @brief This function Initializes the system * * @param None * * @return None * **************************************************************************** * Intializes the MCU, MCG, KBI, RTC modules ***************************************************************************/ static void Init_Sys(void) { Mcu_Init(); /* initialize the MCU registers */ MCG_Init(); /* initialize the MCG to generate 24MHz bus clock */ }
/*----------------------------------------------------------------------------- * Main Program *---------------------------------------------------------------------------*/ int main(void) { Mcu_Init(); Timebase_Init(); sei(); #if defined(UART_OUTPUT) Serial_Init(); printf("\n------------------------------------------------------------\n"); printf( " CAN Test:\n"); printf( " Periodic Transmission on CAN\n"); printf( " CAN Dump\n"); printf( " CAN Echo\n"); printf( "------------------------------------------------------------\n"); printf("CanInit..."); if (Can_Init() != CAN_OK) { printf("FAILED!\n"); printf("Check wires between AVR and MCP2515 and the MCP speed (xtal)."); } else { printf("OK!\n"); printf("MCP2515 working fine\n"); } #elif defined(LED_OUTPUT) Can_Init(); #else Can_Init(); #endif uint32_t timeStamp = 0; Can_Message_t txMsg; Can_Message_t rxMsg; txMsg.RemoteFlag = 0; txMsg.ExtendedFlag = 1; txMsg.Id = SENDING_ID; txMsg.DataLength = 2; txMsg.Data.bytes[0] = 0x12; txMsg.Data.bytes[1] = 0x34; /* main loop */ while (1) { /* service the CAN routines */ Can_Service(); /* send CAN message and check for CAN errors once every second */ if (Timebase_PassedTimeMillis(timeStamp) >= 1000) { timeStamp = Timebase_CurrentTime(); /* send txMsg */ txMsg.Id = SENDING_ID; Can_Send(&txMsg); } /* check if any messages have been received */ while (Can_Receive(&rxMsg) == CAN_OK) { #if defined(UART_OUTPUT) /* Dump message data on uart */ printf("\nPKT %#lx %u %u", rxMsg.Id, (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); for (uint8_t i=0; i<rxMsg.DataLength; i++) { printf(" %#x", rxMsg.Data.bytes[i]); } #endif /* Echo function */ if(rxMsg.Id == ECHO_RECEIVE_ID){ #if defined(UART_OUTPUT) printf("\n\"ping\" received"); txMsg.Id = ECHO_SENDING_ID; /* Send reply */ Can_Send(&txMsg); printf("\nreply sent"); #else txMsg.Id = ECHO_SENDING_ID; /* Send reply */ Can_Send(&txMsg); #endif } } } return 0; }
void EcuM_AL_DriverInitOne(const EcuM_ConfigType* configPtr) { /* provide a proper clock */ Mcu_Init(configPtr->bsw_driver.init_one.mcu_cfg); Mcu_InitClock(0); Mcu_DistributePllClock(); /* ----------------------------------------------------------------------- Interrupt System: ----------------------------------------------------------------------- - four arbitration cycles (max. 255 interrupt sources) - two clocks per arbitration cycle */ __mtcr(0xFE2C, 0x00000000); /* load CPU interrupt control register */ __isync(); /* ----------------------------------------------------------------------- Peripheral Control Processor (PCP): ----------------------------------------------------------------------- - the PCP internal clock is always running - use Full Context save area (R[0] - R[7]) - start progam counter as left by last invocation - channel watchdog is disabled - maximum channel number checking is disabled */ /* - four arbitration cycles (max. 255 PCP channels) */ /* - two clocks per arbitration cycle */ PCP_ICR.U = 0x00000000; /* load PCP interrupt control register */ /* - the PCP warning mechanism is disabled */ PCP_ITR.U = 0x00000000; /* load PCP interrupt threshold register */ /* - type of service of PCP node 4 is CPU interrupt */ PCP_SRC4.U = 0x00001000; /* load service request control register 4 */ /* - type of service of PCP node 5 is CPU interrupt */ PCP_SRC5.U = 0x00001000; /* load service request control register 5 */ /* - type of service of PCP node 6 is CPU interrupt */ PCP_SRC6.U = 0x00001000; /* load service request control register 6 */ /* - type of service of PCP node 7 is CPU interrupt */ PCP_SRC7.U = 0x00001000; /* load service request control register 7 */ /* - type of service of PCP node 8 is CPU interrupt */ PCP_SRC8.U = 0x00001000; /* load service request control register 8 */ ts_initGPTAInt(); Port_Init(configPtr->bsw_driver.init_one.port_cfg); Adc_Init(configPtr->bsw_driver.init_one.adc_cfg); Fls_Init(configPtr->bsw_driver.init_one.fls_cfg); Gpt_Init(configPtr->bsw_driver.init_one.gpt_cfg); Pwm_Init(configPtr->bsw_driver.init_one.pwm_cfg); Spi_Init(configPtr->bsw_driver.init_one.spi_cfg); Wdg_Init(configPtr->bsw_driver.init_one.wdg_cfg); #ifdef ECUM_WDGM_INCLUDED WdgM_Init(configPtr->bsw_driver.init_one.wdgm_cfg); #endif /* setup end of init protected registers for OS */ ts_endinit_clear(); osInitProtected(); ts_endinit_set(); /* Overlay Ram: * Init registers and mem areas for switching from * working page (overlay ram) <-> reference page (flash) */ RAM_OverlayRamReset(); /* - the CPU interrupt system is globally disabled */ __enable(); Spi_SetAsyncMode(SPI_INTERRUPT_MODE); Adc_StartGroupConversion(0); Adc_StartGroupConversion(1); EcuM_SelectApplicationMode(OSDEFAULTAPPMODE); }
/*----------------------------------------------------------------------------- * Main Program *---------------------------------------------------------------------------*/ int main(void) { uint8_t nSensors, i; uint8_t subzero, cel, cel_frac_bits; Mcu_Init(); Timebase_Init(); Serial_Init(); sei(); printf( "\nDS18X20 1-Wire-Reader\n" ); printf( "-----------------------" ); nSensors = search_sensors(); printf( "%i DS18X20 Sensor(s) available:\n", (int) nSensors ); for (i=0; i<nSensors; i++) { printf("Sensor# %i is a ", (int) i+1); if ( gSensorIDs[i][0] == DS18S20_ID) printf("DS18S20/DS1820"); else printf("DS18B20"); printf(" which is "); if ( DS18X20_get_power_status( &gSensorIDs[i][0] ) == DS18X20_POWER_PARASITE ) printf( "parasite" ); else printf( "externally" ); printf( " powered\n" ); } printf("CanInit...\n"); if (Can_Init() != CAN_OK) { printf("FAILED!\n"); } else { printf("OK!\n"); } uint32_t timeStamp = 0; Can_Message_t txMsg; Can_Message_t rxMsg; txMsg.DataLength = 2; txMsg.Id = 0; txMsg.RemoteFlag = 0; txMsg.ExtendedFlag = 1; /* main loop */ while (1) { /* service the CAN routines */ Can_Service(); /* check if any messages have been received */ while (Can_Receive(&rxMsg) == CAN_OK) { } /* check temperature and send on CAN once every other second */ if (Timebase_PassedTimeMillis(timeStamp) >= 2000) { timeStamp = Timebase_CurrentTime(); if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK) { printf("Measuring temperature... "); delay_ms(DS18B20_TCONV_12BIT); for ( i=0; i<nSensors; i++ ) { if ( DS18X20_read_meas( &gSensorIDs[i][0], &subzero, &cel, &cel_frac_bits) == DS18X20_OK ) { //txMsg.Data.bytes[0] = subzero; if (subzero) { txMsg.Data.bytes[i*2] = -cel; txMsg.Data.bytes[i*2+1] = ~(cel_frac_bits<<4); } else { txMsg.Data.bytes[i*2] = cel; txMsg.Data.bytes[i*2+1] = (cel_frac_bits<<4); } } else printf("CRC Error (lost connection?)\n"); } txMsg.DataLength = nSensors*2; printf("sending...\n"); /* send txMsg */ Can_Send(&txMsg); } else printf("Start meas. failed (short circuit?)\n"); } } return 0; }
/** * Part of STARTUP I * * @param ConfigPtr */ void EcuM_AL_DriverInitOne(const EcuM_ConfigType *ConfigPtr) { (void)ConfigPtr; // VALIDATE_STATE( ECUM_STATE_STARTUP_ONE ); //lint --e{715} PC-Lint (715) - ConfigPtr usage depends on configuration of modules #if defined(USE_MCU) Mcu_Init(ConfigPtr->McuConfig); /* Set up default clock (Mcu_InitClock requires initRun==1) */ /* Ignoring return value */ (void) Mcu_InitClock(ConfigPtr->McuConfig->McuDefaultClockSettings); // Wait for PLL to sync. while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) { ; } Mcu_DistributePllClock(); #endif #if defined(USE_DEM) // Preinitialize DEM NO_DRIVER(Dem_PreInit(ConfigPtr->DemConfig)); #endif #if defined(USE_PORT) // Setup Port Port_Init(ConfigPtr->PortConfig); #endif #if defined(USE_GPT) // Setup the GPT Gpt_Init(ConfigPtr->GptConfig); #endif // Setup watchdog #if defined(USE_WDG) Wdg_Init(ConfigPtr->WdgConfig); #endif #if defined(USE_WDGM) NO_DRIVER(WdgM_Init(ConfigPtr->WdgMConfig)); #endif #if defined(USE_DMA) // Setup DMA Dma_Init(ConfigPtr->DmaConfig); #endif #if defined(USE_ADC) // Setup ADC Adc_Init(ConfigPtr->AdcConfig); #endif // Setup ICU // TODO // Setup PWM #if defined(USE_PWM) // Setup PWM Pwm_Init(ConfigPtr->PwmConfig); #endif #if defined(CFG_SHELL) SHELL_Init(); #endif }
void main(void) #endif { USB_STATUS status = USB_OK; _usb_host_handle host_handle; boolean send = TRUE; /* Initialize the current platform. Call for the _bsp_platform_init which is specific to each processor family */ _bsp_platform_init(); #ifdef MCU_MK70F12 sci2_init(); #else sci1_init(); #endif TimerInit(); /* Init polling global variable */ POLL_init(); #if (defined(_MCF51MM256_H) || (defined _MCF51JE256_H)) cmt_init(); Mcu_Init(); Kbi_Init(); pwm_init(); #endif #if (defined(__MCF52259_H__) || (defined (__MCF52221_H__)) ||(defined (_MK_xxx_H_)) ) GPIO_Init(); pit0_init(); pwm_init(); #endif #if (defined MCU_mcf51jf128) GPIO_Init(); mtim_init(); pwm_init(); #endif DisableInterrupts; #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H) usb_int_dis(); #endif /* ** It means that we are going to act like host, so we initialize the ** host stack. This call will allow USB system to allocate memory for ** data structures, it uses later (e.g pipes etc.). */ status = _usb_host_init ( HOST_CONTROLLER_NUMBER, /* Use value in header file */ MAX_FRAME_SIZE, /* Frame size per USB spec */ &host_handle); /* Returned pointer */ if (status != USB_OK) { printf("\nUSB Host Initialization failed! STATUS: 0x%x", (unsigned int) status); fflush(stdout); exit(3); } status = _usb_host_driver_info_register ( host_handle, (pointer)DriverInfoTable ); if (status != USB_OK) { printf("\nDriver Registration failed! STATUS: 0x%x",(unsigned int) status); fflush(stdout); exit(4); } EnableInterrupts; #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H) usb_int_en(); #endif printf("USB Host Audio Demo\r\nWaitting for USB Audio Device to be attached...\r\n"); _usb_event_init(&USB_Event); for(;;) { Poll(); Audio_Task(); __RESET_WATCHDOG(); /* feeds the dog */ } /* loop forever */ /* please make sure that you never leave main */ #ifdef __GNUC__ return 0; #endif }
/*!**************************************************************************** * * \name System_Init * * \brief This function Initializes the system * * \param None * * \return None * **************************************************************************** * Intializes the MCU, MCG, KBI, RTC modules ***************************************************************************/ void System_Init(void) { Mcu_Init(); /* initialize the MCU registers */ MCG_Init(); /* initialize the MCG to generate 24MHz bus clock */ }