]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/hal/_rm48_hdk/port_def.c
61f45219d8d576815481c96b9a3c939052a50313
[pes-rpp/rpp-lib.git] / rpp / src / hal / _rm48_hdk / port_def.c
1 /* Copyright (C) 2012-2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Michal Horn <hornmich@fel.cvut.cz>
5  *
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.
10  *
11  * File : port_def.c
12  *
13  * Abstract:
14  *          This file contains general ports definitions. Ports are defined according to their names on
15  *      the RPP board.
16  *      Each port is define by port descriptor, which consists of:
17  *          - list of its pin (pin descriptors),
18  *          - number of pins,
19  *          - get value function pointer,
20  *          - set value function pointer.
21  *      Finally each port descriptor is mapped to the port name string.
22  *
23  *      Get and set value function are defined for each port style (ADC, SPI, GPIO) in separated files.
24  */
25
26 #include "hal/hal.h"
27 #include "drv/spi.h"
28 #include "drv/_rm48_hdk/adc.h"
29
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
34 };
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
38 };
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
50 };
51 static uint32_t port_cfg_adc[] = { (uint32_t)adcREG1, adcGROUP1, 1 };
52
53 // Port descriptors
54 static port_desc_t port_desc_gioa = {
55  .config = port_cfg_gioa,
56  .numValues = 8,
57  .interfaceType = GPIO,
58  .port_getfnc_ptr = &hal_gpio_port_get_val,
59  .port_setfnc_ptr = &hal_gpio_port_set_val,
60 };
61 static port_desc_t port_desc_giob = {
62  .config = port_cfg_giob,
63  .numValues = 8,
64  .interfaceType = GPIO,
65  .port_getfnc_ptr = &hal_gpio_port_get_val,
66  .port_setfnc_ptr = &hal_gpio_port_set_val,
67 };
68 static port_desc_t port_desc_nhet1 = {
69  .config = port_cfg_nhet1,
70  .numValues = 30,
71  .interfaceType = GPIO,
72  .port_getfnc_ptr = &hal_gpio_port_get_val,
73  .port_setfnc_ptr = &hal_gpio_port_set_val,
74 };
75 static port_desc_t port_desc_adc = {
76  .config = port_cfg_adc,
77  .numValues = 16,
78  .interfaceType = ADC,
79  .port_getfnc_ptr = &adc_get_port_val,
80  .port_setfnc_ptr = ((void *)0),
81 };
82
83
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}
90 };
91
92 /**
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
97  */
98 port_desc_t *hal_port_get_dsc(const char *port_name, int len)
99 {
100         uint32_t i;
101         const char *port_name_ptr;
102         char port_name_term[32];
103
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;
108         }
109         else port_name_ptr = port_name;
110
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;
114         }
115         return NULL;
116 }
117
118 /**
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
123  */
124 const port_def_t *hal_port_get_map()
125 {
126         return (const port_def_t *)port_definition;
127 }