在线时间15 小时
UID2086045
注册时间2016-1-10
NXP金币0
该用户从未签到
注册会员

- 积分
- 117
- 最后登录
- 2022-6-26
|

楼主 |
发表于 2018-5-24 15:01:36
|
显示全部楼层
/* ###################################################################
** Filename : main.c
** Processor : S32K14x
** 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"
volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include "lpuart_driver.h"
#define welcomeMsg0 "This example is an simple echo using LPUART0\r\n\
it will send back any character you send to it.\r\n\
The board will greet you if you send 'Hello Board'\r\
\nNow you can begin typing:\r\n"
#define welcomeMsg1 "This example is an simple echo using LPUART1\r\n\
it will send back any character you send to it.\r\n\
The board will greet you if you send 'Hello Board'\r\
\nNow you can begin typing:\r\n"
/* Declare a buffer used to store the received data */
uint32_t bytesRemaining;
#define lpuart0_receive_size 100
#define lpuart1_receive_size 100
uint8_t lpuart0_send_buf[100] = {0, };
uint8_t lpuart1_send_buf[100] = {0, };
uint8_t lpuart0_receive_buf[lpuart0_receive_size] = {0, };
uint8_t lpuart1_receive_buf[lpuart1_receive_size] = {0, };
uint32_t lpuart0_receive_bytes = 0;
uint32_t lpuart1_receive_bytes = 0;
/* @brief Callback for all peripherals which support UART features
* Implements : uart_callback_t_Class
* typedef void (*uart_callback_t)(void *driverState, uart_event_t event, void *userData);
*/
void LPUART0_Rx_Callback_IRQHandler(void *driverState, uart_event_t event, void *userData)
{
uint8_t ch_temp;
ch_temp = LPUART0->DATA;
lpuart0_receive_buf[lpuart0_receive_bytes] = ch_temp;
if(++lpuart0_receive_bytes >= lpuart0_receive_size)lpuart0_receive_bytes = 0;
#if 0
if (lpuart0_State.bitCountPerChar == LPUART_8_BITS_PER_CHAR) {
++lpuart0_State.rxBuff;
--lpuart0_State.rxSize;
}
lpuart0_State.isRxBusy = false;
lpuart0_State.receiveStatus = STATUS_SUCCESS;
LPUART_DRV_ReceiveData(INST_LPUART0, (uint8_t *)&lpuart0_receive_buf[lpuart0_receive_bytes], 1);
#endif
#if 1
LPUART_DRV_SendDataPolling(INST_LPUART0, &ch_temp, 1);
#endif
}
void LPUART1_Rx_Callback_IRQHandler(void *driverState, uart_event_t event, void *userData)
{
uint8_t ch_temp;
ch_temp = LPUART1->DATA;
lpuart1_receive_buf[lpuart1_receive_bytes] = ch_temp;
if(++lpuart1_receive_bytes >= lpuart1_receive_size)lpuart1_receive_bytes = 0;
#if 0
if (lpuart1_State.bitCountPerChar == LPUART_8_BITS_PER_CHAR) {
++lpuart1_State.rxBuff;
--lpuart1_State.rxSize;
}
lpuart1_State.isRxBusy = false;
lpuart1_State.receiveStatus = STATUS_SUCCESS;
LPUART_DRV_ReceiveData(INST_LPUART1, (uint8_t *)&lpuart1_receive_buf[lpuart1_receive_bytes], 1);
#endif
#if 1
LPUART_DRV_SendDataPolling(INST_LPUART1, &ch_temp, 1);
#endif
}
/*!
\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 */
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
LPUART_DRV_Init(INST_LPUART0, &lpuart0_State, &lpuart0_InitConfig0);
LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0);
/*** 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 */
/* For example: for(;;) { } */
LPUART_DRV_InstallRxCallback(INST_LPUART0, LPUART0_Rx_Callback_IRQHandler, (isr_t*)0);
LPUART_DRV_InstallRxCallback(INST_LPUART1, LPUART1_Rx_Callback_IRQHandler, (isr_t*)0);
/* lpuart0 lpuart1 Start receive for one char or more */
LPUART_DRV_ReceiveData(INST_LPUART0, (uint8_t *)lpuart0_receive_buf, 1);
LPUART_DRV_ReceiveData(INST_LPUART1, (uint8_t *)lpuart1_receive_buf, 1);
#if 1
/* Send a welcome message */
LPUART_DRV_SendData(INST_LPUART0, (uint8_t *)welcomeMsg0, strlen(welcomeMsg0));
/* Wait for transmission to be complete */
while(LPUART_DRV_GetTransmitStatus(INST_LPUART0, &bytesRemaining) != STATUS_SUCCESS);
/* Send a welcome message */
LPUART_DRV_SendData(INST_LPUART1, (uint8_t *)welcomeMsg1, strlen(welcomeMsg1));
/* Wait for transmission to be complete */
while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemaining) != STATUS_SUCCESS);
#endif
while(1){
}
/*** 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.
**
** ###################################################################
*/
|
|