2003-02-07 09:41:57 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* 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__
|
|
|
|
|
2004-10-06 13:49:48 +00:00
|
|
|
#include "cpu.h"
|
2003-02-07 09:41:57 +00:00
|
|
|
#include "config.h"
|
2005-03-01 14:35:10 +00:00
|
|
|
#include "stdbool.h"
|
2003-02-07 09:41:57 +00:00
|
|
|
|
2004-02-25 13:00:36 +00:00
|
|
|
extern void system_reboot (void);
|
|
|
|
extern void system_init(void);
|
|
|
|
|
2005-03-01 14:35:10 +00:00
|
|
|
extern long cpu_frequency;
|
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
#define FREQ cpu_frequency
|
2005-03-03 16:29:02 +00:00
|
|
|
void set_cpu_frequency(long frequency);
|
|
|
|
void cpu_boost(bool on_off);
|
2005-03-01 14:35:10 +00:00
|
|
|
#else
|
2003-02-07 09:41:57 +00:00
|
|
|
#define FREQ CPU_FREQ
|
2005-03-01 14:35:10 +00:00
|
|
|
#endif
|
2005-03-03 16:29:02 +00:00
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
#define BAUDRATE 9600
|
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#define NULL ((void*)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a, b) (((a)<(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(a, b) (((a)>(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LITTLE_ENDIAN
|
|
|
|
#define SWAB16(x) (x)
|
|
|
|
#define SWAB32(x) (x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define nop \
|
|
|
|
asm volatile ("nop")
|
|
|
|
|
2004-07-24 11:39:17 +00:00
|
|
|
/* gcc 3.4 changed the format of the constraints */
|
2005-04-22 19:34:01 +00:00
|
|
|
#if (__GNUC__ >= 3) && (__GNUC_MINOR__ > 3) || (__GNUC__ >= 4)
|
2004-07-24 11:39:17 +00:00
|
|
|
#define I_CONSTRAINT "I08"
|
|
|
|
#else
|
|
|
|
#define I_CONSTRAINT "I"
|
|
|
|
#endif
|
|
|
|
|
2005-02-02 21:45:56 +00:00
|
|
|
/* Utilize the user break controller to catch invalid memory accesses. */
|
|
|
|
int system_memory_guard(int newmode);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
MEMGUARD_KEEP = -1, /* don't change the mode; for reading */
|
|
|
|
MEMGUARD_NONE = 0, /* catch nothing */
|
|
|
|
MEMGUARD_FLASH_WRITES, /* catch writes to area 02 (flash ROM) */
|
|
|
|
MEMGUARD_ZERO_AREA, /* catch all accesses to areas 00 and 01 */
|
|
|
|
MAXMEMGUARD
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-10-15 11:32:58 +00:00
|
|
|
#if CONFIG_CPU == SH7034
|
2003-11-07 12:15:24 +00:00
|
|
|
#define or_b(mask, address) \
|
2003-02-07 09:41:57 +00:00
|
|
|
asm \
|
|
|
|
("or.b\t%0,@(r0,gbr)" \
|
|
|
|
: \
|
2004-07-24 11:39:17 +00:00
|
|
|
: /* %0 */ I_CONSTRAINT((char)(mask)), \
|
2003-02-07 09:41:57 +00:00
|
|
|
/* %1 */ "z"(address-GBR))
|
|
|
|
|
2003-11-07 12:15:24 +00:00
|
|
|
#define and_b(mask, address) \
|
2003-02-07 09:41:57 +00:00
|
|
|
asm \
|
|
|
|
("and.b\t%0,@(r0,gbr)" \
|
|
|
|
: \
|
2004-07-24 11:39:17 +00:00
|
|
|
: /* %0 */ I_CONSTRAINT((char)(mask)), \
|
2003-02-07 09:41:57 +00:00
|
|
|
/* %1 */ "z"(address-GBR))
|
|
|
|
|
2003-11-07 12:15:24 +00:00
|
|
|
#define xor_b(mask, address) \
|
2003-02-07 09:41:57 +00:00
|
|
|
asm \
|
|
|
|
("xor.b\t%0,@(r0,gbr)" \
|
|
|
|
: \
|
2004-07-24 11:39:17 +00:00
|
|
|
: /* %0 */ I_CONSTRAINT((char)(mask)), \
|
2003-02-07 09:41:57 +00:00
|
|
|
/* %1 */ "z"(address-GBR))
|
2004-10-15 11:32:58 +00:00
|
|
|
#endif
|
2003-02-07 09:41:57 +00:00
|
|
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
2004-03-02 11:32:59 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* Interrupt level setting
|
|
|
|
* The level is left shifted 4 bits
|
|
|
|
****************************************************************************/
|
2004-10-15 11:32:58 +00:00
|
|
|
#if CONFIG_CPU == SH7034
|
2004-03-02 11:32:59 +00:00
|
|
|
#define HIGHEST_IRQ_LEVEL (15<<4)
|
|
|
|
static inline int set_irq_level(int level)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* Read the old level and set the new one */
|
|
|
|
asm volatile ("stc sr, %0" : "=r" (i));
|
|
|
|
asm volatile ("ldc %0, sr" : : "r" (level));
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2004-10-06 23:16:38 +00:00
|
|
|
static inline unsigned short SWAB16(unsigned short value)
|
2003-02-07 09:41:57 +00:00
|
|
|
/*
|
|
|
|
result[15..8] = value[ 7..0];
|
|
|
|
result[ 7..0] = value[15..8];
|
2005-01-10 22:02:26 +00:00
|
|
|
*/
|
2003-02-07 09:41:57 +00:00
|
|
|
{
|
|
|
|
short result;
|
|
|
|
asm volatile ("swap.b\t%1,%0" : "=r"(result) : "r"(value));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-10-06 23:16:38 +00:00
|
|
|
static inline unsigned long SWAW32(unsigned long value)
|
2003-02-07 09:41:57 +00:00
|
|
|
/*
|
|
|
|
result[31..16] = value[15.. 0];
|
|
|
|
result[15.. 0] = value[31..16];
|
2005-01-10 22:02:26 +00:00
|
|
|
*/
|
2003-02-07 09:41:57 +00:00
|
|
|
{
|
|
|
|
long result;
|
|
|
|
asm volatile ("swap.w\t%1,%0" : "=r"(result) : "r"(value));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-10-06 23:16:38 +00:00
|
|
|
static inline unsigned long SWAB32(unsigned long value)
|
2003-02-07 09:41:57 +00:00
|
|
|
/*
|
|
|
|
result[31..24] = value[ 7.. 0];
|
|
|
|
result[23..16] = value[15.. 8];
|
|
|
|
result[15.. 8] = value[23..16];
|
|
|
|
result[ 7.. 0] = value[31..24];
|
2005-01-10 22:02:26 +00:00
|
|
|
*/
|
2003-02-07 09:41:57 +00:00
|
|
|
{
|
|
|
|
asm volatile ("swap.b\t%0,%0\n"
|
|
|
|
"swap.w\t%0,%0\n"
|
|
|
|
"swap.b\t%0,%0\n" : "+r"(value));
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2005-02-09 14:18:46 +00:00
|
|
|
#define invalidate_icache()
|
|
|
|
|
2004-10-15 11:32:58 +00:00
|
|
|
#elif CONFIG_CPU == MCF5249
|
|
|
|
#define HIGHEST_IRQ_LEVEL (7<<8)
|
|
|
|
static inline int set_irq_level(int level)
|
|
|
|
{
|
2004-10-27 06:49:15 +00:00
|
|
|
int oldlevel;
|
2004-10-15 11:32:58 +00:00
|
|
|
/* Read the old level and set the new one */
|
|
|
|
asm volatile ("move.w %%sr,%0\n"
|
|
|
|
"or.l #0x2000,%1\n"
|
2004-10-27 06:49:15 +00:00
|
|
|
"move.w %1,%%sr\n" : "=r" (oldlevel), "+r" (level) : );
|
|
|
|
return oldlevel;
|
2004-10-15 11:32:58 +00:00
|
|
|
}
|
|
|
|
|
2004-11-19 00:30:28 +00:00
|
|
|
static inline unsigned short SWAB16(unsigned short value)
|
|
|
|
/*
|
|
|
|
result[15..8] = value[ 7..0];
|
|
|
|
result[ 7..0] = value[15..8];
|
2005-01-10 22:02:26 +00:00
|
|
|
*/
|
2004-11-19 00:30:28 +00:00
|
|
|
{
|
|
|
|
return (value >> 8) | (value << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long SWAB32(unsigned long value)
|
|
|
|
/*
|
|
|
|
result[31..24] = value[ 7.. 0];
|
|
|
|
result[23..16] = value[15.. 8];
|
|
|
|
result[15.. 8] = value[23..16];
|
|
|
|
result[ 7.. 0] = value[31..24];
|
2005-01-10 22:02:26 +00:00
|
|
|
*/
|
2004-11-19 00:30:28 +00:00
|
|
|
{
|
|
|
|
unsigned short hi = SWAB16(value >> 16);
|
|
|
|
unsigned short lo = SWAB16(value & 0xffff);
|
|
|
|
return (lo << 16) | hi;
|
|
|
|
}
|
|
|
|
|
2005-02-09 14:18:46 +00:00
|
|
|
static inline void invalidate_icache(void)
|
|
|
|
{
|
2005-02-09 17:56:52 +00:00
|
|
|
asm volatile ("move.l #0x01000000,%d0\n"
|
|
|
|
"movec.l %d0,%cacr\n"
|
|
|
|
"move.l #0x80000000,%d0\n"
|
2005-02-09 14:18:46 +00:00
|
|
|
"movec.l %d0,%cacr");
|
|
|
|
}
|
|
|
|
|
2005-03-01 14:35:10 +00:00
|
|
|
#define CPUFREQ_DEFAULT CPU_FREQ
|
|
|
|
#define CPUFREQ_NORMAL 47980800
|
2005-03-03 21:48:02 +00:00
|
|
|
#define CPUFREQ_MAX 119952000
|
2005-03-01 14:35:10 +00:00
|
|
|
|
2005-01-10 22:02:26 +00:00
|
|
|
#elif CONFIG_CPU == TCC730
|
|
|
|
|
2005-02-19 17:49:58 +00:00
|
|
|
extern int smsc_version(void);
|
|
|
|
|
|
|
|
extern void smsc_delay(void);
|
|
|
|
|
2005-02-15 14:00:21 +00:00
|
|
|
extern void set_pll_freq(int pll_index, long freq_out);
|
|
|
|
|
|
|
|
|
2005-01-24 00:01:37 +00:00
|
|
|
extern void* volatile interrupt_vector[16] __attribute__ ((section(".idata")));
|
2005-01-10 22:02:26 +00:00
|
|
|
|
2005-02-22 09:55:40 +00:00
|
|
|
extern void ddma_transfer(int dir, int mem, void* intAddr, long extAddr,
|
2005-01-10 22:02:26 +00:00
|
|
|
int num);
|
|
|
|
|
|
|
|
|
2005-01-24 00:01:37 +00:00
|
|
|
#define HIGHEST_IRQ_LEVEL (1)
|
2005-01-10 22:02:26 +00:00
|
|
|
static inline int set_irq_level(int level)
|
|
|
|
{
|
2005-01-24 00:01:37 +00:00
|
|
|
int result;
|
|
|
|
__asm__ ("ld %0, 0\n\t"
|
|
|
|
"tstsr ie\n\t"
|
|
|
|
"incc %0" : "=r"(result));
|
|
|
|
if (level > 0)
|
|
|
|
__asm__ volatile ("clrsr ie");
|
|
|
|
else
|
|
|
|
__asm__ volatile ("setsr ie");
|
|
|
|
|
|
|
|
return result;
|
2005-01-10 22:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned short SWAB16(unsigned short value)
|
|
|
|
/*
|
|
|
|
result[15..8] = value[ 7..0];
|
|
|
|
result[ 7..0] = value[15..8];
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
return (value >> 8) | (value << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long SWAB32(unsigned long value)
|
|
|
|
/*
|
|
|
|
result[31..24] = value[ 7.. 0];
|
|
|
|
result[23..16] = value[15.. 8];
|
|
|
|
result[15.. 8] = value[23..16];
|
|
|
|
result[ 7.. 0] = value[31..24];
|
|
|
|
*/
|
|
|
|
{
|
2005-02-28 09:49:48 +00:00
|
|
|
unsigned long hi = SWAB16(value >> 16);
|
2005-01-10 22:02:26 +00:00
|
|
|
unsigned long lo = SWAB16(value & 0xffff);
|
|
|
|
return (lo << 16) | hi;
|
|
|
|
}
|
|
|
|
|
2005-03-03 16:29:02 +00:00
|
|
|
/* Archos uses:
|
|
|
|
|
|
|
|
22MHz: busy wait on dma
|
|
|
|
32MHz: normal
|
|
|
|
80Mhz: heavy load
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CPUFREQ_DEFAULT CPU_FREQ
|
|
|
|
#define CPUFREQ_NORMAL (32000000)
|
|
|
|
#define CPUFREQ_MAX (80000000)
|
|
|
|
|
2005-02-09 14:18:46 +00:00
|
|
|
#define invalidate_icache()
|
|
|
|
|
2004-10-15 11:32:58 +00:00
|
|
|
#endif
|
2005-02-09 14:23:35 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
#define invalidate_icache()
|
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|