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

This commit is contained in:
gdisirio 2008-03-06 11:38:11 +00:00
parent 8c39bfc93d
commit a6dbd7a691
11 changed files with 177 additions and 366 deletions

View File

@ -80,8 +80,14 @@ OBJDIR = .
# List C source files here. (C dependencies are automatically generated.)
SRC = ./main.c ./chcore.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
SRC = ../../ports/AVR/chcore.c ../../ports/AVR/avr_serial.c \
../../src/chinit.c ../../src/chdebug.c ../../src/chlists.c ../../src/chdelta.c \
../../src/chschd.c ../../src/chthreads.c ../../src/chsem.c ../../src/chmtx.c \
../../src/chevents.c ../../src/chmsg.c ../../src/chsleep.c ../../src/chqueues.c \
../../src/chserial.c \
../../src/lib/evtimer.c \
../../test/test.c \
board.c main.c
# List C++ source files here. (C dependencies are automatically generated.)
@ -95,7 +101,7 @@ CPPSRC =
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC = ./chcore2.S
ASRC =
# Optimization level, can be [0, 1, 2, 3, s].
@ -115,7 +121,7 @@ DEBUG = dwarf-2
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = ../../src/include
EXTRAINCDIRS = ../../src/include ../../src/lib ../../ports/AVR
# Compiler flag to set the C Standard level.
@ -402,12 +408,13 @@ ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
all: begin gccversion sizebefore build sizeafter end
# Change the build target to build a HEX file or a library.
build: elf hex eep lss sym
build: elf hex bin eep lss sym
#build: lib
elf: $(TARGET).elf
hex: $(TARGET).hex
bin: $(TARGET).bin
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
@ -512,6 +519,11 @@ extcoff: $(TARGET).elf
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.bin: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O binary -R .eeprom $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
@ -593,6 +605,7 @@ clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).bin
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
@ -617,7 +630,7 @@ $(shell mkdir $(OBJDIR) 2>/dev/null)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff \
build elf hex bin eep lss sym coff extcoff \
clean clean_list program debug gdb-config

View File

@ -0,0 +1,87 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT 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 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ch.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "board.h"
#include "avr_serial.h"
ISR(TIMER0_COMP_vect) {
chSysIRQEnterI();
chSysTimerHandlerI();
chSysIRQExitI();
}
/*
* Board initialization code.
*/
void hwinit(void) {
/*
* I/O ports setup.
*/
DDRA = VAL_DDRA;
PORTA = VAL_PORTA;
DDRB = VAL_DDRB;
PORTB = VAL_PORTB;
DDRC = VAL_DDRC;
PORTC = VAL_PORTC;
DDRD = VAL_DDRD;
PORTD = VAL_PORTD;
DDRE = VAL_DDRE;
PORTE = VAL_PORTE;
DDRF = VAL_DDRF;
PORTF = VAL_PORTF;
DDRG = VAL_DDRG;
PORTG = VAL_PORTG;
/*
* External interrupts setup, all disabled initially.
*/
EICRA = 0x00;
EICRB = 0x00;
EIMSK = 0x00;
/*
* Enables Idle mode for SLEEP instruction.
*/
SMCR = (1 << SE);
/*
* Timer 0 setup.
*/
TCCR0A = (1 << WGM01) | (0 << WGM00) | // CTC mode.
(0 << COM0A1) | (0 << COM0A0) | // OC0A disabled (normal I/O).
(0 << CS02) | (1 << CS01) | (1 << CS00); // CLK/64 clock source.
OCR0A = F_CPU / 64 / CH_FREQUENCY - 1;
TCNT0 = 0; // Reset counter.
TIFR0 = (1 << OCF0A); // Reset pending (if any).
TIMSK0 = (1 << OCIE0A); // Interrupt on compare.
/*
* Other initializations.
*/
InitSerial();
}

View File

