From 504256c2a189676c71717971e3380d052d9240b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20J=C3=B8rgensen?= Date: Wed, 28 Oct 2020 08:01:31 +0100 Subject: [PATCH] Add test_isr.c See Issues #77 and #138. --- c/test_programs/test_isr.c | 48 ++++++++++++++++++++++++++++------ c/vbcc/machines/qnice/sysdef.h | 1 + monitor/sysdef.asm | 1 + 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/c/test_programs/test_isr.c b/c/test_programs/test_isr.c index 1e392f47..1c0b3e2b 100644 --- a/c/test_programs/test_isr.c +++ b/c/test_programs/test_isr.c @@ -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 #include +#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) { @@ -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; } diff --git a/c/vbcc/machines/qnice/sysdef.h b/c/vbcc/machines/qnice/sysdef.h index 800d6747..fc0028da 100644 --- a/c/vbcc/machines/qnice/sysdef.h +++ b/c/vbcc/machines/qnice/sysdef.h @@ -222,6 +222,7 @@ // programming. #define IC_ENABLE_INTERRUPTS 0x0001 #define IC_BLOCK_INTERRUPTS 0x0002 +#define IC_BLOCK_INTERRUPTS_INVERT 0xFFFD // //--------------------------------------------------------------------------------------- // Block FFE8: SYSINFO diff --git a/monitor/sysdef.asm b/monitor/sysdef.asm index e71647aa..b709b183 100644 --- a/monitor/sysdef.asm +++ b/monitor/sysdef.asm @@ -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