create format rule and reformat

reformat
GongT 2019-05-31 20:30:41 +08:00
parent e2dd551e09
commit 804a11f92d
68 changed files with 7997 additions and 8571 deletions

42
.clang-format Normal file
View File

@ -0,0 +1,42 @@
---
Language: Cpp
BasedOnStyle: LLVM
UseTab: Never
#AlignConsecutiveMacros: true
AlignTrailingComments: true
IndentWidth: 4
TabWidth: 4
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 0
AccessModifierOffset: -4
BreakBeforeBraces: Custom
IncludeCategories:
- Regex: '^<'
Priority: 1
- Regex: '.*'
Priority: 50
- Regex: '^"'
Priority: 99
IncludeIsMainRegex: "^$"
IndentCaseLabels: true
SpaceBeforeParens: Never
BraceWrapping:
# AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
...

View File

@ -34,4 +34,3 @@ void __attribute__((weak)) _fini(void)
* These don't have to do anything since we use init_array/fini_array.
*/
}

View File

@ -21,10 +21,10 @@
#include "fpioa.h"
#include "platform.h"
#include "plic.h"
#include "syscalls.h"
#include "sysctl.h"
#include "syslog.h"
#include "uart.h"
#include "syscalls.h"
extern volatile uint64_t g_wake_up[2];
@ -37,7 +37,8 @@ extern char _heap_end[];
void thread_entry(int core_id)
{
while (!atomic_read(&g_wake_up[core_id]));
while(!atomic_read(&g_wake_up[core_id]))
;
}
void core_enable(int core_id)
@ -96,8 +97,7 @@ void _init_bsp(int core_id, int number_of_cores)
core1_instance.callback = NULL;
core1_instance.ctx = NULL;
ret = os_entry(core_id, number_of_cores, main);
}
else
} else
{
plic_init();
sysctl_enable_irq();
@ -114,4 +114,3 @@ int pthread_setcancelstate(int __state, int *__oldstate)
{
return 0;
}

View File

@ -20,7 +20,6 @@
extern "C" {
#endif
#define SPINLOCK_INIT \
{ \
0 \
@ -33,7 +32,6 @@ extern "C" {
.core = -1 \
}
/* Defination of memory barrier macro */
#define mb() \
{ \
@ -64,7 +62,6 @@ typedef struct _semaphore
int waiting;
} semaphore_t;
typedef struct _corelock
{
spinlock_t lock;
@ -82,7 +79,8 @@ static inline int spinlock_trylock(spinlock_t *lock)
static inline void spinlock_lock(spinlock_t *lock)
{
while (spinlock_trylock(lock));
while(spinlock_trylock(lock))
;
}
static inline void spinlock_unlock(spinlock_t *lock)
@ -150,14 +148,12 @@ static inline int corelock_trylock(corelock_t *lock)
lock->count++;
lock->core = core;
res = 0;
}
else if (lock->core == core)
} else if(lock->core == core)
{
/* Same core get lock */
lock->count++;
res = 0;
}
else
} else
{
/* Different core get lock */
res = -1;
@ -180,13 +176,11 @@ static inline void corelock_lock(corelock_t *lock)
/* First time get lock */
lock->count++;
lock->core = core;
}
else if (lock->core == core)
} else if(lock->core == core)
{
/* Same core get lock */
lock->count++;
}
else
} else
{
/* Different core get lock */
spinlock_unlock(&lock->lock);
@ -218,8 +212,7 @@ static inline void corelock_unlock(corelock_t *lock)
lock->core = -1;
lock->count = 0;
}
}
else
} else
{
/* Different core release lock */
spinlock_unlock(&lock->lock);
@ -241,4 +234,3 @@ static inline void corelock_unlock(corelock_t *lock)
#endif
#endif /* _BSP_ATOMIC_H */

View File

@ -1,9 +1,9 @@
#ifndef _KENDRYTE_BSP_H
#define _KENDRYTE_BSP_H
#include "atomic.h"
#include "entry.h"
#include "sleep.h"
#include "encoding.h"
#include "syscalls.h"
#include "entry.h"
#include "printf.h"
#include "sleep.h"
#include "syscalls.h"
#endif

View File

@ -138,4 +138,3 @@ dump_core(const char *reason, uintptr_t cause, uintptr_t epc, uintptr_t regs[32]
#endif
#endif /* _BSP_DUMP_H */

View File

@ -1323,4 +1323,3 @@ DECLARE_CAUSE("supervisor_ecall", CAUSE_SUPERVISOR_ECALL)
DECLARE_CAUSE("hypervisor_ecall", CAUSE_HYPERVISOR_ECALL)
DECLARE_CAUSE("machine_ecall", CAUSE_MACHINE_ECALL)
#endif

View File

@ -78,4 +78,3 @@ static inline void init_tls(void)
#endif
#endif /* _BSP_ENTRY_H */

View File

@ -44,4 +44,3 @@ extern "C" {
#endif
#endif /* _BSP_INTERRUPT_H */

View File

@ -96,4 +96,3 @@ extern "C" {
#endif
#endif /* _BSP_PLATFORM_H */

View File

@ -194,7 +194,7 @@ namespace std
{
return ::tfp_printf(std::forward<Args>(args)...);
}
}
} // namespace std
#endif
#endif
#endif
@ -206,4 +206,3 @@ int printk(const char *format, ...) _TFP_SPECIFY_PRINTF_FMT(1, 2);
#endif
#endif /* _BSP_PRINTF_H */

View File

@ -16,8 +16,8 @@
#ifndef _BSP_SLEEP_H
#define _BSP_SLEEP_H
#include "encoding.h"
#include "clint.h"
#include "encoding.h"
#include "syscalls.h"
#ifdef __cplusplus
@ -33,4 +33,3 @@ unsigned int sleep(unsigned int seconds);
#endif
#endif /* _BSP_SLEEP_H */

View File

@ -88,4 +88,3 @@ size_t get_free_heap_size(void);
#endif
#endif /* _BSP_SYSCALLS_H */

View File

@ -16,7 +16,6 @@
#ifndef _BSP_UTIL_H
#define _BSP_UTIL_H
#include <stdint.h>
#if defined(__riscv)
#include "encoding.h"
@ -55,15 +54,9 @@ extern "C" {
#define PREALLOCATE 0
#endif
#define static_assert(cond) \
{ \
switch (0) \
{ \
case 0: \
case !!(long)(cond):; \
} \
}
#define static_assert(cond){ \
switch(0){ \
case 0 : case !!(long)(cond):; } }
#define stringify_1(s) #s
#define stringify(s) stringify_1(s)
@ -78,7 +71,6 @@ extern "C" {
stringify(code), _c, _c / iter, 10 * _c / iter % 10, _c / _i, 10 * _c / _i % 10); \
} while(0)
/**
* Set SET_STATS to 1 if you want to carve out the piece that actually
* does the computation.
@ -86,12 +78,13 @@ extern "C" {
#if HOST_DEBUG
#include <stdio.h>
static void setStats(int enable) {}
static void setStats(int enable)
{
}
#else
extern void setStats(int enable);
#endif
static void printArray(const char name[], int n, const int arr[])
{
#if HOST_DEBUG
@ -167,8 +160,7 @@ static void __attribute__((noinline)) barrier(int ncores)
{
count = 0;
sense = threadsense;
}
else
} else
{
while(sense != threadsense)
;
@ -184,7 +176,6 @@ static uint64_t lfsr(uint64_t x)
return (x >> 1) | (bit << 62);
}
#if defined(__GNUC__)
#pragma GCC diagnostic warning "-Wunused-parameter"
#pragma GCC diagnostic warning "-Wunused-function"
@ -195,4 +186,3 @@ static uint64_t lfsr(uint64_t x)
#endif
#endif /* _BSP_UTIL_H */

View File

@ -17,8 +17,8 @@
#include <stdint.h>
#include <stdlib.h>
#include "interrupt.h"
#include "dump.h"
#include "interrupt.h"
#include "syscalls.h"
#include "syslog.h"
@ -63,4 +63,3 @@ handle_irq(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uintptr_t fregs[3
#endif
return irq_table[cause & CAUSE_MACHINE_IRQ_REASON_MASK](cause, epc, regs, fregs);
}

View File

@ -1,5 +1,5 @@
#include <sys/lock.h>
#include <stdlib.h>
#include <sys/lock.h>
#include "bsp.h"
#define LOCK_MAX_NUM (1024)
@ -37,7 +37,8 @@ static inline long lock_trylock(_lock_t *lock)
static inline void lock_lock(_lock_t *lock)
{
while (lock_trylock(lock));
while(lock_trylock(lock))
;
}
static inline void lock_unlock(_lock_t *lock)
@ -77,8 +78,7 @@ static reculock_t *reculock_init(_lock_t *lock)
{
return NULL;
}
*v_reculock = (reculock_t)
{
*v_reculock = (reculock_t){
.lock = lock,
.counter = 0,
.core = 0,
@ -92,8 +92,7 @@ static void reculock_deinit(_lock_t *lock)
reculock_t *v_reculock = get_reculock(lock);
if(v_reculock)
{
*v_reculock = (reculock_t)
{
*v_reculock = (reculock_t){
.lock = NULL,
.counter = 0,
.core = 0,
@ -131,14 +130,12 @@ static inline int reculock_trylock(_lock_t *lock)
v_reculock->counter++;
v_reculock->core = core;
res = 0;
}
else if (v_reculock->core == core)
} else if(v_reculock->core == core)
{
/* Same core get lock */
v_reculock->counter++;
res = 0;
}
else
} else
{
/* Different core get lock */
res = -1;
@ -172,13 +169,11 @@ static inline void reculock_lock(_lock_t *lock)
/* First time get lock */
v_reculock->counter++;
v_reculock->core = core;
}
else if (v_reculock->core == core)
} else if(v_reculock->core == core)
{
/* Same core get lock */
v_reculock->counter++;
}
else
} else
{
/* Different core get lock */
lock_unlock(lock);
@ -217,8 +212,7 @@ static inline void reculock_unlock(_lock_t *lock)
v_reculock->counter = 0;
v_reculock->lock = NULL;
}
}
else
} else
{
/* Different core release lock */
lock_unlock(lock);
@ -276,4 +270,3 @@ void _lock_release_recursive(_lock_t *lock)
{
reculock_unlock(lock);
}

View File

@ -28,8 +28,8 @@
*/
#include <stddef.h>
#include "printf.h"
#include "atomic.h"
#include "printf.h"
#include "syscalls.h"
/**
@ -72,21 +72,17 @@
#define _TFP_GCC_NO_INLINE_
#endif
#if defined(PRINTF_LONG_SUPPORT)
#define BF_MAX 20 /* long = 64b on some architectures */
#else
#define BF_MAX 10 /* int = 32b on some architectures */
#endif
#define IS_DIGIT(x) ((x) >= '0' && (x) <= '9')
/* Clear unused warnings for actually unused variables */
#define UNUSED(x) (void)(x)
/**
* Implementation
*/
@ -106,8 +102,6 @@ struct param
static corelock_t lock = CORELOCK_INIT;
#if defined(PRINTF_LONG_LONG_SUPPORT)
static void _TFP_GCC_NO_INLINE_ ulli2a(unsigned long long int num, struct param *p)
{
@ -267,8 +261,7 @@ static void putchw(void *putp, putcf putf, struct param *p)
{
putf(putp, '0');
putf(putp, (p->uc ? 'X' : 'x'));
}
else if (p->alt && p->base == 8)
} else if(p->alt && p->base == 8)
{
putf(putp, '0');
}
@ -305,8 +298,7 @@ void tfp_format(void *putp, putcf putf, const char *fmt, va_list va)
if(ch != '%')
{
putf(putp, ch);
}
else
} else
{
#if defined(PRINTF_LONG_SUPPORT)
char lng = 0; /* 1 for long, 2 for long long */
@ -355,8 +347,7 @@ void tfp_format(void *putp, putcf putf, const char *fmt, va_list va)
p.align_left = 1;
p.width = -p.width;
}
}
else if (IS_DIGIT(ch))
} else if(IS_DIGIT(ch))
{
unsigned int width;
ch = a2u(ch, &fmt, 10, &(width));
@ -378,14 +369,12 @@ void tfp_format(void *putp, putcf putf, const char *fmt, va_list va)
p.prec = -1;
else
p.prec = prec;
}
else if (IS_DIGIT(ch))
} else if(IS_DIGIT(ch))
{
unsigned int prec;
ch = a2u(ch, &fmt, 10, &(prec));
p.prec = prec;
}
else
} else
{
p.prec = 0;
}
@ -405,8 +394,7 @@ void tfp_format(void *putp, putcf putf, const char *fmt, va_list va)
else if(sizeof(size_t) == sizeof(unsigned long long int))
lng = 2;
#endif
}
else
} else
#endif
#endif
@ -650,4 +638,3 @@ int printk(const char *format, ...)
return 0;
}

View File

@ -36,4 +36,3 @@ unsigned int sleep(unsigned int seconds)
{
return (unsigned int)msleep(seconds * 1000);
}

View File

