]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - rpp/lib/rpp/src/hal/port_def.c
c1abe18e56496a92aad78ceabca169c7a115d003
[pes-rpp/rpp-test-sw.git] / rpp / lib / rpp / src / hal / port_def.c
1 /*
2  * port_def.c
3  *
4  *  Created on: 26.11.2012
5  *      Author: Michal Horn
6  *
7  *  This file contains general ports definitions. Ports are defined according to their names on the RPP board.
8  *  Each port is define by port descriptor, which consists of:
9  *      - list of its pin (pin descriptors),
10  *      - number of pins,
11  *      - get value function pointer,
12  *      - set value function pointer.
13  *  Finally each port descriptor is mapped to the port name string.
14  *
15  *  Get and set value function are defined for each port style (ADC, SPI, GPIO) in separated files.
16  */
17
18 //#include "hal/port_def.h"
19 // Cannot include upper layer
20 //#include "drv_adc.h"
21 //#include "hal/port_spi.h"
22 //#include "hal/port_gpio.h"
23 #include "hal/hal.h"
24
25 // Lists of pins assigned to the ports
26 static uint32_t port_cfg_dinmcu[] = PORT_CFG_DINMCU;
27 static uint32_t port_cfg_dinspi[] = PORT_CFG_DINSPI;
28 static uint32_t port_cfg_houtdiag[] = PORT_CFG_HOUTDIAG;
29 static uint32_t port_cfg_houtin[] = PORT_CFG_HOUTIN;
30 static uint32_t port_cfg_houtifbk[] = PORT_CFG_HOUTIFBK;
31 static uint32_t port_cfg_adc[] = PORT_CFG_ADC;
32 static uint32_t port_cfg_lout[] = PORT_CFG_LOUT;
33 static uint32_t port_cfg_dac1_2[] = PORT_CFG_DAC1_2;
34 static uint32_t port_cfg_dac3_4[] = PORT_CFG_DAC3_4;
35 static uint32_t port_cfg_dacdref[] = PORT_CFG_DACDREF;
36 static uint32_t port_cfg_hbr[] = PORT_CFG_HBR;
37 static uint32_t port_cfg_fray1[] = PORT_CFG_FRAY1;
38 static uint32_t port_cfg_fray2[] = PORT_CFG_FRAY2;
39 static uint32_t port_cfg_mouten[] = PORT_CFG_MOUTEN;
40
41 // Port descriptors
42 static port_desc_t port_desc_dinmcu = {
43         .config = port_cfg_dinmcu,
44         .numValues = PORT_NV_DINMCU,
45         .port_getfnc_ptr = PORT_GFC_DINMCU,
46         .port_setfnc_ptr = PORT_SFC_DINMCU,
47 };
48
49 static port_desc_t port_desc_dinspi = {
50         .config = port_cfg_dinspi,
51         .numValues = PORT_NV_DINSPI,
52         .port_getfnc_ptr = PORT_GFC_DINSPI,
53         .port_setfnc_ptr = PORT_SFC_DINSPI,
54 };
55
56 static port_desc_t port_desc_houtdiag = {
57         .config = port_cfg_houtdiag,
58         .numValues = PORT_NV_HOUTDIAG,
59         .port_getfnc_ptr = PORT_GFC_HOUTDIAG,
60         .port_setfnc_ptr = PORT_SFC_HOUTDIAG,
61 };
62
63 static port_desc_t port_desc_houtin = {
64         .config = port_cfg_houtin,
65         .numValues = PORT_NV_HOUTIN,
66         .port_getfnc_ptr = PORT_GFC_HOUTIN,
67         .port_setfnc_ptr = PORT_SFC_HOUTIN,
68 };
69
70 static port_desc_t port_desc_houtifbk = {
71         .config = port_cfg_houtifbk,
72         .numValues = PORT_NV_HOUTIFBK,
73         .port_getfnc_ptr = PORT_GFC_HOUTIFBK,
74         .port_setfnc_ptr = PORT_SFC_HOUTIFBK,
75 };
76
77 static port_desc_t port_desc_adc = {
78         .config = port_cfg_adc,
79         .numValues = PORT_NV_ADC,
80         .port_getfnc_ptr = PORT_GFC_ADC,
81         .port_setfnc_ptr = PORT_SFC_ADC,
82 };
83
84 static port_desc_t port_desc_lout = {
85         .config = port_cfg_lout,
86         .numValues = PORT_NV_LOUT,
87         .port_getfnc_ptr = PORT_GFC_LOUT,
88         .port_setfnc_ptr = PORT_SFC_LOUT,
89 };
90
91 static port_desc_t port_desc_dac1_2 = {
92         .config = port_cfg_dac1_2,
93         .numValues = PORT_NV_DAC1_2,
94         .port_getfnc_ptr = PORT_GFC_DAC1_2,
95         .port_setfnc_ptr = PORT_SFC_DAC1_2,
96 };
97
98 static port_desc_t port_desc_dac3_4 = {
99         .config = port_cfg_dac3_4,
100         .numValues = PORT_NV_DAC3_4,
101         .port_getfnc_ptr = PORT_GFC_DAC3_4,
102         .port_setfnc_ptr = PORT_SFC_DAC3_4,
103 };
104
105 static port_desc_t port_desc_dacdref = {
106         .config = port_cfg_dacdref,
107         .numValues = PORT_NV_DACDREF,
108         .port_getfnc_ptr = PORT_GFC_DACDREF,
109         .port_setfnc_ptr = PORT_SFC_DACDREF,
110 };
111
112 static port_desc_t port_desc_hbr = {
113         .config = port_cfg_hbr,
114         .numValues = PORT_NV_HBR,
115         .port_getfnc_ptr = PORT_GFC_HBR,
116         .port_setfnc_ptr = PORT_SFC_HBR,
117 };
118
119 static port_desc_t port_desc_fray1 = {
120         .config = port_cfg_fray1,
121         .numValues = PORT_NV_FRAY1,
122         .port_getfnc_ptr = PORT_GFC_FRAY1,
123         .port_setfnc_ptr = PORT_SFC_FRAY1,
124 };
125
126 static port_desc_t port_desc_fray2 = {
127         .config = port_cfg_fray2,
128         .numValues = PORT_NV_FRAY2,
129         .port_getfnc_ptr = PORT_GFC_FRAY2,
130         .port_setfnc_ptr = PORT_SFC_FRAY2,
131 };
132
133 static port_desc_t port_desc_mouten = {
134         .config = port_cfg_mouten,
135         .numValues = PORT_NV_MOUTEN,
136         .port_getfnc_ptr = PORT_GFC_MOUTEN,
137         .port_setfnc_ptr = PORT_SFC_MOUTEN,
138 };
139
140 // Maps of port names to port descriptors
141 static port_def_t port_definition[PORT_CNT] = {
142         {.name = PORT_NAME_DINMCU,      .desc = &port_desc_dinmcu},
143         {.name = PORT_NAME_DINSPI,      .desc = &port_desc_dinspi},
144         {.name = PORT_NAME_HOUTDIAG,    .desc = &port_desc_houtdiag},
145         {.name = PORT_NAME_HOUTIN,      .desc = &port_desc_houtin},
146         {.name = PORT_NAME_HOUTIFBK,    .desc = &port_desc_houtifbk},
147         {.name = PORT_NAME_ADC,         .desc = &port_desc_adc},
148         {.name = PORT_NAME_LOUT,        .desc = &port_desc_lout},
149         {.name = PORT_NAME_DAC1_2,      .desc = &port_desc_dac1_2},
150         {.name = PORT_NAME_DAC3_4,      .desc = &port_desc_dac3_4},
151         {.name = PORT_NAME_DACDREF,     .desc = &port_desc_dacdref},
152         {.name = PORT_NAME_HBR,         .desc = &port_desc_hbr},
153         {.name = PORT_NAME_DAC1_2,      .desc = &port_desc_dac1_2},
154         {.name = PORT_NAME_FRAY1,       .desc = &port_desc_fray1},
155         {.name = PORT_NAME_FRAY2,       .desc = &port_desc_fray2},
156         {.name = PORT_NAME_MOUTEN,      .desc = &port_desc_mouten}
157 };
158
159 /**
160  *  Get port descriptor assigned to port name.
161  *  @param[in]  port_name   Pointer to string - the name of the port.
162  *  @param[in]  len         Length of the name, if terminated by '/0', then len=-1
163  *  @return Port descriptor or NULL if not found
164  */
165 port_desc_t* hal_port_get_dsc(const char* port_name, int len) {
166     uint32_t i;
167     const char* port_name_ptr;
168     char port_name_term[32];
169     if (len != -1) {    // port name not terminated by '\0'
170         strncpy(port_name_term, port_name, len);
171         port_name_term[len] = '\0';
172         port_name_ptr = port_name_term;
173     }
174     else port_name_ptr = port_name;
175
176     for (i = 0; i < PORT_CNT; i++) {
177         if (strcmp(port_name_ptr, port_definition[i].name) == 0) {
178             return port_definition[i].desc;
179         }
180     }
181     return NULL;
182 }
183
184 /**
185  *  Get port descriptor assigned to port name.
186  *  @param[in]  port_name   Pointer to string - the name of the port.
187  *  @param[in]  len         Length of the name, if terminated by '/0', then len=-1
188  *  @return Port descriptor or NULL if not found
189  */
190 const port_def_t* hal_port_get_definitions() {
191     return (const port_def_t*)port_definition;
192 }
193