HAL
authorlekernel <sebastien.bourdeauducq@lekernel.net>
Fri, 16 Oct 2009 23:10:21 +0000 (01:10 +0200)
committerlekernel <sebastien.bourdeauducq@lekernel.net>
Fri, 16 Oct 2009 23:10:21 +0000 (01:10 +0200)
54 files changed:
build_demo.sh
software/demo/Makefile
software/demo/apipe.c
software/demo/brd.c [deleted file]
software/demo/brd.h [deleted file]
software/demo/cpustats.c
software/demo/eval.c
software/demo/eval.h
software/demo/hdlcd.c [deleted file]
software/demo/hdlcd.h [deleted file]
software/demo/isr.c
software/demo/main.c
software/demo/mem.c [deleted file]
software/demo/mem.h [deleted file]
software/demo/pfpu.c [deleted file]
software/demo/pfpu.h [deleted file]
software/demo/renderer.c
software/demo/rpipe.c
software/demo/rpipe.h
software/demo/shell.c
software/demo/slowout.c [deleted file]
software/demo/slowout.h [deleted file]
software/demo/snd.c [deleted file]
software/demo/snd.h [deleted file]
software/demo/tick.c [new file with mode: 0644]
software/demo/time.c [deleted file]
software/demo/time.h [deleted file]
software/demo/tmu.c [deleted file]
software/demo/tmu.h [deleted file]
software/demo/ui.c
software/demo/vga.c [deleted file]
software/demo/vga.h [deleted file]
software/include/hal/brd.h [new file with mode: 0644]
software/include/hal/hdlcd.h [new file with mode: 0644]
software/include/hal/mem.h [new file with mode: 0644]
software/include/hal/pfpu.h [new file with mode: 0644]
software/include/hal/slowout.h [new file with mode: 0644]
software/include/hal/snd.h [new file with mode: 0644]
software/include/hal/time.h [new file with mode: 0644]
software/include/hal/tmu.h [new file with mode: 0644]
software/include/hal/vga.h [new file with mode: 0644]
software/include/version.h
software/libbase/board.c
software/libhal/Makefile [new file with mode: 0644]
software/libhal/brd.c [new file with mode: 0644]
software/libhal/hdlcd.c [new file with mode: 0644]
software/libhal/mem.c [new file with mode: 0644]
software/libhal/pfpu.c [new file with mode: 0644]
software/libhal/slowout.c [new file with mode: 0644]
software/libhal/snd.c [new file with mode: 0644]
software/libhal/time.c [new file with mode: 0644]
software/libhal/tmu.c [new file with mode: 0644]
software/libhal/vga.c [new file with mode: 0644]
software/update_depend.sh

index 30fed13..4ad7f11 100755 (executable)
@@ -41,6 +41,14 @@ if [ "$?" != 0 ] ; then
 else
         echo "OK"
 fi
+echo -n "  HAL..."
+cd $BASEDIR/software/libhal && make >> $LOGFILE 2>&1
+if [ "$?" != 0 ] ; then
+        echo "FAILED"
+       exit 1
+else
+        echo "OK"
+fi
 echo -n "  Demonstration firmware..."
 cd $BASEDIR/software/demo && make >> $LOGFILE 2>&1
 if [ "$?" != 0 ] ; then
index 6f1efe0..19b352b 100644 (file)
@@ -1,7 +1,7 @@
 MMDIR?=../..
 include $(MMDIR)/software/include.mak
 
-OBJECTS=crt0.o isr.o brd.o time.o mem.o vga.o snd.o slowout.o hdlcd.o tmu.o pfpu.o wave.o analyzer.o scanner.o parser.o parser_helper.o compiler.o scheduler.o eval.o line.o apipe.o rpipe.o renderer.o cpustats.o shell.o ui.o main.o
+OBJECTS=crt0.o isr.o tick.o wave.o analyzer.o scanner.o parser.o parser_helper.o compiler.o scheduler.o eval.o line.o apipe.o rpipe.o renderer.o cpustats.o shell.o ui.o main.o
 SEGMENTS=-j .text -j .data -j .rodata
 
 all: boot.bin
@@ -30,7 +30,7 @@ spam.h: spam.raw
        $(MMDIR)/tools/crc32 $@
 
 boot.elf: linker.ld $(OBJECTS)
-       $(LD) $(LDFLAGS) -T linker.ld -N -o $@ $(OBJECTS) -L$(MMDIR)/software/libbase -L$(MMDIR)/software/libmath -lbase -lmath
+       $(LD) $(LDFLAGS) -T linker.ld -N -o $@ -L$(MMDIR)/software/libbase -L$(MMDIR)/software/libmath -L$(MMDIR)/software/libbase -L$(MMDIR)/software/libhal --start-group $(OBJECTS) -lbase -lmath -lhal --end-group
 
 .PHONY: clean depend
 
@@ -45,31 +45,28 @@ clean:
 analyzer.o: ../../software/include/libc.h ../../software/include/console.h
 analyzer.o: analyzer.h bandfilters.h
 apipe.o: ../../software/include/libc.h ../../software/include/console.h
-apipe.o: ../../software/include/board.h brd.h snd.h
-apipe.o: ../../software/include/hw/ac97.h ../../software/include/hw/common.h
-apipe.o: analyzer.h eval.h ../../software/include/hw/pfpu.h
-apipe.o: ../../software/include/hw/tmu.h pfpu.h ast.h time.h cpustats.h
-apipe.o: rpipe.h tmu.h apipe.h
-brd.o: ../../software/include/libc.h ../../software/include/console.h
-brd.o: ../../software/include/board.h brd.h
+apipe.o: ../../software/include/board.h ../../software/include/hal/brd.h
+apipe.o: ../../software/include/hal/snd.h ../../software/include/hw/ac97.h
+apipe.o: ../../software/include/hw/common.h ../../software/include/hal/pfpu.h
+apipe.o: ../../software/include/hw/pfpu.h ../../software/include/hal/time.h
+apipe.o: analyzer.h eval.h ../../software/include/hw/tmu.h ast.h cpustats.h
+apipe.o: rpipe.h ../../software/include/hal/tmu.h apipe.h
 compiler.o: ../../software/include/hw/pfpu.h
 compiler.o: ../../software/include/hw/common.h ../../software/include/libc.h
 compiler.o: ../../software/include/console.h compiler.h ast.h
-cpustats.o: ../../software/include/libc.h ../../software/include/irq.h time.h
-cpustats.o: cpustats.h
+cpustats.o: ../../software/include/libc.h ../../software/include/irq.h
+cpustats.o: ../../software/include/hal/time.h cpustats.h
 eval.o: ../../software/include/libc.h ../../software/include/console.h
 eval.o: ../../software/include/hw/pfpu.h ../../software/include/hw/common.h
-eval.o: pfpu.h ast.h compiler.h scheduler.h eval.h
+eval.o: ../../software/include/hal/pfpu.h ast.h compiler.h scheduler.h eval.h
 eval.o: ../../software/include/hw/tmu.h
-hdlcd.o: ../../software/include/libc.h ../../software/include/board.h
-hdlcd.o: ../../software/include/console.h ../../software/include/hw/sysctl.h
-hdlcd.o: ../../software/include/hw/common.h ../../software/include/hw/gpio.h
-hdlcd.o: brd.h slowout.h hdlcd.h
 isr.o: ../../software/include/hw/interrupts.h ../../software/include/irq.h
-isr.o: ../../software/include/uart.h time.h slowout.h snd.h
+isr.o: ../../software/include/uart.h ../../software/include/hal/time.h
+isr.o: ../../software/include/hal/slowout.h ../../software/include/hal/snd.h
 isr.o: ../../software/include/hw/ac97.h ../../software/include/hw/common.h
-isr.o: tmu.h ../../software/include/hw/tmu.h pfpu.h
-isr.o: ../../software/include/hw/pfpu.h ui.h cpustats.h
+isr.o: ../../software/include/hal/tmu.h ../../software/include/hw/tmu.h
+isr.o: ../../software/include/hal/pfpu.h ../../software/include/hw/pfpu.h
+isr.o: ui.h cpustats.h
 line.o: ../../software/include/libc.h ../../software/include/math.h
 line.o: ../../software/include/console.h color.h line.h
 main.o: ../../software/include/libc.h ../../software/include/console.h
@@ -77,13 +74,15 @@ main.o: ../../software/include/uart.h ../../software/include/system.h
 main.o: ../../software/include/irq.h ../../software/include/board.h
 main.o: ../../software/include/version.h ../../software/include/hw/sysctl.h
 main.o: ../../software/include/hw/common.h ../../software/include/hw/gpio.h
-main.o: ../../software/include/hw/interrupts.h brd.h mem.h time.h vga.h snd.h
-main.o: ../../software/include/hw/ac97.h tmu.h
-main.o: ../../software/include/hw/tmu.h pfpu.h
-main.o: ../../software/include/hw/pfpu.h apipe.h rpipe.h renderer.h slowout.h
-main.o: hdlcd.h ui.h cpustats.h shell.h
-mem.o: ../../software/include/libc.h ../../software/include/console.h
-mem.o: ../../software/include/malloc.h ../../software/include/hw/sram.h mem.h
+main.o: ../../software/include/hw/interrupts.h
+main.o: ../../software/include/hal/brd.h ../../software/include/hal/mem.h
+main.o: ../../software/include/hal/time.h ../../software/include/hal/vga.h
+main.o: ../../software/include/hal/snd.h ../../software/include/hw/ac97.h
+main.o: ../../software/include/hal/tmu.h ../../software/include/hw/tmu.h
+main.o: ../../software/include/hal/pfpu.h ../../software/include/hw/pfpu.h
+main.o: ../../software/include/hal/slowout.h
+main.o: ../../software/include/hal/hdlcd.h apipe.h rpipe.h renderer.h ui.h
+main.o: cpustats.h shell.h
 parser.o: ../../software/include/stdio.h ../../software/include/libc.h
 parser.o: ../../software/include/console.h ../../software/include/malloc.h
 parser.o: ../../software/include/math.h ast.h
@@ -91,22 +90,19 @@ parser_helper.o: ../../software/include/libc.h
 parser_helper.o: ../../software/include/malloc.h
 parser_helper.o: ../../software/include/console.h scanner.h parser.h ast.h
 parser_helper.o: parser_helper.h
-pfpu.o: ../../software/include/libc.h ../../software/include/console.h
-pfpu.o: ../../software/include/irq.h ../../software/include/hw/interrupts.h
-pfpu.o: ../../software/include/hw/pfpu.h ../../software/include/hw/common.h
-pfpu.o: pfpu.h
 renderer.o: ../../software/include/libc.h ../../software/include/console.h
 renderer.o: ../../software/include/math.h ../../software/include/system.h
-renderer.o: ../../software/include/hw/sysctl.h
+renderer.o: ../../software/include/hal/pfpu.h
+renderer.o: ../../software/include/hw/pfpu.h
 renderer.o: ../../software/include/hw/common.h
-renderer.o: ../../software/include/hw/uart.h ../../software/include/hw/ac97.h
-renderer.o: ../../software/include/hw/tmu.h parser_helper.h ast.h pfpu.h
-renderer.o: ../../software/include/hw/pfpu.h vga.h eval.h apipe.h renderer.h
+renderer.o: ../../software/include/hal/vga.h parser_helper.h ast.h eval.h
+renderer.o: ../../software/include/hw/tmu.h apipe.h renderer.h
 rpipe.o: ../../software/include/libc.h ../../software/include/console.h
 rpipe.o: ../../software/include/irq.h ../../software/include/system.h
 rpipe.o: ../../software/include/math.h ../../software/include/hw/interrupts.h
-rpipe.o: renderer.h vga.h tmu.h ../../software/include/hw/tmu.h
-rpipe.o: ../../software/include/hw/common.h wave.h cpustats.h rpipe.h spam.h
+rpipe.o: ../../software/include/hal/vga.h ../../software/include/hal/tmu.h
+rpipe.o: ../../software/include/hw/tmu.h ../../software/include/hw/common.h
+rpipe.o: renderer.h wave.h cpustats.h rpipe.h spam.h
 scanner.o: ../../software/include/libc.h ../../software/include/malloc.h
 scanner.o: scanner.h parser.h
 scheduler.o: ../../software/include/libc.h ../../software/include/console.h
