UTILS API 参考
-
void wm_system_reboot(void)
system reboot
This function reboot the system.
-
int wm_set_cpu_usage_duration(uint32_t time_ms)
This function to set cpu usage duration.
- 参数:
time_ms – [in] : The time of being counted, if 0, the statistical time will be calculated from the last time it was not 0
- 返回:
WM_ERR_SUCCESS on success
other failed
-
int wm_printf(const char *fmt, ...)
format the parameter to stdout, Similar to printf
- 参数:
fmt – [in] format patten
arg_ptr – [in] variable arguments
- 返回:
output size
-
int wm_vprintf(const char *fmt, va_list arg_ptr)
format the arg_ptr to stdout, Similar to vprintf
- 参数:
fmt – [in] format patten
arg_ptr – [in] variable arguments
- 返回:
output size
-
int wm_vsnprintf(char *buffer, size_t count, const char *format, va_list va)
format the va to buffer, Similar to vsnprintf
- 参数:
buffer – [in] buffer for save foarmat string
count – [in] buffer size
format – [in] format patten
va – [in] variable arguments
- 返回:
The size need output
-
int wm_hex_str_to_array(const char *str, uint8_t array[], int array_len)
Converts the hex string to a byte array.
- 参数:
str – [in] hex string
array – [out] hex array
array_len – [in] hex array length
- 返回:
WM_ERR_SUCCESS on success
other failed
-
int wm_hex2byte(const char hex[2])
convert double hex character to byte
- 参数:
hex – [in] double hex character
- 返回:
>= 0 : the result convert by character
-1 : fail
-
int wm_atohex(char ch)
convert hex character to integer
- 参数:
ch – [in] hex character
- 返回:
>= 0 : the result convert by character
-1 : fail
-
int wm_atoi(const char *s, int *err)
convert string to integer
- 参数:
s – [in] the string to be checked
err – [out] error, 0: no error, 1: has error
- 返回:
integer : the result convert by string
-
uint8_t wm_get_crc8(uint8_t *ptr, uint32_t len)
calculate crc8
- 参数:
str – [in] the string to be checked
- 返回:
true : exist double quotation marks
false : not exist double quotation marks
-
bool wm_isstr(const char *str)
Check whether there are double quotation marks at both ends of the string.
- 参数:
str – [in] the string to be checked
- 返回:
true : exist double quotation marks
false : not exist double quotation marks
-
bool wm_isdigitstr(const char *str)
Check the string is a valid digital string.
- 参数:
str – [in] the string to be checked
- 返回:
true : is a digital string
false : is not a digital string
-
bool wm_isdecimalstr(const char *str)
Check the string is a valid decimal string.
- 参数:
str – [in] the string to be checked
- 返回:
true : is a decimal string
false : is not a decimal string
-
bool wm_ishexstr(const char *str)
Check the string is a valid hex string.
- 参数:
str – [in] the string to be checked
- 返回:
true : is a hex string
false : is not a hex string
-
void wm_remove_quotation_mark(int argc, char **argv)
Remove double quotes at both ends of the args.
- 参数:
argc – [in] Number of arguments
argv – [inout] the arguments array
-
int wm_data_align_parser(uint8_t *addr, int32_t size, wm_data_align_t table[3])
Segments the data buffer based on 4-byte alignment requirements.
This function aligns the buffer’s starting address and length to 4-byte boundaries. It categorizes the buffer into segments suitable for DMA and CPU transfers accordingly.
Example B: Input addr=0x10000001, size=103
The output table will be:
table[0]: flag=2 (CPU), addr=0x10000001, size=3 (first 3 bytes for CPU transfer)
table[1]: flag=1 (DMA), addr=0x10000004, size=100 (next 100 bytes for DMA transfer)
table[2]: flag=0 (Invalid), addr=NULL, size=0
Example C: Input addr=0x10000002, size=103
The output table will be:
table[0]: flag=2 (CPU), addr=0x10000002, size=2 (first 2 bytes for CPU transfer)
table[1]: flag=1 (DMA), addr=0x10000004, size=100 (next 100 bytes for DMA transfer)
table[2]: flag=2 (CPU), addr=0x10000108, size=1 (last 1 byte for CPU transfer)
备注
The `table` must have exactly 3 elements to accommodate the maximum of three segments:
The first segment for CPU transfer (if necessary).
The second segment for DMA transfer.
The third segment for any remaining CPU transfer.
备注
Examples: Example A: Input addr=0x10000000, size=103
The output table will be:
table[0]: flag=1 (DMA), addr=0x10000004, size=100 (100 bytes for DMA transfer)
table[1]: flag=2 (CPU), addr=0x10000104, size=3 (remaining 3 bytes for CPU transfer)
table[2]: flag=0 (Invalid), addr=NULL, size=0
- 参数:
addr – [in] The pointer to the source address of the data buffer.
size – [in] The total size of the data to be transferred.
table – [inout] The pointer to the table where the alignment information will be stored. The table must have exactly 3 elements.
- 返回:
WM_ERR_SUCCESS on success, or an error code on failure.
-
void *memrchr(const void *s, int c, size_t n)
The following API prototypes are same with libc, but they are not in the libc library on W80X platform, so they are implemented in wm_utils.c.
-
char *strdup(const char *s)
-
int strcasecmp(const char *s1, const char *s2)
-
int strncasecmp(const char *s1, const char *s2, size_t n)
-
size_t strlcpy(char *dest, const char *src, size_t len)
-
size_t strnlen(const char *s, size_t maxlen)
-
time_t mktime(struct tm *timeptr)
Convert struct tm to seconds since 1970.
- 参数:
timeptr – [in] struct tm pointer, including year, month, day, hour, minute, second and etc.
- 返回:
The number of seconds since 1970.
-
struct tm *localtime(const time_t *tim_p)
Convert seconds since 1970 to struct tm.
- 参数:
tim_p – [in] pointer of seconds since 1970.
- 返回:
NULL: Failed
others: struct tm pointer