ASCLIN模块

AscLin 这个词意思是 UART+SPI+LIN,这是三种在汽车里常用的(相对 CAN 简单的通信接口)简单接口。由于有一些可以复用的电路,AURIX 把这三种接口做成了一个模块,可以通过配置选择。
Asynchronous/Synchronous Interface (ASCLIN)
image.png
image.png

程序

  1. /*********************************************************************************************************************/
  2. /*-----------------------------------------------------Includes------------------------------------------------------*/
  3. /*********************************************************************************************************************/
  4. #include "IfxAsclin_Asc.h"
  5. #include "IfxCpu_Irq.h"
  6. #include "Ifx_Console.h"
  7. /*********************************************************************************************************************/
  8. /*------------------------------------------------------Macros-------------------------------------------------------*/
  9. /*********************************************************************************************************************/
  10. #define SERIAL_BAUDRATE 115200 /* Baud rate in bit/s */
  11. #define SERIAL_PIN_RX IfxAsclin0_RXA_P14_1_IN /* RX pin of the board */
  12. #define SERIAL_PIN_TX IfxAsclin0_TX_P14_0_OUT /* TX pin of the board */
  13. #define INTPRIO_ASCLIN0_TX 19 /* Priority of the ISR */
  14. #define INTPRIO_ASCLIN0_RX 14
  15. #define INTPRIO_ASCLIN0_ER 20
  16. #define ASC_TX_BUFFER_SIZE 64 /* Definition of the buffer size */
  17. #define ASC_RX_BUFFER_SIZE 64
  18. /*********************************************************************************************************************/
  19. /*-------------------------------------------------Global variables--------------------------------------------------*/
  20. /*********************************************************************************************************************/
  21. static IfxStdIf_DPipe stdio; //使用print必须加上
  22. IfxAsclin_Asc g_asc; /* Declaration of the ASC handle */
  23. uint8 g_ascTxBuffer[ASC_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
  24. uint8 g_ascRxBuffer[ASC_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];/* Declaration of the FIFOs parameters */
  25. /*********************************************************************************************************************/
  26. /*---------------------------------------------Function Implementations----------------------------------------------*/
  27. /*********************************************************************************************************************/
  28. IFX_INTERRUPT(asclin0_Tx_ISR, 0, INTPRIO_ASCLIN0_TX); /* Adding the Interrupt Service Routine */
  29. void asclin0_Tx_ISR(void)
  30. {
  31. IfxAsclin_Asc_isrTransmit(&g_asc);
  32. }
  33. void init_UART(void)
  34. {
  35. /* Initialize an instance of IfxAsclin_Asc_Config with default values */
  36. IfxAsclin_Asc_Config ascConfig;
  37. IfxAsclin_Asc_initModuleConfig(&ascConfig, &MODULE_ASCLIN0);//同时配置发送接收
  38. //IfxAsclin_Asc_initModuleConfig(&ascConfig, SERIAL_PIN_TX.module);//只配置了发送
  39. /* Set the desired baud rate设置波特率 */
  40. ascConfig.baudrate.baudrate = SERIAL_BAUDRATE;
  41. /* ISR priorities and interrupt target */
  42. ascConfig.interrupt.txPriority = INTPRIO_ASCLIN0_TX;
  43. ascConfig.interrupt.rxPriority = INTPRIO_ASCLIN0_RX;//加上接收的
  44. ascConfig.interrupt.erPriority = INTPRIO_ASCLIN0_ER;//错误
  45. ascConfig.interrupt.typeOfService = IfxCpu_Irq_getTos(IfxCpu_getCoreIndex());//使能,使用哪个CPU
  46. /* FIFO configuration缓冲区配置 */
  47. ascConfig.txBuffer = &g_ascTxBuffer;
  48. ascConfig.txBufferSize = ASC_TX_BUFFER_SIZE;
  49. ascConfig.rxBuffer = &g_ascRxBuffer;
  50. ascConfig.rxBufferSize = ASC_RX_BUFFER_SIZE;
  51. /* Port pins configuration 管脚配置*/
  52. const IfxAsclin_Asc_Pins pins =
  53. {
  54. NULL_PTR, IfxPort_InputMode_pullUp, /* CTS pin not used */
  55. &SERIAL_PIN_RX, IfxPort_InputMode_pullUp, /* RX pin not used */
  56. NULL_PTR, IfxPort_OutputMode_pushPull, /* RTS pin not used */
  57. &SERIAL_PIN_TX, IfxPort_OutputMode_pushPull, /* TX pin */
  58. IfxPort_PadDriver_cmosAutomotiveSpeed1
  59. };
  60. ascConfig.pins = &pins;
  61. //初始化串口模块 -> 初始化标准输入输出流 -> 初始化标准控制台
  62. IfxAsclin_Asc_initModule(&g_asc, &ascConfig); /* Initialize module with above parameters */
  63. IfxAsclin_Asc_stdIfDPipeInit(&stdio, &g_asc); //使用print必须加上
  64. Ifx_Console_init(&stdio);
  65. }
  66. void send_UART_message(void)
  67. {
  68. uint8 txData[] = "Hello World!"; /* Message to send */
  69. Ifx_SizeT count = 12; /* Size of the message */
  70. IfxAsclin_Asc_write(&g_asc, txData, &count, TIME_INFINITE); /* Transfer of data */
  71. }
  1. #include "Ifx_Types.h"
  2. #include "IfxCpu.h"
  3. #include "IfxScuWdt.h"
  4. #include "UART_VCOM.h"
  5. #include "Ifx_Console.h"//print用
  6. #include "Bsp.h"//延时用得上
  7. IfxCpu_syncEvent g_cpuSyncEvent = 0;
  8. uint32 i = 0;
  9. int core0_main(void)
  10. {
  11. IfxCpu_enableInterrupts();
  12. /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
  13. * Enable the watchdogs and service them periodically if it is required
  14. */
  15. IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
  16. IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
  17. /* Wait for CPU sync event */
  18. IfxCpu_emitEvent(&g_cpuSyncEvent);
  19. IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
  20. init_UART(); /* Initialize the module */
  21. send_UART_message(); /* Send the message "Hello World!" */
  22. while(1)
  23. {
  24. Ifx_Console_print("Hello, world!(%d)\n", i++);//尝试使用Ifx_Console_print的函数,类似于printf
  25. waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 500));
  26. }
  27. return (1);
  28. }

测试结果

image.png