code
stringlengths
1
1.05M
repo_name
stringlengths
6
83
path
stringlengths
3
242
language
stringclasses
222 values
license
stringclasses
20 values
size
int64
1
1.05M
/* Please add this section into app.json when run this script as app.js. This configuration is designed for haas100 edu k1. "qlc5883": { "type": "I2C", "port": 1, "addrWidth": 7, "freq": 400000, "mode": "master", "devAddr": 13 } */ console.log('testing qlc5883...'); var qlc5883 = require('./qlc5883.js'); qlc5883.init("qlc5883"); qlc5883.qmc5883l_readHeading(); qlc5883.qmc5883l_readHeading(); qlc5883.qmc5883l_readHeading(); qlc5883.qmc5883l_readHeading(); qlc5883.deinit(); console.log("test qlc5883 success!");
YifuLiu/AliOS-Things
components/amp/test/test_qlc5883.js
JavaScript
apache-2.0
548
var gpio = require('gpio'); var spi = require('spi'); var sh1106 = require('./sh1106.js'); console.log('Hello') var oled_dc = gpio.open({ id: 'oled_dc', success: function () { console.log('gpio: open oled_dc success') }, fail: function () { console.log('gpio: open oled_dc failed') } }); var oled_res = gpio.open({ id: 'oled_res', success: function () { console.log('gpio: open oled_res success') }, fail: function () { console.log('gpio: open oled_res failed') } }); var oled_spi = spi.open({ id: 'oled_spi', success: function () { console.log('gpio: open oled_spi success') }, fail: function () { console.log('gpio: open oled_spi failed') } }); sh1106.init(132, 64, oled_spi, oled_dc, oled_res, undefined); sh1106.fill(1); sh1106.show(); while (1) { sh1106.fill(1) sh1106.show() sh1106.fill(0) sh1106.show() }
YifuLiu/AliOS-Things
components/amp/test/test_sh1106.js
JavaScript
apache-2.0
944
/* Please add this section into app.json when run this script as app.js. This configuration is designed for haas100 edu k1. "si7006": { "type": "I2C", "port": 1, "addrWidth": 7, "freq": 400000, "mode": "master", "devAddr": 64 } */ console.log('testing si7006...'); var si7006 = require('./si7006.js'); si7006.init("si7006"); var version = si7006.getVer(); console.log("Si7006 version is: " , version); var chipID = si7006.getID(); console.log("Si7006 chipid is: " , chipID); var temperature = si7006.getTemperature(); console.log("Temperature is: " , temperature); var humidity = si7006.getHumidity(); console.log("Humidity is: " , humidity); si7006.deinit(); console.log("test si7006 success!");
YifuLiu/AliOS-Things
components/amp/test/test_si7006.js
JavaScript
apache-2.0
730
/* Please add this section into app.json when run this script as app.js. This configuration is designed for haas100 edu k1. "spl06": { "type": "I2C", "port": 1, "addrWidth": 7, "freq": 400000, "mode": "master", "devAddr": 119 } */ console.log('testing spl06...'); var spl06 = require('./spl06.js'); spl06.init("spl06"); var version = spl06.getID(); console.log("spl06 version is: " , version); spl06.spl06_getdata(); spl06.deinit(); console.log("test spl06 success!");
YifuLiu/AliOS-Things
components/amp/test/test_spl06.js
JavaScript
apache-2.0
499
/* 本测试case,测试tcp的接口,接口返回值等,tcp server是公网tcp服务器:47.101.151.113 */ function ArrayToString(fileData){ var dataString = ""; for (var i = 0; i < fileData.length; i++) { dataString += String.fromCharCode(fileData[i]); } return dataString; } console.log('tcp: testing tcp...'); // 测试 tcp 模块 var tcp = require('tcp'); if(!(tcp && tcp.createClient)){ throw new Error("tcp: [failed] require(\'tcp\')"); } console.log('tcp: [success] require(\'tcp\')'); var tcpSocket = tcp.createClient({ host: '47.101.151.113', port: 50020, success: function() { console.log('tcp: tcp client connect success'); }, fail: function() { console.log('tcp: tcp client connect failed'); } }); // 测试 tcpSocket 接口 if(!tcpSocket || !tcpSocket.send || !tcpSocket.close || !tcpSocket.on || !tcpSocket.reconnect) { throw new Error("tcp: [failed] tcp instance"); } // 测试接收数据 var sendCnt = 0, recvCnt = 0; var defaultMessage = 'AMP tcp server reply'; tcpSocket.on('message', function(message) { if(!message || typeof message !== 'object' || ArrayToString(message) !== defaultMessage) { throw new Error("tcp: [failed] tcp receive message"); } recvCnt ++; console.log('tcp: [debug] on message: ' + ArrayToString(message) + ', cnt: ' + recvCnt); if(recvCnt >= 10){ tcpSocket.close(); console.log('tcp: [success] tcp.on(\'message\')'); console.log('tcp: testing tcp success'); } }); // 接收数据超时 setTimeout(function() { if(recvCnt != 10) { console.log('tcp: [failed] tcp on message'); } }, 12000); // 测试socket异常 tcpSocket.on('error', function(err) { console.log('tcp: tcp error ', err); tcpSocket.close(); throw new Error("tcp: [failed] tcp on error"); }); tcpSocket.on('disconnect', function() { console.log('tcp: tcp disconnected'); }); // 测试发送数据 var intervalHandle = setInterval(function() { tcpSocket.send({ message: "this is xxw, cnt: " + sendCnt, success: function() { sendCnt ++; console.log("tcp: [debug] send success, cnt: ", sendCnt); // 退出发送 if(sendCnt >= 10){ clearInterval(intervalHandle); console.log('tcp: [success] tcp.send()'); } }, fail: function() { console.log("tcp: send fail"); throw new Error("tcp: [failed] tcp send fail"); } }); }, 1000);
YifuLiu/AliOS-Things
components/amp/test/test_tcp.js
JavaScript
apache-2.0
2,463
/* 本测试case,测试udp的接口,接口返回值等,udp server是公网udp服务器:47.101.151.113 */ function ArrayToString(fileData){ var dataString = ""; for (var i = 0; i < fileData.length; i++) { dataString += String.fromCharCode(fileData[i]); } return dataString; } console.log('udp: testing udp...'); // 测试 udp 模块 var udp = require('udp'); if(!(udp && udp.createSocket)){ throw new Error("udp: [failed] require(\'udp\')"); } console.log('udp: [success] require(\'udp\')'); var udpSocket = udp.createSocket(); // 测试 UDPSocket 接口 if(!udpSocket || !udpSocket.bind || !udpSocket.send || !udpSocket.close || !udpSocket.on) { throw new Error("udp: [failed] udp instance"); } // 测试接收数据 var sendCnt = 0, recvCnt = 0; var defaultMessage = 'AMP udp server reply'; udpSocket.on('message', function(message, rinfo) { if(!message || typeof message !== 'object' || ArrayToString(message) !== defaultMessage) { throw new Error("udp: [failed] udp receive message"); } if(!rinfo || !rinfo.host || !rinfo.port) { throw new Error("udp: [failed] udp receive rinfo"); } recvCnt ++; console.log('udp: [debug] remote[' + rinfo.host + ': ' + rinfo.port + '] on message: ' + ArrayToString(message) + ', cnt: ' + recvCnt); if(recvCnt >= 10){ udpSocket.close(); console.log('udp: [success] udp.on(\'message\')'); console.log('udp: testing udp success'); } }); // 接收数据超时 setTimeout(function() { if(recvCnt != 10) { console.log('udp: [failed] udp on message'); } }, 12000); // 测试socket异常 udpSocket.on('error', function(err) { console.log('udp error ', err); throw new Error("udp: [failed] udp on error"); }); // 测试发送数据 var intervalHandle = setInterval(function() { udpSocket.send({ address: "47.101.151.113", port: 50000, message: "this is xxw, cnt: " + sendCnt, success: function() { sendCnt ++; console.log("udp: [debug] send success, cnt: ", sendCnt); // 退出发送 if(sendCnt >= 10){ clearInterval(intervalHandle); console.log('udp: [success] udp.send()'); } }, fail: function() { console.log("udp: send fail"); throw new Error("udp: [failed] udp send fail"); } }); }, 1000); udpSocket.bind(10240); if(!udpSocket.localPort || typeof udpSocket.localPort !== 'number') { throw new Error("udp: [failed] udp localPort"); } console.log('udp: [success] udp.localPort');
YifuLiu/AliOS-Things
components/amp/test/test_udp.js
JavaScript
apache-2.0
2,643
#./demo_prj_v1.2/democfg.mak #--------------------------------------------------------- # tool chain define #--------------------------------------------------------- AMP_VERSION = "2.0.0" GIT_COMMIT = "$(shell git show -s --pretty=format:%h)" COMPILE_TIME = "$(shell date +"%Y-%m-%d %H:%M:%S")" CC = gcc CXX = g++ AR = ar LD = ld OBJCOPY = objcopy CCFLAGS = -DAMP_VERSION=\"$(AMP_VERSION)\" -DCOMPILE_TIME=\"$(COMPILE_TIME)\" -DGIT_COMMIT=\"$(GIT_COMMIT)\" #--------------------------------------------------------- # shell command #--------------------------------------------------------- ECHO = @echo MKDIR = mkdir -p MV = @mv -r RM = @rm -rf MAKE = @make -j8 #--------------------------------------------------------- # complier flags # v for make debug #--------------------------------------------------------- ARFLAGS = rcs #--------------------------------------------------------- # link libs #--------------------------------------------------------- LIBS = -ln -lrt -lpthread -lutil
YifuLiu/AliOS-Things
components/amp/tools/config.mk
Makefile
apache-2.0
1,014
include $(TOOLS_DIR)/config.mk SUB_ALL_SRCS := $(MOD_SOURCES) SUB_ALL_OBJS := $(patsubst %.c,%.o,$(SUB_ALL_SRCS)) $(foreach inc, $(MOD_INCLUDES), $(eval SUB_ALL_INCS += -I$(inc))) all: $(LIBS_DIR)/$(TARGET) $(LIBS_DIR)/$(TARGET): $(SUB_ALL_OBJS) $(ECHO) "Archiving $@ ..." $(AR) $(ARFLAGS) $@ $^ $(SUB_ALL_OBJS): %.o: %.c $(ECHO) Compiling $< ... $(CC) -c -o $@ $< $(SUB_ALL_INCS) $(CCFLAGS)
YifuLiu/AliOS-Things
components/amp/tools/rules.mk
Makefile
apache-2.0
402
/** * @file lvgl.h * Include all LittleV GL related headers */ #ifndef LV_H #define LV_H #ifdef __cplusplus extern "C" { #endif /********************* * INCLUDES *********************/ //#include "aui_version.h" #include "../../../../littlevgl/src/lv_draw/lv_draw_img.h" #include "../../../../littlevgl/src/lv_misc/lv_log.h" #include "../../../../littlevgl/src/lv_misc/lv_task.h" #include "../../../../littlevgl/src/lv_misc/lv_fs.h" #include "../../../../littlevgl/src/lv_misc/lv_color.h" #include "../../../../littlevgl/src/lv_misc/lv_math.h" #include "../../../../littlevgl/src/lv_font/lv_font_fmt_txt.h" #include "../../../../littlevgl/src/lv_hal/lv_hal.h" #include "../../../../littlevgl/src/lv_core/lv_obj.h" #include "../../../../littlevgl/src/lv_core/lv_group.h" //#include "../../../../littlevgl/src/lv_core/lv_lang.h" #include "../../../../littlevgl/src/lv_core/lv_style.h" #include "../../../../littlevgl/src/lv_core/lv_refr.h" #include "../../../../littlevgl/src/lv_themes/lv_theme.h" #include "../../../../littlevgl/src/lv_objx/lv_btn.h" #include "../../../../littlevgl/src/lv_objx/lv_imgbtn.h" #include "../../../../littlevgl/src/lv_objx/lv_img.h" #include "../../../../littlevgl/src/lv_objx/lv_label.h" #include "../../../../littlevgl/src/lv_objx/lv_line.h" #include "../../../../littlevgl/src/lv_objx/lv_page.h" #include "../../../../littlevgl/src/lv_objx/lv_cont.h" #include "../../../../littlevgl/src/lv_objx/lv_list.h" #include "../../../../littlevgl/src/lv_objx/lv_chart.h" #include "../../../../littlevgl/src/lv_objx/lv_table.h" #include "../../../../littlevgl/src/lv_objx/lv_cb.h" #include "../../../../littlevgl/src/lv_objx/lv_bar.h" #include "../../../../littlevgl/src/lv_objx/lv_slider.h" #include "../../../../littlevgl/src/lv_objx/lv_led.h" #include "../../../../littlevgl/src/lv_objx/lv_btnm.h" #include "../../../../littlevgl/src/lv_objx/lv_kb.h" #include "../../../../littlevgl/src/lv_objx/lv_ddlist.h" #include "../../../../littlevgl/src/lv_objx/lv_roller.h" #include "../../../../littlevgl/src/lv_objx/lv_ta.h" #include "../../../../littlevgl/src/lv_objx/lv_canvas.h" #include "../../../../littlevgl/src/lv_objx/lv_win.h" #include "../../../../littlevgl/src/lv_objx/lv_tabview.h" #include "../../../../littlevgl/src/lv_objx/lv_tileview.h" #include "../../../../littlevgl/src/lv_objx/lv_mbox.h" #include "../../../../littlevgl/src/lv_objx/lv_gauge.h" #include "../../../../littlevgl/src/lv_objx/lv_lmeter.h" #include "../../../../littlevgl/src/lv_objx/lv_sw.h" //#include "aui_objx/aui_kb.h" #include "../../../../littlevgl/src/lv_objx/lv_arc.h" #include "../../../../littlevgl/src/lv_objx/lv_preload.h" #include "../../../../littlevgl/src/lv_objx/lv_calendar.h" #include "../../../../littlevgl/src/lv_objx/lv_spinbox.h" /********************* * DEFINES *********************/ /********************** * TYPEDEFS **********************/ /********************** * GLOBAL PROTOTYPES **********************/ /********************** * MACROS **********************/ #ifdef __cplusplus } #endif #endif /*LV_H*/
YifuLiu/AliOS-Things
components/amp/ui/render/include/lvgl.h
C
apache-2.0
3,084
#ifndef _MODEL_BIND_H #define _MODEL_BIND_H #include "view_model.h" #ifdef __cplusplus extern "C" { #endif typedef int (*MODEL_DATA_SEND_TO_VM_F)(vm_msg_t *, int); typedef struct _model_bind_proc_t { bool flag; MODEL_DATA_SEND_TO_VM_F send; }model_bind_proc_t; int model_data_bind_init(MODEL_DATA_SEND_TO_VM_F send); int model_data_bind_deinit(void); int model_data_send_to_vm(vm_msg_t *msg, int len); int model_eval_str(char *name, vm_data_type_t* data); #ifdef __cplusplus } /* extern "C" */ #endif #endif /*_VIEW_BIND_H*/
YifuLiu/AliOS-Things
components/amp/ui/render/include/model_bind.h
C
apache-2.0
562
#ifndef _WIDGET_H #define _WIDGET_H //#include <unistd.h> //#include "amp_system.h" #include "lvgl.h" #include "render_public.h" #include "render_style.h" #ifdef CONFIG_ENGINE_DUKTAPE #include "be_inl.h" #endif #include "amp_defines.h" #ifdef __cplusplus extern "C" { #endif #define UI_MOD_STR "AMP_UI" #define UI_MEM_FREE_CLEAR(addr) \ if ((addr) != NULL) { \ render_free((addr)); \ addr = NULL; \ } typedef enum { render_state_task_crt = 0, render_state_task_entry, render_state_invalid, }render_state_e; typedef enum { msg_unused = 0, msg_vm_to_view, msg_view_to_vm, msg_vm_to_model, msg_model_to_vm, msg_list_to_vm, msg_list_to_view, msg_on_load_trig, msg_on_load_ret, msg_invalid, }vm_msg_type_e; typedef enum { vm_unused = 0, vm_created, vm_to_model, vm_to_view, vm_invalid, }vm_data_state_e; typedef enum { vm_data_none = 0, vm_data_uint, vm_data_int, vm_data_double, vm_data_bool, vm_data_str, vm_data_pointer, vm_data_type_max, }vm_data_type_e; typedef struct _vm_data_type_t { vm_data_type_e type; union { int val_none; void* val_pointer; uint32_t val_uint; int32_t val_int; double val_double; bool val_bool; char *val_str; }; } vm_data_type_t; typedef struct _model_array_element_t { bool flag; char *name; char *full_name; char *props; vm_data_type_t *data; }model_array_element_t; typedef struct _model_array_t { char *name; int ele_num; int array_len; model_array_element_t *element; }model_array_t; typedef enum { widget_type_page = 1, widget_type_button, widget_type_text, widget_type_icon, widget_type_slider, widget_type_bar, widget_type_preload, widget_type_switch, widget_type_roller, widget_type_line, widget_type_image, widget_type_container, widget_type_checkbox, widget_type_text_area, widget_type_qrcode, widget_type_list, widget_type_list_item, widget_type_max }widget_type_e; typedef struct _widget_type_map_t { widget_type_e type; char *name; } widget_type_map_t; typedef enum { widget_clock_hour_angle = 1, widget_clock_second_angle, widget_clock_minute_angle, widget_data_invalid, }widget_data_e; typedef struct _slist_class_t { char *class_name; struct _slist_class_t *next; }slist_class_t; typedef enum { list_parent = 1, list_child, list_child_rdy, list_invalid, }widget_list_flag_e; typedef struct _widget_desc_t { char *id; slist_class_t *class; int class_num; widget_type_e type; int state; bool disabled; bool timer_flag; bool sub_flag; char *data; void *attribute; void *custom_style; widget_common_style_t *common_style; #if 0 widget_style_t *style; uint32_t style_len; int cur_style; int cur_val; #else amp_widget_style_t widget_style; #endif void *object; void *widget; uint32_t child_num; uint32_t disp_num; struct _widget_desc_t *parent; list child; list child_display; list_node_t node; list_node_t node_display; widget_list_flag_e array_parent; widget_list_flag_e array_child; model_array_t *array; int index; }widget_desc_t; typedef int (*WIDGST_CREATE_F)(widget_desc_t*); typedef int (*WIDGST_DELETE_F)(widget_desc_t*); typedef int (*WIDGST_ATTR_PARSE_F)(widget_desc_t*, char*, char*); typedef int (*WIDGST_STYLE_INIT_F)(widget_desc_t*); typedef int (*WIDGST_STYLE_PARSE_F)(widget_style_handle_t *, uint32_t, char*, uint32_t); typedef int (*WIDGST_CUSTOM_STYLE_PARSE_F)(widget_desc_t *, uint32_t, char*, uint32_t); typedef int (*WIDGST_UPDATE_F)(widget_desc_t*); typedef int (*WIDGST_REFRESH_F)(widget_desc_t*); typedef int (*WIDGST_PAINT_F)(widget_desc_t*); typedef int (*WIDGST_ERASE_F)(widget_desc_t*); typedef int (*WIDGST_SET_ATTR_F)(widget_desc_t*,char *, vm_data_type_t *); typedef int (*WIDGST_SET_TEXT_F)(widget_desc_t*); typedef int (*WIDGST_SET_TEXT_AREA_F)(widget_desc_t*); typedef int (*WIDGST_SET_QRCODE_F)(widget_desc_t*); typedef int (*WIDGST_PARA_COPY_F)(widget_desc_t *dest, widget_desc_t *src); typedef struct _widget_style_type_map_t { int type; char *name; WIDGST_STYLE_PARSE_F parse; } widget_style_type_map_t; typedef struct _widget_proc_t { bool flag; widget_type_e type; WIDGST_CREATE_F create; WIDGST_DELETE_F delete; WIDGST_ATTR_PARSE_F attr_parse; WIDGST_STYLE_INIT_F style_init; WIDGST_CUSTOM_STYLE_PARSE_F style_parse; WIDGST_PAINT_F paint; WIDGST_ERASE_F erase; WIDGST_UPDATE_F update; WIDGST_REFRESH_F refresh; WIDGST_SET_ATTR_F set_attr; WIDGST_SET_TEXT_F set_text; WIDGST_SET_TEXT_AREA_F set_text_area; WIDGST_SET_QRCODE_F set_qrcode; WIDGST_PARA_COPY_F copy; }widget_proc_t; typedef enum { page_state_free = 0, page_state_init, page_state_loading, page_state_loaded, page_state_erase, page_state_delete, }page_stete_e; typedef struct { /* options object */ int object; /* ref of globalData */ int data; /* ref of onShow() */ int on_show; /* ref of onUpdate() */ int on_update; /* ref of onExit() */ int on_exit; }page_options_t; typedef struct _page_desc_t { page_stete_e state; int index; char name[32]; char path[64]; char css_file[64]; char xml_file[64]; char js_file[64]; uint32_t total_num; uint32_t used_num; widget_desc_t *root_widget; widget_desc_t **widgets; struct _page_desc_t *next_page; css_parse_state_e parse_state; list style_class; widget_style_handle_t widget_handle; page_options_t options; }page_desc_t; typedef struct _amp_app_desc_t { uint32_t state; int cur_page; int next_page; int num; char *name; page_desc_t *page; }amp_app_desc_t; extern bool g_page_active; extern widget_desc_t **g_widget; extern uint32_t g_widget_num; extern uint32_t g_widget_total; extern widget_desc_t *g_page_root; widget_desc_t *amp_ui_widget_get(page_desc_t* page, char *id); int amp_ui_widget_type_get(char *str); widget_desc_t *amp_ui_widget_creat(page_desc_t* page, widget_type_e type); widget_proc_t *amp_ui_widget_proc_get(widget_type_e type); int amp_ui_widget_proc_reg(widget_type_e type, widget_proc_t *proc); void clock_demo_entry(); int clock_get_seconds_angle(); int clock_get_minutes_angle(); int clock_get_hours_angle(); void amp_bar_proc_init(void); void amp_button_proc_init(void); void amp_image_proc_init(void); void amp_line_proc_init(void); void amp_preload_proc_init(void); void amp_roller_proc_init(void); void amp_slider_proc_init(void); void amp_switch_proc_init(void); void amp_text_proc_init(void); void amp_text_area_proc_init(void); void amp_qrcode_proc_init(void); void amp_cont_proc_init(void); int amp_ui_xml_file_load(page_desc_t* page); int amp_ui_css_file_load(page_desc_t* page); int amp_ui_style_refresh(widget_desc_t *widget); int amp_ui_style_update(page_desc_t* page, widget_desc_t *widget); int amp_ui_layout(widget_desc_t *root); int amp_ui_paint(widget_desc_t *root); int amp_ui_widget_erase(widget_desc_t *widget); int amp_ui_widget_delete(widget_desc_t *widget); int render_init(void); char *amp_bind_para_parse(char *data); int amp_data_bind(widget_desc_t *widget, char *props, char* value); int amp_ui_widget_style_init(widget_desc_t* widget); int amp_ui_widget_style_copy(widget_desc_t* widget,widget_desc_t* src); extern void page_entry(void *para); extern void page_exit(void *para); extern void page_update(void *para); extern uint64_t g_time_render[10]; extern amp_app_desc_t g_app; #ifdef __cplusplus } /* extern "C" */ #endif #endif /*_WIDGET_H*/
YifuLiu/AliOS-Things
components/amp/ui/render/include/render.h
C
apache-2.0
8,667
#ifndef _WIDGET_BASE_H #define _WIDGET_BASE_H #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> //#include <memory.h> #include "amp_defines.h" //#include "amp_system.h" #ifdef __cplusplus extern "C" { #endif #if 0 typedef unsigned char uint8_t; typedef signed char int8_t; typedef unsigned short uint16_t; typedef signed short int16_t; typedef unsigned int uint32_t; typedef signed int int32_t; // typedef unsigned long long uint64_t; // typedef long long int64_t; #endif typedef union { uint32_t value; struct { uint8_t b; uint8_t g; uint8_t r; uint8_t a; }; struct { uint8_t blue; uint8_t green; uint8_t red; uint8_t alpha; }; } widget_color; typedef struct _widget_default_type_map_t { int type; char *name; } widget_default_type_map_t; typedef struct _list_node_t { struct _list_node_t *prev; struct _list_node_t *next; void *data; }list_node_t; typedef struct _list { list_node_t head; list_node_t tail; uint32_t len; }list; char *widget_str_duplicate(char *src); int widget_style_type_get(char *str); bool widget_str_equal(char *str1, char *str2); int widget_str2type(char *name, widget_default_type_map_t* map, int max); int widget_str2uint(char *str, uint32_t *data); int widget_str2int(char *str, int32_t *data); int widget_color_parse(char *str, widget_color *color); void amp_list_init(list* list); void amp_node_insert(list_node_t *list_node, list_node_t *node); void amp_node_delete(list_node_t *node); void amp_list_node_insert(list* list, int index, list_node_t *node); void amp_list_node_append(list* list, list_node_t *node); int amp_list_node_delete(list *list, list_node_t *node); int amp_strtok_num_get(char *str, const char *delim); #if 0 void *amp_debug_malloc(uint32_t size, char* func, int line); void *amp_debug_calloc(uint32_t nitems, uint32_t size, char* func, int line); void *amp_debug_realloc(void* addr, uint32_t size, char* func, int line); void amp_debug_free(void* addr, char* func, int line); #define render_alloc(size) amp_debug_malloc(size, __func__, __LINE__) #define render_calloc(nitems, size) amp_debug_calloc(nitems, size, __func__, __LINE__) #define render_realloc(addr, size) amp_debug_realloc(addr, size, __func__, __LINE__) #define render_free(addr) amp_debug_free(addr, __func__, __LINE__) #else #define render_alloc aos_malloc #define render_calloc aos_calloc #define render_realloc aos_realloc #define render_free aos_free #endif #ifdef __cplusplus } /* extern "C" */ #endif #endif /*_WIDGET_BASE_H*/
YifuLiu/AliOS-Things
components/amp/ui/render/include/render_public.h
C
apache-2.0
2,739
#ifndef _WIDGET_STYLE_H #define _WIDGET_STYLE_H #include "render_public.h" #ifdef __cplusplus extern "C" { #endif #define STYLE_MAX_CLASS_SELECTOR_ONCE 32 typedef enum { //css_parse_start, css_parse_selector_start, css_parse_selector_id, css_parse_selector_class_flag, css_parse_selector_class, css_parse_property, css_parse_value, css_parse_finish, css_parse_invalid, }css_parse_state_e; typedef enum { style_width, style_height, style_top, style_left, style_align, style_main_color, style_grad_color, style_radius, style_opacity, style_border_color, style_border_width, style_border_part, style_border_opacity, style_shadow_color, style_shadow_width, style_shadow_type, style_padding_ver, style_padding_hor, // style_padding_left, // style_padding_right, style_padding_inner, style_text_size, style_text_color, style_text_sel_color, style_text_font, style_text_letter_space, style_text_line_space, style_text_opacity, style_text_align, style_image_color, style_image_intense, style_image_opacity, style_line_color, style_line_width, style_line_opacity, style_line_type, style_position, style_z_index, style_max, }widget_style_type_e; typedef enum { style_data_none = 0, style_data_uint, style_data_int, style_data_float, style_data_bool, style_data_str, style_data_color, style_data_type_max, }widget_data_type_e; typedef enum { selector_none = 0, selector_id, selector_class, selector_max, }widget_style_selector_e; typedef enum { position_static, position_fix, position_absolute, position_invalid, }widget_position_e; typedef struct _widget_style_t { widget_style_selector_e selector; widget_data_type_e type; union { int val_none; uint32_t val_uint; int32_t val_int; float val_float; bool val_bool; char *str; widget_color val_color; }; } widget_style_t; typedef struct _widget_user_style_t { widget_style_t *sheet; uint32_t length; } widget_user_style_t; typedef struct _widget_basic_style_t { uint16_t width; uint16_t height; uint16_t top; uint16_t left; uint16_t align; uint16_t text_align; int z_index; widget_position_e position; }widget_basic_style_t; typedef struct _widget_common_style_t { widget_basic_style_t basic_style; lv_style_t style; }widget_common_style_t; typedef struct _amp_widget_style_t { widget_style_t *style; bool flag; uint32_t style_len; int cur_style; int cur_val; char *class; }amp_widget_style_t; typedef struct _widget_style_class_t { amp_widget_style_t widget_style; list_node_t node; }widget_style_class_t; typedef struct _widget_style_handle_t { amp_widget_style_t *handle[STYLE_MAX_CLASS_SELECTOR_ONCE]; uint32_t num; }widget_style_handle_t; #ifdef __cplusplus } /* extern "C" */ #endif #endif /*_WIDGET_STYLE_H*/
YifuLiu/AliOS-Things
components/amp/ui/render/include/render_style.h
C
apache-2.0
3,315
#ifndef _VIEW_BIND_H #define _VIEW_BIND_H #include "view_model.h" #ifdef __cplusplus extern "C" { #endif typedef int (*VIEW_SEND_TO_VM_F)(vm_msg_t *, int); typedef int (*VIEW_DATA_BIND_VM_F)(widget_desc_t *, char *, char *); typedef int (*VIEW_DATA_UNBIND_VM_F)(widget_desc_t *, char *, char *); typedef struct _view_bind_proc_t { bool flag; VIEW_SEND_TO_VM_F send; VIEW_DATA_BIND_VM_F bind; VIEW_DATA_UNBIND_VM_F unbind; }view_bind_proc_t; int view_data_bind_init(VIEW_DATA_BIND_VM_F bind, VIEW_DATA_UNBIND_VM_F unbind, VIEW_SEND_TO_VM_F send); int view_data_bind_deinit(void); int view_data_send_to_vm(vm_msg_t *msg, int len); int view_data_bind(widget_desc_t *widget, char *props, char* name); int view_data_unbind(widget_desc_t *widget, char *props, char *name); int view_msg_create(void); int view_msg_proc(void); int view_msg_put(vm_msg_t* msg, int size); #ifdef __cplusplus } /* extern "C" */ #endif #endif /*_VIEW_BIND_H*/
YifuLiu/AliOS-Things
components/amp/ui/render/include/view_bind.h
C
apache-2.0
987
#ifndef _VIEW_MODEL_H #define _VIEW_MODEL_H //#include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> //#include <memory.h> #include "aos_system.h" #include "render.h" #ifdef __cplusplus extern "C" { #endif typedef struct _vm_desc_t{ vm_data_state_e state; widget_desc_t *widget; char *name; char *props; //vm_data_type_e type; vm_data_type_t data; int num; }vm_desc_t; typedef struct _vm_msg_t{ vm_desc_t payload; vm_msg_type_e type; }vm_msg_t; int vm_msg_put(vm_msg_t* msg, int size); int vm_data_register(widget_desc_t * widget, char *props, char *name); int vm_data_send_to_view(vm_msg_type_e msg_type, vm_desc_t *payload, int num); bool vm_data_is_registered(widget_desc_t * widget, char *name); int vm_data_duplicate(widget_desc_t *src, widget_desc_t *dest, char *name, int index); int vm_props_set(widget_desc_t *widget, char *name, vm_data_type_t *value, int index); int amp_view_model_init(); #ifdef __cplusplus } /* extern "C" */ #endif #endif /*_VIEW_MODEL_H*/
YifuLiu/AliOS-Things
components/amp/ui/render/include/view_model.h
C
apache-2.0
1,120
/** * @file amp_list.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AMP_LIST_H #define AMP_LIST_H #ifdef __cplusplus extern "C" { #endif /** @addtogroup amp_list LIST * list data structure manage. * * @{ */ /* * 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 amp_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 amp_container_of(ptr, type, member) \ ((type *)((char *)(ptr) - amp_offsetof(type, member))) /* for double link list */ typedef struct dlist_s { struct dlist_s *prev; struct dlist_s *next; } dlist_t; /* * add one node into data list. * * @param[in] node the data node to be inserted. * @param[in] prev previous data node address. * @param[in] next next data node address. */ 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 - amp_offsetof(type, member))) /* * add one node just behind specified node. * * @param[in] node the data node to be inserted. * @param[in] queue the specified last node. */ static inline void dlist_add(dlist_t *node, dlist_t *queue) { __dlist_add(node, queue, queue->next); } /* * add one node just before specified node. * * @param[in] node the data node to be inserted. * @param[in] queue the specified next node before which new node should be inserted. */ static inline void dlist_add_tail(dlist_t *node, dlist_t *queue) { __dlist_add(node, queue->prev, queue); } /* * delete one node from the data list. * * @param[in] node the data node to be deleted. */ static inline void dlist_del(dlist_t *node) { dlist_t *prev = node->prev; dlist_t *next = node->next; prev->next = next; next->prev = prev; } /* * initialize one node. * * @param[in] node the data node to be initialized. */ static inline void dlist_init(dlist_t *node) { node->next = node->prev = node; } /* * initialize one node. * * @param[in] list the data node to be initialized. */ static inline void INIT_AMP_DLIST_HEAD(dlist_t *list) { list->next = list; list->prev = list; } /* * Judge whether data list is empty. * * @param[in] head the head node of data list. * * @return 1 on empty, 0 FALSE. */ 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 AMP_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 = amp_container_of((queue)->next, type, member); \ &node->member != (queue); \ node = amp_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 = amp_container_of((queue)->next, type, member), \ n = (queue)->next ? (queue)->next->next : NULL; \ &node->member != (queue); \ node = amp_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) amp_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. * * @return list length. */ 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 AMP_DLIST_HEAD_INIT(name) {&(name), &(name)} /* * Initialise the list. * * @param[in] name the list to be initialized. */ #define AMP_DLIST_HEAD(name) dlist_t name = AMP_DLIST_HEAD_INIT(name) /* for single link list */ typedef struct slist_s { struct slist_s *next; } slist_t; /* * add one node into a signle link list at head. * * @param[in] node the data node to be inserted. * @param[in] head the specified head node. */ static inline void slist_add(slist_t *node, slist_t *head) { node->next = head->next; head->next = node; } /* * add one node into a signle link list at tail. * * @param[in] node the data node to be inserted. * @param[in] head the specified head node. */ static inline void slist_add_tail(slist_t *node, slist_t *head) { while (head->next) { head = head->next; } slist_add(node, head); } /* * delete one node from the head list. * * @param[in] node the data node to be deleted. * @param[in] head the specified head node. */ 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; } } /* * Judge whether data list is empty. * * @param[in] head the head node of data list. * * @return 1 on empty, 0 FALSE. */ static inline int slist_empty(const slist_t *head) { return !head->next; } /* * initialize one node. * * @param[in] head the data node to be initialized. */ 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 = amp_container_of((queue)->next, type, member); \ (uintptr_t)node + amp_offsetof(type, member) != 0; \ node = amp_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 = amp_container_of((queue)->next, type, member), \ tmp = (queue)->next ? (queue)->next->next : NULL; \ (uintptr_t)node + amp_offsetof(type, member) != 0; \ node = amp_container_of(tmp, type, member), tmp = tmp ? tmp->next : tmp) /* * Initialise the list. * * @param[in] name the list to be initialized. */ #define AMP_SLIST_HEAD_INIT(name) {0} /* * Initialise the list. * * @param[in] name the list to be initialized. */ #define AMP_SLIST_HEAD(name) slist_t name = AMP_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 - amp_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. * * @return list length. */ 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 /* AMP_LIST_H */
YifuLiu/AliOS-Things
components/amp/utils/list/amp_list.h
C
apache-2.0
10,953
TARGET = libadapter.a MODULE = adapter MOD_SOURCES := \ platform/linux/peripheral/amp_hal_adc.c \ platform/linux/peripheral/amp_hal_can.c \ platform/linux/peripheral/amp_hal_gpio.c \ platform/linux/peripheral/amp_hal_i2c.c \ platform/linux/peripheral/amp_hal_pwm.c \ platform/linux/peripheral/amp_hal_rtc.c \ platform/linux/peripheral/amp_hal_spi.c \ platform/linux/peripheral/amp_hal_timer.c \ platform/linux/peripheral/amp_hal_uart.c \ platform/linux/peripheral/amp_hal_vuart.c \ platform/linux/peripheral/amp_hal_wdg.c \ platform/linux/network/amp_cellular.c \ platform/linux/network/amp_wifi.c \ platform/linux/network/amp_tcp.c \ platform/linux/network/amp_udp.c \ platform/linux/network/amp_httpc.c \ platform/linux/amp_flash.c \ platform/linux/amp_fs.c \ platform/linux/amp_kv.c \ platform/linux/amp_pm.c \ platform/linux/amp_system.c \ platform/linux/amp_socket.c \ MOD_INCLUDES := \ include \ include/peripheral \ ../components/http/include \ ../components/ulog \ ../main \ ../utils/mbedtls/include \ ../utils/mbedtls/platform/include \ ../utils/mbedtls/platform/amp/include \ ./platform/linux \ portfiles \ ifeq ($(ADDON), ui) MOD_SOURCES += \ platform/linux/aui_drivers/indev/FT5406EE8.c \ platform/linux/aui_drivers/indev/keyboard.c \ platform/linux/aui_drivers/indev/mouse.c \ platform/linux/aui_drivers/indev/mousewheel.c \ platform/linux/aui_drivers/indev/evdev.c \ platform/linux/aui_drivers/indev/XPT2046.c \ platform/linux/aui_drivers/display/fbdev.c \ platform/linux/aui_drivers/display/scaler.c \ platform/linux/aui_drivers/display/monitor.c \ platform/linux/aui_drivers/display/R61581.c \ platform/linux/aui_drivers/display/SSD1963.c \ platform/linux/aui_drivers/display/ST7565.c MOD_INCLUDES += \ platform/linux/aui_drivers \ platform/linux/aui_drivers/display \ platform/linux/aui_drivers/indev \ ../ui/aui/include \ ../ui/aui/libs \ ../ui/aui/libs/lvgl\ ../ui/aui/libs/lvgl/lv_misc \ ../ui/aui/libs/lvgl/lv_font \ ../ui/aui/libs/lvgl/lv_core \ ../ui/aui/libs/lvgl/lv_draw \ ../ui/aui/libs/lvgl/lv_hal \ ../ui/aui/libs/lvgl/lv_objx \ ../ui/aui/libs/lvgl/lv_themes \ /usr/include/SDL2 endif include $(TOOLS_DIR)/rules.mk
YifuLiu/AliOS-Things
components/amp_adapter/Makefile
Makefile
apache-2.0
2,265
NAME := amp_adapter $(NAME)_MBINS_TYPE := app $(NAME)_VERSION := 1.0.0 $(NAME)_SUMMARY := amp adapter $(NAME)_SOURCES += \ platform/aos/aos_fs.c \ platform/aos/haas700/amp_ota_port.c \ platform/aos/aos_system.c \ platform/aos/network/aos_cellular.c \ platform/aos/network/aos_httpc.c \ platform/aos/network/aos_netdev.c \ platform/aos/network/aos_tcp.c \ platform/aos/network/aos_udp.c \ platform/aos/network/aos_wifi.c \ platform/aos/peripheral/aos_hal_adc.c \ platform/aos/peripheral/aos_hal_can.c \ platform/aos/peripheral/aos_hal_flash.c \ platform/aos/peripheral/aos_hal_gpio.c \ platform/aos/peripheral/aos_hal_i2c.c \ platform/aos/peripheral/aos_hal_lcd.c \ platform/aos/peripheral/aos_hal_pwm.c \ platform/aos/peripheral/aos_hal_rtc.c \ platform/aos/peripheral/aos_hal_spi.c \ platform/aos/peripheral/aos_hal_timer.c \ platform/aos/peripheral/aos_hal_uart.c \ platform/aos/peripheral/aos_hal_wdg.c \ $(NAME)_INCLUDES += \ platform/aos/network GLOBAL_INCLUDES += \ include \ platform/aos \ platform/aos/haas700/ \ include/peripheral
YifuLiu/AliOS-Things
components/amp_adapter/aos.mk
Makefile
apache-2.0
1,154
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef AMP_FS_H #define AMP_FS_H #include <fcntl.h> #include "amp_platform.h" #ifdef AOS_COMP_VFS #include <aos/vfs.h> #endif #if defined(__cplusplus) extern "C" { #endif /** * @brief aos_fs_init() initializes vfs system. * * @param[in] NULL * * @return On success, return new file descriptor. * On error, negative error code is returned to indicate the cause * of the error. */ int aos_fs_init(); int aos_rmdir_r(const char *path); /** * @brief get file system used size in bytes; * * @return fs used size in bytes; negative if failed. */ int aos_fs_usedsize(void); /** * @brief get file system free size in bytes; * * @return fs free size in bytes; negative if failed. */ int aos_fs_freesize(void); /** * @brief kv componment(key-value) initialize * * @return 0: success, -1: failed */ int aos_fs_type(unsigned int mode); #if defined(__cplusplus) } #endif #endif /* AMP_FS_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_fs.h
C
apache-2.0
1,016
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef _AOS_HTTPC_H_ #define _AOS_HTTPC_H_ #include "lwip/sockets.h" struct hostent *aos_httpc_get_host_by_name(const char *name); int aos_httpc_socket_connect(uintptr_t fd, const struct sockaddr *name, socklen_t namelen); #endif /* _AOS_HTTPC_H_ */
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_httpc.h
C
apache-2.0
321
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef AOS_LOG_H #define AOS_LOG_H #include <stdarg.h> #include <string.h> typedef enum { AOS_LOG_NONE, /* disable log */ AOS_LOG_FATAL, /* fatal log will output */ AOS_LOG_ERROR, /* fatal + error log will output */ AOS_LOG_WARN, /* fatal + warn + error log will output(default level) */ AOS_LOG_INFO, /* info + warn + error log will output */ AOS_LOG_DEBUG, /* debug + info + warn + error + fatal log will output */ AOS_LOG_VERBOSE, } haas_log_level_t; /** * Function prototype for syncronized log text, Recommed using below brief API LOGX instead of this. * * @param[in] s Serverity of Log * @param[in] tag Usually File name * @param[in] fmt, ... Variable Parameter, support format print to log * * @return 0 on success, negative error on failure. */ int aos_log(const unsigned char s, const char *tag, const char *fmt, ...); /** * 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. * * @return 0 on success, negative error on failure. */ int aos_log_set_level(haas_log_level_t log_level); #define AOS_LOGF(tag, ...) aos_log(AOS_LOG_FATAL, tag, __VA_ARGS__) #define AOS_LOGE(tag, ...) aos_log(AOS_LOG_ERROR, tag, __VA_ARGS__) #define AOS_LOGW(tag, ...) aos_log(AOS_LOG_WARN, tag, __VA_ARGS__) #define AOS_LOGI(tag, ...) aos_log(AOS_LOG_INFO, tag, __VA_ARGS__) #define AOS_LOGD(tag, ...) aos_log(AOS_LOG_DEBUG, tag, __VA_ARGS__) #define AOS_LOGV(tag, ...) aos_log(AOS_LOG_VERBOSE, tag, __VA_ARGS__) #endif /* AOS_LOG_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_log.h
C
apache-2.0
1,692
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef AOS_NETWORK_H #define AOS_NETWORK_H #include <stdbool.h> #include "aos/kernel.h" #ifndef _AOS_NETWORK_H_ #define _AOS_NETWORK_H_ #define SCANNED_WIFI_COUNT_MAX 32 #define SCANNED_LOCATOR_COUNT_MAX 32 typedef enum { AOS_ERR_WIFI_BASE = 0x3000, /*!< WiFi ERR NUM BASE */ AOS_ERR_WIFI_NOT_INIT, /*!< WiFi driver was not installed by esp_wifi_init */ AOS_ERR_WIFI_NOT_STARTED, /*!< WiFi driver was not started by esp_wifi_start */ AOS_ERR_WIFI_NOT_STOPPED, /*!< WiFi driver was not stopped by esp_wifi_stop */ AOS_ERR_WIFI_IF, /*!< WiFi interface error */ AOS_ERR_WIFI_MODE, /*!< WiFi mode error */ AOS_ERR_WIFI_STATE, /*!< WiFi internal state error */ AOS_ERR_WIFI_CONN, /*!< WiFi internal control block of station or soft-AP error */ AOS_ERR_WIFI_NVS, /*!< WiFi internal NVS module error */ AOS_ERR_WIFI_MAC, /*!< MAC address is invalid */ AOS_ERR_WIFI_SSID, /*!< SSID is invalid */ AOS_ERR_WIFI_PASSWORD, /*!< Password is invalid */ AOS_ERR_WIFI_TIMEOUT, /*!< Timeout error */ AOS_ERR_WIFI_WAKE_FAIL, /*!< WiFi is in sleep state(RF closed) and wakeup fail */ AOS_ERR_WIFI_WOULD_BLOCK, /*!< The caller would block */ AOS_ERR_WIFI_NOT_CONNECT, /*!< Station still in disconnect status */ AOS_ERR_WIFI_POST, /*!< Failed to post the event to WiFi task */ AOS_ERR_WIFI_INIT_STATE, /*!< Invalod WiFi state when init/deinit is called */ AOS_ERR_WIFI_STOP_STATE, /*!< Returned when WiFi is stopping */ AOS_ERR_WIFI_NOT_ASSOC, /*!< The WiFi connection is not associated */ AOS_ERR_WIFI_TX_DISALLOW, /*!< The WiFi TX is disallowed */ AOS_ERR_TCPIP_ADAPTER_INVALID_PARAMS, AOS_ERR_TCPIP_ADAPTER_IF_NOT_READY, AOS_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED, AOS_ERR_TCPIP_ADAPTER_NO_MEM } AOS_NETWORK_ERR_E; typedef enum { AOS_NET_NOINIT = 0, AOS_NET_STA_STARTED, AOS_NET_STA_GOT_IP, AOS_NET_STA_LOST_IP, AOS_NET_STA_DISCONNECTED, AOS_NET_STA_CONNECTED, AOS_NET_STA_STOPED, AOS_NET_STATE_UNKNOWN } AOS_NETWORK_STATE_E; typedef enum { AOS_NETWORK_WIFI, AOS_NETWORK_WIFI_STA, AOS_NETWORK_WIFI_AP, AOS_NETWORK_CELLULAR, AOS_NETWORK_ETHERNET, AOS_NETWORK_UNKNOW, } AOS_NETWORK_TYPE_E; typedef enum { AOS_NETWORK_IPTYPE_IPV4, AOS_NETWORK_IPTYPE_IPV6, AOS_NETWORK_IPTYPE_IPV4V6, AOS_NETWORK_IPTYPE_INVALID } AOS_NETWORK_IPTYPE_E; typedef enum { AOS_NETWORK_SHAREMODE_RNDIS, AOS_NETWORK_SHAREMODE_ECM, AOS_NETWORK_SHAREMODE_INVALID } AOS_NETWORK_SHAREMODE_E; typedef enum { AOS_NETWORK_SHAREMODE_AUTHTYPE_NONE, AOS_NETWORK_SHAREMODE_AUTHTYPE_PAP, AOS_NETWORK_SHAREMODE_AUTHTYPE_CHAP, AOS_NETWORK_SHAREMODE_AUTHTYPE_PAPCHAP, AOS_NETWORK_SHAREMODE_AUTHTYPE_INVALID } AOS_NETWORK_SHAREMODE_AUTHTYPE_E; typedef enum { AOS_WIFI_AUTH_OPEN = 0, AOS_WIFI_AUTH_WEP, AOS_WIFI_AUTH_WPA_PSK, AOS_WIFI_AUTH_WPA2_PSK, AOS_WIFI_AUTH_WPA_WPA2_PSK, AOS_WIFI_AUTH_WPA2_ENTERPRISE, AOS_WIFI_AUTH_MAX } aos_wifi_auth_mode_t; typedef struct { void (*cb)(int status, void *); int wifi_state; int wifi_mode; bool is_initialized; bool is_started; pthread_mutex_t network_mutex; } aos_wifi_manager_t; typedef struct aos_sim_info { char imsi[32]; char imei[32]; char iccid[32]; } aos_sim_info_t; typedef struct aos_locator_info { char mcc[4]; char mnc[4]; int cellid; int lac; int signal; } aos_locator_info_t; typedef struct aos_scanned_locator_info { int num; aos_locator_info_t locator_info[SCANNED_LOCATOR_COUNT_MAX]; } aos_scanned_locator_info_t; typedef struct aos_wifi_info { char ssid[128]; char mac[6]; char ip[16]; int rssi; } aos_wifi_info_t; /** @brief network ifconfig type */ #define IPADDR_STR_LEN 16 typedef struct aos_ifconfig_info { bool dhcp_en; /**< dhcp is enabled */ char ip_addr[IPADDR_STR_LEN]; /**< ip address */ char mask[IPADDR_STR_LEN]; /**< ip address mask */ char gw[IPADDR_STR_LEN]; /**< gateway ip address */ char dns_server[IPADDR_STR_LEN]; /**< dns server address */ char mac[IPADDR_STR_LEN + 2]; /**< mac address */ int rssi; /**< rssi */ } aos_ifconfig_info_t; typedef struct aos_scanned_wifi_info { int num; aos_wifi_info_t wifi_info[SCANNED_WIFI_COUNT_MAX]; } aos_scanned_wifi_info_t; typedef struct aos_sharemode_info { int action; int auto_connect; char apn[99]; char username[64]; char password[64]; AOS_NETWORK_IPTYPE_E ip_type; AOS_NETWORK_SHAREMODE_E share_mode; } aos_sharemode_info_t; typedef struct { char ssid[33]; /**< The SSID of an access point. */ char ap_power; /**< Received Signal Strength Indication, min: -110, max: 0 */ unsigned char bssid[6]; /**< The BSSID of an access point. */ unsigned char channel; /**< The RF frequency, 1-13 */ unsigned char sec_type; /**< details see netmgr_wifi_sec_type */ } aos_wifi_ap_list_t; int aos_wifi_init(aos_wifi_manager_t *wifi_manager); int aos_wifi_start(aos_wifi_manager_t *wifi_manager); int aos_wifi_connect(const char *ssid, const char *passwd); int aos_wifi_stop(aos_wifi_manager_t *wifi_manager); int aos_wifi_disconnect(); int aos_wifi_get_info(aos_wifi_info_t *wifi_info); int aos_wifi_get_state(); int aos_wifi_deinit(aos_wifi_manager_t *wifi_manager); int aos_net_set_ifconfig(aos_ifconfig_info_t *info); int aos_net_get_ifconfig(aos_ifconfig_info_t *info); int aos_wifi_scan(aos_wifi_ap_list_t *ap_list, int ap_list_len); /** * @brief file close * * @param[out] ip: ip pointer * * @return 0: success, -1: failed */ int aos_get_sim_info(aos_sim_info_t *sim_info); /** * @brief file close * * @param[out] ip: ip pointer * * @return 0: success, -1: failed */ int aos_get_locator_info(aos_locator_info_t *locator_info); /** * @brief file close * * @param[out] ip: ip pointer * * @return 0: success, -1: failed */ int aos_get_neighbor_locator_info(void (*cb)(aos_locator_info_t *, int)); /** * @brief file close * * @param[out] ip: ip pointer * * @return 0: success, -1: failed */ int aos_get_network_status(void); /** * @brief file close * * @param[out] ip: ip pointer * * @return 0: success, -1: failed */ AOS_NETWORK_TYPE_E aos_get_network_type(); /* ECM */ /** * @brief get net share mode * * @return mode: 0-RNDIS 1-ECM */ AOS_NETWORK_SHAREMODE_E aos_get_netsharemode(void); /** * @brief set net share mode * * @param[out] share_mode: net mode * * @return 0: success, -1: failed */ int aos_set_netsharemode(AOS_NETWORK_SHAREMODE_E share_mode); /** * @brief net share action * * @param[out] action_p: net share mode: 0-close 1-open * * @return 0: success, -1: failed */ int aos_get_netshareconfig(aos_sharemode_info_t *share_mode_info); /** * @brief file close * * @param[out] ip: ip pointer * * @return 0: success, -1: failed */ int aos_set_netshareconfig(int ucid, int auth_type, aos_sharemode_info_t *share_mode_info); int aos_location_access_wifi_info(aos_wifi_info_t *wifi_info); int aos_location_scaned_wifi_info(aos_scanned_wifi_info_t *scaned_wifi); #endif /* _AOS_NETWORK_H_ */ #endif
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_network.h
C
apache-2.0
7,741
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef AOS_OTA_H #define AOS_OTA_H /** * sys ota upgrade thread function. * * @param[in] ctx device information. * * @return 0 on success, negative error on failure. */ int interval_sys_upgrade_start(void *ctx); /** * submodule ota cb. * * * @param[in] ctx submodule information. * * * @return 0 on success, negative error on failure. */ int interval_module_upgrade_start(void *ctx); /** * amp_fota_image_local_copy. * * * @param[in] image_name image name. * @param[in] image_size image size. * * * @return 0 on success, negative error on failure. */ int aos_fota_image_local_copy(char *image_name, int image_size); #endif /* AOS_OTA_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_ota.h
C
apache-2.0
765
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef __AOS_PCM_H__ #define __AOS_PCM_H__ #define AOS_PCM_DIR_OUT 0 #define AOS_PCM_DIR_IN 1 typedef enum { AOS_PCM_FORMAT_INVALID = -1, AOS_PCM_FORMAT_S16_LE = 0, /* 16-bit signed */ AOS_PCM_FORMAT_S32_LE, /* 32-bit signed */ AOS_PCM_FORMAT_S8, /* 8-bit signed */ AOS_PCM_FORMAT_S24_LE, /* 24-bits in 4-bytes */ AOS_PCM_FORMAT_S24_3LE, /* 24-bits in 3-bytes */ AOS_PCM_FORMAT_MAX, } aos_pcm_format_t; typedef struct { int rate; int channels; int period_size; int period_count; aos_pcm_format_t format; } aos_pcm_config_t; typedef struct { aos_pcm_config_t config; unsigned char dir:1; unsigned char card:2; unsigned char state:3; void *private_data; } aos_pcm_device_t; typedef enum { AOS_SND_DEVICE_OUT_SPEAKER = 1, AOS_SND_DEVICE_OUT_HEADPHONE, AOS_SND_DEVICE_OUT_HEADSET, AOS_SND_DEVICE_OUT_RECEIVER, AOS_SND_DEVICE_OUT_SPEAKER_AND_HEADPHONE, AOS_SND_DEVICE_OUT_SPEAKER_AND_HEADSET, AOS_SND_DEVICE_IN_MAIN_MIC, AOS_SND_DEVICE_IN_HEADSET_MIC, AOS_SND_DEVICE_MAX, } aos_snd_device_t; typedef struct { aos_snd_device_t out_device; int external_pa; int external_pa_pin; int external_pa_delay_ms; int external_pa_active_high; void *priv; } aos_audio_dev_t; /* * Configure external pa control gpio. * * Return: * 0 -- success or unsupport * -1 -- failed */ int aos_ext_pa_config(int gpio, int active_high, int delay_ms); /* * Set output volume. * * Return: * 0 -- success or unsupport * -1 -- failed */ int aos_set_volume(aos_snd_device_t device, int volume); /* * Select audio output/input device * * Return: * 0 -- success or unsupport * -1 -- failed */ int aos_set_path(aos_pcm_device_t *pcm, aos_snd_device_t device); /* * Mute audio output/input. * * Return: * 0 -- success or unsupport * -1 -- failed */ int aos_dev_mute(aos_pcm_device_t *pcm, aos_snd_device_t device, int mute); /** * Configure pcm parameters * * Return: * 0 -- success * -1 -- failed */ int aos_pcm_setup(aos_pcm_device_t *pcm); /** * Open pcm device * * Return: * 0 -- success * -1 -- failed */ int aos_pcm_open(aos_pcm_device_t *pcm); /** * Read data in. Block reading if input data not ready. * * Return read length, or negative if failed. */ int aos_pcm_read(aos_pcm_device_t *pcm, unsigned char *buffer, int nbytes); /* * Block write if free dma buffer not ready, otherwise, * please return after copied. * * Return writen length, or negative if failed. * */ int aos_pcm_write(aos_pcm_device_t *pcm, unsigned char *buffer, int nbytes); /* * Flush remaining data in dma buffer * * Return: * 0 -- success or unsupport * -1 -- failed */ int aos_pcm_flush(aos_pcm_device_t *pcm); /* * close pcm device * * Return: * 0 -- success * -1 -- failed * */ int aos_pcm_close(aos_pcm_device_t *pcm); /* * pcm adapter init * * Return: * 0 -- success * -1 -- failed * */ int amp_pcm_init(void); #endif
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_pcm.h
C
apache-2.0
3,105
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef AOS_PM_H #define AOS_PM_H typedef enum { AOS_CHARGER_STAT_SHUTDOWN = 0, AOS_CHARGER_STAT_CHECK, AOS_CHARGER_STAT_TRICKLE, AOS_CHARGER_STAT_PRE, AOS_CHARGER_STAT_CC, AOS_CHARGER_STAT_CV, AOS_CHARGER_STAT_TERMINAL, AOS_CHARGER_STAT_FAULT } aos_charger_state_t; /** * System enter sleep * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_system_sleep(void); /** * Enable system autosleep interface * * @param[in] mode 1 - autosleep enable, 0 - autosleep disable * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_system_autosleep(int mode); /** * Accquire wakelock * * @param[in] wakelock wakelock instance * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_wakelock_lock(void *wakelock); /** * Release wakelock * * @param[in] wakelock wakelock instance * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_wakelock_unlock(void *wakelock); /** * Accquire wakelock within given time * * @param[in] wakelock wakelock instance * @param[in] msec wakelock keep time in ms * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_wakelock_timedlock(void *wakelock, unsigned int msec); /** * Create wakelock * * @param[in] name wakelock name * * @return 0 : on success, negative number : if an error occurred with any step */ void *aos_wakelock_create(const char *name); /** * Destroy wakelock * * @param[in] wakelock wakelock instance * * @return 0 : on success, negative number : if an error occurred with any step */ void aos_wakelock_release(void *wakelock); /** * Register power key state notifier * * @param[in] cb power key notifier callback (argment: 1 - key down, 0 - key up) * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_pwrkey_notify_register(void (*cb)(int)); /** * Device power down * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_power_down(void); /** * Device power reset * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_power_reset(void); /** * Get battery connection state * * @param[in] state (1 - connected, 0 - disconnected) * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_battery_connect_state_get(int *state); /** * Get battery connection state * * @param[in] store voltage in mV * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_battery_voltage_get(int *voltage); /** * Get battery level * * @param[in] store battery level (0 - 100) * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_battery_level_get(int *level); /** * Get battery temperature * * @param[in] store temperature * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_battery_temperature_get(int *temperature); /** * Get charger connection state * * @param[in] store connection state (1 - connected, 0 - disconnected) * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_charger_connect_state_get(int *state); /** * Get charger state * * @param[in] store charger state * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_charger_state_get(aos_charger_state_t *state); /** * Get charger current * * @param[in] store charger current in mA * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_charger_current_get(int *current); /** * Set charger switch (1 - ON, 0 - OFF) * * @param[in] charger switch onoff * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_charger_switch_set(int enable); /** * Register charger state notify * * @param[in] charger state notify callback (state: 0 - disconnect, 1 - connect) * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_charger_state_notify_register(void (*cb)(int state)); #endif /* AOS_PM_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_pm.h
C
apache-2.0
4,377
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef _AOS_SMARTCARD_H_ #define _AOS_SMARTCARD_H_ typedef enum { AOS_SMARTCARD_ACT_NULL = 0, AOS_SMARTCARD_ACT_2G, AOS_SMARTCARD_ACT_3G, AOS_SMARTCARD_ACT_4G } aos_smartcard_act_t; /** * Configure smartcard * * @param[in] module_type - module type buffer * size - module type buffer size * reset_while_switch - flag to enable/disable reset while switch * card_switch_time - card switch time * module_startup_time - module startup time * * @return 0 : on success, -1 : if an error occurred with any step */ int aos_smartcard_configure(char *module_type, int size, int *reset_while_switch, unsigned short *card_switch_time, unsigned short *module_startup_time); /** * Get imei * * @param[in] imei - imei buffer, size - imei buffer size * * @return 0 : on success, -1 : if an error occurred with any step */ int aos_smartcard_get_imei(char *imei, int size); /** * Get iccid * * @param[in] iccid - iccid buffer, size - iccid buffer size * * @return 0 : on success, -1 : if an error occurred with any step */ int aos_smartcard_get_iccid(char *iccid, int size); /** * Get rssi * * @param[in] rssi - rssi buffer * * @return 0 : on success, -1 : if an error occurred with any step */ int aos_smartcard_get_rssi(int *rssi); /** * Get act * * @param[in] act - act buffer * * @return 0 : on success, -1 : if an error occurred with any step */ int aos_smartcard_get_act(aos_smartcard_act_t *act); /** * Reset module * * @return 0 : on success, -1 : if an error occurred with any step */ int aos_smartcard_reset_module(void); /** * Update phonebook recordings by slot * * @param[in] slot - phone number slot, number - phone number * * @return 0 : on success, -1 : if an error occurred with any step */ int aos_smartcard_cpbw(int slot, char *number); /** * Set phonebook storage location to sim card * * @return 0 : on success, -1 : if an error occurred with any step */ int aos_smartcard_cpbs(void); /** * Read phonebook by slot * * @param[in] slot - phone number slot * name - name buffer * name_size - name buffer size * number - number buffer * number_size - number buffer size * * @return 0 : on success, -1 : if an error occurred with any step */ int aos_smartcard_cpbr(int slot, char *name, int name_size, char *number, int number_size); #endif
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_smartcard.h
C
apache-2.0
2,505
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef _AOS_SOCKET_H_ #define _AOS_SOCKET_H_ #include <sys/socket.h> #include "netdb.h" /** * @brief get socket errno. * * @param[in] NULL * * @return socket errno */ int aos_socket_errno(void); /** * @brief creates an endpoint for communication and returns a descriptor. * * @param[in] domain * @param[in] type * @param[in] protocol * * @return On success, a file descriptor for the new socket is returned. * On error, -1 is returned, and errno is set appropriately */ int aos_socket_open(int domain, int type, int protocol); /** * @brief transmit data to socket. * * @param[in] sockfd * @param[in] data * @param[in] size * @param[in] flags * * @return On success, these calls return the number of bytes sent. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_send(int sockfd, const void *data, size_t size, int flags); /** * @brief receive data from a socket. * * @param[in] sockfd * @param[in] mem * @param[in] len * @param[in] flags * * @return the number of bytes received, or -1 if an error occurred. */ int aos_socket_recv(int sockfd, void *mem, size_t len, int flags); /** * @brief write data to socket. * * @param[in] sockfd * @param[in] data * @param[in] size * * @return On success, these calls return the number of bytes sent. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_write(int sockfd, const void *data, size_t size); /** * @brief read data from a socket. * * @param[in] sockfd * @param[in] data * @param[in] len * * @return the number of bytes received, or -1 if an error occurred. */ int aos_socket_read(int sockfd, void *data, size_t len); /** * @brief transmit data to socket. * * @param[in] sockfd * @param[in] data * @param[in] size * @param[in] flags * @param[in] to * @param[in] tolen * * @return On success, these calls return the number of bytes sent. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_sendto(int sockfd, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen); /** * @brief receive data from a socket. * * @param[in] sockfd * @param[in] data * @param[in] len * @param[in] flags * @param[in] from * @param[in] fromlenq * * @return the number of bytes received, or -1 if an error occurred. */ int aos_socket_recvfrom(int socket, void *data, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); /** * @brief manipulate options for the socket referred to by the file descriptor sockfd. * * @param[in] sockfd * @param[in] level * @param[in] optname * @param[in] optval * @param[in] optlen * * @return On success, zero is returned. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); /** * @brief manipulate options for the socket referred to by the file descriptor sockfd. * * @param[in] sockfd * @param[in] level * @param[in] optname * @param[in] optval * @param[in] optlen * * @return On success, zero is returned. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); /** * @brief connect the socket referred to by the file descriptor sockfd to the address specified by addr. * * @param[in] sockfd * @param[in] addr * @param[in] addrlen * * @return On success, zero is returned. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); /** * @brief assigns the address specified by addr to the socket referred to by the file descriptor sockfd. * * @param[in] sockfd * @param[in] addr * @param[in] addrlen * * @return On success, zero is returned. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); /** * @brief marks the socket referred to by sockfd as a passive socket. * * @param[in] sockfd * @param[in] backlog * * @return On success, zero is returned. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_listen(int sockfd, int backlog); /** * @brief accept the socket referred to by sockfd. * * @param[in] sockfd * @param[in] addr * @param[in] addrlen * * @return On success, zero is returned. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); /** * @brief Monitor multiple file descriptors, waiting until one or more of the file descriptors become "ready" for some class of I/O operatio. * * @param[in] maxfdp1 * @param[in] readset * @param[in] writeset * @param[in] exceptset * @param[in] timeout * * @return On success, zero is returned. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout); /** * @brief Close the socket referred to by sockfd. * * @param[in] sockfd * * @return On success, zero is returned. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_close(int sockfd); /** * @brief Shutdown the socket referred to by sockfd. * * @param[in] sockfd * @param[in] how * * @return On success, zero is returned. * On error, -1 is returned, and errno is set appropriately. */ int aos_socket_shutdown(int socket, int how); #endif /* _AOS_SOCKET_H_ */
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_socket.h
C
apache-2.0
5,785
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef AMP_SYSTEM_H #define AMP_SYSTEM_H #if defined(__cplusplus) extern "C" { #endif #include "stdarg.h" #include "ulog/ulog.h" #include "aos/kernel.h" /* log system operation wrapper */ #define amp_debug(mod, fmt, ...) LOGD(mod, fmt, ##__VA_ARGS__) #define amp_info(mod, fmt, ...) LOGI(mod, fmt, ##__VA_ARGS__) #define amp_warn(mod, fmt, ...) LOGW(mod, fmt, ##__VA_ARGS__) #define amp_error(mod, fmt, ...) LOGE(mod, fmt, ##__VA_ARGS__) #define amp_fatal(mod, fmt, ...) LOGF(mod, fmt, ##__VA_ARGS__) typedef struct amp_heap_info { unsigned long heap_total; /* total heap memory */ unsigned long heap_used; /* used heap memory */ unsigned long heap_free; /* free heap memory */ } amp_heap_info_t; typedef struct _amp_wireless_info_t { int rssi; /* Received Signal Strength Indication */ int snr; /* Signal to Noise Ratio */ int per; /* Packet Error Rate (Unit: PPM, Part Per Million) */ } aos_wireless_info_t; void aos_printf(const char *fmt, ...); /** * @brief get RTOS default priority * * @return default priority */ int aos_snprintf(char *str, const int len, const char *fmt, ...); /** * @brief get RTOS default priority * * @return default priority */ int aos_vsnprintf(char *str, const int len, const char *format, va_list ap); /** * Get system version. * * @return sysinfo_version. */ const char *aos_get_system_version(void); /** * Get system platform type. * * @return platform_type. */ const char *aos_get_platform_type(void); /** * Get device name. * * @return device_name. */ const char *aos_get_device_name(void); /** * @brief get RTOS default priority * * @return default priority */ int aos_system_sleep(void); /** * @brief get RTOS default priority * * @return default priority */ int amp_heap_memory_info(amp_heap_info_t *heap_info); /** * Initialize system */ int aos_system_init(void); /** * @brief get RTOS default priority * * @return default priority */ const char *aos_get_module_hardware_version(void); /** * @brief get RTOS default priority * * @return default priority */ const char *aos_get_module_software_version(void); #if defined(__cplusplus) } #endif #endif /* AMP_SYSTEM_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_system.h
C
apache-2.0
2,306
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef _AOS_TCP_H_ #define _AOS_TCP_H_ /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_tcp_establish(const char *host, unsigned int port); /** * This function will destroy a tcp socket. * * @param[in] fd the file descriptor of the file or device. * * @return 0: success, otherwise: fail. */ int aos_tcp_destroy(unsigned int fd); /** * This function will send data with a tcp socket. * * @param[in] fd the file descriptor of the file or device. * @param[in] buf data buf. * @param[in] len data length. * @param[in] timeout_ms ms of timeout. * * @return 0: success, otherwise: fail. */ int aos_tcp_write(unsigned int fd, const char *buf, unsigned int len, unsigned int timeout_ms); /** * This function will receive data from a tcp socket. * * @param[in] fd the file descriptor of the file or device. * @param[in] buf data buf. * @param[in] len data length. * @param[in] timeout_ms ms of timeout. * * @return 0: success, otherwise: fail. */ int aos_tcp_read(unsigned int fd, char *buf, unsigned int len, unsigned int timeout_ms); #endif /* _AOS_TCP_H_ */
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_tcp.h
C
apache-2.0
1,347
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef __AOS_TTS_H__ #define __AOS_TTS_H__ #include "aos_pcm.h" typedef enum { TEXT_ENCODE_TYPE_UTF8 = 1, TEXT_ENCODE_TYPE_GBK, } aos_text_encode_type_t; typedef enum { AOS_TTS_EVENT_INIT = 0, AOS_TTS_EVENT_DEINIT, AOS_TTS_EVENT_PLAY_START, AOS_TTS_EVENT_PLAY_STOP, AOS_TTS_EVENT_PLAY_COMPLETE, AOS_TTS_EVENT_PLAY_FAIL, AOS_TTS_EVENT_PLAY_INTERRUPT, } aos_tts_event_t; /** * TTS playback interface * * @param[in] text text to play * @param[in] type text encode format * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_play(const char *text, aos_text_encode_type_t type); /** * TTS playback stop interface * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_stop(void); /** * TTS state get interface * * @param[in] volume memory address to store state value * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_state_get(int *state); /** * TTS playback volume set interface * * @param[in] volume volume level * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_volume_set(int volume); /** * TTS playback volume get interface * * @param[in] volume memory address to store volume value * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_volume_get(int *volume); /** * TTS playback pitch set interface * * @param[in] pitch pitch setting * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_pitch_set(int pitch); /** * TTS playback speed set interface * * @param[in] speed speed level * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_speed_set(int speed); /** * TTS playback speed get interface * * @param[in] speed memory address to store speed value * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_speed_get(int *speed); /** * TTS playback out device set * * @param[in] device audio out device selected by user * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_set_out_device(aos_snd_device_t device); /** * TTS playback external pa control config * * @param[in] pin gpio pin number used to turn on/off external pa * @param[in] active_high pin level when external pa is on * @param[in] delay_ms delay in ms after pa is on * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_set_external_pa(int pin, int active_high, int delay_ms); /** * Get tts playing state * * @return 0 : no tts playing, 1 : tts playing */ int aos_tts_is_playing(void); /** * TTS system init * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_init(void (*cb)(aos_tts_event_t event, char *content)); /** * TTS system deinit * * @return 0 : on success, negative number : if an error occurred with any step */ int aos_tts_deinit(void); #endif /* __AOS_TTS_H__ */
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_tts.h
C
apache-2.0
3,252
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef _AOS_UDP_H_ #define _AOS_UDP_H_ #define NETWORK_ADDR_LEN (16) typedef struct { unsigned char addr[NETWORK_ADDR_LEN]; unsigned short port; } aos_networkAddr; /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_udp_socket_create(); /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_udp_socket_bind(int p_socket, unsigned short port); /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_udp_create(char *host, unsigned short port); /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_udp_write(int p_socket, const unsigned char *p_data, unsigned int datalen); /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_udp_read_timeout(int p_socket, unsigned char *p_data, unsigned int datalen, unsigned int timeout); /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_udp_create_without_connect(const char *host, unsigned short port); /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_udp_close_without_connect(int sockfd); /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_udp_joinmulticast(int sockfd, char *p_group); /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_udp_recvfrom(int sockfd, aos_networkAddr *p_remote, unsigned char *p_data, unsigned int datalen, unsigned int timeout_ms); /** * This function will establish a tcp socket. * * @param[in] host host name of tcp socket connect * @param[in] port port. * * @return 0: success, otherwise: fail. */ int aos_udp_sendto(int sockfd, const aos_networkAddr *p_remote, const unsigned char *p_data, unsigned int datalen, unsigned int timeout_ms); #endif /* _AOS_UDP_H_ */
YifuLiu/AliOS-Things
components/amp_adapter/include/aos_udp.h
C
apache-2.0
3,166
/** * @file adc.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_ADC_H #define AOS_HAL_ADC_H #ifdef __cplusplus extern "C" { #endif /** @addtogroup hal_adc ADC * ADC hal API. * * @{ */ #include <stdint.h> /* Define the wait forever timeout macro */ #define HAL_WAIT_FOREVER 0xFFFFFFFFU /* Define ADC config args */ typedef struct { uint32_t sampling_cycle; /**< sampling period in number of ADC clock cycles */ uint8_t adc_atten; uint8_t adc_width; } adc_config_t; /* Define ADC dev hal handle */ 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, otherwise is error */ int32_t aos_hal_adc_init(adc_dev_t *adc); /** * Takes a single sample from an ADC interface * * @note If the ADC is configured with mutiple channels, the result of each channel is * copied to output buffer one by one according to the sequence of the channel registered, * and each result takes sizeof(uint32_t) bytes. * * @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, otherwise is error */ int32_t aos_hal_adc_voltage_value_get(adc_dev_t *adc, uint32_t *output, uint32_t timeout); /** * Takes a single sample from an ADC interface * * @note If the ADC is configured with mutiple channels, the result of each channel is * copied to output buffer one by one according to the sequence of the channel registered, * and each result takes sizeof(uint32_t) bytes. * * @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, otherwise is error */ int32_t aos_hal_adc_raw_value_get(adc_dev_t *adc, uint32_t *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, otherwise is error */ int32_t aos_hal_adc_finalize(adc_dev_t *adc); /** @} */ #ifdef __cplusplus } #endif #endif /* AOS_HAL_ADC_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_adc.h
C
apache-2.0
2,519
/** * @file can.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_CAN_H #define AOS_HAL_CAN_H #ifdef __cplusplus extern "C" { #endif #include <stdint.h> /** @addtogroup hal_can CAN * CAN hal API. * * @{ */ #define CAN_BAUD_1M 1000000 #define CAN_BAUD_500K 500000 #define CAN_BAUD_250K 250000 #define CAN_BAUD_125K 125000 #define CAN_IDE_NORMAL 0 #define CAN_IDE_EXTEND 1 #define CAN_AUTO_BUS_OFF_DISABLE 0 #define CAN_AUTO_BUS_OFF_ENABLE 1 #define CAN_AUTO_RETRY_TRANSMIT_DISABLE 0 #define CAN_AUTO_RETRY_TRANSMIT_ENABLE 1 #if !defined(HAL_CAN_H) /* * CAN handle configuration */ typedef struct { uint32_t baud_rate; /**< baud rate of can */ uint8_t ide; /**< 0:normal can, 1:extend can */ uint8_t auto_bus_off; /**< 1:enable auto bus off, 0:disable */ uint8_t auto_retry_transmit; /**< 1:enable retry transmit, 0:disable */ } can_config_t; /* * CAN device description */ typedef struct { uint8_t port; /**< can port */ can_config_t config; /**< can config */ void *priv; /**< priv data */ } can_dev_t; /* * CAN frameheader config */ typedef struct { uint32_t id; /**< id of can */ uint8_t rtr; /**< 0:data frame, 1:remote frame */ uint8_t dlc; /**< must <=8 */ } can_frameheader_t; /* * CAN filter_item config */ typedef struct{ uint8_t rtr; /**< 0:data frame, 1:remote frame */ uint32_t check_id; /**< the filter identification number */ uint32_t filter_mask; /**< the filter mask number or identification number */ } can_filter_item_t; #endif /** * Initialises a CAN interface * * @param[in] can the interface which should be initialised * * @return 0 : on success, EINVAL : if an error occurred with any step */ int32_t aos_hal_can_init(can_dev_t *can); /** * config a CAN fliter * * @param[in] can the interface which should be initialised * @param[in] filter_grp_cnt 0 will make all id pass. This value must be <=10 * @param[in] filter_config point to a filter config * * @return 0 : on success, EIO : if an error occurred with any step */ int32_t aos_hal_can_filter_init(can_dev_t *can, const uint8_t filter_grp_cnt, can_filter_item_t *filter_config); /** * Transmit data by CAN * * @param[in] can the can interface * @param[in] tx_header frame head * @param[in] data pointer to the start of data * @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 aos_hal_can_send(can_dev_t *can, can_frameheader_t *tx_header, const void *data, const uint32_t timeout); /** * Receive data by CAN * * @param[in] can the can interface * @param[out] rx_header frame head * @param[out] data pointer to the start of data * @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 aos_hal_can_recv(can_dev_t *can, can_frameheader_t *rx_header, void *data, const uint32_t timeout); /** * Deinitialises a CAN interface * * @param[in] can the interface which should be deinitialised * * @return 0 : on success, EIO : if an error occurred with any step */ int32_t aos_hal_can_finalize(can_dev_t *can); /** @} */ #ifdef __cplusplus } #endif #endif /* AOS_HAL_CAN_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_can.h
C
apache-2.0
3,575
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef AOS_HAL_DAC_H #define AOS_HAL_DAC_H #ifdef __cplusplus extern "C" { #endif #include <stdint.h> typedef struct { uint8_t port; /* dac port */ void *priv; /* priv data */ } dac_dev_t; /** * Initialises an dac interface * * @param[in] dac the interface which should be initialised * * @return 0 : on success, EIO : if an error occurred with any step */ int32_t aos_hal_dac_init(dac_dev_t *dac); /** * Start output dac * * @param[in] dac the interface which should be started * @param[out] channel the channel to output dac * * @return 0 : on success, EIO : if an error occurred with any step */ int32_t aos_hal_dac_start(dac_dev_t *dac, uint32_t channel); /** * Stop output dac * * @param[in] dac the interface which should be stopped * @param[out] channel the channel to output dac * * @return 0 : on success, EIO : if an error occurred with any step */ int32_t aos_hal_dac_stop(dac_dev_t *dac, uint32_t channel); /** * Output a value to an dac interface * * @param[in] dac the interface to set value * @param[out] channel the channel to output dac * @param[in] data the value to output * * @return 0 : on success, EIO : if an error occurred with any step */ int32_t aos_hal_dac_set_value(dac_dev_t *dac, uint32_t channel, uint32_t data); /** * Returns the last data output value of the selected dac channel * * @param[in] dac the interface to get value * @param[out] channel channel the channel to output dac * * @return dac output value */ int32_t aos_hal_dac_get_value(dac_dev_t *dac, uint32_t channel); /** * De-initialises an dac interface, Turns off an dac hardware interface * * @param[in] dac the interface which should be de-initialised * * @return 0 : on success, EIO : if an error occurred with any step */ int32_t aos_hal_dac_finalize(dac_dev_t *dac); #ifdef __cplusplus } #endif #endif /* AOS_HAL_DAC_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_dac.h
C
apache-2.0
2,008
/* * Copyright (C) 2015-2017 Alibaba Group Holding Limited */ #ifndef AOS_HAL_FLASH_H #define AOS_HAL_FLASH_H #ifdef __cplusplus extern "C" { #endif #include <stdint.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_LITTLEFS, HAL_PARTITION_LITTLEFS2, HAL_PARTITION_LITTLEFS3, HAL_PARTITION_CUSTOM_1, HAL_PARTITION_CUSTOM_2, HAL_PARTITION_2ND_BOOT, HAL_PARTITION_MBINS_APP, HAL_PARTITION_MBINS_KERNEL, HAL_PARTITION_GPT, HAL_PARTITION_ENV, HAL_PARTITION_ENV_REDUND, HAL_PARTITION_RTOSA, HAL_PARTITION_RTOSB, HAL_PARTITION_BOOT1, HAL_PARTITION_BOOT1_REDUND, HAL_PARTITION_FTL, 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 enum { HAL_FLASH_ERR_OK, /* operation success */ HAL_FLASH_ERR_NAND_BAD, /* Bad block */ HAL_FLASH_ERR_NAND_READ, /* Read fail, can't correct */ HAL_FLASH_ERR_NAND_WRITE, /* Write fail */ HAL_FLASH_ERR_NAND_ERASE, /* Erase fail */ HAL_FLASH_ERR_NAND_FLIPS, /* Too many bitflips, uncorrected */ /* add more hereafter */ } hal_flash_err_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; typedef struct { hal_partition_t p; char *descr; uint32_t offset; uint32_t siz; } hal_mtdpart_info_t; /** * init flash partition * * @param[in] in_partition The target flash logical partition * * @return 0: On success, otherwise is error */ int32_t aos_hal_flash_init(hal_partition_t in_partition); /** * Get the information of the specified flash area * * @param[in] in_partition The target flash logical partition * @param[in] partition The buffer to store partition info * * @return 0: On success, otherwise is error */ int32_t aos_hal_flash_info_get(hal_partition_t in_partition, hal_logic_partition_t **partition); /** * Get the information of all the flash partitions * * @param[in/out] result_errar The pointer to the array of MTD partition info * @param[in/out] cnt The count of the items in the result array * * @return 0 on success, otherwise failure. * * @note Caller is responsible to free the result array memory. */ int32_t aos_hal_flash_mtdpart_info_get(hal_mtdpart_info_t **result_array, int *cnt); /** * 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 aos_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 aos_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 aos_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 aos_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 aos_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 aos_hal_flash_dis_secure(hal_partition_t partition, uint32_t off_set, uint32_t size); /** * Convert physical address to logic partition id and offset in partition * * @param[out] in_partition Point to the logic partition id * @param[out] off_set Point to the offset in logic partition * @param[in] addr The physical address * * @return 0 : On success, EIO : If an error occurred with any step */ int32_t aos_hal_flash_addr2offset(hal_partition_t *in_partition, uint32_t *off_set, uint32_t addr); #ifdef __cplusplus } #endif #endif /* AOS_HAL_FLASH_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_flash.h
C
apache-2.0
8,359
#ifndef AOS_HAL_GPIO_H #define AOS_HAL_GPIO_H #include <aos_hal_gpio_internal.h> typedef aos_hal_gpio_config_t gpio_config_t; typedef aos_hal_gpio_irq_trigger_t gpio_irq_trigger_t; typedef aos_hal_gpio_irq_handler_t gpio_irq_handler_t; typedef aos_hal_gpio_dev_t gpio_dev_t; #endif /* AOS_HAL_GPIO_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_gpio.h
C
apache-2.0
306
/** * @file gpio.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_GPIO_INTERNAL_H #define AOS_HAL_GPIO_INTERNAL_H #ifdef __cplusplus extern "C" { #endif /** @addtogroup hal_gpio GPIO * gpio hal API. * * @{ */ #include <stdint.h> #ifndef ESP_PLATFORM #include "aos/gpioc.h" #endif /* * 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. */ OUTPUT_OPEN_DRAIN_AF, /**< Alternate Function Open Drain Mode. */ OUTPUT_PUSH_PULL_AF, /**< Alternate Function Push Pull Mode. */ } aos_hal_gpio_config_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, IRQ_TRIGGER_LEVEL_HIGH = 0x4, IRQ_TRIGGER_LEVEL_LOW = 0x5, } aos_hal_gpio_irq_trigger_t; /* * GPIO interrupt callback handler */ #ifdef ESP_PLATFORM typedef void (*aos_hal_gpio_irq_handler_t)(int polarity, void *arg); #else typedef aos_gpio_irq_handler_t aos_hal_gpio_irq_handler_t; #endif /* * GPIO dev struct */ typedef struct { uint8_t port; /**< gpio port */ #ifdef ESP_PLATFORM int level; aos_hal_gpio_irq_handler_t irq_handler; void *irq_arg; #else aos_gpioc_ref_t *gpioc; /**gpio device fd*/ int32_t gpioc_index; int32_t pin_index; #endif aos_hal_gpio_config_t config; /**< gpio config */ void *priv; /**< priv data */ } aos_hal_gpio_dev_t; typedef enum { GPIO_INPUT = 0x0000U, /**< Input Floating Mode */ GPIO_OUTPUT_PP = 0x0001U, /**< Output Push Pull Mode */ GPIO_OUTPUT_OD = 0x0011U, /**< Output Open Drain Mode */ } hal_gpio_mode_t; typedef enum { GPIO_PinState_Reset = 0, /**< Pin state 0 */ GPIO_PinState_Set = !GPIO_PinState_Reset, /**< Pin state 1 */ } gpio_pinstate_t; /** * Initialises a GPIO pin * * @note Prepares a GPIO pin for use. * * @param[in] gpio the gpio pin which should be initialised * * @return 0 : on success, otherwise is error */ int32_t aos_hal_gpio_init(aos_hal_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, otherwise is error */ int32_t aos_hal_gpio_output_high(aos_hal_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, otherwise is error */ int32_t aos_hal_gpio_output_low(aos_hal_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 toggled * * @return 0 : on success, otherwise is error */ int32_t aos_hal_gpio_output_toggle(aos_hal_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 * * @return result */ int32_t aos_hal_gpio_get(aos_hal_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[out] value gpio value * * @return 0 : on success, otherwise is error */ int32_t aos_hal_gpio_input_get(aos_hal_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 or both) * @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, otherwise is error */ int32_t aos_hal_gpio_enable_irq(aos_hal_gpio_dev_t *gpio, aos_hal_gpio_irq_trigger_t trigger, aos_hal_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 setted 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, otherwise is error */ int32_t aos_hal_gpio_disable_irq(aos_hal_gpio_dev_t *gpio); /** * Clear an interrupt status for an input GPIO pin. * Using this function on a gpio pin which has generated a interrupt. * * @param[in] gpio the gpio pin which provided the interrupt trigger * * @return 0 : on success, otherwise is error */ int32_t aos_hal_gpio_clear_irq(aos_hal_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, otherwise is error */ int32_t aos_hal_gpio_finalize(aos_hal_gpio_dev_t *gpio); /** @} */ #ifdef __cplusplus } #endif #endif /* AOS_HAL_GPIO_INTERNAL_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_gpio_internal.h
C
apache-2.0
6,967
#ifndef AOS_HAL_I2C_H #define AOS_HAL_I2C_H #include <aos_hal_i2c_internal.h> #define I2C_MODE_MASTER AOS_HAL_I2C_MODE_MASTER #define I2C_MODE_SLAVE AOS_HAL_I2C_MODE_SLAVE typedef aos_hal_i2c_config_t i2c_config_t; typedef aos_hal_i2c_dev_t i2c_dev_t; #endif /* AOS_HAL_I2C_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_i2c.h
C
apache-2.0
284
/** * @file i2c.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_I2C_INTERNAL_H #define AOS_HAL_I2C_INTERNAL_H #ifdef __cplusplus extern "C" { #endif /** @addtogroup hal_i2c I2C * i2c hal API. * * @{ */ #include <stdint.h> /* Define the wait forever timeout macro */ #ifndef HAL_WAIT_FOREVER #define HAL_WAIT_FOREVER 0xFFFFFFFFU #endif #define AOS_HAL_I2C_MODE_MASTER 1 /**< i2c communication is master mode */ #define AOS_HAL_I2C_MODE_SLAVE 2 /**< i2c communication is slave mode */ #define I2C_MEM_ADDR_SIZE_8BIT 1 /**< i2c memory address size 8bit */ #define I2C_MEM_ADDR_SIZE_16BIT 2 /**< i2c memory address size 16bit */ /* * Specifies one of the standard I2C bus bit rates for I2C communication */ #define I2C_BUS_BIT_RATES_100K 100000 #define I2C_BUS_BIT_RATES_400K 400000 #define I2C_BUS_BIT_RATES_3400K 3400000 /* Addressing mode */ #define I2C_HAL_ADDRESS_WIDTH_7BIT 0 /**< 7 bit mode */ #define I2C_HAL_ADDRESS_WIDTH_10BIT 1 /**< 10 bit mode */ /* This struct define i2c config args */ typedef struct { uint32_t address_width; /**< Addressing mode: 7 bit or 10 bit */ uint32_t freq; /**< CLK freq */ uint8_t mode; /**< master or slave mode */ uint16_t dev_addr; /**< slave device addr */ } aos_hal_i2c_config_t; /* This struct define i2c main handle */ typedef struct { uint8_t port; /**< i2c port */ aos_hal_i2c_config_t config; /**< i2c config */ void *priv; /**< priv data */ } aos_hal_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, otherwise is error */ int32_t aos_hal_i2c_init(aos_hal_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 milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0 : on success, otherwise is error */ int32_t aos_hal_i2c_master_send(aos_hal_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 milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0 : on success, otherwise is error */ int32_t aos_hal_i2c_master_recv(aos_hal_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 milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0 : on success, otherwise is error */ int32_t aos_hal_i2c_slave_send(aos_hal_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 milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0 : on success, otherwise is error */ int32_t aos_hal_i2c_slave_recv(aos_hal_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 milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0 : on success, otherwise is error */ int32_t aos_hal_i2c_mem_write(aos_hal_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 milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0 : on success, otherwise is error */ int32_t aos_hal_i2c_mem_read(aos_hal_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, otherwise is error */ int32_t aos_hal_i2c_finalize(aos_hal_i2c_dev_t *i2c); /** @} */ #ifdef __cplusplus } #endif #endif /* AOS_HAL_I2C_INTERNAL_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_i2c_internal.h
C
apache-2.0
5,569
/** * @file lcd.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_LCD_H #define AOS_HAL_LCD_H #ifdef __cplusplus extern "C" { #endif /** @addtogroup hal_lcd LCD * lcd hal API. * * @{ */ #include <stdint.h> #include <stdbool.h> /** * Init the lcd module. * * @retrun 0 on success, otherwise will be failed. */ int32_t aos_hal_lcd_init(void); /** * Uninit the lcd module. * * @retrun 0 on success, otherwise will be failed. */ int32_t aos_hal_lcd_uninit(void); /** * lcd show rect function. * * @param[in] x x coordinate * @param[in] y y coordinate * @param[in] w Graphic Wide * @param[in] h Graphic High * @param[in] buf Graphic Framebuffer * @param[in] rotate Rotate (set true or false, The rotation angle is determined by the drivers) * * @return 0 on success, negative error on failure. */ int32_t aos_hal_lcd_show(int x, int y, int w, int h, uint8_t *buf, bool rotate); /** * udisplay draw function. * * @param[in] x x coordinate * @param[in] y y coordinate * @param[in] w Graphic Wide * @param[in] h Graphic High * @param[in] color Rectangle color * * @return 0 on success, negative error on failure. */ int32_t aos_hal_lcd_fill(int x, int y, int w, int h, uint32_t color); /** @} */ #ifdef __cplusplus } #endif #endif /* AOS_HAL_LCD_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_lcd.h
C
apache-2.0
1,466
#ifndef AOS_HAL_PWM_H #define AOS_HAL_PWM_H #include <aos_hal_pwm_internal.h> typedef aos_hal_pwm_config_t pwm_config_t; typedef aos_hal_pwm_dev_t pwm_dev_t; #endif /* AOS_HAL_PWM_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_pwm.h
C
apache-2.0
188
/** * @file pwm.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_PWM_INTERNAL_H #define AOS_HAL_PWM_INTERNAL_H #ifdef __cplusplus extern "C" { #endif /** @addtogroup hal_pwm PWM * pwm hal API. * * @{ */ #include <stdint.h> typedef struct { uint32_t duty_cycle; /**< the pwm duty_cycle */ uint32_t freq; /**< the pwm freq */ } aos_hal_pwm_config_t; typedef struct { uint8_t port; /**< pwm port */ uint8_t channel; uint8_t active; aos_hal_pwm_config_t config; /**< spi config */ void *priv; /**< priv data */ } aos_hal_pwm_dev_t; /** * Initialises a PWM pin * * @param[in] pwm the PWM device * * @return 0 : on success, otherwise is error */ int32_t aos_hal_pwm_init(aos_hal_pwm_dev_t *pwm); /** * Starts Pulse-Width Modulation signal output on a PWM pin * * @param[in] pwm the PWM device * * @return 0 : on success, otherwise is error */ int32_t aos_hal_pwm_start(aos_hal_pwm_dev_t *pwm); /** * Stops output on a PWM pin * * @param[in] pwm the PWM device * * @return 0 : on success, otherwise is error */ int32_t aos_hal_pwm_stop(aos_hal_pwm_dev_t *pwm); /** * change the para of pwm * * @param[in] pwm the PWM device * @param[in] para the para of pwm * * @return 0 : on success, otherwise is error */ int32_t aos_hal_pwm_para_chg(aos_hal_pwm_dev_t *pwm, aos_hal_pwm_config_t para); /** * 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, otherwise is error */ int32_t aos_hal_pwm_finalize(aos_hal_pwm_dev_t *pwm); /** @} */ #ifdef __cplusplus } #endif #endif /* AOS_HAL_PWM_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_pwm_internal.h
C
apache-2.0
1,772
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef AOS_HAL_RTC_H #define AOS_HAL_RTC_H #ifdef __cplusplus extern "C" { #endif #include <stdint.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 aos_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 aos_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 aos_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 aos_hal_rtc_finalize(rtc_dev_t *rtc); #ifdef __cplusplus } #endif #endif /* AOS_HAL_RTC_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_rtc.h
C
apache-2.0
2,421
#ifndef AOS_HAL_SPI_H #define AOS_HAL_SPI_H #include <aos_hal_spi_internal.h> #ifndef HAL_SPI_H typedef aos_hal_spi_role_e spi_role_e; typedef aos_hal_spi_firstbit_e spi_firstbit_e; typedef aos_hal_spi_work_mode_e spi_work_mode_e; typedef aos_hal_spi_transfer_mode_e spi_transfer_mode_e; typedef aos_hal_spi_data_size_e spi_data_size_e; typedef aos_hal_spi_cs_e spi_cs_e; typedef aos_hal_spi_config_t spi_config_t; typedef aos_hal_spi_dev_t spi_dev_t; typedef aos_hal_spi_attribute_t spi_attribute_t; #endif #endif /* AOS_HAL_SPI_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_spi.h
C
apache-2.0
538
/** * @file spi.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_SPI_INTERNAL_H #define AOS_HAL_SPI_INTERNAL_H #ifdef __cplusplus extern "C" { #endif /** @addtogroup hal_spi SPI * spi hal API. * * @{ */ #include <stdint.h> /* Define the wait forever timeout macro */ #ifndef HAL_WAIT_FOREVER #define HAL_WAIT_FOREVER 0xFFFFFFFFU #endif #ifdef HAL_SPI_H typedef spi_role_e aos_hal_spi_role_e; typedef spi_firstbit_e aos_hal_spi_firstbit_e; typedef spi_work_mode_e aos_hal_spi_work_mode_e; typedef spi_transfer_mode_e aos_hal_spi_transfer_mode_e; typedef spi_data_size_e aos_hal_spi_data_size_e; typedef spi_cs_e aos_hal_spi_cs_e; typedef spi_config_t aos_hal_spi_config_t; typedef spi_dev_t aos_hal_spi_dev_t; typedef spi_attribute_t aos_hal_spi_attribute_t; #else /* 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 */ #define DEFAULT_SPI_SERAIL_LEN 280 typedef enum { SPI_ROLE_SLAVE, SPI_ROLE_MASTER, } aos_hal_spi_role_e; typedef enum { SPI_FIRSTBIT_MSB, SPI_FIRSTBIT_LSB, } aos_hal_spi_firstbit_e; typedef enum { SPI_WORK_MODE_0, // CPOL = 0; CPHA = 0 SPI_WORK_MODE_2, // CPOL = 1; CPHA = 0 SPI_WORK_MODE_1, // CPOL = 0; CPHA = 1 SPI_WORK_MODE_3, // CPOL = 1; CPHA = 1 } aos_hal_spi_work_mode_e; typedef enum { SPI_TRANSFER_DMA, SPI_TRANSFER_NORMAL, } aos_hal_spi_transfer_mode_e; /* size of single spi frame data */ typedef enum { SPI_DATA_SIZE_4BIT = 4, SPI_DATA_SIZE_5BIT, SPI_DATA_SIZE_6BIT, SPI_DATA_SIZE_7BIT, SPI_DATA_SIZE_8BIT, SPI_DATA_SIZE_9BIT, SPI_DATA_SIZE_10BIT, SPI_DATA_SIZE_11BIT, SPI_DATA_SIZE_12BIT, SPI_DATA_SIZE_13BIT, SPI_DATA_SIZE_14BIT, SPI_DATA_SIZE_15BIT, SPI_DATA_SIZE_16BIT, } aos_hal_spi_data_size_e; /* cs signal to active for transfer */ typedef enum { SPI_CS_DIS, SPI_CS_EN, } aos_hal_spi_cs_e; /* Define spi config args */ typedef struct { aos_hal_spi_role_e role; /* spi communication mode */ aos_hal_spi_firstbit_e firstbit; aos_hal_spi_work_mode_e mode; aos_hal_spi_transfer_mode_e t_mode; uint32_t freq; /* communication frequency Hz */ uint16_t serial_len; /* serial frame length, necessary for SPI running as Slave */ aos_hal_spi_data_size_e data_size; aos_hal_spi_cs_e cs; } aos_hal_spi_config_t; /* Define spi dev handle */ typedef struct { uint8_t port; /**< spi port */ aos_hal_spi_config_t config; /**< spi config */ void *priv; /**< priv data */ } aos_hal_spi_dev_t; typedef struct { aos_hal_spi_work_mode_e work_mode; } aos_hal_spi_attribute_t; #endif /* HAL_SPI_H */ /** * Initialises the SPI interface for a given SPI device * * @param[in] spi the spi device * * @return 0 : on success, otherwise is error */ int32_t aos_hal_spi_init(aos_hal_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 milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0 : on success, otherwise is error */ int32_t aos_hal_spi_send(aos_hal_spi_dev_t *spi, const uint8_t *data, uint32_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 milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0 : on success, otherwise is error */ int32_t aos_hal_spi_recv(aos_hal_spi_dev_t *spi, uint8_t *data, uint32_t size, uint32_t timeout); /** * spi send data and recv * * @param[in] spi the spi device * @param[in] tx_data spi send data, only 1 byte * @param[out] rx_data spi recv data * @param[in] rx_size spi data to be recived * @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0, on success, otherwise is error */ int32_t aos_hal_spi_send_recv(aos_hal_spi_dev_t *spi, uint8_t *tx_data, uint8_t *rx_data, uint32_t rx_size, uint32_t timeout); /** * spi send data and then recv data * * @param[in] spi the spi device * @param[in] tx_data the data to be sent * @param[in] tx_size data size to be sent * @param[out] rx_data spi recv data * @param[in] rx_size data size to be recived * @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0, on success, otherwise is error */ int32_t aos_hal_spi_send_and_recv(aos_hal_spi_dev_t *spi, uint8_t *tx_data, uint16_t tx_size, uint8_t *rx_data, uint16_t rx_size, uint32_t timeout); /** * spi send data and then send data * @param[in] spi the spi device * @param[in] tx1_data the first data to be sent * @param[in] tx1_size the first data size to be sent * @param[out] tx2_data the second data to be sent * @param[in] tx2_size the second data size to be sent * @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0, on success, otherwise is error */ int32_t aos_hal_spi_send_and_send(aos_hal_spi_dev_t *spi, uint8_t *tx1_data, uint16_t tx1_size, uint8_t *tx2_data, uint16_t tx2_size, uint32_t timeout); /** * De-initialises a SPI interface * * * @param[in] spi the SPI device to be de-initialised * * @return 0 : on success, otherwise is error */ int32_t aos_hal_spi_finalize(aos_hal_spi_dev_t *spi); /** @} */ #ifdef __cplusplus } #endif #endif /* AOS_HAL_SPI_INTERNAL_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_spi_internal.h
C
apache-2.0
6,126
/** * @file timer.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_TIMER_H #define AOS_HAL_TIMER_H #include <aos_hal_timer_internal.h> typedef aos_hal_timer_config_t timer_config_t; typedef aos_hal_timer_dev_t timer_dev_t; #endif /* AOS_HAL_TIMER_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_timer.h
C
apache-2.0
299
/** * @file timer.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_TIMER_INTERNAL_H #define AOS_HAL_TIMER_INTERNAL_H #ifdef __cplusplus extern "C" { #endif /** @addtogroup hal_timer TIMER * timer hal API. * * @{ */ #include <stdint.h> #define TIMER_RELOAD_AUTO 1 /**< timer reload automatic */ #define TIMER_RELOAD_MANU 0 /**< timer reload manual */ /* Define timer handle function type */ typedef void (*hal_timer_cb_t)(void *arg); /* Define timer config args */ typedef struct { uint64_t period; /**< timer period, us */ uint8_t reload_mode; /**< auto reload or not */ void *handle; hal_timer_cb_t cb; /**< timer handle when expired */ void *arg; /**< timer handle args */ } aos_hal_timer_config_t; /* Define timer dev handle */ typedef struct { int8_t port; /**< timer port */ aos_hal_timer_config_t config; /**< timer config */ void *priv; /**< priv data */ } aos_hal_timer_dev_t; /** * init a hardware timer * * @param[in] tim timer device * * @return 0 : on success, otherwise is error */ int32_t aos_hal_timer_init(aos_hal_timer_dev_t *tim); /** * start a hardware timer * * @param[in] tim timer device * * @return 0 : on success, otherwise is error */ int32_t aos_hal_timer_start(aos_hal_timer_dev_t *tim); /** * stop a hardware timer * * @param[in] tim timer device * * @return none */ void aos_hal_timer_stop(aos_hal_timer_dev_t *tim); /** * start a hardware timer * * @param[in] tim timer device * * @return 0 : on success, otherwise is error */ int32_t aos_hal_timer_reload(aos_hal_timer_dev_t *tim); /** * change the config of a hardware timer * * @param[in] tim timer device * @param[in] para timer config * * @return 0 : on success, otherwise is error */ int32_t aos_hal_timer_para_chg(aos_hal_timer_dev_t *tim, aos_hal_timer_config_t para); /** * De-initialises an TIMER interface, Turns off an TIMER hardware interface * * @param[in] tim timer device * * @return 0 : on success, otherwise is error */ int32_t aos_hal_timer_finalize(aos_hal_timer_dev_t *tim); /** @} */ #ifdef __cplusplus } #endif #endif /* AOS_HAL_TIMER_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_timer_internal.h
C
apache-2.0
2,301
#ifndef AOS_HAL_UART_H #define AOS_HAL_UART_H #include <aos_hal_uart_internal.h> #ifndef HAL_UART_H typedef aos_hal_uart_data_width_t hal_uart_data_width_t; typedef aos_hal_uart_stop_bits_t hal_uart_stop_bits_t; typedef aos_hal_uart_flow_control_t hal_uart_flow_control_t; typedef aos_hal_uart_parity_t hal_uart_parity_t; typedef aos_hal_uart_mode_t hal_uart_mode_t; typedef aos_hal_uart_config_t uart_config_t; typedef aos_hal_uart_dev_t uart_dev_t; #endif #endif /* AOS_HAL_UART_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_uart.h
C
apache-2.0
489
/** * @file uart.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_UART_INTERNAL_H #define AOS_HAL_UART_INTERNAL_H #ifdef __cplusplus extern "C" { #endif /** @addtogroup hal_uart UART * uart hal API. * * @{ */ #include <stdint.h> /* Define the wait forever timeout macro */ #ifndef HAL_WAIT_FOREVER #define HAL_WAIT_FOREVER 0xFFFFFFFFU #endif #ifdef HAL_UART_H typedef hal_uart_data_width_t aos_hal_uart_data_width_t; typedef hal_uart_stop_bits_t aos_hal_uart_stop_bits_t; typedef hal_uart_flow_control_t aos_hal_uart_flow_control_t; typedef hal_uart_parity_t aos_hal_uart_parity_t; typedef hal_uart_mode_t aos_hal_uart_mode_t; typedef uart_config_t aos_hal_uart_config_t; typedef uart_dev_t aos_hal_uart_dev_t; #else /* HAL_UART_H */ /* * UART data width */ typedef enum { DATA_WIDTH_5BIT, DATA_WIDTH_6BIT, DATA_WIDTH_7BIT, DATA_WIDTH_8BIT, DATA_WIDTH_9BIT } aos_hal_uart_data_width_t; /* * UART stop bits */ typedef enum { STOP_BITS_1, STOP_BITS_2 } aos_hal_uart_stop_bits_t; /* * UART flow control */ typedef enum { FLOW_CONTROL_DISABLED, /**< Flow control disabled */ FLOW_CONTROL_CTS, /**< Clear to send, yet to send data */ FLOW_CONTROL_RTS, /**< Require to send, yet to receive data */ FLOW_CONTROL_CTS_RTS /**< Both CTS and RTS flow control */ } aos_hal_uart_flow_control_t; /* * UART parity */ typedef enum { NO_PARITY, /**< No parity check */ ODD_PARITY, /**< Odd parity check */ EVEN_PARITY /**< Even parity check */ } aos_hal_uart_parity_t; /* * UART mode */ typedef enum { MODE_TX, /**< Uart in send mode */ MODE_RX, /**< Uart in receive mode */ MODE_TX_RX /**< Uart in send and receive mode */ } aos_hal_uart_mode_t; /* * UART configuration */ typedef struct { uint32_t baud_rate; /**< Uart baud rate */ aos_hal_uart_data_width_t data_width; /**< Uart data width */ aos_hal_uart_parity_t parity; /**< Uart parity check mode */ aos_hal_uart_stop_bits_t stop_bits; /**< Uart stop bit mode */ aos_hal_uart_flow_control_t flow_control; /**< Uart flow control mode */ aos_hal_uart_mode_t mode; /**< Uart send/receive mode */ } aos_hal_uart_config_t; /* * UART dev handle */ typedef struct { uint8_t port; /**< uart port */ aos_hal_uart_config_t config; /**< uart config */ void *priv; /**< priv data */ void (*cb)(int, void *, uint16_t, void *); void *userdata; } aos_hal_uart_dev_t; #endif /* HAL_UART_H */ typedef int32_t (*uart_rx_cb)(aos_hal_uart_dev_t *uart); /** * Initialises a UART interface * * * @param[in] uart the interface which should be initialised * * @return 0 : on success, otherwise is error */ int32_t aos_hal_uart_init(aos_hal_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 * @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0 : on success, otherwise is error */ int32_t aos_hal_uart_send(aos_hal_uart_dev_t *uart, const void *data, uint32_t size, uint32_t timeout); /** * Transmit data on a UART interface with polling * * @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, otherwise is error */ int32_t aos_hal_uart_send_poll(aos_hal_uart_dev_t *uart, const void *data, uint32_t size); /** * 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, otherwise is error */ int32_t aos_hal_uart_recv(aos_hal_uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t timeout); /** * Receive data on a UART interface with polling * * @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, otherwise is error */ int32_t aos_hal_uart_recv_poll(aos_hal_uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t *recv_size); /** * 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 trully received * @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER * if you want to wait forever * * @return 0 : on success, otherwise is error */ int32_t aos_hal_uart_recv_II(aos_hal_uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t *recv_size, uint32_t timeout); /* * * @param [in] uart the UART interface * @param [in] rx_cb Non-zero pointer is the rx callback handler; * NULL pointer for rx_cb unregister operation * uart in rx_cb must be the same pointer with uart pointer passed to hal_uart_recv_cb_reg * driver must notify upper layer by calling rx_cb if data is available in UART's hw or rx buffer * @return 0: on success, negative no.: if an error occured with any step */ int32_t aos_hal_uart_recv_cb_reg(aos_hal_uart_dev_t *uart, uart_rx_cb cb); /** * Deinitialises a UART interface * * @param[in] uart the interface which should be deinitialised * * @return 0 : on success, otherwise is error */ int32_t aos_hal_uart_finalize(aos_hal_uart_dev_t *uart); /** * Config a UART callback function * * @param[in] uart the interface which should be deinitialised * @param[in] cb the interface which should be callback * @param[in] args the parameters of the calllback function * * @return 0 : on success, otherwise is error */ int32_t aos_hal_uart_callback(aos_hal_uart_dev_t *uart, void (*cb)(int, void *, uint16_t, void *), void *args); int aos_hal_uart_rx_sem_take(int uartid, int timeout); int aos_hal_uart_rx_sem_give(int port); /** @} */ #ifdef __cplusplus } #endif #endif /* AOS_HAL_UART_INTERNAL_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_uart_internal.h
C
apache-2.0
6,918
/** * @file wdg.h * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #ifndef AOS_HAL_WDG_H #define AOS_HAL_WDG_H #ifdef __cplusplus extern "C" { #endif /** @addtogroup hal_wdg WDG * wdg hal API. * * @{ */ #include <stdint.h> /* Define wdt expired time */ typedef struct { uint32_t timeout; /**< Watchdag timeout */ } wdg_config_t; /* Define wdg dev handle */ 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, otherwise is error */ int32_t aos_hal_wdg_init(wdg_dev_t *wdg); /** * Reload watchdog counter. * * @param[in] wdg the watch dog device */ void aos_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, otherwise is error */ int32_t aos_hal_wdg_finalize(wdg_dev_t *wdg); /** @} */ #ifdef __cplusplus } #endif #endif /* AOS_HAL_WDG_H */
YifuLiu/AliOS-Things
components/amp_adapter/include/peripheral/aos_hal_wdg.h
C
apache-2.0
1,202
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "stdio.h" #include <stdlib.h> #include <stdbool.h> #include "aos/errno.h" #include "aos/kernel.h" #ifdef AOS_COMP_KV #include "aos/kv.h" #endif #ifdef AOS_COMP_ULOG #include "ulog/ulog.h" #endif // #include <sys/socket.h>
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/amp_platform.h
C
apache-2.0
296
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "amp_platform.h" #include "aos_system.h" #include "aos_fs.h" #include "aos/vfs.h" #ifndef AOS_BOARD_HAAS700 #include "vfs_types.h" #else #include "fs/vfs_types.h" #endif int aos_fs_init(void) { return 0; } int aos_rmdir_r(const char *path) { struct aos_stat s; int ret = -1; char *dir, *p; int path_len; aos_dir_t *pdir = NULL; aos_dirent_t *entry = NULL; if (!path) return -EINVAL; path_len = strlen(path) + 1; dir = aos_malloc(path_len); if (dir == NULL) { return -1; } memcpy(dir, path, path_len); p = dir + strlen(dir) - 1; while ((*p == '/') && (p > dir)) { *p = '\0'; p--; } if (aos_stat(dir, &s) || !S_ISDIR(s.st_mode)) { aos_printf("%s is neither existed nor a directory\n", dir); goto out; } pdir = aos_opendir(dir); if (!pdir) { aos_printf("opendir %s failed - %s\n", dir, strerror(errno)); goto out; } ret = 0; while ((ret == 0) && (entry = aos_readdir(pdir))) { char fpath[128]; snprintf(fpath, 128, "%s/%s", dir, entry->d_name); ret = aos_stat(fpath, &s); if (ret) { aos_printf("stat %s failed\n", fpath); break; } if (!strcmp(entry->d_name, ".")) continue; if (!strcmp(entry->d_name, "..")) continue; if (S_ISDIR(s.st_mode)) ret = aos_rmdir_r(fpath); else ret = aos_unlink(fpath); } aos_closedir(pdir); if (ret == 0) { ret = aos_rmdir(dir); if (ret) aos_printf("rmdir %s failed\n", dir); } out: aos_free(dir); return ret; } int aos_fs_type(uint mode) { if (mode & S_IFDIR) { return 0; } else if (mode & S_IFREG) { return 1; } return -1; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/aos_fs.c
C
apache-2.0
1,945
#include "aos_log.h" #include <stdarg.h> #include <stdio.h> #include <string.h> #include "ulog/ulog.h" #include "aos/kernel.h" #include "aos/errno.h" static int local_log_level = AOS_LOG_VERBOSE; int aos_log(const unsigned char s, const char *tag, const char *fmt, ...) { if (s > local_log_level) { return 0; } va_list list; va_start(list, fmt); ulog(s, "AOS", tag, 0, fmt, list); va_end(list); return 0; } int aos_log_set_level(haas_log_level_t log_level) { local_log_level = log_level; aos_set_log_level(log_level); }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/aos_log.c
C
apache-2.0
574
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <fcntl.h> #include "k_api.h" #include "aos/kernel.h" #ifdef AOS_COMP_KV #include "aos/kv.h" #endif #ifdef AOS_COMP_VFS #include "aos/vfs.h" #endif #ifdef AOS_COMP_ULOG #include "ulog/ulog.h" #endif #ifndef AOS_BOARD_HAAS700 #include "netmgr.h" #include "netmgr_wifi.h" #endif //#include "infra_config.h" //#include "infra_compat.h" //#include "infra_defs.h" //#include "wrappers_defs.h" #include "aos_system.h" #ifdef BOARD_HAAS200 #include "vfsdev/wifi_dev.h" #endif #define _SYSINFO_DEVICE_NAME "AliOS Things" #define SYSINFO_VERSION "0.0.1" void aos_printf(const char *fmt, ...) { va_list args; va_start(args, fmt); vprintf(fmt, args); va_end(args); fflush(stdout); } int aos_putchar(const char c) { aos_printf("%c", c); } int aos_snprintf(char *str, const int len, const char *fmt, ...) { va_list args; int rc; va_start(args, fmt); rc = vsnprintf(str, len, fmt, args); va_end(args); return rc; } int aos_vsnprintf(char *str, const int len, const char *format, va_list ap) { return vsnprintf(str, len, format, ap); } const char *aos_get_system_version(void) { return SYSINFO_VERSION; } const char *aos_get_platform_type(void) { return _SYSINFO_DEVICE_NAME; } int aos_network_status_registercb(void (*cb)(int status, void *), void *arg) { return aos_wifi_set_msg_cb(cb); } /** * @brief get wifi mac address * @param[out] mac: mac address,format: "01:23:45:67:89:ab" * @param[in] len: size of mac * @returns 0: succeed; -1: failed */ #ifndef MAC2STR #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" #endif int hal_wifi_get_mac_address(char *mac, size_t len) { int ret = 0; #if (defined(BOARD_HAAS100) || defined(BOARD_HAASEDUK1)) extern uint8_t* factory_section_get_wifi_address(void); uint8_t *_mac = factory_section_get_wifi_address(); if(_mac == NULL) ret = -1; else snprintf(mac, len, MACSTR, MAC2STR(_mac)); #elif defined(BOARD_HAAS200) int fd; uint8_t _mac[16]; fd = open("/dev/wifi0", O_RDWR); if (fd < 0) { return -1; } ioctl(fd, WIFI_DEV_CMD_GET_MAC, (unsigned long)_mac); snprintf(mac, len, MACSTR, MAC2STR(_mac)); close(fd); #endif return ret; } char g_chip_id[32]; const char *aos_get_device_name(void) { #if (defined(BOARD_HAAS100) || defined(BOARD_HAASEDUK1)) unsigned char chip_id[16]; tg_get_chipid(chip_id, 16); aos_snprintf(g_chip_id, 32, "haas_%x%x%x%x%x%x", chip_id[0], chip_id[1], chip_id[2], chip_id[3], chip_id[9], chip_id[10]); #else hal_wifi_get_mac_address(g_chip_id, sizeof(g_chip_id)); #endif return g_chip_id; } extern k_mm_head *g_kmm_head; int amp_heap_memory_info(amp_heap_info_t *heap_info) { heap_info->heap_total = g_kmm_head->free_size + g_kmm_head->used_size; heap_info->heap_used = g_kmm_head->used_size; heap_info->heap_free = g_kmm_head->free_size; return 0; } int aos_system_init(void) { return 0; } const char *aos_get_module_hardware_version(void) { return "Module_Hardware_version"; } const char *aos_get_module_software_version(void) { return "Module_Software_version"; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/aos_system.c
C
apache-2.0
3,363
/* * Copyright (C) 2015-2019 Alibaba Group Holding Limited */ #include "aos/kv.h" #include "aos_system.h" #define MOD_STR "APP_MGR" static char app_version[32] = { 0 }; pthread_t system_reboot_thread; void system_reboot(void *argv) { usleep(1000 * 1000); aos_reboot(); } int pyamp_app_upgrade(char *url) { char *key = "_amp_pyapp_url"; int32_t url_len = 0; int32_t ret = 0; url_len = strlen(url); ret = aos_kv_set(key, url, url_len, 1); if (ret != 0) { printf("%s:aos_kv_set failed\n", __func__); } ret = aos_task_new_ext(&system_reboot_thread, "system_reboot", system_reboot, NULL, 1024, AOS_DEFAULT_APP_PRI); if (ret < 0) { printf("pthread_create g_dynreg_dev_thread failed: %d\n", ret); return -1; } return ret; } int save_ssid_and_password(char *ssid, char *password) { char *key_ssid = "_amp_wifi_ssid"; char *key_passwd = "_amp_wifi_passwd"; int32_t ssid_len = 0; int32_t passwd_len = 0; int32_t ret = 0; ssid_len = strlen(ssid); passwd_len = strlen(password); if (ssid_len > 0 && passwd_len > 0) { ret = aos_kv_set(key_ssid, ssid, ssid_len, 1); if (ret != 0) { printf("%s:aos_kv_set failed,key is %s, value is %s, len is %d\n", __func__, key_ssid, ssid, ssid_len); return ret; } ret = aos_kv_set(key_passwd, password, passwd_len, 1); if (ret != 0) { printf("%s:aos_kv_set failed,key is %s, value is %s, len is %d\n", __func__, key_passwd, password, passwd_len); return ret; } } return ret; } int check_channel_enable(void) { int ret = 0; char *key = "app_upgrade_channel"; char value[20] = {0}; int value_len = 20; ret = aos_kv_get(key, value, &value_len); if ((ret == 0) && strcmp(value, "disable") == 0) return 1; else return 0; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/app_ota.c
C
apache-2.0
1,965
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef __AMP_BOARD_CONFIG_H__ #define __AMP_BOARD_CONFIG_H__ #define AMP_RECOVERY_PORT 0 #define AMP_RECOVERY_PORT_BAUDRATE 1500000UL #define AMP_REPL_UART_PORT 0 #define AMP_REPL_UART_BAUDRATE 1500000UL #define AMP_STATUS_IO 40 #define AMP_STATUS_IO_ON 1 /* amp product */ #define PRODUCT_ID KIT #define MODULE_ID HAAS100_HAAS1000 #endif
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/haas100/amp_board_config.h
C
apache-2.0
439
#include "amp_platform.h" #include "aos_system.h" #include "ota_agent.h" void internal_sys_upgrade_start(void *ctx) { ota_service_start((ota_service_t *)ctx); aos_task_exit(0); return; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/haas100/amp_ota_port.c
C
apache-2.0
199
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef __AMP_BOARD_CONFIG_H__ #define __AMP_BOARD_CONFIG_H__ #define AMP_RECOVERY_PORT 0 #define AMP_RECOVERY_PORT_BAUDRATE 115200UL #define AMP_REPL_UART_PORT 0 #define AMP_REPL_UART_BAUDRATE 115200UL #define AMP_STATUS_IO 40 #define AMP_STATUS_IO_ON 1 /* amp product */ #define PRODUCT_ID KIT #define MODULE_ID HAAS200_RTL8723DM #endif
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/haas200/amp_board_config.h
C
apache-2.0
438
#include "amp_platform.h" #include "aos_system.h" #include "ota_agent.h" void internal_sys_upgrade_start(void *ctx) { ota_service_start((ota_service_t *)ctx); aos_task_exit(0); return; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/haas200/amp_ota_port.c
C
apache-2.0
200
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef __AMP_BOARD_CONFIG_H__ #define __AMP_BOARD_CONFIG_H__ #define AMP_RECOVERY_PORT 0 #define AMP_RECOVERY_PORT_BAUDRATE 115200UL #define AMP_REPL_UART_PORT 0 #define AMP_REPL_UART_BAUDRATE 115200UL #define AMP_STATUS_IO 40 #define AMP_STATUS_IO_ON 1 #endif
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/haas700/amp_board_config.h
C
apache-2.0
357
void internal_sys_upgrade_start(void *ctx) { return; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/haas700/amp_ota_port.c
C
apache-2.0
59
/** @defgroup ota_agent_api * @{ * * This is an include file of OTA agent transporting with clould. * * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #ifndef OTA_AGENT_H #define OTA_AGENT_H /******************************************************************* *********** OTA Agent ************** *********** | ************** *********** V ************** *********** Service manager ************** *********** device ----- inform version -----> cloud ************** *********** device ---- subcribe upgrade ----> cloud ************** *********** | ************** *********** V ************** *********** Transport module ************** *********** device <---- transport message --- cloud ************** *********** device <-- new version:url,sign -- cloud ************** *********** | ************** *********** V ************** *********** Download module ************** *********** device <---- download firmware --- cloud ************** *********** | ************** *********** V ************** *********** Common hal module ************** *********** device ---- update image ----> ota part ************** *********** | ************** *********** V ************** *********** Verify module ************** *********** device ---- verfiy firmware ----- verify ************** *********** device ----- report status ----- reboot ************** *********** | ************** *********** V ************** *********** MCU module ************** *********** device ----- send FW ------> MCU ************** ********************************************************************/ #define OTA_VERSION "3.3.0" #define OTA_TRANSTYPE "1" #define OTA_OS_TYPE "0" #define OTA_BOARD_TYPE "0" #ifdef __cplusplus extern "C" { #endif /** @addtogroup aos_ota OTA * OTA upgrade service. * * @{ */ /* OTA upgrade flag */ #define OTA_UPGRADE_CUST 0x8778 /* upgrade user customize image */ #define OTA_UPGRADE_ALL 0x9669 /* upgrade all image: kernel+framework+app */ #define OTA_UPGRADE_XZ 0xA55A /* upgrade xz compressed image */ #define OTA_UPGRADE_DIFF 0xB44B /* upgrade diff compressed image */ #define OTA_UPGRADE_KERNEL 0xC33C /* upgrade kernel image only */ #define OTA_UPGRADE_APP 0xD22D /* upgrade app image only */ #define OTA_UPGRADE_FS 0x7083 /* upgrade fs image only */ #define OTA_BIN_MAGIC_APP 0xabababab #define OTA_BIN_MAGIC_KERNEL 0xcdcdcdcd #define OTA_BIN_MAGIC_ALL 0xefefefef #define OTA_BIN_MAGIC_MCU 0xefcdefcd #define OTA_BIN_MAGIC_FS 0xabcdabcd /** * ENUM: OTA Agent ERRNO. */ typedef enum { OTA_FINISH = 4, /*OTA finish status*/ OTA_DOWNLOAD = 3, /*OTA download status*/ OTA_TRANSPORT = 2, /*OTA transport status*/ OTA_INIT = 1, /*OTA init status*/ OTA_SUCCESS = 0, OTA_INIT_FAIL = -1, /*OTA init failed.*/ OTA_TRANSPORT_INT_FAIL = -2, /*OTA transport init failed.*/ OTA_TRANSPORT_PAR_FAIL = -3, /*OTA transport parse failed.*/ OTA_TRANSPORT_VER_FAIL = -4, /*OTA transport verion is too old.*/ OTA_DOWNLOAD_INIT_FAIL = -5, /*OTA download init failed.*/ OTA_DOWNLOAD_HEAD_FAIL = -6, /*OTA download header failed.*/ OTA_DOWNLOAD_CON_FAIL = -7, /*OTA download connect failed.*/ OTA_DOWNLOAD_REQ_FAIL = -8, /*OTA download request failed.*/ OTA_DOWNLOAD_RECV_FAIL = -9, /*OTA download receive failed.*/ OTA_VERIFY_MD5_FAIL = -10, /*OTA verfiy MD5 failed.*/ OTA_VERIFY_SHA2_FAIL = -11, /*OTA verfiy SH256 failed.*/ OTA_VERIFY_RSA_FAIL = -12, /*OTA verfiy RSA failed.*/ OTA_VERIFY_IMAGE_FAIL = -13, /*OTA verfiy image failed.*/ OTA_UPGRADE_WRITE_FAIL = -14, /*OTA upgrade write failed.*/ OTA_UPGRADE_PARAM_FAIL = -15, /*OTA upgrade parameter failed.*/ OTA_UPGRADE_FW_SIZE_FAIL = -16, /*OTA upgrade FW too big.*/ OTA_UPGRADE_SET_BOOT_FAIL = -17, /*OTA upgrade set boot failed.*/ OTA_CUSTOM_CALLBAK_FAIL = -18, /*OTA custom callback failed.*/ OTA_MCU_INIT_FAIL = -19, /*OTA MCU init failed.*/ OTA_MCU_VERSION_FAIL = -20, /*OTA MCU version failed.*/ OTA_MCU_NOT_READY = -21, /*OTA MCU not ready.*/ OTA_MCU_REBOOT_FAIL = -22, /*OTA MCU fail to reboot.*/ OTA_MCU_HEADER_FAIL = -23, /*OTA MCU header error.*/ OTA_MCU_UPGRADE_FAIL = -24, /*OTA MCU upgrade fail.*/ OTA_INVALID_PARAMETER = -25, /*OTA INVALID PARAMETER.*/ } OTA_ERRNO_E; typedef enum { OTA_REPORT_UPGRADE_ERR = -1, /* ota report upgrading failed to cloud*/ OTA_REPORT_DOWNLOAD_ERR = -2, /* ota report downloading failed to cloud*/ OTA_REPORT_VERIFY_ERR = -3, /* ota report image verified err to cloud*/ OTA_REPORT_BURN_ERR = -4, /* ota report image burning failed to cloud*/ } OTA_REPORT_CLOUD_ERRNO_E; #define OTA_URL_LEN 256 /*OTA download url max len*/ #define OTA_HASH_LEN 66 /*OTA download file hash len*/ #define OTA_SIGN_LEN 256 /*OTA download file sign len*/ #define OTA_VER_LEN 64 /*OTA version string max len*/ typedef enum { OTA_EVENT_UPGRADE_TRIGGER, OTA_EVENT_DOWNLOAD, OTA_EVENT_INSTALL, OTA_EVENT_LOAD, OTA_EVENT_REPORT_VER, } OTA_EVENT_ID; /** * Struct: OTA boot parameter. */ typedef struct { unsigned int dst_adr; /*Single Bank: Destination Address: APP partition.*/ unsigned int src_adr; /*Single Bank: Copy from Source Address: OTA partition.*/ unsigned int len; /*Single Bank: Download file len */ unsigned short crc; /*Single Bank: Download file CRC */ unsigned short upg_flag; /*Upgrade flag: OTA_UPGRADE_ALL OTA_UPGRADE_XZ OTA_UPGRADE_DIFF*/ unsigned char boot_count; /*Boot count: When >=3 Rollback to old version in BL for dual-banker boot*/ int upg_status; /*OTA upgrade status*/ unsigned char hash_type; /*OTA download hash type*/ char url[OTA_URL_LEN]; /*OTA download url*/ char sign[OTA_SIGN_LEN]; /*OTA download file sign*/ char hash[OTA_HASH_LEN]; /*OTA download file hash*/ char ver[OTA_VER_LEN]; /*OTA get version*/ unsigned int old_size; /*Diff upgrade: patch old data size*/ unsigned short patch_num; /*Diff upgrade: patch num*/ unsigned short patch_status; /*Diff upgrade: patch status*/ unsigned int patch_off; /*Diff upgrade: patch offset*/ unsigned int new_off; /*Diff upgrade: patch new data offset*/ unsigned int new_size; /*Diff upgrade: patch new data size*/ unsigned int upg_magic; /*OTA upgrade image magic*/ unsigned char boot_type; /*OS boot type:Single boot(0x00), dual boot(0x01)*/ unsigned char reserved[13]; /*OTA Reserved*/ unsigned short param_crc; /*OTA Parameter crc*/ } ota_boot_param_t; /** * Struct: OTA sign info. */ typedef struct { unsigned int encrypto_magic; /*encrypto type: RSA:0xAABBCCDD or ECC:0xDDCCBBAA*/ char padding_mode; /*sign padding mode:PKCS1 or OAEP*/ char sign_hash_type; /*sign hash type*/ char abstract_hash_type; /*calculate image hash type*/ char reserved[97]; /*reserved buf*/ char hash[32]; /*image hash value(sha256)*/ char signature[256]; /*image digest signature*/ } ota_sign_info_t; /** * Struct: OTA image info. */ typedef struct { unsigned int image_magic; /* image magic */ unsigned int image_size; /* image size */ unsigned char image_md5[16]; /* image md5 info */ unsigned char image_num; /* image number */ unsigned char image_res; /* image resouce */ unsigned short image_crc16; /* image crc16 */ } ota_image_info_t; typedef struct { ota_sign_info_t *sign_info; /* Image sign info */ ota_image_info_t *image_info; /* Package Image info */ } ota_image_header_t; typedef struct { void (*on_user_event_cb)(int event, int errnumb, void *param); void *param; /* users paramter */ } ota_feedback_msg_func_t; typedef int (*report_func)(void *, uint32_t); typedef int (*triggered_func)(void *, char *, char *, void *); typedef struct { report_func report_status_cb; void *param; /* users paramter */ } ota_report_status_func_t; typedef struct { triggered_func triggered_ota_cb; void *param; /* users paramter */ } ota_triggered_func_t; typedef struct { char module_name[33]; char store_path[77]; int module_type; } ota_store_module_info_t; /* OTA service manager */ typedef struct ota_service_s { char pk[20+1]; /* Product Key */ char ps[64+1]; /* Product secret */ char dn[32+1]; /* Device name */ char ds[64+1]; /* Device secret */ unsigned char dev_type; /* device type: 0-->main dev 1-->sub dev*/ char module_name[33]; /* module name*/ unsigned char ota_process; int module_numb; ota_store_module_info_t *module_queue_ptr; ota_feedback_msg_func_t feedback_func; ota_report_status_func_t report_func; /* report percentage to clould */ ota_triggered_func_t ota_triggered_func; /* new version ready, if OTA upgrade or not by User */ int (*on_boot)(ota_boot_param_t *ota_param); /* Upgrade complete to reboot to the new version */ ota_image_header_t header; /* OTA Image header */ void *mqtt_client; /* mqtt client */ /* OTA Upgrade parameters */ } ota_service_t; /* OTA service APIs */ /** * ota_service_init ota service init . * * @param[in] ota_service_t *ctx ota service context * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_service_init(ota_service_t *ctx); /** * ota_service_start ota service start and file store in flash * * @param[in] ota_service_t *ctx ota service context * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_service_start(ota_service_t *ctx); /** * ota_download_to_fs_service ota service submodule start. * * @param[in] void *ctx ota service context * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_download_to_fs_service(void *ota_ctx , char *file_path); /** * ota_install_jsapp ota service submodule start. * * @param[in] void *ota_ctx ota service context * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_install_jsapp(void *ota_ctx, char *store_file, int store_file_len, char *install_path); /** * ota_report_module_version ota report module version. * * @param[in] void *ctx ota service context * @param[in] char *module_name want tp report module name * @param[in] char *version module file version * * @return OTA_SUCCESS OTA success. * @return -1 OTA transport init fail. */ int ota_report_module_version(void *ota_ctx, char *module_name, char *version); /** * ota_service_param_reset; * * @param[in] ota_service_t *ctx ota service context * * @return NULL */ void ota_service_param_reset(ota_service_t *ctx); /** * ota_sevice_parse_msg ota service parse message. * * @param[in] ota_service_t *ctx ota service context * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_sevice_parse_msg(ota_service_t *ctx, const char *json); /** * ota_register_module_store ota register store moudle information buf to ctx; * * * @param[in] ota_service_t *ctx ota service context * @param[in] ota_store_module_info_t *queue store moudle information buf ptr * @param[in] int queue_len module buf size * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL Get information failed. */ int ota_register_module_store(ota_service_t *ctx, ota_store_module_info_t *queue, int queue_len); /** * ota_set_module_information ota set module information to DB, include: * module name, store path, module type. * * @param[in] ota_service_t *ctx ota service context * @param[in] char *module_name ota module name * @param[in] char *store_path want to store module file path * @param[in] int module_type upgrade type: OTA_UPGRADE_ALL.etc. * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL Get information failed. */ int ota_set_module_information(ota_service_t *ctx, char *module_name, char *store_path, int module_type); /** * ota_get_module_information ota get module information,include: * module name, store path, module type. * * @param[in] ota_service_t *ctx ota service context * @param[in] char *module_name ota module name * @param[in] ota_store_module_info_t *module_info want to store module information var * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL Get information failed. */ int ota_get_module_information(ota_service_t *ctx, char *module_name, ota_store_module_info_t *module_info); /** * ota_register_boot_cb ota register boot callback. * * @param[in] ota_service_t *ctx ota service context * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_register_boot_cb(ota_service_t *ctx, void *cb, void *param); /** * ota_register_trigger_msg_cb ota register trigger ota callback. * * @param[in] ota_service_t *ctx ota service context * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_register_trigger_msg_cb(ota_service_t *ctx, void *cb, void *param); /** * ota_register_report_percent_cb ota register file download process callback. * * @param[in] ota_service_t *ctx ota service context * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_register_report_percent_cb(ota_service_t *ctx, void *cb, void *param); /** * ota_register_feedback_msg_cb ota service register callback. * * @param[in] ota_service_t *ctx ota service context * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_register_feedback_msg_cb(ota_service_t *ctx, void *cb, void *param); /*************************************************************** *** OTA transport module:transport message with MQTT or CoAP *** ****************************************************************/ /** * ota_transport_inform OTA inform version to cloud. * * @param[in] void *mqttclient mqtt client ptr * @param[in] char *pk product key value * @param[in] char *dn device name * @param[in] char *module_name want to report module name, when module_name == NULL, report default module ver * @param[in] char *ver version string * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_transport_inform(void *mqttclient, char *pk, char *dn, char *module_name, char *ver); /** * ota_transport_upgrade subscribe OTA upgrade to clould. * * @param[in] ota_service_t *ctx ota service context * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_transport_upgrade(ota_service_t *ctx); /** * ota_transport_upgrade report status to cloud. * * @param[in] void *param ota service context * @param[in] int status ota upgrade status * * @return OTA_SUCCESS OTA success. * @return OTA_TRANSPORT_INT_FAIL OTA transport init fail. * @return OTA_TRANSPORT_PAR_FAIL OTA transport parse fail. * @return OTA_TRANSPORT_VER_FAIL OTA transport verion is too old. */ int ota_transport_status(void *param, int status); /*************************************************************** *** OTA download module: download image with HTTP or CoaP *** ****************************************************************/ /** * ota_download_start OTA download start * * @param[in] char *url download url * @param[in] unsigned int url_len download url length * @param[in] report_func repot_func report http downloading status function * @param[in] void *user_param user's param for repot_func * * @return OTA_SUCCESS OTA success. * @return OTA_DOWNLOAD_INIT_FAIL OTA download init failed. * @return OTA_DOWNLOAD_CON_FAIL OTA download connect failed. * @return OTA_DOWNLOAD_REQ_FAIL OTA download request failed. * @return OTA_DOWNLOAD_RECV_FAIL OTA download receive failed. */ int ota_download_start(char *url, unsigned int url_len, report_func repot_func, void *user_param); /** * ota_download_store_fs_start OTA download file start and store in fs * * @param[in] char *url download url * @param[in] unsigned int url_len download url length * @param[in] char *store_path store file path and name eg:/root/test.bin * @param[in] report_func report_func report http downloading status function * @param[in] void *user_param user's param for repot_func * * @return OTA_SUCCESS OTA success. * @return OTA_DOWNLOAD_INIT_FAIL OTA download init failed. * @return OTA_DOWNLOAD_CON_FAIL OTA download connect failed. * @return OTA_DOWNLOAD_REQ_FAIL OTA download request failed. * @return OTA_DOWNLOAD_RECV_FAIL OTA download receive failed. */ int ota_download_store_fs_start(char *url, unsigned int url_len, char *store_path, report_func report_func, void *user_param); /** * ota_download_image_header ota download image header. * * @param[in] ota_service_t *ctx ota service context * @param[in] char *url download url * @param[in] unsigned int url_len download url length * @param[in] unsigned int size ota image size * * @return OTA_SUCCESS OTA success. * @return OTA_DOWNLOAD_INIT_FAIL OTA download init fail. * @return OTA_DOWNLOAD_HEAD_FAIL OTA download header fail. * @return OTA_DOWNLOAD_CON_FAIL OTA download connect fail. * @return OTA_DOWNLOAD_REQ_FAIL OTA download request fail. * @return OTA_DOWNLOAD_RECV_FAIL OTA download receive fail. */ int ota_download_image_header(ota_service_t *ctx, char *url, unsigned int url_len, unsigned int size); /*************************************************************** *** OTA hal module: update image to OTA partition:ota_hal.h *** ****************************************************************/ /** * ota_read_parameter ota read parameter from flash. * * @param[in] ota_boot_param_t *param ota parameter * * @return OTA_SUCCESS OTA success. * @return OTA_UPGRADE_WRITE_FAIL OTA upgrade write fail. * @return OTA_UPGRADE_PARAM_FAIL OTA upgrade parameter fail. * @return OTA_UPGRADE_FW_SIZE_FAIL OTA upgrade FW too big. * @return OTA_UPGRADE_SET_BOOT_FAIL OTA upgrade set boot fail. */ int ota_read_parameter(ota_boot_param_t *param); /** * ota_update_parameter ota update parameter to flash. * * @param[in] ota_boot_param_t *param ota parameter * * @return OTA_SUCCESS OTA success. * @return OTA_UPGRADE_WRITE_FAIL OTA upgrade write fail. * @return OTA_UPGRADE_PARAM_FAIL OTA upgrade parameter fail. * @return OTA_UPGRADE_FW_SIZE_FAIL OTA upgrade FW too big. * @return OTA_UPGRADE_SET_BOOT_FAIL OTA upgrade set boot fail. */ int ota_update_parameter(ota_boot_param_t *param); /** * ota_get_fs_version ota get fs image version. * * @param[in] char *ver_buf store version buffer * @param[in] cint ver_buf_len store version buffer len * * @return 0 get version success. * @return -1 get version fail. */ int ota_get_fs_version(char *ver_buf, int ver_buf_len); /** * ota_check_image OTA check image. * * @param[in] unsigned int size OTA image size. * * @return OTA_SUCCESS OTA success. * @return OTA_VERIFY_MD5_FAIL OTA verfiy MD5 fail. * @return OTA_VERIFY_SHA2_FAIL OTA verfiy SH256 fail. * @return OTA_VERIFY_RSA_FAIL OTA verfiy RSA fail. * @return OTA_VERIFY_IMAGE_FAIL OTA verfiy image fail. */ int ota_check_image(unsigned int size); /** * ota_jsapp_version_get OTA parase js script version * * @param[in] char *version store version buf. * @param[in] char *file_path js.app json file store path. * * @return 0 get version success. * @return -1 get version failed. */ int ota_jsapp_version_get(char *version, char *file_path); /** * @} */ #ifdef __cplusplus } #endif #endif /* OTA_AGNET_H */
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/haas700/ota_agent.h
C
apache-2.0
23,309
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef __AMP_BOARD_CONFIG_H__ #define __AMP_BOARD_CONFIG_H__ #define AMP_RECOVERY_PORT 0 #define AMP_RECOVERY_PORT_BAUDRATE 1500000UL #define AMP_REPL_UART_PORT 0 #define AMP_REPL_UART_BAUDRATE 1500000UL #define AMP_STATUS_IO 40 #define AMP_STATUS_IO_ON 1 /* amp product */ #define PRODUCT_ID KIT #define MODULE_ID HAASEDUK1_HAAS1000 #endif
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/haaseduk1/amp_board_config.h
C
apache-2.0
440
#include "amp_platform.h" #include "aos_system.h" #include "ota_agent.h" void internal_sys_upgrade_start(void *ctx) { ota_service_start((ota_service_t *)ctx); aos_task_exit(0); return; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/haaseduk1/amp_ota_port.c
C
apache-2.0
199
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "aos_network.h" #include "amp_platform.h" int aos_get_sim_info(aos_sim_info_t *sim_info) { int ret = -1; return ret; } int aos_get_locator_info(aos_locator_info_t *locator_info) { int ret = -1; return ret; } int aos_get_neighbor_locator_info(void (*cb)(aos_locator_info_t*, int)) { cb(NULL, 0); return 0; } AOS_NETWORK_SHAREMODE_E aos_get_netsharemode(void) { return AOS_NETWORK_SHAREMODE_INVALID; } int aos_set_netsharemode(AOS_NETWORK_SHAREMODE_E share_mode) { return -1; } int aos_get_netshareconfig(aos_sharemode_info_t *share_mode_info) { return -1; } int aos_set_netshareconfig(int ucid, int auth_type, aos_sharemode_info_t *share_mode_info) { return -1; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/network/aos_cellular.c
C
apache-2.0
787
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "aos_network.h" #include "amp_platform.h" #include "aos_socket.h" struct hostent *aos_httpc_get_host_by_name(const char *name) { return gethostbyname(name); } int32_t aos_httpc_socket_connect(uintptr_t fd, const struct sockaddr *name, socklen_t namelen) { return connect(fd, name, namelen); }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/network/aos_httpc.c
C
apache-2.0
377
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "amp_platform.h" #include "aos_network.h" #include "netdev.h" #define WIFI_DEV "wifi0" void amp_netdev_set_default(char* netdev_name) { struct netdev* netdev; if(netdev_name == NULL) { return ; } netdev = netdev_get_by_name(netdev_name); if(netdev == NULL) { return ; } netdev_set_default(netdev); } int amp_netdev_set_up(char* netdev_name) { struct netdev* netdev; if(netdev_name == NULL) { return -1; } netdev = netdev_get_by_name(netdev_name); if(netdev == NULL) { return -1; } return netdev_set_up(netdev); } int amp_netdev_set_down(char* netdev_name) { struct netdev* netdev; if(netdev_name == NULL) { return -1; } netdev = netdev_get_by_name(netdev_name); if(netdev == NULL) { return -1; } return netdev_set_down(netdev); } int amp_netdev_dhcp_enabled(char* netdev_name, bool is_enabled) { struct netdev* netdev; if(netdev_name == NULL) { return -1; } netdev = netdev_get_by_name(netdev_name); if(netdev == NULL) { return -1; } return netdev_dhcp_enabled(netdev, is_enabled); } int amp_netdev_set_ipaddr(char* netdev_name, const ip_addr_t* ip_addr) { struct netdev* netdev; if(netdev_name == NULL) { return -1; } netdev = netdev_get_by_name(netdev_name); if(netdev == NULL) { return -1; } return netdev_set_ipaddr(netdev, ip_addr); } int amp_netdev_set_netmask(char* netdev_name, const ip_addr_t* netmask) { struct netdev* netdev; if(netdev_name == NULL) { return -1; } netdev = netdev_get_by_name(netdev_name); if(netdev == NULL) { return -1; } return netdev_set_netmask(netdev, netmask); } int amp_netdev_set_gw(char* netdev_name, const ip_addr_t* gw) { struct netdev* netdev; if(netdev_name == NULL) { return -1; } netdev = netdev_get_by_name(netdev_name); if(netdev == NULL) { return -1; } return netdev_set_gw(netdev, gw); } int amp_netdev_set_dns_server(char* netdev_name, uint8_t dns_num, const ip_addr_t* dns_server) { struct netdev* netdev; if(netdev_name == NULL) { return -1; } netdev = netdev_get_by_name(netdev_name); if(netdev == NULL) { return -1; } return netdev_set_dns_server(netdev, dns_num, dns_server); } void amp_netdev_set_status_callback(char* netdev_name, netdev_callback_fn status_callback) { struct netdev* netdev; if(netdev_name == NULL) { return; } netdev = netdev_get_by_name(netdev_name); if(netdev == NULL) { return; } netdev_set_status_callback(netdev, status_callback); }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/network/aos_netdev.c
C
apache-2.0
2,819
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef AOS_BOARD_HAAS700 #include "amp_platform.h" #include "aos_network.h" #include "netmgr.h" #include "netmgr_wifi.h" #include <uservice/eventid.h> #include <uservice/uservice.h> #ifndef WIFI_DEV_PATH #define WIFI_DEV_PATH "/dev/wifi0" #endif #define LOG_TAG "aos_wifi" static int _remap_exceptions(int e) { int32_t err = 0; // switch (e) { // case ESP_ERR_WIFI_NOT_INIT: // err = AOS_ERR_WIFI_NOT_INIT; // break; // case ESP_ERR_WIFI_NOT_STARTED: // err = AOS_ERR_WIFI_NOT_STARTED; // break; // case ESP_ERR_WIFI_NOT_STOPPED: // err = AOS_ERR_WIFI_NOT_STOPPED; // break; // case ESP_ERR_WIFI_IF: // err = AOS_ERR_WIFI_IF; // break; // case ESP_ERR_WIFI_MODE: // err = AOS_ERR_WIFI_MODE; // break; // case ESP_ERR_WIFI_STATE: // err = AOS_ERR_WIFI_STATE; // break; // case ESP_ERR_WIFI_CONN: // err = AOS_ERR_WIFI_CONN; // break; // case ESP_ERR_WIFI_NVS: // err = AOS_ERR_WIFI_NVS; // break; // case ESP_ERR_WIFI_MAC: // err = AOS_ERR_WIFI_MAC; // break; // case ESP_ERR_WIFI_SSID: // err = AOS_ERR_WIFI_SSID; // break; // case ESP_ERR_WIFI_PASSWORD: // err = AOS_ERR_WIFI_PASSWORD; // break; // case ESP_ERR_WIFI_TIMEOUT: // err = ETIMEDOUT; // break; // case ESP_ERR_WIFI_WAKE_FAIL: // err = AOS_ERR_WIFI_WAKE_FAIL; // break; // case ESP_ERR_WIFI_WOULD_BLOCK: // err = AOS_ERR_WIFI_WOULD_BLOCK; // break; // case ESP_ERR_WIFI_NOT_CONNECT: // err = AOS_ERR_WIFI_NOT_CONNECT; // break; // case ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS: // err = AOS_ERR_TCPIP_ADAPTER_INVALID_PARAMS; // break; // case ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY: // err = AOS_ERR_TCPIP_ADAPTER_IF_NOT_READY; // break; // case ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED: // err = AOS_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED; // break; // case ESP_ERR_TCPIP_ADAPTER_NO_MEM: // err = ENOMEM; // break; // } return err; } static void wifi_event_cb(uint32_t event_id, const void *param, void *ctx) { int32_t event; int wifi_state = 0; aos_wifi_manager_t *wifi_manager = NULL; if (ctx != NULL) { wifi_manager = (aos_wifi_manager_t *)ctx; } switch (event_id) { case EVENT_NETMGR_WIFI_DISCONNECTED: wifi_state = AOS_NET_STA_DISCONNECTED; break; case EVENT_NETMGR_WIFI_CONNECTED: wifi_state = AOS_NET_STA_CONNECTED; break; case EVENT_NETMGR_GOT_IP: wifi_state = AOS_NET_STA_CONNECTED; break; case EVENT_NETMGR_WIFI_CONN_TIMEOUT: wifi_state = AOS_NET_STA_STARTED; break; default: event = AOS_NET_STATE_UNKNOWN; break; } if (wifi_manager != NULL) { wifi_manager->wifi_state = wifi_state; } if (wifi_manager->cb != NULL) { wifi_manager->cb(wifi_state, ctx); } return; } int aos_wifi_init(aos_wifi_manager_t *wifi_manager) { int ret = 0; netmgr_hdl_t hdl = netmgr_get_dev(WIFI_DEV_PATH); if (hdl >= 0) { LOGI(LOG_TAG, "wifi already init by other task\r\n"); } else { LOGD(LOG_TAG, "aos_wifi_init start\r\n"); ret = event_service_init(NULL); if (ret != 0) { LOGE(LOG_TAG, "event_service_init failed\r\n"); return ret; } ret = netmgr_service_init(NULL); if (ret != 0) { LOGE(LOG_TAG, "netmgr_service_init failed\r\n"); return ret; } netmgr_set_auto_reconnect(NULL, false); ret = netmgr_wifi_set_auto_save_ap(true); if (ret != 0) { LOGE(LOG_TAG, "netmgr_wifi_set_auto_save_ap failed\r\n"); return ret; } } event_subscribe(EVENT_NETMGR_WIFI_DISCONNECTED, wifi_event_cb, wifi_manager); event_subscribe(EVENT_NETMGR_WIFI_CONNECTED, wifi_event_cb, wifi_manager); event_subscribe(EVENT_NETMGR_WIFI_CONN_TIMEOUT, wifi_event_cb, wifi_manager); event_subscribe(EVENT_NETMGR_GOT_IP, wifi_event_cb, wifi_manager); return ret; } int aos_wifi_deinit(aos_wifi_manager_t *wifi_manager) { // return netmgr_service_deinit(); return 0; } int aos_wifi_start(aos_wifi_manager_t *wifi_manager) { wifi_manager->is_started = true; return 0; } int aos_wifi_stop(aos_wifi_manager_t *wifi_manager) { return 0; } int aos_net_set_ifconfig(aos_ifconfig_info_t *info) { netmgr_hdl_t hdl; printf("dev %s open failed\r\n", __func__); hdl = netmgr_get_dev(WIFI_DEV_PATH); if (hdl == -1) { return -1; } return netmgr_set_ifconfig(hdl, info); } int aos_net_get_ifconfig(aos_ifconfig_info_t *info) { netmgr_hdl_t hdl; hdl = netmgr_get_dev(WIFI_DEV_PATH); if (hdl == -1) { return -1; } return netmgr_get_ifconfig(hdl, info); } int aos_wifi_set_msg_cb(netmgr_msg_cb_t cb) { netmgr_hdl_t hdl; hdl = netmgr_get_dev(WIFI_DEV_PATH); if (hdl == -1) { return -1; } return netmgr_set_msg_cb(hdl, cb); } int aos_wifi_del_msg_cb(netmgr_msg_cb_t cb) { netmgr_hdl_t hdl; hdl = netmgr_get_dev(WIFI_DEV_PATH); if (hdl == -1) { return -1; } return netmgr_del_msg_cb(hdl, cb); } AOS_NETWORK_TYPE_E aos_get_network_type() { return AOS_NETWORK_WIFI; } int aos_wifi_connect(const char *ssid, const char *passwd) { int ret = -1; netmgr_hdl_t hdl; netmgr_connect_params_t params; hdl = netmgr_get_dev(WIFI_DEV_PATH); if (hdl < 0) { LOGE(LOG_TAG, "netmgr_get_dev failed\r\n"); return -1; } memset(&params, 0, sizeof(netmgr_connect_params_t)); params.type = NETMGR_TYPE_WIFI; strncpy(params.params.wifi_params.ssid, ssid, sizeof(params.params.wifi_params.ssid) - 1); strncpy(params.params.wifi_params.pwd, passwd, sizeof(params.params.wifi_params.pwd) - 1); params.params.wifi_params.timeout = 60000; ret = netmgr_connect(hdl, &params); if (ret != 0) { LOGE(LOG_TAG, "netmgr_connect failed. %d\r\n", ret); return ret; } return ret; } int aos_wifi_get_info(aos_wifi_info_t *wifi_info) { netmgr_hdl_t hdl; netmgr_config_t config; netmgr_ifconfig_info_t info; int ap_num; int used_ap; /**< ap that is used in the array */ hdl = netmgr_get_dev(WIFI_DEV_PATH); if (hdl == -1) { return -1; } memset(&info, 0, sizeof(info)); if (netmgr_get_ifconfig(hdl, &info) == -1) { return -1; } memset(&config, 0, sizeof(config)); if (netmgr_get_config(hdl, &config) == -1) { return -1; } ap_num = config.config.wifi_config.ap_num; used_ap = config.config.wifi_config.used_ap; if ((ap_num < MAX_AP_CONFIG_NUM) && (used_ap < ap_num)) { memset(wifi_info->ssid, 0, sizeof(wifi_info->ssid)); strncpy(wifi_info->ssid, config.config.wifi_config.config[used_ap].ssid, sizeof(wifi_info->ssid) - 1); } else { return -1; } snprintf(wifi_info->ip, sizeof(wifi_info->ip), "%s", info.ip_addr); memcpy(wifi_info->mac, info.mac, sizeof(wifi_info->mac)); wifi_info->rssi = info.rssi; return 0; } int aos_wifi_scan(aos_wifi_ap_list_t *ap_list, int ap_list_len) { netmgr_wifi_ap_list_t* wifi_ap_records = (netmgr_wifi_ap_list_t *) ap_list; int ap_num = netmgr_wifi_scan_result(wifi_ap_records, 16, NETMGR_WIFI_SCAN_TYPE_FULL); return ap_num; } int aos_wifi_disconnect() { netmgr_hdl_t hdl; hdl = netmgr_get_dev(WIFI_DEV_PATH); if (hdl == -1) { return -1; } return netmgr_disconnect(hdl); } int aos_wifi_get_state() { netmgr_hdl_t hdl; hdl = netmgr_get_dev(WIFI_DEV_PATH); if (hdl == -1) { return -1; } return netmgr_get_state(hdl); } int aos_get_network_status() { int net_status = aos_wifi_get_state(); return net_status == AOS_NET_STA_GOT_IP ? 1 : 0; } #endif
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/network/aos_network.c
C
apache-2.0
8,418
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <string.h> #include <errno.h> #include "aos/kernel.h" #include "aos_tcp.h" #include "aos_socket.h" #include "aos_system.h" #define PLATFORM_LOG_D(format, ...) \ do { \ aos_printf("D: %d %s() | " format "\n", __LINE__, __FUNCTION__, \ ##__VA_ARGS__); \ } while (0); #define PLATFORM_LOG_E(format, ...) \ do { \ aos_printf("E: %d %s() | " format "\n", __LINE__, __FUNCTION__, \ ##__VA_ARGS__); \ } while (0); #ifndef CONFIG_NO_TCPIP static uint64_t aliot_platform_time_left(uint64_t t_end, uint64_t t_now) { uint64_t t_left; if (t_end > t_now) { t_left = t_end - t_now; } else { t_left = 0; } return t_left; } int aos_tcp_establish(const char *host, unsigned int port) { struct addrinfo hints; struct addrinfo *addrInfoList = NULL; struct addrinfo *cur = NULL; int fd = 0; int rc = -1; char service[6]; memset(&hints, 0, sizeof(hints)); PLATFORM_LOG_D( "establish tcp connection with server(host=%s port=%u)", host, port); hints.ai_family = AF_INET; // only IPv4 hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; sprintf(service, "%u", port); if ((rc = getaddrinfo(host, service, &hints, &addrInfoList)) != 0) { PLATFORM_LOG_E("getaddrinfo error: %d", rc); return (uintptr_t)-1; } for (cur = addrInfoList; cur != NULL; cur = cur->ai_next) { if (cur->ai_family != AF_INET) { PLATFORM_LOG_E("socket type error"); rc = -1; continue; } fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol); if (fd < 0) { PLATFORM_LOG_E("create socket error"); rc = -1; continue; } if (connect(fd, cur->ai_addr, cur->ai_addrlen) == 0) { rc = fd; break; } close(fd); PLATFORM_LOG_E("connect error"); rc = -1; } if (-1 == rc) { PLATFORM_LOG_D("fail to establish tcp"); } else { PLATFORM_LOG_D("success to establish tcp, fd=%d", rc); } freeaddrinfo(addrInfoList); return rc; } int aos_tcp_destroy(unsigned int fd) { int rc; // Shutdown both send and receive operations. rc = shutdown((int)fd, 2); if (0 != rc) { PLATFORM_LOG_E("shutdown error"); return -1; } rc = close((int)fd); if (0 != rc) { PLATFORM_LOG_E("closesocket error"); return -1; } return 0; } int aos_tcp_write(unsigned int fd, const char *buf, unsigned int len, unsigned int timeout_ms) { int ret, err_code; uint32_t len_sent; uint64_t t_end, t_left; fd_set sets; if (fd >= FD_SETSIZE) { return -1; } t_end = aos_now_ms() + timeout_ms; len_sent = 0; err_code = 0; ret = 1; // send one time if timeout_ms is value 0 do { t_left = aliot_platform_time_left(t_end, aos_now_ms()); if (0 != t_left) { struct timeval timeout; FD_ZERO(&sets); FD_SET(fd, &sets); timeout.tv_sec = t_left / 1000; timeout.tv_usec = (t_left % 1000) * 1000; ret = select(fd + 1, NULL, &sets, NULL, &timeout); if (ret > 0) { if (0 == FD_ISSET(fd, &sets)) { PLATFORM_LOG_D("Should NOT arrive"); // If timeout in next loop, it will not sent any data ret = 0; continue; } } else if (0 == ret) { // PLATFORM_LOG_D("select-write timeout %lu", fd); break; } else { if (EINTR == errno) { PLATFORM_LOG_D("EINTR be caught"); continue; } err_code = -1; PLATFORM_LOG_E("select-write fail"); break; } } if (ret > 0) { ret = send(fd, buf + len_sent, len - len_sent, 0); if (ret > 0) { len_sent += ret; } else if (0 == ret) { PLATFORM_LOG_D("No data be sent"); } else { if (EINTR == errno) { PLATFORM_LOG_D("EINTR be caught"); continue; } err_code = -1; PLATFORM_LOG_E("send fail"); break; } } } while ((len_sent < len) && (aliot_platform_time_left(t_end, aos_now_ms()) > 0)); return err_code == 0 ? len_sent : err_code; } int aos_tcp_read(unsigned int fd, char *buf, unsigned int len, unsigned int timeout_ms) { int res = 0; int32_t recv_bytes = 0; ssize_t recv_res = 0; uint64_t timestart_ms = 0, timenow_ms = 0, timeselect_ms = 0; fd_set recv_sets; struct timeval timestart, timenow, timeselect; FD_ZERO(&recv_sets); FD_SET(fd, &recv_sets); /* Start Time */ gettimeofday(&timestart, NULL); timestart_ms = timestart.tv_sec * 1000 + timestart.tv_usec / 1000; timenow_ms = timestart_ms; do { gettimeofday(&timenow, NULL); timenow_ms = timenow.tv_sec * 1000 + timenow.tv_usec / 1000; if (timenow_ms - timestart_ms >= timenow_ms || timeout_ms - (timenow_ms - timestart_ms) > timeout_ms) { break; } timeselect_ms = timeout_ms - (timenow_ms - timestart_ms); timeselect.tv_sec = timeselect_ms / 1000; timeselect.tv_usec = timeselect_ms % 1000 * 1000; res = select(fd + 1, &recv_sets, NULL, NULL, &timeselect); if (res == 0) { continue; } else if (res < 0) { aos_printf("aos_tcp_read, errno: %d\n", errno); return -1; } else { if (FD_ISSET(fd, &recv_sets)) { recv_res = recv(fd, buf + recv_bytes, len - recv_bytes, 0); if (recv_res == 0) { aos_printf("aos_tcp_read, nwk connection closed\n"); break; } else if (recv_res < 0) { aos_printf("aos_tcp_read, errno: %d\n", errno); if (errno == EINTR) { continue; } return -1; } else { recv_bytes += recv_res; if (recv_bytes == len) { break; } } } } } while (((timenow_ms - timestart_ms) < timeout_ms) && (recv_bytes < len)); return recv_bytes; } #else uintptr_t aos_tcp_establish(_IN_ const char *host, _IN_ uint16_t port) { return 0; } int32_t aos_tcp_destroy(uintptr_t fd) { return 0; } int32_t aos_tcp_write(uintptr_t fd, const char *buf, uint32_t len, uint32_t timeout_ms) { return 0; } int32_t aos_tcp_read(uintptr_t fd, char *buf, uint32_t len, uint32_t timeout_ms) { return 0; } #endif
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/network/aos_tcp.c
C
apache-2.0
7,520
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include "ulog/ulog.h" #include "aos/kernel.h" #include "aos_socket.h" #include <netdb.h> #include "aos_udp.h" #include "aos_system.h" #define TRANSPORT_ADDR_LEN 16 #ifndef IP_PKTINFO #define IP_PKTINFO IP_MULTICAST_IF #endif #ifndef IPV6_PKTINFO #define IPV6_PKTINFO IPV6_V6ONL #endif #define NETWORK_ADDR_LEN (16) #define LOG_TAG "HAL_TL" #define platform_info(format, ...) LOGI(LOG_TAG, format, ##__VA_ARGS__) #define platform_err(format, ...) LOGE(LOG_TAG, format, ##__VA_ARGS__) int aos_udp_socket_create() { int rc = -1; long socket_id = -1; socket_id = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (socket_id < 0) { aos_printf("create socket error"); return rc; } return socket_id; } int aos_udp_socket_bind(int p_socket, unsigned short port) { struct sockaddr_in addr; int opt_val = 1; memset(&addr, 0, sizeof(struct sockaddr_in)); if (0 != setsockopt(p_socket, SOL_SOCKET, SO_REUSEADDR, &opt_val, sizeof(opt_val))) { aos_printf("setsockopt(SO_REUSEADDR) falied\n"); close(p_socket); return -1; } addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_family = AF_INET; addr.sin_port = htons(port); if (-1 == bind(p_socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in))) { aos_printf("bind(%d) falied\n", (int)p_socket); close(p_socket); return -1; } aos_printf("success to establish udp, fd = %d", (int)p_socket); return p_socket; } /** * @brief Create a UDP socket. * * @param [in] port: @n Specify the UDP port of UDP socket * * @retval < 0 : Fail. * @retval >= 0 : Success, the value is handle of this UDP socket. * @see None. */ int aos_udp_create(char *host, unsigned short port) { int rc = -1; long socket_id = -1; char port_ptr[6] = {0}; struct addrinfo hints; char addr[NETWORK_ADDR_LEN] = {0}; struct addrinfo *res, *ainfo; struct sockaddr_in *sa = NULL; if (NULL == host) { return (-1); } sprintf(port_ptr, "%u", port); memset((char *)&hints, 0x00, sizeof(hints)); hints.ai_socktype = SOCK_DGRAM; hints.ai_family = AF_INET; hints.ai_protocol = IPPROTO_UDP; rc = getaddrinfo(host, port_ptr, &hints, &res); if (0 != rc) { platform_err("getaddrinfo error: %d", rc); return (-1); } for (ainfo = res; ainfo != NULL; ainfo = ainfo->ai_next) { if (AF_INET == ainfo->ai_family) { sa = (struct sockaddr_in *)ainfo->ai_addr; inet_ntop(AF_INET, &sa->sin_addr, addr, NETWORK_ADDR_LEN); socket_id = socket(ainfo->ai_family, ainfo->ai_socktype, ainfo->ai_protocol); if (socket_id < 0) { platform_err("create socket error"); continue; } if (0 == connect(socket_id, ainfo->ai_addr, ainfo->ai_addrlen)) { break; } close(socket_id); } } freeaddrinfo(res); return socket_id; } int aos_udp_create_without_connect(const char *host, unsigned short port) { int flag = 1; int ret = -1; int socket_id = -1; struct sockaddr_in local_addr; /*local addr*/ if ((socket_id = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { platform_err("socket create failed\r\n"); return (intptr_t)-1; } ret = setsockopt(socket_id, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)); if (ret < 0) { close(socket_id); platform_err("setsockopt SO_REUSEADDR failed"); return (intptr_t)-1; } flag = 1; #ifdef IP_RECVPKTINFO if ((ret = setsockopt(socket_id, IPPROTO_IP, IP_RECVPKTINFO, &flag, sizeof(flag))) < 0) #else /* IP_RECVPKTINFO */ if ((ret = setsockopt(socket_id, IPPROTO_IP, IP_PKTINFO, &flag, sizeof(flag))) < 0) #endif /* IP_RECVPKTINFO */ if (ret < 0) { close(socket_id); platform_err("setsockopt IP_PKTINFO failed\r\n"); return (intptr_t)-1; } memset(&local_addr, 0x00, sizeof(local_addr)); local_addr.sin_family = AF_INET; if (NULL != host) { inet_aton(host, &local_addr.sin_addr); } else { local_addr.sin_addr.s_addr = htonl(INADDR_ANY); } local_addr.sin_port = htons(port); ret = bind(socket_id, (struct sockaddr *)&local_addr, sizeof(local_addr)); // faos_printf(stderr,"\r\n[%s LINE #%d] Create socket port %d fd %d ret // %d\r\n", // __FILE__, __LINE__, port, socket_id, ret); return socket_id; } int aos_udp_close_without_connect(int sockfd) { return close((int)sockfd); } int aos_udp_recvfrom(int sockfd, aos_networkAddr *p_remote, unsigned char *p_data, unsigned int datalen, unsigned int timeout_ms) { int socket_id = -1; struct sockaddr from; int count = -1, ret = -1; socklen_t addrlen = 0; struct timeval tv; fd_set read_fds; if (NULL == p_remote || NULL == p_data) { return -1; } socket_id = (int)sockfd; FD_ZERO(&read_fds); FD_SET(socket_id, &read_fds); tv.tv_sec = timeout_ms / 1000; tv.tv_usec = (timeout_ms % 1000) * 1000; ret = select(socket_id + 1, &read_fds, NULL, NULL, timeout_ms == 0 ? NULL : &tv); /* Zero fds ready means we timed out */ if (ret == 0) { return 0; /* receive timeout */ } if (ret < 0) { if (errno == EINTR) { return -3; /* want read */ } return -4; /* receive failed */ } addrlen = sizeof(struct sockaddr); count = recvfrom(socket_id, p_data, (size_t)datalen, 0, &from, &addrlen); if (-1 == count) { return -1; } if (from.sa_family == AF_INET) { struct sockaddr_in *sin = (struct sockaddr_in *)&from; inet_ntop(AF_INET, &sin->sin_addr, (char *)p_remote->addr, NETWORK_ADDR_LEN); p_remote->port = ntohs(sin->sin_port); } return count; } int aos_udp_sendto(int sockfd, const aos_networkAddr *p_remote, const unsigned char *p_data, unsigned int datalen, unsigned int timeout_ms) { int rc = -1; int socket_id = -1; struct sockaddr_in remote_addr; if (NULL == p_remote || NULL == p_data) { return -1; } socket_id = (int)sockfd; remote_addr.sin_family = AF_INET; if (1 != (rc = inet_pton(remote_addr.sin_family, (const char *)p_remote->addr, &remote_addr.sin_addr.s_addr))) { return -1; } remote_addr.sin_port = htons(p_remote->port); rc = sendto(socket_id, p_data, (size_t)datalen, 0, (const struct sockaddr *)&remote_addr, sizeof(remote_addr)); if (-1 == rc) { return -1; } return (rc) > 0 ? rc : -1; } int aos_udp_joinmulticast(int sockfd, char *p_group) { int err = -1; int socket_id = -1; if (NULL == p_group) { return -1; } /*set loopback*/ int loop = 1; socket_id = (int)sockfd; err = setsockopt(socket_id, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)); if (err < 0) { aos_printf("setsockopt():IP_MULTICAST_LOOP failed\r\n"); return err; } struct ip_mreq mreq; mreq.imr_multiaddr.s_addr = inet_addr(p_group); mreq.imr_interface.s_addr = htonl(INADDR_ANY); /*default networt interface*/ /*join to the mutilcast group*/ err = setsockopt(socket_id, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); if (err < 0) { aos_printf("setsockopt():IP_ADD_MEMBERSHIP failed\r\n"); return err; } return 0; } int aos_udp_write(int p_socket, const unsigned char *p_data, unsigned int datalen) { int rc = -1; long socket_id = -1; socket_id = (long)p_socket; rc = send(socket_id, (char *)p_data, (int)datalen, 0); if (-1 == rc) { return -1; } return rc; } int aos_udp_read_timeout(int p_socket, unsigned char *p_data, unsigned int datalen, unsigned int timeout) { int ret; struct timeval tv; fd_set read_fds; long socket_id = -1; if (0 == p_socket || NULL == p_data) { return -1; } socket_id = (long)p_socket; if (socket_id < 0) { return -1; } FD_ZERO(&read_fds); FD_SET(socket_id, &read_fds); tv.tv_sec = timeout / 1000; tv.tv_usec = (timeout % 1000) * 1000; ret = select(socket_id + 1, &read_fds, NULL, NULL, timeout == 0 ? NULL : &tv); /* Zero fds ready means we timed out */ if (ret == 0) { return -2; /* receive timeout */ } if (ret < 0) { if (errno == EINTR) { return -3; /* want read */ } return -4; /* receive failed */ } /* This call will not block */ return read((long)p_socket, p_data, datalen); }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/network/aos_udp.c
C
apache-2.0
9,452
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include <aos/errno.h> #include "aos_hal_adc.h" #ifndef AOS_BOARD_HAAS700 #include <vfsdev/adc_dev.h> #endif int32_t aos_hal_adc_init(adc_dev_t *adc) { #ifndef AOS_BOARD_HAAS700 uint32_t flags = 0; int32_t ret = 0; int32_t *p_fd = NULL; char name[16] = {0}; if (!adc || adc->priv) return -EINVAL; p_fd = (int32_t *)malloc(sizeof(int32_t)); if (!p_fd) return -ENOMEM; *p_fd = -1; snprintf(name, sizeof(name), "/dev/adc%d", adc->port); *p_fd = open(name, 0); if (*p_fd < 0) { printf ("open %s failed, fd:%d\r\n", name, *p_fd); ret = -EIO; goto out; } ret = ioctl(*p_fd, IOC_ADC_START, adc->config.sampling_cycle); if (ret) { printf ("start %s failed, ret:%d\r\n", name, ret); goto out; } out: if (!ret) { adc->priv = p_fd; } else { if (*p_fd >= 0) close(*p_fd); free(p_fd); p_fd = NULL; } return ret; #else return -1; #endif } int32_t aos_hal_adc_raw_value_get(adc_dev_t *adc, uint32_t *output, uint32_t timeout) { #ifndef AOS_BOARD_HAAS700 int32_t *p_fd = NULL; int32_t ret = -1; io_adc_arg_t arg; if (!adc || !output) return -EINVAL; p_fd = (int32_t *)adc->priv; if (!p_fd || *p_fd < 0) return -EIO; arg.timeout = timeout; ret = ioctl(*p_fd, IOC_ADC_GET_VALUE, (unsigned long)&arg); if (ret) { printf ("get value of adc%d failed, ret:%d\r\n", adc->port, ret); } else { *(uint32_t *)output = arg.value; } return ret; #else return -1; #endif } int32_t aos_hal_adc_voltage_value_get(adc_dev_t *adc, uint32_t *output, uint32_t timeout) { return aos_hal_adc_raw_value_get(adc, output, timeout); } int32_t aos_hal_adc_finalize(adc_dev_t *adc) { #ifndef AOS_BOARD_HAAS700 int32_t ret = 0; int32_t port = 0; int32_t *p_fd = NULL; if (!adc || !adc->priv) return -EINVAL; p_fd = (int32_t *)adc->priv; if (*p_fd < 0) return -EIO; if (*p_fd >= 0) { ret = ioctl(*p_fd, IOC_ADC_STOP, 0); if (ret) printf ("adc%d stop failed, ret:%d\r\n", adc->port, ret); close(*p_fd); } else ret = -EALREADY; adc->priv = NULL; *p_fd = -1; free(p_fd); return ret; #else return -1; #endif }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_adc.c
C
apache-2.0
2,524
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include "aos/hal/can.h" #include "aos_hal_can.h" #include "aos_system.h" typedef enum { PORT_CAN1 = 1, PORT_CAN2 = 2, PORT_CAN_SIZE, PORT_CAN_INVALID = 255, } PORT_CAN_NUM; extern can_dev_t g_can_handle[2]; static int can_received = 0; static uint8_t can1_rx_data[8] = {0}; static uint8_t can2_rx_data[8] = {0}; static can_frameheader_t can1_rx_message = {0}; static can_frameheader_t can2_rx_message = {0}; int32_t aos_hal_can_init(can_dev_t *can) { return hal_can_init(can); } int32_t aos_hal_can_filter_init(can_dev_t *can, const uint8_t filter_grp_cnt, can_filter_item_t *filter_config) { return hal_can_filter_init(can, filter_grp_cnt, filter_config); } int32_t aos_hal_can_send(can_dev_t *can, can_frameheader_t *tx_header, const void *data, const uint32_t timeout) { return hal_can_send(can, tx_header, data, timeout); } void can1_receive_callback(void) { int i, ret; ret = hal_can_recv(&g_can_handle[PORT_CAN1], &can1_rx_message, can1_rx_data, 0xFFFFFFFF); if (ret != 0) { aos_printf("hal can receive failed!\r\n"); return; } can_received = 1; } void can2_receive_callback(void) { int i, ret; ret = hal_can_recv(&g_can_handle[PORT_CAN2], &can2_rx_message, can2_rx_data, 0xFFFFFFFF); if (ret != 0) { aos_printf("hal can receive failed!\r\n"); return; } can_received = 1; } int32_t aos_hal_can_recv(can_dev_t *can, can_frameheader_t *rx_header, void *data, const uint32_t timeout) { int32_t ret = -1; if (can_received) { if (can->port == PORT_CAN1) { *rx_header = can1_rx_message; if (rx_header->rtr == 0) { memcpy(data, can1_rx_data, 8); } can_received = 0; return 0; } if (can->port == PORT_CAN2) { *rx_header = can2_rx_message; if (rx_header->rtr == 0) { memcpy(data, can2_rx_data, 8); } can_received = 0; return 0; } } } int32_t aos_hal_can_finalize(can_dev_t *can) { return hal_can_finalize(can); }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_can.c
C
apache-2.0
2,231
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include "aos_hal_flash.h" int32_t aos_hal_flash_info_get(hal_partition_t in_partition, hal_logic_partition_t **partition) { return 0; } int32_t aos_hal_flash_read(hal_partition_t id, uint32_t *offset, void *buffer, uint32_t buffer_len) { return 0; } int32_t aos_hal_flash_write(hal_partition_t id, uint32_t *offset, const void *buffer, uint32_t buffer_len) { return 0; } int32_t aos_hal_flash_erase(hal_partition_t id, uint32_t offset, uint32_t size) { return 0; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_flash.c
C
apache-2.0
571
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #ifndef AOS_BOARD_HAAS700 #endif #include "aos_hal_gpio.h" #ifdef CONFIG_GPIO_NUM #define PLATFORM_GPIO_NUM CONFIG_GPIO_NUM #else #define PLATFORM_GPIO_NUM 40 #endif int32_t aos_hal_gpio_init(gpio_dev_t *gpio) { if (!gpio || gpio->port >= PLATFORM_GPIO_NUM) return -1; if (gpio->gpioc != NULL) { LOGE("GPIO_HAL", "gpio has inited;\n"); return -1; } uint32_t mode; uint32_t ret; aos_gpioc_ref_t *gpioc; gpioc = aos_malloc(sizeof(aos_gpioc_ref_t)); memset(gpioc, 0, sizeof(gpioc)); int32_t pin_index = gpio->port; int32_t gpioc_index = 0; while (pin_index > 0) { ret = aos_gpioc_get(gpioc, gpioc_index); if (ret) { LOGE("GPIO_HAL", "get gpioc failed, gpioc_index = %d, ret = %d;\n", gpioc_index, ret); aos_free(gpioc); gpioc = NULL; return ret; } ret = aos_gpioc_get_num_pins(gpioc); if (ret <= 0) { LOGE("GPIO_HAL", "get gpioc pin num failed, %d;\n", ret); aos_free(gpioc); gpioc = NULL; return ret; } if (ret <= pin_index) { gpioc_index++; pin_index -= ret; aos_gpioc_put(gpioc); } else { break; } } mode = AOS_GPIO_DIR_OUTPUT; mode |= AOS_GPIO_OUTPUT_CFG_DEFAULT; gpio->gpioc = gpioc; gpio->pin_index = pin_index; gpio->gpioc_index = gpioc_index; switch (gpio->config) { /**< Used as a function pin, input and output analog */ case ANALOG_MODE: break; /**< Used to trigger interrupt */ case IRQ_MODE: mode = AOS_GPIO_DIR_INPUT; return 0; break; /**< Input with an internal pull-up resistor - use with devices * that actively drive the signal low - e.g. button connected to ground */ case INPUT_PULL_UP: mode = AOS_GPIO_DIR_INPUT; mode |= AOS_GPIO_INPUT_CFG_PU; break; /**< Input with an internal pull-down resistor - use with devices * that actively drive the signal high - e.g. button connected to a power rail */ case INPUT_PULL_DOWN: mode = AOS_GPIO_DIR_INPUT; mode |= AOS_GPIO_INPUT_CFG_PD; break; /**< Input - must always be driven, either actively or by an external pullup resistor */ case INPUT_HIGH_IMPEDANCE: mode = AOS_GPIO_DIR_INPUT; mode |= AOS_GPIO_INPUT_CFG_HI; break; /**< Output actively driven high and actively driven low - * must not be connected to other active outputs - e.g. LED output */ case OUTPUT_PUSH_PULL: mode = AOS_GPIO_DIR_OUTPUT; mode |= AOS_GPIO_OUTPUT_CFG_PP; break; /**< 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 */ case OUTPUT_OPEN_DRAIN_NO_PULL: mode = AOS_GPIO_DIR_OUTPUT; mode |= AOS_GPIO_OUTPUT_CFG_ODNP; break; /**< 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. */ case OUTPUT_OPEN_DRAIN_PULL_UP: mode = AOS_GPIO_DIR_OUTPUT; mode |= AOS_GPIO_OUTPUT_CFG_ODPU; break; /**< Alternate Function Open Drain Mode. */ case OUTPUT_OPEN_DRAIN_AF: break; /**< Alternate Function Push Pull Mode. */ case OUTPUT_PUSH_PULL_AF: default: break; } ret = aos_gpioc_set_mode(gpioc, pin_index, mode); if (ret) { LOGE("GPIO_HAL", "%s: set gpio mode failed, %d;\n", __func__, ret); aos_gpioc_put(&gpioc); aos_free(gpioc); gpioc = NULL; return ret; } return 0; } int32_t aos_hal_gpio_output_high(gpio_dev_t *gpio) { #ifndef AOS_BOARD_HAAS700 if (!gpio || gpio->port >= PLATFORM_GPIO_NUM) return -1; return aos_gpioc_set_value(gpio->gpioc, gpio->pin_index, 1); #else return -1; #endif } int32_t aos_hal_gpio_output_low(gpio_dev_t *gpio) { #ifndef AOS_BOARD_HAAS700 if (!gpio || gpio->port >= PLATFORM_GPIO_NUM) return -1; return aos_gpioc_set_value(gpio->gpioc, gpio->pin_index, 0); #else return -1; #endif } int32_t aos_hal_gpio_output_toggle(gpio_dev_t *gpio) { #ifndef AOS_BOARD_HAAS700 return aos_gpioc_toggle(gpio->gpioc, gpio->pin_index); #else return -1; #endif } int32_t aos_hal_gpio_get(gpio_dev_t *gpio) { return aos_gpioc_get_value(gpio->gpioc, gpio->pin_index); } int32_t aos_hal_gpio_input_get(gpio_dev_t *gpio, uint32_t *value) { #ifndef AOS_BOARD_HAAS700 int ret = -1; ret = aos_gpioc_get_value(gpio->gpioc, gpio->pin_index); *value = ret > 0 ? 1 : 0; return ret; #else return -1; #endif } int32_t aos_hal_gpio_enable_irq(gpio_dev_t *gpio, gpio_irq_trigger_t trigger, aos_gpio_irq_handler_t handler, void *arg) { #ifndef AOS_BOARD_HAAS700 uint32_t ret = -1; uint32_t mode = 0; mode = AOS_GPIO_DIR_INPUT; switch (trigger) { case IRQ_TRIGGER_RISING_EDGE: mode |= AOS_GPIO_IRQ_TRIG_EDGE_RISING; break; case IRQ_TRIGGER_FALLING_EDGE: mode |= AOS_GPIO_IRQ_TRIG_EDGE_FALLING; break; case IRQ_TRIGGER_LEVEL_HIGH: mode |= AOS_GPIO_IRQ_TRIG_LEVEL_HIGH; break; case IRQ_TRIGGER_LEVEL_LOW: mode |= AOS_GPIO_IRQ_TRIG_LEVEL_LOW; break; case IRQ_TRIGGER_BOTH_EDGES: mode |= AOS_GPIO_IRQ_TRIG_EDGE_BOTH; break; default: break; } switch (gpio->config) { case INPUT_PULL_UP: mode |= AOS_GPIO_INPUT_CFG_PU; break; /**< Input with an internal pull-down resistor - use with devices * that actively drive the signal high - e.g. button connected to a power rail */ case INPUT_PULL_DOWN: mode |= AOS_GPIO_INPUT_CFG_PD; break; /**< Input - must always be driven, either actively or by an external pullup resistor */ case INPUT_HIGH_IMPEDANCE: mode |= AOS_GPIO_INPUT_CFG_HI; break; default: mode |= AOS_GPIO_INPUT_CFG_DEFAULT; } LOGE("GPIO_HAL", "aos_gpioc_set_mode_irq mode =%x, gpioc_index=%d, pin_index=%d\n", mode, gpio->gpioc_index, gpio->pin_index); ret = aos_gpioc_set_mode_irq(gpio->gpioc, gpio->pin_index, mode, handler, arg); if (ret) { LOGE("GPIO_HAL", "aos_gpioc_set_mode_irq failed %d\n", ret); } return ret; #else return -1; #endif } int32_t aos_hal_gpio_disable_irq(gpio_dev_t *gpio) { #ifndef AOS_BOARD_HAAS700 // gpio_irq_config_t config; // int r; // if (!gpio || gpio->port >= PLATFORM_GPIO_NUM) // return -1; // config.id = gpio->port; // config.config = GPIO_IRQ_DISABLE; // config.cb = NULL; // config.arg = NULL; // r = ioctl(gpio->fd, IOC_GPIO_SET_IRQ, (unsigned long)&config); // return r < 0 ? -1 : 0; return 0; #else return -1; #endif } int32_t aos_hal_gpio_clear_irq(gpio_dev_t *gpio) { #ifndef AOS_BOARD_HAAS700 return aos_hal_gpio_disable_irq(gpio); #else return -1; #endif } int32_t aos_hal_gpio_finalize(gpio_dev_t *gpio) { if (!gpio || gpio->port >= PLATFORM_GPIO_NUM) return -1; aos_gpioc_put(gpio->gpioc); aos_free(gpio->gpioc); gpio->gpioc = NULL; return 0; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_gpio.c
C
apache-2.0
7,560
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include <aos/errno.h> #ifndef AOS_BOARD_HAAS700 #include <vfsdev/i2c_dev.h> #endif #include "aos_hal_i2c.h" int32_t aos_hal_i2c_init(i2c_dev_t *i2c) { #ifndef AOS_BOARD_HAAS700 int32_t ret = 0; int32_t port = 0; int32_t *p_fd = NULL; char name[16] = {0}; io_i2c_control_u c; if (!i2c || i2c->priv) return -EINVAL; port = i2c->port; p_fd = (int32_t *)malloc(sizeof(int32_t)); if (!p_fd) return -ENOMEM; *p_fd = -1; snprintf(name, sizeof(name), "/dev/i2c%d", port); *p_fd = open(name, 0); if (*p_fd < 0) { printf ("open %s failed, fd:%d\r\n", name, *p_fd); ret = -EIO; goto out; } c.c.addr = i2c->config.dev_addr; /* sensor's address */ c.c.addr_width = i2c->config.address_width; /* 7-bit address */ c.c.role = 1; /* master mode */ ret = ioctl(*p_fd, IOC_I2C_SET_CONFIG, (unsigned long)&c); if (ret) { printf ("set i2c config on %s failed\r\n", name); goto out; } c.freq = i2c->config.freq; ret = ioctl(*p_fd, IOC_I2C_SET_FREQ, (unsigned long)&c); if (ret) { printf ("set i2c config on %s failed\r\n", name); goto out; } out: if (!ret) { i2c->priv = p_fd; } else { if (*p_fd >= 0) close(*p_fd); free(p_fd); p_fd = NULL; } return ret; #else return -1; #endif } int32_t aos_hal_i2c_master_send(i2c_dev_t *i2c, uint16_t dev_addr, const uint8_t *data, uint16_t size, uint32_t timeout) { #ifndef AOS_BOARD_HAAS700 int32_t port = 0; int32_t *p_fd = NULL; int32_t ret = -1; io_i2c_data_t d; if (!i2c) return -EINVAL; p_fd = (int32_t *)i2c->priv; if (!p_fd || *p_fd < 0) return -EIO; d.addr = dev_addr; d.data = (unsigned char *)data; d.length = size; d.maddr = 0; d.mlength = 0; d.timeout = timeout; ret = ioctl(*p_fd, IOC_I2C_MASTER_TX, (unsigned long)&d); return ret; #else return -1; #endif } int32_t aos_hal_i2c_master_recv(i2c_dev_t *i2c, uint16_t dev_addr, uint8_t *data, uint16_t size, uint32_t timeout) { #ifndef AOS_BOARD_HAAS700 int32_t port = 0; int32_t *p_fd = NULL; int32_t ret = -1; io_i2c_data_t d; if (!i2c) return -EINVAL; p_fd = (int32_t *)i2c->priv; if (!p_fd || *p_fd < 0) return -EIO; d.addr = dev_addr; d.data = data; d.length = size; d.maddr = 0; d.mlength = 0; d.timeout = timeout; ret = ioctl(*p_fd, IOC_I2C_MASTER_RX, (unsigned long)&d); return 0; #else return -1; #endif } int32_t aos_hal_i2c_slave_send(i2c_dev_t *i2c, const uint8_t *data, uint16_t size, uint32_t timeout) { // slave operation is not supported return -ENOTSUP; } int32_t aos_hal_i2c_slave_recv(i2c_dev_t *i2c, uint8_t *data, uint16_t size, uint32_t timeout) { // slave operation is not supported return -ENOTSUP; } int32_t aos_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) { #ifndef AOS_BOARD_HAAS700 int32_t port = 0; int32_t *p_fd = NULL; int32_t ret = -1; io_i2c_data_t d; if (!i2c) return -EINVAL; p_fd = (int32_t *)i2c->priv; if (!p_fd || *p_fd < 0) return -EIO; d.addr = dev_addr; d.data = (unsigned char *)data; d.length = size; d.maddr = mem_addr; d.mlength = mem_addr_size / 8; d.timeout = timeout; ret = ioctl(*p_fd, IOC_I2C_MEM_TX, (unsigned long)&d); return 0; #else return -1; #endif } int32_t aos_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) { #ifndef AOS_BOARD_HAAS700 int32_t port = 0; int32_t *p_fd = NULL; int32_t ret = -1; io_i2c_data_t d; if (!i2c) return -EINVAL; p_fd = (int32_t *)i2c->priv; if (!p_fd || *p_fd < 0) return -EIO; d.addr = dev_addr; d.data = data; d.length = size; d.maddr = mem_addr; d.mlength = mem_addr_size / 8; d.timeout = timeout; ret = ioctl(*p_fd, IOC_I2C_MEM_RX, (unsigned long)&d); return 0; #else return -1; #endif } int32_t aos_hal_i2c_finalize(i2c_dev_t *i2c) { #ifndef AOS_BOARD_HAAS700 int32_t ret = 0; int32_t port = 0; int32_t *p_fd = NULL; if (!i2c || !i2c->priv) return -EINVAL; p_fd = (int32_t *)i2c->priv; if (*p_fd < 0) return -EIO; if (*p_fd >= 0) close(*p_fd); else ret = -EALREADY; i2c->priv = NULL; *p_fd = -1; free(p_fd); return ret; #else return -1; #endif }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_i2c.c
C
apache-2.0
5,075
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <unistd.h> #include <sys/ioctl.h> #include "aos_hal_lcd.h" #ifndef AOS_BOARD_HAAS700 #include "udisplay.h" #endif int32_t aos_hal_lcd_init(void) { #ifndef AOS_BOARD_HAAS700 return udisplay_init(); #else return -1; #endif } int32_t aos_hal_lcd_uninit(void) { #ifndef AOS_BOARD_HAAS700 return udisplay_uninit(); #else return -1; #endif } int32_t aos_hal_lcd_show(int x, int y, int w, int h, uint8_t *buf, bool rotate) { #ifndef AOS_BOARD_HAAS700 return udisplay_show_rect(buf, x, y, w, h, rotate); #else return -1; #endif } int32_t aos_hal_lcd_fill(int x, int y, int w, int h, uint32_t color) { #ifndef AOS_BOARD_HAAS700 return udisplay_fill_rect(x, y, w, h, color); #else return -1; #endif }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_lcd.c
C
apache-2.0
820
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include <aos/errno.h> #include "aos_hal_pwm.h" #ifndef AOS_BOARD_HAAS700 #include <aos/pwm.h> #endif #define NS_PER_SEC (1000000000UL) #define DIV_ROUND_CLOSEST(x, divisor)( \ { \ typeof(x) __x = x; \ typeof(divisor) __d = divisor; \ (((typeof(x))-1) > 0 || \ ((typeof(divisor))-1) > 0 || \ (((__x) > 0) == ((__d) > 0))) ? \ (((__x) + ((__d) / 2)) / (__d)) : \ (((__x) - ((__d) / 2)) / (__d)); \ } \ ) int32_t aos_hal_pwm_init(pwm_dev_t *pwm) { #ifndef AOS_BOARD_HAAS700 int ret = 0; aos_pwm_ref_t *ref = NULL; aos_pwm_attr_t attr; ref = (aos_pwm_ref_t *)malloc(sizeof(aos_pwm_ref_t)); if (ref == NULL) { return -ENOMEM; } memset(&attr, 0, sizeof(aos_pwm_attr_t)); ret = aos_pwm_get(ref, pwm->port); if (ret < 0) { goto out; } attr.period = pwm->config.freq > 0 ? DIV_ROUND_CLOSEST(NS_PER_SEC, pwm->config.freq) : 0; attr.duty_cycle = pwm->config.duty_cycle > 0 ? (attr.period * pwm->config.duty_cycle) / 100 : 0; attr.enabled = 1; attr.polarity = 0; ret = aos_pwm_set_attr(ref, &attr); if (ret) { goto out; } out: if (!ret) { pwm->priv = ref; } else { if (ref != NULL) aos_pwm_put(ref); free(ref); ref = NULL; } return ret; #else return -1; #endif } int32_t aos_hal_pwm_stop(pwm_dev_t *pwm) { #ifndef AOS_BOARD_HAAS700 int ret = 0; aos_pwm_ref_t *ref = NULL; aos_pwm_attr_t attr; if (!pwm) return -EINVAL; ref = (aos_pwm_ref_t *)pwm->priv; if (!ref) return -EIO; attr.enabled = 0; ret = aos_pwm_set_attr(ref, &attr); return ret; #else return -1; #endif } int32_t aos_hal_pwm_start(aos_hal_pwm_dev_t *pwm) { #ifndef AOS_BOARD_HAAS700 return 0; #else return -1; #endif } int32_t aos_hal_pwm_para_chg(pwm_dev_t *pwm, pwm_config_t para) { #ifndef AOS_BOARD_HAAS700 int ret = 0; aos_pwm_ref_t *ref = NULL; aos_pwm_attr_t attr; if (!pwm) return -EINVAL; ref = (aos_pwm_ref_t *)pwm->priv; if (!ref) return -EIO; attr.period = para.freq > 0 ? DIV_ROUND_CLOSEST(NS_PER_SEC, para.freq) : 0; attr.duty_cycle = para.duty_cycle > 0 ? (attr.period * para.duty_cycle) / 100 : 0; attr.enabled = 1; attr.polarity = 0; ret = aos_pwm_set_attr(ref, &attr); return ret; #else return -1; #endif } int32_t aos_hal_pwm_finalize(pwm_dev_t *pwm) { #ifndef AOS_BOARD_HAAS700 int ret; aos_pwm_ref_t *ref = NULL; aos_pwm_attr_t attr; if (!pwm) return -EINVAL; ref = (aos_pwm_ref_t *)pwm->priv; if (!ref) return -EIO; attr.enabled = 0; ret = aos_pwm_set_attr(ref, &attr); if (ret) { goto out; } aos_pwm_put(ref); free(ref); return 0; out: return ret; #else return -1; #endif }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_pwm.c
C
apache-2.0
3,246
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include "aos_hal_rtc.h" int32_t aos_hal_rtc_init(rtc_dev_t *rtc) { //return hal_rtc_init(rtc); } int32_t aos_hal_rtc_get_time(rtc_dev_t *rtc, rtc_time_t *time) { //return hal_rtc_get_time(rtc, time); } int32_t aos_hal_rtc_set_time(rtc_dev_t *rtc, const rtc_time_t *time) { //return hal_rtc_set_time(rtc, time); } int32_t aos_hal_rtc_finalize(rtc_dev_t *rtc) { //return hal_rtc_finalize(rtc); }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_rtc.c
C
apache-2.0
499
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <aos/errno.h> #ifndef AOS_BOARD_HAAS700 #include <vfsdev/spi_dev.h> #endif #include "aos/hal/spi.h" #include "aos_hal_spi.h" int32_t aos_hal_spi_init(spi_dev_t *spi) { #ifndef AOS_BOARD_HAAS700 return hal_spi_init(spi); #else return -1; #endif } int32_t aos_hal_spi_send(spi_dev_t *spi, const uint8_t *data, uint32_t size, uint32_t timeout) { #ifndef AOS_BOARD_HAAS700 return hal_spi_send(spi, data, size, timeout); #else return -1; #endif } int32_t aos_hal_spi_recv(spi_dev_t *spi, uint8_t *data, uint32_t size, uint32_t timeout) { #ifndef AOS_BOARD_HAAS700 return hal_spi_recv(spi, data, size, timeout); #else return -1; #endif } int32_t aos_hal_spi_send_recv(spi_dev_t *spi, uint8_t *tx_data, uint8_t *rx_data, uint32_t rx_size, uint32_t timeout) { #ifndef AOS_BOARD_HAAS700 return hal_spi_send_recv(spi, tx_data, rx_data, rx_size, timeout); #else return -1; #endif } int32_t aos_hal_spi_sends_recvs(spi_dev_t *spi, uint8_t *tx_data, uint32_t tx_size, uint8_t *rx_data, uint32_t rx_size, uint32_t timeout) { return hal_spi_sends_recvs(spi, tx_data, tx_size, rx_data, rx_size, timeout); } int32_t aos_hal_spi_send_and_recv(spi_dev_t *spi, uint8_t *tx_data, uint16_t tx_size, uint8_t *rx_data, uint16_t rx_size, uint32_t timeout) { #ifndef AOS_BOARD_HAAS700 return hal_spi_send_and_recv(spi, tx_data, tx_size, rx_data, rx_size, timeout); #else return -1; #endif } int32_t aos_hal_spi_finalize(spi_dev_t *spi) { #ifndef AOS_BOARD_HAAS700 return hal_spi_finalize(spi); #else return -1; #endif }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_spi.c
C
apache-2.0
1,736
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include <aos/errno.h> #include "aos_hal_timer.h" #ifndef AOS_BOARD_HAAS700 #include <vfsdev/timer_dev.h> #endif int32_t aos_hal_timer_init(timer_dev_t *tim) { #ifndef AOS_BOARD_HAAS700 int32_t ret = 0; int32_t port = 0; int32_t *p_fd = NULL; char name[16] = {0}; timer_alarm_t alarm; if (!tim || tim->priv) return -EINVAL; port = tim->port; p_fd = (int32_t *)malloc(sizeof(int32_t)); if (!p_fd) return -ENOMEM; *p_fd = -1; snprintf(name, sizeof(name), "/dev/timer%d", port); *p_fd = open(name, 0); if (*p_fd < 0) { printf ("open %s failed, fd:%d\r\n", name, *p_fd); ret = -EIO; goto out; } ret = 0; out: if (!ret) { tim->priv = p_fd; } else { if (*p_fd >= 0) close(*p_fd); free(p_fd); p_fd = NULL; } return ret; #else return -1; #endif } int32_t aos_hal_timer_start(timer_dev_t *tim) { #ifndef AOS_BOARD_HAAS700 int32_t *p_fd = NULL; int32_t ret = -1; timer_alarm_t alarm; if (!tim) return -EINVAL; p_fd = (int32_t *)tim->priv; if (!p_fd || *p_fd < 0) return -EIO; alarm.arg = tim->config.arg; alarm.cb = tim->config.cb; alarm.period = tim->config.period; alarm.auto_reload = tim->config.reload_mode; ret = ioctl(*p_fd, IOC_TIMER_IRQP_SET, (unsigned long)&alarm); if (ret) printf("ioctl on IOC_TIMER_IRQP_SET failed, ret:%d\r\n", ret); ret = ioctl(*p_fd, IOC_TIMER_CONTROL, (unsigned long)IO_TIMER_START); if (ret) printf("start timer%d failed, ret:%d\r\n", tim->port, ret); return ret; #else return -1; #endif } void aos_hal_timer_stop(timer_dev_t *tim) { #ifndef AOS_BOARD_HAAS700 int32_t *p_fd = NULL; int32_t ret = -1; if (!tim) return; p_fd = (int32_t *)tim->priv; if (!p_fd || *p_fd < 0) return; ret = ioctl(*p_fd, IOC_TIMER_CONTROL, (unsigned long)IO_TIMER_STOP); if (ret) printf("stop timer%d failed, ret:%d\r\n", tim->port, ret); return; #else return; #endif } int32_t aos_hal_timer_reload(aos_hal_timer_dev_t *tim) { int32_t *p_fd = (int32_t *)tim->priv; return ioctl(*p_fd, IOC_TIMER_RELOAD, (unsigned long)false); } int32_t aos_hal_timer_para_chg(timer_dev_t *tim, timer_config_t para) { #ifndef AOS_BOARD_HAAS700 int32_t *p_fd = NULL; int32_t ret = -1; timer_alarm_t alarm; if (!tim) return -EINVAL; p_fd = (int32_t *)tim->priv; if (!p_fd || *p_fd < 0) return -EIO; alarm.arg = para.arg; alarm.cb = para.cb; alarm.period = para.period; alarm.auto_reload = para.reload_mode; ret = ioctl(*p_fd, IOC_TIMER_IRQP_SET, (unsigned long)&alarm); if (ret) printf("change parameter of timer%d failed, ret:%d\r\n", tim->port, ret); return ret; #else return -1; #endif } int32_t aos_hal_timer_finalize(timer_dev_t *tim) { #ifndef AOS_BOARD_HAAS700 int32_t ret = 0; int32_t port = 0; int32_t *p_fd = NULL; if (!tim || !tim->priv) return -EINVAL; p_fd = (int32_t *)tim->priv; if (*p_fd < 0) return -EIO; if (*p_fd >= 0) close(*p_fd); else ret = -EALREADY; tim->priv = NULL; *p_fd = -1; free(p_fd); return ret; #else return -1; #endif }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_timer.c
C
apache-2.0
3,536
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <unistd.h> #include <limits.h> #include <poll.h> #include <errno.h> #ifndef AOS_BOARD_HAAS700 #include <vfsdev/uart_dev.h> #endif #include "aos/hal/uart.h" #include "aos/kernel.h" #include "aos_hal_uart.h" #ifdef CONFIG_UART_NUM #define PLATFORM_UART_NUM CONFIG_UART_NUM #else #define PLATFORM_UART_NUM 4 #endif static int uart_fd_table[PLATFORM_UART_NUM]; int32_t aos_hal_uart_init(uart_dev_t *uart) { return hal_uart_init(uart); } int32_t aos_hal_uart_send(uart_dev_t *uart, const void *data, uint32_t size, uint32_t timeout) { return hal_uart_send(uart, data, size, timeout); } int32_t aos_hal_uart_recv(uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t timeout) { /* deprecated */ return -1; } int32_t aos_hal_uart_recv_poll(uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t *recv_size) { return hal_uart_recv_II(uart, data, expect_size, recv_size, 0); } int32_t aos_hal_uart_recv_II(uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t *recv_size, uint32_t timeout) { return hal_uart_recv_II(uart, data, expect_size, recv_size, timeout); } int aos_hal_uart_rx_sem_take(int uartid, int timeout) { #ifndef AOS_BOARD_HAAS700 return hal_uart_rx_sem_take(uartid, timeout); #else return -1; #endif } int aos_hal_uart_rx_sem_give(int port) { #ifndef AOS_BOARD_HAAS700 return hal_uart_rx_sem_give(port); #else return -1; #endif } typedef struct { void (*callback)(int, void *, uint16_t, void *); void *userdata; uart_dev_t *uart; int task_running; int stop; aos_mutex_t lock; aos_sem_t sem; aos_task_t task; } uart_recv_notify_t; static uart_recv_notify_t *uart_recv_notifiers[PLATFORM_UART_NUM]; static void uart_recv_handler(void *args) { uart_recv_notify_t *notify = (uart_recv_notify_t *)args; uart_dev_t *uart; char recv_buffer[256]; uint32_t recv_size; int ret; if (!notify) return; uart = notify->uart; while (1) { aos_mutex_lock(&notify->lock, AOS_WAIT_FOREVER); if (notify->stop) { aos_mutex_unlock(&notify->lock); break; } aos_mutex_unlock(&notify->lock); ret = aos_hal_uart_recv_II(uart, recv_buffer, sizeof(recv_buffer), &recv_size, 100); if (ret || recv_size <= 0) continue; if (notify->callback) notify->callback(uart->port, recv_buffer, recv_size, notify->userdata); } aos_sem_signal(&notify->sem); } #if 0 extern int32_t hal_uart_receive_register(int port, void(*cb)(int, void *), void *args); static int uart_port_registered[7]; #endif int32_t aos_hal_uart_callback(uart_dev_t *uart, void (*cb)(int, void *, uint16_t, void *), void *args) { #if 0 if (uart_port_registered[uart->port]) return 0; hal_uart_receive_register(uart, cb, args); uart_port_registered[uart->port] = 1; #else uart_recv_notify_t *notify = uart_recv_notifiers[uart->port]; if (!notify) { notify = aos_malloc(sizeof(uart_recv_notify_t)); if (!notify) return -1; memset(notify, 0, sizeof(uart_recv_notify_t)); aos_mutex_new(&notify->lock); aos_sem_new(&notify->sem, 0); uart_recv_notifiers[uart->port] = notify; } notify->callback = cb; notify->userdata = args; notify->uart = uart; if (!notify->task_running) { if (aos_task_new_ext(&notify->task, "amp_uart_recv", uart_recv_handler, notify, 2048, 32)) return -1; notify->task_running = 1; } #endif return 0; } int32_t aos_hal_uart_any(uart_dev_t *uart) { return hal_uart_any(uart); } int32_t aos_hal_uart_finalize(uart_dev_t *uart) { uart_recv_notify_t *notify = uart_recv_notifiers[uart->port]; if (notify) { if (notify->task_running) { aos_mutex_lock(&notify->lock, AOS_WAIT_FOREVER); notify->stop = 1; aos_mutex_unlock(&notify->lock); aos_sem_wait(&notify->sem, 3000); } aos_mutex_free(&notify->lock); aos_sem_free(&notify->sem); aos_free(notify); uart_recv_notifiers[uart->port] = NULL; } //close(uart_fd_table[uart->port]); hal_uart_finalize(uart); uart_fd_table[uart->port] = -1; return 0; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_uart.c
C
apache-2.0
4,479
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include <aos/errno.h> #include "aos_hal_wdg.h" #ifndef AOS_BOARD_HAAS700 #include <vfsdev/wdg_dev.h> #endif int32_t aos_hal_wdg_init(wdg_dev_t *wdg) { #if (defined(BOARD_HAAS100) || defined(BOARD_HAASEDUK1)) hal_wdg_init(wdg); #else #ifndef AOS_BOARD_HAAS700 uint32_t flags = 0; int32_t ret = 0; int32_t *p_fd = NULL; char name[16] = {0}; if (!wdg || wdg->priv) return -EINVAL; p_fd = (int32_t *)malloc(sizeof(int32_t)); if (!p_fd) return -ENOMEM; *p_fd = -1; snprintf(name, sizeof(name), "/dev/wdg%d", wdg->port); *p_fd = open(name, 0); if (*p_fd < 0) { printf ("open %s failed, fd:%d\r\n", name, *p_fd); ret = -EIO; goto out; } out: if (!ret) { wdg->priv = p_fd; } else { if (*p_fd >= 0) close(*p_fd); free(p_fd); p_fd = NULL; } return ret; #endif return -1; #endif } void aos_hal_wdg_reload(wdg_dev_t *wdg) { #if (defined(BOARD_HAAS100) || defined(BOARD_HAASEDUK1)) hal_wdg_reload(wdg); #else #ifndef AOS_BOARD_HAAS700 int32_t *p_fd = NULL; int32_t ret = -1; if (!wdg) return; p_fd = (int32_t *)wdg->priv; if (!p_fd || *p_fd < 0) return; ret = ioctl(*p_fd, IOC_WDG_RELOAD, 0); if (ret) { printf ("reload wdg%d failed, ret:%d\r\n", wdg->port, ret); } return; #endif return -1; #endif } int32_t aos_hal_wdg_finalize(wdg_dev_t *wdg) { #if (defined(BOARD_HAAS100) || defined(BOARD_HAASEDUK1)) hal_wdg_finalize(wdg); #else #ifndef AOS_BOARD_HAAS700 int32_t ret = 0; int32_t port = 0; int32_t *p_fd = NULL; if (!wdg || !wdg->priv) return -EINVAL; p_fd = (int32_t *)wdg->priv; if (*p_fd < 0) return -EIO; if (*p_fd >= 0) { close(*p_fd); } else ret = -EALREADY; wdg->priv = NULL; *p_fd = -1; free(p_fd); return ret; #endif return -1; #endif }
YifuLiu/AliOS-Things
components/amp_adapter/platform/aos/peripheral/aos_hal_wdg.c
C
apache-2.0
2,135
#include "amp_platform.h" #include "aos_system.h" #include "ota_agent.h" void internal_sys_upgrade_start(void *ctx) { ota_service_start((ota_service_t *)ctx); aos_task_exit(0); return; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/amp_ota_port.c
C
apache-2.0
201
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include "aos_hal_adc.h" #include "driver/gpio.h" #include "driver/adc.h" uint8_t adc_bit_width; uint8_t adc_atten_value; typedef enum { ESP32_GPIO_NUM_32 = 32, /*!< GPIO32, input and output */ ESP32_GPIO_NUM_33 = 33, /*!< GPIO33, input and output */ ESP32_GPIO_NUM_34 = 34, /*!< GPIO34, input mode only */ ESP32_GPIO_NUM_35 = 35, /*!< GPIO35, input mode only */ ESP32_GPIO_NUM_36 = 36, /*!< GPIO36, input mode only */ ESP32_GPIO_NUM_37 = 37, /*!< GPIO37, input mode only */ ESP32_GPIO_NUM_38 = 38, /*!< GPIO38, input mode only */ ESP32_GPIO_NUM_39 = 39, /*!< GPIO39, input mode only */ } aos_gpio_num_t; typedef enum { ESP32_ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO1 */ ESP32_ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO2 */ ESP32_ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO3 */ ESP32_ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO4 */ ESP32_ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO5 */ ESP32_ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO6 */ ESP32_ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO7 */ ESP32_ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO8 */ ESP32_ADC1_CHANNEL_8, /*!< ADC1 channel 8 is GPIO9 */ ESP32_ADC1_CHANNEL_9, /*!< ADC1 channel 9 is GPIO10 */ } aos_adc1_channel_t; uint8_t aos_hal_pin_port_change(uint8_t port) { uint8_t gpio_num = 0; switch (port) { case ESP32_ADC1_CHANNEL_0: gpio_num = ESP32_GPIO_NUM_36; break; case ESP32_ADC1_CHANNEL_1: gpio_num = ESP32_GPIO_NUM_37; break; case ESP32_ADC1_CHANNEL_2: gpio_num = ESP32_GPIO_NUM_38; break; case ESP32_ADC1_CHANNEL_3: gpio_num = ESP32_GPIO_NUM_39; break; case ESP32_ADC1_CHANNEL_4: gpio_num = ESP32_GPIO_NUM_32; break; case ESP32_ADC1_CHANNEL_5: gpio_num = ESP32_GPIO_NUM_33; break; case ESP32_ADC1_CHANNEL_6: gpio_num = ESP32_GPIO_NUM_34; break; case ESP32_ADC1_CHANNEL_7: gpio_num = ESP32_GPIO_NUM_35; break; default: break; } return gpio_num; } uint8_t aos_hal_find_adc_channel(uint8_t gpio_num) { uint8_t channel = 0; switch (gpio_num) { case ESP32_GPIO_NUM_32: channel = ESP32_ADC1_CHANNEL_4; break; case ESP32_GPIO_NUM_33: channel = ESP32_ADC1_CHANNEL_5; break; case ESP32_GPIO_NUM_34: channel = ESP32_ADC1_CHANNEL_6; break; case ESP32_GPIO_NUM_35: channel = ESP32_ADC1_CHANNEL_7; break; case ESP32_GPIO_NUM_36: channel = ESP32_ADC1_CHANNEL_0; break; case ESP32_GPIO_NUM_37: channel = ESP32_ADC1_CHANNEL_1; break; case ESP32_GPIO_NUM_38: channel = ESP32_ADC1_CHANNEL_2; break; case ESP32_GPIO_NUM_39: channel = ESP32_ADC1_CHANNEL_3; break; default: break; } return channel; } int32_t aos_hal_adc_init(adc_dev_t *adc) { int initialized = 0; uint8_t channel = 0; if (!initialized) { // set adc config width if (adc->config.adc_width >= 0 && adc->config.adc_width <= 3) { adc1_config_width(adc->config.adc_width); } else { #if CONFIG_IDF_TARGET_ESP32S2 adc->config.adc_width = ADC_WIDTH_BIT_13; adc1_config_width(ADC_WIDTH_BIT_13); #else adc->config.adc_width = ADC_WIDTH_BIT_12; adc1_config_width(ADC_WIDTH_BIT_12); #endif } adc_bit_width = adc->config.adc_width; initialized = 1; } // uint8_t pin_id = adc->port; // channel = aos_hal_find_adc_channel(pin_id); channel = adc->port; // use ADC atten 0db adc_atten_value = adc->config.adc_atten; esp_err_t ret = adc1_config_channel_atten(channel, adc_atten_value); if (ret != ESP_OK) { printf("parameter error"); } return ret; } int32_t aos_hal_adc_voltage_value_get(adc_dev_t *adc, uint32_t *output, uint32_t timeout) { int val = 0; int vout = 0; int vmax = 1100; int dmax = 4095; uint8_t channel = 0; // uint8_t pin_id = adc->port; // channel = aos_hal_find_adc_channel(pin_id); channel = adc->port; val = adc1_get_raw(channel); if (val == -1) { printf("parameter error\r\n"); } // calc v value // Vout = Dout * Vmax /Dmax // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html // atten value // ADC_ATTEN_DV_0 100mV ~ 950mV MAX 1100mV // ADC_ATTEN_DV_2_5 100mV ~ 1250mV MAX 1500mV // ADC_ATTEN_DV_6 150mV ~ 1750mV MAX 2200mV // ADC_ATTEN_DV_11 150mV ~ 2450mV MAX 3900mV // ESP32 Dmax = 4095 switch (adc_atten_value) { case ADC_ATTEN_0db: vmax = 1100; break; case ADC_ATTEN_2_5db: vmax = 1500; break; case ADC_ATTEN_6db: vmax = 2200; break; case ADC_ATTEN_11db: vmax = 3900; break; default: vmax = 1100; break; } switch (adc_bit_width) { #if CONFIG_IDF_TARGET_ESP32 case ADC_WIDTH_BIT_9: dmax = 511; break; case ADC_WIDTH_BIT_10: dmax = 1023; break; case ADC_WIDTH_BIT_11: dmax = 2047; break; case ADC_WIDTH_BIT_12: dmax = 4095; break; #endif default: dmax = 4095; break; } vout = val * vmax / dmax; *(uint32_t *)output = vout; return 0; } int32_t aos_hal_adc_raw_value_get(adc_dev_t *adc, uint32_t *output, uint32_t timeout) { int val = 0; uint8_t channel = 0; // uint8_t pin_id = adc->port; // channel = aos_hal_find_adc_channel(pin_id); channel = adc->port; val = adc1_get_raw(channel); if (val == -1) { printf("parameter error\r\n"); } *(uint32_t *)output = val; return 0; } // esp32 can set atten and width to change adc value // use board config to setting // typedef struct { // uint8_t atten; // uint8_t width; // } adc_param_t; // int32_t aos_hal_adc_para_chg(adc_dev_t *adc, adc_param_t para) // { // esp_err_t ret = 0; // uint8_t channel = 0; // adc_atten_t atten = para.atten; // uint8_t pin_id = adc->port; // channel = aos_hal_find_adc_channel(pin_id); // ret = adc1_config_channel_atten(channel, atten); // if (ret != ESP_OK) { // printf("parameter error, adc config atten failed\r\n"); // return ret; // } // adc_bits_width_t width = para.width; // ret = adc1_config_width(width); // if (ret != ESP_OK) { // printf("parameter error, adc config width failed\r\n"); // return ret; // } // switch (width) { // case ADC_WIDTH_9Bit: // adc_bit_width = 9; // break; // case ADC_WIDTH_10Bit: // adc_bit_width = 10; // break; // case ADC_WIDTH_11Bit: // adc_bit_width = 11; // break; // case ADC_WIDTH_12Bit: // adc_bit_width = 12; // break; // default: // break; // } // return ret; // } int32_t aos_hal_adc_finalize(adc_dev_t *adc) { int32_t ret = 0; return ret; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/aos_hal_adc.c
C
apache-2.0
7,452
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include "aos_hal_flash.h" #include "esp_partition.h" static hal_logic_partition_t default_partitions[HAL_PARTITION_MAX]; int32_t hal_partition_to_esp_partition_type(hal_partition_t in_partition, esp_partition_type_t *type, esp_partition_subtype_t *subtype) { int ret = 0; switch (in_partition) { case HAL_PARTITION_PARAMETER_1: *type = ESP_PARTITION_TYPE_DATA; *subtype = 0x91; break; case HAL_PARTITION_PARAMETER_2: *type = ESP_PARTITION_TYPE_DATA; *subtype = 0x83; break; case HAL_PARTITION_PARAMETER_3: *type = ESP_PARTITION_TYPE_DATA; *subtype = 0x92; break; case HAL_PARTITION_APPLICATION: *type = ESP_PARTITION_TYPE_APP; *subtype = ESP_PARTITION_SUBTYPE_APP_OTA_0; break; case HAL_PARTITION_OTA_TEMP: *type = ESP_PARTITION_TYPE_APP; *subtype = ESP_PARTITION_SUBTYPE_APP_OTA_1; break; case HAL_PARTITION_LITTLEFS: *type = ESP_PARTITION_TYPE_DATA; *subtype = ESP_PARTITION_SUBTYPE_DATA_FAT; break; default: ret = -1; break; } return ret; } int32_t aos_hal_flash_info_get(hal_partition_t in_partition, hal_logic_partition_t **partition) { int ret; const esp_partition_t *esp_partition; esp_partition_type_t type; esp_partition_subtype_t subtype; hal_logic_partition_t *tPartition; tPartition = &default_partitions[in_partition]; ret = hal_partition_to_esp_partition_type(in_partition, &type, &subtype); if (ret < 0) { return ret; } esp_partition = esp_partition_find_first(type, subtype, NULL); tPartition->partition_start_addr = esp_partition->address; tPartition->partition_length = esp_partition->size; *partition = tPartition; return 0; } int32_t aos_hal_flash_read(hal_partition_t id, uint32_t *offset, void *buffer, uint32_t buffer_len) { int ret; const esp_partition_t *esp_partition; esp_partition_type_t type; esp_partition_subtype_t subtype; ret = hal_partition_to_esp_partition_type(id, &type, &subtype); if (ret < 0) { return ret; } esp_partition = esp_partition_find_first(type, subtype, NULL); return esp_partition_read(esp_partition, *offset, buffer, buffer_len); } int32_t aos_hal_flash_write(hal_partition_t id, uint32_t *offset, const void *buffer, uint32_t buffer_len) { int ret; const esp_partition_t *esp_partition; esp_partition_type_t type; esp_partition_subtype_t subtype; ret = hal_partition_to_esp_partition_type(id, &type, &subtype); if (ret < 0) { return ret; } esp_partition = esp_partition_find_first(type, subtype, NULL); return esp_partition_write(esp_partition, *offset, buffer, buffer_len); } int32_t aos_hal_flash_erase(hal_partition_t id, uint32_t offset, uint32_t size) { int ret; const esp_partition_t *esp_partition; esp_partition_type_t type; esp_partition_subtype_t subtype; /* esp32 needs 4K align. */ if (size % 0x1000) { size = ((size + 0x1000 - 1) / 0x1000) * 0x1000; } ret = hal_partition_to_esp_partition_type(id, &type, &subtype); if (ret < 0) { return ret; } esp_partition = esp_partition_find_first(type, subtype, NULL); return esp_partition_erase_range(esp_partition, offset, size); }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/aos_hal_flash.c
C
apache-2.0
3,466
#include <errno.h> #include <driver/gpio.h> #include <aos_hal_gpio_internal.h> int32_t aos_hal_gpio_init(aos_hal_gpio_dev_t *gpio) { gpio_config_t config = { .intr_type = GPIO_INTR_DISABLE, }; if (!gpio) return -EINVAL; config.pin_bit_mask = (uint64_t)1 << gpio->port; switch (gpio->config) { case IRQ_MODE: config.mode = GPIO_MODE_INPUT; config.pull_up_en = GPIO_PULLUP_ENABLE; config.pull_down_en = GPIO_PULLDOWN_DISABLE; break; case INPUT_PULL_UP: config.mode = GPIO_MODE_INPUT; config.pull_up_en = GPIO_PULLUP_ENABLE; config.pull_down_en = GPIO_PULLDOWN_DISABLE; break; case INPUT_PULL_DOWN: config.mode = GPIO_MODE_INPUT; config.pull_up_en = GPIO_PULLUP_DISABLE; config.pull_down_en = GPIO_PULLDOWN_ENABLE; break; case INPUT_HIGH_IMPEDANCE: config.mode = GPIO_MODE_INPUT; config.pull_up_en = GPIO_PULLUP_DISABLE; config.pull_down_en = GPIO_PULLDOWN_DISABLE; break; case OUTPUT_PUSH_PULL: config.mode = GPIO_MODE_INPUT_OUTPUT; config.pull_up_en = GPIO_PULLUP_DISABLE; config.pull_down_en = GPIO_PULLDOWN_DISABLE; break; case OUTPUT_OPEN_DRAIN_NO_PULL: config.mode = GPIO_MODE_INPUT_OUTPUT_OD; config.pull_up_en = GPIO_PULLUP_DISABLE; config.pull_down_en = GPIO_PULLDOWN_DISABLE; break; case OUTPUT_OPEN_DRAIN_PULL_UP: config.mode = GPIO_MODE_INPUT_OUTPUT_OD; config.pull_up_en = GPIO_PULLUP_ENABLE; config.pull_down_en = GPIO_PULLDOWN_DISABLE; break; default: return -EINVAL; } if (gpio_config(&config) != ESP_OK) return -EINVAL; return 0; } int32_t aos_hal_gpio_finalize(aos_hal_gpio_dev_t *gpio) { return 0; } int32_t aos_hal_gpio_get(aos_hal_gpio_dev_t *gpio) { int r; if (!gpio) return -EINVAL; r = gpio_get_level(gpio->port); return (r >= 0) ? !!r : -EIO; } int32_t aos_hal_gpio_output_high(aos_hal_gpio_dev_t *gpio) { if (!gpio) return -EINVAL; gpio->level = 1; if (gpio_set_level(gpio->port, gpio->level) != ESP_OK) return -EIO; return 0; } int32_t aos_hal_gpio_output_low(aos_hal_gpio_dev_t *gpio) { if (!gpio) return -EINVAL; gpio->level = 0; if (gpio_set_level(gpio->port, gpio->level) != ESP_OK) return -EIO; return 0; } int32_t aos_hal_gpio_output_toggle(aos_hal_gpio_dev_t *gpio) { if (!gpio) return -EINVAL; gpio->level = gpio->level ? 0 : 1; if (gpio_set_level(gpio->port, gpio->level) != ESP_OK) return -EIO; return 0; } static void gpio_irq_handler(void *arg) { aos_hal_gpio_dev_t *gpio = (aos_hal_gpio_dev_t *)arg; gpio->irq_handler(0, gpio->irq_arg); } int32_t aos_hal_gpio_enable_irq(aos_hal_gpio_dev_t *gpio, aos_hal_gpio_irq_trigger_t trigger, aos_hal_gpio_irq_handler_t handler, void *arg) { gpio_int_type_t intr_type; if (!gpio || !handler) return -EINVAL; switch (trigger) { case IRQ_TRIGGER_RISING_EDGE: intr_type = GPIO_INTR_POSEDGE; break; case IRQ_TRIGGER_FALLING_EDGE: intr_type = GPIO_INTR_NEGEDGE; break; case IRQ_TRIGGER_BOTH_EDGES: intr_type = GPIO_INTR_ANYEDGE; break; case IRQ_TRIGGER_LEVEL_HIGH: intr_type = GPIO_INTR_HIGH_LEVEL; break; case IRQ_TRIGGER_LEVEL_LOW: intr_type = GPIO_INTR_LOW_LEVEL; break; default: return -EINVAL; } (void)gpio_intr_disable(gpio->port); (void)gpio_isr_handler_remove(gpio->port); gpio->irq_handler = handler; gpio->irq_arg = arg; if (gpio_isr_handler_add(gpio->port, gpio_irq_handler, gpio) != ESP_OK) return -EINVAL; if (gpio_set_intr_type(gpio->port, intr_type) != ESP_OK) return -EINVAL; if (gpio_intr_enable(gpio->port) != ESP_OK) return -EINVAL; return 0; } int32_t aos_hal_gpio_disable_irq(aos_hal_gpio_dev_t *gpio) { if (!gpio) return -EINVAL; if (gpio_intr_disable(gpio->port) != ESP_OK) return -EINVAL; if (gpio_isr_handler_remove(gpio->port) != ESP_OK) return -EINVAL; gpio->irq_handler = NULL; gpio->irq_arg = NULL; return 0; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/aos_hal_gpio.c
C
apache-2.0
4,362
#include <aos_hal_i2c_internal.h> #include <driver/i2c.h> #include <errno.h> #include "esp_log.h" #include "hal/i2c_ll.h" #define TAG "i2c" int32_t aos_hal_i2c_init(aos_hal_i2c_dev_t *i2c) { i2c_config_t config = { .sda_pullup_en = true, .scl_pullup_en = true, /* remove as not supported by IDF-V4.2 */ /* .clk_flags = 0, */ }; if (!i2c) return -EINVAL; switch (i2c->port) { case 0: #ifdef CONFIG_IDF_TARGET_ESP32 config.sda_io_num = 21; config.scl_io_num = 22; #elif CONFIG_IDF_TARGET_ESP32C3 config.scl_io_num = 4; config.sda_io_num = 5; #elif CONFIG_IDF_TARGET_ESP32S3 config.scl_io_num = 2; config.sda_io_num = 1; #endif break; case 1: #ifdef CONFIG_IDF_TARGET_ESP32 config.sda_io_num = 32; config.scl_io_num = 33; #endif break; default: return -EINVAL; } switch (i2c->config.address_width) { case I2C_HAL_ADDRESS_WIDTH_7BIT: break; default: return -EINVAL; } if (i2c->config.freq > 0 && i2c->config.freq <= 1000000) config.master.clk_speed = i2c->config.freq; else return -EINVAL; switch (i2c->config.mode) { case AOS_HAL_I2C_MODE_MASTER: config.mode = I2C_MODE_MASTER; break; default: return -EINVAL; } (void)i2c_driver_delete(i2c->port); if (i2c_param_config(i2c->port, &config) != ESP_OK) return -EINVAL; #if defined CONFIG_IDF_TARGET_ESP32 if (i2c_set_timeout(i2c->port, I2C_APB_CLK_FREQ / 1000000 * 10000) != ESP_OK) return -EINVAL; #elif defined CONFIG_IDF_TARGET_ESP32C3 if (i2c_set_timeout(i2c->port, I2C_LL_MAX_TIMEOUT) != ESP_OK) return -EINVAL; #endif if (i2c_driver_install(i2c->port, config.mode, 0, 0, 0) != ESP_OK) return -EINVAL; return 0; } int32_t aos_hal_i2c_finalize(aos_hal_i2c_dev_t *i2c) { if (!i2c) return -EINVAL; switch (i2c->port) { case 0: break; case 1: break; default: return -EINVAL; } if (i2c_driver_delete(i2c->port) != ESP_OK) return -EINVAL; return 0; } int32_t aos_hal_i2c_master_send(aos_hal_i2c_dev_t *i2c, uint16_t dev_addr, const uint8_t *data, uint16_t size, uint32_t timeout) { i2c_cmd_handle_t cmd; if (!i2c || !data || size == 0) return -EINVAL; cmd = i2c_cmd_link_create(); i2c_master_start(cmd); i2c_master_write_byte(cmd, (dev_addr << 1) | I2C_MASTER_WRITE, true); i2c_master_write(cmd, (uint8_t *)data, size, true); i2c_master_stop(cmd); if (i2c_master_cmd_begin(i2c->port, cmd, portMAX_DELAY)) { i2c_cmd_link_delete(cmd); return -EIO; } i2c_cmd_link_delete(cmd); return 0; } int32_t aos_hal_i2c_master_recv(aos_hal_i2c_dev_t *i2c, uint16_t dev_addr, uint8_t *data, uint16_t size, uint32_t timeout) { i2c_cmd_handle_t cmd; if (!i2c || !data || size == 0) return -EINVAL; cmd = i2c_cmd_link_create(); i2c_master_start(cmd); i2c_master_write_byte(cmd, (dev_addr << 1) | I2C_MASTER_READ, true); i2c_master_read(cmd, data, size, I2C_MASTER_LAST_NACK); i2c_master_stop(cmd); if (i2c_master_cmd_begin(i2c->port, cmd, pdMS_TO_TICKS(1000))) { i2c_cmd_link_delete(cmd); return -EIO; } i2c_cmd_link_delete(cmd); return 0; } typedef struct _hw_i2c_buf_t { size_t len; uint8_t *buf; } hw_i2c_buf_t; static size_t fill_memaddr_buf(uint8_t *memaddr_buf, uint32_t memaddr, uint8_t addrsize) { size_t memaddr_len = 0; if ((addrsize & 7) != 0 || addrsize > 32) { printf("invalid addrsize"); return -EINVAL; } for (int16_t i = addrsize - 8; i >= 0; i -= 8) { memaddr_buf[memaddr_len++] = memaddr >> i; } return memaddr_len; } static int i2c_hw_transfer(aos_hal_i2c_dev_t *i2c, uint16_t addr, size_t n, hw_i2c_buf_t *bufs, unsigned int flags, bool stop) { i2c_cmd_handle_t cmd = i2c_cmd_link_create(); i2c_master_start(cmd); i2c_master_write_byte(cmd, addr << 1 | (flags & I2C_MASTER_READ), true); int data_len = 0; for (; n--; ++bufs) { if (flags & I2C_MASTER_READ) { i2c_master_read(cmd, bufs->buf, bufs->len, n == 0 ? I2C_MASTER_LAST_NACK : I2C_MASTER_ACK); } else { if (bufs->len != 0) { i2c_master_write(cmd, bufs->buf, bufs->len, true); } } data_len += bufs->len; } if (stop) { i2c_master_stop(cmd); } // TODO proper timeout esp_err_t err = i2c_master_cmd_begin(i2c->port, cmd, 100 * (1 + data_len) / portTICK_RATE_MS); i2c_cmd_link_delete(cmd); if (err == ESP_FAIL) { return -ENODEV; } else if (err == ESP_ERR_TIMEOUT) { return -ETIMEDOUT; } else if (err != ESP_OK) { return -abs(err); } return data_len; } static int mp_machine_i2c_readfrom(aos_hal_i2c_dev_t *i2c, uint16_t addr, uint8_t *dest, size_t len, bool stop) { hw_i2c_buf_t buf = { .len = len, .buf = dest }; unsigned int flags = I2C_MASTER_READ; return i2c_hw_transfer(i2c, addr, 1, &buf, flags, stop); } static int mp_machine_i2c_writeto(aos_hal_i2c_dev_t *i2c, uint16_t addr, const uint8_t *src, size_t len, bool stop) { hw_i2c_buf_t buf = { .len = len, .buf = src }; return i2c_hw_transfer(i2c, addr, 1, &buf, 0, stop); } int32_t aos_hal_i2c_mem_read(aos_hal_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) { uint8_t memaddr_buf[4]; size_t memaddr_len = fill_memaddr_buf(&memaddr_buf[0], mem_addr, mem_addr_size); if (!i2c || !data || size == 0) return -EINVAL; int ret = mp_machine_i2c_writeto(i2c, dev_addr, memaddr_buf, memaddr_len, false); if (ret != memaddr_len) { // must generate STOP mp_machine_i2c_writeto(i2c, dev_addr, NULL, 0, true); return ret; } return mp_machine_i2c_readfrom(i2c, dev_addr, data, size, true); } int32_t aos_hal_i2c_mem_write(aos_hal_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) { // Create buffer with memory address uint8_t memaddr_buf[4]; size_t memaddr_len = fill_memaddr_buf(&memaddr_buf[0], mem_addr, mem_addr_size); if (!i2c || !data || size == 0) return -EINVAL; // Create partial write buffers hw_i2c_buf_t bufs[2] = { { .len = memaddr_len, .buf = memaddr_buf }, { .len = size, .buf = (uint8_t *)data }, }; return i2c_hw_transfer(i2c, dev_addr, 2, bufs, 0, true); } /* int32_t aos_hal_i2c_mem_write(aos_hal_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) { uint8_t addr[2]; size_t addr_len; i2c_cmd_handle_t cmd; if (!i2c || !data || size == 0) return -EINVAL; switch (mem_addr_size) { case I2C_MEM_ADDR_SIZE_8BIT: addr[0] = (uint8_t)mem_addr; addr_len = 1; break; case I2C_MEM_ADDR_SIZE_16BIT: addr[0] = (uint8_t)((mem_addr >> 8) & 0xFF); addr[1] = (uint8_t)((mem_addr >> 0) & 0xFF); addr_len = 2; break; default: return -EINVAL; } cmd = i2c_cmd_link_create(); i2c_master_start(cmd); i2c_master_write_byte(cmd, (dev_addr << 1) | I2C_MASTER_WRITE, true); i2c_master_write(cmd, addr, addr_len, true); i2c_master_write(cmd, (uint8_t *)data, size, true); i2c_master_stop(cmd); if (i2c_master_cmd_begin(i2c->port, cmd, portMAX_DELAY)) { i2c_cmd_link_delete(cmd); return -EIO; } i2c_cmd_link_delete(cmd); return 0; } int32_t aos_hal_i2c_mem_read(aos_hal_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) { uint8_t addr[2]; size_t addr_len; i2c_cmd_handle_t cmd; if (!i2c || !data || size == 0) return -EINVAL; switch (mem_addr_size) { case I2C_MEM_ADDR_SIZE_8BIT: addr[0] = (uint8_t)mem_addr; addr_len = 1; break; case I2C_MEM_ADDR_SIZE_16BIT: addr[0] = (uint8_t)((mem_addr >> 8) & 0xFF); addr[1] = (uint8_t)((mem_addr >> 0) & 0xFF); addr_len = 2; break; default: return -EINVAL; } cmd = i2c_cmd_link_create(); i2c_master_start(cmd); i2c_master_write_byte(cmd, (dev_addr << 1) | I2C_MASTER_WRITE, true); i2c_master_write(cmd, addr, addr_len, true); i2c_master_stop(cmd); if (i2c_master_cmd_begin(i2c->port, cmd, portMAX_DELAY)) { i2c_cmd_link_delete(cmd); return -EIO; } i2c_cmd_link_delete(cmd); cmd = i2c_cmd_link_create(); i2c_master_start(cmd); i2c_master_write_byte(cmd, (dev_addr << 1) | I2C_MASTER_READ, true); i2c_master_read(cmd, data, size, I2C_MASTER_LAST_NACK); i2c_master_stop(cmd); if (i2c_master_cmd_begin(i2c->port, cmd, pdMS_TO_TICKS(1000))) { i2c_cmd_link_delete(cmd); return -EIO; } i2c_cmd_link_delete(cmd); return 0; } */
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/aos_hal_i2c.c
C
apache-2.0
9,415
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "aos_hal_pwm.h" #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <sys/ioctl.h> #include <unistd.h> #include "driver/ledc.h" bool pwm_inited = false; int chan_gpio[LEDC_CHANNEL_MAX]; // Params for PW operation // 5khz #define PWFREQ (5000) // High speed mode #if SOC_LEDC_SUPPORT_HS_MODE #define PWMODE (LEDC_HIGH_SPEED_MODE) #else #define PWMODE (LEDC_LOW_SPEED_MODE) #endif // 13-bit resolution #define PWRES (LEDC_TIMER_13_BIT) // Timer 1 #define PWTIMER (LEDC_TIMER_1) ledc_timer_config_t timer_cfg = { .duty_resolution = PWRES, .freq_hz = PWFREQ, .speed_mode = PWMODE, .timer_num = PWTIMER, .clk_cfg = LEDC_USE_APB_CLK }; int32_t aos_hal_pwm_init(aos_hal_pwm_dev_t *pwm) { // init need set params pwm->active = 0; pwm->channel = -1; // init esp32 hw pwm if (!pwm_inited) { // Initial condition: no channels assigned for (int x = 0; x < LEDC_CHANNEL_MAX; ++x) { chan_gpio[x] = -1; } // Init with default timer params ledc_timer_config(&timer_cfg); pwm_inited = true; } int channel; int avail = -1; // Find a free PWM channel, also spot if our pin is // already mentioned. for (channel = 0; channel < LEDC_CHANNEL_MAX; ++channel) { if (chan_gpio[channel] == pwm->port) { break; } if ((avail == -1) && (chan_gpio[channel] == -1)) { avail = channel; } } if (channel >= LEDC_CHANNEL_MAX) { if (avail == -1) { printf("out of PWM channels\r\n"); } channel = avail; } pwm->channel = channel; pwm->active = 1; // New PWM assignment if (chan_gpio[channel] == -1) { ledc_channel_config_t cfg = { .channel = channel, .duty = (1 << timer_cfg.duty_resolution) / 2, .gpio_num = pwm->port, .intr_type = LEDC_INTR_DISABLE, .speed_mode = PWMODE, .timer_sel = PWTIMER, }; if (ledc_channel_config(&cfg) != ESP_OK) { printf("PWM not supported on pin %d\r\n", pwm->port); } chan_gpio[channel] = pwm->port; } return 0; } int32_t aos_hal_pwm_start(aos_hal_pwm_dev_t *pwm) { esp_err_t ret = 0; ret = ledc_update_duty(PWMODE, pwm->channel); return ret; } int32_t aos_hal_pwm_stop(aos_hal_pwm_dev_t *pwm) { esp_err_t ret = 0; int channel = pwm->channel; // Valid channel? if ((channel >= 0) && (channel < LEDC_CHANNEL_MAX)) { // Mark it unused, and tell the hardware to stop routing ret = ledc_stop(PWMODE, channel, 0); } return ret; } int32_t aos_hal_pwm_para_chg(aos_hal_pwm_dev_t *pwm, aos_hal_pwm_config_t para) { esp_err_t ret = 0; // set freq frist if (para.freq != timer_cfg.freq_hz) { int ores = timer_cfg.duty_resolution; int oval = timer_cfg.freq_hz; // Find the highest bit resolution for the requested frequency if (para.freq <= 0) { para.freq = 1; } unsigned int res = 0; for (unsigned int i = LEDC_APB_CLK_HZ / para.freq; i > 1; i >>= 1) { ++res; } if (res == 0) { res = 1; } else if (res > PWRES) { // Limit resolution to PWRES to match units of our duty res = PWRES; } // Configure the new resolution and frequency timer_cfg.duty_resolution = res; timer_cfg.freq_hz = para.freq; if (ledc_timer_config(&timer_cfg) != ESP_OK) { timer_cfg.duty_resolution = ores; timer_cfg.freq_hz = oval; return -1; } } // set duty // calc max duty value int max_duty = 0; max_duty = (1 << timer_cfg.duty_resolution); // calc customer duty value int duty = 0; duty = (int)(para.duty_cycle * max_duty / 100); // duty protect duty &= ((1 << PWRES) - 1); duty >>= PWRES - timer_cfg.duty_resolution; ret = ledc_set_duty(PWMODE, pwm->channel, duty); return ret; } int32_t aos_hal_pwm_finalize(aos_hal_pwm_dev_t *pwm) { esp_err_t ret = 0; int channel = pwm->channel; // Valid channel? if ((channel >= 0) && (channel < LEDC_CHANNEL_MAX)) { // Mark it unused, and tell the hardware to stop routing chan_gpio[channel] = -1; ret = ledc_stop(PWMODE, channel, 0); pwm->active = 0; pwm->channel = -1; gpio_matrix_out(pwm->port, SIG_GPIO_OUT_IDX, false, false); } return ret; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/aos_hal_pwm.c
C
apache-2.0
4,645
#include <aos_hal_spi_internal.h> #include <driver/spi_common.h> #include <driver/spi_master.h> #include <errno.h> #include <stdlib.h> #include "esp_log.h" #define TAG "SPI" #if defined CONFIG_IDF_TARGET_ESP32C3 #define PIN_NUM_MISO 2 #define PIN_NUM_MOSI 7 #define PIN_NUM_CLK 6 #define PIN_NUM_CS 10 #elif CONFIG_IDF_TARGET_ESP32S3 #define PIN_NUM_MISO 13 #define PIN_NUM_MOSI 11 #define PIN_NUM_CLK 12 #define PIN_NUM_CS 10 #endif typedef struct { spi_device_handle_t dev_handle; } spi_pdata_t; int32_t aos_hal_spi_init(aos_hal_spi_dev_t *spi) { spi_host_device_t host_id; spi_bus_config_t bus_config = { .quadwp_io_num = -1, .quadhd_io_num = -1, .max_transfer_sz = 1024, .flags = SPICOMMON_BUSFLAG_MASTER, .intr_flags = 0, }; spi_device_interface_config_t dev_config = { .command_bits = 0, .address_bits = 0, .dummy_bits = 0, .duty_cycle_pos = 0, .cs_ena_pretrans = 0, .cs_ena_posttrans = 0, .input_delay_ns = 0, .flags = SPI_DEVICE_HALFDUPLEX, .queue_size = 1, .pre_cb = NULL, .post_cb = NULL, }; if (!spi) return -EINVAL; switch (spi->port) { case 2: #if defined CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 host_id = SPI2_HOST; bus_config.mosi_io_num = PIN_NUM_MOSI; bus_config.sclk_io_num = PIN_NUM_CLK; bus_config.miso_io_num = PIN_NUM_MISO; dev_config.spics_io_num = PIN_NUM_CS; #endif break; case 3: host_id = SPI3_HOST; bus_config.mosi_io_num = 23; bus_config.sclk_io_num = 18; #ifdef BOARD_M5STACKCORE2 bus_config.miso_io_num = 38; dev_config.spics_io_num = 25; #else bus_config.miso_io_num = 19; dev_config.spics_io_num = 5; #endif break; default: return -EINVAL; } switch (spi->config.role) { case SPI_ROLE_MASTER: break; default: return -EINVAL; } switch (spi->config.firstbit) { case SPI_FIRSTBIT_MSB: break; case SPI_FIRSTBIT_LSB: dev_config.flags |= SPI_DEVICE_BIT_LSBFIRST; break; default: return -EINVAL; } switch (spi->config.mode) { case SPI_WORK_MODE_0: dev_config.mode = 0; break; case SPI_WORK_MODE_1: dev_config.mode = 1; break; case SPI_WORK_MODE_2: dev_config.mode = 2; break; case SPI_WORK_MODE_3: dev_config.mode = 3; break; default: return -EINVAL; } switch (spi->config.t_mode) { case SPI_TRANSFER_DMA: break; case SPI_TRANSFER_NORMAL: break; default: return -EINVAL; } dev_config.clock_speed_hz = spi->config.freq; switch (spi->config.data_size) { case SPI_DATA_SIZE_8BIT: break; default: return -EINVAL; } switch (spi->config.cs) { case SPI_CS_DIS: break; case SPI_CS_EN: break; default: return -EINVAL; } spi->priv = malloc(sizeof(spi_pdata_t)); if (!spi->priv) return -ENOMEM; /* Change SPI_DMA_CH_AUTO to 0 as no supported by IDF-V4.2 */ if (spi_bus_initialize(host_id, &bus_config, 0) != ESP_OK) { free(spi->priv); spi->priv = NULL; return -EINVAL; } if (spi_bus_add_device(host_id, &dev_config, &((spi_pdata_t *)spi->priv)->dev_handle) != ESP_OK) { (void)spi_bus_free(host_id); free(spi->priv); spi->priv = NULL; return -EINVAL; } return 0; } int32_t aos_hal_spi_finalize(aos_hal_spi_dev_t *spi) { spi_host_device_t host_id; if (!spi || !spi->priv) return -EINVAL; switch (spi->port) { case 2: #if defined CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 host_id = SPI2_HOST; #endif break; case 3: host_id = SPI3_HOST; break; default: return -EINVAL; } (void)spi_bus_remove_device(((spi_pdata_t *)spi->priv)->dev_handle); (void)spi_bus_free(host_id); free(spi->priv); spi->priv = NULL; return 0; } int32_t aos_hal_spi_send(aos_hal_spi_dev_t *spi, const uint8_t *data, uint32_t size, uint32_t timeout) { spi_transaction_t trans_desc = { 0 }; if (!spi || !spi->priv || !data || size == 0) return -EINVAL; trans_desc.length = size * 8; trans_desc.tx_buffer = data; if (spi_device_transmit(((spi_pdata_t *)spi->priv)->dev_handle, &trans_desc) != ESP_OK) return -EIO; return 0; } int32_t aos_hal_spi_recv(aos_hal_spi_dev_t *spi, uint8_t *data, uint32_t size, uint32_t timeout) { spi_transaction_t trans_desc = { 0 }; if (!spi || !spi->priv || !data || size == 0) return -EINVAL; trans_desc.rxlength = size * 8; trans_desc.rx_buffer = data; if (spi_device_transmit(((spi_pdata_t *)spi->priv)->dev_handle, &trans_desc) != ESP_OK) return -EIO; return 0; } int32_t aos_hal_spi_sends_recvs(aos_hal_spi_dev_t *spi, uint8_t *tx_data, uint32_t tx_size, uint8_t *rx_data, uint32_t rx_size, uint32_t timeout) { if (!spi || !spi->priv || !tx_data || rx_size == 0 || !rx_data || rx_size == 0) { return -EINVAL; } spi_transaction_t trans_desc = { 0 }; trans_desc.length = tx_size * 8; trans_desc.tx_buffer = tx_data; trans_desc.rxlength = rx_size * 8; trans_desc.rx_buffer = rx_data; esp_err_t ret = spi_device_transmit(((spi_pdata_t *)spi->priv)->dev_handle, &trans_desc); if (ret != ESP_OK) { return -ret; } return 0; } int32_t aos_hal_spi_send_recv(aos_hal_spi_dev_t *spi, uint8_t *tx_data, uint8_t *rx_data, uint32_t rx_size, uint32_t timeout) { return aos_hal_spi_sends_recvs(spi, tx_data, 1, rx_data, rx_size, timeout); } int32_t aos_hal_spi_send_and_recv(aos_hal_spi_dev_t *spi, uint8_t *tx_data, uint16_t tx_size, uint8_t *rx_data, uint16_t rx_size, uint32_t timeout) { return -ENOTSUP; /* if (!spi || !spi->priv || !tx_data || !rx_data || rx_size == 0) return -EINVAL; spi_device_handle_t dev_handle = ((spi_pdata_t *)spi->priv)->dev_handle; int bits_to_send = tx_size * 8; if (tx_size <= 4) { spi_transaction_t transaction; memset(&transaction, 0, sizeof(spi_transaction_t)); if (tx_data != NULL) { memcpy(&transaction.tx_data, tx_data, tx_size); } transaction.flags = SPI_TRANS_USE_TXDATA | SPI_TRANS_USE_RXDATA; transaction.length = bits_to_send; spi_device_transmit(dev_handle, &transaction); if (rx_data != NULL) { memcpy(rx_data, transaction.rx_data, rx_size); } } else { int offset = 0; int bits_remaining = bits_to_send; int max_transaction_bits = 1024 * 8; spi_transaction_t *transaction, *result, transactions[2]; int i = 0; spi_device_acquire_bus(dev_handle, portMAX_DELAY); while (bits_remaining) { transaction = transactions + i++ % 2; memset(transaction, 0, sizeof(spi_transaction_t)); transaction->length = bits_remaining > max_transaction_bits ? max_transaction_bits : bits_remaining; if (tx_data != NULL) { transaction->tx_buffer = tx_data + offset; } if (rx_data != NULL) { transaction->rx_buffer = rx_data + offset; } spi_device_queue_trans(dev_handle, transaction, portMAX_DELAY); bits_remaining -= transaction->length; if (offset > 0) { // wait for previously queued transaction spi_device_get_trans_result(dev_handle, &result, portMAX_DELAY); } // doesn't need ceil(); loop ends when bits_remaining is 0 offset += transaction->length / 8; } // wait for last transaction spi_device_get_trans_result(dev_handle, &result, portMAX_DELAY); spi_device_release_bus(dev_handle); } return 0; */ }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/aos_hal_spi.c
C
apache-2.0
8,233
#include "esp_system.h" void aos_hal_reboot(void) { esp_restart(); } char g_chip_id[32]; const char *aos_get_device_name(void) { uint8_t mac[32] = {0}; extern esp_err_t esp_read_mac(uint8_t *mac, esp_mac_type_t type); esp_read_mac(mac, ESP_MAC_WIFI_STA); memset(g_chip_id, 0, 32); snprintf(g_chip_id, 32, "haas_%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); return g_chip_id; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/aos_hal_system.c
C
apache-2.0
438
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include "aos_hal_timer_internal.h" #include "driver/timer.h" #include "hal/timer_ll.h" #define TIMER_INTR_SEL TIMER_INTR_LEVEL #define TIMER_DIVIDER 8 // TIMER_BASE_CLK is normally 80MHz. TIMER_DIVIDER ought to divide this exactly #define TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER) #define TIMER_FLAGS 0 void aos_hal_timer_isr(void *tim) { aos_hal_timer_dev_t *tim_isr = tim; // calc group & index uint8_t group = ((tim_isr->port) >> 1) & 1; uint8_t index = (tim_isr->port) & 1; timg_dev_t *device = group ? &(TIMERG1) : &(TIMERG0); #if CONFIG_IDF_TARGET_ESP32 device->hw_timer[index].update = 1; #elif CONFIG_IDF_TARGET_ESP32S2 device->hw_timer[index].update.update = 1; #endif timer_ll_clear_intr_status(device, index); timer_ll_set_alarm_enable(device, index, tim_isr->config.reload_mode); tim_isr->config.cb(tim_isr->config.arg); } int32_t aos_hal_timer_init_internel(aos_hal_timer_dev_t *tim) { esp_err_t ret = 0; uint64_t set_period = 0; timer_config_t config; config.alarm_en = TIMER_ALARM_EN; config.auto_reload = tim->config.reload_mode; config.counter_dir = TIMER_COUNT_UP; config.divider = TIMER_DIVIDER; config.intr_type = TIMER_INTR_LEVEL; config.counter_en = TIMER_PAUSE; // calc group & index uint8_t group = ((tim->port) >> 1) & 1; uint8_t index = (tim->port) & 1; // calc period time set_period = (tim->config.period) / 1000UL; set_period = (((uint64_t)(set_period)) * TIMER_SCALE) / 1000UL; ret = timer_init(group, index, &config); ret = timer_set_counter_value(group, index, 0x00000000); ret = timer_set_alarm_value(group, index, set_period); ret = timer_enable_intr(group, index); ret = timer_isr_register(group, index, aos_hal_timer_isr, (void *)tim, TIMER_FLAGS, (timer_isr_handle_t *)&tim->config.handle); return ret; } int32_t aos_hal_timer_init(aos_hal_timer_dev_t *tim) { esp_err_t ret = 0; return ret; } int32_t aos_hal_timer_start(aos_hal_timer_dev_t *tim) { esp_err_t ret = 0; // calc group & index uint8_t group = ((tim->port) >> 1) & 1; uint8_t index = (tim->port) & 1; // reset timer aos_hal_timer_stop(tim); ret = aos_hal_timer_init_internel(tim); // start timer ret = timer_start(group, index); return ret; } void aos_hal_timer_stop(aos_hal_timer_dev_t *tim) { // calc group & index uint8_t group = ((tim->port) >> 1) & 1; uint8_t index = (tim->port) & 1; if (tim->config.handle) { timer_pause(group, index); timer_disable_intr(group, index); esp_intr_free(tim->config.handle); tim->config.handle = NULL; } } int32_t aos_hal_timer_reload(aos_hal_timer_dev_t *tim) { esp_err_t ret = 0; aos_hal_timer_stop(tim); ret = aos_hal_timer_init_internel(tim); ret = aos_hal_timer_start(tim); return ret; } int32_t aos_hal_timer_para_chg(aos_hal_timer_dev_t *tim, aos_hal_timer_config_t para) { esp_err_t ret = 0; aos_hal_timer_stop(tim); // change tim config params tim->config.arg = para.arg; tim->config.period = para.period; tim->config.reload_mode = para.reload_mode; // reset timer ret = aos_hal_timer_init_internel(tim); ret = aos_hal_timer_start(tim); return ret; } int32_t aos_hal_timer_finalize(aos_hal_timer_dev_t *tim) { int32_t ret = 0; return ret; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/aos_hal_timer.c
C
apache-2.0
3,575
#include <errno.h> #include <driver/uart_select.h> #include <aos_hal_uart_internal.h> #include "esp_log.h" #include <soc/uart_caps.h> #if defined CONFIG_IDF_TARGET_ESP32C3 #define GPIO_UART_TXD_OUT (9) #define GPIO_UART_RXD_IN (3) #elif defined CONFIG_IDF_TARGET_ESP32S3 #define GPIO_UART_TXD_OUT (41) #define GPIO_UART_RXD_IN (42) #endif int32_t aos_hal_uart_init(aos_hal_uart_dev_t *uart) { uart_config_t config = { .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .rx_flow_ctrl_thresh = 0, /* .source_clk = UART_SCLK_APB, */ }; int tx_io_num; int rx_io_num; if (!uart) return -EINVAL; switch (uart->port) { case 0: tx_io_num = 1; rx_io_num = 3; break; case 1: #if defined CONFIG_IDF_TARGET_ESP32 tx_io_num = 10; rx_io_num = 9; #elif defined CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 tx_io_num = GPIO_UART_TXD_OUT; rx_io_num = GPIO_UART_RXD_IN; #endif break; #if SOC_UART_NUM > 2 case 2: #ifdef BOARD_M5STACKCORE2 tx_io_num = 14; rx_io_num = 13; #else tx_io_num = 17; rx_io_num = 16; #endif break; #endif default: return -EINVAL; } config.baud_rate = uart->config.baud_rate; switch (uart->config.data_width) { case DATA_WIDTH_5BIT: config.data_bits = UART_DATA_5_BITS; break; case DATA_WIDTH_6BIT: config.data_bits = UART_DATA_6_BITS; break; case DATA_WIDTH_7BIT: config.data_bits = UART_DATA_7_BITS; break; case DATA_WIDTH_8BIT: config.data_bits = UART_DATA_8_BITS; break; default: return -EINVAL; } switch (uart->config.stop_bits) { case STOP_BITS_1: config.stop_bits = UART_STOP_BITS_1; break; case STOP_BITS_2: config.stop_bits = UART_STOP_BITS_2; break; default: return -EINVAL; } switch (uart->config.parity) { case NO_PARITY: config.parity = UART_PARITY_DISABLE; break; case ODD_PARITY: config.parity = UART_PARITY_ODD; break; case EVEN_PARITY: config.parity = UART_PARITY_EVEN; break; default: return -EINVAL; } if (uart_is_driver_installed(uart->port)) { if (uart_set_baudrate(uart->port, config.baud_rate) != ESP_OK) return -EINVAL; if (uart_set_parity(uart->port, config.parity) != ESP_OK) return -EINVAL; if (uart_set_word_length(uart->port, config.data_bits) != ESP_OK) return -EINVAL; if (uart_set_stop_bits(uart->port, config.stop_bits) != ESP_OK) return -EINVAL; } else { if (uart_driver_install(uart->port, 256, 256, 0, NULL, 0) != ESP_OK) return -EINVAL; if (uart_set_pin(uart->port, tx_io_num, rx_io_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE) != ESP_OK) { (void)uart_driver_delete(uart->port); return -EINVAL; } if (uart_param_config(uart->port, &config) != ESP_OK) { (void)uart_driver_delete(uart->port); return -EINVAL; } } (void)uart_flush_input(uart->port); return 0; } int32_t aos_hal_uart_finalize(aos_hal_uart_dev_t *uart) { if (!uart) return -EINVAL; return 0; } int32_t aos_hal_uart_recv_II(aos_hal_uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t *recv_size, uint32_t timeout) { TickType_t ticks; int r; if (!uart || !data || expect_size == 0) return -EINVAL; if (timeout == 0) ticks = 0; else if (timeout == HAL_WAIT_FOREVER) ticks = portMAX_DELAY; else ticks = pdMS_TO_TICKS(timeout); r = uart_read_bytes(uart->port, data, expect_size, ticks); if (r < 0) return -EIO; if (recv_size) *recv_size = r; return 0; } int32_t aos_hal_uart_send(aos_hal_uart_dev_t *uart, const void *data, uint32_t size, uint32_t timeout) { int r; if (!uart || !data || size == 0) return -EINVAL; r = uart_write_bytes(uart->port, data, size); if (r < 0) return -EIO; return 0; } int32_t aos_hal_uart_any(aos_hal_uart_dev_t *uart) { int32_t rx_buf_size; uart_get_buffered_data_len(uart->port, &rx_buf_size); return rx_buf_size; } static struct aos_hal_uart_dev_t* uart_dev_table[UART_NUM_MAX] = {NULL}; static void select_notif_callback_isr(uart_port_t uart_num, uart_select_notif_t uart_select_notif, BaseType_t *task_woken) { size_t rx_data_len = 0; char data[256] = {0}; if (!uart_dev_table[uart_num]) return; aos_hal_uart_dev_t *uart_dev = uart_dev_table[uart_num]; switch (uart_select_notif) { case UART_SELECT_READ_NOTIF: memset(data, 0, sizeof(data)); rx_data_len = uart_read_bytes(uart_num, data, sizeof(data), 0); uart_dev->cb(uart_num, data, (uint16_t)rx_data_len, uart_dev->userdata); break; case UART_SELECT_WRITE_NOTIF: case UART_SELECT_ERROR_NOTIF: break; } } int32_t aos_hal_uart_callback(aos_hal_uart_dev_t *uart, void (*cb)(int, void *, uint16_t, void *), void *userdata) { if (uart->port < 0 || uart->port > UART_NUM_MAX - 1) { return -EINVAL; } uart->cb = cb; uart->userdata = userdata; uart_dev_table[uart->port] = uart; uart_set_select_notif_callback(uart->port, select_notif_callback_isr); return 0; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/aos_hal_uart.c
C
apache-2.0
5,519
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #include <stdint.h> #include <stdbool.h> #include <aos/errno.h> #include <aos_hal_wdg.h> #include <esp_task_wdt.h> #include <esp_err.h> static inline int32_t esp_err_to_std(esp_err_t error) { switch (error) { case ESP_OK: return 0; case ESP_FAIL: return -1; case ESP_ERR_NO_MEM: return -ENOMEM; case ESP_ERR_INVALID_ARG: return -EINVAL; case ESP_ERR_NOT_SUPPORTED: return -ENOSYS; case ESP_ERR_TIMEOUT: return -ETIMEDOUT; default: return -1; } } int32_t aos_hal_wdg_init(wdg_dev_t *wdg) { esp_err_t ret; if (wdg == NULL) return -EINVAL; /* Initialize TWDT */ ret = esp_err_to_std(esp_task_wdt_init(wdg->config.timeout, true)); if (ret < 0) return ret; /* Subscribe current task to the TWDT. */ ret = esp_err_to_std(esp_task_wdt_add(NULL)); if (ret < 0) return ret; ret = esp_err_to_std(esp_task_wdt_status(NULL)); return ret; } void aos_hal_wdg_reload(wdg_dev_t *wdg) { esp_err_t ret; ret = esp_task_wdt_reset(); if (ret != ESP_OK) printf("Error:%s:%d:ret:%d\n", __func__, __LINE__, ret); } int32_t aos_hal_wdg_finalize(wdg_dev_t *wdg) { esp_err_t ret; ret = esp_err_to_std(esp_task_wdt_delete(NULL)); if (ret < 0) return ret; ret = esp_err_to_std(esp_task_wdt_status(NULL)); if (ret != ESP_ERR_NOT_FOUND) return -1; /* Try to deinit, maybe fail if there is still task subscribes. */ esp_task_wdt_deinit(); return 0; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/aos_hal_wdg.c
C
apache-2.0
1,619
/* * Copyright (C) 2015-2019 Alibaba Group Holding Limited */ #include "aos/kv.h" #include "aos_system.h" #define MOD_STR "APP_MGR" static char app_version[32] = { 0 }; pthread_t system_reboot_thread; void system_reboot(void *argv) { usleep(1000 * 1000); esp_restart(); } int pyamp_app_upgrade(char *url) { char *key = "_amp_pyapp_url"; int32_t url_len = 0; int32_t ret = 0; url_len = strlen(url); ret = aos_kv_set(key, url, url_len, 1); if (ret != 0) { printf("%s:aos_kv_set failed\n", __func__); } ret = aos_task_new_ext(&system_reboot_thread, "system_reboot", system_reboot, NULL, 1024, AOS_DEFAULT_APP_PRI); if (ret < 0) { printf("pthread_create g_dynreg_dev_thread failed: %d", ret); return -1; } return ret; } int save_ssid_and_password(char *ssid, char *password) { char *key_ssid = "_amp_wifi_ssid"; char *key_passwd = "_amp_wifi_passwd"; int32_t ssid_len = 0; int32_t passwd_len = 0; int32_t ret = 0; ssid_len = strlen(ssid); passwd_len = strlen(password); if (ssid_len > 0 && passwd_len > 0) { ret = aos_kv_set(key_ssid, ssid, ssid_len, 1); if (ret != 0) { printf("%s:aos_kv_set failed,key is %s, value is %s, len is %d\n", __func__, key_ssid, ssid, ssid_len); return ret; } ret = aos_kv_set(key_passwd, password, passwd_len, 1); if (ret != 0) { printf("%s:aos_kv_set failed,key is %s, value is, len is %d\n", __func__, key_passwd, password, passwd_len); return ret; } } } int check_channel_enable(void) { int ret = 0; char *key = "app_upgrade_channel"; char value[20] = {0}; int value_len = 20; ret = aos_kv_get(key, value, &value_len); if (ret != 0) return 0; if (strcmp(value, "bt") == 0) return 2; if (strcmp(value, "disable") == 0) return 1; return 0; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/esp_idf/peripheral/app_ota.c
C
apache-2.0
1,947
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef __AMP_BOARD_CONFIG_H__ #define __AMP_BOARD_CONFIG_H__ #define AMP_BOOT_UART_PORT 0 #define AMP_BOOT_UART_BAUDRATE 1500000UL #define AMP_REPL_UART_PORT 0 #define AMP_REPL_UART_BAUDRATE 1500000UL #define AMP_STATUS_IO 40 #define AMP_STATUS_IO_ON 1 #endif
YifuLiu/AliOS-Things
components/amp_adapter/platform/linux/amp_board_config.h
C
apache-2.0
355
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "amp_board_config.h" #define AMP_FS_ROOT_DIR "./test/" /* js engine low memory enabled */ // #define AMP_LOWMEMORY_ENABLE /* manager channel */ // #define AMP_NETWORK_ENABLE /* das(device security) service */ // #define AMP_DAS_ENABLED /* ntp service */ // #define AMP_NTP_ENABLED /* location service */ // #define AMP_LOCATION_SERVICE_ENABLED /* enable high-level jsapi */ #define JSE_HIGHLEVEL_JSAPI /* debug mode, use test pk and ps*/ #define AMP_DEBUG_MODE /* os */ #define JSE_CORE_ADDON_BUILDIN // #define JSE_CORE_ADDON_CHECKSUM #define JSE_CORE_ADDON_SYSTEM #define JSE_CORE_ADDON_FS #define JSE_CORE_ADDON_KV // #define JSE_CORE_ADDON_PM // #define JSE_CORE_ADDON_BATTERY // #define JSE_CORE_ADDON_CHARGER #define JSE_CORE_ADDON_SYSTIMER // #define JSE_CORE_ADDON_CRYPTO #define JSE_CORE_ADDON_INITJS /* periperal */ #define JSE_HW_ADDON_ADC // #define JSE_HW_ADDON_CAN #define JSE_HW_ADDON_DAC #define JSE_HW_ADDON_GPIO //#define JSE_HW_ADDON_IR #define JSE_HW_ADDON_I2C // #define JSE_HW_ADDON_SPI #define JSE_HW_ADDON_TIMER #define JSE_HW_ADDON_PWM #define JSE_HW_ADDON_ONEWIRE #define JSE_HW_ADDON_RTC #define JSE_HW_ADDON_UART #define JSE_HW_ADDON_WDG //#define JSE_HW_ADDON_LCD #define JSE_HW_ADDON_DS18B20 /* network */ // #define JSE_NET_ADDON_UDP // #define JSE_NET_ADDON_TCP #define JSE_NET_ADDON_MQTT #define JSE_NET_ADDON_HTTP // #define JSE_NET_ADDON_WIFI // #define JSE_NET_ADDON_CELLULAR // #define JSE_NET_ADDON_NETMGR /* advanced component */ #define JSE_ADVANCED_ADDON_AIOT_DEVICE #define JSE_ADVANCED_ADDON_AIOT_GATEWAY #define JSE_ADVANCED_ADDON_AUDIOPLAYER // #define JSE_ADVANCED_ADDON_TTS // #define JSE_ADVANCED_ADDON_LOCATION // #define JSE_ADVANCED_ADDON_KEYPAD // #define JSE_ADVANCED_ADDON_UND // #define JSE_ADVANCED_ADDON_OTA /* ui component */ #ifdef CONFIG_AMP_UI_SUPPORT #define JSE_ADVANCED_ADDON_UI #endif /* recovery switch & status led */ #define AMP_RECOVERY_ENABLE #define AMP_REPL_PROMPT "amp> " /* manager channel device info for porject */ #define AMP_INTERNAL_PRODUCTKEY_VALUE "" #define AMP_INTERNAL_PRODUCTSECRET_VALUE ""
YifuLiu/AliOS-Things
components/amp_adapter/platform/linux/amp_config.h
C
apache-2.0
2,179
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "stdio.h" #include <stdlib.h> #include <stdbool.h> #include <sys/socket.h> #include <fcntl.h> #include <unistd.h>
YifuLiu/AliOS-Things
components/amp_adapter/platform/linux/amp_platform.h
C
apache-2.0
189
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <dirent.h> #include "amp_config.h" #include "amp_platform.h" #include "aos_system.h" #include "aos_fs.h" #include "aos/vfs.h" int aos_fs_init(void) { return 0; } int aos_open(const char *path, int flags) { return open(path, flags, 0777); } int aos_close(int fd) { return close(fd); } off_t aos_lseek(int fd, off_t offset, int whence) { return lseek(fd, offset, whence); } ssize_t aos_read(int fd, void *buf, size_t nbytes) { return read(fd, buf, nbytes); } ssize_t aos_write(int fd, const void *buf, size_t nbytes) { return write(fd, buf, nbytes); } int aos_sync(int fd) { (void)fd; sync(); } int aos_rmdir(const char *path) { rmdir(path); } int aos_stat(const char *path, struct aos_stat *st) { int ret; struct stat info; ret = stat(path, &info); st->st_mode = info.st_mode; st->st_size = info.st_size; return ret; } int aos_statfs(const char *path, struct aos_statfs *buf) { int ret; struct aos_statfs info; ret = statfs(path, &info); buf->f_bsize = info.f_bsize; buf->f_blocks = info.f_blocks; buf->f_bavail = info.f_bavail; return ret; } int aos_unlink(const char *path) { int ret; ret = unlink(path); return ret; } int aos_remove(const char *path) { int ret; ret = remove(path); return ret; } aos_dir_t *aos_opendir(const char *path) { return opendir(path); } int aos_closedir(aos_dir_t *dir) { return closedir((DIR*)dir); } aos_dirent_t *aos_readdir(aos_dir_t *dir) { return readdir((DIR*)dir); } int aos_mkdir(const char *path) { return mkdir(path, 0x777); } int aos_rmdir_r(const char *path) { struct aos_stat s; int ret = -1; char *dir, *p; int path_len; DIR *pdir = NULL; struct dirent *entry = NULL; if (!path) return -EINVAL; path_len = strlen(path) + 1; dir = aos_malloc(path_len); if (dir == NULL) { return -1; } memcpy(dir, path, path_len); p = dir + strlen(dir) - 1; while ((*p == '/') && (p > dir)) { *p = '\0'; p--; } if (stat(dir, &s) || !S_ISDIR(s.st_mode)) { aos_printf("%s is neither existed nor a directory\n", dir); goto out; } pdir = opendir(dir); if (!pdir) { aos_printf("opendir %s failed - %s\n", dir, strerror(errno)); goto out; } ret = 0; while ((ret == 0) && (entry = (struct dirent *)aos_readdir(pdir))) { char fpath[128]; snprintf(fpath, 128, "%s/%s", dir, entry->d_name); ret = stat(fpath, &s); if (ret) { aos_printf("stat %s failed\n", fpath); break; } if (!strcmp(entry->d_name, ".")) continue; if (!strcmp(entry->d_name, "..")) continue; if (S_ISDIR(s.st_mode)) ret = aos_rmdir_r(fpath); else ret = unlink(fpath); } closedir(pdir); if (ret == 0) { ret = rmdir(dir); if (ret) aos_printf("rmdir %s failed\n", dir); } out: aos_free(dir); return ret; } int aos_fs_type(uint mode) { if (mode & S_IFDIR) { return 0; } else if (mode & S_IFREG) { return 1; } return -1; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/linux/aos_fs.c
C
apache-2.0
3,363
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <dirent.h> #include <string.h> #include "amp_config.h" #include "amp_platform.h" #include "aos_system.h" #include "aos/kv.h" #include <stdio.h> #include <sys/stat.h> #define LEN 128 char tmp_key[LEN] = {0}; char tmp_val[LEN] = {0}; int aos_kv_set(const char *key, const void *value, int len, int sync) { printf("[key] %s [value] %s [len] %d\r\n", key, (char *)value, len); FILE *fp = fopen(key, "wb"); if (fp == NULL) { return -1; } fwrite(value, 1, len, fp); fclose(fp); return 0; } int aos_kv_get(const char *key, void *buffer, int *buffer_len) { FILE *fp = fopen(key, "rb"); if (fp == NULL) { return -1; } fread(buffer, *buffer_len, 1, fp); fclose(fp); return 0; } int aos_kv_del(const char *key) { remove(key); return 0; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/linux/aos_kv.c
C
apache-2.0
903
#include "amp_config.h" #include "aos_system.h" #include "amp_defines.h" #include "ota_agent.h" #include "ota_import.h" #include "app_upgrade.h" void app_js_stop() { } int ota_install_jsapp(void *ota_ctx, char *store_file, int store_file_len, char *install_path) { return 0; } int ota_verify_fsfile(ota_boot_param_t *param, char *file_path) { return 0; } int ota_download_store_fs_start(char *url, unsigned int url_len, char *store_path, report_func report_func, void *user_param) { return 0; } int ota_report_module_version(void *ota_ctx, char *module_name, char *version) { return 0; } int amp_app_version_get(char *version) { return 0; } void internal_sys_upgrade_start(void *ctx) { } int ota_read_parameter(ota_boot_param_t *ota_param) { return 0; } void ota_service_param_reset(ota_service_t *ctx) { } int ota_register_module_store(ota_service_t *ctx, ota_store_module_info_t *queue, int queue_len) { return 0; } typedef int32_t (*cbb)(void *pctx, char *ver, char *module_name, void *args); int ota_register_trigger_msg_cb(ota_service_t *ctx, void *cb, void *param) { ((cbb)cb)(1,"1", "js", param); return 0; } int ota_set_module_information(ota_service_t *ctx, char *module_name, char *store_path, int module_type) { return 0; } int ota_service_init(ota_service_t *ctx) { return 0; } const char *amp_jsapp_version_get(void) { return "0.0.1"; } int ota_transport_inform(void *mqttclient, char *pk, char *dn, char *module_name, char *ver) { return 0; }
YifuLiu/AliOS-Things
components/amp_adapter/platform/linux/aos_ota.c
C
apache-2.0
1,573