提交 79ca654e 编写于 作者: M mbbill

ADD: Add abort handler, it will terminate current thread by default.

ADD: Merged svc, abort and irq mode stack.
ADD: Changed MDK project to new format.
FIX: Removed the "static" qualifier of rt_thread_exit().
FIX: Change AT91SAM7X.h to the standard header(AT91SAM7X256.h) of RealView MDK. (not all of them are changed, e.g. sd.c)
FIX: Moved some board-dependent files to bsp.


git-svn-id: https://rt-thread.googlecode.com/svn/trunk@257 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 78de0344
......@@ -15,7 +15,7 @@
#include <rtthread.h>
#include <rthw.h>
#include <AT91SAM7X.h>
#include <AT91SAM7X256.h>
#include "board.h"
static void rt_hw_board_led_init(void);
......@@ -34,18 +34,18 @@ static void rt_hw_board_led_init(void);
*/
void rt_hw_timer_handler(int vector)
{
if (AT91C_PITC_PISR & 0x01)
if (AT91C_BASE_PITC->PITC_PISR & 0x01)
{
/* increase a tick */
rt_tick_increase();
/* ack interrupt */
AT91C_AIC_EOICR = AT91C_PITC_PIVR;
AT91C_BASE_AIC->AIC_EOICR = AT91C_BASE_PITC->PITC_PIVR;
}
else
{
/* end of interrupt */
AT91C_AIC_EOICR = 0;
AT91C_BASE_AIC->AIC_EOICR = 0;
}
}
/* PIO Flash PA PB PIN */
......@@ -63,11 +63,11 @@ int leds[] = {LED1, LED2, LED3, LED4};
static void rt_hw_board_led_init()
{
/* enable the clock of the PIO A, PIO B */
AT91C_PMC_PCER = 1 << AT91C_ID_PIOA | 1 << AT91C_ID_PIOB;
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA | 1 << AT91C_ID_PIOB;
/* configure PIO as output for led */
AT91C_PIOB_PER = LED_MASK;
AT91C_PIOB_OER = LED_MASK;
AT91C_BASE_PIOB->PIO_PER = LED_MASK;
AT91C_BASE_PIOB->PIO_OER = LED_MASK;
}
/**
......@@ -79,7 +79,7 @@ void rt_hw_board_led_on(int n)
{
if (n >= 0 && n < 4)
{
AT91C_PIOB_CODR = leds[n];
AT91C_BASE_PIOB->PIO_CODR = leds[n];
}
}
......@@ -92,7 +92,7 @@ void rt_hw_board_led_off(int n)
{
if (n >= 0 && n < 4)
{
AT91C_PIOB_SODR = leds[n];
AT91C_BASE_PIOB->PIO_SODR = leds[n];
}
}
......@@ -111,14 +111,14 @@ void rt_hw_console_output(const char* str)
{
if (*str == '\n')
{
while (!(AT91C_US0_CSR & AT91C_US_TXRDY));
AT91C_US0_THR = '\r';
while (!(AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY));
AT91C_BASE_US0->US_THR = '\r';
}
/* Wait for Empty Tx Buffer */
while (!(AT91C_US0_CSR & AT91C_US_TXRDY));
while (!(AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY));
/* Transmit Character */
AT91C_US0_THR = *str;
AT91C_BASE_US0->US_THR = *str;
str ++;
}
......@@ -127,25 +127,25 @@ void rt_hw_console_output(const char* str)
static void rt_hw_console_init()
{
/* Enable Clock for USART0 */
AT91C_PMC_PCER = 1 << AT91C_ID_US0;
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_US0;
/* Enable RxD0 and TxDO Pin */
AT91C_PIO_PDR = (1 << 5) | (1 << 6);
AT91C_BASE_PIOA->PIO_PDR = (1 << 5) | (1 << 6);
AT91C_US0_CR = AT91C_US_RSTRX | /* Reset Receiver */
AT91C_BASE_US0->US_CR = AT91C_US_RSTRX | /* Reset Receiver */
AT91C_US_RSTTX | /* Reset Transmitter */
AT91C_US_RXDIS | /* Receiver Disable */
AT91C_US_TXDIS; /* Transmitter Disable */
AT91C_US0_MR = AT91C_US_USMODE_NORMAL | /* Normal Mode */
AT91C_BASE_US0->US_MR = AT91C_US_USMODE_NORMAL | /* Normal Mode */
AT91C_US_CLKS_CLOCK | /* Clock = MCK */
AT91C_US_CHRL_8_BITS | /* 8-bit Data */
AT91C_US_PAR_NONE | /* No Parity */
AT91C_US_NBSTOP_1_BIT; /* 1 Stop Bit */
/* set baud rate divisor */
AT91C_US0_BRGR = BRD;
AT91C_BASE_US0->US_BRGR = BRD;
AT91C_US0_CR = AT91C_US_RXEN | /* Receiver Enable */
AT91C_BASE_US0->US_CR = AT91C_US_RXEN | /* Receiver Enable */
AT91C_US_TXEN; /* Transmitter Enable */
}
......@@ -163,11 +163,11 @@ void rt_hw_board_init()
rt_hw_board_led_init();
/* init PITC */
AT91C_PITC_PIMR = (1 << 25) | (1 << 24) | PIV;
AT91C_BASE_PITC->PITC_PIMR = (1 << 25) | (1 << 24) | PIV;
/* install timer handler */
rt_hw_interrupt_install(AT91C_ID_SYS, rt_hw_timer_handler, RT_NULL);
AT91C_AIC_SMR(AT91C_ID_SYS) = 0;
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_SYS] = 0;
rt_hw_interrupt_umask(AT91C_ID_SYS);
}
/*@}*/
......@@ -17,46 +17,46 @@
#include <rthw.h>
#include <rtthread.h>
#define AT91C_US_RXRDY ((unsigned int) 0x1 << 0) /* US RXRDY Interrupt */
#define AT91C_US_TXRDY ((unsigned int) 0x1 << 1) /* US TXRDY Interrupt */
#define AT91C_US_RSTRX ((unsigned int) 0x1 << 2) /* US Reset Receiver */
#define AT91C_US_RSTTX ((unsigned int) 0x1 << 3) /* US Reset Transmitter */
#define AT91C_US_RXEN ((unsigned int) 0x1 << 4) /* US Receiver Enable */
#define AT91C_US_RXDIS ((unsigned int) 0x1 << 5) /* US Receiver Disable */
#define AT91C_US_TXEN ((unsigned int) 0x1 << 6) /* US Transmitter Enable */
#define AT91C_US_TXDIS ((unsigned int) 0x1 << 7) /* US Transmitter Disable */
#define AT91C_US_RSTSTA ((unsigned int) 0x1 << 8) /* US Reset Status Bits */
#define AT91C_US_USMODE_NORMAL ((unsigned int) 0x0) /* USAR) Normal */
#define AT91C_US_USMODE_RS485 ((unsigned int) 0x1) /* USAR) RS485 */
#define AT91C_US_USMODE_HWHSH ((unsigned int) 0x2) /* USAR) Hardware Handshaking */
#define AT91C_US_USMODE_MODEM ((unsigned int) 0x3) /* USAR) Modem */
#define AT91C_US_USMODE_ISO7816_0 ((unsigned int) 0x4) /* USAR) ISO7816 protocol: T = 0 */
#define AT91C_US_USMODE_ISO7816_1 ((unsigned int) 0x6) /* USAR) ISO7816 protocol: T = 1 */
#define AT91C_US_USMODE_IRDA ((unsigned int) 0x8) /* USAR) IrDA */
#define AT91C_US_USMODE_SWHSH ((unsigned int) 0xC) /* USAR) Software Handshaking */
#define AT91C_US_CLKS_CLOCK ((unsigned int) 0x0 << 4) /* USAR) Clock */
#define AT91C_US_CLKS_FDIV1 ((unsigned int) 0x1 << 4) /* USAR) fdiv1 */
#define AT91C_US_CLKS_SLOW ((unsigned int) 0x2 << 4) /* USAR) slow_clock (ARM) */
#define AT91C_US_CLKS_EXT ((unsigned int) 0x3 << 4) /* USAR) External (SCK) */
#define AT91C_US_CHRL_5_BITS ((unsigned int) 0x0 << 6) /* USAR) Character Length: 5 bits */
#define AT91C_US_CHRL_6_BITS ((unsigned int) 0x1 << 6) /* USAR) Character Length: 6 bits */
#define AT91C_US_CHRL_7_BITS ((unsigned int) 0x2 << 6) /* USAR) Character Length: 7 bits */
#define AT91C_US_CHRL_8_BITS ((unsigned int) 0x3 << 6) /* USAR) Character Length: 8 bits */
#define AT91C_US_PAR_EVEN ((unsigned int) 0x0 << 9) /* DBGU Even Parity */
#define AT91C_US_PAR_ODD ((unsigned int) 0x1 << 9) /* DBGU Odd Parity */
#define AT91C_US_PAR_SPACE ((unsigned int) 0x2 << 9) /* DBGU Parity forced to 0 (Space) */
#define AT91C_US_PAR_MARK ((unsigned int) 0x3 << 9) /* DBGU Parity forced to 1 (Mark) */
#define AT91C_US_PAR_NONE ((unsigned int) 0x4 << 9) /* DBGU No Parity */
#define AT91C_US_PAR_MULTI_DROP ((unsigned int) 0x6 << 9) /* DBGU Multi-drop mode */
#define AT91C_US_NBSTOP_1_BIT ((unsigned int) 0x0 << 12) /* USART 1 stop bit */
#define AT91C_US_NBSTOP_15_BIT ((unsigned int) 0x1 << 12) /* USART Asynchronous (SYNC=0) 2 stop bits Synchronous (SYNC=1) 2 stop bits */
#define AT91C_US_NBSTOP_2_BIT ((unsigned int) 0x2 << 12) /* USART 2 stop bits */
// These are defined in standard header (at91sam7x256.h) of realview MDK.
//#define AT91C_US_RXRDY ((unsigned int) 0x1 << 0) /* US RXRDY Interrupt */
//#define AT91C_US_TXRDY ((unsigned int) 0x1 << 1) /* US TXRDY Interrupt */
//#define AT91C_US_RSTRX ((unsigned int) 0x1 << 2) /* US Reset Receiver */
//#define AT91C_US_RSTTX ((unsigned int) 0x1 << 3) /* US Reset Transmitter */
//#define AT91C_US_RXEN ((unsigned int) 0x1 << 4) /* US Receiver Enable */
//#define AT91C_US_RXDIS ((unsigned int) 0x1 << 5) /* US Receiver Disable */
//#define AT91C_US_TXEN ((unsigned int) 0x1 << 6) /* US Transmitter Enable */
//#define AT91C_US_TXDIS ((unsigned int) 0x1 << 7) /* US Transmitter Disable */
//#define AT91C_US_RSTSTA ((unsigned int) 0x1 << 8) /* US Reset Status Bits */
//
//#define AT91C_US_USMODE_NORMAL ((unsigned int) 0x0) /* USAR) Normal */
//#define AT91C_US_USMODE_RS485 ((unsigned int) 0x1) /* USAR) RS485 */
//#define AT91C_US_USMODE_HWHSH ((unsigned int) 0x2) /* USAR) Hardware Handshaking */
//#define AT91C_US_USMODE_MODEM ((unsigned int) 0x3) /* USAR) Modem */
//#define AT91C_US_USMODE_ISO7816_0 ((unsigned int) 0x4) /* USAR) ISO7816 protocol: T = 0 */
//#define AT91C_US_USMODE_ISO7816_1 ((unsigned int) 0x6) /* USAR) ISO7816 protocol: T = 1 */
//#define AT91C_US_USMODE_IRDA ((unsigned int) 0x8) /* USAR) IrDA */
//#define AT91C_US_USMODE_SWHSH ((unsigned int) 0xC) /* USAR) Software Handshaking */
//
//#define AT91C_US_CLKS_CLOCK ((unsigned int) 0x0 << 4) /* USAR) Clock */
//#define AT91C_US_CLKS_FDIV1 ((unsigned int) 0x1 << 4) /* USAR) fdiv1 */
//#define AT91C_US_CLKS_SLOW ((unsigned int) 0x2 << 4) /* USAR) slow_clock (ARM) */
//#define AT91C_US_CLKS_EXT ((unsigned int) 0x3 << 4) /* USAR) External (SCK) */
//
//#define AT91C_US_CHRL_5_BITS ((unsigned int) 0x0 << 6) /* USAR) Character Length: 5 bits */
//#define AT91C_US_CHRL_6_BITS ((unsigned int) 0x1 << 6) /* USAR) Character Length: 6 bits */
//#define AT91C_US_CHRL_7_BITS ((unsigned int) 0x2 << 6) /* USAR) Character Length: 7 bits */
//#define AT91C_US_CHRL_8_BITS ((unsigned int) 0x3 << 6) /* USAR) Character Length: 8 bits */
//
//#define AT91C_US_PAR_EVEN ((unsigned int) 0x0 << 9) /* DBGU Even Parity */
//#define AT91C_US_PAR_ODD ((unsigned int) 0x1 << 9) /* DBGU Odd Parity */
//#define AT91C_US_PAR_SPACE ((unsigned int) 0x2 << 9) /* DBGU Parity forced to 0 (Space) */
//#define AT91C_US_PAR_MARK ((unsigned int) 0x3 << 9) /* DBGU Parity forced to 1 (Mark) */
//#define AT91C_US_PAR_NONE ((unsigned int) 0x4 << 9) /* DBGU No Parity */
//#define AT91C_US_PAR_MULTI_DROP ((unsigned int) 0x6 << 9) /* DBGU Multi-drop mode */
//
//#define AT91C_US_NBSTOP_1_BIT ((unsigned int) 0x0 << 12) /* USART 1 stop bit */
//#define AT91C_US_NBSTOP_15_BIT ((unsigned int) 0x1 << 12) /* USART Asynchronous (SYNC=0) 2 stop bits Synchronous (SYNC=1) 2 stop bits */
//#define AT91C_US_NBSTOP_2_BIT ((unsigned int) 0x2 << 12) /* USART 2 stop bits */
#define MCK 48054857
#define BR 115200 /* Baud Rate */
......
此差异已折叠。
此差异已折叠。
......@@ -81,7 +81,7 @@
/* SECTION: lwip, a lighwight TCP/IP protocol stack */
/* Using lighweight TCP/IP protocol stack*/
#define RT_USING_LWIP
//#define RT_USING_LWIP
/* Trace LwIP protocol*/
/* #define RT_LWIP_DEBUG */
......@@ -139,12 +139,12 @@
#define RT_LWIP_MSKADDR3 0
/* SECTION: DFS options */
#define RT_USING_DFS
//#define RT_USING_DFS
/* the max number of mounted filesystem */
#define DFS_FILESYSTEMS_MAX 1
/* the max number of opened files */
#define DFS_FD_MAX 2
/* the max number of cached sector */
#define DFS_CACHE_MAX_NUM 4
#define DFS_CACHE_MAX_NUM 4
#endif
......@@ -78,8 +78,8 @@ static void rt_hw_serial_isr(int irqno)
{
rt_base_t level;
struct rt_device* device;
struct rt_at91serial* serial = RT_NULL;
struct rt_at91serial* serial = RT_NULL;
#ifdef RT_USING_UART1
if (irqno == AT91C_ID_US0)
{
......
......@@ -15,7 +15,6 @@
#include <rthw.h>
#include <rtthread.h>
#include <AT91SAM7X.h>
#include "board.h"
#ifdef RT_USING_DFS
......
......@@ -112,6 +112,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, rt_uint8_t cmd, void* arg);
rt_err_t rt_thread_suspend(rt_thread_t thread);
rt_err_t rt_thread_resume(rt_thread_t thread);
void rt_thread_timeout(void* parameter);
void rt_thread_exit(void);
/*
* idle thread interface
......@@ -175,7 +176,7 @@ void rt_free (void *ptr);
void* rt_realloc(void *ptr, rt_size_t nbytes);
void *rt_calloc(rt_size_t count, rt_size_t size);
void rt_memory_info(rt_uint32_t *total,
void rt_memory_info(rt_uint32_t *total,
rt_uint32_t *used,
rt_uint32_t *max_used);
......
......@@ -13,7 +13,7 @@
*/
#include <rtthread.h>
#include "AT91SAM7X.h"
/**
* @addtogroup AT91SAM7X
......
......@@ -13,7 +13,7 @@
*/
#include <rtthread.h>
#include "AT91SAM7X.h"
#include "AT91SAM7X256.h"
#define MAX_HANDLERS 32
......@@ -41,7 +41,7 @@ void rt_hw_interrupt_init()
for (index = 0; index < MAX_HANDLERS; index ++)
{
AT91C_AIC_SVR(index) = (rt_uint32_t)rt_hw_interrupt_handler;
AT91C_BASE_AIC->AIC_SVR[index] = (rt_uint32_t)rt_hw_interrupt_handler;
}
/* init interrupt nest, and context in thread sp */
......@@ -58,10 +58,10 @@ void rt_hw_interrupt_init()
void rt_hw_interrupt_mask(int vector)
{
/* disable interrupt */
AT91C_AIC_IDCR = 1 << vector;
AT91C_BASE_AIC->AIC_IDCR = 1 << vector;
/* clear interrupt */
AT91C_AIC_ICCR = 1 << vector;
AT91C_BASE_AIC->AIC_ICCR = 1 << vector;
}
/**
......@@ -70,7 +70,7 @@ void rt_hw_interrupt_mask(int vector)
*/
void rt_hw_interrupt_umask(int vector)
{
AT91C_AIC_IECR = 1 << vector;
AT91C_BASE_AIC->AIC_IECR = 1 << vector;
}
/**
......@@ -83,8 +83,8 @@ void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_ha
{
if(vector >= 0 && vector < MAX_HANDLERS)
{
if (*old_handler != RT_NULL) *old_handler = (rt_isr_handler_t)AT91C_AIC_SVR(vector);
if (new_handler != RT_NULL) AT91C_AIC_SVR(vector) = (rt_uint32_t)new_handler;
if (*old_handler != RT_NULL) *old_handler = (rt_isr_handler_t)AT91C_BASE_AIC->AIC_SVR[vector];
if (new_handler != RT_NULL) AT91C_BASE_AIC->AIC_SVR[vector] = (rt_uint32_t)new_handler;
}
}
......
......@@ -12,7 +12,8 @@
* 2006-08-23 Bernard the first version
*/
#include <rtthread.h>
#include "AT91SAM7X.h"
#define SVCMODE 0x13
/**
* @addtogroup AT91SAM7
......
......@@ -27,6 +27,7 @@
; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
; 2009-12-28 MingBai Bug fix (USR mode stack removed).
; 2009-12-29 MingBai Merge svc and irq stack, add abort handler.
Mode_USR EQU 0x10
Mode_FIQ EQU 0x11
......@@ -55,7 +56,7 @@ RAM_BASE EQU 0x00200000
;// </h>
UND_Stack_Size EQU 0x00000000
SVC_Stack_Size EQU 0x00000100
SVC_Stack_Size EQU 0x00000000
ABT_Stack_Size EQU 0x00000000
FIQ_Stack_Size EQU 0x00000000
IRQ_Stack_Size EQU 0x00000100
......@@ -238,8 +239,8 @@ FIQ_Addr DCD FIQ_Handler
Undef_Handler B Undef_Handler
SWI_Handler B SWI_Handler
PAbt_Handler B PAbt_Handler
DAbt_Handler B DAbt_Handler
PAbt_Handler B Abort_Handler
DAbt_Handler B Abort_Handler
FIQ_Handler B FIQ_Handler
......@@ -365,22 +366,22 @@ MC_RCR EQU 0x00 ; MC_RCR Offset
; Enter Undefined Instruction Mode and set its Stack Pointer
MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
MOV SP, R0
SUB R0, R0, #UND_Stack_Size
;SUB R0, R0, #UND_Stack_Size
; Enter Abort Mode and set its Stack Pointer
MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
MOV SP, R0
SUB R0, R0, #ABT_Stack_Size
;SUB R0, R0, #ABT_Stack_Size
; Enter FIQ Mode and set its Stack Pointer
MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
MOV SP, R0
SUB R0, R0, #FIQ_Stack_Size
;SUB R0, R0, #FIQ_Stack_Size
; Enter IRQ Mode and set its Stack Pointer
MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
MOV SP, R0
SUB R0, R0, #IRQ_Stack_Size
;SUB R0, R0, #IRQ_Stack_Size
; Enter Supervisor Mode and set its Stack Pointer
MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
......@@ -414,6 +415,16 @@ MC_RCR EQU 0x00 ; MC_RCR Offset
IMPORT rt_interrupt_from_thread
IMPORT rt_interrupt_to_thread
IMPORT rt_hw_trap_irq
IMPORT rt_hw_trap_abort
Abort_Handler PROC
EXPORT Abort_Handler
stmfd sp!, {r0-r12,lr}
bl rt_interrupt_enter
bl rt_hw_trap_abort
bl rt_interrupt_leave
b SWITCH
ENDP
IRQ_Handler PROC
EXPORT IRQ_Handler
......@@ -424,7 +435,7 @@ IRQ_Handler PROC
; if rt_thread_switch_interrput_flag set, jump to
; rt_hw_context_switch_interrupt_do and don't return
LDR r0, =rt_thread_switch_interrput_flag
SWITCH LDR r0, =rt_thread_switch_interrput_flag
LDR r1, [r0]
CMP r1, #1
BEQ rt_hw_context_switch_interrupt_do
......@@ -492,7 +503,7 @@ rt_hw_context_switch_interrupt_do PROC
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + SVC_Stack_Size)
LDR R1, = (Stack_Mem + IRQ_Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
......
......@@ -15,7 +15,7 @@
#include <rtthread.h>
#include <rthw.h>
#include "AT91SAM7X.h"
#include "AT91SAM7X256.h"
/**
* @addtogroup AT91SAM7
......@@ -24,12 +24,12 @@
void rt_hw_trap_irq()
{
rt_isr_handler_t hander = (rt_isr_handler_t)AT91C_AIC_IVR;
rt_isr_handler_t hander = (rt_isr_handler_t)AT91C_BASE_AIC->AIC_IVR;
hander(AT91C_AIC_ISR);
hander(AT91C_BASE_AIC->AIC_ISR);
/* end of interrupt */
AT91C_AIC_EOICR = 0;
AT91C_BASE_AIC->AIC_EOICR = 0;
}
void rt_hw_trap_fiq()
......@@ -37,4 +37,10 @@ void rt_hw_trap_fiq()
rt_kprintf("fast interrupt request\n");
}
extern void rt_thread_exit(void);
void rt_hw_trap_abort()
{
rt_thread_exit();
rt_kprintf("Abort occured, thread terminated.\n");
}
/*@}*/
......@@ -34,7 +34,6 @@ extern rt_uint8_t rt_current_priority;
extern rt_list_t rt_thread_defunct;
#endif
static void rt_thread_exit(void);
void rt_thread_timeout(void* parameter);
static rt_err_t _rt_thread_init(struct rt_thread* thread,
......@@ -223,7 +222,7 @@ rt_err_t rt_thread_startup (rt_thread_t thread)
return RT_EOK;
}
static void rt_thread_exit()
void rt_thread_exit()
{
struct rt_thread* thread;
register rt_base_t temp;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册