From f2042983f08cd49404be0b6916fc73d778fe8dba Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Fri, 2 May 2008 19:12:09 +0000 Subject: Add the Sansa M200 (v1) as a target - it's extremely similar to the Logik DAX (the LCD driver worked unchanged). Plus various tcc77x work, including a working tick interrupt (enabled in the bootloader). Rockbox itself builds for the M200 (there are no keymaps yet for the DAX), but doesn't progress very far due to the lack of an ATA (NAND flash) driver. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17306 a1c6a512-1295-4272-9138-f99709370657 --- apps/keymaps/keymap-m200.c | 323 +++++++++++++++++++++ bootloader/telechips.c | 65 ++++- firmware/SOURCES | 33 ++- firmware/drivers/audio/tlv320.c | 6 + firmware/drivers/rtc/rtc_tcc77x.c | 75 +++++ firmware/export/config-logikdax.h | 2 +- firmware/export/config-m200.h | 116 ++++++++ firmware/export/config.h | 3 + firmware/export/tcc77x.h | 63 +++- firmware/export/timer.h | 3 +- firmware/target/arm/tcc77x/app.lds | 144 +++++++++ firmware/target/arm/tcc77x/ata-nand-tcc77x.c | 10 + firmware/target/arm/tcc77x/boot.lds | 8 +- firmware/target/arm/tcc77x/crt0.S | 124 ++++++-- firmware/target/arm/tcc77x/debug-target.h | 22 ++ firmware/target/arm/tcc77x/debug-tcc77x.c | 81 ++++++ firmware/target/arm/tcc77x/i2c-target.h | 37 +++ firmware/target/arm/tcc77x/kernel-tcc77x.c | 45 +++ firmware/target/arm/tcc77x/lcd-ssd1815.c | 2 +- firmware/target/arm/tcc77x/m200/adc-target.h | 26 ++ firmware/target/arm/tcc77x/m200/backlight-target.h | 42 +++ firmware/target/arm/tcc77x/m200/button-m200.c | 97 +++++++ firmware/target/arm/tcc77x/m200/button-target.h | 52 ++++ firmware/target/arm/tcc77x/m200/power-m200.c | 66 +++++ firmware/target/arm/tcc77x/pcm-tcc77x.c | 75 +++++ firmware/target/arm/tcc77x/powermgmt-tcc77x.c | 64 ++++ firmware/target/arm/tcc77x/system-tcc77x.c | 152 +++++++++- firmware/target/arm/tcc77x/timer-target.h | 39 +++ firmware/target/arm/tcc77x/timer-tcc77x.c | 79 +++++ firmware/target/arm/tcc77x/usb-tcc77x.c | 36 +++ tools/configure | 26 +- 31 files changed, 1879 insertions(+), 37 deletions(-) create mode 100644 apps/keymaps/keymap-m200.c create mode 100644 firmware/drivers/rtc/rtc_tcc77x.c create mode 100644 firmware/export/config-m200.h create mode 100644 firmware/target/arm/tcc77x/app.lds create mode 100644 firmware/target/arm/tcc77x/debug-target.h create mode 100644 firmware/target/arm/tcc77x/debug-tcc77x.c create mode 100644 firmware/target/arm/tcc77x/i2c-target.h create mode 100644 firmware/target/arm/tcc77x/kernel-tcc77x.c create mode 100644 firmware/target/arm/tcc77x/m200/adc-target.h create mode 100644 firmware/target/arm/tcc77x/m200/backlight-target.h create mode 100644 firmware/target/arm/tcc77x/m200/button-m200.c create mode 100644 firmware/target/arm/tcc77x/m200/button-target.h create mode 100644 firmware/target/arm/tcc77x/m200/power-m200.c create mode 100644 firmware/target/arm/tcc77x/pcm-tcc77x.c create mode 100644 firmware/target/arm/tcc77x/powermgmt-tcc77x.c create mode 100644 firmware/target/arm/tcc77x/timer-target.h create mode 100644 firmware/target/arm/tcc77x/timer-tcc77x.c create mode 100644 firmware/target/arm/tcc77x/usb-tcc77x.c diff --git a/apps/keymaps/keymap-m200.c b/apps/keymaps/keymap-m200.c new file mode 100644 index 0000000000..141905129a --- /dev/null +++ b/apps/keymaps/keymap-m200.c @@ -0,0 +1,323 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 Mark Arigo + * + * 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. + * + ****************************************************************************/ +/* Button Code Definitions for Sandisk c200 target */ + +#include "config.h" +#include "action.h" +#include "button.h" +#include "settings.h" + +/* {Action Code, Button code, Prereq button code } */ + +/* + * The format of the list is as follows + * { Action Code, Button code, Prereq button code } + * if there's no need to check the previous button's value, use BUTTON_NONE + * Insert LAST_ITEM_IN_LIST at the end of each mapping + */ +static const struct button_mapping button_context_standard[] = { + { ACTION_STD_PREV, BUTTON_VOLUP, BUTTON_NONE }, + { ACTION_STD_PREVREPEAT, BUTTON_VOLUP|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_STD_NEXT, BUTTON_VOLDOWN, BUTTON_NONE }, + { ACTION_STD_NEXTREPEAT, BUTTON_VOLDOWN|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_STD_OK, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT }, + { ACTION_STD_OK, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_STD_CANCEL, BUTTON_LEFT, BUTTON_NONE }, + + { ACTION_STD_MENU, BUTTON_MENU|BUTTON_REL, BUTTON_MENU }, + { ACTION_STD_CONTEXT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT }, +// { ACTION_STD_QUICKSCREEN, BUTTON_REC|BUTTON_SELECT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_standard */ + + +static const struct button_mapping button_context_wps[] = { + { ACTION_WPS_PLAY, BUTTON_VOLUP|BUTTON_REL, BUTTON_VOLUP }, + { ACTION_WPS_STOP, BUTTON_VOLUP|BUTTON_REPEAT, BUTTON_VOLUP }, + + { ACTION_WPS_SKIPPREV, BUTTON_LEFT|BUTTON_REL, BUTTON_LEFT }, + { ACTION_WPS_SEEKBACK, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_WPS_STOPSEEK, BUTTON_LEFT|BUTTON_REL, BUTTON_LEFT|BUTTON_REPEAT }, + + { ACTION_WPS_SKIPNEXT, BUTTON_RIGHT|BUTTON_REL, BUTTON_RIGHT }, + { ACTION_WPS_SEEKFWD, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_WPS_STOPSEEK, BUTTON_RIGHT|BUTTON_REL, BUTTON_RIGHT|BUTTON_REPEAT }, + + { ACTION_WPS_ABSETB_NEXTDIR,BUTTON_MENU|BUTTON_RIGHT, BUTTON_MENU }, + { ACTION_WPS_ABSETA_PREVDIR,BUTTON_MENU|BUTTON_LEFT, BUTTON_MENU }, + { ACTION_WPS_ABRESET, BUTTON_MENU|BUTTON_VOLUP, BUTTON_MENU }, + + { ACTION_WPS_MENU, BUTTON_MENU|BUTTON_REL, BUTTON_MENU }, + { ACTION_WPS_BROWSE, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT }, + { ACTION_WPS_PITCHSCREEN, BUTTON_SELECT|BUTTON_VOLUP, BUTTON_SELECT }, + { ACTION_WPS_ID3SCREEN, BUTTON_SELECT|BUTTON_VOLDOWN, BUTTON_SELECT }, + { ACTION_WPS_CONTEXT, BUTTON_VOLDOWN|BUTTON_REL, BUTTON_VOLDOWN }, + { ACTION_WPS_QUICKSCREEN, BUTTON_VOLDOWN|BUTTON_REPEAT, BUTTON_VOLDOWN }, + + LAST_ITEM_IN_LIST +}; /* button_context_wps */ + +static const struct button_mapping button_context_settings[] = { + { ACTION_STD_CANCEL, BUTTON_MENU, BUTTON_NONE }, + { ACTION_SETTINGS_RESET, BUTTON_SELECT, BUTTON_NONE }, + + { ACTION_SETTINGS_INC, BUTTON_VOLUP, BUTTON_NONE }, + { ACTION_SETTINGS_INCREPEAT,BUTTON_VOLUP|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_SETTINGS_DEC, BUTTON_VOLDOWN, BUTTON_NONE }, + { ACTION_SETTINGS_DECREPEAT,BUTTON_VOLDOWN|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_STD_PREV, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_STD_PREVREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_STD_NEXT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_STD_NEXTREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD), +}; /* button_context_settings */ + +static const struct button_mapping button_context_list[] = { +#ifdef HAVE_VOLUME_IN_LIST + { ACTION_LIST_VOLUP, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_LIST_VOLUP, BUTTON_VOL_UP, BUTTON_NONE }, + + { ACTION_LIST_VOLDOWN, BUTTON_VOL_DOWN, BUTTON_NONE }, + { ACTION_LIST_VOLDOWN, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, +#endif + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) +}; /* button_context_list */ + +static const struct button_mapping button_context_tree[] = { + // { ACTION_TREE_WPS, BUTTON_REC|BUTTON_VOLUP, BUTTON_REC }, + // { ACTION_TREE_STOP, BUTTON_REC|BUTTON_VOLUP|BUTTON_REPEAT, BUTTON_REC|BUTTON_VOLUP }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST), +}; /* button_context_tree */ + +static const struct button_mapping button_context_listtree_scroll_without_combo[] = { + { ACTION_NONE, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_STD_CANCEL, BUTTON_LEFT|BUTTON_REL, BUTTON_LEFT }, + { ACTION_TREE_ROOT_INIT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_LEFT }, + { ACTION_TREE_PGLEFT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_TREE_PGLEFT, BUTTON_LEFT|BUTTON_REL, BUTTON_LEFT|BUTTON_REPEAT }, + + { ACTION_NONE, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_STD_OK, BUTTON_RIGHT|BUTTON_REL, BUTTON_RIGHT }, + { ACTION_TREE_PGRIGHT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_TREE_PGRIGHT, BUTTON_RIGHT|BUTTON_REL, BUTTON_RIGHT|BUTTON_REPEAT }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_TREE), +}; /* button_context_listtree_scroll_without_combo */ + +static const struct button_mapping button_context_listtree_scroll_with_combo[] = { + { ACTION_TREE_ROOT_INIT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + +// { ACTION_TREE_PGLEFT, BUTTON_REC|BUTTON_LEFT, BUTTON_REC }, +// { ACTION_TREE_PGLEFT, BUTTON_REC|BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + +// { ACTION_TREE_PGRIGHT, BUTTON_REC|BUTTON_RIGHT, BUTTON_REC }, +// { ACTION_TREE_PGRIGHT, BUTTON_REC|BUTTON_RIGHT|BUTTON_REPEAT,BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_TREE), +}; /* button_context_listtree_scroll_with_combo */ + +static const struct button_mapping button_context_yesno[] = { + { ACTION_YESNO_ACCEPT, BUTTON_SELECT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD), +}; /* button_context_settings_yesno */ + +static const struct button_mapping button_context_quickscreen[] = { + { ACTION_NONE, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_STD_CANCEL, BUTTON_MENU|BUTTON_REL, BUTTON_NONE }, + + { ACTION_QS_DOWNINV, BUTTON_VOLUP|BUTTON_REL, BUTTON_NONE }, + { ACTION_QS_DOWNINV, BUTTON_VOLUP|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_QS_DOWN, BUTTON_VOLDOWN|BUTTON_REL, BUTTON_NONE }, + { ACTION_QS_DOWN, BUTTON_VOLDOWN|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_QS_LEFT, BUTTON_LEFT|BUTTON_REL, BUTTON_NONE }, + { ACTION_QS_LEFT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_QS_RIGHT, BUTTON_RIGHT|BUTTON_REL, BUTTON_NONE }, + { ACTION_QS_RIGHT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD), +}; /* button_context_quickscreen */ + +static const struct button_mapping button_context_settings_right_is_inc[] = { + { ACTION_SETTINGS_INC, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_SETTINGS_INCREPEAT,BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_SETTINGS_DEC, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_SETTINGS_DECREPEAT,BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_STD_CANCEL, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD), +}; /* button_context_settings_right_is_inc */ + +static const struct button_mapping button_context_pitchscreen[] = { + { ACTION_PS_INC_SMALL, BUTTON_VOLUP, BUTTON_NONE }, + { ACTION_PS_INC_BIG, BUTTON_VOLUP|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_PS_DEC_SMALL, BUTTON_VOLDOWN, BUTTON_NONE }, + { ACTION_PS_DEC_BIG, BUTTON_VOLDOWN|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_PS_NUDGE_LEFT, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_PS_NUDGE_LEFTOFF, BUTTON_LEFT|BUTTON_REL, BUTTON_NONE }, + + { ACTION_PS_NUDGE_RIGHT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_PS_NUDGE_RIGHTOFF, BUTTON_RIGHT|BUTTON_REL, BUTTON_NONE }, + + { ACTION_PS_RESET, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_PS_EXIT, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD), +}; /* button_context_pitchscreen */ + +/** Recording Screen **/ +#ifdef HAVE_RECORDING +static const struct button_mapping button_context_recscreen[] = { + { ACTION_STD_MENU, BUTTON_MENU|BUTTON_REL, BUTTON_MENU }, + { ACTION_REC_PAUSE, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT }, + { ACTION_STD_CANCEL, BUTTON_MENU|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_REC_NEWFILE, BUTTON_REC|BUTTON_REL, BUTTON_REC }, + + { ACTION_SETTINGS_INC, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_SETTINGS_INCREPEAT,BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_SETTINGS_DEC, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_SETTINGS_DECREPEAT,BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) +}; /* button_context_recscreen */ +#endif + +/** FM Radio Screen **/ +#if CONFIG_TUNER +static const struct button_mapping button_context_radio[] = { + { ACTION_NONE, BUTTON_VOLUP, BUTTON_NONE }, + { ACTION_FM_MENU, BUTTON_VOLDOWN, BUTTON_NONE }, + { ACTION_FM_PRESET, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_FM_STOP, BUTTON_VOLUP|BUTTON_REPEAT, BUTTON_VOLUP }, + { ACTION_FM_MODE, BUTTON_REC, BUTTON_NONE }, + { ACTION_FM_EXIT, BUTTON_MENU|BUTTON_REL, BUTTON_MENU }, + { ACTION_FM_PLAY, BUTTON_VOLUP|BUTTON_REL, BUTTON_VOLUP }, + { ACTION_SETTINGS_INC, BUTTON_VOL_UP, BUTTON_NONE }, + { ACTION_SETTINGS_INCREPEAT,BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_SETTINGS_DEC, BUTTON_VOL_DOWN, BUTTON_NONE }, + { ACTION_SETTINGS_DECREPEAT,BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_SETTINGS) +}; /* button_context_radio */ +#endif + +static const struct button_mapping button_context_keyboard[] = { + { ACTION_KBD_LEFT, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_KBD_LEFT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_KBD_RIGHT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_KBD_RIGHT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + +// { ACTION_KBD_CURSOR_LEFT, BUTTON_REC|BUTTON_LEFT, BUTTON_NONE }, +// { ACTION_KBD_CURSOR_LEFT, BUTTON_REC|BUTTON_LEFT|BUTTON_REPEAT,BUTTON_NONE }, +// { ACTION_KBD_CURSOR_RIGHT, BUTTON_REC|BUTTON_RIGHT, BUTTON_NONE }, +// { ACTION_KBD_CURSOR_RIGHT, BUTTON_REC|BUTTON_RIGHT|BUTTON_REPEAT,BUTTON_NONE }, + + { ACTION_KBD_UP, BUTTON_VOLUP, BUTTON_NONE }, + { ACTION_KBD_UP, BUTTON_VOLUP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_KBD_DOWN, BUTTON_VOLDOWN, BUTTON_NONE }, + { ACTION_KBD_DOWN, BUTTON_VOLDOWN|BUTTON_REPEAT, BUTTON_NONE }, + +// { ACTION_KBD_BACKSPACE, BUTTON_REC|BUTTON_VOLDOWN, BUTTON_NONE }, +// { ACTION_KBD_BACKSPACE, BUTTON_REC|BUTTON_VOLDOWN|BUTTON_REPEAT,BUTTON_NONE }, + +// { ACTION_KBD_PAGE_FLIP, BUTTON_REC|BUTTON_SELECT, BUTTON_REC }, + + { ACTION_KBD_SELECT, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_KBD_DONE, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT }, + { ACTION_KBD_ABORT, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_keyboard */ + +static const struct button_mapping button_context_bmark[] = { +// { ACTION_BMS_DELETE, BUTTON_REC, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST), +}; /* button_context_bmark */ + +/* get_context_mapping returns a pointer to one of the above defined arrays depending on the context */ +const struct button_mapping* get_context_mapping(int context) +{ + switch (context) + { + case CONTEXT_STD: + return button_context_standard; + + case CONTEXT_WPS: + return button_context_wps; + + case CONTEXT_LIST: + return button_context_list; + case CONTEXT_TREE: + case CONTEXT_MAINMENU: + if (global_settings.hold_lr_for_scroll_in_list) + return button_context_listtree_scroll_without_combo; + else + return button_context_listtree_scroll_with_combo; + case CONTEXT_CUSTOM|CONTEXT_TREE: + return button_context_tree; + + case CONTEXT_SETTINGS: + case CONTEXT_SETTINGS_TIME: + return button_context_settings; + case CONTEXT_CUSTOM|CONTEXT_SETTINGS: + case CONTEXT_SETTINGS_COLOURCHOOSER: + case CONTEXT_SETTINGS_EQ: + return button_context_settings_right_is_inc; + + case CONTEXT_YESNOSCREEN: + return button_context_yesno; +#if CONFIG_TUNER + case CONTEXT_FM: + return button_context_radio; +#endif + case CONTEXT_BOOKMARKSCREEN: + return button_context_bmark; + case CONTEXT_QUICKSCREEN: + return button_context_quickscreen; + case CONTEXT_PITCHSCREEN: + return button_context_pitchscreen; +#ifdef HAVE_RECORDING + case CONTEXT_RECSCREEN: + return button_context_recscreen; +#endif + case CONTEXT_KEYBOARD: + return button_context_keyboard; + + default: + return button_context_standard; + } + return button_context_standard; +} diff --git a/bootloader/telechips.c b/bootloader/telechips.c index 666657565d..7563a18632 100644 --- a/bootloader/telechips.c +++ b/bootloader/telechips.c @@ -53,6 +53,64 @@ extern int line; #define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */ +/* The following function is just test/development code */ +#ifdef CPU_TCC77X +void show_debug_screen(void) +{ + int button; + int power_count = 0; + int count = 0; + bool do_power_off = false; + + lcd_puts_scroll(0,0,"this is a very long line to test scrolling"); + while(!do_power_off) { + line = 1; + button = button_get(false); + + /* Power-off if POWER button has been held for a long time + This loop is currently running at about 100 iterations/second + */ + if (button & POWEROFF_BUTTON) { + power_count++; + if (power_count > 200) + do_power_off = true; + } else { + power_count = 0; + } + + printf("Btn: 0x%08x",button); + printf("Tick: %d",current_tick); + + printf("GPIOA: 0x%08x",GPIOA); + printf("GPIOB: 0x%08x",GPIOB); + printf("GPIOC: 0x%08x",GPIOC); + printf("GPIOD: 0x%08x",GPIOD); +// printf("GPIOE: 0x%08x",GPIOE); + +#if 0 + int i; + for (i = 0; i<4; i++) + { + printf("ADC%d: 0x%04x",i,adc_read(i)); + } +#endif + count++; + printf("Count: %d",count); + sleep(HZ/10); + + } + + lcd_clear_display(); + line = 0; + printf("POWER-OFF"); + + /* Power-off */ + power_off(); + + printf("(NOT) POWERED OFF"); + while (true); +} +#else /* !CPU_TCC77X */ void show_debug_screen(void) { int button; @@ -100,7 +158,7 @@ void show_debug_screen(void) printf("(NOT) POWERED OFF"); while (true); } - +#endif void* main(void) { @@ -111,6 +169,11 @@ void* main(void) power_init(); system_init(); +#ifndef COWON_D2 + /* The D2 doesn't enable threading or interrupts */ + kernel_init(); + enable_irq(); +#endif lcd_init(); adc_init(); diff --git a/firmware/SOURCES b/firmware/SOURCES index 367e8c146b..5a82cd3216 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -151,6 +151,8 @@ drivers/rtc/rtc_rx5x348ab.c drivers/rtc/rtc_mr100.c #elif (CONFIG_RTC == RTC_MC13783) drivers/rtc/rtc_mc13783.c +#elif (CONFIG_RTC == RTC_TCC77X) +drivers/rtc/rtc_tcc77x.c #endif /* (CONFIG_RTC == RTC_) */ #endif /* SIMULATOR */ @@ -316,7 +318,7 @@ target/arm/ffs-arm.S target/arm/i2c-pp.c #elif CONFIG_I2C == I2C_PNX0101 target/arm/pnx0101/i2c-pnx0101.c -#elif CONFIG_I2C == I2C_TCC780X +#elif CONFIG_I2C == I2C_TCC780X || CONFIG_I2C == I2C_TCC77X target/arm/i2c-telechips.c #elif CONFIG_I2C == I2C_S3C2440 /* no i2c driver yet */ @@ -919,10 +921,37 @@ target/arm/pnx0101/pcm-pnx0101.c #ifndef SIMULATOR target/arm/tcc77x/adc-tcc77x.c target/arm/tcc77x/ata-nand-tcc77x.c -target/arm/tcc77x/system-tcc77x.c +target/arm/tcc77x/kernel-tcc77x.c target/arm/tcc77x/lcd-ssd1815.c +target/arm/tcc77x/powermgmt-tcc77x.c +target/arm/tcc77x/system-tcc77x.c +target/arm/tcc77x/timer-tcc77x.c +target/arm/tcc77x/usb-tcc77x.c target/arm/tcc77x/logikdax/button-logikdax.c target/arm/tcc77x/logikdax/power-logikdax.c +#ifndef BOOTLOADER +target/arm/tcc77x/debug-tcc77x.c +target/arm/tcc77x/pcm-tcc77x.c +#endif /* BOOTLOADER */ +#endif /* SIMULATOR */ +#endif /* LOGIK_DAX */ + +#ifdef SANSA_M200 +#ifndef SIMULATOR +target/arm/tcc77x/adc-tcc77x.c +target/arm/tcc77x/ata-nand-tcc77x.c +target/arm/tcc77x/kernel-tcc77x.c +target/arm/tcc77x/lcd-ssd1815.c +target/arm/tcc77x/powermgmt-tcc77x.c +target/arm/tcc77x/system-tcc77x.c +target/arm/tcc77x/timer-tcc77x.c +target/arm/tcc77x/usb-tcc77x.c +target/arm/tcc77x/m200/button-m200.c +target/arm/tcc77x/m200/power-m200.c +#ifndef BOOTLOADER +target/arm/tcc77x/debug-tcc77x.c +target/arm/tcc77x/pcm-tcc77x.c +#endif /* BOOTLOADER */ #endif /* SIMULATOR */ #endif /* LOGIK_DAX */ diff --git a/firmware/drivers/audio/tlv320.c b/firmware/drivers/audio/tlv320.c index c0f37302fc..6a22ab1c74 100644 --- a/firmware/drivers/audio/tlv320.c +++ b/firmware/drivers/audio/tlv320.c @@ -21,7 +21,9 @@ #include "string.h" #include "audio.h" +#ifdef CPU_COLDFIRE #include "i2c-coldfire.h" +#endif #include "audiohw.h" const struct sound_settings_info audiohw_settings[] = { @@ -73,7 +75,11 @@ static void tlv320_write_reg(unsigned reg, unsigned value) data[0] = (reg << 1) | ((value >> 8) & 1); data[1] = value; +#ifdef CPU_COLDFIRE if (i2c_write(I2C_IFACE_0, TLV320_ADDR, data, 2) != 2) +#else + #warning Implement tlv320_write_reg() +#endif { logf("tlv320 error reg=0x%x", reg); return; diff --git a/firmware/drivers/rtc/rtc_tcc77x.c b/firmware/drivers/rtc/rtc_tcc77x.c new file mode 100644 index 0000000000..140adbc27b --- /dev/null +++ b/firmware/drivers/rtc/rtc_tcc77x.c @@ -0,0 +1,75 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Dave Chapman + * + * 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 "config.h" +#include "rtc.h" +#include "system.h" +#include + +void rtc_init(void) +{ +} + +int rtc_read_datetime(unsigned char* buf) +{ + +} + +int rtc_write_datetime(unsigned char* buf) +{ + return 1; +} + +/** + * Checks to see if an alarm interrupt has triggered since last we checked. + */ +bool rtc_check_alarm_flag(void) +{ + +} + +/** + * Enables or disables the alarm. + */ +bool rtc_enable_alarm(bool enable) +{ +} + +/** + * Check if alarm caused unit to start. + */ +bool rtc_check_alarm_started(bool release_alarm) +{ +} + +void rtc_set_alarm(int h, int m) +{ + /* Convert to BCD */ +// pcf50605_write(0x12, ((m/10) << 4) | m%10); +// pcf50605_write(0x13, ((h/10) << 4) | h%10); +} + +void rtc_get_alarm(int *h, int *m) +{ + char buf[2]; + + /* Convert from BCD */ +// *m = ((buf[0] >> 4) & 0x7)*10 + (buf[0] & 0x0f); +// *h = ((buf[1] >> 4) & 0x3)*10 + (buf[1] & 0x0f); +} + diff --git a/firmware/export/config-logikdax.h b/firmware/export/config-logikdax.h index 8c6509cdaf..175bf7ccdf 100644 --- a/firmware/export/config-logikdax.h +++ b/firmware/export/config-logikdax.h @@ -4,7 +4,7 @@ #define TARGET_TREE /* this target is using the target tree system */ /* For Rolo and boot loader */ -#define MODEL_NUMBER 23 +#define MODEL_NUMBER 27 /* define this if you have recording possibility */ //#define HAVE_RECORDING diff --git a/firmware/export/config-m200.h b/firmware/export/config-m200.h new file mode 100644 index 0000000000..760474d628 --- /dev/null +++ b/firmware/export/config-m200.h @@ -0,0 +1,116 @@ +/* + * This config file is for the Sansa M200 series + */ +#define TARGET_TREE /* this target is using the target tree system */ + +/* For Rolo and boot loader */ +#define MODEL_NUMBER 28 + +/* define this if you have recording possibility */ +//#define HAVE_RECORDING + +/* Define bitmask of input sources - recordable bitmask can be defined + explicitly if different */ +//#define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_LINEIN | SRC_CAP_SPDIF) + +/* define this if you have a bitmap LCD display */ +#define HAVE_LCD_BITMAP + +/* define this if you can flip your LCD */ +#define HAVE_LCD_FLIP + +/* define this if you can invert the colours on your LCD */ +#define HAVE_LCD_INVERT + +/* define this if you have access to the quickscreen */ +#define HAVE_QUICKSCREEN +/* define this if you have access to the pitchscreen */ +#define HAVE_PITCHSCREEN + +/* define this if you would like tagcache to build on this target */ +#define HAVE_TAGCACHE + +/* define this if you have a flash memory storage */ +#define HAVE_FLASH_STORAGE + +/* LCD dimensions */ +#define LCD_WIDTH 128 +#define LCD_HEIGHT 64 +#define LCD_DEPTH 1 + +#define LCD_PIXELFORMAT VERTICAL_PACKING + +/* define this to indicate your device's keypad */ +#define CONFIG_KEYPAD SANSA_M200_PAD + +/* define this if you have a real-time clock */ +#define CONFIG_RTC RTC_TCC77X + +/* define this if you have RTC RAM available for settings */ +//#define HAVE_RTC_RAM + +/* Define this if you have a software controlled poweroff */ +#define HAVE_SW_POWEROFF + +/* The number of bytes reserved for loadable plugins */ +#define PLUGIN_BUFFER_SIZE 0x8000 + +#define AB_REPEAT_ENABLE 1 + +/* Define this if you do software codec */ +#define CONFIG_CODEC SWCODEC + +/* Define this if you have the TLV320 audio codec */ +#define HAVE_TLV320 + +/* TLV320 has no tone controls, so we use the software ones */ +#define HAVE_SW_TONE_CONTROLS + +/* Define this for LCD backlight available */ +#define HAVE_BACKLIGHT + +#define CONFIG_I2C I2C_TCC77X + +#define BATTERY_CAPACITY_DEFAULT 1500 /* default battery capacity */ +#define BATTERY_CAPACITY_MIN 1500 /* min. capacity selectable */ +#define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable */ +#define BATTERY_CAPACITY_INC 50 /* capacity increment */ +#define BATTERY_TYPES_COUNT 1 /* only one type */ + +/* define this if the unit should not shut down on low battery. */ +#define NO_LOW_BATTERY_SHUTDOWN + +#ifndef SIMULATOR + +/* Define this if you have a TCC773L */ +#define CONFIG_CPU TCC773L + +/* Define this if you have ATA power-off control */ +#define HAVE_ATA_POWER_OFF + +/* Define this to the CPU frequency */ +#define CPU_FREQ 120000000 + +/* Offset ( in the firmware file's header ) to the file length */ +#define FIRMWARE_OFFSET_FILE_LENGTH 0 + +/* Offset ( in the firmware file's header ) to the file CRC */ +#define FIRMWARE_OFFSET_FILE_CRC 4 + +/* Offset ( in the firmware file's header ) to the real data */ +#define FIRMWARE_OFFSET_FILE_DATA 6 + +/* The start address index for ROM builds */ +/* #define ROM_START 0x11010 for behind original Archos */ +#define ROM_START 0x7010 /* for behind BootBox */ + +/* Software controlled LED */ +#define CONFIG_LED LED_VIRTUAL + +#define CONFIG_LCD LCD_SSD1815 + +#define BOOTFILE_EXT "m200" +#define BOOTFILE "rockbox." BOOTFILE_EXT +#define BOOTDIR "/" + +#endif /* SIMULATOR */ diff --git a/firmware/export/config.h b/firmware/export/config.h index 565f8950ff..e6b84f9aaa 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -80,6 +80,7 @@ #define COWOND2_PAD 22 #define IAUDIO_M3_PAD 23 #define CREATIVEZVM_PAD 24 +#define SANSA_M200_PAD 25 /* CONFIG_REMOTE_KEYPAD */ #define H100_REMOTE 1 @@ -236,6 +237,8 @@ #include "config-e200.h" #elif defined(SANSA_C200) #include "config-c200.h" +#elif defined(SANSA_M200) +#include "config-m200.h" #elif defined(ELIO_TPJ1022) #include "config-tpj1022.h" #elif defined(MROBE_100) diff --git a/firmware/export/tcc77x.h b/firmware/export/tcc77x.h index 1ab1888649..bde8ca255f 100644 --- a/firmware/export/tcc77x.h +++ b/firmware/export/tcc77x.h @@ -45,7 +45,7 @@ #define CLKCTRL (*(volatile unsigned long *)0x80000400) #define PLL0CFG (*(volatile unsigned long *)0x80000404) -#define CLKDIV0 (*(volatile unsigned long *)0x8000040c) +#define CLKDIVC (*(volatile unsigned long *)0x8000040c) #define MODECTR (*(volatile unsigned long *)0x80000410) #define BCLKCTR (*(volatile unsigned long *)0x80000414) #define SWRESET (*(volatile unsigned long *)0x80000418) @@ -78,4 +78,65 @@ #define CLKCFG (*(volatile unsigned long *)0xf0000020) #define SDCMD (*(volatile unsigned long *)0xf0000024) + +/* IRQ Controller */ + +#define TIMER0_IRQ_MASK (1<<6) + +#define IEN (*(volatile unsigned long *)0x80000100) +#define CREQ (*(volatile unsigned long *)0x80000104) +#define IREQ (*(volatile unsigned long *)0x80000108) +#define IRQSEL (*(volatile unsigned long *)0x8000010c) +#define ICFG (*(volatile unsigned long *)0x80000110) +#define MREQ (*(volatile unsigned long *)0x80000114) +#define TSTREQ (*(volatile unsigned long *)0x80000118) +#define IRQ (*(volatile unsigned long *)0x80000120) +#define FIQ (*(volatile unsigned long *)0x80000124) +#define MIRQ (*(volatile unsigned long *)0x80000128) +#define MFIQ (*(volatile unsigned long *)0x8000012c) +#define TMODE (*(volatile unsigned long *)0x80000130) +#define SYNC (*(volatile unsigned long *)0x80000134) +#define WKUP (*(volatile unsigned long *)0x80000138) + +/* Timer Controller */ + +#define TCFG0 (*(volatile unsigned long *)0x80000200) +#define TCNT0 (*(volatile unsigned long *)0x80000204) +#define TREF0 (*(volatile unsigned long *)0x80000208) +#define TMREF0 (*(volatile unsigned long *)0x8000020c) +#define TCFG1 (*(volatile unsigned long *)0x80000210) +#define TCNT1 (*(volatile unsigned long *)0x80000214) +#define TREF1 (*(volatile unsigned long *)0x80000218) +#define TMREF1 (*(volatile unsigned long *)0x8000021c) +#define TCFG2 (*(volatile unsigned long *)0x80000220) +#define TCNT2 (*(volatile unsigned long *)0x80000224) +#define TREF2 (*(volatile unsigned long *)0x80000228) +#define TMREF2 (*(volatile unsigned long *)0x8000022c) +#define TCFG3 (*(volatile unsigned long *)0x80000230) +#define TCNT3 (*(volatile unsigned long *)0x80000234) +#define TREF3 (*(volatile unsigned long *)0x80000238) +#define TMREF3 (*(volatile unsigned long *)0x8000023c) +#define TCFG4 (*(volatile unsigned long *)0x80000240) +#define TCNT4 (*(volatile unsigned long *)0x80000244) +#define TREF4 (*(volatile unsigned long *)0x80000248) +#define TCFG5 (*(volatile unsigned long *)0x80000250) +#define TCNT5 (*(volatile unsigned long *)0x80000254) +#define TREF5 (*(volatile unsigned long *)0x80000258) +#define TIREQ (*(volatile unsigned long *)0x80000260) +#define TWDCFG (*(volatile unsigned long *)0x80000270) +#define TWDCLR (*(volatile unsigned long *)0x80000274) +#define TC32EN (*(volatile unsigned long *)0x80000280) +#define TC32LDV (*(volatile unsigned long *)0x80000284) +#define TC32CMP0 (*(volatile unsigned long *)0x80000288) +#define TC32CMP1 (*(volatile unsigned long *)0x8000028c) +#define TC32PCNT (*(volatile unsigned long *)0x80000290) +#define TC32MCNT (*(volatile unsigned long *)0x80000294) +#define TC32IRQ (*(volatile unsigned long *)0x80000298) + +/* TIREQ flags */ +#define TF0 (1<<8) /* Timer 0 reference value reached */ +#define TF1 (1<<9) /* Timer 1 reference value reached */ +#define TI0 (1<<0) /* Timer 0 IRQ flag */ +#define TI1 (1<<1) /* Timer 1 IRQ flag */ + #endif diff --git a/firmware/export/timer.h b/firmware/export/timer.h index 08bf7b13e4..3613aa32d9 100644 --- a/firmware/export/timer.h +++ b/firmware/export/timer.h @@ -31,7 +31,8 @@ #define TIMER_FREQ (CPU_FREQ/2) #elif CONFIG_CPU == PNX0101 #define TIMER_FREQ 3000000 -#elif CONFIG_CPU == S3C2440 || CONFIG_CPU == DM320 || CONFIG_CPU == TCC7801 +#elif CONFIG_CPU == S3C2440 || CONFIG_CPU == DM320 || CONFIG_CPU == TCC7801 \ + || defined(CPU_TCC77X) #include "timer-target.h" #elif defined(SIMULATOR) #define TIMER_FREQ 1000000 diff --git a/firmware/target/arm/tcc77x/app.lds b/firmware/target/arm/tcc77x/app.lds new file mode 100644 index 0000000000..03a427f76b --- /dev/null +++ b/firmware/target/arm/tcc77x/app.lds @@ -0,0 +1,144 @@ +#include "config.h" + +ENTRY(start) + +OUTPUT_FORMAT(elf32-littlearm) +OUTPUT_ARCH(arm) +STARTUP(target/arm/tcc77x/crt0.o) + +#define PLUGINSIZE PLUGIN_BUFFER_SIZE +#define CODECSIZE CODEC_SIZE + +#include "imx31l.h" + +#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGINSIZE - CODECSIZE + +#define DRAMORIG 0x20000000 +#define IRAMORIG 0x00000000 +#define IRAMSIZE IRAM_SIZE + +/* End of the audio buffer, where the codec buffer starts */ +#define ENDAUDIOADDR (DRAMORIG + DRAMSIZE) + +/* Where the codec buffer ends, and the plugin buffer starts */ +#define ENDADDR (ENDAUDIOADDR + CODECSIZE) + +MEMORY +{ + DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE + IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE +} + +SECTIONS +{ + .text : + { + loadaddress = .; + _loadaddress = .; + . = ALIGN(0x200); + *(.init.text) + *(.text*) + *(.glue_7) + *(.glue_7t) + . = ALIGN(0x4); + } > DRAM + + .rodata : + { + *(.rodata) /* problems without this, dunno why */ + *(.rodata*) + *(.rodata.str1.1) + *(.rodata.str1.4) + . = ALIGN(0x4); + + /* Pseudo-allocate the copies of the data sections */ + _datacopy = .; + } > DRAM + + /* TRICK ALERT! For RAM execution, we put the .data section at the + same load address as the copy. Thus, we don't waste extra RAM + when we don't actually need the copy. */ + .data : AT ( _datacopy ) + { + _datastart = .; + *(.data*) + . = ALIGN(0x4); + _dataend = .; + } > DRAM + + /DISCARD/ : + { + *(.eh_frame) + } + + .vectors 0x0 : + { + _vectorsstart = .; + *(.vectors); + _vectorsend = .; + } AT> DRAM + + _vectorscopy = LOADADDR(.vectors); + + .iram : + { + _iramstart = .; + *(.icode) + *(.irodata) + *(.idata) + . = ALIGN(0x4); + _iramend = .; + } > DRAM + + _iramcopy = LOADADDR(.iram); + + .ibss (NOLOAD) : + { + _iedata = .; + *(.ibss) + . = ALIGN(0x4); + _iend = .; + } > DRAM + + .stack : + { + *(.stack) + stackbegin = .; + . += 0x2000; + stackend = .; + } > DRAM + + .bss : + { + _edata = .; + *(.bss*) + *(COMMON) + . = ALIGN(0x4); + _end = .; + } > DRAM + + .audiobuf ALIGN(4) : + { + _audiobuffer = .; + audiobuffer = .; + } > DRAM + + .audiobufend ENDAUDIOADDR: + { + audiobufend = .; + _audiobufend = .; + } > DRAM + + .codec ENDAUDIOADDR: + { + codecbuf = .; + _codecbuf = .; + } + + .plugin ENDADDR: + { + _pluginbuf = .; + pluginbuf = .; + } +} + diff --git a/firmware/target/arm/tcc77x/ata-nand-tcc77x.c b/firmware/target/arm/tcc77x/ata-nand-tcc77x.c index dd0ae7a950..d7ae5d5ed6 100644 --- a/firmware/target/arm/tcc77x/ata-nand-tcc77x.c +++ b/firmware/target/arm/tcc77x/ata-nand-tcc77x.c @@ -32,6 +32,9 @@ int ata_spinup_time = 0; long last_disk_activity = -1; +/* Used to store (fake?) identify info */ +static unsigned short identify_info[256]; + /** static, private data **/ static bool initialized = false; @@ -91,4 +94,11 @@ void ata_enable(bool on) int ata_init(void) { + return 0; +} + +/* TEMP: This will return junk, it's here for compilation only */ +unsigned short* ata_get_identify(void) +{ + return identify_info; } diff --git a/firmware/target/arm/tcc77x/boot.lds b/firmware/target/arm/tcc77x/boot.lds index 21fc7db96a..890c4ec785 100644 --- a/firmware/target/arm/tcc77x/boot.lds +++ b/firmware/target/arm/tcc77x/boot.lds @@ -10,16 +10,11 @@ STARTUP(target/arm/tcc77x/crt0.o) #define DRAMORIG 0x20000000 #define IRAMORIG 0x00000000 #define IRAMSIZE 64K -#define FLASHORIG 0x0000000 -#define FLASHSIZE 1M + MEMORY { -#ifdef TCCBOOT DRAM : ORIGIN = DRAMORIG + DRAMSIZE - 0x100000, LENGTH = 0x100000 -#else - DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE -#endif IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE } @@ -52,6 +47,7 @@ SECTIONS _stackend = .; stackend = .; } > DRAM + .bss : { _edata = .; *(.bss*); diff --git a/firmware/target/arm/tcc77x/crt0.S b/firmware/target/arm/tcc77x/crt0.S index e4ecb05a4e..246d02a1d7 100644 --- a/firmware/target/arm/tcc77x/crt0.S +++ b/firmware/target/arm/tcc77x/crt0.S @@ -29,6 +29,11 @@ .section .init.text,"ax",%progbits + .extern irq + .extern fiq + .extern UIE + .extern main + .global start /* Telechips firmware files start with a 32-byte header, as part of the code. */ @@ -44,7 +49,8 @@ start: .word 0 /* Saved entrypoint of original firmware*/ .word 0 /* Location in RAM of the start of our bootloader */ #else - ldr pc, =start_loc /* jump to the main entry point */ +// ldr pc, =start_loc /* jump to the main entry point */ + b start_loc .word 0xffff0601 /* Unknown magic */ .word 0x3a726556 /* "Ver:" */ @@ -65,21 +71,40 @@ start: start_loc: #ifdef BOOTLOADER + +/* + If we are appended to the OF (i.e. dual-booting), do a simple GPIO + button check, and branch to the OF's entry point (saved by mktccboot) + if not active +*/ + #ifdef TCCBOOT -#ifdef LOGIK_DAX mov r0, #0x80000000 - ldr r0, [r0, #0x300] /* Read GPIO A */ +#ifdef LOGIK_DAX + ldr r0, [r0, #0x300] /* Hold button is GPIO A, pin 0x2 */ tst r0, #0x2 - ldrne pc, [pc, #-28] /* Jump to original firmware if HOLD button not pressed */ +#elif defined(SANSA_M200) + ldr r0, [r0, #0x310] /* Hold button is GPIO B, pin 0x200 */ + tst r0, #0x200 #else #error No bootup key detection implemented for this target #endif - /* Copy bootloader to safe area - 0x21000000 (DRAM) */ - /* TODO: Adjust this for other targets - DRAM + DRAMSIZE - 0x100000 */ - ldr r0, [pc, #-28] - mov r1, #0x20000000 - add r1, r1, #0x100000 + ldrne pc, [pc, #-28] /* Jump to OF if HOLD button not pressed */ +#endif /* TCCBOOT */ + +/* We are now definitely executing the bootloader, so we relocate to the + linked address (see boot.lds) - 1MB from the end of DRAM. +*/ + +#ifdef TCCBOOT + ldr r0, [pc, #-28] /* mktccboot fills in the load address */ +#else + mov r0, #0x20000000 /* Otherwise, load address is the start of DRAM */ +#endif + mov r1, #0x20000000 /* Destination: 1MB from end of DRAM */ + add r1, r1, #((MEM - 1) * 0x100000) + ldr r2, =_dataend 1: cmp r2, r1 @@ -88,16 +113,14 @@ start_loc: bhi 1b ldr pc, =copied_start /* jump to the relocated start_loc: */ - copied_start: -#endif -#else - /* We don't use interrupts in the bootloader */ +#endif /* BOOTLOADER */ /* Set up stack for IRQ mode */ mov r0,#0xd2 msr cpsr, r0 ldr sp, =irq_stack + /* Set up stack for FIQ mode */ mov r0,#0xd1 msr cpsr, r0 @@ -110,13 +133,22 @@ copied_start: mov r0,#0xdb msr cpsr, r0 ldr sp, =irq_stack -#endif /* Switch to supervisor mode */ mov r0,#0xd3 msr cpsr, r0 ldr sp, =stackend + /* Copy exception handler code to address 0 */ + mov r2, #0x0 + ldr r3, =vectors_start + ldr r4, =vectors_end +1: + cmp r4, r3 + ldrhi r5, [r3], #4 + strhi r5, [r2], #4 + bhi 1b + /* Initialise bss section to zero */ ldr r2, =_edata ldr r3, =_end @@ -139,9 +171,68 @@ copied_start: bl main /* main() should never return */ -#ifndef BOOTLOADER - /* We don't use interrupts in the bootloader */ +/* Exception handlers. Will be copied to address 0 after memory remapping */ +vectors_start: + ldr pc, [pc, #24] + ldr pc, [pc, #24] + ldr pc, [pc, #24] + ldr pc, [pc, #24] + ldr pc, [pc, #24] + ldr pc, [pc, #24] + ldr pc, [pc, #24] + ldr pc, [pc, #24] + + /* Exception vectors */ + .global vectors +vectors: + .word start + .word undef_instr_handler + .word software_int_handler + .word prefetch_abort_handler + .word data_abort_handler + .word reserved_handler + .word irq_handler + .word fiq_handler +vectors_end: + + .text + +/* All illegal exceptions call into UIE with exception address as first + parameter. This is calculated differently depending on which exception + we're in. Second parameter is exception number, used for a string lookup + in UIE. + */ +undef_instr_handler: + mov r0, lr + mov r1, #0 + b UIE +/* We run supervisor mode most of the time, and should never see a software + exception being thrown. Perhaps make it illegal and call UIE? + */ +software_int_handler: +reserved_handler: + movs pc, lr + +prefetch_abort_handler: + sub r0, lr, #4 + mov r1, #1 + b UIE + +data_abort_handler: + sub r0, lr, #8 + mov r1, #2 + b UIE + +irq_handler: + stmfd sp!, {r0-r3, r12, lr} + bl irq + ldmfd sp!, {r0-r3, r12, lr} + subs pc, lr, #4 + +/* Align stacks to cache line boundary */ + .balign 16 + /* 256 words of IRQ stack */ .space 256*4 irq_stack: @@ -150,4 +241,3 @@ irq_stack: .space 256*4 fiq_stack: -#endif diff --git a/firmware/target/arm/tcc77x/debug-target.h b/firmware/target/arm/tcc77x/debug-target.h new file mode 100644 index 0000000000..07e8fc4322 --- /dev/null +++ b/firmware/target/arm/tcc77x/debug-target.h @@ -0,0 +1,22 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Karl Kurbjun + * + * 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. + * + ****************************************************************************/ + +bool __dbg_hw_info(void); +bool __dbg_ports(void); + diff --git a/firmware/target/arm/tcc77x/debug-tcc77x.c b/firmware/target/arm/tcc77x/debug-tcc77x.c new file mode 100644 index 0000000000..dc3db3926f --- /dev/null +++ b/firmware/target/arm/tcc77x/debug-tcc77x.c @@ -0,0 +1,81 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Rob Purchase + * + * 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 "config.h" +#include "cpu.h" +#include "system.h" +#include "string.h" +#include +#include "button.h" +#include "lcd.h" +#include "sprintf.h" +#include "font.h" +#include "debug-target.h" +#include "adc.h" + +bool __dbg_ports(void) +{ + return false; +} + +bool __dbg_hw_info(void) +{ + int line = 0, i, button, oldline; + bool done=false; + char buf[100]; + + lcd_setmargins(0, 0); + lcd_setfont(FONT_SYSFIXED); + lcd_clear_display(); + + /* Put all the static text before the while loop */ + lcd_puts(0, line++, "[Hardware info]"); + + line++; + oldline=line; + while(!done) + { + line = oldline; + button = button_get(false); + + button &= ~BUTTON_REPEAT; + + if (button == BUTTON_SELECT) + done=true; + + snprintf(buf, sizeof(buf), "current tick: %08x Seconds running: %08d", + (unsigned int)current_tick, (unsigned int)current_tick/100); lcd_puts(0, line++, buf); + + snprintf(buf, sizeof(buf), "GPIOA: 0x%08x GPIOB: 0x%08x", + (unsigned int)GPIOA, (unsigned int)GPIOB); lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "GPIOC: 0x%08x GPIOD: 0x%08x", + (unsigned int)GPIOC, (unsigned int)GPIOD); lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "GPIOE: 0x%08x", + (unsigned int)GPIOE); lcd_puts(0, line++, buf); + + for (i = 0; i<4; i++) + { + snprintf(buf, sizeof(buf), "ADC%d: 0x%04x", i, adc_read(i)); + lcd_puts(0, line++, buf); + } + + lcd_update(); + } + return false; +} diff --git a/firmware/target/arm/tcc77x/i2c-target.h b/firmware/target/arm/tcc77x/i2c-target.h new file mode 100644 index 0000000000..4600b8a576 --- /dev/null +++ b/firmware/target/arm/tcc77x/i2c-target.h @@ -0,0 +1,37 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Rob Purchase + * + * 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 I2C_TARGET_H +#define I2C_TARGET_H + +/* Definitions for the TCC77X I2C bus */ + +#define SDA_BIT (1<<10) +#define SCL_BIT (1<<11) + +#define SCL (GPIOB & SCL_BIT) +#define SCL_HI GPIOB |= SCL_BIT +#define SCL_LO GPIOB &= ~SCL_BIT + +#define SDA (GPIOB & SDA_BIT) +#define SDA_HI GPIOB |= SDA_BIT +#define SDA_LO GPIOB &= ~SDA_BIT +#define SDA_INPUT GPIOB_DIR &= ~SDA_BIT +#define SDA_OUTPUT GPIOB_DIR |= SDA_BIT + +#endif /* I2C_TARGET_H */ diff --git a/firmware/target/arm/tcc77x/kernel-tcc77x.c b/firmware/target/arm/tcc77x/kernel-tcc77x.c new file mode 100644 index 0000000000..17c6ff0734 --- /dev/null +++ b/firmware/target/arm/tcc77x/kernel-tcc77x.c @@ -0,0 +1,45 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2008 by Rob Purchase +* +* 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 "config.h" +#include "system.h" +#include "kernel.h" +#include "timer.h" +#include "thread.h" + +void tick_start(unsigned int interval_in_ms) +{ + /* configure Timer T-Clock to 2Mhz (clock source 4 (Xin) divided by 6) */ + PCLKCFG4 = (1 << 31) | (4 << 28) | (5 << 16); + + /* disable Timer0 */ + TCFG0 &= ~1; + + /* set counter reference value based on 1Mhz tick */ + TREF0 = interval_in_ms * 1000; + + /* Timer0 = reset to 0, divide=2, IRQ enable, enable (continuous) */ + TCFG0 = (1<<8) | (0<<4) | (1<<3) | 1; + + /* Unmask timer IRQ */ + IEN |= TIMER0_IRQ_MASK; +} + +/* NB: Since we are using a single timer IRQ, tick tasks are dispatched as + part of the central timer IRQ processing in timer-tcc77x.c */ diff --git a/firmware/target/arm/tcc77x/lcd-ssd1815.c b/firmware/target/arm/tcc77x/lcd-ssd1815.c index 4101f6ab7d..feb8bf1765 100644 --- a/firmware/target/arm/tcc77x/lcd-ssd1815.c +++ b/firmware/target/arm/tcc77x/lcd-ssd1815.c @@ -208,7 +208,7 @@ void lcd_blit_mono(const unsigned char *data, int x, int by, int width, /* Performance function that works with an external buffer note that by and bheight are in 8-pixel units! */ -void lcd_blit_grey_phase_blit(unsigned char *values, unsigned char *phases, +void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases, int x, int by, int width, int bheight, int stride) { (void)values; diff --git a/firmware/target/arm/tcc77x/m200/adc-target.h b/firmware/target/arm/tcc77x/m200/adc-target.h new file mode 100644 index 0000000000..96fb1e44aa --- /dev/null +++ b/firmware/target/arm/tcc77x/m200/adc-target.h @@ -0,0 +1,26 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 Dave Chapman + * + * 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 _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +#define NUM_ADC_CHANNELS 8 + +#define ADC_BUTTONS 1 + +#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/arm/tcc77x/m200/backlight-target.h b/firmware/target/arm/tcc77x/m200/backlight-target.h new file mode 100644 index 0000000000..a54aa4686d --- /dev/null +++ b/firmware/target/arm/tcc77x/m200/backlight-target.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Dave Chapman + * + * 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 BACKLIGHT_TARGET_H +#define BACKLIGHT_TARGET_H + +#include "tcc77x.h" + +static inline bool _backlight_init(void) +{ + GPIOA_DIR |= 0x40; + return true; +} + +static inline void _backlight_on(void) +{ + /* Enable backlight */ + GPIOA |= 0x40; +} + +static inline void _backlight_off(void) +{ + /* Disable backlight */ + GPIOA &= ~0x40; +} + +#endif diff --git a/firmware/target/arm/tcc77x/m200/button-m200.c b/firmware/target/arm/tcc77x/m200/button-m200.c new file mode 100644 index 0000000000..fec745ae99 --- /dev/null +++ b/firmware/target/arm/tcc77x/m200/button-m200.c @@ -0,0 +1,97 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Dave Chapman + * + * 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 "config.h" +#include "cpu.h" +#include "button.h" +#include "adc.h" + +/* + +Results of button testing (viewing ADC values whilst pressing buttons): + +HOLD: GPIOB & 0x0200 (0=hold active, 0x0200 = hold inactive) + +ADC[1]: (approx values) + +Idle - 0x3ff +MENU - unknown + +REPEAT/AB - 0x03? +LEFT - 0x07?-0x08? +SELECT - 0x0c? +RIGHT - 0x11? + +PLAY/PAUSE - 0x17?-0x018? +VOL UP - 0x1e?-0x01f? +VOL DOWN - 0x26? + +*/ + +void button_init_device(void) +{ + /* Nothing to do */ +} + +int button_read_device(void) +{ + int btn = BUTTON_NONE; + int adc; + + /* TODO - determine how to detect BUTTON_MENU - it doesn't appear to + be connected to a GPIO or to an ADC + */ + + adc = adc_read(ADC_BUTTONS); + + if (adc < 0x384) { + if (adc < 0x140) { + if (adc < 0x96) { + if (adc < 0x50) { + btn |= BUTTON_REPEATAB; /* 0x00..0x4f */ + } else { + btn |= BUTTON_LEFT; /* 0x50..0x95 */ + } + } else { + if (adc < 0xe0) { + btn |= BUTTON_SELECT; /* 0x96..0xdf */ + } else { + btn |= BUTTON_RIGHT; /* 0xe0..0x13f */ + } + } + } else { + if (adc < 0x208) { + if (adc < 0x1b0) { + btn |= BUTTON_PLAYPAUSE; /* 0x140..0x1af */ + } else { + btn |= BUTTON_VOLUP; /* 0x1b0..0x207 */ + } + } else { + btn |= BUTTON_VOLDOWN; /* 0x209..0x383 */ + } + } + } + + return btn; +} + +bool button_hold(void) +{ + return (GPIOB & 0x200)?false:true; +} diff --git a/firmware/target/arm/tcc77x/m200/button-target.h b/firmware/target/arm/tcc77x/m200/button-target.h new file mode 100644 index 0000000000..da7c82e6b2 --- /dev/null +++ b/firmware/target/arm/tcc77x/m200/button-target.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Dave Chapman + * + * 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 _BUTTON_TARGET_H_ +#define _BUTTON_TARGET_H_ + +#include +#include "config.h" + +#define HAS_BUTTON_HOLD + +void button_init_device(void); +int button_read_device(void); +bool button_hold(void); + +/* Main unit's buttons */ +#define BUTTON_MENU 0x00000001 +#define BUTTON_VOLUP 0x00000002 +#define BUTTON_VOLDOWN 0x00000004 +#define BUTTON_PLAYPAUSE 0x00000008 +#define BUTTON_REPEATAB 0x00000010 +#define BUTTON_LEFT 0x00000020 +#define BUTTON_RIGHT 0x00000040 +#define BUTTON_SELECT 0x00000080 + +#define BUTTON_MAIN (BUTTON_MENU|BUTTON_VOLUP|BUTTON_VOLDOWN\ + |BUTTON_PLAYPAUSE|BUTTON_REPEATAB|BUTTON_LEFT\ + |BUTTON_RIGHT|BUTTON_SELECT) + +#define BUTTON_REMOTE 0 + +/* Software power-off */ +#define POWEROFF_BUTTON BUTTON_MENU +#define POWEROFF_COUNT 40 + +#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/arm/tcc77x/m200/power-m200.c b/firmware/target/arm/tcc77x/m200/power-m200.c new file mode 100644 index 0000000000..df2ee10d6b --- /dev/null +++ b/firmware/target/arm/tcc77x/m200/power-m200.c @@ -0,0 +1,66 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 Dave Chapman + * + * 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 "config.h" +#include "cpu.h" +#include +#include "kernel.h" +#include "system.h" +#include "power.h" + +#ifndef SIMULATOR + +void power_init(void) +{ +} + +void ide_power_enable(bool on) +{ +} + +bool ide_powered(void) +{ + return true; +} + +void power_off(void) +{ +} + +#else /* SIMULATOR */ + +bool charger_inserted(void) +{ + return false; +} + +void charger_enable(bool on) +{ + (void)on; +} + +void power_off(void) +{ +} + +void ide_power_enable(bool on) +{ + (void)on; +} + +#endif /* SIMULATOR */ diff --git a/firmware/target/arm/tcc77x/pcm-tcc77x.c b/firmware/target/arm/tcc77x/pcm-tcc77x.c new file mode 100644 index 0000000000..953f550612 --- /dev/null +++ b/firmware/target/arm/tcc77x/pcm-tcc77x.c @@ -0,0 +1,75 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by [whoever fills in these functions] + * + * 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 "system.h" +#include "kernel.h" +#include "logf.h" +#include "audio.h" +#include "sound.h" +#include "file.h" + +void pcm_postinit(void) +{ +} + +const void * pcm_play_dma_get_peak_buffer(int *count) +{ + (void)count; + return 0; +} + +void pcm_play_dma_init(void) +{ +} + +void pcm_apply_settings(void) +{ +} + +void pcm_set_frequency(unsigned int frequency) +{ + (void)frequency; +} + +void pcm_play_dma_start(const void *addr, size_t size) +{ + (void)addr; + (void)size; +} + +void pcm_play_dma_stop(void) +{ +} + +void pcm_play_lock(void) +{ +} + +void pcm_play_unlock(void) +{ +} + +void pcm_play_dma_pause(bool pause) +{ + (void)pause; +} + +size_t pcm_get_bytes_waiting(void) +{ + return 0; +} diff --git a/firmware/target/arm/tcc77x/powermgmt-tcc77x.c b/firmware/target/arm/tcc77x/powermgmt-tcc77x.c new file mode 100644 index 0000000000..20172c00ce --- /dev/null +++ b/firmware/target/arm/tcc77x/powermgmt-tcc77x.c @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Karl Kurbjun + * + * 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 "config.h" +#include "adc.h" +#include "powermgmt.h" +#include "kernel.h" +#include "pcf50606.h" + +unsigned short current_voltage = 3910; + +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = +{ + /* FIXME: calibrate value */ + 3380 +}; + +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = +{ + /* FIXME: calibrate value */ + 3300 +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ + /* FIXME: calibrate values. Table is "inherited" from iPod-PCF / H100 */ + { 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4080, 4160 } +}; + +#if CONFIG_CHARGING +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +const unsigned short percent_to_volt_charge[11] = +{ + /* FIXME: calibrate values. Table is "inherited" from iPod-PCF / H100 */ + 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4080, 4160 +}; +#endif /* CONFIG_CHARGING */ + +#define BATTERY_SCALE_FACTOR 6000 +/* full-scale ADC readout (2^10) in millivolt */ + +/* Returns battery voltage from ADC [millivolts] */ +unsigned int battery_adc_voltage(void) +{ + return current_voltage; +} + diff --git a/firmware/target/arm/tcc77x/system-tcc77x.c b/firmware/target/arm/tcc77x/system-tcc77x.c index baa1641c78..7323b0ce55 100644 --- a/firmware/target/arm/tcc77x/system-tcc77x.c +++ b/firmware/target/arm/tcc77x/system-tcc77x.c @@ -21,6 +21,28 @@ #include "system.h" #include "panic.h" +extern void TIMER(void); + +void irq(void) +{ + int irq = IREQ & 0x7fffffff; + CREQ = irq; /* Clears the corresponding IRQ status */ + + if (irq & TIMER0_IRQ_MASK) + { + TIMER(); + } + else + { + panicf("Unhandled IRQ 0x%08X", irq); + } +} + +void fiq_handler(void) +{ + /* TODO */ +} + void system_reboot(void) { } @@ -49,7 +71,7 @@ static void gpio_init(void) GPIOB_DIR = 0x6ffff; GPIOB = 0; GPIOC_FUNC = 1; - GPIOC_DIR = 0x03ffffff; /* mvn r2, 0xfc000000 */ + GPIOC_DIR = 0x03ffffff; /* mvn r2, 0xfc000000 */ GPIOC = 0; } #elif defined(IAUDIO_7) @@ -72,6 +94,11 @@ static void gpio_init(void) GPIOD_DIR = 0x3e3; GPIOE_DIR = 0x88; } +#elif defined(SANSA_M200) +static void gpio_init(void) +{ + /* TODO - Implement for M200 */ +} #endif /* Second function called in the original firmware's startup code - we just @@ -80,14 +107,16 @@ static void clock_init(void) { unsigned int i; + /* STP = 0x1, PW = 0x04 , HLD = 0x0 */ CSCFG3 = (CSCFG3 &~ 0x3fff) | 0x820; + /* XIN=External main, Fcpu=Fsys, BCKDIV=1 (Fbus = Fsys / 2) */ CLKCTRL = (CLKCTRL & ~0xff) | 0x14; if (BMI & 0x20) - PCLKCFG0 = 0xc82d7000; + PCLKCFG0 = 0xc82d7000; /* EN1 = 1, XIN=Ext. main, DIV1 = 0x2d, P1 = 1 */ else - PCLKCFG0 = 0xc8ba7000; + PCLKCFG0 = 0xc8ba7000; /* EN1 = 1, XIN=Ext. main, DIV1 = 0xba, P1 = 1 */ MCFG |= 0x2000; @@ -96,14 +125,20 @@ static void clock_init(void) SDCFG = (SDCFG & ~0x7000) | 0x2000; #endif + /* Disable PLL */ PLL0CFG |= 0x80000000; + /* Enable PLL, M=0xcf, P=0x13. m=M+8, p=P+2, S = 0 + Fout = (215/21)*12MHz = 122857142Hz */ PLL0CFG = 0x0000cf13; i = 8000; while (--i) {}; - CLKDIV0 = 0x81000000; + /* Enable PLL0 */ + CLKDIVC = 0x81000000; + + /* Fsys = PLL0, Fcpu = Fsys, Fbus=Fsys / 2 */ CLKCTRL = 0x80000010; asm volatile ( @@ -112,13 +147,118 @@ static void clock_init(void) ); } +static void cpu_init(void) +{ + /* Memory protection - see page 48 of ARM946 TRM +http://infocenter.arm.com/help/topic/com.arm.doc.ddi0201d/DDI0201D_arm946es_r1p1_trm.pdf + */ + asm volatile ( + /* Region 0 - addr=0, size=4GB, enabled */ + "mov r0, #0x3f \n\t" + "mcr p15, 0, r0, c6, c0, 0 \n\t" + "mcr p15, 0, r0, c6, c0, 1 \n\t" + +#ifdef LOGIK_DAX + /* Address region 1 - addr 0x2fff0000, size=64KB, enabled*/ + "ldr r0, =0x2fff001f \n\t" +#elif defined(IAUDIO_7) + /* Address region 1 - addr 0x20000000, size=8KB, enabled*/ + "mov r0, #0x19 \n\t" + "add r0, r0, #0x20000000 \n\t" +#elif defined(SANSA_M200) + /* Address region 1 - addr 0x20000000, size=256MB, enabled*/ + "mov r0, #0x37 \n\t" + "add r0, r0, #0x20000000 \n\t" +#endif + "mcr p15, 0, r0, c6, c1, 0 \n\t" + "mcr p15, 0, r0, c6, c1, 1 \n\t" + + /* Address region 2 - addr 0x30000000, size=256MB, enabled*/ + "mov r0, #0x37 \n\t" + "add r0, r0, #0x30000000 \n\t" + "mcr p15, 0, r0, c6, c2, 0 \n\t" + "mcr p15, 0, r0, c6, c2, 1 \n\t" + + /* Address region 2 - addr 0x40000000, size=512MB, enabled*/ + "mov r0, #0x39 \n\t" + "add r0, r0, #0x40000000 \n\t" + "mcr p15, 0, r0, c6, c3, 0 \n\t" + "mcr p15, 0, r0, c6, c3, 1 \n\t" + + /* Address region 4 - addr 0x60000000, size=256MB, enabled*/ + "mov r0, #0x37 \n\t" + "add r0, r0, #0x60000000 \n\t" + "mcr p15, 0, r0, c6, c4, 0 \n\t" + "mcr p15, 0, r0, c6, c4, 1 \n\t" + + /* Address region 5 - addr 0x10000000, size=256MB, enabled*/ + "mov r0, #0x37 \n\t" + "add r0, r0, #0x10000000 \n\t" + "mcr p15, 0, r0, c6, c5, 0 \n\t" + "mcr p15, 0, r0, c6, c5, 1 \n\t" + + /* Address region 6 - addr 0x80000000, size=2GB, enabled*/ + "mov r0, #0x37 \n\t" + "add r0, r0, #0x80000006 \n\t" + "mcr p15, 0, r0, c6, c6, 0 \n\t" + "mcr p15, 0, r0, c6, c6, 1 \n\t" + + /* Address region 7 - addr 0x3000f000, size=4KB, enabled*/ + "ldr r0, =0x3000f017 \n\t" + "mcr p15, 0, r0, c6, c7, 0 \n\t" + "mcr p15, 0, r0, c6, c7, 1 \n\t" + + + /* Register 5 - Access Permission Registers */ + + "ldr r0, =0xffff \n\t" + "mcr p15, 0, r0, c5, c0, 0 \n\t" /* write data access permission bits */ + "mcr p15, 0, r0, c5, c0, 1 \n\t" /* write instruction access permission bits */ + + "mov r0, #0xa7 \n\t" + "mcr p15, 0, r0, c3, c0, 0 \n\t" /* set write buffer control register */ + +#ifdef LOGIK_DAX + "mov r0, #0xa5 \n\t" +#elif defined(IAUDIO_7) || defined(SANSA_M200) + "mov r0, #0xa7 \n\t" +#elif + #error NOT DEFINED FOR THIS TARGET! +#endif + "mcr p15, 0, r0, c2, c0, 0 \n\t" + "mcr p15, 0, r0, c2, c0, 1 \n\t" + + "mov r0, #0xa0000006 \n\t" + "mcr p15, 0, r0, c9, c1, 0 \n\t" + + "ldr r1, =0x1107d \n\t" + "mov r0, #0x0 \n\t" + "mcr p15, 0, r0, c7, c5, 0 \n\t" /* Flush instruction cache */ + "mcr p15, 0, r0, c7, c6, 0 \n\t" /* Flush data cache */ + + "mcr p15, 0, r1, c1, c0, 0 \n\t" /* CPU control bits */ + : : : "r0", "r1" + ); +} + + void system_init(void) { - /* TODO: cache init - the original firmwares have cache init code which - is called at the very start of the firmware */ + /* mask all interrupts */ + IEN = 0; + + /* Set all interrupts as IRQ for now - some may need to be FIQ in future */ + IRQSEL = 0xffffffff; + + /* Set master enable bit */ + IEN = 0x80000000; + + cpu_init(); clock_init(); gpio_init(); + + enable_irq(); } int system_memory_guard(int newmode) diff --git a/firmware/target/arm/tcc77x/timer-target.h b/firmware/target/arm/tcc77x/timer-target.h new file mode 100644 index 0000000000..db25df7cd4 --- /dev/null +++ b/firmware/target/arm/tcc77x/timer-target.h @@ -0,0 +1,39 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2007 by Karl Kurbjun +* +* 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 TIMER_TARGET_H +#define TIMER_TARGET_H + +/* timers are based on XIN (12Mhz) */ +#define TIMER_FREQ (12000000) + +bool __timer_set(long cycles, bool set); +bool __timer_register(void); +void __timer_unregister(void); + +#define __TIMER_SET(cycles, set) \ + __timer_set(cycles, set) + +#define __TIMER_REGISTER(reg_prio, unregister_callback, cycles, \ + int_prio, timer_callback) \ + __timer_register() + +#define __TIMER_UNREGISTER(...) \ + __timer_unregister() + +#endif /* TIMER_TARGET_H */ diff --git a/firmware/target/arm/tcc77x/timer-tcc77x.c b/firmware/target/arm/tcc77x/timer-tcc77x.c new file mode 100644 index 0000000000..32010b2d25 --- /dev/null +++ b/firmware/target/arm/tcc77x/timer-tcc77x.c @@ -0,0 +1,79 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2008 by Rob Purchase +* +* 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 "config.h" +#include "cpu.h" +#include "system.h" +#include "timer.h" +#include "logf.h" + +/* Use the TC32 counter [sourced by Xin:12Mhz] for this timer, as it's the + only one that allows a 32-bit counter (Timer0-5 are 16/20 bit only). */ + +bool __timer_set(long cycles, bool start) +{ + #warning function not implemented + + (void)cycles; + (void)start; + return false; +} + +bool __timer_register(void) +{ + #warning function not implemented + + return false; +} + +void __timer_unregister(void) +{ + #warning function not implemented +} + + +/* Timer interrupt processing - all timers (inc. tick) have a single IRQ */ + +extern void (*tick_funcs[MAX_NUM_TICK_TASKS])(void); + +void TIMER(void) +{ + if (TIREQ & TF0) /* Timer0 reached ref value */ + { + int i; + + /* Run through the list of tick tasks */ + for(i = 0; i < MAX_NUM_TICK_TASKS; i++) + { + if(tick_funcs[i]) + { + tick_funcs[i](); + } + } + current_tick++; + + /* reset Timer 0 IRQ & ref flags */ + TIREQ |= TI0 | TF0; + } + + if (TC32IRQ & (1<<3)) /* end of TC32 prescale */ + { + /* dispatch timer */ + } +} diff --git a/firmware/target/arm/tcc77x/usb-tcc77x.c b/firmware/target/arm/tcc77x/usb-tcc77x.c new file mode 100644 index 0000000000..7254b919a7 --- /dev/null +++ b/firmware/target/arm/tcc77x/usb-tcc77x.c @@ -0,0 +1,36 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by [whoever fills in these functions] + * + * 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 "config.h" +#include "usb.h" + +void usb_init_device(void) +{ +} + +void usb_enable(bool on) +{ + (void)on; +} + +/* Always return false for now */ +int usb_detect(void) +{ + return USB_EXTRACTED; +} diff --git a/tools/configure b/tools/configure index 93a0484b6a..1f71c8b51c 100755 --- a/tools/configure +++ b/tools/configure @@ -670,7 +670,7 @@ cat <