mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-21 10:25:54 +08:00
更新硬件SDK
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* LuatOS基础操作
|
||||
* @author wendal
|
||||
* @since 0.0.1
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef LUAT_BASE_H
|
||||
#define LUAT_BASE_H
|
||||
|
||||
#define LUAT_WEAK __attribute__((weak))
|
||||
|
||||
//-------------------------------
|
||||
// 通用头文件
|
||||
#include "stdint.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "stdbool.h"
|
||||
#include "printf.h"
|
||||
#define LUAT_RET int
|
||||
#define LUAT_RT_RET_TYPE void
|
||||
#define LUAT_RT_CB_PARAM void *param
|
||||
#endif
|
||||
127
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_adc.h
Normal file
127
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_adc.h
Normal 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
301
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_fs.h
Normal file
301
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_fs.h
Normal 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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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转换到CSQ,RSSI只能作为天线口状态的一个参考,而不能作为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是CID,SIM卡号之类的序号,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 启动周期性搜索小区基站后,每次搜索的最大时间,单位s,1~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
|
||||
@@ -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
|
||||
344
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_pm.h
Normal file
344
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_pm.h
Normal 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
|
||||
123
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_pwm.h
Normal file
123
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_pwm.h
Normal 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频率设置错误
|
||||
* 返回值为 -3:PWM占空比设置错误
|
||||
* 返回值为 -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频率设置错误
|
||||
* 返回值为 -3:PWM占空比设置错误
|
||||
* 返回值为 -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
|
||||
@@ -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
|
||||
@@ -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模拟mailbox,queue里元素为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
|
||||
@@ -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
|
||||
141
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_sms.h
Normal file
141
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_sms.h
Normal 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
|
||||
104
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_spi.h
Normal file
104
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/include/luat_spi.h
Normal 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 可选 1,0*/
|
||||
int CPHA; /**< CPHA 可选 1,0*/
|
||||
int CPOL; /**< CPOL 可选 1,0*/
|
||||
int dataw; /**< 数据宽度 8:8bit */
|
||||
int bit_dict; /**< 高低位顺序 可选 1:MSB, 0:LSB */
|
||||
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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* 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_AUDIO_PLAY_EC618_H__
|
||||
#define __LUAT_AUDIO_PLAY_EC618_H__
|
||||
#include "common_api.h"
|
||||
#include "audio_ll_drv.h"
|
||||
#include "audio_play.h"
|
||||
/**
|
||||
* @defgroup luatos_audio 音频接口
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief audio播放控制参数
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *path; /**< 文件路径,如果为NULL,则表示是ROM数组 */
|
||||
uint32_t address; /**< ROM数组地址 */
|
||||
uint32_t rom_data_len; /**< ROM数组长度 */
|
||||
uint8_t fail_continue; /**< 如果解码失败是否跳过继续下一个,如果是最后一个文件,强制停止并设置错误信息 */
|
||||
uint8_t dummy[3];
|
||||
}luat_audio_play_info_t;
|
||||
|
||||
enum
|
||||
{
|
||||
LUAT_MULTIMEDIA_CB_AUDIO_DECODE_START = MULTIMEDIA_CB_AUDIO_DECODE_START, /**< 开始解码文件 */
|
||||
LUAT_MULTIMEDIA_CB_AUDIO_OUTPUT_START, /**< 开始输出解码后的音数据 */
|
||||
LUAT_MULTIMEDIA_CB_AUDIO_NEED_DATA, /**< 底层驱动播放播放完一部分数据,需要更多数据 */
|
||||
LUAT_MULTIMEDIA_CB_AUDIO_DONE, /**< 底层驱动播放完全部数据了 */
|
||||
LUAT_MULTIMEDIA_CB_DECODE_DONE, /**< 音频解码完成 */
|
||||
LUAT_MULTIMEDIA_CB_TTS_INIT, /**< TTS做完了必要的初始化,用户可以通过audio_play_tts_set_param做个性化配置 */
|
||||
LUAT_MULTIMEDIA_CB_TTS_DONE, /**< TTS编码完成了。注意不是播放完成 */
|
||||
};
|
||||
|
||||
void luat_audio_play_file_default_fun(void *param);
|
||||
void luat_audio_play_tts_default_fun(void *param);
|
||||
/**
|
||||
* @brief 音频播放初始化,可以选择是否启用TTS,文件播放功能,用来节省flash空间
|
||||
*
|
||||
* @param event_cb 播放时event回调函数
|
||||
* @param data_cb 数据解码回调函数,如果是直接播放原始数据流就不会用到
|
||||
* @param play_file_fun 播放文件的具体处理函数,选择luat_audio_play_file_default_fun进行处理,或者写NULL不启用播放文件的功能
|
||||
* @param play_tts_fun 播放TTS的具体处理函数,选择luat_audio_play_tts_default_fun进行处理,或者写NULL不启用播放TTS的功能
|
||||
* @param user_param 回调函数的用户参数
|
||||
*/
|
||||
void luat_audio_play_global_init(
|
||||
audio_play_event_cb_fun_t event_cb,
|
||||
audio_play_data_cb_fun_t data_cb,
|
||||
audio_play_default_fun_t play_file_fun,
|
||||
audio_play_default_fun_t play_tts_fun,
|
||||
void *user_param);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 播放指定数量的文件或者ROM数组(文件数据直接写成数组形式)
|
||||
*
|
||||
* @param multimedia_id 多媒体通道,目前只有0
|
||||
* @param info 文件信息,文件路径或者ROM信息
|
||||
* @param files_num 文件数量
|
||||
* @return int =0成功,其他失败
|
||||
*/
|
||||
int luat_audio_play_multi_files(uint32_t multimedia_id, audio_play_info_t info[], uint32_t files_num);
|
||||
|
||||
/**
|
||||
* @brief 是否播放完全部数据
|
||||
*
|
||||
* @param multimedia_id multimedia_id 多媒体通道,目前只有0
|
||||
* @return uint8_t =1是,=0没有
|
||||
*/
|
||||
uint8_t luat_audio_play_is_finish(uint32_t multimedia_id);
|
||||
|
||||
/**
|
||||
* @brief 强制停止播放文件,但是不会停止已经输出到底层驱动的数据播放
|
||||
*
|
||||
* @param multimedia_id multimedia_id 多媒体通道,目前只有0
|
||||
* @return int =0成功,其他失败
|
||||
*/
|
||||
int luat_audio_play_stop(uint32_t multimedia_id);
|
||||
/**
|
||||
* @brief 暂停/恢复播放
|
||||
*
|
||||
* @param multimedia_id multimedia_id 多媒体通道,目前只有0
|
||||
* @param is_pause 0恢复,其他暂停
|
||||
* @return int =0成功,其他失败
|
||||
*/
|
||||
int luat_audio_play_pause_raw(uint32_t multimedia_id, uint8_t is_pause);
|
||||
|
||||
/**
|
||||
* @brief 获取上一次播放结果,在MULTIMEDIA_CB_AUDIO_DONE回调时调用最佳
|
||||
*
|
||||
* @param multimedia_id multimedia_id 多媒体通道,目前只有0
|
||||
* @return int =0完整的播放完成,<0被用户停止了,>0 TTS失败,或者第几个音频文件解码失败(用户在play_info未设置了解码失败后继续,文件位置+1)
|
||||
*/
|
||||
int luat_audio_play_get_last_error(uint32_t multimedia_id);
|
||||
|
||||
/**
|
||||
* @brief 在开头或者结尾插入多段空白数据,每段数据约100ms
|
||||
*
|
||||
* @param multimedia_id multimedia_id 多媒体通道,目前只有0
|
||||
* @param cnt 段数
|
||||
* @param add_font 是否加载到开头位置 1是,0否
|
||||
* @return int =0成功,其他失败
|
||||
*/
|
||||
int luat_audio_play_write_blank_raw(uint32_t multimedia_id, uint8_t cnt, uint8_t add_font);
|
||||
/**
|
||||
* @brief 立刻初始化播放未编码的原始音频数据流
|
||||
*
|
||||
* @param multimedia_id multimedia_id 多媒体通道,目前只有0
|
||||
* @param audio_format 音频数据格式,目前只支持PCM,即需要手动解码
|
||||
* @param num_channels 声道数,目前只能1或2
|
||||
* @param sample_rate 采样率,注意只有8K,16K,32K,48K,96K,22.05K,44.1K这些能被支持
|
||||
* @param bits_per_sample 量化bit,只能是16
|
||||
* @param is_signed 量化数据是否带符号,只能是1
|
||||
* @return int =0成功,其他失败
|
||||
*/
|
||||
int luat_audio_play_start_raw(uint32_t multimedia_id, uint8_t audio_format, uint8_t num_channels, uint32_t sample_rate, uint8_t bits_per_sample, uint8_t is_signed);
|
||||
/**
|
||||
* @brief 向底层驱动传入一段原始音频数据
|
||||
*
|
||||
* @param multimedia_id multimedia_id 多媒体通道,目前只有0
|
||||
* @param data 原始音频数据
|
||||
* @param len 原始音频数据长度
|
||||
* @return int =0成功,其他失败
|
||||
*/
|
||||
int luat_audio_play_write_raw(uint32_t multimedia_id, uint8_t *data, uint32_t len);
|
||||
/**
|
||||
* @brief 强制停止所有播放,同时底层驱动也会停止输出,不要用于播放文件的结束
|
||||
*
|
||||
* @param multimedia_id multimedia_id 多媒体通道,目前只有0
|
||||
* @return int =0成功,其他失败
|
||||
*/
|
||||
int luat_audio_play_stop_raw(uint32_t multimedia_id);
|
||||
/**
|
||||
* @brief 编码并播放一段文字
|
||||
*
|
||||
* @param multimedia_id multimedia_id 多媒体通道,目前只有0
|
||||
* @param text 文字数据
|
||||
* @param text_bytes 文字数据长度
|
||||
* @return int =0成功,其他失败
|
||||
*/
|
||||
int luat_audio_play_tts_text(uint32_t multimedia_id, void *text, uint32_t text_bytes);
|
||||
/**
|
||||
* @brief 在收到MULTIMEDIA_CB_TTS_INIT回调时,可以设置TTS参数,等同于ivTTS_SetParam
|
||||
*
|
||||
* @param multimedia_id multimedia_id 多媒体通道,目前只有0
|
||||
* @param param_id 见ivTTS_PARAM_XXX
|
||||
* @param param_value param_id对应的value
|
||||
* @return int =0成功,其他失败
|
||||
*/
|
||||
int luat_audio_play_tts_set_param(uint32_t multimedia_id, uint32_t param_id, uint32_t param_value);
|
||||
|
||||
/**
|
||||
* @brief 设置TTS的资源和对应SDKID,TTS资源有很多种。
|
||||
*
|
||||
* @param address 资源的flash或者ram地址
|
||||
* @param sdk_id 本质上就是传入AISOUND_SDK_USERID
|
||||
* @param tts_resource_read_fun 读取资源文件的函数,如果是NULL,则使用默认函数,即单纯的拷贝,如果用自己的函数,必须按照ivCBReadResExt定义
|
||||
*/
|
||||
void luat_audio_play_tts_set_resource(void *address, void *sdk_id, void *tts_resource_read_fun);
|
||||
/**@}*/
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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_FOTA_H
|
||||
#define LUAT_FOTA_H
|
||||
/**
|
||||
* @defgroup luatos_fota 远程升级接口
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief 升级包数据的上下文结构体
|
||||
*
|
||||
*/
|
||||
typedef void* luat_fota_img_proc_ctx_ptr;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 用于初始化fota,创建写入升级包数据的上下文结构体
|
||||
*
|
||||
* @param
|
||||
* @return luat_fota_img_proc_ctx_ptr
|
||||
*/
|
||||
luat_fota_img_proc_ctx_ptr luat_fota_init(void);
|
||||
|
||||
/**
|
||||
* @brief 用于向本地 Flash 中写入升级包数据
|
||||
*
|
||||
* @param context - 上下文结构体指针
|
||||
* @param data - 升级包数据地址
|
||||
* @param len - 升级包数据长度。 单位:字节
|
||||
* @return int =0成功,其他失败;
|
||||
*/
|
||||
int luat_fota_write(luat_fota_img_proc_ctx_ptr context, void * data, int len);
|
||||
|
||||
/**
|
||||
* @brief 用于结束升级包下载
|
||||
*
|
||||
* @param context - 上下文结构体指针
|
||||
* @return int =0成功,其他失败
|
||||
*/
|
||||
int luat_fota_done(luat_fota_img_proc_ctx_ptr context);
|
||||
/** @}*/
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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_I2S_EC618_H__
|
||||
#define __LUAT_I2S_EC618_H__
|
||||
#include "common_api.h"
|
||||
void luat_i2s_init(void);
|
||||
int luat_i2s_start(uint8_t bus_id, uint8_t is_play, uint32_t sample, uint8_t channel_num);
|
||||
void luat_i2s_base_setup(uint8_t bus_id, uint8_t mode, uint8_t frame_size);
|
||||
void luat_i2s_no_block_tx(uint8_t bus_id, uint8_t* address, uint32_t byte_len, CBFuncEx_t cb, void *param);
|
||||
void luat_i2s_no_block_rx(uint8_t bus_id, uint32_t byte_len, CBFuncEx_t cb, void *param);
|
||||
void luat_i2s_tx_stop(uint8_t bus_id);
|
||||
void luat_i2s_rx_stop(uint8_t bus_id);
|
||||
void luat_i2s_deinit(uint8_t bus_id);
|
||||
void luat_i2s_pause(uint8_t bus_id);
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "luat_audio_play_ec618.h"
|
||||
extern void audio_play_file_default_fun(void *param);
|
||||
extern void audio_play_tts_default_fun(void *param);
|
||||
extern void audio_play_tts_set_resource_ex(void *address, void *sdk_id, void *read_resource_fun);
|
||||
extern void audio_play_global_init_ex(audio_play_event_cb_fun_t event_cb, audio_play_data_cb_fun_t data_cb, audio_play_default_fun_t play_file_fun, audio_play_default_fun_t play_tts_fun, void *user_param);
|
||||
extern int audio_play_write_blank_raw_ex(uint32_t multimedia_id, uint8_t cnt, uint8_t add_font);
|
||||
void luat_audio_play_file_default_fun(void *param)
|
||||
{
|
||||
audio_play_file_default_fun(param);
|
||||
}
|
||||
void luat_audio_play_tts_default_fun(void *param)
|
||||
{
|
||||
audio_play_TTS_default_fun(param);
|
||||
}
|
||||
|
||||
void luat_audio_play_global_init(
|
||||
audio_play_event_cb_fun_t event_cb,
|
||||
audio_play_data_cb_fun_t data_cb,
|
||||
audio_play_default_fun_t play_file_fun,
|
||||
audio_play_default_fun_t play_tts_fun,
|
||||
void *user_param)
|
||||
{
|
||||
audio_play_global_init_ex(event_cb, data_cb, play_file_fun, play_tts_fun, user_param);
|
||||
}
|
||||
|
||||
int luat_audio_play_multi_files(uint32_t multimedia_id, audio_play_info_t info[], uint32_t files_num)
|
||||
{
|
||||
return audio_play_multi_files(multimedia_id, info, files_num);
|
||||
}
|
||||
|
||||
uint8_t luat_audio_play_is_finish(uint32_t multimedia_id)
|
||||
{
|
||||
return audio_play_is_finish(multimedia_id);
|
||||
}
|
||||
|
||||
int luat_audio_play_stop(uint32_t multimedia_id)
|
||||
{
|
||||
return audio_play_stop(multimedia_id);
|
||||
}
|
||||
|
||||
int luat_audio_play_pause_raw(uint32_t multimedia_id, uint8_t is_pause)
|
||||
{
|
||||
return audio_play_pause_raw(multimedia_id, is_pause);
|
||||
}
|
||||
|
||||
int luat_audio_play_get_last_error(uint32_t multimedia_id)
|
||||
{
|
||||
return audio_play_get_last_error(multimedia_id);
|
||||
}
|
||||
|
||||
int luat_audio_play_write_blank_raw(uint32_t multimedia_id, uint8_t cnt, uint8_t add_font)
|
||||
{
|
||||
return audio_play_write_blank_raw_ex(multimedia_id, cnt, add_font);
|
||||
}
|
||||
|
||||
int luat_audio_play_start_raw(uint32_t multimedia_id, uint8_t audio_format, uint8_t num_channels, uint32_t sample_rate, uint8_t bits_per_sample, uint8_t is_signed)
|
||||
{
|
||||
return audio_play_start_raw(multimedia_id, audio_format, num_channels, sample_rate, bits_per_sample, is_signed);
|
||||
}
|
||||
|
||||
int luat_audio_play_write_raw(uint32_t multimedia_id, uint8_t *data, uint32_t len)
|
||||
{
|
||||
return audio_play_write_raw(multimedia_id, data, len);
|
||||
}
|
||||
|
||||
int luat_audio_play_stop_raw(uint32_t multimedia_id)
|
||||
{
|
||||
return audio_play_stop_raw(multimedia_id);
|
||||
}
|
||||
|
||||
int luat_audio_play_tts_text(uint32_t multimedia_id, void *text, uint32_t text_bytes)
|
||||
{
|
||||
return audio_play_tts_text(multimedia_id, text, text_bytes);
|
||||
}
|
||||
|
||||
int luat_audio_play_tts_set_param(uint32_t multimedia_id, uint32_t param_id, uint32_t param_value)
|
||||
{
|
||||
return audio_play_tts_set_param(multimedia_id, param_id, param_value);
|
||||
}
|
||||
|
||||
|
||||
void luat_audio_play_tts_set_resource(void *address, void *sdk_id, void *tts_resource_read_fun)
|
||||
{
|
||||
audio_play_tts_set_resource_ex(address, sdk_id, tts_resource_read_fun);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <luat_fota.h>
|
||||
#include "fota_nvm.h"
|
||||
#include "luat_debug.h"
|
||||
|
||||
|
||||
|
||||
#define LUAT_OTA_HEAD 0x7e
|
||||
#define LUAT_OTA_APP_HEAD 0X7c
|
||||
#define LUAT_OTA_CORE_HEAD 0x7d
|
||||
#define LUAT_OTA_HEAD_LEN (5)
|
||||
#define LUAT_OTA_FILE_MAX (20)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LUAT_OTA_FILE_NULL,
|
||||
LUAT_OTA_FILE_RFBIN,
|
||||
LUAT_OTA_FILE_APP,
|
||||
LUAT_OTA_FILE_CORE,
|
||||
|
||||
} E_LUAT_OTA_FILE_TYPE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char head[LUAT_OTA_HEAD_LEN];
|
||||
unsigned int readLen;
|
||||
unsigned int fileNum;
|
||||
} T_LUAT_OTA_HEAD_CTX;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
E_LUAT_OTA_FILE_TYPE type;
|
||||
unsigned char head[LUAT_OTA_HEAD_LEN];
|
||||
unsigned int readLen;
|
||||
unsigned int size;
|
||||
} T_LUAT_OTA_FILE_CTX;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
T_LUAT_OTA_HEAD_CTX head;
|
||||
T_LUAT_OTA_FILE_CTX file[LUAT_OTA_FILE_MAX];
|
||||
unsigned int readLen;
|
||||
unsigned int fileCur;
|
||||
}openat_otaCtx;
|
||||
|
||||
static openat_otaCtx g_s_otaCtx = {0};
|
||||
|
||||
uint32_t fotaFirmwaresize = 0;
|
||||
|
||||
/**
|
||||
* @brief 用于初始化fota,创建写入升级包数据的上下文结构体
|
||||
*
|
||||
* @param
|
||||
* @return luat_fota_img_proc_ctx_ptr
|
||||
*/
|
||||
luat_fota_img_proc_ctx_ptr luat_fota_init(void){
|
||||
static int luat_fota_core_write_size;
|
||||
luat_fota_core_write_size = 0;
|
||||
fotaNvmInit();
|
||||
if(0 != fotaNvmClearDelta(0, fotaNvmGetDeltaSize(0)))
|
||||
{
|
||||
LUAT_DEBUG_PRINT("clear flash: failure!");
|
||||
return NULL;
|
||||
}
|
||||
LUAT_DEBUG_PRINT("clear flash: success");
|
||||
fotaFirmwaresize = 0;
|
||||
memset(&g_s_otaCtx, 0, sizeof(g_s_otaCtx));
|
||||
return &luat_fota_core_write_size;
|
||||
}
|
||||
|
||||
int luat_fota_write(luat_fota_img_proc_ctx_ptr context, void *data, int len)
|
||||
{
|
||||
int offset = *(int*)context;
|
||||
LUAT_DEBUG_PRINT("offset:%d len:%d", offset, len);
|
||||
uint8_t result = fotaNvmWriteDelta(offset, (uint8_t*)data, len);
|
||||
if(result != 0)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("write_flash error!");
|
||||
return -1;
|
||||
}
|
||||
*(int*)context += len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_fota_done(luat_fota_img_proc_ctx_ptr context)
|
||||
{
|
||||
FotaDefChkDeltaState_t chkDelta = {0};
|
||||
FotaDefChkBaseImage_t chkBase = {0};
|
||||
do
|
||||
{
|
||||
fotaNvmDoExtension(FOTA_DEF_CHK_DELTA_STATE, (void*)&chkDelta);
|
||||
if(!chkDelta.isValid)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("validate delta err! errno(%d)", chkDelta.state);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
LUAT_DEBUG_PRINT("validate delta ok!");
|
||||
fotaNvmDoExtension(FOTA_DEF_CHK_BASE_IMAGE, (void*)&chkBase);
|
||||
if(!chkBase.isMatched)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("however, base fw is unmatched!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}while(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "common_api.h"
|
||||
#include "luat_base.h"
|
||||
#include "luat_mem.h"
|
||||
#include "luat_pm.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "apmu_external.h"
|
||||
#include "slpman.h"
|
||||
#include "reset.h"
|
||||
#include "pwrkey.h"
|
||||
|
||||
extern void soc_usb_onoff(uint8_t onoff);
|
||||
extern void soc_set_usb_sleep(uint8_t onoff);
|
||||
static uint32_t reportMode[LUAT_PM_SLEEP_MODE_STANDBY + 1][10] = {0};
|
||||
|
||||
int luat_pm_set_sleep_mode(int mode, const char *vote_tag)
|
||||
{
|
||||
if (mode < LUAT_PM_SLEEP_MODE_NONE || mode > LUAT_PM_SLEEP_MODE_STANDBY || vote_tag == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool findFirst = true;
|
||||
for (int sleepMode = LUAT_PM_SLEEP_MODE_NONE; sleepMode < LUAT_PM_SLEEP_MODE_STANDBY + 1; sleepMode++)
|
||||
{
|
||||
for (int j = 0; j < 9; j++)
|
||||
{
|
||||
if (strcmp((const char *)reportMode[sleepMode][j], vote_tag) == 0)
|
||||
{
|
||||
findFirst = false;
|
||||
if (mode == sleepMode)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
luat_heap_free(reportMode[sleepMode][j]);
|
||||
reportMode[sleepMode][j] = (uint32_t)NULL;
|
||||
reportMode[sleepMode][9] = reportMode[sleepMode][9] - 1;
|
||||
if (reportMode[mode][9] < 9)
|
||||
{
|
||||
reportMode[mode][j] = (uint32_t)luat_heap_malloc(strlen(vote_tag) + 1);
|
||||
memset((uint32_t *)reportMode[mode][j], 0x00, strlen(vote_tag) + 1);
|
||||
memcpy((uint32_t *)reportMode[mode][j], vote_tag, strlen(vote_tag) + 1);
|
||||
reportMode[mode][9] = reportMode[mode][9] + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (findFirst)
|
||||
{
|
||||
int count = 0;
|
||||
for (int sleepMode = LUAT_PM_SLEEP_MODE_NONE; sleepMode < LUAT_PM_SLEEP_MODE_STANDBY + 1; sleepMode++)
|
||||
{
|
||||
count += reportMode[sleepMode][9];
|
||||
}
|
||||
|
||||
if (count >= 8)
|
||||
return -1;
|
||||
|
||||
if (reportMode[mode][9] < 9)
|
||||
{
|
||||
reportMode[mode][reportMode[mode][9]] = (uint32_t)luat_heap_malloc(strlen(vote_tag) + 1);
|
||||
memset((uint32_t *)reportMode[mode][reportMode[mode][9]], 0x00, strlen(vote_tag) + 1);
|
||||
memcpy((uint32_t *)reportMode[mode][reportMode[mode][9]], vote_tag, strlen(vote_tag) + 1);
|
||||
reportMode[mode][9] = reportMode[mode][9] + 1;
|
||||
}
|
||||
}
|
||||
for (int sleepMode = LUAT_PM_SLEEP_MODE_NONE; sleepMode < LUAT_PM_SLEEP_MODE_STANDBY + 1; sleepMode++)
|
||||
{
|
||||
for (int j = 0; j < 9; j++)
|
||||
{
|
||||
if (reportMode[sleepMode][j] != (uint32_t)NULL)
|
||||
{
|
||||
switch (sleepMode)
|
||||
{
|
||||
case LUAT_PM_SLEEP_MODE_NONE:
|
||||
apmuSetDeepestSleepMode(AP_STATE_ACTIVE);
|
||||
break;
|
||||
case LUAT_PM_SLEEP_MODE_IDLE:
|
||||
apmuSetDeepestSleepMode(AP_STATE_IDLE);
|
||||
break;
|
||||
case LUAT_PM_SLEEP_MODE_LIGHT:
|
||||
apmuSetDeepestSleepMode(AP_STATE_SLEEP1);
|
||||
break;
|
||||
case LUAT_PM_SLEEP_MODE_DEEP:
|
||||
apmuSetDeepestSleepMode(AP_STATE_SLEEP2);
|
||||
break;
|
||||
case LUAT_PM_SLEEP_MODE_STANDBY:
|
||||
apmuSetDeepestSleepMode(AP_STATE_HIBERNATE);
|
||||
break;
|
||||
default:
|
||||
apmuSetDeepestSleepMode(AP_STATE_IDLE);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int luat_pm_get_sleep_mode(const char *vote_tag)
|
||||
{
|
||||
for (int sleepMode = LUAT_PM_SLEEP_MODE_NONE; sleepMode < LUAT_PM_SLEEP_MODE_STANDBY + 1; sleepMode++)
|
||||
{
|
||||
for (int j = 0; j < 9; j++)
|
||||
{
|
||||
if (strcmp((const char *)reportMode[sleepMode][j], vote_tag) == 0)
|
||||
{
|
||||
return sleepMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static luat_pm_sleep_callback_t g_s_user_pre_callback = NULL;
|
||||
static luat_pm_sleep_callback_t g_s_user_post_callback = NULL;
|
||||
|
||||
static slpManBackupCb_t sleep_pre_callback(void *param, slpManLpState mode)
|
||||
{
|
||||
if (g_s_user_pre_callback != NULL)
|
||||
{
|
||||
g_s_user_pre_callback(mode);
|
||||
}
|
||||
}
|
||||
|
||||
static slpManBackupCb_t sleep_post_callback(void *param, slpManLpState mode)
|
||||
{
|
||||
if (g_s_user_post_callback != NULL)
|
||||
{
|
||||
g_s_user_post_callback(mode);
|
||||
}
|
||||
}
|
||||
|
||||
int luat_pm_sleep_register_pre_handler(luat_pm_sleep_callback_t callback_fun)
|
||||
{
|
||||
g_s_user_pre_callback = callback_fun;
|
||||
return slpManRegisterUsrdefinedBackupCb(sleep_pre_callback, NULL);
|
||||
}
|
||||
int luat_pm_sleep_deregister_pre_handler(void)
|
||||
{
|
||||
g_s_user_pre_callback = NULL;
|
||||
return slpManUnregisterUsrdefinedBackupCb(sleep_pre_callback);
|
||||
}
|
||||
int luat_pm_sleep_register_post_handler(luat_pm_sleep_callback_t callback_fun)
|
||||
{
|
||||
g_s_user_post_callback = callback_fun;
|
||||
return slpManRegisterUsrdefinedRestoreCb(sleep_post_callback, NULL);
|
||||
}
|
||||
int luat_pm_sleep_deregister_post_handler(void)
|
||||
{
|
||||
g_s_user_post_callback = NULL;
|
||||
return slpManUnregisterUsrdefinedRestoreCb(sleep_post_callback);
|
||||
}
|
||||
|
||||
int luat_pm_wakeup_pad_set_callback(luat_pm_wakeup_pad_isr_callback_t callback_fun)
|
||||
{
|
||||
soc_set_pad_wakeup_callback(callback_fun);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_wakeup_pad_set(uint8_t enable, LUAT_PM_WAKEUP_PAD_E source_id, luat_pm_wakeup_pad_cfg_t *cfg)
|
||||
{
|
||||
if ((enable != 1 && enable != 0) || ((source_id < LUAT_PM_WAKEUP_PAD_0) && (source_id > LUAT_PM_WAKEUP_PAD_5)) || cfg == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
APmuWakeupPadSettings_t padConfig = {0};
|
||||
padConfig.negEdgeEn = cfg->neg_edge_enable;
|
||||
padConfig.posEdgeEn = cfg->pos_edge_enable;
|
||||
padConfig.pullDownEn = cfg->pull_down_enable;
|
||||
padConfig.pullUpEn = cfg->pull_up_enable;
|
||||
apmuSetWakeupPadCfg(source_id, enable, &padConfig);
|
||||
if(enable)
|
||||
NVIC_EnableIRQ(source_id);
|
||||
else
|
||||
NVIC_DisableIRQ(source_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_wakeup_pad_get_value(LUAT_PM_WAKEUP_PAD_E source_id)
|
||||
{
|
||||
if ((source_id < LUAT_PM_WAKEUP_PAD_0) && (source_id > LUAT_PM_WAKEUP_PAD_5))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return slpManGetWakeupPinValue() & (1 << source_id);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
pwrKeyDly_t dlyCfg = {0};
|
||||
dlyCfg.longPressTimeout = cfg->long_press_timeout;
|
||||
dlyCfg.repeatTimeout = cfg->repeat_timeout;
|
||||
|
||||
pwrKeyInit(mode, pullUpEn, dlyCfg, (pwrKeyCallback_t) callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_get_poweron_reason(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_poweroff(void)
|
||||
{
|
||||
pwrKeyStartPowerOff();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_reboot(void)
|
||||
{
|
||||
ResetECSystemReset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_get_vbus_status(uint8_t *status)
|
||||
{
|
||||
*status = usb_portmon_vbuspad_level();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_event_register_handler(luat_pm_event_callback_t callback_fun)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int luat_pm_set_usb_power(uint8_t onoff)
|
||||
{
|
||||
soc_set_usb_sleep(!onoff);
|
||||
soc_usb_onoff(onoff);
|
||||
}
|
||||
|
||||
int luat_pm_deep_sleep_mode_timer_start(LUAT_PM_DEEPSLEEP_TIMERID_E timer_id, int timeout)
|
||||
{
|
||||
if (timer_id < LUAT_PM_DEEPSLEEP_TIMER_ID0 || timer_id > LUAT_PM_DEEPSLEEP_TIMER_ID6 || timeout <= 0)
|
||||
return -1;
|
||||
if ((timer_id == LUAT_PM_DEEPSLEEP_TIMER_ID0 || timer_id == LUAT_PM_DEEPSLEEP_TIMER_ID1) && (timeout > 9000000))
|
||||
timeout = 9000000;
|
||||
if ((timer_id >= LUAT_PM_DEEPSLEEP_TIMER_ID2 && timer_id <= LUAT_PM_DEEPSLEEP_TIMER_ID6) && (timeout > 2664000000))
|
||||
timeout = 2664000000;
|
||||
slpManDeepSlpTimerStart(timer_id, timeout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_deep_sleep_mode_timer_stop(LUAT_PM_DEEPSLEEP_TIMERID_E timer_id)
|
||||
{
|
||||
if (timer_id < LUAT_PM_DEEPSLEEP_TIMER_ID0 || timer_id > LUAT_PM_DEEPSLEEP_TIMER_ID6)
|
||||
return -1;
|
||||
slpManDeepSlpTimerDel(timer_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_deep_sleep_mode_timer_is_running(LUAT_PM_DEEPSLEEP_TIMERID_E timer_id)
|
||||
{
|
||||
if (timer_id < LUAT_PM_DEEPSLEEP_TIMER_ID0 || timer_id > LUAT_PM_DEEPSLEEP_TIMER_ID6)
|
||||
return -1;
|
||||
return slpManDeepSlpTimerIsRunning(timer_id) == true ? 1 : 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)
|
||||
{
|
||||
if (timer_id < LUAT_PM_DEEPSLEEP_TIMER_ID0 || timer_id > LUAT_PM_DEEPSLEEP_TIMER_ID6 || callback == NULL)
|
||||
return -1;
|
||||
slpManDeepSlpTimerRegisterExpCb(timer_id, callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_get_wakeup_reason()
|
||||
{
|
||||
return slpManGetWakeupSrc();
|
||||
}
|
||||
77
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/src/__wrap.c
Normal file
77
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/src/__wrap.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "common_api.h"
|
||||
#include "time.h"
|
||||
#include "osasys.h"
|
||||
|
||||
void RTC_GetDateTime(Date_UserDataStruct *pDate, Time_UserDataStruct *pTime)
|
||||
{
|
||||
Tamp2UTC(time(NULL), pDate, pTime, 0);
|
||||
}
|
||||
|
||||
static struct tm prvTM;
|
||||
extern const uint32_t DayTable[2][12];
|
||||
struct tm *__wrap_localtime (const time_t *_timer)
|
||||
{
|
||||
Time_UserDataStruct Time;
|
||||
Date_UserDataStruct Date;
|
||||
uint64_t Sec;
|
||||
utc_timer_value_t *timeUtc = OsaSystemTimeReadUtc();
|
||||
if (_timer)
|
||||
{
|
||||
Sec = *_timer;
|
||||
Tamp2UTC(Sec + timeUtc->timeZone * 900, &Date, &Time, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Tamp2UTC(timeUtc->UTCsecs + timeUtc->timeZone * 900, &Date, &Time, 0);
|
||||
}
|
||||
prvTM.tm_year = Date.Year - 1900;
|
||||
prvTM.tm_mon = Date.Mon - 1;
|
||||
prvTM.tm_mday = Date.Day;
|
||||
prvTM.tm_hour = Time.Hour;
|
||||
prvTM.tm_min = Time.Min;
|
||||
prvTM.tm_sec = Time.Sec;
|
||||
prvTM.tm_wday = Time.Week;
|
||||
prvTM.tm_yday = Date.Day - 1;
|
||||
prvTM.tm_yday += DayTable[IsLeapYear(Date.Year)][Date.Mon - 1];
|
||||
return &prvTM;
|
||||
}
|
||||
|
||||
struct tm *__wrap_gmtime (const time_t *_timer)
|
||||
{
|
||||
Time_UserDataStruct Time;
|
||||
Date_UserDataStruct Date;
|
||||
uint64_t Sec;
|
||||
if (_timer)
|
||||
{
|
||||
Sec = *_timer;
|
||||
Tamp2UTC(Sec, &Date, &Time, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
RTC_GetDateTime(&Date, &Time);
|
||||
}
|
||||
prvTM.tm_year = Date.Year - 1900;
|
||||
prvTM.tm_mon = Date.Mon - 1;
|
||||
prvTM.tm_mday = Date.Day;
|
||||
prvTM.tm_hour = Time.Hour;
|
||||
prvTM.tm_min = Time.Min;
|
||||
prvTM.tm_sec = Time.Sec;
|
||||
prvTM.tm_wday = Time.Week;
|
||||
prvTM.tm_yday = Date.Day - 1;
|
||||
prvTM.tm_yday += DayTable[IsLeapYear(Date.Year)][Date.Mon - 1];
|
||||
return &prvTM;
|
||||
}
|
||||
|
||||
clock_t __wrap_clock (void)
|
||||
{
|
||||
return GetSysTickMS()/1000;
|
||||
}
|
||||
|
||||
time_t __wrap_time (time_t *_Time)
|
||||
{
|
||||
utc_timer_value_t *timeUtc = OsaSystemTimeReadUtc();
|
||||
if (_Time != NULL) {
|
||||
*_Time = timeUtc->UTCsecs;
|
||||
}
|
||||
return timeUtc->UTCsecs;
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ADC操作
|
||||
*
|
||||
*/
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "luat_base.h"
|
||||
#ifdef __LUATOS__
|
||||
#include "luat_malloc.h"
|
||||
#include "luat_msgbus.h"
|
||||
#include "luat_timer.h"
|
||||
#endif
|
||||
#include "luat_adc.h"
|
||||
|
||||
#include "adc.h"
|
||||
#include "hal_adc.h"
|
||||
#include "ic.h"
|
||||
#include "hal_trim.h"
|
||||
|
||||
|
||||
/*
|
||||
注意, 按硬件应用手册的描述, ADC0 对应的是 AIO3, ADC1 对应的 AIO4
|
||||
|
||||
而 VBAT和TEMP 则使用LuatOS定义的, 与硬件无关.
|
||||
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LUAT_ADC_RANGE_E range;
|
||||
AdcAioResDiv_e resdiv;
|
||||
float ratio;
|
||||
}adc_range_resdiv_map_item_t;
|
||||
|
||||
extern void delay_us(uint32_t us);
|
||||
|
||||
static uint8_t adc_state[4] = {0}; // 注意实际映射, 当前不支持 AIO1/AIO2的映射
|
||||
static LUAT_ADC_RANGE_E adc_range[4] = {LUAT_ADC_AIO_RANGE_3_8, LUAT_ADC_AIO_RANGE_3_8, LUAT_ADC_VBAT_RANGE_5_3_RATIO, LUAT_ADC_VBAT_RANGE_5_3_RATIO};
|
||||
static volatile uint32_t aio3ChannelResult = 0;
|
||||
static volatile uint32_t aio4ChannelResult = 0;
|
||||
static volatile uint32_t vbatChannelResult = 0;
|
||||
static volatile uint32_t thermalChannelResult = 0;
|
||||
|
||||
static int adc_exist(int id) {
|
||||
if (id >= 0 && id < 5)
|
||||
return 1;
|
||||
if (id == LUAT_ADC_CH_CPU || id == LUAT_ADC_CH_VBAT)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int adc_range_to_resdiv(int id, int range, AdcAioResDiv_e *resdiv, float *ratio)
|
||||
{
|
||||
adc_range_resdiv_map_item_t map[]=
|
||||
{
|
||||
{LUAT_ADC_AIO_RANGE_1_2, ADC_AIO_RESDIV_RATIO_1, (float)1},
|
||||
{LUAT_ADC_AIO_RANGE_1_4, ADC_AIO_RESDIV_RATIO_14OVER16, (float)16/14},
|
||||
{LUAT_ADC_AIO_RANGE_1_6, ADC_AIO_RESDIV_RATIO_12OVER16, (float)16/12},
|
||||
{LUAT_ADC_AIO_RANGE_1_9, ADC_AIO_RESDIV_RATIO_10OVER16, (float)16/10},
|
||||
{LUAT_ADC_AIO_RANGE_2_4, ADC_AIO_RESDIV_RATIO_8OVER16, (float)16/8},
|
||||
{LUAT_ADC_AIO_RANGE_2_7, ADC_AIO_RESDIV_RATIO_7OVER16, (float)16/7},
|
||||
{LUAT_ADC_AIO_RANGE_3_2, ADC_AIO_RESDIV_RATIO_6OVER16, (float)16/6},
|
||||
{LUAT_ADC_AIO_RANGE_3_8, ADC_AIO_RESDIV_RATIO_5OVER16, (float)16/5},
|
||||
// 不再支持以下配置,无意义
|
||||
// {LUAT_ADC_AIO_RANGE_4_8, ADC_AIO_RESDIV_RATIO_4OVER16, (float)16/4},
|
||||
// {LUAT_ADC_AIO_RANGE_6_4, ADC_AIO_RESDIV_RATIO_3OVER16, (float)16/3},
|
||||
// {LUAT_ADC_AIO_RANGE_9_6, ADC_AIO_RESDIV_RATIO_2OVER16, (float)16/2},
|
||||
// {LUAT_ADC_AIO_RANGE_19_2, ADC_AIO_RESDIV_RATIO_1OVER16, (float)16/1},
|
||||
|
||||
{LUAT_ADC_VBAT_RANGE_2_0_RATIO, ADC_VBAT_RESDIV_RATIO_8OVER16, (float)16/8},
|
||||
{LUAT_ADC_VBAT_RANGE_2_2_RATIO, ADC_VBAT_RESDIV_RATIO_7OVER16, (float)16/7},
|
||||
{LUAT_ADC_VBAT_RANGE_2_6_RATIO, ADC_VBAT_RESDIV_RATIO_6OVER16, (float)16/6},
|
||||
{LUAT_ADC_VBAT_RANGE_3_2_RATIO, ADC_VBAT_RESDIV_RATIO_5OVER16, (float)16/5},
|
||||
{LUAT_ADC_VBAT_RANGE_4_0_RATIO, ADC_VBAT_RESDIV_RATIO_4OVER16, (float)16/4},
|
||||
{LUAT_ADC_VBAT_RANGE_5_3_RATIO, ADC_VBAT_RESDIV_RATIO_3OVER16, (float)16/3},
|
||||
{LUAT_ADC_VBAT_RANGE_8_0_RATIO, ADC_VBAT_RESDIV_RATIO_2OVER16, (float)16/2},
|
||||
{LUAT_ADC_VBAT_RANGE_16_0_RATIO, ADC_VBAT_RESDIV_RATIO_1OVER16, (float)16/1},
|
||||
};
|
||||
|
||||
size_t i = 0;
|
||||
|
||||
for (i = 0; i < sizeof(map)/sizeof(map[0]); i++)
|
||||
{
|
||||
if(map[i].range == range)
|
||||
{
|
||||
if (resdiv)
|
||||
{
|
||||
*resdiv = map[i].resdiv;
|
||||
}
|
||||
|
||||
if (ratio)
|
||||
{
|
||||
*ratio = map[i].ratio;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void adc0_cb(uint32_t result) {
|
||||
aio3ChannelResult = result;
|
||||
adc_state[0] = 1;
|
||||
}
|
||||
|
||||
static void adc1_cb(uint32_t result) {
|
||||
aio4ChannelResult = result;
|
||||
adc_state[1] = 1;
|
||||
}
|
||||
|
||||
static void adc_vbat_cb(uint32_t result) {
|
||||
vbatChannelResult = result;
|
||||
adc_state[2] = 1;
|
||||
}
|
||||
static void adc_temp_cb(uint32_t result) {
|
||||
thermalChannelResult = result;
|
||||
adc_state[3] = 1;
|
||||
}
|
||||
|
||||
static volatile uint8_t adc_init = 1;
|
||||
|
||||
int luat_adc_open(int id, void* ptr) {
|
||||
AdcConfig_t adcConfig;
|
||||
if (!adc_exist(id))
|
||||
return -1;
|
||||
ADC_getDefaultConfig(&adcConfig);
|
||||
if (adc_init){
|
||||
trimAdcSetGolbalVar();
|
||||
adc_init = 0;
|
||||
}
|
||||
|
||||
AdcAioResDiv_e resdiv;
|
||||
if (LUAT_ADC_CH_CPU == id)
|
||||
{
|
||||
adc_range_to_resdiv(id, adc_range[2], &resdiv, NULL);
|
||||
}
|
||||
else if (LUAT_ADC_CH_VBAT == id)
|
||||
{
|
||||
adc_range_to_resdiv(id, adc_range[3], &resdiv, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
adc_range_to_resdiv(id, adc_range[id], &resdiv, NULL);
|
||||
}
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case 0:
|
||||
adcConfig.channelConfig.aioResDiv = resdiv;
|
||||
ADC_channelInit(ADC_CHANNEL_AIO3, ADC_USER_APP, &adcConfig, adc0_cb);
|
||||
adc_state[0] = 0;
|
||||
break;
|
||||
case 1:
|
||||
adcConfig.channelConfig.aioResDiv = resdiv;
|
||||
ADC_channelInit(ADC_CHANNEL_AIO4, ADC_USER_APP, &adcConfig, adc1_cb);
|
||||
adc_state[1] = 0;
|
||||
break;
|
||||
case LUAT_ADC_CH_VBAT: // vbat
|
||||
adcConfig.channelConfig.vbatResDiv = resdiv;
|
||||
ADC_channelInit(ADC_CHANNEL_VBAT, ADC_USER_APP, &adcConfig, adc_vbat_cb);
|
||||
adc_state[2] = 0;
|
||||
break;
|
||||
case LUAT_ADC_CH_CPU: // temp
|
||||
adcConfig.channelConfig.vbatResDiv = resdiv;
|
||||
ADC_channelInit(ADC_CHANNEL_THERMAL, ADC_USER_APP, NULL, adc_temp_cb);
|
||||
adc_state[3] = 0;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_adc_read(int id, int* val, int* val2) {
|
||||
if (!adc_exist(id))
|
||||
return -1;
|
||||
int t = 1000;
|
||||
switch (id)
|
||||
{
|
||||
case 0:
|
||||
ADC_startConversion(ADC_CHANNEL_AIO3, ADC_USER_APP);
|
||||
while(adc_state[0] == 0 && t > 0) {
|
||||
delay_us(10);
|
||||
t --;
|
||||
}; // 1w个循环,通常需要4000个循环
|
||||
if (adc_state[0] == 0) return -1;
|
||||
break;
|
||||
case 1:
|
||||
ADC_startConversion(ADC_CHANNEL_AIO4, ADC_USER_APP);
|
||||
while(adc_state[1] == 0 && t > 0) {
|
||||
delay_us(10);
|
||||
t --;
|
||||
}; // 1w个循环,通常需要4000个循环
|
||||
if (adc_state[1] == 0) return -1;
|
||||
break;
|
||||
case LUAT_ADC_CH_VBAT:
|
||||
ADC_startConversion(ADC_CHANNEL_VBAT, ADC_USER_APP);
|
||||
while(adc_state[2] == 0 && t > 0) {
|
||||
delay_us(10);
|
||||
t --;
|
||||
}; // 1w个循环,通常需要4000个循环
|
||||
if (adc_state[2] == 0) return -1;
|
||||
break;
|
||||
case LUAT_ADC_CH_CPU:
|
||||
ADC_startConversion(ADC_CHANNEL_THERMAL, ADC_USER_APP);
|
||||
while(adc_state[3] == 0 && t > 0) {
|
||||
delay_us(10);
|
||||
t --;
|
||||
}; // 1w个循环,通常需要4000个循环
|
||||
if (adc_state[3] == 0) return -1;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
float ratio;
|
||||
if (LUAT_ADC_CH_CPU == id)
|
||||
{
|
||||
adc_range_to_resdiv(id, adc_range[2], NULL, &ratio);
|
||||
}
|
||||
else if (LUAT_ADC_CH_VBAT == id)
|
||||
{
|
||||
adc_range_to_resdiv(id, adc_range[3], NULL, &ratio);
|
||||
}
|
||||
else
|
||||
{
|
||||
adc_range_to_resdiv(id, adc_range[id], NULL, &ratio);
|
||||
}
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case 0:
|
||||
*val = aio3ChannelResult;
|
||||
#ifdef __LUATOS__
|
||||
*val2 = (int)HAL_ADC_CalibrateRawCode(aio3ChannelResult) * ratio /1000;
|
||||
#else
|
||||
*val2 = (int)HAL_ADC_CalibrateRawCode(aio3ChannelResult) * ratio ;
|
||||
#endif
|
||||
break;
|
||||
case 1:
|
||||
*val = aio4ChannelResult;
|
||||
#ifdef __LUATOS__
|
||||
*val2 = (int)HAL_ADC_CalibrateRawCode(aio4ChannelResult) * ratio /1000;
|
||||
#else
|
||||
*val2 = (int)HAL_ADC_CalibrateRawCode(aio4ChannelResult) * ratio ;
|
||||
#endif
|
||||
break;
|
||||
case LUAT_ADC_CH_VBAT:
|
||||
*val = vbatChannelResult;
|
||||
*val2 = (int)HAL_ADC_CalibrateRawCode(vbatChannelResult) * ratio / 1000;
|
||||
break;
|
||||
case LUAT_ADC_CH_CPU:
|
||||
*val = thermalChannelResult;
|
||||
*val2 = (int)HAL_ADC_ConvertThermalRawCodeToTemperature(thermalChannelResult);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_adc_close(int id) {
|
||||
switch (id)
|
||||
{
|
||||
case 0:
|
||||
ADC_channelDeInit(ADC_CHANNEL_AIO3, ADC_USER_APP);
|
||||
break;
|
||||
case 1:
|
||||
ADC_channelDeInit(ADC_CHANNEL_AIO4, ADC_USER_APP);
|
||||
break;
|
||||
case LUAT_ADC_CH_VBAT:
|
||||
ADC_channelDeInit(ADC_CHANNEL_VBAT, ADC_USER_APP);
|
||||
break;
|
||||
case LUAT_ADC_CH_CPU:
|
||||
ADC_channelDeInit(ADC_CHANNEL_THERMAL, ADC_USER_APP);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int luat_adc_global_config(int tp, int val) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int luat_adc_ctrl(int id, LUAT_ADC_CTRL_CMD_E cmd, luat_adc_ctrl_param_t param)
|
||||
{
|
||||
if (!adc_exist(id))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case LUAT_ADC_SET_GLOBAL_RANGE:
|
||||
|
||||
if (LUAT_ADC_CH_CPU == id)
|
||||
{
|
||||
adc_range[2] = param.range;
|
||||
}
|
||||
else if (LUAT_ADC_CH_VBAT == id)
|
||||
{
|
||||
adc_range[3] = param.range;
|
||||
}
|
||||
else
|
||||
{
|
||||
adc_range[id] = param.range;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "rng.h"
|
||||
#include "luat_crypto.h"
|
||||
#include "mbedtls/md5.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/base64.h"
|
||||
#include "mbedtls/des.h"
|
||||
#include "mbedtls/aes.h"
|
||||
#include "mbedtls/rsa.h"
|
||||
|
||||
|
||||
void luat_crypto_md5( unsigned char *input, int ilen, unsigned char output[16] )
|
||||
{
|
||||
mbedtls_md5(input, ilen, output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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 )
|
||||
{
|
||||
mbedtls_base64_encode(dst, dlen, olen, src, 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 )
|
||||
{
|
||||
mbedtls_base64_decode(dst, dlen, olen, src, 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])
|
||||
{
|
||||
mbedtls_sha1(input, ilen, output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
mbedtls_sha256(input, ilen, output, is_224);
|
||||
}
|
||||
|
||||
int luat_crypto_trng(char* buff, size_t len) {
|
||||
uint8_t tmp[24];
|
||||
for (size_t i = 0; i < len; i+=24)
|
||||
{
|
||||
rngGenRandom(tmp);
|
||||
memcpy(buff + i, tmp, len - i > 24 ? 24 : len - i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "luat_debug.h"
|
||||
#include "common_api.h"
|
||||
#include "plat_config.h"
|
||||
#include "reset.h"
|
||||
|
||||
extern void soc_assert(const char *fun_name, uint32_t line_no, const char *fmt, va_list ap);
|
||||
extern void soc_vsprintf(uint8_t no_print, const char *fmt, va_list ap);
|
||||
void luat_debug_set_fault_mode(LUAT_DEBUG_FAULT_MODE_E mode)
|
||||
{
|
||||
BSP_SetPlatConfigItemValue(PLAT_CONFIG_ITEM_FAULT_ACTION, (LUAT_DEBUG_FAULT_RESET == mode)?4:0);
|
||||
if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_FAULT_ACTION) == EXCEP_OPTION_SILENT_RESET)
|
||||
ResetLockupCfg(true, true);
|
||||
else
|
||||
|
||||
ResetLockupCfg(false, false);
|
||||
}
|
||||
|
||||
void luat_debug_assert(const char *fun_name, unsigned int line_no, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
soc_assert(fun_name, line_no, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void luat_debug_print(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
soc_vsprintf(0, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#include "common_api.h"
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_rtos.h"
|
||||
#include "luat_mem.h"
|
||||
#include "luat_debug.h"
|
||||
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "flash_rt.h"
|
||||
|
||||
int luat_flash_read(char* buff, size_t addr, size_t len) {
|
||||
int ret = 0;
|
||||
if (len == 0)
|
||||
return 0;
|
||||
ret = BSP_QSPI_Read_Safe((uint8_t *)buff, addr, len);
|
||||
return ret == 0 ? len : -1;
|
||||
}
|
||||
|
||||
int luat_flash_write(char* buff, size_t addr, size_t len) {
|
||||
int ret = 0;
|
||||
if (len == 0)
|
||||
return 0;
|
||||
// 注意, BSP_QSPI_Write_Safe 的buf不能是flash上的常量数据
|
||||
// 写入flash时XIP会关闭, 导致buf值肯定读不到
|
||||
// 下面的各种判断, 就是把常量数据拷贝到ram, 然后写入
|
||||
uint8_t tmp_small[128];
|
||||
uint8_t *tmp = NULL;
|
||||
uint32_t buff_addr = (uint32_t)buff;
|
||||
if (len <= 128) {
|
||||
// 对于较小的数据, 直接在栈内存里拷贝即可,不必判断
|
||||
memcpy(tmp_small, buff, len);
|
||||
ret = BSP_QSPI_Write_Safe((uint8_t *)tmp_small, addr, len);
|
||||
}
|
||||
else if (buff_addr >= 0x00400000 && buff_addr <= 0x00500000) {
|
||||
// 数据已经处于ram, 可以直接写入
|
||||
ret = BSP_QSPI_Write_Safe((uint8_t *)buff, addr, len);
|
||||
}
|
||||
else {
|
||||
// 超过128字节的常量数据, 应该是不存在的吧, 下面的逻辑主要是防御代码.
|
||||
tmp = malloc(len);
|
||||
if (tmp == NULL) {
|
||||
LUAT_DEBUG_PRINT("out of memory when malloc flash write buff");
|
||||
return -1;
|
||||
}
|
||||
memcpy(tmp, buff, len);
|
||||
ret = BSP_QSPI_Write_Safe((uint8_t *)tmp, addr, len);
|
||||
free(tmp);
|
||||
}
|
||||
return ret == 0 ? len : -1;
|
||||
}
|
||||
|
||||
int luat_flash_erase(size_t addr, size_t len) {
|
||||
int ret = 0;
|
||||
ret = BSP_QSPI_Erase_Safe(addr, len);
|
||||
return ret == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,497 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "luat_base.h"
|
||||
#include "luat_fs.h"
|
||||
#include "osasys.h"
|
||||
#include "lfs_port.h"
|
||||
#include "luat_rtos.h"
|
||||
#include "luat_debug.h"
|
||||
|
||||
#ifdef __LUATOS__
|
||||
#include "luat_malloc.h"
|
||||
#define LUAT_LOG_TAG "fs"
|
||||
#include "luat_log.h"
|
||||
#include "mem_map.h"
|
||||
#else
|
||||
#include "luat_mem.h"
|
||||
#endif
|
||||
|
||||
|
||||
static inline const char* check_path(const char* path) {
|
||||
// if (path == NULL || strlen(path) < 1)
|
||||
// return NULL;
|
||||
// const char* dst = path;
|
||||
// if (dst[0] == '/')
|
||||
// dst = path + 1;
|
||||
return path;
|
||||
}
|
||||
|
||||
static inline int is_file(const char* path) {
|
||||
if (path == NULL || strlen(path) < 1 || path[strlen(path) - 1] == '/')
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// #ifdef LUAT_USE_FS_VFS
|
||||
// #if 1
|
||||
|
||||
FILE* luat_vfs_ec618_fopen(__attribute__((unused)) void* userdata, const char *filename, const char *mode) {
|
||||
int flag = 0;
|
||||
const char* dst = check_path(filename);
|
||||
if (dst == NULL || is_file(dst) == 0)
|
||||
return NULL;
|
||||
//LLOGD("luat_fs_fopen %s %s", filename, mode);
|
||||
lfs_file_t *file = (lfs_file_t*)luat_heap_malloc(sizeof(lfs_file_t));
|
||||
if (NULL == file) {
|
||||
//LLOGE("out of memory when open file");
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
"r": 读模式(默认);
|
||||
"w": 写模式;
|
||||
"a": 追加模式;
|
||||
"r+": 更新模式,所有之前的数据都保留;
|
||||
"w+": 更新模式,所有之前的数据都删除;
|
||||
"a+": 追加更新模式,所有之前的数据都保留,只允许在文件尾部做写入。
|
||||
*/
|
||||
if (!strcmp("r+", mode) || !strcmp("r+b", mode) || !strcmp("rb+", mode)) {
|
||||
flag = LFS_O_RDWR | LFS_O_CREAT;
|
||||
}
|
||||
else if(!strcmp("w+", mode) || !strcmp("w+b", mode) || !strcmp("wb+", mode)) {
|
||||
flag = LFS_O_RDWR | LFS_O_CREAT | LFS_O_TRUNC;
|
||||
}
|
||||
else if(!strcmp("a+", mode) || !strcmp("a+b", mode) || !strcmp("ab+", mode)) {
|
||||
flag = LFS_O_RDWR | LFS_O_APPEND | LFS_O_CREAT;
|
||||
}
|
||||
else if(!strcmp("w", mode) || !strcmp("wb", mode)) {
|
||||
flag = LFS_O_RDWR | LFS_O_CREAT | LFS_O_TRUNC;
|
||||
}
|
||||
else if(!strcmp("r", mode) || !strcmp("rb", mode)) {
|
||||
flag = LFS_O_RDONLY;
|
||||
}
|
||||
else if(!strcmp("a", mode) || !strcmp("ab", mode)) {
|
||||
flag = LFS_O_WRONLY | LFS_O_APPEND | LFS_O_CREAT;
|
||||
}
|
||||
else {
|
||||
//LLOGW("bad file open mode %s, fallback to 'r'", mode);
|
||||
flag = LFS_O_RDONLY;
|
||||
}
|
||||
int ret = LFS_fileOpen(file, dst, flag);
|
||||
//LLOGD("luat_fs_fopen %s %s ret %d", filename, mode, ret);
|
||||
if (ret == LFS_ERR_OK) {
|
||||
return (FILE*)file;
|
||||
}
|
||||
luat_heap_free(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int luat_vfs_ec618_getc(__attribute__((unused))void* userdata, FILE* stream) {
|
||||
char buff[1];
|
||||
buff[0] = 0;
|
||||
int ret = LFS_fileRead((lfs_file_t*)stream, buff, 1);
|
||||
if (ret == 1)
|
||||
return buff[0];
|
||||
return -1;
|
||||
}
|
||||
|
||||
int luat_vfs_ec618_fseek(__attribute__((unused))void* userdata, FILE* stream, long int offset, int origin) {
|
||||
//DBG("luat_fs_fseek fd=%p offset=%ld ori=%ld", stream, offset, origin);
|
||||
return LFS_fileSeek((lfs_file_t*)stream, offset, origin);
|
||||
}
|
||||
|
||||
int luat_vfs_ec618_ftell(__attribute__((unused))void* userdata, FILE* stream) {
|
||||
//DBG("luat_fs_ftell fd=%ld", stream);
|
||||
return LFS_fileTell((lfs_file_t *)stream);
|
||||
}
|
||||
|
||||
int luat_vfs_ec618_fclose(__attribute__((unused))void* userdata, FILE* stream) {
|
||||
if (stream == NULL)
|
||||
return 0;
|
||||
LFS_fileClose((lfs_file_t *)stream);
|
||||
free(stream);
|
||||
return 0;
|
||||
}
|
||||
int luat_vfs_ec618_feof(__attribute__((unused))void* userdata, FILE* stream) {
|
||||
return LFS_fileTell((lfs_file_t *)stream) == LFS_fileSize((lfs_file_t *)stream) ? 1 : 0;
|
||||
}
|
||||
int luat_vfs_ec618_ferror(__attribute__((unused))void* userdata, __attribute__((unused))FILE *stream) {
|
||||
return 0;
|
||||
}
|
||||
size_t luat_vfs_ec618_fread(__attribute__((unused))void* userdata, void *ptr, size_t size, size_t nmemb, FILE *stream) {
|
||||
lfs_ssize_t ret = LFS_fileRead((lfs_file_t*)stream, ptr, size * nmemb);
|
||||
//DBG("luat_fs_fread fd=%p size=%ld nmemb=%ld ret=%ld", stream, size, nmemb, t);
|
||||
//DBG("luat_fs_fread data[0-7] %p %X %X %X %X %X %X %X %X", data, *(data), *(data+1), *(data+2), *(data+3), *(data+4), *(data+5), *(data+6), *(data+7));
|
||||
if (ret < 0)
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
size_t luat_vfs_ec618_fwrite(__attribute__((unused))void* userdata, const void *ptr, size_t size, size_t nmemb, FILE *stream) {
|
||||
//DBG("luat_fs_fwrite fd=%p size=%ld nmemb=%ld", stream, size, nmemb);
|
||||
lfs_ssize_t ret = LFS_fileWrite((lfs_file_t*)stream, ptr, size * nmemb);
|
||||
if (ret < 0)
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
int luat_vfs_ec618_remove(__attribute__((unused))void* userdata, const char *filename) {
|
||||
const char* dst = check_path(filename);
|
||||
if (dst == NULL)
|
||||
return 0;
|
||||
return LFS_remove(dst);
|
||||
}
|
||||
int luat_vfs_ec618_rename(__attribute__((unused))void* userdata, const char *old_filename, const char *new_filename) {
|
||||
const char* src = check_path(old_filename);
|
||||
if (src == NULL)
|
||||
return 0;
|
||||
const char* dst = check_path(new_filename);
|
||||
if (dst == NULL)
|
||||
return 0;
|
||||
return LFS_rename(src, dst);
|
||||
}
|
||||
int luat_vfs_ec618_fexist(__attribute__((unused))void* userdata, const char *filename) {
|
||||
const char* dst = check_path(filename);
|
||||
if (dst == NULL)
|
||||
return 0;
|
||||
lfs_file_t file = {0};
|
||||
int ret = LFS_fileOpen(&file, dst, LFS_O_RDONLY);
|
||||
if (ret == LFS_ERR_OK) {
|
||||
LFS_fileClose(&file);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t luat_vfs_ec618_fsize(__attribute__((unused))void* userdata, const char *filename) {
|
||||
const char* dst = check_path(filename);
|
||||
if (dst == NULL)
|
||||
return 0;
|
||||
lfs_file_t file = {0};
|
||||
int ret = LFS_fileOpen(&file, dst, LFS_O_RDONLY);
|
||||
if (ret == LFS_ERR_OK) {
|
||||
size_t sz = LFS_fileSize(&file);
|
||||
LFS_fileClose(&file);
|
||||
return sz;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_vfs_ec618_truncate(__attribute__((unused))void* userdata, const char* filename, size_t len) {
|
||||
const char* dst = check_path(filename);
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
lfs_file_t file = {0};
|
||||
int ret = LFS_fileOpen(&file, dst, LFS_O_RDWR);
|
||||
if (ret != LFS_ERR_OK) {
|
||||
return -2;
|
||||
}
|
||||
ret = LFS_fileTruncate(&file, len);
|
||||
LFS_fileClose(&file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int luat_vfs_ec618_mkfs(__attribute__((unused))void* userdata, __attribute__((unused))luat_fs_conf_t *conf) {
|
||||
//DBG("not support yet : mkfs");
|
||||
return -1;
|
||||
}
|
||||
int luat_vfs_ec618_mount(__attribute__((unused))void** userdata, __attribute__((unused))luat_fs_conf_t *conf) {
|
||||
//DBG("not support yet : mount");
|
||||
return 0;
|
||||
}
|
||||
int luat_vfs_ec618_umount(__attribute__((unused))void* userdata, __attribute__((unused))luat_fs_conf_t *conf) {
|
||||
//DBG("not support yet : umount");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LFS_mkdir(const char* dir);
|
||||
int luat_vfs_ec618_mkdir(__attribute__((unused))void* userdata, __attribute__((unused))char const* _DirName) {
|
||||
const char* dir = check_path(_DirName);
|
||||
char buff[64] = {0};
|
||||
//LUAT_DEBUG_PRINT("mkdir %s %s", dir, _DirName);
|
||||
if (dir == NULL)
|
||||
return -1;
|
||||
size_t len = strlen(dir);
|
||||
if (strlen(dir) > 63 || strlen(dir) < 2) {
|
||||
return -2;
|
||||
}
|
||||
memcpy(buff, dir, len);
|
||||
if (buff[len - 1] == '/')
|
||||
buff[len - 1] = 0x00;
|
||||
int ret = LFS_mkdir(buff);
|
||||
//LUAT_DEBUG_PRINT("mkdir %s %s %d", dir, _DirName, ret);
|
||||
return ret;
|
||||
}
|
||||
int luat_vfs_ec618_rmdir(__attribute__((unused))void* userdata, __attribute__((unused))char const* _DirName) {
|
||||
const char* dir = check_path(_DirName);
|
||||
if (dir == NULL)
|
||||
return -1;
|
||||
return LFS_remove(dir);
|
||||
}
|
||||
|
||||
int luat_vfs_ec618_lsdir(__attribute__((unused))void* userdata, char const* dir_name, luat_fs_dirent_t* ents, size_t offset, size_t len) {
|
||||
int ret = 0;
|
||||
size_t num = 0;
|
||||
lfs_dir_t *dir = NULL;
|
||||
struct lfs_info info = {0};
|
||||
const char* dirpath = check_path(dir_name);
|
||||
// if (fs->filecount > offset) {
|
||||
// if (offset + len > fs->filecount)
|
||||
// len = fs->filecount - offset;
|
||||
dir = luat_heap_malloc(sizeof(lfs_dir_t));
|
||||
if (dir == NULL) {
|
||||
// LLOGE("out of memory when lsdir");
|
||||
return 0;
|
||||
}
|
||||
ret = LFS_dirOpen(dir, dirpath); // 固定值, 因为不支持文件夹
|
||||
if (ret < 0) {
|
||||
luat_heap_free(dir);
|
||||
// LLOGE("no such dir %s _DirName");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO 使用seek/tell组合更快更省
|
||||
for (size_t i = 0; i < offset; i++)
|
||||
{
|
||||
ret = LFS_dirRead(dir, &info);
|
||||
if (ret <= 0) {
|
||||
LFS_dirClose(dir);
|
||||
luat_heap_free(dir);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
while (num < len)
|
||||
{
|
||||
ret = LFS_dirRead(dir, &info);
|
||||
if (ret < 0) {
|
||||
LFS_dirClose(dir);
|
||||
luat_heap_free(dir);
|
||||
return 0;
|
||||
}
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
if (info.type == 2 && (memcmp(info.name, ".", 2) !=0 ||memcmp(info.name, "..", 3)!=0))
|
||||
continue;
|
||||
ents[num].d_type = info.type - 1; // lfs file =1, dir=2
|
||||
strcpy(ents[num].d_name, info.name);
|
||||
num++;
|
||||
}
|
||||
LFS_dirClose(dir);
|
||||
luat_heap_free(dir);
|
||||
return num;
|
||||
// }
|
||||
// return 0;
|
||||
}
|
||||
|
||||
int luat_vfs_ec618_info(__attribute__((unused))void* userdata, __attribute__((unused))const char* path, luat_fs_info_t *conf) {
|
||||
lfs_status_t status = {0};
|
||||
int ret = LFS_statfs(&status);
|
||||
if (ret == LFS_ERR_OK) {
|
||||
conf->total_block = status.total_block;
|
||||
conf->block_used = status.block_used;
|
||||
conf->block_size = status.block_size;
|
||||
conf->type = 1; // 片上FLASH
|
||||
memcpy(conf->filesystem, "lfs", 3);
|
||||
conf->filesystem[4] = 0;
|
||||
return 0;
|
||||
}
|
||||
// else {
|
||||
// DBG("LFS_Statfs return %d", ret);
|
||||
// }
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef LUAT_USE_FS_VFS
|
||||
|
||||
#define T(name) .name = luat_vfs_ec618_##name
|
||||
const struct luat_vfs_filesystem vfs_fs_ec618 = {
|
||||
.name = "ec618",
|
||||
.opts = {
|
||||
T(mkfs),
|
||||
T(mount),
|
||||
T(umount),
|
||||
T(mkdir),
|
||||
T(rmdir),
|
||||
T(remove),
|
||||
T(rename),
|
||||
T(fsize),
|
||||
T(fexist),
|
||||
T(info),
|
||||
T(lsdir)
|
||||
},
|
||||
.fopts = {
|
||||
T(fopen),
|
||||
T(getc),
|
||||
T(fseek),
|
||||
T(ftell),
|
||||
T(fclose),
|
||||
T(feof),
|
||||
T(ferror),
|
||||
T(fread),
|
||||
T(fwrite)
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef __LUATOS__
|
||||
extern const struct luat_vfs_filesystem vfs_fs_lfs2;
|
||||
extern const struct luat_vfs_filesystem vfs_fs_luadb;
|
||||
void luat_lv_fs_init(void);
|
||||
void lv_split_jpeg_init(void);
|
||||
void lv_bmp_init(void);
|
||||
void lv_png_init(void);
|
||||
#endif
|
||||
|
||||
int luat_fs_init(void) {
|
||||
|
||||
luat_vfs_reg(&vfs_fs_ec618);
|
||||
#ifdef __LUATOS__
|
||||
luat_vfs_reg(&vfs_fs_lfs2);
|
||||
luat_vfs_reg(&vfs_fs_luadb);
|
||||
#endif
|
||||
|
||||
luat_fs_conf_t conf = {
|
||||
.busname = "",
|
||||
.type = "ec618",
|
||||
.filesystem = "ec618",
|
||||
.mount_point = ""
|
||||
};
|
||||
luat_fs_mount(&conf);
|
||||
|
||||
#ifdef __LUATOS__
|
||||
// 以下为临时配置, 从APP区的末端,切出128k作为临时脚本区,80K作为OTA区
|
||||
#define LUADB_ADDR ((uint32_t)LUA_SCRIPT_ADDR | AP_FLASH_XIP_ADDR)
|
||||
//DBG("luadb tmp addr %p", LUADB_ADDR);
|
||||
luat_fs_conf_t conf2 = {
|
||||
.busname = (char*)(const char*)LUADB_ADDR,
|
||||
.type = "luadb",
|
||||
.filesystem = "luadb",
|
||||
.mount_point = "/luadb/",
|
||||
};
|
||||
luat_fs_mount(&conf2);
|
||||
#ifdef LUAT_USE_LVGL
|
||||
luat_lv_fs_init();
|
||||
// lv_bmp_init();
|
||||
// lv_png_init();
|
||||
lv_split_jpeg_init();
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
FILE* luat_fs_fopen(const char *filename, const char *mode) {
|
||||
return luat_vfs_ec618_fopen(NULL, filename, mode);
|
||||
}
|
||||
|
||||
int luat_fs_getc(FILE* stream) {
|
||||
return luat_vfs_ec618_getc(NULL, stream);
|
||||
}
|
||||
|
||||
int luat_fs_fseek(FILE* stream, long int offset, int origin) {
|
||||
return luat_vfs_ec618_fseek(NULL, stream, offset, origin);
|
||||
}
|
||||
|
||||
int luat_fs_ftell(FILE* stream) {
|
||||
return luat_vfs_ec618_ftell(NULL, stream);
|
||||
}
|
||||
|
||||
int luat_fs_fclose(FILE* stream) {
|
||||
return luat_vfs_ec618_fclose(NULL, stream);
|
||||
}
|
||||
|
||||
int luat_fs_feof(FILE* stream) {
|
||||
return luat_vfs_ec618_feof(NULL, stream);
|
||||
}
|
||||
|
||||
int luat_fs_ferror(FILE *stream) {
|
||||
return luat_vfs_ec618_ferror(NULL, stream);
|
||||
}
|
||||
|
||||
|
||||
size_t luat_fs_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) {
|
||||
return luat_vfs_ec618_fread(NULL, ptr, size, nmemb, stream);
|
||||
}
|
||||
|
||||
size_t luat_fs_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) {
|
||||
return luat_vfs_ec618_fwrite(NULL, ptr, size, nmemb, stream);
|
||||
}
|
||||
|
||||
int luat_fs_remove(const char *filename) {
|
||||
return luat_vfs_ec618_remove(NULL, filename);
|
||||
}
|
||||
|
||||
int luat_fs_rename(const char *old_filename, const char *new_filename) {
|
||||
return luat_vfs_ec618_rename(NULL, old_filename, new_filename);
|
||||
}
|
||||
|
||||
|
||||
size_t luat_fs_fsize(const char *filename) {
|
||||
return luat_vfs_ec618_fsize(NULL, filename);
|
||||
}
|
||||
|
||||
int luat_fs_fexist(const char *filename) {
|
||||
return luat_vfs_ec618_fexist(NULL, filename);
|
||||
}
|
||||
|
||||
// int luat_fs_ftruncate(FILE* fp, size_t len) {
|
||||
|
||||
// }
|
||||
|
||||
|
||||
int luat_fs_truncate(const char* filename, size_t len) {
|
||||
return luat_vfs_ec618_truncate(NULL, filename, len);
|
||||
}
|
||||
|
||||
// int luat_fs_readline(char * buf, int bufsize, FILE * stream);
|
||||
|
||||
// 文件夹相关的API
|
||||
|
||||
int luat_fs_mkdir(char const* dir) {
|
||||
return luat_vfs_ec618_mkdir(NULL, dir);
|
||||
}
|
||||
|
||||
int luat_fs_rmdir(char const* dir) {
|
||||
return luat_vfs_ec618_rmdir(NULL, dir);
|
||||
}
|
||||
|
||||
int luat_fs_lsdir(char const* dir, luat_fs_dirent_t* ents, size_t offset, size_t len) {
|
||||
return luat_vfs_ec618_lsdir(NULL, dir, ents, offset, len);
|
||||
}
|
||||
|
||||
int luat_fs_init(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_fs_info(const char* path, luat_fs_info_t *info){
|
||||
return luat_vfs_ec618_info(NULL, path, info);
|
||||
}
|
||||
|
||||
extern int lfs_ready;
|
||||
int luat_fs_ready(void) {
|
||||
return lfs_ready;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,437 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "common_api.h"
|
||||
#include "luat_gpio.h"
|
||||
#include "driver_gpio.h"
|
||||
#include "slpman.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "pwrkey.h"
|
||||
typedef void(* pwrKeyIsrCb)(void);
|
||||
extern pwrKeyIsrCb pwrKeyIsrCallback;
|
||||
__attribute__((weak)) int luat_gpio_irq_default(int pin, void* args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int luat_gpio_irq_callback(void *ptr, void *pParam)
|
||||
{
|
||||
int pin = (int)ptr;
|
||||
luat_gpio_irq_default(pin, (void*)luat_gpio_get(pin));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void luat_gpio_pwrkey_irq_callback(void)
|
||||
{
|
||||
luat_gpio_irq_default(HAL_WAKEUP_PWRKEY, (void*)pwrKeyGetPinLevel());
|
||||
return ;
|
||||
}
|
||||
|
||||
void luat_gpio_set_default_cfg(luat_gpio_cfg_t* gpio)
|
||||
{
|
||||
memset(gpio, 0, sizeof(luat_gpio_cfg_t));
|
||||
}
|
||||
|
||||
int luat_gpio_open(luat_gpio_cfg_t* gpio)
|
||||
{
|
||||
#ifdef __LUATOS__
|
||||
if (((uint32_t)(gpio->pin)) >= HAL_GPIO_QTY) return -1;
|
||||
#else
|
||||
if (((uint32_t)(gpio->pin)) >= HAL_WAKEUP_PWRKEY) return -1;
|
||||
#endif
|
||||
GPIO_GlobalInit(NULL);
|
||||
#ifdef __LUATOS__
|
||||
if (HAL_WAKEUP_PWRKEY == gpio->pin)
|
||||
{
|
||||
if (gpio->mode != LUAT_GPIO_IRQ)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
pwrKeyIsrCallback = luat_gpio_pwrkey_irq_callback;
|
||||
pwrKeyHwInit((LUAT_GPIO_PULLUP == gpio->pull)?1:0);
|
||||
NVIC_EnableIRQ(PwrkeyWakeup_IRQn);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if (gpio->pin >= HAL_GPIO_MAX)
|
||||
{
|
||||
APmuWakeupPadSettings_t padConfig = {0};
|
||||
if (LUAT_GPIO_OUTPUT == gpio->mode) return -1;
|
||||
uint8_t pad_id = gpio->pin - HAL_WAKEUP_0;
|
||||
switch (gpio->pull)
|
||||
{
|
||||
case LUAT_GPIO_PULLUP:
|
||||
padConfig.pullUpEn = 1;
|
||||
break;
|
||||
case LUAT_GPIO_PULLDOWN:
|
||||
padConfig.pullDownEn = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (LUAT_GPIO_IRQ == gpio->mode)
|
||||
{
|
||||
if (gpio->irq_cb) {
|
||||
GPIO_ExtiSetCB(gpio->pin, gpio->irq_cb, gpio->irq_args);
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIO_ExtiSetCB(gpio->pin, luat_gpio_irq_callback, gpio->irq_args);
|
||||
}
|
||||
switch (gpio->irq_type)
|
||||
{
|
||||
case LUAT_GPIO_RISING_IRQ:
|
||||
padConfig.posEdgeEn = 1;
|
||||
break;
|
||||
case LUAT_GPIO_FALLING_IRQ:
|
||||
padConfig.negEdgeEn = 1;
|
||||
break;
|
||||
case LUAT_GPIO_BOTH_IRQ:
|
||||
padConfig.posEdgeEn = 1;
|
||||
padConfig.negEdgeEn = 1;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
apmuSetWakeupPadCfg(pad_id, true, &padConfig);
|
||||
NVIC_EnableIRQ(pad_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
NVIC_DisableIRQ(pad_id);
|
||||
NVIC_ClearPendingIRQ(pad_id);
|
||||
apmuSetWakeupPadCfg(pad_id, false, &padConfig);
|
||||
GPIO_ExtiSetCB(gpio->pin, NULL, gpio->irq_args);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t is_pull;
|
||||
uint8_t is_pullup;
|
||||
uint8_t is_input = (LUAT_GPIO_OUTPUT == gpio->mode)?0:1;
|
||||
switch (gpio->pull)
|
||||
{
|
||||
case LUAT_GPIO_PULLUP:
|
||||
is_pull = 1;
|
||||
is_pullup = 1;
|
||||
break;
|
||||
case LUAT_GPIO_PULLDOWN:
|
||||
is_pull = 1;
|
||||
is_pullup = 0;
|
||||
break;
|
||||
default:
|
||||
is_pull = 0;
|
||||
is_pullup = 0;
|
||||
break;
|
||||
}
|
||||
GPIO_Config(gpio->pin, is_input, gpio->output_level);
|
||||
GPIO_PullConfig(GPIO_ToPadEC618(gpio->pin, gpio->alt_fun), is_pull, is_pullup);
|
||||
|
||||
if (LUAT_GPIO_IRQ == gpio->mode)
|
||||
{
|
||||
if (gpio->irq_cb) {
|
||||
GPIO_ExtiSetCB(gpio->pin, gpio->irq_cb, gpio->irq_args);
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIO_ExtiSetCB(gpio->pin, luat_gpio_irq_callback, gpio->irq_args);
|
||||
}
|
||||
switch (gpio->irq_type)
|
||||
{
|
||||
case LUAT_GPIO_RISING_IRQ:
|
||||
GPIO_ExtiConfig(gpio->pin, 0,1,0);
|
||||
break;
|
||||
case LUAT_GPIO_FALLING_IRQ:
|
||||
GPIO_ExtiConfig(gpio->pin, 0,0,1);
|
||||
break;
|
||||
case LUAT_GPIO_BOTH_IRQ:
|
||||
GPIO_ExtiConfig(gpio->pin, 0,1,1);
|
||||
break;
|
||||
case LUAT_GPIO_HIGH_IRQ:
|
||||
GPIO_ExtiConfig(gpio->pin, 1,1,0);
|
||||
break;
|
||||
case LUAT_GPIO_LOW_IRQ:
|
||||
GPIO_ExtiConfig(gpio->pin, 1,0,1);
|
||||
break;
|
||||
default:
|
||||
GPIO_ExtiConfig(gpio->pin, 0,0,0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIO_ExtiConfig(gpio->pin, 0,0,0);
|
||||
GPIO_ExtiSetCB(gpio->pin, NULL, NULL);
|
||||
}
|
||||
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(gpio->pin, gpio->alt_fun), gpio->alt_fun, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_gpio_setup(luat_gpio_t *gpio){
|
||||
if (((uint32_t)(gpio->pin)) >= HAL_GPIO_QTY) return -1;
|
||||
GPIO_GlobalInit(NULL);
|
||||
#ifdef __LUATOS__
|
||||
if (HAL_WAKEUP_PWRKEY == gpio->pin)
|
||||
{
|
||||
if (gpio->mode != LUAT_GPIO_IRQ)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
pwrKeyIsrCallback = luat_gpio_pwrkey_irq_callback;
|
||||
pwrKeyHwInit((LUAT_GPIO_PULLUP == gpio->pull)?1:0);
|
||||
NVIC_EnableIRQ(PwrkeyWakeup_IRQn);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if (gpio->pin >= HAL_GPIO_MAX)
|
||||
{
|
||||
APmuWakeupPadSettings_t padConfig = {0};
|
||||
if (LUAT_GPIO_OUTPUT == gpio->mode) return -1;
|
||||
uint8_t pad_id = gpio->pin - HAL_WAKEUP_0;
|
||||
switch (gpio->pull)
|
||||
{
|
||||
case LUAT_GPIO_PULLUP:
|
||||
padConfig.pullUpEn = 1;
|
||||
break;
|
||||
case LUAT_GPIO_PULLDOWN:
|
||||
padConfig.pullDownEn = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (LUAT_GPIO_IRQ == gpio->mode)
|
||||
{
|
||||
if (gpio->irq_cb) {
|
||||
GPIO_ExtiSetCB(gpio->pin, gpio->irq_cb, gpio->irq_args);
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIO_ExtiSetCB(gpio->pin, luat_gpio_irq_callback, gpio->irq_args);
|
||||
}
|
||||
switch (gpio->irq)
|
||||
{
|
||||
case LUAT_GPIO_RISING_IRQ:
|
||||
padConfig.posEdgeEn = 1;
|
||||
break;
|
||||
case LUAT_GPIO_FALLING_IRQ:
|
||||
padConfig.negEdgeEn = 1;
|
||||
break;
|
||||
case LUAT_GPIO_BOTH_IRQ:
|
||||
padConfig.posEdgeEn = 1;
|
||||
padConfig.negEdgeEn = 1;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
apmuSetWakeupPadCfg(pad_id, true, &padConfig);
|
||||
NVIC_EnableIRQ(pad_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
NVIC_DisableIRQ(pad_id);
|
||||
NVIC_ClearPendingIRQ(pad_id);
|
||||
apmuSetWakeupPadCfg(pad_id, false, &padConfig);
|
||||
GPIO_ExtiSetCB(gpio->pin, NULL, gpio->irq_args);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
uint8_t is_pull;
|
||||
uint8_t is_pullup;
|
||||
uint8_t is_input = (LUAT_GPIO_OUTPUT == gpio->mode)?0:1;
|
||||
switch (gpio->pull)
|
||||
{
|
||||
case LUAT_GPIO_PULLUP:
|
||||
is_pull = 1;
|
||||
is_pullup = 1;
|
||||
break;
|
||||
case LUAT_GPIO_PULLDOWN:
|
||||
is_pull = 1;
|
||||
is_pullup = 0;
|
||||
break;
|
||||
default:
|
||||
is_pull = 0;
|
||||
is_pullup = 0;
|
||||
break;
|
||||
}
|
||||
GPIO_Config(gpio->pin, is_input, is_pullup);
|
||||
GPIO_PullConfig(GPIO_ToPadEC618(gpio->pin, 0), is_pull, is_pullup);
|
||||
if (LUAT_GPIO_IRQ == gpio->mode)
|
||||
{
|
||||
if (gpio->irq_cb) {
|
||||
GPIO_ExtiSetCB(gpio->pin, gpio->irq_cb, gpio->irq_args);
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIO_ExtiSetCB(gpio->pin, luat_gpio_irq_callback, gpio->irq_args);
|
||||
}
|
||||
switch (gpio->irq)
|
||||
{
|
||||
case LUAT_GPIO_RISING_IRQ:
|
||||
GPIO_ExtiConfig(gpio->pin, 0,1,0);
|
||||
break;
|
||||
case LUAT_GPIO_FALLING_IRQ:
|
||||
GPIO_ExtiConfig(gpio->pin, 0,0,1);
|
||||
break;
|
||||
case LUAT_GPIO_BOTH_IRQ:
|
||||
GPIO_ExtiConfig(gpio->pin, 0,1,1);
|
||||
break;
|
||||
case LUAT_GPIO_HIGH_IRQ:
|
||||
GPIO_ExtiConfig(gpio->pin, 1,1,0);
|
||||
break;
|
||||
case LUAT_GPIO_LOW_IRQ:
|
||||
GPIO_ExtiConfig(gpio->pin, 1,0,1);
|
||||
break;
|
||||
default:
|
||||
GPIO_ExtiConfig(gpio->pin, 0,0,0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIO_ExtiConfig(gpio->pin, 0,0,0);
|
||||
GPIO_ExtiSetCB(gpio->pin, NULL, NULL);
|
||||
}
|
||||
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(gpio->pin, 0), 0, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_gpio_set(int pin, int level){
|
||||
if (((uint32_t)(pin)) >= HAL_GPIO_MAX) return -1;
|
||||
GPIO_Output(pin, level);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_gpio_get(int pin){
|
||||
if (((uint32_t)(pin)) >= HAL_GPIO_QTY) return 0;
|
||||
uint8_t re;
|
||||
if (HAL_WAKEUP_PWRKEY == pin)
|
||||
{
|
||||
return pwrKeyGetPinLevel();
|
||||
}
|
||||
if (pin >= HAL_GPIO_MAX)
|
||||
{
|
||||
pin -= HAL_WAKEUP_0;
|
||||
re = slpManGetWakeupPinValue() & (1 << pin);
|
||||
}
|
||||
else
|
||||
{
|
||||
re = GPIO_Input(pin);
|
||||
}
|
||||
return re?1:0;
|
||||
}
|
||||
|
||||
void luat_gpio_close(int pin){
|
||||
#ifdef __LUATOS__
|
||||
if (pin >= HAL_GPIO_QTY) return ;
|
||||
if (HAL_WAKEUP_PWRKEY == pin)
|
||||
{
|
||||
NVIC_DisableIRQ(PwrkeyWakeup_IRQn);
|
||||
NVIC_ClearPendingIRQ(PwrkeyWakeup_IRQn);
|
||||
pwrKeyHwDeinit(0);
|
||||
pwrKeyIsrCallback = NULL;
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (pin >= HAL_WAKEUP_PWRKEY) return ;
|
||||
#endif
|
||||
if (pin >= HAL_GPIO_MAX)
|
||||
{
|
||||
GPIO_WakeupPadConfig(pin, 0, 0, 0, 0);
|
||||
}
|
||||
GPIO_ExtiSetCB(pin, NULL, 0);
|
||||
GPIO_ExtiConfig(pin, 0,0,0);
|
||||
return ;
|
||||
}
|
||||
int luat_gpio_set_irq_cb(int pin, luat_gpio_irq_cb cb, void* args)
|
||||
{
|
||||
#ifdef __LUATOS__
|
||||
if (pin >= HAL_GPIO_QTY) return -1;
|
||||
if (HAL_WAKEUP_PWRKEY == pin)
|
||||
{
|
||||
pwrKeyIsrCallback = cb;
|
||||
return 0;
|
||||
}
|
||||
GPIO_ExtiSetCB(pin, cb, args);
|
||||
#else
|
||||
if (pin >= HAL_WAKEUP_PWRKEY) return -1;
|
||||
GPIO_ExtiSetCB(pin, cb, args);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void luat_gpio_pulse(int pin, uint8_t *level, uint16_t len, uint16_t delay_ns)
|
||||
{
|
||||
GPIO_OutPulse(pin, level, len, delay_ns);
|
||||
}
|
||||
|
||||
int luat_gpio_ctrl(int pin, LUAT_GPIO_CTRL_CMD_E cmd, int param)
|
||||
{
|
||||
if (pin > (HAL_GPIO_MAX + 1)) return -1;
|
||||
uint8_t alt_fun = (param >> 28);
|
||||
switch(cmd)
|
||||
{
|
||||
case LUAT_GPIO_CMD_SET_PULL_MODE:
|
||||
switch(param)
|
||||
{
|
||||
case LUAT_GPIO_PULLUP:
|
||||
GPIO_Config(GPIO_ToPadEC618(pin, alt_fun), 1, 1);
|
||||
break;
|
||||
case LUAT_GPIO_PULLDOWN:
|
||||
GPIO_Config(GPIO_ToPadEC618(pin, alt_fun), 1, 0);
|
||||
break;
|
||||
default:
|
||||
GPIO_Config(GPIO_ToPadEC618(pin, alt_fun), 0, 0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case LUAT_GPIO_CMD_SET_IRQ_MODE:
|
||||
switch(param)
|
||||
{
|
||||
case LUAT_GPIO_RISING_IRQ:
|
||||
GPIO_ExtiConfig(pin, 0,1,0);
|
||||
break;
|
||||
case LUAT_GPIO_FALLING_IRQ:
|
||||
GPIO_ExtiConfig(pin, 0,0,1);
|
||||
break;
|
||||
case LUAT_GPIO_BOTH_IRQ:
|
||||
GPIO_ExtiConfig(pin, 0,1,1);
|
||||
break;
|
||||
case LUAT_GPIO_HIGH_IRQ:
|
||||
GPIO_ExtiConfig(pin, 1,1,0);
|
||||
break;
|
||||
case LUAT_GPIO_LOW_IRQ:
|
||||
GPIO_ExtiConfig(pin, 1,0,1);
|
||||
break;
|
||||
default:
|
||||
GPIO_ExtiConfig(pin, 0,0,0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "luat_i2c.h"
|
||||
#include "common_api.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "bsp_custom.h"
|
||||
|
||||
#if RTE_I2C0
|
||||
extern ARM_DRIVER_I2C Driver_I2C0;
|
||||
static ARM_DRIVER_I2C *i2cDrv0 = &CREATE_SYMBOL(Driver_I2C, 0);
|
||||
#endif
|
||||
#if RTE_I2C1
|
||||
extern ARM_DRIVER_I2C Driver_I2C1;
|
||||
static ARM_DRIVER_I2C *i2cDrv1 = &CREATE_SYMBOL(Driver_I2C, 1);
|
||||
#endif
|
||||
|
||||
int luat_i2c_exist(int id) {
|
||||
#if RTE_I2C0
|
||||
if (id == 0)
|
||||
return 1;
|
||||
#endif
|
||||
#if RTE_I2C1
|
||||
if (id == 1)
|
||||
return 1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
int luat_i2c_setup(int id, int speed) {
|
||||
if (!luat_i2c_exist(id)) {
|
||||
return -1;
|
||||
}
|
||||
int ret = 0;
|
||||
#if RTE_I2C0
|
||||
if (id==0)
|
||||
{
|
||||
ret = i2cDrv0->Initialize(NULL);
|
||||
if (ret) DBG("i2c0 setup error -- Initialize - %ld", ret);
|
||||
ret = i2cDrv0->PowerControl(ARM_POWER_FULL);
|
||||
if (ret) DBG("i2c0 setup error -- PowerControl - %ld", ret);
|
||||
if (speed == 0)//(100kHz)
|
||||
ret = i2cDrv0->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_STANDARD);
|
||||
else if (speed == 1)//(400kHz)
|
||||
ret = i2cDrv0->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
|
||||
else if (speed == 2)//( 1MHz)
|
||||
ret = i2cDrv0->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST_PLUS);
|
||||
else if (speed == 3)//(3.4MHz)
|
||||
ret = i2cDrv0->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_HIGH);
|
||||
if (ret) DBG("i2c0 setup error -- Control SPEED - %ld", ret);
|
||||
ret = i2cDrv0->Control(ARM_I2C_BUS_CLEAR, 0);
|
||||
if (ret) DBG("i2c0 setup error -- Control CLEAR - %ld", ret);
|
||||
DBG("i2c0 setup complete");
|
||||
}
|
||||
#endif
|
||||
#if RTE_I2C1
|
||||
if (id==1)
|
||||
{
|
||||
ret = i2cDrv1->Initialize(NULL);
|
||||
if (ret) DBG("i2c1 setup error -- Initialize - %ld", ret);
|
||||
ret = i2cDrv1->PowerControl(ARM_POWER_FULL);
|
||||
if (ret) DBG("i2c1 setup error -- PowerControl - %ld", ret);
|
||||
if (speed == 0)//(100kHz)
|
||||
ret = i2cDrv1->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_STANDARD);
|
||||
else if (speed == 1)//(400kHz)
|
||||
ret = i2cDrv1->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
|
||||
else if (speed == 2)//( 1MHz)
|
||||
ret = i2cDrv1->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST_PLUS);
|
||||
else if (speed == 3)//(3.4MHz)
|
||||
ret = i2cDrv1->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_HIGH);
|
||||
if (ret) DBG("i2c1 setup error -- Control SPEED - %ld", ret);
|
||||
ret = i2cDrv1->Control(ARM_I2C_BUS_CLEAR, 0);
|
||||
if (ret) DBG("i2c1 setup error -- Control CLEAR - %ld", ret);
|
||||
DBG("i2c1 setup complete");
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int luat_i2c_close(int id) {
|
||||
if (!luat_i2c_exist(id)) {
|
||||
return -1;
|
||||
}
|
||||
#if RTE_I2C0
|
||||
if (id==0){
|
||||
i2cDrv0->PowerControl(ARM_POWER_OFF);
|
||||
i2cDrv0->Uninitialize();
|
||||
}
|
||||
#endif
|
||||
#if RTE_I2C1
|
||||
if (id==1){
|
||||
i2cDrv1->PowerControl(ARM_POWER_OFF);
|
||||
i2cDrv1->Uninitialize();
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_i2c_send(int id, int addr, void* buff, size_t len, uint8_t stop) {
|
||||
if (!luat_i2c_exist(id)) {
|
||||
return -1;
|
||||
}
|
||||
#if RTE_I2C0
|
||||
if (id==0){
|
||||
if (stop)
|
||||
return i2cDrv0->MasterTransmit(addr, buff, len, false);
|
||||
else
|
||||
return i2cDrv0->MasterTransmit(addr, buff, len, true);
|
||||
}
|
||||
#endif
|
||||
#if RTE_I2C1
|
||||
if (id==1){
|
||||
if (stop)
|
||||
return i2cDrv1->MasterTransmit(addr, buff, len, false);
|
||||
else
|
||||
return i2cDrv1->MasterTransmit(addr, buff, len, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int luat_i2c_recv(int id, int addr, void* buff, size_t len) {
|
||||
if (!luat_i2c_exist(id)) {
|
||||
return -1;
|
||||
}
|
||||
#if RTE_I2C0
|
||||
if (id==0){
|
||||
return i2cDrv0->MasterReceive(addr, buff, len, false);
|
||||
}
|
||||
#endif
|
||||
#if RTE_I2C1
|
||||
if (id==1){
|
||||
return i2cDrv1->MasterReceive(addr, buff, len, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int luat_i2c_transfer(int id, int addr, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len)
|
||||
{
|
||||
int result;
|
||||
result = luat_i2c_send(id, addr, reg, reg_len, 0);
|
||||
if (result != 0) return-1;
|
||||
return luat_i2c_recv(id, addr, buff, len);
|
||||
}
|
||||
|
||||
#else
|
||||
#include "luat_i2c.h"
|
||||
#include "common_api.h"
|
||||
#include "soc_i2c.h"
|
||||
#include "driver_gpio.h"
|
||||
static uint8_t luat_i2c_iomux[I2C_MAX];
|
||||
int luat_i2c_exist(int id) {
|
||||
return (id < I2C_MAX);
|
||||
}
|
||||
|
||||
int luat_i2c_set_iomux(int id, uint8_t value)
|
||||
{
|
||||
if (!luat_i2c_exist(id)) return -1;
|
||||
luat_i2c_iomux[id] = value;
|
||||
}
|
||||
|
||||
int luat_i2c_setup(int id, int speed) {
|
||||
if (speed == 0) {
|
||||
speed = 100 * 1000; // SLOW
|
||||
}
|
||||
else if (speed == 1) {
|
||||
speed = 400 * 1000; // FAST
|
||||
}
|
||||
else if (speed == 2) {
|
||||
speed = 400 * 1000; // SuperFast
|
||||
}
|
||||
if (!luat_i2c_exist(id)) return -1;
|
||||
if (id)
|
||||
{
|
||||
switch(luat_i2c_iomux[id])
|
||||
{
|
||||
case 1:
|
||||
GPIO_IomuxEC618(23, 2, 1, 0);
|
||||
GPIO_IomuxEC618(24, 2, 1, 0);
|
||||
break;
|
||||
default:
|
||||
GPIO_IomuxEC618(19, 2, 1, 0);
|
||||
GPIO_IomuxEC618(20, 2, 1, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(luat_i2c_iomux[id])
|
||||
{
|
||||
case 1:
|
||||
GPIO_IomuxEC618(27, 2, 1, 0);
|
||||
GPIO_IomuxEC618(28, 2, 1, 0);
|
||||
break;
|
||||
case 2:
|
||||
GPIO_IomuxEC618(16, 2, 1, 0);
|
||||
GPIO_IomuxEC618(17, 2, 1, 0);
|
||||
break;
|
||||
default:
|
||||
GPIO_IomuxEC618(13, 2, 1, 0);
|
||||
GPIO_IomuxEC618(14, 2, 1, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
I2C_MasterSetup(id, speed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_i2c_close(int id) {
|
||||
if (!luat_i2c_exist(id)) return -1;
|
||||
if (id)
|
||||
{
|
||||
switch(luat_i2c_iomux[id])
|
||||
{
|
||||
case 1:
|
||||
GPIO_IomuxEC618(23, 0, 1, 0);
|
||||
GPIO_IomuxEC618(24, 0, 1, 0);
|
||||
break;
|
||||
default:
|
||||
GPIO_IomuxEC618(19, 0, 1, 0);
|
||||
GPIO_IomuxEC618(20, 0, 1, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(luat_i2c_iomux[id])
|
||||
{
|
||||
case 1:
|
||||
GPIO_IomuxEC618(27, 0, 1, 0);
|
||||
GPIO_IomuxEC618(28, 0, 1, 0);
|
||||
break;
|
||||
case 2:
|
||||
GPIO_IomuxEC618(16, 0, 1, 0);
|
||||
GPIO_IomuxEC618(17, 0, 1, 0);
|
||||
break;
|
||||
default:
|
||||
GPIO_IomuxEC618(13, 0, 1, 0);
|
||||
GPIO_IomuxEC618(14, 0, 1, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_i2c_send(int id, int addr, void* buff, size_t len, uint8_t stop) {
|
||||
if (!luat_i2c_exist(id)) return -1;
|
||||
return I2C_BlockWrite(id, addr, (const uint8_t *)buff, len, 25, NULL, NULL);
|
||||
// I2C_Prepare(id, addr, 1, NULL, NULL);
|
||||
// I2C_MasterXfer(id, I2C_OP_WRITE, 0, buff, len, 20);
|
||||
}
|
||||
|
||||
int luat_i2c_recv(int id, int addr, void* buff, size_t len) {
|
||||
if (!luat_i2c_exist(id)) return -1;
|
||||
return I2C_BlockRead(id, addr, 0, 0, (uint8_t *)buff, len, 25, NULL, NULL);
|
||||
// I2C_Prepare(id, addr, 1, NULL, NULL);
|
||||
// I2C_MasterXfer(id, I2C_OP_READ, 0, buff, len, 20);
|
||||
}
|
||||
|
||||
int luat_i2c_transfer(int id, int addr, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len) {
|
||||
if (!luat_i2c_exist(id)) return -1;
|
||||
if (reg && reg_len) {
|
||||
return I2C_BlockRead(id, addr, reg, reg_len, (uint8_t *)buff, len, 25, NULL, NULL);
|
||||
} else {
|
||||
return I2C_BlockWrite(id, addr, (const uint8_t *)buff, len, 25, NULL, NULL);
|
||||
}
|
||||
}
|
||||
extern void I2C_SetNoBlock(uint8_t I2CID);
|
||||
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) {
|
||||
if (!luat_i2c_exist(id)) return -1;
|
||||
int32_t Result;
|
||||
if (!I2C_WaitResult(id, &Result)) {
|
||||
return -1;
|
||||
}
|
||||
I2C_Prepare(id, addr, 2, CB, pParam);
|
||||
I2C_SetNoBlock(id);
|
||||
if (reg && reg_len)
|
||||
{
|
||||
I2C_MasterXfer(id, I2C_OP_READ_REG, reg, reg_len, buff, len, Toms);
|
||||
}
|
||||
else if (is_read)
|
||||
{
|
||||
I2C_MasterXfer(id, I2C_OP_READ, NULL, 0, buff, len, Toms);
|
||||
}
|
||||
else
|
||||
{
|
||||
I2C_MasterXfer(id, I2C_OP_WRITE, NULL, 0, buff, len, Toms);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#include "luat_i2s_ec618.h"
|
||||
#include "driver_i2s.h"
|
||||
#include "driver_gpio.h"
|
||||
void luat_i2s_init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void luat_i2s_base_setup(uint8_t bus_id, uint8_t mode, uint8_t frame_size)
|
||||
{
|
||||
I2S_BaseConfig(bus_id, mode, frame_size);
|
||||
switch(bus_id)
|
||||
{
|
||||
case I2S_ID0:
|
||||
GPIO_IomuxEC618(39, 1, 1, 0);
|
||||
GPIO_IomuxEC618(35, 1, 1, 0);
|
||||
GPIO_IomuxEC618(36, 1, 1, 0);
|
||||
GPIO_IomuxEC618(37, 1, 1, 0);
|
||||
GPIO_IomuxEC618(38, 1, 1, 0);
|
||||
break;
|
||||
case I2S_ID1:
|
||||
GPIO_IomuxEC618(18, 1, 1, 0);
|
||||
GPIO_IomuxEC618(19, 1, 1, 0);
|
||||
GPIO_IomuxEC618(20, 1, 1, 0);
|
||||
GPIO_IomuxEC618(21, 1, 1, 0);
|
||||
GPIO_IomuxEC618(22, 1, 1, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int luat_i2s_start(uint8_t bus_id, uint8_t is_play, uint32_t sample, uint8_t channel_num)
|
||||
{
|
||||
return I2S_Start(bus_id, is_play, sample, channel_num);
|
||||
}
|
||||
|
||||
void luat_i2s_no_block_tx(uint8_t bus_id, uint8_t* address, uint32_t byte_len, CBFuncEx_t cb, void *param)
|
||||
{
|
||||
I2S_Tx(bus_id, address, byte_len, cb, param);
|
||||
}
|
||||
void luat_i2s_no_block_rx(uint8_t bus_id, uint32_t byte_len, CBFuncEx_t cb, void *param)
|
||||
{
|
||||
I2S_Rx(bus_id,byte_len, cb, param);
|
||||
}
|
||||
|
||||
|
||||
void luat_i2s_tx_stop(uint8_t bus_id)
|
||||
{
|
||||
I2S_TxStop(bus_id);
|
||||
}
|
||||
|
||||
void luat_i2s_rx_stop(uint8_t bus_id)
|
||||
{
|
||||
I2S_RxStop(bus_id);
|
||||
}
|
||||
|
||||
void luat_i2s_deinit(uint8_t bus_id)
|
||||
{
|
||||
I2S_TxStop(bus_id);
|
||||
}
|
||||
void luat_i2s_pause(uint8_t bus_id)
|
||||
{
|
||||
I2S_TxPause(bus_id);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "luat_base.h"
|
||||
|
||||
#include "luat_iconv.h"
|
||||
#include "iconv.h"
|
||||
|
||||
|
||||
luat_iconv_t luat_iconv_open (const char *to_code, const char *from_code)
|
||||
{
|
||||
return iconv_open(to_code, from_code);
|
||||
}
|
||||
|
||||
|
||||
size_t luat_iconv_convert (luat_iconv_t cd, char ** inbuf, size_t * in_bytes_left, char ** outbuf, size_t * out_bytes_left)
|
||||
{
|
||||
return iconv_convert(cd, inbuf, in_bytes_left, outbuf, out_bytes_left);
|
||||
}
|
||||
|
||||
|
||||
int luat_iconv_close (luat_iconv_t cd)
|
||||
{
|
||||
return iconv_close(cd);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#include "common_api.h"
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_debug.h"
|
||||
#include "luat_kv.h"
|
||||
#include "fal.h"
|
||||
#include "flashdb.h"
|
||||
|
||||
struct fdb_kvdb* luat_kvdb;
|
||||
size_t luat_kvdb_debug_mode = 0;
|
||||
|
||||
int luat_kv_init(void)
|
||||
{
|
||||
if (luat_kvdb != NULL) {
|
||||
return 0;
|
||||
}
|
||||
luat_kvdb = malloc(sizeof(struct fdb_kvdb));
|
||||
if (luat_kvdb == NULL) {
|
||||
LUAT_DEBUG_PRINT("out of memory when malloc fdb_kvdb");
|
||||
return -1;
|
||||
}
|
||||
memset(luat_kvdb, 0, sizeof(struct fdb_kvdb));
|
||||
fdb_err_t ret = fdb_kvdb_init(luat_kvdb, "env", "onchip_fdb", NULL, NULL);
|
||||
LUAT_DEBUG_PRINT("fdb_kvdb_init ret %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int luat_kv_del(const char* key) {
|
||||
if (luat_kvdb == NULL) {
|
||||
LUAT_DEBUG_PRINT("luat_kv NEED init!!!");
|
||||
return -1;
|
||||
}
|
||||
return fdb_kv_del(luat_kvdb, key);
|
||||
}
|
||||
|
||||
int luat_kv_set(const char* key, void* data, size_t len) {
|
||||
if (luat_kvdb == NULL) {
|
||||
LUAT_DEBUG_PRINT("luat_kv NEED init!!!");
|
||||
return -1;
|
||||
}
|
||||
struct fdb_blob blob = {0};
|
||||
blob.buf = data;
|
||||
blob.size = len;
|
||||
int ret = fdb_kv_set_blob(luat_kvdb, key, &blob);
|
||||
if (luat_kvdb_debug_mode)
|
||||
LUAT_DEBUG_PRINT("luat_kv_set %s %p %d %d", key, data, len, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int luat_kv_get(const char* key, void* data, size_t len) {
|
||||
if (luat_kvdb == NULL) {
|
||||
LUAT_DEBUG_PRINT("luat_kv NEED init!!!");
|
||||
return -1;
|
||||
}
|
||||
struct fdb_blob blob = {0};
|
||||
blob.buf = data;
|
||||
blob.size = len;
|
||||
int ret = fdb_kv_get_blob(luat_kvdb, key, &blob);
|
||||
if (luat_kvdb_debug_mode)
|
||||
LUAT_DEBUG_PRINT("luat_kv_get %s %p %d %d", key, data, len, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int luat_kv_clear(void) {
|
||||
if (luat_kvdb == NULL) {
|
||||
LUAT_DEBUG_PRINT("luat_kv NEED init!!!");
|
||||
return -1;
|
||||
}
|
||||
fdb_kv_set_default(luat_kvdb);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "luat_base.h"
|
||||
#include "luat_mcu.h"
|
||||
|
||||
long luat_mcu_ticks(void) {
|
||||
return xTaskGetTickCount();
|
||||
}
|
||||
|
||||
int luat_mcu_set_clk(size_t mhz) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_mcu_get_clk(void) {
|
||||
return 204;
|
||||
}
|
||||
|
||||
|
||||
// 隐藏API, 头文件里没有
|
||||
uint8_t QSPI_FLASH_ReadUUID(uint8_t* uuid, uint32_t* validlen);
|
||||
uint8_t unique_id[16];
|
||||
uint32_t unique_id_len;
|
||||
const char* luat_mcu_unique_id(size_t* t) {
|
||||
if (unique_id[0] == 0) {
|
||||
QSPI_FLASH_ReadUUID(unique_id, &unique_id_len);
|
||||
if (unique_id_len == 16) {
|
||||
for (size_t i = 0; i < 6; i++)
|
||||
{
|
||||
if (unique_id[unique_id_len - 1] == 0xFF) {
|
||||
unique_id_len --;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*t = unique_id_len;
|
||||
return (const char*)unique_id;
|
||||
}
|
||||
|
||||
uint32_t luat_mcu_hz(void) {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
uint64_t luat_mcu_tick64(void) {
|
||||
return soc_get_poweron_time_tick();
|
||||
}
|
||||
int luat_mcu_us_period(void) {
|
||||
return 26;
|
||||
}
|
||||
uint64_t luat_mcu_tick64_ms(void) {
|
||||
return soc_get_poweron_time_ms();
|
||||
}
|
||||
|
||||
void luat_mcu_set_clk_source(uint8_t source_main, uint8_t source_32k, uint32_t delay) {
|
||||
// nop
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* mem操作
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void* luat_heap_malloc(size_t len) {
|
||||
return malloc(len);
|
||||
}
|
||||
|
||||
void luat_heap_free(void* ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void* luat_heap_realloc(void* ptr, size_t len) {
|
||||
return realloc(ptr, len);
|
||||
}
|
||||
|
||||
void* luat_heap_calloc(size_t count, size_t _size) {
|
||||
return calloc(count, _size);
|
||||
}
|
||||
|
||||
size_t xPortGetTotalHeapSize( void );
|
||||
void luat_meminfo_sys(size_t *total, size_t *used, size_t *max_used) {
|
||||
*total = xPortGetTotalHeapSize();
|
||||
*used = *total - xPortGetFreeHeapSize();
|
||||
*max_used = *total - xPortGetMinimumEverFreeHeapSize();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,516 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "luat_mobile.h"
|
||||
#include "ps_lib_api.h"
|
||||
#include "common_api.h"
|
||||
#include "cmimm.h"
|
||||
#include "cmidev.h"
|
||||
#include "cms_api.h"
|
||||
|
||||
extern void soc_mobile_event_deregister_handler(void);
|
||||
extern void soc_mobile_get_imsi(uint8_t *buf);
|
||||
extern void soc_mobile_get_iccid(uint8_t *buf);
|
||||
extern void soc_mobile_event_register_handler(void *handle);
|
||||
extern void soc_mobile_set_period(uint32_t get_cell_period, uint32_t check_sim_period, uint8_t search_cell_time);
|
||||
extern void soc_mobile_reset_stack(void);
|
||||
extern void soc_mobile_get_signal(CmiMmCesqInd *info);
|
||||
extern void soc_mobile_get_cell_info(CmiDevGetBasicCellListInfoInd *info);
|
||||
extern void soc_mobile_get_sim_id(uint8_t *sim_id, uint8_t *is_auto);
|
||||
extern void soc_mobile_set_sim_id(uint8_t sim_id);
|
||||
extern void soc_mobile_sms_event_register_handler(void *handle);
|
||||
extern uint8_t soc_mobile_get_csq(void);
|
||||
extern void soc_mobile_search_cell_info_async(uint8_t param);
|
||||
int soc_mobile_get_default_pdp_part_info(uint8_t *ip_type, uint8_t *apn,uint8_t *apn_len, uint8_t *dns_num, ip_addr_t *dns_ip);
|
||||
|
||||
int luat_mobile_get_imei(int sim_id, char* buff, size_t buf_len)
|
||||
{
|
||||
char temp[20] = {0};
|
||||
int result = appGetImeiNumSync(temp);
|
||||
if (!result)
|
||||
{
|
||||
memcpy(buff, temp, (buf_len > sizeof(temp))?sizeof(temp):buf_len);
|
||||
return (buf_len > sizeof(temp))?sizeof(temp):buf_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int luat_mobile_get_sn(char* buff, size_t buf_len)
|
||||
{
|
||||
char temp[32] = {0};
|
||||
int result = appGetSNNumSync(temp);
|
||||
if (result)
|
||||
{
|
||||
memcpy(buff, temp, (buf_len > sizeof(temp))?sizeof(temp):buf_len);
|
||||
return (buf_len > sizeof(temp))?sizeof(temp):buf_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int luat_mobile_set_sn(char* buff, uint8_t buf_len)
|
||||
{
|
||||
int result = appSetSNNumSync(buff, buf_len);
|
||||
return result==1 ? 0 : -1;
|
||||
}
|
||||
|
||||
int luat_mobile_get_muid(char* buff, size_t buf_len)
|
||||
{
|
||||
char temp[64] = {0};
|
||||
int result = soc_get_sn(temp, sizeof(temp));
|
||||
if (!result)
|
||||
{
|
||||
memcpy(buff, temp, (buf_len > sizeof(temp))?sizeof(temp):buf_len);
|
||||
return (buf_len > sizeof(temp))?sizeof(temp):buf_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int luat_mobile_get_iccid(int sim_id, char* buff, size_t buf_len)
|
||||
{
|
||||
char temp[24] = {0};
|
||||
soc_mobile_get_iccid(temp);
|
||||
if (temp[0])
|
||||
{
|
||||
memcpy(buff, temp, (buf_len > sizeof(temp))?sizeof(temp):buf_len);
|
||||
return (buf_len > sizeof(temp))?sizeof(temp):buf_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int luat_mobile_get_imsi(int sim_id, char* buff, size_t buf_len)
|
||||
{
|
||||
char temp[20] = {0};
|
||||
soc_mobile_get_imsi(temp);
|
||||
if (temp[0])
|
||||
{
|
||||
memcpy(buff, temp, (buf_len > sizeof(temp))?sizeof(temp):buf_len);
|
||||
return (buf_len > sizeof(temp))?sizeof(temp):buf_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int luat_mobile_get_sim_id(int *id)
|
||||
{
|
||||
uint8_t sim_id, is_auto;
|
||||
soc_mobile_get_sim_id(&sim_id, &is_auto);
|
||||
if (sim_id != 0xff)
|
||||
{
|
||||
*id = sim_id;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int luat_mobile_set_sim_id(int id)
|
||||
{
|
||||
if (id > 2)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
soc_mobile_set_sim_id(id);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int luat_mobile_get_apn(int sim_id, int cid, char* buff, size_t buf_len)
|
||||
{
|
||||
uint8_t type;
|
||||
int default_cid = soc_mobile_get_default_pdp_part_info(&type, NULL, NULL, NULL, NULL);
|
||||
if (cid > 0 && default_cid != cid)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
uint8_t apn_len = buf_len;
|
||||
soc_mobile_get_default_pdp_part_info(&type, buff, &apn_len, NULL, NULL);
|
||||
return apn_len;
|
||||
}
|
||||
|
||||
int luat_mobile_get_default_apn(int sim_id, char* buff, size_t buf_len)
|
||||
{
|
||||
return luat_mobile_get_apn(sim_id, -1, buff, buf_len);
|
||||
}
|
||||
|
||||
int luat_mobile_set_apn(int sim_id, int cid, const char* buff, size_t buf_len)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// 进出飞行模式
|
||||
int luat_mobile_set_flymode(int index, int mode)
|
||||
{
|
||||
return appSetCFUN(!mode);
|
||||
}
|
||||
|
||||
int luat_mobile_get_flymode(int index)
|
||||
{
|
||||
uint8_t state;
|
||||
int result = appGetCFUN(&state);
|
||||
if (!result)
|
||||
{
|
||||
return state;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int luat_mobile_get_local_ip(int sim_id, int cid, ip_addr_t *ip_v4, ip_addr_t *ip_v6)
|
||||
{
|
||||
int i;
|
||||
struct netif *netif = netif_find_by_cid(cid);
|
||||
if (netif)
|
||||
{
|
||||
if (ip_v4)
|
||||
{
|
||||
*ip_v4 = netif->ip_addr;
|
||||
}
|
||||
if (ip_v6)
|
||||
{
|
||||
ip_v6->type = 0xff;
|
||||
for(i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++)
|
||||
{
|
||||
if (netif->ip6_addr_state[i] & IP6_ADDR_VALID)
|
||||
{
|
||||
*ip_v6 = netif->ip6_addr[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ip_v4)
|
||||
{
|
||||
ip_v4->type = 0xff;
|
||||
}
|
||||
if (ip_v6)
|
||||
{
|
||||
ip_v6->type = 0xff;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------------- cell info begin -------------------------------------------------- */
|
||||
uint8_t luat_mobile_rssi_to_csq(int8_t rssi)
|
||||
{
|
||||
if (rssi <= -113)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (rssi < -52)
|
||||
{
|
||||
return (rssi + 113) >> 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 31;
|
||||
}
|
||||
}
|
||||
|
||||
static void ec618_cell_to_luat_cell(BasicCellListInfo *bcListInfo, luat_mobile_cell_info_t *info)
|
||||
{
|
||||
info->gsm_info_valid = 0;
|
||||
if (!bcListInfo->sCellPresent && !bcListInfo->nCellNum)
|
||||
{
|
||||
info->lte_info_valid = 0;
|
||||
return;
|
||||
}
|
||||
if (!bcListInfo->sCellPresent)
|
||||
{
|
||||
info->lte_service_info.cid = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
info->lte_service_info.cid = bcListInfo->sCellInfo.cellId;
|
||||
info->lte_service_info.band = bcListInfo->sCellInfo.band;
|
||||
info->lte_service_info.dlbandwidth = bcListInfo->sCellInfo.dlBandWidth;
|
||||
info->lte_service_info.ulbandwidth = bcListInfo->sCellInfo.ulBandWidth;
|
||||
info->lte_service_info.is_tdd = bcListInfo->sCellInfo.isTdd;
|
||||
info->lte_service_info.earfcn = bcListInfo->sCellInfo.earfcn;
|
||||
info->lte_service_info.pci = bcListInfo->sCellInfo.phyCellId;
|
||||
info->lte_service_info.tac = bcListInfo->sCellInfo.tac;
|
||||
info->lte_service_info.snr = bcListInfo->sCellInfo.snr;
|
||||
info->lte_service_info.rsrp = bcListInfo->sCellInfo.rsrp;
|
||||
info->lte_service_info.rsrq = bcListInfo->sCellInfo.rsrq;
|
||||
info->lte_service_info.rssi = bcListInfo->sCellInfo.rsrp - bcListInfo->sCellInfo.rsrq + (bcListInfo->sCellInfo.rssiCompensation/100);
|
||||
info->lte_service_info.mcc = bcListInfo->sCellInfo.plmn.mcc;
|
||||
if (0xf000 == (bcListInfo->sCellInfo.plmn.mncWithAddInfo & 0xf000))
|
||||
{
|
||||
info->lte_service_info.mnc = bcListInfo->sCellInfo.plmn.mncWithAddInfo & 0x0fff;
|
||||
}
|
||||
else
|
||||
{
|
||||
info->lte_service_info.mnc = bcListInfo->sCellInfo.plmn.mncWithAddInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!bcListInfo->nCellNum)
|
||||
{
|
||||
info->lte_neighbor_info_num = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t j = 0;
|
||||
for(uint8_t i = 0; i < bcListInfo->nCellNum; i++)
|
||||
{
|
||||
if (bcListInfo->nCellList[i].cellInfoValid)
|
||||
{
|
||||
info->lte_info[j].cid = bcListInfo->nCellList[i].cellId;
|
||||
info->lte_info[j].tac = bcListInfo->nCellList[i].tac;
|
||||
info->lte_info[j].mcc = bcListInfo->nCellList[i].plmn.mcc;
|
||||
|
||||
if (0xf000 == (bcListInfo->nCellList[i].plmn.mncWithAddInfo & 0xf000))
|
||||
{
|
||||
info->lte_info[j].mnc = bcListInfo->nCellList[i].plmn.mncWithAddInfo & 0x0fff;
|
||||
}
|
||||
else
|
||||
{
|
||||
info->lte_info[j].mnc = bcListInfo->nCellList[i].plmn.mncWithAddInfo;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
info->lte_info[j].cid = 0;
|
||||
info->lte_info[j].tac = 0;
|
||||
info->lte_info[j].mcc = 0;
|
||||
info->lte_info[j].mnc = 0;
|
||||
}
|
||||
info->lte_info[j].earfcn = bcListInfo->nCellList[i].earfcn;
|
||||
info->lte_info[j].pci = bcListInfo->nCellList[i].phyCellId;
|
||||
info->lte_info[j].snr = bcListInfo->nCellList[i].snr;
|
||||
info->lte_info[j].rsrp = bcListInfo->nCellList[i].rsrp;
|
||||
info->lte_info[j].rsrq = bcListInfo->nCellList[i].rsrq;
|
||||
if ((info->lte_info[j].mcc == 0x0460) && (info->lte_info[j].mnc != 0x0015))
|
||||
{
|
||||
j++;
|
||||
|
||||
}
|
||||
}
|
||||
info->lte_neighbor_info_num = j;
|
||||
}
|
||||
}
|
||||
|
||||
static void ec618_signal_to_luat_signal(CmiMmCesqInd *cesq_info, luat_mobile_signal_strength_info_t *info)
|
||||
{
|
||||
uint8_t zero[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
info->luat_mobile_gw_signal_strength_vaild = 0;
|
||||
if (memcmp(zero, cesq_info, sizeof(CmiMmCesqInd)))
|
||||
{
|
||||
info->luat_mobile_lte_signal_strength_vaild = 1;
|
||||
if (cesq_info->rsrp != CMI_MM_NOT_DETECT_RSRP)
|
||||
{
|
||||
if (cesq_info->rsrp > 0)
|
||||
{
|
||||
info->lte_signal_strength.rsrp = (cesq_info->rsrp - 141);
|
||||
}
|
||||
else
|
||||
{
|
||||
info->lte_signal_strength.rsrp = (cesq_info->rsrp - 140);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
info->lte_signal_strength.rsrp = -999;
|
||||
}
|
||||
if (cesq_info->rsrq != CMI_MM_NOT_DETECT_RSRQ)
|
||||
{
|
||||
if (cesq_info->rsrq <= 0)
|
||||
{
|
||||
info->lte_signal_strength.rsrq = (cesq_info->rsrq - 39) >> 1;
|
||||
}
|
||||
else if (cesq_info->rsrq <= 34)
|
||||
{
|
||||
info->lte_signal_strength.rsrq = (cesq_info->rsrq - 40) >> 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
info->lte_signal_strength.rsrq = (cesq_info->rsrq - 41) >> 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
info->lte_signal_strength.rsrq = -999;
|
||||
}
|
||||
if (cesq_info->rsrp != CMI_MM_NOT_DETECT_RSRP &&
|
||||
cesq_info->rsrq != CMI_MM_NOT_DETECT_RSRQ)
|
||||
{
|
||||
info->lte_signal_strength.rssi = info->lte_signal_strength.rsrp - info->lte_signal_strength.rsrq + (cesq_info->rssiCompensation/100);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
info->lte_signal_strength.rssi = -999;
|
||||
}
|
||||
info->lte_signal_strength.snr = cesq_info->snr;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
info->luat_mobile_lte_signal_strength_vaild = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int luat_mobile_get_cell_info(luat_mobile_cell_info_t *info)
|
||||
{
|
||||
BasicCellListInfo bcListInfo;
|
||||
int result = appGetECBCInfoSync(&bcListInfo);
|
||||
if (!result)
|
||||
{
|
||||
ec618_cell_to_luat_cell(&bcListInfo, info);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int luat_mobile_get_cell_info_async(uint8_t max_time)
|
||||
{
|
||||
soc_mobile_search_cell_info_async(max_time);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_mobile_get_last_notify_cell_info(luat_mobile_cell_info_t *info)
|
||||
{
|
||||
BasicCellListInfo bcListInfo;
|
||||
soc_mobile_get_cell_info(&bcListInfo);
|
||||
ec618_cell_to_luat_cell(&bcListInfo, info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int luat_mobile_get_signal_strength_info(luat_mobile_signal_strength_info_t *info)
|
||||
{
|
||||
return luat_mobile_get_last_notify_signal_strength_info(info);
|
||||
}
|
||||
|
||||
int luat_mobile_get_signal_strength(uint8_t *csq)
|
||||
{
|
||||
return luat_mobile_get_last_notify_signal_strength(csq);
|
||||
}
|
||||
|
||||
int luat_mobile_get_last_notify_signal_strength_info(luat_mobile_signal_strength_info_t *info)
|
||||
{
|
||||
CmiMmCesqInd cesq_info;
|
||||
soc_mobile_get_signal(&cesq_info);
|
||||
ec618_signal_to_luat_signal(&cesq_info, info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_mobile_get_last_notify_signal_strength(uint8_t *csq)
|
||||
{
|
||||
*csq = soc_mobile_get_csq();
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------- cell info end --------------------------------------------------- */
|
||||
|
||||
|
||||
/* ------------------------------------------------ mobile status begin ----------------------------------------------- */
|
||||
LUAT_MOBILE_REGISTER_STATUS_E luat_mobile_get_register_status(void)
|
||||
{
|
||||
CeregGetStateParams param;
|
||||
int result = appGetCeregStateSync(¶m);
|
||||
if (!result)
|
||||
{
|
||||
return param.state;
|
||||
}
|
||||
return LUAT_MOBILE_STATUS_UNKNOW;
|
||||
}
|
||||
|
||||
int luat_mobile_event_register_handler(luat_mobile_event_callback_t callback_fun)
|
||||
{
|
||||
soc_mobile_event_register_handler(callback_fun);
|
||||
return 0;
|
||||
}
|
||||
int luat_mobile_event_deregister_handler(void)
|
||||
{
|
||||
soc_mobile_event_deregister_handler();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_mobile_sms_event_register_handler(luat_mobile_sms_event_callback_t callback_fun)
|
||||
{
|
||||
soc_mobile_sms_event_register_handler(callback_fun);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------- mobile status end ------------------------------------------------ */
|
||||
|
||||
extern soc_mobile_set_rrc_release_time(uint8_t s);
|
||||
void luat_mobile_set_rrc_auto_release_time(uint8_t s)
|
||||
{
|
||||
soc_mobile_set_rrc_release_time(s);
|
||||
}
|
||||
|
||||
extern void soc_mobile_release_rrc_pause(uint8_t onoff);
|
||||
void luat_mobile_rrc_auto_release_pause(uint8_t onoff)
|
||||
{
|
||||
soc_mobile_release_rrc_pause(onoff);
|
||||
}
|
||||
|
||||
extern void soc_mobile_rrc_release_once(void);
|
||||
void luat_mobile_rrc_release_once(void)
|
||||
{
|
||||
soc_mobile_rrc_release_once();
|
||||
}
|
||||
|
||||
int luat_mobile_reset_stack(void)
|
||||
{
|
||||
soc_mobile_reset_stack();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_mobile_set_period_work(uint32_t get_cell_period, uint32_t check_sim_period, uint8_t search_cell_time)
|
||||
{
|
||||
soc_mobile_set_period(get_cell_period, check_sim_period, search_cell_time);
|
||||
return 0;
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_otp.h"
|
||||
|
||||
// EC618提供的头文件没有OTP相关的API, 以下调用的均为隐藏API
|
||||
typedef enum
|
||||
{
|
||||
FLASH_OTP_ERASE = 0,
|
||||
FLASH_OTP_WRITE,
|
||||
FLASH_OTP_READ,
|
||||
FLASH_OTP_LOCK
|
||||
}FLASH_OTP_OPS;
|
||||
|
||||
uint8_t QSPI_FLASH_OTP_Handle(FLASH_OTP_OPS opType, uint32_t addr, uint8_t* bufPtr, uint8_t length);
|
||||
|
||||
int luat_otp_read(int zone, char* buff, size_t offset, size_t len) {
|
||||
uint8_t ret = 0;
|
||||
if (zone >= 1 && zone <= 3) {
|
||||
ret = QSPI_FLASH_OTP_Handle(FLASH_OTP_READ, ((uint32_t)zone << 16) + (offset), (uint8_t*)buff, len);
|
||||
if (ret == 0) {
|
||||
return (offset + len) > luat_otp_size(zone) ? luat_otp_size(zone) - offset : len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int luat_otp_write(int zone, char* buff, size_t offset, size_t len) {
|
||||
uint8_t ret = 0;
|
||||
if (zone >= 1 && zone <= 3) {
|
||||
ret = QSPI_FLASH_OTP_Handle(FLASH_OTP_WRITE, ((uint32_t)zone << 16) + (offset), (uint8_t*)buff, len);
|
||||
if (ret == 0) {
|
||||
return (offset + len) > luat_otp_size(zone) ? luat_otp_size(zone) - offset : len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int luat_otp_erase(int zone, size_t offset, size_t len) {
|
||||
if (zone >= 1 && zone <= 3) {
|
||||
return QSPI_FLASH_OTP_Handle(FLASH_OTP_ERASE, (uint32_t)zone << 16, NULL, 0);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int luat_otp_lock(int zone) {
|
||||
if (zone >= 1 && zone <= 3) {
|
||||
return QSPI_FLASH_OTP_Handle(FLASH_OTP_LOCK, (uint32_t)zone << 16, NULL, 0);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int luat_otp_size(int zone) {
|
||||
if (zone >= 1 && zone <= 3) {
|
||||
return 256;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PWM操作
|
||||
*
|
||||
*/
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "luat_base.h"
|
||||
#ifdef __LUATOS__
|
||||
#include "luat_malloc.h"
|
||||
#include "luat_msgbus.h"
|
||||
#include "luat_timer.h"
|
||||
#endif
|
||||
#include "luat_pwm.h"
|
||||
#include "luat_rtos.h"
|
||||
|
||||
#include "timer.h"
|
||||
#include "hal_adc.h"
|
||||
#include "ic.h"
|
||||
#include "hal_trim.h"
|
||||
#include "timer.h"
|
||||
#include "ec618.h"
|
||||
#include "clock.h"
|
||||
#include "pad.h"
|
||||
#include "luat_debug.h"
|
||||
#include "RTE_Device.h"
|
||||
#define EIGEN_TIMER(n) ((TIMER_TypeDef *) (AP_TIMER0_BASE_ADDR + 0x1000*n))
|
||||
|
||||
static signed char if_initialized_timer(const int channel)
|
||||
{
|
||||
if( 0 != EIGEN_TIMER(channel)->TCCR )
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define PWM_CH_MAX (6)
|
||||
|
||||
|
||||
static int g_s_pnum_set[PWM_CH_MAX] = {0}; /*设置PWM脉冲个数*/
|
||||
static volatile int g_s_pnum_update[PWM_CH_MAX] = {0};/*当前PWM个数*/
|
||||
/*最高频率应是26M*/
|
||||
#define MAX_FREQ (26*1000*1000)
|
||||
typedef struct pwm_ctx
|
||||
{
|
||||
TimerPwmConfig_t timer_config;
|
||||
uint32_t freq;
|
||||
uint32_t pulse;
|
||||
uint32_t pnum;
|
||||
}pwm_ctx_t;
|
||||
|
||||
typedef struct pwm_map
|
||||
{
|
||||
int pwm_ch; // 对外展示的pwm id
|
||||
int clockId;
|
||||
int clockId_slect;
|
||||
int time_req;
|
||||
int pad;
|
||||
}pwm_map_t;
|
||||
|
||||
static const pwm_map_t maps[] = {
|
||||
#ifdef RTE_PWM0
|
||||
{.pwm_ch=0, .clockId=FCLK_TIMER0, .clockId_slect=FCLK_TIMER0_SEL_26M, .time_req=PXIC0_TIMER0_IRQn, .pad=RTE_PWM0},
|
||||
#endif
|
||||
#ifdef RTE_PWM1
|
||||
{.pwm_ch=1, .clockId=FCLK_TIMER1, .clockId_slect=FCLK_TIMER1_SEL_26M, .time_req=PXIC0_TIMER1_IRQn, .pad=RTE_PWM1},
|
||||
#endif
|
||||
#ifdef RTE_PWM2
|
||||
{.pwm_ch=2, .clockId=FCLK_TIMER2, .clockId_slect=FCLK_TIMER2_SEL_26M, .time_req=PXIC0_TIMER2_IRQn, .pad=RTE_PWM2},
|
||||
#endif
|
||||
// #ifdef RTE_PWM3
|
||||
// {.pwm_ch=3, .clockId=FCLK_TIMER3, .clockId_slect=FCLK_TIMER3_SEL_26M, .time_req=PXIC0_TIMER3_IRQn, .pad=RTE_PWM3},
|
||||
// #endif
|
||||
#ifdef RTE_PWM4
|
||||
{.pwm_ch=4, .clockId=FCLK_TIMER4, .clockId_slect=FCLK_TIMER4_SEL_26M, .time_req=PXIC0_TIMER4_IRQn, .pad=RTE_PWM4},
|
||||
#endif
|
||||
// #ifdef RTE_PWM5
|
||||
// {.pwm_ch=5, .clockId=FCLK_TIMER5, .clockId_slect=FCLK_TIMER5_SEL_26M, .time_req=PXIC0_TIMER5_IRQn, .pad=RTE_PWM5},
|
||||
// #endif
|
||||
|
||||
// 以下为固定映射
|
||||
/*
|
||||
10 -- GPIO 01 -- PAD 16 ---> LCD_RST
|
||||
11 -- GPIO 02 -- PAD 17
|
||||
12 -- GPIO 16 -- PAD 31
|
||||
13 -- GPIO 17 -- PAD 32 xxx 不可用
|
||||
14 -- GPIO 18 -- PAD 33 ---> UART1_RX
|
||||
15 -- GPIO 19 -- PAD 34 ---> UART1_TX xxx 不可用
|
||||
*/
|
||||
{.pwm_ch=10, .clockId=FCLK_TIMER0, .clockId_slect=FCLK_TIMER0_SEL_26M, .time_req=PXIC0_TIMER0_IRQn, .pad=16},
|
||||
{.pwm_ch=11, .clockId=FCLK_TIMER1, .clockId_slect=FCLK_TIMER1_SEL_26M, .time_req=PXIC0_TIMER1_IRQn, .pad=17},
|
||||
{.pwm_ch=12, .clockId=FCLK_TIMER2, .clockId_slect=FCLK_TIMER2_SEL_26M, .time_req=PXIC0_TIMER2_IRQn, .pad=31},
|
||||
// {.pwm_ch=13, .clockId=FCLK_TIMER3, .clockId_slect=FCLK_TIMER3_SEL_26M, .time_req=PXIC0_TIMER3_IRQn, .pad=32},
|
||||
{.pwm_ch=14, .clockId=FCLK_TIMER4, .clockId_slect=FCLK_TIMER4_SEL_26M, .time_req=PXIC0_TIMER4_IRQn, .pad=33},
|
||||
// {.pwm_ch=15, .clockId=FCLK_TIMER5, .clockId_slect=FCLK_TIMER5_SEL_26M, .time_req=PXIC0_TIMER5_IRQn, .pad=34},
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
static pwm_ctx_t pwms[PWM_CH_MAX];
|
||||
|
||||
static int luat_pwm_mapid(int channel) {
|
||||
int map_id = -1;
|
||||
for (size_t i = 0; i < sizeof(maps) / sizeof(pwm_map_t); i++)
|
||||
{
|
||||
if (maps[i].pwm_ch == channel) {
|
||||
map_id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return map_id;
|
||||
}
|
||||
|
||||
PLAT_PA_RAMCODE static void Timer_ISR()
|
||||
{
|
||||
|
||||
volatile int i = 0;
|
||||
|
||||
// PWM 3/5 通道需要跳过, 其中 3 是 tick64, 5是CP占用了
|
||||
for(i = 0;i < 5;i++)
|
||||
{
|
||||
if (i == 3)
|
||||
continue;
|
||||
if (TIMER_getInterruptFlags(i) & TIMER_MATCH2_INTERRUPT_FLAG)
|
||||
{
|
||||
TIMER_clearInterruptFlags(i, TIMER_MATCH2_INTERRUPT_FLAG);
|
||||
g_s_pnum_update[i]++;
|
||||
if (g_s_pnum_update[i] >= g_s_pnum_set[i])
|
||||
{
|
||||
//luat_pwm_close(i);
|
||||
TIMER_updatePwmDutyCycle(i,0);
|
||||
//luat_pwm_update_dutycycle(i,0);
|
||||
TIMER_stop(i);
|
||||
//LUAT_DEBUG_PRINT("PWM STOP %d",g_s_pnum_update[i]);
|
||||
g_s_pnum_update[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int luat_pwm_open(int channel, size_t freq, size_t pulse, int pnum) {
|
||||
PadConfig_t config = {0};
|
||||
|
||||
int map_id = luat_pwm_mapid(channel);
|
||||
if (map_id == -1)
|
||||
return -1;
|
||||
|
||||
if (freq > MAX_FREQ)
|
||||
return -2;
|
||||
if (pulse > 100)
|
||||
pulse = 100;
|
||||
|
||||
if(if_initialized_timer(channel % 10) < 0)
|
||||
{
|
||||
return -4; // hardware timer is used
|
||||
}
|
||||
|
||||
// LUAT_DEBUG_PRINT("luat_pwm_open get timer_id %d",timer_id);
|
||||
PAD_getDefaultConfig(&config);
|
||||
config.mux = PAD_MUX_ALT5;
|
||||
|
||||
// 为支持复用, 只取低位
|
||||
channel = channel % 10;
|
||||
|
||||
g_s_pnum_set[channel] = pnum;
|
||||
PAD_setPinConfig(maps[map_id].pad, &config);
|
||||
|
||||
CLOCK_setClockSrc(maps[map_id].clockId, maps[map_id].clockId_slect);
|
||||
CLOCK_setClockDiv(maps[map_id].clockId, 1);
|
||||
TIMER_driverInit();
|
||||
|
||||
pwms[channel].timer_config.pwmFreq_HZ = freq;
|
||||
pwms[channel].timer_config.srcClock_HZ = GPR_getClockFreq(maps[map_id].clockId);
|
||||
pwms[channel].timer_config.dutyCyclePercent = pulse;
|
||||
TIMER_setupPwm(channel, &pwms[channel].timer_config);
|
||||
if(0 != pnum)
|
||||
{
|
||||
TIMER_interruptConfig(channel, TIMER_MATCH0_SELECT, TIMER_INTERRUPT_DISABLED);
|
||||
TIMER_interruptConfig(channel, TIMER_MATCH1_SELECT, TIMER_INTERRUPT_DISABLED);
|
||||
TIMER_interruptConfig(channel, TIMER_MATCH2_SELECT, TIMER_INTERRUPT_LEVEL);
|
||||
|
||||
XIC_SetVector(maps[map_id].time_req,Timer_ISR);
|
||||
XIC_EnableIRQ(maps[map_id].time_req);
|
||||
}
|
||||
|
||||
TIMER_start(channel);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pwm_update_dutycycle(int channel,size_t pulse)
|
||||
{
|
||||
int map_id = luat_pwm_mapid(channel);
|
||||
if (map_id == -1)
|
||||
return -1;
|
||||
channel = channel % 10;
|
||||
|
||||
pwms[channel].timer_config.dutyCyclePercent = pulse;
|
||||
TIMER_setupPwm(channel, &pwms[channel].timer_config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pwm_setup(luat_pwm_conf_t* conf)
|
||||
{
|
||||
int channel = conf->channel;
|
||||
int map_id = luat_pwm_mapid(channel);
|
||||
if (map_id == -1)
|
||||
return -1;
|
||||
if (conf->precision != 100) {
|
||||
// 当且仅支持100分辨率,等驱动重构完再改
|
||||
return -1;
|
||||
}
|
||||
channel = channel % 10;
|
||||
// 判断一下是否只修改了占空比. 当且仅当频率相同,pnum为0(即持续输出),才支持单独变更
|
||||
if (pwms[channel].timer_config.pwmFreq_HZ == conf->period && conf->pnum == 0) {
|
||||
if (conf->pulse != pwms[channel].timer_config.dutyCyclePercent) {
|
||||
pwms[channel].timer_config.dutyCyclePercent = conf->pulse;
|
||||
TIMER_updatePwmDutyCycle(conf->channel % 10, conf->pulse);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return luat_pwm_open(conf->channel,conf->period,conf->pulse,conf->pnum);
|
||||
}
|
||||
|
||||
int luat_pwm_capture(int channel,int freq)
|
||||
{
|
||||
int map_id = luat_pwm_mapid(channel);
|
||||
if (map_id == -1)
|
||||
return -1;
|
||||
return EIGEN_TIMER(channel % 10)->TMR[0];
|
||||
}
|
||||
|
||||
int luat_pwm_close(int channel)
|
||||
{
|
||||
int map_id = luat_pwm_mapid(channel);
|
||||
if (map_id == -1)
|
||||
return -1;
|
||||
luat_pwm_update_dutycycle(channel, 0);
|
||||
luat_rtos_task_sleep(1);
|
||||
TIMER_stop(channel % 10);
|
||||
pwms[channel % 10].timer_config.pwmFreq_HZ = 0; // 作为标志位
|
||||
g_s_pnum_update[channel % 10] = 0;
|
||||
g_s_pnum_set[channel % 10] = 0;
|
||||
// 恢复GPIO默认配置
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_rtc.h"
|
||||
#include "common_api.h"
|
||||
#include "time.h"
|
||||
#include "osasys.h"
|
||||
#include "luat_debug.h"
|
||||
static uint32_t g_s_local_tz = 32;
|
||||
int luat_rtc_set(struct tm *tblock){
|
||||
uint32_t Timer1 = (((tblock->tm_year+1900)<<16)&0xfff0000) | (((tblock->tm_mon+1)<<8)&0xff00) | ((tblock->tm_mday)&0xff);
|
||||
uint32_t Timer2 = ((tblock->tm_hour<<24)&0xff000000) | ((tblock->tm_min<<16)&0xff0000) | ((tblock->tm_sec<<8)&0xff00) | g_s_local_tz;
|
||||
uint32_t ret = OsaTimerSync(0, SET_LOCAL_TIME, Timer1, Timer2, 0);
|
||||
if (ret == 0){
|
||||
mwAonSetUtcTimeSyncFlag(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtc_get(struct tm *tblock){
|
||||
struct tm *t = gmtime(NULL);
|
||||
memcpy(tblock,t,sizeof(struct tm));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __LUATOS__
|
||||
|
||||
void luat_rtc_set_tamp32(uint32_t tamp) {
|
||||
Time_UserDataStruct Time;
|
||||
Date_UserDataStruct Date;
|
||||
Tamp2UTC(tamp, &Date, &Time, 0);
|
||||
if (OsaTimerSync(0,
|
||||
SET_LOCAL_TIME,
|
||||
((uint32_t)Date.Year<<16)|((uint32_t)Date.Mon<<8)|((uint32_t)Date.Day),
|
||||
((uint32_t)Time.Hour<<24)|((uint32_t)Time.Min<<16)|((uint32_t)Time.Sec<<8)|g_s_local_tz,0
|
||||
))
|
||||
{
|
||||
LUAT_DEBUG_PRINT("sync NITZ time fail");
|
||||
}
|
||||
else
|
||||
{
|
||||
mwAonSetUtcTimeSyncFlag(TRUE); //set to 1 when NITZ triggered
|
||||
}
|
||||
}
|
||||
|
||||
int luat_rtc_timer_start(int id, struct tm *tblock){
|
||||
return -1;
|
||||
}
|
||||
|
||||
int luat_rtc_timer_stop(int id){
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,433 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "luat_rtos.h"
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "semphr.h"
|
||||
#include "timers.h"
|
||||
#include "cmsis_os2.h"
|
||||
typedef struct
|
||||
{
|
||||
void *timer;
|
||||
luat_rtos_timer_callback_t call_back;
|
||||
void *user_param;
|
||||
uint8_t is_repeat;
|
||||
}luat_rtos_user_timer_t;
|
||||
|
||||
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)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
*task_handle = create_event_task(task_fun, user_data, stack_size, priority, event_cout, task_name);
|
||||
return (*task_handle)?0:-1;
|
||||
}
|
||||
|
||||
int luat_rtos_task_delete(luat_rtos_task_handle task_handle)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
delete_event_task(task_handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_task_suspend(luat_rtos_task_handle task_handle)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
vTaskSuspend(task_handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_task_resume(luat_rtos_task_handle task_handle)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
vTaskResume(task_handle);
|
||||
return 0;
|
||||
}
|
||||
uint32_t luat_rtos_task_get_high_water_mark(luat_rtos_task_handle task_handle)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
return uxTaskGetStackHighWaterMark(task_handle);
|
||||
}
|
||||
void luat_rtos_task_sleep(uint32_t ms)
|
||||
{
|
||||
vTaskDelay(ms);
|
||||
}
|
||||
|
||||
void luat_task_suspend_all(void)
|
||||
{
|
||||
vTaskSuspendAll();
|
||||
}
|
||||
void luat_task_resume_all(void)
|
||||
{
|
||||
xTaskResumeAll();
|
||||
}
|
||||
|
||||
void *luat_get_current_task(void)
|
||||
{
|
||||
return xTaskGetCurrentTaskHandle();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
return send_event_to_task(task_handle, NULL, id, param1, param2, param3, timeout);
|
||||
}
|
||||
|
||||
LUAT_RET luat_send_event_to_task(void *task_handle, uint32_t id, uint32_t param1, uint32_t param2, uint32_t param3)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
return send_event_to_task(task_handle, NULL, id, param1, param2, param3, LUAT_WAIT_FOREVER);
|
||||
}
|
||||
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)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
return get_event_from_task(task_handle, wait_event_id, (void *)out_event, call_back, ms);
|
||||
}
|
||||
|
||||
/**
|
||||
* 等同于luat_rtos_semaphore_create时init_count = 0
|
||||
*/
|
||||
void *luat_mutex_create(void)
|
||||
{
|
||||
SemaphoreHandle_t sem = xSemaphoreCreateBinary();
|
||||
if (sem)
|
||||
{
|
||||
xSemaphoreGive(sem);
|
||||
}
|
||||
return sem;
|
||||
}
|
||||
LUAT_RET luat_mutex_lock(void *mutex)
|
||||
{
|
||||
return luat_rtos_semaphore_take(mutex, LUAT_WAIT_FOREVER);
|
||||
}
|
||||
LUAT_RET luat_mutex_unlock(void *mutex)
|
||||
{
|
||||
return luat_rtos_semaphore_release(mutex);
|
||||
}
|
||||
void luat_mutex_release(void *mutex)
|
||||
{
|
||||
luat_rtos_semaphore_delete(mutex);
|
||||
}
|
||||
|
||||
int luat_rtos_semaphore_create(luat_rtos_semaphore_t *semaphore_handle, uint32_t init_count)
|
||||
{
|
||||
if (!semaphore_handle) return -1;
|
||||
SemaphoreHandle_t sem = NULL;
|
||||
if (init_count <= 1)
|
||||
{
|
||||
sem = xSemaphoreCreateBinary();
|
||||
if (!sem)
|
||||
return -1;
|
||||
if (!init_count)
|
||||
xSemaphoreGive(sem);
|
||||
}
|
||||
else
|
||||
{
|
||||
sem = xSemaphoreCreateCounting(init_count, init_count);
|
||||
if (!sem)
|
||||
return -1;
|
||||
}
|
||||
*semaphore_handle = (luat_rtos_semaphore_t)sem;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_semaphore_delete(luat_rtos_semaphore_t semaphore_handle)
|
||||
{
|
||||
if (!semaphore_handle) return -1;
|
||||
vSemaphoreDelete(semaphore_handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_semaphore_take(luat_rtos_semaphore_t semaphore_handle, uint32_t timeout)
|
||||
{
|
||||
if (!semaphore_handle) return -1;
|
||||
if (pdTRUE == xSemaphoreTake(semaphore_handle, timeout))
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int luat_rtos_semaphore_release(luat_rtos_semaphore_t semaphore_handle)
|
||||
{
|
||||
if (!semaphore_handle) return -1;
|
||||
if (osIsInISRContext())
|
||||
{
|
||||
BaseType_t yield = pdFALSE;
|
||||
if (pdTRUE == xSemaphoreGiveFromISR(semaphore_handle, &yield))
|
||||
{
|
||||
portYIELD_FROM_ISR(yield);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pdTRUE == xSemaphoreGive(semaphore_handle))
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int luat_rtos_mutex_create(luat_rtos_mutex_t *mutex_handle)
|
||||
{
|
||||
if (!mutex_handle) return -1;
|
||||
QueueHandle_t pxNewQueue = NULL;
|
||||
pxNewQueue = xSemaphoreCreateRecursiveMutex();
|
||||
if (!pxNewQueue)
|
||||
return -1;
|
||||
*mutex_handle = pxNewQueue;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_mutex_lock(luat_rtos_mutex_t mutex_handle, uint32_t timeout)
|
||||
{
|
||||
if (!mutex_handle) return -1;
|
||||
if (pdFALSE == xSemaphoreTakeRecursive(mutex_handle, timeout))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_mutex_unlock(luat_rtos_mutex_t mutex_handle)
|
||||
{
|
||||
if (!mutex_handle) return -1;
|
||||
if (pdFALSE == xSemaphoreGiveRecursive(mutex_handle))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_mutex_delete(luat_rtos_mutex_t mutex_handle)
|
||||
{
|
||||
if (!mutex_handle) return -1;
|
||||
vSemaphoreDelete(mutex_handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_queue_create(luat_rtos_queue_t *queue_handle, uint32_t item_count, uint32_t item_size)
|
||||
{
|
||||
if (!queue_handle) return -1;
|
||||
QueueHandle_t pxNewQueue;
|
||||
pxNewQueue = xQueueCreate(item_count, item_size);
|
||||
if (!pxNewQueue)
|
||||
return -1;
|
||||
*queue_handle = pxNewQueue;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_queue_delete(luat_rtos_queue_t queue_handle)
|
||||
{
|
||||
if (!queue_handle) return -1;
|
||||
vQueueDelete ((QueueHandle_t)queue_handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_queue_send(luat_rtos_queue_t queue_handle, void *item, uint32_t item_size, uint32_t timeout)
|
||||
{
|
||||
if (!queue_handle || !item) return -1;
|
||||
if (osIsInISRContext())
|
||||
{
|
||||
BaseType_t pxHigherPriorityTaskWoken;
|
||||
if (xQueueSendToBackFromISR(queue_handle, item, &pxHigherPriorityTaskWoken) != pdPASS)
|
||||
return -1;
|
||||
portYIELD_FROM_ISR(pxHigherPriorityTaskWoken);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xQueueSendToBack (queue_handle, item, timeout) != pdPASS)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_rtos_queue_recv(luat_rtos_queue_t queue_handle, void *item, uint32_t item_size, uint32_t timeout)
|
||||
{
|
||||
if (!queue_handle || !item)
|
||||
return -1;
|
||||
BaseType_t yield = pdFALSE;
|
||||
if (osIsInISRContext())
|
||||
{
|
||||
if (xQueueReceiveFromISR(queue_handle, item, &yield) != pdPASS)
|
||||
return -1;
|
||||
portYIELD_FROM_ISR(yield);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xQueueReceive(queue_handle, item, timeout) != pdPASS)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static void s_timer_callback(TimerHandle_t hTimer)
|
||||
{
|
||||
luat_rtos_user_timer_t *timer = (luat_rtos_user_timer_t *)pvTimerGetTimerID(hTimer);
|
||||
if (!timer)
|
||||
return;
|
||||
if (!timer->is_repeat)
|
||||
{
|
||||
xTimerStop(hTimer, 0);
|
||||
}
|
||||
if (timer->call_back)
|
||||
{
|
||||
timer->call_back(timer->user_param);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------- timer ----------------------------------- */
|
||||
void *luat_create_rtos_timer(void *cb, void *param, void *task_handle)
|
||||
{
|
||||
luat_rtos_user_timer_t *timer = malloc(sizeof(luat_rtos_user_timer_t));
|
||||
if (timer)
|
||||
{
|
||||
timer->timer = xTimerCreate(NULL, 1, 1, timer, s_timer_callback);
|
||||
if (!timer->timer)
|
||||
{
|
||||
free(timer);
|
||||
return NULL;
|
||||
}
|
||||
timer->call_back = cb;
|
||||
timer->user_param = param;
|
||||
timer->is_repeat = 0;
|
||||
}
|
||||
return timer;
|
||||
}
|
||||
int luat_start_rtos_timer(void *timer, uint32_t ms, uint8_t is_repeat)
|
||||
{
|
||||
luat_rtos_user_timer_t *htimer = (luat_rtos_user_timer_t *)timer;
|
||||
BaseType_t pxHigherPriorityTaskWoken;
|
||||
if (osIsInISRContext())
|
||||
{
|
||||
if ((xTimerStopFromISR(htimer->timer, &pxHigherPriorityTaskWoken) != pdPASS))
|
||||
return -1;
|
||||
htimer->is_repeat = is_repeat;
|
||||
if ((xTimerChangePeriodFromISR(htimer->timer, ms, &pxHigherPriorityTaskWoken) != pdPASS))
|
||||
return -1;
|
||||
portYIELD_FROM_ISR(pxHigherPriorityTaskWoken);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xTimerIsTimerActive (htimer->timer))
|
||||
{
|
||||
if (xTimerStop(htimer->timer, LUAT_WAIT_FOREVER) != pdPASS)
|
||||
return -1;
|
||||
}
|
||||
htimer->is_repeat = is_repeat;
|
||||
if (xTimerChangePeriod(htimer->timer, ms, LUAT_WAIT_FOREVER) != pdPASS)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void luat_stop_rtos_timer(void *timer)
|
||||
{
|
||||
luat_rtos_user_timer_t *htimer = (luat_rtos_user_timer_t *)timer;
|
||||
|
||||
if (osIsInISRContext())
|
||||
{
|
||||
BaseType_t pxHigherPriorityTaskWoken;
|
||||
if ((xTimerStopFromISR(htimer->timer, &pxHigherPriorityTaskWoken) != pdPASS))
|
||||
return ;
|
||||
portYIELD_FROM_ISR(pxHigherPriorityTaskWoken);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xTimerIsTimerActive (htimer->timer))
|
||||
{
|
||||
xTimerStop(htimer->timer, LUAT_WAIT_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void luat_release_rtos_timer(void *timer)
|
||||
{
|
||||
luat_rtos_user_timer_t *htimer = (luat_rtos_user_timer_t *)timer;
|
||||
xTimerDelete(htimer->timer, LUAT_WAIT_FOREVER);
|
||||
free(htimer);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if (!timer_handle) return -1;
|
||||
luat_rtos_user_timer_t *htimer = (luat_rtos_user_timer_t *)timer_handle;
|
||||
BaseType_t pxHigherPriorityTaskWoken;
|
||||
if (osIsInISRContext())
|
||||
{
|
||||
if ((xTimerStopFromISR(htimer->timer, &pxHigherPriorityTaskWoken) != pdPASS))
|
||||
return -1;
|
||||
htimer->is_repeat = repeat;
|
||||
htimer->call_back = callback_fun;
|
||||
htimer->user_param = user_param;
|
||||
if ((xTimerChangePeriodFromISR(htimer->timer, timeout, &pxHigherPriorityTaskWoken) != pdPASS))
|
||||
return -1;
|
||||
portYIELD_FROM_ISR(pxHigherPriorityTaskWoken);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xTimerIsTimerActive (htimer->timer))
|
||||
{
|
||||
if (xTimerStop(htimer->timer, LUAT_WAIT_FOREVER) != pdPASS)
|
||||
return -1;
|
||||
}
|
||||
htimer->is_repeat = repeat;
|
||||
htimer->call_back = callback_fun;
|
||||
htimer->user_param = user_param;
|
||||
if (xTimerChangePeriod(htimer->timer, timeout, LUAT_WAIT_FOREVER) != pdPASS)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int luat_rtos_timer_is_active(luat_rtos_timer_t timer_handle)
|
||||
{
|
||||
if (!timer_handle) return -1;
|
||||
luat_rtos_user_timer_t *htimer = (luat_rtos_user_timer_t *)timer_handle;
|
||||
if (pdTRUE == xTimerIsTimerActive (htimer->timer))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*------------------------------------------------ timer end----------------------------------------------- */
|
||||
|
||||
/* ------------------------------------------------ critical begin----------------------------------------------- */
|
||||
/**
|
||||
* @brief 进入临界保护
|
||||
*
|
||||
* @return uint32_t 退出临界保护所需参数
|
||||
*/
|
||||
uint32_t luat_rtos_entry_critical(void)
|
||||
{
|
||||
return OS_EnterCritical();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 退出临界保护
|
||||
*
|
||||
* @param critical 进入临界保护时返回的参数
|
||||
*/
|
||||
void luat_rtos_exit_critical(uint32_t critical)
|
||||
{
|
||||
OS_ExitCritical(critical);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_rtos.h"
|
||||
#include "luat_rtos_legacy.h"
|
||||
|
||||
LUAT_WEAK void luat_rtos_task_suspend_all(void)
|
||||
{
|
||||
luat_task_suspend_all();
|
||||
}
|
||||
LUAT_WEAK void luat_rtos_task_resume_all(void)
|
||||
{
|
||||
luat_task_resume_all();
|
||||
}
|
||||
|
||||
luat_rtos_task_handle luat_rtos_get_current_handle(void)
|
||||
{
|
||||
return luat_get_current_task();
|
||||
}
|
||||
|
||||
LUAT_WEAK 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)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
return luat_send_event_to_task(task_handle, id, param1, param2, param3);
|
||||
}
|
||||
LUAT_WEAK 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)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
return luat_wait_event_from_task(task_handle, wait_event_id, out_event, callback_fun, timeout);
|
||||
}
|
||||
LUAT_WEAK int luat_rtos_message_send(luat_rtos_task_handle task_handle, uint32_t message_id, void *p_message)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
return luat_send_event_to_task(task_handle, message_id, p_message, 0, 0);
|
||||
}
|
||||
LUAT_WEAK int luat_rtos_message_recv(luat_rtos_task_handle task_handle, uint32_t *message_id, void **p_p_message, uint32_t timeout)
|
||||
{
|
||||
if (!task_handle) return -1;
|
||||
luat_event_t event;
|
||||
int result = luat_wait_event_from_task(task_handle, 0, &event, 0, timeout);
|
||||
if (!result)
|
||||
{
|
||||
*message_id = event.id;
|
||||
*p_p_message = (void *)event.param1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
LUAT_WEAK int luat_rtos_timer_create(luat_rtos_timer_t *timer_handle)
|
||||
{
|
||||
if (!timer_handle) return -1;
|
||||
*timer_handle = luat_create_rtos_timer(NULL, NULL, NULL);
|
||||
return (*timer_handle)?0:-1;
|
||||
}
|
||||
|
||||
LUAT_WEAK int luat_rtos_timer_stop(luat_rtos_timer_t timer_handle)
|
||||
{
|
||||
if (!timer_handle) return -1;
|
||||
luat_stop_rtos_timer(timer_handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LUAT_WEAK int luat_rtos_timer_delete(luat_rtos_timer_t timer_handle)
|
||||
{
|
||||
if (!timer_handle) return -1;
|
||||
luat_release_rtos_timer(timer_handle);
|
||||
return 0;
|
||||
}
|
||||
1163
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/src/luat_sms_ec618.c
Normal file
1163
sdk/合宙/air780e/csdk/luatos-soc-2022/interface/src/luat_sms_ec618.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_spi.h"
|
||||
|
||||
#include "common_api.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "bsp_custom.h"
|
||||
#include "soc_spi.h"
|
||||
#include "driver_gpio.h"
|
||||
|
||||
static uint8_t g_s_luat_spi_mode[SPI_MAX] ={0};
|
||||
|
||||
static int spi_exist(int id) {
|
||||
if (id < SPI_MAX) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __LUATOS__
|
||||
int luat_spi_device_config(luat_spi_device_t* spi_dev) {
|
||||
if (!spi_exist(spi_dev->bus_id))
|
||||
return -1;
|
||||
uint8_t spi_mode = SPI_MODE_0;
|
||||
if(spi_dev->spi_config.CPHA&&spi_dev->spi_config.CPOL)spi_mode = SPI_MODE_3;
|
||||
else if(spi_dev->spi_config.CPOL)spi_mode = SPI_MODE_2;
|
||||
else if(spi_dev->spi_config.CPHA)spi_mode = SPI_MODE_1;
|
||||
SPI_SetNewConfig(spi_dev->bus_id, spi_dev->spi_config.bandrate, spi_mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_spi_bus_setup(luat_spi_device_t* spi_dev){
|
||||
if (!spi_exist(spi_dev->bus_id))
|
||||
return -1;
|
||||
uint8_t spi_mode = SPI_MODE_0;
|
||||
if(spi_dev->spi_config.CPHA&&spi_dev->spi_config.CPOL)spi_mode = SPI_MODE_3;
|
||||
else if(spi_dev->spi_config.CPOL)spi_mode = SPI_MODE_2;
|
||||
else if(spi_dev->spi_config.CPHA)spi_mode = SPI_MODE_1;
|
||||
if (spi_dev->bus_id)
|
||||
{
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_13, 0), 1, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_14, 0), 1, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_15, 0), 1, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_9, 0), 1, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_10, 0), 1, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_11, 0), 1, 0, 0);
|
||||
}
|
||||
g_s_luat_spi_mode[spi_dev->bus_id] = spi_dev->spi_config.mode;
|
||||
// LLOGD("SPI_MasterInit luat_bus_%d:%d dataw:%d spi_mode:%d bandrate:%d ",bus_id,luat_spi[bus_id].id, spi_dev->spi_config.dataw, spi_mode, spi_dev->spi_config.bandrate);
|
||||
SPI_MasterInit(spi_dev->bus_id, spi_dev->spi_config.dataw, spi_mode, spi_dev->spi_config.bandrate, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int luat_spi_setup(luat_spi_t* spi) {
|
||||
if (!spi_exist(spi->id))
|
||||
return -1;
|
||||
uint8_t spi_mode = SPI_MODE_0;
|
||||
if(spi->CPHA&&spi->CPOL)spi_mode = SPI_MODE_3;
|
||||
else if(spi->CPOL)spi_mode = SPI_MODE_2;
|
||||
else if(spi->CPHA)spi_mode = SPI_MODE_1;
|
||||
if (spi->id)
|
||||
{
|
||||
if (HAL_GPIO_12 == spi->cs)
|
||||
{
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_12, 0), 1, 0, 0);
|
||||
}
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_13, 0), 1, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_14, 0), 1, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_15, 0), 1, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (HAL_GPIO_8 == spi->cs)
|
||||
{
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_8, 0), 1, 0, 0);
|
||||
}
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_9, 0), 1, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_10, 0), 1, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_11, 0), 1, 0, 0);
|
||||
}
|
||||
g_s_luat_spi_mode[spi->id] = spi->mode;
|
||||
// LLOGD("SPI_MasterInit luat_spi%d:%d dataw:%d spi_mode:%d bandrate:%d ",spi_id,luat_spi[spi_id].id, spi->dataw, spi_mode, spi->bandrate);
|
||||
SPI_MasterInit(spi->id, spi->dataw, spi_mode, spi->bandrate, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//关闭SPI,成功返回0
|
||||
int luat_spi_close(int spi_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//收发SPI数据,返回接收字节数
|
||||
int luat_spi_transfer(int spi_id, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length) {
|
||||
if (!spi_exist(spi_id))
|
||||
return -1;
|
||||
if(g_s_luat_spi_mode[spi_id])
|
||||
{
|
||||
if (SPI_BlockTransfer(spi_id, send_buf, recv_buf, recv_length))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return recv_length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SPI_FlashBlockTransfer(spi_id, send_buf, send_length, recv_buf, recv_length))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return recv_length;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//收SPI数据,返回接收字节数
|
||||
int luat_spi_recv(int spi_id, char* recv_buf, size_t length) {
|
||||
if (!spi_exist(spi_id))
|
||||
return -1;
|
||||
if (SPI_BlockTransfer(spi_id, recv_buf, recv_buf, length))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return length;
|
||||
}
|
||||
}
|
||||
//发SPI数据,返回发送字节数
|
||||
int luat_spi_send(int spi_id, const char* send_buf, size_t length) {
|
||||
if (!spi_exist(spi_id))
|
||||
return -1;
|
||||
if (SPI_BlockTransfer(spi_id, send_buf, send_buf, length))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
||||
int luat_spi_no_block_transfer(int spi_id, uint8_t *tx_buff, uint8_t *rx_buff, size_t len, void *CB, void *pParam)
|
||||
{
|
||||
if (SPI_IsTransferBusy(spi_id)) return -1;
|
||||
SPI_SetCallbackFun(spi_id, CB, pParam);
|
||||
SPI_SetNoBlock(spi_id);
|
||||
return SPI_TransferEx(spi_id, tx_buff, rx_buff, len, 0, 1);
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_uart.h"
|
||||
#include "luat_rtos.h"
|
||||
|
||||
#ifdef __LUATOS__
|
||||
#include "luat_malloc.h"
|
||||
#include "luat_msgbus.h"
|
||||
#include "luat_timer.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bsp_custom.h"
|
||||
#include "bsp_common.h"
|
||||
#include "driver_gpio.h"
|
||||
#include "driver_uart.h"
|
||||
#define MAX_DEVICE_COUNT (UART_MAX+1)
|
||||
static luat_uart_ctrl_param_t uart_cb[MAX_DEVICE_COUNT]={0};
|
||||
static Buffer_Struct g_s_vuart_rx_buffer;
|
||||
static uint32_t g_s_vuart_rx_base_len;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
timer_t *rs485_timer;
|
||||
union
|
||||
{
|
||||
uint32_t rs485_param;
|
||||
struct
|
||||
{
|
||||
uint32_t wait_time:30;
|
||||
uint32_t rx_level:1;
|
||||
uint32_t is_485used:1;
|
||||
}rs485_param_bit;
|
||||
};
|
||||
uint16_t unused;
|
||||
uint8_t alt_type;
|
||||
uint8_t rs485_pin;
|
||||
}serials_info;
|
||||
|
||||
static serials_info g_s_serials[MAX_DEVICE_COUNT - 1] ={0};
|
||||
|
||||
#ifdef __LUATOS__
|
||||
static LUAT_RT_RET_TYPE luat_uart_wait_timer_cb(LUAT_RT_CB_PARAM)
|
||||
{
|
||||
uint32_t uartid = (uint32_t)param;
|
||||
if (g_s_serials[uartid].rs485_param_bit.is_485used) {
|
||||
GPIO_Output(g_s_serials[uartid].rs485_pin, g_s_serials[uartid].rs485_param_bit.rx_level);
|
||||
}
|
||||
uart_cb[uartid].sent_callback_fun(uartid, NULL);
|
||||
}
|
||||
|
||||
void luat_uart_recv_cb(int uart_id, uint32_t data_len){
|
||||
rtos_msg_t msg;
|
||||
msg.handler = l_uart_handler;
|
||||
msg.ptr = NULL;
|
||||
msg.arg1 = uart_id;
|
||||
msg.arg2 = data_len;
|
||||
int re = luat_msgbus_put(&msg, 0);
|
||||
}
|
||||
|
||||
void luat_uart_sent_cb(int uart_id, void *param){
|
||||
rtos_msg_t msg;
|
||||
msg.handler = l_uart_handler;
|
||||
msg.ptr = NULL;
|
||||
msg.arg1 = uart_id;
|
||||
msg.arg2 = 0;
|
||||
int re = luat_msgbus_put(&msg, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int luat_uart_pre_setup(int uart_id, uint8_t use_alt_type)
|
||||
{
|
||||
if (uart_id >= MAX_DEVICE_COUNT){
|
||||
return 0;
|
||||
}
|
||||
g_s_serials[uart_id].alt_type = use_alt_type;
|
||||
}
|
||||
|
||||
|
||||
void luat_uart_sent_dummy_cb(int uart_id, void *param) {;}
|
||||
void luat_uart_recv_dummy_cb(int uart_id, void *param) {;}
|
||||
|
||||
static int32_t luat_uart_cb(void *pData, void *pParam){
|
||||
uint32_t uartid = (uint32_t)pData;
|
||||
uint32_t State = (uint32_t)pParam;
|
||||
uint32_t len;
|
||||
// DBG("luat_uart_cb pData:%d pParam:%d ",uartid,State);
|
||||
switch (State){
|
||||
case UART_CB_TX_BUFFER_DONE:
|
||||
#ifdef __LUATOS__
|
||||
if (g_s_serials[uartid].rs485_param_bit.is_485used && g_s_serials[uartid].rs485_param_bit.wait_time)
|
||||
{
|
||||
luat_start_rtos_timer(g_s_serials[uartid].rs485_timer, g_s_serials[uartid].rs485_param_bit.wait_time, 0);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
uart_cb[uartid].sent_callback_fun(uartid, NULL);
|
||||
}
|
||||
break;
|
||||
case UART_CB_TX_ALL_DONE:
|
||||
#ifdef __LUATOS__
|
||||
if (g_s_serials[uartid].rs485_param_bit.is_485used) {
|
||||
GPIO_Output(g_s_serials[uartid].rs485_pin, g_s_serials[uartid].rs485_param_bit.rx_level);
|
||||
}
|
||||
#endif
|
||||
uart_cb[uartid].sent_callback_fun(uartid, NULL);
|
||||
break;
|
||||
case UART_CB_RX_BUFFER_FULL:
|
||||
//只有UART1可以唤醒
|
||||
#ifdef __LUATOS__
|
||||
if (UART_ID1 == uartid)
|
||||
{
|
||||
uart_cb[uartid].recv_callback_fun(uartid, 0xffffffff);
|
||||
}
|
||||
#else
|
||||
if (UART_ID1 == uartid)
|
||||
{
|
||||
uart_cb[uartid].recv_callback_fun(uartid, 0);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case UART_CB_RX_TIMEOUT:
|
||||
len = Uart_RxBufferRead(uartid, NULL, 0);
|
||||
uart_cb[uartid].recv_callback_fun(uartid, len);
|
||||
break;
|
||||
case UART_CB_RX_NEW:
|
||||
#if 0
|
||||
len = Uart_RxBufferRead(uartid, NULL, 0);
|
||||
uart_cb[uartid].recv_callback_fun(uartid, len);
|
||||
#endif
|
||||
break;
|
||||
case UART_CB_ERROR:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int luat_uart_setup(luat_uart_t* uart) {
|
||||
if (!luat_uart_exist(uart->id)) {
|
||||
DBG("uart.setup FAIL!!!");
|
||||
return -1;
|
||||
}
|
||||
if (uart->id >= MAX_DEVICE_COUNT){
|
||||
OS_ReInitBuffer(&g_s_vuart_rx_buffer, uart->bufsz?uart->bufsz:1024);
|
||||
g_s_vuart_rx_base_len = g_s_vuart_rx_buffer.MaxLen;
|
||||
return 0;
|
||||
}
|
||||
switch (uart->id)
|
||||
{
|
||||
case UART_ID0:
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_14, 0), 3, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_15, 0), 3, 0, 0);
|
||||
break;
|
||||
case UART_ID1:
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_18, 0), 1, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_19, 0), 1, 0, 0);
|
||||
break;
|
||||
case UART_ID2:
|
||||
// #ifdef __LUATOS__
|
||||
if (g_s_serials[UART_ID2].alt_type)
|
||||
{
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_12, 0), 5, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_13, 0), 5, 0, 0);
|
||||
}
|
||||
else
|
||||
// #endif
|
||||
{
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_10, 0), 3, 0, 0);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_11, 0), 3, 0, 0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
int parity = 0;
|
||||
if (uart->parity == 1)parity = UART_PARITY_ODD;
|
||||
else if (uart->parity == 2)parity = UART_PARITY_EVEN;
|
||||
int stop_bits = (uart->stop_bits)==1?UART_STOP_BIT1:UART_STOP_BIT2;
|
||||
{
|
||||
uart_cb[uart->id].recv_callback_fun = luat_uart_recv_dummy_cb;
|
||||
uart_cb[uart->id].sent_callback_fun = luat_uart_sent_dummy_cb;
|
||||
Uart_BaseInitEx(uart->id, uart->baud_rate, 1024, uart->bufsz?uart->bufsz:1024, (uart->data_bits), parity, stop_bits, luat_uart_cb);
|
||||
#ifdef __LUATOS__
|
||||
g_s_serials[uart->id].rs485_param_bit.is_485used = (uart->pin485 < HAL_GPIO_NONE)?1:0;
|
||||
g_s_serials[uart->id].rs485_pin = uart->pin485;
|
||||
g_s_serials[uart->id].rs485_param_bit.rx_level = uart->rx_level;
|
||||
g_s_serials[uart->id].rs485_param_bit.wait_time = uart->delay/1000;
|
||||
if (!g_s_serials[uart->id].rs485_timer) {
|
||||
g_s_serials[uart->id].rs485_timer = luat_create_rtos_timer(luat_uart_wait_timer_cb, uart->id, NULL);
|
||||
}
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(g_s_serials[uart->id].rs485_pin, 0), 0, 0, 0);
|
||||
GPIO_Config(g_s_serials[uart->id].rs485_pin, 0, g_s_serials[uart->id].rs485_param_bit.rx_level);
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_uart_write(int uartid, void* data, size_t length) {
|
||||
if (luat_uart_exist(uartid)) {
|
||||
if (uartid >= MAX_DEVICE_COUNT){
|
||||
usb_serial_output(4,data,length);
|
||||
}else{
|
||||
#ifdef __LUATOS__
|
||||
if (g_s_serials[uartid].rs485_param_bit.is_485used) GPIO_Output(g_s_serials[uartid].rs485_pin, !g_s_serials[uartid].rs485_param_bit.rx_level);
|
||||
#endif
|
||||
Uart_TxTaskSafe(uartid, data, length);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG("not such uart id=%ld", uartid);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_uart_read(int uartid, void* buffer, size_t len) {
|
||||
int rcount = 0;
|
||||
if (luat_uart_exist(uartid)) {
|
||||
|
||||
if (uartid >= MAX_DEVICE_COUNT){
|
||||
rcount = (g_s_vuart_rx_buffer.Pos > len)?len:g_s_vuart_rx_buffer.Pos;
|
||||
memcpy(buffer, g_s_vuart_rx_buffer.Data, rcount);
|
||||
OS_BufferRemove(&g_s_vuart_rx_buffer, rcount);
|
||||
if (!g_s_vuart_rx_buffer.Pos && g_s_vuart_rx_buffer.MaxLen > g_s_vuart_rx_base_len)
|
||||
{
|
||||
OS_ReInitBuffer(&g_s_vuart_rx_buffer, g_s_vuart_rx_base_len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rcount = Uart_RxBufferRead(uartid, (uint8_t *)buffer, len);
|
||||
}
|
||||
}
|
||||
return rcount;
|
||||
}
|
||||
int luat_uart_close(int uartid) {
|
||||
if (luat_uart_exist(uartid)) {
|
||||
if (uartid >= MAX_DEVICE_COUNT){
|
||||
OS_DeInitBuffer(&g_s_vuart_rx_buffer);
|
||||
return 0;
|
||||
}
|
||||
Uart_DeInit(uartid);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_uart_exist(int uartid) {
|
||||
// EC618仅支持 uart0,uart1,uart2
|
||||
// uart0是ulog的输出
|
||||
// uart1是支持下载,也是用户可用
|
||||
// uart2是用户可用的
|
||||
// if (uartid == 0 || uartid == 1 || uartid == 2) {
|
||||
// 暂时只支持UART1和UART2
|
||||
if (uartid >= LUAT_VUART_ID_0) uartid = MAX_DEVICE_COUNT - 1;
|
||||
return (uartid >= MAX_DEVICE_COUNT)?0:1;
|
||||
}
|
||||
|
||||
static void luat_usb_recv_cb(uint8_t channel, uint8_t *input, uint32_t len){
|
||||
if (input){
|
||||
|
||||
OS_BufferWrite(&g_s_vuart_rx_buffer, input, len);
|
||||
#ifdef __LUATOS__
|
||||
rtos_msg_t msg;
|
||||
msg.handler = l_uart_handler;
|
||||
msg.ptr = NULL;
|
||||
msg.arg1 = LUAT_VUART_ID_0;
|
||||
msg.arg2 = len;
|
||||
int re = luat_msgbus_put(&msg, 0);
|
||||
#endif
|
||||
if (uart_cb[UART_MAX].recv_callback_fun){
|
||||
uart_cb[UART_MAX].recv_callback_fun(LUAT_VUART_ID_0,len);
|
||||
}
|
||||
}else{
|
||||
switch(len){
|
||||
case 0:
|
||||
DBG("usb serial connected");
|
||||
break;
|
||||
default:
|
||||
DBG("usb serial disconnected");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int luat_setup_cb(int uartid, int received, int sent) {
|
||||
if (luat_uart_exist(uartid)) {
|
||||
#ifdef __LUATOS__
|
||||
if (uartid >= UART_MAX){
|
||||
set_usb_serial_input_callback(luat_usb_recv_cb);
|
||||
}else{
|
||||
if (received){
|
||||
uart_cb[uartid].recv_callback_fun = luat_uart_recv_cb;
|
||||
}
|
||||
|
||||
if (sent){
|
||||
uart_cb[uartid].sent_callback_fun = luat_uart_sent_cb;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_uart_ctrl(int uart_id, LUAT_UART_CTRL_CMD_E cmd, void* param){
|
||||
if (luat_uart_exist(uart_id)) {
|
||||
if (uart_id >= MAX_DEVICE_COUNT){
|
||||
uart_id = UART_MAX;
|
||||
set_usb_serial_input_callback(luat_usb_recv_cb);
|
||||
}
|
||||
if (cmd == LUAT_UART_SET_RECV_CALLBACK){
|
||||
uart_cb[uart_id].recv_callback_fun = param;
|
||||
}else if(cmd == LUAT_UART_SET_SENT_CALLBACK){
|
||||
uart_cb[uart_id].sent_callback_fun = param;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "wdt.h"
|
||||
#include "clock.h"
|
||||
#include "slpman.h"
|
||||
|
||||
int luat_wdt_setup(size_t timeout)
|
||||
{
|
||||
if(timeout < 1 || timeout > 60)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
GPR_setClockSrc(FCLK_WDG, FCLK_WDG_SEL_32K);
|
||||
GPR_setClockDiv(FCLK_WDG, timeout);
|
||||
|
||||
WdtConfig_t wdtConfig;
|
||||
wdtConfig.mode = WDT_INTERRUPT_RESET_MODE;
|
||||
wdtConfig.timeoutValue = 32768U;
|
||||
WDT_init(&wdtConfig);
|
||||
WDT_start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_wdt_set_timeout(size_t timeout)
|
||||
{
|
||||
if(timeout < 1 || timeout > 60)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
WDT_kick();
|
||||
WDT_stop();
|
||||
WDT_deInit();
|
||||
luat_wdt_setup(timeout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_wdt_feed(void)
|
||||
{
|
||||
WDT_kick();
|
||||
slpManAonWdtFeed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_wdt_close(void)
|
||||
{
|
||||
WDT_stop();
|
||||
WDT_deInit();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "luat_wifiscan.h"
|
||||
#include "common_api.h"
|
||||
#include "ps_lib_api.h"
|
||||
#include "luat_debug.h"
|
||||
|
||||
|
||||
int32_t luat_get_wifiscan_cell_info(luat_wifiscan_set_info_t * set_info,luat_wifisacn_get_info_t* get_info)
|
||||
{
|
||||
int32_t ret;
|
||||
if (set_info == NULL || get_info ==NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
SetWifiScanParams wifiscanreq;
|
||||
GetWifiScanInfo pWifiScanInfo;
|
||||
|
||||
wifiscanreq.maxTimeOut=set_info->maxTimeOut;
|
||||
wifiscanreq.round=set_info->round;
|
||||
wifiscanreq.maxBssidNum=set_info->maxBssidNum;
|
||||
wifiscanreq.scanTimeOut=set_info->scanTimeOut;
|
||||
wifiscanreq.wifiPriority=set_info->wifiPriority;
|
||||
ret=appGetWifiScanInfo(&wifiscanreq, &pWifiScanInfo);
|
||||
if (ret == 0)
|
||||
{
|
||||
|
||||
if (pWifiScanInfo.bssidNum >= LUAT_MAX_WIFI_BSSID_NUM)
|
||||
{
|
||||
get_info->bssidNum = LUAT_MAX_WIFI_BSSID_NUM;
|
||||
}
|
||||
else
|
||||
{
|
||||
get_info->bssidNum =pWifiScanInfo.bssidNum;
|
||||
}
|
||||
get_info->rsvd = pWifiScanInfo.rsvd;
|
||||
for (int i = 0; i < pWifiScanInfo.bssidNum; i++)
|
||||
{
|
||||
get_info->ssidHexLen[i] = pWifiScanInfo.ssidHexLen[i];
|
||||
for (int j = 0; j < pWifiScanInfo.ssidHexLen[i]; j++)
|
||||
{
|
||||
get_info->ssidHex[i][j] = pWifiScanInfo.ssidHex[i][j];
|
||||
}
|
||||
get_info->rssi[i] = pWifiScanInfo.rssi[i];
|
||||
get_info->channel[i] = pWifiScanInfo.channel[i];
|
||||
for (int n = 0; n < 6; n++)
|
||||
{
|
||||
get_info->bssid[i][n] = pWifiScanInfo.bssid[i][n];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
Reference in New Issue
Block a user