1
0
mirror of git://projects.qi-hardware.com/nn-usb-fpga.git synced 2025-01-10 10:30:16 +02:00
nn-usb-fpga/lm32/logic/sakc/firmware/loader_cain/soc-hw.c

90 lines
1.7 KiB
C
Raw Normal View History

2010-10-12 17:05:52 +03:00
#include "soc-hw.h"
2010-10-13 16:49:36 +03:00
uart_t *uart0 = (uart_t *) 0xF0000000;
timer_t *timer0 = (timer_t *) 0xF0010000;
2010-10-12 17:05:52 +03:00
gpio_t *gpio0 = (gpio_t *) 0xF0020000;
2010-10-13 16:49:36 +03:00
uint32_t msec = 0;
2010-10-12 17:05:52 +03:00
/***************************************************************************
2010-10-13 16:49:36 +03:00
* General utility functions
2010-10-12 17:05:52 +03:00
*/
2010-10-13 16:49:36 +03:00
void sleep(int msec)
2010-10-12 17:05:52 +03:00
{
uint32_t tcr;
// Use timer0.1
timer0->compare1 = (FCPU/1000)*msec;
timer0->counter1 = 0;
2010-10-13 16:49:36 +03:00
timer0->tcr1 = TIMER_EN | TIMER_IRQEN;
2010-10-12 17:05:52 +03:00
do {
//halt();
tcr = timer0->tcr1;
} while ( ! (tcr & TIMER_TRIG) );
}
void tic_init()
{
// Setup timer0.0
2010-10-13 16:49:36 +03:00
timer0->compare0 = (FCPU/1000);
2010-10-12 17:05:52 +03: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));
}
char uart_getchar()
{
while (! (uart0->ucr & UART_DR)) ;
return uart0->rxtx;
}
void uart_putchar(char c)
{
while (uart0->ucr & UART_BUSY) ;
uart0->rxtx = c;
}
void uart_putstr(char *str)
{
char *c = str;
while(*c) {
uart_putchar(*c);
c++;
}
}
void hexprint(unsigned int hexval)
{
int digit[8], pos;
uart_putstr("0x");
for(pos = 0; pos < 8; pos++)
{
digit[pos] = (hexval & 0xF); /* last hexit */
hexval = hexval >> 4;
}
for(pos = 7; pos > -1; pos--)
{
if(digit[pos] < 0xA)
2010-10-13 16:49:36 +03:00
uart_putstr((char *)digit[pos] + '0');
2010-10-12 17:05:52 +03:00
else
2010-10-13 16:49:36 +03:00
uart_putstr((char *)digit[pos] + 'A' - 10);
2010-10-12 17:05:52 +03:00
}
uart_putchar(' ');
}
2010-10-13 16:49:36 +03:00