summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libcpu/bfin/serial/uart.h
blob: 730e0e261f040aee8b63f84a8b2142bcb3ce1d5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 *  RTEMS driver for Blackfin UARTs
 *
 *  COPYRIGHT (c) 2008 Kallisti Labs, Los Gatos, CA, USA
 *            written by Allan Hessenflow <allanh@kallisti.com>
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */
 

#ifndef _UART_H_
#define _UART_H_


#ifdef __cplusplus
extern "C" {
#endif

/** bfin_uart_channel object
 */
typedef struct {
  const char        *name;                 /** Holds name of the device */
  uint32_t          uart_baseAddress;           /** UART base address */
  uint32_t          uart_rxDmaBaseAddress;      /** RX DMA base address */
  uint32_t          uart_txDmaBaseAddress;      /** TX DMA base address */
  bool              uart_useInterrupts;         /** are interrupts used */
  bool              uart_useDma;                /** is dma used */
  int               uart_baud;                  /** baud rate, 0 for default */

  void              *termios;                   /** termios associated */
  uint8_t volatile  flags;                      /** flags for internal use */
  uint16_t          length;                     /** length for internal use */
} bfin_uart_channel_t;


typedef struct {
  uint32_t freq;
  int num_channels;
  bfin_uart_channel_t *channels;
} bfin_uart_config_t;

/**
 * @param base_address defines the UART base address
 * @param source defines the source that caused the interrupt. This argument
 * will help us in identifying if Rx or TX caused the interrupt.
 */
typedef struct {
  uint32_t base_address;
  int source;
} bfin_uart_arg_t;



char bfin_uart_poll_read(rtems_device_minor_number minor);

void bfin_uart_poll_write(int minor, char c);


/**
* Uart initialization function.
* @param major major number of the device
* @param config configuration parameters
* @return rtems status code
*/
rtems_status_code bfin_uart_initialize(rtems_device_major_number major,
    bfin_uart_config_t *config);



/**
 * Opens the device in different modes. The supported modes are
 * 1. Polling
 * 2. Interrupt
 * 3. DMA
 * At exit the uart_Exit function will be called to flush the device.
 *
 * @param major Major number of the device
 * @param minor Minor number of the device
 * @param arg
 * @return
 */
rtems_device_driver bfin_uart_open(rtems_device_major_number major,
    rtems_device_minor_number minor, void *arg);



/**
 * This function implements TX dma ISR. It clears the IRQ and dequeues a char
 * The channel argument will have the base address. Since there are two uart
 * and both the uarts can use the same tx dma isr.
 *
 * TODO: 1. Error checking 2. sending correct length ie after looking at the
 * number of elements the uart transmitted.
 *
 * @param _arg argument passed to the interrupt handler. It contains the
 * channel argument.
 */
void bfinUart_txDmaIsr(void *_arg);



/**
 * RX DMA ISR.
 * The polling route is used for receiving the characters. This is a place
 * holder for future implementation.
 * @param _arg
 */
void bfinUart_rxDmaIsr(void *_arg);


/**
 * This function implements TX ISR. The function gets called when the TX FIFO is
 * empty. It clears the interrupt and dequeues the character. It only tx one
 * character at a time.
 *
 * TODO: error handling.
 * @param _arg gets the channel information.
 */
void bfinUart_txIsr(void *_arg);


/**
* This function implements RX ISR
*/
void bfinUart_rxIsr(void *_arg);


#ifdef __cplusplus
}
#endif

#endif /* _UART_H_ */