283 lines
7.0 KiB
C
283 lines
7.0 KiB
C
|
|
#ifndef _HAL_API_FILE_H
|
|
#define _HAL_API_FILE_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
#include <stddef.h>
|
|
#include <stdarg.h>
|
|
#include <stdint.h>
|
|
|
|
#include "hal_list.h"
|
|
#include "ql_log.h"
|
|
#include "build_macro.h"
|
|
|
|
|
|
typedef struct ringbuffer {
|
|
void *buffer;
|
|
int length;
|
|
int start;
|
|
int end;
|
|
void *mutex;
|
|
} ringbuffer;
|
|
|
|
//#define CHECK_FREE_STACK_SIZE
|
|
|
|
#define CHECK_FREE_STACK_INTER 10000
|
|
|
|
// 采样率和缓冲区配置
|
|
#define SAMPLE_RATE 16000
|
|
#define BUFFER_SAMPLES 480 // 30ms @ 16kHz
|
|
|
|
// 超时时间配置(毫秒)
|
|
#define VAD_NO_SOUND_TIMEOUT_MS 10000 // 1分钟无声音超时
|
|
#define VAD_SILENCE_TIMEOUT_MS 1000 // 1秒静音超时
|
|
#define RECORDING_MAX_TIME 10000
|
|
|
|
// 系统状态枚举
|
|
typedef enum {
|
|
STATE_IDLE = 0, // 空闲状态
|
|
STATE_RECORDING_WAIT_SOUND, // 录音中,等待首次声音
|
|
STATE_RECORDING_ACTIVE, // 录音活跃,正在输出数据
|
|
STATE_WAITING_COMMAND // 等待命令输入
|
|
} system_state_t;
|
|
|
|
// VAD状态枚举
|
|
typedef enum {
|
|
VAD_STATE_SILENCE = 0, // 静音/无语音
|
|
VAD_STATE_ACTIVE // 检测到语音
|
|
} vad_state_t;
|
|
|
|
//#define APP_BUILD_DEBUG
|
|
|
|
typedef enum {
|
|
HAL_ERR_NET_TCP_SOCKET_FAILED = -601, // TCP socket connect fail
|
|
HAL_ERR_NET_TCP_UNKNOWN_HOST = -602, // TCP unknown host (DNS fail)
|
|
HAL_ERR_NET_TCP_CONNECT = -603, // TCP/UDP socket connect fail
|
|
HAL_ERR_NET_TCP_READ_TIMEOUT = -604, // TCP read timeout
|
|
HAL_ERR_NET_TCP_WRITE_TIMEOUT = -605, // TCP write timeout
|
|
HAL_ERR_NET_TCP_READ_FAIL = -606, // TCP read error
|
|
HAL_ERR_NET_TCP_WRITE_FAIL = -607, // TCP write error
|
|
HAL_ERR_NET_TCP_PEER_SHUTDOWN = -608, // TCP server close connection
|
|
HAL_ERR_NET_TCP_NOTHING_TO_READ = -609, // TCP socket nothing to read
|
|
} hal_Return_Code;
|
|
|
|
#if 0
|
|
#undef printf
|
|
#define printf(...) RLOGD( __VA_ARGS__)
|
|
#endif
|
|
|
|
|
|
#ifndef LOG_TAG
|
|
#define LOG_TAG __FILE__
|
|
#endif
|
|
|
|
#ifndef LOG_NDEBUG
|
|
#define LOG_NDEBUG 1
|
|
#endif
|
|
|
|
#undef RLOGV
|
|
#undef RLOGD
|
|
#undef RLOGI
|
|
#undef RLOGW
|
|
#undef RLOGE
|
|
|
|
typedef enum rlog_LogPriority {
|
|
RLOG_LOG_UNKNOWN = 0,
|
|
RLOG_LOG_DEFAULT, /* only for SetMinPriority() */
|
|
RLOG_LOG_VERBOSE,
|
|
RLOG_LOG_DEBUG,
|
|
RLOG_LOG_INFO,
|
|
RLOG_LOG_WARN,
|
|
RLOG_LOG_ERROR,
|
|
RLOG_LOG_FATAL,
|
|
RLOG_LOG_SILENT,
|
|
} rlog_LogPriority;
|
|
|
|
|
|
#define RLOGV printf
|
|
#define RLOGD printf
|
|
#define RLOGI printf
|
|
#define RLOGW printf
|
|
#define RLOGE printf
|
|
|
|
#define LOG_W printf
|
|
#define LOG_I printf
|
|
#define LOG_E printf
|
|
#define LOG_D printf
|
|
|
|
#define WAIT_INFINITE ~0
|
|
|
|
typedef enum {
|
|
HAL_OS_TASK_PRIORITY_IDLE = -3, ///< priority: idle (lowest)
|
|
HAL_OS_TASK_PRIORITY_LOW = -2, ///< priority: low
|
|
HAL_OS_TASK_PRIORITY_BELOWNORMAL = -1, ///< priority: below normal
|
|
HAL_OS_TASK_PRIORITY_NORMAL = 0, ///< priority: normal (default)
|
|
HAL_OS_TASK_PRIORITY_ABOVENORMAL = 1, ///< priority: above normal
|
|
HAL_OS_TASK_PRIORITY_HIGH = 2, ///< priority: high
|
|
HAL_OS_TASK_PRIORITY_REALTIME = 3, ///< priority: realtime (highest)
|
|
HAL_OS_TASK_PRIORITY_ERROR = 0x84, ///< system cannot determine priority or thread has illegal priority
|
|
} hal_os_task_priority;
|
|
|
|
|
|
typedef enum {
|
|
HAL_FS_SEEK_SET=0, ///< 文件开头
|
|
HAL_FS_SEEK_CUR, ///< 当前位置
|
|
HAL_FS_SEEK_END ///< 文件结尾
|
|
} hal_fs_seek_type_e;
|
|
|
|
|
|
//////////////// os //////////////////////////////
|
|
|
|
int hal_os_init();
|
|
|
|
void *hal_os_malloc(uint32_t size);
|
|
|
|
void *hal_os_realloc(void *old, uint32_t size);
|
|
|
|
void hal_os_free(void *ptr);
|
|
|
|
int hal_os_get_localtime(char *buf);
|
|
int hal_os_set_localtime(char *buf);
|
|
|
|
int hal_os_set_time(char *buf);
|
|
|
|
int hal_os_get_boottime(char *buf);
|
|
|
|
int hal_os_set_time_sec(uint32_t sec);
|
|
|
|
uint32_t hal_os_get_rand();
|
|
|
|
int hal_os_set_timezone(int zone);
|
|
|
|
int hal_os_get_timezone(int *zone);
|
|
|
|
uint64_t hal_os_up_time_ms(void);
|
|
|
|
uint64_t hal_os_timestamp_ms(void);
|
|
|
|
int hal_os_log(char *tag, int level, const char *buf, int len);
|
|
|
|
int hal_os_get_hal_ver(char *buf);
|
|
int hal_os_get_build_model(char *buf);
|
|
int hal_os_get_build_ver(char *buf);
|
|
int hal_os_get_build_rev(char *buf);
|
|
int hal_os_get_build_time(char *buf);
|
|
|
|
void hal_os_task_sleep_ms(uint32_t ms);
|
|
|
|
void hal_os_delay_us(uint32_t us);
|
|
|
|
void *hal_os_semaphore_create(void);
|
|
|
|
int hal_os_semaphore_destroy(void **sem);
|
|
|
|
int hal_os_semaphore_get_cnt(void *sem, uint32_t *count);
|
|
|
|
int hal_os_semaphore_post(void *sem);
|
|
|
|
int hal_os_semaphore_post_once(void *sem);
|
|
|
|
int hal_os_semaphore_wait(void *sem, uint32_t timeout_ms);
|
|
|
|
void *hal_os_task_create(char *name, uint8_t priority, uint32_t stackSize, void (*work_cb)(void *), void *arg);
|
|
|
|
int hal_os_task_destroy(void **thread);
|
|
|
|
|
|
void *hal_os_timer_create(void (*timer_cb)(void *), void *arg, uint8_t timer_type);
|
|
|
|
|
|
int hal_os_timer_start(void *timer, uint32_t timeMs);
|
|
|
|
int hal_os_timer_stop(void *timer);
|
|
|
|
|
|
int hal_os_timer_destroy(void **timer);
|
|
|
|
|
|
void *hal_os_mutex_create(void);
|
|
|
|
int hal_os_mutex_destroy(void **mutex);
|
|
|
|
int hal_os_mutex_lock(void *mutex);
|
|
|
|
int hal_os_mutex_unlock(void *mutex);
|
|
|
|
void *hal_os_queue_create(uint16_t cnt, uint16_t size);
|
|
|
|
|
|
int hal_os_queue_send(void *queue, void *buf, uint16_t buf_len, uint32_t timeout);
|
|
int hal_os_queue_send_front(void *queue, void *buf, uint16_t buf_len, uint32_t timeout);
|
|
int hal_os_queue_recv(void *queue, void *buf, uint16_t buf_len, uint32_t timeout);
|
|
int hal_os_queue_get_cnt(void *queue);
|
|
|
|
int hal_os_queue_destroy(void** queue);
|
|
|
|
void *hal_os_rb_create(int len);
|
|
|
|
int hal_os_rb_destroy(void *rbx);
|
|
|
|
int hal_os_rb_write(void *rbx, const void *buf, int len, uint32_t timeout);
|
|
|
|
int hal_os_rb_read(void*rbx, void *buf, int len, uint32_t timeout);
|
|
|
|
int hal_os_rb_clean(void*rbx);
|
|
|
|
int rb_get_space_used(struct ringbuffer *rb);
|
|
int hal_os_feed_dog();
|
|
|
|
int hal_os_set_device_id(char *sn);
|
|
int hal_os_get_device_id(char *sn);
|
|
|
|
|
|
int hal_os_reboot(char mode);
|
|
|
|
int hal_os_fota(char *path);
|
|
|
|
int hal_kv_set(char *key, void *val, int len);
|
|
int hal_kv_get(char *key, void *val, int len);
|
|
int hal_kv_del(char *key);
|
|
|
|
|
|
int hal_bt_open(void);
|
|
int hal_bt_status(void);
|
|
int32_t hal_bt_write(unsigned char *buf, uint32_t len, uint32_t timeout_ms);
|
|
int32_t hal_bt_read(unsigned char *buf, uint32_t len, uint32_t timeout_ms);
|
|
int hal_bt_close();
|
|
|
|
int hal_wifi_open();
|
|
|
|
//type = 1 sta. type=0 ap
|
|
int hal_wifi_cfg(int type, char *ssid, char *key);
|
|
|
|
int hal_os_get_model(char *model);
|
|
|
|
|
|
|
|
int hal_http_client_post(char *url, char *header, char *send, int send_len, char *recvbuf, int *recvlen);
|
|
|
|
int hal_http_client_get(char *url, char *recvbuf, int *recvlen);
|
|
|
|
|
|
int hal_audio_player_by_path(char *path);
|
|
|
|
|
|
int hal_http_client_download(char *url, char *file_path);
|
|
|
|
|
|
void * hal_dev_uart_open(uint8_t portno, char* configbuf);
|
|
int hal_dev_uart_config(void *uart, char* configbuf);
|
|
int32_t hal_dev_uart_write(void *uart, unsigned char *buf, uint32_t len, uint32_t timeout_ms);
|
|
int32_t hal_dev_uart_read(void *uart, unsigned char *buf, uint32_t len, uint32_t timeout_ms);
|
|
int hal_dev_uart_close(void *uart);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif |