mirror of
https://github.com/openharmony/device_board_openvalley.git
synced 2026-07-01 00:47:54 -04:00
+11
-4
@@ -14,12 +14,19 @@ device/board/openvalley
|
||||
├── figures # 文档图片目录
|
||||
├── liteos_m # liteos_m适配目录
|
||||
├── arch # 内核指令架构层目录
|
||||
├── driver # 驱动目录
|
||||
├── hals # 硬件抽象层目录
|
||||
├── drivers # 驱动适配目录
|
||||
├── iot_hardware # iothardware子系统适配
|
||||
├── log # 日志输出适配
|
||||
├── memory # 内存管理函数适配
|
||||
├── syscalls # 系统调用函数适配
|
||||
├── update # 程序升级子系统适配
|
||||
└── utils # 通用接口适配
|
||||
├── hdf_config # hdf配置目录
|
||||
├── include # 板级配置头文件目录
|
||||
├── littlefs # littlefs适配目录
|
||||
├── target # 启动文件目录
|
||||
├── target # 板级配置目录
|
||||
├── third_party_adapter # 三方库适配目录
|
||||
├── littlefs # littlefs文件系统适配
|
||||
├── mbedtls # 轻量级加密库适配
|
||||
|
||||
├── xxx # 其它板型,持续开发中...
|
||||
```
|
||||
|
||||
@@ -16,12 +16,11 @@ if (ohos_kernel_type == "liteos_m") {
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
module_group(module_name) {
|
||||
modules = [
|
||||
"target",
|
||||
"littlefs",
|
||||
"drivers",
|
||||
"hals",
|
||||
"arch",
|
||||
"hals",
|
||||
"hdf_config",
|
||||
"target",
|
||||
"third_party_adapter",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "adc_core.h"
|
||||
#include "adc_if.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "device_resource_if.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_irq.h"
|
||||
|
||||
int32_t AdcDevOpen(struct AdcDevice *device, uint32_t number);
|
||||
void AdcDevClose(struct AdcDevice *device);
|
||||
int32_t AdcDevRead(struct AdcDevice *device, uint32_t number, uint32_t channel, uint32_t *val);
|
||||
|
||||
struct AdcMethod g_AdcCntlrMethod = {
|
||||
.read = AdcDevRead,
|
||||
.start = AdcDevOpen,
|
||||
.stop = AdcDevClose,
|
||||
};
|
||||
|
||||
static int32_t DeviceInit(struct HdfDeviceObject *object);
|
||||
static int32_t DeviceBind(struct HdfDeviceObject *object);
|
||||
static void DeviceRelease(struct HdfDeviceObject *object);
|
||||
|
||||
static const struct HdfDriverEntry ADC_DriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "HDF_ADC_MODULE",
|
||||
.Bind = DeviceBind,
|
||||
.Init = DeviceInit,
|
||||
.Release = DeviceRelease,
|
||||
};
|
||||
HDF_INIT(ADC_DriverEntry);
|
||||
|
||||
typedef struct {
|
||||
uint32_t unit;
|
||||
uint32_t channel;
|
||||
} DeviceInfo_t;
|
||||
|
||||
static const DeviceInfo_t DeviceInfoDefault = {
|
||||
.unit = -1,
|
||||
.channel = -1,
|
||||
};
|
||||
|
||||
static int32_t DeviceInit(struct HdfDeviceObject *object)
|
||||
{
|
||||
DeviceInfo_t *dev;
|
||||
int ret;
|
||||
if (object == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
dev = (DeviceInfo_t *)OsalMemAlloc(sizeof(DeviceInfo_t));
|
||||
if (dev == NULL) {
|
||||
HDF_LOGE("%s.malloc\n", ADC_DriverEntry.moduleName);
|
||||
return HDF_DEV_ERR_NO_MEMORY;
|
||||
}
|
||||
object->priv = (void *)dev;
|
||||
ret = memcpy_s(dev, sizeof(DeviceInfoDefault), &DeviceInfoDefault, sizeof(DeviceInfoDefault));
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("memcpy_s fail!\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (object->property) {
|
||||
const struct DeviceResourceNode *node = object->property;
|
||||
struct DeviceResourceIface *resource = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
resource->GetUint32(node, "unit", &dev->unit, -1);
|
||||
resource->GetUint32(node, "channel", &dev->channel, -1);
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t DeviceBind(struct HdfDeviceObject *object)
|
||||
{
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void DeviceRelease(struct HdfDeviceObject *object)
|
||||
{
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
if (object->priv) {
|
||||
DeviceInfo_t *dev = (DeviceInfo_t *)object->priv;
|
||||
AdcDevClose(AdcDevClose);
|
||||
OsalMemFree(object->priv);
|
||||
}
|
||||
object->priv = NULL;
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __ADC_H__
|
||||
#define __ADC_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP32_ADC_H__ */
|
||||
@@ -1,24 +0,0 @@
|
||||
# Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
|
||||
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO)
|
||||
hdf_driver("gpio") {
|
||||
sources = [
|
||||
"gpio.c",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "cmsis_os2.h"
|
||||
#include "device_resource_if.h"
|
||||
#include "gpio_core.h"
|
||||
#include "gpio_if.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_irq.h"
|
||||
|
||||
#define GPIO_OUTPUT_IO_0 18
|
||||
#define GPIO_OUTPUT_IO_1 19
|
||||
#define GPIO_OUTPUT_PIN_SEL ((1ULL << GPIO_OUTPUT_IO_0) | (1ULL << GPIO_OUTPUT_IO_1))
|
||||
#define GPIO_INPUT_IO_0 4
|
||||
#define GPIO_INPUT_IO_1 5
|
||||
#define GPIO_INPUT_PIN_SEL ((1ULL << GPIO_INPUT_IO_0) | (1ULL << GPIO_INPUT_IO_1))
|
||||
|
||||
#define LED_GPIO 5
|
||||
#define LED_OFF 0x00
|
||||
#define LED_ON 0x01
|
||||
typedef void (*gpio_isr_t)(void *);
|
||||
|
||||
int32_t InitGpioDevice(int pin);
|
||||
int32_t GpioDevWrite(int pin, int val);
|
||||
int32_t GpioDevRead(int pin, unsigned int *val);
|
||||
int32_t GpioDevSetDir(int pin, int dir);
|
||||
int32_t GpioDevGetDir(int pin);
|
||||
int32_t GpioDevSetIrq(int pin, int mode, int pin_bit_mask);
|
||||
int32_t GpioDevUnSetIrq(int pin);
|
||||
int32_t GpioDevEnableIrq(int pin, int int_type, gpio_isr_t isr_handler, void *args);
|
||||
int32_t GpioDevDisableIrq(int pin);
|
||||
|
||||
struct GpioMethod g_GpioCntlrMethod = {
|
||||
.request = NULL,
|
||||
.release = NULL,
|
||||
.write = GpioDevWrite,
|
||||
.read = GpioDevRead,
|
||||
.setDir = GpioDevSetDir,
|
||||
.getDir = GpioDevGetDir,
|
||||
.toIrq = NULL,
|
||||
.setIrq = GpioDevSetIrq,
|
||||
.unsetIrq = GpioDevUnSetIrq,
|
||||
.enableIrq = GpioDevEnableIrq,
|
||||
.disableIrq = GpioDevDisableIrq,
|
||||
};
|
||||
|
||||
static int32_t DeviceInit(struct HdfDeviceObject *object);
|
||||
static int32_t DeviceBind(struct HdfDeviceObject *object);
|
||||
static void DeviceRelease(struct HdfDeviceObject *object);
|
||||
|
||||
static const struct HdfDriverEntry GPIO_DriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "HDF_GPIO_MODULE",
|
||||
.Bind = DeviceBind,
|
||||
.Init = DeviceInit,
|
||||
.Release = DeviceRelease,
|
||||
};
|
||||
HDF_INIT(GPIO_DriverEntry);
|
||||
|
||||
typedef struct {
|
||||
int16_t power_pin;
|
||||
int16_t address;
|
||||
int8_t port;
|
||||
DevHandle handle;
|
||||
} DeviceInfo_t;
|
||||
static const DeviceInfo_t DeviceInfoDefault = {
|
||||
.power_pin = -1,
|
||||
.address = -1,
|
||||
.port = -1,
|
||||
};
|
||||
/**
|
||||
* @brief Enumerates GPIO directions.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum HDF_GpioDirType {
|
||||
HDF_GPIO_DIR_IN = (0x00000001), /**< Input direction */
|
||||
HDF_GPIO_DIR_OUT = (0x00000002), /**< Output direction */
|
||||
HDF_GPIO_DIR_ERR, /**< Invalid direction */
|
||||
};
|
||||
typedef enum {
|
||||
GPIO_INTR_DISABLE = 0, /*!< Disable GPIO interrupt */
|
||||
GPIO_INTR_POSEDGE = 1, /*!< GPIO interrupt type : rising edge */
|
||||
GPIO_INTR_NEGEDGE = 2, /*!< GPIO interrupt type : falling edge */
|
||||
GPIO_INTR_ANYEDGE = 3, /*!< GPIO interrupt type : both rising and falling edge */
|
||||
GPIO_INTR_LOW_LEVEL = 4, /*!< GPIO interrupt type : input low level trigger */
|
||||
GPIO_INTR_HIGH_LEVEL = 5, /*!< GPIO interrupt type : input high level trigger */
|
||||
GPIO_INTR_MAX,
|
||||
} gpio_int_type_t;
|
||||
|
||||
static void gpio_isr_handler(void *arg)
|
||||
{
|
||||
uint32_t gpio_num = (uint32_t)arg;
|
||||
HDF_LOGE("gpio_isr_handler success !");
|
||||
}
|
||||
|
||||
static int32_t DeviceInit(struct HdfDeviceObject *object)
|
||||
{
|
||||
DeviceInfo_t *dev;
|
||||
int ret;
|
||||
static unsigned int g_irqData = 100;
|
||||
struct GpioCntlr *gpioCntlr = NULL;
|
||||
if (object == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
dev = (DeviceInfo_t *)OsalMemAlloc(sizeof(DeviceInfo_t));
|
||||
if (dev == NULL) {
|
||||
HDF_LOGE("%s.malloc\n", GPIO_DriverEntry.moduleName);
|
||||
return HDF_DEV_ERR_NO_MEMORY;
|
||||
}
|
||||
object->priv = (void *)dev;
|
||||
ret = memcpy_s(dev, sizeof(DeviceInfoDefault), &DeviceInfoDefault, sizeof(DeviceInfoDefault));
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("memcpy_s fail!\r\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (!OsalRegisterIrq(LED_GPIO, 0, gpio_isr_handler, "test", &g_irqData)) {
|
||||
HDF_LOGE("OsalRegisterIrq success!...\n\r");
|
||||
} else {
|
||||
HDF_LOGE("OsalRegisterIrq error!...\n\r");
|
||||
}
|
||||
if (!OsalDisableIrq(LED_GPIO)) {
|
||||
HDF_LOGE("OsalDisableIrq success!...\n\r");
|
||||
} else {
|
||||
HDF_LOGE("OsalDisableIrq error!...\n\r");
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t DeviceBind(struct HdfDeviceObject *object)
|
||||
{
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void DeviceRelease(struct HdfDeviceObject *object)
|
||||
{
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (object->priv) {
|
||||
DeviceInfo_t *dev = (DeviceInfo_t *)object->priv;
|
||||
InitGpioDevice(dev->port);
|
||||
OsalMemFree(object->priv);
|
||||
}
|
||||
object->priv = NULL;
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __GPIO_H__
|
||||
#define __GPIO_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP32_GPIO_H__ */
|
||||
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "cmsis_os2.h"
|
||||
#include "device_resource_if.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
#include "hdf_log.h"
|
||||
#include "i2c_core.h"
|
||||
#include "i2c.h"
|
||||
|
||||
#define LOG_TAG "I2C"
|
||||
#define I2C_SPEED (400 * 1000)
|
||||
|
||||
static int32_t DeviceInit(struct HdfDeviceObject *object);
|
||||
static int32_t DeviceBind(struct HdfDeviceObject *object);
|
||||
static void DeviceRelease(struct HdfDeviceObject *object);
|
||||
static int32_t ClientOpen(struct HdfDeviceIoClient *client);
|
||||
static int32_t ClientDispatch(struct HdfDeviceIoClient *client, int cmdId,
|
||||
struct HdfSBuf *data, struct HdfSBuf *reply);
|
||||
static void ClientRelease(struct HdfDeviceIoClient *client);
|
||||
static int32_t DeviceTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count);
|
||||
int DeviceI2cInit(DeviceI2cParams *params);
|
||||
unsigned int DeviceI2cWrite(int id, unsigned char addr, const unsigned char *data, unsigned int dataLen, int ack);
|
||||
unsigned int DeviceI2cRead(int id, unsigned char addr, const unsigned char *data, unsigned int dataLen, int ack);
|
||||
|
||||
static const struct HdfDriverEntry I2C_DriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "HDF_I2C_MODULE",
|
||||
.Bind = DeviceBind,
|
||||
.Init = DeviceInit,
|
||||
.Release = DeviceRelease,
|
||||
};
|
||||
static struct IDeviceIoService DriverService = {
|
||||
.object.objectId = 0,
|
||||
.Open = ClientOpen,
|
||||
.Dispatch = ClientDispatch,
|
||||
.Release = ClientRelease,
|
||||
};
|
||||
|
||||
#define DriverEntry I2C_DriverEntry
|
||||
HDF_INIT(I2C_DriverEntry);
|
||||
|
||||
typedef struct {
|
||||
struct I2cCntlr cntlr;
|
||||
uint8_t scl_pin[3];
|
||||
uint8_t sda_pin[3];
|
||||
uint8_t mode;
|
||||
uint8_t port;
|
||||
uint32_t speed;
|
||||
} DeviceInfo_t;
|
||||
|
||||
static const struct I2cMethod I2cOpsDefault = {
|
||||
.transfer = DeviceTransfer};
|
||||
static const DeviceInfo_t DeviceInfoDefault = {
|
||||
.cntlr.ops = &I2cOpsDefault,
|
||||
.cntlr.lockOps = NULL,
|
||||
};
|
||||
|
||||
static int32_t DeviceTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count)
|
||||
{
|
||||
for (; count > 0; --count, ++msgs) {
|
||||
if ((msgs->flags) == 0) {
|
||||
if (DeviceI2cWrite(cntlr->busId, msgs->addr, msgs->buf, msgs->len, 1)) {
|
||||
break;
|
||||
}
|
||||
} else if ((msgs->flags) == I2C_FLAG_READ) {
|
||||
if (DeviceI2cRead(cntlr->busId, msgs->addr, msgs->buf, msgs->len, 1)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static uint32_t DeviceIRQ(uint32_t irqId, void *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t DeviceInit(struct HdfDeviceObject *object)
|
||||
{
|
||||
DeviceInfo_t *dev;
|
||||
int ret;
|
||||
if (object == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
dev = (DeviceInfo_t *)OsalMemAlloc(sizeof(DeviceInfo_t));
|
||||
if (dev == NULL) {
|
||||
HDF_LOGE("%s.malloc\n", DriverEntry.moduleName);
|
||||
return HDF_DEV_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
object->priv = (void *)dev;
|
||||
ret = memcpy_s(dev, sizeof(DeviceInfoDefault), &DeviceInfoDefault, sizeof(DeviceInfoDefault));
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("memcpy_s fail!\r\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (object->property) {
|
||||
struct I2cCntlr *cntlr;
|
||||
const struct DeviceResourceNode *node = object->property;
|
||||
struct DeviceResourceIface *resource = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
cntlr = &dev->cntlr;
|
||||
resource->GetUint8(node, "port", &dev->port, 0);
|
||||
resource->GetUint8Array(node, "scl_pin", dev->scl_pin, sizeof(dev->scl_pin) / sizeof(dev->scl_pin[0]), 0);
|
||||
resource->GetUint8Array(node, "sda_pin", dev->sda_pin, sizeof(dev->sda_pin) / sizeof(dev->sda_pin[0]), 0);
|
||||
resource->GetUint8(node, "mode", &dev->mode, 0xFF);
|
||||
resource->GetUint32(node, "speed", &dev->speed, 0);
|
||||
cntlr->busId = dev->port;
|
||||
}
|
||||
|
||||
DeviceI2cParams dev_params = {
|
||||
.cmd = 0,
|
||||
.id = dev->port,
|
||||
.scl_pin = dev->scl_pin[0],
|
||||
.sda_pin = dev->sda_pin[0],
|
||||
.speed = dev->speed,
|
||||
.mode = dev->mode,
|
||||
};
|
||||
DeviceI2cInit(&dev_params);
|
||||
|
||||
if (I2cCntlrAdd(&dev->cntlr) != HDF_SUCCESS) {
|
||||
OsalMemFree(dev);
|
||||
HDF_LOGE("%s.I2cCntlrAdd\n", DriverEntry.moduleName);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t DeviceBind(struct HdfDeviceObject *object)
|
||||
{
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void DeviceRelease(struct HdfDeviceObject *object)
|
||||
{
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
if (object->priv) {
|
||||
DeviceInfo_t *dev = (DeviceInfo_t *)object->priv;
|
||||
I2cCntlrRemove(&dev->cntlr);
|
||||
DeviceI2cParams dev_params = {
|
||||
.cmd = -1,
|
||||
.id = dev->port,
|
||||
.scl_pin = dev->scl_pin,
|
||||
.sda_pin = dev->sda_pin,
|
||||
.speed = I2C_SPEED,
|
||||
.mode = dev->mode,
|
||||
};
|
||||
DeviceI2cInit(&dev_params);
|
||||
OsalMemFree(object->priv);
|
||||
}
|
||||
object->priv = NULL;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __ESP32_I2C_H__
|
||||
#define __ESP32_I2C_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef struct _DeviceI2cParams {
|
||||
int cmd;
|
||||
int id;
|
||||
int scl_pin;
|
||||
int sda_pin;
|
||||
int speed;
|
||||
int mode;
|
||||
} DeviceI2cParams;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP32_I2C_H__ */
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "device_resource_if.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
#include "osal.h"
|
||||
|
||||
#define LOG_TAG "esp_osal"
|
||||
#define MAX_IRQ_ID 71
|
||||
static intr_handle_data_t *OaslIntrHandle[MAX_IRQ_ID] = {NULL};
|
||||
int32_t OsalRegisterIrq(uint32_t irqId, uint32_t config, OsalIRQHandle handle, const char *name, void *dev)
|
||||
{
|
||||
// xt_set_interrupt_handler
|
||||
int ret;
|
||||
if (irqId >= MAX_IRQ_ID)
|
||||
return HDF_FAILURE;
|
||||
if (OaslIntrHandle[irqId])
|
||||
OsalUnregisterIrq(irqId, dev);
|
||||
ret = esp_intr_alloc(irqId, config, (intr_handler_t)handle, dev, &OaslIntrHandle[irqId]);
|
||||
return (ret == ESP_OK) ? HDF_SUCCESS : HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t OsalUnregisterIrq(uint32_t irqId, void *dev)
|
||||
{
|
||||
intr_handle_data_t *handle;
|
||||
if (irqId > MAX_IRQ_ID)
|
||||
return HDF_FAILURE;
|
||||
handle = OaslIntrHandle[irqId];
|
||||
OaslIntrHandle[irqId] = NULL;
|
||||
if (!handle)
|
||||
return HDF_FAILURE;
|
||||
return (ESP_OK == esp_intr_free(handle)) ? HDF_SUCCESS : HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t OsalEnableIrq(uint32_t irqId)
|
||||
{
|
||||
if (irqId > MAX_IRQ_ID)
|
||||
return HDF_FAILURE;
|
||||
if (!OaslIntrHandle[irqId])
|
||||
return HDF_FAILURE;
|
||||
return (ESP_OK == esp_intr_enable(OaslIntrHandle[irqId])) ? HDF_SUCCESS : HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t OsalDisableIrq(uint32_t irqId)
|
||||
{
|
||||
if (irqId > MAX_IRQ_ID)
|
||||
return HDF_FAILURE;
|
||||
if (!OaslIntrHandle[irqId])
|
||||
return HDF_FAILURE;
|
||||
return (ESP_OK == esp_intr_disable(OaslIntrHandle[irqId])) ? HDF_SUCCESS : HDF_FAILURE;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
# Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
|
||||
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_UART)
|
||||
hdf_driver("uart") {
|
||||
sources = [
|
||||
"uart.c",
|
||||
]
|
||||
#defines = [ "ARM_CMNS=1" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "cmsis_os2.h"
|
||||
#include "device_resource_if.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
#include "hdf_log.h"
|
||||
#include "uart_core.h"
|
||||
#include "uart_if.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t port;
|
||||
uint8_t tx_io;
|
||||
uint8_t rx_io;
|
||||
uint8_t flow_ctrl;
|
||||
uint8_t rts_io;
|
||||
uint8_t cts_io;
|
||||
} uartInfo_t;
|
||||
|
||||
int32_t uartInit(struct UartHost *host);
|
||||
|
||||
int32_t uartDeinit(struct UartHost *host);
|
||||
|
||||
int32_t uartRead(struct UartHost *host, uint8_t *data, uint32_t size);
|
||||
|
||||
int32_t uartWrite(struct UartHost *host, uint8_t *data, uint32_t size);
|
||||
|
||||
int32_t uartGetBaud(struct UartHost *host, uint32_t *baudRate);
|
||||
|
||||
int32_t uartSetBaud(struct UartHost *host, uint32_t baudRate);
|
||||
|
||||
int32_t uartGetAttribute(struct UartHost *host, struct UartAttribute *attribute);
|
||||
|
||||
int32_t uartSetAttribute(struct UartHost *host, struct UartAttribute *attribute);
|
||||
|
||||
int32_t uartSetTransMode(struct UartHost *host, enum UartTransMode mode);
|
||||
|
||||
int32_t uartpollEvent(struct UartHost *host, void *filep, void *table);
|
||||
|
||||
int32_t UartDeviceBind(struct HdfDeviceObject *object);
|
||||
|
||||
int32_t UartDeviceInit(struct HdfDeviceObject *object);
|
||||
|
||||
void UartDeviceRelease(struct HdfDeviceObject *object);
|
||||
|
||||
static const struct UartHostMethod g_uartMethodDefault = {
|
||||
.Init = uartInit,
|
||||
.Deinit = uartDeinit,
|
||||
.Read = uartRead,
|
||||
.Write = uartWrite,
|
||||
.GetAttribute = uartGetAttribute,
|
||||
.GetBaud = uartGetBaud,
|
||||
.pollEvent = uartpollEvent,
|
||||
.SetAttribute = uartSetAttribute,
|
||||
.SetBaud = uartSetBaud,
|
||||
.SetTransMode = uartSetTransMode,
|
||||
};
|
||||
|
||||
static const uartInfo_t uartInfoDefault = {
|
||||
.port = -1,
|
||||
.tx_io = -1,
|
||||
.rx_io = -1,
|
||||
.flow_ctrl = -1,
|
||||
.rts_io = -1,
|
||||
.cts_io = -1,
|
||||
};
|
||||
|
||||
static const struct HdfDriverEntry UartDriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "HDF_PLATFORM_UART",
|
||||
.Bind = UartDeviceBind,
|
||||
.Init = UartDeviceInit,
|
||||
.Release = UartDeviceRelease,
|
||||
};
|
||||
|
||||
HDF_INIT(UartDriverEntry);
|
||||
|
||||
int32_t UartDeviceBind(struct HdfDeviceObject *object)
|
||||
{
|
||||
esp_rom_printf("%s come in\n", __func__);
|
||||
if (object == NULL) {
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
return (UartHostCreate(object) == NULL) ? HDF_FAILURE : HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t UartDeviceInit(struct HdfDeviceObject *object)
|
||||
{
|
||||
int ret;
|
||||
uartInfo_t *dev;
|
||||
struct UartHost *host = NULL;
|
||||
esp_rom_printf("%s come in\n", __func__);
|
||||
|
||||
if (object == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
host = UartHostFromDevice(object);
|
||||
if (host == NULL) {
|
||||
esp_rom_printf("%s: host is null", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
dev = (uartInfo_t *)OsalMemAlloc(sizeof(uartInfo_t));
|
||||
if (dev == NULL) {
|
||||
esp_rom_printf("%s.malloc\n", UartDriverEntry.moduleName);
|
||||
return HDF_DEV_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
ret = memcpy_s(dev, sizeof(uartInfoDefault), &uartInfoDefault, sizeof(uartInfoDefault));
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("memcpy_s fail!\r\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (object->property) {
|
||||
const struct DeviceResourceNode *node = object->property;
|
||||
struct DeviceResourceIface *resource = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
resource->GetUint8(node, "port", &dev->port, -1);
|
||||
resource->GetUint8(node, "tx_io", &dev->tx_io, -1);
|
||||
resource->GetUint8(node, "rx_io", &dev->rx_io, -1);
|
||||
resource->GetUint8(node, "flow_ctrl", &dev->flow_ctrl, -1);
|
||||
resource->GetUint8(node, "rts_io", &dev->rts_io, -1);
|
||||
resource->GetUint8(node, "cts_io", &dev->cts_io, -1);
|
||||
}
|
||||
|
||||
host->priv = dev;
|
||||
host->num = dev->port;
|
||||
host->method = &g_uartMethodDefault;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void UartDeviceRelease(struct HdfDeviceObject *object)
|
||||
{
|
||||
esp_rom_printf("%s come in\n", __func__);
|
||||
struct UartHost *host = NULL;
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
host = UartHostFromDevice(object);
|
||||
if (host == NULL) {
|
||||
esp_rom_printf("%s: host is null", __func__);
|
||||
return;
|
||||
}
|
||||
if (host->priv != NULL) {
|
||||
host->priv = NULL;
|
||||
}
|
||||
OsalMemFree(host->priv);
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "cmsis_os2.h"
|
||||
#include "device_resource_if.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
#include "hdf_log.h"
|
||||
#include "watchdog_core.h"
|
||||
|
||||
#define RWDT_PROTECT_KEY 0x50d83aa1
|
||||
#define RWDT_PROTECT 0x3ff480a4
|
||||
#define RWDT_CFG0 0x3ff4808c
|
||||
#define RWDT_CFG0_VALUE ((1 << 10) | (7 << 11) | (3 << 28) | (1 << 31))
|
||||
#define RWDT_CFG1 0x3ff48090
|
||||
#define RWDT_FEED 0x3ff480a0
|
||||
#define RWDT_TICKS_TYPE 0x3ff48070
|
||||
#define RWDT_WOG_VALUE (1 << 31)
|
||||
#define RWDT_IS_RUN_BIT (1 << 31)
|
||||
#define OFFSET_30 30
|
||||
#define BIT_3 3
|
||||
#define SLOW_CK_TICKS (150 * 1000)
|
||||
#define XTAL_32K_TICKS (32768)
|
||||
#define CK8M_D256_OUT_CK_TICKS (8 * 1000 * 1000 / 256)
|
||||
#define WATCHDOG_TIMEOUT 5
|
||||
static int32_t WatchdogDeviceInit(struct HdfDeviceObject *object);
|
||||
static int32_t WatchdogDeviceBind(struct HdfDeviceObject *object);
|
||||
static void WatchdogDeviceRelease(struct HdfDeviceObject *object);
|
||||
|
||||
static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *wdt, int32_t *status);
|
||||
static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *wdt, uint32_t seconds);
|
||||
static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *wdt, uint32_t *seconds);
|
||||
static int32_t WatchdogDevStart(struct WatchdogCntlr *wdt);
|
||||
static int32_t WatchdogDevStop(struct WatchdogCntlr *wdt);
|
||||
static int32_t WatchdogDevFeed(struct WatchdogCntlr *wdt);
|
||||
static int32_t WatchdogDevGetPriv(struct WatchdogCntlr *wdt);
|
||||
static void WatchdogDevReleasePriv(struct WatchdogCntlr *wdt);
|
||||
|
||||
typedef struct {
|
||||
struct WatchdogCntlr cntlr;
|
||||
uint32_t timeout;
|
||||
} PrivWatchdog_t;
|
||||
|
||||
static struct WatchdogMethod WatchdogCntlrMethod = {
|
||||
.getStatus = WatchdogDevGetStatus,
|
||||
.setTimeout = WatchdogDevSetTimeout,
|
||||
.getTimeout = WatchdogDevGetTimeout,
|
||||
.start = WatchdogDevStart,
|
||||
.stop = WatchdogDevStop,
|
||||
.feed = WatchdogDevFeed,
|
||||
.getPriv = NULL,
|
||||
.releasePriv = NULL};
|
||||
|
||||
static const struct HdfDriverEntry WatchdogDriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "HDF_WATCHDOG_MODULE",
|
||||
.Bind = WatchdogDeviceBind,
|
||||
.Init = WatchdogDeviceInit,
|
||||
.Release = WatchdogDeviceRelease,
|
||||
};
|
||||
|
||||
#define DriverEntry WatchdogDriverEntry
|
||||
HDF_INIT(WatchdogDriverEntry);
|
||||
|
||||
static uint32_t GetRwdtTicksType()
|
||||
{
|
||||
volatile uint32_t *ptr = RWDT_TICKS_TYPE;
|
||||
return (((*ptr) >> OFFSET_30) & BIT_3);
|
||||
}
|
||||
|
||||
static void RWDT_WOG(void)
|
||||
{
|
||||
*(volatile uint32_t *)RWDT_FEED = RWDT_WOG_VALUE;
|
||||
}
|
||||
|
||||
static uint32_t RWDT_IS_RUN(void)
|
||||
{
|
||||
return (*(volatile uint32_t *)RWDT_CFG0) & RWDT_IS_RUN_BIT;
|
||||
}
|
||||
|
||||
static int32_t WatchdogDeviceInit(struct HdfDeviceObject *object)
|
||||
{
|
||||
if (!object)
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
PrivWatchdog_t *dev;
|
||||
int ret;
|
||||
dev = (PrivWatchdog_t *)OsalMemAlloc(sizeof(PrivWatchdog_t));
|
||||
if (dev == NULL) {
|
||||
HDF_LOGE("%s.malloc\n", DriverEntry.moduleName);
|
||||
return HDF_DEV_ERR_NO_MEMORY;
|
||||
}
|
||||
ret = memset_s(dev, sizeof(PrivWatchdog_t), 0, sizeof(PrivWatchdog_t));
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("memset_s fail!\r\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
object->priv = (void *)dev;
|
||||
object->service = &dev->cntlr.service;
|
||||
dev->timeout = WATCHDOG_TIMEOUT;
|
||||
dev->cntlr.wdtId = 0;
|
||||
dev->cntlr.device = object;
|
||||
dev->cntlr.ops = &WatchdogCntlrMethod;
|
||||
dev->cntlr.priv = (void *)dev;
|
||||
if (WatchdogCntlrAdd(&dev->cntlr) != HDF_SUCCESS) {
|
||||
OsalMemFree(dev);
|
||||
HDF_LOGE("%s.WatchdogCntlrAdd\n", DriverEntry.moduleName);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
static int32_t WatchdogDeviceBind(struct HdfDeviceObject *object)
|
||||
{
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
static void WatchdogDeviceRelease(struct HdfDeviceObject *object)
|
||||
{
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
if (object->priv) {
|
||||
return;
|
||||
}
|
||||
WatchdogDevStop(&((PrivWatchdog_t *)object->priv)->cntlr);
|
||||
OsalMemFree(object->priv);
|
||||
object->priv = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *wdt, int32_t *status)
|
||||
{
|
||||
if (!wdt) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (status) {
|
||||
*status = RWDT_IS_RUN() ? 1 : 0;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *wdt, uint32_t seconds)
|
||||
{
|
||||
if (!wdt)
|
||||
return HDF_FAILURE;
|
||||
if (!wdt->priv)
|
||||
return HDF_FAILURE;
|
||||
((PrivWatchdog_t *)wdt->priv)->timeout = seconds;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *wdt, uint32_t *seconds)
|
||||
{
|
||||
if (!wdt)
|
||||
return HDF_FAILURE;
|
||||
if (seconds) {
|
||||
if (!wdt->priv)
|
||||
return HDF_FAILURE;
|
||||
*seconds = ((PrivWatchdog_t *)wdt->priv)->timeout;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
static int32_t WatchdogDevStart(struct WatchdogCntlr *wdt)
|
||||
{
|
||||
uint32_t ticks;
|
||||
if (!wdt)
|
||||
return HDF_FAILURE;
|
||||
if (!wdt->priv)
|
||||
return HDF_FAILURE;
|
||||
switch (GetRwdtTicksType()) {
|
||||
case 1:
|
||||
ticks = XTAL_32K_TICKS;
|
||||
break; // XTAL_32K
|
||||
case 2:
|
||||
ticks = CK8M_D256_OUT_CK_TICKS;
|
||||
break; // CK8M_D256_OUT
|
||||
default:
|
||||
ticks = SLOW_CK_TICKS;
|
||||
break; // SLOW_CK
|
||||
}
|
||||
// ====== RTC_WDT_CFG0
|
||||
/* 7: pause WDT in sleep */
|
||||
/* 8: enable WDT reset APP CPU */
|
||||
/* 9: enable WDT reset PRO CPU */
|
||||
/* 10: enable WDT in flash boot */
|
||||
/* 11-13: system reset counter length */
|
||||
/* 14-16: CPU reset counter length */
|
||||
/* 17: When set, level type interrupt generation is enabled */
|
||||
/* 18: When set, edge type interrupt generation is enabled */
|
||||
/* 19-21: 1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en */
|
||||
/* 22-24: 1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en */
|
||||
/* 25-27: 1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en */
|
||||
/* 28-30: 1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en */
|
||||
/* 31: enable RTC WDT */
|
||||
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
|
||||
RWDT_WOG();
|
||||
*(volatile uint32_t *)RWDT_CFG0 = RWDT_CFG0_VALUE;
|
||||
// 最大超时时间 4G / (150K 或 32768 或 8M/256)
|
||||
*(volatile uint32_t *)RWDT_CFG1 = ((PrivWatchdog_t *)wdt->priv)->timeout * ticks;
|
||||
*(volatile uint32_t *)RWDT_PROTECT = 0;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
static int32_t WatchdogDevStop(struct WatchdogCntlr *wdt)
|
||||
{
|
||||
if (!wdt) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (!RWDT_IS_RUN()) {
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
|
||||
RWDT_WOG();
|
||||
*(volatile uint32_t *)RWDT_CFG0 = 0;
|
||||
*(volatile uint32_t *)RWDT_PROTECT = 0;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t WatchdogDevFeed(struct WatchdogCntlr *wdt)
|
||||
{
|
||||
if (!wdt) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
|
||||
RWDT_WOG();
|
||||
*(volatile uint32_t *)RWDT_PROTECT = 0;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
static int32_t WatchdogDevGetPriv(struct WatchdogCntlr *wdt)
|
||||
{
|
||||
if (!wdt) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
static void WatchdogDevReleasePriv(struct WatchdogCntlr *wdt)
|
||||
{
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
# Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
|
||||
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_WIFI)
|
||||
hdf_driver("wifi_sta") {
|
||||
sources = [
|
||||
"wifi_sta.c",
|
||||
]
|
||||
include_dirs = [
|
||||
"//foundation/communication/wifi_lite/interfaces/wifiservice",
|
||||
"//device/soc/esp/esp32/components/lwip/include/apps",
|
||||
"//device/soc/esp/esp32/components/lwip/include/apps/sntp",
|
||||
"//device/soc/esp/esp32/components/lwip/lwip/src/include",
|
||||
"//device/soc/esp/esp32/components/lwip/port/esp32/include",
|
||||
"//device/soc/esp/esp32/components/lwip/port/esp32/include/arch",
|
||||
"//device/soc/esp/esp32/components/esp_common/include",
|
||||
"//device/soc/esp/esp32/components",
|
||||
"//device/soc/esp/esp32/components/freertos/include",
|
||||
"//device/soc/esp/esp32/components/freertos/port/xtensa/include",
|
||||
"//device/soc/esp/esp32/components/xtensa/include",
|
||||
"//device/soc/esp/esp32/components/xtensa/esp32/include",
|
||||
"//device/soc/esp/esp32/components/esp_rom/include",
|
||||
"//device/soc/esp/esp32/components/spi_flash/sim/stubs/esp_timer/include",
|
||||
"//device/soc/esp/esp32/components/esp_system/include",
|
||||
"//device/soc/esp/esp32/components/newlib/platform_include",
|
||||
"//device/soc/esp/esp32/components/esp_hw_support/include",
|
||||
"//device/soc/esp/esp32/components/hal/include",
|
||||
"//device/soc/esp/esp32/components/soc/esp32/include",
|
||||
"//device/soc/esp/esp32/components/hal/esp32/include",
|
||||
"//device/soc/esp/esp32/components/soc/include",
|
||||
"//device/soc/esp/esp32/components/heap/include",
|
||||
]
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __WIFI_H__
|
||||
#define __WIFI_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void OnWifiConnectSocket(int port, const char *ip); // 指定端口连接socket
|
||||
void OnWifiConnectDevice(const char *wifi_name, const char *wifi_pwd); // 指定wifi名和密码进行连接wifi设备
|
||||
int32_t GetWifiConnectStatus(void); // 获取wifi连接状态
|
||||
int32_t getmac(uint8_t *mac); // 获取以太网mac地址
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP32_WIFI_H__ */
|
||||
@@ -1,270 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "cmsis_os2.h"
|
||||
#include "device_resource_if.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
#include "hdf_log.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_task.h"
|
||||
#include "lwip/netifapi.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "ohos_init.h"
|
||||
#include "ohos_types.h"
|
||||
#include "stdio.h"
|
||||
#include "wifi.h"
|
||||
#include "wifi_device.h"
|
||||
|
||||
#define TICK_COUNT 1000
|
||||
|
||||
#define INDEX_0 0
|
||||
#define INDEX_1 1
|
||||
#define INDEX_2 2
|
||||
#define INDEX_3 3
|
||||
#define INDEX_4 4
|
||||
#define INDEX_5 5
|
||||
#define INDEX_6 6
|
||||
#define INDEX_7 7
|
||||
#define INDEX_8 8
|
||||
#define INDEX_9 9
|
||||
|
||||
#define MOV_8 8
|
||||
#define MOV_16 16
|
||||
#define MOV_24 24
|
||||
|
||||
|
||||
INT32 app_main2(void);
|
||||
int32_t EnableWifi(void);
|
||||
int32_t DisableWifi(void);
|
||||
int32_t Scan(void);
|
||||
int32_t GetScanInfoList(WifiScanInfo *result, unsigned int *size);
|
||||
int32_t AddDeviceConfig(const WifiDeviceConfig *config, int *result);
|
||||
int32_t ConnectTo(int networkId);
|
||||
int32_t RegisterWifiEvent_(WifiEvent *arg);
|
||||
int32_t GetWifiConnectStatus(void);
|
||||
void OnWifiConnectDevice(const char *wifi_name, const char *wifi_pwd);
|
||||
|
||||
static int32_t DeviceInit(struct HdfDeviceObject *object);
|
||||
static int32_t DeviceBind(struct HdfDeviceObject *object);
|
||||
static void DeviceRelease(struct HdfDeviceObject *object);
|
||||
|
||||
static const struct HdfDriverEntry WIFI_DriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "HDF_WIFI_MODULE",
|
||||
.Bind = DeviceBind,
|
||||
.Init = DeviceInit,
|
||||
.Release = DeviceRelease,
|
||||
};
|
||||
HDF_INIT(WIFI_DriverEntry);
|
||||
|
||||
typedef struct {
|
||||
uint32_t mode;
|
||||
} DeviceInfo_t;
|
||||
|
||||
static const DeviceInfo_t DeviceInfoDefault = {
|
||||
.mode = -1,
|
||||
};
|
||||
|
||||
// static const char TAG[]={"WIFI_STA"};
|
||||
int g_wifiState = 0;
|
||||
|
||||
static void Delay(uint32_t ms)
|
||||
{
|
||||
osDelay(ms * osKernelGetTickFreq() / TICK_COUNT);
|
||||
}
|
||||
|
||||
/** Connection state change */
|
||||
static void OnWifiConnectionChanged(int state, WifiLinkedInfo *info)
|
||||
{
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
HDF_LOGE("%s , state = %d \r\n", __FUNCTION__, state);
|
||||
g_wifiState = state;
|
||||
}
|
||||
|
||||
static int print_ap_info(WifiScanInfo *ap_info, int max_num)
|
||||
{
|
||||
int index = -1;
|
||||
for (unsigned int i = 0; i < max_num; ++i) {
|
||||
HDF_LOGE("SSID\t\t%s\nRSSI\t\t%d\nfrequency\t%d\n", ap_info[i].ssid,
|
||||
ap_info[i].rssi, ap_info[i].frequency);
|
||||
HDF_LOGE("MAC \t\t%02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
ap_info[i].bssid[INDEX_0], ap_info[i].bssid[INDEX_1],
|
||||
ap_info[i].bssid[INDEX_2], ap_info[i].bssid[INDEX_3],
|
||||
ap_info[i].bssid[INDEX_4], ap_info[i].bssid[INDEX_5]);
|
||||
if (!strcmp((const char *)ap_info[i].ssid, "HUAWEIP40")) {
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
static void OnWifiScanStateChanged(int state, int size)
|
||||
{
|
||||
int ret;
|
||||
unsigned int maxi = size;
|
||||
if (!state || (size <= 0)) {
|
||||
return;
|
||||
}
|
||||
WifiScanInfo *ap_info = (WifiScanInfo *)malloc(sizeof(WifiScanInfo) * size);
|
||||
if (ap_info == NULL) {
|
||||
HDF_LOGE("malloc WifiScanInfo fail!\r\n");
|
||||
return;
|
||||
}
|
||||
WifiErrorCode error = GetScanInfoList(ap_info, &maxi);
|
||||
if (error != WIFI_SUCCESS || maxi == 0) {
|
||||
HDF_LOGE("WIFI NOT SUCCESS in GetScanInfoList\r\n");
|
||||
return;
|
||||
}
|
||||
WifiDeviceConfig config = {0};
|
||||
int index = print_ap_info(ap_info, maxi);
|
||||
if (index >= 0) {
|
||||
int netId = 0;
|
||||
HDF_LOGE("connect:%s\n", ap_info[index].ssid);
|
||||
config.freq = ap_info[index].frequency;
|
||||
config.securityType = ap_info[index].securityType;
|
||||
config.wapiPskType = WIFI_PSK_TYPE_ASCII;
|
||||
ret = memcpy_s(config.bssid, sizeof(config.bssid), ap_info[index].bssid, WIFI_MAC_LEN);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("memcpy_s bssid fail!\r\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = strcpy_s(config.ssid, sizeof(config.bssid), ap_info[index].ssid);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("strcpy_s ssid fail!\r\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
free(ap_info);
|
||||
ret = strcpy_s(config.preSharedKey, sizeof(config.preSharedKey), "houpengfei8");
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("strcpy_s password fail!\r\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
AddDeviceConfig(&config, &netId);
|
||||
ConnectTo(netId);
|
||||
} else {
|
||||
free(ap_info);
|
||||
}
|
||||
}
|
||||
|
||||
/** Hotspot state change */
|
||||
void OnHotspotStateChanged(int state)
|
||||
{
|
||||
HDF_LOGE("%s state = %X\r\n", __FUNCTION__, state);
|
||||
}
|
||||
/** Station connected */
|
||||
void OnHotspotStaJoin(StationInfo *info)
|
||||
{
|
||||
if (!info) {
|
||||
HDF_LOGE("%s info=NULL\n", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
HDF_LOGE("%s name:%s mac:%02X:%02X:%02X:%02X:%02X:%02X ip:%d.%d.%d.%d connect:%d\r\n", __FUNCTION__, info->name,
|
||||
info->macAddress[INDEX_0], info->macAddress[INDEX_1], info->macAddress[INDEX_2],
|
||||
info->macAddress[INDEX_3], info->macAddress[INDEX_4], info->macAddress[INDEX_5],
|
||||
(info->ipAddress >> MOV_24) & 0xFF, (info->ipAddress >> MOV_16) & 0xFF,
|
||||
(info->ipAddress >> MOV_8) & 0xFF, (info->ipAddress) & 0xFF,
|
||||
info->disconnectedReason);
|
||||
}
|
||||
/** Station disconnected */
|
||||
void OnHotspotStaLeave(StationInfo *info)
|
||||
{
|
||||
if (!info) {
|
||||
HDF_LOGE("%s info=NULL\n", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
HDF_LOGE("%s name:%s mac:%02X:%02X:%02X:%02X:%02X:%02X ip:%d.%d.%d.%d connect:%d\r\n", __FUNCTION__, info->name,
|
||||
info->macAddress[INDEX_0], info->macAddress[INDEX_1], info->macAddress[INDEX_2],
|
||||
info->macAddress[INDEX_3], info->macAddress[INDEX_4], info->macAddress[INDEX_5],
|
||||
(info->ipAddress >> MOV_24) & 0xFF, (info->ipAddress >> MOV_16) & 0xFF,
|
||||
(info->ipAddress >> MOV_8) & 0xFF, (info->ipAddress) & 0xFF, info->disconnectedReason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief WiFi连接程序,CMSIS线程回调函数
|
||||
* @param arg 线程参数
|
||||
*/
|
||||
static void IotWifiConnectTask(void)
|
||||
{
|
||||
WifiEvent eventListener = {
|
||||
.OnWifiConnectionChanged = OnWifiConnectionChanged,
|
||||
.OnWifiScanStateChanged = OnWifiScanStateChanged,
|
||||
.OnHotspotStateChanged = OnHotspotStateChanged,
|
||||
.OnHotspotStaJoin = OnHotspotStaJoin,
|
||||
.OnHotspotStaLeave = OnHotspotStaLeave};
|
||||
g_wifiState = 0;
|
||||
RegisterWifiEvent_(&eventListener);
|
||||
|
||||
WifiErrorCode error = EnableWifi();
|
||||
HDF_LOGE("EnableWifi errCode: %d\r\n", error);
|
||||
if (error != WIFI_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
error = Scan();
|
||||
HDF_LOGE("ScanWifi errCode: %d\r\n", error);
|
||||
if (error != WIFI_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
OnWifiConnectDevice("HUAWEIP40", "houpengfei8");
|
||||
HDF_LOGE("GetWifiConnectStatus: %d\r\n", GetWifiConnectStatus());
|
||||
}
|
||||
static int32_t DeviceInit(struct HdfDeviceObject *object)
|
||||
{
|
||||
DeviceInfo_t *dev;
|
||||
int ret;
|
||||
if (object == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
dev = (DeviceInfo_t *)OsalMemAlloc(sizeof(DeviceInfo_t));
|
||||
if (dev == NULL) {
|
||||
HDF_LOGE("%s.malloc\n", WIFI_DriverEntry.moduleName);
|
||||
return HDF_DEV_ERR_NO_MEMORY;
|
||||
}
|
||||
object->priv = (void *)dev;
|
||||
ret = memcpy_s(dev, sizeof(DeviceInfoDefault), &DeviceInfoDefault, sizeof(DeviceInfoDefault));
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("memcpy_s DeviceInfoDefault fail!\r\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (object->property) {
|
||||
const struct DeviceResourceNode *node = object->property;
|
||||
struct DeviceResourceIface *resource = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
resource->GetUint32(node, "mode", &dev->mode, -1);
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t DeviceBind(struct HdfDeviceObject *object)
|
||||
{
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void DeviceRelease(struct HdfDeviceObject *object)
|
||||
{
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
if (object->priv) {
|
||||
DeviceInfo_t *dev = (DeviceInfo_t *)object->priv;
|
||||
OsalMemFree(object->priv);
|
||||
}
|
||||
object->priv = NULL;
|
||||
}
|
||||
@@ -14,23 +14,11 @@
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
# module_switch = defined(LOSCFG_FS_LITTLEFS)
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"driver/hm_sys.c",
|
||||
"driver/hal_watchdog.c",
|
||||
"libc/syscalls.c",
|
||||
"libc/log.c",
|
||||
module_group(module_name) {
|
||||
modules = [
|
||||
"drivers",
|
||||
"log",
|
||||
"memory",
|
||||
"syscalls",
|
||||
]
|
||||
include_dirs = [
|
||||
"//utils/native/lite/memory/include",
|
||||
"//base/hiviewdfx/hiview_lite",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/mini",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr"
|
||||
]
|
||||
deps = [
|
||||
"driver/wifi_lite",
|
||||
"driver/bluetooth_lite"
|
||||
]
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define RWDT_PROTECT_KEY 0x50d83aa1
|
||||
#define RWDT_PROTECT 0x3ff480a4
|
||||
#define RWDT_CFG0 0x3ff4808c
|
||||
#define RWDT_CFG0_VALUE ((1 << 10) | (7 << 11) | (3 << 28) | (1 << 31))
|
||||
#define RWDT_CFG1 0x3ff48090
|
||||
#define RWDT_FEED 0x3ff480a0
|
||||
#define RWDT_TICKS_TYPE 0x3ff48070
|
||||
#define RWDT_WOG_VALUE (1 << 31)
|
||||
#define RWDT_IS_RUN_BIT (1 << 31)
|
||||
#define OFFSET_30 30
|
||||
#define BIT_3 3
|
||||
#define SLOW_CK_TICKS (150 * 1000)
|
||||
#define XTAL_32K_TICKS (32768)
|
||||
#define CK8M_D256_OUT_CK_TICKS (8 * 1000 * 1000 / 256)
|
||||
|
||||
static uint32_t GetRwdtTicksType(void)
|
||||
{
|
||||
volatile uint32_t *ptr = RWDT_TICKS_TYPE;
|
||||
return (((*ptr) >> OFFSET_30) & BIT_3);
|
||||
}
|
||||
|
||||
static void RWDT_WOG(void)
|
||||
{
|
||||
*(volatile uint32_t *)RWDT_FEED = RWDT_WOG_VALUE;
|
||||
}
|
||||
|
||||
static uint32_t RWDT_IS_RUN(void)
|
||||
{
|
||||
return (*(volatile uint32_t *)RWDT_CFG0) & RWDT_IS_RUN_BIT;
|
||||
}
|
||||
|
||||
void WdtEnable(void)
|
||||
{
|
||||
uint32_t ticks;
|
||||
if (RWDT_IS_RUN()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (GetRwdtTicksType()) {
|
||||
case 1:
|
||||
ticks = XTAL_32K_TICKS;
|
||||
break; // XTAL_32K
|
||||
case 2:
|
||||
ticks = CK8M_D256_OUT_CK_TICKS;
|
||||
break; // CK8M_D256_OUT
|
||||
default:
|
||||
ticks = SLOW_CK_TICKS;
|
||||
break; // SLOW_CK
|
||||
}
|
||||
|
||||
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
|
||||
RWDT_WOG();
|
||||
*(volatile uint32_t *)RWDT_CFG0 = RWDT_CFG0_VALUE;
|
||||
*(volatile uint32_t *)RWDT_CFG1 = 5 * ticks; // 最大超时时间 4G / (150K 或 32768 或 8M/256)
|
||||
*(volatile uint32_t *)RWDT_PROTECT = 0;
|
||||
}
|
||||
|
||||
void WdtDisable(void)
|
||||
{
|
||||
if (!RWDT_IS_RUN()) {
|
||||
return;
|
||||
}
|
||||
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
|
||||
RWDT_WOG();
|
||||
*(volatile uint32_t *)RWDT_CFG0 = 0;
|
||||
*(volatile uint32_t *)RWDT_PROTECT = 0;
|
||||
}
|
||||
|
||||
void WdtFeed(void)
|
||||
{
|
||||
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
|
||||
RWDT_WOG();
|
||||
*(volatile uint32_t *)RWDT_PROTECT = 0;
|
||||
}
|
||||
|
||||
void IoTWatchDogEnable(void)
|
||||
{
|
||||
WdtEnable();
|
||||
}
|
||||
|
||||
void IoTWatchDogKick(void)
|
||||
{
|
||||
WdtFeed();
|
||||
}
|
||||
|
||||
void IoTWatchDogDisable(void)
|
||||
{
|
||||
WdtDisable();
|
||||
}
|
||||
Executable → Regular
+6
-11
@@ -11,17 +11,12 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//drivers/hdf_core/adapter/khdf/liteos_m/hdf.gni")
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_group("drivers") {
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
module_group(module_name) {
|
||||
modules = [
|
||||
# "osal",
|
||||
# "watchdog",
|
||||
# "wifi",
|
||||
# "adc",
|
||||
# "gpio",
|
||||
# "uart",
|
||||
# "i2c",
|
||||
"bluetooth_lite",
|
||||
"wifi_lite",
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+12
-12
@@ -11,20 +11,20 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_DRIVERS_HDF)
|
||||
module_name = "esp_osal"
|
||||
hdf_driver(module_name) {
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"osal.c",
|
||||
]
|
||||
include_dirs = [
|
||||
"../../../../components/esp_system/include",
|
||||
"../../../../components/esp_common/include"
|
||||
"log.c",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
config("public"){
|
||||
include_dirs = [
|
||||
"//base/hiviewdfx/hiview_lite",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/mini",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr"
|
||||
]
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
void mbedtls_test(void)
|
||||
{
|
||||
}
|
||||
Executable → Regular
+9
-8
@@ -11,16 +11,17 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C)
|
||||
module_name = "i2c"
|
||||
hdf_driver(module_name) {
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"i2c.c",
|
||||
"ohos_mem_pool.c",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
config("public"){
|
||||
include_dirs = [
|
||||
"//utils/native/lite/memory/include",
|
||||
]
|
||||
}
|
||||
@@ -11,14 +11,18 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
|
||||
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_ADC)
|
||||
hdf_driver("adc") {
|
||||
sources = [
|
||||
"adc.c",
|
||||
]
|
||||
}
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"syscalls.c",
|
||||
]
|
||||
include_dirs = [
|
||||
"//utils/native/lite/memory/include",
|
||||
"//base/hiviewdfx/hiview_lite",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/mini",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr"
|
||||
]
|
||||
}
|
||||
@@ -15,30 +15,35 @@ import("//kernel/liteos_m/liteos.gni")
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"target_run.c",
|
||||
"target_startup.o",
|
||||
]
|
||||
include_dirs = [
|
||||
"//kernel/liteos_m/include",
|
||||
"//kernel/liteos_m/kernel/include",
|
||||
"//utils/native/lite/include",
|
||||
"//utils/native/lite/memory/include",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
"//base/hiviewdfx/hiview_lite",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/mini",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
|
||||
"//drivers/framework/core/common/include/manager",
|
||||
"src/target_run.c",
|
||||
]
|
||||
deps = [
|
||||
":target_startup",
|
||||
"//vendor/openvalley/niobeu4/demo:demo",
|
||||
]
|
||||
}
|
||||
|
||||
lite_library("target_startup") {
|
||||
target_type = "static_library"
|
||||
sources = []
|
||||
deps = [
|
||||
":copy_target_startup"
|
||||
]
|
||||
}
|
||||
|
||||
build_ext_component("copy_target_startup") {
|
||||
exec_path = rebase_path(".", root_build_dir)
|
||||
out_root_path = rebase_path(root_out_dir)
|
||||
command = "cp lib/libtarget_startup.a $out_root_path/libs/libtarget_startup.a"
|
||||
}
|
||||
|
||||
|
||||
|
||||
config("public") {
|
||||
ESP_SDK_PATH="//device/soc/esp/esp32/components/"
|
||||
include_dirs = [
|
||||
".",
|
||||
"../include",
|
||||
"include",
|
||||
ESP_SDK_PATH+"esp_rom/include",
|
||||
ESP_SDK_PATH+"esp_rom/esp32",
|
||||
ESP_SDK_PATH+"esp_rom/include/esp32",
|
||||
|
||||
BIN
Binary file not shown.
Executable → Regular
+6
-9
@@ -11,13 +11,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG)
|
||||
module_name = "watchdog"
|
||||
hdf_driver(module_name) {
|
||||
sources = [
|
||||
"watchdog.c",
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
module_group(module_name) {
|
||||
modules = [
|
||||
"littlefs",
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
+1
-3
@@ -19,8 +19,6 @@ config("mbedtls_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//third_party/mbedtls/include",
|
||||
# "//device/soc/esp/esp32/components/mbedtls/port/include",
|
||||
"//device/soc/esp/esp32/components",
|
||||
]
|
||||
defines += [
|
||||
"MBEDTLS_CONFIG_FILE=\"mbedtls/config.h\"",
|
||||
@@ -28,6 +26,6 @@ config("mbedtls_config") {
|
||||
}
|
||||
|
||||
group("mbedtls") {
|
||||
public_deps = [ ]
|
||||
public_deps = []
|
||||
public_configs = [ ":mbedtls_config" ]
|
||||
}
|
||||
Reference in New Issue
Block a user