 Question: How do I use the timer from C ?
Answer: Here is an example using the C3x
timer.
Also included are files to use the simulator. cl30 -g vecs.asm timer.c -z timer.cmd
******************************* timer.c ***************************************
void c_int99(void)
{
for(;;);
}
void c_int09(void)
{
static unsigned int count;
count++;
}
void main(void)
{
volatile unsigned int* Timer0GlobalControl = (volatile unsigned int*) 0x808020;
volatile unsigned int* Timer0Counter = (volatile unsigned int*) 0x808024;
volatile unsigned int* Timer0Period = (volatile unsigned int*) 0x808028;
*Timer0Period = 100;
*Timer0GlobalControl = 0x3C1;
asm( or 100h, IE);
asm( or 2000h, ST);
for(;;);
}
******************************* vecs.asm **************************************
.sect .vecs
.ref _c_int00
.ref _c_int09
.ref _c_int99
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_int09
tint1 .word _c_int99
dint .word _c_int99
***************************** timer.cmd **************************************
-c
-stack 0x100
-heap 0x100
-lrts30.lib
-m c3x.map
-o c3x.out
-x
-w /* Remove if using V4.50 */
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 */
}
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
********************************* timer.tak ***********************************
load c3x.out
c
go main
pause - Press any key
step 8
pause - Press any key
go c_int09
wa count
pause - Press any key
mix
step 1000
*******************************************************************************
|