mirror of
https://github.com/pvvx/RTL00MP3.git
synced 2025-07-31 12:41:06 +00:00
update
This commit is contained in:
parent
05ec33236c
commit
9c9e8912a0
24 changed files with 2859 additions and 2451 deletions
|
|
@ -56,7 +56,7 @@ SECTIONS
|
|||
{
|
||||
/* __ram_start_table_start__ = .; */
|
||||
__ram_image1_text_start__ = .;
|
||||
KEEP(*(SORT(.start.ram.data*)))
|
||||
KEEP(*(.boot.start.ram.data*))
|
||||
/* __image1_validate_code__ = .; */
|
||||
KEEP(*(.image1.validate.rodata))
|
||||
|
||||
|
|
@ -67,18 +67,21 @@ SECTIONS
|
|||
KEEP(*(.libc.reent))
|
||||
KEEP(*(.rom.unc.data))
|
||||
KEEP(*(.sdr.rand2.data))
|
||||
__ram_image_end__ = .;
|
||||
/* 0x100020c0: end */
|
||||
|
||||
PROVIDE (__ram_image_end__ = .); /* 0x100020c0: end */
|
||||
|
||||
/* boot & images data */
|
||||
|
||||
KEEP(*(.hal.ram.data))
|
||||
KEEP(*(.hal.flash.data))
|
||||
/* KEEP(*(.data)); ? */
|
||||
build/obj/RTL00_SDKV35a/component/soc/realtek/8195a/fwlib/ram_lib/rtl_bios_data.o (.rodata*)
|
||||
KEEP(*(.ram.boot.text))
|
||||
build/obj/RTL00_SDKV35a/component/soc/realtek/8195a/fwlib/ram_lib/rtl_boot.o (.rodata*)
|
||||
KEEP(*(.boot.rodata*))
|
||||
KEEP(*(.boot.text*))
|
||||
KEEP(*(.boot.data))
|
||||
__image1_bss_start__ = .;
|
||||
KEEP(*(.boot.bss*))
|
||||
__image1_bss_end__ = .;
|
||||
__ram_image1_text_end__ = .;
|
||||
|
||||
} > BOOT_RAM
|
||||
|
||||
.romheap :
|
||||
|
|
@ -249,4 +252,5 @@ SECTIONS
|
|||
{
|
||||
KEEP(*(.loader.head*))
|
||||
}
|
||||
ASSERT(__ram_image_end__ != 0x100020c0, "Error rom-bios-boot code & data!")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,332 @@
|
|||
/*
|
||||
* console_api.c
|
||||
*
|
||||
* Created on: 24/02/17
|
||||
* Author: pvvx
|
||||
*/
|
||||
//======================================================
|
||||
#define LOGUART_STACK_SIZE 400 // USE_MIN_STACK_SIZE modify from 512 to 128
|
||||
#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) {
|
||||
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);
|
||||
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 >:
|
||||
//======================================================
|
||||
_WEAK void console_help(int argc, char *argv[]) { // Help
|
||||
DiagPrintf("CONSOLE COMMAND SET:\n");
|
||||
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("==============================\n");
|
||||
}
|
||||
// (!) размещается в специальном сегменте '.mon.tab*' (см. *.ld файл)
|
||||
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands[] = {
|
||||
{"?", 0, console_help, ": This Help"} // Help
|
||||
// {"HELP", 0, console_help, ": Help"} // Help
|
||||
};
|
||||
#endif
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
#include "rtl_bios_data.h"
|
||||
#include "va_list.h"
|
||||
|
||||
#define NOT_CHECK_LIBC_INIT 1
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
|
||||
|
|
@ -70,6 +72,7 @@ int libc_has_init;
|
|||
void rtl_libc_init(void) {
|
||||
__rom_mallocr_init_v1_00();
|
||||
init_rom_libgloss_ram_map();
|
||||
libc_has_init = 1;
|
||||
}
|
||||
|
||||
//----- rtl_snprintf()
|
||||
|
|
@ -79,10 +82,11 @@ int rtl_snprintf(char *str, size_t size, const char *fmt, ...) {
|
|||
int result;
|
||||
int w;
|
||||
FILE f;
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
libc_has_init = 1;
|
||||
}
|
||||
#endif
|
||||
if (size >= 0) {
|
||||
f._flags = 520;
|
||||
if (size)
|
||||
|
|
@ -109,11 +113,11 @@ int rtl_snprintf(char *str, size_t size, const char *fmt, ...) {
|
|||
//----- rtl_sprintf()
|
||||
int rtl_sprintf(char *str, const char *fmt, ...) {
|
||||
FILE f;
|
||||
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
libc_has_init = 1;
|
||||
}
|
||||
#endif
|
||||
f._flags = 520;
|
||||
f._w = 0x7FFFFFFF;
|
||||
f._bf._size = 0x7FFFFFFF;
|
||||
|
|
@ -130,10 +134,11 @@ int rtl_sprintf(char *str, const char *fmt, ...) {
|
|||
|
||||
//----- rtl_printf()
|
||||
int rtl_printf(const char *fmt, ...) {
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
libc_has_init = 1;
|
||||
}
|
||||
#endif
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr,
|
||||
|
|
@ -145,10 +150,11 @@ int rtl_printf(const char *fmt, ...) {
|
|||
|
||||
//----- rtl_vprintf()
|
||||
int rtl_vprintf(const char *fmt, void *param) {
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
libc_has_init = 1;
|
||||
}
|
||||
#endif
|
||||
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr,
|
||||
_rtl_impure_ptr->_stdout, fmt, *(va_list *)param);
|
||||
__rtl_fflush_r_v1_00(_rtl_impure_ptr, _rtl_impure_ptr->_stdout);
|
||||
|
|
@ -161,11 +167,11 @@ int rtl_vsnprintf(char *str, size_t size, const char *fmt, void *param) {
|
|||
int w;
|
||||
int v11;
|
||||
FILE f;
|
||||
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
libc_has_init = 1;
|
||||
}
|
||||
#endif
|
||||
if (size >= 0) {
|
||||
if (size)
|
||||
w = size - 1;
|
||||
|
|
@ -191,10 +197,11 @@ int rtl_vsnprintf(char *str, size_t size, const char *fmt, void *param) {
|
|||
|
||||
//----- rtl_vfprintf()
|
||||
int rtl_vfprintf(FILE *fp, const char *fmt0, va_list ap) {
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
libc_has_init = 1;
|
||||
}
|
||||
#endif
|
||||
return __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, fp, fmt0, ap);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,311 @@
|
|||
/*
|
||||
* RTL871x1Ax: RAM libc
|
||||
* Created on: 22/02/2017
|
||||
* Author: pvvx
|
||||
*/
|
||||
|
||||
#include "rtl_bios_data.h"
|
||||
#include "va_list.h"
|
||||
|
||||
#define NOT_CHECK_LIBC_INIT 1
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
|
||||
//void libc_init();
|
||||
//int snprintf(char *str, size_t size, const char *fmt, ...);
|
||||
//int sprintf(char *str, const char *fmt, ...);
|
||||
//int printf(const char *fmt, ...);
|
||||
//int vprintf(const char *fmt, void *param);
|
||||
//int vsnprintf(char *str, size_t size, const char *fmt, void *param);
|
||||
//int vfprintf(FILE *fp, const char *fmt0, va_list ap);
|
||||
//int memchr(const void *src_void, int c, size_t length);
|
||||
//int memcmp(const void *m1, const void *m2, size_t n);
|
||||
//int memcpy(void *dst0, const void *src0, size_t len0);
|
||||
//int memmove(void *dst_void, const void *src_void, size_t length);
|
||||
//int memset(void *m, int c, size_t n);
|
||||
//char * strcat(char *s1, const char *s2);
|
||||
//char * strchr(const char *s1, int i);
|
||||
//int strcmp(const char *s1, const char *s2);
|
||||
//char * strcpy(char *dst0, const char *src0);
|
||||
//int strlen(const char *str);
|
||||
//char * strncat(char *s1, const char *s2, size_t n);
|
||||
//int strncmp(const char *s1, const char *s2, size_t n);
|
||||
//char * strncpy(char *dst0, const char *src0, size_t count);
|
||||
//char * strstr(const char *searchee, const char *lookfor);
|
||||
//char * strsep(char **source_ptr, const char *delim);
|
||||
//char * strtok(char *s, const char *delim);
|
||||
// Extern Calls:
|
||||
// extern int init_rom_libgloss_ram_map(_DWORD)
|
||||
// extern int _rom_mallocr_init_v1_00(void)
|
||||
// extern int __rtl_vfprintf_r_v1_00(_DWORD, _DWORD, _DWORD)
|
||||
// extern int __rtl_fflush_r_v1_00(_DWORD, _DWORD)
|
||||
// extern int __rtl_memchr_v1_00(_DWORD, _DWORD, _DWORD)
|
||||
// extern int __rtl_memcmp_v1_00(_DWORD, _DWORD, _DWORD)
|
||||
// extern int __rtl_memcpy_v1_00(_DWORD, _DWORD, _DWORD)
|
||||
// extern int __rtl_memmove_v1_00(_DWORD, _DWORD, _DWORD)
|
||||
// extern int __rtl_memset_v1_00(_DWORD, _DWORD, _DWORD)
|
||||
// extern int __rtl_strcat_v1_00(_DWORD, _DWORD)
|
||||
// extern int __rtl_strchr_v1_00(_DWORD, _DWORD)
|
||||
// extern int __rtl_strcmp_v1_00(_DWORD, _DWORD)
|
||||
// extern int __rtl_strcpy_v1_00(_DWORD, _DWORD)
|
||||
// extern int __rtl_strlen_v1_00(_DWORD)
|
||||
// extern int __rtl_strncat_v1_00(_DWORD, _DWORD, _DWORD)
|
||||
// extern int __rtl_strncmp_v1_00(_DWORD, _DWORD, _DWORD)
|
||||
// extern int __rtl_strncpy_v1_00(_DWORD, _DWORD, _DWORD)
|
||||
// extern int __rtl_strstr_v1_00(_DWORD, _DWORD)
|
||||
// extern int __rtl_strsep_v1_00(_DWORD, _DWORD)
|
||||
// extern int __rtl_strtok_v1_00(_DWORD, _DWORD)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Data declarations
|
||||
|
||||
extern struct _reent * _rtl_impure_ptr;
|
||||
|
||||
extern int libc_has_init;
|
||||
// extern impure_ptr
|
||||
// extern impure_ptr
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Function
|
||||
|
||||
//----- snprintf()
|
||||
int snprintf(char *str, size_t size, const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
int result;
|
||||
int w;
|
||||
FILE f;
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
}
|
||||
#endif
|
||||
if (size >= 0) {
|
||||
f._flags = 520;
|
||||
if (size)
|
||||
w = size - 1;
|
||||
else
|
||||
w = 0;
|
||||
f._w = w; /* write space left for putc() */
|
||||
f._bf._size = w;
|
||||
f._file = -1; /* fileno, if Unix descriptor, else -1 */
|
||||
f._p = str; /* current position in (some) buffer */
|
||||
f._bf._base = str;
|
||||
result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, &f, fmt, args);
|
||||
if (result + 1 < 0)
|
||||
_rtl_impure_ptr->_errno = 139;
|
||||
if (size)
|
||||
*f._p = 0;
|
||||
} else {
|
||||
_rtl_impure_ptr->_errno = 139;
|
||||
result = -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//----- sprintf()
|
||||
int sprintf(char *str, const char *fmt, ...) {
|
||||
FILE f;
|
||||
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
}
|
||||
#endif
|
||||
f._flags = 520;
|
||||
f._w = 0x7FFFFFFF;
|
||||
f._bf._size = 0x7FFFFFFF;
|
||||
f._file = -1;
|
||||
f._p = str;
|
||||
f._bf._base = str;
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, &f, fmt, args);
|
||||
*f._p = 0;
|
||||
// va_end (args);
|
||||
return result;
|
||||
}
|
||||
|
||||
//----- printf()
|
||||
int printf(const char *fmt, ...) {
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
}
|
||||
#endif
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr,
|
||||
_rtl_impure_ptr->_stdout, fmt, args);
|
||||
__rtl_fflush_r_v1_00(_rtl_impure_ptr, _rtl_impure_ptr->_stdout);
|
||||
// va_end (args);
|
||||
return result;
|
||||
}
|
||||
|
||||
//----- vprintf()
|
||||
int vprintf(const char * fmt, __VALIST param) {
|
||||
//int vprintf(const char *fmt, void *param) {
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
}
|
||||
#endif
|
||||
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr,
|
||||
_rtl_impure_ptr->_stdout, fmt, param);
|
||||
__rtl_fflush_r_v1_00(_rtl_impure_ptr, _rtl_impure_ptr->_stdout);
|
||||
return result;
|
||||
}
|
||||
|
||||
//----- vsnprintf()
|
||||
int vsnprintf(char *str, size_t size, const char *fmt, __VALIST param) {
|
||||
int result;
|
||||
int w;
|
||||
int v11;
|
||||
FILE f;
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
}
|
||||
#endif
|
||||
if (size >= 0) {
|
||||
if (size)
|
||||
w = size - 1;
|
||||
else
|
||||
w = 0;
|
||||
f._flags = 520;
|
||||
f._p = str;
|
||||
f._bf._base = str;
|
||||
f._w = w;
|
||||
f._bf._size = w;
|
||||
f._file = -1;
|
||||
result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, &f, fmt, param);
|
||||
if (result + 1 < 0)
|
||||
_rtl_impure_ptr->_errno = 139;
|
||||
if (size)
|
||||
*f._p = 0;
|
||||
} else {
|
||||
_rtl_impure_ptr->_errno = 139;
|
||||
result = -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//----- vfprintf()
|
||||
int vfprintf(FILE *fp, const char *fmt0, va_list ap) {
|
||||
#if NOT_CHECK_LIBC_INIT
|
||||
if (!libc_has_init) {
|
||||
rtl_libc_init();
|
||||
}
|
||||
#endif
|
||||
return __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, fp, fmt0, ap);
|
||||
}
|
||||
|
||||
//----- memchr()
|
||||
void * memchr(const void * src_void , int c , size_t length) {
|
||||
return __rtl_memchr_v1_00(src_void, c, length);
|
||||
}
|
||||
|
||||
//----- memcmp()
|
||||
int memcmp(const void *m1, const void *m2, size_t n) {
|
||||
return __rtl_memcmp_v1_00(m1, m2, n);
|
||||
}
|
||||
|
||||
//----- memcpy()
|
||||
void * memcpy(void *dst0, const void *src0, size_t len0) {
|
||||
return __rtl_memcpy_v1_00(dst0, src0, len0);
|
||||
}
|
||||
|
||||
//----- memmove()
|
||||
void * memmove(void *dst_void, const void *src_void, size_t length) {
|
||||
return __rtl_memmove_v1_00(dst_void, src_void, length);
|
||||
}
|
||||
|
||||
//----- memset()
|
||||
void * memset(void *m, int c, size_t n) {
|
||||
return __rtl_memset_v1_00(m, c, n);
|
||||
}
|
||||
|
||||
//----- strcat()
|
||||
char * strcat(char *s1, const char *s2) {
|
||||
return (char *) __rtl_strcat_v1_00(s1, s2);
|
||||
}
|
||||
|
||||
//----- strchr()
|
||||
char * strchr(const char *s1, int i) {
|
||||
return (char *) __rtl_strchr_v1_00(s1, i);
|
||||
}
|
||||
|
||||
//----- strcmp()
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
return __rtl_strcmp_v1_00(s1, s2);
|
||||
}
|
||||
|
||||
//----- strcpy()
|
||||
char * strcpy(char *dst0, const char *src0) {
|
||||
return (char *) __rtl_strcpy_v1_00(dst0, src0);
|
||||
}
|
||||
|
||||
//----- strlen()
|
||||
size_t strlen(const char *str) {
|
||||
return __rtl_strlen_v1_00(str);
|
||||
}
|
||||
|
||||
//----- strncat()
|
||||
char * strncat(char *s1, const char *s2, size_t n) {
|
||||
return (char *) __rtl_strncat_v1_00(s1, s2, n);
|
||||
}
|
||||
|
||||
//----- strncmp()
|
||||
int strncmp(const char *s1, const char *s2, size_t n) {
|
||||
return __rtl_strncmp_v1_00(s1, s2, n);
|
||||
}
|
||||
|
||||
//----- strncpy()
|
||||
char * strncpy(char *dst0, const char *src0, size_t count) {
|
||||
return (char *) __rtl_strncpy_v1_00(dst0, src0, count);
|
||||
}
|
||||
|
||||
//----- strstr()
|
||||
char * strstr(const char *searchee, const char *lookfor) {
|
||||
return (char *) __rtl_strstr_v1_00(searchee, lookfor);
|
||||
}
|
||||
|
||||
//----- strsep()
|
||||
char * strsep(char **source_ptr, const char *delim) {
|
||||
return (char *) __rtl_strsep_v1_00(source_ptr, delim);
|
||||
}
|
||||
|
||||
//----- strtok()
|
||||
char * strtok(char *s, const char *delim) {
|
||||
return (char *) __rtl_strtok_v1_00(s, delim);
|
||||
}
|
||||
|
||||
int sscanf(const char *buf, const char *fmt, ...) {
|
||||
va_list args;
|
||||
int i;
|
||||
|
||||
va_start(args, fmt);
|
||||
i = _vsscanf(buf, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
#define TOUPPER(CH) \
|
||||
(((CH) >= 'a' && (CH) <= 'z') ? ((CH) - 'a' + 'A') : (CH))
|
||||
|
||||
int _stricmp (const char *s1, const char *s2)
|
||||
{
|
||||
while (*s2 != 0 && TOUPPER (*s1) == TOUPPER (*s2))
|
||||
s1++, s2++;
|
||||
return (int) (TOUPPER (*s1) - TOUPPER (*s2));
|
||||
}
|
||||
|
||||
unsigned long long __aeabi_llsr(unsigned long long val, unsigned int shift)
|
||||
{
|
||||
u32 lo = ((u32)val >> shift) | ((u32)(val >> 32) << (32 - shift));
|
||||
u32 hi = (u32)val >> shift;
|
||||
|
||||
return ((unsigned long long)hi << 32) | lo;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue