LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
suart_api.h
Go to the documentation of this file.
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 
19 #ifndef _SUART_API_H_
20 #define _SUART_API_H_
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /*
27  *====================
28  * Includes
29  *====================
30  */
31 #include "tistdtypes.h"
32 #include "pru.h"
33 /*
34  *====================
35  * Defines
36  *====================
37  */
38  /* Retrun Values */
39 #ifndef BIT
40 #define BIT(x) (1 << x)
41 #endif
42 
43 #define SINGLE_PRU 0
44 #define BOTH_PRU 1
45 #define PRU_ACTIVE SINGLE_PRU //BOTH_PRU
46 
47 #define SUART_NUM_OF_CHANNELS_PER_SUART 2
48 #define SUART_NUM_OF_BYTES_PER_CHANNEL 16
49 
50 #define SUART_PASS 0
51 #define SUART_SUCCESS 0
52 #define SUART_FAIL 1
53 
54 #define SUART_FALSE 0
55 #define SUART_TRUE 1
56 
57 #define PRU_TX_INTR 1
58 #define PRU_RX_INTR 2
59 
60 #define CHN_TXRX_STATUS_TIMEOUT BIT(6)
61 #define CHN_TXRX_STATUS_BI BIT(5)
62 #define CHN_TXRX_STATUS_FE BIT(4)
63 #define CHN_TXRX_STATUS_UNERR BIT(3)
64 #define CHN_TXRX_STATUS_OVRNERR BIT(3) /* UNERR->TX & OVRNERR->RX */
65 #define CHN_TXRX_STATUS_ERR BIT(2)
66 #define CHN_TXRX_STATUS_CMPLT BIT(1)
67 #define CHN_TXRX_STATUS_RDY BIT(0)
68 
69 #define CHN_RX_IE_MASK_OVRN BIT(15)
70 #define CHN_TXRX_IE_MASK_TIMEOUT BIT(14)
71 #define CHN_TXRX_IE_MASK_BI BIT(13)
72 #define CHN_TXRX_IE_MASK_FE BIT(12)
73 #define CHN_TXRX_IE_MASK_CMPLT BIT(1)
74 
75 #define SUART_GBL_INTR_ERR_MASK BIT(9)
76 #define SUART_PRU_ID_MASK 0xFF
77 
78 #define SUART_FIFO_LEN 15
79 
80 #define SUART_8X_OVRSMPL 1
81 #define SUART_16X_OVRSMPL 2
82 #define SUART_DEFAULT_OVRSMPL SUART_8X_OVRSMPL
83 
84 #if (SUART_DEFAULT_OVRSMPL == SUART_16X_OVRSMPL)
85 #define SUART_DEFAULT_BAUD 57600
86 #else
87 #define SUART_DEFAULT_BAUD 115200
88 #endif
89 
90 #define PRU_MODE_INVALID 0x00
91 #define PRU_MODE_TX_ONLY 0x1
92 #define PRU_MODE_RX_ONLY 0x2
93 #define PRU_MODE_RX_TX_BOTH 0x3
94 
95 #if (PRU_ACTIVE == BOTH_PRU)
96 #define PRU0_MODE PRU_MODE_RX_ONLY
97 #define PRU1_MODE PRU_MODE_TX_ONLY
98 #elif (PRU_ACTIVE == SINGLE_PRU)
99 #define PRU0_MODE PRU_MODE_RX_TX_BOTH
100 #define PRU1_MODE PRU_MODE_INVALID
101 #else
102 #define PRU0_MODE PRU_MODE_INVALID
103 #define PRU1_MODE PRU_MODE_INVALID
104 #endif
105 
106 #if !(defined CONFIG_OMAPL_SUART_MCASP) || (CONFIG_OMAPL_SUART_MCASP == 0)
107 #define MCASP_BASE_OFFSET (0x0)
108 #elif (CONFIG_OMAPL_SUART_MCASP == 1)
109 #define MCASP_BASE_OFFSET (0x4000)
110 #elif (CONFIG_OMAPL_SUART_MCASP == 2)
111 #define MCASP_BASE_OFFSET (0x8000)
112 #endif
113 
114 #define MCASP_XBUF_BASE_ADDR (0x01d00200 + MCASP_BASE_OFFSET)
115 #define MCASP_RBUF_BASE_ADDR (0x01d00280 + MCASP_BASE_OFFSET)
116 #define MCASP_SRCTL_BASE_ADDR (0x01d00180 + MCASP_BASE_OFFSET)
117 
118 #define MCASP_SRCTL_TX_MODE (0x000D)
119 #define MCASP_SRCTL_RX_MODE (0x000E)
120 
121 /* Since only PRU0 can work as RX */
122 #define RX_DEFAULT_DATA_DUMP_ADDR (0x00001FC)
123 #define PRU_NUM_OF_CHANNELS (16)
124 
125 #define PRU_SUART_UART1 (1u)
126 
127 #define PRU_SUART_UART2 (2u)
128 
129 #define PRU_SUART_UART3 (3u)
130 
132 #define PRU_SUART_UART4 (4u)
133 
134 #define PRU_SUART_UART5 (5u)
135 
136 #define PRU_SUART_UART6 (6u)
137 
138 #define PRU_SUART_UART7 (7u)
139 
140 #define PRU_SUART_UART8 (8u)
141 
143 #define PRU_SUART_UARTx_INVALID (9u)
144 
146 #define PRU_SUART_HALF_TX (1u)
147 #define PRU_SUART_HALF_RX (2u)
148 #define PRU_SUART_HALF_TX_DISABLED (4u)
149 #define PRU_SUART_HALF_RX_DISABLED (8u)
150 
152 /*
153  *====================
154  * Enumerations
155  *====================
156  */
157 
163  typedef enum {
166  } SUART_CHN_DIR;
167 
174  typedef enum {
177  } SUART_CHN_STATE;
178 
179 
185  typedef enum {
201 
207  typedef enum {
225 
231  typedef enum {
238 
244  typedef enum {
262 
268  typedef enum {
286 
292  typedef enum {
298 
299 /*
300  *====================
301  * Structures
302  *====================
303  */
304 
305 typedef struct
306 {
307  unsigned int mode:2;
308  unsigned int service_req:1;
309  unsigned int asp_id:2;
310  unsigned int reserved1:3;
311  unsigned int serializer_num:4;
312  unsigned int reserved2:4;
313  unsigned int presacler:10;
314  unsigned int over_sampling:2;
315  unsigned int framing_mask:1;
316  unsigned int break_mask:1;
317  unsigned int timeout_mask:1;
318  unsigned int reserved3:1;
320 
321 typedef struct
322 {
323  unsigned int bits_per_char:4;
324  unsigned int reserved1:4;
325  unsigned int data_len:4;
326  unsigned int reserved2:4;
327  unsigned int txrx_ready:1;
328  unsigned int txrx_complete:1;
329  unsigned int txrx_error:1;
330  unsigned int txrx_underrun:1;
331  unsigned int framing_error:1;
332  unsigned int break_error:1;
333  unsigned int timeout_error:1;
334  unsigned int reserved3:8;
335  unsigned int chn_state:1;
337 
338 typedef struct {
343  unsigned int CH_TXRXData;
345  unsigned int Reserved1;
348 
350 
351 typedef struct {
352  unsigned int asp_xsrctl_base;
353  unsigned int asp_xbuf_base;
354  unsigned short buff_addr;
355  unsigned char buff_size;
356  unsigned char bits_loaded;
359 
360 typedef struct {
361  unsigned int asp_rbuf_base;
362  unsigned int asp_rsrctl_base;
363  unsigned int reserved1;
364  unsigned int reserved2;
365  unsigned int reserved3;
366  unsigned int reserved4;
369 
375 typedef struct {
376  unsigned char TXSerializer;
378  unsigned char RXSerializer;
380  unsigned short txClkDivisor;
381  unsigned short rxClkDivisor;
382  unsigned char txBitsPerChar;
383  unsigned char rxBitsPerChar;
384  unsigned char Oversampling;
385  unsigned char BIIntrMask;
386  unsigned char FEIntrMask;
387 } suart_config;
388 
394  typedef struct {
395  unsigned short uartNum;
396  unsigned short uartType;
398  unsigned short uartTxChannel;
400  unsigned short uartRxChannel;
402  unsigned short uartStatus;
405 
407 
408 /*
409  *====================
410  * API declarations
411  *====================
412  */
413 
414  short pru_softuart_init(unsigned int txBaudValue,
415  unsigned int rxBaudValue,
416  unsigned int oversampling,
417  unsigned char *pru_suart_emu_code,
418  unsigned int fw_size,
419  arm_pru_iomap * pru_arm_iomap1);
420  int pru_intr_set_mask(unsigned short uartNum,
421  unsigned int txrxmode, unsigned int intrmask);
422  short pru_softuart_reset(unsigned int txBaudValue,
423  unsigned int rxBaudValue,
424  unsigned int oversampling);
425 
426  short pru_softuart_open(suart_handle hSuart);
427 
428  short pru_softuart_close(suart_handle hUart);
429 
431  (suart_handle hUart,
432  unsigned short txClkDivisor, unsigned short rxClkDivisor);
433 
435  (suart_handle hUart,
436  unsigned short txDataBits, unsigned short rxDataBits);
437 
439  (suart_handle hUart, suart_config * configUart);
440 
442  (suart_handle hUart, suart_config * configUart);
443 
445 
446  short pru_softuart_write
447  (suart_handle hUart,
448  unsigned int *ptTxDataBuf, unsigned short dataLen);
449 
450  short pru_softuart_read
451  (suart_handle hUart,
452  unsigned int *ptDataBuf, unsigned short dataLen);
453 
454  int suart_intr_clrmask(unsigned short uartNum,
455  unsigned int txrxmode, unsigned int intrmask);
456 
457  short pru_softuart_clrTxStatus(suart_handle hUart);
458 
459  short pru_softuart_getTxStatus(suart_handle hUart);
460 
461  short pru_softuart_clrRxStatus(suart_handle hUart);
462 
463  short pru_softuart_getRxStatus(suart_handle hUart);
464 
465  short pru_softuart_get_isrstatus(unsigned short uartNum,
466  unsigned short *txrxFlag);
467 
468  int pru_intr_clr_isrstatus(unsigned short uartNum, unsigned int txrxmode);
469 
470  int suart_intr_getmask(unsigned short uartNum,
471  unsigned int txrxmode, unsigned int intrmask);
472  int suart_intr_setmask(unsigned short uartNum,
473  unsigned int txrxmode, unsigned int intrmask);
474 
475  short pru_softuart_getTxDataLen(suart_handle hUart);
476 
477  short pru_softuart_getRxDataLen(suart_handle hUart);
478  short suart_arm_to_pru_intr(unsigned short uartNum);
479 
480  short arm_to_pru_intr_init(void);
481 
482  void pru_mcasp_deinit (void);
483  short pru_softuart_deinit(void);
484 
485  short pru_softuart_clrRxFifo(suart_handle hUart);
486 
487  short pru_softuart_read_data (suart_handle hUart, Uint8 * pDataBuffer,
488  Int32 s32MaxLen, Uint32 * pu32DataRead);
489 
490  short pru_softuart_stopReceive (suart_handle hUart);
491 
492  int suart_pru_to_host_intr_enable (unsigned short uartNum,
493  unsigned int txrxmode, int s32Flag);
494  void pru_set_fifo_timeout(Uint32 timeout);
495 
496 
497 #ifdef __cplusplus
498 } /* End of extern C */
499 #endif /* #ifdef __cplusplus */
500 #endif
short suart_arm_to_pru_intr(unsigned short uartNum)
Definition: suart_api.c:2398
unsigned int reserved2
Definition: suart_api.h:364
short pru_softuart_setdatabits(suart_handle hUart, unsigned short txDataBits, unsigned short rxDataBits)
Definition: suart_api.c:1005
unsigned char BIIntrMask
Definition: suart_api.h:385
pru_suart_chn_cntrl_config1 CH_Ctrl_Config1
Definition: suart_api.h:339
short pru_softuart_init(unsigned int txBaudValue, unsigned int rxBaudValue, unsigned int oversampling, unsigned char *pru_suart_emu_code, unsigned int fw_size, arm_pru_iomap *pru_arm_iomap1)
Definition: suart_api.c:530
unsigned char buff_size
Definition: suart_api.h:355
unsigned int asp_xsrctl_base
Definition: suart_api.h:352
void pru_set_fifo_timeout(Uint32 timeout)
Definition: suart_api.c:644
unsigned char Oversampling
Definition: suart_api.h:384
SUART_EN_UART_STATUS
One line description of the enum.
Definition: suart_api.h:292
unsigned char rxBitsPerChar
Definition: suart_api.h:383
int suart_pru_to_host_intr_enable(unsigned short uartNum, unsigned int txrxmode, int s32Flag)
Definition: suart_api.c:2772
SUART_EN_UARTNUM
One line description of the enum.
Definition: suart_api.h:207
SUART_EN_RXCHANNEL
One line description of the enum.
Definition: suart_api.h:268
short pru_softuart_close(suart_handle hUart)
Definition: suart_api.c:875
pru_suart_tx_cntx_priv * ppru_suart_tx_cntx_priv
Definition: suart_api.h:358
short pru_softuart_clrRxFifo(suart_handle hUart)
Definition: suart_api.c:2123
unsigned short rxClkDivisor
Definition: suart_api.h:381
short pru_softuart_getRxStatus(suart_handle hUart)
Definition: suart_api.c:2074
unsigned char RXSerializer
Definition: suart_api.h:378
unsigned char FEIntrMask
Definition: suart_api.h:386
unsigned short txClkDivisor
Definition: suart_api.h:380
int pru_intr_clr_isrstatus(unsigned short uartNum, unsigned int txrxmode)
Definition: suart_api.c:2352
SUART_CHN_STATE
Chanel State.
Definition: suart_api.h:174
volatile pru_suart_regs * PRU_SUART_RegsOvly
Definition: suart_api.h:349
unsigned short uartNum
Definition: suart_api.h:395
SUART_CHN_DIR
Chanel direction.
Definition: suart_api.h:163
int suart_intr_setmask(unsigned short uartNum, unsigned int txrxmode, unsigned int intrmask)
Definition: suart_api.c:2824
unsigned short uartType
Definition: suart_api.h:396
short pru_softuart_reset(unsigned int txBaudValue, unsigned int rxBaudValue, unsigned int oversampling)
unsigned int reserved1
Definition: suart_api.h:363
short pru_softuart_open(suart_handle hSuart)
Definition: suart_api.c:722
suart_struct_handle * suart_handle
Definition: suart_api.h:406
short arm_to_pru_intr_init(void)
Definition: suart_api.c:2444
int pru_softuart_pending_tx_request(void)
Definition: suart_api.c:1530
unsigned int asp_xbuf_base
Definition: suart_api.h:353
One line description of the structure.
Definition: suart_api.h:394
pru_suart_chn_config2_status CH_Config2_TXRXStatus
Definition: suart_api.h:341
pru_suart_rx_cntx_priv * ppru_suart_rx_cntx_priv
Definition: suart_api.h:368
unsigned short uartTxChannel
Definition: suart_api.h:398
SUART_EN_TXCHANNEL
One line description of the enum.
Definition: suart_api.h:244
short pru_softuart_getTxStatus(suart_handle hUart)
Definition: suart_api.c:1969
unsigned short buff_addr
Definition: suart_api.h:354
short pru_softuart_getTxDataLen(suart_handle hUart)
Definition: suart_api.c:1286
SUART_EN_BITSPERCHAR
One line description of the enum.
Definition: suart_api.h:185
unsigned int asp_rsrctl_base
Definition: suart_api.h:362
int pru_intr_set_mask(unsigned short uartNum, unsigned int txrxmode, unsigned int intrmask)
unsigned short uartRxChannel
Definition: suart_api.h:400
short pru_softuart_read_data(suart_handle hUart, Uint8 *pDataBuffer, Int32 s32MaxLen, Uint32 *pu32DataRead)
Definition: suart_api.c:1753
unsigned int reserved4
Definition: suart_api.h:366
short pru_softuart_clrRxStatus(suart_handle hUart)
Definition: suart_api.c:2203
int suart_intr_clrmask(unsigned short uartNum, unsigned int txrxmode, unsigned int intrmask)
Definition: suart_api.c:2953
short pru_softuart_getRxDataLen(suart_handle hUart)
Definition: suart_api.c:1343
One line description of the structure.
Definition: suart_api.h:375
short pru_softuart_setconfig(suart_handle hUart, suart_config *configUart)
Definition: suart_api.c:1112
unsigned int CH_TXRXData
Definition: suart_api.h:343
short pru_softuart_deinit(void)
Definition: suart_api.c:689
short pru_softuart_get_isrstatus(unsigned short uartNum, unsigned short *txrxFlag)
Definition: suart_api.c:2262
unsigned char bits_loaded
Definition: suart_api.h:356
SUART_EN_UARTTYPE
One line description of the enum.
Definition: suart_api.h:231
unsigned int reserved3
Definition: suart_api.h:365
short pru_softuart_setbaud(suart_handle hUart, unsigned short txClkDivisor, unsigned short rxClkDivisor)
Definition: suart_api.c:894
short pru_softuart_read(suart_handle hUart, unsigned int *ptDataBuf, unsigned short dataLen)
Definition: suart_api.c:1664
unsigned char txBitsPerChar
Definition: suart_api.h:382
unsigned char TXSerializer
Definition: suart_api.h:376
short pru_softuart_stopReceive(suart_handle hUart)
Definition: suart_api.c:1899
int suart_intr_getmask(unsigned short uartNum, unsigned int txrxmode, unsigned int intrmask)
Definition: suart_api.c:3075
short pru_softuart_getconfig(suart_handle hUart, suart_config *configUart)
Definition: suart_api.c:1401
unsigned short uartStatus
Definition: suart_api.h:402
unsigned int Reserved1
Definition: suart_api.h:345
void pru_mcasp_deinit(void)
Definition: suart_api.c:684
short pru_softuart_clrTxStatus(suart_handle hUart)
Definition: suart_api.c:2018
short pru_softuart_write(suart_handle hUart, unsigned int *ptTxDataBuf, unsigned short dataLen)
Definition: suart_api.c:1577
unsigned int asp_rbuf_base
Definition: suart_api.h:361