pure sdk for main

This commit is contained in:
divadiow
2025-08-27 09:51:58 +01:00
parent f0d033f1c9
commit 0571416e7c
3283 changed files with 1577720 additions and 1 deletions
+95
View File
@@ -0,0 +1,95 @@
#ifndef _OS_ATOMIC_H_
#define _OS_ATOMIC_H_
#include "typesdef.h"
#include "osal/irq.h"
typedef struct {
uint8 counter;
} atomic8_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;
}
#endif
+27
View File
@@ -0,0 +1,27 @@
#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;
};
int32 os_condv_init(struct os_condv *cond);
int32 os_condv_broadcast(struct os_condv *cond);
int32 os_condv_signal(struct os_condv *cond);
int32 os_condv_del(struct os_condv *cond);
int32 os_condv_wait(struct os_condv *cond, struct os_mutex *mutex, uint32 tmo_ms);
#ifdef __cplusplus
}
#endif
#endif
+132
View File
@@ -0,0 +1,132 @@
#ifndef _LINUX_UNALIGNED_BYTESHIFT_H
#define _LINUX_UNALIGNED_BYTESHIFT_H
static inline uint16 __get_unaligned_le16(const uint8 *p)
{
return p[0] | p[1] << 8;
}
static inline uint32 __get_unaligned_le32(const uint8 *p)
{
return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
}
static inline uint64 __get_unaligned_le64(const uint8 *p)
{
return (uint64)__get_unaligned_le32(p + 4) << 32 |
__get_unaligned_le32(p);
}
static inline void __put_unaligned_le16(uint16 val, uint8 *p)
{
*p++ = val;
*p++ = val >> 8;
}
static inline void __put_unaligned_le32(uint32 val, uint8 *p)
{
__put_unaligned_le16(val >> 16, p + 2);
__put_unaligned_le16(val, p);
}
static inline void __put_unaligned_le64(uint64 val, uint8 *p)
{
__put_unaligned_le32(val >> 32, p + 4);
__put_unaligned_le32(val, p);
}
static inline uint16 get_unaligned_le16(const void *p)
{
return __get_unaligned_le16((const uint8 *)p);
}
static inline uint32 get_unaligned_le32(const void *p)
{
return __get_unaligned_le32((const uint8 *)p);
}
static inline uint64 get_unaligned_le64(const void *p)
{
return __get_unaligned_le64((const uint8 *)p);
}
static inline void put_unaligned_le16(uint16 val, void *p)
{
__put_unaligned_le16(val, (uint8 *)p);
}
static inline void put_unaligned_le32(uint32 val, void *p)
{
__put_unaligned_le32(val, (uint8 *)p);
}
static inline void put_unaligned_le64(uint64 val, void *p)
{
__put_unaligned_le64(val, (uint8 *)p);
}
static inline uint16 __get_unaligned_be16(const uint8 *p)
{
return p[0] << 8 | p[1];
}
static inline uint32 __get_unaligned_be32(const uint8 *p)
{
return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
}
static inline uint64 __get_unaligned_be64(const uint8 *p)
{
return (uint64)__get_unaligned_be32(p) << 32 |
__get_unaligned_be32(p + 4);
}
static inline void __put_unaligned_be16(uint16 val, uint8 *p)
{
*p++ = val >> 8;
*p++ = val;
}
static inline void __put_unaligned_be32(uint32 val, uint8 *p)
{
__put_unaligned_be16(val >> 16, p);
__put_unaligned_be16(val, p + 2);
}
static inline void __put_unaligned_be64(uint64 val, uint8 *p)
{
__put_unaligned_be32(val >> 32, p);
__put_unaligned_be32(val, p + 4);
}
static inline uint16 get_unaligned_be16(const void *p)
{
return __get_unaligned_be16((const uint8 *)p);
}
static inline uint32 get_unaligned_be32(const void *p)
{
return __get_unaligned_be32((const uint8 *)p);
}
static inline uint64 get_unaligned_be64(const void *p)
{
return __get_unaligned_be64((const uint8 *)p);
}
static inline void put_unaligned_be16(uint16 val, void *p)
{
__put_unaligned_be16(val, (uint8 *)p);
}
static inline void put_unaligned_be32(uint32 val, void *p)
{
__put_unaligned_be32(val, (uint8 *)p);
}
static inline void put_unaligned_be64(uint64 val, void *p)
{
__put_unaligned_be64(val, (uint8 *)p);
}
#endif /* _LINUX_UNALIGNED_LE_BYTESHIFT_H */
+158
View File
@@ -0,0 +1,158 @@
#ifndef _CSKY_DEFS_H_
#define _CSKY_DEFS_H_
#include <assert.h>
#ifdef __cplusplus
extern "C" {
#endif
#define osWaitForever (-1)
#ifndef ASSERT
#ifdef NDEBUG
#define ASSERT(expr) ((void)0)
#else
extern uint8_t assert_holdup;
void assert_internal(const char *__function, unsigned int __line, const char *__assertion);
//void assert_call_addr(const char *__function, unsigned int __line,void* addr);
#define ASSERT(f) do { \
if(!(f)) { \
assert_internal(__ASSERT_FUNC, __LINE__, #f); \
} \
} while(0)
#endif
#endif
#ifndef NULL
#define NULL ((void *)0)
#endif
#ifndef __inline
#define __inline inline
#endif
#ifndef __weak
#define __weak __attribute__((weak))
#endif
#ifndef __alias
#define __alias(f) __attribute__((alias(#f)))
#endif
#ifndef __at_section
#define __at_section(sec) __attribute__((section(sec)))
#endif
#ifndef __used
#define __used __attribute__((used))
#endif
#ifndef __aligned
#define __aligned(n) __attribute__((aligned(n)))
#endif
#ifndef __packed
#define __packed __attribute__((packed))
#endif
#ifndef __init
//#define __init __at_section("INIT.TXT")
#define __init
#endif
#ifndef __initdata
//#define __initdata __at_section("INIT.DAT")
#define __initdata
#endif
#ifndef __initconst
//#define __initconst __at_section("INIT.RO")
#define __initconst
#endif
#ifndef __rom
//#define __rom __at_section(".rom.text")
#define __rom
#endif
#ifndef __romro
//#define __romro __at_section(".rom.ro")
#define __romro
#endif
#ifndef __ram
//#define __ram __at_section(".ram.text")
#define __ram
#endif
#ifndef __bobj
//#define __bobj __at_section(".bobj")
#define __bobj
#endif
#ifndef __dsleep_text
//#define __dsleep_text __at_section(".dsleep.text")
#define __dsleep_text
#endif
#ifndef __dsleep_date
//#define __dsleep_date __at_section(".dsleep.data")
#define __dsleep_date
#endif
#ifndef NULL
#define NULL (void *)0
#endif
#ifndef BIT
#define BIT(a) (1UL << (a))
#endif
#ifndef offsetof
#define offsetof(type, member) ((long) &((type *) 0)->member)
#endif
#ifndef container_of
#define container_of(ptr, type, member) ({ \
void *__mptr = (void *)(ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
#ifndef RETURN_ADDR
#define RETURN_ADDR() __builtin_return_address(0)
#endif
#ifndef __always_inline
#define __always_inline inline
#endif
#ifndef ASSERT_HOLDUP
#define ASSERT_HOLDUP 0
#endif
#ifndef ATCMD_ARGS_COUNT
#define ATCMD_ARGS_COUNT (16)
#endif
#ifndef ATCMD_PRINT_BUF_SIZE
#define ATCMD_PRINT_BUF_SIZE (256)
#endif
static int inline min(int a, int b)
{
return ((a)<(b)?(a):(b));
}
static int inline max(int a, int b)
{
return ((a)>(b)?(a):(b));
}
#define cpu_dcache_disable() csi_dcache_clean_invalid(); csi_dcache_disable();
#define cpu_dcache_enable() csi_dcache_enable()
#ifdef __cplusplus
}
#endif
#endif
+21
View File
@@ -0,0 +1,21 @@
#ifndef __CSKY_SLEEP_H_
#define __CSKY_SLEEP_H_
#include "k_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#define OS_MS_PERIOD_TICK (1000/OS_SYSTICK_HZ)
#define os_jiffies_to_msecs(j) ((j)*OS_MS_PERIOD_TICK)
#define os_msecs_to_jiffies(m) ((m)/OS_MS_PERIOD_TICK)
#ifdef __cplusplus
}
#endif
#endif
+136
View File
@@ -0,0 +1,136 @@
#ifndef _OS_CSKY_STDLIB_H_
#define _OS_CSKY_STDLIB_H_
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "osal/sleep.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef MEM_TRACE
#ifndef os_malloc
#define os_malloc(s) _os_malloc_t(s, __FUNCTION__, __LINE__)
#endif
#ifndef os_free
#define os_free(p) do{ _os_free_t((void *)p); (p)=NULL;}while(0)
#endif
#ifndef os_zalloc
#define os_zalloc(s) _os_zalloc_t(s, __FUNCTION__, __LINE__)
#endif
#ifndef os_realloc
#define os_realloc(p,s) _os_realloc_t(p, s, __FUNCTION__, __LINE__)
#endif
#ifndef os_calloc
#define os_calloc(p,s) _os_calloc_t(p, s, __FUNCTION__, __LINE__)
#endif
#ifndef os_malloc_psram
#define os_malloc_psram(s) _os_malloc_psram_t(s, __FUNCTION__, __LINE__)
#endif
#ifndef os_free_psram
#define os_free_psram(p) do{ _os_free_psram_t((void *)p); (p)=NULL;}while(0)
#endif
#ifndef os_zalloc_psram
#define os_zalloc_psram(s) _os_zalloc_psram_t(s, __FUNCTION__, __LINE__)
#endif
#ifndef os_realloc_psram
#define os_realloc_psram(p,s) _os_realloc_psram_t(p, s, __FUNCTION__, __LINE__)
#endif
#ifndef os_calloc_psram
#define os_calloc_psram(p,s) _os_calloc_psram_t(p, s, __FUNCTION__, __LINE__)
#endif
#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
#ifndef os_malloc
#define os_malloc(s) _os_malloc(s)
#endif
#ifndef os_free
#define os_free(p) do{ _os_free((void *)p); (p)=NULL;}while(0)
#endif
#ifndef os_zalloc
#define os_zalloc(s) _os_zalloc(s)
#endif
#ifndef os_realloc
#define os_realloc(p,s) _os_realloc(p,s)
#endif
#ifndef os_calloc
#define os_calloc(p,s) _os_calloc(p, s)
#endif
#ifndef os_malloc_psram
#define os_malloc_psram(s) _os_malloc_psram(s)
#endif
#ifndef os_free_psram
#define os_free_psram(p) do{ _os_free_psram((void *)p); (p)=NULL;}while(0)
#endif
#ifndef os_zalloc_psram
#define os_zalloc_psram(s) _os_zalloc_psram(s)
#endif
#ifndef os_realloc_psram
#define os_realloc_psram(p,s) _os_realloc_psram(p,s)
#endif
#ifndef os_calloc_psram
#define os_calloc_psram(p,s) _os_calloc_psram(p, s)
#endif
#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(s, ...) sprintf((char *)(s), __VA_ARGS__)
#define os_vsnprintf vsnprintf
#define os_snprintf snprintf
#endif
#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
#define os_htons(x) ((((x) & (uint16)0x00ffUL) << 8) | (((x) & (uint16)0xff00UL) >> 8))
#define os_ntohs(x) os_htons(x)
#define os_htonl(x) ((((x) & (uint32)0x000000ffUL) << 24) | \
(((x) & (uint32)0x0000ff00UL) << 8) | \
(((x) & (uint32)0x00ff0000UL) >> 8) | \
(((x) & (uint32)0xff000000UL) >> 24))
#define os_ntohl(x) os_htonl(x)
int strncasecmp(const char *s1, const char *s2, size_t n);
int strcasecmp(const char *s1, const char *s2);
char *os_strdup(const char *s);
uint32 os_atoh(char *str);
uint64 os_atohl(char *str);
#ifdef __cplusplus
}
#endif
#endif
+96
View File
@@ -0,0 +1,96 @@
#ifndef __CSKY_OS_TIME_H_
#define __CSKY_OS_TIME_H_
#include <time.h>
#include <sys/time.h>
#ifdef __NEWLIB__
#include <sys/timespec.h>
#if !defined(__time_t_defined) && !defined(_TIME_T_DECLARED)
typedef uint64 time_t;
#define __time_t_defined
#define _TIME_T_DECLARED
#endif
#endif
#ifndef _USECONDS_T_DECLARED
typedef unsigned long useconds_t; /* microseconds (unsigned) */
#define _USECONDS_T_DECLARED
#endif
#if !defined(_CLOCKID_T_DECLARED)
typedef unsigned long clockid_t;
#define __clockid_t_defined
#define _CLOCKID_T_DECLARED
#endif
#if !defined(__timer_t_defined) && !defined(_TIMER_T_DECLARED)
typedef unsigned long timer_t;
#define __timer_t_defined
#define _TIMER_T_DECLARED
#endif
#ifndef _SYS_TIMESPEC_H_
struct itimerspec {
struct timespec it_interval; /**< Timer period. */
struct timespec it_value; /**< Timer expiration. */
};
#endif
/*struct timeval */
/* Convenience macros for operations on timevals.
NOTE: `timercmp' does not work for >= or <=. */
#ifndef timerisset
#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
#endif
#ifndef timerclear
#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
#endif
#ifndef timercmp
#define timercmp(a, b, CMP) \
(((a)->tv_sec == (b)->tv_sec) ? \
((a)->tv_usec CMP (b)->tv_usec) : \
((a)->tv_sec CMP (b)->tv_sec))
#endif
#if 1 //see: posix/timer.c
#ifndef timeradd
#define timeradd(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
if ((result)->tv_usec >= 1000000) \
{ \
++(result)->tv_sec; \
(result)->tv_usec -= 1000000; \
} \
} while (0)
#endif
#ifndef timersub
#define timersub(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
if ((result)->tv_usec < 0) { \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
} \
} while (0)
#endif
#endif
extern int32 settimeofday(const struct timeval *tv, const struct timezone *tz);
#endif
+46
View File
@@ -0,0 +1,46 @@
#ifndef __CSKY_TYPESDEF_H_
#define __CSKY_TYPESDEF_H_
#include <stdint.h>
#include <stdbool.h>
#include "defs.h"
#ifdef __cplusplus
extern "C" {
#endif
//typedef enum { FALSE=0, TRUE=1, false=0, true=1} bool;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#ifndef _SIZE_T_DECLARED
typedef unsigned int size_t;
#define _SIZE_T_DECLARED
#endif
#ifndef _SSIZE_T_DECLARED
#if defined(__INT_MAX__) && __INT_MAX__ == 2147483647
typedef int ssize_t;
#else
typedef long ssize_t;
#endif
#define _SSIZE_T_DECLARED
#endif
typedef unsigned long ulong;
#ifdef __cplusplus
}
#endif
#include "byteshift.h"
#endif
+31
View 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;
};
int32 os_event_init(struct os_event *evt);
int32 os_event_del(struct os_event *evt);
int32 os_event_set(struct os_event *evt, uint32 flags, uint32 *rflags);
int32 os_event_clear(struct os_event *evt, uint32 flags, uint32 *rflags);
int32 os_event_get(struct os_event *evt, uint32 *rflags);
int32 os_event_wait(struct os_event *evt, uint32 flags, uint32 *rflags, uint32 mode, int32 timeout);
#ifdef __cplusplus
}
#endif
#endif
+79
View 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
+31
View File
@@ -0,0 +1,31 @@
#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;
uint32 tot_cycle;
uint32 max_cycle;
#endif
};
__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);
int32 request_irq(uint32 irq_num, irq_handle handle, void *data);
int32 release_irq(uint32 irq_num);
uint32 irq_status(void);
uint32 cpu_runtime_calc(uint8 start, uint32 val);
#ifdef __cplusplus
}
#endif
#endif
+30
View File
@@ -0,0 +1,30 @@
#ifndef _OS_MSG_QUEUE_H_
#define _OS_MSG_QUEUE_H_
#ifdef __cplusplus
extern "C" {
#endif
struct os_msgqueue {
uint32 magic;
void *hdl;
};
int32 os_msgq_init(struct os_msgqueue *msgq, int32 size);
uint32 os_msgq_get(struct os_msgqueue *msgq, int32 tmo_ms);
uint32 os_msgq_get2(struct os_msgqueue *msgq, int32 tmo_ms, int32 *err);
int32 os_msgq_put(struct os_msgqueue *msgq, uint32 data, int32 tmo_ms);
int32 os_msgq_put_head(struct os_msgqueue *msgq, uint32 data, int32 tmo_ms);
int32 os_msgq_del(struct os_msgqueue *msgq);
int32 os_msgq_cnt(struct os_msgqueue *msgq);
#ifndef OS_MSGQ_DEF
#define OS_MSGQ_DEF(name, size) struct os_msgqueue name;
#endif
#ifdef __cplusplus
}
#endif
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef _OS_MUTEX_H_
#define _OS_MUTEX_H_
#ifdef __cplusplus
extern "C" {
#endif
struct os_mutex {
uint32 magic;
void *hdl;
};
int32 os_mutex_init(struct os_mutex *mutex);
int32 os_mutex_lock(struct os_mutex *mutex, int32 tmo);
int32 os_mutex_unlock(struct os_mutex *mutex);
int32 os_mutex_del(struct os_mutex *mutex);
#ifdef __cplusplus
}
#endif
#endif
+132
View File
@@ -0,0 +1,132 @@
#ifndef _LINUX_UNALIGNED_BYTESHIFT_H
#define _LINUX_UNALIGNED_BYTESHIFT_H
static inline uint16 __get_unaligned_le16(const uint8 *p)
{
return p[0] | p[1] << 8;
}
static inline uint32 __get_unaligned_le32(const uint8 *p)
{
return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
}
static inline uint64 __get_unaligned_le64(const uint8 *p)
{
return (uint64)__get_unaligned_le32(p + 4) << 32 |
__get_unaligned_le32(p);
}
static inline void __put_unaligned_le16(uint16 val, uint8 *p)
{
*p++ = val;
*p++ = val >> 8;
}
static inline void __put_unaligned_le32(uint32 val, uint8 *p)
{
__put_unaligned_le16(val >> 16, p + 2);
__put_unaligned_le16(val, p);
}
static inline void __put_unaligned_le64(uint64 val, uint8 *p)
{
__put_unaligned_le32(val >> 32, p + 4);
__put_unaligned_le32(val, p);
}
static inline uint16 get_unaligned_le16(const void *p)
{
return __get_unaligned_le16((const uint8 *)p);
}
static inline uint32 get_unaligned_le32(const void *p)
{
return __get_unaligned_le32((const uint8 *)p);
}
static inline uint64 get_unaligned_le64(const void *p)
{
return __get_unaligned_le64((const uint8 *)p);
}
static inline void put_unaligned_le16(uint16 val, void *p)
{
__put_unaligned_le16(val, (uint8 *)p);
}
static inline void put_unaligned_le32(uint32 val, void *p)
{
__put_unaligned_le32(val, (uint8 *)p);
}
static inline void put_unaligned_le64(uint64 val, void *p)
{
__put_unaligned_le64(val, (uint8 *)p);
}
static inline uint16 __get_unaligned_be16(const uint8 *p)
{
return p[0] << 8 | p[1];
}
static inline uint32 __get_unaligned_be32(const uint8 *p)
{
return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
}
static inline uint64 __get_unaligned_be64(const uint8 *p)
{
return (uint64)__get_unaligned_be32(p) << 32 |
__get_unaligned_be32(p + 4);
}
static inline void __put_unaligned_be16(uint16 val, uint8 *p)
{
*p++ = val >> 8;
*p++ = val;
}
static inline void __put_unaligned_be32(uint32 val, uint8 *p)
{
__put_unaligned_be16(val >> 16, p);
__put_unaligned_be16(val, p + 2);
}
static inline void __put_unaligned_be64(uint64 val, uint8 *p)
{
__put_unaligned_be32(val >> 32, p);
__put_unaligned_be32(val, p + 4);
}
static inline uint16 get_unaligned_be16(const void *p)
{
return __get_unaligned_be16((const uint8 *)p);
}
static inline uint32 get_unaligned_be32(const void *p)
{
return __get_unaligned_be32((const uint8 *)p);
}
static inline uint64 get_unaligned_be64(const void *p)
{
return __get_unaligned_be64((const uint8 *)p);
}
static inline void put_unaligned_be16(uint16 val, void *p)
{
__put_unaligned_be16(val, (uint8 *)p);
}
static inline void put_unaligned_be32(uint32 val, void *p)
{
__put_unaligned_be32(val, (uint8 *)p);
}
static inline void put_unaligned_be64(uint64 val, void *p)
{
__put_unaligned_be64(val, (uint8 *)p);
}
#endif /* _LINUX_UNALIGNED_LE_BYTESHIFT_H */
+144
View File
@@ -0,0 +1,144 @@
#ifndef _OHOS_DEFS_H_
#define _OHOS_DEFS_H_
#include "los_interrupt.h"
#include "los_debug.h"
#ifdef __cplusplus
extern "C" {
#endif
#define osWaitForever (-1)
#define ASSERT LOS_ASSERT
#ifndef NULL
#define NULL ((void *)0)
#endif
#ifndef __inline
#define __inline inline
#endif
#ifndef __weak
#define __weak __attribute__((weak))
#endif
#ifndef __alias
#define __alias(f) __attribute__((alias(#f)))
#endif
#ifndef __at_section
#define __at_section(sec) __attribute__((section(sec)))
#endif
#ifndef __used
#define __used __attribute__((used))
#endif
#ifndef __aligned
#define __aligned(n) __attribute__((aligned(n)))
#endif
#ifndef __packed
#define __packed __attribute__((packed))
#endif
#ifndef __init
//#define __init __at_section("INIT.TXT")
#define __init
#endif
#ifndef __initdata
//#define __initdata __at_section("INIT.DAT")
#define __initdata
#endif
#ifndef __initconst
//#define __initconst __at_section("INIT.RO")
#define __initconst
#endif
#ifndef __rom
//#define __rom __at_section(".rom.text")
#define __rom
#endif
#ifndef __romro
//#define __romro __at_section(".rom.ro")
#define __romro
#endif
#ifndef __ram
//#define __ram __at_section(".ram.text")
#define __ram
#endif
#ifndef __bobj
//#define __bobj __at_section(".bobj")
#define __bobj
#endif
#ifndef __dsleep_text
//#define __dsleep_text __at_section(".dsleep.text")
#define __dsleep_text
#endif
#ifndef __dsleep_date
//#define __dsleep_date __at_section(".dsleep.data")
#define __dsleep_date
#endif
#ifndef NULL
#define NULL (void *)0
#endif
#ifndef BIT
#define BIT(a) (1UL << (a))
#endif
#ifndef offsetof
#define offsetof(type, member) ((long) &((type *) 0)->member)
#endif
#ifndef container_of
#define container_of(ptr, type, member) ({ \
void *__mptr = (void *)(ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
#ifndef RETURN_ADDR
#define RETURN_ADDR() __builtin_return_address(0)
#endif
#ifndef __always_inline
#define __always_inline inline
#endif
#ifndef ASSERT_HOLDUP
#define ASSERT_HOLDUP 0
#endif
#ifndef ATCMD_ARGS_COUNT
#define ATCMD_ARGS_COUNT (16)
#endif
#ifndef ATCMD_PRINT_BUF_SIZE
#define ATCMD_PRINT_BUF_SIZE (256)
#endif
static int inline min(int a, int b)
{
return ((a)<(b)?(a):(b));
}
static int inline max(int a, int b)
{
return ((a)>(b)?(a):(b));
}
#define cpu_dcache_disable() csi_dcache_clean_invalid(); csi_dcache_disable();
#define cpu_dcache_enable() csi_dcache_enable()
#ifdef __cplusplus
}
#endif
#endif
+19
View File
@@ -0,0 +1,19 @@
#ifndef __CSKY_SLEEP_H_
#define __CSKY_SLEEP_H_
#include "los_tick.h"
#ifdef __cplusplus
extern "C" {
#endif
#define os_jiffies_to_msecs(j) LOS_Tick2MS(j)
#define os_msecs_to_jiffies(m) LOS_MS2Tick(m)
#ifdef __cplusplus
}
#endif
#endif
+106
View File
@@ -0,0 +1,106 @@
#ifndef _OS_CSKY_STDLIB_H_
#define _OS_CSKY_STDLIB_H_
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "osal/sleep.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef os_malloc
#define os_malloc(s) malloc(s)
#endif
#ifndef os_free
#define os_free(p) do{ free((void *)p); (p)=NULL;}while(0)
#endif
#ifndef os_zalloc
#define os_zalloc(s) zalloc(s)
#endif
#ifndef os_realloc
#define os_realloc(p,s) realloc(p,s)
#endif
#ifndef os_calloc
#define os_calloc(p,s) calloc(p, s)
#endif
#ifndef os_malloc_psram
#define os_malloc_psram(s) _os_malloc_psram(s)
#endif
#ifndef os_free_psram
#define os_free_psram(p) do{ _os_free_psram((void *)p); (p)=NULL;}while(0)
#endif
#ifndef os_zalloc_psram
#define os_zalloc_psram(s) _os_zalloc_psram(s)
#endif
#ifndef os_realloc_psram
#define os_realloc_psram(p,s) _os_realloc_psram(p,s)
#endif
#ifndef os_calloc_psram
#define os_calloc_psram(p,s) _os_calloc_psram(p, s)
#endif
#ifdef MEM_TRACE
#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_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(s, ...) sprintf((char *)(s), __VA_ARGS__)
#define os_vsnprintf vsnprintf
#define os_snprintf snprintf
#endif
#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
#define os_htons(x) ((((x) & (uint16)0x00ffUL) << 8) | (((x) & (uint16)0xff00UL) >> 8))
#define os_ntohs(x) os_htons(x)
#define os_htonl(x) ((((x) & (uint32)0x000000ffUL) << 24) | \
(((x) & (uint32)0x0000ff00UL) << 8) | \
(((x) & (uint32)0x00ff0000UL) >> 8) | \
(((x) & (uint32)0xff000000UL) >> 24))
#define os_ntohl(x) os_htonl(x)
int strncasecmp(const char *s1, const char *s2, size_t n);
int strcasecmp(const char *s1, const char *s2);
char *os_strdup(const char *s);
uint32 os_atoh(char *str);
uint64 os_atohl(char *str);
void *zalloc(size_t size);
#ifdef __cplusplus
}
#endif
#endif
+95
View File
@@ -0,0 +1,95 @@
#ifndef __CSKY_OS_TIME_H_
#define __CSKY_OS_TIME_H_
#include <time.h>
#include <sys/time.h>
#ifdef __NEWLIB__
#include <sys/timespec.h>
#if !defined(__time_t_defined) && !defined(_TIME_T_DECLARED)
typedef uint64 time_t;
#define __time_t_defined
#define _TIME_T_DECLARED
#endif
#endif
#ifndef _USECONDS_T_DECLARED
typedef unsigned long useconds_t; /* microseconds (unsigned) */
#define _USECONDS_T_DECLARED
#endif
#if !defined(_CLOCKID_T_DECLARED)
typedef unsigned long clockid_t;
#define __clockid_t_defined
#define _CLOCKID_T_DECLARED
#endif
#if !defined(__timer_t_defined) && !defined(_TIMER_T_DECLARED)
typedef unsigned long timer_t;
#define __timer_t_defined
#define _TIMER_T_DECLARED
#endif
#ifndef _SYS_TIMESPEC_H_
struct itimerspec {
struct timespec it_interval; /**< Timer period. */
struct timespec it_value; /**< Timer expiration. */
};
#endif
/*struct timeval */
/* Convenience macros for operations on timevals.
NOTE: `timercmp' does not work for >= or <=. */
#ifndef timerisset
#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
#endif
#ifndef timerclear
#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
#endif
#ifndef timercmp
#define timercmp(a, b, CMP) \
(((a)->tv_sec == (b)->tv_sec) ? \
((a)->tv_usec CMP (b)->tv_usec) : \
((a)->tv_sec CMP (b)->tv_sec))
#endif
#if 1 //see: posix/timer.c
#ifndef timeradd
#define timeradd(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
if ((result)->tv_usec >= 1000000) \
{ \
++(result)->tv_sec; \
(result)->tv_usec -= 1000000; \
} \
} while (0)
#endif
#ifndef timersub
#define timersub(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
if ((result)->tv_usec < 0) { \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
} \
} while (0)
#endif
#endif
extern int32 settimeofday(const struct timeval *tv, const struct timezone *tz);
#endif
+46
View File
@@ -0,0 +1,46 @@
#ifndef __CSKY_TYPESDEF_H_
#define __CSKY_TYPESDEF_H_
#include <stdint.h>
#include <stdbool.h>
#include "defs.h"
#ifdef __cplusplus
extern "C" {
#endif
//typedef enum { FALSE=0, TRUE=1, false=0, true=1} bool;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#ifndef _SIZE_T_DECLARED
typedef unsigned int size_t;
#define _SIZE_T_DECLARED
#endif
#ifndef _SSIZE_T_DECLARED
#if defined(__INT_MAX__) && __INT_MAX__ == 2147483647
typedef int ssize_t;
#else
typedef long ssize_t;
#endif
#define _SSIZE_T_DECLARED
#endif
typedef unsigned long ulong;
#ifdef __cplusplus
}
#endif
#include "byteshift.h"
#endif
+24
View File
@@ -0,0 +1,24 @@
#ifndef __OS_SEMAPHORE_H
#define __OS_SEMAPHORE_H
#ifdef __cplusplus
extern "C" {
#endif
struct os_semaphore {
uint32 magic;
void *hdl;
};
int32 os_sema_init(struct os_semaphore *sem, int32 val);
int32 os_sema_del(struct os_semaphore *sem);
int32 os_sema_down(struct os_semaphore *sem, int32 tmo_ms);
int32 os_sema_up(struct os_semaphore *sem);
int32 os_sema_count(struct os_semaphore *sem);
void os_sema_eat(struct os_semaphore *sem);
#ifdef __cplusplus
}
#endif
#endif
+203
View File
@@ -0,0 +1,203 @@
#ifndef __OS_SLEEP_H_
#define __OS_SLEEP_H_
#ifdef CSKY_OS
#include "osal/csky/sleep.h"
#endif
#ifdef OHOS
#include "osal/ohos/sleep.h"
#endif
#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_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_USR_DSLEEP_CB,
DSLEEP_IOCTL_SET_WKIO_PUPD_DIS,
/*Get CMDs*/
DSLEEP_IOCTL_GET_IP_ADDR = 0x20000000,
DSLEEP_IOCTL_GET_DTIM,
};
//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_usr_dsleep_cb(priv, func) dsleep_ioctl(DSLEEP_IOCTL_SET_USR_DSLEEP_CB, (uint32)priv, (uint32)(func))
#define dsleep_set_wkio_pupd_dis(en) dsleep_ioctl(DSLEEP_IOCTL_SET_WKIO_PUPD_DIS, (uint8)en, 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)
int32 dsleep_ioctl(uint32 cmd, uint32 param1, uint32 param2);
uint64 dsleep_get_timestamp(void);
void os_sleep(int sec);
void os_sleep_ms(int msec);
extern void os_sleep_us(int us);
int usleep(useconds_t usec);
unsigned int sleep(unsigned int us);
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
+144
View File
@@ -0,0 +1,144 @@
#ifndef __OS_STRING_H__
#define __OS_STRING_H__
#include "typesdef.h"
#ifdef CSKY_OS
#include "osal/csky/string.h"
#endif
#ifdef OHOS
#include "osal/ohos/string.h"
#endif
#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 *_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);
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(size_t nmemb, size_t size, const char *func, int line);
void *_os_malloc_psram(int size);
void _os_free_psram(void *ptr);
void *_os_zalloc_psram(size_t size);
void *_os_realloc_psram(void *ptr, int size);
void *_os_calloc_psram(size_t nmemb, size_t size);
void *_os_malloc_psram_t(int size, const char *func, int line);
void _os_free_psram_t(void *ptr);
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(size_t nmemb, size_t size, const char *func, int line);
void mem_free_rec(void *addr, void *lr);
void mem_alloc_rec(void *addr, void *lr);
void mem_reclist_dump(void);
#ifdef M2M_DMA
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);
#else
#define hw_memcpy os_memcpy
#define hw_memset os_memset
#define hw_memcpy0 os_memcpy
#endif
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);
#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 "%d.%d.%d.%d"
#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)
#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 dis);
void hgprintf(const char *fmt, ...);
void hgprintf_out(char *str, int32 len, uint8 level);
typedef void (*osprint_hook)(void *priv, char *msg);
void print_redirect(osprint_hook hook, void *priv);
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_memory(char *title, uint32 *data, uint32 len);
void dump_key(char *str, uint8 *key, uint32 len, uint32 sp);
void key_str(uint8 *key, uint32 key_len, uint8 *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
#ifdef __cplusplus
}
#endif
#endif
+103
View File
@@ -0,0 +1,103 @@
#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, stksize) do { \
os_task_init((const uint8 *)name, task, (os_task_func_t)func, (uint32)data); \
os_task_set_stacksize(task, NULL, stksize); \
os_task_set_priority(task, prio); \
os_task_run(task);\
}while(0)
#define OS_TASK_INIT2(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_stacksize(task, stack, stksize); \
os_task_set_priority(task, prio); \
os_task_run(task);\
}while(0)
#ifndef OS_BLKLIST
#define OS_BLKLIST
struct os_blklist{
void *hdl;
};
#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;
};
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, struct os_task *task, os_task_func_t func, uint32 data);
int32 os_task_priority(struct os_task *task);
int32 os_task_stacksize(struct os_task *task);
int32 os_task_set_priority(struct os_task *task, uint32 priority);
int32 os_task_set_stacksize(struct os_task *task, void *stack, int32 stack_size);
int32 os_task_run(struct os_task *task);
int32 os_task_stop(struct os_task *task);
int32 os_task_del(struct os_task *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(struct os_task *task);
int32 os_task_resume(struct os_task *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);
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(struct os_blklist *blkobj);
void os_blklist_del(struct os_blklist *blkobj);
void os_blklist_suspend(struct os_blklist *blkobj, void *task_hdl);
void os_blklist_resume(struct os_blklist *blkobj);
#ifdef __cplusplus
}
#endif
#endif
+37
View File
@@ -0,0 +1,37 @@
#ifndef __OS_TIME_H_
#define __OS_TIME_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CSKY_OS
#include "osal/csky/time.h"
#endif
#ifdef OHOS
#include "osal/ohos/time.h"
#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);
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);
int clock_gettime(uint32 clk_id, struct timespec *tp);
#ifdef __cplusplus
}
#endif
#endif
+40
View File
@@ -0,0 +1,40 @@
#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;
};
int os_timer_init(struct os_timer *timer, os_timer_func_t func, enum OS_TIMER_MODE mode, void *arg);
int os_timer_start(struct os_timer *timer, unsigned long expires);
int os_timer_stop(struct os_timer *timer);
int os_timer_del(struct os_timer *timer);
int os_timer_stat(struct os_timer *timer);
#ifdef __cplusplus
}
#endif
#endif
+71
View File
@@ -0,0 +1,71 @@
#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;
uint32 running: 1, alloc : 1, delay: 1, pri: 5, init: 1, rev: 7;
uint32 schedule;
uint64 expired;
os_work_func_t func;
};
struct os_workqueue {
char *name;
uint16 priority: 10, init: 1, wait_sema: 1, rev: 4;
uint16 stack_size;
struct os_timer timer;
struct os_task task;
struct list_head works;
struct list_head delay_works;
struct os_semaphore sema;
struct os_work *runwk;
uint64 run_jiff;
};
#define OS_WORK_INIT(work, function, priority) do{\
os_memset(work, 0, sizeof(struct os_work));\
(work)->init = 1;\
(work)->func = function;\
(work)->pri = ((priority)&0x1f);\
}while (0)
#define OS_WORK_REINIT(work) do{\
(work)->init = 1;\
}while (0)
int32 mainwkq_monitor_init(void);
int32 os_workqueue_init(struct os_workqueue *wkq, char *name, uint16 priority, 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);
#endif