]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blobdiff - rpp/src/hal/_tms570_hdk/port_def.c
Remove indirect port definition and the related macros
[pes-rpp/rpp-lib.git] / rpp / src / hal / _tms570_hdk / port_def.c
index f43826b3bd5d123d19ac462c8699e8a0709b1ccf..aaab689b4618ca79ae49c042a4184d74b494fdfb 100644 (file)
  */
 
 #include "hal/hal.h"
+#include "drv/spi.h"
+#include "drv/_tms570_hdk/adc.h"
 
 // Lists of pins assigned to the ports
-static uint32_t port_cfg_gioa[] = PORT_CFG_GIOA;
-static uint32_t port_cfg_giob[] = PORT_CFG_GIOB;
-static uint32_t port_cfg_nhet1[] = PORT_CFG_NHET1;
-static uint32_t port_cfg_adc[] = PORT_CFG_ADC;
+static uint32_t port_cfg_gioa[] = {
+               PIN_DSC_GIOA0, PIN_DSC_GIOA1, PIN_DSC_GIOA2, PIN_DSC_GIOA3,
+               PIN_DSC_GIOA4, PIN_DSC_GIOA5, PIN_DSC_GIOA6, PIN_DSC_GIOA7
+};
+static uint32_t port_cfg_giob[] = {
+               PIN_DSC_GIOB0, PIN_DSC_GIOB1, PIN_DSC_GIOB2, PIN_DSC_GIOB3,
+               PIN_DSC_GIOB4, PIN_DSC_GIOB5, PIN_DSC_GIOB6, PIN_DSC_GIOB7
+};
+static uint32_t port_cfg_nhet1[] = {
+               PIN_DSC_NHET1_0, PIN_DSC_NHET1_1, PIN_DSC_NHET1_2,
+               PIN_DSC_NHET1_3, PIN_DSC_NHET1_4, PIN_DSC_NHET1_5,
+               PIN_DSC_NHET1_7, PIN_DSC_NHET1_8, PIN_DSC_NHET1_9,
+               PIN_DSC_NHET1_10, PIN_DSC_NHET1_11, PIN_DSC_NHET1_12,
+               PIN_DSC_NHET1_14, PIN_DSC_NHET1_15, PIN_DSC_NHET1_16,
+               PIN_DSC_NHET1_17, PIN_DSC_NHET1_18, PIN_DSC_NHET1_19,
+               PIN_DSC_NHET1_20, PIN_DSC_NHET1_21, PIN_DSC_NHET1_22,
+               PIN_DSC_NHET1_23, PIN_DSC_NHET1_24, PIN_DSC_NHET1_25,
+               PIN_DSC_NHET1_26, PIN_DSC_NHET1_27, PIN_DSC_NHET1_28,
+               PIN_DSC_NHET1_29, PIN_DSC_NHET1_30, PIN_DSC_NHET1_31
+};
+static uint32_t port_cfg_adc[] = { (uint32_t)adcREG1, adcGROUP1, 1 };
 
 // Port descriptors
 static port_desc_t port_desc_gioa = {
      .config = port_cfg_gioa,
      .numValues = PORT_NV_GIOA,
      .interfaceType = PORT_INT_TYPE_GIOA,
      .port_getfnc_ptr = PORT_GFC_GIOA,
      .port_setfnc_ptr = PORT_SFC_GIOA,
+ .config = port_cfg_gioa,
.numValues = 8,
.interfaceType = GPIO,
.port_getfnc_ptr = &hal_gpio_port_get_val,
.port_setfnc_ptr = &hal_gpio_port_set_val,
 };
-
 static port_desc_t port_desc_giob = {
      .config = port_cfg_giob,
      .numValues = PORT_NV_GIOB,
      .interfaceType = PORT_INT_TYPE_GIOB,
      .port_getfnc_ptr = PORT_GFC_GIOB,
      .port_setfnc_ptr = PORT_SFC_GIOB,
+ .config = port_cfg_giob,
.numValues = 8,
.interfaceType = GPIO,
.port_getfnc_ptr = &hal_gpio_port_get_val,
.port_setfnc_ptr = &hal_gpio_port_set_val,
 };
-
 static port_desc_t port_desc_nhet1 = {
      .config = port_cfg_nhet1,
      .numValues = PORT_NV_NHET1,
      .interfaceType = PORT_INT_TYPE_NHET1,
      .port_getfnc_ptr = PORT_GFC_NHET1,
      .port_setfnc_ptr = PORT_SFC_NHET1,
+ .config = port_cfg_nhet1,
.numValues = 30,
.interfaceType = GPIO,
.port_getfnc_ptr = &hal_gpio_port_get_val,
.port_setfnc_ptr = &hal_gpio_port_set_val,
 };
-
 static port_desc_t port_desc_adc = {
      .config = port_cfg_adc,
      .numValues = PORT_NV_ADC,
      .interfaceType = PORT_INT_TYPE_ADC,
      .port_getfnc_ptr = PORT_GFC_ADC,
      .port_setfnc_ptr = PORT_SFC_ADC,
+ .config = port_cfg_adc,
.numValues = 16,
.interfaceType = ADC,
.port_getfnc_ptr = &adc_get_port_val,
.port_setfnc_ptr = ((void *)0),
 };
 
+
 // Maps of port names to port descriptors
 port_def_t port_definition[PORT_CNT] = {
        {.name = PORT_NAME_GIOA,      .desc = &port_desc_gioa},
@@ -71,3 +88,40 @@ port_def_t port_definition[PORT_CNT] = {
        {.name = PORT_NAME_NHET1,    .desc = &port_desc_nhet1},
        {.name = PORT_NAME_ADC,      .desc = &port_desc_adc}
 };
+
+/**
+ *  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)
+{
+       uint32_t i;
+       const char *port_name_ptr;
+       char port_name_term[32];
+
+       if (len != -1) {    // port name not terminated by '\0'
+               strncpy(port_name_term, port_name, len);
+               port_name_term[len] = '\0';
+               port_name_ptr = port_name_term;
+       }
+       else port_name_ptr = port_name;
+
+       for (i = 0; i < PORT_CNT; i++) {
+               if (strcmp(port_name_ptr, port_definition[i].name) == 0)
+                       return port_definition[i].desc;
+       }
+       return NULL;
+}
+
+/**
+ *  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()
+{
+       return (const port_def_t *)port_definition;
+}