1 /* Copyright (C) 2012-2013 Czech Technical University in Prague
4 * - Michal Horn <hornmich@fel.cvut.cz>
6 * This document contains proprietary information belonging to Czech
7 * Technical University in Prague. Passing on and copying of this
8 * document, and communication of its contents is not permitted
9 * without prior written authorization.
14 * This file contains general ports definitions. Ports are defined according to their names on
16 * Each port is define by port descriptor, which consists of:
17 * - list of its pin (pin descriptors),
19 * - get value function pointer,
20 * - set value function pointer.
21 * Finally each port descriptor is mapped to the port name string.
23 * Get and set value function are defined for each port style (ADC, SPI, GPIO) in separated files.
28 // Lists of pins assigned to the ports
29 static uint32_t port_cfg_dinmcu[] = PORT_CFG_DINMCU;
30 static uint32_t port_cfg_dinspi[] = PORT_CFG_DINSPI;
31 static uint32_t port_cfg_houtdiag[] = PORT_CFG_HOUTDIAG;
32 static uint32_t port_cfg_houtin[] = PORT_CFG_HOUTIN;
33 static uint32_t port_cfg_houtifbk[] = PORT_CFG_HOUTIFBK;
34 static uint32_t port_cfg_adc[] = PORT_CFG_ADC;
35 static uint32_t port_cfg_lout[] = PORT_CFG_LOUT;
36 static uint32_t port_cfg_dac1_2[] = PORT_CFG_DAC1_2;
37 static uint32_t port_cfg_dac3_4[] = PORT_CFG_DAC3_4;
38 static uint32_t port_cfg_dacdref[] = PORT_CFG_DACDREF;
39 static uint32_t port_cfg_hbr[] = PORT_CFG_HBR;
40 static uint32_t port_cfg_fray1[] = PORT_CFG_FRAY1;
41 static uint32_t port_cfg_fray2[] = PORT_CFG_FRAY2;
42 static uint32_t port_cfg_mouten[] = PORT_CFG_MOUTEN;
43 static uint32_t port_cfg_moutin[] = PORT_CFG_MOUTIN;
46 static port_desc_t port_desc_dinmcu = {
47 .config = port_cfg_dinmcu,
48 .numValues = PORT_NV_DINMCU,
49 .interfaceType = PORT_INT_TYPE_DINMCU,
50 .port_getfnc_ptr = PORT_GFC_DINMCU,
51 .port_setfnc_ptr = PORT_SFC_DINMCU,
54 static port_desc_t port_desc_dinspi = {
55 .config = port_cfg_dinspi,
56 .numValues = PORT_NV_DINSPI,
57 .interfaceType = PORT_INT_TYPE_DINSPI,
58 .port_getfnc_ptr = PORT_GFC_DINSPI,
59 .port_setfnc_ptr = PORT_SFC_DINSPI,
62 static port_desc_t port_desc_houtdiag = {
63 .config = port_cfg_houtdiag,
64 .numValues = PORT_NV_HOUTDIAG,
65 .interfaceType = PORT_INT_TYPE_HOUTDIAG,
66 .port_getfnc_ptr = PORT_GFC_HOUTDIAG,
67 .port_setfnc_ptr = PORT_SFC_HOUTDIAG,
70 static port_desc_t port_desc_houtin = {
71 .config = port_cfg_houtin,
72 .numValues = PORT_NV_HOUTIN,
73 .interfaceType = PORT_INT_TYPE_HOUTIN,
74 .port_getfnc_ptr = PORT_GFC_HOUTIN,
75 .port_setfnc_ptr = PORT_SFC_HOUTIN,
78 static port_desc_t port_desc_houtifbk = {
79 .config = port_cfg_houtifbk,
80 .numValues = PORT_NV_HOUTIFBK,
81 .interfaceType = PORT_INT_TYPE_HOUTIFBK,
82 .port_getfnc_ptr = PORT_GFC_HOUTIFBK,
83 .port_setfnc_ptr = PORT_SFC_HOUTIFBK,
86 static port_desc_t port_desc_adc = {
87 .config = port_cfg_adc,
88 .numValues = PORT_NV_ADC,
89 .interfaceType = PORT_INT_TYPE_ADC,
90 .port_getfnc_ptr = PORT_GFC_ADC,
91 .port_setfnc_ptr = PORT_SFC_ADC,
94 static port_desc_t port_desc_lout = {
95 .config = port_cfg_lout,
96 .numValues = PORT_NV_LOUT,
97 .interfaceType = PORT_INT_TYPE_LOUT,
98 .port_getfnc_ptr = PORT_GFC_LOUT,
99 .port_setfnc_ptr = PORT_SFC_LOUT,
102 static port_desc_t port_desc_dac1_2 = {
103 .config = port_cfg_dac1_2,
104 .numValues = PORT_NV_DAC1_2,
105 .interfaceType = PORT_INT_TYPE_DAC1_2,
106 .port_getfnc_ptr = PORT_GFC_DAC1_2,
107 .port_setfnc_ptr = PORT_SFC_DAC1_2,
110 static port_desc_t port_desc_dac3_4 = {
111 .config = port_cfg_dac3_4,
112 .numValues = PORT_NV_DAC3_4,
113 .interfaceType = PORT_INT_TYPE_DAC3_4,
114 .port_getfnc_ptr = PORT_GFC_DAC3_4,
115 .port_setfnc_ptr = PORT_SFC_DAC3_4,
118 static port_desc_t port_desc_dacdref = {
119 .config = port_cfg_dacdref,
120 .numValues = PORT_NV_DACDREF,
121 .interfaceType = PORT_INT_TYPE_DACDREF,
122 .port_getfnc_ptr = PORT_GFC_DACDREF,
123 .port_setfnc_ptr = PORT_SFC_DACDREF,
126 static port_desc_t port_desc_hbr = {
127 .config = port_cfg_hbr,
128 .numValues = PORT_NV_HBR,
129 .interfaceType = PORT_INT_TYPE_HBR,
130 .port_getfnc_ptr = PORT_GFC_HBR,
131 .port_setfnc_ptr = PORT_SFC_HBR,
134 static port_desc_t port_desc_fray1 = {
135 .config = port_cfg_fray1,
136 .numValues = PORT_NV_FRAY1,
137 .interfaceType = PORT_INT_TYPE_FRAY1,
138 .port_getfnc_ptr = PORT_GFC_FRAY1,
139 .port_setfnc_ptr = PORT_SFC_FRAY1,
142 static port_desc_t port_desc_fray2 = {
143 .config = port_cfg_fray2,
144 .numValues = PORT_NV_FRAY2,
145 .interfaceType = PORT_INT_TYPE_FRAY2,
146 .port_getfnc_ptr = PORT_GFC_FRAY2,
147 .port_setfnc_ptr = PORT_SFC_FRAY2,
150 static port_desc_t port_desc_mouten = {
151 .config = port_cfg_mouten,
152 .numValues = PORT_NV_MOUTEN,
153 .interfaceType = PORT_INT_TYPE_MOUTEN,
154 .port_getfnc_ptr = PORT_GFC_MOUTEN,
155 .port_setfnc_ptr = PORT_SFC_MOUTEN,
158 static port_desc_t port_desc_moutin = {
159 .config = port_cfg_moutin,
160 .numValues = PORT_NV_MOUTIN,
161 .interfaceType = PORT_INT_TYPE_MOUTIN,
162 .port_getfnc_ptr = PORT_GFC_MOUTIN,
163 .port_setfnc_ptr = PORT_SFC_MOUTIN,
166 // Maps of port names to port descriptors
167 static port_def_t port_definition[PORT_CNT] = {
168 {.name = PORT_NAME_DINMCU, .desc = &port_desc_dinmcu},
169 {.name = PORT_NAME_DINSPI, .desc = &port_desc_dinspi},
170 {.name = PORT_NAME_HOUTDIAG, .desc = &port_desc_houtdiag},
171 {.name = PORT_NAME_HOUTIN, .desc = &port_desc_houtin},
172 {.name = PORT_NAME_HOUTIFBK, .desc = &port_desc_houtifbk},
173 {.name = PORT_NAME_ADC, .desc = &port_desc_adc},
174 {.name = PORT_NAME_LOUT, .desc = &port_desc_lout},
175 {.name = PORT_NAME_DAC1_2, .desc = &port_desc_dac1_2},
176 {.name = PORT_NAME_DAC3_4, .desc = &port_desc_dac3_4},
177 {.name = PORT_NAME_DACDREF, .desc = &port_desc_dacdref},
178 {.name = PORT_NAME_HBR, .desc = &port_desc_hbr},
179 {.name = PORT_NAME_FRAY1, .desc = &port_desc_fray1},
180 {.name = PORT_NAME_FRAY2, .desc = &port_desc_fray2},
181 {.name = PORT_NAME_MOUTEN, .desc = &port_desc_mouten},
182 {.name = PORT_NAME_MOUTIN, .desc = &port_desc_moutin}
186 * Get port descriptor assigned to port name.
187 * @param[in] port_name Pointer to string - the name of the port.
188 * @param[in] len Length of the name, if terminated by '/0', then len=-1
189 * @return Port descriptor or NULL if not found
191 port_desc_t *hal_port_get_dsc(const char *port_name, int len)
194 const char *port_name_ptr;
195 char port_name_term[32];
197 if (len != -1) { // port name not terminated by '\0'
198 strncpy(port_name_term, port_name, len);
199 port_name_term[len] = '\0';
200 port_name_ptr = port_name_term;
202 else port_name_ptr = port_name;
204 for (i = 0; i < PORT_CNT; i++) {
205 if (strcmp(port_name_ptr, port_definition[i].name) == 0)
206 return port_definition[i].desc;
212 * Get port descriptor assigned to port name.
213 * @param[in] port_name Pointer to string - the name of the port.
214 * @param[in] len Length of the name, if terminated by '/0', then len=-1
215 * @return Port descriptor or NULL if not found
217 const port_def_t *hal_port_get_definitions()
219 return (const port_def_t *)port_definition;