diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 5fb62a9..3c6a185 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES @@ -164,3 +164,6 @@ md5sum.c lua.c #endif +test_codec.c +test_disk.c +test_fps.c diff --git a/apps/plugins/plugin.lds b/apps/plugins/plugin.lds index 57b2faf..508f4d2 100644 --- a/apps/plugins/plugin.lds +++ b/apps/plugins/plugin.lds @@ -1,4 +1,5 @@ #include "config.h" +#include "cpu.h" /* These output formats should be in the config-files */ diff --git a/firmware/SOURCES b/firmware/SOURCES index 3ee805e..8007d23 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -372,6 +372,7 @@ target/arm/as3525/usb-as3525.c target/arm/as3525/dma-pl081.c target/arm/as3525/ascodec-as3525.c #ifndef BOOTLOADER +target/arm/mmu-arm.S drivers/generic_i2c.c target/arm/adc-as3514.c target/arm/as3525/audio-as3525.c diff --git a/firmware/export/as3525.h b/firmware/export/as3525.h index 21bf2bd..58973ca 100644 --- a/firmware/export/as3525.h +++ b/firmware/export/as3525.h @@ -40,8 +40,7 @@ #define ECCBYTES 3 /* AS352X MMU Page Table Entries */ -/* to be implemented */ -#define TTB_SIZE 0x0 +#define TTB_SIZE 0x4000 #define TTB_BASE_ADDR (DRAM_ORIG + DRAM_SIZE - TTB_SIZE) @@ -493,4 +492,7 @@ interface */ #define I2SOUT_CLEAR (*(volatile unsigned char*)(I2SOUT_BASE+0x10)) #define I2SOUT_DATA (volatile unsigned long*)(I2SOUT_BASE+0x14) +/* PCM addresses for obtaining buffers will be what DMA is using (physical) */ +#define HAVE_PCM_DMA_ADDRESS + #endif /*__AS3525_H__*/ diff --git a/firmware/target/arm/as3525/ata_sd_as3525.c b/firmware/target/arm/as3525/ata_sd_as3525.c index b3ab31b..d2b6e90 100644 --- a/firmware/target/arm/as3525/ata_sd_as3525.c +++ b/firmware/target/arm/as3525/ata_sd_as3525.c @@ -618,7 +618,8 @@ static int sd_select_bank(signed char bank) } #define UNALIGNED_NUM_SECTORS 10 -static int32_t aligned_buffer[UNALIGNED_NUM_SECTORS* (SECTOR_SIZE / 4)]; +static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS* SECTOR_SIZE] CACHEALIGN_ATTR; +static unsigned char *uncached_buffer = UNCACHED_ADDR(aligned_buffer); static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf, const bool write) @@ -627,7 +628,7 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, const int drive = 0; #endif int ret = 0; - bool unaligned_transfer = (int)buf & 3; + bool unaligned_transfer = true;//(int)buf & 3; /* skip SanDisk OF */ if (drive == INTERNAL_AS3525) @@ -699,7 +700,7 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, if(transfer > UNALIGNED_NUM_SECTORS) transfer = UNALIGNED_NUM_SECTORS; if(write) - memcpy(aligned_buffer, buf, transfer * SECTOR_SIZE); + memcpy(uncached_buffer, buf, transfer * SECTOR_SIZE); } else /* Aligned transfers are faster : no memcpy */ dma_buf = buf; @@ -735,7 +736,7 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, if(!retry) { if(unaligned_transfer && !write) - memcpy(buf, aligned_buffer, transfer * SECTOR_SIZE); + memcpy(buf, uncached_buffer, transfer * SECTOR_SIZE); buf += transfer * SECTOR_SIZE; start += transfer; count -= transfer; diff --git a/firmware/target/arm/as3525/kernel-as3525.c b/firmware/target/arm/as3525/kernel-as3525.c index fd3b219..c96af62 100644 --- a/firmware/target/arm/as3525/kernel-as3525.c +++ b/firmware/target/arm/as3525/kernel-as3525.c @@ -51,6 +51,29 @@ void INT_TIMER2(void) } #endif +void usleep(int us) +{ + const int cycles = (3 * us) >> 1; + /* TIMER_FREQ * us / 1000000 = + * 24000000 / 16 * us / 1000000 = + * 1.5 * us = 3 * us / 2 + */ + int timer_start = TIMER2_VALUE; + while(1) + { + int timer_val = TIMER2_VALUE; + if(timer_val > timer_start) /* timer wrapped */ + timer_start += (TIMER_FREQ / HZ) +#ifdef HAVE_SCROLLWHEEL + >> 1 +#endif + ; + + if(timer_start - timer_val >= cycles) + break; + } +} + void tick_start(unsigned int interval_in_ms) { int phi = 0; /* prescaler bits */ diff --git a/firmware/target/arm/as3525/pcm-as3525.c b/firmware/target/arm/as3525/pcm-as3525.c index 5074941..4f9e185 100644 --- a/firmware/target/arm/as3525/pcm-as3525.c +++ b/firmware/target/arm/as3525/pcm-as3525.c @@ -28,6 +28,7 @@ #include "panic.h" #include "as3514.h" #include "audiohw.h" +#include "mmu-arm.h" #define MAX_TRANSFER (4*((1<<11)-1)) /* maximum data we can transfer via DMA * i.e. 32 bits at once (size of I2SO_DATA) @@ -69,6 +70,7 @@ static void play_start_pcm(void) CGU_PERI |= CGU_I2SOUT_APB_CLOCK_ENABLE; CGU_AUDIO |= (1<<11); + clean_dcache_range((void*)addr, size); /* force write back */ dma_enable_channel(1, (void*)addr, (void*)I2SOUT_DATA, DMA_PERI_I2SOUT, DMAC_FLOWCTRL_DMAC_MEM_TO_PERI, true, false, size >> 2, DMA_S1, dma_callback); @@ -164,6 +166,15 @@ const void * pcm_play_dma_get_peak_buffer(int *count) return (const void*)dma_start_addr; } +#ifdef HAVE_PCM_DMA_ADDRESS +void * pcm_dma_addr(void *addr) +{ + if (addr != NULL) + addr = UNCACHED_ADDR(addr); + return addr; +} +#endif + /**************************************************************************** ** Recording DMA transfer diff --git a/firmware/target/arm/as3525/sansa-clip/button-clip.c b/firmware/target/arm/as3525/sansa-clip/button-clip.c index b6da130..2d2a3a6 100644 --- a/firmware/target/arm/as3525/sansa-clip/button-clip.c +++ b/firmware/target/arm/as3525/sansa-clip/button-clip.c @@ -46,8 +46,9 @@ int button_read_device(void) /* This is a keypad using C4-C6 as columns and B0-B2 as rows */ GPIOC_PIN(4) = (1<<4); + asm volatile("nop\nnop\nnop\nnop\nnop\n"); /* small delay */ - /* C4B0 is unused */ + (void)GPIOB_PIN(0); /* C4B0 is unused */ if (GPIOB_PIN(1)) result |= BUTTON_VOL_UP; @@ -58,6 +59,7 @@ int button_read_device(void) GPIOC_PIN(4) = 0x00; GPIOC_PIN(5) = (1<<5); + asm volatile("nop\nnop\nnop\nnop\nnop\n"); /* small delay */ if (GPIOB_PIN(0)) result |= BUTTON_LEFT; @@ -71,6 +73,7 @@ int button_read_device(void) GPIOC_PIN(5) = 0x00; GPIOC_PIN(6) = (1<<6); + asm volatile("nop\nnop\nnop\nnop\nnop\n"); /* small delay */ if (GPIOB_PIN(0)) result |= BUTTON_DOWN; diff --git a/firmware/target/arm/as3525/system-as3525.c b/firmware/target/arm/as3525/system-as3525.c index 2f320e9..ebfe28c 100644 --- a/firmware/target/arm/as3525/system-as3525.c +++ b/firmware/target/arm/as3525/system-as3525.c @@ -28,6 +28,9 @@ #include "clock-target.h" #include "fmradio_i2c.h" #include "button-target.h" +#ifndef BOOTLOADER +#include "mmu-arm.h" +#endif #define default_interrupt(name) \ extern __attribute__((weak,alias("UIRQ"))) void name (void) @@ -226,6 +229,9 @@ void system_init(void) CCU_SRL = CCU_SRL_MAGIC_NUMBER; CCU_SRC = CCU_SRL = 0; + CCU_SCON = 1; /* AHB master's priority configuration : + TIC (Test Interface Controller) > DMA > USB > IDE > ARM */ + CGU_PROC = 0; /* fclk 24 MHz */ CGU_PERI &= ~0x7f; /* pclk 24 MHz */ @@ -244,15 +250,22 @@ void system_init(void) asm volatile( "mov r0, #0 \n" - "mcr p15, 0, r0, c7, c7 \n" /* invalidate icache & dcache */ "mrc p15, 0, r0, c1, c0 \n" /* control register */ - "bic r0, r0, #3<<30 \n" /* clears bus bits & sets fastbus */ - "orr r0, r0, #1<<12 \n" /* enable icache */ + "bic r0, r0, #3<<30 \n" /* clears bus bits : sets fastbus */ "mcr p15, 0, r0, c1, c0 \n" : : : "r0" ); #ifdef BOOTLOADER sdram_init(); +#else + ttb_init(); + + map_section(0, 0, 4096, CACHE_NONE); + map_section(0, 0, 1, CACHE_ALL); /* IRAM */ + map_section(0, 0x10000000, 1, CACHE_NONE); /* IRAM */ + map_section(0x30000000, 0x30000000, MEMORYSIZE, CACHE_ALL); /* sdram */ + map_section(0x30000000, 0x40000000, MEMORYSIZE, CACHE_NONE); /* sdram */ + enable_mmu(); #endif /* BOOTLOADER */ #if 0 /* the GPIO clock is already enabled by the dualboot function */ diff --git a/firmware/target/arm/as3525/system-target.h b/firmware/target/arm/as3525/system-target.h index 713e96c..8639162 100644 --- a/firmware/target/arm/as3525/system-target.h +++ b/firmware/target/arm/as3525/system-target.h @@ -25,4 +25,13 @@ #include "clock-target.h" /* CPUFREQ_* are defined here */ +#define PROC_NEEDS_CACHEALIGN +#define CACHEALIGN_BITS 5 /* 2^5 = 32 bytes = cacheline size */ + +#ifdef BOOTLOADER +#define UNCACHED_ADDR(a) (a) +#else +#define UNCACHED_ADDR(a) (a + 0x10000000) +#endif + #endif /* SYSTEM_TARGET_H */