first commit

This commit is contained in:
2025-11-07 17:02:04 +06:00
commit d577c5193c
16 changed files with 951 additions and 0 deletions

25
port/sys_arch.c Normal file
View File

@@ -0,0 +1,25 @@
#include "ch32fun.h"
#include "lwip/def.h"
#include "systick.h"
typedef uint32_t sys_prot_t;
static unsigned long next = 1;
int rand(void) {
next = next * 1103515245 + 12345;
return (unsigned int)(next / 65536) % 32768;
}
void srand(unsigned int seed) { next = seed; }
uint32_t sys_now(void) { return systick_millis; }
sys_prot_t sys_arch_protect(void) {
unsigned int old_mstatus;
__asm__ volatile("csrrci %0, mstatus, 8" : "=r"(old_mstatus));
return old_mstatus;
}
void sys_arch_unprotect(sys_prot_t pval) {
__asm__ volatile("csrw mstatus, %0" : : "r"(pval));
}