portserial.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * FreeModbus Libary: BARE Port
  3. * Copyright (C) 2006 Christian Walter <wolti@sil.at>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. * File: $Id$
  20. */
  21. #include "port.h"
  22. #include "stm32f10x.h"
  23. /* ----------------------- Modbus includes ----------------------------------*/
  24. #include "mb.h"
  25. #include "mbport.h"
  26. /* ----------------------- static functions ---------------------------------*/
  27. void prvvUARTTxReadyISR( void );
  28. void prvvUARTRxISR( void );
  29. /* ----------------------- Start implementation -----------------------------*/
  30. void
  31. vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )
  32. {
  33. /* If xRXEnable enable serial receive interrupts. If xTxENable enable
  34. * transmitter empty interrupts.
  35. */
  36. if (xRxEnable)
  37. {
  38. USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
  39. for (uint32_t i = 0; i < 20000; i++) ;
  40. GPIO_ResetBits(GPIOC, GPIO_Pin_14);
  41. }
  42. else
  43. {
  44. USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
  45. GPIO_SetBits(GPIOC, GPIO_Pin_14);
  46. }
  47. if (xTxEnable)
  48. {
  49. USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
  50. }
  51. else
  52. {
  53. USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
  54. }
  55. }
  56. BOOL
  57. xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
  58. {
  59. return TRUE;
  60. }
  61. BOOL
  62. xMBPortSerialPutByte( CHAR ucByte )
  63. {
  64. /* Put a byte in the UARTs transmit buffer. This function is called
  65. * by the protocol stack if pxMBFrameCBTransmitterEmpty( ) has been
  66. * called. */
  67. USART_SendData(USART2, ucByte);
  68. return TRUE;
  69. }
  70. BOOL
  71. xMBPortSerialGetByte( CHAR * pucByte )
  72. {
  73. /* Return the byte in the UARTs receive buffer. This function is called
  74. * by the protocol stack after pxMBFrameCBByteReceived( ) has been called.
  75. */
  76. *pucByte = USART_ReceiveData(USART2);
  77. return TRUE;
  78. }
  79. /* Create an interrupt handler for the transmit buffer empty interrupt
  80. * (or an equivalent) for your target processor. This function should then
  81. * call pxMBFrameCBTransmitterEmpty( ) which tells the protocol stack that
  82. * a new character can be sent. The protocol stack will then call
  83. * xMBPortSerialPutByte( ) to send the character.
  84. */
  85. void prvvUARTTxReadyISR( void )
  86. {
  87. pxMBFrameCBTransmitterEmpty( );
  88. }
  89. /* Create an interrupt handler for the receive interrupt for your target
  90. * processor. This function should then call pxMBFrameCBByteReceived( ). The
  91. * protocol stack will then call xMBPortSerialGetByte( ) to retrieve the
  92. * character.
  93. */
  94. void prvvUARTRxISR( void )
  95. {
  96. pxMBFrameCBByteReceived( );
  97. }