first commit
This commit is contained in:
25
port/sys_arch.c
Normal file
25
port/sys_arch.c
Normal 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));
|
||||
}
|
||||
Reference in New Issue
Block a user