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_gioa[] = PORT_CFG_GIOA;
30 static uint32_t port_cfg_giob[] = PORT_CFG_GIOB;
31 static uint32_t port_cfg_nhet1[] = PORT_CFG_NHET1;
32 static uint32_t port_cfg_adc[] = PORT_CFG_ADC;
35 static port_desc_t port_desc_gioa = {
36 .config = port_cfg_gioa,
37 .numValues = PORT_NV_GIOA,
38 .interfaceType = PORT_INT_TYPE_GIOA,
39 .port_getfnc_ptr = PORT_GFC_GIOA,
40 .port_setfnc_ptr = PORT_SFC_GIOA,
43 static port_desc_t port_desc_giob = {
44 .config = port_cfg_giob,
45 .numValues = PORT_NV_GIOB,
46 .interfaceType = PORT_INT_TYPE_GIOB,
47 .port_getfnc_ptr = PORT_GFC_GIOB,
48 .port_setfnc_ptr = PORT_SFC_GIOB,
51 static port_desc_t port_desc_nhet1 = {
52 .config = port_cfg_nhet1,
53 .numValues = PORT_NV_NHET1,
54 .interfaceType = PORT_INT_TYPE_NHET1,
55 .port_getfnc_ptr = PORT_GFC_NHET1,
56 .port_setfnc_ptr = PORT_SFC_NHET1,
59 static port_desc_t port_desc_adc = {
60 .config = port_cfg_adc,
61 .numValues = PORT_NV_ADC,
62 .interfaceType = PORT_INT_TYPE_ADC,
63 .port_getfnc_ptr = PORT_GFC_ADC,
64 .port_setfnc_ptr = PORT_SFC_ADC,
67 // Maps of port names to port descriptors
68 port_def_t port_definition[PORT_CNT] = {
69 {.name = PORT_NAME_GIOA, .desc = &port_desc_gioa},
70 {.name = PORT_NAME_GIOB, .desc = &port_desc_giob},
71 {.name = PORT_NAME_NHET1, .desc = &port_desc_nhet1},
72 {.name = PORT_NAME_ADC, .desc = &port_desc_adc}
76 * Get port descriptor assigned to port name.
77 * @param[in] port_name Pointer to string - the name of the port.
78 * @param[in] len Length of the name, if terminated by '/0', then len=-1
79 * @return Port descriptor or NULL if not found
81 port_desc_t *hal_port_get_dsc(const char *port_name, int len)
84 const char *port_name_ptr;
85 char port_name_term[32];
87 if (len != -1) { // port name not terminated by '\0'
88 strncpy(port_name_term, port_name, len);
89 port_name_term[len] = '\0';
90 port_name_ptr = port_name_term;
92 else port_name_ptr = port_name;
94 for (i = 0; i < PORT_CNT; i++) {
95 if (strcmp(port_name_ptr, port_definition[i].name) == 0)
96 return port_definition[i].desc;
102 * Get port descriptor assigned to port name.
103 * @param[in] port_name Pointer to string - the name of the port.
104 * @param[in] len Length of the name, if terminated by '/0', then len=-1
105 * @return Port descriptor or NULL if not found
107 const port_def_t *hal_port_get_map()
109 return (const port_def_t *)port_definition;