@ -17,9 +17,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ch.h>
#ifndef _BOARD_H_
#define _BOARD_H_
#include <avr/io.h>
#define BOARD_OLIMEX_AVR_CAN
/*
* All inputs with pullups.
@ -77,61 +78,9 @@
#define VAL_DDRG 0x00
#define VAL_PORTG 0x07
void hwinit(void) {
#define PORTE_LED (1 << 4)
#define PORTE_BUTTON (1 << 5)
/*
* I/O ports setup.
*/
DDRA = VAL_DDRA;
PORTA = VAL_PORTA;
DDRB = VAL_DDRB;
PORTB = VAL_PORTB;
DDRC = VAL_DDRC;
PORTC = VAL_PORTC;
DDRD = VAL_DDRD;
PORTD = VAL_PORTD;
DDRE = VAL_DDRE;
PORTE = VAL_PORTE;
DDRF = VAL_DDRF;
PORTF = VAL_PORTF;
DDRG = VAL_DDRG;
PORTG = VAL_PORTG;
void hwinit(void);
/*
* External interrupts setup, all disabled initially.
*/
EICRA = 0x00;
EICRB = 0x00;
EIMSK = 0x00;
/*
* Enables Idle mode for SLEEP instruction.
*/
SMCR = 1;
/*
* Timer 0 setup.
*/
TCCR0A = (1 << WGM01) | (0 << WGM00) | // CTC mode.
(0 << COM0A1) | (0 << COM0A0) | // OC0A disabled (normal I/O).
(0 << CS02) | (1 << CS01) | (1 << CS00); // CLK/64 clock source.
OCR0A = F_CPU / 64 / CH_FREQUENCY - 1;
TCNT0 = 0; // Reset counter.
TIFR0 = (1 << OCF0A); // Reset pending (if any).
TIMSK0 = (1 << OCIE0A); // Interrupt on compare.
}
void _IdleThread(void *p) {
while (TRUE) {
// asm volatile ("sleep");
}
}
void chSysHalt(void) {
chSysLock();
while (TRUE)
;
}
#endif /* _BOARD_H_ */

View File

