Skip to content

Commit

Permalink
Add test_isr.c
Browse files Browse the repository at this point in the history
See Issues #77 and #138.
  • Loading branch information
MJoergen committed Oct 28, 2020
1 parent 140120d commit 504256c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
48 changes: 40 additions & 8 deletions c/test_programs/test_isr.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
// This program is a test for writing ISR's in pure C.
//
// Compile with the command "qvc test_isr.c"
//
// The program runs for a few seconds, and should then print the result
// count=30000
// sum=50744
//
// While running, the program displays a pattern of alternating lines on the
// VGA screen. There should be no flickering in this pattern.


#include <stdio.h>
#include <sysdef.h>
#include "qmon.h" // Random generator

// convenient mechanism to access QNICE's Memory Mapped IO registers
#define MMIO( __x ) *((unsigned int volatile *) __x )

static unsigned int counter;
unsigned int count = 0;
unsigned int sum = 0;

static __interrupt __norbank void isr(void)
static __interrupt void isr(void)
{
counter++;
}
// Do some calculations that use the EAE.
sum += qmon_rand();
count += 1;
} // isr

int main()
{
// Configure a one-second timer interrupt
// Enable timer interrupt @ 10000 Hz
MMIO(IO_TIMER_0_INT) = (unsigned int) isr;
MMIO(IO_TIMER_0_PRE) = 100;
MMIO(IO_TIMER_0_CNT) = 1000;
MMIO(IO_TIMER_0_PRE) = 10;
MMIO(IO_TIMER_0_CNT) = 1;

// Initialize random number
qmon_srand(1);

// Enable user palette
MMIO(VGA_PALETTE_OFFS) = VGA_PALETTE_OFFS_USER;
MMIO(VGA_PALETTE_ADDR) = VGA_PALETTE_OFFS_USER+16;

while (1)
{
printf("%u\n", counter);
if (count >= 30000)
break;

// Set background colour using the EAE
MMIO(IC_CSR) |= IC_BLOCK_INTERRUPTS;
MMIO(VGA_PALETTE_DATA) = MMIO(VGA_SCAN_LINE)*65;
MMIO(IC_CSR) &= IC_BLOCK_INTERRUPTS_INVERT;

if (MMIO(IO_UART_SRA) & 1)
{
Expand All @@ -38,6 +67,9 @@ int main()
MMIO(IO_TIMER_0_PRE) = 0;
MMIO(IO_TIMER_0_CNT) = 0;

printf("count=%u\n", count);
printf("sum=%u\n", sum);

return 0;
}

1 change: 1 addition & 0 deletions c/vbcc/machines/qnice/sysdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
// programming.
#define IC_ENABLE_INTERRUPTS 0x0001
#define IC_BLOCK_INTERRUPTS 0x0002
#define IC_BLOCK_INTERRUPTS_INVERT 0xFFFD
//
//---------------------------------------------------------------------------------------
// Block FFE8: SYSINFO
Expand Down
1 change: 1 addition & 0 deletions monitor/sysdef.asm
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ IC$CSR .EQU 0xFF50 ; Global Interrupt Enable
; programming.
IC$ENABLE_INTERRUPTS .EQU 0x0001
IC$BLOCK_INTERRUPTS .EQU 0x0002
IC$BLOCK_INTERRUPTS_INVERT .EQU 0xFFFD
;
;---------------------------------------------------------------------------------------
; Block FFE8: SYSINFO
Expand Down

0 comments on commit 504256c

Please sign in to comment.