@@ -119,34 +115,21 @@ shell.o: ../../software/include/irq.h ../../software/include/board.h
 shell.o: ../../software/include/hw/pfpu.h ../../software/include/hw/common.h
 shell.o: ../../software/include/hw/tmu.h ../../software/include/hw/sysctl.h
 shell.o: ../../software/include/hw/gpio.h
-shell.o: ../../software/include/hw/interrupts.h vga.h snd.h
-shell.o: ../../software/include/hw/ac97.h tmu.h line.h wave.h time.h brd.h
-shell.o: rpipe.h cpustats.h shell.h ui.h
-slowout.o: ../../software/include/libc.h ../../software/include/console.h
-slowout.o: ../../software/include/irq.h
-slowout.o: ../../software/include/hw/interrupts.h
-slowout.o: ../../software/include/hw/sysctl.h
-slowout.o: ../../software/include/hw/common.h
-snd.o: ../../software/include/libc.h ../../software/include/console.h
-snd.o: ../../software/include/irq.h ../../software/include/hw/ac97.h
-snd.o: ../../software/include/hw/common.h
-snd.o: ../../software/include/hw/interrupts.h snd.h
-time.o: ../../software/include/libc.h ../../software/include/console.h
-time.o: ../../software/include/irq.h ../../software/include/board.h
-time.o: ../../software/include/hw/sysctl.h ../../software/include/hw/common.h
-time.o: ../../software/include/hw/interrupts.h brd.h rpipe.h tmu.h
-time.o: ../../software/include/hw/tmu.h cpustats.h ui.h time.h
-tmu.o: ../../software/include/libc.h ../../software/include/console.h
-tmu.o: ../../software/include/irq.h ../../software/include/board.h
-tmu.o: ../../software/include/hw/interrupts.h ../../software/include/hw/tmu.h
-tmu.o: ../../software/include/hw/common.h brd.h tmu.h
+shell.o: ../../software/include/hw/interrupts.h
+shell.o: ../../software/include/hal/vga.h ../../software/include/hal/snd.h
+shell.o: ../../software/include/hw/ac97.h ../../software/include/hal/tmu.h
+shell.o: ../../software/include/hal/time.h ../../software/include/hal/brd.h
+shell.o: line.h wave.h rpipe.h cpustats.h shell.h ui.h
+tick.o: ../../software/include/hal/time.h rpipe.h
+tick.o: ../../software/include/hal/tmu.h ../../software/include/hw/tmu.h
+tick.o: ../../software/include/hw/common.h cpustats.h ui.h
 ui.o: ../../software/include/libc.h ../../software/include/console.h
 ui.o: ../../software/include/cffat.h ../../software/include/irq.h
 ui.o: ../../software/include/version.h ../../software/include/hw/interrupts.h
 ui.o: ../../software/include/hw/sysctl.h ../../software/include/hw/common.h
-ui.o: ../../software/include/hw/gpio.h renderer.h hdlcd.h time.h rpipe.h
-ui.o: tmu.h ../../software/include/hw/tmu.h cpustats.h ui.h
-vga.o: ../../software/include/console.h ../../software/include/hw/vga.h
-vga.o: ../../software/include/hw/common.h
+ui.o: ../../software/include/hw/gpio.h ../../software/include/hal/hdlcd.h
+ui.o: ../../software/include/hal/time.h renderer.h rpipe.h
+ui.o: ../../software/include/hal/tmu.h ../../software/include/hw/tmu.h
+ui.o: cpustats.h ui.h
 wave.o: ../../software/include/libc.h ../../software/include/math.h
 wave.o: ../../software/include/console.h line.h color.h wave.h renderer.h
index 91786fc..f05fbc9 100644 (file)
 #include <console.h>
 #include <board.h>
 
-#include "brd.h"
-#include "snd.h"
+#include <hal/brd.h>
+#include <hal/snd.h>
+#include <hal/pfpu.h>
+#include <hal/time.h>
+
 #include "analyzer.h"
 #include "eval.h"
-#include "pfpu.h"
-#include "time.h"
 #include "cpustats.h"
 #include "rpipe.h"
 #include "apipe.h"
diff --git a/software/demo/brd.c b/software/demo/brd.c
deleted file mode 100644 (file)
index 7826775..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <libc.h>
-#include <console.h>
-#include <board.h>
-
-#include "brd.h"
-
-const struct board_desc *brd_desc;
-
-void brd_init()
-{
-       brd_desc = get_board_desc();
-       if(brd_desc == NULL) {
-               printf("BRD: Fatal error, unknown board\n");
-               while(1);
-       }
-       printf("BRD: detected %s\n", brd_desc->name);
-}
diff --git a/software/demo/brd.h b/software/demo/brd.h
deleted file mode 100644 (file)
index 20cdd56..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __BRD_H
-#define __BRD_H
-
-extern const struct board_desc *brd_desc;
-
-void brd_init();
-
-#endif /* __BRD_H */
index 9555471..8bd96db 100644 (file)
@@ -18,7 +18,8 @@
 #include <libc.h>
 #include <irq.h>
 
-#include "time.h"
+#include <hal/time.h>
+
 #include "cpustats.h"
 
 static int enter_count;
index 5df2756..115239d 100644 (file)
@@ -19,7 +19,8 @@
 #include <console.h>
 #include <hw/pfpu.h>
 
-#include "pfpu.h"
+#include <hal/pfpu.h>
+
 #include "ast.h"
 #include "compiler.h"
 #include "scheduler.h"
index 7b71636..c5ad00b 100644 (file)
@@ -21,7 +21,8 @@
 #include <hw/pfpu.h>
 #include <hw/tmu.h>
 
-#include "pfpu.h"
+#include <hal/pfpu.h>
+
 #include "ast.h"
 
 /****************************************************************/
diff --git a/software/demo/hdlcd.c b/software/demo/hdlcd.c
deleted file mode 100644 (file)
index 4ff06e6..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <libc.h>
-#include <board.h>
-#include <console.h>
-#include <hw/sysctl.h>
-#include <hw/gpio.h>
-
-#include "brd.h"
-#include "slowout.h"
-#include "hdlcd.h"
-
-/* In tenths of microseconds */
-#define SETUP_DELAY 3
-#define CLOCK_DELAY 130
-#define OP_DELAY 10000
-
-/* In clock cycles */
-static unsigned int setup_delay;
-static unsigned int clock_delay;
-static unsigned int op_delay;
-
-static void hdlcd_send_byte(char c, int isdata)
-{
-       unsigned int mask;
-       unsigned int b = c;
-
-       if(isdata)
-               mask = GPIO_HDLCDRS;
-       else
-               mask = 0;
-
-       slowout_queue(setup_delay, mask|(((b & 0xf0) >> 4) << GPIO_HDLCDD_SHIFT));
-       slowout_queue(clock_delay, mask|GPIO_HDLCDE|(((b & 0xf0) >> 4) << GPIO_HDLCDD_SHIFT));
-       slowout_queue(clock_delay, mask|(((b & 0xf0) >> 4) << GPIO_HDLCDD_SHIFT));
-
-       slowout_queue(setup_delay, mask|((b & 0x0f) << GPIO_HDLCDD_SHIFT));
-       slowout_queue(clock_delay, mask|GPIO_HDLCDE|((b & 0x0f) << GPIO_HDLCDD_SHIFT));
-       slowout_queue(clock_delay+op_delay, mask|((b & 0x0f) << GPIO_HDLCDD_SHIFT));
-}
-
-void hdlcd_init()
-{
-       setup_delay = SETUP_DELAY*(brd_desc->clk_frequency/10000000);
-       clock_delay = CLOCK_DELAY*(brd_desc->clk_frequency/10000000);
-       op_delay = OP_DELAY*(brd_desc->clk_frequency/10000000);
-
-       if(!(CSR_GPIO_IN & GPIO_DIP3)) {
-               /* Select 4-bit operation on the LCD */
-               slowout_queue(setup_delay, GPIO_HDLCDD5);
-               slowout_queue(clock_delay, GPIO_HDLCDE|GPIO_HDLCDD5);
-               slowout_queue(clock_delay+op_delay, GPIO_HDLCDD5);
-       }
-       
-       /* Set up the LCD */
-       hdlcd_send_byte(0x28, 0);
-       hdlcd_send_byte(0x0c, 0);
-       hdlcd_send_byte(0x06, 0);
-       hdlcd_send_byte(0x01, 0);
-
-       printf("LCD: ready\n");
-}
-
-void hdlcd_clear()
-{
-       hdlcd_send_byte(0x01, 0);
-}
-
-int hdlcd_printf(const char *fmt, ...)
-{
-       va_list args;
-       char buffer[34];
-       unsigned i;
-       int len;
-
-       va_start(args, fmt);
-       len = vscnprintf(buffer, sizeof(buffer), fmt, args);
-       va_end(args);
-       
-       hdlcd_send_byte(0x80, 0);
-
-       for(i=0;i<len;i++) {
-               if(buffer[i] == '\n')
-                       hdlcd_send_byte(0xc0, 0);
-               else
-                       hdlcd_send_byte(buffer[i], 1);
-       }
-
-       return len;
-}
diff --git a/software/demo/hdlcd.h b/software/demo/hdlcd.h
deleted file mode 100644 (file)
index 7688682..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __HDLCD_H
-#define __HDLCD_H
-
-void hdlcd_init();
-void hdlcd_clear();
-int hdlcd_printf(const char *fmt, ...);
-
-#endif /* __HDLCD_H */
index a945de0..818fa01 100644 (file)
 #include <irq.h>
 #include <uart.h>
 
-#include "time.h"
-#include "slowout.h"
-#include "snd.h"
-#include "tmu.h"
-#include "pfpu.h"
+#include <hal/time.h>
+#include <hal/slowout.h>
+#include <hal/snd.h>
+#include <hal/tmu.h>
+#include <hal/pfpu.h>
+
 #include "ui.h"
 #include "cpustats.h"
 
index 2919cd4..72802cb 100644 (file)
 #include <hw/gpio.h>
 #include <hw/interrupts.h>
 
-#include "brd.h"
-#include "mem.h"
-#include "time.h"
-#include "vga.h"
-#include "snd.h"
-#include "tmu.h"
-#include "pfpu.h"
+#include <hal/brd.h>
+#include <hal/mem.h>
+#include <hal/time.h>
+#include <hal/vga.h>
+#include <hal/snd.h>
+#include <hal/tmu.h>
+#include <hal/pfpu.h>
+#include <hal/slowout.h>
+#include <hal/hdlcd.h>
+
 #include "apipe.h"
 #include "rpipe.h"
 #include "renderer.h"
-#include "slowout.h"
-#include "hdlcd.h"
 #include "ui.h"
 #include "cpustats.h"
 #include "shell.h"
diff --git a/software/demo/mem.c b/software/demo/mem.c
deleted file mode 100644 (file)
index 1f65e70..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <libc.h>
-#include <console.h>
-#include <malloc.h>
-#include <hw/sram.h>
-
-#include "mem.h"
-
-static char heap[16*1024*1024] __attribute__((aligned(8)));
-
-struct malloc_bank banks[2] = {
-       {
-               .addr_start = (unsigned int)&heap,
-               .addr_end = (unsigned int)&heap + sizeof(heap)
-       },
-       {
-               .addr_start = SRAM_BASE,
-               .addr_end = SRAM_BASE + SRAM_SIZE
-       }
-};
-
-void mem_init()
-{
-       int i, n;
-       
-       n = sizeof(banks)/sizeof(struct malloc_bank);
-       malloc_init(banks, n, BANK_SDRAM);
-       printf("MEM: registered %d dynamic banks:\n", n);
-       for(i=0;i<n;i++)
-               printf("MEM:   #%d 0x%08x-0x%08x\n", i, banks[i].addr_start, banks[i].addr_end);
-}
diff --git a/software/demo/mem.h b/software/demo/mem.h
deleted file mode 100644 (file)
index dab0fd9..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __MEM_H
-#define __MEM_H
-
-#define BANK_SDRAM     (0)
-#define BANK_SRAM      (1)
-
-void mem_init();
-
-#endif /* __MEM_H */
diff --git a/software/demo/pfpu.c b/software/demo/pfpu.c
deleted file mode 100644 (file)
index ec3af01..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <libc.h>
-#include <console.h>
-#include <irq.h>
-#include <hw/interrupts.h>
-#include <hw/pfpu.h>
-
-#include "pfpu.h"
-
-#define PFPU_TASKQ_SIZE 4 /* < must be a power of 2 */
-#define PFPU_TASKQ_MASK (PFPU_TASKQ_SIZE-1)
-
-static struct pfpu_td *queue[PFPU_TASKQ_SIZE];
-static unsigned int produce;
-static unsigned int consume;
-static unsigned int level;
-static int cts;
-
-void pfpu_init()
-{
-       unsigned int mask;
-
-       CSR_PFPU_CTL = 0; /* Ack any pending IRQ */
-
-       produce = 0;
-       consume = 0;
-       level = 0;
-       cts = 1;
-
-       mask = irq_getmask();
-       mask |= IRQ_PFPU;
-       irq_setmask(mask);
-       
-       printf("FPU: programmable floating point unit initialized\n");
-}
-
-static void load_program(pfpu_instruction *program, int size)
-{
-       int page;
-       int word;
-       volatile pfpu_instruction *pfpu_prog = (pfpu_instruction *)CSR_PFPU_CODEBASE;
-
-       for(page=0;page<(PFPU_PROGSIZE/PFPU_PAGESIZE);page++) {
-               for(word=0;word<PFPU_PAGESIZE;word++) {
-                       if(size == 0) return;
-                       pfpu_prog[word] = *program;
-                       program++;
-                       size--;
-               }
-       }
-}
-
-static void load_registers(float *registers)
-{
-       volatile float *pfpu_regs = (float *)CSR_PFPU_DREGBASE;
-       int i;
-
-       for(i=0;i<PFPU_REG_COUNT;i++) {
-               if(pfpu_is_reserved(i)) continue;
-               pfpu_regs[i] = registers[i];
-       }
-}
-
-static void update_registers(float *registers)
-{
-       volatile float *pfpu_regs = (float *)CSR_PFPU_DREGBASE;
-       int i;
-
-       for(i=0;i<PFPU_REG_COUNT;i++) {
-               if(pfpu_is_reserved(i)) continue;
-               registers[i] = pfpu_regs[i];
-       }
-}
-
-static void pfpu_start(struct pfpu_td *td)
-{
-       load_program(td->program, td->progsize);
-       load_registers(td->registers);
-       CSR_PFPU_MESHBASE = (unsigned int)td->output;
-       CSR_PFPU_HMESHLAST = td->hmeshlast;
-       CSR_PFPU_VMESHLAST = td->vmeshlast;
-
-       CSR_PFPU_CTL = PFPU_CTL_START;
-}
-
-void pfpu_isr()
-{
-       if(queue[consume]->update)
-               update_registers(queue[consume]->registers);
-       if(queue[consume]->invalidate) {
-               asm volatile( /* Invalidate Level-1 data cache */
-                       "wcsr DCC, r0\n"
-                       "nop\n"
-               );
-       }
-       queue[consume]->callback(queue[consume]);
-       consume = (consume + 1) & PFPU_TASKQ_MASK;
-       level--;
-       if(level > 0)
-               pfpu_start(queue[consume]); /* IRQ automatically acked */
-       else {
-               cts = 1;
-               CSR_PFPU_CTL = 0; /* Ack IRQ */
-       }
-}
-
-int pfpu_submit_task(struct pfpu_td *td)
-{
-       unsigned int oldmask;
-
-       oldmask = irq_getmask();
-       irq_setmask(oldmask & (~IRQ_PFPU));
-
-       if(level >= PFPU_TASKQ_SIZE) {
-               irq_setmask(oldmask);
-               printf("FPU: taskq overflow\n");
-               return 0;
-       }
-
-       queue[produce] = td;
-       produce = (produce + 1) & PFPU_TASKQ_MASK;
-       level++;
-
-       if(cts) {
-               cts = 0;
-               pfpu_start(td);
-       }
-
-       irq_setmask(oldmask);
-
-       return 1;
-}
diff --git a/software/demo/pfpu.h b/software/demo/pfpu.h
deleted file mode 100644 (file)
index 06cc255..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __PFPU_H
-#define __PFPU_H
-
-#include <hw/pfpu.h>
-
-struct pfpu_td;
-
-typedef void (*pfpu_callback)(struct pfpu_td *);
-
-struct pfpu_td {
-       unsigned int *output;
-       unsigned int hmeshlast;
-       unsigned int vmeshlast;
-       pfpu_instruction *program;
-       unsigned int progsize;
-       float *registers;
-       int update; /* < shall we update the "registers" array after completion */
-       int invalidate; /* < shall we invalidate L1 data cache after completion */
-       pfpu_callback callback;
-       void *user; /* < for application use */
-};
-
-void pfpu_init();
-void pfpu_isr();
-int pfpu_submit_task(struct pfpu_td *td);
-
-#endif /* __PFPU_H */
index df706e6..4b4e04b 100644 (file)
 #include <console.h>
 #include <math.h>
 #include <system.h>
-#include <hw/sysctl.h>
-#include <hw/uart.h>
-#include <hw/ac97.h>
-#include <hw/tmu.h>
+
+#include <hal/pfpu.h>
+#include <hal/vga.h>
 
 #include "parser_helper.h"
-#include "pfpu.h"
-#include "vga.h"
 #include "eval.h"
 #include "apipe.h"
 #include "renderer.h"
index d1104a2..2b5dc75 100644 (file)
 #include <math.h>
 #include <hw/interrupts.h>
 
+#include <hal/vga.h>
+#include <hal/tmu.h>
+
 #include "renderer.h"
-#include "vga.h"
-#include "tmu.h"
 #include "wave.h"
 #include "cpustats.h"
 #include "rpipe.h"
index acc2ccf..93dde42 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef __RPIPE_H
 #define __RPIPE_H
 
-#include "tmu.h"
+#include <hal/tmu.h>
 
 struct rpipe_frame;
 
index 86fd36b..00cf5e4 100644 (file)
 #include <hw/gpio.h>
 #include <hw/interrupts.h>
 
-#include "vga.h"
-#include "snd.h"
-#include "tmu.h"
+#include <hal/vga.h>
+#include <hal/snd.h>
+#include <hal/tmu.h>
+#include <hal/time.h>
+#include <hal/brd.h>
+
 #include "line.h"
 #include "wave.h"
-#include "time.h"
-#include "brd.h"
 #include "rpipe.h"
 #include "cpustats.h"
 #include "shell.h"
