Contiki 3.x
devicemap.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Eistec AB.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * This file is part of the Mulle platform port of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Device I/O mappings for the Mulle platform.
36  * \author
37  * Joakim Gebart <joakim.gebart@eistec.se>
38  */
39 
40 #include <stddef.h> /* for NULL */
41 #include "devopttab.h"
42 #include "devicemap.h"
43 #include "devio-uart.h"
44 #include "devio-null.h"
45 #include "K60.h"
46 
47 static const devoptab_t dotab_uart0 = {
48  "UART0", /* name */
49  1, /* isatty */
50  S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, /* Character device, 0777 perms (crwxrwxrwx) */
51  devnull_open_r,
52  devnull_close_r,
53  uart0_write_r,
54  NULL, /* Not yet implemented */
55  NULL, /* No seeking on UART */
56  NULL, /* No fstat on UART */
57 };
58 
59 static const devoptab_t dotab_uart1 = {
60  "UART1", /* name */
61  1, /* isatty */
62  S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, /* Character device, 0777 perms (crwxrwxrwx) */
63  devnull_open_r,
64  devnull_close_r,
65  uart1_write_r,
66  NULL, /* Not yet implemented */
67  NULL, /* No seeking on UART */
68  NULL, /* No fstat on UART */
69 };
70 
71 static const devoptab_t dotab_uart2 = {
72  "UART2", /* name */
73  1, /* isatty */
74  S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, /* Character device, 0777 perms (crwxrwxrwx) */
75  devnull_open_r,
76  devnull_close_r,
77  uart2_write_r,
78  NULL, /* Not yet implemented */
79  NULL, /* No seeking on UART */
80  NULL, /* No fstat on UART */
81 };
82 
83 static const devoptab_t dotab_uart3 = {
84  "UART3", /* name */
85  1, /* isatty */
86  S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, /* Character device, 0777 perms (crwxrwxrwx) */
87  devnull_open_r,
88  devnull_close_r,
89  uart3_write_r,
90  NULL, /* Not yet implemented */
91  NULL, /* No seeking on UART */
92  NULL, /* No fstat on UART */
93 };
94 
95 static const devoptab_t dotab_uart4 = {
96  "UART4", /* name */
97  1, /* isatty */
98  S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, /* Character device, 0777 perms (crwxrwxrwx) */
99  devnull_open_r,
100  devnull_close_r,
101  uart4_write_r,
102  NULL, /* Not yet implemented */
103  NULL, /* No seeking on UART */
104  NULL, /* No fstat on UART */
105 };
106 
107 static const devoptab_t dotab_stdin = {
108  "stdin", /* name */
109  1, /* isatty */
110  S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH, /* Character device, 0444 perms (cr--r--r--) */
111  devnull_open_r,
112  devnull_close_r,
113  NULL,
114  NULL, /* Not yet implemented */
115  NULL, /* No seeking on UART */
116  NULL, /* No fstat on UART */
117 };
118 
119 static const devoptab_t dotab_stdout = {
120  "stdout", /* name */
121  1, /* isatty */
122  S_IFCHR | S_IWUSR | S_IWGRP | S_IWOTH, /* Character device, 0222 perms (c-w--w--w-) */
123  devnull_open_r,
124  devnull_close_r,
125  uart1_write_r,
126  NULL, /* Not yet implemented */
127  NULL, /* No seeking on UART */
128  NULL, /* No fstat on UART */
129 };
130 
131 
132 
133 /* This table maps the standard streams to device operations table entries. */
134 const devoptab_t *devoptab_list[MAX_OPEN_DEVICES] = { 0 };
135  //~ &dotab_com1, /* standard input */
136  //~ &dotab_com1, /* standard output */
137  //~ &dotab_com1, /* standard error */
138  //~ 0, /* another device */
139  //~ 0, /* and so on... */
140  //~ 0 /* terminates the list */
141 //~ };
142 
143 static const devoptab_name_t devoptab_names[] = {
144  {"UART0", &dotab_uart0},
145  {"UART1", &dotab_uart1},
146  {"UART2", &dotab_uart2},
147  {"UART3", &dotab_uart3},
148  {"UART4", &dotab_uart4},
149 };
150 
151 const devoptab_name_list_t devoptab_name_list = {
152  sizeof(devoptab_names) / sizeof(devoptab_names[0]), /* len */
153  &devoptab_names[0], /* data */
154 };
155 
156 void devicemap_init(void) {
157  /* Set up stdin, stdout and stderr */
158  devoptab_list[STDIN_FILENO] = &dotab_stdin;
159  devoptab_list[STDOUT_FILENO] = &dotab_stdout;
160  devoptab_list[STDERR_FILENO] = &dotab_stdout;
161 }
File-like I/O device operations table.
Device I/O mappings for the Mulle platform.
A simple &quot;device operations&quot; table, with function pointers for all the kinds of activities you would ...
Definition: devopttab.h:58
#define NULL
The null pointer.
K60 hardware register header wrapper.
Device I/O helpers for UARTs on K60.
Device I/O helpers for a no-op device.
#define MAX_OPEN_DEVICES
Maximum number of file descriptors allocated to hardware devices.
Definition: devicemap.h:50