update jz47xx branch code.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@902 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com committed 2010-09-12 23:35:14 +00:00
1 parent 81ad360b98
commit 427a00e9b4
13 files changed
+600 -68

No files matched your search

+25
View File
@@ -18,8 +18,33 @@
/*@{*/
#include <rtthread.h>
#include <jz4755.h>
#include <mipsregs.h>
static struct rt_thread thread1;
static rt_uint8_t thread1_stack[1024];
void thread_entry(void* parameter)
{
while (1)
{
rt_kprintf("IPR: 0x%08x, SR : 0x%08x, CAUSE: 0x%08x\n", INTC_IPR, read_c0_status(), read_c0_cause());
rt_thread_delay(100);
}
}
int rt_application_init()
{
rt_err_t result;
result = rt_thread_init(&thread1, "t1",
thread_entry, RT_NULL,
&thread1_stack[0], sizeof(thread1_stack),
200, 10);
if (result == RT_EOK)
rt_thread_startup(&thread1);
return 0;
}
+64 -5
View File
@@ -17,6 +17,7 @@
#include "board.h"
#include "uart.h"
#include <jz4755.h>
/**
* @addtogroup JZ47xx
@@ -28,13 +29,68 @@
*/
void rt_hw_timer_handler()
{
/* enter interrupt */
rt_interrupt_enter();
/* increase a OS tick */
rt_tick_increase();
/* leave interrupt */
rt_interrupt_leave();
/* clear flag */
TCU_TFCR = TCU_TFCR_OSTFLAG;
}
/**
* This function will initial OS timer
*/
void rt_hw_timer_init()
{
rt_uint32_t val;
/* disable TCU clock */
CPM_CLKGR &= ~CPM_CLKGR_TCU;
TCU_TECR = TCU_TECR_OSTCL;
/* set */
OST_DR = RT_TICK_PER_SECOND * 0xcffff;
/* clear counter */
OST_CNT = 0;
#if 0
switch (RTC_DIV)
{
case 1:
val = OST_TCSR_PRESCALE1;
break;
case 4:
val = OST_TCSR_PRESCALE4;
break;
case 16:
val = OST_TCSR_PRESCALE16;
break;
case 64:
val = OST_TCSR_PRESCALE64;
break;
case 256:
val = OST_TCSR_PRESCALE256;
break;
case 1024:
val = OST_TCSR_PRESCALE1024;
break;
default:
val = OST_TCSR_PRESCALE4;
break;
}
#endif
#ifdef RTC_SRC_EXTAL
OST_CSR = (val | OST_TCSR_EXT_EN);
#else
OST_CSR = (val | OST_TCSR_PCLK_EN);
#endif
TCU_TFCR = TCU_TFCR_OSTFLAG;
TCU_TMCR = TCU_TMCR_OSTMCL;
TCU_TESR = TCU_TESR_OSTST;
rt_hw_interrupt_install(IRQ_TCU0, rt_hw_timer_handler, RT_NULL);
rt_hw_interrupt_umask (IRQ_TCU0);
}
/**
@@ -51,5 +107,8 @@ void rt_hw_board_init()
/* set console device */
rt_console_set_device("uart");
#endif
/* init operating system timer */
rt_hw_timer_init();
}
/*@}*/
+1 -1
View File
@@ -84,4 +84,4 @@ else:
RT_USING_MINILIBC = True
DUMP_ACTION = OBJDUMP + ' -D -S $TARGET > rtt.asm\n'
COPY_ACTION = 'copy rtthread.bin usbboot\n'
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n' + DUMP_ACTION + COPY_ACTION
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n' + COPY_ACTION
+3 -13
View File
@@ -14,6 +14,7 @@
#include <rthw.h>
#include <rtthread.h>
#include <cache.h>
#include "board.h"
@@ -27,22 +28,13 @@ extern unsigned char __bss_end;
extern int rt_application_init(void);
void dump_memory(rt_uint8_t* ptr, rt_size_t size)
{
rt_size_t index;
for (index = 0; index < size; index ++)
{
rt_kprintf("%02x ", ptr[index] & 0xff);
if ((index + 1) % 16 == 0) rt_kprintf("\n");
}
}
/**
* This function will startup RT-Thread RTOS.
*/
void rtthread_startup(void)
{
/* init cache */
rt_hw_cache_init();
/* init hardware interrupt */
rt_hw_interrupt_init();
@@ -50,8 +42,6 @@ void rtthread_startup(void)
rt_hw_board_init();
rt_show_version();
dump_memory((rt_uint8_t*)0x80000200, 32);
/* init tick */
rt_system_tick_init();
+2 -1
View File
@@ -1,6 +1,7 @@
#include <rthw.h>
#include <rtthread.h>
#include <jz47xx.h>
#include <jz4755.h>
/**
* @addtogroup Jz47xx
+93
View File
@@ -0,0 +1,93 @@
#include "jz47xx.h"
#include "cache.h"
#define CACHE_SIZE 16*1024
#define CACHE_LINE_SIZE 32
#define KSEG0 0x80000000
#define K0_TO_K1() \
do { \
unsigned long __k0_addr; \
\
__asm__ __volatile__( \
"la %0, 1f\n\t" \
"or %0, %0, %1\n\t" \
"jr %0\n\t" \
"nop\n\t" \
"1: nop\n" \
: "=&r"(__k0_addr) \
: "r" (0x20000000) ); \
} while(0)
#define K1_TO_K0() \
do { \
unsigned long __k0_addr; \
__asm__ __volatile__( \
"nop;nop;nop;nop;nop;nop;nop\n\t" \
"la %0, 1f\n\t" \
"jr %0\n\t" \
"nop\n\t" \
"1: nop\n" \
: "=&r" (__k0_addr)); \
} while (0)
#define INVALIDATE_BTB() \
do { \
unsigned long tmp; \
__asm__ __volatile__( \
".set mips32\n\t" \
"mfc0 %0, $16, 7\n\t" \
"nop\n\t" \
"ori %0, 2\n\t" \
"mtc0 %0, $16, 7\n\t" \
"nop\n\t" \
".set mips2\n\t" \
: "=&r" (tmp)); \
} while (0)
#define SYNC_WB() __asm__ __volatile__ ("sync")
#define cache_op(op,addr) \
__asm__ __volatile__( \
" .set noreorder \n" \
" .set mips32\n\t \n" \
" cache %0, %1 \n" \
" .set mips0 \n" \
" .set reorder" \
: \
: "i" (op), "m" (*(unsigned char *)(addr)))
void __icache_invalidate_all(void)
{
unsigned int i;
K0_TO_K1();
asm volatile (".set noreorder\n"
".set mips32\n\t"
"mtc0\t$0,$28\n\t"
"mtc0\t$0,$29\n"
".set mips0\n"
".set reorder\n");
for (i=KSEG0;i<KSEG0+CACHE_SIZE;i+=CACHE_LINE_SIZE)
cache_op(Index_Store_Tag_I, i);
K1_TO_K0();
INVALIDATE_BTB();
}
void __dcache_writeback_all(void)
{
unsigned int i;
for (i=KSEG0;i<KSEG0+CACHE_SIZE;i+=CACHE_LINE_SIZE)
cache_op(Index_Writeback_Inv_D, i);
SYNC_WB();
}
void rt_hw_cache_init(void)
{
__dcache_writeback_all();
__icache_invalidate_all();
}
+40
View File
@@ -0,0 +1,40 @@
#ifndef __CACHE_H__
#define __CACHE_H__
/*
* Cache Operations
*/
#define Index_Invalidate_I 0x00
#define Index_Writeback_Inv_D 0x01
#define Index_Invalidate_SI 0x02
#define Index_Writeback_Inv_SD 0x03
#define Index_Load_Tag_I 0x04
#define Index_Load_Tag_D 0x05
#define Index_Load_Tag_SI 0x06
#define Index_Load_Tag_SD 0x07
#define Index_Store_Tag_I 0x08
#define Index_Store_Tag_D 0x09
#define Index_Store_Tag_SI 0x0A
#define Index_Store_Tag_SD 0x0B
#define Create_Dirty_Excl_D 0x0d
#define Create_Dirty_Excl_SD 0x0f
#define Hit_Invalidate_I 0x10
#define Hit_Invalidate_D 0x11
#define Hit_Invalidate_SI 0x12
#define Hit_Invalidate_SD 0x13
#define Fill 0x14
#define Hit_Writeback_Inv_D 0x15
/* 0x16 is unused */
#define Hit_Writeback_Inv_SD 0x17
#define Hit_Writeback_I 0x18
#define Hit_Writeback_D 0x19
/* 0x1a is unused */
#define Hit_Writeback_SD 0x1b
/* 0x1c is unused */
/* 0x1e is unused */
#define Hit_Set_Virtual_SI 0x1e
#define Hit_Set_Virtual_SD 0x1f
void rt_hw_cache_init(void);
#endif
+7 -7
View File
@@ -3,6 +3,7 @@
* Change Logs:
* Date Author Notes
* 2010-05-17 swkyer first version
* 2010-09-11 bernard port to Jz4755
*/
#include "../common/mips.inc"
#include "../common/stackframe.h"
@@ -79,6 +80,7 @@ _reswitch:
jr ra
nop
.globl system_dump
/*
* void rt_hw_context_switch_interrupt_do(rt_base_t flag)
@@ -97,13 +99,11 @@ mips_irq_handle:
beqz t0, spurious_interrupt
nop
/* let k0 keep the current context sp */
move k0, sp
/* switch to kernel stack */
move k0, sp
li sp, SYSTEM_STACK
addiu sp, sp, -4
sw k0, 0(sp)
1:
jal rt_interrupt_enter
nop
jal rt_interrupt_dispatch
@@ -112,8 +112,6 @@ mips_irq_handle:
nop
/* switch sp back to thread's context */
lw k0, 0(sp)
nop
move sp, k0
/*
@@ -124,15 +122,17 @@ mips_irq_handle:
lw k1, 0(k0)
beqz k1, spurious_interrupt
nop
sw zero, 0(k0) /* clear flag */
nop
/*
* switch to the new thread
*/
sw zero, 0(k0) /* clear flag */
la k0, rt_interrupt_from_thread
lw k1, 0(k0)
nop
sw sp, 0(k1) /* store sp in preempted tasks's TCB */
la k0, rt_interrupt_to_thread
lw k1, 0(k0)
nop
+25
View File
@@ -10,9 +10,26 @@
* Change Logs:
* Date Author Notes
* 2010-07-09 Bernard first version
* 2010-09-11 Bernard add CPU reset implementation
*/
#include <rtthread.h>
#include <jz4755.h>
/* Watchdog definitions */
#define WDT_CLK_PRESCALE_CLK1 ( 0x0 << 3)
#define WDT_CLK_PRESCALE_CLK4 ( 0x1 << 3)
#define WDT_CLK_PRESCALE_CLK16 ( 0x2 << 3)
#define WDT_CLK_PRESCALE_CLK64 ( 0x3 << 3)
#define WDT_CLK_PRESCALE_CLK256 ( 0x4 << 3)
#define WDT_CLK_PRESCALE_CLK1024 ( 0x5 << 3)
#define WDT_CLK_PRESCALE_MASK ( 0x3F << 3)
#define WDT_CLK_EXTAL ( 0x1 << 2)
#define WDT_CLK_RTC ( 0x1 << 1)
#define WDT_CLK_PCLK ( 0x1 << 0)
#define WDT_CLK_MASK ( 7 )
#define WDT_ENABLE ( 1 << 0 )
/**
* @addtogroup Jz47xx
@@ -26,6 +43,14 @@
void rt_hw_cpu_reset()
{
/* open the watch-dog */
WDT_TCSR = WDT_CLK_EXTAL;
WDT_TCSR |= WDT_CLK_PRESCALE_CLK1024;
WDT_TDR = 0x03;
WDT_TCNT = 0x00;
WDT_TCER |= WDT_ENABLE;
rt_kprintf("reboot system...\n");
while (1);
}
/**
+2 -2
View File
@@ -88,17 +88,17 @@ void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_ha
}
}
static rt_uint32_t pending ;
void rt_interrupt_dispatch(void *ptreg)
{
int i;
rt_isr_handler_t irq_func;
static rt_uint32_t pending = 0;
/* the hardware interrupt */
pending |= INTC_IPR;
if (!pending) return;
for (i = 0; i < JZ47XX_MAX_INTR; i++)
for (i = JZ47XX_MAX_INTR; i > 0; --i)
{
if ((pending & (1<<i)))
{
+55
View File
@@ -0,0 +1,55 @@
#ifndef __JZ4740_H__
#define __JZ4740_H__
#include "jz47xx.h"
#define WDT_BASE 0xB0002000
/* Watchdog */
#define WDT_TDR __REG16(WDT_BASE + 0x00) /* Watchdog Timer Data Register */
#define WDT_TCER __REG8(WDT_BASE + 0x04) /* Watchdog Counter Enable Register */
#define WDT_TCNT __REG16(WDT_BASE + 0x08) /* Watchdog Timer Counter Register */
#define WDT_TCSR __REG16(WDT_BASE + 0x0C) /* Watchdog Timer Control Register */
/* Clock Gate Register Definitions */
#define CPM_CLKGR_UART1 (1 << 15)
#define CPM_CLKGR_UHC (1 << 14)
#define CPM_CLKGR_IPU (1 << 13)
#define CPM_CLKGR_DMAC (1 << 12)
#define CPM_CLKGR_UDC (1 << 11)
#define CPM_CLKGR_LCD (1 << 10)
#define CPM_CLKGR_CIM (1 << 9)
#define CPM_CLKGR_SADC (1 << 8)
#define CPM_CLKGR_MSC (1 << 7)
#define CPM_CLKGR_AIC1 (1 << 6)
#define CPM_CLKGR_AIC2 (1 << 5)
#define CPM_CLKGR_SSI (1 << 4)
#define CPM_CLKGR_I2C (1 << 3)
#define CPM_CLKGR_RTC (1 << 2)
#define CPM_CLKGR_TCU (1 << 1)
#define CPM_CLKGR_UART0 (1 << 0)
/* Interrupt Definitions */
#define IRQ_I2C 1
#define IRQ_UHC 3
#define IRQ_UART0 9
#define IRQ_SADC 12
#define IRQ_MSC 14
#define IRQ_RTC 15
#define IRQ_SSI 16
#define IRQ_CIM 17
#define IRQ_AIC 18
#define IRQ_ETH 19
#define IRQ_DMAC 20
#define IRQ_TCU2 21
#define IRQ_TCU1 22
#define IRQ_TCU0 23
#define IRQ_UDC 24
#define IRQ_GPIO3 25
#define IRQ_GPIO2 26
#define IRQ_GPIO1 27
#define IRQ_GPIO0 28
#define IRQ_IPU 29
#define IRQ_LCD 30
#endif
+79
View File
@@ -1,4 +1,83 @@
#ifndef __JZ4755_H__
#define __JZ4755_H__
#include "jz47xx.h"
#define WDT_BASE 0xB0002000
#define OST_BASE 0xB00020e0
/* Watchdog */
#define WDT_TDR __REG16(WDT_BASE + 0x00) /* Watchdog Timer Data Register */
#define WDT_TCER __REG8(WDT_BASE + 0x04) /* Watchdog Counter Enable Register */
#define WDT_TCNT __REG16(WDT_BASE + 0x08) /* Watchdog Timer Counter Register */
#define WDT_TCSR __REG16(WDT_BASE + 0x0C) /* Watchdog Timer Control Register */
/* OS Timer */
#define OST_DR __REG32(OST_BASE + 0x00) /* OS Timer Data Register */
#define OST_CNT __REG32(OST_BASE + 0x08) /* OS Timer Counter Register */
#define OST_CSR __REG16(OST_BASE + 0x0C) /* OS Timer Control Register */
/* OST Register Definitions */
#define OST_TCSR_EXT_EN ( 0x1 << 2)
#define OST_TCSR_RTC_EN ( 0x1 << 1)
#define OST_TCSR_PCLK_EN ( 0x1 << 0)
/* Clock Gate Register Definitions */
#define CPM_CLKGR_AUX_CPU ( 1 << 24 )
#define CPM_CLKGR_AHB1 ( 1 << 23 )
#define CPM_CLKGR_IDCT ( 1 << 22 )
#define CPM_CLKGR_DB ( 1 << 21 )
#define CPM_CLKGR_ME ( 1 << 20 )
#define CPM_CLKGR_MC ( 1 << 19 )
#define CPM_CLKGR_TVE ( 1 << 18 )
#define CPM_CLKGR_TSSI ( 1 << 17 )
#define CPM_CLKGR_MSC1 ( 1 << 16 )
#define CPM_CLKGR_UART2 ( 1 << 15 )
#define CPM_CLKGR_UART1 ( 1 << 14 )
#define CPM_CLKGR_IPU ( 1 << 13 )
#define CPM_CLKGR_DMAC ( 1 << 12 )
#define CPM_CLKGR_BCH ( 1 << 11 )
#define CPM_CLKGR_UDC ( 1 << 10 )
#define CPM_CLKGR_LCD ( 1 << 9 )
#define CPM_CLKGR_CIM ( 1 << 8 )
#define CPM_CLKGR_SADC ( 1 << 7 )
#define CPM_CLKGR_MSC0 ( 1 << 6 )
#define CPM_CLKGR_AIC ( 1 << 5 )
#define CPM_CLKGR_SSI1 ( 1 << 4 )
#define CPM_CLKGR_I2C ( 1 << 3 )
#define CPM_CLKGR_RTC ( 1 << 2 )
#define CPM_CLKGR_TCU ( 1 << 1 )
#define CPM_CLKGR_UART0 ( 1 << 0 )
/* Interrupt Definitions */
#define IRQ_ETH 0
#define IRQ_SFT 4
#define IRQ_I2C 5
#define IRQ_RTC 6
#define IRQ_UART2 7
#define IRQ_UART1 8
#define IRQ_UART0 9
#define IRQ_AIC 10
#define IRQ_GPIO5 11
#define IRQ_GPIO4 12
#define IRQ_GPIO3 13
#define IRQ_GPIO2 14
#define IRQ_GPIO1 15
#define IRQ_GPIO0 16
#define IRQ_BCH 17
#define IRQ_SADC 18
#define IRQ_CIM 19
#define IRQ_TSSI 20
#define IRQ_TCU2 21
#define IRQ_TCU1 22
#define IRQ_TCU0 23
#define IRQ_MSC1 24
#define IRQ_MSC0 25
#define IRQ_SSI 26
#define IRQ_UDC 27
#define IRQ_DMA1 28 /* Used for DMA channel 4-7 */
#define IRQ_DMA0 29 /* Used for DMA channel 0-3 */
#define IRQ_IPU 30
#define IRQ_LCD 31
#endif
File diff suppressed because it is too large. Load diff