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
+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