From 5af5fd4fb0f3b99f3f6e31863b15dac9c018fc3e Mon Sep 17 00:00:00 2001 From: Michal Horn Date: Thu, 16 Jul 2015 10:59:02 +0200 Subject: [PATCH] Separate target independent code The target dependent code (pin and port definitions) is in the target specific files in rpp/hal/_target directory. The target independent code 9structures and code) has been moved to files in rpp/hal directory. --- rpp/include/hal/_rm48_hdk/port_def.h | 4 --- rpp/include/hal/_tms570_hdk/port_def.h | 4 --- rpp/include/hal/_tms570_hydctr/port_def.h | 4 --- rpp/include/hal/_tms570_rpp/port_def.h | 4 --- rpp/include/hal/port_gpio.h | 18 +++++++++++ rpp/src/hal/_rm48_hdk/port_def.c | 39 +---------------------- rpp/src/hal/_tms570_hdk/port_def.c | 39 +---------------------- rpp/src/hal/_tms570_hydctr/port_def.c | 39 +---------------------- rpp/src/hal/_tms570_rpp/port_def.c | 38 +--------------------- rpp/src/hal/port_gpio.c | 27 ++++++++++++++++ 10 files changed, 49 insertions(+), 167 deletions(-) diff --git a/rpp/include/hal/_rm48_hdk/port_def.h b/rpp/include/hal/_rm48_hdk/port_def.h index 2994f39..5095a19 100644 --- a/rpp/include/hal/_rm48_hdk/port_def.h +++ b/rpp/include/hal/_rm48_hdk/port_def.h @@ -97,8 +97,4 @@ typedef struct port_def_st { #define PORT_SFC_ADC NULL #define PORT_INT_TYPE_ADC PORT_INTERFACE_ADC -port_desc_t *hal_port_get_dsc(const char *port_name, int len); -const port_def_t *hal_port_get_definitions(); - - #endif /* PORT_DEF_H_ */ diff --git a/rpp/include/hal/_tms570_hdk/port_def.h b/rpp/include/hal/_tms570_hdk/port_def.h index 2994f39..5095a19 100644 --- a/rpp/include/hal/_tms570_hdk/port_def.h +++ b/rpp/include/hal/_tms570_hdk/port_def.h @@ -97,8 +97,4 @@ typedef struct port_def_st { #define PORT_SFC_ADC NULL #define PORT_INT_TYPE_ADC PORT_INTERFACE_ADC -port_desc_t *hal_port_get_dsc(const char *port_name, int len); -const port_def_t *hal_port_get_definitions(); - - #endif /* PORT_DEF_H_ */ diff --git a/rpp/include/hal/_tms570_hydctr/port_def.h b/rpp/include/hal/_tms570_hydctr/port_def.h index 2994f39..5095a19 100644 --- a/rpp/include/hal/_tms570_hydctr/port_def.h +++ b/rpp/include/hal/_tms570_hydctr/port_def.h @@ -97,8 +97,4 @@ typedef struct port_def_st { #define PORT_SFC_ADC NULL #define PORT_INT_TYPE_ADC PORT_INTERFACE_ADC -port_desc_t *hal_port_get_dsc(const char *port_name, int len); -const port_def_t *hal_port_get_definitions(); - - #endif /* PORT_DEF_H_ */ diff --git a/rpp/include/hal/_tms570_rpp/port_def.h b/rpp/include/hal/_tms570_rpp/port_def.h index 9c09f64..d11484e 100644 --- a/rpp/include/hal/_tms570_rpp/port_def.h +++ b/rpp/include/hal/_tms570_rpp/port_def.h @@ -168,8 +168,4 @@ extern uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels, uint32 #define PORT_SFC_MOUTIN &hal_gio_port_set_val #define PORT_INT_TYPE_MOUTIN PORT_INTERFACE_GPIO -port_desc_t *hal_port_get_dsc(const char *port_name, int len); -const port_def_t *hal_port_get_definitions(); - - #endif /* PORT_DEF_H_ */ diff --git a/rpp/include/hal/port_gpio.h b/rpp/include/hal/port_gpio.h index a3d5277..f7b0b3e 100644 --- a/rpp/include/hal/port_gpio.h +++ b/rpp/include/hal/port_gpio.h @@ -32,4 +32,22 @@ uint32_t hal_gio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *valu */ uint32_t hal_gio_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_definitions(); + +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); + #endif /* PORT_GPIO_H_ */ diff --git a/rpp/src/hal/_rm48_hdk/port_def.c b/rpp/src/hal/_rm48_hdk/port_def.c index 2da9a43..f43826b 100644 --- a/rpp/src/hal/_rm48_hdk/port_def.c +++ b/rpp/src/hal/_rm48_hdk/port_def.c @@ -65,46 +65,9 @@ static port_desc_t port_desc_adc = { }; // Maps of port names to port descriptors -static port_def_t port_definition[PORT_CNT] = { +port_def_t port_definition[PORT_CNT] = { {.name = PORT_NAME_GIOA, .desc = &port_desc_gioa}, {.name = PORT_NAME_GIOB, .desc = &port_desc_giob}, {.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_definitions() -{ - return (const port_def_t *)port_definition; -} diff --git a/rpp/src/hal/_tms570_hdk/port_def.c b/rpp/src/hal/_tms570_hdk/port_def.c index 2da9a43..f43826b 100644 --- a/rpp/src/hal/_tms570_hdk/port_def.c +++ b/rpp/src/hal/_tms570_hdk/port_def.c @@ -65,46 +65,9 @@ static port_desc_t port_desc_adc = { }; // Maps of port names to port descriptors -static port_def_t port_definition[PORT_CNT] = { +port_def_t port_definition[PORT_CNT] = { {.name = PORT_NAME_GIOA, .desc = &port_desc_gioa}, {.name = PORT_NAME_GIOB, .desc = &port_desc_giob}, {.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_definitions() -{ - return (const port_def_t *)port_definition; -} diff --git a/rpp/src/hal/_tms570_hydctr/port_def.c b/rpp/src/hal/_tms570_hydctr/port_def.c index 2da9a43..f43826b 100644 --- a/rpp/src/hal/_tms570_hydctr/port_def.c +++ b/rpp/src/hal/_tms570_hydctr/port_def.c @@ -65,46 +65,9 @@ static port_desc_t port_desc_adc = { }; // Maps of port names to port descriptors -static port_def_t port_definition[PORT_CNT] = { +port_def_t port_definition[PORT_CNT] = { {.name = PORT_NAME_GIOA, .desc = &port_desc_gioa}, {.name = PORT_NAME_GIOB, .desc = &port_desc_giob}, {.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_definitions() -{ - return (const port_def_t *)port_definition; -} diff --git a/rpp/src/hal/_tms570_rpp/port_def.c b/rpp/src/hal/_tms570_rpp/port_def.c index 37c4ad0..62add29 100644 --- a/rpp/src/hal/_tms570_rpp/port_def.c +++ b/rpp/src/hal/_tms570_rpp/port_def.c @@ -167,7 +167,7 @@ static port_desc_t port_desc_moutin = { }; // Maps of port names to port descriptors -static port_def_t port_definition[PORT_CNT] = { +port_def_t port_definition[PORT_CNT] = { {.name = PORT_NAME_DINMCU, .desc = &port_desc_dinmcu}, {.name = PORT_NAME_DINSPI, .desc = &port_desc_dinspi}, {.name = PORT_NAME_HOUTDIAG, .desc = &port_desc_houtdiag}, @@ -185,39 +185,3 @@ static port_def_t port_definition[PORT_CNT] = { {.name = PORT_NAME_MOUTIN, .desc = &port_desc_moutin} }; -/** - * 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_definitions() -{ - return (const port_def_t *)port_definition; -} diff --git a/rpp/src/hal/port_gpio.c b/rpp/src/hal/port_gpio.c index 71efad2..099e839 100644 --- a/rpp/src/hal/port_gpio.c +++ b/rpp/src/hal/port_gpio.c @@ -16,6 +16,8 @@ #include "hal/hal.h" +extern port_def_t port_definition[PORT_CNT]; + uint32_t hal_gio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values) { uint32_t i; @@ -35,3 +37,28 @@ uint32_t hal_gio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t } return 0; } + +const port_def_t *hal_port_get_definitions() +{ + return (const port_def_t *)port_definition; +} + +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; +} -- 2.39.2