mirror of
https://github.com/pvvx/RTL00_WEB.git
synced 2025-07-31 20:31:05 +00:00
update
This commit is contained in:
parent
34d3652711
commit
39f77eb92b
1844 changed files with 899433 additions and 7 deletions
262
USDK/component/common/api/platform/dlist.h
Normal file
262
USDK/component/common/api/platform/dlist.h
Normal file
|
|
@ -0,0 +1,262 @@
|
|||
#ifndef __LIST_H
|
||||
#define __LIST_H
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#ifndef inline
|
||||
#define inline __inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This file is from Linux Kernel (include/linux/list.h)
|
||||
* and modified by simply removing hardware prefetching of list items.
|
||||
* Here by copyright, credits attributed to wherever they belong.
|
||||
* Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
#define INIT_LIST_HEAD(ptr) do { \
|
||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_add(struct list_head *new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = new;
|
||||
new->next = next;
|
||||
new->prev = prev;
|
||||
prev->next = new;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
static inline void list_add(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head, head->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add_tail - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
static inline void list_add_tail(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head->prev, head);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_del(struct list_head *prev, struct list_head *next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
* Note: list_empty on entry does not return true after this, the entry is in an undefined state.
|
||||
*/
|
||||
static inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = (void *) 0;
|
||||
entry->prev = (void *) 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
static inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move - delete from one list and add as another's head
|
||||
* @list: the entry to move
|
||||
* @head: the head that will precede our entry
|
||||
*/
|
||||
static inline void list_move(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move_tail - delete from one list and add as another's tail
|
||||
* @list: the entry to move
|
||||
* @head: the head that will follow our entry
|
||||
*/
|
||||
static inline void list_move_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add_tail(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_empty(struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
static inline void __list_splice(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->next;
|
||||
|
||||
first->prev = head;
|
||||
head->next = first;
|
||||
|
||||
last->next = at;
|
||||
at->prev = last;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice - join two lists
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list))
|
||||
__list_splice(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_init - join two lists and reinitialise the emptied list.
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*
|
||||
* The list at @list is reinitialised
|
||||
*/
|
||||
static inline void list_splice_init(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head);
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
|
||||
|
||||
/**
|
||||
* list_first_entry - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_head within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
|
||||
#define list_first_entry(ptr, type, member) \
|
||||
list_entry((ptr)->next, type, member)
|
||||
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); \
|
||||
pos = pos->next)
|
||||
/**
|
||||
* list_for_each_prev - iterate over a list backwards
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; pos != (head); \
|
||||
pos = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry(pos, head, member, type) \
|
||||
for (pos = list_entry((head)->next, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, type, member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe(pos, n, head, member, type) \
|
||||
for (pos = list_entry((head)->next, type, member), \
|
||||
n = list_entry(pos->member.next, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, type, member))
|
||||
|
||||
#endif
|
||||
154
USDK/component/common/api/platform/esp_comp.h
Normal file
154
USDK/component/common/api/platform/esp_comp.h
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
#ifndef _INCLUDE_ESP_COMP_H_
|
||||
#define _INCLUDE_ESP_COMP_H_
|
||||
|
||||
#include "platform_autoconf.h"
|
||||
#include "flash_api.h"
|
||||
|
||||
#define ICACHE_FLASH_ATTR
|
||||
#define ICACHE_RODATA_ATTR
|
||||
#define DATA_IRAM_ATTR
|
||||
#define ICACHE_RAM_ATTR
|
||||
|
||||
#define os_printf(...) rtl_printf(__VA_ARGS__)
|
||||
#define os_printf_plus(...) rtl_printf(__VA_ARGS__)
|
||||
#define os_sprintf_fd(...) rtl_sprintf(__VA_ARGS__)
|
||||
#define ets_sprintf(...) rtl_sprintf(__VA_ARGS__)
|
||||
#ifndef os_malloc
|
||||
#define os_malloc pvPortMalloc
|
||||
#define os_zalloc pvPortZalloc
|
||||
#define os_calloc pvPortCalloc
|
||||
#define os_realloc pvPortRealloc
|
||||
#endif
|
||||
#undef os_free
|
||||
#define os_free vPortFree
|
||||
#define system_get_free_heap_size xPortGetFreeHeapSize
|
||||
#undef os_realloc
|
||||
#define os_realloc pvPortReAlloc
|
||||
|
||||
|
||||
#define os_bzero rtl_bzero
|
||||
#define os_delay_us wait_us // HalDelayUs
|
||||
//#define os_install_putc1 rtl_install_putc1
|
||||
//#define os_install_putc2 rtl_install_putc2
|
||||
//#define os_intr_lock rtl_intr_lock
|
||||
//#define os_intr_unlock rtl_intr_unlock
|
||||
//#define os_isr_attach rtl_isr_attach
|
||||
//#define os_isr_mask rtl_isr_mask
|
||||
//#define os_isr_unmask rtl_isr_unmask
|
||||
#define os_memcmp rtl_memcmp
|
||||
#define os_memcpy rtl_memcpy
|
||||
#define ets_memcpy rtl_memcpy
|
||||
#define os_memmove rtl_memmove
|
||||
#define os_memset rtl_memset
|
||||
#define os_putc rtl_putc
|
||||
//#define os_str2macaddr rtl_str2macaddr
|
||||
//#define os_strcat strcat
|
||||
#define os_strchr rtl_strchr
|
||||
#define os_strrchr rtl_strrchr
|
||||
#define os_strcmp rtl_strcmp
|
||||
#define os_strcpy rtl_strcpy
|
||||
#define os_strlen rtl_strlen
|
||||
#define os_strncmp rtl_strncmp
|
||||
#define os_strncpy rtl_strncpy
|
||||
#define os_strstr rtl_strstr
|
||||
#define os_random Rand
|
||||
|
||||
//extern uint32 phy_get_rand(void);
|
||||
#define system_get_os_print() 1
|
||||
|
||||
#ifdef USE_US_TIMER
|
||||
#define os_timer_arm_us(a, b, c) rtl_timer_arm_new(a, b, c, 0)
|
||||
#endif
|
||||
|
||||
|
||||
//#define os_timer_arm(a, b, c) rtl_timer_arm_new(a, b, c, 1)
|
||||
//#define os_timer_disarm rtl_timer_disarm
|
||||
//#define os_timer_init rtl_timer_init
|
||||
//#define os_timer_setfn rtl_timer_setfn
|
||||
|
||||
//#define os_timer_done rtl_timer_done
|
||||
//#define os_timer_handler_isr rtl_timer_handler_isr
|
||||
|
||||
//#define os_update_cpu_frequency rtl_update_cpu_frequency
|
||||
|
||||
//#define os_sprintf ets_sprintf
|
||||
/*
|
||||
typedef struct{
|
||||
uint32_t deviceId; //+00
|
||||
uint32_t chip_size; //+04 chip size in byte
|
||||
uint32_t block_size; //+08
|
||||
uint32_t sector_size; //+0c
|
||||
uint32_t page_size; //+10
|
||||
uint32_t status_mask; //+14
|
||||
} SpiFlashChip;
|
||||
|
||||
typedef enum {
|
||||
SPI_FLASH_RESULT_OK,
|
||||
SPI_FLASH_RESULT_ERR,
|
||||
SPI_FLASH_RESULT_TIMEOUT
|
||||
} SpiFlashOpResult;
|
||||
|
||||
extern SpiFlashChip * flashchip; // in RAM-BIOS: 0x3fffc714
|
||||
*/
|
||||
|
||||
// include "flash_api.h"
|
||||
#define spi_flash_real_size() flash_get_size(&flashobj)
|
||||
#define Cache_Read_Disable() SpicDisableRtl8195A()
|
||||
#define Cache_Read_Enable(a, b, c) flash_turnon()
|
||||
|
||||
#define spi_flash_get_id() ((flashobj.SpicInitPara.id[0] << 16) | (flashobj.SpicInitPara.id[1]<<8) | flashobj.SpicInitPara.id[2])
|
||||
//SpiFlashOpResult spi_flash_read_status(uint32_t * sta);
|
||||
//SpiFlashOpResult spi_flash_write_status(uint32_t sta);
|
||||
#define spi_flash_erase_sector(sec) flash_erase_sector(&flashobj, (sec)<<12)
|
||||
#define spi_flash_write(faddr, pbuf, size) flash_stream_write(&flashobj, faddr, size, (uint8_t *)pbuf)
|
||||
#define spi_flash_read(faddr, pbuf, size) flash_stream_read(&flashobj, faddr, size, (uint8_t *)pbuf)
|
||||
#define spi_flash_erase_block(blk) flash_erase_block(&flashobj, (blk)<<16);
|
||||
|
||||
#define ip4_addr1(ipaddr) (((u8_t*)(ipaddr))[0])
|
||||
#define ip4_addr2(ipaddr) (((u8_t*)(ipaddr))[1])
|
||||
#define ip4_addr3(ipaddr) (((u8_t*)(ipaddr))[2])
|
||||
#define ip4_addr4(ipaddr) (((u8_t*)(ipaddr))[3])
|
||||
/* These are cast to u16_t, with the intent that they are often arguments
|
||||
* to printf using the U16_F format from cc.h. */
|
||||
#define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
|
||||
#define ip4_addr2_16(ipaddr) ((u16_t)ip4_addr2(ipaddr))
|
||||
#define ip4_addr3_16(ipaddr) ((u16_t)ip4_addr3(ipaddr))
|
||||
#define ip4_addr4_16(ipaddr) ((u16_t)ip4_addr4(ipaddr))
|
||||
|
||||
#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \
|
||||
ip4_addr2_16(ipaddr), \
|
||||
ip4_addr3_16(ipaddr), \
|
||||
ip4_addr4_16(ipaddr)
|
||||
|
||||
#define IPSTR "%d.%d.%d.%d"
|
||||
|
||||
#ifndef MAC2STR
|
||||
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
||||
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DEBUGSOO
|
||||
/* CONFIG_DEBUG_LOG:
|
||||
=0 Off all diag/debug msg,
|
||||
=1 Only errors,
|
||||
=2 errors + warning, (default)
|
||||
=3 errors + warning + info,
|
||||
=4 errors + warning + info + debug,
|
||||
=5 full */
|
||||
#if CONFIG_DEBUG_LOG > 3
|
||||
#define DEBUGSOO (CONFIG_DEBUG_LOG - 1)
|
||||
#elif CONFIG_DEBUG_LOG > 1
|
||||
#define DEBUGSOO 2
|
||||
#else
|
||||
#define DEBUGSOO CONFIG_DEBUG_LOG
|
||||
#endif
|
||||
#endif //#ifndef DEBUGSOO
|
||||
|
||||
//#define system_get_sdk_version() "3.5.3"
|
||||
|
||||
//#define system_get_time xTaskGetTickCount
|
||||
//#define ets_get_cpu_frequency HalGetCpuClk
|
||||
|
||||
|
||||
#endif // _INCLUDE_ESP_COMP_H_
|
||||
280
USDK/component/common/api/platform/platform_stdlib.h
Normal file
280
USDK/component/common/api/platform/platform_stdlib.h
Normal file
|
|
@ -0,0 +1,280 @@
|
|||
/******************************************************************************
|
||||
* Copyright (c) 2013-2016 Realtek Semiconductor Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
#ifndef __PLATFORM_STDLIB_H__
|
||||
#define __PLATFORM_STDLIB_H__
|
||||
|
||||
#define USE_CLIB_PATCH 0
|
||||
#if defined (__GNUC__)
|
||||
/* build rom should set USE_RTL_ROM_CLIB=0 */
|
||||
#ifndef CONFIG_MBED_ENABLED
|
||||
#include <rt_lib_rom.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BUILD_ROM
|
||||
#define USE_RTL_ROM_CLIB 0
|
||||
#else
|
||||
#define BUFFERED_PRINTF 0
|
||||
#ifndef CONFIG_MBED_ENABLED
|
||||
#define USE_RTL_ROM_CLIB 1
|
||||
#else
|
||||
#define USE_RTL_ROM_CLIB 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_8195A)
|
||||
#if defined (__IARSTDLIB__)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "diag.h"
|
||||
|
||||
#define strsep(str, delim) _strsep(str, delim)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "diag.h"
|
||||
#include "strproc.h"
|
||||
#include "basic_types.h"
|
||||
#include "hal_misc.h"
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#include "rtl_lib.h"
|
||||
#endif
|
||||
|
||||
#undef printf
|
||||
#undef sprintf
|
||||
#undef snprintf
|
||||
#undef atoi
|
||||
#undef memcmp
|
||||
#undef memcpy
|
||||
#undef memset
|
||||
#undef strcmp
|
||||
#undef strcpy
|
||||
#undef strlen
|
||||
#undef strncmp
|
||||
#undef strncpy
|
||||
#undef strsep
|
||||
#undef strtok
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#undef memchr
|
||||
#undef memmove
|
||||
#undef strcat
|
||||
#undef strchr
|
||||
#undef strncat
|
||||
#undef strstr
|
||||
#endif
|
||||
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#if BUFFERED_PRINTF
|
||||
extern int buffered_printf(const char* fmt, ...);
|
||||
#define printf buffered_printf
|
||||
#else
|
||||
#define printf rtl_printf
|
||||
#endif
|
||||
#define sprintf rtl_sprintf
|
||||
#define snprintf rtl_snprintf
|
||||
#define memchr rtl_memchr
|
||||
#define memcmp rtl_memcmp
|
||||
#define memcpy rtl_memcpy
|
||||
#define memmove rtl_memmove
|
||||
#define memset rtl_memset
|
||||
#define strcat rtl_strcat
|
||||
#define strchr rtl_strchr
|
||||
#define strcmp rtl_strcmp
|
||||
#define strcpy rtl_strcpy
|
||||
#define strlen rtl_strlen
|
||||
#define strncat rtl_strncat
|
||||
#define strncmp rtl_strncmp
|
||||
#define strncpy rtl_strncpy
|
||||
#define strstr rtl_strstr
|
||||
#define strsep rtl_strsep
|
||||
#define strtok rtl_strtok
|
||||
#else
|
||||
#if USE_CLIB_PATCH
|
||||
extern int DiagSscanfPatch(const char *buf, const char *fmt, ...);
|
||||
extern char* DiagStrtokPatch(char *str, const char* delim);
|
||||
extern char* DiagStrstrPatch(char *string, char *substring);
|
||||
extern int DiagSnPrintfPatch(char *buf, size_t size, const char *fmt, ...);
|
||||
extern u32 DiagPrintfPatch(const char *fmt, ...);
|
||||
extern u32 DiagSPrintfPatch(u8 *buf, const char *fmt, ...);
|
||||
#define printf DiagPrintfPatch
|
||||
#define sprintf DiagSPrintfPatch
|
||||
#define snprintf DiagSnPrintfPatch
|
||||
#define strstr(a, b) DiagStrstrPatch((char *)(a), (char *)(b))
|
||||
#define strtok DiagStrtokPatch
|
||||
#else
|
||||
#define printf DiagPrintf
|
||||
#define sprintf(fmt, arg...) DiagSPrintf((u8*)fmt, ##arg)
|
||||
#if defined (__GNUC__)
|
||||
#define snprintf DiagSnPrintf // NULL function
|
||||
#define strstr(str1, str2) prvStrStr(str1, str2) // NULL function
|
||||
#endif
|
||||
#define strtok(str, delim) _strsep(str, delim)
|
||||
#endif
|
||||
#define memcmp(dst, src, sz) _memcmp(dst, src, sz)
|
||||
#define memcpy(dst, src, sz) _memcpy(dst, src, sz)
|
||||
#define memset(dst, val, sz) _memset(dst, val, sz)
|
||||
#define strchr(s, c) _strchr(s, c) // for B-cut ROM
|
||||
#define strcmp(str1, str2) prvStrCmp((const unsigned char *) str1, (const unsigned char *) str2)
|
||||
#define strcpy(dest, src) _strcpy(dest, src)
|
||||
#define strlen(str) prvStrLen((const unsigned char *) str)
|
||||
#define strncmp(str1, str2, cnt) _strncmp(str1, str2, cnt)
|
||||
#define strncpy(dest, src, count) _strncpy(dest, src, count)
|
||||
#define strsep(str, delim) _strsep(str, delim)
|
||||
#endif
|
||||
|
||||
#define atoi(str) prvAtoi(str)
|
||||
#define strpbrk(cs, ct) _strpbrk(cs, ct) // for B-cut ROM
|
||||
|
||||
#if USE_CLIB_PATCH
|
||||
#undef sscanf
|
||||
#define sscanf DiagSscanfPatch
|
||||
#else
|
||||
#if defined (__GNUC__)
|
||||
#undef sscanf //_sscanf
|
||||
//extern int DiagSscanfPatch(const char *buf, const char *fmt, ...);
|
||||
//#define sscanf DiagSscanfPatch
|
||||
#define sscanf sscanf // use libc sscanf
|
||||
#endif
|
||||
#endif
|
||||
#endif // defined (__IARSTDLIB__)
|
||||
|
||||
//
|
||||
// memory management
|
||||
//
|
||||
#ifndef CONFIG_MBED_ENABLED
|
||||
extern void *pvPortMalloc( size_t xWantedSize );
|
||||
extern void vPortFree( void *pv );
|
||||
#define malloc pvPortMalloc
|
||||
#define zalloc pvPortZalloc
|
||||
#define free vPortFree
|
||||
#endif
|
||||
#elif defined (CONFIG_PLATFORM_8711B)
|
||||
|
||||
#if defined (__IARSTDLIB__)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h> /* va_list */
|
||||
#include "diag.h"
|
||||
|
||||
#define strsep(str, delim) _strsep(str, delim)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h> /* va_list */
|
||||
#include "diag.h"
|
||||
#include "strproc.h"
|
||||
#include "memproc.h"
|
||||
#include "basic_types.h"
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#include "rtl_lib.h"
|
||||
#include "rom_libc_string.h"
|
||||
#endif
|
||||
|
||||
#undef printf
|
||||
#undef sprintf
|
||||
#undef snprintf
|
||||
#undef memchr
|
||||
#undef memcmp
|
||||
#undef memcpy
|
||||
#undef memset
|
||||
#undef memmove
|
||||
#undef strcmp
|
||||
#undef strcpy
|
||||
#undef strlen
|
||||
#undef strncmp
|
||||
#undef strncpy
|
||||
#undef strsep
|
||||
#undef strtok
|
||||
#undef strcat
|
||||
#undef strchr
|
||||
#undef strncat
|
||||
#undef strstr
|
||||
#undef atol
|
||||
#undef atoi
|
||||
#undef strpbrk
|
||||
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#if BUFFERED_PRINTF
|
||||
extern int buffered_printf(const char* fmt, ...);
|
||||
#define printf buffered_printf
|
||||
#else
|
||||
#define printf rtl_printf
|
||||
#endif
|
||||
#define sprintf rtl_sprintf
|
||||
#define snprintf rtl_snprintf
|
||||
#define vsnprintf rtl_vsnprintf
|
||||
#else
|
||||
#define printf DiagPrintf
|
||||
#define sprintf(fmt, arg...) DiagSPrintf((u8*)fmt, ##arg)
|
||||
#define snprintf DiagSnPrintf // NULL function
|
||||
#define vsnprintf(buf, size, fmt, ap) VSprintf(buf, fmt, ap)
|
||||
#endif
|
||||
#define memchr __rtl_memchr_v1_00
|
||||
#define memcmp(dst, src, sz) _memcmp(dst, src, sz)
|
||||
#define memcpy(dst, src, sz) _memcpy(dst, src, sz)
|
||||
#define memmove __rtl_memmove_v1_00
|
||||
#define memset(dst, val, sz) _memset(dst, val, sz)
|
||||
|
||||
#define strchr(s, c) _strchr(s, c) // for B-cut ROM
|
||||
#define strcmp(str1, str2) prvStrCmp((const unsigned char *) str1, (const unsigned char *) str2)
|
||||
#define strcpy(dest, src) _strcpy(dest, src)
|
||||
#define strlen(str) prvStrLen((const unsigned char *) str)
|
||||
#define strsep(str, delim) _strsep(str, delim)
|
||||
#define strstr(str1, str2) prvStrStr(str1, str2) // NULL function
|
||||
#define strtok(str, delim) prvStrtok(str, delim)//_strsep(str, delim)
|
||||
#define strcat __rtl_strcat_v1_00
|
||||
|
||||
#define strncmp(str1, str2, cnt) _strncmp(str1, str2, cnt)
|
||||
#define strncpy(dest, src, count) _strncpy(dest, src, count)
|
||||
#define strncat __rtl_strncat_v1_00
|
||||
|
||||
#define atol(str) strtol(str,NULL,10)
|
||||
#define atoi(str) prvAtoi(str)
|
||||
#define strpbrk(cs, ct) _strpbrk(cs, ct) // for B-cut ROM
|
||||
#if defined (__GNUC__)
|
||||
#undef sscanf
|
||||
#define sscanf _sscanf_patch
|
||||
#define rand Rand
|
||||
#endif
|
||||
//extern int _sscanf_patch(const char *buf, const char *fmt, ...);
|
||||
//#define sscanf _sscanf_patch
|
||||
|
||||
|
||||
#endif // defined (__IARSTDLIB__)
|
||||
|
||||
//
|
||||
// memory management
|
||||
//
|
||||
extern void *pvPortMalloc( size_t xWantedSize );
|
||||
extern void vPortFree( void *pv );
|
||||
#define malloc pvPortMalloc
|
||||
#define free vPortFree
|
||||
#elif defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL) || defined(STM32F10X_XL)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
|
||||
#endif //__PLATFORM_STDLIB_H__
|
||||
|
||||
915
USDK/component/common/api/platform/stdlib_patch.c
Normal file
915
USDK/component/common/api/platform/stdlib_patch.c
Normal file
|
|
@ -0,0 +1,915 @@
|
|||
/*
|
||||
|
||||
this is the c lib patch, It can help when the clib provided by IAR
|
||||
does not work well.
|
||||
|
||||
How to use this:
|
||||
1.You must include platform_stdlib.h in you source file。
|
||||
2.There is a macro USE_CLIB_PATCH in platform_stdlib.h should be opened.
|
||||
|
||||
If there is some problems using this patch,
|
||||
You'd better check if you code runs into these functions:
|
||||
|
||||
DiagSscanfPatch
|
||||
DiagStrtokPatch
|
||||
DiagStrstrPatch
|
||||
DiagSnPrintfPatch
|
||||
DiagPrintfPatch
|
||||
DiagSPrintfPatch
|
||||
DiagPrintfPatch
|
||||
DiagSPrintfPatch
|
||||
DiagSnPrintfPatch
|
||||
DiagStrstrPatch
|
||||
DiagStrtokPatch
|
||||
|
||||
*/
|
||||
#ifndef CONFIG_PLATFORM_8711B
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define DiagPutChar HalSerialPutcRtl8195a
|
||||
|
||||
#define IN
|
||||
#define NULL 0
|
||||
|
||||
typedef unsigned int size_t;
|
||||
typedef unsigned int SIZE_T;
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned short int u16;
|
||||
typedef unsigned char u8;
|
||||
typedef signed long long s64;
|
||||
typedef signed int s32;
|
||||
typedef signed short int s16;
|
||||
typedef unsigned char bool;
|
||||
|
||||
|
||||
extern u8 txt0123456789ABCDEF[16];
|
||||
#define tab0123456789ABCDEF txt0123456789ABCDEF // = "0123456789ABCDEF"
|
||||
|
||||
|
||||
#define in_range(c, lo, up) ((u8)c >= lo && (u8)c <= up)
|
||||
#define isprint(c) in_range(c, 0x20, 0x7f)
|
||||
#define isdigit(c) in_range(c, '0', '9')
|
||||
#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
|
||||
#define islower(c) in_range(c, 'a', 'z')
|
||||
#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v' || c == ',')
|
||||
#define ULLONG_MAX (~0ULL)
|
||||
#define USHRT_MAX ((u16)(~0U))
|
||||
#define KSTRTOX_OVERFLOW (1U << 31)
|
||||
#define SHRT_MAX ((s16)(USHRT_MAX>>1))
|
||||
|
||||
static inline char _tolower(const char c)
|
||||
{
|
||||
return c | 0x20;
|
||||
}
|
||||
|
||||
|
||||
extern s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder);
|
||||
extern s64 div_s64(s64 dividend, s32 divisor);
|
||||
extern inline char _tolower(const char c);
|
||||
extern u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder);
|
||||
extern u64 div_u64(u64 dividend, u32 divisor);
|
||||
extern unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p);
|
||||
extern const char *_parse_integer_fixup_radix(const char *s, unsigned int *base);
|
||||
extern char *skip_spaces(const char *str);
|
||||
extern int skip_atoi(const char **s);
|
||||
extern void HalSerialPutcRtl8195a(u8 c);
|
||||
|
||||
|
||||
static unsigned long long simple_strtoull_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
unsigned long long result;
|
||||
unsigned int rv;
|
||||
|
||||
cp = _parse_integer_fixup_radix(cp, &base);
|
||||
rv = _parse_integer(cp, base, &result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static long long simple_strtoll_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
if(*cp == '-')
|
||||
return -simple_strtoull_patch(cp + 1, endp, base);
|
||||
|
||||
return simple_strtoull_patch(cp, endp, base);
|
||||
}
|
||||
static unsigned long simple_strtoul_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
return simple_strtoull_patch(cp, endp, base);
|
||||
}
|
||||
|
||||
static long simple_strtol_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
if(*cp == '-')
|
||||
return -simple_strtoul_patch(cp + 1, endp, base);
|
||||
|
||||
return simple_strtoul_patch(cp, endp, base);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int judge_digit_width(const char *str)
|
||||
{
|
||||
|
||||
int width = 0;
|
||||
|
||||
while(isdigit(*str)) {
|
||||
width++;
|
||||
str++;
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
static int _vsscanf_patch(const char *buf, const char *fmt, va_list args)
|
||||
{
|
||||
const char *str = buf;
|
||||
char *next;
|
||||
char digit;
|
||||
int num = 0;
|
||||
int i =0;
|
||||
u8 qualifier;
|
||||
unsigned int base;
|
||||
union {
|
||||
long long s;
|
||||
unsigned long long u;
|
||||
} val;
|
||||
s16 field_width;
|
||||
bool is_sign;
|
||||
|
||||
char str_store[20] = {0};
|
||||
|
||||
|
||||
|
||||
while(*fmt) {
|
||||
/* skip any white space in format */
|
||||
/* white space in format matchs any amount of
|
||||
* white space, including none, in the input.
|
||||
*/
|
||||
if(isspace(*fmt)) {
|
||||
fmt = skip_spaces(++fmt);
|
||||
str = skip_spaces(str);
|
||||
}
|
||||
|
||||
/* anything that is not a conversion must match exactly */
|
||||
if(*fmt != '%' && *fmt) {
|
||||
if(*fmt++ != *str++) {
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!*fmt) {
|
||||
break;
|
||||
}
|
||||
|
||||
++fmt;
|
||||
|
||||
/* skip this conversion.
|
||||
* advance both strings to next white space
|
||||
*/
|
||||
if(*fmt == '*') {
|
||||
if(!*str) {
|
||||
break;
|
||||
}
|
||||
|
||||
while(!isspace(*fmt) && *fmt != '%' && *fmt)
|
||||
fmt++;
|
||||
|
||||
while(!isspace(*str) && *str)
|
||||
str++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* get field width */
|
||||
field_width = -1;
|
||||
|
||||
if(isdigit(*fmt)) {
|
||||
|
||||
field_width = skip_atoi(&fmt);
|
||||
|
||||
|
||||
|
||||
if(field_width <= 0) {
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* get conversion qualifier */
|
||||
qualifier = -1;
|
||||
|
||||
if(*fmt == 'h' || _tolower(*fmt) == 'l' ||
|
||||
_tolower(*fmt) == 'z') {
|
||||
qualifier = *fmt++;
|
||||
|
||||
if(qualifier == *fmt) {
|
||||
if(qualifier == 'h') {
|
||||
qualifier = 'H';
|
||||
fmt++;
|
||||
} else if(qualifier == 'l') {
|
||||
qualifier = 'L';
|
||||
fmt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!*fmt) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(*fmt == 'n') {
|
||||
/* return number of characters read so far */
|
||||
*va_arg(args, int *) = str - buf;
|
||||
++fmt;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!*str) {
|
||||
break;
|
||||
}
|
||||
|
||||
base = 10;
|
||||
is_sign = 0;
|
||||
|
||||
switch(*fmt++) {
|
||||
case 'c': {
|
||||
char *s = (char *)va_arg(args, char*);
|
||||
|
||||
if(field_width == -1)
|
||||
field_width = 1;
|
||||
|
||||
do {
|
||||
*s++ = *str++;
|
||||
} while(--field_width > 0 && *str);
|
||||
|
||||
num++;
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
case 's': {
|
||||
char *s = (char *)va_arg(args, char *);
|
||||
|
||||
if(field_width == -1)
|
||||
field_width = SHRT_MAX;
|
||||
|
||||
/* first, skip leading white space in buffer */
|
||||
str = skip_spaces(str);
|
||||
|
||||
/* now copy until next white space */
|
||||
while(*str && !isspace(*str) && field_width--) {
|
||||
*s++ = *str++;
|
||||
}
|
||||
|
||||
*s = '\0';
|
||||
num++;
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
case 'o':
|
||||
base = 8;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
case 'X':
|
||||
base = 16;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
base = 0;
|
||||
|
||||
case 'd':
|
||||
is_sign = 1;
|
||||
|
||||
case 'u':
|
||||
break;
|
||||
|
||||
case '%':
|
||||
|
||||
/* looking for '%' in str */
|
||||
if(*str++ != '%') {
|
||||
return num;
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
default:
|
||||
/* invalid format; stop here */
|
||||
return num;
|
||||
}
|
||||
|
||||
/* have some sort of integer conversion.
|
||||
* first, skip white space in buffer.
|
||||
*/
|
||||
str = skip_spaces(str);
|
||||
|
||||
digit = *str;
|
||||
|
||||
if(is_sign && digit == '-')
|
||||
digit = *(str + 1);
|
||||
|
||||
if(!digit
|
||||
|| (base == 16 && !isxdigit(digit))
|
||||
|| (base == 10 && !isdigit(digit))
|
||||
|| (base == 8 && (!isdigit(digit) || digit > '7'))
|
||||
|| (base == 0 && !isdigit(digit))) {
|
||||
break;
|
||||
}
|
||||
|
||||
//here problem *******************************************
|
||||
|
||||
|
||||
|
||||
//troy add ,fix support %2d, but not support %d
|
||||
if(field_width <= 0) {
|
||||
|
||||
field_width = judge_digit_width(str);
|
||||
}
|
||||
|
||||
|
||||
/////troy add, fix str passed inwidth wrong
|
||||
for(i = 0; i<field_width ; i++)
|
||||
str_store[i] = str[i];
|
||||
|
||||
next = (char*)str + field_width;
|
||||
|
||||
|
||||
|
||||
if(is_sign) {
|
||||
val.s = qualifier != 'L' ?
|
||||
simple_strtol_patch(str_store, &next, base) :
|
||||
simple_strtoll_patch(str_store, &next, base);
|
||||
} else {
|
||||
val.u = qualifier != 'L' ?
|
||||
simple_strtoul_patch(str_store, &next, base) :
|
||||
simple_strtoull_patch(str_store, &next, base);
|
||||
}
|
||||
|
||||
|
||||
////troy add
|
||||
for(i = 0; i<20 ; i++)
|
||||
str_store[i] = 0;
|
||||
|
||||
|
||||
//判断转换的字符串的宽度是否大于 %2d
|
||||
if(field_width > 0 && next - str > field_width) {
|
||||
if(base == 0)
|
||||
_parse_integer_fixup_radix(str, &base);
|
||||
|
||||
while(next - str > field_width) {
|
||||
if(is_sign) {
|
||||
val.s = div_s64(val.s, base);
|
||||
} else {
|
||||
val.u = div_u64(val.u, base);
|
||||
}
|
||||
|
||||
--next;
|
||||
}
|
||||
}
|
||||
|
||||
switch(qualifier) {
|
||||
case 'H': /* that's 'hh' in format */
|
||||
if(is_sign)
|
||||
*va_arg(args, signed char *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned char *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
if(is_sign)
|
||||
*va_arg(args, short *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned short *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
if(is_sign)
|
||||
*va_arg(args, long *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned long *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
if(is_sign)
|
||||
*va_arg(args, long long *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned long long *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'Z':
|
||||
case 'z':
|
||||
*va_arg(args, size_t *) = val.u;
|
||||
break;
|
||||
|
||||
default:
|
||||
if(is_sign)
|
||||
*va_arg(args, int *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned int *) = val.u;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
num++;
|
||||
|
||||
if(!next) {
|
||||
break;
|
||||
}
|
||||
|
||||
str = next;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
int DiagSscanfPatch(const char *buf, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int i;
|
||||
|
||||
va_start(args, fmt);
|
||||
i = _vsscanf_patch(buf, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
|
||||
char* DiagStrtokPatch(char *str, const char* delim) {
|
||||
static char* _buffer;
|
||||
|
||||
if(str != NULL) _buffer = str;
|
||||
|
||||
if(_buffer[0] == '\0') return NULL;
|
||||
|
||||
char *ret = _buffer, *b;
|
||||
const char *d;
|
||||
|
||||
for(b = _buffer; *b !='\0'; b++) {
|
||||
for(d = delim; *d != '\0'; d++) {
|
||||
if(*b == *d) {
|
||||
*b = '\0';
|
||||
_buffer = b+1;
|
||||
|
||||
// skip the beginning delimiters
|
||||
if(b == ret) {
|
||||
ret++;
|
||||
continue;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
|
||||
char *DiagStrstrPatch(char *string, char *substring)
|
||||
{
|
||||
register char *a, *b;
|
||||
|
||||
/* First scan quickly through the two strings looking for a
|
||||
* single-character match. When it's found, then compare the
|
||||
* rest of the substring.
|
||||
*/
|
||||
|
||||
b = substring;
|
||||
|
||||
if(*b == 0) {
|
||||
return string;
|
||||
}
|
||||
|
||||
for(; *string != 0; string += 1) {
|
||||
if(*string != *b) {
|
||||
continue;
|
||||
}
|
||||
|
||||
a = string;
|
||||
|
||||
while(1) {
|
||||
if(*b == 0) {
|
||||
return string;
|
||||
}
|
||||
|
||||
if(*a++ != *b++) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
b = substring;
|
||||
}
|
||||
|
||||
return (char *) 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
int DiagSnPrintfPatch(char *buf, size_t size, const char *fmt, ...)
|
||||
{
|
||||
|
||||
va_list ap;
|
||||
char *p, *s, *buf_end = NULL;
|
||||
const int *dp = ((const int *)&fmt)+1;
|
||||
|
||||
if(buf == NULL)
|
||||
return 0;
|
||||
|
||||
|
||||
va_start(ap, fmt);
|
||||
s = buf;
|
||||
buf_end = size? (buf + size):(char*)~0;
|
||||
|
||||
for(; *fmt != '\0'; ++fmt) {
|
||||
|
||||
if(*fmt != '%') {
|
||||
*s++ = *fmt;
|
||||
|
||||
if(s >= buf_end) {
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(*++fmt == 's') {
|
||||
for(p = (char *)*dp++; *p != '\0'; p++) {
|
||||
*s++ = *p;
|
||||
|
||||
if(s >= buf_end) {
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* Length of item is bounded */
|
||||
char tmp[20], *q = tmp;
|
||||
int alt = 0;
|
||||
int shift = 0;// = 12;
|
||||
const long *lpforchk = (const long *)dp;
|
||||
|
||||
if((*lpforchk) < 0x10) {
|
||||
shift = 0;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x10) && ((*lpforchk) < 0x100)) {
|
||||
shift = 4;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x100) && ((*lpforchk) < 0x1000)) {
|
||||
shift = 8;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x1000) && ((*lpforchk) < 0x10000)) {
|
||||
shift = 12;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x10000) && ((*lpforchk) < 0x100000)) {
|
||||
shift = 16;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x100000) && ((*lpforchk) < 0x1000000)) {
|
||||
shift = 20;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x1000000) && ((*lpforchk) < 0x10000000)) {
|
||||
shift = 24;
|
||||
}
|
||||
else if((*lpforchk) >= 0x10000000) {
|
||||
shift = 28;
|
||||
}
|
||||
else {
|
||||
shift = 28;
|
||||
}
|
||||
|
||||
if((*fmt >= '0') && (*fmt <= '9'))
|
||||
{
|
||||
int width;
|
||||
unsigned char fch = *fmt;
|
||||
|
||||
for(width=0; (fch>='0') && (fch<='9'); fch=*++fmt)
|
||||
{ width = width * 10 + fch - '0';
|
||||
}
|
||||
|
||||
shift=(width-1)*4;
|
||||
}
|
||||
|
||||
/*
|
||||
* Before each format q points to tmp buffer
|
||||
* After each format q points past end of item
|
||||
*/
|
||||
if((*fmt == 'x')||(*fmt == 'X') || (*fmt == 'p') || (*fmt == 'P')) {
|
||||
/* With x86 gcc, sizeof(long) == sizeof(int) */
|
||||
const long *lp = (const long *)dp;
|
||||
long h = *lp++;
|
||||
int hex_count = 0;
|
||||
unsigned long h_back = h;
|
||||
int ncase = (*fmt & 0x20);
|
||||
dp = (const int *)lp;
|
||||
|
||||
if((*fmt == 'p') || (*fmt == 'P'))
|
||||
alt=1;
|
||||
|
||||
if(alt) {
|
||||
*q++ = '0';
|
||||
*q++ = 'X' | ncase;
|
||||
}
|
||||
|
||||
while(h_back) {
|
||||
hex_count += (h_back & 0xF) ? 1 : 0;
|
||||
h_back = h_back >> 4;
|
||||
}
|
||||
|
||||
if(shift < (hex_count - 1)*4)
|
||||
shift = (hex_count - 1)*4;
|
||||
|
||||
for(; shift >= 0; shift -= 4)
|
||||
*q++ = tab0123456789ABCDEF[(h >> shift) & 0xF] | ncase;
|
||||
}
|
||||
else if(*fmt == 'd') {
|
||||
int i = *dp++;
|
||||
char *r;
|
||||
int digit_space = 0;
|
||||
|
||||
|
||||
if(i < 0) {
|
||||
*q++ = '-';
|
||||
i = -i;
|
||||
digit_space++;
|
||||
}
|
||||
|
||||
p = q; /* save beginning of digits */
|
||||
|
||||
|
||||
do {
|
||||
*q++ = '0' + (i % 10);
|
||||
i /= 10;
|
||||
digit_space++;
|
||||
} while(i);
|
||||
|
||||
|
||||
for(; shift >= 0; shift -= 4) {
|
||||
|
||||
if(digit_space-- > 0) {
|
||||
; //do nothing
|
||||
} else {
|
||||
*q++ = '0';
|
||||
}
|
||||
}
|
||||
|
||||
/* reverse digits, stop in middle */
|
||||
r = q; /* don't alter q */
|
||||
|
||||
while(--r > p) {
|
||||
i = *r;
|
||||
*r = *p;
|
||||
*p++ = i;
|
||||
}
|
||||
}
|
||||
else if(*fmt == 'c')
|
||||
*q++ = *dp++;
|
||||
else
|
||||
*q++ = *fmt;
|
||||
|
||||
/* now output the saved string */
|
||||
for(p = tmp; p < q; ++p) {
|
||||
*s++ = *p;
|
||||
|
||||
if(s >= buf_end) {
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Exit:
|
||||
|
||||
if(buf)
|
||||
*s = '\0';
|
||||
|
||||
va_end(ap);
|
||||
return(s-buf);
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
static int VSprintfPatch(char *buf, const char *fmt, const int *dp)
|
||||
{
|
||||
char *p, *s;
|
||||
s = buf;
|
||||
|
||||
for(; *fmt != '\0'; ++fmt) {
|
||||
if(*fmt != '%') {
|
||||
if(buf) {
|
||||
*s++ = *fmt;
|
||||
} else {
|
||||
DiagPutChar(*fmt);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(*++fmt == 's') {
|
||||
for(p = (char *)*dp++; *p != '\0'; p++) {
|
||||
if(buf) {
|
||||
*s++ = *p;
|
||||
} else {
|
||||
DiagPutChar(*p);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* Length of item is bounded */
|
||||
char tmp[20], *q = tmp;
|
||||
int alt = 0;
|
||||
int shift = 0;// = 12;
|
||||
const long *lpforchk = (const long *)dp;
|
||||
|
||||
if((*lpforchk) < 0x10) {
|
||||
shift = 0;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x10) && ((*lpforchk) < 0x100)) {
|
||||
shift = 4;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x100) && ((*lpforchk) < 0x1000)) {
|
||||
shift = 8;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x1000) && ((*lpforchk) < 0x10000)) {
|
||||
shift = 12;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x10000) && ((*lpforchk) < 0x100000)) {
|
||||
shift = 16;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x100000) && ((*lpforchk) < 0x1000000)) {
|
||||
shift = 20;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x1000000) && ((*lpforchk) < 0x10000000)) {
|
||||
shift = 24;
|
||||
}
|
||||
else if((*lpforchk) >= 0x10000000) {
|
||||
shift = 28;
|
||||
}
|
||||
else {
|
||||
shift = 28;
|
||||
}
|
||||
|
||||
#if 1 //wei patch for %02x
|
||||
|
||||
if((*fmt >= '0') && (*fmt <= '9'))
|
||||
{
|
||||
int width;
|
||||
unsigned char fch = *fmt;
|
||||
|
||||
for(width=0; (fch>='0') && (fch<='9'); fch=*++fmt)
|
||||
{ width = width * 10 + fch - '0';
|
||||
}
|
||||
|
||||
shift=(width-1)*4;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Before each format q points to tmp buffer
|
||||
* After each format q points past end of item
|
||||
*/
|
||||
|
||||
if((*fmt == 'x')||(*fmt == 'X') || (*fmt == 'p') || (*fmt == 'P')) {
|
||||
/* With x86 gcc, sizeof(long) == sizeof(int) */
|
||||
const long *lp = (const long *)dp;
|
||||
long h = *lp++;
|
||||
int hex_count = 0;
|
||||
unsigned long h_back = h;
|
||||
int ncase = (*fmt & 0x20);
|
||||
dp = (const int *)lp;
|
||||
|
||||
if((*fmt == 'p') || (*fmt == 'P'))
|
||||
alt=1;
|
||||
|
||||
if(alt) {
|
||||
*q++ = '0';
|
||||
*q++ = 'X' | ncase;
|
||||
}
|
||||
|
||||
//hback 是实际得到的数据,hex_count是统计数据的HEX字符个数
|
||||
while(h_back) {
|
||||
hex_count += (h_back & 0xF) ? 1 : 0;
|
||||
h_back = h_back >> 4;
|
||||
}
|
||||
|
||||
//这里修复 example: 字符有4个,但是用了%02x导致字符被截断的情况
|
||||
if(shift < (hex_count - 1)*4)
|
||||
shift = (hex_count - 1)*4;
|
||||
|
||||
//printf("(%d,%d)", hex_count, shift);
|
||||
|
||||
for(; shift >= 0; shift -= 4) {
|
||||
|
||||
*q++ = tab0123456789ABCDEF[(h >> shift) & 0xF] | ncase;
|
||||
}
|
||||
|
||||
}
|
||||
else if(*fmt == 'd') {
|
||||
int i = *dp++;
|
||||
char *r;
|
||||
int digit_space = 0;
|
||||
|
||||
if(i < 0) {
|
||||
*q++ = '-';
|
||||
i = -i;
|
||||
digit_space++;
|
||||
}
|
||||
|
||||
p = q; /* save beginning of digits */
|
||||
|
||||
do {
|
||||
*q++ = '0' + (i % 10);
|
||||
i /= 10;
|
||||
digit_space++;
|
||||
} while(i);
|
||||
|
||||
//这里修复 example:用了%08d后,在数字前面没有0的情况
|
||||
for(; shift >= 0; shift -= 4) {
|
||||
|
||||
if(digit_space-- > 0) {
|
||||
; //do nothing
|
||||
} else {
|
||||
*q++ = '0';
|
||||
}
|
||||
}
|
||||
|
||||
/* reverse digits, stop in middle */
|
||||
r = q; /* don't alter q */
|
||||
|
||||
while(--r > p) {
|
||||
i = *r;
|
||||
*r = *p;
|
||||
*p++ = i;
|
||||
}
|
||||
}
|
||||
else if(*fmt == 'c')
|
||||
*q++ = *dp++;
|
||||
else
|
||||
*q++ = *fmt;
|
||||
|
||||
/* now output the saved string */
|
||||
for(p = tmp; p < q; ++p) {
|
||||
if(buf) {
|
||||
*s++ = *p;
|
||||
} else {
|
||||
DiagPutChar(*p);
|
||||
}
|
||||
|
||||
if((*p) == '\n') {
|
||||
DiagPutChar('\r');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(buf)
|
||||
*s = '\0';
|
||||
|
||||
return (s - buf);
|
||||
}
|
||||
|
||||
|
||||
int DiagPrintfPatch(
|
||||
IN const char *fmt, ...
|
||||
)
|
||||
{
|
||||
return VSprintfPatch(0, fmt, ((const int *)&fmt)+1);
|
||||
}
|
||||
|
||||
int DiagSPrintfPatch(
|
||||
IN u8 *buf,
|
||||
IN const char *fmt, ...
|
||||
)
|
||||
{
|
||||
return VSprintfPatch((char*)buf, fmt, ((const int *)&fmt)+1);
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue