增加所有文件

This commit is contained in:
2025-11-07 10:05:24 +08:00
parent e248b10f07
commit 7dc1e89694
8376 changed files with 2995205 additions and 42 deletions

88
devices/include/bits.h Normal file
View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef DEV_BITS_H
#define DEV_BITS_H
#include <types.h>
#include <compiler.h>
#include <armv7-r/atomic.h>
#define BIT(x, bit) ((x) & (1UL << (bit)))
#define BIT_SHIFT(x, bit) (((x) >> (bit)) & 1)
#define BITS(x, high, low) ((x) & (((1UL<<((high)+1))-1) & ~((1UL<<(low))-1)))
#define BITS_SHIFT(x, high, low) (((x) >> (low)) & ((1UL<<((high)-(low)+1))-1))
#define BIT_SET(x, bit) (((x) & (1UL << (bit))) ? 1 : 0)
#define BITMAP_BITS_PER_WORD (sizeof(unsigned long) * 8)
#define BITMAP_NUM_WORDS(x) (((x) + BITMAP_BITS_PER_WORD - 1) / BITMAP_BITS_PER_WORD)
#define BITMAP_WORD(x) ((x) / BITMAP_BITS_PER_WORD)
#define BITMAP_BIT_IN_WORD(x) ((x) & (BITMAP_BITS_PER_WORD - 1))
#define BITMAP_BITS_PER_INT (sizeof(unsigned int) * 8)
#define BITMAP_BIT_IN_INT(x) ((x) & (BITMAP_BITS_PER_INT - 1))
#define BITMAP_INT(x) ((x) / BITMAP_BITS_PER_INT)
#define BIT_MASK(x) (((x) >= sizeof(unsigned long) * 8) ? (0UL-1) : ((1UL << (x)) - 1))
static inline int bitmap_set(unsigned long *bitmap, int bit)
{
unsigned long mask = 1UL << BITMAP_BIT_IN_INT(bit);
return arch_atomic_or(&((int *)bitmap)[BITMAP_INT(bit)], mask) & mask ? 1 : 0;
}
static inline int bitmap_clear(unsigned long *bitmap, int bit)
{
unsigned long mask = 1UL << BITMAP_BIT_IN_INT(bit);
return arch_atomic_and(&((int *)bitmap)[BITMAP_INT(bit)], ~mask) & mask ? 1:0;
}
static inline int bitmap_test(unsigned long *bitmap, int bit)
{
return BIT_SET(bitmap[BITMAP_WORD(bit)], BITMAP_BIT_IN_WORD(bit));
}
/* find first zero bit starting from LSB */
static inline unsigned long _ffz(unsigned long x)
{
/* only for gcc, TODO */
return __builtin_ffsl(~x) - 1;
}
static inline int bitmap_ffz(unsigned long *bitmap, int numbits)
{
uint32_t i;
int bit;
for (i = 0; i < BITMAP_NUM_WORDS(numbits); i++) {
if (bitmap[i] == ~0UL)
continue;
bit = i * BITMAP_BITS_PER_WORD + _ffz(bitmap[i]);
if (bit < numbits)
return bit;
return -1;
}
return -1;
}
#endif

80
devices/include/common.h Normal file
View File

@@ -0,0 +1,80 @@
/*
* common.h
*
* Copyright (c) 2020 Semidrive Semiconductor.
* All rights reserved.
*
* Description: common interface.
*
* Revision History:
* -----------------
*/
#ifndef COMMON_H
#define COMMON_H
#include "part.h"
#include "reg.h"
#include "regs_base.h"
#if (CONFIG_E3 || CONFIG_D3 || CONFIG_E3L)
#define FUSE0_OFFSET 0x1000
/* Product ID fuse index, starting from address 0x18.
* 0x18: PRODUCT_MINOR_ID
* 0x19: PRODUCT_MAJOR_ID
* 0x1A: [3:0] MASK_MINOR_ID, [7:4] MASK_MAJOR_ID
*/
#define PART_FUSE_INDEX 0x6
#define V_MAJOR_MASK 0x00f00000
#define V_MAJOR_POS 20
#define V_MINOR_MASK 0x000f0000
#define V_MINOR_POS 16
#ifndef ASSEMBLY
#if (CONFIG_E3 || CONFIG_D3)
#define IS_1P1 (sdrv_fuse_get_major_chipid() == 0 && \
sdrv_fuse_get_minor_chipid() == 1)
#define IS_1P0 (sdrv_fuse_get_major_chipid() == 0 && \
sdrv_fuse_get_minor_chipid() == 0)
#define IS_P1 (sdrv_fuse_get_minor_chipid() == 1)
#define IS_P0 (sdrv_fuse_get_minor_chipid() == 0)
#elif (CONFIG_E3L)
#define IS_1P1 (sdrv_fuse_get_major_chipid() == 0 && \
sdrv_fuse_get_minor_chipid() == 2)
#define IS_1P0 (sdrv_fuse_get_major_chipid() == 0 && \
sdrv_fuse_get_minor_chipid() <= 1)
#define IS_P1 (sdrv_fuse_get_minor_chipid() == 2)
#define IS_P0 (sdrv_fuse_get_minor_chipid() <= 1)
#endif
static inline uint32_t fuse_get_version(void)
{
return readl(APB_EFUSEC_BASE + FUSE0_OFFSET + PART_FUSE_INDEX * 4);
}
static inline uint8_t sdrv_fuse_get_minor_chipid(void)
{
uint32_t info = fuse_get_version();
uint8_t minor_id = (info & V_MINOR_MASK) >> V_MINOR_POS;
return minor_id;
}
static inline uint8_t sdrv_fuse_get_major_chipid(void)
{
uint32_t info = fuse_get_version();
uint8_t major_id = (info & V_MAJOR_MASK) >> V_MAJOR_POS;
return major_id;
}
#endif /* !ASSEMBLY */
#endif /* CONFIG_E3 || CONFIG_D3 || CONFIG_E3L */
#endif /* !COMMON_H */

271
devices/include/compiler.h Normal file
View File

@@ -0,0 +1,271 @@
/*
* Copyright (c) 2008-2013 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _INCLUDE_COMPILER_H
#define _INCLUDE_COMPILER_H
#ifndef ASSEMBLY
#if __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define __ASM __asm__
#define __INLINE inline
#define __STATIC_INLINE static inline
#define __USED __attribute__((__used__))
#define __UNUSED __attribute__((__unused__))
#define __PACKED __attribute__((packed))
#define __ALIGNED(x) __attribute__((aligned(x)))
#define __PRINTFLIKE(__fmt,__varargs) __attribute__((__format__ (__printf__, __fmt, __varargs)))
#define __SCANFLIKE(__fmt,__varargs) __attribute__((__format__ (__scanf__, __fmt, __varargs)))
#define __SECTION(x) __attribute((section(x)))
#define __PURE __attribute((pure))
#define __CONST __attribute((const))
#define __NO_RETURN __attribute__((noreturn))
#define __MALLOC __attribute__((malloc))
#define __WEAK __attribute__((weak))
#define __GNU_INLINE __attribute__((gnu_inline))
#define __GET_CALLER(x) __builtin_return_address(0)
#define __GET_FRAME(x) __builtin_frame_address(0)
#define __NAKED __attribute__((naked))
#define __ISCONSTANT(x) __builtin_constant_p(x)
#define __NO_INLINE __attribute((noinline))
#define __SRAM __NO_INLINE __SECTION(".sram.text")
#define __CONSTRUCTOR __attribute__((constructor))
#define __DESTRUCTOR __attribute__((destructor))
#define __OPTIMIZE(x) __attribute__((optimize(x)))
#define INCBIN(symname, sizename, filename, section) \
__asm__ (".section " section "; .align 4; .globl "#symname); \
__asm__ (""#symname ":\n.incbin \"" filename "\""); \
__asm__ (".section " section "; .align 1;"); \
__asm__ (""#symname "_end:"); \
__asm__ (".section " section "; .align 4; .globl "#sizename); \
__asm__ (""#sizename ": .long "#symname "_end - "#symname " - 1"); \
extern unsigned char symname[]; \
extern unsigned int sizename
#define INCFILE(symname, sizename, filename) INCBIN(symname, sizename, filename, ".rodata")
/* look for gcc 3.0 and above */
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 0)
#define __ALWAYS_INLINE __attribute__((always_inline))
#else
#define __ALWAYS_INLINE
#endif
/* look for gcc 3.1 and above */
#if !defined(__DEPRECATED) // seems to be built in in some versions of the compiler
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
#define __DEPRECATED __attribute((deprecated))
#else
#define __DEPRECATED
#endif
#endif
/* look for gcc 3.3 and above */
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
/* the may_alias attribute was introduced in gcc 3.3; before that, there
* was no way to specify aliasiang rules on a type-by-type basis */
#define __MAY_ALIAS __attribute__((may_alias))
/* nonnull was added in gcc 3.3 as well */
#define __NONNULL(x) __attribute((nonnull x))
#else
#define __MAY_ALIAS
#define __NONNULL(x)
#endif
/* look for gcc 3.4 and above */
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#define __WARN_UNUSED_RESULT __attribute((warn_unused_result))
#else
#define __WARN_UNUSED_RESULT
#endif
#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) && !defined(__clang__))
#define __EXTERNALLY_VISIBLE __attribute__((externally_visible))
#else
#define __EXTERNALLY_VISIBLE
#endif
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__)
#define __UNREACHABLE __builtin_unreachable()
#else
#define __UNREACHABLE
#endif
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#ifdef __cplusplus
#define STATIC_ASSERT(e) static_assert(e, #e)
#else
#define STATIC_ASSERT(e) _Static_assert(e, #e)
#endif
#else
#define STATIC_ASSERT(e) extern char (*ct_assert(void)) [sizeof(char[1 - 2*!(e)])]
#endif
/* compiler fence */
#define CF do { __asm__ volatile("" ::: "memory"); } while(0)
#define __WEAK_ALIAS(x) __attribute__((weak, alias(x)))
#define __ALIAS(x) __attribute__((alias(x)))
#define __LOCAL __attribute__ ((visibility("hidden")))
#define __THREAD __thread
#define __NOP __asm__ volatile("nop")
#define __BKPT __asm ("BKPT #0\n\t")
#define __ARM __attribute__((target("arm")))
#elif __ICCARM__
#include <intrinsics.h>
#include <lnk_sym.h>
#ifdef __aarch64__
static inline int __RBIT(int x) {
int ret;
asm("rbit %w0, %w1" :"=r"(ret) :"r"(x));
return ret;
}
static inline int __CLZ(int x) {
int ret;
asm("clz %w0, %w1" :"=r"(ret) :"r"(x));
return ret;
}
#endif
static inline int _bin_fls(int x) {
int i = __CLZ(x);
return 32 - i;
}
static inline int _bin_ffs(int x) {
unsigned long __t = (x);
return _bin_fls(__t & -__t);
}
static inline int _bin_ctz(int x) {
x = __RBIT(x);
return __CLZ(x);
}
#define likely(x) (x)
#define unlikely(x) (x)
#define __ASM asm
#define __INLINE inline
#define __STATIC_INLINE static inline
#define __USED __root
#define __UNUSED __attribute__((__unused__))
#define __PACKED __attribute__((packed))
#define __ALIGNED(x) __attribute__((aligned(x)))
#define __SECTION(x) __attribute__((section(x)))
#define __NO_RETURN __attribute__((__noreturn__))
#define __ALWAYS_INLINE __attribute__((always_inline))
#define __NO_INLINE __attribute__((noinline))
#define __SRAM __NO_INLINE __SECTION(".sram.text")
#define __CONSTRUCTOR __attribute__((constructor))
#define __DEPRECATED __attribute__((deprecated))
#define __offsetof(type, field) offsetof(type, field)
#define __PRINTFLIKE(__fmt,__varargs)
#define __SCANFLIKE(__fmt,__varargs)
#define __GET_CALLER(x) ((void *)__FILE__)
#define __CONST
#define __PURE
#define __MALLOC
#define __NONNULL(x)
#define __EXTERNALLY_VISIBLE
#define __UNREACHABLE
#define __builtin_clz __CLZ
#define __builtin_ffs(x) _bin_ffs(x)
#define __builtin_ffsl(x) _bin_ffs(x)
#define __builtin_ctz(x) _bin_ctz(x)
#define __builtin_clzll __CLZ
#define STATIC_ASSERT(e) _Static_assert(e, #e)
#define CF do { asm volatile("" ::: "memory"); } while(0)
#define __NOP asm("nop")
#define __BKPT __asm ("BKPT #0\n\t")
#define __ARM __arm
#else
#define likely(x) (x)
#define unlikely(x) (x)
#define __ASM
#define __INLINE
#define __STATIC_INLINE
#define __USED
#define __UNUSED
#define __PACKED
#define __ALIGNED(x)
#define __PRINTFLIKE(__fmt,__varargs)
#define __SCANFLIKE(__fmt,__varargs)
#define __SECTION(x)
#define __PURE
#define __CONST
#define __NONNULL(x)
#define __DEPRECATED
#define __WARN_UNUSED_RESULT
#define __ALWAYS_INLINE
#define __MAY_ALIAS
#define __NO_RETURN
#endif
#else
#if __GNUC__
#define FUNCTION(x) .global x; .type x,STT_FUNC; x:
#define DATA(x) .global x; .type x,STT_OBJECT; x:
#define LOCAL_FUNCTION(x) .type x,STT_FUNC; x:
#define LOCAL_DATA(x) .type x,STT_OBJECT; x:
#endif
#endif
/* TODO: add type check */
#define countof(a) (sizeof(a) / sizeof((a)[0]))
/* CPP header guards */
#ifdef __cplusplus
#define __BEGIN_CDECLS extern "C" {
#define __END_CDECLS }
#else
#define __BEGIN_CDECLS
#define __END_CDECLS
#endif
#endif

76
devices/include/debug.h Normal file
View File

@@ -0,0 +1,76 @@
/*
* debug.h
*
* Copyright (c) 2020 Semidrive Semiconductor.
* All rights reserved.
*
* Description: debug interface.
*
* Revision History:
* -----------------
*/
#ifndef _INCLUDE_DEBUG_H
#define _INCLUDE_DEBUG_H
#include <types.h>
#include <stdio.h>
#include <compiler.h>
#include <param.h>
#include <ctype.h>
/* SSDK debug level */
#define SSDK_EMERG 0 /* System is unusable */
#define SSDK_ALERT 1 /* Action must be taken immediately */
#define SSDK_CRIT 2 /* Critical conditions */
#define SSDK_ERR 3 /* Error conditions */
#define SSDK_WARNING 4 /* Warning conditions */
#define SSDK_NOTICE 5 /* Normal, but significant, condition */
#define SSDK_INFO 6 /* Informational message */
#define SSDK_DEBUG 7 /* Debug-level message */
/* SSDK printf */
#if CONFIG_DEBUG
#if CONFIG_PRINTF_LIB
#include <printf/printf.h>
#else
#define printf(x...)
#endif
#define ssdk_printf(level, x...) do { if ((level) <= CONFIG_DEBUG_LEVEL) {printf(x); } } while (0)
#define PANIC() ssdk_panic((const uint8_t *)__FILE__, (int)__LINE__)
#define ASSERT(x) do { if (!(x)) PANIC(); } while (0)
static void ssdk_panic(const uint8_t *filename, int linenum)
{
ssdk_printf(SSDK_EMERG, "Assertion failed at file:%s line: %d\r\n",
filename, linenum);
__BKPT;
for(;;);
}
/**
* @brief hex dump function
*
* @param[in] ptr: dump data address
* @param[in] len: dump data length
*/
void hexdump(const void *ptr, size_t len);
/**
* @brief hex dump8 function with display address
*
* @param[in] ptr: ptr dump data address
* @param[in] len: len dump data length
* @param[in] addr: disp_addr display address
*/
void hexdump8_ex(const void *ptr, size_t len, uint64_t addr);
#else
#define ssdk_printf(level, x...)
#define PANIC()
#define ASSERT(x)
#define hexdump(ptr, len)
#define hexdump8_ex(ptr, len, disp_addr)
#endif
#endif

189
devices/include/errno.h Normal file
View File

