mirror of
https://github.com/drasko/open-ameba.git
synced 2026-07-11 13:55:42 +00:00
Change SDK dir name. Use OpenOCD only.
Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
This commit is contained in:
parent
05b731b5f3
commit
eeb7f808ae
1446 changed files with 1 additions and 65 deletions
46
sdk/component/soc/realtek/8195a/misc/driver/low_level_io.c
Normal file
46
sdk/component/soc/realtek/8195a/misc/driver/low_level_io.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include <stdio.h>
|
||||
#include "hal_api.h"
|
||||
|
||||
#if !defined (__ICCARM__)
|
||||
extern u8 RAM_IMG1_VALID_PATTEN[];
|
||||
void *tmp = RAM_IMG1_VALID_PATTEN;
|
||||
#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
|
||||
365
sdk/component/soc/realtek/8195a/misc/driver/rtl_consol.c
Normal file
365
sdk/component/soc/realtek/8195a/misc/driver/rtl_consol.c
Normal file
|
|
@ -0,0 +1,365 @@
|
|||
/*
|
||||
* 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_bios_data.h"
|
||||
//#include "rtl_consol.h"
|
||||
#include "osdep_api.h"
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#endif
|
||||
#include "tcm_heap.h"
|
||||
|
||||
//MON_RAM_BSS_SECTION UART_LOG_CTL UartLogCtl;
|
||||
//MON_RAM_BSS_SECTION 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
|
||||
|
||||
_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)
|
||||
RtlUpSemaFromISR((_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);
|
||||
pUartLogCtl->TaskRdy = 0;
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
#define LOGUART_STACK_SIZE 200 //USE_MIN_STACK_SIZE modify from 512 to 128
|
||||
#if 0 //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 *)"log_uart",
|
||||
LOGUART_STACK_SIZE,
|
||||
NULL,
|
||||
tskIDLE_PRIORITY + 5 + PRIORITIE_OFFSET, // +5
|
||||
NULL,
|
||||
stack_addr,
|
||||
NULL);
|
||||
if (pdTRUE != ret)
|
||||
{
|
||||
DiagPrintf("Create Log UART Task Err!\n");
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (pdTRUE != xTaskCreate( RtlConsolTaskRam, (const signed char * const)"log_uart", LOGUART_STACK_SIZE, NULL, tskIDLE_PRIORITY + 5 + PRIORITIE_OFFSET, NULL))
|
||||
{
|
||||
DiagPrintf("Create Log UART Task Err!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
CONSOLE_8195A();
|
||||
}
|
||||
|
||||
#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);
|
||||
#endif
|
||||
ArrayInitialize(argv[0], sizeof(argv[0]) ,0);
|
||||
}else{
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
acquire_wakelock(WAKELOCK_LOGUART);
|
||||
#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();
|
||||
#else
|
||||
#ifdef CONFIG_AT_USR
|
||||
at_user_init();
|
||||
#endif
|
||||
#endif
|
||||
//4 Set this for UartLog check cmd history
|
||||
#ifdef CONFIG_KERNEL
|
||||
pUartLogCtl->TaskRdy = 1;
|
||||
#else
|
||||
pUartLogCtl->BootRdy = 1;
|
||||
#endif
|
||||
do{
|
||||
#if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED
|
||||
RtlDownSema((_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);
|
||||
}
|
||||
extern void * UartLogRomCmdTable;
|
||||
//======================================================
|
||||
void console_init(void)
|
||||
{
|
||||
IRQ_HANDLE UartIrqHandle;
|
||||
|
||||
//4 Register Log Uart Callback function
|
||||
UartIrqHandle.Data = 0;//(u32)&UartAdapter;
|
||||
UartIrqHandle.IrqNum = UART_LOG_IRQ;
|
||||
UartIrqHandle.IrqFun = (IRQ_FUN) UartLogIrqHandleRam;
|
||||
UartIrqHandle.Priority = 0; // ??
|
||||
|
||||
|
||||
//4 Register Isr handle
|
||||
InterruptUnRegister(&UartIrqHandle);
|
||||
InterruptRegister(&UartIrqHandle);
|
||||
#if !TASK_SCHEDULER_DISABLED
|
||||
// RtlConsolInitRam((u32)ROM_STAGE,(u32)0,(VOID*)NULL);
|
||||
RtlConsolInitRam((u32)RAM_STAGE,(u32)6,(VOID*)UartLogRomCmdTable); // ); NULL);
|
||||
#else
|
||||
RtlConsolInitRam((u32)RAM_STAGE,(u32)6,(VOID*)UartLogRomCmdTable); // ); NULL);
|
||||
// RtlConsolInitRam((u32)ROM_STAGE,(u32)0,(VOID*)NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
136
sdk/component/soc/realtek/8195a/misc/driver/rtl_consol.h
Normal file
136
sdk/component/soc/realtek/8195a/misc/driver/rtl_consol.h
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* 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 "hal_diag.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
|
||||
|
||||
//extern COMMAND_TABLE UartLogRomCmdTable[6]; // in ROM (hal_diag.h)
|
||||
|
||||
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; //+0x00
|
||||
u8 SeeIdx; //+0x01
|
||||
u8 RevdNo; //+0x02
|
||||
u8 EscSTS; //+0x03
|
||||
u8 ExecuteCmd; //+0x04
|
||||
u8 ExecuteEsc; //+0x05
|
||||
u8 BootRdy; //+0x06
|
||||
u8 Resvd; //+0x07
|
||||
PUART_LOG_BUF pTmpLogBuf; //+0x08 = UartLogBuf
|
||||
VOID *pfINPUT; //+0x0C = DiagPrintf
|
||||
PCOMMAND_TABLE pCmdTbl; //+0x10
|
||||
u32 CmdTblSz; //+0x14
|
||||
#ifdef CONFIG_UART_LOG_HISTORY
|
||||
u32 CRSTS; //+0x18
|
||||
u8 (*pHistoryBuf)[UART_LOG_CMD_BUFLEN]; //+0x1C UartLogHistoryBuf[UART_LOG_HISTORY_LEN][UART_LOG_CMD_BUFLEN]
|
||||
#endif
|
||||
#ifdef CONFIG_KERNEL
|
||||
u32 TaskRdy; //+0x20
|
||||
_Sema Sema; //+0x24
|
||||
#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
|
||||
|
||||
#if CONFIG_DEBUG_LOG > 0
|
||||
#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
|
||||
);
|
||||
|
||||
_LONG_CALL_ extern VOID UartLogIrqHandle(VOID * Data); // in ROM
|
||||
|
||||
void console_init(void);
|
||||
|
||||
extern _LONG_CALL_ROM_ int GetArgc(const u8 *string);
|
||||
extern _LONG_CALL_ROM_ u8** GetArgv(const u8 *string);
|
||||
|
||||
|
||||
#endif //_RTK_CONSOL_H_
|
||||
340
sdk/component/soc/realtek/8195a/misc/driver/rtl_console_new.c
Normal file
340
sdk/component/soc/realtek/8195a/misc/driver/rtl_console_new.c
Normal file
|
|
@ -0,0 +1,340 @@
|
|||
/*
|
||||
* console_api.c
|
||||
*
|
||||
* Created on: 24/02/17
|
||||
* Author: pvvx
|
||||
*/
|
||||
//======================================================
|
||||
#ifndef LOGUART_STACK_SIZE
|
||||
#define LOGUART_STACK_SIZE 400 // USE_MIN_STACK_SIZE modify from 512 to 128
|
||||
#endif
|
||||
#define CONSOLE_PRIORITY 0
|
||||
//======================================================
|
||||
#include "rtl8195a.h"
|
||||
#include "rtl_bios_data.h"
|
||||
#include "osdep_api.h"
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#else
|
||||
#error "Define configUSE_WAKELOCK_PMU = 1 & configUSE_WAKELOCK_PMU = 1!"
|
||||
#endif
|
||||
#if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED
|
||||
#else
|
||||
#error "Define CONFIG_KERNEL & TASK_SCHEDULER_DISABLED = 0!"
|
||||
#endif
|
||||
#ifndef CONFIG_UART_LOG_HISTORY
|
||||
#error "Define CONFIG_UART_LOG_HISTORY!"
|
||||
#endif
|
||||
//======================================================
|
||||
// #define USE_ROM_CONSOLE
|
||||
//======================================================
|
||||
_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);
|
||||
//======================================================
|
||||
extern PCOMMAND_TABLE UartLogRamCmdTable[];
|
||||
extern UartLogRamCmdTableSize;
|
||||
//======================================================
|
||||
//<Function>: UartLogIrqHandleRam
|
||||
//<Usage >: To deal with Uart-Log RX IRQ
|
||||
//<Argus >: void
|
||||
//<Return >: void
|
||||
//<Notes >: NA
|
||||
//======================================================
|
||||
// overload original UartLogIrqHandle
|
||||
MON_RAM_TEXT_SECTION
|
||||
void UartLogIrqHandleRam(void * Data) {
|
||||
uint32 IrqEn = DiagGetIsrEnReg(); // HAL_UART_READ32(UART_INTERRUPT_EN_REG_OFF)
|
||||
DiagSetIsrEnReg(0); // HAL_UART_WRITE32(UART_INTERRUPT_EN_REG_OFF, 0)
|
||||
uint8 UartReceiveData = DiagGetChar(_FALSE); // if(flg) while(!(HAL_UART_READ32(UART_LINE_STATUS_REG_OFF)&1)); return HAL_UART_READ32(UART_REV_BUF_OFF);
|
||||
if (UartReceiveData == 0) {
|
||||
goto exit;
|
||||
}
|
||||
PUART_LOG_CTL p = pUartLogCtl;
|
||||
//KB_ESC chk is for cmd history, it's a special case here.
|
||||
if (UartReceiveData == KB_ASCII_ESC) {
|
||||
// Esc detection is only valid in the first stage of boot sequence (few seconds)
|
||||
if (p->ExecuteEsc != _TRUE) {
|
||||
p->ExecuteEsc = _TRUE;
|
||||
p->EscSTS = 0;
|
||||
} else {
|
||||
//4 the input commands are valid only when the task is ready to execute commands
|
||||
if (p->BootRdy == 1 || p->TaskRdy == 1) {
|
||||
if (p->EscSTS == 0) {
|
||||
p->EscSTS = 1;
|
||||
}
|
||||
} else {
|
||||
p->EscSTS = 0;
|
||||
}
|
||||
}
|
||||
} else if (p->EscSTS == 1) {
|
||||
if (UartReceiveData != KB_ASCII_LBRKT) { // '['
|
||||
p->EscSTS = 0;
|
||||
} else {
|
||||
p->EscSTS = 2;
|
||||
}
|
||||
} else {
|
||||
if (p->EscSTS == 2) {
|
||||
p->EscSTS = 0;
|
||||
if (UartReceiveData == 'A' || UartReceiveData == 'B') {
|
||||
// if(UartReceiveData == ...) set pUartLogCtl->SeeIdx ...
|
||||
// prvStrCpy(pUartLogCtl->pTmpLogBuf->UARTLogBuf, pUartLogCtl->pHistoryBuf[pUartLogCtl->SeeIdx]);
|
||||
// pUartLogCtl->pTmpLogBuf->BufCount = prvStrLen(pUartLogCtl->pTmpLogBuf->UARTLogBuf);
|
||||
// if(EchoFlag) pUartLogCtl->pfINPUT(pUartLogCtl->pTmpLogBuf->UARTLogBuf);
|
||||
UartLogHistoryCmd(UartReceiveData, (UART_LOG_CTL *) pUartLogCtl,
|
||||
1);
|
||||
}
|
||||
} else {
|
||||
if (UartLogCmdChk(UartReceiveData, (UART_LOG_CTL *) pUartLogCtl, 1)
|
||||
== 2) {
|
||||
// check UartLog buffer to prevent from incorrect access
|
||||
if (p->pTmpLogBuf != NULL) {
|
||||
p->ExecuteCmd = _TRUE;
|
||||
if (p->TaskRdy) {
|
||||
RtlUpSemaFromISR((_Sema *) &pUartLogCtl->Sema);
|
||||
}
|
||||
} else {
|
||||
ArrayInitialize((u8 *) pUartLogCtl->pTmpLogBuf->UARTLogBuf,
|
||||
UART_LOG_CMD_BUFLEN, '\0');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exit:
|
||||
DiagSetIsrEnReg(IrqEn); // HAL_UART_WRITE32(UART_INTERRUPT_EN_REG_OFF, IrqEn)
|
||||
}
|
||||
//======================================================
|
||||
//<Function>: GetArgvRam
|
||||
//<Usage >: парсигн аргументов строки
|
||||
//<Argus >: pstr - указатель на строку
|
||||
//<Return >: кол-во аргументов
|
||||
//<Notes >: 2 формата:
|
||||
// 1) cmd=arg1,arg2,...
|
||||
// 2) cmd arg1 arg2
|
||||
// arg может быть обрамлен '"' или '\''
|
||||
// для передачи ' ' или ','.
|
||||
// Начальные пробелы cmd или arg удаляются.
|
||||
//======================================================
|
||||
int GetArgvRam(IN u8 *pstr, u8** argv) {
|
||||
int arvc = 0;
|
||||
// u8** argv = ArgvArray;
|
||||
u8* p = pstr;
|
||||
u8 t, n = ' ';
|
||||
int m = 0;
|
||||
while(*p != 0
|
||||
&& *p != '\r'
|
||||
&& *p != '\n'
|
||||
&& arvc < MAX_ARGV
|
||||
&& p < &pstr[UART_LOG_CMD_BUFLEN-1]) {
|
||||
switch(m) {
|
||||
case 0: // wait cmd
|
||||
if(*p == ' ') {
|
||||
// *p = 0;
|
||||
break;
|
||||
}
|
||||
*argv++ = p;
|
||||
arvc++;
|
||||
m++;
|
||||
break;
|
||||
case 1: // test end cmd, type format parm
|
||||
if(*p == ' ') { // format cmd arg1 arg2 ...
|
||||
m++;
|
||||
*p = 0;
|
||||
} else if(*p == '=') { // "at" format cmd=arg1,arg2,...
|
||||
n = ',';
|
||||
m++;
|
||||
*p = 0;
|
||||
}
|
||||
break;
|
||||
case 2: // wait start arg
|
||||
if(*p == ' ') {
|
||||
*p = 0;
|
||||
break;
|
||||
}
|
||||
if(*p == '"' || *p == '\'') {
|
||||
t = *p;
|
||||
m = 4;
|
||||
*p = 0;
|
||||
break;
|
||||
}
|
||||
*argv++ = p;
|
||||
arvc++;
|
||||
m++;
|
||||
case 3: // end arg
|
||||
if(*p == n) { // ' ' or ','
|
||||
m = 2;
|
||||
*p = 0;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
*argv++ = p;
|
||||
arvc++;
|
||||
m++;
|
||||
case 5:
|
||||
if(*p == t) { // '\'' or '"'
|
||||
m = 3;
|
||||
*p = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
return arvc;
|
||||
}
|
||||
//======================================================
|
||||
//<Function>: RtlConsolTaskRam
|
||||
//<Usage >: overload original RtlConsolTaskRam
|
||||
//<Argus >: Data - указатель PUART_LOG_CTL
|
||||
//<Return >: none
|
||||
//<Notes >:
|
||||
//======================================================
|
||||
MON_RAM_TEXT_SECTION void RtlConsolTaskRam(void *Data) {
|
||||
PUART_LOG_CTL p = pUartLogCtl;
|
||||
#ifdef USE_ROM_CONSOLE // show Help
|
||||
p->pTmpLogBuf->UARTLogBuf[0] = '?';
|
||||
p->pTmpLogBuf->BufCount = 1;
|
||||
p->ExecuteCmd = _TRUE;
|
||||
#endif
|
||||
do {
|
||||
p->TaskRdy = _TRUE;
|
||||
RtlDownSema(&p->Sema);
|
||||
if (p->ExecuteCmd) {
|
||||
// UartLogCmdExecute(pUartLogCtl);
|
||||
int argc = GetArgvRam(p->pTmpLogBuf->UARTLogBuf, ArgvArray);
|
||||
if(argc) {
|
||||
StrUpr(ArgvArray[0]);
|
||||
PCOMMAND_TABLE pcmd = p->pCmdTbl;
|
||||
int flg = 1;
|
||||
#ifdef USE_ROM_CONSOLE
|
||||
for(int i = 0; i < p->CmdTblSz; i++) {
|
||||
#else
|
||||
while(pcmd->cmd) {
|
||||
#endif
|
||||
if(prvStrCmp(ArgvArray[0], pcmd->cmd) == 0) {
|
||||
flg = 0;
|
||||
if(pcmd->ArgvCnt < argc) {
|
||||
#ifdef USE_ROM_CONSOLE
|
||||
pcmd->func(argc-1, &ArgvArray[1]);
|
||||
#else
|
||||
pcmd->func(argc, &ArgvArray);
|
||||
#endif
|
||||
} else {
|
||||
#ifdef USE_ROM_CONSOLE
|
||||
DiagPrintf(pcmd->msg);
|
||||
#else
|
||||
DiagPrintf("%s%s\n", pcmd->cmd, pcmd->msg);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
pcmd++;
|
||||
}
|
||||
if(flg) DiagPrintf("cmd: %s - nothing!\n", ArgvArray[0]);
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
release_wakelock(WAKELOCK_LOGUART);
|
||||
#endif
|
||||
}
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
else acquire_wakelock(WAKELOCK_LOGUART);
|
||||
#endif
|
||||
p->pTmpLogBuf->BufCount = 0;
|
||||
p->pTmpLogBuf->UARTLogBuf[0] = 0;
|
||||
HalSerialPutcRtl8195a('\r');
|
||||
HalSerialPutcRtl8195a('>');
|
||||
p->ExecuteCmd = _FALSE;
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
//======================================================
|
||||
//<Function>: console_init
|
||||
//<Usage >: Initialize rtl console
|
||||
//<Argus >: none
|
||||
//<Return >: none
|
||||
//<Notes >: delete rtl_concole.h from project
|
||||
//======================================================
|
||||
MON_RAM_TEXT_SECTION void console_init(void) {
|
||||
IRQ_HANDLE UartIrqHandle;
|
||||
// Register Log Uart Callback function
|
||||
UartIrqHandle.Data = 0; // (u32)&UartAdapter;
|
||||
UartIrqHandle.IrqNum = UART_LOG_IRQ;
|
||||
UartIrqHandle.IrqFun = (IRQ_FUN) UartLogIrqHandleRam;
|
||||
UartIrqHandle.Priority = 0; // ??
|
||||
// Register Isr handle
|
||||
InterruptUnRegister(&UartIrqHandle);
|
||||
#ifdef USE_ROM_CONSOLE // use ROM Consol init & printf "<RTL8195A>"
|
||||
RtlConsolInit(RAM_STAGE, (u32) 6, (void*) UartLogRomCmdTable);
|
||||
#else
|
||||
UartLogBuf.BufCount = 0;
|
||||
ArrayInitialize(&UartLogBuf.UARTLogBuf[0], UART_LOG_CMD_BUFLEN, '\0');
|
||||
pUartLogCtl = &UartLogCtl;
|
||||
pUartLogCtl->NewIdx = 0;
|
||||
pUartLogCtl->SeeIdx = 0;
|
||||
pUartLogCtl->EscSTS = 0;
|
||||
pUartLogCtl->BootRdy = 0;
|
||||
pUartLogCtl->pTmpLogBuf = &UartLogBuf;
|
||||
pUartLogCtl->CRSTS = 0;
|
||||
pUartLogCtl->pHistoryBuf = UartLogHistoryBuf;
|
||||
pUartLogCtl->pfINPUT = (void*) &DiagPrintf;
|
||||
pUartLogCtl->pCmdTbl = (PCOMMAND_TABLE) UartLogRamCmdTable;
|
||||
pUartLogCtl->CmdTblSz = UartLogRamCmdTableSize/16; //6; // GetRomCmdNum()
|
||||
pUartLogCtl->TaskRdy = 0;
|
||||
#endif
|
||||
pUartLogCtl->RevdNo = UART_LOG_HISTORY_LEN;
|
||||
// Create a Semaphone
|
||||
RtlInitSema(&pUartLogCtl->Sema, 1);
|
||||
// executing boot sequence
|
||||
pUartLogCtl->ExecuteCmd = _FALSE;
|
||||
pUartLogCtl->ExecuteEsc = _TRUE; //don't check Esc anymore
|
||||
InterruptRegister(&UartIrqHandle);
|
||||
if (pdTRUE
|
||||
!= xTaskCreate(RtlConsolTaskRam,
|
||||
(const signed char * const )"loguart", LOGUART_STACK_SIZE,
|
||||
NULL, tskIDLE_PRIORITY + CONSOLE_PRIORITY + PRIORITIE_OFFSET, NULL)) {
|
||||
DiagPrintf("Create Log UART Task Err!!\n");
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef USE_ROM_CONSOLE
|
||||
//======================================================
|
||||
//<Function>: console_help
|
||||
//<Usage >: Initialize rtl console
|
||||
//<Argus >: argc - кол-во аргуметов, argv - список аргументов
|
||||
//<Return >: none
|
||||
//<Notes >:
|
||||
//======================================================
|
||||
extern char str_rom_57ch3Dch0A[]; // "=========================================================\n" 57 шт
|
||||
_WEAK void console_help(int argc, char *argv[]) { // Help
|
||||
DiagPrintf("CONSOLE COMMAND SET:\n");
|
||||
DiagPrintf(&str_rom_57ch3Dch0A[25]); // DiagPrintf("==============================\n");
|
||||
PCOMMAND_TABLE pcmdtab = UartLogRamCmdTable;
|
||||
while(pcmdtab->cmd) {
|
||||
#ifdef USE_ROM_CONSOLE
|
||||
DiagPrintf(pcmdtab->msg);
|
||||
#else
|
||||
DiagPrintf("%s%s\n", pcmdtab->cmd, pcmdtab->msg);
|
||||
#endif
|
||||
pcmdtab++;
|
||||
}
|
||||
DiagPrintf(&str_rom_57ch3Dch0A[25]); // DiagPrintf("==============================\n");
|
||||
}
|
||||
LOCAL void print_on(int argc, char *argv[])
|
||||
{
|
||||
print_off = argv[1][0]!='1';
|
||||
}
|
||||
// (!) размещается в специальном сегменте '.mon.tab*' (см. *.ld файл)
|
||||
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands[] = {
|
||||
{"PR", 1, print_on, "=<1/0>: Printf on/off"}, // Help
|
||||
{"?", 0, console_help, ": This Help"} // Help
|
||||
// {"HELP", 0, console_help, ": Help"} // Help
|
||||
};
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue