From 51bba09ad0522224a5ef75b21b82ed14992928a9 Mon Sep 17 00:00:00 2001 From: zhangjun <2281979437@qq.com> Date: Mon, 31 Jul 2017 12:17:12 +0800 Subject: [PATCH] remove cpuusage.c remove unused line in SConstruct --- bsp/hifive1/SConstruct | 9 -- bsp/hifive1/applications/applications.c | 13 +-- bsp/hifive1/drivers/cpuusage.c | 75 --------------- bsp/hifive1/platform/plic_driver.c | 120 ++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 95 deletions(-) delete mode 100644 bsp/hifive1/drivers/cpuusage.c create mode 100644 bsp/hifive1/platform/plic_driver.c diff --git a/bsp/hifive1/SConstruct b/bsp/hifive1/SConstruct index 98b5712caf..c885c34448 100644 --- a/bsp/hifive1/SConstruct +++ b/bsp/hifive1/SConstruct @@ -25,14 +25,5 @@ Export('rtconfig') # prepare building environment objs = PrepareBuilding(env, RTT_ROOT) -if GetDepend('RT_USING_WEBSERVER'): - objs = objs + SConscript(RTT_ROOT + '/components/net/webserver/SConscript', variant_dir='build/net/webserver', duplicate=0) - -if GetDepend('RT_USING_RTGUI'): - objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0) - -# libc testsuite -#objs = objs + SConscript(RTT_ROOT + '/examples/libc/SConscript', variant_dir='build/examples/libc', duplicate=0) - # make a building DoBuilding(TARGET, objs) diff --git a/bsp/hifive1/applications/applications.c b/bsp/hifive1/applications/applications.c index aaae803c76..5211b7108a 100644 --- a/bsp/hifive1/applications/applications.c +++ b/bsp/hifive1/applications/applications.c @@ -17,22 +17,13 @@ static void led_thread_entry(void* parameter) rt_hw_led_init(); while (0) { - /* led1 on */ -#ifndef RT_USING_FINSH -/* rt_kprintf("led on, count : %d\r\n",count);*/ -#endif - rt_kprintf("core freq at %d Hz\n", get_cpu_freq()); - count++; - rt_thread_delay( RT_TIMER_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */ /* rt_hw_led_on(0);*/ + rt_thread_delay( RT_TIMER_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */ /* led1 off */ -#ifndef RT_USING_FINSH -/* rt_kprintf("led off\r\n");*/ -#endif rt_hw_led_off(0); -/* rt_thread_delay( RT_TIMER_TICK_PER_SECOND*2);*/ + rt_thread_delay( RT_TIMER_TICK_PER_SECOND*2); } } static rt_uint8_t led_stack[ 1024]; diff --git a/bsp/hifive1/drivers/cpuusage.c b/bsp/hifive1/drivers/cpuusage.c deleted file mode 100644 index 659c2807d6..0000000000 --- a/bsp/hifive1/drivers/cpuusage.c +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include "board.h" - -static rt_uint8_t cpu_usage_major = 0, cpu_usage_minor= 0; -static rt_uint32_t idle_begin = 0,idle_count = 0; -static rt_uint32_t run_begin = 0,run_count = 0; -static rt_uint32_t update_tick = 0; -static wtdog_count = 0; -#define jiffies rt_tick_get() - -void cpu_usage_idle_hook() -{ - wtdog_count = 0; -} - -void thread_switch_hook(struct rt_thread *from, struct rt_thread *to) -{ - //leave idle - if (from->init_priority == RT_THREAD_PRIORITY_MAX - 1) - { - run_begin = jiffies; - idle_count += jiffies-idle_begin; - } - //enter idle - if (to->init_priority == RT_THREAD_PRIORITY_MAX - 1) - { - idle_begin = jiffies; - run_count += jiffies-run_begin; - } - //enter main once 500ms - else if (to->init_priority == 2) - { - register rt_uint32_t total_count; - run_count += jiffies-run_begin; - run_begin = jiffies; - total_count = run_count+idle_count; - cpu_usage_major = (run_count * 100) / total_count; - cpu_usage_minor = ((run_count * 100) % total_count) * 100 / total_count; - idle_count = run_count = 0; - update_tick = rt_tick_get(); - } -} - -#if defined(RT_USING_FINSH) -#include -void cpu_usage() -{ - //long time no update?? 100% - if ((rt_tick_get() - update_tick) > 1000) - { - cpu_usage_major = 100; - cpu_usage_minor = 0; - } - rt_kprintf("Cpu Usage: %d.%d\n",cpu_usage_major,cpu_usage_minor); -} - -void rt_usage_info(rt_uint32_t *major, rt_uint32_t *minor) -{ - //long time no update?? 100% - if ((rt_tick_get() - update_tick) > 1000) - { - cpu_usage_major = 100; - cpu_usage_minor = 0; - } - if (major) - *major = cpu_usage_major; - if (minor) - *minor = cpu_usage_minor; -} -RTM_EXPORT(rt_usage_info); - -FINSH_FUNCTION_EXPORT(cpu_usage, cpu usage); -MSH_CMD_EXPORT(cpu_usage, cpu usage); -#endif //RT_USING_FINSH diff --git a/bsp/hifive1/platform/plic_driver.c b/bsp/hifive1/platform/plic_driver.c new file mode 100644 index 0000000000..b14aecfff6 --- /dev/null +++ b/bsp/hifive1/platform/plic_driver.c @@ -0,0 +1,120 @@ +#include "sifive/devices/plic.h" +#include "plic_driver.h" +#include "platform.h" +#include "encoding.h" +#include + +void volatile_memzero(uint8_t * base, unsigned int size) +{ + volatile uint8_t * ptr; + for (ptr = base; ptr < (base + size); ptr++){ + *ptr = 0; + } +} + +void PLIC_init ( + plic_instance_t * this_plic, + uintptr_t base_addr, + uint32_t num_sources, + uint32_t num_priorities + ) +{ + + this_plic->base_addr = base_addr; + this_plic->num_sources = num_sources; + this_plic->num_priorities = num_priorities; + + // Disable all interrupts (don't assume that these registers are reset). + unsigned long hart_id = read_csr(mhartid); + volatile_memzero((uint8_t*) (this_plic->base_addr + + PLIC_ENABLE_OFFSET + + (hart_id << PLIC_ENABLE_SHIFT_PER_TARGET)), + (num_sources + 8) / 8); + + // Set all priorities to 0 (equal priority -- don't assume that these are reset). + volatile_memzero ((uint8_t *)(this_plic->base_addr + + PLIC_PRIORITY_OFFSET), + (num_sources + 1) << PLIC_PRIORITY_SHIFT_PER_SOURCE); + + // Set the threshold to 0. + volatile plic_threshold* threshold = (plic_threshold*) + (this_plic->base_addr + + PLIC_THRESHOLD_OFFSET + + (hart_id << PLIC_THRESHOLD_SHIFT_PER_TARGET)); + + *threshold = 0; + +} + +void PLIC_set_threshold (plic_instance_t * this_plic, + plic_threshold threshold){ + + unsigned long hart_id = read_csr(mhartid); + volatile plic_threshold* threshold_ptr = (plic_threshold*) (this_plic->base_addr + + PLIC_THRESHOLD_OFFSET + + (hart_id << PLIC_THRESHOLD_SHIFT_PER_TARGET)); + + *threshold_ptr = threshold; + +} + + +void PLIC_enable_interrupt (plic_instance_t * this_plic, plic_source source){ + + unsigned long hart_id = read_csr(mhartid); + volatile uint8_t * current_ptr = (volatile uint8_t *)(this_plic->base_addr + + PLIC_ENABLE_OFFSET + + (hart_id << PLIC_ENABLE_SHIFT_PER_TARGET) + + (source >> 3)); + uint8_t current = *current_ptr; + current = current | ( 1 << (source & 0x7)); + *current_ptr = current; + +} + +void PLIC_disable_interrupt (plic_instance_t * this_plic, plic_source source){ + + unsigned long hart_id = read_csr(mhartid); + volatile uint8_t * current_ptr = (volatile uint8_t *) (this_plic->base_addr + + PLIC_ENABLE_OFFSET + + (hart_id << PLIC_ENABLE_SHIFT_PER_TARGET) + + (source >> 3)); + uint8_t current = *current_ptr; + current = current & ~(( 1 << (source & 0x7))); + *current_ptr = current; + +} + +void PLIC_set_priority (plic_instance_t * this_plic, plic_source source, plic_priority priority){ + + if (this_plic->num_priorities > 0) { + volatile plic_priority * priority_ptr = (volatile plic_priority *) + (this_plic->base_addr + + PLIC_PRIORITY_OFFSET + + (source << PLIC_PRIORITY_SHIFT_PER_SOURCE)); + *priority_ptr = priority; + } +} + +plic_source PLIC_claim_interrupt(plic_instance_t * this_plic){ + + unsigned long hart_id = read_csr(mhartid); + + volatile plic_source * claim_addr = (volatile plic_source * ) + (this_plic->base_addr + + PLIC_CLAIM_OFFSET + + (hart_id << PLIC_CLAIM_SHIFT_PER_TARGET)); + + return *claim_addr; + +} + +void PLIC_complete_interrupt(plic_instance_t * this_plic, plic_source source){ + + unsigned long hart_id = read_csr(mhartid); + volatile plic_source * claim_addr = (volatile plic_source *) (this_plic->base_addr + + PLIC_CLAIM_OFFSET + + (hart_id << PLIC_CLAIM_SHIFT_PER_TARGET)); + *claim_addr = source; + +}