Browse Source

[libcpu][c906] enable fpu, improve os ticks accuracy

jasonhu 3 years ago
parent
commit
2b3ff6ae8f

+ 2 - 2
libcpu/risc-v/t-head/c906/cpuport.c

@@ -72,8 +72,8 @@ rt_uint8_t *rt_hw_stack_init(void       *tentry,
     frame->epc     = (rt_ubase_t)tentry;
     frame->user_sp_exc_stack = (rt_ubase_t)(((rt_ubase_t)stk) + sizeof(struct rt_hw_stack_frame));
 
-    /* force to supervisor mode(SPP=1) and set SPIE and SUM to 1 */
-    frame->sstatus = 0x00040120;
+    /* force to supervisor mode(SPP=1) and set SPIE and SUM to 1, enable FPU */
+    frame->sstatus = 0x00042120;
 
     return stk;
 }

+ 5 - 16
libcpu/risc-v/t-head/c906/tick.c

@@ -13,13 +13,13 @@
 
 #include <encoding.h>
 #include "sbi.h"
-
-/* 100 ticks per second */
-#define TICK_CYCLE (4000 * 65)
+#include "tick.h"
 
 static volatile uint64_t time_elapsed = 0;
 static volatile unsigned long tick_cycles = 0;
 
+static unsigned long tick_delta = TIMER_CLK_FREQ / RT_TICK_PER_SECOND;
+
 static uint64_t get_ticks()
 {
     __asm__ __volatile__(
@@ -30,30 +30,19 @@ static uint64_t get_ticks()
 
 int tick_isr(void)
 {
-    // uint64_t core_id = current_coreid();
-    int tick_cycles = TICK_CYCLE;
-    // clint->mtimecmp[core_id] += tick_cycles;
     rt_tick_increase();
-    sbi_set_timer(get_ticks() + tick_cycles);
-
+    sbi_set_timer(get_ticks() + tick_delta);
     return 0;
 }
 
 /* Sets and enable the timer interrupt */
 int rt_hw_tick_init(void)
 {
-    /* Read core id */
-    // unsigned long core_id = current_coreid();
-    unsigned long interval = 1000/RT_TICK_PER_SECOND;
-
     /* Clear the Supervisor-Timer bit in SIE */
     clear_csr(sie, SIP_STIP);
 
-    /* calculate the tick cycles */
-    // tick_cycles = interval * sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / CLINT_CLOCK_DIV / 1000ULL - 1;
-    tick_cycles = TICK_CYCLE;
     /* Set timer */
-    sbi_set_timer(get_ticks() + tick_cycles);
+    sbi_set_timer(get_ticks() + tick_delta);
 
     /* Enable the Supervisor-Timer bit in SIE */
     set_csr(sie, SIP_STIP);

+ 3 - 0
libcpu/risc-v/t-head/c906/tick.h

@@ -11,6 +11,9 @@
 #ifndef TICK_H__
 #define TICK_H__
 
+/* timer clock is 24 MHZ */
+#define TIMER_CLK_FREQ  (24000000)
+
 int tick_isr(void);
 int rt_hw_tick_init(void);