First commit

This commit is contained in:
anschrammh 2022-06-10 07:20:18 +02:00
parent 671e6583a9
commit a70a610579
2105 changed files with 954458 additions and 0 deletions

15
app/Makefile Normal file
View File

@ -0,0 +1,15 @@
TOP_DIR = ..
sinclude $(TOP_DIR)/tools/w800/conf.mk
ifndef PDIR
GEN_LIBS = libuser$(LIB_EXT)
endif
#DEFINES +=
sinclude $(TOP_DIR)/tools/w800/rules.mk
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

53
app/main.c Normal file
View File

@ -0,0 +1,53 @@
/*****************************************************************************
*
* File Name : main.c
*
* Description: main
*
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-6-14
*****************************************************************************/
#include "wm_include.h"
#include "nano_shell.h"
extern s16 uart0_rx_callback(u16 len, void *user_data);
#define NANO_SHELL_TASK_STK_SIZE 1024
#define STATUS_LED WM_IO_PB_18
void user_main(void)
{
//We create a task for the nano_shell process
u8 *nano_shell_task_stack = NULL;
tls_os_task_t nano_shell_task_handle = NULL;
tls_uart_rx_callback_register(TLS_UART_0, &(uart0_rx_callback), NULL);
nano_shell_task_stack = tls_mem_alloc(sizeof(u32) * NANO_SHELL_TASK_STK_SIZE);
if(nano_shell_task_stack != NULL)
{
tls_os_task_create(
&nano_shell_task_handle,
"na_shell",
&(nano_shell_loop),
NULL,
(void*) nano_shell_task_stack,
NANO_SHELL_TASK_STK_SIZE * sizeof(u32),
62,
0
);
}
tls_gpio_cfg(STATUS_LED, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
for(;;)
{
tls_gpio_write(STATUS_LED, !tls_gpio_read(STATUS_LED));
tls_os_time_delay(500);
}
}

78
app/nano_shell_command.c Normal file
View File

@ -0,0 +1,78 @@
#include <stdlib.h>
#include <string.h>
#include "command/command.h"
#include "wm_include.h"
extern int shell_printf(const char *format, ...);
int _task_list(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
tls_os_disp_task_stat_info();
return 0;
}
int _reset(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
tls_sys_reset();
return 0;
}
int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
if(argc > 1)
{
if(strcmp(argv[1], "state") == 0)
{
shell_printf("SOFT AP state : %u\n", tls_wifi_softap_get_state());
}
else if(strcmp(argv[1], "create") == 0)
{
struct tls_softap_info_t ap_info;
struct tls_ip_info_t ip_info;
tls_wifi_disconnect();
strncpy((char *)ap_info.ssid, argv[2], 32);
ap_info.ssid[32] = '\0';
ap_info.encrypt = IEEE80211_ENCRYT_TKIP_WPA2;
ap_info.channel = 5;
ap_info.keyinfo.format = 1;
ap_info.keyinfo.index = 1;
ap_info.keyinfo.key_len = strlen(argv[3]);
strncpy((char *)ap_info.keyinfo.key, argv[3], 63);
ip_info.ip_addr[0] = 192;
ip_info.ip_addr[1] = 168;
ip_info.ip_addr[2] = 1;
ip_info.ip_addr[3] = 1;
ip_info.netmask[0] = 255;
ip_info.netmask[1] = 255;
ip_info.netmask[2] = 255;
ip_info.netmask[3] = 0;
ip_info.dnsname[0] = '\0';
int result = tls_wifi_softap_create(&ap_info, &ip_info);
shell_printf("Create AP with SSID : %s, key(%d) : %s -> %d\n", ap_info.ssid, ap_info.keyinfo.key_len, ap_info.keyinfo.key, result);
}
}
else
{
shell_printf("Unknown SOFT AP command\n");
}
return 0;
}
NANO_SHELL_ADD_CMD(task_list,
_task_list,
"List all tasks",
" Use this command to list all defined tasks\r\n");
NANO_SHELL_ADD_CMD(reset,
_reset,
"Reset the system",
" Use this command reset the system\r\n");
NANO_SHELL_ADD_CMD(soft_ap,
_soft_ap,
"Command to control SOFT AP",
" Use this command to control the SOFT AP subsystem\r\n");

31
app/nano_shell_port.c Normal file
View File

@ -0,0 +1,31 @@
#include "wm_include.h"
#include "shell_io/static_fifo.h"
static_fifo_declare(uart0_char_fifo, 256, unsigned char, char);
extern int sendchar(int ch);
s16 uart0_rx_callback(u16 len, void *user_data)
{
u8 buff[256] = "";
int data_len = tls_uart_read(TLS_UART_0, (u8 *) buff, 256);
for(int i = 0; i < data_len; i++)
fifo_push(uart0_char_fifo, buff[i]);
return 0;
}
int shell_getc(char *ch)
{
//Do not forget to sleep a bit to let the idle task run ...
tls_os_time_delay(5);
if(is_fifo_empty(uart0_char_fifo))
return 0;
*ch = fifo_pop_unsafe(uart0_char_fifo);
return 1;
//return tls_uart_read(TLS_UART_0, (u8 *) ch, 1);
}
void low_level_write_char(char ch)
{
(void)sendchar((int)ch);
}

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Liber
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.

View File

@ -0,0 +1,18 @@
TOP_DIR = ../../..
sinclude $(TOP_DIR)/tools/w800/conf.mk
ifndef PDIR
GEN_LIBS = libnanoshell$(LIB_EXT)
COMPONENTS_libnanoshell = command/libcommand$(LIB_EXT) \
parse/libparse$(LIB_EXT) \
readline/libreadline$(LIB_EXT) \
shell_io/libshell_io$(LIB_EXT)
endif
#DEFINES +=
sinclude $(TOP_DIR)/tools/w800/rules.mk
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

View File

@ -0,0 +1,384 @@
# Nano-Shell <!-- omit in toc -->
<img src="doc/pic/nano_shell_welcome.png" width=600>
## Contents <!-- omit in toc -->
- [Hot Key Bind](#hot-key-bind)
- [Add Your Command](#add-your-command)
- [HOW:](#how)
- [Example:](#example)
- [Configuring](#configuring)
- [readline configurations:](#readline-configurations)
- [command configurations:](#command-configurations)
- [shell configurations:](#shell-configurations)
- [shell io configurations:](#shell-io-configurations)
- [Porting nano-shell to your project](#porting-nano-shell-to-your-project)
---
Nano-Shell is a light but powerful shell designed for embedded systems.
- with or without an operating system;
- `<main loop mode>` or `<react mode>`;
- highly configurable;
- powerful: command line editing, history record, multi-line input, hot key bind, etc...
- memory friendly: **NO** malloc and free;
- light (build with arm-none-eabi-gcc 7.3.1 20180622, -O3):
| | .text<sup>(1)</sup> | .rodata | .bss<sup>(2)</sup> | .data |
|:------------------------------------------:|:------:|:-------:|:-----:|:-----:|
| main loop mode,<br/>all configurations on | 2.5KB | 1.03KB | 852B | 8B |
| main loop mode,<br/>all configurations off<sup>(3)</sup> | 616B | 600B | 180B | 0B |
| react mode,<br/>all configurations on | 2.52KB | 1.03KB | 852B | 8B |
| react mode,<br/>all configurations off<sup>(3)</sup> | 608B | 600B | 180B | 0B |
> 1: include built-in `help` command.
>
> 2: include `input buffer`(default 128Bytes) and `hisroty record buffer`(defaut 650Bytes(5*(128+2)))
>
> 3: except `CONFIG_SHELL_CMD_BUILTIN_HELP`.
---
## Hot Key Bind
nano-shell has internally bound these hotkeys:
| HOT KEY | ASCII/ANSI-Escape Code<br/>(Xterm, VT100) | Function |
|---------|------------------------|----------|
| Ctrl-A | 1 | Home<br/>Move curosr to the start of line.|
| Ctrl-E | 5 | End<br/>Move curosr to the end of line.|
| Ctrl-P | 16 | Up arrow(-->)<br/>Move cursor right one char.|
| Ctrl-N | 14 | Down arrow(-->)<br/>Move cursor right one char.|
| Ctrl-B | 2 | Left arrow(<--)<br/>Move cursor left one char.|
| Ctrl-F | 6 | Right arrow(-->)<br/>Move cursor right one char.|
| Ctrl-D | 4 | Delete<br/>Delete the character under the cursor.|
| Ctrl-K | 11 | Erase forward<br/>Clears all characters from the cursor position to the end of the line.|
| Ctrl-U | 21 | Erase backword<br/>Clears all characters from the cursor position to the start of the line..|
| Ctrl-C | 3 | Kill the line.|
| Home | Esc[H | Move curosr to the beginning of line.|
| End | Esc[F | Move curosr to the end of line.|
| Up Arrow | Esc[A | Get the previous history. |
| Down Arrow | Esc[B | Get the next history. |
| Left Arrow | Esc[D | Left arrow(<--)<br/>Move cursor left one char. |
| Right Arrow | Esc[C | Right arrow(-->)<br/>Move cursor right one char.|
| Delete | Esc[3~ | Delete the character under the cursor.|
---
## Add Your Command
### HOW:
Commands are added to nano-shell by creating a new command structure.
This is done by first including `command/command.h`, then using the `NANO_SHELL_ADD_CMD()` macro to fill in a `shell_cmd_t` struct.
``` c
NANO_SHELL_ADD_CMD(_name, _func, _brief, _help)
```
`_name`: name of the command. Note: **THIS IS NOT** a string.
`_func`: function pointer: `(*cmd)(const shell_cmd_t *, int, int, char *const[])`.
`_brief`: brief summaries of the command. This is a string.
`_help`: detailed help information of the command. This is a string.
Commands with sub-commands can easily be created with a combination of `NANO_SHELL_DEFINE_SUBCMDS`,
`NANO_SHELL_SUBCMD_ENTRY` and `NANO_SHELL_ADD_CMD`. See examples for more details.
### Example 1: Simple command:
```c
int _do_demo(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
for (int i=0; i<argc; i++) {
shell_printf(" [DEMO] ARGV[%d]: %s\r\n", i, argv[i]);
}
return 0;
}
NANO_SHELL_ADD_CMD(demo,
_do_demo,
"a command demo",
" It's detailed help information of demo command\r\n");
```
Run `demo` in terminal:
<img src="doc/pic/command_demo.png" width=600>
Run `help` and `help demo` in terminal:
<img src="doc/pic/help_demo.png" width=600>
### Example 2: Command with sub-commands:
It is possible to create commands with sub-commands. More nested command can also be created.
```c
/* Create a bunch of commands to be run as a demo */
int _top_command_fallback_fct(const shell_cmd_t* pCmdt, int argc, char* const argv[])
{
if(argc > 1) {
shell_printf(" '%s' is not a subcommand of %s\r\n", argv[1], argv[0]);
}
else {
shell_printf(" Hey, there is subcommands here, type '%s help' for more info\r\n", argv[0]);
}
return 0;
}
int _do_subcommand1(const shell_cmd_t* pCmdt, int argc, char* const argv[]) {
shell_puts(" This is sub-command 1\r\n");
return 0;
}
int _do_subsubcommand1(const shell_cmd_t* pCmdt, int argc, char* const argv[]) {
shell_puts(" This is sub-sub-command 1\r\n");
return 0;
}
int _do_subsubcommand2(const shell_cmd_t* pCmdt, int argc, char* const argv[]) {
shell_puts(" This is sub-sub-command 2\r\n");
return 0;
}
// Sub-Sub commands group
NANO_SHELL_DEFINE_SUBCMDS(subcommand2_group,
NULL,
NANO_SHELL_SUBCMD_ENTRY(subsubcommand1,
_do_subsubcommand1,
"first sub-sub-command",
""),
NANO_SHELL_SUBCMD_ENTRY(subsubcommand2,
_do_subsubcommand2,
"second sub-sub-command",
""));
// Sub commands group
NANO_SHELL_DEFINE_SUBCMDS(top_command_group,
_top_command_fallback_fct,
NANO_SHELL_SUBCMD_ENTRY(subcommand1,
_do_subcommand1,
"first subcommand",
""),
NANO_SHELL_SUBCMD_ENTRY(subcommand2,
NANO_SHELL_SUBCMDS_FCT(subcommand2_group),
"second subcommand with sub-sub commands",
""));
// Command with sub commands
NANO_SHELL_ADD_CMD(top_command,
NANO_SHELL_SUBCMDS_FCT(top_command_group),
"A command with subcommand",
" This command have 2 sub-commands and one sub-sub-command\r\n");
```
In a terminal, you get:
<img src="doc/pic/subcommand_demo.png" width=600>
---
## Configuring
@file: [`shell_config.h`](/shell_config.h)
### readline configurations:
- CONFIG_SHELL_INPUT_BUFFSIZE (127U)
- default: `(127U)`
- config the command line input buffer size (in byte).
- CONFIG_SHELL_LINE_EDITING
- default: `1(enabled)`
- set this to `0` will disable command line editing.
- CONFIG_SHELL_KEY_SEQ_BIND
- default: `1(enabled)`
- set this to `0` will disable ANSI-Escape-Sequence. nano-shell will not be able to detect Home/End/Delete/Arrow keys. Doesn't affect Ctrl-P, Ctrl-N, etc...
- CONFIG_SHELL_MULTI_LINE
- default: `1(enabled)`
- use Backslash('\\') for line continuation when enabled, set this to `0` will disable line continuation.
- line continuation example:<br/><img src="doc/pic/line_continuation.png" width=600> <br/>
- CONFIG_SHELL_HIST_MIN_RECORD
- default: `(5U)`
- set this to `0` will disable history record.
- nano-shell will take `CONFIG_SHELL_HIST_MIN_RECORD*(2+CONFIG_SHELL_INPUT_BUFFSIZE)` bytes to record **At Least** `CONFIG_SHELL_HIST_MIN_RECORD` histroys. The max history records depends on the average length of the input.
### command configurations:
- CONFIG_SHELL_CMD_BRIEF_USAGE
- default: `1(enabled)`
- command structure `shell_cmd_t` has a pointer point to "brief usage information of the command", set this to `0` will remove it.
- CONFIG_SHELL_CMD_LONG_HELP
- default: `1(enabled)`
- command structure `shell_cmd_t` has a pointer point to "detailed help information of the command", set this to `0` will remove it.
- CONFIG_SHELL_CMD_BUILTIN_HELP
- default: `1(enabled)`
- nano-shell provides a built-in `help` command, set this to `0` will remove the deault `help` command.
- CONFIG_SHELL_CMD_MAX_ARGC
- default: `(10U)`
- config the max number of arguments, must be no less than 1.
### shell configurations:
- CONFIG_SHELL_PROMPT
- default: `"Nano-Shell >> "`
- config the shell promot that will displayed at the start of line. If you don't need it, set this to `NULL` or `""`.
### shell io configurations:
- CONFIG_SHELL_PRINTF_BUFFER_SIZE
- default: `(128U)`
- config the buffer size of `shell_printf()`.
---
## Porting nano-shell to your project
### 1. add nano-shell root path to your project include path. <!-- omit in toc -->
### 2. implement these functions([`@file shell_io.h`](/shell_io/shell_io.h)) in your project: <!-- omit in toc -->
this file may help: [`/shell_io/shell_io.c`](/shell_io/shell_io.c).
```c
/**
* @brief send a chararcter...
*
*/
extern void shell_putc(char ch);
/**
* @brief send string...
*
*/
extern void shell_puts(const char *str);
/**
* @brief printf() for nano-shell
*
*/
extern int shell_printf(const char *format, ...) __attribute__((format(printf, 1, 2)));
/**
* @brief: Get next character available from stream.
*
* @param ch: Return the character in `ch` if there was...
* @return: Result is non-zero if there was a character, or 0 if there wasn't.
*
*/
extern int shell_getc(char *ch);
```
Note:
- `int shell_getc(char *ch)` is **NOT USED** in `<react mode>`
- If you run nano-shell in `<main loop mode>`, to avoid losing characters, you'd better use a low layer receive fifo.
Take uart for example, you can detect incoming data using interrupts and then store each received character in a first-in-first-out (FIFO) buffer:
```c
void your_uart_interrupt_handler(void)
{
/* your uart receive code */
char ch = uart_get_char();
/* store character in fifo */
fifo_push(ch);
}
```
then `shell_getc(char *ch)` may be:
```c
int shell_getc(char *ch)
{
if (fifo_empty()) { // if no character in fifo,
return 0; // return false
}
*ch = fifo_pop(); // fifo is not empty, get a character from fifo.
return 1; // return true
}
```
I write a simple and lock free fifo based on ring buffer in [`@file: /shell_io/static_fifo.h`](/shell_io/static_fifo.h), maybe helpful...
### 3. then modify the configuration file: [`shell_config.h`](/shell_config.h) <!-- omit in toc -->
### 4. according to your system, you can: <!-- omit in toc -->
#### 4.1 without os, main loop mode: <!-- omit in toc -->
```c
#include "nano_shell.h"
int main(void)
{
/* system init code... */
/* nano-shell infinite loop. */
nano_shell_loop(NULL);
}
```
#### 4.2 without os, react mode(non-block): <!-- omit in toc -->
you can use it in interrupt, take UART for example:
```c
void your_uart_interrupt_handler (void)
{
/* your uart receive code */
char ch = uart_get_char();
/* nano-shell isr interface */
nano_shell_react(ch);
}
```
Note:
- `nano_shell_react()` is non-blocked (unless there was an infinite loop in your command function), you can call it when get a new character.
- ~~It is recommended to disable some configurations in `shell_config.h` if it was called in interrupt.~~
#### 4.3 with os, take freertos for example: <!-- omit in toc -->
```c
#include "nano_shell.h"
int main(void)
{
/* system init code... */
/* create nano_shell task */
TaskHandle_t shellTaskHandle = NULL;
xTaskCreate(nano_shell_loop, "shellTask", <stack_size>, NULL,
<task_priority>, &shellTaskHandle);
/* start rtos task scheduler */
vTaskStartScheduler();
}
```
Note:
- When determining the stack size for nano-shell, you should consider the memory occupied by commands added in nano-shell.
### 5. define nano_shell section in your linker script file: <!-- omit in toc -->
add these 5 lines to your linker script file:
```ld
.nano_shell : {
. = ALIGN(4);
KEEP (*(SORT(.nano_shell*)))
. = ALIGN(4);
} >FLASH
```
### 6. build, flash and try it. <!-- omit in toc -->

View File

@ -0,0 +1,13 @@
TOP_DIR = ../../../..
sinclude $(TOP_DIR)/tools/w800/conf.mk
ifndef PDIR
GEN_LIBS = libcommand$(LIB_EXT)
endif
#DEFINES +=
sinclude $(TOP_DIR)/tools/w800/rules.mk
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

View File

@ -0,0 +1,102 @@
/**
* @file cmd_help.c
* @author Liber (lvlebin@outlook.com), Cédric CARRÉE (beg0@free.fr)
* @brief nano-shell build in command: help
* @version 1.0
* @date 2020-03-25
*
* @copyright Copyright (c) Liber 2020
*
*/
#include "command.h"
#include "shell_io/shell_io.h"
#include "shell_config.h"
/****************************** build in command: help ******************************/
#if CONFIG_SHELL_CMD_BUILTIN_HELP
static void shell_print_cmd_list(const shell_cmd_t* start, unsigned int count)
{
const shell_cmd_t* tmp = start;
while (count) {
#if CONFIG_SHELL_CMD_BRIEF_USAGE
shell_printf(" %s: %s\r\n", tmp->name, tmp->brief_usage);
#else
shell_printf(" %s\r\n", tmp->name);
#endif
count--;
tmp++;
}
}
static void shell_print_cmd_help(const char *cmd_name,
const shell_cmd_t* start, unsigned int count)
{
#if CONFIG_SHELL_CMD_LONG_HELP
const shell_cmd_t *tmp = shell_find_cmd(cmd_name, start, count);
if (tmp) {
#if CONFIG_SHELL_CMD_BRIEF_USAGE
shell_printf("%s: %s\r\n", cmd_name, tmp->brief_usage);
#else
shell_printf("%s:\r\n", cmd_name);
#endif
// use puts() instead of printf() to avoid printf buffer overflow
shell_puts(tmp->help);
} else {
shell_printf("%s: command not found.\r\n", cmd_name);
}
#endif /* CONFIG_SHELL_CMD_LONG_HELP */
}
int shell_cmd_help(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
const shell_cmd_t *start = _shell_entry_start(shell_cmd_t);
unsigned int count = _shell_entry_count(shell_cmd_t);
return shell_help_generic(argc, argv,
"nano-shell, version 1.0.0.",
start, count);
}
int shell_help_generic(int argc, char *const argv[],
const char* preamble,
const shell_cmd_t* start, unsigned int count)
{
if (argc == 1) {
shell_puts(preamble);
shell_puts("\r\n"
#if CONFIG_SHELL_CMD_LONG_HELP
"Type `help name' to find out more about the function `name'.\r\n"
#endif
"\r\n");
shell_print_cmd_list(start, count);
shell_puts("\r\n");
}
#if CONFIG_SHELL_CMD_LONG_HELP
else {
for (int i = 1; i < argc; i++) {
shell_print_cmd_help(argv[i], start, count);
}
}
#endif /* CONFIG_SHELL_CMD_LONG_HELP */
return 0;
}
NANO_SHELL_ADD_CMD(help,
shell_cmd_help,
"help [pattern ...]",
" Print information about builtin commands.\r\n"
"\r\n"
" If PATTERN is specified, gives detailed help on all commands\r\n"
" matching PATTERN, otherwise print the list of all available commands.\r\n"
"\r\n"
" Arguments:\r\n"
" PATTERN: specifiying the help topic\r\n");
#endif /* CONFIG_SHELL_CMD_BUILTIN_HELP */

View File

@ -0,0 +1,80 @@
/**
* @file command.c
* @author Liber (lvlebin@outlook.com), Cédric CARRÉE (beg0@free.fr)
* @brief
* @version 1.0
* @date 2020-03-24
*
* @copyright Copyright (c) Liber 2020
*
*/
#include <string.h>
#include "shell_io/shell_io.h"
#include "command.h"
const shell_cmd_t *shell_find_top_cmd(const char *cmd_name)
{
const shell_cmd_t *start = _shell_entry_start(shell_cmd_t);
unsigned int count = _shell_entry_count(shell_cmd_t);
return shell_find_cmd(cmd_name, start, count);
}
const shell_cmd_t *shell_find_cmd(const char *cmd_name, const shell_cmd_t* start, unsigned int count)
{
const shell_cmd_t *tmp = start;
if (cmd_name == NULL || start == NULL) {
return NULL;
}
while (count) {
if (strcmp(cmd_name, tmp->name) == 0) {
return tmp;
}
count--;
tmp++;
}
return NULL;
}
int shell_run_cmd(int argc, char *const argv[])
{
if (argc > 0) {
const shell_cmd_t *pCmdt = shell_find_top_cmd(argv[0]);
if (pCmdt) {
return pCmdt->cmd(pCmdt, argc, argv);
}
shell_printf(" %s: command not found.\r\n", argv[0]);
}
return -1;
}
int shell_run_subcmd_implem(const shell_cmd_t* pCmdt,
int argc, char* const argv[],
shell_cmd_cb_t fallback_fct,
const shell_cmd_t* subcommands, unsigned int subcommands_count)
{
if (argc > 1) {
const shell_cmd_t* pSubCmdt = shell_find_cmd(argv[1], subcommands, subcommands_count);
if (pSubCmdt) {
return pSubCmdt->cmd(pSubCmdt, argc - 1, argv + 1);
}
else if(fallback_fct) {
return fallback_fct(pCmdt, argc, argv);
}
else {
shell_printf(" %s: sub-command not found.\r\n", argv[1]);
}
}
else if(fallback_fct) {
return fallback_fct(pCmdt, argc, argv);
}
return -1;
}

View File

@ -0,0 +1,249 @@
/**
* @file command.h
* @author Liber (lvlebin@outlook.com), Cédric CARRÉE (beg0@free.fr)
* @brief
* @version 1.0
* @date 2020-03-23
*
* @copyright Copyright (c) Liber 2020
*
*/
#ifndef __NANO_SHELL_COMMAND_H
#define __NANO_SHELL_COMMAND_H
#include "shell_linker.h"
#include "shell_config.h"
// Forward delecation of shell command structure
struct _shell_cmd_s;
/**
* @brief this is the implementation function of the command.
*
* @param pCmdt: pointer of the structure.
* @param argc: the count of arguments.
* @param argv: argument vector.
* @return 0 if succeed, else non-zero. (return value is not used in ver1.0)
*
* @note the command name is the first argument, argv[0], so argc is always at least 1.
*/
typedef int (*shell_cmd_cb_t)(const struct _shell_cmd_s *pCmdt, int argc, char *const argv[]);
// shell command structure
typedef struct _shell_cmd_s {
const char *name; // command name
shell_cmd_cb_t cmd; // Callback function to run the shell command
#if CONFIG_SHELL_CMD_BRIEF_USAGE
const char *brief_usage; // brief usage of the command.
#endif
#if CONFIG_SHELL_CMD_LONG_HELP
const char *help; // detailed help information of the command.
#endif
} shell_cmd_t;
// shell function structure
typedef struct {
const char *name; // function name
const int param_n; // number of parameters
int (*func)(); // function pointr.
#if CONFIG_SHELL_FUNC_BRIEF_USAGE
const char *brief; // brief summaries of the command.
#endif
} shell_func_t;
#if CONFIG_SHELL_CMD_BRIEF_USAGE
#define _CMD_BRIEF(x) x,
#else
#define _CMD_BRIEF(x)
#endif /* CONFIG_SHELL_CMD_BRIEF_USAGE */
#if CONFIG_SHELL_CMD_LONG_HELP
#define _CMD_HELP(x) x,
#else
#define _CMD_HELP(x)
#endif /* CONFIG_SHELL_CMD_LONG_HELP */
#if CONFIG_SHELL_FUNC_BRIEF_USAGE
#define _FUNC_BRIEF(x) x,
#else
#define _FUNC_BRIEF(x)
#endif /* CONFIG_SHELL_FUNC_BRIEF_USAGE */
#define _shell_cmd_complete(_name, _func, _brief, _help) \
{ #_name, _func, _CMD_BRIEF(_brief) _CMD_HELP(_help) }
#define _shell_func_complete(_name, _nparam, _func, _brief) \
{ #_name, _nparam, _func, _FUNC_BRIEF(_brief) }
/**
* @brief add a command to nano-shell
*
* @_name: name of the command. Note: THIS IS NOT a string.
* @_func: function pointer: (*cmd)(const shell_cmd_t *, int, int, char *const[]).
* @_brief: brief summaries of the command. This is a string.
* @_help: detailed help information of the command. This is a string.
*/
#define NANO_SHELL_ADD_CMD(_name, _func, _brief, _help) \
_shell_entry_declare(shell_cmd_t, _name) = _shell_cmd_complete(_name, _func, _brief, _help)
/**
* @brief add a function to nano-shell.
*
* @_name: name of the function. Note: THIS IS NOT a string.
* @_nparam: param num of the function.
* @_func: pointer of the function.
* @_brief: brief summaries of the function. This is a string.
*/
#define NANO_SHELL_ADD_FUNC(_name, _nparam, _func, _brief) \
_shell_entry_declare(shell_func_t, _name) = _shell_func_complete(_name, _nparam, _func, _brief)
#if CONFIG_SHELL_CMD_BUILTIN_HELP
#define _shell_help_subcmd_entry(_name) \
NANO_SHELL_SUBCMD_ENTRY(help, _name ## _subcmd_help, \
"help [pattern ...]", \
" Print information about subcommands of " # _name ".\r\n" \
"\r\n" \
" If PATTERN is specified, gives detailed help on all commands\r\n" \
" matching PATTERN, otherwise print the list of all available commands.\r\n" \
"\r\n" \
" Arguments:\r\n" \
" PATTERN: specifiying the help topic\r\n"),
#define _shell_help_subcmd_declare(_name) \
static int _name ## _subcmd_help(const shell_cmd_t* pCmd, int argc, char* const argv[]);
#define _shell_help_subcmd_define(_name) \
static int _name ## _subcmd_help(const shell_cmd_t* pCmd, int argc, char* const argv[]) \
{ \
const unsigned int subcommands_count = sizeof(_name ## _subcommands)/sizeof(shell_cmd_t); \
return shell_help_generic( \
argc, argv, \
"Help for " #_name, \
_name ## _subcommands, subcommands_count); \
}
#else
#define _shell_help_subcmd_entry(_name)
#define _shell_help_subcmd_declare(_name)
#define _shell_help_subcmd_define(_name)
#endif /* CONFIG_SHELL_CMD_BUILTIN_HELP */
/**
* @brief Add a sub command in a group of sub-command
*
* To be used as the last arguments of @ref NANO_SHELL_DEFINE_SUBCMDS()
* The syntax is similar to @ref NANO_SHELL_ADD_CMD()
*
* @param _name: name of the command. Note: THIS IS NOT a string.
* @param _func: function pointer: (*cmd)(const shell_cmd_t *, int, int, char *const[]).
* @param _brief: brief summaries of the command. This is a string.
* @param _help: detailed help information of the command. This is a string.
*/
#define NANO_SHELL_SUBCMD_ENTRY(_name, _func, _brief, _help) _shell_cmd_complete(_name, _func, _brief, _help)
/**
* @brief Get the name of the function implementing a sub-command group in nano-shell
*
* @param _name name of the group of sub-commands
*
* @note this macro is to be used for the @c _func parameter of @ref NANO_SHELL_ADD_CMD() or @c _func parameter of @ref NANO_SHELL_SUBCMD_ENTRY()
*/
#define NANO_SHELL_SUBCMDS_FCT(_name) _name ## _shell_cmd
/**
* @brief Define a group of sub-commands in nano-shell
*
* @param _name name of the group of sub-commands
* @param fallback_fct: function that will be run if no subcommand can be found (either @c argc is 1 or argv[1] is not found in @c subcommand)
* @param ... A list of @ref NANO_SHELL_SUBCMD_ENTRY() that define the list of sub-commands
*/
#define NANO_SHELL_DEFINE_SUBCMDS(_name, fallback_fct, ...) \
_shell_help_subcmd_declare(_name) \
static const shell_cmd_t _name ## _subcommands[] = { \
_shell_help_subcmd_entry(_name) \
__VA_ARGS__ }; \
_shell_help_subcmd_define(_name) \
int NANO_SHELL_SUBCMDS_FCT(_name)(const shell_cmd_t* pCmd, int argc, char* const argv[]) \
{ \
const unsigned int subcommands_count = sizeof(_name ## _subcommands)/sizeof(shell_cmd_t); \
return shell_run_subcmd_implem(pCmd, argc, argv, \
fallback_fct, _name ## _subcommands, subcommands_count); \
}
/**
* @brief Find a shell command by name
*
* Find in the list of commandes registred by @ref NANO_SHELL_ADD_CMD().
*
* @param cmd_name name of the shell command to search
* @return const shell_cmd_t*
*/
const shell_cmd_t *shell_find_top_cmd(const char *cmd_name);
/**
* @brief Find a shell command by name in a specific list of commands
*
* @param cmd_name name of the shell command to search
* @param cmds list of commands to search
* @count number of entries in @c cmds
* @return const shell_cmd_t*
*/
const shell_cmd_t *shell_find_cmd(const char *cmd_name, const shell_cmd_t* cmds, unsigned int count);
/**
* @brief Run a shell command from a parsed line
*
* @param argc
* @param argv
* @return int
*/
int shell_run_cmd(int argc, char *const argv[]);
/**
* @brief Implementation function for @ref NANO_SHELL_ADD_CMD_WITH_SUB
*
* @param pCmdt: pointer of the structure.
* @param argc: the count of arguments.
* @param argv: argument vector.
* @param fallback_fct: function that will be run if no subcommand can be found (either @c argc is 1 or argv[1] is not found in @c subcommand)
* @param subcommands: a list of sub-commands
* @param subcommands_count: number of entries in @c subcommands
*
* @return 0 if succeed, else non-zero. (return value is not used in ver1.0)
*/
int shell_run_subcmd_implem(const shell_cmd_t* pCmdt,
int argc, char* const argv[],
shell_cmd_cb_t fallback_fct,
const shell_cmd_t* subcommands, unsigned int subcommands_count);
/**
* @brief Implementation function for 'help' command (or sub-command)
*
* @param argc: the count of arguments.
* @param argv: argument vector.
* @param preamble: text that will appears before the list of commands
* @param start first command in the list of commands that we want to display helps for
* @param count number of command in the list of command
*
* @return 0 if succeed, else non-zero. (return value is not used in ver1.0)
*/
int shell_help_generic(int argc, char *const argv[],
const char* preamble,
const shell_cmd_t* start, unsigned int count);
#endif /* __NANO_SHELL_COMMAND_H */

View File

@ -0,0 +1,62 @@
/**
* @file command.h
* @author Liber (lvlebin@outlook.com)
* @brief
* @version 1.0
* @date 2020-03-23
*
*/
#ifndef __NANO_SHELL_LINKER_H
#define __NANO_SHELL_LINKER_H
#define __align(x) __attribute__((aligned(x)))
/**
* @brief array entry declare.
* @_type: data type of the entry.
* @_name: name of the entry.
*/
#define _shell_entry_declare(_type, _name) \
static const _type nano_shell_##_type##_##_name __align(4) \
__attribute__((used, section(".nano_shell_" #_type "_1_" #_name)))
/**
* @brief: get the pointer of first entry.
* @_type: data type of the entry.
*/
#define _shell_entry_start(_type) \
({ \
static char start[0] __align(4) \
__attribute__((unused, section(".nano_shell_" #_type "_0"))); \
(_type *)&start; \
})
/**
* @brief: get the pointer after last entry.
* @_type: data type of the entry.
*/
#define _shell_entry_end(_type) \
({ \
static char end[0] __align(4) \
__attribute__((unused, section(".nano_shell_" #_type "_2"))); \
(_type *)&end; \
})
/**
* @brief: get the number of elements.
* @_type: data type of the entry.
*/
#define _shell_entry_count(_type) \
({ \
_type *start = _shell_entry_start(_type); \
_type *end = _shell_entry_end(_type); \
unsigned int count = end - start; \
count; \
})
#endif /* __NANO_SHELL_LINKER_H */

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -0,0 +1,120 @@
/**
* @file nano_shell.c
* @author Liber (lvlebin@outlook.com), Cédric CARRÉE (beg0@free.fr)
* @brief nano-shell: a light but powerful shell designed for embedded systems.
* @version 1.0
* @date 2020-03-27
*
* @copyright Copyright (c) Liber 2020
*
*/
#include <string.h>
#include "nano_shell.h"
#include "shell_io/shell_io.h"
#include "command/command.h"
#include "readline/readline.h"
#include "parse/text_parse.h"
#include "shell_config.h"
#define NANO_SHELL_BUILD_VERDION "1.0"
/**
* @brief
*
* @param argc: MUST be larger than 0
* @param argv:
* @return int
*/
int nano_shell_run_cmd(int argc, char *const argv[])
{
const shell_cmd_t *pCmdt = shell_find_top_cmd(argv[0]);
if (pCmdt) {
return pCmdt->cmd(pCmdt, argc, argv);
}
shell_printf(" %s: command not found.\r\n", argv[0]);
return -1;
}
#if (CONFIG_SHELL_CMD_MAX_ARGC < 1)
#error "CONFIG_SHELL_CMD_MAX_ARGC must be no less than 1."
#endif
void nano_shell_loop(void *argument)
{
static char *argv[CONFIG_SHELL_CMD_MAX_ARGC + 1];
char *line;
int argc;
shell_puts("\r\n"
" _ _ ____ _ _ _\r\n"
"| \\ | | __ _ _ __ ___ / ___|| |__ ___| | |\r\n"
"| \\| |/ _` | '_ \\ / _ \\ \\___ \\| '_ \\ / _ \\ | |\r\n"
"| |\\ | (_| | | | | (_) | ___) | | | | __/ | |\r\n"
"|_| \\_|\\__,_|_| |_|\\___/ |____/|_| |_|\\___|_|_|\r\n"
"\r\n"
"Welcome to Nano-Shell "NANO_SHELL_BUILD_VERDION"\r\n"
"\r\n"
" * Build: "__DATE__" - "__TIME__"\r\n"
" * Source: https://github.com/lebinlv/nano-shell\r\n"
" * Copyright: (c) Liber 2020\r\n"
"\r\n");
for (;;) {
line = readline(CONFIG_SHELL_PROMPT);
argc = nano_shell_parse_line(line, argv, CONFIG_SHELL_CMD_MAX_ARGC + 1);
// shell_printf("[DEBUG] argc: %d\r\n", argc);
// for (int i = 0; i < argc; i++) {
// shell_printf("[DEBUG] ARGV[%d]: %s\r\n", i, argv[i]);
// }
if (argc > CONFIG_SHELL_CMD_MAX_ARGC) {
argc--;
shell_printf("** WARNING: too many args (max: %d)! ", CONFIG_SHELL_CMD_MAX_ARGC);
shell_printf("arguments after \"%s\" will be ignored. **\r\n", argv[argc - 1]);
}
if (argc > 0) {
nano_shell_run_cmd(argc, argv);
}
}
}
void nano_shell_react(char ch)
{
static char *argv[CONFIG_SHELL_CMD_MAX_ARGC + 1];
int argc;
char *line = readline_react(ch);
if (line) {
/**
* in react mode, use if (* line) to avoid unnecessary process
* to improve speed.
*/
if (*line) {
argc = nano_shell_parse_line(line, argv, CONFIG_SHELL_CMD_MAX_ARGC + 1);
if (argc > CONFIG_SHELL_CMD_MAX_ARGC) {
argc--;
shell_printf("** WARNING: too many args (max: %d)! ", CONFIG_SHELL_CMD_MAX_ARGC);
shell_printf("arguments after \"%s\" will be ignored. **\r\n", argv[argc - 1]);
}
if (argc > 0) {
nano_shell_run_cmd(argc, argv);
}
}
if (CONFIG_SHELL_PROMPT) {
shell_puts(CONFIG_SHELL_PROMPT);
}
}
}

View File

@ -0,0 +1,34 @@
/**
* @file nano_shell.h
* @author Liber (lvlebin@outlook.com)
* @brief nano-shell interface. include this file in your project.
* @version 1.0
* @date 2020-03-27
*
* @copyright Copyright (c) Liber 2020
*
*/
#ifndef __NANO_SHELL_H
#define __NANO_SHELL_H
/**
* @brief nano-shell infinite loop
*
* @param argument not used in ver1.0
*/
void nano_shell_loop(void *argument);
/**
* @brief nano-shell non-block interface, just react to the input character.
* It is non-blocked (unless there is an infinite loop in your command function)
* you can call it when get a new character.
*
* @param ch input character
*/
void nano_shell_react(char ch);
#endif /*__NANO_SHELL_H */

View File

@ -0,0 +1,13 @@
TOP_DIR = ../../../..
sinclude $(TOP_DIR)/tools/w800/conf.mk
ifndef PDIR
GEN_LIBS = libparse$(LIB_EXT)
endif
#DEFINES +=
sinclude $(TOP_DIR)/tools/w800/rules.mk
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

View File

@ -0,0 +1,54 @@
/**
* @file text_parse.c
* @author Liber (lvlebin@outlook.com)
* @brief
* @version 1.0
* @date 2020-03-28
*
* @copyright Copyright (c) Liber 2020
*
*/
#include <stddef.h>
#include "text_parse.h"
#define isblank(c) ((c) == ' ' || (c) == '\t')
int nano_shell_parse_line(char *input, char *argv[], const int maxArgc)
{
char tmp;
int nargc = 0;
while (nargc < maxArgc) {
while (isblank(*input)) {
input++;
}
if (*input == '\0') { // end of input
argv[nargc] = NULL;
break;
}
tmp = *input;
// single quotes ('') and double quotes ("")
if (tmp == '\'' || tmp == '"') {
argv[nargc] = ++input;
while (*input && (*input != tmp)) {
input++;
}
} else { // normal character
argv[nargc] = input++;
while (*input && !isblank(*input)) {
input++;
}
}
nargc++;
if (*input) {
*input++ = '\0'; /* terminate current arg */
}
}
return nargc;
}

View File

@ -0,0 +1,27 @@
/**
* @file text_parse.h
* @author Liber (lvlebin@outlook.com)
* @brief
* @version 1.0
* @date 2020-03-28
*
* @copyright Copyright (c) Liber 2020
*
*/
#ifndef __NANO_SHELL_TEXT_PARSE_H
#define __NANO_SHELL_TEXT_PARSE_H
/**
* @brief parse the line, doesn't support backslash('\') in ver1.0
*
* @param input: the line to be parsed.
* @param argv:
* @param maxArgc: max number of arguments.
* @return int: the number of parsed arguments.
*/
int nano_shell_parse_line(char *input, char *argv[], const int maxArgc);
#endif /* __NANO_SHELL_TEXT_PARSE_H */

View File

@ -0,0 +1,13 @@
TOP_DIR = ../../../..
sinclude $(TOP_DIR)/tools/w800/conf.mk
ifndef PDIR
GEN_LIBS = libreadline$(LIB_EXT)
endif
#DEFINES +=
sinclude $(TOP_DIR)/tools/w800/rules.mk
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

View File

@ -0,0 +1,115 @@
/**
* @file history.c
* @author Liber (lvlebin@outlook.com)
* @brief history manager
* @version 1.0
* @date 2020-03-18
*
* @copyright Copyright (c) Liber 2020
*
*/
#include <string.h>
#include "history.h"
#include "shell_config.h"
#if CONFIG_SHELL_HIST_MIN_RECORD > 0
typedef unsigned char len_t;
/**
memory view of the history buffer:
-------------------------------------------------------------------------------------------
|length| string |length| *** |length| string |length| |
|<---- 1st record ---->| *** |<---- record ---->| |
^ ^ ^ ^
&buffer[0] cursor tail buffer end
(new record will be saved here)
-------------------------------------------------------------------------------------------
Let the data type of `length` be `len_t`,
then the value of length: length = strlen(string) + 1 + 2*sizeof(len_t)
*/
#define TOTAL_BUFFER_SIZE \
(CONFIG_SHELL_HIST_MIN_RECORD * (CONFIG_SHELL_INPUT_BUFFSIZE + 1 + 2 * sizeof(len_t)))
static char historyBuffer[TOTAL_BUFFER_SIZE]; // history buffer
#define HISTORY_BUFFER_BEGIN() (&historyBuffer[0])
#define HISTORY_BUFFER_END() (&historyBuffer[TOTAL_BUFFER_SIZE])
#define GET_RECORD_SIZE(pRecord) ((len_t)(*((len_t *)(pRecord))))
static char *historyCursor = HISTORY_BUFFER_BEGIN();
static char *historyTail = HISTORY_BUFFER_BEGIN(); // new record will be saved here
char *rl_history_next(void)
{
if (historyCursor >= historyTail || // cursor point to the tail
historyCursor + GET_RECORD_SIZE(historyCursor) >= historyTail // cursor point to the last one
) {
return NULL;
}
historyCursor += GET_RECORD_SIZE(historyCursor);
return historyCursor + sizeof(len_t);
}
char *rl_history_prev(void)
{
if (historyTail != HISTORY_BUFFER_BEGIN() && // buffer is not empty
historyCursor > HISTORY_BUFFER_BEGIN() // cursor does not point to the first
) {
historyCursor -= GET_RECORD_SIZE(historyCursor - sizeof(len_t));
return historyCursor + sizeof(len_t);
}
return NULL;
}
void rl_history_add(char *input)
{
size_t freeSpace = HISTORY_BUFFER_END() - historyTail;
len_t inputLength = strlen(input) + 1;
len_t newRecordLength = inputLength + 2 * sizeof(len_t);
if (freeSpace < newRecordLength) {
len_t tmpLength;
char *tmpRecord = HISTORY_BUFFER_BEGIN();
do {
tmpLength = GET_RECORD_SIZE(tmpRecord);
freeSpace += tmpLength;
tmpRecord += tmpLength;
} while (freeSpace < newRecordLength);
memmove(HISTORY_BUFFER_BEGIN(), tmpRecord, historyTail - tmpRecord);
historyTail -= (tmpRecord - HISTORY_BUFFER_BEGIN());
}
/* put the new record in the history buffer */
*((len_t *)historyTail) = newRecordLength;
memcpy(historyTail + sizeof(len_t), input, inputLength);
historyTail += newRecordLength; // move tail to the end of the new record
*((len_t *)(historyTail - sizeof(len_t))) = newRecordLength;
/* set cursor point to the end */
historyCursor = historyTail;
}
void rl_history_rm_last(void)
{
if (historyTail > HISTORY_BUFFER_BEGIN()) {
historyTail -= GET_RECORD_SIZE(historyTail - sizeof(len_t));
historyCursor = historyTail;
}
}
#endif /* CONFIG_SHELL_HIST_MIN_RECORD > 0 */

View File

@ -0,0 +1,46 @@
/**
* @file history.h
* @author Liber (lvlebin@outlook.com)
* @brief history manage interface
* @version 1.0
* @date 2020-03-20
*
* @copyright Copyright (c) Liber 2020
*
*/
#ifndef __NANO_SHELL_HISTORY_H
#define __NANO_SHELL_HISTORY_H
/**
* @brief add a new record
*
* @param input
*/
void rl_history_add(char *input);
/**
* @brief Get next record
*
* @return char*
*/
char *rl_history_next(void);
/**
* @brief Get previous record
*
* @return char*
*/
char *rl_history_prev(void);
/**
* @brief Remove last record
*
*/
void rl_history_rm_last(void);
#endif /* __NANO_SHELL_HISTORY_H */

View File

@ -0,0 +1,98 @@
/**
* @file key_seq.c
* @author Liber (lvlebin@outlook.com)
* @brief ESC Control Sequence recognize and key-sequence-map.
* @version 1.0
* @date 2020-03-21
*
* @copyright Copyright (c) Liber 2020
*
*/
#ifndef __NANO_SEHLL_KEY_SEQ_MAP_H
#define __NANO_SHELL_KEY_SEQ_MAP_H
#include "key_seq.h"
#include "shell_io/shell_io.h"
#include "shell_config.h"
extern void rl_get_pre_history(void); // `up arrow` or `Ctrl P`
extern void rl_get_next_history(void); // `down arrow` or `Ctrl N`
extern void rl_backward_cursor(void); // `right arrow` or `Ctrl F`
extern void rl_forward_cursor(void); // `left arrow` or `Ctrl B`
extern void rl_line_home(void); // `Home`
extern void rl_line_end(void); // `End`
extern void rl_delete(void); // `Delete`
#if CONFIG_SHELL_KEY_SEQ_BIND
const static key_seq_t key_seq_map[] = {
#if CONFIG_SHELL_HIST_MIN_RECORD > 0
{CONVERT_KEY_SEQ('\033', '[', 'A', 0), rl_get_pre_history}, // up arrow
{CONVERT_KEY_SEQ('\033', '[', 'B', 0), rl_get_next_history}, // down arrow
// {CONVERT_KEY_SEQ('\033', 'O', 'A', 0), rl_get_pre_history},
// {CONVERT_KEY_SEQ('\033', 'O', 'B', 0), rl_get_next_history},
#endif /* CONFIG_SHELL_HIST_MIN_RECORD */
#if CONFIG_SHELL_LINE_EDITING
{CONVERT_KEY_SEQ('\033', '[', 'C', 0), rl_backward_cursor}, // right arrow
{CONVERT_KEY_SEQ('\033', '[', 'D', 0), rl_forward_cursor}, // left arrow
{CONVERT_KEY_SEQ('\033', '[', 'H', 0), rl_line_home}, // home
{CONVERT_KEY_SEQ('\033', '[', 'F', 0), rl_line_end}, // end
// {CONVERT_KEY_SEQ('\033', 'O', 'C', 0), rl_forward_cursor},
// {CONVERT_KEY_SEQ('\033', 'O', 'D', 0), rl_backward_cursor},
// {CONVERT_KEY_SEQ('\033', 'O', 'H', 0), rl_line_home},
// {CONVERT_KEY_SEQ('\033', 'O', 'F', 0), rl_line_end},
{CONVERT_KEY_SEQ('\033', '[', '3', '~'), rl_delete}, // delete
#endif /* CONFIG_SHELL_LINE_EDITING */
};
#define KEY_SEQ_MAP_SIZE (sizeof(key_seq_map) / sizeof(key_seq_t))
extern int _rl_key_seq_len;
void rl_dispatch_seq(char ch)
{
static uint32_t key_seq_val, key_seq_mask;
uint32_t offset, miss_match, tmp_val;
_rl_key_seq_len++;
offset = ((uint32_t)(sizeof(uint32_t) - _rl_key_seq_len)) << 3; // (4-_rl_key_seq_len)*8
key_seq_val |= (((uint32_t)ch) << offset);
key_seq_mask |= (0xFF << offset);
miss_match = 1;
for (int i = 0; i < KEY_SEQ_MAP_SIZE; i++) {
tmp_val = key_seq_map[i].key_seq_val;
if ((tmp_val & key_seq_mask) == key_seq_val) { // partial match
if (key_seq_val == tmp_val) { // full match
key_seq_val = 0;
key_seq_mask = 0;
_rl_key_seq_len = 0;
key_seq_map[i].key_func();
return;
}
miss_match = 0;
}
}
if (miss_match) {
key_seq_val = 0;
key_seq_mask = 0;
_rl_key_seq_len = 0;
shell_putc('\a');
}
}
#endif /* CONFIG_SHELL_KEY_SEQ_BIND */
#endif /* __NANO_SHELL_KEY_SEQ_MAP_H */

View File

@ -0,0 +1,33 @@
/**
* @file key_seq.h
* @author Liber (lvlebin@outlook.com)
* @brief
* @version 1.0
* @date 2020-03-21
*
* @copyright Copyright (c) Liber 2020
*
*/
#ifndef __NANO_SHELL_KEY_SEQ_H
#define __NANO_SHELL_KEY_SEQ_H
#include <stdint.h>
typedef uint32_t u32;
typedef uint8_t u8;
#define CONVERT_KEY_SEQ(c1, c2, c3, c4) \
((u32)((((u8)(c1)) << 24) | (((u8)(c2)) << 16) | (((u8)(c3)) << 8) | (((u8)(c4)) << 0)))
typedef struct {
u32 key_seq_val;
void (*key_func)(void);
} key_seq_t;
void rl_dispatch_seq(char ch);
#endif /* __NANO_SHELL_KEY_SEQ_H */

View File

@ -0,0 +1,419 @@
/**
* @file readline.c
* @author Liber (lvlebin@outlook.com)
* @brief readline component of nano-shell
* @version 1.0
* @date 2020-03-21
*
* @copyright Copyright (c) Liber 2020
*
*/
#include <string.h>
#include "readline.h"
#include "shell_io/shell_io.h"
#include "history.h"
#include "key_seq.h"
#include "shell_config.h"
#define CTL_CH(ch) ((ch) - 'A' + 1)
#define U_SHELL_ALERT() shell_putc('\a')
// erase sequence, used to erase one character on screen.
static const char _erase_seq[] = "\b \b";
// console input buffer
static char _rl_line_buffer[CONFIG_SHELL_INPUT_BUFFSIZE + 1];
// non-zero means readline completed.
static int _rl_done;
/**
* The number of characters present in `_rl_line_buffer`.
* 0 <= `_rl_end` <= `CONFIG_SHELL_INPUT_BUFFSIZE`
* When `_rl_cursor` is at the end of the line, `_rl_cursor` and `_rl_end` are equal.
* Note that the value of `_rl_line_buffer[_rl_end]` should be `\0` in any case.
*/
static int _rl_end;
#if CONFIG_SHELL_LINE_EDITING
// The offset of the current cursor position in `_rl_line_buffer`
// 0 <= `_rl_cursor` <= `_rl_end`
static int _rl_cursor;
#endif /* CONFIG_SHELL_LINE_EDITING */
#if CONFIG_SHELL_KEY_SEQ_BIND
/* uesed by @file{key_seq.c} to recognize key sequences */
int _rl_key_seq_len = 0;
#endif
void rl_end_input(void);
#if CONFIG_SHELL_MULTI_LINE
static int _rl_home;
/**
* @brief Judge whether the line should be continued
*
* @return int 1: continue.
* 0: no continue, start a new line.
*/
int rl_should_continue()
{
// in version 1.0, only judged whether the last character is '\' or not
return (_rl_end > _rl_home && _rl_line_buffer[_rl_end-1] == '\\');
}
void rl_new_line()
{
if (rl_should_continue()) {
_rl_line_buffer[--_rl_end] = '\0'; // overwrite the backslash('\')
_rl_home = _rl_end;
#if CONFIG_SHELL_LINE_EDITING
_rl_cursor = _rl_end; // update _rl_cursor if LINE_EDITING is enabled.
#endif /* CONFIG_SHELL_LINE_EDITING */
shell_puts("\r\n> ");
} else {
rl_end_input();
}
}
#else
#define _rl_home 0
#define rl_new_line() rl_end_input()
#endif /* CONFIG_SHELL_MULTI_LINE */
void rl_end_input(void)
{
#if CONFIG_SHELL_HIST_MIN_RECORD > 0
if (*_rl_line_buffer) {
rl_history_add(_rl_line_buffer);
}
#endif /*CONFIG_SHELL_HIST_MIN_RECORD */
#if CONFIG_SHELL_MULTI_LINE
_rl_home = 0;
#endif /* CONFIG_SHELL_MULTI_LINE */
#if CONFIG_SHELL_LINE_EDITING
_rl_cursor = 0;
#endif /* CONFIG_SHELL_LINE_EDITING */
_rl_end = 0;
_rl_done = 1;
shell_puts("\r\n");
}
// add one character to the buffer
void rl_add_char(char ch)
{
if (_rl_end < CONFIG_SHELL_INPUT_BUFFSIZE && ch >= ' ') {
#if CONFIG_SHELL_LINE_EDITING
int len = _rl_end - _rl_cursor;
_rl_end++;
_rl_line_buffer[_rl_end] = '\0';
memmove(&_rl_line_buffer[_rl_cursor + 1], &_rl_line_buffer[_rl_cursor], len);
_rl_line_buffer[_rl_cursor] = ch;
shell_puts(&_rl_line_buffer[_rl_cursor++]);
while (len > 0) {
shell_putc('\b');
len--;
}
#else
shell_putc(ch);
_rl_line_buffer[_rl_end++] = ch;
_rl_line_buffer[_rl_end] = '\0';
#endif /* CONFIG_SHELL_LINE_EDITING */
} else {
U_SHELL_ALERT();
}
}
// Rubout the character behind `_rl_cursor`(Backspace).
void rl_rubout(void)
{
#if CONFIG_SHELL_LINE_EDITING
if (_rl_cursor > _rl_home) {
int len = _rl_end - (--_rl_cursor);
_rl_end--;
memmove(&_rl_line_buffer[_rl_cursor], &_rl_line_buffer[_rl_cursor + 1], len);
shell_putc('\b');
shell_puts(&_rl_line_buffer[_rl_cursor]);
shell_putc(' ');
do {
shell_putc('\b');
len--;
} while (len > 0);
#else
if (_rl_end > _rl_home) {
_rl_end--;
_rl_line_buffer[_rl_end] = '\0';
shell_puts(_erase_seq);
#endif /* CONFIG_SHELL_LINE_EDITING */
} else {
U_SHELL_ALERT();
}
}
#if CONFIG_SHELL_HIST_MIN_RECORD > 0
void rl_process_history(const char *history)
{
if (history) {
#if CONFIG_SHELL_LINE_EDITING
shell_puts(&_rl_line_buffer[_rl_cursor]); // move cursor to the end on screen.
#endif
while (_rl_end > _rl_home) { // erase all on the screen.
shell_puts(_erase_seq);
_rl_end--;
}
_rl_end = strlen(history) + _rl_home; // update _rl_end.
#if CONFIG_SHELL_LINE_EDITING
_rl_cursor = _rl_end; // update _rl_cursor if LINE_EDITING is enabled.
#endif
memcpy(_rl_line_buffer + _rl_home, history, _rl_end -_rl_home + 1);
shell_puts(_rl_line_buffer + _rl_home); // display new text and move cursor to the end on screen.
} else {
U_SHELL_ALERT();
}
}
void rl_get_pre_history(void)
{
rl_process_history(rl_history_prev());
}
void rl_get_next_history(void)
{
rl_process_history(rl_history_next());
}
#endif /* CONFIG_SHELL_HIST_MIN_RECORD > 0 */
#if CONFIG_SHELL_LINE_EDITING
// Delete the character under the cursor (Delete).
void rl_delete(void)
{
if (_rl_cursor < _rl_end) {
int len = _rl_end - _rl_cursor;
_rl_end--;
memmove(&_rl_line_buffer[_rl_cursor], &_rl_line_buffer[_rl_cursor + 1], len);
shell_puts(&_rl_line_buffer[_rl_cursor]);
shell_putc(' ');
do {
shell_putc('\b');
len--;
} while (len > 0);
}
}
// Move curosr to the beginning of line.
void rl_line_home(void)
{
while (_rl_cursor > _rl_home) {
shell_putc('\b');
_rl_cursor--;
}
}
// Move cursor to the end of line.
void rl_line_end(void)
{
shell_puts(_rl_line_buffer + _rl_cursor);
_rl_cursor = _rl_end;
}
// Move forward (left).
void rl_forward_cursor(void)
{
if (_rl_cursor > _rl_home) {
shell_putc('\b');
_rl_cursor--;
} else {
U_SHELL_ALERT();
}
}
// Move backward (right).
void rl_backward_cursor(void)
{
if (_rl_cursor < _rl_end) {
shell_putc(_rl_line_buffer[_rl_cursor]);
_rl_cursor++;
} else {
U_SHELL_ALERT();
}
}
// Erase from beginning of line to cursor.
void rl_erase_all_backward(void)
{
if (_rl_cursor > _rl_home) {
int len = _rl_end - _rl_cursor + 1;
shell_puts(&_rl_line_buffer[_rl_cursor]); // move cursor to the end on screen.
while (_rl_end > _rl_home) { // erase all on the screen
shell_puts(_erase_seq);
_rl_end--;
}
memmove(_rl_line_buffer + _rl_home, &_rl_line_buffer[_rl_cursor], len--); // new text.
shell_puts(_rl_line_buffer + _rl_home); // display new text and move cursor to the end on screen.
_rl_cursor = _rl_home;
_rl_end = len + _rl_home;
while (len > 0) { // move cursor to the begin on the screen.
shell_putc('\b');
len--;
}
}
}
// Erase from cursor to end of line.
void rl_erase_all_forward(void)
{
shell_puts(&_rl_line_buffer[_rl_cursor]); // move cursor to the end on screen.
while (_rl_end > _rl_cursor) {
shell_puts(_erase_seq); // erase all right to _rl_cursor, and move screen cursor to _rl_cursor.
_rl_end--;
}
_rl_line_buffer[_rl_end] = '\0';
}
#endif /* CONFIG_SHELL_LINE_EDITING */
void rl_dispatch(char ch)
{
#if CONFIG_SHELL_KEY_SEQ_BIND
if (_rl_key_seq_len) {
rl_dispatch_seq(ch);
return;
}
#endif /* CONFIG_SHELL_KEY_SEQ_BIND */
switch (ch) {
case '\r': // CTL_CH('M')
case '\n': // CTL_CH('J')
rl_new_line();
break;
case CTL_CH('C'):
shell_puts("^C\r\n");
*_rl_line_buffer = '\0';
rl_end_input();
break;
case 255:
case 127:
case 8: // backspace, CTL_CH('H')
rl_rubout();
break;
#if CONFIG_SHELL_KEY_SEQ_BIND
case '\033': // ESC(\033)
rl_dispatch_seq(ch);
break;
#endif /* CONFIG_SHELL_KEY_SEQ_BIND */
#if CONFIG_SHELL_LINE_EDITING
case CTL_CH('A'): // HOME
rl_line_home();
break;
case CTL_CH('E'): // END
rl_line_end();
break;
case CTL_CH('B'): // <-- (left arrow)
rl_forward_cursor();
break;
case CTL_CH('F'): // --> (right arrow)
rl_backward_cursor();
break;
case CTL_CH('K'): // Delete all characters on the right side.
rl_erase_all_forward();
break;
case CTL_CH('U'): // Delete all characters one the left side.
rl_erase_all_backward();
break;
case CTL_CH('D'): // DELETE
rl_delete();
break;
// case CTL_CH('X'):
// case CTL_CH('O'):
// break;
#endif /* CONFIG_SHELL_LINE_EDITING */
#if CONFIG_SHELL_HIST_MIN_RECORD > 0
case CTL_CH('P'): // up arrow
rl_get_pre_history();
break;
case CTL_CH('N'): // down arrow
rl_get_next_history();
break;
#endif /* CONFIG_SHELL_HIST_MIN_RECORD > 0 */
default: // add current character to the buffer
rl_add_char(ch);
break;
}
}
char *readline(const char *promot)
{
char input;
if (promot) {
shell_puts(promot);
}
// clean last line.
_rl_done = 0;
*_rl_line_buffer = '\0';
// start read the new line.
while (_rl_done == 0) {
while (!shell_getc(&input)) {
}
rl_dispatch(input);
}
return _rl_line_buffer;
}
char *readline_react(char ch)
{
if (_rl_done) { // clean last line.
_rl_done = 0;
*_rl_line_buffer = '\0';
}
rl_dispatch(ch);
return (_rl_done ? _rl_line_buffer : NULL);
}

View File

@ -0,0 +1,30 @@
/**
* @file readline.h
* @author Liber (lvlebin@outlook.com)
* @brief readline interface
* @version 1.0
* @date 2020-03-21
*
* @copyright Copyright (c) Liber 2020
*
*/
#ifndef __NANO_SHELL_READLINE_H
#define __NANO_SHELL_READLINE_H
// read a line of input. Prompt with PROMPT. A NULL PROMPT means none.
char *readline(const char *promot);
/**
* @brief react to the input character `ch`.
*
* @param[in] ch: input character.
* @return: NULL means the current line has not been completed (need more input).
*
*/
char *readline_react(char ch);
#endif /* __NANO_SHELL_READLINE_H */

View File

@ -0,0 +1,64 @@
/**
* @file shell_config.h
* @author Liber (lvlebin@outlook.com)
* @brief nano-shell configurations.
* @version 1.0
* @date 2020-03-18
*
* @copyright Copyright (c) Liber 2020
*
*/
#ifndef __NANO_SHELL_CONFIG_H
#define __NANO_SHELL_CONFIG_H
/******************************* readline configuration ****************************/
/* command line input buffer size(byte) */
#define CONFIG_SHELL_INPUT_BUFFSIZE (256U)
/* set 1 to enable command line edit */
#define CONFIG_SHELL_LINE_EDITING 1
/* ESC Control Sequence detect, such as Home, Delete, Arrow, etc. */
#define CONFIG_SHELL_KEY_SEQ_BIND 1
/* set 1 to enable Backslash('\') for line continuation */
#define CONFIG_SHELL_MULTI_LINE 1
/**
* set 0 to disable history record.
*
* nano-shell will take `CONFIG_SHELL_HIST_MIN_RECORD*(2+CONFIG_SHELL_INPUT_BUFFSIZE)` bytes to
* record **at least** `CONFIG_SHELL_HIST_MIN_RECORD` histroys.
* the maximum number of history records depends on the average length of the input.
*/
#define CONFIG_SHELL_HIST_MIN_RECORD (10U)
/******************************* command configuration ****************************/
#define CONFIG_SHELL_FUNC_BRIEF_USAGE 1
#define CONFIG_SHELL_CMD_BRIEF_USAGE 1
#define CONFIG_SHELL_CMD_LONG_HELP 1
/* nano-shell provides a built-in help command, set 0 to disable it */
#define CONFIG_SHELL_CMD_BUILTIN_HELP 1
/* config the max number of arguments, must be no less than 1. */
#define CONFIG_SHELL_CMD_MAX_ARGC (10U)
/******************************* shell io configuration ****************************/
/* config the buffer size (shell_printf()) */
#define CONFIG_SHELL_PRINTF_BUFFER_SIZE 128U
/******************************* shell configuration ****************************/
#define CONFIG_SHELL_PROMPT "Nano-Shell >> "
#endif /* __NANO_SHELL_CONFIG_H */

View File

@ -0,0 +1,13 @@
TOP_DIR = ../../../..
sinclude $(TOP_DIR)/tools/w800/conf.mk
ifndef PDIR
GEN_LIBS = libshell_io$(LIB_EXT)
endif
#DEFINES +=
sinclude $(TOP_DIR)/tools/w800/rules.mk
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

View File

@ -0,0 +1,80 @@
/**
* @file shell_io.c
* @author Liber (lvlebin@outlook.com)
* @brief Example implementation of some functions in file "shell_io.h".
* @version 1.0
* @date 2020-03-24
*
* @copyright Copyright (c) Liber 2020
*
*/
#include <stdio.h>
#include <stdarg.h>
#include "shell_io.h"
#include "shell_config.h"
/**
* @brief This function should do the actual transmission of the character.
* It can also be implemented by macro definition, for example:
* ```
* #define low_level_write_char(ch) \
* do { \
* uart_send_char(ch); \
* } while(0)
* ```
*
* @param ch the character to be transmitted.
*/
extern void low_level_write_char(char ch);
#if defined(__GNUC__)
#ifndef __weak
#define __weak __attribute__((weak))
#endif /* __weak */
#endif /* __GNUC__ */
/****************************************************************/
#if !(CONFIG_SHELL_PRINTF_BUFFER_SIZE > 0)
#error "the value of CONFIG_SHELL_PRINTF_BUFFER_SIZE must be greater than 0!"
#endif
__weak int shell_printf(const char *format, ...)
{
static char shell_printf_buffer[CONFIG_SHELL_PRINTF_BUFFER_SIZE];
int length = 0;
va_list ap;
va_start(ap, format);
length = vsnprintf(shell_printf_buffer, CONFIG_SHELL_PRINTF_BUFFER_SIZE, format, ap);
va_end(ap);
for (int i = 0; i < length; i++) {
low_level_write_char(shell_printf_buffer[i]);
}
return length;
}
__weak void shell_puts(const char *str)
{
while (*str) {
low_level_write_char(*str);
str++;
}
}
__weak void shell_putc(char ch)
{
low_level_write_char(ch);
}

View File

@ -0,0 +1,69 @@
/**
* @file shell_io.h
* @author Liber (lvlebin@outlook.com)
* @brief I/O interface
* @version 1.0
* @date 2020-03-17
*
* @copyright Copyright (c) Liber 2020
*
*/
#ifndef __NANO_SHELL_IO_H
#define __NANO_SHELL_IO_H
/*********************************************************************
nano-shell uses these functions to get/send character from/to stream.
You should implement these functions in your project.
*********************************************************************/
/**
* @brief send a chararcter...
*
*/
extern void shell_putc(char ch);
/**
* @brief send string...
*
*/
extern void shell_puts(const char *str);
/**
* @brief printf() for nano-shell
*
*/
extern int shell_printf(const char *format, ...) __attribute__((format(printf, 1, 2)));
/**
* @brief Get next character available from stream.
* not used in <interrupt mode>.
*
* @param ch Return the character in `ch` if there was...
* @return Result is non-zero if there was a character, or 0 if there wasn't.
*
* @note if you run nano-shell in <main loop mode>, to avoid losing characters, you'd better use a
* low layer receive fifo. Take uart for example, you can detect incoming data using interrupts and
* then store each received character in a first-in-first out (FIFO) buffer.
*
* then `shell_getc(char *ch)` may be like this:
*
* int shell_getc(char *ch)
* {
* if (fifo_empty()) { // if no character in fifo,
* return 0; // return false
* }
*
* *ch = fifo_pop(); // fifo is not empty, get it.
* return 1; // return true
* }
*
*/
extern int shell_getc(char *ch);
#endif /* __NANO_SHELL_IO_H */

View File

@ -0,0 +1,104 @@
/**
* @file fifo.h
* @author Liber (lvlebin@outlook.com)
* @brief simple fifo based on ring buffer
* @version 1.0
* @date 2020-03-24
*
* @copyright Copyright (c) Liber 2020
*
*/
#ifndef __NANO_SHELL_FIFO_H
#define __NANO_SHELL_FIFO_H
/**
* @brief: declare a STATIC fifo
*
* @name: name of the fifo, THIS IS NOT a string.
* @size: MUST be a CONSTANT, and MUST be a POWER OF 2!!! such as 64, 128, 256, 512, etc ...
* @size_type: data type of size, MUST be unsigned!!! such as, uint8_t, uint16_t, uint32_t, etc...
* and max_value(size_type) >= size-1
* @data_type: data type of element.
*
* @example:
* 1). declare a char type fifo: static_fifo_declare(my_fifo, 256, unsigned char, char);
* 2). add a char to the fifo: fifo_push(my_fifo, ch);
* 3). get and remove a char: char ch = fifo_pop(my_fifo);
*
* 4). check manually and then get and remove a char:
* char ch = 0;
* if (is_fifo_empty(my_fifo)) {
* ch = fifo_pop_unsafe(my_fifo);
* }
*
* 5). get a char without remove: char ch = fifo_peek(my_fifo);
* 6). get capacity of the fifo: size_t capacity = get_fifo_capacity(my_fifo);
* 7). get size of the fifo: size_t size = get_fifo_size(my_fifo);
*
* @note: All operations on the same FIFO declared by `static_fifo_declare` must be in the same scope.
*
*/
#define static_fifo_declare(name, size, size_type, data_type) \
static struct { \
size_type head; \
size_type tail; \
data_type buff[size]; \
} _fifo_##name = { 0, 0, {0, } }; \
static const size_type _fifo_size_##name = ((size)-1); // the actual available size is (size-1). use const type for gcc optimization
#define get_fifo_capacity(name) (_fifo_size_##name)
#define get_fifo_size(name) ((unsigned int)(_fifo_##name.head - _fifo_##name.tail))
#define is_fifo_empty(name) (_fifo_##name.head == _fifo_##name.tail)
#define is_fifo_full(name) (_fifo_##name.head - _fifo_##name.tail >= _fifo_size_##name)
/**
* @brief: add a new element to the fifo. if the fifo is full, do nothing.
*
* @name: name of the fifo.
* @data: the new element to be added.
*/
#define fifo_push(name, data) \
do { \
if (!is_fifo_full(name)) { \
_fifo_##name.buff[_fifo_##name.head++ & _fifo_size_##name] = (data); \
} \
} while (0)
/**
* @brief: Returns the last element in the fifo, without remove it.
* If the fifo is empty, return 0.
*
* @name: name of the fifo.
*
*/
#define fifo_peek(name) \
(is_fifo_empty(name) ? 0 : _fifo_##name.buff[_fifo_##name.tail & _fifo_size_##name])
/**
* @brief: remove and return last element without checking if the fifo is empty.
*
* @name: name of the fifo
*/
#define fifo_pop_unsafe(name) \
(_fifo_##name.buff[_fifo_##name.tail++ & _fifo_size_##name])
/**
* @brief: Remove and return last element in the fifo.
* If the fifo is empty, return 0.
*
* @name: name of the fifo.
*/
#define fifo_pop(name) \
(is_fifo_empty(name) ? 0 : _fifo_##name.buff[_fifo_##name.tail++ & _fifo_size_##name])
#endif

281
doc/ChangeLog.txt Normal file
View File

@ -0,0 +1,281 @@
==========================================================
| CHANGELOG: WinnerMicro Software Development Kit |
==========================================================
W800 SDK v1.00.04 | 2021/10/30
==========================
*********
SDK功能
*********
1.驱动相关
*低速SPI做主时默认IO复用为PB2,PB3,PB4,PB5与DEMO保持一致
*增加UART5功能
*修复使用40M分频时32K不校准导致不准的问题RTC使用40M分频时精度基本没有问题
*修复LCD功能不工作的问题
*增加ADC获取供电电压的功能
*增加Flash的OTP操作增加读取Unique ID的操作
*增加touch功能
*修改Flash驱动部分读取操作未加保护问题
*修复去使能某个IO中断使能位时将整个IO中断也关闭的问题
2.DEMO相关
*增加获取供电电压DEMO
*增加PMU demo选择时钟使用
3.调试相关
*增加打印口可设置为UART0/UART1的可配操作默认使用UART0
4.配网相关
*优改联盛德一键配网的内存使用
*增加TLS_CONFIG_BLE_WIFI_ONESHOT宏定义
5.编译打包相关:
*清理部分无效代码
*修复PPP_SUPPORT宏定义打开编译报错的问题
*修复TLS_CONFIG_HOSTIF宏关闭RMMS编译报错的问题
*wm_tool.c打包工具更新解决当升级文件小于1024Byte时打包出的文件无法升级成功的问题
*增加CKLINK调试下载使用的flash驱动(tools/w800/utilities/W800_Flash_Tool.elf)
6.蓝牙相关
*修复蓝牙wm_ble_client_demo_on_mtu设置MTU时不设限的问题
7.Wi-Fi相关
*修复ssid为空时tls_sys.c文件里自动联网依然触发问题
*修复apssid为空时依然可以创建热点成功的问题
*优化Wi-Fi联网
*优化联网低功耗
*修复热点模式Beacon帧发送问题
8.AT相关
*UART作为AT指令传输通道时可指定为除UART0外的任意一个UART。
*修复STA模式固定IP时AT指令第二次加网无法查询网络状态的问题
9.增加单独支持生产测试的AT指令(src/app/factorycmd目录下
*支持发送测试
*支持接收测试
*支持频偏补偿(AT+FREQ
*支持是否校准查询(AT+&CALFIN)
W800 SDK v1.00.02 | 2021/5/13
==========================
*********
SDK功能
*********
1. 简化RAM分配调整详见wm_ram_config.h除了HSPI和WiFi必须使用静态内存外
2. 代码空间调整说明:
1调整ld文件里的I-SRAM的LENGTH值如果LENGTH值加ORIGIN值已越界FLASH容量则调整ORIGIN的初始值
2 依据是CDK编译工程还是直接make来选择调整
1 CDK工程里要调整代码空间大小除了步骤1之外要调整tools\w800\uitilities\aft_build_project.sh文件里的
run_img_header和run_img_posrun_img_pos要和ORIGIN的值一致run_img_header为ORIGIN值减0x400
2 命令行方式编译除了步骤1之外要调整CONFIG_W800_IMAGE_HEADER和CONFIG_W800_RUN_ADDRESS的值方法同1
3 由于代码空间变大,用户空间会变小,那么需要注意用户空间的位置,作为使用时局限。
3. 蓝牙:
1ble host切换为nimble默认使用的蓝牙协议栈
2增加了ble多连接示例
3蓝牙控制器代码优化
4标准蓝牙部分提供了br_edr lib文件libbtcontroller_br_edr.a和libbthost_br_edr.a
如果需要使用标准蓝牙,需要操作:
1 把wm_config.h里的宏TLS_CONFIG_BR_EDR设置为CFG_ON
2编译时
如果使用命令行编译需要make menuconfig在编译选项菜单里去使能nimble的选项或者修改.config文件把NIMBLE_FTR去掉
如果使用CDK编译需要把DNIMBLE_FTR设置为0在CDK的编译设置项里
3相应的需要把libbtcontroller_br_edr.a和libbthost_br_edr.a改为libbtcontroller.a和libbthost.a
4还需要单独编译一下src/app目录命令行编译
5 因蓝牙增加了Code Size需扩大gcc.ld文件里I-SRAM的空间
5蓝牙任务删除统一修改为通过句柄方式删除
6蓝牙host的代码统一开源位置位于目录:src\bt
4. Wi-Fi优化
1 STA节能处理优化
2 软ap功能暂不支持wmm功能
5. 驱动问题处理:
DMA 修复DMA是用loop方式时循环地址处理不正确导致的中断不产生的问题
ADC DMA方式回调接口统一DMA时使用内存为动态申请内存ADC的回调函数统一处理
GPIO 修复GPIOB的中断关闭操作时没有正确操作的问题
FLASH 修复Flash加锁操作的操作数异常
PMU 删除PMU中断处理里的重复的csi_kernel_intrpt_exit调用触发调度的操作
7816 增加7816接口demo
SPI 低速主SPI当使用DMA方式传输时所用内存为动态分配内存
IO复用 增加了W801的IO复用功能设置接口
uart 为了适配某些平台,增加的单个字符即回调的接口。
6. OS
1 增加通过任务句柄删除任务的操作(wm_osal_rtos.c, tasks.c)
2 完善通过优先级删除任务的操作(wm_osal_rtos.c, tasks.c)
3 部分os的适配接口增加了中断里的使用保护(wm_osal_rtos.c)
7. 网络部分修改:
1网络主机名改为WinnerMicro_+mac地址末2字段的格式。(ethernetif.c)
2修复sys_arch.c里的queue delete函数不再使用开关中断保护
8. wm_main.c里的主任务增加可删除操作可通过打开宏开关使得wm_main里的任务使用完毕后删除
9. 内存分配wm_mem.c的封装函数改为仅用信号量来管理
10. 应用修复:
1FATFS文件系统增加可重入保护处理针对SDIO HOST部分对接的写SD卡时的非4字节对齐做了处理。
2SSL不再使用之前的版本改为使用mbed TLS 2.7.10
3修复oneshot宏关闭链接失败的问题
11. 清理部分编译告警
W800 SDK v1.00.01 | 2020/12/29
==========================
*********
SDK功能
*********
*ld调整
因增加BT功能代码空间超过1MB当前设定为1MB+64KB相应的用户区要减少64KB
用户区宏调整wm_flash_map.h#define USER_ADDR_START (0x81E0000UL)
当前升级区针对超过1MB的情况只能选择使用压缩的ota固件
*二级BOOT更新
1发布SDK里添加secboot.bin文件生成img的操作以免客户调整运行区起始地址时因为secboot的头信息与其不匹配导致升级fls启动不了
*蓝牙:
1提供三种蓝牙的库bt和ble都有的lib单独标准bt的lib单独ble的lib
用户可根据实际需要配合wm_config.h里的TLS_CONFIG_BR_EDR和TLS_CONFIG_BLE的设置把相关的lib更名为libbt.a。
2发布时默认使用ble都有的lib
3优化蓝牙参数
4增加蓝牙demo
*Wi-Fi
1优化低功耗功能
2优化异常恢复处理
*系统参数及驱动:
1增加关键参数区写保护操作
2优化参数区使用内存改为只使用一块静态内存
3解决SDIO多block写操作失败问题
4Master SPI使用的任务栈改为使用申请创建任务不再使用静态内存
*芯片的sleep和standby功能修改
1sleep和standby的进入条件修改
2at指令里的AT+ENTS需要的芯片Sleep和standby功能函数从wifi lib移至wm_cmdp.c
W800 SDK v1.00.00 | 2020/08/04
==========================
*********
SDK功能
*********
*ld调整
因增加BT功能代码空间超过1MB当前设定为1MB+64KB相应的用户区要减少64KB
用户区宏调整wm_flash_map.h#define USER_ADDR_START (0x81E0000UL)
当前升级区针对超过1MB的情况只能选择使用压缩的ota固件
*蓝牙:
1支持BT功能提供Audio sink和免提电话相关的API
2提供三种蓝牙的库bt和ble都有的lib单独标准bt的lib单独ble的lib
用户可根据实际需要配合wm_config.h里的TLS_CONFIG_BR_EDR和TLS_CONFIG_BLE的设置把相关的lib更名为libbt.a。
3发布时默认使用bt和ble都有的lib
*Wi-Fi
1解决设定参数扫描时间过长扫描个数反而少的问题
*增加DSP功能以lib和demo方式提供
*提供dsp功能的相关demo详见DEMO_DSP宏包含的相关代码
*增加IO下拉功能配置
*修改GPIO demo增加下拉功能GPIO的输出高或低的测试
*修改ADC功能提供芯片温度和外部输入电压的测试不支持芯片电源电压的检测功能。
*修改PWM demo支持PWM两组复用的测试demo
*SDK提供CDK编译工程编译限制路径长度80字符以内
*CDKCSKY Development Kit的版本>V2.2.2获取路径https://occ.t-head.cn/community/download?id=575997419775328256
*增加BLE数据通信的demo
W800 SDK v0.00.06 | 2020/07/07
==========================
*********
SDK功能
*********
*低功耗:
1只有Wi-Fi的时候断网也进入节能
2部分外设的时钟改为只在使用时打开LSPI
*蓝牙:开放蓝牙应用代码,路径:src/app/btapp
*Wi-Fi
1增加可配扫描参数的扫描API接口tls_wifi_scan_by_param
2内部增益优化
3Wi-FI的调试LOG默认关闭
4更新Wi-Fi默认增益参数
5处理SSID长度为0时也触发联网的问题
6默认wifi工作使用温补wm_main.c里设置
*与PWM相关的IO复用配置的API命名更改为0,1,2,3,4编号即函数:wm_pwmX_configX=0,1,2,3,4
*更改部分DEMO的IO使用GPIOPWMLSPII2S
*解决LSD ONESHOT可能使用空SSID联网的问题
*处理IPERF SERVER测试后无法启动Client测试的问题
*更改内部温度检测函数的结果计算(不再计算平均值)
*解决RMMS反复创建存在的内存不释放问题
*调整ping的任务栈大小
*解决某些路由DHCP拿不到IP的问题
W800 SDK v0.00.05 | 2020/06/12
==========================
*********
SDK功能
*********
*修改CPU默认时钟为80M
*默认打开Wi-Fi的节能功能Wi-Fi和蓝牙共存时Wi-Fi不节能
*优化蓝牙配网兼容性
*修改部分任务栈使用动态申请内存,不再使用静态数组
*打开并生效Wi-Fi的本振和相位补偿功能
*修复GPIO的数据定义边界问题
*删除link文件当前默认make使用的是use lib
*修复命令行编译结果不变的问题因elf文件未移动导致的
W800 SDK v0.00.04 | 2020/06/04
==========================
*********
SDK功能
*********
*优化蓝牙配网兼容性
*增加CK-LINK复用打开关闭的宏开关:WM_SWD_ENABLE默认打开
*代码清理
*sdk打包里添加编译的固件bin目录
*修改Standby和Sleep功耗问题
*修改ADC采集内部温度功能采集电压功能还不支持
W800 SDK v0.00.03 | 2020/06/01
==========================
*********
SDK功能
*********
*优化蓝牙配网兼容性
*优化Wi-Fi的基带参数解决最大输入电平问题
*增加mbedtls及demo
*默认JTAG复用功能打开
W800 SDK v0.00.02 | 2020/05/19
==========================
*********
SDK功能
*********
*更新优化后的Wi-Fi相关参数
*更新Flash工作模式及工作频率(80MHz)
*更新SDIO HOST和I2S驱动
*更新AT+ENTS的Sleep和Standby功能更新文档
*更新AT+HTTPC的返回值说明更新文档
*更新secboot版本
*默认打开IPERF功能
W800 SDK v0.00.01 | 2020/04/30
==========================
*********
SDK功能
*********
*Wi-Fi基本功能STAAPAPSTA
*Wi-Fi配网功能oneshot蓝牙apweb
*基本驱动功能除adcsdio hosti2s外
*Flash的布局及参数区
*升级功能串口升级OTAhttp服务器升级
*加密功能
*基础的demo

BIN
doc/w800_apis.chm Normal file

Binary file not shown.

View File

@ -0,0 +1,79 @@
/**
* @file wm_at_ri_init.h
*
* @brief AT_RI task and interface resource initial Module
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_AT_RI_H
#define WM_AT_RI_H
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup AT_RI_APIs AT_RI APIs
* @brief AT_RI command APIs
*/
/**
* @addtogroup AT_RI_APIs
* @{
*/
/**
* @brief This function is used to initialize hostif task
used by AT&RI Command
*
* @param None
*
* @retval 0 success
* @retval other failed
*
* @note Usually the system will call this api at power on.
*/
int tls_hostif_init(void);
/**
* @}
*/
/**
* @}
*/
/**
* @brief This function is used to initialize high speed SPI
*
* @param None
*
* @retval 0 success
* @retval other failed
*
* @note Users can decide to call this api or not according to his application.
*/
int tls_hspi_init(void);
/**
* @brief This function is used to initialize UART
*
* @param None
*
* @return None
*
* @note Usually the system will call this api at power on.
*/
void tls_uart_init(void);
#endif /* WM_AT_RI_H */

91
include/app/wm_crypto.h Normal file
View File

@ -0,0 +1,91 @@
/**
* @file wm_crypto.h
*
* @brief crypto driver module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_CRYPTO_H
#define WM_CRYPTO_H
/**
* @brief Encrypt plain data by 128 AES crypto
* @param[in] key the key for encryption
* @param[in] iv the IV value for encryption
* @param[in] data where the plain data stored
* @param[in] data_len length of the plain data to be encrypted
* @retval 0 finish Encryption successfully
* @retval -1 Error
* @note Encrypted data will be placed into the plain @data area
*
*/
int aes_128_cbc_encrypt (const u8 *key, const u8 *iv, u8 *data, size_t data_len) ;
/**
* @brief Decrypt data by 128 AES crypto
* @param[in] key the key for encryption
* @param[in] iv the IV value for encryption
* @param[in] data where the plain data stored
* @param[in] data_len length of the plain data to be decrypted
* @retval 0 finish Decryption successfully
* @retval -1 Error
* @note plain data will be placed into the encrypted @data area
*
*/
int aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data,
size_t data_len);
/**
* @brief XOR RC4 stream to given data with skip-stream-start
* @param[in] key RC4 key
* @param[in] keylen RC4 key length
* @param[in] data data to be XOR'ed with RC4 stream
* @param[in] data_len length of the plain data to be encrypted
* @retval 0 finish Encryption/Decryption successfully
* @retval -1 Error
* @note this function should be used for Encryption & Decryption both For the Encryption, the plain @data
* will be replaced by the encrypted output, and vice versa;
*/
int rc4(const u8 *key, size_t keylen, u8 *data, size_t data_len);
/**
* @brief MD5 hash for data vector
* @param[in] addr Pointers to the data area
* @param[in] len Lengths of the data block
* @param[in] mac Buffer for the hash (16 bytes)
* @retval 0 finish caculation successfully
* @retval -1 Error
* @note
*/
int md5(const u8 *addr, int len, u8 *mac);
/**
* @brief HMAC-MD5 over data buffer (RFC 2104)
* @param[in] key Key for HMAC operations
* @param[in] keylen Length of the key in bytes
* @param[in] data data to be caculated
* @param[in] data_len Lengths of the data block
* @param[in] mac Buffer for the hash (16 bytes)
* @retval 0 finish caculation successfully
* @retval -1 Error
* @note
*/
int hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len, u8 *mac);
/**
* @brief SHA1 hash for data vector
* @param[in] addr Pointers to the data area
* @param[in] len Lengths of the data block
* @param[in] mac Buffer for the hash (16 bytes)
* @retval 0 finish caculation successfully
* @retval -1 Error
* @note
*/
int sha1(const u8 *addr, int len, u8 *mac);
#endif

View File

@ -0,0 +1,91 @@
/**
* @file wm_dhcp_server.h
*
* @brief DHCP SERVER
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_DHCP_SERVER_H
#define WM_DHCP_SERVER_H
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup DHCPS_APIs DHCPS APIs
* @brief DHCP server APIs
*/
/**
* @addtogroup DHCPS_APIs
* @{
*/
/**
* @brief This function is used to start DHCP Server for a network
interface
*
* @param None
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
s8 tls_dhcps_start(void);
/**
* @brief This function is used to stop DHCP server
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_dhcps_stop(void);
/**
* @brief This function is used to get station's IP address by
MAC address
*
* @param[in] *mac STA's MAC address
*
* @retval ip_addr STA's IP address
* @retval NULL Not found match IP with MAC address
*
* @note None
*/
ip_addr_t *tls_dhcps_getip(const u8 *mac);
/**
* @brief This function is used to set DHCP server's DNS address
*
* @param[in] numdns the index of the DNS server to set must be 0 or 1
*
* @return None
*
* @note None
*/
void tls_dhcps_setdns(u8 numdns);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_DHCP_SERVER_H */

View File

@ -0,0 +1,66 @@
/**
* @file wm_dns_server.h
*
* @brief DNS SERVER
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_DNS_SERVER_H
#define WM_DNS_SERVER_H
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup DNSS_APIs DNSS APIs
* @brief DNS server APIs
*/
/**
* @addtogroup DNSS_APIs
* @{
*/
/**
* @brief This function is used to start DNS service
*
* @param[in] *dnsname Specify the server's dns name
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
s8 tls_dnss_start(u8 *dnsname);
/**
* @brief This function is used to stop DNS service
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_dnss_stop(void);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_DNS_SERVER_H */

View File

@ -0,0 +1,486 @@
/**
* @file wm_http_client.h
*
* @brief Http client APIs
*
* @author wanghf
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_HTTP_CLIENT_H
#define WM_HTTP_CLIENT_H
#include "wm_config.h"
#include "wm_type_def.h"
#ifdef BOOL
#undef BOOL
#endif
#ifdef UCHAR
#undef UCHAR
#endif
#ifdef CHAR
#undef CHAR
#endif
#ifdef UINT16
#undef UINT16
#endif
#ifdef INT16
#undef INT16
#endif
#ifdef UINT32
#undef UINT32
#endif
#ifdef INT32
#undef INT32
#endif
#ifdef UINT64
#undef UINT64
#endif
#ifdef INT64
#undef INT64
#endif
#ifdef ULONG
#undef ULONG
#endif
#ifdef LONG
#undef LONG
#endif
#define VOID void
typedef int BOOL;
typedef unsigned char UCHAR;
//typedef signed char CHAR;
typedef char CHAR;
typedef unsigned short UINT16;
typedef signed short INT16;
typedef unsigned int UINT32;
typedef signed int INT32;
typedef unsigned long long UINT64;
typedef long long INT64;
typedef unsigned long ULONG;
typedef signed long LONG;
/* HTTP Status, API Return codes */
/** HTTP Success status */
#define HTTP_CLIENT_SUCCESS 0
/** Unknown error */
#define HTTP_CLIENT_UNKNOWN_ERROR 1
/** an Invalid handle or possible bad pointer was passed to a function */
#define HTTP_CLIENT_ERROR_INVALID_HANDLE 2
/** Buffer too small or a failure while in memory allocation */
#define HTTP_CLIENT_ERROR_NO_MEMORY 3
/** an attempt to use an invalid socket handle was made */
#define HTTP_CLIENT_ERROR_SOCKET_INVALID 4
/** Can't send socket parameters */
#define HTTP_CLIENT_ERROR_SOCKET_CANT_SET 5
/** Error while resolving host name */
#define HTTP_CLIENT_ERROR_SOCKET_RESOLVE 6
/** Error while connecting to the remote server */
#define HTTP_CLIENT_ERROR_SOCKET_CONNECT 7
/** socket time out error */
#define HTTP_CLIENT_ERROR_SOCKET_TIME_OUT 8
/** Error while receiving data */
#define HTTP_CLIENT_ERROR_SOCKET_RECV 9
/** Error while sending data */
#define HTTP_CLIENT_ERROR_SOCKET_SEND 10
/** Error while receiving the remote HTTP headers */
#define HTTP_CLIENT_ERROR_HEADER_RECV 11
/** Could not find element within header */
#define HTTP_CLIENT_ERROR_HEADER_NOT_FOUND 12
/** The headers search clue was too large for the internal API buffer */
#define HTTP_CLIENT_ERROR_HEADER_BIG_CLUE 13
/** No content length was specified for the outgoing data. the caller should
specify chunking mode in the session creation */
#define HTTP_CLIENT_ERROR_HEADER_NO_LENGTH 14
/** The HTTP chunk token that was received from the server was too big and possibly wrong */
#define HTTP_CLIENT_ERROR_CHUNK_TOO_BIG 15
/** Could not authenticate with the remote host */
#define HTTP_CLIENT_ERROR_AUTH_HOST 16
/** Could not authenticate with the remote proxy */
#define HTTP_CLIENT_ERROR_AUTH_PROXY 17
/** Bad or not supported HTTP verb was passed to a function */
#define HTTP_CLIENT_ERROR_BAD_VERB 18
/** a function received a parameter that was too large */
#define HTTP_CLIENT_ERROR_LONG_INPUT 19
/** The session state prevents the current function from proceeding */
#define HTTP_CLIENT_ERROR_BAD_STATE 20
/** Could not parse the chunk length while in chunked transfer */
#define HTTP_CLIENT_ERROR_CHUNK 21
/** Could not parse curtail elements from the URL (such as the host name, HTTP prefix act') */
#define HTTP_CLIENT_ERROR_BAD_URL 22
/** Could not detect key elements in the received headers */
#define HTTP_CLIENT_ERROR_BAD_HEADER 23
/** Error while attempting to resize a buffer */
#define HTTP_CLIENT_ERROR_BUFFER_RSIZE 24
/** Authentication schema is not supported */
#define HTTP_CLIENT_ERROR_BAD_AUTH 25
/** The selected authentication schema does not match the server response */
#define HTTP_CLIENT_ERROR_AUTH_MISMATCH 26
/** an element was missing while parsing the digest authentication challenge */
#define HTTP_CLIENT_ERROR_NO_DIGEST_TOKEN 27
/** Digest algorithem could be MD5 or MD5-sess other types are not supported */
#define HTTP_CLIENT_ERROR_NO_DIGEST_ALG 28
/** Binding error */
#define HTTP_CLIENT_ERROR_SOCKET_BIND 29
/** Tls negotiation error */
#define HTTP_CLIENT_ERROR_TLS_NEGO 30
/** Feature is not (yet) implemented */
#define HTTP_CLIENT_ERROR_NOT_IMPLEMENTED 64
/** HTTP end of stream message */
#define HTTP_CLIENT_EOS 1000
// HTTP Session flags (Public flags)
#define HTTP_CLIENT_FLAG_KEEP_ALIVE 0x00000001 // Set the keep alive header
#define HTTP_CLIENT_FLAG_SEND_CHUNKED 0x00000002 // The outgoing should chunked
#define HTTP_CLIENT_FLAG_NO_CACHE 0x00000004 // Set the no cache header
#define HTTP_CLIENT_FLAG_ASYNC 0x00000008 // Currently not implemented
#define HTTP_CLIENT_FLAG_MULTIPART_FORM 0x00000010 // The outgoing should multipart/form-data
// HTTP Type Definitions
typedef UINT32 HTTP_SESSION_HANDLE;
typedef UINT32 HTTP_CLIENT_SESSION_FLAGS;
/******************************************************************************
*
* Section : HTTP API structures
*
******************************************************************************/
/* HTTP Type Definitions */
/** http seesion handle */
typedef u32 tls_http_session_handle_t;
/** http seesion flags */
typedef u32 tls_http_session_flags_t;
/** HTTP Supported authentication methods */
typedef enum _HTTP_AUTH_SCHEMA
{
AuthSchemaNone = 0,
AuthSchemaBasic,
AuthSchemaDigest,
AuthSchemaKerberos,
AuthNotSupported
} HTTP_AUTH_SCHEMA;
/** HTTP supported verbs */
typedef enum _HTTP_VERB
{
VerbGet = 0,
VerbHead,
VerbPost,
VerbPut,
VerbFwup,
VerbNotSupported
// Note: others verb such as connect and put are currently not supported
} HTTP_VERB;
/** Data structure that the caller can request at any time that will include
some information regarding the session */
typedef struct _HTTP_CLIENT
{
UINT32 HTTPStatusCode; // HTTP Status code (200 OK)
UINT32 RequestBodyLengthSent; // Total bytes sent (body only)
UINT32 ResponseBodyLengthReceived; // Total bytes received (body only)
UINT32 TotalResponseBodyLength; // as extracted from the “content-length" header
UINT32 HttpState;
} HTTP_CLIENT;
/** HTTP parameters */
typedef struct _HTTPParameters
{
CHAR* Uri;
CHAR* ProxyHost;
UINT32 UseProxy ;
UINT32 ProxyPort;
UINT32 Verbose;
CHAR* UserName;
CHAR* Password;
HTTP_AUTH_SCHEMA AuthType;
} HTTPParameters;
#if TLS_CONFIG_HTTP_CLIENT_TASK
/** the callback function of http clent for received */
typedef void (*http_client_recv_callback_fn)(HTTP_SESSION_HANDLE pSession, CHAR * data, UINT32 totallen, UINT32 datalen);
/** the callback function of http clent for err */
typedef void (*http_client_err_callback_fn)(HTTP_SESSION_HANDLE pSession, int err);
/** message of the http client */
typedef struct _http_client_msg
{
HTTP_SESSION_HANDLE pSession;
HTTPParameters param;
HTTP_VERB method;
CHAR* sendData;
UINT32 dataLen;
http_client_recv_callback_fn recv_fn;
http_client_err_callback_fn err_fn;
} http_client_msg;
#endif
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup HTTPC_APIs HTTPC APIs
* @brief HTTP client APIs
*/
/**
* @addtogroup HTTPC_APIs
* @{
*/
/******************************************************************************
*
* Section : HTTP API public interface
*
******************************************************************************/
/**
* @brief Allocate memory for a new HTTP Session
*
* @param[in] Flags HTTP Session internal API flags, 0 should be passed here
*
* @retval 0 failed
* @retval other HTTP Session handle
*
* @note None
*/
HTTP_SESSION_HANDLE HTTPClientOpenRequest (HTTP_CLIENT_SESSION_FLAGS Flags);
/**
* @brief Closes the active connection and free the corresponding memory
*
* @param[in] *pSession HTTP Session handle
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientCloseRequest (HTTP_SESSION_HANDLE *pSession);
/**
* @brief Sets the HTTP authentication schema
*
* @param[in] pSession HTTP Session handle
* @param[in] AuthSchema HTTP Supported authentication methods
* @param[in] *pReserved Reserved parameter
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientSetAuth (HTTP_SESSION_HANDLE pSession, HTTP_AUTH_SCHEMA AuthSchema, void *pReserved);
/**
* @brief Sets credentials for the target host
*
* @param[in] pSession HTTP Session handle
* @param[in] *pUserName User name
* @param[in] *pPassword Password
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientSetCredentials (HTTP_SESSION_HANDLE pSession, CHAR *pUserName, CHAR *pPassword);
/**
* @brief Sets all the proxy related parameters
*
* @param[in] pSession HTTP Session handle
* @param[in] *pProxyName The host name
* @param[in] nPort The proxy port number
* @param[in] *pUserName User name for proxy authentication (can be null)
* @param[in] *pPassword User password for proxy authentication (can be null)
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientSetProxy (HTTP_SESSION_HANDLE pSession, CHAR *pProxyName, UINT16 nPort, CHAR *pUserName, CHAR *pPassword);
/**
* @brief Sets the HTTP verb for the outgoing request
*
* @param[in] pSession HTTP Session handle
* @param[in] HttpVerb HTTP supported verbs
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientSetVerb (HTTP_SESSION_HANDLE pSession, HTTP_VERB HttpVerb);
/**
* @brief Add headers into the outgoing request
*
* @param[in] pSession HTTP Session
* @param[in] *pHeaderName The Header name
* @param[in] *pHeaderData The header data
* @param[in] nInsert Reserved, could be any
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientAddRequestHeaders (HTTP_SESSION_HANDLE pSession, CHAR *pHeaderName, CHAR *pHeaderData, BOOL nInsert);
/**
* @brief This function builds the request headers, performs a DNS resolution,
* opens the connection (if it was not opened yet by a previous request
* or if it has closed) and sends the request headers
*
* @param[in] pSession HTTP Session handle
* @param[in] *pUrl The requested URL
* @param[in] *pData Data to post to the server
* @param[in] nDataLength Length of posted data
* @param[in] TotalLength Valid only when http method is post
* TRUE: Post data to http server.
* FALSE: In a post request without knowing the total
* length in advance so return error or use chunking.
* @param[in] nTimeout Operation timeout
* @param[in] nClientPort Client side port 0 for none
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientSendRequest (HTTP_SESSION_HANDLE pSession, CHAR *pUrl, VOID *pData, UINT32 nDataLength, BOOL TotalLength, UINT32 nTimeout,UINT32 nClientPort);
/**
* @brief Write data to the remote server
*
* @param[in] pSession HTTP Session handle
* @param[in] *pBuffer Data to write to the server
* @param[in] nBufferLength Length of wtitten data
* @param[in] nTimeout Timeout for the operation
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientWriteData (HTTP_SESSION_HANDLE pSession, VOID *pBuffer, UINT32 nBufferLength, UINT32 nTimeout);
/**
* @brief Receives the response header on the connection and parses it.
* Performs any required authentication.
*
* @param[in] pSession HTTP Session handle
* @param[in] nTimeout Timeout for the operation
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientRecvResponse (HTTP_SESSION_HANDLE pSession, UINT32 nTimeout);
/**
* @brief Read data from the server. Parse out the chunks data
*
* @param[in] pSession HTTP Session handle
* @param[out] *pBuffer A pointer to a buffer that will be filled with the servers response
* @param[in] nBytesToRead The size of the buffer (numbers of bytes to read)
* @param[in] nTimeout Operation timeout in seconds
* @param[out] *nBytesRecived Count of the bytes that were received in this operation
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientReadData (HTTP_SESSION_HANDLE pSession, VOID *pBuffer, UINT32 nBytesToRead, UINT32 nTimeout, UINT32 *nBytesRecived);
/**
* @brief Fill the users structure with the session information
*
* @param[in] pSession HTTP Session handle
* @param[out] *HTTPClient The session information
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientGetInfo (HTTP_SESSION_HANDLE pSession, HTTP_CLIENT *HTTPClient);
/**
* @brief Initiate the headr searching functions and find the first header
*
* @param[in] pSession HTTP Session handle
* @param[in] *pSearchClue Search clue
* @param[out] *pHeaderBuffer A pointer to a buffer that will be filled with the header name and value
* @param[out] *nLength Count of the bytes that were received in this operation
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientFindFirstHeader (HTTP_SESSION_HANDLE pSession, CHAR *pSearchClue,CHAR *pHeaderBuffer, UINT32 *nLength);
/**
* @brief Find the next header.
*
* @param[in] pSession HTTP Session handle
* @param[out] *pHeaderBuffer A pointer to a buffer that will be filled with the header name and value
* @param[out] *nLength Count of the bytes that were received in this operation
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientGetNextHeader (HTTP_SESSION_HANDLE pSession, CHAR *pHeaderBuffer, UINT32 *nLength);
/**
* @brief Terminate a headers search session
*
* @param[in] pSession HTTP Session handle
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientFindCloseHeader (HTTP_SESSION_HANDLE pSession);
#if TLS_CONFIG_HTTP_CLIENT_TASK
/**
* @brief initialize task of the http client
*
* @param None
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int http_client_task_init(void);
/**
* @brief post message to the task of http client
*
* @param[in] msg pointer to the message
*
* @retval ERR_OK success
* @retval other failed
*
* @note None
*/
int http_client_post(http_client_msg * msg);
#endif /* TLS_CONFIG_HTTP_CLIENT_TASK */
/**
* @}
*/
/**
* @}
*/
#endif /* WM_HTTP_CLIENT_H */

15
include/app/wm_netif.h Normal file
View File

@ -0,0 +1,15 @@
/**
* @file wm_netif.h
*
* @brief ETHERNET INIT Interface
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_NETIF_H
#define WM_NETIF_H
#include "wm_config.h"
#include "wm_netif2.0.3.h"
#endif /* WM_NETIF_H */

437
include/app/wm_netif2.0.3.h Normal file
View File

@ -0,0 +1,437 @@
/**
* @file wm_netif2.0.3.h
*
* @brief netif203 module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_NETIF2_0_3_H
#define WM_NETIF2_0_3_H
#include "wm_config.h"
#include "wm_type_def.h"
#include "wm_sockets.h"
#include "wm_wifi.h"
#include "wm_params.h"
/** MACRO for callback EVENT to join AP or create soft-AP successfully */
#define NETIF_WIFI_JOIN_SUCCESS 0x1
/** MACRO for callback EVENT to fail to join AP */
#define NETIF_WIFI_JOIN_FAILED 0x2
/** MACRO for callback EVENT to disconnect from AP or destroy soft-AP */
#define NETIF_WIFI_DISCONNECTED 0x3
/** MACRO for callbck EVENT to get IP address */
#define NETIF_IP_NET_UP 0x4
/** MACRO for callback EVNET to create AP successfully */
#define NETIF_WIFI_SOFTAP_SUCCESS 0x5
/** MACRO for callback EVNET to create soft-AP failed */
#define NETIF_WIFI_SOFTAP_FAILED 0x6
/** MACRO for callback EVNET to close soft-AP */
#define NETIF_WIFI_SOFTAP_CLOSED 0x7
/** MACRO for callback EVNET to inform soft ap's net */
#define NETIF_IP_NET2_UP 0x8
#define NETIF_IPV6_NET_UP 0x9
/** These are the values for ip_addr_t.type */
#define IPADDR_TYPE_V4 0U
#define IPADDR_TYPE_V6 6U
#define IPADDR_TYPE_ANY 46U
#define IPV6_ADDR_MAX_NUM 3
#if 0
struct ip_addr {
u32_t addr;
};
typedef struct ip_addr ip_addr_t;
#endif
#if 0
struct ip4_addr {
u32_t addr;
};
typedef struct ip4_addr ip4_addr_t;
struct ip6_addr {
u32_t addr[4];
};
typedef struct ip6_addr ip6_addr_t;
#if (TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6)
typedef struct _ip_addr {
union {
ip6_addr_t ip6;
ip4_addr_t ip4;
} u_addr;
u8_t type;
} ip_addr_t;
#else
#if TLS_CONFIG_IPV4
typedef ip4_addr_t ip_addr_t;
#else
typedef ip6_addr_t ip_addr_t;
#endif
#endif
#endif
struct tls_ethif {
ip_addr_t ip_addr;
ip_addr_t netmask;
ip_addr_t gw;
#if TLS_CONFIG_IPV6
ip_addr_t ip6_addr[IPV6_ADDR_MAX_NUM];
#endif
ip_addr_t dns1;
ip_addr_t dns2;
u8 status; //0:net down; 1:net up
#if TLS_CONFIG_IPV6
u8 ipv6_status[IPV6_ADDR_MAX_NUM]; //0:net down; 1:net up
#endif
};
//type defination of netif status changed callback.
typedef void (*tls_netif_status_event_fn)(u8 status);
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup NETIF_APIs NETIF APIs
* @brief network interface APIs
*/
/**
* @addtogroup NETIF_APIs
* @{
*/
/**
* @brief This function is used to initialize TCP/IP Stack
*
* @param[in] None
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_ethernet_init(void);
/**
* @brief This function is used to get IP information stored in
tls_ethif struct
*
* @param[in] None
*
* @retval tls_ethif * Pointer to struct tls_ethif
*
* @note None
*/
struct tls_ethif * tls_netif_get_ethif(void);
/**
* @brief This function is used to set tls_ethif status
*
* @param[in] status net status, 0-up, 1-down
*
* @return None
*
* @note None
*/
void tls_netif_set_status(u8 status);
/**
* @brief This function is used to start DHCP Client
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_dhcp_start(void);
/**
* @brief This function is used to stop DHCP client
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_dhcp_stop(void);
/**
* @brief This function is used to change IP information
*
* @param[in] *ipaddr IP address
* @param[in] *netmask netmask
* @param[in] *gw default gateway
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_netif_set_addr(ip_addr_t *ipaddr,
ip_addr_t *netmask,
ip_addr_t *gw);
/**
* @brief This function is used to set dns servers
*
* @param[in] numdns index of the DNS server to set
must be < DNS_MAX_SERVERS
* @param[in] *dnsserver IP address of the DNS server to set
*
* @return None
*
* @note None
*/
void tls_netif_dns_setserver(u8 numdns, ip_addr_t *dnsserver);
/**
* @brief This function is used to bring up an interface,available
for processing traffic
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_netif_set_up(void);
/**
* @brief This function is used to bring down an interface,disabling
any traffic processing
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_netif_set_down(void);
/**
* @brief This function is used to add netif status changed callback
to event list,if exists, do nothing
*
* @param[in] event_fn pointer to tls_netif_status_event_fn
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_netif_add_status_event(tls_netif_status_event_fn event_fn);
/**
* @brief This function is used to remove netif status changed
callback function from event list,if not exists, do nothing
*
* @param[in] event_fn pointer to tls_netif_status_event_fn
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_netif_remove_status_event(tls_netif_status_event_fn event_fn);
/**
* @brief This function is used to get pointer of netif
*
* @param[in] None
*
* @retval pointer of netif
*
* @note None
*/
struct netif *tls_get_netif(void);
#if TLS_CONFIG_AP
/**
* @brief Start DHCP Server for a network interface
* *
* @retval DHCPS_ERR_SUCCESS - No error
* @retval DHCPS_ERR_MEM - Out of memory
* @retval DHCPS_ERR_LINKDOWN - The NI is inactive
*
* @note None
*/
INT8S tls_dhcps_start(void);
/**
* @brief This function is used to stop DHCP Server
*
* @param[in] None
*
* @retval None
*
* @note None
*/
void tls_dhcps_stop(void);
/**
* @brief Start the dns server's service
* *
* @retval DHCPS_ERR_SUCCESS - No error
* @retval DHCPS_ERR_MEM - Out of memory
* @retval DHCPS_ERR_LINKDOWN - The NI is inactive
* @retval DNSS_ERR_PARAM - Input parameter error
*
* @note None
*/
INT8S tls_dnss_start(INT8U * DnsName);
/**
* @brief Stop the dns server's service
*
* @param[in] None
*
* @retval None
*
* @note None
*/
void tls_dnss_stop(void);
/**
* @brief Get station's ip address by mac address
*
* @param[in] mac station's mac address
*
* @retval ip_addr station's ip address
*
* @note None
*/
ip_addr_t *tls_dhcps_getip(const u8_t *mac);
/**
* @brief Get station's mac address by ip address
*
* @param[in] ip station's ip address
*
* @retval u8* station's mac address
*
* @note None
*/
u8 *tls_dhcps_getmac(const ip_addr_t *ip);
#endif //TLS_CONFIG_AP
#if TLS_CONFIG_RMMS
/**
* @brief Start remote manager server.
* *
* @retval DHCPS_ERR_SUCCESS - No error
* @retval DHCPS_ERR_MEM - Out of memory
* @retval DHCPS_ERR_LINKDOWN - The NIF is inactive
*
* @note None
*/
INT8S tls_rmms_start(void);
/**
* @brief Disable remote manager server
*
* @param[in] None
*
* @retval None
*
* @note None
*/
void tls_rmms_stop(void);
#endif
#if TLS_CONFIG_AP
/**
* @brief This is used to bring up an interface for APSTA,available
for processing traffic
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note Can only be used at APSTA mode
*/
err_t tls_netif2_set_up(void);
/**
* @brief This function is used to bring down an interface for APSTA, disabling
any traffic processing
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note Can only be used at APSTA mode
*/
err_t tls_netif2_set_down(void);
/**
* @brief This function is used to change IP information for
a network interface for APSTA
*
* @param[in] *ipaddr IP address
* @param[in] *netmask netmask
* @param[in] *gw default gateway
*
* @retval 0 success
* @retval Minus failed
*
* @note Can only be used at APSTA mode
*/
err_t tls_netif2_set_addr(ip_addr_t *ipaddr,
ip_addr_t *netmask,
ip_addr_t *gw);
/***************************************************************************
* Function: tls_dhcps_setdns
* Description: Set dhcp server's dns address.
*
* Input: numdns: the index of the DNS server to set must be less than DNS_MAX_SERVERS
*
* Output: None
*
* Return: None
*
* Date : 2015-3-10
****************************************************************************/
/**
* @brief Set dhcp server's dns address
*
* @param[in] numdns the index of the DNS server to set must be less than DNS_MAX_SERVERS
*
* @retval None
*
* @note Can only be used at APSTA mode
*/
void tls_dhcps_setdns(u8_t numdns);
#endif
/**
* @}
*/
/**
* @}
*/
#endif //WM_NETIF_H

80
include/app/wm_ntp.h Normal file
View File

@ -0,0 +1,80 @@
/**
* @file wm_ntp.h
*
* @brief ntp module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_NTP_H
#define WM_NTP_H
#include "wm_type_def.h"
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup NTP_APIs NTP APIs
* @brief NTP APIs
*/
/**
* @addtogroup NTP_APIs
* @{
*/
/**
* @brief This function is used to get network time.
*
* @param None
*
* @retval time value
*
* @note None
*/
u32 tls_ntp_client(void);
/**
* @brief This function is used to set ntp servers.
*
* @param[in] *ipaddr xxx.xxx.xxx.xxx
* @param[in] server_no max num is three
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_ntp_set_server(char *ipaddr, int server_no);
/**
* @brief This function is used to query params of the ntp servers
*
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_ntp_query_sntpcfg(void);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_NTP_H */

159
include/app/wm_ssl_server.h Normal file
View File

@ -0,0 +1,159 @@
#ifndef _SSL_SERVER_H_
#define _SSL_SERVER_H_
#include "wm_config.h"
#include "HTTPClientWrapper.h"
#if 1//for doxygen
//#if TLS_CONFIG_SERVER_SIDE_SSL
#if TLS_CONFIG_USE_POLARSSL
#include "polarssl/config.h"
#include "polarssl/ssl.h"
#error "PolaSSL does not support ssl server now!"
#elif TLS_CONFIG_USE_MBEDTLS
typedef void tls_ssl_key_t;
#endif
//key type for tls_ssl_server_init
#define KEY_RSA 1
#define KEY_ECC 2
#define KEY_DH 3
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup SSL_SERVER_APIs SSL SERVER APIs
* @brief SSL Server APIs
*/
/**
* @addtogroup SSL_SERVER_APIs
* @{
*/
/**
* @brief This function is used to initialize SSL Server
*
* @param[in] *arg proto version: 0 - sslv3
* 1 - tls1.0
* 2 - tls1.1
* 3 - tls1.2
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_ssl_server_init(void * arg);
/**
* @brief This function is used to set SSL keys
*
* @param[in] **keys SSL key pointer
* @param[in] *certBuf SSL certificate
* @param[in] certLen SSL certificate length
* @param[in] *privBuf SSL private key
* @param[in] privLen SSL private key length
* @param[in] *CAbuf CA certificate
* @param[in] CAlen CA certificate length
* @param[in] keyType key type: KEY_RSA,KEY_ECC,KEY_DH
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_ssl_server_load_keys(tls_ssl_key_t **keys, unsigned char *certBuf,
int32 certLen, unsigned char *privBuf, int32 privLen,
unsigned char *CAbuf, int32 CAlen, int keyType);
/**
* @brief This function is used to set SSL Server working
*
* @param[in] **ssl_p SSL hanlde
* @param[in] fd socket number
* @param[in] *keys SSL keys
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_ssl_server_handshake(tls_ssl_t **ssl_p, int fd, tls_ssl_key_t *keys);
/**
* @brief This function is used to send data
*
* @param[in] *ssl SSL hanlde
* @param[in] s socket number
* @param[in] *sndbuf send buffer
* @param[in] len send length
* @param[in] flags some flags
*
* @retval > 0 success
* @retval <=0 failed
*
* @note None
*/
int tls_ssl_server_send(tls_ssl_t *ssl, int s,char *sndbuf, int len,int flags);
/**
* @brief This function is used to receive data
*
* @param[in] *ssl SSL hanlde
* @param[in] s socket number
* @param[in] *buf receive buffer
* @param[in] len receive buffer length
* @param[in] flags some flags
*
* @retval > 0 success
* @retval <=0 failed
*
* @note None
*/
int tls_ssl_server_recv(tls_ssl_t *ssl,int s,char *buf, int len,int flags);
/**
* @brief This function is used to close connection
*
* @param[in] *ssl SSL hanlde
* @param[in] s socket number
*
* @return None
*
* @note None
*/
void tls_ssl_server_close_conn(tls_ssl_t *ssl, int s);
/**
* @brief This function is used to close SSL Server
*
* @param[in] *keys SSL keys
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_ssl_server_close(tls_ssl_key_t * keys);
/**
* @}
*/
/**
* @}
*/
#endif /*TLS_CONFIG_SERVER_SIDE_SSL*/
#endif /*_SSL_SERVER_H_*/

View File

@ -0,0 +1,65 @@
/**
* @file wm_webserver.h
*
* @brief WEB SERVER
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef __WEBSERVER_H__
#define __WEBSERVER_H__
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup WEB_APIs WEB APIs
* @brief WEB server APIs
*/
/**
* @addtogroup WEB_APIs
* @{
*/
/**
* @brief This function is used to start WEB SERVER service
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_webserver_init(void);
/**
* @brief This function is used to deinit WEB SERVER service
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_webserver_deinit(void);
/**
* @}
*/
/**
* @}
*/
#endif /*__WEBSERVER_H__*/

View File

@ -0,0 +1,291 @@
/**
* @file wm_wifi_oneshot.h
*
* @brief Wi-Fi OneShot
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_WIFI_ONESHOT_H
#define WM_WIFI_ONESHOT_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wm_type_def.h>
#if (GCC_COMPILE==1)
#include "wm_ieee80211_gcc.h"
#else
#include <wm_ieee80211.h>
#endif
#include "wm_config.h"
#include "wm_bt_config.h"
/** DEBUG USE MAC FILTER START */
#define CONFIG_ONESHOT_MAC_FILTER 0
extern int tls_filter_module_srcmac(u8 *mac);
#define ONESHOT_ON 1
#define ONESHOT_OFF 0
/* ONE SHOT */
/** UDP MULTICAST ONE SHOT */
#define TLS_CONFIG_UDP_ONE_SHOT ONESHOT_ON
/** WinnerMicro ONSHOT */
#define TLS_CONFIG_UDP_LSD_SPECIAL (ONESHOT_ON&& TLS_CONFIG_UDP_ONE_SHOT)
/** AP ONESHOT */
#define TLS_CONFIG_AP_MODE_ONESHOT (ONESHOT_ON && TLS_CONFIG_AP)
#define TLS_CONFIG_WEB_SERVER_MODE (ONESHOT_ON && TLS_CONFIG_AP_MODE_ONESHOT)
#define TLS_CONFIG_SOCKET_MODE (ONESHOT_ON && TLS_CONFIG_AP_MODE_ONESHOT)
/** AIRKISS ONESHOT */
#define TLS_CONFIG_AIRKISS_MODE_ONESHOT (ONESHOT_OFF && TLS_CONFIG_UDP_ONE_SHOT)
#define AIRKISS_USE_SELF_WRITE 1
/** BLE ONESHOT */
#define TLS_CONFIG_BLE_WIFI_ONESHOT (ONESHOT_ON && (WM_BLE_INCLUDED == CFG_ON || WM_NIMBLE_INCLUDED == CFG_ON))
typedef enum{
ONESHOT_SCAN_START,
ONESHOT_SCAN_FINISHED,
ONESHOT_SWITCH_CHANNEL,
ONESHOT_STOP_TMP_CHAN_SWITCH,
ONESHOT_STOP_CHAN_SWITCH,
ONESHOT_HANDSHAKE_TIMEOUT,
ONESHOT_RECV_TIMEOUT,
ONESHOT_RECV_ERR,
ONESHOT_STOP_DATA_CLEAR,
ONESHOT_NET_UP,
AP_SOCK_S_MSG_SOCKET_RECEIVE_DATA,
AP_WEB_S_MSG_RECEIVE_DATA,
AP_SOCK_S_MSG_SOCKET_CREATE,
AP_SOCK_S_MSG_WJOIN_FAILD,
}ONESHOT_MSG_ENUM;
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup Oneshot_APIs Oneshot APIs
* @brief Wi-Fi oneshot APIs
*/
/**
* @addtogroup Oneshot_APIs
* @{
*/
/**
* @brief This function is used to set oneshot flag.
*
* @param[in] flag, 0: one shot closed
* 1: one shot open
* 2: AP+socket
* 3: AP+WEBSERVER
* 4: bt
*
* @param[out] None
*
* @retval 0: success
* -1: failed
*
* @note None
*/
int tls_wifi_set_oneshot_flag(u8 flag);
/**
* @brief This function is used to get oneshot flag.
*
* @param[in] None
*
* @param[out] None
*
* @retval 0: one shot closed
* 1: one shot open
* 2: AP+socket
* 3: AP+WEBSERVER
* 4: bt
*
* @note None
*/
int tls_wifi_get_oneshot_flag(void);
/**
* @}
*/
/**
* @}
*/
/**
* @brief Handle wild packets coming from the air.
*
* @param[in] *hdr point to ieee80211 data header
* @param[in] data_len data len of ieee80211 data
*
* @retval no mean
*
* @note None
*/
u8 tls_wifi_dataframe_recv(struct ieee80211_hdr *hdr, u32 data_len);
#if TLS_CONFIG_AIRKISS_MODE_ONESHOT
/**
* @brief This function is used to acknowledge app when airkiss process is done.
*
* @param[in] None
*
* @return None
*
* @note None
*/
void oneshot_airkiss_send_reply(void);
/**
* @brief This function is used to deal with airkiss's
wild packet
*
* @param[in] *data ieee80211 packet
* @param[in] data_len packet length
*
* @return None
*
* @note None
*/
void tls_airkiss_recv(u8 *data, u16 data_len);
/**
* @brief This function is used to start airkiss
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_airkiss_start(void);
/**
* @brief This function is used to stop airkiss
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_airkiss_stop(void);
/**
* @brief This function is used to change channel for airkiss
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_oneshot_airkiss_change_channel(void);
#endif /*TLS_CONFIG_AIRKISS_MODE_ONESHOT*/
/**
* @brief This function is used to init oneshot task
*
* @param[in] None
*
* @return None
*
* @note Not in use now
*/
int wm_oneshot_task_init(void);
/**
* @brief This function is used to stop oneshot timer
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_oneshot_switch_channel_tim_stop(struct ieee80211_hdr *hdr);
/**
* @brief This function is used to stop oneshot temp timer
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_oneshot_switch_channel_tim_temp_stop(void);
/**
* @brief handle if use bssid to connect wifi.
*
* @param[in] *ssid : ap name to connect
* @param[in] *ssid_len: ap name's length to connect
* @param[in] *bssid : ap bssid
*
* @retval no mean
*
* @note None
*/
int tls_oneshot_if_use_bssid(u8 *ssid, u8 *ssid_len, u8 *bssid);
/**
* @brief Find channel according to ssid
*
* @param[in] *ssid ssid to be compared
* @param[in] ssid_len ssid length
* @param[out] chlist chlist to be add according to ssid info
*
* @retval None
*
* @note None
*/
void tls_oneshot_find_chlist(u8 *ssid, u8 ssid_len, u16 *chlist);
/**
* @brief This function is to deal with oneshot event according netif status.
*
* @param[in] status:net status
*
* @param[out] None
*
* @retval None
*
* @note None
*/
void wm_oneshot_netif_status_event(u8 status );
#if TLS_CONFIG_WEB_SERVER_MODE
/**
* @brief This function is used to send web config msg to oneshot task.
*
* @param[in] None
*
* @param[out] None
*
* @retval None
*
* @note None
*/
void tls_oneshot_send_web_connect_msg(void);
#endif
#endif /*WM_WIFI_ONESHOT_H*/

View File

@ -0,0 +1,16 @@
#ifndef __CSI_CONFIG_H__
#define __CSI_CONFIG_H__
#define CONFIG_CHIP_SL04 1
#define CONFIG_KERNEL_FREERTOS 1
//#define CONFIG_KERNEL_NONE 1
#define CONFIG_HAVE_VIC 1
#define CONFIG_SEPARATE_IRQ_SP 1
#define CONFIG_ARCH_INTERRUPTSTACK 4096
#define CONFIG_IRQ_VECTOR_SIZE 256
#define USE_UART0_PRINT 1
#ifdef CONFIG_KERNEL_NONE
#define CONFIG_SYSTEM_SECURE 1
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,63 @@
/*
* Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/******************************************************************************
* @file csi_core.h
* @brief CSI Core Layer Header File
* @version V1.0
* @date 02. June 2017
******************************************************************************/
#ifndef _CORE_H_
#define _CORE_H_
#include <stdint.h>
#if defined(__CK801__) || defined(__E801__)
#include <core_801.h>
#elif defined(__CK802__) || defined(__E802__) || defined(__S802__)
#include <core_802.h>
#elif defined(__E803__) || defined(__S803__)
#include <core_803.h>
#elif defined(__CK803__) || defined(__CK804__) || defined(__E804__) || defined(__E804D__) || defined(__E804F__) || defined (__E804DF__)
#include <core_804.h>
#elif defined(__CK805__) || defined(__I805__) || defined(__I805F__)
#include <core_805.h>
#elif defined(__CK610__)
#include <core_ck610.h>
#elif defined(__CK810__) || defined(__C810__) || defined(__C810V__)
#include <core_810.h>
#elif defined(__CK807__) || defined(__C807__) || defined(__C807F__) || defined(__C807FV__)
#include <core_807.h>
#elif defined(__riscv)
#include <core_rv32.h>
#endif
#ifdef __riscv
#include <csi_rv32_gcc.h>
#else
#include <csi_gcc.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* _CORE_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,351 @@
/******************************************************************************
* @file csky_common_tables.h
* @brief This file has extern declaration for common tables like
* Bitreverse, reciprocal etc which are used across different functions.
* @version V1.0
* @date 20. Dec 2016
******************************************************************************/
/* ---------------------------------------------------------------------------
* Copyright (C) 2016 CSKY Limited. All rights reserved.
*
* Redistribution and use of this software in source and binary forms,
* with or without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of CSKY Ltd. nor the names of CSKY's contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission of CSKY Ltd.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
* -------------------------------------------------------------------------- */
#ifndef _CSKY_COMMON_TABLES_H
#define _CSKY_COMMON_TABLES_H
#include "csky_math.h"
extern const uint16_t cskyBitRevTable[1024];
extern const q15_t cskyRecipTableQ15[64];
extern const q31_t cskyRecipTableQ31[64];
extern const float32_t twiddleCoef_16[32];
extern const float32_t twiddleCoef_32[64];
extern const float32_t twiddleCoef_64[128];
extern const float32_t twiddleCoef_128[256];
extern const float32_t twiddleCoef_256[512];
extern const float32_t twiddleCoef_512[1024];
extern const float32_t twiddleCoef_1024[2048];
extern const float32_t twiddleCoef_2048[4096];
extern const float32_t twiddleCoef_4096[8192];
extern const q31_t twiddleCoef_16_q31[24];
extern const q31_t twiddleCoef_32_q31[48];
extern const q31_t twiddleCoef_64_q31[96];
extern const q31_t twiddleCoef_128_q31[192];
extern const q31_t twiddleCoef_256_q31[384];
extern const q31_t twiddleCoef_512_q31[768];
extern const q31_t twiddleCoef_1024_q31[1536];
extern const q31_t twiddleCoef_2048_q31[3072];
extern const q31_t twiddleCoef_4096_q31[6144];
extern const q15_t twiddleCoef_16_q15[24];
extern const q15_t twiddleCoef_32_q15[48];
extern const q15_t twiddleCoef_64_q15[96];
extern const q15_t twiddleCoef_128_q15[192];
extern const q15_t twiddleCoef_256_q15[384];
extern const q15_t twiddleCoef_512_q15[768];
extern const q15_t twiddleCoef_1024_q15[1536];
extern const q15_t twiddleCoef_2048_q15[3072];
extern const q15_t twiddleCoef_4096_q15[6144];
extern const float32_t twiddleCoef_rfft_32[32];
extern const float32_t twiddleCoef_rfft_64[64];
extern const float32_t twiddleCoef_rfft_128[128];
extern const float32_t twiddleCoef_rfft_256[256];
extern const float32_t twiddleCoef_rfft_512[512];
extern const float32_t twiddleCoef_rfft_1024[1024];
extern const float32_t twiddleCoef_rfft_2048[2048];
extern const float32_t twiddleCoef_rfft_4096[4096];
extern const float32_t twiddleCoef_rfft_8192[8192];
extern const q15_t realCoefAQ15_8192[8192];
extern const q31_t realCoefAQ31_8192[8192];
/*Tables for RFFT.*/
extern const q15_t ALIGN4 realCoefAQ15_32[32];
extern const q15_t ALIGN4 realCoefAQ15_64[64];
extern const q15_t ALIGN4 realCoefAQ15_128[128];
extern const q15_t ALIGN4 realCoefAQ15_256[256];
extern const q15_t ALIGN4 realCoefAQ15_512[512];
extern const q15_t ALIGN4 realCoefAQ15_1024[1024];
extern const q15_t ALIGN4 realCoefAQ15_2048[2048];
extern const q15_t ALIGN4 realCoefAQ15_4096[4096];
extern const q31_t realCoefAQ31_32[32];
extern const q31_t realCoefAQ31_64[64];
extern const q31_t realCoefAQ31_128[128];
extern const q31_t realCoefAQ31_256[256];
extern const q31_t realCoefAQ31_512[512];
extern const q31_t realCoefAQ31_1024[1024];
extern const q31_t realCoefAQ31_2048[2048];
extern const q31_t realCoefAQ31_4096[4096];
extern const float32_t realCoefA[8192];
extern const float32_t realCoefB[8192];
/*Tables for DCT4*/
extern const q15_t ALIGN4 WeightsQ15_128[128+2];
extern const q15_t ALIGN4 WeightsQ15_512[512+2];
extern const q15_t ALIGN4 WeightsQ15_2048[2048+2];
extern const q15_t ALIGN4 WeightsQ15_8192[8192+2];
extern const q15_t ALIGN4 cos_factorsQ15_128[128];
extern const q15_t ALIGN4 cos_factorsQ15_512[512];
extern const q15_t ALIGN4 cos_factorsQ15_2048[2048];
extern const q15_t ALIGN4 cos_factorsQ15_8192[8192];
extern const q31_t WeightsQ31_128[128+2];
extern const q31_t WeightsQ31_512[512+2];
extern const q31_t WeightsQ31_2048[2048+2];
extern const q31_t WeightsQ31_8192[8192+2];
extern const q31_t cos_factorsQ31_128[128];
extern const q31_t cos_factorsQ31_512[512];
extern const q31_t cos_factorsQ31_2048[2048];
extern const q31_t cos_factorsQ31_8192[8192];
extern const float32_t Weights_128[128+2];
extern const float32_t Weights_512[512+2];
extern const float32_t Weights_2048[2048+2];
extern const float32_t Weights_8192[8192+2];
extern const float32_t cos_factors_128[128];
extern const float32_t cos_factors_512[512];
extern const float32_t cos_factors_2048[2048];
extern const float32_t cos_factors_8192[8192];
/* floating-point bit reversal tables */
#define CSKYBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 )
#define CSKYBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 )
#define CSKYBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 )
#define CSKYBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
#define CSKYBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
#define CSKYBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
#define CSKYBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800)
#define CSKYBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808)
#define CSKYBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032)
extern const uint16_t cskyBitRevIndexTable16[CSKYBITREVINDEXTABLE__16_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable32[CSKYBITREVINDEXTABLE__32_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable64[CSKYBITREVINDEXTABLE__64_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable128[CSKYBITREVINDEXTABLE_128_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable256[CSKYBITREVINDEXTABLE_256_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable512[CSKYBITREVINDEXTABLE_512_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable1024[CSKYBITREVINDEXTABLE1024_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable2048[CSKYBITREVINDEXTABLE2048_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable4096[CSKYBITREVINDEXTABLE4096_TABLE_LENGTH];
/* fixed-point bit reversal tables */
#define CSKYBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 )
#define CSKYBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 )
#define CSKYBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 )
#define CSKYBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 )
#define CSKYBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 )
#define CSKYBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 )
#define CSKYBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 )
#define CSKYBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984)
#define CSKYBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032)
extern const uint16_t cskyBitRevIndexTable_fixed_16[CSKYBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_32[CSKYBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_64[CSKYBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_128[CSKYBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_256[CSKYBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_512[CSKYBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_1024[CSKYBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_2048[CSKYBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_4096[CSKYBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH];
/* Tables for Fast Math Sine and Cosine */
extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1];
extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1];
extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1];
/*Table for Fast math pow*/
extern const log2_cof1 ui;
extern const log2_cof2 vj;
extern const exp_cof1 coar;
extern const exp_cof2 fine;
/*Table for Fast math pow2*/
extern const float64_t exp2_accuratetable[512];
extern const float32_t exp2_deltatable[512];
/*Table for Fast math pow2*/
extern const mynumber Iu[182];
extern const mynumber Iv[362];
extern const mynumber Lu[182][2];
extern const mynumber Lv[362][2];
/*constant for Fast math*/
const static mynumber
nZERO = {{0, 0x80000000}}, /* -0.0 */
INF = {{0x00000000, 0x7ff00000}}, /* INF */
nINF = {{0x00000000, 0xfff00000}}, /* -INF */
sqrt_2 = {{0x667f3bcc, 0x3ff6a09e}}, /* sqrt(2) */
ln2a = {{0xfefa3800, 0x3fe62e42}}, /* ln(2) 43 bits */
ln2b = {{0x93c76730, 0x3d2ef357}}, /* ln(2)-ln2a */
bigu = {{0xfffffd2c, 0x4297ffff}}, /* 1.5*2**42 -724*2**-10 */
bigv = {{0xfff8016a, 0x4207ffff}}, /* 1.5*2**33-1+362*2**-19 */
t52 = {{0x00000000, 0x43300000}}, /* 2**52 */
two52e = {{0x000003ff, 0x43300000}}, /* 2**52' */
//nan = {{0x00000000, 0x7ff80000}}, /* NAN */
t256 = {{0, 0x4ff00000}}, /* 2^256 */
ln_two1 = {{0xFEFA3800, 0x3FE62E42}}, /* 0.69314718055989033 */
ln_two2 = {{0x93C76730, 0x3D2EF357}}, /* 5.4979230187083712e-14*/
log2e = {{0x652B82FE, 0x3FF71547}}, /* 1.4426950408889634 */
ep2 = {{0x000004DC, 0x3FE00000}}, /* 0.50000000000013811 */
ep3 = {{0x55555A0F, 0x3FC55555}}, /* 0.16666666666670024 */
three33 = {{0, 0x42180000}}, /* 25769803776 */
three51 = {{0, 0x43380000}}; /* 6755399441055744 */
const static float64_t
p2 = -0.5, p3 = 3.3333333333333333333e-1, p4 = -0.25,
q2 = -0.5, q3 = 3.3333333333331404e-01, q4 = -2.4999999999996436e-01,
q5 = 2.0000010500004459e-01, q6 = -1.6666678916688004e-01,
r3 = 3.33333333333333333372884096563030E-01,
r4 = -2.50000000000000000213574153875908E-01,
r5 = 1.99999999999683593814072199830603E-01,
r6 = -1.66666666666065494878165510225378E-01,
r7 = 1.42857517857114380606360005067609E-01,
r8 = -1.25000449999974370683775964001702E-01,
s3 = 0.333251953125000000e0,
ss3 = 8.138020833333333333e-05,
s4 = -2.500000000000000000e-01,
s5 = 1.999999999999960937e-01,
s6 = -1.666666666666592447e-01,
s7 = 1.428571845238194705e-01;
// s8 = -1.250000500000149097e-01;
const static float64_t huge = 1.0e300, tiny = 1.0e-300;
const static float64_t err_0 = 1.000014, err_1 = 0.000016, zero = 0.0;
const static q31_t bigint = 0x40862002,
badint = 0x40876000, smallint = 0x3C8fffff;
const static q31_t hugeint = 0x7fffffff, infint = 0x7ff00000;
static const mynumber
/* polynomial I */
a2 = {{0x0001aa8f, 0xbfe00000} }, /* -0.500... */
a3 = {{0x55588d2e, 0x3fd55555} }, /* 0.333... */
/*polynomial II */
b0 = {{0x55555555, 0x3fd55555} }, /* 0.333... */
b1 = {{0xffffffbb, 0xbfcfffff} }, /* -0.249... */
b2 = {{0x9999992f, 0x3fc99999} }, /* 0.199... */
b3 = {{0x556503fd, 0xbfc55555} }, /* -0.166... */
b4 = {{0x925b3d62, 0x3fc24924} }, /* 0.142... */
b5 = {{0x160472fc, 0xbfbffffe} }, /* -0.124... */
b6 = {{0x25db58ac, 0x3fbc71c5} }, /* 0.111... */
b7 = {{0x11a2a61c, 0xbfb9a4ac} }, /* -0.100... */
b8 = {{0x0df2b591, 0x3fb75077} }, /* 0.091... */
/*polynomial III */
c2 = {{0x00000000, 0xbfe00000} }, /* -1/2 */
c3 = {{0x55555555, 0x3fd55555} }, /* 1/3 */
c4 = {{0x00000000, 0xbfd00000} }, /* -1/4 */
c5 = {{0x9999999a, 0x3fc99999} }, /* 1/5 */
/*polynomial IV */
d2 = {{0x00000000, 0xbfe00000} }, /* -1/2 */
dd2 = {{0x00000000, 0x00000000} }, /* -1/2-d2 */
d3 = {{0x55555555, 0x3fd55555} }, /* 1/3 */
dd3 = {{0x55555555, 0x3c755555} }, /* 1/3-d3 */
d4 = {{0x00000000, 0xbfd00000} }, /* -1/4 */
dd4 = {{0x00000000, 0x00000000} }, /* -1/4-d4 */
d5 = {{0x9999999a, 0x3fc99999} }, /* 1/5 */
dd5 = {{0x9999999a, 0xbc699999} }, /* 1/5-d5 */
d6 = {{0x55555555, 0xbfc55555} }, /* -1/6 */
dd6 = {{0x55555555, 0xbc655555} }, /* -1/6-d6 */
d7 = {{0x92492492, 0x3fc24924} }, /* 1/7 */
dd7 = {{0x92492492, 0x3c624924} }, /* 1/7-d7 */
d8 = {{0x00000000, 0xbfc00000} }, /* -1/8 */
dd8 = {{0x00000000, 0x00000000} }, /* -1/8-d8 */
d9 = {{0x1c71c71c, 0x3fbc71c7} }, /* 1/9 */
dd9 = {{0x1c71c71c, 0x3c5c71c7} }, /* 1/9-d9 */
d10 = {{0x9999999a, 0xbfb99999} }, /* -1/10 */
dd10 = {{0x9999999a, 0x3c599999} }, /* -1/10-d10 */
d11 = {{0x745d1746, 0x3fb745d1} }, /* 1/11 */
d12 = {{0x55555555, 0xbfb55555} }, /* -1/12 */
d13 = {{0x13b13b14, 0x3fb3b13b} }, /* 1/13 */
d14 = {{0x92492492, 0xbfb24924} }, /* -1/14 */
d15 = {{0x11111111, 0x3fb11111} }, /* 1/15 */
d16 = {{0x00000000, 0xbfb00000} }, /* -1/16 */
d17 = {{0x1e1e1e1e, 0x3fae1e1e} }, /* 1/17 */
d18 = {{0x1c71c71c, 0xbfac71c7} }, /* -1/18 */
d19 = {{0xbca1af28, 0x3faaf286} }, /* 1/19 */
d20 = {{0x9999999a, 0xbfa99999} }, /* -1/20 */
/*constants */
h1 = {{0x00000000, 0x3fd2e000} }, /* 151/2**9 */
h2 = {{0x00000000, 0x3f669000} }, /* 361/2**17 */
delu = {{0x00000000, 0x3f700000} }, /* 1/2**8 */
delv = {{0x00000000, 0x3ef00000} }, /* 1/2**16 */
e1 = {{0x00000000, 0x3bbcc868} }, /* 6.095e-21 */
e2 = {{0x00000000, 0x3c1138ce} }, /* 2.334e-19 */
e3 = {{0x00000000, 0x3aa1565d} }, /* 2.801e-26 */
e4 = {{0x00000000, 0x39809d88} }, /* 1.024e-31 */
e[4] = {{{0x00000000, 0x37da223a} },/* 1.2e-39 */
{{0x00000000, 0x35c851c4} }, /* 1.3e-49 */
{{0x00000000, 0x2ab85e51} }, /* 6.8e-103 */
{{0x00000000, 0x17383827} }},/* 8.1e-197 */
two54 = {{0x00000000, 0x43500000} }, /* 2**54 */
u03 = {{0xeb851eb8, 0x3f9eb851} }; /* 0.03 */
#define SQRT_2 sqrt_2.x
#define DEL_U delu.x
#define DEL_V delv.x
#define LN2A ln2a.x
#define LN2B ln2b.x
#define E1 e1.x
#define E2 e2.x
#define E3 e3.x
#define E4 e4.x
#define U03 u03.x
#define HALF 0x1.0p-1 /* 1/2 */
#define MHALF -0x1.0p-1 /* -1/2 */
/*coeffient for log2 funtion*/
static const float64_t
ln2 = 0.69314718055994530942,
two54_d = 1.80143985094819840000e+16, /* 43500000 00000000 */
Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
/*coeffient for log10 function*/
static const float64_t
ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
/*constant for log10 function*/
static const float64_t
TWO1023 = 8.988465674311579539e+307,
TWOM1000 = 9.3326361850321887899e-302;
#endif /* CSKY_COMMON_TABLES_H */

View File

@ -0,0 +1,140 @@
/******************************************************************************
* @file csky_const_structs.h
* @brief This file has constant structs that are initialized for
* user convenience. For example, some can be given as
* arguments to the csky_cfft_f32() function.
* @version V1.0
* @date 20. Dec 2016
******************************************************************************/
/* ---------------------------------------------------------------------------
* Copyright (C) 2016 CSKY Limited. All rights reserved.
*
* Redistribution and use of this software in source and binary forms,
* with or without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of CSKY Ltd. nor the names of CSKY's contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission of CSKY Ltd.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
* -------------------------------------------------------------------------- */
#ifndef _CSKY_CONST_STRUCTS_H
#define _CSKY_CONST_STRUCTS_H
#include "csky_math.h"
#include "csky_common_tables.h"
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len16;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len32;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len64;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len128;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len256;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len512;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len1024;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len2048;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len4096;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len16;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len32;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len64;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len128;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len256;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len512;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len1024;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len2048;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len4096;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len16;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len32;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len64;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len128;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len256;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len512;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len1024;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len2048;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len4096;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len32;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len64;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len128;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len256;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len512;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len1024;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len2048;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len4096;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len8192;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len32;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len64;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len128;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len256;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len512;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len1024;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len2048;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len4096;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len8192;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len32;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len64;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len128;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len256;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len512;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len1024;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len2048;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len4096;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len8192;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len32;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len64;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len128;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len256;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len512;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len1024;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len2048;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len4096;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len8192;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len32;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len64;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len128;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len256;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len512;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len1024;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len2048;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len4096;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len8192;
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len128;
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len512;
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len2048;
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len8192;
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len128;
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len512;
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len2048;
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len8192;
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len128;
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len512;
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len2048;
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len8192;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,140 @@
/******************************************************************************
* @file csky_vdsp2_const_structs.h
* @brief This file has constant structs that are initialized for
* user convenience. For example, some can be given as
* arguments to the csky_vdsp2_cfft_f32() function.
* @version V1.0
* @date 20. Dec 2016
******************************************************************************/
/* ---------------------------------------------------------------------------
* Copyright (C) 2016 CSKY Limited. All rights reserved.
*
* Redistribution and use of this software in source and binary forms,
* with or without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of CSKY Ltd. nor the names of CSKY's contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission of CSKY Ltd.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
* -------------------------------------------------------------------------- */
#ifndef _CSKY_CONST_STRUCTS_H
#define _CSKY_CONST_STRUCTS_H
#include "csky_vdsp2_math.h"
#include "csky_common_tables.h"
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len16;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len32;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len64;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len128;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len256;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len512;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len1024;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len2048;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len4096;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len16;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len32;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len64;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len128;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len256;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len512;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len1024;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len2048;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len4096;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len16;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len32;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len64;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len128;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len256;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len512;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len1024;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len2048;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len4096;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len32;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len64;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len128;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len256;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len512;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len1024;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len2048;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len4096;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len8192;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len32;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len64;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len128;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len256;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len512;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len1024;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len2048;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len4096;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len8192;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len32;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len64;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len128;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len256;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len512;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len1024;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len2048;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len4096;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len8192;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len32;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len64;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len128;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len256;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len512;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len1024;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len2048;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len4096;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len8192;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len32;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len64;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len128;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len256;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len512;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len1024;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len2048;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len4096;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len8192;
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len128;
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len512;
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len2048;
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len8192;
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len128;
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len512;
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len2048;
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len8192;
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len128;
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len512;
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len2048;
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len8192;
#endif

File diff suppressed because it is too large Load Diff

248
include/bt/wm_ble.h Normal file
View File

@ -0,0 +1,248 @@
/**
* @file wm_ble.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_BLE_H
#define WM_BLE_H
#include "wm_bt_def.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BLE_APIs BLE APIs
* @brief BLE APIs
*/
/**
* @addtogroup BLE_APIs
* @{
*/
/**
* @brief initialize the application callback function
*
* @param[in] *p_callback pointer on callback function
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_dm_init(tls_ble_dm_callback_t callback);
/**
* @brief start/stop ble advertisement
*
* @param[in] start 1 connectable and discoverable; 2 disconnectable and discoverable; 0 stop
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_adv(uint8_t adv_state);
/**
* @brief configure the advertisment content
*
* @param[in] *data @ref btif_dm_adv_data_t
*
* @retval @ref tls_bt_status_t
*
* @note if pure_data equals to true, the filed of manufacturer equals to all fileds of advetisement data.
* otherwise, the filed manufacturer will be advertised in 0xFF filed.
*
*/
tls_bt_status_t tls_ble_set_adv_data(tls_ble_dm_adv_data_t *data);
/**
* @brief configure the advertisment parameters
*
* @param[in] *param @ref btif_dm_adv_param_t
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_set_adv_param(tls_ble_dm_adv_param_t *param);
/**
* @brief configure the advertisment extented parameters
*
* @param[in] *param @ref tls_ble_dm_adv_ext_param_t
*
* @retval @ref tls_bt_status_t
*
* @note if you know how to config all the parameters, you can use this function; otherwise, tls_ble_set_adv_param will be recommanded strongly;
*/
tls_bt_status_t tls_ble_set_adv_ext_param(tls_ble_dm_adv_ext_param_t *param);
/**
* @brief start/stop ble scan
*
* @param[in] start TRUE enable; FALSE disable
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_scan(bool start);
/**
* @brief configure the scan parameters
*
* @param[in] window scan window size
* @param[in] interval scan interval length
* @param[in] scan mode 0 passive scan; 1 active scan;
*
* @retval @ref tls_bt_status_t
*
* @note interval should greater or equals to windows,
* both range should be within (0x0004, 0x4000)
*/
tls_bt_status_t tls_ble_set_scan_param(int window, int interval, uint8_t scan_mode);
/**
* @brief enable a async process evt
*
* @param[in] id user specific definition
* @param[in] *p_callback callback function
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_dm_evt_triger(int id, tls_ble_dm_triger_callback_t callback);
/**
* @brief configure the max transmit unit
*
* @param[in] *bd_addr the remote device address
* @param[in] length range [27 - 251]
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_dm_set_data_length(tls_bt_addr_t *bd_addr, uint16_t length);
/**
* @brief configure the ble privacy
*
* @param[in] enable TRUE: using rpa/random address, updated every 15 mins
** FALSE: public address
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_dm_set_privacy(uint8_t enable);
/**
* @brief update the connection parameters
*
* @param[in] *bd_addr remote device address
* @param[in] min_interval
* @param[in] max_interval
* @param[in] latency
* @param[in] timeout
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_conn_parameter_update(const tls_bt_addr_t *bd_addr,
int min_interval,
int max_interval,
int latency,
int timeout);
/**
* @brief read the remote device signal strength connected
*
* @param[in] *bd_addr remote device address
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_dm_read_remote_rssi(const tls_bt_addr_t *bd_addr);
/**
* @brief config the io capabilities of local device
*
* @param[in] io_cap
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_set_sec_io_cap(uint8_t io_cap);
/**
* @brief config the auth requirement of local device
*
* @param[in] auth_req
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_set_sec_auth_req(uint8_t auth_req);
/**
* @brief This function is called to ensure that connection is
* encrypted. Should be called only on an open connection.
* Typically only needed for connections that first want to
* bring up unencrypted links, then later encrypt them.
* @param[in]sec_act - This is the security action to indicate
* what knid of BLE security level is required for
* the BLE link if the BLE is supported
* @param[in]bd_addr - Address of the peer device
* @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_set_sec(const tls_bt_addr_t *bd_addr, uint8_t sec_act);
/**
* @brief only used to start/stop ble advertisement
*
* @param[in] start 1 start advertisement; 0 stop advertisement;
* @param[in] duration valid for start advertisement. 0 for forever, otherwise the last seconds of advertisement
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_gap_adv(uint8_t start, int duration);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_BLE_H */

480
include/bt/wm_ble_gatt.h Normal file
View File

@ -0,0 +1,480 @@
/**
* @file wm_ble_gatt.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_BLE_GATT_H
#define WM_BLE_GATT_H
#include "wm_bt_def.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BLE_GATT_Client_APIs BLE GATT Client APIs
* @brief BLE GATT Client APIs
*/
/**
* @addtogroup BLE_GATT_Client_APIs
* @{
*/
/**
* @brief initialize the btif_gatt_client callback function
*
* @param[in] *p_callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_app_init(tls_ble_callback_t callback);
/**
* @brief free the tls_ble_callback_t pointer
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_app_deinit(void);
/**
* @brief this function is called to register client application
*
* @param[in] *uuid pointer on uuid
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_app_register(tls_bt_uuid_t *uuid);
/**
* @brief this function is called to unregister client application
*
* @param[in] client_if gatt client access interface
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_app_unregister(uint8_t client_if);
/**
* @brief this function is called to open an BLE connection to a remote
* device or add a background auto connection
*
* @param[in] client_if gatt client access interface
* @param[in] *bd_addr remote device bluetooth device address
* @param[in] is_direct direct connection or background auto connection
* @param[in] transport specific BLE/BR-EDR/mixed
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_connect(uint8_t client_if, const tls_bt_addr_t *bd_addr, uint8_t is_direct, int transport);
/**
* @brief this function is called to disconnect with gatt server connection
*
* @param[in] client_if gatt client access interface
* @param[in] *bd_addr remote device bluetooth device address
* @param[in] conn_id connection ID to be closed
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_disconnect(uint8_t client_if, const tls_bt_addr_t *bd_addr, int conn_id);
/**
* @brief start or stop advertisements to listen for incoming connections
*
* @param[in] client_if gatt client access interface
* @param[in] start start: 1; stop 0
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_listen(uint8_t client_if, uint8_t start);
/**
* @brief clear the attribute cache for a given device
*
* @param[in] client_if gatt client access interface
* @param[in] *bd_addr remote device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_refresh(uint8_t client_if, const tls_bt_addr_t *bd_addr);
/**
* @brief enumerate all GATT services on a connected device
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] *filter_uuid filter this uuid
*
* @retval @ref tls_bt_status_t
*
* @note Optionally, the results can be filtered for a given UUID
*/
tls_bt_status_t tls_ble_client_search_service(uint16_t conn_id, tls_bt_uuid_t *filter_uuid);
/**
* @brief write a remote characteristic
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] handle the character attribute handle
* @param[in] write_type the type of attribute write operation
* @param[in] len length of the value to be written
* @param[in] auth_req authentication request
* @param[in] *p_value the value to be written
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_write_characteristic(uint16_t conn_id, uint16_t handle, int write_type, int len, int auth_req, char *p_value);
/**
* @brief read a characteristic on a remote device
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] handle the character attribute handle
* @param[in] auth_req authentication request
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_read_characteristic(uint16_t conn_id, uint16_t handle, int auth_req);
/**
* @brief read the descriptor for a given characteristic
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] handle the character attribute handle
* @param[in] auth_req authentication request
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_read_descriptor(uint16_t conn_id, uint16_t handle, int auth_req);
/**
* @brief write a remote descriptor for a given characteristic
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] handle the character attribute handle
* @param[in] write_type the type of attribute write operation
* @param[in] len length of the value to be written
* @param[in] auth_req authentication request
* @param[in] *p_value the value to be written
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_write_descriptor(uint16_t conn_id, uint16_t handle, int write_type, int len, int auth_req, char *p_value);
/**
* @brief execute a prepared write operation
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] execute execute or cancel
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_execute_write(uint16_t conn_id, int execute);
/**
* @brief Register to receive notifications or indications for a given
* characteristic
*
* @param[in] client_if gatt client access interface
* @param[in] *bd_addr the target server address
* @param[in] handle the attribute handle of characteristic
* @param[in] conn_id the connection id
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_register_for_notification(int client_if, const tls_bt_addr_t *bd_addr, uint16_t handle, uint16_t conn_id);
/**
* @brief deregister a previous request for notifications/indications
*
* @param[in] client_if gatt client access interface
* @param[in] *bd_addr the target server address
* @param[in] handle the attribute handle of characteristic
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_deregister_for_notification(int client_if, const tls_bt_addr_t *bd_addr, uint16_t handle,uint16_t conn_id);
/**
* @brief configure the MTU for a given connection
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] mtu the max transmit unit of this connection
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_configure_mtu(uint16_t conn_id, uint16_t mtu);
/**
* @brief get gatt db content
*
* @param[in] conn_id connection indicator return value when connected
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_get_gatt_db(uint16_t conn_id);
/**
* @}
*/
/**
* @defgroup BLE_GATT_Server_APIs BLE GATT Server APIs
* @brief BLE GATT Server APIs
*/
/**
* @addtogroup BLE_GATT_Server_APIs
* @{
*/
/**
* @brief initialize the btif_gatt_server callback function
*
* @param[in] *p_callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_app_init(tls_ble_callback_t callback);
/*******************************************************************************
**
** Function tls_ble_server_app_deinit
**
** Description free the tls_ble_callback_t pointer
**
** Parameters None
**
** Returns TLS_BT_STATUS_SUCCESS
** TLS_BT_STATUS_DONE
**
*******************************************************************************/
tls_bt_status_t tls_ble_server_app_deinit();
/**
* @brief this function is called to register server application
*
* @param[in] *uuid pointer on uuid
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_app_register(tls_bt_uuid_t *uuid);
/**
* @brief this function is called to unregister server application
*
* @param[in] server_if assigned after app registering
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_app_unregister(uint8_t server_if);
/**
* @brief create a new service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] inst_id instance identifier of this service
* @param[in] primay is primary or not service
* @param[in] *uuid the id property of this service
* @param[in] num_handles number of handle requested for this service
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_add_service(uint8_t server_if, int inst_id, int primay, tls_bt_uuid_t *uuid, int num_handles);
/**
* @brief add a characteristic to a service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] service_handle the handle of this service assigned when creating a service
* @param[in] *uuid the id property of this characteristic
* @param[in] properties access properties
* @param[in] permission access permission
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_add_characteristic(uint8_t server_if, uint16_t service_handle, tls_bt_uuid_t *uuid, int properties, int permission);
/**
* @brief add a descriptor to a given service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] service_handle the handle of this service assigned when creating a service
* @param[in] *uuid the id property of this characteristic
* @param[in] permission access permission
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_add_descriptor(uint8_t server_if, uint16_t service_handle, tls_bt_uuid_t *uuid, int permissions);
/**
* @brief starts a local service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] service_handle the handle of this service assigned when creating a service
* @param[in] transport tranport type, BLE/BR-EDR/MIXED
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_start_service(uint8_t server_if, uint16_t service_handle, int transport);
/**
* @brief stop a local service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] service_handle the handle of this service assigned when creating a service
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_stop_service(uint8_t server_if, uint16_t service_handle);
/**
* @brief delete a local service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] service_handle the handle of this service assigned when creating a service
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_delete_service(uint8_t server_if, uint16_t service_handle);
/**
* @brief create a connection to a remote peripheral
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] *bd_addr the remote device address
* @param[in] is_direct true direct connection; false: background auto connection
* @param[in] transport tranport type, BLE/BR-EDR/MIXED
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_connect(uint8_t server_if, const tls_bt_addr_t *bd_addr, uint8_t is_direct, int transport);
/**
* @brief disconnect an established connection or cancel a pending one
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] *bd_addr the remote device address
* @param[in] conn_id connection id create when connection established
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_disconnect(uint8_t server_if, const tls_bt_addr_t *bd_addr, uint16_t conn_id);
/**
* @brief send value indication to a remote device
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] attribute_handle the handle of characteristic
* @param[in] conn_id connection id create when connection established
* @param[in] len the length of value to be sent
* @param[in] confirm need the remote device acked after receive the message , normally
* Whether a confirmation is required. FALSE sends a GATT notification,
* TRUE sends a GATT indication
* @param[in] *p_value the value to be written
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_send_indication(uint8_t server_if, uint16_t attribute_handle, uint16_t conn_id, int len, int confirm, char *p_value);
/**
* @brief send a response to a read/write operation
*
* @param[in] conn_id connection id create when connection established
* @param[in] trans_id the transation identifier
* @param[in] status TODO:
* @param[in] offset the offset the fragmented value
* @param[in] attr_handle the attribute handle
* @param[in] auth_req access properties
* @param[in] *p_value the value to be written
* @param[in] len the length of value to be written
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_send_response(uint16_t conn_id, uint32_t trans_id, uint8_t status, int offset, uint16_t attr_handle, int auth_req, uint8_t *p_value, int len);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_BLE_GATT_H */

422
include/bt/wm_bt.h Normal file
View File

@ -0,0 +1,422 @@
/**
* @file wm_bt.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_BT_H
#define WM_BT_H
#include "wm_bt_def.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BT_Host_APIs BT Host APIs
* @brief BT Host APIs
*/
/**
* @addtogroup BT_Host_APIs
* @{
*/
/**
* @brief reply the pin request
*
* @param[in] *bd_addr remote device address
* @param[in] accept
* @param[in] pin_len
* @param[in] *pin_code
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_pin_reply(const tls_bt_addr_t *bd_addr, uint8_t accept,
uint8_t pin_len, tls_bt_pin_code_t *pin_code);
/**
* @brief reply the ssp request
*
* @param[in] *bd_addr remote device address
* @param[in] variant @ref tls_bt_ssp_variant_t
* @param[in] accept
* @param[in] passkey
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ssp_reply(const tls_bt_addr_t *bd_addr, tls_bt_ssp_variant_t variant,
uint8_t accept, uint32_t passkey);
/**
* @brief set the adapter property
*
* @param[in] *property remote device address
* @param[in] update_to_flash save the property to flash or not
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_set_adapter_property(const tls_bt_property_t *property, uint8_t update_to_flash);
/**
* @brief get the adapter property
*
* @param[in] type @ref tls_bt_property_type_t
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_get_adapter_property(tls_bt_property_type_t type);
/**
* @brief
*
* @param None
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_start_discovery(void);
/**
* @brief
*
* @param None
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_cancel_discovery(void);
/**
* @brief
*
* @param[in] *bd_addr
* @param[in] transport
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_create_bond(const tls_bt_addr_t *bd_addr, int transport);
/**
* @brief
*
* @param[in] *bd_addr
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_cancel_bond(const tls_bt_addr_t *bd_addr);
/**
* @brief
*
* @param[in] *bd_addr
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_remove_bond(const tls_bt_addr_t *bd_addr);
/**
* @brief
*
* @param None
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_host_cleanup(void);
/**
* @brief
*
* @param[in] callback
* @param[in] *p_hci_if
* @param[in] log_level
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_enable(tls_bt_host_callback_t callback, tls_bt_hci_if_t *p_hci_if, tls_bt_log_level_t log_level);
/**
* @brief
*
* @param None
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_disable();
/**
* @}
*/
/**
* @defgroup BT_Controller_APIs BT Controller APIs
* @brief BT Controller APIs
*/
/**
* @addtogroup BT_Controller_APIs
* @{
*/
/**
* @brief enable the bluetooth controller stack
*
* @param[in] *p_hci_if pointer on uart property
* @param[in] log_level @ref tls_bt_log_level_t
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_enable(tls_bt_hci_if_t *p_hci_if, tls_bt_log_level_t log_level);
/**
* @brief disable the bluetooth controller stack
*
* @param None
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_disable(void);
/**
* @brief configure the ble emit power of different ble handle type
*
* @param[in] power_type @ref tls_ble_power_type_t
* @param[in] power_level_index [1,2,3,4,5] map to[1,4,7,10,13]dBm
*
* @retval @ref tls_bt_status_t
*
* @note power_type, supports TLS_BLE_PWR_TYPE_DEFAULT only.
*/
tls_bt_status_t tls_ble_set_tx_power(tls_ble_power_type_t power_type, int8_t power_level_index);
/**
* @brief get the ble emit power of different ble handle type
*
* @param[in] power_type @ref tls_ble_power_type_t
*
* @retval power value db
*
* @note power_type, supports TLS_BLE_PWR_TYPE_DEFAULT only.
*/
int8_t tls_ble_get_tx_power(tls_ble_power_type_t power_type);
/**
* @brief configure the classic/enhanced bluetooth transmit power
*
* @param[in] min_power_level power level[1,13]dBm
* @param[in] max_power_level power level[1,13]dBm
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bredr_set_tx_power(int8_t min_power_level,int8_t max_power_level);
/**
* @brief get the classic/enhanced bluetooth transmit power level
*
* @param[in] *min_power_level pointer on min_power_level
* @param[in] *max_power_level pointer on max_power_level
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bredr_get_tx_power(int8_t* min_power_level, int8_t* max_power_level);
/**
* @brief configure the voice output path
*
* @param[in] data_path @ref tls_sco_data_path_t
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bredr_sco_datapath_set(tls_sco_data_path_t data_path);
/**
* @brief get controller stack status
*
* @param None
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_ctrl_status_t tls_bt_controller_get_status(void);
/**
* @brief this function receive the hci message from host hci_h4 inteface
*
* @param[in] *data hci formated message
* @param[in] len command length
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_vuart_host_send_packet( uint8_t *data, uint16_t len);
/**
* @brief this function register the host stack receive message function
* and indication the controller receive hci command avaiable
*
* @param[in] *p_host_if @ref tls_bt_host_if_t
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_if_register(const tls_bt_host_if_t *p_host_if);
/**
* @brief this function unregister the host stack receive message function
* and indication the controller receive hci command avaiable
*
* @param None
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_if_unregister();
/**
* @brief this function configure the controller enter into sleep mode when controller
* is in idle mode
*
* @param[in] enable TRUE: enable
* FALSE: didsable
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_sleep(bool enable);
/**
* @brief this function look up the controller is in sleep mode or not
*
* @param None
*
* @retval TRUE: sleep mode
* FALSE: not sleep mode
*
* @note None
*/
bool tls_bt_ctrl_is_sleep(void);
/**
* @brief this function wake up the controller, in other words exit sleep mode
*
* @param None
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_wakeup(void);
/**
* @brief this function check controller can handle hci commands yes or no
*
* @param None
*
* @retval @ref bool TRUE or FALSE
*
* @note None
*/
bool tls_bt_vuart_host_check_send_available();
/**
* @brief this function exit bluetooth test mode
*
* @param None
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t exit_bt_test_mode();
/**
* @brief this function enable bluetooth test mode
*
* @param[in] p_hci_if, specific the uart port property
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t enable_bt_test_mode(tls_bt_hci_if_t *p_hci_if);
/**
* @brief this function enable rf to bluetooth mode
*
* @param[in] 1, bluetooth mode, 0 wifi/bluetooth mode
*
* @retval None
*
* @note None
*/
void tls_rf_bt_mode(uint8_t enable);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_BT_H */

300
include/bt/wm_bt_av.h Normal file
View File

@ -0,0 +1,300 @@
/**
* @file wm_bt_av.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_BT_A2DP_H__
#define __WM_BT_A2DP_H__
#include "wm_bt.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BT_AV_APIs
* @brief BT_AV APIs
*/
/**
* @addtogroup BT_AV_APIs
* @{
*/
/**sink realed api*/
/**
* @brief Initializes the AV interface for sink mode
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_sink_init(tls_bt_a2dp_sink_callback_t callback);
/**
* @brief Shuts down the AV sink interface and does the cleanup
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_sink_deinit(void);
/**
* @brief Establishes the AV signalling channel with the source
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_sink_connect_src(tls_bt_addr_t *bd_addr);
/**
* @brief Tears down the AV signalling channel with the source side
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_sink_disconnect(tls_bt_addr_t *bd_addr);
/**src realed api*/
/**
* @brief Initializes the AV interface for source mode
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_src_init(tls_bt_a2dp_src_callback_t callback);
/**
* @brief Shuts down the AV source interface and does the cleanup
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_src_deinit(void);
/**
* @brief Establishes the AV signalling channel with the sink
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_src_connect_sink(tls_bt_addr_t *bd_addr);
/**
* @brief Tears down the AV signalling channel with the sink side
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_src_disconnect(tls_bt_addr_t *bd_addr);
/**btrc related api supported by now*/
/**
* @brief Initializes the AVRC interface
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_init(tls_btrc_callback_t callback);
/**
* @brief Closes the AVRC interface
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_deinit(void);
/**
* @brief Returns the current play status.
*
* @param[in] tls_btrc_play_status_t stopped, playing, paused...
* @param[in] song_len seconds of the song
* @param[in] song_pos played seconds of the song
*
* @retval @ref tls_bt_status_t
*
* @note This method is called in response to GetPlayStatus request.
*/
tls_bt_status_t tls_btrc_get_play_status_rsp(tls_btrc_play_status_t play_status, uint32_t song_len,
uint32_t song_pos);
/**
* @brief Returns the current songs' element attributes in text
*
* @param[in] num_attr counter of song`s element attributes
* @param[in] p_attrs pointer of element attributes
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_get_element_attr_rsp(uint8_t num_attr, tls_btrc_element_attr_val_t *p_attrs);
/**
* @brief Response to the register notification request in text
*
* @param[in] event_id play_status, track or play_pos changed
* @param[in] type notification type
* @param[in] p_param pointer to details of notification structer
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_register_notification_rsp(tls_btrc_event_id_t event_id,
tls_btrc_notification_type_t type, tls_btrc_register_notification_t *p_param);
/**
* @brief Send current volume setting to remote side
*
* @param[in] volue Should be in the range 0-127. bit7 is reseved and cannot be set
*
* @retval @ref tls_bt_status_t
*
* @note Support limited to SetAbsoluteVolume
* This can be enhanced to support Relative Volume (AVRCP 1.0).
* With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN
* as opposed to absolute volume level
*/
tls_bt_status_t tls_btrc_set_volume(uint8_t volume);
/**btrc ctrl related api supported by now*/
/**
* @brief Initializes the AVRC ctrl interface
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_init(tls_btrc_ctrl_callback_t callback);
/**
* @brief Closes the AVRC ctrl interface
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_deinit(void);
/**
* @brief Send Pass-Through command
*
* @param[in] bd_addr remote device bluetooth device address
* @param[in] key_code code definition of the key
* @param[in] key_state key stae
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_send_passthrough_cmd(tls_bt_addr_t *bd_addr, uint8_t key_code, uint8_t key_state);
/**
* @brief Send group navigation command
*
* @param[in] bd_addr remote device bluetooth device address
* @param[in] key_code code definition of the key
* @param[in] key_state key stae
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_send_groupnavigation_cmd(tls_bt_addr_t *bd_addr, uint8_t key_code, uint8_t key_state);
/**
* @brief Set current values of Player Attributes
*
* @param[in] bd_addr remote device bluetooth device address
* @param[in] num_attrib couner of attributes
* @param[in] attrib_ids atrribute of index indicator
* @param[in] attrib_vals attribute of values
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_change_player_app_setting(tls_bt_addr_t *bd_addr, uint8_t num_attrib, uint8_t *attrib_ids, uint8_t *attrib_vals);
/**
* @brief Rsp for SetAbsoluteVolume Command
*
* @param[in] bd_addr remote device bluetooth device address
* @param[in] abs_vol the absolute volume
* @param[in] label label indicator
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_set_volume_rsp(tls_bt_addr_t *bd_addr, uint8_t abs_vol, uint8_t label);
/**
* @brief Rsp for Notification of Absolute Volume
*
* @param[in] bd_addr remote device bluetooth device address
* @param[in] rsp_type interim or changed
* @param[in] abs_vol the absolute volume value
* @param[in] label label indicator
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_volume_change_notification_rsp(tls_bt_addr_t *bd_addr, tls_btrc_notification_type_t rsp_type,uint8_t abs_vol, uint8_t label);
#endif

1893
include/bt/wm_bt_def.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,261 @@
/**
* @file wm_bt_hf_client.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_BT_HF_CLIENT_H__
#define __WM_BT_HF_CLIENT_H__
#include "wm_bt.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BT_HF_CLIENT_APIs
* @brief BT_HF_CLIENT APIs
*/
/**
* @addtogroup BT_HF_CLIENT_APIs
* @{
*/
/**
* @brief initializes the hf client interface
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_init(tls_bthf_client_callback_t callback);
/**
* @brief Closes the HF client interface
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_deinit(void);
/**
* @brief connect to audio gateway
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_connect(tls_bt_addr_t *bd_addr);
/**
* @brief disconnect from audio gateway
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_disconnect(tls_bt_addr_t *bd_addr);
/**
* @brief create an audio connection
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_connect_audio(tls_bt_addr_t *bd_addr);
/**
* @brief close the audio connection
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_disconnect_audio(tls_bt_addr_t *bd_addr);
/**
* @brief start voice recognition
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_start_voice_recognition(void);
/**
* @brief stop voice recognition
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_stop_voice_recognition(void);
/**
* @brief volume control
*
* @param[in] type Mic or speaker
* @param[in] volume index value
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_volume_control(tls_bthf_client_volume_type_t type, int volume);
/**
* @brief place a call
*
* @param[in] number phone number to be called
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_dial(const char *number);
/**
* @brief place a call with number specified by location (speed dial)
*
* @param[in] location
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_dial_memory(int location);
/**
* @brief handle specified call related action
*
* @param[in] action call action
* @param[in] idx index indicator
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_handle_call_action(tls_bthf_client_call_action_t action, int idx);
/**
* @brief query list of current calls
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_query_current_calls(void);
/**
* @brief query current selected operator name
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_query_current_operator_name(void);
/**
* @brief retrieve subscriber number information
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_retrieve_subscriber_info(void);
/**
* @brief send dtmf
*
* @param[in] code number code
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_send_dtmf(char code);
/**
* @brief Request number from AG for VR purposes
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_request_last_voice_tag_number(void);
/**
* @brief Send requested AT command to remote device
*
* @param[in] cmd
* @param[in] val1
* @param[in] val2
* @param[in] arg
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_send_at_cmd(int cmd, int val1, int val2, const char *arg);
/**
* @brief Send audio to audio gateway
*
* @param[in] bd_addr bluetooth address of audio gateway
* @param[in] p_data audio data
* @param[in] length audio length
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_send_audio(tls_bt_addr_t *bd_addr, uint8_t *p_data, uint16_t length);
#endif

151
include/bt/wm_bt_spp.h Normal file
View File

@ -0,0 +1,151 @@
/**
* @file wm_bt_spp.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_BT_SPP_H__
#define __WM_BT_SPP_H__
#include "wm_bt.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BT_SPP_APIs
* @brief BT_SPP APIs
*/
/**
* @addtogroup BT_SPP_APIs
* @{
*/
/**spp realed api*/
/**
* @brief Initializes the SPP interface
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_init(tls_bt_spp_callback_t callback);
/**
* @brief Shuts down the SPP interface and does the cleanup
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_deinit(void);
/**
* @brief Enable the bta jv interface
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_enable(void);
/**
* @brief Disable the bta jv interface and cleanup internal resource
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_disable(void);
/**
* @brief Discovery the spp service by the given peer device.
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_start_discovery(tls_bt_addr_t *bd_addr, tls_bt_uuid_t *uuid);
/**
* @brief Create a spp connection to the remote device
*
* @param[in] sec_mask: Security Setting Mask
* @param[in] role: Server or client
* @param[in] remote_scn: Remote device bluetooth device SCN
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_connect(wm_spp_sec_t sec_mask,
tls_spp_role_t role, uint8_t remote_scn, tls_bt_addr_t *bd_addr);
/**
* @brief Close a spp connection
*
* @param[in] handle: The connection handle
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_disconnect(uint32_t handle);
/**
* @brief This function create a SPP server and starts listening for an
* SPP connection request from a remote Bluetooth device
*
* @param[in] sec_mask: Security Setting Mask .
* @param[in] role: Server or client.
* @param[in] local_scn: The specific channel you want to get.
* If channel is 0, means get any channel.
* @param[in] name: Server's name.
*
* @retval @ref tls_bt_status_t
*/
tls_bt_status_t tls_bt_spp_start_server(wm_spp_sec_t sec_mask,
tls_spp_role_t role, uint8_t local_scn, const char *name);
/**
* @brief This function is used to write data
*
* @param[in] handle: The connection handle.
* @param[in] len: The length of the data written.
* @param[in] p_data: The data written.
*
* @retval @ref tls_bt_status_t
*/
tls_bt_status_t tls_bt_spp_write(uint32_t handle, uint8_t *p_data, int length);
#endif

270
include/driver/wm_7816.h Normal file
View File

@ -0,0 +1,270 @@
/**************************************************************************//**
* @file wm_7816.h
* @author
* @version
* @date
* @brief
* @copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
*****************************************************************************/
#ifndef WM_7816_H_
#define WM_7816_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>
#include <stdbool.h>
#include "wm_regs.h"
#include "wm_type_def.h"
#include "wm_io.h"
#define WM_SC_RST_PIN WM_IO_PB_23 //(23)
#define WM_SC_PWR_PIN WM_IO_PB_24 //(29)
#define WM_SC_DEFAULT_FD (372)
typedef struct sc_io_map_ {
enum tls_io_name clk_pin_num;
uint32_t clk_opt;
enum tls_io_name io_pin_num;
uint32_t io_opt;
uint8_t initialed;
} sc_io_map;
extern sc_io_map sc_io;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup 7816_Driver_APIs 7816 Driver APIs
* @brief 7816 driver APIs
*/
/**
* @addtogroup 7816_Driver_APIs
* @{
*/
/**
* @brief
* This function is used to config the pin in gpio or 7816 mode for the 7816 power on timing
*
* @param[in] mode : 1--gpio mode ; 0--7816 mode
*
* @retval
*/
void wm_sc_io_clk_config(uint8_t mode);
/**
* @brief
* close af to use as gpio
* @retval
*/
void wm_sc_powerInit(void);
/**
* @brief
* power on the 7816 device if power is controled by GPIO
* @retval
*/
void wm_sc_poweron(void);
/**
* @brief
* power off the 7816 device if power is controled by GPIO
* @retval
*/
void wm_sc_poweroff(void);
/**
* @brief
* driver the reset gpio in low level
* @retval
*/
void wm_sc_rst_low(void);
/**
* @brief
* driver the reset gpio in high level
* @retval
*/
void wm_sc_rst_high(void);
/**
* @brief
* hotrest the 7816 device obey the 7816-3 timing
* @retval
*/
void wm_sc_hotreset(void);
/**
* @brief
* colreset the 7816 device obey the 7816-3 timing
* @retval
*/
void wm_sc_colreset(void);
/**
* @brief
* deactive the 7816 device obey the 7816-3 timing
* @retval
*/
void wm_sc_deactive(void);
/**
* @brief
* This function is used to config the block guard time param in 7816 mode
* @param[in] bgt : the value of blcok guard time will be set
* @retval
*/
void wm_sc_set_bgt(uint8_t bgt);
/**
* @brief
* This function is used to config the tx retry count when detect err signal
* @param[in] count : the value of retry time will be set 7 for max
* @retval
*/
void wm_sc_tx_retry_times(uint8_t count);
/**
* @brief
* This function is used to config the rx retry count when detect parity error
* @param[in] count : the value of retry time will be set 7 for max
* @retval
*/
void wm_sc_rx_retry_times(uint8_t count);
/**
* @brief
* This function is used to config the etu param
* @param[in] etu : the value of etu will be set
* @retval
*/
void wm_sc_set_etu(uint16_t etu);
/**
* @brief
* This function config the module clock freq
* @param[in] freq : the value of clock freq
* @retval
*/
void wm_sc_set_frequency(uint32_t freq);
/**
* @brief
* config recv or not when parity error
* @param[in] bl : 1--- recv
* 0--- don't recv
* @retval
*/
static inline void wm_sc_parity_recv(bool bl)
{
tls_bitband_write(HR_UART2_LINE_CTRL, 9, bl);
}
/**
* @brief
* select the model in 7816 or uart function
* @param[in] bl : 1---7816 mode
* 0---uart mode
* @retval
*/
static inline void wm_sc_7816_mode(bool bl)
{
tls_bitband_write(HR_UART2_LINE_CTRL, 24, bl);
}
/**
* @brief
* This function is used to config the guard time param
* @param[in] bwt : the value of the guard time will be set
* @retval
*/
static inline void wm_sc_set_guardtime(uint8_t gt)
{
tls_reg_write32(HR_UART2_GUARD_TIME, gt);
}
/**
* @brief
* This function is used to config the CWT or BWT param
* @param[in] bwt : the value of CWT or BWT will be set
* @retval
*/
static inline void wm_sc_set_bcwt(uint32_t bwt)
{
bwt = (bwt > 0xFFFFFF) ? 0xFFFFFF : bwt;
tls_reg_write32(HR_UART2_WAIT_TIME, bwt);
}
/**
* @brief
* module errsignal int enable or disable
* @param[in] bl : 1---enable
* 0---disable
* @retval
*/
static inline void wm_sc_tx_errsignal_mask(bool bl)
{
tls_bitband_write(HR_UART2_INT_MASK, 9, bl);
}
/**
* @brief
* config the module protol
* @param[in] bl : 1--- T1 protocol
* 0--- T0 protocol
* @retval
*/
static inline void wm_sc_set_protocol(bool bl)
{
tls_bitband_write(HR_UART2_LINE_CTRL, 8, bl);
}
/**
* @brief
* get the module protol
* @retval
* 1--- T1 protocol
* 0--- T0 protocol
*/
static inline uint8_t wm_sc_get_protocol()
{
return tls_bitband_read(HR_UART2_LINE_CTRL, 8);
}
/**
* @brief
* smart card clock output enable or disable
* @param[in] bl : 0---enable;
* 1---disable;
* @retval
*/
static inline void wm_sc_clk_enable(bool bl)
{
tls_bitband_write(HR_UART2_LINE_CTRL, 10, bl);
}
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif

316
include/driver/wm_adc.h Normal file
View File

@ -0,0 +1,316 @@
/*****************************************************************************
*
* File Name : wm_adc.h
*
* Description: adc Driver Module
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-8-15
*****************************************************************************/
#ifndef WM_ADC_H
#define WM_ADC_H
#include "wm_type_def.h"
#define ADC_DEST_BUFFER_SIZE 16383//以字为单位
/*ADC Result*/
#define ADC_RESULT_MASK (0x3FFFC)
#define ADC_RESULT_VAL(n) ((n)&ADC_RESULT_MASK)
/*ADC_ANALOG_CTRL*/
#define CONFIG_ADC_CHL_SEL_MASK (0xF<<8)
#define CONFIG_ADC_CHL_SEL(n) ((n)<<8)
#define CONFIG_PD_ADC_MASK (0x1<<2)
#define CONFIG_PD_ADC_VAL(n) ((n)<<2) /*1:pd adc, 0: normal work*/
#define CONFIG_RSTN_ADC_MASK (0x1<<1)
#define CONFIG_RSTN_ADC_VAL(n) ((n)<<1) /*1:normal work, 0:adc reset*/
#define CONFIG_EN_LDO_ADC_MASK (0x1<<0)
#define CONFIG_EN_LDO_ADC_VAL(n) ((n)<<0) /*1:ldo work, 0: ldo shutdown*/
/*PGA_CTRL*/
#define CLK_CHOP_SEL_PGA_MASK (0x7<<4)
#define CLK_CHOP_SEL_PGA_VAL(n) ((n)<<4)
#define GAIN_CTRL_PGA_MASK (0x3<<7)
#define GAIN_CTRL_PGA_VAL(n) ((n)<<7)
#define PGA_BYPASS_MASK (0x1<<3)
#define PGA_BYPASS_VAL(n) ((n)<<3) /*1:bypass pga, 0:use pga*/
#define BYPASS_INNER_REF_SEL (0x1<<2) /*Internal or external reference select*/
#define PGA_CHOP_ENP_MASK (0x1<<1)
#define PGA_CHOP_ENP_VAL(n) ((n)<<1) /*1: enable chop, 0: disable chop*/
#define PGA_EN_MASK (0x1<<0)
#define PGA_EN_VAL(n) ((n)<<0) /*1: enable pga, 0: disable pga*/
/*Temperature Control*/
#define TEMP_GAIN_MASK (0x3<<4)
#define TEMP_GAIN_VAL(n) ((n)<<4)
#define TEMP_CAL_OFFSET_MASK (0x1<<1)
#define TEMP_EN_MASK (0x1<<0)
#define TEMP_EN_VAL(n) ((n)<<0) /*1: enable temperature, 0: disable temperature*/
/*ADC CTRL*/
#define ANALOG_SWITCH_TIME_MASK (0x3FF<<20)
#define ANALOG_SWITCH_TIME_VAL(n) (((n)&0x3FF)<<20)
#define ANALOG_INIT_TIME_MASK (0x3FF<<8)
#define ANALOG_INIT_TIME_VAL(n) (((n)&0x3FF)<<8)
#define CMP_POLAR_MASK (0x1<<6)
#define CMP_IRQ_EN_MASK (0x1<<5)
#define CMP_IRQ_EN_VAL(n) ((n)<<5) /*1: enable cmp irq, 0: disable cmp irq*/
#define CMP_EN_MASK (0x1<<4)
#define CMP_EN_VAL(n) ((n)<<4) /*1: enable cmp function, 0: disable cmp function*/
#define ADC_IRQ_EN_MASK (0x1<<1)
#define ADC_IRQ_EN_VAL(n) ((n)<<1) /*1:enable adc transfer irq, 0: disable*/
#define ADC_DMA_EN_MASK (0x1<<0)
#define ADC_DMA_EN_VAL(n) ((n)<<0) /*1:enable adc dma, 0: disable*/
/*ADC IRQ Status*/
#define CMP_INT_MASK (0x1<<1)
#define ADC_INT_MASK (0x1<<0)
/*CMP Value*/
#define CONFIG_ADC_INPUT_CMP_VAL(n) ((n)&0x3FFFF)
/*ADC Channel*/
#define CONFIG_ADC_CHL_OFFSET (0x0E)
#define CONFIG_ADC_CHL_VOLT (0x0D)
#define CONFIG_ADC_CHL_TEMP (0x0C)
#define ADC_INT_TYPE_ADC 0
#define ADC_INT_TYPE_DMA 1
#define ADC_INT_TYPE_ADC_COMP 2
#define ADC_REFERENCE_EXTERNAL 0 //外部参考
#define ADC_REFERENCE_INTERNAL 1 //内部参考
typedef struct adc_st{
u8 dmachannel;
void (*adc_cb)(int *buf, u16 len);
void (*adc_bigger_cb)(int *buf, u16 len);
void (*adc_dma_cb)(int *buf,u16 len);
u16 valuelen; /*dma 采样数据长度*/
u16 offset;
}ST_ADC;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup ADC_Driver_APIs ADC Driver APIs
* @brief ADC driver APIs
*/
/**
* @addtogroup ADC_Driver_APIs
* @{
*/
/**
* @brief This function is used to init adc.
*
* @param[in] ifusedma if use dma
* @param[in] dmachannel dma channel
*
* @return None
*
* @note None
*/
void tls_adc_init(u8 ifusedma,u8 dmachannel);
/**
* @brief This function is used to register interrupt callback function.
*
* @param[in] inttype interrupt type:
* ADC_INT_TYPE_ADC adc interrupt,user get adc result from the callback function.
* ADC_INT_TYPE_DMA dma interrupt,dma transfer the adc result to the user's buffer.
* @param[in] callback interrupt callback function.
*
* @return None
*
* @note None
*/
void tls_adc_irq_register(int inttype, void (*callback)(int *buf, u16 len));
/**
* @brief This function is used to clear the interrupt source.
*
* @param[in] inttype interrupt type:
* ADC_INT_TYPE_ADC adc interrupt,user get adc result from the callback function.
* ADC_INT_TYPE_DMA dma interrupt,dma transfer the adc result to the user's buffer.
*
* @return None
*
* @note None
*/
void tls_adc_clear_irq(int inttype);
/**
* @brief This function is used to register interrupt callback function.
*
* @param[in] Channel adc channel,from 0 to 3 is single input;4 and 5 is differential input.
* @param[in] Length byte data length,is an integer multiple of half word,need <= 0x500
*
* @return None
*
* @note None
*/
void tls_adc_start_with_dma(int Channel, int Length);
/**
* @brief This function is used to start adc.
*
* @param[in] Channel adc channel,from 0 to 3 is single input;4 and 5 is differential input.
*
* @return None
*
* @note None
*/
void tls_adc_start_with_cpu(int Channel);
/**
* @brief This function is used to read adc result.
*
* @param[in] None
*
* @retval adc result
*
* @note None
*/
u32 tls_read_adc_result(void);
/**
* @brief This function is used to stop the adc.
*
* @param[in] ifusedma if use dma
*
* @return None
*
* @note None
*/
void tls_adc_stop(int ifusedma);
/**
* @brief This function is used to config adc bigger register.
*
* @param[in] cmp_data compare data
* @param[in] cmp_pol compare pol
*
* @return None
*
* @note None
*/
void tls_adc_config_cmp_reg(int cmp_data, int cmp_pol);
/**
* @brief This function is used to set adc reference source.
*
* @param[in] ref ADC_REFERENCE_EXTERNAL,ADC_REFERENCE_INTERNAL
*
* @return None
*
* @note None
*/
void tls_adc_reference_sel(int ref);
/**
* @brief This function is used to read internal temperature.
*
* @param[in] None
*
* @retval temperature
*
* @note None
*/
int adc_get_interTemp(void);
/**
* @brief This function is used to read input voltage.
*
* @param[in] channel adc channel,from 0 to 3 is single input;8 and 9 is differential input.
*
* @retval voltage unit:mV
*
* @note None
*/
int adc_get_inputVolt(u8 channel);
/**
* @brief This function is used to read internal voltage.
*
* @param[in] None
*
* @retval voltage (mV)
*
* @note None
*/
u32 adc_get_interVolt(void);
/**
* @brief This function is used to read temperature.
*
* @param[in] None
*
* @retval temperature
*
* @note None
*/
int adc_temp(void);
/**
* @}
*/
/**
* @}
*/
void tls_adc_enable_calibration_buffer_offset(void);
void tls_adc_voltage_start_with_cpu(void);
void tls_adc_temp_offset_with_cpu(u8 calTemp12);
void tls_adc_voltage_start_with_dma(int Length);
void tls_adc_set_clk(int div);
void signedToUnsignedData(int *adcValue);
void tls_adc_buffer_bypass_set(u8 isset);
void tls_adc_cmp_start(int Channel, int cmp_data, int cmp_pol);
u32 adc_get_offset(void);
#endif

101
include/driver/wm_cpu.h Normal file
View File

@ -0,0 +1,101 @@
/**
* @file wm_cpu.h
*
* @brief cpu driver module
*
* @author dave
*
* @copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_CPU_H
#define WM_CPU_H
#include <stdint.h>
/**W800 BASE PLL CLOCK*/
#define W800_PLL_CLK_MHZ (480)
enum CPU_CLK{
CPU_CLK_240M = 2,
CPU_CLK_160M = 3,
CPU_CLK_80M = 6,
CPU_CLK_40M = 12,
CPU_CLK_2M = 240,
};
typedef union {
struct {
uint32_t CPU: 8; /*!< bit: 0.. 7 cpu clock divider */
uint32_t WLAN: 8; /*!< bit: 8.. 15 Wlan clock divider */
uint32_t BUS2: 8; /*!< bit: 16.. 23 clock dividing ratio of bus2 & bus1 */
uint32_t PD: 4; /*!< bit: 24.. 27 peripheral divider */
uint32_t RSV: 3; /*!< bit: 28.. 30 Reserved */
uint32_t DIV_EN: 1; /*!< bit: 31 divide frequency enable */
} b;
uint32_t w;
} clk_div_reg;
#define UNIT_MHZ (1000000)
typedef struct{
u32 apbclk;
u32 cpuclk;
u32 wlanclk;
}tls_sys_clk;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup CPUCLK_Driver_APIs CPU CLOCK Driver APIs
* @brief CPU CLOCK driver APIs
*/
/**
* @addtogroup CPUCLK_Driver_APIs
* @{
*/
/**
* @brief This function is used to set cpu clock
*
* @param[in] clk select cpu clock
* clk == CPU_CLK_80M 80M
* clk == CPU_CLK_40M 40M
*
* @return None
*
* @note None
*/
void tls_sys_clk_set(u32 clk);
/**
* @brief This function is used to get cpu clock
*
* @param[out] *sysclk point to the addr for system clk output
*
* @return None
*
* @note None
*/
void tls_sys_clk_get(tls_sys_clk *sysclk);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_CPU_H */

233
include/driver/wm_dma.h Normal file
View File

@ -0,0 +1,233 @@
/**
* @file wm_dma.h
*
* @brief DMA Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_DMA_H_
#define __WM_DMA_H_
#define TLS_DMA_SEL_UART_RX 0
#define TLS_DMA_SEL_UART_TX 1
#define TLS_DMA_SEL_PWM_CAP0 2
#define TLS_DMA_SEL_PWM_CAP1 3
#define TLS_DMA_SEL_LSSPI_RX 4
#define TLS_DMA_SEL_LSSPI_TX 5
#define TLS_DMA_SEL_SDADC_CH0 6
#define TLS_DMA_SEL_SDADC_CH1 7
#define TLS_DMA_SEL_SDADC_CH2 8
#define TLS_DMA_SEL_SDADC_CH3 9
#define TLS_DMA_SEL_I2S_RX 10
#define TLS_DMA_SEL_I2S_TX 11
#define TLS_DMA_SEL_SDIO_HOST 12
#define TLS_DMA_FLAGS_HARD_MODE (1 << 0)
#define TLS_DMA_FLAGS_CHAIN_MODE (1 << 1)
#define TLS_DMA_FLAGS_CHANNEL_SEL(n) ((n) << 2)
#define TLS_DMA_FLAGS_CHAIN_LINK_EN (1 << 6)
#define TLS_DMA_FLAGS_CHANNEL_VALID (1 << 7)
#define TLS_DMA_DESC_VALID (1U << 31)
#define TLS_DMA_DESC_CTRL_SRC_ADD_INC (1 << 0)
#define TLS_DMA_DESC_CTRL_DEST_ADD_INC (1 << 2)
#define TLS_DMA_DESC_CTRL_DATA_SIZE_BYTE (0 << 4)
#define TLS_DMA_DESC_CTRL_DATA_SIZE_SHORT (1 << 4)
#define TLS_DMA_DESC_CTRL_DATA_SIZE_WORD (2 << 4)
#define TLS_DMA_DESC_CTRL_BURST_SIZE1 (0 << 6)
#define TLS_DMA_DESC_CTRL_BURST_SIZE4 (1 << 6)
#define TLS_DMA_DESC_CTRL_TOTAL_BYTES(n) ((n) << 7)
/* dma interrupt flags */
#define TLS_DMA_IRQ_BURST_DONE (1 << 0)
#define TLS_DMA_IRQ_TRANSFER_DONE (1 << 1)
#define TLS_DMA_IRQ_BOTH_DONE (TLS_DMA_IRQ_BURST_DONE | TLS_DMA_IRQ_TRANSFER_DONE)
struct tls_dma_descriptor {
unsigned int valid;
unsigned int dma_ctrl;
unsigned int src_addr;
unsigned int dest_addr;
struct tls_dma_descriptor *next; /**< next dms descriptor */
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup DMA_Driver_APIs DMA Driver APIs
* @brief DMA driver APIs
*/
/**
* @addtogroup DMA_Driver_APIs
* @{
*/
/**
* @brief This function is used to clear dma interrupt flag.
*
* @param[in] ch Channel no.[0~7]
* @param[in] flags Flags setted to TLS_DMA_IRQ_BURST_DONE, TLS_DMA_IRQ_TRANSFER_DONE, TLS_DMA_IRQ_BOTH_DONE.
*
* @return None
*
* @note None
*/
void tls_dma_irq_clr(unsigned char ch, unsigned char flags);
/**
* @brief This function is used to register dma interrupt callback function.
*
* @param[in] ch Channel no.[0~7]
* @param[in] callback is the dma interrupt call back function.
* @param[in] arg the param of the callback function.
* @param[in] flags Flags setted to TLS_DMA_IRQ_BURST_DONE, TLS_DMA_IRQ_TRANSFER_DONE, TLS_DMA_IRQ_BOTH_DONE.
*
* @return None
*
* @note None
*/
void tls_dma_irq_register(unsigned char ch, void (*callback)(void *p), void *arg, unsigned char flags);
/**
* @brief This function is used to register dma interrupt
*
* @param[in] ch DMA channel no.[0~7]
*
* @return None
*
* @note None
*/
int tls_dma_wait_complt(unsigned char ch);
/**
* @brief This function is used to Start the DMA controller by Wrap
*
* @param[in] autoReload Does restart when current transfer complete?
* @param[in] ch Channel no.[0~7]
* @param[in] pDmaDesc Pointer to DMA channel descriptor structure.
*
* @retval Always STATUS_SUCCESS.
*
* @note
* DMA Descriptor:
* +--------------------------------------------------------------+
* |Vld[31] | RSV |
* +--------------------------------------------------------------+
* | RSV | Dma_Ctrl[16:0] |
* +--------------------------------------------------------------+
* | Src_Addr[31:0] |
* +--------------------------------------------------------------+
* | Dest_Addr[31:0] |
* +--------------------------------------------------------------+
* | Next_Desc_Add[31:0] |
* +--------------------------------------------------------------+
*/
unsigned char tls_dma_start_by_wrap(unsigned char ch, struct tls_dma_descriptor *dma_desc,
unsigned char auto_reload, unsigned short src_zize,
unsigned short dest_zize);
/**
* @brief This function is used to Wait until DMA operation completes
*
* @param[in] autoReload Does restart when current transfer complete?
* @param[in] ch Channel no.[0~7]
* @param[in] pDmaDesc Pointer to DMA channel descriptor structure.
*
* @retval Always STATUS_SUCCESS.
*
* @note
* DMA Descriptor:
* +--------------------------------------------------------------+
* |Vld[31] | RSV |
* +--------------------------------------------------------------+
* | RSV | Dma_Ctrl[16:0] |
* +--------------------------------------------------------------+
* | Src_Addr[31:0] |
* +--------------------------------------------------------------+
* | Dest_Addr[31:0] |
* +--------------------------------------------------------------+
* | Next_Desc_Add[31:0] |
* +--------------------------------------------------------------+
*/
unsigned char tls_dma_start(unsigned char ch, struct tls_dma_descriptor *dma_desc,
unsigned char auto_reload);
/**
* @brief This function is used to To stop current DMA channel transfer
*
* @param[in] ch channel no. to be stopped
*
* @retval Always STATUS_SUCCESS
*
* @note If channel stop, DMA_CHNL_CTRL_CHNL_ON bit in DMA_CHNLCTRL_REG is cleared.
*/
unsigned char tls_dma_stop(unsigned char ch);
/**
* @brief This function is used to Request a free dma channel
* If ch is out of range [0,7] or valid but used, the function will select another free channel.
* else return the selected channel no.
* @param[in] ch specified channel when ch is valid and not used.
* @param[in] flags flags setted to selected channel
*
* @return Real DMA Channel No: if there is free dma channel.
* 0xFF: when DMA channels are all used.
*
* @note If ch is invalid or valid but used, the function will select another free channel.
* else return the selected channel no.
*/
unsigned char tls_dma_request(unsigned char ch, unsigned char flags);
/**
* @brief This function is used to Free the DMA channel when not use
*
* @param[in] ch channel no. that is ready to free
*
* @return None
*
* @note None
*/
void tls_dma_free(unsigned char ch);
/**
* @brief This function is used to Initialize DMA Control
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_dma_init(void);
/**
* @}
*/
/**
* @}
*/
#endif /* __TLS_DMA_H_151606__ */

285
include/driver/wm_efuse.h Normal file
View File

@ -0,0 +1,285 @@
/**
* @file wm_efuse.h
*
* @brief virtual efuse Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_EFUSE_H
#define WM_EFUSE_H
#define TLS_EFUSE_STATUS_OK (0)
#define TLS_EFUSE_STATUS_EINVALID (1)
#define TLS_EFUSE_STATUS_EIO (2)
enum {
CMD_WIFI_MAC = 0x01,
CMD_BT_MAC,
CMD_TX_DC,
CMD_RX_DC,
CMD_TX_IQ_GAIN,
CMD_RX_IQ_GAIN,
CMD_TX_IQ_PHASE,
CMD_RX_IQ_PHASE,
CMD_TX_GAIN,
CMD_ALL,
};
#define FREQERR_ADDR (FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST))
#define FREQERR_LEN (4)
#define CAL_FLAG_ADDR (FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST)+4)
#define CAL_FLAG_LEN (4)
//#define TX_GAIN_NEW_ADDR (VCG_ADDR+VCG_LEN)
#define TX_GAIN_LEN (28*3)
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup EFUSE_Driver_APIs EFUSE Driver APIs
* @brief EFUSE driver APIs
*/
/**
* @addtogroup EFUSE_Driver_APIs
* @{
*/
/**
* @brief This function is used to init ft param.
*
* @param[in] None
*
* @retval TRUE init success
* @retval FALSE init failed
*/
int tls_ft_param_init(void);
/**
* @brief This function is used to write ft_param.
*
* @param[in] opnum ft cmd
* @param[in] data data pointer
* @param[in] len len to write data
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_ft_param_set(unsigned int opnum, void *data, unsigned int len);
/**
* @brief This function is used to read ft_param.
*
* @param[in] opnum ft cmd
* @param[in] data data pointer
* @param[in] len len to read data
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_ft_param_get(unsigned int opnum, void *data, unsigned int rdlen);
/**
* @brief This function is used to get mac addr
*
* @param[in] mac mac addr,6 byte
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_mac_addr(u8 *mac);
/**
* @brief This function is used to set mac addr
*
* @param[in] mac mac addr,6 byte
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_mac_addr(u8 *mac);
/**
* @brief This function is used to get bluetooth mac addr
*
* @param[in] mac mac addr,6 byte
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_bt_mac_addr(u8 *mac);
/**
* @brief This function is used to set bluetooth mac addr
*
* @param[in] mac mac addr,6 byte
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_bt_mac_addr(u8 *mac);
/**
* @brief This function is used to get tx gain
*
* @param[in] txgain tx gain,12 byte
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_tx_gain(u8 *txgain);
/**
* @brief This function is used to set tx gain
*
* @param[in] txgain tx gain,12 byte
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_tx_gain(u8 *txgain);
/**
* @brief This function is used to get tx lod
*
* @param[in] txlo tx lod
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_tx_lo(u8 *txlo);
/**
* @brief This function is used to set tx lod
*
* @param[in] txlo tx lod
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_tx_lo(u8 *txlo);
/**
* @brief This function is used to get tx iq gain
*
* @param[in] txGain
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_tx_iq_gain(u8 *txGain);
/**
* @brief This function is used to set tx iq gain
*
* @param[in] txGain
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_tx_iq_gain(u8 *txGain);
/**
* @brief This function is used to get rx iq gain
*
* @param[in] rxGain
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_rx_iq_gain(u8 *rxGain);
/**
* @brief This function is used to get rx iq gain
*
* @param[in] rxGain
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_rx_iq_gain(u8 *rxGain);
/**
* @brief This function is used to get tx iq phase
*
* @param[in] txPhase
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_tx_iq_phase(u8 *txPhase);
/**
* @brief This function is used to set tx iq phase
*
* @param[in] txPhase
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_tx_iq_phase(u8 *txPhase);
/**
* @brief This function is used to get rx iq phase
*
* @param[in] rxPhase
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_rx_iq_phase(u8 *rxPhase);
/**
* @brief This function is used to set rx iq phase
*
* @param[in] rxPhase
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_rx_iq_phase(u8 *rxPhase);
/**
* @brief This function is used to set/get freq err
*
* @param[in] freqerr (Unit:Hz),relative to base frequency(chan 1,2,3,4,5......13,14)
* @param[in] flag 1-set 0-get
* @retval TLS_EFUSE_STATUS_OK set/get success
* @retval TLS_EFUSE_STATUS_EIO set/get failed
*/
int tls_freq_err_op(u8 *freqerr, u8 flag);
/**
* @brief This function is used to set/get cal finish flag
*
* @param[in] calflag 1- finish calibration, non-1-do not calibration
* @param[in] flag 1-set 0-get
*
* @retval TLS_EFUSE_STATUS_OK set/get success
* @retval TLS_EFUSE_STATUS_EIO set/get failed
*/
int tls_rf_cal_finish_op(u8 *calflag, u8 flag);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_EFUSE_H */

159
include/driver/wm_flash.h Normal file
View File

@ -0,0 +1,159 @@
/**
* @file wm_flash.h
*
* @brief flash Driver module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_FLASH_H
#define WM_FLASH_H
#include "wm_type_def.h"
#include "wm_osal.h"
#define TLS_FLS_STATUS_OK (0)
#define TLS_FLS_STATUS_EINVAL (1)
#define TLS_FLS_STATUS_EBUSY (2)
#define TLS_FLS_STATUS_EPERM (3)
#define TLS_FLS_STATUS_ENOSUPPORT (4)
#define TLS_FLS_STATUS_EEXIST (5)
#define TLS_FLS_STATUS_ENOMEM (6)
#define TLS_FLS_STATUS_EOVERFLOW (7)
#define TLS_FLS_STATUS_ENODEV (8)
#define TLS_FLS_STATUS_EDEV (9)
#define TLS_FLS_STATUS_EIO (10)
#define TLS_FLS_STATUS_ENODRV (11)
#define TLS_FLS_PARAM_TYPE_ID (0)
#define TLS_FLS_PARAM_TYPE_SIZE (1)
#define TLS_FLS_PARAM_TYPE_PAGE_SIZE (2)
#define TLS_FLS_PARAM_TYPE_PROG_SIZE (3)
#define TLS_FLS_PARAM_TYPE_SECTOR_SIZE (4)
#define TLS_FLS_FLAG_UNDER_PROTECT (1<<0)
#define TLS_FLS_FLAG_FAST_READ (1<<1)
#define TLS_FLS_FLAG_AAAI (1<<2)
#define FLS_CMD_READ_DEV_ID (0x9F) // read device id //(0x9f)
/**
* @struct fls_list list
*/
struct fls_list
{
struct fls_list *next;
struct fls_list *prev;
};
/**
* @struct tls_fls_drv flash driver
*/
struct tls_fls_drv
{
struct fls_list drv_list;
u32 id;
u32 total_size;
u32 page_size;
u32 program_size;
u32 sector_size;
u32 clock;
u8 mode;
u8 cs_active;
u8 flags;
int (*read) (u32, u8 *, u32);
int (*fast_read) (u32, u8 *, u32);
int (*page_write) (u32, u8 *);
int (*erase) (u32);
int (*chip_erase) (void);
int (*probe)(u32 id);
void (*remove) (void);
};
/**
* @struct tls_fls flash
*/
struct tls_fls
{
struct fls_list fls_drvs;
struct tls_fls_drv *current_drv;
tls_os_sem_t *fls_lock;
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup SPIFLASH_Driver_APIs SPI FLASH Driver APIs
* @brief SPI FLASH driver APIs
*/
/**
* @addtogroup SPIFLASH_Driver_APIs
* @{
*/
/**
* @brief This function is used to initial flash module structer.
*
* @param[in] None
*
* @retval TLS_FLS_STATUS_OK if init sucsess
* @retval TLS_FLS_STATUS_EBUSY already inited
* @retval TLS_FLS_STATUS_ENOMEM memory error
*
* @note None
*/
int tls_spifls_init(void);
/**
* @brief This function is used to read data from the flash.
*
* @param[in] addr Specifies the starting address to read from
* @param[in] buf Pointer to a byte array that is to be written.
* @param[in] len length to read.
*
* @retval TLS_FLS_STATUS_OK if read sucsess
* @retval TLS_FLS_STATUS_EIO if read fail
*
* @note None
*/
int tls_spifls_read(u32 addr, u8 * buf, u32 len);
/**
* @brief This function is used to write data into the flash.
*
* @param[in] addr Specifies the starting address to write to.
* @param[in] buf Pointer to a byte array that holds the data to be written.
* @param[in] len length to write.
*
* @retval TLS_FLS_STATUS_OK if write flash success
* @retval TLS_FLS_STATUS_EPERM if flash struct point is null
* @retval TLS_FLS_STATUS_ENODRV if flash driver is not installed
* @retval TLS_FLS_STATUS_EINVAL if argument is invalid
* @retval TLS_FLS_STATUS_EIO if io error
*
* @note None
*/
int tls_spifls_write(u32 addr, u8 * buf, u32 len);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_FLASH_H */

View File

@ -0,0 +1,39 @@
/**
* @file wm_flash_map.h
*
* @brief flash zone map
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_FLASH_MAP_H__
#define __WM_FLASH_MAP_H__
/**FLASH MAP**/
/**Flash Base Address */
#define FLASH_BASE_ADDR (0x8000000UL)
/**Upgrade image area*/
#define CODE_UPD_START_ADDR (0x8010000UL)
/**Run-time image header area*/
#define CODE_RUN_START_ADDR (0x80D0000UL)
/**Area can be used by User*/
#define USER_ADDR_START (0x81E0000UL)
/**System parameter defined in wm_internal_fls.c*/
extern unsigned int TLS_FLASH_PARAM_DEFAULT;
extern unsigned int TLS_FLASH_PARAM1_ADDR;
extern unsigned int TLS_FLASH_PARAM2_ADDR;
extern unsigned int TLS_FLASH_PARAM_RESTORE_ADDR;
extern unsigned int TLS_FLASH_OTA_FLAG_ADDR;
extern unsigned int TLS_FLASH_END_ADDR;
#define SIGNATURE_WORD (0xA0FFFF9FUL)
#define IMAGE_START_ADDR_MSK (0x400)
#endif /*__WM_CONFIG_H__*/

View File

@ -0,0 +1,60 @@
/**
* @file wm_fls_gd25qxx.h
*
* @brief wm gd25qxx flash driver
*
* @author dave
*
* @copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef TLS_EXSPIFLS_H
#define TLS_EXSPIFLS_H
#define SPI_SCLK (10000000) /** 10MHz. */
#define FLASH_TOTAL_SIZE (1024*1024)
#define PAGE_SIZE 256
#define PROGRAM_SIZE 256
#define PAGE_ADDR_OFFSET 8
#define SECTOR_SIZE 4096
/**
* command code define.
*/
#define EXSPIFLASH_WRITE_ENABLE (0x06) /** Global write enable */
#define EXSPIFLASH_WRITE_DISABLE (0x04) /** Global write disable */
#define EXSPIFLASH_READ_SR1 (0x05) /** Read flash status register s0~s7 */
#define EXSPIFLASH_READ_SR2 (0x35) /** Read flash status register s8~s15 */
#define EXSPIFLASH_WRITE_SR (0x01) /** Write flash status register s0~s15 */
#define EXSPIFLASH_PAGE_PROGRAM (0x02) /** program one page */
#define EXSPIFLASH_DATA_READ (0x03) /** read data from specified address */
#define EXSPIFLASH_DATA_FAST_READ (0x0b) /** fast read data from specified address */
#define EXSPIFLASH_SECTOR_ERASE (0x20) /** Sector erase */
#define EXSPIFLASH_BLOCK32_ERASE (0x52) /** 32KB Block erase(128 pages) */
#define EXSPIFLASH_BLOCK64_ERASE (0xd8) /** 64kb Block erase(256 pages) */
#define EXSPIFLASH_CHIP_ERASE (0xc7) /** Chip erase */
#define EXSPIFLASH_FLASH_DEVICEID (0x90) /** Read flash manufacturer/device ID */
#define EXSPIFLASH_FLASH_ID (0x9f) /** Read flash ID */
#define FLASH_STATUS_BUSY (1 << 0)
#define FLASH_STATUS_WEL (1 << 1)
/**
* @brief This function is used to install gd25qxx driver.
*
* @param[in] None
*
* @retval TLS_FLS_STATUS_OK if write flash success
* @retval TLS_FLS_STATUS_EPERM if flash struct point is null
* @retval TLS_FLS_STATUS_ENODRV if flash driver is not installed
* @retval TLS_FLS_STATUS_EINVAL if argument is invalid
* @retval TLS_FLS_STATUS_EIO if io error
* @retval TLS_FLS_STATUS_EEXIST if driver is already existed
*
* @note None
*/
int tls_spifls_drv_install(void);
#endif /* TLS_FLS_GD25QXX_H */

181
include/driver/wm_gpio.h Normal file
View File

@ -0,0 +1,181 @@
/**
* @file wm_gpio.h
*
* @brief GPIO Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_GPIO_H
#define WM_GPIO_H
#include "wm_type_def.h"
#include "wm_io.h"
/** gpio interrupte callback function */
typedef void (*tls_gpio_irq_callback)(void *arg);
/** Indicating gpio direction */
enum tls_gpio_dir {
WM_GPIO_DIR_OUTPUT, /**< output */
WM_GPIO_DIR_INPUT /**< input */
};
/** Indicating gpio attribute */
enum tls_gpio_attr {
WM_GPIO_ATTR_FLOATING, /**< floating status */
WM_GPIO_ATTR_PULLHIGH, /**< pull high */
WM_GPIO_ATTR_PULLLOW /**< pull low */
};
/** Indicating gpio interrupt trigger type */
enum tls_gpio_irq_trig {
WM_GPIO_IRQ_TRIG_RISING_EDGE, /**< rising edge arises the interrupt */
WM_GPIO_IRQ_TRIG_FALLING_EDGE, /**< falling edge arises the interrupt */
WM_GPIO_IRQ_TRIG_DOUBLE_EDGE, /**< both rising edge and falling edge arise the interrupt */
WM_GPIO_IRQ_TRIG_HIGH_LEVEL, /**< high power level arises the interrupt */
WM_GPIO_IRQ_TRIG_LOW_LEVEL /**< low power level arises the interrupt */
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup GPIO_Driver_APIs GPIO Driver APIs
* @brief GPIO driver APIs
*/
/**
* @addtogroup GPIO_Driver_APIs
* @{
*/
/**
* @brief This function is used to config gpio function
*
* @param[in] gpio_pin gpio pin num
* @param[in] dir gpio direction
* @param[in] attr gpio attribute
*
* @return None
*
* @note None
*/
void tls_gpio_cfg(enum tls_io_name gpio_pin, enum tls_gpio_dir dir, enum tls_gpio_attr attr);
/**
* @brief This function is used to read gpio status
*
* @param[in] gpio_pin gpio pin num
*
* @retval 0 power level is low
* @retval 1 power level is high
*
* @note None
*/
u8 tls_gpio_read(enum tls_io_name gpio_pin);
/**
* @brief This function is used to modify gpio status
*
* @param[in] gpio_pin gpio pin num
* @param[in] value power level
* 0: low power level
* 1: high power level
*
* @return None
*
* @note None
*/
void tls_gpio_write(enum tls_io_name gpio_pin, u8 value);
/**
* @brief This function is used to config gpio interrupt
*
* @param[in] gpio_pin gpio pin num
* @param[in] mode interrupt trigger type
*
* @return None
*
* @note None
*/
void tls_gpio_irq_enable(enum tls_io_name gpio_pin, enum tls_gpio_irq_trig mode);
/**
* @brief This function is used to disable gpio interrupt
*
* @param[in] gpio_pin gpio pin num
*
* @return None
*
* @note None
*/
void tls_gpio_irq_disable(enum tls_io_name gpio_pin);
/**
* @brief This function is used to get gpio interrupt status
*
* @param[in] gpio_pin gpio pin num
*
* @retval 0 no interrupt happened
* @retval 1 interrupt happened
*
* @note None
*/
u8 tls_get_gpio_irq_status(enum tls_io_name gpio_pin);
/**
* @brief This function is used to clear gpio interrupt flag
*
* @param[in] gpio_pin gpio pin num
*
* @return None
*
* @note None
*/
void tls_clr_gpio_irq_status(enum tls_io_name gpio_pin);
/**
* @brief This function is used to register gpio interrupt
*
* @param[in] gpio_pin gpio pin num
* @param[in] callback the gpio interrupt call back function
* @param[in] arg parammeter for the callback
*
* @return None
*
* @note
* gpio callback function is called in interrupt,
* so can not operate the critical data in the callback fuuction,
* recommendation to send messages to other tasks to operate it.
*/
void tls_gpio_isr_register(enum tls_io_name gpio_pin,
tls_gpio_irq_callback callback,
void *arg);
/**
* @}
*/
/**
* @}
*/
#endif /* end of WM_GPIO_H */

View File

@ -0,0 +1,589 @@
/**
* @file wm_gpio_afsel.h
*
* @brief GPIO Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_GPIO_AFSEL_H
#define WM_GPIO_AFSEL_H
#include "wm_gpio.h"
#include "wm_regs.h"
#include "wm_irq.h"
#include "wm_osal.h"
#include "tls_common.h"
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup IOMUX_Driver_APIs IOMUX Driver APIs
* @brief IO Multiplex driver APIs
*/
/**
* @addtogroup IOMUX_Driver_APIs
* @{
*/
/**
* @brief config the pins used for highspeed spi
* @param numsel: config highspeed spi pins multiplex relation,valid para 0,1
* 0: hspi0 1: hspi1 only for 56pin
* hspi_ck PB06 hspi_ck PB12
* hspi_int PB07 hspi_int PB13
* hspi_cs PB09 hspi_cs PB14
* hspi_di PB10 hspi_di PB15
* hspi_do PB11 hspi_do PB16
* @return None
*/
void wm_hspi_gpio_config(uint8_t numsel);
/**
* @brief config the pins used for spi ck
* @param io_name: config spi ck pins name
* WM_IO_PB_01
* WM_IO_PB_02
* WM_IO_PB_15 only for 56pin
* WM_IO_PB_24 only for 56pin
*
* @return None
*/
void wm_spi_ck_config(enum tls_io_name io_name);
/**
* @brief config the pins used for spi cs
* @param io_name: config spi cs pins name
* WM_IO_PA_00
* WM_IO_PB_04
* WM_IO_PB_14 only for 56pin
* WM_IO_PB_23 only for 56pin
*
* @return None
*/
void wm_spi_cs_config(enum tls_io_name io_name);
/**
* @brief config the pins used for spi di
* @param io_name: config spi di pins name
* WM_IO_PB_00
* WM_IO_PB_03
* WM_IO_PB_16 only for 56pin
* WM_IO_PB_25 only for 56pin
*
* @return None
*/
void wm_spi_di_config(enum tls_io_name io_name);
/**
* @brief config the pins used for spi do
* @param io_name: config spi do pins name
* WM_IO_PA_07
* WM_IO_PB_05
* WM_IO_PB_17 only for 56pin
* WM_IO_PB_26 only for 56pin
*
* @return None
*/
void wm_spi_do_config(enum tls_io_name io_name);
/**
* @brief config the pins used for sdio host ck dat0 dat1 dat2 dat3
* @param numsel: config sdio ck cmd dat0 dat1 dat2 dat3 pins multiplex relation,valid para 0,1
* 0: 1: only for 56pin
* sdio_ck PB06 sdio_ck PA09
* sdio_cmd PB07 sdio_cmd PA10
* sdio_dat0 PB08 sdio_dat0 PA11
* sdio_dat1 PB09 sdio_dat1 PA12
* sdio_dat2 PB10 sdio_dat2 PA13
* sdio_dat3 PB11 sdio_dat3 PA14
*
* @return None
*/
void wm_sdio_host_config(uint8_t numsel);
/**
* @brief config the pins used for sdio slave ck dat0 dat1 dat2 dat3
* @param numsel: config sdio ck cmd dat0 dat1 dat2 dat3 pins multiplex relation,valid para 0
* 0:
* sdio_ck PB06
* sdio_cmd PB07
* sdio_dat0 PB08
* sdio_dat1 PB09
* sdio_dat2 PB10
* sdio_dat3 PB11
*
* @return None
*/
void wm_sdio_slave_config(uint8_t numsel);
/**
* @brief config the pins used for psram ck cs dat0 dat1 dat2 dat3
* @param numsel: config psram ck cs dat0 dat1 dat2 dat3 pins multiplex relation,valid para 0,1
* 0: 1: only for 56pin
* psram_ck PB00 psram_ck PA15
* psram_cs PB01 psram_cs PB27
* psram_dat0 PB02 psram_dat0 PB02
* psram_dat1 PB03 psram_dat1 PB03
* psram_dat2 PB04 psram_dat2 PB04
* psram_dat3 PB05 psram_dat3 PB05
* @return None
*/
void wm_psram_config(uint8_t numsel);
/**
* @brief config the pins used for uart0 tx
* @param io_name: config uart0 tx pins name
* WM_IO_PB_19
* WM_IO_PB_27 only for 56pin
*
* @return None
*/
void wm_uart0_tx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart0 rx
* @param io_name: config uart0 rx pins name
* WM_IO_PB_20
*
* @return None
*/
void wm_uart0_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart1 tx
* @param io_name: config uart1 tx pins name
* WM_IO_PB_06
*
* @return None
*/
void wm_uart1_tx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart1 rx
* @param io_name: config uart1 rx pins name
* WM_IO_PB_07
* WM_IO_PB_16 only for 56pin
*
* @return None
*/
void wm_uart1_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart1 rts
* @param io_name: config uart1 rts pins name
* WM_IO_PB_19
* WM_IO_PA_02 only for 56pin
*
* @return None
*/
void wm_uart1_rts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart1 cts
* @param io_name: config uart1 cts pins name
* WM_IO_PB_20
* WM_IO_PA_03 only for 56pin
*
* @return None
*/
void wm_uart1_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart2 tx or 7816-io
* @param io_name: config uart2 tx or 7816-io pins name
* WM_IO_PB_02
* WM_IO_PA_02 only for 56pin
*
* @return None
*/
void wm_uart2_tx_scio_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart2 rx
* @param io_name: config uart2 rx pins name
* WM_IO_PB_03
* WM_IO_PA_03 only for 56pin
*
* @return None
*/
void wm_uart2_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart2 rts or 7816-clk
* @param io_name: config uart2 rts or 7816-clk pins name
* WM_IO_PB_04
* WM_IO_PA_05 only for 56pin
*
* @return None
*/
void wm_uart2_rts_scclk_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart2 cts
* @param io_name: config uart2 cts pins name
* WM_IO_PB_05
* WM_IO_PA_06 only for 56pin
*
* @return None
*/
void wm_uart2_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart3 tx
* @param io_name: config uart1 tx pins name
* WM_IO_PB_00
* WM_IO_PA_05 only for 56pin
*
* @return None
*/
void wm_uart3_tx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart3 rx
* @param io_name: config uart1 rx pins name
* WM_IO_PB_01
* WM_IO_PA_06 only for 56pin
*
* @return None
*/
void wm_uart3_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart3 rts
* @param io_name: config uart3 rts pins name
* WM_IO_PA_02
*
* @return None
*/
void wm_uart3_rts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart3 cts
* @param io_name: config uart3 cts pins name
* WM_IO_PA_03
*
* @return None
*/
void wm_uart3_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 tx
* @param io_name: config uart1 tx pins name
* WM_IO_PB_04
* WM_IO_PA_08 only for 56pin
*
* @return None
*/
void wm_uart4_tx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 rx
* @param io_name: config uart1 rx pins name
* WM_IO_PB_05
* WM_IO_PA_09 only for 56pin
*
* @return None
*/
void wm_uart4_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 rts
* @param io_name: config uart4 rts pins name
* WM_IO_PA_05 only for 56pin
* WM_IO_PA_10 only for 56pin
*
* @return None
*/
void wm_uart4_rts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 cts
* @param io_name: config uart4 cts pins name
* WM_IO_PA_06 only for 56pin
* WM_IO_PA_11 only for 56pin
*
* @return None
*/
void wm_uart4_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 tx
* @param io_name: config uart1 tx pins name
* WM_IO_PA_08 only for 56pin
* WM_IO_PA_12 only for 56pin
* WM_IO_PB_18 only for 56pin
*
* @return None
*/
void wm_uart5_tx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 rx
* @param io_name: config uart1 rx pins name
* WM_IO_PA_09 only for 56pin
* WM_IO_PA_13 only for 56pin
* WM_IO_PB_17 only for 56pin
*
* @return None
*/
void wm_uart5_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 rts
* @param io_name: config uart4 rts pins name
* WM_IO_PA_14 only for 56pin
* WM_IO_PB_12 only for 56pin
*
* @return None
*/
void wm_uart5_rts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 cts
* @param io_name: config uart4 cts pins name
* WM_IO_PA_15 only for 56pin
* WM_IO_PB_13 only for 56pin
*
* @return None
*/
void wm_uart5_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s ck
* @param io_name: config i2s master ck pins name
* WM_IO_PA_04
* WM_IO_PB_08
* WM_IO_PA_08 only for 56pin
* WM_IO_PB_12 only for 56pin
*
* @return None
*/
void wm_i2s_ck_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s ws
* @param io_name: config i2s master ws pins name
* WM_IO_PA_01
* WM_IO_PB_09
* WM_IO_PA_09 only for 56pin
* WM_IO_PB_13 only for 56pin
*
* @return None
*/
void wm_i2s_ws_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s do
* @param io_name: config i2s master do pins name
* WM_IO_PA_00
* WM_IO_PB_11
* WM_IO_PA_10 only for 56pin
* WM_IO_PB_14 only for 56pin
*
* @return None
*/
void wm_i2s_do_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s di
* @param io_name: config i2s slave di pins name
* WM_IO_PA_07
* WM_IO_PB_10
* WM_IO_PA_11 only for 56pin
* WM_IO_PB_15 only for 56pin
*
* @return None
*/
void wm_i2s_di_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s mclk
* @param io_name: config i2s mclk pins name
* WM_IO_PA_00
*
* @return None
*/
void wm_i2s_mclk_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s extclk
* @param io_name: config i2s extclk pins name
* WM_IO_PA_07
*
* @return None
*/
void wm_i2s_extclk_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2c scl
* @param io_name: config i2c scl pins name
* WM_IO_PA_01
* WM_IO_PB_20
*
* @return None
*/
void wm_i2c_scl_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2c sda
* @param io_name: config i2c sda pins name
* WM_IO_PA_04
* WM_IO_PB_19
*
* @return None
*/
void wm_i2c_sda_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm0
* @param io_name: config pwm1 pins name
* WM_IO_PB_00
* WM_IO_PB_19
* WM_IO_PA_02 only for 56pin
* WM_IO_PA_10 only for 56pin
* WM_IO_PB_12 only for 56pin
*
* @return None
*/
void wm_pwm0_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm1
* @param io_name: config pwm1 pins name
* WM_IO_PB_01
* WM_IO_PB_20
* WM_IO_PA_03 only for 56pin
* WM_IO_PA_11 only for 56pin
* WM_IO_PB_13 only for 56pin
*
* @return None
*/
void wm_pwm1_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm2
* @param io_name: config pwm3 pins name
* WM_IO_PA_00
* WM_IO_PB_02
* WM_IO_PA_12 only for 56pin
* WM_IO_PB_14 only for 56pin
* WM_IO_PB_24 only for 56pin
*
* @return None
*/
void wm_pwm2_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm3
* @param io_name: config pwm4 pins name
* WM_IO_PA_01
* WM_IO_PB_03
* WM_IO_PA_13 only for 56pin
* WM_IO_PB_15 only for 56pin
* WM_IO_PB_25 only for 56pin
*
* @return None
*/
void wm_pwm3_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm4
* @param io_name: config pwm5 pins name
* WM_IO_PA_04
* WM_IO_PA_07
* WM_IO_PA_14 only for 56pin
* WM_IO_PB_16 only for 56pin
* WM_IO_PB_26 only for 56pin
*
* @return None
*/
void wm_pwm4_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm break
* @param io_name: config pwm break pins name
* WM_IO_PB_08
* WM_IO_PA_05 only for 56pin
* WM_IO_PA_08 only for 56pin
* WM_IO_PA_15 only for 56pin
* WM_IO_PB_17 only for 56pin
*
* @return None
*/
void wm_pwmbrk_config(enum tls_io_name io_name);
/**
* @brief config the pins used for swd
* @param enable: enable or disable chip swd function
* 1: enable
* 0: disable
*
* @return None
*/
void wm_swd_config(bool enable);
/**
* @brief config the pins used for adc
* @param Channel: the channel that shall be used
* 0~1: single-ended input
* 2~3: single-ended input only for 56pin
* 0 and 1 can be used differential input
* 2 and 3 can be used differential input only for 56pin
*
* @return None
*/
void wm_adc_config(u8 Channel);
/**
* @brief config the pins used for touch sensor
* @param io_name: config touch sensor pins name
* WM_IO_PA_07
* WM_IO_PB_00
* WM_IO_PB_01
* WM_IO_PB_02
* WM_IO_PB_03
* WM_IO_PB_04
* WM_IO_PB_05
* WM_IO_PB_06
* WM_IO_PB_07
* WM_IO_PB_08
* WM_IO_PB_09
* WM_IO_PA_09 only for 56pin
* WM_IO_PA_10 only for 56pin
* WM_IO_PA_12 only for 56pin
* WM_IO_PA_14 only for 56pin
*
* @return None
* @note If user use touch sensor function, firstly consider using WM_IO_PA_07 as TOUCH SENSOR pin.
*/
void wm_touch_sensor_config(enum tls_io_name io_name);
/**
* @brief disable all the gpio af
*
* @return None
*
* @note This function must call before any others for configure
* gpio Alternate functions
*/
void wm_gpio_af_disable(void);
/**
* @}
*/
/**
* @}
*/
#endif /* end of WM_GPIO_AFSEL_H */

289
include/driver/wm_hostspi.h Normal file
View File

@ -0,0 +1,289 @@
/**
* @file wm_hostspi.h
*
* @brief host spi Driver Module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_HOST_SPI_H
#define WM_HOST_SPI_H
#include "wm_type_def.h"
#include "list.h"
#include "wm_osal.h"
#include "wm_ram_config.h"
#define SPI_USE_DMA
#define SPI_DMA_CMD_MAX_SIZE (0x20)
#define SPI_DMA_BUF_MAX_SIZE (8160)
#define SPI_DMA_MAX_TRANS_SIZE (4092)
/**
* error code.
*/
#define TLS_SPI_STATUS_OK (0)
#define TLS_SPI_STATUS_EINVAL (-1)
#define TLS_SPI_STATUS_ENOMEM (-2)
#define TLS_SPI_STATUS_EBUSY (-3)
#define TLS_SPI_STATUS_ESHUTDOWN (-4)
#define TLS_SPI_STATUS_EPERM (-5)
#define TLS_SPI_STATUS_ECLKNOSUPPORT (-6)
#define TLS_SPI_STATUS_EMODENOSUPPORT (-7)
#define SPI_MASTER_FIFO_SIZE (32)
/**
* the SPI master controller's configuration data.
*/
/** configuration data. */
#define SPI_CPHA (0x01) /** clock phase. */
#define SPI_CPOL (0x02) /** clock polarity. */
#define TLS_SPI_MODE_0 (0|0) /** motorola mode. */
#define TLS_SPI_MODE_1 (0|SPI_CPHA)
#define TLS_SPI_MODE_2 (SPI_CPOL|0)
#define TLS_SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
#define TLS_SPI_CS_LOW 0x00 /** chipselect active low. */
#define TLS_SPI_CS_HIGH 0x01 /** chipselect active high. */
#define TLS_SPI_FCLK_MIN (1000) /** minimum work clock rate(Hz). */
#define TLS_SPI_FCLK_MAX (APB_CLK/2) /** maximum work clock rate(Hz). */
/** default configuration data. */
#define SPI_DEFAULT_SPEED (2000000) /** default clock rate is 2MHz. */
#define SPI_DEFAULT_MODE (TLS_SPI_MODE_0) /** default mode MODE_0. */
#define SPI_CS_ACTIVE_MODE (TLS_SPI_CS_LOW) /** default chipselect mode is active low. */
#define SPI_CS_INACTIVE_MODE (TLS_SPI_CS_HIGH)
/** SPI transaction message status. */
#define SPI_MESSAGE_STATUS_IDLE (0)
#define SPI_MESSAGE_STATUS_INPROGRESS (1)
#define SPI_MESSAGE_STATUS_DONE (2)
/**slave type*/
#define SPI_SLAVE_FLASH 0 /**flash */
#define SPI_SLAVE_CARD 1 /** SD card */
#define SPI_SLAVE_CONTROL_PIN 0
/**transfer type*/
#define SPI_BYTE_TRANSFER 0 /**byte transfer*/
#define SPI_WORD_TRANSFER 1 /**word transfer*/
#define SPI_DMA_TRANSFER 2 /** DMA transfer */
/**
* a read/write buffer pair
*
* SPI transfers always write the same number of bytes as they read.
* If the transmit buffer is null, zeroes will be shifted out while
* filling rx_buf. If the receive buffer is null, the data shifted in
* will be discarded.
*/
struct tls_spi_transfer
{
struct dl_list transfer_list; /**< transfers are sequenced through
tls_spi_message.transfers. */
const void *tx_buf; /**< data to be written, or NULL. */
void *rx_buf; /**< data to be read, or NULL. */
u32 len; /**< size of rx and tx buffers (in bytes). */
u32 delay_usecs; /**< microseconds to delay after this transfer. */
};
/**
* one multi-segment SPI transaction
*
* A struct tls_spi_message is used to execute an atomic sequence of data
* transfers, each represented by a struct tls_spi_transfer. The sequence
* is "atomic" in the sense that no other spi_message may use that SPI bus
* until that sequence completes.
*/
struct tls_spi_message
{
struct dl_list queue; /**< transaction messages are sequenced through
tls_spi_port.wait_queue. */
struct dl_list transfers; /**< list of transfer segments in this transaction. */
void (*complete) (void *); /**< called to report transaction completions. */
void *context; /**< the argument to complete() when it's called. */
u32 status; /**< transaction message status. */
};
/**
* driver structure to SPI master controller
*
* This data structure presents the SPI master controller's configuration
* data. The device attached to this SPI master controller share the same
* transfer mode, chipselect mode and clock rate. And this structure maintains
* a queue of tls_spi_message transactions and uses this tls_spi_message transaction
* to access to the SPI device. For each such message it queues, it calls the message's
* completion function when the transaction completes.
*/
struct tls_spi_port
{
u32 speed_hz; /**< clock rate to be used. */
u8 cs_active; /**< chipselect mode, maybe active low or active
high. */
u8 mode; /**< SPI transfer mode: mode_0(CPHA=0, CHOL=0),
mode_1(CPHA=0, CHOL=1), mode_2(CPHA=1,
CHOL=0), mode_3(CPHA=1, CHOL=1). */
u8 reconfig;
struct dl_list wait_queue; /**< wait list of transaction messages. */
tls_os_queue_t *lock;
tls_os_queue_t *msg_queue; /**< notify the schedule thread that there's
transaction message queued. */
struct tls_spi_message *current_message; /**< current transaction message
in-progressing. */
u32 current_remaining_transfer; /**< remaining transfer segments count in
current transaction message. */
struct tls_spi_transfer *current_transfer; /**< current transfer segment
in-progressing. */
u32 current_remaining_bytes; /**< remaining data length in current
transfer segment. */
u8 transtype; /**< transfer type */
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup MASTERSPI_Driver_APIs MASTER SPI Driver APIs
* @brief MASTERSPI driver APIs
*/
/**
* @addtogroup MASTERSPI_Driver_APIs
* @{
*/
/**
* @brief This function is used to initialize the SPI master driver.
*
* @param[in] None
*
* @retval TLS_SPI_STATUS_OK if initialize success
* @retval TLS_SPI_STATUS_EBUSY if SPI is already initialized
* @retval TLS_SPI_STATUS_ENOMEM if malloc SPI memory fail
*
* @note None
*/
int tls_spi_init(void);
/**
* @brief This function is used to setup the spi controller.
*
* @param[in] mode is CPOL and CPHA type defined in TLS_SPI_MODE_0 to TLS_SPI_MODE_3
* @param[in] cs_active is cs mode, defined as TLS_SPI_CS_LOW or TLS_SPI_CS_HIGH
* @param[in] fclk is spi clock,the unit is HZ.
*
* @retval TLS_SPI_STATUS_OK if setup success
* @retval TLS_SPI_STATUS_EMODENOSUPPORT if mode is not support
* @retval TLS_SPI_STATUS_EINVAL if cs_active is not support
* @retval TLS_SPI_STATUS_ECLKNOSUPPORT if fclk is not support
*
* @note None
*/
int tls_spi_setup(u8 mode, u8 cs_active, u32 fclk);
/**
* @brief This function is used to synchronous write data by SPI.
*
* @param[in] buf data to be sent.
* @param[in] len data length.
*
* @retval TLS_SPI_STATUS_OK if write success.
* @retval TLS_SPI_STATUS_EINVAL if argument is invalid.
* @retval TLS_SPI_STATUS_ENOMEM if there is no enough memory.
* @retval TLS_SPI_STATUS_ESHUTDOWN if SPI driver does not installed.
*
* @note None
*/
int tls_spi_write(const u8 * buf, u32 len);
/**
* @brief This function is used to synchronously read data from SPI.
*
* @param[in] buf is the buffer for saving SPI data.
* @param[in] len is the data length.
*
* @retval TLS_SPI_STATUS_OK if write success.
* @retval TLS_SPI_STATUS_EINVAL if argument is invalid.
* @retval TLS_SPI_STATUS_ENOMEM if there is no enough memory.
* @retval TLS_SPI_STATUS_ESHUTDOWN if SPI driver does not installed.
*
* @note None
*/
int tls_spi_read(u8 * buf, u32 len);
/**
* @brief This function is used to synchronously write command and then read data from SPI.
*
* @param[in] txbuf is the write data buffer.
* @param[in] n_tx is the write data length.
* @param[in] rxbuf is the read data buffer.
* @param[in] n_rx is the read data length.
*
* @retval TLS_SPI_STATUS_OK if write success.
* @retval TLS_SPI_STATUS_EINVAL if argument is invalid.
* @retval TLS_SPI_STATUS_ENOMEM if there is no enough memory.
* @retval TLS_SPI_STATUS_ESHUTDOWN if SPI driver has not been installed.
*
* @note None
*/
int tls_spi_read_with_cmd(const u8 * txbuf, u32 n_tx, u8 * rxbuf, u32 n_rx);
/**
* @brief This function is used to synchronous write 32bit command then write data from SPI.
*
* @param[in] cmd is the command data.
* @param[in] n_cmd is the command len,can not bigger than four
* @param[in] txbuf is the write data buffer.
* @param[in] n_tx is the write data length.
*
* @retval TLS_SPI_STATUS_OK if write success.
* @retval TLS_SPI_STATUS_EINVAL if argument is invalid.
* @retval TLS_SPI_STATUS_ENOMEM if there is no enough memory.
* @retval TLS_SPI_STATUS_ESHUTDOWN if SPI driver does not installed.
*
* @note None
*/
int tls_spi_write_with_cmd(const u8 * cmd, u32 n_cmd, const u8 * txbuf, u32 n_tx);
/**
* @brief This function is used to set SPI transfer mode.
*
* @param[in] type is the transfer type.
* SPI_BYTE_TRANSFER ->byte transfer;
* SPI_WORD_TRANSFER ->word transfer;
* SPI_DMA_TRANSFER ->DMA transfer;
*
* @return None
*
* @note None
*/
void tls_spi_trans_type(u8 type);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_HOST_SPI_H */

253
include/driver/wm_hspi.h Normal file
View File

@ -0,0 +1,253 @@
/**
* @file wm_hspi.h
*
*
* @brief High speed spi slave Module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_HSPI_H
#define WM_HSPI_H
#include "wm_type_def.h"
#include "wm_ram_config.h"
#define HSPI_TX_MEM_MALLOC 0 /** tx mem dynamic malloc*/
#define HSPI_INTERFACE_SPI 2 /** spi interface*/
#define HSPI_INTERFACE_SDIO 3 /** sdio interface*/
/**rx message*/
#define HSPI_RX_CMD_MSG 1
#define HSPI_RX_DATA_MSG 2
/**spi/sdio buffer*/
#define HSPI_TXBUF_NUM 2
#define HSPI_TX_DESC_NUM HSPI_TXBUF_NUM
#define HSPI_RXBUF_NUM 3
#define HSPI_RX_DESC_NUM HSPI_RXBUF_NUM
#define HSPI_TXBUF_SIZE 1500
#define HSPI_RXBUF_SIZE 1500
#define HSPI_TX_DESC_SIZE sizeof(struct tls_hspi_tx_desc)
#define HSPI_RX_DESC_SIZE sizeof(struct tls_hspi_rx_desc)
/*****************************************************************************
* sdio/hspi sram partition
******************************************************************************/
/* HSPI txbuf zone */
#define HSPI_TXBUF_BASE_ADDR ((u32)(SLAVE_HSPI_SDIO_ADDR))
#if HSPI_TX_MEM_MALLOC
#define HSPI_TXBUF_TOTAL_SIZE 0
#else
#define HSPI_TXBUF_TOTAL_SIZE (HSPI_TXBUF_SIZE * HSPI_TXBUF_NUM)
#endif
/** HSPI tx desc zone */
#define HSPI_TX_DESC_BASE_ADDR ((u32)(HSPI_TXBUF_BASE_ADDR + HSPI_TXBUF_TOTAL_SIZE))
#define HSPI_TX_DESC_TOTAL_SIZE (HSPI_TX_DESC_SIZE * HSPI_TX_DESC_NUM) //28*3=84
/** HSPI rxbuf zone */
#define HSPI_RXBUF_BASE_ADDR ((u32)(HSPI_TX_DESC_BASE_ADDR + HSPI_TX_DESC_TOTAL_SIZE))
#define HSPI_RXBUF_TOTAL_SIZE (HSPI_RXBUF_NUM * HSPI_RXBUF_SIZE) //4500
/** HSPI rx desc zone */
#define HSPI_RX_DESC_BASE_ADDR ((u32)(HSPI_RXBUF_BASE_ADDR + HSPI_RXBUF_TOTAL_SIZE))
#define HSPI_RX_DESC_TOTAL_SIZE (HSPI_RX_DESC_SIZE * HSPI_RX_DESC_NUM) //36
#define SDIO_CIS_SIZE (0x80)
#define SDIO_CMD_RXBUF_SIZE 256
#define SDIO_CIS0_ADDR (HSPI_RX_DESC_BASE_ADDR + HSPI_RX_DESC_TOTAL_SIZE) //128
#define SDIO_CIS1_ADDR (SDIO_CIS0_ADDR + SDIO_CIS_SIZE) //128
#define SDIO_CMD_RXBUF_ADDR (SDIO_CIS1_ADDR + SDIO_CIS_SIZE)
#define CIS_FUN0_ADDR ((u32)SDIO_CIS0_ADDR)
#define CIS_FUN1_ADDR ((u32)SDIO_CIS1_ADDR)
#define FN0_TPL_FUNCID (CIS_FUN0_ADDR + 0x00)
#define FN0_TPL_FUNCE (CIS_FUN0_ADDR + 0x04)
#define FN0_TPL_FUNCE_MAXBLK (CIS_FUN0_ADDR + 0x08)
#define FN0_TPL_MANFID_MID (CIS_FUN0_ADDR + 0x0C)
#define FN0_TPL_END (CIS_FUN0_ADDR + 0x10)
#define FN1_TPL_FUNCID (CIS_FUN1_ADDR + 0x00)
#define FN1_TPL_FUNCE (CIS_FUN1_ADDR + 0x04)
#define FN1_TPL_FUNCE_VER (CIS_FUN1_ADDR + 0x08)
#define FN1_TPL_FUNCE_NSN (CIS_FUN1_ADDR + 0x0C)
#define FN1_TPL_FUNCE_CSASIZE (CIS_FUN1_ADDR + 0x10)
#define FN1_TPL_FUNCE_OCR (CIS_FUN1_ADDR + 0x14)
#define FN1_TPL_FUNCE_MINPWR (CIS_FUN1_ADDR + 0x18)
#define FN1_TPL_FUNCE_STANDBY (CIS_FUN1_ADDR + 0x1C)
#define FN1_TPL_FUNCE_OPTBW (CIS_FUN1_ADDR + 0x20)
#define FN1_TPL_FUNCE_NTIMEOUT (CIS_FUN1_ADDR + 0x24)
#define FN1_TPL_FUNCE_AVGPWR (CIS_FUN1_ADDR + 0x28)
#define FN1_TPL_END (CIS_FUN1_ADDR + 0x30)
/** SDIO interrupt bit definition */
#define SDIO_WP_INT_SRC_CMD_DOWN (1UL<<3)
#define SDIO_WP_INT_SRC_CMD_UP (1UL<<2)
#define SDIO_WP_INT_SRC_DATA_DOWN (1UL<<1)
#define SDIO_WP_INT_SRC_DATA_UP (1UL<<0)
/** Definition of send data descriptor structure */
struct tls_hspi_tx_desc {
volatile u32 valid_ctrl;
u32 buf_info;
u32 buf_addr[3];
u32 next_desc_addr;
#if HSPI_TX_MEM_MALLOC
u32 txbuf_addr; /**< txbuf addr, pbuf and buf_addr[0] are different */
#endif
};
/** Definition of receive data descriptor structure */
struct tls_hspi_rx_desc {
u32 valid_ctrl;
u32 buf_addr;
u32 next_desc_addr;
};
/** struct tls_slave_hspi */
struct tls_slave_hspi {
u8 ifusermode;
s16 (*rx_cmd_callback)(char *buf);
s16 (*rx_data_callback)(char *buf);
s16 (*tx_data_callback)(char *buf);
struct tls_hspi_tx_desc *curr_tx_desc; /**< Upstream data management */
struct tls_hspi_rx_desc *curr_rx_desc; /**< Downlink data management */
#if HSPI_TX_MEM_MALLOC
u8 txdoneflag; /**< tx done falg*/
#endif
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup HSPI_Driver_APIs HSPI Driver APIs
* @brief HSPI driver APIs
*/
/**
* @addtogroup HSPI_Driver_APIs
* @{
*/
/**
* @brief This function is used to initial HSPI register.
*
* @param[in] None
*
* @retval 0 success
* @retval other failed
*
* @note When the system is initialized, the function has been called, so users can not call this function.
*/
int tls_slave_spi_init(void);
/**
* @brief This function is used to enable or disable user mode.
*
* @param[in] ifenable TRUE or FALSE
*
* @return None
*
* @note If the user enables the user mode, RICM instruction in the system will not be used by SPI.
* If the user wants to use the SPI interface as other use, need to enable the user mode.
* This function must be called before the register function.
*/
void tls_set_hspi_user_mode(u8 ifenable);
/**
* @brief This function is used to set high speed interface type.
*
* @param[in] type is the interface type. HSPI_INTERFACE_SPI or HSPI_INTERFACE_SDIO
*
* @return None
*
* @note None
*/
void tls_set_high_speed_interface_type(int type);
/**
* @brief This function is used to register hspi rx command interrupt.
*
* @param[in] rx_cmd_callback is the hspi rx interrupt call back function.
*
* @return None
*
* @note None
*/
void tls_hspi_rx_cmd_callback_register(s16 (*rx_cmd_callback)(char *buf));
/**
* @brief This function is used to register hspi rx data interrupt.
*
* @param[in] rx_data_callback is the hspi rx interrupt call back function.
*
* @return None
*
* @note None
*/
void tls_hspi_rx_data_callback_register(s16 (*rx_data_callback)(char *buf));
/**
* @brief This function is used to register hspi tx data interrupt.
*
* @param[in] tx_data_callback is the hspi tx interrupt call back function.
*
* @return None
*
* @note None
*/
void tls_hspi_tx_data_callback_register(s16 (*tx_data_callback)(char *buf));
/**
* @brief This function is used to transfer data.
*
* @param[in] txbuf is a buf for saving user data.
* @param[in] len is the data length.
*
* @retval transfer data len success
* @retval 0 failed
*
* @note None
*/
int tls_hspi_tx_data(char *txbuf, int len);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_HSPI_H */

140
include/driver/wm_i2c.h Normal file
View File

@ -0,0 +1,140 @@
/**************************************************************************//**
* @file wm_i2c.h
* @author
* @version
* @date
* @brief
* @copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
*****************************************************************************/
#ifndef __WM_I2C_H
#define __WM_I2C_H
#ifdef __cplusplus
extern "C" {
#endif
#include "wm_regs.h"
#include "wm_type_def.h"
#include "wm_cpu.h"
#include "wm_irq.h"
typedef struct
{
__IO uint32_t PRER_LO;
__IO uint32_t PRER_HI;
__IO uint32_t CTRL;
__O uint32_t TX_RX;
__O uint32_t CR_SR;
__I uint32_t TXR;
__I uint32_t CR;
}I2C_T;
#define I2C ((I2C_T *)(HR_I2C_BASE_ADDR))
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup I2C_Driver_APIs I2C Driver APIs
* @brief I2C driver APIs
*/
/**
* @addtogroup I2C_Driver_APIs
* @{
*/
/**
* @brief Init the I2C module
* @param freq I2C reference clock frequency in Hz that will be used
* @note
* the value must be between 100k and 400k
*/
void tls_i2c_init(u32 freq);
/** I2C initialization mask */
#define wm_i2c_int_mask(bl) do { tls_bitband_write(HR_I2C_CTRL, 6, bl);}while(0);
/**
* @brief send stop signal
*
*/
void tls_i2c_stop(void);
/**
* @brief Waiting for ack signal
* @retval
* - \ref WM_FAILED
* - \ref WM_SUCCESS
*/
int tls_i2c_wait_ack(void);
/**
* @brief Writes the data to data register of I2C module
* when ifstart one the start signal will be sent followed by the data
* when ifstart zero only the data will be send
* @param[in] data the data will be write to the data register of I2C module
* @param[in] ifstart when one send start signal, when zero don't
* @retval
*
*/
void tls_i2c_write_byte(u8 data, u8 ifstart);
/**
* @brief Get the data stored in data register of I2C module
* @param[in] ifack when one send ack after reading the data register,when zero don't
* @param[in] ifstop when one send stop signal after read, when zero do not send stop
* @retval
* the received data
*/
u8 tls_i2c_read_byte(u8 ifack, u8 ifstop);
/**
* @brief This function is used to register i2c transfer done callback function.
* @param[in] done is the i2c transfer done callback function.
* @retval None
* @note None
*/
void wm_i2c_transfer_done_register(void (*done)(void));
/**
* @brief Start writing through int mode
* @param[in] devaddr the device address
* @param[in] wordaddr when one send stop signal after read, when zero do not send stop
* @param[in] buf the address point where data shoule be stored
* @param[in] len the length of data will be received
* @retval
* - \ref WM_FAILED
* - \ref WM_SUCCESS
*/
int wm_i2c_start_write_it(uint8_t devaddr, uint8_t wordaddr, uint8_t * buf, uint16_t len);
/**
* @brief Get the data stored in data register of I2C module
* @param[in] ifack when one send ack after reading the data register,when zero don't
* @param[in] ifstop when one send stop signal after read, when zero do not send stop
* @retval the received data
*/
int wm_i2c_start_read_it(uint8_t devaddr, uint8_t wordaddr, uint8_t * buf, uint16_t len);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

300
include/driver/wm_i2s.h Normal file
View File

@ -0,0 +1,300 @@
#ifndef __WM_I2S_H
#define __WM_I2S_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
//#include "wm_regs_cm3.h"
#include "wm_regs.h"
#include "wm_debug.h"
#include "wm_dma.h"
typedef void (*tls_i2s_callback)(uint32_t *data, uint16_t *len);
typedef struct {
__IO uint32_t CTRL;
__IO uint32_t INT_MASK;
__IO uint32_t INT_SRC;
__I uint32_t INT_STATUS;
__O uint32_t TX;
__I uint32_t RX;
} I2S_T;
typedef struct {
uint32_t I2S_Mode_MS; //master or slave mode
uint32_t I2S_Mode_SS; //stereo or single channel
uint32_t I2S_Mode_LR; //left or right channel
uint32_t I2S_Trans_STD;
uint32_t I2S_DataFormat;
uint32_t I2S_AudioFreq;
uint32_t I2S_MclkFreq;
} I2S_InitDef;
typedef struct _wm_dma_desc
{
unsigned int valid;
unsigned int dma_ctrl;
unsigned int src_addr;
unsigned int dest_addr;
struct _wm_dma_desc * next;
}wm_dma_desc;
typedef struct _dma_handler_type
{
uint8_t channel;
void (* XferCpltCallback)( struct _dma_handler_type * hdma); /*!< DMA transfer complete callback */
void (* XferHalfCpltCallback)( struct _dma_handler_type * hdma); /*!< DMA Half transfer complete callback */
}wm_dma_handler_type;
#define I2S ((I2S_T *)HR_I2S_REG_BASE)
#define I2S_MODE_MASTER ((bool)0x0)
#define I2S_MODE_SLAVE ((bool)0x1)
#define I2S_RIGHT_CHANNEL ((bool)0x0)
#define I2S_LEFT_CHANNEL ((bool)0x1)
#define I2S_Standard (0x0UL)
#define I2S_Standard_MSB (0x1000000UL)
#define I2S_Standard_PCMA (0x2000000UL)
#define I2S_Standard_PCMB (0x3000000UL)
#define I2S_DataFormat_8 (8)
#define I2S_DataFormat_16 (16)
#define I2S_DataFormat_24 (24)
#define I2S_DataFormat_32 (32)
#define I2S_CTRL_CHSEL_MASK (1UL<<23)
#define I2S_CTRL_CHSEL_LEFT (1UL<<23)
#define I2S_CTRL_MONO (1UL<<22)
#define I2S_CTRL_STEREO (0UL<<22)
#define I2S_CTRL_RXDMA_EN (1UL<<21)
#define I2S_CTRL_TXDMA_EN (1UL<<20)
#define I2S_CTRL_RX_CLR (1UL<<19)
#define I2S_CTRL_TX_CLR (1UL<<18)
#define I2S_CTRL_LZCEN (1UL<<17)
#define I2S_CTRL_RZCEN (1UL<<16)
#define I2S_CTRL_RXTH(n) ((n-1)<<12)
#define I2S_CTRL_TXTH(n) ((n)<<9)
#define I2S_CTRL_SLAVE_SEL (1UL<<8)
#define I2S_CTRL_MUTE (1UL<<3)
#define I2S_CTRL_RXE (1UL<<2)
#define I2S_CTRL_TXE (1UL<<1)
#define I2S_CTRL_EN (1UL<<0)
#define I2S_INT_MASK_LZC ((uint16_t)0x200)
#define I2S_INT_MASK_RZC ((uint16_t)0x100)
#define I2S_INT_MASK_TXDONE ((uint16_t)0x080)
#define I2S_INT_MASK_TXTH ((uint16_t)0x040)
#define I2S_INT_MASK_TXOV ((uint16_t)0x020)
#define I2S_INT_MASK_TXUD ((uint16_t)0x010)
#define I2S_INT_MASK_RXDONE ((uint16_t)0x008)
#define I2S_INT_MASK_RXTH ((uint16_t)0x004)
#define I2S_INT_MASK_RXOV ((uint16_t)0x002)
#define I2S_INT_MASK_RXUD ((uint16_t)0x002)
#define I2S_FLAG_TX ((uint16_t)0x1000)
#define I2S_FLAG_RX ((uint16_t)0x0800)
#define I2S_FLAG_I2S ((uint16_t)0x0400)
#define I2S_FLAG_LZC ((uint16_t)0x0200)
#define I2S_FLAG_RZC ((uint16_t)0x0100)
#define I2S_FLAG_TXDONE ((uint16_t)0x0080)
#define I2S_FLAG_TXTH ((uint16_t)0x0040)
#define I2S_FLAG_TXOV ((uint16_t)0x0020)
#define I2S_FLAG_TXUD ((uint16_t)0x0010)
#define I2S_FLAG_RXDONE ((uint16_t)0x0008)
#define I2S_FLAG_RXTH ((uint16_t)0x0004)
#define I2S_FLAG_RXOV ((uint16_t)0x0002)
#define I2S_FLAG_RXUD ((uint16_t)0x0001)
#define WM_I2S_TX_DMA_CHANNEL (1)
#define WM_I2S_RX_DMA_CHANNEL (5)
typedef struct wm_i2s_buf_s {
volatile uint32_t *txbuf;
volatile uint32_t txlen;
volatile uint32_t txtail;
volatile uint32_t *rxbuf;
volatile uint32_t rxlen;
volatile uint32_t int_txlen;
volatile uint32_t rxhead;
volatile uint8_t rxdata_ready;
volatile uint8_t txdata_done;
/** function pointer for data receiver */
void (*rx_callback)(void);
/** function pointer for data transmit */
void (*tx_callback)(uint32_t *data, uint16_t *len);
} wm_i2s_buf_t;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup I2S_Driver_APIs I2S Driver APIs
* @brief I2S driver APIs
*/
/**
* @addtogroup I2S_Driver_APIs
* @{
*/
/**
* @brief Register a callback function
* @param callback pointer to a callback function in which you can prepare the next buffer
* @param callback->data pointer to data buffer to be prepared
* @param callback->len size of the data buffer to be prepared in 32-bit
* @note The registerred callback function will be called as long as the transmission begins
* @retval none
*/
void wm_i2s_register_callback(tls_i2s_callback callback);
/**
* @brief Initializes the I2S according to the specified parameters
* in the I2S_InitDef.
* @param opts pointer to a I2S_InitDef structure that contains
* the configuration information for I2S module
* @retval status
*/
int wm_i2s_port_init(I2S_InitDef *opts);
/**
* @brief stop i2s module
* @retval none
*/
void wm_i2s_tx_rx_stop(void);
/**
* @brief Transmit an amount of data in blocking mode with Interrupt
* @param data a 16-bit pointer to data buffer.
* @param len number of data sample to be sent:
* @param next_data a 16-bit pointer to the next data buffer, same size with data; set to NULL if it's not needed
* @note the len parameter means the number of 16-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @note This function will call the registerred callback function as long as the transmission begins
* @retval status
*/
int wm_i2s_tx_int(int16_t *data, uint16_t len, int16_t *next_data);
/**
* @brief Transmit an amount of data in blocking mode with DMA's normal mode
* @param data a 16-bit pointer to data buffer.
* @param len number of data sample to be sent:
* @param next_data a 16-bit pointer to the next data buffer, same size with data; set to NULL if it's not needed
* @note the len parameter means the number of 32-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @note This function will call the registerred callback function as long as the transmission begins
* @retval status
*/
int wm_i2s_tx_dma(int16_t *data, uint16_t len, int16_t *next_data);
/**
* @brief Transmit an amount of data in blocking mode with DMA's link mode
* @param data a 16-bit pointer to data buffer.
* @param len number of data sample to be sent:
* @param next_data a 16-bit pointer to the next data buffer, same size with data:
* @note the len parameter means the number of 32-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.Set len to 0xffff will exit this rountine.
* @note This function will call the registerred callback function as long as the data or next_data
* is sent out.So prepare it in the callback.
* @note See the demo for detail use.
* @retval status
*/
int wm_i2s_tx_dma_link(int16_t *data, uint16_t len, int16_t *next_data);
/**
* @brief Receive an amount of data in blocking mode with Interrupt
* @param data a 16-bit pointer to the Receive data buffer.
* @param len number of data sample to be received:
* @note the len parameter means the number of 16-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @retval status
*/
int wm_i2s_rx_int(int16_t *data, uint16_t len);
/**
* @brief Receive an amount of data in blocking mode with DMA
* @param data a 16-bit pointer to the Receive data buffer.
* @param len number of data sample to be received:
* @note the len parameter means the number of 16-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @retval status
*/
int wm_i2s_rx_dma(int16_t *data, uint16_t len);
/**
* @brief Full-Duplex Transmit/Receive data in blocking mode using Interrupt
* @param opts pointer to a I2S_InitDef structure that contains
* the configuration information for I2S module
* @param data_tx a 16-bit pointer to the Transmit data buffer.
* @param data_rx a 16-bit pointer to the Receive data buffer.
* @param len number of data sample to be sent:
* @note the len parameter means the number of 16-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @retval status
*/
int wm_i2s_tx_rx_int(I2S_InitDef *opts, int16_t *data_tx, int16_t *data_rx, uint16_t len);
/**
* @brief Full-Duplex Transmit/Receive data in blocking mode using DMA
* @param opts pointer to a I2S_InitDef structure that contains
* the configuration information for I2S module
* @param data_tx a 16-bit pointer to the Transmit data buffer.
* @param data_rx a 16-bit pointer to the Receive data buffer.
* @param len number of data sample to be sent:
* @note the len parameter means the number of 16-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @retval status
*/
int wm_i2s_tx_rx_dma(I2S_InitDef *opts, int16_t *data_tx, int16_t *data_rx, uint16_t len);
int wm_i2s_transmit_dma(wm_dma_handler_type *hdma, uint16_t *data, uint16_t len);
int wm_i2s_receive_dma(wm_dma_handler_type *hdma, uint16_t *data, uint16_t len);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,328 @@
/**
* @file wm_internal_flash.h
*
* @brief inter flash driver
*
* @author dave
*
* @copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_INTERNAL_FLASH_H
#define WM_INTERNAL_FLASH_H
#include "wm_type_def.h"
#include "wm_osal.h"
typedef volatile unsigned char vu8;
typedef volatile unsigned short vu16;
typedef volatile unsigned long vu32;
#define M8(adr) (*((vu8 *) (adr)))
#define M16(adr) (*((vu16*) (adr)))
#define M32(adr) (*((vu32*) (adr)))
#define INSIDE_FLS_SECTOR_SIZE 0x1000
#define INSIDE_FLS_PAGE_SIZE 256
#define INSIDE_FLS_BASE_ADDR 0x8000000UL
#define INSIDE_FLS_SECBOOT_ADDR (INSIDE_FLS_BASE_ADDR + 0x02000)
enum TYPE_FLASH_ID{
SPIFLASH_MID_GD = 0xC8,
SPIFLASH_MID_ESMT = 0x1C,
SPIFLASH_MID_PUYA = 0x85,
SPIFLASH_MID_WINBOND = 0xEF,
SPIFLASH_MID_FUDANMICRO = 0xA1,
SPIFLASH_MID_BOYA = 0x68,
SPIFLASH_MID_XMC = 0x20,
SPIFLASH_MID_XTX = 0x0B,
SPIFLASH_MID_TSINGTENG = 0xEB, /*UNIGROUP TSINGTENG*/
};
typedef union {
struct {
uint32_t _reserved0: 1; /*!< bit: 0 Reserved */
uint32_t code_decrypt: 1; /*!< bit: 1 read code from AHB decrypt flag */
uint32_t dbus_decrypt: 1; /*!< bit: 2 read data from Flash register controller decrypt flag */
uint32_t data_decrypt: 1; /*!< bit: 3 read data from AHB decrypt flag */
uint32_t prikey_sel: 3; /*!< bit: 4.. 6 private key selection: 0 : first one; 1 : second one; */
uint32_t decrypt_start: 1; /*!< bit: 7 write 1 to start RSA decryption operation */
uint32_t _reserved2: 24; /*!< bit: 8.. 31 Reserved */
} b; /*!< Structure Access by bit */
uint32_t w; /*!< Type Access by whole register */
} FLASH_ENCRYPT_CTRL_Type;
/**
* @typedef struct Flash Registers
*/
typedef struct
{
vu32 ACR; /**< offset 0x000 */
vu32 KEYR; /**< offset 0x004 */
vu32 SR; /**< offset 0x008 */
vu32 CR; /**< offset 0x00C */
vu32 AR; /**< offset 0x010 */
} FLASH_TypeDef;
#define FLASH_HS 0x00000001
/** Flash Keys */
#define RDPRT_KEY 0x5AA5
#define FLASH_KEY1 0x57696E6E
#define FLASH_KEY2 0x65724D69
#define FLASH_KEY3 0x63726F21
/** Flash Control Register definitions */
#define FLASH_PG 0x00000001
#define FLASH_PER 0x00000002
#define FLASH_MER 0x00000004
#define FLASH_STRT 0x00000008
#define FLASH_LOCK 0x00000020
#define FLASH_ERRIE 0x00000040
#define FLASH_EOPIE 0x00000080
/** Flash Status Register definitions */
#define FLASH_BSY 0x00000001
#define FLASH_PGERR 0x00000002
#define FLASH_EOP 0x00000004
#define TLS_FLS_STATUS_OK (0)
#define TLS_FLS_STATUS_EINVAL (1)
#define TLS_FLS_STATUS_EBUSY (2)
#define TLS_FLS_STATUS_EPERM (3)
#define TLS_FLS_STATUS_ENOSUPPORT (4)
#define TLS_FLS_STATUS_EEXIST (5)
#define TLS_FLS_STATUS_ENOMEM (6)
#define TLS_FLS_STATUS_EOVERFLOW (7)
#define TLS_FLS_STATUS_ENODEV (8)
#define TLS_FLS_STATUS_EDEV (9)
#define TLS_FLS_STATUS_EIO (10)
#define TLS_FLS_STATUS_ENODRV (11)
#define TLS_FLS_PARAM_TYPE_ID (0)
#define TLS_FLS_PARAM_TYPE_SIZE (1)
#define TLS_FLS_PARAM_TYPE_PAGE_SIZE (2)
#define TLS_FLS_PARAM_TYPE_PROG_SIZE (3)
#define TLS_FLS_PARAM_TYPE_SECTOR_SIZE (4)
#define TLS_FLS_FLAG_UNDER_PROTECT (1<<0)
#define TLS_FLS_FLAG_FAST_READ (1<<1)
#define TLS_FLS_FLAG_AAAI (1<<2)
#define CMD_START_Pos 8U /*!< CMD start position */
#define CMD_START_Msk (1UL << CMD_START_Pos) /*!< CMD start Mask */
typedef struct {
uint16_t eraseSize;
uint16_t pageSize;
} FLASH_OTP_WR_PARAM_ST;
/**
* @struct tls_inside_fls
*/
struct tls_inside_fls
{
tls_os_sem_t *fls_lock;
unsigned char flashid;
unsigned int density;
FLASH_OTP_WR_PARAM_ST OTPWRParam;
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup INNER_FLASH_Driver_APIs INNER FLASH Driver APIs
* @brief INNER FLASH driver APIs
*/
/**
* @addtogroup INNER_FLASH_Driver_APIs
* @{
*/
/**
* @brief This function is used to unlock flash protect area [0x0~0x2000].
*
* @param None
*
* @return 0-success,non-zero-failure
*
* @note None
*/
int tls_flash_unlock(void);
/**
* @brief This function is used to lock flash protect area [0x0~0x2000].
*
* @param None
*
* @return 0-success,non-zero-failure
*
* @note None
*/
int tls_flash_lock(void);
/**
* @brief This function is used to get the flash semaphore.
*
* @param None
*
* @return None
*
* @note None
*/
void tls_fls_sem_lock(void);
/**
* @brief This function is used to release the flash semaphore.
*
* @param None
*
* @return None
*
* @note None
*/
void tls_fls_sem_unlock(void);
/**
* @brief This function is used to read the unique id of the internal flash.
*
* @param[out] uuid Specified the address to save the uuid, the length must be greater than or equals to 18 bytes.
*
* @retval TLS_FLS_STATUS_OK if read sucsess
* @retval TLS_FLS_STATUS_EIO if read fail
*
* @note The uuid's length must be greater than or equals to 18 bytes.
*/
int tls_fls_read_unique_id(unsigned char *uuid);
/**
* @brief This function is used to initial flash module structer.
*
* @param[in] None
*
* @retval TLS_FLS_STATUS_OK if init sucsess
* @retval TLS_FLS_STATUS_EBUSY already inited
* @retval TLS_FLS_STATUS_ENOMEM memory error
*
* @note None
*/
int tls_fls_init(void);
/**
* @brief This function is used to read data from the flash.
*
* @param[in] addr Specifies the starting address to read from.
* @param[in] buf Specified the address to save the readback data.
* @param[in] len Specifies the length of the data to read.
*
* @retval TLS_FLS_STATUS_OK if read sucsess
* @retval TLS_FLS_STATUS_EIO if read fail
*
* @note None
*/
int tls_fls_read(u32 addr, u8 * buf, u32 len);
/**
* @brief This function is used to write data into the flash.
*
* @param[in] addr Specifies the starting address to write to
* @param[in] buf Pointer to a byte array that is to be written
* @param[in] len Specifies the length of the data to be written
*
* @retval TLS_FLS_STATUS_OK if write flash success
* @retval TLS_FLS_STATUS_EPERM if flash struct point is null
* @retval TLS_FLS_STATUS_ENODRV if flash driver is not installed
* @retval TLS_FLS_STATUS_EINVAL if argument is invalid
* @retval TLS_FLS_STATUS_EIO if io error
*
* @note None
*/
int tls_fls_write(u32 addr, u8 * buf, u32 len);
/**
* @brief This function is used to erase the appointed sector
*
* @param[in] sector sector num of the flash, 4K bytes every sector
*
* @retval TLS_FLS_STATUS_OK if read sucsess
* @retval other if read fail
*
* @note None
*/
int tls_fls_erase(u32 sector);
/**
* @brief This function is used to initialize system parameter postion by flash density
*
* @param None
*
* @retval None
*
* @note must be called before tls_param_init
*/
void tls_fls_sys_param_postion_init(void);
/**
* @brief This function is used to read data from the security registers.
*
* @param[in] addr Specifies the starting address to read from.
* @param[in] buf Specified the address to save the readback data.
* @param[in] len Specifies the length of the data to read.
*
* @retval TLS_FLS_STATUS_OK if read sucsess
* @retval TLS_FLS_STATUS_EPERM if flash struct point is null
*
* @note None
*/
int tls_fls_otp_read(u32 addr, u8 *buf, u32 len);
/**
* @brief This function is used to write data into the security registers.
*
* @param[in] addr Specifies the starting address to write to
* @param[in] buf Pointer to a byte array that is to be written
* @param[in] len Specifies the length of the data to be written
*
* @retval TLS_FLS_STATUS_OK if write the security registers success
* @retval TLS_FLS_STATUS_EPERM if flash struct point is null
* @retval TLS_FLS_STATUS_ENOSUPPORT if flash is not supported
* @retval TLS_FLS_STATUS_EINVAL if argument is invalid
* @retval TLS_FLS_STATUS_ENOMEN if no memory
*
* @note None
*/
int tls_fls_otp_write(u32 addr, u8 *buf, u32 len);
/**
* @brief This function is used to lock the security registers.
*
* @param None
*
* @return None
*
* @note None
*/
int tls_fls_otp_lock(void);
#endif /* WM_INTERNAL_FLASH_H */

204
include/driver/wm_io.h Normal file
View File

@ -0,0 +1,204 @@
/**
* @file wm_io.h
*
* @brief IO Driver Module
*
* @author lilm
*
* @copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_IO_H
#define WM_IO_H
#define TLS_IO_AB_OFFSET (0x40011400 - 0x40011200)
/** io name */
enum tls_io_name {
WM_IO_PA_00 = 0, /**< gpio a0 */
WM_IO_PA_01, /**< gpio a1 */
WM_IO_PA_02, /**< gpio a2 */
WM_IO_PA_03, /**< gpio a3 */
WM_IO_PA_04, /**< gpio a4 */
WM_IO_PA_05, /**< gpio a5 */
WM_IO_PA_06, /**< gpio a6 */
WM_IO_PA_07, /**< gpio a7 */
WM_IO_PA_08, /**< gpio a8 */
WM_IO_PA_09, /**< gpio a9 */
WM_IO_PA_10, /**< gpio a10 */
WM_IO_PA_11, /**< gpio a11 */
WM_IO_PA_12, /**< gpio a12 */
WM_IO_PA_13, /**< gpio a13 */
WM_IO_PA_14, /**< gpio a14 */
WM_IO_PA_15, /**< gpio a15 */
WM_IO_PB_00, /**< gpio b0 */
WM_IO_PB_01, /**< gpio b1 */
WM_IO_PB_02, /**< gpio b2 */
WM_IO_PB_03, /**< gpio b3 */
WM_IO_PB_04, /**< gpio b4 */
WM_IO_PB_05, /**< gpio b5 */
WM_IO_PB_06, /**< gpio b6 */
WM_IO_PB_07, /**< gpio b7 */
WM_IO_PB_08, /**< gpio b8 */
WM_IO_PB_09, /**< gpio b9 */
WM_IO_PB_10, /**< gpio b10 */
WM_IO_PB_11, /**< gpio b11 */
WM_IO_PB_12, /**< gpio b12 */
WM_IO_PB_13, /**< gpio b13 */
WM_IO_PB_14, /**< gpio b14 */
WM_IO_PB_15, /**< gpio b15 */
WM_IO_PB_16, /**< gpio b16 */
WM_IO_PB_17, /**< gpio b17 */
WM_IO_PB_18, /**< gpio b18 */
WM_IO_PB_19, /**< gpio b19 */
WM_IO_PB_20, /**< gpio b20 */
WM_IO_PB_21, /**< gpio b21 */
WM_IO_PB_22, /**< gpio b22 */
WM_IO_PB_23, /**< gpio b23 */
WM_IO_PB_24, /**< gpio b24 */
WM_IO_PB_25, /**< gpio b25 */
WM_IO_PB_26, /**< gpio b26 */
WM_IO_PB_27, /**< gpio b27 */
WM_IO_PB_28, /**< gpio b28 */
WM_IO_PB_29, /**< gpio b29 */
WM_IO_PB_30, /**< gpio b30 */
WM_IO_PB_31 /**< gpio b31 */
};
/** option 1 of the io */
#define WM_IO_OPTION1 1
/** option 2 of the io */
#define WM_IO_OPTION2 2
/** option 3 of the io */
#define WM_IO_OPTION3 3
/** option 4 of the io */
#define WM_IO_OPTION4 4
/** option 5 of the io */
#define WM_IO_OPTION5 5
/** option 6 of the io */
#define WM_IO_OPTION6 6
/** option 7 of the io */
#define WM_IO_OPTION7 7
/* io option1 */
#define WM_IO_OPT1_I2C_DAT WM_IO_OPTION1
#define WM_IO_OPT1_PWM1 WM_IO_OPTION1
#define WM_IO_OPT1_PWM2 WM_IO_OPTION1
#define WM_IO_OPT1_PWM3 WM_IO_OPTION1
#define WM_IO_OPT1_PWM4 WM_IO_OPTION1
#define WM_IO_OPT1_PWM5 WM_IO_OPTION1
#define WM_IO_OPT1_UART0_RXD WM_IO_OPTION1
#define WM_IO_OPT1_UART0_TXD WM_IO_OPTION1
#define WM_IO_OPT1_PWM_BRAKE WM_IO_OPTION1
#define WM_IO_OPT1_I2S_M_EXTCLK WM_IO_OPTION1
#define WM_IO_OPT1_SPI_M_DO WM_IO_OPTION1
#define WM_IO_OPT1_SPI_M_DI WM_IO_OPTION1
#define WM_IO_OPT1_SPI_M_CS WM_IO_OPTION1
#define WM_IO_OPT1_SPI_M_CK WM_IO_OPTION1
#define WM_IO_OPT1_I2S_S_RL WM_IO_OPTION1
#define WM_IO_OPT1_I2S_S_SCL WM_IO_OPTION1
#define WM_IO_OPT1_I2S_S_SDA WM_IO_OPTION1
#define WM_IO_OPT1_I2S_M_RL WM_IO_OPTION1
#define WM_IO_OPT1_I2S_M_SCL WM_IO_OPTION1
#define WM_IO_OPT1_I2S_M_SDA WM_IO_OPTION1
#define WM_IO_OPT1_JTAG_RST WM_IO_OPTION1
#define WM_IO_OPT1_JTAG_TDO WM_IO_OPTION1
#define WM_IO_OPT1_JTAG_TDI WM_IO_OPTION1
#define WM_IO_OPT1_JTAG_TCK_SWDCK WM_IO_OPTION1
#define WM_IO_OPT1_JTAG_TMS_SWDAT WM_IO_OPTION1
#define WM_IO_OPT1_UART1_RXD WM_IO_OPTION1
#define WM_IO_OPT1_UART1_TXD WM_IO_OPTION1
#define WM_IO_OPT1_UART1_RTS WM_IO_OPTION1
#define WM_IO_OPT1_UART1_CTS WM_IO_OPTION1
#define WM_IO_OPT1_SDIO_DAT WM_IO_OPTION1
/* io option2 */
#define WM_IO_OPT2_PWM1 WM_IO_OPTION2
#define WM_IO_OPT2_PWM2 WM_IO_OPTION2
#define WM_IO_OPT2_PWM3 WM_IO_OPTION2
#define WM_IO_OPT2_PWM4 WM_IO_OPTION2
#define WM_IO_OPT2_PWM5 WM_IO_OPTION2
#define WM_IO_OPT2_SPI_M_DO WM_IO_OPTION2
#define WM_IO_OPT2_SPI_M_DI WM_IO_OPTION2
#define WM_IO_OPT2_SPI_M_CS WM_IO_OPTION2
#define WM_IO_OPT2_SPI_M_CK WM_IO_OPTION2
#define WM_IO_OPT2_I2C_SCL WM_IO_OPTION2
#define WM_IO_OPT2_I2S_M_EXTCLK WM_IO_OPTION2
#define WM_IO_OPT2_UART1_RXD WM_IO_OPTION2
#define WM_IO_OPT2_UART1_TXD WM_IO_OPTION2
#define WM_IO_OPT2_UART1_RTS WM_IO_OPTION2
#define WM_IO_OPT2_UART1_CTS WM_IO_OPTION2
#define WM_IO_OPT2_I2C_DAT WM_IO_OPTION2
#define WM_IO_OPT2_PWM_BRAKE WM_IO_OPTION2
#define WM_IO_OPT2_UART0_RTS WM_IO_OPTION2
#define WM_IO_OPT2_UART0_CTS WM_IO_OPTION2
#define WM_IO_OPT2_SDIO_DAT WM_IO_OPTION2
#define WM_IO_OPT2_HSPI_CK WM_IO_OPTION2
#define WM_IO_OPT2_HSPI_INT WM_IO_OPTION2
#define WM_IO_OPT2_HSPI_CS WM_IO_OPTION2
#define WM_IO_OPT2_HSPI_DI WM_IO_OPTION2
#define WM_IO_OPT2_HSPI_DO WM_IO_OPTION2
/* io option3 */
#define WM_IO_OPT3_UART0_RXD WM_IO_OPTION3
#define WM_IO_OPT3_UART0_TXD WM_IO_OPTION3
#define WM_IO_OPT3_UART0_RTS WM_IO_OPTION3
#define WM_IO_OPT3_UART0_CTS WM_IO_OPTION3
#define WM_IO_OPT3_SPI_M_DO WM_IO_OPTION3
#define WM_IO_OPT3_SPI_M_DI WM_IO_OPTION3
#define WM_IO_OPT3_SPI_M_CS WM_IO_OPTION3
#define WM_IO_OPT3_SDIO_CK WM_IO_OPTION3
#define WM_IO_OPT3_SDIO_CMD WM_IO_OPTION3
#define WM_IO_OPT3_SDIO_DAT WM_IO_OPTION3
/* io option4 */
#define WM_IO_OPT4_I2S_M_MCLK WM_IO_OPTION4
#define WM_IO_OPT4_I2S_M_RL WM_IO_OPTION4
#define WM_IO_OPT4_I2S_M_SCL WM_IO_OPTION4
#define WM_IO_OPT4_I2S_M_SDA WM_IO_OPTION4
/* io option5 */
#define WM_IO_OPT5_GPIO WM_IO_OPTION5
/* io option6 */
#define WM_IO_OPT6_ADC WM_IO_OPTION6
#define WM_IO_OPT6_LCD_COM WM_IO_OPTION6
#define WM_IO_OPT6_LCD_SEG WM_IO_OPTION6
/* io option7 */
#define WM_IO_OPT7_TOUCH_SENSOR WM_IO_OPTION7
/**
* @brief This function is used to config io function
*
* @param[in] name io name
* @param[in] option io function option, value is WM_IO_OPT*_*, also is WM_IO_OPTION1~6
*
* @return None
*
* @note None
*/
void tls_io_cfg_set(enum tls_io_name name, u8 option);
/**
* @brief This function is used to get io function config
*
* @param[in] name io name
*
* @retval WM_IO_OPTION1~6 Mapping io function
*
* @note None
*/
int tls_io_cfg_get(enum tls_io_name name);
#endif /* end of WM_IO_H */

118
include/driver/wm_irq.h Normal file
View File

@ -0,0 +1,118 @@
/**
* @file wm_irq.h
*
* @brief interupt driver module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_IRQ_H
#define WM_IRQ_H
#include "wm_type_def.h"
typedef void (*intr_handler_func) (void *);
/**
* @typedef struct tls_irq_handler
*/
typedef struct tls_irq_handler
{
void (*handler) (void *);
void *data;
u32 counter;
} tls_irq_handler_t;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup IRQ_Driver_APIs IRQ Driver APIs
* @brief IRQ driver APIs
*/
/**
* @addtogroup IRQ_Driver_APIs
* @{
*/
/**
* @brief This function is used to initial system interrupt.
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_irq_init(void);
/**
* @brief This function is used to register interrupt handler function.
*
* @param[in] vec_no interrupt NO
* @param[in] handler
* @param[in] *data
*
* @return None
*
* @note None
*/
void tls_irq_register_handler(u8 vec_no, intr_handler_func handler, void *data);
/**
* @brief This function is used to enable interrupt.
*
* @param[in] vec_no interrupt NO
*
* @return None
*
* @note None
*/
void tls_irq_enable(u8 vec_no);
/**
* @brief This function is used to disable interrupt.
*
* @param[in] vec_no interrupt NO
*
* @return None
*
* @note None
*/
void tls_irq_disable(u8 vec_no);
/**
* @brief This function is used to get the isr count.
*
* @param[in] None
*
* @retval count
*
* @note None
*/
u8 tls_get_isr_count(void);
void tls_irq_priority(u8 vec_no, u32 prio);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_IRQ_H */

238
include/driver/wm_lcd.h Normal file
View File

@ -0,0 +1,238 @@
/**
* @file wm_lcd.h
*
* @brief LCD Driver Module
*
* @author dave
*
* @copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_LCD_H
#define __WM_LCD_H
#ifdef __cplusplus
extern "C" {
#endif
#include "wm_regs.h"
#include <stdbool.h>
/**
* @brief LCD Register Declaration
*
*/
typedef struct
{
/** Control Register */
__IO uint32_t CTRL;
/** Refresh Rate Prescaler Register */
__IO uint32_t FRAMECNT;
__IO uint32_t COM0;
__IO uint32_t COM1;
__IO uint32_t COM2;
__IO uint32_t COM3;
__IO uint32_t COM4;
__IO uint32_t COM5;
__IO uint32_t COM6;
__IO uint32_t COM7;
/** LCD COM Control Register */
__IO uint32_t COM_EN;
/** LCD SEG Control Register */
__IO uint32_t SEG_EN;
} LCD_T;
/** LCD base pointer */
#define LCD ((LCD_T *)HR_LCD_REG_BASE)
typedef enum
{
/** Static (2 levels) */
BIAS_STATIC = LCD_BIAS_STATIC,
/** 1/2 Bias (3 levels) */
BIAS_ONEHALF = LCD_BIAS_ONEHALF,
/** 1/3 Bias (4 levels) */
BIAS_ONETHIRD = LCD_BIAS_ONETHIRD,
/** 1/4 Bias (4 levels) */
BIAS_ONEFOURTH = LCD_BIAS_ONEFOURTH,
} LCD_BiasDef;
typedef enum
{
/** VLCD 2.7v */
VLCD27 = LCD_VLCD_27,
/** VLCD 2.9v */
VLCD29 = LCD_VLCD_29,
/** VLCD 3.1v */
VLCD31 = LCD_VLCD_31,
/** VLCD 3.3v */
VLCD33 = LCD_VLCD_33,
} LCD_VlcdDef;
typedef enum
{
/** Static (segments can be multiplexed with LCD_COM[0]) */
DUTY_STATIC = LCD_DUTY_STATIC,
/** 1/2 Duty cycle (segments can be multiplexed with LCD_COM[0:1]) */
DUTY_ONEHALF = LCD_DUTY_ONEHALF,
/** 1/3 Duty cycle (segments can be multiplexed with LCD_COM[0:2]) */
DUTY_ONETHIRD = LCD_DUTY_ONETHIRD,
/** 1/4 Duty cycle (segments can be multiplexed with LCD_COM[0:3]) */
DUTY_ONEFOURTH = LCD_DUTY_ONEFOURTH,
/** 1/5 Duty cycle (segments can be multiplexed with LCD_COM[0:4]) */
DUTY_ONEFIFTH = LCD_DUTY_ONEFIFTH,
/** 1/6 Duty cycle (segments can be multiplexed with LCD_COM[0:5]) */
DUTY_ONESIXTH = LCD_DUTY_ONESIXTH,
/** 1/7 Duty cycle (segments can be multiplexed with LCD_COM[0:6]) */
DUTY_ONESEVENTH = LCD_DUTY_ONESEVENTH,
/** 1/8 Duty cycle (segments can be multiplexed with LCD_COM[0:7]) */
DUTY_ONEEIGHTH = LCD_DUTY_ONEEIGHTH,
} LCD_DutyDef;
typedef struct tls_lcd_options
{
/** */
bool enable;
/** Bias configuration */
LCD_BiasDef bias;
/** Duty configuration */
LCD_DutyDef duty;
/** Vlcd configuration */
LCD_VlcdDef vlcd;
/** com number */
uint8_t com_number;
/** Fresh rate configuration */
uint16_t fresh_rate;
} tls_lcd_options_t;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup LCD_Driver_APIs LCD Driver APIs
* @brief LCD driver APIs
*/
/**
* @addtogroup LCD_Driver_APIs
* @{
*/
/**
* @brief Initialize LCD Frame Counter
* @param[in] com_num Number of the com
* @param[in] freq LCD reference refresh frequency in Hz that will be used
*/
void tls_lcd_fresh_ratio(uint8_t com_num, uint16_t freq);
/**
* @brief initialize the LCD module
*
*/
void tls_lcd_init(tls_lcd_options_t *opts);
/**
* @brief Initialize LCD Frame Counter
* @param[in] freq LCD reference refresh frequency in Hz that will be used
*
*/
void tls_lcd_fresh_rate(uint16_t freq);
/**
* @brief Turn on or clear a segment
* @param[in] com Which COM line to update
* @param[in] bit Bit index of which field to change
* @param[in] enable When one will set segment, when zero will clear segment
* @note Before this function be called, the module must have been intialized
*/
void tls_lcd_seg_set(int com, int bit, int on_off);
/**
* @brief Select the voltage of LCD module
* @param[in] vlcd This parameter can be one of the following values:
* - \ref VLCD27
* - \ref VLCD29
* - \ref VLCD31
* - \ref VLCD33
*/
void tls_lcd_vlcd_sel(LCD_VlcdDef vlcd);
/**
* @brief Set the duty of LCD module
* @param[in] duty This parameter can be one of the following values:
* - \ref DUTY_STATIC
* - \ref DUTY_ONEHALF
* - \ref DUTY_ONETHIRD
* - \ref DUTY_ONEFOURTH
* - \ref DUTY_ONEFIFTH
* - \ref DUTY_ONESIXTH
* - \ref DUTY_ONESEVENTH
* - \ref DUTY_ONEEIGHTH
*
*/
void tls_lcd_duty_set(LCD_DutyDef duty);
/**
* @brief Set the bias of LCD module
* @param[in] duty This parameter can be one of the following values:
* - \ref BIAS_STATIC
* - \ref BIAS_ONEHALF
* - \ref BIAS_ONETHIRD
* - \ref BIAS_ONEFOURTH
*
*/
void tls_lcd_bias_set(LCD_BiasDef bias);
/**
* @brief Enable or disable clock of LCD module
* @param[in] enable When one enable the clock of LCD module, when zero disable
*/
#define TLS_LCD_CLK_ENABLE(enable) \
do { \
tls_bitband_write(HR_CLK_BASE_ADDR, HR_CLK_LCD_GATE_Pos, enable); \
} while(0)
/**
* @brief Enable or disable the LCD module
* @param[in] enable When one enable the LCD module, when zero disable
*
*/
#define TLS_LCD_ENABLE(enable) \
do { \
tls_bitband_write(HR_LCD_CR, LCD_CR_EN_Pos, enable); \
} while(0)
/**
* @brief Enable or disable the LCD module
* @param[in] enable When one close LCD module, when zero open the LCD module
*
*/
#define TLS_LCD_POWERDOWM(enable) \
do { \
tls_bitband_write(HR_LCD_CR, LCD_CR_PD_Pos, enable); \
} while(0)
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

254
include/driver/wm_pmu.h Normal file
View File

@ -0,0 +1,254 @@
/**
* @file wm_pmu.h
*
* @brief pmu driver module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_PMU_H
#define WM_PMU_H
#include "wm_type_def.h"
/** peripheral type */
typedef enum {
TLS_PERIPHERAL_TYPE_I2C = (1 << 0), /**< peripheral type : I2C */
TLS_PERIPHERAL_TYPE_UART0 = (1 << 1), /**< peripheral type : UART0 */
TLS_PERIPHERAL_TYPE_UART1 = (1 << 2), /**< peripheral type : UART1 */
TLS_PERIPHERAL_TYPE_UART2 = (1 << 3), /**< peripheral type : UART2 */
TLS_PERIPHERAL_TYPE_UART3 = (1 << 4), /**< peripheral type : UART3 */
TLS_PERIPHERAL_TYPE_UART4 = (1 << 5), /**< peripheral type : UART4 */
TLS_PERIPHERAL_TYPE_UART5 = (1 << 6), /**< peripheral type : UART4 */
TLS_PERIPHERAL_TYPE_LSPI = (1 << 7), /**< peripheral type : LSPI */
TLS_PERIPHERAL_TYPE_DMA = (1 << 8), /**< peripheral type : DMA */
TLS_PERIPHERAL_TYPE_TIMER = (1 << 10), /**< peripheral type : TIMER */
TLS_PERIPHERAL_TYPE_GPIO = (1 << 11), /**< peripheral type : GPIO */
TLS_PERIPHERAL_TYPE_SDADC = (1 << 12), /**< peripheral type : SDADC */
TLS_PERIPHERAL_TYPE_PWM = (1 << 13), /**< peripheral type : PWM */
TLS_PERIPHERAL_TYPE_LCD = (1 << 14), /**< peripheral type : LCD */
TLS_PERIPHERAL_TYPE_I2S = (1 << 15), /**< peripheral type : I2S */
TLS_PERIPHERAL_TYPE_RSA = (1 << 16), /**< peripheral type : RSA */
TLS_PERIPHERAL_TYPE_GPSEC = (1 << 17), /**< peripheral type : GPSEC */
TLS_PERIPHERAL_TYPE_SDIO_MASTER = (1<<18), /**< peripheral type : SDIO */
TLS_PERIPHERAL_TYPE_PSRAM = (1<<19), /**< peripheral type : PSRAM */
TLS_PERIPHERAL_TYPE_BT = (1<<20), /**< peripheral type : BT */
TLS_PERIPHERAL_TYPE_TOUCH_SENSOR = (1 << 21) /**< peripheral type : TOUCH */
}tls_peripheral_type_s;
/** callback function of PMU interrupt */
typedef void (*tls_pmu_irq_callback)(void *arg);
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup PMU_Driver_APIs PMU Driver APIs
* @brief PMU driver APIs
*/
/**
* @addtogroup PMU_Driver_APIs
* @{
*/
/**
* @brief This function is used to register pmu timer1 interrupt
*
* @param[in] callback the pmu timer1 interrupt call back function
* @param[in] arg parameter of call back function
*
* @return None
*
* @note
* user not need clear interrupt flag.
* pmu timer1 callback function is called in interrupt,
* so can not operate the critical data in the callback fuuction,
* recommendation to send messages to other tasks to operate it.
*/
void tls_pmu_timer1_isr_register(tls_pmu_irq_callback callback, void *arg);
/**
* @brief This function is used to register pmu timer0 interrupt
*
* @param[in] callback the pmu timer0 interrupt call back function
* @param[in] arg parameter of call back function
*
* @return None
*
* @note
* user not need clear interrupt flag.
* pmu timer0 callback function is called in interrupt,
* so can not operate the critical data in the callback fuuction,
* recommendation to send messages to other tasks to operate it.
*/
void tls_pmu_timer0_isr_register(tls_pmu_irq_callback callback, void *arg);
/**
* @brief This function is used to register pmu gpio interrupt
*
* @param[in] callback the pmu gpio interrupt call back function
* @param[in] arg parameter of call back function
*
* @return None
*
* @note
* user not need clear interrupt flag.
* pmu gpio callback function is called in interrupt,
* so can not operate the critical data in the callback fuuction,
* recommendation to send messages to other tasks to operate it.
*/
void tls_pmu_gpio_isr_register(tls_pmu_irq_callback callback, void *arg);
/**
* @brief This function is used to register pmu sdio interrupt
*
* @param[in] callback the pmu sdio interrupt call back function
* @param[in] arg parameter of call back function
*
* @return None
*
* @note
* user not need clear interrupt flag.
* pmu sdio callback function is called in interrupt,
* so can not operate the critical data in the callback fuuction,
* recommendation to send messages to other tasks to operate it.
*/
void tls_pmu_sdio_isr_register(tls_pmu_irq_callback callback, void *arg);
/**
* @brief This function is used to select pmu clk
*
* @param[in] bypass pmu clk whether or not use bypass mode
* 1 pmu clk use 32K by 40MHZ
* other pmu clk 32K by calibration circuit
*
* @return None
*
* @note None
*/
void tls_pmu_clk_select(u8 bypass);
/**
* @brief This function is used to start pmu timer0
*
* @param[in] second vlaue of timer0 count[s]
*
* @return None
*
* @note None
*/
void tls_pmu_timer0_start(u16 second);
/**
* @brief This function is used to stop pmu timer0
*
* @param None
*
* @return None
*
* @note None
*/
void tls_pmu_timer0_stop(void);
/**
* @brief This function is used to start pmu timer1
*
* @param[in] second vlaue of timer1 count[ms]
*
* @return None
*
* @note None
*/
void tls_pmu_timer1_start(u16 msec);
/**
* @brief This function is used to stop pmu timer1
*
* @param None
*
* @return None
*
* @note None
*/
void tls_pmu_timer1_stop(void);
/**
* @brief This function is used to start pmu goto standby
*
* @param None
*
* @return None
*
* @note None
*/
void tls_pmu_standby_start(void);
/**
* @brief This function is used to start pmu goto sleep
*
* @param None
*
* @return None
*
* @note None
*/
void tls_pmu_sleep_start(void);
/**
* @brief This function is used to close peripheral's clock
*
* @param[in] devices peripherals
*
* @return None
*
* @note None
*/
void tls_close_peripheral_clock(tls_peripheral_type_s devices);
/**
* @brief This function is used to open peripheral's clock
*
* @param[in] devices peripherals
*
* @return None
*
* @note None
*/
void tls_open_peripheral_clock(tls_peripheral_type_s devices);
/**
* @}
*/
/**
* @}
*/
#endif

66
include/driver/wm_psram.h Normal file
View File

@ -0,0 +1,66 @@
#ifndef __WM_PSRAM_H__
#define __WM_PSRAM_H__
#define PSRAM_ADDR_START 0x30000000
#define PSRAM_SIZE_BYTE 0x00800000
typedef enum{
PSRAM_SPI = 0,
PSRAM_QPI,
} psram_mode_t;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup PSRAM_Driver_APIs PSRAM Driver APIs
* @brief PSRAM driver APIs
*/
/**
* @addtogroup PSRAM_Driver_APIs
* @{
*/
/**
* @brief This function is used to init the psram .
*
* @param[in] mode is work mode, PSRAM_SPI or PSRAM_QPI
*
* @retval none
*
* @note None
*/
void psram_init(psram_mode_t mode);
/**
* @brief This function is used to Copy block of memory in dma mode .
*
* @param[in] src Pointer to the source of data to be copied
* @param[in] dst Pointer to the destination array where the content is to be copied
* @param[in] num Number of bytes to copy
*
* @retval num Number of bytes that's been copied
*
* @note None
*/
int memcpy_dma(unsigned char *dst, unsigned char *src, int num);
/**
* @}
*/
/**
* @}
*/
#endif

400
include/driver/wm_pwm.h Normal file
View File

@ -0,0 +1,400 @@
/**
* @file wm_pwm.h
*
* @brief pwm driver module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_PWM_H
#define WM_PWM_H
#include "wm_type_def.h"
/** pwm channel's maximum number */
#define PWM_CHANNEL_MAX_NUM 5
/** pwm work mode for signal generate */
enum tls_pwm_out_mode
{
WM_PWM_OUT_MODE_BRAKE = 0, /**< brake mode */
WM_PWM_OUT_MODE_ALLSYC, /**< all synchronous mode */
WM_PWM_OUT_MODE_2SYC, /**< two channel synchronous mode */
WM_PWM_OUT_MODE_MC, /**< complementary mode */
WM_PWM_OUT_MODE_INDPT /**< independent mode */
};
/** interrupt type for capture mode */
enum tls_pwm_cap_int_type{
WM_PWM_CAP_RISING_EDGE_INT, /**< rising edge arises the interrupt */
WM_PWM_CAP_FALLING_EDGE_INT, /**< falling edge arises the interrupt */
WM_PWM_CAP_RISING_FALLING_EDGE_INT, /**< both rising edge and falling edge arise the interrupt */
WM_PWM_CAP_DMA_INT /**< dma request */
};
/** pwm output status */
enum tls_pwm_out_en_state{
WM_PWM_OUT_EN_STATE_TRI, /**< set tristate status */
WM_PWM_OUT_EN_STATE_OUT /**< set output status */
};
/** pwm count mode */
enum tls_pwm_cnt_type{
WM_PWM_CNT_TYPE_EDGE_ALLGN_CAP, /**< edge alignment(only capture mode) */
WM_PWM_CNT_TYPE_EDGE_ALIGN_OUT, /**< edge alignment(only output mode) */
WM_PWM_CNT_TYPE_CENTER_ALIGN /**< central alignment */
};
/** pwm cycle type */
enum tls_pwm_loop_type{
WM_PWM_LOOP_TYPE_SINGLE, /**< single mode */
WM_PWM_LOOP_TYPE_LOOP /**< auto load */
};
/** pwm waveform inversion mode */
enum tls_pwm_waveform_inversion{
WM_PWM_WAVEFORM_NOINVERSION, /**< not inverse */
WM_PWM_WAVEFORM_INVERSION /**< inversion */
};
/** pwm output level in the brake mode */
enum tls_pwm_brake_out_level{
WM_PWM_BRAKE_OUT_HIGH, /**< output high level */
WM_PWM_BRAKE_OUT_LOW /**< output low level */
};
/** pwm initial parameters */
typedef struct _pwm_init_param{
enum tls_pwm_out_mode mode; /**< work mode */
u8 channel; /**< channel id 0~4 */
u16 clkdiv; /**< clock divided value */
u8 period; /**< period value(output frequency F = CLK/CLK_DIV/PERIOD) */
u8 duty; /**< duty radio (range 0~255, high level or low level by out_inversion decided */
bool dten; /**< enable dead zone time (ENABLE or DISABLE) */
u8 dtclkdiv; /**< dead zone clock divided value (0~3) */
u8 dtcnt; /**< period number of dead zone time (0~255) */
enum tls_pwm_cnt_type cnt_type; /**< count type */
enum tls_pwm_loop_type loop_type; /**< cycle type */
bool inverse_en; /**< output is inverse */
u8 pnum; /**< generate interrupt after pnum period */
bool pnum_int; /**< period interrupt is enable */
}pwm_init_param;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup PWM_Driver_APIs PWM Driver APIs
* @brief PWM driver APIs
*/
/**
* @addtogroup PWM_Driver_APIs
* @{
*/
/**
* @brief This function is used to register the pwm interrupt callback function
*
* @param[in] callback the pwm interrupt callback function
*
* @return None
*
* @note None
*/
void tls_pwm_isr_register(void (*callback)(void));
/**
* @brief This function is used to set duty radio
*
* @param[in] channel pwm channel NO.,range form 0 to 4
* @param[in] duty Number of active levels
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_duty_config(u8 channel, u8 duty);
/**
* @brief This function is used to set frequency
*
* @param[in] channel pwm channel NO., range form 0 to 4
* @param[in] clkdiv clock divider, range 0 to 65535
* @param[in] period the number of the counting clock cycle
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_freq_config(u8 channel, u16 clkdiv, u8 period);
/**
* @brief This function is used to set the output mode
*
* @param[in] channel pwm channel NO., range form 0 to 4
* @param[in] mode pwm work mode for signal generate
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_out_mode_config(u8 channel, enum tls_pwm_out_mode mode);
/**
* @brief This function is used to set the counting mode
*
* @param[in] channel pwm channel NO.,range form 0 to 4
* @param[in] cnt_type counting mode
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_cnt_type_config(u8 channel, enum tls_pwm_cnt_type cnt_type);
/**
* @brief This function is used to set whether to loop
*
* @param[in] channel pwm channel NO.,range form 0 to 4
* @param[in] loop_mode whether to loop
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_loop_mode_config(u8 channel, enum tls_pwm_loop_type loop_mode);
/**
* @brief This function is used to set whether to inverse the output
*
* @param[in] channel pwm channel NO.,range form 0 to 4
* @param[in] en ENABLE or DISABLE
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_out_inverse_cmd(u8 channel, bool en);
/**
* @brief This function is used to set the number of period to be generated
*
* @param[in] channel pwm channel NO.,range form 0 to 4
* @param[in] pnum the number of period to be generated,range from 0 to 255
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_stoptime_by_period_config(u8 channel, u8 pnum);
/**
* @brief This function is used to set output enable
*
* @param[in] channel pwm channel NO.,channel 0 or channel 4
* @param[in] en ENABLE or DISABLE
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_output_en_cmd(u8 channel, bool en);
/**
* @brief This function is used to set the dead time
*
* @param[in] channel pwm channel NO.,channel 0 or channel 2
* @param[in] dten whether enalbe the deat time, ENABLE or DISABLE
* @param[in] dtclkdiv dead zone clock divider, range 0 to 3
* @param[in] dtcnt the number of the counting clock cycle, range 0 to 255
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_deadzone_config(u8 channel, bool dten, u8 dtclkdiv, u8 dtcnt);
/**
* @brief This function is used to set whether to inverse the capture input
*
* @param[in] channel pwm channel NO.,channel 0 or channel 4
* @param[in] en ENABLE or DISABLE
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_capture_inverse_cmd(u8 channel, bool en);
/**
* @brief This function is used to set break mode
*
* @param[in] channel pwm channel NO.,channel 0 or channel 4
* @param[in] en whether enable the break mode,ENABLE or DISABLE
* @param[in] brok when break
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_brake_mode_config(u8 channel, bool en, enum tls_pwm_brake_out_level brok);
/**
* @brief This function is used to enable the capture mode
*
* @param[in] channel pwm channel NO.,channel 0 or channel 4
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_capture_mode_config(u8 channel);
/**
* @brief This function is used to set the interrupt about the number of period
*
* @param[in] channel pwm channel,range from 0 to 4
* @param[in] en enble or disable
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_stoptime_irq_cmd(u8 channel, bool en);
/**
* @brief This function is used to set the interrupt about the
capture
*
* @param[in] channel pwm channel,channel 0 or channel 4
* @param[in] int_type interrupt type
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_capture_irq_type_config(u8 channel, enum tls_pwm_cap_int_type int_type);
/**
* @brief This function is used to initial pwm(out mode)
*
* @param[in] pwm_param structure containing the initialization parameters
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_out_init(pwm_init_param *pwm_param);
/**
* @brief This function is used to initial pwm(capture mode)
*
* @param[in] channel pwm channel, channel 0 or channel 4
* @param[in] clkdiv clock divider, range 0 to 65535
* @param[in] inverse_en whether the input signal is reversed
* @param[in] int_type interrupt type
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_cap_init(u8 channel, u16 clkdiv, bool inverse_en, enum tls_pwm_cap_int_type int_type);
/**
* @brief This function is used to start pwm
*
* @param[in] channel pwm channel, range from 0 to 4
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_start(u8 channel);
/**
* @brief This function is used to stop pwm
*
* @param[in] channel pwm channel no, range form 0 to 4
* @param[in] freq frequency, range from 1 to 156250
*
* @return None
*
* @note None
*/
void tls_pwm_freq_set(u8 channel, u32 freq);
/**
* @brief This function is used to set duty radio
*
* @param[in] channel pwm channel NO., range form 0 to 4
* @param[in] duty duty radio, range from 0 to 255
*
* @return None
*
* @note None
*/
void tls_pwm_duty_set(u8 channel, u8 duty);
/**
* @brief This function is used to initial pwm
*
* @param[in] channel pwm channel, range from 0 to 4
* @param[in] freq is a pointer to frequency, freq range from 1 to 156250
* @param[in] duty is a pointer to duty radio, duty range from 0 to 255
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_init(u8 channel,u32 freq, u8 duty, u8 pnum);
/**
* @brief This function is used to stop pwm
*
* @param[in] channel pwm channel, range from 0 to 4
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_pwm_stop(u8 channel);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_PWM_H */

109
include/driver/wm_rtc.h Normal file
View File

@ -0,0 +1,109 @@
/**
* @file wm_rtc.h
*
* @brief rtc Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_RTC_H
#define WM_RTC_H
#include <time.h>
#include "wm_type_def.h"
/** rtc interrupt callback */
typedef void (*tls_rtc_irq_callback)(void *arg);
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup RTC_Driver_APIs RTC Driver APIs
* @brief RTC driver APIs
*/
/**
* @addtogroup RTC_Driver_APIs
* @{
*/
/**
* @brief This function is used to set pmu rtc time
*
* @param[in] tblock time value
*
* @return None
*
* @note None
*/
void tls_set_rtc(struct tm *tblock);
/**
* @brief This function is used to get pmu rtc time
*
* @param[out] tblock time value
*
* @return None
*
* @note None
*/
void tls_get_rtc(struct tm *tblock);
/**
* @brief This function is used to register pmu rtc interrupt
*
* @param[in] callback the rtc interrupt call back function
* @param[in] arg parameter of call back function
*
* @return None
*
* @note
* User does not need to clear the interrupt flag.
* Rtc callback function is called in interrupt,
* so do not operate the critical data in the callback fuuction.
* Sending messages to other tasks to handle is recommended.
*/
void tls_rtc_isr_register(tls_rtc_irq_callback callback, void *arg);
/**
* @brief This function is used to start pmu rtc timer
*
* @param[in] tblock timer value
*
* @return None
*
* @note None
*/
void tls_rtc_timer_start(struct tm *tblock);
/**
* @brief This function is used to stop pmu rtc timer
*
* @param None
*
* @return None
*
* @note This function also is used to clear rtc timer interrupt
*/
void tls_rtc_timer_stop(void);
/**
* @}
*/
/**
* @}
*/
#endif

150
include/driver/wm_sasc.h Normal file
View File

@ -0,0 +1,150 @@
#ifndef __WM_SASC_H_
#define __WM_SASC_H_
#include <core_804.h>
#include "wm_regs.h"
#define HR_SASC_B1_BASE (DEVICE_BASE_ADDR + 0xB000)
#define HR_SASC_FLASH_BASE (DEVICE_BASE_ADDR + 0xB100)
#define HR_SASC_B2_BASE (DEVICE_BASE_ADDR + 0xB200)
#define _R1_Pos(val, rgn) ((val&0x1) << (rgn))
#define _R1_Msk(rgn) (0x1 << (rgn))
#define _R2_Pos(val, rgn) ((val&0x3) << (2*rgn))
#define _R2_Msk(rgn) (0x3 << (2*rgn))
typedef enum {
SASC_UN_SE_USER = 0,
SASC_UN_SE_SUPER,
SASC_SE_USER,
SASC_SE_SUPER
} sasc_car_e;
typedef enum {
SASC_AP_RW = 0,
SASC_AP_RO,
SASC_AP_WO,
SASC_AP_DENYALL
} sasc_ap_e;
typedef enum {
SASC_CD_DA_OF = 0,
SASC_CD_DA,
SASC_CD_OF,
SASC_CD_DENYALL
} sasc_cd_e;
typedef enum {
SASC_REGION_SIZE_4B = 0x5,
SASC_REGION_SIZE_8B,
SASC_REGION_SIZE_16B,
SASC_REGION_SIZE_32B,
SASC_REGION_SIZE_64B,
SASC_REGION_SIZE_128B,
SASC_REGION_SIZE_256B,
SASC_REGION_SIZE_512B,
SASC_REGION_SIZE_1KB,
SASC_REGION_SIZE_2KB,
SASC_REGION_SIZE_4KB,
SASC_REGION_SIZE_8KB,
SASC_REGION_SIZE_16KB,
SASC_REGION_SIZE_32KB,
SASC_REGION_SIZE_64KB,
SASC_REGION_SIZE_128KB,
SASC_REGION_SIZE_256KB,
SASC_REGION_SIZE_512KB,
SASC_REGION_SIZE_1MB,
SASC_REGION_SIZE_2MB,
SASC_REGION_SIZE_4MB,
SASC_REGION_SIZE_8MB
} sasc_region_size_e;
typedef struct {
sasc_car_e car; /* security and user or super */
sasc_ap_e ap; /* super user and normal user access.*/
sasc_cd_e cd; /* instruction fetched excution */
} sasc_region_attr_t;
typedef struct {
__IOM uint32_t CAR;
__IOM uint32_t CR;
__IOM uint32_t AP0;
__IOM uint32_t CD0;
__IOM uint32_t AP1;
__IOM uint32_t CD1;
__IOM uint32_t AP2;
__IOM uint32_t CD2;
__IOM uint32_t REGION[8];
} SASC_Type;
#define SASC_B1 ((SASC_Type *) HR_SASC_B1_BASE)
#define SASC_FLASH ((SASC_Type *) HR_SASC_FLASH_BASE)
#define SASC_B2 ((SASC_Type *) HR_SASC_B2_BASE)
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup SASC_Driver_APIs SASC Driver APIs
* @brief SASC driver APIs
*/
/**
* @addtogroup SASC_Driver_APIs
* @{
*/
/**
* @brief This function is used enable region.
*
* @param[in] block sasc type
* @param[in] idx index
*
* @return None
*
* @note None
*/
void wm_sasc_enable_region(SASC_Type *block, uint32_t idx);
/**
* @brief This function is used disable region.
*
* @param[in] block sasc type
* @param[in] idx index
*
* @return None
*
* @note None
*/
void wm_sasc_disable_region(SASC_Type *block, uint32_t idx);
/**
* @brief This function is used set region protect.
*
* @param[in] base_addr base address
* @param[in] idx index
* @param[in] size size
* @param[in] attr attribute
*
* @return None
*
* @note None
*/
void set_region_protect(uint32_t base_addr, uint32_t idx, sasc_region_size_e size, sasc_region_attr_t *attr);
/**
* @}
*/
/**
* @}
*/
#endif

View File

@ -0,0 +1,142 @@
#ifndef __WM_SDIO_HOST_H_
#define __WM_SDIO_HOST_H_
#include <core_804.h>
#include "wm_regs.h"
typedef struct {
__IOM uint32_t MMC_CTL;
__IOM uint32_t MMC_IO;
__IOM uint32_t MMC_BYTECNTL;
__IM uint32_t MMC_TR_BLOCKCNT;
__IOM uint32_t MMC_CRCCTL; /*!< Offset: 0x010 */
__IM uint32_t CMD_CRC;
__IM uint32_t DAT_CRCL;
__IM uint32_t DAT_CRCH;
__IOM uint32_t MMC_PORT; /*!< Offset: 0x020 */
__IOM uint32_t MMC_INT_MASK;
__IOM uint32_t MMC_INT_SRC;
__IOM uint32_t MMC_CARDSEL;
__IM uint32_t MMC_SIG; /*!< Offset: 0x030 */
__IOM uint32_t MMC_IO_MBCTL;
__IOM uint32_t MMC_BLOCKCNT;
__IOM uint32_t MMC_TIMEOUTCNT;
__IOM uint32_t CMD_BUF[16]; /*!< Offset: 0x040 */
__IOM uint32_t BUF_CTL; /*!< Offset: 0x080 */
uint32_t RESERVED3[31U];
__IOM uint32_t DATA_BUF[128]; /*!< Offset: 0x100 */
}SDIO_HOST_Type;
#define SDIO_HOST ((SDIO_HOST_Type *)HR_SDIO_HOST_BASE_ADDR)
typedef struct
{
long long CardCapacity;
u32 CardBlockSize;
u16 RCA;
u8 CardType;
} SD_CardInfo_t;
extern SD_CardInfo_t SDCardInfo;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup SDIOH_Driver_APIs SDIO HOST Driver APIs
* @brief SDIO HOST driver APIs
*/
/**
* @addtogroup SDIOH_Driver_APIs
* @{
*/
/**
* @brief This function is used to initial the sd host module .
*
* @param[out] rca_ref Pointer to the rca reference
*
* @retval status 0 if succeed, otherwise fail
*
* @note None
*/
int sdh_card_init(uint32_t *rca_ref);
/**
* @brief This function is used to set the width of bus .
*
* @param[in] rca the rca reference
* @param[in] bus_width: 0:1bit; 2:4bits
*
* @retval status 0 if succeed, otherwise fail
*
* @note None
*/
int wm_sd_card_set_bus_width(uint32_t rca, uint8_t bus_width);
/**
* @brief This function is used to read one block data from the sd card with irq mode .
*
* @param[in] sd_addr address that to be read from
* @param[in] buf Pointer to the buffer that the data shall be read into
*
* @retval status 0 if succeed, otherwise fail
*
* @note None
*/
int wm_sd_card_block_read(uint32_t rca, uint32_t sd_addr, char *buf);
/**
* @brief This function is used to write one block data into the sd card with irq mode .
*
* @param[in] sd_addr address that to be written to
* @param[in] buf Pointer to the buffer that holding the data to be written
*
* @retval status 0 if succeed, otherwise fail
*
* @note None
*/
int wm_sd_card_block_write(uint32_t rca, uint32_t sd_addr, char *buf);
/**
* @brief This function is used to read blocks of data from the sd card with dma mode .
*
* @param[in] sd_addr address that to be read from
* @param[in] buf Pointer to the buffer that the data shall be read into
* @param[in] buflen buffer size, should be integer multiple of 512
*
* @retval status 0 if succeed, otherwise fail
*
* @note None
*/
int wm_sd_card_blocks_read(uint32_t rca, uint32_t sd_addr, char *buf, uint32_t buflen);
/**
* @brief This function is used to write blocks of data into the sd card with dma mode .
*
* @param[in] sd_addr address that to be written to
* @param[in] buf Pointer to the buffer that holding the data to be written
* @param[in] buflen buffer size, should be integer multiple of 512
*
* @retval status 0 if succeed, otherwise fail
*
* @note None
*/
int wm_sd_card_blocks_write(uint32_t rca, uint32_t sd_addr, char *buf, uint32_t buflen);
/**
* @}
*/
/**
* @}
*/
#endif //__WM_SDIO_HOST_H_

137
include/driver/wm_timer.h Normal file
View File

@ -0,0 +1,137 @@
/**
* @file wm_timer.h
*
* @brief Timer Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_TIMER_H
#define WM_TIMER_H
#include "wm_type_def.h"
/** invalid timer id */
#define WM_TIMER_ID_INVALID 0xFF
/** timer interrupt callback */
typedef void (*tls_timer_irq_callback)(void *arg);
/** timer unit */
enum tls_timer_unit{
TLS_TIMER_UNIT_US = 0, /**< microsecond level(us) */
TLS_TIMER_UNIT_MS /**< millisecond level(ms) */
};
/** timer configuration */
struct tls_timer_cfg {
enum tls_timer_unit unit; /**< timer accuracy */
u32 timeout; /**< timeout period */
bool is_repeat; /**< cycle timer */
tls_timer_irq_callback callback; /**< timeout callback function */
void *arg; /**< parameter fot the timeout callback function */
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup TIMER_Driver_APIs TIMER Driver APIs
* @brief TIMER driver APIs
*/
/**
* @addtogroup TIMER_Driver_APIs
* @{
*/
/**
* @brief This function is used to create a timer
*
* @param[in] cfg timer configuration
*
* @retval WM_TIMER_ID_INVALID failed
* @retval other timer id
*
* @note
* User does not need to clear the interrupt flag.
* Rtc callback function is called in interrupt,
* so do not operate the critical data in the callback fuuction.
* Sending messages to other tasks to handle is recommended.
*/
u8 tls_timer_create(struct tls_timer_cfg *cfg);
/**
* @brief This function is used to start a timer
*
* @param[in] timer_id timer id
*
* @return None
*
* @note None
*/
void tls_timer_start(u8 timer_id);
/**
* @brief This function is used to stop a timer
*
* @param[in] timer_id timer id
*
* @return None
*
* @note None
*/
void tls_timer_stop(u8 timer_id);
/**
* @brief This function is used to change a timer wait time
*
* @param[in] timer_id timer id[0~5]
*
* @param[in] newtime new wait time
*
* @retval None
*
* @note If the timer does not start, this function will start the timer
*/
void tls_timer_change(u8 timer_id, u32 newtime);
/**
* @brief This function is used to read a timer's current value
*
* @param[in] timer_id timer id[0~5]
*
* @retval timer's current value
*
* @note none
*/
u32 tls_timer_read(u8 timer_id);
/**
* @brief This function is used to delete a timer
*
* @param[in] timer_id timer id
*
* @return None
*
* @note None
*/
void tls_timer_destroy(u8 timer_id);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_TIMER_H */

1284
include/driver/wm_tipc.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,107 @@
/**
* @file wm_touchsensor.h
*
* @brief touchsensor Driver Module
*
* @author
*
* Copyright (c) 2021 Winner Microelectronics Co., Ltd.
*/
#include "wm_type_def.h"
/**
* @brief This function is used to initialize touch sensor.
*
* @param[in] sensorno is the touch sensor number from 1-15
* @param[in] scan_period is scan period for per touch sensor ,unit:16ms, >0
* @param[in] window is count window, window must be greater than 2.Real count window is window - 2.
* @param[in] enable is touch sensor enable bit.
*
* @retval 0:success
*
* @note if use touch sensor, user must configure the IO multiplex by API wm_touch_sensor_config.
*/
int tls_touchsensor_init_config(u32 sensorno, u8 scan_period, u8 window, u32 enable);
/**
* @brief This function is used to deinit touch sensor's selection and disable touch.
*
* @param[in] sensorno is the touch sensor number from 1-15
*
* @retval 0:success
*
* @note if do not use touch sensor, user can deinit by this interface and configure this touch sensor as GPIO.
*/
int tls_touchsensor_deinit(u32 sensorno);
/**
* @brief This function is used to set threshold per touch sensor.
*
* @param[in] sensorno is the touch sensor number from 1-15
* @param[in] threshold is the sensorno's touch sensor threshold,max value is 127.
*
* @retval 0:success. minus value: parameter wrong.
*
* @note None
*/
int tls_touchsensor_threshold_config(u32 sensorno, u8 threshold);
/**
* @brief This function is used to get touch sensor's count number.
*
* @param[in] sensorno is the touch sensor number from 1 to 15.
*
* @retval sensorno's count number .
*
* @note None
*/
int tls_touchsensor_countnum_get(u32 sensorno);
/**
* @brief This function is used to enable touch sensor's irq.
*
* @param[in] sensorno is the touch sensor number from 1 to 15.
*
* @retval 0:successfully enable irq, -1:parameter wrong.
*
* @note None
*/
int tls_touchsensor_irq_enable(u32 sensorno);
/**
* @brief This function is used to disable touch sensor's irq.
*
* @param[in] sensorno is the touch sensor number from 1 to 15.
*
* @retval 0:successfully disable irq, -1:parameter wrong.
*
* @note None
*/
int tls_touchsensor_irq_disable(u32 sensorno);
/**
* @brief This function is used to register touch sensor's irq callback.
*
* @param[in] callback is call back for user's application.
*
* @retval None.
*
* @note None
*/
void tls_touchsensor_irq_register(void (*callback)(u32 status));
/**
* @brief This function is used to get touch sensor's irq status.
*
* @param[in] sensorno is the touch sensor number from 1 to 15.
*
* @retval >=0:irq status, -1:parameter wrong.
*
* @note None
*/
int tls_touchsensor_irq_status_get(u32 sensorno);

529
include/driver/wm_uart.h Normal file
View File

@ -0,0 +1,529 @@
/**
* @file wm_uart.h
*
* @brief uart Driver Module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_UART_H
#define WM_UART_H
#include "list.h"
//#include "wm_regs.h"
#include "wm_type_def.h"
#include "wm_osal.h"
#define TLS_UART_RX_BUF_SIZE 4096
#define TLS_UART_TX_BUF_SIZE 4096
#define WAKEUP_CHARS 256
#define MBOX_MSG_UART_RX 1
#define MBOX_MSG_UART_TX 2
/** baud rate definition */
#define UART_BAUDRATE_B600 600
#define UART_BAUDRATE_B1200 1200
#define UART_BAUDRATE_B1800 1800
#define UART_BAUDRATE_B2400 2400
#define UART_BAUDRATE_B4800 4800
#define UART_BAUDRATE_B9600 9600
#define UART_BAUDRATE_B19200 19200
#define UART_BAUDRATE_B38400 38400
#define UART_BAUDRATE_B57600 57600
#define UART_BAUDRATE_B115200 115200
#define UART_BAUDRATE_B230400 230400
#define UART_BAUDRATE_B460800 460800
#define UART_BAUDRATE_B921600 921600
#define UART_BAUDRATE_B1000000 1000000
#define UART_BAUDRATE_B1250000 1250000
#define UART_BAUDRATE_B1500000 1500000
#define UART_BAUDRATE_B2000000 2000000
#define UART_RX_INT_FLAG (UIS_RX_FIFO | UIS_RX_FIFO_TIMEOUT | UIS_BREAK |\
UIS_OVERRUN | UIS_FRM_ERR | UIS_PARITY_ERR)
#define UART_RX_ERR_INT_FLAG (UIS_BREAK | UIS_FRM_ERR | \
UIS_PARITY_ERR)
#define UART_TX_INT_FLAG (UIS_TX_FIFO | UIS_TX_FIFO_EMPTY)
/** return count in buffer. */
#define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size)-1))
/** Return space available, 0..size-1. We always leave one free char
as a completely full buffer has head == tail, which is the same as
empty. */
#define CIRC_SPACE(head,tail,size) CIRC_CNT((tail),((head)+1),(size))
/** Return count up to the end of the buffer. Carefully avoid
accessing head and tail more than once, so they can change
underneath us without returning inconsistent results. */
#define CIRC_CNT_TO_END(head,tail,size) \
({int end = (size) - (tail); \
int n = ((head) + end) & ((size)-1); \
n < end ? n : end;})
/** Return space available up to the end of the buffer. */
#define CIRC_SPACE_TO_END(head,tail,size) \
({int end = (size) - 1 - (head); \
int n = (end + (tail)) & ((size)-1); \
n <= end ? n : end+1;})
#define CIRC_SPACE_TO_END_FULL(head,tail,size) \
({int end = (size) - 1 - (head); \
int n = (end + (tail)) & ((size)-1); \
n < end ? n : end+1;})
#define uart_circ_empty(circ) ((circ)->head == (circ)->tail)
#define uart_circ_chars_pending(circ) \
(CIRC_CNT((circ)->head, (circ)->tail, TLS_UART_TX_BUF_SIZE))
/**
* @struct tls_uart_baud_rate baudrate define
*/
struct tls_uart_baud_rate
{
u32 baud_rate;
u16 ubdiv;
u16 ubdiv_frac;
};
/**
* @enum uart number enum
*/
enum
{
TLS_UART_0 = 0,
TLS_UART_1 = 1,
TLS_UART_2 = 2,
TLS_UART_3 = 3,
TLS_UART_4 = 4,
TLS_UART_5 = 5,
TLS_UART_MAX = 6,
};
/**
* @typedef enum TLS_UART_PMODE Parity Mode
*/
typedef enum TLS_UART_PMODE
{
TLS_UART_PMODE_DISABLED = 0, /**< No Parity */
TLS_UART_PMODE_ODD = 1, /**< Odd Parity */
TLS_UART_PMODE_EVEN = 2, /**< Even Parity */
TLS_UART_PMODE_MARK = 3, /**< The parity bit is always 1. */
TLS_UART_PMODE_SPACE = 4, /**< The parity bit is always 0. */
} TLS_UART_PMODE_T;
/**
* @typedef enum TLS_UART_CHSIZE Character Size
*/
typedef enum TLS_UART_CHSIZE
{
TLS_UART_CHSIZE_5BIT = (0x00 << 0), /**< Character size: 5 bit */
TLS_UART_CHSIZE_6BIT = (0x01 << 0), /**< Character size: 6 bit */
TLS_UART_CHSIZE_7BIT = (0x02 << 0), /**< Character size: 7 bit */
TLS_UART_CHSIZE_8BIT = (0x03 << 0), /**< Character size: 8 bit */
} TLS_UART_CHSIZE_T;
/**
* @typedef enum TLS_UART_FLOW_CTRL_MODE flow control mode
*/
typedef enum TLS_UART_FLOW_CTRL_MODE
{
TLS_UART_FLOW_CTRL_NONE,
TLS_UART_FLOW_CTRL_HARDWARE,
} TLS_UART_FLOW_CTRL_MODE_T;
/**
* @typedef enum TLS_UART_RX_FLOW_CTRL_FLAG flow control rx flag
*/
typedef enum TLS_UART_RX_FLOW_CTRL_FLAG
{
TLS_UART_RX_DISABLE,
TLS_UART_RX_ENABLE,
} TLS_UART_RX_FLOW_CTRL_FLAG_T;
/**
* @typedef enum TLS_UART_STOPBITS
*/
typedef enum TLS_UART_STOPBITS
{
TLS_UART_ONE_STOPBITS,
TLS_UART_TWO_STOPBITS,
} TLS_UART_STOPBITS_T;
/**
* @typedef enum TLS_UART_STATUS
*/
typedef enum TLS_UART_STATUS
{
TLS_UART_STATUS_OK,
TLS_UART_STATUS_ERROR,
} TLS_UART_STATUS_T;
/**
* @typedef enum TLS_UART_MODE operation mode
*/
typedef enum TLS_UART_MODE
{
TLS_UART_MODE_POLL, /**< uart operation mode: poll */
TLS_UART_MODE_INT, /**< uart operation mode: interrupt mode */
} TLS_UART_MODE_T;
/**
* @struct tls_uart_icount
*/
struct tls_uart_icount
{
u32 cts;
u32 dsr;
u32 rng;
u32 dcd;
u32 rx;
u32 tx;
u32 frame;
u32 overrun;
u32 parity;
u32 brk;
u32 buf_overrun;
};
/**
* @typedef struct tls_uart_options
*/
typedef struct tls_uart_options
{
u32 baudrate; /**< Set baud rate of the UART */
TLS_UART_CHSIZE_T charlength; /**< Number of bits to transmit as a character (5 to 8). */
TLS_UART_PMODE_T paritytype; /**< Parity type */
TLS_UART_FLOW_CTRL_MODE_T flow_ctrl; /**< Flow control type */
TLS_UART_STOPBITS_T stopbits; /**< Number of stop bits */
} tls_uart_options_t;
/**
* @typedef struct tls_uart_circ_buf
*/
typedef struct tls_uart_circ_buf
{
volatile u8 *buf;
volatile u32 head;
volatile u32 tail;
} tls_uart_circ_buf_t;
#if TLS_CONFIG_CMD_NET_USE_LIST_FTR
/**
* @typedef struct tls_uart_net_buf
*/
typedef struct tls_uart_net_buf
{
struct dl_list list;
char *buf;
void *pbuf;
u16 buflen;
u16 offset;
} tls_uart_net_buf_t;
typedef struct tls_uart_net_msg
{
struct dl_list tx_msg_pending_list;
} tls_uart_net_msg_t;
#endif
/**
* @typedef struct TLS_UART_REGS
*/
typedef struct TLS_UART_REGS
{
u32 UR_LC; /**< line control register */
u32 UR_FC; /**< flow control register */
u32 UR_DMAC; /**< dma control register */
u32 UR_FIFOC; /**< fifo control register */
u32 UR_BD; /**< baud rate register */
u32 UR_INTM; /**< interrupt mask register */
u32 UR_INTS; /**< interrupt source register */
u32 UR_FIFOS; /**< fifo status register */
u32 UR_TXW; /**< tx windows register */
u32 UR_RES0;
u32 UR_RES1;
u32 UR_RES2;
u32 UR_RXW; /**< rx windows register */
} TLS_UART_REGS_T;
/**
* @typedef struct tls_uart_port
*/
typedef struct tls_uart_port
{
u32 uart_no; /**< uart number: 0 or 1 */
u32 uart_irq_no; /**< uart interrupt number */
u32 plus_char_cnt;
TLS_UART_MODE_T uart_mode; /**< uart work mode: interrupt mode or poll mode */
struct tls_uart_options opts; /**< uart config parameters */
int fcStatus; /**< flow ctrl status,0 closed ,1 opened */
enum TLS_UART_RX_FLOW_CTRL_FLAG rxstatus;
u32 tx_fifofull; /**< uart tx fifo trigger level */
TLS_UART_REGS_T volatile *regs; /**< uart registers struct pointer */
struct tls_uart_icount icount; /**< uart statistics information */
struct tls_uart_circ_buf recv; /**< uart ring buffer */
// struct tls_uart_circ_buf xmit;
struct dl_list tx_msg_pending_list;
struct dl_list tx_msg_to_be_freed_list;
u8 hw_stopped;
tls_os_sem_t *tx_sem;
char *buf_ptr;
u16 buf_len;
s16(*rx_callback) (u16 len, void* priv_data);
s16(*tx_callback) (struct tls_uart_port * port);
s16(*tx_sent_callback) (struct tls_uart_port * port);
bool tx_dma_on;
bool rx_dma_on;
void *priv_data;
} tls_uart_port_t;
/**
* @typedef struct tls_uart_tx_msg
*/
typedef struct tls_uart_tx_msg
{
struct dl_list list;
char *buf;
u16 buflen;
u16 offset;
void (*finish_callback) (void *arg);
void *callback_arg;
} tls_uart_tx_msg_t;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup UART_Driver_APIs UART Driver APIs
* @brief UART driver APIs
*/
/**
* @addtogroup UART_Driver_APIs
* @{
*/
/**
* @brief This function is used to initial uart port.
*
* @param[in] uart_no: is the uart number.
* - \ref TLS_UART_0 TLS_UART_1 TLS_UART_2 TLS_UART_3 TLS_UART_4 TLS_UART_5
* @param[in] opts: is the uart setting options,if this param is NULL,this function will use the default options.
* @param[in] modeChoose:; choose uart2 mode or 7816 mode when uart_no is TLS_UART_2, 0 for uart2 mode and 1 for 7816 mode.
*
* @retval
* - \ref WM_SUCCESS
* - \ref WM_FAILED
*
* @note When the system is initialized, the function has been called, so users can not call the function.
*/
int tls_uart_port_init(u16 uart_no, tls_uart_options_t * opts, u8 modeChoose);
/**
* @brief This function is used to register uart rx interrupt.
*
* @param[in] uart_no TLS_UART_0 or TLS_UART_1
* @param[in] rx_callback is the uart rx interrupt call back function.
*
* @return None
*
* @note None
*/
void tls_uart_rx_callback_register(u16 uart_no, s16(*rx_callback) (u16 len, void* user_data), void* user_data);
void tls_uart_rx_byte_callback_flag(u16 uart_no, u8 flag);
/**
* @brief This function is used to register uart tx interrupt.
*
* @param[in] uart_no: is the uart numer.
* @param[in] callback: is the uart tx interrupt call back function.
*
* @retval
*/
void tls_uart_tx_callback_register(u16 uart_no, s16(*tx_callback) (struct tls_uart_port *port));
/**
* @brief This function is used to copy circular buffer data to user buffer.
*
* @param[in] uart_no is the uart numer
* @param[in] buf is the user buffer
* @param[in] readsize is the user read size
*
* @retval copy data size
*
* @note None
*/
int tls_uart_read(u16 uart_no, u8 * buf, u16 readsize);
/**
* @brief This function is used to check the available data in the cache buffer.
*
* @param[in] uart_no is the uart numer
* @param[in] readsize is the user read size
*
* @retval if the cache buffer size is greater or equals to readsize , then return readsize; otherwise return 0;
*
* @note None
*/
int tls_uart_try_read(u16 uart_no, int32_t read_size);
/**
* @brief This function is used to transfer data synchronously.
*
* @param[in] uart_no is the uart number
* @param[in] buf is a buf for saving user data
* @param[in] writesize is the user data length
*
* @retval WM_SUCCESS tx success
* @retval WM_FAILED tx failed
*
* @note None
*/
int tls_uart_write(u16 uart_no, char *buf, u16 writesize);
/**
* @brief This function is used to transfer data with DMA.
*
* @param[in] buf is a buf for saving user data
* @param[in] writesize is the user data length
* @param[in] cmpl_callback function point,when the transfer is completed, the function will be called.
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note Only uart1 support DMA transfer.
*/
int tls_uart_dma_write(char *buf, u16 writesize, void (*cmpl_callback) (void *p), u16 uart_no);
/**
* @brief This function is used to set uart parity.
*
* @param[in] uart_no is the uart number
* @param[in] paritytype is a parity type defined in TLS_UART_PMODE_T
*
* @retval WM_SUCCESS if setting success
* @retval WM_FAILED if setting fail
*
* @note None
*/
int tls_uart_set_parity(u16 uart_no, TLS_UART_PMODE_T paritytype);
/**
* @brief This function is used to set uart baudrate.
*
* @param[in] uart_no is the uart number
* @param[in] baudrate is the baudrate user want used,the unit is HZ.
*
* @retval WM_SUCCESS if setting success
* @retval WM_FAILED if setting fail
*
* @note None
*/
int tls_uart_set_baud_rate(u16 uart_no, u32 baudrate);
/**
* @brief This function is used to set uart stop bits.
*
* @param[in] uart_no is the uart number
* @param[in] stopbits is a stop bit type defined in TLS_UART_STOPBITS_T
*
* @retval WM_SUCCESS if setting success
* @retval WM_FAILED if setting fail
*
* @note None
*/
int tls_uart_set_stop_bits(u16 uart_no, TLS_UART_STOPBITS_T stopbits);
/**
* @}
*/
/**
* @}
*/
void tls_uart_push(int uart_no, u8* data, int length);
/**
* @brief This function is used to transfer data asynchronously.
*
* @param[in] uart_no is the uart number
* @param[in] buf is a buf for saving user data
* @param[in] writesize is the user data length
*
* @retval WM_SUCCESS tx success
* @retval WM_FAILED tx failed
*
* @note None
*/
int tls_uart_write_async(u16 uart_no, char *buf, u16 writesize);
/**
* @brief This function is used to register uart tx sent callback function.
*
* @param[in] uart_no: is the uart numer.
* @param[in] callback: is the uart tx sent out call back function.
*
* @retval
*/
void tls_uart_tx_sent_callback_register(u16 uart_no, s16(*tx_callback) (struct tls_uart_port *port));
#endif /* WM_UART_H */

View File

@ -0,0 +1,86 @@
/**
* @file wm_watchdog.h
*
* @brief watchdog Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_WATCHDOG_H
#define WM_WATCHDOG_H
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup WDG_Driver_APIs WDG Driver APIs
* @brief WDG driver APIs
*/
/**
* @addtogroup WDG_Driver_APIs
* @{
*/
/**
* @brief This function is used to feed the dog.
*
* @param None
*
* @return None
*
* @note None
*/
void tls_watchdog_clr(void);
/**
* @brief This function is used to init and start the watchdog.
*
* @param[in] usec microseconds
*
* @return None
*
* @note None
*/
void tls_watchdog_init(u32 usec);
/**
* @brief This function is used to deinit watchdog
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_watchdog_deinit(void);
/**
* @brief This function is used to reset the system.
*
* @param None
*
* @return None
*
* @note None
*/
void tls_sys_reset(void);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_WATCHDOG_H */

317
include/list.h Normal file
View File

@ -0,0 +1,317 @@
/*
* @file list.h
* @brief Doubly-linked list
* @copyright (c) 2009, Jouni Malinen <j@w1.fi>
*
* @note This program 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.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*/
#ifndef LIST_H
#define LIST_H
#include <stdio.h>
/** struct dl_list - Doubly-linked list */
struct dl_list {
struct dl_list *next; /**< pointer to the next */
struct dl_list *prev; /**< pointer to the previous */
};
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup DLIST_APIs DLIST APIs
* @brief Double listed APIs
*/
/**
* @addtogroup DLIST_APIs
* @{
*/
/**
* @brief reinitialize the list
*
* @param[in] *list the list
*
* @return None
*
* @note None
*/
static __inline void dl_list_init(struct dl_list *list)
{
list->next = list;
list->prev = list;
}
/**
* @brief Insert a new entry after the specified head
*
* @param[in] *list list head to add it after
* @param[in] *item new entry to be added
*
* @return None
*
* @note None
*/
static __inline void dl_list_add(struct dl_list *list, struct dl_list *item)
{
item->next = list->next;
item->prev = list;
list->next->prev = item;
list->next = item;
}
/**
* @brief Insert a new entry before the specified head
*
* @param[in] *list list head to add it after
* @param[in] *item new entry to be added
*
* @return None
*
* @note None
*/
static __inline void dl_list_add_tail(struct dl_list *list, struct dl_list *item)
{
dl_list_add(list->prev, item);
}
/**
* @brief deletes entry from list
*
* @param[in] *item the element to delete from the list
*
* @return None
*
* @note None
*/
static __inline void dl_list_del(struct dl_list *item)
{
item->next->prev = item->prev;
item->prev->next = item->next;
item->next = NULL;
item->prev = NULL;
}
/**
* @brief tests whether a list is empty
*
* @param[in] *list the list to test
*
* @retval 0 not empty
* @retval 1 empty
*
* @note None
*/
static __inline int dl_list_empty(struct dl_list *list)
{
return list->next == list;
}
/**
* @brief count length of the list
*
* @param[in] *list the list to count
*
* @return length
*
* @note None
*/
static __inline unsigned int dl_list_len(struct dl_list *list)
{
struct dl_list *item;
int count = 0;
for (item = list->next; item != list; item = item->next)
count++;
return count;
}
/**
* @}
*/
/**
* @}
*/
#ifndef offsetof
/** offset address of the struct member */
#define offsetof(type, member) ((long) &((type *) 0)->member)
#endif
/**
* @brief get the struct for this entry
*
* @param[in] item the &struct list_head pointer
* @param[in] type the type of the struct this is embedded in
* @param[in] member the name of the list_struct within the struct
*
* @return pointer to the struct for this entry
*
* @note None
*/
#define dl_list_entry(item, type, member) \
((type *) ((char *) item - offsetof(type, member)))
/**
* @brief get the first element from a list
*
* @param[in] list 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 list_struct within the struct
*
* @return pointer to the first element from a list
*
* @note None
*/
#define dl_list_first(list, type, member) \
(dl_list_empty((list)) ? NULL : \
dl_list_entry((list)->next, type, member))
/**
* @brief get the last element from a list
*
* @param[in] list 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 list_struct within the struct
*
* @return pointer to the last element from a list
*
* @note None
*/
#define dl_list_last(list, type, member) \
(dl_list_empty((list)) ? NULL : \
dl_list_entry((list)->prev, type, member))
/**
* @brief iterate over list of given type
*
* @param[in] item a loop cursor
* @param[in] list the head for your list
* @param[in] type struct type
* @param[in] member the name of the list_struct within the struct
*
* @return None
*
* @note None
*/
#define dl_list_for_each(item, list, type, member) \
for (item = dl_list_entry((list)->next, type, member); \
&item->member != (list); \
item = dl_list_entry(item->member.next, type, member))
/**
* @brief iterate over list of given type safe against removal of list entry
*
* @param[in] item a loop cursor
* @param[in] n temporary storage
* @param[in] list the head for your list
* @param[in] type struct type
* @param[in] member the name of the list_struct within the struct
*
* @return None
*
* @note None
*/
#define dl_list_for_each_safe(item, n, list, type, member) \
for (item = dl_list_entry((list)->next, type, member), \
n = dl_list_entry(item->member.next, type, member); \
&item->member != (list); \
item = n, n = dl_list_entry(n->member.next, type, member))
/**
* @brief iterate backwards over list of given type
*
* @param[in] item a loop cursor
* @param[in] list the head for your list
* @param[in] type struct type
* @param[in] member the name of the list_struct within the struct
*
* @return None
*
* @note None
*/
#define dl_list_for_each_reverse(item, list, type, member) \
for (item = dl_list_entry((list)->prev, type, member); \
&item->member != (list); \
item = dl_list_entry(item->member.prev, type, member))
/** define the list head */
#define DEFINE_DL_LIST(name) \
struct dl_list name = { &(name), &(name) }
/**
* @brief iterate over list of given type
*
* @param[in] item the type * to use as a loop cursor
* @param[in] list the head for your list
* @param[in] member the name of the list_struct within the struct
*
* @return None
*
* @note None
*/
#define __dl_list_for_each(item, list, member) \
for (item = dl_list_entry((list)->next, typeof(*(item)), member); \
&item->member != (list); \
item = dl_list_entry(item->member.next, typeof(*(item)), member))
/**
* @brief iterate over list of given type safe against removal of list entry
*
* @param[in] item the type * to use as a loop cursor
* @param[in] n temporary storage
* @param[in] list the head for your list
* @param[in] member the name of the list_struct within the struct
*
* @return None
*
* @note None
*/
#define __dl_list_for_each_safe(item, n, list, member) \
for (item = dl_list_entry((list)->next, typeof(*(item)), member), \
n = dl_list_entry(item->member.next, typeof(*(item)), member); \
&item->member != (list); \
item = n, n = dl_list_entry(n->member.next, typeof(*(item)), member))
/**
* @brief iterate backwards over list of given type
*
* @param[in] item the type * to use as a loop cursor
* @param[in] list the head for your list
* @param[in] member the name of the list_struct within the struct
*
* @return None
*
* @note None
*/
#define __dl_list_for_each_reverse(item, list, member) \
for (item = dl_list_entry((list)->prev, typeof(*(item)), member); \
&item->member != (list); \
item = dl_list_entry(item->member.prev, typeof(*(item)), member))
/**
* @}
*/
/**
* @}
*/
#endif /* LIST_H */

17
include/net/wm_socket.h Normal file
View File

@ -0,0 +1,17 @@
/**
* @file wm_socket.h
*
* @brief socket Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_SOCKET_H
#define WM_SOCKET_H
#include "wm_config.h"
#include "wm_socket2.0.3.h"
#endif

View File

@ -0,0 +1,422 @@
/**
* @file wm_socket2.0.3.h
*
* @brief socket203 Module
*
* @author dave
*
* @copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_SOCKET2_0_3_H
#define WM_SOCKET2_0_3_H
#include "wm_type_def.h"
#include "wm_netif.h"
//socket state defination
#define NETCONN_STATE_NONE 0
#define NETCONN_STATE_WAITING 1
#define NETCONN_STATE_CONNECTED 2
#define NETCONN_STATE_CLOSED 3
//socket event defination
#define NET_EVENT_TCP_JOINED 0
#define NET_EVENT_TCP_DISCONNECT 1
#define NET_EVENT_TCP_CONNECTED 2
#define NET_EVENT_TCP_CONNECT_FAILED 3
#define NET_EVENT_UDP_START 4
#define NET_EVENT_UDP_START_FAILED 5
#define TLS_MAX_SOCKET_NUM 4
#define TLS_MAX_NETCONN_NUM 20
/** Main packet buffer struct */
struct pbuf {
/** next pbuf in singly linked pbuf chain */
struct pbuf *next;
/** pointer to the actual data in the buffer */
void *payload;
/**
* total length of this buffer and all next buffers in chain
* belonging to the same packet.
*
* For non-queue packet chains this is the invariant:
* p->tot_len == p->len + (p->next? p->next->tot_len: 0)
*/
u16_t tot_len;
/** length of this buffer */
u16_t len;
/** pbuf_type as u8_t instead of enum to save space */
u8_t /*pbuf_type*/ type;
/** misc flags */
u8_t flags;
/**
* the reference count always equals the number of pointers
* that refer to this pbuf. This can be pointers from an application,
* the stack itself, or pbuf->next pointers from a chain.
*/
u16_t ref;
};
/**
* @brief This Function prototype for tcp error callback functions. Called when
* receives a RST or is unexpectedly closed for any other reason.
* The corresponding socket is already freed when this callback is called!
*
* @param[in] skt_num Is the socket number that returned by tls_socket_create function.
*
* @param[in] err Error code to indicate why the socket has been closed
* ERR_ABRT: aborted through returning ERR_ABRT from within others
* callback functions
* ERR_RST: the connection was reset by the remote host
*/
typedef void (*socket_err_fn)(u8 skt_num, err_t err);
/**
* @brief This Function prototype for socket receive callback functions. Called when data has
* been received.
*
* @param[in] skt_num Is the socket number that returned by tls_socket_create function.
*
* @param[in] p The received data (or NULL when the connection has been closed!)
*
* @param[in] err An error code if there has been an error receiving, always be ERR_OK
* when cs mode is udp.
*
* @retval The return value is only valid for tcp receive, for upd it means nothing.
* ERR_OK: Return this value after handling the received data.
* ERR_ABRT: Only return ERR_ABRT if you want to abort the socket from within the
* callback function!
*/
typedef err_t (*socket_recv_fn)(u8 skt_num, struct pbuf *p, err_t err);
/**
* @brief This Function prototype for socket srce ip callback functions. Called when data has
* been received.
*
* @param[in] skt_num Is the socket number that returned by tls_socket_create function.
*
* @param[in] datalen The received data length
*
* @param[in] ipsrc source ip addr
*
* @param[in] port source port
*
* @param[in] err An error code if there has been an error receiving, always be ERR_OK
* when cs mode is udp.
*
* @retval The return value is only valid for UDP receive, for udp it means nothing.
* ERR_OK: Return this value after handling the received data.
* ERR_ABRT: Only return ERR_ABRT if you want to abort the socket from within the
* callback function!
*/
typedef err_t (*socket_recv_ip_rpt_fn)(u8 skt_num, u16 datalen, u8 *ipsrc, u16 port, err_t err);
/**
* @brief This Function prototype for tcp connected callback functions. Called when
* connected to the remote side.
*
* @param[in] skt_num Is the socket number that returned by tls_socket_create function.
*
* @param[in] err An unused error code, always ERR_OK currently.
*
* @retval ERR_OK: Return this value after handling your logic.
* @retval ERR_ABRT: Only return ERR_ABRT if you want to abort the socket from within the
* callback function!
*/
typedef err_t (*socket_connected_fn)(u8 skt_num, err_t err);
/**
* @brief This Function prototype for tcp poll callback functions. Called periodically.
*
* @param[in] skt_num Is the socket number that returned by tls_socket_create function.
*
* @retval ERR_OK: Try to do something periodically.
* @retval ERR_ABRT: Only return ERR_ABRT if you want to abort the socket from within the
* callback function!
*/
typedef err_t (*socket_poll_fn)(u8 skt_num);
/**
* @brief This Function prototype for tcp accept callback functions. Called when a new
* connection can be accepted on a listening tcp.
*
* @param[in] skt_num Is the socket number that returned by tls_socket_create function.
*
* @param[in] err An error code if there has been an error accepting.
*
* @retval ERR_OK: Return this value after handling your logic.
* @retval ERR_ABRT: Only return ERR_ABRT if you want to abort the socket from within the
* callback function!
*/
typedef err_t (*socket_accept_fn)(u8 skt_num, err_t err);
/**
* @brief This Function prototype for socket state changed callback functions. Called when socket
* the sockte's state changed.
*
* @param[in] skt_num Is the socket number that returned by tls_socket_create function.
*
* @param[in] event Is the event number, see socket event defination.
*
* @param[in] state Is the socket state, see socket state defination.
*/
typedef void(*socket_state_changed_fn)(u8 skt_num, u8 event, u8 state);
/** Definitions for error constants. */
typedef enum {
/** No error, everything OK. */
ERR_OK = 0,
/** Out of memory error. */
ERR_MEM = -1,
/** Buffer error. */
ERR_BUF = -2,
/** Timeout. */
ERR_TIMEOUT = -3,
/** Routing problem. */
ERR_RTE = -4,
/** Operation in progress */
ERR_INPROGRESS = -5,
/** Illegal value. */
ERR_VAL = -6,
/** Operation would block. */
ERR_WOULDBLOCK = -7,
/** Address in use. */
ERR_USE = -8,
/** Already connecting. */
ERR_ALREADY = -9,
/** Conn already established.*/
ERR_ISCONN = -10,
/** Not connected. */
ERR_CONN = -11,
/** Low-level netif error */
ERR_IF = -12,
/** Connection aborted. */
ERR_ABRT = -13,
/** Connection reset. */
ERR_RST = -14,
/** Connection closed. */
ERR_CLSD = -15,
/** Illegal argument. */
ERR_ARG = -16
} err_enum_t;
enum tls_socket_protocol{
SOCKET_PROTO_TCP, /* TCP Protocol */
SOCKET_PROTO_UDP, /* UDP Protocol */
};
enum tls_socket_cs_mode{
SOCKET_CS_MODE_CLIENT, /* Client mode */
SOCKET_CS_MODE_SERVER, /* Server mode */
};
struct tls_socket_desc {
enum tls_socket_cs_mode cs_mode; /* Server mode or Client mode, Only for tcp protocol is valid */
enum tls_socket_protocol protocol; /* TCP Protocol or UDP Protocol */
ip_addr_t ip_addr; /* Remote ip address, for tcp client mode is remote server's ip address; for tcp server mode can be any address. */
/* for udp is remote server's ip address */
u16 port; /* port, for tcp client mode is remote server's port; for tcp server mode is local listen port .
for udp is remote server's port */
u16 localport; /* local port, for udp and tcp client is local listen port, for tcp server means nothing, tcp server always listen at port */
char host_name[32]; /* remote host name, not support for now */
u8 host_len; /* the length of host name */
u32 timeout; /* poll timeout, not implemented for now */
socket_err_fn errf; /* a pointer to socket_err_fn */
socket_recv_fn recvf; /* a pointer to socket_recv_fn */
socket_connected_fn connf; /* a pointer to socket_connected_fn */
socket_poll_fn pollf; /* a pointer to socket_poll_fn */
socket_accept_fn acceptf; /* a pointer to socket_accept_fn */
socket_state_changed_fn state_changed; /* a pointer to socket_state_changed_fn */
socket_recv_ip_rpt_fn recvwithipf; /*recv skt info report*/
};
/**
* @brief This function is called by your application code to create a socket.
*
* @param[in] skd Is a pointer to an tls_socket_desc.
*
* @retval ERR_OK If create socket successfully.
* negative number If an error was detected.
*/
int tls_socket_create(struct tls_socket_desc * skd);
/**
* @brief This function is called by your application code to send data by the socket.
*
* @param[in] skt_num Is the socket number that returned by tls_socket_create function.
*
* @param[in] pdata Is a pointer to the data which need to be send by the socket.
*
* @param[in] len The data's length.
*
* @retval ERR_OK If send data successfully.
* negative number If an error was detected.
*/
int tls_socket_send(u8 skt_num, void *pdata, u16 len);
/**
* @brief This function is called by your application code to close the socket, and the related resources would be released.
*
* @param[in] skt_num Is the socket number that returned by tls_socket_create function.
*
* @retval ERR_OK If close socket successfully.
* negative number If an error was detected.
*/
int tls_socket_close(u8 skt_num);
struct tls_skt_status_ext_t {
u8 socket;
u8 status;
enum tls_socket_protocol protocol;
u8 host_ipaddr[4];
u16 remote_port;
u16 local_port;
};
struct tls_skt_status_t {
u32 socket_cnt;
struct tls_skt_status_ext_t skts_ext[1];
};
/**
* @brief This function is called by your application code to get the socket status of specified socket num.
*
* @param[in] skt_num Is the socket number that returned by tls_socket_create function.
*
* @param[in] buf Is a pointer to the data contains the socket status, if the socket is server, also contains it's client's status.
*
* @param[in] len The buf's length. At least, the len should be bigger than sizeof(struct tls_skt_status_t).
*
* @retval ERR_OK If send data successfully.
* negative number If an error was detected.
*/
int tls_socket_get_status(u8 skt_num, u8 *buf, u32 bufsize);
/**
* @brief This function is called by your application code to send data by udp socket.
*
* @param[in] localport This function will search all created sockets, if there is a socket whose localport equals this value and it's protocol is udp,
* then send the data by this socket, otherwise, nothing to send.
*
* @param[in] ip_addr Is the remote ip address.
*
* @param[in] port Is the remote port which upd send to.
*
* @param[in] pdata Is a pointer to the data which need to be send by the socket.
*
* @param[in] len The data's length.
* @retval ERR_OK If send data successfully.
* negative number If an error was detected.
*/
int tls_socket_udp_sendto(u16 localport, u8 *ip_addr, u16 port, void *pdata, u16 len);
/**
* @ingroup pbuf
* Enumeration of pbuf layers
*/
typedef enum {
/** Includes spare room for transport layer header, e.g. UDP header.
* Use this if you intend to pass the pbuf to functions like udp_send().
*/
PBUF_TRANSPORT,
/** Includes spare room for IP header.
* Use this if you intend to pass the pbuf to functions like raw_send().
*/
PBUF_IP,
/** Includes spare room for link layer header (ethernet header).
* Use this if you intend to pass the pbuf to functions like ethernet_output().
* @see PBUF_LINK_HLEN
*/
PBUF_LINK,
/** Includes spare room for additional encapsulation header before ethernet
* headers (e.g. 802.11).
* Use this if you intend to pass the pbuf to functions like netif->linkoutput().
* @see PBUF_LINK_ENCAPSULATION_HLEN
*/
PBUF_RAW_TX,
/** Use this for input packets in a netif driver when calling netif->input()
* in the most common case - ethernet-layer netif driver. */
PBUF_RAW
} pbuf_layer;
/**
* @ingroup pbuf
* Enumeration of pbuf types
*/
typedef enum {
/** pbuf data is stored in RAM, used for TX mostly, struct pbuf and its payload
are allocated in one piece of contiguous memory (so the first payload byte
can be calculated from struct pbuf).
pbuf_alloc() allocates PBUF_RAM pbufs as unchained pbufs (although that might
change in future versions).
This should be used for all OUTGOING packets (TX).*/
PBUF_RAM,
/** pbuf data is stored in ROM, i.e. struct pbuf and its payload are located in
totally different memory areas. Since it points to ROM, payload does not
have to be copied when queued for transmission. */
PBUF_ROM,
/** pbuf comes from the pbuf pool. Much like PBUF_ROM but payload might change
so it has to be duplicated when queued before transmitting, depending on
who has a 'ref' to it. */
PBUF_REF,
/** pbuf payload refers to RAM. This one comes from a pool and should be used
for RX. Payload can be chained (scatter-gather RX) but like PBUF_RAM, struct
pbuf and its payload are allocated in one piece of contiguous memory (so
the first payload byte can be calculated from struct pbuf).
Don't use this for TX, if the pool becomes empty e.g. because of TCP queuing,
you are unable to receive TCP acks! */
PBUF_POOL
} pbuf_type;
/**
* @brief This Function allocates a pbuf of the given type (possibly a chain for PBUF_POOL type).
*
* The actual memory allocated for the pbuf is determined by the
* layer at which the pbuf is allocated and the requested size
* (from the size parameter).
*
* @param[in] l layer flag to define header size
* @param[in] length size of the pbuf's payload
* @param[in] type this parameter decides how and where the pbuf
*
* @retval The allocated pbuf. If multiple pbufs where allocated, this
* is the first pbuf of a pbuf chain.
*/
struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type);
/**
* @brief This Function for release the buffer that you receive within the socket_recv_fn callback function.
* Attention please: If you return ERR_OK in the socket_recv_fn callback function, you must call this
* function to release the buffer by yourself. Otherwise, the buffer do not need be
* released by your code.
*
* @param[in] p The buffer you received in the socket_recv_fn callback function.
*
* @retval The number of de-allocated pbufs
*/
u8 pbuf_free(struct pbuf *p);
/**
* @brief This Function for copy (part of) the contents of a packet buffer to an application supplied buffer.
*
* @param[in] p the pbuf from which to copy data.
*
* @param[in] dataptr the application supplied buffer
*
* @param[in] len length of data to copy (dataptr must be big enough). No more
* than buf->tot_len will be copied, irrespective of len
*
* @param[in] offset offset into the packet buffer from where to begin copying len bytes
*
* @retval The number of bytes copied, or 0 on failure
*/
u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset);
#endif

15
include/net/wm_sockets.h Normal file
View File

@ -0,0 +1,15 @@
/**
* @file wm_sockets.h
*
* @brief socket apis
*
* @author winnermicro
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_SOCKET_API_H
#define WM_SOCKET_API_H
#include "wm_config.h"
#include "wm_sockets2.0.3.h"
#endif

File diff suppressed because it is too large Load Diff

18
include/os/wm_os_config.h Normal file
View File

@ -0,0 +1,18 @@
/**
* @file wm_os_config.h
*
* @brief WM OS select freertos or ucos
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_OS_CONFIG_H__
#define __WM_OS_CONFIG_H__
#define OS_CFG_ON 1
#define OS_CFG_OFF 0
#undef TLS_OS_FREERTOS
#define TLS_OS_FREERTOS OS_CFG_ON /*FreeRTOS need to modify wm_config.inc*/
#endif

731
include/os/wm_osal.h Normal file
View File

@ -0,0 +1,731 @@
/**
* @file wm_osal.h
*
* @brief WM OS adapter layer
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_OSAL_H
#define WM_OSAL_H
#include <stdio.h>
#include <stdlib.h>
#include "wm_config.h"
#include <core_804.h>
#include "wm_type_def.h"
/** OS TICK Frequency ,this value needs to keep the same as OS self-defined tick value*/
extern const unsigned int HZ;
/** Type definition of os_time_t */
typedef long os_time_t;
/** Structure definition of os_time */
struct os_time {
os_time_t sec;
os_time_t usec;
};
/** ENUMERATION of OS */
enum TLS_OS_TYPE{
OS_UCOSII = 0,
OS_FREERTOS = 1,
OS_MAX_NUM
};
/** TYPE definition of OS_STK */
#ifdef OS_STK
#undef OS_STK
#endif
typedef unsigned int OS_STK;
/** TYPE definition of OS_CPU_SR */
#ifdef OS_CPU_SR
#undef OS_CPU_SR
#endif
typedef unsigned int OS_CPU_SR;
/** TYPE definition of tls_os_task_t */
typedef void * tls_os_task_t;
/** TYPE definition of tls_os_timer_t */
typedef void tls_os_timer_t;
/** TYPE definition of tls_os_sem_t */
typedef void tls_os_sem_t;
/** TYPE definition of tls_os_queue_t */
typedef void tls_os_queue_t;
/** TYPE definition of tls_os_mailbox_t */
typedef void tls_os_mailbox_t;
/** TYPE definition of tls_os_mutex_t */
typedef void tls_os_mutex_t;
/** TYPE definition of TLS_OS_TIMER_CALLBACK */
typedef void (*TLS_OS_TIMER_CALLBACK)(void *ptmr, void *parg);
/** MACRO definition of TIMER ONE times */
#define TLS_OS_TIMER_OPT_ONE_SHORT 1u
/** MACRO definition of TIMER PERIOD */
#define TLS_OS_TIMER_OPT_PERIOD 2u
/** ENUMERATION definition of OS STATUS */
typedef enum tls_os_status {
TLS_OS_SUCCESS = 0,
TLS_OS_ERROR,
TLS_OS_ERR_TIMEOUT,
} tls_os_status_t;
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup OS_APIs OS APIs
* @brief Operate system APIs
*/
/**
* @addtogroup OS_APIs
* @{
*/
/**
* @brief This function is used to register OS tick timer irq
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_os_timer_init(void);
/**
* @brief This function is used to tick handler
*
* @param[in] *p argument
*
* @return None
*
* @note None
*/
void tls_os_time_tick(void *p);
/**
* @brief This function is used to initialize OS common resource
*
* @param[in] *arg
*
* @return None
*
* @note None
*/
void tls_os_init(void *arg);
/**
* @brief This function is used to start task scheduler
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_os_start_scheduler(void);
/**
* @brief This function is used to get OS type
*
* @param[in] None
*
* @retval 0 OS_UCOSII
* @retval 1 OS_FREERTOS
*
* @note May not be used by now.
*/
int tls_os_get_type(void);
/**
* @brief This function is used to create a task. Tasks can either be created prior to
the start of multitasking or by a running task.
A task cannot be created in an ISR.
*
* @param[in] *task pointer to the task
* @param[in] name the task's name
* @param[in] entry the task's entry function
* @param[in] param pointer to an optional data area which can be
used to pass parameters to the task when the
task first executes. Where the task is
concerned it thinks it was invoked and passed
the argument 'param' as follows:
void Task (void *param)
{
for (;;) {
Task code;
}
}
* @param[in] *stk_start pointer to the task's bottom of stack. Address must be between 0x20000000 and 0x20028000
* @param[in] stk_size the size of the stack in number of elements.
If OS_STK is set to INT8U,
'stk_size' corresponds to the number of bytes
available.
If OS_STK is set to INT16U, 'stk_size' contains
the number of 16-bit entries available.
Finally, if OS_STK is set to INT32U,
'stk_size' contains the number of 32-bit entries
available on the stack.
* @param[in] prio the task's priority. A unique priority MUST be
assigned to each task and the lower the number,
the higher the priority.
* @param[in] flag contains additional information about the behavior of the task
*
* @retval TLS_OS_SUCCESS the call was successful.
* @retval TLS_OS_ERROR failed
*
* @note 1) Stack Range: [stk_start, stk_start + stk_size) must be between 0x20000000 and 0x20028000
* 2) task stack: Using static memory like array, not using dynamic memory.
* 3) And if you use static memory like array (large size) as data storage in your application,
* we suggest you change it to dynamic memory by tls_mem_alloc.
*/
tls_os_status_t tls_os_task_create(tls_os_task_t *task,
const char* name,
void (*entry)(void* param),
void* param,
u8 *stk_start,
u32 stk_size,
u32 prio,
u32 flag);
/**
* @brief This function allows you to delete a task. The calling
task can delete itself by its own priority number.
The deleted task is returned to the dormant state
and can be re-activated by creating the deleted task
again.
*
* @param[in] prio task priority to delete
* @param[in] (*freefun)(void) function to free resource
*
* @retval TLS_OS_SUCCESS the call is successful
* @retval TLS_OS_ERROR failed
*
* @note Generally, you do not need to call this function in your application.
*/
tls_os_status_t tls_os_task_del(u8 prio, void (*freefun)(void));
/**
* @brief This function allows you to delete a task. The calling
task can delete itself by taks's handler.
The deleted task is returned to the dormant state
and can be re-activated by creating the deleted task
again.
*
* @param[in] prio task handler to delete
* @param[in] (*freefun)(void) function to free resource
*
* @retval TLS_OS_SUCCESS the call is successful
* @retval TLS_OS_ERROR failed
*
*/
tls_os_status_t tls_os_task_del_by_task_handle(void *handle, void (*freefun)(void));
/**
* @brief This function creates a mutual exclusion semaphore
*
* @param[in] prio the priority to use when accessing the mutual
exclusion semaphore. In other words, when the
semaphore is acquired and a higher priority task
attempts to obtain the semaphore then the
priority of the task owning the semaphore is
raised to this priority. It is assumed that
you will specify a priority that is LOWER in
value than ANY of the tasks competing for the
mutex.
* @param[in] **mutex pointer to the event control clock (OS_EVENT)
associated with the created mutex.
*
* @retval TLS_OS_SUCCESS the call was successful
* @retval TLS_OS_ERROR failed
*
* @note 1) The LEAST significant 8 bits of '.OSEventCnt' are used
to hold the priority number of the task owning the mutex
or 0xFF if no task owns the mutex.
2) The MOST significant 8 bits of '.OSEventCnt' are used to
hold the priority number to use to reduce priority
inversion.
*/
tls_os_status_t tls_os_mutex_create(u8 prio, tls_os_mutex_t **mutex);
/**
* @brief This function deletes a mutual exclusion semaphore and
readies all tasks pending on the it
*
* @param[in] *mutex pointer to the event control block associated
with the desired mutex
*
* @retval TLS_OS_SUCCESS The call was successful and the mutex
was deleted
* @retval TLS_OS_ERROR failed
*
* @note 1) This function must be used with care. Tasks that would
normally expect the presence of the mutex MUST check the
return code of OSMutexPend().
2) This call can potentially disable interrupts for a long
time. The interrupt disable time is directly
proportional to the number of tasks waiting on the mutex.
3) Because ALL tasks pending on the mutex will be readied,
you MUST be careful because the resource(s) will no
longer be guarded by the mutex.
4) IMPORTANT: In the 'OS_DEL_ALWAYS' case, we assume that
the owner of the Mutex (if there is one) is ready-to-run
and is thus NOT pending on another kernel object or has
delayed itself.In other words, if a task owns the mutex
being deleted,that task will be made ready-to-run at
its original priority.
*/
tls_os_status_t tls_os_mutex_delete(tls_os_mutex_t *mutex);
/**
* @brief This function waits for a mutual exclusion semaphore
*
* @param[in] *mutex pointer to the event control block
associated with the desired mutex
* @param[in] wait_time an optional timeout period (in clock ticks).
If non-zero, your task will wait for the resource
up to the amount of time specified by
this argument.
If you specify 0, however, your task will wait
forever at the specified mutex or,
until the resource becomes available.
*
* @retval TLS_OS_SUCCESS The call was successful and your task
owns the mutex
* @retval TLS_OS_ERROR failed
*
* @note 1) The task that owns the Mutex MUST NOT pend on
any other event while it owns the mutex.
2) You MUST NOT change the priority of the task
that owns the mutex
*/
tls_os_status_t tls_os_mutex_acquire(tls_os_mutex_t *mutex,
u32 wait_time);
/**
* @brief This function releases a mutual exclusion semaphore
*
* @param[in] *mutex pointer to the event control block
associated with the desired mutex
*
* @retval TLS_OS_SUCCESS The call was successful and the mutex was signaled.
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_mutex_release(tls_os_mutex_t *mutex);
/**
* @brief This function creates a semaphore
*
* @param[in] **sem pointer to the event control block (OS_EVENT)
associated with the created semaphore
* @param[in] cnt the initial value for the semaphore.
If the value is 0, no resource is available
(or no event has occurred).
You initialize the semaphore to a non-zero value
to specify how many resources are available
(e.g. if you have 10 resources, you would
initialize the semaphore to 10).
*
* @retval TLS_OS_SUCCESS success,The call was successful
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_sem_create(tls_os_sem_t **sem, u32 cnt);
/**
* @brief This function deletes a semaphore and readies all tasks
pending on this semaphore.
*
* @param[in] *sem pointer to the event control block associated
with the desired semaphore
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_sem_delete(tls_os_sem_t *sem);
/**
* @brief This function waits for a semaphore
*
* @param[in] *sem pointer to the event control block
associated with the desired semaphore
* @param[in] wait_time an optional timeout period (in clock ticks).
If non-zero, your task will wait for the
resource up to the amount of time specified
by this argument.If you specify 0, however,
your task will wait forever at the specified
semaphore or, until the resource becomes
available (or the event occurs).
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_sem_acquire(tls_os_sem_t *sem,
u32 wait_time);
/**
* @brief This function signals a semaphore
*
* @param[in] *sem pointer to the event control block associated
with the desired semaphore
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_sem_release(tls_os_sem_t *sem);
/**
* @brief This function sets the semaphore count to the value specified
as an argument.Typically,this value would be 0.You
would typically use this function when a semaphore is
used as a signaling mechanism and, you want to reset
the count value.
*
* @param[in] *sem pointer to the event control block
* @param[in] cnt the new value for the semaphore count. You would
pass 0 to reset the semaphore count.
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_sem_set(tls_os_sem_t *sem, u16 cnt);
/**
* @brief This function creates a message queue if free event cont
rol blocks are available
*
* @param[in] **queue pointer to the event control clock (OS_EVENT)
associated with the created queue
* @param[in] queue_size the number of elements in the storage area
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_queue_create(tls_os_queue_t **queue, u32 queue_size);
/**
* @brief This function deletes a message queue and readies all
tasks pending on the queue
*
* @param[in] *queue pointer to the event control block associated
with the desired queue
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_queue_delete(tls_os_queue_t *queue);
/**
* @brief This function sends a message to a queue
*
* @param[in] *queue pointer to the event control block
associated with the desired queue
* @param[in] *msg pointer to the message to send.
* @param[in] msg_size message size
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
tls_os_status_t tls_os_queue_send(tls_os_queue_t *queue,
void *msg,
u32 msg_size);
/**
* @brief This function is used to flush the contents of the message
queue.
*
* @param[in] *queue
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_queue_flush(tls_os_queue_t *queue);
/**
* @brief This function waits for a message to be sent to a queue
*
* @param[in] *queue pointer to the event control block associated
with the desired queue
* @param[in] **msg pointer to the message received
* @param[in] msg_size message size
* @param[in] wait_time an optional timeout period (in clock ticks).
If non-zero, your task will wait for a message
to arrive at the queue up to the amount of time
specified by this argument. If you specify 0,
however, your task will wait forever at the
specified queue or, until a message arrives.
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_queue_receive(tls_os_queue_t *queue,void **msg,
u32 msg_size,
u32 wait_time);
/**
* @brief This function creates a message mailbox if free event
control blocks are available.
*
* @param[in] **mailbox pointer to the event control clock (OS_EVENT)
associated with the created mailbox
* @param[in] mailbox_size size
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_mailbox_create(tls_os_mailbox_t **mailbox, u32 mailbox_size);
/**
* @brief This function deletes a mailbox and readies all of the tasks
pending on the this mailbox.
*
* @param[in] *mailbox pointer to the event control block
associated with the desired mailbox.
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_mailbox_delete(tls_os_mailbox_t *mailbox);
/**
* @brief This function sends a message to a mailbox
*
* @param[in] *mailbox pointer to the event control block associated
with the desired mailbox
* @param[in] *msg pointer to the message to send.
You MUST NOT send a NULL pointer
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_mailbox_send(tls_os_mailbox_t *mailbox,void *msg);
/**
* @brief This function waits for a message to be sent to a mailbox
*
* @param[in] *mailbox pointer to the event control block associated
with the desired mailbox
* @param[in] **msg pointer to the message received
* @param[in] wait_time an optional timeout period (in clock ticks).
If non-zero, your task will wait for a message
to arrive at the mailbox up to the amount of
time specified by this argument.
If you specify 0, however, your task will wait
forever at the specified mailbox or,
until a message arrives.
*
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_mailbox_receive(tls_os_mailbox_t *mailbox,
void **msg,
u32 wait_time);
/**
* @brief This function is used by your application to obtain the
current value of the 32-bit counter which keeps track
of the number of clock ticks since the system starts.
*
* @param[in] None
*
* @retval current value of OSTime
*
* @note None
*/
u32 tls_os_get_time(void);
/**
* @brief This function is used to disable interrupts by preserving
the state of interrupts
*
* @param[in] None
*
* @retval cpu_sr
*
* @note None
*/
u32 tls_os_set_critical(void);
/**
* @brief This function is used to enable interrupts by preserving
the state of interrupts
*
* @param[in] cpu_sr
*
* @return None
*
* @note None
*/
void tls_os_release_critical(u32 cpu_sr);
/**
* @brief This function is called by your application code to create
a timer
*
* @param[in] **timer pointer to an OS_TMR data structure.
This is the 'handle' that your application will
use to reference the timer created
* @param[in] callback pointer to a callback function that will
be called when the timer expires. The callback
function must be declared as follows
void MyCallback (OS_TMR *ptmr, void *p_arg);
* @param[in] *callback_arg argument (a pointer) that is passed to
the callback function when it is called
* @param[in] period The 'period' being repeated for the timer.
If you specified 'OS_TMR_OPT_PERIODIC' as
an option, when the timer expires, it will
automatically restart with the same period.
* @param[in] repeat if repeat
* @param[in] *name pointer to an ASCII string that is used to
name the timer. Names are useful for
debugging.
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_timer_create(tls_os_timer_t **timer,
TLS_OS_TIMER_CALLBACK callback,
void *callback_arg,
u32 period,
bool repeat,
u8 *name);
/**
* @brief This function is called by your application code to start
a timer.
*
* @param[in] *timer pointer to an OS_TMR
*
* @return None
*
* @note None
*/
void tls_os_timer_start(tls_os_timer_t *timer);
/*
************************************************************************************************************************
* CHANGE A TIMER WAIT TIME
*
* Description: This function is called by your application code to change a timer wait time.
*
* Arguments : timer Is a pointer to an OS_TMR
*
* ticks is the wait time
************************************************************************************************************************
*/
void tls_os_timer_change(tls_os_timer_t *timer, u32 ticks);
/**
* @brief This function is called by your application code to stop
a timer
*
* @param[in] *timer pointer to the timer to stop.
*
* @return None
*
* @note None
*/
void tls_os_timer_stop(tls_os_timer_t *timer);
/**
* @brief This function is called by your application code to delete
a timer
*
* @param[in] *timer pointer to the timer to delete
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
tls_os_status_t tls_os_timer_delete(tls_os_timer_t *timer);
/**
* @brief This function is called to delay execution of the currently
running task until the specified number of system
ticks expires. This, of course, directly equates to
delaying the current task for some time to expire.
There will be no delay if the specified delay is 0.
If the specified delay is greater than 0 then,
a context switch will executed.
*
* @param[in] ticks the time delay that the task will be suspended
in number of clock 'ticks'.Note that by specifying 0,
the task will not be delayed.
*
* @return None
*
* @note None
*/
void tls_os_time_delay(u32 ticks);
/**
* @brief This function is used to display all the tasks' detail status.
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_os_disp_task_stat_info(void);
/**
* @}
*/
/**
* @}
*/
#endif /* end of WM_OSAL_H */

29
include/platform/aes.h Normal file
View File

@ -0,0 +1,29 @@
/**
* @file aes.h
* @brief AES functions
* @copyright (c) 2003-2006, Jouni Malinen <jkmaline@cc.hut.fi>
*
* @note This program 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.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*/
#ifndef AES_H
#define AES_H
#include <stddef.h>
#include "wm_type_def.h"
int aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data,
size_t data_len);
int aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data,
size_t data_len);
#endif /* AES_H */

Some files were not shown because too many files have changed in this diff Show More