uart: cleanup and bring inline with standard
Removed mraa_setup_uart from core mraa.c moved logic within init function Add more syslog output for easier debugging. Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
@@ -45,14 +45,6 @@ extern mraa_board_t* plat;
|
|||||||
*/
|
*/
|
||||||
mraa_result_t mraa_setup_mux_mapped(mraa_pin_t meta);
|
mraa_result_t mraa_setup_mux_mapped(mraa_pin_t meta);
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup uart muxes to exposes the pins physically.
|
|
||||||
*
|
|
||||||
* @param index of the uart in the board definition to expose physically
|
|
||||||
* @return mraa_result_t of operation
|
|
||||||
*/
|
|
||||||
mraa_result_t mraa_setup_uart(int index);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* runtime detect running x86 platform
|
* runtime detect running x86 platform
|
||||||
*
|
*
|
||||||
|
|||||||
29
src/mraa.c
29
src/mraa.c
@@ -300,35 +300,6 @@ mraa_adc_supported_bits()
|
|||||||
return plat->adc_supported;
|
return plat->adc_supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
mraa_result_t
|
|
||||||
mraa_setup_uart(int index)
|
|
||||||
{
|
|
||||||
if (plat == NULL)
|
|
||||||
return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
|
|
||||||
|
|
||||||
if (plat->uart_dev_count == 0)
|
|
||||||
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
|
|
||||||
|
|
||||||
if (plat->uart_dev_count <= index)
|
|
||||||
return MRAA_ERROR_NO_RESOURCES;
|
|
||||||
|
|
||||||
int pos = plat->uart_dev[index].rx;
|
|
||||||
if (pos >= 0) {
|
|
||||||
if (plat->pins[pos].uart.mux_total > 0)
|
|
||||||
if (mraa_setup_mux_mapped(plat->pins[pos].uart) != MRAA_SUCCESS)
|
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos >= 0) {
|
|
||||||
pos = plat->uart_dev[index].tx;
|
|
||||||
if (plat->pins[pos].uart.mux_total > 0)
|
|
||||||
if (mraa_setup_mux_mapped(plat->pins[pos].uart) != MRAA_SUCCESS)
|
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return MRAA_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
char*
|
char*
|
||||||
mraa_get_platform_name()
|
mraa_get_platform_name()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,15 +33,53 @@
|
|||||||
mraa_uart_context
|
mraa_uart_context
|
||||||
mraa_uart_init(int index)
|
mraa_uart_init(int index)
|
||||||
{
|
{
|
||||||
if (advance_func->uart_init_pre != NULL) {
|
if (plat == NULL) {
|
||||||
if (advance_func->uart_init_pre(index) != MRAA_SUCCESS)
|
syslog(LOG_ERR, "uart: platform not initialised");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mraa_setup_uart(index) != MRAA_SUCCESS)
|
if (advance_func->uart_init_pre != NULL) {
|
||||||
|
if (advance_func->uart_init_pre(index) != MRAA_SUCCESS) {
|
||||||
|
syslog(LOG_ERR, "uart: failure in pre-init platform hook");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plat->uart_dev_count == 0) {
|
||||||
|
syslog(LOG_ERR, "uart: platform has no UARTs defined");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plat->uart_dev_count <= index) {
|
||||||
|
syslog(LOG_ERR, "uart: platform has only %i", plat->uart_dev_count);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = plat->uart_dev[index].rx;
|
||||||
|
if (pos >= 0) {
|
||||||
|
if (plat->pins[pos].uart.mux_total > 0) {
|
||||||
|
if (mraa_setup_mux_mapped(plat->pins[pos].uart) != MRAA_SUCCESS) {
|
||||||
|
syslog(LOG_ERR, "uart: failed to setup muxes for RX pin");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos >= 0) {
|
||||||
|
pos = plat->uart_dev[index].tx;
|
||||||
|
if (plat->pins[pos].uart.mux_total > 0) {
|
||||||
|
if (mraa_setup_mux_mapped(plat->pins[pos].uart) != MRAA_SUCCESS) {
|
||||||
|
syslog(LOG_ERR, "uart: failed to setup muxes for TX pin");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mraa_uart_context dev = (mraa_uart_context) malloc(sizeof(struct _uart));
|
mraa_uart_context dev = (mraa_uart_context) malloc(sizeof(struct _uart));
|
||||||
|
if (dev == NULL) {
|
||||||
|
syslog(LOG_CRIT, "uart: Failed to allocate memory for context");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memset(dev, 0, sizeof(struct _uart));
|
memset(dev, 0, sizeof(struct _uart));
|
||||||
|
|
||||||
dev->index = index;
|
dev->index = index;
|
||||||
|
|||||||
Reference in New Issue
Block a user