From 33853d3637f6833ad1d4bdfdecc9fc32568db9cf Mon Sep 17 00:00:00 2001 From: wangweidong Date: Mon, 10 Oct 2022 10:18:15 +0800 Subject: [PATCH] sync bes hal apis from master Signed-off-by: wangweidong --- platform/gpio/gpio_bes.c | 82 ++++--- platform/i2c/i2c_bes.c | 169 ++++++-------- platform/i2c/i2c_bes.h | 2 + platform/pwm/pwm_bes.c | 23 +- platform/pwm/pwm_bes.h | 2 + platform/spi/spi_bes.c | 323 +++++++++++++++------------ platform/spi/spi_bes.h | 2 + platform/uart/uart_bes.c | 365 +++++++++++++++++++++---------- platform/watchdog/watchdog_bes.c | 4 +- 9 files changed, 577 insertions(+), 395 deletions(-) diff --git a/platform/gpio/gpio_bes.c b/platform/gpio/gpio_bes.c index 6699d51..e255d3e 100644 --- a/platform/gpio/gpio_bes.c +++ b/platform/gpio/gpio_bes.c @@ -69,26 +69,10 @@ typedef int32_t (*oem_gpio_irq_handler_t)(uint16_t gpio, void *data); #define OCTALNUM 8 static struct GpioCntlr g_gpioCntlr; -struct OemGpioIrqHandler { - uint8_t port; - GpioIrqFunc func; - void *arg; -}; enum HAL_GPIO_PIN_T g_gpioPinReflectionMap[HAL_GPIO_PIN_LED_NUM] = {0}; -static struct HAL_GPIO_IRQ_CFG_T g_gpioIrqCfg[HAL_GPIO_PIN_LED_NUM] = {0}; - -static struct HAL_GPIO_IRQ_CFG_T HalGpioGetIrqConfig(enum HAL_GPIO_PIN_T pin) -{ - struct HAL_GPIO_IRQ_CFG_T irqCfg; - irqCfg.irq_enable = g_gpioIrqCfg[pin].irq_enable; - irqCfg.irq_debounce = g_gpioIrqCfg[pin].irq_debounce; - irqCfg.irq_type = g_gpioIrqCfg[pin].irq_type; - irqCfg.irq_polarity = g_gpioIrqCfg[pin].irq_polarity; - - return irqCfg; -} +static struct HAL_GPIO_IRQ_CFG_T g_gpioIrqCfg[HAL_GPIO_PIN_LED_NUM] = {0}; static void OemGpioIrqHdl(enum HAL_GPIO_PIN_T pin) { @@ -216,8 +200,7 @@ static uint32_t GetGpioDeviceResource(struct GpioDevice *device) return HDF_SUCCESS; } #else -static uint32_t GetGpioDeviceResource( - struct GpioDevice *device, const struct DeviceResourceNode *resourceNode) +static uint32_t GetGpioDeviceResource(struct GpioDevice *device, const struct DeviceResourceNode *resourceNode) { uint32_t relPin; int32_t ret; @@ -271,12 +254,10 @@ static uint32_t GetGpioDeviceResource( return HDF_FAILURE; } } - return HDF_SUCCESS; } #endif - static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device) { int32_t ret; @@ -302,12 +283,12 @@ static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObj ret = GetGpioDeviceResource(gpioDevice, device->property); #endif if (ret != HDF_SUCCESS) { - (void)OsalMemFree(gpioDevice); + OsalMemFree(gpioDevice); return HDF_FAILURE; } gpioCntlr->count = gpioDevice->resource.pinNum; - + gpioCntlr->priv = (void *)gpioDevice; return HDF_SUCCESS; } @@ -363,7 +344,8 @@ static void GpioDriverRelease(struct HdfDeviceObject *device) return HDF_DEV_ERR_NO_DEVICE_SERVICE; } - (void)OsalMemFree(gpioCntlr->priv); + gpioCntlr->ops = NULL; + OsalMemFree(gpioCntlr->priv); gpioCntlr->count = 0; } @@ -371,9 +353,13 @@ static void GpioDriverRelease(struct HdfDeviceObject *device) static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val) { (void)cntlr; + if (gpio >= HAL_GPIO_PIN_LED_NUM) { + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio); + return HDF_ERR_NOT_SUPPORT; + } uint16_t halGpio = g_gpioPinReflectionMap[gpio]; if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio); + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio); return HDF_ERR_NOT_SUPPORT; } @@ -386,9 +372,13 @@ static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val { (void)cntlr; uint16_t value; + if (gpio >= HAL_GPIO_PIN_LED_NUM) { + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio); + return HDF_ERR_NOT_SUPPORT; + } uint16_t halGpio = g_gpioPinReflectionMap[gpio]; if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio); + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio); return HDF_ERR_NOT_SUPPORT; } @@ -401,9 +391,13 @@ static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir) { (void)cntlr; + if (gpio >= HAL_GPIO_PIN_LED_NUM) { + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio); + return HDF_ERR_NOT_SUPPORT; + } uint16_t halGpio = g_gpioPinReflectionMap[gpio]; if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio); + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio); return HDF_ERR_NOT_SUPPORT; } @@ -416,9 +410,13 @@ static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *d { (void)cntlr; uint16_t value; + if (gpio >= HAL_GPIO_PIN_LED_NUM) { + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio); + return HDF_ERR_NOT_SUPPORT; + } uint16_t halGpio = g_gpioPinReflectionMap[gpio]; if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, gpio); + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio); return HDF_ERR_NOT_SUPPORT; } @@ -431,9 +429,13 @@ static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *d static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode) { (void)cntlr; + if (gpio >= HAL_GPIO_PIN_LED_NUM) { + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio); + return HDF_ERR_NOT_SUPPORT; + } enum HAL_GPIO_PIN_T pin = (enum HAL_GPIO_PIN_T)g_gpioPinReflectionMap[gpio]; if (pin >= HAL_GPIO_PIN_LED_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, pin); + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, pin); return HDF_ERR_NOT_SUPPORT; } @@ -442,10 +444,16 @@ static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mo } else if ((mode == OSAL_IRQF_TRIGGER_HIGH) || (mode == OSAL_IRQF_TRIGGER_LOW)) { g_gpioIrqCfg[pin].irq_type = HAL_GPIO_IRQ_TYPE_LEVEL_SENSITIVE; } else { - HDF_LOGE("%s %d, error mode:%d", __func__, __LINE__, mode); + HDF_LOGE("%s %d, error mode:%hu", __func__, __LINE__, mode); return HDF_ERR_NOT_SUPPORT; } + if (mode == OSAL_IRQF_TRIGGER_HIGH || mode == OSAL_IRQF_TRIGGER_RISING) { + mode = HAL_GPIO_IRQ_POLARITY_HIGH_RISING; + } else { + mode = HAL_GPIO_IRQ_POLARITY_LOW_FALLING; + } + g_gpioIrqCfg[pin].irq_polarity = mode; return HDF_SUCCESS; @@ -454,6 +462,10 @@ static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mo static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio) { (void)cntlr; + if (gpio >= HAL_GPIO_PIN_LED_NUM) { + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio); + return HDF_ERR_NOT_SUPPORT; + } enum HAL_GPIO_PIN_T pin = (enum HAL_GPIO_PIN_T)g_gpioPinReflectionMap[gpio]; if (pin >= HAL_GPIO_PIN_LED_NUM) { HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, pin); @@ -467,6 +479,10 @@ static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio) { (void)cntlr; struct HAL_GPIO_IRQ_CFG_T gpioCfg; + if (gpio >= HAL_GPIO_PIN_LED_NUM) { + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio); + return HDF_ERR_NOT_SUPPORT; + } uint16_t halGpio = (enum HAL_GPIO_PIN_T)g_gpioPinReflectionMap[gpio]; if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) { HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, (enum HAL_GPIO_PIN_T)halGpio); @@ -490,9 +506,13 @@ static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio) static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio) { (void)cntlr; + if (gpio >= HAL_GPIO_PIN_LED_NUM) { + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio); + return HDF_ERR_NOT_SUPPORT; + } uint16_t halGpio = (enum HAL_GPIO_PIN_T)g_gpioPinReflectionMap[gpio]; if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio); + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio); return HDF_ERR_NOT_SUPPORT; } diff --git a/platform/i2c/i2c_bes.c b/platform/i2c/i2c_bes.c index af822f7..feecca0 100644 --- a/platform/i2c/i2c_bes.c +++ b/platform/i2c/i2c_bes.c @@ -48,25 +48,9 @@ struct I2cMethod g_i2cHostMethod = { .transfer = i2cHostTransfer, }; -int32_t InitI2cDevice(struct I2cDevice *device) +static int32_t I2cDeviceIomuxInit(uint32_t i2cId, struct I2cResource *resource) { - int32_t ret = -1; - uint32_t i2cPort; - struct I2cResource *resource = NULL; - struct HAL_I2C_CONFIG_T *i2cConfig = NULL; - if (device == NULL) { - HDF_LOGE("device is NULL\r\n"); - return HDF_ERR_INVALID_PARAM; - } - - resource = &device->resource; - if (resource == NULL) { - HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); - return HDF_ERR_INVALID_PARAM; - } - - i2cConfig = &device->i2cCfg; - if (i2cConfig == NULL) { + if (i2cId > HAL_I2C_ID_NUM || resource == NULL) { HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } @@ -76,63 +60,52 @@ int32_t InitI2cDevice(struct I2cDevice *device) {0, 0, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}, }; - device->port = resource->port; - i2cPort = device->port; - if (i2cPort > HAL_I2C_ID_NUM) { - HDF_LOGE("i2c port %u not support\r\n", i2cPort); - return HDF_ERR_NOT_SUPPORT; - } - - if (i2cPort == 0) { +#ifdef LOSCFG_SOC_SERIES_BES2600 + if (i2cId == 0) { pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M0_SCL; pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M0_SDA; } else { pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M1_SCL; pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M1_SDA; } - - if (OsalMutexInit(&device->mutex) != HDF_SUCCESS) { - HDF_LOGE("%s %d OsalMutexInit fail\r\n", __func__, __LINE__); - return HDF_FAILURE; - } - - if (HDF_SUCCESS != OsalMutexLock(&device->mutex)) { - HDF_LOGE("%s %d osMutexWait fail\r\n", __func__, __LINE__); - return HDF_ERR_TIMEOUT; +#elif defined (LOSCFG_SOC_SERIES_BES2700) + if (i2cId == 0) { + pinMuxI2c[0].function = HAL_IOMUX_FUNC_SYS_I2C_M0_SCL; + pinMuxI2c[1].function = HAL_IOMUX_FUNC_SYS_I2C_M0_SDA; + } else { + pinMuxI2c[0].function = HAL_IOMUX_FUNC_SYS_I2C_M1_SCL; + pinMuxI2c[1].function = HAL_IOMUX_FUNC_SYS_I2C_M1_SDA; } - +#endif pinMuxI2c[0].pin = resource->sclPin; pinMuxI2c[1].pin = resource->sdaPin; hal_iomux_init(pinMuxI2c, ARRAY_SIZE(pinMuxI2c)); - - ret = hal_i2c_open(i2cPort, i2cConfig); - if (ret == HDF_SUCCESS) { - HDF_LOGD("open %u i2c succ.\r\n", i2cPort); - } - OsalMutexUnlock(&device->mutex); - return ret; + return HDF_SUCCESS; } -static int32_t HostRestI2cDevice(struct I2cDevice *device) +int32_t InitI2cDevice(struct I2cDevice *device) { - int32_t ret = -1; + int32_t ret; + uint32_t i2cPort; struct I2cResource *resource = NULL; struct HAL_I2C_CONFIG_T *i2cConfig = NULL; - uint32_t i2cPort; if (device == NULL) { - HDF_LOGE("%s %d device is null\r\n", __func__, __LINE__); + HDF_LOGE("%s %d:device is NULL\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } + resource = &device->resource; if (resource == NULL) { HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); - return HDF_ERR_INVALID_OBJECT; + return HDF_ERR_INVALID_PARAM; } + i2cConfig = &device->i2cCfg; if (i2cConfig == NULL) { HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); - return HDF_ERR_INVALID_OBJECT; + return HDF_ERR_INVALID_PARAM; } + device->port = resource->port; i2cPort = device->port; if (i2cPort > HAL_I2C_ID_NUM) { @@ -140,59 +113,66 @@ static int32_t HostRestI2cDevice(struct I2cDevice *device) return HDF_ERR_NOT_SUPPORT; } - hal_i2c_close(i2cPort); + if (OsalMutexInit(&device->mutex) != HDF_SUCCESS) { + HDF_LOGE("%s %d OsalMutexInit fail\r\n", __func__, __LINE__); + return HDF_FAILURE; + } + + if (OsalMutexLock(&device->mutex) != HDF_SUCCESS) { + HDF_LOGE("%s %d osMutexWait fail\r\n", __func__, __LINE__); + return HDF_ERR_TIMEOUT; + } + + ret = I2cDeviceIomuxInit(i2cPort, resource); + if (ret != HDF_SUCCESS) { + HDF_LOGD("I2C iomux init failed.\r\n"); + OsalMutexUnlock(&device->mutex); + return ret; + } + ret = hal_i2c_open(i2cPort, i2cConfig); if (ret == HDF_SUCCESS) { HDF_LOGD("open %u i2c succ.\r\n", i2cPort); } + OsalMutexUnlock(&device->mutex); return ret; } -#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO -#define I2C_FIND_CONFIG(node, name, resource) \ - do { \ - if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \ - resource->port = HCS_PROP(node, port); \ - tempPin = HCS_PROP(node, sclPin); \ - resource->sclPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \ - tempPin = HCS_PROP(node, sdaPin); \ - resource->sdaPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \ - resource->speed = HCS_PROP(node, speed); \ - resource->mode = HCS_PROP(node, mode); \ - resource->useDma = HCS_PROP(node, useDma); \ - resource->useSync = HCS_PROP(node, useSync); \ - resource->asMaster = HCS_PROP(node, asMaster); \ - break; \ - } \ - } while (0) - -#define PLATFORM_I2C_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), i2c_config) -static uint32_t GetI2cDeviceResource(struct I2cDevice *device, - const char *deviceMatchAttr) + +static int32_t GetI2cDeviceIomuxConfig(struct I2cResource *resource, const struct DeviceResourceNode *resourceNode) { - uint32_t tempPin = 0; - struct I2cResource *resource = NULL; - if (device == NULL) { - HDF_LOGE("device or resourceNode is NULL\r\n"); + struct DeviceResourceIface *dri = NULL; + if (resource == NULL || resourceNode == NULL) { + HDF_LOGE("%s %d:resource or resourceNode is NULL\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } - resource = &device->resource; - if (resource == NULL) { - HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); + + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid\r\n"); return HDF_ERR_INVALID_OBJECT; } - HCS_FOREACH_CHILD_VARGS(PLATFORM_I2C_CONFIG, I2C_FIND_CONFIG, deviceMatchAttr, resource); + if (dri->GetUint32(resourceNode, "sclPin", &resource->sclPin, 0) != HDF_SUCCESS) { + HDF_LOGE("i2c config sclPin fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "sdaPin", &resource->sdaPin, 0) != HDF_SUCCESS) { + HDF_LOGE("i2c config sdaPin fail\r\n"); + return HDF_FAILURE; + } + resource->sclPin = ((resource->sclPin / DEC_NUM) * GROUP_PIN_NUM) + (resource->sclPin % DEC_NUM); + + resource->sdaPin = ((resource->sdaPin / DEC_NUM) * GROUP_PIN_NUM) + (resource->sdaPin % DEC_NUM); return HDF_SUCCESS; } -#else -static uint32_t GetI2cDeviceResource(struct I2cDevice *device, - const struct DeviceResourceNode *resourceNode) + +static int32_t GetI2cDeviceResource(struct I2cDevice *device, const struct DeviceResourceNode *resourceNode) { - uint32_t tempPin = 0; struct I2cResource *resource = NULL; struct DeviceResourceIface *dri = NULL; if (device == NULL || resourceNode == NULL) { - HDF_LOGE("device or resourceNode is NULL\r\n"); + HDF_LOGE("%s %d:device or resourceNode is NULL\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } resource = &device->resource; @@ -211,18 +191,6 @@ static uint32_t GetI2cDeviceResource(struct I2cDevice *device, return HDF_FAILURE; } - if (dri->GetUint32(resourceNode, "sclPin", &tempPin, 0) != HDF_SUCCESS) { - HDF_LOGE("i2c config sclPin fail\r\n"); - return HDF_FAILURE; - } - resource->sclPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); - - if (dri->GetUint32(resourceNode, "sdaPin", &tempPin, 0) != HDF_SUCCESS) { - HDF_LOGE("i2c config sdaPin fail\r\n"); - return HDF_FAILURE; - } - resource->sdaPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); - if (dri->GetUint32(resourceNode, "speed", &resource->speed, 0) != HDF_SUCCESS) { HDF_LOGE("i2c config speed fail\r\n"); return HDF_FAILURE; @@ -247,9 +215,10 @@ static uint32_t GetI2cDeviceResource(struct I2cDevice *device, HDF_LOGE("i2c config asMaster fail\r\n"); return HDF_FAILURE; } - return HDF_SUCCESS; + + return GetI2cDeviceIomuxConfig(resource, resourceNode); } -#endif + static int32_t AttachI2cDevice(struct I2cCntlr *host, struct HdfDeviceObject *device) { int32_t ret; @@ -278,11 +247,13 @@ static int32_t AttachI2cDevice(struct I2cCntlr *host, struct HdfDeviceObject *de resource = &i2cDevice->resource; if (resource == NULL) { HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); + OsalMemFree(i2cDevice); return HDF_ERR_INVALID_OBJECT; } i2cConfig = &i2cDevice->i2cCfg; if (i2cConfig == NULL) { HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); + OsalMemFree(i2cDevice); return HDF_ERR_INVALID_OBJECT; } i2cDevice->port = resource->port; @@ -320,12 +291,10 @@ static int32_t i2cDriverInit(struct HdfDeviceObject *device) ret = AttachI2cDevice(host, device); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: attach error\r\n", __func__); - i2cDriverRelease(device); return HDF_DEV_ERR_ATTACHDEV_FAIL; } ret = I2cCntlrAdd(host); if (ret != HDF_SUCCESS) { - i2cDriverRelease(device); return HDF_FAILURE; } return ret; diff --git a/platform/i2c/i2c_bes.h b/platform/i2c/i2c_bes.h index aa62df7..404e8ff 100644 --- a/platform/i2c/i2c_bes.h +++ b/platform/i2c/i2c_bes.h @@ -11,7 +11,9 @@ #include "hal_i2c.h" #include "hal_iomux.h" +#ifdef CHIP_BEST2003 #include "hal_iomux_best2003.h" +#endif #include "device_resource_if.h" #include "osal_mutex.h" #ifdef __cplusplus diff --git a/platform/pwm/pwm_bes.c b/platform/pwm/pwm_bes.c index 31348f8..1efc069 100644 --- a/platform/pwm/pwm_bes.c +++ b/platform/pwm/pwm_bes.c @@ -12,7 +12,6 @@ #include "hdf_device_desc.h" #include "hal_trace.h" #include "hal_timer.h" -#include "hal_iomux.h" #include "pwm_core.h" #include "hdf_log.h" #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO @@ -22,7 +21,13 @@ #include "device_resource_if.h" #endif +#if defined (LOSCFG_SOC_SERIES_BES2700) +#define PWM_MAX_FUNCTION 4 +#elif defined (LOSCFG_SOC_SERIES_BES2600) +#include "hal_iomux.h" #define PWM_MAX_FUNCTION 8 +#endif + #define UNTIL_NAN0SECONDS 1000000000 #define PERCENT 100 #define DEC_TEN 10 @@ -33,10 +38,12 @@ static uint32_t g_pwmFunction[PWM_MAX_FUNCTION] = { HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_PWM2, HAL_IOMUX_FUNC_PWM3, +#if defined (LOSCFG_SOC_SERIES_BES2600) HAL_IOMUX_FUNC_PWM4, HAL_IOMUX_FUNC_PWM5, HAL_IOMUX_FUNC_PWM6, HAL_IOMUX_FUNC_PWM7, +#endif }; static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config); @@ -54,7 +61,7 @@ static int InitPwmDevice(struct PwmDev *host) struct PwmDevice *pwmDevice = NULL; struct PwmResource *resource = NULL; if (host == NULL || host->priv == NULL) { - HDF_LOGE("%s: invaild parameter\r\n", __func__); + HDF_LOGE("%s: invalid parameter\r\n", __func__); return HDF_ERR_INVALID_PARAM; } pwmDevice = (struct PwmDevice *)host->priv; @@ -81,13 +88,7 @@ static int InitPwmDevice(struct PwmDev *host) return HDF_SUCCESS; } -#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO -static uint32_t GetPwmDeviceResource(struct PwmDevice *device) -{ -} -#else -static uint32_t GetPwmDeviceResource( - struct PwmDevice *device, const struct DeviceResourceNode *resourceNode) +static uint32_t GetPwmDeviceResource(struct PwmDevice *device, const struct DeviceResourceNode *resourceNode) { uint32_t tempPin = 0; struct DeviceResourceIface *dri = NULL; @@ -122,7 +123,7 @@ static uint32_t GetPwmDeviceResource( return HDF_SUCCESS; } -#endif + static int32_t AttachPwmDevice(struct PwmDev *host, struct HdfDeviceObject *device) { int32_t ret; @@ -142,7 +143,7 @@ static int32_t AttachPwmDevice(struct PwmDev *host, struct HdfDeviceObject *devi return HDF_ERR_MALLOC_FAIL; } #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO - ret = GetPwmDeviceResource(pwmDevice); + ret = GetPwmDeviceResource(pwmDevice, device->deviceMatchAttr); #else ret = GetPwmDeviceResource(pwmDevice, device->property); #endif diff --git a/platform/pwm/pwm_bes.h b/platform/pwm/pwm_bes.h index fedef7e..98af98e 100644 --- a/platform/pwm/pwm_bes.h +++ b/platform/pwm/pwm_bes.h @@ -11,7 +11,9 @@ #include "hal_pwm.h" #include "hal_gpio.h" +#ifdef CHIP_BEST2003 #include "hal_iomux.h" +#endif #include "pwm_core.h" #ifdef __cplusplus diff --git a/platform/spi/spi_bes.c b/platform/spi/spi_bes.c index e027e71..13e3949 100644 --- a/platform/spi/spi_bes.c +++ b/platform/spi/spi_bes.c @@ -37,10 +37,17 @@ static void Spi1DmaIrq(int error); static struct SPI_CTX_OBJ_T spiCtx[MAX_SPI_NUMBER] = { { .spiPinCS0 = 0, +#if defined (LOSCFG_SOC_SERIES_BES2700) + .spiFunDI0 = HAL_IOMUX_FUNC_SYS_SPI_DI0, + .spiFunCLK = HAL_IOMUX_FUNC_SYS_SPI_CLK, + .spiFunCS0 = HAL_IOMUX_FUNC_SYS_SPI_CS0, + .spiFunDIO = HAL_IOMUX_FUNC_SYS_SPI_DIO, +#elif defined (LOSCFG_SOC_SERIES_BES2600) .spiFunDI0 = HAL_IOMUX_FUNC_SPI_DI0, .spiFunCLK = HAL_IOMUX_FUNC_SPI_CLK, .spiFunCS0 = HAL_IOMUX_FUNC_SPI_CS0, .spiFunDIO = HAL_IOMUX_FUNC_SPI_DIO, +#endif .sem = { NULL }, .mutex = { NULL }, .SpiOpen = hal_spi_open, @@ -53,10 +60,17 @@ static struct SPI_CTX_OBJ_T spiCtx[MAX_SPI_NUMBER] = { }, { .spiPinCS0 = 0, +#if defined (LOSCFG_SOC_SERIES_BES2700) + .spiFunDI0 = HAL_IOMUX_FUNC_SYS_SPILCD_DI0, + .spiFunCLK = HAL_IOMUX_FUNC_SYS_SPILCD_CLK, + .spiFunCS0 = HAL_IOMUX_FUNC_SYS_SPILCD_CS0, + .spiFunDIO = HAL_IOMUX_FUNC_SYS_SPILCD_DIO, +#elif defined (LOSCFG_SOC_SERIES_BES2600) .spiFunDI0 = HAL_IOMUX_FUNC_SPILCD_DI0, .spiFunCLK = HAL_IOMUX_FUNC_SPILCD_CLK, .spiFunCS0 = HAL_IOMUX_FUNC_SPILCD_CS0, .spiFunDIO = HAL_IOMUX_FUNC_SPILCD_DIO, +#endif .sem = { NULL }, .mutex = { NULL }, .SpiOpen = hal_spilcd_open, @@ -100,19 +114,19 @@ static void SpiIomuxInit(struct SpiDevice *spiDevice) HDF_LOGI("%s: Enter\r\n", __func__); if (spiDevice == NULL) { - HDF_LOGE("%s: invalid parameter\r\n", __func__); + HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); return; } resource = &spiDevice->resource; if (resource == NULL) { - HDF_LOGE("resource is null\r\n"); - return HDF_ERR_INVALID_OBJECT; + HDF_LOGE("%s %d:resource is null\r\n", __func__, __LINE__); + return; } spiDevCfg = &spiDevice->spiDevCfg; if (spiDevCfg == NULL) { - HDF_LOGE("resource is null\r\n"); - return HDF_ERR_INVALID_OBJECT; + HDF_LOGE("%s %d:spiconfig is null\r\n", __func__, __LINE__); + return; } spiDevCfg->rate = resource->speed; @@ -135,14 +149,55 @@ static void SpiIomuxInit(struct SpiDevice *spiDevice) pinMuxSpi[SPI_PIN_2].function = spiCtx[spiPort].spiFunCS0; pinMuxSpi[SPI_PIN_3].function = spiCtx[spiPort].spiFunDIO; - if (spiDevCfg->rate > MAX_SPI_SPEED) { - hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_1].pin, DRIVER_LEVEL); - hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_3].pin, DRIVER_LEVEL); - } + hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_0].pin, DRIVER_LEVEL); + hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_1].pin, DRIVER_LEVEL); + hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_2].pin, DRIVER_LEVEL); + hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_3].pin, DRIVER_LEVEL); hal_iomux_init(pinMuxSpi, ARRAY_SIZE(pinMuxSpi)); } +static int32_t SpiDevCfgInit(struct HAL_SPI_CFG_T *spiDevCfg, struct SpiResource *resource) +{ + if (spiDevCfg == NULL || resource == NULL) { + HDF_LOGE("%s %d:invalid parameter error\r\n", __func__, __LINE__); + return HDF_ERR_INVALID_PARAM; + } + switch (resource->mode) { + case SPI_WORK_MODE_0: + spiDevCfg->clk_delay_half = false; + spiDevCfg->clk_polarity = false; + break; + case SPI_WORK_MODE_1: + spiDevCfg->clk_delay_half = true; + spiDevCfg->clk_polarity = false; + break; + case SPI_WORK_MODE_2: + spiDevCfg->clk_delay_half = false; + spiDevCfg->clk_polarity = true; + break; + case SPI_WORK_MODE_3: + spiDevCfg->clk_delay_half = true; + spiDevCfg->clk_polarity = true; + break; + default: + spiDevCfg->clk_delay_half = true; + spiDevCfg->clk_polarity = true; + } + spiDevCfg->slave = 0; + if (resource->transmode == SPI_TRANSFER_DMA) { + spiDevCfg->dma_rx = true; + spiDevCfg->dma_tx = true; + } else { + spiDevCfg->dma_rx = false; + spiDevCfg->dma_tx = false; + } + spiDevCfg->cs = 0; + spiDevCfg->rx_bits = resource->dataSize; + spiDevCfg->tx_bits = resource->dataSize; + spiDevCfg->rx_frame_bits = 0; + return HDF_SUCCESS; +} /** * Spi send * @@ -160,14 +215,14 @@ static void SpiIomuxInit(struct SpiDevice *spiDevice) #endif int32_t HalSpiSend(struct SpiDevice *spiDevice, const uint8_t *data, uint16_t size, uint32_t timeOut) { - int32_t ret = 0; + int32_t ret; uint32_t spiId; uint32_t len = size; struct SpiResource *resource = NULL; int32_t status = HDF_FAILURE; if (spiDevice == NULL || data == NULL || size == 0) { - HDF_LOGE("spi input para err\r\n"); + HDF_LOGE("%s %d:invalid parameter error\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } @@ -182,7 +237,9 @@ int32_t HalSpiSend(struct SpiDevice *spiDevice, const uint8_t *data, uint16_t si HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); return HDF_ERR_TIMEOUT; } - +#ifdef LOSCFG_SOC_SERIES_BES2700 + hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); +#endif if (resource->transmode == SPI_TRANSFER_DMA) { ret = spiCtx[spiId].SpiDmaSend(data, len, spiCtx[spiId].SpiDmaIrq); if (OsalSemWait(&spiCtx[spiId].sem, timeOut) != HDF_SUCCESS) { @@ -193,8 +250,8 @@ int32_t HalSpiSend(struct SpiDevice *spiDevice, const uint8_t *data, uint16_t si ret = spiCtx[spiId].SpiSend(data, len); } - if (ret) { - HDF_LOGE("spi tail send fail %ld, size %ld\r\n", ret, len); + if (ret != 0) { + HDF_LOGE("spi tail send fail %d, size %u\r\n", ret, len); goto OUT; } OUT: @@ -217,17 +274,17 @@ OUT: * * @return 0 : on success, EIO : if the SPI device could not be initialised */ -int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, uint32_t timeOut) +static int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, uint32_t timeOut) { - int32_t ret = 0; - uint32_t len = size; - uint32_t remainder = 0; + int32_t ret; + int32_t len = (int32_t)size; + uint32_t remainder; int32_t status = HDF_FAILURE; uint8_t *cmd = NULL; uint32_t spiId; struct SpiResource *resource = NULL; if (spiDevice == NULL || data == NULL || size == 0) { - HDF_LOGE("spi input para err\r\n"); + HDF_LOGE("%s %d:invalid parameter error\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } @@ -237,70 +294,68 @@ int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, ui HDF_LOGE("resource is null\r\n"); return HDF_ERR_INVALID_OBJECT; } - cmd = (uint8_t *)OsalMemAlloc(len); - if (cmd == NULL) { - HDF_LOGE("%s OsalMemAlloc size %ld error\r\n", __FUNCTION__, len); - return HDF_ERR_MALLOC_FAIL; - } - - memset_s(cmd, len, 0, len); + cmd = (uint8_t *)0x20020000; // 0x20020000 : non secure sram base. tx buf is useless, use sram instead of malloc. status = OsalMutexLock(&spiCtx[spiId].mutex); - if (HDF_SUCCESS != status) { + if (status != HDF_SUCCESS) { HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); - OsalMemFree(cmd); return HDF_ERR_TIMEOUT; } - remainder = len <= SPI_DMA_MAX ? len : SPI_DMA_MAX; - - if (resource->transmode == SPI_TRANSFER_DMA) { - ret = spiCtx[spiId].SpiDmaRecv(cmd, data, remainder, spiCtx[spiId].SpiDmaIrq); - if (OsalSemWait(&spiCtx[spiId].sem, timeOut) <= 0) { - HDF_LOGE("SPI Read timeOut!\r\n"); - goto OUT; +#ifdef LOSCFG_SOC_SERIES_BES2700 + hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); +#endif + do { + remainder = len <= SPI_DMA_MAX ? len : SPI_DMA_MAX; + if (resource->transmode == SPI_TRANSFER_DMA) { + ret = spiCtx[spiId].SpiDmaRecv(cmd, data, remainder, spiCtx[spiId].SpiDmaIrq); + if (OsalSemWait(&spiCtx[spiId].sem, timeOut) <= 0) { + HDF_LOGE("SPI Read timeOut!\r\n"); + goto OUT; + } + } else { + ret = spiCtx[spiId].SpiRecv(cmd, data, remainder); } - } else { - ret = spiCtx[spiId].SpiRecv(cmd, data, remainder); - } - len -= remainder; - data += remainder; + len -= remainder; + data += remainder; - if (ret) { - HDF_LOGE("spi tail fail %ld, size %ld\r\n", ret, len); - goto OUT; - } + if (ret != 0) { + HDF_LOGE("spi tail fail %ld, size %ld\r\n", ret, len); + goto OUT; + } + } while (len); OUT: OsalMutexUnlock(&spiCtx[spiId].mutex); - OsalMemFree(cmd); return ret; } #ifdef HalSpiSendRecv #undef HalSpiSendRecv #endif -int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t txSize, uint8_t *rxData, - uint16_t rxSize, uint32_t timeOut) +static int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t txSize, uint8_t *rxData, + uint16_t rxSize) { int32_t ret; int32_t status; uint32_t spiId; struct SpiResource *resource = NULL; if (spiDevice == NULL || txData == NULL || txSize == 0 || rxData == NULL || rxSize == 0) { - HDF_LOGE("spi input para err\r\n"); + HDF_LOGE("%s %d:invalid parameter error\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } spiId = spiDevice->spiId; resource = &spiDevice->resource; status = OsalMutexLock(&spiCtx[spiId].mutex); if (HDF_SUCCESS != status) { - HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); + HDF_LOGE("%s OsalMutexLock error = 0x%X!\r\n", __func__, status); return HDF_ERR_TIMEOUT; } - +#ifdef LOSCFG_SOC_SERIES_BES2700 + hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); +#endif if (resource->transmode == SPI_TRANSFER_DMA) { ret = spiCtx[spiId].SpiDmaRecv(txData, rxData, rxSize, spiCtx[spiId].SpiDmaIrq); - if (OsalSemWait(&spiCtx[spiId].sem, timeOut) <= 0) { + if (OsalSemWait(&spiCtx[spiId].sem, TIMEOUT) <= 0) { HDF_LOGE("%s:SPI Read timeOut!\r\n", __func__); goto OUT; } @@ -309,7 +364,6 @@ int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t tx } if (ret) { HDF_LOGE("spi dma tail fail %d\r\n", ret); - goto OUT; } OUT: OsalMutexUnlock(&spiCtx[spiId].mutex); @@ -319,10 +373,11 @@ OUT: static int32_t InitSpiDevice(struct SpiDevice *spiDevice) { uint32_t spiPort; + int32_t ret; struct HAL_SPI_CFG_T *spiDevCfg = NULL; struct SpiResource *resource = NULL; if (spiDevice == NULL) { - HDF_LOGE("%s: invalid parameter\r\n", __func__); + HDF_LOGE("%s %d:invalid parameter error\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } @@ -331,40 +386,11 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice) spiPort = spiDevice->spiId; SpiIomuxInit(spiDevice); - - switch (resource->mode) { - case SPI_WORK_MODE_0: - spiDevCfg->clk_delay_half = false; - spiDevCfg->clk_polarity = false; - break; - case SPI_WORK_MODE_1: - spiDevCfg->clk_delay_half = true; - spiDevCfg->clk_polarity = false; - break; - case SPI_WORK_MODE_2: - spiDevCfg->clk_delay_half = false; - spiDevCfg->clk_polarity = true; - break; - case SPI_WORK_MODE_3: - spiDevCfg->clk_delay_half = true; - spiDevCfg->clk_polarity = true; - break; - default: - spiDevCfg->clk_delay_half = true; - spiDevCfg->clk_polarity = true; - } - spiDevCfg->slave = 0; - if (resource->transmode == SPI_TRANSFER_DMA) { - spiDevCfg->dma_rx = true; - spiDevCfg->dma_tx = true; - } else { - spiDevCfg->dma_rx = false; - spiDevCfg->dma_tx = false; + ret = SpiDevCfgInit(spiDevCfg, resource); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: SPI config init failed\r\n", __func__); + return HDF_FAILURE; } - spiDevCfg->cs = 0; - spiDevCfg->rx_bits = resource->dataSize; - spiDevCfg->tx_bits = resource->dataSize; - spiDevCfg->rx_frame_bits = 0; /* spi open move to hdf open api */ /* if cs use as gpio ,pull up at first */ if (spiCtx[spiPort].spiFunCS0 == HAL_IOMUX_FUNC_AS_GPIO) { @@ -388,25 +414,47 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice) } /* get spi config from hcs file */ -#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO -static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice) +static int32_t GetSpiDeviceIomuxConfig(struct SpiResource *resource, const struct DeviceResourceNode *resourceNode) { + struct DeviceResourceIface *dri = NULL; + if (resource == NULL || resourceNode == NULL) { + HDF_LOGE("%s %d:invalid parameter error\r\n", __func__, __LINE__); + return HDF_ERR_INVALID_PARAM; + } + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); // open HDF + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid\r\n"); + return HDF_ERR_INVALID_PARAM; + } + if (dri->GetUint32(resourceNode, "spiClkPin", &resource->spiClkPin, 0) != HDF_SUCCESS) { + HDF_LOGE("spi config read spiClkPin fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "spiMosiPin", &resource->spiMosiPin, 0) != HDF_SUCCESS) { + HDF_LOGE("spi config read spiMosiPin fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "spiMisoPin", &resource->spiMisoPin, 0) != HDF_SUCCESS) { + HDF_LOGE("spi config read spiMisoPin fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "spiCsPin", &resource->spiCsPin, 0) != HDF_SUCCESS) { + HDF_LOGE("spi config read spiCsPin fail\r\n"); + return HDF_FAILURE; + } + return HDF_SUCCESS; } -#else -static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct DeviceResourceNode *resourceNode) + +static int32_t GetSpiDeviceConfig(struct SpiResource *resource, const struct DeviceResourceNode *resourceNode) { - uint32_t relPin; - struct SpiResource *resource = NULL; struct DeviceResourceIface *dri = NULL; - if (spiDevice == NULL || resourceNode == NULL) { - HDF_LOGE("%s: PARAM is NULL\r\n", __func__); + if (resource == NULL || resourceNode == NULL) { + HDF_LOGE("%s %d:invalid parameter error\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } - resource = &spiDevice->resource; - if (resource == NULL) { - HDF_LOGE("%s: resource is NULL\r\n", __func__); - return HDF_ERR_INVALID_OBJECT; - } dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); // open HDF if (dri == NULL || dri->GetUint32 == NULL) { HDF_LOGE("DeviceResourceIface is invalid\r\n"); @@ -418,7 +466,6 @@ static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct De return HDF_FAILURE; } - spiDevice->spiId = resource->num; if (dri->GetUint32(resourceNode, "speed", &resource->speed, 0) != HDF_SUCCESS) { HDF_LOGE("spi config read base fail\r\n"); return HDF_FAILURE; @@ -449,40 +496,40 @@ static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct De return HDF_FAILURE; } - if (dri->GetUint32(resourceNode, "spiClkPin", &resource->spiClkPin, 0) != HDF_SUCCESS) { - HDF_LOGE("spi config read spiClkPin fail\r\n"); - return HDF_FAILURE; - } - - relPin = (resource->spiClkPin / DEC_NUM) * GROUP_PIN_NUM + (resource->spiClkPin % DEC_NUM); - resource->spiClkPin = relPin; + return GetSpiDeviceIomuxConfig(resource, resourceNode); +} - if (dri->GetUint32(resourceNode, "spiMosiPin", &resource->spiMosiPin, 0) != HDF_SUCCESS) { - HDF_LOGE("spi config read spiMosiPin fail\r\n"); - return HDF_FAILURE; +static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct DeviceResourceNode *resourceNode) +{ + struct SpiResource *resource = NULL; + int32_t ret; + if (spiDevice == NULL || resourceNode == NULL) { + HDF_LOGE("%s %d:invalid parameter error\r\n", __func__, __LINE__); + return HDF_ERR_INVALID_PARAM; } - - relPin = (resource->spiMosiPin / DEC_NUM) * GROUP_PIN_NUM + (resource->spiMosiPin % DEC_NUM); - resource->spiMosiPin = relPin; - if (dri->GetUint32(resourceNode, "spiMisoPin", &resource->spiMisoPin, 0) != HDF_SUCCESS) { - HDF_LOGE("spi config read spiMisoPin fail\r\n"); - return HDF_FAILURE; + resource = &spiDevice->resource; + if (resource == NULL) { + HDF_LOGE("%s: resource is NULL\r\n", __func__); + return HDF_ERR_INVALID_OBJECT; } + ret = GetSpiDeviceConfig(resource, resourceNode); + if (ret != HDF_SUCCESS) { + HDF_LOGE("get spi config fail\r\n"); + return ret; + } + spiDevice->spiId = resource->num; - relPin = ((resource->spiMisoPin / DEC_NUM) * GROUP_PIN_NUM) + (resource->spiMisoPin % DEC_NUM); - resource->spiMisoPin = relPin; + resource->spiClkPin = (resource->spiClkPin / DEC_NUM) * GROUP_PIN_NUM + (resource->spiClkPin % DEC_NUM); - if (dri->GetUint32(resourceNode, "spiCsPin", &resource->spiCsPin, 0) != HDF_SUCCESS) { - HDF_LOGE("spi config read spiCsPin fail\r\n"); - return HDF_FAILURE; - } + resource->spiMosiPin = (resource->spiMosiPin / DEC_NUM) * GROUP_PIN_NUM + (resource->spiMosiPin % DEC_NUM); + + resource->spiMisoPin = ((resource->spiMisoPin / DEC_NUM) * GROUP_PIN_NUM) + (resource->spiMisoPin % DEC_NUM); - relPin = ((resource->spiCsPin / DEC_NUM) * GROUP_PIN_NUM) + (resource->spiCsPin % DEC_NUM); - resource->spiCsPin = relPin; + resource->spiCsPin = ((resource->spiCsPin / DEC_NUM) * GROUP_PIN_NUM) + (resource->spiCsPin % DEC_NUM); return HDF_SUCCESS; } -#endif + int32_t AttachSpiDevice(struct SpiCntlr *spiCntlr, struct HdfDeviceObject *device) { int32_t ret; @@ -502,7 +549,7 @@ int32_t AttachSpiDevice(struct SpiCntlr *spiCntlr, struct HdfDeviceObject *devic return HDF_ERR_MALLOC_FAIL; } #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO - ret = GetSpiDeviceResource(spiDevice); + ret = GetSpiDeviceResource(spiDevice, device->deviceMatchAttr); #else ret = GetSpiDeviceResource(spiDevice, device->property); #endif @@ -606,7 +653,7 @@ static void SpiDriverRelease(struct HdfDeviceObject *device) } spiCntlr = SpiCntlrFromDevice(device); - if (spiCntlr == NULL || spiCntlr->priv == NULL) { + if (spiCntlr == NULL) { HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); return; } @@ -672,8 +719,8 @@ static int32_t SpiDevClose(struct SpiCntlr *spiCntlr) static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) { struct SpiDevice *spiDevice = NULL; - if (spiCntlr == NULL || spiCfg == NULL || spiCntlr->priv == NULL) { - HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + if (spiCntlr == NULL || spiCfg == NULL) { + HDF_LOGE("%s %d:invalid parameter error\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } spiDevice = (struct SpiDevice *)spiCntlr->priv; @@ -687,12 +734,13 @@ static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) return HDF_SUCCESS; } + static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) { struct SpiDevice *spiDevice = NULL; struct HAL_SPI_CFG_T *spiDevCfg = NULL; - if (spiCntlr == NULL || spiCfg == NULL || spiCntlr->priv == NULL) { - HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + if (spiCntlr == NULL || spiCfg == NULL) { + HDF_LOGE("%s %d:invalid parameter error\r\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } spiDevice = (struct SpiDevice *)spiCntlr->priv; @@ -717,11 +765,11 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, struct SpiDevice *spiDevice = NULL; struct HAL_SPI_CFG_T *spiDevCfg = NULL; struct SpiMsg *msg = NULL; + int32_t ret; if (spiCntlr == NULL || spiCntlr->priv == NULL) { HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); return HDF_ERR_INVALID_PARAM; } - HDF_LOGI("%s: %u Enter\r\n", __func__, spiId); spiDevice = (struct SpiDevice *)spiCntlr->priv; spiId = spiDevice->spiId; for (size_t i = 0; i < count; i++) { @@ -732,19 +780,22 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, } if ((msg->wbuf != NULL) && (msg->rbuf == NULL)) { - HalSpiSend(spiDevice, msg->wbuf, msg->len, TIMEOUT); + ret = HalSpiSend(spiDevice, msg->wbuf, msg->len, TIMEOUT); } if ((msg->rbuf != NULL) && (msg->wbuf == NULL)) { - HalSpiRecv(spiDevice, msg->rbuf, msg->len, TIMEOUT); + ret = HalSpiRecv(spiDevice, msg->rbuf, msg->len, TIMEOUT); } if ((msg->wbuf != NULL) && (msg->rbuf != NULL)) { - HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len, TIMEOUT); + ret = HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len); } /* pull pull up cs at the end */ - if (msg->csChange) { + if (msg->keepCs == 0) { hal_gpio_pin_set_dir(spiCtx[spiId].spiPinCS0, HAL_GPIO_DIR_OUT, 1); } + if (ret < 0) { + HDF_LOGE("%s send error!\r\n", __func__); + } DelayUs(msg->delayUs); } return HDF_SUCCESS; diff --git a/platform/spi/spi_bes.h b/platform/spi/spi_bes.h index 5242cfa..8cdf916 100644 --- a/platform/spi/spi_bes.h +++ b/platform/spi/spi_bes.h @@ -12,7 +12,9 @@ #include "hal_spi.h" #include "hal_gpio.h" #include "hal_iomux.h" +#ifdef CHIP_BEST2003 #include "hal_iomux_best2003.h" +#endif #include "osal_mutex.h" #include "osal_sem.h" diff --git a/platform/uart/uart_bes.c b/platform/uart/uart_bes.c index e12c0bc..c09aa05 100644 --- a/platform/uart/uart_bes.c +++ b/platform/uart/uart_bes.c @@ -11,23 +11,39 @@ #include #include "hal_iomux.h" #include "hal_timer.h" +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#include "hcs_macro.h" +#include "hdf_config_macro.h" +#else #include "device_resource_if.h" +#endif #include "hal_trace.h" #include "hal_cache.h" #include "hdf_log.h" -#define HDF_UART_TMO 1000 + +#define HDF_UART_TMO OSAL_WAIT_FOREVER #define HDF_LOG_TAG uartDev #define UART_FIFO_MAX_BUFFER 2048 #define UART_DMA_RING_BUFFER_SIZE 256 // mast be 2^n - +#ifdef LOSCFG_SOC_SERIES_BES2700 +#include "hal_location.h" +#define MAX_UART_NUMBER 2 +#define MAX_UART_ID HAL_UART_ID_1 +static SRAM_BSS_LOC unsigned char g_halUartBuf[UART_DMA_RING_BUFFER_SIZE]; +static SRAM_BSS_LOC unsigned char g_halUart1Buf[UART_DMA_RING_BUFFER_SIZE]; +static unsigned char *g_uartKfifoBuffer[MAX_UART_NUMBER] = { NULL, NULL }; +#elif defined (LOSCFG_SOC_SERIES_BES2600) +#define MAX_UART_NUMBER 3 +#define MAX_UART_ID HAL_UART_ID_2 static __SRAMBSS unsigned char g_halUartBuf[UART_DMA_RING_BUFFER_SIZE]; static __SRAMBSS unsigned char g_halUart1Buf[UART_DMA_RING_BUFFER_SIZE]; static __SRAMBSS unsigned char g_halUart2Buf[UART_DMA_RING_BUFFER_SIZE]; +static unsigned char *g_uartKfifoBuffer[MAX_UART_NUMBER] = {NULL, NULL, NULL}; +#endif -static struct UART_CTX_OBJ g_uartCtx[4] = {0}; -static unsigned char *g_uartKfifoBuffer[4] = {NULL, NULL, NULL, NULL}; +static struct UART_CTX_OBJ g_uartCtx[MAX_UART_NUMBER] = {0}; struct HAL_UART_CFG_T g_lowUartCfg = { // used for tgdb cli console .parity = HAL_UART_PARITY_NONE, @@ -44,21 +60,31 @@ struct HAL_UART_CFG_T g_lowUartCfg = { static void HalSetUartIomux(enum HAL_UART_ID_T uartId) { + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d not support!\r\n", __func__, uartId); + return; + } if (uartId == HAL_UART_ID_0) { hal_iomux_set_uart0(); - } else if (uartId == HAL_UART_ID_1) { + } + if (uartId == HAL_UART_ID_1) { hal_iomux_set_uart1(); - } else if (uartId == HAL_UART_ID_2) { + } +#ifdef LOSCFG_SOC_SERIES_BES2600 + if (uartId == HAL_UART_ID_2) { hal_iomux_set_uart2(); - } else { - hal_iomux_set_uart3(); } +#endif } -static void HalUartRxStart(uint32_t uartId) +static void HalUartStartDmaRx(uint32_t uartId) { + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %u not support!\r\n", __func__, uartId); + return; + } struct HAL_DMA_DESC_T dmaDescRx; - unsigned int descCnt = 1; + uint32_t descCnt; union HAL_UART_IRQ_T mask; mask.reg = 0; @@ -67,58 +93,69 @@ static void HalUartRxStart(uint32_t uartId) mask.OE = 0; mask.PE = 0; mask.RT = 1; - + descCnt = 1; hal_uart_dma_recv_mask(uartId, g_uartCtx[uartId].buffer, UART_DMA_RING_BUFFER_SIZE, &dmaDescRx, &descCnt, &mask); } -static void UartRxHandler(enum HAL_UART_ID_T id, union HAL_UART_IRQ_T status) +static void UartRxHandler(enum HAL_UART_ID_T uartId, union HAL_UART_IRQ_T status) { - int32_t ret; - - if (status.TX) { - ret = OsalSemPost(&g_uartCtx[id].txSem); - ASSERT(ret == HDF_SUCCESS, "%s: Failed to release write_sem: %d", __func__, ret); + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %u not support!\r\n", __func__, uartId); + return; + } + if (status.TX != 0) { + if (OsalSemPost(&g_uartCtx[uartId].txSem) != HDF_SUCCESS) { + HDF_LOGE("%s OsalSemPost txSem failed!\r\n", __func__); + return; + } } - if (status.RX || status.RT) { - ret = OsalSemPost(&g_uartCtx[id].rxSem); - ASSERT(ret == HDF_SUCCESS, "%s: Failed to release read_sem: %d", __func__, ret); + if (status.RX != 0 || status.RT != 0) { + if (OsalSemPost(&g_uartCtx[uartId].rxSem) != HDF_SUCCESS) { + HDF_LOGE("%s OsalSemPost rxSem failed!\r\n", __func__); + return; + } } } static void UartDmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status) { - uint32_t len = 0; - uint32_t uartid = 0; - - len = kfifo_put(&g_uartCtx[uartid].fifo, g_uartCtx[uartid].buffer, xferSize); + int32_t ret; + uint32_t len = kfifo_put(&g_uartCtx[HAL_UART_ID_0].fifo, g_uartCtx[HAL_UART_ID_0].buffer, xferSize); if (len < xferSize) { HDF_LOGE("%s ringbuf is full have %d need %d\r", __FUNCTION__, (int)len, (int)xferSize); return; } - memset_s(g_uartCtx[uartid].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); - OsalSemPost(&g_uartCtx[uartid].rxSem); - HalUartRxStart(uartid); + ret = memset_s(g_uartCtx[HAL_UART_ID_0].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); + if (ret != 0) { + HDF_LOGE("%s %d:memset_s error\r\n", __func__, __LINE__); + return; + } + OsalSemPost(&g_uartCtx[HAL_UART_ID_0].rxSem); + HalUartStartDmaRx(HAL_UART_ID_0); } static void UartDmaTxHandler(uint32_t xferSize, int dmaError) { - OsalSemPost(&g_uartCtx[0].txSem); + OsalSemPost(&g_uartCtx[HAL_UART_ID_0].txSem); } static void Uart1DmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status) { - uint32_t len = 0; - uint32_t uartid = HAL_UART_ID_1; - len = kfifo_put(&g_uartCtx[uartid].fifo, g_uartCtx[uartid].buffer, xferSize); + int32_t ret; + uint32_t len = kfifo_put(&g_uartCtx[HAL_UART_ID_1].fifo, g_uartCtx[HAL_UART_ID_1].buffer, xferSize); if (len < xferSize) { HDF_LOGE("%s ringbuf is full have %d need %d\r", __FUNCTION__, (int)len, (int)xferSize); return; } - memset_s(g_uartCtx[uartid].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); - OsalSemPost(&g_uartCtx[uartid].rxSem); - HalUartRxStart(uartid); + ret = memset_s(g_uartCtx[HAL_UART_ID_1].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); + if (ret != 0) { + HDF_LOGE("%s %d:memset_s error\r\n", __func__, __LINE__); + return; + } + OsalSemPost(&g_uartCtx[HAL_UART_ID_1].rxSem); + HalUartStartDmaRx(HAL_UART_ID_1); } static void Uart1DmaTxHandler(uint32_t xferSize, int dmaError) @@ -126,29 +163,38 @@ static void Uart1DmaTxHandler(uint32_t xferSize, int dmaError) OsalSemPost(&g_uartCtx[HAL_UART_ID_1].txSem); } +#ifdef LOSCFG_SOC_SERIES_BES2600 /* uart2 */ static void Uart2DmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status) { - uint32_t len = 0; - uint32_t uartid = HAL_UART_ID_2; - len = kfifo_put(&g_uartCtx[uartid].fifo, g_uartCtx[uartid].buffer, xferSize); + int32_t ret; + uint32_t len = kfifo_put(&g_uartCtx[HAL_UART_ID_2].fifo, g_uartCtx[HAL_UART_ID_2].buffer, xferSize); if (len < xferSize) { HDF_LOGE("%s ringbuf is full have %d need %d\r", __FUNCTION__, (int)len, (int)xferSize); return; } - memset_s(g_uartCtx[uartid].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); - OsalSemPost(&g_uartCtx[uartid].rxSem); - HalUartRxStart(uartid); + ret = memset_s(g_uartCtx[HAL_UART_ID_2].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); + if (ret != 0) { + HDF_LOGE("%s %d:memset_s error\r\n", __func__, __LINE__); + return; + } + OsalSemPost(&g_uartCtx[HAL_UART_ID_2].rxSem); + HalUartStartDmaRx(HAL_UART_ID_2); } static void Uart2DmaTxHandler(uint32_t xferSize, int dmaError) { OsalSemPost(&g_uartCtx[HAL_UART_ID_2].txSem); } +#endif static void HalUartStartRx(uint32_t uartId) { + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); + return; + } union HAL_UART_IRQ_T mask; mask.reg = 0; mask.RT = 1; @@ -160,20 +206,22 @@ static void HalUartStartRx(uint32_t uartId) static int32_t HalUartSend(uint32_t uartId, const void *data, uint32_t size, uint32_t timeOut) { - int32_t ret = HDF_FAILURE; + int32_t ret; struct HAL_DMA_DESC_T dmaSescTx; - unsigned int descCnt = 1; - + uint32_t descCnt; if (data == NULL || size == 0) { HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); return HDF_ERR_INVALID_PARAM; } - if (uartId > HAL_UART_ID_2) { + if (uartId > MAX_UART_ID) { HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); return HDF_ERR_NOT_SUPPORT; } - + descCnt = 1; +#ifdef LOSCFG_SOC_SERIES_BES2700 + hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); +#endif hal_uart_dma_send(uartId, data, size, &dmaSescTx, &descCnt); OsalSemWait(&g_uartCtx[uartId].txSem, timeOut); @@ -181,21 +229,20 @@ static int32_t HalUartSend(uint32_t uartId, const void *data, uint32_t size, uin } static int32_t HalUartRecv(uint8_t uartId, void *data, uint32_t expectSize, - uint32_t *recvSize, uint32_t timeOut) + uint32_t *recvSize, uint32_t timeOut) { - int32_t ret = HDF_FAILURE; - uint32_t beginTime = 0; - uint32_t nowTime = 0; - uint32_t fifoPopLen = 0; + uint32_t beginTime; + uint32_t nowTime; + uint32_t fifoPopLen; uint32_t recvedLen = 0; - uint32_t expectLen = expectSize; + int32_t expectLen = (int32_t)expectSize; - if (data == NULL || expectSize == 0 || recvSize == NULL) { + if (data == NULL || expectLen == 0 || recvSize == NULL) { HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); return HDF_ERR_INVALID_PARAM; } - if (uartId > HAL_UART_ID_2) { + if (uartId > MAX_UART_ID) { HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); return HDF_ERR_NOT_SUPPORT; } @@ -223,19 +270,36 @@ static int32_t HalUartRecv(uint8_t uartId, void *data, uint32_t expectSize, if (recvSize != NULL) { *recvSize = recvedLen; } - return HDF_SUCCESS; } -static void HalUartHandlerInit(struct UartDevice *device) +static int32_t InitUartCtxCfg(struct UartDevice *device) { + int32_t ret; uint32_t uartId; + struct HAL_UART_CFG_T *uartCfg = NULL; if (device == NULL) { HDF_LOGE("%s: INVALID PARAM", __func__); - return HDF_ERR_INVALID_PARAM; + return HDF_ERR_INVALID_OBJECT; + } + uartCfg = &device->config; + if (uartCfg == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return HDF_ERR_INVALID_OBJECT; } uartId = device->uartId; - HDF_LOGI("%s %ld\r\n", __func__, uartId); + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } + ret = memset_s(&g_uartCtx[uartId], sizeof(struct UART_CTX_OBJ), 0, sizeof(struct UART_CTX_OBJ)); + if (ret != 0) { + HDF_LOGE("%s %d:memset_s error\r\n", __func__, __LINE__); + return HDF_FAILURE; + } + g_uartCtx[uartId].txDMA = uartCfg->dma_tx; + g_uartCtx[uartId].rxDMA = uartCfg->dma_rx; + if (uartId == HAL_UART_ID_0) { g_uartCtx[uartId].UartDmaRxHandler = UartDmaRxHandler; g_uartCtx[uartId].UartDmaTxHandler = UartDmaTxHandler; @@ -247,13 +311,36 @@ static void HalUartHandlerInit(struct UartDevice *device) g_uartCtx[uartId].UartDmaTxHandler = Uart1DmaTxHandler; g_uartCtx[uartId].buffer = g_halUart1Buf; } - +#ifdef LOSCFG_SOC_SERIES_BES2600 if (uartId == HAL_UART_ID_2) { g_uartCtx[uartId].UartDmaRxHandler = Uart2DmaRxHandler; g_uartCtx[uartId].UartDmaTxHandler = Uart2DmaTxHandler; g_uartCtx[uartId].buffer = g_halUart2Buf; } +#endif + return HDF_SUCCESS; +} + +static void HalUartHandlerInit(struct UartDevice *device) +{ + uint32_t uartId; + int32_t ret; + struct HAL_UART_CFG_T *uartCfg = NULL; + if (device == NULL) { + HDF_LOGE("%s: INVALID PARAM!\r\n", __func__); + return; + } + uartId = device->uartId; + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT!\r\n", __FILE__, __LINE__); + return; + } + ret = InitUartCtxCfg(device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s %d InitUartCtxCfg failed\r\n", __FILE__, __LINE__); + return; + } if (!g_uartKfifoBuffer[uartId]) { g_uartKfifoBuffer[uartId] = (char *)OsalMemAlloc(UART_FIFO_MAX_BUFFER); if (!g_uartKfifoBuffer[uartId]) { @@ -263,13 +350,19 @@ static void HalUartHandlerInit(struct UartDevice *device) kfifo_init(&g_uartCtx[uartId].fifo, g_uartKfifoBuffer[uartId], UART_FIFO_MAX_BUFFER); } - OsalSemInit(&g_uartCtx[uartId].rxSem, 0); - OsalSemInit(&g_uartCtx[uartId].txSem, 0); + if (OsalSemInit(&g_uartCtx[uartId].rxSem, 0) != HDF_SUCCESS) { + HDF_LOGE("UART rxsem init failed!"); + return; + } + if (OsalSemInit(&g_uartCtx[uartId].txSem, 0) != HDF_SUCCESS) { + HDF_LOGE("UART txsem init failed!"); + return; + } - if (g_uartCtx[uartId].rxDMA) { - HDF_LOGE("uart %ld start dma rx\r\n", uartId); + if (g_uartCtx[uartId].rxDMA == true) { + HDF_LOGI("uart %u start dma rx\r\n", uartId); hal_uart_irq_set_dma_handler(uartId, g_uartCtx[uartId].UartDmaRxHandler, g_uartCtx[uartId].UartDmaTxHandler); - HalUartRxStart(uartId); + HalUartStartDmaRx(uartId); } else { HalUartStartRx(uartId); } @@ -284,13 +377,16 @@ static void UartStart(struct UartDevice *device) return; } uartId = device->uartId; + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return; + } uartCfg = &device->config; if (uartCfg == NULL) { HDF_LOGE("%s: INVALID OBJECT", __func__); return; } hal_uart_open(uartId, uartCfg); - HDF_LOGI("%s %ld\r\n", __FUNCTION__, uartId); HalUartHandlerInit(device); } @@ -302,7 +398,7 @@ static void UartDriverRelease(struct HdfDeviceObject *device); /* HdfDriverEntry definitions */ struct HdfDriverEntry g_UartDriverEntry = { .moduleVersion = 1, - .moduleName = "BES_UART_MODULE_HDF", + .moduleName = "HDF_UART_MODULE_HDF", .Bind = UartDriverBind, .Init = UartDriverInit, .Release = UartDriverRelease, @@ -361,28 +457,22 @@ static int InitUartDevice(struct UartHost *host) HDF_LOGE("%s: INVALID OBJECT", __func__); return HDF_ERR_INVALID_OBJECT; } - uartDevice->uartId = resource->num; - uartCfg->parity = resource->parity; - uartCfg->stop = resource->stopBit; - uartCfg->data = resource->wLen; + uint32_t uartId = resource->num; + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } uartCfg->flow = HAL_UART_FLOW_CONTROL_NONE; - uartCfg->tx_level = HAL_UART_FIFO_LEVEL_1_2; + uartCfg->tx_level = HAL_UART_FIFO_LEVEL_1_8; uartCfg->rx_level = HAL_UART_FIFO_LEVEL_1_2; - uartCfg->baud = resource->baudRate; uartCfg->dma_rx_stop_on_err = false; - uartCfg->dma_rx = resource->rxDMA; - uartCfg->dma_tx = resource->txDMA; - - g_uartCtx[uartDevice->uartId].txDMA = resource->txDMA; - g_uartCtx[uartDevice->uartId].rxDMA = resource->rxDMA; if (!uartDevice->initFlag) { - HDF_LOGE("uart %ld device init\r\n", uartDevice->uartId); + HDF_LOGE("uart %u device init\r\n", uartDevice->uartId); HalSetUartIomux(uartDevice->uartId); UartStart(uartDevice); uartDevice->initFlag = true; } - return HDF_SUCCESS; } @@ -431,6 +521,7 @@ static uint32_t GetUartDeviceResource( resource->rxDMA = dri->GetBool(resourceNode, "rxDMA"); // copy config + device->initFlag = false; device->uartId = resource->num; device->config.baud = resource->baudRate; device->config.parity = resource->parity; @@ -445,8 +536,11 @@ static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObjec { int32_t ret; struct UartDevice *uartDevice = NULL; - +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + if (device == NULL || uartHost == NULL) { +#else if (uartHost == NULL || device == NULL || device->property == NULL) { +#endif HDF_LOGE("%s: property is NULL", __func__); return HDF_ERR_INVALID_PARAM; } @@ -456,8 +550,11 @@ static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObjec HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__); return HDF_ERR_MALLOC_FAIL; } - +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + ret = GetUartDeviceResource(uartDevice, device->deviceMatchAttr); +#else ret = GetUartDeviceResource(uartDevice, device->property); +#endif if (ret != HDF_SUCCESS) { (void)OsalMemFree(uartDevice); return HDF_FAILURE; @@ -470,7 +567,7 @@ static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObjec static int32_t UartDriverBind(struct HdfDeviceObject *device) { - struct UartHost *devService; + struct UartHost *devService = NULL; if (device == NULL) { HDF_LOGE("%s: invalid parameter", __func__); return HDF_ERR_INVALID_PARAM; @@ -554,8 +651,8 @@ static int32_t UartHostDevInit(struct UartHost *host) HDF_LOGE("%s: invalid parameter", __func__); return HDF_ERR_INVALID_PARAM; } - InitUartDevice(host); - return HDF_SUCCESS; + + return InitUartDevice(host); } static int32_t UartHostDevDeinit(struct UartHost *host) @@ -584,7 +681,7 @@ static int32_t UartHostDevDeinit(struct UartHost *host) static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size) { struct UartDevice *device = NULL; - uint32_t portId; + uint32_t uartId; if (host == NULL || data == NULL || size == 0 || host->priv == NULL) { HDF_LOGE("%s: invalid parameter", __func__); @@ -597,15 +694,19 @@ static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t s return HDF_ERR_INVALID_OBJECT; } - portId = device->uartId; - if (g_uartCtx[portId].txDMA) { - HalUartSend(portId, data, size, HDF_UART_TMO); + uartId = device->uartId; + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } + if (g_uartCtx[uartId].txDMA) { + HalUartSend(uartId, data, size, HDF_UART_TMO); } else { for (uint32_t idx = 0; idx < size; idx++) { - if (g_uartCtx[portId].isBlock) { - hal_uart_blocked_putc(portId, data[idx]); + if (g_uartCtx[uartId].isBlock) { + hal_uart_blocked_putc(uartId, data[idx]); } else { - hal_uart_putc(portId, data[idx]); + hal_uart_putc(uartId, data[idx]); } } } @@ -615,7 +716,7 @@ static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t s static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size) { - uint32_t recvSize = 0; + uint32_t recvSize; int32_t ret; uint32_t uartId; struct UartDevice *uartDevice = NULL; @@ -642,7 +743,9 @@ static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t si if (g_uartCtx[uartId].isBlock) { data[0] = hal_uart_blocked_getc(uartId); } else { - data[0] = hal_uart_getc(uartId); + if (hal_uart_readable(uartId) > 0) { + data[0] = hal_uart_getc(uartId); + } } ret = 1; } @@ -667,7 +770,10 @@ static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate) return HDF_ERR_INVALID_OBJECT; } uartId = uartDevice->uartId; - + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } uartCfg = &uartDevice->config; if (uartCfg == NULL) { HDF_LOGE("%s: device config is NULL", __func__); @@ -675,7 +781,7 @@ static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate) } uartCfg->baud = baudRate; - hal_uart_reopen(uartId, uartCfg); + hal_uart_open(uartId, uartCfg); return HDF_SUCCESS; } @@ -696,6 +802,10 @@ static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate) return HDF_ERR_INVALID_OBJECT; } uartId = uartDevice->uartId; + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } uartCfg = &uartDevice->config; if (uartCfg == NULL) { HDF_LOGE("%s: device is NULL", __func__); @@ -709,22 +819,14 @@ static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate) return HDF_SUCCESS; } -static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute) +static int32_t SetUartDevConfig(struct UartAttribute *attribute, struct UartDevice *uartDevice) { - HDF_LOGI("%s: Enter", __func__); - struct UartDevice *uartDevice = NULL; struct HAL_UART_CFG_T *uartCfg = NULL; uint32_t uartId; - if (host == NULL || attribute == NULL || host->priv == NULL) { + if (attribute == NULL || uartDevice == NULL) { HDF_LOGE("%s: invalid parameter", __func__); return HDF_ERR_INVALID_PARAM; } - - uartDevice = (struct UartDevice *)host->priv; - if (uartDevice == NULL) { - HDF_LOGE("%s: device is NULL", __func__); - return HDF_ERR_INVALID_OBJECT; - } uartId = uartDevice->uartId; uartCfg = &uartDevice->config; if (uartCfg == NULL) { @@ -771,17 +873,15 @@ static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribu } else { uartCfg->flow = HAL_UART_FLOW_CONTROL_NONE; } - - hal_uart_reopen(uartId, uartCfg); - + hal_uart_open(uartId, uartCfg); return HDF_SUCCESS; } -static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute) +static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute) { HDF_LOGI("%s: Enter", __func__); struct UartDevice *uartDevice = NULL; - struct HAL_UART_CFG_T *uartCfg = NULL; + int ret; if (host == NULL || attribute == NULL || host->priv == NULL) { HDF_LOGE("%s: invalid parameter", __func__); return HDF_ERR_INVALID_PARAM; @@ -792,12 +892,21 @@ static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribu HDF_LOGE("%s: device is NULL", __func__); return HDF_ERR_INVALID_OBJECT; } - uartCfg = &uartDevice->config; - if (uartCfg == NULL) { - HDF_LOGE("%s: config is NULL", __func__); - return HDF_ERR_INVALID_OBJECT; + + ret = SetUartDevConfig(attribute, uartDevice); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: SetUartDevConfig error", __func__); + return HDF_FAILURE; } + return HDF_SUCCESS; +} +static int32_t GetUartDevConfig(struct UartAttribute *attribute, struct HAL_UART_CFG_T *uartCfg) +{ + if (attribute == NULL || uartCfg == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } switch (uartCfg->data) { case HAL_UART_DATA_BITS_8: attribute->dataBits = UART_ATTR_DATABIT_8; @@ -841,10 +950,33 @@ static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribu attribute->cts = 0; break; } - return HDF_SUCCESS; } +static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute) +{ + HDF_LOGI("%s: Enter", __func__); + struct UartDevice *uartDevice = NULL; + struct HAL_UART_CFG_T *uartCfg = NULL; + if (host == NULL || attribute == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartCfg = &uartDevice->config; + if (uartCfg == NULL) { + HDF_LOGE("%s: config is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + return GetUartDevConfig(attribute, uartCfg); +} + static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode) { HDF_LOGI("%s: Enter", __func__); @@ -861,7 +993,10 @@ static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode return HDF_ERR_INVALID_OBJECT; } uartId = uartDevice->uartId; - + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } switch (mode) { case UART_MODE_RD_BLOCK: g_uartCtx[uartId].isBlock = true; diff --git a/platform/watchdog/watchdog_bes.c b/platform/watchdog/watchdog_bes.c index e70f336..7071f41 100644 --- a/platform/watchdog/watchdog_bes.c +++ b/platform/watchdog/watchdog_bes.c @@ -47,7 +47,7 @@ static int InitWatchdogDevice(struct WatchdogDevice *watchdogDevice) struct WatchdogResource *resource = NULL; int32_t watchdogId; if (watchdogDevice == NULL) { - HDF_LOGE("%s: invaild parameter\r\n", __func__); + HDF_LOGE("%s: invalid parameter\r\n", __func__); return HDF_ERR_INVALID_PARAM; } @@ -182,7 +182,7 @@ static int32_t WatchdogDriverInit(struct HdfDeviceObject *device) } watchdogCntlr->ops = &g_WatchdogCntlrMethod; - + HDF_LOGE("WatchdogDriverInit success!\r\n"); return ret; } -- Gitee