2
0

Cpu0_Main.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* Cpu0_Main.c
  2. *
  3. * Copyright (C) 2006-2022 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* Infineon includes */
  22. #include "Ifx_Types.h"
  23. #include "IfxCpu.h"
  24. #include "IfxScuWdt.h"
  25. #include "IfxAsclin_Asc.h"
  26. #include "IfxCpu_Irq.h"
  27. #include "IfxPort.h"
  28. #include "SysSe/Bsp/Bsp.h"
  29. /* For mapping stdio printf */
  30. #include <stdio.h>
  31. #include <string.h>
  32. /* used to wait for CPU sync event */
  33. IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
  34. #define SERIAL_BAUDRATE 115200 /* Baud rate in bit/s */
  35. #define SERIAL_PIN_RX IfxAsclin0_RXA_P14_1_IN /* RX pin of the board */
  36. #define SERIAL_PIN_TX IfxAsclin0_TX_P14_0_OUT /* TX pin of the board */
  37. #define INTPRIO_ASCLIN0_TX 19 /* Priority of the ISR */
  38. #define ASC_TX_BUFFER_SIZE 128 /* Definition of the buffer size */
  39. /* Declaration of the ASC handle */
  40. static IfxAsclin_Asc g_asc;
  41. /* Declaration of the FIFOs parameters:
  42. * The transfer buffers allocate memory for the data itself and for FIFO runtime
  43. * variables. 8 more bytes have to be added to ensure a proper circular buffer
  44. * handling independent from the address to which the buffers have been located.
  45. */
  46. static uint8 g_ascTxBuffer[ASC_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
  47. /******************************************************************************/
  48. /*----Function Implementations------------------------------------------------*/
  49. /******************************************************************************/
  50. /* Re-target the C library printf function to the asc lin. */
  51. int fputc(int ch, FILE *f)
  52. {
  53. Ifx_SizeT count;
  54. /* convert to CRLF */
  55. if (ch == (int)'\n') {
  56. int chcr = (int)'\r';
  57. count = 1;
  58. IfxAsclin_Asc_write(&g_asc, &chcr, &count, TIME_INFINITE);
  59. }
  60. count = 1;
  61. IfxAsclin_Asc_write(&g_asc, &ch, &count, TIME_INFINITE);
  62. return ch;
  63. }
  64. /* Add the Interrupt Service Routine */
  65. IFX_INTERRUPT(asclin0_Tx_ISR, 0, INTPRIO_ASCLIN0_TX);
  66. void asclin0_Tx_ISR(void)
  67. {
  68. IfxAsclin_Asc_isrTransmit(&g_asc);
  69. }
  70. static void init_UART(void)
  71. {
  72. IfxAsclin_Asc_Config ascConfig;
  73. /* Port pins configuration */
  74. const IfxAsclin_Asc_Pins pins = {
  75. NULL_PTR, IfxPort_InputMode_pullUp, /* CTS pin not used */
  76. &SERIAL_PIN_RX, IfxPort_InputMode_pullUp, /* RX pin */
  77. NULL_PTR, IfxPort_OutputMode_pushPull, /* RTS pin not used */
  78. &SERIAL_PIN_TX, IfxPort_OutputMode_pushPull, /* TX pin */
  79. IfxPort_PadDriver_cmosAutomotiveSpeed1
  80. };
  81. /* Initialize an instance of IfxAsclin_Asc_Config with default values */
  82. IfxAsclin_Asc_initModuleConfig(&ascConfig, SERIAL_PIN_TX.module);
  83. /* Set the desired baud rate */
  84. ascConfig.baudrate.baudrate = SERIAL_BAUDRATE;
  85. /* ISR priorities and interrupt target */
  86. ascConfig.interrupt.txPriority = INTPRIO_ASCLIN0_TX;
  87. ascConfig.interrupt.typeOfService = IfxCpu_Irq_getTos(IfxCpu_getCoreIndex());
  88. /* FIFO configuration */
  89. ascConfig.txBuffer = &g_ascTxBuffer;
  90. ascConfig.txBufferSize = ASC_TX_BUFFER_SIZE;
  91. ascConfig.pins = &pins;
  92. /* Initialize module with above parameters */
  93. IfxAsclin_Asc_initModule(&g_asc, &ascConfig);
  94. /* Turn off buffers, so I/O occurs immediately */
  95. setvbuf(stdin, NULL, _IONBF, 0);
  96. setvbuf(stdout, NULL, _IONBF, 0);
  97. setvbuf(stderr, NULL, _IONBF, 0);
  98. }
  99. int send_UART(const char* str)
  100. {
  101. Ifx_SizeT count = (Ifx_SizeT)strlen(str);
  102. IfxAsclin_Asc_write(&g_asc, str, &count, TIME_INFINITE);
  103. return (int)count;
  104. }
  105. void core0_main(void)
  106. {
  107. IfxCpu_enableInterrupts();
  108. /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
  109. * Enable the watchdogs and service them periodically if it is required
  110. */
  111. IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
  112. IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
  113. /* Wait for CPU sync event */
  114. IfxCpu_emitEvent(&g_cpuSyncEvent);
  115. IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
  116. /* Initialize the UART to board VCOM */
  117. init_UART();
  118. /* bare metal loop */
  119. while(1)
  120. {
  121. extern void run_wolf_tests(void);
  122. run_wolf_tests();
  123. /* wait 5 seconds */
  124. waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 5 * 1000));
  125. } /* while */
  126. }