Subversion Repositories freemyipod

Rev

Rev 652 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
652 theseven 1
//
2
//
3
//    Copyright 2011 TheSeven
4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
495 theseven 24
#include "emcoreapp.h"
25
 
26
 
27
#define ULCON  (*((uint32_t volatile*)0x3cc00000))
28
#define UCON   (*((uint32_t volatile*)0x3cc00004))
29
#define UFCON  (*((uint32_t volatile*)0x3cc00008))
30
#define UMCON  (*((uint32_t volatile*)0x3cc0000c))
31
#define UFSTAT (*((uint32_t volatile*)0x3cc00018))
32
#define UTXH   (*((uint8_t volatile*)0x3cc00020))
33
#define URXH   (*((uint8_t volatile*)0x3cc00024))
34
#define UBRDIV (*((uint32_t volatile*)0x3cc00028))
35
 
36
 
37
static void uart_tx(char byte)
38
{
39
    while (UFSTAT & BIT(9)) sleep(100);
40
    UTXH = byte;
41
}
42
 
43
static char uart_rx()
44
{
45
    while (!(UFSTAT & BITRANGE(0, 3))) sleep(100);
46
    return URXH;
47
}
48
 
835 theseven 49
static void main(int argc, const char** argv)
495 theseven 50
{
51
    int i;
52
    clockgate_enable(41, true);
53
    ULCON = 3;
54
    UCON = 0x405;
55
    UFCON = 7;
56
    UMCON = 0;
57
    switch (get_platform_id())
58
    {
59
    case 0x47324e49:  // IN2G
60
        UBRDIV = 38;
61
        break;
62
    case 0x4c435049:  // IPCL
63
        UBRDIV = 18;
64
        break;
65
    default:
66
        panic(PANIC_KILLTHREAD, "Unknown platform!");
67
    }
68
    uart_tx('~');
69
    while (true) uart_tx(uart_rx() ^ 0x20);
70
}
71
 
72
 
73
EMCORE_APP_HEADER("UART test", main, 127)