ASCLIN模块
AscLin 这个词意思是 UART+SPI+LIN,这是三种在汽车里常用的(相对 CAN 简单的通信接口)简单接口。由于有一些可以复用的电路,AURIX 把这三种接口做成了一个模块,可以通过配置选择。
Asynchronous/Synchronous Interface (ASCLIN)
程序
/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "IfxAsclin_Asc.h"
#include "IfxCpu_Irq.h"
#include "Ifx_Console.h"
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
#define SERIAL_BAUDRATE 115200 /* Baud rate in bit/s */
#define SERIAL_PIN_RX IfxAsclin0_RXA_P14_1_IN /* RX pin of the board */
#define SERIAL_PIN_TX IfxAsclin0_TX_P14_0_OUT /* TX pin of the board */
#define INTPRIO_ASCLIN0_TX 19 /* Priority of the ISR */
#define INTPRIO_ASCLIN0_RX 14
#define INTPRIO_ASCLIN0_ER 20
#define ASC_TX_BUFFER_SIZE 64 /* Definition of the buffer size */
#define ASC_RX_BUFFER_SIZE 64
/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
static IfxStdIf_DPipe stdio; //使用print必须加上
IfxAsclin_Asc g_asc; /* Declaration of the ASC handle */
uint8 g_ascTxBuffer[ASC_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
uint8 g_ascRxBuffer[ASC_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];/* Declaration of the FIFOs parameters */
/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
IFX_INTERRUPT(asclin0_Tx_ISR, 0, INTPRIO_ASCLIN0_TX); /* Adding the Interrupt Service Routine */
void asclin0_Tx_ISR(void)
{
IfxAsclin_Asc_isrTransmit(&g_asc);
}
void init_UART(void)
{
/* Initialize an instance of IfxAsclin_Asc_Config with default values */
IfxAsclin_Asc_Config ascConfig;
IfxAsclin_Asc_initModuleConfig(&ascConfig, &MODULE_ASCLIN0);//同时配置发送接收
//IfxAsclin_Asc_initModuleConfig(&ascConfig, SERIAL_PIN_TX.module);//只配置了发送
/* Set the desired baud rate设置波特率 */
ascConfig.baudrate.baudrate = SERIAL_BAUDRATE;
/* ISR priorities and interrupt target */
ascConfig.interrupt.txPriority = INTPRIO_ASCLIN0_TX;
ascConfig.interrupt.rxPriority = INTPRIO_ASCLIN0_RX;//加上接收的
ascConfig.interrupt.erPriority = INTPRIO_ASCLIN0_ER;//错误
ascConfig.interrupt.typeOfService = IfxCpu_Irq_getTos(IfxCpu_getCoreIndex());//使能,使用哪个CPU
/* FIFO configuration缓冲区配置 */
ascConfig.txBuffer = &g_ascTxBuffer;
ascConfig.txBufferSize = ASC_TX_BUFFER_SIZE;
ascConfig.rxBuffer = &g_ascRxBuffer;
ascConfig.rxBufferSize = ASC_RX_BUFFER_SIZE;
/* Port pins configuration 管脚配置*/
const IfxAsclin_Asc_Pins pins =
{
NULL_PTR, IfxPort_InputMode_pullUp, /* CTS pin not used */
&SERIAL_PIN_RX, IfxPort_InputMode_pullUp, /* RX pin not used */
NULL_PTR, IfxPort_OutputMode_pushPull, /* RTS pin not used */
&SERIAL_PIN_TX, IfxPort_OutputMode_pushPull, /* TX pin */
IfxPort_PadDriver_cmosAutomotiveSpeed1
};
ascConfig.pins = &pins;
//初始化串口模块 -> 初始化标准输入输出流 -> 初始化标准控制台
IfxAsclin_Asc_initModule(&g_asc, &ascConfig); /* Initialize module with above parameters */
IfxAsclin_Asc_stdIfDPipeInit(&stdio, &g_asc); //使用print必须加上
Ifx_Console_init(&stdio);
}
void send_UART_message(void)
{
uint8 txData[] = "Hello World!"; /* Message to send */
Ifx_SizeT count = 12; /* Size of the message */
IfxAsclin_Asc_write(&g_asc, txData, &count, TIME_INFINITE); /* Transfer of data */
}
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "UART_VCOM.h"
#include "Ifx_Console.h"//print用
#include "Bsp.h"//延时用得上
IfxCpu_syncEvent g_cpuSyncEvent = 0;
uint32 i = 0;
int core0_main(void)
{
IfxCpu_enableInterrupts();
/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
init_UART(); /* Initialize the module */
send_UART_message(); /* Send the message "Hello World!" */
while(1)
{
Ifx_Console_print("Hello, world!(%d)\n", i++);//尝试使用Ifx_Console_print的函数,类似于printf
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 500));
}
return (1);
}