diff options
| author | zhangjun <[email protected]> | 2017-07-30 19:46:28 +0800 |
|---|---|---|
| committer | zhangjun <[email protected]> | 2017-07-30 19:46:28 +0800 |
| commit | b032dff1616fe64a4dfec63e593f0fac634ef3ab (patch) | |
| tree | 0906b0617156a4e898713bea4669a459406c44a3 /bsp | |
| parent | 2d56a27c20d430f678a77e48f1d00591f4fc4c8b (diff) | |
fix bug in rt_hw_context_switch_interrupt_do
save sp to old thread
clear rt_thread_switch_interrupt_flag
always enable interrupt after rt_hw_context_switch
judeg the type of interrupt in trap_entry, then call handler(Machine timer interrupt of Machine external interrupt)
Diffstat (limited to 'bsp')
| -rw-r--r-- | bsp/risc-v/applications/applications.c | 9 | ||||
| -rw-r--r-- | bsp/risc-v/drivers/board.c | 14 | ||||
| -rw-r--r-- | bsp/risc-v/drivers/led.c | 149 |
3 files changed, 81 insertions, 91 deletions
diff --git a/bsp/risc-v/applications/applications.c b/bsp/risc-v/applications/applications.c index c26b4903d8..bba2b58053 100644 --- a/bsp/risc-v/applications/applications.c +++ b/bsp/risc-v/applications/applications.c @@ -15,17 +15,16 @@ static void led_thread_entry(void* parameter) unsigned int count=0; rt_hw_led_init(); - rt_kprintf("core freq at %d Hz\n", get_cpu_freq()); while (1) { /* 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 */ - while(1); - rt_hw_led_on(0); +/* rt_hw_led_on(0);*/ /* led1 off */ #ifndef RT_USING_FINSH @@ -33,10 +32,10 @@ static void led_thread_entry(void* parameter) #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[ 2048 ]; +static rt_uint8_t led_stack[ 1024]; static struct rt_thread led_thread; void rt_application_init() { diff --git a/bsp/risc-v/drivers/board.c b/bsp/risc-v/drivers/board.c index da324a83b1..3915d4bac3 100644 --- a/bsp/risc-v/drivers/board.c +++ b/bsp/risc-v/drivers/board.c @@ -14,11 +14,6 @@ static struct mem_desc hw_mem_desc[] = }; #endif -static void rt_systick_handler(int vector, void *param) -{ - rt_tick_increase(); - return; -} #include <encoding.h> static void rt_hw_timer_init(void) { @@ -26,11 +21,12 @@ static void rt_hw_timer_init(void) GPIO_REG(GPIO_OUTPUT_EN) |= ((0x1<< RED_LED_OFFSET)| (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ; GPIO_REG(GPIO_OUTPUT_VAL) |= (0x1 << BLUE_LED_OFFSET) ; GPIO_REG(GPIO_OUTPUT_VAL) &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET)) ; - rt_hw_interrupt_enable(1); - - CLINT_REG(CLINT_MTIME) = 0x0; - CLINT_REG(CLINT_MTIMECMP) = 0x10000; + +/* enable timer interrupt*/ + set_csr(mie, MIP_MTIP); volatile uint64_t * mtimecmp = (uint64_t*) (CLINT_CTRL_ADDR + CLINT_MTIMECMP); + CLINT_REG(CLINT_MTIME) = 0x0; +/* CLINT_REG(CLINT_MTIMECMP) = 0x10000;*/ *mtimecmp = 0x20000; return; } diff --git a/bsp/risc-v/drivers/led.c b/bsp/risc-v/drivers/led.c index 900bb40f7d..6aa3ddcd4b 100644 --- a/bsp/risc-v/drivers/led.c +++ b/bsp/risc-v/drivers/led.c @@ -75,87 +75,82 @@ void rt_hw_led_on(int led) { /* - // Make sure the HFROSC is on before the next line: - PRCI_REG(PRCI_HFROSCCFG) |= ROSC_EN(1); - // Run off 16 MHz Crystal for accuracy. Note that the - // first line is - PRCI_REG(PRCI_PLLCFG) = (PLL_REFSEL(1) | PLL_BYPASS(1)); - PRCI_REG(PRCI_PLLCFG) |= (PLL_SEL(1)); - // Turn off HFROSC to save power - PRCI_REG(PRCI_HFROSCCFG) &= ~(ROSC_EN(1)); - */ - + // Make sure the HFROSC is on before the next line: + PRCI_REG(PRCI_HFROSCCFG) |= ROSC_EN(1); + // Run off 16 MHz Crystal for accuracy. Note that the + // first line is + PRCI_REG(PRCI_PLLCFG) = (PLL_REFSEL(1) | PLL_BYPASS(1)); + PRCI_REG(PRCI_PLLCFG) |= (PLL_SEL(1)); + // Turn off HFROSC to save power + PRCI_REG(PRCI_HFROSCCFG) &= ~(ROSC_EN(1)); + */ - // Wait a bit to avoid corruption on the UART. - // (In some cases, switching to the IOF can lead - // to output glitches, so need to let the UART - // reciever time out and resynchronize to the real - // start of the stream. - volatile int i=0; - while(i < 10000){i++;} - _puts(sifive_msg); - //_puts("Config String:\n\r"); - //_puts(*((const char **) 0x100C)); - //_puts("\n\r"); - _puts(led_msg); - uint16_t r=0xFF; - uint16_t g=0; - uint16_t b=0; - char c = 0; - - // Set up RGB PWM - - /* - PWM1_REG(PWM_CFG) = 0; - // To balance the power consumption, make one left, one right, and one center aligned. - PWM1_REG(PWM_CFG) = (PWM_CFG_ENALWAYS) | (PWM_CFG_CMP2CENTER); - PWM1_REG(PWM_COUNT) = 0; - - // Period is approximately 244 Hz - // the LEDs are intentionally left somewhat dim, - // as the full brightness can be painful to look at. - PWM1_REG(PWM_CMP0) = 0; - */ + // Wait a bit to avoid corruption on the UART. + // (In some cases, switching to the IOF can lead + // to output glitches, so need to let the UART + // reciever time out and resynchronize to the real + // start of the stream. + volatile int i=0; + while(i < 10000){i++;} + _puts(sifive_msg); + //_puts("Config String:\n\r"); + //_puts(*((const char **) 0x100C)); + //_puts("\n\r"); + _puts(led_msg); + uint16_t r=0xFF; + uint16_t g=0; + uint16_t b=0; + char c = 0; - while(1){ - - if(r > 0 && b == 0){ - r--; - g++; - } - if(g > 0 && r == 0){ - g--; - b++; - } - if(b > 0 && g == 0){ - r++; - b--; - } - - uint32_t G = g; - uint32_t R = r; - uint32_t B = b; - - PWM1_REG(PWM_CMP1) = G << 4; // PWM is low on the left, GPIO is low on the left side, LED is ON on the left. - PWM1_REG(PWM_CMP2) = (B << 1) << 4; // PWM is high on the middle, GPIO is low in the middle, LED is ON in the middle. - PWM1_REG(PWM_CMP3) = 0xFFFF - (R << 4); // PWM is low on the left, GPIO is low on the right, LED is on on the right. - - // Check for user input - if (c == 0){ - if (_getc(&c) != 0){ - _putc(c); - _puts("\n\r"); - - if ((c == 'y') || (c == 'Y')){ - _puts("PASS\n\r"); - } else{ - _puts("FAIL\n\r"); - } - } - } - } + // Set up RGB PWM + + /* + PWM1_REG(PWM_CFG) = 0; + // To balance the power consumption, make one left, one right, and one center aligned. + PWM1_REG(PWM_CFG) = (PWM_CFG_ENALWAYS) | (PWM_CFG_CMP2CENTER); + PWM1_REG(PWM_COUNT) = 0; + + // Period is approximately 244 Hz + // the LEDs are intentionally left somewhat dim, + // as the full brightness can be painful to look at. + PWM1_REG(PWM_CMP0) = 0; + */ + if(r > 0 && b == 0){ + r--; + g++; + } + if(g > 0 && r == 0){ + g--; + b++; + } + if(b > 0 && g == 0){ + r++; + b--; + } + + uint32_t G = g; + uint32_t R = r; + uint32_t B = b; + + PWM1_REG(PWM_CMP1) = G << 4; // PWM is low on the left, GPIO is low on the left side, LED is ON on the left. + PWM1_REG(PWM_CMP2) = (B << 1) << 4; // PWM is high on the middle, GPIO is low in the middle, LED is ON in the middle. + PWM1_REG(PWM_CMP3) = 0xFFFF - (R << 4); // PWM is low on the left, GPIO is low on the right, LED is on on the right. + + // Check for user input + if (c == 0){ + if (_getc(&c) != 0){ + _putc(c); + _puts("\n\r"); + + if ((c == 'y') || (c == 'Y')){ + _puts("PASS\n\r"); + } else{ + _puts("FAIL\n\r"); + } + } + } return; } void rt_hw_led_off(int led) |
