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 #include "drv/_rm48_hdk/adc.h"
30 // Lists of pins assigned to the ports
31 static uint32_t port_cfg_gioa[] = {
32 PIN_DSC_GIOA0, PIN_DSC_GIOA1, PIN_DSC_GIOA2, PIN_DSC_GIOA3,
33 PIN_DSC_GIOA4, PIN_DSC_GIOA5, PIN_DSC_GIOA6, PIN_DSC_GIOA7
35 static uint32_t port_cfg_giob[] = {
36 PIN_DSC_GIOB0, PIN_DSC_GIOB1, PIN_DSC_GIOB2, PIN_DSC_GIOB3,
37 PIN_DSC_GIOB4, PIN_DSC_GIOB5, PIN_DSC_GIOB6, PIN_DSC_GIOB7
39 static uint32_t port_cfg_nhet1[] = {
40 PIN_DSC_NHET1_0, PIN_DSC_NHET1_1, PIN_DSC_NHET1_2,
41 PIN_DSC_NHET1_3, PIN_DSC_NHET1_4, PIN_DSC_NHET1_5,
42 PIN_DSC_NHET1_7, PIN_DSC_NHET1_8, PIN_DSC_NHET1_9,
43 PIN_DSC_NHET1_10, PIN_DSC_NHET1_11, PIN_DSC_NHET1_12,
44 PIN_DSC_NHET1_14, PIN_DSC_NHET1_15, PIN_DSC_NHET1_16,
45 PIN_DSC_NHET1_17, PIN_DSC_NHET1_18, PIN_DSC_NHET1_19,
46 PIN_DSC_NHET1_20, PIN_DSC_NHET1_21, PIN_DSC_NHET1_22,
47 PIN_DSC_NHET1_23, PIN_DSC_NHET1_24, PIN_DSC_NHET1_25,
48 PIN_DSC_NHET1_26, PIN_DSC_NHET1_27, PIN_DSC_NHET1_28,
49 PIN_DSC_NHET1_29, PIN_DSC_NHET1_30, PIN_DSC_NHET1_31
51 static uint32_t port_cfg_adc[] = { (uint32_t)adcREG1, adcGROUP1, 1 };
54 static port_desc_t port_desc_gioa = {
55 .config = port_cfg_gioa,
57 .interfaceType = GPIO,
58 .port_getfnc_ptr = &hal_gpio_port_get_val,
59 .port_setfnc_ptr = &hal_gpio_port_set_val,
61 static port_desc_t port_desc_giob = {
62 .config = port_cfg_giob,
64 .interfaceType = GPIO,
65 .port_getfnc_ptr = &hal_gpio_port_get_val,
66 .port_setfnc_ptr = &hal_gpio_port_set_val,
68 static port_desc_t port_desc_nhet1 = {
69 .config = port_cfg_nhet1,
71 .interfaceType = GPIO,
72 .port_getfnc_ptr = &hal_gpio_port_get_val,
73 .port_setfnc_ptr = &hal_gpio_port_set_val,
75 static port_desc_t port_desc_adc = {
76 .config = port_cfg_adc,
79 .port_getfnc_ptr = &adc_get_port_val,
80 .port_setfnc_ptr = ((void *)0),
84 // Maps of port names to port descriptors
85 port_def_t port_definition[PORT_CNT] = {
86 {.name = PORT_NAME_GIOA, .desc = &port_desc_gioa},
87 {.name = PORT_NAME_GIOB, .desc = &port_desc_giob},
88 {.name = PORT_NAME_NHET1, .desc = &port_desc_nhet1},
89 {.name = PORT_NAME_ADC, .desc = &port_desc_adc}
93 * Get port descriptor assigned to port name.
94 * @param[in] port_name Pointer to string - the name of the port.
95 * @param[in] len Length of the name, if terminated by '/0', then len=-1
96 * @return Port descriptor or NULL if not found
98 port_desc_t *hal_port_get_dsc(const char *port_name, int len)
101 const char *port_name_ptr;
102 char port_name_term[32];
104 if (len != -1) { // port name not terminated by '\0'
105 strncpy(port_name_term, port_name, len);
106 port_name_term[len] = '\0';
107 port_name_ptr = port_name_term;
109 else port_name_ptr = port_name;
111 for (i = 0; i < PORT_CNT; i++) {
112 if (strcmp(port_name_ptr, port_definition[i].name) == 0)
113 return port_definition[i].desc;
119 * Get port descriptor assigned to port name.
120 * @param[in] port_name Pointer to string - the name of the port.
121 * @param[in] len Length of the name, if terminated by '/0', then len=-1
122 * @return Port descriptor or NULL if not found
124 const port_def_t *hal_port_get_map()
126 return (const port_def_t *)port_definition;