Root/lm32/logic/sakc/firmware/ddr-phaser/spike_hw.c

1#include "spike_hw.h"
2
3uart_t *uart0 = (uart_t *) 0xF0000000;
4timer_t *timer0 = (timer_t *) 0xF0010000;
5gpio_t *gpio0 = (gpio_t *) 0xF0020000;
6
7uint32_t msec = 0;
8
9/***************************************************************************
10 * General utility functions
11 */
12void sleep(int msec)
13{
14    uint32_t tcr;
15
16    // Use timer0.1
17    timer0->compare1 = (FCPU/1000)*msec;
18    timer0->counter1 = 0;
19    timer0->tcr1 = TIMER_EN | TIMER_IRQEN;
20
21    do {
22        //halt();
23         tcr = timer0->tcr1;
24     } while ( ! (tcr & TIMER_TRIG) );
25}
26
27void tic_init()
28{
29    // Setup timer0.0
30    timer0->compare0 = (FCPU/1000);
31    timer0->counter0 = 0;
32    timer0->tcr0 = TIMER_EN | TIMER_AR | TIMER_IRQEN;
33}
34
35/***************************************************************************
36 * UART Functions
37 */
38void uart_init()
39{
40    //uart0->ier = 0x00; // Interrupt Enable Register
41    //uart0->lcr = 0x03; // Line Control Register: 8N1
42    //uart0->mcr = 0x00; // Modem Control Register
43
44    // Setup Divisor register (Fclk / Baud)
45    //uart0->div = (FCPU/(57600*16));
46}
47
48char uart_getchar()
49{
50    while (! (uart0->ucr & UART_DR)) ;
51    return uart0->rxtx;
52}
53
54void uart_putchar(char c)
55{
56    while (uart0->ucr & UART_BUSY) ;
57    uart0->rxtx = c;
58}
59
60void uart_putstr(char *str)
61{
62    char *c = str;
63    while(*c) {
64        uart_putchar(*c);
65        c++;
66    }
67}
68
69

Archive Download this file

Branches:
master



interactive