You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

378 lines
10 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * linux/<file location within the kernel tree>
  3. *
  4. * Copyright (C) 2010 Texas Instruments Incorporated
  5. * Author: Ganeshan N
  6. *
  7. * Based on <Give reference of old kernel file from which this file is derived from>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation version 2.
  12. *
  13. * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
  14. * whether express or implied; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. */
  18. #ifndef _SUART_API_H_
  19. #define _SUART_API_H_
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /*
  24. *====================
  25. * Includes
  26. *====================
  27. */
  28. #include "tistdtypes.h"
  29. #include "pru.h"
  30. /*
  31. *====================
  32. * Defines
  33. *====================
  34. */
  35. /* Retrun Values */
  36. #ifndef BIT
  37. #define BIT(x) (1 << x)
  38. #endif
  39. #define SUART_NUM_OF_CHANNELS_PER_SUART 2
  40. #define SUART_NUM_OF_BYTES_PER_CHANNEL 16
  41. #define SUART_PASS 0
  42. #define SUART_SUCCESS 0
  43. #define SUART_FAIL 1
  44. #define SUART_FALSE 0
  45. #define SUART_TRUE 1
  46. #define PRU_TX_INTR 1
  47. #define PRU_RX_INTR 2
  48. #define CHN_TXRX_STATUS_TIMEOUT BIT(6)
  49. #define CHN_TXRX_STATUS_BI BIT(5)
  50. #define CHN_TXRX_STATUS_FE BIT(4)
  51. #define CHN_TXRX_STATUS_UNERR BIT(3)
  52. #define CHN_TXRX_STATUS_OVRNERR BIT(3) /* UNERR->TX & OVRNERR->RX */
  53. #define CHN_TXRX_STATUS_ERR BIT(2)
  54. #define CHN_TXRX_STATUS_CMPLT BIT(1)
  55. #define CHN_TXRX_STATUS_RDY BIT(0)
  56. #define CHN_TXRX_IE_MASK_TIMEOUT BIT(14)
  57. #define CHN_TXRX_IE_MASK_BI BIT(13)
  58. #define CHN_TXRX_IE_MASK_FE BIT(12)
  59. #define CHN_TXRX_IE_MASK_CMPLT BIT(1)
  60. #define SUART_GBL_INTR_ERR_MASK BIT(9)
  61. #define SUART_PRU_ID_MASK 0xFF
  62. #define SUART_FIFO_LEN 15
  63. #define SUART_8X_OVRSMPL 1
  64. #define SUART_16X_OVRSMPL 2
  65. #define SUART_DEFAULT_OVRSMPL SUART_8X_OVRSMPL
  66. #if (SUART_DEFAULT_OVRSMPL == SUART_16X_OVRSMPL)
  67. #define SUART_DEFAULT_BAUD 57600
  68. #else
  69. #define SUART_DEFAULT_BAUD 115200
  70. #endif
  71. #define PRU_SUART_UART1 (1u)
  72. /** UART instance */
  73. #define PRU_SUART_UART2 (2u)
  74. /** UART instance */
  75. #define PRU_SUART_UART3 (3u)
  76. /** UART instance */
  77. #define PRU_SUART_UART4 (4u)
  78. /** UART instance */
  79. #define PRU_SUART_UART5 (5u)
  80. /** UART instance */
  81. #define PRU_SUART_UART6 (6u)
  82. /** UART instance */
  83. #define PRU_SUART_UART7 (7u)
  84. /** UART instance */
  85. #define PRU_SUART_UART8 (8u)
  86. /** UART instance */
  87. #define PRU_SUART_UARTx_INVALID (9u)
  88. /** UART instance */
  89. /*
  90. *====================
  91. * Enumerations
  92. *====================
  93. */
  94. /**
  95. * \brief One line description of the enum
  96. *
  97. * Detailed description of the enum
  98. */
  99. typedef enum {
  100. ePRU_SUART_DATA_BITS6 = 8,
  101. /**< 6 + 2 */
  102. ePRU_SUART_DATA_BITS7,
  103. /**< member2 description */
  104. ePRU_SUART_DATA_BITS8,
  105. /**< member1 description */
  106. ePRU_SUART_DATA_BITS9,
  107. /**< member2 description */
  108. ePRU_SUART_DATA_BITS10,
  109. /**< member1 description */
  110. ePRU_SUART_DATA_BITS11,
  111. /**< member1 description */
  112. ePRU_SUART_DATA_BITS12
  113. /**< member1 description */
  114. } SUART_EN_BITSPERCHAR;
  115. /**
  116. * \brief One line description of the enum
  117. *
  118. * Detailed description of the enum
  119. */
  120. typedef enum {
  121. ePRU_SUART_NUM_1 = 1,
  122. /**< member1 description */
  123. ePRU_SUART_NUM_2,
  124. /**< member1 description */
  125. ePRU_SUART_NUM_3,
  126. /**< member1 description */
  127. ePRU_SUART_NUM_4,
  128. /**< member1 description */
  129. ePRU_SUART_NUM_5,
  130. /**< member1 description */
  131. ePRU_SUART_NUM_6,
  132. /**< member1 description */
  133. ePRU_SUART_NUM_7,
  134. /**< member1 description */
  135. ePRU_SUART_NUM_8
  136. /**< member1 description */
  137. } SUART_EN_UARTNUM;
  138. /**
  139. * \brief One line description of the enum
  140. *
  141. * Detailed description of the enum
  142. */
  143. typedef enum {
  144. ePRU_SUART_HALF_TX = 1,
  145. ePRU_SUART_HALF_RX,
  146. ePRU_SUART_FULL_TX_RX
  147. } SUART_EN_UARTTYPE;
  148. /**
  149. * \brief One line description of the enum
  150. *
  151. * Detailed description of the enum
  152. */
  153. typedef enum {
  154. ePRU_SUART_TX_CH0 = 0,
  155. /**< member1 description */
  156. ePRU_SUART_TX_CH1,
  157. /**< member1 description */
  158. ePRU_SUART_TX_CH2,
  159. /**< member1 description */
  160. ePRU_SUART_TX_CH3,
  161. /**< member1 description */
  162. ePRU_SUART_TX_CH4,
  163. /**< member1 description */
  164. ePRU_SUART_TX_CH5,
  165. /**< member1 description */
  166. ePRU_SUART_TX_CH6,
  167. /**< member1 description */
  168. ePRU_SUART_TX_CH7
  169. /**< member1 description */
  170. } SUART_EN_TXCHANNEL;
  171. /**
  172. * \brief One line description of the enum
  173. *
  174. * Detailed description of the enum
  175. */
  176. typedef enum {
  177. ePRU_SUART_RX_CH0 = 0,
  178. /**< member1 description */
  179. ePRU_SUART_RX_CH1,
  180. /**< member1 description */
  181. ePRU_SUART_RX_CH2,
  182. /**< member1 description */
  183. ePRU_SUART_RX_CH3,
  184. /**< member1 description */
  185. ePRU_SUART_RX_CH4,
  186. /**< member1 description */
  187. ePRU_SUART_RX_CH5,
  188. /**< member1 description */
  189. ePRU_SUART_RX_CH6,
  190. /**< member1 description */
  191. ePRU_SUART_RX_CH7
  192. /**< member1 description */
  193. } SUART_EN_RXCHANNEL;
  194. /**
  195. * \brief One line description of the enum
  196. *
  197. * Detailed description of the enum
  198. */
  199. typedef enum {
  200. ePRU_SUART_UART_FREE = 0,
  201. /**< member1 description */
  202. ePRU_SUART_UART_IN_USE
  203. /**< member1 description */
  204. } SUART_EN_UART_STATUS;
  205. /*
  206. *====================
  207. * Structures
  208. *====================
  209. */
  210. #define PRU_NUM_OF_CHANNELS 16
  211. typedef struct {
  212. unsigned short CH_Ctrl;
  213. /**< PRU SUART control register */
  214. unsigned short CH_Config1;
  215. /**< PRU SUART configuration1 register */
  216. unsigned short CH_Config2;
  217. /**< PRU SUART configuration2 register */
  218. unsigned short CH_TXRXStatus;
  219. /**< PRU SUART TX/RX status register */
  220. unsigned int CH_TXRXData;
  221. /**< PRU SUART TX/RX data register */
  222. unsigned int Reserved1;
  223. /**< Reserved 1 */
  224. } pru_suart_regs[PRU_NUM_OF_CHANNELS];
  225. typedef volatile pru_suart_regs *PRU_SUART_RegsOvly;
  226. /**
  227. * \brief One line description of the structure
  228. *
  229. * Detailed description of the structure
  230. */
  231. typedef struct {
  232. unsigned char TXSerializer;
  233. /**< It takes the value of the serializer. It takes the value 0-15 range */
  234. unsigned char RXSerializer;
  235. /**< It takes the value of the serializer. It takes the value 0-15 range */
  236. unsigned short txClkDivisor; /**< Divisor (CLKXDIV* HCLKXDIV) value to generate the appropriate baud rate */
  237. unsigned short rxClkDivisor; /**< Divisor (CLKXDIV* HCLKXDIV) value to generate the appropriate baud rate */
  238. unsigned char txBitsPerChar; /**< Bits per Character (Range: 6 to 12) */
  239. unsigned char rxBitsPerChar; /**< Bits per Character (Range: 6 to 12) */
  240. unsigned char Oversampling; /**< Oversampling rate */
  241. unsigned char BIIntrMask; /**< Break Indicator Interrupt Mask Bit */
  242. unsigned char FEIntrMask; /**< Framing Error Interrupt Mask Bit */
  243. } suart_config;
  244. /**
  245. * \brief One line description of the structure
  246. *
  247. * Detailed description of the structure
  248. */
  249. typedef struct {
  250. unsigned short uartNum;/**< UART number (Range 1 to 16) */
  251. unsigned short uartType;
  252. /**< Type of the UART i.e., Full UART, Half UART */
  253. unsigned short uartTxChannel;
  254. /**< Soft UART Channel for Transmission */
  255. unsigned short uartRxChannel;
  256. /**< Soft UART Channel for Reception */
  257. unsigned short uartStatus;
  258. /**< Status of the UART */
  259. } suart_struct_handle;
  260. typedef suart_struct_handle *suart_handle;
  261. /*
  262. *====================
  263. * API declarations
  264. *====================
  265. */
  266. short pru_softuart_init(unsigned int txBaudValue,
  267. unsigned int rxBaudValue,
  268. unsigned int oversampling,
  269. unsigned char *pru_suart_emu_code,
  270. unsigned int fw_size,
  271. arm_pru_iomap * pru_arm_iomap1);
  272. int pru_intr_set_mask(unsigned short uartNum,
  273. unsigned int txrxmode, unsigned int intrmask);
  274. short pru_softuart_reset(unsigned int txBaudValue,
  275. unsigned int rxBaudValue,
  276. unsigned int oversampling);
  277. short pru_softuart_open(suart_handle hSuart);
  278. short pru_softuart_close(suart_handle hUart);
  279. short pru_softuart_setbaud
  280. (suart_handle hUart,
  281. unsigned short txClkDivisor, unsigned short rxClkDivisor);
  282. short pru_softuart_setdatabits
  283. (suart_handle hUart,
  284. unsigned short txDataBits, unsigned short rxDataBits);
  285. short pru_softuart_setconfig
  286. (suart_handle hUart, suart_config * configUart);
  287. short pru_softuart_getconfig
  288. (suart_handle hUart, suart_config * configUart);
  289. short pru_softuart_write
  290. (suart_handle hUart,
  291. unsigned int *ptTxDataBuf, unsigned short dataLen);
  292. short pru_softuart_read
  293. (suart_handle hUart,
  294. unsigned int *ptDataBuf, unsigned short dataLen);
  295. int suart_intr_clrmask(unsigned short uartNum,
  296. unsigned int txrxmode, unsigned int intrmask);
  297. short pru_softuart_clrTxStatus(suart_handle hUart);
  298. short pru_softuart_getTxStatus(suart_handle hUart);
  299. short pru_softuart_clrRxStatus(suart_handle hUart);
  300. short pru_softuart_getRxStatus(suart_handle hUart);
  301. short pru_softuart_get_isrstatus(unsigned short uartNum,
  302. unsigned short *txrxFlag);
  303. int pru_intr_clr_isrstatus(unsigned short uartNum, unsigned int txrxmode);
  304. int suart_intr_getmask(unsigned short uartNum,
  305. unsigned int txrxmode, unsigned int intrmask);
  306. int suart_intr_setmask(unsigned short uartNum,
  307. unsigned int txrxmode, unsigned int intrmask);
  308. short pru_softuart_getTxDataLen(suart_handle hUart);
  309. short pru_softuart_getRxDataLen(suart_handle hUart);
  310. short suart_arm_to_pru_intr(unsigned short uartNum);
  311. short arm_to_pru_intr_init(void);
  312. short pru_softuart_deinit(void);
  313. short pru_softuart_clrRxFifo(suart_handle hUart);
  314. short pru_softuart_read_data (suart_handle hUart, Uint8 * pDataBuffer,
  315. Int32 s32MaxLen, Uint32 * pu32DataRead);
  316. short pru_softuart_stopReceive (suart_handle hUart);
  317. int suart_pru_to_host_intr_enable (unsigned short uartNum,
  318. unsigned int txrxmode, int s32Flag);
  319. void pru_set_fifo_timeout(Uint32 timeout);
  320. #ifdef __cplusplus
  321. } /* End of extern C */
  322. #endif /* #ifdef __cplusplus */
  323. #endif