mirror of
https://github.com/sengeiou/realtek_ameba_mp_sdk.git
synced 2026-07-08 12:35:43 +00:00
ameba micropython sdk first commit
This commit is contained in:
commit
8508ee6139
5619 changed files with 1874619 additions and 0 deletions
145
sdk/component/common/utilities/cJSON.h
Normal file
145
sdk/component/common/utilities/cJSON.h
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
Copyright (c) 2009 Dave Gamble
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef cJSON__h
|
||||
#define cJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* cJSON Types: */
|
||||
#define cJSON_False 0
|
||||
#define cJSON_True 1
|
||||
#define cJSON_NULL 2
|
||||
#define cJSON_Number 3
|
||||
#define cJSON_String 4
|
||||
#define cJSON_Array 5
|
||||
#define cJSON_Object 6
|
||||
|
||||
#define cJSON_IsReference 256
|
||||
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON {
|
||||
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
|
||||
int type; /* The type of the item, as above. */
|
||||
|
||||
char *valuestring; /* The item's string, if type==cJSON_String */
|
||||
int valueint; /* The item's number, if type==cJSON_Number */
|
||||
double valuedouble; /* The item's number, if type==cJSON_Number */
|
||||
|
||||
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
} cJSON;
|
||||
|
||||
typedef struct cJSON_Hooks {
|
||||
void *(*malloc_fn)(size_t sz);
|
||||
void (*free_fn)(void *ptr);
|
||||
} cJSON_Hooks;
|
||||
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
extern void cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||
|
||||
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
|
||||
extern cJSON *cJSON_Parse(const char *value);
|
||||
/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
|
||||
extern char *cJSON_Print(cJSON *item);
|
||||
/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
|
||||
extern char *cJSON_PrintUnformatted(cJSON *item);
|
||||
/* Delete a cJSON entity and all subentities. */
|
||||
extern void cJSON_Delete(cJSON *c);
|
||||
|
||||
/* Returns the number of items in an array (or object). */
|
||||
extern int cJSON_GetArraySize(cJSON *array);
|
||||
/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
|
||||
extern cJSON *cJSON_GetArrayItem(cJSON *array,int item);
|
||||
/* Get item "string" from object. Case insensitive. */
|
||||
extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
|
||||
|
||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
extern const char *cJSON_GetErrorPtr(void);
|
||||
|
||||
/* These calls create a cJSON item of the appropriate type. */
|
||||
extern cJSON *cJSON_CreateNull(void);
|
||||
extern cJSON *cJSON_CreateTrue(void);
|
||||
extern cJSON *cJSON_CreateFalse(void);
|
||||
extern cJSON *cJSON_CreateBool(int b);
|
||||
extern cJSON *cJSON_CreateNumber(double num);
|
||||
extern cJSON *cJSON_CreateString(const char *string);
|
||||
extern cJSON *cJSON_CreateArray(void);
|
||||
extern cJSON *cJSON_CreateObject(void);
|
||||
|
||||
/* These utilities create an Array of count items. */
|
||||
extern cJSON *cJSON_CreateIntArray(const int *numbers,int count);
|
||||
extern cJSON *cJSON_CreateFloatArray(const float *numbers,int count);
|
||||
extern cJSON *cJSON_CreateDoubleArray(const double *numbers,int count);
|
||||
extern cJSON *cJSON_CreateStringArray(const char **strings,int count);
|
||||
|
||||
/* Append item to the specified array/object. */
|
||||
extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||
extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
|
||||
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
||||
extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
||||
extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
|
||||
|
||||
/* Remove/Detatch items from Arrays/Objects. */
|
||||
extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
|
||||
extern void cJSON_DeleteItemFromArray(cJSON *array,int which);
|
||||
extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
|
||||
extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
|
||||
|
||||
/* Update array items. */
|
||||
extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
|
||||
extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
||||
|
||||
/* Duplicate a cJSON item */
|
||||
extern cJSON *cJSON_Duplicate(cJSON *item,int recurse);
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
|
||||
need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
||||
The item->next and ->prev pointers are always zero on return from Duplicate. */
|
||||
|
||||
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||
extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated);
|
||||
|
||||
extern void cJSON_Minify(char *json);
|
||||
|
||||
/* Macros for creating things quickly. */
|
||||
#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
|
||||
#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
|
||||
#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
|
||||
#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
|
||||
#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
|
||||
#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
|
||||
|
||||
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
||||
#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
10
sdk/component/common/utilities/http_client.h
Normal file
10
sdk/component/common/utilities/http_client.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef _HTTP_H_
|
||||
#define _HTTP_H_
|
||||
|
||||
char *http_post_header(char *address, char *resource, char *type, int data_len);
|
||||
char *http_get_header(char *address, char *resource);
|
||||
char *http_response_header(char *buf, int response_len);
|
||||
char *http_response_body(char *buf, int response_len);
|
||||
void http_free(void *buf);
|
||||
|
||||
#endif
|
||||
55
sdk/component/common/utilities/uart_socket.h
Normal file
55
sdk/component/common/utilities/uart_socket.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#ifndef __UART_SOCKET_H_
|
||||
#define __UART_SOCKET_H_
|
||||
|
||||
//#include "osdep_api.h"
|
||||
#include "osdep_service.h"
|
||||
|
||||
#include "serial_api.h"
|
||||
#include "serial_ex_api.h"
|
||||
|
||||
#define UART_SEND_BUFFER_LEN 512
|
||||
#define UART_RECV_BUFFER_LEN 1024
|
||||
#define UART_MAX_DELAY_TIME 20
|
||||
|
||||
typedef struct _uart_set_str
|
||||
{
|
||||
char UartName[8]; // the name of uart
|
||||
int BaudRate; //The baud rate
|
||||
char number; //The number of data bits
|
||||
char parity; //The parity(default NONE)
|
||||
char StopBits; //The number of stop bits
|
||||
char FlowControl; //support flow control is 1
|
||||
}uart_set_str;
|
||||
|
||||
typedef struct _uart_socket_t
|
||||
{
|
||||
serial_t sobj;
|
||||
int fd;
|
||||
|
||||
/* Used for UART RX */
|
||||
u32 rx_start;
|
||||
//u32 rx_bytes;
|
||||
u32 prxread;
|
||||
u32 prxwrite;
|
||||
u32 rxoverlap;
|
||||
u32 last_update; //tick count when rx byte
|
||||
u8 recv_buf[UART_RECV_BUFFER_LEN];
|
||||
|
||||
u32 tx_start;
|
||||
u32 tx_bytes;
|
||||
u8 send_buf[UART_SEND_BUFFER_LEN];
|
||||
//_Sema tx_sema;
|
||||
//_Sema dma_tx_sema;
|
||||
_sema tx_sema;
|
||||
_sema dma_tx_sema;
|
||||
|
||||
//_Sema action_sema;
|
||||
_sema action_sema;
|
||||
}uart_socket_t;
|
||||
|
||||
uart_socket_t* uart_open(uart_set_str *puartpara);
|
||||
int uart_close(uart_socket_t *u);
|
||||
int uart_read(uart_socket_t *u, void *read_buf, size_t size);
|
||||
int uart_write(uart_socket_t *u, void *pbuf, size_t size);
|
||||
|
||||
#endif //__UART_SOCKET_H_
|
||||
94
sdk/component/common/utilities/uart_ymodem.h
Normal file
94
sdk/component/common/utilities/uart_ymodem.h
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/****************************************uart_ymodem.h**************************************************/
|
||||
|
||||
#ifndef __YMODEM_H_
|
||||
#define __YMODEM_H_
|
||||
|
||||
//#include "osdep_api.h"
|
||||
#include "osdep_service.h"
|
||||
#include "serial_api.h"
|
||||
#include "flash_api.h"
|
||||
#include "device_lock.h"
|
||||
/***********************************************************************
|
||||
* Macros *
|
||||
***********************************************************************/
|
||||
#if defined(CONFIG_PLATFORM_8711B)
|
||||
// 8710B
|
||||
#define UART_TX PA_23
|
||||
#define UART_RX PA_18
|
||||
#else
|
||||
// 8711AM
|
||||
#define UART_TX PA_7
|
||||
#define UART_RX PA_6
|
||||
//8711AF
|
||||
//#define UART_TX PA_4
|
||||
//#define UART_RX PA_0
|
||||
#endif
|
||||
|
||||
#define UART_BAUDRATE 115200
|
||||
#define UART_YMODEM_TASK_PRIORITY 5
|
||||
#define UART_YMODEM_TASK_DEPTH 512
|
||||
|
||||
#define CONFIG_CALC_FILE_SIZE 1
|
||||
#define CRC_CHECK 1
|
||||
#define AUTO_REBOOT 0
|
||||
#define DUMP_DATA 0
|
||||
|
||||
#define OFFSET_DATA FLASH_SYSTEM_DATA_ADDR
|
||||
#define IMAGE_TWO (0x80000)
|
||||
//Y-modem related
|
||||
#define MODEM_MAX_RETRIES 1
|
||||
#define MODEM_CRC_RETRIES 51
|
||||
#define MODEM_CAN_COUNT 3
|
||||
#define MODEM_EOT_COUNT 1
|
||||
|
||||
// ymodem protocol definition
|
||||
#define MODEM_SOH 0x01
|
||||
#define MODEM_STX 0x02
|
||||
#define MODEM_EOT 0x04
|
||||
#define MODEM_ACK 0x06
|
||||
#define MODEM_NAK 0x15
|
||||
#define MODEM_CAN 0x18
|
||||
#define MODEM_C 0x43
|
||||
// 1 block size byte + 2 block number bytes + 1024 data body + 2 crc bytes
|
||||
#define RCV_BUF_SIZE ((1)+(2)+(1024)+(2))
|
||||
/******************************** data struct **********************************/
|
||||
typedef struct _uart_ymodem_t
|
||||
{
|
||||
serial_t sobj;
|
||||
flash_t flash;
|
||||
|
||||
/* Used for UART RX */
|
||||
u8 uart_rcv_buf[RCV_BUF_SIZE];
|
||||
u8 uart_irq_buf[RCV_BUF_SIZE];
|
||||
//_Sema uart_rx_sema;
|
||||
_sema uart_rx_sema;
|
||||
u32 image_address;
|
||||
|
||||
u32 tick_last_update;
|
||||
u32 tick_current;
|
||||
u32 uart_recv_index;
|
||||
u32 uart_recv_buf_index;
|
||||
/* uart ymodem related*/
|
||||
u32 modemtype;
|
||||
u32 crc_mode;
|
||||
u32 nxt_num; //next block num
|
||||
u32 cur_num; //current block num
|
||||
u32 len;
|
||||
u32 rec_err; //blcok data recv status
|
||||
u32 filelen; //Ymodem file length
|
||||
u8 *buf; //data buf
|
||||
u8 *filename; //file name
|
||||
}uart_ymodem_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
extern int uart_ymodem(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
11
sdk/component/common/utilities/update.h
Normal file
11
sdk/component/common/utilities/update.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef UPDATE_H
|
||||
#define UPDATE_H
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
int update_ota_local(char *ip, int port);
|
||||
int update_ota_cloud(char *repository, char *file_path);
|
||||
void cmd_update(int argc, char **argv);
|
||||
void cmd_ota_image(bool cmd);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
#endif
|
||||
71
sdk/component/common/utilities/webserver.h
Normal file
71
sdk/component/common/utilities/webserver.h
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
FreeRTOS V6.0.4 - Copyright (C) 2010 Real Time Engineers Ltd.
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* If you are: *
|
||||
* *
|
||||
* + New to FreeRTOS, *
|
||||
* + Wanting to learn FreeRTOS or multitasking in general quickly *
|
||||
* + Looking for basic training, *
|
||||
* + Wanting to improve your FreeRTOS skills and productivity *
|
||||
* *
|
||||
* then take a look at the FreeRTOS eBook *
|
||||
* *
|
||||
* "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
|
||||
* http://www.FreeRTOS.org/Documentation *
|
||||
* *
|
||||
* A pdf reference manual is also available. Both are usually delivered *
|
||||
* to your inbox within 20 minutes to two hours when purchased between 8am *
|
||||
* and 8pm GMT (although please allow up to 24 hours in case of *
|
||||
* exceptional circumstances). Thank you for your support! *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
This file is part of the FreeRTOS distribution.
|
||||
|
||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License (version 2) as published by the
|
||||
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
||||
***NOTE*** The exception to the GPL is included to allow you to distribute
|
||||
a combined work that includes FreeRTOS without being obliged to provide the
|
||||
source code for proprietary components outside of the FreeRTOS kernel.
|
||||
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
more details. You should have received a copy of the GNU General Public
|
||||
License and the FreeRTOS license exception along with FreeRTOS; if not it
|
||||
can be viewed here: http://www.freertos.org/a00114.html and also obtained
|
||||
by writing to Richard Barry, contact details for whom are available on the
|
||||
FreeRTOS WEB site.
|
||||
|
||||
1 tab == 4 spaces!
|
||||
|
||||
http://www.FreeRTOS.org - Documentation, latest information, license and
|
||||
contact details.
|
||||
|
||||
http://www.SafeRTOS.com - A version that is certified for use in safety
|
||||
critical systems.
|
||||
|
||||
http://www.OpenRTOS.com - Commercial support, development, porting,
|
||||
licensing and training services.
|
||||
*/
|
||||
|
||||
#ifndef BASIC_WEB_SERVER_H
|
||||
#define BASIC_WEB_SERVER_H
|
||||
#include <wifi/wifi_conf.h>
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* MACROS */
|
||||
/*------------------------------------------------------------------------------*/
|
||||
#define basicwebWEBSERVER_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
||||
|
||||
#define lwipBASIC_SERVER_STACK_SIZE 256
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
|
||||
/* The function that implements the WEB server task. */
|
||||
extern void start_web_server(void);
|
||||
|
||||
#endif /*
|
||||
*/
|
||||
|
||||
43
sdk/component/common/utilities/xml.h
Normal file
43
sdk/component/common/utilities/xml.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef _XML_H_
|
||||
#define _XML_H_
|
||||
|
||||
struct xml_node {
|
||||
char *name;
|
||||
char *text;
|
||||
char *prefix;
|
||||
char *uri;
|
||||
char *attr;
|
||||
struct xml_node *parent;
|
||||
struct xml_node *child;
|
||||
struct xml_node *prev;
|
||||
struct xml_node *next;
|
||||
};
|
||||
|
||||
struct xml_node_set {
|
||||
int count;
|
||||
struct xml_node **node;
|
||||
};
|
||||
|
||||
void xml_free(void *buf);
|
||||
int xml_doc_name(char *doc_buf, int doc_len, char **doc_prefix, char **doc_name, char **doc_uri);
|
||||
struct xml_node *xml_parse_doc(char *doc_buf, int doc_len, char *prefix, char *doc_name, char *uri);
|
||||
struct xml_node *xml_parse(char *doc_buf, int doc_len);
|
||||
struct xml_node *xml_new_element(char *prefix, char *name, char *uri);
|
||||
struct xml_node *xml_new_text(char *text);
|
||||
int xml_is_element(struct xml_node *node);
|
||||
int xml_is_text(struct xml_node *node);
|
||||
struct xml_node* xml_copy_tree(struct xml_node *root);
|
||||
void xml_delete_tree(struct xml_node *root);
|
||||
void xml_add_child(struct xml_node *node, struct xml_node *child);
|
||||
void xml_clear_child(struct xml_node *node);
|
||||
struct xml_node* xml_text_child(struct xml_node *node);
|
||||
void xml_set_text(struct xml_node *node, char *text);
|
||||
struct xml_node_set* xml_find_element(struct xml_node *root, char *name);
|
||||
struct xml_node_set* xml_find_path(struct xml_node *root, char *path);
|
||||
void xml_delete_set(struct xml_node_set *node_set);
|
||||
char *xml_dump_tree(struct xml_node *root);
|
||||
char *xml_dump_tree_ex(struct xml_node *root, char *prolog, int new_line, int space);
|
||||
void xml_set_attribute(struct xml_node *node, char *attr, char *value);
|
||||
char *xml_get_attribute(struct xml_node *node, char *attr);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue