-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharm7tdmi-ks32c50100.c
158 lines (122 loc) · 3.01 KB
/
arm7tdmi-ks32c50100.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
Copyright (c) 2001 by William A. Gatliff
All rights reserved. bgat@billgatliff.com
See the file COPYING for details.
This file is provided "as-is", and without any express or implied
warranties, including, without limitation, the implied warranties of
merchantability and fitness for a particular purpose.
The author welcomes feedback regarding this file.
**
$Id: arm7tdmi-ks32c50100.c,v 1.6 2003/05/27 15:46:13 bgat Exp $
*/
#define CPU_HZ 50000000
#include "gdb.h"
#include "arm7tdmi.h"
#include "arm7tdmi-ks32c50100.h"
#define UTXBUF UTXBUF1
#define URXBUF URXBUF1
#define USTAT USTAT1
#define UCON UCON1
#define UBRDIV UBRDIV1
int gdb_putc (int c)
{
while (!(USTAT_TBE & *USTAT))
;
*UTXBUF = c;
return c & 0xff;
}
int gdb_getc (void)
{
int retval;
while (!(USTAT_RDR & *USTAT))
;
retval = *URXBUF;
return retval;
}
void arm7tdmi_ks32c50100_startup (void)
{
int brgout;
int bps;
// force polled i/o on both uart channels */
*INTMSK |= ((1 << 7) + (1 << 6));
*INTMSK |= ((1 << 5) + (1 << 4));
*UCON = (*UCON & ~UCON_TXM) | 8;
*UCON = (*UCON & ~UCON_RXM) | 1;
// TODO: some math here
#warning MCLK2 == 50 MHz, bps == 9600 assumed.
bps = 9600;
// TODO: compute appropriate CNT0 and CNT1
// from the manual:
// BRGOUT = (MCLK2 or UCLK) / (CNT0 + 1) / (16^CNT1) / 16
// i.e. 9600 = (50000000)/(CNT0 + 1)/(16^(CNT1))/16
// where CNT1 == [0|1], so (16^CNT1) == [0|16]
// (no other CNT1 values are legal)
brgout = 162 << 4;
*UBRDIV = brgout;
return;
}
void gdb_kill (void)
{
}
void gdb_detach (void)
{
}
void update_leds (void)
{
#define SEG_MASK 0x1fc00
static const int SEG[] = {0x5f << 10, 6 << 10, 0x3b << 10, 0x2f << 10,
0x66 << 10, 0x6d << 10, 0x7d << 10, 7 << 10,
0x7f << 10, 0x6f << 10};
static int seg;
/* force io ports to output, turn everything off */
*IOPMOD |= SEG_MASK;
*IOPDATA &= ~SEG_MASK;
/* output a digit */
if (10 <= seg) seg = 0;
*IOPDATA |= SEG[seg++];
}
#if defined(CRT0)
#define MODULE_MAGIC 0x4d484944
#define UNPLUGGED_FLAG 1
#define AUTOSTART_FLAG 2
#define MAJOR_VERSION 1
#define MINOR_VERSION 1
typedef struct module_header_t module_header_t;
struct module_header_t {
unsigned magic;
unsigned flags:16;
unsigned major:8;
unsigned minor:8;
unsigned checksum;
void *ro_base;
void *ro_limit;
void *rw_base;
void *zi_base;
void *zi_limit;
const module_header_t *self;
void *start;
void *init;
void *final;
void *service;
const char *title;
const char *help;
void *cmdtbl;
void *swi_base;
void *swi_code;
} __attribute__((packed));
extern char __text_start__, __text_end__;
extern void _start(void);
const module_header_t module_header __attribute__((aligned(4))) =
{
magic: MODULE_MAGIC,
major: MAJOR_VERSION,
minor: MINOR_VERSION,
self: &module_header,
start: _start,
init: _start,
title: "gdbstub",
help: "gdbstub v0.01 May 22 2003",
ro_base: &__text_start__,
ro_limit: &__text_end__,
};
#endif