rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,170 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_ALINK_H
#define AOS_ALINK_H
#ifdef __cplusplus
extern "C"
{
#endif
enum ALINK_LOG_LEVEL {
ALINK_LL_NONE, /* disable log */
ALINK_LL_FATAL, /* fatal error log will output */
ALINK_LL_ERROR, /* error + fatal log will output */
ALINK_LL_WARN, /* warn + error + fatal log will output(default level) */
ALINK_LL_INFO, /* info + warn + error + fatal log will output */
ALINK_LL_DEBUG, /* debug + info + warn + error + fatal log will output */
ALINK_LL_TRACE, /* trace + debug + info + warn + error + fatal will output */
};
/**
* Log level control
*
* @param[in] loglevel ALINK_LOG_LEVEL
*/
void alink_set_loglevel(enum ALINK_LOG_LEVEL loglevel);
/**
* Enable sandbox mode, for debug
*
* @return 0 on success, otherwise -1 will return
*/
int alink_enable_sandbox_mode(void);
/**
* Enable daily mode, for debug
*
* @param[in] server_ip IP Addr
* @param[in] port server port
*
* @return 0 on success, otherwise -1 will return
*/
int alink_enable_daily_mode(const char *server_ip, int port);
/**
* Entry function. start alink gateway service.
*
* @return 0 on success, otherwise -1 will return
*/
int alink_start(void);
#define ALINK_WAIT_FOREVER (0)
/**
* Waiting alink connect to aliyun server
*
* @param[in] timeout_ms time in milliseconds, use ALINK_WAIT_FOREVER to wait until server is connected
*
* @return 0 when connect to server successfully, otherwise -1 will return
*/
int alink_wait_connect(int timeout_ms);
/**
* Destroy alink service and free resources
*
* @note this func will block at most 15 seconds to stop all alink related process(thread)
*
* @return 0 on success, otherwise -1 will return
*/
int alink_end(void);
/**
* Reset user account binding.
*
* @return 0 on success, -1 when params invalid
*/
int alink_factory_reset(void);
/**
* Report alink message, it is a fundamental func.
*
* @note when connection with server is unstable, this func will block until got response from server or timeout.
*
* @param[in] method alink protocol method, i.e. "postDeviceRawData", "retrieveDeviceData".
* @param[in] json_buffer json format buffer, like {"OnOff":"1", "Light":"80"}.
*
* @return 0 when successfully got response from cloud,
* otherwise this func will block until timeout and -1 will return
*/
int alink_report(const char *method, const char *json_buffer);
int alink_report_async(const char *method, const char *json_buffer,
void *(*cb)(void *), void *arg);
int alink_report_rawdata(const char *rawdata, int len);
enum ALINK_WIFI_CALLBACK {
/*
* void callback_cloud_connected(void)
* @n@n called each time when gateway successfully connect(or reconnect)
* to aliyun server
*/
ALINK_CLOUD_CONNECTED = 0,
/*
* void callback_cloud_disconnected(void)
* @n@n called each time when gateway lose connection with aliyun server
*/
ALINK_CLOUD_DISCONNECTED,
/*
* int callback_read_device_status(const char *params)
* @n@nuccessfully
*/
ALINK_GET_DEVICE_STATUS,
/*
* void callback_write_device_status(const char *params)
*/
ALINK_SET_DEVICE_STATUS,
/*
* int callback_read_device_rawdata(const char *params)
* @n@nuccessfully
*/
ALINK_GET_DEVICE_RAWDATA,
/*
* void callback_write_device_rawdata(const char *params)
*/
ALINK_SET_DEVICE_RAWDATA,
};
int awss_register_callback(unsigned char cb_type, void *cb_func);
/**
* Register misc callback
*
* @param[in] cb_type callback type.
* @param[in] cb_func callback func pointer, func declaration see related comments.
*
* @return 0 on success, otherwise -1 will return
*/
int alink_register_callback(unsigned char cb_type, void *cb_func);
/**
* Start awss service, block method, block until awss succeed, or timeout(see Note).
*
* @note platform_awss_get_timeout_interval_ms() return monitor timeout interval,
* AP connection timeout is 30s.
*
* @return 0 on success, otherwise non-zero value will return
* = 0: connect AP & DHCP success
* = -1: get ssid & passwd fail
* = -2: connect AP / DHCP fail
*/
int awss_start(void);
/**
* Calling this func force awss_start exit.
*
* @return 0 on success, otherwise -1 will return
*/
int awss_stop(void);
#ifdef __cplusplus
}
#endif
#endif /* AOS_ALINK_H */

View file

@ -0,0 +1,62 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_AOS_H
#define AOS_AOS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <aos/types.h>
#include <aos/cli.h>
#include <aos/cloud.h>
#include <aos/debug.h>
#include <aos/kernel.h>
#include <aos/kv.h>
#include <aos/list.h>
#include <aos/log.h>
#include <aos/vfs.h>
#include <aos/version.h>
#include <aos/yloop.h>
#include <aos/errno.h>
#include <aos/init.h>
/*
#include <aos/alink.h>
#include <aos/network.h>
*/
/**
* Transmit data on a UART interface
*
* @param data pointer to the start of data
* @param size number of bytes to transmit
* @param timeout time to wait
*
* @return 0 success, EIO if an error occurred with any step
*/
int32_t aos_uart_send(void *data, uint32_t size, uint32_t timeout);
/**
* Recv data on a UART interface
*
* @param data pointer to the start of recv buf
* @param expect_size number of bytes expect to recv
* @param recv_size number of bytes trully received
* @param timeout time to wait
*
* @return 0 success, EIO if an error occurred with any step
*/
int32_t aos_uart_recv(void *data, uint32_t expect_size, uint32_t *recv_size, uint32_t timeout);
#ifdef __cplusplus
}
#endif
#endif /* AOS_AOS_H */

View file

@ -0,0 +1,195 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_CLI_H
#define AOS_CLI_H
#ifndef AOS_CLI_MINI_SIZE
#define AOS_CLI_MINI_SIZE 0
#endif
#if(AOS_CLI_MINI_SIZE > 0)
/*can config to cut mem size*/
#define INBUF_SIZE 256
#define OUTBUF_SIZE 200 /*not use now*/
#define MAX_COMMANDS 32
#define CLI_MAX_ARG_NUM 8
#define CLI_MAX_ONCECMD_NUM 1
#else
/*can config to cut mem size*/
#define MAX_COMMANDS 64
#define INBUF_SIZE 256
#define OUTBUF_SIZE 2048
#define CLI_MAX_ARG_NUM 16
#define CLI_MAX_ONCECMD_NUM 6
#endif
#ifndef FUNCPTR
typedef void (*FUNCPTR)(void);
#endif
/* Structure for registering CLI commands */
struct cli_command {
const char *name;
const char *help;
void (*function)(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv);
};
struct cli_st {
int initialized;
int echo_disabled;
const struct cli_command *commands[MAX_COMMANDS];
unsigned int num_commands;
unsigned int bp; /* buffer pointer */
char inbuf[INBUF_SIZE];
char *outbuf;
#if(AOS_CLI_MINI_SIZE <= 0)
int his_idx;
int his_cur;
char history[INBUF_SIZE];
#endif
};
#define CLI_ARGS char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv
#ifdef CONFIG_AOS_CLI
#define cmd_printf(...) \
do { \
if (xWriteBufferLen > 0) { \
snprintf(pcWriteBuffer, xWriteBufferLen, __VA_ARGS__); \
xWriteBufferLen-= os_strlen(pcWriteBuffer); \
pcWriteBuffer+= os_strlen(pcWriteBuffer); \
} \
} while(0)
/**
* This function registers a command with the command-line interface.
*
* @param[in] command The structure to register one CLI command
*
* @return 0 on success, error code otherwise.
*/
int aos_cli_register_command(const struct cli_command *command);
/**
* This function unregisters a command from the command-line interface.
*
* @param[in] command The structure to unregister one CLI command
*
* @return 0 on success, error code otherwise.
*/
int aos_cli_unregister_command(const struct cli_command *command);
/**
* Register a batch of CLI commands
* Often, a module will want to register several commands.
*
* @param[in] commands Pointer to an array of commands.
* @param[in] num_commands Number of commands in the array.
*
* @return 0 on success error code otherwise.
*/
int aos_cli_register_commands(const struct cli_command *commands, int num_commands);
/**
* Unregister a batch of CLI commands
*
* @param[in] commands Pointer to an array of commands.
* @param[in] num_commands Number of commands in the array.
*
* @return 0 on success, error code otherwise.
*/
int aos_cli_unregister_commands(const struct cli_command *commands, int num_commands);
/**
* Print CLI msg
*
* @param[in] buff Pointer to a char * buffer.
*
* @return 0 on success, error code otherwise.
*/
#if defined BUILD_BIN || defined BUILD_KERNEL
/* SINGLEBIN or KERNEL */
int aos_cli_printf(const char *buff, ...);
#else
/* FRAMWORK or APP */
#define aos_cli_printf(fmt, ...) csp_printf("%s" fmt, aos_cli_get_tag(), ##__VA_ARGS__)
#endif
/**
* CLI initial function
*
* @return 0 on success, error code otherwise
*/
int aos_cli_init(void);
/**
* Stop the CLI thread and carry out the cleanup
*
* @return 0 on success, error code otherwise.
*
*/
int aos_cli_stop(void);
/**
* CLI get tag string
*
* @return cli tag storing buffer
*/
const char *aos_cli_get_tag(void);
#else /* CONFIG_AOS_CLI */
#include "k_types.h"
#define cmd_printf(...) do {} while(0)
RHINO_INLINE int aos_cli_register_command(const struct cli_command *command)
{
return 0;
}
RHINO_INLINE int aos_cli_unregister_command(const struct cli_command *command)
{
return 0;
}
RHINO_INLINE int aos_cli_register_commands(const struct cli_command *commands,
int num_commands)
{
return 0;
}
RHINO_INLINE int aos_cli_unregister_commands(const struct cli_command *commands,
int num_commands)
{
return 0;
}
#define aos_cli_printf csp_printf
RHINO_INLINE int aos_cli_init(void)
{
return 0;
}
RHINO_INLINE int aos_cli_stop(void)
{
return 0;
}
#endif
#endif /* AOS_CLI_H */

View file

@ -0,0 +1,65 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_CLOUD_H
#define AOS_CLOUD_H
enum {
CLOUD_CONNECTED,
CLOUD_DISCONNECTED,
GET_DEVICE_STATUS,
SET_DEVICE_STATUS,
GET_DEVICE_RAWDATA,
SET_DEVICE_RAWDATA,
UPGRADE_DEVICE,
CANCEL_UPGRADE_DEVICE,
GET_SUB_DEVICE_STATUS,
SET_SUB_DEVICE_STATUS,
MAX_EVENT_TYPE,
};
typedef void (*aos_cloud_cb_t)(int event, const char *json_buffer);
/**
* Register cloud event callback.
*
* @param[in] cb_type event type interested.
* @param[in] cb cloud event callback.
*
* @return the operation status, 0 is OK, others is error.
*/
int aos_cloud_register_callback(int cb_type, aos_cloud_cb_t cb);
/**
* Report event to cloud.
*
* @param[in] method remote method name.
* @param[in] json_buffer method's payload.
* @param[in] done_cb report done callback.
* @param[in] arg private data passed to done_cb.
*
* @return the operation status, 0 is OK, others is error.
*/
int aos_cloud_report(const char *method,
const char *json_buffer,
void (*done_cb)(void *),
void *arg);
/**
* Trigger specific event, used by Cloud Backend.
*
* @param[in] cb_type event type.
* @param[in] json_buffer payload.
*/
void aos_cloud_trigger(int cb_type, const char *json_buffer);
/**
* Register Cloud Backend.
*
* @param[in] report called when user do aos_cloud_report.
*/
void aos_cloud_register_backend(int (*report)(const char *method, const char *json_buffer));
#endif /* AOS_CLOUD_H */

View file

@ -0,0 +1,301 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_DEBUG_H
#define AOS_DEBUG_H
#ifdef __cplusplus
extern "C" {
#endif
#define SHORT_FILE __FILENAME__
#define debug_print_assert(A,B,C,D,E,F)
#if (!defined(unlikely))
#define unlikely(EXPRESSSION) !!(EXPRESSSION)
#endif
/*
* Check that an expression is true (non-zero).
* If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
* function name, etc.) using the default debugging output method.
*
* @param[in] X expression to be evaluated.
*/
#if (!defined(check))
#define check(X) \
do { \
if (unlikely(!(X))) { \
debug_print_assert(0, #X, NULL, SHORT_FILE, __LINE__, __PRETTY_FUNCTION__); \
} \
} while(1 == 0)
#endif
/*
* Check that an expression is true (non-zero) with an explanation.
* If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
* function name, etc.) using the default debugging output method.
*
* @param[in] X expression to be evaluated.
* @param[in] STR If the expression evaluate to false, custom string to print.
*/
#if (!defined(check_string))
#define check_string(X, STR) \
do { \
if (unlikely(!(X))) { \
debug_print_assert(0, #X, STR, SHORT_FILE, __LINE__, __PRETTY_FUNCTION__); \
AOS_ASSERTION_FAIL_ACTION(); \
} \
} while(1 == 0)
#endif
/*
* Requires that an expression evaluate to true.
* If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
* function name, etc.) using the default debugging output method then jumps to a label.
*
* @param[in] X expression to be evalulated.
* @param[in] LABEL if expression evaluate to false,jumps to the LABEL.
*/
#if (!defined(require))
#define require(X, LABEL) \
do { \
if (unlikely(!(X))) { \
debug_print_assert( 0, #X, NULL, SHORT_FILE, __LINE__, __PRETTY_FUNCTION__ ); \
goto LABEL; \
} \
} while(1 == 0)
#endif
/*
* Requires that an expression evaluate to true with an explanation.
* If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
* function name, etc.) and a custom explanation string using the default debugging output method then jumps to a label.
*
* @param[in] X expression to be evalulated.
* @param[in] LABEL if expression evaluate to false,jumps to the LABEL.
* @param[in] STR if expression evaluate to false,custom explanation string to print.
*/
#if (!defined(require_string))
#define require_string(X, LABEL, STR) \
do { \
if (unlikely(!(X))) { \
debug_print_assert(0, #X, STR, SHORT_FILE, __LINE__, __PRETTY_FUNCTION__); \
goto LABEL; \
} \
} while(1 == 0)
#endif
/*
* Requires that an expression evaluate to true.
* If expression evalulates to false, this jumps to a label. No debugging information is printed.
*
* @param[in] X expression to be evalulated
* @param[in] LABEL if expression evaluate to false,jumps to the LABEL.
*/
#if (!defined(require_quiet))
#define require_quiet(X, LABEL) \
do { \
if (unlikely(!(X))) { \
goto LABEL; \
} \
} while(1 == 0)
#endif
/*
* Require that an error code is noErr (0).
* If the error code is non-0, this prints debugging information (actual expression string, file, line number,
* function name, etc.) using the default debugging output method then jumps to a label.
*
* @param[in] ERR error to be evaluated
* @param[in] LABEL If the error code is non-0,jumps to the LABEL.
*/
#if (!defined(require_noerr))
#define require_noerr(ERR, LABEL) \
do { \
int localErr; \
\
localErr = (int)(ERR); \
if (unlikely(localErr != 0)) { \
debug_print_assert(localErr, NULL, NULL, SHORT_FILE, __LINE__, __PRETTY_FUNCTION__); \
goto LABEL; \
} \
\
} while(1 == 0)
#endif
/*
* Require that an error code is noErr (0) with an explanation.
* If the error code is non-0, this prints debugging information (actual expression string, file, line number,
* function name, etc.), and a custom explanation string using the default debugging output method using the
* default debugging output method then jumps to a label.
*
* @param[in] ERR error to be evaluated
* @param[in] LABEL If the error code is non-0, jumps to the LABEL.
* @param[in] STR If the error code is non-0, custom explanation string to print
*/
#if (!defined(require_noerr_string))
#define require_noerr_string(ERR, LABEL, STR) \
do { \
int localErr; \
\
localErr = (int)(ERR); \
if (unlikely(localErr != 0)) { \
debug_print_assert(localErr, NULL, STR, SHORT_FILE, __LINE__, __PRETTY_FUNCTION__); \
goto LABEL; \
} \
} while(1 == 0)
#endif
/*
* Require that an error code is noErr (0) with an explanation and action to execute otherwise.
* If the error code is non-0, this prints debugging information (actual expression string, file, line number,
* function name, etc.), and a custom explanation string using the default debugging output method using the
* default debugging output method then executes an action and jumps to a label.
*
* @param[in] ERR error to be evaluated.
* @param[in] LABEL If the error code is non-0, jumps to the LABEL.
* @param[in] ACTION If the error code is non-0, custom code to executes.
* @param[in] STR If the error code is non-0, custom explanation string to print.
*/
#if (!defined(require_noerr_action_string))
#define require_noerr_action_string(ERR, LABEL, ACTION, STR) \
do { \
int localErr; \
\
localErr = (int)(ERR); \
if (unlikely(localErr != 0)) { \
debug_print_assert(localErr, NULL, STR, SHORT_FILE, __LINE__, __PRETTY_FUNCTION__); \
{ ACTION; } \
goto LABEL; \
} \
} while(1 == 0)
#endif
/*
* Require that an error code is noErr (0).
* If the error code is non-0, this jumps to a label. No debugging information is printed.
*
* @param[in] ERR error to be evaluated.
* @param[in] LABEL If the error code is non-0, jumps to the LABEL.
*/
#if (!defined(require_noerr_quiet))
#define require_noerr_quiet(ERR, LABEL) \
do { \
if (unlikely((ERR) != 0)) { \
goto LABEL; \
} \
} while(1 == 0)
#endif
/*
* Require that an error code is noErr (0) with an action to execute otherwise.
* If the error code is non-0, this prints debugging information (actual expression string, file, line number,
* function name, etc.) using the default debugging output method then executes an action and jumps to a label.
*
* @param[in] ERR error to be evaluated.
* @param[in] LABEL If the error code is non-0, jumps to the LABEL.
* @param[in] ACTION If the error code is non-0, custom code to executes.
*/
#if (!defined(require_noerr_action))
#define require_noerr_action(ERR, LABEL, ACTION) \
do { \
int localErr; \
\
localErr = (int)(ERR); \
if (unlikely(localErr != 0)) { \
debug_print_assert(localErr, NULL, NULL, SHORT_FILE, __LINE__, __PRETTY_FUNCTION__); \
{ ACTION; } \
goto LABEL; \
} \
} while(1 == 0)
#endif
/*
* Require that an error code is noErr (0) with an action to execute otherwise.
* If the error code is non-0, this executes an action and jumps to a label. No debugging information is printed.
*
* @param[in] ERR error to be evaluated.
* @param[in] LABEL If the error code is non-0, jumps to the LABEL.
* @param[in] ACTION If the error code is non-0, custom code to executes.
*/
#if (!defined(require_noerr_action_quiet))
#define require_noerr_action_quiet(ERR, LABEL, ACTION) \
do { \
if (unlikely((ERR) != 0)) { \
{ ACTION; } \
goto LABEL; \
} \
} while(1 == 0)
#endif
/*
* Requires that an expression evaluate to true with an action to execute otherwise.
* If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
* function name, etc.) using the default debugging output method then executes an action and jumps to a label.
*
* @param[in] X expression to be evaluated.
* @param[in] LABEL If the expression evaluate to false, jumps to the LABEL.
* @param[in] ACTION If the expression evaluate to false, custom code to executes.
*/
#if (!defined(require_action))
#define require_action(X, LABEL, ACTION) \
do { \
if (unlikely(!(X))) { \
debug_print_assert(0, #X, NULL, SHORT_FILE, __LINE__, __PRETTY_FUNCTION__); \
{ ACTION; } \
goto LABEL; \
} \
} while (1 == 0)
#endif
/*
* Requires that an expression evaluate to true with an explanation and action to execute otherwise.
* If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
* function name, etc.) and a custom explanation string using the default debugging output method then executes an
* action and jumps to a label.
*
* @param[in] X expression to be evaluated.
* @param[in] LABEL If the expression evaluate to false, jumps to the LABEL.
* @param[in] ACTION If the expression evaluate to false, custom code to executes.
* @param[in] STR If the expression evaluate to false, custom string to print.
*/
#if (!defined(require_action_string))
#define require_action_string(X, LABEL, ACTION, STR) \
do { \
if (unlikely(!(X))) { \
debug_print_assert(0, #X, STR, SHORT_FILE, __LINE__, __PRETTY_FUNCTION__); \
{ ACTION; } \
goto LABEL; \
} \
} while (1 == 0)
#endif
/*
* Requires that an expression evaluate to true with an action to execute otherwise.
* If expression evalulates to false, this executes an action and jumps to a label.
* No debugging information is printed.
*
* @param[in] X expression to be evaluated.
* @param[in] LABEL If the expression evaluate to false, jumps to the LABEL.
* @param[in] ACTION If the expression evaluate to false, custom code to executes.
*/
#if (!defined(require_action_quiet))
#define require_action_quiet(X, LABEL, ACTION) \
do { \
if (unlikely(!(X))) { \
{ ACTION; } \
goto LABEL; \
} \
\
} while(1 == 0)
#endif
#ifdef __cplusplus
}
#endif
#endif /* AOS_DEBUG_H */

View file

@ -0,0 +1,207 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_ERRNO_H
#define AOS_ERRNO_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined (__GNUC__)&&!defined(__CC_ARM)
#include <errno.h>
#else
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Arg list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#ifdef ENOMEM
#undef ENOMEM
#endif
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#ifdef EINVAL
#undef EINVAL
#endif
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#ifdef EDOM
#undef EDOM
#define EDOM 33 /* Math argument out of domain of func */
#endif
#ifdef ERANGE
#undef ERANGE
#define ERANGE 34 /* Math result not representable */
#endif
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#ifdef EILSEQ
#undef EILSEQ
#endif
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale NFS file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#define ENSROK 0 /* DNS server returned answer with no data */
#define ENSRNODATA 160 /* DNS server returned answer with no data */
#define ENSRFORMERR 161 /* DNS server claims query was misformatted */
#define ENSRSERVFAIL 162 /* DNS server returned general failure */
#define ENSRNOTFOUND 163 /* Domain name not found */
#define ENSRNOTIMP 164 /* DNS server does not implement requested operation */
#define ENSRREFUSED 165 /* DNS server refused query */
#define ENSRBADQUERY 166 /* Misformatted DNS query */
#define ENSRBADNAME 167 /* Misformatted domain name */
#define ENSRBADFAMILY 168 /* Unsupported address family */
#define ENSRBADRESP 169 /* Misformatted DNS reply */
#define ENSRCONNREFUSED 170 /* Could not contact DNS servers */
#define ENSRTIMEOUT 171 /* Timeout while contacting DNS servers */
#define ENSROF 172 /* End of file */
#define ENSRFILE 173 /* Error reading file */
#define ENSRNOMEM 174 /* Out of memory */
#define ENSRDESTRUCTION 175 /* Application terminated lookup */
#define ENSRQUERYDOMAINTOOLONG 176 /* Domain name is too long */
#define ENSRCNAMELOOP 177 /* Domain name is too long */
#endif
/**
* Redefine the errno, Only use in framework/app
*
*/
#ifdef BUILD_BIN
#undef set_errno
#define set_errno(err) do { if (err) { errno = (err); } } while(0)
#else
#ifdef BUILD_APP
extern int get_errno(void);
extern void set_errno(int err);
#undef errno
#define errno get_errno()
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif /* AOS_ERRNO_H */

View file

@ -0,0 +1,70 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_INIT_H
#define AOS_INIT_H
#include <stdbool.h>
typedef struct {
int argc;
char **argv;
bool cli_enable;
} kinit_t;
extern int aos_kernel_init(kinit_t *kinit);
#ifdef AOS_BINS
#include <k_api.h>
struct app_info_t {
void (*app_entry)(void *ksyscall_tbl, void *fsyscall_tbl, int argc, char *argv[]);
unsigned int data_ram_start;
unsigned int data_ram_end;
unsigned int data_flash_begin;
unsigned int bss_start;
unsigned int bss_end;
unsigned int heap_start;
unsigned int heap_end;
};
struct framework_info_t {
void (*framework_entry)(void *syscall_tbl, int argc, char *argv[]);
unsigned int data_ram_start;
unsigned int data_ram_end;
unsigned int data_flash_begin;
unsigned int bss_start;
unsigned int bss_end;
unsigned int heap_start;
unsigned int heap_end;
};
struct m_app_info_t {
void (*app_entry)(void *ksyscall_tbl, int argc, char *argv[]);
unsigned int data_ram_start;
unsigned int data_ram_end;
unsigned int data_flash_begin;
unsigned int bss_start;
unsigned int bss_end;
unsigned int heap_start;
unsigned int heap_end;
/* reserve for other */
unsigned int reserve0;
unsigned int reserve1;
/* this bin_type must be here, 0x28, uniform with single bin & kernel bin,
arm cortex not used */
unsigned int bin_type;
unsigned int reserve2;
unsigned int reserve3;
unsigned int reserve4;
unsigned int reserve5;
unsigned int reserve6;
};
#endif
#endif /* AOS_INIT_H */

View file

@ -0,0 +1,155 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_EVENT_TYPE_CODE_API_H
#define AOS_EVENT_TYPE_CODE_API_H
/* remote procedure call */
#define EV_RPC 0x0100
/* YunIO event */
#define EV_YUNIO 0x0101
#define CODE_YUNIO_CMD_START 1
#define CODE_YUNIO_CMD_RETRY 2
#define CODE_YUNIO_CMD_DISCONNECT 3
#define CODE_YUNIO_ON_CONNECTED 4
#define CODE_YUNIO_ON_DISCONNECTED 5
#define CODE_YUNIO_ON_CONNECT_FAILED 6
#define CODE_YUNIO_ON_READ_ERROR 7
#define CODE_YUNIO_ON_WRITE_ERROR 8
#define CODE_YUNIO_ON_HEARTBIT_ERROR 9
#define CODE_YUNIO_PUBLISH_SUCCESS 10
#define CODE_YUNIO_PUBLISH_TIMEOUT 11
/** OTA event define */
#define EV_OTA 0x0102
#define CODE_OTA_ON_RESULT 1
/** register device service */
#define EV_DEVICE_REGISTER 0x0103
#define CODE_REGISTER_ON_RESULT 1
#define VALUE_REGISTER_SUCCESS 0
/** id2 device activate */
#define EV_ACTIVATE_ID2 0x0104
#define CODE_ACTIVATE_ID2_ON_RESULT 1
#define VALUE_ACTIVATE_ID2_SUCCESS 0
#define VALUE_ACTIVATE_ID2_FAILURE 1
#define EV_DDA 0x0105
#define CODE_DDA_ON_CONNECTED 1
#define EV_BZ_COMBO 0x0106
#define CODE_COMBO_AP_INFO_READY 1
/** General key define */
#define EV_KEY 0x0201
#define CODE_RECORD 1
#define CODE_VOLUME 2 /* Reserve */
#define CODE_VOLUME_INC 3
#define CODE_VOLUME_DEC 4
#define CODE_PLAY_PAUSE 5
#define CODE_MUTE 6
#define CODE_CHANNEL 7
#define CODE_NEXT 8
#define CODE_RECORD_PRE 9
#define CODE_RESET 0x1001
#define CODE_STATUS 11
#define CODE_ELINK 12
#define CODE_BOOT 13
/** General key value */
#define VALUE_KEY_UP 0
#define VALUE_KEY_DOWN 1
#define VALUE_KEY_CLICK 2
#define VALUE_KEY_LTCLICK 3
#define VALUE_KEY_LLTCLICK 4
#define VALUE_KEY_DBCLICK 5
/** General channel value */
#define VALUE_SYS_CHN_CONNECTED 0
#define VALUE_SYS_CHN_CONNECTING 1
#define VALUE_SYS_CHN_DISCONNECTED 2
/** Reserve event */
#define EV_KNOD 0x0203
/** SD card event */
#define EV_SD 0x0204
#define CODE_SD_PLUG 1
#define VALUE_SD_OUT 0
#define VALUE_SD_IN 1
/** LAN Driver event */
#define EV_LAN 0x0205
#define VALUE_LAN_OUT 0
#define VALUE_LAN_IN 1
/** Net event define */
#define EV_NET 0x0206
#define CODE_NET_DHCP_START 1
#define CODE_NET_DHCP_RESULT 2
#define CODE_NET_IP_STATIC 3
#define CODE_NET_STATUS 4
#define VALUE_NET_LAN_OK 0x01
#define VALUE_NET_WIFI_OK 0x02
/** Usb driver event */
#define EV_USB 0x0207
#define VALUE_USB_OUT 0
#define VALUE_USB_IN 1
/** PM event */
#define EV_PM 0x0208
#define CODE_PM_ENTER_INFORM 1
#define CODE_PM_ENTER 2
#define CODE_PM_DONE 3
#define CODE_PM_QUIT 4
#define CODE_PM_SHUTDOWN_INFORM 5
#define CODE_PM_STARTUP_INFORM 6
#define CODE_PM_LOWPOWER_INFORM 7
#define CODE_PM_POWERRECOVER_INFORM 8
#define CODE_PM_START_HEARTBEAT_INFORM 9
#define CODE_PM_STOP_HEARTBEAT_INFORM 10
#define VALUE_PM_IDLE_INFORM 1
#define VALUE_PM_POWERBUTTON_INFORM 2
/** File system event */
#define EV_FS 0x0209
#define CODE_FSYS_SD_LOAD 1
#define CODE_FSYS_UDISK_LOAD 2
#define CODE_FSYS_FLASH_LOAD 3
#define CODE_FSYS_SD_SPACE 4
#define CODE_FSYS_UDISK_SPACE 5
#define CODE_FSYS_FLASH_SPACE 6
/** Bluetooth */
#define EV_BT 0x020A
#define CODE_BT_DEVICE_CONNECT 1
#define CODE_BT_DEVICE_DISCONNECT 2
#define CODE_BT_MODE_ON 3
#define CODE_BT_MODE_OFF 4
/** DLNA */
#define EV_DLNA 0x020B
#define CODE_DLNA_DEVICE_CONNECT 1
#define CODE_DLNA_DEVICE_DISCONNECT 2
#define CODE_DLNA_MODE_ON 3
#define CODE_DLNA_MODE_OFF 4
/** AIRPLAY */
#define EV_AIRPLAY 0x020C
#define CODE_AIRPLAY_DEVICE_CONNECT 1
#define CODE_AIRPLAY_DEVICE_DISCONNECT 2
#define CODE_AIRPLAY_MODE_ON 3
#define CODE_AIRPLAY_MODE_OFF 4
/** AT */
#define EV_AT 0x020D
#define CODE_AT_IF_READY 1
#define CODE_AT_IF_DISAPPEAR 2
/** AT */
#define EV_BLE 0x020E
#define CODE_BLE_TX_COMPLETED 1
#endif /* AOS_EVENT_TYPE_CODE_API_H */

View file

@ -0,0 +1,138 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_LOG_IMPL_H
#define AOS_LOG_IMPL_H
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned int aos_log_level;
static inline unsigned int aos_log_get_level(void)
{
return aos_log_level;
}
enum log_level_bit {
AOS_LL_V_NONE_BIT = -1,
AOS_LL_V_FATAL_BIT,
AOS_LL_V_ERROR_BIT,
AOS_LL_V_WARN_BIT,
AOS_LL_V_INFO_BIT,
AOS_LL_V_DEBUG_BIT,
AOS_LL_V_MAX_BIT
};
#define AOS_LOG_LEVEL aos_log_get_level()
#define AOS_LL_V_NONE 0
#define AOS_LL_V_ALL 0XFF
#define AOS_LL_V_FATAL (1 << AOS_LL_V_FATAL_BIT)
#define AOS_LL_V_ERROR (1 << AOS_LL_V_ERROR_BIT)
#define AOS_LL_V_WARN (1 << AOS_LL_V_WARN_BIT)
#define AOS_LL_V_INFO (1 << AOS_LL_V_INFO_BIT)
#define AOS_LL_V_DEBUG (1 << AOS_LL_V_DEBUG_BIT)
/*
* color def.
* see http://stackoverflow.com/questions/3585846/color-text-in-terminal-applications-in-unix
*/
#define COL_DEF "\x1B[0m" /* white */
#define COL_RED "\x1B[31m" /* red */
#define COL_GRE "\x1B[32m" /* green */
#define COL_BLU "\x1B[34m" /* blue */
#define COL_YEL "\x1B[33m" /* yellow */
#define COL_WHE "\x1B[37m" /* white */
#define COL_CYN "\x1B[36m"
#define COL_MAG "\x1B[35m"
#include <aos/kernel.h>
extern int csp_printf(const char *fmt, ...);
#ifdef CONFIG_LOGMACRO_DETAILS
#define log_print(CON, MOD, COLOR, LVL, FMT, ...) \
do { \
if (AOS_LOG_LEVEL & CON) { \
long long ms = aos_now_ms(); \
csp_printf(COLOR " [%4d.%03d]<%s> %s [%s#%d] : ", (int)(ms/1000), (int)(ms%1000), LVL, MOD, __FUNCTION__, __LINE__); \
csp_printf(FMT COL_DEF "\r\n", ##__VA_ARGS__); \
} \
} while (0)
#else
#if defined(LOG_SIMPLE)
extern void log_print_simple(unsigned int log_level, const char *fmt, ...);
#define log_print(CON, MOD, COLOR, LVL, FMT, ...) \
do { \
log_print_simple(CON, FMT, ##__VA_ARGS__);\
} while (0)
#else
#define log_print(CON, MOD, COLOR, LVL, FMT, ...) \
do { \
if (AOS_LOG_LEVEL & CON) { \
csp_printf("[%06d]<" LVL "> ", (unsigned)aos_now_ms()); \
csp_printf(FMT, ##__VA_ARGS__); \
csp_printf("\r\n"); \
} \
} while (0)
#endif
#endif
#define void_func(fmt, ...)
#ifndef os_printf
#ifndef csp_printf
int csp_printf(const char *fmt, ...);
#else
extern int csp_printf(const char *fmt, ...);
#endif
#else
extern int csp_printf(const char *fmt, ...);
#endif
#undef LOGF
#undef LOGE
#undef LOGW
#undef LOGI
#undef LOGD
#undef LOG
#define LOG_IMPL(fmt, ...) \
log_print(AOS_LL_V_ALL, "AOS", COL_DEF, "V", fmt, ##__VA_ARGS__)
#ifdef NDEBUG
#define CONFIG_LOGMACRO_SILENT
#endif
#ifdef DEBUG
#define LOGD_IMPL(mod, fmt, ...) \
log_print(AOS_LL_V_DEBUG, mod, COL_WHE, "D", fmt, ##__VA_ARGS__)
#else
#define LOGD_IMPL(mod, fmt, ...) void_func(fmt, ##__VA_ARGS__)
#endif
#ifdef CONFIG_LOGMACRO_SILENT
#define LOGF_IMPL(mod, fmt, ...) void_func(fmt, ##__VA_ARGS__)
#define LOGE_IMPL(mod, fmt, ...) void_func(fmt, ##__VA_ARGS__)
#define LOGW_IMPL(mod, fmt, ...) void_func(fmt, ##__VA_ARGS__)
#define LOGI_IMPL(mod, fmt, ...) void_func(fmt, ##__VA_ARGS__)
#else
#define LOGF_IMPL(mod, fmt, ...) \
log_print(AOS_LL_V_FATAL, mod, COL_RED, "F", fmt, ##__VA_ARGS__)
#define LOGE_IMPL(mod, fmt, ...) \
log_print(AOS_LL_V_ERROR, mod, COL_YEL, "E", fmt, ##__VA_ARGS__)
#define LOGW_IMPL(mod, fmt, ...) \
log_print(AOS_LL_V_WARN, mod, COL_BLU, "W", fmt, ##__VA_ARGS__)
#define LOGI_IMPL(mod, fmt, ...) \
log_print(AOS_LL_V_INFO, mod, COL_GRE, "I", fmt, ##__VA_ARGS__)
#endif /* CONFIG_LOGMACRO_SILENT */
#ifdef __cplusplus
}
#endif
#endif /* AOS_LOG_IMPL_H */

View file

@ -0,0 +1,550 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_KERNEL_H
#define AOS_KERNEL_H
#include <stddef.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define AOS_WAIT_FOREVER 0xffffffffu
#define AOS_NO_WAIT 0x0
#define AOS_DEFAULT_APP_PRI 32
typedef struct {
void *hdl;
} aos_hdl_t;
typedef aos_hdl_t aos_task_t;
typedef aos_hdl_t aos_mutex_t;
typedef aos_hdl_t aos_sem_t;
typedef aos_hdl_t aos_queue_t;
typedef aos_hdl_t aos_timer_t;
typedef aos_hdl_t aos_work_t;
typedef aos_hdl_t aos_event_t;
typedef struct {
void *hdl;
void *stk;
} aos_workqueue_t;
typedef unsigned int aos_task_key_t;
/**
* Reboot AliOS.
*/
void aos_reboot(void);
/**
* Get HZ(ticks per second).
*
* @return RHINO_CONFIG_TICKS_PER_SECOND.
*/
int aos_get_hz(void);
/**
* Get kernel version.
*
* @return SYSINFO_KERNEL_VERSION.
*/
const char *aos_version_get(void);
/**
* Create a task.
*
* @param[in] name task name.
* @param[in] fn function to run.
* @param[in] arg argument of the function.
* @param[in] stacksize stack-size in bytes.
*
* @return 0: success.
*/
int aos_task_new(const char *name, void (*fn)(void *), void *arg, int stack_size);
/**
* Create a task.
*
* @param[in] task handle.
* @param[in] name task name.
* @param[in] fn task function.
* @param[in] arg argument of the function..
* @param[in] stack_buf stack-buf: if stack_buf==NULL, provided by kernel.
* @param[in] stack_size stack-size in bytes.
* @param[in] prio priority value, the max is RHINO_CONFIG_USER_PRI_MAX(default 60).
*
* @return 0: success.
*/
int aos_task_new_ext(aos_task_t *task, const char *name, void (*fn)(void *), void *arg,
int stack_size, int prio);
/**
* Exit a task.
*
* @param[in] code not used now.
*/
void aos_task_exit(int code);
/**
* Get task name.
*
* @return the name of the task
*/
const char *aos_task_name(void);
/**
* Create a task key.
*
* @param[in] key pointer of key object.
*
* @return 0: success, -EINVAL: error.
*/
int aos_task_key_create(aos_task_key_t *key);
/**
* Delete a task key.
*
* @param[in] key key object.
*/
void aos_task_key_delete(aos_task_key_t key);
/**
* Associate a task-specific value with a key.
*
* @param[in] key key object.
* @param[in] vp pointer of a task-specific value.
*
* @return the check status, 0 is OK, -1 indicates invalid.
*/
int aos_task_setspecific(aos_task_key_t key, void *vp);
/**
* Get the value currently bound to the specified key.
*
* @param[in] key key object.
*/
void *aos_task_getspecific(aos_task_key_t key);
/**
* Alloc a mutex.
*
* @param[in] mutex pointer of mutex object, mutex object must be alloced,
* hdl pointer in aos_mutex_t will refer a kernel obj internally.
*
* @return 0: success.
*/
int aos_mutex_new(aos_mutex_t *mutex);
/**
* Free a mutex.
*
* @param[in] mutex mutex object, mem refered by hdl pointer in aos_mutex_t will
* be freed internally.
*/
void aos_mutex_free(aos_mutex_t *mutex);
/**
* Lock a mutex.
*
* @param[in] mutex mutex object, it contains kernel obj pointer which aos_mutex_new alloced.
* @param[in] timeout waiting until timeout in milliseconds.
*
* @return 0: success.
*/
int aos_mutex_lock(aos_mutex_t *mutex, unsigned int timeout);
/**
* Unlock a mutex.
*
* @param[in] mutex mutex object, it contains kernel obj pointer which oc_mutex_new alloced.
*
* @return 0: success.
*/
int aos_mutex_unlock(aos_mutex_t *mutex);
/**
* This function will check if mutex is valid.
*
* @param[in] mutex pointer to the mutex.
*
* @return 0: invalid, 1: valid.
*/
int aos_mutex_is_valid(aos_mutex_t *mutex);
/**
* Alloc a semaphore.
*
* @param[out] sem pointer of semaphore object, semaphore object must be alloced,
* hdl pointer in aos_sem_t will refer a kernel obj internally.
* @param[in] count initial semaphore counter.
*
* @return 0:success.
*/
int aos_sem_new(aos_sem_t *sem, int count);
/**
* Destroy a semaphore.
*
* @param[in] sem pointer of semaphore object, mem refered by hdl pointer
* in aos_sem_t will be freed internally.
*/
void aos_sem_free(aos_sem_t *sem);
/**
* Acquire a semaphore.
*
* @param[in] sem semaphore object, it contains kernel obj pointer which aos_sem_new alloced.
* @param[in] timeout waiting until timeout in milliseconds.
*
* @return 0: success.
*/
int aos_sem_wait(aos_sem_t *sem, unsigned int timeout);
/**
* Release a semaphore.
*
* @param[in] sem semaphore object, it contains kernel obj pointer which aos_sem_new alloced.
*/
void aos_sem_signal(aos_sem_t *sem);
/**
* This function will check if semaphore is valid.
*
* @param[in] sem pointer to the semaphore.
*
* @return 0: invalid, 1: valid.
*/
int aos_sem_is_valid(aos_sem_t *sem);
/**
* Release all semaphore.
*
* @param[in] sem semaphore object, it contains kernel obj pointer which aos_sem_new alloced.
*/
void aos_sem_signal_all(aos_sem_t *sem);
/**
* This function will create an event with an initialization flag set.
* This function should not be called from interrupt context.
*
* @param[in] event event object pointer.
* @param[in] flags initialization flag set(provided by caller).
*
* @return 0: success.
*/
int aos_event_new(aos_event_t *event, unsigned int flags);
/**
* This function will free an event.
* This function shoud not be called from interrupt context.
*
* @param[in] event memory refered by hdl pointer in event will be freed.
*
* @return N/A.
*/
void aos_event_free(aos_event_t *event);
/**
* This function will try to get flag set from given event, if the request flag
* set is satisfied, it will return immediately, if the request flag set is not
* satisfied with timeout(RHINO_WAIT_FOREVER,0xFFFFFFFF), the caller task will be
* pended on event until the flag is satisfied, if the request flag is not
* satisfied with timeout(RHINO_NO_WAIT, 0x0), it will also return immediately.
* Note, this function should not be called from interrupt context because it has
* possible to lead context switch and an interrupt has no TCB to save context.
*
* @param[in] event event object pointer.
* @param[in] flags request flag set.
* @param[in] opt operation type, such as AND,OR,AND_CLEAR,OR_CLEAR.
* @param[out] actl_flags the internal flags value hold by event.
* @param[in] flags request flag set.
* @param[in] timeout max wait time in millisecond.
*
* @return 0: success.
*/
int aos_event_get(aos_event_t *event, unsigned int flags, unsigned char opt,
unsigned int *actl_flags, unsigned int timeout);
/**
* This function will set flag set to given event, and it will check if any task
* which is pending on the event should be waken up.
*
* @param[in] event event object pointer.
* @param[in] flags flag set to be set into event.
* @param[in] opt operation type, such as AND,OR.
*
* @return 0: success.
*/
int aos_event_set(aos_event_t *event, unsigned int flags, unsigned char opt);
/**
* This function will create a queue.
*
* @param[in] queue pointer to the queue(the space is provided by user).
* @param[in] buf buf of the queue(provided by user).
* @param[in] size the bytes of the buf.
* @param[in] max_msg the max size of the msg.
*
* @return 0: success.
*/
int aos_queue_new(aos_queue_t *queue, void *buf, unsigned int size, int max_msg);
/**
* This function will delete a queue.
*
* @param[in] queue pointer to the queue.
*/
void aos_queue_free(aos_queue_t *queue);
/**
* This function will send a msg to the front of a queue.
*
* @param[in] queue pointer to the queue.
* @param[in] msg msg to send.
* @param[in] size size of the msg.
*
* @return 0: success.
*/
int aos_queue_send(aos_queue_t *queue, void *msg, unsigned int size);
/**
* This function will receive msg from a queue.
*
* @param[in] queue pointer to the queue.
* @param[in] ms ms to wait before receive.
* @param[out] msg buf to save msg.
* @param[out] size size of the msg.
*
* @return 0: success.
*/
int aos_queue_recv(aos_queue_t *queue, unsigned int ms, void *msg, unsigned int *size);
/**
* This function will check if queue is valid.
*
* @param[in] queue pointer to the queue.
*
* @return 0: invalid, 1: valid.
*/
int aos_queue_is_valid(aos_queue_t *queue);
/**
* This function will return buf ptr if queue is inited.
*
* @param[in] queue pointer to the queue.
*
* @return NULL: error.
*/
void *aos_queue_buf_ptr(aos_queue_t *queue);
/**
* This function will create a timer and run auto.
*
* @param[in] timer pointer to the timer.
* @param[in] fn callbak of the timer.
* @param[in] arg the argument of the callback.
* @param[in] ms ms of the normal timer triger.
* @param[in] repeat repeat or not when the timer is created.
*
* @return 0: success.
*/
int aos_timer_new(aos_timer_t *timer, void (*fn)(void *, void *),
void *arg, int ms, int repeat);
/**
* This function will create a timer.
*
* @param[in] timer pointer to the timer.
* @param[in] fn callbak of the timer.
* @param[in] arg the argument of the callback.
* @param[in] ms ms of the normal timer triger.
* @param[in] repeat repeat or not when the timer is created.
* @param[in] auto_run run auto or not when the timer is created.
*
* @return 0: success.
*/
int aos_timer_new_ext(aos_timer_t *timer, void (*fn)(void *, void *),
void *arg, int ms, int repeat, unsigned char auto_run);
/**
* This function will delete a timer.
*
* @param[in] timer pointer to a timer.
*/
void aos_timer_free(aos_timer_t *timer);
/**
* This function will start a timer.
*
* @param[in] timer pointer to the timer.
*
* @return 0: success.
*/
int aos_timer_start(aos_timer_t *timer);
/**
* This function will stop a timer.
*
* @param[in] timer pointer to the timer.
*
* @return 0: success.
*/
int aos_timer_stop(aos_timer_t *timer);
/**
* This function will change attributes of a timer.
*
* @param[in] timer pointer to the timer.
* @param[in] ms ms of the timer triger.
*
* @return 0: success.
*/
int aos_timer_change(aos_timer_t *timer, int ms);
/**
* This function will creat a workqueue.
*
* @param[in] workqueue the workqueue to be created.
* @param[in] pri the priority of the worker.
* @param[in] stack_size the size of the worker-stack.
*
* @return 0: success.
*/
int aos_workqueue_create(aos_workqueue_t *workqueue, int pri, int stack_size);
/**
* This function will initialize a work.
*
* @param[in] work the work to be initialized.
* @param[in] fn the call back function to run.
* @param[in] arg the paraments of the function.
* @param[in] dly ms to delay before run.
*
* @return 0: success.
*/
int aos_work_init(aos_work_t *work, void (*fn)(void *), void *arg, int dly);
/**
* This function will destroy a work.
*
* @param[in] work the work to be destroied.
*/
void aos_work_destroy(aos_work_t *work);
/**
* This function will run a work on a workqueue.
*
* @param[in] workqueue the workqueue to run work.
* @param[in] work the work to run.
*
* @return 0: success.
*/
int aos_work_run(aos_workqueue_t *workqueue, aos_work_t *work);
/**
* This function will run a work on the default workqueue.
*
* @param[in] work the work to run.
*
* @return 0: success.
*/
int aos_work_sched(aos_work_t *work);
/**
* This function will cancel a work on the default workqueue.
*
* @param[in] work the work to cancel.
*
* @return 0: success.
*/
int aos_work_cancel(aos_work_t *work);
/**
* Realloc memory.
*
* @param[in] mem current memory address point.
* @param[in] size new size of the mem to remalloc.
*
* @return NULL: error.
*/
void *aos_realloc(void *mem, unsigned int size);
/**
* Alloc memory.
*
* @param[in] size size of the mem to malloc.
*
* @return NULL: error.
*/
void *aos_malloc(unsigned int size);
/**
* Alloc memory and clear to zero.
*
* @param[in] size size of the mem to malloc.
*
* @return NULL: error.
*/
void *aos_zalloc(unsigned int size);
/**
* Trace alloced mems.
*
* @param[in] addr pointer of the mem alloced by malloc.
* @param[in] allocator buildin_address.
*/
void aos_alloc_trace(void *addr, size_t allocator);
/**
* Free memory.
*
* @param[in] ptr address point of the mem.
*/
void aos_free(void *mem);
/**
* Get current time in nano seconds.
*
* @return elapsed time in nano seconds from system starting.
*/
long long aos_now(void);
/**
* Get current time in mini seconds.
*
* @return elapsed time in mini seconds from system starting.
*/
long long aos_now_ms(void);
/**
* Msleep.
*
* @param[in] ms sleep time in milliseconds.
*/
void aos_msleep(int ms);
/**
* Initialize system
*/
void aos_init(void);
/**
* Start system
*/
void aos_start(void);
#ifdef __cplusplus
}
#endif
#endif /* AOS_KERNEL_H */

View file

@ -0,0 +1,65 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_KV_H
#define AOS_KV_H
#include <aos/types.h>
#ifdef __cplusplus
extern "C"
{
#endif
/**
* Add a new KV pair.
*
* @param[in] key the key of the KV pair.
* @param[in] value the value of the KV pair.
* @param[in] len the length of the value.
* @param[in] sync save the KV pair to flash right now (should always be 1).
*
* @return 0 on success, negative error on failure.
*/
int aos_kv_set(const char *key, const void *value, int len, int sync);
/**
* Get the KV pair's value stored in buffer by its key.
*
* @note: the buffer_len should be larger than the real length of the value,
* otherwise buffer would be NULL.
*
* @param[in] key the key of the KV pair to get.
* @param[out] buffer the memory to store the value.
* @param[in-out] buffer_len in: the length of the input buffer.
* out: the real length of the value.
*
* @return 0 on success, negative error on failure.
*/
int aos_kv_get(const char *key, void *buffer, int *buffer_len);
/**
* Delete the KV pair by its key.
*
* @param[in] key the key of the KV pair to delete.
*
* @return 0 on success, negative error on failure.
*/
int aos_kv_del(const char *key);
/**
* Delete the KV pair by key's prefix.
*
* @param[in] key the key's prefix of the KV pair to delete.
*
* @return 0 on success, negative error on failure.
*/
int aos_kv_del_by_prefix(const char *prefix);
#ifdef __cplusplus
}
#endif
#endif /* AOS_KV_H */

View file

@ -0,0 +1,338 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_LIST_H
#define AOS_LIST_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* Get offset of a member variable.
*
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the variable within the struct.
*/
#define aos_offsetof(type, member) ((size_t)&(((type *)0)->member))
/*
* Get the struct for this entry.
*
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the variable within the struct.
*/
#define aos_container_of(ptr, type, member) \
((type *) ((char *) (ptr) - aos_offsetof(type, member)))
/* for double link list */
typedef struct dlist_s {
struct dlist_s *prev;
struct dlist_s *next;
} dlist_t;
static inline void __dlist_add(dlist_t *node, dlist_t *prev, dlist_t *next)
{
node->next = next;
node->prev = prev;
prev->next = node;
next->prev = node;
}
/*
* Get the struct for this entry.
*
* @param[in] addr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_entry(addr, type, member) \
((type *)((long)addr - aos_offsetof(type, member)))
static inline void dlist_add(dlist_t *node, dlist_t *queue)
{
__dlist_add(node, queue, queue->next);
}
static inline void dlist_add_tail(dlist_t *node, dlist_t *queue)
{
__dlist_add(node, queue->prev, queue);
}
static inline void dlist_del(dlist_t *node)
{
dlist_t *prev = node->prev;
dlist_t *next = node->next;
prev->next = next;
next->prev = prev;
}
static inline void dlist_init(dlist_t *node)
{
node->next = node->prev = node;
}
static inline void INIT_AOS_DLIST_HEAD(dlist_t *list)
{
list->next = list;
list->prev = list;
}
static inline int dlist_empty(const dlist_t *head)
{
return head->next == head;
}
/*
* Initialise the list.
*
* @param[in] list the list to be inited.
*/
#define AOS_DLIST_INIT(list) {&(list), &(list)}
/*
* Get the first element from a list
*
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_first_entry(ptr, type, member) \
dlist_entry((ptr)->next, type, member)
/*
* Iterate over a list.
*
* @param[in] pos the &struct dlist_t to use as a loop cursor.
* @param[in] head he head for your list.
*/
#define dlist_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
/*
* Iterate over a list safe against removal of list entry.
*
* @param[in] pos the &struct dlist_t to use as a loop cursor.
* @param[in] n another &struct dlist_t to use as temporary storage.
* @param[in] head he head for your list.
*/
#define dlist_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/*
* Iterate over list of given type.
*
* @param[in] queue he head for your list.
* @param[in] node the &struct dlist_t to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_for_each_entry(queue, node, type, member) \
for (node = aos_container_of((queue)->next, type, member); \
&node->member != (queue); \
node = aos_container_of(node->member.next, type, member))
/*
* Iterate over list of given type safe against removal of list entry.
*
* @param[in] queue the head for your list.
* @param[in] n the type * to use as a temp.
* @param[in] node the type * to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_for_each_entry_safe(queue, n, node, type, member) \
for (node = aos_container_of((queue)->next, type, member), \
n = (queue)->next ? (queue)->next->next : NULL; \
&node->member != (queue); \
node = aos_container_of(n, type, member), n = n ? n->next : NULL)
/*
* Get the struct for this entry.
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the variable within the struct.
*/
#define list_entry(ptr, type, member) \
aos_container_of(ptr, type, member)
/*
* Iterate backwards over list of given type.
*
* @param[in] pos the type * to use as a loop cursor.
* @param[in] head he head for your list.
* @param[in] member the name of the dlist_t within the struct.
* @param[in] type the type of the struct this is embedded in.
*/
#define dlist_for_each_entry_reverse(pos, head, member, type) \
for (pos = list_entry((head)->prev, type, member); \
&pos->member != (head); \
pos = list_entry(pos->member.prev, type, member))
/*
* Get the list length.
*
* @param[in] queue the head for your list.
*/
static inline int dlist_entry_number(dlist_t *queue)
{
int num;
dlist_t *cur = queue;
for (num=0;cur->next != queue;cur=cur->next, num++)
;
return num;
}
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_DLIST_HEAD_INIT(name) { &(name), &(name) }
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_DLIST_HEAD(name) \
dlist_t name = AOS_DLIST_HEAD_INIT(name)
/* for single link list */
typedef struct slist_s {
struct slist_s *next;
} slist_t;
static inline void slist_add(slist_t *node, slist_t *head)
{
node->next = head->next;
head->next = node;
}
static inline void slist_add_tail(slist_t *node, slist_t *head)
{
while (head->next) {
head = head->next;
}
slist_add(node, head);
}
static inline void slist_del(slist_t *node, slist_t *head)
{
while (head->next) {
if (head->next == node) {
head->next = node->next;
break;
}
head = head->next;
}
}
static inline int slist_empty(const slist_t *head)
{
return !head->next;
}
static inline void slist_init(slist_t *head)
{
head->next = 0;
}
/*
* Iterate over list of given type.
*
* @param[in] queue he head for your list.
* @param[in] node the type * to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_for_each_entry(queue, node, type, member) \
for (node = aos_container_of((queue)->next, type, member); \
&node->member; \
node = aos_container_of(node->member.next, type, member))
/*
* Iterate over list of given type safe against removal of list entry.
*
* @param[in] queue the head for your list.
* @param[in] tmp the type * to use as a temp.
* @param[in] node the type * to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_for_each_entry_safe(queue, tmp, node, type, member) \
for (node = aos_container_of((queue)->next, type, member), \
tmp = (queue)->next ? (queue)->next->next : NULL; \
&node->member; \
node = aos_container_of(tmp, type, member), tmp = tmp ? tmp->next : tmp)
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_SLIST_HEAD_INIT(name) {0}
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_SLIST_HEAD(name) \
slist_t name = AOS_SLIST_HEAD_INIT(name)
/*
* Get the struct for this entry.
* @param[in] addr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_entry(addr, type, member) ( \
addr ? (type *)((long)addr - aos_offsetof(type, member)) : (type *)addr \
)
/*
* Get the first element from a list.
*
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_first_entry(ptr, type, member) \
slist_entry((ptr)->next, type, member)
/*
* Get the list length.
*
* @param[in] queue the head for your list.
*/
static inline int slist_entry_number(slist_t *queue)
{
int num;
slist_t *cur = queue;
for (num=0;cur->next;cur=cur->next, num++)
;
return num;
}
#ifdef __cplusplus
}
#endif
#endif /* AOS_LIST_H */

View file

@ -0,0 +1,95 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_LOG_H
#define AOS_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
#include <aos/internal/log_impl.h>
typedef enum {
AOS_LL_NONE, /* disable log */
AOS_LL_FATAL, /* fatal log will output */
AOS_LL_ERROR, /* fatal + error log will output */
AOS_LL_WARN, /* fatal + warn + error log will output(default level) */
AOS_LL_INFO, /* info + warn + error log will output */
AOS_LL_DEBUG, /* debug + info + warn + error + fatal log will output */
} aos_log_level_t;
extern unsigned int aos_log_level;
/**
* Get the log level.
*/
static inline int aos_get_log_level(void) {
return aos_log_level;
}
/**
* Set the log level.
*
* @param[in] log_level level to be set,must be one of AOS_LL_NONE,AOS_LL_FATAL,AOS_LL_ERROR,AOS_LL_WARN,AOS_LL_INFO or AOS_LL_DEBUG.
*/
void aos_set_log_level(aos_log_level_t log_level);
/*
* Log at fatal level.
*
* @param[in] mod string description of module.
* @param[in] fmt same as printf() usage.
*/
#define LOGF(mod, fmt, ...) LOGF_IMPL(mod, fmt, ##__VA_ARGS__)
/*
* Log at error level.
*
* @param[in] mod string description of module.
* @param[in] fmt same as printf() usage.
*/
#define LOGE(mod, fmt, ...) LOGE_IMPL(mod, fmt, ##__VA_ARGS__)
/*
* Log at warning level.
*
* @param[in] mod string description of module.
* @param[in] fmt same as printf() usage.
*/
#define LOGW(mod, fmt, ...) LOGW_IMPL(mod, fmt, ##__VA_ARGS__)
/*
* Log at info level.
*
* @param[in] mod string description of module.
* @param[in] fmt same as printf() usage.
*/
#define LOGI(mod, fmt, ...) LOGI_IMPL(mod, fmt, ##__VA_ARGS__)
/*
* Log at debug level.
*
* @param[in] mod string description of module.
* @param[in] fmt same as printf() usage.
*/
#define LOGD(mod, fmt, ...) LOGD_IMPL(mod, fmt, ##__VA_ARGS__)
/*
* Log at the level set by aos_set_log_level().
*
* @param[in] fmt same as printf() usage.
*/
#define LOG(fmt, ...) LOG_IMPL(fmt, ##__VA_ARGS__)
#ifdef AOS_DISABLE_ALL_LOGS
extern int log_check_uart_input(int);
extern char log_get_enable_aos_log_flag(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* AOS_LOG_H */

View file

@ -0,0 +1,61 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_MBEDTLS_SSL_H
#define AOS_MBEDTLS_SSL_H
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#include <stdlib.h>
#include <aos/aos.h>
/**
* Create a ssl connect.
*
* @param[in] tcp_fd handle of the tcp socket.
* @param[in] ca_cert CA.
* @param[in] ca_cert_len length of the CA.
*
* @return NULL: error; ssl_param: success.
*/
void *mbedtls_ssl_connect(void *tcp_fd, const char *ca_cert, int ca_cert_len);
/**
* Send data through ssl.
*
* @param[in] ssl handle of the ssl.
* @param[in] buffer data to send.
* @param[in] length length of the data.
*
* @return -1: error; others: length of the data be sended.
*/
int mbedtls_ssl_send(void *ssl, const char *buffer, int length);
/**
* Recv data through ssl.
*
* @param[in] ssl handle of the ssl.
* @param[in] buffer buffer to recv data.
* @param[in] length the max size of the buffer.
*
* @return -1: error; 0: EOF; others: length of the data be sended.
*/
int mbedtls_ssl_recv(void *ssl, char *buffer, int length);
/**
* Close the ssl.
*
* @param[in] ssl handle to be closed.
*
* @return 0: success.
*/
int mbedtls_ssl_close(void *ssl);
#endif /* AOS_MBEDTLS_SSL_H */

View file

@ -0,0 +1,40 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_NETWORK_H
#define AOS_NETWORK_H
#ifdef __cplusplus
extern "C" {
#endif
#include <errno.h>
#include <fcntl.h>
/* network */
#ifdef WITH_LWIP
#include <lwip/def.h>
#include <lwip/netdb.h>
#include <lwip/sockets.h>
#elif defined(WITH_SAL)
#include <sal_arch.h>
#include <sal_def.h>
#include <sal_ipaddr.h>
#include <sal_sockets.h>
#elif !defined(CONFIG_NO_TCPIP)
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/eventfd.h>
#endif
#ifdef __cplusplus
}
#endif
#endif /* AOS_NETWORK_H */

View file

@ -0,0 +1,53 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_TYPES_H
#define AOS_TYPES_H
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#if defined(WITH_LWIP) || defined(CONFIG_NO_TCPIP) || defined(WITH_SAL)
#define POLLIN 0x1
#define POLLOUT 0x2
#define POLLERR 0x4
struct pollfd {
int fd;
short events;
short revents;
};
#else
#include <poll.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif
#ifndef AOS_EXPORTX
/**
* define the AOS_EXPORT macro*
*/
#define AOS_EXPORT(ret, fun, ...)
#endif
#ifndef AOS_COMPONENT_INIT
/**
* define the AOS_COMPONENT_INIT macro
*/
#define AOS_COMPONENT_INIT(fun, ...)
#endif
#ifndef AOS_TESTCASE
/**
* define the AOS_TESTCASE macro
*/
#define AOS_TESTCASE(fun, ...)
#endif
#endif /* AOS_TYPES_H */

View file

@ -0,0 +1,18 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef UDATA_H
#define UDATA_H
#include "../../framework/uData/include/uData_com_desc.h"
int uData_report_publish(input_event_t *event, void *pdata);
int uData_dev_ioctl(udata_t* pkg, uint8_t cmd, long long parm);
int uData_subscribe(udata_type_e type);
int uData_unsubscribe(udata_type_e type);
#endif /*UDATA_H*/

View file

@ -0,0 +1,49 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VERSION_H
#define AOS_VERSION_H
/**
* Get aos product model.
*
* @return model success, 0 failure.
*/
const char *aos_get_product_model(void);
/**
* Get aos os version.
*
* @return os version success, 0 failure.
*/
const char *aos_get_os_version(void);
/**
* Get aos kernel version.
*
* @return kernel version success, 0 failure.
*/
const char *aos_get_kernel_version(void);
/**
* Get aos app version.
*
* @return app version success, 0 failure.
*/
const char *aos_get_app_version(void);
/**
* Get aos device name.
*
* @return device name success, 0 failure.
*/
const char *aos_get_device_name(void);
/**
* dump sys info.
*/
void dump_sys_info(void);
#endif /* AOS_VERSION_H */

View file

@ -0,0 +1,195 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_H
#define AOS_VFS_H
#include <sys/types.h>
#include <sys/stat.h>
#include <aos/types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int d_ino; /* file number */
uint8_t d_type; /* type of file */
char d_name[]; /* file name */
} aos_dirent_t;
typedef struct {
int dd_vfs_fd;
int dd_rsv;
} aos_dir_t;
/**
* Open the file or device by its path.
*
* @param[in] path the path of the file or device to open.
* @param[in] flags the mode of open operation.
*
* @return the new file descriptor, negative error on failure.
*/
int aos_open(const char *path, int flags);
/**
* Close the file or device by its file descriptor.
*
* @param[in] fd the file descriptor of the file or device.
*
* @return 0 on success, negative error on failure.
*/
int aos_close(int fd);
/**
* Read the contents of a file or device into a buffer.
*
* @param[in] fd the file descriptor of the file or device.
* @param[in] nbytes the number of bytes to read.
* @param[out] buf the buffer to read in to.
*
* @return The number of bytes read, 0 at end of file, negative error on failure.
*/
ssize_t aos_read(int fd, void *buf, size_t nbytes);
/**
* Write the contents of a buffer to file or device.
*
* @param[in] fd the file descriptor of the file or device.
* @param[in] nbytes the number of bytes to write.
* @param[in] buf the buffer to write from.
*
* @return The number of bytes written, negative error on failure.
*/
ssize_t aos_write(int fd, const void *buf, size_t nbytes);
/**
* This is a wildcard API for sending controller specific commands.
*
* @param[in] fd the file descriptior of the file or device.
* @param[in] cmd A controller specific command.
* @param[in] arg Argument to the command, interpreted according to the command.
*
* @return any return from the command.
*/
int aos_ioctl(int fd, int cmd, unsigned long arg);
/**
* A mechanism to multiplex input/output over a set of file descriptors.
* For every file descriptor provided, poll() examines it for any events registered for that particular file descriptor.
*
* @param[in] fds a point to the array of pollfd struct carrying a file descriptor and bitmasks of events.
* @param[in] nfhs number of file descriptors.
* @param[in] timeout timer value to timeout or -1 for loop forever.
*
* @return number of file descriptors selected (for which revents is non-zero). 0 if timed out with nothing selected. -1 for error.
*/
int aos_poll(struct pollfd *fds, int nfds, int timeout);
/**
* Performs one of the operations described below on the open file descriptor, The operation is determined by cmd.
*
* @param[in] fd the file descriptor of the file or device.
* @param[in] cmd the operation of the file or device.
* @param[in] val it depends on whether cmd need params.
*
* @return 0 on success, negative error on failure.
*/
int aos_fcntl(int fd, int cmd, int val);
/**
* Move the file position to a given offset from a given location.
*
* @param[in] fd the file descriptor of the file.
* @param[in] offset The offset from whence to move to.
* @param[in] whence The start of where to seek.
* SEEK_SET to start from beginning of file.
* SEEK_CUR to start from current position in file.
* SEEK_END to start from end of file.
*
* @return The new offset of the file.
*/
off_t aos_lseek(int fd, off_t offset, int whence);
/**
* Flush any buffers associated with the file.
*
* @param[in] fd the file descriptor of the file.
*
* @return 0 on success, negative error code on failure.
*/
int aos_sync(int fd);
/**
* Store information about the file in a stat structure.
*
* @param[in] path The path of the file to find information about.
* @param[out] st The stat buffer to write to.
*
* @return 0 on success, negative error code on failure.
*/
int aos_stat(const char *path, struct stat *st);
/**
* Remove a file from the filesystem.
*
* @param[in] path The path of the file to remove.
*
* @return 0 on success, negative error code on failure.
*/
int aos_unlink(const char *path);
/**
* Rename a file in the filesystem.
*
* @param[in] oldpath The path of the file to rename.
* @param[in] newpath The path to rename it to.
*
* @return 0 on success, negative error code on failure.
*/
int aos_rename(const char *oldpath, const char *newpath);
/**
* Open a directory on the filesystem.
*
* @param[in] path the path of the directory to open.
*
* @return a point of directory stream on success, NULL on failure.
*/
aos_dir_t *aos_opendir(const char *path);
/**
* Close a directory.
*
* @param[in] dir the handle of the directory to close.
*
* @return 0 on success, negative error code on failure.
*/
int aos_closedir(aos_dir_t *dir);
/**
* Read the next directory entry.
*
* @param[in] dir the handle of the directory to read.
*
* @return a pointer to a dirent structure.
*/
aos_dirent_t *aos_readdir(aos_dir_t *dir);
/**
* Create the directory, if they do not already exist.
*
* @param[in] path the path of the directory.
*
* @return 0 on success, negative error code on failure.
*/
int aos_mkdir(const char *path);
#ifdef __cplusplus
}
#endif
#endif /* AOS_VFS_H */

View file

@ -0,0 +1,248 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_YLOOP_H
#define AOS_YLOOP_H
#include <aos/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <aos/internal/event_type_code.h>
#ifndef AOS_DOXYGEN_MODE
/* special event filter */
#define EV_ALL 0
#define EV_FLAG_URGENT 0x8000
/* system event */
#define EV_SYS 0x0001
#define CODE_SYS_ON_STARTING 1
#define CODE_SYS_ON_START_COMPLETED 2
#define CODE_SYS_ON_START_FAILED 4
#define CODE_SYS_ON_IDLE 3
#define CODE_SYS_ON_START_FOTA 5
#define CODE_SYS_ON_ALINK_ONLINE 6
#define CODE_SYS_ON_ALINK_OFFLINE 7
#define CODE_SYS_ON_MQTT_READ 8
#define CODE_SYS_ON_COAP_AUTHED 9
/* WiFi event */
#define EV_WIFI 0x0002
#define CODE_WIFI_CMD_RECONNECT 1
#define CODE_WIFI_ON_CONNECTED 2
#define CODE_WIFI_ON_DISCONNECT 3
#define CODE_WIFI_ON_PRE_GOT_IP 4
#define CODE_WIFI_ON_GOT_IP 5
#define CODE_WIFI_ON_CONNECT_FAILED 6
/* Mesh event */
#define EV_MESH 0x0003
/* user app start 0x1000 - 0x7fff */
#define EV_USER 0x1000
/** uData event */
#define EV_UDATA 0x0004
#define CODE_UDATA_DEV_READ 1
#define CODE_UDATA_DEV_IOCTL 2
#define CODE_UDATA_DEV_OPEN 3
#define CODE_UDATA_DEV_CLOSE 4
#define CODE_UDATA_DEV_ENABLE 5
#define CODE_UDATA_DEV_DISABLE 6
#define CODE_UDATA_SERVICE_SUBSRIBE 7 /* for external component */
#define CODE_UDATA_SERVICE_UNSUBSRIBE 8 /* for external component */
#define CODE_UDATA_SERVICE_PROCESS 9
#define CODE_UDATA_SERVICE_IOCTL 10
#define CODE_UDATA_REPORT_PUBLISH 11
/* linkkit event */
#define EV_LINKKIT 0x0005
#endif
typedef struct {
/* The time event is generated, auto filled by aos event system */
uint32_t time;
/* Event type, value < 0x1000 are used by aos system */
uint16_t type;
/* Defined according to type */
uint16_t code;
/* Defined according to type/code */
unsigned long value;
/* Defined according to type/code */
unsigned long extra;
} input_event_t;
/* Event callback */
typedef void (*aos_event_cb)(input_event_t *event, void *private_data);
/* Delayed execution callback */
typedef void (*aos_call_t)(void *arg);
/* Delayed execution callback */
typedef void (*aos_poll_call_t)(int fd, void *arg);
/**
* Register system event filter callback.
*
* @param[in] type event type interested.
* @param[in] cb system event callback.
* @param[in] priv private data past to cb.
*
* @return the operation status, 0 is OK, others is error.
*/
int aos_register_event_filter(uint16_t type, aos_event_cb cb, void *priv);
/**
* Unregister native event callback.
*
* @param[in] type event type interested.
* @param[in] cb system event callback.
* @param[in] priv private data past to cb.
*
* @return the operation status, 0 is OK, others is error.
*/
int aos_unregister_event_filter(uint16_t type, aos_event_cb cb, void *priv);
/**
* Post local event.
*
* @param[in] type event type.
* @param[in] code event code.
* @param[in] value event value.
*
* @return the operation status, 0 is OK,others is error.
*/
int aos_post_event(uint16_t type, uint16_t code, unsigned long value);
/**
* Register a poll event in main loop.
*
* @param[in] fd poll fd.
* @param[in] action action to be executed.
* @param[in] param private data past to action.
*
* @return the operation status, 0 is OK,others is error.
*/
int aos_poll_read_fd(int fd, aos_poll_call_t action, void *param);
/**
* Cancel a poll event to be executed in main loop.
*
* @param[in] fd poll fd.
* @param[in] action action to be executed.
* @param[in] param private data past to action.
*/
void aos_cancel_poll_read_fd(int fd, aos_poll_call_t action, void *param);
/**
* Post a delayed action to be executed in main loop.
*
* @param[in] ms milliseconds to wait.
* @param[in] action action to be executed.
* @param[in] arg private data past to action.
*
* @return the operation status, 0 is OK,others is error.
*/
int aos_post_delayed_action(int ms, aos_call_t action, void *arg);
/**
* Cancel a delayed action to be executed in main loop.
*
* @param[in] ms milliseconds to wait, -1 means don't care.
* @param[in] action action to be executed.
* @param[in] arg private data past to action.
*/
void aos_cancel_delayed_action(int ms, aos_call_t action, void *arg);
/**
* Cancel a delayed action to be executed in main loop.
*
* @param[in] ms milliseconds to wait, -1 means don't care.
* @param[in] action action to be executed.
*/
void aos_cancel_delayed_action_loose(int ms, aos_call_t action);
/**
* Schedule a callback in next event loop.
* Unlike aos_post_delayed_action,
* this function can be called from non-aos-main-loop context.
* @param[in] action action to be executed.
* @param[in] arg private data past to action.
*
* @return the operation status, <0 is error,others is OK.
*/
int aos_schedule_call(aos_call_t action, void *arg);
typedef void *aos_loop_t;
/**
* Init a per-task event loop.
*
* @return the handler of aos_loop_t,NULL failure,others success.
*/
aos_loop_t aos_loop_init(void);
/**
* Get current event loop.
*
* @return default event loop.
*/
aos_loop_t aos_current_loop(void);
/**
* Start event loop.
*/
void aos_loop_run(void);
/**
* Exit event loop, aos_loop_run() will return.
*/
void aos_loop_exit(void);
/**
* Free event loop resources.
*/
void aos_loop_destroy(void);
/**
* Schedule a callback specified event loop.
*
* @param[in] loop event loop to be scheduled, NULL for default main loop.
* @param[in] action action to be executed.
* @param[in] arg private data past to action.
*
* @return the operation status, <0 is error,others is OK.
*/
int aos_loop_schedule_call(aos_loop_t *loop, aos_call_t action, void *arg);
/**
* Schedule a work to be executed in workqueue.
*
* @param[in] ms milliseconds to delay before execution, 0 means immediately.
* @param[in] action action to be executed.
* @param[in] arg1 private data past to action.
* @param[in] fini_cb finish callback to be executed after action is done in current event loop.
* @param[in] arg2 data past to fini_cb.
*
* @return work handle,NULL failure,others is OK.
*/
void *aos_loop_schedule_work(int ms, aos_call_t action, void *arg1,
aos_call_t fini_cb, void *arg2);
/**
* Cancel a work.
*
* @param[in] work work to be cancelled.
* @param[in] action action to be executed.
* @param[in] arg1 private data past to action.
*/
void aos_cancel_work(void *work, aos_call_t action, void *arg1);
#ifdef __cplusplus
}
#endif
#endif /* AOS_YLOOP_H */

View file

@ -0,0 +1,60 @@
#ifndef _AIS_OTA_H_
#define _AIS_OTA_H_
#include <stdbool.h>
#include <bluetooth/bluetooth.h>
typedef enum {
ALI_OTA_FLASH_ERASE_OK = 0,
ALI_OTA_FLASH_ERASE_FAIL,
ALI_OTA_FLASH_STORE_OK,
ALI_OTA_FLASH_STORE_FAIL,
ALI_OTA_FLASH_ERROR = 0xff
} ali_ota_flash_evt_t;
typedef enum {
ALI_OTA_FLASH_CODE_SUCCESS,
ALI_OTA_FLASH_CODE_ERROR
} ali_ota_flash_err_t;
typedef enum {
ALI_OTA_SETTINGS_CODE_SUCCESS,
ALI_OTA_SETTINGS_CODE_ERROR
} ali_ota_settings_err_t;
typedef void (*flash_event_handler_t)(ali_ota_flash_evt_t t);
typedef void (*settings_event_handler_t)(ali_ota_flash_evt_t t);
uint32_t ais_ota_get_setting_fw_offset();
void ais_ota_set_setting_fw_offset(uint32_t offset);
uint32_t ais_ota_get_page_size();
ali_ota_flash_err_t ais_ota_flash_erase(uint32_t const *addr, uint32_t num_pages, flash_event_handler_t cb);
ali_ota_flash_err_t ais_ota_flash_store(uint32_t const *addr, uint32_t const * p_data, uint16_t len, flash_event_handler_t cb);
void ais_ota_flash_init();
void ais_ota_settings_init();
uint32_t ais_ota_get_dst_addr();
ali_ota_settings_err_t ais_ota_settings_write(settings_event_handler_t cb);
bool ais_ota_check_if_resume(uint8_t * p_data, uint16_t length);
void ais_ota_update_fw_version(uint8_t * p_data, uint16_t length);
bool ais_ota_check_if_update_finished();
void ais_ota_update_settings_after_update_finished();
void ais_ota_update_setting_after_xfer_finished(uint32_t img_size, uint32_t img_crc);
int ais_ota_bt_storage_init();
int ais_ota_get_local_addr(bt_addr_le_t *addr);
#endif

View file

@ -0,0 +1,54 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _ATCMD_H_
#define _ATCMD_H_
/**
* AT related platform-dependent definituons are here, including:
* 1. AT command;
* 2. AT response code;
* 3. AT delimiter;
* 4. AT event;
* 5. Uart port used by AT;
* 6. ...
*/
/**
* You will need to define below things in your platform header,
* which is to be included by this file.
*
* -------------------------------------------------------------
* AT commands (mk3060 as example):
* #define AT_CMD_ENET_SEND "AT+ENETRAWSEND"
* #define AT_CMD_ENTER_ENET_MODE "AT+ENETRAWMODE=ON"
* #define AT_CMD_TEST "AT"
* #define AT_CMD_CONNECT_AP "AT+WJAP"
* #define AT_CMD_OBTAIN_MAC "AT+WMAC?"
* #define AT_CMD_OBTAIN_IP "AT+WJAPIP?"
* #define AT_CMD_EHCO_OFF "AT+UARTE=OFF"
*
* AT response:
* #define AT_RSP_SUCCESS "OK"
* #define AT_RSP_FAIL "ERROR"
*
* Delimiter:
* #define AT_RECV_DELIMITER "\r\n"
* #define AT_SEND_DELIMITER "\r"
*
* AT events:
* #define AT_EVENT_GOT_IP "+WEVENT:STATION_UP\r\n"
*
* AT uart:
* #define AT_UART_PORT 1
* #define AT_UART_LINUX_DEV "/dev/ttyUSB1"
* -------------------------------------------------------------
*/
#ifdef AOS_ATCMD
#include <atcmd_config_platform.h>
#include <atcmd_config_module.h>
#endif
#endif // #ifndef _ATCMD_H_

View file

@ -0,0 +1,29 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_BASE_H
#define HAL_BASE_H
#include <aos/aos.h>
/*
* HAL common error code
*/
enum {
HAL_ERR_ARG = -4096,
HAL_ERR_CAP,
};
/*
* HAL Module define
*/
typedef struct {
dlist_t list;
int magic;
const char *name;
void *priv_dev; /* Driver may want to describe it */
} hal_module_base_t;
#endif /* HAL_BASE_H */

View file

@ -0,0 +1,21 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_HAL_H_
#define HAL_HAL_H_
#include <stdint.h>
#include <stddef.h>
#include <hal/base.h>
#include <hal/ota.h>
#include <hal/sensor.h>
#include <hal/trace.h>
#include <hal/wifi.h>
#include <hal/atcmd.h>
#include <hal/soc/soc.h>
#endif /* HAL_HAL_H */

View file

@ -0,0 +1,62 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_LRWAN_H
#define HAL_LRWAN_H
#ifdef __cplusplus
extern "C" {
#endif
/*INCLUDES*******************************************************************
* SYSTEM HEADER FILES
*END***********************************************************************/
#include <stdint.h>
#include "base.h"
#include "timeServer.h"
/*MACROS*********************************************************************
* DATATYPE DEFINITIONS
*END***********************************************************************/
/* the struct is for changing the device working mode */
typedef struct
{
void (*enter_stop_mode)(void);
void (*exit_stop_mode)(void);
void (*enter_sleep_mode)(void);
} hal_lrwan_dev_chg_mode_t;
/* LoRaWan time and timer interface */
typedef struct
{
void (*delay_ms)(uint32_t delay);
uint32_t (*set_timer_context)(void);
uint32_t (*get_timer_context)(void);
uint32_t (*get_timer_elapsed_time)(void);
void (*stop_alarm)(void);
void (*set_alarm)(uint32_t timeout);
void (*set_uc_wakeup_time)(void);
void (*set_timeout)(TimerEvent_t *obj);
TimerTime_t (*compute_elapsed_time)(TimerTime_t time);
TimerTime_t (*get_current_time)(void );
void (*set_timer_val)(TimerEvent_t *obj, uint32_t value);
} hal_lrwan_time_itf_t;
/* the struct is for control of radio */
typedef struct
{
void (*radio_reset)(void);
void (*radio_reset_cfg_input)(void);
void (*radio_rw_en)(void);
void (*radio_rw_dis)(void);
uint16_t (*radio_rw)(uint16_t tx_data);
} hal_lrwan_radio_ctrl_t;
#ifdef __cplusplus
}
#endif
#endif /* HAL_LRWAN_H */

View file

@ -0,0 +1,134 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_OTA_H
#define HAL_OTA_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "base.h"
typedef enum {
OTA_KERNEL,
OTA_APP,
OTA_ALL
} OTA_ENUM_UPDATE_TYPE;
typedef enum {
OTA_FINISH,
OTA_BREAKPOINT
} OTA_ENUM_RESULT_TYPE;
enum ota_parti_e {
OTA_PARTITION_KERNEL,
OTA_PARTITION_APP,
OTA_PARTITION_DEFAULT,
};
typedef struct {
OTA_ENUM_UPDATE_TYPE update_type;
OTA_ENUM_RESULT_TYPE result_type ;
} ota_finish_param_t;
typedef struct {
uint32_t start_address; /* the address of the bin saved on flash. */
uint32_t length; /* file real length */
uint8_t version[8];
uint8_t type; /* B:bootloader, P:boot_table, A:application, D: 8782 driver */
uint8_t upgrade_type; /* u:upgrade */
uint16_t crc;
uint8_t reserved[4];
} boot_table_t;
typedef struct hal_ota_module_s hal_ota_module_t;
typedef int hal_stat_t;
struct hal_ota_module_s {
hal_module_base_t base;
/* Link to HW */
int (*init)(hal_ota_module_t *m, void *something);
int (*ota_write)(hal_ota_module_t *m, volatile uint32_t *off_set,
uint8_t *in_buf , uint32_t in_buf_len);
int (*ota_read)(hal_ota_module_t *m, volatile uint32_t *off_set,
uint8_t *out_buf , uint32_t out_buf_len);
int (*ota_set_boot)(hal_ota_module_t *m, void *something);
};
/**
* Arch register a new module before HAL startup
*/
void hal_ota_register_module(hal_ota_module_t *module);
/**
* init ota partition
*
* @note when ota start, maybe it need init something
* @param something extra info for ota init
*
* @return 0 : On success, 1 : If an error occurred with any step
*/
hal_stat_t hal_ota_init(void *something);
/**
* Write data to an area on ota partition
*
* @param m Refer the ota module which will be used,default module will be used if value is NULL
* @param off_set Point to the start address that the data is written to, and
* point to the last unwritten address after this function is
* returned, so you can call this function serval times without
* update this start address.
* @param inbuf point to the data buffer that will be written to flash
* @param in_buf_len The length of the buffer
*
* @return 0 : On success, 1 : If an error occurred with any step
*/
hal_stat_t hal_ota_write(hal_ota_module_t *m, volatile uint32_t *off_set,
uint8_t *in_buf , uint32_t in_buf_len);
/**
* Read data from an area on ota Flash to data buffer in RAM
*
* @param m Refer the ota module which will be used,default module will be used if value is NULL
* @param off_set Point to the start address that the data is read, and
* point to the last unread address after this function is
* returned, so you can call this function serval times without
* update this start address.
* @param out_buf Point to the data buffer that stores the data read from flash
* @param out_buf_len The length of the buffer
*
* @return 0 : On success, 1 : If an error occurred with any step
*/
hal_stat_t hal_ota_read(hal_ota_module_t *m, volatile uint32_t *off_set,
uint8_t *out_buf, uint32_t out_buf_len);
/**
* Set boot options when ota reboot
*
* @param m Refer the ota module which will be used,default module will be used if value is NULL
* @param something boot parms
*
* @return kNoErr : On success. kGeneralErr : If an error occurred with any step
*/
hal_stat_t hal_ota_set_boot(hal_ota_module_t *m, void *something);
/**
* Get the default ota module
*
* @return the first registered ota module ,which is the head of module list
*/
hal_ota_module_t *hal_ota_get_default_module(void);
#ifdef __cplusplus
}
#endif
#endif /* HAL_OTA_H */

View file

@ -0,0 +1,322 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*
* sensor hal
*/
#ifndef HAL_SENSOR_H
#define HAL_SENSOR_H
#include <stdint.h>
#include <hal/base.h>
#include "hal/soc/soc.h"
#include "hal/soc/gpio.h"
#include "hal/soc/i2c.h"
#define I2C_REG_LEN 1
#define I2C_DATA_LEN 1
#define I2C_OP_RETRIES AOS_WAIT_FOREVER
/* ioctl cmd list for sensor */
#define SENSOR_IOCTL_ODR_SET (0x01<<0)
#define SENSOR_IOCTL_RANGE_SET (0x01<<1)
#define SENSOR_IOCTL_GET_INFO (0x01<<2)
#define SENSOR_IOCTL_BIST_PROCESS (0x01<<3)
#define SENSOR_IOCTL_WHO_AM_I (0x01<<4)
#define SENSOR_IOCTL_SET_POWER (0x01<<5)
#define SENSOR_IOCTL_GET_SENSOR_LIST (0x01<<6)
#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
#endif
#ifndef unlikely
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
/* Physical generic sensor data defs generic structs here*/
#define DATA_AXIS_X 0
#define DATA_AXIS_Y 1
#define DATA_AXIS_Z 2
#define dev_acc_path "/dev/acc"
#define dev_mag_path "/dev/mag"
#define dev_gyro_path "/dev/gyro"
#define dev_als_path "/dev/als"
#define dev_ps_path "/dev/ps"
#define dev_baro_path "/dev/baro"
#define dev_temp_path "/dev/temp"
#define dev_uv_path "/dev/uv"
#define dev_humi_path "/dev/humi"
#define dev_hall_path "/dev/hall"
#define dev_hr_path "/dev/hr"
#define dev_gps_path "/dev/gps"
#define sensor_node_path "/dev/sensor"
#define gps_node_path "/dev/nodegps"
#define GPS_STR "gps: "
#define SENSOR_STR "sensor: " /* sensor debug header */
#define ERROR_LINE "error on line is "
#define ACCELEROMETER_UNIT_FACTOR 1000 //mg
#define MAGNETOMETER_UNIT_FACTOR 1000 //mGauss
#define GYROSCOPE_UNIT_FACTOR 1000000 //uDPS
/* add the new sensor type into the last postion */
typedef enum{
TAG_DEV_ACC = 0, /* Accelerometer */
TAG_DEV_MAG, /* Magnetometer */
TAG_DEV_GYRO, /* Gyroscope */
TAG_DEV_ALS, /* Ambient light sensor */
TAG_DEV_PS, /* Proximity */
TAG_DEV_BARO, /* Barometer */
TAG_DEV_TEMP, /* Temperature */
TAG_DEV_UV, /* Ultraviolet */
TAG_DEV_HUMI, /* Humidity */
TAG_DEV_HALL, /* HALL */
TAG_DEV_HR, /* Heart Rate */
TAG_DEV_GPS,
TAG_DEV_SENSOR_NUM_MAX,
} sensor_tag_e;
typedef enum {
DEV_SENSOR_VENDOR_STM = 0,
DEV_SENSOR_VENDOR_SEMTECH,
DEV_SENSOR_VENDOR_AKM,
DEV_SENSOR_VENDOR_CAPELLA,
DEV_SENSOR_VENDOR_INVENSENSE,
DEV_SENSOR_VENDOR_ROHM,
DEV_SENSOR_VENDOR_BOSCH,
DEV_SENSOR_VENDOR_KIONIX,
DEV_SENSOR_VENDOR_LITEON,
DEV_SENSOR_VENDOR_AMS,
DEV_SENSOR_VENDOR_CNT_MAXIM,
} vendor_id_e;
typedef enum {
I2C_PORT,
SPI_PORT,
I2S_PORT,
UART_PORT,
} dev_io_port_e;
typedef enum {
DEV_POWER_OFF = 0,
DEV_POWER_ON,
DEV_SLEEP,
DEV_SUSPEND,
DEV_DEEP_SUSPEND,
} dev_power_mode_e;
typedef enum {
DEV_HEALTH_GOOD,
DEV_HEALTH_SICK,
} dev_health_state_e;
typedef enum {
DEV_POLLING = 0,
DEV_INT,
DEV_DATA_READY,
DEV_FIFO,
DEV_MODE_INV
} work_mode_e;
typedef enum {
mg = 0,
uGauss,
udps,
lux,
cm,
pa,
permillage,
bpm,
dCelsius,
} value_unit_e;
typedef struct _dev_accel_data_t {
uint64_t timestamp;
int32_t data[3];
#ifdef AOS_SENSOR_ACC_SUPPORT_STEP
uint32_t step;
#endif
}accel_data_t;
typedef struct _dev_gyro_data_t {
uint64_t timestamp;
int32_t data[3];
}gyro_data_t;
typedef struct _dev_mag_data_t {
uint64_t timestamp;
int32_t data[3];
}mag_data_t;
typedef struct _dev_barometer_data_t{
uint64_t timestamp;
uint32_t p;
}barometer_data_t;
typedef struct _dev_temperature_data_t{
uint64_t timestamp;
int32_t t;
}temperature_data_t;
typedef struct _dev_humidity_data_t{
uint64_t timestamp;
uint32_t h;
}humidity_data_t;
typedef struct _dev_als_data_t{
uint64_t timestamp;
uint32_t lux;
}als_data_t;
typedef struct _dev_uv_data_t{
uint64_t timestamp;
uint16_t uvi;
}uv_data_t;
typedef struct _dev_proximity_data_t{
uint64_t timestamp;
uint32_t present;
}proximity_data_t;
typedef struct _dev_hall_data_t {
uint64_t timestamp;
uint8_t hall_level;
}hall_data_t;
typedef struct _dev_rgb_data_t{
uint64_t timestamp;
uint32_t data[3];
}rgb_data_t;
typedef struct _dev_ir_data_t{
uint64_t timestamp;
uint32_t ir;
}ir_data_t;
typedef struct _dev_ecg_data_t{
uint64_t timestamp;
int16_t raw_data;
}ecg_data_t;
typedef struct _dev_heart_rate_data_t {
uint64_t timestamp;
uint8_t hear_rate;
}heart_rate_data_t;
typedef struct _dev_blood_pressure_data_t {
uint64_t timestamp;
uint16_t systolic;
uint16_t diastolic;
}blood_pressure_t;
typedef struct _dev_sensor_config_t {
uint8_t id;
uint32_t range;
uint32_t odr;
}dev_sensor_config_t;
typedef struct _sensor_list_t{
uint32_t cnt;
uint8_t list[TAG_DEV_SENSOR_NUM_MAX];
}sensor_list_t;
typedef struct _dev_sensor_info_t {
vendor_id_e vendor;
char* model;
value_unit_e unit;
uint32_t range_max;
uint32_t range_min;
dev_health_state_e health;
//sensor_list_t list;
}dev_sensor_info_t;
typedef struct _dev_sensor_full_info_t {
dev_sensor_info_t info;
dev_sensor_config_t config;
}dev_sensor_full_info_t;
typedef struct _dev_sensor_data_t {
uint64_t timestamp;
int32_t data[3];
}dev_sensor_data_t;
typedef struct _dev_sensor_pkg_t {
sensor_tag_e tag;
union{
dev_sensor_info_t info;
dev_sensor_config_t config;
dev_sensor_data_t data;
}allocator;
}dev_sensor_pkg_t;
typedef struct _sensor_obj_t {
char* path;
sensor_tag_e tag;
dev_io_port_e io_port;
work_mode_e mode;
dev_power_mode_e power;
gpio_dev_t gpio;
dev_sensor_full_info_t info;
uint8_t ref;
int (*open)(void);
int (*close)(void);
int (*read)(void *, size_t);
int (*write)(const void *buf, size_t len);
int (*ioctl)(int cmd, unsigned long arg);
void(*irq_handle)(void);
}sensor_obj_t;
typedef struct _sensor_node_t{
sensor_tag_e tag;
char *path;
int fd;
} sensor_node_t;
typedef enum{
ACC_RANGE_2G,
ACC_RANGE_4G,
ACC_RANGE_8G,
ACC_RANGE_16G,
ACC_RANGE_MAX
}acc_range_e;
typedef enum{
GYRO_RANGE_125DPS,
GYRO_RANGE_250DPS,
GYRO_RANGE_500DPS,
GYRO_RANGE_1000DPS,
GYRO_RANGE_2000DPS,
GYRO_RANGE_MAX
}gyro_range_e;
typedef struct _gps_time
{
int year;
int mon;
int day;
int hour;
int min;
int sec;
int hsec;
} gps_time_t;
typedef struct _dev_gps_data_t {
uint64_t timestamp;
gps_time_t utc;
float lat;
float lon;
float elv;
}gps_data_t;
#endif /* HAL_SENSOR_H */

View file

@ -0,0 +1,48 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_ADC_H
#define HAL_ADC_H
typedef struct {
uint32_t sampling_cycle; /* sampling period in number of ADC clock cycles */
} adc_config_t;
typedef struct {
uint8_t port; /* adc port */
adc_config_t config; /* adc config */
void *priv; /* priv data */
} adc_dev_t;
/**
* Initialises an ADC interface, Prepares an ADC hardware interface for sampling
*
* @param[in] adc the interface which should be initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_adc_init(adc_dev_t *adc);
/**
* Takes a single sample from an ADC interface
*
* @param[in] adc the interface which should be sampled
* @param[out] output pointer to a variable which will receive the sample
* @param[in] timeout ms timeout
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_adc_value_get(adc_dev_t *adc, void *output, uint32_t timeout);
/**
* De-initialises an ADC interface, Turns off an ADC hardware interface
*
* @param[in] adc the interface which should be de-initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_adc_finalize(adc_dev_t *adc);
#endif /* HAL_ADC_H */

View file

@ -0,0 +1,157 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_FLASH_H
#define HAL_FLASH_H
#define PAR_OPT_READ_POS ( 0 )
#define PAR_OPT_WRITE_POS ( 1 )
#define PAR_OPT_READ_MASK ( 0x1u << PAR_OPT_READ_POS )
#define PAR_OPT_WRITE_MASK ( 0x1u << PAR_OPT_WRITE_POS )
#define PAR_OPT_READ_DIS ( 0x0u << PAR_OPT_READ_POS )
#define PAR_OPT_READ_EN ( 0x1u << PAR_OPT_READ_POS )
#define PAR_OPT_WRITE_DIS ( 0x0u << PAR_OPT_WRITE_POS )
#define PAR_OPT_WRITE_EN ( 0x1u << PAR_OPT_WRITE_POS )
typedef enum {
HAL_PARTITION_ERROR = -1,
HAL_PARTITION_BOOTLOADER,
HAL_PARTITION_APPLICATION,
HAL_PARTITION_ATE,
HAL_PARTITION_OTA_TEMP,
HAL_PARTITION_RF_FIRMWARE,
HAL_PARTITION_PARAMETER_1,
HAL_PARTITION_PARAMETER_2,
HAL_PARTITION_PARAMETER_3,
HAL_PARTITION_PARAMETER_4,
HAL_PARTITION_BT_FIRMWARE,
HAL_PARTITION_SPIFFS,
HAL_PARTITION_SYS_DATA,
HAL_PARTITION_HFILOP,
HAL_PARTITION_META_DATA,
HAL_PARTITION_MAX,
HAL_PARTITION_NONE,
} hal_partition_t;
typedef enum {
HAL_FLASH_EMBEDDED,
HAL_FLASH_SPI,
HAL_FLASH_QSPI,
HAL_FLASH_MAX,
HAL_FLASH_NONE,
} hal_flash_t;
typedef struct {
hal_flash_t partition_owner;
const char *partition_description;
uint32_t partition_start_addr;
uint32_t partition_length;
uint32_t partition_options;
} hal_logic_partition_t;
/**
* Get the infomation of the specified flash area
*
* @param[in] in_partition The target flash logical partition
*
* @return HAL_logi_partition struct
*/
hal_logic_partition_t *hal_flash_get_info(hal_partition_t in_partition);
/**
* Erase an area on a Flash logical partition
*
* @note Erase on an address will erase all data on a sector that the
* address is belonged to, this function does not save data that
* beyond the address area but in the affected sector, the data
* will be lost.
*
* @param[in] in_partition The target flash logical partition which should be erased
* @param[in] off_set Start address of the erased flash area
* @param[in] size Size of the erased flash area
*
* @return 0 : On success, EIO : If an error occurred with any step
*/
int32_t hal_flash_erase(hal_partition_t in_partition, uint32_t off_set, uint32_t size);
/**
* Write data to an area on a flash logical partition without erase
*
* @param[in] in_partition The target flash logical partition which should be read which should be written
* @param[in] off_set Point to the start address that the data is written to, and
* point to the last unwritten address after this function is
* returned, so you can call this function serval times without
* update this start address.
* @param[in] inBuffer point to the data buffer that will be written to flash
* @param[in] inBufferLength The length of the buffer
*
* @return 0 : On success, EIO : If an error occurred with any step
*/
int32_t hal_flash_write(hal_partition_t in_partition, uint32_t *off_set,
const void *in_buf, uint32_t in_buf_len);
/**
* Write data to an area on a flash logical partition with erase first
*
* @param[in] in_partition The target flash logical partition which should be read which should be written
* @param[in] off_set Point to the start address that the data is written to, and
* point to the last unwritten address after this function is
* returned, so you can call this function serval times without
* update this start address.
* @param[in] inBuffer point to the data buffer that will be written to flash
* @param[in] inBufferLength The length of the buffer
*
* @return 0 : On success, EIO : If an error occurred with any step
*/
int32_t hal_flash_erase_write(hal_partition_t in_partition, uint32_t *off_set,
const void *in_buf, uint32_t in_buf_len);
/**
* Read data from an area on a Flash to data buffer in RAM
*
* @param[in] in_partition The target flash logical partition which should be read
* @param[in] off_set Point to the start address that the data is read, and
* point to the last unread address after this function is
* returned, so you can call this function serval times without
* update this start address.
* @param[in] outBuffer Point to the data buffer that stores the data read from flash
* @param[in] inBufferLength The length of the buffer
*
* @return 0 : On success, EIO : If an error occurred with any step
*/
int32_t hal_flash_read(hal_partition_t in_partition, uint32_t *off_set,
void *out_buf, uint32_t in_buf_len);
/**
* Set security options on a logical partition
*
* @param[in] partition The target flash logical partition
* @param[in] offset Point to the start address that the data is read, and
* point to the last unread address after this function is
* returned, so you can call this function serval times without
* update this start address.
* @param[in] size Size of enabled flash area
*
* @return 0 : On success, EIO : If an error occurred with any step
*/
int32_t hal_flash_enable_secure(hal_partition_t partition, uint32_t off_set, uint32_t size);
/**
* Disable security options on a logical partition
*
* @param[in] partition The target flash logical partition
* @param[in] offset Point to the start address that the data is read, and
* point to the last unread address after this function is
* returned, so you can call this function serval times without
* update this start address.
* @param[in] size Size of disabled flash area
*
* @return 0 : On success, EIO : If an error occurred with any step
*/
int32_t hal_flash_dis_secure(hal_partition_t partition, uint32_t off_set, uint32_t size);
#endif /* HAL_FLASH_H */

154
Living_SDK/include/hal/soc/gpio.h Executable file
View file

@ -0,0 +1,154 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_GPIO_H
#define HAL_GPIO_H
/*
* Pin configuration
*/
typedef enum {
ANALOG_MODE, /* Used as a function pin, input and output analog */
IRQ_MODE, /* Used to trigger interrupt */
INPUT_PULL_UP, /* Input with an internal pull-up resistor - use with devices
that actively drive the signal low - e.g. button connected to ground */
INPUT_PULL_DOWN, /* Input with an internal pull-down resistor - use with devices
that actively drive the signal high - e.g. button connected to a power rail */
INPUT_HIGH_IMPEDANCE, /* Input - must always be driven, either actively or by an external pullup resistor */
OUTPUT_PUSH_PULL, /* Output actively driven high and actively driven low -
must not be connected to other active outputs - e.g. LED output */
OUTPUT_OPEN_DRAIN_NO_PULL, /* Output actively driven low but is high-impedance when set high -
can be connected to other open-drain/open-collector outputs.
Needs an external pull-up resistor */
OUTPUT_OPEN_DRAIN_PULL_UP, /* Output actively driven low and is pulled high
with an internal resistor when set high -
can be connected to other open-drain/open-collector outputs. */
} gpio_config_t;
/*
* GPIO dev struct
*/
typedef struct {
uint8_t port; /* gpio port */
gpio_config_t config; /* gpio config */
void *priv; /* priv data */
} gpio_dev_t;
/*
* GPIO interrupt trigger
*/
typedef enum {
IRQ_TRIGGER_RISING_EDGE = 0x1, /* Interrupt triggered at input signal's rising edge */
IRQ_TRIGGER_FALLING_EDGE = 0x2, /* Interrupt triggered at input signal's falling edge */
IRQ_TRIGGER_BOTH_EDGES = IRQ_TRIGGER_RISING_EDGE | IRQ_TRIGGER_FALLING_EDGE,
} gpio_irq_trigger_t;
/*
* GPIO interrupt callback handler
*/
typedef void (*gpio_irq_handler_t)(void *arg);
/**
* Initialises a GPIO pin
*
* @note Prepares a GPIO pin for use.
*
* @param[in] gpio the gpio pin which should be initialised
* @param[in] configuration A structure containing the required gpio configuration
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_gpio_init(gpio_dev_t *gpio);
/**
* Sets an output GPIO pin high
*
* @note Using this function on a gpio pin which is set to input mode is undefined.
*
* @param[in] gpio the gpio pin which should be set high
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_gpio_output_high(gpio_dev_t *gpio);
/**
* Sets an output GPIO pin low
*
* @note Using this function on a gpio pin which is set to input mode is undefined.
*
* @param[in] gpio the gpio pin which should be set low
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_gpio_output_low(gpio_dev_t *gpio);
/**
* Trigger an output GPIO pin's output. Using this function on a
* gpio pin which is set to input mode is undefined.
*
* @param[in] gpio the gpio pin which should be set low
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_gpio_output_toggle(gpio_dev_t *gpio);
/**
* Get the state of an input GPIO pin. Using this function on a
* gpio pin which is set to output mode will return an undefined value.
*
* @param[in] gpio the gpio pin which should be read
* @param[in] value gpio value
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_gpio_input_get(gpio_dev_t *gpio, uint32_t *value);
/**
* Enables an interrupt trigger for an input GPIO pin.
* Using this function on a gpio pin which is set to
* output mode is undefined.
*
* @param[in] gpio the gpio pin which will provide the interrupt trigger
* @param[in] trigger the type of trigger (rising/falling edge)
* @param[in] handler a function pointer to the interrupt handler
* @param[in] arg an argument that will be passed to the interrupt handler
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_gpio_enable_irq(gpio_dev_t *gpio, gpio_irq_trigger_t trigger,
gpio_irq_handler_t handler, void *arg);
/**
* Disables an interrupt trigger for an input GPIO pin.
* Using this function on a gpio pin which has not been set up
* using @ref hal_gpio_input_irq_enable is undefined.
*
* @param[in] gpio the gpio pin which provided the interrupt trigger
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_gpio_disable_irq(gpio_dev_t *gpio);
/**
* Disables an interrupt trigger for an input GPIO pin.
* Using this function on a gpio pin which has not been set up
* using @ref hal_gpio_input_irq_enable is undefined.
*
* @param[in] gpio the gpio pin which provided the interrupt trigger
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_gpio_clear_irq(gpio_dev_t *gpio);
/**
* Set a GPIO pin in default state.
*
* @param[in] gpio the gpio pin which should be deinitialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_gpio_finalize(gpio_dev_t *gpio);
#endif /* HAL_GPIO_H */

134
Living_SDK/include/hal/soc/i2c.h Executable file
View file

@ -0,0 +1,134 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_I2C_H
#define HAL_I2C_H
#define I2C_MODE_MASTER 1 /* i2c communication is master mode */
#define I2C_MODE_SLAVE 2 /* i2c communication is slave mode */
#define I2C_MEM_ADDR_SIZE_8BIT 1 /* i2c menory address size 8bit */
#define I2C_MEM_ADDR_SIZE_16BIT 2 /* i2c menory address size 16bit */
typedef struct {
uint32_t address_width;
uint32_t freq;
uint8_t mode;
uint16_t dev_addr;
} i2c_config_t;
typedef struct {
uint8_t port; /* i2c port */
i2c_config_t config; /* i2c config */
void *priv; /* priv data */
} i2c_dev_t;
/**
* Initialises an I2C interface
* Prepares an I2C hardware interface for communication as a master or slave
*
* @param[in] i2c the device for which the i2c port should be initialised
*
* @return 0 : on success, EIO : if an error occurred during initialisation
*/
int32_t hal_i2c_init(i2c_dev_t *i2c);
/**
* I2c master send
*
* @param[in] i2c the i2c device
* @param[in] dev_addr device address
* @param[in] data i2c send data
* @param[in] size i2c send data size
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if an error occurred during initialisation
*/
int32_t hal_i2c_master_send(i2c_dev_t *i2c, uint16_t dev_addr, const uint8_t *data,
uint16_t size, uint32_t timeout);
/**
* I2c master recv
*
* @param[in] i2c the i2c device
* @param[in] dev_addr device address
* @param[out] data i2c receive data
* @param[in] size i2c receive data size
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if an error occurred during initialisation
*/
int32_t hal_i2c_master_recv(i2c_dev_t *i2c, uint16_t dev_addr, uint8_t *data,
uint16_t size, uint32_t timeout);
/**
* I2c slave send
*
* @param[in] i2c the i2c device
* @param[in] data i2c slave send data
* @param[in] size i2c slave send data size
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if an error occurred during initialisation
*/
int32_t hal_i2c_slave_send(i2c_dev_t *i2c, const uint8_t *data, uint16_t size, uint32_t timeout);
/**
* I2c slave receive
*
* @param[in] i2c tthe i2c device
* @param[out] data i2c slave receive data
* @param[in] size i2c slave receive data size
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if an error occurred during initialisation
*/
int32_t hal_i2c_slave_recv(i2c_dev_t *i2c, uint8_t *data, uint16_t size, uint32_t timeout);
/**
* I2c mem write
*
* @param[in] i2c the i2c device
* @param[in] dev_addr device address
* @param[in] mem_addr mem address
* @param[in] mem_addr_size mem address
* @param[in] data i2c master send data
* @param[in] size i2c master send data size
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if an error occurred during initialisation
*/
int32_t hal_i2c_mem_write(i2c_dev_t *i2c, uint16_t dev_addr, uint16_t mem_addr,
uint16_t mem_addr_size, const uint8_t *data, uint16_t size,
uint32_t timeout);
/**
* I2c master mem read
*
* @param[in] i2c the i2c device
* @param[in] dev_addr device address
* @param[in] mem_addr mem address
* @param[in] mem_addr_size mem address
* @param[out] data i2c master send data
* @param[in] size i2c master send data size
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if an error occurred during initialisation
*/
int32_t hal_i2c_mem_read(i2c_dev_t *i2c, uint16_t dev_addr, uint16_t mem_addr,
uint16_t mem_addr_size, uint8_t *data, uint16_t size,
uint32_t timeout);
/**
* Deinitialises an I2C device
*
* @param[in] i2c the i2c device
*
* @return 0 : on success, EIO : if an error occurred during deinitialisation
*/
int32_t hal_i2c_finalize(i2c_dev_t *i2c);
#endif /* HAL_I2C_H */

View file

@ -0,0 +1,54 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_INTERPT_H
#define HAL_INTERPT_H
typedef void (*hal_interpt_t)(int32_t vec, void *para);
typedef struct {
hal_interpt_t fun;
void *para;
} hal_interpt_desc_t;
/**
* Interrupt vector init
*
* @return 0 : on success, -1 : if an error occurred with any step
*/
int32_t hal_interpt_init(void);
/**
* Mask specified interrupt vector
*
*
* @param[in] vec specified interrupt vector
*
* @return 0 : on success, -1 : if an error occurred with any step
*/
int32_t hal_interpt_mask(int32_t vec);
/**
* Unmask specified interrupt vector
*
*
* @param[in] vec specified interrupt vector
*
* @return 0 : on success, -1 : if an error occurred with any step
*/
int32_t hal_interpt_umask(int32_t vec);
/**
* Install specified interrupt vector
*
*
* @param[in] vec specified interrupt vector
*
* @return 0 : on success, -1 : if an error occurred with any step
*/
int32_t hal_interpt_install(int32_t vec, hal_interpt_t handler,
void *para, char *name);
#endif

View file

@ -0,0 +1,105 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_NAND_H
#define HAL_NAND_H
typedef struct {
uint32_t page_size; /* NAND memory page size w/o spare area */
uint32_t spare_area_size; /* NAND memory spare area size */
uint32_t block_size; /* NAND memory block size number of pages */
uint32_t zone_size; /* NAND memory zone size measured in number of blocks */
uint32_t zone_number; /* NAND memory number of zones */
} nand_config_t;
typedef struct {
uint16_t page; /* NAND memory Page address */
uint16_t block; /* NAND memory Block address */
uint16_t zone; /* NAND memory Zone address */
} nand_addr_t;
typedef struct {
uint32_t base_addr;
nand_config_t config;
void *priv;
} nand_dev_t;
/**
* Initialises a nand flash interface
*
* @param[in] nand the interface which should be initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nand_init(nand_dev_t *nand);
/**
* Deinitialises a nand flash interface
*
* @param[in] nand the interface which should be initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nand_finalize(nand_dev_t *nand);
/**
* Read nand page(s)
*
* @param[in] nand the interface which should be initialised
* @param[out] data pointer to the buffer which will store incoming data
* @param[in] addr nand address
* @param[in] page_count the number of pages to read
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nand_read_page(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t page_count);
/**
* Write nand page(s)
*
* @param[in] nand the interface which should be initialised
* @param[in] data pointer to source buffer to write
* @param[in] addr nand address
* @param[in] page_count the number of pages to write
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nand_write_page(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t page_count);
/**
* Read nand spare area
*
* @param[in] nand the interface which should be initialised
* @param[out] data pointer to the buffer which will store incoming data
* @param[in] addr nand address
* @param[in] data_len the number of spares to read
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nand_read_spare(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t data_len);
/**
* Write nand spare area
*
* @param[in] nand the interface which should be initialised
* @param[in] data pointer to source buffer to write
* @param[in] addr nand address
* @param[in] data_len the number of spares to write
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nand_write_spare(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t data_len);
/**
* Erase nand block
*
* @param[in] nand the interface which should be initialised
* @param[in] addr nand address
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nand_erase_block(nand_dev_t *nand, nand_addr_t *addr);
#endif

View file

@ -0,0 +1,83 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_NOR_H
#define HAL_NOR_H
typedef struct {
uint32_t block_size; /* NOR memory block size number of bytes */
uint32_t chip_size; /* NOR memory chip size measured in number of blocks */
} nor_config_t;
typedef struct {
uint32_t base_addr;
nor_config_t config;
void *priv;
} nor_dev_t;
/**
* Initialises a nor flash interface
*
* @param[in] nor the interface which should be initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nor_init(nor_dev_t *nor);
/**
* Deinitialises a nor flash interface
*
* @param[in] nand the interface which should be initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nor_finalize(nor_dev_t *nor);
/**
* Read data from NOR memory
*
* @param[in] nor the interface which should be initialised
* @param[out] data pointer to the buffer which will store incoming data
* @param[in] addr nor memory address
* @param[in] len the number of bytes to read
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nor_read(nor_dev_t *nor, uint32_t *addr, uint8_t *data, uint32_t len);
/**
* Write data to NOR memory
*
* @param[in] nor the interface which should be initialised
* @param[in] data pointer to source buffer to write
* @param[in] addr nor memory address
* @param[in] len the number of bytes to write
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nor_write(nor_dev_t *nor, uint32_t *addr, uint8_t *data, uint32_t len);
/*
* Erase the blocks of the NOR memory
*
* @param[in] nor the interface which should be initialised
* @param[in] addr nor memory address
* @param[in] block_count the number of block to erase
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nor_erase_block(nor_dev_t *nor, uint32_t *addr, uint32_t block_count);
/*
* Erase the entire NOR chip
*
* @param[in] nor the interface which should be initialised
* @param[in] addr nor memory address
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_nor_erase_chip(nor_dev_t *nor, uint32_t *addr);
#endif

View file

@ -0,0 +1,56 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_PWM_H
#define HAL_PWM_H
typedef struct {
float duty_cycle; /* the pwm duty_cycle */
uint32_t freq; /* the pwm freq */
} pwm_config_t;
typedef struct {
uint8_t port; /* pwm port */
pwm_config_t config; /* spi config */
void *priv; /* priv data */
} pwm_dev_t;
/**
* Initialises a PWM pin
*
*
* @param[in] pwm the PWM device
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_pwm_init(pwm_dev_t *pwm);
/**
* Starts Pulse-Width Modulation signal output on a PWM pin
*
* @param[in] pwm the PWM device
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_pwm_start(pwm_dev_t *pwm);
/**
* Stops output on a PWM pin
*
* @param[in] pwm the PWM device
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_pwm_stop(pwm_dev_t *pwm);
/**
* De-initialises an PWM interface, Turns off an PWM hardware interface
*
* @param[in] pwm the interface which should be de-initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_pwm_finalize(pwm_dev_t *pwm);
#endif /* HAL_PWM_H */

View file

@ -0,0 +1,89 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_QSPI_H
#define HAL_QSPI_H
typedef struct {
uint32_t freq; /* communication frequency Hz */
} qspi_config_t;
typedef struct {
uint8_t port; /* qspi port */
qspi_config_t config; /* qspi config */
void *priv; /* priv data */
} qspi_dev_t;
typedef struct {
uint32_t instruction; /* qspi instruction */
uint32_t address; /* qspi cmd address */
uint32_t size; /* qspi cmd size */
} qspi_cmd_t;
/**
* Initialises the QSPI interface for a given QSPI device
*
* @param[in] qspi the spi device
*
* @return 0 : on success, EIO : if an error occurred
*/
int32_t hal_qspi_init(qspi_dev_t *qspi);
/**
* Qspi send
*
* @param[in] qspi the qspi device
* @param[in] data spi send data
* @param[in] size spi send data size
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if an error occurred
*/
int32_t hal_qspi_send(qspi_dev_t *qspi, const uint8_t *data, uint32_t timeout);
/**
* Qspi recv
*
* @param[in] qspi the qspi device
* @param[out] data qspi recv data
* @param[in] size qspi recv data size
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if an error occurred
*/
int32_t hal_qspi_recv(qspi_dev_t *qspi, uint8_t *data, uint32_t timeout);
/**
* Set qspi command
*
* @param[in] qspi the qspi device
* @param[out] cmd qspi cmd
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if an error occurred
*/
int32_t hal_qspi_command(qspi_dev_t *qspi, qspi_cmd_t *cmd, uint32_t timeout);
/**
* Configure automatic polling mode to wait for processing
*
* @param[in] qspi the qspi device
* @param[out] cmd qspi cmd
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if an error occurred
*/
int32_t hal_qspi_auto_polling(qspi_dev_t *qspi, uint32_t cmd, uint32_t timeout);
/**
* De-initialises a QSPI interface
*
* @param[in] qspi the QSPI device to be de-initialised
*
* @return 0 : on success, EIO : if an error occurred
*/
int32_t hal_qspi_finalize(qspi_dev_t *qspi);
#endif /* HAL_QSPI_H */

View file

@ -0,0 +1,26 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_RNG_H
#define HAL_RNG_H
typedef struct {
uint8_t port; /* random device port */
void *priv; /* priv data */
} random_dev_t;
/**
* Fill in a memory buffer with random data
*
* @param[in] random the random device
* @param[out] inBuffer Point to a valid memory buffer, this function will fill
* in this memory with random numbers after executed
* @param[in] inByteCount Length of the memory buffer (bytes)
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_random_num_read(random_dev_t random, void *buf, int32_t bytes);
#endif /* HAL_RNG_H */

View file

@ -0,0 +1,74 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_RTC_H
#define HAL_RTC_H
#define HAL_RTC_FORMAT_DEC 1
#define HAL_RTC_FORMAT_BCD 2
typedef struct {
uint8_t format; /* time formart DEC or BCD */
} rtc_config_t;
typedef struct {
uint8_t port; /* rtc port */
rtc_config_t config; /* rtc config */
void *priv; /* priv data */
} rtc_dev_t;
/*
* RTC time
*/
typedef struct {
uint8_t sec; /* DEC format:value range from 0 to 59, BCD format:value range from 0x00 to 0x59 */
uint8_t min; /* DEC format:value range from 0 to 59, BCD format:value range from 0x00 to 0x59 */
uint8_t hr; /* DEC format:value range from 0 to 23, BCD format:value range from 0x00 to 0x23 */
uint8_t weekday; /* DEC format:value range from 1 to 7, BCD format:value range from 0x01 to 0x07 */
uint8_t date; /* DEC format:value range from 1 to 31, BCD format:value range from 0x01 to 0x31 */
uint8_t month; /* DEC format:value range from 1 to 12, BCD format:value range from 0x01 to 0x12 */
uint8_t year; /* DEC format:value range from 0 to 99, BCD format:value range from 0x00 to 0x99 */
} rtc_time_t;
/**
* This function will initialize the on board CPU real time clock
*
*
* @param[in] rtc rtc device
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_rtc_init(rtc_dev_t *rtc);
/**
* This function will return the value of time read from the on board CPU real time clock.
*
* @param[in] rtc rtc device
* @param[out] time pointer to a time structure
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_rtc_get_time(rtc_dev_t *rtc, rtc_time_t *time);
/**
* This function will set MCU RTC time to a new value.
*
* @param[in] rtc rtc device
* @param[out] time pointer to a time structure
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_rtc_set_time(rtc_dev_t *rtc, const rtc_time_t *time);
/**
* De-initialises an RTC interface, Turns off an RTC hardware interface
*
* @param[in] RTC the interface which should be de-initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_rtc_finalize(rtc_dev_t *rtc);
#endif /* HAL_RTC_H */

View file

@ -0,0 +1,116 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_SD_H
#define HAL_SD_H
typedef enum {
SD_STAT_RESET,
SD_STAT_READY,
SD_STAT_TIMEOUT,
SD_STAT_BUSY,
SD_STAT_PROGRAMMING,
SD_STAT_RECEIVING,
SD_STAT_TRANSFER,
SD_STAT_ERR
} hal_sd_stat;
typedef struct {
uint32_t blk_nums; /* sd total block nums */
uint32_t blk_size; /* sd block size */
} hal_sd_info_t;
/*
* UART configuration
*/
typedef struct {
uint32_t bus_wide; /* sd bus wide */
uint32_t freq; /* sd freq */
} sd_config_t;
typedef struct {
uint8_t port; /* sd port */
sd_config_t config; /* sd config */
void *priv; /* priv data */
} sd_dev_t;
/**
* Initialises a sd interface
*
* @param[in] sd the interface which should be initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_sd_init(sd_dev_t *sd);
/**
* Read sd blocks
*
* @param[in] sd the interface which should be initialised
* @param[out] data pointer to the buffer which will store incoming data
* @param[in] blk_addr sd blk addr
* @param[in] blks sd blks
* @param[in] timeout timeout in milisecond
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_sd_blks_read(sd_dev_t *sd, uint8_t *data, uint32_t blk_addr,
uint32_t blks, uint32_t timeout);
/**
* Write sd blocks
*
* @param[in] sd the interface which should be initialised
* @param[in] data pointer to the buffer which will store incoming data
* @param[in] blk_addr sd blk addr
* @param[in] blks sd blks
* @param[in] timeout timeout in milisecond
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_sd_blks_write(sd_dev_t *sd, uint8_t *data, uint32_t blk_addr,
uint32_t blks, uint32_t timeout);
/**
* Erase sd blocks
*
* @param[in] sd the interface which should be initialised
* @param[in] blk_start_addr sd blocks start addr
* @param[in] blk_end_addr sd blocks end addr
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_sd_erase(sd_dev_t *sd, uint32_t blk_start_addr, uint32_t blk_end_addr);
/**
* Get sd state
*
* @param[in] sd the interface which should be initialised
* @param[out] stat pointer to the buffer which will store incoming data
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_sd_stat_get(sd_dev_t *sd, hal_sd_stat *stat);
/**
* Get sd info
*
* @param[in] sd the interface which should be initialised
* @param[out] stat pointer to the buffer which will store incoming data
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_sd_info_get(sd_dev_t *sd, hal_sd_info_t *info);
/**
* Deinitialises a sd interface
*
* @param[in] sd the interface which should be initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_sd_finalize(sd_dev_t *sd);
#endif /* HAL_SD_H */

View file

@ -0,0 +1,31 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_SOC_H
#define HAL_SOC_H
#include <stdint.h>
#include <stddef.h>
#include <hal/soc/adc.h>
#include <hal/soc/flash.h>
#include <hal/soc/gpio.h>
#include <hal/soc/i2c.h>
#include <hal/soc/nand.h>
#include <hal/soc/nor.h>
#include <hal/soc/pwm.h>
#include <hal/soc/qspi.h>
#include <hal/soc/rng.h>
#include <hal/soc/rtc.h>
#include <hal/soc/sd.h>
#include <hal/soc/spi.h>
#include <hal/soc/timer.h>
#include <hal/soc/uart.h>
#include <hal/soc/wdg.h>
#include <hal/soc/interpt.h>
#define HAL_WAIT_FOREVER 0xFFFFFFFFU
#endif /* HAL_SOC_H */

View file

@ -0,0 +1,80 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_SPI_H
#define HAL_SPI_H
#define HAL_SPI_MODE_MASTER 1 /* spi communication is master mode */
#define HAL_SPI_MODE_SLAVE 2 /* spi communication is slave mode */
typedef struct {
uint32_t mode; /* spi communication mode */
uint32_t freq; /* communication frequency Hz */
} spi_config_t;
typedef struct {
uint8_t port; /* spi port */
spi_config_t config; /* spi config */
void *priv; /* priv data */
} spi_dev_t;
/**
* Initialises the SPI interface for a given SPI device
*
* @param[in] spi the spi device
*
* @return 0 : on success, EIO : if the SPI device could not be initialised
*/
int32_t hal_spi_init(spi_dev_t *spi);
/**
* Spi send
*
* @param[in] spi the spi device
* @param[in] data spi send data
* @param[in] size spi send data size
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if the SPI device could not be initialised
*/
int32_t hal_spi_send(spi_dev_t *spi, const uint8_t *data, uint16_t size, uint32_t timeout);
/**
* spi_recv
*
* @param[in] spi the spi device
* @param[out] data spi recv data
* @param[in] size spi recv data size
* @param[in] timeout timeout in ms
*
* @return 0 : on success, EIO : if the SPI device could not be initialised
*/
int32_t hal_spi_recv(spi_dev_t *spi, uint8_t *data, uint16_t size, uint32_t timeout);
/**
* spi send data and recv
*
* @param[in] spi the spi device
* @param[in] tx_data spi send data
* @param[in] rx_data spi recv data
* @param[in] size spi data to be sent and recived
* @param[in] timeout timeout in ms
*
* @return 0, on success; EIO : if the SPI device could not be initialised
*/
int32_t hal_spi_send_recv(spi_dev_t *spi, uint8_t *tx_data, uint8_t *rx_data,
uint16_t size, uint32_t timeout);
/**
* De-initialises a SPI interface
*
*
* @param[in] spi the SPI device to be de-initialised
*
* @return 0 : on success, EIO : if an error occurred
*/
int32_t hal_spi_finalize(spi_dev_t *spi);
#endif /* HAL_SPI_H */

View file

@ -0,0 +1,64 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_TIMER_H
#define HAL_TIMER_H
#define TIMER_RELOAD_AUTO 1 /* timer reload automatic */
#define TIMER_RELOAD_MANU 2 /* timer reload manual */
typedef void (*hal_timer_cb_t)(void *arg);
typedef struct {
uint32_t period;
uint8_t reload_mode;
hal_timer_cb_t cb;
void *arg;
} timer_config_t;
typedef struct {
int8_t port; /* timer port */
timer_config_t config; /* timer config */
void *priv; /* priv data */
} timer_dev_t;
/**
* init a hardware timer
*
* @param[in] tmr timer struct
* @param[in] period micro seconds for repeat timer trigger
* @param[in] auto_reoad set to 0, if you just need oneshot timer
* @param[in] cb callback to be triggered after useconds
* @param[in] ch timer channel
* @param[in] arg passed to cb
*/
int32_t hal_timer_init(timer_dev_t *tim);
/**
* start a hardware timer
*
* @return 0 == success, EIO == failure
*/
int32_t hal_timer_start(timer_dev_t *tim);
/**
* stop a hardware timer
*
* @param[in] tmr timer struct
* @param[in] cb callback to be triggered after useconds
* @param[in] arg passed to cb
*/
void hal_timer_stop(timer_dev_t *tim);
/**
* De-initialises an TIMER interface, Turns off an TIMER hardware interface
*
* @param[in] timer the interface which should be de-initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_timer_finalize(timer_dev_t *tim);
#endif /* HAL_TIMER_H*/

132
Living_SDK/include/hal/soc/uart.h Executable file
View file

@ -0,0 +1,132 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_UART_H
#define HAL_UART_H
/*
* UART data width
*/
typedef enum {
DATA_WIDTH_5BIT,
DATA_WIDTH_6BIT,
DATA_WIDTH_7BIT,
DATA_WIDTH_8BIT,
DATA_WIDTH_9BIT
} hal_uart_data_width_t;
/*
* UART stop bits
*/
typedef enum {
STOP_BITS_1,
STOP_BITS_2
} hal_uart_stop_bits_t;
/*
* UART flow control
*/
typedef enum {
FLOW_CONTROL_DISABLED,
FLOW_CONTROL_CTS,
FLOW_CONTROL_RTS,
FLOW_CONTROL_CTS_RTS
} hal_uart_flow_control_t;
/*
* UART parity
*/
typedef enum {
NO_PARITY,
ODD_PARITY,
EVEN_PARITY
} hal_uart_parity_t;
/*
* UART mode
*/
typedef enum {
MODE_TX,
MODE_RX,
MODE_TX_RX
} hal_uart_mode_t;
/*
* UART configuration
*/
typedef struct {
uint32_t baud_rate;
hal_uart_data_width_t data_width;
hal_uart_parity_t parity;
hal_uart_stop_bits_t stop_bits;
hal_uart_flow_control_t flow_control;
hal_uart_mode_t mode;
} uart_config_t;
typedef struct {
uint8_t port; /* uart port */
uart_config_t config; /* uart config */
void *priv; /* priv data */
} uart_dev_t;
/**
* Initialises a UART interface
*
*
* @param[in] uart the interface which should be initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_uart_init(uart_dev_t *uart);
/**
* Transmit data on a UART interface
*
* @param[in] uart the UART interface
* @param[in] data pointer to the start of data
* @param[in] size number of bytes to transmit
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_uart_send(uart_dev_t *uart, const void *data, uint32_t size, uint32_t timeout);
/**
* Receive data on a UART interface
*
* @param[in] uart the UART interface
* @param[out] data pointer to the buffer which will store incoming data
* @param[in] expect_size number of bytes to receive
* @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER
* if you want to wait forever
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_uart_recv(uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t timeout);
/**
* Receive data on a UART interface
*
* @param[in] uart the UART interface
* @param[out] data pointer to the buffer which will store incoming data
* @param[in] expect_size number of bytes to receive
* @param[out] recv_size number of bytes received
* @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER
* if you want to wait forever
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_uart_recv_II(uart_dev_t *uart, void *data, uint32_t expect_size,
uint32_t *recv_size, uint32_t timeout);
/**
* Deinitialises a UART interface
*
* @param[in] uart the interface which should be deinitialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_uart_finalize(uart_dev_t *uart);
#endif /* HAL_UART_H */

View file

@ -0,0 +1,46 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_WDG_H
#define HAL_WDG_H
#include <stdint.h>
typedef struct {
uint32_t timeout; /* Watchdag timeout */
} wdg_config_t;
typedef struct {
uint8_t port; /* wdg port */
wdg_config_t config; /* wdg config */
void *priv; /* priv data */
} wdg_dev_t;
/**
* This function will initialize the on board CPU hardware watch dog
*
* @param[in] wdg the watch dog device
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_wdg_init(wdg_dev_t *wdg);
/**
* Reload watchdog counter.
*
* @param[in] wdg the watch dog device
*/
void hal_wdg_reload(wdg_dev_t *wdg);
/**
* This function performs any platform-specific cleanup needed for hardware watch dog.
*
* @param[in] wdg the watch dog device
*
* @return 0 : on success, EIO : if an error occurred with any step
*/
int32_t hal_wdg_finalize(wdg_dev_t *wdg);
#endif /* HAL_WDG_H */

View file

@ -0,0 +1,42 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_TRACE_H
#define HAL_TRACE_H
/**
* trace data transfer init.
*/
void *trace_hal_init(void);
/**
* trace data transfer send.
*
* @param[in] handle data transfer channel object
* @param[in] buf the buffer store data
* @param[in] len the len of data
*
* @return the size send success.
*/
ssize_t trace_hal_send(void *handle, void *buf, size_t len);
/**
* trace data transfer receive.
*
* @param[in] handle data transfer channel object
* @param[in] buf the buffer to store data
*
* @return the size receive success.
*/
ssize_t trace_hal_recv(void *handle, void *buf);
/**
* trace data transfer init.
*
* @param[in] handle data transfer channel object
*/
void trace_hal_deinit(void *handle);
#endif /* HAL_TRACE_H */

532
Living_SDK/include/hal/wifi.h Executable file
View file

@ -0,0 +1,532 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef HAL_WIFI_H
#define HAL_WIFI_H
#include <stdint.h>
#include <hal/base.h>
#include <k_api.h>
#ifdef STM32L475xx
#include "stm32_wifi.h"
#endif
typedef struct hal_wifi_module_s hal_wifi_module_t;
enum wlan_sec_type_e
{
SECURITY_TYPE_NONE, /* Open system. */
SECURITY_TYPE_WEP, /* Wired Equivalent Privacy. WEP security. */
SECURITY_TYPE_WPA_TKIP, /* WPA /w TKIP */
SECURITY_TYPE_WPA_AES, /* WPA /w AES */
SECURITY_TYPE_WPA2_TKIP, /* WPA2 /w TKIP */
SECURITY_TYPE_WPA2_AES, /* WPA2 /w AES */
SECURITY_TYPE_WPA2_MIXED, /* WPA2 /w AES or TKIP */
SECURITY_TYPE_AUTO, /* It is used when calling @ref micoWlanStartAdv, MICO
read security type from scan result. */
};
typedef struct
{
char ssid[32 + 1];
char ap_power;
} ap_list_t;
/*
* Scan result using normal scan.
*/
typedef struct
{
char ap_num; /* The number of access points found in scanning. */
ap_list_t *ap_list;
} hal_wifi_scan_result_t;
typedef struct
{
char ssid[32 + 1]; /* The SSID of an access point. */
char ap_power; /* Signal strength, min:0, max:100 */
char bssid[6]; /* The BSSID of an access point. */
char channel; /* The RF frequency, 1-13 */
uint8_t security; /* Security type, @ref wlan_sec_type_t */
} ap_list_adv_t;
typedef struct
{
char ap_num; /* The number of access points found in scanning. */
ap_list_adv_t *ap_list;
} hal_wifi_scan_result_adv_t;
typedef enum
{
NOTIFY_STATION_UP = 1, /* AP connected(Authenticate and Associate success) */
NOTIFY_STATION_DOWN, /* AP disconnected(Authenticate or Associate fail) */
NOTIFY_AP_UP, /* SoftAP mode up */
NOTIFY_AP_DOWN, /* SoftAP mode down */
} hal_wifi_event_t;
typedef struct
{
#ifdef BOARD_MK3060 /* mk3060 lib use ssid[32], so ... */
char ssid[32]; /* SSID of the wlan that needs to be connected. Example:
"SSID String". */
#else
char ssid[32 + 1]; /* SSID of the wlan that needs to be connected. Example:
"SSID String". */
#endif
char bssid[6]; /* BSSID of the wlan needs to be connected. Example: {0xC8
0x93 0x46 0x11 0x22 0x33}. */
uint8_t channel; /* Wlan's RF frequency, channel 0-13. 1-13 means a fixed
channelthat can speed up a connection procedure, 0 is
not a fixed input means all channels are possible*/
uint8_t security;
} hal_wifi_ap_info_adv_t;
typedef struct
{
char wifi_mode; /* DHCP mode: @ref wlanInterfaceTypedef. */
char wifi_ssid[32 + 1]; /* SSID of the wlan needs to be connected. */
char wifi_key[64 + 1]; /* Security key of the wlan needs to be connected,
ignored in an open system. */
char local_ip_addr[16]; /* Static IP configuration, Local IP address. */
char net_mask[16]; /* Static IP configuration, Netmask. */
char gateway_ip_addr[16]; /* Static IP configuration, Router IP address. */
char dns_server_ip_addr[16]; /* Static IP configuration, DNS server IP
address. */
char dhcp_mode; /* DHCP mode, @ref DHCP_Disable, @ref DHCP_Client and @ref
DHCP_Server. */
char reserved[32];
int wifi_retry_interval; /* Retry interval if an error is occured when
connecting an access point, time unit is
millisecond. */
#ifdef STM32L475xx
WIFI_Ecn_t access_sec;
#endif
} hal_wifi_init_type_t;
typedef struct
{
hal_wifi_ap_info_adv_t ap_info;
char key[64 + 1]; /* Security key or PMK of the wlan. */
int key_len; /* The length of the key. */
char local_ip_addr[16]; /* Static IP configuration, Local IP address. */
char net_mask[16]; /* Static IP configuration, Netmask. */
char gateway_ip_addr[16]; /* Static IP configuration, Router IP address. */
char dns_server_ip_addr[16]; /* Static IP configuration, DNS server IP
address. */
char dhcp_mode; /* DHCP mode, @ref DHCP_Disable, @ref DHCP_Client and @ref
DHCP_Server. */
char reserved[32];
int wifi_retry_interval; /* Retry interval if an error is occured when
connecting an access point, time unit is
millisecond. */
} hal_wifi_init_type_adv_t;
typedef struct
{
uint8_t dhcp; /* DHCP mode: @ref DHCP_Disable, @ref DHCP_Client, @ref
DHCP_Server. */
char ip[16]; /* Local IP address on the target wlan interface: @ref
wlanInterfaceTypedef. */
char gate[16]; /* Router IP address on the target wlan interface: @ref
wlanInterfaceTypedef. */
char mask[16]; /* Netmask on the target wlan interface: @ref
wlanInterfaceTypedef. */
char dns[16]; /* DNS server IP address. */
char mac[16]; /* MAC address, example: "C89346112233". */
char broadcastip[16];
} hal_wifi_ip_stat_t;
typedef enum
{
SOFT_AP, /* Act as an access point, and other station can connect, 4
stations Max */
STATION /* Act as a station which can connect to an access point */
} hal_wifi_type_t;
enum
{
DHCP_DISABLE = 0,
DHCP_CLIENT,
DHCP_SERVER,
};
typedef struct
{
int is_connected; /* The link to wlan is established or not, 0:
disconnected, 1: connected. */
int wifi_strength; /* Signal strength of the current connected AP */
uint8_t ssid[32 + 1]; /* SSID of the current connected wlan */
uint8_t bssid[6]; /* BSSID of the current connected wlan */
int channel; /* Channel of the current connected wlan */
} hal_wifi_link_stat_t;
typedef struct hal_wifi_link_info_s
{
int8_t rssi; /* rssi value of received packet */
} hal_wifi_link_info_t;
/*
* The event call back function called at specific events occurred.
*
* @note For HAL implementors, these callbacks must be
* called under normal task context, not from interrupt.
*/
typedef struct
{
void (*connect_fail)(hal_wifi_module_t *m, int err, void *arg);
void (*ip_got)(hal_wifi_module_t *m, hal_wifi_ip_stat_t *pnet, void *arg);
void (*stat_chg)(hal_wifi_module_t *m, hal_wifi_event_t stat, void *arg);
void (*scan_compeleted)(hal_wifi_module_t * m,
hal_wifi_scan_result_t *result, void *arg);
void (*scan_adv_compeleted)(hal_wifi_module_t * m,
hal_wifi_scan_result_adv_t *result, void *arg);
void (*para_chg)(hal_wifi_module_t *m, hal_wifi_ap_info_adv_t *ap_info,
char *key, int key_len, void *arg);
void (*fatal_err)(hal_wifi_module_t *m, void *arg);
} hal_wifi_event_cb_t;
typedef void (*monitor_data_cb_t)(uint8_t *data, int len,
hal_wifi_link_info_t *info);
struct hal_wifi_module_s
{
hal_module_base_t base;
const hal_wifi_event_cb_t *ev_cb;
int (*init)(hal_wifi_module_t *m);
void (*get_mac_addr)(hal_wifi_module_t *m, uint8_t *mac);
void (*set_mac_addr)(hal_wifi_module_t *m, const uint8_t *mac);
int (*start)(hal_wifi_module_t *m, hal_wifi_init_type_t *init_para);
int (*start_adv)(hal_wifi_module_t * m,
hal_wifi_init_type_adv_t *init_para_adv);
int (*get_ip_stat)(hal_wifi_module_t *m, hal_wifi_ip_stat_t *out_net_para,
hal_wifi_type_t wifi_type);
int (*get_link_stat)(hal_wifi_module_t *m, hal_wifi_link_stat_t *out_stat);
void (*start_scan)(hal_wifi_module_t *m);
void (*start_scan_adv)(hal_wifi_module_t *m);
int (*power_off)(hal_wifi_module_t *m);
int (*power_on)(hal_wifi_module_t *m);
int (*suspend)(hal_wifi_module_t *m);
int (*suspend_station)(hal_wifi_module_t *m);
int (*suspend_soft_ap)(hal_wifi_module_t *m);
int (*set_channel)(hal_wifi_module_t *m, int ch);
int (*get_channel)(hal_wifi_module_t *m);
int (*get_channel_list)(hal_wifi_module_t *m, const uint8_t **chnlist);
void (*start_monitor)(hal_wifi_module_t *m);
void (*stop_monitor)(hal_wifi_module_t *m);
void (*register_monitor_cb)(hal_wifi_module_t *m, monitor_data_cb_t fn);
void (*register_wlan_mgnt_monitor_cb)(hal_wifi_module_t *m,
monitor_data_cb_t fn);
int (*wlan_send_80211_raw_frame)(hal_wifi_module_t *m, uint8_t *buf,
int len);
int (*start_ap)(hal_wifi_module_t *m, const char *ssid, const char *passwd, int interval, int hide);
int (*stop_ap)(hal_wifi_module_t *m);
/* debug related */
void (*start_debug_mode)(hal_wifi_module_t *m);
void (*stop_debug_mode)(hal_wifi_module_t *m);
/* mesh related */
void (*mesh_register_cb)(hal_wifi_module_t *m, monitor_data_cb_t fn);
void (*mesh_set_bssid)(hal_wifi_module_t *m, const uint8_t *mac);
int (*mesh_enable)(hal_wifi_module_t *m);
int (*mesh_disable)(hal_wifi_module_t *m);
int (*mesh_radio_sleep)(hal_wifi_module_t *m);
int (*mesh_radio_wakeup)(hal_wifi_module_t *m);
#if (WIFI_CONFIG_SUPPORT_LOWPOWER > 0)
int (*set_listeninterval)(hal_wifi_module_t *m, uint8_t listen_interval);
int (*enter_powersave)(hal_wifi_module_t *m, uint8_t recvDTIMs);
int (*exit_powersave)(hal_wifi_module_t *m);
#endif
/* Put new added API in the end, since some lib built with our old wifi.h, hmm ... */
void (*start_scan_direct)(hal_wifi_module_t *m);
};
/**
* Get the default wifi instance.
* The system may have more than one wifi instance,
* this API returns the default one.
*
* @return Instance pointer, or NULL if no instance registered.
*/
hal_wifi_module_t *hal_wifi_get_default_module(void);
/**
* Regster a wifi instance to the HAL framework.
*
* @param[in] m the wifi instance.
*/
void hal_wifi_register_module(hal_wifi_module_t *m);
/**
* Initialize wifi instances.
*
* @note This is supposed to be called during system boot,
* not supposed to be called by user module directly.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_init(void);
/**
* Get the MAC address of the specified wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
* @param[out] mac the place to hold the result.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_get_mac_addr(hal_wifi_module_t *m, uint8_t *mac);
/**
* Set the MAC address of the specified wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
* @param[in] mac mac value
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_set_mac_addr(hal_wifi_module_t *m, const uint8_t *mac);
/**
* Start the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
* @param[in] init_para the config used to start the wifi.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_start(hal_wifi_module_t *m, hal_wifi_init_type_t *init_para);
/**
* Start the wifi instance in anvanced way (more config specified).
*
* @param[in] m the wifi instance, NULL if default.
* @param[in] init_para_adv the advanced config used to start the wifi.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_start_adv(hal_wifi_module_t * m,
hal_wifi_init_type_adv_t *init_para_adv);
/**
* Get the status of the specified wifi instance, e.g. the IP, mask, dhcp mode,
* etc.
*
* @param[in] m the wifi instance, NULL if default.
* @param[out] out_net_para the place to hold the results.
* @param[in] wifi_type SOFT_AP or STATION.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_get_ip_stat(hal_wifi_module_t *m, hal_wifi_ip_stat_t *out_net_para,
hal_wifi_type_t wifi_type);
/**
* Get the link status of the wifi instance ,e.g. ssid, bssid, channel, rssi,
* etc.
*
* @param[in] m the wifi instance, NULL if default.
* @param[out] out_stat the place to hold the results.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_get_link_stat(hal_wifi_module_t * m,
hal_wifi_link_stat_t *out_stat);
/**
* Start the scanning of the specified wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
*/
void hal_wifi_start_scan(hal_wifi_module_t *m);
/**
* Start the scanning of the specified wifi instance in advanced way.
*
* @param[in] m the wifi instance, NULL if default.
*/
void hal_wifi_start_scan_adv(hal_wifi_module_t *m);
void hal_wifi_start_scan_direct(hal_wifi_module_t *m);
/**
* Power off the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_power_off(hal_wifi_module_t *m);
/**
* Power on the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_power_on(hal_wifi_module_t *m);
/**
* Suspend the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_suspend(hal_wifi_module_t *m);
/**
* Suspend the wifi instance in station mode.
*
* @param[in] m the wifi instance, NULL if default.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_suspend_station(hal_wifi_module_t *m);
/**
* Suspend the wifi instance in soft_ap mode.
*
* @param[in] m the wifi instance, NULL if default.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_suspend_soft_ap(hal_wifi_module_t *m);
/**
* Set the channel of the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
*
* @return 0 on success, otherwise failure.
*/
int hal_wifi_set_channel(hal_wifi_module_t *m, int ch);
/**
* Get the channel of the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
*
* @return -1 on failure, otherwise current channel number.
*/
int hal_wifi_get_channel(hal_wifi_module_t *m);
/**
* Get the channel list of the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
* @param[out] chnlist channel list in array
*
* @return -1 on failure, otherwise number of available channels.
*/
int hal_wifi_get_channel_list(hal_wifi_module_t *m, const uint8_t **chnlist);
/**
* Start the monitor mode of the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
*/
void hal_wifi_start_wifi_monitor(hal_wifi_module_t *m);
/**
* Stop the monitor mode of the wifi instance.
*
* @param[in] m The wifi instance, NULL if default.
*/
void hal_wifi_stop_wifi_monitor(hal_wifi_module_t *m);
/**
* Register the montior callback on the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
* @param[in] fn the callback function.
*/
void hal_wifi_register_monitor_cb(hal_wifi_module_t *m, monitor_data_cb_t fn);
/**
* Register management frame montior callback on the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
* @param[in] fn the callback function.
*/
void hal_wlan_register_mgnt_monitor_cb(hal_wifi_module_t *m,
monitor_data_cb_t fn);
/**
* Send 802.11 raw frame
*
* @param[in] m the wifi instance, NULL if default.
* @param[in] buf frame buffer.
* @param[in] len length of frame buffer.
*/
int hal_wlan_send_80211_raw_frame(hal_wifi_module_t *m, uint8_t *buf, int len);
/**
* Start debug mode of the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
*/
void hal_wifi_start_debug_mode(hal_wifi_module_t *m);
/**
* Stop debug mode of the wifi instance.
*
* @param[in] m the wifi instance, NULL if default.
*/
void hal_wifi_stop_debug_mode(hal_wifi_module_t *m);
/**
* Set the event callback function array for the wifi.
* Please don't do time consuming work in these callbacks.
*
* @note Please don't do time consuming work in these callbacks.
*
* @param[in] m the wifi instance, NULL for default.
* @param[in] cb the event callback function info.
*/
void hal_wifi_install_event(hal_wifi_module_t * m,
const hal_wifi_event_cb_t *cb);
/**
* Regster a wifi instance to the uMesh
*
* @param[in] m the wifi instance.
*/
void hal_umesh_register_wifi(hal_wifi_module_t *m);
#if (WIFI_CONFIG_SUPPORT_LOWPOWER > 0)
/**
* Set the event listen interval for the wifi.
*
* @param[in] m the wifi instance, NULL for default.
* @param[uint8_t] listen_interval the listen interval in power save mode.
*/
int hal_wifi_set_listeninterval(hal_wifi_module_t *m, uint8_t listen_interval);
/**
* enter power save mode.
*
* @param[in] m the wifi instance, NULL for default.
* @param[uint8_t] recvDTIMs set 1 to receive DTIM, set 0 not to receive DTIM .
*/
int hal_wifi_enter_powersave(hal_wifi_module_t *m, uint8_t recvDTIMs);
/**
* exit power save mode.
*
* @param[in] m the wifi instance, NULL for default.
*/
int hal_wifi_exit_powersave(hal_wifi_module_t *m);
#endif
#endif /* HAL_WIFI_H */