更新硬件SDK

This commit is contained in:
kerwincui
2023-03-04 03:44:56 +08:00
parent dcdf6e1b7c
commit e39d3d2f03
1900 changed files with 663153 additions and 0 deletions

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef Luat_ADC_H
#define Luat_ADC_H
#include "luat_base.h"
#include "luat_adc_legacy.h"
#define LUAT_ADC_CH_CPU (-1)
#define LUAT_ADC_CH_VBAT (-2)
/**
* @ingroup luatos_device 外设接口
* @{
*/
/**
* @defgroup luatos_device_adc ADC接口
* @{
*/
/**
* luat_adc_open
* @brief 打开一个adc通道
*
* @param pin[in] adc通道的序号
* @param args[in] 保留用,传NULL
* @return 0 成功, 其他值为失败
*/
int luat_adc_open(int pin, void *args);
/**
* luat_adc_read
* @brief 读取adc通道的值
*
* @param pin[in] adc通道的序号
* @param val[out] adc通道的原始值
* @param val2[out] adc通道的计算值,与具体通道有关
* @return 0 成功, 其他值为失败
*/
int luat_adc_read(int pin, int *val, int *val2);
/**
* luat_adc_close
* @brief 关闭adc通道
*
* @param pin[in] adc通道的序号
* @return 0 成功, 其他值为失败
*/
int luat_adc_close(int pin);
/**
* @brief ADC控制命令
*/
typedef enum LUAT_ADC_CTRL_CMD
{
LUAT_ADC_SET_GLOBAL_RANGE,/**< 量程 */
}LUAT_ADC_CTRL_CMD_E;
/**
* @brief ADC测量范围量程,和具体的芯片有关移芯618芯片LUAT_ADC_RANGE_1_2表示1.2V,内部无分压,其余量程内部都有分压
*/
typedef enum LUAT_ADC_RANGE
{
LUAT_ADC_AIO_RANGE_1_2,
LUAT_ADC_AIO_RANGE_1_4,
LUAT_ADC_AIO_RANGE_1_6,
LUAT_ADC_AIO_RANGE_1_9,
LUAT_ADC_AIO_RANGE_2_4,
LUAT_ADC_AIO_RANGE_2_7,
LUAT_ADC_AIO_RANGE_3_2,
LUAT_ADC_AIO_RANGE_3_8,
// 不再支持以下配置,无意义
// LUAT_ADC_AIO_RANGE_4_8,
// LUAT_ADC_AIO_RANGE_6_4,
// LUAT_ADC_AIO_RANGE_9_6,
// LUAT_ADC_AIO_RANGE_19_2,
LUAT_ADC_VBAT_RANGE_2_0_RATIO,
LUAT_ADC_VBAT_RANGE_2_2_RATIO,
LUAT_ADC_VBAT_RANGE_2_6_RATIO,
LUAT_ADC_VBAT_RANGE_3_2_RATIO,
LUAT_ADC_VBAT_RANGE_4_0_RATIO,
LUAT_ADC_VBAT_RANGE_5_3_RATIO,
LUAT_ADC_VBAT_RANGE_8_0_RATIO,
LUAT_ADC_VBAT_RANGE_16_0_RATIO,
}LUAT_ADC_RANGE_E;
/**
* @brief ADC控制参数
*/
typedef union luat_adc_ctrl_param
{
LUAT_ADC_RANGE_E range;/**< adc量程*/
void *userdata;/**< 预留 */
} luat_adc_ctrl_param_t;
/**
* luat_adc_ctrl
* @brief adc控制
*
* @param pin[in] adc通道的序号
* @param cmd adc控制命令
* @param param adc控制参数
* @return 0 成功, 其他值为失败
*/
int luat_adc_ctrl(int pin, LUAT_ADC_CTRL_CMD_E cmd, luat_adc_ctrl_param_t param);
/** @}*/
/** @}*/
#endif

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef Luat_ADC_LEGACY_H
#define Luat_ADC_LEGACY_H
#include "luat_base.h"
/**
* @brief ADC控制命令
*/
typedef enum
{
ADC_SET_GLOBAL_RANGE = 0x80,/**< 内部分压 */
} ADC_SET_CMD_ENUM;
/**
* luat_adc_global_config
* Description: 设置adc全局参数
* @param tp[in] 参数类型
* @param val[in] 参数值
* @return 0 成功, 其他值为失败
*/
int luat_adc_global_config(int tp, int val);
#endif

View File

@@ -0,0 +1,89 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef Luat_CRYPTO_H
#define Luat_CRYPTO_H
#include "luat_base.h"
/**
* @defgroup luatos_crypto crypto数据加密
* @{
*/
/**
* \brief 进行MD5检验
* \param input 输入的数据
* \param ilen 输入的数据长度
* \param output 输出的MD5检验值
*/
void luat_crypto_md5( unsigned char *input, int ilen, unsigned char output[16] );
/**
* @brief BASE64加密
* @param dst buffer
* @param dlen buffer长度
* @param olen 写入的字节数
* @param src 加密密钥
* @param slen 加密密钥长度
* @return 0成功
*/
int luat_crypto_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen );
/**
* @brief BASE64解密
* @param dst buffer
* @param dlen buffer长度
* @param olen 写入的字节数
* @param src 密钥
* @param slen 密钥长度
* @return 0成功
*/
int luat_crypto_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen );
/**
* @brief 进行SHA1校验
* @param input 输入的数据
* @param ilen 输入的数据长度
* @param output 输出的SHA1检验值
*/
void luat_crypto_sha1(const unsigned char *input, size_t ilen, unsigned char output[20]);
/**
* @brief 进行SHA256校验
* @param input 输入的数据
* @param ilen 输入的数据长度
* @param output 输出的SHA1检验值
* @param is_224 是否是224校验
*/
void luat_crypto_sha256(const unsigned char *input, size_t ilen, unsigned char output[20], int is_224);
/**
* @brief 产生随机数
* @param buff 随机数存放地址
* @param ilen 随机数长度
*/
int luat_crypto_trng(char* buff, size_t len);
/**@}*/
#endif

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_DEBUG_H
#define LUAT_DEBUG_H
/**
* @defgroup luatos_debug 调式接口
* @{
*/
/**
* @brief 出现异常后系统处理
*
*/
typedef enum LUAT_DEBUG_FAULT_MODE
{
LUAT_DEBUG_FAULT_RESET, /**< 出现异常后重启 */
LUAT_DEBUG_FAULT_HANG /**< 出现异常后死机 */
}LUAT_DEBUG_FAULT_MODE_E;
/**
* @brief 格式打印并输出到LOG口
*
* @param fmt 格式
* @param ... 后续变量
*/
void luat_debug_print(const char *fmt, ...);
/**
* @brief luat_debug_print宏定义为LUAT_DEBUG_PRINT
* @param fmt 格式
* @param ... 后续变量
*/
#define LUAT_DEBUG_PRINT(fmt, argv...) luat_debug_print("%s %d:"fmt, __FUNCTION__,__LINE__, ##argv)
/**
* @brief 断言处理并格式打印输出到LOG口
*
* @param fun_name 断言的函数
* @param line_no 行号
* @param fmt 格式
* @param ... 后续变量
*/
void luat_debug_assert(const char *fun_name, unsigned int line_no, const char *fmt, ...);
#define LUAT_DEBUG_ASSERT(condition, fmt, argv...) do { \
{ \
if((condition) == 0) \
{ \
luat_debug_assert(__FUNCTION__, __LINE__, fmt, ##argv); \
}\
} \
} while(0) ///< luat_debug_assert宏定义为LUAT_DEBUG_ASSERT
/**
* @brief 设置出现异常后系统处理模式
*
* @param mode 处理模式 LUAT_DEBUG_FAULT_RESET 重启模式
LUAT_DEBUG_FAULT_HANG 死机模式
*/
void luat_debug_set_fault_mode(LUAT_DEBUG_FAULT_MODE_E mode);
/** @}*/
#endif

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_flash_H
#define LUAT_flash_H
#include "luat_base.h"
/**
* @defgroup luatos_flash 片上Flash操作
* @{
*/
/**
* @brief 读取指定区域的Flash数据
*
* @param buff[OUT] 读出的数据
* @param addr 偏移量, 与具体设备相关
* @param len 读取长度
* @return int <= 0错误 >0实际读取的大小
*/
int luat_flash_read(char* buff, size_t addr, size_t len);
/**
* @brief 写入指定区域的flash数据
*
* @param buff[IN] 写入的数据
* @param addr 偏移量, 与具体设备相关
* @param len 写入长度
* @return int <= 0错误 >0实际写入的大小
*/
int luat_flash_write(char* buff, size_t addr, size_t len);
/**
* @brief 抹除指定区域的flash数据
*
* @param addr 偏移量, 与具体设备相关
* @param len 抹除长度,通常为区域大小, 例如4096
* @return int != 0错误 =0 正常
*/
int luat_flash_erase(size_t addr, size_t len);
/**
* @}
*/
#endif

View File

