First version

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@60 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Björn Stenberg 2002-03-28 15:09:10 +00:00
parent cd0f122071
commit d9eb5c7603
15 changed files with 3119 additions and 0 deletions

47
firmware/Makefile Normal file
View file

@ -0,0 +1,47 @@
# __________ __ ___.
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
# \/ \/ \/ \/ \/
# $Id$
#
HPATH = /usr/local/sh-gcc/bin
CC = $(HPATH)/sh-elf-gcc
LD = $(HPATH)/sh-elf-ld
AR = $(HPATH)/sh-elf-ar
AS = $(HPATH)/sh-elf-as
OC = $(HPATH)/sh-elf-objcopy
INCLUDES=-I.
CFLAGS = -Os -Wall -m1 -nostdlib -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns $(INCLUDES)
AFLAGS += -small -relax
SRC := $(wildcard *.c)
OBJS := $(SRC:%.c=%.o)
%.o: %.s
$(CC) -o $@ $(CFLAGS) $(INCLUDES) $(DEFS) -c $<
all : $(OBJS) # archos.mod # archos.asm
archos.elf : $(OBJS) app.lds
$(CC) -nostdlib -o archos.elf $(OBJS) -lgcc -Tapp.lds -Wl,-Map,archos.map
archos.bin : archos.elf
$(OC) -O binary archos.elf archos.bin
archos.asm: archos.bin
sh2d -sh1 archos.bin > archos.asm
archos.mod : archos.bin
scramble archos.bin archos.mod
dist:
tar czvf dist.tar.gz Makefile main.c start.s app.lds
clean:
-rm -f *.x *.i *.o *.elf *.bin *.map *.mod *.bak *~

23
firmware/app.lds Normal file
View file

@ -0,0 +1,23 @@
ENTRY(_start)
OUTPUT_FORMAT(elf32-sh)
SECTIONS
{
.vectors 0x09000000 :
{
*(.vectors);
. = ALIGN(0x200);
*(.text.start)
*(.text)
*(.rodata)
}
.bss :
{
_stack = . + 0x1000;
}
.pad 0x0900C800 :
{
LONG(0);
}
}

1315
firmware/fat.c Normal file

File diff suppressed because it is too large Load diff

154
firmware/fat.h Normal file
View file

@ -0,0 +1,154 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Linus Nielsen Feltzing
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef FAT_H
#define FAT_H
#define FATTYPE_FAT12 0
#define FATTYPE_FAT16 1
#define FATTYPE_FAT32 2
#define BS_JMPBOOT 0
#define BS_OEMNAME 3
#define BPB_BYTSPERSEC 11
#define BPB_SECPERCLUS 13
#define BPB_RSVDSECCNT 14
#define BPB_NUMFATS 16
#define BPB_ROOTENTCNT 17
#define BPB_TOTSEC16 19
#define BPB_MEDIA 21
#define BPB_FATSZ16 22
#define BPB_SECPERTRK 24
#define BPB_NUMHEADS 26
#define BPB_HIDDSEC 28
#define BPB_TOTSEC32 32
#define BS_DRVNUM 36
#define BS_RESERVED1 37
#define BS_BOOTSIG 38
#define BS_VOLID 39
#define BS_VOLLAB 43
#define BS_FILSYSTYPE 54
#define BPB_FATSZ32 36
#define BPB_LAST_WORD 510
#define MIN(a,b) (((a) < (b))?(a):(b)))
struct bpb
{
char bs_oemname[9]; /* OEM string, ending with \0 */
int bpb_bytspersec; /* Bytes per sectory, typically 512 */
int bpb_secperclus; /* Sectors per cluster */
int bpb_rsvdseccnt; /* Number of reserved sectors */
int bpb_numfats; /* Number of FAT structures, typically 2 */
int bpb_rootentcnt; /* Number of dir entries in the root */
int bpb_totsec16; /* Number of sectors on the volume (old 16-bit) */
int bpb_media; /* Media type (typically 0xf0 or 0xf8) */
int bpb_fatsz16; /* Number of used sectors per FAT structure */
int bpb_secpertrk; /* Number of sectors per track */
int bpb_numheads; /* Number of heads */
int bpb_hiddsec; /* Hidden sectors before the volume */
unsigned int bpb_totsec32; /* Number of sectors on the volume
(new 32-bit) */
/**** FAT12/16 specific *****/
int bs_drvnum; /* Drive number */
int bs_bootsig; /* Is 0x29 if the following 3 fields are valid */
unsigned int bs_volid; /* Volume ID */
char bs_vollab[12]; /* Volume label, 11 chars plus \0 */
char bs_filsystype[9]; /* File system type, 8 chars plus \0 */
/**** FAT32 specific *****/
int bpb_fatsz32;
int last_word; /* Must be 0xaa55 */
int fat_type; /* What type of FAT is this? */
};
#define FAT_ATTR_READ_ONLY 0x01
#define FAT_ATTR_HIDDEN 0x02
#define FAT_ATTR_SYSTEM 0x04
#define FAT_ATTR_VOLUME_ID 0x08
#define FAT_ATTR_DIRECTORY 0x10
#define FAT_ATTR_ARCHIVE 0x20
#define FAT_ATTR_LONG_NAME (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | \
FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID)
#define FATDIR_NAME 0
#define FATDIR_ATTR 11
#define FATDIR_NTRES 12
#define FATDIR_CRTTIMETENTH 13
#define FATDIR_CRTTIME 14
#define FATDIR_CRTDATE 16
#define FATDIR_LSTACCDATE 18
#define FATDIR_FSTCLUSHI 20
#define FATDIR_WRTTIME 22
#define FATDIR_WRTDATE 24
#define FATDIR_FSTCLUSLO 26
#define FATDIR_FILESIZE 28
struct fat_direntry
{
unsigned char name[12]; /* Name plus \0 */
unsigned short attr; /* Attributes */
unsigned char crttimetenth; /* Millisecond creation
time stamp (0-199) */
unsigned short crttime; /* Creation time */
unsigned short crtdate; /* Creation date */
unsigned short lstaccdate; /* Last access date */
unsigned short fstclushi; /* High word of first cluster
(0 for FAT12/16) */
unsigned short wrttime; /* Last write time */
unsigned short wrtdate; /* Last write date */
unsigned short fstcluslo; /* Low word of first cluster */
unsigned int filesize; /* File size in bytes */
};
struct fat_context
{
unsigned int curr_dir_sec; /* Current directory sector */
};
struct disk_info
{
int num_sectors;
int sec_per_track;
int num_heads;
unsigned int hidden_sectors;
};
struct fat_dirent
{
int entry;
unsigned int cached_sec;
unsigned int num_sec;
char cached_buf[BLOCK_SIZE];
};
int fat_format(struct disk_info *di, char *vol_name);
int fat_create_file(struct bpb *bpb, unsigned int currdir, char *name);
int fat_opendir(struct bpb *bpb, struct fat_dirent *ent, unsigned int currdir);
int fat_getnext(struct bpb *bpb, struct fat_dirent *ent,
struct fat_direntry *entry);
#endif

