]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/hal/hal.h
30760358a6876ce2e251b7f91f4b509d1eb31bf2
[pes-rpp/rpp-lib.git] / rpp / include / hal / hal.h
1 /**
2  * Hardware Abstraction Layer library interface file.
3  *
4  * @file hal.h
5  *
6  * @copyright Copyright (C) 2013, 2015 Czech Technical University in Prague
7  *
8  * @author Carlos Jenkins <carlos@jenkins.co.cr>
9  */
10
11 #ifndef __HAL_H
12 #define __HAL_H
13
14 #include "sys/sys.h"
15
16 #if defined(TARGET_POSIX)
17 #include "hal/_rm48_hdk/gpio_def.h"
18 #include "hal/_rm48_hdk/port_def.h"
19 #elif defined(TARGET_RM48_HDK)
20 #include "hal/_rm48_hdk/gpio_def.h"
21 #include "hal/_rm48_hdk/port_def.h"
22 #elif defined(TARGET_TMS570_HDK)
23 #include "hal/_tms570_hdk/gpio_def.h"
24 #include "hal/_tms570_hdk/port_def.h"
25 #elif defined(TARGET_TMS570_HYDCTR)
26 #include "hal/_tms570_hydctr/gpio_def.h"
27 #include "hal/_tms570_hydctr/port_def.h"
28 #elif defined(TARGET_TMS570_RPP)
29 #include "hal/_tms570_rpp/gpio_def.h"
30 #include "hal/_tms570_rpp/port_def.h"
31 #else
32 #error No supported target specified!
33 #endif
34
35 uint8_t hal_gpio_get_pin_cnt();
36
37 pin_map_element_t* hal_gpio_get_pin_map();
38
39 /**
40  * Get port base assigned to port number
41  * @param[in]   port_num    Port number <0;4>
42  * @return Pointer to port registers
43  */
44 gioPORT_t *hal_gpio_get_port_base(uint32_t port_num);
45
46 /**
47  * Get port number assigned to pin in its descriptor
48  * @param[in]   pin descriptor
49  * @return  Index of port
50  */
51 uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc);
52
53 /**
54  * Get port base from pin descriptor
55  * Combines two upper defined functions
56  * @param[in]   pin_dcs Pin descriptor
57  * @return      Pointer to port registers
58  */
59 gioPORT_t *hal_gpio_pin_get_port_base(uint32_t pin_dsc);
60
61 /**
62  *  Get pin descriptor assigned to pin name.
63  *  @param[in]  pin_name    Pointer to string - the name of the pin.
64  *  @param[in]  len         Length of the name, if terminated by '/0', then len=-1
65  *  @return Pin descriptor or NULL if not found
66  */
67 uint32_t *hal_gpio_pin_get_dsc(const char *pin_name, int len);
68
69 /**
70  * Get value from GPIO pin
71  * @param[in]   pin_dsc pin descriptor
72  * @return  value read from specified gpio pin
73  */
74 uint32_t hal_gpio_pin_get_value(uint32_t pin_dsc);
75
76 /**
77  * Set value to gpio pin
78  * @param[in]   pin_dsc pin descriptor
79  * @param[in]   value   value to be assigned to the pin
80  */
81 void hal_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value);
82
83 /**
84  * Set pin direction to input
85  * @param[in] pin_dsc pin descriptor
86  * @return always 0
87  */
88 int hal_gpio_pin_set_dir_in(uint32_t pin_dsc);
89
90 /**
91  * Set pin direction to output
92  * @param[in] pin_dsc pin descriptor
93  * @return always 0
94  */
95 int hal_gpio_pin_set_dir_out(uint32_t pin_dsc, uint32_t value);
96
97 /**
98  * Get pin direction
99  * @param[in] pin_dsc pin descriptor
100  * @return 1 - output, 0 - input
101  */
102 int hal_gpio_pin_get_dir(uint32_t pin_dsc);
103
104 /**
105  * Set pin as pull down or pull up and pull resistor enabled or disabled.
106  * @param[in] pin_dsc Descriptor of the pin
107  * @param[in] Mode on which pin will be configured to.
108  *              PORT_CONF_MODE_PU - pull up
109  *              PORT_CONF_MODE_PD - pull down
110  *              must be | with
111  *              PORT_CONF_MODE_PEN - pull resistor enable
112  *              PORT_CONF_MODE_PDIS - pull resistor disable
113  * @return always 0
114  */
115 uint32_t hal_gpio_pin_set_mode(uint32_t pin_dsc, uint32_t mode);
116
117 /**
118  * Configure pin to be open drain or not
119  * @param[in] pin_dsc Descriptor of the pin
120  * @param[in] Mode on which pin will be configured to.
121  *              PORT_CONF_OD_OFF - open-drain disabled
122  *              PORT_CONF_OD_ON - open drain enabled
123  *
124  * @return always 0
125  */
126 uint32_t hal_gpio_pin_set_od(uint32_t pin_dsc, uint32_t od);
127
128 /**
129  * Configure pin
130  * @param[in] pin_dsc Descriptor of the pin
131  * @param[in] Mode on which pin will be configured to.
132  *              PORT_CONF_OD_OFF - open-drain disabled
133  *              PORT_CONF_OD_ON - open drain enabled
134  *
135  *              PORT_CONF_MODE_PU - pull up
136  *              PORT_CONF_MODE_PD - pull down
137  *
138  *              PORT_CONF_MODE_PEN - pull resistor enable
139  *              PORT_CONF_MODE_PDIS - pull resistor disable
140  *
141  *              PORT_CONF_DIR_IN - direction input
142  *              PORT_CONF_DIR_OUT - direction output
143  *
144  *              PORT_CONF_INIT_LOW - init value 0
145  *              PORT_CONF_INIT_HIGH - init value 1
146  *
147  *              PORT_CONF_FNC_GPIO - port function GPIO
148  *              PORT_CONF_FNC_FNCX - port alternate function X
149  *
150  * @return always 0
151  */
152 uint32_t hal_gpio_pin_set_config(uint32_t pin_dsc, uint32_t conf);
153
154 /**
155  * Do the initial pin configuration according values in pin descriptor
156  * @param[in]   pin_dsc pin descriptor
157  * @return always 0;
158  */
159 uint32_t hal_gpio_pin_configure(uint32_t pin_dsc);
160
161 /**
162  * Get values of all pins of given port.
163  * @param[in] config    Pointer to array of pin descriptors
164  * @param[in] num_val   Number of pins assigned to the port
165  * @param[out] values   Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1...
166  * @return always 0
167  */
168 uint32_t hal_gpio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values);
169
170 /**
171  * Set values to all pins of given port.
172  * @param[in] config    Pointer to array of pin descriptors
173  * @param[in] num_val   Number of pins assigned to the port
174  * @param[in] values    Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1...
175  * @return always 0
176  */
177 uint32_t hal_gpio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values);
178
179 /**
180  *  Get port descriptor assigned to port name.
181  *  @param[in]  port_name   Pointer to string - the name of the port.
182  *  @param[in]  len         Length of the name, if terminated by '/0', then len=-1
183  *  @return Port descriptor or NULL if not found
184  */
185 const port_def_t *hal_port_get_map();
186
187 port_desc_t *hal_port_get_dsc(const char *port_name, int len);
188
189 /**
190  *  Get port descriptor assigned to port name.
191  *  @param[in]  port_name   Pointer to string - the name of the port.
192  *  @param[in]  len         Length of the name, if terminated by '/0', then len=-1
193  *  @return Port descriptor or NULL if not found
194  */
195 port_desc_t *hal_port_get_dsc(const char *port_name, int len);
196
197 /**
198  * Transfer command through the spi
199  * @param[in] config    Address of the SPI
200  * @param[in] num_bytes Number of bytes to be trasfered
201  * @param[in] commands  SPI command to be sent
202  * @return spi response
203  */
204 uint32_t hal_spi_port_transfer_command(uint32_t *config, uint32_t num_bytes, const uint32_t *commands);
205
206
207 #endif /* __HAL_H */