@@ -0,0 +1,301 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_FS_H
#define LUAT_FS_H
//#include "luat_base.h"
#include "stdio.h"
/**
* @defgroup luat_fs 文件系统接口
* @{
*/
#ifndef LUAT_WEAK
#define LUAT_WEAK __attribute__((weak))
#endif
typedef struct luat_fs_conf {
char* busname;
char* type;
char* filesystem;
const char* mount_point;
} luat_fs_conf_t;
typedef struct luat_fs_info
{
char filesystem[8]; // 文件系统类型
unsigned char type; // 连接方式, 片上,spi flash, tf卡等
size_t total_block;
size_t block_used;
size_t block_size;
}luat_fs_info_t;
/**
* @brief 文件系统初始化
* @return int =0成功其他失败
*/
int luat_fs_init(void);
// int luat_fs_mkfs(luat_fs_conf_t *conf);
// int luat_fs_mount(luat_fs_conf_t *conf);
// int luat_fs_umount(luat_fs_conf_t *conf);
/**
* @brief 获取文件系统状态
* @param path[IN] 挂载路径, 通常为 /
* @param info[OUT] 文件系统信息
* @return int =0成功其他失败
*/
int luat_fs_info(const char* path, luat_fs_info_t *info);
/**
* @brief 打开文件,类似于fopen
* @param path[IN] 文件路径
* @param mode[IN] 打开模式,与posix类型, 例如 "r" "rw" "w" "w+" "a"
* @return FILE* 文件句柄,失败返回NULL
*/
FILE* luat_fs_fopen(const char *filename, const char *mode);
/**
* @brief 读到单个字节,类似于getc
* @param stream[IN] 文件句柄
* @return int >=0读取成功返回, -1失败, 例如读取到文件尾部
*/
int luat_fs_getc(FILE* stream);
/**
* @brief 设置句柄位置,类似于fseek
* @param stream[IN] 文件句柄
* @param offset[IN] 偏移量
* @param origin[IN] 参考点, 例如 SEEK_SET 绝对坐标, SEEK_END 结尾, SEEK_CUR 当前
* @return int =0成功,否则失败
*/
int luat_fs_fseek(FILE* stream, long int offset, int origin);
/**
* @brief 获取句柄位置,类似于ftell
* @param stream[IN] 文件句柄
* @return int >=0当前位置, 否则失败
*/
int luat_fs_ftell(FILE* stream);
/**
* @brief 关闭句柄位置,类似于fclose
* @param stream[IN] 文件句柄
* @return int =0成功,否则失败
*/
int luat_fs_fclose(FILE* stream);
/**
* @brief 是否已经到文件结尾,类似于feof
* @param stream[IN] 文件句柄
* @return int =0未到文件尾部,其余为到达文件尾部
*/
int luat_fs_feof(FILE* stream);
/**
* @brief 是否有文件系统错误,类似于ferror
* @param stream[IN] 文件句柄
* @return int =0无错误, 其余为错误值
*/
int luat_fs_ferror(FILE *stream);
/**
* @brief 读取文件,类似于fread
* @param ptr[OUT] 存放读取数据的缓冲区
* @param size[IN] 单次读取大小
* @param nmemb[IN] 读取次数
* @param stream[IN] 文件句柄
* @return int >=0实际读取的数量,<0出错
*/
size_t luat_fs_fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
/**
* @brief 写入文件,类似于fwrite
* @param ptr[OUT] 存放写入数据的缓冲区
* @param size[IN] 单次读取大小
* @param nmemb[IN] 读取次数
* @param stream[IN] 文件句柄
* @return int >=0实际写入的数量,<0出错
*/
size_t luat_fs_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
/**
* @brief 删除文件,类似于remove
* @param filename[IN] 文件路径
* @return int =0成功,否则失败
*/
int luat_fs_remove(const char *filename);
/**
* @brief 文件改名,类似于rename
* @param old_filename[IN] 原文件路径
* @param new_filename[IN] 新文件路径
* @return int =0成功,否则失败
*/
int luat_fs_rename(const char *old_filename, const char *new_filename);
/**
* @brief 文件大小,类似于fsize
* @param filename[IN] 文件路径
* @return int >=0文件大小, <0文件存在或者不可访问
*/
size_t luat_fs_fsize(const char *filename);
/**
* @brief 文件是否存在,类似于fexist
* @param filename[IN] 文件路径
* @return int =0不存在,否则存在
*/
int luat_fs_fexist(const char *filename);
/**
* @brief 截断文件,类似于ftruncate
* @param fp[IN] 文件句柄
* @return int >=0截断后的文件大小,否则失败
*/
// int luat_fs_ftruncate(FILE* fp, size_t len);
/**
* @brief 截断文件,类似于truncate
* @param filename[IN] 文件路径
* @return int >=0截断后的文件大小,否则失败
*/
int luat_fs_truncate(const char* filename, size_t len);
// int luat_fs_readline(char * buf, int bufsize, FILE * stream);
// 文件夹相关的API
typedef struct luat_fs_dirent
{
unsigned char d_type; //0:文件1文件夹(EC618不支持创建目录操作所以理论上不会出现为1的情况)
char d_name[255];
}luat_fs_dirent_t;
/**
* @brief 创建文件夹,当前EC618不支持
* @param dir[IN] 文件夹路径
* @return int =0成功,否则失败
*/
int luat_fs_mkdir(char const* dir);
/**
* @brief 删除文件夹,必须为空文件夹
* @param dir[IN] 文件夹路径
* @return int =0成功,否则失败
*/
int luat_fs_rmdir(char const* dir);
/**
* @brief 遍历文件夹
* @param dir[IN] 文件夹路径
* @param ents[OUT] 文件列表,必须已分配内存,且不小于len个元素
* @param offset[IN] 跳过多少个文件
* @param len[IN] 最多读取多少个文件
* @return int =>0读取到文件个数,否则失败
*/
int luat_fs_lsdir(char const* dir, luat_fs_dirent_t* ents, size_t offset, size_t len);
/**
* @brief 文件系统是否已经就绪
* @return int 0未就绪, >0已就绪
*/
int luat_fs_ready(void);
#if LUAT_USE_FS_VFS
#ifndef LUAT_VFS_FILESYSTEM_MAX
#define LUAT_VFS_FILESYSTEM_MAX 4
#endif
#ifndef LUAT_VFS_FILESYSTEM_MOUNT_MAX
#define LUAT_VFS_FILESYSTEM_MOUNT_MAX 4
#endif
#ifndef LUAT_VFS_FILESYSTEM_FD_MAX
#define LUAT_VFS_FILESYSTEM_FD_MAX 16
#endif
struct luat_vfs_file_opts {
FILE* (*fopen)(void* fsdata, const char *filename, const char *mode);
int (*getc)(void* fsdata, FILE* stream);
int (*fseek)(void* fsdata, FILE* stream, long int offset, int origin);
int (*ftell)(void* fsdata, FILE* stream);
int (*fclose)(void* fsdata, FILE* stream);
int (*feof)(void* fsdata, FILE* stream);
int (*ferror)(void* fsdata, FILE *stream);
size_t (*fread)(void* fsdata, void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t (*fwrite)(void* fsdata, const void *ptr, size_t size, size_t nmemb, FILE *stream);
};
struct luat_vfs_filesystem_opts {
int (*remove)(void* fsdata, const char *filename);
int (*rename)(void* fsdata, const char *old_filename, const char *new_filename);
size_t (*fsize)(void* fsdata, const char *filename);
int (*fexist)(void* fsdata, const char *filename);
int (*mkfs)(void* fsdata, luat_fs_conf_t *conf);
int (*mount)(void** fsdata, luat_fs_conf_t *conf);
int (*umount)(void* fsdata, luat_fs_conf_t *conf);
int (*info)(void* fsdata, const char* path, luat_fs_info_t *conf);
int (*mkdir)(void* fsdata, char const* _DirName);
int (*rmdir)(void* fsdata, char const* _DirName);
int (*lsdir)(void* fsdata, char const* _DirName, luat_fs_dirent_t* ents, size_t offset, size_t len);
};
typedef struct luat_vfs_filesystem {
char name[16];
struct luat_vfs_filesystem_opts opts;
struct luat_vfs_file_opts fopts;
}luat_vfs_filesystem_t;
typedef struct luat_vfs_mount {
struct luat_vfs_filesystem *fs;
void *userdata;
char prefix[16];
int ok;
} luat_vfs_mount_t;
typedef struct luat_vfs_fd{
FILE* fd;
luat_vfs_mount_t *fsMount;
}luat_vfs_fd_t;
typedef struct luat_vfs
{
struct luat_vfs_filesystem* fsList[LUAT_VFS_FILESYSTEM_MAX];
luat_vfs_mount_t mounted[LUAT_VFS_FILESYSTEM_MOUNT_MAX];
luat_vfs_fd_t fds[LUAT_VFS_FILESYSTEM_FD_MAX+1];
}luat_vfs_t;
int luat_vfs_init(void* params);
int luat_vfs_reg(const struct luat_vfs_filesystem* fs);
FILE* luat_vfs_add_fd(FILE* fd, luat_vfs_mount_t * mount);
int luat_vfs_rm_fd(FILE* fd);
const char* luat_vfs_mmap(FILE* fd);
#endif
/** @}*/
#endif

View File

@@ -0,0 +1,143 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_GPIO_H
#define LUAT_GPIO_H
#include "luat_base.h"
#include "luat_gpio_legacy.h"
/**
* @defgroup luatos_device 外设接口
* @{
*/
/**
* @defgroup luatos_device_gpio GPIO接口
* @{
*/
#define LUAT_GPIO_LOW (Luat_GPIO_LOW) ///< GPIO配置为低电平
#define LUAT_GPIO_HIGH (Luat_GPIO_HIGH) ///< GPIO配置为高电平
#define LUAT_GPIO_OUTPUT (Luat_GPIO_OUTPUT) ///< GPIO配置为输出模式
#define LUAT_GPIO_INPUT (Luat_GPIO_INPUT) ///< GPIO配置为输入模式
#define LUAT_GPIO_IRQ (Luat_GPIO_IRQ) ///< GPIO配置为中断模式
#define LUAT_GPIO_DEFAULT (Luat_GPIO_DEFAULT) ///< GPIO配置为默认模式,EC618平台普通的GPIO配置为LUAT_GPIO_DEFAULT表示完全关闭上下拉AGPIO软件上不支持配置上下拉即使配置了也无效一直是硬件开机或者复位时的默认状态
#define LUAT_GPIO_PULLUP (Luat_GPIO_PULLUP) ///< GPIO配置为上拉模式
#define LUAT_GPIO_PULLDOWN (Luat_GPIO_PULLDOWN)///< GPIO配置为下拉模式
#define LUAT_GPIO_RISING_IRQ (Luat_GPIO_RISING) ///<上升沿中断
#define LUAT_GPIO_FALLING_IRQ (Luat_GPIO_FALLING)///< 下降沿中断
#define LUAT_GPIO_BOTH_IRQ (Luat_GPIO_BOTH) ///< 上升沿 下降沿都中断
#define LUAT_GPIO_HIGH_IRQ (Luat_GPIO_HIGH_IRQ) ///< GPIO配置为高电平中断模式
#define LUAT_GPIO_LOW_IRQ (Luat_GPIO_LOW_IRQ) ///< GPIO配置为低电平模式
#define LUAT_GPIO_NO_IRQ (0xff) ///< GPIO没有中断模式
#define LUAT_GPIO_MAX_ID (Luat_GPIO_MAX_ID) ///< 最大GPIO序号
/**
* @brief GPIO控制参数
*/
typedef struct luat_gpio_cfg
{
int pin; /**<引脚*/
uint8_t mode;/**<GPIO模式*/
uint8_t pull;/**<GPIO上下拉模式*/
uint8_t irq_type;/**<GPIO中断模式*/
uint8_t output_level;/**<GPIO输出高低电平选择*/
luat_gpio_irq_cb irq_cb;/**<GPIO中断回调函数*/
void* irq_args;/**<GPIO中断回调时用户参数*/
uint8_t alt_fun;/**<有些SOC的GPIO会在不同引脚上被复用通过alt_fun来确定具体用哪个*/
} luat_gpio_cfg_t;
/**
* @brief GPIO上下拉\中断设置参数
*/
typedef enum
{
LUAT_GPIO_CMD_SET_PULL_MODE,/**<上下拉模式*/
LUAT_GPIO_CMD_SET_IRQ_MODE,/**<中断模式*/
}LUAT_GPIO_CTRL_CMD_E;
/**
* @brief GPIO设置默认参数
* @param luat_gpio_cfg_t
*/
void luat_gpio_set_default_cfg(luat_gpio_cfg_t* gpio);
/**
* @brief 打开GPIO
* @param luat_gpio_cfg_t
*/
int luat_gpio_open(luat_gpio_cfg_t* gpio);
/**
* @brief GPIO输出电平
* @param Pin Pin序号
* @param Level 1高电平0低电平
*/
int luat_gpio_set(int pin, int level);
/**
* @brief 读取GPIO输入电平
* @param Pin Pin序号
* @return 1高电平 0低电平其他无效
*/
int luat_gpio_get(int pin);
/**
* @brief 关闭GPIO
* @param Pin Pin序号
*/
void luat_gpio_close(int pin);
/**
* @brief 设置GPIO中断回调函数
* @param Pin Pin序号
* @param cb 中断处理函数
* @param args 中断函数参数
* @return -1 失败 0 成功
*/
int luat_gpio_set_irq_cb(int pin, luat_gpio_irq_cb cb, void* args);
/**
* @brief GPIO模拟单线输出模式
* @param Pin Pin序号
* @param Data 输出电平序列
* @param BitLen 输出电平序列中一共有几个bit
* @param Delay 每个bit之间的delay
* @return 无
* @attention 在同一个GPIO输出一组脉冲, 注意, len的单位是bit, 高位在前.
*/
void luat_gpio_pulse(int pin, uint8_t *level, uint16_t len, uint16_t delay_ns);
/**
* @brief GPIO上下拉\中断单独设置函数
* @param pin Pin序号
* @param LUAT_GPIO_CTRL_CMD_E 设置命令 LUAT_GPIO_CMD_SET_PULL_MODE 设置上下拉命令 LUAT_GPIO_CMD_SET_IRQ_MODE
* @param param 设置参数 参数取自上下拉、以及中断的宏定义
* @return -1 失败 0 成功
*/
int luat_gpio_ctrl(int pin, LUAT_GPIO_CTRL_CMD_E cmd, int param);
/** @}*/
/** @}*/
#endif

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_GPIO_LEGACY_H
#define LUAT_GPIO_LEGACY_H
#include "luat_base.h"
#ifdef __LUATOS__
#include "luat_msgbus.h"
int l_gpio_handler(lua_State *L, void* ptr);
#endif
typedef int (*luat_gpio_irq_cb)(int pin, void* args);
#define Luat_GPIO_LOW 0x00 ///< GPIO配置为低电平
#define Luat_GPIO_HIGH 0x01 ///< GPIO配置为高电平
#define Luat_GPIO_OUTPUT 0x00 ///< GPIO配置为输出模式
#define Luat_GPIO_INPUT 0x01 ///< GPIO配置为输入模式
#define Luat_GPIO_IRQ 0x02 ///< GPIO配置为中断模式
#define Luat_GPIO_DEFAULT 0x00 ///< GPIO配置为默认模式
#define Luat_GPIO_PULLUP 0x01 ///< GPIO配置为上拉模式
#define Luat_GPIO_PULLDOWN 0x02 ///< GPIO配置为下拉模式
#define Luat_GPIO_RISING 0x00 ///<上升沿中断
#define Luat_GPIO_FALLING 0x01 ///< 下降沿中断
#define Luat_GPIO_BOTH 0x02 ///< 上升沿 下降沿都中断
#define Luat_GPIO_HIGH_IRQ 0x03 ///< GPIO配置为高电平中断模式
#define Luat_GPIO_LOW_IRQ 0x04 ///< GPIO配置为低电平模式
#define Luat_GPIO_MAX_ID 255 ///< 最大GPIO序号
/**
* @brief GPIO控制参数
*/
typedef struct luat_gpio
{
int pin;/**<引脚*/
int mode;/**<GPIO模式*/
int pull;/**<GPIO上下拉模式*/
int irq;/**<GPIO中断模式*/
int lua_ref;
luat_gpio_irq_cb irq_cb;/**<中断处理函数*/
void* irq_args;
} luat_gpio_t;
/**
* @brief GPIO初始化
* @param gpio gpio初始化结构体参数
*/
int luat_gpio_setup(luat_gpio_t* gpio);
/**
* @brief GPIO_Mode 配置函数
* @param pin GPIO引脚序号
* @param mode GPIO模式
* @param pull GPIO上下拉选择
* @param initOutput 初始输出模式
*/
void luat_gpio_mode(int pin, int mode, int pull, int initOutput);
#endif

View File

@@ -0,0 +1,98 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_I2C_H
#define LUAT_I2C_H
#include "luat_base.h"
#include "luat_i2c_legacy.h"
/**
* @ingroup luatos_device 外设接口
* @{
*/
/**
* @defgroup luatos_device_i2c I2C接口
* @{
*/
/**
* @brief 检查i2c是否存在
*
* @param id i2c_id
* @return int
*/
int luat_i2c_exist(int id);
/**
* @brief 初始化i2c
*
* @param id i2c_id
* @param speed i2c 速度
* @param slaveaddr i2c 从地址
* @return int
*/
int luat_i2c_setup(int id, int speed);
/**
* @brief 关闭 i2c
*
* @param id i2c_id
* @return int
*/
int luat_i2c_close(int id);
/**
* @brief I2C 发送数据
*
* @param id i2c_id
* @param addr 7位设备地址
* @param buff 数据buff
* @param len 数据长度
* @param stop 是否发送停止位
* @return int
*/
int luat_i2c_send(int id, int addr, void* buff, size_t len, uint8_t stop);
/**
* @brief I2C 接受数据
*
* @param id i2c_id
* @param addr 7位设备地址
* @param buff 数据buff
* @param len 数据长度
* @return int
*/
int luat_i2c_recv(int id, int addr, void* buff, size_t len);
/**
* @brief I2C 收发数据
*
* @param id i2c_id
* @param addr 7位设备地址
* @param reg 发送数据
* @param reg_len 发送数据长度
* @param buff 数据buff
* @param len 数据长度
* @return int
*/
int luat_i2c_transfer(int id, int addr, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len);
/** @}*/
/** @}*/
#endif

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_I2C_LEGACY_H
#define LUAT_I2C_LEGACY_H
#include "luat_base.h"
/**
* @brief I2C发送数据
*
* @param id i2c_id
* @param addr 7位设备地址
* @param buff 数据buff
* @param len 数据长度
* @param stop 是否发送停止位
* @return int
*/
int luat_i2c_write_reg(int id, int addr, int reg, uint16_t value, uint8_t stop);
/**
* @brief I2C接受数据
*
* @param id i2c_id
* @param addr 7位设备地址
* @param buff 数据buff
* @param len 数据长度
* @return int
*/
int luat_i2c_read_reg(int id, int addr, int reg, uint16_t* value);
/**
* @brief 非阻塞I2C收发数据
*/
int luat_i2c_no_block_transfer(int id, int addr, uint8_t is_read, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len, uint16_t Toms, void *CB, void *pParam);
#endif

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_ICONV_H
#define LUAT_ICONV_H
#include "luat_base.h"
/**
* @defgroup luatos_iconv 字符编码转换接口
* @{
*/
typedef void *luat_iconv_t;
/**
* @brief 开启iconv转换流分配内存
* @param to_code 待转换编码
* @param from_code 目标编码
* @return cionv转换流
*/
luat_iconv_t luat_iconv_open (const char *to_code, const char *from_code);
/**
* @brief 转换编码格式
* @param cd cionv转换流
* @param inbuf 输入缓冲区
* @param in_bytes_left 输入缓冲区长度
* @param outbuf 输出缓冲区
* @param out_bytes_left 输出缓冲区长度
* @return 0为成功-1为失败
*/
size_t luat_iconv_convert (luat_iconv_t cd, char ** inbuf, size_t * in_bytes_left, char ** outbuf, size_t * out_bytes_left);
/**
* @brief 关闭iconv转换流释放内存
* @param cd cionv转换流
* @return 1成功0失败
*/
int luat_iconv_close (luat_iconv_t cd);
/**@}*/
#endif

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_IRQ_H
#define LUAT_IRQ_H
#include "luat_base.h"
int luat_irq_fire(int tp, int arg, void* args);
int luat_irq_gpio_cb(int pin, void* args);
int luat_irq_uart_cb(int uartid, void* args);
int luat_irq_spi_cb(int id);
int32_t luat_irq_hardware_cb_handler(void *pdata, void *param);
#endif

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_KV_H
#define LUAT_KV_H
/**
* @defgroup luatos_kv 持久化数据存储接口
* @{
*/
/**
* @brief 初始化kv数据存储
*
* @return int == 0 正常 != 0失败
*/
int luat_kv_init(void);
/**
* @brief 删除指定的key
* @param key[IN] 待删除的key值
* @return int == 0 正常 != 0失败
*/
int luat_kv_del(const char* key);
/**
* @brief 写入指定key的数据
* @param key[IN] 待写入的key值,不能为NULL,必须是\0结尾,最大长度64字节
* @param data[IN] 待写入的数据, 不需要\0结尾
* @param len[IN] 待写入的数据长度, 不含\0,当前支持最大长度255字节
* @return int == 0 正常 != 0失败
*/
int luat_kv_set(const char* key, void* data, size_t len);
/**
* @brief 读取指定key的数据
* @param key[IN] 待读取的key值,不能为NULL,必须是\0结尾
* @param data[IN] 待读取的数据, 可写入空间必须大于等于len值
* @param len[IN] 待读取的数据长度最大长度, 不含\0
* @return int > 0 实际读取的长度, <=0 失败
*/
int luat_kv_get(const char* key, void* data, size_t len);
/**
* @brief 清空所有数据
* @return int == 0 正常 != 0失败
*/
int luat_kv_clear(void);
/**
* @}
*/
#endif

View File

@@ -0,0 +1,98 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_MCU_H
#define LUAT_MCU_H
#include "luat_base.h"
/**
* @defgroup luatos_mcu MCU特殊操作
* @{
*/
/**
* @brief 设置主频
*
* @param mhz 时钟频率,单位MHz, 仅Air101/Air103支持, EC618不支持
* @return int <= 0错误 >0实际传出的大小
*/
int luat_mcu_set_clk(size_t mhz);
/**
* @brief 获取主频
*
* @return int 时钟频率,单位MHz
*/
int luat_mcu_get_clk(void);
/**
* @brief 获取唯一id
*
* @param t id的长度,若失败设置为0
* @return char* 唯一id, 不需要释放!!
*/
const char* luat_mcu_unique_id(size_t* t);
/**
* @brief 获取系统tick计数
*
* @return long tick计数值
*/
long luat_mcu_ticks(void);
/**
* @brief 获取系统tick频率
*
* @return long tick频率,通常为1000, 即每个tick占1ms, 频率1000hz
*/
uint32_t luat_mcu_hz(void);
/**
* @brief 获取tick计数,64位的
*
* @return uint64_t tick计数
*/
uint64_t luat_mcu_tick64(void);
/**
* @brief 对应tick64的频率数据
*
* @return int 每us对应的tick数量
*/
int luat_mcu_us_period(void);
/**
* @brief 开机至今的毫秒数
*
* @return uint64_t 毫秒数,休眠后会继续累计,但精度比其他tick要低
*/
uint64_t luat_mcu_tick64_ms(void);
/**
* @brief 设置时钟源(仅Air105支持)
*
* @param source_main 主时钟源
* @param source_32k 32k时钟源
* @param delay 设置之后延时多久
*/
void luat_mcu_set_clk_source(uint8_t source_main, uint8_t source_32k, uint32_t delay);
#endif

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_MEM_H
#define LUAT_MEM_H
/**
* @defgroup luatos_mem 内存管理
* @{
*/
#include "stdint.h"
/**
* @brief 在堆区分配一块指定大小的内存空间,用来存放数据
*
* @param len 开辟内存的长度大小
* @return NULL 失败 !NULL 成功
*/
void* luat_heap_malloc(size_t len);
/**
* @brief 释放ptr所指向的内存块,释放的是动态分配的内存空间
*
* @param ptr 所指向的内存块
*/
void luat_heap_free(void* ptr);
/**
* @brief 重新分配内存,把内存扩展到 len
*
* @param ptr 所指向的内存块
* @param len 长度
*/
void* luat_heap_realloc(void* ptr, size_t len);
/**
* @brief 在内存中动态地分配 count 个长度为 size_t 的连续空间,并将每一个字节都初始化为 0
*
* @param count 长度
* @param _size 数据类型
* @return NULL 失败 !NULL 成功
*/
void* luat_heap_calloc(size_t count, size_t _size);
/**
* @brief 获取内存使用信息
*
* @param[out] total 模组总的的内存大小
* @param[out] used 获取当前已分配的内存堆大小
* @param[out] max_used 获取当前最大已分配的内存堆大小
*/
void luat_meminfo_sys(size_t* total, size_t* used, size_t* max_used);
#define LUAT_MEM_MALLOC luat_heap_malloc ///< 在堆区分配一块指定大小的内存空间,用来存放数据
#define LUAT_MEM_FREE luat_heap_free ///< 释放ptr所指向的内存块,释放的是动态分配的内存空间
#define LUAT_MEM_REALLOC luat_heap_realloc ///< 重新分配内存,把内存扩展到 len
#define LUAT_MEM_CALLOC luat_heap_calloc ///< 在内存中动态地分配 count 个长度为 size_t 的连续空间,并将每一个字节都初始化为 0
#define LUAT_MEM_INFO luat_meminfo_sys ///< 获取内存使用信息
/**
* @}
*/
#endif

View File

@@ -0,0 +1,469 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LUAT_MOBILE_H__
#define __LUAT_MOBILE_H__
#include "luat_base.h"
/**
* @defgroup luatos_mobile 移动网络相关接口
* @{
*/
/**
* @brief 获取IMEI
*
* @param sim_id sim位置对于双卡双待的设备选0或者1其他设备随意
* @param buff[OUT] IMEI数据
* @param buf_len 用户传入缓存的大小如果底层数据量大于buf_len只会传出buf_len大小的数据
* @return int <= 0错误 >0实际传出的大小
*/
int luat_mobile_get_imei(int sim_id, char* buff, size_t buf_len);
/**
* @brief 获取SN如果用户没有调用luat_mobile_set_sn接口写过SN默认值为空
*
* @param buff[OUT] SN数据
* @param buf_len 用户传入缓存的大小EC618平台底层支持的最大长度为32字节如果底层数据量大于buf_len只会传出buf_len大小的数据
* @return int <= 0错误 >0实际传出的大小
*/
int luat_mobile_get_sn(char* buff, size_t buf_len);
/**
* @brief 设置SN
*
* @param buff SN数据必须是ascii值大于等于0x21小于等于0x7e的可见ascii字符
* @param buf_len SN数据长度EC618平台底层支持的最大长度为32字节如果buf_len大于32只会保存前32字节的数据
* @return int = 0成功 = -1失败
*/
int luat_mobile_set_sn(char* buff, uint8_t buf_len);
/**
* @brief 获取MUID并不一定存在
*
* @param buff[OUT] MUID数据
* @param buf_len 用户传入缓存的大小如果底层数据量大于buf_len只会传出buf_len大小的数据
* @return int <= 0错误 >0实际传出的大小
*/
int luat_mobile_get_muid(char* buff, size_t buf_len);
/**
* @brief 获取SIM卡的ICCID
*
* @param sim_id sim位置对于双卡双待的设备选0或者1其他设备随意
* @param buff[OUT] ICCID数据
* @param buf_len 用户传入缓存的大小如果底层数据量大于buf_len只会传出buf_len大小的数据
* @return int <= 0错误 >0实际传出的大小
*/
int luat_mobile_get_iccid(int sim_id, char* buff, size_t buf_len);
/**
* @brief 获取SIM卡的IMSI
*
* @param sim_id sim位置对于双卡双待的设备选0或者1其他设备随意
* @param buff[OUT] IMSI数据
* @param buf_len 用户传入缓存的大小如果底层数据量大于buf_len只会传出buf_len大小的数据
* @return int <= 0错误 >0实际传出的大小
*/
int luat_mobile_get_imsi(int sim_id, char* buff, size_t buf_len);
/**
* @brief 当前使用的SIM卡的位置并不一定支持
*
* @param id[OUT] sim位置对于双卡双待的设备输出0或者1其他设备输出0
* @return int =0成功其他失败
*/
int luat_mobile_get_sim_id(int *id);
/**
* @brief 改变使用的SIM卡的位置并不一定支持
*
* @param id sim位置对于双卡的设备选0或者1其他为自动选择模式。非双卡的设备不支持
* @return int =0成功其他失败
*/
int luat_mobile_set_sim_id(int id);
/**
* @brief 获取配置的apn name并不一定支持
*
* @param sim_id sim位置对于双卡双待的设备选0或者1其他设备随意
* @param cid cid位置 1~6
* @param buff[OUT] apn name
* @param buf_len 用户传入缓存的大小如果底层数据量大于buf_len只会传出buf_len大小的数据
* @return int <= 0错误 >0实际传出的大小
*/
int luat_mobile_get_apn(int sim_id, int cid, char* buff, size_t buf_len);
/**
* @brief 获取默认CID的apn name并不一定支持
*
* @param sim_id sim位置对于双卡双待的设备选0或者1其他设备随意
* @param buff[OUT] apn name
* @param buf_len 用户传入缓存的大小如果底层数据量大于buf_len只会传出buf_len大小的数据
* @return int <= 0错误 >0实际传出的大小
*/
int luat_mobile_get_default_apn(int sim_id, char* buff, size_t buf_len);
/**
* @brief 进出飞行模式
*
* @param index sim位置对于双卡双待的设备选0或者1其他设备随意
* @param mode 飞行模式1进入0退出
* @return int =0成功其他失败
*/
int luat_mobile_set_flymode(int index, int mode);
/**
* @brief 飞行模式当前状态
*
* @param index sim位置对于双卡双待的设备选0或者1其他设备随意
* @return int <0 异常 =0飞行模式 =1正常工作 =4射频关闭
*/
int luat_mobile_get_flymode(int index);
#if (!defined __LUATOS__) || ((defined __LUATOS__) && (defined LUAT_USE_LWIP))
#include "lwip/opt.h"
#include "lwip/netif.h"
#include "lwip/inet.h"
/**
* @brief 获取已激活承载分配的本地ip地址
*
* @param sim_id sim位置对于双卡双待的设备选0或者1其他设备随意
* @param cid cid位置 1~6没有使用专网APN的话就是用1
* @param ip_v4, ipv4的IP地址
* @param ip_v6, ipv6的IP地址
* @return int =0成功其他失败
*/
int luat_mobile_get_local_ip(int sim_id, int cid, ip_addr_t *ip_v4, ip_addr_t *ip_v6);
#endif
/* -------------------------------------------------- cell info begin -------------------------------------------------- */
#define LUAT_MOBILE_CELL_MAX_NUM 9
typedef struct luat_mobile_gsm_service_cell_info
{
int cid; /**< Cell ID, (0 indicates information is not represent).*/
int mcc; /**< This field should be ignored when cid is not present*/
int mnc; /**< This field should be ignored when cid is not present*/
int lac; /**< Location area code.(This field should be ignord when cid is not present). */
int arfcn; /**< Absolute RF channel number. */
int bsic; /**< Base station identity code. (0 indicates information is not present). */
int rssi; /**< Receive signal strength, Value range: rxlev-111 for dbm format */
}luat_mobile_gsm_service_cell_info_t;
typedef struct luat_mobile_gsm_cell_info
{
int cid; /**Cell ID, (0 indicates information is not represent).*/
int mcc; /**This field should be ignored when cid is not present*/
int mnc; /**This field should be ignored when cid is not present*/
int lac; /**Location area code.(This field should be ignord when cid is not present). */
int arfcn; /**Absolute RF channel number. */
int bsic; /**Base station identity code. (0 indicates information is not present). */
int rssi; /**< Receive signal strength, Value range: rxlev-111 for dbm format */
}luat_mobile_gsm_cell_info_t;
typedef struct luat_mobile_lte_service_cell_info
{
uint32_t cid; /**<Cell ID, (0 indicates information is not represent).*/
uint16_t mcc; /**This field should be ignored when cid is not present*/
uint16_t mnc; /**This field should be ignored when cid is not present*/
uint16_t tac; /**Tracing area code (This field should be ignored when cid is not present). */
uint16_t pci; /**Physical cell ID. Range: 0 to 503. */
uint32_t earfcn; /**E-UTRA absolute radio frequency channel number of the cell. RANGE: 0 TO 65535. */
int16_t rssi; /**< Receive signal strength, Value range: rsrp-140 for dbm format */
int16_t rsrp;
int16_t rsrq;
int16_t snr;
uint8_t is_tdd;
uint8_t band;
uint8_t ulbandwidth;
uint8_t dlbandwidth;
}luat_mobile_lte_service_cell_info_t;
typedef struct luat_mobile_lte_cell_info
{
uint32_t cid; /**<Cell ID, (0 indicates information is not represent).*/
uint16_t mcc; /**This field should be ignored when cid is not present*/
uint16_t mnc; /**This field should be ignored when cid is not present*/
uint16_t tac; /**Tracing area code (This field should be ignored when cid is not present). */
uint16_t pci; /**Physical cell ID. Range: 0 to 503. */
uint32_t earfcn; /**E-UTRA absolute radio frequency channel number of the cell. RANGE: 0 TO 65535. */
int16_t rsrp;
int16_t rsrq;
int16_t snr;
}luat_mobile_lte_cell_info_t;
typedef struct luat_mobile_cell_info
{
luat_mobile_gsm_service_cell_info_t gsm_service_info;
luat_mobile_gsm_cell_info_t gsm_info[LUAT_MOBILE_CELL_MAX_NUM]; /**< GSM cell information (Serving and neighbor. */
luat_mobile_lte_service_cell_info_t lte_service_info;
luat_mobile_lte_cell_info_t lte_info[LUAT_MOBILE_CELL_MAX_NUM]; /**< LTE cell information (Serving and neighbor). */
uint8_t gsm_info_valid; /**< Must be set to TRUE if gsm_info is being passed. */
uint8_t gsm_neighbor_info_num; /**< Must be set to the number of elements in entry*/
uint8_t lte_info_valid; /**< Must be set to TRUE if lte_info is being passed. */
uint8_t lte_neighbor_info_num; /**< Must be set to the number of elements in entry*/
}luat_mobile_cell_info_t;
/**
* @brief 立刻搜索一次周围小区基站信息,并同步返回结果
*
* @param info 当前移动网络信号状态详细信息
* @return int =0成功其他失败
*/
int luat_mobile_get_cell_info(luat_mobile_cell_info_t *info);
/**
* @brief 立刻搜索一次周围小区基站信息通过LUAT_MOBILE_CELL_INFO_UPDATE返回搜索完成消息luat_mobile_get_last_notify_cell_info获取详细信息
*
* @param max_time 搜索的最大时间,单位秒
* @return int =0成功其他失败
*/
int luat_mobile_get_cell_info_async(uint8_t max_time);
/**
* @brief 获取上一次异步搜索周围小区基站信息包括周期性搜索和异步搜索在LUAT_MOBILE_CELL_INFO_UPDATE到来后用本函数获取信息
*
* @param info 当前移动网络信号状态详细信息
* @param max_time 搜索的最大时间
* @return int =0成功其他失败
*/
int luat_mobile_get_last_notify_cell_info(luat_mobile_cell_info_t *info);
typedef struct luat_mobile_gw_signal_strength_info
{
int rssi;
int bitErrorRate;
int rscp;
int ecno;
}luat_mobile_gw_signal_strength_info_t;
typedef struct luat_mobile_lte_signal_strength_info
{
int16_t rssi; /**< Receive signal strength, Value range: rsrp-140 for dbm format */
int16_t rsrp;
int16_t rsrq;
int16_t snr;
}luat_mobile_lte_signal_strength_info_t;
typedef struct luat_mobile_signal_strength_info
{
luat_mobile_gw_signal_strength_info_t gw_signal_strength;
luat_mobile_lte_signal_strength_info_t lte_signal_strength;
uint8_t luat_mobile_gw_signal_strength_vaild;
uint8_t luat_mobile_lte_signal_strength_vaild;
}luat_mobile_signal_strength_info_t;
/**
* @brief 从RSSI转换到CSQRSSI只能作为天线口状态的一个参考而不能作为LTE网络信号状态的参考
*
* @param rssi RSSI值
* @return uint8_t CSQ值
*/
uint8_t luat_mobile_rssi_to_csq(int8_t rssi);
/**
* @brief 获取当前移动网络信号状态详细信息
*
* @param info 当前移动网络信号状态详细信息
* @return int =0成功其他失败
*/
int luat_mobile_get_signal_strength_info(luat_mobile_signal_strength_info_t *info);
/**
* @brief 获取CSQ值 CSQ从RSSI转换而来只能作为天线口状态的一个参考而不能作为LTE网络信号状态的参考
*
* @param csq CSQ值
* @return int =0成功其他失败
*/
int luat_mobile_get_signal_strength(uint8_t *csq);
/**
* @brief 获取最近一次网络信号状态更新通知后的网络信号状态详细信息
*
* @param info 网络信号状态详细信息
* @return int =0成功其他失败
*/
int luat_mobile_get_last_notify_signal_strength_info(luat_mobile_signal_strength_info_t *info);
/**
* @brief 获取最近一次网络信号状态更新通知后的CSQ值
*
* @param info CSQ值
* @return int =0成功其他失败
*/
int luat_mobile_get_last_notify_signal_strength(uint8_t *csq);
/* --------------------------------------------------- cell info end --------------------------------------------------- */
/* ------------------------------------------------ mobile status begin ----------------------------------------------- */
/**
* @brief 网络状态及相关功能状态发生更换的消息
*
*/
typedef enum LUAT_MOBILE_EVENT
{
LUAT_MOBILE_EVENT_CFUN = 0, /**< CFUN消息 */
LUAT_MOBILE_EVENT_SIM, /**< SIM卡消息*/
LUAT_MOBILE_EVENT_REGISTER_STATUS, /**< 移动网络注册消息*/
LUAT_MOBILE_EVENT_CELL_INFO, /**< 小区基站信息和网络信号变更消息*/
LUAT_MOBILE_EVENT_PDP, /**< PDP状态消息*/
LUAT_MOBILE_EVENT_NETIF, /**< internet状态*/
LUAT_MOBILE_EVENT_TIME_SYNC, /**< 通过基站同步时间完成*/
LUAT_MOBILE_EVENT_CSCON, /**< RRC状态0 idle 1 active*/
}LUAT_MOBILE_EVENT_E;
typedef enum LUAT_MOBILE_CFUN_STATUS
{
LUAT_MOBILE_CFUN_OFF = 0,
LUAT_MOBILE_CFUN_ON,
LUAT_MOBILE_CFUN_NO_RF = 4,
}LUAT_MOBILE_CFUN_STATUS_E;
typedef enum LUAT_MOBILE_SIM_STATUS
{
LUAT_MOBILE_SIM_READY = 0,
LUAT_MOBILE_NO_SIM,
LUAT_MOBILE_SIM_NEED_PIN,
}LUAT_MOBILE_SIM_STATUS_E;
typedef enum LUAT_MOBILE_REGISTER_STATUS
{
LUAT_MOBILE_STATUS_UNREGISTER, /**< 网络未注册*/
LUAT_MOBILE_STATUS_REGISTERED, /**< 网络已注册*/
LUAT_MOBILE_STATUS_DENIED, /**< 网络注册被拒绝,或者正在搜网中*/
LUAT_MOBILE_STATUS_UNKNOW, /**< 网络状态未知*/
LUAT_MOBILE_STATUS_REGISTERED_ROAMING, /**< 网络已注册,漫游*/
LUAT_MOBILE_STATUS_SMS_ONLY_REGISTERED,
LUAT_MOBILE_STATUS_SMS_ONLY_REGISTERED_ROAMING,
LUAT_MOBILE_STATUS_EMERGENCY_REGISTERED,
LUAT_MOBILE_STATUS_CSFB_NOT_PREFERRED_REGISTERED,
LUAT_MOBILE_STATUS_CSFB_NOT_PREFERRED_REGISTERED_ROAMING,
}LUAT_MOBILE_REGISTER_STATUS_E;
typedef enum LUAT_MOBILE_CELL_INFO_STATUS
{
LUAT_MOBILE_CELL_INFO_UPDATE = 0, /**< 小区基站信息变更,只有设置了周期性搜索小区基站时才会有*/
LUAT_MOBILE_SIGNAL_UPDATE, /**< 网络信号状态变更,但是不一定是有变化*/
}LUAT_MOBILE_CELL_INFO_STATUS_E;
typedef enum LUAT_MOBILE_PDP_STATUS
{
LUAT_MOBILE_PDP_ACTIVED = 0,
LUAT_MOBILE_PDP_DEACTIVING,
LUAT_MOBILE_PDP_DEACTIVED,
}LUAT_MOBILE_PDP_STATUS_E;
typedef enum LUAT_MOBILE_NETIF_STATUS
{
LUAT_MOBILE_NETIF_LINK_ON = 0, /**< 已联网*/
LUAT_MOBILE_NETIF_LINK_OFF, /**< 断网*/
LUAT_MOBILE_NETIF_LINK_OOS, /**< 失去网络连接尝试恢复中等同于LUAT_MOBILE_NETIF_LINK_OFF*/
}LUAT_MOBILE_NETIF_STATUS_E;
/**
* @brief 获取当前移动网络注册状态
*
* @return 见@enum LUAT_MOBILE_REGISTER_STATUS_E
*/
LUAT_MOBILE_REGISTER_STATUS_E luat_mobile_get_register_status(void);
/**
* @brief 网络状态及相关功能状态发生更换时的回调函数event是消息index是CIDSIM卡号之类的序号status是变更后的状态或者更具体的ENUM
*
*/
typedef void (*luat_mobile_event_callback_t)(LUAT_MOBILE_EVENT_E event, uint8_t index, uint8_t status);
/**
* @brief 底层短信消息回调函数event是消息param是具体数据指针暂时不同的平台需要独自处理
*
*/
typedef void (*luat_mobile_sms_event_callback_t)(uint32_t event, void *param);
/**
* @brief 注册网络状态及相关功能状态发生更换时的回调函数
*
* @param callback_fun 网络状态及相关功能状态发生更换时的回调函数
* @return int =0成功其他失败
*/
int luat_mobile_event_register_handler(luat_mobile_event_callback_t callback_fun);
/**
* @brief 注销网络状态及相关功能状态发生更换时的回调函数
*
* @return int =0成功其他失败
*/
int luat_mobile_event_deregister_handler(void);
/**
* @brief 注册底层短信消息回调函数,后续改为统一消息处理
*
* @param callback_fun 短信消息回调函数如果为NULL则是注销
* @return int =0成功其他失败
*/
int luat_mobile_sms_sdk_event_register_handler(luat_mobile_sms_event_callback_t callback_fun);
/* ------------------------------------------------- mobile status end ------------------------------------------------ */
/**
* @brief 设置RRC自动释放时间在RRC active见LUAT_MOBILE_EVENT_CSCON后经过一段时间在适当的时机释放RRC
*
* @param s 超时时间单位秒如果为0则是关闭功能
* @note 没有在Air724上使用过AT*RTIME的或者不明白RRC的含义请不要使用RRC相关API
*/
void luat_mobile_set_rrc_auto_release_time(uint8_t s);
/**
* @brief RRC自动释放暂停/恢复
*
* @param onoff 1暂停 0恢复
* @note 没有在Air724上使用过AT*RTIME的或者不明白RRC的含义请不要使用RRC相关API
*/
void luat_mobile_rrc_auto_release_pause(uint8_t onoff);
/**
* @brief RRC立刻释放一次不能在luat_mobile_event_callback里使用
* @note 没有在Air724上使用过AT*RTIME的或者不明白RRC的含义请不要使用RRC相关API
*/
void luat_mobile_rrc_release_once(void);
/**
* @brief 重新底层网络协议栈,本质是快速的进出飞行模式,注意和设置飞行模式是冲突的,一定时间内只能用一个。
*
* @return int =0成功其他失败
*/
int luat_mobile_reset_stack(void);
/**
* @brief 设置周期性辅助工作包括周期性搜索小区基站SIM卡短时间脱离卡槽后周期性尝试恢复这个功能和luat_mobile_reset_stack是有可能冲突的。所有功能默认都是关闭的
*
* @param get_cell_period 周期性搜索小区基站的时间间隔单位ms这个会增加低功耗尽量的长或者写0关闭这个功能用上面的手段搜索
* @param check_sim_period SIM卡短时间脱离卡槽后尝试恢复的时间间隔单位ms建议在5000~10000或者写0当SIM卡移除的消息上来后手动重启协议栈
* @param search_cell_time 启动周期性搜索小区基站后每次搜索的最大时间单位s1~8
* @return int
*/
int luat_mobile_set_period_work(uint32_t get_cell_period, uint32_t check_sim_period, uint8_t search_cell_time);
/** @}*/
#endif

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_OTP_H
#define LUAT_OTP_H
#include "luat_base.h"
/**
* @defgroup luatos_otp OTP操作
* @{
*/
/**
* @brief 读取指定区域的OTP数据
*
* @param zone OTP的区域, 通常为1,2,3等整数,与设备相关
* @param buff[OUT] 读出的数据
* @param offset 偏移量, 通常为0
* @param len 读取长度, offset+len不能超过OTP区域的长度
* @return int <= 0错误 >0实际传出的大小
*/
int luat_otp_read(int zone, char* buff, size_t offset, size_t len);
/**
* @brief 写入指定区域的OTP数据
*
* @param zone OTP的区域, 通常为1,2,3等整数,与设备相关
* @param buff[IN] 写入的数据
* @param offset 偏移量, 通常为0
* @param len 读取长度, offset+len不能超过OTP区域的长度
* @return int <= 0错误 >0实际写入的大小
*/
int luat_otp_write(int zone, char* buff, size_t offset, size_t len);
/**
* @brief 抹除指定区域的OTP数据
*
* @param zone OTP的区域, 通常为1,2,3等整数,与设备相关
* @param offset 偏移量, 通常为0, 大部分设备只支持整个区域的抹除,该参数无效
* @param len 抹除长度,通常为区域大小. 若设备只支持正常抹除,该参数无效
* @return int != 0错误 =0 正常
*/
int luat_otp_erase(int zone, size_t offset, size_t len);
/**
* @brief 锁定指定区域的OTP数据,不再可写,不可抹除
*
* @param zone OTP的区域, 通常为1,2,3等整数,与设备相关
* @return int != 0错误 =0 正常
*/
int luat_otp_lock(int zone);
/**
* @brief 指定区域的OTP区域大小
*
* @param zone OTP的区域, 通常为1,2,3等整数,与设备相关
* @return int == 0 无该区域, > 0 区域大小, 例如 256, 512
*/
int luat_otp_size(int zone);
/**
* @}
*/
#endif

View File

@@ -0,0 +1,344 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_PM_H
#define LUAT_PM_H
#include "luat_base.h"
/**
* @defgroup luatos_pm 电源管理接口
* @{
*/
/* ------------------------------------------------ sleep begin----------------------------------------------- */
#define LUAT_PM_SLEEP_MODE_NONE 0 ///< 系统处于活跃状态,未采取任何的降低功耗状态
#define LUAT_PM_SLEEP_MODE_IDLE 1 ///< 空闲模式,该模式在系统空闲时停止 CPU 和部分时钟,任意事件或中断均可以唤醒
#define LUAT_PM_SLEEP_MODE_LIGHT 2 ///< 轻度睡眠模式CPU 停止,多数时钟和外设停止
#define LUAT_PM_SLEEP_MODE_DEEP 3 ///< 深度睡眠模式CPU 停止,仅少数低功耗外设工作,可被特殊中断唤醒
#define LUAT_PM_SLEEP_MODE_STANDBY 4 ///< 待机模式CPU 停止,设备上下文丢失(可保存至特殊外设),唤醒后通常复位
//#define LUAT_PM_SLEEP_MODE_SHUTDOWN 5 ///<关断模式,比 Standby 模式功耗更低, 上下文通常不可恢复, 唤醒后复位
/**
* @brief 设置最深休眠模式标记
*
* @param mode 最深休眠模式
* @param vote_tag 休眠标记
* @return int =0成功其他失败
*/
int luat_pm_set_sleep_mode(int mode, const char *vote_tag);
/**
* @brief 获取休眠标记对应的休眠模式
*
* @param vote_tag 休眠标记
* @return int = -1 失败,其他成功
*/
int luat_pm_get_sleep_mode(const char *vote_tag);
typedef void (*luat_pm_sleep_callback_t)(int mode);
/**
* @brief 注册休眠前回调函数
*
* @param callback_fun 休眠前用户回调
* @return int =0成功其他失败
*/
int luat_pm_sleep_register_pre_handler(luat_pm_sleep_callback_t callback_fun);
/**
* @brief 解注册休眠前回调函数
*
* @return int =0成功其他失败
*/
int luat_pm_sleep_deregister_pre_handler(void);
/**
* @brief 注册唤醒后回调函数
*
* @param callback_fun 唤醒后用户回调
* @return int =0成功其他失败
*/
int luat_pm_sleep_register_post_handler(luat_pm_sleep_callback_t callback_fun);
/**
* @brief 解注册唤醒后回调函数
*
* @param callback_fun 唤醒后用户回调
* @return int =0成功其他失败
*/
int luat_pm_sleep_deregister_post_handler(void);
/*------------------------------------------------ sleep end----------------------------------------------- */
/* ----------------------------------------------- wkaeup begin---------------------------------------------- */
/**
* @brief wakeupPad
*/
typedef enum LUAT_PM_WAKEUP_PAD
{
LUAT_PM_WAKEUP_PAD_0 = 0, /**<wakeupid_0*/
LUAT_PM_WAKEUP_PAD_1, /**<wakeupid_1*/
LUAT_PM_WAKEUP_PAD_2,/**<wakeupid_2*/
LUAT_PM_WAKEUP_PAD_3,/**<wakeupid_3*/
LUAT_PM_WAKEUP_PAD_4,/**<wakeupid_4*/
LUAT_PM_WAKEUP_PAD_5,/**<wakeupid_5*/
LUAT_PM_WAKEUP_LPUART,/**<LPUART 唤醒*/
LUAT_PM_WAKEUP_LPUSB,/**<LPUSB唤醒*/
LUAT_PM_WAKEUP_PWRKEY,/**<PWRKEY唤醒*/
LUAT_PM_WAKEUP_CHARGE,/**<CHARGE唤醒*/
LUAT_PM_WAKEUP_PAD_MAX
}LUAT_PM_WAKEUP_PAD_E;
/**
* @brief wakeupPad配置参数
*/
typedef struct luat_pm_wakeup_pad_cfg
{
uint8_t pos_edge_enable;
uint8_t neg_edge_enable;
uint8_t pull_up_enable;
uint8_t pull_down_enable;
}luat_pm_wakeup_pad_cfg_t;
/**
* @brief 定义wakeupPad中断回调函数类型
*/
typedef void (*luat_pm_wakeup_pad_isr_callback_t)(LUAT_PM_WAKEUP_PAD_E num);
/**
* @brief 设置wakeupPad中断回调函数
*
* @param callback_fun wakeupPad中断回调函数
* @return int =0成功其他失败
*/
int luat_pm_wakeup_pad_set_callback(luat_pm_wakeup_pad_isr_callback_t callback_fun);
/**
* @brief 配置wakeupPad中断参数和GPIO20-22输入配置冲突不可以和GPIO的API同时使用建议使用GPIO的API
*
* @param enable 中断使能
* @param source_id wakeupPad
* @param cfg wakeupPad配置参数
* @return int =0成功其他失败
*/
int luat_pm_wakeup_pad_set(uint8_t enable, LUAT_PM_WAKEUP_PAD_E source_id, luat_pm_wakeup_pad_cfg_t *cfg);
/**
* @brief 获取wakeupPad引脚电平
*
* @param source_id wakeupPad
* @return int =-1失败0为低电平1为高电平
*/
int luat_pm_wakeup_pad_get_value(LUAT_PM_WAKEUP_PAD_E source_id);
/**
* @brief powerkey设置模式
*/
typedef enum LUAT_PM_POWERKEY_MODE
{
LUAT_PM_PWRKEY_PWRON_MODE = 0, /**默认*/
LUAT_PM_PWRKEY_WAKEUP_LOWACTIVE_MODE, /**低电平按下*/
LUAT_PM_PWRKEY_WAKEUP_HIGHACTIVE_MODE, /**高电平按下*/
LUAT_PM_PWRKEY_UNKNOW_MODE,
}LUAT_PM_POWERKEY_MODE_E;
/**
* @brief powerkey状态
*/
typedef enum LUAT_PM_POWERKEY_STATE
{
LUAT_PM_PWRKEY_RELEASE = 0, /**释放*/
LUAT_PM_PWRKEY_PRESS, /**按下*/
LUAT_PM_PWRKEY_LONGPRESS, /**长按*/
LUAT_PM_PWRKEY_REPEAT, /**重复激活*/
}LUAT_PM_POWERKEY_STATE_E;
/**
* @brief powerkey配置参数
*/
typedef struct
{
int16_t long_press_timeout; /**长按超时时间*/
int16_t repeat_timeout; /**重复超时时间*/
int16_t pwroff_timeout; /**关机时间,此值无意义*/
}luat_pm_pwrkey_cfg_t;
typedef void(* luat_pm_pwrkey_callback_t)(LUAT_PM_POWERKEY_MODE_E status);
/**
* @brief 配置powerkey按键
*
* @param mode 中断使能
* @param pullUpEn wakeupPad
* @param cfg powerkey配置参数
* @param callback powerkey回调函数
* @return int =0成功其他失败
*/
int luat_pm_set_pwrkey(LUAT_PM_POWERKEY_MODE_E mode, bool pullUpEn, luat_pm_pwrkey_cfg_t *cfg, luat_pm_pwrkey_callback_t callback);
/* ------------------------------------------------ wakeup end----------------------------------------------- */
/* ---------------------------------------- power on/off/reboot begin---------------------------------------- */
/**
* @brief 开机原因
*/
typedef enum LUAT_PM_POWERON_REASON
{
LUAT_PM_POWERON_REASON_KEY, /**<按键开机*/
LUAT_PM_POWERON_REASON_CHARGER, /**<充电开机*/
LUAT_PM_POWERON_REASON_ALARM, /**<闹钟开机*/
LUAT_PM_POWERON_REASON_REBOOT, /**<软件重启开机*/
LUAT_PM_POWERON_REASON_EXCEPTION, /**<异常重启*/
LUAT_PM_POWERON_REASON_RESET, /**<reset 键重启*/
LUAT_PM_POWERON_REASON_WDT, /**<看门狗重启*/
LUAT_PM_POWERON_REASON_UNKOWN = 0xFF /**<未知原因*/
} LUAT_PM_POWERON_REASON_E;
/**
* @brief 获取开机原因
* @param NULL
* @return @see LUAT_PM_POWERON_REASON_E
*/
int luat_pm_get_poweron_reason(void);
/**
* @brief 设置设备关机
*/
int luat_pm_poweroff(void);
/**
* @brief 设备重启
*/
int luat_pm_reboot(void);
/* ----------------------------------------- power on/off/reboot end----------------------------------------- */
/* --------------------------------------------- vbat/vbus begin--------------------------------------------- */
/**
* @brief 获取充电器状态
* @param status 充电器状态
*/
int luat_pm_get_vbus_status(uint8_t *status);
/**
* @brief 电源管理事件变化参数
*/
typedef enum LUAT_PM_EVENT
{
LUAT_PM_BATTERY_VOLT_EVENT = 0,/**<电池电量发生变化*/
LUAT_PM_VBUS_STATUS_EVENT/**<VBUS状态发生变化*/
}LUAT_PM_EVENT_E;
/**
* @brief 定义PM_event事件处理函数
*/
typedef void (*luat_pm_event_callback_t)(LUAT_PM_EVENT_E event, uint32_t param);
/**
* @brief 定义PM_event事件处理函数回调函数
* @param luat_pm_event_callback_t 指针函数
*/
int luat_pm_event_register_handler(luat_pm_event_callback_t callback_fun);
/* ---------------------------------------------- vbat/vbus end---------------------------------------------- */
/* ------------------------------------------------ timer begin----------------------------------------------- */\
/**
* @brief 深度睡眠模式的软件定时器ID
*/
typedef enum LUAT_PM_DEEPSLEEP_TIMERID
{
LUAT_PM_DEEPSLEEP_TIMER_ID0 = 0, /**0和1最大定时时间为2.5小时精度为10ms不需要存储信息到flash*/
LUAT_PM_DEEPSLEEP_TIMER_ID1,
LUAT_PM_DEEPSLEEP_TIMER_ID2, /**2到6最大定时时间为740小时精度为10ms需要存储信息到flash此类定时器尽量避免反复启动停止防止减少flash寿命如果定时时长不超过2.5小时建议使用0和1*/
LUAT_PM_DEEPSLEEP_TIMER_ID3,
LUAT_PM_DEEPSLEEP_TIMER_ID4,
LUAT_PM_DEEPSLEEP_TIMER_ID5,
LUAT_PM_DEEPSLEEP_TIMER_ID6,
}LUAT_PM_DEEPSLEEP_TIMERID_E;
/**
* @brief 从深度休眠模式下唤醒的原因
*/
typedef enum LUAT_PM_WAKEUP_REASON
{
LUAT_PM_WAKEUP_FROM_POR = 0,
LUAT_PM_WAKEUP_FROM_RTC,
LUAT_PM_WAKEUP_FROM_PAD,
LUAT_PM_WAKEUP_FROM_LPUART,
LUAT_PM_WAKEUP_FROM_LPUSB,
LUAT_PM_WAKEUP_FROM_PWRKEY,
LUAT_PM_WAKEUP_FROM_CHARG,
}LUAT_PM_WAKEUP_REASON_E;
/**
* @brief 定义定时时间到后的回调函数类型
*/
typedef LUAT_RT_RET_TYPE (*luat_pm_deep_sleep_mode_timer_callback_t)(LUAT_PM_DEEPSLEEP_TIMERID_E timer_id);
/**
* @brief 注册深度睡眠模式下的软件定时器超时回调函数
*
* @param timer_id 定时器ID
* @param callback 回调函数
* @return int =0成功其他失败
*/
int luat_pm_deep_sleep_mode_register_timer_cb(LUAT_PM_DEEPSLEEP_TIMERID_E timer_id, luat_pm_deep_sleep_mode_timer_callback_t callback);
/**
* @brief 启动深度睡眠模式下的软件定时器
*
* @param timer_id 定时器ID
* @param timeout 超时时间单位ms
* @return int =0成功其他失败
*/
int luat_pm_deep_sleep_mode_timer_start(LUAT_PM_DEEPSLEEP_TIMERID_E timer_id, int timeout);
/**
* @brief 停止深度睡眠模式下的软件定时器
*
* @param timer_id 定时器ID
* @return int =0成功其他失败
*/
int luat_pm_deep_sleep_mode_timer_stop(LUAT_PM_DEEPSLEEP_TIMERID_E timer_id);
/**
* @brief 检查深度睡眠模式下的软件定时器是否正在运行
*
* @param timer_id 定时器ID
* @return int =0未运行int =1正在运行
*/
int luat_pm_deep_sleep_mode_timer_is_running(LUAT_PM_DEEPSLEEP_TIMERID_E timer_id);
/**
* @brief 获取唤醒原因
*
* @return LUAT_PM_WAKEUP_REASON
*/
int luat_pm_get_wakeup_reason(void);
/*------------------------------------------------ timer end----------------------------------------------- */
/**
* @brief 手动控制USB电源
*
* @param onoff 0关其他开
* @return int =0成功其他失败
*/
int luat_pm_set_usb_power(uint8_t onoff);
/**@}*/
#endif

View File

@@ -0,0 +1,123 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_PWM_H
#define LUAT_PWM_H
/**
*@version V1.0
*@attention
1.在使用int luat_pwm_open(int channel, size_t period, size_t freq, int pnum);
函数时依次依次设置PWM通道设置PWM频率设置占空比PWM个数
若需要使用设置PWM个数时PWM频率不宜高于50K,若高于50K可能会多出几个个数的现象
2.int luat_pwm_capture(int channel,int freq); 获取pwm 频率
此函数获取PWM频率功能尚未实现
*/
/**
* @ingroup luatos_device 外设接口
* @{
*/
/**
* @defgroup luatos_device_PWM PWM接口
* @{
*/
#include "luat_base.h"
/**
* @brief PWM控制参数
*/
typedef struct luat_pwm_conf {
int channel; /**<PWM通道 可选通道为 0 / 1 / 2 / 4 总计4个通道*/
size_t period; /**<频率, 1Hz - 13MHz*/
size_t pulse; /**<占空比0-100 如将pulse设为50时输出高电平时间占周期50%时间 */
size_t pnum; /**<输出周期 0为持续输出, 1为单次输出, 其他为指定脉冲数输出*/
size_t precision; /**<分频精度, 100/256/1000, 默认为100, 若设备不支持会有日志提示*/
} luat_pwm_conf_t;
/**
* @brief 配置pwm 参数
*
* @param conf->channel: 选择PWM通道 可选通道为 0 / 1 / 2 / 4 总计4个通道
* conf->period : 设置产生的PWM频率
* conf->pulse : 设置产生的PWM占空比
* conf->pnum : 设置产生的PWM个数若pnum设为0将一直输出PWM
* @return int
* 返回值为 0 : 配置PWM成功
* 返回值为 -1: PWM通道选择错误
* 返回值为 -2: PWM频率设置错误
* 返回值为 -3PWM占空比设置错误
* 返回值为 -4: 该PWM通道已被使用
*/
int luat_pwm_setup(luat_pwm_conf_t* conf);
/**
* @brief 打开pwm 通道
*
* @param channel: 选择PWM通道 可选通道为 0 / 1 / 2 / 4 总计4个通道
* period : 设置产生的PWM频率
* pulse : 设置产生的PWM占空比
* pnum 设置产生的PWM个数若pnum设为0将一直输出PWM
* @return int
* 返回值为 0 : 配置PWM成功
* 返回值为 -1: PWM通道选择错误
* 返回值为 -2: PWM频率设置错误
* 返回值为 -3PWM占空比设置错误
* 返回值为 -4: 该PWM通道已被使用
*/
int luat_pwm_open(int channel, size_t period, size_t pulse, int pnum);
/**
* @brief 获取pwm 频率 本功能暂未实现
*
* @param id i2c_id
* @return int
*/
int luat_pwm_capture(int channel,int freq);
/**
* @brief 关闭pwm 接口
*
* @param channel: 选择PWM通道 可选通道为 0 / 1 / 2 / 4 总计4个通道
* @return int
*/
int luat_pwm_close(int channel);
/**
* @brief 修改占空比
* @param channel: 选择pwm通道 可选通道为 0 / 1 / 2 / 4 总计4个通道
* pulse 修改pwm占空比值
* @return int
*/
/*int luat_pwm_update_dutycycle(int channel,size_t pulse);函数使用方法*/
/*此函数为修改PWM占空比函数可在完成配置并打开PWM输出后根据使用者需求改变PWM输出占空比*/
/*可用于whiile 循环中int channel 参数为要修改的PWM通道size_t pulse 参数为将要输出的目标占空比*/
/*使用者根据自身使用需求填入相应参数数值即可*/
int luat_pwm_update_dutycycle(int channel,size_t pulse);
/** @}*/
/** @}*/
/** @}*/
#endif

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_RTC_H
#define LUAT_RTC_H
#include "luat_base.h"
#include "time.h"
/**
* @defgroup luatos_RTC 时钟接口(RTC)
* @{
*/
/**
* @brief 设置系统时间
*
* @param tblock
* @return int =0成功其他失败
*/
int luat_rtc_set(struct tm *tblock);
/**
* @brief 获取系统时间
*
* @param tblock
* @return int =0成功其他失败
*/
int luat_rtc_get(struct tm *tblock);
#endif

View File

@@ -0,0 +1,420 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_RTOS_H
#define LUAT_RTOS_H
#include "luat_base.h"
#include "luat_rtos_legacy.h"
/**
* @defgroup luatos_os 操作系统接口
* @{
*/
/**
* @brief LUAT_RTOS 超时时间枚举值
*/
typedef enum LUAT_RTOS_WAIT
{
LUAT_NO_WAIT = 0, /**< 超时时间为0 */
LUAT_WAIT_FOREVER = (uint32_t)0xFFFFFFFF /**< 最大超时时间0xFFFFFFFF*/
} LUAT_RTOS_WAIT_E;
/* ------------------------------------------------ task begin------------------------------------------------ */
/**
* @defgroup luatos_os_Task 线程任务接口函数
* @{
*/
/**
*@brief task的入口函数,函数类型
*/
typedef void (*luat_rtos_task_entry) (void*);
/**
*@brief 定义task任务句柄
*/
typedef void * luat_rtos_task_handle;
/**
* @brief 创建一个可以带mailbox机制的task
*
* @param task_handle[OUT] 返回创建的句柄
* @param stack_size task的栈空间大小单位byte必须4字节对齐
* @param priority 优先级单位是百分比0%~100%,100%为最高等级由具体实现转换到底层SDK用的优先级
* @param task_name task名字
* @param task_fun task的入口函数
* @param user_data task的入口参数
* @param event_cout =0表示不需要使用mailbox机制>0表示启用mailbox可以使用下列event和massage api同时如果底层SDK不支持mailbox会创建一个queue模拟mailboxqueue里元素为luat_event_t数量为event_cout
* @return int =0成功其他失败
*/
int luat_rtos_task_create(luat_rtos_task_handle *task_handle, uint32_t stack_size, uint8_t priority, const char *task_name, luat_rtos_task_entry task_fun, void* user_data, uint16_t event_cout);
/**
* @brief 删除task
*
* @param task_handle
* @return int =0成功其他失败
*/
int luat_rtos_task_delete(luat_rtos_task_handle task_handle);
/**
* @brief 挂起某个task
*
* @param task_handle task句柄
* @return int =0成功其他失败
*/
int luat_rtos_task_suspend(luat_rtos_task_handle task_handle);
/**
* @brief 恢复挂起的task
*
* @param task_handle task句柄
* @return int =0成功其他失败
*/
int luat_rtos_task_resume(luat_rtos_task_handle task_handle);
/**
* @brief 挂起全部task
*
*/
void luat_rtos_task_suspend_all(void);
/**
* @brief 恢复全部task
*
*/
void luat_rtos_task_resume_all(void);
/**
* @brief task休眠一段时间
*
* @param ms 休眠时间单位ms
*/
void luat_rtos_task_sleep(uint32_t ms);
/**
* @brief 获取当前task的句柄
*
* @return luat_rtos_task_handle 当前task的句柄
*/
luat_rtos_task_handle luat_rtos_get_current_handle(void);
/**
* @brief 获取task堆栈剩余的最小值叫做“高水位线”
*
* @param luat_rtos_task_handle task的句柄
* @return task堆栈剩余的最小值,单位为字
*/
uint32_t luat_rtos_task_get_high_water_mark(luat_rtos_task_handle task_handle);
/** @}*/
/* ------------------------------------------------ task end------------------------------------------------ */
/**
* @defgroup luatos_os_event 消息事件函数
* @{
*/
/* ----------------------------------------------- event begin---------------------------------------------- */
/**
* @brief 在等待event中如果设置了目标event id而到来的不是目标event id可以通过回调函数交给用户处理
*
*/
typedef LUAT_RT_RET_TYPE (*luat_rtos_event_wait_callback_t)(LUAT_RT_CB_PARAM);
/**
* @brief 发送一个event给task的mailbox只有设置了mailbox启用的task能接收
*
* @param task_handle 需要接收event的task句柄
* @param id event id
* @param param1 event参数1
* @param param2 event参数2
* @param param3 event参数3
* @param timeout 发送超时在task发送才有单位ms特殊值见LUAT_RTOS_WAIT_E
* @return int =0成功其他失败
*/
int luat_rtos_event_send(luat_rtos_task_handle task_handle, uint32_t id, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t timeout);
/**
* @brief 接收一个event只能在task里接收
*
* @param task_handle 需要接收event的task句柄
* @param wait_event_id 目标event的ID=0表示不限制任意event id都会返回
* @param out_event[OUT] 接收到的event
* @param callback_fun event的ID不是目标ID时用户回调函数可以为NULL从而抛弃掉这个event
* @param timeout 接收超时单位ms特殊值见LUAT_RTOS_WAIT_E
* @return int =0成功其他失败
*/
int luat_rtos_event_recv(luat_rtos_task_handle task_handle, uint32_t wait_event_id, luat_event_t *out_event, luat_rtos_event_wait_callback_t *callback_fun, uint32_t timeout);
/* ----------------------------------------------- event end---------------------------------------------- */
/* ----------------------------------------------- message begin---------------------------------------------- */
/**
* @brief 发送一个message给task的mailbox只有设置了mailbox启用的task能接收message可以动态创建的可以任意大小
*
* @param task_handle 需要接收massage的task句柄
* @param message_id message id
* @param p_message message内容传入指针如果动态创建需要在接收时释放
* @return int =0成功其他失败
*/
int luat_rtos_message_send(luat_rtos_task_handle task_handle, uint32_t message_id, void *p_message);
/**
* @brief 接收一个message只能在task里接收
*
* @param task_handle 需要接收massage的task句柄
* @param message_id[OUT] 接收到的message id
* @param p_p_message[OUT] message内容输出一个void *指针,如果是发送时动态创建的,需要释放掉
* @param timeout 接收超时单位ms特殊值见LUAT_RTOS_WAIT_E
* @return int =0成功其他失败
*/
int luat_rtos_message_recv(luat_rtos_task_handle task_handle, uint32_t *message_id, void **p_p_message, uint32_t timeout);
/** @}*/
/* ----------------------------------------------- message end---------------------------------------------- */
/**
* @defgroup luatos_os_semaphore 信号量接口函数
* @{
*/
/* ---------------------------------------------- semaphore begin--------------------------------------------- */
/**
* @brief 定义信号量句柄
*/
typedef void * luat_rtos_semaphore_t;
/**
* @brief 信号量创建可以在中断中release
*
* @param semaphore_handle[OUT] 信号量句柄
* @param init_count 初始值
* @return int =0成功其他失败
*/
int luat_rtos_semaphore_create(luat_rtos_semaphore_t *semaphore_handle, uint32_t init_count);
/**
* @brief 删除信号量
*
* @param semaphore_handle 信号量句柄
* @return int =0成功其他失败
*/
int luat_rtos_semaphore_delete(luat_rtos_semaphore_t semaphore_handle);
/**
* @brief 信号量等待获取
*
* @param semaphore_handle 信号量句柄
* @param timeout 接收超时单位ms特殊值见LUAT_RTOS_WAIT_E
* @return int =0成功其他失败
*/
int luat_rtos_semaphore_take(luat_rtos_semaphore_t semaphore_handle, uint32_t timeout);
/**
* @brief 信号量释放发送
*
* @param semaphore_handle 信号量句柄
* @return int =0成功其他失败
*/
int luat_rtos_semaphore_release(luat_rtos_semaphore_t semaphore_handle);
/* ---------------------------------------------- semaphore end--------------------------------------------- */
/** @}*/
/**
* @defgroup luatos_os_mutex 互斥锁接口函数
* @{
*/
/* ------------------------------------------------ mutex begin----------------------------------------------- */
/**
* @brief 定义mutex句柄
*/
typedef void * luat_rtos_mutex_t;
/**
* @brief 互斥锁创建不能在中断中unlock
*
* @param mutex_handle[OUT] 互斥锁句柄
* @return int =0成功其他失败
*/
int luat_rtos_mutex_create(luat_rtos_mutex_t *mutex_handle);
/**
* @brief 获得锁
*
* @param mutex_handle 互斥锁句柄
* @param timeout 超时单位ms特殊值见LUAT_RTOS_WAIT_E
* @return int =0成功其他失败
*/
int luat_rtos_mutex_lock(luat_rtos_mutex_t mutex_handle, uint32_t timeout);
/**
* @brief 释放锁
*
* @param mutex_handle 互斥锁句柄
* @return int =0成功其他失败
*/
int luat_rtos_mutex_unlock(luat_rtos_mutex_t mutex_handle);
/**
* @brief 删除互斥锁
*
* @param mutex_handle 互斥锁句柄
* @return int =0成功其他失败
*/
int luat_rtos_mutex_delete(luat_rtos_mutex_t mutex_handle);
/* ------------------------------------------------ mutex end----------------------------------------------- */
/** @}*/
/**
* @defgroup luatos_os_queue 队列接口函数
* @{
*/
/* ------------------------------------------------ queue begin----------------------------------------------- */
/**
* @brief 定义队列句柄
*/
typedef void * luat_rtos_queue_t;
/**
* @brief 创建队列
*
* @param queue_handle[OUT] 返回的队列句柄
* @param msgcount 队列里元素的最大数量
* @param msgsize 队列里单个元素的大小
* @return int =0成功其他失败
*/
int luat_rtos_queue_create(luat_rtos_queue_t *queue_handle, uint32_t item_count, uint32_t item_size);
/**
* @brief 删除队列
*
* @param queue_handle 队列句柄
* @return int =0成功其他失败
*/
int luat_rtos_queue_delete(luat_rtos_queue_t queue_handle);
/**
* @brief 往队列里发送一个元素
*
* @param queue_handle 队列句柄
* @param item 元素指针
* @param item_size 元素大小这个是兼容性参数实际上必须于创建时的item_size一致所以忽略
* @param timeout 超时单位ms特殊值见LUAT_RTOS_WAIT_E
* @return int =0成功其他失败
*/
int luat_rtos_queue_send(luat_rtos_queue_t queue_handle, void *item, uint32_t item_size, uint32_t timeout);
/**
* @brief 从队列里取出一个元素
*
* @param queue_handle 队列句柄
* @param item 元素指针
* @param item_size 元素大小这个是兼容性参数实际上必须于创建时的item_size一致所以忽略
* @param timeout 超时单位ms特殊值见LUAT_RTOS_WAIT_E
* @return int =0成功其他失败
*/
int luat_rtos_queue_recv(luat_rtos_queue_t queue_handle, void *item, uint32_t item_size, uint32_t timeout);
/* ------------------------------------------------ queue end----------------------------------------------- */
/** @}*/
/**
* @defgroup luatos_os_timer 软件定时器接口函数
* @{
*/
/* ------------------------------------------------ timer begin----------------------------------------------- */
/**
* @brief 定时器头数据类型
*/
typedef void * luat_rtos_timer_t;
/**
* @brief 定义定时器处理函数
*/
typedef LUAT_RT_RET_TYPE (*luat_rtos_timer_callback_t)(LUAT_RT_CB_PARAM);
/**
* @brief 创建软件定时器
*
* @param timer_handle[OUT] 返回定时器句柄
* @return int =0成功其他失败
*/
int luat_rtos_timer_create(luat_rtos_timer_t *timer_handle);
/**
* @brief 删除软件定时器
*
* @param timer_handle 定时器句柄
* @return int =0成功其他失败
*/
int luat_rtos_timer_delete(luat_rtos_timer_t timer_handle);
/**
* @brief 启动软件定时器
*
* @param timer_handle 定时器句柄
* @param timeout 超时时间单位ms没有特殊值
* @param repeat 0不重复其他重复
* @param callback_fun 定时时间到后的回调函数
* @param user_param 回调函数时的最后一个输入参数
* @return int =0成功其他失败
*/
int luat_rtos_timer_start(luat_rtos_timer_t timer_handle, uint32_t timeout, uint8_t repeat, luat_rtos_timer_callback_t callback_fun, void *user_param);
/**
* @brief 停止软件定时器
*
* @param timer_handle 定时器句柄
* @return int =0成功其他失败
*/
int luat_rtos_timer_stop(luat_rtos_timer_t timer_handle);
/**
* @brief 检测软件定时器是否处于激活状态
*
* @param timer_handle 定时器句柄
* @return int =0未激活1激活其他失败
*/
int luat_rtos_timer_is_active(luat_rtos_timer_t timer_handle);
/*------------------------------------------------ timer end----------------------------------------------- */
/** @}*/
/**
* @defgroup luatos_os_critical 临界保护接口函数
* @{
*/
/* ------------------------------------------------ critical begin----------------------------------------------- */
/**
* @brief 进入临界保护
*
* @return uint32_t 退出临界保护所需参数
*/
uint32_t luat_rtos_entry_critical(void);
/**
* @brief 退出临界保护
*
* @param critical 进入临界保护时返回的参数
*/
void luat_rtos_exit_critical(uint32_t critical);
/*------------------------------------------------ critical end----------------------------------------------- */
/** @}*/
/** @}*/
#endif

View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_RTOS_LEGACY_H
#define LUAT_RTOS_LEGACY_H
#include "luat_base.h"
/**
* @brief event参数
*/
typedef struct
{
uint32_t id;
uint32_t param1;
uint32_t param2;
uint32_t param3;
}luat_event_t;
//定时器回调函数需要定义成 LUAT_RT_RET_TYPE fun_name(LUAT_RT_CB_PARAM)
//定时器回调函数退出时需要, return LUAT_RT_RET;
#ifndef LUAT_RT_RET_TYPE
#define LUAT_RT_RET_TYPE void
#endif
#ifndef LUAT_RT_RET
#define LUAT_RT_RET
#endif
#ifndef LUAT_RT_CB_PARAM
#define LUAT_RT_CB_PARAM void
//#define LUAT_RT_CB_PARAM void *param
//#define LUAT_RT_CB_PARAM void *pdata, void *param
#endif
/* ----------------------------------- thread ----------------------------------- */
LUAT_RET luat_send_event_to_task(void *task_handle, uint32_t id, uint32_t param1, uint32_t param2, uint32_t param3);
LUAT_RET luat_wait_event_from_task(void *task_handle, uint32_t wait_event_id, luat_event_t *out_event, void *call_back, uint32_t ms);
void *luat_get_current_task(void);
/* -----------------------------------信号量模拟互斥锁可以在中断中unlock-------------------------------*/
void *luat_mutex_create(void);
LUAT_RET luat_mutex_lock(void *mutex);
LUAT_RET luat_mutex_unlock(void *mutex);
void luat_mutex_release(void *mutex);
/* ----------------------------------- timer ----------------------------------- */
/**
* @brief 创建软件定时器
* @param cb 定时处理函数
* @param param 参数
* @param task_handle[OUT] 返回定时器句柄
* @return int =0成功其他失败
*/
void *luat_create_rtos_timer(void *cb, void *param, void *task_handle);
/**
* @brief 启动软件定时器
* @param timer 定时器句柄
* @param ms 定时时间
* @param is_repeat 是否为周期定时
*/
int luat_start_rtos_timer(void *timer, uint32_t ms, uint8_t is_repeat);
/**
* @brief 停止软件定时器
* @param timer 定时器句柄
*/
void luat_stop_rtos_timer(void *timer);
/**
* @brief 复位软件定时器
* @param timer 定时器句柄
*/
void luat_release_rtos_timer(void *timer);
/**
* @brief 挂起全部task
*
*/
void luat_task_suspend_all(void);
/**
* @brief 恢复全部task
*
*/
void luat_task_resume_all(void);
#endif

View File

@@ -0,0 +1,141 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_SMS_H
#define LUAT_SMS_H
#include "luat_base.h"
#define LUAT_MSG_MAX_ADDR_LEN 80
#define LUAT_SMS_MAX_TXT_SIZE 640
#define LUAT_SMS_MAX_PDU_SIZE 180
#define LUAT_SMS_MAX_LENGTH_OF_ADDRESS_VALUE 40
#define LUAT_SMS_MAX_ADDR_STR_MAX_LEN ((LUAT_SMS_MAX_LENGTH_OF_ADDRESS_VALUE + 1) * 4)
typedef void (*LUAT_SMS_HANDLE_CB)(uint8_t event, void* param);
typedef void (*LUAT_SMS_HANDLE_SEND_CB)(int ret);
typedef enum
{
SMS_SEND_OK = 0,
SMS_ME_FAILURE = 300,
SMS_SERVICE_OF_ME_RESV,
SMS_OPERATION_NOT_ALLOWED,
SMS_OPERATION_NOT_SUPPORTED,
SMS_INVALID_PDU_MODE_PARAMETER,
SMS_INVALID_TEXT_MODE_PARAMETER,
SMS_USIM_NOT_INSERTED = 310,
SMS_USIM_PIN_REQUIRED,
SMS_PHSIM_PIN_REQUIRED,
SMS_USIM_FAILURE,
SMS_USIM_BUSY,
SMS_USIM_WRONG,
SMS_USIM_PUK_REQUIRED,
SMS_USIM_PIN2_REQUIRED,
SMS_USIM_PUK2_REQUIRED,
SMS_MEMORY_FAILURE = 320,
SMS_INVALID_MEM_INDEX,
SMS_MEM_FULL,
SMS_SMSC_ADDR_UNKNOWN = 330,
SMS_NO_NETWORK_SERVICE,
SMS_NETWORK_TIMEOUT,
SMS_NO_CNMA_ACK_EXPECTED = 340,
SMS_UNKNOWN_ERROR = 500,
SMS_INVALID_DATA = 550,
SMS_UNSUPPORT_TEXT_WITH_CHINESE = 555,
SMS_MAX_ERROR = 0xFFFF
}LUAT_SMS_SEND_RET_CODE_E;
typedef struct
{
LUAT_SMS_HANDLE_CB cb;
LUAT_SMS_HANDLE_SEND_CB send_cb;
}LUAT_SMS_MAIN_CFG_T;
typedef struct
{
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
uint8_t tz; /* time zone */
uint8_t tz_sign; /* '+'/'-' */
}LUAT_SMS_RECV_MSG_TIME_T;
typedef struct
{
uint8_t type;
uint8_t msg_class;
uint8_t alpha_bet;
uint8_t indication;
uint8_t dcs;
}LUAT_SMS_RECV_MSG_DCS_T;
//接受的短信信息结构体
typedef struct
{
uint16_t pdu_length;//PDU 长度
uint16_t sms_length;//TEXT 的长度
LUAT_SMS_RECV_MSG_TIME_T time;//时间
LUAT_SMS_RECV_MSG_DCS_T dcs_info;//Data Coding Scheme
char pdu_data[LUAT_SMS_MAX_TXT_SIZE + 1];//PDU 数据
uint8_t sms_buffer[LUAT_SMS_MAX_TXT_SIZE + 1];//TEXT 数据
uint8_t sc_address[LUAT_MSG_MAX_ADDR_LEN + 1];//中心地址
uint8_t phone_address[LUAT_MSG_MAX_ADDR_LEN + 1];//来电号码
uint8_t refNum;
uint8_t maxNum;
uint8_t seqNum;
}LUAT_SMS_RECV_MSG_T;
/**
* @defgroup luatos_sms 短信功能
* @{
*/
/**
* @brief 初始化短信
*/
void luat_sms_init(void);
/**
* @brief 发送短信
* @param p_input 短信的内容(当 is_pdu = false 时, 只支持英文,数字以及常用符号)
* @param p_des 接收短信的手机号
* @param is_pdu 是否是PDU格式的短信(当 false 时, 有效参数为 p_input & pdes, 当 true 时, 有效参数为 p_input & pudLen)
* @param input_pdu_len PDU格式短信的长度注意和p_input长度没有关系
* @return 0成功,-1失败
*/
int luat_sms_send_msg(uint8_t *p_input, char *p_des, bool is_pdu, int input_pdu_len);
/**
* @brief 接受短信回调
* @param callback_fun 回调函数
*/
void luat_sms_recv_msg_register_handler(LUAT_SMS_HANDLE_CB callback_fun);
/**
* @brief 发送短信回调
* @param callback_fun 回调函数
*/
void luat_sms_send_msg_register_handler(LUAT_SMS_HANDLE_SEND_CB callback_fun);
#endif

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_SPI_H
#define LUAT_SPI_H
#include "luat_base.h"
#include "luat_spi_legacy.h"
/**
* @ingroup luatos_device 外设接口
* @{
*/
/**
* @defgroup luatos_device_spi SPI接口
* @{
*/
/**
* @brief SPI功能配置
*/
typedef struct luat_spi
{
int id; /**< spi id 可选 10*/
int CPHA; /**< CPHA 可选 10*/
int CPOL; /**< CPOL 可选 10*/
int dataw; /**< 数据宽度 88bit */
int bit_dict; /**< 高低位顺序 可选 1MSB 0LSB */
int master; /**< 设置主从模式 可选 1主机 0从机 */
int mode; /**< 设置全\半双工 可选 1全双工0半双工 */
int bandrate; /**< 频率 最小100000 最大25600000*/
int cs; /**< cs控制引脚 SPI0的片选为GPIO8, 当配置为8时表示启用SPI0自带片选其他配置时需要自行编码控制片选*/
} luat_spi_t;
/**
* @brief 初始化配置SPI各项参数并打开SPI
*
* @param spi spi结构体
* @return int 成功返回0
*/
int luat_spi_setup(luat_spi_t* spi);
/**
* @brief 关闭SPI
*
* @param spi_id spi id
* @return int 成功返回0
*/
int luat_spi_close(int spi_id);
/**
* @brief 收发SPI数据
*
* @param spi_id spi id
* @param send_buf 发送数据
* @param send_length 发送数据长度
* @param recv_buf 接收数据
* @param recv_length 接收数据长度
* @return int 返回接收字节数
*/
int luat_spi_transfer(int spi_id, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length);
/**
* @brief 收SPI数据
*
* @param spi_id spi id
* @param recv_buf 接收数据
* @param length 数据长度
* @return int 返回接收字节数
*/
int luat_spi_recv(int spi_id, char* recv_buf, size_t length);
/**
* @brief 发SPI数据
*
* @param spi_id spi id
* @param send_buf 发送数据
* @param length 数据长度
* @return int 返回发送字节数
*/
int luat_spi_send(int spi_id, const char* send_buf, size_t length);
/**@}*/
/**@}*/
#endif

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_SPI_LEGACY_H
#define LUAT_SPI_LEGACY_H
#include "luat_base.h"
#ifdef __LUATOS__
typedef struct luat_spi_device
{
uint8_t bus_id;
luat_spi_t spi_config;
void* user_data;
} luat_spi_device_t;
typedef struct luat_fatfs_spi
{
uint8_t type;
uint8_t spi_id;
uint8_t spi_cs;
uint8_t nop;
uint32_t fast_speed;
luat_spi_device_t * spi_device;
}luat_fatfs_spi_t;
//收发SPI数据尝试启动DMA模式
int luat_spi_config_dma(int spi_id, uint32_t tx_channel, uint32_t rx_channel);
//非阻塞SPI收发数据
int luat_spi_no_block_transfer(int spi_id, uint8_t *tx_buff, uint8_t *rx_buff, size_t len, void *CB, void *pParam);
// 初始化总线
int luat_spi_bus_setup(luat_spi_device_t* spi_dev);
// 初始化设备
int luat_spi_device_setup(luat_spi_device_t* spi_dev);
// 配置设备
int luat_spi_device_config(luat_spi_device_t* spi_dev);
//关闭SPI设备成功返回0
int luat_spi_device_close(luat_spi_device_t* spi_dev);
//收发SPI数据返回接收字节数
int luat_spi_device_transfer(luat_spi_device_t* spi_dev, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length);
//收SPI数据返回接收字节数
int luat_spi_device_recv(luat_spi_device_t* spi_dev, char* recv_buf, size_t length);
//发SPI数据返回发送字节数
int luat_spi_device_send(luat_spi_device_t* spi_dev, const char* send_buf, size_t length);
#endif
#endif

View File

@@ -0,0 +1,176 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_UART_H
#define LUAT_UART_H
#include "luat_base.h"
#include "luat_uart_legacy.h"
/**
*@version V1.0
*@attention
*上报接收数据中断的逻辑:
* 1.串口初始化时,新建一个缓冲区
* 2.可以考虑多为用户申请几百字节的缓冲长度,用户处理时防止丢包
* 3.每次串口收到数据时,先存入缓冲区,记录长度
* 4.遇到以下情况时,再调用串口中断
a)缓冲区满(帮用户多申请的的情况)/缓冲区只剩几百字节(按实际长度申请缓冲区的情况)
b)收到fifo接收超时中断此时串口数据应该是没有继续收了
* 5.触发收到数据中断时,返回的数据应是缓冲区的数据
* 6.关闭串口时,释放缓冲区资源
*/
/**
* @ingroup luatos_device 外设接口
* @{
*/
/**
* @defgroup luatos_device_uart UART接口
* @{
*/
/**
* @brief 校验位
*/
#define LUAT_PARITY_NONE 0 /**< 无校验 */
#define LUAT_PARITY_ODD 1 /**< 奇校验 */
#define LUAT_PARITY_EVEN 2 /**< 偶校验 */
/**
* @brief 高低位顺序
*/
#define LUAT_BIT_ORDER_LSB 0 /**< 低位有效 */
#define LUAT_BIT_ORDER_MSB 1 /**< 高位有效 */
/**
* @brief 停止位
*/
#define LUAT_0_5_STOP_BITS 0xf0 /**< 0.5 */
#define LUAT_1_5_STOP_BITS 0xf1 /**< 1.5 */
#define LUAT_VUART_ID_0 0x20
/**
* @brief luat_uart
* @attention uart0 为底层日志口接口,如果确需使用并明白所带来的后果, 请调用soc_uart0_set_log_off(1)关闭底层日志口具体实例参见project/example_uart demo;
*/
typedef struct luat_uart {
int id; /**< 串口id */
int baud_rate; /**< 波特率 */
uint8_t data_bits; /**< 数据位 */
uint8_t stop_bits; /**< 停止位 */
uint8_t bit_order; /**< 高低位 */
uint8_t parity; /**< 奇偶校验位 */
size_t bufsz; /**< 接收数据缓冲区大小 */
uint32_t pin485; /**< 转换485的pin, 如果没有则是0xffffffff*/
uint32_t delay; /**< 485翻转延迟时间单位us */
uint8_t rx_level; /**< 接收方向的电平 */
} luat_uart_t;
/**
* @brief uart初始化
*
* @param uart luat_uart结构体
* @return int
*/
int luat_uart_setup(luat_uart_t* uart);
/**
* @brief 串口写数据
*
* @param uart_id 串口id
* @param data 数据
* @param length 数据长度
* @return int
*/
int luat_uart_write(int uart_id, void* data, size_t length);
/**
* @brief 串口读数据
*
* @param uart_id 串口id
* @param buffer 数据
* @param length 数据长度
* @return int
*/
int luat_uart_read(int uart_id, void* buffer, size_t length);
/**
* @brief 关闭串口
*
* @param uart_id 串口id
* @return int
*/
int luat_uart_close(int uart_id);
/**
* @brief 检测串口是否存在
*
* @param uart_id 串口id
* @return int
*/
int luat_uart_exist(int uart_id);
/**
* @brief 串口控制参数
*/
typedef enum LUAT_UART_CTRL_CMD
{
LUAT_UART_SET_RECV_CALLBACK,/**< 接收回调 */
LUAT_UART_SET_SENT_CALLBACK/**< 发送回调 */
}LUAT_UART_CTRL_CMD_E;
/**
* @brief 接收回调函数
*
*/
typedef void (*luat_uart_recv_callback_t)(int uart_id, uint32_t data_len);
/**
* @brief 发送回调函数
*
*/
typedef void (*luat_uart_sent_callback_t)(int uart_id, void *param);
/**
* @brief 串口控制参数
*
*/
typedef struct luat_uart_ctrl_param
{
luat_uart_recv_callback_t recv_callback_fun;/**< 接收回调函数 */
luat_uart_sent_callback_t sent_callback_fun;/**< 发送回调函数 */
}luat_uart_ctrl_param_t;
/**
* @brief 串口控制
*
* @param uart_id 串口id
* @param cmd 串口控制命令
* @param param 串口控制参数
* @return int
*/
int luat_uart_ctrl(int uart_id, LUAT_UART_CTRL_CMD_E cmd, void* param);
/** @}*/
/** @}*/
#endif

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_UART_LEGACY_H
#define LUAT_UART_LEGACY_H
#include "luat_base.h"
#ifdef __LUATOS__
int l_uart_handler(lua_State *L, void* ptr);
#endif
#ifdef LUAT_FORCE_WIN32
int luat_uart_list(uint8_t* list, size_t buff_len);
#endif
int luat_setup_cb(int uartid, int received, int sent);
/*
上报接收数据中断的逻辑:
1.串口初始化时,新建一个缓冲区
2.可以考虑多为用户申请几百字节的缓冲长度,用户处理时防止丢包
3.每次串口收到数据时,先存入缓冲区,记录长度
4.遇到以下情况时,再调用串口中断
a)缓冲区满(帮用户多申请的的情况)/缓冲区只剩几百字节(按实际长度申请缓冲区的情况)
b)收到fifo接收超时中断此时串口数据应该是没有继续收了
5.触发收到数据中断时,返回的数据应是缓冲区的数据
6.关闭串口时,释放缓冲区资源
*/
#endif

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2022 OpenLuat & AirM2M
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LUAT_WDT_H
#define LUAT_WDT_H
#include "luat_base.h"
/**
* @brief 开启看门狗
* @param timeout 看门狗超时时间
* @return int =0成功其他失败
*/
int luat_wdt_setup(size_t timeout);
/**
* @brief 重新设置看门狗超时时间
* @param timeout 看门狗超时时间
* @return int =0成功其他失败
*/
int luat_wdt_set_timeout(size_t timeout);
/**
* @brief 喂狗
* @return int =0成功其他失败
*/
int luat_wdt_feed(void);
/**
* @brief 关闭看门狗
* @return int =0成功其他失败
*/
int luat_wdt_close(void);
#endif

View File

@@ -0,0 +1,56 @@
#ifndef _LUAT_WIFISCAN_H_
#define _LUAT_WIFISCAN_H_
#include "luat_base.h"
/**
* @defgroup luat_wifiscan wifiscan扫描接口
* @{
*/
/// @brief wifiscan 扫描的优先级
typedef enum luat_wifiscan_set_priority
{
LUAT_WIFISCAN_DATA_PERFERRD=0,/**< 数据优先*/
LUAT_WIFISCAN_WIFI_PERFERRD
}luat_wifiscan_set_priority_t;
/// @brief wifiscan 控制参数结构体
typedef struct luat_wifiscan_set_info
{
int maxTimeOut; //ms, AT max execution time
uint8_t round; //wifiscan total round
uint8_t maxBssidNum; //wifiscan max report num
uint8_t scanTimeOut; //s, max time of each round executed by RRC
uint8_t wifiPriority; //CmiWifiScanPriority
}luat_wifiscan_set_info_t;
#define LUAT_MAX_WIFI_BSSID_NUM 10 ///< bssid 的最大数量
#define LUAT_MAX_SSID_HEX_LENGTH 32 ///< SSID 的最大长度
/// @brief wifiscan 扫描结果
typedef struct luat_wifisacn_get_info
{
uint8_t bssidNum; /**<wifi 个数*/
uint8_t rsvd;
uint8_t ssidHexLen[LUAT_MAX_WIFI_BSSID_NUM]; /**<SSID name 的长度*/
uint8_t ssidHex[LUAT_MAX_WIFI_BSSID_NUM][LUAT_MAX_SSID_HEX_LENGTH]; /**<SSID name*/
int8_t rssi[LUAT_MAX_WIFI_BSSID_NUM]; /**<rssi*/
uint8_t channel[LUAT_MAX_WIFI_BSSID_NUM]; /**<record channel index of bssid, 2412MHz ~ 2472MHz correspoding to 1 ~ 13*/
uint8_t bssid[LUAT_MAX_WIFI_BSSID_NUM][6]; /**<mac address is fixed to 6 digits*/
}luat_wifisacn_get_info_t;
/**
* @brief 获取wifiscan 的信息
* @param set_info[in] 设置控制wifiscan的参数
* @param get_info[out] wifiscan 扫描结果
* @return int =0成功其他失败
*/
int32_t luat_get_wifiscan_cell_info(luat_wifiscan_set_info_t * set_info,luat_wifisacn_get_info_t* get_info);
/** @}*/
#endif