TImer working with tests
TODO: think of other way of shifting in data. Bit errors make uploading difficult
This commit is contained in:
@@ -1,14 +1,45 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define GPIO_BASE 0x40000000u
|
||||
#define GPIO_BASE 0x40000000u
|
||||
static volatile uint32_t * const R_FREQ = (volatile uint32_t *)(GPIO_BASE+0);
|
||||
static volatile uint32_t * const LEDS = (volatile uint32_t *)(GPIO_BASE+4);
|
||||
static volatile uint32_t * const LEDGR = (volatile uint32_t *)(GPIO_BASE+8);
|
||||
|
||||
static volatile uint32_t * const R_FREQ = (volatile uint32_t *)GPIO_BASE;
|
||||
#define TIMER_BASE 0x40010000u
|
||||
static volatile uint32_t * const TIMER = (volatile uint32_t *)(TIMER_BASE+0);
|
||||
|
||||
#define MSTATUS_MIE (1u << 3)
|
||||
#define MIE_MTIE (1u << 7)
|
||||
|
||||
extern void trap_entry();
|
||||
|
||||
static inline void irq_init() {
|
||||
/* mtvec first */
|
||||
asm volatile ("csrw mtvec, %0" :: "r"(trap_entry));
|
||||
|
||||
/* enable machine timer interrupt */
|
||||
asm volatile ("csrs mie, %0" :: "r"(MIE_MTIE));
|
||||
|
||||
/* global enable last */
|
||||
asm volatile ("csrs mstatus, %0" :: "r"(MSTATUS_MIE));
|
||||
}
|
||||
|
||||
void timer_isr(){
|
||||
static int set = 0;
|
||||
*TIMER = 18400;
|
||||
*LEDGR = ~(*LEDGR);
|
||||
}
|
||||
|
||||
void main(){
|
||||
irq_init();
|
||||
|
||||
*LEDGR = 3;
|
||||
*TIMER = 18400;
|
||||
|
||||
for(;;){
|
||||
for(int i=1000; i<10000; i++){
|
||||
*R_FREQ = i;
|
||||
// for(int j=0; j<100; j++) asm volatile("nop");
|
||||
for(int j=0; j<100; j++) asm volatile("nop");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user