这个页面的 最新开发版本 可能比这个发布的 2.1.0rc1 版本新。

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_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

参数:
  • ptr[in] A pointer to the data buffer to compute the CRC

  • len[in] The length of the data buffer in bytes

返回:

  • 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

int wm_str2int(const char *str, int *value)

transfer a num string to int value

参数:
  • str[in] the string indicates a hex value or digital value

  • value[out] the pointer indicates digital value

返回:

  • true : translate success

  • false : translate failure

bool wm_isnumstr(const char *str)

Check the string is a valid hex string or digital string.

参数:

str[in] the string to be checked

返回:

  • true : is a string indicates a hex value or digital value

  • false : is not a hex value or digital value

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

int settimeofday(const struct timeval *tv, const struct timezone *tz)

Set time and date.

参数:
  • tv[in] Pointer of struct timeval, include seconds and microseconds since 1970.

  • tz[in] Time zone related information has been discarded

返回:

  • 0: success

  • others: failure

int setenv(const char *name, const char *value, int overwrite)

Set environment variable.

参数:
  • name[in] Name of the variable.

  • value[in] Value to set to the variable

  • overwrite[in] Whether existing variable should be overwritten

返回:

  • 0: success

  • others: failure