X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-lib.git/blobdiff_plain/1118eedc25dc262f681b9154ec14236c2dffdfea..cc2ca82b4245bfb8eeecd7585cc7abd16d35ea8d:/rpp/include/hal/hal.h diff --git a/rpp/include/hal/hal.h b/rpp/include/hal/hal.h index 5292d87..3076035 100644 --- a/rpp/include/hal/hal.h +++ b/rpp/include/hal/hal.h @@ -3,7 +3,7 @@ * * @file hal.h * - * @copyright Copyright (C) 2013 Czech Technical University in Prague + * @copyright Copyright (C) 2013, 2015 Czech Technical University in Prague * * @author Carlos Jenkins */ @@ -13,10 +13,195 @@ #include "sys/sys.h" -#include "hal/gpio_rm48_def.h" -#include "hal/gpio_rm48.h" -#include "hal/port_def.h" -#include "hal/port_gpio.h" +#if defined(TARGET_POSIX) +#include "hal/_rm48_hdk/gpio_def.h" +#include "hal/_rm48_hdk/port_def.h" +#elif defined(TARGET_RM48_HDK) +#include "hal/_rm48_hdk/gpio_def.h" +#include "hal/_rm48_hdk/port_def.h" +#elif defined(TARGET_TMS570_HDK) +#include "hal/_tms570_hdk/gpio_def.h" +#include "hal/_tms570_hdk/port_def.h" +#elif defined(TARGET_TMS570_HYDCTR) +#include "hal/_tms570_hydctr/gpio_def.h" +#include "hal/_tms570_hydctr/port_def.h" +#elif defined(TARGET_TMS570_RPP) +#include "hal/_tms570_rpp/gpio_def.h" +#include "hal/_tms570_rpp/port_def.h" +#else +#error No supported target specified! +#endif + +uint8_t hal_gpio_get_pin_cnt(); + +pin_map_element_t* hal_gpio_get_pin_map(); + +/** + * Get port base assigned to port number + * @param[in] port_num Port number <0;4> + * @return Pointer to port registers + */ +gioPORT_t *hal_gpio_get_port_base(uint32_t port_num); + +/** + * Get port number assigned to pin in its descriptor + * @param[in] pin descriptor + * @return Index of port + */ +uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc); + +/** + * Get port base from pin descriptor + * Combines two upper defined functions + * @param[in] pin_dcs Pin descriptor + * @return Pointer to port registers + */ +gioPORT_t *hal_gpio_pin_get_port_base(uint32_t pin_dsc); + +/** + * Get pin descriptor assigned to pin name. + * @param[in] pin_name Pointer to string - the name of the pin. + * @param[in] len Length of the name, if terminated by '/0', then len=-1 + * @return Pin descriptor or NULL if not found + */ +uint32_t *hal_gpio_pin_get_dsc(const char *pin_name, int len); + +/** + * Get value from GPIO pin + * @param[in] pin_dsc pin descriptor + * @return value read from specified gpio pin + */ +uint32_t hal_gpio_pin_get_value(uint32_t pin_dsc); + +/** + * Set value to gpio pin + * @param[in] pin_dsc pin descriptor + * @param[in] value value to be assigned to the pin + */ +void hal_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value); + +/** + * Set pin direction to input + * @param[in] pin_dsc pin descriptor + * @return always 0 + */ +int hal_gpio_pin_set_dir_in(uint32_t pin_dsc); + +/** + * Set pin direction to output + * @param[in] pin_dsc pin descriptor + * @return always 0 + */ +int hal_gpio_pin_set_dir_out(uint32_t pin_dsc, uint32_t value); + +/** + * Get pin direction + * @param[in] pin_dsc pin descriptor + * @return 1 - output, 0 - input + */ +int hal_gpio_pin_get_dir(uint32_t pin_dsc); + +/** + * Set pin as pull down or pull up and pull resistor enabled or disabled. + * @param[in] pin_dsc Descriptor of the pin + * @param[in] Mode on which pin will be configured to. + * PORT_CONF_MODE_PU - pull up + * PORT_CONF_MODE_PD - pull down + * must be | with + * PORT_CONF_MODE_PEN - pull resistor enable + * PORT_CONF_MODE_PDIS - pull resistor disable + * @return always 0 + */ +uint32_t hal_gpio_pin_set_mode(uint32_t pin_dsc, uint32_t mode); + +/** + * Configure pin to be open drain or not + * @param[in] pin_dsc Descriptor of the pin + * @param[in] Mode on which pin will be configured to. + * PORT_CONF_OD_OFF - open-drain disabled + * PORT_CONF_OD_ON - open drain enabled + * + * @return always 0 + */ +uint32_t hal_gpio_pin_set_od(uint32_t pin_dsc, uint32_t od); + +/** + * Configure pin + * @param[in] pin_dsc Descriptor of the pin + * @param[in] Mode on which pin will be configured to. + * PORT_CONF_OD_OFF - open-drain disabled + * PORT_CONF_OD_ON - open drain enabled + * + * PORT_CONF_MODE_PU - pull up + * PORT_CONF_MODE_PD - pull down + * + * PORT_CONF_MODE_PEN - pull resistor enable + * PORT_CONF_MODE_PDIS - pull resistor disable + * + * PORT_CONF_DIR_IN - direction input + * PORT_CONF_DIR_OUT - direction output + * + * PORT_CONF_INIT_LOW - init value 0 + * PORT_CONF_INIT_HIGH - init value 1 + * + * PORT_CONF_FNC_GPIO - port function GPIO + * PORT_CONF_FNC_FNCX - port alternate function X + * + * @return always 0 + */ +uint32_t hal_gpio_pin_set_config(uint32_t pin_dsc, uint32_t conf); + +/** + * Do the initial pin configuration according values in pin descriptor + * @param[in] pin_dsc pin descriptor + * @return always 0; + */ +uint32_t hal_gpio_pin_configure(uint32_t pin_dsc); + +/** + * Get values of all pins of given port. + * @param[in] config Pointer to array of pin descriptors + * @param[in] num_val Number of pins assigned to the port + * @param[out] values Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1... + * @return always 0 + */ +uint32_t hal_gpio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values); + +/** + * Set values to all pins of given port. + * @param[in] config Pointer to array of pin descriptors + * @param[in] num_val Number of pins assigned to the port + * @param[in] values Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1... + * @return always 0 + */ +uint32_t hal_gpio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values); + +/** + * Get port descriptor assigned to port name. + * @param[in] port_name Pointer to string - the name of the port. + * @param[in] len Length of the name, if terminated by '/0', then len=-1 + * @return Port descriptor or NULL if not found + */ +const port_def_t *hal_port_get_map(); + +port_desc_t *hal_port_get_dsc(const char *port_name, int len); + +/** + * Get port descriptor assigned to port name. + * @param[in] port_name Pointer to string - the name of the port. + * @param[in] len Length of the name, if terminated by '/0', then len=-1 + * @return Port descriptor or NULL if not found + */ +port_desc_t *hal_port_get_dsc(const char *port_name, int len); + +/** + * Transfer command through the spi + * @param[in] config Address of the SPI + * @param[in] num_bytes Number of bytes to be trasfered + * @param[in] commands SPI command to be sent + * @return spi response + */ +uint32_t hal_spi_port_transfer_command(uint32_t *config, uint32_t num_bytes, const uint32_t *commands); #endif /* __HAL_H */