OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [syn/] [components/] [sd_card/] [firmware/] [bsp/] [drivers/] [inc/] [altera_avalon_jtag_uart.h] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 alfik
/******************************************************************************
2
*                                                                             *
3
* License Agreement                                                           *
4
*                                                                             *
5
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA.           *
6
* All rights reserved.                                                        *
7
*                                                                             *
8
* Permission is hereby granted, free of charge, to any person obtaining a     *
9
* copy of this software and associated documentation files (the "Software"),  *
10
* to deal in the Software without restriction, including without limitation   *
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
12
* and/or sell copies of the Software, and to permit persons to whom the       *
13
* Software is furnished to do so, subject to the following conditions:        *
14
*                                                                             *
15
* The above copyright notice and this permission notice shall be included in  *
16
* all copies or substantial portions of the Software.                         *
17
*                                                                             *
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
19
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
21
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
22
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
23
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
24
* DEALINGS IN THE SOFTWARE.                                                   *
25
*                                                                             *
26
* This agreement shall be governed in all respects by the laws of the State   *
27
* of California and by the laws of the United States of America.              *
28
*                                                                             *
29
******************************************************************************/
30
 
31
#ifndef __ALT_AVALON_JTAG_UART_H__
32
#define __ALT_AVALON_JTAG_UART_H__
33
 
34
#include <stddef.h>
35
 
36
#include "sys/alt_alarm.h"
37
#include "sys/alt_warning.h"
38
 
39
#include "os/alt_sem.h"
40
#include "os/alt_flag.h"
41
 