@ -17,6 +17,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Configuration file for LPC214x-GCC demo project.
*/
/**
* @addtogroup Config
* @{
@ -25,15 +29,10 @@
#ifndef _CHCONF_H_
#define _CHCONF_H_
/*
* NOTE: this is just documentation for doxigen, the real configuration file
* is the one into the project directories.
*/
/** Configuration option: if specified then time efficient rather than space
* efficient code is used when two possible implementations exist, note
* that this is not related to the compiler optimization options.*/
//#define CH_OPTIMIZE_SPEED
#define CH_OPTIMIZE_SPEED
/** Configuration option: if specified then the Virtual Timers subsystem is
* included in the kernel.*/
@ -151,9 +150,9 @@
* on processors with many registers like ARM cores.
* @note If this option is enabled then ALL the libraries linked to the
* ChibiOS/RT code <b>must</b> be recompiled with the GCC option \p
* -ffixed-\<reg\>.
* -ffixed-<reg>.
*/
//#define CH_CURRP_REGISTER_CACHE "reg"
//#define CH_CURRP_REGISTER_CACHE "r8"
/** Configuration option: Includes basic debug support to the kernel.
* @note the debug support is port-dependent, it may be not present on some

View File

@ -1,116 +0,0 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT 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 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @addtogroup Core
* @{
*/
#ifndef _CHCORE_H_
#define _CHCORE_H_
/*
* Interrupt saved context.
*/
struct extctx {
BYTE8 sr;
BYTE8 r31;
BYTE8 r30;
BYTE8 r27;
BYTE8 r26;
BYTE8 r25;
BYTE8 r24;
BYTE8 r23;
BYTE8 r22;
BYTE8 r21;
BYTE8 r20;
BYTE8 r19;
BYTE8 r18;
BYTE8 r1;
BYTE8 r0;
UWORD16 pc;
};
/*
* System saved context.
*/
struct intctx {
BYTE8 r29;
BYTE8 r28;
BYTE8 r17;
BYTE8 r16;
BYTE8 r15;
BYTE8 r14;
BYTE8 r13;
BYTE8 r12;
BYTE8 r11;
BYTE8 r10;
BYTE8 r9;
BYTE8 r8;
BYTE8 r7;
BYTE8 r6;
BYTE8 r5;
BYTE8 r4;
BYTE8 r3;
BYTE8 r2;
UWORD16 pc;
};
/*
* Port dependent part of the Thread structure, you may add fields in
* this structure.
*/
typedef struct {
struct intctx *sp;
} Context;
/**
* Platform dependent part of the \p chThdCreate() API.
*/
#define SETUP_CONTEXT(workspace, wsize, pf, arg) { \
tp->p_ctx.sp--; \
tp->p_ctx.sp->r2 = (int)pf; \
tp->p_ctx.sp->r3 = (int)pf >> 8; \
tp->p_ctx.sp->r4 = (int)arg; \
tp->p_ctx.sp->r5 = (int)arg >> 8; \
tp->p_ctx.sp->pc = (UWORD16)threadstart; \
}
#define INT_REQUIRED_STACK 0x10
#define StackAlign(n) (n)
#define UserStackSize(n) StackAlign(sizeof(Thread) + \
sizeof(struct intctx) + \
sizeof(struct extctx) + \
(n) + (INT_REQUIRED_STACK))
#define WorkingArea(s, n) BYTE8 s[UserStackSize(n)];
#define chSysLock() asm("cli")
#define chSysUnlock() asm("sei")
#define chSysPuts(msg) {}
#define IDLE_THREAD_STACK_SIZE 8
void _IdleThread(void *p) __attribute__((noreturn));
void chSysHalt(void) __attribute__((noreturn)) ;
void chSysSwitchI(Context *oldp, Context *newp);
void threadstart(void);
#endif /* _CHCORE_H_ */
/** @} */

View File

@ -1,123 +0,0 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT 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 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
.global threadstart
threadstart:
sei
movw r24, r4 // argument
movw r30, r2 // thread function
icall
call chThdExit
.global chSysSwitchI
chSysSwitchI:
push r2
push r3
push r4
push r5
push r6
push r7
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
push r16
push r17
push r28
push r29
movw r30, r24 // Z <- oldp
in r0, _SFR_IO_ADDR(SPL)
st Z, r0
in r0, _SFR_IO_ADDR(SPH)
std Z+1, r0
movw r30, r22 // Z <- newp
ld r0, Z
out _SFR_IO_ADDR(SPL), r0
ldd r0, Z+1
out _SFR_IO_ADDR(SPH), r0
pop r29
pop r28
pop r17
pop r16
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop r7
pop r6
pop r5
pop r4
pop r3
pop r2
ret
.global __vector_17
__vector_17:
push r0
push r1
push r18
push r19
push r20
push r21
push r22
push r23
push r24
push r25
push r26
push r27
push r30
push r31
in r0, _SFR_IO_ADDR(SREG)
push r0
clr r1
call chSysTimerHandlerI
intcommon:
call chSchRescRequiredI
tst r24
breq noschd
call chSchDoRescheduleI
noschd:
pop r0
out _SFR_IO_ADDR(SREG), r0
pop r31
pop r30
pop r27
pop r26
pop r25
pop r24
pop r23
pop r22
pop r21
pop r20
pop r19
pop r18
pop r1
pop r0
reti

View File

