Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
104
sdk/include/osal/atomic.h
Normal file
104
sdk/include/osal/atomic.h
Normal file
@@ -0,0 +1,104 @@
|
||||
|
||||
#ifndef _OS_ATOMIC_H_
|
||||
#define _OS_ATOMIC_H_
|
||||
#include "typesdef.h"
|
||||
#include "osal/irq.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8 counter;
|
||||
} atomic8_t;
|
||||
|
||||
typedef struct {
|
||||
uint16 counter;
|
||||
} atomic16_t;
|
||||
|
||||
typedef struct {
|
||||
uint32 counter;
|
||||
} atomic_t;
|
||||
|
||||
typedef struct {
|
||||
uint64 counter;
|
||||
} atomic64_t;
|
||||
|
||||
|
||||
#define atomic64_read(v) ((v)->counter)
|
||||
#define atomic_read(v) ((v)->counter)
|
||||
|
||||
#define atomic_set(v,i) ({ \
|
||||
uint32 __mask__ = disable_irq();\
|
||||
((v)->counter = i); \
|
||||
enable_irq(__mask__);\
|
||||
})
|
||||
#define atomic_add(v,i) ({ \
|
||||
uint32 __mask__ = disable_irq();\
|
||||
((v)->counter += i); \
|
||||
enable_irq(__mask__);\
|
||||
})
|
||||
#define atomic_sub(v,i) ({ \
|
||||
uint32 __mask__ = disable_irq();\
|
||||
if((v)->counter > (i)) { ((v)->counter -= (i)); }\
|
||||
else { (v)->counter = 0; }\
|
||||
enable_irq(__mask__);\
|
||||
})
|
||||
#define atomic_inc(v) ({ \
|
||||
uint32 __mask__ = disable_irq();\
|
||||
((v)->counter++); \
|
||||
enable_irq(__mask__);\
|
||||
})
|
||||
#define atomic_dec(v) ({ \
|
||||
uint32 __mask__ = disable_irq();\
|
||||
if((v)->counter > 0){ (v)->counter--; }\
|
||||
enable_irq(__mask__);\
|
||||
})
|
||||
#define atomic_inc_return(v) ({\
|
||||
uint32 __mask__ = disable_irq();\
|
||||
uint32_t __val__ = (++(v)->counter);\
|
||||
enable_irq(__mask__);\
|
||||
__val__;\
|
||||
})
|
||||
#define atomic_dec_return(v) ({\
|
||||
uint32 __mask__ = disable_irq();\
|
||||
uint32_t __val__ = ((v)->counter > 0) ? (--(v)->counter) : 0;\
|
||||
enable_irq(__mask__);\
|
||||
__val__;\
|
||||
})
|
||||
#define atomic_dec2_return(v) ({\
|
||||
uint32 __mask__ = disable_irq();\
|
||||
uint32_t __val__ = (v)->counter;\
|
||||
if((v)->counter) (--(v)->counter);\
|
||||
enable_irq(__mask__);\
|
||||
__val__;\
|
||||
})
|
||||
#define atomic_dec_and_test(v) ({\
|
||||
uint32 __mask__ = disable_irq();\
|
||||
uint32_t __val__ = ((v)->counter > 0) ? ((--(v)->counter) == 0) : 1;\
|
||||
enable_irq(__mask__);\
|
||||
__val__;\
|
||||
})
|
||||
#define atomic_cmpxchg(v,o,n) ({\
|
||||
uint32 __mask__ = disable_irq();\
|
||||
uint32_t __val = (v)->counter;\
|
||||
if(__val == o) { (v)->counter = n; }\
|
||||
enable_irq(__mask__);\
|
||||
__val;\
|
||||
})
|
||||
|
||||
static inline int atomic_add_unless(atomic_t *v, int a, int u)
|
||||
{
|
||||
int c, old;
|
||||
c = atomic_read(v);
|
||||
while (c != u && (old = atomic_cmpxchg((v), c, c + a)) != c) {
|
||||
c = old;
|
||||
}
|
||||
return c != u;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
28
sdk/include/osal/condv.h
Normal file
28
sdk/include/osal/condv.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef __OS_CONDV_H
|
||||
#define __OS_CONDV_H
|
||||
#include "osal/atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct os_condv {
|
||||
uint32 magic;
|
||||
atomic_t waitings;
|
||||
void *sema;
|
||||
};
|
||||
typedef struct os_condv os_condv_t;
|
||||
|
||||
int32 os_condv_init(os_condv_t *cond);
|
||||
|
||||
int32 os_condv_broadcast(os_condv_t *cond);
|
||||
int32 os_condv_signal(os_condv_t *cond);
|
||||
|
||||
int32 os_condv_del(os_condv_t *cond);
|
||||
int32 os_condv_wait(os_condv_t *cond, os_mutex_t *mutex, uint32 tmo_ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
31
sdk/include/osal/event.h
Normal file
31
sdk/include/osal/event.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef __OS_EVENT_H
|
||||
#define __OS_EVENT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum OS_EVENT_WMODE{
|
||||
OS_EVENT_WMODE_AND = BIT(0), //all bit has been set.
|
||||
OS_EVENT_WMODE_OR = BIT(1), //any bit has been set.
|
||||
OS_EVENT_WMODE_CLEAR = BIT(2), //clear bit after exit.
|
||||
};
|
||||
|
||||
struct os_event {
|
||||
uint32 magic;
|
||||
void *hdl;
|
||||
};
|
||||
typedef struct os_event os_event_t;
|
||||
|
||||
int32 os_event_init(os_event_t *evt);
|
||||
int32 os_event_del(os_event_t *evt);
|
||||
int32 os_event_set(os_event_t *evt, uint32 flags, uint32 *rflags);
|
||||
int32 os_event_clear(os_event_t *evt, uint32 flags, uint32 *rflags);
|
||||
int32 os_event_get(os_event_t *evt, uint32 *rflags);
|
||||
int32 os_event_wait(os_event_t *evt, uint32 flags, uint32 *rflags, uint32 mode, int32 timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
79
sdk/include/osal/ffs.h
Normal file
79
sdk/include/osal/ffs.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#ifndef __OS_FFS_H_
|
||||
#define __OS_FFS_H_
|
||||
|
||||
#if 0
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline int ffs(int x)
|
||||
{
|
||||
int r = 1;
|
||||
|
||||
if (!x) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(x & 0xffff)) {
|
||||
x >>= 16;
|
||||
r += 16;
|
||||
}
|
||||
if (!(x & 0xff)) {
|
||||
x >>= 8;
|
||||
r += 8;
|
||||
}
|
||||
if (!(x & 0xf)) {
|
||||
x >>= 4;
|
||||
r += 4;
|
||||
}
|
||||
if (!(x & 3)) {
|
||||
x >>= 2;
|
||||
r += 2;
|
||||
}
|
||||
if (!(x & 1)) {
|
||||
x >>= 1;
|
||||
r += 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline int fls(int x)
|
||||
{
|
||||
int r = 32;
|
||||
|
||||
if (!x) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(x & 0xffff0000u)) {
|
||||
x <<= 16;
|
||||
r -= 16;
|
||||
}
|
||||
if (!(x & 0xff000000u)) {
|
||||
x <<= 8;
|
||||
r -= 8;
|
||||
}
|
||||
if (!(x & 0xf0000000u)) {
|
||||
x <<= 4;
|
||||
r -= 4;
|
||||
}
|
||||
if (!(x & 0xc0000000u)) {
|
||||
x <<= 2;
|
||||
r -= 2;
|
||||
}
|
||||
if (!(x & 0x80000000u)) {
|
||||
x <<= 1;
|
||||
r -= 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
int ffs(int x);
|
||||
int fls(int x);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
39
sdk/include/osal/irq.h
Normal file
39
sdk/include/osal/irq.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef __OS_IRQ_H_
|
||||
#define __OS_IRQ_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*irq_handle)(void *data);
|
||||
struct sys_hwirq {
|
||||
void *data;
|
||||
irq_handle handle;
|
||||
#ifdef SYS_IRQ_STAT
|
||||
uint32 trig_cnt;
|
||||
uint16 max, min;
|
||||
uint32 tot_cycle;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef CONFIG_SLEEP
|
||||
__dsleep_text void irq_enable(uint32 irq);
|
||||
__dsleep_text void irq_disable(uint32 irq);
|
||||
__dsleep_text uint32 disable_irq(void);
|
||||
__dsleep_text void enable_irq(uint32 flag);
|
||||
#else
|
||||
void irq_enable(uint32 irq);
|
||||
void irq_disable(uint32 irq);
|
||||
uint32 disable_irq(void);
|
||||
void enable_irq(uint32 flag);
|
||||
#endif
|
||||
|
||||
void irq_priority(uint32 irq, uint32 prio);
|
||||
int32 request_irq(uint32 irq_num, irq_handle handle, void *data);
|
||||
int32 release_irq(uint32 irq_num);
|
||||
uint32 sysirq_time(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
31
sdk/include/osal/msgqueue.h
Normal file
31
sdk/include/osal/msgqueue.h
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
#ifndef _OS_MSG_QUEUE_H_
|
||||
#define _OS_MSG_QUEUE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct os_msgqueue {
|
||||
uint32 magic;
|
||||
void *hdl;
|
||||
};
|
||||
typedef struct os_msgqueue os_msgqueue_t;
|
||||
|
||||
int32 os_msgq_init(os_msgqueue_t *msgq, int32 size);
|
||||
uint32 os_msgq_get(os_msgqueue_t *msgq, int32 tmo_ms);
|
||||
uint32 os_msgq_get2(struct os_msgqueue *msgq, int32 tmo_ms, int32 *err);
|
||||
int32 os_msgq_put(os_msgqueue_t *msgq, uint32 data, int32 tmo_ms);
|
||||
int32 os_msgq_del(os_msgqueue_t *msgq);
|
||||
int32 os_msgq_cnt(os_msgqueue_t *msgq);
|
||||
int32 os_msgq_put_head(os_msgqueue_t *msgq, uint32 data, int32 tmo_ms);
|
||||
|
||||
#ifndef OS_MSGQ_DEF
|
||||
#define OS_MSGQ_DEF(name, size) os_msgqueue_t name;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
24
sdk/include/osal/mutex.h
Normal file
24
sdk/include/osal/mutex.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef _OS_MUTEX_H_
|
||||
#define _OS_MUTEX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct os_mutex {
|
||||
uint32 magic;
|
||||
void *hdl;
|
||||
};
|
||||
typedef struct os_mutex os_mutex_t;
|
||||
|
||||
int32 os_mutex_init(os_mutex_t *mutex);
|
||||
int32 os_mutex_lock(os_mutex_t *mutex, int32 tmo);
|
||||
int32 os_mutex_unlock(os_mutex_t *mutex);
|
||||
int32 os_mutex_del(os_mutex_t *mutex);
|
||||
void *os_mutex_owner(os_mutex_t *mutex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
26
sdk/include/osal/semaphore.h
Normal file
26
sdk/include/osal/semaphore.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __OS_SEMAPHORE_H
|
||||
#define __OS_SEMAPHORE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct os_semaphore {
|
||||
uint32 magic;
|
||||
void *hdl;
|
||||
};
|
||||
|
||||
typedef struct os_semaphore os_semaphore_t;
|
||||
|
||||
int32 os_sema_init(os_semaphore_t *sem, int32 val);
|
||||
int32 os_sema_del(os_semaphore_t *sem);
|
||||
int32 os_sema_down(os_semaphore_t *sem, int32 tmo_ms);
|
||||
int32 os_sema_up(os_semaphore_t *sem);
|
||||
int32 os_sema_count(os_semaphore_t *sem);
|
||||
void os_sema_eat(os_semaphore_t *sem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
194
sdk/include/osal/sleep.h
Normal file
194
sdk/include/osal/sleep.h
Normal file
@@ -0,0 +1,194 @@
|
||||
|
||||
#ifndef __OS_SLEEP_H_
|
||||
#define __OS_SLEEP_H_
|
||||
|
||||
#include "typesdef.h"
|
||||
#include "osal/time.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*jiffies is 64bit*/
|
||||
#ifndef DIFF_JIFFIES
|
||||
#define DIFF_JIFFIES(j1,j2) ((j2)-(j1))
|
||||
#endif
|
||||
|
||||
#ifndef TIME_AFTER
|
||||
/* returns true if the time a is after time b. */
|
||||
#define TIME_AFTER(a,b) ((int64)(b) - (int64)(a) < 0)
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
SYSTEM_SLEEP_TYPE_SRAM_WIFI = 1,
|
||||
SYSTEM_SLEEP_TYPE_WIFI_DSLEEP = 2,
|
||||
SYSTEM_SLEEP_TYPE_SRAM_ONLY = 3,
|
||||
SYSTEM_SLEEP_TYPE_LIGHT_SLEEP = 4,
|
||||
SYSTEM_SLEEP_TYPE_RTCC = 5,
|
||||
SYSTEM_SLEEP_TYPE_MAX = 6,
|
||||
} SYSTEM_SLEEP_TYPE;
|
||||
|
||||
typedef enum {
|
||||
DSLEEP_WK_REASON_TIMER = 1,
|
||||
DSLEEP_WK_REASON_TIM = 2,
|
||||
DSLEEP_WK_REASON_BC_TIM = 3,
|
||||
DSLEEP_WK_REASON_IO = 4, //discard
|
||||
DSLEEP_WK_REASON_BEACON_LOST = 5,
|
||||
DSLEEP_WK_REASON_AP_ERROR = 6,
|
||||
DSLEEP_WK_REASON_HB_TIMEOUT = 7,
|
||||
DSLEEP_WK_REASON_WK_DATA = 8,
|
||||
DSLEEP_WK_REASON_MCLR = 9,
|
||||
DSLEEP_WK_REASON_LVD = 10,
|
||||
DSLEEP_WK_REASON_PIR = 11,
|
||||
DSLEEP_WK_REASON_APWK = 12,
|
||||
DSLEEP_WK_REASON_PS_DISCONNECT = 13,
|
||||
DSLEEP_WK_REASON_STANDBY = 14,
|
||||
DSLEEP_WK_REASON_MAX_IDLE_TMO = 15,
|
||||
DSLEEP_WK_REASON_WEAK_SIGNAL = 16,
|
||||
|
||||
DSLEEP_WK_REASON_STA_ERROR = 20,
|
||||
DSLEEP_WK_REASON_SLEEPED_STA_ERROR = 21,
|
||||
DSLEEP_WK_REASON_STA_DATA = 22,
|
||||
DSLEEP_WK_REASON_AP_PAIR = 23,
|
||||
DSLEEP_WK_REASON_KEY_UPDATE = 24,
|
||||
|
||||
DSLEEP_WK_REASON_RTC_ALARM = 25,
|
||||
DSLEEP_WK_REASON_NULL_TX_FAIL = 26,
|
||||
|
||||
DSLEEP_WK_REASON_IO0 = 27,
|
||||
DSLEEP_WK_REASON_IO1 = 28,
|
||||
DSLEEP_WK_REASON_IO2 = 29,
|
||||
DSLEEP_WK_REASON_IO3 = 30,
|
||||
DSLEEP_WK_REASON_IO4 = 31,
|
||||
DSLEEP_WK_REASON_IO5 = 32,
|
||||
DSLEEP_WK_REASON_WDT = 33,
|
||||
} DSLEEP_WK_REASON;
|
||||
|
||||
typedef enum {
|
||||
SYS_SLEEPCB_ACTION_RESUME = 0,
|
||||
SYS_SLEEPCB_ACTION_SUSPEND = 1,
|
||||
} SYS_SLEEPCB_ACTION;
|
||||
|
||||
typedef enum {
|
||||
SYS_SLEEPCB_LMAC,
|
||||
SYS_SLEEPCB_MID,
|
||||
SYS_SLEEPCB_UMAC,
|
||||
SYS_SLEEPCB_APP,
|
||||
} SYS_SLEEPCB_STEP;
|
||||
|
||||
struct system_sleep_param {
|
||||
uint32 sleep_ms;
|
||||
uint8 wkup_io_sel[6];//sel IO0 - IO5
|
||||
uint8 wkup_io_en;//0: dis; 1 en
|
||||
uint8 wkup_io_edge;//0:Rising ; 1: Falling
|
||||
uint8 lsleep_enable :1,
|
||||
lsleep_clk_div :5;
|
||||
};
|
||||
|
||||
struct sys_sleepcb_param {
|
||||
uint8 action, step;
|
||||
union {
|
||||
struct {
|
||||
uint8 wkreason;
|
||||
} resume;
|
||||
struct {
|
||||
struct system_sleep_param *param;
|
||||
} suspend;
|
||||
};
|
||||
};
|
||||
|
||||
typedef int32(*sys_sleepcb)(uint16 type, struct sys_sleepcb_param *args, void *priv);
|
||||
|
||||
enum DSLEEP_IOCTL_CMD {
|
||||
/*Set CMDs*/
|
||||
DSLEEP_IOCTL_SET_ENTER_SLEEP_CB = 0x1, //discard
|
||||
DSLEEP_IOCTL_SET_KEEP_ALIVE_CB,
|
||||
DSLEEP_IOCTL_SET_USR_WKDET_CB,
|
||||
DSLEEP_IOCTL_SET_DSLEEP_BSS_MAX_IDLE,
|
||||
DSLEEP_IOCTL_SET_DSLEEP_WKIO_PIN,
|
||||
DSLEEP_IOCTL_SET_DSLEEP_WKIO_EDGE,
|
||||
DSLEEP_IOCTL_SET_DSLEEP_APLOST_TIME,
|
||||
DSLEEP_IOCTL_SET_DSLEEP_SENS_LEVEL,
|
||||
DSLEEP_IOCTL_SET_DSLEEP_PWM_SEL,
|
||||
DSLEEP_IOCTL_SET_DSLEEP_PWM_MODE,
|
||||
DSLEEP_IOCTL_SET_IP_ADDR,
|
||||
DSLEEP_IOCTL_SET_GPIOA_RESV,
|
||||
DSLEEP_IOCTL_SET_GPIOB_RESV,
|
||||
DSLEEP_IOCTL_SET_GPIOC_RESV,
|
||||
DSLEEP_IOCTL_SET_DTIM,
|
||||
DSLEEP_IOCTL_SET_DEBOUNCE,
|
||||
DSLEEP_IOCTL_SET_TXIC_EN,
|
||||
DSLEEP_IOCTL_SET_TXIC_WAKEP,
|
||||
DSLEEP_IOCTL_SET_WATCHDOG_CLOSE,
|
||||
DSLEEP_IOCTL_SET_FAKE_TIM_FADEOUT,
|
||||
DSLEEP_IOCTL_SET_CLK_SWITCH_DIS,
|
||||
DSLEEP_IOCTL_SET_USE_OLD_LIBFLASH,
|
||||
DSLEEP_IOCTL_SET_PA_LATCH,
|
||||
DSLEEP_IOCTL_SET_EXT_DCDC,
|
||||
DSLEEP_IOCTL_SET_ASSERT_HOLD,
|
||||
DSLEEP_IOCTL_SET_DBG_CFG,
|
||||
/*Get CMDs*/
|
||||
DSLEEP_IOCTL_GET_IP_ADDR = 0x20000000,
|
||||
DSLEEP_IOCTL_GET_DTIM,
|
||||
DSLEEP_IOCTL_GET_DBG_CFG
|
||||
};
|
||||
|
||||
//ioctrl: set_cfg
|
||||
#define dsleep_set_keep_alive_cb(priv, func) dsleep_ioctl(DSLEEP_IOCTL_SET_KEEP_ALIVE_CB, (uint32)priv, (uint32)(func))
|
||||
#define dsleep_set_usr_wkdet_cb(priv, func) dsleep_ioctl(DSLEEP_IOCTL_SET_USR_WKDET_CB, (uint32)priv, (uint32)(func))
|
||||
#define dsleep_set_max_idle(max_idle_sec) dsleep_ioctl(DSLEEP_IOCTL_SET_DSLEEP_BSS_MAX_IDLE, (uint32)(max_idle_sec), 0)
|
||||
#define dsleep_set_wkio_pin(pin_idx, pin_num) dsleep_ioctl(DSLEEP_IOCTL_SET_DSLEEP_WKIO_PIN, (uint32)(pin_idx), (uint32)(pin_num))
|
||||
#define dsleep_set_wkio_edge(pin_idx, neg_edge) dsleep_ioctl(DSLEEP_IOCTL_SET_DSLEEP_WKIO_EDGE, (uint32)(pin_idx), (uint32)(neg_edge))
|
||||
#define dsleep_set_aplost_time(t_sec) dsleep_ioctl(DSLEEP_IOCTL_SET_DSLEEP_APLOST_TIME, (uint32)(t_sec), 0)
|
||||
#define dsleep_set_sens_level(sens_level) dsleep_ioctl(DSLEEP_IOCTL_SET_DSLEEP_SENS_LEVEL, (uint32)(sens_level), 0)
|
||||
#define dsleep_set_pwm_sel(pwm_idx, pin_num) dsleep_ioctl(DSLEEP_IOCTL_SET_DSLEEP_PWM_SEL, (uint32)(pwm_idx), (pin_num))
|
||||
#define dsleep_set_pwm_mode(pwm_idx, mode) dsleep_ioctl(DSLEEP_IOCTL_SET_DSLEEP_PWM_MODE, (uint32)(pwm_idx), (mode))
|
||||
#define dsleep_set_ip_addr(ip_addr) dsleep_ioctl(DSLEEP_IOCTL_SET_IP_ADDR, (uint32)ip_addr, 0)
|
||||
#define dsleep_set_user_gioa(user_gioa) dsleep_ioctl(DSLEEP_IOCTL_SET_GPIOA_RESV, (uint32)user_gioa, 0)
|
||||
#define dsleep_set_user_giob(user_giob) dsleep_ioctl(DSLEEP_IOCTL_SET_GPIOB_RESV, (uint32)user_giob, 0)
|
||||
#define dsleep_set_user_gioc(user_gioc) dsleep_ioctl(DSLEEP_IOCTL_SET_GPIOC_RESV, (uint32)user_gioc, 0)
|
||||
#define dsleep_set_dtim(val) dsleep_ioctl(DSLEEP_IOCTL_SET_DTIM, (uint32)val, 0)
|
||||
#define dsleep_set_debounce(val) dsleep_ioctl(DSLEEP_IOCTL_SET_DEBOUNCE, (uint32)val, 0)
|
||||
#define dsleep_set_txic_en(en) dsleep_ioctl(DSLEEP_IOCTL_SET_TXIC_EN, (uint32)en, 0)
|
||||
#define dsleep_set_txic_wakeup(en) dsleep_ioctl(DSLEEP_IOCTL_SET_TXIC_WAKEP, (uint32)en, 0)
|
||||
#define dsleep_set_watchdog_close(en) dsleep_ioctl(DSLEEP_IOCTL_SET_WATCHDOG_CLOSE, (uint32)en, 0)
|
||||
#define dsleep_set_tim_fadeout(val) dsleep_ioctl(DSLEEP_IOCTL_SET_FAKE_TIM_FADEOUT, (uint32)val, 0)
|
||||
#define dsleep_set_clk_switch_dis(val) dsleep_ioctl(DSLEEP_IOCTL_SET_CLK_SWITCH_DIS, (uint32)val, 0)
|
||||
#define dsleep_set_use_old_libflash(val) dsleep_ioctl(DSLEEP_IOCTL_SET_USE_OLD_LIBFLASH, (uint32)val, 0)
|
||||
#define dsleep_set_pa_latch(val) dsleep_ioctl(DSLEEP_IOCTL_SET_PA_LATCH, (uint32)val, 0)
|
||||
#define dsleep_set_ext_dcdc(en) dsleep_ioctl(DSLEEP_IOCTL_SET_EXT_DCDC, (uint32)en, 0)
|
||||
#define dsleep_set_assert_hold(en) dsleep_ioctl(DSLEEP_IOCTL_SET_ASSERT_HOLD, (uint32)en, 0)
|
||||
#define dsleep_set_dbg_cfg(dbg_cfg) dsleep_ioctl(DSLEEP_IOCTL_SET_DBG_CFG, (uint32)dbg_cfg, 0)
|
||||
|
||||
//ioctrl: get_cfg
|
||||
#define dsleep_get_ip_addr() dsleep_ioctl(DSLEEP_IOCTL_GET_IP_ADDR, 0, 0)
|
||||
#define dsleep_get_dtim() dsleep_ioctl(DSLEEP_IOCTL_GET_DTIM, 0, 0)
|
||||
#define dsleep_get_dbg_cfg() dsleep_ioctl(DSLEEP_IOCTL_GET_DBG_CFG, 0, 0)
|
||||
|
||||
int32 dsleep_ioctl(uint32 cmd, uint32 param1, uint32 param2);
|
||||
void os_sleep(int32 sec);
|
||||
void os_sleep_ms(int32 msec);
|
||||
extern void os_sleep_us(int us);
|
||||
|
||||
int usleep(useconds_t usec);
|
||||
unsigned int sleep(unsigned int sec);
|
||||
void delay_us(uint32 n);
|
||||
|
||||
int sys_sleepcb_init(void);
|
||||
int sys_register_sleepcb(sys_sleepcb cb, void *priv);
|
||||
int sys_suspend(uint16 type, uint8 step, struct system_sleep_param *args);
|
||||
int sys_resume(uint16 type, uint8 step, uint8 wkreason);
|
||||
|
||||
void sys_wakeup_host(void);
|
||||
void sys_enter_sleep(void);
|
||||
uint8 sys_wakeup_reason(void);
|
||||
|
||||
int32 system_sleep(uint16 type, struct system_sleep_param *args);
|
||||
void system_resume(uint16 type, uint8 wkreason);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
212
sdk/include/osal/string.h
Normal file
212
sdk/include/osal/string.h
Normal file
@@ -0,0 +1,212 @@
|
||||
#ifndef __OS_STRING_H__
|
||||
#define __OS_STRING_H__
|
||||
#include "typesdef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*from kernel*/
|
||||
#define KERN_SOH "\001" /* ASCII Start Of Header */
|
||||
#define KERN_TSOH "\002" /* ASCII Start Of Tick Header */
|
||||
#define KERN_EMERG KERN_SOH"0" /* system is unusable */
|
||||
#define KERN_ALERT KERN_SOH"1" /* action must be taken immediately */
|
||||
#define KERN_CRIT KERN_SOH"2" /* critical conditions */
|
||||
#define KERN_ERR KERN_SOH"3" /* error conditions */
|
||||
#define KERN_WARNING KERN_SOH"4" /* warning conditions */
|
||||
#define KERN_NOTICE KERN_SOH"5" /* normal but significant condition */
|
||||
#define KERN_INFO KERN_SOH"6" /* informational */
|
||||
#define KERN_DEBUG KERN_SOH"7" /* debug-level messages */
|
||||
|
||||
void print_level(int8 level);
|
||||
|
||||
void hw_memcpy(void *dest, const void *src, uint32 size);
|
||||
void hw_memset(void *dest, uint8 val, uint32 n);
|
||||
void hw_memcpy0(void *dest, const void *src, uint32 size);
|
||||
void hw_memcpy_no_cache(void *dest, const void *src, uint32 size);
|
||||
|
||||
void *_os_memcpy(void *str1, const void *str2, int32 n);
|
||||
char *_os_strcpy(char *dest, const char *src);
|
||||
void *_os_memset(void *str, int c, int32 n);
|
||||
void *_os_memmove(void *str1, const void *str2, size_t n);
|
||||
char *_os_strncpy(char *dest, const char *src, int32 n);
|
||||
int _os_sprintf(char *str, const char *format, ...);
|
||||
int _os_vsnprintf(char *s, size_t n, const char *format, va_list arg);
|
||||
int _os_snprintf(char *str, size_t size, const char *format, ...);
|
||||
int32 os_strtok(char *str, char *separator, char *argv[], int argv_size);
|
||||
const char *os_strncasechr(const char *s, char c, int32 n);
|
||||
const char *os_strncasestr(const char *str1, const char *str2, int32 n);
|
||||
char *os_strdup(const char *s);
|
||||
uint32 os_atoh(char *str);
|
||||
uint64 os_atohl(char *str);
|
||||
|
||||
#ifndef MAC2STR
|
||||
#define MAC2STR(a) (a)[0]&0xff, (a)[1]&0xff, (a)[2]&0xff, (a)[3]&0xff, (a)[4]&0xff, (a)[5]&0xff
|
||||
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#endif
|
||||
|
||||
#ifndef STR2MAC
|
||||
#define STR2MAC(s, a) str2mac((char *)(s), (uint8 *)(a))
|
||||
#endif
|
||||
|
||||
#ifndef IP2STR_H
|
||||
#define IP2STR_H(ip) ((ip)>>24)&0xff,((ip)>>16)&0xff,((ip)>>8)&0xff,(ip&0xff) //host byteorder
|
||||
#define IP2STR_N(ip) (ip&0xff),((ip)>>8)&0xff,((ip)>>16)&0xff,((ip)>>24)&0xff //network byteorder
|
||||
#define IPSTR "%-03d.%-03d.%-03d.%-03d"
|
||||
#endif
|
||||
|
||||
#define MAC_EQU(a1,a2) (os_memcmp((a1), (a2), 6)==0)
|
||||
#define IS_BCAST_ADDR(a) (((a)[0]&(a)[1]&(a)[2]&(a)[3]&(a)[4]&(a)[5]) == 0xff)
|
||||
#define IS_MCAST_ADDR(a) ((a)[0]&0x01)
|
||||
#define IS_ZERO_ADDR(a) (!((a)[0] | (a)[1] | (a)[2] | (a)[3] | (a)[4] | (a)[5]))
|
||||
#define SSID_MAX_LEN (32)
|
||||
#define PASSWD_MAX_LEN (63)
|
||||
|
||||
//The next position that can be rewound.
|
||||
#define NEXT_RPOS(p,s,i) (((p)+(i)) >= (s) ? ((p)+(i)-(s)) : ((p)+(i)))
|
||||
|
||||
#define os_printf(fmt, ...) hgprintf(KERN_TSOH fmt, ##__VA_ARGS__)
|
||||
#define _os_printf(fmt, ...) hgprintf(fmt, ##__VA_ARGS__)
|
||||
|
||||
void disable_print(int8 dis);
|
||||
void disable_print_color(int8_t dis);
|
||||
void disable_print_time(int8_t dis);
|
||||
void print_with_ntp(uint8 en);
|
||||
void hgprintf(const char *fmt, ...);
|
||||
void hgvprintf(const char *fmt, va_list ap);
|
||||
void hgprintf_out(char *str, int32 len, uint8 level);
|
||||
|
||||
typedef void (*osprint_hook)(void *priv, char *msg, int len);
|
||||
void print_redirect(osprint_hook hook, void *priv, uint8 dual_out);
|
||||
|
||||
int32 hexchr2int(char c);
|
||||
int32 hex2char(char *hex);
|
||||
int32 hex2bin(char *hex, uint8 *buf, uint32 len);
|
||||
void str2mac(char *macstr, uint8 *mac);
|
||||
uint32 str2ip(char *ipstr);
|
||||
void dump_hex(char *str, uint8 *data, uint32 len, int32 newline);
|
||||
void dump_key(char *str, uint8 *key, uint32 len, uint32 sp);
|
||||
void dump_memory(char *title, uint32 *addr, uint32 len);
|
||||
void key_str(uint8 *key, uint32 key_len, char *str_buf);
|
||||
void *os_memdup(const void *ptr, uint32 len);
|
||||
int32 os_random_bytes(uint8 *data, int32 len);
|
||||
|
||||
extern int snprintf(char *str, size_t size, const char *format, ...);
|
||||
extern int sprintf(char *string, const char *format, ...);
|
||||
extern int vsprintf(char *str, const char *format, va_list arg_ptr);
|
||||
extern int vsnprintf(char *str, size_t length, const char *format, va_list arg_ptr);
|
||||
extern int printf(const char *format, ...);
|
||||
|
||||
#ifdef ERRLOG_ENABLE
|
||||
void sys_errlog_save(char *log, int32 len, uint8 level);
|
||||
void sys_errlog_flush(uint32 p1, uint32 p2, uint32 p3);
|
||||
void sys_errlog_init(int8 level, uint16 buf_size);
|
||||
void sys_errlog_dump(void);
|
||||
#else
|
||||
#define sys_errlog_save(log, len, level)
|
||||
#define sys_errlog_flush(p1, p2, p3)
|
||||
#define sys_errlog_init(level, buf_size)
|
||||
#define sys_errlog_dump()
|
||||
#endif
|
||||
|
||||
void mem_free_rec(void *addr, void *lr);
|
||||
void mem_alloc_rec(void *addr, void *lr);
|
||||
void mem_reclist_dump(void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
void *_os_malloc(int size);
|
||||
void _os_free(void *ptr);
|
||||
void *_os_zalloc(int size);
|
||||
void *_os_realloc(void *ptr, int size);
|
||||
void *_os_calloc(size_t nmemb, size_t size);
|
||||
void *_os_malloc_t(int size, const char *func, int line);
|
||||
void _os_free_t(void *ptr, const char *func, int line);
|
||||
void *_os_zalloc_t(int size, const char *func, int line);
|
||||
void *_os_realloc_t(void *ptr, int size, const char *func, int line);
|
||||
void *_os_calloc_t(int nmemb, int size, const char *func, int line);
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
void *_os_malloc_psram(int size);
|
||||
void _os_free_psram(void *ptr);
|
||||
void *_os_zalloc_psram(int size);
|
||||
void *_os_realloc_psram(void *ptr, int size);
|
||||
void *_os_calloc_psram(int nmemb, int size);
|
||||
void *_os_malloc_psram_t(int size, const char *func, int line);
|
||||
void _os_free_psram_t(void *ptr, const char *func, int line);
|
||||
void *_os_zalloc_psram_t(int size, const char *func, int line);
|
||||
void *_os_realloc_psram_t(void *ptr, int size, const char *func, int line);
|
||||
void *_os_calloc_psram_t(int nmemb, int size, const char *func, int line);
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define os_abs abs
|
||||
#define os_atoi(c) atoi((const char *)c)
|
||||
#define os_atol(c) atol((const char *)c)
|
||||
#define os_atoll(c) atoll((const char *)c)
|
||||
#define os_atof(c) atof((const char *)c)
|
||||
#define os_strcmp(s1,s2) strcmp((const char *)(s1), (const char *)(s2))
|
||||
#define os_strstr(s1,s2) strstr((const char *)(s1), (const char *)(s2))
|
||||
#define os_strchr(s,c) strchr((const char *)(s), c)
|
||||
#define os_strlen(s) strlen((const char *)(s))
|
||||
#define os_memcmp(s1,s2,n) memcmp((const void *)(s1), (const void *)(s2), n)
|
||||
#define os_strncmp(s1,s2,n) strncmp((const char *)s1, (const char *)s2, n)
|
||||
#define os_strrchr(s,c) strrchr((const char *)(s), c)
|
||||
#define os_strncasecmp(s1,s2,n) strncasecmp((const char *)(s1), (const char *)(s2), n)
|
||||
#define os_strcasecmp(s1,s2) strcasecmp((const char *)(s1), (const char *)(s2))
|
||||
#define os_srand(v) srand(v)
|
||||
#define os_rand() rand()
|
||||
#define os_sscanf sscanf
|
||||
|
||||
#ifdef MEM_TRACE
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#define os_malloc(s) _os_malloc_t(s, __FUNCTION__, __LINE__)
|
||||
#define os_free(p) do{ _os_free_t((void *)p, __FUNCTION__, __LINE__); (p)=NULL;}while(0)
|
||||
#define os_zalloc(s) _os_zalloc_t(s, __FUNCTION__, __LINE__)
|
||||
#define os_realloc(p,s) _os_realloc_t(p, s, __FUNCTION__, __LINE__)
|
||||
#define os_calloc(p,s) _os_calloc_t(p, s, __FUNCTION__, __LINE__)
|
||||
#define os_malloc_psram(s) _os_malloc_psram_t(s, __FUNCTION__, __LINE__)
|
||||
#define os_free_psram(p) do{ _os_free_psram_t((void *)p, __FUNCTION__, __LINE__); (p)=NULL;}while(0)
|
||||
#define os_zalloc_psram(s) _os_zalloc_psram_t(s, __FUNCTION__, __LINE__)
|
||||
#define os_realloc_psram(p,s) _os_realloc_psram_t(p, s, __FUNCTION__, __LINE__)
|
||||
#define os_calloc_psram(p,s) _os_calloc_psram_t(p, s, __FUNCTION__, __LINE__)
|
||||
|
||||
#define os_strcpy(d,s) _os_strcpy((char *)(d), (const char *)(s))
|
||||
#define os_strncpy(d,s,n) _os_strncpy((char *)(d), (const char *)(s), n)
|
||||
#define os_memset(s,c,n) _os_memset((void *)(s), c, n)
|
||||
#define os_memcpy(d,s,n) _os_memcpy((void *)(d), (const void *)(s), n)
|
||||
#define os_memmove(d,s,n) _os_memmove((void *)(d), (const void *)(s), n)
|
||||
#define os_sprintf(s, ...) _os_sprintf((char *)(s), __VA_ARGS__)
|
||||
#define os_vsnprintf _os_vsnprintf
|
||||
#define os_snprintf _os_snprintf
|
||||
|
||||
#else
|
||||
#define os_malloc(s) _os_malloc(s)
|
||||
#define os_free(p) do{ _os_free((void *)p); (p)=NULL;}while(0)
|
||||
#define os_zalloc(s) _os_zalloc(s)
|
||||
#define os_realloc(p,s) _os_realloc(p,s)
|
||||
#define os_calloc(p,s) _os_calloc(p, s)
|
||||
#define os_malloc_psram(s) _os_malloc_psram(s)
|
||||
#define os_free_psram(p) do{ _os_free_psram((void *)p); (p)=NULL;}while(0)
|
||||
#define os_zalloc_psram(s) _os_zalloc_psram(s)
|
||||
#define os_realloc_psram(p,s) _os_realloc_psram(p,s)
|
||||
#define os_calloc_psram(p,s) _os_calloc_psram(p, s)
|
||||
|
||||
#define os_strcpy(d,s) strcpy((char *)(d), (const char *)(s))
|
||||
#define os_strncpy(d,s,n) strncpy((char *)(d), (const char *)(s), n)
|
||||
#define os_memset(s,c,n) memset((void *)(s), c, n)
|
||||
#define os_memcpy(d,s,n) memcpy((void *)(d), (const void *)(s), n)
|
||||
#define os_memmove(d,s,n) memmove((void *)(d), (const void *)(s), n)
|
||||
#define os_sprintf sprintf
|
||||
#define os_vsnprintf vsnprintf
|
||||
#define os_snprintf snprintf
|
||||
#endif
|
||||
|
||||
|
||||
extern uint8 assert_holdup;
|
||||
extern void assert_internal(const char *__function, unsigned int __line, const char *__assertion, void *lr);
|
||||
#define ASSERT(f) if(!(f)) {\
|
||||
assert_internal(__ASSERT_FUNC, __LINE__, #f, RETURN_ADDR()); \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
104
sdk/include/osal/task.h
Normal file
104
sdk/include/osal/task.h
Normal file
@@ -0,0 +1,104 @@
|
||||
|
||||
#ifndef _OS_TASK_H_
|
||||
#define _OS_TASK_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*os_task_func_t)(void *arg);
|
||||
|
||||
enum OS_TASK_FLAGS{
|
||||
OS_TASK_FLAGS_LPRUN = BIT(31), //TASK在低功耗保活状态下需要调度运行
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
OS_TASK_PRIORITY_IDLE = 0,
|
||||
OS_TASK_PRIORITY_LOW = 0x10,
|
||||
OS_TASK_PRIORITY_BELOW_NORMAL = 0x20,
|
||||
OS_TASK_PRIORITY_NORMAL = 0x30,
|
||||
OS_TASK_PRIORITY_ABOVE_NORMAL = 0x40,
|
||||
OS_TASK_PRIORITY_HIGH = 0x50,
|
||||
OS_TASK_PRIORITY_REALTIME = 0x60,
|
||||
OS_TASK_PRIORITY_ISR = 0xFF,
|
||||
} OS_TASK_PRIORITY;
|
||||
|
||||
#define OS_TASK_INIT(name, task, func, data, prio, stack, stksize) do { \
|
||||
os_task_init((const uint8 *)name, task, (os_task_func_t)func, (uint32)data); \
|
||||
os_task_set_stack(task, stack, stksize); \
|
||||
os_task_set_priority(task, prio); \
|
||||
os_task_run(task);\
|
||||
}while(0)
|
||||
|
||||
#define OS_TASK_INIT2 OS_TASK_INIT2
|
||||
|
||||
#ifndef OS_BLKLIST
|
||||
#define OS_BLKLIST
|
||||
struct os_blklist{
|
||||
void *hdl;
|
||||
};
|
||||
typedef struct os_blklist os_blklist_t;
|
||||
#endif
|
||||
|
||||
struct os_task {
|
||||
void *hdl;
|
||||
os_task_func_t func;
|
||||
const char *name;
|
||||
uint32_t args;
|
||||
uint32_t priority:8, stack_size:20, lprun:1, rev:3;
|
||||
void *stack;
|
||||
};
|
||||
typedef struct os_task os_task_t;
|
||||
|
||||
struct os_task_info {
|
||||
uint32 id;
|
||||
const char *name;
|
||||
const char *status;
|
||||
uint32 time;
|
||||
uint32 stack;
|
||||
uint32 prio;
|
||||
uint32 arg;
|
||||
};
|
||||
|
||||
|
||||
int32 os_task_init(const uint8 *name, os_task_t *task, os_task_func_t func, uint32 data);
|
||||
int32 os_task_priority(os_task_t *task);
|
||||
int32 os_task_priority2(void *hdl);
|
||||
int32 os_task_stacksize(os_task_t *task);
|
||||
int32 os_task_stacksize2(void *hdl);
|
||||
int32 os_task_set_priority(os_task_t *task, uint32 pri);
|
||||
int32 os_task_set_stack(os_task_t *task, void *stack, int32 stack_size);
|
||||
int32 os_task_run(os_task_t *task);
|
||||
int32 os_task_stop(os_task_t *task);
|
||||
int32 os_task_del(os_task_t *task);
|
||||
int32 os_task_runtime(struct os_task_info *tsk_times, int32 count);
|
||||
void os_task_print(void);
|
||||
void *os_task_current(void);
|
||||
void *os_task_data(void *hdl);
|
||||
int32 os_task_suspend(os_task_t *task);
|
||||
int32 os_task_resume(os_task_t *task);
|
||||
void os_task_dump(void *hdl, void *stack);
|
||||
int32 os_task_count(void);
|
||||
int32 os_task_yield(void);
|
||||
|
||||
int32 os_sched_disable(void);
|
||||
int32 os_sched_enbale(void);
|
||||
void os_lpower_mode(uint8 enable);
|
||||
|
||||
os_task_t *os_task_hdl2tsk(void *hdl);
|
||||
void *os_task_create(const char *name, os_task_func_t func, void *args, uint32 prio, uint32 time, void *stack, uint32 stack_size);
|
||||
int32 os_task_destroy(void *hdl);
|
||||
|
||||
int32 os_task_suspend2(void *hdl);
|
||||
int32 os_task_resume2(void *hdl);
|
||||
|
||||
int32 os_blklist_init(os_blklist_t *blkobj);
|
||||
void os_blklist_del(os_blklist_t *blkobj);
|
||||
void os_blklist_suspend(os_blklist_t *blkobj, void *task_hdl);
|
||||
void os_blklist_resume(os_blklist_t *blkobj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
37
sdk/include/osal/time.h
Normal file
37
sdk/include/osal/time.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef __OS_TIME_H_
|
||||
#define __OS_TIME_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MICROSECONDS_PER_SECOND ( 1000000LL ) /**< Microseconds per second. */
|
||||
#define NANOSECONDS_PER_SECOND ( 1000000000LL ) /**< Nanoseconds per second. */
|
||||
#define NANOSECONDS_PER_TICK ( NANOSECONDS_PER_SECOND / OS_SYSTICK_HZ ) /**< Nanoseconds per FreeRTOS tick. */
|
||||
|
||||
uint64 os_jiffies(void); //系统开机后经过的 tick数
|
||||
uint32 os_seconds(void); //系统开机后经过的 秒数
|
||||
uint64 os_mseconds(void); //系统开机后经过的 毫秒数
|
||||
uint64 os_useconds(void); //系统开机后经过的 微秒数
|
||||
uint32 os_cpuloading(void);
|
||||
|
||||
int clock_gettime(uint32 clk_id, struct timespec *tp);
|
||||
|
||||
void os_systime(struct timespec *tm);
|
||||
int32 timespec_detal_ticks(const struct timespec *abstime, const struct timespec *curtime, uint64 *result);
|
||||
int32 timespec_to_ticks(const struct timespec *time, uint64 *result);
|
||||
void nanosec_to_timespec(int64 llSource, struct timespec *time);
|
||||
int32 timespec_add(const struct timespec *x, const struct timespec *y, struct timespec *result);
|
||||
int32 timespec_add_nanosec(const struct timespec *x, int64 llNanoseconds, struct timespec *result);
|
||||
int32 timespec_sub(const struct timespec *x, const struct timespec *y, struct timespec *result);
|
||||
int32 timespec_cmp(const struct timespec *x, const struct timespec *y);
|
||||
int32 timespec_validate(const struct timespec *time);
|
||||
|
||||
uint64 os_jiffies_to_msecs(uint64 jiff); //tick数 转换为 毫秒数
|
||||
uint64 os_msecs_to_jiffies(uint64 msec); //毫秒数 转换为 tick数
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
41
sdk/include/osal/timer.h
Normal file
41
sdk/include/osal/timer.h
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
#ifndef __OS_TIMER_H_
|
||||
#define __OS_TIMER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "osal/time.h"
|
||||
|
||||
typedef void (*os_timer_func_t)(void *arg);
|
||||
|
||||
enum OS_TIMER_MODE {
|
||||
OS_TIMER_MODE_ONCE,
|
||||
OS_TIMER_MODE_PERIODIC
|
||||
};
|
||||
|
||||
struct os_timer {
|
||||
uint32_t magic;
|
||||
void *hdl;
|
||||
os_timer_func_t cb;
|
||||
void *data;
|
||||
uint8 mode;
|
||||
uint32 interval;
|
||||
uint32_t trigger_cnt;
|
||||
uint32_t total_time;
|
||||
uint32_t max_time;
|
||||
};
|
||||
typedef struct os_timer os_timer_t;
|
||||
|
||||
int os_timer_init(os_timer_t *timer, os_timer_func_t func, enum OS_TIMER_MODE mode, void *arg);
|
||||
int os_timer_start(os_timer_t *timer, unsigned long expires);
|
||||
int os_timer_stop(os_timer_t *timer);
|
||||
int os_timer_del(os_timer_t *timer);
|
||||
int os_timer_stat(os_timer_t *timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
63
sdk/include/osal/work.h
Normal file
63
sdk/include/osal/work.h
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
#ifndef _OS_TASK_WORK_H_
|
||||
#define _OS_TASK_WORK_H_
|
||||
|
||||
#include "typesdef.h"
|
||||
#include "errno.h"
|
||||
#include "list.h"
|
||||
#include "osal/string.h"
|
||||
#include "osal/time.h"
|
||||
#include "osal/timer.h"
|
||||
#include "osal/mutex.h"
|
||||
#include "osal/task.h"
|
||||
#include "osal/semaphore.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct os_work;
|
||||
typedef int32 (*os_work_func_t)(struct os_work *work);
|
||||
typedef void (*os_run_func_t)(uint32 param1, uint32 parma2, uint32 param3);
|
||||
|
||||
struct os_work {
|
||||
struct list_head list;
|
||||
struct os_workqueue *wkq;
|
||||
uint16 running: 1, alloc : 1, delay: 1, pri: 5, init: 1, rev: 7;
|
||||
uint16 schedule;
|
||||
uint64 expired;
|
||||
uint32 runtime;
|
||||
os_work_func_t func;
|
||||
};
|
||||
|
||||
struct os_workqueue {
|
||||
char *name;
|
||||
uint16 priority: 10, init: 1, rev: 5;
|
||||
uint16 stack_size;
|
||||
os_timer_t timer;
|
||||
os_task_t task;
|
||||
struct list_head works;
|
||||
struct list_head delay_works;
|
||||
os_semaphore_t sema;
|
||||
void *run_func;
|
||||
uint64 run_jiff;
|
||||
};
|
||||
|
||||
int32 mainwkq_monitor_init(void);
|
||||
int32 os_workqueue_init(struct os_workqueue *wkq, char *name, uint16 priority, void *stack, uint16 stack_size);
|
||||
void os_work_schedule(struct os_workqueue *wkq, struct os_work *work);
|
||||
void os_work_schedule_delay(struct os_workqueue *wkq, struct os_work *work, uint32 delay_ms);
|
||||
void os_work_cancle(struct os_work *work, uint8 sync);
|
||||
void os_work_cancle2(struct os_work *work, uint8 sync); //执行此API后,必须设置init=1才能再次schedule work
|
||||
int32 os_run_func(os_run_func_t func, uint32 param1, uint32 param2, uint32 param3);
|
||||
int32 os_run_func_delay(os_run_func_t func, uint32 param1, uint32 param2, uint32 delay_ms);
|
||||
int32 os_run_work(struct os_work *work);
|
||||
int32 os_run_work_delay(struct os_work *work, uint32 delay_ms);
|
||||
int32 OS_WORK_INIT(struct os_work *work, os_work_func_t func, int32 priority);
|
||||
int32 OS_WORK_REINIT(struct os_work *work);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user