42
#ifdef __cplusplus
43
extern "C"
44
{
45
#endif /* __cplusplus */
46
 
47
/*
48
 * If the user wants all drivers to be small rather than fast then make sure
49
 * this one is marked as needing to be small.
50
 */
51
#if defined ALT_USE_SMALL_DRIVERS && !defined ALTERA_AVALON_JTAG_UART_SMALL
52
#define ALTERA_AVALON_JTAG_UART_SMALL
53
#endif
54
 
55
/*
56
 * If the user wants to ignore FIFO full error after timeout
57
  */
58
#if defined ALT_JTAG_UART_IGNORE_FIFO_FULL_ERROR && !defined ALTERA_AVALON_JTAG_UART_IGNORE_FIFO_FULL_ERROR
59
#define ALTERA_AVALON_JTAG_UART_IGNORE_FIFO_FULL_ERROR
60
#endif
61
 
62
/*
63
 * Constants that can be overriden.
64
 */
65
#ifndef ALTERA_AVALON_JTAG_UART_DEFAULT_TIMEOUT
66
#define ALTERA_AVALON_JTAG_UART_DEFAULT_TIMEOUT 10
67
#endif
68
 
69
#ifndef ALTERA_AVALON_JTAG_UART_BUF_LEN
70
#define ALTERA_AVALON_JTAG_UART_BUF_LEN 2048
71
#endif
72
 
73
/*
74
 * ALT_JTAG_UART_READ_RDY and ALT_JTAG_UART_WRITE_RDY are the bitmasks
75
 * that define uC/OS-II event flags that are releated to this device.
76
 *
77
 * ALT_JTAG_UART_READ_RDY indicates that there is read data in the buffer
78
 * ready to be processed. ALT_JTAG_UART_WRITE_RDY indicates that the transmitter is
79
 * ready for more data.
80
 */
81
#define ALT_JTAG_UART_READ_RDY  0x1
82
#define ALT_JTAG_UART_WRITE_RDY 0x2
83
#define ALT_JTAG_UART_TIMEOUT   0x4
84
 
85
/*
86
 * State structure definition. Each instance of the driver uses one
87
 * of these structures to hold its associated state.
88
 */
89
 
90
typedef struct altera_avalon_jtag_uart_state_s
91
{
92
  unsigned int base;
93
 
94
#ifndef ALTERA_AVALON_JTAG_UART_SMALL
95
 
96
  unsigned int  timeout; /* Timeout until host is assumed inactive */
97
  alt_alarm     alarm;
98
  unsigned int  irq_enable;
99
  unsigned int  host_inactive;
100
 
101
  ALT_SEM      (read_lock)
102
  ALT_SEM      (write_lock)
103
  ALT_FLAG_GRP (events)
104
 
105
  /* The variables below are volatile because they are modified by the
106
   * interrupt routine.  Making them volatile and reading them atomically
107
   * means that we don't need any large critical sections.
108
   */
109
  volatile unsigned int rx_in;
110
  unsigned int  rx_out;
111
  unsigned int  tx_in;
112
  volatile unsigned int tx_out;
113
  char          rx_buf[ALTERA_AVALON_JTAG_UART_BUF_LEN];
114
  char          tx_buf[ALTERA_AVALON_JTAG_UART_BUF_LEN];
115
 
116
#endif /* !ALTERA_AVALON_JTAG_UART_SMALL */
117
 
118
} altera_avalon_jtag_uart_state;
119
 
120
/*
121
 * Macros used by alt_sys_init when the ALT file descriptor facility isn't used.
122
 */
123
 
124
#ifdef ALTERA_AVALON_JTAG_UART_SMALL
125
 
126
#define ALTERA_AVALON_JTAG_UART_STATE_INSTANCE(name, state)    \
127
  altera_avalon_jtag_uart_state state =                  \
128
  {                                                      \
129
    name##_BASE,                                         \
130
  }
131
 
132
#define ALTERA_AVALON_JTAG_UART_STATE_INIT(name, state)
133
 
134
#else /* !ALTERA_AVALON_JTAG_UART_SMALL */
135
 
136
#define ALTERA_AVALON_JTAG_UART_STATE_INSTANCE(name, state)   \
137
  altera_avalon_jtag_uart_state state =                  \
138
  {                                                      \
139
    name##_BASE,                                         \
140
    ALTERA_AVALON_JTAG_UART_DEFAULT_TIMEOUT,             \
141
  }
142
 
143
/*
144
 * Externally referenced routines
145
 */
146
extern void altera_avalon_jtag_uart_init(altera_avalon_jtag_uart_state* sp,
147
                                        int irq_controller_id, int irq);
148
 
149
#define ALTERA_AVALON_JTAG_UART_STATE_INIT(name, state)                      \
150
  {                                                                          \
151
    if (name##_IRQ == ALT_IRQ_NOT_CONNECTED)                                 \
152
    {                                                                        \
153
      ALT_LINK_ERROR ("Error: Interrupt not connected for " #name ". "       \
154
                      "You have selected the interrupt driven version of "   \
155
                      "the ALTERA Avalon JTAG UART driver, but the "         \
156
                      "interrupt is not connected for this device. You can " \
157
                      "select a polled mode driver by checking the 'small "  \
158
                      "driver' option in the HAL configuration window, or "  \
159
                      "by using the -DALTERA_AVALON_JTAG_UART_SMALL "        \
160
                      "preprocessor flag.");                                 \
161
    }                                                                        \
162
    else                                                                     \
163
      altera_avalon_jtag_uart_init(&state,                                   \
164
                                   name##_IRQ_INTERRUPT_CONTROLLER_ID,       \
165
                                   name##_IRQ);                              \
166
  }
167
 
168
#endif /* ALTERA_AVALON_JTAG_UART_SMALL */
169
 
170
/*
171
 * Include in case non-direct version of driver required.
172
 */
173
#include "altera_avalon_jtag_uart_fd.h"
174
 
175
/*
176
 * Map alt_sys_init macros to direct or non-direct versions.
177
 */
178
#ifdef ALT_USE_DIRECT_DRIVERS
179
 
180
#define ALTERA_AVALON_JTAG_UART_INSTANCE(name, state) \
181
   ALTERA_AVALON_JTAG_UART_STATE_INSTANCE(name, state)
182
#define ALTERA_AVALON_JTAG_UART_INIT(name, state) \
183
   ALTERA_AVALON_JTAG_UART_STATE_INIT(name, state)
184
 
185
#else /* !ALT_USE_DIRECT_DRIVERS */
186
 
187
#define ALTERA_AVALON_JTAG_UART_INSTANCE(name, dev) \
188
   ALTERA_AVALON_JTAG_UART_DEV_INSTANCE(name, dev)
189
#define ALTERA_AVALON_JTAG_UART_INIT(name, dev) \
190
   ALTERA_AVALON_JTAG_UART_DEV_INIT(name, dev)
191
 
192
#endif /* ALT_USE_DIRECT_DRIVERS */
193
 
194
#ifdef __cplusplus
195
}
196
#endif /* __cplusplus */
197
 
198
#endif /* __ALT_AVALON_JTAG_UART_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.