734 lines
25 KiB
C
734 lines
25 KiB
C
/**
|
||
* NOTE:
|
||
*
|
||
* HAL_TCP_xxx API reference implementation: wrappers/os/ubuntu/HAL_TCP_linux.c
|
||
*
|
||
*/
|
||
#include "infra_types.h"
|
||
#include "infra_defs.h"
|
||
#include "infra_compat.h"
|
||
#include "wrappers_defs.h"
|
||
#include "stdarg.h"
|
||
#include "generic/typedef.h"
|
||
#include "os/os_api.h"
|
||
|
||
static const char _firmware_version[IOTX_FIRMWARE_VER_LEN] = "JL-APP-V2021-4-19";
|
||
extern u32 timer_get_ms(void);
|
||
/**
|
||
*
|
||
* 函数 HAL_Free() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_Free() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_Free(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_Free, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Deallocate memory block
|
||
*
|
||
* @param[in] ptr @n Pointer to a memory block previously allocated with platform_malloc.
|
||
* @return None.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
extern void HAL_Free(void *ptr)
|
||
{
|
||
free(ptr);
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_GetDeviceName() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_GetDeviceName() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_GetDeviceName(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_GetDeviceName, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Get device name from user's system persistent storage
|
||
*
|
||
* @param [ou] device_name: array to store device name, max length is IOTX_DEVICE_NAME_LEN
|
||
* @return the actual length of device name
|
||
*/
|
||
int HAL_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN])
|
||
{
|
||
strcpy(device_name, "iot-001");
|
||
return (int)1;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_GetDeviceSecret() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_GetDeviceSecret() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_GetDeviceSecret(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_GetDeviceSecret, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Get device secret from user's system persistent storage
|
||
*
|
||
* @param [ou] device_secret: array to store device secret, max length is IOTX_DEVICE_SECRET_LEN
|
||
* @return the actual length of device secret
|
||
*/
|
||
int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN])
|
||
{
|
||
strcpy(device_secret, "6cba2f877c8683c2341009750b88481b");
|
||
return (int)1;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_GetFirmwareVersion() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_GetFirmwareVersion() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_GetFirmwareVersion(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_GetFirmwareVersion, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Get firmware version
|
||
*
|
||
* @param [ou] version: array to store firmware version, max length is IOTX_FIRMWARE_VER_LEN
|
||
* @return the actual length of firmware version
|
||
*/
|
||
int HAL_GetFirmwareVersion(char *version)
|
||
{
|
||
int len = strlen(_firmware_version);
|
||
memset(version, 0x0, IOTX_FIRMWARE_VER_LEN);
|
||
strncpy(version, _firmware_version, IOTX_FIRMWARE_VER_LEN);
|
||
version[len] = '\0';
|
||
return strlen(version);
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_GetProductKey() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_GetProductKey() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_GetProductKey(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_GetProductKey, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Get product key from user's system persistent storage
|
||
*
|
||
* @param [ou] product_key: array to store product key, max length is IOTX_PRODUCT_KEY_LEN
|
||
* @return the actual length of product key
|
||
*/
|
||
int HAL_GetProductKey(char product_key[IOTX_PRODUCT_KEY_LEN])
|
||
{
|
||
strcpy(product_key, "a1mhUx5m6Uq");
|
||
return (int)1;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_GetProductSecret() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_GetProductSecret() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_GetProductSecret(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_GetProductSecret, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
int HAL_GetProductSecret(char *product_secret)
|
||
{
|
||
strcpy(product_secret, "a1mhUx5m6Uq");
|
||
return (int)1;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_Malloc() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_Malloc() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_Malloc(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_Malloc, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.
|
||
*
|
||
* @param [in] size @n specify block size in bytes.
|
||
* @return A pointer to the beginning of the block.
|
||
* @see None.
|
||
* @note Block value is indeterminate.
|
||
*/
|
||
extern void *HAL_Malloc(uint32_t size)
|
||
{
|
||
return malloc(size);
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_MutexCreate() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_MutexCreate() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_MutexCreate(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_MutexCreate, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Create a mutex.
|
||
*
|
||
* @retval NULL : Initialize mutex failed.
|
||
* @retval NOT_NULL : The mutex handle.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
extern void *HAL_MutexCreate(void)
|
||
{
|
||
OS_MUTEX *pmutex;
|
||
|
||
pmutex = (OS_MUTEX *)malloc(sizeof(OS_MUTEX));
|
||
|
||
if (pmutex == NULL) {
|
||
return NULL;
|
||
}
|
||
|
||
os_mutex_create(pmutex);
|
||
|
||
return (void *)pmutex;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_MutexDestroy() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_MutexDestroy() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_MutexDestroy(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_MutexDestroy, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Destroy the specified mutex object, it will release related resource.
|
||
*
|
||
* @param [in] mutex @n The specified mutex.
|
||
* @return None.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
extern void HAL_MutexDestroy(void *mutex)
|
||
{
|
||
if (mutex != NULL) {
|
||
os_mutex_del((OS_MUTEX *)mutex, 0);
|
||
free((void *)mutex);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_MutexLock() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_MutexLock() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_MutexLock(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_MutexLock, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Waits until the specified mutex is in the signaled state.
|
||
*
|
||
* @param [in] mutex @n the specified mutex.
|
||
* @return None.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
extern void HAL_MutexLock(void *mutex)
|
||
{
|
||
if (mutex != NULL) {
|
||
os_mutex_pend((OS_MUTEX *)mutex, 0);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_MutexUnlock() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_MutexUnlock() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_MutexUnlock(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_MutexUnlock, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Releases ownership of the specified mutex object..
|
||
*
|
||
* @param [in] mutex @n the specified mutex.
|
||
* @return None.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
extern void HAL_MutexUnlock(void *mutex)
|
||
{
|
||
if (mutex != NULL) {
|
||
os_mutex_post((OS_MUTEX *)mutex);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_Printf() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_Printf() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_Printf(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_Printf, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Writes formatted data to stream.
|
||
*
|
||
* @param [in] fmt: @n String that contains the text to be written, it can optionally contain embedded format specifiers
|
||
that specifies how subsequent arguments are converted for output.
|
||
* @param [in] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers.
|
||
* @return None.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
extern void HAL_Printf(const char *fmt, ...)
|
||
{
|
||
va_list args;
|
||
va_start(args, fmt);
|
||
vprintf(fmt, args);
|
||
va_end(args);
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_Random() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_Random() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_Random(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_Random, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
uint32_t HAL_Random(uint32_t region)
|
||
{
|
||
return (uint32_t)rand32();
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_SetDeviceName() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_SetDeviceName() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_SetDeviceName(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_SetDeviceName, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
int HAL_SetDeviceName(char *device_name)
|
||
{
|
||
return (int)1;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_SetDeviceSecret() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_SetDeviceSecret() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_SetDeviceSecret(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_SetDeviceSecret, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
int HAL_SetDeviceSecret(char *device_secret)
|
||
{
|
||
return (int)1;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_SetProductKey() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_SetProductKey() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_SetProductKey(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_SetProductKey, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
int HAL_SetProductKey(char *product_key)
|
||
{
|
||
return (int)1;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_SetProductSecret() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_SetProductSecret() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_SetProductSecret(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_SetProductSecret, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
int HAL_SetProductSecret(char *product_secret)
|
||
{
|
||
|
||
return (int)1;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_SleepMs() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_SleepMs() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_SleepMs(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_SleepMs, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Sleep thread itself.
|
||
*
|
||
* @param [in] ms @n the time interval for which execution is to be suspended, in milliseconds.
|
||
* @return None.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
extern void HAL_SleepMs(uint32_t ms)
|
||
{
|
||
unsigned int t;
|
||
|
||
t = ms / 10 + ((ms % 10) > 5 ? 1 : 0);
|
||
os_time_dly(t == 0 ? 1 : t);
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_Snprintf() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_Snprintf() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_Snprintf(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_Snprintf, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Writes formatted data to string.
|
||
*
|
||
* @param [out] str: @n String that holds written text.
|
||
* @param [in] len: @n Maximum length of character will be written
|
||
* @param [in] fmt: @n Format that contains the text to be written, it can optionally contain embedded format specifiers
|
||
that specifies how subsequent arguments are converted for output.
|
||
* @param [in] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers.
|
||
* @return bytes of character successfully written into string.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int HAL_Snprintf(char *str, const int len, const char *fmt, ...)
|
||
{
|
||
va_list args;
|
||
int rc;
|
||
|
||
va_start(args, fmt);
|
||
rc = vsnprintf(str, len, fmt, args);
|
||
va_end(args);
|
||
|
||
return rc;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_Srandom() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_Srandom() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_Srandom(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_Srandom, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
void HAL_Srandom(uint32_t seed)
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_UptimeMs() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_UptimeMs() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_UptimeMs(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_UptimeMs, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
/**
|
||
* @brief Retrieves the number of milliseconds that have elapsed since the system was boot.
|
||
*
|
||
* @return the number of milliseconds.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
uint64_t HAL_UptimeMs(void)
|
||
{
|
||
return (uint64_t)timer_get_ms();
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* 函数 HAL_Vsnprintf() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
|
||
* ---
|
||
* Interface of HAL_Vsnprintf() requires to be implemented by user of SDK, according to target device platform
|
||
*
|
||
* 如果需要参考如何实现函数 HAL_Vsnprintf(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
|
||
* ---
|
||
* If you need guidance about how to implement HAL_Vsnprintf, you can check its reference implementation for Ubuntu platform
|
||
*
|
||
* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
|
||
*
|
||
*
|
||
* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
|
||
*
|
||
* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
|
||
*
|
||
*/
|
||
int HAL_Vsnprintf(char *str, const int len, const char *format, va_list ap)
|
||
{
|
||
return vsnprintf(str, len, format, ap);
|
||
}
|
||
|
||
#if 0
|
||
int HAL_ThreadCreate(
|
||
void **thread_handle,
|
||
void *(*work_routine)(void *),
|
||
void *arg,
|
||
hal_os_thread_param_t *hal_os_thread_param,
|
||
int *stack_used)
|
||
{
|
||
size_t stacksize;
|
||
|
||
int handle;
|
||
|
||
if (thread_handle == NULL) {
|
||
return -1;
|
||
}
|
||
|
||
if (work_routine == NULL) {
|
||
return -1;
|
||
}
|
||
|
||
if (hal_os_thread_param == NULL) {
|
||
return -1;
|
||
}
|
||
if (stack_used == NULL) {
|
||
return -1;
|
||
}
|
||
|
||
if (stack_used != NULL) {
|
||
*stack_used = 0;
|
||
}
|
||
|
||
if (thread_fork(hal_os_thread_param->name, hal_os_thread_param->priority, hal_os_thread_param->stack_size, \
|
||
0, &handle, work_routine, arg) != OS_NO_ERR) {
|
||
puts("HAL_ThreadCreate : thread_fork");
|
||
return -1;
|
||
}
|
||
|
||
*thread_handle = (void *)handle;
|
||
|
||
return 0;
|
||
}
|
||
#endif
|