@ -15,27 +15,27 @@
/* Enable kernel-mode log API */
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/unistd.h>
#include <machine/syscall.h>
#include <stdbool.h>
#include <errno.h>
#include <limits.h>
#include <machine/syscall.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "syscalls.h"
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/unistd.h>
#include "atomic.h"
#include "clint.h"
#include "dump.h"
#include "fpioa.h"
#include "interrupt.h"
#include "syscalls.h"
#include "sysctl.h"
#include "util.h"
#include "syslog.h"
#include "dump.h"
#include "util.h"
/**
* @note System call list
@ -182,16 +182,14 @@ static size_t sys_brk(size_t pos)
/* Memory out, return -ENOMEM */
LOGE(TAG, "Out of memory\r\n");
res = -ENOMEM;
}
else
} else
{
/* Adjust brk pointer. */
_heap_cur = (char *)(uintptr_t)pos;
/* Return current address. */
res = (uintptr_t)_heap_cur;
}
}
else
} else
{
/* First call, return initial address */
res = (uintptr_t)&_heap_start[0];
@ -220,15 +218,15 @@ static ssize_t sys_write(int file, const void *ptr, size_t len)
if(STDOUT_FILENO == file || STDERR_FILENO == file)
{
/* Write data */
while (length-- > 0 && data != NULL) {
while(length-- > 0 && data != NULL)
{
if(sys_putchar)
sys_putchar(*(data++));
}
/* Return the actual size written */
res = len;
}
else
} else
{
/* Not support yet */
res = -ENOSYS;
@ -261,13 +259,16 @@ static ssize_t sys_read(int file, void *ptr, size_t len)
{
/* Read data */
actual_length = 0;
while (length-- > 0 && data != NULL) {
if (sys_getchar) {
while(length-- > 0 && data != NULL)
{
if(sys_getchar)
{
int getchar_result = sys_getchar();
/* Get char until not EOF */
while(getchar_result == EOF)
getchar_result = sys_getchar();
if (getchar_result != EOF) {
if(getchar_result != EOF)
{
/* Not EOF, read data to buffer */
*(data++) = (char)getchar_result;
actual_length++;
@ -279,15 +280,15 @@ static ssize_t sys_read(int file, void *ptr, size_t len)
break;
if((char)getchar_result == '\n')
break;
} else {
} else
{
/* EOF, do nothing */
}
}
}
/* Return the actual size read */
res = actual_length;
}
else
} else
{
/* Not support yet */
res = -ENOSYS;
@ -413,54 +414,94 @@ handle_ecall(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uintptr_t fregs
static const uint8_t syscall_id_table[0x100] =
{
[0x00 ... 0xFF] = SYS_ID_NOSYS,
[0xFF & SYS_exit] = SYS_ID_EXIT,
[0xFF & SYS_exit_group] = SYS_ID_EXIT,
[0xFF & SYS_getpid] = SYS_ID_NOSYS,
[0xFF & SYS_kill] = SYS_ID_NOSYS,
[0xFF & SYS_read] = SYS_ID_READ,
[0xFF & SYS_write] = SYS_ID_WRITE,
[0xFF & SYS_open] = SYS_ID_NOSYS,
[0xFF & SYS_openat] = SYS_ID_NOSYS,
[0xFF & SYS_close] = SYS_ID_CLOSE,
[0xFF & SYS_lseek] = SYS_ID_NOSYS,
[0xFF & SYS_brk] = SYS_ID_BRK,
[0xFF & SYS_link] = SYS_ID_NOSYS,
[0xFF & SYS_unlink] = SYS_ID_NOSYS,
[0xFF & SYS_mkdir] = SYS_ID_NOSYS,
[0xFF & SYS_chdir] = SYS_ID_NOSYS,
[0xFF & SYS_getcwd] = SYS_ID_NOSYS,
[0xFF & SYS_stat] = SYS_ID_NOSYS,
[0xFF & SYS_fstat] = SYS_ID_FSTAT,
[0xFF & SYS_lstat] = SYS_ID_NOSYS,
[0xFF & SYS_fstatat] = SYS_ID_NOSYS,
[0xFF & SYS_access] = SYS_ID_NOSYS,
[0xFF & SYS_faccessat] = SYS_ID_NOSYS,
[0xFF & SYS_pread] = SYS_ID_NOSYS,
[0xFF & SYS_pwrite] = SYS_ID_NOSYS,
[0xFF & SYS_uname] = SYS_ID_NOSYS,
[0xFF & SYS_getuid] = SYS_ID_NOSYS,
[0xFF & SYS_geteuid] = SYS_ID_NOSYS,
[0xFF & SYS_getgid] = SYS_ID_NOSYS,
[0xFF & SYS_getegid] = SYS_ID_NOSYS,
[0xFF & SYS_mmap] = SYS_ID_NOSYS,
[0xFF & SYS_munmap] = SYS_ID_NOSYS,
[0xFF & SYS_mremap] = SYS_ID_NOSYS,
[0xFF & SYS_time] = SYS_ID_NOSYS,
[0xFF & SYS_getmainvars] = SYS_ID_NOSYS,
[0xFF & SYS_rt_sigaction] = SYS_ID_NOSYS,
[0xFF & SYS_writev] = SYS_ID_NOSYS,
[0xFF & SYS_gettimeofday] = SYS_ID_GETTIMEOFDAY,
[0xFF & SYS_times] = SYS_ID_NOSYS,
[0xFF & SYS_fcntl] = SYS_ID_NOSYS,
[0xFF & SYS_getdents] = SYS_ID_NOSYS,
[0xFF & SYS_dup] = SYS_ID_NOSYS,
[0xFF &
SYS_exit] = SYS_ID_EXIT,
[0xFF &
SYS_exit_group] = SYS_ID_EXIT,
[0xFF &
SYS_getpid] = SYS_ID_NOSYS,
[0xFF &
SYS_kill] = SYS_ID_NOSYS,
[0xFF &
SYS_read] = SYS_ID_READ,
[0xFF &
SYS_write] = SYS_ID_WRITE,
[0xFF &
SYS_open] = SYS_ID_NOSYS,
[0xFF &
SYS_openat] = SYS_ID_NOSYS,
[0xFF &
SYS_close] = SYS_ID_CLOSE,
[0xFF &
SYS_lseek] = SYS_ID_NOSYS,
[0xFF &
SYS_brk] = SYS_ID_BRK,
[0xFF &
SYS_link] = SYS_ID_NOSYS,
[0xFF &
SYS_unlink] = SYS_ID_NOSYS,
[0xFF &
SYS_mkdir] = SYS_ID_NOSYS,
[0xFF &
SYS_chdir] = SYS_ID_NOSYS,
[0xFF &
SYS_getcwd] = SYS_ID_NOSYS,
[0xFF &
SYS_stat] = SYS_ID_NOSYS,
[0xFF &
SYS_fstat] = SYS_ID_FSTAT,
[0xFF &
SYS_lstat] = SYS_ID_NOSYS,
[0xFF &
SYS_fstatat] = SYS_ID_NOSYS,
[0xFF &
SYS_access] = SYS_ID_NOSYS,
[0xFF &
SYS_faccessat] = SYS_ID_NOSYS,
[0xFF &
SYS_pread] = SYS_ID_NOSYS,
[0xFF &
SYS_pwrite] = SYS_ID_NOSYS,
[0xFF &
SYS_uname] = SYS_ID_NOSYS,
[0xFF &
SYS_getuid] = SYS_ID_NOSYS,
[0xFF &
SYS_geteuid] = SYS_ID_NOSYS,
[0xFF &
SYS_getgid] = SYS_ID_NOSYS,
[0xFF &
SYS_getegid] = SYS_ID_NOSYS,
[0xFF &
SYS_mmap] = SYS_ID_NOSYS,
[0xFF &
SYS_munmap] = SYS_ID_NOSYS,
[0xFF &
SYS_mremap] = SYS_ID_NOSYS,
[0xFF &
SYS_time] = SYS_ID_NOSYS,
[0xFF &
SYS_getmainvars] = SYS_ID_NOSYS,
[0xFF &
SYS_rt_sigaction] = SYS_ID_NOSYS,
[0xFF &
SYS_writev] = SYS_ID_NOSYS,
[0xFF &
SYS_gettimeofday] = SYS_ID_GETTIMEOFDAY,
[0xFF &
SYS_times] = SYS_ID_NOSYS,
[0xFF &
SYS_fcntl] = SYS_ID_NOSYS,
[0xFF &
SYS_getdents] = SYS_ID_NOSYS,
[0xFF &
SYS_dup] = SYS_ID_NOSYS,
};
#if defined(__GNUC__)
#pragma GCC diagnostic warning "-Woverride-init"
#endif
regs[10] = syscall_table[syscall_id_table[0xFF & regs[17]]]
(
regs[10] = syscall_table[syscall_id_table[0xFF & regs[17]]](
regs[10], /* a0 */
regs[11], /* a1 */
regs[12], /* a2 */
@ -536,8 +577,7 @@ handle_misaligned_load(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uintp
{
/* compressed instruction should not get this fault. */
goto on_error;
}
else
} else
{
uint32_t instruct = *(uint32_t *)epc;
uint8_t opcode = instruct & 0x7F;
@ -568,7 +608,6 @@ handle_misaligned_load(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uintp
for(int i = 0; i < len; ++i)
data_load |= ((uint64_t) * ((uint8_t *)addr + i)) << (8 * i);
if(!unsigned_ & !fpu)
{
/* adjust sign */
@ -628,8 +667,7 @@ handle_misaligned_store(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uint
{
/* compressed instruction should not get this fault. */
goto on_error;
}
else
} else
{
uint32_t instruct = *(uint32_t *)epc;
uint8_t opcode = instruct & 0x7F;
@ -656,7 +694,6 @@ handle_misaligned_store(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uint
addr = (uint64_t)((uint64_t)regs[dst] + offset);
if(fpu)
data_store = fregs[src];
else
@ -708,4 +745,3 @@ size_t get_free_heap_size(void)
{
return (size_t)(&_heap_end[0] - _heap_cur);
}

View File

@ -14,8 +14,8 @@
*/
#include <stdlib.h>
#include <string.h>
#include "sysctl.h"
#include "aes.h"
#include "sysctl.h"
#include "utils.h"
volatile aes_t *const aes = (volatile aes_t *)AES_BASE_ADDR;
@ -85,8 +85,7 @@ static uint32_t gcm_check_tag(uint32_t *gcm_tag)
{
gcm_clear_chk_tag();
return 1;
}
else
} else
{
gcm_clear_chk_tag();
return 0;
@ -125,7 +124,6 @@ void gcm_get_tag(uint8_t *gcm_tag)
gcm_check_tag((uint32_t *)gcm_tag);
}
void aes_init(uint8_t *input_key, size_t input_key_len, uint8_t *iv, size_t iv_len, uint8_t *gcm_aad,
aes_cipher_mode_t cipher_mode, aes_encrypt_sel_t encrypt_sel, size_t gcm_aad_len, size_t input_data_len)
{
@ -492,7 +490,6 @@ void aes_ecb128_hard_decrypt_dma(dmac_channel_number_t dma_receive_channel_num,
dmac_wait_done(dma_receive_channel_num);
}
void aes_ecb128_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
uint8_t *input_key,
uint8_t *input_data,
@ -800,4 +797,3 @@ void aes_gcm256_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
gcm_get_tag(gcm_tag);
}

View File

@ -12,12 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <math.h>
#include <stddef.h>
#include <stdint.h>
#include <math.h>
#include "apu.h"
#include "syscalls.h"
#include "sysctl.h"
#include "apu.h"
#define BEAFORMING_BASE_ADDR (0x50250200)
#ifndef M_PI
@ -126,20 +126,16 @@ void apu_set_src_mode(uint8_t src_mode)
*/
void apu_set_direction_delay(uint8_t dir_num, uint8_t *dir_bidx)
{
apu->bf_dir_bidx[dir_num][0] =(apu_dir_bidx_t)
{
apu->bf_dir_bidx[dir_num][0] = (apu_dir_bidx_t){
.dir_rd_idx0 = dir_bidx[0],
.dir_rd_idx1 = dir_bidx[1],
.dir_rd_idx2 = dir_bidx[2],
.dir_rd_idx3 = dir_bidx[3]
};
apu->bf_dir_bidx[dir_num][1] =(apu_dir_bidx_t)
{
.dir_rd_idx3 = dir_bidx[3]};
apu->bf_dir_bidx[dir_num][1] = (apu_dir_bidx_t){
.dir_rd_idx0 = dir_bidx[4],
.dir_rd_idx1 = dir_bidx[5],
.dir_rd_idx2 = dir_bidx[6],
.dir_rd_idx3 = dir_bidx[7]
};
.dir_rd_idx3 = dir_bidx[7]};
}
/*
@ -169,7 +165,6 @@ void apu_set_delay(float radius, uint8_t mic_num_a_circle, uint8_t center)
for(; i < 8; i++)
offsets[0][i] = 0;
for(j = 1; j < DIRECTION_RES; ++j)
{
for(i = 0; i < mic_num_a_circle; ++i)
@ -289,12 +284,12 @@ void apu_dir_set_prev_fir(uint16_t *fir_coef)
{
uint8_t i = 0;
for (i = 0; i < 9; i++) {
for(i = 0; i < 9; i++)
{
apu->bf_pre_fir0_coef[i] =
(apu_fir_coef_t){
.fir_tap0 = fir_coef[i * 2],
.fir_tap1 = i == 8 ? 0 : fir_coef[i * 2 + 1]
};
.fir_tap1 = i == 8 ? 0 : fir_coef[i * 2 + 1]};
}
}
@ -302,12 +297,12 @@ void apu_dir_set_post_fir(uint16_t *fir_coef)
{
uint8_t i = 0;
for (i = 0; i < 9; i++) {
for(i = 0; i < 9; i++)
{
apu->bf_post_fir0_coef[i] =
(apu_fir_coef_t){
.fir_tap0 = fir_coef[i * 2],
.fir_tap1 = i == 8 ? 0 : fir_coef[i * 2 + 1]
};
.fir_tap1 = i == 8 ? 0 : fir_coef[i * 2 + 1]};
}
}
@ -315,12 +310,12 @@ void apu_voc_set_prev_fir(uint16_t *fir_coef)
{
uint8_t i = 0;
for (i = 0; i < 9; i++) {
for(i = 0; i < 9; i++)
{
apu->bf_pre_fir1_coef[i] =
(apu_fir_coef_t){
.fir_tap0 = fir_coef[i * 2],
.fir_tap1 = i == 8 ? 0 : fir_coef[i * 2 + 1]
};
.fir_tap1 = i == 8 ? 0 : fir_coef[i * 2 + 1]};
}
}
@ -328,12 +323,12 @@ void apu_voc_set_post_fir(uint16_t *fir_coef)
{
uint8_t i = 0;
for (i = 0; i < 9; i++) {
for(i = 0; i < 9; i++)
{
apu->bf_post_fir1_coef[i] =
(apu_fir_coef_t){
.fir_tap0 = fir_coef[i * 2],
.fir_tap1 = i == 8 ? 0 : fir_coef[i * 2 + 1]
};
.fir_tap1 = i == 8 ? 0 : fir_coef[i * 2 + 1]};
}
}
@ -342,8 +337,7 @@ void apu_set_fft_shift_factor(uint8_t enable_flag, uint16_t shift_factor)
apu->bf_fft_cfg_reg =
(apu_fft_cfg_t){
.fft_enable = enable_flag,
.fft_shift_factor = shift_factor
};
.fft_shift_factor = shift_factor};
apu_ch_cfg_t ch_cfg = apu->bf_ch_cfg_reg;
@ -398,24 +392,21 @@ void apu_set_interrupt_mask(uint8_t dir_int_mask, uint8_t voc_int_mask)
apu->bf_int_mask_reg =
(apu_int_mask_t){
.dir_data_rdy_msk = dir_int_mask,
.voc_buf_rdy_msk = voc_int_mask
};
.voc_buf_rdy_msk = voc_int_mask};
}
void apu_dir_clear_int_state(void)
{
apu->bf_int_stat_reg =
(apu_int_stat_t){
.dir_search_data_rdy = 1
};
.dir_search_data_rdy = 1};
}
void apu_voc_clear_int_state(void)
{
apu->bf_int_stat_reg =
(apu_int_stat_t){
.voc_buf_data_rdy = 1
};
.voc_buf_data_rdy = 1};
}
/* reset saturation_counter */
@ -447,7 +438,8 @@ uint32_t apu_voc_get_saturation_limit(void)
static void print_fir(const char *member_name, volatile apu_fir_coef_t *pfir)
{
printf(" for(int i = 0; i < 9; i++){\n");
for (int i = 0; i < 9; i++) {
for(int i = 0; i < 9; i++)
{
apu_fir_coef_t fir = pfir[i];
printf(" apu->%s[%d] = (apu_fir_coef_t){\n", member_name, i);
@ -478,7 +470,8 @@ void apu_print_setting(void)
printf(" };\n");
printf(" for(int i = 0; i < 16; i++){\n");
for (int i = 0; i < 16; i++) {
for(int i = 0; i < 16; i++)
{
apu_dir_bidx_t bidx0 = apu->bf_dir_bidx[i][0];
apu_dir_bidx_t bidx1 = apu->bf_dir_bidx[i][1];
@ -502,7 +495,6 @@ void apu_print_setting(void)
print_fir("bf_pre_fir1_coef", apu->bf_pre_fir1_coef);
print_fir("bf_post_fir1_coef", apu->bf_post_fir1_coef);
apu_dwsz_cfg_t bf_dwsz_cfg_reg = apu->bf_dwsz_cfg_reg;
printf(" apu->bf_dwsz_cfg_reg = (apu_dwsz_cfg_t){\n");
@ -526,4 +518,3 @@ void apu_print_setting(void)
printf("}\n");
}

View File

@ -14,8 +14,8 @@
*/
#include <stddef.h>
#include <stdint.h>
#include "encoding.h"
#include "clint.h"
#include "encoding.h"
#include "sysctl.h"
volatile clint_t *const clint = (volatile clint_t *)CLINT_BASE_ADDR;
@ -236,8 +236,7 @@ uintptr_t handle_irq_m_timer(uintptr_t cause, uintptr_t epc)
{
/* Set mtimecmp by core id */
clint->mtimecmp[core_id] += clint_timer_instance[core_id].cycles;
}
else
} else
clear_csr(mie, MIP_MTIP);
return epc;
}
@ -258,4 +257,3 @@ uintptr_t handle_irq_m_soft(uintptr_t cause, uintptr_t epc)
set_csr(mie, MIP_MSIP);
return epc;
}

View File

@ -12,15 +12,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include "dmac.h"
#include "sysctl.h"
#include "fpioa.h"
#include "utils.h"
#include "plic.h"
#include "stdlib.h"
#include "sysctl.h"
#include "utils.h"
volatile dmac_t *const dmac = (dmac_t *)DMAC_BASE_ADDR;
@ -35,7 +35,8 @@ dmac_context_t dmac_context[6];
static int is_memory(uintptr_t address)
{
enum {
enum
{
mem_len = 6 * 1024 * 1024,
mem_no_cache_len = 8 * 1024 * 1024,
};
@ -93,7 +94,8 @@ void dmac_channel_enable(dmac_channel_number_t channel_num)
chen.data = readq(&dmac->chen);
switch (channel_num) {
switch(channel_num)
{
case DMAC_CHANNEL0:
chen.dmac_chen.ch1_en = 1;
chen.dmac_chen.ch1_en_we = 1;
@ -170,7 +172,8 @@ int32_t dmac_check_channel_busy(dmac_channel_number_t channel_num)
dmac_chen_u_t chen_u;
chen_u.data = readq(&dmac->chen);
switch (channel_num) {
switch(channel_num)
{
case DMAC_CHANNEL0:
if(chen_u.dmac_chen.ch1_en == 1)
ret = 1;
@ -213,7 +216,8 @@ int32_t dmac_set_list_master_select(dmac_channel_number_t channel_num,
ctl.data = readq(&dmac->channel[channel_num].ctl);
ret = dmac_check_channel_busy(channel_num);
if (ret == 0) {
if(ret == 0)
{
if(sd_sel == DMAC_SRC || sd_sel == DMAC_SRC_DST)
ctl.ch_ctl.sms = mst_num;
@ -631,10 +635,12 @@ void dmac_link_list_item(dmac_channel_number_t channel_num,
ctl.ch_ctl.src_stat_en = cfg_param->ctl_src_stat_en;
ctl.ch_ctl.dst_stat_en = cfg_param->ctl_dst_stat_en;
if (LLI_last_row != LAST_ROW) {
if(LLI_last_row != LAST_ROW)
{
ctl.ch_ctl.shadowreg_or_lli_valid = 1;
ctl.ch_ctl.shadowreg_or_lli_last = 0;
} else {
} else
{
ctl.ch_ctl.shadowreg_or_lli_valid = 1;
ctl.ch_ctl.shadowreg_or_lli_last = 1;
}
@ -660,7 +666,8 @@ void dmac_update_shandow_register(dmac_channel_number_t channel_num,
{
dmac_ch_ctl_u_t ctl_u;
do {
do
{
ctl_u.data = readq(&dmac->channel[channel_num].ctl);
} while(ctl_u.ch_ctl.shadowreg_or_lli_valid);
@ -682,7 +689,8 @@ void dmac_update_shandow_register(dmac_channel_number_t channel_num,
{
ctl_u.ch_ctl.shadowreg_or_lli_valid = 1;
ctl_u.ch_ctl.shadowreg_or_lli_last = 0;
} else {
} else
{
ctl_u.ch_ctl.shadowreg_or_lli_valid = 1;
ctl_u.ch_ctl.shadowreg_or_lli_last = 1;
}
@ -706,7 +714,8 @@ void dmac_set_single_mode(dmac_channel_number_t channel_num,
dmac_address_increment_t dest_inc,
dmac_burst_trans_length_t dmac_burst_size,
dmac_transfer_width_t dmac_trans_width,
size_t block_size) {
size_t block_size)
{
dmac_chanel_interrupt_clear(channel_num);
dmac_channel_disable(channel_num);
dmac_wait_idle(channel_num);
@ -741,7 +750,8 @@ int dmac_is_idle(dmac_channel_number_t channel_num)
void dmac_wait_idle(dmac_channel_number_t channel_num)
{
while(!dmac_is_idle(channel_num));
while(!dmac_is_idle(channel_num))
;
dmac_chanel_interrupt_clear(channel_num); /* clear interrupt */
}
@ -789,4 +799,3 @@ void dmac_irq_unregister(dmac_channel_number_t channel_num)
}
void __attribute__((weak, alias("dmac_irq_unregister"))) dmac_free_irq(dmac_channel_number_t channel_num);

View File

@ -12,13 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <math.h>
#include <stddef.h>
#include <stdint.h>
#include "dvp.h"
#include "utils.h"
#include "fpioa.h"
#include "sysctl.h"
#include <math.h>
#include "utils.h"
volatile dvp_t *const dvp = (volatile dvp_t *)DVP_BASE_ADDR;
static uint8_t g_sccb_reg_len = 8;
@ -81,8 +81,7 @@ void dvp_sccb_send_data(uint8_t dev_addr, uint16_t reg_addr, uint8_t reg_data)
if(g_sccb_reg_len == 8)
{
dvp->sccb_ctl = DVP_SCCB_WRITE_DATA_ENABLE | DVP_SCCB_DEVICE_ADDRESS(dev_addr) | DVP_SCCB_REG_ADDRESS(reg_addr) | DVP_SCCB_WDATA_BYTE0(reg_data);
}
else
} else
{
dvp->sccb_ctl = DVP_SCCB_WRITE_DATA_ENABLE | DVP_SCCB_DEVICE_ADDRESS(dev_addr) | DVP_SCCB_REG_ADDRESS(reg_addr >> 8) | DVP_SCCB_WDATA_BYTE0(reg_addr & 0xff) | DVP_SCCB_WDATA_BYTE1(reg_data);
}
@ -105,8 +104,7 @@ uint8_t dvp_sccb_receive_data(uint8_t dev_addr, uint16_t reg_addr)
if(g_sccb_reg_len == 8)
{
dvp->sccb_ctl = DVP_SCCB_WRITE_DATA_ENABLE | DVP_SCCB_DEVICE_ADDRESS(dev_addr) | DVP_SCCB_REG_ADDRESS(reg_addr);
}
else
} else
{
dvp->sccb_ctl = DVP_SCCB_WRITE_DATA_ENABLE | DVP_SCCB_DEVICE_ADDRESS(dev_addr) | DVP_SCCB_REG_ADDRESS(reg_addr >> 8) | DVP_SCCB_WDATA_BYTE0(reg_addr & 0xff);
}
@ -285,8 +283,7 @@ void dvp_set_output_enable(dvp_output_mode_t index, int enable)
dvp->dvp_cfg |= DVP_CFG_AI_OUTPUT_ENABLE;
else
dvp->dvp_cfg &= ~DVP_CFG_AI_OUTPUT_ENABLE;
}
else
} else
{
if(enable)
dvp->dvp_cfg |= DVP_CFG_DISPLAY_OUTPUT_ENABLE;
@ -294,4 +291,3 @@ void dvp_set_output_enable(dvp_output_mode_t index, int enable)
dvp->dvp_cfg &= ~DVP_CFG_DISPLAY_OUTPUT_ENABLE;
}
}

View File

@ -14,9 +14,9 @@
*/
#include <stddef.h>
#include "dmac.h"
#include "utils.h"
#include "sysctl.h"
#include "fft.h"
#include "sysctl.h"
#include "utils.h"
static volatile fft_t *const fft = (volatile fft_t *)FFT_BASE_ADDR;
@ -64,5 +64,3 @@ void fft_complex_uint16_dma(dmac_channel_number_t dma_send_channel_num, dmac_cha
DMAC_MSIZE_4, DMAC_TRANS_WIDTH_64, point_num >> 1);
dmac_wait_done(dma_receive_channel_num);
}

File diff suppressed because it is too large Load Diff

View File

@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio.h"
#include "utils.h"
#include "fpioa.h"
#include "gpio.h"
#include "sysctl.h"
#include "utils.h"
#define GPIO_MAX_PINNO 8
volatile gpio_t *const gpio = (volatile gpio_t *)GPIO_BASE_ADDR;
@ -76,4 +76,3 @@ void gpio_set_pin(uint8_t pin, gpio_pin_value_t value)
configASSERT(dir == 1);
set_gpio_bit(reg, pin, value);
}

View File

@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpiohs.h"
#include "utils.h"
#include "fpioa.h"
#include "gpiohs.h"
#include "sysctl.h"
#include "utils.h"
#define GPIOHS_MAX_PINNO 32
volatile gpiohs_t *const gpiohs = (volatile gpiohs_t *)GPIOHS_BASE_ADDR;
@ -98,8 +98,7 @@ void gpiohs_set_pin_edge(uint8_t pin, gpio_pin_edge_t edge)
if(edge & GPIO_PE_FALLING)
{
set_gpio_bit(gpiohs->fall_ie.u32, pin, 1);
}
else
} else
{
set_gpio_bit(gpiohs->fall_ie.u32, pin, 0);
}
@ -107,8 +106,7 @@ void gpiohs_set_pin_edge(uint8_t pin, gpio_pin_edge_t edge)
if(edge & GPIO_PE_RISING)
{
set_gpio_bit(gpiohs->rise_ie.u32, pin, 1);
}
else
} else
{
set_gpio_bit(gpiohs->rise_ie.u32, pin, 0);
}
@ -116,8 +114,7 @@ void gpiohs_set_pin_edge(uint8_t pin, gpio_pin_edge_t edge)
if(edge & GPIO_PE_LOW)
{
set_gpio_bit(gpiohs->low_ie.u32, pin, 1);
}
else
} else
{
set_gpio_bit(gpiohs->low_ie.u32, pin, 0);
}
@ -125,8 +122,7 @@ void gpiohs_set_pin_edge(uint8_t pin, gpio_pin_edge_t edge)
if(edge & GPIO_PE_HIGH)
{
set_gpio_bit(gpiohs->high_ie.u32, pin, 1);
}
else
} else
{
set_gpio_bit(gpiohs->high_ie.u32, pin, 0);
}
@ -215,4 +211,3 @@ void gpiohs_irq_disable(size_t pin)
{
plic_irq_disable(IRQN_GPIOHS0_INTERRUPT + pin);
}

View File

@ -13,14 +13,14 @@
* limitations under the License.
*/
#include <stddef.h>
#include "i2c.h"
#include "utils.h"
#include "bsp.h"
#include "fpioa.h"
#include "i2c.h"
#include "platform.h"
#include "stdlib.h"
#include "string.h"
#include "sysctl.h"
#include "bsp.h"
#include "utils.h"
typedef struct _i2c_slave_instance
{
@ -45,8 +45,7 @@ volatile i2c_t* const i2c[3] =
{
(volatile i2c_t *)I2C0_BASE_ADDR,
(volatile i2c_t *)I2C1_BASE_ADDR,
(volatile i2c_t*)I2C2_BASE_ADDR
};
(volatile i2c_t *)I2C2_BASE_ADDR};
static void i2c_clk_init(i2c_device_number_t i2c_num)
{
@ -322,8 +321,7 @@ void i2c_handle_data_dma(i2c_device_number_t i2c_num, i2c_data_t data, plic_inte
configASSERT(!"source abort");
}
}
}
else
} else
{
configASSERT(data.rx_buf && data.rx_len);
if(data.tx_len)

View File

@ -12,20 +12,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include "i2s.h"
#include "sysctl.h"
#include "stdlib.h"
#include "sysctl.h"
#include "utils.h"
volatile i2s_t *const i2s[3] =
{
(volatile i2s_t *)I2S0_BASE_ADDR,
(volatile i2s_t *)I2S1_BASE_ADDR,
(volatile i2s_t *)I2S2_BASE_ADDR
};
(volatile i2s_t *)I2S2_BASE_ADDR};
typedef struct _i2s_instance
{
@ -111,8 +110,7 @@ static void i2s_disable_block(i2s_device_number_t device_num, i2s_transmit_t rxt
u_irer.irer.rxen = 0;
writel(u_irer.reg_data, &i2s[device_num]->irer);
/* Receiver block disable */
}
else
} else
{
u_iter.reg_data = readl(&i2s[device_num]->iter);
u_iter.iter.txen = 0;
@ -178,7 +176,6 @@ static void i2s_master_configure(i2s_device_number_t device_num,
u_cer.cer.clken = 1;
writel(u_cer.reg_data, &i2s[device_num]->cer);
/* Clock generation enable */
}
static int i2s_set_rx_threshold(i2s_device_number_t device_num,
@ -446,7 +443,6 @@ static void i2s_parse_voice(i2s_device_number_t device_num, uint32_t *buf, const
}
}
void i2s_play(i2s_device_number_t device_num, dmac_channel_number_t channel_num,
const uint8_t *buf, size_t buf_len, size_t frame, size_t bits_per_sample, uint8_t track_num)
{
@ -470,8 +466,7 @@ void i2s_play(i2s_device_number_t device_num, dmac_channel_number_t channel_num,
trans_buf = buf + frame_cnt * frame * (bits_per_sample / 8) * track_num;
i2s_send_data_dma(device_num, trans_buf, frame_remain, channel_num);
}
}
else if (bits_per_sample == 32 && track_num == 2)
} else if(bits_per_sample == 32 && track_num == 2)
{
for(i = 0; i < frame_cnt; i++)
{
@ -483,8 +478,7 @@ void i2s_play(i2s_device_number_t device_num, dmac_channel_number_t channel_num,
trans_buf = buf + frame_cnt * frame * (bits_per_sample / 8) * track_num;
i2s_send_data_dma(device_num, trans_buf, frame_remain * 2, channel_num);
}
}
else
} else
{
uint32_t *buff[2];
buff[0] = malloc(frame * 2 * sizeof(uint32_t) * 2);
@ -600,16 +594,14 @@ void i2s_init(i2s_device_number_t device_num, i2s_transmit_t rxtx_mode, uint32_t
{
i2s_set_mask_interrupt(device_num, I2S_CHANNEL_0 + i, 1, 1, 1, 1);
i2s_transimit_enable(device_num, I2S_CHANNEL_0 + i);
}
else
} else
{
i2s_transmit_channel_enable(device_num, I2S_CHANNEL_0 + i, 0);
}
channel_mask >>= 2;
}
i2s_transmit_dma_enable(device_num, 1);
}
else
} else
{
for(int i = 0; i < 4; i++)
{
@ -617,8 +609,7 @@ void i2s_init(i2s_device_number_t device_num, i2s_transmit_t rxtx_mode, uint32_t
{
i2s_set_mask_interrupt(device_num, I2S_CHANNEL_0 + i, 1, 1, 1, 1);
i2s_receive_enable(device_num, I2S_CHANNEL_0 + i);
}
else
} else
{
i2s_recv_channel_enable(device_num, I2S_CHANNEL_0 + i, 0);
}
@ -680,8 +671,7 @@ void i2s_handle_data_dma(i2s_device_number_t device_num, i2s_data_t data, plic_i
{
dmac_wait_done(data.tx_channel);
}
}
else
} else
{
configASSERT(data.rx_buf && data.rx_len);
if(!data.nowait_dma_idle)
@ -705,4 +695,3 @@ void i2s_handle_data_dma(i2s_device_number_t device_num, i2s_data_t data, plic_i
}
}
}

View File

@ -14,10 +14,10 @@
*/
#ifndef _DRIVER_AES_H
#define _DRIVER_AES_H
#include <stdlib.h>
#include <stdint.h>
#include "platform.h"
#include <stdlib.h>
#include "dmac.h"
#include "platform.h"
#ifdef __cplusplus
extern "C" {

View File

@ -335,4 +335,3 @@ int clint_ipi_unregister(void);
#endif
#endif /* _DRIVER_CLINT_H */

View File

@ -15,12 +15,12 @@
#ifndef _DRIVER_DMAC_H
#define _DRIVER_DMAC_H
#include <stddef.h>
#include <stdint.h>
#include "io.h"
#include "platform.h"
#include "stdbool.h"
#include "plic.h"
#include <stddef.h>
#include "stdbool.h"
#ifdef __cplusplus
extern "C" {
@ -1484,7 +1484,6 @@ void dmac_set_irq(dmac_channel_number_t channel_num , plic_irq_callback_t dmac_c
*/
void dmac_irq_register(dmac_channel_number_t channel_num, plic_irq_callback_t dmac_callback, void *ctx, uint32_t priority);
/**
* @brief Unregister dmac interrupt
*

View File

@ -244,4 +244,3 @@ void fft_complex_uint16_dma(dmac_channel_number_t dma_send_channel_num,
#endif
#endif /* _DRIVER_FFT_H */

View File

@ -1033,4 +1033,3 @@ int fpioa_set_oe_inv(int number, uint8_t inv_enable);
#endif
#endif /* _DRIVER_FPIOA_H */

View File

@ -15,10 +15,10 @@
#ifndef _DRIVER_GPIO_H
#define _DRIVER_GPIO_H
#include "platform.h"
#include <inttypes.h>
#include <stddef.h>
#include "gpio_common.h"
#include "platform.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -165,4 +165,3 @@ void gpio_set_pin(uint8_t pin, gpio_pin_value_t value);
#endif
#endif /* _DRIVER_GPIO_H */

View File

@ -48,4 +48,3 @@ typedef enum _gpio_pin_value
#endif
#endif /* _GPIO_COMMON_H */

View File

@ -15,10 +15,10 @@
#ifndef _DRIVER_GPIOHS_H
#define _DRIVER_GPIOHS_H
#include <stdint.h>
#include "platform.h"
#include <stddef.h>
#include <stdint.h>
#include "gpio_common.h"
#include "platform.h"
#include "plic.h"
#ifdef __cplusplus
extern "C" {
@ -264,4 +264,3 @@ void gpiohs_irq_unregister(uint8_t pin);
#endif
#endif /* _DRIVER_GPIOHS_H */

View File

@ -15,8 +15,8 @@
#ifndef _DRIVER_I2C_H
#define _DRIVER_I2C_H
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#include "dmac.h"
#ifdef __cplusplus

View File

@ -15,18 +15,17 @@
#ifndef _DRIVER_I2S_H
#define _DRIVER_I2S_H
#include <stdint.h>
#include <stddef.h>
#include "platform.h"
#include "io.h"
#include "dmac.h"
#include <stdint.h>
#include "bsp.h"
#include "dmac.h"
#include "io.h"
#include "platform.h"
#ifdef __cplusplus
extern "C" {
#endif
#define I2S0_IN_D0 90
#define I2S0_SCLK 88
#define I2S0_WS 89
@ -136,7 +135,6 @@ typedef enum _fifo_threshold
TRIGGER_LEVEL_16 = 0xf
} i2s_fifo_threshold_t;
typedef struct _i2s_ier
{
/* Bit 0 is ien, 0 for disable i2s and 1 for enable i2s */
@ -336,7 +334,8 @@ typedef struct _i2s_rcr_tcr
uint32_t resv : 29;
} __attribute__((packed, aligned(4))) i2s_rcr_tcr_t;
typedef union _rcr_tcr_u {
typedef union _rcr_tcr_u
{
i2s_rcr_tcr_t rcr_tcr;
uint32_t reg_data;
} rcr_tcr_t;

View File

@ -15,8 +15,8 @@
#ifndef _KPU_H
#define _KPU_H
#include <stdint.h>
#include <plic.h>
#include <stdint.h>
#include "dmac.h"
#define kpu_matmul_begin kpu_conv2d_output
@ -230,7 +230,6 @@ typedef struct
} batchnorm;
} kpu_batchnorm_argument_t;
typedef struct
{
union
@ -274,7 +273,6 @@ typedef struct
uint64_t reserved : 63;
} kpu_config_eight_bit_mode_t;
typedef struct
{
volatile uint64_t layer_argument_fifo;
@ -291,7 +289,8 @@ typedef struct
kpu_config_interrupt_t data;
} interrupt_raw;
volatile union {
volatile union
{
uint64_t reg;
kpu_config_interrupt_t data;
} interrupt_mask;

View File

@ -324,7 +324,8 @@ typedef struct _plic_target_enables
typedef struct _plic_target
{
/* 0x0C200000-0x0FFFF004: target 0-15871 */
struct {
struct
{
uint32_t priority_threshold; /* Offset 0x000 */
uint32_t claim_complete; /* Offset 0x004 */
uint8_t resv[0x1FF8]; /* Offset 0x008, Size 0xFF8 */

View File

@ -15,8 +15,8 @@
#ifndef _DRIVER_PWM_H
#define _DRIVER_PWM_H
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -66,7 +66,6 @@ void pwm_set_enable(pwm_device_number_t pwm_number, pwm_channel_number_t channel
*/
double pwm_set_frequency(pwm_device_number_t pwm_number, pwm_channel_number_t channel, double frequency, double duty);
#ifdef __cplusplus
}
#endif

View File

@ -21,11 +21,11 @@
#ifndef _DRIVER_RTC_H
#define _DRIVER_RTC_H
#include <stdint.h>
#include <time.h>
#include <plic.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#include "platform.h"
@ -109,7 +109,6 @@ typedef struct _rtc_mask
*
*/
/**
* @brief Timer date information
*
@ -261,10 +260,10 @@ typedef struct _rtc_extended
{
uint32_t century : 5; /*!< Century. Range [0,31] */
uint32_t leap_year : 1; /*!< Is leap year. 1 is leap year, 0 is not leap year */
uint32_t resv : 26; /*!< Reserved */;
uint32_t resv : 26; /*!< Reserved */
;
} __attribute__((packed, aligned(4))) rtc_extended_t;
/**
* @brief Real-time clock struct
*
@ -286,7 +285,6 @@ typedef struct _rtc
rtc_extended_t extended; /*!< No. 10 (0x28): Timer extended information */
} __attribute__((packed, aligned(4))) rtc_t;
/**
* @brief Real-time clock object
*/

View File

@ -14,8 +14,8 @@
*/
#ifndef _SHA256_H
#define _SHA256_H
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
@ -125,4 +125,3 @@ void sha256_hard_calculate(const uint8_t *input, size_t input_len, uint8_t *outp
#endif
#endif

View File

@ -15,8 +15,8 @@
#ifndef _DRIVER_SPI_H
#define _DRIVER_SPI_H
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#include "dmac.h"
#ifdef __cplusplus
@ -140,7 +140,6 @@ typedef enum _spi_transfer_mode
SPI_TMOD_EEROM
} spi_transfer_mode_t;
typedef enum _spi_transfer_width
{
SPI_TRANS_CHAR = 0x1,

View File

@ -15,8 +15,8 @@
#ifndef _DRIVER_TIMER_H
#define _DRIVER_TIMER_H
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -38,9 +38,9 @@
#define _DRIVER_APBUART_H
#include <stdint.h>
#include "dmac.h"
#include "platform.h"
#include "plic.h"
#include "dmac.h"
#ifdef __cplusplus
extern "C" {
@ -363,7 +363,6 @@ void uart_send_data_dma(uart_device_number_t uart_channel, dmac_channel_number_t
*/
void uart_receive_data_dma(uart_device_number_t uart_channel, dmac_channel_number_t dmac_channel, uint8_t *buffer, size_t buf_len);
/**
* @brief Send data by dma
*

View File

@ -344,4 +344,3 @@ uint32_t get_gpio_bit(volatile uint32_t *bits, size_t offset);
}
#endif /* __cplusplus */
#endif /* _DRIVER_COMMON_H */

View File

@ -15,9 +15,9 @@
#ifndef _DRIVER_WDT_H
#define _DRIVER_WDT_H
#include <stdint.h>
#include <stddef.h>
#include <plic.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {

View File

@ -1,15 +1,15 @@
#include "kpu.h"
#include <platform.h>
#include <sysctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "printf.h"
#include "dmac.h"
#include <string.h>
#include "bsp.h"
#include <assert.h>
#include <float.h>
#include <math.h>
#include <platform.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysctl.h>
#include "bsp.h"
#include "dmac.h"
#include "kpu.h"
#include "printf.h"
#define LAYER_BURST_SIZE 12
@ -47,12 +47,10 @@ int kpu_continue(void* _task)
kpu_task_t *task = (kpu_task_t *)_task;
int layer_burst_size = 1;
kpu->interrupt_clear.data = (kpu_config_interrupt_t)
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int=1
};
.layer_cfg_almost_full_int = 1};
if(task->remain_layers_length == 0)
{
@ -76,8 +74,7 @@ int kpu_continue(void* _task)
kpu->layer_argument_fifo = task->remain_layers[i].dma_parameter.reg;
}
task->remain_layers_length = 0;
}
else
} else
{
for(uint32_t i = 0; i < layer_burst_size; i++)
{
@ -114,25 +111,19 @@ static int kpu_run_dma_input_done_push_layers(void* _task)
kpu_task_t *task = (kpu_task_t *)_task;
kpu->interrupt_clear.reg = 7;
dmac->channel[task->dma_ch].intclear = 0xFFFFFFFF;
kpu->fifo_threshold.data = (kpu_config_fifo_threshold_t)
{
.fifo_full_threshold = 10, .fifo_empty_threshold=1
};
kpu->eight_bit_mode.data = (kpu_config_eight_bit_mode_t)
{
.eight_bit_mode=task->eight_bit_mode
};
kpu->fifo_threshold.data = (kpu_config_fifo_threshold_t){
.fifo_full_threshold = 10, .fifo_empty_threshold = 1};
kpu->eight_bit_mode.data = (kpu_config_eight_bit_mode_t){
.eight_bit_mode = task->eight_bit_mode};
kpu_layer_argument_t *last_layer = &task->layers[task->layers_length - 1];
kpu_run_dma_output(task->dma_ch, task->dst, last_layer->dma_parameter.data.dma_total_byte + 1, kpu_run_all_done, task);
kpu->interrupt_mask.data = (kpu_config_interrupt_t)
{
kpu->interrupt_mask.data = (kpu_config_interrupt_t){
.calc_done_int = 0,
.layer_cfg_almost_empty_int = 0,
.layer_cfg_almost_full_int=1
};
.layer_cfg_almost_full_int = 1};
kpu_continue(task);
return 0;
}
@ -222,8 +213,7 @@ static int kpu_config_input(void *ctx)
}
task->remain_layers_length = 0;
kpu->interrupt_mask.reg = 7;
}
else
} else
{
for(uint32_t i = 0; i < LAYER_BURST_SIZE; i++)
{
@ -264,21 +254,17 @@ static int kpu_data_ready(void *ctx)
kpu->eight_bit_mode.reg = task->eight_bit_mode;
kpu->interrupt_mask.reg = 7;
kpu->interrupt_clear.reg = 7;
kpu->fifo_threshold.data = (kpu_config_fifo_threshold_t)
{
.fifo_full_threshold = 12, .fifo_empty_threshold = 1
};
kpu->fifo_threshold.data = (kpu_config_fifo_threshold_t){
.fifo_full_threshold = 12, .fifo_empty_threshold = 1};
plic_set_priority(IRQN_AI_INTERRUPT, 2);
plic_irq_register(IRQN_AI_INTERRUPT, kpu_config_input, task);
plic_irq_enable(IRQN_AI_INTERRUPT);
kpu_config_input(task);
kpu->interrupt_mask.data = (kpu_config_interrupt_t)
{
kpu->interrupt_mask.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 0,
.layer_cfg_almost_full_int = 1
};
.layer_cfg_almost_full_int = 1};
return 0;
}
@ -376,20 +362,14 @@ static void kpu_send_layer(const kpu_layer_argument_t *layer)
void kpu_init(int eight_bit_mode, plic_irq_callback_t callback, void *userdata)
{
kpu->interrupt_clear.reg = 7;
kpu->fifo_threshold.data = (kpu_config_fifo_threshold_t)
{
.fifo_full_threshold = 10, .fifo_empty_threshold = 1
};
kpu->eight_bit_mode.data = (kpu_config_eight_bit_mode_t)
{
.eight_bit_mode = eight_bit_mode
};
kpu->interrupt_mask.data = (kpu_config_interrupt_t)
{
kpu->fifo_threshold.data = (kpu_config_fifo_threshold_t){
.fifo_full_threshold = 10, .fifo_empty_threshold = 1};
kpu->eight_bit_mode.data = (kpu_config_eight_bit_mode_t){
.eight_bit_mode = eight_bit_mode};
kpu->interrupt_mask.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 0,
.layer_cfg_almost_full_int = 1
};
.layer_cfg_almost_full_int = 1};
plic_set_priority(IRQN_AI_INTERRUPT, 1);
plic_irq_register(IRQN_AI_INTERRUPT, callback, userdata);
@ -411,35 +391,27 @@ static void kpu_conv2d_core(kpu_layer_argument_t *layer)
void kpu_conv2d(kpu_layer_argument_t *layer)
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t)
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
kpu->interrupt_mask.data = (kpu_config_interrupt_t)
{
.layer_cfg_almost_full_int = 1};
kpu->interrupt_mask.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 0,
.layer_cfg_almost_full_int = 1
};
.layer_cfg_almost_full_int = 1};
kpu_conv2d_core(layer);
}
void kpu_conv2d_output(kpu_layer_argument_t *layer, dmac_channel_number_t dma_ch, uint8_t *dest, plic_irq_callback_t callback, void *userdata)
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t)
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
kpu->interrupt_mask.data = (kpu_config_interrupt_t)
{
.layer_cfg_almost_full_int = 1};
kpu->interrupt_mask.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
.layer_cfg_almost_full_int = 1};
layer->dma_parameter.data.send_data_out = 1;
sysctl_dma_select(dma_ch, SYSCTL_DMA_SELECT_AI_RX_REQ);
dmac_set_irq(dma_ch, callback, userdata, 1);
@ -453,18 +425,14 @@ void kpu_conv2d_output_full_add(kpu_layer_argument_t *layer, dmac_channel_number
uint32_t channels = layer->image_channel_num.data.o_ch_num + 1;
layer->interrupt_enabe.data.full_add = 1;
kpu->interrupt_clear.data = (kpu_config_interrupt_t)
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
kpu->interrupt_mask.data = (kpu_config_interrupt_t)
{
.layer_cfg_almost_full_int = 1};
kpu->interrupt_mask.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
.layer_cfg_almost_full_int = 1};
layer->dma_parameter.data.send_data_out = 1;
sysctl_dma_select(dma_ch, SYSCTL_DMA_SELECT_AI_RX_REQ);
dmac_set_irq(dma_ch, callback, userdata, 1);
@ -481,8 +449,10 @@ void kpu_add(const uint8_t *src1, const quantize_param_t *src1_param, const uint
for(i = 0; i < count; i++)
{
int value = ((*src1++ * q1.scale + q1.bias + *src2++ * q2.scale + q2.bias) - q3.bias) / q3.scale;
if (value < 0) value = 0;
if (value > 0xFF) value = 0xFF;
if(value < 0)
value = 0;
if(value > 0xFF)
value = 0xFF;
*dest++ = value;
}
}
@ -513,14 +483,15 @@ void kpu_global_average_pool(const uint8_t *src, const quantize_param_t *src_par
sum += *src++;
int value = ((sum * q1.scale + q1.bias) / kernel_size - q2.bias) / q2.scale;
if (value < 0) value = 0;
if (value > 0xFF) value = 0xFF;
if(value < 0)
value = 0;
if(value > 0xFF)
value = 0xFF;
y_origin[x] = value;
}
}
}
}
else
} else
{
for(oc = 0; oc < channels; oc++)
{
@ -530,8 +501,10 @@ void kpu_global_average_pool(const uint8_t *src, const quantize_param_t *src_par
sum += *src++;
int value = ((sum * q1.scale + q1.bias) / kernel_size - q2.bias) / q2.scale;
if (value < 0) value = 0;
if (value > 0xFF) value = 0xFF;
if(value < 0)
value = 0;
if(value > 0xFF)
value = 0xFF;
dest[oc] = value;
}
}
@ -584,7 +557,6 @@ void kpu_dequantize(const uint8_t *src, const quantize_param_t *src_param, size_
*dest++ = src[i] * q1.scale + q1.bias;
}
void kpu_input_with_padding(kpu_layer_argument_t *layer, const uint8_t *src, int width, int height, int channels)
{
uint8_t *dest = (uint8_t *)(uintptr_t)(AI_IO_BASE_ADDR + layer->image_addr.data.image_src_addr * 64);
@ -599,14 +571,12 @@ void kpu_input_with_padding(kpu_layer_argument_t *layer, const uint8_t *src, int
row_padding = 16;
row_group = 4;
row_length = 1;
}
else if (width <= 32)
} else if(width <= 32)
{
row_padding = 32;
row_group = 2;
row_length = 1;
}
else
} else
{
row_padding = 64;
row_group = 1;
@ -649,8 +619,7 @@ static int64_t kpu_carry_shift(int64_t value, uint32_t shift)
value = (value >> 1) - 1;
else
value = (value >> 1) + 1;
}
else
} else
{
value >>= 1;
}
@ -670,14 +639,12 @@ static void kpu_upload_core(size_t width, size_t height, size_t channels, const
row_padding = 16;
row_group = 4;
row_length = 1;
}
else if (width <= 32)
} else if(width <= 32)
{
row_padding = 32;
row_group = 2;
row_length = 1;
}
else
} else
{
row_padding = 64;
row_group = 1;
@ -692,7 +659,7 @@ static void kpu_upload_core(size_t width, size_t height, size_t channels, const
uint8_t *channel_origin = dest + oc / row_group * row_length * height * 64 + oc % row_group * row_padding; \
for(y = 0; y < height; y++) \
{ \
uint64_t* y_origin = (uint64_t*)(channel_origin + y * row_length * 64); \
uint64_t *y_origin = (uint64_t *)(channel_origin + y * row_length * 64);
#define UPLOAD_END() \
} \
@ -705,8 +672,7 @@ static void kpu_upload_core(size_t width, size_t height, size_t channels, const
UPLOAD_BEGIN()
y_origin[0] = *u64_src++;
UPLOAD_END()
}
else if (width == 2)
} else if(width == 2)
{
UPLOAD_BEGIN()
{
@ -714,8 +680,7 @@ static void kpu_upload_core(size_t width, size_t height, size_t channels, const
y_origin[1] = *u64_src++;
}
UPLOAD_END()
}
else if (width == 4)
} else if(width == 4)
{
UPLOAD_BEGIN()
{
@ -725,16 +690,14 @@ static void kpu_upload_core(size_t width, size_t height, size_t channels, const
y_origin[3] = *u64_src++;
}
UPLOAD_END()
}
else
} else
{
UPLOAD_BEGIN()
for(x = 0; x < width; x++)
y_origin[x] = *u64_src++;
UPLOAD_END()
}
}
else
} else
{
for(oc = 0; oc < channels; oc++)
{
@ -770,8 +733,7 @@ static void kpu_float_activation(float *data, size_t count, kpu_model_activation
{
for(i = 0; i < count; i++)
data[i] = max(data[i], 0);
}
else if (act == KLA_RELU6)
} else if(act == KLA_RELU6)
{
for(i = 0; i < count; i++)
data[i] = min(max(data[i], 0), 6);
@ -859,8 +821,7 @@ static void kpu_quantized_add(const kpu_model_quant_add_layer_argument_t *arg, k
QADD_UNROLL_S(9);
QADD_UNROLL_S(10);
}
}
else
} else
{
#undef QADD_UNROLL_1
#define QADD_UNROLL_1(x) \
@ -1041,7 +1002,8 @@ static void kpu_average_pool2d(const kpu_model_ave_pool2d_layer_argument_t *arg,
static void kpu_quantize(const kpu_model_quantize_layer_argument_t *arg, kpu_model_context_t *ctx)
{
size_t count = arg->count;
const float *src = (const float *)(ctx->main_buffer + arg->main_mem_in_address);;
const float *src = (const float *)(ctx->main_buffer + arg->main_mem_in_address);
;
const kpu_model_quant_param_t q = arg->quant_param;
float scale = 1.f / q.scale;
@ -1050,8 +1012,10 @@ static void kpu_quantize(const kpu_model_quantize_layer_argument_t *arg, kpu_mod
for(i = 0; i < count; i++)
{
int value = roundf((*src++ - q.bias) * scale);
if (value < 0) value = 0;
if (value > 0xFF) value = 0xFF;
if(value < 0)
value = 0;
if(value > 0xFF)
value = 0xFF;
*dest++ = (uint8_t)value;
}
}
@ -1102,8 +1066,7 @@ static void kpu_requantize(const kpu_model_requantize_layer_argument_t *arg, kpu
dest[oc++] = table[*src++];
dest[oc++] = table[*src++];
}
}
else
} else
{
for(oc = 0; oc < count; oc++)
dest[oc] = table[src[oc]];
@ -1203,8 +1166,7 @@ static void kpu_kmodel_fully_connected(const kpu_model_fully_connected_layer_arg
dest[oc] = sum + bias[oc];
}
}
else
} else
{
for(oc = 0; oc < out_channels; oc++)
{
@ -1308,18 +1270,14 @@ static void kpu_conv(const kpu_model_conv_layer_argument_t *arg, kpu_model_conte
{
dmac_channel_number_t dma_ch = ctx->dma_ch;
uint8_t *dest = ctx->main_buffer + arg->main_mem_out_address;
kpu->interrupt_clear.data = (kpu_config_interrupt_t)
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
kpu->interrupt_mask.data = (kpu_config_interrupt_t)
{
.layer_cfg_almost_full_int = 1};
kpu->interrupt_mask.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
.layer_cfg_almost_full_int = 1};
layer.dma_parameter.data.send_data_out = 1;
sysctl_dma_select(dma_ch, SYSCTL_DMA_SELECT_AI_RX_REQ);
if(ctx->current_layer != ctx->layers_length)
@ -1328,22 +1286,17 @@ static void kpu_conv(const kpu_model_conv_layer_argument_t *arg, kpu_model_conte
dmac_set_irq(dma_ch, (plic_irq_callback_t)kpu_kmodel_done, ctx, 1);
dmac_set_single_mode(dma_ch, (void *)(&kpu->fifo_data_out), dest, DMAC_ADDR_NOCHANGE, DMAC_ADDR_INCREMENT,
DMAC_MSIZE_8, DMAC_TRANS_WIDTH_64, (layer.dma_parameter.data.dma_total_byte + 8) / 8);
}
else
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t)
} else
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
.layer_cfg_almost_full_int = 1};
kpu->interrupt_mask.data = (kpu_config_interrupt_t)
{
kpu->interrupt_mask.data = (kpu_config_interrupt_t){
.calc_done_int = 0,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
.layer_cfg_almost_full_int = 1};
layer.interrupt_enabe.data.int_en = 1;
}
@ -1417,8 +1370,7 @@ int kpu_load_kmodel(kpu_model_context_t *ctx, const uint8_t *buffer)
ctx->main_buffer = (uint8_t *)malloc(header->main_mem_usage);
if(!ctx->main_buffer)
return -1;
}
else
} else
{
return -1;
}
@ -1505,18 +1457,14 @@ static const char *str_layer_type(uint32_t type)
static int kpu_kmodel_done(kpu_model_context_t *ctx)
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t)
{
kpu->interrupt_clear.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
kpu->interrupt_mask.data = (kpu_config_interrupt_t)
{
.layer_cfg_almost_full_int = 1};
kpu->interrupt_mask.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 1,
.layer_cfg_almost_full_int = 1
};
.layer_cfg_almost_full_int = 1};
#if KPU_DEBUG
uint32_t cnt_layer_id = ctx->current_layer - 1;
uint64_t time = sysctl_get_time_us();
@ -1660,20 +1608,14 @@ int kpu_run_kmodel(kpu_model_context_t *ctx, const uint8_t *src, dmac_channel_nu
kpu_kmodel_header_t *header = (kpu_kmodel_header_t *)ctx->model_buffer;
kpu->interrupt_clear.reg = 7;
kpu->fifo_threshold.data = (kpu_config_fifo_threshold_t)
{
.fifo_full_threshold = 10, .fifo_empty_threshold = 1
};
kpu->eight_bit_mode.data = (kpu_config_eight_bit_mode_t)
{
.eight_bit_mode = header->flags & 1
};
kpu->interrupt_mask.data = (kpu_config_interrupt_t)
{
kpu->fifo_threshold.data = (kpu_config_fifo_threshold_t){
.fifo_full_threshold = 10, .fifo_empty_threshold = 1};
kpu->eight_bit_mode.data = (kpu_config_eight_bit_mode_t){
.eight_bit_mode = header->flags & 1};
kpu->interrupt_mask.data = (kpu_config_interrupt_t){
.calc_done_int = 1,
.layer_cfg_almost_empty_int = 0,
.layer_cfg_almost_full_int = 1
};
.layer_cfg_almost_full_int = 1};
plic_set_priority(IRQN_AI_INTERRUPT, 1);
plic_irq_register(IRQN_AI_INTERRUPT, ai_step, ctx);
@ -1692,8 +1634,7 @@ int kpu_run_kmodel(kpu_model_context_t *ctx, const uint8_t *src, dmac_channel_nu
{
kpu_kmodel_input_with_padding(&layer_arg, src);
ai_step_not_isr(ctx);
}
else
} else
{
kpu_input_dma(&layer_arg, src, ctx->dma_ch, ai_step, ctx);
}
@ -1712,4 +1653,3 @@ int kpu_run_kmodel(kpu_model_context_t *ctx, const uint8_t *src, dmac_channel_nu
return 0;
}

View File

@ -12,13 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "timer.h"
#include <stddef.h>
#include "io.h"
#include "plic.h"
#include "pwm.h"
#include "sysctl.h"
#include <stddef.h>
#include "timer.h"
#include "utils.h"
#include "plic.h"
#include "io.h"
void pwm_init(pwm_device_number_t pwm_number)
{
@ -34,8 +34,7 @@ void pwm_set_enable(pwm_device_number_t pwm_number, pwm_channel_number_t channel
if(timer[pwm_number]->load_count2[channel] == 0)
timer[pwm_number]->load_count2[channel] = 1;
timer[pwm_number]->channel[channel].control = TIMER_CR_INTERRUPT_MASK | TIMER_CR_PWM_ENABLE | TIMER_CR_USER_MODE | TIMER_CR_ENABLE;
}
else
} else
{
timer[pwm_number]->channel[channel].control = TIMER_CR_INTERRUPT_MASK;
}
@ -55,4 +54,3 @@ double pwm_set_frequency(pwm_device_number_t pwm_number, pwm_channel_number_t ch
return frequency;
}

View File

@ -13,12 +13,12 @@
* limitations under the License.
*/
#include <stdint.h>
#include <time.h>
#include <stdlib.h>
#include <time.h>
#include "encoding.h"
#include "sysctl.h"
#include "rtc.h"
#include "printf.h"
#include "rtc.h"
#include "sysctl.h"
volatile rtc_t *const rtc = (volatile rtc_t *)RTC_BASE_ADDR;
@ -40,8 +40,7 @@ typedef struct _rtc_instance_t
rtc_tick_interrupt_mode_t tick_mode_by_alarm;
} rtc_instance_t;
rtc_instance_t rtc_instance = (rtc_instance_t)
{
rtc_instance_t rtc_instance = (rtc_instance_t){
.tick_mode_by_user = -1,
.tick_mode_by_alarm = RTC_INT_MAX,
};
@ -50,7 +49,8 @@ int rtc_timer_set_mode(rtc_timer_mode_t timer_mode)
{
rtc_register_ctrl_t register_ctrl = rtc->register_ctrl;
switch (timer_mode) {
switch(timer_mode)
{
case RTC_TIMER_PAUSE:
register_ctrl.read_enable = 0;
register_ctrl.write_enable = 0;
@ -89,16 +89,20 @@ rtc_timer_mode_t rtc_timer_get_mode(void)
rtc_register_ctrl_t register_ctrl = rtc->register_ctrl;
rtc_timer_mode_t timer_mode = RTC_TIMER_PAUSE;
if ((!register_ctrl.read_enable) && (!register_ctrl.write_enable)) {
if((!register_ctrl.read_enable) && (!register_ctrl.write_enable))
{
/* RTC_TIMER_PAUSE */
timer_mode = RTC_TIMER_PAUSE;
} else if ((register_ctrl.read_enable) && (!register_ctrl.write_enable)) {
} else if((register_ctrl.read_enable) && (!register_ctrl.write_enable))
{
/* RTC_TIMER_RUNNING */
timer_mode = RTC_TIMER_RUNNING;
} else if ((!register_ctrl.read_enable) && (register_ctrl.write_enable)) {
} else if((!register_ctrl.read_enable) && (register_ctrl.write_enable))
{
/* RTC_TIMER_SETTING */
timer_mode = RTC_TIMER_RUNNING;
} else {
} else
{
/* Something is error, reset timer mode */
rtc_timer_set_mode(timer_mode);
}
@ -117,7 +121,8 @@ int rtc_timer_set_tm(const struct tm *tm)
rtc_time_t timer_time;
rtc_extended_t timer_extended;
if (tm) {
if(tm)
{
/*
* Range of tm->tm_sec could be [0,61]
*
@ -167,7 +172,8 @@ int rtc_timer_set_tm(const struct tm *tm)
int rtc_century = human_year / 100;
if(rtc_in_range(rtc_year, 0, 99) &&
rtc_in_range(rtc_century, 0, 31)) {
rtc_in_range(rtc_century, 0, 31))
{
timer_date.year = rtc_year;
timer_extended.century = rtc_century;
} else
@ -197,7 +203,8 @@ int rtc_alarm_set_tm(const struct tm *tm)
rtc_alarm_date_t alarm_date;
rtc_alarm_time_t alarm_time;
if (tm) {
if(tm)
{
/*
* Range of tm->tm_sec could be [0,61]
*
@ -247,7 +254,8 @@ int rtc_alarm_set_tm(const struct tm *tm)
int rtc_century = human_year / 100;
if(rtc_in_range(rtc_year, 0, 99) &&
rtc_in_range(rtc_century, 0, 31)) {
rtc_in_range(rtc_century, 0, 31))
{
alarm_date.year = rtc_year;
} else
return -1;
@ -279,8 +287,7 @@ int rtc_get_yday(int year, int month, int day)
{
static const int days[2][13] = {
{0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
{0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
};
{0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}};
int leap = rtc_year_is_leap(year);
return days[leap][month] + day;
@ -362,7 +369,8 @@ int rtc_timer_get(int *year, int *month, int *day, int *hour, int *minute, int *
{
struct tm *tm = rtc_timer_get_tm();
if (tm) {
if(tm)
{
if(year)
*year = tm->tm_year + 1900;
if(month)
@ -402,7 +410,8 @@ int rtc_alarm_get(int *year, int *month, int *day, int *hour, int *minute, int *
{
struct tm *tm = rtc_alarm_get_tm();
if (tm) {
if(tm)
{
if(year)
*year = tm->tm_year + 1900;
if(month)
@ -563,13 +572,15 @@ int rtc_protect_set(int enable)
.year = 0, /* Year mask */
};
if (enable) {
if(enable)
{
/* Turn RTC in protect mode, no one can write time */
register_ctrl.timer_mask = *(uint8_t *)&unmask;
register_ctrl.alarm_mask = *(uint8_t *)&unmask;
register_ctrl.initial_count_mask = 0;
register_ctrl.interrupt_register_mask = 0;
} else {
} else
{
/* Turn RTC in unprotect mode, everyone can write time */
register_ctrl.timer_mask = *(uint8_t *)&mask;
register_ctrl.alarm_mask = *(uint8_t *)&mask;
@ -591,8 +602,7 @@ int rtc_init(void)
rtc_protect_set(0);
/* Set RTC clock frequency */
rtc_timer_set_clock_frequency(
sysctl_clock_get_freq(SYSCTL_CLOCK_IN0)
);
sysctl_clock_get_freq(SYSCTL_CLOCK_IN0));
rtc_timer_set_clock_count_value(1);
/* Set RTC mode to timer running mode */
rtc_timer_set_mode(RTC_TIMER_RUNNING);
@ -667,8 +677,7 @@ int rtc_irq_callback(void *ctx)
rtc_tick_set_interrupt_mode(instance->tick_mode_by_user);
rtc_tick_set_interrupt(1);
}
}
else
} else
{
rtc_tick_set_interrupt(0);
}
@ -780,8 +789,7 @@ int rtc_alarm_irq_register(bool is_single_shot, rtc_mask_t mask, plic_irq_callba
{
rtc_instance.tick_mode_by_alarm = RTC_INT_HOUR;
goto alarm_mode;
}
else
} else
{
rtc_instance.tick_mode_by_alarm = RTC_INT_DAY;
}
@ -819,8 +827,7 @@ void rtc_alarm_irq_unregister(void)
rtc_tick_set_interrupt_mode(rtc_instance.tick_mode_by_user);
rtc_tick_set_interrupt(1);
}
}
else
} else
{
rtc_tick_set_interrupt(0);
}
@ -830,4 +837,3 @@ void rtc_alarm_irq_unregister(void)
plic_irq_unregister(IRQN_RTC_INTERRUPT);
}
}

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#include <string.h>
#include "sysctl.h"
#include "sha256.h"
#include "sysctl.h"
#include "utils.h"
#define ROTL(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
@ -32,8 +32,7 @@ static const uint8_t padding[64] =
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static inline uint64_t byteswap64(uint64_t x)
{
@ -117,4 +116,3 @@ void sha256_hard_calculate(const uint8_t *input, size_t input_len, uint8_t *outp
sha256_update(&sha, input, input_len);
sha256_final(&sha, output);
}

View File

@ -12,24 +12,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "platform.h"
#include "spi.h"
#include "fpioa.h"
#include "utils.h"
#include "gpiohs.h"
#include "sysctl.h"
#include <bsp.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <bsp.h>
#include "fpioa.h"
#include "gpiohs.h"
#include "platform.h"
#include "spi.h"
#include "sysctl.h"
#include "utils.h"
volatile spi_t *const spi[4] =
{
(volatile spi_t *)SPI0_BASE_ADDR,
(volatile spi_t *)SPI1_BASE_ADDR,
(volatile spi_t *)SPI_SLAVE_BASE_ADDR,
(volatile spi_t *)SPI3_BASE_ADDR
};
(volatile spi_t *)SPI3_BASE_ADDR};
typedef struct _spi_dma_context
{
@ -92,7 +91,8 @@ static int spi_dma_irq(void *ctx)
spi_instance_t *v_instance = (spi_instance_t *)ctx;
volatile spi_t *spi_handle = spi[v_instance->spi_num];
dmac_irq_unregister(v_instance->dmac_channel);
while ((spi_handle->sr & 0x05) != 0x04);
while((spi_handle->sr & 0x05) != 0x04)
;
spi_handle->ser = 0x00;
spi_handle->ssienr = 0x00;
spinlock_unlock(&v_instance->lock);
@ -227,8 +227,7 @@ uint32_t spi_set_clk_rate(spi_device_num_t spi_num, uint32_t spi_clk)
if(spi_baudr < 2)
{
spi_baudr = 2;
}
else if(spi_baudr > 65534)
} else if(spi_baudr > 65534)
{
spi_baudr = 65534;
}
@ -288,8 +287,7 @@ void spi_send_data_normal(spi_device_num_t spi_num, spi_chip_select_t chip_selec
spi_handle->dr[0] = v_send_data;
i += 4;
}
}
else
} else
{
for(index = 0; index < fifo_len / 4; index++)
spi_handle->dr[0] = ((uint32_t *)tx_buff)[i++];
@ -305,8 +303,7 @@ void spi_send_data_normal(spi_device_num_t spi_num, spi_chip_select_t chip_selec
spi_handle->dr[0] = v_send_data;
i += 2;
}
}
else
} else
{
for(index = 0; index < fifo_len / 2; index++)
spi_handle->dr[0] = ((uint16_t *)tx_buff)[i++];
@ -323,7 +320,6 @@ void spi_send_data_normal(spi_device_num_t spi_num, spi_chip_select_t chip_selec
;
spi_handle->ser = 0x00;
spi_handle->ssienr = 0x00;
}
void spi_send_data_standard(spi_device_num_t spi_num, spi_chip_select_t chip_select, const uint8_t *cmd_buff,
@ -690,7 +686,6 @@ void spi_receive_data_normal_dma(dmac_channel_number_t dma_send_channel_num,
spi_handle->ssienr = 0x00;
}
void spi_receive_data_standard_dma(dmac_channel_number_t dma_send_channel_num,
dmac_channel_number_t dma_receive_channel_num,
spi_device_num_t spi_num, spi_chip_select_t chip_select, const uint8_t *cmd_buff,
@ -852,7 +847,6 @@ void spi_receive_data_multiple(spi_device_num_t spi_num, spi_chip_select_t chip_
spi_handle->ser = 0x00;
spi_handle->ssienr = 0x00;
}
void spi_receive_data_multiple_dma(dmac_channel_number_t dma_send_channel_num,
@ -1114,8 +1108,7 @@ static void spi_slave_command_mode(void)
spi[2]->rxftlr = g_instance.command.len / data_width - 1;
spi_handle->imr = 0x00;
spi_handle->ssienr = 0x01;
}
else if (g_instance.command.cmd == READ_CONFIG)
} else if(g_instance.command.cmd == READ_CONFIG)
{
spi_handle->ctrlr0 = (0x0 << g_instance.work_mode) | (0x0 << g_instance.slv_oe) | ((g_instance.data_bit_length - 1) << g_instance.dfs);
spi_set_tmod(2, SPI_TMOD_TRANS);
@ -1143,15 +1136,13 @@ static void spi_slave_command_mode(void)
}
break;
}
}
else if (g_instance.command.cmd == WRITE_DATA_BYTE)
} else if(g_instance.command.cmd == WRITE_DATA_BYTE)
{
spi_handle->ctrlr0 = (0x0 << g_instance.work_mode) | (0x1 << g_instance.slv_oe) | ((g_instance.data_bit_length - 1) << g_instance.dfs);
spi[2]->rxftlr = g_instance.command.len / data_width - 1;
spi_handle->imr = 0x00;
spi_handle->ssienr = 0x01;
}
else if (g_instance.command.cmd == READ_DATA_BYTE)
} else if(g_instance.command.cmd == READ_DATA_BYTE)
{
spi_handle->ctrlr0 = (0x0 << g_instance.work_mode) | (0x0 << g_instance.slv_oe) | ((g_instance.data_bit_length - 1) << g_instance.dfs);
spi_set_tmod(2, SPI_TMOD_TRANS);
@ -1179,8 +1170,7 @@ static void spi_slave_command_mode(void)
}
break;
}
}
else if (g_instance.command.cmd == WRITE_DATA_BLOCK)
} else if(g_instance.command.cmd == WRITE_DATA_BLOCK)
{
spi_handle->ctrlr0 = (0x0 << g_instance.work_mode) | (0x1 << g_instance.slv_oe) | ((32 - 1) << g_instance.dfs);
@ -1192,8 +1182,7 @@ static void spi_slave_command_mode(void)
dmac_set_single_mode(g_instance.dmac_channel, (void *)(&spi_handle->dr[0]), (void *)((uintptr_t)g_instance.command.addr & 0xFFFFFFF0), DMAC_ADDR_NOCHANGE, DMAC_ADDR_INCREMENT,
DMAC_MSIZE_4, DMAC_TRANS_WIDTH_32, g_instance.command.len * 4);
}
else if (g_instance.command.cmd == READ_DATA_BLOCK)
} else if(g_instance.command.cmd == READ_DATA_BLOCK)
{
spi_handle->ctrlr0 = (0x0 << g_instance.work_mode) | (0x0 << g_instance.slv_oe) | ((32 - 1) << g_instance.dfs);
spi_set_tmod(2, SPI_TMOD_TRANS);
@ -1204,8 +1193,7 @@ static void spi_slave_command_mode(void)
sysctl_dma_select(g_instance.dmac_channel, SYSCTL_DMA_SELECT_SSI0_TX_REQ + spi_num * 2);
dmac_set_single_mode(g_instance.dmac_channel, (void *)((uintptr_t)g_instance.command.addr & 0xFFFFFFF0), (void *)(&spi_handle->dr[0]), DMAC_ADDR_INCREMENT, DMAC_ADDR_NOCHANGE,
DMAC_MSIZE_4, DMAC_TRANS_WIDTH_32, g_instance.command.len * 4);
}
else
} else
{
spi_slave_idle_mode();
return;
@ -1236,8 +1224,7 @@ static void spi_slave_transfer_mode(void)
{
if(spi_handle->rxflr < command_len - 1)
g_instance.command.err = 1;
}
else if (g_instance.command.cmd == READ_CONFIG || g_instance.command.cmd == READ_DATA_BYTE)
} else if(g_instance.command.cmd == READ_CONFIG || g_instance.command.cmd == READ_DATA_BYTE)
{
if(spi_handle->txflr != 0)
g_instance.command.err = 2;
@ -1245,8 +1232,7 @@ static void spi_slave_transfer_mode(void)
{
if(dmac->channel[g_instance.dmac_channel].intstatus != 0x02)
g_instance.command.err = 3;
}
else
} else
{
spi_slave_idle_mode();
return;
@ -1277,8 +1263,7 @@ static void spi_slave_transfer_mode(void)
}
break;
}
}
else if (g_instance.command.cmd == WRITE_DATA_BYTE)
} else if(g_instance.command.cmd == WRITE_DATA_BYTE)
{
switch(frame_width)
{
@ -1475,8 +1460,7 @@ void spi_handle_data_dma(spi_device_num_t spi_num, spi_chip_select_t chip_select
{
dmac_irq_register(data.tx_channel, spi_dma_irq, &g_spi_instance[spi_num], cb->priority);
g_spi_instance[spi_num].dmac_channel = data.tx_channel;
}
else
} else
{
dmac_irq_register(data.rx_channel, spi_dma_irq, &g_spi_instance[spi_num], cb->priority);
g_spi_instance[spi_num].dmac_channel = data.rx_channel;
@ -1510,4 +1494,3 @@ void spi_handle_data_dma(spi_device_num_t spi_num, spi_chip_select_t chip_select
spi_handle->ssienr = 0x00;
}
}

View File

@ -12,14 +12,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include "sysctl.h"
#include "string.h"
#include "encoding.h"
#include <stdlib.h>
#include "bsp.h"
#include "encoding.h"
#include "string.h"
#include "sysctl.h"
#include "uart.h"
#define SYSCTRL_CLOCK_FREQ_IN0 (26000000UL)
@ -1144,8 +1144,7 @@ static uint32_t sysctl_pll_source_set_freq(sysctl_pll_t pll, sysctl_clock_source
if((no > 1) && (!firstx))
continue;
/* wait for larger nf in later iterations */
}
else
} else
{
nrx /= no;
nfx *= nor;
@ -1843,16 +1842,13 @@ sysctl_reset_enum_status_t sysctl_get_reset_status(void)
if(sysctl->reset_status.wdt0_reset_sts)
{
s_reset_status = SYSCTL_RESET_STATUS_WDT0;
}
else if(sysctl->reset_status.wdt1_reset_sts)
} else if(sysctl->reset_status.wdt1_reset_sts)
{
s_reset_status = SYSCTL_RESET_STATUS_WDT1;
}
else if(sysctl->reset_status.soft_reset_sts)
} else if(sysctl->reset_status.soft_reset_sts)
{
s_reset_status = SYSCTL_RESET_STATUS_SOFT;
}
else
} else
{
s_reset_status = SYSCTL_RESET_STATUS_HARD;
}
@ -1860,4 +1856,3 @@ sysctl_reset_enum_status_t sysctl_get_reset_status(void)
return s_reset_status;
}

