1 /******************************************************************************
2 * *
3 * License Agreement *
4 * *
5 * Copyright (c) 2007 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 * *
27 ******************************************************************************/
28
29 #include "alt_types.h"
30 #include "sys/alt_dev.h"
31 #include "altera_avalon_uart.h"
32
33 extern int altera_avalon_uart_read(altera_avalon_uart_state* sp,
34 char* buffer, int space, int flags);
35 extern int altera_avalon_uart_write(altera_avalon_uart_state* sp,
36 const char* ptr, int count, int flags);
37 extern int altera_avalon_uart_ioctl(altera_avalon_uart_state* sp,
38 int req, void* arg);
39 extern int altera_avalon_uart_close(altera_avalon_uart_state* sp, int flags);
40
41 /* ----------------------------------------------------------------------- */
42 /* --------------------- WRAPPERS FOR ALT FD SUPPORT --------------------- */
43 /*
44 *
45 */
46
47 int
altera_avalon_uart_read_fd(alt_fd * fd,char * buffer,int space)48 altera_avalon_uart_read_fd(alt_fd* fd, char* buffer, int space)
49 {
50 altera_avalon_uart_dev* dev = (altera_avalon_uart_dev*) fd->dev;
51
52 return altera_avalon_uart_read(&dev->state, buffer, space,
53 fd->fd_flags);
54 }
55
56 int
altera_avalon_uart_write_fd(alt_fd * fd,const char * buffer,int space)57 altera_avalon_uart_write_fd(alt_fd* fd, const char* buffer, int space)
58 {
59 altera_avalon_uart_dev* dev = (altera_avalon_uart_dev*) fd->dev;
60
61 return altera_avalon_uart_write(&dev->state, buffer, space,
62 fd->fd_flags);
63 }
64
65 #if !defined(ALT_USE_SMALL_DRIVERS) && !defined(ALTERA_AVALON_UART_SMALL)
66
67 /*
68 * Fast driver
69 */
70
71 /*
72 * To reduce the code footprint of this driver, the ioctl() function is not
73 * included by default. If you wish to use the ioctl features provided
74 * below, you can do so by adding the option : -DALTERA_AVALON_UART_USE_IOCTL
75 * to CPPFLAGS in the Makefile (or through the Eclipse IDE).
76 */
77
78 #ifdef ALTERA_AVALON_UART_USE_IOCTL
79
80 int
altera_avalon_uart_ioctl_fd(alt_fd * fd,int req,void * arg)81 altera_avalon_uart_ioctl_fd(alt_fd* fd, int req, void* arg)
82 {
83 altera_avalon_uart_dev* dev = (altera_avalon_uart_dev*) fd->dev;
84
85 return altera_avalon_uart_ioctl(&dev->state, req, arg);
86 }
87
88 #endif /* ALTERA_AVALON_UART_USE_IOCTL */
89
90 int
altera_avalon_uart_close_fd(alt_fd * fd)91 altera_avalon_uart_close_fd(alt_fd* fd)
92 {
93 altera_avalon_uart_dev* dev = (altera_avalon_uart_dev*) fd->dev;
94
95 return altera_avalon_uart_close(&dev->state, fd->fd_flags);
96 }
97
98 #endif /* fast driver */
99