diff --git a/software/demo/slowout.c b/software/demo/slowout.c
deleted file mode 100644 (file)
index db4c08a..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* Asynchronous slow outputs - Using HW timer 1 */
-
-#include <libc.h>
-#include <console.h>
-#include <irq.h>
-#include <hw/interrupts.h>
-#include <hw/sysctl.h>
-
-struct slowout_operation {
-       unsigned int duration;
-       unsigned int mask;
-};
-
-#define OPQ_SIZE 1024 /* < must be a power of 2 */
-#define OPQ_MASK (OPQ_SIZE-1)
-
-static struct slowout_operation queue[OPQ_SIZE];
-static unsigned int produce;
-static unsigned int consume;
-static unsigned int level;
-static int cts;
-
-void slowout_init()
-{
-       unsigned int mask;
-
-       produce = 0;
-       consume = 0;
-       level = 0;
-       cts = 1;
-
-       CSR_TIMER1_CONTROL = 0; /* Disable timer + ack any pending IRQ */
-
-       mask = irq_getmask();
-       mask |= IRQ_TIMER1;
-       irq_setmask(mask);
-
-       printf("SLO: slow outputs initialized\n");
-}
-
-static void slowout_start(struct slowout_operation *op)
-{
-       CSR_GPIO_OUT = op->mask;
-       CSR_TIMER1_COUNTER = 0;
-       CSR_TIMER1_COMPARE = op->duration;
-       CSR_TIMER1_CONTROL = TIMER_ENABLE;
-}
-
-void slowout_isr()
-{
-       consume = (consume + 1) & OPQ_MASK;
-       level--;
-       if(level > 0)
-               slowout_start(&queue[consume]);
-       else {
-               CSR_TIMER1_CONTROL = 0; /* Ack IRQ */
-               cts = 1;
-       }
-}
-
-int slowout_queue(unsigned int duration, unsigned int mask)
-{
-       unsigned int oldmask;
-
-       oldmask = irq_getmask();
-       irq_setmask(oldmask & (~IRQ_TIMER1));
-
-       if(level >= OPQ_SIZE) {
-               irq_setmask(oldmask);
-               printf("SLO: opq overflow\n");
-               return 0;
-       }
-
-       queue[produce].duration = duration;
-       queue[produce].mask = mask;
-       if(cts) {
-               cts = 0;
-               slowout_start(&queue[produce]);
-       }
-       produce = (produce + 1) & OPQ_MASK;
-       level++;
-
-       irq_setmask(oldmask);
-
-       return 1;
-}
-
diff --git a/software/demo/slowout.h b/software/demo/slowout.h
deleted file mode 100644 (file)
index 61a1671..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __SLOWOUT_H
-#define __SLOWOUT_H
-
-void slowout_init();
-void slowout_isr();
-int slowout_queue(unsigned int duration, unsigned int mask);
-
-#endif /* __SLOWOUT_H */
diff --git a/software/demo/snd.c b/software/demo/snd.c
deleted file mode 100644 (file)
index 2b31a5e..0000000
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <libc.h>
-#include <console.h>
-#include <irq.h>
-#include <hw/ac97.h>
-#include <hw/interrupts.h>
-
-#include "snd.h"
-
-/****************************************************************/
-/* GENERAL                                                      */
-/****************************************************************/
-
-/*
- * We use interrupts and busy wait on those variables
- * (which end up in the data cache) rather than
- * busy waiting on the CSR, which would use bus bandwidth
- * for nothing.
- */
-static volatile int snd_cr_request;
-static volatile int snd_cr_reply;
-
-void snd_init()
-{
-       unsigned int codec_id;
-       unsigned int mask;
-       
-       snd_cr_request = 0;
-       snd_cr_reply = 0;
-       CSR_AC97_DCTL = 0;
-       CSR_AC97_UCTL = 0;
-       
-       mask = irq_getmask();
-       mask |= IRQ_AC97CRREQUEST|IRQ_AC97CRREPLY|IRQ_AC97DMAR|IRQ_AC97DMAW;
-       irq_setmask(mask);
-       
-       codec_id = snd_ac97_read(0x00);
-       if(codec_id == 0x0d50)
-               printf("SND: found LM4550 AC'97 codec\n");
-       else
-               printf("SND: warning, unknown codec found (ID:%04x)\n", codec_id);
-       
-       /* Unmute and set volumes */
-       /* TODO: API for this */
-       snd_ac97_write(0x02, 0x0000);
-       snd_ac97_write(0x04, 0x0f0f);
-       snd_ac97_write(0x18, 0x0000);
-       snd_ac97_write(0x0e, 0x0000);
-       snd_ac97_write(0x1c, 0x0f0f);
-
-       snd_play_empty();
-       snd_record_empty();
-       
-       printf("SND: initialization complete\n");
-}
-
-void snd_isr_crrequest()
-{
-       snd_cr_request = 1;
-       CSR_AC97_CRCTL = AC97_CRCTL_REQUEST; /* Ack interrupt */
-}
-
-void snd_isr_crreply()
-{
-       snd_cr_reply = 1;
-       CSR_AC97_CRCTL = AC97_CRCTL_REPLY; /* Ack interrupt */
-}
-
-unsigned int snd_ac97_read(unsigned int addr)
-{
-       CSR_AC97_CRADDR = addr;
-       snd_cr_reply = 0;
-       CSR_AC97_CRCTL = AC97_CRCTL_RQEN;
-       while(!snd_cr_reply);
-       return CSR_AC97_CRDATAIN;
-}
-
-void snd_ac97_write(unsigned int addr, unsigned int value)
-{
-       CSR_AC97_CRADDR = addr;
-       CSR_AC97_CRDATAOUT = value;
-       snd_cr_request = 0;
-       CSR_AC97_CRCTL = AC97_CRCTL_RQEN|AC97_CRCTL_WRITE;
-       while(!snd_cr_request);
-}
-
-/****************************************************************/
-/* PLAYING                                                      */
-/****************************************************************/
-
-static snd_callback play_callback;
-static void *play_user;
-static unsigned int play_nbytes;
-
-#define PLAY_BUFQ_SIZE 4 /* < must be a power of 2 */
-#define PLAY_BUFQ_MASK (PLAY_BUFQ_SIZE-1)
-
-static short *play_queue[PLAY_BUFQ_SIZE];
-static unsigned int play_produce;
-static unsigned int play_consume;
-static unsigned int play_level;
-static int play_underrun;
-
-static void play_start(short *buffer)
-{
-       CSR_AC97_DADDRESS = (unsigned int)buffer;
-       CSR_AC97_DREMAINING = play_nbytes;
-       CSR_AC97_DCTL = AC97_SCTL_EN; /* Start/ack interrupt */
-}
-
-void snd_isr_dmar()
-{
-       /* NB. the callback can give us buffers by calling snd_play_refill() */
-       play_callback(play_queue[play_consume], play_user);
-
-       play_consume = (play_consume + 1) & PLAY_BUFQ_MASK;
-       play_level--;
-
-       if(play_level > 0)
-               play_start(play_queue[play_consume]);
-       else {
-               printf("SND: playing underrun\n");
-               play_underrun = 1;
-               CSR_AC97_DCTL = AC97_SCTL_EN; /* Ack interrupt anyway */
-       }
-}
-
-void snd_play_empty()
-{
-       play_produce = 0;
-       play_consume = 0;
-       play_level = 0;
-       play_underrun = 0;
-}
-
-int snd_play_refill(short *buffer)
-{
-       unsigned int oldmask;
-
-       oldmask = irq_getmask();
-       irq_setmask(oldmask & (~IRQ_AC97DMAR));
-       
-       if(play_level >= PLAY_BUFQ_SIZE) {
-               irq_setmask(oldmask);
-               printf("SND: play bufq overflow\n");
-               return 0;
-       }
-
-       play_queue[play_produce] = buffer;
-       play_produce = (play_produce + 1) & PLAY_BUFQ_MASK;
-       play_level++;
-
-       if(play_underrun) {
-               play_underrun = 0;
-               play_start(buffer);
-       }
-
-       irq_setmask(oldmask);
-       
-       return 1;
-}
-
-void snd_play_start(snd_callback callback, unsigned int nsamples, void *user)
-{
-       if(snd_play_active()) {
-               printf("SND: snd_play_start called while already playing\n");
-               return;
-       }
-       
-       play_callback = callback;
-       play_user = user;
-       play_nbytes = nsamples*4;
-
-       if(play_level > 0)
-               play_start(play_queue[play_consume]);
-       else {
-               printf("SND: playing underrun\n");
-               play_underrun = 1;
-       }
-}
-
-void snd_play_stop()
-{
-       unsigned int oldmask;
-
-       oldmask = irq_getmask();
-       irq_setmask(oldmask & (~IRQ_AC97DMAR));
-       CSR_AC97_DCTL = 0; /* this also acks any pending IRQ in the AC97 core */
-       irq_ack(IRQ_AC97DMAR);
-       irq_setmask(oldmask);
-}
-
-int snd_play_active()
-{
-       return(CSR_AC97_DCTL & AC97_SCTL_EN);
-}
-
-/****************************************************************/
-/* RECORDING                                                    */
-/****************************************************************/
-
-static snd_callback record_callback;
-static void *record_user;
-
-static unsigned int record_nbytes;
-
-#define RECORD_BUFQ_SIZE 4 /* < must be a power of 2 */
-#define RECORD_BUFQ_MASK (RECORD_BUFQ_SIZE-1)
-
-static short *record_queue[RECORD_BUFQ_SIZE];
-static unsigned int record_produce;
-static unsigned int record_consume;
-static unsigned int record_level;
-static int record_overrun;
-
-static void record_start(short *buffer)
-{
-       CSR_AC97_UADDRESS = (unsigned int)buffer;
-       CSR_AC97_UREMAINING = record_nbytes;
-       CSR_AC97_UCTL = AC97_SCTL_EN; /* Start/ack interrupt */
-}
-
-void snd_isr_dmaw()
-{
-       asm volatile( /* Invalidate Level-1 data cache */
-               "wcsr DCC, r0\n"
-               "nop\n"
-       );
-       
-       /* NB. the callback can give us buffers by calling snd_record_refill() */
-       record_callback(record_queue[record_consume], record_user);
-
-       record_consume = (record_consume + 1) & RECORD_BUFQ_MASK;
-       record_level--;
-
-       if(record_level > 0)
-               record_start(record_queue[record_consume]);
-       else {
-               printf("SND: recording overrun\n");
-               record_overrun = 1;
-               CSR_AC97_UCTL = AC97_SCTL_EN; /* Ack interrupt anyway */
-       }
-}
-
-void snd_record_empty()
-{
-       record_produce = 0;
-       record_consume = 0;
-       record_level = 0;
-       record_overrun = 0;
-}
-
-int snd_record_refill(short *buffer)
-{
-       unsigned int oldmask;
-
-       oldmask = irq_getmask();
-       irq_setmask(oldmask & (~IRQ_AC97DMAW));
-
-       if(record_level >= RECORD_BUFQ_SIZE) {
-               irq_setmask(oldmask);
-               printf("SND: record bufq overflow\n");
-               return 0;
-       }
-
-       record_queue[record_produce] = buffer;
-       record_produce = (record_produce + 1) & RECORD_BUFQ_MASK;
-       record_level++;
-
-       if(record_overrun) {
-               record_overrun = 0;
-               record_start(buffer);
-       }
-
-       irq_setmask(oldmask);
-
-       return 1;
-}
-
-void snd_record_start(snd_callback callback, unsigned int nsamples, void *user)
-{
-       if(snd_record_active()) {
-               printf("SND: snd_record_start called while already recording\n");
-               return;
-       }
-
-       record_callback = callback;
-       record_user = user;
-       record_nbytes = nsamples*4;
-
-       if(record_level > 0)
-               record_start(record_queue[record_consume]);
-       else {
-               printf("SND: recording overrun\n");
-               record_overrun = 1;
-       }
-}
-
-void snd_record_stop()
-{
-       unsigned int oldmask;
-
-       oldmask = irq_getmask();
-       irq_setmask(oldmask & (~IRQ_AC97DMAW));
-       CSR_AC97_UCTL = 0; /* this also acks any pending IRQ in the AC97 core */
-       irq_ack(IRQ_AC97DMAW);
-       irq_setmask(oldmask);
-}
-
-int snd_record_active()
-{
-       return(CSR_AC97_UCTL & AC97_SCTL_EN);
-}
diff --git a/software/demo/snd.h b/software/demo/snd.h
deleted file mode 100644 (file)
index 7833047..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __SND_H
-#define __SND_H
-
-#include <hw/ac97.h>
-
-void snd_init();
-void snd_isr_crrequest();
-void snd_isr_crreply();
-void snd_isr_dmar();
-void snd_isr_dmaw();
-
-unsigned int snd_ac97_read(unsigned int addr);
-void snd_ac97_write(unsigned int addr, unsigned int value);
-
-typedef void (*snd_callback)(short *buffer, void *user);
-
-void snd_play_empty();
-int snd_play_refill(short *buffer);
-void snd_play_start(snd_callback callback, unsigned int nsamples, void *user);
-void snd_play_stop();
-int snd_play_active();
-
-void snd_record_empty();
-int snd_record_refill(short *buffer);
-void snd_record_start(snd_callback callback, unsigned int nsamples, void *user);
-void snd_record_stop();
-int snd_record_active();
-
-/*
- * Each sample has 2 channels and 16 bits per channel
- * making up 4 bytes per sample.
- */
-#define SND_MAX_NSAMPLES (AC97_MAX_DMASIZE/4)
-
-#endif /* __SND_H */
diff --git a/software/demo/tick.c b/software/demo/tick.c
new file mode 100644 (file)
index 0000000..cf95097
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <hal/time.h>
+
+#include "rpipe.h"
+#include "cpustats.h"
+#include "ui.h"
+
+void time_tick()
+{
+       rpipe_tick();
+       cpustats_tick();
+       ui_tick();
+}
+
diff --git a/software/demo/time.c b/software/demo/time.c
deleted file mode 100644 (file)
index 172eac6..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* SYSTEM CLOCK - Using HW timer 0 */
-
-#include <libc.h>
-#include <console.h>
-#include <irq.h>
-#include <board.h>
-#include <hw/sysctl.h>
-#include <hw/interrupts.h>
-
-#include "brd.h"
-#include "rpipe.h"
-#include "cpustats.h"
-#include "ui.h"
-#include "time.h"
-
-static int sec;
-
-void time_init()
-{
-       unsigned int mask;
-       
-       CSR_TIMER0_COUNTER = 0;
-       CSR_TIMER0_COMPARE = brd_desc->clk_frequency;
-       CSR_TIMER0_CONTROL = TIMER_AUTORESTART|TIMER_ENABLE;
-
-       mask = irq_getmask();
-       mask |= IRQ_TIMER0;
-       irq_setmask(mask);
-
-       printf("TIM: system timer started\n");
-}
-
-void time_isr()
-{
-       sec++;
-       CSR_TIMER0_CONTROL = TIMER_AUTORESTART|TIMER_ENABLE; /* Ack interrupt */
-
-       rpipe_tick();
-       cpustats_tick();
-       ui_tick();
-}
-
-void time_get(struct timestamp *ts)
-{
-       unsigned int oldmask = 0;
-       unsigned int ctl, counter, sec2;
-
-       oldmask = irq_getmask();
-       irq_setmask(oldmask & ~(IRQ_TIMER0));
-       counter = CSR_TIMER0_COUNTER;
-       ctl = CSR_TIMER0_CONTROL;
-       sec2 = sec;
-       irq_setmask(oldmask);
-
-       ts->sec = sec2;
-       ts->usec = counter/(brd_desc->clk_frequency/1000000);
-       
-       /*
-        * If the counter is less than half a second, we consider that
-        * the overflow was already present when we read the counter
-        * value.
-        */
-       if(ctl & TIMER_MATCH) {
-               if(counter < (brd_desc->clk_frequency/2))
-                       ts->sec++;
-       }
-}
-
-void time_add(struct timestamp *dest, struct timestamp *delta)
-{
-       dest->sec += delta->sec;
-       dest->usec += delta->usec;
-       if(dest->usec >= 1000000) {
-               dest->sec++;
-               dest->usec -= 1000000;
-       }
-}
-
-void time_diff(struct timestamp *dest, struct timestamp *t1, struct timestamp *t0)
-{
-       dest->sec = t1->sec - t0->sec;
-       dest->usec = t1->usec - t0->usec;
-       if(dest->usec < 0) {
-               dest->sec--;
-               dest->usec += 1000000;
-       }
-}
diff --git a/software/demo/time.h b/software/demo/time.h
deleted file mode 100644 (file)
index 0506e8c..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __TIME_H
-#define __TIME_H
-
-struct timestamp {
-       int sec;
-       int usec;
-};
-
-void time_init();
-void time_isr();
-
-void time_get(struct timestamp *ts);
-
-void time_add(struct timestamp *dest, struct timestamp *delta);
-void time_diff(struct timestamp *dest, struct timestamp *t1, struct timestamp *t0);
-
-#endif /* __TIME_H */
diff --git a/software/demo/tmu.c b/software/demo/tmu.c
deleted file mode 100644 (file)
index 47d3bdc..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <libc.h>
-#include <console.h>
-#include <irq.h>
-#include <board.h>
-#include <hw/interrupts.h>
-#include <hw/tmu.h>
-
-#include "brd.h"
-#include "tmu.h"
-
-#define TMU_TASKQ_SIZE 4 /* < must be a power of 2 */
-#define TMU_TASKQ_MASK (TMU_TASKQ_SIZE-1)
-
-static struct tmu_td *queue[TMU_TASKQ_SIZE];
-static unsigned int produce;
-static unsigned int consume;
-static unsigned int level;
-static int cts;
-
-void tmu_init()
-{
-       unsigned int mask;
-
-       produce = 0;
-       consume = 0;
-       level = 0;
-       cts = 1;
-
-       CSR_TMU_CTL = 0; /* Ack any pending IRQ */
-
-       mask = irq_getmask();
-       mask |= IRQ_TMU;
-       irq_setmask(mask);
-
-       printf("TMU: texture mapping unit initialized\n");
-}
-
-static void tmu_start(struct tmu_td *td)
-{
-       CSR_TMU_HMESHLAST = td->hmeshlast;
-       CSR_TMU_VMESHLAST = td->vmeshlast;
-       CSR_TMU_BRIGHTNESS = td->brightness;
-       CSR_TMU_CHROMAKEY = td->chromakey;
-       CSR_TMU_SRCMESH = (unsigned int)td->srcmesh;
-       CSR_TMU_SRCFBUF = (unsigned int)td->srcfbuf;
-       CSR_TMU_SRCHRES = td->srchres;
-       CSR_TMU_SRCVRES = td->srcvres;
-       CSR_TMU_DSTMESH = (unsigned int)td->dstmesh;
-       CSR_TMU_DSTFBUF = (unsigned int)td->dstfbuf;
-       CSR_TMU_DSTHRES = td->dsthres;
-       CSR_TMU_DSTVRES = td->dstvres;
-
-       CSR_TMU_CTL = td->flags|TMU_CTL_START;
-       //printf("write %d read %d\n", td->flags|TMU_CTL_START, CSR_TMU_CTL);
-}
-
-void tmu_isr()
-{
-       if(queue[consume]->callback)
-               queue[consume]->callback(queue[consume]);
-       if(queue[consume]->profile) {
-               int pixels, clocks, misses, hits;
-
-               printf("TMU: ====================================================\n");
-               pixels = CSR_TMUP_PIXELS;
-               clocks = CSR_TMUP_CLOCKS;
-               printf("TMU: Drawn pixels:                         %d\n", pixels);
-               printf("TMU: Processing time (clock cycles):       %d\n", clocks);
-               printf("TMU: Fill rate (Mpixels/s):                %d\n", (brd_desc->clk_frequency/1000000)*pixels/clocks);
-               printf("TMU: Frames per second:                    %d\n", brd_desc->clk_frequency/clocks);
-               printf("TMU: Geometry rate (Kvertices/s):          %d\n", (brd_desc->clk_frequency/1000)*((CSR_TMU_HMESHLAST+1)*(CSR_TMU_VMESHLAST+1))/clocks);
-               printf("TMU: At point 1:\n");
-               printf("TMU:   - stalled transactions:             %d\n", CSR_TMUP_STALL1);
-               printf("TMU:   - completed transactions:           %d\n", CSR_TMUP_COMPLETE1);
-               printf("TMU: At point 2:\n");
-               printf("TMU:   - stalled transactions:             %d\n", CSR_TMUP_STALL2);
-               printf("TMU:   - completed transactions:           %d\n", CSR_TMUP_COMPLETE2);
-               printf("TMU: Texel cache:\n");
-               misses = CSR_TMUP_MISSES;
-               hits = pixels-misses;
-               printf("TMU:   - hits:                             %d\n", hits);
-               printf("TMU:   - misses:                           %d\n", misses);
-               printf("TMU:   - hit rate:                         %d%%\n", 100*hits/(hits+misses));
-               printf("TMU: ====================================================\n");
-       }
-       consume = (consume + 1) & TMU_TASKQ_MASK;
-       level--;
-       if(level > 0)
-               tmu_start(queue[consume]); /* IRQ automatically acked */
-       else {
-               cts = 1;
-               CSR_TMU_CTL = 0; /* Ack IRQ */
-       }
-}
-
-int tmu_submit_task(struct tmu_td *td)
-{
-       unsigned int oldmask;
-
-       oldmask = irq_getmask();
-       irq_setmask(oldmask & (~IRQ_TMU));
-
-       if(level >= TMU_TASKQ_SIZE) {
-               irq_setmask(oldmask);
-               printf("TMU: taskq overflow\n");
-               return 0;
-       }
-
-       queue[produce] = td;
-       produce = (produce + 1) & TMU_TASKQ_MASK;
-       level++;
-
-       if(cts) {
-               cts = 0;
-               tmu_start(td);
-       }
-
-       irq_setmask(oldmask);
-
-       return 1;
-}
-
diff --git a/software/demo/tmu.h b/software/demo/tmu.h
deleted file mode 100644 (file)
index fb0c3e9..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __TMU_H
-#define __TMU_H
-
-#include <hw/tmu.h>
-
-struct tmu_td;
-
-typedef void (*tmu_callback)(struct tmu_td *);
-
-struct tmu_td {
-       unsigned int flags;
-       unsigned int hmeshlast;
-       unsigned int vmeshlast;
-       unsigned int brightness;
-       unsigned short chromakey;
-       struct tmu_vertex *srcmesh;
-       unsigned short *srcfbuf;
-       unsigned int srchres;
-       unsigned int srcvres;
-       struct tmu_vertex *dstmesh;
-       unsigned short *dstfbuf;
-       unsigned int dsthres;
-       unsigned int dstvres;
-
-       int profile; /* < prints profiling info after completion */
-       tmu_callback callback;
-       void *user; /* < for application use */
-};
-
-void tmu_init();
-void tmu_isr();
-int tmu_submit_task(struct tmu_td *td);
-
-#endif /* __TMU_H */
index 54f81f2..543feec 100644 (file)
 #include <hw/sysctl.h>
 #include <hw/gpio.h>
 
