git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@59 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2007-10-23 18:43:39 +00:00
parent bca8923f62
commit 4674513d38
7 changed files with 64 additions and 68 deletions

View File

@ -62,8 +62,8 @@ UDEFS =
UADEFS =
# List ARM-mode C source files here
ASRC = chcore.c main.c buzzer.c ../../src/lib/evtimer.c \
../../test/test.c ../../ports/ARM7-LPC214x/GCC/lpc214x_serial.c \
ASRC = chcore.c main.c buzzer.c ../../src/lib/evtimer.c ../../test/test.c \
../../ports/ARM7-LPC214x/GCC/vic.c ../../ports/ARM7-LPC214x/GCC/lpc214x_serial.c \
../../src/chinit.c ../../src/chlists.c ../../src/chdelta.c ../../src/chschd.c \
../../src/chthreads.c ../../src/chsem.c ../../src/chevents.c ../../src/chmsg.c \
../../src/chsleep.c ../../src/chqueues.c ../../src/chserial.c

View File

@ -20,7 +20,9 @@
#include <ch.h>
#include "lpc214x.h"
#include "vic.h"
#include "lpc214x_serial.h"
#include "buzzer.h"
extern void IrqHandler(void);
@ -62,7 +64,6 @@ extern void T0IrqHandler(void);
* NOTE: Interrupts are still disabled.
*/
void hwinit(void) {
int i;
/*
* All peripherals clock disabled by default in order to save power.
@ -110,17 +111,9 @@ void hwinit(void) {
/*
* Interrupt vectors assignment.
* NOTE: Better reset everything in the VIC, it is a HUGE source of trouble.
*/
VIC *vic = VICBase;
vic->VIC_IntSelect = 0;
vic->VIC_IntEnable = 0;
vic->VIC_VectAddr = 0;
for (i = 0; i < 16; i++) {
vic->VIC_VectCntls[i] = 0;
vic->VIC_VectAddrs[i] = 0;
}
vic->VIC_DefVectAddr = (IOREG32)IrqHandler;
InitVIC();
VICDefVectAddr = (IOREG32)IrqHandler;
SetVICVector(T0IrqHandler, 0, SOURCE_Timer0);
SetVICVector(UART0IrqHandler, 1, SOURCE_UART0);
SetVICVector(UART1IrqHandler, 2, SOURCE_UART1);
@ -128,7 +121,7 @@ void hwinit(void) {
/*
* System Timer initialization, 1ms intervals.
*/
vic->VIC_IntEnable |= INTMASK(SOURCE_Timer0);
VICIntEnable = INTMASK(SOURCE_Timer0);
TC *timer = T0Base;
timer->TC_PR = VAL_TC0_PRESCALER;
timer->TC_MR0 = (PCLK / CH_FREQUENCY) / (VAL_TC0_PRESCALER + 1);
@ -167,21 +160,12 @@ void chSysHalt(void) {
;
}
/*
* Set a vector for an interrupt source, the vector is enabled too.
*/
void SetVICVector(void *handler, int vector, int source) {
VIC *vicp = VICBase;
vicp->VIC_VectAddrs[vector] = (IOREG32)handler;
vicp->VIC_VectCntls[vector] = (IOREG32)(source | 0x20);
}
/*
* Undefined Instruction exception handler.
* Yellow LED + RED LED 2.
*/
void UndHandler(void) {
IO0SET = 0x80000C00;
IO0CLR = 0x80000800;
while(TRUE)
@ -193,6 +177,7 @@ void UndHandler(void) {
* Yellow LED + RED LED 1.
*/
void PrefetchHandler(void) {
IO0SET = 0x80000C00;
IO0CLR = 0x80000400;
while(TRUE)
@ -204,6 +189,7 @@ void PrefetchHandler(void) {
* Yellow LED + both RED LEDs.
*/
void AbortHandler(void) {
IO0SET = 0x80000C00;
IO0CLR = 0x80000C00;
while(TRUE)
@ -214,6 +200,7 @@ void AbortHandler(void) {
* Non-vectored IRQs handling here.
*/
void NonVectoredIrq(void) {
VICVectAddr = 0;
}
@ -221,7 +208,8 @@ void NonVectoredIrq(void) {
* Timer 0 IRQ handling here.
*/
void Timer0Irq(void) {
chSchTimerHandlerI();
T0IR = 1; /* Clear interrupt on match MR0. */
VICVectAddr = 0;
chSchTimerHandlerI();
}

View File

@ -19,16 +19,41 @@
#include <ch.h>
#include <avr/io.h>
void hwinit(void) {
/*
* I/O ports setup.
* Everything configured as input with pull-up initially.
*/
DDRA = 0;
PORTA = 0xFF;
DDRB = 0;
PORTB = 0xFF;
DDRC = 0;
PORTC = 0xFF;
DDRD = 0;
PORTD = 0xFF;
DDRE = 0;
PORTE = 0xFF;
DDRF = 0;
PORTF = 0xFF;
DDRG = 0;
PORTG = 0xFF;
/*
* Enables Idle mode for SLEEP instruction.
*/
SMCR = 1;
}
void chSysPause(void) {
chThdSetPriority(IDLEPRIO);
asm volatile (
"ldi r18, 1 \n\t" // SE bit
"out 0x33, r18" // SMCR
);
while (TRUE) {
asm volatile ("sleep");
// asm volatile ("sleep");
}
}

View File

@ -19,6 +19,10 @@
#include <ch.h>
#include <avr/io.h>
void hwinit(void);
static BYTE8 waThread1[UserStackSize(32)];
static t_msg Thread1(void *arg) {
@ -31,6 +35,8 @@ static t_msg Thread1(void *arg) {
int main(int argc, char **argv) {
hwinit();
chSysInit();
chThdCreate(NORMALPRIO, 0, waThread1, sizeof(waThread1), Thread1, NULL);
chSysPause();

View File

@ -122,6 +122,17 @@ typedef struct {
#define SOURCE_USB 22
#define INTMASK(n) (1 << (n))
#define ALLINTMASK (INTMASK(SOURCE_WDT) | INTMASK(SOURCE_ARMCore0) | \
INTMASK(SOURCE_ARMCore1) | INTMASK(SOURCE_Timer0) | \
INTMASK(SOURCE_Timer1) | INTMASK(SOURCE_UART0) | \
INTMASK(SOURCE_UART1) | INTMASK(SOURCE_PWM0) | \
INTMASK(SOURCE_I2C0) | INTMASK(SOURCE_SPI0) | \
INTMASK(SOURCE_SPI1) | INTMASK(SOURCE_PLL) | \
INTMASK(SOURCE_RTC) | INTMASK(SOURCE_EINT0) | \
INTMASK(SOURCE_EINT1) | INTMASK(SOURCE_EINT2) | \
INTMASK(SOURCE_EINT3) | INTMASK(SOURCE_ADC0) | \
INTMASK(SOURCE_I2C1) | INTMASK(SOURCE_BOD) | \
INTMASK(SOURCE_ADC1) | INTMASK(SOURCE_USB))
typedef struct {
IOREG32 VIC_IRQStatus;
@ -249,42 +260,6 @@ typedef struct {
IOREG32 UART_TER;
} UART;
/*typedef struct {
union {
IOREG8 UART_RBR;
IOREG8 UART_THR;
IOREG8 UART_DLL;
IOREG8 f1[4];
};
union {
IOREG8 UART_IER;
IOREG8 UART_DLM;
IOREG8 f2[4];
};
union {
IOREG8 UART_IIR;
IOREG8 UART_FCR;
IOREG8 f3[4];
};
IOREG8 UART_LCR;
IOREG8 f4[3];
IOREG8 UART_MCR; // UART1 only
IOREG8 f5[3];
IOREG8 UART_LSR;
IOREG8 f6[3];
IOREG32 unused18;
IOREG8 UART_SCR;
IOREG8 f7[3];
IOREG8 UART_ACR;
IOREG8 f8[3];
IOREG32 unused24;
IOREG8 UART_FDR;
IOREG8 f9[3];
IOREG32 unused2C;
IOREG8 UART_TER;
IOREG8 f10[3];
} UART;*/
#define U0Base ((UART *)0xE000C000)
#define U0RBR (U0Base->UART_RBR)
#define U0THR (U0Base->UART_THR)

View File

@ -146,5 +146,5 @@ void InitSerial(void) {
chFDDInit(&COM2, ib2, sizeof ib2, NULL, ob2, sizeof ob2, OutNotify2);
SetUARTI(U1Base, 38400, LCR_WL8 | LCR_STOP1 | LCR_NOPARITY, FCR_TRIGGER0);
VICIntEnable |= INTMASK(SOURCE_UART0) | INTMASK(SOURCE_UART1);
VICIntEnable = INTMASK(SOURCE_UART0) | INTMASK(SOURCE_UART1);
}

View File

@ -43,7 +43,9 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet.
- Changed the behavior of chEvtWaitTimeout() when the timeout parameter is
set to zero, now it is consistent with all the other syscalls that have a
timeout option.
- Reorganized all the inline definitions into a single file (inline.h).
- Reorganized all the kernel inline definitions into a single file (inline.h).
- Fixed a minor problem in the interrupt initialization code for the LPC214x
demo, regrouped the VIC code into vic.c/vic.h.
*** 0.3.4 ***
- Fixed a problem in chVTSetI().