 Question:
How do I use the serial port and DMA from C ?
Answer:
Here is a C3x example that uses the DMA and serial
port. Also included
is the files to run the program with the Simulator.
cl30 -g -s serial.c vecs.asm -z serial.cmd
********************************************************************************
serial.c
********************************************************************************
int array[10];
static const int enable = 0x200400;
void c_int99(void)
{
for(;;);
}
void c_int10(void)
{
for(;;);
}
void main(void)
{
int i;
volatile unsigned int* Serial0GlobalControl
=
(volatile unsigned int*) 0x808040;
volatile unsigned int* Serial0XControl = (volatile unsigned int*)
0x808042;
volatile unsigned int* Serial0RControl = (volatile unsigned int*)
0x808043;
volatile unsigned int* Serial0TimerControl = (volatile unsigned int*) 0x808044;
volatile unsigned int* Serial0TimerCounter = (volatile unsigned int*) 0x808045;
volatile unsigned int* Serial0TimerPeriod = (volatile unsigned int*) 0x808046;
volatile unsigned int* Serial0DataX = (volatile
unsigned int*) 0x808048;
volatile unsigned int* Serial0DataR = (volatile
unsigned int*) 0x80804c;
volatile unsigned int* DMAGlobalControl = (volatile unsigned int*)
0x808000;
volatile unsigned int* DMASourceAddress = (volatile unsigned int*)
0x808004;
volatile unsigned int* DMADestinAddress = (volatile unsigned int*)
0x808006;
volatile unsigned int* DMATransferCounter = (volatile unsigned int*) 0x808008;
*DMAGlobalControl = 0x0;
*DMASourceAddress = (unsigned) Serial0DataR;
*DMADestinAddress = (unsigned) array;
*DMATransferCounter = 10;
*DMAGlobalControl = 0xd43;
*Serial0TimerControl = 0x0;
*Serial0GlobalControl = 0x1200084;
*Serial0RControl = 0x111;
*Serial0TimerPeriod = 0x1600000;
*Serial0TimerControl = 0x2c0;
*Serial0GlobalControl = 0x9200084;
asm(" ldi
0h, IF
");
asm(" ldi
@_enable, IE ");
asm(" or
2000h, ST ");
for (;;);
}
********************************************************************************
vecs.asm
********************************************************************************
.sect ".vecs"
.ref _c_int00
.ref _c_int99
.ref _c_int10
reset .word _c_int00
int0 .word _c_int99
int1 .word _c_int99
int2 .word _c_int99
int3 .word _c_int99
xint0 .word _c_int99
rint0 .word _c_int99
xint1 .word _c_int99
rint1 .word _c_int99
tint0 .word _c_int99
tint1 .word _c_int99
dint .word _c_int10
********************************************************************************
serial.cmd
********************************************************************************
-c
/*
LINK USING C CONVENTIONS */
-stack 0x100
/*
1K STACK
*/
-heap 0x100
/*
1K HEAP
*/
-lrts30.lib
/*
GET RUN-TIME SUPPORT */
-m c3x.map
-o c3x.out
-x
-w
/* SPECIFY THE SYSTEM MEMORY MAP */
MEMORY
{
ROM: org = 0x0 len = 0x1000
/* INTERNAL 4K ROM
*/
EXT0: org = 0x1000 len = 0x7ff000 /*
EXTERNAL MEMORY
*/
XBUS: org = 0x800000 len = 0x2000 /*
EXPANSION BUS
*/
IOBUS: org = 0x804000 len = 0x2000 /* I/O BUS
*/
RAM0: org = 0x809800 len = 0x400 /*
RAM BLOCK 0
*/
RAM1: org = 0x809c00 len = 0x400 /*
RAM BLOCK 1
*/
EXT1: org = 0x80a000 len = 0x1000 /* EXTERNAL MEMORY
*/
}
/* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY */
SECTIONS
{
.text: > RAM0
/*
CODE
*/
.cinit: > RAM0
/*
INITIALIZATION TABLES
*/
.const: > RAM0
/*
CONSTANTS
*/
.stack: > RAM1
/*
SYSTEM STACK
*/
.sysmem: > RAM1
/*
DYNAMIC MEMORY - DELETE IF NOT USED */
.bss: > RAM0, block 0x10000 /*
VARIABLES
*/
.vecs > 0h
}
********************************************************************************
siminit.cmd
********************************************************************************
ma 0x0,0x1000,ram
ma 0x808000,0x10,ram ; 0x808010 to 0x80801F reserved mem
ma 0x808020,0x400, ram; This one and above block defines some of
;
the memory mapped registers. These memory maps
;
are must for normal execution of simulator.
;
If you define your own siminit, please include
;
these two.
ma 0x809800,0x800,ram
map on
take serial.tak
********************************************************************************
serial.tak
********************************************************************************
md 0x808020
ma 0x808020, 44, ram
ma 0x80804c,0x1,IPORT
ma 0x80804d,0x400,ram
mc 0x80804c,input.dat,READ
map on
********************************************************************************
input.dat
********************************************************************************
0x000001
0x000002
0x000003
0x000004
0x000005
0x000006
0x000007
0x000008
0x000009
0x000010
********************************************************************************
|