Cpu0_Main.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* Cpu0_Main.c
  2. *
  3. * Copyright (C) 2006-2024 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. IfxCpu_Irq_installInterruptHandler(asclin0_Tx_ISR, INTPRIO_ASCLIN0_TX);
  74. /* Port pins configuration */
  75. const IfxAsclin_Asc_Pins pins = {
  76. NULL_PTR, IfxPort_InputMode_pullUp, /* CTS pin not used */
  77. &SERIAL_PIN_RX, IfxPort_InputMode_pullUp, /* RX pin */
  78. NULL_PTR, IfxPort_OutputMode_pushPull, /* RTS pin not used */
  79. &SERIAL_PIN_TX, IfxPort_OutputMode_pushPull, /* TX pin */
  80. IfxPort_PadDriver_cmosAutomotiveSpeed1
  81. };
  82. /* Initialize an instance of IfxAsclin_Asc_Config with default values */
  83. IfxAsclin_Asc_initModuleConfig(&ascConfig, SERIAL_PIN_TX.module);
  84. /* Set the desired baud rate */
  85. ascConfig.baudrate.baudrate = SERIAL_BAUDRATE;
  86. /* ISR priorities and interrupt target */
  87. ascConfig.interrupt.txPriority = INTPRIO_ASCLIN0_TX;
  88. ascConfig.interrupt.typeOfService = IfxCpu_Irq_getTos(IfxCpu_getCoreIndex());
  89. /* FIFO configuration */
  90. ascConfig.txBuffer = &g_ascTxBuffer;
  91. ascConfig.txBufferSize = ASC_TX_BUFFER_SIZE;
  92. ascConfig.pins = &pins;
  93. /* Initialize module with above parameters */
  94. IfxAsclin_Asc_initModule(&g_asc, &ascConfig);
  95. /* Turn off buffers, so I/O occurs immediately */
  96. setvbuf(stdin, NULL, _IONBF, 0);
  97. setvbuf(stdout, NULL, _IONBF, 0);
  98. setvbuf(stderr, NULL, _IONBF, 0);
  99. }
  100. int send_UART(const char* str)
  101. {
  102. Ifx_SizeT count = (Ifx_SizeT)strlen(str);
  103. IfxAsclin_Asc_write(&g_asc, str, &count, TIME_INFINITE);
  104. return (int)count;
  105. }
  106. void core0_main(void)
  107. {
  108. IfxCpu_enableInterrupts();
  109. /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
  110. * Enable the watchdogs and service them periodically if it is required
  111. */
  112. IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
  113. IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
  114. /* Wait for CPU sync event */
  115. IfxCpu_emitEvent(&g_cpuSyncEvent);
  116. IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
  117. /* Initialize the UART to board VCOM */
  118. init_UART();
  119. /* bare metal loop */
  120. while(1)
  121. {
  122. extern void run_wolf_tests(void);
  123. run_wolf_tests();
  124. /* wait 5 seconds */
  125. waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 5 * 1000));
  126. } /* while */
  127. }