romapi_uart.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * @brief UART ROM API declarations and functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2014
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #include "romapi_5410x.h"
  32. /* Get memory size in bytes needed for ADC driver context */
  33. uint32_t ROM_UART_GetMemSize(void)
  34. {
  35. #if defined(ROMDRIVERSV2_PRESENT)
  36. return ROMAPI_UART_API->GetMemSize();
  37. #else
  38. return uartrom_api.GetMemSize();
  39. #endif
  40. }
  41. /* Initialize the UART ROM driver */
  42. UART_HANDLE_T ROM_UART_Init(void *pMem, uint32_t baseAddr, void *pUserData)
  43. {
  44. #if defined(ROMDRIVERSV2_PRESENT)
  45. return ROMAPI_UART_API->Init(pMem, baseAddr, pUserData);
  46. #else
  47. return uartrom_api.Init(pMem, baseAddr, pUserData);
  48. #endif
  49. }
  50. /* Configure the UART peripheral */
  51. ErrorCode_t ROM_UART_Configure(UART_HANDLE_T hUART, const UART_CFG_T *pCfg)
  52. {
  53. #if defined(ROMDRIVERSV2_PRESENT)
  54. return ROMAPI_UART_API->Configure(hUART, pCfg);
  55. #else
  56. return uartrom_api.Configure(hUART, pCfg);
  57. #endif
  58. }
  59. /* Calculate baudrate dividers and oversampling values */
  60. ErrorCode_t ROM_UART_CalBaud(UART_BAUD_T *baud)
  61. {
  62. #if defined(ROMDRIVERSV2_PRESENT)
  63. return ROMAPI_UART_API->CalBaud(baud);
  64. #else
  65. return uartrom_api.CalBaud(baud);
  66. #endif
  67. }
  68. /* Set/Clear special control operations like BREAK, IDLE, etc., */
  69. void ROM_UART_SetCtrl(UART_HANDLE_T hUART, uint32_t cfgVal)
  70. {
  71. #if defined(ROMDRIVERSV2_PRESENT)
  72. ROMAPI_UART_API->SetCtrl(hUART, cfgVal);
  73. #else
  74. uartrom_api.SetCtrl(hUART, cfgVal);
  75. #endif
  76. }
  77. /* Registers an UART callback function */
  78. ErrorCode_t ROM_UART_RegisterCB(UART_HANDLE_T hUART, UART_CBINDEX_T cbIndex, void (*pCbFunc)(UART_HANDLE_T,
  79. UART_EVENT_T,
  80. void *))
  81. {
  82. #if defined(ROMDRIVERSV2_PRESENT)
  83. return ROMAPI_UART_API->RegisterCB(hUART, cbIndex, pCbFunc);
  84. #else
  85. return uartrom_api.RegisterCB(hUART, cbIndex, pCbFunc);
  86. #endif
  87. }
  88. /* UART Event handler, should be called from the ISR */
  89. void ROM_UART_Handler(UART_HANDLE_T hUART)
  90. {
  91. #if defined(ROMDRIVERSV2_PRESENT)
  92. ROMAPI_UART_API->Handler(hUART);
  93. #else
  94. uartrom_api.Handler(hUART);
  95. #endif
  96. }
  97. /* Send data to UART */
  98. ErrorCode_t ROM_UART_Send(UART_HANDLE_T hUART, const void *buffer, uint16_t size)
  99. {
  100. #if defined(ROMDRIVERSV2_PRESENT)
  101. return ROMAPI_UART_API->Send(hUART, buffer, size);
  102. #else
  103. return uartrom_api.Send(hUART, buffer, size);
  104. #endif
  105. }
  106. /* Receive data from UART */
  107. ErrorCode_t ROM_UART_Receive(UART_HANDLE_T hUART, void *buffer, uint16_t size)
  108. {
  109. #if defined(ROMDRIVERSV2_PRESENT)
  110. return ROMAPI_UART_API->Receive(hUART, buffer, size);
  111. #else
  112. return uartrom_api.Receive(hUART, buffer, size);
  113. #endif
  114. }
  115. /* Wait for UART TX to complete; Used for polling */
  116. void ROM_UART_WaitTx(UART_HANDLE_T hUART)
  117. {
  118. #if defined(ROMDRIVERSV2_PRESENT)
  119. ROMAPI_UART_API->WaitTx(hUART);
  120. #else
  121. uartrom_api.WaitTx(hUART);
  122. #endif
  123. }
  124. /* Wait for UART data receive to complete; Used for polling */
  125. void ROM_UART_WaitRx(UART_HANDLE_T hUART)
  126. {
  127. #if defined(ROMDRIVERSV2_PRESENT)
  128. ROMAPI_UART_API->WaitRx(hUART);
  129. #else
  130. uartrom_api.WaitRx(hUART);
  131. #endif
  132. }
  133. /* Get Current verion of the UART ROM driver */
  134. uint16_t ROM_UART_GetDriverVersion(void)
  135. {
  136. #if defined(ROMDRIVERSV2_PRESENT)
  137. return ROMAPI_UART_API->GetDriverVersion();
  138. #else
  139. return uartrom_api.GetDriverVersion();
  140. #endif
  141. }