diff --git a/poc/avr_iotest/Makefile b/poc/avr_iotest/Makefile new file mode 100644 index 0000000..92ed2b5 --- /dev/null +++ b/poc/avr_iotest/Makefile @@ -0,0 +1,438 @@ +# Hey Emacs, this is a -*- makefile -*- +# +# WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al. +# Released to the Public Domain +# Please read the make user manual! +# +# Additional material for this makefile was submitted by: +# Tim Henigan +# Peter Fleury +# Reiner Patommel +# Sander Pool +# Frederik Rouleau +# Markus Pfaff +# +# On command line: +# +# make all = Make software. +# +# make clean = Clean out built project files. +# +# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB). +# +# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio +# 4.07 or greater). +# +# make program = Download the hex file to the device, using avrdude. Please +# customize the avrdude settings below first! +# +# make filename.s = Just compile filename.c into the assembler code only +# +# To rebuild project do "make clean" then "make all". +# + +# mth 2004/09 +# Differences from WinAVR 20040720 sample: +# - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum) +# - F_OSC Define in CFLAGS and AFLAGS + + +# MCU name +MCU = atmega16 + +# Main Oscillator Frequency +# This is only used to define F_OSC in all assembler and c-sources. +F_OSC = 16000000 + +# Output format. (can be srec, ihex, binary) +FORMAT = ihex + +# Target file name (without extension). +TARGET = main + + +# List C source files here. (C dependencies are automatically generated.) +SRC = $(TARGET).c uart.c + + +# List Assembler source files here. +# Make them always end in a capital .S. Files ending in a lowercase .s +# will not be considered source files but generated files (assembler +# output from the compiler), and will be deleted upon "make clean"! +# Even though the DOS/Win* filesystem matches both .s and .S the same, +# it will preserve the spelling of the filenames, and gcc itself does +# care about how the name is spelled on its command-line. +ASRC = + + + +# Optimization level, can be [0, 1, 2, 3, s]. +# 0 = turn off optimization. s = optimize for size. +# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) +OPT = s + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +#DEBUG = stabs +#DEBUG = dwarf-2 + +# List any extra directories to look for include files here. +# Each directory must be seperated by a space. +EXTRAINCDIRS = + + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 + +# Place -D or -U options here +CDEFS = + +# Place -I options here +CINCS = + + +# Compiler flags. +# -g*: generate debugging information +# -O*: optimization level +# -f...: tuning, see GCC manual and avr-libc documentation +# -Wall...: warning level +# -Wa,...: tell GCC to pass this to the assembler. +# -adhlns...: create assembler listing +CFLAGS = -g$(DEBUG) +CFLAGS += $(CDEFS) $(CINCS) +CFLAGS += -O$(OPT) +CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +CFLAGS += -Wall -Wstrict-prototypes +CFLAGS += -Wa,-adhlns=$(<:.c=.lst) +CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) +CFLAGS += $(CSTANDARD) +CFLAGS += -DF_OSC=$(F_OSC) +CFLAGS += -DF_CPU=16000000UL +#CFLAGS += -DF_CPU=3686400UL + + +# Assembler flags. +# -Wa,...: tell GCC to pass this to the assembler. +# -ahlms: create listing +# -gstabs: have the assembler create line number information; note that +# for use in COFF files, additional information about filenames +# and function names needs to be present in the assembler source +# files -- see avr-libc docs [FIXME: not yet described there] +ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs +ASFLAGS += -DF_OSC=$(F_OSC) + + +#Additional libraries. + +# Minimalistic printf version +PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min + +# Floating point printf version (requires MATH_LIB = -lm below) +PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt + +PRINTF_LIB = + +# Minimalistic scanf version +SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min + +# Floating point + %[ scanf version (requires MATH_LIB = -lm below) +SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt + +SCANF_LIB = + +MATH_LIB = -lm + +# External memory options + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# used for variables (.data/.bss) and heap (malloc()). +#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# only used for heap (malloc()). +#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff + +EXTMEMOPTS = + +# Linker flags. +# -Wl,...: tell GCC to pass this to linker. +# -Map: create map file +# --cref: add cross reference to map file +LDFLAGS = -Wl,-Map=$(TARGET).map,--cref +LDFLAGS += $(EXTMEMOPTS) +LDFLAGS += $(PRINTF_LIB_MIN) $(SCANF_LIB) $(MATH_LIB) + + + + +# Programming support using avrdude. Settings and variables. + +# Programming hardware: alf avr910 avrisp bascom bsd +# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 +# +# Type: avrdude -c ? +# to get a full listing. +# +AVRDUDE_PROGRAMMER = stk500v2 + +# com1 = serial port. Use lpt1 to connect to parallel port. + +AVRDUDE_PORT = /dev/tty.PL2303-00002126 + +AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex + +# Uncomment the following if you want avrdude's erase cycle counter. +# Note that this counter needs to be initialized first using -Yn, +# see avrdude manual. +#AVRDUDE_ERASE_COUNTER = -y + +# Uncomment the following if you do /not/ wish a verification to be +# performed after programming the device. +AVRDUDE_NO_VERIFY = -V + +# Increase verbosity level. Please use this when submitting bug +# reports about avrdude. See +# to submit bug reports. +AVRDUDE_VERBOSE = -v -v + +AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) +AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) +AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) +AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) + +#flash_fuse: +# avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U lfuse:w:0xfe:m +# avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U hfuse:w:0xd9:m + + +# --------------------------------------------------------------------------- + +# Define directories, if needed. +DIRAVR = c:/winavr +DIRAVRBIN = $(DIRAVR)/bin +DIRAVRUTILS = $(DIRAVR)/utils/bin +DIRINC = . +DIRLIB = $(DIRAVR)/avr/lib + + +# Define programs and commands. +SHELL = sh +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +COPY = cp + + + + +# Define Messages +# English +MSG_ERRORS_NONE = Errors: none +MSG_BEGIN = -------- begin -------- +MSG_END = -------- end -------- +MSG_SIZE_BEFORE = Size before: +MSG_SIZE_AFTER = Size after: +MSG_COFF = Converting to AVR COFF: +MSG_EXTENDED_COFF = Converting to AVR Extended COFF: +MSG_FLASH = Creating load file for Flash: +MSG_EEPROM = Creating load file for EEPROM: +MSG_EXTENDED_LISTING = Creating Extended Listing: +MSG_SYMBOL_TABLE = Creating Symbol Table: +MSG_LINKING = Linking: +MSG_COMPILING = Compiling: +MSG_ASSEMBLING = Assembling: +MSG_CLEANING = Cleaning project: + + + + +# Define all object files. +OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) + + +# Compiler flags to generate dependency files. +### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d +GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + + + + +# Default target. +all: begin gccversion sizebefore build sizeafter finished end + +build: elf hex eep lss sym + +elf: $(TARGET).elf +hex: $(TARGET).hex +eep: $(TARGET).eep +lss: $(TARGET).lss +sym: $(TARGET).sym + + + +# Eye candy. +# AVR Studio 3.x does not check make's exit code but relies on +# the following magic strings to be generated by the compile job. +begin: + @echo + @echo $(MSG_BEGIN) + +finished: + @echo $(MSG_ERRORS_NONE) + +end: + @echo $(MSG_END) + @echo + + +# Display size of file. +HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex +ELFSIZE = $(SIZE) -A $(TARGET).elf +sizebefore: + @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi + +sizeafter: + @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi + + + +# Display compiler version information. +gccversion : + @$(CC) --version + + + +# Program the device. + + +flash: $(TARGET).hex $(TARGET).eep + sudo $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: $(TARGET).elf + @echo + @echo $(MSG_COFF) $(TARGET).cof + $(COFFCONVERT) -O coff-avr $< $(TARGET).cof + + +extcoff: $(TARGET).elf + @echo + @echo $(MSG_EXTENDED_COFF) $(TARGET).cof + $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof + + + +# Create final output files (.hex, .eep) from ELF output file. +%.hex: %.elf + @echo + @echo $(MSG_FLASH) $@ + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +%.eep: %.elf + @echo + @echo $(MSG_EEPROM) $@ + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +%.lss: %.elf + @echo + @echo $(MSG_EXTENDED_LISTING) $@ + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +%.sym: %.elf + @echo + @echo $(MSG_SYMBOL_TABLE) $@ + $(NM) -n $< > $@ + + + +# Link: create ELF output file from object files. +.SECONDARY : $(TARGET).elf +.PRECIOUS : $(OBJ) +%.elf: $(OBJ) + @echo + @echo $(MSG_LINKING) $@ + $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) + + +# Compile: create object files from C source files. +%.o : %.c + @echo + @echo $(MSG_COMPILING) $< + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +%.s : %.c + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +%.o : %.S + @echo + @echo $(MSG_ASSEMBLING) $< + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +# Target: clean project. +clean: begin clean_list finished end + +clean_list : + @echo + @echo $(MSG_CLEANING) + $(REMOVE) $(TARGET).hex + $(REMOVE) $(TARGET).eep + $(REMOVE) $(TARGET).obj + $(REMOVE) $(TARGET).cof + $(REMOVE) $(TARGET).elf + $(REMOVE) $(TARGET).map + $(REMOVE) $(TARGET).obj + $(REMOVE) $(TARGET).a90 + $(REMOVE) $(TARGET).sym + $(REMOVE) $(TARGET).lnk + $(REMOVE) $(TARGET).lss + $(REMOVE) $(OBJ) + $(REMOVE) $(LST) + $(REMOVE) $(SRC:.c=.s) + $(REMOVE) $(SRC:.c=.d) + $(REMOVE) .dep/* + + + +# Include the dependency files. +-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) + + +# Listing of phony targets. +.PHONY : all begin finish end sizebefore sizeafter gccversion \ +build elf hex eep lss sym coff extcoff \ +clean clean_list program + diff --git a/poc/avr_iotest/checksize b/poc/avr_iotest/checksize new file mode 100644 index 0000000..5ca1c32 --- /dev/null +++ b/poc/avr_iotest/checksize @@ -0,0 +1,35 @@ +#!/bin/sh +# Name: checksize +# Project: PowerSwitch/AVR-USB +# Author: Christian Starkjohann +# Creation Date: 2004-12-29 +# Tabsize: 4 +# Copyright: (c) 2005 OBJECTIVE DEVELOPMENT Software GmbH. +# Revision: $Id: checksize 83 2006-01-05 22:20:53Z cs $ + +error=0 +codelimit=2048 # default value +datalimit=96 # default value; leave 32 bytes for stack + +if [ $# -gt 1 ]; then + codelimit="$2" +fi +if [ $# -gt 2 ]; then + datalimit="$3" +fi + +set -- `avr-size -d "$1" | awk '/[0-9]/ {print $1 + $2, $2 + $3, $2}'` +if [ $1 -gt $codelimit ]; then + echo "*** code size $1 exceeds limit of $codelimit" + error=1 +else + echo "ROM: $1 bytes (data=$3)" +fi +if [ $2 -gt $datalimit ]; then + echo "*** data size $2 exceeds limit of $datalimit" + error=1 +else + echo "RAM: $2 bytes" +fi + +exit $error diff --git a/poc/avr_iotest/fifo.c b/poc/avr_iotest/fifo.c new file mode 100644 index 0000000..c06e7b4 --- /dev/null +++ b/poc/avr_iotest/fifo.c @@ -0,0 +1,28 @@ +#include "fifo.h" + +void fifo_init(fifo_t * f, uint8_t * buffer, const uint8_t size) +{ + f->count = 0; + f->pread = f->pwrite = buffer; + f->read2end = f->write2end = f->size = size; +} + +uint8_t fifo_put(fifo_t * f, const uint8_t data) +{ + return _inline_fifo_put(f, data); +} + +uint8_t fifo_get_wait(fifo_t * f) +{ + while (!f->count); + + return _inline_fifo_get(f); +} + +int fifo_get_nowait(fifo_t * f) +{ + if (!f->count) + return -1; + + return (int) _inline_fifo_get(f); +} diff --git a/poc/avr_iotest/fifo.h b/poc/avr_iotest/fifo.h new file mode 100644 index 0000000..bcf9aad --- /dev/null +++ b/poc/avr_iotest/fifo.h @@ -0,0 +1,69 @@ +#ifndef _FIFO_H_ +#define _FIFO_H_ + +#include +#include + +typedef struct { + uint8_t volatile count; // # Zeichen im Puffer + uint8_t size; // Puffer-Größe + uint8_t *pread; // Lesezeiger + uint8_t *pwrite; // Schreibzeiger + uint8_t read2end, write2end; // # Zeichen bis zum Überlauf Lese-/Schreibzeiger +} fifo_t; + +extern void fifo_init(fifo_t *, uint8_t * buf, const uint8_t size); +extern uint8_t fifo_put(fifo_t *, const uint8_t data); +extern uint8_t fifo_get_wait(fifo_t *); +extern int fifo_get_nowait(fifo_t *); + +static inline uint8_t _inline_fifo_put(fifo_t * f, const uint8_t data) +{ + if (f->count >= f->size) + return 0; + + uint8_t *pwrite = f->pwrite; + + *(pwrite++) = data; + + uint8_t write2end = f->write2end; + + if (--write2end == 0) { + write2end = f->size; + pwrite -= write2end; + } + + f->write2end = write2end; + f->pwrite = pwrite; + + uint8_t sreg = SREG; + cli(); + f->count++; + SREG = sreg; + + return 1; +} + +static inline uint8_t _inline_fifo_get(fifo_t * f) +{ + uint8_t *pread = f->pread; + uint8_t data = *(pread++); + uint8_t read2end = f->read2end; + + if (--read2end == 0) { + read2end = f->size; + pread -= read2end; + } + + f->pread = pread; + f->read2end = read2end; + + uint8_t sreg = SREG; + cli(); + f->count--; + SREG = sreg; + + return data; +} + +#endif /* _FIFO_H_ */ diff --git a/poc/avr_iotest/main.c b/poc/avr_iotest/main.c new file mode 100644 index 0000000..fb7eb57 --- /dev/null +++ b/poc/avr_iotest/main.c @@ -0,0 +1,35 @@ + +#include +#include +#include + +#include "uart.h" +extern FILE uart_stdout; + +int main(void) +{ + + uart_init(); + stdout = &uart_stdout; + printf("Init done\n"); + + DDRD |= (1 << PD7); + + while(1){ + + /* + PORTD |= (1 << PD7); + PORTD &= ~(1 << PD7); + */ + PORTD ^= (1 << PD7); + + } + + return 0 ; + +} + + + + + diff --git a/poc/avr_iotest/uart.c b/poc/avr_iotest/uart.c new file mode 100644 index 0000000..22aa618 --- /dev/null +++ b/poc/avr_iotest/uart.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include "uart.h" +#include "fifo.h" + +volatile struct +{ + uint8_t tmr_int: 1; + uint8_t adc_int: 1; + uint8_t rx_int: 1; +} +intflags; + +/* + * * Last character read from the UART. + * + */ +volatile char rxbuff; + + +FILE uart_stdout = FDEV_SETUP_STREAM(uart_stream, NULL, _FDEV_SETUP_WRITE); + +void uart_init(void) +{ + UCSRA = _BV(U2X); /* improves baud rate error @ F_CPU = 1 MHz */ + UCSRB = _BV(TXEN)|_BV(RXEN)|_BV(RXCIE); /* tx/rx enable, rx complete intr */ + UBRRL = (F_CPU / (8 * 115200UL)) - 1; /* 9600 Bd */ + +} + + +ISR(USART_RXC_vect) +{ + uint8_t c; + c = UDR; + if (bit_is_clear(UCSRA, FE)){ + rxbuff = c; + intflags.rx_int = 1; + } +} + + +void uart_putc(uint8_t c) +{ + loop_until_bit_is_set(UCSRA, UDRE); + UDR = c; +} + + +void uart_puts(const char *s) +{ + do { + uart_putc(*s); + } + while (*s++); +} + +void uart_puts_P(PGM_P s) +{ + while (1) { + unsigned char c = pgm_read_byte(s); + s++; + if ('\0' == c) + break; + uart_putc(c); + } +} + +static int uart_stream(char c, FILE *stream) +{ + if (c == '\n') + uart_putc('\r'); + loop_until_bit_is_set(UCSRA, UDRE); + UDR = c; + return 0; +} + diff --git a/poc/avr_iotest/uart.h b/poc/avr_iotest/uart.h new file mode 100644 index 0000000..7af251f --- /dev/null +++ b/poc/avr_iotest/uart.h @@ -0,0 +1,18 @@ +#ifndef _UART_H_ +#define _UART_H_ + +#define CR "\r\n" + + +#include +#include +#include + +void uart_init(void); +void uart_putc(const uint8_t); +void uart_puts(const char *s); +void uart_puts_P(PGM_P s); +static int uart_stream(char c, FILE *stream); + + +#endif /* _UART_H_ */ diff --git a/poc/avr_sdcard/Makefile b/poc/avr_sdcard/Makefile index db636c7..ef1d310 100644 --- a/poc/avr_sdcard/Makefile +++ b/poc/avr_sdcard/Makefile @@ -182,7 +182,7 @@ AVRDUDE_PROGRAMMER = stk500v2 # com1 = serial port. Use lpt1 to connect to parallel port. -AVRDUDE_PORT =/dev/tty.PL2303-00001124 +AVRDUDE_PORT = /dev/tty.PL2303-00002126 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex diff --git a/poc/avr_sdcard/main.c b/poc/avr_sdcard/main.c index 5fefee5..8a55f06 100644 --- a/poc/avr_sdcard/main.c +++ b/poc/avr_sdcard/main.c @@ -58,14 +58,15 @@ extern FILE uart_stdout; //#define FILENAME "vram2.smc" //ok //#define FILENAME "super02.smc" //ok //#define FILENAME "super01.smc"//ok -//#define FILENAME "crc.smc" //ok +#define FILENAME "crc.smc" //ok //#define FILENAME "banks.smc" //ok //#define FILENAME "hungry.smc" //ok //#define FILENAME "arkanoid.smc"//ok //#define FILENAME "eric.smc" -#define FILENAME "turrican.smc" +//#define FILENAME "super01.smc" -#define ROMSIZE 4 +#define ROMSIZE 2 // 4 == 4mbit == 512kb + // 2 == 2mbit == 256kb #define DUMPNAME "dump256.smc" #define BUFFER_SIZE 512 #define BLOCKS (ROMSIZE << 8) @@ -213,20 +214,29 @@ void sram_write(uint32_t addr, uint8_t data) { RAM_DIR = 0xff; - CTRL_PORT |= (1<>16)); spi_master_transmit((uint8_t)(addr>>8)); spi_master_transmit((uint8_t)(addr>>0)); + /* passthru address in sreg */ LATCH_PORT |= (1<> 16) & 0xff; - usb_control_msg(handle, + cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, USB_UPLOAD_ADDR, addr_hi, addr_lo, (char *) read_buffer + step, SEND_BUFFER_SIZE, 5000); + + if (cnt < 0) { + fprintf(stderr, "USB error: %s\n", usb_strerror()); + exit(-1); + } #if 0 dump_packet(addr, SEND_BUFFER_SIZE, read_buffer + step); #endif diff --git a/poc/avr_usbload/main.c b/poc/avr_usbload/main.c index 43f11ef..4601aa6 100644 --- a/poc/avr_usbload/main.c +++ b/poc/avr_usbload/main.c @@ -179,7 +179,7 @@ uint8_t usbFunctionRead(uint8_t * data, uint8_t len) int main(void) { uint8_t i; - wdt_enable(WDTO_1S); + //wdt_enable(WDTO_1S); uart_init(); stdout = &uart_stdout; sram_init(); diff --git a/poc/avr_usbload/uart.c b/poc/avr_usbload/uart.c index 3fe037d..dd916da 100644 --- a/poc/avr_usbload/uart.c +++ b/poc/avr_usbload/uart.c @@ -27,6 +27,7 @@ void uart_init(void) * intr */ UBRRL = (F_CPU / (8 * 115200UL)) - 1; /* 9600 Bd */ + } diff --git a/snes/fatfstest/Makefile b/snes/fatfstest/Makefile index bdcff1b..a780900 100644 --- a/snes/fatfstest/Makefile +++ b/snes/fatfstest/Makefile @@ -24,7 +24,10 @@ LD=$(WINE) $(SDK)/bin/WDCLN.exe # Project INC=$(SDK)/include -LIBS=$(SDK)/lib/cc +LIBS=-L$(SDK)/lib/cc +#-L$(SDK)/lib/c134 + + OBJS=StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj diskio.obj ff.obj APP=fatfs.smc GFX=debugfont @@ -62,7 +65,7 @@ $(APP): $(OBJS) -Avectors=FFE4,7FE4 \ -Aregistration_data=FFB0,7FB0 \ -Aressource=18000,8000 \ - -N $(OBJS) -L$(LIBS) -O $@ + -N $(OBJS) $(LIBS) -O $@ ucon64 -snes -chk $(APP) clean: diff --git a/snes/fatfstest/debug.c b/snes/fatfstest/debug.c index 96de0e0..38f53f7 100644 --- a/snes/fatfstest/debug.c +++ b/snes/fatfstest/debug.c @@ -1,20 +1,33 @@ #include +#include +#include + #include "data.h" #include "pad.h" #include "PPU.h" #include "ressource.h" word debugMap[0x400]; - +static char debug_buffer[255]; +char hex_chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; void debug_init(void) { word i; for(i=0; i<0x400; i++) { debugMap[i] = 0x00; } + memset(debug_buffer,0,255); +} + +void debug_enable(void){ + VRAMLoad((word) debugFont_pic, 0x5000, 2048); + CGRAMLoad((word) debugFont_pal, (byte) 0x00, (word) 16); + VRAMLoad((word) debugMap, 0x4000, 0x0800); + setTileMapLocation(0x4000, (byte) 0x00, (byte) 0); + setCharacterLocation(0x5000, (byte) 0); + *(byte*) 0x2100 = 0x0f; // enable background } -char hex_chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; void int2hex(unsigned long number, char *buf,word size) { @@ -30,6 +43,8 @@ void int2hex(unsigned long number, char *buf,word size) } + + void print_screen(char *buffer,word y){ char i; char l; @@ -43,16 +58,55 @@ void print_screen(char *buffer,word y){ } } + + void print_console(char *buffer){ while(*buffer) *(byte*) 0x3000=*buffer++; } -void debug_enable(void){ - VRAMLoad((word) debugFont_pic, 0x5000, 2048); - CGRAMLoad((word) debugFont_pal, (byte) 0x00, (word) 16); - VRAMLoad((word) debugMap, 0x4000, 0x0800); - setTileMapLocation(0x4000, (byte) 0x00, (byte) 0); - setCharacterLocation(0x5000, (byte) 0); - *(byte*) 0x2100 = 0x0f; // enable background -} \ No newline at end of file + +void printfc(char *fmt, ...){ + va_list arg; + va_start(arg,fmt); + vsprintf(debug_buffer,fmt,arg); + print_console(debug_buffer); +} + + +/* keep the linker happy */ +int open(const char * _name, int _mode){ + print_console("open called\n"); + return -1; +} + +int close(int fd){ + print_console("close called\n"); + return -1; + +} + +size_t read(int fd, void * buff, size_t len){ + print_console("read called\n"); + return 0; +} + +size_t write(int fd, void * buffer, size_t len){ + print_console("write called\n"); + return 0; +} + +long lseek(int fd, long off, int count){ + print_console("lseek called\n"); + return 0; +} + +int unlink(const char * name){ + print_console("unlink called\n"); + return -1; +} + +int isatty(){ + print_console("isatty called\n"); + return 1; +} diff --git a/snes/fatfstest/diskio.c b/snes/fatfstest/diskio.c index e0e189f..012462f 100644 --- a/snes/fatfstest/diskio.c +++ b/snes/fatfstest/diskio.c @@ -3,8 +3,9 @@ #include "diskio.h" #include "config.h" #include "data.h" +#include "debug.h" -static +volatile static DSTATUS Stat = STA_NOINIT; /* Disk status */ @@ -38,6 +39,7 @@ BYTE *image_addr; DSTATUS disk_initialize (BYTE drv) { byte retval; + print_console("disk_initialize\n"); if (drv) return STA_NOINIT; /* Supports only single drive */ @@ -46,7 +48,8 @@ DSTATUS disk_initialize (BYTE drv) { *(byte*) MMIO_CMD = CMD_INIT; while(*(byte*) MMIO_RETVAL == STA_VOID); retval = *(byte*) MMIO_RETVAL; - Stat &= ~retval; /* When device goes ready, clear STA_NOINIT */ + Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */ + print_console("disk_initialize done\n"); return Stat; } @@ -76,11 +79,12 @@ DRESULT disk_read ( INT size; byte retval; word i; - for (i=0;i<(count*512);i++) - *(byte*)(SHARED_ADDR+i) = buff[i]; - if (drv || !count) return RES_PARERR; + print_console("disk_read enter\n"); + //if (drv || !count) return RES_PARERR; + print_console("drv ok\n"); if (Stat & STA_NOINIT) return RES_NOTRDY; + print_console("sta ok\n"); *(byte*) MMIO_RETVAL = STA_VOID; *(byte*) MMIO_CMD = CMD_READ; @@ -95,6 +99,9 @@ DRESULT disk_read ( while(*(byte*) MMIO_RETVAL == STA_VOID); retval = *(byte*) MMIO_RETVAL; + print_console("copy buffer\n"); + for (i=0;i<(count*512);i++) + *(byte*)(SHARED_ADDR+i) = buff[i]; return retval; } diff --git a/snes/fatfstest/ff.h b/snes/fatfstest/ff.h index 3381a2f..57786c9 100644 --- a/snes/fatfstest/ff.h +++ b/snes/fatfstest/ff.h @@ -38,7 +38,7 @@ / performance and code efficiency. */ -#define _FS_READONLY 1 +#define _FS_READONLY 0 /* Setting _FS_READONLY to 1 defines read only configuration. This removes / writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename, / f_truncate and useless f_getfree. */ diff --git a/snes/fatfstest/main.c b/snes/fatfstest/main.c index 0d66614..a49025b 100644 --- a/snes/fatfstest/main.c +++ b/snes/fatfstest/main.c @@ -5,12 +5,29 @@ #include "ressource.h"; #include "PPU.h" #include "debug.h" +#include "ff.h" #include +#include +#include padStatus pad1; + +WORD acc_size; /* Work register for fs command */ +WORD acc_files, acc_dirs; +FILINFO finfo; + +FATFS fatfs[2]; /* File system object for each logical drive */ +BYTE buff[512]; /* Working buffer */ + +FATFS *fs; +DIR dir; /* Directory object */ +FIL file1, file2; /* File object */ +DWORD p1, p2, p3; + + void initInternalRegisters(void) { characterLocation[0] = 0x0000; characterLocation[1] = 0x0000; @@ -24,14 +41,73 @@ void preInit(void) { // Insert code here to be executed before register init } +DWORD get_fattime () +{ + time_t rawtime; + struct tm * ptm; + //time ( &rawtime ); + ptm = gmtime ( &rawtime ); + + return ((DWORD)(ptm->tm_year - 80) << 25) + | ((DWORD)(ptm->tm_mon +1) << 21) + | ((DWORD)ptm->tm_mday << 16) + | ((DWORD)ptm->tm_hour << 11) + | ((DWORD)ptm->tm_min << 5) + | ((DWORD)ptm->tm_sec >> 1); +} + + +static +FRESULT scan_files (char* path) +{ + DIR dirs; + FRESULT res; + int i; + + if ((res = f_opendir(&dirs, path)) == FR_OK) { + i = strlen(path); + //printf("Ok\n"); + while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) { + if (finfo.fattrib & AM_DIR) { + acc_dirs++; + *(path+i) = '/'; strcpy(path+i+1, &finfo.fname[0]); + res = scan_files(path); + *(path+i) = '\0'; + if (res != FR_OK) break; + } else { + acc_files++; + acc_size += finfo.fsize; + } + } + } + print_console("scan_files ret\n"); + return res; +} + + +void put_rc (FRESULT rc) +{ + char *p; + static char str[] = + "OK\0" "NOT_READY\0" "NO_FILE\0" "FR_NO_PATH\0" "INVALID_NAME\0" "INVALID_DRIVE\0" + "DENIED\0" "EXIST\0" "RW_ERROR\0" "WRITE_PROTECTED\0" "NOT_ENABLED\0" + "NO_FILESYSTEM\0" "INVALID_OBJECT\0" "MKFS_ABORTED\0"; + FRESULT i; + + for (p = str, i = 0; i != rc && *p; i++) { + while(*p++); + } + print_console(p); +} + +void halt(void) { + while(1); + +} void main(void) { word i,j; - word crc01; - word crc02; - padStatus pad1; - char line_header[32] = "OK2"; + BYTE res; initInternalRegisters(); - *(byte*) 0x2105 = 0x01; // MODE 1 value *(byte*) 0x212c = 0x01; // Plane 0 (bit one) enable register *(byte*) 0x212d = 0x00; // All subPlane disable @@ -39,9 +115,45 @@ void main(void) { debug_enable(); print_screen("FATFS TEST",0); - print_console("Debugging console test\n"); - print_console("test me\n"); + print_console("mount "); + + put_rc(f_mount(0, &fatfs[0])); + + print_console("disk_initialize \n"); + disk_initialize(0); + print_console("disk_read \n"); + disk_read(0,buff,0xaabb,1); + print_console("disk_done \n"); + + halt(); + + res = f_getfree("/", &p2, &fs); + if (res) { + put_rc(res); + } + /* + printf("FAT type = %u\nBytes/Cluster = %lu\nNumber of FATs = %u\n" + "Root DIR entries = %u\nSectors/FAT = %lu\nNumber of clusters = %lu\n" + "FAT start (lba) = %lu\nDIR start (lba,clustor) = %lu\nData start (lba) = %lu\n", + (WORD)fs->fs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats, + fs->n_rootdir, (DWORD)fs->sects_fat, (DWORD)fs->max_clust - 2, + fs->fatbase, fs->dirbase, fs->database + ); + */ + acc_size = acc_files = acc_dirs = 0; + res = scan_files("/"); + if (res) { + put_rc(res); + } + /* + printf("%u files, %lu bytes.\n%u folders.\n" + "%lu KB total disk space.\n%lu KB available.\n", + acc_files, acc_size, acc_dirs, + (fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2) + ); + */ + while(1){ while(!pad1.start) { waitForVBlank(); diff --git a/snesram.tmproj b/snesram.tmproj index 4186f87..26e913b 100644 --- a/snesram.tmproj +++ b/snesram.tmproj @@ -2,6 +2,8 @@ + currentDocument + snes/fatfstest/diskio.c documents @@ -75,6 +77,146 @@ firstVisibleLine 211 + snes/fatfstest/data.h + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + snes/fatfstest/debug.c + + caret + + column + 0 + line + 71 + + firstVisibleColumn + 0 + firstVisibleLine + 43 + + snes/fatfstest/debug.h + + caret + + column + 19 + line + 4 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + snes/fatfstest/diskio.c + + caret + + column + 9 + line + 7 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + snes/fatfstest/diskio.h + + caret + + column + 28 + line + 50 + + firstVisibleColumn + 0 + firstVisibleLine + 3 + + snes/fatfstest/event.c + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + snes/fatfstest/ff.c + + caret + + column + 0 + line + 169 + + firstVisibleColumn + 0 + firstVisibleLine + 136 + + snes/fatfstest/ff.h + + caret + + column + 22 + line + 40 + + firstVisibleColumn + 0 + firstVisibleLine + 49 + + snes/fatfstest/main.c + + caret + + column + 0 + line + 114 + + firstVisibleColumn + 0 + firstVisibleLine + 98 + + snes/fatfstest/pad.h + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + tools/bsnes/cart/cart.cpp caret @@ -103,6 +245,118 @@ firstVisibleLine 24 + tools/bsnes/chip/cmmio/cmmio.cpp + + caret + + column + 14 + line + 34 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + tools/bsnes/chip/cmmio/cmmio.hpp + + caret + + column + 0 + line + 16 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + tools/bsnes/chip/fatfs/config.h + + caret + + column + 0 + line + 1 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + tools/bsnes/chip/fatfs/diskio.cpp + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 89 + + tools/bsnes/chip/fatfs/diskio.h + + caret + + column + 28 + line + 50 + + firstVisibleColumn + 0 + firstVisibleLine + 11 + + tools/bsnes/chip/fatfs/fatfs.cpp + + caret + + column + 23 + line + 69 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + tools/bsnes/chip/fatfs/fatfs.hpp + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + tools/bsnes/chip/fatfs/integer.h + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + tools/bsnes/cpu/scpu/memory/memory.hpp caret @@ -117,10 +371,139 @@ firstVisibleLine 0 + tools/ffsample/linux/diskio.c + + caret + + column + 0 + line + 141 + + firstVisibleColumn + 0 + firstVisibleLine + 115 + + tools/ffsample/linux/main.c + + caret + + column + 0 + line + 63 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 149 + selectFrom + + column + 0 + line + 52 + + selectTo + + column + 0 + line + 63 + + + tools/wdcheader/TIME.H + + caret + + column + 13 + line + 103 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 71 + selectFrom + + column + 12 + line + 103 + + selectTo + + column + 18 + line + 103 + + + tools/wdcheader/WCHAR.H + + caret + + column + 0 + line + 76 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 0 + selectFrom + + column + 74 + line + 76 + + selectTo + + column + 0 + line + 76 + + + openDocuments + + snes/fatfstest/debug.c + tools/bsnes/chip/cmmio/cmmio.hpp + tools/bsnes/chip/cmmio/cmmio.cpp + snes/fatfstest/ff.h + snes/fatfstest/ff.c + tools/ffsample/linux/main.c + snes/fatfstest/pad.h + snes/fatfstest/event.c + snes/fatfstest/main.c + tools/wdcheader/TIME.H + tools/wdcheader/WCHAR.H + snes/fatfstest/debug.h + tools/ffsample/linux/diskio.c + snes/fatfstest/data.h + tools/bsnes/chip/fatfs/fatfs.cpp + snes/fatfstest/diskio.c + snes/fatfstest/diskio.h + tools/bsnes/chip/fatfs/config.h + tools/bsnes/chip/fatfs/diskio.cpp + tools/bsnes/chip/fatfs/diskio.h + tools/bsnes/chip/fatfs/integer.h + tools/bsnes/chip/fatfs/fatfs.hpp + showFileHierarchyDrawer windowFrame - {{0, 51}, {1110, 827}} + {{0, 55}, {1110, 823}} diff --git a/tools/bsnes/chip/fatfs/fatfs.cpp b/tools/bsnes/chip/fatfs/fatfs.cpp index 89155f3..553ab33 100644 --- a/tools/bsnes/chip/fatfs/fatfs.cpp +++ b/tools/bsnes/chip/fatfs/fatfs.cpp @@ -67,7 +67,7 @@ void FATFS::mmio_write(unsigned addr, uint8 data) { case CMD_INIT: printf("FATFS::mmio_write CMD_INIT \n"); command = CMD_INIT; - disk_initialize(0); + retval = disk_initialize(0); break; case CMD_READ: printf("FATFS::mmio_write CMD_READ \n");