Skip to content

Commit

Permalink
Timer for raspberry pi.
Browse files Browse the repository at this point in the history
  • Loading branch information
pykello committed Jun 6, 2015
1 parent b31601e commit 4c6f46c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions arch/raspberrypi/build.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

OBJS += arch/raspberrypi/irq.o
OBJS += arch/raspberrypi/uart.o
OBJS += arch/raspberrypi/timer.o
1 change: 1 addition & 0 deletions arch/raspberrypi/include/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
#define MMIO_BASE_PHYSICAL 0x20000000
#define TOTAL_MEMORY_SIZE 0x1ff00000 /* 511MB */
#define UART_IRQ 29
#define TIMER_IRQ 1

#endif
1 change: 1 addition & 0 deletions arch/raspberrypi/irq.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <irq.h>
#include <vm.h>
#include <lib/string.h>
#include <klib.h>

/* memory mapping for the interrupt controller */
#define PIC MMIO_P2V(0x2000B000)
Expand Down
45 changes: 45 additions & 0 deletions arch/raspberrypi/timer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <timer.h>
#include <types.h>
#include <vm.h>
#include <klib.h>

/* http://www.valvers.com/open-software/raspberry-pi/step04-bare-metal-programming-in-c-pt4/ */

/* memory mapping for timer */
#define TIMER MMIO_P2V(0x20003000)

#define CS 0x20003000
#define CLO 0x20003004
#define C0 0x2000300C
#define C1 0x20003010
#define C2 0x20003014
#define C3 0x20003018


static void PUT32(uint32_t address, uint32_t value) {
*MMIO_P2V(address) = value;
}

static uint32_t GET32(uint32_t address) {
return *MMIO_P2V(address);
}

static uint32_t saved_interval_microsecond;


void timer_set_interval(uint32_t interval_microsecond)
{
saved_interval_microsecond = interval_microsecond;
timer_clear_interrupt();
}

void timer_clear_interrupt(void)
{
unsigned int ra;

PUT32(CS, 2);

ra = GET32(CLO);
ra += saved_interval_microsecond;
PUT32(C1, ra);
}
1 change: 1 addition & 0 deletions kernel/irq.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <irq.h>
#include <klib.h>


/* interrupt handler vector */
Expand Down
4 changes: 2 additions & 2 deletions kernel/proc/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ void handle_timer(void)
void scheduler_init(void)
{
round_robin_index = 0;
timer_set_interval(1000);
register_interrupt_handler(0x5, handle_timer);
timer_set_interval(100000);
register_interrupt_handler(TIMER_IRQ, handle_timer);
}

void schedule(void)
Expand Down
4 changes: 2 additions & 2 deletions user/concurrency_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ void _start()
int i = 0;
fork();

for (i = 0; i < 5; i++) {
for (i = 0; i < 50000; i++) {
printf("step %d at pid %d\n", i, getpid());
yield();
//yield();
}

exit(0);
Expand Down

0 comments on commit 4c6f46c

Please sign in to comment.