44
firmware/key.h Normal file
View file

@ -0,0 +1,44 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __key_h__
#define __key_h__
#include <sh7034.h>
#include <system.h>
#define key_released(key) \
(key_released_##key ())
#define key_pressed(key) \
(!(key_released_##key ()))
static inline int key_released_ON (void)
{ return (QI(PADR+1)&(1<<5)); }
static inline int key_released_STOP (void)
{ return (QI(PADR+0)&(1<<3)); }
static inline int key_released_MINUS (void)
{ return (QI(PCDR+0)&(1<<0)); }
static inline int key_released_MENU (void)
{ return (QI(PCDR+0)&(1<<1)); }
static inline int key_released_PLUS (void)
{ return (QI(PCDR+0)&(1<<2)); }
static inline int key_released_PLAY (void)
{ return (QI(PCDR+0)&(1<<3)); }
#endif

135
firmware/lcd.c Normal file
View file

@ -0,0 +1,135 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "lcd.h"
void lcd_data (int data)
{ lcd_byte (data,1); }
void lcd_instruction (int instruction)
{ lcd_byte (instruction,0); }
void lcd_zero (int length)
{ length *= 8; while (--length >= 0) lcd_data (0); }
void lcd_fill (int data,int length)
{ length *= 8; while (--length >= 0) lcd_data (data); }
void lcd_copy (void *data,int count)
{ while (--count >= 0) lcd_data (*((char *)data)++); }
#ifdef JBP
# ifndef JBP_OLD
static char const lcd_ascii[] =
{
/*****************************************************************************************/
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
/* ************************************************************************************/
/* 0x */ 0x00,0x01,0x02,0x03,0x00,0x00,0x00,0x00,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x00,
/* 1x */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/* 2x */ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
/* 3x */ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
/* 4x */ 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
/* 5x */ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
/* 6x */ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
/* 7x */ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x20,0x20,0x20,0x20,0x20,
/* 8x */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
/* 9x */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
/* Ax */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
/* Bx */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
/* Cx */ 0x41,0x41,0x41,0x41,0x41,0x41,0x20,0x43,0x45,0x45,0x45,0x45,0x49,0x49,0x49,0x49,
/* Dx */ 0x44,0x4E,0x4F,0x4F,0x4F,0x4F,0x4F,0x20,0x20,0x55,0x55,0x55,0x55,0x59,0x20,0x20,
/* Ex */ 0x61,0x61,0x61,0x61,0x61,0x61,0x20,0x63,0x65,0x65,0x65,0x65,0x69,0x69,0x69,0x69,
/* Fx */ 0x64,0x6E,0x6F,0x6F,0x6F,0x6F,0x6F,0x20,0x20,0x75,0x75,0x75,0x75,0x79,0x79,0x79
/******/
};
# else
static char const lcd_ascii[] =
{
/*****************************************************************************************/
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
/* ************************************************************************************/
/* 0x */ 0x00,0x01,0x02,0x03,0x00,0x00,0x00,0x00,0x85,0x89,0x00,0x00,0x00,0x00,0x00,0x00,
/* 1x */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/* 2x */ 0x24,0x25,0x26,0x37,0x06,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,
/* 3x */ 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,
/* 4x */ 0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,
/* 5x */ 0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0xA9,0x33,0xCE,0x00,0x15,
/* 6x */ 0x00,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,
/* 7x */ 0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x24,0x24,0x24,0x24,0x24,
/* 8x */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
/* 9x */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
/* Ax */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
/* Bx */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
/* Cx */ 0x45,0x45,0x45,0x45,0x45,0x45,0x24,0x47,0x49,0x49,0x49,0x49,0x4D,0x4D,0x4D,0x4D,
/* Dx */ 0x48,0x52,0x53,0x53,0x53,0x53,0x53,0x24,0x24,0x59,0x59,0x59,0x59,0x5D,0x24,0x24,
/* Ex */ 0x65,0x65,0x65,0x65,0x65,0x65,0x24,0x67,0x69,0x69,0x69,0x69,0x6D,0x6D,0x6D,0x6D,
/* Fx */ 0x73,0x72,0x73,0x73,0x73,0x73,0x73,0x24,0x24,0x79,0x79,0x79,0x79,0x7D,0x24,0x7D
/******/
};
# endif
void lcd_puts (char const *string)
{
while (*string)
lcd_data (LCD_ASCII(*string++));
}
void lcd_putns (char const *string,int n)
{
while (n--)
lcd_data (LCD_ASCII(*string++));
}
void lcd_putc (int character)
{
lcd_data (LCD_ASCII(character));
}
void lcd_pattern (int which,char const *pattern,int count)
{
lcd_instruction (LCD_PRAM|which);
lcd_copy ((void *)pattern,count);
}
#else
# error "JBR : FIX ME"
#endif
void lcd_puthex (unsigned int value,int digits)
{
switch (digits)
{
case 8:
lcd_puthex (value >> 16,4);
case 4:
lcd_puthex (value >> 8,2);
case 2:
lcd_puthex (value >> 4,1);
case 1:
value &= 15;
lcd_putc (value+((value < 10) ? '0' : ('A'-10)));
}
}

263
firmware/lcd.h Normal file
View file

@ -0,0 +1,263 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __LCD_H__
#define __LCD_H__
#include <sh7034.h>
#include <system.h>
#define LCDR (PBDR+1)
/* PA14 : /LCD-BL --- backlight */
#define LCD_BL (14-8)
#ifdef JBP /* JukeBox MP3 Player - AJB6K, AJBS20 */
# define LCD_DS +1 // PB0 = 1 --- 0001 --- LCD-DS
# define LCD_CS +2 // PB1 = 1 --- 0010 --- /LCD-CS
# define LCD_SD +4 // PB2 = 1 --- 0100 --- LCD-SD
# define LCD_SC +8 // PB3 = 1 --- 1000 --- LCD-SC
# ifndef JBP_OLD
# define LCD_CONTRAST_SET ((char)0x50)
# define LCD_CRAM ((char)0x80) /* Characters */
# define LCD_PRAM ((char)0xC0) /* Patterns */
# define LCD_IRAM ((char)0x40) /* Icons */
# else
# define LCD_CONTRAST_SET ((char)0xA8)
# define LCD_CRAM ((char)0xB0) /* Characters */
# define LCD_PRAM ((char)0x80) /* Patterns */
# define LCD_IRAM ((char)0xE0) /* Icons */
# endif
# define LCD_ASCII(c) (lcd_ascii[(c)&255])
# define LCD_CURSOR(x,y) ((char)(LCD_CRAM+((y)*16+(x))))
# define LCD_ICON(i) ((char)(LCD_IRAM+i))
# define LCD_ICON_BATTERY 0
# define LCD_BATTERY_FRAME 0x02
# define LCD_BATTERY_BAR1 0x08
# define LCD_BATTERY_BAR2 0x04
# define LCD_BATTERY_BAR3 0x10
# define LCD_ICON_USB 2
# define LCD_USB_LOGO 0xFF
# define LCD_ICON_PLAY 3
# define LCD_PLAY_ICON 0xFF
# define LCD_ICON_RECORD 4
# define LCD_RECORD_ICON 0x10
# define LCD_ICON_STOP 5
# define LCD_STOP_ICON 0x0F
# define LCD_ICON_AUDIO 5
# define LCD_AUDIO_ICON 0xF0
# define LCD_ICON_REVERSE 6
# define LCD_REVERSE_ICON 0xFF
# define LCD_ICON_SINGLE 7
# define LCD_SINGLE_ICON 0xFF
# define LCD_ICON_VOLUME0 9
# define LCD_VOLUME_ICON 0x04
# define LCD_VOLUME_BAR1 0x02
# define LCD_VOLUME_BAR2 0x01
# define LCD_ICON_VOLUME1 10
# define LCD_VOLUME_BAR3 0x08
# define LCD_VOLUME_BAR4 0x04
# define LCD_VOLUME_BAR5 0x01
# define LCD_ICON_PARAM 10
# define LCD_PARAM_SYMBOL 0xF0
#endif
#ifdef JBR /* JukeBox MP3 Recorder - AJBR --- FIXME */
# error "JBR : FIX ME"
#endif
/*
* About /CS,DS,SC,SD
* ------------------
*
* LCD on JBP and JBR uses a SPI protocol to receive orders (SDA and SCK lines)
*
* - /CS -> Chip Selection line :
* 0 : LCD chipset is activated.
* - DS -> Data Selection line, latched at the rising edge
* of the 8th serial clock (*) :
* 0 : instruction register,
* 1 : data register;
* - SC -> Serial Clock line (SDA).
* - SD -> Serial Data line (SCK), latched at the rising edge
* of each serial clock (*).
*
* _ _
* /CS \ /
* \______________________________________________________/
* _____ ____ ____ ____ ____ ____ ____ ____ ____ _____
* SD \/ D7 \/ D6 \/ D5 \/ D4 \/ D3 \/ D2 \/ D1 \/ D0 \/
* _____/\____/\____/\____/\____/\____/\____/\____/\____/\_____
*
* _____ _ _ _ _ _ _ _ ________
* SC \ * \ * \ * \ * \ * \ * \ * \ *
* \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
* _ _________________________________________________________
* DS \/
* _/\_________________________________________________________
*
*/
/*
* The only way to do logical operations in an atomic way
* on SH1 is using :
*
* or.b/and.b/tst.b/xor.b #imm,@(r0,gbr)
*
* but GCC doesn't generate them at all so some assembly
* codes are needed here.
*
* The Global Base Register gbr is expected to be zero
* and r0 is the address of one register in the on-chip
* peripheral module.
*
*/
static inline void lcd_start (void)
/*
* Enter a LCD session :
*
* QI(LCDR) &= ~(LCD_CS|LCD_DS|LCD_SD|LCD_SC);
*/
{
asm
("and.b\t%0,@(r0,gbr)"
:
: /* %0 */ "I"(~(LCD_CS|LCD_DS|LCD_SD|LCD_SC)),
/* %1 */ "z"(LCDR));
}
static inline void lcd_stop (void)
/*
* Leave a LCD session :
*
* QI(LCDR) |= LCD_CS|LCD_RS|LCD_SD|LCD_SC;
*/
{
asm
("or.b\t%0,@(r0,gbr)"
:
: /* %0 */ "I"(LCD_CS|LCD_DS|LCD_SD|LCD_SC),
/* %1 */ "z"(LCDR));
}
static inline void lcd_byte (int byte,int rs)
/*
* char j = 0x80;
* if (rs)
* do
* {
* QI(LCDR) &= ~(LCD_SC|LCD_SD);
* if (j & byte)
* QI(LCDR) |= LCD_SD;
* QI(LCDR) |= LCD_SC|LCD_DS;
* }
* while ((unsigned char)j >>= 1);
* else
* do
* {
* QI(LCDR) &= ~(LCD_SC|LCD_SD|LCD_DS);
* if (j & byte)
* QI(LCDR) |= LCD_SD;
* QI(LCDR) |= LCD_SC;
* }
* while ((unsigned char)j >>= 1);
*/
{
if (rs > 0)
asm
("shll8\t%0\n"
"0:\n\t"
"and.b\t%2,@(r0,gbr)\n\t"
"shll\t%0\n\t"
"bf\t1f\n\t"
"or.b\t%3,@(r0,gbr)\n"
"1:\n\t"
"or.b\t%4,@(r0,gbr)\n"
"add\t#-1,%1\n\t"
"cmp/pl\t%1\n\t"
"bt\t0b"
:
: /* %0 */ "r"(((unsigned)byte)<<16),
/* %1 */ "r"(8),
/* %2 */ "I"(~(LCD_SC|LCD_SD)),
/* %3 */ "I"(LCD_SD),
/* %4 */ "I"(LCD_SC|LCD_DS),
/* %5 */ "z"(LCDR));
else
asm
("shll8\t%0\n"
"0:\n\t"
"and.b\t%2,@(r0,gbr)\n\t"
"shll\t%0\n\t"
"bf\t1f\n\t"
"or.b\t%3,@(r0,gbr)\n"
"1:\n\t"
"or.b\t%4,@(r0,gbr)\n"
"add\t#-1,%1\n\t"
"cmp/pl\t%1\n\t"
"bt\t0b"
:
: /* %0 */ "r"(((unsigned)byte)<<16),
/* %1 */ "r"(8),
/* %2 */ "I"(~(LCD_SC|LCD_DS|LCD_SD)),
/* %3 */ "I"(LCD_SD),
/* %4 */ "I"(LCD_SC),
/* %5 */ "z"(LCDR));
}
extern void lcd_data (int data);
extern void lcd_instruction (int instruction);
extern void lcd_zero (int length);
extern void lcd_fill (int data,int length);
extern void lcd_copy (void *data,int count);
#ifdef JBP
extern void lcd_puts (char const *string);
extern void lcd_putns (char const *string,int n);
extern void lcd_putc (int character);
extern void lcd_puthex (unsigned int value,int digits);
extern void lcd_pattern (int which,char const *pattern,int count);
static inline void lcd_goto (int x,int y)
{ lcd_instruction (LCD_CURSOR(x,y)); }
#endif
#ifdef JBR
# error "JBR : FIX ME"
#endif
/*** BACKLIGHT ***/
static inline void lcd_toggle_backlight (void)
{ toggle_bit (LCD_BL,PAIOR); }
static inline void lcd_turn_on_backlight (void)
{ set_bit (LCD_BL,PAIOR); }
static inline void lcd_turn_off_backlight (void)
{ clear_bit (LCD_BL,PAIOR); }
/*** ICONS ***/
#endif

68
firmware/led.c Normal file
View file

@ -0,0 +1,68 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <led.h>
#define turn_on() \
set_bit (LEDB,PBDR+1)
#define turn_off() \
clear_bit (LEDB,PBDR+1)
#define start_timer() \
set_bit (2,ITUTSTR)
#define stop_timer() \
clear_bit (2,ITUTSTR)
#define eoi(subinterrupt) \
clear_bit (subinterrupt,ITUTSR2)
#define set_volume(volume) \
HI(ITUGRA2) = volume & 0x7FFF
void led_set_volume (unsigned short volume)
{
volume <<= 10;
if (volume == 0)
led_turn_off ();
else if (volume == 0x8000)
led_turn_on ();
else
{
set_volume (volume);
start_timer ();
}
}
#pragma interrupt
void IMIA2 (void)
{
turn_off ();
eoi (0);
}
#pragma interrupt
void OVI2 (void)
{
turn_on ();
eoi (2);
}

50
firmware/led.h Normal file
View file

@ -0,0 +1,50 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __LED_H__
#define __LED_H__
#include <sh7034.h>
#include <system.h>
#define LEDB 6 /* PB6 : red LED */
static inline void led_turn_off (void)
{
clear_bit (LEDB,PBDR+1);
clear_bit (2,ITUTSTR);
}
static inline void led_turn_on (void)
{
set_bit (LEDB,PBDR+1);
set_bit (2,ITUTSTR);
}
static inline void led_toggle (void)
{
toggle_bit (LEDB,PBDR+1);
}
extern void led_set_volume (unsigned short volume);
extern void led_setup (void);
#endif

82
firmware/serial.c Normal file
View file

@ -0,0 +1,82 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <serial.h>
#include <lcd.h>
#define TDRE 7 /* transmit data register empty */
#define RDRF 6 /* receive data register full */
#define ORER 5 /* overrun error */
#define FER 4 /* frame error */
#define PER 3 /* parity error */
static int serial_byte,serial_flag;
void serial_putc (char byte)
{
static int i = 0;
while (!(QI(SCISSR1) & (1<<TDRE)));
QI(SCITDR1) = byte;
clear_bit (TDRE,SCISSR1);
lcd_goto ((i++)%11,1); lcd_putc (byte);
}
void serial_puts (char const *string)
{
int byte;
while ((byte = *string++))
serial_putc (byte);
}
int serial_getc( void )
{
int byte;
while (!serial_flag);
byte = serial_byte;
serial_flag = 0;
serial_putc (byte);
return byte;
}
void serial_setup (int baudrate)
{
QI(SCISCR1) =
QI(SCISSR1) =
QI(SCISMR1) = 0;
QI(SCIBRR1) = (PHI/(32*baudrate))-1;
QI(SCISCR1) = 0x70;
}
#pragma interrupt
void REI1 (void)
{
clear_bit (FER,SCISSR1);
}
#pragma interrupt
void RXI1 (void)
{
serial_byte = QI(SCIRDR1);
serial_flag = 1;
clear_bit (RDRF,SCISSR1);
if (serial_byte == '0')
lcd_turn_off_backlight ();
if (serial_byte == '1')
lcd_turn_on_backlight ();
}

31
firmware/serial.h Normal file
View file

@ -0,0 +1,31 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __SERIAL_H__
#define __SERIAL_H__
#include <sh7034.h>
#include <system.h>
extern void serial_putc (char);
extern void serial_puts (char const *);
extern int serial_getc (void);
extern void serial_setup (int);
#endif

167
firmware/sh7034.h Normal file
View file

@ -0,0 +1,167 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __SH7034_H__
#define __SH7034_H__
#define GBR 0x00000000
#define SCISMR0 0x05FFFEC0
#define SCIBRR0 0x05FFFEC1
#define SCISCR0 0x05FFFEC2
#define SCITDR0 0x05FFFEC3
#define SCISSR0 0x05FFFEC4
#define SCIRDR0 0x05FFFEC5
#define SCISMR1 0x05FFFEC8
#define SCIBRR1 0x05FFFEC9
#define SCISCR1 0x05FFFECA
#define SCITDR1 0x05FFFECB
#define SCISSR1 0x05FFFECC
#define SCIRDR1 0x05FFFECD
#define ADDRA 0x05FFFEE0
#define ADDRAH 0x05FFFEE0
#define ADDRAL 0x05FFFEE1
#define ADDRB 0x05FFFEE2
#define ADDRBH 0x05FFFEE2
#define ADDRBL 0x05FFFEE3
#define ADDRC 0x05FFFEE4
#define ADDRCH 0x05FFFEE4
#define ADDRCL 0x05FFFEE5
#define ADDRD 0x05FFFEE6
#define ADDRDH 0x05FFFEE6
#define ADDRDL 0x05FFFEE6
#define ADCSR 0x05FFFEE8
#define ADCR 0x05FFFEE9
#define ITUTSTR 0x05FFFF00
#define ITUTSNC 0x05FFFF01
#define ITUTMDR 0x05FFFF02
#define ITUTFCR 0x05FFFF03
#define ITUTCR0 0x05FFFF04
#define ITUTIOR0 0x05FFFF05
#define ITUTIER0 0x05FFFF06
#define ITUTSR0 0x05FFFF07
#define ITUTCNT0 0x05FFFF08
#define ITUGRA0 0x05FFFF0A
#define ITUGRB0 0x05FFFF0C
#define ITUTCR1 0x05FFFF0E
#define ITUTIOR1 0x05FFFF0F
#define ITUTIER1 0x05FFFF10
#define ITUTSR1 0x05FFFF11
#define ITUTCNT1 0x05FFFF12
#define ITUGRA1 0x05FFFF14
#define ITUGRB1 0x05FFFF16
#define ITUTCR2 0x05FFFF18
#define ITUTIOR2 0x05FFFF19
#define ITUTIER2 0x05FFFF1A
#define ITUTSR2 0x05FFFF1B
#define ITUTCNT2 0x05FFFF1C
#define ITUGRA2 0x05FFFF1E
#define ITUGRB2 0x05FFFF20
#define ITUTCR3 0x05FFFF22
#define ITUTIOR3 0x05FFFF23
#define ITUTIER3 0x05FFFF24
#define ITUTSR3 0x05FFFF25
#define ITUTCNT3 0x05FFFF26
#define ITUGRA3 0x05FFFF28
#define ITUGRB3 0x05FFFF2A
#define ITUBRA3 0x05FFFF2C
#define ITUBRB3 0x05FFFF2E
#define ITUTOCR 0x05FFFF31
#define ITUTCR4 0x05FFFF32
#define ITUTIOR4 0x05FFFF33
#define ITUTIER4 0x05FFFF34
#define ITUTSR4 0x05FFFF35
#define ITUTCNT4 0x05FFFF36
#define ITUGRA4 0x05FFFF38
#define ITUGRB4 0x05FFFF3A
#define ITUBRA4 0x05FFFF3C
#define ITUBRB4 0x05FFFF3E
#define DMACSAR0 0x05FFFF40
#define DMACDAR0 0x05FFFF44
#define DMACOR 0x05FFFF48
#define DMACTCR0 0x05FFFF4A
#define DMACCHCR0 0x05FFFF4E
#define DMACSAR1 0x05FFFF50
#define DMACDAR1 0x05FFFF54
#define DMACTCR1 0x05FFFF5A
#define DMACCHCR1 0x05FFFF5E
#define DMACSAR2 0x05FFFF60
#define DMACDAR2 0x05FFFF64
#define DMACTCR2 0x05FFFF6A
#define DMACCHCR2 0x05FFFF6E
#define DMACSAR3 0x05FFFF70
#define DMACDAR3 0x05FFFF74
#define DMACTCR3 0x05FFFF7A
#define DMACCHCR3 0x05FFFF7E
#define INTCIPRAB 0x05FFFF84
#define INTCIPRA 0x05FFFF84
#define INTCIPRB 0x05FFFF86
#define INTCIPRCD 0x05FFFF88
#define INTCIPRC 0x05FFFF88
#define INTCIPRD 0x05FFFF8A
#define INTCIPRE 0x05FFFF8C
#define INTCICR 0x05FFFF8E
#define UBCBAR 0x05FFFF90
#define UBCBARH 0x05FFFF90
#define UBCBARL 0x05FFFF92
#define UBCBAMR 0x05FFFF94
#define UBCBAMRH 0x05FFFF94
#define UBCBAMRL 0x05FFFF96
#define UBCBBR 0x05FFFF98
#define BSCBCR 0x05FFFFA0
#define BSCWCR1 0x05FFFFA2
#define BSCWCR2 0x05FFFFA4
#define BSCWCR3 0x05FFFFA6
#define BSCDCR 0x05FFFFA8
#define BSCPCR 0x05FFFFAA
#define BSCRCR 0x05FFFFAC
#define BSCRTCSR 0x05FFFFAE
#define BSCRTCNT 0x05FFFFB0
#define BSCRTCOR 0x05FFFFB2
#define WDTTCSR 0x05FFFFB8
#define WDTTCNT 0x05FFFFB9
#define WDTRSTCSR 0x05FFFFBB
#define SBYCR 0x05FFFFBC
#define PABDR 0x05FFFFC0
#define PADR 0x05FFFFC0
#define PBDR 0x05FFFFC2
#define PABIOR 0x05FFFFC4
#define PAIOR 0x05FFFFC4
#define PBIOR 0x05FFFFC6
#define PACR 0x05FFFFC8
#define PACR1 0x05FFFFC8
#define PACR2 0x05FFFFCA
#define PBCR 0x05FFFFCC
#define PBCR1 0x05FFFFCC
#define PBCR2 0x05FFFFCE
#define PCDR 0x05FFFFD1
#define CASCR 0x05FFFFEE
#endif

41
firmware/start.s Normal file
View file

@ -0,0 +1,41 @@
!----------------------------------------------------------------------------
! __________ __ ___.
! Open \______ \ ____ ____ | | _\_ |__ _______ ___
! Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
! Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
! Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
! \/ \/ \/ \/ \/
! $Id$
!
! Copyright (C) 2002 by Björn Stenberg
!
! All files in this archive are subject to the GNU General Public License.
! See the file COPYING in the source tree root for full license agreement.
!
! This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
! KIND, either express or implied.
!----------------------------------------------------------------------------
!
! note: sh-1 has a "delay cycle" after every branch where you can
! execute another instruction "for free".
.file "start.s"
.section .text.start
.extern _main
.extern _vectors
.extern _stack
.global _start
.align 2
_start:
mov.l 1f, r1
mov.l 3f, r3
mov.l 2f, r15
jmp @r3
ldc r1, vbr
nop
1: .long _vectors
2: .long _stack
3: .long _main
.type _start,@function

432
firmware/system.c Normal file
View file

@ -0,0 +1,432 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <lcd.h>
#include <led.h>
#define default_interrupt(name,number) \
extern __attribute__((weak,alias("UIE" #number))) void name (void); void UIE##number (void)
#define reserve_interrupt(number) \
void UIE##number (void)
extern void reset_pc (void);
extern void reset_sp (void);
reserve_interrupt ( 0);
reserve_interrupt ( 1);
reserve_interrupt ( 2);
reserve_interrupt ( 3);
default_interrupt (GII, 4);
reserve_interrupt ( 5);
default_interrupt (ISI, 6);
reserve_interrupt ( 7);
reserve_interrupt ( 8);
default_interrupt (CPUAE, 9);
default_interrupt (DMAAE, 10);
default_interrupt (NMI, 11);
default_interrupt (UB, 12);
reserve_interrupt ( 13);
reserve_interrupt ( 14);
reserve_interrupt ( 15);
reserve_interrupt ( 16); // TCB #0
reserve_interrupt ( 17); // TCB #1
reserve_interrupt ( 18); // TCB #2
reserve_interrupt ( 19); // TCB #3
reserve_interrupt ( 20); // TCB #4
reserve_interrupt ( 21); // TCB #5
reserve_interrupt ( 22); // TCB #6
reserve_interrupt ( 23); // TCB #7
reserve_interrupt ( 24); // TCB #8
reserve_interrupt ( 25); // TCB #9
reserve_interrupt ( 26); // TCB #10
reserve_interrupt ( 27); // TCB #11
reserve_interrupt ( 28); // TCB #12
reserve_interrupt ( 29); // TCB #13
reserve_interrupt ( 30); // TCB #14
reserve_interrupt ( 31); // TCB #15
default_interrupt (TRAPA32, 32);
default_interrupt (TRAPA33, 33);
default_interrupt (TRAPA34, 34);
default_interrupt (TRAPA35, 35);
default_interrupt (TRAPA36, 36);
default_interrupt (TRAPA37, 37);
default_interrupt (TRAPA38, 38);
default_interrupt (TRAPA39, 39);
default_interrupt (TRAPA40, 40);
default_interrupt (TRAPA41, 41);
default_interrupt (TRAPA42, 42);
default_interrupt (TRAPA43, 43);
default_interrupt (TRAPA44, 44);
default_interrupt (TRAPA45, 45);
default_interrupt (TRAPA46, 46);
default_interrupt (TRAPA47, 47);
default_interrupt (TRAPA48, 48);
default_interrupt (TRAPA49, 49);
default_interrupt (TRAPA50, 50);
default_interrupt (TRAPA51, 51);
default_interrupt (TRAPA52, 52);
default_interrupt (TRAPA53, 53);
default_interrupt (TRAPA54, 54);
default_interrupt (TRAPA55, 55);
default_interrupt (TRAPA56, 56);
default_interrupt (TRAPA57, 57);
default_interrupt (TRAPA58, 58);
default_interrupt (TRAPA59, 59);
default_interrupt (TRAPA60, 60);
default_interrupt (TRAPA61, 61);
default_interrupt (TRAPA62, 62);
default_interrupt (TRAPA63, 63);
default_interrupt (IRQ0, 64);
default_interrupt (IRQ1, 65);
default_interrupt (IRQ2, 66);
default_interrupt (IRQ3, 67);
default_interrupt (IRQ4, 68);
default_interrupt (IRQ5, 69);
default_interrupt (IRQ6, 70);
default_interrupt (IRQ7, 71);
default_interrupt (DEI0, 72);
reserve_interrupt ( 73);
default_interrupt (DEI1, 74);
reserve_interrupt ( 75);
default_interrupt (DEI2, 76);
reserve_interrupt ( 77);
default_interrupt (DEI3, 78);
reserve_interrupt ( 79);
default_interrupt (IMIA0, 80);
default_interrupt (IMIB0, 81);
default_interrupt (OVI0, 82);
reserve_interrupt ( 83);
default_interrupt (IMIA1, 84);
default_interrupt (IMIB1, 85);
default_interrupt (OVI1, 86);
reserve_interrupt ( 87);
default_interrupt (IMIA2, 88);
default_interrupt (IMIB2, 89);
default_interrupt (OVI2, 90);
reserve_interrupt ( 91);
default_interrupt (IMIA3, 92);
default_interrupt (IMIB3, 93);
default_interrupt (OVI3, 94);
reserve_interrupt ( 95);
default_interrupt (IMIA4, 96);
default_interrupt (IMIB4, 97);
default_interrupt (OVI4, 98);
reserve_interrupt ( 99);
default_interrupt (REI0, 100);
default_interrupt (RXI0, 101);
default_interrupt (TXI0, 102);
default_interrupt (TEI0, 103);
default_interrupt (REI1, 104);
default_interrupt (RXI1, 105);
default_interrupt (TXI1, 106);
default_interrupt (TEI1, 107);
reserve_interrupt ( 108);
default_interrupt (ADITI, 109);
void (*vbr[]) (void) __attribute__ ((section (".sram.vbr"))) =
{
/*** 0-1 Power-on Reset ***/
reset_pc,reset_sp,
/*** 2-3 Manual Reset ***/
reset_pc,reset_sp,
/*** 4 General Illegal Instruction ***/
GII,
/*** 5 Reserved ***/
UIE5,
/*** 6 Illegal Slot Instruction ***/
ISI,
/*** 7-8 Reserved ***/
UIE7,UIE8,
/*** 9 CPU Address Error ***/
CPUAE,
/*** 10 DMA Address Error ***/
DMAAE,
/*** 11 NMI ***/
NMI,
/*** 12 User Break ***/
UB,
/*** 13-31 Reserved ***/
UIE13,UIE14,UIE15,UIE16,UIE17,UIE18,UIE19,UIE20,UIE21,UIE22,UIE23,UIE24,UIE25,UIE26,UIE27,UIE28,UIE29,UIE30,UIE31,
/*** 32-63 TRAPA #20...#3F ***/
TRAPA32,TRAPA33,TRAPA34,TRAPA35,TRAPA36,TRAPA37,TRAPA38,TRAPA39,TRAPA40,TRAPA41,TRAPA42,TRAPA43,TRAPA44,TRAPA45,TRAPA46,TRAPA47,TRAPA48,TRAPA49,TRAPA50,TRAPA51,TRAPA52,TRAPA53,TRAPA54,TRAPA55,TRAPA56,TRAPA57,TRAPA58,TRAPA59,TRAPA60,TRAPA61,TRAPA62,TRAPA63,
/*** 64-71 IRQ0-7 ***/
IRQ0,IRQ1,IRQ2,IRQ3,IRQ4,IRQ5,IRQ6,IRQ7,
/*** 72 DMAC0 ***/
DEI0,
/*** 73 Reserved ***/
UIE73,
/*** 74 DMAC1 ***/
DEI1,
/*** 75 Reserved ***/
UIE75,
/*** 76 DMAC2 ***/
DEI2,
/*** 77 Reserved ***/
UIE77,
/*** 78 DMAC3 ***/
DEI3,
/*** 79 Reserved ***/
UIE79,
/*** 80-82 ITU0 ***/
IMIA0,IMIB0,OVI0,
/*** 83 Reserved ***/
UIE83,
/*** 84-86 ITU1 ***/
IMIA1,IMIB1,OVI1,
/*** 87 Reserved ***/
UIE87,
/*** 88-90 ITU2 ***/
IMIA2,IMIB2,OVI2,
/*** 91 Reserved ***/
UIE91,
/*** 92-94 ITU3 ***/
IMIA3,IMIB3,OVI3,
/*** 95 Reserved ***/
UIE95,
/*** 96-98 ITU4 ***/
IMIA4,IMIB4,OVI4,
/*** 99 Reserved ***/
UIE99,
/*** 100-103 SCI0 ***/
REI0,RXI0,TXI0,TEI0,
/*** 104-107 SCI1 ***/
REI1,RXI1,TXI1,TEI1,
/*** 108 Parity Control Unit ***/
UIE108,
/*** 109 AD Converter ***/
ADITI
};
void system_reboot (void)
{
cli ();
asm volatile ("ldc\t%0,vbr" : : "r"(0));
SI(INTCIPRAB) =
SI(INTCIPRCD) = 0;
HI(INTCIPRE) =
HI(INTCICR) = 0;
asm volatile ("jmp @%0; mov.l @%1,r15" : : "r"(SI(0)),"r"(4));
}
void UIE (unsigned int pc) /* Unexpected Interrupt or Exception */
{
unsigned int i,n;
lcd_stop ();
asm volatile ("sts\tpr,%0" : "=r"(n));
n = (n - (unsigned)UIE0 - 4)>>2; // get exception or interrupt number
lcd_start ();
lcd_goto (0,0); lcd_puts ("** UIE00 **");
lcd_goto (0,1); lcd_puts ("AT 00000000");
lcd_goto (6,0); lcd_puthex (n,2);
lcd_goto (3,1); lcd_puthex (pc,8); /* or pc - 4 !? */
lcd_stop ();
while (1)
{
led_toggle ();
for (i = 0; i < 240000; ++i);
}
}
asm (
"_UIE0:\tbsr\t_UIE\n\tmov.l\t@r15+,r4\t\n"
"_UIE1:\tbsr\t_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r\t_UIE\n\tmov.l\t@r15+,r4\t\n"
"_UIE102:\tbsr\t_UIE\n\tmov.l\t@r15+,r4\t\n"
"_UIE103:\tbsr\t_UIE\n\tmov.l\t@r15+,r4\t\n"
"_UIE104:\tbsr\t_UIE\n\tmov.l\t@r15+,r4\t\n"
"_UIE105:\tbsr\t_UIE\n\tmov.l\t@r15+,r4\t\n"
"_UIE106:\tbsr\t_UIE\n\tmov.l\t@r15+,r4\t\n"
"_UIE107:\tbsr\t_UIE\n\tmov.l\t@r15+,r4\t\n"
"_UIE108:\tbsr\t_UIE\n\tmov.l\t@r15+,r4\t\n"
"_UIE109:\tbsr\t_UIE\n\tmov.l\t@r15+,r4");

267
firmware/system.h Normal file
View file

@ -0,0 +1,267 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __SYSTEM_H__
#define __SYSTEM_H__
#include <sh7034.h>
#define KB *1024
#define MB *1024 KB
#define GB *1024 MB
#define Hz *1
#define KHz *1000 Hz
#define MHz *1000 KHz
#define ns *1
#define us *1000 ns
#define ms *1000 us
/*
* 11.059,200 MHz => 90.4224537037037037037037037037037... ns
* 12.000,000 MHz => 83.3333333333333333333333333333333... ns
*/
#define PHI ((int)(12.000000 MHz))
#define BAUDRATE 9600
//#define PHI ((int)(11.059200 MHz))
//#define BAUDRATE 115200 /* 115200 - 9600 */
#define SI(a) \
(*((volatile int *)a)) /* single integer access - 32-bit */
#define HI(a) \
(*((volatile short *)a)) /* half integer access - 16-bit */
#define QI(a) \
(*((volatile char *)a)) /* quarter integer access - 8-bit */
#define nop \
asm volatile ("nop")
#define __set_mask_constant(mask,address) \
asm \
("or.b\t%0,@(r0,gbr)" \
: \
: /* %0 */ "I"((char)(mask)), \
/* %1 */ "z"(address-GBR))
#define __clear_mask_constant(mask,address) \
asm \
("and.b\t%0,@(r0,gbr)" \
: \
: /* %0 */ "I"((char)~(mask)), \
/* %1 */ "z"(address-GBR))
#define __toggle_mask_constant(mask,address) \
asm \
("xor.b\t%0,@(r0,gbr)" \
: \
: /* %0 */ "I"((char)(mask)), \
/* %1 */ "z"(address-GBR))
#define __test_mask_constant(mask,address) \
({ \
int result; \
asm \
("tst.b\t%1,@(r0,gbr)\n\tmovt\t%0" \
: "=r"(result) \
: "I"((char)(mask)),"z"(address-GBR)); \
result; \
})
#define __set_bit_constant(bit,address) \
asm \
("or.b\t%0,@(r0,gbr)" \
: \
: /* %0 */ "I"((char)(1<<(bit))), \
/* %1 */ "z"(address-GBR))
#define __clear_bit_constant(bit,address) \
asm \
("and.b\t%0,@(r0,gbr)" \
: \
: /* %0 */ "I"((char)~(1<<(bit))), \
/* %1 */ "z"(address-GBR))
#define __toggle_bit_constant(bit,address) \
asm \
("xor.b\t%0,@(r0,gbr)" \
: \
: /* %0 */ "I"((char)(1<<(bit))), \
/* %1 */ "z"(address-GBR))
#define __test_bit_constant(bit,address) \
({ \
int result; \
asm \
("tst.b\t%1,@(r0,gbr)\n\tmovt\t%0" \
: "=r"(result) \
: "I"((char)(1<<(bit))),"z"(address-GBR)); \
result; \
})
#define __set_mask(mask,address) /* FIXME */
#define __test_mask(mask,address) 0 /* FIXME */
#define __clear_mask(mask,address) /* FIXME */
#define __toggle_mask(mask,address) /* FIXME */
#define __set_bit(bit,address) /* FIXME */
#define __test_bit(bit,address) 0 /* FIXME */
#define __clear_bit(bit,address) /* FIXME */
#define __toggle_bit(bit,address) /* FIXME */
#define set_mask(mask,address) \
if (__builtin_constant_p (mask)) \
__set_mask_constant (mask,address); \
else \
__set_mask (mask,address)
#define clear_mask(mask,address) \
if (__builtin_constant_p (mask)) \
__clear_mask_constant (mask,address); \
else \
__clear_mask (mask,address)
#define toggle_mask(mask,address) \
if (__builtin_constant_p (mask)) \
__toggle_mask_constant (mask,address); \
else \
__toggle_mask (mask,address)
#define test_mask(mask,address) \
( \
(__builtin_constant_p (mask)) \
? (int)__test_mask_constant (mask,address) \
: (int)__test_mask (mask,address) \
)
#define set_bit(bit,address) \
if (__builtin_constant_p (bit)) \
__set_bit_constant (bit,address); \
else \
__set_bit (bit,address)
#define clear_bit(bit,address) \
if (__builtin_constant_p (bit)) \
__clear_bit_constant (bit,address); \
else \
__clear_bit (bit,address)
#define toggle_bit(bit,address) \
if (__builtin_constant_p (bit)) \
__toggle_bit_constant (bit,address); \
else \
__toggle_bit (bit,address)
#define test_bit(bit,address) \
( \
(__builtin_constant_p (bit)) \
? (int)__test_bit_constant (bit,address) \
: (int)__test_bit (bit,address) \
)
extern char __swap_bit[256];
#define swap_bit(byte) \
__swap_bit[byte]
static inline short swabHI (short value)
/*
result[15..8] = value[ 7..0];
result[ 7..0] = value[15..8];
*/
{
short result;
asm volatile ("swap.b\t%1,%0" : "=r"(result) : "r"(value));
return result;
}
static inline int swawSI (int value)
/*
result[31..16] = value[15.. 0];
result[15.. 0] = value[31..16];
*/
{
int result;
asm volatile ("swap.w\t%1,%0" : "=r"(result) : "r"(value));
return result;
}
static inline int swabSI (int value) // should be avoided as much as possible
/*
result[31..24] = value[ 7.. 0];
result[23..16] = value[15.. 8];
result[15.. 8] = value[23..16];
result[ 7.. 0] = value[31..24];
*/
{
return swabHI(swawSI(swabSI(value)));
}
/* Test And Set - UNTESTED */
static inline int tas (volatile int *pointer)
{
int result;
asm volatile ("tas.b\t@%1;movt\t%0" : "=t"(result) : "r"((char *)pointer) : "memory");
return result;
}
static inline void sti (void)
{
asm volatile ("ldc\t%0,sr" : : "r"(0<<4));
}
static inline void cli (void)
{
asm volatile ("ldc\t%0,sr" : : "r"(15<<4));
}
/* Compare And Swap */
static inline int cas (volatile int *pointer,int requested_value,int new_value)
{
cli();
if (*pointer == requested_value)
{
*pointer = new_value;
sti ();
return 1;
}
sti ();
return 0;
}
static inline int cas2 (volatile int *pointer1,volatile int *pointer2,int requested_value1,int requested_value2,int new_value1,int new_value2)
{
cli();
if (*pointer1 == requested_value1 && *pointer2 == requested_value2)
{
*pointer1 = new_value1;
*pointer2 = new_value2;
sti ();
return 1;
}
sti ();
return 0;
}
extern void system_reboot (void);
#endif