add ALIENTEK_W601 support

add ALIENTEK_W601 wifi support
This commit is contained in:
supowang
2019-09-25 15:24:38 +08:00
parent 874b7307ae
commit e147b06080
120 changed files with 44790 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
#ifndef __BEEP_H
#define __BEEP_H
/*********************************************************************************
___ _ _____ _____ _ _ _____ _____ _ __
/ _ \ | | |_ _|| ___|| \ | ||_ _|| ___|| | / /
/ /_\ \| | | | | |__ | \| | | | | |__ | |/ /
| _ || | | | | __| | . ` | | | | __| | \
| | | || |_____| |_ | |___ | |\ | | | | |___ | |\ \
\_| |_/\_____/\___/ \____/ \_| \_/ \_/ \____/ \_| \_/
* ******************************************************************************
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
* ALIENTEK W601<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2019/7/10
* <09><EFBFBD><E6B1BE>V1.0
* <09><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
* Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2019-2029
* All rights reserved
* ******************************************************************************
* <09><>ʼ<EFBFBD>
* ******************************************************************************/
#define BEEP PBout(15)
void BEEP_Init(void);
#endif

View File

@@ -0,0 +1,21 @@
#ifndef __DWT_H_
#define __DWT_H_
#include "sys.h"
#define DWT_CR *(volatile uint32_t *)0xE0001000
#define DWT_CYCCNT *(volatile uint32_t *)0xE0001004
#define DEM_CR *(volatile uint32_t *)0xE000EDFC
#define DEM_CR_TRCENA (1 << 24)
#define DWT_CR_CYCCNTENA (1 << 0)
#define delayms(msec) delayus(msec*1000)
void dwt_delay_init(uint32_t clk);
void delay_us(uint32_t usec);
void delay_ms(__IO uint32_t nTime);
#endif

View File

@@ -0,0 +1,43 @@
#ifndef _KEY_H
#define _KEY_H
#include "sys.h"
/*********************************************************************************
___ _ _____ _____ _ _ _____ _____ _ __
/ _ \ | | |_ _|| ___|| \ | ||_ _|| ___|| | / /
/ /_\ \| | | | | |__ | \| | | | | |__ | |/ /
| _ || | | | | __| | . ` | | | | __| | \
| | | || |_____| |_ | |___ | |\ | | | | |___ | |\ \
\_| |_/\_____/\___/ \____/ \_| \_/ \_/ \____/ \_| \_/
* ******************************************************************************
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
* ALIENTEK W601<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* KEY<45><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2019/7/10
* <09><EFBFBD><E6B1BE>V1.0
* <09><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
* Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2019-2029
* All rights reserved
* ******************************************************************************
* <09><>ʼ<EFBFBD>
* ******************************************************************************/
/*
KEY0 - PA7
KEY1 - PA6
KEY_UP - PA8
*/
#define KEY0 PAin(7)
#define KEY1 PAin(6)
#define KEY_UP PAin(8)
#define KEY0_PRES 1
#define KEY1_PRES 2
#define WKUP_PRES 3
void KEY_Init(void);
u8 KEY_Scan(u8 mode);
#endif

View File

@@ -0,0 +1,40 @@
#ifndef _LED_H
#define _LED_H
#include "sys.h"
/*********************************************************************************
___ _ _____ _____ _ _ _____ _____ _ __
/ _ \ | | |_ _|| ___|| \ | ||_ _|| ___|| | / /
/ /_\ \| | | | | |__ | \| | | | | |__ | |/ /
| _ || | | | | __| | . ` | | | | __| | \
| | | || |_____| |_ | |___ | |\ | | | | |___ | |\ \
\_| |_/\_____/\___/ \____/ \_| \_/ \_/ \____/ \_| \_/
* ******************************************************************************
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
* ALIENTEK W601<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2018/10/27
* <09><EFBFBD><E6B1BE>V1.0
* <09><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
* Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2014-2024
* All rights reserved
* ******************************************************************************
* <09><>ʼ<EFBFBD>
* ******************************************************************************/
//RGB<47>ӿڶ<D3BF><DAB6><EFBFBD>
#define LED_R PAout(13)
#define LED_G PAout(14)
#define LED_B PAout(15)
void LED_Init(void);
#endif

View File

@@ -0,0 +1,78 @@
#ifndef __SYS_H
#define __SYS_H
/*********************************************************************************
___ _ _____ _____ _ _ _____ _____ _ __
/ _ \ | | |_ _|| ___|| \ | ||_ _|| ___|| | / /
/ /_\ \| | | | | |__ | \| | | | | |__ | |/ /
| _ || | | | | __| | . ` | | | | __| | \
| | | || |_____| |_ | |___ | |\ | | | | |___ | |\ \
\_| |_/\_____/\___/ \____/ \_| \_/ \_/ \____/ \_| \_/
* ******************************************************************************
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
* ALIENTEK W601<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ϵͳʱ<CDB3>ӳ<EFBFBD>ʼ<EFBFBD><CABC>
* <09><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F>жϹ<D0B6><CFB9><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2019/7/10
* <09><EFBFBD><E6B1BE>V1.0
* <09><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
* Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2019-2029
* All rights reserved
* ******************************************************************************
* <09><EFBFBD>޸<EFBFBD>˵<EFBFBD><CBB5>
* <09><>
* ******************************************************************************/
#include "misc.h"
#include "wm_type_def.h"
#include "wm_cpu.h"
#include "wm_ram_config.h"
#include "wm_gpio.h"
#include "wm_regs.h"
#include "wm_gpio_afsel.h"
#include "wm_uart_new.h"
#include "wm_uart.h"
#include "wm_pmu.h"
//λ<><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><CAB5>51<35><31><EFBFBD>Ƶ<EFBFBD>GPIO<49><4F><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>˼<EFBFBD><CBBC>,<2C>ο<EFBFBD><<CM3Ȩ<33><C8A8>ָ<EFBFBD><D6B8>>><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(87ҳ~92ҳ).M4ͬM3<4D><33><EFBFBD><EFBFBD><>ǼĴ<C7BC><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>.
//IO<49>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EAB6A8>
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
//IO<49>ڲ<EFBFBD><DAB2><EFBFBD><>Ե<EFBFBD>һ<EFBFBD><D2BB>IO<49><4F>!
//ȷ<><C8B7>n<EFBFBD><6E>ֵС<D6B5><D0A1>32!
#define PAout(n) BIT_ADDR(HR_GPIOA_DATA,n) //<2F><><EFBFBD><EFBFBD>
#define PAin(n) BIT_ADDR(HR_GPIOA_DATA,n) //<2F><><EFBFBD><EFBFBD>
#define PBout(n) BIT_ADDR(HR_GPIOB_DATA,n) //<2F><><EFBFBD><EFBFBD>
#define PBin(n) BIT_ADDR(HR_GPIOB_DATA,n) //<2F><><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><E0BAAF>
void WFI_SET(void); //ִ<><D6B4>WFIָ<49><D6B8>
void INTX_DISABLE(void);//<2F>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
void INTX_ENABLE(void); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
void MSR_MSP(u32 addr); //<2F><><EFBFBD>ö<EFBFBD>ջ<EFBFBD><D5BB>ַ
#endif

View File

@@ -0,0 +1,38 @@
#ifndef __USART_H
#define __USART_H
#include "stdio.h"
#include "sys.h"
/*********************************************************************************
___ _ _____ _____ _ _ _____ _____ _ __
/ _ \ | | |_ _|| ___|| \ | ||_ _|| ___|| | / /
/ /_\ \| | | | | |__ | \| | | | | |__ | |/ /
| _ || | | | | __| | . ` | | | | __| | \
| | | || |_____| |_ | |___ | |\ | | | | |___ | |\ \
\_| |_/\_____/\___/ \____/ \_| \_/ \_/ \____/ \_| \_/
* ******************************************************************************
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
* ALIENTEK W601<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD>0<EFBFBD><30>ʼ<EFBFBD><CABC>
* <09><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2019/7/10
* <09><EFBFBD><E6B1BE>V1.0
* <09><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
* Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2019-2029
* All rights reserved
* ******************************************************************************
* <09>޸<EFBFBD>˵<EFBFBD><CBB5>
* ******************************************************************************/
#define USART_REC_LEN 200 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD> 200
#define EN_USART1_RX 1 //ʹ<>ܣ<EFBFBD>1<EFBFBD><31>/<2F><>ֹ<EFBFBD><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>
extern u8 USART_RX_BUF[USART_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD><>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>з<EFBFBD>
extern u16 USART_RX_STA; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB4AE><EFBFBD>жϽ<D0B6><CFBD>գ<EFBFBD><D5A3>벻Ҫע<D2AA><D7A2><EFBFBD><EFBFBD><EFBFBD>º궨<C2BA><EAB6A8>
void uart_init(u32 bound);
#endif

View File

@@ -0,0 +1,56 @@
#include "sys.h"
#include "beep.h"
/*********************************************************************************
___ _ _____ _____ _ _ _____ _____ _ __
/ _ \ | | |_ _|| ___|| \ | ||_ _|| ___|| | / /
/ /_\ \| | | | | |__ | \| | | | | |__ | |/ /
| _ || | | | | __| | . ` | | | | __| | \
| | | || |_____| |_ | |___ | |\ | | | | |___ | |\ \
\_| |_/\_____/\___/ \____/ \_| \_/ \_/ \____/ \_| \_/
* ******************************************************************************
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
* ALIENTEK W601<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2019/7/10
* <09><EFBFBD><E6B1BE>V1.0
* <09><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
* Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2019-2029
* All rights reserved
* ******************************************************************************
* <09><>ʼ<EFBFBD>
* ******************************************************************************/
/**
* @brief <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IO<49><4F>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param void
*
* @return void
*/
void BEEP_Init(void)
{
/*
BEEP PB15
*/
tls_gpio_cfg(WM_IO_PB_15, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLLOW);
BEEP = 0;
}

View File

@@ -0,0 +1,36 @@
#include "dwt.h"
static uint32_t cpuclkfeq;
void dwt_delay_init(uint32_t clk)
{
cpuclkfeq = clk;
DEM_CR |= DEM_CR_TRCENA;
DWT_CYCCNT = 0u;
DWT_CR |= DWT_CR_CYCCNTENA;
}
void delay_us(uint32_t usec)
{
uint32_t startts, endts, ts;
startts = DWT_CYCCNT;
ts = usec * (cpuclkfeq / (1000 * 1000));
endts = startts + ts;
if(endts > startts)
{
while(DWT_CYCCNT < endts);
}
else
{
while(DWT_CYCCNT > endts);
while(DWT_CYCCNT < endts);
}
}
void delay_ms(__IO uint32_t nTime)
{
delay_us(1000 * nTime);
}

View File

@@ -0,0 +1,77 @@
#include "key.h"
#include "dwt.h"
/*********************************************************************************
___ _ _____ _____ _ _ _____ _____ _ __
/ _ \ | | |_ _|| ___|| \ | ||_ _|| ___|| | / /
/ /_\ \| | | | | |__ | \| | | | | |__ | |/ /
| _ || | | | | __| | . ` | | | | __| | \
| | | || |_____| |_ | |___ | |\ | | | | |___ | |\ \
\_| |_/\_____/\___/ \____/ \_| \_/ \_/ \____/ \_| \_/
* ******************************************************************************
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
* ALIENTEK W601<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* KEY<45><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2019/7/10
* <09><EFBFBD><E6B1BE>V1.0
* <09><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
* Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2019-2029
* All rights reserved
* ******************************************************************************
* <09><>ʼ<EFBFBD>
* ******************************************************************************/
/**
* @brief <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param void
*
* @return void
*/
void KEY_Init(void)
{
/*
KEY0 - PA7
KEY1 - PA6
KEY_UP - PA8 <09>ߵ<EFBFBD>ƽ<EFBFBD><C6BD>Ч
*/
tls_gpio_cfg(WM_IO_PA_06, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_cfg(WM_IO_PA_07, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_cfg(WM_IO_PA_08, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLLOW);
}
/**
* @brief <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @remark ע<><D7A2><EFBFBD>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD>,KEY0>KEY1>KEY2>KEY_UP!!
*
* @param mode 0:<3A><>֧<EFBFBD><D6A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,1:֧<><D6A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @return u8 <09><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD>ֵ
* 0:û<><C3BB><EFBFBD>κΰ<CEBA><CEB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,1:KEY0<59><30><EFBFBD><EFBFBD>,2:KEY1<59><31><EFBFBD><EFBFBD>,3:KEY2<59><32><EFBFBD><EFBFBD>,4:KEY_UP<55><50><EFBFBD><EFBFBD>
*/
u8 KEY_Scan(u8 mode)
{
static u8 key_up = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD>־
if(mode == 1)key_up = 1; //֧<><D6A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(key_up && (KEY0 == 0 || KEY1 == 0 || KEY_UP == 1))
{
delay_ms(10);
key_up = 0;
if(KEY0 == 0) return KEY0_PRES;
else if(KEY1 == 0) return KEY1_PRES;
else if(KEY_UP == 1) return WKUP_PRES;
}
else if(KEY0 == 1 && KEY1 == 1 && KEY_UP == 0)key_up = 1;
return 0; //<2F>ް<EFBFBD><DEB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}

View File

@@ -0,0 +1,54 @@
#include "led.h"
/*********************************************************************************
___ _ _____ _____ _ _ _____ _____ _ __
/ _ \ | | |_ _|| ___|| \ | ||_ _|| ___|| | / /
/ /_\ \| | | | | |__ | \| | | | | |__ | |/ /
| _ || | | | | __| | . ` | | | | __| | \
| | | || |_____| |_ | |___ | |\ | | | | |___ | |\ \
\_| |_/\_____/\___/ \____/ \_| \_/ \_/ \____/ \_| \_/
* ******************************************************************************
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
* ALIENTEK W601<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2019/7/10
* <09><EFBFBD><E6B1BE>V1.0
* <09><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
* Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2019-2029
* All rights reserved
* ******************************************************************************
* <09><>ʼ<EFBFBD>
* ******************************************************************************/
/**
* @brief LED IO<49><4F>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param void
*
* @return void
*/
void LED_Init(void)
{
/*
LED-B PA13
LED-G PA14
LED-R PA15
*/
tls_gpio_cfg(WM_IO_PA_13, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
tls_gpio_cfg(WM_IO_PA_14, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
tls_gpio_cfg(WM_IO_PA_15, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
LED_R = 1;
LED_G = 1;
LED_B = 1;
}

View File

@@ -0,0 +1,48 @@
#include "sys.h"
#include "usart.h"
#include "led.h"
#include "beep.h"
#include "key.h"
#include "dwt.h"
#include "cmsis_os.h"
#define APPLICATION_TASK_STK_SIZE 1024
extern void application_entry(void *arg);
osThreadDef(application_entry, osPriorityNormal, 1, APPLICATION_TASK_STK_SIZE);
void board_init(void)
{
dwt_delay_init(80000000);
uart_init(115200); //<2F><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC>
LED_Init(); //LED<45>ӿڳ<D3BF>ʼ<EFBFBD><CABC>
}
void OS_CPU_SysTickHandler(void)
{
if (tos_knl_is_running())
{
tos_knl_irq_enter();
tos_tick_handler();
tos_knl_irq_leave();
}
}
__weak void application_entry(void *arg)
{
while (1) {
printf("This is a demo task,please use your task entry!\r\n");
tos_task_delay(1000);
}
}
int main(void)
{
board_init();
printf("Welcome to TencentOS tiny\r\n");
osKernelInitialize(); // TOS Tiny kernel initialize
osThreadCreate(osThread(application_entry), NULL); // Create TOS Tiny task
osKernelStart(); // Start TOS Tiny
}

View File

@@ -0,0 +1,122 @@
#include "sys.h"
#include "tos_config.h"
/*********************************************************************************
___ _ _____ _____ _ _ _____ _____ _ __
/ _ \ | | |_ _|| ___|| \ | ||_ _|| ___|| | / /
/ /_\ \| | | | | |__ | \| | | | | |__ | |/ /
| _ || | | | | __| | . ` | | | | __| | \
| | | || |_____| |_ | |___ | |\ | | | | |___ | |\ \
\_| |_/\_____/\___/ \____/ \_| \_/ \_/ \____/ \_| \_/
* ******************************************************************************
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
* ALIENTEK W601<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ϵͳʱ<CDB3>ӳ<EFBFBD>ʼ<EFBFBD><CABC>
* <09><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F>жϹ<D0B6><CFB9><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2019/7/10
* <09><EFBFBD><E6B1BE>V1.0
* <09><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
* Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2019-2029
* All rights reserved
* ******************************************************************************
* <09><EFBFBD>޸<EFBFBD>˵<EFBFBD><CBB5>
* <09><>
* ******************************************************************************/
/**
* @brief ϵͳ<CFB5><CDB3><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
*
* @remark <09>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD>startup.s<>е<EFBFBD><D0B5><EFBFBD>,W601ϵͳʱ<CDB3>ӳ<EFBFBD>ʼ<EFBFBD><CABC>Ϊ80MHz
*
* @param void
*
* @return void
*/
void SystemInit(void)
{
tls_sys_clk sysclk;
/*ϵͳʱ<CDB3><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ80MHz*/
tls_sys_clk_set(CPU_CLK_80M);
/*<2A>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>IO<49>ĸ<EFBFBD><C4B8>ù<EFBFBD><C3B9>ܣ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>SWD<57><44><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>*/
wm_gpio_af_disable();
tls_sys_clk_get(&sysclk);
SysTick_Config(sysclk.cpuclk * UNIT_MHZ / TOS_CFG_CPU_TICK_PER_SECOND);
/*<2A>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˯<EFBFBD>ߵ͹<DFB5><CDB9><EFBFBD>ģʽ*/
NVIC_SystemLPConfig(NVIC_LP_SLEEPDEEP, ENABLE);
/*ѡ<><D1A1>PMUʱ<55><CAB1>*/
tls_pmu_clk_select(0);
}
/**
* @brief THUMBָ<42>֧<EEB2BB>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ʵ<EFBFBD><CAB5>ִ<EFBFBD>л<EFBFBD><D0BB><EFBFBD>ָ<EFBFBD><D6B8>WFI
*
* @param void
*
* @return __asm
*/
__asm void WFI_SET(void)
{
WFI;
}
/**
* @brief <09>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>(<28><><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD>fault<6C><74>NMI<4D>ж<EFBFBD>)
*
* @param void
*
* @return __asm
*/
__asm void INTX_DISABLE(void)
{
CPSID I
BX LR
}
/**
* @brief <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
*
* @param void
*
* @return __asm
*/
__asm void INTX_ENABLE(void)
{
CPSIE I
BX LR
}
/**
* @brief <09><><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD>ַ
*
* @param addr ջ<><D5BB><EFBFBD><EFBFBD>ַ
*
* @return __asm
*/
__asm void MSR_MSP(u32 addr)
{
MSR MSP, r0 //set Main Stack value
BX r14
}

View File

@@ -0,0 +1,176 @@
#include "sys.h"
#include "usart.h"
/*********************************************************************************
___ _ _____ _____ _ _ _____ _____ _ __
/ _ \ | | |_ _|| ___|| \ | ||_ _|| ___|| | / /
/ /_\ \| | | | | |__ | \| | | | | |__ | |/ /
| _ || | | | | __| | . ` | | | | __| | \
| | | || |_____| |_ | |___ | |\ | | | | |___ | |\ \
\_| |_/\_____/\___/ \____/ \_| \_/ \_/ \____/ \_| \_/
* ******************************************************************************
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
* ALIENTEK W601<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <09><><EFBFBD><EFBFBD>0<EFBFBD><30>ʼ<EFBFBD><CABC>
* <09><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2019/7/10
* <09><EFBFBD><E6B1BE>V1.0
* <09><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
* Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2019-2029
* All rights reserved
* ******************************************************************************
* <09>޸<EFBFBD>˵<EFBFBD><CBB5>
* ******************************************************************************/
//////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD><><D6A7>printf<74><66><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫѡ<D2AA><D1A1>use MicroLIB
#if 1
#pragma import(__use_no_semihosting)
//<2F><>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>֧<EFBFBD>ֺ<EFBFBD><D6BA><EFBFBD>
struct __FILE
{
int handle;
};
FILE __stdout;
/**
* @brief <09><><EFBFBD><EFBFBD>_sys_exit()<29>Ա<EFBFBD><D4B1><EFBFBD>ʹ<EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD>ģʽ
*
* @param void
*
* @return void
*/
void _sys_exit(int x)
{
x = x;
}
/**
* @brief <09>ض<EFBFBD><D8B6><EFBFBD>fputc<74><63><EFBFBD><EFBFBD>
*
* @param ch <09><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
* @param f <09>ļ<EFBFBD>ָ<EFBFBD><D6B8>
*
* @return void
*/
int fputc(int ch, FILE *f)
{
while(tls_reg_read32(HR_UART0_FIFO_STATUS) & 0x3F); //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
tls_reg_write32(HR_UART0_TX_WIN, (u8) ch);
return ch;
}
#endif
#if EN_USART1_RX //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>˽<EFBFBD><CBBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>1<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ע<><D7A2>,<2C><>ȡUSARTx->SR<53>ܱ<EFBFBD><DCB1><EFBFBD>Ī<EFBFBD><C4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
u8 USART_RX_BUF[USART_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD>.
//<2F><><EFBFBD><EFBFBD>״̬
//bit15<31><35> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
//bit14<31><34> <09><><EFBFBD>յ<EFBFBD>0x0d
//bit13~0<><30> <09><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ŀ
u16 USART_RX_STA = 0; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
/**
* @brief <09><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>
*
* @param bound <09><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
*
* @return void
*/
void uart_init(u32 bound)
{
u32 bd;
u32 apbclk;
tls_sys_clk sysclk;
/* 1.<2E><><EFBFBD><EFBFBD>IO */
wm_uart0_tx_config(WM_IO_PA_04);
wm_uart0_rx_config(WM_IO_PA_05);
/* 2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
ubdiv = (apbclk / (16 * bound) - 1)
ubdiv_frac = ((apbclk % (bound * 16)) / (bound)) */
tls_sys_clk_get(&sysclk);
apbclk = sysclk.apbclk * 1000000;
bd = (apbclk / (16 * bound) - 1) | (((apbclk % (bound * 16)) / (bound)) << 16);
tls_reg_write32(HR_UART0_BAUD_RATE_CTRL, bd);
/* 2.<2E><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><38><CEBB><EFBFBD><EFBFBD>λ/1λֹͣλ/<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ/<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>/<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> */
tls_reg_write32(HR_UART0_LINE_CTRL, ULCON_WL8 | ULCON_TX_EN | ULCON_RX_EN);
/* 3.Ӳ<><D3B2><EFBFBD><EFBFBD><EFBFBD>عر<D8B9> */
tls_reg_write32(HR_UART0_FLOW_CTRL, 0);
/* 3.<2E><>ʹ<EFBFBD><CAB9>DMA */
tls_reg_write32(HR_UART0_DMA_CTRL, 0);
/* 4.FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>1<EFBFBD><31><EFBFBD>ֽ<EFBFBD> */
tls_reg_write32(HR_UART0_FIFO_CTRL, 0);
/* 5.<2E><><EFBFBD><EFBFBD>RX<52>ж<EFBFBD>:<3A><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD>жϺͽ<CFBA><CDBD>ճ<EFBFBD>ʱ<EFBFBD>ж<EFBFBD>*/
tls_reg_write32(HR_UART0_INT_MASK, 0xFF & (~(UIS_RX_FIFO | UIS_RX_FIFO_TIMEOUT)));
/* 6.<2E><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD> */
NVIC_ClearPendingIRQ(UART0_IRQn);
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = UART0_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 7;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
/**
* @brief <09><><EFBFBD><EFBFBD>0<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param void
*
* @return void
*/
void UART0_IRQHandler(void)
{
u8 res;
if(tls_reg_read32(HR_UART0_INT_SRC) & UIS_RX_FIFO) //<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
{
res = (u8)tls_reg_read32(HR_UART0_RX_WIN);
if((USART_RX_STA & 0x8000) == 0) //<2F><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
{
if(USART_RX_STA & 0x4000) //<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>0x0d
{
if(res != 0x0a)USART_RX_STA = 0; //<2F><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD>,<2C><><EFBFBD>¿<EFBFBD>ʼ
else USART_RX_STA |= 0x8000; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
else //<2F><>û<EFBFBD>յ<EFBFBD>0X0D
{
if(res == 0x0d)USART_RX_STA |= 0x4000;
else
{
USART_RX_BUF[USART_RX_STA & 0X3FFF] = res;
USART_RX_STA++;
if(USART_RX_STA > (USART_REC_LEN - 1))USART_RX_STA = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>,<2C><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
}
}
}
tls_reg_write32(HR_UART0_INT_SRC, UIS_RX_FIFO); //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>־λ
}
if(tls_reg_read32(HR_UART0_INT_SRC) & UIS_RX_FIFO_TIMEOUT) //<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
{
tls_reg_write32(HR_UART0_INT_SRC, UIS_RX_FIFO_TIMEOUT); //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>־λ
}
}
#endif

Binary file not shown.

View File

@@ -0,0 +1 @@
1.0.06

View File

@@ -0,0 +1 @@
1.0.06

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,686 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_optx.xsd">
<SchemaVersion>1.0</SchemaVersion>
<Header>### uVision Project, (C) Keil Software</Header>
<Extensions>
<cExt>*.c</cExt>
<aExt>*.s*; *.src; *.a*</aExt>
<oExt>*.obj; *.o</oExt>
<lExt>*.lib</lExt>
<tExt>*.txt; *.h; *.inc</tExt>
<pExt>*.plm</pExt>
<CppX>*.cpp</CppX>
<nMigrate>0</nMigrate>
</Extensions>
<DaveTm>
<dwLowDateTime>0</dwLowDateTime>
<dwHighDateTime>0</dwHighDateTime>
</DaveTm>
<Target>
<TargetName>TencentOS_tiny</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<TargetOption>
<CLKADS>12000000</CLKADS>
<OPTTT>
<gFlags>1</gFlags>
<BeepAtEnd>1</BeepAtEnd>
<RunSim>0</RunSim>
<RunTarget>1</RunTarget>
<RunAbUc>0</RunAbUc>
</OPTTT>
<OPTHX>
<HexSelection>1</HexSelection>
<FlashByte>65535</FlashByte>
<HexRangeLowAddress>0</HexRangeLowAddress>
<HexRangeHighAddress>0</HexRangeHighAddress>
<HexOffset>0</HexOffset>
</OPTHX>
<OPTLEX>
<PageWidth>79</PageWidth>
<PageLength>66</PageLength>
<TabStop>8</TabStop>
<ListingPath>..\OBJ\</ListingPath>
</OPTLEX>
<ListingPage>
<CreateCListing>1</CreateCListing>
<CreateAListing>1</CreateAListing>
<CreateLListing>1</CreateLListing>
<CreateIListing>0</CreateIListing>
<AsmCond>1</AsmCond>
<AsmSymb>1</AsmSymb>
<AsmXref>0</AsmXref>
<CCond>1</CCond>
<CCode>0</CCode>
<CListInc>0</CListInc>
<CSymb>0</CSymb>
<LinkerCodeListing>0</LinkerCodeListing>
</ListingPage>
<OPTXL>
<LMap>1</LMap>
<LComments>1</LComments>
<LGenerateSymbols>1</LGenerateSymbols>
<LLibSym>1</LLibSym>
<LLines>1</LLines>
<LLocSym>1</LLocSym>
<LPubSym>1</LPubSym>
<LXref>0</LXref>
<LExpSel>0</LExpSel>
</OPTXL>
<OPTFL>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>1</IsCurrentTarget>
</OPTFL>
<CpuCode>7</CpuCode>
<DebugOpt>
<uSim>0</uSim>
<uTrg>1</uTrg>
<sLdApp>1</sLdApp>
<sGomain>1</sGomain>
<sRbreak>1</sRbreak>
<sRwatch>1</sRwatch>
<sRmem>1</sRmem>
<sRfunc>1</sRfunc>
<sRbox>1</sRbox>
<tLdApp>1</tLdApp>
<tGomain>1</tGomain>
<tRbreak>1</tRbreak>
<tRwatch>1</tRwatch>
<tRmem>1</tRmem>
<tRfunc>0</tRfunc>
<tRbox>1</tRbox>
<tRtrace>1</tRtrace>
<sRSysVw>1</sRSysVw>
<tRSysVw>1</tRSysVw>
<sRunDeb>0</sRunDeb>
<sLrtime>0</sLrtime>
<bEvRecOn>1</bEvRecOn>
<bSchkAxf>0</bSchkAxf>
<bTchkAxf>0</bTchkAxf>
<nTsel>6</nTsel>
<sDll></sDll>
<sDllPa></sDllPa>
<sDlgDll></sDlgDll>
<sDlgPa></sDlgPa>
<sIfile></sIfile>
<tDll></tDll>
<tDllPa></tDllPa>
<tDlgDll></tDlgDll>
<tDlgPa></tDlgPa>
<tIfile></tIfile>
<pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
</DebugOpt>
<TargetDriverDllRegistry>
<SetRegEntry>
<Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key>
<Name>-U003900513137510B39383538 -O206 -SF4000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0W60X_QFlash -FS08000000 -FL0100000</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>CMSIS_AGDI</Key>
<Name>-X"Any" -UAny -O206 -S8 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC2000 -FN1 -FF0W60X_QFlash -FS08000000 -FL0100000</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>UL2CM3</Key>
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000)</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint/>
<Tracepoint>
<THDelay>0</THDelay>
</Tracepoint>
<DebugFlag>
<trace>0</trace>
<periodic>0</periodic>
<aLwin>0</aLwin>
<aCover>0</aCover>
<aSer1>0</aSer1>
<aSer2>0</aSer2>
<aPa>0</aPa>
<viewmode>0</viewmode>
<vrSel>0</vrSel>
<aSym>0</aSym>
<aTbox>0</aTbox>
<AscS1>0</AscS1>
<AscS2>0</AscS2>
<AscS3>0</AscS3>
<aSer3>0</aSer3>
<eProf>0</eProf>
<aLa>0</aLa>
<aPa1>0</aPa1>
<AscS4>0</AscS4>
<aSer4>0</aSer4>
<StkLoc>0</StkLoc>
<TrcWin>0</TrcWin>
<newCpu>0</newCpu>
<uProt>0</uProt>
</DebugFlag>
<LintExecutable></LintExecutable>
<LintConfigFile></LintConfigFile>
<bLintAuto>0</bLintAuto>
<bAutoGenD>0</bAutoGenD>
<LntExFlags>0</LntExFlags>
<pMisraName></pMisraName>
<pszMrule></pszMrule>
<pSingCmds></pSingCmds>
<pMultCmds></pMultCmds>
<pMisraNamep></pMisraNamep>
<pszMrulep></pszMrulep>
<pSingCmdsp></pSingCmdsp>
<pMultCmdsp></pMultCmdsp>
</TargetOption>
</Target>
<Group>
<GroupName>USER</GroupName>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>1</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\BSP\Src\beep.c</PathWithFileName>
<FilenameWithoutPath>beep.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>2</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\BSP\Src\key.c</PathWithFileName>
<FilenameWithoutPath>key.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>3</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\BSP\Src\led.c</PathWithFileName>
<FilenameWithoutPath>led.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>4</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\BSP\Src\main.c</PathWithFileName>
<FilenameWithoutPath>main.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>5</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\BSP\Src\sys.c</PathWithFileName>
<FilenameWithoutPath>sys.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>6</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\BSP\Src\usart.c</PathWithFileName>
<FilenameWithoutPath>usart.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>7</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\BSP\Src\dwt.c</PathWithFileName>
<FilenameWithoutPath>dwt.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
<GroupName>WMLIB</GroupName>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>8</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\boot\armcc\misc.c</PathWithFileName>
<FilenameWithoutPath>misc.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>9</FileNumber>
<FileType>2</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\boot\armcc\startup.s</PathWithFileName>
<FilenameWithoutPath>startup.s</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>10</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_cpu.c</PathWithFileName>
<FilenameWithoutPath>wm_cpu.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>11</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_gpio.c</PathWithFileName>
<FilenameWithoutPath>wm_gpio.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>12</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_gpio_afsel.c</PathWithFileName>
<FilenameWithoutPath>wm_gpio_afsel.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>13</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_io.c</PathWithFileName>
<FilenameWithoutPath>wm_io.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>14</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_irq.c</PathWithFileName>
<FilenameWithoutPath>wm_irq.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>15</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_pmu.c</PathWithFileName>
<FilenameWithoutPath>wm_pmu.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>16</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_timer.c</PathWithFileName>
<FilenameWithoutPath>wm_timer.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
<GroupName>tos/arch</GroupName>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>17</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\arch\arm\arm-v7m\common\tos_cpu.c</PathWithFileName>
<FilenameWithoutPath>tos_cpu.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>18</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\arch\arm\arm-v7m\cortex-m3\armcc\port_c.c</PathWithFileName>
<FilenameWithoutPath>port_c.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>19</FileNumber>
<FileType>2</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\arch\arm\arm-v7m\cortex-m3\armcc\port_s.S</PathWithFileName>
<FilenameWithoutPath>port_s.S</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
<GroupName>tos/kernel</GroupName>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>20</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_event.c</PathWithFileName>
<FilenameWithoutPath>tos_event.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>21</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_fifo.c</PathWithFileName>
<FilenameWithoutPath>tos_fifo.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>22</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_global.c</PathWithFileName>
<FilenameWithoutPath>tos_global.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>23</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_mmblk.c</PathWithFileName>
<FilenameWithoutPath>tos_mmblk.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>24</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_mmheap.c</PathWithFileName>
<FilenameWithoutPath>tos_mmheap.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>25</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_msg.c</PathWithFileName>
<FilenameWithoutPath>tos_msg.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>26</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_mutex.c</PathWithFileName>
<FilenameWithoutPath>tos_mutex.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>27</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_pend.c</PathWithFileName>
<FilenameWithoutPath>tos_pend.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>28</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_queue.c</PathWithFileName>
<FilenameWithoutPath>tos_queue.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>29</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_robin.c</PathWithFileName>
<FilenameWithoutPath>tos_robin.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>30</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_sched.c</PathWithFileName>
<FilenameWithoutPath>tos_sched.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>31</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_sem.c</PathWithFileName>
<FilenameWithoutPath>tos_sem.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>32</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_sys.c</PathWithFileName>
<FilenameWithoutPath>tos_sys.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>33</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_task.c</PathWithFileName>
<FilenameWithoutPath>tos_task.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>34</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_tick.c</PathWithFileName>
<FilenameWithoutPath>tos_tick.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>35</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_time.c</PathWithFileName>
<FilenameWithoutPath>tos_time.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>36</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\kernel\core\tos_timer.c</PathWithFileName>
<FilenameWithoutPath>tos_timer.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
<GroupName>tos/cmsis</GroupName>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>5</GroupNumber>
<FileNumber>37</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\osal\cmsis_os\cmsis_os.c</PathWithFileName>
<FilenameWithoutPath>cmsis_os.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
<GroupName>examples</GroupName>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>6</GroupNumber>
<FileNumber>38</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\examples\hello_world\hello_world.c</PathWithFileName>
<FilenameWithoutPath>hello_world.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
</ProjectOpt>

View File

@@ -0,0 +1,612 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
<SchemaVersion>2.1</SchemaVersion>
<Header>### uVision Project, (C) Keil Software</Header>
<Targets>
<Target>
<TargetName>TencentOS_tiny</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5060750::V5.06 update 6 (build 750)::ARMCC</pCCUsed>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>
<Device>ARMCM3</Device>
<Vendor>ARM</Vendor>
<PackID>ARM.CMSIS.5.4.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x00020000) IROM(0x00000000,0x00040000) CPUTYPE("Cortex-M3") CLOCK(12000000) ESEL ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile>
<FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000)</FlashDriverDll>
<DeviceId>0</DeviceId>
<RegisterFile>$$Device:ARMCM3$Device\ARM\ARMCM3\Include\ARMCM3.h</RegisterFile>
<MemoryEnv></MemoryEnv>
<Cmp></Cmp>
<Asm></Asm>
<Linker></Linker>
<OHString></OHString>
<InfinionOptionDll></InfinionOptionDll>
<SLE66CMisc></SLE66CMisc>
<SLE66AMisc></SLE66AMisc>
<SLE66LinkerMisc></SLE66LinkerMisc>
<SFDFile></SFDFile>
<bCustSvd>0</bCustSvd>
<UseEnv>0</UseEnv>
<BinPath></BinPath>
<IncludePath></IncludePath>
<LibPath></LibPath>
<RegisterFilePath></RegisterFilePath>
<DBRegisterFilePath></DBRegisterFilePath>
<TargetStatus>
<Error>0</Error>
<ExitCodeStop>0</ExitCodeStop>
<ButtonStop>0</ButtonStop>
<NotGenerated>0</NotGenerated>
<InvalidFlash>1</InvalidFlash>
</TargetStatus>
<OutputDirectory>..\OBJ\</OutputDirectory>
<OutputName>TencentOS_tiny</OutputName>
<CreateExecutable>1</CreateExecutable>
<CreateLib>0</CreateLib>
<CreateHexFile>1</CreateHexFile>
<DebugInformation>1</DebugInformation>
<BrowseInformation>1</BrowseInformation>
<ListingPath>..\OBJ\</ListingPath>
<HexFormatSelection>1</HexFormatSelection>
<Merge32K>0</Merge32K>
<CreateBatchFile>0</CreateBatchFile>
<BeforeCompile>
<RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name></UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopU1X>0</nStopU1X>
<nStopU2X>0</nStopU2X>
</BeforeCompile>
<BeforeMake>
<RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name></UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopB1X>0</nStopB1X>
<nStopB2X>0</nStopB2X>
</BeforeMake>
<AfterMake>
<RunUserProg1>1</RunUserProg1>
<RunUserProg2>1</RunUserProg2>
<UserProg1Name>fromelf.exe --bin -o "$L@L.bin" "#L"</UserProg1Name>
<UserProg2Name>makeimg.bat</UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopA1X>0</nStopA1X>
<nStopA2X>0</nStopA2X>
</AfterMake>
<SelectedForBatchBuild>0</SelectedForBatchBuild>
<SVCSIdString></SVCSIdString>
</TargetCommonOption>
<CommonProperty>
<UseCPPCompiler>0</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>1</IncludeInBuild>
<AlwaysBuild>0</AlwaysBuild>
<GenerateAssemblyFile>0</GenerateAssemblyFile>
<AssembleAssemblyFile>0</AssembleAssemblyFile>
<PublicsOnly>0</PublicsOnly>
<StopOnExitCode>3</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<DllOption>
<SimDllName>SARMCM3.DLL</SimDllName>
<SimDllArguments> -MPU</SimDllArguments>
<SimDlgDll>DCM.DLL</SimDlgDll>
<SimDlgDllArguments>-pCM3</SimDlgDllArguments>
<TargetDllName>SARMCM3.DLL</TargetDllName>
<TargetDllArguments> -MPU</TargetDllArguments>
<TargetDlgDll>TCM.DLL</TargetDlgDll>
<TargetDlgDllArguments>-pCM3</TargetDlgDllArguments>
</DllOption>
<DebugOption>
<OPTHX>
<HexSelection>1</HexSelection>
<HexRangeLowAddress>0</HexRangeLowAddress>
<HexRangeHighAddress>0</HexRangeHighAddress>
<HexOffset>0</HexOffset>
<Oh166RecLen>16</Oh166RecLen>
</OPTHX>
</DebugOption>
<Utilities>
<Flash1>
<UseTargetDll>1</UseTargetDll>
<UseExternalTool>0</UseExternalTool>
<RunIndependent>0</RunIndependent>
<UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
<Capability>1</Capability>
<DriverSelection>4096</DriverSelection>
</Flash1>
<bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3>"" ()</Flash3>
<Flash4></Flash4>
<pFcarmOut></pFcarmOut>
<pFcarmGrp></pFcarmGrp>
<pFcArmRoot></pFcArmRoot>
<FcArmLst>0</FcArmLst>
</Utilities>
<TargetArmAds>
<ArmAdsMisc>
<GenerateListings>0</GenerateListings>
<asHll>1</asHll>
<asAsm>1</asAsm>
<asMacX>1</asMacX>
<asSyms>1</asSyms>
<asFals>1</asFals>
<asDbgD>1</asDbgD>
<asForm>1</asForm>
<ldLst>0</ldLst>
<ldmm>1</ldmm>
<ldXref>1</ldXref>
<BigEnd>0</BigEnd>
<AdsALst>1</AdsALst>
<AdsACrf>1</AdsACrf>
<AdsANop>0</AdsANop>
<AdsANot>0</AdsANot>
<AdsLLst>1</AdsLLst>
<AdsLmap>1</AdsLmap>
<AdsLcgr>1</AdsLcgr>
<AdsLsym>1</AdsLsym>
<AdsLszi>1</AdsLszi>
<AdsLtoi>1</AdsLtoi>
<AdsLsun>1</AdsLsun>
<AdsLven>1</AdsLven>
<AdsLsxf>1</AdsLsxf>
<RvctClst>0</RvctClst>
<GenPPlst>0</GenPPlst>
<AdsCpuType>"Cortex-M3"</AdsCpuType>
<RvctDeviceName></RvctDeviceName>
<mOS>0</mOS>
<uocRom>0</uocRom>
<uocRam>0</uocRam>
<hadIROM>1</hadIROM>
<hadIRAM>1</hadIRAM>
<hadXRAM>0</hadXRAM>
<uocXRam>0</uocXRam>
<RvdsVP>0</RvdsVP>
<RvdsMve>0</RvdsMve>
<hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
<useUlib>0</useUlib>
<EndSel>1</EndSel>
<uLtcg>0</uLtcg>
<nSecure>0</nSecure>
<RoSelD>3</RoSelD>
<RwSelD>3</RwSelD>
<CodeSel>0</CodeSel>
<OptFeed>0</OptFeed>
<NoZi1>0</NoZi1>
<NoZi2>0</NoZi2>
<NoZi3>0</NoZi3>
<NoZi4>0</NoZi4>
<NoZi5>0</NoZi5>
<Ro1Chk>0</Ro1Chk>
<Ro2Chk>0</Ro2Chk>
<Ro3Chk>0</Ro3Chk>
<Ir1Chk>1</Ir1Chk>
<Ir2Chk>0</Ir2Chk>
<Ra1Chk>0</Ra1Chk>
<Ra2Chk>0</Ra2Chk>
<Ra3Chk>0</Ra3Chk>
<Im1Chk>1</Im1Chk>
<Im2Chk>0</Im2Chk>
<OnChipMemories>
<Ocm1>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm1>
<Ocm2>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm2>
<Ocm3>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm3>
<Ocm4>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm4>
<Ocm5>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm5>
<Ocm6>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm6>
<IRAM>
<Type>0</Type>
<StartAddress>0x20000000</StartAddress>
<Size>0x20000</Size>
</IRAM>
<IROM>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x40000</Size>
</IROM>
<XRAM>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</XRAM>
<OCR_RVCT1>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT1>
<OCR_RVCT2>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT2>
<OCR_RVCT3>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT3>
<OCR_RVCT4>
<Type>1</Type>
<StartAddress>0x8010100</StartAddress>
<Size>0xeff00</Size>
</OCR_RVCT4>
<OCR_RVCT5>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT5>
<OCR_RVCT6>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT6>
<OCR_RVCT7>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT7>
<OCR_RVCT8>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT8>
<OCR_RVCT9>
<Type>0</Type>
<StartAddress>0x20000000</StartAddress>
<Size>0x28000</Size>
</OCR_RVCT9>
<OCR_RVCT10>
<Type>0</Type>
<StartAddress>0x20028000</StartAddress>
<Size>0x20000</Size>
</OCR_RVCT10>
</OnChipMemories>
<RvctStartVector></RvctStartVector>
</ArmAdsMisc>
<Cads>
<interw>1</interw>
<Optim>1</Optim>
<oTime>0</oTime>
<SplitLS>0</SplitLS>
<OneElfS>1</OneElfS>
<Strict>0</Strict>
<EnumInt>0</EnumInt>
<PlainCh>0</PlainCh>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<wLevel>2</wLevel>
<uThumb>0</uThumb>
<uSurpInc>0</uSurpInc>
<uC99>1</uC99>
<uGnu>1</uGnu>
<useXO>0</useXO>
<v6Lang>1</v6Lang>
<v6LangP>1</v6LangP>
<vShortEn>1</vShortEn>
<vShortWch>1</vShortWch>
<v6Lto>0</v6Lto>
<v6WtE>0</v6WtE>
<v6Rtti>0</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\include;..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\include\armcc;..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\include\driver;..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\include\platform;..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\inc;..\..\BSP\Inc;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m3\armcc;..\..\..\..\kernel\core\include;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\TOS_CONFIG</IncludePath>
</VariousControls>
</Cads>
<Aads>
<interw>1</interw>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<thumb>0</thumb>
<SplitLS>0</SplitLS>
<SwStkChk>0</SwStkChk>
<NoWarn>0</NoWarn>
<uSurpInc>0</uSurpInc>
<useXO>0</useXO>
<uClangAs>0</uClangAs>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Aads>
<LDads>
<umfTarg>1</umfTarg>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<noStLib>0</noStLib>
<RepFail>1</RepFail>
<useFile>0</useFile>
<TextAddressRange>0x00000000</TextAddressRange>
<DataAddressRange>0x20000000</DataAddressRange>
<pXoBase></pXoBase>
<ScatterFile></ScatterFile>
<IncludeLibs></IncludeLibs>
<IncludeLibsPath></IncludeLibsPath>
<Misc></Misc>
<LinkerInputFile></LinkerInputFile>
<DisabledWarnings></DisabledWarnings>
</LDads>
</TargetArmAds>
</TargetOption>
<Groups>
<Group>
<GroupName>USER</GroupName>
<Files>
<File>
<FileName>beep.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\beep.c</FilePath>
</File>
<File>
<FileName>key.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\key.c</FilePath>
</File>
<File>
<FileName>led.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\led.c</FilePath>
</File>
<File>
<FileName>main.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\main.c</FilePath>
</File>
<File>
<FileName>sys.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\sys.c</FilePath>
</File>
<File>
<FileName>usart.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\usart.c</FilePath>
</File>
<File>
<FileName>dwt.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\dwt.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>WMLIB</GroupName>
<Files>
<File>
<FileName>misc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\boot\armcc\misc.c</FilePath>
</File>
<File>
<FileName>startup.s</FileName>
<FileType>2</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\boot\armcc\startup.s</FilePath>
</File>
<File>
<FileName>wm_cpu.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_cpu.c</FilePath>
</File>
<File>
<FileName>wm_gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_gpio.c</FilePath>
</File>
<File>
<FileName>wm_gpio_afsel.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_gpio_afsel.c</FilePath>
</File>
<File>
<FileName>wm_io.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_io.c</FilePath>
</File>
<File>
<FileName>wm_irq.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_irq.c</FilePath>
</File>
<File>
<FileName>wm_pmu.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_pmu.c</FilePath>
</File>
<File>
<FileName>wm_timer.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\WinnerMicro\w601\WMLIB\platform\drivers\wm_timer.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>tos/arch</GroupName>
<Files>
<File>
<FileName>tos_cpu.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\arch\arm\arm-v7m\common\tos_cpu.c</FilePath>
</File>
<File>
<FileName>port_c.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\arch\arm\arm-v7m\cortex-m3\armcc\port_c.c</FilePath>
</File>
<File>
<FileName>port_s.S</FileName>
<FileType>2</FileType>
<FilePath>..\..\..\..\arch\arm\arm-v7m\cortex-m3\armcc\port_s.S</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>tos/kernel</GroupName>
<Files>
<File>
<FileName>tos_event.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_event.c</FilePath>
</File>
<File>
<FileName>tos_fifo.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_fifo.c</FilePath>
</File>
<File>
<FileName>tos_global.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_global.c</FilePath>
</File>
<File>
<FileName>tos_mmblk.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_mmblk.c</FilePath>
</File>
<File>
<FileName>tos_mmheap.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_mmheap.c</FilePath>
</File>
<File>
<FileName>tos_msg.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_msg.c</FilePath>
</File>
<File>
<FileName>tos_mutex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_mutex.c</FilePath>
</File>
<File>
<FileName>tos_pend.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_pend.c</FilePath>
</File>
<File>
<FileName>tos_queue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_queue.c</FilePath>
</File>
<File>
<FileName>tos_robin.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_robin.c</FilePath>
</File>
<File>
<FileName>tos_sched.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_sched.c</FilePath>
</File>
<File>
<FileName>tos_sem.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_sem.c</FilePath>
</File>
<File>
<FileName>tos_sys.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_sys.c</FilePath>
</File>
<File>
<FileName>tos_task.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_task.c</FilePath>
</File>
<File>
<FileName>tos_tick.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_tick.c</FilePath>
</File>
<File>
<FileName>tos_time.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_time.c</FilePath>
</File>
<File>
<FileName>tos_timer.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_timer.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>tos/cmsis</GroupName>
<Files>
<File>
<FileName>cmsis_os.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\cmsis_os\cmsis_os.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>examples</GroupName>
<Files>
<File>
<FileName>hello_world.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\examples\hello_world\hello_world.c</FilePath>
</File>
</Files>
</Group>
</Groups>
</Target>
</Targets>
<RTE>
<apis/>
<components/>
<files/>
</RTE>
</Project>

View File

@@ -0,0 +1,31 @@
@rem <20><><EFBFBD><EFBFBD>0: exe
@rem <20><><EFBFBD><EFBFBD>1: <20><><EFBFBD><EFBFBD>bin<69>ļ<EFBFBD>ʼ<D4AD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
@rem <20><><EFBFBD><EFBFBD>2: <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>(Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
@rem <20><><EFBFBD><EFBFBD>3: <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>,0<>Ǿɲ<C7BE><C9B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>image<67>ļ<EFBFBD><C4BC><EFBFBD>3<EFBFBD><33><EFBFBD>²<EFBFBD><C2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>image<67>ļ<EFBFBD>
@rem <20><><EFBFBD><EFBFBD>4: <20>Ƿ<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>0<EFBFBD><30>plain<69>ļ<EFBFBD><C4BC><EFBFBD>1<EFBFBD><31>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
@rem <20><><EFBFBD><EFBFBD>5: <20><EFBFBD><E6B1BE><EFBFBD>ļ<EFBFBD>
@rem <20><><EFBFBD><EFBFBD>6<EFBFBD><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>FLASH<53><48><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD>
@rem <20><><EFBFBD><EFBFBD>7<EFBFBD><37><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD>
@rem <20><><EFBFBD><EFBFBD>8<EFBFBD><38>ԭʼbin<69>ļ<EFBFBD>
@echo off
@rem <20><><EFBFBD><EFBFBD>bin<69>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MDKħ<4B><C4A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>->Output->Name of Executable<6C><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
set PATH_NAME=TencentOS_tiny
@rem <20><><EFBFBD><EFBFBD>bin<69>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
set PATH_OUT=..\OBJ
@rem <20><><EFBFBD><EFBFBD>TOOLS·<53><C2B7>
set PATH_TOOLS=..\TOOLS
@rem <20><><EFBFBD><EFBFBD>BIN<49><4E><EFBFBD><EFBFBD>·<EFBFBD><C2B7>(<28><>W601<30><31><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ļ<EFBFBD>·<EFBFBD><C2B7>)
set PATH_BIN=..\BIN
copy %PATH_OUT%\%PATH_NAME%.bin %PATH_BIN%
cd %PATH_TOOLS%
copy %PATH_BIN%\version.txt %PATH_BIN%\version_bk.txt
makeimg.exe "%PATH_BIN%\%PATH_NAME%.bin" "%PATH_BIN%\%PATH_NAME%.img" 0 0 "%PATH_BIN%\version.txt" 90000 10100
makeimg_all.exe "%PATH_BIN%\secboot.img" "%PATH_BIN%\%PATH_NAME%.img" "%PATH_BIN%\%PATH_NAME%.FLS"
@del "%PATH_BIN%\%PATH_NAME%.img"

View File

@@ -0,0 +1,47 @@
#ifndef _TOS_CONFIG_H_
#define _TOS_CONFIG_H_
#include "sys.h"
#define TOS_CFG_TICKLESS_EN 0u
#define TOS_CFG_TASK_PRIO_MAX 10u
#define TOS_CFG_ROUND_ROBIN_EN 1u
#define TOS_CFG_OBJECT_VERIFY_EN 0u
#define TOS_CFG_EVENT_EN 1u
#define TOS_CFG_MMBLK_EN 1u
#define TOS_CFG_MMHEAP_EN 1u
#define TOS_CFG_MMHEAP_POOL_SIZE 0x1000
#define TOS_CFG_MUTEX_EN 1u
#define TOS_CFG_QUEUE_EN 1u
#define TOS_CFG_TIMER_EN 1u
#define TOS_CFG_SEM_EN 1u
#if (TOS_CFG_QUEUE_EN > 0u)
#define TOS_CFG_MSG_EN 1u
#else
#define TOS_CFG_MSG_EN 0u
#endif
#define TOS_CFG_MSG_POOL_SIZE 10u
#define TOS_CFG_IDLE_TASK_STK_SIZE 80u
#define TOS_CFG_CPU_TICK_PER_SECOND 1000u
#define TOS_CFG_CPU_CLOCK (80000000)
#define TOS_CFG_TIMER_AS_PROC 1u
#endif

View File

@@ -0,0 +1,98 @@
/* ----------------------------------------------------------------------
* Copyright (C) 2010-2013 ARM Limited. All rights reserved.
*
* $Date: 16. October 2013
* $Revision: V1.4.2
*
* Project: CMSIS DSP Library
* Title: arm_common_tables.h
*
* Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions
*
* Target Processor: Cortex-M4/Cortex-M3
*
* Redistribution and use 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 ARM LIMITED nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 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 _ARM_COMMON_TABLES_H
#define _ARM_COMMON_TABLES_H
#include "arm_math.h"
extern const uint16_t armBitRevTable[1024];
extern const q15_t armRecipTableQ15[64];
extern const q31_t armRecipTableQ31[64];
extern const q31_t realCoefAQ31[1024];
extern const q31_t realCoefBQ31[1024];
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];
#define twiddleCoef twiddleCoef_4096
extern const q31_t twiddleCoefQ31[6144];
extern const q15_t twiddleCoefQ15[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];
#define ARMBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 )
#define ARMBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 )
#define ARMBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 )
#define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
#define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
#define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
#define ARMBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800)
#define ARMBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808)
#define ARMBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032)
extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE__16_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE__32_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE__64_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE1024_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE2048_TABLE_LENGTH];
extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE4096_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];
#endif /* ARM_COMMON_TABLES_H */

View File

@@ -0,0 +1,59 @@
/* ----------------------------------------------------------------------
* Copyright (C) 2010-2013 ARM Limited. All rights reserved.
*
* $Date: 16. October 2013
* $Revision: V1.4.2
*
* Project: CMSIS DSP Library
* Title: arm_const_structs.h
*
* Description: This file has constant structs that are initialized for
* user convenience. For example, some can be given as
* arguments to the arm_cfft_f32() function.
*
* Target Processor: Cortex-M4/Cortex-M3
*
* Redistribution and use 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 ARM LIMITED nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 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 _ARM_CONST_STRUCTS_H
#define _ARM_CONST_STRUCTS_H
#include "arm_math.h"
#include "arm_common_tables.h"
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048;
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,702 @@
/**************************************************************************//**
* @file core_cm0.h
* @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File
* @version V3.30
* @date 17. February 2014
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2014 ARM LIMITED
All rights reserved.
Redistribution and use 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 ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
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 COPYRIGHT HOLDERS AND 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.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __CORE_CM0_H_GENERIC
#define __CORE_CM0_H_GENERIC
/** \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
CMSIS violates the following MISRA-C:2004 rules:
\li Required Rule 8.5, object/function definition in header file.<br>
Function definitions in header files are used to allow 'inlining'.
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
Unions are used for effective representation of core registers.
\li Advisory Rule 19.7, Function-like macro defined.<br>
Function-like macros are used to allow more efficient code.
*/
/*******************************************************************************
* CMSIS definitions
******************************************************************************/
/** \ingroup Cortex_M0
@{
*/
/* CMSIS CM0 definitions */
#define __CM0_CMSIS_VERSION_MAIN (0x03) /*!< [31:16] CMSIS HAL main version */
#define __CM0_CMSIS_VERSION_SUB (0x20) /*!< [15:0] CMSIS HAL sub version */
#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16) | \
__CM0_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
#define __CORTEX_M (0x00) /*!< Cortex-M Core */
#if defined ( __CC_ARM )
#define __ASM __asm /*!< asm keyword for ARM Compiler */
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
#define __STATIC_INLINE static __inline
#elif defined ( __GNUC__ )
#define __ASM __asm /*!< asm keyword for GNU Compiler */
#define __INLINE inline /*!< inline keyword for GNU Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __ICCARM__ )
#define __ASM __asm /*!< asm keyword for IAR Compiler */
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
#define __STATIC_INLINE static inline
#elif defined ( __TMS470__ )
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __TASKING__ )
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __CSMC__ ) /* Cosmic */
#define __packed
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
#define __INLINE inline /*use -pc99 on compile line !< inline keyword for COSMIC Compiler */
#define __STATIC_INLINE static inline
#endif
/** __FPU_USED indicates whether an FPU is used or not. This core does not support an FPU at all
*/
#define __FPU_USED 0
#if defined ( __CC_ARM )
#if defined __TARGET_FPU_VFP
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __GNUC__ )
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __ICCARM__ )
#if defined __ARMVFP__
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TMS470__ )
#if defined __TI__VFP_SUPPORT____
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TASKING__ )
#if defined __FPU_VFP__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __CSMC__ ) /* Cosmic */
#if ( __CSMC__ & 0x400) // FPU present for parser
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#endif
#include <stdint.h> /* standard types definitions */
#include <core_cmInstr.h> /* Core Instruction Access */
#include <core_cmFunc.h> /* Core Function Access */
#endif /* __CORE_CM0_H_GENERIC */
#ifndef __CMSIS_GENERIC
#ifndef __CORE_CM0_H_DEPENDANT
#define __CORE_CM0_H_DEPENDANT
/* check device defines and use defaults */
#if defined __CHECK_DEVICE_DEFINES
#ifndef __CM0_REV
#define __CM0_REV 0x0000
#warning "__CM0_REV not defined in device header file; using default!"
#endif
#ifndef __NVIC_PRIO_BITS
#define __NVIC_PRIO_BITS 2
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
#endif
#ifndef __Vendor_SysTickConfig
#define __Vendor_SysTickConfig 0
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
#endif
#endif
/* IO definitions (access restrictions to peripheral registers) */
/**
\defgroup CMSIS_glob_defs CMSIS Global Defines
<strong>IO Type Qualifiers</strong> are used
\li to specify the access to peripheral variables.
\li for automatic generation of peripheral register debug information.
*/
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/*@} end of group Cortex_M0 */
/*******************************************************************************
* Register Abstraction
Core Register contain:
- Core Register
- Core NVIC Register
- Core SCB Register
- Core SysTick Register
******************************************************************************/
/** \defgroup CMSIS_core_register Defines and Type Definitions
\brief Type definitions and defines for Cortex-M processor based devices.
*/
/** \ingroup CMSIS_core_register
\defgroup CMSIS_CORE Status and Control Registers
\brief Core Register type definitions.
@{
*/
/** \brief Union type to access the Application Program Status Register (APSR).
*/
typedef union
{
struct
{
#if (__CORTEX_M != 0x04)
uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */
#else
uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
#endif
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} APSR_Type;
/** \brief Union type to access the Interrupt Program Status Register (IPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} IPSR_Type;
/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
#if (__CORTEX_M != 0x04)
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
#else
uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
#endif
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} xPSR_Type;
/** \brief Union type to access the Control Registers (CONTROL).
*/
typedef union
{
struct
{
uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} CONTROL_Type;
/*@} end of group CMSIS_CORE */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
\brief Type definitions for the NVIC Registers
@{
*/
/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
*/
typedef struct
{
__IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
uint32_t RESERVED0[31];
__IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
uint32_t RSERVED1[31];
__IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
uint32_t RESERVED2[31];
__IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
uint32_t RESERVED3[31];
uint32_t RESERVED4[64];
__IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
} NVIC_Type;
/*@} end of group CMSIS_NVIC */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SCB System Control Block (SCB)
\brief Type definitions for the System Control Block Registers
@{
*/
/** \brief Structure type to access the System Control Block (SCB).
*/
typedef struct
{
__I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
__IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
uint32_t RESERVED0;
__IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
__IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
__IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
uint32_t RESERVED1;
__IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
__IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
} SCB_Type;
/* SCB CPUID Register Definitions */
#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
#define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */
/* SCB Interrupt Control State Register Definitions */
#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */
/* SCB Application Interrupt and Reset Control Register Definitions */
#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
/* SCB System Control Register Definitions */
#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
/* SCB Configuration Control Register Definitions */
#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
/* SCB System Handler Control and State Register Definitions */
#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
/*@} end of group CMSIS_SCB */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
\brief Type definitions for the System Timer Registers.
@{
*/
/** \brief Structure type to access the System Timer (SysTick).
*/
typedef struct
{
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
/* SysTick Control / Status Register Definitions */
#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
#define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
/* SysTick Reload Register Definitions */
#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
/* SysTick Current Register Definitions */
#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
/* SysTick Calibration Register Definitions */
#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */
/*@} end of group CMSIS_SysTick */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
\brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR)
are only accessible over DAP and not via processor. Therefore
they are not covered by the Cortex-M0 header file.
@{
*/
/*@} end of group CMSIS_CoreDebug */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_core_base Core Definitions
\brief Definitions for base addresses, unions, and structures.
@{
*/
/* Memory mapping of Cortex-M0 Hardware */
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
/*@} */
/*******************************************************************************
* Hardware Abstraction Layer
Core Function Interface contains:
- Core NVIC Functions
- Core SysTick Functions
- Core Register Access Functions
******************************************************************************/
/** \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
*/
/* ########################## NVIC functions #################################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
\brief Functions that manage interrupts and exceptions via the NVIC.
@{
*/
/* Interrupt Priorities are WORD accessible only under ARMv6M */
/* The following MACROS handle generation of the register offset and byte masks */
#define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 )
#define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) )
#define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) )
/** \brief Enable External Interrupt
The function enables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Disable External Interrupt
The function disables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
{
NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Get Pending Interrupt
The function reads the pending register in the NVIC and returns the pending bit
for the specified interrupt.
\param [in] IRQn Interrupt number.
\return 0 Interrupt status is not pending.
\return 1 Interrupt status is pending.
*/
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
}
/** \brief Set Pending Interrupt
The function sets the pending bit of an external interrupt.
\param [in] IRQn Interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Clear Pending Interrupt
The function clears the pending bit of an external interrupt.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
}
/** \brief Set Interrupt Priority
The function sets the priority of an interrupt.
\note The priority cannot be set for every core interrupt.
\param [in] IRQn Interrupt number.
\param [in] priority Priority to set.
*/
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if(IRQn < 0) {
SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
else {
NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
}
/** \brief Get Interrupt Priority
The function reads the priority of an interrupt. The interrupt
number can be positive to specify an external (device specific)
interrupt, or negative to specify an internal (core) interrupt.
\param [in] IRQn Interrupt number.
\return Interrupt Priority. Value is aligned automatically to the implemented
priority bits of the microcontroller.
*/
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
{
if(IRQn < 0) {
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */
else {
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
}
/** \brief System Reset
The function initiates a system reset request to reset the MCU.
*/
__STATIC_INLINE void NVIC_SystemReset(void)
{
__DSB(); /* Ensure all outstanding memory accesses included
buffered write are completed before reset */
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
SCB_AIRCR_SYSRESETREQ_Msk);
__DSB(); /* Ensure completion of memory access */
while(1); /* wait until reset */
}
/*@} end of CMSIS_Core_NVICFunctions */
/* ################################## SysTick function ############################################ */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
\brief Functions that configure the System.
@{
*/
#if (__Vendor_SysTickConfig == 0)
/** \brief System Tick Configuration
The function initializes the System Timer and its interrupt, and starts the System Tick Timer.
Counter is in free running mode to generate periodic interrupts.
\param [in] ticks Number of ticks between two interrupts.
\return 0 Function succeeded.
\return 1 Function failed.
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
SysTick->LOAD = ticks - 1; /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */
SysTick->VAL = 0; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0); /* Function successful */
}
#endif
/*@} end of CMSIS_Core_SysTickFunctions */
#endif /* __CORE_CM0_H_DEPENDANT */
#endif /* __CMSIS_GENERIC */
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,813 @@
/**************************************************************************//**
* @file core_cm0plus.h
* @brief CMSIS Cortex-M0+ Core Peripheral Access Layer Header File
* @version V3.30
* @date 17. February 2014
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2014 ARM LIMITED
All rights reserved.
Redistribution and use 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 ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
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 COPYRIGHT HOLDERS AND 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.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __CORE_CM0PLUS_H_GENERIC
#define __CORE_CM0PLUS_H_GENERIC
/** \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
CMSIS violates the following MISRA-C:2004 rules:
\li Required Rule 8.5, object/function definition in header file.<br>
Function definitions in header files are used to allow 'inlining'.
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
Unions are used for effective representation of core registers.
\li Advisory Rule 19.7, Function-like macro defined.<br>
Function-like macros are used to allow more efficient code.
*/
/*******************************************************************************
* CMSIS definitions
******************************************************************************/
/** \ingroup Cortex-M0+
@{
*/
/* CMSIS CM0P definitions */
#define __CM0PLUS_CMSIS_VERSION_MAIN (0x03) /*!< [31:16] CMSIS HAL main version */
#define __CM0PLUS_CMSIS_VERSION_SUB (0x20) /*!< [15:0] CMSIS HAL sub version */
#define __CM0PLUS_CMSIS_VERSION ((__CM0PLUS_CMSIS_VERSION_MAIN << 16) | \
__CM0PLUS_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */
#define __CORTEX_M (0x00) /*!< Cortex-M Core */
#if defined ( __CC_ARM )
#define __ASM __asm /*!< asm keyword for ARM Compiler */
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
#define __STATIC_INLINE static __inline
#elif defined ( __GNUC__ )
#define __ASM __asm /*!< asm keyword for GNU Compiler */
#define __INLINE inline /*!< inline keyword for GNU Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __ICCARM__ )
#define __ASM __asm /*!< asm keyword for IAR Compiler */
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
#define __STATIC_INLINE static inline
#elif defined ( __TMS470__ )
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __TASKING__ )
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __CSMC__ ) /* Cosmic */
#define __packed
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
#define __INLINE inline /*use -pc99 on compile line !< inline keyword for COSMIC Compiler */
#define __STATIC_INLINE static inline
#endif
/** __FPU_USED indicates whether an FPU is used or not. This core does not support an FPU at all
*/
#define __FPU_USED 0
#if defined ( __CC_ARM )
#if defined __TARGET_FPU_VFP
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __GNUC__ )
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __ICCARM__ )
#if defined __ARMVFP__
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TMS470__ )
#if defined __TI__VFP_SUPPORT____
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TASKING__ )
#if defined __FPU_VFP__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __CSMC__ ) /* Cosmic */
#if ( __CSMC__ & 0x400) // FPU present for parser
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#endif
#include <stdint.h> /* standard types definitions */
#include <core_cmInstr.h> /* Core Instruction Access */
#include <core_cmFunc.h> /* Core Function Access */
#endif /* __CORE_CM0PLUS_H_GENERIC */
#ifndef __CMSIS_GENERIC
#ifndef __CORE_CM0PLUS_H_DEPENDANT
#define __CORE_CM0PLUS_H_DEPENDANT
/* check device defines and use defaults */
#if defined __CHECK_DEVICE_DEFINES
#ifndef __CM0PLUS_REV
#define __CM0PLUS_REV 0x0000
#warning "__CM0PLUS_REV not defined in device header file; using default!"
#endif
#ifndef __MPU_PRESENT
#define __MPU_PRESENT 0
#warning "__MPU_PRESENT not defined in device header file; using default!"
#endif
#ifndef __VTOR_PRESENT
#define __VTOR_PRESENT 0
#warning "__VTOR_PRESENT not defined in device header file; using default!"
#endif
#ifndef __NVIC_PRIO_BITS
#define __NVIC_PRIO_BITS 2
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
#endif
#ifndef __Vendor_SysTickConfig
#define __Vendor_SysTickConfig 0
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
#endif
#endif
/* IO definitions (access restrictions to peripheral registers) */
/**
\defgroup CMSIS_glob_defs CMSIS Global Defines
<strong>IO Type Qualifiers</strong> are used
\li to specify the access to peripheral variables.
\li for automatic generation of peripheral register debug information.
*/
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/*@} end of group Cortex-M0+ */
/*******************************************************************************
* Register Abstraction
Core Register contain:
- Core Register
- Core NVIC Register
- Core SCB Register
- Core SysTick Register
- Core MPU Register
******************************************************************************/
/** \defgroup CMSIS_core_register Defines and Type Definitions
\brief Type definitions and defines for Cortex-M processor based devices.
*/
/** \ingroup CMSIS_core_register
\defgroup CMSIS_CORE Status and Control Registers
\brief Core Register type definitions.
@{
*/
/** \brief Union type to access the Application Program Status Register (APSR).
*/
typedef union
{
struct
{
#if (__CORTEX_M != 0x04)
uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */
#else
uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
#endif
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} APSR_Type;
/** \brief Union type to access the Interrupt Program Status Register (IPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} IPSR_Type;
/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
#if (__CORTEX_M != 0x04)
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
#else
uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
#endif
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} xPSR_Type;
/** \brief Union type to access the Control Registers (CONTROL).
*/
typedef union
{
struct
{
uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} CONTROL_Type;
/*@} end of group CMSIS_CORE */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
\brief Type definitions for the NVIC Registers
@{
*/
/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
*/
typedef struct
{
__IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
uint32_t RESERVED0[31];
__IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
uint32_t RSERVED1[31];
__IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
uint32_t RESERVED2[31];
__IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
uint32_t RESERVED3[31];
uint32_t RESERVED4[64];
__IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
} NVIC_Type;
/*@} end of group CMSIS_NVIC */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SCB System Control Block (SCB)
\brief Type definitions for the System Control Block Registers
@{
*/
/** \brief Structure type to access the System Control Block (SCB).
*/
typedef struct
{
__I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
__IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
#if (__VTOR_PRESENT == 1)
__IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
#else
uint32_t RESERVED0;
#endif
__IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
__IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
__IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
uint32_t RESERVED1;
__IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
__IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
} SCB_Type;
/* SCB CPUID Register Definitions */
#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
#define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */
/* SCB Interrupt Control State Register Definitions */
#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */
#if (__VTOR_PRESENT == 1)
/* SCB Interrupt Control State Register Definitions */
#define SCB_VTOR_TBLOFF_Pos 8 /*!< SCB VTOR: TBLOFF Position */
#define SCB_VTOR_TBLOFF_Msk (0xFFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
#endif
/* SCB Application Interrupt and Reset Control Register Definitions */
#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
/* SCB System Control Register Definitions */
#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
/* SCB Configuration Control Register Definitions */
#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
/* SCB System Handler Control and State Register Definitions */
#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
/*@} end of group CMSIS_SCB */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
\brief Type definitions for the System Timer Registers.
@{
*/
/** \brief Structure type to access the System Timer (SysTick).
*/
typedef struct
{
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
/* SysTick Control / Status Register Definitions */
#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
#define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
/* SysTick Reload Register Definitions */
#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
/* SysTick Current Register Definitions */
#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
/* SysTick Calibration Register Definitions */
#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */
/*@} end of group CMSIS_SysTick */
#if (__MPU_PRESENT == 1)
/** \ingroup CMSIS_core_register
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
\brief Type definitions for the Memory Protection Unit (MPU)
@{
*/
/** \brief Structure type to access the Memory Protection Unit (MPU).
*/
typedef struct
{
__I uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */
__IO uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */
__IO uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */
__IO uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */
__IO uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
} MPU_Type;
/* MPU Type Register */
#define MPU_TYPE_IREGION_Pos 16 /*!< MPU TYPE: IREGION Position */
#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
#define MPU_TYPE_DREGION_Pos 8 /*!< MPU TYPE: DREGION Position */
#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */
#define MPU_TYPE_SEPARATE_Pos 0 /*!< MPU TYPE: SEPARATE Position */
#define MPU_TYPE_SEPARATE_Msk (1UL << MPU_TYPE_SEPARATE_Pos) /*!< MPU TYPE: SEPARATE Mask */
/* MPU Control Register */
#define MPU_CTRL_PRIVDEFENA_Pos 2 /*!< MPU CTRL: PRIVDEFENA Position */
#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */
#define MPU_CTRL_HFNMIENA_Pos 1 /*!< MPU CTRL: HFNMIENA Position */
#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */
#define MPU_CTRL_ENABLE_Pos 0 /*!< MPU CTRL: ENABLE Position */
#define MPU_CTRL_ENABLE_Msk (1UL << MPU_CTRL_ENABLE_Pos) /*!< MPU CTRL: ENABLE Mask */
/* MPU Region Number Register */
#define MPU_RNR_REGION_Pos 0 /*!< MPU RNR: REGION Position */
#define MPU_RNR_REGION_Msk (0xFFUL << MPU_RNR_REGION_Pos) /*!< MPU RNR: REGION Mask */
/* MPU Region Base Address Register */
#define MPU_RBAR_ADDR_Pos 8 /*!< MPU RBAR: ADDR Position */
#define MPU_RBAR_ADDR_Msk (0xFFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */
#define MPU_RBAR_VALID_Pos 4 /*!< MPU RBAR: VALID Position */
#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */
#define MPU_RBAR_REGION_Pos 0 /*!< MPU RBAR: REGION Position */
#define MPU_RBAR_REGION_Msk (0xFUL << MPU_RBAR_REGION_Pos) /*!< MPU RBAR: REGION Mask */
/* MPU Region Attribute and Size Register */
#define MPU_RASR_ATTRS_Pos 16 /*!< MPU RASR: MPU Region Attribute field Position */
#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */
#define MPU_RASR_XN_Pos 28 /*!< MPU RASR: ATTRS.XN Position */
#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */
#define MPU_RASR_AP_Pos 24 /*!< MPU RASR: ATTRS.AP Position */
#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */
#define MPU_RASR_TEX_Pos 19 /*!< MPU RASR: ATTRS.TEX Position */
#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */
#define MPU_RASR_S_Pos 18 /*!< MPU RASR: ATTRS.S Position */
#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */
#define MPU_RASR_C_Pos 17 /*!< MPU RASR: ATTRS.C Position */
#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */
#define MPU_RASR_B_Pos 16 /*!< MPU RASR: ATTRS.B Position */
#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */
#define MPU_RASR_SRD_Pos 8 /*!< MPU RASR: Sub-Region Disable Position */
#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */
#define MPU_RASR_SIZE_Pos 1 /*!< MPU RASR: Region Size Field Position */
#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */
#define MPU_RASR_ENABLE_Pos 0 /*!< MPU RASR: Region enable bit Position */
#define MPU_RASR_ENABLE_Msk (1UL << MPU_RASR_ENABLE_Pos) /*!< MPU RASR: Region enable bit Disable Mask */
/*@} end of group CMSIS_MPU */
#endif
/** \ingroup CMSIS_core_register
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
\brief Cortex-M0+ Core Debug Registers (DCB registers, SHCSR, and DFSR)
are only accessible over DAP and not via processor. Therefore
they are not covered by the Cortex-M0 header file.
@{
*/
/*@} end of group CMSIS_CoreDebug */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_core_base Core Definitions
\brief Definitions for base addresses, unions, and structures.
@{
*/
/* Memory mapping of Cortex-M0+ Hardware */
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
#if (__MPU_PRESENT == 1)
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
#endif
/*@} */
/*******************************************************************************
* Hardware Abstraction Layer
Core Function Interface contains:
- Core NVIC Functions
- Core SysTick Functions
- Core Register Access Functions
******************************************************************************/
/** \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
*/
/* ########################## NVIC functions #################################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
\brief Functions that manage interrupts and exceptions via the NVIC.
@{
*/
/* Interrupt Priorities are WORD accessible only under ARMv6M */
/* The following MACROS handle generation of the register offset and byte masks */
#define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 )
#define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) )
#define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) )
/** \brief Enable External Interrupt
The function enables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Disable External Interrupt
The function disables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
{
NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Get Pending Interrupt
The function reads the pending register in the NVIC and returns the pending bit
for the specified interrupt.
\param [in] IRQn Interrupt number.
\return 0 Interrupt status is not pending.
\return 1 Interrupt status is pending.
*/
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
}
/** \brief Set Pending Interrupt
The function sets the pending bit of an external interrupt.
\param [in] IRQn Interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Clear Pending Interrupt
The function clears the pending bit of an external interrupt.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
}
/** \brief Set Interrupt Priority
The function sets the priority of an interrupt.
\note The priority cannot be set for every core interrupt.
\param [in] IRQn Interrupt number.
\param [in] priority Priority to set.
*/
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if(IRQn < 0) {
SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
else {
NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
}
/** \brief Get Interrupt Priority
The function reads the priority of an interrupt. The interrupt
number can be positive to specify an external (device specific)
interrupt, or negative to specify an internal (core) interrupt.
\param [in] IRQn Interrupt number.
\return Interrupt Priority. Value is aligned automatically to the implemented
priority bits of the microcontroller.
*/
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
{
if(IRQn < 0) {
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */
else {
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
}
/** \brief System Reset
The function initiates a system reset request to reset the MCU.
*/
__STATIC_INLINE void NVIC_SystemReset(void)
{
__DSB(); /* Ensure all outstanding memory accesses included
buffered write are completed before reset */
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
SCB_AIRCR_SYSRESETREQ_Msk);
__DSB(); /* Ensure completion of memory access */
while(1); /* wait until reset */
}
/*@} end of CMSIS_Core_NVICFunctions */
/* ################################## SysTick function ############################################ */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
\brief Functions that configure the System.
@{
*/
#if (__Vendor_SysTickConfig == 0)
/** \brief System Tick Configuration
The function initializes the System Timer and its interrupt, and starts the System Tick Timer.
Counter is in free running mode to generate periodic interrupts.
\param [in] ticks Number of ticks between two interrupts.
\return 0 Function succeeded.
\return 1 Function failed.
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
SysTick->LOAD = ticks - 1; /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */
SysTick->VAL = 0; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0); /* Function successful */
}
#endif
/*@} end of CMSIS_Core_SysTickFunctions */
#endif /* __CORE_CM0PLUS_H_DEPENDANT */
#endif /* __CMSIS_GENERIC */
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,697 @@
/**************************************************************************//**
* @file core_cm4_simd.h
* @brief CMSIS Cortex-M4 SIMD Header File
* @version V3.30
* @date 17. February 2014
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2014 ARM LIMITED
All rights reserved.
Redistribution and use 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 ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
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 COPYRIGHT HOLDERS AND 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.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#endif
#ifndef __CORE_CM4_SIMD_H
#define __CORE_CM4_SIMD_H
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* Hardware Abstraction Layer
******************************************************************************/
/* ################### Compiler specific Intrinsics ########################### */
/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
Access to dedicated SIMD instructions
@{
*/
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
/* ARM armcc specific functions */
#define __SADD8 __sadd8
#define __QADD8 __qadd8
#define __SHADD8 __shadd8
#define __UADD8 __uadd8
#define __UQADD8 __uqadd8
#define __UHADD8 __uhadd8
#define __SSUB8 __ssub8
#define __QSUB8 __qsub8
#define __SHSUB8 __shsub8
#define __USUB8 __usub8
#define __UQSUB8 __uqsub8
#define __UHSUB8 __uhsub8
#define __SADD16 __sadd16
#define __QADD16 __qadd16
#define __SHADD16 __shadd16
#define __UADD16 __uadd16
#define __UQADD16 __uqadd16
#define __UHADD16 __uhadd16
#define __SSUB16 __ssub16
#define __QSUB16 __qsub16
#define __SHSUB16 __shsub16
#define __USUB16 __usub16
#define __UQSUB16 __uqsub16
#define __UHSUB16 __uhsub16
#define __SASX __sasx
#define __QASX __qasx
#define __SHASX __shasx
#define __UASX __uasx
#define __UQASX __uqasx
#define __UHASX __uhasx
#define __SSAX __ssax
#define __QSAX __qsax
#define __SHSAX __shsax
#define __USAX __usax
#define __UQSAX __uqsax
#define __UHSAX __uhsax
#define __USAD8 __usad8
#define __USADA8 __usada8
#define __SSAT16 __ssat16
#define __USAT16 __usat16
#define __UXTB16 __uxtb16
#define __UXTAB16 __uxtab16
#define __SXTB16 __sxtb16
#define __SXTAB16 __sxtab16
#define __SMUAD __smuad
#define __SMUADX __smuadx
#define __SMLAD __smlad
#define __SMLADX __smladx
#define __SMLALD __smlald
#define __SMLALDX __smlaldx
#define __SMUSD __smusd
#define __SMUSDX __smusdx
#define __SMLSD __smlsd
#define __SMLSDX __smlsdx
#define __SMLSLD __smlsld
#define __SMLSLDX __smlsldx
#define __SEL __sel
#define __QADD __qadd
#define __QSUB __qsub
#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
((int64_t)(ARG3) << 32) ) >> 32))
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
/* GNU gcc specific functions */
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
{
uint32_t result;
__ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
return(result);
}
#define __SSAT16(ARG1,ARG2) \
({ \
uint32_t __RES, __ARG1 = (ARG1); \
__ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
__RES; \
})
#define __USAT16(ARG1,ARG2) \
({ \
uint32_t __RES, __ARG1 = (ARG1); \
__ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
__RES; \
})
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1)
{
uint32_t result;
__ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1)
{
uint32_t result;
__ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
{
uint32_t result;
__ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
{
uint32_t result;
__ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
{
union llreg_u{
uint32_t w32[2];
uint64_t w64;
} llr;
llr.w64 = acc;
#ifndef __ARMEB__ // Little endian
__ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
#else // Big endian
__ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
#endif
return(llr.w64);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
{
union llreg_u{
uint32_t w32[2];
uint64_t w64;
} llr;
llr.w64 = acc;
#ifndef __ARMEB__ // Little endian
__ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
#else // Big endian
__ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
#endif
return(llr.w64);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
{
uint32_t result;
__ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
{
uint32_t result;
__ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
{
union llreg_u{
uint32_t w32[2];
uint64_t w64;
} llr;
llr.w64 = acc;
#ifndef __ARMEB__ // Little endian
__ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
#else // Big endian
__ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
#endif
return(llr.w64);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
{
union llreg_u{
uint32_t w32[2];
uint64_t w64;
} llr;
llr.w64 = acc;
#ifndef __ARMEB__ // Little endian
__ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
#else // Big endian
__ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
#endif
return(llr.w64);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
return(result);
}
#define __PKHBT(ARG1,ARG2,ARG3) \
({ \
uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
__ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
__RES; \
})
#define __PKHTB(ARG1,ARG2,ARG3) \
({ \
uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
if (ARG3 == 0) \
__ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
else \
__ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
__RES; \
})
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
{
int32_t result;
__ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
return(result);
}
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
/* IAR iccarm specific functions */
#include <cmsis_iar.h>
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
/* TI CCS specific functions */
#include <cmsis_ccs.h>
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
/* TASKING carm specific functions */
/* not yet supported */
#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/
/* Cosmic specific functions */
#include <cmsis_csm.h>
#endif
/*@} end of group CMSIS_SIMD_intrinsics */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_CM4_SIMD_H */

View File

@@ -0,0 +1,637 @@
/**************************************************************************//**
* @file core_cmFunc.h
* @brief CMSIS Cortex-M Core Function Access Header File
* @version V3.30
* @date 17. February 2014
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2014 ARM LIMITED
All rights reserved.
Redistribution and use 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 ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
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 COPYRIGHT HOLDERS AND 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 __CORE_CMFUNC_H
#define __CORE_CMFUNC_H
/* ########################### Core Function Access ########################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
@{
*/
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
/* ARM armcc specific functions */
#if (__ARMCC_VERSION < 400677)
#error "Please use ARM Compiler Toolchain V4.0.677 or later!"
#endif
/* intrinsic void __enable_irq(); */
/* intrinsic void __disable_irq(); */
/** \brief Get Control Register
This function returns the content of the Control Register.
\return Control Register value
*/
__STATIC_INLINE uint32_t __get_CONTROL(void)
{
register uint32_t __regControl __ASM("control");
return(__regControl);
}
/** \brief Set Control Register
This function writes the given value to the Control Register.
\param [in] control Control Register value to set
*/
__STATIC_INLINE void __set_CONTROL(uint32_t control)
{
register uint32_t __regControl __ASM("control");
__regControl = control;
}
/** \brief Get IPSR Register
This function returns the content of the IPSR Register.
\return IPSR Register value
*/
__STATIC_INLINE uint32_t __get_IPSR(void)
{
register uint32_t __regIPSR __ASM("ipsr");
return(__regIPSR);
}
/** \brief Get APSR Register
This function returns the content of the APSR Register.
\return APSR Register value
*/
__STATIC_INLINE uint32_t __get_APSR(void)
{
register uint32_t __regAPSR __ASM("apsr");
return(__regAPSR);
}
/** \brief Get xPSR Register
This function returns the content of the xPSR Register.
\return xPSR Register value
*/
__STATIC_INLINE uint32_t __get_xPSR(void)
{
register uint32_t __regXPSR __ASM("xpsr");
return(__regXPSR);
}
/** \brief Get Process Stack Pointer
This function returns the current value of the Process Stack Pointer (PSP).
\return PSP Register value
*/
__STATIC_INLINE uint32_t __get_PSP(void)
{
register uint32_t __regProcessStackPointer __ASM("psp");
return(__regProcessStackPointer);
}
/** \brief Set Process Stack Pointer
This function assigns the given value to the Process Stack Pointer (PSP).
\param [in] topOfProcStack Process Stack Pointer value to set
*/
__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
{
register uint32_t __regProcessStackPointer __ASM("psp");
__regProcessStackPointer = topOfProcStack;
}
/** \brief Get Main Stack Pointer
This function returns the current value of the Main Stack Pointer (MSP).
\return MSP Register value
*/
__STATIC_INLINE uint32_t __get_MSP(void)
{
register uint32_t __regMainStackPointer __ASM("msp");
return(__regMainStackPointer);
}
/** \brief Set Main Stack Pointer
This function assigns the given value to the Main Stack Pointer (MSP).
\param [in] topOfMainStack Main Stack Pointer value to set
*/
__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
{
register uint32_t __regMainStackPointer __ASM("msp");
__regMainStackPointer = topOfMainStack;
}
/** \brief Get Priority Mask
This function returns the current state of the priority mask bit from the Priority Mask Register.
\return Priority Mask value
*/
__STATIC_INLINE uint32_t __get_PRIMASK(void)
{
register uint32_t __regPriMask __ASM("primask");
return(__regPriMask);
}
/** \brief Set Priority Mask
This function assigns the given value to the Priority Mask Register.
\param [in] priMask Priority Mask
*/
__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
{
register uint32_t __regPriMask __ASM("primask");
__regPriMask = (priMask);
}
#if (__CORTEX_M >= 0x03)
/** \brief Enable FIQ
This function enables FIQ interrupts by clearing the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
#define __enable_fault_irq __enable_fiq
/** \brief Disable FIQ
This function disables FIQ interrupts by setting the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
#define __disable_fault_irq __disable_fiq
/** \brief Get Base Priority
This function returns the current value of the Base Priority register.
\return Base Priority register value
*/
__STATIC_INLINE uint32_t __get_BASEPRI(void)
{
register uint32_t __regBasePri __ASM("basepri");
return(__regBasePri);
}
/** \brief Set Base Priority
This function assigns the given value to the Base Priority register.
\param [in] basePri Base Priority value to set
*/
__STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
{
register uint32_t __regBasePri __ASM("basepri");
__regBasePri = (basePri & 0xff);
}
/** \brief Get Fault Mask
This function returns the current value of the Fault Mask register.
\return Fault Mask register value
*/
__STATIC_INLINE uint32_t __get_FAULTMASK(void)
{
register uint32_t __regFaultMask __ASM("faultmask");
return(__regFaultMask);
}
/** \brief Set Fault Mask
This function assigns the given value to the Fault Mask register.
\param [in] faultMask Fault Mask value to set
*/
__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
{
register uint32_t __regFaultMask __ASM("faultmask");
__regFaultMask = (faultMask & (uint32_t)1);
}
#endif /* (__CORTEX_M >= 0x03) */
#if (__CORTEX_M == 0x04)
/** \brief Get FPSCR
This function returns the current value of the Floating Point Status/Control register.
\return Floating Point Status/Control register value
*/
__STATIC_INLINE uint32_t __get_FPSCR(void)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
register uint32_t __regfpscr __ASM("fpscr");
return(__regfpscr);
#else
return(0);
#endif
}
/** \brief Set FPSCR
This function assigns the given value to the Floating Point Status/Control register.
\param [in] fpscr Floating Point Status/Control value to set
*/
__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
register uint32_t __regfpscr __ASM("fpscr");
__regfpscr = (fpscr);
#endif
}
#endif /* (__CORTEX_M == 0x04) */
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
/* GNU gcc specific functions */
/** \brief Enable IRQ Interrupts
This function enables IRQ interrupts by clearing the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
{
__ASM volatile ("cpsie i" : : : "memory");
}
/** \brief Disable IRQ Interrupts
This function disables IRQ interrupts by setting the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
{
__ASM volatile ("cpsid i" : : : "memory");
}
/** \brief Get Control Register
This function returns the content of the Control Register.
\return Control Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void)
{
uint32_t result;
__ASM volatile ("MRS %0, control" : "=r" (result) );
return(result);
}
/** \brief Set Control Register
This function writes the given value to the Control Register.
\param [in] control Control Register value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control)
{
__ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
}
/** \brief Get IPSR Register
This function returns the content of the IPSR Register.
\return IPSR Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void)
{
uint32_t result;
__ASM volatile ("MRS %0, ipsr" : "=r" (result) );
return(result);
}
/** \brief Get APSR Register
This function returns the content of the APSR Register.
\return APSR Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
{
uint32_t result;
__ASM volatile ("MRS %0, apsr" : "=r" (result) );
return(result);
}
/** \brief Get xPSR Register
This function returns the content of the xPSR Register.
\return xPSR Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void)
{
uint32_t result;
__ASM volatile ("MRS %0, xpsr" : "=r" (result) );
return(result);
}
/** \brief Get Process Stack Pointer
This function returns the current value of the Process Stack Pointer (PSP).
\return PSP Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
{
register uint32_t result;
__ASM volatile ("MRS %0, psp\n" : "=r" (result) );
return(result);
}
/** \brief Set Process Stack Pointer
This function assigns the given value to the Process Stack Pointer (PSP).
\param [in] topOfProcStack Process Stack Pointer value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
{
__ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp");
}
/** \brief Get Main Stack Pointer
This function returns the current value of the Main Stack Pointer (MSP).
\return MSP Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
{
register uint32_t result;
__ASM volatile ("MRS %0, msp\n" : "=r" (result) );
return(result);
}
/** \brief Set Main Stack Pointer
This function assigns the given value to the Main Stack Pointer (MSP).
\param [in] topOfMainStack Main Stack Pointer value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
{
__ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
}
/** \brief Get Priority Mask
This function returns the current state of the priority mask bit from the Priority Mask Register.
\return Priority Mask value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void)
{
uint32_t result;
__ASM volatile ("MRS %0, primask" : "=r" (result) );
return(result);
}
/** \brief Set Priority Mask
This function assigns the given value to the Priority Mask Register.
\param [in] priMask Priority Mask
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
{
__ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
}
#if (__CORTEX_M >= 0x03)
/** \brief Enable FIQ
This function enables FIQ interrupts by clearing the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void)
{
__ASM volatile ("cpsie f" : : : "memory");
}
/** \brief Disable FIQ
This function disables FIQ interrupts by setting the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void)
{
__ASM volatile ("cpsid f" : : : "memory");
}
/** \brief Get Base Priority
This function returns the current value of the Base Priority register.
\return Base Priority register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void)
{
uint32_t result;
__ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
return(result);
}
/** \brief Set Base Priority
This function assigns the given value to the Base Priority register.
\param [in] basePri Base Priority value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
{
__ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory");
}
/** \brief Get Fault Mask
This function returns the current value of the Fault Mask register.
\return Fault Mask register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
{
uint32_t result;
__ASM volatile ("MRS %0, faultmask" : "=r" (result) );
return(result);
}
/** \brief Set Fault Mask
This function assigns the given value to the Fault Mask register.
\param [in] faultMask Fault Mask value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
{
__ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
}
#endif /* (__CORTEX_M >= 0x03) */
#if (__CORTEX_M == 0x04)
/** \brief Get FPSCR
This function returns the current value of the Floating Point Status/Control register.
\return Floating Point Status/Control register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
uint32_t result;
/* Empty asm statement works as a scheduling barrier */
__ASM volatile ("");
__ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
__ASM volatile ("");
return(result);
#else
return(0);
#endif
}
/** \brief Set FPSCR
This function assigns the given value to the Floating Point Status/Control register.
\param [in] fpscr Floating Point Status/Control value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
/* Empty asm statement works as a scheduling barrier */
__ASM volatile ("");
__ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc");
__ASM volatile ("");
#endif
}
#endif /* (__CORTEX_M == 0x04) */
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
/* IAR iccarm specific functions */
#include <cmsis_iar.h>
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
/* TI CCS specific functions */
#include <cmsis_ccs.h>
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
/* TASKING carm specific functions */
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/
/* Cosmic specific functions */
#include <cmsis_csm.h>
#endif
/*@} end of CMSIS_Core_RegAccFunctions */
#endif /* __CORE_CMFUNC_H */

View File

@@ -0,0 +1,687 @@
/**************************************************************************//**
* @file core_cmInstr.h
* @brief CMSIS Cortex-M Core Instruction Access Header File
* @version V3.30
* @date 17. February 2014
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2014 ARM LIMITED
All rights reserved.
Redistribution and use 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 ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
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 COPYRIGHT HOLDERS AND 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 __CORE_CMINSTR_H
#define __CORE_CMINSTR_H
/* ########################## Core Instruction Access ######################### */
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
Access to dedicated instructions
@{
*/
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
/* ARM armcc specific functions */
#if (__ARMCC_VERSION < 400677)
#error "Please use ARM Compiler Toolchain V4.0.677 or later!"
#endif
/** \brief No Operation
No Operation does nothing. This instruction can be used for code alignment purposes.
*/
#define __NOP __nop
/** \brief Wait For Interrupt
Wait For Interrupt is a hint instruction that suspends execution
until one of a number of events occurs.
*/
#define __WFI __wfi
/** \brief Wait For Event
Wait For Event is a hint instruction that permits the processor to enter
a low-power state until one of a number of events occurs.
*/
#define __WFE __wfe
/** \brief Send Event
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
*/
#define __SEV __sev
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
#define __ISB() __isb(0xF)
/** \brief Data Synchronization Barrier
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
#define __DSB() __dsb(0xF)
/** \brief Data Memory Barrier
This function ensures the apparent order of the explicit memory operations before
and after the instruction, without ensuring their completion.
*/
#define __DMB() __dmb(0xF)
/** \brief Reverse byte order (32 bit)
This function reverses the byte order in integer value.
\param [in] value Value to reverse
\return Reversed value
*/
#define __REV __rev
/** \brief Reverse byte order (16 bit)
This function reverses the byte order in two unsigned short values.
\param [in] value Value to reverse
\return Reversed value
*/
#ifndef __NO_EMBEDDED_ASM
__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
{
rev16 r0, r0
bx lr
}
#endif
/** \brief Reverse byte order in signed short value
This function reverses the byte order in a signed short value with sign extension to integer.
\param [in] value Value to reverse
\return Reversed value
*/
#ifndef __NO_EMBEDDED_ASM
__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
{
revsh r0, r0
bx lr
}
#endif
/** \brief Rotate Right in unsigned value (32 bit)
This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
\param [in] value Value to rotate
\param [in] value Number of Bits to rotate
\return Rotated value
*/
#define __ROR __ror
/** \brief Breakpoint
This function causes the processor to enter Debug state.
Debug tools can use this to investigate system state when the instruction at a particular address is reached.
\param [in] value is ignored by the processor.
If required, a debugger can use it to store additional information about the breakpoint.
*/
#define __BKPT(value) __breakpoint(value)
#if (__CORTEX_M >= 0x03)
/** \brief Reverse bit order of value
This function reverses the bit order of the given value.
\param [in] value Value to reverse
\return Reversed value
*/
#define __RBIT __rbit
/** \brief LDR Exclusive (8 bit)
This function performs a exclusive LDR command for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
/** \brief LDR Exclusive (16 bit)
This function performs a exclusive LDR command for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
/** \brief LDR Exclusive (32 bit)
This function performs a exclusive LDR command for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
/** \brief STR Exclusive (8 bit)
This function performs a exclusive STR command for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXB(value, ptr) __strex(value, ptr)
/** \brief STR Exclusive (16 bit)
This function performs a exclusive STR command for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXH(value, ptr) __strex(value, ptr)
/** \brief STR Exclusive (32 bit)
This function performs a exclusive STR command for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXW(value, ptr) __strex(value, ptr)
/** \brief Remove the exclusive lock
This function removes the exclusive lock which is created by LDREX.
*/
#define __CLREX __clrex
/** \brief Signed Saturate
This function saturates a signed value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (1..32)
\return Saturated value
*/
#define __SSAT __ssat
/** \brief Unsigned Saturate
This function saturates an unsigned value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (0..31)
\return Saturated value
*/
#define __USAT __usat
/** \brief Count leading zeros
This function counts the number of leading zeros of a data value.
\param [in] value Value to count the leading zeros
\return number of leading zeros in value
*/
#define __CLZ __clz
#endif /* (__CORTEX_M >= 0x03) */
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
/* GNU gcc specific functions */
/* Define macros for porting to both thumb1 and thumb2.
* For thumb1, use low register (r0-r7), specified by constrant "l"
* Otherwise, use general registers, specified by constrant "r" */
#if defined (__thumb__) && !defined (__thumb2__)
#define __CMSIS_GCC_OUT_REG(r) "=l" (r)
#define __CMSIS_GCC_USE_REG(r) "l" (r)
#else
#define __CMSIS_GCC_OUT_REG(r) "=r" (r)
#define __CMSIS_GCC_USE_REG(r) "r" (r)
#endif
/** \brief No Operation
No Operation does nothing. This instruction can be used for code alignment purposes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __NOP(void)
{
__ASM volatile ("nop");
}
/** \brief Wait For Interrupt
Wait For Interrupt is a hint instruction that suspends execution
until one of a number of events occurs.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFI(void)
{
__ASM volatile ("wfi");
}
/** \brief Wait For Event
Wait For Event is a hint instruction that permits the processor to enter
a low-power state until one of a number of events occurs.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFE(void)
{
__ASM volatile ("wfe");
}
/** \brief Send Event
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __SEV(void)
{
__ASM volatile ("sev");
}
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __ISB(void)
{
__ASM volatile ("isb");
}
/** \brief Data Synchronization Barrier
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __DSB(void)
{
__ASM volatile ("dsb");
}
/** \brief Data Memory Barrier
This function ensures the apparent order of the explicit memory operations before
and after the instruction, without ensuring their completion.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __DMB(void)
{
__ASM volatile ("dmb");
}
/** \brief Reverse byte order (32 bit)
This function reverses the byte order in integer value.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV(uint32_t value)
{
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
return __builtin_bswap32(value);
#else
uint32_t result;
__ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return(result);
#endif
}
/** \brief Reverse byte order (16 bit)
This function reverses the byte order in two unsigned short values.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV16(uint32_t value)
{
uint32_t result;
__ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return(result);
}
/** \brief Reverse byte order in signed short value
This function reverses the byte order in a signed short value with sign extension to integer.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __REVSH(int32_t value)
{
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
return (short)__builtin_bswap16(value);
#else
uint32_t result;
__ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return(result);
#endif
}
/** \brief Rotate Right in unsigned value (32 bit)
This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
\param [in] value Value to rotate
\param [in] value Number of Bits to rotate
\return Rotated value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
{
return (op1 >> op2) | (op1 << (32 - op2));
}
/** \brief Breakpoint
This function causes the processor to enter Debug state.
Debug tools can use this to investigate system state when the instruction at a particular address is reached.
\param [in] value is ignored by the processor.
If required, a debugger can use it to store additional information about the breakpoint.
*/
#define __BKPT(value) __ASM volatile ("bkpt "#value)
#if (__CORTEX_M >= 0x03)
/** \brief Reverse bit order of value
This function reverses the bit order of the given value.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
{
uint32_t result;
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
/** \brief LDR Exclusive (8 bit)
This function performs a exclusive LDR command for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)
{
uint32_t result;
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
__ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
#else
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
accepted by assembler. So has to use following less efficient pattern.
*/
__ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
#endif
return ((uint8_t) result); /* Add explicit type cast here */
}
/** \brief LDR Exclusive (16 bit)
This function performs a exclusive LDR command for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)
{
uint32_t result;
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
__ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
#else
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
accepted by assembler. So has to use following less efficient pattern.
*/
__ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
#endif
return ((uint16_t) result); /* Add explicit type cast here */
}
/** \brief LDR Exclusive (32 bit)
This function performs a exclusive LDR command for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)
{
uint32_t result;
__ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
return(result);
}
/** \brief STR Exclusive (8 bit)
This function performs a exclusive STR command for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
{
uint32_t result;
__ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
return(result);
}
/** \brief STR Exclusive (16 bit)
This function performs a exclusive STR command for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
{
uint32_t result;
__ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
return(result);
}
/** \brief STR Exclusive (32 bit)
This function performs a exclusive STR command for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
{
uint32_t result;
__ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
return(result);
}
/** \brief Remove the exclusive lock
This function removes the exclusive lock which is created by LDREX.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __CLREX(void)
{
__ASM volatile ("clrex" ::: "memory");
}
/** \brief Signed Saturate
This function saturates a signed value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (1..32)
\return Saturated value
*/
#define __SSAT(ARG1,ARG2) \
({ \
uint32_t __RES, __ARG1 = (ARG1); \
__ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
__RES; \
})
/** \brief Unsigned Saturate
This function saturates an unsigned value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (0..31)
\return Saturated value
*/
#define __USAT(ARG1,ARG2) \
({ \
uint32_t __RES, __ARG1 = (ARG1); \
__ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
__RES; \
})
/** \brief Count leading zeros
This function counts the number of leading zeros of a data value.
\param [in] value Value to count the leading zeros
\return number of leading zeros in value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __CLZ(uint32_t value)
{
uint32_t result;
__ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) );
return ((uint8_t) result); /* Add explicit type cast here */
}
#endif /* (__CORTEX_M >= 0x03) */
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
/* IAR iccarm specific functions */
#include <cmsis_iar.h>
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
/* TI CCS specific functions */
#include <cmsis_ccs.h>
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
/* TASKING carm specific functions */
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/
/* Cosmic specific functions */
#include <cmsis_csm.h>
#endif
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
#endif /* __CORE_CMINSTR_H */

View File

@@ -0,0 +1,833 @@
/**************************************************************************//**
* @file core_sc000.h
* @brief CMSIS SC000 Core Peripheral Access Layer Header File
* @version V3.30
* @date 17. February 2014
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2014 ARM LIMITED
All rights reserved.
Redistribution and use 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 ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
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 COPYRIGHT HOLDERS AND 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.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __CORE_SC000_H_GENERIC
#define __CORE_SC000_H_GENERIC
/** \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
CMSIS violates the following MISRA-C:2004 rules:
\li Required Rule 8.5, object/function definition in header file.<br>
Function definitions in header files are used to allow 'inlining'.
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
Unions are used for effective representation of core registers.
\li Advisory Rule 19.7, Function-like macro defined.<br>
Function-like macros are used to allow more efficient code.
*/
/*******************************************************************************
* CMSIS definitions
******************************************************************************/
/** \ingroup SC000
@{
*/
/* CMSIS SC000 definitions */
#define __SC000_CMSIS_VERSION_MAIN (0x03) /*!< [31:16] CMSIS HAL main version */
#define __SC000_CMSIS_VERSION_SUB (0x20) /*!< [15:0] CMSIS HAL sub version */
#define __SC000_CMSIS_VERSION ((__SC000_CMSIS_VERSION_MAIN << 16) | \
__SC000_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
#define __CORTEX_SC (000) /*!< Cortex secure core */
#if defined ( __CC_ARM )
#define __ASM __asm /*!< asm keyword for ARM Compiler */
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
#define __STATIC_INLINE static __inline
#elif defined ( __GNUC__ )
#define __ASM __asm /*!< asm keyword for GNU Compiler */
#define __INLINE inline /*!< inline keyword for GNU Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __ICCARM__ )
#define __ASM __asm /*!< asm keyword for IAR Compiler */
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
#define __STATIC_INLINE static inline
#elif defined ( __TMS470__ )
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __TASKING__ )
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __CSMC__ ) /* Cosmic */
#define __packed
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
#define __INLINE inline /*use -pc99 on compile line !< inline keyword for COSMIC Compiler */
#define __STATIC_INLINE static inline
#endif
/** __FPU_USED indicates whether an FPU is used or not. This core does not support an FPU at all
*/
#define __FPU_USED 0
#if defined ( __CC_ARM )
#if defined __TARGET_FPU_VFP
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __GNUC__ )
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __ICCARM__ )
#if defined __ARMVFP__
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TMS470__ )
#if defined __TI__VFP_SUPPORT____
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TASKING__ )
#if defined __FPU_VFP__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __CSMC__ ) /* Cosmic */
#if ( __CSMC__ & 0x400) // FPU present for parser
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#endif
#include <stdint.h> /* standard types definitions */
#include <core_cmInstr.h> /* Core Instruction Access */
#include <core_cmFunc.h> /* Core Function Access */
#endif /* __CORE_SC000_H_GENERIC */
#ifndef __CMSIS_GENERIC
#ifndef __CORE_SC000_H_DEPENDANT
#define __CORE_SC000_H_DEPENDANT
/* check device defines and use defaults */
#if defined __CHECK_DEVICE_DEFINES
#ifndef __SC000_REV
#define __SC000_REV 0x0000
#warning "__SC000_REV not defined in device header file; using default!"
#endif
#ifndef __MPU_PRESENT
#define __MPU_PRESENT 0
#warning "__MPU_PRESENT not defined in device header file; using default!"
#endif
#ifndef __NVIC_PRIO_BITS
#define __NVIC_PRIO_BITS 2
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
#endif
#ifndef __Vendor_SysTickConfig
#define __Vendor_SysTickConfig 0
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
#endif
#endif
/* IO definitions (access restrictions to peripheral registers) */
/**
\defgroup CMSIS_glob_defs CMSIS Global Defines
<strong>IO Type Qualifiers</strong> are used
\li to specify the access to peripheral variables.
\li for automatic generation of peripheral register debug information.
*/
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/*@} end of group SC000 */
/*******************************************************************************
* Register Abstraction
Core Register contain:
- Core Register
- Core NVIC Register
- Core SCB Register
- Core SysTick Register
- Core MPU Register
******************************************************************************/
/** \defgroup CMSIS_core_register Defines and Type Definitions
\brief Type definitions and defines for Cortex-M processor based devices.
*/
/** \ingroup CMSIS_core_register
\defgroup CMSIS_CORE Status and Control Registers
\brief Core Register type definitions.
@{
*/
/** \brief Union type to access the Application Program Status Register (APSR).
*/
typedef union
{
struct
{
#if (__CORTEX_M != 0x04)
uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */
#else
uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
#endif
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} APSR_Type;
/** \brief Union type to access the Interrupt Program Status Register (IPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} IPSR_Type;
/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
#if (__CORTEX_M != 0x04)
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
#else
uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
#endif
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} xPSR_Type;
/** \brief Union type to access the Control Registers (CONTROL).
*/
typedef union
{
struct
{
uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} CONTROL_Type;
/*@} end of group CMSIS_CORE */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
\brief Type definitions for the NVIC Registers
@{
*/
/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
*/
typedef struct
{
__IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
uint32_t RESERVED0[31];
__IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
uint32_t RSERVED1[31];
__IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
uint32_t RESERVED2[31];
__IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
uint32_t RESERVED3[31];
uint32_t RESERVED4[64];
__IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
} NVIC_Type;
/*@} end of group CMSIS_NVIC */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SCB System Control Block (SCB)
\brief Type definitions for the System Control Block Registers
@{
*/
/** \brief Structure type to access the System Control Block (SCB).
*/
typedef struct
{
__I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
__IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
__IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
__IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
__IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
__IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
uint32_t RESERVED0[1];
__IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
__IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
uint32_t RESERVED1[154];
__IO uint32_t SFCR; /*!< Offset: 0x290 (R/W) Security Features Register */
} SCB_Type;
/* SCB CPUID Register Definitions */
#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
#define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */
/* SCB Interrupt Control State Register Definitions */
#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */
/* SCB Interrupt Control State Register Definitions */
#define SCB_VTOR_TBLOFF_Pos 7 /*!< SCB VTOR: TBLOFF Position */
#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
/* SCB Application Interrupt and Reset Control Register Definitions */
#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
/* SCB System Control Register Definitions */
#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
/* SCB Configuration Control Register Definitions */
#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
/* SCB System Handler Control and State Register Definitions */
#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
/* SCB Security Features Register Definitions */
#define SCB_SFCR_UNIBRTIMING_Pos 0 /*!< SCB SFCR: UNIBRTIMING Position */
#define SCB_SFCR_UNIBRTIMING_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SFCR: UNIBRTIMING Mask */
#define SCB_SFCR_SECKEY_Pos 16 /*!< SCB SFCR: SECKEY Position */
#define SCB_SFCR_SECKEY_Msk (0xFFFFUL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SFCR: SECKEY Mask */
/*@} end of group CMSIS_SCB */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB)
\brief Type definitions for the System Control and ID Register not in the SCB
@{
*/
/** \brief Structure type to access the System Control and ID Register not in the SCB.
*/
typedef struct
{
uint32_t RESERVED0[2];
__IO uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
} SCnSCB_Type;
/* Auxiliary Control Register Definitions */
#define SCnSCB_ACTLR_DISMCYCINT_Pos 0 /*!< ACTLR: DISMCYCINT Position */
#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL << SCnSCB_ACTLR_DISMCYCINT_Pos) /*!< ACTLR: DISMCYCINT Mask */
/*@} end of group CMSIS_SCnotSCB */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
\brief Type definitions for the System Timer Registers.
@{
*/
/** \brief Structure type to access the System Timer (SysTick).
*/
typedef struct
{
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
/* SysTick Control / Status Register Definitions */
#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
#define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
/* SysTick Reload Register Definitions */
#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
/* SysTick Current Register Definitions */
#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
/* SysTick Calibration Register Definitions */
#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */
/*@} end of group CMSIS_SysTick */
#if (__MPU_PRESENT == 1)
/** \ingroup CMSIS_core_register
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
\brief Type definitions for the Memory Protection Unit (MPU)
@{
*/
/** \brief Structure type to access the Memory Protection Unit (MPU).
*/
typedef struct
{
__I uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */
__IO uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */
__IO uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */
__IO uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */
__IO uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
} MPU_Type;
/* MPU Type Register */
#define MPU_TYPE_IREGION_Pos 16 /*!< MPU TYPE: IREGION Position */
#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
#define MPU_TYPE_DREGION_Pos 8 /*!< MPU TYPE: DREGION Position */
#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */
#define MPU_TYPE_SEPARATE_Pos 0 /*!< MPU TYPE: SEPARATE Position */
#define MPU_TYPE_SEPARATE_Msk (1UL << MPU_TYPE_SEPARATE_Pos) /*!< MPU TYPE: SEPARATE Mask */
/* MPU Control Register */
#define MPU_CTRL_PRIVDEFENA_Pos 2 /*!< MPU CTRL: PRIVDEFENA Position */
#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */
#define MPU_CTRL_HFNMIENA_Pos 1 /*!< MPU CTRL: HFNMIENA Position */
#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */
#define MPU_CTRL_ENABLE_Pos 0 /*!< MPU CTRL: ENABLE Position */
#define MPU_CTRL_ENABLE_Msk (1UL << MPU_CTRL_ENABLE_Pos) /*!< MPU CTRL: ENABLE Mask */
/* MPU Region Number Register */
#define MPU_RNR_REGION_Pos 0 /*!< MPU RNR: REGION Position */
#define MPU_RNR_REGION_Msk (0xFFUL << MPU_RNR_REGION_Pos) /*!< MPU RNR: REGION Mask */
/* MPU Region Base Address Register */
#define MPU_RBAR_ADDR_Pos 8 /*!< MPU RBAR: ADDR Position */
#define MPU_RBAR_ADDR_Msk (0xFFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */
#define MPU_RBAR_VALID_Pos 4 /*!< MPU RBAR: VALID Position */
#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */
#define MPU_RBAR_REGION_Pos 0 /*!< MPU RBAR: REGION Position */
#define MPU_RBAR_REGION_Msk (0xFUL << MPU_RBAR_REGION_Pos) /*!< MPU RBAR: REGION Mask */
/* MPU Region Attribute and Size Register */
#define MPU_RASR_ATTRS_Pos 16 /*!< MPU RASR: MPU Region Attribute field Position */
#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */
#define MPU_RASR_XN_Pos 28 /*!< MPU RASR: ATTRS.XN Position */
#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */
#define MPU_RASR_AP_Pos 24 /*!< MPU RASR: ATTRS.AP Position */
#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */
#define MPU_RASR_TEX_Pos 19 /*!< MPU RASR: ATTRS.TEX Position */
#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */
#define MPU_RASR_S_Pos 18 /*!< MPU RASR: ATTRS.S Position */
#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */
#define MPU_RASR_C_Pos 17 /*!< MPU RASR: ATTRS.C Position */
#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */
#define MPU_RASR_B_Pos 16 /*!< MPU RASR: ATTRS.B Position */
#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */
#define MPU_RASR_SRD_Pos 8 /*!< MPU RASR: Sub-Region Disable Position */
#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */
#define MPU_RASR_SIZE_Pos 1 /*!< MPU RASR: Region Size Field Position */
#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */
#define MPU_RASR_ENABLE_Pos 0 /*!< MPU RASR: Region enable bit Position */
#define MPU_RASR_ENABLE_Msk (1UL << MPU_RASR_ENABLE_Pos) /*!< MPU RASR: Region enable bit Disable Mask */
/*@} end of group CMSIS_MPU */
#endif
/** \ingroup CMSIS_core_register
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
\brief SC000 Core Debug Registers (DCB registers, SHCSR, and DFSR)
are only accessible over DAP and not via processor. Therefore
they are not covered by the Cortex-M0 header file.
@{
*/
/*@} end of group CMSIS_CoreDebug */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_core_base Core Definitions
\brief Definitions for base addresses, unions, and structures.
@{
*/
/* Memory mapping of SC000 Hardware */
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
#define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
#if (__MPU_PRESENT == 1)
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
#endif
/*@} */
/*******************************************************************************
* Hardware Abstraction Layer
Core Function Interface contains:
- Core NVIC Functions
- Core SysTick Functions
- Core Register Access Functions
******************************************************************************/
/** \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
*/
/* ########################## NVIC functions #################################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
\brief Functions that manage interrupts and exceptions via the NVIC.
@{
*/
/* Interrupt Priorities are WORD accessible only under ARMv6M */
/* The following MACROS handle generation of the register offset and byte masks */
#define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 )
#define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) )
#define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) )
/** \brief Enable External Interrupt
The function enables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Disable External Interrupt
The function disables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
{
NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Get Pending Interrupt
The function reads the pending register in the NVIC and returns the pending bit
for the specified interrupt.
\param [in] IRQn Interrupt number.
\return 0 Interrupt status is not pending.
\return 1 Interrupt status is pending.
*/
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
}
/** \brief Set Pending Interrupt
The function sets the pending bit of an external interrupt.
\param [in] IRQn Interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Clear Pending Interrupt
The function clears the pending bit of an external interrupt.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
}
/** \brief Set Interrupt Priority
The function sets the priority of an interrupt.
\note The priority cannot be set for every core interrupt.
\param [in] IRQn Interrupt number.
\param [in] priority Priority to set.
*/
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if(IRQn < 0) {
SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
else {
NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
}
/** \brief Get Interrupt Priority
The function reads the priority of an interrupt. The interrupt
number can be positive to specify an external (device specific)
interrupt, or negative to specify an internal (core) interrupt.
\param [in] IRQn Interrupt number.
\return Interrupt Priority. Value is aligned automatically to the implemented
priority bits of the microcontroller.
*/
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
{
if(IRQn < 0) {
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */
else {
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
}
/** \brief System Reset
The function initiates a system reset request to reset the MCU.
*/
__STATIC_INLINE void NVIC_SystemReset(void)
{
__DSB(); /* Ensure all outstanding memory accesses included
buffered write are completed before reset */
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
SCB_AIRCR_SYSRESETREQ_Msk);
__DSB(); /* Ensure completion of memory access */
while(1); /* wait until reset */
}
/*@} end of CMSIS_Core_NVICFunctions */
/* ################################## SysTick function ############################################ */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
\brief Functions that configure the System.
@{
*/
#if (__Vendor_SysTickConfig == 0)
/** \brief System Tick Configuration
The function initializes the System Timer and its interrupt, and starts the System Tick Timer.
Counter is in free running mode to generate periodic interrupts.
\param [in] ticks Number of ticks between two interrupts.
\return 0 Function succeeded.
\return 1 Function failed.
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
SysTick->LOAD = ticks - 1; /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */
SysTick->VAL = 0; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0); /* Function successful */
}
#endif
/*@} end of CMSIS_Core_SysTickFunctions */
#endif /* __CORE_SC000_H_DEPENDANT */
#endif /* __CMSIS_GENERIC */
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,342 @@
/**
* @file VS10XX.h
*
* @brief VS10XX driver
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef __VS10XX_H__
#define __VS10XX_H__
//#include "sys.h"
#include "wm_type_def.h"
/** VS10XX ID list*/
#define VS1001 0
#define VS1011 1
#define VS1002 2
#define VS1003 3
#define VS1053 4
#define VS1033 5
#define VS1103 7
extern u8 VS10XX_ID; /** VS10XX id */
/**command */
#define VS_WRITE_COMMAND 0x02 /** write command */
#define VS_READ_COMMAND 0x03 /** read command */
/** VS10XX register definition */
#define SPI_MODE 0x00 /** mode control */
#define SPI_STATUS 0x01 /** VS10XX status register */
#define SPI_BASS 0x02 /** bass control */
#define SPI_CLOCKF 0x03 /** Clock frequency multiplier register */
#define SPI_DECODE_TIME 0x04 /** Decoding time length */
#define SPI_AUDATA 0x05 /** Audio data */
#define SPI_WRAM 0x06 /** RAM write/read */
#define SPI_WRAMADDR 0x07 /** RAM write/read start addr */
#define SPI_HDAT0 0x08 /** The data stream header 0 */
#define SPI_HDAT1 0x09 /** The data stream header 1 */
#define SPI_AIADDR 0x0a /** application start addr */
#define SPI_VOL 0x0b /** volumn control */
#define SPI_AICTRL0 0x0c /** Application control register 0 */
#define SPI_AICTRL1 0x0d /** Application control register 1 */
#define SPI_AICTRL2 0x0e /** Application control register 2 */
#define SPI_AICTRL3 0x0f /** Application control register 3 */
//SPI_MODE的各位功能,下表根据VS1053的手册标注
#define SM_DIFF 0x01 /**差分 */
#define SM_LAYER12 0x02 /**允许MPEG 1,2解码 FOR vs1053 */
#define SM_RESET 0x04 /**软件复位 */
#define SM_CANCEL 0x08 /**取消当前解码 */
#define SM_EARSPEAKER_LO 0x10 /**EarSpeaker低设定 */
#define SM_TESTS 0x20 /**允许SDI测试 */
#define SM_STREAM 0x40 /**流模式 */
#define SM_EARSPEAKER_HI 0x80 /**EarSpeaker高设定 */
#define SM_DACT 0x100 /**DCLK的有效边沿 */
#define SM_SDIORD 0x200 /**SDI位顺序 */
#define SM_SDISHARE 0x400 /**共享SPI片选 */
#define SM_SDINEW 0x800 /**VS1002 本地SPI模式 */
#define SM_ADPCM 0x1000/**ADPCM录音激活 */
#define SM_LINE1 0x4000/**咪/线路1 选择 */
#define SM_CLK_RANGE 0x8000/**输入时钟范围 */
//VS10xx与外部接口定义(未包含MISO,MOSI,SCK)
//#define VS_DQ PAin(12) //DREQ
//#define VS_RST PAout(11) //RST
//#define VS_XCS PAout(8) //XCS
//#define VS_XDCS PAout(4) //XDCS
//#define VS_DQ 3//13
//#define VS_RST 11
//#define VS_XCS 12
//#define VS_XDCS 2//18
#define VS_DQ WM_GPIO_A_PIN_12
#define VS_RST WM_GPIO_A_PIN_13
#define VS_XCS WM_GPIO_A_PIN_11
#define VS_XDCS WM_GPIO_A_PIN_9
#define VS_SPI_CLK_LOW 250000
#define VS_SPI_CLK_HIGH 5000000
#define VS_REC_PKG_SIZE 512
/**
* @brief pull cs low
*
* @param[in] None
*
* @return None
*
* @note None
*/
void codec_data_cs_low(void);
/**
* @brief pull cs high
*
* @param[in] None
*
* @return None
*
* @note None
*/
void codec_data_cs_high(void);
/**
* @brief read register
*
* @param[in] address
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
u16 VS_RD_Reg(u8 address);
/**
* @brief write command
*
* @param[in] address
* @param[in] data
*
* @return None
*
* @note None
*/
void VS_WR_Cmd(u8 address,u16 data);
/**
* @brief write data
*
* @param[in] data
*
* @return None
*
* @note None
*/
void VS_WR_Data(u8 data);
/**
* @brief read ram
*
* @param[in] addr
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
u16 VS_RD_Wram(u16 addr);
/**
* @brief initial VS10XX
*
* @param[in] None
*
* @return None
*
* @note None
*/
void VS_Init(void);
/**
* @brief hardware reset
*
* @param[in] None
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
u8 VS_HD_Reset(void);
/**
* @brief software reset
*
* @param[in] None
*
* @return None
*
* @note None
*/
void VS_Soft_Reset(void);
/**
* @brief ram test
*
* @param[in] None
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
u16 VS_Ram_Test(void);
/**
* @brief sine test
*
* @param[in] None
*
* @return None
*
* @note None
*/
void VS_Sine_Test(void);
/**
* @brief get decode time
*
* @param[in] None
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
u16 VS_Get_DecodeTime(void);
/**
* @brief get bitrate
*
* @param[in] None
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
u16 VS_Get_HeadInfo(void);
/**
* @brief set decode time
*
* @param[in] None
*
* @return None
*
* @note None
*/
void VS_Rst_DecodeTime(void);
/**
* @brief set VS10XX
*
* @param[in] None
*
* @return None
*
* @note None
*/
void set10XX(void);
/**
* @brief load FLAC decode code
*
* @param[in] *patch
* @param[in] len
*
* @return None
*
* @note None
*/
void VS_Load_Patch(u16 *patch,u16 len);
/**
* @brief set volumn
*
* @param[in] vol
*
* @return None
*
* @note None
*/
void vs_set_vol(int vol);
/**
* @brief mute
*
* @param[in] None
*
* @return None
*
* @note None
*/
void vs_mute(void);
/**
* @brief set record mode
*
* @param[in] agc
*
* @return None
*
* @note None
*/
void VS_Rec_Mode(u16 agc);
/**
* @brief get record data
*
* @param[in] recbuf
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int VS_Rec_GetData(char* recbuf);
#endif

View File

@@ -0,0 +1,242 @@
/**************************************************************************//**
* @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_29 //(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;
/**
* @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

View File

@@ -0,0 +1,297 @@
/**
* @file wm_adc.h
*
* @brief ADC Driver Module
*
* @author
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_ADC_H
#define WM_ADC_H
#ifdef __cplusplus
extern "C" {
#endif
#include "wm_type_def.h"
/** ADC MACRO */
//每次启动dma之后需要一段稳定时间所以采集到的数据前面的12个byte不稳定要舍去
#define ADC_DEST_BUFFER_DMA (u32)0x20028000
#define ADC_DEST_BUFFER_SIZE 65532
#define SAMPLE_NUM_PER_CHANNEL 20
#define CONFIG_ADC_CAL_OFFSET_TEMP12 (1<<23)
#define CONFIG_ADC_G_CTRL12 (1<<22)
#define CONFIG_ADC_CMP_POL (1<<21)
#define CONFIG_ADC_REF_SEL (1<<20)
#define CONFIG_ADC_BUF_BYPASS (1<<19)
#define CONFIG_ADC_DMA_MASK (0xFF<<11)
#define CONFIG_ADC_EN_CAL (1<<10)
#define CONFIG_ADC_INT_CMP (1<<9)
#define CONFIG_ADC_INT (1<<8)
#define CONFIG_ADC_CMP_INT_MASK (1<<7)
#define CONFIG_ADC_INT_MASK (1<<6)
#define CONFIG_ADC_TEMP_ON (1<<5)
#define CONFIG_ADC_START (1<<4)
#define CONFIG_ADC_CHL_MASK (0xF)
#define CONFIG_ADC_CHL_OFFSET (0x0E)
#define CONFIG_ADC_CHL_VOLT (0x0D)
#define CONFIG_ADC_CHL_TEMP (0x0C)
#define CONFIG_ADC_INPUT_CMP_VAL(n) ((n&0x3FFF)<<14)
#define CONFIG_ADC_VCM(n) (((u32)n&0x3F)<<26)
#define CONFIG_ADC_G_TEMP12(n) ((n&0x03)<<24)
#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)(u16 *buf, u16 len);
void (*adc_bigger_cb)(u16 *buf, u16 len);
void (*adc_dma_cb)(u16 *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 If the requested dma channel is already used by other task, system will auto use other dma channel.
*/
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)(u16 *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.
* ADC_INT_TYPE_ADC_COMP adc compare with setting data
*
* @return None
*
* @note None
*/
void tls_adc_clear_irq(int inttype);
/**
* @brief This function is used to start adc,use dma for transfer data
*
* @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,use cpu
*
* @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 enable input buffer calibration
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_adc_enable_calibration_buffer_offset(void);
/**
* @brief This function is used to sample voltage using cpu
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_adc_voltage_start_with_cpu(void);
/**
* @brief This function is used to sample temperature using cpu
*
* @param[in] calenflag 1:enable calibration , 0: disable calibration
*
* @return None
*
* @note None
*/
void tls_adc_temp_offset_with_cpu(u8 calenflag);
/**
* @brief This function is used to read adc result
*
* @param[in] None
*
* @return None
*
* @note None
*/
u16 tls_read_adc_result(void);
/**
* @brief This function is used to stop the adc
*
* @param[in] ifusedma 1:use dma, 0:not use dma
*
* @return None
*
* @note None
*/
void tls_adc_stop(int ifusedma);
/**
* @brief This function is used to config adc compare register
*
* @param[in] cmp_data compare data
*
* @param[in] cmp_pol compare polarity
*
* @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 set clock division
*
* @param[in] div
*
* @return None
*
* @note None
*/
void tls_adc_set_clk(int div);
void signedToUnsignedData(u16 *adcValue, u16 *offset);
/**
* @brief This function is used to set buffer bypass
*
* @param[in] isset 1: buffer bypass, 0: buffer work
*
* @return None
*
* @note None
*/
void tls_adc_buffer_bypass_set(u8 isset);
/**
* @brief This function is used to start compare
*
* @param[in] Channel sample channel
*
* @param[in] cmp_data compare data
*
* @param[in] cmp_pol compare polarity
*
* @return None
*
* @note None
*/
void tls_adc_cmp_start(int Channel, int cmp_data, int cmp_pol);
u16 adc_get_offset(void);
u32 adc_get_interTemp(void);
u16 adc_get_inputVolt(u8 channel);
u16 adc_get_interVolt(void);
u32 adc_temp(void);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* end of WM_ADC_H */
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

View File

@@ -0,0 +1,94 @@
/**
* @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
#ifdef __cplusplus
extern "C" {
#endif
/** cpu clock: 80Mhz */
#define CPU_CLK_80M 0
/** cpu clock: 40Mhz */
#define CPU_CLK_40M 1
#define CPU_CLK_16M 2
#define W600_PLL_CLK_MHZ 160
#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 CPU_CLOCK_Driver_APIs CPU_CLOCK Driver APIs
* @brief CPU_CLOCK driver APIs
*/
/**
* @addtogroup CPU_CLOCK_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);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* end of WM_CPU_H */
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

View File

@@ -0,0 +1,245 @@
/**
* @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_
#ifdef __cplusplus
extern "C" {
#endif
#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_SDADC_CH4 10
#define TLS_DMA_SEL_SDADC_CH5 11
#define TLS_DMA_SEL_SDADC_CH6 12
#define TLS_DMA_SEL_SDADC_CH7 13
#define TLS_DMA_SEL_I2S_RX 14
#define TLS_DMA_SEL_I2S_TX 15
#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 0, the function will select a random free channel,
* else return the selected channel no. if free.
*
* @param[in] ch channel no.
* @param[in] flags flags setted to selected channel
*
* @return Channel no. that is free now
*
* @note Channel no. that is free now
*/
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);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* end of __WM_DMA_H_ */
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

View File

@@ -0,0 +1,269 @@
/**
* @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_MAC = 0x01,
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 VCG_ADDR (FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST)+4)
#define VCG_LEN (4)
//#define TX_GAIN_NEW_ADDR (VCG_ADDR+VCG_LEN)
#define TX_GAIN_LEN (28*3)
/**
* @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 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
* @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 vcg ctrl
*
* @param[in] vcg
* @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_vcg_ctrl_op(u8 *vcg, u8 flag);
/**
* @brief This function is used to get chip ID
*
* @param[out] chip_id
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_FLS_STATUS_EPERM flash driver module not beed installed
*/
int tls_get_chipid(u8 chip_id[16]);
/**
* @brief This function is used to get chip ID
*
* @param[in] seconds
*
* @retval TLS_EFUSE_STATUS_OK success
*/
unsigned int tls_sleep(unsigned int seconds);
/**
* @brief This function is used to get chip ID
*
* @param[in] msec
*
* @retval TLS_EFUSE_STATUS_OK success
*/
int tls_msleep(unsigned int msec);
/**
* @brief This function is used to get chip ID
*
* @param[in] usec
*
* @retval TLS_EFUSE_STATUS_OK success
*/
int tls_usleep(unsigned int usec);
#endif /* WM_EFUSE_H */

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 SPIFLASH Driver APIs
* @brief SPIFLASH 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,84 @@
/**
* @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 (0x08000000UL)
#define FLASH_1M_END_ADDR (0x08100000UL)
/**Run-time image header area*/
#define CODE_RUN_HEADER_ADDR (0x08010000UL)
#define CODE_RUN_HEADER_AREA_LEN (0x100)
/**Run-time image area*/
#define CODE_RUN_START_ADDR (0x08010100UL)
/********************************************************
******************LAYOUT For 1M Flash**********************
*Reserved 0x8000000-0x8010000 64Kbyte
*Code 0x8010100-0x808FFFF 512Kbyte - 256 byte
*Update 0x8090000-0x80EFFFF 384Kbyte
*User 0x80F0000-0x80FBFFF 48Kbyte
*Parameter 0x80FC000-0x80FFFFF 16Kbyte
*********************************************************
**************LAYOUT For 2M Flash as 1M LAYOUT**************
*Reserved 0x8000000-0x8010000 64Kbyte
*Code 0x8010100-0x80FFFFF 896Kbyte -256byte
*Old User Area 0x80F0000-0x80FBFFF 48Kbyte
*Parameter 0x80FC000-0x80FFFFF 16Kbyte
*Update 0x8100000-0x81AFFFF 704Kbyte
*EXT User 0x81B0000-0x81FFFFF 320Kbyte
*********************************************************
******************LAYOUT For 2M Flash*********************
*Reserved 0x8000000-0x8010000 64Kbyte
*Code 0x8010100-0x80FFFFF 960Kbyte -256byte
*Update 0x8100000-0x81BFFFF 768Kbyte
*User 0x81C0000-0x81FBFFF 240Kbyte
*Parameter 0x81FC000-0x81FFFFF 16Kbyte
*********************************************************
*********************************************************/
/**Run-time image area size*/
extern unsigned int CODE_RUN_AREA_LEN;
/**Area can be used by User in 1M position*/
extern unsigned int USER_ADDR_START;
extern unsigned int TLS_FLASH_PARAM_DEFAULT;
extern unsigned int USER_AREA_LEN;
extern unsigned int USER_ADDR_END;
/**Upgrade image header area & System parameter area */
extern unsigned int CODE_UPD_HEADER_ADDR;
extern unsigned int TLS_FLASH_PARAM1_ADDR;
extern unsigned int TLS_FLASH_PARAM2_ADDR;
extern unsigned int TLS_FLASH_PARAM_RESTORE_ADDR;
/**Upgrade image area*/
extern unsigned int CODE_UPD_START_ADDR;
extern unsigned int CODE_UPD_AREA_LEN;
/**Area can be used by User in 2M position*/
extern unsigned int EX_USER_ADDR_START;
extern unsigned int EX_USER_AREA_LEN;
extern unsigned int EX_USER_ADDR_END;
extern unsigned int TLS_FLASH_END_ADDR;
#define SIGNATURE_WORD 0xa0ffff9f
#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 */

View File

@@ -0,0 +1,189 @@
/**
* @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
#ifdef __cplusplus
extern "C" {
#endif
#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);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* end of WM_GPIO_H */
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

View File

@@ -0,0 +1,506 @@
/**
* @file wm_gpio_afsel.h
*
* @brief GPIO Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_IO_MUX_H
#define WM_IO_MUX_H
#ifdef __cplusplus
extern "C" {
#endif
#include "wm_gpio.h"
#include "wm_regs.h"
#include "wm_irq.h"
#include "tls_common.h"
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup IOMUX_Driver_APIs IOMUX Driver APIs
* @brief IOMUX 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
* hspi_int PB14
* hspi_cs PB15
* hspi_ck PB16
* hspi_di PB17
* hspi_do PB18
* 1: hspi1
* hspi_int PB08
* hspi_cs PB09
* hspi_ck PB10
* hspi_di PB11
* hspi_do PB12
* @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_PA_01
* WM_IO_PB_16
* WM_IO_PB_27
* WM_IO_PA_11
*
* @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_02
* WM_IO_PB_15
* WM_IO_PB_00
* WM_IO_PB_07
* WM_IO_PA_12
*
* @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_PA_03
* WM_IO_PB_17
* WM_IO_PB_01
* WM_IO_PA_05
* WM_IO_PA_10
*
* @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_PB_18
* WM_IO_PB_02
* WM_IO_PB_04
* WM_IO_PA_09
* WM_IO_PA_10
*
* @return None
*/
void wm_spi_do_config(enum tls_io_name io_name);
/**
* @brief config the pins used for sdio ck dat0 dat1 dat2 dat3
* @param numsel: config sdio ck dat0 dat1 dat2 dat3 pins multiplex relation,valid para 0
* 0:
* sdio_ck PB08
* sdio_dat0 PB09
* sdio_dat1 PB10
* sdio_dat2 PB11
* sdio_dat3 PB12
*
* @return None
*/
void wm_sdio_config(uint8_t numsel);
/**
* @brief config the pins used for sdio cmd
* @param io_name: config sdio cmd pins name
* WM_IO_PA_06
* WM_IO_PB_07
* WM_IO_PB_13
*
* @return None
*/
void wm_sdio_cmd_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart0 tx
* @param io_name: config uart0 tx pins name
* WM_IO_PA_04
* WM_IO_PA_08
* WM_IO_PB_07
* WM_IO_PB_26
*
* @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_PA_05
* WM_IO_PA_09
* WM_IO_PB_06
* WM_IO_PB_25
*
* @return None
*/
void wm_uart0_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart0 rts
* @param io_name: config uart0 rts pins name
* WM_IO_PA_13
* WM_IO_PB_04
* WM_IO_PB_24
*
* @return None
*/
void wm_uart0_rts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart0 cts
* @param io_name: config uart0 cts pins name
* WM_IO_PA_14
* WM_IO_PB_05
* WM_IO_PB_23
*
* @return None
*/
void wm_uart0_cts_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_12
* WM_IO_PB_18
*
* @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_11
* WM_IO_PB_17
*
* @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_10
*
* @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_09
*
* @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_PA_01
* WM_IO_PA_11
* WM_IO_PB_02
* WM_IO_PB_20
*
* @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_PA_00
* WM_IO_PA_10
* WM_IO_PB_03
* WM_IO_PB_19
* WM_IO_PB_30
*
* @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_PA_02
* WM_IO_PA_12
* WM_IO_PB_01
* WM_IO_PB_21
* WM_IO_PB_06
*
* @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_PA_03
* WM_IO_PB_28
* WM_IO_PB_00
*
* @return None
*/
void wm_uart2_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s master ck
* @param io_name: config i2s master ck pins name
* WM_IO_PA_04
* WM_IO_PA_08
* WM_IO_PB_08
*
* @return None
*/
void wm_i2s_m_ck_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s master ws
* @param io_name: config i2s master ws pins name
* WM_IO_PA_13
* WM_IO_PA_09
* WM_IO_PB_10
*
* @return None
*/
void wm_i2s_m_ws_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s master do
* @param io_name: config i2s master do pins name
* WM_IO_PA_03
* WM_IO_PA_07
* WM_IO_PB_09
*
* @return None
*/
void wm_i2s_m_do_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s slave ck
* @param io_name: config i2s slave ck pins name
* WM_IO_PA_15
* WM_IO_PA_11
* WM_IO_PB_15
* WM_IO_PB_04
*
* @return None
*/
void wm_i2s_s_ck_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s slave ws
* @param io_name: config i2s slave ws pins name
* WM_IO_PA_06
* WM_IO_PA_12
* WM_IO_PB_16
* WM_IO_PB_05
*
* @return None
*/
void wm_i2s_s_ws_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s slave di
* @param io_name: config i2s slave di pins name
* WM_IO_PA_14
* WM_IO_PA_10
* WM_IO_PB_14
* WM_IO_PB_03
*
* @return None
*/
void wm_i2s_s_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_02
* WM_IO_PB_28
* WM_IO_PB_31
*
* @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_05
*
* @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_06
* WM_IO_PA_08
* WM_IO_PB_13
* WM_IO_PB_11
* WM_IO_PB_21
*
* @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_15
* WM_IO_PA_07
* WM_IO_PB_14
* WM_IO_PB_12
* WM_IO_PB_22
*
* @return None
*/
void wm_i2c_sda_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm1
* @param io_name: config pwm1 pins name
* WM_IO_PA_00
* WM_IO_PB_18
* WM_IO_PB_05
* WM_IO_PA_05
* WM_IO_PB_19
* WM_IO_PB_30
*
* @return None
*/
void wm_pwm1_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm1
* @param io_name: config pwm1 pins name
* WM_IO_PA_01
* WM_IO_PB_11
* WM_IO_PB_04
* WM_IO_PA_07
* WM_IO_PB_13
* WM_IO_PB_20
*
* @return None
*/
void wm_pwm2_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm3
* @param io_name: config pwm3 pins name
* WM_IO_PA_02
* WM_IO_PB_16
* WM_IO_PB_03
* WM_IO_PA_08
* WM_IO_PB_21
*
* @return None
*/
void wm_pwm3_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm4
* @param io_name: config pwm4 pins name
* WM_IO_PA_03
* WM_IO_PB_15
* WM_IO_PB_02
* WM_IO_PA_09
* WM_IO_PB_22
*
* @return None
*/
void wm_pwm4_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm5
* @param io_name: config pwm5 pins name
* WM_IO_PA_04
* WM_IO_PB_14
* WM_IO_PB_01
* WM_IO_PA_10
* WM_IO_PB_23
*
* @return None
*/
void wm_pwm5_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_24
* WM_IO_PB_29
* WM_IO_PB_00
* WM_IO_PA_11
*
* @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~07: single-ended input
* 8~11: differential input
*
* @return None
*/
void wm_adc_config(u8 Channel);
/**
* @brief disable all the gpio af
*
* @return None
*
* @note This function must call before anyothers for configure
* gpio Alternate functions
*/
void wm_gpio_af_disable(void);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* end of WM_IO_MUX_H */
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

View File

@@ -0,0 +1,296 @@
/**
* @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_TX_DMA_MASK 0x01
#define SPI_RX_DMA_MASK 0x02
#define SPI_DMA_CMD_ADDR ((u32)(MASTER_SPI_DMA_ADDR))
#define SPI_DMA_CMD_MAX_SIZE (0x20)
#define SPI_DMA_BUF_ADDR ((u32)(SPI_DMA_CMD_ADDR + SPI_DMA_CMD_MAX_SIZE))
#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 HOSTSPI_Driver_APIs HOSTSPI Driver APIs
* @brief HOSTSPI driver APIs
*/
/**
* @addtogroup HOSTSPI_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 */

View File

@@ -0,0 +1,264 @@
/**
* @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_IO_REUSE_NUM 0
#define SDIO_IO_REUSE_NUM 2
#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, Wraper controller can only access the address after the 0x60000*/
#define HSPI_TXBUF_NUM 2
#define HSPI_TX_DESC_NUM HSPI_TXBUF_NUM
#define HSPI_RXBUF_NUM 3//10
#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
* total size : 0x61800 - 0x67FFFF (26KB)
******************************************************************************/
/* 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
#if 0
#define SDIO_CMD_RXBUF_SIZE (0x100)
#define SDIO_CMD_RXBUF_ADDR (0x00068000 - SDIO_CMD_RXBUF_SIZE)
#define SDIO_CIS1_ADDR (SDIO_CMD_RXBUF_ADDR - 0x80)
#define SDIO_CIS0_ADDR (SDIO_CIS1_ADDR - 0x80)
#else
#define SDIO_CIS0_ADDR (HSPI_RX_DESC_BASE_ADDR + HSPI_RX_DESC_TOTAL_SIZE) //128
#define SDIO_CIS1_ADDR (SDIO_CIS0_ADDR + 0x80) //128
#define SDIO_CMD_RXBUF_ADDR (SDIO_CIS1_ADDR + 0x80)
#define SDIO_CMD_RXBUF_SIZE 256//(1500) //256
#endif
#define CIS_FUN0_ADDR SDIO_CIS0_ADDR
#define CIS_FUN1_ADDR 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)
/**Definition of SDIO interrupt in the system*/
#define SDIO_RX_DATA_INT (0UL)
#define SDIO_TX_DATA_INT (1UL)
#define SDIO_RX_CMD_INT (2UL)
#define SDIO_TX_CMD_INT (3UL)
/**IO control register*/
#define HR_IOCTL_GP_SDIO HR_IOCTL_GP_SDIO_I2C
/** 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 */

View File

@@ -0,0 +1,136 @@
/**************************************************************************//**
* @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"
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);
#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. ***/

View File

@@ -0,0 +1,584 @@
/**************************************************************************//**
* @file wm_i2s.h
* @author
* @version
* @date
* @brief
*
* @copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
*****************************************************************************/
#ifndef __WM_I2S_H
#define __WM_I2S_H
#ifdef __cplusplus
extern "C" {
#endif
#include "wm_type_def.h"
#include "wm_regs.h"
#include "wm_osal.h"
#include "misc.h"
#include "wm_dma.h"
#define I2S_CTRL_FORMAT_Pos (24) /*!< CTRL : FORMAT Position */
#define I2S_CTRL_FORMAT_MASK (3UL<<I2S_CTRL_FORMAT_Pos) /*!< CTRL : FORMAT mask */
#define I2S_CTRL_FORMAT_I2S (0x0UL<<I2S_CTRL_FORMAT_Pos) /*!< I2S data format*/
#define I2S_CTRL_FORMAT_MSB (0x1UL<<I2S_CTRL_FORMAT_Pos) /*!< MSB data format*/
#define I2S_CTRL_FORMAT_PCMA (0x2UL<<I2S_CTRL_FORMAT_Pos) /*!< PCMA data format*/
#define I2S_CTRL_FORMAT_PCMB (0x3UL<<I2S_CTRL_FORMAT_Pos) /*!< PCMB data format*/
#define I2S_CTRL_DATABIT_MASK (0x30UL) /*!< CTRL : DATABIT mask */
#define I2S_CTRL_DATABIT_8 ((uint8_t)0x0) /*!< I2S data width is 8-bit */
#define I2S_CTRL_DATABIT_16 ((uint8_t)0x10) /*!< I2S data width is 16-bit */
#define I2S_CTRL_DATABIT_24 ((uint8_t)0x20) /*!< I2S data width is 24-bit */
#define I2S_CTRL_DATABIT_32 ((uint8_t)0x30) /*!< I2S data width is 32-bit */
#define I2S_CTRL_CHSEL_Pos (23) /*!< CTRL : Channel select position */
#define I2S_CTRL_CHSEL_MASK (1UL<<I2S_CTRL_CHSEL_Pos) /*!< CTRL: Channel select mask */
#define I2S_CTRL_CHSEL_LEFT (1UL<<I2S_CTRL_CHSEL_Pos) /*!< CTRL: Left channel select */
#define I2S_CTRL_CHSEL_RIGHT (0UL<<I2S_CTRL_CHSEL_Pos) /*!< CTRL: Right channel select */
#define I2S_CTRL_STEREO_MONO_Pos (22) /*!< CTRL: STEREO MONO Position */
#define I2S_CTRL_STEREO_MONO_MASK (1UL<<I2S_CTRL_STEREO_MONO_Pos) /*!< CTRL: STEREO MONO MASK */
#define I2S_CTRL_MONO (1UL<<I2S_CTRL_STEREO_MONO_Pos) /*!< Monaural channel */
#define I2S_CTRL_STERO (0UL<<I2S_CTRL_STEREO_MONO_Pos) /*!< Stereo channel */
#define I2S_CTRL_RXDMA_Pos (21) /*!< CTRL: RXDMA Position */
#define I2S_CTRL_RXDMA_MASK (1UL<<I2S_CTRL_RXDMA_Pos) /*!< CTRL: RXDMA mask */
#define I2S_CTRL_TXDMA_Pos (20) /*!< CTRL: TXDMA Position*/
#define I2S_CTRL_TXDMA_MASK (1UL<<I2S_CTRL_TXDMA_Pos) /*!< CTRL: TXDMA mask */
#define I2S_CTRL_RX_CLR_Pos (19) /*!< CTRL: RXFIFO clear Position */
#define I2S_CTRL_RX_CLR_MASK (1UL<<I2S_CTRL_RX_CLR_Pos) /*!< CTRL: RXFIFO clear mask */
#define I2S_CTRL_TX_CLR_Pos (18) /*!< CTRL: TXFIFO clear Position */
#define I2S_CTRL_TX_CLR_MASK (1UL<<I2S_CTRL_TX_CLR_Pos) /*!< CTRL: TXFIFO clear mask */
#define I2S_CTRL_LZCEN_Pos (17) /*!< CTRL: LZCEN Position */
#define I2S_CTRL_LZCEN_MASK (1UL<<I2S_CTRL_LZCEN_Pos) /*!< CTRL: LZCEN mask */
#define I2S_CTRL_RZCEN_Pos (16) /*!< CTRL: RZCEN Position */
#define I2S_CTRL_RZCEN_MASK (1UL<<I2S_CTRL_RZCEN_Pos) /*!< CTRL: RZCEN mask */
#define I2S_CTRL_RXTH_Pos (12) /*!< CTRL: RXTH Position */
#define I2S_CTRL_RXTH_MASK (7UL<<I2S_CTRL_RXTH_Pos) /*!< CTRL: RXTH mask */
#define I2S_CTRL_TXTH_Pos (9) /*!< CTRL: TXTH Position */
#define I2S_CTRL_TXTH_MASK (7UL<<I2S_CTRL_TXTH_Pos) /*!< CTRL: TXTH mask */
#define I2S_CTRL_MUTE_Pos (3) /*!< CTRL: MUTE Position */
#define I2S_CTRL_MUTE_MASK (1UL<<I2S_CTRL_MUTE_Pos) /*!< CTRL: MUTE mask */
#define I2S_CTRL_RXE_Pos (2) /*!< CTRL: RXEN Position */
#define I2S_CTRL_RXE_MASK (1UL<<I2S_CTRL_RXE_Pos) /*!< CTRL: RXEN mask */
#define I2S_CTRL_TXE_Pos (1) /*!< CTRL: TXEN Position */
#define I2S_CTRL_TXE_MASK (1UL<<I2S_CTRL_TXE_Pos) /*!< CTRL: TXEN mask */
#define I2S_CTRL_EN_Pos (0) /*!< CTRL: EN Position */
#define I2S_CTRL_EN_MASK (1UL<<I2S_CTRL_EN_Pos) /*!< CTRL: EN mask */
#define I2S_INT_MASK_LZC ((uint16_t)0x200) /*!< Left Channel Zero-Cross Interrupt MASK */
#define I2S_INT_MASK_RZC ((uint16_t)0x100) /*!< Right Channel Zero-Cross Interrupt MASK */
#define I2S_INT_MASK_TXDONE ((uint16_t)0x080) /*!< Transmit Done Interrupt Mask */
#define I2S_INT_MASK_TXTH ((uint16_t)0x040) /*!< Transmit FIFO Threshold level Interrupt MASK */
#define I2S_INT_MASK_TXOV ((uint16_t)0x020) /*!< Transmit FIFO Overflow Interrupt MASK */
#define I2S_INT_MASK_TXUD ((uint16_t)0x010) /*!< Transmit FIFO Underflow Interrupt MASK */
#define I2S_INT_MASK_RXDONE ((uint16_t)0x008) /*!< Receive Done Interrupt Mask */
#define I2S_INT_MASK_RXTH ((uint16_t)0x004) /*!< Receive FIFO Threshold level Interrupt MASK */
#define I2S_INT_MASK_RXOV ((uint16_t)0x002) /*!< Receive FIFO Overflow Interrupt MASK */
#define I2S_INT_MASK_RXUD ((uint16_t)0x002) /*!< Receive FIFO Underflow Interrupt MASK */
#define I2S_FLAG_TX_Pos (12) /*!< INT_SRC: TX interrupt flag Position */
#define I2S_FLAG_RX_Pos (11) /*!< INT_SRC: RX interrupt flag Position */
#define I2S_FLAG_I2S_Pos (10) /*!< INT_SRC: I2S module interrupt flag Position */
#define I2S_FLAG_LZC_Pos (9) /*!< INT_SRC: LZC module interrupt flag Position */
#define I2S_FLAG_RZC_Pos (8) /*!< INT_SRC: RZC module interrupt flag Position */
#define I2S_FLAG_TXDONE_Pos (7) /*!< INT_SRC: TXDONE module interrupt flag Position */
#define I2S_FLAG_TXTH_Pos (6) /*!< INT_SRC: TXTH module interrupt flag Position */
#define I2S_FLAG_TXOV_Pos (5) /*!< INT_SRC: TXOV module interrupt flag Position */
#define I2S_FLAG_TXUD_Pos (4) /*!< INT_SRC: TXUD module interrupt flag Position */
#define I2S_FLAG_RXDONE_Pos (3) /*!< INT_SRC: RXDONE module interrupt flag Position */
#define I2S_FLAG_RXTH_Pos (2) /*!< INT_SRC: RXTH module interrupt flag Position */
#define I2S_FLAG_RXOV_Pos (1) /*!< INT_SRC: RXOV module interrupt flag Position */
#define I2S_FLAG_RXUD_Pos (0) /*!< INT_SRC: RXUD module interrupt flag Position */
#define I2S_FLAG_TX (1<<I2S_FLAG_TX_Pos) /*!< INT_SRC: TX interrupt flag */
#define I2S_FLAG_RX (1<<I2S_FLAG_RX_Pos) /*!< INT_SRC: RX interrupt flag */
#define I2S_FLAG_I2S (1<<I2S_FLAG_I2S_Pos) /*!< INT_SRC: I2S module interrupt flag */
#define I2S_FLAG_LZC (1<<I2S_FLAG_LZC_Pos) /*!< INT_SRC: LZC module interrupt flag */
#define I2S_FLAG_RZC (1<<I2S_FLAG_RZC_Pos) /*!< INT_SRC: RZC module interrupt flag */
#define I2S_FLAG_TXDONE (1<<I2S_FLAG_TXDONE_Pos) /*!< INT_SRC: TXDONE module interrupt flag */
#define I2S_FLAG_TXTH (1<<I2S_FLAG_TXTH_Pos) /*!< INT_SRC: TXTH module interrupt flag */
#define I2S_FLAG_TXOV (1<<I2S_FLAG_TXOV_Pos) /*!< INT_SRC: TXOV module interrupt flag */
#define I2S_FLAG_TXUD (1<<I2S_FLAG_TXUD_Pos) /*!< INT_SRC: TXUD module interrupt flag */
#define I2S_FLAG_RXDONE (1<<I2S_FLAG_RXDONE_Pos) /*!< INT_SRC: RXDONE module interrupt flag */
#define I2S_FLAG_RXTH (1<<I2S_FLAG_RXTH_Pos) /*!< INT_SRC: RXTH module interrupt flag */
#define I2S_FLAG_RXOV (1<<I2S_FLAG_RXOV_Pos) /*!< INT_SRC: RXOV module interrupt flag */
#define I2S_FLAG_RXUD (1<<I2S_FLAG_RXUD_Pos) /*!< INT_SRC: RXUD module interrupt flag */
#define I2S_RX_FIFO_CNT_MASK (0x0F) /*!< RX fifo count mask */
#define I2S_TX_FIFO_CNT_MASK (0xF0) /*!< TX fifo count mask */
#define I2S_MAX_RXTXFIFO_LEVEL (8) /*!< max rx/tx fifo level */
#define WM_I2S_TX_DMA_CHANNEL (4)
#define WM_I2S_RX_DMA_CHANNEL (5)
typedef void (*tls_i2s_callback)();
typedef struct
{
/** I2S Control Register */
__IO uint32_t CTRL;
/** I2S Interrupt mask Register */
__IO uint32_t INT_MASK;
/** I2S Interrupt source Register */
__IO uint32_t INT_SRC;
/** I2S Interrupt status Register */
__I uint32_t INT_STATUS;
/** I2S TX data Register */
__O uint32_t TX;
/** I2S RX data Register */
__I uint32_t RX;
} I2S_T;
/** base address of the I2S module */
#define I2S ((I2S_T *)HR_I2S_REG_BASE)
typedef enum
{
/** left channel select */
I2S_CHANNEL_LEFT = I2S_CTRL_CHSEL_LEFT,
/** right channel select */
I2S_CHANNEL_RIGHT = I2S_CTRL_CHSEL_RIGHT
} I2S_CHANNEL_SEL;
typedef struct tls_i2s_options
{
/** I2S receiver enable */
uint8_t rx_en;
/** I2S transfer enable */
uint8_t tx_en;
/** I2S Stereo or Monaural
- \ref I2S_CTRL_STERO
- \ref I2S_CTRL_MONO
*/
uint32_t stereo_mono;
/** I2S module format
- \ref I2S_CTRL_FORMAT_I2S
- \ref I2S_CTRL_FORMAT_MSB
- \ref I2S_CTRL_FORMAT_PCMA
- \ref I2S_CTRL_FORMAT_PCMB
*/
uint32_t format;
/** I2S module data width
- \ref I2S_CTRL_DATABIT_8
- \ref I2S_CTRL_DATABIT_16
- \ref I2S_CTRL_DATABIT_24
- \ref I2S_CTRL_DATABIT_32
*/
uint32_t data_width;
/** I2S module sample rate max 128KHz */
uint32_t sample_rate;
} tls_i2s_options_t;
typedef struct tls_i2s_buf_t
{
/** pointer the bufffer address */
uint32_t * buf;
/** the buffer size in bytes */
uint16_t len;
/** current position of the data */
uint16_t index;
}tls_i2s_buf;
typedef struct _tls_i2s_port
{
/** i2s config params */
struct tls_i2s_options opts;
/** pointer to the I2S registers */
I2S_T * regs;
/** the semaphore used to synchronous transmission */
tls_os_sem_t *tx_sem;
/** instance of tls_i2s_buf struct for data receive */
tls_i2s_buf rx_buf;
/** instance of tls_i2s_buf struct for data receive */
tls_i2s_buf tx_buf;
/** function pointer for data receiver when in interrupt mode */
void (*rx_callback)(u16 len);
/** function pointer for data transmit when in interrupt mode */
void (*tx_callback)(u16 len);
} tls_i2s_port_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 This function is used to initial i2s port.
* @param[in] opts the i2s setting options,if this param is NULL,this function will use the default options.
* @retval
* - \ref WM_SUCCESS
* - \ref WM_FAILED
*
*/
int tls_i2s_port_init(tls_i2s_options_t *opts);
/**
* @brief This function is used to config i2s port.
* @param[in] opts is the i2s setting options
*
*/
void tls_i2s_config(tls_i2s_options_t *opts);
/**
* @brief Set the frequency of the i2s port.
* @param[in] freq the required frequency of the i2s module
* @retval
*
*/
void tls_i2s_set_freq(uint32_t freq);
/**
* @brief
* set the frequency of the i2s port.
*
* @param[in] freq
* the required frequency of the i2s module
* @param[in] exclk
* the frequency of the external clock
*
* @retval
*
*/
void wm_i2s_set_freq_exclk(uint32_t freq, uint32_t exclk);
/**
* @brief This function is used to transfer data in blocking mode.
* @param[in] buf pointer to data buffer
* @param[in] len amount of data to be sent.
* @retval
* - \ref WM_SUCCESS
* - \ref WM_FAILED
*/
int tls_i2s_tx_block(uint32_t *buf, uint16_t len);
/**
* @brief This function is used to transfer data in non-blocking mode.
* @param[in] buf pointer to data buffer
* @param[in] len bytes of data to be sent.
* @param[in] tx_callback function pointer to a callback,when the data have been sent this specified function will be called
* @retval
* - \ref WM_SUCCESS
* - \ref WM_FAILED
* @note
* this function only submit the data
* when the data transfer finished the tx_callback function will be called
*/
int tls_i2s_tx_nonblock(uint32_t *buf, uint16_t len, void (*tx_callback)(u16 len));
/**
* @brief This function is used to receive data in non-blocking mode.
* @param[in] buf pointer to data buffer
* @param[in] len bytes of data to be sent.
* @param[in] rx_callback function pointer to a callback,when the data have been received this specified function will be called
*
* @retval
* - \ref WM_SUCCESS
* - \ref WM_FAILED
* @note
*
*/
int tls_i2s_rx_nonblock(uint32_t *buf, uint16_t len, void (*rx_callback)(u16 len));
/**
* @brief This function is used to receive data in DMA mode.
* @param[in] buf pointer to data buffer
* @param[in] len bytes of data to be sent.
* @param[in] callback function pointer to a callback,when the data have been sent this specified function will be called
* @retval
* - \ref WM_SUCCESS
* - \ref WM_FAILED
* @note
*
*/
int tls_i2s_tx_dma(uint32_t * addr, uint16_t len, tls_i2s_callback callback);
/**
* @brief This function is used to receive data in DMA mode.
* @param[in] addr pointer to data buffer
* @param[in] len bytes of data to be sent.
* @param[in] callback function pointer to a callback,when the data have been received this specified function will be called
* @retval
* - \ref WM_SUCCESS
* - \ref WM_FAILED
* @note
* this function only submit the data
* when the data transfer finished the callback function will be called
*/
int tls_i2s_rx_dma(uint32_t * addr, uint16_t len, tls_i2s_callback callback);
/**
* @brief Enable I2S module
*
*/
#define TLS_I2S_ENABLE() (I2S->CTRL |= I2S_CTRL_EN_MASK)
/**
* @brief Disable I2S module
*
*/
#define TLS_I2S_DISABLE() (I2S->CTRL &= ~I2S_CTRL_EN_MASK)
/**
* @brief Enable clock of I2S module
*
*/
#define TLS_I2S_CLK_ENABLE() \
do { \
tls_bitband_write(HR_CLK_I2S_CTL, HR_CLK_I2S_GATE_Pos , 1); \
} while(0)
/**
* @brief Disnable clock of I2S module
*
*/
#define TLS_I2S_CLK_DISABLE() \
do { \
tls_bitband_write(HR_CLK_I2S_CTL, HR_CLK_I2S_GATE_Pos , 0); \
} while(0)
/**
* @brief Enable transmit of I2S module
*
*/
#define TLS_I2S_TX_ENABLE() \
do { \
tls_bitband_write(HR_I2S_CTRL, I2S_CTRL_TXE_Pos, 1); \
} while(0)
/**
* @brief Disable transmit of I2S module
*
*/
#define TLS_I2S_TX_DISABLE() \
do { \
tls_bitband_write(HR_I2S_CTRL, I2S_CTRL_TXE_Pos, 0); \
} while(0)
/**
* @brief Enable receive of I2S module
*
*/
#define TLS_I2S_RX_ENABLE() \
do { \
tls_bitband_write(HR_I2S_CTRL, I2S_CTRL_RXE_Pos, 1); \
} while(0)
/**
* @brief Disable receive of I2S module
*
*/
#define TLS_I2S_RX_DISABLE() \
do { \
tls_bitband_write(HR_I2S_CTRL, I2S_CTRL_RXE_Pos, 0); \
} while(0)
/**
* @brief Clear receive FIFO
*
*/
#define TLS_I2S_RX_FIFO_CLEAR() \
do { \
tls_bitband_write(HR_I2S_CTRL, I2S_CTRL_RX_CLR_Pos, 1); \
} while(0)
/**
* @brief Clear transmit FIFO
*
*/
#define TLS_I2S_TX_FIFO_CLEAR() \
do { \
tls_bitband_write(HR_I2S_CTRL, I2S_CTRL_TX_CLR_Pos, 1); \
} while(0)
/**
* @brief Enable transmit DMA request
*
*/
#define TLS_I2S_TXDMA_ENABLE() (I2S->CTRL |= I2S_CTRL_TXDMA_MASK)
/**
* @brief Disnable transmit DMA request
*
*/
#define TLS_I2S_TXDMA_DISABLE() (I2S->CTRL &= ~I2S_CTRL_TXDMA_MASK)
/**
* @brief Enable receive DMA request
*
*/
#define TLS_I2S_RXDMA_ENABLE() (I2S->CTRL |= I2S_CTRL_RXDMA_MASK)
/**
* @brief Disnable receive DMA request
*
*/
#define TLS_I2S_RXDMA_DISABLE() (I2S->CTRL &= ~I2S_CTRL_RXDMA_MASK)
/**
* @brief Left channel zero-cross detection enable
*
*/
#define TLS_I2S_LZC_ENABLE() (I2S->CTRL |= I2S_CTRL_LZCEN_MASK)
/**
* @brief Left channel zero-cross detection disable
*
*/
#define TLS_I2S_LZC_DISABLE() (I2S->CTRL &= ~I2S_CTRL_LZCEN_MASK)
/**
* @brief Right channel zero-cross detection enable
*
*/
#define TLS_I2S_RZC_ENABLE() (I2S->CTRL |= I2S_CTRL_RZCEN_MASK)
/**
* @brief Right channel zero-cross detection disable
*
*/
#define TLS_I2S_RZC_DISABLE() (I2S->CTRL &= ~I2S_CTRL_RZCEN_MASK)
/** @brief Enable transmit mute
*
*/
#define TLS_I2S_TX_MUTE_ENABLE() (I2S->CTRL |= I2S_CTRL_MUTE_MASK)
/**
* @brief Disable transmit mute
*
*/
#define TLS_I2S_TX_MUTE_DISABLE() (I2S->CTRL &= ~ I2S_CTRL_MUTE_MASK)
/**
* @brief Set receive FIFO threshold level
* @param[in] level The value set to Rx threshold level
*
*/
static __inline__ void tls_i2s_set_rxth(uint8_t level)
{
if (level > 8)
{
level = 3;
}
I2S->CTRL &= ~ I2S_CTRL_RXTH_MASK;
I2S->CTRL |= ((level - 1)<<I2S_CTRL_RXTH_Pos);
}
/**
* @brief Set transmit FIFO threshold level
* @param[in] level The value set to Tx threshold level
*/
static __inline__ void tls_i2s_set_txth(uint8_t level)
{
if (level > 8)
level = 4;
I2S->CTRL &= ~ I2S_CTRL_TXTH_MASK;
I2S->CTRL |= (level<<I2S_CTRL_TXTH_Pos);
}
/**
* @brief Enable or disable receiver of I2S module
* @param[in] enable When one enable the receiver of I2S module, when zero disable
*/
static __inline__ void tls_i2s_channel_sel(I2S_CHANNEL_SEL channel_sel)
{
I2S->CTRL &= ~ I2S_CTRL_CHSEL_MASK;
I2S->CTRL |= channel_sel;
}
/**
* @brief Enables or disables the specified I2S interrupts
* @param[in] i2s_int_mask specifies the I2S interrupt sources to be enabled or disabled.
* This parameter can be one of the following values:
* - \ref I2S_INT_MASK_LZC
* - \ref I2S_INT_MASK_RZC
* - \ref I2S_INT_MASK_TXDONE
* - \ref I2S_INT_MASK_TXTH
* - \ref I2S_INT_MASK_TXOV
* - \ref I2S_INT_MASK_TXUD
* - \ref I2S_INT_MASK_RXDONE
* - \ref I2S_INT_MASK_RXTH
* - \ref I2S_INT_MASK_RXOV
* - \ref I2S_INT_MASK_RXUD
* @param[in] enable when set ,enable interrupt, zero disabled
* @retval None
*/
static __inline__ void tls_i2s_int_config(uint32_t i2s_int_mask, uint8_t enable)
{
if(enable)
{
I2S->INT_MASK &= ~i2s_int_mask;
}
else
{
I2S->INT_MASK |= i2s_int_mask;
}
}
/**
* @brief Enable master clock (MCLK).
* @param[in] clock The target MCLK clock rate.
* @retval actual MCLK clock rate
* @details Set the master clock rate according to u32BusClock parameter and enable master clock output.
* The actual master clock rate may be different from the target master clock rate.
* The real master clock rate will be returned for reference.
*/
uint32_t tls_i2s_mclk_enable(uint32_t clock);
/**
* @brief disable master clock (MCLK).
*
*/
void tls_i2s_mclk_disable(void);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /** __WM_I2S_H*/
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

View File

@@ -0,0 +1,234 @@
/**
* @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_BLOCK_SIZE (0x10000UL)
#define INSIDE_FLS_SECTOR_SIZE (0x1000UL)
#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,
};
/**
* @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)
/**
* @struct tls_inside_fls
*/
struct tls_inside_fls
{
tls_os_sem_t *fls_lock;
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup INTERNAL_FLASH_Driver_APIs INTERNAL_FLASH Driver APIs
* @brief INTERNAL_FLASH driver APIs
*/
/**
* @addtogroup INTERNAL_FLASH_Driver_APIs
* @{
*/
/**
* @brief This function is used to unlock flash protect area [0x0~0x2000].
*
* @param None
*
* @return None
*
* @note None
*/
int tls_flash_unlock(void);
/**
* @brief This function is used to lock flash protect area [0x0~0x2000].
*
* @param None
*
* @return None
*
* @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 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);
#endif /* WM_INTERNAL_FLASH_H */

View File

@@ -0,0 +1,196 @@
/**
* @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
#include "wm_type_def.h"
#define TLS_IO_AB_OFFSET (0x40011200 - 0x40010C00)
/** 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
/* 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
/**
* @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 */

View File

@@ -0,0 +1,163 @@
/**
* @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"
/* Number of interrupts. */
#define INTR_CNT 41
#define SDIO_UP_DATA_INT (0UL)
#define SDIO_DOWN_DATA_INT (1UL)
#define SDIO_UP_CMD_INT (2UL)
#define SDIO_DOWN_CMD_INT (3UL)
#define MAC_INT (4UL)
#define RX_INT (6UL)
#define TX_MGMT_COMPLETE_INT (7UL)
#define TX_DATA_COMPLETE_INT (8UL)
#define PMU_TIMER1_INT (9UL)
#define PMU_TIMER0_INT (10UL)
#define PMU_GPIO_WAKEUP_INT (11UL)
#define PMU_SDIO_WAKEUP_INT (12UL)
#define DMA0_INT (13UL)
#define DMA1_INT (14UL)
#define DMA2_INT (15UL)
#define DMA3_INT (16UL)
#define DMA4_INT (17UL)
#define DMA_BURST_INT (18UL)
#define I2C_INT (19UL)
#define ADC_INT (20UL)
#define SPI0_INT (21UL)
#define SPI1_INT (22UL)
#define UART0_INT (23UL)
#define UART1_INT (24UL)
#define GPIO_INT (25UL)
#define TIMER0_INT (26UL)
#define TIMER1_INT (27UL)
#define TIMER2_INT (28UL)
#define TIMER3_INT (29UL)
#define TIMER4_INT (30UL)
#define TIMER5_INT (31UL)
#define WATCHDOG_INT (32UL)
#define PMU_BOD_INT (33UL)
#define FLASH_INT (34UL)
#define PWM_INT (35UL)
#define I2S_INT (36UL)
#define PMU_RTC_INT (37UL)
#define RSA_INT (38UL)
#define CRYPTION_INT (39UL)
#define GPIOB_INT (40UL)
#define UART2_INT (41UL)
typedef void (*intr_handler_func) (void *);
/**
* @typedef struct tls_irq_handler
*/
typedef struct tls_irq_handler
{
void (*handler) (void *);
void *data;
// const char *name;
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);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_IRQ_H */

View File

@@ -0,0 +1,245 @@
/**
* @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;
/** Data Register */
__IO uint32_t COM01;
/** Data Register */
__IO uint32_t COM23;
/** Data Register */
__IO uint32_t COM45;
/** Data Register */
__IO uint32_t COM67;
/** LCD IO Control Register */
__IO uint32_t IO_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
{
/** max configuration is 8x16 */
MODE8x16 = LCD_CR_MODE_8X16,
/** max configuration is 4x20 */
MODE4x20 = LCD_CR_MODE_4x20,
} LCD_ModeDef;
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;
/** 8x16 or 4x20*/
LCD_ModeDef mode;
/** Bias configuration */
LCD_BiasDef bias;
/** Duty configuration */
LCD_DutyDef duty;
/** Vlcd configuration */
LCD_VlcdDef vlcd;
/** 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 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 the LCD module gpio
*
* @param[in] the config value per bit for one LCD gpio, set enable gpio output ,clear disabled
*
*/
void tls_lcd_io_config(unsigned int val);
/**
* @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. ***/

View File

@@ -0,0 +1,239 @@
/**
* @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
#ifdef __cplusplus
extern "C" {
#endif
#include "wm_type_def.h"
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);
typedef enum {
TLS_PERIPHERAL_TYPE_I2C = (1 << 0),
TLS_PERIPHERAL_TYPE_UART0 = (1 << 1),
TLS_PERIPHERAL_TYPE_UART1 = (1 << 2),
TLS_PERIPHERAL_TYPE_LSPI = (1 << 3),
TLS_PERIPHERAL_TYPE_DMA = (1 << 4),
TLS_PERIPHERAL_TYPE_RFCFG = (1 << 5),
TLS_PERIPHERAL_TYPE_TIMER = (1 << 6),
TLS_PERIPHERAL_TYPE_GPIO = (1 << 7),
TLS_PERIPHERAL_TYPE_SDADC = (1 << 8),
TLS_PERIPHERAL_TYPE_PWM = (1 << 9),
TLS_PERIPHERAL_TYPE_LCD = (1 << 10),
TLS_PERIPHERAL_TYPE_I2S = (1 << 11),
TLS_PERIPHERAL_TYPE_RSA = (1 << 12),
TLS_PERIPHERAL_TYPE_GPSEC = (1 << 13),
TLS_PERIPHERAL_TYPE_7816 = (1 << 14)
}tls_peripheral_type_s;
/**
* @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);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* end of WM_PMU_H */
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

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

View File

@@ -0,0 +1,50 @@
/**
* @file wm_reflector.h
*
* @brief reflector driver module
*
* @author dave
*
* Copyright (c) 2016 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_REFLECTOR_H
#define WM_REFLECTOR_H
#include "wm_type_def.h"
/**
* @brief This function is used to initial the reflector.
*
* @param[in] ctr_io ctrl io
*
* @return None
*
* @note None
*/
void tls_reflector_open(int ctr_io);
/**
* @brief This function is used to close the reflector.
*
* @param[in] ctr_io ctrl io
*
* @return None
*
* @note None
*/
void tls_reflector_close(int ctr_io);
/**
* @brief This function is used to read reflector output status.
*
* @param[in] out_io output io
*
* @retval output status
*
* @note None
*/
int tls_reflector_output_status(int out_io);
#endif

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

View File

@@ -0,0 +1,295 @@
/*****************************************************************************
*
* File Name : wm_spi_hal.h
*
* Description: host spi Driver Module
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-6-6
*****************************************************************************/
#include "wm_regs.h"
#include "list.h"
#include "wm_hostspi.h"
#include "wm_cpu.h"
static __inline void spi_set_mode(u8 mode);
static __inline void spi_set_mode(u8 mode)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_SPICFG_REG);
switch (mode) {
case TLS_SPI_MODE_0:
reg_val &= ~(0x03U);
reg_val |= (SPI_SET_CPOL(0) | SPI_SET_CPHA(0));
break;
case TLS_SPI_MODE_1:
reg_val &= ~(0x03U);
reg_val |= (SPI_SET_CPOL(0) | SPI_SET_CPHA(1));
break;
case TLS_SPI_MODE_2:
reg_val &= ~(0x03U);
reg_val |= (SPI_SET_CPOL(1) | SPI_SET_CPHA(0));
break;
case TLS_SPI_MODE_3:
reg_val &= ~(0x03U);
reg_val |= (SPI_SET_CPOL(1) | SPI_SET_CPHA(1));
break;
default:
break;
}
tls_reg_write32(HR_SPI_SPICFG_REG, reg_val);
}
static __inline void spi_set_endian(u8 endian)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_SPICFG_REG);
if (endian == 0) {
reg_val &= ~(0x01U << 3);
reg_val |= SPI_LITTLE_ENDIAN;
} else if(endian == 1) {
reg_val &= ~(0x01U << 3);
reg_val |= SPI_BIG_ENDIAN;
}
tls_reg_write32(HR_SPI_SPICFG_REG, reg_val);
}
static __inline void spi_set_chipselect_mode(u8 cs_active)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_CHCFG_REG);
if (cs_active == 0) {
reg_val &= ~(0x01U << 2);
reg_val |= SPI_CS_LOW;
} else if(cs_active == 1) {
reg_val &= ~(0x01U << 2);
reg_val |= SPI_CS_HIGH;
}
tls_reg_write32(HR_SPI_CHCFG_REG, reg_val);
}
static __inline void spi_clear_fifo(void)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_CHCFG_REG);
reg_val |= SPI_CLEAR_FIFOS;
tls_reg_write32(HR_SPI_CHCFG_REG, reg_val);
}
static __inline void spi_set_rx_channel(u8 on_off)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_CHCFG_REG);
if (on_off == 0) {
reg_val &= ~(0x01U << 20);
reg_val |= SPI_RX_CHANNEL_OFF;
} else if(on_off == 1) {
reg_val &= ~(0x01U << 20);
reg_val |= SPI_RX_CHANNEL_ON;
}
tls_reg_write32(HR_SPI_CHCFG_REG, reg_val);
}
static __inline void spi_set_tx_channel(u8 on_off)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_CHCFG_REG);
if (on_off == 0) {
reg_val &= ~(0x01U << 19);
reg_val |= SPI_TX_CHANNEL_OFF;
} else if(on_off == 1) {
reg_val &= ~(0x01U << 19);
reg_val |= SPI_TX_CHANNEL_ON;
}
tls_reg_write32(HR_SPI_CHCFG_REG, reg_val);
}
static __inline void spi_set_sclk_length(u16 sclk_num, u8 invalid_rx_sclk_num)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_CHCFG_REG);
reg_val &= ~((0xffU << 23) | (0xffff << 3));
reg_val |= SPI_VALID_CLKS_NUM(sclk_num) | SPI_RX_INVALID_BITS(invalid_rx_sclk_num);
tls_reg_write32(HR_SPI_CHCFG_REG, reg_val);
}
static __inline void spi_force_cs_out(u8 enable)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_CHCFG_REG);
if (enable) {
reg_val |= SPI_FORCE_SPI_CS_OUT;
} else {
reg_val &= ~SPI_FORCE_SPI_CS_OUT;
}
tls_reg_write32(HR_SPI_CHCFG_REG, reg_val);
}
static __inline void spi_sclk_start(void)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_CHCFG_REG);
reg_val |= SPI_START;
tls_reg_write32(HR_SPI_CHCFG_REG, reg_val);
}
static __inline void spi_set_sclk(u32 fclk)
{
u32 reg_val;
tls_sys_clk sysclk;
tls_sys_clk_get(&sysclk);
reg_val = tls_reg_read32(HR_SPI_CLKCFG_REG);
reg_val &= ~(0xffffU);
reg_val |= sysclk.apbclk*UNIT_MHZ/(fclk*2) - 1;
tls_reg_write32(HR_SPI_CLKCFG_REG, reg_val);
}
static __inline void spi_set_tx_trigger_level(u8 level)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_MODECFG_REG);
reg_val &= ~(0x07U << 2);
reg_val |= SPI_TX_TRIGGER_LEVEL(level);
tls_reg_write32(HR_SPI_MODECFG_REG, reg_val);
}
static __inline void spi_set_rx_trigger_level(u8 level)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_MODECFG_REG);
reg_val &= ~(0x07U << 6);
reg_val |= SPI_RX_TRIGGER_LEVEL(level);
tls_reg_write32(HR_SPI_MODECFG_REG, reg_val);
}
static __inline void spi_set_timeout(u32 timeout, u8 enable)
{
u32 reg_val;
reg_val = SPI_TIME_OUT(timeout);
reg_val |= enable ? SPI_TIMER_EN : 0;
tls_reg_write32(HR_SPI_TIMEOUT_REG, reg_val);
}
static __inline void spi_get_status(u8 *busy, u8 *rx_fifo_level, u8 *tx_fifo_level)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_STATUS_REG);
if (busy) {*busy = SPI_IS_BUSY(reg_val);}
if (rx_fifo_level) {*rx_fifo_level = SPI_GET_RX_FIFO_CNT(reg_val);}
if (tx_fifo_level) {*tx_fifo_level = 32 - SPI_GET_TX_FIFO_CNT(reg_val);}
}
static __inline u32 spi_int_mask(void)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_INT_MASK_REG);
return reg_val & SPI_INT_MASK_ALL;
}
static __inline void spi_mask_int(u32 mask)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_INT_MASK_REG);
reg_val |= mask & SPI_INT_MASK_ALL;
tls_reg_write32(HR_SPI_INT_MASK_REG, reg_val);
}
static __inline void spi_unmask_int(u32 mask)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_INT_MASK_REG);
reg_val &= ~(mask & SPI_INT_MASK_ALL);
tls_reg_write32(HR_SPI_INT_MASK_REG, reg_val);
}
static __inline u32 spi_get_int_status(void)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_INT_STATUS_REG);
return reg_val;
}
static __inline void spi_clear_int_status(u32 int_srcs)
{
u32 reg_val;
reg_val = tls_reg_read32(HR_SPI_INT_STATUS_REG);
reg_val &= ~(int_srcs & SPI_INT_CLEAR_ALL);
reg_val |= int_srcs & SPI_INT_CLEAR_ALL;
tls_reg_write32(HR_SPI_INT_STATUS_REG, reg_val);
}
static __inline void spi_data_put(u32 data)
{
tls_reg_write32(HR_SPI_TXDATA_REG, data);
}
static __inline u32 spi_data_get(void)
{
return tls_reg_read32(HR_SPI_RXDATA_REG);
}

View File

@@ -0,0 +1,141 @@
/**
* @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
#define TIMER_MS_UNIT_FLAG 1
#define TIMER_US_UNIT_FLAG 0
/** 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 delete a timer
*
* @param[in] timer_id timer id
*
* @return None
*
* @note None
*/
void tls_timer_destroy(u8 timer_id);
/**
* @brief This function is create a delay to elapse
*
* @param[timeout] timeout the value writed into TMR0_PRD
* @param[in] m_flag millisecond flag in TIMER0
*
* @return None
*
* @note None
*/
int tls_delay_via_timer(unsigned int timeout, unsigned int m_flag);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_TIMER_H */

View File

@@ -0,0 +1,451 @@
/**
* @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)
#ifndef UART0_INT
#define UART0_INT (23UL)
#endif
#ifndef UART1_INT
#define UART1_INT (24UL)
#endif
/** 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,
};
/**
* @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
{
u8 *buf;
u32 head;
u32 tail;
} tls_uart_circ_buf_t;
/**
* @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);
s16(*tx_callback) (struct tls_uart_port * port);
bool tx_dma_on;
} 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. TLS_UART_0 or TLS_UART_1
* @param[in] opts is the uart setting options,if this param is NULL,this function will use the default options.
*
* @retval WM_SUCCESS success
* @retval WM_FAILED 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));
/**
* @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 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);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_UART_H */

View File

@@ -0,0 +1,297 @@
/*
* ESPRSSIF MIT License
*
* Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __UART_H__
#define __UART_H__
#ifdef __cplusplus
extern "C" {
#endif
#define ETS_UART_INTR_ENABLE() _xt_isr_unmask(1 << ETS_UART_INUM)
#define ETS_UART_INTR_DISABLE() _xt_isr_mask(1 << ETS_UART_INUM)
#define UART_INTR_MASK 0x1ff
#define UART_LINE_INV_MASK (0x3f<<19)
typedef enum {
UART_WordLength_5b = 0x0,
UART_WordLength_6b = 0x1,
UART_WordLength_7b = 0x2,
UART_WordLength_8b = 0x3
} UART_WordLength;
typedef enum {
USART_StopBits_1 = 0x0,
USART_StopBits_2 = 0x1,
} UART_StopBits;
typedef enum {
UART0 = 0x0,
UART1 = 0x1,
} UART_Port;
typedef enum {
USART_Parity_None = 0x2,
USART_Parity_Even = 0x0,
USART_Parity_Odd = 0x1
} UART_ParityMode;
typedef enum {
PARITY_DIS = 0x0,
PARITY_EN = 0x2
} UartExistParity;
typedef enum {
BIT_RATE_300 = 300,
BIT_RATE_600 = 600,
BIT_RATE_1200 = 1200,
BIT_RATE_2400 = 2400,
BIT_RATE_4800 = 4800,
BIT_RATE_9600 = 9600,
BIT_RATE_19200 = 19200,
BIT_RATE_38400 = 38400,
BIT_RATE_57600 = 57600,
BIT_RATE_74880 = 74880,
BIT_RATE_115200 = 115200,
BIT_RATE_230400 = 230400,
BIT_RATE_460800 = 460800,
BIT_RATE_921600 = 921600,
BIT_RATE_1843200 = 1843200,
BIT_RATE_3686400 = 3686400,
} UART_BautRate; //you can add any rate you need in this range
typedef enum {
USART_HardwareFlowControl_None = 0x0,
USART_HardwareFlowControl_RTS = 0x1,
USART_HardwareFlowControl_CTS = 0x2,
USART_HardwareFlowControl_CTS_RTS = 0x3
} UART_HwFlowCtrl;
//typedef enum {
// UART_None_Inverse = 0x0,
// UART_Rxd_Inverse = UART_RXD_INV,
// UART_CTS_Inverse = UART_CTS_INV,
// UART_Txd_Inverse = UART_TXD_INV,
// UART_RTS_Inverse = UART_RTS_INV,
//} UART_LineLevelInverse;
typedef struct {
UART_BautRate baud_rate;
UART_WordLength data_bits;
UART_ParityMode parity; // chip size in byte
UART_StopBits stop_bits;
UART_HwFlowCtrl flow_ctrl;
u8 UART_RxFlowThresh ;
// u32 UART_InverseMask;
} UART_ConfigTypeDef;
typedef struct {
u32 UART_IntrEnMask;
u8 UART_RX_TimeOutIntrThresh;
u8 UART_TX_FifoEmptyIntrThresh; //txfifo trigger level
u8 UART_RX_FifoFullIntrThresh; //rxfifo trigger level
} UART_IntrConfTypeDef;
//=======================================
/** \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 Wait uart tx fifo empty, do not use it if tx flow control enabled.
*
* @param UART_Port uart_no:UART0 or UART1
*
* @return null
*/
void UART_WaitTxFifoEmpty(UART_Port uart_no); //do not use if tx flow control enabled
/**
* @brief Clear uart tx fifo and rx fifo.
*
* @param UART_Port uart_no : UART0 or UART1
*
* @return null
*/
void UART_ResetFifo(UART_Port uart_no);
/**
* @brief Clear uart interrupt flags.
*
* @param UART_Port uart_no : UART0 or UART1
* @param u32 clr_mask : To clear the interrupt bits
*
* @return null
*/
void UART_ClearIntrStatus(UART_Port uart_no, u32 clr_mask);
/**
* @brief Enable uart interrupts .
*
* @param UART_Port uart_no : UART0 or UART1
* @param u32 ena_mask : To enable the interrupt bits
*
* @return null
*/
void UART_SetIntrEna(UART_Port uart_no, u32 ena_mask);
/**
* @brief Register an application-specific interrupt handler for Uarts interrupts.
*
* @param UART_Port uart_no : UART0 or UART1
* @param void *fn : interrupt handler for Uart interrupts.
* @param void *arg : interrupt handler's arg.
*
* @return null
*/
void UART_intr_handler_register(UART_Port uart_no, void *fn, void *arg);
/**
* @brief Config from which serial output printf function.
*
* @param UART_Port uart_no : UART0 or UART1
*
* @return null
*/
void UART_SetPrintPort(UART_Port uart_no);
/**
* @brief Config Common parameters of serial ports.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_ConfigTypeDef *pUARTConfig : parameters structure
*
* @return null
*/
void UART_ParamConfig(UART_Port uart_no, UART_ConfigTypeDef *pUARTConfig);
/**
* @brief Config types of uarts.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_IntrConfTypeDef *pUARTIntrConf : parameters structure
*
* @return null
*/
void UART_IntrConfig(UART_Port uart_no, UART_IntrConfTypeDef *pUARTIntrConf);
/**
* @brief Config the length of the uart communication data bits.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_WordLength len : the length of the uart communication data bits
*
* @return null
*/
void UART_SetWordLength(UART_Port uart_no, UART_WordLength len);
/**
* @brief Config the length of the uart communication stop bits.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_StopBits bit_num : the length uart communication stop bits
*
* @return null
*/
void UART_SetStopBits(UART_Port uart_no, UART_StopBits bit_num);
/**
* @brief Configure whether to open the parity.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_ParityMode Parity_mode : the enum of uart parity configuration
*
* @return null
*/
void UART_SetParity(UART_Port uart_no, UART_ParityMode Parity_mode) ;
/**
* @brief Configure the Baud rate.
*
* @param UART_Port uart_no : UART0 or UART1
* @param u32 baud_rate : the Baud rate
*
* @return null
*/
void UART_SetBaudrate(UART_Port uart_no, u32 baud_rate);
/**
* @brief Configure Hardware flow control.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_HwFlowCtrl flow_ctrl : Hardware flow control mode
* @param u8 rx_thresh : threshold of Hardware flow control
*
* @return null
*/
void UART_SetFlowCtrl(UART_Port uart_no, UART_HwFlowCtrl flow_ctrl, u8 rx_thresh);
/**
* @brief Configure trigging signal of uarts.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_LineLevelInverse inverse_mask : Choose need to flip the IO
*
* @return null
*/
//void UART_SetLineInverse(UART_Port uart_no, UART_LineLevelInverse inverse_mask) ;
/**
* @brief An example illustrates how to configure the serial port.
*
* @param null
*
* @return null
*/
void uart_init_new(void);
void uart0_write_char(char c);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,75 @@
/**
* @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 reset the system.
*
* @param None
*
* @return None
*
* @note None
*/
void tls_sys_reset(void);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_WATCHDOG_H */

View File

@@ -0,0 +1,309 @@
/*
* @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 */

View File

@@ -0,0 +1,186 @@
/**
* @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 "crypto/cryptoApi.h"
#include <stddef.h>
#include "wm_type_def.h"
#define USE_AES
#define PSPUBLIC
#ifndef CRYPT_INVALID_KEYSIZE
#define CRYPT_INVALID_KEYSIZE -21
#endif
#ifndef MAXBLOCKSIZE
#define MAXBLOCKSIZE 24
#endif
#define STORE32H(x, y) { \
(y)[0] = (unsigned char)(((x)>>24)&255); \
(y)[1] = (unsigned char)(((x)>>16)&255); \
(y)[2] = (unsigned char)(((x)>>8)&255); \
(y)[3] = (unsigned char)((x)&255); \
}
#define LOAD32H(x, y) { \
x = ((unsigned long)((y)[0] & 255)<<24) | \
((unsigned long)((y)[1] & 255)<<16) | \
((unsigned long)((y)[2] & 255)<<8) | \
((unsigned long)((y)[3] & 255)); \
}
#define byte(x, n) (((x) >> (8 * (n))) & 255)
#define ROR(x, y) \
( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | \
((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
#define psTraceCrypto(x)
/******************************************************************************/
/*
Universal return codes
*/
#define PS_SUCCESS 0
#define PS_FAILURE -1
/* NOTE: Failure return codes MUST be < 0 */
/* NOTE: The range for core error codes should be between -2 and -29 */
#define PS_ARG_FAIL -6 /* Failure due to bad function param */
#define PS_PLATFORM_FAIL -7 /* Failure as a result of system call error */
#define PS_MEM_FAIL -8 /* Failure to allocate requested memory */
#define PS_LIMIT_FAIL -9 /* Failure on sanity/limit tests */
#define PS_UNSUPPORTED_FAIL -10 /* Unimplemented feature error */
#define PS_DISABLED_FEATURE_FAIL -11 /* Incorrect #define toggle for feature */
#define PS_PROTOCOL_FAIL -12 /* A protocol error occurred */
#define PS_TIMEOUT_FAIL -13 /* A timeout occurred and MAY be an error */
#define PS_INTERRUPT_FAIL -14 /* An interrupt occurred and MAY be an error */
#define PS_PENDING -15 /* In process. Not necessarily an error */
#define PS_EAGAIN -16 /* Try again later. Not necessarily an error */
#define PS_TRUE 1
#define PS_FALSE 0
//typedef int int32; //调用wm_type_def.h
//typedef unsigned int uint32;
//typedef short int16;
//typedef unsigned short uint16;
//typedef unsigned char uint8;
//typedef long long int64;
//typedef unsigned long long uint64;
//#if (GCC_COMPILE==0)
//typedef unsigned int size_t;
//#endif
/******************************************************************************/
#ifdef USE_AES
/******************************************************************************/
#ifndef USE_AES_CBC_EXTERNAL
typedef struct {
unsigned int eK[64], dK[64];
int Nr;
} psAesKey_t;
typedef struct {
int blocklen;
unsigned char IV[16];
psAesKey_t key;
#if defined(USE_AES_GCM) || defined(USE_AES_CCM)
unsigned char EncCtr[16];
unsigned char CtrBlock[16];
#endif
#ifdef USE_AES_GCM
unsigned char gInit[16];
unsigned int TagTemp[4];
unsigned char Hash_SubKey[16];
unsigned int ProcessedBitCount[4];
unsigned int InputBufferCount;
unsigned int OutputBufferCount;
union
{
unsigned char Buffer[128];
unsigned int BufferAlignment;
} Input;
#endif /* USE_AES_GCM */
#ifdef USE_AES_CCM
unsigned int ccmTagTemp[16 / sizeof(unsigned int)]; /* 32 */
union
{
/* Used for formatting IV. */
unsigned char Temporary[16];
/* Used for processing Mac. */
unsigned char Y0[16];
} u; /* 48 */
#endif /* USE_AES_CCM */
} psAesCipher_t;
typedef union {
#ifdef USE_AES
psAesCipher_t aes;
#endif
} psAesCipherContext_t;
#endif /* USE_AES_CBC_EXTERNAL */
#endif /* USE_AES */
#if 0
void * aes_encrypt_init(const u8 *key, size_t len);
void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
void aes_encrypt_deinit(void *ctx);
void * aes_decrypt_init(const u8 *key, size_t len);
void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain);
void aes_decrypt_deinit(void *ctx);
#endif
#ifndef USE_AES
#error "Must Enable USE_AES in cryptoConfig.h!"
#endif
#ifdef USE_AES
/******************************************************************************/
/*
CBC Mode AES
*/
PSPUBLIC int psAesInit(psAesCipherContext_t *ctx, unsigned char *IV,
unsigned char *key, unsigned int keylen);
PSPUBLIC int psAesDecrypt(psAesCipherContext_t *ctx, unsigned char *ct,
unsigned char *pt, unsigned int len);
PSPUBLIC int psAesEncrypt(psAesCipherContext_t *ctx, unsigned char *pt,
unsigned char *ct, unsigned int len);
/*
Block Mode AES
*/
PSPUBLIC int psAesInitKey(const unsigned char *key, unsigned int keylen,
psAesKey_t *skey);
PSPUBLIC void psAesEncryptBlock(const unsigned char *pt, unsigned char *ct,
psAesKey_t *skey);
PSPUBLIC void psAesDecryptBlock(const unsigned char *ct, unsigned char *pt,
psAesKey_t *skey);
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
#endif /* AES_H */

View File

@@ -0,0 +1,513 @@
/**
* @file wm_crypto_hard.h
*
* @brief hard crypto module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_CRYPTO_HARD_H
#define WM_CRYPTO_HARD_H
#include "wm_type_def.h"
#include "cryptoConfig.h"
#include "digest.h"
#include "pstm.h"
#include "symmetric.h"
#include "cryptolib.h"
#include "cryptoApi.h"
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif /* min */
/** The base address of the registers of encryption/decryption module. */
#define HR_CRYPTO_BASE_ADDR 0x40003200
/** The address of the source text address register. */
#define HR_CRYPTO_SRC_ADDR (HR_CRYPTO_BASE_ADDR + 0x00)
/** The address of the encrypted/decrypted text address register. */
#define HR_CRYPTO_DEST_ADDR (HR_CRYPTO_BASE_ADDR + 0x04)
/** The address of the configuration register. */
#define HR_CRYPTO_SEC_CFG (HR_CRYPTO_BASE_ADDR + 0x08)
/** The address of the control register. */
#define HR_CRYPTO_SEC_CTRL (HR_CRYPTO_BASE_ADDR + 0x0C)
/** The address of the key0 register. */
#define HR_CRYPTO_KEY0 (HR_CRYPTO_BASE_ADDR + 0x10)
/** The address of the key1 register. */
#define HR_CRYPTO_KEY1 (HR_CRYPTO_BASE_ADDR + 0x14)
/** The address of the key2 register. */
#define HR_CRYPTO_KEY2 (HR_CRYPTO_BASE_ADDR + 0x18)
/** The address of the key3 register. */
#define HR_CRYPTO_KEY3 (HR_CRYPTO_BASE_ADDR + 0x1C)
/** The address of the key4 register. */
#define HR_CRYPTO_KEY4 (HR_CRYPTO_BASE_ADDR + 0x20)
/** The address of the key5 register. */
#define HR_CRYPTO_KEY5 (HR_CRYPTO_BASE_ADDR + 0x24)
/** The address of the IV0 register. */
#define HR_CRYPTO_IV0 (HR_CRYPTO_BASE_ADDR + 0x28)
/** The address of the IV1 register. */
#define HR_CRYPTO_IV1 (HR_CRYPTO_BASE_ADDR + 0x20)
/** The address of the encrypted/decrypted status register. */
#define HR_CRYPTO_SEC_STS (HR_CRYPTO_BASE_ADDR + 0x30)
/** The address of the SHA1/MD5 digest0 register. */
#define HR_CRYPTO_SHA1_DIGEST0 (HR_CRYPTO_BASE_ADDR + 0x34)
/** The address of the SHA1/MD5 digest1 register. */
#define HR_CRYPTO_SHA1_DIGEST1 (HR_CRYPTO_BASE_ADDR + 0x38)
/** The address of the SHA1/MD5 digest2 register. */
#define HR_CRYPTO_SHA1_DIGEST2 (HR_CRYPTO_BASE_ADDR + 0x3C)
/** The address of the SHA1/MD5 digest3 register. */
#define HR_CRYPTO_SHA1_DIGEST3 (HR_CRYPTO_BASE_ADDR + 0x40)
/** The address of the SHA1 digest4 and CRC in/output register. */
#define HR_CRYPTO_SHA1_DIGEST4 (HR_CRYPTO_BASE_ADDR + 0x44)
/** The address of the RNG RESULT register. */
#define HR_CRYPTO_RNG_RESULT (HR_CRYPTO_BASE_ADDR + 0x48)
/** The address of the CRC in register. */
#define HR_CRYPTO_CRC_KEY HR_CRYPTO_SHA1_DIGEST4
/** The address of the CRC output register. */
#define HR_CRYPTO_CRC_RESULT HR_CRYPTO_SHA1_DIGEST4
#define ERR_CRY_OK 0 ///< No error, everything OK.
#define ERR_FAILURE -1 /* failure */
#define ERR_ARG_FAIL -6 /* Failure due to bad function param */
//CRC
#define OUTPUT_REFLECT 1
#define INPUT_REFLECT 2
typedef enum __CRYPTO_METHOD
{
CRYPTO_METHOD_RSV=0,
CRYPTO_METHOD_RC4,
CRYPTO_METHOD_SHA1,
CRYPTO_METHOD_AES,
CRYPTO_METHOD_DES,
CRYPTO_METHOD_3DES,
CRYPTO_METHOD_CRC, ///< CRC
CRYPTO_METHOD_MD5 ///< MD5
}CRYPTO_METHOD;
/**
* The enum of the encryption/decryption way.
*/
typedef enum __CRYPTO_WAY
{
CRYPTO_WAY_ENCRYPT=0, ///< Encryption
CRYPTO_WAY_DECRYPT ///< Decryption
}CRYPTO_WAY;
typedef enum __CRYPTO_RNG_SWITCH
{
CRYPTO_RNG_SWITCH_16 = 0,
CRYPTO_RNG_SWITCH_32
}CRYPTO_RNG_SWITCH;
/**
* The enum of the encryption/decryption mode, only for (aes des 3des).
*/
typedef enum __CRYPTO_MODE
{
CRYPTO_MODE_ECB=0, ///< ECB
CRYPTO_MODE_CBC, ///< CBC
CRYPTO_MODE_CTR ///< CTR, only for AES
}CRYPTO_MODE;
/**
* The enum of the CRC type.
*/
typedef enum __CRYPTO_CRC_TYPE
{
CRYPTO_CRC_TYPE_8=0, ///< 8 bits CRC
CRYPTO_CRC_TYPE_16_MODBUS, ///< 16 bits Modbus CRC
CRYPTO_CRC_TYPE_16_CCITT, ///< 16 bits CCITT CRC
CRYPTO_CRC_TYPE_32 ///< 32 bits CRC
}CRYPTO_CRC_TYPE;
/**
* The struct of the CRC context.
*/
typedef struct {
u32 state; ///< The initial value input and result value output.
u8 type; ///< The type of CRC, refernec the CRYPTO_CRC_TYPE enum.
u8 mode; ///< The mode of CRC, bit0 means output reflection and bit1 means input reflection.
}psCrcContext_t;
#if 1
struct hsha1_state {
#ifdef HAVE_NATIVE_INT64
uint64 length;
#else
u32 lengthHi;
u32 lengthLo;
#endif /* HAVE_NATIVE_INT64 */
u32 state[5], curlen;
unsigned char buf[64];
};
struct hmd5_state {
#ifdef HAVE_NATIVE_INT64
uint64 length;
#else
u32 lengthHi;
u32 lengthLo;
#endif /* HAVE_NATIVE_INT64 */
u32 state[4], curlen;
unsigned char buf[64];
};
typedef union {
struct hsha1_state sha1;
struct hmd5_state md5;
} hsDigestContext_t;
typedef u32 hstm_digit;
typedef struct {
int16 used, alloc, sign;
hstm_digit *dp;
} hstm_int;
#endif
/**
* @brief This function is used to stop random produce.
*
* @param[in] None
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_random_stop(void);
/**
* @brief This function initializes random digit seed and BIT number.
*
* @param[in] seed The random digit seed.
* @param[in] rng_switch The random digit bit number. (0: 16bit 1:32bit)
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_random_init(u32 seed, CRYPTO_RNG_SWITCH rng_switch);
/**
* @brief This function is used to get random digit content.
*
* @param[in] out Pointer to the output of random digit.
* @param[in] len The random digit bit number will output.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_random_bytes(unsigned char *out, u32 len);
/**
* @brief This function initializes a RC4 encryption algorithm,
* i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data.
*
* @param[in] ctx Pointer to the Cipher Context.
* @param[in] key Pointer to the key.
* @param[in] keylen the length of key.
*
* @retval 0 success
* @retval other failed
*
* @note The first parameter ctx must be a structure which is allocated externally.
* And all of Context parameters in the initializing methods should be allocated externally too.
*/
int tls_crypto_rc4_init(psCipherContext_t * ctx, const unsigned char *key, u32 keylen);
/**
* @brief This function encrypts a variable length data stream according to RC4.
* The RC4 algorithm it generates a "keystream" which is simply XORed with the plaintext to produce the ciphertext stream.
* Decryption is exactly the same as encryption. This function also decrypts a variable length data stream according to RC4.
*
* @param[in] ctx Pointer to the Cipher Context.
* @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
* @param[in] out Pointer to the resulting ciphertext data stream.
* @param[in] len Length of the plaintext data stream in octets.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_rc4(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len);
/**
* @brief This function initializes a AES encryption algorithm, i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data.
*
* @param[in] ctx Pointer to the Cipher Context.
* @param[in] IV Pointer to the Initialization Vector
* @param[in] key Pointer to the key.
* @param[in] keylen the length of key.
* @param[in] cbc the encryption mode, AES supports ECB/CBC/CTR modes.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_aes_init(psCipherContext_t * ctx, const unsigned char *IV, const unsigned char *key, u32 keylen, CRYPTO_MODE cbc);
/**
* @brief This function encrypts or decrypts a variable length data stream according to AES.
*
* @param[in] ctx Pointer to the Cipher Context.
* @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
* @param[in] out Pointer to the resulting ciphertext data stream.
* @param[in] len Length of the plaintext data stream in octets.
* @param[in] dec The cryption way which indicates encryption or decryption.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_aes_encrypt_decrypt(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len, CRYPTO_WAY dec);
/**
* @brief This function initializes a 3DES encryption algorithm, i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data.
*
* @param[in] ctx Pointer to the Cipher Context.
* @param[in] IV Pointer to the Initialization Vector
* @param[in] key Pointer to the key.
* @param[in] keylen the length of key.
* @param[in] cbc the encryption mode, 3DES supports ECB/CBC modes.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_3des_init(psCipherContext_t * ctx, const unsigned char *IV, const unsigned char *key, u32 keylen, CRYPTO_MODE cbc);
/**
* @brief This function encrypts or decrypts a variable length data stream according to 3DES.
*
* @param[in] ctx Pointer to the Cipher Context.
* @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
* @param[in] out Pointer to the resulting ciphertext data stream.
* @param[in] len Length of the plaintext data stream in octets.
* @param[in] dec The cryption way which indicates encryption or decryption.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_3des_encrypt_decrypt(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len, CRYPTO_WAY dec);
/**
* @brief This function initializes a DES encryption algorithm, i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data.
*
* @param[in] ctx Pointer to the Cipher Context.
* @param[in] IV Pointer to the Initialization Vector
* @param[in] key Pointer to the key.
* @param[in] keylen the length of key.
* @param[in] cbc the encryption mode, DES supports ECB/CBC modes.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_des_init(psCipherContext_t * ctx, const unsigned char *IV, const unsigned char *key, u32 keylen, CRYPTO_MODE cbc);
/**
* @brief This function encrypts or decrypts a variable length data stream according to DES.
*
* @param[in] ctx Pointer to the Cipher Context.
* @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
* @param[in] out Pointer to the resulting ciphertext data stream.
* @param[in] len Length of the plaintext data stream in octets.
* @param[in] dec The cryption way which indicates encryption or decryption.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_des_encrypt_decrypt(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len, CRYPTO_WAY dec);
/**
* @brief This function initializes a CRC algorithm, i.e. fills the psCrcContext_t structure pointed to by ctx with necessary data.
*
* @param[in] ctx Pointer to the CRC Context.
* @param[in] key The initialization key.
* @param[in] crc_type The CRC type, supports CRC8/CRC16 MODBUS/CRC16 CCITT/CRC32
* @param[in] mode Set input or outpu reflect.
* @param[in] dec The cryption way which indicates encryption or decryption.
* see OUTPUT_REFLECT
* see INPUT_REFLECT
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_crc_init(psCrcContext_t * ctx, u32 key, CRYPTO_CRC_TYPE crc_type, u8 mode);
/**
* @brief This function updates the CRC value with a variable length bytes.
* This function may be called as many times as necessary, so the message may be processed in blocks.
*
* @param[in] ctx Pointer to the CRC Context.
* @param[in] in Pointer to a variable length bytes
* @param[in] len The bytes 's length
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_crc_update(psCrcContext_t * ctx, unsigned char *in, u32 len);
/**
* @brief This function ends a CRC operation and produces a CRC value.
*
* @param[in] ctx Pointer to the CRC Context.
* @param[in] crc_val Pointer to the CRC value.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_crc_final(psCrcContext_t * ctx, u32 *crc_val);
/**
* @brief This function initializes Message-Diggest context for usage in SHA1 algorithm, starts a new SHA1 operation and writes a new Digest Context.
*
* @param[in] md Pointer to the SHA1 Digest Context.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
void tls_crypto_sha1_init(psDigestContext_t * md);
/**
* @brief Process a message block using SHA1 algorithm.
* This function performs a SHA1 block update operation. It continues an SHA1 message-digest operation,
* by processing InputLen-byte length message block pointed to by buf, and by updating the SHA1 context pointed to by md.
* This function may be called as many times as necessary, so the message may be processed in blocks.
*
* @param[in] md Pointer to the SHA1 Digest Context.
* @param[in] buf InputLen-byte length message block
* @param[in] len The buf 's length
*
* @returnl None
*
* @note None
*/
void tls_crypto_sha1_update(psDigestContext_t * md, const unsigned char *buf, u32 len);
/**
* @brief This function ends a SHA1 operation and produces a Message-Digest.
* This function finalizes SHA1 algorithm, i.e. ends an SHA1 Message-Digest operation,
* writing the Message-Digest in the 20-byte buffer pointed to by hash in according to the information stored in context.
*
* @param[in] md Pointer to the SHA1 Digest Context.
* @param[in] hash Pointer to the Message-Digest
*
* @retval 20 success, return the hash size.
* @retval <0 failed
*
* @note None
*/
int tls_crypto_sha1_final(psDigestContext_t * md, unsigned char *hash);
/**
* @brief This function initializes Message-Diggest context for usage in MD5 algorithm, starts a new MD5 operation and writes a new Digest Context.
* This function begins a MD5 Message-Diggest Algorithm, i.e. fills the psDigestContext_t structure pointed to by md with necessary data.
* MD5 is the algorithm which takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input.
* It is conjectured that it is computationally infeasible to produce two messages having the same message digest,
* or to produce any message having a given prespecified target message digest.
*
* @param[in] md MD5 Digest Context.
*
* @return None
*
* @note None
*/
void tls_crypto_md5_init(psDigestContext_t * md);
/**
* @brief Process a message block using MD5 algorithm.
* This function performs a MD5 block update operation. It continues an MD5 message-digest operation,
* by processing InputLen-byte length message block pointed to by buf, and by updating the MD5 context pointed to by md.
* This function may be called as many times as necessary, so the message may be processed in blocks.
*
* @param[in] md MD5 Digest Context.
* @param[in] buf InputLen-byte length message block
* @param[in] len The buf 's length
*
* @return None
*
* @note None
*/
void tls_crypto_md5_update(psDigestContext_t * md, const unsigned char *buf, u32 len);
/**
* @brief This function ends a MD5 operation and produces a Message-Digest.
* This function finalizes MD5 algorithm, i.e. ends an MD5 Message-Digest operation,
* writing the Message-Digest in the 16-byte buffer pointed to by hash in according to the information stored in context.
*
* @param[in] md MD5 Digest Context.
* @param[in] hash the Message-Digest
*
* @retval 16 success, return the hash size.
* @retval <0 failed
*
* @note None
*/
int tls_crypto_md5_final(psDigestContext_t * md, unsigned char *hash);
/**
* @brief This function implements the large module power multiplication algorithm.
* res = a**e (mod n)
*
* @param[in] a Pointer to a bignumber.
* @param[in] e Pointer to a bignumber.
* @param[in] n Pointer to a bignumber.
* @param[out] res Pointer to the result bignumber.
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_crypto_exptmod(pstm_int *a, pstm_int *e, pstm_int *n, pstm_int *res);
/**
* @brief This function initializes the encryption module.
*
* @param None
*
* @return None
*
* @note None
*/
void tls_crypto_init(void);
#endif

View File

@@ -0,0 +1,343 @@
/**
* @file wm_fwup.h
*
* @brief Firmware upgrade
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_FWUP_H
#define WM_FWUP_H
#include "wm_osal.h"
#include "list.h"
/** firmware update status */
#define TLS_FWUP_STATUS_OK (0)
#define TLS_FWUP_STATUS_EINVALID (1)
#define TLS_FWUP_STATUS_EMEM (2)
#define TLS_FWUP_STATUS_EPERM (3)
#define TLS_FWUP_STATUS_EBUSY (4)
#define TLS_FWUP_STATUS_ESESSIONID (5)
#define TLS_FWUP_STATUS_EIO (6)
#define TLS_FWUP_STATUS_ESIGNATURE (7)
#define TLS_FWUP_STATUS_ECRC (8)
#define TLS_FWUP_STATUS_EUNDEF (9)
/** firmware signature */
#define TLS_FWUP_IMAGE_SIGNATURE_WORD 0x64365577
#define TLS_FWUP_IMAGE_SIGNATURE_WORD_B 0x62161900
/** firmware block size for one time */
#define TLS_FWUP_BLK_SIZE 512
/** firmware update request status */
#define TLS_FWUP_REQ_STATUS_IDLE (0)
#define TLS_FWUP_REQ_STATUS_BUSY (1)
#define TLS_FWUP_REQ_STATUS_SUCCESS (2)
#define TLS_FWUP_REQ_STATUS_FIO (3)
#define TLS_FWUP_REQ_STATUS_FSIGNATURE (4)
#define TLS_FWUP_REQ_STATUS_FMEM (5)
#define TLS_FWUP_REQ_STATUS_FCRC (6)
#define TLS_FWUP_REQ_STATUS_FCOMPLETE (7)
/** firmware update state */
#define TLS_FWUP_STATE_UNDEF (0xffff)
#define TLS_FWUP_STATE_BUSY (1 << 0)
#define TLS_FWUP_STATE_COMPLETE (1 << 1)
#define TLS_FWUP_STATE_ERROR_IO (1 << 2)
#define TLS_FWUP_STATE_ERROR_SIGNATURE (1 << 3)
#define TLS_FWUP_STATE_ERROR_MEM (1 << 4)
#define TLS_FWUP_STATE_ERROR_CRC (1 << 5)
#define TLS_FWUP_STATE_ERROR (TLS_FWUP_STATE_ERROR_IO | TLS_FWUP_STATE_ERROR_SIGNATURE | TLS_FWUP_STATE_ERROR_MEM | TLS_FWUP_STATE_ERROR_CRC)
/** update type 0:firmware, 1: data */
#define TLS_FWUP_DEST_SPECIFIC_FIRMWARE (0)
#define TLS_FWUP_DEST_SPECIFIC_DATA (1)
enum IMAGE_TYPE_ENUM{
IMG_TYPE_OLD_PLAIN = 0,
IMG_TYPE_FLASHBIN = 1,
IMG_TYPE_SECBOOT = 2,
IMG_TYPE_NEW_PLAIN = 3
};
enum {
NOT_ZIP_FILE = 0,
ZIP_FILE = 1
};
typedef struct __T_BOOTER
{
unsigned int magic_no;
unsigned short img_type;
unsigned short zip_type; /** image type zip flag, 0: non-zip, 1:zip*/
unsigned int run_img_addr; /** run area image start address */
unsigned int run_img_len; /** run area image length */
unsigned int run_org_checksum; /** run area image checksum */
unsigned int upd_img_addr; /** upgrade area image start address*/
unsigned int upd_img_len; /** upgrade area image length*/
unsigned int upd_checksum; /** upgrade area image checksum */
unsigned int upd_no;
unsigned char ver[16];
unsigned int hd_checksum;
} T_BOOTER;
/** Structure for firmware image header */
struct tls_fwup_image_hdr {
u32 magic;
u8 crc8;
u8 dest_specific;
u16 dest_offset; // unit: 4KB, valid when dest_specific is TRUE
u32 file_len;
char time[4];
};
/** Structure for one packet data */
struct tls_fwup_block {
u16 number; //0~Sum-1
u16 sum;
u8 data[TLS_FWUP_BLK_SIZE];
u32 crc32;
u8 pad[8];
};
/** Enumeration for image soure when firmware update */
enum tls_fwup_image_src {
TLS_FWUP_IMAGE_SRC_LUART = 0, /**< LOW SPEED UART */
TLS_FWUP_IMAGE_SRC_HUART, /**< HIGH SPEED UART */
TLS_FWUP_IMAGE_SRC_HSPI, /**< HIGH SPEED SPI */
TLS_FWUP_IMAGE_SRC_WEB /**< WEB SERVER */
};
/** Structure for firmware update request */
struct tls_fwup_request {
struct dl_list list;
u8 *data;
u32 data_len;
int status;
void (*complete)(struct tls_fwup_request *request, void *arg);
void *arg;
};
/** Structure for firmware update */
struct tls_fwup {
struct dl_list wait_list;
tls_os_sem_t *list_lock;
bool busy;
enum tls_fwup_image_src current_image_src;
u16 current_state;
u32 current_session_id;
u32 received_len;
u32 total_len;
u32 updated_len;
u32 program_base;
u32 program_offset;
s32 received_number;
};
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup FWUP_APIs FWUP APIs
* @brief firmware upgrade APIs
*/
/**
* @addtogroup FWUP_APIs
* @{
*/
/**
* @brief This function is used to initialize firmware update task
*
* @param[in] None
*
* @retval TLS_FWUP_STATUS_OK initial success
* @retval TLS_FWUP_STATUS_EBUSY already initialed
* @retval TLS_FWUP_STATUS_EMEM memory error
* @note None
*/
int tls_fwup_init(void);
/**
* @brief This function is used to enter firmware update progress.
*
* @param[in] image_src image file's source,
from TLS_FWUP_IMAGE_SRC_LUART,
TLS_FWUP_IMAGE_SRC_WEB,TLS_FWUP_IMAGE_SRC_HUART,
TLS_FWUP_IMAGE_SRC_HSPI
*
* @retval non-zero successfully, return session id
* @retval 0 failed
*
* @note None
*/
u32 tls_fwup_enter(enum tls_fwup_image_src image_src);
/**
* @brief This function is used to exit firmware update progress.
*
* @param[in] session_id session identity of firmware update progress
*
* @retval TLS_FWUP_STATUS_OK exit success
* @retval TLS_FWUP_STATUS_EPERM globle param is not initialed
* @retval TLS_FWUP_STATUS_ESESSIONID error session id
* @retval TLS_FWUP_STATUS_EBUSY update state is busy
*
* @note None
*/
int tls_fwup_exit(u32 session_id);
/**
* @brief This function is used to start update progress
*
* @param[in] session_id current sessin id
* @param[in] *data the data want to update
* @param[in] data_len data length
*
* @retval TLS_FWUP_STATUS_OK updade success
* @retval TLS_FWUP_STATUS_EPERM globle param is not initialed
* @retval TLS_FWUP_STATUS_ESESSIONID error session id
* @retval TLS_FWUP_STATUS_EINVALID invalid param
* @retval TLS_FWUP_STATUS_EMEM memory error
* @retval TLS_FWUP_STATUS_EIO write flash error
* @retval TLS_FWUP_STATUS_ECRC crc error
* @retval TLS_FWUP_STATUS_ESIGNATURE signature error
* @retval TLS_FWUP_STATUS_EUNDEF other error
*
* @note None
*/
int tls_fwup_request_sync(u32 session_id, u8 *data, u32 data_len);
/**
* @brief This function is used to get current update status
*
* @param[in] session_id current sessin id
*
* @retval current state TLS_FWUP_STATUS_OK to TLS_FWUP_STATUS_EUNDEF
*
* @note None
*/
u16 tls_fwup_current_state(u32 session_id);
/**
* @brief This function is used to reset the update information
*
* @param[in] session_id current sessin id
*
* @retval TLS_FWUP_STATUS_OK reset success
* @retval TLS_FWUP_STATUS_EPERM globle param is not initialed
* @retval TLS_FWUP_STATUS_ESESSIONID error session id
* @retval TLS_FWUP_STATUS_EBUSY update state is busy
*
* @note None
*/
int tls_fwup_reset(u32 session_id);
/**
* @brief This function is used to clear error update state
*
* @param[in] session_id current sessin id
*
* @retval TLS_FWUP_STATUS_OK reset success
*
* @note None
*/
int tls_fwup_clear_error(u32 session_id);
/**
* @brief This function is used to set update state to
TLS_FWUP_STATE_ERROR_CRC
*
* @param[in] session_id current sessin id
*
* @retval TLS_FWUP_STATUS_OK set success
* @retval TLS_FWUP_STATUS_EPERM globle param is not initialed
* @retval TLS_FWUP_STATUS_ESESSIONID error session id
*
* @note None
*/
int tls_fwup_set_crc_error(u32 session_id);
/**
* @brief This function is used to get progress's status
*
* @param[in] None
*
* @retval TRUE busy
* @retval FALSE idle
*
* @note None
*/
int tls_fwup_get_status(void);
/**
* @brief This function is used to set update packet number
*
* @param[in] number
*
* @retval TLS_FWUP_STATUS_OK success
* @retval TLS_FWUP_STATE_UNDEF failed
*
* @note None
*/
int tls_fwup_set_update_numer(int number);
/**
* @brief This function is used to get received update packet number
*
* @param[in] None
*
* @retval return current packet number
*
* @note None
*/
int tls_fwup_get_current_update_numer(void);
/**
* @brief This function is used to get current session id
*
* @param[in] None
*
* @retval non-zoro session id
* @retval 0 error
*
* @note None
*/
int tls_fwup_get_current_session_id(void);
/**
* @brief This function is used to check image header
*
* @param[in] None
*
* @retval TRUE: success
* @retval FALSE: failure
*
* @note None
*/
int tls_fwup_img_header_check(T_BOOTER *img_param);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_FWUP_H */

View File

@@ -0,0 +1,201 @@
/*****************************************************************************
*
* File Name : wm_mem.h
*
* Description: memory manager Module
*
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-6-12
*****************************************************************************/
#ifndef WM_MEM_H
#define WM_MEM_H
#include "wm_type_def.h"
//#define WM_MEM_DEBUG 1
#if WM_MEM_DEBUG
#include "list.h"
#define MEM_HEADER_PATTERN 0x76028412
#define MEM_TAILER_PATTERN 0x83395627
#define MEM_FREED_PATTERN 0x82962503
extern u32 alloc_heap_mem_bytes;
extern u32 alloc_heap_mem_blk_cnt;
extern u32 alloc_heap_mem_max_size;
//
// Note: it's important that the size of MP_MEMORY_BLOCK structure
// be multiple of 16 bytes.
//
typedef struct _MEMORY_BLOCK {
struct dl_list list; /**< Pointer to next and previous blocks */
char *file; /**< name of the file which is doing the allocation */
u32 pad; /**< pad to make the size of whole structure multiple of 16 bytes */
u32 line; /**< line number where allocated */
u32 length; /**< ulong index of trailer (=(length/4)-1 relative to data start */
u32 header_pattern; /**< To help detect underflows. A trailer is also added to find overflows */
} MEMORY_BLOCK, *PMEMORY_BLOCK;
typedef struct _MEMORY_PATTERN{
u32 pattern0;
//u32 pattern1;
//u32 pattern2;
//u32 pattern3;
}MEMORY_PATTERN, *PMEMORY_PATTERN;
void mem_free_debug(void *p, char* file, int line);
#define tls_mem_free(p) mem_free_debug( p, __FILE__, __LINE__)
void *mem_alloc_debug(u32 size, char* file, int line);
void mem_free_allocated_blocks(void);
#define tls_mem_alloc(size) mem_alloc_debug(size, __FILE__, __LINE__)
void * mem_realloc_debug(void *mem_address, u32 size, char* file, int line);
#define tls_mem_realloc(mem_address, size) mem_realloc_debug(mem_address, size, __FILE__, __LINE__)
void *mem_calloc_debug(u32 n,u32 size,char * file,int line);
#define tls_mem_calloc(n, size) mem_calloc_debug(n, size, __FILE__, __LINE__)
void tls_mem_alloc_info(void);
int is_safe_addr_debug(void* p, u32 len, char* file, int line);
#define tls_is_safe_addr(p, len) is_safe_addr_debug(p, len, __FILE__, __LINE__)
#if 1
#define MEMCPY memcpy
#define SMEMCPY MEMCPY
#else
#define MEMCPY(dst,src,len) do { \
if(tls_is_safe_addr(dst, len)){ \
memcpy(dst,src,len);}}while(0)
#define SMEMCPY(dst,src,len) do { \
if(tls_is_safe_addr(dst, len)){ \
memcpy(dst,src,len);}}while(0)
#endif
#else /* WM_MEM_DEBUG */
void * mem_alloc_debug(u32 size);
void mem_free_debug(void *p);
void * mem_realloc_debug(void *mem_address, u32 size);
void *mem_calloc_debug(u32 length, u32 size);
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup MEM_APIs MEM APIs
* @brief memory manager APIs
*/
/**
* @addtogroup MEM_APIs
* @{
*/
/**
* @brief This function is called by memory allocation
*
* @param[in] size
*
* @retval NULL malloc failed
* @retval pointer pointer to the address of the allocated memory
*
* @note None
*/
#define tls_mem_alloc(size) mem_alloc_debug(size)
/**
* @brief This function is used to free memory
*
* @param None
*
* @return None
*
* @note None
*/
#define tls_mem_free mem_free_debug
/**
* @brief This function is used to realloc memory
*
* @param None
*
* @retval NULL realloc failed
* @retval Pointer pointer to the address of the allocated memory
*
* @note None
*/
#define tls_mem_realloc mem_realloc_debug
/**
* @brief This function is used to calloc memory
*
* @param None
*
* @retval NULL realloc failed
* @retval Pointer pointer to the address of the allocated memory
*
* @note None
*/
#define tls_mem_calloc mem_calloc_debug
/**
* @brief This function is used to copy memory content from one address to another address
*
* @param[in] dst pointer to destination address
* @param[in] src pointer to source address
* @param[in] len length to copy
*
* @retval dst
*
* @note None
*/
#define MEMCPY(dst,src,len) memcpy(dst,src,len)
/**
* @brief This function is used to copy memory content from one address to another address
*
* @param[in] dst pointer to destination address
* @param[in] src pointer to source address
* @param[in] len length to copy
*
* @retval dst
*
* @note None
*/
#define SMEMCPY(dst,src,len) memcpy(dst,src,len)
/**
* @brief This function is used to get available memory
*
* @param[in] None
*
* @return None
*
* @note This api just can get coarse memory that is remained
*/
unsigned int tls_mem_get_avail_heapsize(void);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_MEM_DEBUG */
#endif /* TLS_MEM_H */

View File

@@ -0,0 +1,124 @@
/*****************************************************************************
*
* File Name : tls_param.h
*
* Description: param manager Module
*
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-6-12
*****************************************************************************/
#ifndef TLS_PARAM_H
#define TLS_PARAM_H
#include "wm_type_def.h"
struct tls_param_quick_connect{
bool quick_connect_en;
u8 chanId;
};
struct tls_sys_param {
struct tls_param_hardware_version hardware_version;
struct tls_param_bssid bssid;
struct tls_param_ssid ssid;
u8 channel_enable;
u8 channel;
u8 wireless_region;
u8 encry;
u8 wireless_protocol;
u8 auto_create_adhoc;
u8 auto_retrycnt;
u8 auto_roam;
u8 auto_powersave;
u8 ssid_broadcast_enable;
u16 channellist;
struct tls_param_key key;
struct tls_param_bgr wbgr;
struct tls_param_wps wps;
struct tls_param_ip ipcfg;
u8 local_dnsname[32];
u8 local_device_name[32];
struct tls_param_oray_client oray_client_setting;
u8 upnp_enable;
u8 always_online;
u8 user_port_mode;
u8 res_2;
struct tls_param_uart uart_cfg;
u8 auto_mode;
u8 res_3;
u16 transparent_trigger_length;
u16 transparent_trigger_period;
struct tls_param_socket remote_socket_cfg;
u32 debug_mode;
u32 res_4[2]; /* reserv and mark the end */
/*escape char*/
u8 EscapeChar;
u8 EscReserved;
u16 EscapePeriod; /* unit: ms */
u8 IoMode;
u8 CmdMode;
u8 PassWord[6];
struct tls_webs_cfg WebsCfg;
u8 oneshotflag;
u8 oneshotres[2];
struct tls_param_sha1 psk;
struct tls_param_original_key original_key;
struct tls_param_ssid original_ssid;
u8 auto_reconnect;
u8 res_5[3];
struct tls_param_quick_connect quick_connect;
u8 key_changed;
u8 ssid_changed;
struct tls_param_ssid apsta_ssid;
struct tls_param_sha1 apsta_psk;
u8 res_6[1];
u8 channel4softap;
u8 encry4softap;
struct tls_param_key key4softap;
struct tls_param_ip ipcfg4softap;
struct tls_param_bgr wbgr4softap;
char sntp_service1[32];
char sntp_service2[32];
char sntp_service3[32];
struct tls_param_tem_offset params_tem;
};
struct tls_param_flash {
u32 magic;
u16 partition_num;
u16 modify_count;
u32 resv_1;
u16 resv_2;
u16 length;
struct tls_sys_param parameters;
u32 crc32;
};
#endif /* WM_PARAM_H */

View File

@@ -0,0 +1,615 @@
/**
* @file wm_params.h
*
* @brief param manager Module
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef TLS_PARAMS_H
#define TLS_PARAMS_H
#include "wm_type_def.h"
/***************************************************************************************
ID | Data Type
***************************************************************************************
TLS_PARAM_ID_SSID | struct tls_param_ssid ssid
TLS_PARAM_ID_ENCRY | u8 encry
TLS_PARAM_ID_KEY | struct tls_param_key key
TLS_PARAM_ID_IP | struct tls_param_ip ipcfg
TLS_PARAM_ID_AUTOMODE | u8 auto_mode
TLS_PARAM_ID_DEFSOCKET | N/A
TLS_PARAM_ID_BSSID | struct tls_param_bssid bssid
TLS_PARAM_ID_CHANNEL | u8 channel
TLS_PARAM_ID_CHANNEL_EN | u8 channel_enable
TLS_PARAM_ID_COUNTRY_REGION | u8 wireless_region
TLS_PARAM_ID_WPROTOCOL | u8 wireless_protocol
TLS_PARAM_ID_ADHOC_AUTOCREATE | N/A
TLS_PARAM_ID_ROAMING | u8 auto_roam
TLS_PARAM_ID_AUTO_RETRY_CNT | N/A
TLS_PARAM_ID_WBGR | struct tls_param_bgr wbgr
TLS_PARAM_ID_USRINTF | N/A
TLS_PARAM_ID_AUTO_TRIGGER_LENGTH | N/A
TLS_PARAM_ID_DEBUG_MODE | N/A
TLS_PARAM_ID_HARDVERSION | struct tls_param_hardware_version hardware_v
TLS_PARAM_ID_BRDSSID | u8 ssid_broadcast_enable
TLS_PARAM_ID_DNSNAME | u8 local_dnsname[32]
TLS_PARAM_ID_DEVNAME | u8 local_device_name[32]
TLS_PARAM_ID_PSM | u8 auto_powersave
TLS_PARAM_ID_ORAY_CLIENT | N/A
TLS_PARAM_ID_UPNP | N/A
TLS_PARAM_ID_UART | struct tls_param_uart uart_cfg
TLS_PARAM_ID_WPS | struct tls_param_wps wps
TLS_PARAM_ID_AUTO_TRIGGER_PERIOD | N/A
TLS_PARAM_ID_ESCAPE_CHAR | N/A
TLS_PARAM_ID_ESCAPE_PERIOD | N/A
TLS_PARAM_ID_IO_MODE | N/A
TLS_PARAM_ID_CMD_MODE | N/A
TLS_PARAM_ID_PASSWORD | u8 PassWord[6]
TLS_PARAM_ID_CHANNEL_LIST | u16 channellist
TLS_PARAM_ID_WEBS_CONFIG | struct tls_webs_cfg WebsCfg
TLS_PARAM_ID_ONESHOT_CFG | u8 oneshotflag
TLS_PARAM_ID_SHA1 | N/A
TLS_PARAM_ID_ORIGIN_KEY | N/A
TLS_PARAM_ID_ORIGIN_SSID | N/A
TLS_PARAM_ID_AUTO_RECONNECT | u8 auto_reconnect
***************************************************************************************/
#define TLS_PARAM_STATUS_OK (0)
#define TLS_PARAM_STATUS_EINVALID (1)
#define TLS_PARAM_STATUS_EMEM (2)
#define TLS_PARAM_STATUS_EIO (3)
#define TLS_PARAM_STATUS_EPERM (4)
#define TLS_PARAM_STATUS_EINVALIDID (5)
/** MACRO of Magic number initial value */
#define TLS_PARAM_INIT_MAGIC (0xffffffff)
/** MACRO of Magic number valid value */
#define TLS_PARAM_MAGIC (0x4947414d)
/** MACRO of parameter partition number */
#define TLS_PARAM_PARTITION_NUM (2)
/** MACRO of parameter identity */
#define TLS_PARAM_ID_ALL (-1)
#define TLS_PARAM_ID_SSID (0)
#define TLS_PARAM_ID_ENCRY (1)
#define TLS_PARAM_ID_KEY (2)
#define TLS_PARAM_ID_IP (3)
#define TLS_PARAM_ID_AUTOMODE (4)
#define TLS_PARAM_ID_DEFSOCKET (5)
#define TLS_PARAM_ID_BSSID (6)
#define TLS_PARAM_ID_CHANNEL (7)
#define TLS_PARAM_ID_CHANNEL_EN (8)
#define TLS_PARAM_ID_COUNTRY_REGION (9)
#define TLS_PARAM_ID_WPROTOCOL (10)
#define TLS_PARAM_ID_ADHOC_AUTOCREATE (11)
#define TLS_PARAM_ID_ROAMING (12)
#define TLS_PARAM_ID_AUTO_RETRY_CNT (13)
#define TLS_PARAM_ID_WBGR (14)
#define TLS_PARAM_ID_USRINTF (15)
#define TLS_PARAM_ID_AUTO_TRIGGER_LENGTH (16)
#define TLS_PARAM_ID_DEBUG_MODE (17)
#define TLS_PARAM_ID_HARDVERSION (18)
#define TLS_PARAM_ID_BRDSSID (19)
#define TLS_PARAM_ID_DNSNAME (20)
#define TLS_PARAM_ID_DEVNAME (21)
#define TLS_PARAM_ID_PSM (22)
#define TLS_PARAM_ID_ORAY_CLIENT (23)
#define TLS_PARAM_ID_UPNP (24)
#define TLS_PARAM_ID_UART (26)
#define TLS_PARAM_ID_WPS (27)
#define TLS_PARAM_ID_AUTO_TRIGGER_PERIOD (28)
#define TLS_PARAM_ID_ESCAPE_CHAR (29)
#define TLS_PARAM_ID_ESCAPE_PERIOD (30)
#define TLS_PARAM_ID_IO_MODE (31)
#define TLS_PARAM_ID_CMD_MODE (32)
#define TLS_PARAM_ID_PASSWORD (33)
#define TLS_PARAM_ID_CHANNEL_LIST (34)
#define TLS_PARAM_ID_WEBS_CONFIG (35)
#define TLS_PARAM_ID_ONESHOT_CFG (36)
#define TLS_PARAM_ID_SHA1 (37)
#define TLS_PARAM_ID_ORIGIN_KEY (38)
#define TLS_PARAM_ID_ORIGIN_SSID (39)
#define TLS_PARAM_ID_AUTO_RECONNECT (40)
#define TLS_PARAM_ID_QUICK_CONNECT (41)
#define TLS_PARAM_ID_KEY_CHANGE (42)
#define TLS_PARAM_ID_SSID_CHANGE (43)
#define TLS_PARAM_ID_SOFTAP_SSID (44)
#define TLS_PARAM_ID_SOFTAP_PSK (45)
#define TLS_PARAM_ID_SOFTAP_ENCRY (46)
#define TLS_PARAM_ID_SOFTAP_KEY (47)
#define TLS_PARAM_ID_SOFTAP_IP (48)
#define TLS_PARAM_ID_SOFTAP_CHANNEL (49)
#define TLS_PARAM_ID_SOFTAP_WBGR (50)
#define TLS_PARAM_ID_SNTP_SERVER1 (51)
#define TLS_PARAM_ID_SNTP_SERVER2 (52)
#define TLS_PARAM_ID_SNTP_SERVER3 (53)
#define TLS_PARAM_ID_TEM_OFFSET (54)
#define TLS_PARAM_ID_MAX (55)
/** MACRO of Physical moe of Ieee802.11 */
#define TLS_PARAM_PHY_11BG_MIXED (0)
#define TLS_PARAM_PHY_11B (1)
#define TLS_PARAM_PHY_11BGN_MIXED (2)
/** MACRO of Ieee802.11 Tx Rate for parameter set */
#define TLS_PARAM_TX_RATEIDX_1M (0)
#define TLS_PARAM_TX_RATEIDX_2M (1)
#define TLS_PARAM_TX_RATEIDX_5_5M (2)
#define TLS_PARAM_TX_RATEIDX_11M (3)
#define TLS_PARAM_TX_RATEIDX_6M (4)
#define TLS_PARAM_TX_RATEIDX_9M (5)
#define TLS_PARAM_TX_RATEIDX_12M (6)
#define TLS_PARAM_TX_RATEIDX_18M (7)
#define TLS_PARAM_TX_RATEIDX_24M (8)
#define TLS_PARAM_TX_RATEIDX_36M (9)
#define TLS_PARAM_TX_RATEIDX_48M (10)
#define TLS_PARAM_TX_RATEIDX_54M (11)
#define TLS_PARAM_TX_RATEIDX_MCS0 (12)
#define TLS_PARAM_TX_RATEIDX_MCS1 (13)
#define TLS_PARAM_TX_RATEIDX_MCS2 (14)
#define TLS_PARAM_TX_RATEIDX_MCS3 (15)
#define TLS_PARAM_TX_RATEIDX_MCS4 (16)
#define TLS_PARAM_TX_RATEIDX_MCS5 (17)
#define TLS_PARAM_TX_RATEIDX_MCS6 (18)
#define TLS_PARAM_TX_RATEIDX_MCS7 (19)
#define TLS_PARAM_TX_RATEIDX_MCS8 (20)
#define TLS_PARAM_TX_RATEIDX_MCS9 (21)
#define TLS_PARAM_TX_RATEIDX_MCS10 (22)
#define TLS_PARAM_TX_RATEIDX_MCS11 (23)
#define TLS_PARAM_TX_RATEIDX_MCS12 (24)
#define TLS_PARAM_TX_RATEIDX_MCS13 (25)
#define TLS_PARAM_TX_RATEIDX_MCS14 (26)
#define TLS_PARAM_TX_RATEIDX_MCS15 (27)
#define TLS_PARAM_TX_RATEIDX_MCS32 (28)
/** MACRO of SSID Broadcast */
#define TLS_PARAM_SSIDBRD_DISABLE (0)
#define TLS_PARAM_SSIDBRD_ENABLE (1)
#define TLS_PARAM_ROAM_DISABLE (0)
#define TLS_PARAM_ROAM_ENABLE (1)
/** MACRO of Power Saving Mode */
#define TLS_PARAM_PSM_DISABLE (0)
#define TLS_PARAM_PSM_ENABLE (1)
#define TLS_PARAM_DDNS_DISABLE (0)
#define TLS_PARAM_DDNS_ENABLE (1)
#define TLS_PARAM_AUTO_CREATE_ADHOC_DISABLE (0)
#define TLS_PARAM_AUTO_CREATE_ADHOC_ENABLE (1)
#define TLS_PARAM_WPS_DISABLE (0)
#define TLS_PARAM_WPS_ENABLE (1)
#define TLS_PARAM_WPS_MODE_PIN (0)
#define TLS_PARAM_WPS_MODE_PBC (1)
#define TLS_PARAM_WPS_FLAG_NEGOTIATED (1 << 0)
#define TLS_PARAM_UPNP_DISABLE (0)
#define TLS_PARAM_UPNP_ENABLE (1)
/** MACRO of IEEE802.11 Work MODE */
#define TLS_PARAM_IEEE80211_INFRA (1)
#define TLS_PARAM_IEEE80211_ADHOC (2)
#define TLS_PARAM_IEEE80211_SOFTAP (4)
/** MACRO of Command or Transparent Mode */
#define TLS_PARAM_MANUAL_MODE (0)
#define TLS_PARAM_AUTO_MODE (1)
#define TLS_PARAM_ALWAYS_ONLINE_ENABLE (1)
#define TLS_PARAM_ALWAYS_ONLINE_DISABLE (0)
/** MACRO of DHCP ENABLE or DISABLE */
#define TLS_PARAM_DHCP_ENABLE (1)
#define TLS_PARAM_DHCP_DISABLE (0)
/** MACRO of COUNTRY CODE for channel number */
#define TLS_PARAM_REGION_0_BG_BAND (0) /* 1-11 */
#define TLS_PARAM_REGION_1_BG_BAND (1) /* 1-13 */
#define TLS_PARAM_REGION_2_BG_BAND (2) /* 10-11 */
#define TLS_PARAM_REGION_3_BG_BAND (3) /* 10-13 */
#define TLS_PARAM_REGION_4_BG_BAND (4) /* 14 */
#define TLS_PARAM_REGION_5_BG_BAND (5) /* 1-14 */
#define TLS_PARAM_REGION_6_BG_BAND (6) /* 3-9 */
#define TLS_PARAM_REGION_7_BG_BAND (7) /* 5-13 */
#define TLS_PARAM_REGION_MAXIMUM_BG_BAND TLS_PARAM_REGION_7_BG_BAND
/** MACRO of ENCRYPT TYPE */
#define TLS_PARAM_ENCRY_OPEN (0)
#define TLS_PARAM_ENCRY_WEP64 (1)
#define TLS_PARAM_ENCRY_WEP128 (2)
#define TLS_PARAM_ENCRY_WPA_PSK_TKIP (3)
#define TLS_PARAM_ENCRY_WPA_PSK_AES (4)
#define TLS_PARAM_ENCRY_WPA2_PSK_TKIP (5)
#define TLS_PARAM_ENCRY_WPA2_PSK_AES (6)
/** MACRO of USER INTERFACE TYPE */
#define TLS_PARAM_USR_INTF_LUART (0)
#define TLS_PARAM_USR_INTF_HUART (1)
#define TLS_PARAM_USR_INTF_HSPI (2)
#define TLS_PARAM_USR_INTF_HSDIO (3)
/** MACRO of UART BAUDRATE */
#define TLS_PARAM_UART_BAUDRATE_B600 (600)
#define TLS_PARAM_UART_BAUDRATE_B1200 (1200)
#define TLS_PARAM_UART_BAUDRATE_B1800 (1800)
#define TLS_PARAM_UART_BAUDRATE_B2400 (2400)
#define TLS_PARAM_UART_BAUDRATE_B4800 (4800)
#define TLS_PARAM_UART_BAUDRATE_B9600 (9600)
#define TLS_PARAM_UART_BAUDRATE_B19200 (19200)
#define TLS_PARAM_UART_BAUDRATE_B38400 (38400)
#define TLS_PARAM_UART_BAUDRATE_B57600 (57600)
#define TLS_PARAM_UART_BAUDRATE_B115200 (115200)
#define TLS_PARAM_HUART_BAUDRATE_B230400 (230400)
#define TLS_PARAM_HUART_BAUDRATE_B460800 (460800)
#define TLS_PARAM_HUART_BAUDRATE_B921600 (921600)
#define TLS_PARAM_HUART_BAUDRATE_B1000000 (1000000)
#define TLS_PARAM_HUART_BAUDRATE_B1250000 (1250000)
#define TLS_PARAM_HUART_BAUDRATE_B1500000 (1500000)
#define TLS_PARAM_HUART_BAUDRATE_B2000000 (2000000)
/** MACRO of UART PARITY */
#define TLS_PARAM_UART_PARITY_NONE (0)
#define TLS_PARAM_UART_PARITY_EVEN (1)
#define TLS_PARAM_UART_PARITY_ODD (2)
#define TLS_PARAM_UART_PARITY_MARK (3)
#define TLS_PARAM_UART_PARITY_SPACE (4)
/** MACRO of UART STOP BITS */
#define TLS_PARAM_UART_STOPBITS_1BITS (0)
#define TLS_PARAM_UART_STOPBITS_2BITS (1)
/** MACRO of UART FLOW CONTROL */
#define TLS_PARAM_UART_FLOW_DISABLE (0)
#define TLS_PARAM_UART_FLOW_ENABLE (1)
#define TLS_PARAM_HSPI_MAX_SCLK (33000000)
/** MACRO of SOCKET PARAMETER */
#define TLS_PARAM_SOCKET_TCP (0)
#define TLS_PARAM_SOCKET_UDP (1)
#define TLS_PARAM_SOCKET_CLIENT (0)
#define TLS_PARAM_SOCKET_SERVER (1)
#define TLS_PARAM_SOCKET_DEFAULT_PORT (60000)
/** Structure of hardware parameter */
struct tls_param_hardware_version {
u8 mark;
u8 main;
u8 sub;
u8 material;
u8 year;
u8 week;
u8 res[2];
};
/** Structure of specified BSSID parameter */
struct tls_param_bssid {
u8 bssid_enable;
u8 res;
u8 bssid[6];
};
/** Structure of SSID parameter */
struct tls_param_ssid {
u8 ssid[32];
u32 ssid_len;
};
/** Structure of TEM parameter */
struct tls_param_tem_offset {
u8 offset_len;
s32 offset;
};
/** Structure of KEY parameter */
struct tls_param_key {
u8 psk[64];
u8 key_length;
u8 key_index;
u8 key_format;
u8 res;
};
/** Structure of original KEY parameter */
struct tls_param_original_key {
u8 psk[64];
u32 key_length;
};
/** Structure of SHA1 KEY parameter */
struct tls_param_sha1{
u8 psk_set;
u8 psk[32];
};
/** Structure of 802.11 bgn rate parameter */
struct tls_param_bgr {
u8 bg;
u8 max_rate;
u8 res[2];
};
/** Structure of IP parameter */
struct tls_param_ip {
u8 dhcp_enable;
u8 res[3];
u8 ip[4];
u8 netmask[4];
u8 gateway[4];
u8 dns1[4];
u8 dns2[4];
};
/** Structure of uart parameter */
struct tls_param_uart {
u32 baudrate;
u8 stop_bits;
u8 parity;
u8 flow;
u8 charsize;
};
/** Structure of socket parameter */
struct tls_param_socket {
u8 protocol;
u8 client_or_server;
u16 port_num;
u8 host[32];
};
struct tls_param_wps {
u8 wps_enable;
u8 mode;
u8 flag;
u8 res;
u8 pin[8];
};
/** Structure of oray client */
struct tls_param_oray_client {
u32 oray_client_enable;
u8 oray_client_user[32];
u8 oray_client_pass[32];
};
/** Structure of web server parameter */
struct tls_webs_cfg {
u8 AutoRun;
u8 Reserved;
u16 PortNum;
};
/** Structure of user default parameter */
typedef struct tls_user_param{
u8 wireless_protocol;
u8 auto_mode;
u8 dhcp_enable;
u8 user_port_mode;
u8 ip[4];
u8 netmask[4];
u8 gateway[4];
u8 dns[4];
u32 baudrate;
u8 socket_protocol;
u8 socket_client_or_server;
u16 socket_port_num;
u8 socket_host[32];
u8 auto_powersave;
u8 PassWord[6];
}ST_Wm_User_Param;
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup Param_APIs Param APIs
* @brief Param manager APIs
*/
/**
* @addtogroup Param_APIs
* @{
*/
/**
* @brief This function is used to initialize parameter's manamge module
*
* @param[in] None
*
* @retval TLS_PARAM_STATUS_OK init success
* @retval TLS_PARAM_STATUS_EMEM memory error
* @retval TLS_PARAM_STATUS_EIO io error
* @retval TLS_PARAM_STATUS_EPERM magic number error
*
* @note None
*/
int tls_param_init(void);
/**
* @brief This function is used to load the system's default
parameters
*
* @param[in] None
*
* @return None
*
* @note This function read user defined parameters first,
if wrong, all the parameters restore factory settings
*/
void tls_param_load_factory_default(void);
/**
* @brief This function is used to set one system parameter by its id
*
* @param[in] id param id,from TLS_PARAM_ID_SSID
to (TLS_PARAM_ID_MAX - 1)
* @param[in] *argv store parameters
* @param[in] to_flash whether the parameter is written to flash,
1:write to flash,0:only write memory
*
* @retval TLS_PARAM_STATUS_OK set success
* @retval TLS_PARAM_STATUS_EINVALID invalid param
*
* @note None
*/
int tls_param_set(int id, void *argv, bool to_flash);
/**
* @brief This function is used to get one system parameter by its id.
*
* @param[in] id param id,from TLS_PARAM_ID_SSID
to (TLS_PARAM_ID_MAX - 1)
* @param[in] *argv store parameters
* @param[in] from_flash whether the parameter is readed from flash,
1 read from flash,0 read from memory
*
* @retval TLS_PARAM_STATUS_OK success
* @retval TLS_PARAM_STATUS_EINVALID invalid param
*
* @note None
*/
int tls_param_get(int id, void *argv, bool from_flash);
/**
* @brief This function is used to write parameter into flash
*
* @param[in] id param id,from TLS_PARAM_ID_ALL
to (TLS_PARAM_ID_MAX - 1)
*
* @retval TLS_PARAM_STATUS_OK success
* @retval TLS_PARAM_STATUS_EINVALID invalid param
* @retval TLS_PARAM_STATUS_EIO read or write flash error
*
* @note None
*/
int tls_param_to_flash(int id);
/**
* @brief This function is used to recovery the parameters from
the backup area to the parameter area,and load them into ram
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_restore_param_from_backup(void);
/**
* @brief This function is used to load default parametes into ram
*
* @param[in] None
*
* @retval TLS_PARAM_STATUS_OK set success
* @retval TLS_PARAM_STATUS_EINVALID parameter wrong
* @retval TLS_PARAM_STATUS_EIO read or write falsh error
*
* @note This function read user defined parameters first,
if wrong, all the parameters restore factory settings
*/
int tls_param_to_default(void);
/**
* @brief This function is used to write user's parameters into the
flash
*
* @param[in] None
*
* @retval TLS_PARAM_STATUS_OK success
* @retval other failed
*
* @note None
*/
int tls_param_save_user_default(void);
/**
* @brief This function is used to modify user's default parameters,
then write them into flash
*
* @param[in] *user_param
*
* @retval TLS_PARAM_STATUS_OK success
* @retval other failed
*
* @note None
*/
int tls_param_save_user(struct tls_user_param *user_param);
/**
* @brief This function is used to get updp mode.(updp:update user
default parameters)
*
* @param[in] None
*
* @retval update mode
*
* @note None
*/
u8 tls_param_get_updp_mode(void);
/**
* @brief This function is used to set updp mode
*
* @param[in] mode
*
* @return None
*
* @note None
*/
void tls_param_set_updp_mode(u8 mode);
/**
* @brief This function is used to get program param
*
* @param[in] *pBase pointer to save base address
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_param_get_program_param(u32 *pBase);
/**
* @brief This function is used to set program base,image len,and
checksum
*
* @param[in] base base address
* @param[in] totallen total length of the image
* @param[in] checksum checksum value of the image
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_param_set_program_param(u32 base, u32 totallen, u32 checksum);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_PARAM_H */

View File

@@ -0,0 +1,115 @@
/**
* @file wm_wl_mbox.h
*
* @brief mailbox (mbox) APIs
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef __TLS_WL_MBOX_H__
#define __TLS_WL_MBOX_H__
#include "wm_type_def.h"
#include "wm_osal.h"
/** max value of time out */
#define SYS_ARCH_TIMEOUT 0xffffffffUL
/** pointer to the mailbox */
typedef tls_os_queue_t * tls_mbox_t;
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup MBOX_APIs MBOX APIs
* @brief Software mailbox APIs
*/
/**
* @addtogroup MBOX_APIs
* @{
*/
/**
* @brief Create a malibox
*
* @param[out] *mbox pointer to the mailbox
* @param[in] size size of mailbox
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
s8 tls_mbox_new(tls_mbox_t *mbox, int size);
/**
* @brief Check if an mbox is valid/allocated
*
* @param[in] mbox pointer to the mailbox
*
* @retval 0 invalid
* @retval 1 valid
*
* @note None
*/
int tls_mbox_valid(tls_mbox_t mbox);
/**
* @brief Sends a message to a mailbox
*
* @param[in] mbox pointer to the mailbox
* @param[in] *msg pointer to the message to be post
*
* @return None
*
* @note None
*/
void tls_mbox_post(tls_mbox_t mbox, void *msg);
/**
* @brief Posts the msg to the mailbox.
*
* @param[in] mbox pointer to the mailbox
* @param[in] *msg pointer to the message to be post
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note this function have to block until the "msg" is really posted.
*/
s8 tls_mbox_trypost(tls_mbox_t mbox, void *msg);
/**
* @brief Waits for a message within specified time
*
* @param[in] mbox pointer to the mailbox
* @param[out] **msg pointer to the message to be received
* @param[in] timeout the specified time
*
* @retval SYS_ARCH_TIMEOUT time out
* @retval other time of elapsed
*
* @note None
*/
u32 tls_arch_mbox_fetch(tls_mbox_t mbox, void **msg, u32 timeout);
/**
* @}
*/
/**
* @}
*/
#endif

View File

@@ -0,0 +1,233 @@
/**
* @file wm_wl_task.h
*
* @brief task APIs
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef __TLS_WL_TASK_H__
#define __TLS_WL_TASK_H__
#include "wm_type_def.h"
#include "wm_wl_mbox.h"
#include "wm_wl_timers.h"
//#include "ithread.h"
#define TLS_TASK_START_PRIO 0
#define TASK_WL_PRIO 9
#define TASK_WL_PRIO_MAX 12
#define TLS_SUPPLICANT_TASK_PRIO (TASK_WL_PRIO_MAX + 1)
#define TLS_SUPPLICANT_TIMER_TASK_PRIO (TASK_WL_PRIO_MAX + 2)
#define TLS_LWIP_TASK_PRIO (TASK_WL_PRIO_MAX + 3)
#define TLS_SYS_TASK_PRIO (TASK_WL_PRIO_MAX + 5)
#define TLS_HOSTIF_TASK_PRIO (TASK_WL_PRIO_MAX + 6)
#define TLS_SPI_SCHEDULER_TASK_PRIO (TASK_WL_PRIO_MAX + 7)
#define TLS_FWUP_TASK_PRIO (TASK_WL_PRIO_MAX + 8)
#define TLS_HTTP_CLIENT_TASK_PRIO (TASK_WL_PRIO_MAX + 9)
#define AP_SOCKET_S_TASK_PRIO (TASK_WL_PRIO_MAX + 10)
#define TLS_UPNP_TASK_PRIO (TASK_WL_PRIO_MAX + 11)
#define TLS_ONESHOT_TASK_PRIO (TASK_WL_PRIO_MAX + 15)
#define TLS_ONESHOT_SPEC_TASK_PRIO (TASK_WL_PRIO_MAX + 16)
#define TLS_MBOX_ALL_COUNT 8
#define TLS_MBOX_ID_WL_TASK 0
#define TLS_MBOX_ID_HOSTIF_TASK 1
#define TLS_MBOX_ID_JDCLOUD_SERVER 2
#define TLS_MBOX_ID_JDCLOUD_DATA 3
#define TLS_MBOX_ID_UPNP_HD 4
#define TLS_MBOX_ID_UPNP_COMMON 5
#define TLS_MBOX_ID_UPNP_GENA 6
#define TLS_MBOX_ID_UPNP_MINISERVER 7
#define TLS_TIMEO_ALL_COUONT 9
#define TLS_TIMEO_ID_NULL 0
#define TLS_TIMEO_ID_WL_TASK 1
#define TLS_TIMEO_ID_HOSTIF_TASK 2
#define TLS_TIMEO_ID_JDCLOUD_SERVER 3
#define TLS_TIMEO_ID_JDCLOUD_DATA 4
#define TLS_TIMEO_ID_UPNP_HD 5
#define TLS_TIMEO_ID_UPNP_COMMON 6
#define TLS_TIMEO_ID_UPNP_GENA 7
#define TLS_TIMEO_ID_UPNP_MINISERVER 8
#define TLS_MSG_ALL_COUONT 9
#define TLS_MSG_ID_TX_MGMT_CMPLT 0
#define TLS_MSG_ID_MLME_TASK 1
#define TLS_MSG_ID_UART_SENT_FREE 2
#define TLS_MSG_ID_UART0_RX 3
#define TLS_MSG_ID_HSPI_RX_CMD 4
#define TLS_MSG_ID_HSPI_RX_DATA 5
#define TLS_MSG_ID_HSPI_TX_DATA 6
#define TLS_MSG_ID_TX_DATA_CMPLT 7
#define TLS_MSG_ID_UART1_RX 8
/** pointer to the semaphore */
typedef tls_os_sem_t * tls_sem_t;
/** Thread start routine */
typedef void *(*start_routine)(void *arg);
/** message type of task */
enum task_msg_type {
TASK_MSG_TIMEOUT,
TASK_MSG_UNTIMEOUT,
TASK_MSG_CALLBACK_WITH_BLOCK,
TASK_MSG_CALLBACK,
TASK_MSG_CALLBACK_STATIC,
TASK_MSG_NULL
};
/** message of task */
struct task_msg {
enum task_msg_type type;
tls_sem_t *sem;
union {
struct {
start_routine function;
void *ctx;
} cb;
struct {
start_routine function;
void *ctx;
u8 cnt;
} cbs;
struct {
u32 msecs;
tls_timeout_handler h;
void *arg;
} tmo;
} msg;
};
/** task parameters */
struct task_parameter{
u8 task_id; /**< task ID */
const char * name; /**< task name */
u8 *stk_start; /**< start address of task stack */
u32 stk_size; /**< size of task stack */
u8 mbox_size; /**< size of mailbox */
u8 mbox_id; /**< mailbox ID */
u8 timeo_id; /**< timer ID */
};
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup Task_APIs Task APIs
* @brief Software task APIs
*/
/**
* @addtogroup Task_APIs
* @{
*/
/**
* @brief Task initialized
*
* @param None
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
s8 tls_wl_task_init(void);
/**
* @brief Running the task
*
* @param[in] *task_param pointer to the task parameters
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
s8 tls_wl_task_run(struct task_parameter *task_param);
/**
* @brief Running the callback function
*
* @param[in] *task_param pointer to the task parameters
* @param[in] function the callback function
* @param[in] *ctx parameter of the callback function
* @param[in] block
* @param[in] msg_id
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
s8 tls_wl_task_callback_static(struct task_parameter *task_param,
start_routine function, void *ctx, u8 block, u8 msg_id);
/**
* @brief Running the callback function
*
* @param[in] *task_param pointer to the task parameters
* @param[in] function the callback function
* @param[in] *ctx parameter of the callback function
* @param[in] block
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
s8 tls_wl_task_callback(struct task_parameter *task_param,
start_routine function, void *ctx, u8 block);
/**
* @brief Add a timer to the task
*
* @param[in] *task_param pointer to the task parameters
* @param[in] msecs timer value
* @param[in] h the callback function
* @param[in] *arg parameter of the callback function
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
s8 tls_wl_task_add_timeout(struct task_parameter *task_param, u32 msecs,
tls_timeout_handler h, void *arg);
/**
* @brief Stop or delay the timer to expire.
*
* @param[in] *task_param pointer to the task parameters
* @param[in] h the callback function
* @param[in] *arg parameter of the callback function
*
* @retval TLS_OS_SUCCESS success
* @retval TLS_OS_ERROR failed
*
* @note None
*/
s8 tls_wl_task_untimeout(struct task_parameter *task_param,
tls_timeout_handler h, void *arg);
/**
* @}
*/
/**
* @}
*/
#endif

View File

@@ -0,0 +1,102 @@
/**
* @file wm_wl_timers.h
*
* @brief task APIs
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef __TLS_WL_TIMERS_H__
#define __TLS_WL_TIMERS_H__
#include "wm_type_def.h"
#include "wm_wl_mbox.h"
/** callback function of time out */
typedef void (* tls_timeout_handler)(void *arg);
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup Timer_APIs Timer APIs
* @brief Software timer APIs
*/
/**
* @addtogroup Timer_APIs
* @{
*/
/**
* @brief Create a one-shot timer (aka timeout)
*
* @param[in] timeo_assigned timer NO. by assigned
* @param[in] msecs time in milliseconds after that the timer should expire
* @param[in] handler callback function that would be called by the timeout
* @param[in] *arg callback argument that would be passed to handler
*
* @return None
*
* @note While waiting for a message using sys_timeouts_mbox_fetch()
*/
void tls_timeout_p(u8 timeo_assigned, u32 msecs, tls_timeout_handler handler, void *arg);
/**
* @brief Go through timeout list (for this task only) and remove the first
* matching entry, even though the timeout has not been triggered yet
*
* @param[in] timeo_assigned timer NO. by assigned
* @param[in] handler callback function that would be called by the timeout
* @param[in] *arg callback argument that would be passed to handler
*
* @return None
*
* @note None
*/
void tls_untimeout_p(u8 timeo_assigned, tls_timeout_handler handler, void *arg);
/**
* @brief Wait (forever) for a message to arrive in an mbox.
* While waiting, timeouts are processed
*
* @param[in] timeo_assigned timer NO. by assigned
* @param[in] mbox the mbox to fetch the message from
* @param[out] **msg the place to store the message
*
* @return None
*
* @note None
*/
void tls_timeouts_mbox_fetch_p(u8 timeo_assigned, tls_mbox_t mbox, void **msg);
/**
* @brief Initialize the timer
*
* @param None
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
s8 tls_wl_timer_init(void);
/**
* @}
*/
/**
* @}
*/
#endif

View File

@@ -0,0 +1,80 @@
/*
* @file random.h
* @brief Random number generator
* @copyright (c) 2010-2011, 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.
*
* @note Alternatively, this software may be distributed under the terms of BSD
* license.
*
* @note See README and COPYING for more details.
*/
#ifndef RANDOM_H
#define RANDOM_H
void random_deinit(void);
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup Random_APIs Random APIs
* @brief Random APIs
*/
/**
* @addtogroup Random_APIs
* @{
*/
/**
* @brief This function is used to add number to random pool
*
* @param[in] *buf number to add
* @param[in] len number count
*
* @return None
*
* @note None
*/
void random_add_randomness(const void *buf, size_t len);
/**
* @brief This function is used to get random number with len from
random pool
*
* @param[in] *buf used to save random number
* @param[in] len length of random number
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int random_get_bytes(void *buf, size_t len);
/**
* @}
*/
/**
* @}
*/
#define random_mark_pool_ready() do { } while (0)
/** random pool ready */
#define random_pool_ready() 1
#endif /* RANDOM_H */

View File

@@ -0,0 +1,83 @@
/**
* @file wm_config.h
*
* @brief w600 chip inferface configure
*
* @author dave
*
* @copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_CONFIG_H__
#define __WM_CONFIG_H__
#define CFG_ON 1
#define CFG_OFF 0
#define WM_CONFIG_DEBUG_UART1 CFG_OFF /*PRINTF PORT USE UART1*/
/**Driver Support**/
#define TLS_CONFIG_HS_SPI CFG_ON /*High Speed SPI*/
#define TLS_CONFIG_LS_SPI CFG_ON /*Low Speed SPI*/
#define TLS_CONFIG_UART CFG_ON /*UART*/
/**Host Interface&Command**/
#define TLS_CONFIG_HOSTIF CFG_ON
#define TLS_CONFIG_AT_CMD (CFG_ON && TLS_CONFIG_HOSTIF)
#define TLS_CONFIG_RI_CMD (CFG_ON && TLS_CONFIG_HOSTIF)
#define TLS_CONFIG_RMMS CFG_OFF
//LWIP CONFIG
#define TLS_CONFIG_LWIP_VER2_0_3 CFG_ON
#define TLS_CONFIG_IPV4 CFG_ON //must ON
#define TLS_CONFIG_IPV6 CFG_OFF
#define TLS_CONFIG_DHCP_OPTION60 "Winnermicro:W600_01"
/** SOCKET CONFIG **/
#define TLS_CONFIG_SOCKET_STD CFG_ON
#define TLS_CONFIG_SOCKET_RAW CFG_ON
#define TLS_CONFIG_CMD_USE_RAW_SOCKET (CFG_ON && TLS_CONFIG_SOCKET_RAW)
#define TLS_CONFIG_HARD_CRYPTO CFG_ON
#define TLS_CONFIG_USE_POLARSSL CFG_OFF
#define TLS_CONFIG_SERVER_SIDE_SSL (CFG_OFF && TLS_CONFIG_HTTP_CLIENT_SECURE) /*MUST configure TLS_CONFIG_HTTP_CLIENT_SECURE CFG_ON */
/** HTTP CLIENT **/
/*
HTTP Lib
HTTPS Lib
SSL LIB
CRYPTO
*/
#define TLS_CONFIG_HTTP_CLIENT (CFG_ON)
#define TLS_CONFIG_HTTP_CLIENT_PROXY CFG_OFF
#define TLS_CONFIG_HTTP_CLIENT_AUTH_BASIC CFG_OFF
#define TLS_CONFIG_HTTP_CLIENT_AUTH_DIGEST CFG_OFF
#define TLS_CONFIG_HTTP_CLIENT_AUTH (TLS_CONFIG_HTTP_CLIENT_AUTH_BASIC || TLS_CONFIG_HTTP_CLIENT_AUTH_DIGEST)
#define TLS_CONFIG_HTTP_CLIENT_SECURE CFG_OFF
#define TLS_CONFIG_HTTP_CLIENT_TASK (CFG_ON && TLS_CONFIG_HTTP_CLIENT)
/**IGMP**/
#define TLS_CONFIG_IGMP CFG_ON
/** UPNP AND DLNA**/
#define TLS_CONFIG_UPNP CFG_OFF
#define TLS_CONFIG_DLNA CFG_OFF && TLS_CONFIG_UPNP
#define TLS_CONFIG_NTP CFG_ON
#define VERC_DNS_OPT CFG_ON
#define VERC_LWIP_OPT CFG_ON
#include "wm_ram_config.h"
#endif /*__WM_CONFIG_H__*/

View File

@@ -0,0 +1,127 @@
/**
* @file wm_debug.h
*
* @brief debug Module APIs
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_DEBUG_H
#define WM_DEBUG_H
#include <stdio.h>
#include <stdlib.h>
#include "wm_config.h"
/* 0x00000000 - 0x80000000 */
/** Define the debugging switch: on */
#define TLS_DBG_ON 1
/** Define the debugging switch: off */
#define TLS_DBG_OFF 0
/* 0x0000000F - 0x00000001 */
/** Define the debugging level: info */
#define TLS_DBG_LEVEL_INFO TLS_DBG_OFF
/** Define the debugging level: warning */
#define TLS_DBG_LEVEL_WARNING TLS_DBG_OFF
/** Define the debugging level: error */
#define TLS_DBG_LEVEL_ERR TLS_DBG_OFF
/** Define the debugging level: dump */
#define TLS_DBG_LEVEL_DUMP TLS_DBG_OFF
/** general debug info switch, default: off */
#define TLS_GENERAL_DBG TLS_DBG_OFF
#define __TLS_DBGPRT_INFO(fmt, ...) \
do { \
u32 time = tls_os_get_time(); \
printf("[WM_I] <%d.%02d> %s : "fmt, (time/100), (time%100), __func__ , ##__VA_ARGS__); \
} while (0)
#define __TLS_DBGPRT_WARNING(fmt, ...) \
do { \
u32 time = tls_os_get_time(); \
printf("[WM_W] <%d.%02d> %s : "fmt, (time/100), (time%100), __func__ , ##__VA_ARGS__); \
} while (0)
#define __TLS_DBGPRT_ERR(fmt, ...) \
do { \
u32 time = tls_os_get_time(); \
printf("[WM_E] <%d.%02d> %s : "fmt, (time/100), (time%100), __func__ , ##__VA_ARGS__); \
} while (0)
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup DEBUG_APIs DEBUG APIs
* @brief DEBUG APIs
*/
/**
* @addtogroup DEBUG_APIs
* @{
*/
#if (TLS_GENERAL_DBG && TLS_DBG_LEVEL_INFO)
/** Print information of the info level */
#define TLS_DBGPRT_INFO(f, a...) __TLS_DBGPRT_INFO(f, ##a)
#else
/** Print information of the info level */
#define TLS_DBGPRT_INFO(f, a...)
#endif
#if (TLS_GENERAL_DBG && TLS_DBG_LEVEL_WARNING)
/** Print information of the warning level */
#define TLS_DBGPRT_WARNING(f, a...) __TLS_DBGPRT_WARNING(f, ##a)
#else
/** Print information of the warning level */
#define TLS_DBGPRT_WARNING(f, a...)
#endif
#if (TLS_GENERAL_DBG && TLS_DBG_LEVEL_ERR)
/** Print information of the error level */
#define TLS_DBGPRT_ERR(f, a...) __TLS_DBGPRT_ERR(f, ##a)
#else
/** Print information of the error level */
#define TLS_DBGPRT_ERR(f, a...)
#endif
#if (TLS_GENERAL_DBG && TLS_DBG_LEVEL_DUMP)
/**
* @brief dump memory
*
* @param[in] *p pointer the memory
* @param[in] len length of memory
*
* @return None
*
* @note None
*/
void TLS_DBGPRT_DUMP(char *p, u32 len);
#else
/** Print information of the dump level */
#define TLS_DBGPRT_DUMP(p, len)
#endif
/**
* @}
*/
/**
* @}
*/
#endif /* end of WM_DEBUG_H */

View File

@@ -0,0 +1,75 @@
/**
* @file wm_include.h
*
* @brief the configuration file of sdk
*
* @author winnermicro
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_INCLUDE_H__
#define __WM_INCLUDE_H__
/**
* @mainpage WinnerMicro SDK
*
* Quick Start of WinnerMicro SDK.
*
*
* HOW TO CODE ?
*
* Function UserMain(void) is the entrance function of the application:
* @code
* void UserMain(void)
* {
* printf("\n user task\n");
*
* #if DEMO_CONSOLE
* CreateDemoTask();
* #endif
*
* //user's task
* }
* @endcode
*
*
* \n
* HOW TO COMPILE ?
*
* To build with the SDK you can use the keil tools.
* Opening "Tools\Keil\Project\WM_SDK.uvproj" to compile.
*
*
* \n
* HOW TO DOWNLOAD THE FIRMWARE ?
*
* Download the "WM_W600.FLS" image
*
* This will download image which includes secboot & sdk into flash by ROM using xModem-protocol.
* @code
* Pulling down the bootmode pin and reset the device. Then UART0 will output:
* CCC...
* For details,please refer to the sdk manual.
* @endcode
*
* Download the "WM_W600_SEC.IMG" image
*
* This will download image which includes sdk by secboot using xmodem-protocol.
* @code
* Press "ESC" and then reset the device. Then UART0 will output:
* secboot running...
* CCC...
* For details,please refer to the sdk manual.
* @endcode
*
* \n
*/
#include <stdio.h>
#include <stdlib.h>
#include "wm_type_def.h"
#include "wm_gpio.h"
//#include "wm_flash.h"
#include "wm_regs.h"
#endif

View File

@@ -0,0 +1,29 @@
/**
* @file wm_ram_config.h
*
* @brief WM ram model configure
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_RAM_CONFIG_H__
#define __WM_RAM_CONFIG_H__
/*OS Task Stack's lower & upper range*/
#define TASK_STACK_USING_MEM_LOWER_RANGE (0x20000000UL)
#define TASK_STACK_USING_MEM_UPPER_RANGE (0x20028000UL)
/*0x20000000~MASTER_SPI_DMA_ADDR for stack,heap & data*/
/*Master SPI use buffer when spi use dma transfer mode*/
#define MASTER_SPI_DMA_ADDR 0x20038000UL
/*High speed SPI or SDIO buffer to exchange data*/
#define SLAVE_HSPI_SDIO_ADDR 0x2003A000UL
/*Wi-Fi use buffer to exchange data*/
#define WIFI_MEM_START_ADDR 0x2003C000UL
#endif /*__WM_RAM_CONFIG_H__*/

View File

@@ -0,0 +1,918 @@
/**
* @file wm_regs.h
*
* @brief register & operation file
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_REGS_H
#define WM_REGS_H
#define __MPU_PRESENT 1
#define __CM3_REV 0x0201 /*!< Core Revision r2p1 */
#define __NVIC_PRIO_BITS 4 /*!< W600 uses 4 Bits for the Priority Levels */
#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
typedef enum IRQn
{
/****** Cortex-M3 Processor Exceptions Numbers ***************************************************/
NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */
BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */
UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */
SVCall_IRQn = -5, /*!< 11 Cortex-M3 SV Call Interrupt */
DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 Debug Monitor Interrupt */
PendSV_IRQn = -2, /*!< 14 Cortex-M3 Pend SV Interrupt */
SysTick_IRQn = -1, /*!< 15 Cortex-M3 System Tick Interrupt */
/****** Venus specific Interrupt Numbers *********************************************************/
SDIO_RX_IRQn = 0, /*!< SDIO Receiver Interrupt */
SDIO_TX_IRQn = 1, /*!< SDIO Transmit Interrupt */
SDIO_RX_CMD_IRQn = 2, /*!< SDIO Command Receiver Interrupt */
SDIO_TX_CMD_IRQn = 3, /*!< SDIO Command Transmit Interrupt */
MAC_IRQn = 4, /*!< MAC Interrupt */
SEC_RX_IRQn = 6, /*!< EXTI Line0 Interrupt */
SEC_TX_MNGT_IRQn = 7, /*!< EXTI Line1 Interrupt */
SEC_TX_DAT_IRQn = 8, /*!< EXTI Line2 Interrupt */
PMU_RTC_IRQn = 9, /*!< PMU RTC Interrupt */
PMU_SLP_INTVL_IRQn = 10, /*!< PMU Sleep Interval Interrupt */
PMU_GPIO_WAKE_IRQn = 11, /*!< PMU GPIO Wake Interrupt */
PMU_SDIO_WAKE_IRQn = 12, /*!< PMU SDIO Wake Interrupt */
DMA_Channel0_IRQn = 13, /*!< DMA Channel 0 global Interrupt */
DMA_Channel1_IRQn = 14, /*!< DMA Channel 1 global Interrupt */
DMA_Channel2_IRQn = 15, /*!< DMA Channel 2 global Interrupt */
DMA_Channel3_IRQn = 16, /*!< DMA Channel 3 global Interrupt */
DMA_Channel4_7_IRQn = 17, /*!< DMA Channel 4~7 global Interrupt */
DMA_BRUST_IRQn = 18, /*!< DMA Burst global Interrupt */
I2C_IRQn = 19, /*!< I2C Interrupts */
ADC_IRQn = 20, /*!< ADC Convert Interrupts */
SPI_LS_IRQn = 21, /*!< Low Speed SPI Interrupt */
SPI_HS_IRQn = 22, /*!< High Speed SPI Interrupt */
UART0_IRQn = 23, /*!< UART0 Interrupts */
UART1_IRQn = 24, /*!< UART1 Interrupt */
GPIO_IRQn = 25, /*!< GPIO Interrupt */
TIM1_IRQn = 26, /*!< TIM1 Trigger and Commutation Interrupt */
TIM2_IRQn = 27, /*!< TIM1 Capture Compare Interrupt */
TIM3_IRQn = 28, /*!< TIM2 global Interrupt */
TIM4_IRQn = 29, /*!< TIM3 global Interrupt */
TIM5_IRQn = 31, /*!< I2C1 Event Interrupt */
WDG_IRQn = 32, /*!< Watch Dog Interrupt */
PMU_IRQn = 33, /*!< PMU Interrupt */
FLASH_IRQn = 34, /*!< Flash Interrupt */
PWM_IRQn = 35, /*!< PWM Interrupt */
I2S_IRQn = 36, /*!< I2S Interrupts */
RSA_IRQn = 38,
CRYPTION_IRQn = 39,
GPIOB_IRQn = 40,
UART2_IRQn = 41,
} IRQn_Type;
#include "core_cm3.h"
typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
typedef volatile unsigned int TLS_REG; /* Hardware register definition */
#define APB_CLK (40000000) /* 40MHz */
#define DEVICE_BASE_ADDR 0x40000000
/***************************************************************
* SDIO模块寄存器定义
***************************************************************/
#define HR_SDIO_BASE_ADDR DEVICE_BASE_ADDR
#define HR_SDIO_CIS0 (HR_SDIO_BASE_ADDR + 0x008)
#define HR_SDIO_CIS1 (HR_SDIO_BASE_ADDR + 0x00C)
#define HR_SDIO_CSA (HR_SDIO_BASE_ADDR + 0x010)
#define HR_SDIO_READ (HR_SDIO_BASE_ADDR + 0x014)
#define HR_SDIO_WRITE (HR_SDIO_BASE_ADDR + 0x018)
#define HR_SDIO_INTEN (HR_SDIO_BASE_ADDR + 0x030)
#define HR_SDIO_OCR (HR_SDIO_BASE_ADDR + 0x034)
#define HR_SDIO_CIA (HR_SDIO_BASE_ADDR + 0x024)
#define HR_SDIO_PROG (HR_SDIO_BASE_ADDR + 0x028)
/***************************************************************
* SPI模块寄存器定义
***************************************************************/
#define HR_HSPI_BASE_ADDR (DEVICE_BASE_ADDR + 0x200)
#define HR_HSPI_CLEAR_FIFO (HR_HSPI_BASE_ADDR)
#define HR_HSPI_SPI_CFG (HR_HSPI_BASE_ADDR + 0x04)
#define HR_HSPI_MODE_CFG (HR_HSPI_BASE_ADDR + 0x08)
#define HR_HSPI_INT_MASK (HR_HSPI_BASE_ADDR + 0x0C)
#define HR_HSPI_INT_STTS (HR_HSPI_BASE_ADDR + 0x10)
#define HR_HSPI_RXDAT_LEN (HR_HSPI_BASE_ADDR + 0x18)
/***************************************************************
* SDIO WRAPPER寄存器定义
***************************************************************/
#define HR_SDIO_WRAPPER_BASE_ADDR (DEVICE_BASE_ADDR + 0x300)
#define HR_SDIO_INT_SRC (HR_SDIO_WRAPPER_BASE_ADDR + 0x000)
#define HR_SDIO_INT_MASK (HR_SDIO_WRAPPER_BASE_ADDR + 0x004)
#define HR_SDIO_UPCMDVALID (HR_SDIO_WRAPPER_BASE_ADDR + 0x008)
#define HR_SDIO_DOWNCMDVALID (HR_SDIO_WRAPPER_BASE_ADDR + 0x00C)
#define HR_SDIO_TXBD_LINKEN (HR_SDIO_WRAPPER_BASE_ADDR + 0x010)
#define HR_SDIO_TXBD_ADDR (HR_SDIO_WRAPPER_BASE_ADDR + 0x014)
#define HR_SDIO_TXEN (HR_SDIO_WRAPPER_BASE_ADDR + 0x018)
#define HR_SDIO_TX_STTS (HR_SDIO_WRAPPER_BASE_ADDR + 0x01C)
#define HR_SDIO_RXBD_LINKEN (HR_SDIO_WRAPPER_BASE_ADDR + 0x020)
#define HR_SDIO_RXBD_ADDR (HR_SDIO_WRAPPER_BASE_ADDR + 0x024)
#define HR_SDIO_RXEN (HR_SDIO_WRAPPER_BASE_ADDR + 0x028)
#define HR_SDIO_RX_STTS (HR_SDIO_WRAPPER_BASE_ADDR + 0x02C)
#define HR_SDIO_CMD_ADDR (HR_SDIO_WRAPPER_BASE_ADDR + 0x030)
#define HR_SDIO_CMD_SIZE (HR_SDIO_WRAPPER_BASE_ADDR + 0x034)
/* 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)
/***************************************************************
* DMA模块寄存器定义
***************************************************************/
#define HR_DMA_BASE_ADDR (DEVICE_BASE_ADDR + 0x400)
#define HR_DMA_INT_MASK (HR_DMA_BASE_ADDR + 0x0)
#define HR_DMA_INT_SRC (HR_DMA_BASE_ADDR + 0x4)
#define HR_DMA_CHNL_SEL (HR_DMA_BASE_ADDR + 0x08)
#define HR_DMA_CHNL0_SRC_ADDR (HR_DMA_BASE_ADDR + 0x10)
#define HR_DMA_CHNL0_DEST_ADDR (HR_DMA_BASE_ADDR + 0x14)
#define HR_DMA_CHNL0_SRC_WRAP_ADDR (HR_DMA_BASE_ADDR + 0x18)
#define HR_DMA_CHNL0_DEST_WRAP_ADDR (HR_DMA_BASE_ADDR + 0x1C)
#define HR_DMA_CHNL0_WRAP_SIZE (HR_DMA_BASE_ADDR + 0x20)
#define HR_DMA_CHNL0_CHNL_CTRL (HR_DMA_BASE_ADDR + 0x24)
#define HR_DMA_CHNL0_DMA_MODE (HR_DMA_BASE_ADDR + 0x28)
#define HR_DMA_CHNL0_DMA_CTRL (HR_DMA_BASE_ADDR + 0x2C)
#define HR_DMA_CHNL0_DMA_STATUS (HR_DMA_BASE_ADDR + 0x30)
#define HR_DMA_CHNL0_LINK_DEST_ADDR (HR_DMA_BASE_ADDR + 0x34)
#define HR_DMA_CHNL0_CURRENT_DEST_ADDR (HR_DMA_BASE_ADDR + 0x38)
#define DMA_STARTADDRESS (0x40000400)
#define DMA_INTMASK_REG (*(volatile unsigned int*)(DMA_STARTADDRESS+0x000))
#define DMA_INTSRC_REG (*(volatile unsigned int*)(DMA_STARTADDRESS+0x004))
#define DMA_CHNL_REG_BASE (DMA_STARTADDRESS+0x010)
#define DMA_SRCADDR_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x00))
#define DMA_DESTADDR_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x04))
#define DMA_SRCWRAPADDR_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x08))
#define DMA_DESTWRAPADDR_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x0C))
#define DMA_WRAPSIZE_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x10))
#define DMA_CHNLCTRL_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x14))
#define DMA_MODE_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x18))
#define DMA_CTRL_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x1C))
#define DMA_STATUS_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x20))
#define DMA_CURRSRCADDR_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x24))
#define DMA_CURRDESTADDR_REG(ch) (*(volatile unsigned int*)(DMA_CHNL_REG_BASE + 0x30 * (ch /*- 1*/) +0x28))
#define DMA_CHNL_CTRL_CHNL_ON (1<<0)
#define DMA_CHNL_CTRL_CHNL_OFF (1<<1)
#define DMA_MODE_HARD_MODE (1<<0)
#define DMA_MODE_CHAIN_MODE (1<<1)
/***************************************************************
* 节能模块寄存器定义
***************************************************************/
#define HR_PMU_BASE_ADDR (DEVICE_BASE_ADDR + 0x600)
#define HR_PMU_PS_CR (HR_PMU_BASE_ADDR + 0x00)
#define HR_PMU_TIMER0 (HR_PMU_BASE_ADDR + 0x04)
#define HR_PMU_TIMER1 (HR_PMU_BASE_ADDR + 0x08)
#define HR_PMU_RTC_CTRL1 (HR_PMU_BASE_ADDR + 0x0C)
#define HR_PMU_RTC_CTRL2 (HR_PMU_BASE_ADDR + 0x10)
#define HR_PMU_INTERRUPT_SRC (HR_PMU_BASE_ADDR + 0x14)
#define HR_PMU_INTERRUPT_MASK (HR_PMU_BASE_ADDR + 0x18)
#define HR_PMU_WLAN_STTS (HR_PMU_BASE_ADDR + 0x1C)
/* 节能寄存器位定义 */
#define PMU_WLAN_SLEEP_EN_BIT (1UL << 0)
#define PMU_PRETBTT_PERIOD_RSV (0xE0000000)
#define PMU_TBTT_TIMER_MASK (0x3FFFF)
#define PMU_TBTT_TIMER_SHIFT (11)
#define PMU_SLEEP_INTERVAL_MASK (0x7FF)
#define PMU_SLEEP_INTERVAL_SHIFT (0)
#define PMU_TBTT_OFFSET_MASK (0x7FFF)
#define PMU_TBTT_OFFSET_SHIFT (17)
#define PMU_PRETBTT_TIMER_MASK (0x1FFFF)
#define PMU_PRETBTT_TIMER_SHIFT (0)
#define PMU_PRETBTT_OFFSET_DEFAULT (((30UL) << 17) | (300UL))
#define PMU_TIMER0_WAKEUP_EN (1UL << 3)
#define PMU_TIMER1_WAKEUP_EN (1UL << 2)
#define PMU_GPIO_WAKEUP_EN (1UL << 1)
#define PMU_SDIO_WAKEUP_EN (1UL << 0)
#define PMU_TIMER0_NTERRUPT_SRC (1UL << 0)
#define PMU_TIMER1_NTERRUPT_SRC (1UL << 1)
#define PMU_GPIO_NTERRUPT_SRC (1UL << 2)
#define PMU_SDIO_NTERRUPT_SRC (1UL << 3)
#define PMU_TIMER0_NTERRUPT_MASK (1UL << 0)
#define PMU_TIMER1_NTERRUPT_MASK (1UL << 1)
#define PMU_GPIO_NTERRUPT_MASK (1UL << 2)
#define PMU_SDIO_NTERRUPT_MASK (1UL << 3)
#define PMU_WLAN_RX_IDLE_BIT (1UL << 1)
#define PMU_WLAN_TX_IDLE_BIT (1UL << 0)
#define PMU_LDO_DAC28_BYPASS (1UL<<0)
#define PMU_LDO_SW_BYPASS (1UL<<1)
#define PMU_DLDO_BYPASS (1UL<<2)
#define PMU_LDO_PRE_BYPASS (1UL<<3)
#define PMU_LDO_ADDA_D_BYPASS (1UL<<4)
#define PMU_LDO_ADDA_A_BYPASS (1UL<<5)
#define PMU_LDO_UM_PA_BYPASS (1UL<<6)
#define PMU_LDO_CHP_BYPASS (1UL<<7)
#define PMU_LDO_DM_IF_BYPASS (1UL<<8)
#define PMU_LDO_LNA_BYPASS (1UL<<9)
#define PMU_LDO_VCO_BYPASS (1UL<<10)
#define PMU_LDO_LO_BYPASS (1UL<<11)
#define PMU_LDO_PLL_BYPASS (1UL<<15)
#define PMU_LDO_WLAN_BYPASS (1UL<<19)
#define PMU_LDO_BGR_BYPASS (1UL<<20)
#define PMU_LDO_BB_BYPASS (1UL<<21)
/***************************************************************
* system clock 和bus clock寄存器定义
***************************************************************/
#define HR_CLK_BASE_ADDR (DEVICE_BASE_ADDR + 0x700)
#define HR_CLK_SOFT_CLK_MASK (HR_CLK_BASE_ADDR + 0x04)
#define HR_CLK_BBP_CLT_CTRL (HR_CLK_BASE_ADDR + 0x08)
#define HR_CLK_RST_CTL (HR_CLK_BASE_ADDR + 0x0c)
#define HR_CLK_DIV_CTL (HR_CLK_BASE_ADDR + 0x10)
#define HR_CLK_I2S_CTL (HR_CLK_BASE_ADDR + 0x18)
#define I2S_CLK_CTL_EXT_Pos (0)
#define I2S_CLK_CTL_MCLK_Pos (1)
#define I2S_CLK_CTL_MCLKDIV_Pos (2)
#define I2S_CLK_CTL_BCLKDIV_Pos (8)
/***************************************************************
* 内存模块寄存器定义
***************************************************************/
#define HR_MEM_BASE_ADDR (DEVICE_BASE_ADDR + 0x800)
#define HR_MEM_TXBUF_BASE_ADDR (HR_MEM_BASE_ADDR + 0x00)
#define HR_MEM_RXBUF_BASE_ADDR (HR_MEM_BASE_ADDR + 0x04)
#define HR_MEM_BUF_NUM_CFG (HR_MEM_BASE_ADDR + 0x08)
#define HR_MEM_BUF_SIZE_CFG (HR_MEM_BASE_ADDR + 0x0C)
#define HR_MEM_AGGR_CFG (HR_MEM_BASE_ADDR + 0x10)
#define HR_MEM_BUF_EN (HR_MEM_BASE_ADDR + 0x14)
/***************************************************************
* 中断模块寄存器定义
***************************************************************/
#define HR_VIC_BASE_ADDR 0xFFFFF000
#define HR_VIC_IRQ_STATUS (HR_VIC_BASE_ADDR + 0x0)
#define HR_VIC_FIQ_STATUS (HR_VIC_BASE_ADDR + 0x4)
#define HR_VIC_RAW_INTR (HR_VIC_BASE_ADDR + 0x8)
#define HR_VIC_INT_SELECT (HR_VIC_BASE_ADDR + 0xc)
#define HR_VIC_INT_ENABLE (HR_VIC_BASE_ADDR + 0x10)
#define HR_VIC_INT_EN_CLR (HR_VIC_BASE_ADDR + 0x14)
#define HR_VIC_SOFT_INT (HR_VIC_BASE_ADDR + 0x18)
#define HR_VIC_SOFT_INT_CLR (HR_VIC_BASE_ADDR + 0x1c)
#define HR_VIC_PROTECT (HR_VIC_BASE_ADDR + 0x20)
#define HR_VIC_VECT_ADDR (HR_VIC_BASE_ADDR + 0x30)
#define HR_VIC_DEF_VECT_ADDR (HR_VIC_BASE_ADDR + 0x34)
#define HR_VIC_VECT_ENABLE (HR_VIC_BASE_ADDR + 0x100)
#define HR_VIC_VECT_BASE_ADDR (HR_VIC_BASE_ADDR + 0x104)
#define HR_VIC_INT_NUM (HR_VIC_BASE_ADDR + 0x108)
#define HR_VIC_INT_PRIO0 (HR_VIC_BASE_ADDR + 0x10C)
#define HR_VIC_INT_PRIO1 (HR_VIC_BASE_ADDR + 0x110)
#define HR_VIC_INT_PRIO2 (HR_VIC_BASE_ADDR + 0x114)
#define HR_VIC_INT_PRIO3 (HR_VIC_BASE_ADDR + 0x118)
/* APB基地址*/
#define HR_APB_BASE_ADDR 0x40010000
/***************************************************************
* I2C模块寄存器定义
***************************************************************/
#define HR_I2C_BASE_ADDR (HR_APB_BASE_ADDR)
#define HR_I2C_PRER_LO (HR_I2C_BASE_ADDR + 0x0)
#define HR_I2C_PRER_HI (HR_I2C_BASE_ADDR + 0x04)
#define HR_I2C_CTRL (HR_I2C_BASE_ADDR + 0x08)
#define HR_I2C_TX_RX (HR_I2C_BASE_ADDR + 0x0C)
#define HR_I2C_CR_SR (HR_I2C_BASE_ADDR + 0x10)
#define HR_I2C_TXR (HR_I2C_BASE_ADDR + 0x14)
#define HR_I2C_CR (HR_I2C_BASE_ADDR + 0x18)
#define I2C_CTRL_INT_DISABLE (0x1UL<<6)
#define I2C_CTRL_ENABLE (0x1UL<<7)
#define I2C_CR_STA (0x1UL<<7)
#define I2C_CR_STO (0x1UL<<6)
#define I2C_CR_RD (0x1UL<<5)
#define I2C_CR_WR (0x1UL<<4)
#define I2C_CR_NAK (0x1UL<<3)
#define I2C_CR_IACK (0x1UL)
#define I2C_SR_NAK (0x1UL<<7)
#define I2C_SR_BUSY (0x1UL<<6)
#define I2C_SR_TIP (0x1UL<<1)
#define I2C_SR_IF (0x1UL)
/***************************************************************
* SD ADC模块寄存器定义
***************************************************************/
#define HR_SD_ADC_BASE_ADDR (HR_APB_BASE_ADDR + 0x200)
#define HR_SD_ADC_RESULT_REG ((HR_SD_ADC_BASE_ADDR+0x000))
#define HR_SD_ADC_CONFIG_REG ((HR_SD_ADC_BASE_ADDR+0x004))
#define HR_SD_ADC_CTRL_REG ((HR_SD_ADC_BASE_ADDR+0x008))
#define HR_SD_ADC_INT_MASK_REG ((HR_SD_ADC_BASE_ADDR+0x00C))
#define HR_SD_ADC_INT_SOURCE_REG ((HR_SD_ADC_BASE_ADDR+0x010))
/***************************************************************
* SPI模块寄存器定义
***************************************************************/
#define HR_SPI_BASE_ADDR (HR_APB_BASE_ADDR + 0x400)
#define HR_SPI_CHCFG_REG (HR_SPI_BASE_ADDR + 0x000)
#define HR_SPI_SPICFG_REG (HR_SPI_BASE_ADDR + 0x004)
#define HR_SPI_CLKCFG_REG (HR_SPI_BASE_ADDR + 0x008)
#define HR_SPI_MODECFG_REG (HR_SPI_BASE_ADDR + 0x00C)
#define HR_SPI_INT_MASK_REG (HR_SPI_BASE_ADDR + 0x010)
#define HR_SPI_INT_STATUS_REG (HR_SPI_BASE_ADDR + 0x014)
#define HR_SPI_STATUS_REG (HR_SPI_BASE_ADDR + 0x018)
#define HR_SPI_TIMEOUT_REG (HR_SPI_BASE_ADDR + 0x01C)
#define HR_SPI_TXDATA_REG (HR_SPI_BASE_ADDR + 0x020)
#define HR_SPI_TRANSLEN_REG (HR_SPI_BASE_ADDR + 0x024)
#define HR_SPI_SLV_XMIT_LEN_REG (HR_SPI_BASE_ADDR + 0x028)
#define HR_SPI_RXDATA_REG (HR_SPI_BASE_ADDR + 0x030)
#define SPIM_STARTADDRESS (HR_APB_BASE_ADDR + 0x400)
#define SPIM_CHCFG_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x000))
#define SPIM_SPICFG_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x004))
#define SPIM_CLKCFG_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x008))
#define SPIM_MODECFG_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x00C))
#define SPIM_INTEN_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x010))
#define SPIM_INTSRC_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x014))
#define SPIM_SPISTATUS_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x018))
#define SPIM_SPITIMEOUT_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x01C))
#define SPIM_TXDATA_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x020))
#define SPIM_TRANSLEN_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x024))
#define SPIM_RXDATA_REG (*(volatile unsigned int*)(SPIM_STARTADDRESS+0x030))
/*RSA寄存器*/
#define RSA_BASE_ADDRESS 0x40002200
#define RSAXBUF (*((volatile unsigned long *) (RSA_BASE_ADDRESS + 0x0 )))
#define RSAYBUF (*((volatile unsigned long *) (RSA_BASE_ADDRESS + 0x100 )))
#define RSAMBUF (*((volatile unsigned long *) (RSA_BASE_ADDRESS + 0x200 )))
#define RSADBUF (*((volatile unsigned long *) (RSA_BASE_ADDRESS + 0x300 )))
#define RSACON (*((volatile unsigned long *) (RSA_BASE_ADDRESS + 0x400 )))
#define RSAMC (*((volatile unsigned long *) (RSA_BASE_ADDRESS + 0x404 )))
#define RSAN (*((volatile unsigned long *) (RSA_BASE_ADDRESS + 0x408 )))
/* Bits Definitions of "CH_CFG" */
#define SPI_RX_INVALID_BITS(n) ((n) << 23)
#define SPI_CLEAR_FIFOS (1U << 22)
#define SPI_CONTINUE_MODE (1U << 21)
#define SPI_RX_CHANNEL_ON (1U << 20)
#define SPI_RX_CHANNEL_OFF (0U << 20)
#define SPI_TX_CHANNEL_ON (1U << 19)
#define SPI_TX_CHANNEL_OFF (0U << 19)
#define SPI_VALID_CLKS_NUM(n) ((n) << 3)
#define SPI_CS_LOW (0U << 2)
#define SPI_CS_HIGH (1U << 2)
#define SPI_FORCE_SPI_CS_OUT (1U << 1)
#define SPI_START (1U << 0)
/* Bits Definitions of "SPI_CFG" */
#define SPI_FRAME_FORMAT_MOTO (0U << 17)
#define SPI_FRAME_FORMAT_TI (1U << 17)
#define SPI_FRAME_FORMAT_MICROWAIRE (2U << 17)
#define SPI_TX_PIN_ALWS_DRIVER (1U << 16)
#define SPI_CS_HOLD(n) ((n) << 12)
#define CS_HOLD_1_CLKS 0
#define CS_HOLD_2_CLKS 1
#define CS_HOLD_4_CLKS 2
#define CS_HOLD_8_CLKS 3
#define CS_HOLD_16_CLKS 4
#define CS_HOLD_32_CLKS 5
#define CS_HOLD_64_CLKS 6
#define CS_HOLD_127_CLKS 7
#define SPI_CS_SETUP(n) ((n) << 9)
#define CS_SETUP_1_CLKS 0
#define CS_SETUP_2_CLKS 1
#define CS_SETUP_4_CLKS 2
#define CS_SETUP_8_CLKS 3
#define CS_SETUP_16_CLKS 4
#define CS_SETUP_32_CLKS 5
#define CS_SETUP_64_CLKS 6
#define CS_SETUP_127_CLKS 7
#define SPI_DATA_OUT_DELAY(n) ((n) << 7)
#define DATA_OUT_DELAY_1_CLKS 0
#define DATA_OUT_DELAY_2_CLKS 1
#define DATA_OUT_DELAY_3_CLKS 2
#define DATA_OUT_DELAY_0_CLKS 3
#define SPI_FRAME_DELAY(n) ((n) << 4)
#define FRAME_DELAY_1_CLKS 0
#define FRAME_DELAY_2_CLKS 1
#define FRAME_DELAY_4_CLKS 2
#define FRAME_DELAY_8_CLKS 3
#define FRAME_DELAY_16_CLKS 4
#define FRAME_DELAY_32_CLKS 5
#define FRAME_DELAY_64_CLKS 6
#define FRAME_DELAY_127_CLKS 7
#define SPI_LITTLE_ENDIAN (0 << 3)
#define SPI_BIG_ENDIAN (1 << 3)
#define SPI_SET_MASTER_SLAVE(mode) ((mode) << 2)
#define SPI_MASTER 1
#define SPI_SLAVE 0
#define SPI_SET_CPHA(n) ((n) << 1)
#define SPI_SET_CPOL(n) ((n) << 0)
/* Bits Definitions of "CLK_CFG" */
#define SPI_GET_SCLK_DIVIDER(clk) ((APB_CLK)/((clk) * 2) - 1)/*In HZ*/
#define SPI_SCLK_DIVIDER(n) ((n) << 0)
/* Bits Definitions of "MODE_CFG" */
#define SPI_RX_TRIGGER_LEVEL(n) ((n) << 6)
#define SPI_TX_TRIGGER_LEVEL(n) ((n) << 2)
#define SPI_RX_DMA_ON (1 << 1)
#define SPI_RX_DMA_OFF (0 << 1)
#define SPI_TX_DMA_ON (1 << 0)
#define SPI_TX_DMA_OFF (0 << 0)
/* Bits Definitions of SPI interrupt register(SPI_INT_MASK and SPI_INT_SOURCE) */
#define SPI_INT_MASK_ALL 0xffU
#define SPI_INT_CLEAR_ALL 0xffU
#define SPI_INT_TIMEOUT (1U << 7)
#define SPI_INT_TRANSFER_DONE (1U << 6)
#define SPI_INT_RX_OVERRUN (1U << 5)
#define SPI_INT_RX_UNDERRUN (1U << 4)
#define SPI_INT_TX_OVERRUN (1U << 3)
#define SPI_INT_TX_UNDERRUN (1U << 2)
#define SPI_INT_RX_FIFO_RDY (1U << 1)
#define SPI_INT_TX_FIFO_RDY (1U << 0)
/* Bits Definitions of "SPI_STATUS" */
#define SPI_IS_BUSY(value) ((((value) & (1 << 12)) != 0) ? 1 : 0)
#define SPI_GET_RX_FIFO_CNT(value) (((value) & 0xFC0) >> 6)
#define SPI_GET_TX_FIFO_CNT(value) ((value) & 0x3F)
/* Bits Definitions of "SPI_TIMEOUT" */
#define SPI_TIMER_EN (1U << 31)
#define SPI_TIME_OUT(n) (((((n) * (APB_CLK)) / 1000) & ~(0x01U << 31)) << 0)
/***************************************************************
* UART寄存器定义
***************************************************************/
#define HR_UART0_BASE_ADDR (HR_APB_BASE_ADDR + 0x800)
#define HR_UART1_BASE_ADDR (HR_APB_BASE_ADDR + 0xA00)
#define HR_UART2_BASE_ADDR (HR_APB_BASE_ADDR + 0x1C00)
#define HR_UART0_LINE_CTRL (HR_UART0_BASE_ADDR + 0x0)
#define HR_UART0_FLOW_CTRL (HR_UART0_BASE_ADDR + 0x04)
#define HR_UART0_DMA_CTRL (HR_UART0_BASE_ADDR + 0x08)
#define HR_UART0_FIFO_CTRL (HR_UART0_BASE_ADDR + 0x0C)
#define HR_UART0_BAUD_RATE_CTRL (HR_UART0_BASE_ADDR + 0x10)
#define HR_UART0_INT_MASK (HR_UART0_BASE_ADDR + 0x14)
#define HR_UART0_INT_SRC (HR_UART0_BASE_ADDR + 0x18)
#define HR_UART0_FIFO_STATUS (HR_UART0_BASE_ADDR + 0x1C)
#define HR_UART0_TX_WIN (HR_UART0_BASE_ADDR + 0x20)
#define HR_UART0_RX_WIN (HR_UART0_BASE_ADDR + 0x30)
#define HR_UART1_LINE_CTRL (HR_UART1_BASE_ADDR + 0x0)
#define HR_UART1_FLOW_CTRL (HR_UART1_BASE_ADDR + 0x04)
#define HR_UART1_DMA_CTRL (HR_UART1_BASE_ADDR + 0x08)
#define HR_UART1_FIFO_CTRL (HR_UART1_BASE_ADDR + 0x0C)
#define HR_UART1_BAUD_RATE_CTRL (HR_UART1_BASE_ADDR + 0x10)
#define HR_UART1_INT_MASK (HR_UART1_BASE_ADDR + 0x14)
#define HR_UART1_INT_SRC (HR_UART1_BASE_ADDR + 0x18)
#define HR_UART1_FIFO_STATUS (HR_UART1_BASE_ADDR + 0x1C)
#define HR_UART1_TX_WIN (HR_UART1_BASE_ADDR + 0x20)
#define HR_UART1_RX_WIN (HR_UART1_BASE_ADDR + 0x30)
#define HR_UART2_LINE_CTRL (HR_UART2_BASE_ADDR + 0x0)
#define HR_UART2_FLOW_CTRL (HR_UART2_BASE_ADDR + 0x04)
#define HR_UART2_DMA_CTRL (HR_UART2_BASE_ADDR + 0x08)
#define HR_UART2_FIFO_CTRL (HR_UART2_BASE_ADDR + 0x0C)
#define HR_UART2_BAUD_RATE_CTRL (HR_UART2_BASE_ADDR + 0x10)
#define HR_UART2_INT_MASK (HR_UART2_BASE_ADDR + 0x14)
#define HR_UART2_INT_SRC (HR_UART2_BASE_ADDR + 0x18)
#define HR_UART2_FIFO_STATUS (HR_UART2_BASE_ADDR + 0x1C)
#define HR_UART2_TX_WIN (HR_UART2_BASE_ADDR + 0x20)
#define HR_UART2_RX_WIN (HR_UART2_BASE_ADDR + 0x30)
#define HR_UART2_GUARD_TIME (HR_UART2_BASE_ADDR + 0x40)
#define HR_UART2_WAIT_TIME (HR_UART2_BASE_ADDR + 0x44)
/*
* Line Control Register bits definition
* ULCON0 ULCON1 Register
*/
/* bit 0-1 : Word length */
#define ULCON_WL5 0x00
#define ULCON_WL6 0x01
#define ULCON_WL7 0x02
#define ULCON_WL8 0x03
#define ULCON_WL_MASK 0x03
/* bit 2 : Number of stop bits */
#define ULCON_STOP_2 0x04 /* 2 stop bit */
/* bit 3-4 : Parity mode */
#define ULCON_PMD_MASK 0x18
#define ULCON_PMD_EN 0x08 /* no parity */
#define ULCON_PMD_ODD 0x18 /* odd parity */
#define ULCON_PMD_EVEN 0x08 /* even parity */
/* bit 6 uart tx enable */
#define ULCON_TX_EN 0x40
#define ULCON_RX_EN 0x80
/* bit 6 : Infra-red mode */
#define ULCON_INFRA_RED 0x80
/*
* auto flow control register bits definition
*/
#define UFC_ENABLE 0x01
#define UFC_SW_RTS_SET 0x02
#define UFC_RTS_TRIGGER_LVL_4_BYTE (0<<2)
#define UFC_RTS_TRIGGER_LVL_8_BYTE (1<<2)
#define UFC_RTS_TRIGGER_LVL_12_BYTE (2<<2)
#define UFC_RTS_TRIGGER_LVL_16_BYTE (3<<2)
#define UFC_RTS_TRIGGER_LVL_20_BYTE (4<<2)
#define UFC_RTS_TRIGGER_LVL_24_BYTE (5<<2)
#define UFC_RTS_TRIGGER_LVL_28_BYTE (6<<2)
#define UFC_RTS_TRIGGER_LVL_31_BYTE (7<<2)
#define UFC_TX_FIFO_RESET 0x01
#define UFC_RX_FIFO_RESET 0x02
#define UFC_TX_FIFO_LVL_ZERO (0<<2)
#define UFC_TX_FIFO_LVL_4_BYTE (1<<2)
#define UFC_TX_FIFO_LVL_8_BYTE (2<<2)
#define UFC_TX_FIFO_LVL_16_BYTE (3<<2)
#define UFC_RX_FIFO_LVL_ZERO (0<<4)
#define UFC_RX_FIFO_LVL_4_BYTE (1<<4)
#define UFC_RX_FIFO_LVL_8_BYTE (2<<4)
#define UFC_RX_FIFO_LVL_16_BYTE (3<<4)
/* dma control */
#define UDMA_RX_FIFO_TIMEOUT (1<<2)
#define UDMA_RX_FIFO_TIMEOUT_SHIFT (3)
/*
* uart interrupt source register bits definition
*/
#define UIS_TX_FIFO_EMPTY (1UL<<0)
#define UIS_TX_FIFO (1UL<<1)
#define UIS_RX_FIFO (1UL<<2)
#define UIS_RX_FIFO_TIMEOUT (1UL<<3)
#define UIS_CTS_CHNG (1UL<<4)
#define UIS_BREAK (1UL<<5)
#define UIS_FRM_ERR (1UL<<6)
#define UIS_PARITY_ERR (1UL<<7)
#define UIS_OVERRUN (1UL<<8)
/*
* fifo status register bits definition
*/
/* bit 0-5 : tx fifo count */
#define UFS_TX_FIFO_CNT_MASK 0x3F
/* bit 6-11 : rx fifo count */
#define UFS_RX_FIFO_CNT_MASK 0x3C0
#define UFS_CST_STS (1UL<<12)
/***************************************************************
* GPIO寄存器定义
***************************************************************/
#define HR_GPIO_BASE_ADDR (HR_APB_BASE_ADDR + 0x0C00)
#define HR_GPIO_DATA (HR_GPIO_BASE_ADDR + 0x0)
#define HR_GPIO_DATA_EN (HR_GPIO_BASE_ADDR + 0x04)
#define HR_GPIO_DIR (HR_GPIO_BASE_ADDR + 0x08)
#define HR_GPIO_PULL_EN (HR_GPIO_BASE_ADDR + 0x0C)
#define HR_GPIO_AF_SEL (HR_GPIO_BASE_ADDR + 0x10)
#define HR_GPIO_AF_S1 (HR_GPIO_BASE_ADDR + 0x14)
#define HR_GPIO_AF_S0 (HR_GPIO_BASE_ADDR + 0x18)
#define HR_GPIO_IS (HR_GPIO_BASE_ADDR + 0x20)
#define HR_GPIO_IBE (HR_GPIO_BASE_ADDR + 0x24)
#define HR_GPIO_IEV (HR_GPIO_BASE_ADDR + 0x28)
#define HR_GPIO_IE (HR_GPIO_BASE_ADDR + 0x2c)
#define HR_GPIO_RIS (HR_GPIO_BASE_ADDR + 0x30)
#define HR_GPIO_MIS (HR_GPIO_BASE_ADDR + 0x34)
#define HR_GPIO_IC (HR_GPIO_BASE_ADDR + 0x38)
#define HR_GPIOA_BASE_ADDR (HR_APB_BASE_ADDR + 0x0C00)
#define HR_GPIOA_DATA (HR_GPIOA_BASE_ADDR + 0x0)
#define HR_GPIOA_DATA_EN (HR_GPIOA_BASE_ADDR + 0x04)
#define HR_GPIOA_DATA_DIR (HR_GPIOA_BASE_ADDR + 0x08)
#define HR_GPIOA_DATA_PULLEN (HR_GPIOA_BASE_ADDR + 0x0c)
#define HR_GPIOA_AFSEL (HR_GPIOA_BASE_ADDR + 0x10)
#define HR_GPIOA_AFS1 (HR_GPIOA_BASE_ADDR + 0x14)
#define HR_GPIOA_AFS0 (HR_GPIOA_BASE_ADDR + 0x18)
#define HR_GPIOA_IS (HR_GPIOA_BASE_ADDR + 0x20)
#define HR_GPIOA_IBE (HR_GPIOA_BASE_ADDR + 0x24)
#define HR_GPIOA_IEV (HR_GPIOA_BASE_ADDR + 0x28)
#define HR_GPIOA_IE (HR_GPIOA_BASE_ADDR + 0x2C)
#define HR_GPIOA_RIS (HR_GPIOA_BASE_ADDR + 0x30)
#define HR_GPIOA_MIS (HR_GPIOA_BASE_ADDR + 0x34)
#define HR_GPIOA_IC (HR_GPIOA_BASE_ADDR + 0x38)
#define HR_GPIOB_BASE_ADDR (HR_APB_BASE_ADDR + 0x1200)
#define HR_GPIOB_DATA (HR_GPIOB_BASE_ADDR + 0x0)
#define HR_GPIOB_DATA_EN (HR_GPIOB_BASE_ADDR + 0x04)
#define HR_GPIOB_DATA_DIR (HR_GPIOB_BASE_ADDR + 0x08)
#define HR_GPIOB_DATA_PULLEN (HR_GPIOB_BASE_ADDR + 0x0c)
#define HR_GPIOB_AFSEL (HR_GPIOB_BASE_ADDR + 0x10)
#define HR_GPIOB_AFS1 (HR_GPIOB_BASE_ADDR + 0x14)
#define HR_GPIOB_AFS0 (HR_GPIOB_BASE_ADDR + 0x18)
#define HR_GPIOB_IS (HR_GPIOB_BASE_ADDR + 0x20)
#define HR_GPIOB_IBE (HR_GPIOB_BASE_ADDR + 0x24)
#define HR_GPIOB_IEV (HR_GPIOB_BASE_ADDR + 0x28)
#define HR_GPIOB_IE (HR_GPIOB_BASE_ADDR + 0x2C)
#define HR_GPIOB_RIS (HR_GPIOB_BASE_ADDR + 0x30)
#define HR_GPIOB_MIS (HR_GPIOB_BASE_ADDR + 0x34)
#define HR_GPIOB_IC (HR_GPIOB_BASE_ADDR + 0x38)
#define IO_PA_BASE_ADDR (HR_APB_BASE_ADDR + 0x0C00)
#define IO_PA_DATA (*(volatile unsigned int*)(IO_PA_BASE_ADDR + 0x0))
#define IO_PA_EN (*(volatile unsigned int*)(IO_PA_BASE_ADDR + 0x4))
#define IO_PA_DIR (*(volatile unsigned int*)(IO_PA_BASE_ADDR + 0x8))
#define IO_PA_REN (*(volatile unsigned int*)(IO_PA_BASE_ADDR + 0xC))
#define IO_PA_AFSEL (*(volatile unsigned int*)(IO_PA_BASE_ADDR + 0x10))
#define IO_PA_AFS1 (*(volatile unsigned int*)(IO_PA_BASE_ADDR + 0x14))
#define IO_PA_AFS0 (*(volatile unsigned int*)(IO_PA_BASE_ADDR + 0x18))
/***************************************************************
* TIMER寄存器定义
***************************************************************/
#define HR_TIMER_BASE_ADDR (HR_APB_BASE_ADDR + 0x0E00)
#define HR_TIMER_CFG (HR_TIMER_BASE_ADDR + 0x0)
#define HR_TIMER0_5_CSR (HR_TIMER_BASE_ADDR + 0x04)
#define HR_TIMER0_PRD (HR_TIMER_BASE_ADDR + 0x08)
#define HR_TIMER1_PRD (HR_TIMER_BASE_ADDR + 0x0C)
#define HR_TIMER2_PRD (HR_TIMER_BASE_ADDR + 0x10)
#define HR_TIMER3_PRD (HR_TIMER_BASE_ADDR + 0x14)
#define HR_TIMER4_PRD (HR_TIMER_BASE_ADDR + 0x18)
#define HR_TIMER5_PRD (HR_TIMER_BASE_ADDR + 0x1C)
/* timer csr bits defintion */
#define TLS_TIMER_MS_UNIT(n) (1UL<<(0+5*n))
#define TLS_TIMER_ONE_TIME(n) (1UL<<(1+5*n))
#define TLS_TIMER_EN(n) (1UL<<(2+5*n))
#define TLS_TIMER_INT_EN(n) (1UL<<(3+5*n))
#define TLS_TIMER_INT_CLR(n) (1UL<<(4+5*n))
/***************************************************************
* WATCH DOG寄存器定义
***************************************************************/
#define HR_WDG_BASE_ADDR (HR_APB_BASE_ADDR + 0x1000)
#define HR_WDG_LOAD_VALUE (HR_WDG_BASE_ADDR + 0x00)
#define HR_WDG_CUR_VALUE (HR_WDG_BASE_ADDR + 0x04)
#define HR_WDG_CTRL (HR_WDG_BASE_ADDR + 0x08)
#define HR_WDG_INT_CLR (HR_WDG_BASE_ADDR + 0x0C)
#define HR_WDG_INT_SRC (HR_WDG_BASE_ADDR + 0x10)
#define HR_WDG_INT_MIS (HR_WDG_BASE_ADDR + 0x14)
#define HR_WDG_LOCK (HR_WDG_BASE_ADDR + 0x40)
/***************************************************************
* IOCTL寄存器定义
***************************************************************/
#define HR_IOCTL_BASE_ADDR (HR_APB_BASE_ADDR + 0x1200)
#define HR_IOCTL_DL_MODE (HR_IOCTL_BASE_ADDR + 0x0)
#define HR_IOCTL_GP_SDIO_I2C (HR_IOCTL_BASE_ADDR + 0x04)
#define HR_IOCTL_GP_JTAG (HR_IOCTL_BASE_ADDR + 0x08)
#define HR_IOCTL_GP_SPI (HR_IOCTL_BASE_ADDR + 0x0C)
#define HR_IOCTL_PE (HR_IOCTL_BASE_ADDR + 0x10)
#define IOCTRL_STARTADDRESS (HR_APB_BASE_ADDR + 0x1200)
#define IOCTRL_DOWNLOAD_MODE_REG (*(volatile unsigned *)(IOCTRL_STARTADDRESS+0x000))
#define IOCTRL_PIN_CONFIG_REG1 (*(volatile unsigned *)(IOCTRL_STARTADDRESS+0x004))
#define IOCTRL_PIN_CONFIG_REG2 (*(volatile unsigned *)(IOCTRL_STARTADDRESS+0x008))
#define IOCTRL_PIN_CONFIG_REG3 (*(volatile unsigned *)(IOCTRL_STARTADDRESS+0x00C))
/** bit field of the lcd gate control in CLK gating register */
#define HR_CLK_LCD_GATE_Pos (10)
/***********************************************************//**
* LCD寄存器定义
***************************************************************/
#define HR_LCD_REG_BASE (HR_APB_BASE_ADDR + 0x1600) //(0x4001 1600)
#define HR_LCD_CR (HR_LCD_REG_BASE+0x000)
#define HR_LCD_FRAME_CNT (HR_LCD_REG_BASE+0x004)
#define HR_LCD_COM0_1_SEG (HR_LCD_REG_BASE+0x008)
#define HR_LCD_COM2_3_SEG (HR_LCD_REG_BASE+0x00C)
#define HR_LCD_COM4_5_SEG (HR_LCD_REG_BASE+0x010)
#define HR_LCD_COM6_7_SEG (HR_LCD_REG_BASE+0x014)
#define HR_LCD_IO_EN (HR_LCD_REG_BASE+0x018)
#define LCD_CR_EN_Pos (8)
#define LCD_CR_PD_Pos (9)
#define LCD_CR_MODE_Pos (11)
#define LCD_CR_MODE_MASK (1UL<<11)
#define LCD_CR_MODE_4x20 (1UL<<11)
#define LCD_CR_MODE_8X16 (0UL<<11)
#define LCD_EN (1UL<<8)
#define LCD_BIAS_MASK (3UL<<6)
#define LCD_BIAS_MASK_Pos (6)
#define LCD_BIAS_ONEFOURTH (0UL<<6)
#define LCD_BIAS_ONEHALF (1UL<<6)
#define LCD_BIAS_ONETHIRD (2UL<<6)
#define LCD_BIAS_STATIC (3UL<<6)
#define LCD_VLCD_MASK (7UL<<3)
#define LCD_VLCD_MASK_Pos (3)
#define LCD_VLCD_27 (0UL<<3)
#define LCD_VLCD_29 (1UL<<3)
#define LCD_VLCD_31 (2UL<<3)
#define LCD_VLCD_33 (3UL<<3)
#define LCD_DUTY_MASK (7UL<<0)
#define LCD_DUTY_MASK_Pos (0)
#define LCD_DUTY_STATIC (0UL<<0)
#define LCD_DUTY_ONEHALF (1UL<<0)
#define LCD_DUTY_ONETHIRD (2UL<<0)
#define LCD_DUTY_ONEFOURTH (3UL<<0)
#define LCD_DUTY_ONEFIFTH (4UL<<0)
#define LCD_DUTY_ONESIXTH (5UL<<0)
#define LCD_DUTY_ONESEVENTH (6UL<<0)
#define LCD_DUTY_ONEEIGHTH (7UL<<0)
/***********************************************************//**
* I2S寄存器定义
***************************************************************/
#define HR_CLK_I2S_GATE_Pos (10)
#define HR_I2S_REG_BASE (HR_APB_BASE_ADDR+0x1A00)
#define HR_I2S_CTRL (HR_I2S_REG_BASE+0x000)
#define HR_I2S_INT_MASK (HR_I2S_REG_BASE+0x004)
#define HR_I2S_INT_SRC (HR_I2S_REG_BASE+0x008)
#define HR_I2S_STATUS (HR_I2S_REG_BASE+0x00C)
#define HR_I2S_TX (HR_I2S_REG_BASE+0x010)
#define HR_I2S_RX (HR_I2S_REG_BASE+0x014)
/******************************************************************************/
/* */
/* PWM */
/* */
/******************************************************************************/
#define HR_PWM_REG_BASE (HR_APB_BASE_ADDR+0x1800)
#define HR_PWM_CLKDIV01 (HR_PWM_REG_BASE+0x0000)
#define HR_PWM_CLKDIV23 (HR_PWM_REG_BASE+0x0004)
#define HR_PWM_CTL (HR_PWM_REG_BASE+0x0008)
#define HR_PWM_PERIOD (HR_PWM_REG_BASE+0x000C)
#define HR_PWM_PNUM (HR_PWM_REG_BASE+0x0010)
#define HR_PWM_CMPDAT (HR_PWM_REG_BASE+0x0014)
#define HR_PWM_DTCTL (HR_PWM_REG_BASE+0x0018)
#define HR_PWM_INTEN (HR_PWM_REG_BASE+0x001C)
#define HR_PWM_INTSTS (HR_PWM_REG_BASE+0x0020)
#define HR_PWM_CAPDAT (HR_PWM_REG_BASE+0x0024)
#define HR_PWM_BRKCTL (HR_PWM_REG_BASE+0x0028)
#define HR_PWM_CH4_REG1 (HR_PWM_REG_BASE+0x002C)
#define HR_PWM_CH4_REG2 (HR_PWM_REG_BASE+0x0030)
#define HR_PWM_CAP2DAT (HR_PWM_REG_BASE+0x0034)
#define HR_PWM_CAP2CTL (HR_PWM_REG_BASE+0x0038)
/* EFUSE Register */
#define HR_EFUSE_REG_BASE (0x0f001600)
#define HR_EFUSE_WDATA_PORT (HR_EFUSE_REG_BASE+0x000)
#define HR_EFUSE_PGM_CMD (HR_EFUSE_REG_BASE+0x004)
#define HR_EFUSE_PGM_STTS (HR_EFUSE_REG_BASE+0x008)
#define HR_EFUSE_CLEAR (HR_EFUSE_REG_BASE+0x00C)
#define HR_EFUSE_VDDQ_SETUP (HR_EFUSE_REG_BASE+0x010)
/* PGM_CMD define */
#define EFUSE_PGM_START (1UL)
#define EFUSE1_SELECT (1UL << 1)
#define EFUSE2_SELECT (1UL << 2)
/* PGM STTS define */
#define EFUSE_PGM_DONE (1UL)
#define EFUSE_FIFO_FREE (1UL << 1)
/* CLEAR_EFUSE */
#define EFUSE_RESET (1UL)
/**
* @defgroup System_APIs System APIs
* @brief System APIs
*/
/**
* @addtogroup System_APIs
* @{
*/
/**
* @defgroup REG_APIs REG APIs
* @brief Register operate APIs
*/
/**
* @addtogroup REG_APIs
* @{
*/
/**
* @brief This function is used to write value to register or memory
*
* @param[in] reg address to be written
* @param[in] val value to write
*
* @return None
*
* @note None
*/
static __inline void tls_reg_write32(unsigned int reg, unsigned int val)
{
*(TLS_REG *)reg = val;
}
/**
* @brief This function is used to read value from register or memory
*
* @param[in] reg address to read
*
* @retval val read from register or memory
*
* @note None
*/
static __inline unsigned int tls_reg_read32(unsigned int reg)
{
unsigned int val = *(TLS_REG *)reg;
return val;
}
/**
* @brief This function is used to write specified bit through
bit-band alias region
*
* @param[in] addr 32-bit aligned byte address where the bit exists.
* @param[in] bit Bit position.
* @param[in] val The value that the bit is set to, 0 or 1.
*
* @return None
*
* @note Only when bit-band mechnism is supported, you can use it
*/
static __inline void tls_bitband_write(volatile unsigned int addr, unsigned int bit, unsigned int val)
{
unsigned int temp;
temp = (((unsigned int)(addr) & 0xF0000000) + 0x02000000) \
+((((unsigned int)(addr)&0xFFFFF)<<5)\
+( (unsigned int)(bit)<<2));
*((volatile unsigned int * )temp) = val;
}
/**
* @brief This function is used to read a single bit from address
by bit-band alias region
*
* @param[in] addr 32-bit aligned byte address where the bit exists
* @param[in] bit Bit position
*
* @retval The value of the requested bit
*
* @note Only when bit-band mechnism is supported, you can use it
*/
static __inline unsigned int tls_bitband_read(volatile unsigned int addr, unsigned int bit)
{
unsigned int temp;
temp = (((unsigned int)(addr) & 0xF0000000) + 0x02000000) \
+((((unsigned int)(addr)&0xFFFFF)<<5)\
+( (unsigned int)(bit)<<2));
return *((volatile unsigned int *)temp);
}
/**
* @}
*/
/**
* @}
*/
#endif /* WM_REGS_H */

View File

@@ -0,0 +1,163 @@
/**
* @file wm_type_def.h
*
* @brief WM type redefine
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_TYPE_DEF_H__
#define __WM_TYPE_DEF_H__
#ifdef bool
#undef bool
#endif
#ifdef u8
#undef u8
#endif
#ifdef s8
#undef s8
#endif
#ifdef u16
#undef u16
#endif
#ifdef s16
#undef s16
#endif
#ifdef u32
#undef u32
#endif
#ifdef s32
#undef s32
#endif
#ifdef u64
#undef u64
#endif
#ifdef s64
#undef s64
#endif
#ifdef u_char
#undef u_char
#endif
typedef unsigned char u_char;
#ifdef INT8U
#undef INT8U
#endif
typedef unsigned char INT8U;
#ifdef INT8S
#undef INT8S
#endif
typedef signed char INT8S;
typedef unsigned char bool;
typedef unsigned char u8;
typedef signed char s8;
typedef unsigned short u16;
typedef signed short s16;
typedef unsigned int u32;
typedef signed int s32;
typedef unsigned long long u64;
typedef long long s64;
#if (GCC_COMPILE==0)
#ifdef int32_t
#undef int32_t
#endif
typedef int int32_t;
#ifdef uint32_t
#undef uint32_t
#endif
typedef unsigned int uint32_t;
#endif
#ifdef ULONG
#undef ULONG
#endif
typedef unsigned long ULONG;
#ifdef u8_t
#undef u8_t
#endif
typedef unsigned char u8_t;
#ifdef uint8_t
#undef uint8_t
#endif
typedef unsigned char uint8_t;
#ifdef u16_t
#undef u16_t
#endif
typedef unsigned short u16_t;
#ifdef uint16_t
#undef uint16_t
#endif
typedef unsigned short uint16_t;
#ifdef u32_t
#undef u32_t
#endif
typedef unsigned int u32_t;
#ifdef s8_t
#undef s8_t
#endif
typedef signed char s8_t;
#ifdef s16_t
#undef s16_t
#endif
typedef signed short s16_t;
#ifdef s32_t
#undef s32_t
#endif
typedef signed int s32_t;
#if (GCC_COMPILE==0)
#ifdef size_t
#undef size_t
#endif
typedef unsigned int size_t;
#endif
#ifdef err_t
#undef err_t
#endif
typedef signed char err_t;
#ifdef mem_ptr_t
#undef mem_ptr_t
#endif
typedef unsigned int mem_ptr_t;
#ifdef TRUE
#undef TRUE
#endif
#define TRUE 1
#ifdef FALSE
#undef FALSE
#endif
#define FALSE 0
#define true 1
#define false 0
#define WM_SUCCESS 0
#define WM_FAILED -1
#ifndef IGNORE_PARAMETER
#define IGNORE_PARAMETER(x) ((x) = (x))
#endif
#endif

View File

@@ -0,0 +1,55 @@
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
TOP_DIR = ../../
sinclude $(TOP_DIR)/tools/tool_chain.def
#ifndef PDIR
#UP_EXTRACT_DIR = ..
#GEN_LIBS = libboot$(LIB_EXT)
#ifeq ($(COMPILE), gcc)
#COMPONENTS_libboot += gcc/libboot_gcc$(LIB_EXT)
#else
#COMPONENTS_libboot += armcc/libboot_armcc$(LIB_EXT)
#endif
#endif
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
sinclude $(TOP_DIR)/tools/rules.mk
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

View File

@@ -0,0 +1,48 @@
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifeq ($(COMPILE), gcc)
else
TOP_DIR = ../../../
sinclude $(TOP_DIR)/tools/tool_chain.def
ifndef PDIR
GEN_LIBS = libboot$(LIB_EXT)
endif
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
sinclude $(TOP_DIR)/tools/rules.mk
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
endif

View File

@@ -0,0 +1,227 @@
/**
******************************************************************************
* @file misc.c
* @author MCD Application Team
* @version V3.6.1
* @date 05-March-2012
* @brief This file provides all the miscellaneous firmware functions (add-on
* to CMSIS functions).
*/
#if (GCC_COMPILE!=1)
/* Includes ------------------------------------------------------------------*/
#include "misc.h"
/** @addtogroup W600_Driver
* @{
*/
/** @defgroup MISC
* @brief MISC driver modules
* @{
*/
/** @defgroup MISC_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup MISC_Private_Defines
* @{
*/
#define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
/**
* @}
*/
/** @defgroup MISC_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup MISC_Private_Variables
* @{
*/
/**
* @}
*/
/** @defgroup MISC_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup MISC_Private_Functions
* @{
*/
/**
* @brief Configures the priority grouping: pre-emption priority and subpriority.
* @param NVIC_PriorityGroup: specifies the priority grouping bits length.
* This parameter can be one of the following values:
* @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
* 4 bits for subpriority
* @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
* 3 bits for subpriority
* @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
* 2 bits for subpriority
* @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
* 1 bits for subpriority
* @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
* 0 bits for subpriority
* @retval None
*/
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
{
/* Check the parameters */
// assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
/* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
}
/**
* @brief Initializes the NVIC peripheral according to the specified
* parameters in the NVIC_InitStruct.
* @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
* the configuration information for the specified NVIC peripheral.
* @retval None
*/
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
{
uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
/* Check the parameters */
// assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
// assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
// assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
{
/* Compute the Corresponding IRQ Priority --------------------------------*/
tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
tmppre = (0x4 - tmppriority);
tmpsub = tmpsub >> tmppriority;
tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
tmppriority = tmppriority << 0x04;
NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
/* Enable the Selected IRQ Channels --------------------------------------*/
NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
(uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
}
else
{
/* Disable the Selected IRQ Channels -------------------------------------*/
NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
(uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
}
}
void NVIC_Configration(int irqno, FunctionalState irqstatus)
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = irqno;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = irqstatus;
NVIC_Init(&NVIC_InitStruct);
}
/**
* @brief Sets the vector table location and Offset.
* @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
* This parameter can be one of the following values:
* @arg NVIC_VectTab_RAM
* @arg NVIC_VectTab_FLASH
* @param Offset: Vector Table base offset field. This value must be a multiple
* of 0x200.
* @retval None
*/
void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
{
/* Check the parameters */
// assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
// assert_param(IS_NVIC_OFFSET(Offset));
SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
}
/**
* @brief Selects the condition for the system to enter low power mode.
* @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
* This parameter can be one of the following values:
* @arg NVIC_LP_SEVONPEND
* @arg NVIC_LP_SLEEPDEEP
* @arg NVIC_LP_SLEEPONEXIT
* @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
{
/* Check the parameters */
// assert_param(IS_NVIC_LP(LowPowerMode));
// assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
SCB->SCR |= LowPowerMode;
}
else
{
SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
}
}
/**
* @brief Configures the SysTick clock source.
* @param SysTick_CLKSource: specifies the SysTick clock source.
* This parameter can be one of the following values:
* @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
* @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
* @retval None
*/
void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
{
/* Check the parameters */
// assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
{
SysTick->CTRL |= SysTick_CLKSource_HCLK;
}
else
{
SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. *****END OF FILE****/
#endif

View File

@@ -0,0 +1,471 @@
/******************************************************************************/
/* RETARGET.C: 'Retarget' layer for target-dependent low level functions */
/******************************************************************************/
#include <stdio.h>
#include <rt_misc.h>
#include "wm_config.h"
#include "wm_regs.h"
#include <string.h>
#include <stdarg.h>
#if (GCC_COMPILE!=1)
//#pragma import(__use_no_semihosting_swi)
static unsigned int std_libspace[__USER_LIBSPACE_SIZE];
void *__user_libspace(void)
{
return (void *)&std_libspace;
}
extern int sendchar(int ch);
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f)
{
return (sendchar(ch));
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
#if TLS_CONFIG_IOUART
int sendchar(int ch)
{
if(ch == '\n')
iouart_tx_byte('\r');
iouart_tx_byte((char)ch);
}
#else
//function: 将数据转换成字符串
//paramter:
//str : 转换之后存在此buffer
//num : 要转换的数据
//base : 十进制,十六进制
//width : 对齐宽度
//opflag : 操作符bit定义如下
#define P_ALIGN_BIT (0x01<<0) // bit=1 左对齐 bit=0右对齐
#define P_FILL_BIT (0x01<<1) //bit = 1填充'0',否则填充' '
#define P_BIG_BIT (0x01<<2) //bit=1大写否则小写
int Int2Str(char *str,int num,char base,char width,int opflag)
{
char temp;
int len = 0;
signed char k = 0;
char *str_bk;
signed char k_bk;
if(num <0)
{
num = -num;
*str='-';
str++;
len++;
}
if(0 == num)
{
*str = '0';
str ++;
k ++;
}
while(num)
{
temp= num%base;
if(temp > 9) // insert hexdecimal--ABCDEF--
{
temp-=10;
if(opflag & P_BIG_BIT)
*str = temp + 'A';
else
*str = temp + 'a';
}
else
{
*str = temp + '0';
}
num=num/base;
str++;
k++;
}
if(opflag&P_ALIGN_BIT) //左对齐
{
str_bk = str;
k_bk = k; //先备份指针和长度,倒序之后继续
str --;
k --;
while(k>0)
{
temp = *str;
*str = *(str-k);
*(str-k) = temp;
str--;
k-=2;
}
k = k_bk;
str = str_bk;
}
//不足宽度的用' '补齐
while(width>k)
{
if(opflag&P_FILL_BIT)
{
*str++ ='0';
}
else
{
*str++ =' ';
}
k++;
}
len=len+k;
*str-- = '\0';
k--;
if(0 == (opflag&P_ALIGN_BIT)) //右对齐
{
//倒序
while(k>0)
{
temp = *str;
*str = *(str-k);
*(str-k) = temp;
str--;
k-=2;
}
}
return len;
}
static int IP2Str(unsigned char v4v6, unsigned int *inuint, char *outtxt)
{
unsigned char i;
unsigned char j = 0;
unsigned char k;
unsigned char h;
unsigned char m;
unsigned char l;
unsigned char bit;
if (4 == v4v6)
{
for(i = 0; i < 4; i++)
{
bit = (*inuint >> (8 * i)) & 0xff;
h = bit / 100;
if (h)
outtxt[j++] = '0' + h;
m = (bit % 100) / 10;
if (m)
{
outtxt[j++] = '0' + m;
}
else
{
if (h)
outtxt[j++] = '0';
}
l = (bit % 100) % 10;
outtxt[j++] = '0' + l;
outtxt[j++] = '.';
}
}
else
{
for (k = 0; k < 4; k++)
{
for(i = 0; i < 4; i++)
{
m = (*inuint >> (8 * i)) & 0xff;
h = m >> 4;
l = m & 0xf;
if (h > 9)
outtxt[j++] = 'A' + h - 10;
else
outtxt[j++]= '0' + h;
if (l > 9)
outtxt[j++] = 'A' + l - 10;
else
outtxt[j++] = '0' + l;
if (0 != (i % 2))
outtxt[j++] = ':';
}
inuint++;
}
}
outtxt[j - 1] = 0;
return j - 1;
}
static int Mac2Str(unsigned char *inchar, char *outtxt)
{
unsigned char hbit,lbit;
unsigned int i;
for(i = 0; i < 6; i++)/* mac length */
{
hbit = (*(inchar + i) & 0xf0) >> 4;
lbit = *(inchar + i ) & 0x0f;
if (hbit > 9)
outtxt[3 * i] = 'A' + hbit - 10;
else
outtxt[3 * i]= '0' + hbit;
if (lbit > 9)
outtxt[3 * i + 1] = 'A' + lbit - 10;
else
outtxt[3 * i + 1] = '0' + lbit;
outtxt[3 * i + 2] = '-';
}
outtxt[3 * (i - 1) + 2] = 0;
return 3 * (i - 1) + 2;
}
int wm_vprintf(const char *fmt, va_list arg_ptr)
{
unsigned char width=0; //保留宽度
unsigned int len; //数据宽度
char *fp = (char *)fmt;
//va_list arg_ptr;
char *pval;
int opflag = 0;
char store[40];
char c;
int i;
char* str;
//va_start(arg_ptr, fmt); //arg_ptr 指向第一个参数
while (*fp !='\0')
{
c = *fp++;
if (c != '%')
{
sendchar(c);
}
else
{
width = 0; //获取数据宽度
opflag = 0;
if('-' == *fp)
{
opflag |= P_ALIGN_BIT;//左对齐
fp ++;
}
if('0' == *fp) //前面补零
{
opflag |= P_FILL_BIT; //补零
fp ++;
}
while(*fp>='0'&&*fp<='9')
{
width = width * 10 + (*fp) - '0';
fp++;
}
if('.' == *fp) //浮点运算暂时没用,不处理
{
fp ++;
while(*fp>='0'&&*fp<='9')
{
fp++;
}
}
while('l' == *fp || 'h' == *fp)
{
fp ++;
}
switch (*fp)
{
case 'c':
case 'C':
c = (char)va_arg(arg_ptr, int);
sendchar(c);
break;
case 'd':
case 'i':
case 'u':
i = va_arg(arg_ptr, int);
str = store;
Int2Str(store,i,10,width,opflag);
while( *str != '\0') sendchar(*str++);
break;
case 'x':
case 'X':
i = va_arg(arg_ptr, int);
str = store;
if('X' == *fp)
{
opflag |= P_BIG_BIT;
}
Int2Str(store,i,16,width,opflag);
while( *str != '\0') sendchar(*str++);
break;
case 'o':
i = va_arg(arg_ptr, int);
str = store;
Int2Str(store,i,8,width,opflag);
while( *str != '\0') sendchar(*str++);
break;
case 's':
case 'S':
pval=va_arg(arg_ptr,char*);
len = strlen(pval);
if((width > len) && (0 == (opflag&P_ALIGN_BIT))) //右对齐
{
for(i = 0;i < (width - len);i ++) //左边补空格
{
sendchar(' ');
}
}
for(i=0;i < len;i++)
{
sendchar(pval[i]);
}
if((width > len) && (opflag&P_ALIGN_BIT)) //左对齐
{
for(i = 0;i < (width - len);i ++) //右边补空格
{
sendchar(' ');
}
}
break;
case 'v':/* ip v4 address */
i = va_arg(arg_ptr, int);
len = IP2Str(4, (unsigned int *)&i, store);
if((width > len) && (0 == (opflag&P_ALIGN_BIT))) //右对齐
{
for(i = 0;i < (width - len);i ++) //左边补空格
{
sendchar(' ');
}
}
str = store;
while( *str != '\0') sendchar(*str++);
if((width > len) && (opflag&P_ALIGN_BIT)) //左对齐
{
for(i = 0;i < (width - len);i ++) //右边补空格
{
sendchar(' ');
}
}
break;
case 'V':/* ip v6 address */
pval=va_arg(arg_ptr,char*);
len = IP2Str(6, (unsigned int *)pval, store);
if((width > len) && (0 == (opflag&P_ALIGN_BIT))) //右对齐
{
for(i = 0;i < (width - len);i ++) //左边补空格
{
sendchar(' ');
}
}
str = store;
while( *str != '\0') sendchar(*str++);
if((width > len) && (opflag&P_ALIGN_BIT)) //左对齐
{
for(i = 0;i < (width - len);i ++) //右边补空格
{
sendchar(' ');
}
}
break;
case 'M':/* mac address */
pval = va_arg(arg_ptr, char*);
len = Mac2Str((unsigned char *)pval, store);
if((width > len) && (0 == (opflag&P_ALIGN_BIT))) //右对齐
{
for(i = 0;i < (width - len);i ++) //左边补空格
{
sendchar(' ');
}
}
str = store;
while( *str != '\0') sendchar(*str++);
if((width > len) && (opflag&P_ALIGN_BIT)) //左对齐
{
for(i = 0;i < (width - len);i ++) //右边补空格
{
sendchar(' ');
}
}
break;
case '%':
sendchar('%');
break;
default:
break;
}
fp++;
}
}
//va_end(arg_ptr);
return 0;
}
int wm_printf(const char *fmt,...)
{
va_list ap;
va_start(ap, fmt);
wm_vprintf(fmt,ap);
va_end(ap);
return 0;
}
int sendchar(int ch)
{
#if WM_CONFIG_DEBUG_UART1
tls_reg_write32(HR_UART1_INT_MASK, 0x3);
if(ch == '\n')
{
while (tls_reg_read32(HR_UART1_FIFO_STATUS)&0x3F);
tls_reg_write32(HR_UART1_TX_WIN, '\r');
}
while(tls_reg_read32(HR_UART1_FIFO_STATUS)&0x3F);
tls_reg_write32(HR_UART1_TX_WIN, (char)ch);
tls_reg_write32(HR_UART1_INT_MASK, 0x0);
#else
tls_reg_write32(HR_UART0_INT_MASK, 0x3);
// if(ch == '\n')
// {
// while (tls_reg_read32(HR_UART0_FIFO_STATUS)&0x3F);
// tls_reg_write32(HR_UART0_TX_WIN, '\r');
// }
while(tls_reg_read32(HR_UART0_FIFO_STATUS)&0x3F);
tls_reg_write32(HR_UART0_TX_WIN, (char)ch);
tls_reg_write32(HR_UART0_INT_MASK, 0x0);
#endif
return ch;
}
#endif
void _ttywrch(int ch)
{
sendchar(ch);
}
void _sys_exit(int return_code)
{
label:
goto label; /* endless loop */
}
#endif

View File

@@ -0,0 +1,310 @@
;******************** Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd. ********************
;* File Name : startup_venus.s
;* Author :
;* Version :
;* Date :
;* Description :
; <h> Stack Configuration
; <o> Stack Size (in Bytes)
; </h>
Stack_Size EQU 0x00000400
AREA |.bss|, BSS, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes):at least 80Kbyte
; </h>
Heap_Size EQU 0
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
IMPORT PendSV_Handler
IMPORT OS_CPU_SysTickHandler
; IMPORT UART0_IRQHandler
; IMPORT UART1_IRQHandler
; IMPORT tls_wl_rx_isr
; IMPORT tls_wl_mgmt_tx_isr
; IMPORT tls_wl_data_tx_isr
; IMPORT tls_wl_mac_isr
IMPORT TIM0_IRQHandler
IMPORT TIM1_IRQHandler
IMPORT TIM2_IRQHandler
IMPORT TIM3_IRQHandler
IMPORT TIM4_IRQHandler
IMPORT TIM5_IRQHandler
; IMPORT WDG_IRQHandler
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD OS_CPU_SysTickHandler ; SysTick Handler
; External Interrupts
DCD SDIO_RX_IRQHandler ; Window Watchdog
DCD SDIO_TX_IRQHandler ; PVD through EXTI Line detect
DCD SDIO_RX_CMD_IRQHandler ; Tamper
DCD SDIO_TX_CMD_IRQHandler ; RTC
DCD tls_wl_mac_isr ; Flash
DCD 0 ; rf_cfg
DCD tls_wl_rx_isr ; EXTI Line 0
DCD tls_wl_mgmt_tx_isr ; EXTI Line 1
DCD tls_wl_data_tx_isr ; EXTI Line 2
DCD PMU_TIMER1_IRQHandler ; pmu_timer1
DCD PMU_TIMER0_IRQHandler ; pmu_timer0
DCD PMU_GPIO_WAKE_IRQHandler ; gpio
DCD PMU_SDIO_WAKE_IRQHandler ; sdio
DCD DMA_Channel0_IRQHandler ; DMA1 Channel 3
DCD DMA_Channel1_IRQHandler ; DMA1 Channel 4
DCD DMA_Channel2_IRQHandler ; DMA1 Channel 5
DCD DMA_Channel3_IRQHandler ; DMA1 Channel 6
DCD DMA_Channel4_7_IRQHandler ; DMA1 Channel 7
DCD DMA_BRUST_IRQHandler ; ADC1 & ADC2
DCD I2C_IRQHandler ; USB High Priority or CAN1 TX
DCD ADC_IRQHandler ; USB Low Priority or CAN1 RX0
DCD SPI_LS_IRQHandler ; CAN1 RX1
DCD SPI_HS_IRQHandler ; CAN1 SCE
DCD UART0_IRQHandler ; EXTI Line 9..5
DCD UART1_IRQHandler ; TIM1 Break
DCD WM_GPIOA_IRQHandler ; TIM1 Update
DCD TIM0_IRQHandler ; TIM1 Trigger and Commutation
DCD TIM1_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD TIM5_IRQHandler ; I2C1 Event
DCD WDG_IRQHandler ; watch dog handle
DCD PMU_IRQHandler ; I2C2 Event
DCD FLASH_IRQHandler ; I2C2 Error
DCD PWM_IRQHandler ; SPI1
DCD I2S_IRQHandler ; SPI2
DCD PMU_RTC_IRQHandler
DCD RSA_IRQHandler
DCD CRYPTION_IRQHandler ;CRYPTION
DCD WM_GPIOB_IRQHandler ; GBIOB
DCD UART2_IRQHandler ; USART1
DCD 0 ;
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
;PendSV_Handler PROC
; EXPORT PendSV_Handler [WEAK]
; B .
; ENDP
;SysTick_Handler PROC
; EXPORT SysTick_Handler [WEAK]
; B .
; ENDP
tls_wl_mac_isr\
PROC
EXPORT tls_wl_mac_isr [WEAK]
B .
ENDP
tls_wl_rx_isr\
PROC
EXPORT tls_wl_rx_isr [WEAK]
B .
ENDP
tls_wl_mgmt_tx_isr\
PROC
EXPORT tls_wl_mgmt_tx_isr [WEAK]
B .
ENDP
tls_wl_data_tx_isr\
PROC
EXPORT tls_wl_data_tx_isr [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT SDIO_RX_IRQHandler [WEAK]
EXPORT SDIO_TX_IRQHandler [WEAK]
EXPORT SDIO_RX_CMD_IRQHandler [WEAK]
EXPORT SDIO_TX_CMD_IRQHandler [WEAK]
EXPORT RSV_IRQHandler [WEAK]
EXPORT PMU_RTC_IRQHandler [WEAK]
EXPORT PMU_TIMER1_IRQHandler [WEAK]; pmu_timer1
EXPORT PMU_TIMER0_IRQHandler [WEAK]; pmu_timer0
EXPORT PMU_GPIO_WAKE_IRQHandler [WEAK]; gpio
EXPORT PMU_SDIO_WAKE_IRQHandler [WEAK]
EXPORT DMA_Channel0_IRQHandler [WEAK]
EXPORT DMA_Channel1_IRQHandler [WEAK]
EXPORT DMA_Channel2_IRQHandler [WEAK]
EXPORT DMA_Channel3_IRQHandler [WEAK]
EXPORT DMA_Channel4_7_IRQHandler [WEAK]
EXPORT DMA_BRUST_IRQHandler [WEAK]
EXPORT I2C_IRQHandler [WEAK]
EXPORT ADC_IRQHandler [WEAK]
EXPORT SPI_LS_IRQHandler [WEAK]
EXPORT SPI_HS_IRQHandler [WEAK]
EXPORT UART0_IRQHandler [WEAK]
EXPORT UART1_IRQHandler [WEAK]
EXPORT WM_GPIOA_IRQHandler [WEAK]
; EXPORT TIM0_IRQHandler [WEAK]
; EXPORT TIM1_IRQHandler [WEAK]
; EXPORT TIM2_IRQHandler [WEAK]
; EXPORT TIM3_IRQHandler [WEAK]
; EXPORT TIM4_IRQHandler [WEAK]
; EXPORT TIM5_IRQHandler [WEAK]
EXPORT WDG_IRQHandler [WEAK]
EXPORT PMU_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT PWM_IRQHandler [WEAK]
EXPORT I2S_IRQHandler [WEAK]
EXPORT PMU_6IRQHandler [WEAK]
EXPORT RSA_IRQHandler [WEAK]
EXPORT CRYPTION_IRQHandler [WEAK]
EXPORT WM_GPIOB_IRQHandler [WEAK]
EXPORT UART2_IRQHandler [WEAK]
SDIO_RX_IRQHandler
SDIO_TX_IRQHandler
SDIO_RX_CMD_IRQHandler
SDIO_TX_CMD_IRQHandler
;MAC_IRQHandler
RSV_IRQHandler
;SEC_RX_IRQHandler
;SEC_TX_MNGT_IRQHandler
;SEC_TX_DAT_IRQHandler
PMU_RTC_IRQHandler
PMU_TIMER1_IRQHandler
PMU_TIMER0_IRQHandler
PMU_GPIO_WAKE_IRQHandler
PMU_SDIO_WAKE_IRQHandler
DMA_Channel0_IRQHandler
DMA_Channel1_IRQHandler
DMA_Channel2_IRQHandler
DMA_Channel3_IRQHandler
DMA_Channel4_7_IRQHandler
DMA_BRUST_IRQHandler
I2C_IRQHandler
ADC_IRQHandler
SPI_LS_IRQHandler
SPI_HS_IRQHandler
UART0_IRQHandler
UART1_IRQHandler
WM_GPIOA_IRQHandler
;TIM0_IRQHandler
;TIM1_IRQHandler
;TIM2_IRQHandler
;TIM3_IRQHandler
;TIM4_IRQHandler
;TIM5_IRQHandler
WDG_IRQHandler
PMU_IRQHandler
FLASH_IRQHandler
PWM_IRQHandler
I2S_IRQHandler
PMU_6IRQHandler
RSA_IRQHandler
CRYPTION_IRQHandler
WM_GPIOB_IRQHandler
UART2_IRQHandler
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
;******************* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd. *****END OF FILE*****

View File

@@ -0,0 +1,261 @@
/**
* @file VS10XX.c
*
* @brief VS10XX driver
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#include <string.h>
#include "VS10XX.h"
#include "wm_hostspi.h"
#include "wm_gpio.h"
#include "wm_config.h"
#if CODEC_VS1053
extern void delay_us(unsigned int time);
extern int gSpiCsFlag;
void codec_data_cs_low(void)
{
while (0 == tls_gpio_read(SPI_CS_PIN))
{
// printf("\nflash is busy,codec data cs wait...\n");
tls_os_time_delay(1);
}
gSpiCsFlag = 1;
tls_gpio_cfg(VS_XDCS, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_write(VS_XDCS, 0);
}
void codec_data_cs_high(void)
{
tls_gpio_cfg(VS_XDCS, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_write(VS_XDCS, 1);
gSpiCsFlag = 0;
}
void codec_cmd_cs_low(void)
{
while (0 == tls_gpio_read(SPI_CS_PIN))
{
// printf("\nflash is busy,codec cmd cs wait...\n");
tls_os_time_delay(1);
}
gSpiCsFlag = 1;
tls_gpio_cfg(VS_XCS, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_write(VS_XCS, 0);
}
void codec_cmd_cs_high(void)
{
tls_gpio_cfg(VS_XCS, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_write(VS_XCS, 1);
gSpiCsFlag = 0;
}
int VS_Wait_Timeout(void)
{
u16 retry = 0;
while ((tls_gpio_read(VS_DQ) == 0) && (retry < 0xFFFE))
{
retry++;
// delay_us(50);
}
if (retry >= 0xFFFE)
{
printf("VS1053 wait timeout\r\n");
return 1;
}
return 0;
}
const u16 wav_plugin[40] = /* Compressed plugin */
{
0x0007, 0x0001, 0x8010, 0x0006, 0x001c, 0x3e12, 0xb817, 0x3e14, /* 0 */
0xf812, 0x3e01, 0xb811, 0x0007, 0x9717, 0x0020, 0xffd2, 0x0030, /* 8 */
0x11d1, 0x3111, 0x8024, 0x3704, 0xc024, 0x3b81, 0x8024, 0x3101, /* 10 */
0x8024, 0x3b81, 0x8024, 0x3f04, 0xc024, 0x2808, 0x4800, 0x36f1, /* 18 */
0x9811, 0x0007, 0x0001, 0x8028, 0x0006, 0x0002, 0x2a00, 0x040e,
};
//vs10xx装载patch.
//patchpatch首地址
//lenpatch长度
void VS_Load_Patch(u16 * patch, u16 len)
{
u16 i;
u16 addr, n, val;
for (i = 0; i < len;)
{
addr = patch[i++];
n = patch[i++];
if (n & 0x8000U) // RLE run, replicate n samples
{
n &= 0x7FFF;
val = patch[i++];
while (n--)
{
VS_WR_Cmd(addr, val);
}
}
else // copy run, copy n sample
{
while (n--)
{
val = patch[i++];
VS_WR_Cmd(addr, val);
}
}
}
}
//硬复位MP3
u8 VS_HD_Reset(void)
{
tls_gpio_write(VS_XDCS, 1); // 取消数据传输
tls_gpio_write(VS_XCS, 1);
tls_gpio_write(VS_RST, 0);
tls_os_time_delay(10);
tls_gpio_write(VS_RST, 1);
return VS_Wait_Timeout();
}
//软复位VS10XX
void VS_Soft_Reset(void)
{
tls_spi_setup(TLS_SPI_MODE_0, TLS_SPI_CS_LOW, VS_SPI_CLK_LOW);
VS_WR_Cmd(SPI_MODE, 0x0816);
VS_WR_Cmd(SPI_CLOCKF, 0x9800);
VS_WR_Cmd(SPI_DECODE_TIME, 0x0000);
VS_WR_Cmd(SPI_DECODE_TIME, 0x0000);
}
//向VS10XX写命令
//address:命令地址
//data:命令数据
void VS_WR_Cmd(u8 address, u16 data)
{
u8 temp[5];
if (VS_Wait_Timeout())
{
return;
}
codec_cmd_cs_low();
temp[0] = VS_WRITE_COMMAND;
temp[1] = address;
temp[2] = data >> 8;
temp[3] = data & 0xff;
tls_spi_write(temp, 4);
codec_cmd_cs_high();
}
//读VS10XX的寄存器
//注意不要用倍速读取,会出错
u16 VS_RD_Reg(u8 address)
{
u8 txbuf[2];
u8 rxbuf[2];
if (VS_Wait_Timeout())
{
return;
}
codec_cmd_cs_low();
txbuf[0] = VS_READ_COMMAND;
txbuf[1] = address;
tls_spi_read_with_cmd(txbuf, 2, rxbuf, 2);
codec_cmd_cs_high();
return ((rxbuf[0] << 8) | rxbuf[1]);
}
//得到mp3的播放时间n sec
u16 VS_Get_DecodeTime(void)
{
tls_spi_setup(TLS_SPI_MODE_0, TLS_SPI_CS_LOW, VS_SPI_CLK_LOW);
return VS_RD_Reg(SPI_DECODE_TIME);
}
void vs_set_vol(int vol)
{
int tmp;
u16 volt = 0;
tmp = vol;
if (vol >= 0 && vol <= 100)
{
volt = tmp << 8;
volt += tmp;
printf("\nvolt==%x\n", volt);
tls_spi_setup(TLS_SPI_MODE_0, TLS_SPI_CS_LOW, VS_SPI_CLK_LOW);
VS_WR_Cmd(SPI_VOL, volt); // 设音量
}
}
void vs_mute(void)
{
tls_spi_setup(TLS_SPI_MODE_0, TLS_SPI_CS_LOW, VS_SPI_CLK_LOW);
VS_WR_Cmd(SPI_VOL, 0xfefe); // 设音量
}
//激活PCM 录音模式
//agc:0,自动增益.1024相当于1倍,512相当于0.5倍,最大值65535=64倍
void VS_Rec_Mode(u16 agc)
{
tls_spi_setup(TLS_SPI_MODE_0, TLS_SPI_CS_LOW, VS_SPI_CLK_LOW);
VS_WR_Cmd(SPI_BASS, 0x0000);
VS_WR_Cmd(SPI_AICTRL0, 8000); // 设置采样率,设置为8Khz
VS_WR_Cmd(SPI_AICTRL1, agc); // 设置增益,0,自动增益.1024相当于1倍,512相当于0.5倍,最大值65535=64倍
//
VS_WR_Cmd(SPI_AICTRL2, 0); // 设置增益最大值,0,代表最大值65536=64X
VS_WR_Cmd(SPI_AICTRL3, 6); // 左通道(MIC单声道输入)
VS_WR_Cmd(SPI_CLOCKF, 0X2000); // 设置VS10XX的时钟,MULT:2倍频;ADD:不允许;CLK:12.288Mhz
VS_WR_Cmd(SPI_MODE, 0x1804); // MIC,录音激活
tls_os_time_delay(1); // 等待至少1.35ms
VS_Load_Patch((u16 *) wav_plugin, 40); // VS1053的WAV录音需要patch
}
int VS_Rec_GetData(char *recbuf)
{
int datalen, idx;
u16 data;
tls_spi_setup(TLS_SPI_MODE_0, TLS_SPI_CS_LOW, VS_SPI_CLK_HIGH);
datalen = VS_RD_Reg(SPI_HDAT1);
if ((datalen >= VS_REC_PKG_SIZE) && (datalen < 896))
{
idx = 0;
while (idx < VS_REC_PKG_SIZE)
{
data = VS_RD_Reg(SPI_HDAT0);
recbuf[idx++] = data & 0XFF;
recbuf[idx++] = data >> 8;
}
return 1;
}
else if (datalen >= 896)
{
printf("#%d\r\n", datalen);
}
return 0;
}
//初始化VS10XX的IO口
void VS_Init(void)
{
tls_gpio_cfg(VS_RST, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_write(VS_RST, 1);
tls_gpio_cfg(VS_XCS, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_write(VS_XCS, 1);
tls_gpio_cfg(VS_XDCS, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_write(VS_XDCS, 1);
tls_gpio_cfg(VS_DQ, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLHIGH);
}
#endif

View File

@@ -0,0 +1,291 @@
/**************************************************************************//**
* @file wm_i2s.c
* @author
* @version
* @date
* @brief
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
*****************************************************************************/
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include "wm_regs.h"
#include "wm_7816.h"
#include "wm_gpio.h"
#include "wm_uart.h"
#include "wm_cpu.h"
#include "wm_osal.h"
#define DEBUG_7816 1
#if DEBUG_7816
#define PRINT_DEBUG(fmt, args...) do{(printf("[DEBUG] "), printf(fmt, ##args));}while(0)
#else
#define PRINT_DEBUG(fmt, args...)
#endif
#define SYS_CLK (40000000)
sc_io_map sc_io;
/**
* @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)
{
if (sc_io.initialed == 0)
{
printf("error : 7816 io map must init....\r\n");
return ;
}
if (mode) //gpio mode
{
tls_io_cfg_set(sc_io.clk_pin_num, WM_IO_OPTION5);
tls_io_cfg_set(sc_io.io_pin_num, WM_IO_OPTION5);
tls_gpio_cfg(sc_io.clk_pin_num, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
tls_gpio_cfg(sc_io.io_pin_num, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
}
else //7816 mode
{
tls_io_cfg_set(sc_io.clk_pin_num, sc_io.clk_opt);
tls_io_cfg_set(sc_io.io_pin_num, sc_io.io_opt);
}
}
/**
* @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)
{
uint32_t reg;
bgt = (bgt > 0x1f) ? 0x1F : bgt;
reg = tls_reg_read32(HR_UART2_LINE_CTRL);
reg &= ~(0x1f << 11);
reg |= (bgt << 11);
tls_reg_write32(HR_UART2_LINE_CTRL, reg);
}
/**
* @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)
{
uint32_t reg;
reg = tls_reg_read32(HR_UART2_LINE_CTRL);
reg &= ~(0x7 << 16);
tls_reg_write32(HR_UART2_LINE_CTRL, reg|(count<<16));
tls_bitband_write(HR_UART2_LINE_CTRL, 23, 1);
}
/**
* @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)
{
uint32_t reg;
reg = tls_reg_read32(HR_UART2_LINE_CTRL);
reg &= ~(0x7 << 20);
tls_reg_write32(HR_UART2_LINE_CTRL, reg|(count<<20));
tls_bitband_write(HR_UART2_LINE_CTRL, 19, 1);
}
/**
* @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)
{
uint32_t reg;
reg = tls_reg_read32(HR_UART2_BAUD_RATE_CTRL);
reg &= ~ 0xFFFF;
reg |= etu;
tls_reg_write32(HR_UART2_BAUD_RATE_CTRL, reg);
}
/**
* @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)
{
uint32_t reg;
uint8_t div;
tls_sys_clk clk;
tls_sys_clk_get(&clk);
div = (clk.apbclk * 1000000 + freq)/(2 * freq) - 1;
reg = tls_reg_read32(HR_UART2_BAUD_RATE_CTRL);
reg &= ~ 0x3F0000;
reg |= (div<<16);
tls_reg_write32(HR_UART2_BAUD_RATE_CTRL, reg);
}
/**
* @brief
* close af to use PB29 and PB30(uart2_rx as default if af is on) as gpio
* @retval
*/
void wm_sc_powerInit(void)
{
#ifdef WM_SC_PWR_PIN
u32 regValue;
// PB29 AF close, used as GPIO
regValue = tls_reg_read32(HR_GPIOB_AFSEL);
regValue &= ~0x20000000;
tls_reg_write32(HR_GPIOB_AFSEL, regValue);
// PB30 AF close, used as GPIO
regValue = tls_reg_read32(HR_GPIOB_AFSEL);
regValue &= ~0x40000000;
tls_reg_write32(HR_GPIOB_AFSEL, regValue);
#endif
}
/**
* @brief
* power on the 7816 device if power is controled by GPIO
* @retval
*/
void wm_sc_poweron(void)
{
#ifdef WM_SC_PWR_PIN
tls_gpio_cfg(WM_SC_PWR_PIN, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
tls_gpio_write(WM_SC_PWR_PIN, 1);
#endif
}
/**
* @brief
* power off the 7816 device if power is controled by GPIO
* @retval
*/
void wm_sc_poweroff(void)
{
#ifdef WM_SC_PWR_PIN
tls_gpio_cfg(WM_SC_PWR_PIN, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
tls_gpio_write(WM_SC_PWR_PIN, 0);
#endif
}
/**
* @brief
* driver the reset gpio in low level
* @retval
*/
void wm_sc_rst_low(void)
{
#ifdef WM_SC_RST_PIN
tls_gpio_cfg(WM_SC_RST_PIN, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
tls_gpio_write(WM_SC_RST_PIN, 0);
#endif
}
/**
* @brief
* driver the reset gpio in high level
* @retval
*/
void wm_sc_rst_high(void)
{
#ifdef WM_SC_RST_PIN
tls_gpio_cfg(WM_SC_RST_PIN, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
tls_gpio_write(WM_SC_RST_PIN, 1);
#endif
}
/**
* @brief
* hotrest the 7816 device obey the 7816-3 timing
* @retval
*/
void wm_sc_hotreset(void)
{
uint32_t delay = 0xffff;
/* set the rst pin to low */
wm_sc_rst_low();
/* delay */
while(delay--);
/* set f/d to default 372 */
wm_sc_set_etu(WM_SC_DEFAULT_FD);
/* set the rst pin to high */
wm_sc_rst_high();
}
/**
* @brief
* colreset the 7816 device obey the 7816-3 timing
* @retval
*/
void wm_sc_colreset(void)
{
/* power down */
wm_sc_poweroff();
/* select the clk io in gpio mode */
wm_sc_io_clk_config(1);
/* reset the clk pin */
tls_gpio_write(sc_io.clk_pin_num, 0);
/* reset the io pin */
tls_gpio_write(sc_io.io_pin_num, 0);
/* set the ret pin to low */
wm_sc_rst_low();
/* power on the card */
wm_sc_poweron();
/* config the model in 7816 mode */
wm_sc_7816_mode(1);
/* select the clk io pin in 7816 mode */
wm_sc_io_clk_config(0);
/* config the output clock freq*/
wm_sc_set_frequency(5000000);
/* set the F/D to default (372)*/
wm_sc_set_etu(WM_SC_DEFAULT_FD);
/* set the rst pin to high */
wm_sc_rst_high();
}
/**
* @brief
* deactive the 7816 device obey the 7816-3 timing
* @retval
*/
void wm_sc_deactive(void)
{
/* set the rst pin in low level*/
wm_sc_rst_low();
/* select the clk and io pin to 7816 mode */
wm_sc_io_clk_config(0);
/* disable the output clock */
wm_sc_clk_enable(0);
/* select the clk and io pin to gpio mode */
wm_sc_io_clk_config(1);
/* set the clk pin to low */
tls_gpio_write(sc_io.clk_pin_num, 0);
/* set the io pin to low */
tls_gpio_write(sc_io.io_pin_num, 0);
/* set the power pin to low */
wm_sc_poweroff();
}

View File

@@ -0,0 +1,503 @@
/*****************************************************************************
*
* File Name : wm_adc.c
*
* Description: adc Driver Module
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-8-15
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "wm_regs.h"
#include "wm_adc.h"
#include "wm_dma.h"
#include "misc.h"
#include "wm_io.h"
#include "wm_irq.h"
static u16 adc_offset = 0;
volatile ST_ADC gst_adc;
volatile u8 adc_irq_flag = 0;
void ADC_IRQHandler(void)
{
u16 adcvalue;
int reg;
reg = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
if(reg & CONFIG_ADC_INT) //ADC中断
{
adc_irq_flag = 1;
tls_adc_clear_irq(ADC_INT_TYPE_ADC);
adcvalue = tls_read_adc_result();
if(gst_adc.adc_cb)
gst_adc.adc_cb(&adcvalue,1);
}
if(reg & CONFIG_ADC_INT_CMP)
{
tls_adc_clear_irq(ADC_INT_TYPE_ADC_COMP);
if(gst_adc.adc_bigger_cb)
gst_adc.adc_bigger_cb(NULL, 0);
}
}
static void adc_dma_isr_callbk(void)
{
if(gst_adc.adc_dma_cb)
gst_adc.adc_dma_cb((u16 *)(ADC_DEST_BUFFER_DMA), gst_adc.valuelen);
}
void tls_adc_init(u8 ifusedma,u8 dmachannel)
{
tls_reg_write32(HR_SD_ADC_CONFIG_REG, 0x0);
tls_irq_enable(ADC_IRQn);
//注册中断和channel有关所以需要先请求
if(ifusedma)
{
gst_adc.dmachannel = tls_dma_request(dmachannel, NULL); //请求dma不要直接指定因为请求的dma可能会被别的任务使用
tls_dma_irq_register(gst_adc.dmachannel, (void(*)(void*))adc_dma_isr_callbk, NULL, TLS_DMA_IRQ_TRANSFER_DONE);
}
//printf("\ndma channel = %d\n",gst_adc.dmachannel);
}
void tls_adc_clear_irq(int inttype)
{
int reg;
reg = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
if(ADC_INT_TYPE_ADC == inttype)
{
reg |= CONFIG_ADC_INT;
tls_reg_write32(HR_SD_ADC_CONFIG_REG, reg);
}
else if(ADC_INT_TYPE_ADC_COMP== inttype)
{
reg |= CONFIG_ADC_INT_CMP;
tls_reg_write32(HR_SD_ADC_CONFIG_REG, reg);
}
else if(ADC_INT_TYPE_DMA == inttype)
{
tls_dma_irq_clr(gst_adc.dmachannel, TLS_DMA_IRQ_TRANSFER_DONE);
}
}
void tls_adc_irq_register(int inttype, void (*callback)(u16 *buf, u16 len))
{
if(ADC_INT_TYPE_ADC == inttype)
{
gst_adc.adc_cb = callback;
}
else if(ADC_INT_TYPE_DMA == inttype)
{
gst_adc.adc_dma_cb = callback;
}
else if(ADC_INT_TYPE_ADC_COMP == inttype)
{
gst_adc.adc_bigger_cb = callback;
}
}
u16 tls_read_adc_result(void)
{
u32 value;
u16 ret;
value = tls_reg_read32(HR_SD_ADC_RESULT_REG);
ret = value&0x3fff;
return ret;
}
void tls_adc_start_with_cpu(int Channel)
{
u32 value;
Channel &= CONFIG_ADC_CHL_MASK;
/* Stop adc first */
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value &= ~CONFIG_ADC_DMA_MASK;
value &= ~CONFIG_ADC_START;
value |= Channel;
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value |= CONFIG_ADC_START;
value |= CONFIG_ADC_INT_MASK;
if(Channel < 8)
{
value |= CONFIG_ADC_G_CTRL12;
value &= ~ CONFIG_ADC_VCM(0x3F);
value |= CONFIG_ADC_VCM(0x1F);
}
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
}
void tls_adc_enable_calibration_buffer_offset(void)
{
u32 value;
/* Stop adc first */
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value &= ~CONFIG_ADC_DMA_MASK;
value &= ~CONFIG_ADC_START;
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value |= CONFIG_ADC_CHL_OFFSET;
value |= CONFIG_ADC_START;
value |= CONFIG_ADC_INT_MASK;
value |= CONFIG_ADC_EN_CAL;
value |= CONFIG_ADC_G_CTRL12;
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
}
void tls_adc_temp_offset_with_cpu(u8 calTemp12)
{
u32 value;
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value &= ~CONFIG_ADC_DMA_MASK;
value &= ~CONFIG_ADC_START;
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value |= CONFIG_ADC_CHL_TEMP;
value |= CONFIG_ADC_START;
value |= CONFIG_ADC_INT_MASK;
if(calTemp12)
{
value |= CONFIG_ADC_CAL_OFFSET_TEMP12;
}
else
{
value &= ~CONFIG_ADC_CAL_OFFSET_TEMP12;
}
value &= ~CONFIG_ADC_G_CTRL12;
value |= CONFIG_ADC_TEMP_ON;
value |= CONFIG_ADC_G_TEMP12(3);
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value); /*start adc*/
}
void tls_adc_voltage_start_with_cpu(void)
{
u32 value;
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value &= ~CONFIG_ADC_DMA_MASK;
value &= ~CONFIG_ADC_START;
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value |= CONFIG_ADC_CHL_VOLT;
value |= CONFIG_ADC_START;
value |= CONFIG_ADC_INT_MASK;
value |= CONFIG_ADC_G_CTRL12;
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value); /*start adc*/
}
void tls_adc_start_with_dma(int Channel, int Length)
{
u32 value;
int len;
if(Channel < 0 || Channel > 11)
return;
if(Length > ADC_DEST_BUFFER_SIZE)
len = ADC_DEST_BUFFER_SIZE;
else
len = Length;
gst_adc.valuelen = len;
Channel &= CONFIG_ADC_CHL_MASK;
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value &= ~CONFIG_ADC_START; //stop
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
/* Stop dma if necessary */
while(DMA_CHNLCTRL_REG(gst_adc.dmachannel) & 1)
{
DMA_CHNLCTRL_REG(gst_adc.dmachannel) = 2;
}
DMA_SRCADDR_REG(gst_adc.dmachannel) = HR_SD_ADC_RESULT_REG;
DMA_DESTADDR_REG(gst_adc.dmachannel) = ADC_DEST_BUFFER_DMA;
/* Hard, Normal, adc_req */
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
if (Channel == 8){
DMA_MODE_REG(gst_adc.dmachannel) = (0x01 | (0+6)<<2);
value |= (0x1 << 11);
}
else if (Channel == 9){
DMA_MODE_REG(gst_adc.dmachannel) = (0x01 | (2+6)<<2);
value |= (0x1 << 13);
}
else if (Channel == 10){
DMA_MODE_REG(gst_adc.dmachannel) = (0x01 | (4+6)<<2);
value |= (0x1 << 15);
}
else if (Channel == 11){
DMA_MODE_REG(gst_adc.dmachannel) = (0x01 | (6+6)<<2);
value |= (0x1 << 17);
}
else{
DMA_MODE_REG(gst_adc.dmachannel) = (0x01 | (Channel+6)<<2);
value |= (0x1 << (11 + Channel));
}
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
/* Dest_add_inc, halfword, */
DMA_CTRL_REG(gst_adc.dmachannel) = (1<<3)|(1<<5)|((len*2)<<8);
DMA_INTMASK_REG &= ~(0x01 << (gst_adc.dmachannel *2 + 1));
DMA_CHNLCTRL_REG(gst_adc.dmachannel) = 1; /* Enable dma */
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value |= CONFIG_ADC_START;
value |= Channel;
if(Channel < 8)
{
value |= CONFIG_ADC_G_CTRL12;
value &= ~ CONFIG_ADC_VCM(0x3F);
value |= CONFIG_ADC_VCM(0x1F);
}
// printf("config value==%x\n", value);
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value); /*start adc*/
}
void tls_adc_stop(int ifusedma)
{
u32 value;
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value &= ~CONFIG_ADC_START;
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
if(ifusedma)
tls_dma_free(gst_adc.dmachannel);
}
void tls_adc_config_cmp_reg(int cmp_data, int cmp_pol)
{
u32 value;
cmp_data &= 0x3FFF;
value = tls_reg_read32(HR_SD_ADC_RESULT_REG);
value &= ~(0x3FFF<<14);
value |= (cmp_data<<14);
tls_reg_write32(HR_SD_ADC_RESULT_REG, value);
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value |= CONFIG_ADC_CMP_INT_MASK;
if(cmp_pol)
{
value |= CONFIG_ADC_CMP_POL;
}
else
{
value &= ~CONFIG_ADC_CMP_POL;
}
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
}
void tls_adc_cmp_start(int Channel, int cmp_data, int cmp_pol)
{
u32 value;
Channel &= CONFIG_ADC_CHL_MASK;
/* Stop adc first */
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value &= ~CONFIG_ADC_DMA_MASK;
value &= ~CONFIG_ADC_START;
value |= Channel;
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
tls_adc_config_cmp_reg(cmp_data, cmp_pol);
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
value |= CONFIG_ADC_START;
if(Channel < 8)
{
value |= CONFIG_ADC_G_CTRL12;
value &= ~ CONFIG_ADC_VCM(0x3F);
value |= CONFIG_ADC_VCM(0x1F);
}
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value); /*start adc*/
}
void tls_adc_reference_sel(int ref)
{
u32 value;
value = tls_reg_read32(HR_SD_ADC_CONFIG_REG);
if(ADC_REFERENCE_EXTERNAL == ref)
{
value &= ~CONFIG_ADC_REF_SEL;
value |= CONFIG_ADC_BUF_BYPASS;
}
else if(ADC_REFERENCE_INTERNAL == ref)
{
value |= CONFIG_ADC_REF_SEL;
value &= ~CONFIG_ADC_BUF_BYPASS;
}
tls_reg_write32(HR_SD_ADC_CONFIG_REG, value);
}
void tls_adc_set_clk(int div)
{
u32 value;
value = tls_reg_read32(HR_CLK_DIV_CTL);
value &= ~(0xffff<<12);
value |= (div << 12);
value |= ((u32)0x1<<31);
tls_reg_write32(HR_CLK_DIV_CTL, value);
}
void signedToUnsignedData(u16 *adcValue, u16 *offset)
{
// s16 temp = 0;
if(*adcValue >= 8192)
{
*adcValue -= 8192;
}
else
{
*adcValue += 8192;
}
/* if (*offset >=8192)
{
temp =((*offset-1)&0x1FFF) - 8192;
}else{
temp = *offset;
}
*adcValue -= temp;
*/
}
static void waitForAdcDone(void)
{
while(1)
{
if(adc_irq_flag) //ADC中断
{
adc_irq_flag = 0;
break;
}
}
}
u16 adc_get_offset(void)
{
tls_adc_init(0, 0);
tls_adc_reference_sel(ADC_REFERENCE_INTERNAL);
adc_irq_flag = 0;
tls_adc_enable_calibration_buffer_offset(); //使能校准功能
waitForAdcDone();
adc_offset = tls_read_adc_result(); //获取adc转换结果
tls_adc_stop(0);
//printf("\r\noffset:%d", adc_offset);
return adc_offset;
}
u32 adc_get_interTemp(void)
{
u16 code2, code1, realCode;
u32 tem;
tls_adc_init(0, 0);
tls_adc_reference_sel(ADC_REFERENCE_INTERNAL);
adc_irq_flag = 0;
tls_adc_temp_offset_with_cpu(1); //code2
waitForAdcDone();
code2 = tls_read_adc_result();
tls_adc_stop(0);
signedToUnsignedData(&code2, &adc_offset);
adc_irq_flag = 0;
tls_adc_temp_offset_with_cpu(0); //code1
waitForAdcDone();
code1 = tls_read_adc_result();
tls_adc_stop(0);
signedToUnsignedData(&code1, &adc_offset);
realCode = ( (code1-code2)/2+8192 );
//printf("\r\nTEMP:%.1f", realCode*0.12376-1294.58);
//return (realCode*0.12376-1294.58);
tem = realCode*124-1294580;
return tem;
}
u16 adc_get_inputVolt(u8 channel)
{
u16 average = 0;
/*calibration*/
adc_get_offset();
/*get value*/
tls_adc_init(0, 0);
tls_adc_reference_sel(ADC_REFERENCE_INTERNAL);
adc_irq_flag = 0;
tls_adc_start_with_cpu(channel);
waitForAdcDone();
average = tls_read_adc_result();
tls_adc_stop(0);
signedToUnsignedData(&average, &adc_offset);
//printf("ch[%d]inputVolt:%.3f\r\n", channel+1, ((average-8192.0)/8192*2.25/1.2 + 1.584));
return average;
}
u16 adc_get_interVolt(void)
{
u16 voltValue;
/*calibration*/
adc_get_offset();
/*get value*/
tls_adc_init(0, 0);
tls_adc_reference_sel(ADC_REFERENCE_INTERNAL);
adc_irq_flag = 0;
tls_adc_voltage_start_with_cpu();
waitForAdcDone();
voltValue = tls_read_adc_result();
tls_adc_stop(0);
signedToUnsignedData(&voltValue, &adc_offset);
float voltage = ( 1.214 - ((float)voltValue-8192)/8192*2.25/1.2 )*2;
//printf("\r\ninterVolt:%.2f", voltage);
return voltValue;
}
u32 adc_temp(void)
{
u32 tem;
adc_get_offset();
tem = adc_get_interTemp();
return tem;
}

View File

@@ -0,0 +1,72 @@
/**
* @file wm_cpu.c
*
* @brief cpu driver module
*
* @author kevin
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#include "wm_debug.h"
#include "wm_regs.h"
#include "wm_irq.h"
#include "wm_cpu.h"
#include "wm_pwm.h"
/**
* @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)
{
u32 RegValue;
u8 wlanDiv, cpuDiv;
RegValue = tls_reg_read32(HR_CLK_DIV_CTL);
wlanDiv = (RegValue>>4)&0x0F;
RegValue &= 0xFFFFF000;
RegValue |= 0x80000000;
switch(clk)
{
case CPU_CLK_40M:
cpuDiv = 4;
break;
default:
cpuDiv = 2;
break;
}
RegValue |= ((wlanDiv*4/cpuDiv)<<8) | (wlanDiv<<4) | cpuDiv;
tls_reg_write32(HR_CLK_DIV_CTL, RegValue);
return;
}
/**
* @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)
{
u32 value;
value = tls_reg_read32(HR_CLK_DIV_CTL);
sysclk->apbclk = W600_PLL_CLK_MHZ/4/((value>>4)&0x0F);
sysclk->cpuclk = W600_PLL_CLK_MHZ/(value&0x0F);
sysclk->wlanclk = W600_PLL_CLK_MHZ/((value>>4)&0x0F);
}

View File

@@ -0,0 +1,389 @@
/**
* @file wm_dma.c
*
* @brief DMA Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "misc.h"
#include "wm_dma.h"
#include "wm_regs.h"
#include "wm_irq.h"
#include "wm_osal.h"
struct tls_dma_channels {
unsigned char channels[8]; /* list of channels */
};
typedef void (*dma_irq_callback)(void *p);
struct dma_irq_context {
u8 flags;
dma_irq_callback burst_done_pf;
void *burst_done_priv;
dma_irq_callback transfer_done_pf;
void *transfer_done_priv;
};
static struct dma_irq_context dma_context[8];
static struct tls_dma_channels channels;
extern void wm_delay_ticks(uint32_t ticks);
static void dma_irq_proc(void *p)
{
unsigned char ch;
unsigned int int_src;
ch = (unsigned char)(unsigned long)p;
int_src = tls_reg_read32(HR_DMA_INT_SRC);
if (ch > 3)
{
for (ch = 4; ch < 8; ch++)
{
if (int_src & (TLS_DMA_IRQ_BOTH_DONE << ch * 2))
break;
}
if (8 == ch)
return;
}
if ((int_src & (TLS_DMA_IRQ_BOTH_DONE << ch * 2)) &&
(TLS_DMA_IRQ_BOTH_DONE == dma_context[ch].flags))
{
tls_dma_irq_clr(ch, TLS_DMA_IRQ_BOTH_DONE);
if (dma_context[ch].burst_done_pf)
dma_context[ch].burst_done_pf(dma_context[ch].burst_done_priv);
}
else if ((int_src & (TLS_DMA_IRQ_BURST_DONE << ch * 2)) &&
(TLS_DMA_IRQ_BURST_DONE == dma_context[ch].flags))
{
tls_dma_irq_clr(ch, TLS_DMA_IRQ_BOTH_DONE);
if (dma_context[ch].burst_done_pf)
dma_context[ch].burst_done_pf(dma_context[ch].burst_done_priv);
}
else if ((int_src & (TLS_DMA_IRQ_TRANSFER_DONE << ch * 2)) &&
(TLS_DMA_IRQ_TRANSFER_DONE == dma_context[ch].flags))
{
tls_dma_irq_clr(ch, TLS_DMA_IRQ_BOTH_DONE);
if (dma_context[ch].transfer_done_pf)
dma_context[ch].transfer_done_pf(dma_context[ch].transfer_done_priv);
}
return;
}
void DMA_Channel0_IRQHandler(void)
{
dma_irq_proc((void *)0);
}
void DMA_Channel1_IRQHandler(void)
{
dma_irq_proc((void *)1);
}
void DMA_Channel2_IRQHandler(void)
{
dma_irq_proc((void *)2);
}
void DMA_Channel3_IRQHandler(void)
{
dma_irq_proc((void *)3);
}
void DMA_Channel4_7_IRQHandler(void)
{
dma_irq_proc((void *)4);
}
/**
* @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)
{
unsigned int int_src = 0;
int_src |= flags << 2 * ch;
tls_reg_write32(HR_DMA_INT_SRC, int_src);
return;
}
/**
* @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)
{
unsigned int mask;
mask = tls_reg_read32(HR_DMA_INT_MASK);
mask |= TLS_DMA_IRQ_BOTH_DONE << 2 * ch;
mask &= ~(flags << 2 * ch);
tls_reg_write32(HR_DMA_INT_MASK, mask);
dma_context[ch].flags = flags;
if (flags & TLS_DMA_IRQ_BURST_DONE)
{
dma_context[ch].burst_done_pf = callback;
dma_context[ch].burst_done_priv = arg;
}
if (flags & TLS_DMA_IRQ_TRANSFER_DONE)
{
dma_context[ch].transfer_done_pf = callback;
dma_context[ch].transfer_done_priv = arg;
}
if (ch > 3)
ch = 4;
tls_irq_enable(DMA0_INT + ch);
return;
}
/**
* @brief This function is used to Wait until DMA operation completes
*
* @param[in] ch channel no
*
* @retval 0 completed
* @retval -1 failed
*
* @note None
*/
int tls_dma_wait_complt(unsigned char ch)
{
unsigned long timeout = 0;
while(DMA_CHNLCTRL_REG(ch) & DMA_CHNL_CTRL_CHNL_ON)
{
tls_os_time_delay(1);
timeout ++;
if(timeout > 500)
return -1;
}
return 0;
}
/**
* @brief This function is used to Start the DMA controller by Wrap
*
* @param[in] ch channel no
* @param[in] dma_desc pointer to DMA channel descriptor structure
* @param[in] auto_reload does restart when current transfer complete
* @param[in] src_zize dource address size
* @param[in] dest_zize destination address size
*
* @retval 1 success
* @retval 0 failed
*
* @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)
{
if((ch > 7) && !dma_desc) return 1;
DMA_SRCWRAPADDR_REG(ch) = dma_desc->src_addr;
DMA_DESTWRAPADDR_REG(ch) = dma_desc->dest_addr;
DMA_WRAPSIZE_REG(ch) = (dest_zize << 16) | src_zize;
DMA_CTRL_REG(ch) = ((dma_desc->dma_ctrl & 0x1ffff) << 1) | (auto_reload ? 0x1: 0x0);
DMA_CHNLCTRL_REG(ch) |= DMA_CHNL_CTRL_CHNL_ON;
return 0;
}
/**
* @brief This function is used to Start the DMA controller
*
* @param[in] ch channel no
* @param[in] dma_desc pointer to DMA channel descriptor structure
* @param[in] auto_reload does restart when current transfer complete
*
* @retval 1 success
* @retval 0 failed
*
* @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)
{
if((ch > 7) && !dma_desc) return 1;
DMA_SRCADDR_REG(ch) = dma_desc->src_addr;
DMA_DESTADDR_REG(ch) = dma_desc->dest_addr;
DMA_CTRL_REG(ch) = ((dma_desc->dma_ctrl & 0x7fffff) << 1) | (auto_reload ? 0x1: 0x0);
DMA_CHNLCTRL_REG(ch) |= DMA_CHNL_CTRL_CHNL_ON;
return 0;
}
/**
* @brief This function is used to To stop current DMA channel transfer
*
* @param[in] ch channel no. to be stopped
*
* @retval 0 success
* @retval 1 failed
*
* @note
* If channel stop, DMA_CHNL_CTRL_CHNL_ON bit in DMA_CHNLCTRL_REG is cleared.
*/
unsigned char tls_dma_stop(unsigned char ch)
{
if(ch > 7) return 1;
if(DMA_CHNLCTRL_REG(ch) & DMA_CHNL_CTRL_CHNL_ON)
{
DMA_CHNLCTRL_REG(ch) |= DMA_CHNL_CTRL_CHNL_OFF;
while(DMA_CHNLCTRL_REG(ch) & DMA_CHNL_CTRL_CHNL_ON);
}
return 0;
}
/**
* @brief This function is used to Request a free dma channel
*
* @param[in] ch channel no.
* @param[in] flags flags setted to selected channel
*
* @return Channel no. that is free now
*
* @note
* If ch is 0, the function will select a random free channel,
* else return the selected channel no.
*/
unsigned char tls_dma_request(unsigned char ch, unsigned char flags)
{
unsigned char freeCh = 0;
int i = 0;
if (ch == 0)
{
for (i = 0; i < 8; i++)
{
if (!(channels.channels[i] & TLS_DMA_FLAGS_CHANNEL_VALID))
{
freeCh = i;
break;
}
}
if (8 == i)
{
printf("!!!there is no free DMA channel.!!!\n");
freeCh = 0;
}
}
else if ((ch >0) && (ch < 8))
{
if (!(channels.channels[ch] & TLS_DMA_FLAGS_CHANNEL_VALID))
{
freeCh = ch;
}
else
{
printf("!!!there is no free DMA channel.!!!\n");
freeCh = 0;
}
}
//if(freeCh != 0)
{
channels.channels[freeCh] = flags | TLS_DMA_FLAGS_CHANNEL_VALID;
DMA_MODE_REG(freeCh) = flags;
}
return freeCh;
}
/**
* @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)
{
if(ch < 8)
{
tls_dma_stop(ch);
DMA_SRCADDR_REG(ch) = 0;
DMA_DESTADDR_REG(ch) = 0;
DMA_MODE_REG(ch) = 0;
DMA_CTRL_REG(ch) = 0;
// DMA_INTSRC_REG = 0xffff;
DMA_INTSRC_REG |= 0x03<<(ch*2);
channels.channels[ch] = 0x00;
}
}
/**
* @brief This function is used to Initialize DMA Control
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_dma_init(void)
{
DMA_INTMASK_REG = 0xffff;
DMA_INTSRC_REG = 0xffff;
}

View File

@@ -0,0 +1,575 @@
/**************************************************************************
* File Name : tls_efuse.c
* Author :
* Version :
* Date :
* Description : Use Flash Addr as virtual efuse
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
* All rights reserved.
*
***************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "wm_debug.h"
#include "wm_regs.h"
#include "wm_efuse.h"
#include "wm_config.h"
#include "list.h"
#include "wm_internal_flash.h"
#include "wm_crypto_hard.h"
#include "wm_timer.h"
#include "wm_cpu.h"
#include "wm_irq.h"
#include "wm_flash_map.h"
extern void flashSRRW(unsigned long offset,unsigned char *buf,unsigned long sz, unsigned char *backbuf, unsigned int backlen, unsigned int rd);
#define FT_MAGICNUM_ADDR (FLASH_BASE_ADDR)
#define MAGICNUM_LEN (4)
#define FT_CHECKSUM_ADDR (FT_MAGICNUM_ADDR + MAGICNUM_LEN)
#define CHECKSUM_LEN (4)
#define FT_DATALEN_ADDR (FT_CHECKSUM_ADDR + CHECKSUM_LEN)
#define FT_DATALEN_LEN (4)
#define FT_MAC_ADDR (FT_DATALEN_ADDR + FT_DATALEN_LEN)
#define MAC_ADDR_LEN (8)
#define FT_TX_DC_OFFSET_ADDR (FT_MAC_ADDR + MAC_ADDR_LEN)
#define TX_DC_OFFSET_LEN (4)
#define FT_RX_DC_OFFSET_ADDR (FT_TX_DC_OFFSET_ADDR + TX_DC_OFFSET_LEN)
#define RX_DC_OFFSET_LEN (4)
#define FT_TX_IQ_GAIN_ADDR (FT_RX_DC_OFFSET_ADDR + RX_DC_OFFSET_LEN)
#define TX_IQ_GAIN_LEN (4)
#define FT_RX_IQ_GAIN_ADDR (FT_TX_IQ_GAIN_ADDR + TX_IQ_GAIN_LEN)
#define RX_IQ_GAIN_LEN (4)
#define FT_TX_IQ_PHASE_ADDR (FT_RX_IQ_GAIN_ADDR + RX_IQ_GAIN_LEN)
#define TX_IQ_PHASE_LEN (4)
#define FT_RX_IQ_PHASE_ADDR (FT_TX_IQ_PHASE_ADDR + TX_IQ_PHASE_LEN)
#define RX_IQ_PHASE_LEN (4)
#define FT_GAIN_ADDR (FT_RX_IQ_PHASE_ADDR + RX_IQ_PHASE_LEN)
#define FT_GAIN_LEN (84)
#define FT_FIX_DATA_LEN (MAC_ADDR_LEN + TX_DC_OFFSET_LEN + RX_DC_OFFSET_LEN + TX_IQ_GAIN_LEN + RX_IQ_GAIN_LEN \
+ TX_IQ_PHASE_LEN \
+ RX_IQ_PHASE_LEN)
/* key paramater area -- begin -- */
/** PHY parameter area **/
#define PHY_BASE_ADDR (FLASH_BASE_ADDR)
#define PHY_AREA_LEN (0x1000)
/** QFlash parameter area **/
#define QFLASH_BASE_ADDR (PHY_BASE_ADDR + PHY_AREA_LEN)
#define QFLASH_AREA_LEN (0x1000)
#define QFLASH_HDR_BASE_ADDR (QFLASH_BASE_ADDR)
#define QFLASH_HDR_LEN (12)
#define QFLASH_Sec_Level_BASE_ADDR (QFLASH_HDR_BASE_ADDR + QFLASH_HDR_LEN)
#define QFLASH_Sec_Level_LEN (4)
#define QFLASH_CHIP_ID_BASE_ADDR (QFLASH_Sec_Level_BASE_ADDR + QFLASH_Sec_Level_LEN)
#define QFLASH_CHIP_ID_LEN (16)
/* key parameter area -- end -- */
typedef struct FT_PARAM
{
unsigned int magic_no;
unsigned int checksum;
unsigned int data_len;
unsigned char mac_addr[MAC_ADDR_LEN];
unsigned int tx_dcoffset;
unsigned int rx_dcoffset;
unsigned int tx_iq_gain;
unsigned int rx_iq_gain;
unsigned int tx_iq_phase;
unsigned int rx_iq_phase;
unsigned char tx_gain[FT_GAIN_LEN];
}FT_PARAM_ST;
static u8 default_mac[6] = {0x00,0x25,0x08,0x09,0x01,0x0F};
FT_PARAM_ST gftParam;
int tls_ft_param_init(void)
{
int i = 0;
int usedcnt[2] = {0, 0};
u32 crcvalue = 0;
psCrcContext_t ctx;
u8 *pmem = NULL;
FT_PARAM_ST *pft = NULL;
if (gftParam.magic_no == SIGNATURE_WORD)
{
return TRUE;
}
pmem = tls_mem_alloc(512);
if (pmem == NULL)
{
return FALSE;
}
pft = tls_mem_alloc(sizeof(FT_PARAM_ST));
if (pft == NULL)
{
return FALSE;
}
for (i = 0; i < 2; i++)
{
if (i == 0)
{
tls_fls_read(FT_MAGICNUM_ADDR, (unsigned char *)pft, sizeof(FT_PARAM_ST));
}else{
flashSRRW(0, (unsigned char *)pft, sizeof(FT_PARAM_ST), pmem, 512, 1);
}
if (pft->magic_no == SIGNATURE_WORD)
{
tls_crypto_init();
tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
tls_crypto_crc_update(&ctx, (unsigned char *)pft + 12, sizeof(FT_PARAM_ST) - 12);
tls_crypto_crc_final(&ctx, &crcvalue);
if ((pft->checksum != crcvalue))
{
usedcnt[i] = -1;
continue;
}
if (gftParam.magic_no != SIGNATURE_WORD)
{
memcpy(&gftParam, pft, sizeof(FT_PARAM_ST));
}
}else{
usedcnt[i] = -1;
}
}
if ((usedcnt[0] + usedcnt[1]) == -2)
{
/*Use default ft param*/
}
else if (usedcnt[0] < 0) /*flash param destroyed*/
{
tls_flash_unlock();
tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)&gftParam, sizeof(gftParam));
tls_flash_lock();
}
else if (usedcnt[1] < 0) /*SR param destroyed*/
{
flashSRRW(0, (unsigned char *)&gftParam, sizeof(FT_PARAM_ST), pmem, 512, 0);
}
else
{
if (gftParam.checksum != pft->checksum)
{
flashSRRW(0, (unsigned char *)&gftParam, sizeof(FT_PARAM_ST), pmem, 512, 0);
}
}
tls_mem_free(pmem);
tls_mem_free(pft);
return TRUE;
}
int tls_ft_param_get(unsigned int opnum, void *data, unsigned int rdlen)
{
//FT_PARAM_ST ft;
//tls_fls_read(FT_MAGICNUM_ADDR, (unsigned char *)&ft, sizeof(ft));
switch (opnum)
{
case CMD_MAC: /*MAC*/
if ((gftParam.mac_addr[0]&0x1)
||(0 == (gftParam.mac_addr[0]|gftParam.mac_addr[1]|gftParam.mac_addr[2]|gftParam.mac_addr[3]|gftParam.mac_addr[4]|gftParam.mac_addr[5])))
{
memcpy(data, default_mac, rdlen);
}
else
{
memcpy(data, gftParam.mac_addr, rdlen);
}
break;
case CMD_TX_DC: /*tx_dcoffset*/
*(unsigned int *)data = gftParam.tx_dcoffset;
break;
case CMD_RX_DC: /*rx_dcoffset*/
*(unsigned int *)data = gftParam.rx_dcoffset;
break;
case CMD_TX_IQ_GAIN:
*(unsigned int *)data = gftParam.tx_iq_gain;
break;
case CMD_RX_IQ_GAIN:
*(unsigned int *)data = gftParam.rx_iq_gain;
break;
case CMD_TX_IQ_PHASE:
*(unsigned int *)data = gftParam.tx_iq_phase;
break;
case CMD_RX_IQ_PHASE:
*(unsigned int *)data = gftParam.rx_iq_phase;
break;
case CMD_TX_GAIN: /*gain*/
if (rdlen < FT_GAIN_LEN)
{
memcpy(data, gftParam.tx_gain, rdlen);
}
else
{
memcpy(data, gftParam.tx_gain, FT_GAIN_LEN);
}
break;
default:
return -1;
}
return 0;
}
int tls_ft_param_set(unsigned int opnum, void *data, unsigned int len)
{
psCrcContext_t ctx;
unsigned int writelen = 0;
u8 *pmem = NULL;
if (!data || !len)
{
return -1;
}
//tls_fls_read(FT_MAGICNUM_ADDR, (unsigned char *)&gftParam, sizeof(gftParam));
switch (opnum)
{
case CMD_MAC: /*MAC*/
memcpy(gftParam.mac_addr, (unsigned char *)data, len);
break;
case CMD_TX_DC: /*tx_dcoffset*/
gftParam.tx_dcoffset = *(unsigned int *)data;
break;
case CMD_RX_DC: /*rx_dcoffset*/
gftParam.rx_dcoffset = *(unsigned int *)data;
break;
case CMD_TX_IQ_GAIN:
gftParam.tx_iq_gain = *(unsigned int *)data;
break;
case CMD_RX_IQ_GAIN:
gftParam.rx_iq_gain = *(unsigned int *) data;
break;
case CMD_TX_IQ_PHASE:
gftParam.tx_iq_phase = *(unsigned int *)data;
break;
case CMD_RX_IQ_PHASE:
gftParam.rx_iq_phase = *(unsigned int *) data;
break;
case CMD_TX_GAIN: /*gain*/
if (len >= FT_GAIN_LEN)
{
writelen = FT_GAIN_LEN;
}
else
{
writelen = len;
}
memcpy(gftParam.tx_gain, data, writelen);
break;
default:
return -1;
}
tls_crypto_init();
tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
gftParam.magic_no = SIGNATURE_WORD;
tls_crypto_crc_update(&ctx, (unsigned char *)&gftParam + 12, sizeof(gftParam) -12);
tls_crypto_crc_final(&ctx, &gftParam.checksum);
tls_flash_unlock();
tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)&gftParam, sizeof(gftParam));
tls_flash_lock();
pmem = tls_mem_alloc(512);
if (pmem)
{
flashSRRW(0, (unsigned char *)&gftParam, sizeof(gftParam), pmem, 512, 0);
tls_mem_free(pmem);
}
return 0;
}
/**********************************************************************************************************
* Description: This function is used to get mac addr.
*
* Arguments : mac mac addr,6 byte
*
* Returns : TLS_EFUSE_STATUS_OK get success
* TLS_EFUSE_STATUS_EIO get failed
**********************************************************************************************************/
int tls_get_mac_addr(u8 *mac)
{
return tls_ft_param_get(CMD_MAC, mac, 6);
}
/**********************************************************************************************************
* Description: This function is used to set mac addr.
*
* Arguments : mac mac addr,6 byte
*
* Returns : TLS_EFUSE_STATUS_OK get success
* TLS_EFUSE_STATUS_EIO get failed
**********************************************************************************************************/
int tls_set_mac_addr(u8 *mac)
{
return tls_ft_param_set(CMD_MAC, mac, 6);
}
/**********************************************************************************************************
* Description: This function is used to get tx lod.
*
* Arguments : *txlo
*
* Returns : TLS_EFUSE_STATUS_OK get success
* TLS_EFUSE_STATUS_EIO get failed
**********************************************************************************************************/
int tls_get_tx_lo(u8 *txlo)
{
return tls_ft_param_get(CMD_TX_DC, txlo, 4);
}
/**********************************************************************************************************
* Description: This function is used to set tx lo.
*
* Arguments : txlo
*
* Returns : TLS_EFUSE_STATUS_OK set success
* TLS_EFUSE_STATUS_EIO set failed
**********************************************************************************************************/
int tls_set_tx_lo(u8 *txlo)
{
return tls_ft_param_set(CMD_TX_DC, txlo, 4);
}
/**********************************************************************************************************
* Description: This function is used to get tx iq gain.
*
* Arguments : txGain
*
* Returns : TLS_EFUSE_STATUS_OK set success
* TLS_EFUSE_STATUS_EIO set failed
**********************************************************************************************************/
int tls_get_tx_iq_gain(u8 *txGain)
{
return tls_ft_param_get(CMD_TX_IQ_GAIN, txGain, 4);
}
/**********************************************************************************************************
* Description: This function is used to set tx iq gain.
*
* Arguments : txGain
*
* Returns : TLS_EFUSE_STATUS_OK set success
* TLS_EFUSE_STATUS_EIO set failed
**********************************************************************************************************/
int tls_set_tx_iq_gain(u8 *txGain)
{
return tls_ft_param_set(CMD_TX_IQ_GAIN, txGain, 4);
}
/**********************************************************************************************************
* Description: This function is used to get rx iq gain.
*
* Arguments : rxGain
*
* Returns : TLS_EFUSE_STATUS_OK set success
* TLS_EFUSE_STATUS_EIO set failed
**********************************************************************************************************/
int tls_get_rx_iq_gain(u8 *rxGain)
{
return tls_ft_param_get(CMD_RX_IQ_GAIN, rxGain, 4);
}
/**********************************************************************************************************
* Description: This function is used to set rx iq gain.
*
* Arguments : rxGain
*
* Returns : TLS_EFUSE_STATUS_OK set success
* TLS_EFUSE_STATUS_EIO set failed
**********************************************************************************************************/
int tls_set_rx_iq_gain(u8 *rxGain)
{
return tls_ft_param_set(CMD_RX_IQ_GAIN, rxGain, 4);
}
/**********************************************************************************************************
* Description: This function is used to get tx iq phase.
*
* Arguments : txPhase
*
* Returns : TLS_EFUSE_STATUS_OK set success
* TLS_EFUSE_STATUS_EIO set failed
**********************************************************************************************************/
int tls_get_tx_iq_phase(u8 *txPhase)
{
return tls_ft_param_get(CMD_TX_IQ_PHASE, txPhase, 4);
}
/**********************************************************************************************************
* Description: This function is used to set tx iq phase.
*
* Arguments : txPhase
*
* Returns : TLS_EFUSE_STATUS_OK set success
* TLS_EFUSE_STATUS_EIO set failed
**********************************************************************************************************/
int tls_set_tx_iq_phase(u8 *txPhase)
{
return tls_ft_param_set(CMD_TX_IQ_PHASE, txPhase, 4);
}
/**********************************************************************************************************
* Description: This function is used to get rx iq phase.
*
* Arguments : rxPhase
*
* Returns : TLS_EFUSE_STATUS_OK set success
* TLS_EFUSE_STATUS_EIO set failed
**********************************************************************************************************/
int tls_get_rx_iq_phase(u8 *rxPhase)
{
return tls_ft_param_get(CMD_RX_IQ_PHASE, rxPhase, 4);
}
/**********************************************************************************************************
* Description: This function is used to set tx iq phase.
*
* Arguments : rxPhase
*
* Returns : TLS_EFUSE_STATUS_OK set success
* TLS_EFUSE_STATUS_EIO set failed
**********************************************************************************************************/
int tls_set_rx_iq_phase(u8 *rxPhase)
{
return tls_ft_param_set(CMD_RX_IQ_PHASE, rxPhase, 4);
}
int tls_freq_err_op(u8 *freqerr, u8 flag)
{
tls_flash_unlock();
if (flag){
tls_fls_write(FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST), freqerr, 4);
}
else
{
tls_fls_read(FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST), freqerr, 4);
}
tls_flash_lock();
return TLS_EFUSE_STATUS_OK;
}
int tls_rf_vcg_ctrl_op(u8 *vcg, u8 flag)
{
tls_flash_unlock();
if (flag){
tls_fls_write(VCG_ADDR, vcg, VCG_LEN);
}
else
{
tls_fls_read(VCG_ADDR, vcg, VCG_LEN);
}
tls_flash_lock();
return TLS_EFUSE_STATUS_OK;
}
/**********************************************************************************************************
* Description: This function is used to get tx gain.
*
* Arguments : txgain tx gain
*
* Returns : TLS_EFUSE_STATUS_OK get success
* TLS_EFUSE_STATUS_EIO get failed
**********************************************************************************************************/
int tls_get_tx_gain(u8 *txgain)
{
tls_ft_param_get(CMD_TX_GAIN, txgain, TX_GAIN_LEN);
return TLS_EFUSE_STATUS_OK;
}
/**********************************************************************************************************
* Description: This function is used to set tx gain.
*
* Arguments : txgain tx gain
*
* Returns : TLS_EFUSE_STATUS_OK set success
* TLS_EFUSE_STATUS_EIO set failed
**********************************************************************************************************/
int tls_set_tx_gain(u8 *txgain)
{
tls_ft_param_set(CMD_TX_GAIN, txgain, TX_GAIN_LEN);
return TLS_EFUSE_STATUS_OK;
}
#define FF_n16 0xff, 0xff, 0xff, 0xff, \
0xff, 0xff, 0xff, 0xff, \
0xff, 0xff, 0xff, 0xff, \
0xff, 0xff, 0xff, 0xff
int tls_get_chipid(u8 chip_id[QFLASH_CHIP_ID_LEN])
{
int ret = 0;
static u8 _chip_id[QFLASH_CHIP_ID_LEN] = { FF_n16 };
u8 zero[QFLASH_CHIP_ID_LEN] = { FF_n16 };
if (!memcmp(_chip_id, zero, QFLASH_CHIP_ID_LEN))
{
ret = tls_fls_read(QFLASH_CHIP_ID_BASE_ADDR, _chip_id, QFLASH_CHIP_ID_LEN);
}
if (0 == ret)
{
memcpy(chip_id, _chip_id, QFLASH_CHIP_ID_LEN);
}
return ret;
}
#undef FF_n16
unsigned int tls_sleep(unsigned int seconds)
{
int ret = 0;
ret = tls_msleep(seconds * 1000);
return ret;
}
int tls_msleep(unsigned int msec)
{
int ret = 0;
ret = tls_delay_via_timer(msec, TIMER_MS_UNIT_FLAG);
return ret;
}
int tls_usleep(unsigned int /*useconds_t*/ usec)
{
int ret = 0;
ret = tls_delay_via_timer(usec, TIMER_US_UNIT_FLAG);
return ret;
}

View File

@@ -0,0 +1,542 @@
/**
* @file wm_fls.c
*
* @brief flash Driver Module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "list.h"
#include "wm_hostspi.h"
#include "wm_flash.h"
#include "wm_dbg.h"
#include "wm_mem.h"
#include "wm_fls_gd25qxx.h"
static struct tls_fls *spi_fls = NULL;
int tls_spifls_read_id(u32 * id)
{
u32 cmd;
int err;
cmd = FLS_CMD_READ_DEV_ID;
*id = 0;
err = tls_spi_read_with_cmd((const u8 *) &cmd, 4, (u8 *) id, 3);
if (err != TLS_SPI_STATUS_OK)
{
TLS_DBGPRT_ERR("flash read ID fail(%d)!\n", err);
return TLS_FLS_STATUS_EIO;
}
TLS_DBGPRT_FLASH_INFO("flash ID - 0x%x.\n", *id);
return TLS_FLS_STATUS_OK;
}
/**
* @brief This function is used to read data from the flash.
*
* @param[in] addr is byte offset addr for read from the flash.
* @param[in] buf is user for data buffer of flash read
* @param[in] len is byte length for 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)
{
int err;
u32 read_bytes;
struct tls_fls_drv *drv;
if (spi_fls == NULL)
{
TLS_DBGPRT_ERR("flash driver module not beed installed!\n");
return TLS_FLS_STATUS_EPERM;
}
if (spi_fls->current_drv == NULL)
{
TLS_DBGPRT_ERR("the current spi flash driver not installed!\n");
return TLS_FLS_STATUS_ENODRV;
}
if ((addr >= spi_fls->current_drv->total_size) || (len == 0)
|| (buf == NULL))
{
return TLS_FLS_STATUS_EINVAL;
}
tls_os_sem_acquire(spi_fls->fls_lock, 0);
drv = spi_fls->current_drv;
read_bytes =
((addr + len) > drv->total_size) ? (drv->total_size - addr) : len;
err = TLS_FLS_STATUS_OK;
err = drv->read(addr, buf, read_bytes);
tls_os_sem_release(spi_fls->fls_lock);
return err;
}
int tls_spifls_fast_read(u32 addr, u8 * buf, u32 len)
{
int err;
u32 read_bytes;
struct tls_fls_drv *drv;
if (spi_fls == NULL)
{
TLS_DBGPRT_ERR("flash driver module not beed installed!\n");
return TLS_FLS_STATUS_EPERM;
}
if (spi_fls->current_drv == NULL)
{
TLS_DBGPRT_ERR("the current spi flash driver not installed!\n");
return TLS_FLS_STATUS_ENODRV;
}
if ((addr >= spi_fls->current_drv->total_size) || (len == 0)
|| (buf == NULL))
{
return TLS_FLS_STATUS_EINVAL;
}
if ((spi_fls->current_drv->flags & TLS_FLS_FLAG_FAST_READ) !=
TLS_FLS_FLAG_FAST_READ)
{
return TLS_FLS_STATUS_ENOSUPPORT;
}
drv = spi_fls->current_drv;
read_bytes =
((addr + len) > drv->total_size) ? (drv->total_size - addr) : len;
err = TLS_FLS_STATUS_OK;
err = drv->fast_read(addr, buf, read_bytes);
return err;
}
int tls_spifls_page_write(u32 page, u8 * buf, u32 page_cnt)
{
int err;
u32 write_pages;
u32 i;
struct tls_fls_drv *drv;
if (spi_fls == NULL)
{
TLS_DBGPRT_ERR("flash driver module not beed installed!\n");
return TLS_FLS_STATUS_EPERM;
}
if (spi_fls->current_drv == NULL)
{
TLS_DBGPRT_ERR("the current spi flash driver not installed!\n");
return TLS_FLS_STATUS_ENODRV;
}
if ((page >= (spi_fls->current_drv->total_size / spi_fls->current_drv->page_size))
|| (page_cnt == 0) || (buf == NULL))
{
return TLS_FLS_STATUS_EINVAL;
}
drv = spi_fls->current_drv;
write_pages = ((page + page_cnt) > (drv->total_size / drv->page_size)) ?
((drv->total_size / drv->page_size) -page) : page_cnt;
err = TLS_FLS_STATUS_OK;
for (i = 0; i < write_pages; i++)
{
err = drv->page_write(page + i, buf + i * drv->page_size);
if (err != TLS_FLS_STATUS_OK)
{
TLS_DBGPRT_ERR("flash page write fail(page %d)!\n", (page + i));
break;
}
}
return err;
}
/**
* @brief This function is used to write data to the flash.
*
* @param[in] addr is byte offset addr for write to the flash
* @param[in] buf is the data buffer want to write to flash
* @param[in] len is the byte length want 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)
{
u8 *cache;
int err;
u32 sector_addr;
u32 sector_num;
u32 write_bytes;
u32 i;
struct tls_fls_drv *drv;
if (spi_fls == NULL)
{
TLS_DBGPRT_ERR("flash driver module not beed installed!\n");
return TLS_FLS_STATUS_EPERM;
}
if (spi_fls->current_drv == NULL)
{
TLS_DBGPRT_ERR("the current spi flash driver not installed!\n");
return TLS_FLS_STATUS_ENODRV;
}
if ((addr >= spi_fls->current_drv->total_size) || (len == 0)
|| (buf == NULL))
{
return TLS_FLS_STATUS_EINVAL;
}
tls_os_sem_acquire(spi_fls->fls_lock, 0);
drv = spi_fls->current_drv;
write_bytes =
((addr + len) > drv->total_size) ? (drv->total_size - addr) : len;
sector_addr = addr / drv->sector_size;
sector_num = (addr + write_bytes - 1) / drv->sector_size - sector_addr + 1;
TLS_DBGPRT_FLASH_INFO
("write to flash: sector address - %d, sectors - %d.\n", sector_addr,
sector_num);
err = TLS_FLS_STATUS_OK;
cache = tls_mem_alloc(drv->sector_size);
if (cache == NULL)
{
tls_os_sem_release(spi_fls->fls_lock);
TLS_DBGPRT_ERR("allocate sector cache memory(%dB) fail!\n",
drv->sector_size);
return TLS_FLS_STATUS_ENOMEM;
}
for (i = 0; i < sector_num; i++)
{
TLS_DBGPRT_FLASH_INFO("firstly, read the sector - %d to cache.\n",
sector_addr + i);
err = drv->read((sector_addr + i) * drv->sector_size, cache, drv->sector_size);
if (err != TLS_FLS_STATUS_OK)
{
tls_os_sem_release(spi_fls->fls_lock);
TLS_DBGPRT_ERR("flash read fail(sector %d)!\n", (sector_addr + i));
break;
}
if (1 == sector_num){/*flash write only in one sector*/
MEMCPY(cache + (addr%drv->sector_size), buf, write_bytes);
buf += write_bytes;
write_bytes = 0;
}else{/*flash write through some sectors*/
if (0 == i) {
MEMCPY(cache+(addr%drv->sector_size), buf, drv->sector_size - (addr%drv->sector_size));
buf += drv->sector_size - (addr%drv->sector_size);
write_bytes -= drv->sector_size - (addr%drv->sector_size);
} else if (i == (sector_num - 1)) {
MEMCPY(cache, buf, write_bytes);
buf += write_bytes;
write_bytes = 0;
} else {
MEMCPY(cache, buf, drv->sector_size);
buf += drv->sector_size;
write_bytes -= drv->sector_size;
}
}
TLS_DBGPRT_FLASH_INFO("second, erase the sector - %d.\n",
sector_addr + i);
err = drv->erase(sector_addr + i);
if (err != TLS_FLS_STATUS_OK)
{
tls_os_sem_release(spi_fls->fls_lock);
TLS_DBGPRT_ERR("flash erase fail(sector %d)!\n", (sector_addr + i));
break;
}
TLS_DBGPRT_FLASH_INFO
("finnaly, write the data in cache to the sector - %d.\n",
sector_addr + i);
err = tls_spifls_page_write((sector_addr +i) * (drv->sector_size / drv->page_size),
cache, drv->sector_size / drv->page_size);
if (err != TLS_FLS_STATUS_OK)
{
tls_os_sem_release(spi_fls->fls_lock);
TLS_DBGPRT_ERR("flash write fail(sector %d)!\n", (sector_addr + i));
break;
}
}
tls_mem_free(cache);
tls_os_sem_release(spi_fls->fls_lock);
return err;
}
int tls_spifls_erase(u32 sector)
{
int err;
struct tls_fls_drv *drv;
if (spi_fls == NULL)
{
TLS_DBGPRT_ERR("flash driver module not beed installed!\n");
return TLS_FLS_STATUS_EPERM;
}
if (spi_fls->current_drv == NULL)
{
TLS_DBGPRT_ERR("the current spi flash driver not installed!\n");
return TLS_FLS_STATUS_ENODRV;
}
if (sector >= (spi_fls->current_drv->total_size / spi_fls->current_drv->sector_size))
{
TLS_DBGPRT_ERR("the sector to be erase overflow!\n");
return TLS_FLS_STATUS_EINVAL;
}
tls_os_sem_acquire(spi_fls->fls_lock, 0);
drv = spi_fls->current_drv;
err = TLS_FLS_STATUS_OK;
err = drv->erase(sector);
tls_os_sem_release(spi_fls->fls_lock);
return err;
}
int tls_spifls_chip_erase(void)
{
int err;
struct tls_fls_drv *drv;
if (spi_fls == NULL)
{
TLS_DBGPRT_ERR("flash driver module not beed installed!\n");
return TLS_FLS_STATUS_EPERM;
}
if (spi_fls->current_drv == NULL)
{
TLS_DBGPRT_ERR("the current spi flash driver not installed!\n");
return TLS_FLS_STATUS_ENODRV;
}
drv = spi_fls->current_drv;
err = TLS_FLS_STATUS_OK;
err = drv->chip_erase();
return err;
}
int tls_spifls_get_param(u8 type, void *param)
{
int err;
struct tls_fls_drv *drv;
if (spi_fls == NULL)
{
TLS_DBGPRT_ERR("flash driver module not beed installed!\n");
return TLS_FLS_STATUS_EPERM;
}
if (spi_fls->current_drv == NULL)
{
TLS_DBGPRT_ERR("the current spi flash driver not installed!\n");
return TLS_FLS_STATUS_ENODRV;
}
if (param == NULL)
{
return TLS_FLS_STATUS_EINVAL;
}
tls_os_sem_acquire(spi_fls->fls_lock, 0);
drv = spi_fls->current_drv;
err = TLS_FLS_STATUS_OK;
switch (type)
{
case TLS_FLS_PARAM_TYPE_ID:
*((u32 *) param) = drv->id;
break;
case TLS_FLS_PARAM_TYPE_SIZE:
*((u32 *) param) = drv->total_size;
break;
case TLS_FLS_PARAM_TYPE_PAGE_SIZE:
*((u32 *) param) = drv->page_size;
break;
case TLS_FLS_PARAM_TYPE_PROG_SIZE:
*((u32 *) param) = drv->program_size;
break;
case TLS_FLS_PARAM_TYPE_SECTOR_SIZE:
*((u32 *) param) = drv->sector_size;
break;
default:
TLS_DBGPRT_WARNING("invalid parameter ID!\n");
err = TLS_FLS_STATUS_EINVAL;
break;
}
tls_os_sem_release(spi_fls->fls_lock);
return err;
}
int tls_spifls_drv_register(struct tls_fls_drv *fls_drv)
{
u32 cpu_sr;
struct tls_fls_drv *drv;
if (fls_drv == NULL)
{
TLS_DBGPRT_ERR("flash driver module not beed installed!\n");
return TLS_FLS_STATUS_EINVAL;
}
dl_list_for_each(drv, &spi_fls->fls_drvs, struct tls_fls_drv, drv_list)
{
if (drv->id == fls_drv->id)
{
TLS_DBGPRT_WARNING
("corresponding spi flash driver has registered!\n");
return TLS_FLS_STATUS_EEXIST;
}
}
cpu_sr = tls_os_set_critical();
dl_list_add_tail((struct dl_list *) &spi_fls->fls_drvs,
(struct dl_list *) &fls_drv->drv_list);
tls_os_release_critical(cpu_sr);
TLS_DBGPRT_FLASH_INFO("the spi flash driver is registered successfully!\n");
return TLS_FLS_STATUS_OK;
}
int tls_spifls_drv_unregister(struct tls_fls_drv *fls_drv)
{
TLS_DBGPRT_WARNING
("unregister spi flash driver operation is not supported!\n");
return TLS_FLS_STATUS_EPERM;
}
int tls_spifls_probe(void)
{
int err;
u32 id;
struct tls_fls_drv *drv;
if (spi_fls == NULL)
{
TLS_DBGPRT_ERR("flash driver module not beed installed!\n");
return TLS_FLS_STATUS_EPERM;
}
if (spi_fls->current_drv != NULL)
{
TLS_DBGPRT_ERR("the current spi flash has fount the matched driver!\n");
return TLS_FLS_STATUS_EBUSY;
}
TLS_DBGPRT_FLASH_INFO("try to read the current spi flash ID.\n");
err = tls_spifls_read_id(&id);
if (err != TLS_FLS_STATUS_OK)
{
return err;
}
TLS_DBGPRT_FLASH_INFO("current spi flash ID - 0x%x.\n", id);
dl_list_for_each(drv, &spi_fls->fls_drvs, struct tls_fls_drv, drv_list)
{
err = drv->probe(id);
if (err != TLS_FLS_STATUS_OK)
{
return err;
}
tls_spi_setup(drv->mode, drv->cs_active, drv->clock);
TLS_DBGPRT_FLASH_INFO("matched the spi flash driver.\n");
spi_fls->current_drv = drv;
break;
}
if (spi_fls->current_drv == NULL)
{
TLS_DBGPRT_WARNING("not found the matched spi flash driver!\n");
return TLS_FLS_STATUS_ENODRV;
}
return TLS_FLS_STATUS_OK;
}
int tls_spifls_init(void)
{
struct tls_fls *fls;
int err;
if (spi_fls != NULL)
{
TLS_DBGPRT_ERR("flash driver module has been installed!\n");
return TLS_FLS_STATUS_EBUSY;
}
fls = (struct tls_fls *) tls_mem_alloc(sizeof(struct tls_fls));
if (fls == NULL)
{
TLS_DBGPRT_ERR("allocate @spi_fls fail!\n");
return TLS_FLS_STATUS_ENOMEM;
}
memset(fls, 0, sizeof(*fls));
dl_list_init((struct dl_list *) &fls->fls_drvs);
err = tls_os_sem_create(&fls->fls_lock, 1);
if (err != TLS_OS_SUCCESS)
{
tls_mem_free(fls);
TLS_DBGPRT_ERR("create semaphore @fls_lock fail!\n");
return TLS_FLS_STATUS_ENOMEM;
}
spi_fls = fls;
tls_spifls_drv_install();
return TLS_FLS_STATUS_OK;
}
int tls_spifls_exit(void)
{
TLS_DBGPRT_FLASH_INFO("Not support flash driver module uninstalled!\n");
return TLS_FLS_STATUS_EPERM;
}

View File

@@ -0,0 +1,308 @@
/**
* @file wm_fls_gd25qxx.c
*
* @brief gd25qxx flash Driver Module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#include <stdio.h>
#include <stdlib.h>
#include "wm_type_def.h"
#include "wm_flash.h"
#include "wm_hostspi.h"
#include "wm_fls_gd25qxx.h"
#include "wm_debug.h"
#include "wm_gpio.h"
#include "VS10XX.h"
static int tls_spifls_drv_read(u32 addr, u8 * buf, u32 len);
static int tls_spifls_drv_fast_read(u32 addr, u8 * buf, u32 len);
static int tls_spifls_drv_page_write(u32 page, u8 * buf);
static int tls_spifls_drv_erase(u32 sector);
static int tls_spifls_drv_chip_erase(void);
static int tls_spifls_drv_probe(u32 id);
static void tls_spifls_drv_remove(void);
static struct tls_fls_drv exspi_fls = {
.drv_list = {NULL, NULL},
.clock = SPI_SCLK,
.mode = TLS_SPI_MODE_0,
.cs_active = TLS_SPI_CS_LOW,
.flags = 0,
.read = tls_spifls_drv_read,
.fast_read = tls_spifls_drv_fast_read,
.page_write = tls_spifls_drv_page_write,
.erase = tls_spifls_drv_erase,
.chip_erase = tls_spifls_drv_chip_erase,
.probe = tls_spifls_drv_probe,
.remove = tls_spifls_drv_remove
};
static struct tls_fls_drv *exspifls_drv = NULL;
static unsigned int swap32(unsigned int v)
{
return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
((v & 0xff0000) >> 8) | (v >> 24);
}
static int tls_spifls_drv_write_enable(void)
{
u8 cmd;
int err;
cmd = EXSPIFLASH_WRITE_ENABLE;
err = tls_spi_write((const u8 *) &cmd, 1);
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
return TLS_FLS_STATUS_OK;
}
static int tls_spifls_drv_wait_write_enable(void)
{
u8 cmd;
u8 sr;
int err;
cmd = EXSPIFLASH_READ_SR1;
sr = 0;
do
{
err = tls_spi_read_with_cmd((const u8 *) &cmd, 1, &sr, 1);
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
if (sr & FLASH_STATUS_WEL)
{
break;
}
}
while (1);
return TLS_FLS_STATUS_OK;
}
static int tls_spifls_drv_wait_flash_ready(void)
{
u8 cmd;
u8 sr;
int err;
cmd = EXSPIFLASH_READ_SR1;
sr = 0;
do
{
err = tls_spi_read_with_cmd((const u8 *) &cmd, 1, &sr, 1);
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
if ((sr & FLASH_STATUS_BUSY) == 0x00)
{
break;
}
}
while (1);
return TLS_FLS_STATUS_OK;
}
static int tls_spifls_drv_read(u32 addr, u8 * buf, u32 len)
{
u32 cmd;
int err;
cmd = 0;
cmd |= EXSPIFLASH_DATA_READ;
cmd |= swap32(addr) & 0xffffff00;
err = tls_spi_read_with_cmd((const u8 *) &cmd, 4, buf, len);
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
return TLS_FLS_STATUS_OK;
}
static int tls_spifls_drv_fast_read(u32 addr, u8 * buf, u32 len)
{
return TLS_FLS_STATUS_ENOSUPPORT;
}
static int tls_spifls_drv_page_write(u32 page, u8 * buf)
{
u32 cmd;
int err;
err = tls_spifls_drv_write_enable();
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
err = tls_spifls_drv_wait_write_enable();
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
cmd = 0;
cmd |= EXSPIFLASH_PAGE_PROGRAM;
cmd |= swap32(page * exspifls_drv->page_size) & 0xffffff00;
err = tls_spi_write_with_cmd((const u8 *) &cmd, 4, (const u8 *) buf,
exspifls_drv->page_size);
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
err = tls_spifls_drv_wait_flash_ready();
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
return TLS_FLS_STATUS_OK;
}
static int tls_spifls_drv_erase(u32 sector)
{
u32 cmd;
int err;
err = tls_spifls_drv_write_enable();
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
err = tls_spifls_drv_wait_write_enable();
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
cmd = 0;
cmd |= EXSPIFLASH_SECTOR_ERASE;
cmd |= swap32(sector * exspifls_drv->sector_size) & 0xffffff00;
err = tls_spi_write((const u8 *) &cmd, 4);
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
tls_os_time_delay(6);
err = tls_spifls_drv_wait_flash_ready();
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
return TLS_FLS_STATUS_OK;
}
static int tls_spifls_drv_chip_erase(void)
{
u8 cmd;
int err;
err = tls_spifls_drv_write_enable();
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
err = tls_spifls_drv_wait_write_enable();
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
cmd = EXSPIFLASH_CHIP_ERASE;
err = tls_spi_write((const u8 *) &cmd, 1);
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
err = tls_spifls_drv_wait_flash_ready();
if (err != TLS_SPI_STATUS_OK)
{
return TLS_FLS_STATUS_EIO;
}
return TLS_FLS_STATUS_OK;
}
static int tls_spifls_drv_probe(u32 id)
{
// int i = 0;
if (!id)
{
return TLS_FLS_STATUS_EINVAL;
}
exspi_fls.id = id;
if ((id>>16)&0xFF)
{
exspi_fls.total_size = 1 << (id>>16);
}else{
exspi_fls.total_size = FLASH_TOTAL_SIZE; /*1MByte*/
}
exspi_fls.page_size = PAGE_SIZE;
exspi_fls.program_size = PROGRAM_SIZE;
exspi_fls.sector_size = SECTOR_SIZE;
exspifls_drv = &exspi_fls;
return TLS_FLS_STATUS_OK;
}
static void tls_spifls_drv_remove(void)
{
exspifls_drv = NULL;
}
/**
* @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)
{
int err;
extern int tls_spifls_probe(void);
extern int tls_spifls_drv_register(struct tls_fls_drv *fls_drv);
err = tls_spifls_drv_register((struct tls_fls_drv *) &exspi_fls);
if (err == TLS_FLS_STATUS_EEXIST)
{
return err;
}
TLS_DBGPRT_INFO("register the spi flash driver - %d.\n", err);
err = tls_spifls_probe();
TLS_DBGPRT_INFO("probe spi flash - %d.\n", err);
return err;

View File

@@ -0,0 +1,420 @@
/**
* @file wm_gpio.c
*
* @brief GPIO Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#include "wm_gpio.h"
#include "wm_regs.h"
#include "wm_irq.h"
//#include "wm_osal.h"
#include "tls_common.h"
#include "stdio.h"
struct gpio_irq_context{
tls_gpio_irq_callback callback;
void *arg;
};
static struct gpio_irq_context gpio_context[WM_IO_PB_30 - WM_IO_PA_00 + 1] = {{0,0}};
void GPIOA_IRQHandler(void)
{
u8 i = 0;
u8 found = 0;
u32 reg = 0;
reg = tls_reg_read32(HR_GPIO_MIS);
for (i = 0; i <= WM_IO_PA_15; i++)
{
if (reg & BIT(i))
{
found = 1;
break;
}
}
if (found)
{
if (NULL != gpio_context[i].callback)
gpio_context[i].callback(gpio_context[i].arg);
}
return;
}
void GPIOB_IRQHandler(void)
{
u8 i = 0;
u8 found = 0;
u32 reg = 0;
reg = tls_reg_read32(HR_GPIO_MIS + TLS_IO_AB_OFFSET);
for (i = WM_IO_PB_00; i <= WM_IO_PB_31; i++)
{
if (reg & BIT(i - WM_IO_PB_00))
{
found = 1;
break;
}
}
if (found)
{
if (NULL != gpio_context[i].callback)
gpio_context[i].callback(gpio_context[i].arg);
}
return;
}
/**
* @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
* From gpio3 to gpio7,attribute can set to WM_GPIO_ATTR_PULLHIGH,
* but can not set to WM_GPIO_ATTR_PULLLOW,
* the default attribute is WM_GPIO_ATTR_PULLHIGH.
* Other gpio can set to WM_GPIO_ATTR_PULLLOW,but can not set to WM_GPIO_ATTR_PULLHIGH,the deault
* attribute is WM_GPIO_ATTR_PULLLOW.
* all gpio can set to WM_GPIO_ATTR_FLOATING
*/
void tls_gpio_cfg(enum tls_io_name gpio_pin, enum tls_gpio_dir dir, enum tls_gpio_attr attr)
{
u8 pin;
u16 offset;
if (gpio_pin >= WM_IO_PB_00)
{
pin = gpio_pin - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = gpio_pin;
offset = 0;
}
/* enable gpio function */
tls_io_cfg_set(gpio_pin, WM_IO_OPT5_GPIO);
/* gpio direction */
if (WM_GPIO_DIR_OUTPUT == dir)
tls_reg_write32(HR_GPIO_DIR + offset, tls_reg_read32(HR_GPIO_DIR + offset) | BIT(pin)); /* 1 set output */
else if (WM_GPIO_DIR_INPUT == dir)
tls_reg_write32(HR_GPIO_DIR + offset, tls_reg_read32(HR_GPIO_DIR + offset) & (~BIT(pin))); /* 0 set input */
/* gpio pull attribute */
if (WM_GPIO_ATTR_FLOATING == attr)
tls_reg_write32(HR_GPIO_PULL_EN + offset, tls_reg_read32(HR_GPIO_PULL_EN + offset) | BIT(pin)); /* 1 disable pull */
if ((WM_GPIO_ATTR_PULLHIGH == attr) || (WM_GPIO_ATTR_PULLLOW == attr))
tls_reg_write32(HR_GPIO_PULL_EN + offset, tls_reg_read32(HR_GPIO_PULL_EN + offset) & (~BIT(pin))); /* 0 enable pull */
}
/**
* @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)
{
u32 reg_en;
u32 reg;
u8 pin;
u16 offset;
if (gpio_pin >= WM_IO_PB_00)
{
pin = gpio_pin - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = gpio_pin;
offset = 0;
}
reg_en = tls_reg_read32(HR_GPIO_DATA_EN + offset);
tls_reg_write32(HR_GPIO_DATA_EN + offset, reg_en | (1 << pin));
reg = tls_reg_read32(HR_GPIO_DATA + offset);
tls_reg_write32(HR_GPIO_DATA_EN + offset, reg_en);
if(reg & (0x1 << pin))
return 1;
else
return 0;
}
/**
* @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)
{
// u32 cpu_sr = 0;
u32 reg;
u32 reg_en;
u8 pin;
u16 offset;
if (gpio_pin >= WM_IO_PB_00)
{
pin = gpio_pin - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = gpio_pin;
offset = 0;
}
//cpu_sr = tls_os_set_critical();
reg_en = tls_reg_read32(HR_GPIO_DATA_EN + offset);
tls_reg_write32(HR_GPIO_DATA_EN + offset, reg_en | (1 << pin));
reg = tls_reg_read32(HR_GPIO_DATA + offset);
if(value)
tls_reg_write32(HR_GPIO_DATA + offset, reg | (1 << pin)); /* write high */
else
tls_reg_write32(HR_GPIO_DATA + offset, reg & (~(1 << pin)));/* write low */
tls_reg_write32(HR_GPIO_DATA_EN + offset, reg_en);
//tls_os_release_critical(cpu_sr);
}
/**
* @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)
{
u32 reg;
u8 pin;
u16 offset;
u8 vec_no;
if (gpio_pin >= WM_IO_PB_00)
{
pin = gpio_pin - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
vec_no = GPIOB_INT;
}
else
{
pin = gpio_pin;
offset = 0;
vec_no = GPIO_INT;
}
// TLS_DBGPRT_INFO("\r\ntls_gpio_int_enable gpio pin =%d,mode==%d\r\n",gpio_pin,mode);
switch(mode)
{
case WM_GPIO_IRQ_TRIG_RISING_EDGE:
reg = tls_reg_read32(HR_GPIO_IS + offset);
reg &= (~(0x1 << pin));
// TLS_DBGPRT_INFO("\r\nrising edge is ret=%x\r\n",reg);
tls_reg_write32(HR_GPIO_IS + offset, reg); /* 0 edge trigger */
reg = tls_reg_read32(HR_GPIO_IBE + offset);
reg &= (~(0x1 << pin));
// TLS_DBGPRT_INFO("\r\nrising edge ibe ret=%x\r\n",reg);
tls_reg_write32(HR_GPIO_IBE + offset, reg); /* 0 edge trigger */
reg = tls_reg_read32(HR_GPIO_IEV + offset);
reg |= (0x1 << pin);
// TLS_DBGPRT_INFO("\r\nrising edge iev ret=%x\r\n",reg);
tls_reg_write32(HR_GPIO_IEV + offset, reg); /* 1 rising edge trigger */
break;
case WM_GPIO_IRQ_TRIG_FALLING_EDGE:
reg = tls_reg_read32(HR_GPIO_IS + offset);
reg &= (~(0x1 << pin));
// TLS_DBGPRT_INFO("\falling edge is ret=%x\n",reg);
tls_reg_write32(HR_GPIO_IS + offset, reg); /* 0 edge trigger */
reg = tls_reg_read32(HR_GPIO_IBE + offset);
reg &= (~(0x1 << pin));
// TLS_DBGPRT_INFO("\falling edge ibe ret=%x\n",reg);
tls_reg_write32(HR_GPIO_IBE + offset, reg); /* 0 edge trigger */
reg = tls_reg_read32(HR_GPIO_IEV + offset);
reg &= (~(0x1 << pin));
// TLS_DBGPRT_INFO("\falling edge iev ret=%x\n",reg);
tls_reg_write32(HR_GPIO_IEV + offset, reg); /* 0 falling edge trigger */
break;
case WM_GPIO_IRQ_TRIG_DOUBLE_EDGE:
reg = tls_reg_read32(HR_GPIO_IS + offset);
tls_reg_write32(HR_GPIO_IS + offset, reg & (~(0x1 << pin))); /* 0 edge trigger */
reg = tls_reg_read32(HR_GPIO_IBE + offset);
tls_reg_write32(HR_GPIO_IBE + offset, reg | (0x1 << pin)); /* 1 double edge trigger */
break;
case WM_GPIO_IRQ_TRIG_HIGH_LEVEL:
reg = tls_reg_read32(HR_GPIO_IS + offset);
tls_reg_write32(HR_GPIO_IS + offset, reg | (0x1 << pin)); /* 1 level trigger */
reg = tls_reg_read32(HR_GPIO_IEV + offset);
tls_reg_write32(HR_GPIO_IEV + offset, reg | (0x1 << pin)); /* 1 high level trigger */
break;
case WM_GPIO_IRQ_TRIG_LOW_LEVEL:
reg = tls_reg_read32(HR_GPIO_IS + offset);
tls_reg_write32(HR_GPIO_IS + offset, reg | (0x1 << pin)); /* 1 level trigger */
reg = tls_reg_read32(HR_GPIO_IEV + offset);
tls_reg_write32(HR_GPIO_IEV + offset, reg & (~(0x1 << pin))); /* 0 low level trigger */
break;
}
reg = tls_reg_read32(HR_GPIO_IE + offset);
reg |= (0x1 << pin);
// TLS_DBGPRT_INFO("\nie ret=%x\n",reg);
tls_reg_write32(HR_GPIO_IE + offset, reg); /* enable interrupt */
tls_irq_enable(vec_no);
}
/**
* @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)
{
u32 reg;
u8 pin;
u16 offset;
if (gpio_pin >= WM_IO_PB_00)
{
pin = gpio_pin - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = gpio_pin;
offset = 0;
}
reg = tls_reg_read32(HR_GPIO_IE + offset);
tls_reg_write32(HR_GPIO_IE + offset, reg & (~(0x1 << pin))); /* disable interrupt */
tls_irq_disable(GPIO_INT);
}
/**
* @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)
{
u32 reg;
u8 pin;
u16 offset;
if (gpio_pin >= WM_IO_PB_00)
{
pin = gpio_pin - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = gpio_pin;
offset = 0;
}
reg = tls_reg_read32(HR_GPIO_RIS + offset);
if(reg & (0x1 << pin))
return 1;
else
return 0;
}
/**
* @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)
{
u32 reg;
u8 pin;
u16 offset;
if (gpio_pin >= WM_IO_PB_00)
{
pin = gpio_pin - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = gpio_pin;
offset = 0;
}
reg = tls_reg_read32(HR_GPIO_IC + offset);
tls_reg_write32(HR_GPIO_IC + offset, reg | (0x1 << pin)); /* 1 clear interrupt status */
}
/**
* @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)
{
gpio_context[gpio_pin].callback = callback;
gpio_context[gpio_pin].arg = arg;
}

View File

@@ -0,0 +1,964 @@
/**
* @file wm_gpio.c
*
* @brief GPIO Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#include "wm_gpio.h"
#include "wm_regs.h"
#include "wm_irq.h"
//#include "wm_osal.h"
#include "tls_common.h"
#include "wm_gpio_afsel.h"
#include "wm_debug.h"
void wm_hspi_gpio_config(uint8_t numsel)
{
switch(numsel)
{
case 0:
tls_io_cfg_set(WM_IO_PB_14, WM_IO_OPTION1);
tls_io_cfg_set(WM_IO_PB_15, WM_IO_OPTION1);
tls_io_cfg_set(WM_IO_PB_16, WM_IO_OPTION1);
tls_io_cfg_set(WM_IO_PB_17, WM_IO_OPTION1);
tls_io_cfg_set(WM_IO_PB_18, WM_IO_OPTION1);
break;
case 1:
tls_io_cfg_set(WM_IO_PB_08, WM_IO_OPTION2);
tls_io_cfg_set(WM_IO_PB_09, WM_IO_OPTION2);
tls_io_cfg_set(WM_IO_PB_10, WM_IO_OPTION2);
tls_io_cfg_set(WM_IO_PB_11, WM_IO_OPTION2);
tls_io_cfg_set(WM_IO_PB_12, WM_IO_OPTION2);
break;
default:
TLS_DBGPRT_ERR("highspeed spi gpio config error!");
break;
}
}
void wm_spi_ck_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_01:
tls_io_cfg_set(WM_IO_PA_01, WM_IO_OPTION3);
break;
case WM_IO_PB_16:
tls_io_cfg_set(WM_IO_PB_16, WM_IO_OPTION3);
break;
case WM_IO_PB_27:
tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION1);
break;
case WM_IO_PA_11:
tls_io_cfg_set(WM_IO_PA_11, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("spi ck afsel config error!");
break;
}
}
void wm_spi_cs_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_02:
tls_io_cfg_set(WM_IO_PA_02, WM_IO_OPTION3);
break;
case WM_IO_PB_15:
tls_io_cfg_set(WM_IO_PB_15, WM_IO_OPTION3);
break;
case WM_IO_PB_00:
tls_io_cfg_set(WM_IO_PB_00, WM_IO_OPTION1);
break;
case WM_IO_PB_07:
tls_io_cfg_set(WM_IO_PB_07, WM_IO_OPTION4);
break;
case WM_IO_PA_12:
tls_io_cfg_set(WM_IO_PA_12, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("spi cs afsel config error!");
break;
}
}
void wm_spi_di_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_03:
tls_io_cfg_set(WM_IO_PA_03, WM_IO_OPTION3);
break;
case WM_IO_PB_17:
tls_io_cfg_set(WM_IO_PB_17, WM_IO_OPTION3);
break;
case WM_IO_PB_01:
tls_io_cfg_set(WM_IO_PB_01, WM_IO_OPTION1);
break;
case WM_IO_PA_05:
tls_io_cfg_set(WM_IO_PA_05, WM_IO_OPTION3);
break;
case WM_IO_PA_10:
tls_io_cfg_set(WM_IO_PA_10, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("spi di afsel config error!");
break;
}
}
void wm_spi_do_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PB_18:
tls_io_cfg_set(WM_IO_PB_18, WM_IO_OPTION3);
break;
case WM_IO_PB_02:
tls_io_cfg_set(WM_IO_PB_02, WM_IO_OPTION1);
break;
case WM_IO_PA_04:
tls_io_cfg_set(WM_IO_PA_04, WM_IO_OPTION3);
break;
case WM_IO_PA_09:
tls_io_cfg_set(WM_IO_PA_09, WM_IO_OPTION4);
break;
case WM_IO_PA_10:
tls_io_cfg_set(WM_IO_PA_10, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("spi do afsel config error!");
break;
}
}
void wm_sdio_config(uint8_t numsel)
{
switch(numsel)
{
case 0:
tls_io_cfg_set(WM_IO_PB_08, WM_IO_OPTION3);
tls_io_cfg_set(WM_IO_PB_09, WM_IO_OPTION3);
tls_io_cfg_set(WM_IO_PB_10, WM_IO_OPTION3);
tls_io_cfg_set(WM_IO_PB_11, WM_IO_OPTION3);
tls_io_cfg_set(WM_IO_PB_12, WM_IO_OPTION3);
break;
default:
TLS_DBGPRT_ERR("sdio afsel config error!");
break;
}
}
void wm_sdio_cmd_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_06:
tls_io_cfg_set(WM_IO_PA_06, WM_IO_OPTION3);
break;
case WM_IO_PB_07:
tls_io_cfg_set(WM_IO_PB_07, WM_IO_OPTION3);
break;
case WM_IO_PB_13:
tls_io_cfg_set(WM_IO_PB_13, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("sdio cmd afsel config error!");
break;
}
}
void wm_uart0_tx_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_04:
tls_io_cfg_set(WM_IO_PA_04, WM_IO_OPTION1);
break;
case WM_IO_PA_08:
tls_io_cfg_set(WM_IO_PA_08, WM_IO_OPTION3);
break;
case WM_IO_PB_07:
tls_io_cfg_set(WM_IO_PB_07, WM_IO_OPTION2);
break;
case WM_IO_PB_26:
tls_io_cfg_set(WM_IO_PB_26, WM_IO_OPTION2);
break;
default:
TLS_DBGPRT_ERR("uart0 tx afsel config error!");
break;
}
}
void wm_uart0_rx_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_05:
tls_io_cfg_set(WM_IO_PA_05, WM_IO_OPTION1);
tls_bitband_write(HR_GPIOA_DATA_PULLEN, 5, 0);
break;
case WM_IO_PA_09:
tls_io_cfg_set(WM_IO_PA_09, WM_IO_OPTION3);
tls_bitband_write(HR_GPIOA_DATA_PULLEN, 9, 0);
break;
case WM_IO_PB_06:
tls_io_cfg_set(WM_IO_PB_06, WM_IO_OPTION2);
tls_bitband_write(HR_GPIOB_DATA_PULLEN, 6, 0);
break;
case WM_IO_PB_25:
tls_io_cfg_set(WM_IO_PB_25, WM_IO_OPTION2);
tls_bitband_write(HR_GPIOB_DATA_PULLEN, 25, 0);
break;
default:
TLS_DBGPRT_ERR("uart0 rx afsel config error!");
break;
}
}
void wm_uart0_rts_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_13:
tls_io_cfg_set(WM_IO_PA_13, WM_IO_OPTION1);
break;
case WM_IO_PB_04:
tls_io_cfg_set(WM_IO_PB_04, WM_IO_OPTION2);
break;
case WM_IO_PB_24:
tls_io_cfg_set(WM_IO_PB_24, WM_IO_OPTION2);
break;
default:
TLS_DBGPRT_ERR("uart0 rts afsel config error!");
break;
}
}
void wm_uart0_cts_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_14:
tls_io_cfg_set(WM_IO_PA_14, WM_IO_OPTION1);
break;
case WM_IO_PB_05:
tls_io_cfg_set(WM_IO_PB_05, WM_IO_OPTION2);
break;
case WM_IO_PB_23:
tls_io_cfg_set(WM_IO_PB_23, WM_IO_OPTION2);
break;
default:
TLS_DBGPRT_ERR("uart0 cts afsel config error!");
break;
}
}
void wm_uart1_tx_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PB_12:
tls_io_cfg_set(WM_IO_PB_12, WM_IO_OPTION1);
break;
case WM_IO_PB_18:
tls_io_cfg_set(WM_IO_PB_18, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("uart1 tx afsel config error!");
break;
}
}
void wm_uart1_rx_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PB_11:
tls_io_cfg_set(WM_IO_PB_11, WM_IO_OPTION1);
tls_bitband_write(HR_GPIOB_DATA_PULLEN, 11, 0);
break;
case WM_IO_PB_17:
tls_io_cfg_set(WM_IO_PB_17, WM_IO_OPTION4);
tls_bitband_write(HR_GPIOB_DATA_PULLEN, 17, 0);
break;
default:
TLS_DBGPRT_ERR("uart1 rx afsel config error!");
break;
}
}
void wm_uart1_rts_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PB_10:
tls_io_cfg_set(WM_IO_PB_10, WM_IO_OPTION1);
break;
default:
TLS_DBGPRT_ERR("uart1 rts afsel config error!");
break;
}
}
void wm_uart1_cts_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PB_09:
tls_io_cfg_set(WM_IO_PB_09, WM_IO_OPTION1);
break;
default:
TLS_DBGPRT_ERR("uart1 cts afsel config error!");
break;
}
}
void wm_uart2_tx_scio_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_01:
tls_io_cfg_set(WM_IO_PA_01, WM_IO_OPTION1);
break;
case WM_IO_PA_11:
tls_io_cfg_set(WM_IO_PA_11, WM_IO_OPTION3);
break;
case WM_IO_PB_02:
tls_io_cfg_set(WM_IO_PB_02, WM_IO_OPTION2);
break;
case WM_IO_PB_20:
tls_io_cfg_set(WM_IO_PB_20, WM_IO_OPTION2);
break;
default:
TLS_DBGPRT_ERR("uart2 tx afsel config error!");
break;
}
}
void wm_uart2_rx_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_00:
tls_io_cfg_set(WM_IO_PA_00, WM_IO_OPTION1);
tls_bitband_write(HR_GPIOA_DATA_PULLEN, 0, 0);
break;
case WM_IO_PA_10:
tls_io_cfg_set(WM_IO_PA_10, WM_IO_OPTION3);
tls_bitband_write(HR_GPIOA_DATA_PULLEN, 10, 0);
break;
case WM_IO_PB_03:
tls_io_cfg_set(WM_IO_PB_03, WM_IO_OPTION2);
tls_bitband_write(HR_GPIOB_DATA_PULLEN, 3, 0);
break;
case WM_IO_PB_19:
tls_io_cfg_set(WM_IO_PB_19, WM_IO_OPTION2);
tls_bitband_write(HR_GPIOB_DATA_PULLEN, 19, 0);
break;
case WM_IO_PB_30:
tls_io_cfg_set(WM_IO_PB_30, WM_IO_OPTION1);
tls_bitband_write(HR_GPIOB_DATA_PULLEN, 30, 0);
break;
default:
TLS_DBGPRT_ERR("uart2 rx afsel config error!");
break;
}
}
void wm_uart2_rts_scclk_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_02:
tls_io_cfg_set(WM_IO_PA_02, WM_IO_OPTION1);
break;
case WM_IO_PA_12:
tls_io_cfg_set(WM_IO_PA_12, WM_IO_OPTION3);
break;
case WM_IO_PB_01:
tls_io_cfg_set(WM_IO_PB_01, WM_IO_OPTION2);
break;
case WM_IO_PB_21:
tls_io_cfg_set(WM_IO_PB_21, WM_IO_OPTION2);
break;
case WM_IO_PB_06:
tls_io_cfg_set(WM_IO_PB_06, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("uart2 rts afsel config error!");
break;
}
}
void wm_uart2_cts_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_03:
tls_io_cfg_set(WM_IO_PA_03, WM_IO_OPTION1);
break;
case WM_IO_PB_28:
tls_io_cfg_set(WM_IO_PB_28, WM_IO_OPTION2);
break;
case WM_IO_PB_00:
tls_io_cfg_set(WM_IO_PB_00, WM_IO_OPTION2);
break;
case WM_IO_PB_22:
tls_io_cfg_set(WM_IO_PB_22, WM_IO_OPTION2);
break;
default:
TLS_DBGPRT_ERR("uart2 cts afsel config error!");
break;
}
}
void wm_i2s_m_ck_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_04:
tls_io_cfg_set(WM_IO_PA_04, WM_IO_OPTION4);
break;
case WM_IO_PA_08:
tls_io_cfg_set(WM_IO_PA_08, WM_IO_OPTION1);
break;
case WM_IO_PB_08:
tls_io_cfg_set(WM_IO_PB_08, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("i2s master ck afsel config error!");
break;
}
}
void wm_i2s_m_ws_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_13:
tls_io_cfg_set(WM_IO_PA_13, WM_IO_OPTION2);
break;
case WM_IO_PA_09:
tls_io_cfg_set(WM_IO_PA_09, WM_IO_OPTION1);
break;
case WM_IO_PB_10:
tls_io_cfg_set(WM_IO_PB_10, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("i2s master ws afsel config error!");
break;
}
}
void wm_i2s_m_do_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_03:
tls_io_cfg_set(WM_IO_PA_03, WM_IO_OPTION4);
break;
case WM_IO_PA_07:
tls_io_cfg_set(WM_IO_PA_07, WM_IO_OPTION1);
break;
case WM_IO_PB_09:
tls_io_cfg_set(WM_IO_PB_09, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("i2s master do afsel config error!");
break;
}
}
void wm_i2s_s_ck_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_15:
tls_io_cfg_set(WM_IO_PA_15, WM_IO_OPTION2);
break;
case WM_IO_PA_11:
tls_io_cfg_set(WM_IO_PA_11, WM_IO_OPTION1);
break;
case WM_IO_PB_15:
tls_io_cfg_set(WM_IO_PB_15, WM_IO_OPTION4);
break;
case WM_IO_PB_04:
tls_io_cfg_set(WM_IO_PB_04, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("i2s slave ck afsel config error!");
break;
}
}
void wm_i2s_s_ws_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_06:
tls_io_cfg_set(WM_IO_PA_06, WM_IO_OPTION2);
break;
case WM_IO_PA_12:
tls_io_cfg_set(WM_IO_PA_12, WM_IO_OPTION1);
break;
case WM_IO_PB_16:
tls_io_cfg_set(WM_IO_PB_16, WM_IO_OPTION4);
break;
case WM_IO_PB_05:
tls_io_cfg_set(WM_IO_PB_05, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("i2s slave ws afsel config error!");
break;
}
}
void wm_i2s_s_di_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_14:
tls_io_cfg_set(WM_IO_PA_14, WM_IO_OPTION2);
break;
case WM_IO_PA_10:
tls_io_cfg_set(WM_IO_PA_10, WM_IO_OPTION1);
break;
case WM_IO_PB_14:
tls_io_cfg_set(WM_IO_PB_14, WM_IO_OPTION4);
break;
case WM_IO_PB_03:
tls_io_cfg_set(WM_IO_PB_03, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("i2s slave di afsel config error!");
break;
}
}
void wm_i2s_mclk_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_02:
tls_io_cfg_set(WM_IO_PA_02, WM_IO_OPTION4);
break;
case WM_IO_PB_28:
tls_io_cfg_set(WM_IO_PB_28, WM_IO_OPTION1);
break;
case WM_IO_PB_31:
tls_io_cfg_set(WM_IO_PB_31, WM_IO_OPTION1);
break;
default:
TLS_DBGPRT_ERR("i2s mclk afsel config error!");
break;
}
}
void wm_i2s_extclk_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_05:
tls_io_cfg_set(WM_IO_PA_05, WM_IO_OPTION4);
break;
default:
TLS_DBGPRT_ERR("i2s extclk afsel config error!");
break;
}
}
void wm_i2c_scl_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_06:
tls_io_cfg_set(WM_IO_PA_06, WM_IO_OPTION1);
break;
case WM_IO_PA_08:
tls_io_cfg_set(WM_IO_PA_08, WM_IO_OPTION4);
break;
case WM_IO_PB_13:
tls_io_cfg_set(WM_IO_PB_13, WM_IO_OPTION3);
break;
case WM_IO_PB_11:
tls_io_cfg_set(WM_IO_PB_11, WM_IO_OPTION4);
break;
case WM_IO_PB_21:
tls_io_cfg_set(WM_IO_PB_21, WM_IO_OPTION3);
break;
default:
TLS_DBGPRT_ERR("i2c scl afsel config error!");
break;
}
}
void wm_i2c_sda_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_15:
tls_io_cfg_set(WM_IO_PA_15, WM_IO_OPTION1);
break;
case WM_IO_PA_07:
tls_io_cfg_set(WM_IO_PA_07, WM_IO_OPTION4);
break;
case WM_IO_PB_14:
tls_io_cfg_set(WM_IO_PB_14, WM_IO_OPTION3);
break;
case WM_IO_PB_12:
tls_io_cfg_set(WM_IO_PB_12, WM_IO_OPTION4);
break;
case WM_IO_PB_22:
tls_io_cfg_set(WM_IO_PB_22, WM_IO_OPTION3);
break;
default:
TLS_DBGPRT_ERR("i2c sda afsel config error!");
break;
}
}
void wm_pwm1_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_00:
tls_io_cfg_set(WM_IO_PA_00, WM_IO_OPTION2);
break;
case WM_IO_PB_18:
tls_io_cfg_set(WM_IO_PB_18, WM_IO_OPTION2);
break;
case WM_IO_PB_05:
tls_io_cfg_set(WM_IO_PB_05, WM_IO_OPTION3);
break;
case WM_IO_PA_05:
tls_io_cfg_set(WM_IO_PA_05, WM_IO_OPTION2);
break;
case WM_IO_PB_19:
tls_io_cfg_set(WM_IO_PB_19, WM_IO_OPTION1);
break;
case WM_IO_PB_30:
tls_io_cfg_set(WM_IO_PB_30, WM_IO_OPTION2);
break;
default:
TLS_DBGPRT_ERR("pwm1 afsel config error!");
break;
}
}
void wm_pwm2_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_01:
tls_io_cfg_set(WM_IO_PA_01, WM_IO_OPTION2);
break;
case WM_IO_PB_17:
tls_io_cfg_set(WM_IO_PB_17, WM_IO_OPTION2);
break;
case WM_IO_PB_04:
tls_io_cfg_set(WM_IO_PB_04, WM_IO_OPTION3);
break;
case WM_IO_PA_07:
tls_io_cfg_set(WM_IO_PA_07, WM_IO_OPTION2);
break;
case WM_IO_PB_13:
tls_io_cfg_set(WM_IO_PB_13, WM_IO_OPTION1);
break;
case WM_IO_PB_20:
tls_io_cfg_set(WM_IO_PB_20, WM_IO_OPTION1);
break;
default:
TLS_DBGPRT_ERR("pwm2 afsel config error!");
break;
}
}
void wm_pwm3_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_02:
tls_io_cfg_set(WM_IO_PA_02, WM_IO_OPTION2);
break;
case WM_IO_PB_16:
tls_io_cfg_set(WM_IO_PB_16, WM_IO_OPTION2);
break;
case WM_IO_PB_03:
tls_io_cfg_set(WM_IO_PB_03, WM_IO_OPTION3);
break;
case WM_IO_PA_08:
tls_io_cfg_set(WM_IO_PA_08, WM_IO_OPTION2);
break;
case WM_IO_PB_21:
tls_io_cfg_set(WM_IO_PB_21, WM_IO_OPTION1);
break;
default:
TLS_DBGPRT_ERR("pwm3 afsel config error!");
break;
}
}
void wm_pwm4_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_03:
tls_io_cfg_set(WM_IO_PA_03, WM_IO_OPTION2);
break;
case WM_IO_PB_15:
tls_io_cfg_set(WM_IO_PB_15, WM_IO_OPTION2);
break;
case WM_IO_PB_02:
tls_io_cfg_set(WM_IO_PB_02, WM_IO_OPTION3);
break;
case WM_IO_PA_09:
tls_io_cfg_set(WM_IO_PA_09, WM_IO_OPTION2);
break;
case WM_IO_PB_22:
tls_io_cfg_set(WM_IO_PB_22, WM_IO_OPTION1);
break;
case WM_IO_PB_06:
tls_io_cfg_set(WM_IO_PB_06, WM_IO_OPTION3);
break;
default:
TLS_DBGPRT_ERR("pwm4 afsel config error!");
break;
}
}
void wm_pwm5_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PA_04:
tls_io_cfg_set(WM_IO_PA_04, WM_IO_OPTION2);
break;
case WM_IO_PB_14:
tls_io_cfg_set(WM_IO_PB_14, WM_IO_OPTION2);
break;
case WM_IO_PB_01:
tls_io_cfg_set(WM_IO_PB_01, WM_IO_OPTION3);
break;
case WM_IO_PA_10:
tls_io_cfg_set(WM_IO_PA_10, WM_IO_OPTION2);
break;
case WM_IO_PB_23:
tls_io_cfg_set(WM_IO_PB_23, WM_IO_OPTION1);
break;
case WM_IO_PB_08:
tls_io_cfg_set(WM_IO_PB_08, WM_IO_OPTION1);
break;
default:
TLS_DBGPRT_ERR("pwm5 afsel config error!");
break;
}
}
void wm_pwmbrk_config(enum tls_io_name io_name)
{
switch(io_name)
{
case WM_IO_PB_24:
tls_io_cfg_set(WM_IO_PB_24, WM_IO_OPTION1);
break;
case WM_IO_PB_29:
tls_io_cfg_set(WM_IO_PB_29, WM_IO_OPTION2);
break;
case WM_IO_PB_00:
tls_io_cfg_set(WM_IO_PB_00, WM_IO_OPTION3);
break;
case WM_IO_PA_11:
tls_io_cfg_set(WM_IO_PA_11, WM_IO_OPTION2);
break;
default:
TLS_DBGPRT_ERR("pwmbrk afsel config error!");
break;
}
}
void wm_swd_config(bool enable)
{
if (enable)
{
tls_io_cfg_set(WM_IO_PB_06, WM_IO_OPTION1);
tls_io_cfg_set(WM_IO_PB_07, WM_IO_OPTION1);
}
else
{
tls_io_cfg_set(WM_IO_PB_06, WM_IO_OPTION5);
tls_io_cfg_set(WM_IO_PB_07, WM_IO_OPTION5);
}
}
void wm_adc_config(u8 Channel)
{
switch(Channel)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
tls_io_cfg_set((enum tls_io_name)(WM_IO_PB_19+Channel), WM_IO_OPTION6);
break;
case 8:
case 9:
case 10:
case 11:
tls_io_cfg_set((enum tls_io_name)(WM_IO_PB_19+(Channel-8)*2), WM_IO_OPTION6);
tls_io_cfg_set((enum tls_io_name)(WM_IO_PB_19+(Channel-8)*2+1), WM_IO_OPTION6);
break;
default:
break;
}
}
void wm_gpio_af_disable(void)
{
tls_reg_write32(HR_GPIOA_AFSEL, 0x0);
tls_reg_write32(HR_GPIOB_AFSEL, BIT(6) | BIT(7));//only enable swd
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,493 @@
/**
* @file wm_hspi.c
*
* @brief High speed spi slave Module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wm_hspi.h"
#include "wm_regs.h"
#include "wm_config.h"
#include "wm_mem.h"
#include "wm_osal.h"
#include "wm_irq.h"
#include "lwip/mem.h"
#include "wm_io.h"
#if TLS_CONFIG_HS_SPI
struct tls_slave_hspi g_slave_hspi;
#define SET_BIT(x) (1UL << (x))
void hspi_free_rxdesc(struct tls_hspi_rx_desc *rx_desc);
void hspi_rx_init(struct tls_slave_hspi *hspi)
{
struct tls_hspi_rx_desc *hspi_rx_desc;
int i;
/* set current availble rx desc pointer */
hspi_rx_desc = (struct tls_hspi_rx_desc *) HSPI_RX_DESC_BASE_ADDR;
hspi->curr_rx_desc = hspi_rx_desc;
/* initialize rx descriptor content */
for (i = 0; i < HSPI_RX_DESC_NUM; i++)
{
/* initialize tx descriptors */
if (i < HSPI_RXBUF_NUM)
{
hspi_rx_desc->valid_ctrl = SET_BIT(31);
hspi_rx_desc->buf_addr = HSPI_RXBUF_BASE_ADDR + i * HSPI_RXBUF_SIZE;
}
else
{
/* indicate this descriptor is can't use by hspi */
hspi_rx_desc->valid_ctrl = 0;
/* point to null */
hspi_rx_desc->buf_addr = 0x0;
}
if (i == (HSPI_RX_DESC_NUM - 1))
{
hspi_rx_desc->next_desc_addr = (u32) HSPI_RX_DESC_BASE_ADDR;
}
else
{
hspi_rx_desc->next_desc_addr = (u32) (hspi_rx_desc + 1);
}
hspi_rx_desc++;
}
}
void hspi_tx_init(struct tls_slave_hspi *hspi)
{
struct tls_hspi_tx_desc *hspi_tx_desc;
int i;
hspi_tx_desc = (struct tls_hspi_tx_desc *) HSPI_TX_DESC_BASE_ADDR;
hspi->curr_tx_desc = hspi_tx_desc;
for (i = 0; i < HSPI_TX_DESC_NUM; i++)
{
hspi_tx_desc->valid_ctrl = 0;
hspi_tx_desc->buf_info = 0;
#if HSPI_TX_MEM_MALLOC
hspi_tx_desc->txbuf_addr = NULL;
hspi_tx_desc->buf_addr[0] = 0;
#else
hspi_tx_desc->buf_addr[0] = HSPI_TXBUF_BASE_ADDR + i * HSPI_TXBUF_SIZE;
#endif
hspi_tx_desc->buf_addr[1] = 0;
hspi_tx_desc->buf_addr[2] = 0;
if (i == (HSPI_TX_DESC_NUM - 1))
{
hspi_tx_desc->next_desc_addr = (u32) HSPI_TX_DESC_BASE_ADDR;
}
else
{
hspi_tx_desc->next_desc_addr = (u32) (hspi_tx_desc + 1);
}
hspi_tx_desc++;
}
}
static int slave_spi_rx_data(struct tls_slave_hspi *hspi)
{
struct tls_hspi_rx_desc *rx_desc;
/* get rx descriptor */
rx_desc = hspi->curr_rx_desc;
while (!(rx_desc->valid_ctrl & SET_BIT(31)))
{
if (hspi->rx_data_callback)
hspi->rx_data_callback((char *) rx_desc->buf_addr);
hspi_free_rxdesc(rx_desc);
rx_desc = (struct tls_hspi_rx_desc *) rx_desc->next_desc_addr;
hspi->curr_rx_desc = rx_desc;
}
return 0;
}
void SDIO_RX_IRQHandler(void)
{
struct tls_slave_hspi *hspi = (struct tls_slave_hspi *) &g_slave_hspi;
#if HSPI_TX_MEM_MALLOC
hspi->txdoneflag = 1;
#endif
if (hspi->tx_data_callback)
hspi->tx_data_callback((char *) hspi->curr_tx_desc->buf_addr);
/* clear interrupt */
tls_reg_write32(HR_SDIO_INT_SRC, SDIO_WP_INT_SRC_DATA_UP);
}
void SDIO_TX_IRQHandler(void)
{
struct tls_slave_hspi *hspi = (struct tls_slave_hspi *) &g_slave_hspi;
//用户模式下,直接给出数据,链表的操作不对外开放,避免造成链表操作错误
if (hspi->ifusermode)
{
slave_spi_rx_data(hspi);
}
else
{
if (hspi->rx_data_callback)
hspi->rx_data_callback((char *) hspi->curr_rx_desc->buf_addr);
}
/* clear interrupt */
tls_reg_write32(HR_SDIO_INT_SRC, SDIO_WP_INT_SRC_DATA_DOWN);
}
void SDIO_TX_CMD_IRQHandler(void)
{
struct tls_slave_hspi *hspi = (struct tls_slave_hspi *) &g_slave_hspi;
if (hspi->rx_cmd_callback)
hspi->rx_cmd_callback((char *) SDIO_CMD_RXBUF_ADDR);
if (hspi->ifusermode) // 用户模式下,数据给出去之后,寄存器由驱动自己操作
{
tls_reg_write32(HR_SDIO_DOWNCMDVALID, 0x1);
}
/* clear interrupt */
tls_reg_write32(HR_SDIO_INT_SRC, SDIO_WP_INT_SRC_CMD_DOWN);
}
void SPI_HS_IRQHandler(void)
{
printf("spi HS irqhandle\n");
}
void hspi_free_rxdesc(struct tls_hspi_rx_desc *rx_desc)
{
rx_desc->valid_ctrl = SET_BIT(31);
/* 设置hspi/sdio tx enable寄存器让sdio硬件知道有可用的tx descriptor */
tls_reg_write32(HR_SDIO_TXEN, SET_BIT(0));
}
void hspi_regs_cfg(void)
{
tls_reg_write32(HR_HSPI_CLEAR_FIFO, 0x1); /* Clear data up&down interrput
*/
tls_reg_write32(HR_HSPI_SPI_CFG, 0); /* CPOL=0, CPHA=0, Small-Endian */
tls_reg_write32(HR_HSPI_MODE_CFG, 0x0);
tls_reg_write32(HR_HSPI_INT_MASK, 0x03);
tls_reg_write32(HR_HSPI_INT_STTS, 0x03);
}
void sdio_init_cis(void)
{
tls_reg_write32(FN0_TPL_FUNCID, 0x000C0221);
tls_reg_write32(FN0_TPL_FUNCE, 0x00000422);
tls_reg_write32(FN0_TPL_FUNCE_MAXBLK, 0x04203208);
tls_reg_write32(FN0_TPL_MANFID_MID, 0x53470296);
tls_reg_write32(FN0_TPL_END, 0x000000ff);
tls_reg_write32(FN1_TPL_FUNCID, 0x000C0221);
tls_reg_write32(FN1_TPL_FUNCE, 0x01012a22);
tls_reg_write32(FN1_TPL_FUNCE_VER, 0x00000011);
tls_reg_write32(FN1_TPL_FUNCE_NSN, 0x02000000);
tls_reg_write32(FN1_TPL_FUNCE_CSASIZE, 0x08000300);
tls_reg_write32(FN1_TPL_FUNCE_OCR, 0x00FF8000);
tls_reg_write32(FN1_TPL_FUNCE_MINPWR, 0x010f0a08);
tls_reg_write32(FN1_TPL_FUNCE_STANDBY, 0x00000101);
tls_reg_write32(FN1_TPL_FUNCE_OPTBW, 0x00000000);
tls_reg_write32(FN1_TPL_FUNCE_NTIMEOUT, 0x00000000);
tls_reg_write32(FN1_TPL_FUNCE_AVGPWR, 0x00000000);
tls_reg_write32(FN1_TPL_FUNCE_AVGPWR + 4, 0x00000000);
tls_reg_write32(FN1_TPL_END, 0x000000ff);
}
void hsdio_regs_cfg(void)
{
u32 v;
sdio_init_cis();
tls_reg_write32(HR_SDIO_CIS0, SDIO_CIS0_ADDR - 0x1000);
tls_reg_write32(HR_SDIO_CIS1, SDIO_CIS1_ADDR - 0x2000);
v = tls_reg_read32(HR_SDIO_CIA);
tls_reg_write32(HR_SDIO_CIA, (v & 0xFFFFF000) | 0x232);
/* set sdio ready */
tls_reg_write32(HR_SDIO_PROG, 0x02FD);
}
/**
* @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 the function.
*/
int tls_slave_spi_init(void)
{
struct tls_slave_hspi *hspi;
hspi = &g_slave_hspi;
memset(hspi, 0, sizeof(struct tls_slave_hspi));
hspi_rx_init(hspi);
hspi_tx_init(hspi);
// tls_set_high_speed_interface_type(HSPI_INTERFACE_SPI);
/* regiseter hspi tx rx cmd interrupt handler */
/* setting hw interrupt module isr enable regiset */
tls_irq_enable(SDIO_TX_DATA_INT);
tls_irq_enable(SDIO_RX_DATA_INT);
tls_irq_enable(SDIO_TX_CMD_INT);
tls_irq_enable(SPI1_INT);
/********************************************
* setting hspi wrapper registers
*********************************************/
/* hspi data down(rx) */
tls_reg_write32(HR_SDIO_TXBD_ADDR, HSPI_RX_DESC_BASE_ADDR);
tls_reg_write32(HR_SDIO_TXBD_LINKEN, 1);
tls_reg_write32(HR_SDIO_TXEN, 1);
/* hspi data up (tx) */
tls_reg_write32(HR_SDIO_RXBD_ADDR, HSPI_TX_DESC_BASE_ADDR);
tls_reg_write32(HR_SDIO_RXBD_LINKEN, 1);
/* hspi cmd down */
tls_reg_write32(HR_SDIO_CMD_ADDR, SDIO_CMD_RXBUF_ADDR);
tls_reg_write32(HR_SDIO_CMD_SIZE, SDIO_CMD_RXBUF_SIZE);
tls_reg_write32(HR_SDIO_DOWNCMDVALID, 0x1);
/* enable sdio module register */
tls_reg_write32(HR_SDIO_INT_MASK, 0x00);
return 0;
}
/**
* @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)
{
if (HSPI_INTERFACE_SPI == type)
{
#if 0
#if (HSPI_IO_REUSE_NUM == 0)
tls_io_cfg_set(WM_IO_PB_14, WM_IO_OPTION1);
tls_io_cfg_set(WM_IO_PB_15, WM_IO_OPTION1);
tls_io_cfg_set(WM_IO_PB_16, WM_IO_OPTION1);
tls_io_cfg_set(WM_IO_PB_17, WM_IO_OPTION1);
tls_io_cfg_set(WM_IO_PB_18, WM_IO_OPTION1);
#else
if(WM_IO_OPTION1 == tls_io_cfg_get(WM_IO_PB_14))
tls_io_cfg_set(WM_IO_PB_14, WM_IO_OPTION5);
if(WM_IO_OPTION1 == tls_io_cfg_get(WM_IO_PB_15))
tls_io_cfg_set(WM_IO_PB_15, WM_IO_OPTION5);
if(WM_IO_OPTION1 == tls_io_cfg_get(WM_IO_PB_16))
tls_io_cfg_set(WM_IO_PB_16, WM_IO_OPTION5);
if(WM_IO_OPTION1 == tls_io_cfg_get(WM_IO_PB_17))
tls_io_cfg_set(WM_IO_PB_17, WM_IO_OPTION5);
if(WM_IO_OPTION1 == tls_io_cfg_get(WM_IO_PB_18))
tls_io_cfg_set(WM_IO_PB_18, WM_IO_OPTION5);
tls_io_cfg_set(WM_IO_PB_08, WM_IO_OPTION2);
tls_io_cfg_set(WM_IO_PB_09, WM_IO_OPTION2);
tls_io_cfg_set(WM_IO_PB_10, WM_IO_OPTION2);
tls_io_cfg_set(WM_IO_PB_11, WM_IO_OPTION2);
tls_io_cfg_set(WM_IO_PB_12, WM_IO_OPTION2);
#endif
#endif
hspi_regs_cfg();
}
else if (HSPI_INTERFACE_SDIO == type)
{
#if 0
if(WM_IO_OPTION1 == tls_io_cfg_get(WM_IO_PB_16)) //HSPI_CK,as sdio need close
tls_io_cfg_set(WM_IO_PB_16, WM_IO_OPTION5);
if(WM_IO_OPTION2 == tls_io_cfg_get(WM_IO_PB_08)) //HSPI_CK,as sdio need close
tls_io_cfg_set(WM_IO_PB_08, WM_IO_OPTION5);
tls_io_cfg_set(WM_IO_PB_08, WM_IO_OPTION3);
tls_io_cfg_set(WM_IO_PB_09, WM_IO_OPTION3);
tls_io_cfg_set(WM_IO_PB_10, WM_IO_OPTION3);
tls_io_cfg_set(WM_IO_PB_11, WM_IO_OPTION3);
tls_io_cfg_set(WM_IO_PB_12, WM_IO_OPTION3);
#if (SDIO_IO_REUSE_NUM == 0)
tls_io_cfg_set(WM_IO_PA_06, WM_IO_OPTION3);
#elif (SDIO_IO_REUSE_NUM == 1)
tls_io_cfg_set(WM_IO_PB_07, WM_IO_OPTION3);
#else
tls_io_cfg_set(WM_IO_PB_13, WM_IO_OPTION4);
#endif
#endif
hsdio_regs_cfg();
}
}
/**
* @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)
{
struct tls_slave_hspi *hspi = &g_slave_hspi;
hspi->ifusermode = ifenable;
if (ifenable)
{
hspi->rx_cmd_callback = NULL;
hspi->rx_data_callback = NULL;
hspi->tx_data_callback = NULL;
}
}
/**
* @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))
{
g_slave_hspi.rx_cmd_callback = rx_cmd_callback;
}
/**
* @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))
{
g_slave_hspi.rx_data_callback = rx_data_callback;
}
/**
* @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))
{
g_slave_hspi.tx_data_callback = tx_data_callback;
}
/**
* @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)
{
struct tls_hspi_tx_desc *tx_desc;
int totallen = len;
int txlen;
if (NULL == txbuf || len <= 0 || len > (HSPI_TXBUF_SIZE * HSPI_TX_DESC_NUM))
{
printf("\nhspi tx param error\n");
return 0;
}
tx_desc = g_slave_hspi.curr_tx_desc;
while (1)
{
// printf("---\n");
if ((tx_desc->valid_ctrl & SET_BIT(31)) == 0)
break;
tls_os_time_delay(1);
}
while (!(tx_desc->valid_ctrl & SET_BIT(31)))
{
txlen = (totallen > HSPI_TXBUF_SIZE) ? HSPI_TXBUF_SIZE : totallen;
#if HSPI_TX_MEM_MALLOC
if (tx_desc->txbuf_addr != NULL)
{
printf("\nhspi txbuf not null,error %x\n", tx_desc->txbuf_addr);
if (tx_desc->txbuf_addr == tx_desc->buf_addr[0])
{
mem_free((void *) tx_desc->txbuf_addr);
tx_desc->txbuf_addr = NULL;
}
else // 不应该出现
{
printf("\nhspi tx mem error\n");
break;
}
}
tx_desc->txbuf_addr = (u32) mem_malloc(txlen + 1);
if (NULL == tx_desc->txbuf_addr)
{
printf("\nhspi tx data malloc error\n");
break;
}
tx_desc->buf_addr[0] = tx_desc->txbuf_addr;
#endif
MEMCPY((char *) tx_desc->buf_addr[0], txbuf, txlen);
tx_desc->buf_info = txlen << 12;
tx_desc->valid_ctrl = SET_BIT(31);
tls_reg_write32(HR_SDIO_RXEN, 0x01);
tx_desc = (struct tls_hspi_tx_desc *) tx_desc->next_desc_addr;
g_slave_hspi.curr_tx_desc = tx_desc;
totallen -= txlen;
if (totallen <= 0)
break;
}
return (len - totallen);
}
#endif

View File

@@ -0,0 +1,319 @@
/**************************************************************************//**
* @file wm_i2c.c
* @author
* @version
* @date
* @brief
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "wm_regs.h"
#include "wm_i2c.h"
#include "wm_cpu.h"
#include "wm_irq.h"
#define I2C_FREQ_MAX (400000)
#define I2C_FREQ_MIN (100000)
#define I2C_WRITE (0x80)
#define I2C_READ (0x00)
typedef struct {
uint8_t addr;
uint8_t dev_addr;
uint8_t state;
uint8_t *buf;
uint16_t len;
uint16_t cnt;
uint8_t cmd;
void (*transfer_done)(void);
} i2c_desc;
enum {
START,
RESTART,
TRANSMIT,
PRERECEIVE,
RECEIVE,
STOP,
DONE,
IDLE,
};
static i2c_desc i2c_transfer;
void tls_i2c_init(u32 freq)
{
u32 div = 0;
tls_sys_clk clk;
if (freq < I2C_FREQ_MIN)
{
freq = I2C_FREQ_MIN;
}
else if (freq > I2C_FREQ_MAX)
{
freq = I2C_FREQ_MAX;
}
tls_sys_clk_get(&clk);
div = (clk.apbclk * 1000000)/(5 * freq) - 1;
tls_reg_write32(HR_I2C_PRER_LO, div & 0xff);
tls_reg_write32(HR_I2C_PRER_HI, (div>>8) & 0xff);
/** enable I2C | Disable Int*/
tls_reg_write32(HR_I2C_CTRL, I2C_CTRL_INT_DISABLE | I2C_CTRL_ENABLE);
tls_irq_enable(I2C_IRQn);
}
/**
* @brief send stop signal
*
*/
void tls_i2c_stop(void)
{
tls_reg_write32(HR_I2C_CR_SR, I2C_CR_STO);
while(tls_reg_read32(HR_I2C_CR_SR) & I2C_SR_TIP);
}
/**
* @brief waiting for ack signal
* @retval
* - \ref WM_FAILED
* - \ref WM_SUCCESS
*/
int tls_i2c_wait_ack(void)
{
u16 errtime=0;
u32 value;
while(tls_reg_read32(HR_I2C_CR_SR) & I2C_SR_TIP);
value = tls_reg_read32(HR_I2C_CR_SR);
while(value & I2C_SR_NAK)
{
errtime ++;
if(errtime > 512)
{
printf("wait ack err\n");
tls_i2c_stop();
return WM_FAILED;
}
value = tls_reg_read32(HR_I2C_CR_SR);
}
return WM_SUCCESS;
}
/**
* @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)
{
tls_reg_write32(HR_I2C_TX_RX, data);
if(ifstart)
tls_reg_write32(HR_I2C_CR_SR, I2C_CR_STA | I2C_CR_WR);
else
tls_reg_write32(HR_I2C_CR_SR, I2C_CR_WR);
while(tls_reg_read32(HR_I2C_CR_SR) & I2C_SR_TIP);
}
/**
* @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)
{
u8 data;
u32 value = I2C_CR_RD;
if(!ifack)
value |= I2C_CR_NAK;
if(ifstop)
value |= I2C_CR_STO;
tls_reg_write32(HR_I2C_CR_SR, value);
/** Waiting finish */
while(tls_reg_read32(HR_I2C_CR_SR) & I2C_SR_TIP);
data = tls_reg_read32(HR_I2C_TX_RX);
return data;
}
/**
* @brief start write 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)
{
if (buf == NULL)
{
return WM_FAILED;
}
I2C->TX_RX = devaddr;
i2c_transfer.dev_addr = devaddr;
i2c_transfer.state = START;
i2c_transfer.cmd = I2C_WRITE;
i2c_transfer.buf = buf;
i2c_transfer.len = len;
i2c_transfer.cnt = 0;
i2c_transfer.addr = wordaddr;
I2C->CR_SR = I2C_CR_STA | I2C_CR_WR;
return WM_SUCCESS;
}
/**
* @brief start read 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_read_it(uint8_t devaddr, uint8_t wordaddr, uint8_t * buf, uint16_t len)
{
if (buf == NULL)
{
return WM_FAILED;
}
I2C->TX_RX = devaddr;
i2c_transfer.dev_addr = devaddr;
i2c_transfer.state = START;
i2c_transfer.cmd = I2C_READ;
i2c_transfer.buf = buf;
i2c_transfer.len = len;
i2c_transfer.cnt = 0;
i2c_transfer.addr = wordaddr;
I2C->CR_SR = I2C_CR_STA | I2C_CR_WR;
return WM_SUCCESS;
}
/**
* @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))
{
i2c_transfer.transfer_done = done;
}
void I2C_IRQHandler(void)
{
int i2c_sr;
i2c_sr = I2C->CR_SR;
I2C->CR_SR = 1;
if (i2c_sr & 0x20)
{
printf("I2C AL lost\r\n");
}
if (i2c_sr & 0x01)
{
if ((i2c_sr & 0x80) == 0)
{
switch(i2c_transfer.state)
{
case START:
I2C->TX_RX = i2c_transfer.addr;
I2C->CR_SR = I2C_CR_WR;
if ((i2c_transfer.cmd & I2C_WRITE) == I2C_WRITE)
{
i2c_transfer.state = TRANSMIT;
}
else
{
i2c_transfer.state = RESTART;
}
break;
case RESTART:
I2C->TX_RX = (i2c_transfer.dev_addr | 0x01);
I2C->CR_SR = (I2C_CR_STA | I2C_CR_WR);
i2c_transfer.state = PRERECEIVE;
break;
case TRANSMIT:
I2C->TX_RX = i2c_transfer.buf[i2c_transfer.cnt++];
I2C->CR_SR = I2C_CR_WR;
if (i2c_transfer.cnt == i2c_transfer.len)
{
i2c_transfer.state = STOP;
}
break;
case PRERECEIVE:
i2c_transfer.state = RECEIVE;
I2C->CR_SR = I2C_CR_RD;
break;
case RECEIVE:
i2c_transfer.buf[i2c_transfer.cnt++] = I2C->TX_RX;
if (i2c_transfer.cnt == (i2c_transfer.len - 1))
{
I2C->CR_SR = (I2C_CR_STO | I2C_CR_NAK | I2C_CR_RD);
i2c_transfer.state = STOP;
}
else if (i2c_transfer.len == 1)
{
I2C->CR_SR = (I2C_CR_STO | I2C_CR_NAK | I2C_CR_RD);
i2c_transfer.state = DONE;
if (i2c_transfer.transfer_done)
{
i2c_transfer.transfer_done();
}
}
else
{
I2C->CR_SR = I2C_CR_RD;
}
break;
case STOP:
I2C->CR_SR = I2C_CR_STO;
i2c_transfer.state = DONE;
if (i2c_transfer.transfer_done)
{
i2c_transfer.transfer_done();
}
break;
}
}
else
{
if ((i2c_transfer.state == STOP) && i2c_transfer.cmd != I2C_WRITE)
{
i2c_transfer.buf[i2c_transfer.cnt] = I2C->TX_RX;
i2c_transfer.state = DONE;
if (i2c_transfer.transfer_done)
{
i2c_transfer.transfer_done();
}
}
}
}
// if ((i2c_sr & 0x40) == 0)
// {
// i2c_transfer.state = IDLE;
// }
}
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

View File

@@ -0,0 +1,584 @@
/**************************************************************************//**
* @file wm_i2s.c
* @author
* @version
* @date
* @brief
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
*****************************************************************************/
#define TLS_CONFIG_I2S 1
#if TLS_CONFIG_I2S
#include "wm_i2s.h"
#include "string.h"
#include "wm_debug.h"
#include "wm_irq.h"
#include "wm_config.h"
#include "wm_mem.h"
#define I2S_CLK (160000000)
#define WM_I2S_FIFO_LEN (8)
static tls_i2s_port_t tls_i2s_port;
static void tls_i2s_fill_txfifo(void);
/**
* @brief This function is used to initial i2s port.
* @param[in] opts the i2s setting options,if this param is NULL,this function will use the default options.
* @retval
* - \ref WM_SUCCESS
* - \ref WM_FAILED
*
*/
int tls_i2s_port_init(tls_i2s_options_t *opts)
{
tls_i2s_options_t opt;
tls_i2s_port.regs = I2S;
if(NULL == opts)
{
memset(&opt, 0, sizeof(tls_i2s_options_t));
opt.data_width = I2S_CTRL_DATABIT_16;
opt.format = I2S_CTRL_FORMAT_I2S;
opt.stereo_mono = I2S_CTRL_STERO;
opt.sample_rate = 8000;
opt.tx_en = 1;
tls_i2s_config(&opt);
}
else
{
tls_i2s_config(opts);
}
/* enable i2s interrupt */
NVIC_ClearPendingIRQ(I2S_IRQn);
tls_irq_enable(I2S_INT);
return WM_SUCCESS;
}
/**
* @brief This function is used to initial i2s port.
* @param[in] opts the i2s setting options,if this param is NULL,this function will use the default options.
*
* @retval
*
* @note
*/
void tls_i2s_config(tls_i2s_options_t *opts)
{
tls_i2s_port.regs->CTRL &= ~(I2S_CTRL_FORMAT_MASK | \
I2S_CTRL_DATABIT_MASK | \
I2S_CTRL_STEREO_MONO_MASK);
tls_i2s_port.regs->CTRL = opts->data_width | opts->format | opts->stereo_mono;
if (opts->rx_en)
{
TLS_I2S_RX_ENABLE();
TLS_I2S_RX_FIFO_CLEAR();
}
if (opts->tx_en)
{
TLS_I2S_TX_ENABLE();
TLS_I2S_TX_FIFO_CLEAR();
}
tls_i2s_set_freq(opts->sample_rate);
}
/**
* @brief
* set the frequency of the i2s port.
*
* @param[in] freq
* the required frequency of the i2s module
*
* @retval
*
*/
void tls_i2s_set_freq(uint32_t freq)
{
uint32_t div;
uint32_t reg;
uint8_t width, stereo;
reg = I2S->CTRL;
width = (((reg>>4)&0x03)+1)<<3;
stereo = tls_bitband_read(HR_I2S_CTRL, I2S_CTRL_STEREO_MONO_Pos) ? 1:2;
div = (I2S_CLK + freq * width * stereo)/(freq * width * stereo) - 1;
*(volatile uint32_t *)HR_CLK_I2S_CTL &= ~0xFF00;
*(volatile uint32_t *)HR_CLK_I2S_CTL |= (uint32_t)div<<8;
}
/**
* @brief
* set the frequency of the i2s port.
*
* @param[in] freq
* the required frequency of the i2s module
* @param[in] exclk
* the frequency of the ext clock
*
* @retval
*
* @note
* this function will be called after tls_i2s_port_init function
*/
void wm_i2s_set_freq_exclk(uint32_t freq, uint32_t exclk)
{
uint32_t div;
uint32_t temp;
uint8_t wdwidth, stereo;
temp = I2S->CTRL;
wdwidth = (((temp>>4)&0x03)+1)<<3;
stereo = tls_bitband_read(HR_I2S_CTRL, 22) ? 1:2;
div = (exclk * 2 + freq * wdwidth * stereo)/(2* freq * wdwidth * stereo) - 1;
*(volatile uint32_t *)0x40000718 &= ~0x3FF00;
*(volatile uint32_t *)0x40000718 |= (uint32_t)div<<8;
*(volatile uint32_t *)0x40000718 |= 0x01;
}
void I2S_IRQHandler(void)
{
uint8_t rx_fifocnt;
/** LZC */
if (tls_bitband_read(HR_I2S_INT_SRC, I2S_FLAG_LZC_Pos) && !tls_bitband_read(HR_I2S_INT_MASK, I2S_FLAG_LZC_Pos))
{
tls_reg_write32(HR_I2S_INT_SRC, I2S_FLAG_LZC);
}
/** RZC */
if (tls_bitband_read(HR_I2S_INT_SRC, I2S_FLAG_RZC_Pos) && !tls_bitband_read(HR_I2S_INT_MASK, I2S_FLAG_RZC_Pos))
{
tls_reg_write32(HR_I2S_INT_SRC, I2S_FLAG_RZC);
}
/** Tx Done*/
if (tls_bitband_read(HR_I2S_INT_SRC, I2S_FLAG_TXDONE_Pos) && !tls_bitband_read(HR_I2S_INT_MASK, I2S_FLAG_TXDONE_Pos))
{
tls_reg_write32(HR_I2S_INT_SRC, I2S_FLAG_TXDONE);
}
/** TxTH*/
if (tls_bitband_read(HR_I2S_INT_SRC, I2S_FLAG_TXTH_Pos)&& !tls_bitband_read(HR_I2S_INT_MASK, I2S_FLAG_TXTH_Pos))
{
tls_reg_write32(HR_I2S_INT_SRC, I2S_FLAG_TXTH);
tls_i2s_fill_txfifo();
}
/** TXOV*/
if (tls_bitband_read(HR_I2S_INT_SRC, I2S_FLAG_TXOV_Pos) && !tls_bitband_read(HR_I2S_INT_MASK, I2S_FLAG_TXOV_Pos))
{
tls_reg_write32(HR_I2S_INT_SRC, I2S_FLAG_TXOV);
}
/** TXUD*/
if (tls_bitband_read(HR_I2S_INT_SRC, I2S_FLAG_TXUD_Pos) && !tls_bitband_read(HR_I2S_INT_MASK, I2S_FLAG_TXUD_Pos))
{
tls_reg_write32(HR_I2S_INT_SRC, I2S_FLAG_TXUD);
}
/** Rx Done*/
if (tls_bitband_read(HR_I2S_INT_SRC, I2S_FLAG_RXDONE_Pos) && !tls_bitband_read(HR_I2S_INT_MASK, I2S_FLAG_RXDONE_Pos))
{
tls_reg_write32(HR_I2S_INT_SRC, I2S_FLAG_RXDONE);
}
/** RxTH */
if (tls_bitband_read(HR_I2S_INT_SRC, I2S_FLAG_RXTH_Pos)&& !tls_bitband_read(HR_I2S_INT_MASK, I2S_FLAG_RXTH_Pos))
{
tls_reg_write32(HR_I2S_INT_SRC, I2S_FLAG_RXTH);
rx_fifocnt = tls_i2s_port.regs->INT_STATUS & I2S_RX_FIFO_CNT_MASK;
if (tls_i2s_port.rx_buf.buf != NULL)
{
while(rx_fifocnt-- > 0)
{
tls_i2s_port.rx_buf.buf[tls_i2s_port.rx_buf.index] = tls_i2s_port.regs->RX;
tls_i2s_port.rx_buf.index++;
}
if (tls_i2s_port.rx_buf.index >= (tls_i2s_port.rx_buf.len))
{
tls_i2s_port.rx_buf.buf = NULL;
tls_i2s_int_config(I2S_INT_MASK_RXTH, 0);
if (tls_i2s_port.rx_callback != NULL)
{
tls_i2s_port.rx_callback(tls_i2s_port.rx_buf.len);
}
tls_i2s_port.rx_buf.index = 0;
}
}
}
/** RXOV*/
if (tls_bitband_read(HR_I2S_INT_SRC, I2S_FLAG_RXOV_Pos) && !tls_bitband_read(HR_I2S_INT_MASK, I2S_FLAG_RXOV_Pos))
{
tls_reg_write32(HR_I2S_INT_SRC, I2S_FLAG_RXOV);
}
/** RXUD*/
if (tls_bitband_read(HR_I2S_INT_SRC, I2S_FLAG_RXUD_Pos) && !tls_bitband_read(HR_I2S_INT_MASK, I2S_FLAG_RXUD_Pos))
{
tls_reg_write32(HR_I2S_INT_SRC, I2S_FLAG_RXUD);
}
}
/**
* @brief
* This function is used to register i2s rx interrupt.
*
* @param[in] rx_callback
* is the i2s interrupt call back function.
*
* @retval
*
*/
void tls_i2s_rx_register( void (*rx_callback)(u16 len))
{
tls_i2s_port.rx_callback = rx_callback;
}
/**
* @brief
* This function is used to register i2s tx interrupt.
*
* @param[in] tx_callback
* is the i2s interrupt call back function.
*
* @retval
*
*/
void tls_i2s_tx_register(void (* tx_callback)(u16 len))
{
tls_i2s_port.tx_callback = tx_callback;
}
static void tls_i2s_fill_txfifo()
{
s8 fifo_left = 0;
if (tls_i2s_port.tx_buf.index < tls_i2s_port.tx_buf.len)
{
fifo_left = I2S_MAX_RXTXFIFO_LEVEL - ((tls_i2s_port.regs->INT_STATUS & I2S_TX_FIFO_CNT_MASK)>>4);
while (fifo_left--)
{
tls_i2s_port.regs->TX = *(uint32_t *)(tls_i2s_port.tx_buf.buf + tls_i2s_port.tx_buf.index);
tls_i2s_port.tx_buf.index ++;
}
if(tls_i2s_port.tx_buf.index >= tls_i2s_port.tx_buf.len)
{
while((tls_i2s_port.regs->INT_STATUS & I2S_TX_FIFO_CNT_MASK)>>4);
if(tls_i2s_port.tx_sem)
{
memset(&tls_i2s_port.tx_buf, 0, sizeof(tls_i2s_buf));
tls_os_sem_release(tls_i2s_port.tx_sem);
return;
}
if (tls_i2s_port.tx_callback)
{
tls_i2s_port.tx_callback(tls_i2s_port.tx_buf.len);
}
}
}
}
/**
* @brief
* This function is used to transfer data in blocking mode.
*
* @param[in] buf
* pointer to the transfering data.
*
* @param[in] len
* is the data length.
*
* @retval
*
*/
int tls_i2s_tx_block(uint32_t *buf, uint16_t len)
{
uint8_t err;
err = tls_os_sem_create(&tls_i2s_port.tx_sem, 0);
if (err != TLS_OS_SUCCESS)
{
TLS_DBGPRT_ERR("\ni2s tx sem create fail\n");
return WM_FAILED;
}
TLS_I2S_TX_FIFO_CLEAR();
tls_reg_write32(HR_I2S_INT_SRC, 0x1FF);
NVIC_ClearPendingIRQ(I2S_IRQn);
tls_i2s_port.tx_buf.buf = buf;
tls_i2s_port.tx_buf.len = len;
tls_i2s_port.tx_buf.index = 0;
tls_i2s_set_txth(5);
tls_i2s_int_config(I2S_INT_MASK_TXTH, 1);
TLS_I2S_TX_ENABLE();
TLS_I2S_ENABLE();
tls_os_sem_acquire(tls_i2s_port.tx_sem, 0);
tls_os_sem_delete(tls_i2s_port.tx_sem);
tls_i2s_port.tx_sem = NULL;
TLS_I2S_TX_DISABLE();
return WM_SUCCESS;
}
/**
* @brief
* This function is used to transfer data in non blocking mode.
*
* @param[in] buf
* is a buf for user data.
*
* @param[in] len
* is the data length.
*
* @param[in] tx_callback
* a function pointer,which will be called when the designated data sent
*
* @retval
*
* @note the \ref len in words
*/
int tls_i2s_tx_nonblock(uint32_t *buf, uint16_t len, void (*tx_callback)(u16 len))
{
tls_i2s_port.tx_buf.buf = (uint32_t *)buf;
tls_i2s_port.tx_buf.len = len;
tls_i2s_port.tx_buf.index = 0;
tls_i2s_set_txth(5);
tls_i2s_int_config(I2S_INT_MASK_TXTH, 1);
tls_i2s_tx_register( tx_callback);
TLS_I2S_TX_FIFO_CLEAR();
TLS_I2S_TX_ENABLE();
TLS_I2S_ENABLE();
return WM_SUCCESS;
}
/**
* @brief
* This function is used to receiver data in non blocking mode.
*
* @param[in] buf
* the buffer for storing the received data.
*
* @param[in] len
* the length of the data will be receiving
*
* @param[in] rx_callback
* a function pointer,which will be called when the demanded data have been received
*
* @retval
*
*/
int tls_i2s_rx_nonblock(uint32_t *buf, uint16_t len, void (*rx_callback)(u16 len))
{
tls_i2s_port.rx_buf.buf = buf;
tls_i2s_port.rx_buf.len = len;
tls_i2s_port.rx_buf.index = 0;
tls_i2s_set_rxth(5);
tls_i2s_int_config(I2S_INT_MASK_RXTH, 1);
tls_i2s_rx_register( rx_callback);
TLS_I2S_RX_FIFO_CLEAR();
NVIC_ClearPendingIRQ(I2S_IRQn);
TLS_I2S_RX_ENABLE();
TLS_I2S_ENABLE();
return WM_SUCCESS;
}
/**
* @brief
* This function is used to the tx DMA configuration of the I2S module.
*
* @param[in] dma_channel
* the free dma channel number which returned by calling function tls_dma_request()
*
* @param[in] addr
* point to the data buffer will be sent
*
* @param[in] len
* length of the data to be transfered in bytes
*
* @retval
*/
void tls_i2s_tx_dma_config(uint8_t dma_channel, uint32_t * addr, uint16_t len)
{
struct tls_dma_descriptor DmaDesc;
TLS_I2S_TX_DISABLE();
TLS_I2S_TX_FIFO_CLEAR();
/** Mask i2s txth interrupt*/
tls_i2s_set_txth(4);
tls_i2s_int_config(I2S_INT_MASK_TXTH, 0);
DmaDesc.src_addr = (unsigned int) addr;
DmaDesc.dest_addr = (unsigned int)HR_I2S_TX;
DmaDesc.dma_ctrl = TLS_DMA_DESC_CTRL_SRC_ADD_INC | TLS_DMA_DESC_CTRL_DATA_SIZE_WORD |
(len << 7);
DmaDesc.valid = TLS_DMA_DESC_VALID;
DmaDesc.next = NULL;
tls_dma_start(dma_channel, &DmaDesc, 0);
}
/**
* @brief
* datas transmit throuth DMA
*
* @param[in] addr
* point to the data buffer will be sent
* @param[in] len
* length of the data to be transfered in bytes
* @param[in] callback
* the callback function when datas transfer finished
*
* @retval
*
* @note the \ref len in bytes
*/
int tls_i2s_tx_dma(uint32_t * addr, uint16_t len, tls_i2s_callback callback)
{
uint8_t tx_channel;
TLS_I2S_TX_FIFO_CLEAR();
tls_reg_write32(HR_I2S_INT_SRC, 0x1FF);
NVIC_ClearPendingIRQ(I2S_IRQn);
TLS_I2S_TX_FIFO_CLEAR();
tx_channel = tls_dma_request(WM_I2S_TX_DMA_CHANNEL, TLS_DMA_FLAGS_CHANNEL_SEL(TLS_DMA_SEL_I2S_TX) | TLS_DMA_FLAGS_HARD_MODE);
if (tx_channel == 0)
{
return WM_FAILED;
}
if (tls_dma_stop(tx_channel))
{
return WM_FAILED;
}
tls_i2s_tx_dma_config(tx_channel, addr, len);
tls_dma_irq_register(tx_channel, callback, NULL, TLS_DMA_IRQ_TRANSFER_DONE);
TLS_I2S_TXDMA_ENABLE();
TLS_I2S_TX_ENABLE();
TLS_I2S_ENABLE();
return WM_SUCCESS;
}
/**
* @brief
* This function is used to the rx DMA configuration of the I2S module.
*
* @param[in] addr
* point to the storge buffer of the received data
*
* @param[in] len
* the storge buffer length in bytes
*
* @retval
*/
void tls_i2s_rx_dma_config(uint8_t dma_channel, uint32_t * addr, uint16_t len)
{
struct tls_dma_descriptor DmaDesc;
tls_i2s_int_config(I2S_INT_MASK_RXTH, 0);
TLS_I2S_RX_DISABLE();
TLS_I2S_RXDMA_DISABLE();
TLS_I2S_RX_FIFO_CLEAR();
/** Mask i2s rxth interrupt*/
tls_i2s_set_rxth(4);
tls_i2s_int_config(I2S_INT_MASK_RXTH, 0);
DmaDesc.src_addr = (int)HR_I2S_RX;
DmaDesc.dest_addr = (int)addr;
DmaDesc.dma_ctrl = TLS_DMA_DESC_CTRL_DEST_ADD_INC | TLS_DMA_DESC_CTRL_DATA_SIZE_WORD |
(len << 7);
DmaDesc.valid = TLS_DMA_DESC_VALID;
DmaDesc.next = NULL;
tls_dma_start(dma_channel, &DmaDesc, 0);
}
int tls_i2s_rx_dma(uint32_t * addr, uint16_t len, tls_i2s_callback callback)
{
uint8_t rx_channel;
rx_channel = tls_dma_request(WM_I2S_RX_DMA_CHANNEL, TLS_DMA_FLAGS_CHANNEL_SEL(TLS_DMA_SEL_I2S_RX) | TLS_DMA_FLAGS_HARD_MODE);
if (rx_channel == 0)
{
return WM_FAILED;
}
if (tls_dma_stop(rx_channel))
{
return WM_FAILED;
}
tls_i2s_rx_dma_config(rx_channel, addr, len);
tls_dma_irq_register(rx_channel, callback, NULL, TLS_DMA_IRQ_TRANSFER_DONE);
TLS_I2S_RXDMA_ENABLE();
NVIC_ClearPendingIRQ(I2S_IRQn);
TLS_I2S_RX_ENABLE();
TLS_I2S_ENABLE();
return WM_SUCCESS;
}
#if 1
uint8_t tst_flag = 0;
void tls_i2s_tx_dma_callback()
{
I2S->TX = 0x00;
while(!tls_bitband_read(HR_I2S_INT_SRC, 7));
TLS_I2S_TX_DISABLE();
DMA_CHNLCTRL_REG(WM_I2S_TX_DMA_CHANNEL) |= DMA_CHNL_CTRL_CHNL_OFF;
tls_dma_free(WM_I2S_TX_DMA_CHANNEL);
tst_flag = 1;
}
void tls_i2s_rx_dma_callback()
{
TLS_I2S_RX_DISABLE();
DMA_CHNLCTRL_REG(WM_I2S_RX_DMA_CHANNEL) |= DMA_CHNL_CTRL_CHNL_OFF;
tls_dma_free(WM_I2S_RX_DMA_CHANNEL);
tst_flag = 1;
}
void tls_i2s_rx_callback()
{
TLS_I2S_RX_DISABLE();
tst_flag = 1;
}
void tls_i2s_test()
{
uint32_t *ptr = NULL;
uint32_t len;
uint32_t * i2s_tx_test = tls_mem_alloc(1024);
tls_i2s_port.opts.data_width = I2S_CTRL_DATABIT_16;
tls_i2s_port.opts.format = I2S_CTRL_FORMAT_I2S;
tls_i2s_port.opts.tx_en = 1;
tls_i2s_port.opts.sample_rate = 8000;
tls_i2s_port.opts.stereo_mono = I2S_CTRL_STERO;
tls_i2s_port_init(&tls_i2s_port.opts);
if (i2s_tx_test == NULL)
{
return;
}
ptr = i2s_tx_test;
for (len = 0; len < 256; len++)
{
*ptr++ = 0xABCD0200 + len;
}
i2s_tx_test[255] = 0xABCD02FA;
tls_i2s_tx_dma(i2s_tx_test, 1024,tls_i2s_tx_dma_callback);
while(!tst_flag);
tst_flag = 0;
tls_i2s_tx_dma(i2s_tx_test, 1024,tls_i2s_tx_dma_callback);
while(!tst_flag);
tst_flag = 0;
}
#endif
#endif /** TLS_CONFIG_I2S */
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,277 @@
/**
* @file wm_io.c
*
* @brief IO Driver Module
*
* @author lilm
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#include "wm_regs.h"
//#include "wm_osal.h"
#include "wm_io.h"
#include "wm_dbg.h"
#include "tls_common.h"
static void io_cfg_option1(enum tls_io_name name)
{
u8 pin;
u16 offset;
if ( (WM_IO_PB_25 == name) || (WM_IO_PB_26 == name) || (WM_IO_PB_29 == name) )
{
TLS_DBGPRT_IO_ERR("io %u have no option1.\r\n", name);
return;
}
if (name >= WM_IO_PB_00)
{
pin = name - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = name;
offset = 0;
}
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) & (~BIT(pin)));
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) & (~BIT(pin)));
return;
}
static void io_cfg_option2(enum tls_io_name name)
{
u8 pin;
u16 offset;
if ( (WM_IO_PB_13 == name) || (WM_IO_PB_27 == name) ||
(WM_IO_PB_31 == name) )
{
TLS_DBGPRT_IO_ERR("io %u have no option2.\r\n", name);
return;
}
if (name >= WM_IO_PB_00)
{
pin = name - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = name;
offset = 0;
}
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) & (~BIT(pin)));
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) | BIT(pin));
return;
}
static void io_cfg_option3(enum tls_io_name name)
{
u8 pin;
u16 offset;
if ( (name == WM_IO_PB_19) || (name == WM_IO_PB_20) ||
(name >= WM_IO_PB_23) || (name == WM_IO_PA_00) ||
(name == WM_IO_PA_07) ||
((name >= WM_IO_PA_13) && (name <= WM_IO_PA_15)) )
{
TLS_DBGPRT_IO_ERR("io %u have no option3.\r\n", name);
return;
}
if (name >= WM_IO_PB_00)
{
pin = name - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = name;
offset = 0;
}
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) | BIT(pin));
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) & (~BIT(pin)));
return;
}
static void io_cfg_option4(enum tls_io_name name)
{
u8 pin;
u16 offset;
if( (name == WM_IO_PA_00) || (name == WM_IO_PA_01) ||
(name == WM_IO_PA_06) ||
((name >= WM_IO_PA_13) && (name <= WM_IO_PA_15)) ||
((name >= WM_IO_PB_00) && (name <= WM_IO_PB_02)) ||
(name >= WM_IO_PB_19) )
{
TLS_DBGPRT_IO_ERR("io %u have no option4.\r\n", name);
return;
}
if (name >= WM_IO_PB_00)
{
pin = name - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = name;
offset = 0;
}
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) | BIT(pin));
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) | BIT(pin));
return;
}
static void io_cfg_option5(enum tls_io_name name)
{
u8 pin;
u16 offset;
if (name >= WM_IO_PB_00)
{
pin = name - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = name;
offset = 0;
}
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) & (~BIT(pin))); /* disable gpio function */
return;
}
static void io_cfg_option6(enum tls_io_name name)
{
u8 pin;
u16 offset;
if( ((name >= WM_IO_PB_06)&&(name <= WM_IO_PB_18)) ||
((name >= WM_IO_PB_29)&&(name <= WM_IO_PB_31)))
{
TLS_DBGPRT_IO_ERR("io %u have no option6.\r\n", name);
return;
}
if (name >= WM_IO_PB_00)
{
pin = name - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = name;
offset = 0;
}
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) & (~BIT(pin))); /* disable gpio function */
tls_reg_write32(HR_GPIO_DIR + offset, tls_reg_read32(HR_GPIO_DIR + offset) & (~BIT(pin)));
tls_reg_write32(HR_GPIO_PULL_EN + offset, tls_reg_read32(HR_GPIO_PULL_EN + offset) & (~BIT(pin)));
return;
}
/**
* @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)
{
if (WM_IO_OPTION1 == option)
io_cfg_option1(name);
else if (WM_IO_OPTION2 == option)
io_cfg_option2(name);
else if (WM_IO_OPTION3 == option)
io_cfg_option3(name);
else if (WM_IO_OPTION4 == option)
io_cfg_option4(name);
else if (WM_IO_OPTION5 == option)
io_cfg_option5(name);
else if (WM_IO_OPTION6 == option)
io_cfg_option6(name);
else
TLS_DBGPRT_IO_ERR("invalid io option.\r\n");
return;
}
/**
* @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)
{
u8 pin;
u16 offset;
u32 afsel,afs1,afs0,dir,pullen;
if (name >= WM_IO_PB_00)
{
pin = name - WM_IO_PB_00;
offset = TLS_IO_AB_OFFSET;
}
else
{
pin = name;
offset = 0;
}
afsel = tls_reg_read32(HR_GPIO_AF_SEL + offset);
afs1 = tls_reg_read32(HR_GPIO_AF_S1 + offset);
afs0 = tls_reg_read32(HR_GPIO_AF_S0 + offset);
dir = tls_reg_read32(HR_GPIO_DIR + offset);
pullen = tls_reg_read32(HR_GPIO_PULL_EN + offset);
if(afsel&BIT(pin))
{
if((0==(afs1&BIT(pin))) && (0==(afs0&BIT(pin))))
return WM_IO_OPTION1;
else if((0==(afs1&BIT(pin))) && (afs0&BIT(pin)))
return WM_IO_OPTION2;
else if((afs1&BIT(pin)) && (0==(afs0&BIT(pin))))
return WM_IO_OPTION3;
else if((afs1&BIT(pin)) && (afs0&BIT(pin)))
return WM_IO_OPTION4;
}
else
{
if((!(dir&BIT(pin))) && (pullen&BIT(pin)))
return WM_IO_OPTION6;
else
return WM_IO_OPTION5;
}
return 0;
}

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