/* * Copyright (c) 2015 - 2016 , Freescale Semiconductor, Inc. * Copyright 2016-2017 NXP * All rights reserved. * * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ /* Including needed modules to compile this module/procedure */ #include "Cpu.h" #include "clockMan1.h" #include "pin_mux.h" #include "canCom1.h" #include "dmaController1.h" #include "osif1.h" #if CPU_INIT_CONFIG #include "Init_Config.h" #endif volatile int exit_code = 0; /* User includes (#include below this line is not maintained by Processor Expert) */ #include #include /* This example is setup to work by default with EVB. To use it with other boards please comment the following line */ #define TX_MAILBOX (1UL) #define RX_MAILBOX (0UL) #define RX_PHY_ID 0x74Eu #define TX_PHY_ID 0x74Fu static const uint8_t msg_data[8] = {0x00, 0x01, 0x2, 0x03, 0x04, 0x05, 0x06, 0x07}; #define EVB #ifdef EVB #define LED_PORT PORTE #define GPIO_PORT PTE #define PCC_CLOCK PCC_PORTE_CLOCK #define LED1 21U #define LED2 22U #else #define LED_PORT PORTC #define GPIO_PORT PTC #define PCC_CLOCK PCC_PORTC_CLOCK #define LED1 0U #define LED2 1U #endif void delay(volatile int cycles) { /* Delay function - do nothing for a number of cycles */ while(cycles--); } void FlexCANInit(void) { FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0); } int main(void) { /*** 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 */ /* 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); /* Output direction for LED0 & LED1 */ PINS_DRV_SetPinsDirection(GPIO_PORT, ((1 << LED1) | (1 << LED2))); FlexCANInit(); /* 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 buff_RxTx_Cfg = { .msg_id_type = FLEXCAN_MSG_ID_STD, .data_length = 8, .fd_enable = false, .fd_padding = 0u, .enable_brs = true, .is_remote = false, }; /* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */ //FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &buff_RxTx_Cfg, RX_PHY_ID); FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, TX_MAILBOX, &buff_RxTx_Cfg,TX_PHY_ID); /* Set Output value LED0 & LED1 */ PINS_DRV_SetPins(GPIO_PORT, 1 << LED1); PINS_DRV_ClearPins(GPIO_PORT, 1 << LED2); /* Define receive buffer */ //flexcan_msgbuff_t recvBuff; FLEXCAN_DRV_Send(INST_CANCOM1,TX_MAILBOX,&buff_RxTx_Cfg,(uint32_t)TX_PHY_ID,msg_data); /*Send Test message on the bus*/ for (;;) { /* 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); /* Insert a small delay to make the blinking visible */ delay(720000); /* Toggle output value LED0 & LED1 */ PINS_DRV_TogglePins(GPIO_PORT, ((1 << LED1) | (1 << LED2))); } /*** 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 Freescale S32K series of microcontrollers. ** ** ################################################################### */