]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/hal/_tms570_hdk/port_def.c
Give the HAL functions better names
[pes-rpp/rpp-lib.git] / rpp / src / hal / _tms570_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
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;
33
34 // Port descriptors
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,
41 };
42
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,
49 };
50
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,
57 };
58
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,
65 };
66
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}
73 };
74
75 /**
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
80  */
81 port_desc_t *hal_port_get_dsc(const char *port_name, int len)
82 {
83         uint32_t i;
84         const char *port_name_ptr;
85         char port_name_term[32];
86
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;
91         }
92         else port_name_ptr = port_name;
93
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;
97         }
98         return NULL;
99 }
100
101 /**
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
106  */
107 const port_def_t *hal_port_get_map()
108 {
109         return (const port_def_t *)port_definition;
110 }