/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2008 by Maurus Cuelenaere * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ #include "config.h" #include "jz4740.h" #include "mips.h" #include "mipsregs.h" #include "panic.h" #include "system-target.h" #include #include "kernel.h" void intr_handler(void) { printf("Interrupt!"); return; } void except_handler(void* stack_ptr, unsigned int cause, unsigned int epc) { panicf("Exception occurred: [0x%x] at 0x%x (stack at 0x%x)", cause, epc, (unsigned int)stack_ptr); } static const int FR2n[] = {1, 2, 3, 4, 6, 8, 12, 16, 24, 32}; static unsigned int iclk; static void detect_clock(void) { unsigned int cfcr, pllout; cfcr = REG_CPM_CPCCR; pllout = (__cpm_get_pllm() + 2)* JZ_EXTAL / (__cpm_get_plln() + 2); iclk = pllout / FR2n[__cpm_get_cdiv()]; /*printf("EXTAL_CLK = %dM PLL = %d iclk = %d\r\n",EXTAL_CLK / 1000 /1000,pllout,iclk);*/ } void udelay(unsigned int usec) { unsigned int i = usec * (iclk / 2000000); __asm__ __volatile__ ( ".set noreorder \n" "1: \n" "bne %0, $0, 1b \n" "addi %0, %0, -1 \n" ".set reorder \n" : "=r" (i) : "0" (i) ); } void mdelay(unsigned int msec) { unsigned int i; for(i=0; i>1)) / tps; #else __tcu_select_extalclk(0); __tcu_select_clk_div4(0); latch = (JZ_EXTAL / 4 + (tps>>1)) / tps; #endif REG_TCU_TDFR(0) = latch; REG_TCU_TDHR(0) = latch; __tcu_clear_full_match_flag(0); __tcu_start_counter(0); //printf("TCSR = 0x%04x\r\n",*(volatile u16 *)0xb000204C); } extern int main(void); extern unsigned int _loadaddress; extern unsigned int _resetvectorsstart; extern unsigned int _resetvectorsend; extern unsigned int _vectorsstart; extern unsigned int _vectorsend; /* see boot.lds/app.lds */ void system_main(void) { cli(); write_c0_status(0x10000400); memcpy((void *)A_K0BASE, (void *)&_loadaddress, 0x20); memcpy((void *)(A_K0BASE + 0x180), (void *)&_vectorsstart, 0x20); memcpy((void *)(A_K0BASE + 0x200), (void *)&_vectorsstart, 0x20); __dcache_writeback_all(); __icache_invalidate_all(); sti(); detect_clock(); main(); while(1); } void system_reboot(void) { REG_WDT_TCSR = WDT_TCSR_PRESCALE4 | WDT_TCSR_EXT_EN; REG_WDT_TCNT = 0; REG_WDT_TDR = JZ_EXTAL/1000; /* reset after 4ms */ REG_TCU_TSCR = TCU_TSSR_WDTSC; /* enable wdt clock */ REG_WDT_TCER = WDT_TCER_TCEN; /* wdt start */ while (1); }