lowlvl.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /***********************************************************************************************************************
  2. * DISCLAIMER
  3. * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No
  4. * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
  5. * applicable laws, including copyright laws.
  6. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
  7. * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
  8. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM
  9. * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES
  10. * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS
  11. * SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  12. * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
  13. * this software. By using this software, you agree to the additional terms and conditions found by accessing the
  14. * following link:
  15. * http://www.renesas.com/disclaimer
  16. *
  17. * Copyright (C) 2013 Renesas Electronics Corporation. All rights reserved.
  18. ***********************************************************************************************************************/
  19. /***********************************************************************************************************************
  20. * File Name : lowlvl.c
  21. * Description : Functions to support stream I/O to the E1 virtual Console
  22. ***********************************************************************************************************************/
  23. /***********************************************************************************************************************
  24. * History : DD.MM.YYYY Version Description
  25. * : 26.10.2011 1.00 First Release
  26. * : 13.04.2016 1.01 Added the redirect processing of charget() and charput() functions.
  27. * : 15.05.2017 2.00 Added the bsp startup module disable function.
  28. * :(01.11.2017 2.00 Added the bsp startup module disable function.)
  29. * : 27.07.2018 2.01 Added the comment to while statement.
  30. ***********************************************************************************************************************/
  31. /***********************************************************************************************************************
  32. Includes <System Includes> , "Project Includes"
  33. ***********************************************************************************************************************/
  34. /* r_bsp access. */
  35. #include "platform.h"
  36. /* When using the user startup program, disable the following code. */
  37. #if (BSP_CFG_STARTUP_DISABLE == 0)
  38. #if BSP_CFG_USER_CHARPUT_ENABLED != 0
  39. /* If user has indicated they want to provide their own charput function then this is the prototype. */
  40. void BSP_CFG_USER_CHARPUT_FUNCTION(uint32_t output_char);
  41. #endif
  42. #if BSP_CFG_USER_CHARGET_ENABLED != 0
  43. /* If user has indicated they want to provide their own charget function then this is the prototype. */
  44. uint32_t BSP_CFG_USER_CHARGET_FUNCTION(void);
  45. #endif
  46. /***********************************************************************************************************************
  47. Macro definitions
  48. ***********************************************************************************************************************/
  49. #define E1_DBG_PORT (*(volatile struct st_dbg __evenaccess *)0x84080)
  50. #define TXFL0EN 0x00000100 // debug tx flow control bit
  51. #define RXFL0EN 0x00001000 // debug RX flow control bit
  52. /***********************************************************************************************************************
  53. Typedef definitions
  54. ***********************************************************************************************************************/
  55. struct st_dbg
  56. {
  57. uint32_t TX_DATA; // Debug Virtual Console TX data
  58. char wk1[12]; // spacer
  59. uint32_t RX_DATA; // Debug Virtual Console RX data
  60. char wk2[44]; // spacer
  61. uint32_t DBGSTAT; // Debug Virtual Console Status
  62. };
  63. /***********************************************************************************************************************
  64. Exported global variables (to be accessed by other files)
  65. ***********************************************************************************************************************/
  66. /***********************************************************************************************************************
  67. Private global variables and functions
  68. ***********************************************************************************************************************/
  69. /***********************************************************************************************************************
  70. * Function Name: charput
  71. * Description : Outputs a character on a serial port
  72. * Arguments : character to output
  73. * Return Value : none
  74. ***********************************************************************************************************************/
  75. void charput (uint32_t output_char)
  76. {
  77. /* If user has provided their own charput() function, then call it. */
  78. #if BSP_CFG_USER_CHARPUT_ENABLED == 1
  79. BSP_CFG_USER_CHARPUT_FUNCTION(output_char);
  80. #else
  81. /* Wait for transmit buffer to be empty */
  82. /* WAIT_LOOP */
  83. while(0 != (E1_DBG_PORT.DBGSTAT & TXFL0EN));
  84. /* Write the character out */
  85. E1_DBG_PORT.TX_DATA = output_char;
  86. #endif
  87. }
  88. /***********************************************************************************************************************
  89. * Function Name: charget
  90. * Description : Gets a character on a serial port
  91. * Arguments : none
  92. * Return Value : received character
  93. ***********************************************************************************************************************/
  94. uint32_t charget (void)
  95. {
  96. /* If user has provided their own charget() function, then call it. */
  97. #if BSP_CFG_USER_CHARGET_ENABLED == 1
  98. return BSP_CFG_USER_CHARGET_FUNCTION();
  99. #else
  100. /* Wait for rx buffer buffer to be ready */
  101. /* WAIT_LOOP */
  102. while(0 == (E1_DBG_PORT.DBGSTAT & RXFL0EN));
  103. /* Read data, send back up */
  104. return E1_DBG_PORT.RX_DATA;
  105. #endif
  106. }
  107. #endif /* BSP_CFG_STARTUP_DISABLE == 0 */