/* ################################################################### ** Filename : main.c ** Processor : S32K1xx ** Abstract : ** Main module. ** This module contains user's application code. ** Settings : ** Contents : ** No public methods ** ** ###################################################################*/ /*! ** @file main.c ** @version 01.00 ** @brief ** Main module. ** This module contains user's application code. */ /*! ** @addtogroup main_module main module documentation ** @{ */ /* MODULE main */ /* Including necessary module. Cpu.h contains other modules needed for compiling.*/ #include "Cpu.h" #include "pin_mux.h" #include "flexTimer_pwm1.h" #include "clockMan1.h" volatile int exit_code = 0U; /* User includes (#include below this line is not maintained by Processor Expert) */ #include #include #define TX_MAILBOX (1UL) #define TX_MSG_ID (0x123) #define RX_MAILBOX (0UL) #define RX_MSG_ID (0x111) #define SPEED_CHANGE_REQUESTED (01) /* * @brief : Initialize clocks, pins and power modes */ void BoardInit(void) { /* Initialize and configure clocks * - Setup system clocks, dividers * - Configure FlexCAN clock, GPIO * - see clock manager component for more details */ CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT); CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE); /* Initialize pins * - Init FlexCAN and GPIO pins * - See PinSettings component for more info */ PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr); } void SendCANData(uint32_t mailbox, uint32_t messageId, uint8_t * data, uint32_t len) { /* Set information about the data to be sent * - 1 byte in length * - Standard message ID * - Bit rate switch enabled to use a different bitrate for the data segment * - Flexible data rate enabled * - Use zeros for FD padding */ flexcan_data_info_t dataInfo = { .data_length = len, .msg_id_type = FLEXCAN_MSG_ID_STD, .enable_brs = true, .fd_enable = false, .fd_padding = 0U }; /* Configure TX message buffer with index TX_MSG_ID and TX_MAILBOX*/ FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, mailbox, &dataInfo, messageId); /* Execute send non-blocking */ FLEXCAN_DRV_Send(INST_CANCOM1, mailbox, &dataInfo, messageId, data); } /* * @brief Initialize FlexCAN driver and configure the bit rate */ void FlexCANInit(void) { /* * Initialize FlexCAN driver * - 8 byte payload size * - FD enabled * - Bus clock as peripheral engine clock */ FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0); } /*********************************** * @brief: Wait for a number of cycles * @param nbOfCycles is number of cycles to be waited for ***********************************/ void delayCycles(volatile uint32_t cycles) { while (cycles--) { } } /* User includes (#include below this line is not maintained by Processor Expert) */ /*! \brief The main function for the project. \details The startup initialization sequence is the following: * - startup asm routine * - main() */ int main(void) { /* Write your local variable definition here */ /* Variables used to store PWM duty cycle */ ftm_state_t ftmStateStruct; uint16_t dutyCycle = 0xFFFU; bool increaseDutyCycle = false; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ #ifdef PEX_RTOS_INIT PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ /* Do the initializations required for this application */ BoardInit(); FlexCANInit(); // /* Initialize and configure clocks // * - see clock manager component for details // */ CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT); CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT); // // /* Initialize pins // * - See PinSettings component for more info // */ PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr); /* Initialize FTM PWM channel 0 PTE21 * - See ftm component for more info */ FTM_DRV_Init(INST_FLEXTIMER_PWM1, &flexTimer_pwm1_InitConfig, &ftmStateStruct); /* Initialize FTM PWM channel */ FTM_DRV_InitPwm(INST_FLEXTIMER_PWM1, &flexTimer_pwm1_PwmConfig); /* Infinite loop * - increment or decrement duty cycle * - Update channel duty cycle * - Wait for a number of cycles to make * the change visible */ /* Set information about the data to be received * - 1 byte in length * - Standard message ID * - Bit rate switch enabled to use a different bitrate for the data segment * - Flexible data rate enabled * - Use zeros for FD padding */ flexcan_data_info_t dataInfo = { .data_length = 8U, .msg_id_type = FLEXCAN_MSG_ID_STD, .enable_brs = true, .fd_enable = true, .fd_padding = 0U }; /* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */ FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, RX_MSG_ID); uint8_t MCU_DATA[8] = {1,2,3,4,5,6,7,8}; //void SendCANData(uint32_t mailbox, uint32_t messageId, uint8_t * data, uint32_t len) while (1) { //SendCANData(TX_MAILBOX,TX_MSG_ID,MCU_DATA,8); //delayCycles(20000); /* Define receive buffer */ flexcan_msgbuff_t recvBuff; // // /* Start receiving data in RX_MAILBOX. */ FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff); // // /* Wait until the previous FlexCAN receive is completed */ while(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) == STATUS_BUSY); // /* Check the received message ID and payload */ if((recvBuff.data[0] == 0x01) && recvBuff.msgId == RX_MSG_ID) { int a = 0; } } /* For example: for(;;) { } */ /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;) { if(exit_code != 0) { break; } } return exit_code; /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/ /* END main */ /*! ** @} */ /* ** ################################################################### ** ** This file was created by Processor Expert 10.1 [05.21] ** for the NXP S32K series of microcontrollers. ** ** ################################################################### */