serial.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. /*====================================================================*
  42. *
  43. * serial.h - Atheros Serial Line Definitions and declarations;
  44. *
  45. *. Qualcomm Atheros HomePlug AV Powerline Toolkit
  46. *: Copyright (c) 2009-2013 by Qualcomm Atheros Inc. ALL RIGHTS RESERVED;
  47. *; For demonstration and evaluation only; Not for production use.
  48. *
  49. * Contributor(s):
  50. * Charles Maier
  51. *
  52. *--------------------------------------------------------------------*/
  53. #ifndef SERIAL_HEADER
  54. #define SERIAL_HEADER
  55. /*====================================================================*
  56. * system header files;
  57. *--------------------------------------------------------------------*/
  58. #include <ctype.h>
  59. #ifndef WIN32
  60. #include <termios.h>
  61. #endif
  62. /*====================================================================*
  63. * custom header files;
  64. *--------------------------------------------------------------------*/
  65. #include "../tools/types.h"
  66. /*====================================================================*
  67. *
  68. *--------------------------------------------------------------------*/
  69. #if defined (WIN32)
  70. # define DEVICE "com1:"
  71. # define PAUSE(x) Sleep (x)
  72. #else
  73. # define DEVICE "/dev/ttyUSB0"
  74. # define PAUSE(x) usleep ((x)*1000)
  75. #endif
  76. /*====================================================================*
  77. *
  78. *--------------------------------------------------------------------*/
  79. #define UART_MODE 0
  80. #define UART_BAUDRATE 115200
  81. #define UART_DATABITS 8
  82. #define UART_STOPBITS 1
  83. #define UART_PARITY 0
  84. #define UART_FLOWCTRL 0
  85. #define UART_BUFFERSIZE 4096
  86. #define UART_BLOCKSIZE 512
  87. #define UART_PORT "PLCUART"
  88. /*====================================================================*
  89. * Atheros Serial Line Command flags;
  90. *--------------------------------------------------------------------*/
  91. #define UART_SILENCE (1 << 0)
  92. #define UART_VERBOSE (1 << 1)
  93. #define UART_DEFAULT (1 << 2)
  94. #define UART_COMMAND (1 << 3)
  95. #define UART_WAKE (1 << 4)
  96. #define UART_RESPOND (1 << 5)
  97. #define UART_ATRV (1 << 6)
  98. #define UART_ATRPM (1 << 7)
  99. #define UART_ATSK1 (1 << 8)
  100. #define UART_ATSK2 (1 << 9)
  101. #define UART_ATZ (1 << 10)
  102. #define UART_ATDST1 (1 << 11)
  103. #define UART_ATDST2 (1 << 12)
  104. #define UART_ATNI (1 << 13)
  105. #define UART_ATFD (1 << 14)
  106. #define UART_ATPS (1 << 15)
  107. #define UART_ATO (1 << 16)
  108. #define UART_ATHSC (1 << 17)
  109. #define UART_ATRP (1 << 18)
  110. #define UART_ATWPF1 (1 << 19)
  111. #define UART_ATWPF2 (1 << 20)
  112. #define UART_ATWNV (1 << 21)
  113. #define UART_ATBSZ1 (1 << 22)
  114. #define UART_ATBSZ2 (1 << 23)
  115. #define UART_ATTO (1 << 24)
  116. #define UART_ATBR (1 << 25)
  117. #define UART_ATM (1 << 26)
  118. /*====================================================================*
  119. *
  120. * struct command;
  121. *
  122. * structure containing serial command buffer and two pointers; the
  123. * buffer is used for both transmit and receive and shared by most
  124. * function below;
  125. *
  126. *--------------------------------------------------------------------*/
  127. typedef struct command
  128. {
  129. char buffer [UART_BUFFERSIZE];
  130. unsigned length;
  131. unsigned offset;
  132. }
  133. COMMAND;
  134. /*====================================================================*
  135. *
  136. *--------------------------------------------------------------------*/
  137. #ifndef WIN32
  138. signed baudrate (unsigned rate, speed_t * speed);
  139. #endif
  140. void openport (struct _file_ * port, flag_t mode);
  141. void closeport (struct _file_ * port);
  142. /*====================================================================*
  143. * serial command line buffer functions;
  144. *--------------------------------------------------------------------*/
  145. void clearcommand ();
  146. void sendcommand (struct _file_ * port, flag_t flags);
  147. void readcommand (struct _file_ * port, flag_t flags);
  148. void insert (char c);
  149. size_t readframe (signed fd, void * memory, size_t extent);
  150. void decode (void const * memory, size_t extent);
  151. void encode (void * memory, size_t extent);
  152. void string (char * string);
  153. uint64_t hextoint (unsigned bytes);
  154. void mustbe (char c);;
  155. /*====================================================================*
  156. *
  157. *--------------------------------------------------------------------*/
  158. #endif