sdk:examples: adapte to new perips

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/4/head
liangkangnan 2021-08-13 10:07:13 +08:00
parent fdd953c0f0
commit 477d9efc34
7 changed files with 97 additions and 83 deletions

View File

@ -50,9 +50,9 @@ extern "C" {
#define UART_RXDATA_RXDATA_FIELD \
((bitfield_field32_t) { .mask = UART_RXDATA_RXDATA_MASK, .index = UART_RXDATA_RXDATA_OFFSET })
typedef void (*putc)(uint8_t);
typedef void (*myputc)(uint8_t);
void uart0_init(putc put);
void uart0_init(myputc putc);
uint8_t uart0_getc();
void uart0_putc(uint8_t c);

View File

@ -21,7 +21,7 @@ uint8_t uart0_getc()
}
// 115200bps, 8 N 1
void uart0_init(putc put)
void uart0_init(myputc put)
{
// enable tx and rx
UART0_REG(UART_CTRL_REG_OFFSET) |= 0x3;

View File

@ -1,58 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
#include "coremark.h"
#include "../../bsp/include/utils.h"
#include "../../bsp/include/uart.h"
#include "../../bsp/include/xprintf.h"
#if VALIDATION_RUN
volatile ee_s32 seed1_volatile=0x3415;
volatile ee_s32 seed2_volatile=0x3415;
volatile ee_s32 seed3_volatile=0x66;
#endif
#if PERFORMANCE_RUN
volatile ee_s32 seed1_volatile=0x0;
volatile ee_s32 seed2_volatile=0x0;
volatile ee_s32 seed3_volatile=0x66;
#endif
#if PROFILE_RUN
volatile ee_s32 seed1_volatile=0x8;
volatile ee_s32 seed2_volatile=0x8;
volatile ee_s32 seed3_volatile=0x8;
#endif
volatile ee_s32 seed4_volatile=ITERATIONS;
volatile ee_s32 seed5_volatile=0;
static CORE_TICKS t0, t1;
void start_time(void)
{
t0 = get_cycle_value();
}
void stop_time(void)
{
t1 = get_cycle_value();
}
CORE_TICKS get_time(void)
{
return t1 - t0;
}
secs_ret time_in_secs(CORE_TICKS ticks)
{
// scale timer down to avoid uint64_t -> double conversion in RV32
int scale = 256;
uint32_t delta = ticks / scale;
uint32_t freq = CPU_FREQ_HZ / scale;
return delta / (double)freq;
}
void portable_init(core_portable *p, int *argc, char *argv[])
{
uart_init();
}
#include <stdio.h>
#include <stdlib.h>
#include "coremark.h"
#include "../../bsp/include/utils.h"
#include "../../bsp/include/uart.h"
#include "../../bsp/include/xprintf.h"
#if VALIDATION_RUN
volatile ee_s32 seed1_volatile=0x3415;
volatile ee_s32 seed2_volatile=0x3415;
volatile ee_s32 seed3_volatile=0x66;
#endif
#if PERFORMANCE_RUN
volatile ee_s32 seed1_volatile=0x0;
volatile ee_s32 seed2_volatile=0x0;
volatile ee_s32 seed3_volatile=0x66;
#endif
#if PROFILE_RUN
volatile ee_s32 seed1_volatile=0x8;
volatile ee_s32 seed2_volatile=0x8;
volatile ee_s32 seed3_volatile=0x8;
#endif
volatile ee_s32 seed4_volatile=ITERATIONS;
volatile ee_s32 seed5_volatile=0;
static CORE_TICKS t0, t1;
void start_time(void)
{
t0 = get_cycle_value();
}
void stop_time(void)
{
t1 = get_cycle_value();
}
CORE_TICKS get_time(void)
{
return t1 - t0;
}
secs_ret time_in_secs(CORE_TICKS ticks)
{
// scale timer down to avoid uint64_t -> double conversion in RV32
int scale = 256;
uint32_t delta = ticks / scale;
uint32_t freq = CPU_FREQ_HZ / scale;
return delta / (double)freq;
}
void portable_init(core_portable *p, int *argc, char *argv[])
{
uart0_init(uart0_putc);
}

View File

@ -107,7 +107,7 @@ int main( void )
static void prvSetupHardware( void )
{
GPIO_REG(GPIO_CTRL) |= 0x1; // set gpio0 output mode
gpio_set_mode(GPIO0, GPIO_MODE_OUTPUT); // set gpio0 output mode
}
/*-----------------------------------------------------------*/
@ -180,7 +180,7 @@ const uint32_t ulNullLoopDelay = 0x1ffffUL;
{
__asm volatile( "nop" );
}
GPIO_REG(GPIO_DATA) ^= 0x1;
gpio_set_output_toggle(GPIO0); // toggle led
}
}
/*-----------------------------------------------------------*/
@ -192,7 +192,7 @@ void vToggleLED( void )
set_test_pass();
while (1);
#else
GPIO_REG(GPIO_DATA) ^= 0x1;
gpio_set_output_toggle(GPIO0); // toggle led
#endif
}