+#include <hal/hdlcd.h>
+#include <hal/time.h>
+
 #include "renderer.h"
-#include "hdlcd.h"
-#include "time.h"
 #include "rpipe.h"
 #include "cpustats.h"
 #include "ui.h"
diff --git a/software/demo/vga.c b/software/demo/vga.c
deleted file mode 100644 (file)
index bcc88b3..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <console.h>
-#include <hw/vga.h>
-
-/*
- * RGB565 framebuffers.
- * We use page flipping triple buffering as described on
- * http://en.wikipedia.org/wiki/Triple_buffering
- *
- * Buffers must be aligned to the start of an FML burst
- * which is 4x64 bits, that is, 256 bits, or 32 bytes.
- */
-static unsigned short int framebufferA[640*480] __attribute__((aligned(32)));
-static unsigned short int framebufferB[640*480] __attribute__((aligned(32)));
-static unsigned short int framebufferC[640*480] __attribute__((aligned(32)));
-
-int vga_hres;
-int vga_vres;
-
-unsigned short int *vga_frontbuffer; /* < buffer currently displayed (or request sent to HW) */
-unsigned short int *vga_backbuffer;  /* < buffer currently drawn to, never read by HW */
-unsigned short int *vga_lastbuffer;  /* < buffer displayed just before (or HW finishing last scan) */
-
-void vga_init()
-{
-       vga_hres = 640;
-       vga_vres = 480;
-       
-       vga_frontbuffer = framebufferA;
-       vga_backbuffer = framebufferB;
-       vga_lastbuffer = framebufferC;
-       
-       CSR_VGA_BASEADDRESS = (unsigned int)vga_frontbuffer;
-
-       /* by default, VGA core puts out 640x480@60Hz */
-       CSR_VGA_RESET = 0;
-
-       printf("VGA: initialized at resolution %dx%d\n", vga_hres, vga_vres);
-       printf("VGA: framebuffers at 0x%08x 0x%08x 0x%08x\n",
-               (unsigned int)&framebufferA, (unsigned int)&framebufferB, (unsigned int)&framebufferC);
-}
-
-void vga_disable()
-{
-       CSR_VGA_RESET = VGA_RESET;
-}
-
-void vga_swap_buffers()
-{
-       unsigned short int *p;
-
-       /*
-        * Make sure last buffer swap has been executed.
-        * Beware, DMA address registers of vgafb are incomplete
-        * (only LSBs are present) so don't compare them directly
-        * with CPU pointers.
-        */
-       while(CSR_VGA_BASEADDRESS_ACT != CSR_VGA_BASEADDRESS);
-
-       p = vga_frontbuffer;
-       vga_frontbuffer = vga_backbuffer;
-       vga_backbuffer = vga_lastbuffer;
-       vga_lastbuffer = p;
-       
-       CSR_VGA_BASEADDRESS = (unsigned int)vga_frontbuffer;
-}
diff --git a/software/demo/vga.h b/software/demo/vga.h
deleted file mode 100644 (file)
index 4178741..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Milkymist VJ SoC (Software)
- * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __VGA_H
-#define __VGA_H
-
-extern int vga_hres;
-extern int vga_vres;
-extern unsigned short int *vga_frontbuffer;
-extern unsigned short int *vga_backbuffer;
-extern unsigned short int *vga_lastbuffer;
-
-void vga_init();
-void vga_disable();
-void vga_swap_buffers();
-
-#endif /* __VGA_H */
diff --git a/software/include/hal/brd.h b/software/include/hal/brd.h
new file mode 100644 (file)
index 0000000..6ee6834
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HAL_BRD_H
+#define __HAL_BRD_H
+
+extern const struct board_desc *brd_desc;
+
+void brd_init();
+
+#endif /* __HAL_BRD_H */
diff --git a/software/include/hal/hdlcd.h b/software/include/hal/hdlcd.h
new file mode 100644 (file)
index 0000000..4aba1d0
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HAL_HDLCD_H
+#define __HAL_HDLCD_H
+
+void hdlcd_init();
+void hdlcd_clear();
+int hdlcd_printf(const char *fmt, ...);
+
+#endif /* __HAL_HDLCD_H */
diff --git a/software/include/hal/mem.h b/software/include/hal/mem.h
new file mode 100644 (file)
index 0000000..89881f3
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HAL_MEM_H
+#define __HAL_MEM_H
+
+#define BANK_SDRAM     (0)
+#define BANK_SRAM      (1)
+
+void mem_init();
+
+#endif /* __HAL_MEM_H */
diff --git a/software/include/hal/pfpu.h b/software/include/hal/pfpu.h
new file mode 100644 (file)
index 0000000..c990a33
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HAL_PFPU_H
+#define __HAL_PFPU_H
+
+#include <hw/pfpu.h>
+
+struct pfpu_td;
+
+typedef void (*pfpu_callback)(struct pfpu_td *);
+
+struct pfpu_td {
+       unsigned int *output;
+       unsigned int hmeshlast;
+       unsigned int vmeshlast;
+       pfpu_instruction *program;
+       unsigned int progsize;
+       float *registers;
+       int update; /* < shall we update the "registers" array after completion */
+       int invalidate; /* < shall we invalidate L1 data cache after completion */
+       pfpu_callback callback;
+       void *user; /* < for application use */
+};
+
+void pfpu_init();
+void pfpu_isr();
+int pfpu_submit_task(struct pfpu_td *td);
+
+#endif /* __HAL_PFPU_H */
diff --git a/software/include/hal/slowout.h b/software/include/hal/slowout.h
new file mode 100644 (file)
index 0000000..c65c090
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HAL_SLOWOUT_H
+#define __HAL_SLOWOUT_H
+
+void slowout_init();
+void slowout_isr();
+int slowout_queue(unsigned int duration, unsigned int mask);
+
+#endif /* __HAL_SLOWOUT_H */
diff --git a/software/include/hal/snd.h b/software/include/hal/snd.h
new file mode 100644 (file)
index 0000000..0fb84c7
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HAL_SND_H
+#define __HAL_SND_H
+
+#include <hw/ac97.h>
+
+void snd_init();
+void snd_isr_crrequest();
+void snd_isr_crreply();
+void snd_isr_dmar();
+void snd_isr_dmaw();
+
+unsigned int snd_ac97_read(unsigned int addr);
+void snd_ac97_write(unsigned int addr, unsigned int value);
+
+typedef void (*snd_callback)(short *buffer, void *user);
+
+void snd_play_empty();
+int snd_play_refill(short *buffer);
+void snd_play_start(snd_callback callback, unsigned int nsamples, void *user);
+void snd_play_stop();
+int snd_play_active();
+
+void snd_record_empty();
+int snd_record_refill(short *buffer);
+void snd_record_start(snd_callback callback, unsigned int nsamples, void *user);
+void snd_record_stop();
+int snd_record_active();
+
+/*
+ * Each sample has 2 channels and 16 bits per channel
+ * making up 4 bytes per sample.
+ */
+#define SND_MAX_NSAMPLES (AC97_MAX_DMASIZE/4)
+
+#endif /* __HAL_SND_H */
diff --git a/software/include/hal/time.h b/software/include/hal/time.h
new file mode 100644 (file)
index 0000000..c7492f7
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HAL_TIME_H
+#define __HAL_TIME_H
+
+struct timestamp {
+       int sec;
+       int usec;
+};
+
+void time_init();
+void time_isr();
+
+void time_get(struct timestamp *ts);
+
+void time_add(struct timestamp *dest, struct timestamp *delta);
+void time_diff(struct timestamp *dest, struct timestamp *t1, struct timestamp *t0);
+
+void time_tick(); /* provided by app */
+
+#endif /* __HAL_TIME_H */
diff --git a/software/include/hal/tmu.h b/software/include/hal/tmu.h
new file mode 100644 (file)
index 0000000..4ac1eb1
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HAL_TMU_H
+#define __HAL_TMU_H
+
+#include <hw/tmu.h>
+
+struct tmu_td;
+
+typedef void (*tmu_callback)(struct tmu_td *);
+
+struct tmu_td {
+       unsigned int flags;
+       unsigned int hmeshlast;
+       unsigned int vmeshlast;
+       unsigned int brightness;
+       unsigned short chromakey;
+       struct tmu_vertex *srcmesh;
+       unsigned short *srcfbuf;
+       unsigned int srchres;
+       unsigned int srcvres;
+       struct tmu_vertex *dstmesh;
+       unsigned short *dstfbuf;
+       unsigned int dsthres;
+       unsigned int dstvres;
+
+       int profile; /* < prints profiling info after completion */
+       tmu_callback callback;
+       void *user; /* < for application use */
+};
+
+void tmu_init();
+void tmu_isr();
+int tmu_submit_task(struct tmu_td *td);
+
+#endif /* __HAL_TMU_H */
diff --git a/software/include/hal/vga.h b/software/include/hal/vga.h
new file mode 100644 (file)
index 0000000..37a3551
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HAL_VGA_H
+#define __HAL_VGA_H
+
+extern int vga_hres;
+extern int vga_vres;
+extern unsigned short int *vga_frontbuffer;
+extern unsigned short int *vga_backbuffer;
+extern unsigned short int *vga_lastbuffer;
+
+void vga_init();
+void vga_disable();
+void vga_swap_buffers();
+
+#endif /* __HAL_VGA_H */
index d055e36..979ce01 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef __VERSION_H
 #define __VERSION_H
 
