Kernel API

int aos_task_setspecific(aos_task_key_t key, void * vp)

Associate a task-specific value with a key.

Return
the check status, 0 is OK, -1 indicates invalid.
Parameters
  • key: key object.
  • vp: pointer of a task-specific value.

void* aos_task_getspecific(aos_task_key_t key)

Get the value currently bound to the specified key.

Parameters
  • key: key object.

int aos_mutex_new(aos_mutex_t * mutex)

Alloc a mutex.

Return
0: success.
Parameters
  • mutex: pointer of mutex object, mutex object must be alloced, hdl pointer in aos_mutex_t will refer a kernel obj internally.

void aos_mutex_free(aos_mutex_t * mutex)

Free a mutex.

Parameters
  • mutex: mutex object, mem refered by hdl pointer in aos_mutex_t will be freed internally.

int aos_mutex_lock(aos_mutex_t * mutex, unsigned int timeout)

Lock a mutex.

Return
0: success.
Parameters
  • mutex: mutex object, it contains kernel obj pointer which aos_mutex_new alloced.
  • timeout: waiting until timeout in milliseconds.

int aos_mutex_unlock(aos_mutex_t * mutex)

Unlock a mutex.

Return
0: success.
Parameters
  • mutex: mutex object, it contains kernel obj pointer which oc_mutex_new alloced.

int aos_mutex_is_valid(aos_mutex_t * mutex)

This function will check if mutex is valid.

Return
0: success.
Parameters
  • mutex: pointer to the mutex.

int aos_sem_new(aos_sem_t * sem, int count)

Alloc a semaphore.

Return
0:success.
Parameters
  • sem: pointer of semaphore object, semaphore object must be alloced, hdl pointer in aos_sem_t will refer a kernel obj internally.
  • count: initial semaphore counter.

void aos_sem_free(aos_sem_t * sem)

Destroy a semaphore.

Parameters
  • sem: pointer of semaphore object, mem refered by hdl pointer in aos_sem_t will be freed internally.

int aos_sem_wait(aos_sem_t * sem, unsigned int timeout)

Acquire a semaphore.

Return
0: success.
Parameters
  • sem: semaphore object, it contains kernel obj pointer which aos_sem_new alloced.
  • timeout: waiting until timeout in milliseconds.

void aos_sem_signal(aos_sem_t * sem)

Release a semaphore.

Parameters
  • sem: semaphore object, it contains kernel obj pointer which aos_sem_new alloced.

int aos_sem_is_valid(aos_sem_t * sem)

This function will check if semaphore is valid.

Return
0: success.
Parameters
  • sem: pointer to the semaphore.

void aos_sem_signal_all(aos_sem_t * sem)

Release all semaphore.

Parameters
  • sem: semaphore object, it contains kernel obj pointer which aos_sem_new alloced.

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

This function will create a queue.

Return
0: success.
Parameters
  • queue: pointer to the queue(the space is provided by user).
  • buf: buf of the queue(provided by user).
  • size: the bytes of the buf.
  • max_msg: the max size of the msg.

void aos_queue_free(aos_queue_t * queue)

This function will delete a queue.

Parameters
  • queue: pointer to the queue.

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

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

Return
0: success.
Parameters
  • queue: pointer to the queue.
  • msg: msg to send.
  • size: size of the msg.

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

This function will receive msg from a queue.

Return
0: success.
Parameters
  • queue: pointer to the queue.
  • ms: ms to wait before receive.
  • msg: buf to save msg.
  • size: size of the msg.

int aos_queue_is_valid(aos_queue_t * queue)

This function will check if queue is valid.

Return
0: success.
Parameters
  • queue: pointer to the queue.

void* aos_queue_buf_ptr(aos_queue_t * queue)

This function will return buf ptr if queue is inited.

Return
NULL: error.
Parameters
  • queue: pointer to the queue.

int aos_sched_disable(void)

This function will disable kernel sched.

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

int aos_sched_enable(void)

This function will enable kernel sched.

Return
0: success.

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

This function will create a timer.

Return
0: success.
Parameters
  • timer: pointer to the timer.
  • fn: callbak of the timer.
  • arg: the argument of the callback.
  • ms: ms of the normal timer triger.
  • repeat: repeat or not when the timer is created.

void aos_timer_free(aos_timer_t * timer)

This function will delete a timer.

Parameters
  • timer: pointer to a timer.

int aos_timer_start(aos_timer_t * timer)

This function will start a timer.

Return
0: success.
Parameters
  • timer: pointer to the timer.

int aos_timer_stop(aos_timer_t * timer)

This function will stop a timer.

Return
0: success.
Parameters
  • timer: pointer to the timer.

int aos_timer_change(aos_timer_t * timer, int ms)

This function will change attributes of a timer.

Return
0: success.
Parameters
  • timer: pointer to the timer.
  • ms: ms of the timer triger.

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

This function will creat a workqueue.

Return
0: success.
Parameters
  • workqueue: the workqueue to be created.
  • pri: the priority of the worker.
  • stack_size: the size of the worker-stack.

void aos_workqueue_del(aos_workqueue_t * workqueue)

This function will delete a workqueue.

Parameters
  • workqueue: the workqueue to be deleted.

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

This function will initialize a work.

Return
0: success.
Parameters
  • work: the work to be initialized.
  • fn: the call back function to run.
  • arg: the paraments of the function.
  • dly: ms to delay before run.

void aos_work_destroy(aos_work_t * work)

This function will destroy a work.

Parameters
  • work: the work to be destroied.

int aos_work_run(aos_workqueue_t * workqueue, aos_work_t * work)

This function will run a work on a workqueue.

Return
0: success.
Parameters
  • workqueue: the workqueue to run work.
  • work: the work to run.

int aos_work_sched(aos_work_t * work)

This function will run a work on the default workqueue.

Return
0: success.
Parameters
  • work: the work to run.

int aos_work_cancel(aos_work_t * work)

This function will cancel a work on the default workqueue.

Return
0: success.
Parameters
  • work: the work to cancel.

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

Realloc memory.

Return
NULL: error.
Parameters
  • mem: current memory address point.
  • size: new size of the mem to remalloc.

void* aos_malloc(unsigned int size)

Alloc memory.

Return
NULL: error.
Parameters
  • size: size of the mem to malloc.

void* aos_zalloc(unsigned int size)

Alloc memory and clear to zero.

Return
NULL: error.
Parameters
  • size: size of the mem to malloc.

void aos_alloc_trace(void * addr, size_t allocator)

Trace alloced mems.

Parameters
  • addr: pointer of the mem alloced by malloc.
  • allocator: buildin_address.

void aos_free(void * mem)

Free memory.

Parameters
  • ptr: address point of the mem.

long long aos_now(void)

Get current time in nano seconds.

Return
elapsed time in nano seconds from system starting.

long long aos_now_ms(void)

Get current time in mini seconds.

Return
elapsed time in mini seconds from system starting.

void aos_msleep(int ms)

Msleep.

Parameters
  • ms: sleep time in milliseconds.