View File

@ -37,7 +37,7 @@
/* Standard includes. */
#include "string.h"
#include "include/machine_timer.h"
#include "include/timer.h"
#include "include/rvic.h"
/* Let the user override the pre-loading of the initial LR with the address of
@ -134,19 +134,23 @@ volatile uint32_t ulHartId;
#endif
#ifdef SIMULATION
machine_timer_set_cmp_val(5000);
timer0_set_div(50);
timer0_set_value(100); // 100us period
#else
machine_timer_set_cmp_val(uxTimerIncrementsForOneTick);
timer0_set_div(configCPU_CLOCK_HZ/1000000);
timer0_set_value(1000000/configTICK_RATE_HZ); // 10ms period
#endif
machine_timer_irq_enable(1);// enable timer interrupt
timer0_set_int_enable(1);
timer0_set_mode_auto_reload();
rvic_set_irq_prio_level(0, 1);
rvic_irq_enable(0);
machine_timer_enable(1); // start timer
timer0_start(1); // start timer
}
/*-----------------------------------------------------------*/
void xPortClearTimerIntPending()
{
machine_timer_clear_irq_pending(); // clear int pending
timer0_clear_int_pending();
rvic_clear_irq_pending(0);
}

View File

@ -2,19 +2,29 @@
#include "../../bsp/include/gpio.h"
#include "../../bsp/include/utils.h"
#include "../../bsp/include/rvic.h"
int main()
{
gpio_output_enable(GPIO0); // gpio0输出模式
gpio_input_enable(GPIO1); // gpio1输入模式
gpio_set_mode(GPIO0, GPIO_MODE_OUTPUT); // gpio0输出模式
gpio_set_mode(GPIO1, GPIO_MODE_INPUT); // gpio1输入模式
gpio_set_interrupt_mode(GPIO1, GPIO_INTR_DOUBLE_EDGE);
rvic_irq_enable(3);
rvic_set_irq_prio_level(3, 1);
global_irq_enable();
while (1) {
// 如果GPIO1输入高
if (gpio_get_data(GPIO1))
gpio_set_data(GPIO0, 1); // GPIO0输出高
// 如果GPIO1输入低
else
gpio_set_data(GPIO0, 0); // GPIO0输出低
}
while (1);
}
void gpio1_irq_handler()
{
gpio_clear_intr_pending(GPIO1);
rvic_clear_irq_pending(3);
// 如果GPIO1输入高
if (gpio_get_input_data(GPIO1))
gpio_set_output_data(GPIO0, 1); // GPIO0输出高
// 如果GPIO1输入低
else
gpio_set_output_data(GPIO0, 0); // GPIO0输出低
}

View File

@ -43,13 +43,13 @@ int main()
rvic_irq_enable(0);
timer0_start(1);
gpio_output_enable(GPIO0);
gpio_set_mode(GPIO0, GPIO_MODE_OUTPUT);
while (1) {
// 500ms
if (count == 50) {
count = 0;
gpio_data_toggle(GPIO0); // toggle led
gpio_set_output_toggle(GPIO0); // toggle led
}
}
#endif