Skip to content

Commit d4337d3

Browse files
wuxn9999YiluMao
authored andcommitted
IssueID:1909:New RTC device driver framework
[Detail] New RTC device driver framework. [Verified Cases] Build Pass: helloworld_demo@haaseduk1 Test Pass: helloworld_demo@haaseduk1
1 parent 8745cb9 commit d4337d3

File tree

4 files changed

+452
-0
lines changed

4 files changed

+452
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (C) 2021-2022 Alibaba Group Holding Limited
3+
*/
4+
5+
#ifndef AOS_RTC_H
6+
#define AOS_RTC_H
7+
8+
#ifdef AOS_KERNEL_BUILD
9+
#include <aos/device.h>
10+
#else
11+
#include <stdint.h>
12+
#endif
13+
14+
/**
15+
* @defgroup rtc_api RTC
16+
* @ingroup driver_api
17+
* @brief AOS API for RTC.
18+
* @{
19+
*/
20+
21+
typedef struct {
22+
uint64_t year : 22;
23+
uint64_t month : 4; /* 1 ~ 12 */
24+
uint64_t mday : 5;
25+
uint64_t hour : 5;
26+
uint64_t min : 6;
27+
uint64_t sec : 6;
28+
uint64_t reserved : 16; /* Reserved for millisecond, leap second flag, etc. */
29+
} aos_rtc_time_t;
30+
31+
#if (defined(AOS_KERNEL_BUILD) && defined(AOS_COMP_DEVFS)) || !defined(AOS_KERNEL_BUILD)
32+
33+
#define AOS_RTC_IOC_GET_TIME 0x5201
34+
#define AOS_RTC_IOC_SET_TIME 0x5202
35+
36+
#endif /* (defined(AOS_KERNEL_BUILD) && defined(AOS_COMP_DEVFS)) || !defined(AOS_KERNEL_BUILD) */
37+
38+
#ifdef AOS_KERNEL_BUILD
39+
40+
typedef aos_dev_ref_t aos_rtc_ref_t;
41+
42+
#ifdef __cplusplus
43+
extern "C" {
44+
#endif
45+
46+
/**
47+
* @brief Get an RTC device.
48+
* @param ref RTC ref to operate.
49+
* @param id RTC device ID.
50+
* @return 0: on success; < 0: on failure.
51+
*/
52+
aos_status_t aos_rtc_get(aos_rtc_ref_t *ref, uint32_t id);
53+
/**
54+
* @brief Release an RTC device.
55+
* @param ref RTC ref to operate.
56+
* @return None.
57+
*/
58+
void aos_rtc_put(aos_rtc_ref_t *ref);
59+
/**
60+
* @brief Read time from an RTC device.
61+
* @param ref RTC ref to operate.
62+
* @param time Time buffer.
63+
* @return 0: on success; < 0: on failure.
64+
*/
65+
aos_status_t aos_rtc_get_time(aos_rtc_ref_t *ref, aos_rtc_time_t *time);
66+
67+
/**
68+
* @brief Write time to an RTC device.
69+
* @param ref RTC ref to operate.
70+
* @param time Time buffer.
71+
* @return 0: on success; < 0: on failure.
72+
*/
73+
aos_status_t aos_rtc_set_time(aos_rtc_ref_t *ref, const aos_rtc_time_t *time);
74+
75+
#ifdef __cplusplus
76+
}
77+
#endif
78+
79+
#endif /* AOS_KERNEL_BUILD */
80+
81+
/** @} */
82+
83+
#endif /* AOS_RTC_H */
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2021-2022 Alibaba Group Holding Limited
3+
*/
4+
5+
#ifndef AOS_RTC_CORE_H
6+
#define AOS_RTC_CORE_H
7+
8+
#include <aos/device_core.h>
9+
#include <aos/rtc.h>
10+
11+
struct aos_rtc_ops;
12+
13+
typedef struct {
14+
aos_dev_t dev;
15+
16+
/* must be initialized before registration */
17+
const struct aos_rtc_ops *ops;
18+
} aos_rtc_t;
19+
20+
typedef struct aos_rtc_ops {
21+
void (*unregister)(aos_rtc_t *);
22+
aos_status_t (*startup)(aos_rtc_t *);
23+
void (*shutdown)(aos_rtc_t *);
24+
aos_status_t (*get_time)(aos_rtc_t *, aos_rtc_time_t *);
25+
aos_status_t (*set_time)(aos_rtc_t *, const aos_rtc_time_t *);
26+
} aos_rtc_ops_t;
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
aos_status_t aos_rtc_register(aos_rtc_t *rtc);
33+
aos_status_t aos_rtc_register_argumented(aos_rtc_t *rtc, uint32_t id, const aos_rtc_ops_t *ops);
34+
aos_status_t aos_rtc_unregister(uint32_t id);
35+
36+
#ifdef __cplusplus
37+
}
38+
#endif
39+
40+
#endif /* AOS_RTC_CORE_H */
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
## 第一部分:基础信息
2+
name: rtc # <必选项> 包名称 (符合C语言变量命名规则),长度少于等于64字节
3+
version: master # <必选项> 组件版本号
4+
description: RTC通用驱动 # <必选项> 建议至少20字以上
5+
type: common # <必选项> 组件类型,为:solution, chip, board, common, sdk
6+
7+
tag: 第三方驱动 # <可选项> 组件分类,缺省值: ''
8+
keywords: # <可选项> 标签,会影响到组件被搜索的效果,合理的标签很重要
9+
- rtc driver
10+
license: Apache license v2.0 # <可选项> 源代码的许可证,要确保所有代码、文件的许可证不冲突。如:MIT,Apache license v2.0,BSD
11+
12+
## 第二部分:依赖信息
13+
# 指定该组件依赖的组件及版本,版本支持条件比较,支持:>=v1.0, >v1.0, ==v1.0, <=v1.0, <v1.0, v1.0
14+
# 未指定条件时,默认为 ==,如 v1.0 与 ==v1.0
15+
# depends: # <可选项> 该组件依赖其他的组件,合理的依赖才能保证组件能编译、使用
16+
# - minilibc: v7.2.0
17+
# - aos: >=v7.2.0
18+
depends:
19+
- base: master
20+
21+
## 第四部分:编译连接信息
22+
# build_config: # <可选项> 编译配置项
23+
# include: # <可选项> 编译时,影响编译器的-I 参数 ,全局有效
24+
# - src # include 只能是该软件包下的目录,不能使用外部目录
25+
# internal_include: # <可选项> 编译时,影响编译器的-I 参数 ,组件内有效
26+
# - include
27+
# cflag: '' # <可选项> C 编译器所需要要的编译参数
28+
# cxxflag: '' # <可选项> CXX 编译器所需要要的编译参数
29+
# asmflag: '' # <可选项> 汇编器所需要要参数
30+
# define: # <可选项> 宏定义, 增加编译器的-D 选项,如:
31+
# XXX: 1 # -DXXX=1
32+
# AAA: 1 # -DAAA
33+
# STR: "abc" # -DSTR="abc"
34+
# libs: # 该组件中支持的二进制静态库,如:libxxx.a, libyyy.a
35+
# - xxx # -lxxx
36+
# - yyy # -lyyy
37+
# libpath: # 指定静态库所在的路径(相对于该组件路径)
38+
# - libs # -Llibs
39+
build_config:
40+
include:
41+
- include
42+
43+
define:
44+
45+
# source_file: # <可选项> 指定参与编译的源代码文件,支持通配符,采用相对路径
46+
# - src/*.c # 例:组件 src 目录下所有的扩展名为 c 的源代码文件
47+
source_file:
48+
- src/rtc.c
49+
50+
## 第五部分:配置信息
51+
# def_config: # 组件的可配置项
52+
# CONFIG_DEBUG: y
53+
# CONFIG_PARAM_NOT_CHECK: y
54+
# CONFIG_CLI: y
55+
def_config:
56+
AOS_COMP_RTC: 1
57+
58+
## 第六部分:安装信息
59+
# install:
60+
# - dest: include/ # 安装的目的路径 dest是相当路径,通常是相对于YoC SDK 安装目录
61+
# source: # 安装源列表
62+
# - src/*.h # 支持通配符,相对路径
63+
install:
64+
- dest: "include/aos"
65+
source:
66+
- "include/aos/rtc.h"
67+
68+
## 第七部分:导出部分
69+
# export:
70+
# - dest: "<SOLUTION_PATH>/generated/data" # 安装的目的路径 dest是相当路径
71+
# source: # 安装源列表
72+
# - "bootimgs/boot"
73+
# - "bootimgs/tee"
74+
# - "bootimgs/mtb"
75+
# - "configs/config.yaml"

0 commit comments

Comments
 (0)