-#define VERSION "0.1.2"
+#define VERSION "0.1.3"
 
 #endif /* __VERSION_H */
index 4de25a8..02ab573 100644 (file)
@@ -19,7 +19,7 @@
 #include <libc.h>
 #include <board.h>
 
-static const struct board_desc boards[2] = {
+static const struct board_desc boards[3] = {
        {
                .id = 0x58343031, /* X401 */
                .name = "Xilinx ML401 development board",
diff --git a/software/libhal/Makefile b/software/libhal/Makefile
new file mode 100644 (file)
index 0000000..e89f1c8
--- /dev/null
@@ -0,0 +1,59 @@
+MMDIR?=../..
+include $(MMDIR)/software/include.mak
+
+OBJECTS=brd.o hdlcd.o mem.o pfpu.o slowout.o snd.o time.o tmu.o vga.o
+
+all: libhal.a
+
+libhal.a: $(OBJECTS)
+       $(AR) clr libhal.a $(OBJECTS)
+       $(RANLIB) libhal.a
+
+.PHONY: clean depend
+
+depend:
+       makedepend -Y -- $(CFLAGS) -- *.c
+
+clean:
+       rm -f *.o libhal.a .*~ *~ Makefile.bak
+
+# DO NOT DELETE
+
+brd.o: ../../software/include/libc.h ../../software/include/console.h
+brd.o: ../../software/include/board.h ../../software/include/hal/brd.h
+hdlcd.o: ../../software/include/libc.h ../../software/include/board.h
+hdlcd.o: ../../software/include/console.h ../../software/include/hw/sysctl.h
+hdlcd.o: ../../software/include/hw/common.h ../../software/include/hw/gpio.h
+hdlcd.o: ../../software/include/hal/brd.h
+hdlcd.o: ../../software/include/hal/slowout.h
+hdlcd.o: ../../software/include/hal/hdlcd.h
+mem.o: ../../software/include/libc.h ../../software/include/console.h
+mem.o: ../../software/include/malloc.h ../../software/include/hw/sram.h
+mem.o: ../../software/include/hal/mem.h
+pfpu.o: ../../software/include/libc.h ../../software/include/console.h
+pfpu.o: ../../software/include/irq.h ../../software/include/hw/interrupts.h
+pfpu.o: ../../software/include/hw/pfpu.h ../../software/include/hw/common.h
+pfpu.o: ../../software/include/hal/pfpu.h
+slowout.o: ../../software/include/libc.h ../../software/include/console.h
+slowout.o: ../../software/include/irq.h
+slowout.o: ../../software/include/hw/interrupts.h
+slowout.o: ../../software/include/hw/sysctl.h
+slowout.o: ../../software/include/hw/common.h
+slowout.o: ../../software/include/hal/slowout.h
+snd.o: ../../software/include/libc.h ../../software/include/console.h
+snd.o: ../../software/include/irq.h ../../software/include/hw/ac97.h
+snd.o: ../../software/include/hw/common.h
+snd.o: ../../software/include/hw/interrupts.h
+snd.o: ../../software/include/hal/snd.h
+time.o: ../../software/include/libc.h ../../software/include/console.h
+time.o: ../../software/include/irq.h ../../software/include/board.h
+time.o: ../../software/include/hw/sysctl.h ../../software/include/hw/common.h
+time.o: ../../software/include/hw/interrupts.h
+time.o: ../../software/include/hal/brd.h ../../software/include/hal/time.h
+tmu.o: ../../software/include/libc.h ../../software/include/console.h
+tmu.o: ../../software/include/irq.h ../../software/include/board.h
+tmu.o: ../../software/include/hw/interrupts.h ../../software/include/hw/tmu.h
+tmu.o: ../../software/include/hw/common.h ../../software/include/hal/brd.h
+tmu.o: ../../software/include/hal/tmu.h
+vga.o: ../../software/include/console.h ../../software/include/hw/vga.h
+vga.o: ../../software/include/hw/common.h ../../software/include/hal/vga.h
diff --git a/software/libhal/brd.c b/software/libhal/brd.c
new file mode 100644 (file)
index 0000000..66b808e
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libc.h>
+#include <console.h>
+#include <board.h>
+
+#include <hal/brd.h>
+
+const struct board_desc *brd_desc;
+
+void brd_init()
+{
+       brd_desc = get_board_desc();
+       if(brd_desc == NULL) {
+               printf("BRD: Fatal error, unknown board\n");
+               while(1);
+       }
+       printf("BRD: detected %s\n", brd_desc->name);
+}
diff --git a/software/libhal/hdlcd.c b/software/libhal/hdlcd.c
new file mode 100644 (file)
index 0000000..f1a43d0
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libc.h>
+#include <board.h>
+#include <console.h>
+#include <hw/sysctl.h>
+#include <hw/gpio.h>
+
+#include <hal/brd.h>
+#include <hal/slowout.h>
+#include <hal/hdlcd.h>
+
+/* In tenths of microseconds */
+#define SETUP_DELAY 3
+#define CLOCK_DELAY 130
+#define OP_DELAY 10000
+
+/* In clock cycles */
+static unsigned int setup_delay;
+static unsigned int clock_delay;
+static unsigned int op_delay;
+
+static void hdlcd_send_byte(char c, int isdata)
+{
+       unsigned int mask;
+       unsigned int b = c;
+
+       if(isdata)
+               mask = GPIO_HDLCDRS;
+       else
+               mask = 0;
+
+       slowout_queue(setup_delay, mask|(((b & 0xf0) >> 4) << GPIO_HDLCDD_SHIFT));
+       slowout_queue(clock_delay, mask|GPIO_HDLCDE|(((b & 0xf0) >> 4) << GPIO_HDLCDD_SHIFT));
+       slowout_queue(clock_delay, mask|(((b & 0xf0) >> 4) << GPIO_HDLCDD_SHIFT));
+
+       slowout_queue(setup_delay, mask|((b & 0x0f) << GPIO_HDLCDD_SHIFT));
+       slowout_queue(clock_delay, mask|GPIO_HDLCDE|((b & 0x0f) << GPIO_HDLCDD_SHIFT));
+       slowout_queue(clock_delay+op_delay, mask|((b & 0x0f) << GPIO_HDLCDD_SHIFT));
+}
+
+void hdlcd_init()
+{
+       setup_delay = SETUP_DELAY*(brd_desc->clk_frequency/10000000);
+       clock_delay = CLOCK_DELAY*(brd_desc->clk_frequency/10000000);
+       op_delay = OP_DELAY*(brd_desc->clk_frequency/10000000);
+
+       if(!(CSR_GPIO_IN & GPIO_DIP3)) {
+               /* Select 4-bit operation on the LCD */
+               slowout_queue(setup_delay, GPIO_HDLCDD5);
+               slowout_queue(clock_delay, GPIO_HDLCDE|GPIO_HDLCDD5);
+               slowout_queue(clock_delay+op_delay, GPIO_HDLCDD5);
+       }
+       
+       /* Set up the LCD */
+       hdlcd_send_byte(0x28, 0);
+       hdlcd_send_byte(0x0c, 0);
+       hdlcd_send_byte(0x06, 0);
+       hdlcd_send_byte(0x01, 0);
+
+       printf("LCD: ready\n");
+}
+
+void hdlcd_clear()
+{
+       hdlcd_send_byte(0x01, 0);
+}
+
+int hdlcd_printf(const char *fmt, ...)
+{
+       va_list args;
+       char buffer[34];
+       unsigned i;
+       int len;
+
+       va_start(args, fmt);
+       len = vscnprintf(buffer, sizeof(buffer), fmt, args);
+       va_end(args);
+       
+       hdlcd_send_byte(0x80, 0);
+
+       for(i=0;i<len;i++) {
+               if(buffer[i] == '\n')
+                       hdlcd_send_byte(0xc0, 0);
+               else
+                       hdlcd_send_byte(buffer[i], 1);
+       }
+
+       return len;
+}
diff --git a/software/libhal/mem.c b/software/libhal/mem.c
new file mode 100644 (file)
index 0000000..595ad2f
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libc.h>
+#include <console.h>
+#include <malloc.h>
+#include <hw/sram.h>
+
+#include <hal/mem.h>
+
+static char heap[16*1024*1024] __attribute__((aligned(8)));
+
+struct malloc_bank banks[2] = {
+       {
+               .addr_start = (unsigned int)&heap,
+               .addr_end = (unsigned int)&heap + sizeof(heap)
+       },
+       {
+               .addr_start = SRAM_BASE,
+               .addr_end = SRAM_BASE + SRAM_SIZE
+       }
+};
+
+void mem_init()
+{
+       int i, n;
+       
+       n = sizeof(banks)/sizeof(struct malloc_bank);
+       malloc_init(banks, n, BANK_SDRAM);
+       printf("MEM: registered %d dynamic banks:\n", n);
+       for(i=0;i<n;i++)
+               printf("MEM:   #%d 0x%08x-0x%08x\n", i, banks[i].addr_start, banks[i].addr_end);
+}
diff --git a/software/libhal/pfpu.c b/software/libhal/pfpu.c
new file mode 100644 (file)
index 0000000..ac6a55c
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libc.h>
+#include <console.h>
+#include <irq.h>
+#include <hw/interrupts.h>
+#include <hw/pfpu.h>
+
+#include <hal/pfpu.h>
+
+#define PFPU_TASKQ_SIZE 4 /* < must be a power of 2 */
+#define PFPU_TASKQ_MASK (PFPU_TASKQ_SIZE-1)
+
+static struct pfpu_td *queue[PFPU_TASKQ_SIZE];
+static unsigned int produce;
+static unsigned int consume;
+static unsigned int level;
+static int cts;
+
+void pfpu_init()
+{
+       unsigned int mask;
+
+       CSR_PFPU_CTL = 0; /* Ack any pending IRQ */
+
+       produce = 0;
+       consume = 0;
+       level = 0;
+       cts = 1;
+
+       mask = irq_getmask();
+       mask |= IRQ_PFPU;
+       irq_setmask(mask);
+       
+       printf("FPU: programmable floating point unit initialized\n");
+}
+
+static void load_program(pfpu_instruction *program, int size)
+{
+       int page;
+       int word;
+       volatile pfpu_instruction *pfpu_prog = (pfpu_instruction *)CSR_PFPU_CODEBASE;
+
+       for(page=0;page<(PFPU_PROGSIZE/PFPU_PAGESIZE);page++) {
+               for(word=0;word<PFPU_PAGESIZE;word++) {
+                       if(size == 0) return;
+                       pfpu_prog[word] = *program;
+                       program++;
+                       size--;
+               }
+       }
+}
+
+static void load_registers(float *registers)
+{
+       volatile float *pfpu_regs = (float *)CSR_PFPU_DREGBASE;
+       int i;
+
+       for(i=0;i<PFPU_REG_COUNT;i++) {
+               if(pfpu_is_reserved(i)) continue;
+               pfpu_regs[i] = registers[i];
+       }
+}
+
+static void update_registers(float *registers)
+{
+       volatile float *pfpu_regs = (float *)CSR_PFPU_DREGBASE;
+       int i;
+
+       for(i=0;i<PFPU_REG_COUNT;i++) {
+               if(pfpu_is_reserved(i)) continue;
+               registers[i] = pfpu_regs[i];
+       }
+}
+
+static void pfpu_start(struct pfpu_td *td)
+{
+       load_program(td->program, td->progsize);
+       load_registers(td->registers);
+       CSR_PFPU_MESHBASE = (unsigned int)td->output;
+       CSR_PFPU_HMESHLAST = td->hmeshlast;
+       CSR_PFPU_VMESHLAST = td->vmeshlast;
+
+       CSR_PFPU_CTL = PFPU_CTL_START;
+}
+
+void pfpu_isr()
+{
+       if(queue[consume]->update)
+               update_registers(queue[consume]->registers);
+       if(queue[consume]->invalidate) {
+               asm volatile( /* Invalidate Level-1 data cache */
+                       "wcsr DCC, r0\n"
+                       "nop\n"
+               );
+       }
+       queue[consume]->callback(queue[consume]);
+       consume = (consume + 1) & PFPU_TASKQ_MASK;
+       level--;
+       if(level > 0)
+               pfpu_start(queue[consume]); /* IRQ automatically acked */
+       else {
+               cts = 1;
+               CSR_PFPU_CTL = 0; /* Ack IRQ */
+       }
+}
+
+int pfpu_submit_task(struct pfpu_td *td)
+{
+       unsigned int oldmask;
+
+       oldmask = irq_getmask();
+       irq_setmask(oldmask & (~IRQ_PFPU));
+
+       if(level >= PFPU_TASKQ_SIZE) {
+               irq_setmask(oldmask);
+               printf("FPU: taskq overflow\n");
+               return 0;
+       }
+
+       queue[produce] = td;
+       produce = (produce + 1) & PFPU_TASKQ_MASK;
+       level++;
+
+       if(cts) {
+               cts = 0;
+               pfpu_start(td);
+       }
+
+       irq_setmask(oldmask);
+
+       return 1;
+}
diff --git a/software/libhal/slowout.c b/software/libhal/slowout.c
new file mode 100644 (file)
index 0000000..49dd535
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Asynchronous slow outputs - Using HW timer 1 */
+
+#include <libc.h>
+#include <console.h>
+#include <irq.h>
+#include <hw/interrupts.h>
+#include <hw/sysctl.h>
+
+#include <hal/slowout.h>
+
+struct slowout_operation {
+       unsigned int duration;
+       unsigned int mask;
+};
+
+#define OPQ_SIZE 1024 /* < must be a power of 2 */
+#define OPQ_MASK (OPQ_SIZE-1)
+
+static struct slowout_operation queue[OPQ_SIZE];
+static unsigned int produce;
+static unsigned int consume;
+static unsigned int level;
+static int cts;
+
+void slowout_init()
+{
+       unsigned int mask;
+
+       produce = 0;
+       consume = 0;
+       level = 0;
+       cts = 1;
+
+       CSR_TIMER1_CONTROL = 0; /* Disable timer + ack any pending IRQ */
+
+       mask = irq_getmask();
+       mask |= IRQ_TIMER1;
+       irq_setmask(mask);
+
+       printf("SLO: slow outputs initialized\n");
+}
+
+static void slowout_start(struct slowout_operation *op)
+{
+       CSR_GPIO_OUT = op->mask;
+       CSR_TIMER1_COUNTER = 0;
+       CSR_TIMER1_COMPARE = op->duration;
+       CSR_TIMER1_CONTROL = TIMER_ENABLE;
+}
+
+void slowout_isr()
+{
+       consume = (consume + 1) & OPQ_MASK;
+       level--;
+       if(level > 0)
+               slowout_start(&queue[consume]);
+       else {
+               CSR_TIMER1_CONTROL = 0; /* Ack IRQ */
+               cts = 1;
+       }
+}
+
+int slowout_queue(unsigned int duration, unsigned int mask)
+{
+       unsigned int oldmask;
+
+       oldmask = irq_getmask();
+       irq_setmask(oldmask & (~IRQ_TIMER1));
+
+       if(level >= OPQ_SIZE) {
+               irq_setmask(oldmask);
+               printf("SLO: opq overflow\n");
+               return 0;
+       }
+
+       queue[produce].duration = duration;
+       queue[produce].mask = mask;
+       if(cts) {
+               cts = 0;
+               slowout_start(&queue[produce]);
+       }
+       produce = (produce + 1) & OPQ_MASK;
+       level++;
+
+       irq_setmask(oldmask);
+
+       return 1;
+}
+
diff --git a/software/libhal/snd.c b/software/libhal/snd.c
new file mode 100644 (file)
index 0000000..2b56c08
--- /dev/null
@@ -0,0 +1,329 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libc.h>
+#include <console.h>
+#include <irq.h>
+#include <hw/ac97.h>
+#include <hw/interrupts.h>
+
+#include <hal/snd.h>
+
+/****************************************************************/
+/* GENERAL                                                      */
+/****************************************************************/
+
+/*
+ * We use interrupts and busy wait on those variables
+ * (which end up in the data cache) rather than
+ * busy waiting on the CSR, which would use bus bandwidth
+ * for nothing.
+ */
+static volatile int snd_cr_request;
+static volatile int snd_cr_reply;
+
+void snd_init()
+{
+       unsigned int codec_id;
+       unsigned int mask;
+       
+       snd_cr_request = 0;
+       snd_cr_reply = 0;
+       CSR_AC97_DCTL = 0;
+       CSR_AC97_UCTL = 0;
+       
+       mask = irq_getmask();
+       mask |= IRQ_AC97CRREQUEST|IRQ_AC97CRREPLY|IRQ_AC97DMAR|IRQ_AC97DMAW;
+       irq_setmask(mask);
+       
+       codec_id = snd_ac97_read(0x00);
+       if(codec_id == 0x0d50)
+               printf("SND: found LM4550 AC'97 codec\n");
+       else
+               printf("SND: warning, unknown codec found (ID:%04x)\n", codec_id);
+       
+       /* Unmute and set volumes */
+       /* TODO: API for this */
+       snd_ac97_write(0x02, 0x0000);
+       snd_ac97_write(0x04, 0x0f0f);
+       snd_ac97_write(0x18, 0x0000);
+       snd_ac97_write(0x0e, 0x0000);
+       snd_ac97_write(0x1c, 0x0f0f);
+
+       snd_play_empty();
+       snd_record_empty();
+       
+       printf("SND: initialization complete\n");
+}
+
+void snd_isr_crrequest()
+{
+       snd_cr_request = 1;
+       CSR_AC97_CRCTL = AC97_CRCTL_REQUEST; /* Ack interrupt */
+}
+
+void snd_isr_crreply()
+{
+       snd_cr_reply = 1;
+       CSR_AC97_CRCTL = AC97_CRCTL_REPLY; /* Ack interrupt */
+}
+
+unsigned int snd_ac97_read(unsigned int addr)
+{
+       CSR_AC97_CRADDR = addr;
+       snd_cr_reply = 0;
+       CSR_AC97_CRCTL = AC97_CRCTL_RQEN;
+       while(!snd_cr_reply);
+       return CSR_AC97_CRDATAIN;
+}
+
+void snd_ac97_write(unsigned int addr, unsigned int value)
+{
+       CSR_AC97_CRADDR = addr;
+       CSR_AC97_CRDATAOUT = value;
+       snd_cr_request = 0;
+       CSR_AC97_CRCTL = AC97_CRCTL_RQEN|AC97_CRCTL_WRITE;
+       while(!snd_cr_request);
+}
+
+/****************************************************************/
+/* PLAYING                                                      */
+/****************************************************************/
+
+static snd_callback play_callback;
+static void *play_user;
+static unsigned int play_nbytes;
+
+#define PLAY_BUFQ_SIZE 4 /* < must be a power of 2 */
+#define PLAY_BUFQ_MASK (PLAY_BUFQ_SIZE-1)
+
+static short *play_queue[PLAY_BUFQ_SIZE];
+static unsigned int play_produce;
+static unsigned int play_consume;
+static unsigned int play_level;
+static int play_underrun;
+
+static void play_start(short *buffer)
+{
+       CSR_AC97_DADDRESS = (unsigned int)buffer;
+       CSR_AC97_DREMAINING = play_nbytes;
+       CSR_AC97_DCTL = AC97_SCTL_EN; /* Start/ack interrupt */
+}
+
+void snd_isr_dmar()
+{
+       /* NB. the callback can give us buffers by calling snd_play_refill() */
+       play_callback(play_queue[play_consume], play_user);
+
+       play_consume = (play_consume + 1) & PLAY_BUFQ_MASK;
+       play_level--;
+
+       if(play_level > 0)
+               play_start(play_queue[play_consume]);
+       else {
+               printf("SND: playing underrun\n");
+               play_underrun = 1;
+               CSR_AC97_DCTL = AC97_SCTL_EN; /* Ack interrupt anyway */
+       }
+}
+
+void snd_play_empty()
+{
+       play_produce = 0;
+       play_consume = 0;
+       play_level = 0;
+       play_underrun = 0;
+}
+
+int snd_play_refill(short *buffer)
+{
+       unsigned int oldmask;
+
+       oldmask = irq_getmask();
+       irq_setmask(oldmask & (~IRQ_AC97DMAR));
+       
+       if(play_level >= PLAY_BUFQ_SIZE) {
+               irq_setmask(oldmask);
+               printf("SND: play bufq overflow\n");
+               return 0;
+       }
+
+       play_queue[play_produce] = buffer;
+       play_produce = (play_produce + 1) & PLAY_BUFQ_MASK;
+       play_level++;
+
+       if(play_underrun) {
+               play_underrun = 0;
+               play_start(buffer);
+       }
+
+       irq_setmask(oldmask);
+       
+       return 1;
+}
+
+void snd_play_start(snd_callback callback, unsigned int nsamples, void *user)
+{
+       if(snd_play_active()) {
+               printf("SND: snd_play_start called while already playing\n");
+               return;
+       }
+       
+       play_callback = callback;
+       play_user = user;
+       play_nbytes = nsamples*4;
+
+       if(play_level > 0)
+               play_start(play_queue[play_consume]);
+       else {
+               printf("SND: playing underrun\n");
+               play_underrun = 1;
+       }
+}
+
+void snd_play_stop()
+{
+       unsigned int oldmask;
+
+       oldmask = irq_getmask();
+       irq_setmask(oldmask & (~IRQ_AC97DMAR));
+       CSR_AC97_DCTL = 0; /* this also acks any pending IRQ in the AC97 core */
+       irq_ack(IRQ_AC97DMAR);
+       irq_setmask(oldmask);
+}
+
+int snd_play_active()
+{
+       return(CSR_AC97_DCTL & AC97_SCTL_EN);
+}
+
+/****************************************************************/
+/* RECORDING                                                    */
+/****************************************************************/
+
+static snd_callback record_callback;
+static void *record_user;
+
+static unsigned int record_nbytes;
+
+#define RECORD_BUFQ_SIZE 4 /* < must be a power of 2 */
+#define RECORD_BUFQ_MASK (RECORD_BUFQ_SIZE-1)
+
+static short *record_queue[RECORD_BUFQ_SIZE];
+static unsigned int record_produce;
+static unsigned int record_consume;
+static unsigned int record_level;
+static int record_overrun;
+
+static void record_start(short *buffer)
+{
+       CSR_AC97_UADDRESS = (unsigned int)buffer;
+       CSR_AC97_UREMAINING = record_nbytes;
+       CSR_AC97_UCTL = AC97_SCTL_EN; /* Start/ack interrupt */
+}
+
+void snd_isr_dmaw()
+{
+       asm volatile( /* Invalidate Level-1 data cache */
+               "wcsr DCC, r0\n"
+               "nop\n"
+       );
+       
+       /* NB. the callback can give us buffers by calling snd_record_refill() */
+       record_callback(record_queue[record_consume], record_user);
+
+       record_consume = (record_consume + 1) & RECORD_BUFQ_MASK;
+       record_level--;
+
+       if(record_level > 0)
+               record_start(record_queue[record_consume]);
+       else {
+               printf("SND: recording overrun\n");
+               record_overrun = 1;
+               CSR_AC97_UCTL = AC97_SCTL_EN; /* Ack interrupt anyway */
+       }
+}
+
+void snd_record_empty()
+{
+       record_produce = 0;
+       record_consume = 0;
+       record_level = 0;
+       record_overrun = 0;
+}
+
+int snd_record_refill(short *buffer)
+{
+       unsigned int oldmask;
+
+       oldmask = irq_getmask();
+       irq_setmask(oldmask & (~IRQ_AC97DMAW));
+
+       if(record_level >= RECORD_BUFQ_SIZE) {
+               irq_setmask(oldmask);
+               printf("SND: record bufq overflow\n");
+               return 0;
+       }
+
+       record_queue[record_produce] = buffer;
+       record_produce = (record_produce + 1) & RECORD_BUFQ_MASK;
+       record_level++;
+
+       if(record_overrun) {
+               record_overrun = 0;
+               record_start(buffer);
+       }
+
+       irq_setmask(oldmask);
+
+       return 1;
+}
+
+void snd_record_start(snd_callback callback, unsigned int nsamples, void *user)
+{
+       if(snd_record_active()) {
+               printf("SND: snd_record_start called while already recording\n");
+               return;
+       }
+
+       record_callback = callback;
+       record_user = user;
+       record_nbytes = nsamples*4;
+
+       if(record_level > 0)
+               record_start(record_queue[record_consume]);
+       else {
+               printf("SND: recording overrun\n");
+               record_overrun = 1;
+       }
+}
+
+void snd_record_stop()
+{
+       unsigned int oldmask;
+
+       oldmask = irq_getmask();
+       irq_setmask(oldmask & (~IRQ_AC97DMAW));
+       CSR_AC97_UCTL = 0; /* this also acks any pending IRQ in the AC97 core */
+       irq_ack(IRQ_AC97DMAW);
+       irq_setmask(oldmask);
+}
+
+int snd_record_active()
+{
+       return(CSR_AC97_UCTL & AC97_SCTL_EN);
+}
diff --git a/software/libhal/time.c b/software/libhal/time.c
new file mode 100644 (file)
index 0000000..ae0489a
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* SYSTEM CLOCK - Using HW timer 0 */
+
+#include <libc.h>
+#include <console.h>
+#include <irq.h>
+#include <board.h>
+#include <hw/sysctl.h>
+#include <hw/interrupts.h>
+
+#include <hal/brd.h>
+#include <hal/time.h>
+
+static int sec;
+
+void time_init()
+{
+       unsigned int mask;
+       
+       CSR_TIMER0_COUNTER = 0;
+       CSR_TIMER0_COMPARE = brd_desc->clk_frequency;
+       CSR_TIMER0_CONTROL = TIMER_AUTORESTART|TIMER_ENABLE;
+
+       mask = irq_getmask();
+       mask |= IRQ_TIMER0;
+       irq_setmask(mask);
+
+       printf("TIM: system timer started\n");
+}
+
+void time_isr()
+{
+       sec++;
+       CSR_TIMER0_CONTROL = TIMER_AUTORESTART|TIMER_ENABLE; /* Ack interrupt */
+       time_tick();
+}
+
+void time_get(struct timestamp *ts)
+{
+       unsigned int oldmask = 0;
+       unsigned int ctl, counter, sec2;
+
+       oldmask = irq_getmask();
+       irq_setmask(oldmask & ~(IRQ_TIMER0));
+       counter = CSR_TIMER0_COUNTER;
+       ctl = CSR_TIMER0_CONTROL;
+       sec2 = sec;
+       irq_setmask(oldmask);
+
+       ts->sec = sec2;
+       ts->usec = counter/(brd_desc->clk_frequency/1000000);
+       
+       /*
+        * If the counter is less than half a second, we consider that
+        * the overflow was already present when we read the counter
+        * value.
+        */
+       if(ctl & TIMER_MATCH) {
+               if(counter < (brd_desc->clk_frequency/2))
+                       ts->sec++;
+       }
+}
+
+void time_add(struct timestamp *dest, struct timestamp *delta)
+{
+       dest->sec += delta->sec;
+       dest->usec += delta->usec;
+       if(dest->usec >= 1000000) {
+               dest->sec++;
+               dest->usec -= 1000000;
+       }
+}
+
+void time_diff(struct timestamp *dest, struct timestamp *t1, struct timestamp *t0)
+{
+       dest->sec = t1->sec - t0->sec;
+       dest->usec = t1->usec - t0->usec;
+       if(dest->usec < 0) {
+               dest->sec--;
+               dest->usec += 1000000;
+       }
+}
diff --git a/software/libhal/tmu.c b/software/libhal/tmu.c
new file mode 100644 (file)
index 0000000..ce0095a
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libc.h>
+#include <console.h>
+#include <irq.h>
+#include <board.h>
+#include <hw/interrupts.h>
+#include <hw/tmu.h>
+
+#include <hal/brd.h>
+#include <hal/tmu.h>
+
+#define TMU_TASKQ_SIZE 4 /* < must be a power of 2 */
+#define TMU_TASKQ_MASK (TMU_TASKQ_SIZE-1)
+
+static struct tmu_td *queue[TMU_TASKQ_SIZE];
+static unsigned int produce;
+static unsigned int consume;
+static unsigned int level;
+static int cts;
+
+void tmu_init()
+{
+       unsigned int mask;
+
+       produce = 0;
+       consume = 0;
+       level = 0;
+       cts = 1;
+
+       CSR_TMU_CTL = 0; /* Ack any pending IRQ */
+
+       mask = irq_getmask();
+       mask |= IRQ_TMU;
+       irq_setmask(mask);
+
+       printf("TMU: texture mapping unit initialized\n");
+}
+
+static void tmu_start(struct tmu_td *td)
+{
+       CSR_TMU_HMESHLAST = td->hmeshlast;
+       CSR_TMU_VMESHLAST = td->vmeshlast;
+       CSR_TMU_BRIGHTNESS = td->brightness;
+       CSR_TMU_CHROMAKEY = td->chromakey;
+       CSR_TMU_SRCMESH = (unsigned int)td->srcmesh;
+       CSR_TMU_SRCFBUF = (unsigned int)td->srcfbuf;
+       CSR_TMU_SRCHRES = td->srchres;
+       CSR_TMU_SRCVRES = td->srcvres;
+       CSR_TMU_DSTMESH = (unsigned int)td->dstmesh;
+       CSR_TMU_DSTFBUF = (unsigned int)td->dstfbuf;
+       CSR_TMU_DSTHRES = td->dsthres;
+       CSR_TMU_DSTVRES = td->dstvres;
+
+       CSR_TMU_CTL = td->flags|TMU_CTL_START;
+       //printf("write %d read %d\n", td->flags|TMU_CTL_START, CSR_TMU_CTL);
+}
+
+void tmu_isr()
+{
+       if(queue[consume]->callback)
+               queue[consume]->callback(queue[consume]);
+       if(queue[consume]->profile) {
+               int pixels, clocks, misses, hits;
+
+               printf("TMU: ====================================================\n");
+               pixels = CSR_TMUP_PIXELS;
+               clocks = CSR_TMUP_CLOCKS;
+               printf("TMU: Drawn pixels:                         %d\n", pixels);
+               printf("TMU: Processing time (clock cycles):       %d\n", clocks);
+               printf("TMU: Fill rate (Mpixels/s):                %d\n", (brd_desc->clk_frequency/1000000)*pixels/clocks);
+               printf("TMU: Frames per second:                    %d\n", brd_desc->clk_frequency/clocks);
+               printf("TMU: Geometry rate (Kvertices/s):          %d\n", (brd_desc->clk_frequency/1000)*((CSR_TMU_HMESHLAST+1)*(CSR_TMU_VMESHLAST+1))/clocks);
+               printf("TMU: At point 1:\n");
+               printf("TMU:   - stalled transactions:             %d\n", CSR_TMUP_STALL1);
+               printf("TMU:   - completed transactions:           %d\n", CSR_TMUP_COMPLETE1);
+               printf("TMU: At point 2:\n");
+               printf("TMU:   - stalled transactions:             %d\n", CSR_TMUP_STALL2);
+               printf("TMU:   - completed transactions:           %d\n", CSR_TMUP_COMPLETE2);
+               printf("TMU: Texel cache:\n");
+               misses = CSR_TMUP_MISSES;
+               hits = pixels-misses;
+               printf("TMU:   - hits:                             %d\n", hits);
+               printf("TMU:   - misses:                           %d\n", misses);
+               printf("TMU:   - hit rate:                         %d%%\n", 100*hits/(hits+misses));
+               printf("TMU: ====================================================\n");
+       }
+       consume = (consume + 1) & TMU_TASKQ_MASK;
+       level--;
+       if(level > 0)
+               tmu_start(queue[consume]); /* IRQ automatically acked */
+       else {
+               cts = 1;
+               CSR_TMU_CTL = 0; /* Ack IRQ */
+       }
+}
+
+int tmu_submit_task(struct tmu_td *td)
+{
+       unsigned int oldmask;
+
+       oldmask = irq_getmask();
+       irq_setmask(oldmask & (~IRQ_TMU));
+
+       if(level >= TMU_TASKQ_SIZE) {
+               irq_setmask(oldmask);
+               printf("TMU: taskq overflow\n");
+               return 0;
+       }
+
+       queue[produce] = td;
+       produce = (produce + 1) & TMU_TASKQ_MASK;
+       level++;
+
+       if(cts) {
+               cts = 0;
+               tmu_start(td);
+       }
+
+       irq_setmask(oldmask);
+
+       return 1;
+}
+
diff --git a/software/libhal/vga.c b/software/libhal/vga.c
new file mode 100644 (file)
index 0000000..97c7189
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <console.h>
+#include <hw/vga.h>
+
+#include <hal/vga.h>
+
+/*
+ * RGB565 framebuffers.
+ * We use page flipping triple buffering as described on
+ * http://en.wikipedia.org/wiki/Triple_buffering
+ *
+ * Buffers must be aligned to the start of an FML burst
+ * which is 4x64 bits, that is, 256 bits, or 32 bytes.
+ */
+static unsigned short int framebufferA[640*480] __attribute__((aligned(32)));
+static unsigned short int framebufferB[640*480] __attribute__((aligned(32)));
+static unsigned short int framebufferC[640*480] __attribute__((aligned(32)));
+
+int vga_hres;
+int vga_vres;
+
+unsigned short int *vga_frontbuffer; /* < buffer currently displayed (or request sent to HW) */
+unsigned short int *vga_backbuffer;  /* < buffer currently drawn to, never read by HW */
+unsigned short int *vga_lastbuffer;  /* < buffer displayed just before (or HW finishing last scan) */
+
+void vga_init()
+{
+       vga_hres = 640;
+       vga_vres = 480;
+       
+       vga_frontbuffer = framebufferA;
+       vga_backbuffer = framebufferB;
+       vga_lastbuffer = framebufferC;
+       
+       CSR_VGA_BASEADDRESS = (unsigned int)vga_frontbuffer;
+
+       /* by default, VGA core puts out 640x480@60Hz */
+       CSR_VGA_RESET = 0;
+
+       printf("VGA: initialized at resolution %dx%d\n", vga_hres, vga_vres);
+       printf("VGA: framebuffers at 0x%08x 0x%08x 0x%08x\n",
+               (unsigned int)&framebufferA, (unsigned int)&framebufferB, (unsigned int)&framebufferC);
+}
+
+void vga_disable()
+{
+       CSR_VGA_RESET = VGA_RESET;
+}
+
+void vga_swap_buffers()
+{
+       unsigned short int *p;
+
+       /*
+        * Make sure last buffer swap has been executed.
+        * Beware, DMA address registers of vgafb are incomplete
+        * (only LSBs are present) so don't compare them directly
+        * with CPU pointers.
+        */
+       while(CSR_VGA_BASEADDRESS_ACT != CSR_VGA_BASEADDRESS);
+
+       p = vga_frontbuffer;
+       vga_frontbuffer = vga_backbuffer;
+       vga_backbuffer = vga_lastbuffer;
+       vga_lastbuffer = p;
+       
+       CSR_VGA_BASEADDRESS = (unsigned int)vga_frontbuffer;
+}
index 52d1eae..a9e301e 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 
-make -C baselib depend
-make -C mathlib depend
+make -C libbase depend
+make -C libmath depend
+make -C libhal depend
 make -C bios depend
 make -C demo depend