void CanRxInterruptHandler0(void) { /* Check for Node error */ if (CAN_NODE_GetStatus(&CAN_NODE_0) & XMC_CAN_NODE_STATUS_LAST_ERROR_CODE) { XMC_DEBUG("Something failed\n"); } else if (CAN_NODE_MO_GetStatus(&CAN_NODE_0_LMO_01_Config) & XMC_CAN_MO_STATUS_RX_PENDING) { /* Read the received Message object and stores in Request_Node_LMO_02_Config*/ CAN_NODE_MO_Receive(&CAN_NODE_0_LMO_01_Config); if (CAN_NODE_0_LMO_01_Config.mo_ptr->can_data_byte[7] == 1) { enable_flooding = ACTIVATED; } else { enable_flooding = NOT_ACTIVATED; } } else if (CAN_NODE_MO_GetStatus(&CAN_NODE_0_LMO_02_Config) & XMC_CAN_MO_STATUS_RX_PENDING) { //enable_flooding = ACTIVATED; /* Read the received Message object and stores in Request_Node_LMO_02_Config*/ CAN_NODE_MO_Receive(&CAN_NODE_0_LMO_02_Config); } }
/*Gets the timer value of CCU4_CC4 slice. */ uint32_t PWM_CCU4_GetTimerValue(PWM_CCU4_t* handle_ptr) { uint32_t timer_value; XMC_ASSERT("PWM_CCU4_GetTimerValue:handle_ptr NULL", (handle_ptr != NULL)); timer_value = (uint32_t) XMC_CCU4_SLICE_GetTimerValue(handle_ptr->ccu4_slice_ptr); XMC_DEBUG("PWM_CCU4_GetTimerValue:timer value"); return (timer_value); }/* end of PWM_CCU4_GetTimerValue() api */
/*Sets the frequency for CCU4_CC4 slice. */ PWM_CCU4_STATUS_t PWM_CCU4_SetFreq(PWM_CCU4_t* handle_ptr, uint32_t pwm_freq_hz) { PWM_CCU4_STATUS_t status; uint32_t frequency_tclk; uint32_t period; uint32_t duty; uint16_t compare; status = PWM_CCU4_STATUS_FAILURE; frequency_tclk = 0U; XMC_ASSERT("PWM_CCU4_SetFreq:handle_ptr NULL", (handle_ptr != NULL)); if (PWM_CCU4_STATE_UNINITIALIZED != handle_ptr->state) { if (0U == pwm_freq_hz) { XMC_DEBUG("PWM_CCU4_SetFreq:cannot set frequency 0Hz"); } else { frequency_tclk = handle_ptr->frequency_tclk; period = frequency_tclk / pwm_freq_hz; if ((uint32_t) XMC_CCU4_SLICE_TIMER_COUNT_MODE_CA == handle_ptr->config_ptr->ccu4_cc4_slice_timer_ptr->timer_mode) { period = period >> 1U;/*divide by 2*/ } if ((period != 0U) && (period <= PWM_CCU4_MAX_TIMER_COUNT)) { /*Calculate the current duty cycle in no-timer concatenation mode*/ duty = handle_ptr->sym_duty; duty = (PWM_CCU4_DUTY_FULL_SCALE - duty); duty = duty * period; duty = duty / PWM_CCU4_DUTY_FULL_SCALE; compare = (uint16_t) duty; XMC_CCU4_SLICE_SetTimerPeriodMatch(handle_ptr->ccu4_slice_ptr, (uint16_t)(period - 1U)); XMC_CCU4_SLICE_SetTimerCompareMatch(handle_ptr->ccu4_slice_ptr, compare); XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_module_ptr, handle_ptr->shadow_txfr_msk); XMC_DEBUG("PWM_CCU4_SetFreq:frequency set"); status = PWM_CCU4_STATUS_SUCCESS; } } }
int main(void) { DAVE_STATUS_t status; const uint32_t Button_NotPressed = 1; uint32_t Button1OldValue = Button_NotPressed; status = DAVE_Init(); /* Initialization of DAVE APPs */ if (status == DAVE_STATUS_FAILURE) { /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */ XMC_DEBUG("DAVE APPs initialization failed\n"); while (1U) { } } /* Placeholder for user application code. The while loop below can be replaced with user application code. */ while (1U) { if (enable_flooding == ACTIVATED) { DIGITAL_IO_SetOutputHigh(&LED2); CAN_NODE_MO_Transmit(&CAN_NODE_0_LMO_03_Config); } else { DIGITAL_IO_SetOutputLow(&LED2); } { uint32_t Button1Value = DIGITAL_IO_GetInput(&Button1); /* react on edge */ if ((Button1Value != Button_NotPressed) && (Button1Value != Button1OldValue)) { if (enable_flooding == ACTIVATED) { enable_flooding = NOT_ACTIVATED; } else { enable_flooding = ACTIVATED; } } Button1OldValue = Button1Value; } } }
/* * Initialization function which initializes the SYSTIMER APP, configures SysTick timer and SysTick exception. */ SYSTIMER_STATUS_t SYSTIMER_Init(SYSTIMER_t *handle) { SYSTIMER_STATUS_t status = SYSTIMER_STATUS_SUCCESS; XMC_ASSERT("SYSTIMER_Init: SYSTIMER APP handle pointer uninitialized", (handle != NULL)); /* Check APP initialization status to ensure whether SYSTIMER_Init called or not, initialize SYSTIMER if * SYSTIMER_Init called first time. */ if (false == handle->init_status) { #if (UC_FAMILY == XMC4) /* Initialization of CPU_CTRL_XMC4 APP */ status = (SYSTIMER_STATUS_t)CPU_CTRL_XMC4_Init(CPU_CTRL_HANDLE); #else /* Initialization of CPU_CTRL_XMC1 APP */ status = (SYSTIMER_STATUS_t)CPU_CTRL_XMC1_Init(CPU_CTRL_HANDLE); #endif if (SYSTIMER_STATUS_FAILURE != status) { /* Initialize the header of the list */ g_timer_list = NULL; /* Initialize SysTick timer */ status = (SYSTIMER_STATUS_t)SysTick_Config((uint32_t)(SYSTIMER_SYSTICK_CLOCK * SYSTIMER_TICK_PERIOD)); if (SYSTIMER_STATUS_FAILURE == status) { XMC_DEBUG("SYSTIMER_Init: Timer reload value out of range"); } else { #if (UC_FAMILY == XMC4) /* setting of First SW Timer period is always and subpriority value for XMC4000 devices */ NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority( NVIC_GetPriorityGrouping(), SYSTIMER_PRIORITY, SYSTIMER_SUBPRIORITY)); #elif (UC_FAMILY == XMC1) /* setting of priority value for XMC1000 devices */ NVIC_SetPriority(SysTick_IRQn, SYSTIMER_PRIORITY); #endif g_timer_tracker = 0U; /* Update the Initialization status of the SYSTIMER APP instance */ handle->init_status = true; status = SYSTIMER_STATUS_SUCCESS; } } } return (status); }
int main(void) { DAVE_STATUS_t status; // Startup error status = DAVE_Init(); // Initialization of DAVE APPs if(status == DAVE_STATUS_FAILURE) { XMC_DEBUG("DAVE APPs initialization failed\n"); while(1U) { DIGITAL_IO_SetOutputHigh(&DIGITAL_IO_1); // Turn on LED2 for errors } } startCommRX(); // Start serial connection with the node while(1U) { if(mbTimeout > MB_TIMEOUT) // Check if the current slave is taking too long to reply // If it is, move on to the next one { if(mbCurrentSlave == MB_MAX_SLAVE) { mbCurrentSlave = 1; } else { mbCurrentSlave++; } mbReadyForRead = 1; } if(mbReadyForRead) { mbReadFloat(mbCurrentSlave); // Poll the mbReadyForRead flag and start a new reading } if(commReadyForWrite && !queueIsEmpty) { commSendData(); // commReadyForWrite - UART Hardware ready // queueIsEmpty - Readings Queue } } }
/*Stops the CCU4_CC4 slice. */ PWM_CCU4_STATUS_t PWM_CCU4_Stop(PWM_CCU4_t* handle_ptr) { PWM_CCU4_STATUS_t status; status = PWM_CCU4_STATUS_FAILURE; XMC_ASSERT("PWM_CCU4_Stop:handle_ptr NULL", (handle_ptr != NULL)); if (PWM_CCU4_STATE_UNINITIALIZED != handle_ptr->state) { XMC_CCU4_SLICE_StopTimer(handle_ptr->ccu4_slice_ptr); XMC_CCU4_SLICE_ClearTimer(handle_ptr->ccu4_slice_ptr); XMC_CCU4_DisableClock(handle_ptr->ccu4_module_ptr, handle_ptr->slice_number); handle_ptr->state = PWM_CCU4_STATE_STOPPED; status = PWM_CCU4_STATUS_SUCCESS; XMC_DEBUG("PWM_CCU4_Stop:stop PWM"); } return (status); } /* end of PWM_CCU4_Stop() api */
/** * \brief This function initializes the hardware * * * \details Sensors are set up, polynomials are calculated and other general preparations are made */ void setup(void) { initBluetoothStorage();//initialize space for variables used for Bluetooth Communication //-------------------Dave Setup--------------------- DAVE_STATUS_t status; status = DAVE_Init();//Initialization of DAVE APPs if (status == DAVE_STATUS_FAILURE) { /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */ XMC_DEBUG("DAVE APPs initialization failed\n"); while (1U); } disableIRQ();//disables all Interrupts delay(2000);//waits 2000ms enableIRQ();//enables configurated Interrupts setup_STATE_LEDs();//setup Status-LED's WatchRC_Init();//initialize RC-Watchdog setup_UART_Trigger_limits();//setup Trigger-Limits of UART-FIFO PressureFIR = Initialize_FIR_Filter(PressureFIR, MOVING_AVERAGE);//initialize FIR Filter setupDPS310I2C();//initialize DPS310 getCoefficients();//get Coefficients of DPS310 setupDPS310();//setup DPS Hardware MPU9150_Setup();//configures the IMU delay(3000);//wait 3000ms to wait for ESC's to startup // initialize controller polynomials polynoms.b_roll[0]=parameter.P_roll-parameter.I_roll*parameter.T-parameter.P_roll*parameter.N_roll*parameter.T+parameter.N_roll*parameter.I_roll*parameter.T*parameter.T+parameter.D_roll*parameter.N_roll; polynoms.b_roll[1]=parameter.I_roll*parameter.T-2*parameter.P_roll+parameter.P_roll*parameter.N_roll*parameter.T-2*parameter.D_roll*parameter.N_roll; polynoms.b_roll[2]=parameter.P_roll+parameter.D_roll*parameter.N_roll; polynoms.a_roll[0]=1-parameter.N_roll*parameter.T; polynoms.a_roll[1]=parameter.N_roll*parameter.T-2; polynoms.b_pitch[0]=parameter.P_pitch-parameter.I_pitch*parameter.T-parameter.P_pitch*parameter.N_pitch*parameter.T+parameter.N_pitch*parameter.I_pitch*parameter.T*parameter.T+parameter.D_pitch*parameter.N_pitch; polynoms.b_pitch[1]=parameter.I_pitch*parameter.T-2*parameter.P_pitch+parameter.P_pitch*parameter.N_pitch*parameter.T-2*parameter.D_pitch*parameter.N_pitch; polynoms.b_pitch[2]=parameter.P_pitch+parameter.D_pitch*parameter.N_pitch; polynoms.a_pitch[0]=1-parameter.N_pitch*parameter.T; polynoms.a_pitch[1]=parameter.N_pitch*parameter.T-2; TIMER_Start(&Control_Timer);//start Timer for Controller }
/*Starts the CCU4_CC4 slice. This needs to be called even if external start is configured.*/ PWM_CCU4_STATUS_t PWM_CCU4_Start(PWM_CCU4_t* handle_ptr) { PWM_CCU4_STATUS_t status; status = PWM_CCU4_STATUS_FAILURE; XMC_ASSERT("PWM_CCU4_Start:handle_ptr NULL", (handle_ptr != NULL)); if ((PWM_CCU4_STATE_INITIALIZED == handle_ptr->state) || (PWM_CCU4_STATE_STOPPED == handle_ptr->state)) { /* clear IDLE mode for the slice; Start timer */ XMC_CCU4_EnableClock(handle_ptr->ccu4_module_ptr, handle_ptr->slice_number); if (XMC_CCU4_SLICE_EVENT_NONE == handle_ptr->config_ptr->ext_start_event) { XMC_CCU4_SLICE_StartTimer(handle_ptr->ccu4_slice_ptr); } handle_ptr->state = PWM_CCU4_STATE_RUNNING; status = PWM_CCU4_STATUS_SUCCESS; XMC_DEBUG("PWM_CCU4_Start:start PWM"); } return (status); } /* end of PWM_CCU4_Start() api */
int main(void) { DAVE_STATUS_t status; status = DAVE_Init(); /* Initialization of DAVE APPs */ if(status == DAVE_STATUS_FAILURE) { /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */ XMC_DEBUG("DAVE APPs initialization failed\n"); while(1U) { } } tempinit(); /* Placeholder for user application code. The while loop below can be replaced with user application code. */ while(1U) { } }
static void PWM_CCU4_lInit_Interrupt(PWM_CCU4_t* handle_ptr) { /* Enable events. Bind event to corresponding service request node.Enable Interrupts. The user may choose to disable the interrupts by LLD calls. */ if ((bool) true == handle_ptr->config_ptr->int_per_match) { XMC_DEBUG("PWM_CCU4_Init: Interrupt period match enable"); XMC_CCU4_SLICE_SetInterruptNode(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH, handle_ptr->config_ptr->sr_per_match); XMC_CCU4_SLICE_EnableEvent(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH); } if ((bool) true == handle_ptr->config_ptr->int_cmp_match_up) { XMC_DEBUG("PWM_CCU4_Init: Interrupt compare match up enable"); XMC_CCU4_SLICE_SetInterruptNode(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP, handle_ptr->config_ptr->sr_cmp_match_up); XMC_CCU4_SLICE_EnableEvent(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP); } if ((bool) true == handle_ptr->config_ptr->int_cmp_match_down) { XMC_DEBUG("PWM_CCU4_Init: Interrupt compare match down enable"); XMC_CCU4_SLICE_SetInterruptNode(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_DOWN, handle_ptr->config_ptr->sr_cmp_match_down); XMC_CCU4_SLICE_EnableEvent(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_DOWN); } if ((bool) true == handle_ptr->config_ptr->int_one_match_down) { XMC_DEBUG("PWM_CCU4_Init: Interrupt one match enable"); XMC_CCU4_SLICE_SetInterruptNode(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_ONE_MATCH, handle_ptr->config_ptr->sr_one_match_down); XMC_CCU4_SLICE_EnableEvent(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_ONE_MATCH); } if ((bool) true == handle_ptr->config_ptr->int_e0) { XMC_DEBUG("PWM_CCU4_Init: Interrupt event 0 enable"); XMC_CCU4_SLICE_SetInterruptNode(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_EVENT0, handle_ptr->config_ptr->sr_e0); XMC_CCU4_SLICE_EnableEvent(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_EVENT0); } if ((bool) true == handle_ptr->config_ptr->int_e1) { XMC_DEBUG("PWM_CCU4_Init: Interrupt event 1 enable"); XMC_CCU4_SLICE_SetInterruptNode(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_EVENT1, handle_ptr->config_ptr->sr_e1); XMC_CCU4_SLICE_EnableEvent(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_EVENT1); } if ((bool) true == handle_ptr->config_ptr->int_e2) { XMC_DEBUG("PWM_CCU4_Init: Interrupt event 2 enable"); XMC_CCU4_SLICE_SetInterruptNode(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_EVENT2, handle_ptr->config_ptr->sr_e2); XMC_CCU4_SLICE_EnableEvent(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_EVENT2); } }
/* This function initializes the app */ PWM_CCU4_STATUS_t PWM_CCU4_Init(PWM_CCU4_t* handle_ptr) { PWM_CCU4_STATUS_t status; GLOBAL_CCU4_STATUS_t status_ccu4_global; uint32_t frequency_module; uint32_t prescalar; status = PWM_CCU4_STATUS_FAILURE; status_ccu4_global = GLOBAL_CCU4_STATUS_FAILURE; XMC_ASSERT("PWM_CCU4_Init:handle_ptr is NULL", (handle_ptr != NULL)); if (PWM_CCU4_STATE_UNINITIALIZED == handle_ptr->state) { /* Initialize consumed Apps */ status_ccu4_global = GLOBAL_CCU4_Init(handle_ptr->config_ptr->global_ccu4_handle); /* Initialize CCU4x_CC4y slice */ if (GLOBAL_CCU4_STATUS_SUCCESS == status_ccu4_global) { XMC_DEBUG("PWM_CCU4_Init:Initilizing slice"); /* Configure CCU4x_CC4y slice as timer */ XMC_CCU4_SLICE_CompareInit(handle_ptr->ccu4_slice_ptr, handle_ptr->config_ptr->ccu4_cc4_slice_timer_ptr); /* Set period match value of the timer */ XMC_CCU4_SLICE_SetTimerPeriodMatch(handle_ptr->ccu4_slice_ptr, handle_ptr->config_ptr->period_value); /* Set timer compare match value for channel 1 */ XMC_CCU4_SLICE_SetTimerCompareMatch(handle_ptr->ccu4_slice_ptr, (uint16_t) handle_ptr->config_ptr->compare_value); if (1U == handle_ptr->config_ptr->ccu4_cc4_slice_timer_ptr->mcm_enable) { XMC_CCU4_SetMultiChannelShadowTransferMode(handle_ptr->ccu4_module_ptr, (uint32_t) handle_ptr->config_ptr->mcm_shadow_txfr_mode); } #if (UC_SERIES == XMC14) /*below feature available in XMC14xx devices */ XMC_CCU4_SLICE_SetShadowTransferMode(handle_ptr->ccu4_slice_ptr, handle_ptr->config_ptr->shadow_transfer_mode); XMC_CCU4_SLICE_WriteImmediateAfterShadowTransfer(handle_ptr->ccu4_slice_ptr, handle_ptr->config_ptr->immediate_write); XMC_CCU4_SLICE_EnableAutomaticShadowTransferRequest(handle_ptr->ccu4_slice_ptr, handle_ptr->config_ptr->automatic_shadow_transfer); if((bool)true == handle_ptr->config_ptr->cascaded_shadow_txfr_enable) { XMC_CCU4_SLICE_EnableCascadedShadowTransfer(handle_ptr->ccu4_slice_ptr); } #endif /* Transfer value from shadow timer registers to actual timer registers */ XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_module_ptr, handle_ptr->shadow_txfr_msk); XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_module_ptr, handle_ptr->dither_shadow_txfr_msk); /* Configure events */ PWM_CCU4_lConfigure_Events(handle_ptr); /* Enable the interrupts */ PWM_CCU4_lInit_Interrupt(handle_ptr); /*Initializes the GPIO*/ if ((bool) true == handle_ptr->config_ptr->gpio_ch_out_enable) { XMC_GPIO_Init(handle_ptr->config_ptr->gpio_ch_out_ptr, handle_ptr->config_ptr->gpio_ch_out_pin, handle_ptr->config_ptr->gpio_ch_out_config_ptr); } frequency_module = handle_ptr->config_ptr->global_ccu4_handle->module_frequency; prescalar = (uint32_t) handle_ptr->config_ptr->ccu4_cc4_slice_timer_ptr->prescaler_initval; frequency_module = frequency_module / ((uint32_t) 1 << prescalar); handle_ptr->frequency_tclk = frequency_module; handle_ptr->state = PWM_CCU4_STATE_INITIALIZED; status = PWM_CCU4_STATUS_SUCCESS; /* Start the PWM generation if start at initialization is enabled */ if ((bool) true == handle_ptr->config_ptr->start_control) { status = PWM_CCU4_Start(handle_ptr); } } else { handle_ptr->state = PWM_CCU4_STATE_UNINITIALIZED; } } else { status = PWM_CCU4_STATUS_ALREADY_INITIALIZED; XMC_DEBUG("PWM_CCU4_Init:PWM_CCU4_STATUS_ALREADY_INITIALIZED"); } return (status); } /* end of PWM_CCU4_Init() api */