@@ -0,0 +1,189 @@
/*
* errno.h
*
* Copyright (c) 2021 Semidrive Semiconductor.
* All rights reserved.
*
* Description: errno defines.
*
* Revision History:
* -----------------
*/
#ifndef DEV_ERRNO_H
#define DEV_ERRNO_H
#if defined(__GNUC__) && !defined(__SES_ARM)
#include <sys/errno.h>
#else
#if defined(__ICCARM__)
#include <c/errno.h>
#define ERR_BASE _NERR
#else
#define ERR_BASE 0
#endif
#if defined(__SES_ARM)
#include "__SEGGER_RTL.h"
#define errno (*__SEGGER_RTL_X_errno_addr())
#endif
#define EPERM (ERR_BASE + 1)
#define ENOENT (ERR_BASE + 2)
#define ESRCH (ERR_BASE + 3)
#define EINTR (ERR_BASE + 4)
#define EIO (ERR_BASE + 5)
#define ENXIO (ERR_BASE + 6)
#define E2BIG (ERR_BASE + 7)
#define ENOEXEC (ERR_BASE + 8)
#define EBADF (ERR_BASE + 9)
#define ECHILD (ERR_BASE + 10)
#define EAGAIN (ERR_BASE + 11)
#ifndef ENOMEM
#define ENOMEM (ERR_BASE + 12)
#endif
#define EACCES (ERR_BASE + 13)
#define EFAULT (ERR_BASE + 14)
#define ENOTBLK (ERR_BASE + 15)
#define EBUSY (ERR_BASE + 16)
#define EEXIST (ERR_BASE + 17)
#define EXDEV (ERR_BASE + 18)
#define ENODEV (ERR_BASE + 19)
#define ENOTDIR (ERR_BASE + 20)
#define EISDIR (ERR_BASE + 21)
#ifndef EINVAL
#define EINVAL (ERR_BASE + 22)
#endif
#define ENFILE (ERR_BASE + 23)
#define EMFILE (ERR_BASE + 24)
#define ENOTTY (ERR_BASE + 25)
#define ETXTBSY (ERR_BASE + 26)
#define EFBIG (ERR_BASE + 27)
#define ENOSPC (ERR_BASE + 28)
#define ESPIPE (ERR_BASE + 29)
#define EROFS (ERR_BASE + 30)
#define EMLINK (ERR_BASE + 31)
#define EPIPE (ERR_BASE + 32)
#ifndef EDOM
#define EDOM (ERR_BASE + 33)
#endif
#ifndef ERANGE
#define ERANGE (ERR_BASE + 34)
#endif
#define EDEADLK (ERR_BASE + 35)
#define ENAMETOOLONG (ERR_BASE + 36)
#define ENOLCK (ERR_BASE + 37)
#define ENOSYS (ERR_BASE + 38)
#define ENOTEMPTY (ERR_BASE + 39)
#define ELOOP (ERR_BASE + 40)
#define EWOULDBLOCK EAGAIN
#define ENOMSG (ERR_BASE + 42)
#define EIDRM (ERR_BASE + 43)
#define ECHRNG (ERR_BASE + 44)
#define EL2NSYNC (ERR_BASE + 45)
#define EL3HLT (ERR_BASE + 46)
#define EL3RST (ERR_BASE + 47)
#define ELNRNG (ERR_BASE + 48)
#define EUNATCH (ERR_BASE + 49)
#define ENOCSI (ERR_BASE + 50)
#define EL2HLT (ERR_BASE + 51)
#define EBADE (ERR_BASE + 52)
#define EBADR (ERR_BASE + 53)
#define EXFULL (ERR_BASE + 54)
#define ENOANO (ERR_BASE + 55)
#define EBADRQC (ERR_BASE + 56)
#define EBADSLT (ERR_BASE + 57)
#define EDEADLOCK EDEADLK
#define EBFONT (ERR_BASE + 59)
#define ENOSTR (ERR_BASE + 60)
#define ENODATA (ERR_BASE + 61)
#define ETIME (ERR_BASE + 62)
#define ENOSR (ERR_BASE + 63)
#define ENONET (ERR_BASE + 64)
#define ENOPKG (ERR_BASE + 65)
#define EREMOTE (ERR_BASE + 66)
#define ENOLINK (ERR_BASE + 67)
#define EADV (ERR_BASE + 68)
#define ESRMNT (ERR_BASE + 69)
#define ECOMM (ERR_BASE + 70)
#define EPROTO (ERR_BASE + 71)
#define EMULTIHOP (ERR_BASE + 72)
#define EDOTDOT (ERR_BASE + 73)
#define EBADMSG (ERR_BASE + 74)
#define EOVERFLOW (ERR_BASE + 75)
#define ENOTUNIQ (ERR_BASE + 76)
#define EBADFD (ERR_BASE + 77)
#define EREMCHG (ERR_BASE + 78)
#define ELIBACC (ERR_BASE + 79)
#define ELIBBAD (ERR_BASE + 80)
#define ELIBSCN (ERR_BASE + 81)
#define ELIBMAX (ERR_BASE + 82)
#define ELIBEXEC (ERR_BASE + 83)
#ifndef EILSEQ
#define EILSEQ (ERR_BASE + 84)
#endif
#define ERESTART (ERR_BASE + 85)
#define ESTRPIPE (ERR_BASE + 86)
#define EUSERS (ERR_BASE + 87)
#define ENOTSOCK (ERR_BASE + 88)
#define EDESTADDRREQ (ERR_BASE + 89)
#define EMSGSIZE (ERR_BASE + 90)
#define EPROTOTYPE (ERR_BASE + 91)
#define ENOPROTOOPT (ERR_BASE + 92)
#define EPROTONOSUPPORT (ERR_BASE + 93)
#define ESOCKTNOSUPPORT (ERR_BASE + 94)
#define EOPNOTSUPP (ERR_BASE + 95)
#define ENOTSUP EOPNOTSUPP
#define EPFNOSUPPORT (ERR_BASE + 96)
#define EAFNOSUPPORT (ERR_BASE + 97)
#define EADDRINUSE (ERR_BASE + 98)
#define EADDRNOTAVAIL (ERR_BASE + 99)
#define ENETDOWN (ERR_BASE + 100)
#define ENETUNREACH (ERR_BASE + 101)
#define ENETRESET (ERR_BASE + 102)
#define ECONNABORTED (ERR_BASE + 103)
#define ECONNRESET (ERR_BASE + 104)
#define ENOBUFS (ERR_BASE + 105)
#define EISCONN (ERR_BASE + 106)
#define ENOTCONN (ERR_BASE + 107)
#define ESHUTDOWN (ERR_BASE + 108)
#define ETOOMANYREFS (ERR_BASE + 109)
#define ETIMEDOUT (ERR_BASE + 110)
#define ECONNREFUSED (ERR_BASE + 111)
#define EHOSTDOWN (ERR_BASE + 112)
#define EHOSTUNREACH (ERR_BASE + 113)
#define EALREADY (ERR_BASE + 114)
#define EINPROGRESS (ERR_BASE + 115)
#define ESTALE (ERR_BASE + 116)
#define EUCLEAN (ERR_BASE + 117)
#define ENOTNAM (ERR_BASE + 118)
#define ENAVAIL (ERR_BASE + 119)
#define EISNAM (ERR_BASE + 120)
#define EREMOTEIO (ERR_BASE + 121)
#define EDQUOT (ERR_BASE + 122)
#define ENOMEDIUM (ERR_BASE + 123)
#define EMEDIUMTYPE (ERR_BASE + 124)
#define ECANCELED (ERR_BASE + 125)
#define ENOKEY (ERR_BASE + 126)
#define EKEYEXPIRED (ERR_BASE + 127)
#define EKEYREVOKED (ERR_BASE + 128)
#define EKEYREJECTED (ERR_BASE + 129)
#define EOWNERDEAD (ERR_BASE + 130)
#define ENOTRECOVERABLE (ERR_BASE + 131)
#define ERFKILL (ERR_BASE + 132)
#define EHWPOISON (ERR_BASE + 133)
#endif
#endif /* DEV_ERRNO_H */