View File

@ -14,12 +14,12 @@
*/
#include <syslog.h>
#include "timer.h"
#include "sysctl.h"
#include "stddef.h"
#include "utils.h"
#include "plic.h"
#include "io.h"
#include "plic.h"
#include "stddef.h"
#include "sysctl.h"
#include "timer.h"
#include "utils.h"
/**
* @brief Private definitions for the timer instance
@ -37,8 +37,7 @@ volatile kendryte_timer_t *const timer[3] =
{
(volatile kendryte_timer_t *)TIMER0_BASE_ADDR,
(volatile kendryte_timer_t *)TIMER1_BASE_ADDR,
(volatile kendryte_timer_t *)TIMER2_BASE_ADDR
};
(volatile kendryte_timer_t *)TIMER2_BASE_ADDR};
void timer_init(timer_device_number_t timer_number)
{
@ -54,9 +53,7 @@ void timer_init(timer_device_number_t timer_number)
void timer_set_clock_div(timer_device_number_t timer_number, uint32_t div)
{
sysctl_clock_set_threshold(timer_number == 0 ? SYSCTL_THRESHOLD_TIMER0 :
timer_number == 1 ? SYSCTL_THRESHOLD_TIMER1 :
SYSCTL_THRESHOLD_TIMER2, div);
sysctl_clock_set_threshold(timer_number == 0 ? SYSCTL_THRESHOLD_TIMER0 : timer_number == 1 ? SYSCTL_THRESHOLD_TIMER1 : SYSCTL_THRESHOLD_TIMER2, div);
}
void timer_enable(timer_device_number_t timer_number, timer_channel_number_t channel)
@ -202,8 +199,7 @@ void timer_set_irq(timer_device_number_t timer_number, timer_channel_number_t ch
plic_set_priority(IRQN_TIMER0A_INTERRUPT + timer_number * 2, priority);
plic_irq_register(IRQN_TIMER0A_INTERRUPT + timer_number * 2, timer_isr, (void *)timer[timer_number]);
plic_irq_enable(IRQN_TIMER0A_INTERRUPT + timer_number * 2);
}
else
} else
{
plic_set_priority(IRQN_TIMER0B_INTERRUPT + timer_number * 2, priority);
plic_irq_register(IRQN_TIMER0B_INTERRUPT + timer_number * 2, timer_isr, (void *)timer[timer_number]);
@ -221,7 +217,8 @@ void timer_set_irq(timer_device_number_t timer_number, timer_channel_number_t ch
*/
static plic_irq_t get_timer_irqn_by_device_and_channel(timer_device_number_t device, timer_channel_number_t channel)
{
if (device < TIMER_DEVICE_MAX && channel < TIMER_CHANNEL_MAX) {
if(device < TIMER_DEVICE_MAX && channel < TIMER_CHANNEL_MAX)
{
/*
* Select timer interrupt part
* Hierarchy of Timer interrupt to PLIC
@ -256,11 +253,12 @@ static plic_irq_t get_timer_irqn_by_device_and_channel(timer_device_number_t dev
* +---------+ +-----------+
*
*/
if (channel < 2) {
if(channel < 2)
{
/* It is part A interrupt, offset + 0 */
return IRQN_TIMER0A_INTERRUPT + device * 2;
}
else {
} else
{
/* It is part B interrupt, offset + 1 */
return IRQN_TIMER0B_INTERRUPT + device * 2;
}
@ -285,11 +283,13 @@ static int timer_interrupt_handler(timer_device_number_t device, void *ctx)
/* Check every bit for interrupt status */
if(channel_int_stat & 1)
{
if (timer_instance[device][i].callback) {
if(timer_instance[device][i].callback)
{
/* Process user callback function */
timer_instance[device][i].callback(timer_instance[device][i].ctx);
/* Check if this timer is a single shot timer */
if (timer_instance[device][i].single_shot) {
if(timer_instance[device][i].single_shot)
{
/* Single shot timer, disable it */
timer_set_enable(device, i, 0);
}
@ -347,7 +347,8 @@ static int timer2_interrupt_callback(void *ctx)
int timer_irq_register(timer_device_number_t device, timer_channel_number_t channel, int is_single_shot, uint32_t priority, timer_callback_t callback, void *ctx)
{
if (device < TIMER_DEVICE_MAX && channel < TIMER_CHANNEL_MAX) {
if(device < TIMER_DEVICE_MAX && channel < TIMER_CHANNEL_MAX)
{
plic_irq_t irq_number = get_timer_irqn_by_device_and_channel(device, channel);
plic_irq_callback_t plic_irq_callback[TIMER_DEVICE_MAX] = {
timer0_interrupt_callback,
@ -370,7 +371,8 @@ int timer_irq_register(timer_device_number_t device, timer_channel_number_t chan
int timer_irq_unregister(timer_device_number_t device, timer_channel_number_t channel)
{
if (device < TIMER_DEVICE_MAX && channel < TIMER_CHANNEL_MAX) {
if(device < TIMER_DEVICE_MAX && channel < TIMER_CHANNEL_MAX)
{
timer_instance[device][channel] = (const timer_instance_t){
.callback = NULL,
.ctx = NULL,
@ -381,7 +383,8 @@ int timer_irq_unregister(timer_device_number_t device, timer_channel_number_t ch
if((!(timer_instance[device][TIMER_CHANNEL_0].callback ||
timer_instance[device][TIMER_CHANNEL_1].callback)) ||
(!(timer_instance[device][TIMER_CHANNEL_2].callback ||
timer_instance[device][TIMER_CHANNEL_3].callback))) {
timer_instance[device][TIMER_CHANNEL_3].callback)))
{
plic_irq_t irq_number = get_timer_irqn_by_device_and_channel(device, channel);
plic_irq_unregister(irq_number);
}

View File

@ -12,14 +12,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <stdint.h>
#include <stdlib.h>
#include "atomic.h"
#include "plic.h"
#include "syscalls.h"
#include "sysctl.h"
#include "uart.h"
#include "utils.h"
#include "atomic.h"
#include "syscalls.h"
#define __UART_BRATE_CONST 16
@ -27,8 +27,7 @@ volatile uart_t* const uart[3] =
{
(volatile uart_t *)UART1_BASE_ADDR,
(volatile uart_t *)UART2_BASE_ADDR,
(volatile uart_t*)UART3_BASE_ADDR
};
(volatile uart_t *)UART3_BASE_ADDR};
#define UART_INTERRUPT_SEND 0x02U
#define UART_INTERRUPT_RECEIVE 0x04U
@ -87,8 +86,7 @@ static int uart_irq_callback(void *param)
{
if(uart_instance->uart_send_instance.callback != NULL)
uart_instance->uart_send_instance.callback(uart_instance->uart_send_instance.ctx);
}
else if(v_int_status == UART_INTERRUPT_RECEIVE || v_int_status == UART_INTERRUPT_CHARACTER_TIMEOUT)
} else if(v_int_status == UART_INTERRUPT_RECEIVE || v_int_status == UART_INTERRUPT_CHARACTER_TIMEOUT)
{
if(uart_instance->uart_receive_instance.callback != NULL)
uart_instance->uart_receive_instance.callback(uart_instance->uart_receive_instance.ctx);
@ -140,8 +138,7 @@ void uart_debug_init(uart_device_number_t uart_channel)
{
sys_register_getchar(uart_debug_getchar);
sys_register_putchar(uart_debug_putchar);
}
else
} else
{
if(sys_getchar == NULL)
sys_register_getchar(uart_debug_getchar);
@ -271,7 +268,6 @@ void uart_send_data_dma_irq(uart_device_number_t uart_channel, dmac_channel_numb
sysctl_dma_select((sysctl_dma_channel_t)dmac_channel, SYSCTL_DMA_SELECT_UART1_TX_REQ + uart_channel * 2);
dmac_set_single_mode(dmac_channel, v_send_buf, (void *)(&uart[uart_channel]->THR), DMAC_ADDR_INCREMENT, DMAC_ADDR_NOCHANGE,
DMAC_MSIZE_1, DMAC_TRANS_WIDTH_32, buf_len);
}
void uart_configure(uart_device_number_t channel, uint32_t baud_rate, uart_bitwidth_t data_width, uart_stopbit_t stopbit, uart_parity_t parity)
@ -280,8 +276,7 @@ void uart_configure(uart_device_number_t channel, uint32_t baud_rate, uart_bitwi
if(data_width == 5)
{
configASSERT(stopbit != UART_STOP_2);
}
else
} else
{
configASSERT(stopbit != UART_STOP_1_5);
}
@ -349,8 +344,7 @@ void uart_irq_register(uart_device_number_t channel, uart_interrupt_mode_t inter
uart[channel]->IER |= 0x2;
g_uart_instance[channel].uart_send_instance.callback = uart_callback;
g_uart_instance[channel].uart_send_instance.ctx = ctx;
}
else if(interrupt_mode == UART_RECEIVE)
} else if(interrupt_mode == UART_RECEIVE)
{
uart[channel]->IER |= 0x1;
g_uart_instance[channel].uart_receive_instance.callback = uart_callback;
@ -369,8 +363,7 @@ void uart_irq_unregister(uart_device_number_t channel, uart_interrupt_mode_t int
uart[channel]->IER &= ~(0x2);
g_uart_instance[channel].uart_send_instance.callback = NULL;
g_uart_instance[channel].uart_send_instance.ctx = NULL;
}
else if(interrupt_mode == UART_RECEIVE)
} else if(interrupt_mode == UART_RECEIVE)
{
uart[channel]->IER &= ~(0x1);
g_uart_instance[channel].uart_receive_instance.callback = NULL;
@ -388,7 +381,8 @@ int uart_dma_irq(void *ctx)
dmac_irq_unregister(v_instance->dmac_channel);
if(v_instance->transfer_mode == UART_SEND)
{
while(!(uart[v_instance->uart_num]->LSR & (1u << 6)));
while(!(uart[v_instance->uart_num]->LSR & (1u << 6)))
;
}
spinlock_unlock(&v_instance->lock);
if(v_instance->uart_int_instance.callback)
@ -419,11 +413,11 @@ void uart_handle_data_dma(uart_device_number_t uart_channel ,uart_data_t data, p
if(!cb)
{
dmac_wait_done(data.tx_channel);
while(!(uart[uart_channel]->LSR & (1u << 6)));
while(!(uart[uart_channel]->LSR & (1u << 6)))
;
spinlock_unlock(&g_uart_send_instance_dma[uart_channel].lock);
}
}
else
} else
{
configASSERT(data.rx_buf && data.rx_len && data.rx_channel < DMAC_CHANNEL_MAX);
spinlock_lock(&g_uart_recv_instance_dma[uart_channel].lock);
@ -551,4 +545,3 @@ void uart_set_tat(uart_device_number_t uart_channel, uart_tat_mode_t tat_mode, s
break;
}
}

View File

@ -15,9 +15,9 @@
#include <stdint.h>
#include <stdio.h>
#include "uarths.h"
#include "sysctl.h"
#include "encoding.h"
#include "sysctl.h"
#include "uarths.h"
volatile uarths_t *const uarths = (volatile uarths_t *)UARTHS_BASE_ADDR;
@ -171,4 +171,3 @@ void uarths_config(uint32_t baud_rate, uarths_stopbit_t stopbit)
uarths->div.div = div;
uarths->txctrl.nstop = stopbit;
}

View File

@ -41,4 +41,3 @@ uint32_t get_gpio_bit(volatile uint32_t *bits, size_t offset)
{
return get_bit(bits, 1, offset);
}

View File

@ -12,19 +12,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "wdt.h"
#include "platform.h"
#include "stddef.h"
#include "utils.h"
#include "sysctl.h"
#include "plic.h"
#include "math.h"
#include "platform.h"
#include "plic.h"
#include "stddef.h"
#include "sysctl.h"
#include "utils.h"
#include "wdt.h"
volatile wdt_t *const wdt[2] =
{
(volatile wdt_t *)WDT0_BASE_ADDR,
(volatile wdt_t *)WDT1_BASE_ADDR
};
(volatile wdt_t *)WDT1_BASE_ADDR};
static void wdt_enable(wdt_device_number_t id)
{
@ -112,4 +111,3 @@ void wdt_stop(wdt_device_number_t id)
{
wdt_disable(id);
}

View File

@ -17,8 +17,8 @@
#include <stdint.h>
#include <stdio.h>
#include "printf.h"
#include "encoding.h"
#include "printf.h"
#ifdef __cplusplus
extern "C" {
@ -119,11 +119,36 @@ typedef enum _kendryte_log_level
#endif
#ifdef CONFIG_LOG_ENABLE
#define LOGE(tag, format, ...) do {if (CONFIG_LOG_LEVEL >= LOG_ERROR) LOG_PRINTF(LOG_FORMAT(E, format), read_cycle(), tag, ##__VA_ARGS__); } while (0)
#define LOGW(tag, format, ...) do {if (CONFIG_LOG_LEVEL >= LOG_WARN) LOG_PRINTF(LOG_FORMAT(W, format), read_cycle(), tag, ##__VA_ARGS__); } while (0)
#define LOGI(tag, format, ...) do {if (CONFIG_LOG_LEVEL >= LOG_INFO) LOG_PRINTF(LOG_FORMAT(I, format), read_cycle(), tag, ##__VA_ARGS__); } while (0)
#define LOGD(tag, format, ...) do {if (CONFIG_LOG_LEVEL >= LOG_DEBUG) LOG_PRINTF(LOG_FORMAT(D, format), read_cycle(), tag, ##__VA_ARGS__); } while (0)
#define LOGV(tag, format, ...) do {if (CONFIG_LOG_LEVEL >= LOG_VERBOSE) LOG_PRINTF(LOG_FORMAT(V, format), read_cycle(), tag, ##__VA_ARGS__); } while (0)
#define LOGE(tag, format, ...) \
do \
{ \
if(CONFIG_LOG_LEVEL >= LOG_ERROR) \
LOG_PRINTF(LOG_FORMAT(E, format), read_cycle(), tag, ##__VA_ARGS__); \
} while(0)
#define LOGW(tag, format, ...) \
do \
{ \
if(CONFIG_LOG_LEVEL >= LOG_WARN) \
LOG_PRINTF(LOG_FORMAT(W, format), read_cycle(), tag, ##__VA_ARGS__); \
} while(0)
#define LOGI(tag, format, ...) \
do \
{ \
if(CONFIG_LOG_LEVEL >= LOG_INFO) \
LOG_PRINTF(LOG_FORMAT(I, format), read_cycle(), tag, ##__VA_ARGS__); \
} while(0)
#define LOGD(tag, format, ...) \
do \
{ \
if(CONFIG_LOG_LEVEL >= LOG_DEBUG) \
LOG_PRINTF(LOG_FORMAT(D, format), read_cycle(), tag, ##__VA_ARGS__); \
} while(0)
#define LOGV(tag, format, ...) \
do \
{ \
if(CONFIG_LOG_LEVEL >= LOG_VERBOSE) \
LOG_PRINTF(LOG_FORMAT(V, format), read_cycle(), tag, ##__VA_ARGS__); \
} while(0)
#else
#define LOGE(tag, format, ...)
#define LOGW(tag, format, ...)
@ -136,6 +161,4 @@ typedef enum _kendryte_log_level
}
#endif
#endif /* _SYSLOG_H */

22
scripts/reformat-all.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
_CLANG_FORMAT=${CLANG_FORMAT-"clang-format"}
if ! command -v "$_CLANG_FORMAT" &>/dev/null ; then
echo "You must install clang-format and add it to your PATH." >&2
echo " See: http://releases.llvm.org/download.html" >&2
echo "Use CLANG_FORMAT=/path/to/clang-format if you do not want it in PATH. " >&2
exit 1
fi
cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
cd ..
DIFF_BEFORE=$(git diff | wc -l)
echo "Difference before format: $DIFF_BEFORE"
find lib -iname *.h -o -iname *.c -o -iname *.cpp -o -iname *.hpp | xargs "$_CLANG_FORMAT" -i
DIFF_AFTER=$(git diff | wc -l)
echo "Difference after format: $DIFF_AFTER (delta: $(($DIFF_BEFORE - $DIFF_AFTER)))"