1
0
mirror of git://projects.qi-hardware.com/nn-usb-fpga.git synced 2025-02-03 10:21:06 +02:00

70 lines
1.3 KiB
C
Raw Permalink Normal View History

2010-10-12 09:05:52 -05:00
#include "soc-hw.h"
2010-10-13 08:49:36 -05:00
uart_t *uart0 = (uart_t *) 0xF0000000;
timer_t *timer0 = (timer_t *) 0xF0010000;
2010-10-12 09:05:52 -05:00
gpio_t *gpio0 = (gpio_t *) 0xF0020000;
2010-10-15 12:59:46 -05:00
// uint32_t *sram0 = (uint32_t *) 0x40000000;
2010-10-12 09:05:52 -05:00
2010-10-13 08:49:36 -05:00
uint32_t msec = 0;
2010-10-12 09:05:52 -05:00
/***************************************************************************
2010-10-13 08:49:36 -05:00
* General utility functions
2010-10-12 09:05:52 -05:00
*/
2010-10-13 08:49:36 -05:00
void sleep(int msec)
2010-10-12 09:05:52 -05:00
{
uint32_t tcr;
// Use timer0.1
timer0->compare1 = (FCPU/1000)*msec;
timer0->counter1 = 0;
2010-10-13 08:49:36 -05:00
timer0->tcr1 = TIMER_EN | TIMER_IRQEN;
2010-10-12 09:05:52 -05:00
do {
//halt();
tcr = timer0->tcr1;
} while ( ! (tcr & TIMER_TRIG) );
}
void tic_init()
{
// Setup timer0.0
2010-10-13 08:49:36 -05:00
timer0->compare0 = (FCPU/1000);
2010-10-12 09:05:52 -05:00
timer0->counter0 = 0;
timer0->tcr0 = TIMER_EN | TIMER_AR | TIMER_IRQEN;
}
/***************************************************************************
* UART Functions
*/
void uart_init()
{
//uart0->ier = 0x00; // Interrupt Enable Register
//uart0->lcr = 0x03; // Line Control Register: 8N1
//uart0->mcr = 0x00; // Modem Control Register
// Setup Divisor register (Fclk / Baud)
//uart0->div = (FCPU/(57600*16));
}
unsigned char uart_getchar()
2010-10-12 09:05:52 -05:00
{
while (! (uart0->ucr & UART_DR)) ;
return (uart0->rxtx) & 0xFF;
2010-10-12 09:05:52 -05:00
}
void uart_putchar(unsigned char c)
2010-10-12 09:05:52 -05:00
{
while (uart0->ucr & UART_BUSY) ;
uart0->rxtx = c;
}
void uart_putstr(char *str)
{
char *c = str;
while(*c) {
uart_putchar(*c);
c++;
}
}