mirror of
https://github.com/dgoodlad/rtl8710-sdk.git
synced 2026-07-14 23:35:41 +00:00
Import required parts of ameba sdk 4.0b
This commit is contained in:
parent
2d21e45bba
commit
7319ca1482
737 changed files with 304718 additions and 0 deletions
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/image/ram_1.p.bin
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/image/ram_1.p.bin
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/image/ram_1.r.bin
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/image/ram_1.r.bin
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_dct.a
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_dct.a
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_http.a
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_http.a
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_mdns.a
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_mdns.a
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_platform.a
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_platform.a
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_rtlstd.a
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_rtlstd.a
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_websocket.a
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_websocket.a
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_wlan.a
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_wlan.a
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_wps.a
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_wps.a
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_xmodem.a
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_xmodem.a
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/va0/rom.a
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/va0/rom.a
vendored
Normal file
Binary file not shown.
247
vendor/sdk/component/soc/realtek/8195a/misc/driver/console_hs_uart.c
vendored
Normal file
247
vendor/sdk/component/soc/realtek/8195a/misc/driver/console_hs_uart.c
vendored
Normal file
|
|
@ -0,0 +1,247 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include <platform_opts.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "semphr.h"
|
||||
#include "device.h"
|
||||
#include "serial_api.h"
|
||||
#include "at_cmd/log_service.h"
|
||||
#include "osdep_service.h"
|
||||
#include "serial_ex_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
char hs_uart_ready = 0; // used to switch between loguart and high speed uart
|
||||
// 0: loguart
|
||||
// 1: highspeed uart
|
||||
|
||||
// select uart tx/rx pin with gpio interrupt function
|
||||
#define UART_TX PA_7
|
||||
#define UART_RX PA_6
|
||||
|
||||
#define KEY_NL 0xa // '\n'
|
||||
#define KEY_ENTER 0xd // '\r'
|
||||
#define KEY_BS 0x8
|
||||
#define KEY_ESC 0x1B
|
||||
#define KEY_LBRKT 0x5B
|
||||
#define STR_END_OF_MP_FORMAT "\r\n\r\r#"
|
||||
|
||||
|
||||
#define CMD_HISTORY_LEN 4 // max number of executed command saved
|
||||
extern char log_buf[LOG_SERVICE_BUFLEN];
|
||||
extern xSemaphoreHandle log_rx_interrupt_sema;
|
||||
char cmd_history[CMD_HISTORY_LEN][LOG_SERVICE_BUFLEN];
|
||||
static unsigned int cmd_history_count = 0;
|
||||
|
||||
serial_t loguart_sobj;
|
||||
//_sema at_printf_sema;
|
||||
_sema hs_uart_dma_tx_sema;
|
||||
|
||||
#define HS_UART_USE_DMA_TX 1
|
||||
|
||||
void hs_uart_put_char(u8 c){
|
||||
serial_putc(&loguart_sobj, c);
|
||||
}
|
||||
|
||||
void hs_uart_send_string(char *str)
|
||||
{
|
||||
unsigned int i=0;
|
||||
while (str[i] != '\0') {
|
||||
serial_putc(&loguart_sobj, str[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
#if UART_AT_USE_DMA_TX
|
||||
static void hs_uart_send_buf_done(uint32_t id)
|
||||
{
|
||||
//serial_t *sobj = (serial_t *)id;
|
||||
|
||||
rtw_up_sema_from_isr(&uart_at_dma_tx_sema);
|
||||
}
|
||||
#endif
|
||||
|
||||
void hs_uart_send_buf(u8 *buf, u32 len)
|
||||
{
|
||||
unsigned char *st_p=buf;
|
||||
if(!len || (!buf)){
|
||||
return;
|
||||
}
|
||||
#if UART_AT_USE_DMA_TX
|
||||
int ret;
|
||||
while(rtw_down_sema(&uart_at_dma_tx_sema) == _TRUE){
|
||||
ret = serial_send_stream_dma(&loguart_sobj, st_p, len);
|
||||
if(ret != HAL_OK){
|
||||
rtw_up_sema(&uart_at_dma_tx_sema);
|
||||
return;
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else
|
||||
while(len){
|
||||
serial_putc(&loguart_sobj, *st_p);
|
||||
st_p++;
|
||||
len--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void hs_uart_irq(uint32_t id, SerialIrq event)
|
||||
{
|
||||
serial_t *sobj = (serial_t *)id;
|
||||
unsigned char rc=0;
|
||||
static unsigned char temp_buf[LOG_SERVICE_BUFLEN] = "\0";
|
||||
static unsigned char combo_key = 0;
|
||||
static unsigned short buf_count = 0;
|
||||
static unsigned char key_enter = 0;
|
||||
static char cmd_history_index = 0;
|
||||
if(event == RxIrq) {
|
||||
rc = serial_getc(sobj);
|
||||
|
||||
if(key_enter && rc == KEY_NL){
|
||||
//serial_putc(sobj, rc);
|
||||
return;
|
||||
}
|
||||
|
||||
if(rc == KEY_ESC){
|
||||
combo_key = 1;
|
||||
}else if(combo_key == 1){
|
||||
if(rc == KEY_LBRKT)
|
||||
combo_key = 2;
|
||||
else
|
||||
combo_key = 0;
|
||||
}else if(combo_key == 2){
|
||||
if(rc == 'A' || rc == 'B'){ // UP or Down
|
||||
if(rc == 'A'){
|
||||
cmd_history_index--;
|
||||
if(cmd_history_index < 0)
|
||||
cmd_history_index = (cmd_history_count>CMD_HISTORY_LEN)?CMD_HISTORY_LEN-1:(cmd_history_count-1)%CMD_HISTORY_LEN;
|
||||
}else{
|
||||
cmd_history_index++;
|
||||
if(cmd_history_index > (cmd_history_count>CMD_HISTORY_LEN?CMD_HISTORY_LEN-1:(cmd_history_count-1)%CMD_HISTORY_LEN))
|
||||
cmd_history_index = 0;
|
||||
}
|
||||
|
||||
if(cmd_history_count > 0){
|
||||
buf_count = strlen(temp_buf);
|
||||
rtw_memset(temp_buf,'\0',buf_count);
|
||||
while(--buf_count >= 0){
|
||||
serial_putc(sobj, KEY_BS);
|
||||
serial_putc(sobj, ' ');
|
||||
serial_putc(sobj, KEY_BS);
|
||||
}
|
||||
hs_uart_send_string(cmd_history[cmd_history_index%CMD_HISTORY_LEN]);
|
||||
strcpy(temp_buf, cmd_history[cmd_history_index%CMD_HISTORY_LEN]);
|
||||
buf_count = strlen(temp_buf);
|
||||
}
|
||||
}
|
||||
|
||||
// exit combo
|
||||
combo_key = 0;
|
||||
}
|
||||
else if(rc == KEY_ENTER){
|
||||
key_enter = 1;
|
||||
if(buf_count>0){
|
||||
serial_putc(sobj, KEY_NL);
|
||||
serial_putc(sobj, KEY_ENTER);
|
||||
rtw_memset(log_buf,'\0',LOG_SERVICE_BUFLEN);
|
||||
strncpy(log_buf,(char *)&temp_buf[0],buf_count);
|
||||
rtw_up_sema_from_isr(&log_rx_interrupt_sema);
|
||||
rtw_memset(temp_buf,'\0',buf_count);
|
||||
|
||||
/* save command */
|
||||
rtw_memset(cmd_history[((cmd_history_count)%CMD_HISTORY_LEN)], '\0', buf_count+1);
|
||||
strcpy(cmd_history[((cmd_history_count++)%CMD_HISTORY_LEN)], log_buf);
|
||||
cmd_history_index = cmd_history_count%CMD_HISTORY_LEN;
|
||||
//cmd_history_count++;
|
||||
buf_count=0;
|
||||
}else{
|
||||
hs_uart_send_string(STR_END_OF_MP_FORMAT);
|
||||
}
|
||||
}
|
||||
else if(rc == KEY_BS){
|
||||
if(buf_count>0){
|
||||
buf_count--;
|
||||
temp_buf[buf_count] = '\0';
|
||||
|
||||
serial_putc(sobj, rc);
|
||||
serial_putc(sobj, ' ');
|
||||
serial_putc(sobj, rc);
|
||||
}
|
||||
}
|
||||
else{
|
||||
/* cache input characters */
|
||||
if(buf_count < (LOG_SERVICE_BUFLEN - 1)){
|
||||
temp_buf[buf_count] = rc;
|
||||
buf_count++;
|
||||
serial_putc(sobj, rc);
|
||||
key_enter = 0;
|
||||
}
|
||||
else if(buf_count == (LOG_SERVICE_BUFLEN - 1)){
|
||||
temp_buf[buf_count] = '\0';
|
||||
|
||||
hs_uart_send_string("\r\nERROR:exceed size limit"STR_END_OF_ATCMD_RET);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void console_init_hs_uart(void)
|
||||
{
|
||||
serial_init(&loguart_sobj,UART_TX,UART_RX);
|
||||
serial_baud(&loguart_sobj,38400);
|
||||
serial_format(&loguart_sobj, 8, ParityNone, 1);
|
||||
|
||||
#if UART_AT_USE_DMA_TX
|
||||
rtw_init_sema(&hs_uart_dma_tx_sema, 1);
|
||||
serial_send_comp_handler(&loguart_sobj, (void*)hs_uart_send_buf_done, (uint32_t)&loguart_sobj);
|
||||
#endif
|
||||
|
||||
serial_irq_handler(&loguart_sobj, hs_uart_irq, (uint32_t)&loguart_sobj);
|
||||
serial_irq_set(&loguart_sobj, RxIrq, 1);
|
||||
|
||||
for(char i=0; i<CMD_HISTORY_LEN; i++)
|
||||
memset(cmd_history[i], '\0', LOG_SERVICE_BUFLEN);
|
||||
|
||||
/* indicate low level layer that hs uart is ready */
|
||||
hs_uart_ready = 1;
|
||||
}
|
||||
|
||||
int use_mode;
|
||||
|
||||
|
||||
VOID HalSerialPutcRtl8195a(
|
||||
IN u8 c
|
||||
)
|
||||
{
|
||||
extern char hs_uart_ready;
|
||||
extern void hs_uart_put_char(u8 c);
|
||||
if(hs_uart_ready)
|
||||
hs_uart_put_char(c);
|
||||
}
|
||||
|
||||
void console_init(void)
|
||||
{
|
||||
sys_log_uart_off();
|
||||
console_init_hs_uart();
|
||||
|
||||
#if !TASK_SCHEDULER_DISABLED
|
||||
RtlConsolInitRam((u32)RAM_STAGE,(u32)0,(VOID*)NULL);
|
||||
#else
|
||||
RtlConsolInitRam((u32)ROM_STAGE,(u32)0,(VOID*)NULL);
|
||||
#endif
|
||||
|
||||
#if BUFFERED_PRINTF
|
||||
rtl_printf_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
166
vendor/sdk/component/soc/realtek/8195a/misc/driver/console_i2c.c
vendored
Normal file
166
vendor/sdk/component/soc/realtek/8195a/misc/driver/console_i2c.c
vendored
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
#include <platform_opts.h>
|
||||
#include "serial_api.h"
|
||||
#include "serial_ex_api.h"
|
||||
#include "PinNames.h"
|
||||
#include "i2c_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "ex_api.h"
|
||||
|
||||
#define MBED_I2C_MTR_SDA PB_3 //i2c3
|
||||
#define MBED_I2C_MTR_SCL PB_2
|
||||
|
||||
#define UART_BAUDRATE 115200
|
||||
|
||||
#define MBED_I2C_SLAVE_ADDR0 0x4D // 0x9A //
|
||||
#define MBED_I2C_BUS_CLK 500000 //hz *Remind that in baud rate 9600 or 19200, 100000hz is suitable*
|
||||
|
||||
static i2c_t i2cmaster;
|
||||
|
||||
#define I2C_DATA_LENGTH 2
|
||||
static char i2cdatardsrc[I2C_DATA_LENGTH];
|
||||
static char i2cdatarddst[I2C_DATA_LENGTH];
|
||||
|
||||
const u8 DLL = 921600/UART_BAUDRATE;
|
||||
|
||||
char ctrl_initial_1[2] = {0x03 << 3,0x80};
|
||||
char ctrl_initial_2[2] = {0x00 << 3,921600/UART_BAUDRATE};
|
||||
char ctrl_initial_3[2] = {0x01 << 3,0x00};
|
||||
char ctrl_initial_4[2] = {0x03 << 3,0xbf};
|
||||
char ctrl_initial_5[2] = {0x02 << 3,0x10};
|
||||
char ctrl_initial_6[2] = {0x03 << 3,0x03};
|
||||
char ctrl_initial_7[2] = {0x02 << 3,0x06};
|
||||
char ctrl_initial_8[2] = {0x02 << 3,0x01};
|
||||
//end i2c
|
||||
|
||||
|
||||
// Master// Tx
|
||||
#define CLEAR_MST_TXC_FLAG (masterTXC = 0)
|
||||
#define SET_MST_TXC_FLAG (masterTXC = 1)
|
||||
#define WAIT_MST_TXC while(masterTXC == 0){;}
|
||||
|
||||
volatile int masterTXC;
|
||||
static char i2c_ready = 0;
|
||||
|
||||
|
||||
static void i2c_master_rxc_callback(void *userdata)
|
||||
{
|
||||
|
||||
int i2clocalcnt;
|
||||
int result = 0;
|
||||
|
||||
// verify result
|
||||
result = 1;
|
||||
for (i2clocalcnt = 0; i2clocalcnt < I2C_DATA_LENGTH; i2clocalcnt++) {
|
||||
if (i2cdatarddst[i2clocalcnt] != i2cdatardsrc[i2clocalcnt]) {
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void i2c_master_txc_callback(void *userdata)
|
||||
{
|
||||
SET_MST_TXC_FLAG;
|
||||
}
|
||||
|
||||
static void i2c_master_write(void)
|
||||
{
|
||||
|
||||
//DBG_8195A("Mst-W\n");
|
||||
CLEAR_MST_TXC_FLAG;
|
||||
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_1[0], 2, 1);
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_2[0], 2, 1);
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_3[0], 2, 1);
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_4[0], 2, 1);
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_5[0], 2, 1);
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_6[0], 2, 1);
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_7[0], 2, 1);
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_8[0], 2, 1);
|
||||
|
||||
WAIT_MST_TXC;
|
||||
|
||||
}
|
||||
|
||||
static void i2c_master_enable(void)
|
||||
{
|
||||
_memset(&i2cmaster, 0x00, sizeof(i2c_t));
|
||||
i2c_init(&i2cmaster, MBED_I2C_MTR_SDA ,MBED_I2C_MTR_SCL);
|
||||
i2c_frequency(&i2cmaster,MBED_I2C_BUS_CLK);
|
||||
i2c_set_user_callback(&i2cmaster, I2C_RX_COMPLETE, i2c_master_rxc_callback);
|
||||
i2c_set_user_callback(&i2cmaster, I2C_TX_COMPLETE, i2c_master_txc_callback);
|
||||
//i2c_set_user_callback(&i2cmaster, I2C_ERR_OCCURRED, i2c_master_err_callback);
|
||||
|
||||
}
|
||||
|
||||
void i2c_redirect_init(void)
|
||||
{
|
||||
|
||||
// prepare for transmission
|
||||
|
||||
_memset(&i2cdatardsrc[0], 0x00, I2C_DATA_LENGTH);
|
||||
_memset(&i2cdatarddst[0], 0x00, I2C_DATA_LENGTH);
|
||||
|
||||
i2c_ready = 1;
|
||||
|
||||
i2c_master_enable();
|
||||
i2c_master_write();
|
||||
|
||||
}
|
||||
|
||||
static u8 tx_data_i2c[2];
|
||||
static u8 rx_data_i2c[2];
|
||||
|
||||
void i2c_put_char(u8 c){
|
||||
|
||||
_memset(&tx_data_i2c[0],0x00,2);
|
||||
_memset(&rx_data_i2c[0],0x00,2);
|
||||
tx_data_i2c[0] = 0x00 << 3;
|
||||
tx_data_i2c[1] = c;
|
||||
i2c_write(&i2cmaster, 0x4D, &tx_data_i2c[0], 2, 1);
|
||||
i2c_read (&i2cmaster, 0x4D, &rx_data_i2c[0], 2, 1);
|
||||
}
|
||||
|
||||
int use_mode;
|
||||
|
||||
void console_init(void)
|
||||
{
|
||||
i2c_redirect_init();
|
||||
|
||||
if(HalCheckSDramExist()){
|
||||
//DiagPrintf("It's 8195_AM\n");
|
||||
redirect_rom_init();
|
||||
}
|
||||
|
||||
#if !TASK_SCHEDULER_DISABLED
|
||||
RtlConsolInitRam((u32)RAM_STAGE,(u32)0,(VOID*)NULL);
|
||||
#else
|
||||
RtlConsolInitRam((u32)ROM_STAGE,(u32)0,(VOID*)NULL);
|
||||
#endif
|
||||
|
||||
#if BUFFERED_PRINTF
|
||||
rtl_printf_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
VOID HalSerialPutcRtl8195a(IN u8 c){
|
||||
|
||||
u32 CounterIndex = 0;
|
||||
|
||||
extern char i2c_ready;
|
||||
if(i2c_ready)
|
||||
i2c_put_char(c);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
119
vendor/sdk/component/soc/realtek/8195a/misc/driver/low_level_io.c
vendored
Normal file
119
vendor/sdk/component/soc/realtek/8195a/misc/driver/low_level_io.c
vendored
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
#include <stdio.h>
|
||||
#include "hal_api.h"
|
||||
#include "rtl8195a.h"
|
||||
#include "platform_opts.h"
|
||||
|
||||
#if !defined (__ICCARM__)
|
||||
extern u8 RAM_IMG1_VALID_PATTEN[];
|
||||
void *tmp = RAM_IMG1_VALID_PATTEN;
|
||||
#endif
|
||||
|
||||
//for internal test
|
||||
#ifdef USE_MODE
|
||||
extern int use_mode;
|
||||
void mode_init(void){use_mode = 1;}
|
||||
#endif
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
size_t __write(int Handle, const unsigned char * Buf, size_t Bufsize)
|
||||
{
|
||||
int nChars = 0;
|
||||
/* Check for stdout and stderr
|
||||
(only necessary if file descriptors are enabled.) */
|
||||
if (Handle != 1 && Handle != 2)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (/*Empty */; Bufsize > 0; --Bufsize)
|
||||
{
|
||||
DiagPutChar(*Buf++);
|
||||
++nChars;
|
||||
}
|
||||
return nChars;
|
||||
}
|
||||
|
||||
size_t __read(int Handle, unsigned char * Buf, size_t Bufsize)
|
||||
{
|
||||
int nChars = 0;
|
||||
/* Check for stdin
|
||||
(only necessary if FILE descriptors are enabled) */
|
||||
if (Handle != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (/*Empty*/; Bufsize > 0; --Bufsize)
|
||||
{
|
||||
int c = DiagGetChar(_FALSE);
|
||||
if (c < 0)
|
||||
break;
|
||||
*(Buf++) = c;
|
||||
++nChars;
|
||||
}
|
||||
return nChars;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int disablePrintf = FALSE;
|
||||
|
||||
|
||||
__weak VOID HalSerialPutcRtl8195a(IN u8 c){
|
||||
|
||||
u32 CounterIndex = 0;
|
||||
|
||||
if(disablePrintf == TRUE) return;
|
||||
|
||||
while(1) {
|
||||
CounterIndex++;
|
||||
if (CounterIndex >=6540)
|
||||
break;
|
||||
|
||||
if (HAL_UART_READ8(UART_LINE_STATUS_REG_OFF) & 0x60)
|
||||
break;
|
||||
}
|
||||
HAL_UART_WRITE8(UART_TRAN_HOLD_OFF, c);
|
||||
if (c == 0x0a) {
|
||||
HAL_UART_WRITE8(UART_TRAN_HOLD_OFF, 0x0d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include <diag.h>
|
||||
u32
|
||||
DiagPrintf(
|
||||
IN const char *fmt, ...
|
||||
)
|
||||
{
|
||||
if(disablePrintf == TRUE) return _TRUE;
|
||||
|
||||
(void)VSprintf(0, fmt, ((const int *)&fmt)+1);
|
||||
return _TRUE;
|
||||
}
|
||||
|
||||
extern u32 ConfigDebugErr;
|
||||
extern u32 ConfigDebugInfo;
|
||||
extern u32 ConfigDebugWarn;
|
||||
static u32 backupErr;
|
||||
static u32 backupInfo;
|
||||
static u32 backupWarn;
|
||||
void log_uart_enable_printf(void)
|
||||
{
|
||||
disablePrintf = FALSE;
|
||||
ConfigDebugErr = backupErr;
|
||||
ConfigDebugInfo = backupInfo;
|
||||
ConfigDebugWarn = backupWarn;
|
||||
}
|
||||
|
||||
void log_uart_disable_printf(void)
|
||||
{
|
||||
disablePrintf = TRUE;
|
||||
backupErr = ConfigDebugErr;
|
||||
backupInfo = ConfigDebugInfo;
|
||||
backupWarn = ConfigDebugWarn;
|
||||
ConfigDebugErr = 0;
|
||||
ConfigDebugInfo = 0;
|
||||
ConfigDebugWarn = 0;
|
||||
}
|
||||
487
vendor/sdk/component/soc/realtek/8195a/misc/driver/rtl_consol.c
vendored
Normal file
487
vendor/sdk/component/soc/realtek/8195a/misc/driver/rtl_consol.c
vendored
Normal file
|
|
@ -0,0 +1,487 @@
|
|||
/*
|
||||
* Routines to access hardware
|
||||
*
|
||||
* Copyright (c) 2013 Realtek Semiconductor Corp.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*/
|
||||
|
||||
#include "rtl8195a.h"
|
||||
//#include <stdarg.h>
|
||||
#include "rtl_consol.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <event_groups.h>
|
||||
#include "semphr.h"
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#endif
|
||||
#include "tcm_heap.h"
|
||||
|
||||
// Those symbols will be defined in linker script for gcc compiler
|
||||
// If not doing this would cause extra memory cost
|
||||
#if defined (__GNUC__)
|
||||
|
||||
extern volatile UART_LOG_CTL UartLogCtl;
|
||||
extern volatile UART_LOG_CTL *pUartLogCtl;
|
||||
extern u8 *ArgvArray[MAX_ARGV];
|
||||
extern UART_LOG_BUF UartLogBuf;
|
||||
|
||||
#ifdef CONFIG_UART_LOG_HISTORY
|
||||
extern u8 UartLogHistoryBuf[UART_LOG_HISTORY_LEN][UART_LOG_CMD_BUFLEN];
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
MON_RAM_BSS_SECTION
|
||||
volatile UART_LOG_CTL UartLogCtl;
|
||||
MON_RAM_BSS_SECTION
|
||||
volatile UART_LOG_CTL *pUartLogCtl;
|
||||
MON_RAM_BSS_SECTION
|
||||
u8 *ArgvArray[MAX_ARGV];
|
||||
MON_RAM_BSS_SECTION
|
||||
UART_LOG_BUF UartLogBuf;
|
||||
|
||||
#ifdef CONFIG_UART_LOG_HISTORY
|
||||
MON_RAM_BSS_SECTION
|
||||
u8 UartLogHistoryBuf[UART_LOG_HISTORY_LEN][UART_LOG_CMD_BUFLEN];
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_KERNEL
|
||||
static void (*up_sema_from_isr)(_sema *) = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
_LONG_CALL_
|
||||
extern u8
|
||||
UartLogCmdChk(
|
||||
IN u8 RevData,
|
||||
IN UART_LOG_CTL *prvUartLogCtl,
|
||||
IN u8 EchoFlag
|
||||
);
|
||||
|
||||
_LONG_CALL_
|
||||
extern VOID
|
||||
ArrayInitialize(
|
||||
IN u8 *pArrayToInit,
|
||||
IN u8 ArrayLen,
|
||||
IN u8 InitValue
|
||||
);
|
||||
|
||||
_LONG_CALL_
|
||||
extern VOID
|
||||
UartLogHistoryCmd(
|
||||
IN u8 RevData,
|
||||
IN UART_LOG_CTL *prvUartLogCtl,
|
||||
IN u8 EchoFlag
|
||||
);
|
||||
|
||||
_LONG_CALL_
|
||||
extern VOID
|
||||
UartLogCmdExecute(
|
||||
IN PUART_LOG_CTL pUartLogCtlExe
|
||||
);
|
||||
|
||||
|
||||
|
||||
//=================================================
|
||||
|
||||
|
||||
/* Minimum and maximum values a `signed long int' can hold.
|
||||
(Same as `int'). */
|
||||
#ifndef __LONG_MAX__
|
||||
#if defined (__alpha__) || (defined (__sparc__) && defined(__arch64__)) || defined (__sparcv9) || defined (__s390x__)
|
||||
#define __LONG_MAX__ 9223372036854775807L
|
||||
#else
|
||||
#define __LONG_MAX__ 2147483647L
|
||||
#endif /* __alpha__ || sparc64 */
|
||||
#endif
|
||||
#undef LONG_MIN
|
||||
#define LONG_MIN (-LONG_MAX-1)
|
||||
#undef LONG_MAX
|
||||
#define LONG_MAX __LONG_MAX__
|
||||
|
||||
/* Maximum value an `unsigned long int' can hold. (Minimum is 0). */
|
||||
#undef ULONG_MAX
|
||||
#define ULONG_MAX (LONG_MAX * 2UL + 1)
|
||||
|
||||
#ifndef __LONG_LONG_MAX__
|
||||
#define __LONG_LONG_MAX__ 9223372036854775807LL
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
//======================================================
|
||||
//<Function>: UartLogIrqHandleRam
|
||||
//<Usage >: To deal with Uart-Log RX IRQ
|
||||
//<Argus >: VOID
|
||||
//<Return >: VOID
|
||||
//<Notes >: NA
|
||||
//======================================================
|
||||
//MON_RAM_TEXT_SECTION
|
||||
VOID
|
||||
UartLogIrqHandleRam
|
||||
(
|
||||
VOID * Data
|
||||
)
|
||||
{
|
||||
u8 UartReceiveData = 0;
|
||||
//For Test
|
||||
BOOL PullMode = _FALSE;
|
||||
|
||||
u32 IrqEn = DiagGetIsrEnReg();
|
||||
|
||||
DiagSetIsrEnReg(0);
|
||||
|
||||
UartReceiveData = DiagGetChar(PullMode);
|
||||
if (UartReceiveData == 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
//KB_ESC chk is for cmd history, it's a special case here.
|
||||
if (UartReceiveData == KB_ASCII_ESC) {
|
||||
//4 Esc detection is only valid in the first stage of boot sequence (few seconds)
|
||||
if (pUartLogCtl->ExecuteEsc != _TRUE)
|
||||
{
|
||||
pUartLogCtl->ExecuteEsc = _TRUE;
|
||||
(*pUartLogCtl).EscSTS = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//4 the input commands are valid only when the task is ready to execute commands
|
||||
if ((pUartLogCtl->BootRdy == 1)
|
||||
#ifdef CONFIG_KERNEL
|
||||
||(pUartLogCtl->TaskRdy == 1)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if ((*pUartLogCtl).EscSTS==0)
|
||||
{
|
||||
(*pUartLogCtl).EscSTS = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(*pUartLogCtl).EscSTS = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((*pUartLogCtl).EscSTS==1){
|
||||
if (UartReceiveData != KB_ASCII_LBRKT){
|
||||
(*pUartLogCtl).EscSTS = 0;
|
||||
}
|
||||
else{
|
||||
(*pUartLogCtl).EscSTS = 2;
|
||||
}
|
||||
}
|
||||
|
||||
else{
|
||||
if ((*pUartLogCtl).EscSTS==2){
|
||||
(*pUartLogCtl).EscSTS = 0;
|
||||
#ifdef CONFIG_UART_LOG_HISTORY
|
||||
if ((UartReceiveData=='A')|| UartReceiveData=='B'){
|
||||
UartLogHistoryCmd(UartReceiveData,(UART_LOG_CTL *)pUartLogCtl,1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else{
|
||||
if (UartLogCmdChk(UartReceiveData,(UART_LOG_CTL *)pUartLogCtl,1)==2)
|
||||
{
|
||||
//4 check UartLog buffer to prevent from incorrect access
|
||||
if (pUartLogCtl->pTmpLogBuf != NULL)
|
||||
{
|
||||
pUartLogCtl->ExecuteCmd = _TRUE;
|
||||
#if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED
|
||||
if (pUartLogCtl->TaskRdy && up_sema_from_isr != NULL)
|
||||
//RtlUpSemaFromISR((_Sema *)&pUartLogCtl->Sema);
|
||||
up_sema_from_isr((_sema *)&pUartLogCtl->Sema);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayInitialize((u8 *)pUartLogCtl->pTmpLogBuf->UARTLogBuf, UART_LOG_CMD_BUFLEN, '\0');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exit:
|
||||
DiagSetIsrEnReg(IrqEn);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//MON_RAM_TEXT_SECTION
|
||||
VOID
|
||||
RtlConsolInitRam(
|
||||
IN u32 Boot,
|
||||
IN u32 TBLSz,
|
||||
IN VOID *pTBL
|
||||
)
|
||||
{
|
||||
UartLogBuf.BufCount = 0;
|
||||
ArrayInitialize(&UartLogBuf.UARTLogBuf[0],UART_LOG_CMD_BUFLEN,'\0');
|
||||
pUartLogCtl = &UartLogCtl;
|
||||
|
||||
pUartLogCtl->NewIdx = 0;
|
||||
pUartLogCtl->SeeIdx = 0;
|
||||
pUartLogCtl->RevdNo = 0;
|
||||
pUartLogCtl->EscSTS = 0;
|
||||
pUartLogCtl->BootRdy = 0;
|
||||
pUartLogCtl->pTmpLogBuf = &UartLogBuf;
|
||||
#ifdef CONFIG_UART_LOG_HISTORY
|
||||
pUartLogCtl->CRSTS = 0;
|
||||
pUartLogCtl->pHistoryBuf = &UartLogHistoryBuf[0];
|
||||
#endif
|
||||
pUartLogCtl->pfINPUT = (VOID*)&DiagPrintf;
|
||||
pUartLogCtl->pCmdTbl = (PCOMMAND_TABLE) pTBL;
|
||||
pUartLogCtl->CmdTblSz = TBLSz;
|
||||
#ifdef CONFIG_KERNEL
|
||||
pUartLogCtl->TaskRdy = 0;
|
||||
#endif
|
||||
//executing boot sequence
|
||||
if (Boot == ROM_STAGE)
|
||||
{
|
||||
pUartLogCtl->ExecuteCmd = _FALSE;
|
||||
pUartLogCtl->ExecuteEsc = _FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
pUartLogCtl->ExecuteCmd = _FALSE;
|
||||
pUartLogCtl->ExecuteEsc= _TRUE;//don't check Esc anymore
|
||||
#if defined(CONFIG_KERNEL)
|
||||
/* Create a Semaphone */
|
||||
//RtlInitSema((_Sema*)&(pUartLogCtl->Sema), 0);
|
||||
rtw_init_sema((_sema*)&(pUartLogCtl->Sema), 0);
|
||||
pUartLogCtl->TaskRdy = 0;
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
#define LOGUART_STACK_SIZE 128 //USE_MIN_STACK_SIZE modify from 512 to 128
|
||||
#if CONFIG_USE_TCM_HEAP
|
||||
{
|
||||
int ret = 0;
|
||||
void *stack_addr = tcm_heap_malloc(LOGUART_STACK_SIZE*sizeof(int));
|
||||
//void *stack_addr = rtw_malloc(stack_size*sizeof(int));
|
||||
if(stack_addr == NULL){
|
||||
DiagPrintf("Out of TCM heap in \"LOGUART_TASK\" ");
|
||||
}
|
||||
ret = xTaskGenericCreate(
|
||||
RtlConsolTaskRam,
|
||||
(const char *)"LOGUART_TASK",
|
||||
LOGUART_STACK_SIZE,
|
||||
NULL,
|
||||
tskIDLE_PRIORITY + 5 + PRIORITIE_OFFSET,
|
||||
NULL,
|
||||
stack_addr,
|
||||
NULL);
|
||||
if (pdTRUE != ret)
|
||||
{
|
||||
DiagPrintf("Create Log UART Task Err!!\n");
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (pdTRUE != xTaskCreate( RtlConsolTaskRam, (const signed char * const)"LOGUART_TASK", LOGUART_STACK_SIZE, NULL, tskIDLE_PRIORITY + 5 + PRIORITIE_OFFSET, NULL))
|
||||
{
|
||||
DiagPrintf("Create Log UART Task Err!!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
CONSOLE_8195A();
|
||||
}
|
||||
|
||||
extern u8** GetArgv(const u8 *string);
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
extern char log_buf[LOG_SERVICE_BUFLEN];
|
||||
extern xSemaphoreHandle log_rx_interrupt_sema;
|
||||
#endif
|
||||
//======================================================
|
||||
void console_cmd_exec(PUART_LOG_CTL pUartLogCtlExe)
|
||||
{
|
||||
u8 CmdCnt = 0;
|
||||
u8 argc = 0;
|
||||
u8 **argv;
|
||||
//u32 CmdNum;
|
||||
PUART_LOG_BUF pUartLogBuf = pUartLogCtlExe->pTmpLogBuf;
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
strncpy(log_buf, (const u8*)&(*pUartLogBuf).UARTLogBuf[0], LOG_SERVICE_BUFLEN-1);
|
||||
#endif
|
||||
argc = GetArgc((const u8*)&((*pUartLogBuf).UARTLogBuf[0]));
|
||||
argv = GetArgv((const u8*)&((*pUartLogBuf).UARTLogBuf[0]));
|
||||
|
||||
if(argc > 0){
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
// if(log_handler(argv[0]) == NULL)
|
||||
// legency_interactive_handler(argc, argv);
|
||||
//RtlUpSema((_Sema *)&log_rx_interrupt_sema);
|
||||
rtw_up_sema((_sema *)&log_rx_interrupt_sema);
|
||||
#endif
|
||||
ArrayInitialize(argv[0], sizeof(argv[0]) ,0);
|
||||
}else{
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
pmu_acquire_wakelock(BIT(PMU_LOGUART_DEVICE));
|
||||
#endif
|
||||
CONSOLE_8195A(); // for null command
|
||||
}
|
||||
|
||||
(*pUartLogBuf).BufCount = 0;
|
||||
ArrayInitialize(&(*pUartLogBuf).UARTLogBuf[0], UART_LOG_CMD_BUFLEN, '\0');
|
||||
}
|
||||
//======================================================
|
||||
// overload original RtlConsolTaskRam
|
||||
//MON_RAM_TEXT_SECTION
|
||||
VOID
|
||||
RtlConsolTaskRam(
|
||||
VOID *Data
|
||||
)
|
||||
{
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
log_service_init();
|
||||
#endif
|
||||
//4 Set this for UartLog check cmd history
|
||||
#ifdef CONFIG_KERNEL
|
||||
pUartLogCtl->TaskRdy = 1;
|
||||
up_sema_from_isr = rtw_up_sema_from_isr;
|
||||
#endif
|
||||
#ifndef CONFIG_KERNEL
|
||||
pUartLogCtl->BootRdy = 1;
|
||||
#endif
|
||||
do{
|
||||
#if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED
|
||||
//RtlDownSema((_Sema *)&pUartLogCtl->Sema);
|
||||
rtw_down_sema((_sema *)&pUartLogCtl->Sema);
|
||||
#endif
|
||||
if (pUartLogCtl->ExecuteCmd) {
|
||||
// Add command handler here
|
||||
console_cmd_exec((PUART_LOG_CTL)pUartLogCtl);
|
||||
//UartLogCmdExecute((PUART_LOG_CTL)pUartLogCtl);
|
||||
pUartLogCtl->ExecuteCmd = _FALSE;
|
||||
}
|
||||
}while(1);
|
||||
}
|
||||
|
||||
//======================================================
|
||||
#if BUFFERED_PRINTF
|
||||
xTaskHandle print_task = NULL;
|
||||
EventGroupHandle_t print_event = NULL;
|
||||
char print_buffer[MAX_PRINTF_BUF_LEN];
|
||||
int flush_idx = 0;
|
||||
int used_length = 0;
|
||||
|
||||
int available_space(void)
|
||||
{
|
||||
return MAX_PRINTF_BUF_LEN-used_length;
|
||||
}
|
||||
|
||||
int buffered_printf(const char* fmt, ...)
|
||||
{
|
||||
if((print_task==NULL) || (print_event==NULL) )
|
||||
return 0;
|
||||
char tmp_buffer[UART_LOG_CMD_BUFLEN+1];
|
||||
static int print_idx = 0;
|
||||
int cnt;
|
||||
|
||||
if(xEventGroupGetBits(print_event)!=1)
|
||||
xEventGroupSetBits(print_event, 1);
|
||||
|
||||
memset(tmp_buffer,0,UART_LOG_CMD_BUFLEN+1);
|
||||
VSprintf(tmp_buffer, fmt, ((const int *)&fmt)+1);
|
||||
cnt = _strlen(tmp_buffer);
|
||||
if(cnt < available_space()){
|
||||
if(print_idx >= flush_idx){
|
||||
if(MAX_PRINTF_BUF_LEN-print_idx >= cnt){
|
||||
memcpy(&print_buffer[print_idx], tmp_buffer, cnt);
|
||||
}else{
|
||||
memcpy(&print_buffer[print_idx], tmp_buffer, MAX_PRINTF_BUF_LEN-print_idx);
|
||||
memcpy(&print_buffer[0], &tmp_buffer[MAX_PRINTF_BUF_LEN-print_idx], cnt-(MAX_PRINTF_BUF_LEN-print_idx));
|
||||
}
|
||||
}else{ // space is flush_idx - print_idx, and available space is enough
|
||||
memcpy(&print_buffer[print_idx], tmp_buffer, cnt);
|
||||
}
|
||||
// protection needed
|
||||
taskENTER_CRITICAL();
|
||||
used_length+=cnt;
|
||||
taskEXIT_CRITICAL();
|
||||
print_idx+=cnt;
|
||||
if(print_idx>=MAX_PRINTF_BUF_LEN)
|
||||
print_idx -= MAX_PRINTF_BUF_LEN;
|
||||
}else{
|
||||
// skip
|
||||
cnt = 0;
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
void printing_task(void* arg)
|
||||
{
|
||||
while(1){
|
||||
//wait event
|
||||
if(xEventGroupWaitBits(print_event, 1, pdFALSE, pdFALSE, 100 ) == 1){
|
||||
while(used_length > 0){
|
||||
putchar(print_buffer[flush_idx]);
|
||||
flush_idx++;
|
||||
if(flush_idx >= MAX_PRINTF_BUF_LEN)
|
||||
flush_idx-=MAX_PRINTF_BUF_LEN;
|
||||
taskENTER_CRITICAL();
|
||||
used_length--;
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
// clear event
|
||||
xEventGroupClearBits( print_event, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rtl_printf_init()
|
||||
{
|
||||
if(print_event==NULL){
|
||||
print_event = xEventGroupCreate();
|
||||
if(print_event == NULL)
|
||||
printf("\n\rprint event init fail!\n");
|
||||
}
|
||||
if(print_task == NULL){
|
||||
if(xTaskCreate(printing_task, (const char *)"print_task", 512, NULL, tskIDLE_PRIORITY + 1, &print_task) != pdPASS)
|
||||
printf("\n\rprint task init fail!\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//======================================================
|
||||
|
||||
|
||||
__weak void console_init(void)
|
||||
{
|
||||
|
||||
IRQ_HANDLE UartIrqHandle;
|
||||
|
||||
//4 Register Log Uart Callback function
|
||||
UartIrqHandle.Data = NULL;//(u32)&UartAdapter;
|
||||
UartIrqHandle.IrqNum = UART_LOG_IRQ;
|
||||
UartIrqHandle.IrqFun = (IRQ_FUN) UartLogIrqHandleRam;
|
||||
UartIrqHandle.Priority = 6;
|
||||
|
||||
|
||||
//4 Register Isr handle
|
||||
InterruptUnRegister(&UartIrqHandle);
|
||||
InterruptRegister(&UartIrqHandle);
|
||||
|
||||
|
||||
|
||||
#if !TASK_SCHEDULER_DISABLED
|
||||
RtlConsolInitRam((u32)RAM_STAGE,(u32)0,(VOID*)NULL);
|
||||
#else
|
||||
RtlConsolInitRam((u32)ROM_STAGE,(u32)0,(VOID*)NULL);
|
||||
#endif
|
||||
|
||||
#if BUFFERED_PRINTF
|
||||
rtl_printf_init();
|
||||
#endif
|
||||
}
|
||||
140
vendor/sdk/component/soc/realtek/8195a/misc/driver/rtl_consol.h
vendored
Normal file
140
vendor/sdk/component/soc/realtek/8195a/misc/driver/rtl_consol.h
vendored
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Routines to access hardware
|
||||
*
|
||||
* Copyright (c) 2013 Realtek Semiconductor Corp.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*/
|
||||
|
||||
#ifndef _RTK_CONSOL_H_
|
||||
#define _RTK_CONSOL_H_
|
||||
/*
|
||||
* Include user defined options first. Anything not defined in these files
|
||||
* will be set to standard values. Override anything you dont like!
|
||||
*/
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
#include "platform_opts.h"
|
||||
#endif
|
||||
|
||||
//#include "osdep_api.h"
|
||||
#include "osdep_service.h"
|
||||
#include "hal_diag.h"
|
||||
#include "platform_stdlib.h"
|
||||
|
||||
#define CONSOLE_PREFIX "#"
|
||||
|
||||
|
||||
//Log UART
|
||||
//UART_LOG_CMD_BUFLEN: only 126 bytes could be used for keeping input
|
||||
// cmd, the last byte is for string end ('\0').
|
||||
#define UART_LOG_CMD_BUFLEN 127
|
||||
#define MAX_ARGV 10
|
||||
|
||||
//print log buffer length, if buffer get full, the extra logs will be discarded.
|
||||
#if BUFFERED_PRINTF
|
||||
#define MAX_PRINTF_BUF_LEN 1024
|
||||
#endif
|
||||
|
||||
|
||||
typedef u32 (*ECHOFUNC)(IN u8*,...); //UART LOG echo-function type.
|
||||
|
||||
typedef struct _UART_LOG_BUF_ {
|
||||
u8 BufCount; //record the input cmd char number.
|
||||
u8 UARTLogBuf[UART_LOG_CMD_BUFLEN]; //record the input command.
|
||||
} UART_LOG_BUF, *PUART_LOG_BUF;
|
||||
|
||||
|
||||
|
||||
typedef struct _UART_LOG_CTL_ {
|
||||
u8 NewIdx;
|
||||
u8 SeeIdx;
|
||||
u8 RevdNo;
|
||||
u8 EscSTS;
|
||||
u8 ExecuteCmd;
|
||||
u8 ExecuteEsc;
|
||||
u8 BootRdy;
|
||||
u8 Resvd;
|
||||
PUART_LOG_BUF pTmpLogBuf;
|
||||
VOID *pfINPUT;
|
||||
PCOMMAND_TABLE pCmdTbl;
|
||||
u32 CmdTblSz;
|
||||
#ifdef CONFIG_UART_LOG_HISTORY
|
||||
u32 CRSTS;
|
||||
#endif
|
||||
#ifdef CONFIG_UART_LOG_HISTORY
|
||||
u8 (*pHistoryBuf)[UART_LOG_CMD_BUFLEN];
|
||||
#endif
|
||||
#ifdef CONFIG_KERNEL
|
||||
u32 TaskRdy;
|
||||
//_Sema Sema;
|
||||
_sema Sema;
|
||||
#else
|
||||
// Since ROM code will reference this typedef, so keep the typedef same size
|
||||
u32 TaskRdy;
|
||||
void *Sema;
|
||||
#endif
|
||||
} UART_LOG_CTL, *PUART_LOG_CTL;
|
||||
|
||||
|
||||
#define KB_ASCII_NUL 0x00
|
||||
#define KB_ASCII_BS 0x08
|
||||
#define KB_ASCII_TAB 0x09
|
||||
#define KB_ASCII_LF 0x0A
|
||||
#define KB_ASCII_CR 0x0D
|
||||
#define KB_ASCII_ESC 0x1B
|
||||
#define KB_ASCII_SP 0x20
|
||||
#define KB_ASCII_BS_7F 0x7F
|
||||
#define KB_ASCII_LBRKT 0x5B //[
|
||||
|
||||
#define KB_SPACENO_TAB 1
|
||||
|
||||
#ifdef CONFIG_UART_LOG_HISTORY
|
||||
#define UART_LOG_HISTORY_LEN 5
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_LOG
|
||||
#define _ConsolePrint DiagPrintf
|
||||
#else
|
||||
#define _ConsolePrint
|
||||
#endif
|
||||
|
||||
#ifndef CONSOLE_PREFIX
|
||||
#define CONSOLE_PREFIX "<RTL8195A>"
|
||||
#endif
|
||||
|
||||
#define CONSOLE_8195A(...) do {\
|
||||
_ConsolePrint("\r"CONSOLE_PREFIX __VA_ARGS__);\
|
||||
}while(0)
|
||||
|
||||
|
||||
_LONG_CALL_ VOID
|
||||
RtlConsolInit(
|
||||
IN u32 Boot,
|
||||
IN u32 TBLSz,
|
||||
IN VOID *pTBL
|
||||
);
|
||||
|
||||
#if defined(CONFIG_KERNEL)
|
||||
_LONG_CALL_ VOID
|
||||
RtlConsolTaskRam(
|
||||
VOID *Data
|
||||
);
|
||||
#endif
|
||||
|
||||
_LONG_CALL_ VOID
|
||||
RtlConsolTaskRom(
|
||||
VOID *Data
|
||||
);
|
||||
|
||||
|
||||
_LONG_CALL_ u32
|
||||
Strtoul(
|
||||
IN const u8 *nptr,
|
||||
IN u8 **endptr,
|
||||
IN u32 base
|
||||
);
|
||||
|
||||
void console_init(void);
|
||||
|
||||
#endif //_RTK_CONSOL_H_
|
||||
12
vendor/sdk/component/soc/realtek/8195a/misc/driver/rtl_sec.h
vendored
Normal file
12
vendor/sdk/component/soc/realtek/8195a/misc/driver/rtl_sec.h
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef RTL_SEC_H
|
||||
#define RTL_SEC_H
|
||||
|
||||
#include <platform_stdlib.h>
|
||||
|
||||
#define SEC_PROCESS_OPT_ENC 1
|
||||
#define SEC_PROCESS_OPT_DEC 2
|
||||
|
||||
#define sec_process_data ProcessSecData
|
||||
uint32_t sec_process_data(uint8_t key_idx, uint32_t opt, uint8_t *iv, uint8_t *input_buf, uint32_t buf_len, uint8_t *output_buf);
|
||||
|
||||
#endif // RTL_SEC_H
|
||||
77
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/Check_Jtag.sh
vendored
Normal file
77
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/Check_Jtag.sh
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#!/bin/sh
|
||||
|
||||
#===============================================================================
|
||||
CURRENT_UTILITY_DIR=$(pwd)
|
||||
GDBSCPTFILE="../../../component/soc/realtek/8195a/misc/gcc_utility/rtl_gdb_flash_write.txt"
|
||||
|
||||
#===============================================================================
|
||||
RLXSTS=$(ps -W | grep "rlx_probe_driver.exe" | grep -v "grep" | wc -l)
|
||||
echo $RLXSTS
|
||||
JLKSTS=$(ps -W | grep "JLinkGDBServer.exe" | grep -v "grep" | wc -l)
|
||||
echo $JLKSTS
|
||||
|
||||
echo $CURRENT_UTILITY_DIR
|
||||
|
||||
#===============================================================================
|
||||
#make the new string for being written
|
||||
if [ $RLXSTS = 1 ]
|
||||
then
|
||||
echo "probe get"
|
||||
|
||||
#-------------------------------------------
|
||||
LINE_NUMBER=$(grep -n "monitor reset " $GDBSCPTFILE | awk -F":" '{print $1}')
|
||||
DEFAULT_STR=$(grep -n "monitor reset " $GDBSCPTFILE | awk -F":" '{print $2}')
|
||||
#echo $LINE_NUMBER
|
||||
echo $DEFAULT_STR
|
||||
STRLEN_DFT=$(expr length "$DEFAULT_STR")
|
||||
DEFAULT_STR="#monitor reset 1"
|
||||
echo $DEFAULT_STR
|
||||
#-------------------------------------------
|
||||
SED_PARA="$LINE_NUMBER""c""$DEFAULT_STR"
|
||||
sed -i "$SED_PARA" $GDBSCPTFILE
|
||||
|
||||
#===========================================
|
||||
LINE_NUMBER=$(grep -n "monitor sleep " $GDBSCPTFILE | awk -F":" '{print $1}')
|
||||
DEFAULT_STR=$(grep -n "monitor sleep " $GDBSCPTFILE | awk -F":" '{print $2}')
|
||||
#echo $LINE_NUMBER
|
||||
echo $DEFAULT_STR
|
||||
STRLEN_DFT=$(expr length "$DEFAULT_STR")
|
||||
DEFAULT_STR="#monitor sleep 20"
|
||||
echo $DEFAULT_STR
|
||||
#-------------------------------------------
|
||||
SED_PARA="$LINE_NUMBER""c""$DEFAULT_STR"
|
||||
sed -i "$SED_PARA" $GDBSCPTFILE
|
||||
else
|
||||
|
||||
if [ $JLKSTS = 1 ]
|
||||
then
|
||||
echo "jlink get"
|
||||
|
||||
#-------------------------------------------
|
||||
LINE_NUMBER=$(grep -n "monitor reset " $GDBSCPTFILE | awk -F":" '{print $1}')
|
||||
DEFAULT_STR=$(grep -n "monitor reset " $GDBSCPTFILE | awk -F":" '{print $2}')
|
||||
#echo $LINE_NUMBER
|
||||
echo $DEFAULT_STR
|
||||
STRLEN_DFT=$(expr length "$DEFAULT_STR")
|
||||
DEFAULT_STR="monitor reset 1"
|
||||
echo $DEFAULT_STR
|
||||
#-------------------------------------------
|
||||
SED_PARA="$LINE_NUMBER""c""$DEFAULT_STR"
|
||||
sed -i "$SED_PARA" $GDBSCPTFILE
|
||||
|
||||
#===========================================
|
||||
LINE_NUMBER=$(grep -n "monitor sleep " $GDBSCPTFILE | awk -F":" '{print $1}')
|
||||
DEFAULT_STR=$(grep -n "monitor sleep " $GDBSCPTFILE | awk -F":" '{print $2}')
|
||||
#echo $LINE_NUMBER
|
||||
echo $DEFAULT_STR
|
||||
STRLEN_DFT=$(expr length "$DEFAULT_STR")
|
||||
DEFAULT_STR="monitor sleep 20"
|
||||
echo $DEFAULT_STR
|
||||
#-------------------------------------------
|
||||
SED_PARA="$LINE_NUMBER""c""$DEFAULT_STR"
|
||||
sed -i "$SED_PARA" $GDBSCPTFILE
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
#===============================================================================
|
||||
20
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/SetupGDB_NORMAL.sh
vendored
Normal file
20
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/SetupGDB_NORMAL.sh
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
|
||||
#===============================================================================
|
||||
CURRENT_UTILITY_DIR=$(pwd)
|
||||
echo "..."
|
||||
echo $CURRENT_UTILITY_DIR
|
||||
RAMFILENAME="./application/Debug/bin/ram_all.bin"
|
||||
echo $RAMFILENAME
|
||||
#RAMFILENAME="ram_2.bin"
|
||||
GDBSCPTFILE="../../../component/soc/realtek/8195a/misc/gcc_utility/rtl_gdb_flash_write.txt"
|
||||
|
||||
#===============================================================================
|
||||
#get file size
|
||||
RAM_FILE_SIZE=$(stat -c %s $RAMFILENAME)
|
||||
RAM_FILE_SIZE_HEX=`echo "obase=16; $RAM_FILE_SIZE"|bc`
|
||||
|
||||
echo "size "$RAM_FILE_SIZE" --> 0x"$RAM_FILE_SIZE_HEX
|
||||
|
||||
echo "set \$RamFileSize = 0x$RAM_FILE_SIZE_HEX" > fwsize.gdb
|
||||
exit
|
||||
38
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/SetupGDB_NORMAL.bat
vendored
Normal file
38
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/SetupGDB_NORMAL.bat
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
@echo off
|
||||
|
||||
set RAMFILENAME=".\Debug\ram_all.bin"
|
||||
::echo %RAMFILENAME%
|
||||
|
||||
cp ..\..\..\..\..\component\soc\realtek\8195a\misc\gcc_utility\target_NORMALB.axf ..\..\..\..\..\component\soc\realtek\8195a\misc\gcc_utility\target_NORMAL.axf
|
||||
|
||||
::===============================================================================
|
||||
::get file size and translate to HEX
|
||||
for %%A in (%RAMFILENAME%) do set fileSize=%%~zA
|
||||
@call :toHex %fileSize% fileSizeHex
|
||||
|
||||
::echo %fileSize%
|
||||
::echo %fileSizeHex%
|
||||
|
||||
echo set $RamFileSize = 0x%fileSizeHex% > .\Debug\fwsize.gdb
|
||||
|
||||
:: start GDB for flash write, argument 1 (%1) could be rather "openocd" or "jlink"
|
||||
::echo %1
|
||||
..\..\..\..\..\tools\arm-none-eabi-gcc\4_8-2014q3\bin\arm-none-eabi-gdb -x ..\..\..\..\..\component\soc\realtek\8195a\misc\gcc_utility\eclipse\rtl_eclipse_flash_write_%1.txt
|
||||
|
||||
exit
|
||||
|
||||
:toHex dec hex -- convert a decimal number to hexadecimal, i.e. -20 to FFFFFFEC or 26 to 0000001A
|
||||
@echo off
|
||||
SETLOCAL ENABLEDELAYEDEXPANSION
|
||||
set /a dec=%~1
|
||||
set "hex="
|
||||
set "map=0123456789ABCDEF"
|
||||
for /L %%N in (1,1,8) do (
|
||||
set /a "d=dec&15,dec>>=4"
|
||||
for %%D in (!d!) do set "hex=!map:~%%D,1!!hex!"
|
||||
)
|
||||
|
||||
( ENDLOCAL & REM RETURN VALUES
|
||||
IF "%~2" NEQ "" (SET %~2=%hex%) ELSE ECHO.%hex%
|
||||
)
|
||||
EXIT /b
|
||||
38
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/compile_dram_eclipse_win.bat
vendored
Normal file
38
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/compile_dram_eclipse_win.bat
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
:: application/Debug
|
||||
@echo off
|
||||
|
||||
set bindir=.
|
||||
set gccdir=..\..\..\..\..\..\tools\arm-none-eabi-gcc\4_8-2014q3\bin
|
||||
|
||||
::e.g. arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -std=gnu99 -DGCC_ARMCM3 -DM3 -DCONFIG_PLATFORM_8195A -DF_CPU=166000000L -I..\..\..\..\inc -I..\..\..\..\..\..\component\soc\realtek\common\bsp -I..\..\..\..\..\..\component\os\freertos -I..\..\..\..\..\..\component\os\freertos\freertos_v8.1.2\Source\include -I..\..\..\..\..\..\component\os\freertos\freertos_v8.1.2\Source\portable\GCC\ARM_CM3 -I..\..\..\..\..\..\component\os\os_dep\include -I..\..\..\..\..\..\component\soc\realtek\8195a\misc\driver -I..\..\..\..\..\..\component\common\api\network\include -I..\..\..\..\..\..\component\common\api -I..\..\..\..\..\..\component\common\api\platform -I..\..\..\..\..\..\component\common\api\wifi -I..\..\..\..\..\..\component\common\api\wifi\rtw_wpa_supplicant\src -I..\..\..\..\..\..\component\common\application -I..\..\..\..\..\..\component\common\media\framework -I..\..\..\..\..\..\component\common\example -I..\..\..\..\..\..\component\common\example\wlan_fast_connect -I..\..\..\..\..\..\component\common\mbed\api -I..\..\..\..\..\..\component\common\mbed\hal -I..\..\..\..\..\..\component\common\mbed\hal_ext -I..\..\..\..\..\..\component\common\mbed\targets\hal\rtl8195a -I..\..\..\..\..\..\component\common\network -I..\..\..\..\..\..\component\common\network\lwip\lwip_v1.4.1\port\realtek\freertos -I..\..\..\..\..\..\component\common\network\lwip\lwip_v1.4.1\src\include -I..\..\..\..\..\..\component\common\network\lwip\lwip_v1.4.1\src\include\lwip -I..\..\..\..\..\..\component\common\network\lwip\lwip_v1.4.1\src\include\ipv4 -I..\..\..\..\..\..\component\common\network\lwip\lwip_v1.4.1\port\realtek -I..\..\..\..\..\..\component\common\test -I..\..\..\..\..\..\component\soc\realtek\8195a\cmsis -I..\..\..\..\..\..\component\soc\realtek\8195a\cmsis\device -I..\..\..\..\..\..\component\soc\realtek\8195a\fwlib -I..\..\..\..\..\..\component\soc\realtek\8195a\fwlib\rtl8195a -I..\..\..\..\..\..\component\soc\realtek\8195a\misc\rtl_std_lib\include -I..\..\..\..\..\..\component\common\drivers\wlan\realtek\include -I..\..\..\..\..\..\component\common\drivers\wlan\realtek\src\osdep -I..\..\..\..\..\..\component\soc\realtek\8195a\fwlib\ram_lib\wlan\realtek\wlan_ram_map\rom -I..\..\..\..\..\..\component\common\network\ssl\polarssl-1.3.8\include -I..\..\..\..\..\..\component\common\network\ssl\ssl_ram_map\rom -I..\..\..\..\..\..\component\common\utilities -I..\..\..\..\..\..\component\soc\realtek\8195a\misc\rtl_std_lib\include -I..\..\..\..\..\..\component\soc\realtek\8195a\fwlib\ram_lib\usb_otg\include -I..\..\..\..\..\..\component\common\video\v4l2\inc -I..\..\..\..\..\..\component\common\media\codec -I..\..\..\..\..\..\component\common\drivers\usb_class\host\uvc\inc -I..\..\..\..\..\..\component\common\drivers\usb_class\device -I..\..\..\..\..\..\component\common\drivers\usb_class\device\class -I..\..\..\..\..\..\component\common\file_system\fatfs -I..\..\..\..\..\..\component\common\file_system\fatfs\r0.10c\include -I..\..\..\..\..\..\component\common\drivers\sdio\realtek\sdio_host\inc -I..\..\..\..\..\..\component\common\audio -I..\..\..\..\..\..\component\common\drivers\i2s -I..\..\..\..\..\..\component\common\application\apple\WACServer\External\Curve25519 -I..\..\..\..\..\..\component\common\application\apple\WACServer\External\GladmanAES -I..\..\..\..\..\..\component\common\application\google -I..\..\..\..\..\..\component\common\application\xmodem -O2 -g -Wno-pointer-sign -fno-common -fmessage-length=0 -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-short-enums -fsigned-char -MMD -MP -MFSDRAM/polarssl/aes.d -MTSDRAM/polarssl/aes.o -o SDRAM/polarssl/aes.o D:/test/sdk-ameba1-v3.5b_beta_v2/component/common/network/ssl/polarssl-1.3.8/library/aes.c
|
||||
|
||||
REM get last two argument which is the output object file
|
||||
call :GetLastTwoArg %*
|
||||
::echo %lastTwoArg%
|
||||
|
||||
:: check argument count
|
||||
::set argC=0
|
||||
::for %%x in (%*) do Set /A argC+=1
|
||||
::echo %argC%
|
||||
|
||||
:: gcc compile, %1 might be gcc or arm-none-eabi-gcc
|
||||
set arg1=%1
|
||||
if not "%arg1:arm-none-eabi-=%" == "%arg1%" (
|
||||
::echo is arm-none-eabi-gcc
|
||||
%gccdir%\%*
|
||||
) else (
|
||||
::echo is gcc
|
||||
%gccdir%\arm-none-eabi-%*
|
||||
)
|
||||
|
||||
:: objcopy append .sdram section info
|
||||
%gccdir%\arm-none-eabi-objcopy --prefix-alloc-sections .sdram %lastTwoArg%
|
||||
|
||||
REM This subroutine gets the last command-line argument by using SHIFT
|
||||
:GetLastTwoArg
|
||||
set "lastTwoArg=%~1"
|
||||
shift
|
||||
if not "%~2"=="" goto GetLastTwoArg
|
||||
goto :eof
|
||||
|
||||
exit
|
||||
74
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/postbuild_eclipse_win.bat
vendored
Normal file
74
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/postbuild_eclipse_win.bat
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
:: application/Debug
|
||||
@echo off
|
||||
|
||||
set bindir=.
|
||||
set tooldir=..\..\..\..\..\..\component\soc\realtek\8195a\misc\iar_utility\common\tools
|
||||
set libdir=..\..\..\..\..\..\component\soc\realtek\8195a\misc\bsp
|
||||
set gccdir=..\..\..\..\..\..\tools\arm-none-eabi-gcc\4_8-2014q3\bin
|
||||
|
||||
::echo %tooldir%
|
||||
::echo %libdir%
|
||||
|
||||
::copy bootloader and convert from image to object file
|
||||
::copy ../../../../../component/soc/realtek/8195a/misc/bsp/image/ram_1.r.bin ram_1.r.bin
|
||||
::%gccdir%/arm-none-eabi-objcopy --rename-section .data=.loader.data,contents,alloc,load,readonly,data -I binary -O elf32-littlearm -B arm ram_1.r.bin ram_1.r.o
|
||||
|
||||
::del Debug/Exe/target.map Debug/Exe/application.asm *.bin
|
||||
cmd /c "%gccdir%\arm-none-eabi-nm %bindir%/application.axf | %tooldir%\sort > %bindir%/application.nm.map"
|
||||
cmd /c "%gccdir%\arm-none-eabi-objdump -d %bindir%/application.axf > %bindir%/application.asm"
|
||||
|
||||
|
||||
for /f "delims=" %%i in ('cmd /c "%tooldir%\grep __ram_image2_text_start__ %bindir%/application.nm.map | %tooldir%\gawk '{print $1}'"') do set ram2_start=0x%%i
|
||||
for /f "delims=" %%i in ('cmd /c "%tooldir%\grep __sdram_data_start__ %bindir%/application.nm.map | %tooldir%\gawk '{print $1}'"') do set ram3_start=0x%%i
|
||||
|
||||
for /f "delims=" %%i in ('cmd /c "%tooldir%\grep __ram_image2_text_end__ %bindir%/application.nm.map | %tooldir%\gawk '{print $1}'"') do set ram2_end=0x%%i
|
||||
for /f "delims=" %%i in ('cmd /c "%tooldir%\grep __sdram_data_end__ %bindir%/application.nm.map | %tooldir%\gawk '{print $1}'"') do set ram3_end=0x%%i
|
||||
|
||||
::echo %ram1_start% > tmp.txt
|
||||
echo %ram2_start%
|
||||
echo %ram3_start%
|
||||
::echo %ram1_end% >> tmp.txt
|
||||
echo %ram2_end%
|
||||
echo %ram3_end%
|
||||
|
||||
|
||||
%gccdir%\arm-none-eabi-objcopy -j .image2.start.table -j .ram_image2.text -j .ram_image2.rodata -j .ram.data -Obinary %bindir%/application.axf %bindir%/ram_2.bin
|
||||
if NOT %ram3_start% == %ram3_end% (
|
||||
%gccdir%\arm-none-eabi-objcopy -j .sdr_text -j .sdr_rodata -j .sdr_data -Obinary %bindir%/application.axf %bindir%/sdram.bin
|
||||
)
|
||||
|
||||
%tooldir%\pick %ram2_start% %ram2_end% %bindir%\ram_2.bin %bindir%\ram_2.p.bin body+reset_offset+sig
|
||||
if defined %ram3_start (
|
||||
%tooldir%\pick %ram3_start% %ram3_end% %bindir%\sdram.bin %bindir%\ram_3.p.bin body+reset_offset
|
||||
)
|
||||
|
||||
:: check ram_1.p.bin exist, copy default
|
||||
if not exist %bindir%\ram_1.p.bin (
|
||||
copy %libdir%\image\ram_1.p.bin %bindir%\ram_1.p.bin
|
||||
)
|
||||
|
||||
::padding ram_1.p.bin to 32K+4K+4K+4K, LOADER/RSVD/SYSTEM/CALIBRATION
|
||||
%tooldir%\padding 44k 0xFF %bindir%\ram_1.p.bin
|
||||
|
||||
:: SDRAM case
|
||||
if defined %ram3_start (
|
||||
copy /b %bindir%\ram_1.p.bin+%bindir%\ram_2.p.bin+%bindir%\ram_3.p.bin %bindir%\ram_all.bin
|
||||
copy /b %bindir%\ram_2.p.bin+%bindir%\ram_3.p.bin %bindir%\ota.bin
|
||||
)
|
||||
|
||||
%tooldir%\checksum Debug\Exe\ota.bin
|
||||
|
||||
:: NO SDRAM case
|
||||
if not defined %ram3_start (
|
||||
copy /b %bindir%\ram_1.p.bin+%bindir%\ram_2.p.bin %bindir%\ram_all.bin
|
||||
copy /b %bindir%\ram_2.p.bin %bindir%\ota.bin
|
||||
)
|
||||
|
||||
del ram_1.r.*
|
||||
del ram*.p.bin
|
||||
del ram_2.bin
|
||||
if exist sdram.bin (
|
||||
del sdram.bin
|
||||
)
|
||||
|
||||
exit
|
||||
48
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/prebuild_eclipse_win.bat
vendored
Normal file
48
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/prebuild_eclipse_win.bat
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
:: application/Debug
|
||||
@echo off
|
||||
|
||||
set bindir=.
|
||||
|
||||
:: unzip arm-none-eabi-gcc\4_8-2014q3.tar
|
||||
set tooldir=..\..\..\..\..\..\component\soc\realtek\8195a\misc\gcc_utility\tools
|
||||
set currentdir=%cd%
|
||||
|
||||
:CheckOS
|
||||
if exist "%PROGRAMFILES(X86)%" (goto 64bit) else (goto 32bit)
|
||||
:64bit
|
||||
set os_prefix=x86_64
|
||||
goto next
|
||||
:32bit
|
||||
set os_prefix=x86
|
||||
:next
|
||||
|
||||
if not exist ..\..\..\..\..\..\tools\arm-none-eabi-gcc\4_8-2014q3\ (
|
||||
:: %tooldir%\%os_prefix%\gzip -dc ..\..\..\..\..\..\tools\arm-none-eabi-gcc\4.8.3-2014q1.tar.gz > ..\..\..\..\..\..\tools\arm-none-eabi-gcc\4.8.3-2014q1.tar
|
||||
cd ..\..\..\..\..\..\tools\arm-none-eabi-gcc
|
||||
..\..\component\soc\realtek\8195a\misc\gcc_utility\tools\%os_prefix%\tar -xf 4_8-2014q3.tar
|
||||
cd %currentdir%
|
||||
)
|
||||
|
||||
set gccdir=..\..\..\..\..\..\tools\arm-none-eabi-gcc\4_8-2014q3\bin
|
||||
|
||||
::echo %tooldir%
|
||||
|
||||
:: Generate build_info.h
|
||||
for /f "usebackq" %%i in (`hostname`) do set hostname=%%i
|
||||
|
||||
echo #define UTS_VERSION "%date:~0,10%-%time:~0,8%" > ..\..\..\..\inc\build_info.h
|
||||
echo #define RTL8195AFW_COMPILE_TIME "%date:~0,10%-%time:~0,8%" >> ..\..\..\..\inc\build_info.h
|
||||
echo #define RTL8195AFW_COMPILE_DATE "%date:~0,4%%date:~5,2%%date:~8,2%" >> ..\..\..\..\inc\build_info.h
|
||||
echo #define RTL8195AFW_COMPILE_BY "%USERNAME%" >> ..\..\..\..\inc\build_info.h
|
||||
echo #define RTL8195AFW_COMPILE_HOST "%hostname%" >> ..\..\..\..\inc\build_info.h
|
||||
echo #define RTL8195AFW_COMPILE_DOMAIN >> ..\..\..\..\inc\build_info.h
|
||||
echo #define RTL195AFW_COMPILER "GCC compiler" >> ..\..\..\..\inc\build_info.h
|
||||
|
||||
xcopy /Y ..\..\..\rlx8195A-symbol-v02-img2.ld .
|
||||
xcopy /Y ..\..\..\export-rom_v02.txt .
|
||||
|
||||
::copy bootloader and convert from image to object file
|
||||
xcopy /Y ..\..\..\..\..\..\component\soc\realtek\8195a\misc\bsp\image\ram_1.r.bin .
|
||||
%gccdir%\arm-none-eabi-objcopy --rename-section .data=.loader.data,contents,alloc,load,readonly,data -I binary -O elf32-littlearm -B arm ram_1.r.bin ram_1.r.o
|
||||
|
||||
exit
|
||||
199
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/rtl_eclipse_flash_write_jlink.txt
vendored
Normal file
199
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/rtl_eclipse_flash_write_jlink.txt
vendored
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
# GDB script for loading ram.bin process
|
||||
|
||||
#===============================================================================
|
||||
#set GDB connection
|
||||
set remotetimeout 100000
|
||||
target remote :2331
|
||||
|
||||
#===============================================================================
|
||||
#set file path
|
||||
set $BINFILE = "./Debug/ram_all.bin"
|
||||
|
||||
#===============================================================================
|
||||
#Message display setting
|
||||
#disable all messages
|
||||
|
||||
set verbose off
|
||||
set complaints 0
|
||||
set confirm off
|
||||
set exec-done-display off
|
||||
show exec-done-display
|
||||
set trace-commands off
|
||||
#set debug aix-thread off
|
||||
#set debug dwarf2-die 0
|
||||
set debug displaced off
|
||||
set debug expression 0
|
||||
set debug frame 0
|
||||
set debug infrun 0
|
||||
set debug observer 0
|
||||
set debug overload 0
|
||||
set debugvarobj 0
|
||||
set pagination off
|
||||
set print address off
|
||||
set print symbol-filename off
|
||||
set print symbol off
|
||||
set print pretty off
|
||||
set print object off
|
||||
#set debug notification off
|
||||
set debug parser off
|
||||
set debug remote 0
|
||||
|
||||
#===============================================================================
|
||||
#set JTAG and external SRAM
|
||||
monitor reset 1
|
||||
monitor sleep 20
|
||||
monitor clrbp
|
||||
#===============================================================================
|
||||
#Variables declaration (1)
|
||||
#binary file size
|
||||
set $RamFileSize = 0x0000
|
||||
source ./Debug/fwsize.gdb
|
||||
printf "-------------------------------\n"
|
||||
printf "RamFileSize: %x\n",$RamFileSize
|
||||
printf "-------------------------------\n"
|
||||
|
||||
#===============================================================================
|
||||
set $FLASHDATBUFSIZE = 0x800
|
||||
|
||||
#===============================================================================
|
||||
#define PERI_ON_BASE 0x40000000
|
||||
set $PERI_ON_BASE = 0x40000000
|
||||
#define REG_SOC_PERI_FUNC0_EN 0x0218
|
||||
set $REG_SOC_PERI_FUNC0_EN = 0x0210
|
||||
|
||||
#define SPI_FLASH_BASE 0x4000000
|
||||
set $SPI_FLASH_BASE = 0x98000000
|
||||
|
||||
#------------------------------------------------------------------
|
||||
set $Temp = 0x0
|
||||
|
||||
#===============================================================================
|
||||
#Load flash download file
|
||||
file ../../../../../component/soc/realtek/8195a/misc/gcc_utility/target_NORMAL.axf
|
||||
|
||||
#Load the file
|
||||
lo
|
||||
|
||||
printf "Load flash controller.\n"
|
||||
|
||||
#===============================================================================
|
||||
#Set for executing flash controller funciton
|
||||
set $Temp = {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN)
|
||||
p /x $Temp
|
||||
|
||||
set $Temp = ($Temp | (0x01 << 27))
|
||||
p /x $Temp
|
||||
|
||||
set {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) = $Temp
|
||||
printf "....\n"
|
||||
printf "wakeup bit(%x):%x\n", ($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN), {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN)
|
||||
#===============================================================================
|
||||
#Direct the startup wake function to flash program function
|
||||
#the function pointer address
|
||||
#set $testpointer = 0x200006b4
|
||||
#set $testpointer2 = 0x200006b8
|
||||
#set $FuntionPointer = 0x200006c4
|
||||
#set $FPTemp = 0x200a08e9
|
||||
#set {int}($FuntionPointer) = $FPTemp
|
||||
#printf "testpointer(%x):%x\n", $testpointer, {int}$testpointer
|
||||
#printf "testpointer2(%x):%x\n", $testpointer2, {int}$testpointer2
|
||||
#printf "FuntionPointer(%x):%x\n", $FuntionPointer, {int}$FuntionPointer
|
||||
|
||||
#===============================================================================
|
||||
#Load file
|
||||
# restore filename [binary] bias start end
|
||||
# Restore the contents of file filename into memory.
|
||||
# The restore command can automatically recognize any known bfd file format, except for raw binary.
|
||||
# To restore a raw binary file you must specify the optional keyword binary after the filename.
|
||||
#===============================================================================
|
||||
|
||||
set $LoopNum = ($RamFileSize / $FLASHDATBUFSIZE)
|
||||
printf "LoopNum = %x\n", $LoopNum
|
||||
set $TailSize = ($RamFileSize % $FLASHDATBUFSIZE)
|
||||
printf "TailSize = %x\n", $TailSize
|
||||
|
||||
printf "global variables\n"
|
||||
|
||||
set $FLASHDATSRC = 0x0
|
||||
set $FILESTARTADDR = 0X0
|
||||
set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE
|
||||
|
||||
#b RtlFlashProgram:StartOfFlashBlockWrite
|
||||
b rtl_flash_download.c:489
|
||||
b rtl_flash_download.c:524
|
||||
#b Rtl_flash_control.c:RtlFlashProgram
|
||||
|
||||
#continue to 489
|
||||
c
|
||||
|
||||
# Mode 0: erase full chip, Mode 1: skip calibration section and erase to firmware size
|
||||
set EraseMode=1
|
||||
print EraseMode
|
||||
set FirmwareSize=$RamFileSize
|
||||
print FirmwareSize
|
||||
|
||||
#continue to 524
|
||||
c
|
||||
|
||||
#printf "...\n"
|
||||
set $FLASHDATSRC = FlashDatSrc
|
||||
printf "FlashDatSrc:%x\n", $FLASHDATSRC
|
||||
|
||||
printf "FlashBlockWriteSize "
|
||||
set FlashBlockWriteSize = $FLASHDATBUFSIZE
|
||||
#p /x FlashBlockWriteSize
|
||||
printf "FlashBlockWriteSize:%x\n", FlashBlockWriteSize
|
||||
|
||||
printf "FlashAddrForWrite"
|
||||
set FlashAddrForWrite = 0x0
|
||||
|
||||
|
||||
|
||||
printf "Flash write start...\n"
|
||||
set $LoopCnt = 0
|
||||
while ($LoopCnt < $LoopNum)
|
||||
p /x FlashAddrForWrite
|
||||
restore ./Debug/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR
|
||||
c
|
||||
|
||||
printf "FILEENDADDR"
|
||||
p /x $FILEENDADDR
|
||||
set FlashBlockWriteSize = $FLASHDATBUFSIZE
|
||||
set FlashAddrForWrite = $FILEENDADDR
|
||||
set $FILESTARTADDR = $FILEENDADDR
|
||||
set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE
|
||||
|
||||
set $LoopCnt = $LoopCnt + 0x01
|
||||
end
|
||||
|
||||
#set FlashBlockWriteSize = $FLASHDATBUFSIZE
|
||||
#set FlashAddrForWrite = $FILEENDADDR
|
||||
#set $FILESTARTADDR = $FILEENDADDR
|
||||
set $FILEENDADDR = $FILESTARTADDR + $TailSize
|
||||
restore ./Debug/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR
|
||||
c
|
||||
|
||||
#Set complete flas
|
||||
set FlashWriteComplete = 0x1
|
||||
|
||||
printf "dump for check\n"
|
||||
|
||||
set $LoopCnt = 0
|
||||
set $dumpaddr = 0
|
||||
|
||||
set $dumpstartaddr = $SPI_FLASH_BASE
|
||||
set $dumpendaddr = $SPI_FLASH_BASE + $RamFileSize
|
||||
printf "start addr of dumping"
|
||||
p /x $dumpstartaddr
|
||||
printf "end addr of dumping"
|
||||
p /x $dumpendaddr
|
||||
dump binary memory ./Debug/dump.bin $dumpstartaddr $dumpendaddr
|
||||
|
||||
|
||||
delete
|
||||
b rtl_flash_download.c:556
|
||||
c
|
||||
|
||||
quit
|
||||
#===============================================================================
|
||||
|
||||
198
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/rtl_eclipse_flash_write_openocd.txt
vendored
Normal file
198
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/eclipse/rtl_eclipse_flash_write_openocd.txt
vendored
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
# GDB script for loading ram.bin process
|
||||
|
||||
#===============================================================================
|
||||
#set GDB connection
|
||||
set remotetimeout 100000
|
||||
target remote :3333
|
||||
|
||||
#===============================================================================
|
||||
#set file path
|
||||
set $BINFILE = "./Debug/ram_all.bin"
|
||||
|
||||
#===============================================================================
|
||||
#Message display setting
|
||||
#disable all messages
|
||||
|
||||
set verbose off
|
||||
set complaints 0
|
||||
set confirm off
|
||||
set exec-done-display off
|
||||
show exec-done-display
|
||||
set trace-commands off
|
||||
#set debug aix-thread off
|
||||
#set debug dwarf2-die 0
|
||||
set debug displaced off
|
||||
set debug expression 0
|
||||
set debug frame 0
|
||||
set debug infrun 0
|
||||
set debug observer 0
|
||||
set debug overload 0
|
||||
set debugvarobj 0
|
||||
set pagination off
|
||||
set print address off
|
||||
set print symbol-filename off
|
||||
set print symbol off
|
||||
set print pretty off
|
||||
set print object off
|
||||
#set debug notification off
|
||||
set debug parser off
|
||||
set debug remote 0
|
||||
|
||||
#===============================================================================
|
||||
#set JTAG and external SRAM
|
||||
monitor reset init
|
||||
monitor halt
|
||||
monitor sleep 20
|
||||
#===============================================================================
|
||||
#Variables declaration (1)
|
||||
#binary file size
|
||||
set $RamFileSize = 0x0000
|
||||
source ./Debug/fwsize.gdb
|
||||
printf "-------------------------------\n"
|
||||
printf "RamFileSize: %x\n",$RamFileSize
|
||||
printf "-------------------------------\n"
|
||||
|
||||
#===============================================================================
|
||||
set $FLASHDATBUFSIZE = 0x800
|
||||
|
||||
#===============================================================================
|
||||
#define PERI_ON_BASE 0x40000000
|
||||
set $PERI_ON_BASE = 0x40000000
|
||||
#define REG_SOC_PERI_FUNC0_EN 0x0218
|
||||
set $REG_SOC_PERI_FUNC0_EN = 0x0210
|
||||
|
||||
#define SPI_FLASH_BASE 0x4000000
|
||||
set $SPI_FLASH_BASE = 0x98000000
|
||||
|
||||
#------------------------------------------------------------------
|
||||
set $Temp = 0x0
|
||||
|
||||
#===============================================================================
|
||||
#Load flash download file
|
||||
file ../../../../../component/soc/realtek/8195a/misc/gcc_utility/target_NORMAL.axf
|
||||
|
||||
#Load the file
|
||||
lo
|
||||
|
||||
printf "Load flash controller.\n"
|
||||
#===============================================================================
|
||||
#Set for executing flash controller funciton
|
||||
set $Temp = {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN)
|
||||
p /x $Temp
|
||||
|
||||
set $Temp = ($Temp | (0x01 << 27))
|
||||
p /x $Temp
|
||||
|
||||
set {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) = $Temp
|
||||
printf "....\n"
|
||||
printf "wakeup bit(%x):%x\n", ($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN), {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN)
|
||||
#===============================================================================
|
||||
#Direct the startup wake function to flash program function
|
||||
#the function pointer address
|
||||
#set $testpointer = 0x200006b4
|
||||
#set $testpointer2 = 0x200006b8
|
||||
#set $FuntionPointer = 0x200006c4
|
||||
#set $FPTemp = 0x200a08e9
|
||||
#set {int}($FuntionPointer) = $FPTemp
|
||||
#printf "testpointer(%x):%x\n", $testpointer, {int}$testpointer
|
||||
#printf "testpointer2(%x):%x\n", $testpointer2, {int}$testpointer2
|
||||
#printf "FuntionPointer(%x):%x\n", $FuntionPointer, {int}$FuntionPointer
|
||||
|
||||
#===============================================================================
|
||||
#Load file
|
||||
# restore filename [binary] bias start end
|
||||
# Restore the contents of file filename into memory.
|
||||
# The restore command can automatically recognize any known bfd file format, except for raw binary.
|
||||
# To restore a raw binary file you must specify the optional keyword binary after the filename.
|
||||
#===============================================================================
|
||||
|
||||
set $LoopNum = ($RamFileSize / $FLASHDATBUFSIZE)
|
||||
printf "LoopNum = %x\n", $LoopNum
|
||||
set $TailSize = ($RamFileSize % $FLASHDATBUFSIZE)
|
||||
printf "TailSize = %x\n", $TailSize
|
||||
|
||||
printf "global variables\n"
|
||||
|
||||
set $FLASHDATSRC = 0x0
|
||||
set $FILESTARTADDR = 0X0
|
||||
set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE
|
||||
|
||||
#b RtlFlashProgram:StartOfFlashBlockWrite
|
||||
b rtl_flash_download.c:489
|
||||
b rtl_flash_download.c:524
|
||||
#b Rtl_flash_control.c:RtlFlashProgram
|
||||
|
||||
#continue to 489
|
||||
c
|
||||
|
||||
# Mode 0: erase full chip, Mode 1: skip calibration section and erase to firmware size
|
||||
set EraseMode=1
|
||||
print EraseMode
|
||||
set FirmwareSize=$RamFileSize
|
||||
print FirmwareSize
|
||||
|
||||
#continue to 524
|
||||
c
|
||||
|
||||
#printf "...\n"
|
||||
set $FLASHDATSRC = FlashDatSrc
|
||||
printf "FlashDatSrc:%x\n", $FLASHDATSRC
|
||||
|
||||
printf "FlashBlockWriteSize "
|
||||
set FlashBlockWriteSize = $FLASHDATBUFSIZE
|
||||
#p /x FlashBlockWriteSize
|
||||
printf "FlashBlockWriteSize:%x\n", FlashBlockWriteSize
|
||||
|
||||
printf "FlashAddrForWrite"
|
||||
set FlashAddrForWrite = 0x0
|
||||
|
||||
|
||||
|
||||
printf "Flash write start...\n"
|
||||
set $LoopCnt = 0
|
||||
while ($LoopCnt < $LoopNum)
|
||||
p /x FlashAddrForWrite
|
||||
restore ./Debug/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR
|
||||
c
|
||||
|
||||
printf "FILEENDADDR"
|
||||
p /x $FILEENDADDR
|
||||
set FlashBlockWriteSize = $FLASHDATBUFSIZE
|
||||
set FlashAddrForWrite = $FILEENDADDR
|
||||
set $FILESTARTADDR = $FILEENDADDR
|
||||
set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE
|
||||
|
||||
set $LoopCnt = $LoopCnt + 0x01
|
||||
end
|
||||
|
||||
#set FlashBlockWriteSize = $FLASHDATBUFSIZE
|
||||
#set FlashAddrForWrite = $FILEENDADDR
|
||||
#set $FILESTARTADDR = $FILEENDADDR
|
||||
set $FILEENDADDR = $FILESTARTADDR + $TailSize
|
||||
restore ./Debug/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR
|
||||
c
|
||||
|
||||
#Set complete flas
|
||||
set FlashWriteComplete = 0x1
|
||||
|
||||
printf "dump for check\n"
|
||||
|
||||
set $LoopCnt = 0
|
||||
set $dumpaddr = 0
|
||||
|
||||
set $dumpstartaddr = $SPI_FLASH_BASE
|
||||
set $dumpendaddr = $SPI_FLASH_BASE + $RamFileSize
|
||||
printf "start addr of dumping"
|
||||
p /x $dumpstartaddr
|
||||
printf "end addr of dumping"
|
||||
p /x $dumpendaddr
|
||||
dump binary memory ./Debug/dump.bin $dumpstartaddr $dumpendaddr
|
||||
|
||||
|
||||
delete
|
||||
b rtl_flash_download.c:556
|
||||
c
|
||||
|
||||
quit
|
||||
#===============================================================================
|
||||
|
||||
124
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/openocd/ameba1.cfg
vendored
Normal file
124
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/openocd/ameba1.cfg
vendored
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
# Main file for Ameba1 series Cortex-M3 parts
|
||||
#
|
||||
# !!!!!!
|
||||
#
|
||||
|
||||
set CHIPNAME rtl8195a
|
||||
set CHIPSERIES ameba1
|
||||
|
||||
# Adapt based on what transport is active.
|
||||
source [find target/swj-dp.tcl]
|
||||
|
||||
if { [info exists CHIPNAME] } {
|
||||
set _CHIPNAME $CHIPNAME
|
||||
} else {
|
||||
error "CHIPNAME not set. Please do not include ameba1.cfg directly."
|
||||
}
|
||||
|
||||
if { [info exists CHIPSERIES] } {
|
||||
# Validate chip series is supported
|
||||
if { $CHIPSERIES != "ameba1" } {
|
||||
error "Unsupported chip series specified."
|
||||
}
|
||||
set _CHIPSERIES $CHIPSERIES
|
||||
} else {
|
||||
error "CHIPSERIES not set. Please do not include ameba1.cfg directly."
|
||||
}
|
||||
|
||||
if { [info exists CPUTAPID] } {
|
||||
# Allow user override
|
||||
set _CPUTAPID $CPUTAPID
|
||||
} else {
|
||||
# Ameba1 use a Cortex M3 core.
|
||||
if { $_CHIPSERIES == "ameba1" } {
|
||||
if { [using_jtag] } {
|
||||
set _CPUTAPID 0x4ba00477
|
||||
} {
|
||||
set _CPUTAPID 0x2ba01477
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
|
||||
|
||||
set _TARGETNAME $_CHIPNAME.cpu
|
||||
target create $_TARGETNAME cortex_m -chain-position $_TARGETNAME
|
||||
|
||||
|
||||
# Run with *real slow* clock by default since the
|
||||
# boot rom could have been playing with the PLL, so
|
||||
# we have no idea what clock the target is running at.
|
||||
adapter_khz 10
|
||||
|
||||
# delays on reset lines
|
||||
adapter_nsrst_delay 200
|
||||
if {[using_jtag]} {
|
||||
jtag_ntrst_delay 200
|
||||
}
|
||||
|
||||
|
||||
# Ameba1 (Cortex M3 core) support SYSRESETREQ
|
||||
if {![using_hla]} {
|
||||
# if srst is not fitted use SYSRESETREQ to
|
||||
# perform a soft reset
|
||||
cortex_m reset_config sysresetreq
|
||||
}
|
||||
|
||||
$_TARGETNAME configure -event reset-init {ameba1_init}
|
||||
|
||||
# Ameba1 SDRAM enable
|
||||
proc ameba1_init { } {
|
||||
# init System
|
||||
mww 0x40000014 0x00000021
|
||||
sleep 10
|
||||
mww 0x40000304 0x1fc00002
|
||||
sleep 10
|
||||
mww 0x40000250 0x00000400
|
||||
sleep 10
|
||||
mww 0x40000340 0x00000000
|
||||
sleep 10
|
||||
mww 0x40000230 0x0000dcc4
|
||||
sleep 10
|
||||
mww 0x40000210 0x00011117
|
||||
sleep 10
|
||||
mww 0x40000210 0x00011157
|
||||
sleep 10
|
||||
mww 0x400002c0 0x00110011
|
||||
sleep 10
|
||||
mww 0x40000320 0xffffffff
|
||||
sleep 10
|
||||
# init SDRAM
|
||||
mww 0x40000040 0x00fcc702
|
||||
sleep 10
|
||||
mdw 0x40000040
|
||||
mww 0x40005224 0x00000001
|
||||
sleep 10
|
||||
mww 0x40005004 0x00000208
|
||||
sleep 10
|
||||
mww 0x40005008 0xffffd000
|
||||
sleep 13
|
||||
mww 0x40005020 0x00000022
|
||||
sleep 13
|
||||
mww 0x40005010 0x09006201
|
||||
sleep 13
|
||||
mww 0x40005014 0x00002611
|
||||
sleep 13
|
||||
mww 0x40005018 0x00068413
|
||||
sleep 13
|
||||
mww 0x4000501c 0x00000042
|
||||
sleep 13
|
||||
mww 0x4000500c 0x700 ;# set Idle
|
||||
sleep 20
|
||||
mww 0x40005000 0x1 ;# start init
|
||||
sleep 100
|
||||
mdw 0x40005000
|
||||
mww 0x4000500c 0x600 ;# enter memory mode
|
||||
sleep 30
|
||||
|
||||
mww 0x40005008 0x00000000 ;# 0xf00
|
||||
;# mww 0x40005008 0x00000f00
|
||||
sleep 3
|
||||
mww 0x40000300 0x0006005e ;# 0x5e
|
||||
;# mww 0x40000300 0x0000005e
|
||||
sleep 3
|
||||
}
|
||||
BIN
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/ram_all.bin
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/ram_all.bin
vendored
Normal file
Binary file not shown.
124
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/rtl_flash_download.c
vendored
Normal file
124
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/rtl_flash_download.c
vendored
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "rtl8710b.h"
|
||||
#include "build_info.h"
|
||||
|
||||
|
||||
|
||||
#define FLASHDATALEN 2048
|
||||
BOOT_RAM_BSS_SECTION volatile u8 FlashDataBuf[FLASHDATALEN];
|
||||
BOOT_RAM_BSS_SECTION volatile u32 *pFlashDatSrc;
|
||||
BOOT_RAM_BSS_SECTION volatile u32 FlashBlockWriteSize; //The maximum size of each block write is FLASHDATALEN,
|
||||
//The actual value MUST be given by GDB.
|
||||
BOOT_RAM_BSS_SECTION volatile u32 FlashAddrForWrite; //The flash address to be written.
|
||||
//The actual value MUST be given by GDB.
|
||||
BOOT_RAM_BSS_SECTION volatile u8 FlashWriteComplete;
|
||||
BOOT_RAM_BSS_SECTION volatile u32 FlashDatSrc;
|
||||
BOOT_RAM_BSS_SECTION u32 erase_sector_addr = 0;
|
||||
|
||||
extern u8 __rom_bss_start__[];
|
||||
extern u8 __rom_bss_end__[];
|
||||
extern u8 __ram_start_table_start__[];
|
||||
|
||||
extern u32 ConfigDebugErr;
|
||||
extern u32 ConfigDebugInfo;
|
||||
extern u32 ConfigDebugWarn;
|
||||
|
||||
void BOOT_RAM_TEXT_SECTION
|
||||
RtlFlashProgram(VOID)
|
||||
{
|
||||
volatile u32 FlashWriteCnt = 0;
|
||||
u8 flash_ID[3];
|
||||
|
||||
//2 Need Modify
|
||||
VECTOR_TableInit(0x1003EFFC);
|
||||
DBG_8195A("==========================================================\n");
|
||||
DBG_8195A("Flash Downloader Build Time: "UTS_VERSION"\n");
|
||||
DBG_8195A("==========================================================\n");
|
||||
|
||||
FlashDatSrc = (u32)&FlashDataBuf;
|
||||
pFlashDatSrc = (u32 *)&FlashDataBuf;
|
||||
FlashWriteComplete = 0;
|
||||
FlashBlockWriteSize = 0;
|
||||
FlashAddrForWrite = 0;
|
||||
erase_sector_addr = 0;
|
||||
|
||||
Cache_Enable(DISABLE);
|
||||
RCC_PeriphClockCmd(APBPeriph_FLASH, APBPeriph_FLASH_CLOCK, DISABLE);
|
||||
|
||||
/* set 500MHz Div to gen spic clock 200MHz */
|
||||
FLASH_ClockDiv(FLASH_CLK_DIV2P5);
|
||||
RCC_PeriphClockCmd(APBPeriph_FLASH, APBPeriph_FLASH_CLOCK, ENABLE);
|
||||
PinCtrl(PERIPHERAL_SPI_FLASH,S0,ON);
|
||||
|
||||
DBG_8195A("Flash init start\n");
|
||||
FLASH_StructInit(&flash_init_para);
|
||||
FLASH_Init(SpicOneBitMode);
|
||||
DBG_8195A("Flash init done\n");
|
||||
|
||||
FLASH_RxCmd(flash_init_para.FLASH_cmd_rd_id, 3, flash_ID);
|
||||
if(flash_ID[0] == 0x20){
|
||||
flash_init_para.FLASH_cmd_chip_e = 0xC7;}
|
||||
|
||||
//4 Erase the flash before writing it
|
||||
//FLASH_Erase(EraseChip, 0);
|
||||
//DBG_8195A("Flash erace done\n");
|
||||
DBG_8195A("Flash download start\n");
|
||||
//4 Program the flash from memory data
|
||||
while(1)
|
||||
{
|
||||
StartOfFlashBlockWrite:
|
||||
asm("nop");
|
||||
asm("nop");
|
||||
asm("nop");
|
||||
asm("nop");
|
||||
|
||||
FlashWriteCnt = 0;
|
||||
pFlashDatSrc = (u32 *)&FlashDataBuf[0];
|
||||
if (FlashWriteComplete == 1)
|
||||
break;
|
||||
|
||||
while (FlashWriteCnt < FlashBlockWriteSize)
|
||||
{
|
||||
u32 sector_addr1 = FlashAddrForWrite & 0xFFFFF000; /* sector of first byte */
|
||||
|
||||
if(sector_addr1 >= erase_sector_addr) {
|
||||
FLASH_Erase(EraseSector, sector_addr1);
|
||||
erase_sector_addr = sector_addr1 + 0x1000; /* next sector we should erase */
|
||||
}
|
||||
|
||||
FLASH_TxData12B(FlashAddrForWrite, 4, pFlashDatSrc);
|
||||
|
||||
FlashAddrForWrite += 4;
|
||||
FlashWriteCnt += 4;
|
||||
pFlashDatSrc+= 1;
|
||||
}
|
||||
|
||||
goto StartOfFlashBlockWrite;
|
||||
}
|
||||
|
||||
DBG_8195A("Flash download done\n");
|
||||
|
||||
while(1){
|
||||
if (FlashWriteComplete == 1) {
|
||||
FlashWriteComplete = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
57
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/rtl_gdb_debug.txt
vendored
Normal file
57
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/rtl_gdb_debug.txt
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# GDB script for loading ram.bin process
|
||||
|
||||
#===============================================================================
|
||||
#set GDB connection
|
||||
set remotetimeout 100000
|
||||
target remote :3333
|
||||
|
||||
#===============================================================================
|
||||
#Message display setting
|
||||
#disable all messages
|
||||
|
||||
set verbose off
|
||||
set complaints 0
|
||||
set confirm off
|
||||
set exec-done-display off
|
||||
show exec-done-display
|
||||
set trace-commands off
|
||||
#set debug aix-thread off
|
||||
#set debug dwarf2-die 0
|
||||
set debug displaced off
|
||||
set debug expression 0
|
||||
set debug frame 0
|
||||
set debug infrun 0
|
||||
set debug observer 0
|
||||
set debug overload 0
|
||||
set debugvarobj 0
|
||||
set pagination off
|
||||
set print address off
|
||||
set print symbol-filename off
|
||||
set print symbol off
|
||||
set print pretty off
|
||||
set print object off
|
||||
#set debug notification off
|
||||
set debug parser off
|
||||
set debug remote 0
|
||||
|
||||
#===============================================================================
|
||||
monitor reset init
|
||||
monitor sleep 20
|
||||
monitor halt
|
||||
#===============================================================================
|
||||
#Load flash download file
|
||||
file ./application/Debug/bin/application.axf
|
||||
|
||||
#skip sdram init, it has been init in openocd config
|
||||
set {int}0x40000210=0x211157
|
||||
#x /1xw 0x40000210
|
||||
|
||||
b main
|
||||
continue
|
||||
clear main
|
||||
#Load the file
|
||||
#lo
|
||||
|
||||
|
||||
|
||||
|
||||
198
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/rtl_gdb_flash_write.txt
vendored
Normal file
198
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/rtl_gdb_flash_write.txt
vendored
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
# GDB script for loading ram.bin process
|
||||
|
||||
#===============================================================================
|
||||
#set GDB connection
|
||||
set remotetimeout 100000
|
||||
target remote :3333
|
||||
|
||||
#===============================================================================
|
||||
#set file path
|
||||
set $BINFILE = "./application/Debug/bin/ram_all.bin"
|
||||
|
||||
#===============================================================================
|
||||
#Message display setting
|
||||
#disable all messages
|
||||
|
||||
set verbose off
|
||||
set complaints 0
|
||||
set confirm off
|
||||
set exec-done-display off
|
||||
show exec-done-display
|
||||
set trace-commands off
|
||||
#set debug aix-thread off
|
||||
#set debug dwarf2-die 0
|
||||
set debug displaced off
|
||||
set debug expression 0
|
||||
set debug frame 0
|
||||
set debug infrun 0
|
||||
set debug observer 0
|
||||
set debug overload 0
|
||||
set debugvarobj 0
|
||||
set pagination off
|
||||
set print address off
|
||||
set print symbol-filename off
|
||||
set print symbol off
|
||||
set print pretty off
|
||||
set print object off
|
||||
#set debug notification off
|
||||
set debug parser off
|
||||
set debug remote 0
|
||||
|
||||
#===============================================================================
|
||||
#set JTAG and external SRAM
|
||||
monitor reset init
|
||||
monitor halt
|
||||
monitor sleep 20
|
||||
#===============================================================================
|
||||
#Variables declaration (1)
|
||||
#binary file size
|
||||
set $RamFileSize = 0x0000
|
||||
source fwsize.gdb
|
||||
printf "-------------------------------\n"
|
||||
printf "RamFileSize: %x\n",$RamFileSize
|
||||
printf "-------------------------------\n"
|
||||
|
||||
#===============================================================================
|
||||
set $FLASHDATBUFSIZE = 0x800
|
||||
|
||||
#===============================================================================
|
||||
#define PERI_ON_BASE 0x40000000
|
||||
set $PERI_ON_BASE = 0x40000000
|
||||
#define REG_SOC_PERI_FUNC0_EN 0x0218
|
||||
set $REG_SOC_PERI_FUNC0_EN = 0x0210
|
||||
|
||||
#define SPI_FLASH_BASE 0x4000000
|
||||
set $SPI_FLASH_BASE = 0x98000000
|
||||
|
||||
#------------------------------------------------------------------
|
||||
set $Temp = 0x0
|
||||
|
||||
#===============================================================================
|
||||
#Load flash download file
|
||||
file ../../../component/soc/realtek/8195a/misc/gcc_utility/target_NORMAL.axf
|
||||
|
||||
#Load the file
|
||||
lo
|
||||
|
||||
printf "Load flash controller.\n"
|
||||
#===============================================================================
|
||||
#Set for executing flash controller funciton
|
||||
set $Temp = {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN)
|
||||
p /x $Temp
|
||||
|
||||
set $Temp = ($Temp | (0x01 << 27))
|
||||
p /x $Temp
|
||||
|
||||
set {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) = $Temp
|
||||
printf "....\n"
|
||||
printf "wakeup bit(%x):%x\n", ($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN), {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN)
|
||||
#===============================================================================
|
||||
#Direct the startup wake function to flash program function
|
||||
#the function pointer address
|
||||
#set $testpointer = 0x200006b4
|
||||
#set $testpointer2 = 0x200006b8
|
||||
#set $FuntionPointer = 0x200006c4
|
||||
#set $FPTemp = 0x200a08e9
|
||||
#set {int}($FuntionPointer) = $FPTemp
|
||||
#printf "testpointer(%x):%x\n", $testpointer, {int}$testpointer
|
||||
#printf "testpointer2(%x):%x\n", $testpointer2, {int}$testpointer2
|
||||
#printf "FuntionPointer(%x):%x\n", $FuntionPointer, {int}$FuntionPointer
|
||||
|
||||
#===============================================================================
|
||||
#Load file
|
||||
# restore filename [binary] bias start end
|
||||
# Restore the contents of file filename into memory.
|
||||
# The restore command can automatically recognize any known bfd file format, except for raw binary.
|
||||
# To restore a raw binary file you must specify the optional keyword binary after the filename.
|
||||
#===============================================================================
|
||||
|
||||
set $LoopNum = ($RamFileSize / $FLASHDATBUFSIZE)
|
||||
printf "LoopNum = %x\n", $LoopNum
|
||||
set $TailSize = ($RamFileSize % $FLASHDATBUFSIZE)
|
||||
printf "TailSize = %x\n", $TailSize
|
||||
|
||||
printf "global variables\n"
|
||||
|
||||
set $FLASHDATSRC = 0x0
|
||||
set $FILESTARTADDR = 0X0
|
||||
set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE
|
||||
|
||||
#b RtlFlashProgram:StartOfFlashBlockWrite
|
||||
b rtl_flash_download.c:489
|
||||
b rtl_flash_download.c:524
|
||||
#b Rtl_flash_control.c:RtlFlashProgram
|
||||
|
||||
#continue to 489
|
||||
c
|
||||
|
||||
# Mode 0: erase full chip, Mode 1: skip calibration section and erase to firmware size
|
||||
set EraseMode=1
|
||||
print EraseMode
|
||||
set FirmwareSize=$RamFileSize
|
||||
print FirmwareSize
|
||||
|
||||
#continue to 524
|
||||
c
|
||||
|
||||
#printf "...\n"
|
||||
set $FLASHDATSRC = FlashDatSrc
|
||||
printf "FlashDatSrc:%x\n", $FLASHDATSRC
|
||||
|
||||
printf "FlashBlockWriteSize "
|
||||
set FlashBlockWriteSize = $FLASHDATBUFSIZE
|
||||
#p /x FlashBlockWriteSize
|
||||
printf "FlashBlockWriteSize:%x\n", FlashBlockWriteSize
|
||||
|
||||
printf "FlashAddrForWrite"
|
||||
set FlashAddrForWrite = 0x0
|
||||
|
||||
|
||||
|
||||
printf "Flash write start...\n"
|
||||
set $LoopCnt = 0
|
||||
while ($LoopCnt < $LoopNum)
|
||||
p /x FlashAddrForWrite
|
||||
restore ./application/Debug/bin/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR
|
||||
c
|
||||
|
||||
printf "FILEENDADDR"
|
||||
p /x $FILEENDADDR
|
||||
set FlashBlockWriteSize = $FLASHDATBUFSIZE
|
||||
set FlashAddrForWrite = $FILEENDADDR
|
||||
set $FILESTARTADDR = $FILEENDADDR
|
||||
set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE
|
||||
|
||||
set $LoopCnt = $LoopCnt + 0x01
|
||||
end
|
||||
|
||||
#set FlashBlockWriteSize = $FLASHDATBUFSIZE
|
||||
#set FlashAddrForWrite = $FILEENDADDR
|
||||
#set $FILESTARTADDR = $FILEENDADDR
|
||||
set $FILEENDADDR = $FILESTARTADDR + $TailSize
|
||||
restore ./application/Debug/bin/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR
|
||||
c
|
||||
|
||||
#Set complete flas
|
||||
set FlashWriteComplete = 0x1
|
||||
|
||||
printf "dump for check\n"
|
||||
|
||||
set $LoopCnt = 0
|
||||
set $dumpaddr = 0
|
||||
|
||||
set $dumpstartaddr = $SPI_FLASH_BASE
|
||||
set $dumpendaddr = $SPI_FLASH_BASE + $RamFileSize
|
||||
printf "start addr of dumping"
|
||||
p /x $dumpstartaddr
|
||||
printf "end addr of dumping"
|
||||
p /x $dumpendaddr
|
||||
dump binary memory ./application/Debug/bin/dump.bin $dumpstartaddr $dumpendaddr
|
||||
|
||||
|
||||
delete
|
||||
b rtl_flash_download.c:556
|
||||
c
|
||||
|
||||
quit
|
||||
#===============================================================================
|
||||
|
||||
61
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/rtl_gdb_ramdebug.txt
vendored
Normal file
61
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/rtl_gdb_ramdebug.txt
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# GDB script for loading ram.bin process
|
||||
|
||||
#===============================================================================
|
||||
#set GDB connection
|
||||
set remotetimeout 100000
|
||||
target remote :3333
|
||||
|
||||
#===============================================================================
|
||||
#Message display setting
|
||||
#disable all messages
|
||||
|
||||
set verbose off
|
||||
set complaints 0
|
||||
set confirm off
|
||||
set exec-done-display off
|
||||
show exec-done-display
|
||||
set trace-commands off
|
||||
#set debug aix-thread off
|
||||
#set debug dwarf2-die 0
|
||||
set debug displaced off
|
||||
set debug expression 0
|
||||
set debug frame 0
|
||||
set debug infrun 0
|
||||
set debug observer 0
|
||||
set debug overload 0
|
||||
set debug varobj 0
|
||||
set pagination off
|
||||
set print address off
|
||||
set print symbol-filename off
|
||||
set print symbol off
|
||||
set print pretty off
|
||||
set print object off
|
||||
#set debug notification off
|
||||
set debug parser off
|
||||
set debug remote 0
|
||||
|
||||
#===============================================================================
|
||||
monitor reset init
|
||||
monitor sleep 20
|
||||
monitor halt
|
||||
#===============================================================================
|
||||
#Load flash download file
|
||||
#file ./target/Debug/bin/target.axf
|
||||
file ./target/thumbv7m-none-eabi/debug/rustl8710
|
||||
|
||||
#boot from ram, igonore loading flash
|
||||
set {int}0x40000210=0x8011157
|
||||
|
||||
#Load the file
|
||||
lo
|
||||
|
||||
#Run to main
|
||||
b main
|
||||
b main_entry
|
||||
continue
|
||||
clear main
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/target_NORMAL.axf
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/target_NORMAL.axf
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/target_NORMALB.axf
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/target_NORMALB.axf
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/target_NORMALC.axf
vendored
Normal file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/gcc_utility/target_NORMALC.axf
vendored
Normal file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/iar_utility/common/tools/checksum
vendored
Executable file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/iar_utility/common/tools/checksum
vendored
Executable file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/iar_utility/common/tools/padding
vendored
Executable file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/iar_utility/common/tools/padding
vendored
Executable file
Binary file not shown.
BIN
vendor/sdk/component/soc/realtek/8195a/misc/iar_utility/common/tools/pick
vendored
Executable file
BIN
vendor/sdk/component/soc/realtek/8195a/misc/iar_utility/common/tools/pick
vendored
Executable file
Binary file not shown.
307
vendor/sdk/component/soc/realtek/8195a/misc/os/freertos_pmu_8195a.c
vendored
Normal file
307
vendor/sdk/component/soc/realtek/8195a/misc/os/freertos_pmu_8195a.c
vendored
Normal file
|
|
@ -0,0 +1,307 @@
|
|||
#include "FreeRTOS.h"
|
||||
|
||||
#include "freertos_pmu.h"
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#include "platform_autoconf.h"
|
||||
#include "sys_api.h"
|
||||
#include "sleep_ex_api.h"
|
||||
|
||||
#ifndef portNVIC_SYSTICK_CURRENT_VALUE_REG
|
||||
#define portNVIC_SYSTICK_CURRENT_VALUE_REG ( * ( ( volatile uint32_t * ) 0xe000e018 ) )
|
||||
#endif
|
||||
|
||||
uint32_t missing_tick = 0;
|
||||
|
||||
static uint32_t wakelock = DEFAULT_WAKELOCK;
|
||||
static uint32_t wakeup_event = DEFAULT_WAKEUP_EVENT;
|
||||
|
||||
typedef struct {
|
||||
uint32_t nDeviceId;
|
||||
PSM_HOOK_FUN sleep_hook_fun;
|
||||
void* sleep_param_ptr;
|
||||
PSM_HOOK_FUN wakeup_hook_fun;
|
||||
void* wakeup_param_ptr;
|
||||
} PSM_DD_HOOK_INFO;
|
||||
|
||||
#define MAX_PSM_DD_HOOK_INFO_SIZE 8
|
||||
uint32_t psm_dd_hook_info_size = 0;
|
||||
PSM_DD_HOOK_INFO psm_dd_hook_infos[MAX_PSM_DD_HOOK_INFO_SIZE];
|
||||
|
||||
static uint8_t last_wakelock_state[32] = {
|
||||
DEFAULT_WAKELOCK & 0x01, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
static uint32_t last_acquire_wakelock_time[32] = {0};
|
||||
static uint32_t hold_wakelock_time[32] = {0};
|
||||
static uint32_t base_sys_time = 0;
|
||||
|
||||
static uint32_t sys_sleep_time = 0;
|
||||
|
||||
unsigned char reserve_pll = 0;
|
||||
unsigned char generate_wakelock_stats = 0;
|
||||
|
||||
/* ++++++++ FreeRTOS macro implementation ++++++++ */
|
||||
|
||||
/*
|
||||
* It is called in idle task.
|
||||
*
|
||||
* @return true : System is ready to check conditions that if it can enter sleep.
|
||||
* false : System keep awake.
|
||||
**/
|
||||
/*
|
||||
* It is called when freertos is going to sleep.
|
||||
* At this moment, all sleep conditons are satisfied. All freertos' sleep pre-processing are done.
|
||||
*
|
||||
* @param expected_idle_time : The time that FreeRTOS expect to sleep.
|
||||
* If we set this value to 0 then FreeRTOS will do nothing in its sleep function.
|
||||
**/
|
||||
void freertos_pre_sleep_processing(unsigned int *expected_idle_time) {
|
||||
|
||||
#ifdef CONFIG_SOC_PS_MODULE
|
||||
|
||||
uint32_t i;
|
||||
uint32_t stime;
|
||||
uint32_t tick_before_sleep;
|
||||
uint32_t tick_after_sleep;
|
||||
uint32_t tick_passed;
|
||||
uint32_t backup_systick_reg;
|
||||
unsigned char IsDramOn = 1;
|
||||
unsigned char suspend_sdram = 1;
|
||||
|
||||
/* To disable freertos sleep function and use our sleep function,
|
||||
* we can set original expected idle time to 0. */
|
||||
stime = *expected_idle_time;
|
||||
*expected_idle_time = 0;
|
||||
|
||||
for (i=0; i<psm_dd_hook_info_size; i++) {
|
||||
if ( psm_dd_hook_infos[i].sleep_hook_fun != NULL) {
|
||||
psm_dd_hook_infos[i].sleep_hook_fun( stime, psm_dd_hook_infos[i].sleep_param_ptr );
|
||||
}
|
||||
}
|
||||
|
||||
// Store gtimer timestamp before sleep
|
||||
tick_before_sleep = us_ticker_read();
|
||||
|
||||
if ( sys_is_sdram_power_on() == 0 ) {
|
||||
IsDramOn = 0;
|
||||
}
|
||||
|
||||
if (IsDramOn) {
|
||||
#if defined(FREERTOS_PMU_TICKLESS_SUSPEND_SDRAM) && (FREERTOS_PMU_TICKLESS_SUSPEND_SDRAM==0)
|
||||
// sdram is turned on, and we don't want suspend sdram
|
||||
suspend_sdram = 0;
|
||||
#endif
|
||||
} else {
|
||||
// sdram didn't turned on, we should not suspend it
|
||||
suspend_sdram = 0;
|
||||
}
|
||||
|
||||
backup_systick_reg = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||
|
||||
// sleep
|
||||
sleep_ex_selective(wakeup_event, stime, reserve_pll, suspend_sdram);
|
||||
|
||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = backup_systick_reg;
|
||||
|
||||
// update kernel tick by calculating passed tick from gtimer
|
||||
{
|
||||
// get current gtimer timestamp
|
||||
tick_after_sleep = us_ticker_read();
|
||||
|
||||
// calculated passed time
|
||||
if (tick_after_sleep > tick_before_sleep) {
|
||||
tick_passed = tick_after_sleep - tick_before_sleep;
|
||||
} else {
|
||||
// overflow
|
||||
tick_passed = (0xffffffff - tick_before_sleep) + tick_after_sleep;
|
||||
}
|
||||
|
||||
/* If there is a rapid interrupt (<1ms), it makes tick_passed less than 1ms.
|
||||
* The tick_passed would be rounded and make OS can't step tick.
|
||||
* We collect the rounded tick_passed into missing_tick and step tick properly.
|
||||
* */
|
||||
tick_passed += missing_tick;
|
||||
if (tick_passed > stime * 1000) {
|
||||
missing_tick = tick_passed - stime * 1000;
|
||||
tick_passed = stime * 1000;
|
||||
} else {
|
||||
missing_tick = tick_passed % 1000;
|
||||
}
|
||||
|
||||
// update kernel tick
|
||||
vTaskStepTick( tick_passed/1000 );
|
||||
}
|
||||
|
||||
sys_sleep_time += tick_passed/1000;
|
||||
|
||||
for (i=0; i<psm_dd_hook_info_size; i++) {
|
||||
if ( psm_dd_hook_infos[i].wakeup_hook_fun != NULL) {
|
||||
psm_dd_hook_infos[i].wakeup_hook_fun( stime, psm_dd_hook_infos[i].wakeup_param_ptr );
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
// If PS is not enabled, then use freertos sleep function
|
||||
#endif
|
||||
}
|
||||
|
||||
void freertos_post_sleep_processing(unsigned int *expected_idle_time) {
|
||||
#ifndef configSYSTICK_CLOCK_HZ
|
||||
*expected_idle_time = 1 + ( portNVIC_SYSTICK_CURRENT_VALUE_REG / ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) );
|
||||
#else
|
||||
*expected_idle_time = 1 + ( portNVIC_SYSTICK_CURRENT_VALUE_REG / ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) );
|
||||
#endif
|
||||
}
|
||||
/* -------- FreeRTOS macro implementation -------- */
|
||||
|
||||
int freertos_ready_to_sleep() {
|
||||
return wakelock == 0;
|
||||
}
|
||||
|
||||
void pmu_acquire_wakelock(uint32_t lock_id) {
|
||||
|
||||
wakelock |= BIT(lock_id);
|
||||
|
||||
if (generate_wakelock_stats) {
|
||||
uint32_t i;
|
||||
uint32_t current_timestamp = osKernelSysTick();
|
||||
for (i=0; i<32; i++) {
|
||||
if ( (1<<i & BIT(lock_id)) && (last_wakelock_state[i] == 0) ) {
|
||||
last_acquire_wakelock_time[i] = current_timestamp;
|
||||
last_wakelock_state[i] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pmu_release_wakelock(uint32_t lock_id) {
|
||||
wakelock &= ~BIT(lock_id);
|
||||
|
||||
if (generate_wakelock_stats) {
|
||||
uint32_t i;
|
||||
uint32_t current_timestamp = osKernelSysTick();
|
||||
for (i=0; i<32; i++) {
|
||||
if ( (1<<i & BIT(lock_id)) && (last_wakelock_state[i] == 1) ) {
|
||||
hold_wakelock_time[i] += current_timestamp - last_acquire_wakelock_time[i];
|
||||
last_wakelock_state[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t pmu_get_wakelock_status() {
|
||||
return wakelock;
|
||||
}
|
||||
|
||||
void pmu_enable_wakelock_stats(unsigned char enable) {
|
||||
generate_wakelock_stats = enable;
|
||||
}
|
||||
|
||||
void pmu_get_wakelock_hold_stats( char *pcWriteBuffer ) {
|
||||
uint32_t i;
|
||||
uint32_t current_timestamp = osKernelSysTick();
|
||||
|
||||
*pcWriteBuffer = 0x00;
|
||||
|
||||
if (generate_wakelock_stats) {
|
||||
// print header
|
||||
sprintf(pcWriteBuffer, "wakelock_id\tholdtime\r\n");
|
||||
pcWriteBuffer += strlen( pcWriteBuffer );
|
||||
|
||||
for (i=0; i<32; i++) {
|
||||
if (last_wakelock_state[i] == 1) {
|
||||
sprintf(pcWriteBuffer, "%x\t\t%d\r\n", i, hold_wakelock_time[i] + (current_timestamp - last_acquire_wakelock_time[i]));
|
||||
} else {
|
||||
if (hold_wakelock_time[i] > 0) {
|
||||
sprintf(pcWriteBuffer, "%x\t\t%d\r\n", i, hold_wakelock_time[i]);
|
||||
}
|
||||
}
|
||||
pcWriteBuffer += strlen( pcWriteBuffer );
|
||||
}
|
||||
sprintf(pcWriteBuffer, "time passed: %d ms, system sleep %d ms\r\n", current_timestamp - base_sys_time, sys_sleep_time);
|
||||
}
|
||||
}
|
||||
|
||||
void pmu_clean_wakelock_stat() {
|
||||
uint32_t i;
|
||||
base_sys_time = osKernelSysTick();
|
||||
for (i=0; i<32; i++) {
|
||||
hold_wakelock_time[i] = 0;
|
||||
if (last_wakelock_state[i] == 1) {
|
||||
last_acquire_wakelock_time[i] = base_sys_time;
|
||||
}
|
||||
}
|
||||
sys_sleep_time = 0;
|
||||
}
|
||||
|
||||
void pmu_add_wakeup_event(uint32_t event) {
|
||||
wakeup_event |= event;
|
||||
}
|
||||
|
||||
void pmu_del_wakeup_event(uint32_t event) {
|
||||
wakeup_event &= ~event;
|
||||
// To fulfill tickless design, system timer is required to be wakeup event
|
||||
wakeup_event |= SLEEP_WAKEUP_BY_STIMER;
|
||||
}
|
||||
|
||||
void pmu_register_sleep_callback(uint32_t nDeviceId, PSM_HOOK_FUN sleep_hook_fun, void* sleep_param_ptr, PSM_HOOK_FUN wakeup_hook_fun, void* wakeup_param_ptr) {
|
||||
uint32_t i;
|
||||
for (i=0; i<psm_dd_hook_info_size; i++) {
|
||||
if (psm_dd_hook_infos[i].nDeviceId == nDeviceId) {
|
||||
psm_dd_hook_infos[i].sleep_hook_fun = sleep_hook_fun;
|
||||
psm_dd_hook_infos[i].sleep_param_ptr = sleep_param_ptr;
|
||||
psm_dd_hook_infos[i].wakeup_hook_fun = wakeup_hook_fun;
|
||||
psm_dd_hook_infos[i].wakeup_param_ptr = wakeup_param_ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == psm_dd_hook_info_size) {
|
||||
psm_dd_hook_infos[psm_dd_hook_info_size].nDeviceId = nDeviceId;
|
||||
psm_dd_hook_infos[psm_dd_hook_info_size].sleep_hook_fun = sleep_hook_fun;
|
||||
psm_dd_hook_infos[psm_dd_hook_info_size].sleep_param_ptr = sleep_param_ptr;
|
||||
psm_dd_hook_infos[psm_dd_hook_info_size].wakeup_hook_fun = wakeup_hook_fun;
|
||||
psm_dd_hook_infos[psm_dd_hook_info_size].wakeup_param_ptr = wakeup_param_ptr;
|
||||
psm_dd_hook_info_size++;
|
||||
}
|
||||
}
|
||||
|
||||
void pmu_unregister_sleep_callback(uint32_t nDeviceId) {
|
||||
uint32_t i;
|
||||
for (i=0; i<psm_dd_hook_info_size; i++) {
|
||||
if (psm_dd_hook_infos[i].nDeviceId == nDeviceId) {
|
||||
if (psm_dd_hook_info_size > 1) {
|
||||
// if we have more than 2 items, just swap the last item into current slot
|
||||
psm_dd_hook_infos[i].nDeviceId = psm_dd_hook_infos[psm_dd_hook_info_size-1].nDeviceId;
|
||||
psm_dd_hook_infos[i].sleep_hook_fun = psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_hook_fun;
|
||||
psm_dd_hook_infos[i].sleep_param_ptr = psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_param_ptr;
|
||||
psm_dd_hook_infos[i].wakeup_hook_fun = psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_hook_fun;
|
||||
psm_dd_hook_infos[i].wakeup_param_ptr = psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_param_ptr;
|
||||
|
||||
// Then erase the last item
|
||||
psm_dd_hook_infos[psm_dd_hook_info_size-1].nDeviceId = 0;
|
||||
psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_hook_fun = NULL;
|
||||
psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_param_ptr = NULL;
|
||||
psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_hook_fun = NULL;
|
||||
psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_param_ptr = NULL;
|
||||
} else {
|
||||
// we only have one item, just erase it
|
||||
psm_dd_hook_infos[i].nDeviceId = 0;
|
||||
psm_dd_hook_infos[i].sleep_hook_fun = NULL;
|
||||
psm_dd_hook_infos[i].sleep_param_ptr = NULL;
|
||||
psm_dd_hook_infos[i].wakeup_hook_fun = NULL;
|
||||
psm_dd_hook_infos[i].wakeup_param_ptr = NULL;
|
||||
}
|
||||
psm_dd_hook_info_size--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pmu_set_pll_reserved(unsigned char reserve) {
|
||||
reserve_pll = reserve;
|
||||
}
|
||||
|
||||
4
vendor/sdk/component/soc/realtek/8195a/misc/os/freertos_pmu_8195a.h
vendored
Normal file
4
vendor/sdk/component/soc/realtek/8195a/misc/os/freertos_pmu_8195a.h
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _FREERTOS_PMU_8195A_H_
|
||||
#define _FREERTOS_PMU_8195A_H_
|
||||
|
||||
#endif
|
||||
566
vendor/sdk/component/soc/realtek/8195a/misc/os/mailbox.c
vendored
Normal file
566
vendor/sdk/component/soc/realtek/8195a/misc/os/mailbox.c
vendored
Normal file
|
|
@ -0,0 +1,566 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#define _MAILBOX_C_
|
||||
|
||||
#include "mailbox.h"
|
||||
|
||||
/******************************************************************************
|
||||
* Function Prototype Declaration
|
||||
******************************************************************************/
|
||||
static PRTL_MAILBOX RtlMBoxIdToHdl(IN u8 MBoxId);
|
||||
|
||||
PRTL_MAILBOX RtlMailboxCreate(IN u8 MboxID, IN u32 MboxSize, IN _Sema *pWakeSema);
|
||||
|
||||
VOID RtlMailboxDel(IN PRTL_MAILBOX MboxHdl);
|
||||
|
||||
u8 RtlMailboxSendToBack(
|
||||
IN u8 MboxID,
|
||||
IN MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
);
|
||||
|
||||
u8 RtlMailboxSendToFront(
|
||||
IN u8 MboxID,
|
||||
IN MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
);
|
||||
|
||||
u8 RtlMailboxReceive(
|
||||
IN u8 MboxID,
|
||||
OUT MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
);
|
||||
|
||||
u8 RtlMailboxPeek(
|
||||
IN u8 MboxID,
|
||||
OUT MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
);
|
||||
|
||||
u32 RtlMailboxMsgWaiting(
|
||||
IN u8 MboxID,
|
||||
IN u8 IsFromISR
|
||||
);
|
||||
|
||||
/******************************************************************************
|
||||
* Global Variable Declaration
|
||||
******************************************************************************/
|
||||
static RTL_MBOX_ROOT MBox_Entry;
|
||||
|
||||
/******************************************************************************
|
||||
* External Function & Variable Declaration
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlMBoxIdToHdl
|
||||
* Desc: Map a mailbox ID to the mailbox pointer.
|
||||
* Para:
|
||||
* MBoxId: The Mailbox ID
|
||||
* Return: The pointer of the mailbox. If didn't found match mailbox,
|
||||
* return NULL.
|
||||
*
|
||||
******************************************************************************/
|
||||
static PRTL_MAILBOX RtlMBoxIdToHdl(
|
||||
IN u8 MBoxId
|
||||
)
|
||||
{
|
||||
RTL_MAILBOX *pMbox=NULL;
|
||||
RTL_MAILBOX *pTmpMbox;
|
||||
_LIST *pHead;
|
||||
_LIST *pList;
|
||||
|
||||
// if the Mailbox root entry initialed ? if not, initial it
|
||||
if (!MBox_Entry.isInitialed) {
|
||||
RtlMutexInit(&MBox_Entry.Mutex); // Init the Mutex for the mailbox add/delete procedure protection
|
||||
RtlInitListhead(&MBox_Entry.mbox_list); // Init the link list head to chain all created mailbox
|
||||
MBox_Entry.isInitialed = 1;
|
||||
MSG_MBOX_INFO("MBox Entry Initial...\n");
|
||||
}
|
||||
|
||||
pHead = &MBox_Entry.mbox_list;
|
||||
RtlDownMutex(&MBox_Entry.Mutex);
|
||||
pList = RtlListGetNext(&MBox_Entry.mbox_list);
|
||||
while (pList != pHead) {
|
||||
pTmpMbox = CONTAINER_OF(pList, RTL_MAILBOX, mbox_list);
|
||||
if (MBoxId == pTmpMbox->mbox_id) {
|
||||
pMbox = pTmpMbox;
|
||||
break;
|
||||
}
|
||||
pList = RtlListGetNext(pList);
|
||||
}
|
||||
RtlUpMutex(&MBox_Entry.Mutex);
|
||||
|
||||
return pMbox;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlMailboxCreate
|
||||
* Desc: To create a mailbox with a given mailbox ID and size
|
||||
* Para:
|
||||
* MboxID: A number to identify this created mailbox. A message block can
|
||||
* be send to a mailbox by a given MboxID. The MboxID must be unique
|
||||
* in the whole system. If this MboxID is conflict with a created
|
||||
* mailbox, the mailbox creation will fail and return NULL.
|
||||
* MboxSize: The size of this mailbox to be created. It means maximum number
|
||||
* of message blocks can be stored in this mailbox.
|
||||
* pWakeSema: The semaphore to wake up the receiving task to receive the new
|
||||
* message. If the receiving task doesn't need a semaphore to wakeup
|
||||
* it, then just let this pointer is NULL.
|
||||
* Return: The created mailbox pointer. If it failed, return NULL.
|
||||
******************************************************************************/
|
||||
PRTL_MAILBOX RtlMailboxCreate(
|
||||
IN u8 MboxID,
|
||||
IN u32 MboxSize,
|
||||
IN _Sema *pWakeSema
|
||||
)
|
||||
{
|
||||
PRTL_MAILBOX pMBox=NULL;
|
||||
|
||||
// if the Mailbox root entry initialed ? if not, initial it
|
||||
if (!MBox_Entry.isInitialed) {
|
||||
RtlMutexInit(&MBox_Entry.Mutex); // Init the Mutex for the mailbox add/delete procedure protection
|
||||
RtlInitListhead(&MBox_Entry.mbox_list); // Init the link list head to chain all created mailbox
|
||||
MBox_Entry.isInitialed = 1;
|
||||
MSG_MBOX_INFO("MBox Entry Initial...\n");
|
||||
}
|
||||
|
||||
// check if this mailbox ID is ocupied ?
|
||||
pMBox = RtlMBoxIdToHdl(MboxID);
|
||||
if (NULL != pMBox) {
|
||||
MSG_MBOX_ERR("RtlMailboxCreate: The Mailbox ID %d is used by someone!!\n", MboxID);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pMBox = (RTL_MAILBOX *)RtlZmalloc(sizeof(RTL_MAILBOX));
|
||||
if (NULL==pMBox) {
|
||||
MSG_MBOX_ERR("RtlMailboxCreate: MAlloc Failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RtlInitListhead(&pMBox->mbox_list); // Init the link list to be chained into the created mailbox list
|
||||
pMBox->mbox_id = MboxID;
|
||||
pMBox->pWakeSema = pWakeSema;
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
pMBox->mbox_hdl = xQueueCreate(MboxSize, sizeof(MSG_BLK));
|
||||
if (NULL == pMBox->mbox_hdl) {
|
||||
MSG_MBOX_ERR("RtlMailboxCreate: xQueueCreate Failed\n");
|
||||
RtlMfree((void *)pMBox, sizeof(RTL_MAILBOX));
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
#ifdef PLATFORM_ECOS
|
||||
// TODO: Create mailbox
|
||||
#endif
|
||||
|
||||
// Add this mailbox to the link list of created mailbox
|
||||
RtlDownMutex(&MBox_Entry.Mutex);
|
||||
RtlListInsertTail(&pMBox->mbox_list, &MBox_Entry.mbox_list);
|
||||
RtlUpMutex(&MBox_Entry.Mutex);
|
||||
|
||||
MSG_MBOX_INFO("A Mailbox Created: Size=%d\n", MboxSize);
|
||||
|
||||
return pMBox;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlMailboxDel
|
||||
* Desc: To delete a mailbox by a given mailbox handle.
|
||||
* Para:
|
||||
* MboxHdl: The handle of the mailbox to be deleted.
|
||||
* Return: None.
|
||||
******************************************************************************/
|
||||
VOID RtlMailboxDel(
|
||||
IN PRTL_MAILBOX MboxHdl
|
||||
)
|
||||
{
|
||||
if (NULL == MboxHdl) {
|
||||
MSG_MBOX_ERR("RtlMailboxDel: Try to delete a NULL mailbox\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove this mailbox from the link list of created mailbox
|
||||
RtlDownMutex(&MBox_Entry.Mutex);
|
||||
RtlListDelete(&MboxHdl->mbox_list);
|
||||
RtlUpMutex(&MBox_Entry.Mutex);
|
||||
|
||||
// delete the Queue/Mailbox
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
vQueueDelete((xQueueHandle)(MboxHdl->mbox_hdl));
|
||||
#endif
|
||||
#ifdef PLATFORM_ECOS
|
||||
// TODO: Delete mailbox
|
||||
#endif
|
||||
|
||||
RtlMfree((void *)MboxHdl, sizeof(RTL_MAILBOX));
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlMailboxSendToBack
|
||||
* Desc: To put a message block to the tail of a given mailbox.
|
||||
* Para:
|
||||
* MboxID: The identifier of the target mailbox.
|
||||
* pMsg: The pointer of the message block to be put into the mailbox.
|
||||
* MSToWait: If the mailbox is full, this value gives a time to wait to put
|
||||
* this message. The time unit is millisecond.
|
||||
* The special values are:
|
||||
* 0: no waiting;
|
||||
* 0xffffffff: wait without timeout.
|
||||
* If the waiting is timeout, the message sending is failed and
|
||||
* return _FAIL.
|
||||
* IsFromISR: Is this function is called from an ISR ?
|
||||
* Return: _SUCCESS or _FAIL.
|
||||
******************************************************************************/
|
||||
u8 RtlMailboxSendToBack(
|
||||
IN u8 MboxID,
|
||||
IN MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
)
|
||||
{
|
||||
RTL_MAILBOX *pMbox=NULL;
|
||||
u32 wait_ticks;
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
portBASE_TYPE ret;
|
||||
#endif
|
||||
|
||||
pMbox = RtlMBoxIdToHdl(MboxID);
|
||||
|
||||
if (NULL == pMbox) {
|
||||
MSG_MBOX_ERR("RtlMailboxSendToBack: Didn't find matched MBoxID=%d\n", MboxID);
|
||||
return _FAIL;
|
||||
}
|
||||
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
if (MBOX_WAIT_NO_TIMEOUT == MSToWait) {
|
||||
wait_ticks = portMAX_DELAY;
|
||||
}
|
||||
else if (MBOX_WAIT_NONE == MSToWait) {
|
||||
wait_ticks = 0;
|
||||
}
|
||||
else {
|
||||
wait_ticks = ((MSToWait/portTICK_RATE_MS)>0)?(MSToWait/portTICK_RATE_MS):(1);
|
||||
}
|
||||
|
||||
if (IsFromISR) {
|
||||
ret = xQueueSendToBackFromISR(pMbox->mbox_hdl, (void *)pMsg, NULL);//(portTickType) wait_ticks);
|
||||
}
|
||||
else {
|
||||
ret = xQueueSendToBack(pMbox->mbox_hdl, (void *)pMsg, (portTickType) wait_ticks);
|
||||
}
|
||||
|
||||
if(ret != pdPASS ) {
|
||||
// send message to the queue failed
|
||||
MSG_MBOX_ERR("RtlMailboxSendToBack: Put Msg to Queue Failed, MBoxID=%d\n", MboxID);
|
||||
ret = _FAIL;
|
||||
}
|
||||
else {
|
||||
// try to give a semaphore to wake up the receiving task
|
||||
if (pMbox->pWakeSema) {
|
||||
RtlUpSema(pMbox->pWakeSema);
|
||||
}
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_ECOS
|
||||
// TODO: Put the message to a mailbox
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlMailboxSendToFront
|
||||
* Desc: To put a message block to the head of a mailbox.
|
||||
* Para:
|
||||
* MboxID: The identifier of the target mailbox.
|
||||
* pMsg: The pointer of the message block to be put into the mailbox.
|
||||
* MSToWait: If the mailbox is full, this value gives a time to wait to put
|
||||
* this message. The time unit is millisecond.
|
||||
* The special values are:
|
||||
* 0: no waiting;
|
||||
* 0xffffffff: wait without timeout.
|
||||
* If the waiting is timeout, the message sending is failed and
|
||||
* return _FAIL.
|
||||
* IsFromISR: Is this function is called from an ISR ?
|
||||
* Return: _SUCCESS or _FAIL.
|
||||
******************************************************************************/
|
||||
u8 RtlMailboxSendToFront(
|
||||
IN u8 MboxID,
|
||||
IN MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
)
|
||||
{
|
||||
RTL_MAILBOX *pMbox=NULL;
|
||||
u32 wait_ticks;
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
portBASE_TYPE ret;
|
||||
#endif
|
||||
|
||||
pMbox = RtlMBoxIdToHdl(MboxID);
|
||||
|
||||
if (NULL == pMbox) {
|
||||
MSG_MBOX_ERR("RtlMailboxSendToBack: Didn't find matched MBoxID=%d\n", MboxID);
|
||||
return _FAIL;
|
||||
}
|
||||
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
if (MBOX_WAIT_NO_TIMEOUT == MSToWait) {
|
||||
wait_ticks = portMAX_DELAY;
|
||||
}
|
||||
else if (MBOX_WAIT_NONE == MSToWait) {
|
||||
wait_ticks = 0;
|
||||
}
|
||||
else {
|
||||
wait_ticks = ((MSToWait/portTICK_RATE_MS)>0)?(MSToWait/portTICK_RATE_MS):(1);
|
||||
}
|
||||
|
||||
if (IsFromISR) {
|
||||
ret = xQueueSendToFrontFromISR(pMbox->mbox_hdl, (void *)pMsg, NULL);//(portTickType) wait_ticks);
|
||||
}
|
||||
else {
|
||||
ret = xQueueSendToFront(pMbox->mbox_hdl, (void *)pMsg, (portTickType) wait_ticks);
|
||||
}
|
||||
|
||||
if(ret != pdPASS ) {
|
||||
// send message to the queue failed
|
||||
MSG_MBOX_ERR("RtlMailboxSendToBack: Put Msg to Queue Failed, MBoxID=%d\n", MboxID);
|
||||
ret = _FAIL;
|
||||
}
|
||||
else {
|
||||
// try to give a semaphore to wake up the receiving task
|
||||
if (pMbox->pWakeSema) {
|
||||
RtlUpSema(pMbox->pWakeSema);
|
||||
}
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_ECOS
|
||||
// TODO: eCos has no API to put message to the head of a mailbox
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlMailboxSendToFront
|
||||
* Desc: To get a message block from a given mailbox.
|
||||
* Para:
|
||||
* MboxID: The identifier of the target mailbox.
|
||||
* pMsg: The message block to store the gotten message.
|
||||
* MSToWait: If the mailbox is full, this value gives a time to wait to put
|
||||
* this message. The time unit is millisecond.
|
||||
* The special values are:
|
||||
* 0: no waiting;
|
||||
* 0xffffffff: wait without timeout.
|
||||
* If the waiting is timeout, the message sending is failed and
|
||||
* return _FAIL.
|
||||
* IsFromISR: Is this function is called from an ISR ?
|
||||
* Return: _SUCCESS or _FAIL.
|
||||
******************************************************************************/
|
||||
u8 RtlMailboxReceive(
|
||||
IN u8 MboxID,
|
||||
OUT MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
)
|
||||
{
|
||||
RTL_MAILBOX *pMbox=NULL;
|
||||
u32 wait_ticks;
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
portBASE_TYPE ret;
|
||||
#endif
|
||||
|
||||
pMbox = RtlMBoxIdToHdl(MboxID);
|
||||
|
||||
if (NULL == pMbox) {
|
||||
MSG_MBOX_ERR("RtlMailboxReceive: Didn't find the MBox with ID=%d\n", MboxID);
|
||||
return _FAIL;
|
||||
}
|
||||
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
if (MBOX_WAIT_NONE == MSToWait) {
|
||||
wait_ticks = 0;
|
||||
}
|
||||
else if (MBOX_WAIT_NO_TIMEOUT == MSToWait) {
|
||||
wait_ticks = portMAX_DELAY;
|
||||
}
|
||||
else {
|
||||
wait_ticks = ((MSToWait/portTICK_RATE_MS)>0)?(MSToWait/portTICK_RATE_MS):(1);
|
||||
}
|
||||
|
||||
if (IsFromISR) {
|
||||
ret = xQueueReceiveFromISR(pMbox->mbox_hdl, (void *)pMsg, NULL);//( portTickType ) wait_ticks);
|
||||
}
|
||||
else {
|
||||
ret = xQueueReceive(pMbox->mbox_hdl, (void *)pMsg, ( portTickType ) wait_ticks);
|
||||
|
||||
}
|
||||
|
||||
if(ret != pdTRUE ) {
|
||||
// receive message failed
|
||||
if (0 != MSToWait) {
|
||||
MSG_MBOX_ERR("RtlMailboxReceive: Receive Msg Failed, MBoxID=%d\n", MboxID);
|
||||
}
|
||||
ret = _FAIL;
|
||||
}
|
||||
else {
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_ECOS
|
||||
// TODO: Get a message from the mailbox
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlMailboxPeek
|
||||
* Desc: To copy the head message from a given mailbox without move this
|
||||
* message block out from the mailbox.
|
||||
* Para:
|
||||
* MboxID: The identifier of the target mailbox.
|
||||
* pMsg: The message block to store the gotten message.
|
||||
* MSToWait: If the mailbox is full, this value gives a time to wait to put
|
||||
* this message. The time unit is millisecond.
|
||||
* The special values are:
|
||||
* 0: no waiting;
|
||||
* 0xffffffff: wait without timeout.
|
||||
* If the waiting is timeout, the message sending is failed and
|
||||
* return _FAIL.
|
||||
* IsFromISR: Is this function is called from an ISR ?
|
||||
* Return: _SUCCESS or _FAIL.
|
||||
******************************************************************************/
|
||||
u8 RtlMailboxPeek(
|
||||
IN u8 MboxID,
|
||||
OUT MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
)
|
||||
{
|
||||
RTL_MAILBOX *pMbox=NULL;
|
||||
u32 wait_ticks;
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
portBASE_TYPE ret;
|
||||
#endif
|
||||
|
||||
pMbox = RtlMBoxIdToHdl(MboxID);
|
||||
|
||||
if (NULL == pMbox) {
|
||||
MSG_MBOX_ERR("RtlMailboxPeek: Didn't find the MBox with ID=%d\n", MboxID);
|
||||
return _FAIL;
|
||||
}
|
||||
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
if (MBOX_WAIT_NONE == MSToWait) {
|
||||
wait_ticks = 0;
|
||||
}
|
||||
else if (MBOX_WAIT_NO_TIMEOUT == MSToWait) {
|
||||
wait_ticks = portMAX_DELAY;
|
||||
}
|
||||
else {
|
||||
wait_ticks = ((MSToWait/portTICK_RATE_MS)>0)?(MSToWait/portTICK_RATE_MS):(1);
|
||||
}
|
||||
|
||||
if (IsFromISR) {
|
||||
// ret = xQueuePeekFromISR(pMbox->mbox_hdl, (void *)pMsg, ( portTickType ) wait_ticks);
|
||||
// TODO: check why we have no "xQueuePeekFromISR"
|
||||
MSG_MBOX_ERR("RtlMailboxPeek: Current version has no 'xQueuePeekFromISR'\n");
|
||||
ret = pdFALSE;
|
||||
}
|
||||
else {
|
||||
ret = xQueuePeek(pMbox->mbox_hdl, (void *)pMsg, ( portTickType ) wait_ticks);
|
||||
|
||||
}
|
||||
|
||||
if(ret != pdTRUE ) {
|
||||
// receive message failed
|
||||
MSG_MBOX_ERR("RtlMailboxReceive: Receive Msg Failed, MBoxID=%d\n", MboxID);
|
||||
ret = _FAIL;
|
||||
}
|
||||
else {
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_ECOS
|
||||
// TODO: Get a message from the mailbox
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlMailboxMsgWaiting
|
||||
* Desc: To get the number of message blocks are storing in a given mailbox.
|
||||
* Para:
|
||||
* MboxID: The identifier of the target mailbox.
|
||||
* IsFromISR: Is this function is called from an ISR ?
|
||||
* Return: The number of message blocks are storing in this mailbox.
|
||||
******************************************************************************/
|
||||
u32 RtlMailboxMsgWaiting(
|
||||
IN u8 MboxID,
|
||||
IN u8 IsFromISR
|
||||
)
|
||||
{
|
||||
RTL_MAILBOX *pMbox=NULL;
|
||||
u32 msg_num=0;
|
||||
|
||||
pMbox = RtlMBoxIdToHdl(MboxID);
|
||||
|
||||
if (NULL == pMbox) {
|
||||
MSG_MBOX_ERR("RtlMailboxMsgWaiting: Didn't find the MBox with ID=%d\n", MboxID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
if (IsFromISR) {
|
||||
msg_num = uxQueueMessagesWaitingFromISR(pMbox->mbox_hdl);
|
||||
}
|
||||
else {
|
||||
msg_num = uxQueueMessagesWaiting(pMbox->mbox_hdl);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_ECOS
|
||||
// TODO: call eCos API to implement this function
|
||||
#endif
|
||||
|
||||
return msg_num;
|
||||
|
||||
}
|
||||
|
||||
127
vendor/sdk/component/soc/realtek/8195a/misc/os/mailbox.h
vendored
Normal file
127
vendor/sdk/component/soc/realtek/8195a/misc/os/mailbox.h
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef __MAILBOX_H_
|
||||
#define __MAILBOX_H_
|
||||
|
||||
#include "hal_api.h"
|
||||
#include "osdep_api.h"
|
||||
#include "hal_util.h"
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
#include "queue.h"
|
||||
#endif
|
||||
|
||||
#define MBOX_WAIT_NO_TIMEOUT 0xffffffff // waiting for send/receive message with no timeout
|
||||
#define MBOX_WAIT_NONE 0 // No wait for send/receive message
|
||||
|
||||
typedef enum _MAILBOX_ID_ {
|
||||
MBOX_ID_WLAN = 0,
|
||||
MBOX_ID_UART = 1,
|
||||
MBOX_ID_I2C = 2,
|
||||
MBOX_ID_I2S = 3,
|
||||
MBOX_ID_SPI = 4,
|
||||
MBOX_ID_SDIO = 5,
|
||||
MBOX_ID_SDIO_MP = 6,
|
||||
|
||||
MBOX_ID_MAX = 0xff
|
||||
} MAILBOX_ID;
|
||||
|
||||
#if defined(CONFIG_SDIO_DEVICE_EN) && defined(CONFIG_SDIO_DEVICE_NORMAL)
|
||||
typedef enum _MSG_TYPE_SDIO {
|
||||
MSG_SDIO_RX_PKT=1, // request to send a SDIO RX packet to the host side
|
||||
MSG_SDIO_C2H=2, // request to send a C2H message
|
||||
MSG_SDIO_RPWM=3, // request to set the RPWM
|
||||
MSG_SDIO_MP_LOOP_TXPKT=4, // request to loopback this TX packet
|
||||
|
||||
MSG_SDIO_MAX=0xff
|
||||
} MSG_TYPE_SDIO;
|
||||
#endif // end of "#ifdef CONFIG_SDIO_DEVICE_EN"
|
||||
|
||||
/* the data structure of a MailBox to deliver message blocks */
|
||||
typedef struct _RTL_MAILBOX_ {
|
||||
void *mbox_hdl; // the mailbox handle which return from OS create queue API
|
||||
_Sema *pWakeSema; // the semaphore to wakeup the message receiving task
|
||||
_LIST mbox_list; // the link list to chain all created mailbox
|
||||
u8 mbox_id; /* the ID of this Mailbox, this ID is
|
||||
used to locate the MBox for send/get message */
|
||||
} RTL_MAILBOX, *PRTL_MAILBOX;
|
||||
|
||||
/* the data structure of a message block */
|
||||
typedef struct _RTL_MSG_BLK {
|
||||
u8 MsgType; // the message type
|
||||
u8 Reserved; // reserved
|
||||
u16 DateLen; // the vaild data length of the pBuf
|
||||
u32 Para; // the optional parameters associated with this message type
|
||||
u8 *pBuf; // point to a data buffer associated with this message type
|
||||
} MSG_BLK, *PMSG_BLK;
|
||||
|
||||
/* the data structure for system level message block management */
|
||||
typedef struct _RTL_MBOX_ROOT_ {
|
||||
_LIST mbox_list; // the link list of all created mailbox
|
||||
_Mutex Mutex; // the Mutex to protect the mailbox create/delete procedure
|
||||
u8 isInitialed; // is this Mailbox link-list initialed
|
||||
} RTL_MBOX_ROOT, *PRTL_MBOX_ROOT;
|
||||
|
||||
// Export Funcction API
|
||||
extern PRTL_MAILBOX RtlMailboxCreate(
|
||||
IN u8 MboxID,
|
||||
IN u32 MboxSize,
|
||||
IN _Sema *pWakeSema
|
||||
);
|
||||
|
||||
extern VOID RtlMailboxDel(
|
||||
IN PRTL_MAILBOX MboxHdl
|
||||
);
|
||||
|
||||
extern u8 RtlMailboxSendToBack(
|
||||
IN u8 MboxID,
|
||||
IN MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
);
|
||||
|
||||
extern u8 RtlMailboxSendToFront(
|
||||
IN u8 MboxID,
|
||||
IN MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
);
|
||||
|
||||
extern u8 RtlMailboxReceive(
|
||||
IN u8 MboxID,
|
||||
OUT MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
);
|
||||
|
||||
extern u8 RtlMailboxPeek(
|
||||
IN u8 MboxID,
|
||||
OUT MSG_BLK *pMsg,
|
||||
IN u32 MSToWait,
|
||||
IN u8 IsFromISR
|
||||
);
|
||||
|
||||
extern u32 RtlMailboxMsgWaiting(
|
||||
IN u8 MboxID,
|
||||
IN u8 IsFromISR
|
||||
);
|
||||
|
||||
|
||||
#endif // #ifndef __MAILBOX_H_
|
||||
|
||||
36
vendor/sdk/component/soc/realtek/8195a/misc/os/os_support.h
vendored
Normal file
36
vendor/sdk/component/soc/realtek/8195a/misc/os/os_support.h
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Name: sys-support.h - System type support for Linux
|
||||
* $Revision: 1.1.1.1 $
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __OS_SUPPORT_H__
|
||||
#define __OS_SUPPORT_H__
|
||||
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <basic_types.h>
|
||||
#include "task.h"
|
||||
#include "osdep_service.h"
|
||||
|
||||
#define RTL_HZ 100
|
||||
|
||||
#define RtlKmalloc(size, flag) pvPortMalloc(size)
|
||||
#define RtlKfree(pv) vPortFreeAligned(pv)
|
||||
|
||||
|
||||
#ifdef CONFIG_TIMER_MODULE
|
||||
#define __Delay(t) HalDelayUs(t)
|
||||
#else
|
||||
static __inline__ u32 __Delay(u32 us)
|
||||
{
|
||||
DBG_8195A("No Delay: please enable hardware Timer\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#define Mdelay(t) __Delay(t*1000)
|
||||
#define Udelay(t) __Delay(t)
|
||||
|
||||
#endif /* __SYS_SUPPORT_H__ */
|
||||
165
vendor/sdk/component/soc/realtek/8195a/misc/os/os_timer.h
vendored
Normal file
165
vendor/sdk/component/soc/realtek/8195a/misc/os/os_timer.h
vendored
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Name: sys-support.h - System type support for Linux
|
||||
* $Revision: 1.1.1.1 $
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __OS_TIMER_H__
|
||||
#define __OS_TIMER_H__
|
||||
|
||||
#include "diag.h"
|
||||
#include "os_support.h"
|
||||
#include "osdep_service.h"
|
||||
|
||||
|
||||
#define JIFFIES xTaskGetTickCount()
|
||||
|
||||
enum {
|
||||
TIMER_NO_INIT = 0,
|
||||
TIMER_INIT = 1,
|
||||
TIMER_START = 2,
|
||||
TIMER_DISABLE = 3
|
||||
};
|
||||
|
||||
struct TIMER_LIST {
|
||||
_timerHandle TimeHdl;
|
||||
u32 Flag;
|
||||
unsigned long Data;
|
||||
VOID (*Function)(void *);
|
||||
u32 TimerID;
|
||||
};
|
||||
|
||||
static inline VOID InitTimer(IN struct TIMER_LIST *Timer)
|
||||
{
|
||||
u32 TimerID = Timer->TimerID;
|
||||
VOID (*Function)(VOID *) = Timer->Function;
|
||||
|
||||
save_and_cli();
|
||||
|
||||
if (Timer->Flag != TIMER_DISABLE) {
|
||||
if (Timer->Flag == TIMER_NO_INIT) {
|
||||
Timer->TimeHdl = rtw_timerCreate( (const char *)"Timer", // Just a test name, not used by the kernel.
|
||||
( 100 ), // The timer period in ticks.
|
||||
_FALSE, // The timers will auto-reload themselves when they expire.
|
||||
( void * ) TimerID, // Assign each timer a unique id equal to its array index.
|
||||
Function
|
||||
#ifdef RTK_MODE_TIMER
|
||||
,data // Each timer calls the same callback when it expires.
|
||||
#endif
|
||||
);
|
||||
if (NULL == Timer->TimeHdl) {
|
||||
DBG_ERROR_LOG("\rInitial Timer fail !!!!!!!!!\n");
|
||||
}
|
||||
else {
|
||||
TimerID++;
|
||||
}
|
||||
|
||||
Timer->Flag = TIMER_INIT;
|
||||
}
|
||||
else if (Timer->Flag == TIMER_START) {
|
||||
rtw_timerStop(Timer->TimeHdl,0);
|
||||
Timer->Flag = TIMER_DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
restore_flags();
|
||||
}
|
||||
|
||||
static inline void ModTimer(IN struct TIMER_LIST *Timer, IN u32 TimeoutTicks)
|
||||
{
|
||||
#ifndef PLATFORM_FREERTOS
|
||||
u32 Flags;
|
||||
#endif
|
||||
|
||||
void (*Function)(void *) = Timer->Function;
|
||||
|
||||
save_and_cli();
|
||||
|
||||
if (Timer->Flag == TIMER_NO_INIT) {
|
||||
if (Timer->Function) {
|
||||
Timer->TimeHdl = rtw_timerCreate((const char *)"Timer", // Just a text name, not used by the kernel.
|
||||
( 100 ), // The timer period in ticks.
|
||||
_FALSE, // The timers will auto-reload themselves when they expire.
|
||||
( void * ) Timer->TimerID, // Assign each timer a unique id equal to its array index.
|
||||
Function
|
||||
#ifdef RTK_MODE_TIMER
|
||||
,Timer->Data // Each timer calls the same callback when it expires.
|
||||
#endif
|
||||
);
|
||||
if (NULL == Timer->TimeHdl) {
|
||||
DBG_ERROR_LOG("\rInitial Timer fail !!!!!!!!!\n");
|
||||
}
|
||||
else {
|
||||
Timer->TimerID++;
|
||||
}
|
||||
|
||||
Timer->Flag = TIMER_INIT;
|
||||
}
|
||||
else {
|
||||
restore_flags();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (Timer->Flag == TIMER_START) {
|
||||
rtw_timerStop(Timer->TimeHdl,0);
|
||||
Timer->Flag = TIMER_DISABLE;
|
||||
}
|
||||
|
||||
TimeoutTicks -= rtw_get_current_time();
|
||||
if (TimeoutTicks <= 0)
|
||||
TimeoutTicks = 2;
|
||||
|
||||
if (xTimerStart(Timer->TimeHdl, TimeoutTicks ))
|
||||
Timer->Flag = TIMER_START;
|
||||
else
|
||||
DBG_ERROR_LOG("\r###mod_timer() - no slots available###\n");
|
||||
restore_flags();
|
||||
}
|
||||
|
||||
|
||||
static inline int TimerPending (IN const struct TIMER_LIST *Timer)
|
||||
{
|
||||
if (Timer->TimeHdl && Timer->Flag != TIMER_NO_INIT)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void DelTimerSync(IN struct TIMER_LIST *Timer)
|
||||
{
|
||||
save_and_cli();
|
||||
|
||||
if (Timer->TimeHdl && Timer->Flag != TIMER_INIT) {
|
||||
if (Timer->Flag == TIMER_START)
|
||||
rtw_timerStop(Timer->TimeHdl, 0);
|
||||
|
||||
rtw_timerDelete(Timer->TimeHdl, 0);
|
||||
Timer->Flag = TIMER_NO_INIT;
|
||||
}
|
||||
|
||||
restore_flags();
|
||||
}
|
||||
|
||||
/*
|
||||
* These inlines deal with timer wrapping correctly. You are
|
||||
* strongly encouraged to use them
|
||||
* 1. Because people otherwise forget
|
||||
* 2. Because if the timer wrap changes in future you wont have to
|
||||
* alter your driver code.
|
||||
*
|
||||
* time_after(a,b) returns true if the time a is after time b.
|
||||
*
|
||||
* Do this with "<0" and ">=0" to only test the sign of the result. A
|
||||
* good compiler would generate better code (and a really good compiler
|
||||
* wouldn't care). Gcc is currently neither.
|
||||
*/
|
||||
#define TIME_AFTER(a,b) ((long)(b) - (long)(a) < 0)
|
||||
#define TIMER_BEFORE(a,b) TIME_AFTER(b,a)
|
||||
|
||||
#define TIME_AFTER_EQ(a,b) ((long)(a) - (long)(b) >= 0)
|
||||
#define TIMER_BEFORE_EQ(a,b) TIME_AFTER_EQ(b,a)
|
||||
|
||||
|
||||
|
||||
#endif //__OS_TIMER_H__
|
||||
535
vendor/sdk/component/soc/realtek/8195a/misc/os/osdep_api.c
vendored
Normal file
535
vendor/sdk/component/soc/realtek/8195a/misc/os/osdep_api.c
vendored
Normal file
|
|
@ -0,0 +1,535 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#define _OSDEP_API_C_
|
||||
|
||||
#include <osdep_api.h>
|
||||
#include "osdep_service.h"
|
||||
|
||||
extern _LONG_CALL_ char *_strcpy(char *dest, const char *src);
|
||||
extern _LONG_CALL_ VOID *_memset(void *dst0, int Val,SIZE_T length);
|
||||
|
||||
u8* RtlMalloc(IN u32 sz)
|
||||
{
|
||||
u8 *pbuf=NULL;
|
||||
|
||||
pbuf = rtw_malloc((u32)sz);
|
||||
|
||||
return pbuf;
|
||||
}
|
||||
|
||||
|
||||
u8* RtlZmalloc(IN u32 sz)
|
||||
{
|
||||
u8 *pbuf;
|
||||
|
||||
pbuf= rtw_malloc((u32)sz);
|
||||
|
||||
if (pbuf != NULL) {
|
||||
_memset(pbuf, 0, sz);
|
||||
}
|
||||
|
||||
return pbuf;
|
||||
}
|
||||
|
||||
VOID RtlMfree(IN u8 *pbuf, IN u32 sz)
|
||||
{
|
||||
rtw_mfree(pbuf, sz);
|
||||
}
|
||||
|
||||
VOID* RtlMalloc2d(IN u32 h, IN u32 w, IN u32 size)
|
||||
{
|
||||
u32 j;
|
||||
|
||||
VOID **a = (VOID **) rtw_malloc2d(h, w, size);
|
||||
if(a == NULL)
|
||||
{
|
||||
DBG_ERROR_LOG("%s: alloc memory fail!\n", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
VOID RtlMfree2d(IN VOID *pbuf, IN u32 h, IN u32 w, IN u32 size)
|
||||
{
|
||||
rtw_mfree2d(pbuf, h, w, size);
|
||||
}
|
||||
|
||||
VOID RtlInitSema(IN _Sema *sema, IN u32 init_val)
|
||||
{
|
||||
rtw_init_sema(sema, init_val);
|
||||
}
|
||||
|
||||
VOID RtlFreeSema(IN _Sema *sema)
|
||||
{
|
||||
rtw_free_sema(sema);
|
||||
}
|
||||
|
||||
VOID RtlUpSema(IN _Sema *sema)
|
||||
{
|
||||
rtw_up_sema(sema);
|
||||
}
|
||||
|
||||
VOID RtlUpSemaFromISR(IN _Sema *sema)
|
||||
{
|
||||
rtw_up_sema_from_isr(sema);
|
||||
}
|
||||
|
||||
u32 RtlDownSema(IN _Sema *sema)
|
||||
{
|
||||
rtw_down_sema(sema);
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
u32 RtlDownSemaWithTimeout(IN _Sema *sema,IN u32 ms)
|
||||
{
|
||||
return rtw_down_timeout_sema(sema, ms);
|
||||
}
|
||||
|
||||
VOID RtlMutexInit(IN _Mutex *pmutex)
|
||||
{
|
||||
rtw_mutex_init(pmutex);
|
||||
}
|
||||
|
||||
VOID RtlMutexFree(IN _Mutex *pmutex)
|
||||
{
|
||||
rtw_mutex_free(pmutex);
|
||||
}
|
||||
|
||||
VOID RtlSpinlockInit(IN _Lock *plock)
|
||||
{
|
||||
rtw_spinlock_init((_lock *)plock);
|
||||
}
|
||||
|
||||
VOID RtlSpinlockFree(IN _Lock *plock)
|
||||
{
|
||||
rtw_spinlock_free((_lock *)plock);
|
||||
}
|
||||
|
||||
VOID RtlSpinlock(IN _Lock *plock)
|
||||
{
|
||||
rtw_spin_lock((_lock *)plock);
|
||||
}
|
||||
|
||||
VOID RtlSpinunlock(IN _Lock *plock)
|
||||
{
|
||||
rtw_spin_unlock((_lock *)plock);
|
||||
}
|
||||
|
||||
VOID RtlSpinlockEx(IN _Lock *plock)
|
||||
{
|
||||
}
|
||||
|
||||
VOID RtlSpinunlockEx(IN _Lock *plock)
|
||||
{
|
||||
}
|
||||
|
||||
u32 RtlGetCurrentTime(VOID)
|
||||
{
|
||||
return rtw_get_current_time();
|
||||
}
|
||||
|
||||
VOID RtlSleepSchedulable(IN u32 ms)
|
||||
{
|
||||
}
|
||||
|
||||
VOID RtlMsleepOS(IN u32 ms)
|
||||
{
|
||||
rtw_msleep_os(ms);
|
||||
}
|
||||
|
||||
VOID RtlUsleepOS(IN u32 us)
|
||||
{
|
||||
rtw_usleep_os(us);
|
||||
}
|
||||
|
||||
VOID RtlMdelayOS(IN u32 ms)
|
||||
{
|
||||
rtw_mdelay_os(ms);
|
||||
}
|
||||
|
||||
VOID RtlUdelayOS(IN u32 us)
|
||||
{
|
||||
rtw_udelay_os(us);
|
||||
}
|
||||
|
||||
VOID RtlYieldOS(VOID)
|
||||
{
|
||||
rtw_yield_os();
|
||||
}
|
||||
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
u64 RtlModular64(IN u64 n, IN u64 base)
|
||||
{
|
||||
unsigned int __base = (base);
|
||||
unsigned int __rem;
|
||||
//(void)(((typeof((n)) *)0) == ((__uint64_t *)0));
|
||||
if (((n) >> 32) == 0) {
|
||||
__rem = (unsigned int)(n) % __base;
|
||||
(n) = (unsigned int)(n) / __base;
|
||||
} else
|
||||
__rem = __Div64_32(&(n), __base);
|
||||
return __rem;
|
||||
|
||||
}
|
||||
#else
|
||||
u64 RtlModular64(IN u64 x, IN u64 y)
|
||||
{
|
||||
return rtw_modular64(x, y);
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlTimerCallbckEntry
|
||||
* Desc: This function is a timer callback wrapper. All OS timer callback
|
||||
* will call this function and then call the real callback function inside
|
||||
* this function.
|
||||
*
|
||||
* Para:
|
||||
* pxTimer: The FreeRTOS timer handle which is expired and call this callback.
|
||||
*
|
||||
* Return: None
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
void RtlTimerCallbckEntry (IN _timerHandle pxTimer)
|
||||
{
|
||||
PRTL_TIMER pTimer;
|
||||
|
||||
if (NULL == pxTimer) {
|
||||
MSG_TIMER_ERR("RtlTimerCallbckEntry: NULL Timer Handle Err!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pTimer = (PRTL_TIMER) rtw_timerGetID( pxTimer );
|
||||
pTimer->CallBackFunc(pTimer->Context);
|
||||
}
|
||||
#endif // end of "#ifdef PLATFORM_FREERTOS"
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlTimerCreate
|
||||
* Desc: To create a software timer.
|
||||
*
|
||||
* Para:
|
||||
* pTimerName: A string for the timer name.
|
||||
* TimerPeriodMS: The timer period, the unit is milli-second.
|
||||
* CallbckFunc: The callback function of this timer.
|
||||
* pContext: A pointer will be used as the parameter to call the timer
|
||||
* callback function.
|
||||
* isPeriodical: Is this timer periodical ? (Auto reload after expired)
|
||||
* Return: The created timer handle, a pointer. It can be used to delete the
|
||||
* timer. If timer createion failed, return NULL.
|
||||
*
|
||||
******************************************************************************/
|
||||
PRTL_TIMER RtlTimerCreate(
|
||||
IN char *pTimerName,
|
||||
IN u32 TimerPeriodMS,
|
||||
IN RTL_TIMER_CALL_BACK CallbckFunc,
|
||||
IN void *pContext,
|
||||
IN u8 isPeriodical)
|
||||
{
|
||||
PRTL_TIMER pTimer;
|
||||
u32 timer_ticks;
|
||||
int i;
|
||||
|
||||
pTimer = (PRTL_TIMER)RtlZmalloc(sizeof(RTL_TIMER));
|
||||
if (NULL == pTimer) {
|
||||
MSG_TIMER_ERR("RtlTimerCreate: Alloc Mem Err!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (portTICK_RATE_MS >= TimerPeriodMS) {
|
||||
timer_ticks = 1; // at least 1 system tick
|
||||
}
|
||||
else {
|
||||
timer_ticks = TimerPeriodMS/portTICK_RATE_MS;
|
||||
}
|
||||
|
||||
pTimer->TimerHandle = rtw_timerCreate ((const char*)(pTimer->TimerName), timer_ticks,
|
||||
(portBASE_TYPE)isPeriodical, (void *) pTimer, RtlTimerCallbckEntry);
|
||||
|
||||
#ifdef PLATFORM_FREERTOS // if any RTOS is used
|
||||
if (pTimer->TimerHandle) {
|
||||
pTimer->msPeriod = TimerPeriodMS;
|
||||
pTimer->CallBackFunc = CallbckFunc;
|
||||
pTimer->Context = pContext;
|
||||
pTimer->isPeriodical = isPeriodical;
|
||||
// copy the timer name
|
||||
if (NULL != pTimerName) {
|
||||
for(i = 0; i < sizeof(pTimer->TimerName); i++)
|
||||
{
|
||||
pTimer->TimerName[i] = pTimerName[i];
|
||||
if(pTimerName[i] == '\0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
_strcpy((char*)(pTimer->TimerName), "None");
|
||||
}
|
||||
MSG_TIMER_INFO("RtlTimerCreate: SW Timer Created: Name=%s Period=%d isPeriodical=%d\n", \
|
||||
pTimer->TimerName, pTimer->msPeriod, pTimer->isPeriodical);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
RtlMfree((u8 *)pTimer, sizeof(RTL_TIMER));
|
||||
pTimer = NULL;
|
||||
MSG_TIMER_ERR("RtlTimerCreate: OS Create Timer Failed!\n");
|
||||
}
|
||||
|
||||
return (pTimer);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlTimerDelete
|
||||
* Desc: To delete a created software timer.
|
||||
*
|
||||
* Para:
|
||||
* pTimerHdl: The timer to be deleted
|
||||
*
|
||||
* Return: None
|
||||
*
|
||||
******************************************************************************/
|
||||
VOID RtlTimerDelete(IN PRTL_TIMER pTimerHdl)
|
||||
{
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
portBASE_TYPE ret;
|
||||
#endif
|
||||
|
||||
if (NULL == pTimerHdl) {
|
||||
MSG_TIMER_ERR("RtlTimerDelete: NULL Timer Handle!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
MSG_TIMER_INFO("RtlTimerDelete: Name=%s\n", pTimerHdl->TimerName);
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
/* try to delete the soft timer and wait max RTL_TIMER_API_MAX_BLOCK_TICKS
|
||||
to send the delete command to the timer command queue */
|
||||
ret = rtw_timerDelete(pTimerHdl->TimerHandle, RTL_TIMER_API_MAX_BLOCK_TICKS);
|
||||
if (pdPASS != ret) {
|
||||
MSG_TIMER_ERR("RtlTimerDelete: Delete OS Timer Failed!\n");
|
||||
}
|
||||
#endif
|
||||
RtlMfree((u8 *)pTimerHdl, sizeof(RTL_TIMER));
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlTimerStart
|
||||
* Desc: To start a created timer..
|
||||
*
|
||||
* Para:
|
||||
* pTimerHdl: The timer to be started.
|
||||
* isFromISR: The flag to indicate that is this function is called from an ISR.
|
||||
*
|
||||
* Return: _SUCCESS or _FAIL
|
||||
*
|
||||
******************************************************************************/
|
||||
u8 RtlTimerStart(IN PRTL_TIMER pTimerHdl, IN u8 isFromISR)
|
||||
{
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
u8 ret=_FAIL;
|
||||
portBASE_TYPE HigherPriorityTaskWoken=pdFALSE;
|
||||
|
||||
if (isFromISR) {
|
||||
if (pdPASS == rtw_timerStartFromISR(pTimerHdl->TimerHandle,&HigherPriorityTaskWoken))
|
||||
{
|
||||
// start OS timer successful
|
||||
if (pdFALSE != HigherPriorityTaskWoken) {
|
||||
rtw_yield_os();
|
||||
}
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
else {
|
||||
MSG_TIMER_ERR("RtlTimerStart: Start Timer(%s) from ISR failed\n", pTimerHdl->TimerName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pdPASS == rtw_timerStart(pTimerHdl->TimerHandle, RTL_TIMER_API_MAX_BLOCK_TICKS)) {
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
else {
|
||||
MSG_TIMER_ERR("RtlTimerStart: Start Timer(%s) failed\n", pTimerHdl->TimerName);
|
||||
}
|
||||
}
|
||||
|
||||
MSG_TIMER_INFO("RtlTimerStart: SW Timer %s Started\n", pTimerHdl->TimerName);
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlTimerStop
|
||||
* Desc: To stop a running timer..
|
||||
*
|
||||
* Para:
|
||||
* pTimerHdl: The timer to be stoped.
|
||||
* isFromISR: The flag to indicate that is this function is called from an ISR.
|
||||
*
|
||||
* Return: _SUCCESS or _FAIL
|
||||
*
|
||||
******************************************************************************/
|
||||
u8 RtlTimerStop(IN PRTL_TIMER pTimerHdl, IN u8 isFromISR)
|
||||
{
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
u8 ret=_FAIL;
|
||||
portBASE_TYPE HigherPriorityTaskWoken=pdFALSE;
|
||||
|
||||
if (isFromISR) {
|
||||
if (pdPASS == rtw_timerStopFromISR(pTimerHdl->TimerHandle,&HigherPriorityTaskWoken))
|
||||
{
|
||||
// start OS timer successful
|
||||
if (pdFALSE != HigherPriorityTaskWoken) {
|
||||
rtw_yield_os();
|
||||
}
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pdPASS == rtw_timerStop(pTimerHdl->TimerHandle, RTL_TIMER_API_MAX_BLOCK_TICKS)) {
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (_FAIL == ret) {
|
||||
MSG_TIMER_ERR("RtlTimerStop: Stop Timer(%s) Failed, IsFromISR=%d\n", pTimerHdl->TimerName, isFromISR);
|
||||
}
|
||||
|
||||
MSG_TIMER_INFO("RtlTimerStop: SW Timer %s Stoped\n", pTimerHdl->TimerName);
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlTimerReset
|
||||
* Desc: To reset a timer. A reset will get a re-start and reset
|
||||
* the timer ticks counting. A running timer expired time is relative
|
||||
* to the time when Reset function be called. Please ensure the timer
|
||||
* is in active state (Started). A stopped timer also will be started
|
||||
* when this function is called.
|
||||
*
|
||||
* Para:
|
||||
* pTimerHdl: The timer to be reset.
|
||||
* isFromISR: The flag to indicate that is this function is called from an ISR.
|
||||
*
|
||||
* Return: _SUCCESS or _FAIL
|
||||
*
|
||||
******************************************************************************/
|
||||
u8
|
||||
RtlTimerReset(
|
||||
IN PRTL_TIMER pTimerHdl,
|
||||
IN u8 isFromISR
|
||||
)
|
||||
{
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
u8 ret=_FAIL;
|
||||
portBASE_TYPE HigherPriorityTaskWoken=pdFALSE;
|
||||
|
||||
if (isFromISR) {
|
||||
if (pdPASS == rtw_timerResetFromISR(pTimerHdl->TimerHandle,&HigherPriorityTaskWoken))
|
||||
{
|
||||
// start OS timer successful
|
||||
if (pdFALSE != HigherPriorityTaskWoken) {
|
||||
rtw_yield_os();
|
||||
}
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pdPASS == rtw_timerReset(pTimerHdl->TimerHandle, RTL_TIMER_API_MAX_BLOCK_TICKS)) {
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (_FAIL == ret) {
|
||||
MSG_TIMER_ERR("RtlTimerReset: Reset Timer(%s) Failed, IsFromISR=%d\n", pTimerHdl->TimerName, isFromISR);
|
||||
}
|
||||
|
||||
MSG_TIMER_INFO("RtlTimerReset: SW Timer %s Reset\n", pTimerHdl->TimerName);
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function: RtlTimerChangePeriod
|
||||
* Desc: To change the period of a timer that was created previously.
|
||||
*
|
||||
* Para:
|
||||
* pTimerHdl: The timer handle to be changed the priod.
|
||||
* NewPeriodMS: The new timer period, in milli-second.
|
||||
* isFromISR: The flag to indicate that is this function is called from an ISR.
|
||||
*
|
||||
* Return: _SUCCESS or _FAIL
|
||||
*
|
||||
******************************************************************************/
|
||||
u8 RtlTimerChangePeriod(
|
||||
IN PRTL_TIMER pTimerHdl,
|
||||
IN u32 NewPeriodMS,
|
||||
IN u8 isFromISR)
|
||||
{
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
u32 timer_ticks;
|
||||
u8 ret=_FAIL;
|
||||
portBASE_TYPE HigherPriorityTaskWoken=pdFALSE;
|
||||
|
||||
if (portTICK_RATE_MS >= NewPeriodMS) {
|
||||
timer_ticks = 1; // at least 1 system tick
|
||||
}
|
||||
else {
|
||||
timer_ticks = NewPeriodMS/portTICK_RATE_MS;
|
||||
}
|
||||
|
||||
if (isFromISR) {
|
||||
if (pdPASS == rtw_timerChangePeriodFromISR(pTimerHdl->TimerHandle, timer_ticks, &HigherPriorityTaskWoken))
|
||||
{
|
||||
// start OS timer successful
|
||||
if (pdFALSE != HigherPriorityTaskWoken) {
|
||||
taskYIELD();
|
||||
}
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pdPASS == rtw_timerChangePeriod(pTimerHdl->TimerHandle, timer_ticks, RTL_TIMER_API_MAX_BLOCK_TICKS)) {
|
||||
ret = _SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (_FAIL == ret) {
|
||||
MSG_TIMER_ERR("RtlTimerChangePeriod: Change Timer(%s) Period Failed, IsFromISR=%d\n", pTimerHdl->TimerName, isFromISR);
|
||||
}
|
||||
else {
|
||||
pTimerHdl->msPeriod = NewPeriodMS;
|
||||
MSG_TIMER_INFO("RtlTimerChangePeriod: SW Timer %s change period to %d\n", pTimerHdl->TimerName, pTimerHdl->msPeriod);
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
362
vendor/sdk/component/soc/realtek/8195a/misc/os/osdep_api.h
vendored
Normal file
362
vendor/sdk/component/soc/realtek/8195a/misc/os/osdep_api.h
vendored
Normal file
|
|
@ -0,0 +1,362 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef __OSDEP_API_H_
|
||||
#define __OSDEP_API_H_
|
||||
|
||||
#include "os_timer.h"
|
||||
#include "os_support.h"
|
||||
#include "osdep_service.h"
|
||||
|
||||
|
||||
#define MAX_SEMA_COUNT 32 /* the maximum count of a semaphore */
|
||||
|
||||
typedef _sema _Sema;
|
||||
typedef _mutex _Mutex;
|
||||
typedef u32 _Lock;
|
||||
typedef struct TIMER_LIST _Timer;
|
||||
typedef unsigned long _IRQL;
|
||||
typedef _thread_hdl_ _THREAD_HDL_;
|
||||
typedef VOID THREAD_RETURN;
|
||||
typedef VOID THREAD_CONTEXT;
|
||||
|
||||
|
||||
#ifndef mdelay
|
||||
#define mdelay(t) ((t/portTICK_RATE_MS)>0)?(vTaskDelay(t/portTICK_RATE_MS)):(vTaskDelay(1))
|
||||
#endif
|
||||
|
||||
#ifndef udelay
|
||||
#define udelay(t) ((t/(portTICK_RATE_MS*1000))>0)?vTaskDelay(t/(portTICK_RATE_MS*1000)):(vTaskDelay(1))
|
||||
#endif
|
||||
|
||||
/* to delete/start/stop a timer it will send a message to the timer task through a message queue,
|
||||
so we define the max wait time for message sending */
|
||||
#define RTL_TIMER_API_MAX_BLOCK_TIME 1000 // unit is ms
|
||||
#define RTL_TIMER_API_MAX_BLOCK_TICKS (RTL_TIMER_API_MAX_BLOCK_TIME/portTICK_RATE_MS)
|
||||
|
||||
typedef VOID (*RTL_TIMER_CALL_BACK)(void *pContext);
|
||||
|
||||
typedef struct _RTL_TIMER{
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
_timerHandle TimerHandle; // The timer handle of created FreeRTOS soft-timer
|
||||
#endif
|
||||
RTL_TIMER_CALL_BACK CallBackFunc; // Callback function of this timer
|
||||
u32 msPeriod; // The period of this timer
|
||||
void *Context; // Timer specific context.
|
||||
u8 isPeriodical; // Is a periodical timer
|
||||
u8 TimerName[35]; // The Name of timer
|
||||
}RTL_TIMER, *PRTL_TIMER;
|
||||
|
||||
__inline static VOID RtlEnterCritical(VOID)
|
||||
{
|
||||
rtw_enter_critical(NULL, NULL);
|
||||
}
|
||||
|
||||
__inline static VOID RtlExitCritical(VOID)
|
||||
{
|
||||
rtw_exit_critical(NULL, NULL);
|
||||
}
|
||||
|
||||
__inline static VOID RtlEnterCriticalBh(IN _Lock *plock, IN _IRQL *pirqL)
|
||||
{
|
||||
rtw_enter_critical_bh((_lock *)plock, pirqL);
|
||||
}
|
||||
|
||||
__inline static VOID RtlExitCriticalBh(IN _Lock *plock, IN _IRQL *pirqL)
|
||||
{
|
||||
rtw_exit_critical_bh((_lock *)plock, pirqL);
|
||||
}
|
||||
|
||||
__inline static u32 RtlEnterCriticalMutex(IN _Mutex *pmutex, IN _IRQL *pirqL)
|
||||
{
|
||||
return rtw_enter_critical_mutex(pmutex, pirqL);
|
||||
}
|
||||
|
||||
__inline static VOID RtlExitCriticalMutex(IN _Mutex *pmutex,IN _IRQL *pirqL)
|
||||
{
|
||||
rtw_exit_critical_mutex(pmutex, pirqL);
|
||||
}
|
||||
|
||||
__inline static VOID RtlInitTimer(
|
||||
IN _Timer *ptimer,
|
||||
IN VOID *Data,
|
||||
IN VOID (*pfunc)(VOID *),
|
||||
IN VOID* cntx
|
||||
)
|
||||
{
|
||||
ptimer->Function = pfunc;
|
||||
ptimer->Data = (unsigned long)cntx;
|
||||
InitTimer(ptimer);
|
||||
}
|
||||
|
||||
__inline static VOID RtlSetTimer(
|
||||
IN _Timer *ptimer,
|
||||
IN u32 delay_time
|
||||
)
|
||||
{
|
||||
ModTimer(ptimer , (JIFFIES+(delay_time*RTL_HZ/1000)));
|
||||
}
|
||||
|
||||
__inline static VOID RtlCancelTimer(
|
||||
IN _Timer *ptimer,
|
||||
IN u8 *bcancelled
|
||||
)
|
||||
{
|
||||
DelTimerSync(ptimer);
|
||||
*bcancelled= _TRUE;//TRUE ==1; FALSE==0
|
||||
}
|
||||
|
||||
__inline static u32 RtlSystime2Ms(IN u32 systime)
|
||||
{
|
||||
return rtw_systime_to_ms(systime);
|
||||
}
|
||||
|
||||
__inline static u32 RtlMs2Systime(IN u32 ms)
|
||||
{
|
||||
return rtw_ms_to_systime(ms);
|
||||
}
|
||||
|
||||
extern u8* RtlZmalloc(u32 sz);
|
||||
extern u8* RtlMalloc(u32 sz);
|
||||
extern VOID RtlMfree(u8 *pbuf, u32 sz);
|
||||
|
||||
extern VOID* RtlMalloc2d(u32 h, u32 w, u32 size);
|
||||
extern VOID RtlMfree2d(VOID *pbuf, u32 h, u32 w, u32 size);
|
||||
|
||||
extern VOID RtlInitSema(_Sema *sema, u32 init_val);
|
||||
extern VOID RtlFreeSema(_Sema *sema);
|
||||
extern VOID RtlUpSema(_Sema *sema);
|
||||
extern VOID RtlUpSemaFromISR(_Sema *sema);
|
||||
extern u32 RtlDownSema(_Sema *sema);
|
||||
extern u32 RtlDownSemaWithTimeout(_Sema *sema, u32 ms);
|
||||
|
||||
extern VOID RtlMutexInit(_Mutex *pmutex);
|
||||
extern VOID RtlMutexFree(_Mutex *pmutex);
|
||||
|
||||
extern VOID RtlSpinlockInit(_Lock *plock);
|
||||
extern VOID RtlSpinlockFree(_Lock *plock);
|
||||
extern VOID RtlSpinlock(_Lock *plock);
|
||||
extern VOID RtlSpinunlock(_Lock *plock);
|
||||
extern VOID RtlSpinlockEx(_Lock *plock);
|
||||
extern VOID RtlSpinunlockEx(_Lock *plock);
|
||||
|
||||
extern VOID RtlSleepSchedulable(u32 ms);
|
||||
|
||||
extern VOID RtlMsleepOS(u32 ms);
|
||||
extern VOID RtlUsleepOS(u32 us);
|
||||
extern VOID RtlMdelayOS(u32 ms);
|
||||
extern VOID RtlUdelayOS(u32 us);
|
||||
extern VOID RtlYieldOS(VOID);
|
||||
|
||||
#define RtlUpMutex(mutex) RtlUpSema(mutex)
|
||||
#define RtlDownMutex(mutex) RtlDownSema(mutex)
|
||||
|
||||
__inline static u8 RtlCancelTimerEx(IN _Timer *ptimer)
|
||||
{
|
||||
DelTimerSync(ptimer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static __inline VOID ThreadEnter(IN char *name)
|
||||
{
|
||||
DBG_8195A("\rRTKTHREAD_enter %s\n", name);
|
||||
}
|
||||
|
||||
#define ThreadExit() do{DBG_8195A("\rRTKTHREAD_exit %s\n", __FUNCTION__);}while(0)
|
||||
|
||||
__inline static VOID FlushSignalsThread(VOID)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#define RTL_RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
|
||||
#define RTL_RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2)
|
||||
|
||||
__inline static u32 RtlRnd4(IN u32 sz)
|
||||
{
|
||||
|
||||
u32 val;
|
||||
|
||||
val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2;
|
||||
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
__inline static u32 RtlRnd8(IN u32 sz)
|
||||
{
|
||||
|
||||
u32 val;
|
||||
|
||||
val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3;
|
||||
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
__inline static u32 RtlRnd128(IN u32 sz)
|
||||
{
|
||||
|
||||
u32 val;
|
||||
|
||||
val = ((sz >> 7) + ((sz & 127) ? 1: 0)) << 7;
|
||||
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
__inline static u32 RtlRnd256(IN u32 sz)
|
||||
{
|
||||
|
||||
u32 val;
|
||||
|
||||
val = ((sz >> 8) + ((sz & 255) ? 1: 0)) << 8;
|
||||
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
__inline static u32 RtlRnd512(IN u32 sz)
|
||||
{
|
||||
|
||||
u32 val;
|
||||
|
||||
val = ((sz >> 9) + ((sz & 511) ? 1: 0)) << 9;
|
||||
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
__inline static u32 BitShift(IN u32 BitMask)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i <= 31; i++)
|
||||
if (((BitMask>>i) & 0x1) == 1) break;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
//#ifdef __GNUC__
|
||||
#ifdef PLATFORM_LINUX
|
||||
#define STRUCT_PACKED __attribute__ ((packed))
|
||||
#else
|
||||
#define STRUCT_PACKED
|
||||
#endif
|
||||
|
||||
|
||||
//Atomic integer operations
|
||||
#define RTL_ATOMIC_T atomic_t
|
||||
|
||||
static inline VOID RTL_ATOMIC_SET(IN RTL_ATOMIC_T *v, IN u32 i)
|
||||
{
|
||||
ATOMIC_SET(v,i);
|
||||
}
|
||||
|
||||
static inline uint32_t RTL_ATOMIC_READ(IN RTL_ATOMIC_T *v)
|
||||
{
|
||||
return ATOMIC_READ(v);
|
||||
}
|
||||
|
||||
static inline VOID RTL_ATOMIC_ADD(IN RTL_ATOMIC_T *v, IN u32 i)
|
||||
{
|
||||
ATOMIC_ADD(v,i);
|
||||
}
|
||||
|
||||
static inline VOID RTL_ATOMIC_SUB(IN RTL_ATOMIC_T *v, IN u32 i)
|
||||
{
|
||||
ATOMIC_SUB(v,i);
|
||||
}
|
||||
|
||||
static inline VOID RTL_ATOMIC_INC(IN RTL_ATOMIC_T *v)
|
||||
{
|
||||
ATOMIC_INC(v);
|
||||
}
|
||||
|
||||
static inline VOID RTL_ATOMIC_DEC(IN RTL_ATOMIC_T *v)
|
||||
{
|
||||
ATOMIC_DEC(v);
|
||||
}
|
||||
|
||||
static inline u32 RTL_ATOMIC_ADD_RETURN(IN RTL_ATOMIC_T *v, IN u32 i)
|
||||
{
|
||||
return ATOMIC_ADD_RETURN(v, i);
|
||||
}
|
||||
|
||||
static inline u32 RTL_ATOMIC_SUB_RETURN(IN RTL_ATOMIC_T *v, IN u32 i)
|
||||
{
|
||||
return ATOMIC_SUB_RETURN(v, i);
|
||||
}
|
||||
|
||||
static inline u32 RTL_ATOMIC_INC_RETURN(IN RTL_ATOMIC_T *v)
|
||||
{
|
||||
return ATOMIC_INC_RETURN(v);
|
||||
}
|
||||
|
||||
static inline u32 RTL_ATOMIC_DEC_RETURN(IN RTL_ATOMIC_T *v)
|
||||
{
|
||||
return ATOMIC_DEC_RETURN(v);
|
||||
}
|
||||
|
||||
extern u64 RtlModular64(u64 x, u64 y);
|
||||
|
||||
extern PRTL_TIMER
|
||||
RtlTimerCreate(
|
||||
IN char *pTimerName,
|
||||
IN u32 TimerPeriodMS,
|
||||
IN RTL_TIMER_CALL_BACK CallbckFunc,
|
||||
IN void *pContext,
|
||||
IN u8 isPeriodical
|
||||
);
|
||||
|
||||
extern VOID
|
||||
RtlTimerDelete(
|
||||
IN PRTL_TIMER pTimerHdl
|
||||
);
|
||||
|
||||
extern u8
|
||||
RtlTimerStart(
|
||||
IN PRTL_TIMER pTimerHdl,
|
||||
IN u8 isFromISR
|
||||
);
|
||||
|
||||
extern u8
|
||||
RtlTimerStop(
|
||||
IN PRTL_TIMER pTimerHdl,
|
||||
IN u8 isFromISR
|
||||
);
|
||||
|
||||
extern u8
|
||||
RtlTimerReset(
|
||||
IN PRTL_TIMER pTimerHdl,
|
||||
IN u8 isFromISR
|
||||
);
|
||||
|
||||
extern u8
|
||||
RtlTimerChangePeriod(
|
||||
IN PRTL_TIMER pTimerHdl,
|
||||
IN u32 NewPeriodMS,
|
||||
IN u8 isFromISR
|
||||
);
|
||||
|
||||
#endif //#ifndef __OSDEP_API_H_
|
||||
|
||||
|
||||
22
vendor/sdk/component/soc/realtek/8195a/misc/platform/gcc_wrap.c
vendored
Normal file
22
vendor/sdk/component/soc/realtek/8195a/misc/platform/gcc_wrap.c
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/**************************************************
|
||||
* malloc/free/realloc wrap for gcc compiler
|
||||
*
|
||||
**************************************************/
|
||||
#if defined(__GNUC__)
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
void* __wrap_malloc( size_t size )
|
||||
{
|
||||
return pvPortMalloc(size);
|
||||
}
|
||||
|
||||
void* __wrap_realloc( void *p, size_t size )
|
||||
{
|
||||
return pvPortReAalloc(p, size);
|
||||
}
|
||||
|
||||
void __wrap_free( void *p )
|
||||
{
|
||||
vPortFree(p);
|
||||
}
|
||||
#endif
|
||||
825
vendor/sdk/component/soc/realtek/8195a/misc/platform/ota_8195a.c
vendored
Normal file
825
vendor/sdk/component/soc/realtek/8195a/misc/platform/ota_8195a.c
vendored
Normal file
|
|
@ -0,0 +1,825 @@
|
|||
#include <sys.h>
|
||||
#include <device_lock.h>
|
||||
#include "ota_8195a.h"
|
||||
#include "lwip/netdb.h"
|
||||
|
||||
sys_thread_t TaskOTA = NULL;
|
||||
#define STACK_SIZE 1024
|
||||
#define TASK_PRIORITY tskIDLE_PRIORITY + 1
|
||||
#if SWAP_UPDATE
|
||||
static uint32_t OldImg2Addr;
|
||||
#endif
|
||||
static flash_t flash_ota;
|
||||
|
||||
#if CONFIG_CUSTOM_SIGNATURE
|
||||
/* ---------------------------------------------------
|
||||
* Customized Signature
|
||||
* ---------------------------------------------------*/
|
||||
// This signature can be used to verify the correctness of the image
|
||||
// It will be located in fixed location in application image
|
||||
#include "section_config.h"
|
||||
SECTION(".custom.validate.rodata")
|
||||
const unsigned char cus_sig_demo[32] = "Customer Signature-modelxxx";
|
||||
#endif
|
||||
|
||||
void* update_malloc(unsigned int size){
|
||||
return pvPortMalloc(size);
|
||||
}
|
||||
|
||||
void update_free(void *buf){
|
||||
vPortFree(buf);
|
||||
}
|
||||
|
||||
void ota_platform_reset(void){
|
||||
// Set processor clock to default before system reset
|
||||
HAL_WRITE32(SYSTEM_CTRL_BASE, 0x14, 0x00000021);
|
||||
osDelay(100);
|
||||
|
||||
// Cortex-M3 SCB->AIRCR
|
||||
HAL_WRITE32(0xE000ED00, 0x0C, (0x5FA << 16) | // VECTKEY
|
||||
(HAL_READ32(0xE000ED00, 0x0C) & (7 << 8)) | // PRIGROUP
|
||||
(1 << 2)); // SYSRESETREQ
|
||||
while(1) osDelay(1000);
|
||||
}
|
||||
|
||||
#if WRITE_OTA_ADDR
|
||||
int write_ota_addr_to_system_data(flash_t *flash, uint32_t ota_addr)
|
||||
{
|
||||
uint32_t data, i = 0;
|
||||
//Get upgraded image 2 addr from offset
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_read_word(flash, OFFSET_DATA, &data);
|
||||
printf("\n\r[%s] data 0x%x ota_addr 0x%x", __FUNCTION__, data, ota_addr);
|
||||
if(~0x0 == data){
|
||||
flash_write_word(flash, OFFSET_DATA, ota_addr);
|
||||
}
|
||||
else{
|
||||
//erase backup sector
|
||||
flash_erase_sector(flash, BACKUP_SECTOR);
|
||||
//backup system data to backup sector
|
||||
for(i = 0; i < 0x1000; i+= 4){
|
||||
flash_read_word(flash, OFFSET_DATA + i, &data);
|
||||
if(0 == i)
|
||||
data = ota_addr;
|
||||
flash_write_word(flash, BACKUP_SECTOR + i,data);
|
||||
}
|
||||
//erase system data
|
||||
flash_erase_sector(flash, OFFSET_DATA);
|
||||
//write data back to system data
|
||||
for(i = 0; i < 0x1000; i+= 4){
|
||||
flash_read_word(flash, BACKUP_SECTOR + i, &data);
|
||||
flash_write_word(flash, OFFSET_DATA + i,data);
|
||||
}
|
||||
//erase backup sector
|
||||
flash_erase_sector(flash, BACKUP_SECTOR);
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int update_ota_connect_server(int server_socket, update_cfg_local_t *cfg){
|
||||
struct sockaddr_in server_addr;
|
||||
|
||||
server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(server_socket < 0){
|
||||
printf("\n\r[%s] Create socket failed", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_addr.s_addr = cfg->ip_addr;
|
||||
server_addr.sin_port = cfg->port;
|
||||
|
||||
if(connect(server_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1){
|
||||
printf("\n\r[%s] Socket connect failed", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return server_socket;
|
||||
}
|
||||
|
||||
uint32_t update_ota_prepare_addr(void){
|
||||
|
||||
uint32_t Img2Len = 0;
|
||||
uint32_t IMAGE_x = 0, ImgxLen = 0, ImgxAddr = 0;
|
||||
uint32_t NewImg2Addr = 0;
|
||||
#if WRITE_OTA_ADDR
|
||||
uint32_t ota_addr = 0x80000;
|
||||
#endif
|
||||
|
||||
DBG_INFO_MSG_OFF(_DBG_SPI_FLASH_);
|
||||
// The upgraded image2 pointer must 4K aligned and should not overlap with Default Image2
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_read_word(&flash_ota, IMAGE_2, &Img2Len);
|
||||
IMAGE_x = IMAGE_2 + Img2Len + 0x10;
|
||||
flash_read_word(&flash_ota, IMAGE_x, &ImgxLen);
|
||||
flash_read_word(&flash_ota, IMAGE_x+4, &ImgxAddr);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
|
||||
if(0x30000000 == ImgxAddr){
|
||||
printf("\n\r[%s] IMAGE_3 0x%x Img3Len 0x%x", __FUNCTION__, IMAGE_x, ImgxLen);
|
||||
}
|
||||
else{
|
||||
printf("\n\r[%s] There is no IMAGE_3", __FUNCTION__);
|
||||
IMAGE_x = IMAGE_2;
|
||||
ImgxLen = Img2Len;
|
||||
}
|
||||
#if WRITE_OTA_ADDR
|
||||
if((ota_addr > IMAGE_x) && ((ota_addr < (IMAGE_x+ImgxLen))) || (ota_addr < IMAGE_x) ||
|
||||
((ota_addr & 0xfff) != 0) || (ota_addr == ~0x0)){
|
||||
printf("\n\r[%s] illegal ota addr 0x%x", __FUNCTION__, ota_addr);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
write_ota_addr_to_system_data(&flash_ota, ota_addr);
|
||||
#endif
|
||||
|
||||
//Get upgraded image 2 addr from offset
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_read_word(&flash_ota, OFFSET_DATA, &NewImg2Addr);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
if((NewImg2Addr > IMAGE_x) && ((NewImg2Addr < (IMAGE_x+ImgxLen))) || (NewImg2Addr < IMAGE_x) ||
|
||||
((NewImg2Addr & 0xfff) != 0) || (NewImg2Addr == ~0x0)){
|
||||
printf("\n\r[%s] Invalid OTA Address 0x%x", __FUNCTION__, NewImg2Addr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return NewImg2Addr;
|
||||
}
|
||||
|
||||
#if SWAP_UPDATE
|
||||
uint32_t update_ota_swap_addr(uint32_t img_len, uint32_t NewImg2Addr){
|
||||
uint32_t SigImage0,SigImage1;
|
||||
uint32_t Part1Addr=0xFFFFFFFF, Part2Addr=0xFFFFFFFF;
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_read_word(&flash_ota, 0x18, &Part1Addr);
|
||||
Part1Addr = (Part1Addr&0xFFFF)*1024; //PART1 : 0x0000B000
|
||||
Part2Addr = NewImg2Addr; //PART2 : 0x00080000
|
||||
|
||||
// read Part1 signature
|
||||
flash_read_word(&flash_ota, Part1Addr+8, &SigImage0);
|
||||
flash_read_word(&flash_ota, Part1Addr+12, &SigImage1);
|
||||
printf("\n\r[%s] Part1 Sig %x", __FUNCTION__, SigImage0);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
if(SigImage0==0x35393138 && SigImage1==0x31313738)//Part1 is the new one with signature "81958711"
|
||||
OldImg2Addr = Part1Addr; //Change Part1 to older version
|
||||
else{
|
||||
// read Part2 signature
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_read_word(&flash_ota, Part2Addr+8, &SigImage0);
|
||||
flash_read_word(&flash_ota, Part2Addr+12, &SigImage1);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
printf("\n\r[%s] Part2 Sig %x", __FUNCTION__, SigImage0);
|
||||
if(SigImage0==0x30303030 && SigImage1==0x30303030){// ATSC signature "00000000"
|
||||
OldImg2Addr = Part1Addr; //Store the new version to Part2
|
||||
}
|
||||
else if(SigImage0==0x35393138 && SigImage1==0x31313738){//Part2 is the new one with signature "81958711"
|
||||
OldImg2Addr = Part2Addr; //Change Part2 to older version
|
||||
NewImg2Addr = Part1Addr;
|
||||
if( img_len > (Part2Addr-Part1Addr) ){ // firmware size too large
|
||||
printf("\n\r[%s] Part1 size < OTA size", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
NewImg2Addr = Part2Addr;
|
||||
}
|
||||
|
||||
printf("\n\r[%s] New %x, Old %x", __FUNCTION__, NewImg2Addr, OldImg2Addr);
|
||||
return NewImg2Addr;
|
||||
}
|
||||
#endif
|
||||
|
||||
int update_ota_erase_upg_region(uint32_t img_len, uint32_t NewImg2Len, uint32_t NewImg2Addr){
|
||||
uint32_t NewImg2BlkSize = 0;
|
||||
|
||||
if(NewImg2Len == 0){
|
||||
NewImg2Len = img_len;
|
||||
printf("\n\r[%s] NewImg2Len %d ", __FUNCTION__, NewImg2Len);
|
||||
if((int)NewImg2Len > 0){
|
||||
NewImg2BlkSize = ((NewImg2Len - 1)/4096) + 1;
|
||||
printf("\n\r[%s] NewImg2BlkSize %d 0x%8x", __FUNCTION__, NewImg2BlkSize, NewImg2BlkSize);
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
for(int i = 0; i < NewImg2BlkSize; i++)
|
||||
flash_erase_sector(&flash_ota, NewImg2Addr + i * 4096);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
}else{
|
||||
printf("\n\r[%s] Size INVALID", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n\r[%s] NewImg2Addr 0x%x", __FUNCTION__, NewImg2Addr);
|
||||
return NewImg2Len;
|
||||
}
|
||||
|
||||
int update_ota_checksum(_file_checksum *file_checksum, uint32_t flash_checksum, uint32_t NewImg2Addr){
|
||||
|
||||
#if CONFIG_CUSTOM_SIGNATURE
|
||||
char custom_sig[32] = "Customer Signature-modelxxx";
|
||||
uint32_t read_custom_sig[8];
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
for(int i = 0; i < 8; i ++){
|
||||
flash_read_word(&flash_ota, NewImg2Addr + 0x28 + i *4, read_custom_sig + i);
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
printf("\n\r[%s] read_custom_sig %s", __FUNCTION__ , (char*)read_custom_sig);
|
||||
#endif
|
||||
|
||||
printf("\n\rflash checksum 0x%8x attached checksum 0x%8x", flash_checksum, file_checksum->u);
|
||||
|
||||
// compare checksum with received checksum
|
||||
if( (file_checksum->u == flash_checksum)
|
||||
#if CONFIG_CUSTOM_SIGNATURE
|
||||
&& !strcmp((char*)read_custom_sig,custom_sig)
|
||||
#endif
|
||||
){
|
||||
//Set signature in New Image 2 addr + 8 and + 12
|
||||
uint32_t sig_readback0,sig_readback1;
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_write_word(&flash_ota,NewImg2Addr + 8, 0x35393138);
|
||||
flash_write_word(&flash_ota,NewImg2Addr + 12, 0x31313738);
|
||||
flash_read_word(&flash_ota, NewImg2Addr + 8, &sig_readback0);
|
||||
flash_read_word(&flash_ota, NewImg2Addr + 12, &sig_readback1);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
printf("\n\r[%s] signature %x,%x", __FUNCTION__ , sig_readback0, sig_readback1);
|
||||
#if SWAP_UPDATE
|
||||
if(OldImg2Addr != ~0x0){
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_write_word(&flash_ota,OldImg2Addr + 8, 0x35393130);
|
||||
flash_write_word(&flash_ota,OldImg2Addr + 12, 0x31313738);
|
||||
flash_read_word(&flash_ota, OldImg2Addr + 8, &sig_readback0);
|
||||
flash_read_word(&flash_ota, OldImg2Addr + 12, &sig_readback1);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
printf("\n\r[%s] old signature %x,%x", __FUNCTION__ , sig_readback0, sig_readback1);
|
||||
}
|
||||
#endif
|
||||
printf("\n\r[%s] Update OTA success!", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void update_ota_local_task(void *param)
|
||||
{
|
||||
int server_socket;
|
||||
unsigned char *buf, *alloc;
|
||||
_file_checksum *file_checksum;
|
||||
int read_bytes = 0, size = 0, i = 0;
|
||||
update_cfg_local_t *cfg = (update_cfg_local_t *)param;
|
||||
uint32_t address, flash_checksum=0;
|
||||
uint32_t NewImg2Len = 0, NewImg2Addr = 0, file_info[3];
|
||||
int ret = -1 ;
|
||||
|
||||
printf("\n\r[%s] Update task start", __FUNCTION__);
|
||||
alloc = update_malloc(BUF_SIZE+4);
|
||||
if(!alloc){
|
||||
printf("\n\r[%s] Alloc buffer failed", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
buf = &alloc[4];
|
||||
file_checksum = (void*)alloc;
|
||||
|
||||
// Connect server
|
||||
server_socket = update_ota_connect_server(server_socket, cfg);
|
||||
if(server_socket == -1){
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
NewImg2Addr = update_ota_prepare_addr();
|
||||
if(NewImg2Addr == -1){
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
//Clear file_info
|
||||
memset(file_info, 0, sizeof(file_info));
|
||||
|
||||
if(file_info[0] == 0){
|
||||
printf("\n\r[%s] Read info first", __FUNCTION__);
|
||||
read_bytes = read(server_socket, file_info, sizeof(file_info));
|
||||
// !X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X
|
||||
// !W checksum !W padding 0 !W file size !W
|
||||
// !X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X
|
||||
printf("\n\r[%s] info %d bytes", __FUNCTION__, read_bytes);
|
||||
printf("\n\r[%s] tx chechsum 0x%x, file size 0x%x", __FUNCTION__, file_info[0],file_info[2]);
|
||||
if(file_info[2] == 0){
|
||||
printf("\n\r[%s] No checksum and file size", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
}
|
||||
|
||||
#if SWAP_UPDATE
|
||||
NewImg2Addr = update_ota_swap_addr(file_info[2], NewImg2Addr);
|
||||
if(NewImg2Addr == -1){
|
||||
goto update_ota_exit;
|
||||
}
|
||||
#endif
|
||||
|
||||
NewImg2Len = update_ota_erase_upg_region(file_info[2], NewImg2Len, NewImg2Addr);
|
||||
if(NewImg2Len == -1){
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
// reset
|
||||
file_checksum->u = 0;
|
||||
// Write New Image 2 sector
|
||||
if(NewImg2Addr != ~0x0){
|
||||
address = NewImg2Addr;
|
||||
printf("\n\rStart to read data %d bytes\r\n", NewImg2Len);
|
||||
while(1){
|
||||
memset(buf, 0, BUF_SIZE);
|
||||
read_bytes = read(server_socket, buf, BUF_SIZE);
|
||||
if(read_bytes == 0)
|
||||
break; // Read end
|
||||
if(read_bytes < 0){
|
||||
printf("\n\r[%s] Read socket failed", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
if(read_bytes<4)
|
||||
printf("\n\r[%s] Recv small packet", __FUNCTION__);
|
||||
printf(".");
|
||||
|
||||
if((size+read_bytes)>NewImg2Len){
|
||||
printf("\n\r[%s] Redundant bytes received", __FUNCTION__);
|
||||
read_bytes = NewImg2Len-size;
|
||||
}
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
if(flash_stream_write(&flash_ota, address + size, read_bytes, buf) < 0){
|
||||
printf("\n\r[%s] Write stream failed", __FUNCTION__);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
size += read_bytes;
|
||||
|
||||
file_checksum->c[0] = alloc[4+read_bytes-4]; // checksum attached at file end
|
||||
file_checksum->c[1] = alloc[4+read_bytes-3];
|
||||
file_checksum->c[2] = alloc[4+read_bytes-2];
|
||||
file_checksum->c[3] = alloc[4+read_bytes-1];
|
||||
|
||||
if(size == NewImg2Len)
|
||||
break;
|
||||
}
|
||||
printf("\n\rRead data finished\r\n");
|
||||
|
||||
// read flash data back and calculate checksum
|
||||
for(i = 0; i < size-4; i += BUF_SIZE){
|
||||
int k;
|
||||
int rlen = (size-4-i) > BUF_SIZE ? BUF_SIZE : (size-4-i);
|
||||
flash_stream_read(&flash_ota, NewImg2Addr+i, rlen, buf);
|
||||
for(k = 0; k < rlen; k++)
|
||||
flash_checksum+=buf[k];
|
||||
}
|
||||
|
||||
ret = update_ota_checksum(file_checksum, flash_checksum, NewImg2Addr);
|
||||
if(ret == -1){
|
||||
printf("\r\nThe checksume is wrong!\r\n");
|
||||
goto update_ota_exit;
|
||||
}
|
||||
}
|
||||
update_ota_exit:
|
||||
if(alloc)
|
||||
update_free(alloc);
|
||||
if(server_socket >= 0)
|
||||
close(server_socket);
|
||||
if(param)
|
||||
update_free(param);
|
||||
TaskOTA = NULL;
|
||||
printf("\n\r[%s] Update task exit", __FUNCTION__);
|
||||
if(!ret){
|
||||
printf("\n\r[%s] Ready to reboot", __FUNCTION__);
|
||||
ota_platform_reset();
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
int update_ota_local(char *ip, int port){
|
||||
update_cfg_local_t *pUpdateCfg;
|
||||
|
||||
if(TaskOTA){
|
||||
printf("\n\r[%s] Update task has created.", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
pUpdateCfg = update_malloc(sizeof(update_cfg_local_t));
|
||||
if(pUpdateCfg == NULL){
|
||||
printf("\n\r[%s] Alloc update cfg failed", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
pUpdateCfg->ip_addr = inet_addr(ip);
|
||||
pUpdateCfg->port = ntohs(port);
|
||||
|
||||
if(xTaskCreate(update_ota_local_task, "OTA_server", STACK_SIZE, pUpdateCfg, TASK_PRIORITY, &TaskOTA) != pdPASS){
|
||||
update_free(pUpdateCfg);
|
||||
printf("\n\r[%s] Create update task failed", __FUNCTION__);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cmd_update(int argc, char **argv){
|
||||
int port;
|
||||
if(argc != 3){
|
||||
printf("\n\r[%s] Usage: update IP PORT", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
port = atoi(argv[2]);
|
||||
update_ota_local(argv[1], port);
|
||||
}
|
||||
|
||||
void cmd_ota_image(bool cmd){
|
||||
flash_t flash;
|
||||
uint32_t Part1Addr = 0xFFFFFFFF,Part2Addr = 0xFFFFFFFF;
|
||||
uint8_t *pbuf = NULL;
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_read_word(&flash, 0x18, &Part1Addr);
|
||||
Part1Addr = (Part1Addr&0xFFFF)*1024; // first partition
|
||||
flash_read_word(&flash, OFFSET_DATA, &Part2Addr);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
|
||||
if(Part2Addr == ~0x0)
|
||||
return;
|
||||
|
||||
pbuf = update_malloc(FLASH_SECTOR_SIZE);
|
||||
if(!pbuf) return;
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash, Part2Addr, FLASH_SECTOR_SIZE, pbuf);
|
||||
if (cmd == 1)
|
||||
memcpy((char*)pbuf+8, "81958711", 8);
|
||||
else
|
||||
memcpy((char*)pbuf+8, "01958711", 8);
|
||||
|
||||
flash_erase_sector(&flash, Part2Addr);
|
||||
flash_stream_write(&flash, Part2Addr, FLASH_SECTOR_SIZE, pbuf);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
|
||||
#if SWAP_UPDATE
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash, Part1Addr, FLASH_SECTOR_SIZE, pbuf);
|
||||
if (cmd == 1)
|
||||
memcpy((char*)pbuf+8, "01958711", 8);
|
||||
else
|
||||
memcpy((char*)pbuf+8, "81958711", 8);
|
||||
|
||||
flash_erase_sector(&flash, Part1Addr);
|
||||
flash_stream_write(&flash, Part1Addr, FLASH_SECTOR_SIZE, pbuf);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
#endif
|
||||
update_free(pbuf);
|
||||
}
|
||||
|
||||
#ifdef HTTP_OTA_UPDATE
|
||||
/******************************************************************************************************************
|
||||
** Function Name : update_ota_http_connect_server
|
||||
** Description : connect to the OTA server
|
||||
** Input : server_socket: the socket used
|
||||
** host: host address of the OTA server
|
||||
** port: port of the OTA server
|
||||
** Return : connect ok: socket value
|
||||
** Failed: -1
|
||||
*******************************************************************************************************************/
|
||||
int update_ota_http_connect_server(int server_socket, char *host, int port){
|
||||
struct sockaddr_in server_addr;
|
||||
struct hostent *server;
|
||||
|
||||
server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(server_socket < 0){
|
||||
printf("\n\r[%s] Create socket failed", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
server = gethostbyname(host);
|
||||
if(server == NULL){
|
||||
printf("[ERROR] Get host ip failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&server_addr,0,sizeof(server_addr));
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = htons(port);
|
||||
memcpy(&server_addr.sin_addr.s_addr,server->h_addr,server->h_length);
|
||||
|
||||
if (connect(server_socket,(struct sockaddr *)&server_addr, sizeof(server_addr)) < 0){
|
||||
printf("\n\r[%s] Socket connect failed", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return server_socket;
|
||||
}
|
||||
|
||||
/******************************************************************************************************************
|
||||
** Function Name : parse_http_response
|
||||
** Description : Parse the http response to get some useful parameters
|
||||
** Input : response : The http response got from server
|
||||
** response_len: The length of http response
|
||||
** result : The struct that store the usful infor about the http response
|
||||
** Return : Parse OK: 1 -> Only got the status code
|
||||
** 3 -> Got the status code and content_length, but didn't get the full header
|
||||
** 4 -> Got all the information needed
|
||||
** Failed: -1
|
||||
*******************************************************************************************************************/
|
||||
int parse_http_response(uint8_t *response, uint32_t response_len, http_response_result_t *result) {
|
||||
uint32_t i, p, q, m;
|
||||
uint32_t header_end = 0;
|
||||
|
||||
//Get status code
|
||||
if(0 == result->parse_status){//didn't get the http response
|
||||
uint8_t status[4] = {0};
|
||||
i = p = q = m = 0;
|
||||
for (; i < response_len; ++i) {
|
||||
if (' ' == response[i]) {
|
||||
++m;
|
||||
if (1 == m) {//after HTTP/1.1
|
||||
p = i;
|
||||
}
|
||||
else if (2 == m) {//after status code
|
||||
q = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!p || !q || q-p != 4) {//Didn't get the status code
|
||||
return -1;
|
||||
}
|
||||
memcpy(status, response+p+1, 3);//get the status code
|
||||
result->status_code = atoi((char const *)status);
|
||||
if(result->status_code == 200)
|
||||
result->parse_status = 1;
|
||||
else{
|
||||
printf("\n\r[%s] The http response status code is %d", __FUNCTION__, result->status_code);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
//if didn't receive the full http header
|
||||
if(3 == result->parse_status){//didn't get the http response
|
||||
p = q = 0;
|
||||
for (i = 0; i < response_len; ++i) {
|
||||
if (response[i] == '\r' && response[i+1] == '\n' &&
|
||||
response[i+2] == '\r' && response[i+3] == '\n') {//the end of header
|
||||
header_end = i+4;
|
||||
result->parse_status = 4;
|
||||
result->header_len = header_end;
|
||||
result->body = response + header_end;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (3 == result->parse_status) {//Still didn't receive the full header
|
||||
result->header_bak = update_malloc(HEADER_BAK_LEN + 1);
|
||||
memset(result->header_bak, 0, strlen(result->header_bak));
|
||||
memcpy(result->header_bak, response + response_len - HEADER_BAK_LEN, HEADER_BAK_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
//Get Content-Length
|
||||
if(1 == result->parse_status){//didn't get the content length
|
||||
uint32_t content_length = 0;
|
||||
const uint8_t *content_length_buf1 = "CONTENT-LENGTH";
|
||||
const uint8_t *content_length_buf2 = "Content-Length";
|
||||
const uint32_t content_length_buf_len = strlen(content_length_buf1);
|
||||
p = q = 0;
|
||||
|
||||
for (i = 0; i < response_len; ++i) {
|
||||
if (response[i] == '\r' && response[i+1] == '\n') {
|
||||
q = i;//the end of the line
|
||||
if (!memcmp(response+p, content_length_buf1, content_length_buf_len) ||
|
||||
!memcmp(response+p, content_length_buf2, content_length_buf_len)) {//get the content length
|
||||
int j1 = p+content_length_buf_len, j2 = q-1;
|
||||
while ( j1 < q && (*(response+j1) == ':' || *(response+j1) == ' ') ) ++j1;
|
||||
while ( j2 > j1 && *(response+j2) == ' ') --j2;
|
||||
uint8_t len_buf[12] = {0};
|
||||
memcpy(len_buf, response+j1, j2-j1+1);
|
||||
result->body_len = atoi((char const *)len_buf);
|
||||
result->parse_status = 2;
|
||||
}
|
||||
p = i+2;
|
||||
}
|
||||
if (response[i] == '\r' && response[i+1] == '\n' &&
|
||||
response[i+2] == '\r' && response[i+3] == '\n') {//Get the end of header
|
||||
header_end = i+4;//p is the start of the body
|
||||
if(result->parse_status == 2){//get the full header and the content length
|
||||
result->parse_status = 4;
|
||||
result->header_len = header_end;
|
||||
result->body = response + header_end;
|
||||
}
|
||||
else {//there are no content length in header
|
||||
printf("\n\r[%s] No Content-Length in header", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (1 == result->parse_status) {//didn't get the content length and the full header
|
||||
result->header_bak = update_malloc(HEADER_BAK_LEN + 1);
|
||||
memset(result->header_bak, 0, strlen(result->header_bak));
|
||||
memcpy(result->header_bak, response + response_len - HEADER_BAK_LEN, HEADER_BAK_LEN);
|
||||
}
|
||||
else if (2 == result->parse_status) {//didn't get the full header but get the content length
|
||||
result->parse_status = 3;
|
||||
result->header_bak = update_malloc(HEADER_BAK_LEN + 1);
|
||||
memset(result->header_bak, 0, strlen(result->header_bak));
|
||||
memcpy(result->header_bak, response + response_len - HEADER_BAK_LEN, HEADER_BAK_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
return result->parse_status;
|
||||
}
|
||||
|
||||
int http_update_ota(char *host, int port, char *resource)
|
||||
{
|
||||
int server_socket;
|
||||
unsigned char *buf, *alloc, *request;
|
||||
_file_checksum *file_checksum;
|
||||
int read_bytes = 0, i = 0;
|
||||
uint32_t address, flash_checksum = 0;
|
||||
uint32_t NewImg2Len = 0, NewImg2Addr = 0;
|
||||
int ret = -1;
|
||||
http_response_result_t rsp_result = {0};
|
||||
|
||||
alloc = update_malloc(BUF_SIZE + 4);
|
||||
if(!alloc){
|
||||
printf("\n\r[%s] Alloc buffer failed", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
buf = &alloc[4];
|
||||
file_checksum = (void*)alloc;
|
||||
|
||||
// Connect server
|
||||
server_socket = update_ota_http_connect_server(server_socket, host, port);
|
||||
if(server_socket == -1){
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
NewImg2Addr = update_ota_prepare_addr();
|
||||
if(NewImg2Addr == -1){
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
// reset
|
||||
file_checksum->u = 0;
|
||||
|
||||
// Write New Image 2 sector
|
||||
if(NewImg2Addr != ~0x0){
|
||||
uint32_t idx = 0;
|
||||
int data_len = 0;
|
||||
printf("\n\r");
|
||||
|
||||
//send http request
|
||||
request = (unsigned char *) update_malloc(strlen("GET /") + strlen(resource) + strlen(" HTTP/1.1\r\nHost: ")
|
||||
+ strlen(host) + strlen("\r\n\r\n") + 1);
|
||||
sprintf(request, "GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", resource, host);
|
||||
|
||||
ret = write(server_socket, request, strlen(request));
|
||||
if(ret < 0){
|
||||
printf("\n\r[%s] Send HTTP request failed", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
while (3 >= rsp_result.parse_status){//still read header
|
||||
if(0 == rsp_result.parse_status){//didn't get the http response
|
||||
memset(buf, 0, BUF_SIZE);
|
||||
read_bytes = read(server_socket, buf, BUF_SIZE);
|
||||
if(read_bytes == 0)
|
||||
continue;
|
||||
if(read_bytes < 0){
|
||||
printf("\n\r[%s] Read socket failed", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
idx = read_bytes;
|
||||
memset(&rsp_result, 0, sizeof(rsp_result));
|
||||
if(parse_http_response(buf, idx, &rsp_result) == -1){
|
||||
goto update_ota_exit;
|
||||
}
|
||||
}
|
||||
else if((1 == rsp_result.parse_status) || (3 == rsp_result.parse_status)){//just get the status code
|
||||
memset(buf, 0, BUF_SIZE);
|
||||
memcpy(buf, rsp_result.header_bak, HEADER_BAK_LEN);
|
||||
update_free(rsp_result.header_bak);
|
||||
rsp_result.header_bak = NULL;
|
||||
read_bytes = read(server_socket, buf+ HEADER_BAK_LEN, (BUF_SIZE - HEADER_BAK_LEN));
|
||||
if(read_bytes == 0)
|
||||
continue;
|
||||
if(read_bytes < 0){
|
||||
printf("\n\r[%s] Read socket failed", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
idx = read_bytes + HEADER_BAK_LEN;
|
||||
|
||||
if(parse_http_response(buf, read_bytes + HEADER_BAK_LEN, &rsp_result) == -1){
|
||||
goto update_ota_exit;
|
||||
}
|
||||
}
|
||||
else if(3 == rsp_result.parse_status){
|
||||
printf("\n\r[%s] Get the content_length failed", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == rsp_result.body_len){
|
||||
printf("\n\r[%s] New firmware size = 0 !", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
else
|
||||
printf("\n\r[%s] Download new firmware begin, total size : %d\n\r", __FUNCTION__, rsp_result.body_len);
|
||||
|
||||
#if SWAP_UPDATE
|
||||
NewImg2Addr = update_ota_swap_addr(rsp_result.body_len, NewImg2Addr);
|
||||
if(NewImg2Addr == -1){
|
||||
goto update_ota_exit;
|
||||
}
|
||||
#endif
|
||||
address = NewImg2Addr;
|
||||
NewImg2Len = update_ota_erase_upg_region(rsp_result.body_len, NewImg2Len, NewImg2Addr);
|
||||
if(NewImg2Len == -1){
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
//Write the body of http response into flash
|
||||
data_len = idx - rsp_result.header_len;
|
||||
if(data_len > 0){
|
||||
file_checksum->c[0] = alloc[4+data_len-4]; // checksum attached at file end
|
||||
file_checksum->c[1] = alloc[4+data_len-3];
|
||||
file_checksum->c[2] = alloc[4+data_len-2];
|
||||
file_checksum->c[3] = alloc[4+data_len-1];
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
if(flash_stream_write(&flash_ota, address, data_len, (buf+rsp_result.header_len)) < 0){
|
||||
printf("\n\r[%s] Write sector failed", __FUNCTION__);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
}
|
||||
|
||||
idx = 0;
|
||||
idx += data_len;
|
||||
while (idx < NewImg2Len){
|
||||
printf(".");
|
||||
data_len = NewImg2Len - idx;
|
||||
if(data_len > BUF_SIZE)
|
||||
data_len = BUF_SIZE;
|
||||
|
||||
memset(buf, 0, BUF_SIZE);
|
||||
read_bytes = read(server_socket, buf, data_len);
|
||||
if(read_bytes == 0)
|
||||
continue;
|
||||
if(read_bytes < 0){
|
||||
printf("\n\r[%s] Read socket failed", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
if(read_bytes<4)
|
||||
printf("\n\r[%s] Recv small packet", __FUNCTION__);
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
if(flash_stream_write(&flash_ota, address + idx, read_bytes, buf) < 0){
|
||||
printf("\n\r[%s] Write sector failed", __FUNCTION__);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
|
||||
file_checksum->c[0] = alloc[4+read_bytes-4]; // checksum attached at file end
|
||||
file_checksum->c[1] = alloc[4+read_bytes-3];
|
||||
file_checksum->c[2] = alloc[4+read_bytes-2];
|
||||
file_checksum->c[3] = alloc[4+read_bytes-1];
|
||||
|
||||
idx += read_bytes;
|
||||
}
|
||||
printf("\n\r[%s] Download new firmware %d bytes completed\n\r", __FUNCTION__, idx);
|
||||
|
||||
// read flash data back and calculate checksum
|
||||
for(i = 0; i < idx-4; i += BUF_SIZE){
|
||||
int k;
|
||||
int rlen = (idx-4-i)>BUF_SIZE?BUF_SIZE:(idx-4-i);
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash_ota, NewImg2Addr+i, rlen, buf);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
for(k = 0; k < rlen; k++)
|
||||
flash_checksum+=buf[k];
|
||||
}
|
||||
|
||||
ret = update_ota_checksum(file_checksum, flash_checksum, NewImg2Addr);
|
||||
if(ret == -1){
|
||||
printf("\n\r[%s] The checksume is wrong!\n\r", __FUNCTION__);
|
||||
goto update_ota_exit;
|
||||
}
|
||||
}
|
||||
update_ota_exit:
|
||||
if(alloc)
|
||||
update_free(alloc);
|
||||
if(request)
|
||||
update_free(request);
|
||||
if(server_socket >= 0)
|
||||
close(server_socket);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
97
vendor/sdk/component/soc/realtek/8195a/misc/platform/ota_8195a.h
vendored
Normal file
97
vendor/sdk/component/soc/realtek/8195a/misc/platform/ota_8195a.h
vendored
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#ifndef OTA_8195A_H
|
||||
#define OTA_8195A_H
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <platform_stdlib.h>
|
||||
#include <flash_api.h>
|
||||
#include <lwip/sockets.h>
|
||||
|
||||
/************************Related setting****************************/
|
||||
#define HTTP_OTA_UPDATE //if define, using http protocol, if not, will use socket
|
||||
#define CONFIG_CUSTOM_SIGNATURE 0 //if verify the custom signature(define in ota_8195a.c cus_sig)
|
||||
#define WRITE_OTA_ADDR 1
|
||||
#define SWAP_UPDATE 0
|
||||
|
||||
|
||||
#define BUF_SIZE 512
|
||||
#define HEADER_BAK_LEN 32
|
||||
|
||||
#define OFFSET_DATA FLASH_SYSTEM_DATA_ADDR
|
||||
#define IMAGE_2 0x0000B000
|
||||
#if WRITE_OTA_ADDR
|
||||
#define BACKUP_SECTOR (FLASH_SYSTEM_DATA_ADDR - 0x1000)
|
||||
#endif
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
/****************Define the structures used*************************/
|
||||
typedef struct{
|
||||
uint32_t ip_addr;
|
||||
uint16_t port;
|
||||
}update_cfg_local_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t status_code;
|
||||
uint32_t header_len;
|
||||
uint8_t *body;
|
||||
uint32_t body_len;
|
||||
uint8_t *header_bak;
|
||||
uint32_t parse_status;
|
||||
} http_response_result_t;
|
||||
|
||||
typedef union {
|
||||
uint32_t u;
|
||||
unsigned char c[4];
|
||||
} _file_checksum;
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
/****************General functions used by ota update***************/
|
||||
void *update_malloc(unsigned int size);
|
||||
void update_free(void *buf);
|
||||
void ota_platform_reset(void);
|
||||
#if WRITE_OTA_ADDR
|
||||
int write_ota_addr_to_system_data(flash_t *flash, uint32_t ota_addr);
|
||||
#endif
|
||||
int update_ota_connect_server(int server_socket, update_cfg_local_t *cfg);
|
||||
uint32_t update_ota_prepare_addr(void);
|
||||
#if SWAP_UPDATE
|
||||
uint32_t update_ota_swap_addr(uint32_t img_len, uint32_t NewImg2Addr);
|
||||
#endif
|
||||
int update_ota_erase_upg_region(uint32_t img_len, uint32_t NewImg2Len, uint32_t NewImg2Addr);
|
||||
int update_ota_checksum(_file_checksum *file_checksum, uint32_t flash_checksum, uint32_t NewImg2Addr);
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
/*******************Functions called by AT CMD**********************/
|
||||
void cmd_update(int argc, char **argv);
|
||||
void cmd_ota_image(bool cmd);
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : update_ota_local
|
||||
** Description : Starting a thread of OTA updating through socket
|
||||
** Input : ip:The IP address of OTA server
|
||||
** port:The Port of OTA server
|
||||
** Return : 0: Task created OK
|
||||
** -1: Task created failed
|
||||
**************************************************************************************************/
|
||||
int update_ota_local(char *ip, int port);
|
||||
|
||||
|
||||
#ifdef HTTP_OTA_UPDATE
|
||||
int parse_http_response(uint8_t *response, uint32_t response_len, http_response_result_t *result);
|
||||
int update_ota_http_connect_server(int server_socket, char *host, int port);
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : http_update_ota
|
||||
** Description : The process of OTA updating through http protocol
|
||||
** Input : cfg:struct update_cfg_local_t
|
||||
** Return : NULL
|
||||
**************************************************************************************************/
|
||||
int http_update_ota(char *host, int port, char *resource);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
256
vendor/sdk/component/soc/realtek/8195a/misc/rtl_std_lib/include/rt_lib_rom.h
vendored
Normal file
256
vendor/sdk/component/soc/realtek/8195a/misc/rtl_std_lib/include/rt_lib_rom.h
vendored
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
* rtl_lib.h
|
||||
*
|
||||
* Definitions for RTL library functions
|
||||
*/
|
||||
|
||||
#ifndef _RTL_LIB_ROM_H_
|
||||
#define _RTL_LIB_ROM_H_
|
||||
|
||||
|
||||
#include <basic_types.h>
|
||||
#include <diag.h>
|
||||
|
||||
#include <reent.h>
|
||||
|
||||
#include "../libc/rom/string/rom_libc_string.h"
|
||||
#include "../libgloss/rtl8195a/rom/rom_libgloss_retarget.h"
|
||||
|
||||
#ifndef _PTR
|
||||
#define _PTR void *
|
||||
#endif
|
||||
|
||||
#ifndef _AND
|
||||
#define _AND ,
|
||||
#endif
|
||||
|
||||
#ifndef _NOARGS
|
||||
#define _NOARGS void
|
||||
#endif
|
||||
|
||||
#ifndef _CONST
|
||||
#define _CONST const
|
||||
#endif
|
||||
|
||||
#ifndef _VOLATILE
|
||||
#define _VOLATILE volatile
|
||||
#endif
|
||||
|
||||
#ifndef _SIGNED
|
||||
#define _SIGNED signed
|
||||
#endif
|
||||
|
||||
#ifndef _DOTS
|
||||
#define _DOTS , ...
|
||||
#endif
|
||||
|
||||
#ifndef _VOID
|
||||
#define _VOID void
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// RTL library functions in ROM
|
||||
//
|
||||
|
||||
#define __rtl_memset __rtl_memset_v1_00
|
||||
#define __rtl_memchr __rtl_memchr_v1_00
|
||||
#define __rtl_memmove __rtl_memmove_v1_00
|
||||
#define __rtl_strcmp __rtl_strcmp_v1_00
|
||||
#define __rtl_memcpy __rtl_memcpy_v1_00
|
||||
|
||||
|
||||
|
||||
extern _LONG_CALL_ void * __rtl_memset_v1_00(void * m , int c , size_t n);
|
||||
extern _LONG_CALL_ void * __rtl_memchr_v1_00(const void * src_void , int c , size_t length);
|
||||
extern _LONG_CALL_ void * __rtl_memmove_v1_00( void * dst_void , const void * src_void , size_t length);
|
||||
extern _LONG_CALL_ int __rtl_strcmp_v1_00(const char *s1 , const char *s2);
|
||||
extern _LONG_CALL_ void * __rtl_memcpy_v1_00(void * __restrict dst0 , const void * __restrict src0 , size_t len0);
|
||||
|
||||
|
||||
//
|
||||
// rtl eabi functions
|
||||
//
|
||||
|
||||
#define __rtl_itod __rtl_itod_v1_00
|
||||
#define __rtl_dtoi __rtl_dtoi_v1_00
|
||||
#define __rtl_uitof __rtl_uitof_v1_00
|
||||
#define __rtl_uitod __rtl_uitod_v1_00
|
||||
|
||||
|
||||
|
||||
#define __rtl_dcmpeq __rtl_dcmpeq_v1_00
|
||||
#define __rtl_dcmplt __rtl_dcmplt_v1_00
|
||||
#define __rtl_dcmpgt __rtl_dcmpgt_v1_00
|
||||
|
||||
|
||||
#define __rtl_dadd __rtl_dadd_v1_00
|
||||
#define __rtl_dsub __rtl_dsub_v1_00
|
||||
#define __rtl_dmul __rtl_dmul_v1_00
|
||||
#define __rtl_ddiv __rtl_ddiv_v1_00
|
||||
|
||||
extern _LONG_CALL_ double __rtl_itod_v1_00(int lval);
|
||||
extern _LONG_CALL_ int __rtl_dtoi_v1_00(double d);
|
||||
extern _LONG_CALL_ float __rtl_uitof_v1_00(unsigned int lval);
|
||||
extern _LONG_CALL_ double __rtl_uitod_v1_00(unsigned int lval);
|
||||
|
||||
|
||||
extern _LONG_CALL_ int __rtl_dcmpeq_v1_00(double a, double b);
|
||||
extern _LONG_CALL_ int __rtl_dcmplt_v1_00(double a, double b);
|
||||
extern _LONG_CALL_ int __rtl_dcmpgt_v1_00(double a, double b);
|
||||
|
||||
|
||||
extern _LONG_CALL_ double __rtl_dadd_v1_00(double a, double b);
|
||||
extern _LONG_CALL_ double __rtl_dsub_v1_00(double a, double b);
|
||||
extern _LONG_CALL_ double __rtl_dmul_v1_00(double a, double b);
|
||||
extern _LONG_CALL_ double __rtl_ddiv_v1_00(double a, double b);
|
||||
|
||||
|
||||
//
|
||||
// mprec
|
||||
//
|
||||
|
||||
#include <reent.h>
|
||||
|
||||
|
||||
typedef struct _Bigint _Bigint;
|
||||
|
||||
|
||||
#define __rtl_Balloc __rtl_Balloc_v1_00
|
||||
#define __rtl_Bfree __rtl_Bfree_v1_00
|
||||
#define __rtl_d2b __rtl_d2b_v1_00
|
||||
#define __rtl_i2b __rtl_i2b_v1_00
|
||||
#define __rtl_pow5mult __rtl_pow5mult_v1_00
|
||||
#define __rtl_multadd __rtl_multadd_v1_00
|
||||
#define __rtl_mult __rtl_mult_v1_00
|
||||
#define __rtl_hi0bits __rtl_hi0bits_v1_00
|
||||
#define __rtl_lshift __rtl_lshift_v1_00
|
||||
#define __rtl_cmp __rtl_cmp_v1_00
|
||||
#define __rtl_diff __rtl_diff_v1_00
|
||||
|
||||
|
||||
extern _LONG_CALL_ _Bigint * __rtl_Balloc_v1_00(struct _reent *ptr, int k);
|
||||
|
||||
extern _LONG_CALL_ void __rtl_Bfree_v1_00(struct _reent *ptr, _Bigint * v);
|
||||
|
||||
extern _LONG_CALL_ _Bigint * __rtl_d2b_v1_00(struct _reent * ptr, double _d, int *e, int *bits);
|
||||
extern _LONG_CALL_ _Bigint * __rtl_i2b_v1_00(struct _reent *ptr, int i );
|
||||
extern _LONG_CALL_ _Bigint * __rtl_pow5mult_v1_00(struct _reent * ptr, _Bigint *b, int k);
|
||||
extern _LONG_CALL_ _Bigint * __rtl_multadd_v1_00(struct _reent *ptr, _Bigint * b, int m, int a);
|
||||
extern _LONG_CALL_ _Bigint * __rtl_mult_v1_00(struct _reent *ptr, _Bigint *a, _Bigint *b);
|
||||
extern _LONG_CALL_ int __rtl_hi0bits_v1_00(register __ULong x);
|
||||
extern _LONG_CALL_ _Bigint *__rtl_lshift_v1_00(struct _reent *ptr, _Bigint *b, int k);
|
||||
extern _LONG_CALL_ int __rtl_cmp_v1_00(_Bigint *a, _Bigint *b);
|
||||
extern _LONG_CALL_ _Bigint *__rtl_diff_v1_00(struct _reent* ptr, _Bigint *a, _Bigint *b);
|
||||
|
||||
//
|
||||
// dtoa
|
||||
//
|
||||
|
||||
#define __rtl_dtoa_r __rtl_dtoa_r_v1_00
|
||||
|
||||
extern char * __rtl_dtoa_r_v1_00(struct _reent *ptr, double _d, int mode, int ndigits, int *decpt, int *sign, char **rve);
|
||||
|
||||
//
|
||||
// mallocr
|
||||
//
|
||||
#include <sys/config.h>
|
||||
#include <reent.h>
|
||||
|
||||
|
||||
|
||||
#define __rom_mallocr_init __rom_mallocr_init_v1_00
|
||||
|
||||
#define __rtl_calloc_r __rtl_calloc_r_v1_00
|
||||
#define __rtl_cfree_r __rtl_cfree_r_v1_00
|
||||
#define __rtl_malloc_r __rtl_malloc_r_v1_00
|
||||
#define __rtl_free_r __rtl_free_r_v1_00
|
||||
#define __rtl_realloc_r __rtl_realloc_r_v1_00
|
||||
#define __rtl_memalign_r __rtl_memalign_r_v1_00
|
||||
#define __rtl_valloc_r __rtl_valloc_r_v1_00
|
||||
#define __rtl_pvalloc_r __rtl_pvalloc_r_v1_00
|
||||
|
||||
|
||||
extern _LONG_CALL_ void __rom_mallocr_init_v1_00(void);
|
||||
|
||||
|
||||
#define RARG struct _reent *reent_ptr,
|
||||
extern _LONG_CALL_ void* __rtl_calloc_r_v1_00(RARG size_t n, size_t elem_size);
|
||||
extern _LONG_CALL_ void __rtl_cfree_r_v1_00(void *mem);
|
||||
extern _LONG_CALL_ void* __rtl_malloc_r_v1_00(RARG size_t bytes);
|
||||
extern _LONG_CALL_ void __rtl_free_r_v1_00(RARG void* mem);
|
||||
extern _LONG_CALL_ void* __rtl_realloc_r_v1_00(RARG void* oldmem, size_t bytes);
|
||||
extern _LONG_CALL_ void* __rtl_memalign_r_v1_00(RARG size_t alignment, size_t bytes);
|
||||
extern _LONG_CALL_ void* __rtl_valloc_r_v1_00(RARG size_t bytes);
|
||||
extern _LONG_CALL_ void* __rtl_pvalloc_r_v1_00(RARG size_t bytes);
|
||||
|
||||
|
||||
//
|
||||
// stdio
|
||||
//
|
||||
extern int __rtl_errno;
|
||||
|
||||
#ifndef _READ_WRITE_RETURN_TYPE
|
||||
#define _READ_WRITE_RETURN_TYPE _ssize_t
|
||||
#endif
|
||||
|
||||
#ifndef _READ_WRITE_BUFSIZE_TYPE
|
||||
#define _READ_WRITE_BUFSIZE_TYPE int
|
||||
#endif
|
||||
|
||||
#define __rtl_sread __rtl_sread_v1_00
|
||||
#define __rtl_swrite __rtl_swrite_v1_00
|
||||
#define __rtl_seofread __rtl_seofread_v1_00
|
||||
#define __rtl_sseek __rtl_sseek_v1_00
|
||||
#define __rtl_sclose __rtl_sclose_v1_00
|
||||
#define __rtl_sbrk_r __rtl_sbrk_r_v1_00
|
||||
|
||||
extern _LONG_CALL_ _READ_WRITE_RETURN_TYPE __rtl_sread_v1_00(
|
||||
struct _reent *ptr,
|
||||
void *cookie,
|
||||
char *buf,
|
||||
_READ_WRITE_BUFSIZE_TYPE n);
|
||||
|
||||
extern _LONG_CALL_ _READ_WRITE_RETURN_TYPE __rtl_swrite_v1_00(
|
||||
struct _reent *ptr,
|
||||
void *cookie,
|
||||
char const *buf,
|
||||
_READ_WRITE_BUFSIZE_TYPE n);
|
||||
|
||||
extern _LONG_CALL_ _READ_WRITE_RETURN_TYPE __rtl_seofread_v1_00(
|
||||
struct _reent *_ptr,
|
||||
_PTR cookie,
|
||||
char *buf,
|
||||
_READ_WRITE_BUFSIZE_TYPE len);
|
||||
|
||||
extern _LONG_CALL_ _fpos_t __rtl_sseek_v1_00(
|
||||
struct _reent *ptr _AND
|
||||
void *cookie _AND
|
||||
_fpos_t offset _AND
|
||||
int whence);
|
||||
|
||||
extern _LONG_CALL_ int __rtl_sclose_v1_00(
|
||||
struct _reent *ptr _AND
|
||||
void *cookie);
|
||||
|
||||
extern _LONG_CALL_ void * __rtl_sbrk_r_v1_00(
|
||||
struct _reent *ptr,
|
||||
ptrdiff_t incr);
|
||||
|
||||
//
|
||||
// vfprintf
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define __rtl_vfprintf_r __rtl_vfprintf_r_v1_00
|
||||
|
||||
extern _LONG_CALL_ int __rtl_vfprintf_r_v1_00(struct _reent *, FILE *, const char *, va_list);
|
||||
|
||||
#ifndef CONFIG_RELEASE_BUILD_LIBRARIES
|
||||
#define __rtl_fflush_r __rtl_fflush_r_v1_00
|
||||
extern _LONG_CALL_ int __rtl_fflush_r_v1_00(struct _reent *ptr, register FILE * fp);
|
||||
#endif
|
||||
|
||||
#endif /* _RTL_LIB_ROM_H_ */
|
||||
143
vendor/sdk/component/soc/realtek/8195a/misc/rtl_std_lib/include/rtl_lib.h
vendored
Normal file
143
vendor/sdk/component/soc/realtek/8195a/misc/rtl_std_lib/include/rtl_lib.h
vendored
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* rtl_lib.h
|
||||
*
|
||||
* Definitions for RTL library functions
|
||||
*/
|
||||
|
||||
#ifndef _RTL_LIB_H_
|
||||
#define _RTL_LIB_H_
|
||||
|
||||
|
||||
#include <basic_types.h>
|
||||
#include <diag.h>
|
||||
#include <va_list.h>
|
||||
|
||||
extern int __rtl_errno;
|
||||
|
||||
|
||||
void init_rom_libgloss_ram_map(void);
|
||||
|
||||
|
||||
//
|
||||
// RTL library functions for Libc::stdio
|
||||
//
|
||||
|
||||
extern int rtl_printf(IN const char* fmt, ...);
|
||||
extern int rtl_vprintf(const char *fmt, va_list ap);
|
||||
extern int rtl_sprintf(char* str, const char* fmt, ...);
|
||||
extern int rtl_snprintf(char* str, size_t size, const char* fmt, ...);
|
||||
extern int rtl_vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
|
||||
|
||||
//
|
||||
// RTL library functions for string
|
||||
//
|
||||
|
||||
extern void * rtl_memchr(const void * src_void , int c , size_t length);
|
||||
extern int rtl_memcmp(const void * m1 , const void * m2 , size_t n);
|
||||
extern void * rtl_memcpy(void * dst0 , const void * src0 , size_t len0);
|
||||
extern void * rtl_memmove( void * dst_void , const void * src_void , size_t length);
|
||||
extern void * rtl_memset(void * m , int c , size_t n);
|
||||
extern char * rtl_strcat(char * s1 , const char * s2);
|
||||
extern char * rtl_strchr(const char *s1 , int i);
|
||||
extern int rtl_strcmp(const char *s1 , const char *s2);
|
||||
extern char* rtl_strcpy(char *dst0 , const char *src0);
|
||||
extern size_t rtl_strlen(const char *str);
|
||||
extern char * rtl_strncat(char * s1 , const char * s2 , size_t n);
|
||||
extern int rtl_strncmp(const char *s1 , const char *s2 , size_t n);
|
||||
extern char * rtl_strncpy(char * dst0 , const char * src0 , size_t count);
|
||||
extern char * rtl_strstr(const char *searchee , const char *lookfor);
|
||||
extern char * rtl_strsep(char **source_ptr , const char *delim);
|
||||
extern char * rtl_strtok(char * s , const char * delim);
|
||||
|
||||
//
|
||||
// RTL library functions for math
|
||||
//
|
||||
|
||||
|
||||
extern double rtl_fabs(double);
|
||||
extern float rtl_fabsf(float a);
|
||||
extern float rtl_cos_f32(float a);
|
||||
extern float rtl_sin_f32(float a);
|
||||
|
||||
extern float rtl_fadd(float a, float b);
|
||||
extern float rtl_fsub(float a, float b);
|
||||
extern float rtl_fmul(float a, float b);
|
||||
extern float rtl_fdiv(float a, float b);
|
||||
|
||||
extern int rtl_fcmplt(float a, float b);
|
||||
extern int rtl_fcmpgt(float a, float b);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// RTL eabi functions
|
||||
|
||||
extern double rtl_ftod(float f);
|
||||
|
||||
extern double rtl_ddiv(double a, double b);
|
||||
|
||||
|
||||
//
|
||||
// Macro Library Functions
|
||||
//
|
||||
|
||||
typedef union
|
||||
{
|
||||
float value;
|
||||
u32 word;
|
||||
} ieee_float_shape_type;
|
||||
|
||||
/* Get a 32 bit int from a float. */
|
||||
|
||||
#define GET_FLOAT_WORD(i,d) \
|
||||
do { \
|
||||
ieee_float_shape_type gf_u; \
|
||||
gf_u.value = (d); \
|
||||
(i) = gf_u.word; \
|
||||
} while (0)
|
||||
|
||||
/* Set a float from a 32 bit int. */
|
||||
|
||||
#define SET_FLOAT_WORD(d,i) \
|
||||
do { \
|
||||
ieee_float_shape_type sf_u; \
|
||||
sf_u.word = (i); \
|
||||
(d) = sf_u.value; \
|
||||
} while (0)
|
||||
|
||||
static inline
|
||||
float rtl_nanf(void)
|
||||
{
|
||||
float x;
|
||||
|
||||
SET_FLOAT_WORD(x,0x7fc00000);
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Library Test functions
|
||||
//
|
||||
|
||||
extern int rtl_lib_test(IN u16 argc, IN u8 *argv[]);
|
||||
extern int rtl_math_test(IN u16 argc, IN u8 *argv[]);
|
||||
extern int rtl_string_test(IN u16 argc, IN u8 *argv[]);
|
||||
|
||||
|
||||
//
|
||||
// Macro functions
|
||||
//
|
||||
|
||||
#undef dbg_printf
|
||||
#define dbg_printf(fmt, args...) \
|
||||
rtl_printf("%s():%d : " fmt "\n", __FUNCTION__, __LINE__, ##args);
|
||||
|
||||
|
||||
#undef err_printf
|
||||
#define err_printf(fmt, args...) \
|
||||
rtl_printf("%s():%d : " fmt "\n", __FUNCTION__, __LINE__, ##args);
|
||||
|
||||
|
||||
#endif /* _RTL_LIB_H_ */
|
||||
49
vendor/sdk/component/soc/realtek/8195a/misc/rtl_std_lib/libc/rom/string/rom_libc_string.h
vendored
Normal file
49
vendor/sdk/component/soc/realtek/8195a/misc/rtl_std_lib/libc/rom/string/rom_libc_string.h
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* rom_libc_string.h
|
||||
*
|
||||
* Definitions for standard library - libc functions.
|
||||
*/
|
||||
#ifndef _ROM_LIBC_STRING_H_
|
||||
#define _ROM_LIBC_STRING_H_
|
||||
|
||||
#include <basic_types.h>
|
||||
|
||||
#define __rtl_memchr __rtl_memchr_v1_00
|
||||
#define __rtl_memcmp __rtl_memcmp_v1_00
|
||||
#define __rtl_memcpy __rtl_memcpy_v1_00
|
||||
#define __rtl_memmove __rtl_memmove_v1_00
|
||||
#define __rtl_memset __rtl_memset_v1_00
|
||||
#define __rtl_strcat __rtl_strcat_v1_00
|
||||
#define __rtl_strchr __rtl_strchr_v1_00
|
||||
#define __rtl_strcmp __rtl_strcmp_v1_00
|
||||
#define __rtl_strcpy __rtl_strcpy_v1_00
|
||||
#define __rtl_strlen __rtl_strlen_v1_00
|
||||
#define __rtl_strncat __rtl_strncat_v1_00
|
||||
#define __rtl_strncmp __rtl_strncmp_v1_00
|
||||
#define __rtl_strncpy __rtl_strncpy_v1_00
|
||||
#define __rtl_strstr __rtl_strstr_v1_00
|
||||
#define __rtl_strsep __rtl_strsep_v1_00
|
||||
#define __rtl_strtok __rtl_strtok_v1_00
|
||||
|
||||
#define __rtl_critical_factorization __rtl_critical_factorization_v1_00
|
||||
#define __rtl_two_way_short_needle __rtl_two_way_short_needle_v1_00
|
||||
#define __rtl_two_way_long_needle __rtl_two_way_long_needle_v1_00
|
||||
|
||||
extern _LONG_CALL_ void * __rtl_memchr_v1_00(const void * src_void , int c , size_t length);
|
||||
extern _LONG_CALL_ int __rtl_memcmp_v1_00(const void * m1 , const void * m2 , size_t n);
|
||||
extern _LONG_CALL_ void * __rtl_memcpy_v1_00(void * __restrict dst0 , const void * __restrict src0 , size_t len0);
|
||||
extern _LONG_CALL_ void * __rtl_memmove_v1_00( void * dst_void , const void * src_void , size_t length);
|
||||
extern _LONG_CALL_ void * __rtl_memset_v1_00(void * m , int c , size_t n);
|
||||
extern _LONG_CALL_ char * __rtl_strcat_v1_00(char *__restrict s1 , const char *__restrict s2);
|
||||
extern _LONG_CALL_ char * __rtl_strchr_v1_00(const char *s1 , int i);
|
||||
extern _LONG_CALL_ int __rtl_strcmp_v1_00(const char *s1 , const char *s2);
|
||||
extern _LONG_CALL_ char* __rtl_strcpy_v1_00(char *dst0 , const char *src0);
|
||||
extern _LONG_CALL_ size_t __rtl_strlen_v1_00(const char *str);
|
||||
extern _LONG_CALL_ char * __rtl_strncat_v1_00(char *__restrict s1 , const char *__restrict s2 , size_t n);
|
||||
extern _LONG_CALL_ int __rtl_strncmp_v1_00(const char *s1 , const char *s2 , size_t n);
|
||||
extern _LONG_CALL_ char * __rtl_strncpy_v1_00(char *__restrict dst0 , const char *__restrict src0 , size_t count);
|
||||
extern _LONG_CALL_ char * __rtl_strstr_v1_00(const char *searchee , const char *lookfor);
|
||||
extern _LONG_CALL_ char * __rtl_strsep_v1_00(register char **source_ptr , register const char *delim);
|
||||
extern _LONG_CALL_ char * __rtl_strtok_v1_00(register char *__restrict s , register const char *__restrict delim);
|
||||
|
||||
#endif /* _ROM_LIBC_STRING_H_ */
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef ROM_LIBGLOSS_RETARGET_H
|
||||
#define ROM_LIBGLOSS_RETARGET_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <basic_types.h>
|
||||
|
||||
#define __rtl_close __rtl_close_v1_00
|
||||
#define __rtl_fstat __rtl_fstat_v1_00
|
||||
#define __rtl_isatty __rtl_isatty_v1_00
|
||||
#define __rtl_lseek __rtl_lseek_v1_00
|
||||
#define __rtl_open __rtl_open_v1_00
|
||||
#define __rtl_read __rtl_read_v1_00
|
||||
#define __rtl_write __rtl_write_v1_00
|
||||
#define __rtl_sbrk __rtl_sbrk_v1_00
|
||||
|
||||
extern _LONG_CALL_ int __rtl_close_v1_00(int fildes);
|
||||
extern _LONG_CALL_ int __rtl_fstat_v1_00(int fildes , struct stat *st);
|
||||
extern _LONG_CALL_ int __rtl_isatty_v1_00(int file);
|
||||
extern _LONG_CALL_ int __rtl_lseek_v1_00(int file , int ptr , int dir);
|
||||
extern _LONG_CALL_ int __rtl_open_v1_00(char *file , int flags , int mode);
|
||||
extern _LONG_CALL_ int __rtl_read_v1_00(int file , char *ptr , int len);
|
||||
extern _LONG_CALL_ int __rtl_write_v1_00(int file , const char *ptr , int len);
|
||||
extern _LONG_CALL_ void* __rtl_sbrk_v1_00(int incr);
|
||||
|
||||
|
||||
struct _rom_libgloss_ram_map {
|
||||
int (*libgloss_close)(int fildes);
|
||||
int (*libgloss_fstat)(int fildes , struct stat *st);
|
||||
int (*libgloss_isatty)(int file);
|
||||
int (*libgloss_lseek)(int file , int ptr , int dir);
|
||||
int (*libgloss_open)(char *file , int flags , int mode);
|
||||
int (*libgloss_read)(int file , char *ptr , int len);
|
||||
int (*libgloss_write)(int file , const char *ptr , int len);
|
||||
void* (*libgloss_sbrk)(int incr);
|
||||
};
|
||||
|
||||
#endif /* ROM_LIBGLOSS_RETARGET_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue