AliOS Things API KERNEL Guide - Shaofa/AliOS-Things-Certification-Manual GitHub Wiki

API INDEX


1-aos_reboot

void aos_reboot(void)
  • Description

    Reboot AliOS.

  • Parameters

    None.

  • Returns

    None.

2-aos_get_hz

int aos_get_hz(void)
  • Description

    Get HZ(ticks per second).

  • Parameters

    None.

  • Returns

    RHINO_CONFIG_TICKS_PER_SECOND.

3-aos_version_get

const char *aos_version_get(void)
  • Description

    Get kernel version.

  • Parameters

    None.

  • Returns

    SYSINFO_KERNEL_VERSION.

4-aos_task_new

int aos_task_new(const char *name, void (*fn)(void *), void *arg, int stack_size)
  • Description

    Create a task.

  • Parameters

    IN/OUT NAME DESC
    [in] name task name.
    [in] fn function to run.
    [in] arg argument of the function.
    [in] stacksize stack-size in bytes.
  • Returns

    0: success.

5-aos_task_new_ext

int aos_task_new_ext(aos_task_t *task, const char *name, void (*fn)(void *), void *arg,
                     int stack_size, int prio)
  • Description

    Create a task.

  • Parameters

    IN/OUT NAME DESC
    [in] task handle.
    [in] name task name.
    [in] fn task function.
    [in] arg argument of the function..
    [in] stack_buf stack-buf: if stack_buf==NULL, provided by kernel.
    [in] stack_size stack-size in bytes.
    [in] prio priority value, the max is RHINO_CONFIG_USER_PRI_MAX(default 60).
  • Returns

    0: success.

6-aos_task_exit

void aos_task_exit(int code)
  • Description

    Exit a task.

  • Parameters

    IN/OUT NAME DESC
    [in] code not used now.
  • Returns

    None.

7-aos_task_name

const char *aos_task_name(void)
  • Description

    Get task name.

  • Parameters

    None.

  • Returns

    the name of the task

8-aos_task_key_create

int aos_task_key_create(aos_task_key_t *key)
  • Description

    Create a task key.

  • Parameters

    IN/OUT NAME DESC
    [in] key pointer of key object.
  • Returns

    0: success, -EINVAL: error.

9-aos_task_key_delete

void aos_task_key_delete(aos_task_key_t key)
  • Description

    Delete a task key.

  • Parameters

    IN/OUT NAME DESC
    [in] key key object.
  • Returns

    None.

10-aos_task_setspecific

int aos_task_setspecific(aos_task_key_t key, void *vp)
  • Description

    Associate a task-specific value with a key.

  • Parameters

    IN/OUT NAME DESC
    [in] key key object.
    [in] vp pointer of a task-specific value.
  • Returns

    the check status, 0 is OK, -1 indicates invalid.

11-aos_task_getspecific

void *aos_task_getspecific(aos_task_key_t key)
  • Description

    Get the value currently bound to the specified key.

  • Parameters

    IN/OUT NAME DESC
    [in] key key object.
  • Returns

    None.

12-aos_mutex_new

int aos_mutex_new(aos_mutex_t *mutex)
  • Description

    Alloc a mutex.

  • Parameters

    IN/OUT NAME DESC
    [in] mutex pointer of mutex object, mutex object must be alloced, hdl pointer in aos_mutex_t will refer a kernel obj internally.
  • Returns

    0: success.

13-aos_mutex_free

void aos_mutex_free(aos_mutex_t *mutex)
  • Description

    Free a mutex.

  • Parameters

    IN/OUT NAME DESC
    [in] mutex mutex object, mem refered by hdl pointer in aos_mutex_t will be freed internally.
  • Returns

    None.

14-aos_mutex_lock

int aos_mutex_lock(aos_mutex_t *mutex, unsigned int timeout)
  • Description

    Lock a mutex.

  • Parameters

    IN/OUT NAME DESC
    [in] mutex mutex object, it contains kernel obj pointer which aos_mutex_new alloced.
    [in] timeout waiting until timeout in milliseconds.
  • Returns

    0: success.

15-aos_mutex_unlock

int aos_mutex_unlock(aos_mutex_t *mutex)
  • Description

    Unlock a mutex.

  • Parameters

    IN/OUT NAME DESC
    [in] mutex mutex object, it contains kernel obj pointer which oc_mutex_new alloced.
  • Returns

    0: success.

16-aos_mutex_is_valid

int aos_mutex_is_valid(aos_mutex_t *mutex)
  • Description

    This function will check if mutex is valid.

  • Parameters

    IN/OUT NAME DESC
    [in] mutex pointer to the mutex.
  • Returns

    0: success.

17-aos_sem_new

int aos_sem_new(aos_sem_t *sem, int count)
  • Description

    Alloc a semaphore.

  • Parameters

    IN/OUT NAME DESC
    [out] sem pointer of semaphore object, semaphore object must be alloced,hdl pointer in aos_sem_t will refer a kernel obj internally.
    [in] count initial semaphore counter.
  • Returns

    0:success.

18-aos_sem_free

void aos_sem_free(aos_sem_t *sem)
  • Description

    Destroy a semaphore.

  • Parameters

    IN/OUT NAME DESC
    [in] sem pointer of semaphore object, mem refered by hdl pointer in aos_sem_t will be freed internally.
  • Returns

    None.

19-aos_sem_wait

int aos_sem_wait(aos_sem_t *sem, unsigned int timeout)
  • Description

    Acquire a semaphore.

  • Parameters

    IN/OUT NAME DESC
    [in] sem semaphore object, it contains kernel obj pointer which aos_sem_new alloced.
    [in] timeout waiting until timeout in milliseconds.
  • Returns

    0: success.

20-aos_sem_signal

void aos_sem_signal(aos_sem_t *sem)
  • Description

    Release a semaphore.

  • Parameters

    IN/OUT NAME DESC
    [in] sem semaphore object, it contains kernel obj pointer which aos_sem_new alloced.
  • Returns

    None.

21-aos_sem_is_valid

int aos_sem_is_valid(aos_sem_t *sem)
  • Description

    This function will check if semaphore is valid.

  • Parameters

    IN/OUT NAME DESC
    [in] sem pointer to the semaphore.
  • Returns

    0: success.

22-aos_sem_signal_all

void aos_sem_signal_all(aos_sem_t *sem)
  • Description

    Release all semaphore.

  • Parameters

    IN/OUT NAME DESC
    [in] sem semaphore object, it contains kernel obj pointer which aos_sem_new alloced.
  • Returns

    None.

23-aos_queue_new

int aos_queue_new(aos_queue_t *queue, void *buf, unsigned int size, int max_msg)
  • Description

    This function will create a queue.

  • Parameters

    IN/OUT NAME DESC
    [in] queue pointer to the queue(the space is provided by user).
    [in] buf buf of the queue(provided by user).
    [in] size the bytes of the buf.
    [in] max_msg the max size of the msg.
  • Returns

    0: success.

24-aos_queue_free

void aos_queue_free(aos_queue_t *queue)
  • Description

    This function will delete a queue.

  • Parameters

    IN/OUT NAME DESC
    [in] queue pointer to the queue.
  • Returns

    None.

25-aos_queue_send

int aos_queue_send(aos_queue_t *queue, void *msg, unsigned int size)
  • Description

    This function will send a msg to the front of a queue.

  • Parameters

    IN/OUT NAME DESC
    [in] queue pointer to the queue.
    [in] msg msg to send.
    [in] size size of the msg.
  • Returns

    0: success.

26-aos_queue_recv

int aos_queue_recv(aos_queue_t *queue, unsigned int ms, void *msg,unsigned int *size)
  • Description

    This function will receive msg from a queue.

  • Parameters

    IN/OUT NAME DESC
    [in] queue pointer to the queue.
    [in] ms ms to wait before receive.
    [out] msg buf to save msg.
    [out] size size of the msg.
  • Returns

    0: success.

27-aos_queue_is_valid

int aos_queue_is_valid(aos_queue_t *queue)
  • Description

    This function will check if queue is valid.

  • Parameters

    IN/OUT NAME DESC
    [in] queue pointer to the queue.
  • Returns

    0: success.

28-aos_queue_buf_ptr

void *aos_queue_buf_ptr(aos_queue_t *queue)
  • Description

    This function will return buf ptr if queue is inited.

  • Parameters

    IN/OUT NAME DESC
    [in] queue pointer to the queue.
  • Returns

    NULL: error.

29-aos_sched_disable

int aos_sched_disable(void)
  • Description

    This function will disable kernel sched.

  • Parameters

    None.

  • Returns

    the operation status, 0 is OK, others is error.

30-aos_sched_enable

int aos_sched_enable(void)
  • Description

    This function will enable kernel sched.

  • Parameters

    None.

  • Returns

    0: success.

31-aos_timer_new

int aos_timer_new(aos_timer_t *timer, void (*fn)(void *, void *),
                  void *arg, int ms, int repeat)
  • Description

    This function will create a timer.

  • Parameters

    IN/OUT NAME DESC
    [in] timer pointer to the timer.
    [in] fn callbak of the timer.
    [in] arg the argument of the callback.
    [in] ms ms of the normal timer triger.
    [in] repeat repeat or not when the timer is created.
  • Returns

    0: success.

32-aos_timer_free

void aos_timer_free(aos_timer_t *timer)
  • Description

    This function will delete a timer.

  • Parameters

    IN/OUT NAME DESC
    [in] timer pointer to a timer.
  • Returns

    None.

33-aos_timer_start

int aos_timer_start(aos_timer_t *timer)
  • Description

    This function will start a timer.

  • Parameters

    IN/OUT NAME DESC
    [in] timer pointer to the timer.
  • Returns

    0: success.

34-aos_timer_stop

int aos_timer_stop(aos_timer_t *timer)
  • Description

    This function will stop a timer.

  • Parameters

    IN/OUT NAME DESC
    [in] timer pointer to the timer.
  • Returns

    0: success.

35-aos_timer_change

int aos_timer_change(aos_timer_t *timer, int ms)
  • Description

    This function will change attributes of a timer.

  • Parameters

    IN/OUT NAME DESC
    [in] timer pointer to the timer.
    [in] ms ms of the timer triger.
  • Returns

    0: success.

36-aos_workqueue_create

int aos_workqueue_create(aos_workqueue_t *workqueue, int pri, int stack_size)
  • Description

    This function will creat a workqueue.

  • Parameters

    IN/OUT NAME DESC
    [in] workqueue the workqueue to be created.
    [in] pri the priority of the worker.
    [in] stack_size the size of the worker-stack.
  • Returns

    0: success.

37-aos_workqueue_del

void aos_workqueue_del(aos_workqueue_t *workqueue)
  • Description

    This function will delete a workqueue.

  • Parameters

    IN/OUT NAME DESC
    [in] workqueue the workqueue to be deleted.
  • Returns

    None.

38-aos_work_init

int aos_work_init(aos_work_t *work, void (*fn)(void *), void *arg, int dly)
  • Description

    This function will initialize a work.

  • Parameters

    IN/OUT NAME DESC
    [in] work the work to be initialized.
    [in] fn the call back function to run.
    [in] arg the paraments of the function.
    [in] dly ms to delay before run.
  • Returns

    0: success.

39-aos_work_destroy

void aos_work_destroy(aos_work_t *work)
  • Description

    This function will destroy a work.

  • Parameters

    IN/OUT NAME DESC
    [in] work the work to be destroied.
  • Returns

    None.

40-aos_work_run

int aos_work_run(aos_workqueue_t *workqueue, aos_work_t *work)
  • Description

    This function will run a work on a workqueue.

  • Parameters

    IN/OUT NAME DESC
    [in] workqueue the workqueue to run work.
    [in] work the work to run.
  • Returns

    0: success.

41-aos_work_sched

int aos_work_sched(aos_work_t *work)
  • Description

    This function will run a work on the default workqueue.

  • Parameters

    IN/OUT NAME DESC
    [in] work the work to run.
  • Returns

    0: success.

42-aos_work_cancel

int aos_work_cancel(aos_work_t *work)
  • Description

    This function will cancel a work on the default workqueue.

  • Parameters

    IN/OUT NAME DESC
    [in] work the work to cancel.
  • Returns

    0: success.

43-aos_realloc

void *aos_realloc(void *mem, unsigned int size)
  • Description

    Realloc memory.

  • Parameters

    IN/OUT NAME DESC
    [in] mem current memory address point.
    [in] size new size of the mem to remalloc.
  • Returns

    NULL: error.

44-aos_malloc

void *aos_malloc(unsigned int size)
  • Description

    Alloc memory.

  • Parameters

    IN/OUT NAME DESC
    [in] size size of the mem to malloc.
  • Returns

    NULL: error.

45-aos_zalloc

void *aos_zalloc(unsigned int size)
  • Description

    Alloc memory and clear to zero.

  • Parameters

    IN/OUT NAME DESC
    [in] size size of the mem to malloc.
  • Returns

    NULL: error.

46-aos_alloc_trace

void aos_alloc_trace(void *addr, size_t allocator)
  • Description

    Trace alloced mems.

  • Parameters

    IN/OUT NAME DESC
    [in] addr pointer of the mem alloced by malloc.
    [in] allocator buildin_address.
  • Returns

    None.

47-aos_free

void aos_free(void *mem)
  • Description

    Free memory.

  • Parameters

    IN/OUT NAME DESC
    [in] ptr address point of the mem.
  • Returns

    None.

48-aos_now

long long aos_now(void)
  • Description

    Get current time in nano seconds.

  • Parameters

    None.

  • Returns

    elapsed time in nano seconds from system starting.

49-aos_now_ms

long long aos_now_ms(void)
  • Description

    Get current time in mini seconds.

  • Parameters

    None.

  • Returns

    elapsed time in mini seconds from system starting.

50-aos_msleep

void aos_msleep(int ms)
  • Description

    Msleep.

  • Parameters

    IN/OUT NAME DESC
    [in] ms sleep time in milliseconds.
  • Returns

    None.

⚠️ **GitHub.com Fallback** ⚠️