@ -1,48 +0,0 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT 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 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CHTYPES_H_
#define _CHTYPES_H_
/*
* Generic types often dependant on the compiler.
*/
#define BOOL char
#define BYTE8 unsigned char
#define SBYTE8 signed char
#define WORD16 int
#define UWORD16 unsigned int
#define LONG32 long
#define ULONG32 unsigned long
#define PTR_EQ int
typedef BYTE8 t_tmode;
typedef BYTE8 t_tstate;
typedef BYTE8 t_tid;
typedef BYTE8 t_prio;
typedef WORD16 t_msg;
typedef BYTE8 t_eventid;
typedef BYTE8 t_eventmask;
typedef UWORD16 t_time;
typedef SBYTE8 t_cnt;
typedef UWORD16 t_size;
#define INLINE inline
#endif /* _CHTYPES_H_ */

View File

@ -18,21 +18,38 @@
*/
#include <ch.h>
#include <evtimer.h>
#include <avr_serial.h>
#include <avr/io.h>
#include "board.h"
void hwinit(void);
static WorkingArea(waThread1, 32);
static t_msg Thread1(void *arg) {
static msg_t Thread1(void *arg) {
while (TRUE) {
chThdSleep(800);
PORTE ^= PORTE_LED;
chThdSleep(500);
}
return 0;
}
static void TimerHandler(eventid_t id) {
msg_t TestThread(void *p);
if (!(PORTE & PORTE_BUTTON))
TestThread(&SER2);
}
int main(int argc, char **argv) {
static EvTimer evt;
static evhandler_t handlers[1] = {
TimerHandler
};
static EventListener el0;
hwinit();
@ -42,13 +59,20 @@ int main(int argc, char **argv) {
*/
chSysInit();
/*
* Event Timer initialization.
*/
evtInit(&evt, 500); /* Initializes an event timer object. */
evtStart(&evt); /* Starts the event timer. */
chEvtRegister(&evt.et_es, &el0, 0); /* Registers on the timer event source. */
/*
* Starts the LED blinker thread.
*/
chThdCreate(NORMALPRIO, 0, waThread1, sizeof(waThread1), Thread1, NULL);
while(TRUE)
/* Do stuff*/ ;
chEvtWait(ALL_EVENTS, handlers);
return 0;
}

View File

@ -0,0 +1,25 @@
*****************************************************************************
** ChibiOS/RT port for Atmel AVR AT90CAN128. **
*****************************************************************************
** TARGET **
The demo runs on an Olimex AVR-CAN board.
** The Demo **
The demo currently just flashes the board LED using a thread. It will be
expanded in next releases.
By pressing the board button the test suite is activated, output on serial
port 2.
** Build Procedure **
The demo was built using the WinAVR toolchain.
** Notes **
The demo requires include files from WinAVR that are not part of the ChibiOS/RT
distribution, please install WinAVR.
http://winavr.sourceforge.net/

View File

@ -1,5 +1,5 @@
*****************************************************************************
** ChibiOS/RT port for Atmel AVRmega128. **
** ChibiOS/RT port for Atmel AVR ATmega128. **
*****************************************************************************
** TARGET **
@ -10,6 +10,7 @@ The demo runs on an Olimex AVR-MT-128 board.
The demo currently just toggles the relay using a thread. It will be expanded
in next releases.
By pressing the button 1 the test suite is activated, output on serial port 2.
** Build Procedure **

View File

@ -42,8 +42,7 @@ AVR-AVRmega128-GCC - Port on AVRmega128, experimental. A special thanks to
Vladimir for the work done on the AVR port. The demo
program targets the Olimex AVR-MT-128 mini terminal
board.
AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet, scheduled
for a complete rewrite.
AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not tested on hardware yet.
*****************************************************************************
*** Plans ***
@ -72,9 +71,10 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet, scheduled
the size_t type defined into stddef.h. Some type names were modified in
order to not match commonly used type names.
- The above changes have an impact on some API prototypes but we can't help
it, the change was required because the type names were the main concern of
it, the change was required because the type names were a concern for
some users.
- Implemented a serial driver in the AVR port.
- Reworked the AVR AT90CAN128 port to share the common AVR code.
- Modified the test suite to be compatible with 8 bit micros.
- MSVC demo dropped, it is still possible to use the MinGW demo as simulator
in Win32.