126 lines
3.6 KiB
C
Executable File
126 lines
3.6 KiB
C
Executable File
|
|
#include "hsf.h"
|
|
|
|
#define HFTHREAD_PRIORITIES_LOW (15)
|
|
#define HFTHREAD_PRIORITIES_MID (13)
|
|
#define HFTHREAD_PRIORITIES_NORMAL (10)
|
|
#define HFTHREAD_PRIORITIES_HIGH (8)
|
|
#define HFTHREAD_MAX_PRIORITIES (1)
|
|
|
|
|
|
typedef void (*PHFTHREAD_START_ROUTINE)( void * arg);
|
|
|
|
typedef void* hfthread_sem_t;
|
|
|
|
int hfthread_create(PHFTHREAD_START_ROUTINE routine, char * name, uint16_t stack_depth, void *parameters, uint32_t uxpriority, uint32_t *created_thread, uint32_t *stack_buffer);
|
|
|
|
int hfsys_init(void);
|
|
|
|
void HSF_API hfthread_delay(uint32_t ms);
|
|
void HSF_API hfthread_destroy(uint32_t task_id);
|
|
|
|
|
|
#define msleep(ms) hfthread_delay(ms)
|
|
|
|
|
|
typedef void* hfthread_mutex_t;
|
|
|
|
#define NULL_MUTEX (hfthread_mutex_t)0
|
|
|
|
/**
|
|
* @brief create a mutex, not allow in ISR.
|
|
*
|
|
* @param[in] mutex: a pointer to mutex handle
|
|
* @return[out] HF_SUCCESS-successfully, other value is failed
|
|
* @see None.
|
|
* @note None.
|
|
*/
|
|
int HSF_API hfthread_mutext_new(hfthread_mutex_t *pmutex);
|
|
|
|
/**
|
|
* @brief free a mutex, not allow in ISR.
|
|
*
|
|
* @param[in] pmutex: the specified mutex handle
|
|
* @return[out] None
|
|
* @see None.
|
|
* @note None.
|
|
*/
|
|
void HSF_API hfthread_mutext_free(hfthread_mutex_t mutex);
|
|
|
|
/**
|
|
* @brief releases ownership of the specified mutex object, not allow in ISR.
|
|
*
|
|
* @param[in] mutex: the specified mutex handle
|
|
* @return[out] None
|
|
* @see None.
|
|
* @note None.
|
|
*/
|
|
void HSF_API hfthread_mutext_unlock(hfthread_mutex_t mutex);
|
|
|
|
/**
|
|
* @brief waits until the specified mutex is in the signaled state, not allow in ISR.
|
|
*
|
|
* @param[in] mutex: the specified mutex handle
|
|
* timeout: timeout interval in millisecond, value >= 10, 0xFFFFFFFF mean the function will return only when the mutex is signaled
|
|
* @return[out] HF_SUCCESS-successfully, other value is failed
|
|
* @see None.
|
|
* @note None.
|
|
*/
|
|
int HSF_API hfthread_mutext_wait(hfthread_mutex_t mutex, uint32_t timeout);
|
|
|
|
/**
|
|
* @brief try to wait a mutex, not allow in ISR.
|
|
*
|
|
* @param[in] mutex: the specified mutex handle
|
|
* @return[out] HF_SUCCESS-successfully, other value is failed
|
|
* @see None.
|
|
* @note None.
|
|
*/
|
|
int HSF_API hfthread_mutext_trylock(hfthread_mutex_t mutex);
|
|
|
|
#define hfthread_mutext_lock(_mu) hfthread_mutext_wait(_mu,0xFFFFFFFF)
|
|
|
|
|
|
/**
|
|
* @brief create a semaphore, not allow in ISR.
|
|
*
|
|
* @param[in] sem: a pointer to semaphore handle
|
|
* cnt: the count of the semaphore, maximum is 255
|
|
* @return[out] HF_SUCCESS-successfully, other value is failed
|
|
* @see None.
|
|
* @note None.
|
|
*/
|
|
int HSF_API hfthread_sem_new(hfthread_sem_t *sem,uint8_t cnt);
|
|
|
|
/**
|
|
* @brief free a semaphore, not allow in ISR.
|
|
*
|
|
* @param[in] sem: the specified semaphore handle
|
|
* @return[out] None
|
|
* @see None.
|
|
* @note None.
|
|
*/
|
|
void HSF_API hfthread_sem_free(hfthread_sem_t sem);
|
|
|
|
/**
|
|
* @brief increases the count of the specified semaphore object by 1.
|
|
*
|
|
* @param[in] sem: the specified semaphore handle
|
|
* @return[out] None
|
|
* @see None.
|
|
* @note None.
|
|
*/
|
|
void HSF_API hfthread_sem_signal(hfthread_sem_t sem);
|
|
|
|
/**
|
|
* @brief wait until the specified mutex is in the signaled state or the time-out interval elapses, not allow in ISR.
|
|
*
|
|
* @param[in] sem: the specified semaphore handle
|
|
* timeout: timeout interval in millisecond, value >= 10, 0xFFFFFFFF mean the function will return only when the semaphore is signaled
|
|
* @return[out] 1-the state of the specified object is signaled, 0-the time-out interval elapsed, and the object's state is nonsignaled
|
|
* @see None.
|
|
* @note None.
|
|
*/
|
|
int HSF_API hfthread_sem_wait(hfthread_sem_t sem, uint32_t timeout);
|
|
|