288
devices/include/lib/list.h Normal file
View File

@@ -0,0 +1,288 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef INCLUDE_LIST_H
#define INCLUDE_LIST_H
#include <compiler.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
__BEGIN_CDECLS;
#define containerof(ptr, type, member) \
((type *)((uintptr_t)(ptr) - offsetof(type, member)))
struct list_node {
struct list_node *prev;
struct list_node *next;
};
#define LIST_INITIAL_VALUE(list) { &(list), &(list) }
#define LIST_INITIAL_CLEARED_VALUE { NULL, NULL }
static inline void list_initialize(struct list_node *list)
{
list->prev = list->next = list;
}
static inline void list_clear_node(struct list_node *item)
{
item->prev = item->next = 0;
}
static inline bool list_in_list(struct list_node *item)
{
if (item->prev == 0 && item->next == 0)
return false;
else
return true;
}
static inline void list_add_head(struct list_node *list, struct list_node *item)
{
item->next = list->next;
item->prev = list;
list->next->prev = item;
list->next = item;
}
#define list_add_after(entry, new_entry) list_add_head(entry, new_entry)
static inline void list_add_tail(struct list_node *list, struct list_node *item)
{
item->prev = list->prev;
item->next = list;
list->prev->next = item;
list->prev = item;
}
#define list_add_before(entry, new_entry) list_add_tail(entry, new_entry)
static inline void list_delete(struct list_node *item)
{
item->next->prev = item->prev;
item->prev->next = item->next;
item->prev = item->next = 0;
}
static inline struct list_node *list_remove_head(struct list_node *list)
{
if (list->next != list) {
struct list_node *item = list->next;
list_delete(item);
return item;
} else {
return NULL;
}
}
#define list_remove_head_type(list, type, element) ({\
struct list_node *__nod = list_remove_head(list);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node *list_remove_tail(struct list_node *list)
{
if (list->prev != list) {
struct list_node *item = list->prev;
list_delete(item);
return item;
} else {
return NULL;
}
}
#define list_remove_tail_type(list, type, element) ({\
struct list_node *__nod = list_remove_tail(list);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node *list_peek_head(struct list_node *list)
{
if (list->next != list) {
return list->next;
} else {
return NULL;
}
}
#define list_peek_head_type(list, type, element) ({\
struct list_node *__nod = list_peek_head(list);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node *list_peek_tail(struct list_node *list)
{
if (list->prev != list) {
return list->prev;
} else {
return NULL;
}
}
#define list_peek_tail_type(list, type, element) ({\
struct list_node *__nod = list_peek_tail(list);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node *list_prev(struct list_node *list, struct list_node *item)
{
if (item->prev != list)
return item->prev;
else
return NULL;
}
#define list_prev_type(list, item, type, element) ({\
struct list_node *__nod = list_prev(list, item);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node *list_prev_wrap(struct list_node *list, struct list_node *item)
{
if (item->prev != list)
return item->prev;
else if (item->prev->prev != list)
return item->prev->prev;
else
return NULL;
}
#define list_prev_wrap_type(list, item, type, element) ({\
struct list_node *__nod = list_prev_wrap(list, item);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node *list_next(struct list_node *list, struct list_node *item)
{
if (item->next != list)
return item->next;
else
return NULL;
}
#define list_next_type(list, item, type, element) ({\
struct list_node *__nod = list_next(list, item);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node *list_next_wrap(struct list_node *list, struct list_node *item)
{
if (item->next != list)
return item->next;
else if (item->next->next != list)
return item->next->next;
else
return NULL;
}
#define list_next_wrap_type(list, item, type, element) ({\
struct list_node *__nod = list_next_wrap(list, item);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
// iterates over the list, node should be struct list_node*
#define list_for_every(list, node) \
for(node = (list)->next; node != (list); node = node->next)
// iterates over the list in a safe way for deletion of current node
// node and temp_node should be struct list_node*
#define list_for_every_safe(list, node, temp_node) \
for(node = (list)->next, temp_node = (node)->next;\
node != (list);\
node = temp_node, temp_node = (node)->next)
// iterates over the list, entry should be the container structure type *
#define list_for_every_entry(list, entry, type, member) \
for((entry) = containerof((list)->next, type, member);\
&(entry)->member != (list);\
(entry) = containerof((entry)->member.next, type, member))
// iterates over the list in a safe way for deletion of current node
// entry and temp_entry should be the container structure type *
#define list_for_every_entry_safe(list, entry, temp_entry, type, member) \
for(entry = containerof((list)->next, type, member),\
temp_entry = containerof((entry)->member.next, type, member);\
&(entry)->member != (list);\
entry = temp_entry, temp_entry = containerof((temp_entry)->member.next, type, member))
static inline bool list_is_empty(struct list_node *list)
{
return (list->next == list) ? true : false;
}
static inline size_t list_length(struct list_node *list)
{
size_t cnt = 0;
struct list_node *node = list;
list_for_every(list, node) {
cnt++;
}
return cnt;
}
__END_CDECLS;
#endif

39
devices/include/lnk_sym.h Normal file
View File

@@ -0,0 +1,39 @@
/**
* @file lnk_sym.h
* @brief IAR link symbols.
*
* @copyright Copyright (c) 2021 Semidrive Semiconductor.
* All rights reserved.
*/
#ifndef DEV_LNK_SYM_H__
#define DEV_LNK_SYM_H__
#include <types.h>
#ifdef __ICCARM__
#define __commands_start COMMANDS$$Base
#define __commands_end COMMANDS$$Limit
#define _heap_start HEAP$$Base
#define _heap_end HEAP$$Limit
#define __except_stack_start CSTACK$$Base
#define __cstack_end CSTACK$$Limit
#define __load_data_start DATA_init$$Base
#define __data_start DATA$$Base
#define __data_end DATA$$Limit
#define __data_start_rom DATA$$Base
#define __data_end DATA$$Limit
#define __bss_start BSS$$Base
#define __bss_end BSS$$Limit
#endif /* __ICCARM__ */
#if !defined(ASSEMBLY)
extern uint32_t *__except_stack_start;
extern uint32_t *__cstack_end;
#endif
#endif /* DEV_LNK_SYM_H__ */

58
devices/include/param.h Normal file
View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2008-2014 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef DEV_PARAM_H_
#define DEV_PARAM_H_
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef ROUNDUP
#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
#endif
#ifndef ROUNDDOWN
#define ROUNDDOWN(a, b) ((a) & ~((b)-1))
#endif
#ifndef DIV_ROUND_UP
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#endif
#ifndef ALIGN
#define ALIGN(a, b) ROUNDUP(a, b)
#endif
#ifndef IS_ALIGNED
#define IS_ALIGNED(a, b) (!(((uintptr_t)(a)) & (((uintptr_t)(b))-1)))
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif
#endif

76
devices/include/reg.h Normal file
View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef DEV_REG_H_
#define DEV_REG_H_
#include <stdint.h>
#define REG64(addr) ((volatile uint64_t *)(uintptr_t)(addr))
#define REG32(addr) ((volatile uint32_t *)(uintptr_t)(addr))
#define REG16(addr) ((volatile uint16_t *)(uintptr_t)(addr))
#define REG8(addr) ((volatile uint8_t *)(uintptr_t)(addr))
#define RMWREG64(addr, startbit, width, val) *REG64(addr) = (*REG64(addr) & ~((((uint64_t)1u<<(width)) - 1u) << (startbit))) | ((uint64_t)(val) << (startbit))
#define RMWREG32(addr, startbit, width, val) *REG32(addr) = (*REG32(addr) & ~((((uint32_t)1u<<(width)) - 1u) << (startbit))) | ((uint32_t)(val) << (startbit))
#define RMWREG16(addr, startbit, width, val) *REG16(addr) = (*REG16(addr) & ~((((uint16_t)1u<<(width)) - 1u) << (startbit))) | ((uint16_t)(val) << (startbit))
#define RMWREG8(addr, startbit, width, val) *REG8(addr) = (*REG8(addr) & ~((((uint8_t)1u<<(width)) - 1u) << (startbit))) | ((uint8_t)(val) << (startbit))
#define writeq(v, a) (*REG64(a) = (v))
#define readq(a) (*REG64(a))
#define writel(v, a) (*REG32(a) = (v))
#define readl(a) (*REG32(a))
#define writew(v, a) (*REG16(a) = (v))
#define readw(a) (*REG16(a))
#define writeb(v, a) (*REG8(a) = (v))
#define readb(a) (*REG8(a))
static inline
void clrbits_32(volatile uint32_t *addr, uint32_t clear)
{
*addr &= ~clear;
}
static inline
void setbits_32(volatile uint32_t *addr, uint32_t set)
{
*addr |= set;
}
static inline
void clrsetbits_32(volatile uint32_t *addr, uint32_t clear, uint32_t set)
{
uint32_t temp;
temp = *addr;
temp &= ~clear;
temp |= set;
*addr = temp;
}
#define CLRBITS_32(addr, clear) clrbits_32(REG32(addr), clear)
#define SETBITS_32(addr, set) setbits_32(REG32(addr), set)
#define CLRSETBITS_32(addr, clear, set) clrsetbits_32(REG32(addr), clear, set)
#endif

View File

@@ -0,0 +1,93 @@
/**
* @brief spinlock.h
*
* Copyright (c) 2020 Semidrive Semiconductor.
* All rights reserved.
*
* Description: spinlock interface.
*
* Revision History:
* -----------------
*/
#ifndef _INCLUDE_SPINLOCK_H_
#define _INCLUDE_SPINLOCK_H_
#ifndef ASSEMBLY
#include <armv7-r/spinlock.h>
#include <armv7-r/irq.h>
__BEGIN_CDECLS
/**
* @brief spinlock init.
*
* @param[in] spinlock spinlock address.
*/
static inline void spin_lock_init(spin_lock_t *spinlock)
{
arch_spin_lock_init(spinlock);
}
/**
* @brief spin lock.
*
* @param[in] spinlock spinlock address.
*/
static inline void spin_lock(spin_lock_t *spinlock)
{
arch_spin_lock(spinlock);
}
/**
* @brief spin trylock.
*
* @param[in] spinlock spinlock address.
* @return try lock result.
*/
static inline int spin_trylock(spin_lock_t *spinlock)
{
return arch_spin_trylock(spinlock);
}
/**
* @brief spin unlock.
*
* @param[in] spinlock spinlock address.
*/
static inline void spin_unlock(spin_lock_t *spinlock)
{
arch_spin_unlock(spinlock);
}
/**
* @brief spin lock with irq save
*
* @param[in] spinlock spinlock address.
* @return old irq state.
*/
static inline irq_state_t spin_lock_irqsave(spin_lock_t *spinlock)
{
irq_state_t state = arch_irq_save();
spin_lock(spinlock);
return state;
}
/**
* @brief spin unlock with irq restore
*
* @param[in] spinlock spinlock address.
* @param[in] state old irq state.
*/
static inline void spin_unlock_irqrestore(spin_lock_t *spinlock, irq_state_t state)
{
spin_unlock(spinlock);
arch_irq_restore(state);
}
__END_CDECLS
#endif
#endif

29
devices/include/types.h Normal file
View File

@@ -0,0 +1,29 @@
/*
* types.h
*
* Copyright (c) 2020 Semidrive Semiconductor.
* All rights reserved.
*
* Description: types interface.
*
* Revision History:
* -----------------
*/
#ifndef DEV_TYPES_H
#define DEV_TYPES_H
#ifndef ASSEMBLY
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
typedef uintptr_t addr_t;
typedef uintptr_t vaddr_t;
typedef uintptr_t paddr_t;
#endif
#endif