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