]> git.zerfleddert.de Git - linexec-j720/blame - uart.cpp
Initial import of xdadeveloper linexec sources
[linexec-j720] / uart.cpp
CommitLineData
77a37381 1#include "stdafx.h"
2#include "tester1.h"
3#include <commctrl.h>
4//#include <aygshell.h>
5#include <sipapi.h>
6#include "setup.h"
7
8// moved to config.h\r
9//#define FUART 0x40100000
10\r
11
12void UART_puts(char *s)
13{
14 UINT32 *base=(UINT32*)VirtualAlloc((void*)0x0,sizeof(void*)*0xffff, MEM_RESERVE,PAGE_READWRITE);
15 int ret=VirtualCopy(base,(void *) ((UARTBASE)/256),sizeof(void*)*0xffff , PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
16 int a=0;
17 while(s[a])
18 {
19 while((base[UARTSTATUS/4]&1<<UARTTXRDY) == UARTTXBIT) {}
20 base[UARTDATA/4]=(char)(s[a]);
21 a++;
22 }
23}
24
25void UART_setup()
26{
27 UINT32 *base=(UINT32*)VirtualAlloc((void*)0x0,sizeof(void*)*0xffff, MEM_RESERVE,PAGE_READWRITE);
28 int ret=VirtualCopy(base,(void *) ((UARTBASE)/256),sizeof(void*)*0xffff , PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
29\r
30#ifdef STRONGARM\r
31// Apparently there is something we don't know. This is needed.\r
32 HANDLE hSerial = CreateFile(L"COM1:", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);\r
33// disable UART\r
34 base[0x0C/4] = 0;\r
35// clear status\r
36 base[0x1C/4] = 0xFF;\r
37// set 8 bit no parity 1 stopbit\r
38 base[0x00/4] = 9;\r
39// set 115200 bps\r
40 base[0x04/4] = 0;\r
41 base[0x08/4] = 1;\r
42// enable TX/RX\r
43 base[0x0C/4] = 3;\r
44#else
45// set DLAB
46 base[0x0C/4]=128+2+1;
47// set divisor
48 base[0]=8; // 115200 bps
49 base[0x04/4]=0;
50// unset DLAB
51 base[0x0C/4]=2+1;
52// UART enable & no FIFO
53 base[0x04/4]=64;
54 base[0x08/4]=0;
55#endif\r
56
57 char test[]="LinExec: UART Initialized.\n\r";
58 int a=0;
59 while(test[a])
60 {
61 while((base[UARTSTATUS/4]&1<<UARTTXRDY) == UARTTXBIT) {}
62 base[UARTDATA/4]=(char)(test[a]);
63 a++;
64 }
65}
Impressum, Datenschutz