!48 OPENH-96-hdf-uart-driver

Merge pull request !48 from dimahorbenko/feature/OPENH-96-hdf-uart-driver
This commit is contained in:
openharmony_ci
2023-05-29 02:48:58 +00:00
committed by Gitee
14 changed files with 497 additions and 0 deletions
+1
View File
@@ -4,3 +4,4 @@ LOSCFG_FS_LITTLEFS=y
LOSCFG_DRIVERS_HDF=y
LOSCFG_DRIVERS_HDF_PLATFORM=y
LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
+28
View File
@@ -0,0 +1,28 @@
# Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
# All rights reserved.
#
# 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("//device/soc/telink/util/util.gni")
b91_firmware("uart_demo") {
explicit_libs = [
"bootstrap",
"broadcast",
]
deps = [
"uart_demo",
"//build/lite:ohos",
]
}
+53
View File
@@ -0,0 +1,53 @@
{
"product_name": "uart_demo",
"ohos_version": "OpenHarmony 3.x",
"device_company": "telink",
"board": "b91_devkit",
"kernel_type": "liteos_m",
"kernel_version": "3.0.0",
"subsystems": [
{
"subsystem": "kernel",
"components": [
{ "component": "liteos_m", "features": [] }
]
},
{
"subsystem": "startup",
"components": [
{ "component": "bootstrap_lite", "features":[] },
{
"component": "init_lite",
"features": [
"enable_ohos_startup_init_feature_begetctl_liteos = true",
"enable_ohos_startup_init_lite_use_posix_file_api = true",
"config_ohos_startup_init_lite_data_path = \"/data/\"",
"config_ohos_startup_syspara_lite_data_path = \"/data/\""
]
}
]
},
{
"subsystem": "systemabilitymgr",
"components": [
{ "component": "samgr_lite", "features":[] }
]
},
{
"subsystem": "hiviewdfx",
"components": [
{ "component": "hilog_lite", "features":[] },
{ "component": "hievent_lite", "features":[] }
]
},
{
"subsystem": "commonlibrary",
"components": [
{ "component": "file", "features":[] }
]
}
],
"third_party_dir": "",
"vendor_adapter_dir": "//device/soc/telink/b91/adapter",
"product_adapter_dir": "//vendor/telink/led_demo/hals"
}
+27
View File
@@ -0,0 +1,27 @@
# Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
# All rights reserved.
#
# 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.
static_library("hal_sysparam") {
sources = [ "hal_sys_param.c" ]
include_dirs = [ "//base/startup/init/interfaces/hals" ]
defines = [
"INCREMENTAL_VERSION=\"${ohos_version}\"",
"BUILD_TYPE=\"${ohos_build_type}\"",
"BUILD_USER=\"${ohos_build_user}\"",
"BUILD_TIME=\"${ohos_build_time}\"",
"BUILD_HOST=\"${ohos_build_host}\"",
"BUILD_ROOTHASH=\"${ohos_build_roothash}\"",
]
}
@@ -0,0 +1,26 @@
/******************************************************************************
* Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
* All rights reserved.
*
* 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 "hal_sys_param.h"
static const char OHOS_SERIAL[] = {"1234567890"}; // if not provid serial algorithm,Serial will use this default value.
const char *HalGetSerial(void)
{
return OHOS_SERIAL;
}
@@ -0,0 +1,40 @@
# Copyright (c) 2022 Huawei Device 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.
const.build.characteristics="Evaluation Board"
const.product.manufacturer=Telink
const.product.brand=Telink
const.product.name="B91 Generic Starter Kit"
const.build.product="TLSR9"
const.product.model="v1.0.0"
const.software.model="v1.0.0"
const.product.hardwareversion="v1.3"
const.product.hardwareprofile="BLE:true"
const.ohos.serial=1234567890
const.product.bootloader.version=bootloader
const.product.cpu.abilist=default
const.product.software.version="OpenHarmony 3.x"
const.product.firstapiversion=1
+24
View File
@@ -0,0 +1,24 @@
# Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
# All rights reserved.
#
# 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.
static_library("hal_token_static") {
sources = [ "hal_token.c" ]
include_dirs = [
"//base/startup/init/interfaces/hals",
"//commonlibrary/utils_lite/include",
]
deps = []
}
+108
View File
@@ -0,0 +1,108 @@
/******************************************************************************
* Copyright (c) 2020 Huawei Device Co., Ltd.
* All rights reserved.
*
* 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.
* Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
*
*****************************************************************************/
#include "hal_token.h"
#include "ohos_errno.h"
#include "ohos_types.h"
static int OEMReadToken(char *token, unsigned int len)
{
// OEM need add here, read token from device
(void)(token);
(void)(len);
return EC_SUCCESS;
}
static int OEMWriteToken(const char *token, unsigned int len)
{
// OEM need add here, write token to device
(void)(token);
(void)(len);
return EC_SUCCESS;
}
static int OEMGetAcKey(char *acKey, unsigned int len)
{
// OEM need add here, get AcKey
(void)(acKey);
(void)(len);
return EC_SUCCESS;
}
static int OEMGetProdId(char *productId, unsigned int len)
{
// OEM need add here, get ProdId
(void)(productId);
(void)(len);
return EC_SUCCESS;
}
static int OEMGetProdKey(char *productKey, unsigned int len)
{
// OEM need add here, get ProdKey
(void)(productKey);
(void)(len);
return EC_SUCCESS;
}
int HalReadToken(char *token, unsigned int len)
{
if (token == NULL) {
return EC_FAILURE;
}
return OEMReadToken(token, len);
}
int HalWriteToken(const char *token, unsigned int len)
{
if (token == NULL) {
return EC_FAILURE;
}
return OEMWriteToken(token, len);
}
int HalGetAcKey(char *acKey, unsigned int len)
{
if (acKey == NULL) {
return EC_FAILURE;
}
return OEMGetAcKey(acKey, len);
}
int HalGetProdId(char *productId, unsigned int len)
{
if (productId == NULL) {
return EC_FAILURE;
}
return OEMGetProdId(productId, len);
}
int HalGetProdKey(char *productKey, unsigned int len)
{
if (productKey == NULL) {
return EC_FAILURE;
}
return OEMGetProdKey(productKey, len);
}
+25
View File
@@ -0,0 +1,25 @@
# Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
# All rights reserved.
#
# 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_name = "hdf_hcs"
hdf_driver(module_name) {
hcs_sources = [ "hdf.hcs" ]
visibility += [
"$device_path",
".",
]
}
+1
View File
@@ -0,0 +1 @@
#include "../../../../device/soc/telink/b91/hcs/hdf.hcs"
+7
View File
@@ -0,0 +1,7 @@
LOSCFG_PLATFORM_QEMU_RISCV32_VIRT=y
LOSCFG_SOC_SERIES_B91=y
LOSCFG_FS_LITTLEFS=y
LOSCFG_DRIVERS_HDF=y
LOSCFG_DRIVERS_HDF_PLATFORM=y
LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
+10
View File
@@ -0,0 +1,10 @@
{
"parts": {
"product_uart_demo": {
"module_list": [
"//vendor/telink/uart_demo:uart_demo"
]
}
},
"subsystem": "product_uart_demo"
}
+48
View File
@@ -0,0 +1,48 @@
# Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
# All rights reserved.
#
# 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.
declare_args() {
telink_gpio_irq_sample_enable = false
}
config("myapp_config") {
include_dirs = [ "//commonlibrary/utils_lite/include" ]
configs = [ "//device/soc/telink/b91:B91_config" ]
}
source_set("myapp_inner") {
sources = [ "app.c" ]
deps = [ "//base/hiviewdfx/hiview_lite" ]
if (!defined(defines)) {
defines = []
}
if (telink_gpio_irq_sample_enable) {
defines += [ "TELINK_GPIO_IRQ_SAMPLE_ENABLE=1" ]
} else {
defines += [ "TELINK_GPIO_IRQ_SAMPLE_ENABLE=0" ]
}
configs += [ ":myapp_config" ]
}
static_library("uart_demo") {
deps = [ ":myapp_inner" ]
configs += [ ":myapp_config" ]
}
+99
View File
@@ -0,0 +1,99 @@
/******************************************************************************
* Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
* All rights reserved.
*
* 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 <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <los_task.h>
#include <los_arch_interrupt.h>
#include <ohos_init.h>
#include <ohos_types.h>
#include <hiview_log.h>
#include <uart_if.h>
#include <board_config.h>
#define UART_TASK_PRIORITY LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO
#define DELAY 2000
#define UART0 0
#define UART1 1
#define BAUD_115200 115200
#define BAUD_921600 921600
uint8_t txbuf[80] = "\nHDF uart test string 1\n";
STATIC VOID uart_test_task(VOID)
{
LOS_TaskDelay(DELAY);
/* See device/soc/telink/b91/hcs/uart/uart_config.hcs
for hdf uart configuration */
DevHandle *uart1 = UartOpen(UART1);
if (uart1 == NULL) {
printf("UartOpen %u: failed!\n", UART1);
}
uint32_t baud;
UartGetBaud(uart1, &baud);
printf("\n%s: Get baudrate %u\r\n", __func__, baud);
baud = BAUD_115200;
UartSetBaud(uart1, baud);
UartGetBaud(uart1, &baud);
printf("%s: Set baudrate %u\r\n", __func__, baud);
baud = BAUD_921600;
UartSetBaud(uart1, baud);
UartGetBaud(uart1, &baud);
printf("%s: Set baudrate %u\r\n", __func__, baud);
uint32_t ret = UartWrite(uart1, txbuf, strlen((char *)txbuf));
if (ret != 0) {
printf("UartWrite %u: failed!\n", UART1);
}
}
void AppMain(void)
{
UINT32 ret;
UINT32 taskId = 0;
TSK_INIT_PARAM_S taskParam = {0};
taskParam.pfnTaskEntry = (TSK_ENTRY_FUNC)uart_test_task;
taskParam.uwArg = 0;
taskParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
taskParam.pcName = "uart_task";
taskParam.usTaskPrio = UART_TASK_PRIORITY;
ret = LOS_TaskCreate(&taskId, &taskParam);
if (ret != LOS_OK) {
HILOG_ERROR(HILOG_MODULE_APP, "ret of LOS_TaskCreate(uart_task) = %#x", ret);
}
}
SYS_RUN(AppMain);