OpenCores
URL https://opencores.org/ocsvn/light52/light52/trunk

Subversion Repositories light52

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 17 to Rev 18
    Reverse comparison

Rev 17 → Rev 18

/light52/trunk/test/include/LIGHT52.MCU
18,7 → 18,7
P2 DATA 0A0H
IE DATA 0A8H
P3 DATA 0B0H
;IP DATA 0B8H
IP DATA 0B8H
EXTINT0 DATA 0C0H
PSW DATA 0D0H
ACC DATA 0E0H
/light52/trunk/test/irq_test/obj_code_pkg.vhdl
37,55 → 37,91
-- Size of XCODE memory in bytes.
constant XCODE_SIZE : natural := 2048;
-- Size of XDATA memory in bytes.
constant XDATA_SIZE : natural := 512;
constant XDATA_SIZE : natural := 0;
 
-- Object code initialization constant.
constant object_code : t_obj_code(0 to 355) := (
X"02", X"00", X"30", X"02", X"00", X"d4", X"00", X"00",
X"00", X"00", X"00", X"02", X"00", X"e2", X"00", X"00",
X"00", X"00", X"00", X"02", X"00", X"e2", X"00", X"00",
X"00", X"00", X"00", X"02", X"00", X"e2", X"00", X"00",
X"00", X"00", X"00", X"02", X"00", X"e2", X"00", X"00",
constant object_code : t_obj_code(0 to 639) := (
X"02", X"00", X"46", X"02", X"01", X"3f", X"00", X"00",
X"00", X"00", X"00", X"02", X"01", X"9a", X"00", X"00",
X"00", X"00", X"00", X"02", X"01", X"ea", X"00", X"00",
X"00", X"00", X"00", X"02", X"01", X"ea", X"00", X"00",
X"00", X"00", X"00", X"02", X"01", X"ea", X"00", X"00",
X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00",
X"75", X"a8", X"00", X"75", X"90", X"01", X"00", X"00",
X"00", X"e5", X"60", X"b4", X"00", X"7f", X"d2", X"c0",
X"75", X"a8", X"01", X"75", X"90", X"01", X"00", X"00",
X"00", X"e5", X"60", X"b4", X"00", X"6f", X"d2", X"c0",
X"75", X"90", X"00", X"75", X"a8", X"81", X"75", X"60",
X"00", X"75", X"90", X"01", X"00", X"00", X"00", X"e5",
X"60", X"b4", X"01", X"4e", X"d2", X"c0", X"90", X"01",
X"08", X"12", X"00", X"c8", X"75", X"a8", X"00", X"75",
X"88", X"00", X"75", X"8d", X"00", X"75", X"8c", X"00",
X"75", X"8f", X"c3", X"75", X"8e", X"50", X"75", X"88",
X"30", X"78", X"5f", X"00", X"d8", X"fd", X"e5", X"8d",
X"b4", X"00", X"1c", X"e5", X"8c", X"b4", X"00", X"17",
X"78", X"0a", X"00", X"d8", X"fd", X"e5", X"8d", X"b4",
X"00", X"0d", X"e5", X"8c", X"b4", X"01", X"08", X"90",
X"01", X"43", X"12", X"00", X"c8", X"01", X"a5", X"90",
X"01", X"35", X"12", X"00", X"c8", X"75", X"a8", X"00",
X"01", X"b0", X"90", X"01", X"27", X"12", X"00", X"c8",
X"75", X"a8", X"00", X"01", X"bb", X"90", X"00", X"f6",
X"12", X"00", X"c8", X"75", X"a8", X"00", X"01", X"c6",
X"78", X"00", X"e8", X"08", X"93", X"60", X"04", X"f5",
X"99", X"80", X"f7", X"22", X"75", X"90", X"00", X"75",
X"c0", X"ff", X"05", X"60", X"90", X"00", X"e4", X"11",
X"c8", X"32", X"01", X"e2", X"3c", X"45", X"78", X"74",
X"65", X"72", X"6e", X"61", X"6c", X"20", X"69", X"72",
X"71", X"3e", X"0d", X"0a", X"00", X"00", X"55", X"6e",
X"65", X"78", X"70", X"65", X"63", X"74", X"65", X"64",
X"20", X"49", X"52", X"51", X"0d", X"0a", X"00", X"00",
X"49", X"52", X"51", X"20", X"74", X"65", X"73", X"74",
X"20", X"66", X"69", X"6e", X"69", X"73", X"68", X"65",
X"64", X"2c", X"20", X"6e", X"6f", X"20", X"65", X"72",
X"72", X"6f", X"72", X"73", X"0d", X"0a", X"00", X"4d",
X"69", X"73", X"73", X"69", X"6e", X"67", X"20", X"49",
X"52", X"51", X"0d", X"0a", X"00", X"54", X"69", X"6d",
X"65", X"72", X"20", X"65", X"72", X"72", X"6f", X"72",
X"0d", X"0a", X"00", X"54", X"69", X"6d", X"65", X"72",
X"20", X"74", X"65", X"73", X"74", X"20", X"66", X"69",
X"6e", X"69", X"73", X"68", X"65", X"64", X"2c", X"20",
X"6e", X"6f", X"20", X"65", X"72", X"72", X"6f", X"72",
X"73", X"0d", X"0a", X"00"
X"90", X"02", X"43", X"12", X"01", X"33", X"75", X"a8",
X"00", X"01", X"39", X"90", X"02", X"12", X"12", X"01",
X"33", X"75", X"a8", X"00", X"01", X"44", X"75", X"a8",
X"00", X"75", X"b8", X"01", X"75", X"64", X"00", X"75",
X"90", X"01", X"00", X"00", X"00", X"e5", X"60", X"b4",
X"00", X"e1", X"d2", X"c0", X"75", X"a8", X"01", X"75",
X"90", X"01", X"00", X"00", X"00", X"e5", X"60", X"b4",
X"00", X"d1", X"d2", X"c0", X"75", X"90", X"00", X"75",
X"a8", X"81", X"75", X"60", X"00", X"75", X"90", X"01",
X"00", X"00", X"00", X"e5", X"60", X"b4", X"01", X"b0",
X"d2", X"c0", X"75", X"64", X"01", X"75", X"90", X"00",
X"75", X"a8", X"83", X"75", X"60", X"00", X"75", X"90",
X"01", X"00", X"00", X"e5", X"60", X"b4", X"01", X"98",
X"d2", X"c0", X"75", X"64", X"02", X"75", X"90", X"00",
X"75", X"a8", X"83", X"75", X"60", X"00", X"75", X"90",
X"01", X"00", X"00", X"e5", X"60", X"b4", X"01", X"80",
X"d2", X"c0", X"75", X"64", X"03", X"75", X"62", X"00",
X"75", X"90", X"00", X"75", X"a8", X"83", X"75", X"60",
X"00", X"75", X"88", X"01", X"75", X"8d", X"00", X"75",
X"8c", X"00", X"75", X"8f", X"00", X"75", X"8e", X"01",
X"75", X"88", X"30", X"79", X"5f", X"00", X"00", X"00",
X"00", X"00", X"00", X"00", X"00", X"d9", X"f6", X"e5",
X"62", X"b4", X"01", X"41", X"90", X"02", X"24", X"12",
X"01", X"33", X"75", X"a8", X"00", X"75", X"88", X"00",
X"75", X"8d", X"00", X"75", X"8c", X"00", X"75", X"8f",
X"c3", X"75", X"8e", X"50", X"75", X"88", X"30", X"78",
X"5f", X"00", X"d8", X"fd", X"e5", X"8d", X"b4", X"00",
X"1f", X"e5", X"8c", X"b4", X"00", X"1a", X"78", X"0a",
X"00", X"d8", X"fd", X"e5", X"8d", X"b4", X"00", X"10",
X"e5", X"8c", X"b4", X"01", X"0b", X"90", X"02", X"5f",
X"12", X"01", X"33", X"21", X"23", X"02", X"01", X"f6",
X"90", X"02", X"51", X"12", X"01", X"33", X"75", X"a8",
X"00", X"21", X"31", X"78", X"00", X"e8", X"08", X"93",
X"60", X"04", X"f5", X"99", X"80", X"f7", X"22", X"75",
X"90", X"00", X"75", X"c0", X"ff", X"05", X"60", X"e5",
X"64", X"b4", X"00", X"06", X"90", X"02", X"00", X"31",
X"33", X"32", X"b4", X"02", X"2a", X"75", X"62", X"00",
X"75", X"88", X"01", X"75", X"8d", X"00", X"75", X"8c",
X"00", X"75", X"8f", X"00", X"75", X"8e", X"01", X"75",
X"a8", X"82", X"75", X"88", X"30", X"78", X"5f", X"00",
X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"d8",
X"f6", X"e5", X"62", X"b4", X"00", X"6e", X"32", X"b4",
X"01", X"17", X"75", X"60", X"00", X"75", X"64", X"00",
X"75", X"a8", X"81", X"75", X"90", X"01", X"78", X"0a",
X"00", X"d8", X"fd", X"e5", X"60", X"b4", X"00", X"54",
X"32", X"32", X"e5", X"64", X"b4", X"03", X"45", X"75",
X"60", X"00", X"75", X"64", X"00", X"75", X"a8", X"81",
X"75", X"90", X"01", X"78", X"0a", X"00", X"d8", X"fd",
X"e5", X"60", X"b4", X"01", X"41", X"75", X"64", X"00",
X"75", X"62", X"00", X"75", X"88", X"01", X"75", X"8d",
X"00", X"75", X"8c", X"00", X"75", X"8f", X"00", X"75",
X"8e", X"01", X"75", X"88", X"30", X"79", X"5f", X"00",
X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"d9",
X"f6", X"e5", X"62", X"b4", X"00", X"0e", X"05", X"62",
X"75", X"88", X"01", X"32", X"05", X"62", X"75", X"88",
X"01", X"32", X"21", X"ea", X"90", X"02", X"12", X"31",
X"33", X"75", X"a8", X"00", X"21", X"f4", X"90", X"02",
X"43", X"31", X"33", X"75", X"a8", X"00", X"21", X"fe",
X"3c", X"45", X"78", X"74", X"65", X"72", X"6e", X"61",
X"6c", X"20", X"69", X"72", X"71", X"3e", X"0d", X"0a",
X"00", X"00", X"55", X"6e", X"65", X"78", X"70", X"65",
X"63", X"74", X"65", X"64", X"20", X"49", X"52", X"51",
X"0d", X"0a", X"00", X"00", X"49", X"52", X"51", X"20",
X"74", X"65", X"73", X"74", X"20", X"66", X"69", X"6e",
X"69", X"73", X"68", X"65", X"64", X"2c", X"20", X"6e",
X"6f", X"20", X"65", X"72", X"72", X"6f", X"72", X"73",
X"0d", X"0a", X"00", X"4d", X"69", X"73", X"73", X"69",
X"6e", X"67", X"20", X"49", X"52", X"51", X"0d", X"0a",
X"00", X"54", X"69", X"6d", X"65", X"72", X"20", X"65",
X"72", X"72", X"6f", X"72", X"0d", X"0a", X"00", X"54",
X"69", X"6d", X"65", X"72", X"20", X"74", X"65", X"73",
X"74", X"20", X"66", X"69", X"6e", X"69", X"73", X"68",
X"65", X"64", X"2c", X"20", X"6e", X"6f", X"20", X"65",
X"72", X"72", X"6f", X"72", X"73", X"0d", X"0a", X"00"
);
 
 
/light52/trunk/test/irq_test/src/irq_test.a51
1,6 → 1,6
; irq_test.a51 -- First interrupt service test.
; irq_test.a51 -- Basic interrupt service test.
;
; This progam is only meant to work in the simulation test bench, because it
; This program is only meant to work in the simulation test bench, because it
; requires the external interrupt inputs to be wired to the P1 output port.
; They are in the simulation test bench entity but not in the synthesizable
; demo top entity.
8,6 → 8,14
; Its purpose is to demonstrate the working of the interrupt service logic. No
; actual tests are performed (other than the co-simulation tests), only checks.
;
; This program makes the following assumptions about the MCU configuration:
;
; 1.- Port line P1.0 is wired to external input EXTINT0.0
; 2.- The timer prescaler is set to 20us@50MHz.
;
; NOTE: I am aware that this code is perfectly hideous and nearly useless as a
; test bench; it will have to do for the time being. I can seldom find quality
; time for this project...
;-------------------------------------------------------------------------------
 
; Include the definitions for the light52 derivative
15,6 → 23,9
$include (light52.mcu)
ext_irq_ctr set 060h ; Incremented by external irq routine
timer_irq_ctr set 062h ; Incremented by timer irq routine
uart_irq_ctr set 063h ; Incremented by uart irq routine
irq_test_code set 064h ; Selects the behavior of the irq routines
 
;-- Macros -------------------------------------------------------------
24,6 → 35,8
local putc_loop
mov SBUF,character
putc_loop:
; This program will only ever run in the simulated environment, where
; UART transmission is instantaneous. No need to loop here.
;mov a,SCON
;anl a,#10h
;jz putc_loop
54,14 → 67,36
 
;-- Main test program --------------------------------------------------
org 30h
; Place a few utility routines here at the start so they are reachable
; by CJNE.
; Did not get expected IRQ: print failure message and block.
fail_expected:
mov DPTR,#text3
call puts
mov IE,#00h
ajmp $
 
; Got unexpected IRQ: print failure message and block.
fail_unexpected:
mov DPTR,#text1
call puts
mov IE,#00h
ajmp $
 
start:
 
; Disable all interrupts.
mov IE,#00
mov IE,#00 ; Disable all interrupts...
mov IP,#01 ; ...and set EXTINT as high-priority.
mov irq_test_code,#00h ; Tell irq routines to only inc the counters
 
;---- External interrupt test --------------------------------------
; Basic interrupt test.
; We'll be asserting the external interrupt request line 0, making
; sure the interrupt enable flags work properly. No other interrupt
; will be asserted simultaneously or while in the interrupt service
84,7 → 119,7
nop
mov a,ext_irq_ctr ; ...and make sure the interrupt was NOT
cjne a,#00,fail_unexpected ; serviced.
setb EXTINT0.0 ; Clear timer IRQ flag
setb EXTINT0.0 ; Clear external IRQ flag
 
; Trigger external IRQ with external and global IRQ enabled
mov P1,#00h ; Clear the external interrupt line...
96,8 → 131,78
nop
mov a,ext_irq_ctr ; ...and make sure it has been serviced.
cjne a,#01,fail_expected
setb EXTINT0.0 ; Clear timer IRQ flag
setb EXTINT0.0 ; Clear external IRQ flag
; Somewhat less basic interrupt test: priorities.
; Here we are going to use the test code byte (irq_test_code) to tell
; the interrupt routines what we want them to do. Since we only use two
; interrupt routines to test everything, each routine has to perform
; a few different roles.
; Basically we want to make sure that the irq priority rules hold:
;
; A.-Nothing can interrupt a high priority irq routine.
; B.- Only a high-priority irq can interrupt a low-priority irq.
; C.- Simultaneous irqs get ordered by their vector number.
;
; Rule C will NOT be tested in this program; and rules B and A get only
; the most basic of basic tests.
; Run test 1: Trigger another external interrupt while serving an
; external interrupt. Since both are high-priority, the timer interrupt
; should be ignored.
mov irq_test_code,#01h
mov P1,#00h ; Clear the external interrupt line...
mov IE,#83h ; ...before enabling interrupts globally.
mov ext_irq_ctr,#00 ; Reset the interrupt counter...
mov P1,#01h ; ...and assert the external interrupt.
nop ; Give it some time to be acknowledged...
nop
mov a,ext_irq_ctr ; ...and make sure it has been serviced.
cjne a,#01,fail_expected
setb EXTINT0.0 ; Clear external IRQ flag
 
; Run test 2: Trigger Timer interrupt while serving an external
; interrupt. Since the Timer irq is low-priority, it should be ignored.
mov irq_test_code,#02h
mov P1,#00h ; Clear the external interrupt line...
mov IE,#83h ; ...before enabling interrupts globally.
mov ext_irq_ctr,#00 ; Reset the interrupt counter...
mov P1,#01h ; ...and assert the external interrupt.
nop ; Give it some time to be acknowledged...
nop
mov a,ext_irq_ctr ; ...and make sure it has been serviced.
cjne a,#01,fail_expected
setb EXTINT0.0 ; Clear external IRQ flag
 
; Run test 3: Trigger interrupts within the timer interrupt service
; routine.
mov irq_test_code,#03h
mov timer_irq_ctr,#00h
mov P1,#00h ; Clear the external interrupt line...
mov IE,#83h ; ...before enabling interrupts globally.
mov ext_irq_ctr,#00 ; Reset the interrupt counter...
mov TSTAT,#01 ; Stop timer and clear timer interrupt...
mov TH,#00h ; ...set counter = 000h...
mov TL,#00h ;
mov TCH,#00h ; ...and set Compare register = 0001h...
mov TCL,#01h ;
mov TSTAT,#030h ; ...then start counting.
 
mov r1,#95 ; Wait for the timer IRQ to trigger...
loop_001:
nop
nop
nop
nop
nop
nop
nop
nop
djnz r1,loop_001 ; ...then make sure the timer irq has
mov a,timer_irq_ctr ; been triggered.
cjne a,#01h,fail_expected_irq_bridge
 
; End of irq test, print message and continue
mov DPTR,#text2
call puts
109,6 → 214,9
; time, i.e. 20us after being started. We will NOT test the full
; functionality of the timer (not in this version of the test).
; Note that the irq tests above already assume the timer works... this
; test is somewhat redundant.
mov IE,#000h ; Disable all interrupts...
; ...and put timer in
mov TSTAT,#00 ; Stop timer...
147,6 → 255,8
;-- End of test program, enter single-instruction endless loop
quit: ajmp $
 
fail_expected_irq_bridge:
jmp fail_expected_irq
 
fail_timer_error:
mov DPTR,#text4
154,21 → 264,6
mov IE,#00h
ajmp $
 
 
; Did not get expected IRQ: print failure message and block.
fail_expected:
mov DPTR,#text3
call puts
mov IE,#00h
ajmp $
 
; Got unexpected IRQ: print failure message and block.
fail_unexpected:
mov DPTR,#text1
call puts
mov IE,#00h
ajmp $
 
; End of the test code. Now let's define a few utility routines.
 
;-- puts: output to UART a zero-terminated string at DPTR ----------------------
185,20 → 280,154
puts_done:
ret
 
;-- irq_timer: interrupt routine for timer -------------------------------------
;-- irq_ext: interrupt routine for external irq lines --------------------------
; Note we don't bother to preserve any registers.
irq_ext:
mov P1,#00h ; Remove the external interrupt request
mov EXTINT0,#0ffh ; Clear all external IRQ flags
inc ext_irq_ctr ; Increment irq counter
; Ok, now check the test code byte to see what we have to do here.
mov a,irq_test_code
cjne a,#00h,irq_ext_0
; Test 0: Just increment irq counter (already done).
mov DPTR,#text0 ; Print IRQ message...
call puts
reti ; ...and quit
irq_ext_0:
cjne a,#02h,irq_ext_1
; Test 2: Trigger timer interrupt while in the service routine.
; Verify that low-priority interrupts get ignored while in the service
; routine of a high-priority interrupt.
mov timer_irq_ctr,#00h
mov TSTAT,#01 ; Stop timer and clear timer interrupt...
mov TH,#00h ; ...set counter = 000h...
mov TL,#00h ;
mov TCH,#00h ; ...and set Compare register = 0001h.
mov TCL,#01h ;
mov IE,#82h ; Enable timer interrupt...
mov TSTAT,#030h ; ...and start counting.
 
mov r0,#95 ; Wait for the timer interrupt to trigger...
irq_ext_test0_loop0:
nop
nop
nop
nop
nop
nop
nop
nop
djnz r0,irq_ext_test0_loop0 ; ...the make sure the timer irq has
mov a,timer_irq_ctr ; NOT triggered.
cjne a,#00h,fail_unexpected_irq
reti
 
irq_ext_1:
cjne a,#01h,irq_ext_2
; Test 1: Trigger external interrupt while in the service routine.
; Verify that high-priority interrupts get ignored while in the service
; routine of another high-priority interrupt.
mov ext_irq_ctr,#00h
mov irq_test_code,#00h
mov IE,#81h ; ...enable the UART irq...
mov P1,#01h ; ...and trigger it
 
mov r0,#10 ; Give time for the irq to trigger...
irq_ext_test2_loop0:
nop
djnz r0,irq_ext_test2_loop0 ; ...the make sure the Timer irq has
mov a,ext_irq_ctr ; NOT triggered.
cjne a,#00h,fail_unexpected_irq
reti
 
irq_ext_2:
; Code byte irq_test_code not used; ignored.
reti
 
;-- irq_timer: interrupt routine for timer -------------------------------------
; Note we don't bother to preserve any registers.
irq_timer:
; Check the test code to see what we have to do here.
mov a,irq_test_code
cjne a,#03,irq_timer_0
; Test code 3: interrupts within timer irq service routine.
; Trigger external interrupt within this irq service routine and make
; sure it gets serviced.
mov ext_irq_ctr,#00h
mov irq_test_code,#00h
mov IE,#81h ; ...enable the UART irq...
mov P1,#01h ; ...and trigger it
 
mov r0,#10 ; Give time for the irq to trigger...
irq_timer_test3_loop0:
nop
djnz r0,irq_timer_test3_loop0 ; ...the make sure the Timer irq has
mov a,ext_irq_ctr ; NOT triggered.
cjne a,#01h,fail_expected_irq
; Ok, now re-trigger the timer interrupt within the timer service
; interrupt and make sure the new interrupt is not serviced.
mov irq_test_code,#00h
mov timer_irq_ctr,#00h
mov TSTAT,#01 ; Stop timer and clear timer interrupt...
mov TH,#00h ; ...set counter = 000h...
mov TL,#00h ;
mov TCH,#00h ; ...and set Compare register = 0001h...
mov TCL,#01h ;
mov TSTAT,#030h ; ...then start counting.
 
mov r1,#95 ; Wait for the timer IRQ to trigger...
irq_timer_test3_loop1:
nop
nop
nop
nop
nop
nop
nop
nop
djnz r1,irq_timer_test3_loop1 ; ...then make sure the timer irq has
mov a,timer_irq_ctr ; been ignored.
cjne a,#00h,fail_unexpected_irq
 
inc timer_irq_ctr ; Increment timer interrupt counter...
mov TSTAT,#01 ; Stop timer and clear timer interrupt.
 
reti
 
irq_timer_0:
; Test code 0: increment irq counter.
; Just increment the timer irq counter and quit.
inc timer_irq_ctr ; Increment timer interrupt counter...
mov TSTAT,#01 ; Stop timer and clear timer interrupt.
reti ; ...and quit.
 
irq_wrong:
ajmp irq_wrong
 
; Utility functions -- error messages to console, etc.
; Got unexpected IRQ: print failure message and block.
fail_unexpected_irq:
mov DPTR,#text1
call puts
mov IE,#00h
ajmp $
 
; Did not get expected IRQ: print failure message and block.
fail_expected_irq:
mov DPTR,#text3
call puts
mov IE,#00h
ajmp $
 
; End of the utility routines. Define constant data and we're done.
 
text0: db '<External irq>',13,10,00h,00h
/light52/trunk/test/irq_test/readme.txt
13,7 → 13,9
DOS BAT script 'build.bat' will assemble the demo and build a suitable object
code VHDL package that can then be used in synthesis or simulation.
 
You can run this demo on the software simulator B51 by running script 'run.bat'.
You can run this demo on the software simulator B51 by running script 'run.bat';
it will fail because B51 does not simulate the wiring on EXTINT required by this
program, as mentioned above.
You can run this demo in Modelsim using script /sim/light52_irq_tb.do.
 
Once you have run the demo in Modelsim and B51, you can then compare the

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.