mirror of
https://github.com/sengeiou/realtek_ameba_mp_sdk.git
synced 2026-07-14 07:25:40 +00:00
ameba micropython sdk first commit
This commit is contained in:
commit
8508ee6139
5619 changed files with 1874619 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#ifndef _RTL_LIB_ROM_H_
|
||||
#define _RTL_LIB_ROM_H_
|
||||
|
||||
#include "memproc.h"
|
||||
#include "strproc.h"
|
||||
#include "diag.h"
|
||||
|
||||
#endif /* _RTL_LIB_ROM_H_ */
|
||||
8
sdk/component/soc/realtek/amebad/swlib/include/rtl_lib.h
Normal file
8
sdk/component/soc/realtek/amebad/swlib/include/rtl_lib.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _RTL_LIB_H_
|
||||
#define _RTL_LIB_H_
|
||||
|
||||
#include "memproc.h"
|
||||
#include "strproc.h"
|
||||
#include "diag.h"
|
||||
|
||||
#endif /* _RTL_LIB_H_ */
|
||||
43
sdk/component/soc/realtek/amebad/swlib/string/Makefile
Normal file
43
sdk/component/soc/realtek/amebad/swlib/string/Makefile
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
include $(MAKE_INCLUDE_GEN)
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
MODULE_IFLAGS = -I./include
|
||||
|
||||
|
||||
#*****************************************************************************#
|
||||
# Object FILE LIST #
|
||||
#*****************************************************************************#
|
||||
#OBJS = diag.o memset.o strproc.o rand.o memcpy.o memcmp.o rtl_utility.o
|
||||
|
||||
OBJS =
|
||||
|
||||
INFRA_ROM_OBJS = diag.o memset.o strproc.o rand.o memcpy.o memcmp.o
|
||||
|
||||
OBJS = $(INFRA_ROM_OBJS)
|
||||
|
||||
#*****************************************************************************#
|
||||
# RULES TO GENERATE TARGETS #
|
||||
#*****************************************************************************#
|
||||
|
||||
# Define the Rules to build the core targets
|
||||
all: CORE_TARGETS RENAME_ROM_OBJS COPY_ROM_OBJS
|
||||
|
||||
#*****************************************************************************#
|
||||
# GENERATE OBJECT FILE
|
||||
#*****************************************************************************#
|
||||
CORE_TARGETS: $(OBJS)
|
||||
|
||||
|
||||
|
||||
#*****************************************************************************#
|
||||
# RULES TO CLEAN TARGETS #
|
||||
#*****************************************************************************#
|
||||
clean:
|
||||
$(REMOVE) *.o
|
||||
$(REMOVE) *.i
|
||||
$(REMOVE) *.s
|
||||
$(REMOVE) *.d
|
||||
|
||||
-include $(DEPS)
|
||||
183
sdk/component/soc/realtek/amebad/swlib/string/diag.h
Normal file
183
sdk/component/soc/realtek/amebad/swlib/string/diag.h
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
* 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 _DIAG_H_
|
||||
#define _DIAG_H_
|
||||
|
||||
#include "platform_autoconf.h"
|
||||
#include "basic_types.h"
|
||||
#include "rtl_trace.h"
|
||||
|
||||
u32 DiagPrintf(const char *fmt, ...);
|
||||
u32 DiagPrintfD(const char *fmt, ...);
|
||||
int DiagVSprintf(char *buf, const char *fmt, const int *dp);
|
||||
|
||||
//arduino
|
||||
#define _DbgDump DiagPrintf
|
||||
|
||||
/** @addtogroup Ameba_Platform
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Platform_Debug Debug
|
||||
* @brief Platform_Debug modules
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Platform_Debug_Log_Trace_Exported_Types Log Trace Types
|
||||
* @{
|
||||
*/
|
||||
/** @brief Log Module Definition */
|
||||
typedef enum {
|
||||
MODULE_OS = 0, /**< FreeRTOS */
|
||||
MODULE_BOOT = 1, /**< bootloader */
|
||||
MODULE_GDMA = 2, /**< gdma */
|
||||
MODULE_GPIO = 3, /**< gpio */
|
||||
MODULE_TIMER = 4, /**< timer */
|
||||
MODULE_I2C = 5, /**< i2c */
|
||||
MODULE_I2S = 6, /**< i2s */
|
||||
MODULE_PWM = 7, /**< pwm */
|
||||
MODULE_SDIO = 8, /**< sdio */
|
||||
MODULE_SPI = 9, /**< spi */
|
||||
MODULE_FLASH = 10, /**< flash */
|
||||
MODULE_UART = 11, /**< uart */
|
||||
MODULE_USB_OTG = 12, /**< usb otg */
|
||||
MODULE_IPSEC = 13, /**< ipsec */
|
||||
MODULE_ADC = 14, /**< adc */
|
||||
MODULE_EFUSE = 15, /**< efuse */
|
||||
MODULE_MONIT = 16, /**< monitor */
|
||||
MODULE_MISC = 17, /**< misc */
|
||||
MODULE_IR = 18,
|
||||
MODULE_QDECODE = 19,
|
||||
MODULE_KEYSCAN = 20,
|
||||
MODULE_SGPIO = 21,
|
||||
MODULE_AUDIO = 22,
|
||||
MODULE_LCD = 23,
|
||||
MODULE_WIFIFW = 24,
|
||||
MODULE_BT = 25,
|
||||
MODULE_IPC = 26,
|
||||
MODULE_KM4 = 27,
|
||||
|
||||
MODULE_NUMs = 32 /**< Module Number */
|
||||
} MODULE_DEFINE;
|
||||
|
||||
/** @brief Log Level Definition */
|
||||
typedef enum {
|
||||
LEVEL_ERROR = 0, /**< Error */
|
||||
LEVEL_WARN = 1, /**< Warning */
|
||||
LEVEL_INFO = 2, /**< Information */
|
||||
LEVEL_TRACE = 3, /**< Trace Data */
|
||||
LEVEL_NUMs = 4 /**< Level Number */
|
||||
} LEVEL_DEFINE;
|
||||
/** End of Platform_Debug_Log_Trace_Exported_Types
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup Platform_Debug_Log_Trace_Functions_And_Macro Function & Macro
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @cond private */
|
||||
/** @brief Debug Log mask */
|
||||
extern u32 ConfigDebug[];
|
||||
/** @endcond */
|
||||
|
||||
/**
|
||||
* @brief Debug Log Mask Set.
|
||||
* @param config[4] -- Print log if bit MODULE_DEFINE of config[LEVEL_DEFINE] is 1;
|
||||
* @return void.
|
||||
* @note Here is a MODULE_BOOT module sample to demostrate the using of LOG_MASK().
|
||||
* We want to print log under ERROR level and INFO level.
|
||||
* @code{.c}
|
||||
* u32 debug[4];
|
||||
* debug[LEVEL_ERROR] = BIT(MODULE_BOOT);
|
||||
* debug[LEVEL_WARN] = 0x0;
|
||||
* debug[LEVEL_INFO] = BIT(MODULE_BOOT);
|
||||
* debug[LEVEL_TRACE] = 0x0;
|
||||
*
|
||||
* LOG_MASK(LEVEL_ERROR, debug[LEVEL_ERROR]);
|
||||
* LOG_MASK(LEVEL_WARN, debug[LEVEL_WARN]);
|
||||
* LOG_MASK(LEVEL_INFO, debug[LEVEL_INFO]);
|
||||
* LOG_MASK(LEVEL_TRACE, debug[LEVEL_TRACE]);
|
||||
*
|
||||
* DBG_PRINTF(MODULE_BOOT, LEVEL_INFO, "MODULE_BOOT Info.\n");
|
||||
* DBG_PRINTF(MODULE_BOOT, LEVEL_ERROR, "MODULE_BOOT Error!\n");
|
||||
* @endcode
|
||||
*/
|
||||
#define LOG_MASK(level, config) do {\
|
||||
ConfigDebug[level] = config;\
|
||||
} while (0)
|
||||
|
||||
#define LOG_MASK_MODULE(module, level, new_status) do {\
|
||||
if (new_status == ENABLE) { \
|
||||
ConfigDebug[level] |= BIT(module); \
|
||||
} else { \
|
||||
ConfigDebug[level] &= ~BIT(module); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @brief DBG_PRINTF is used to print log
|
||||
*/
|
||||
//#define RELEASE_VERSION
|
||||
#ifdef RELEASE_VERSION
|
||||
#define DBG_PRINTF(MODULE, LEVEL, pFormat, ...) do {\
|
||||
if ((LEVEL < LEVEL_NUMs) && (MODULE < MODULE_NUMs) && (ConfigDebug[LEVEL] & BIT(MODULE))) {\
|
||||
}\
|
||||
}while(0)
|
||||
#else
|
||||
#define DBG_PRINTF(MODULE, LEVEL, pFormat, ...) do {\
|
||||
if ((LEVEL < LEVEL_NUMs) && (MODULE < MODULE_NUMs) && (ConfigDebug[LEVEL] & BIT(MODULE)))\
|
||||
DiagPrintf("["#MODULE"-"#LEVEL"]:"pFormat, ##__VA_ARGS__);\
|
||||
}while(0)
|
||||
#endif
|
||||
|
||||
#define DBG_ERR_MSG_ON(x) (ConfigDebug[LEVEL_ERROR] |= BIT(x))
|
||||
#define DBG_WARN_MSG_ON(x) (ConfigDebug[LEVEL_WARN] |= BIT(x))
|
||||
#define DBG_INFO_MSG_ON(x) (ConfigDebug[LEVEL_INFO] |= BIT(x))
|
||||
|
||||
#define DBG_ERR_MSG_OFF(x) (ConfigDebug[LEVEL_ERROR] &= ~BIT(x))
|
||||
#define DBG_WARN_MSG_OFF(x) (ConfigDebug[LEVEL_WARN] &= ~BIT(x))
|
||||
#define DBG_INFO_MSG_OFF(x) (ConfigDebug[LEVEL_INFO] &= ~BIT(x))
|
||||
#define DRIVER_PREFIX "RTL8721D[Driver]: "
|
||||
|
||||
#ifdef CONFIG_DEBUG_LOG
|
||||
#define DBG_8195A(...) do {\
|
||||
if (unlikely(ConfigDebug[LEVEL_ERROR] & BIT(MODULE_MISC))) \
|
||||
DiagPrintf("\r" __VA_ARGS__);\
|
||||
}while(0)
|
||||
|
||||
#define MONITOR_LOG(...) do {\
|
||||
if (unlikely(ConfigDebug[LEVEL_ERROR] & BIT(MODULE_MONIT))) \
|
||||
DiagPrintf( __VA_ARGS__);\
|
||||
}while(0)
|
||||
|
||||
#else // else of "#if CONFIG_DEBUG_LOG"
|
||||
#define DBG_8195A(...)
|
||||
#define MONITOR_LOG(...)
|
||||
#endif
|
||||
|
||||
/** End of Platform_Debug_Log_Trace_Functions_And_Macro
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** End of Platform_Debug
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** End of AmebaZ_Platform
|
||||
* @}
|
||||
*/
|
||||
|
||||
extern u32 ConfigDebugBuffer;
|
||||
extern u32 ConfigDebugClose;
|
||||
extern u32 ConfigDebug[];
|
||||
|
||||
|
||||
#endif //_DIAG_H_
|
||||
24
sdk/component/soc/realtek/amebad/swlib/string/local.h
Normal file
24
sdk/component/soc/realtek/amebad/swlib/string/local.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include <_ansi.h>
|
||||
//#include <../libc/rom/ctype/local.h>
|
||||
|
||||
/* internal function to compute width of wide char. */
|
||||
int _EXFUN (__wcwidth, (wint_t));
|
||||
|
||||
/* Defined in locale/locale.c. Returns a value != 0 if the current
|
||||
language is assumed to use CJK fonts. */
|
||||
int __locale_cjk_lang (void);
|
||||
|
||||
/*
|
||||
Taken from glibc:
|
||||
Add the compiler optimization to inhibit loop transformation to library
|
||||
calls. This is used to avoid recursive calls in memset and memmove
|
||||
default implementations.
|
||||
*/
|
||||
#ifdef _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
|
||||
# define __inhibit_loop_to_libcall \
|
||||
__attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
|
||||
#else
|
||||
# define __inhibit_loop_to_libcall
|
||||
#endif
|
||||
|
||||
|
||||
26
sdk/component/soc/realtek/amebad/swlib/string/memproc.h
Normal file
26
sdk/component/soc/realtek/amebad/swlib/string/memproc.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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 _MEM_PROC_H_
|
||||
#define _MEM_PROC_H_
|
||||
|
||||
#include <basic_types.h>
|
||||
|
||||
/* change name from hal_misc.h */
|
||||
extern _LONG_CALL_ void *_memset( void *s, int c, SIZE_T n );
|
||||
extern _LONG_CALL_ void *_memcpy( void *s1, const void *s2, SIZE_T n );
|
||||
extern _LONG_CALL_ int _memcmp( const void *av, const void *bv, SIZE_T len );
|
||||
extern _LONG_CALL_ void * _memchr(const void * src_void , int c , size_t length);
|
||||
extern _LONG_CALL_ void * _memmove( void * dst_void , const void * src_void , size_t length);
|
||||
|
||||
void memcpy_gdma_init(void);
|
||||
int memcpy_gdma(void *dest, void *src, u32 size);
|
||||
|
||||
|
||||
#endif //_MEM_PROC_H_
|
||||
33
sdk/component/soc/realtek/amebad/swlib/string/printf.h
Normal file
33
sdk/component/soc/realtek/amebad/swlib/string/printf.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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 _RTL_PRINTF_H_
|
||||
#define _RTL_PRINTF_H_
|
||||
|
||||
#define LONGFLAG 0x00000001
|
||||
#define LONGLONGFLAG 0x00000002
|
||||
#define HALFFLAG 0x00000004
|
||||
#define HALFHALFFLAG 0x00000008
|
||||
#define SIZETFLAG 0x00000010
|
||||
#define INTMAXFLAG 0x00000020
|
||||
#define PTRDIFFFLAG 0x00000040
|
||||
#define ALTFLAG 0x00000080
|
||||
#define CAPSFLAG 0x00000100
|
||||
#define SHOWSIGNFLAG 0x00000200
|
||||
#define SIGNEDFLAG 0x00000400
|
||||
#define LEFTFORMATFLAG 0x00000800
|
||||
#define LEADZEROFLAG 0x00001000
|
||||
#define BLANKPOSFLAG 0x00002000
|
||||
|
||||
|
||||
unsigned int printf_engine(const char *fmt, va_list args);
|
||||
int _rtl_printf(const char * fmt,...);
|
||||
|
||||
|
||||
#endif
|
||||
18
sdk/component/soc/realtek/amebad/swlib/string/rand.h
Normal file
18
sdk/component/soc/realtek/amebad/swlib/string/rand.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
extern u32 rand_seed[4]; //z1, z2, z3, z4,
|
||||
extern u32 rand_first;
|
||||
|
||||
u32
|
||||
Rand (
|
||||
VOID
|
||||
);
|
||||
|
||||
|
||||
10
sdk/component/soc/realtek/amebad/swlib/string/rom_lib.mk
Normal file
10
sdk/component/soc/realtek/amebad/swlib/string/rom_lib.mk
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
#*****************************************************************************#
|
||||
# ROM Object FILE LIST #
|
||||
#*****************************************************************************#
|
||||
SYS_ROM_OBJS = diag.o \
|
||||
memcmp.o \
|
||||
memcpy.o \
|
||||
memset.o \
|
||||
rand.o \
|
||||
strproc.o
|
||||
424
sdk/component/soc/realtek/amebad/swlib/string/str-two-way.h
Normal file
424
sdk/component/soc/realtek/amebad/swlib/string/str-two-way.h
Normal file
|
|
@ -0,0 +1,424 @@
|
|||
/* Byte-wise substring search, using the Two-Way algorithm.
|
||||
* Copyright (C) 2008, 2010 Eric Blake
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* is freely granted, provided that this notice is preserved.
|
||||
*/
|
||||
|
||||
|
||||
/* Before including this file, you need to include <string.h>, and define:
|
||||
RESULT_TYPE A macro that expands to the return type.
|
||||
AVAILABLE(h, h_l, j, n_l) A macro that returns nonzero if there are
|
||||
at least N_L bytes left starting at
|
||||
H[J]. H is 'unsigned char *', H_L, J,
|
||||
and N_L are 'size_t'; H_L is an
|
||||
lvalue. For NUL-terminated searches,
|
||||
H_L can be modified each iteration to
|
||||
avoid having to compute the end of H
|
||||
up front.
|
||||
|
||||
For case-insensitivity, you may optionally define:
|
||||
CMP_FUNC(p1, p2, l) A macro that returns 0 iff the first L
|
||||
characters of P1 and P2 are equal.
|
||||
CANON_ELEMENT(c) A macro that canonicalizes an element
|
||||
right after it has been fetched from
|
||||
one of the two strings. The argument
|
||||
is an 'unsigned char'; the result must
|
||||
be an 'unsigned char' as well.
|
||||
|
||||
This file undefines the macros documented above, and defines
|
||||
LONG_NEEDLE_THRESHOLD.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern void * _memchr(const void * src_void , int c , size_t length);
|
||||
extern int _memcmp(const void * m1 , const void * m2 , size_t n);
|
||||
|
||||
/* We use the Two-Way string matching algorithm, which guarantees
|
||||
linear complexity with constant space. Additionally, for long
|
||||
needles, we also use a bad character shift table similar to the
|
||||
Boyer-Moore algorithm to achieve improved (potentially sub-linear)
|
||||
performance.
|
||||
|
||||
See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260
|
||||
and http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm
|
||||
*/
|
||||
|
||||
/* Point at which computing a bad-byte shift table is likely to be
|
||||
worthwhile. Small needles should not compute a table, since it
|
||||
adds (1 << CHAR_BIT) + NEEDLE_LEN computations of preparation for a
|
||||
speedup no greater than a factor of NEEDLE_LEN. The larger the
|
||||
needle, the better the potential performance gain. On the other
|
||||
hand, on non-POSIX systems with CHAR_BIT larger than eight, the
|
||||
memory required for the table is prohibitive. */
|
||||
#if CHAR_BIT < 10
|
||||
# define LONG_NEEDLE_THRESHOLD 32U
|
||||
#else
|
||||
# define LONG_NEEDLE_THRESHOLD SIZE_MAX
|
||||
#endif
|
||||
|
||||
#define MAX(a, b) ((a < b) ? (b) : (a))
|
||||
|
||||
#ifndef CANON_ELEMENT
|
||||
# define CANON_ELEMENT(c) c
|
||||
#endif
|
||||
#ifndef CMP_FUNC
|
||||
# define CMP_FUNC _memcmp
|
||||
#endif
|
||||
|
||||
/* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
|
||||
Return the index of the first byte in the right half, and set
|
||||
*PERIOD to the global period of the right half.
|
||||
|
||||
The global period of a string is the smallest index (possibly its
|
||||
length) at which all remaining bytes in the string are repetitions
|
||||
of the prefix (the last repetition may be a subset of the prefix).
|
||||
|
||||
When NEEDLE is factored into two halves, a local period is the
|
||||
length of the smallest word that shares a suffix with the left half
|
||||
and shares a prefix with the right half. All factorizations of a
|
||||
non-empty NEEDLE have a local period of at least 1 and no greater
|
||||
than NEEDLE_LEN.
|
||||
|
||||
A critical factorization has the property that the local period
|
||||
equals the global period. All strings have at least one critical
|
||||
factorization with the left half smaller than the global period.
|
||||
|
||||
Given an ordered alphabet, a critical factorization can be computed
|
||||
in linear time, with 2 * NEEDLE_LEN comparisons, by computing the
|
||||
larger of two ordered maximal suffixes. The ordered maximal
|
||||
suffixes are determined by lexicographic comparison of
|
||||
periodicity. */
|
||||
LIBC_ROM_TEXT_SECTION
|
||||
_LONG_CALL_
|
||||
static size_t
|
||||
__rtl_critical_factorization (const unsigned char *needle, size_t needle_len,
|
||||
size_t *period)
|
||||
{
|
||||
/* Index of last byte of left half, or SIZE_MAX. */
|
||||
size_t max_suffix, max_suffix_rev;
|
||||
size_t j; /* Index into NEEDLE for current candidate suffix. */
|
||||
size_t k; /* Offset into current period. */
|
||||
size_t p; /* Intermediate period. */
|
||||
unsigned char a, b; /* Current comparison bytes. */
|
||||
|
||||
/* Invariants:
|
||||
0 <= j < NEEDLE_LEN - 1
|
||||
-1 <= max_suffix{,_rev} < j (treating SIZE_MAX as if it were signed)
|
||||
min(max_suffix, max_suffix_rev) < global period of NEEDLE
|
||||
1 <= p <= global period of NEEDLE
|
||||
p == global period of the substring NEEDLE[max_suffix{,_rev}+1...j]
|
||||
1 <= k <= p
|
||||
*/
|
||||
|
||||
/* Perform lexicographic search. */
|
||||
max_suffix = SIZE_MAX;
|
||||
j = 0;
|
||||
k = p = 1;
|
||||
while (j + k < needle_len)
|
||||
{
|
||||
a = CANON_ELEMENT (needle[j + k]);
|
||||
b = CANON_ELEMENT (needle[(size_t)(max_suffix + k)]);
|
||||
if (a < b)
|
||||
{
|
||||
/* Suffix is smaller, period is entire prefix so far. */
|
||||
j += k;
|
||||
k = 1;
|
||||
p = j - max_suffix;
|
||||
}
|
||||
else if (a == b)
|
||||
{
|
||||
/* Advance through repetition of the current period. */
|
||||
if (k != p)
|
||||
++k;
|
||||
else
|
||||
{
|
||||
j += p;
|
||||
k = 1;
|
||||
}
|
||||
}
|
||||
else /* b < a */
|
||||
{
|
||||
/* Suffix is larger, start over from current location. */
|
||||
max_suffix = j++;
|
||||
k = p = 1;
|
||||
}
|
||||
}
|
||||
*period = p;
|
||||
|
||||
/* Perform reverse lexicographic search. */
|
||||
max_suffix_rev = SIZE_MAX;
|
||||
j = 0;
|
||||
k = p = 1;
|
||||
while (j + k < needle_len)
|
||||
{
|
||||
a = CANON_ELEMENT (needle[j + k]);
|
||||
b = CANON_ELEMENT (needle[max_suffix_rev + k]);
|
||||
if (b < a)
|
||||
{
|
||||
/* Suffix is smaller, period is entire prefix so far. */
|
||||
j += k;
|
||||
k = 1;
|
||||
p = j - max_suffix_rev;
|
||||
}
|
||||
else if (a == b)
|
||||
{
|
||||
/* Advance through repetition of the current period. */
|
||||
if (k != p)
|
||||
++k;
|
||||
else
|
||||
{
|
||||
j += p;
|
||||
k = 1;
|
||||
}
|
||||
}
|
||||
else /* a < b */
|
||||
{
|
||||
/* Suffix is larger, start over from current location. */
|
||||
max_suffix_rev = j++;
|
||||
k = p = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Choose the longer suffix. Return the first byte of the right
|
||||
half, rather than the last byte of the left half. */
|
||||
if (max_suffix_rev + 1 < max_suffix + 1)
|
||||
return max_suffix + 1;
|
||||
*period = p;
|
||||
return max_suffix_rev + 1;
|
||||
}
|
||||
|
||||
/* Return the first location of non-empty NEEDLE within HAYSTACK, or
|
||||
NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
|
||||
method is optimized for NEEDLE_LEN < LONG_NEEDLE_THRESHOLD.
|
||||
Performance is guaranteed to be linear, with an initialization cost
|
||||
of 2 * NEEDLE_LEN comparisons.
|
||||
|
||||
If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
|
||||
most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching.
|
||||
If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
|
||||
HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. */
|
||||
LIBC_ROM_TEXT_SECTION
|
||||
_LONG_CALL_
|
||||
static RETURN_TYPE
|
||||
__rtl_two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
|
||||
const unsigned char *needle, size_t needle_len)
|
||||
{
|
||||
size_t i; /* Index into current byte of NEEDLE. */
|
||||
size_t j; /* Index into current window of HAYSTACK. */
|
||||
size_t period; /* The period of the right half of needle. */
|
||||
size_t suffix; /* The index of the right half of needle. */
|
||||
|
||||
/* Factor the needle into two halves, such that the left half is
|
||||
smaller than the global period, and the right half is
|
||||
periodic (with a period as large as NEEDLE_LEN - suffix). */
|
||||
suffix = __rtl_critical_factorization (needle, needle_len, &period);
|
||||
|
||||
/* Perform the search. Each iteration compares the right half
|
||||
first. */
|
||||
if (CMP_FUNC (needle, needle + period, suffix) == 0)
|
||||
{
|
||||
/* Entire needle is periodic; a mismatch can only advance by the
|
||||
period, so use memory to avoid rescanning known occurrences
|
||||
of the period. */
|
||||
size_t memory = 0;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Scan for matches in right half. */
|
||||
i = MAX (suffix, memory);
|
||||
while (i < needle_len && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (memory < i + 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i + 1 < memory + 1)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
/* No match, so remember how many repetitions of period
|
||||
on the right half were scanned. */
|
||||
j += period;
|
||||
memory = needle_len - period;
|
||||
}
|
||||
else
|
||||
{
|
||||
j += i - suffix + 1;
|
||||
memory = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The two halves of needle are distinct; no extra memory is
|
||||
required, and any mismatch results in a maximal shift. */
|
||||
period = MAX (suffix, needle_len - suffix) + 1;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Scan for matches in right half. */
|
||||
i = suffix;
|
||||
while (i < needle_len && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i == SIZE_MAX)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
j += period;
|
||||
}
|
||||
else
|
||||
j += i - suffix + 1;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Return the first location of non-empty NEEDLE within HAYSTACK, or
|
||||
NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
|
||||
method is optimized for LONG_NEEDLE_THRESHOLD <= NEEDLE_LEN.
|
||||
Performance is guaranteed to be linear, with an initialization cost
|
||||
of 3 * NEEDLE_LEN + (1 << CHAR_BIT) operations.
|
||||
|
||||
If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
|
||||
most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching,
|
||||
and sublinear performance O(HAYSTACK_LEN / NEEDLE_LEN) is possible.
|
||||
If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
|
||||
HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching, and
|
||||
sublinear performance is not possible. */
|
||||
LIBC_ROM_TEXT_SECTION
|
||||
_LONG_CALL_
|
||||
static RETURN_TYPE
|
||||
__rtl_two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
|
||||
const unsigned char *needle, size_t needle_len)
|
||||
{
|
||||
size_t i; /* Index into current byte of NEEDLE. */
|
||||
size_t j; /* Index into current window of HAYSTACK. */
|
||||
size_t period; /* The period of the right half of needle. */
|
||||
size_t suffix; /* The index of the right half of needle. */
|
||||
size_t shift_table[1U << CHAR_BIT]; /* See below. */
|
||||
|
||||
/* Factor the needle into two halves, such that the left half is
|
||||
smaller than the global period, and the right half is
|
||||
periodic (with a period as large as NEEDLE_LEN - suffix). */
|
||||
suffix = __rtl_critical_factorization (needle, needle_len, &period);
|
||||
|
||||
/* Populate shift_table. For each possible byte value c,
|
||||
shift_table[c] is the distance from the last occurrence of c to
|
||||
the end of NEEDLE, or NEEDLE_LEN if c is absent from the NEEDLE.
|
||||
shift_table[NEEDLE[NEEDLE_LEN - 1]] contains the only 0. */
|
||||
for (i = 0; i < 1U << CHAR_BIT; i++)
|
||||
shift_table[i] = needle_len;
|
||||
for (i = 0; i < needle_len; i++)
|
||||
shift_table[CANON_ELEMENT (needle[i])] = needle_len - i - 1;
|
||||
|
||||
/* Perform the search. Each iteration compares the right half
|
||||
first. */
|
||||
if (CMP_FUNC (needle, needle + period, suffix) == 0)
|
||||
{
|
||||
/* Entire needle is periodic; a mismatch can only advance by the
|
||||
period, so use memory to avoid rescanning known occurrences
|
||||
of the period. */
|
||||
size_t memory = 0;
|
||||
size_t shift;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Check the last byte first; if it does not match, then
|
||||
shift to the next possible match location. */
|
||||
shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
|
||||
if (0 < shift)
|
||||
{
|
||||
if (memory && shift < period)
|
||||
{
|
||||
/* Since needle is periodic, but the last period has
|
||||
a byte out of place, there can be no match until
|
||||
after the mismatch. */
|
||||
shift = needle_len - period;
|
||||
}
|
||||
memory = 0;
|
||||
j += shift;
|
||||
continue;
|
||||
}
|
||||
/* Scan for matches in right half. The last byte has
|
||||
already been matched, by virtue of the shift table. */
|
||||
i = MAX (suffix, memory);
|
||||
while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len - 1 <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (memory < i + 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i + 1 < memory + 1)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
/* No match, so remember how many repetitions of period
|
||||
on the right half were scanned. */
|
||||
j += period;
|
||||
memory = needle_len - period;
|
||||
}
|
||||
else
|
||||
{
|
||||
j += i - suffix + 1;
|
||||
memory = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The two halves of needle are distinct; no extra memory is
|
||||
required, and any mismatch results in a maximal shift. */
|
||||
size_t shift;
|
||||
period = MAX (suffix, needle_len - suffix) + 1;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Check the last byte first; if it does not match, then
|
||||
shift to the next possible match location. */
|
||||
shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
|
||||
if (0 < shift)
|
||||
{
|
||||
j += shift;
|
||||
continue;
|
||||
}
|
||||
/* Scan for matches in right half. The last byte has
|
||||
already been matched, by virtue of the shift table. */
|
||||
i = suffix;
|
||||
while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len - 1 <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i == SIZE_MAX)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
j += period;
|
||||
}
|
||||
else
|
||||
j += i - suffix + 1;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#undef AVAILABLE
|
||||
#undef CANON_ELEMENT
|
||||
#undef CMP_FUNC
|
||||
#undef MAX
|
||||
#undef RETURN_TYPE
|
||||
80
sdk/component/soc/realtek/amebad/swlib/string/strproc.h
Normal file
80
sdk/component/soc/realtek/amebad/swlib/string/strproc.h
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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 _STRPROC_H_
|
||||
#define _STRPROC_H_
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
#include <stdarg.h>
|
||||
#include "platform_autoconf.h"
|
||||
#include "basic_types.h"
|
||||
|
||||
#ifndef isprint
|
||||
#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 isupper(c) (((c)>='A')&&((c)<='Z'))
|
||||
#define islower(c) (((c)>='a')&&((c)<='z'))
|
||||
#define isalpha(c) (isupper(c) || islower(c))
|
||||
#endif
|
||||
|
||||
|
||||
extern _LONG_CALL_ int _vsscanf(const char *buf, const char *fmt, va_list args);
|
||||
|
||||
|
||||
extern _LONG_CALL_ SIZE_T _strlen(const char *s);
|
||||
extern _LONG_CALL_ int _strcmp(const char *cs, const char *ct);
|
||||
extern _LONG_CALL_ char *_strncpy(char *dest, const char *src, size_t count);
|
||||
extern _LONG_CALL_ char *_strcpy(char *dest, const char *src);
|
||||
extern _LONG_CALL_ size_t _strlen(const char *s);
|
||||
extern _LONG_CALL_ size_t _strnlen(const char *s, size_t count);
|
||||
extern _LONG_CALL_ int _strncmp(const char *cs, const char *ct, size_t count);
|
||||
extern _LONG_CALL_ int _sscanf(const char *buf, const char *fmt, ...);
|
||||
extern _LONG_CALL_ char *_strsep(char **s, const char *ct);
|
||||
extern _LONG_CALL_ char * _strcat(char *__restrict s1 , const char *__restrict s2);
|
||||
|
||||
extern _LONG_CALL_ char *_strpbrk(const char *cs, const char *ct);
|
||||
extern _LONG_CALL_ char *_strchr(const char *s, int c);
|
||||
extern _LONG_CALL_ int _stricmp(const char* str1, const char* str2);
|
||||
extern _LONG_CALL_ u8* _strupr(IN u8 *string);
|
||||
extern _LONG_CALL_ int _stratoi(IN const char * s);
|
||||
extern _LONG_CALL_ char * _strstr(IN const char * str1, IN const char * str2);
|
||||
extern _LONG_CALL_ char* _strtok(IN char *str, IN const char* delim);
|
||||
|
||||
extern _LONG_CALL_ long _strtol(const char *cp, char **endp, int base);
|
||||
extern _LONG_CALL_ unsigned long _strtoul(const char *cp, char **endp, int base);
|
||||
extern _LONG_CALL_ long long _strtoll(const char *cp, char **endp, unsigned int base);
|
||||
extern _LONG_CALL_ unsigned long long _strtoull(const char *cp, char **endp, unsigned int base);
|
||||
|
||||
extern _LONG_CALL_ u8 _char2num(u8 ch);
|
||||
extern _LONG_CALL_ u8 _2char2dec(u8 hch, u8 lch);
|
||||
extern _LONG_CALL_ u8 _2char2hex(u8 hch, u8 lch);
|
||||
|
||||
/*
|
||||
* Fast implementation of tolower() for internal usage. Do not use in your
|
||||
* code.
|
||||
*/
|
||||
#ifndef _tolower
|
||||
static inline char _tolower(const char c)
|
||||
{
|
||||
return (c | 0x20);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Fast check for octal digit */
|
||||
static inline int isodigit(const char c)
|
||||
{
|
||||
return (c >= '0' && c <= '7');
|
||||
}
|
||||
|
||||
#endif
|
||||
37
sdk/component/soc/realtek/amebad/swlib/string/va_list.h
Normal file
37
sdk/component/soc/realtek/amebad/swlib/string/va_list.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 _VA_LIST_H_
|
||||
#define _VA_LIST_H_
|
||||
|
||||
#include "platform_autoconf.h"
|
||||
#include "basic_types.h"
|
||||
|
||||
#ifndef va_arg //this part is adapted from linux (Linux/include/acpi/platform/acenv.h)
|
||||
|
||||
typedef s32 acpi_native_int;//this definition is in (Linux/include/acpi/actypes.h)
|
||||
|
||||
#ifndef _VALIST
|
||||
#define _VALIST
|
||||
typedef char *va_list;
|
||||
#endif /* _VALIST */
|
||||
|
||||
/* Storage alignment properties */
|
||||
#define _AUPBND (sizeof (acpi_native_int) - 1)
|
||||
#define _ADNBND (sizeof (acpi_native_int) - 1)
|
||||
|
||||
/* Variable argument list macro definitions */
|
||||
#define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))
|
||||
#define va_arg(ap, T) (*(T *)(((ap) += (_bnd (T, _AUPBND))) - (_bnd (T,_ADNBND))))
|
||||
#define va_end(ap) (ap = (va_list) NULL)
|
||||
#define va_start(ap, A) (void) ((ap) = (((char *) &(A)) + (_bnd (A,_AUPBND))))
|
||||
|
||||
#endif /* va_arg */
|
||||
|
||||
#endif //_VA_LIST_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue