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,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 */