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

master
gdisirio 2007-10-06 08:58:52 +00:00
parent ff4dd3f8f0
commit d6d799ed48
19 changed files with 334 additions and 123 deletions

View File

@ -62,7 +62,7 @@ UDEFS =
UADEFS =
# List ARM-mode C source files here
ASRC = chcore.c main.c buzzer.c \
ASRC = chcore.c main.c buzzer.c ../../src/lib/evtimer.c \
../../test/test.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 \
@ -92,8 +92,6 @@ AOPT =
TOPT = -mthumb -D THUMB
# Common options here
# NOTE: -mthumb-interwork increases the code size, remove it if you dont have
# Thumb code anywhere in the project.
# NOTE: -ffixed-f7 is only needed if you enabled CH_CURRP_REGISTER_CACHE in chconf.h.
OPT = -O2 -ggdb -fomit-frame-pointer -fno-strict-aliasing
#OPT += -ffixed-f7
@ -117,7 +115,7 @@ LIBS = $(DLIBS) $(ULIBS)
MCFLAGS = -mcpu=$(MCU)
ASFLAGS = $(MCFLAGS) -Wa,-amhls=$(<:.s=.lst) $(ADEFS)
CPFLAGS = $(MCFLAGS) $(OPT) $(WARN) -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS)
CPFLAGS = $(MCFLAGS) $(OPT) $(WARN) -Wa,-ahlms=$(<:.c=.lst) $(DEFS)
LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR)
ODFLAGS = -x --syms
@ -137,15 +135,19 @@ CPFLAGS += -MD -MP -MF .dep/$(@F).d
all: $(OBJS) $(PROJECT).elf $(PROJECT).hex $(PROJECT).bin $(PROJECT).dmp
$(AOBJS) : %.o : %.c
@echo
$(CC) -c $(CPFLAGS) $(AOPT) -I . $(INCDIR) $< -o $@
$(TOBJS) : %.o : %.c
@echo
$(CC) -c $(CPFLAGS) $(TOPT) -I . $(INCDIR) $< -o $@
$(ASMOBJS) : %.o : %.s
@echo
$(AS) -c $(ASFLAGS) $< -o $@
%elf: $(OBJS)
@echo
$(CC) $(ASMOBJS) $(AOBJS) $(TOBJS) $(LDFLAGS) $(LIBS) -o $@
%hex: %elf

View File

@ -98,7 +98,7 @@ extern void chSysUnlock(void);
sizeof(struct stackregs) + (n) + (INT_REQUIRED_STACK))
void chSysHalt(void) __attribute__((noreturn));
void chSysPause(void);
void chSysPause(void) __attribute__((noreturn));
void chSysSwitchI(Context *oldp, Context *newp);
void threadstart(void);
void DefFiqHandler(void);

View File

@ -97,8 +97,8 @@ typedef struct {
#define chSysLock() asm("cli")
#define chSysUnlock() asm("sei")
void chSysHalt(void);
void chSysPause(void);
void chSysHalt(void) __attribute__((noreturn)) ;
void chSysPause(void) __attribute__((noreturn)) ;
void chSysSwitchI(Context *oldp, Context *newp);
#endif /* _CHCORE_H_ */

View File

@ -6,6 +6,10 @@
./license.txt - GPL3 license file.
./src/ - ChibiOS/RT portable kernel source files.
./src/include/ - ChibiOS/RT include files.
./src/lib/ - ChibiOS/RT library code that can be included into
user applications but is not part of the core system.
The code in this directory is meant to be portable,
generic and architecture indipendent.
./src/templates/ - ChibiOS/RT non portable source templates, new ports
are started by copying the templates into a new
directory under ./demos/.
@ -35,7 +39,9 @@ AVR-AT90CANx-GCC - Port on AVER AT90CAN128, not complete yet.
*****************************************************************************
*** 0.3.2 ***
- Removed an obsolete definition in ./src/templates/chtypes.h
- Added a generic events generator timer to the library code.
- Added the "#ifdef __cplusplus" stuff to the header files.
- Removed an obsolete definition in ./src/templates/chtypes.h.
*** 0.3.1 ***
- Test program added to the demos. Telnet the MinGW and MSVS demos and type

View File

@ -92,7 +92,13 @@
#define NULL 0
#endif
#ifdef __cplusplus
extern "C" {
#endif
void chSysInit(void);
#ifdef __cplusplus
}
#endif
#endif /* _CH_H_ */

View File

@ -66,7 +66,6 @@ typedef struct {
t_time dl_dtime;
} DeltaList;
extern DeltaList dlist;
#define chVTDoTickI() \
@ -85,9 +84,15 @@ extern DeltaList dlist;
/*
* Virtual Timers APIs.
*/
#ifdef __cplusplus
extern "C" {
#endif
void chVTInit(void);
void chVTSetI(VirtualTimer *vtp, t_time time, t_vtfunc vtfunc, void *par);
void chVTResetI(VirtualTimer *vtp);
#ifdef __cplusplus
}
#endif
#endif /* CH_USE_VIRTUAL_TIMER */

View File

@ -76,6 +76,9 @@ typedef struct EventSource {
/** Event Handler callback function.*/
typedef void (*t_evhandler)(t_eventid);
#ifdef __cplusplus
extern "C" {
#endif
void chEvtRegister(EventSource *esp, EventListener *elp, t_eventid eid);
void chEvtUnregister(EventSource *esp, EventListener *elp);
void chEvtClear(t_eventmask mask);
@ -88,6 +91,9 @@ t_eventid chEvtWaitTimeout(t_eventmask ewmask,
t_evhandler handlers[],
t_time time);
#endif
#ifdef __cplusplus
}
#endif
#endif /* CH_USE_EVENTS */

View File

@ -55,13 +55,21 @@ typedef struct {
#define list_init(tlp) ((tlp)->p_next = (Thread *)(tlp))
#ifndef CH_OPTIMIZE_SPEED
#ifdef __cplusplus
extern "C" {
#endif
void fifo_insert(Thread *tp, ThreadsQueue *tqp);
Thread *fifo_remove(ThreadsQueue *tqp);
Thread *dequeue(Thread *tp);
void list_insert(Thread *tp, ThreadsList *tlp);
Thread *list_remove(ThreadsList *tlp);
#ifdef __cplusplus
}
#endif
#endif /* CH_OPTIMIZE_SPEED */
#endif /* _LISTS_H_ */
/** @} */

View File

@ -39,6 +39,9 @@
#define chMsgGetI(tp) \
((tp)->p_msgqueue.p_next->p_msg)
#ifdef __cplusplus
extern "C" {
#endif
t_msg chMsgSend(Thread *tp, t_msg msg);
t_msg chMsgWait(void);
t_msg chMsgGet(void);
@ -51,6 +54,9 @@ t_msg chMsgSendWithEvent(Thread *tp, t_msg msg, EventSource *esp);
#ifdef CH_USE_MESSAGES_TIMEOUT
t_msg chMsgSendTimeout(Thread *tp, t_msg msg, t_time time);
#endif
#ifdef __cplusplus
}
#endif
#endif /* CH_USE_MESSAGES */

View File

@ -84,6 +84,9 @@ typedef struct {
#define chOQIsFull(q) \
(chQSpace(q) <= 0)
#ifdef __cplusplus
extern "C" {
#endif
/*
* Input Queues functions. An Input Queue is usually written into by an
* interrupt handler and read from a thread.
@ -106,6 +109,9 @@ void chOQReset(Queue *queue);
void chOQPut(Queue *queue, BYTE8 b);
t_msg chOQGetI(Queue *queue);
t_size chOQWrite(Queue *queue, BYTE8 *buffer, t_size n);
#ifdef __cplusplus
}
#endif
#endif /* CH_USE_QUEUES */
#ifdef CH_USE_QUEUES_HALFDUPLEX
@ -155,6 +161,9 @@ typedef struct {
#define chHDQIsFullReceive(q) \
(chHDQFilledSpace(q) >= chHDQSize(q))
#ifdef __cplusplus
extern "C" {
#endif
void chHDQInit(HalfDuplexQueue *qp, BYTE8 *buffer, t_size size,
t_qnotify inotify, t_qnotify onotify);
t_msg chHDQGetReceive(HalfDuplexQueue *qp);
@ -164,6 +173,9 @@ t_msg chHDQPutReceiveI(HalfDuplexQueue *qp, BYTE8 b);
#ifdef CH_USE_QUEUES_TIMEOUT
t_msg chHDQGetReceiveTimeout(HalfDuplexQueue *qp, t_time time);
#endif
#ifdef __cplusplus
}
#endif
#endif /* CH_USE_QUEUES_HALFDUPLEX */

View File

@ -45,6 +45,9 @@ typedef struct {
/*
* Scheduler APIs.
*/
#ifdef __cplusplus
extern "C" {
#endif
void chSchInit(void);
Thread *chSchReadyI(Thread *tp);
void chSchGoSleepI(t_tstate newstate);
@ -53,6 +56,9 @@ void chSchRescheduleI(void);
void chSchDoRescheduleI(void);
BOOL chSchRescRequiredI(void);
void chSchTimerHandlerI(void);
#ifdef __cplusplus
}
#endif
/**
* Current thread pointer.

View File

@ -37,6 +37,9 @@ typedef struct {
t_cnt s_cnt;
} Semaphore;
#ifdef __cplusplus
extern "C" {
#endif
void chSemInit(Semaphore *sp, t_cnt n);
void chSemReset(Semaphore *sp, t_cnt n);
void chSemResetI(Semaphore *sp, t_cnt n);
@ -54,6 +57,9 @@ void chSemLowerPrioSignal(Semaphore *sp);
void chSemRaisePrioSignalWait(Semaphore *sps, Semaphore *spw);
void chSemLowerPrioSignalWait(Semaphore *sps, Semaphore *spw);
#endif
#ifdef __cplusplus
}
#endif
/**
* Decreases the semaphore counter, this macro can be used when it is ensured

View File

@ -72,6 +72,9 @@ typedef struct {
EventSource sd_sevent;
} FullDuplexDriver;
#ifdef __cplusplus
extern "C" {
#endif
void chFDDInit(FullDuplexDriver *sd,
BYTE8 *ib, t_size isize, t_qnotify inotify,
BYTE8 *ob, t_size osize, t_qnotify onotify);
@ -79,6 +82,9 @@ void chFDDIncomingDataI(FullDuplexDriver *sd, BYTE8 b);
t_msg chFDDRequestDataI(FullDuplexDriver *sd);
void chFDDAddFlagsI(FullDuplexDriver *sd, t_dflags mask);
t_dflags chFDDGetAndClearFlags(FullDuplexDriver *sd);
#ifdef __cplusplus
}
#endif
/** @see chIQRead()*/
#define chFDDRead(sd, b, n) \
@ -128,12 +134,18 @@ typedef struct {
EventSource sd_sevent;
} HalfDuplexDriver;
#ifdef __cplusplus
extern "C" {
#endif
void chHDDInit(HalfDuplexDriver *sd, BYTE8 *b, t_size size,
t_qnotify inotify, t_qnotify onotify);
void chHDDIncomingDataI(HalfDuplexDriver *sd, BYTE8 b);
t_msg chHDDRequestDataI(HalfDuplexDriver *sd);
void chHDDAddFlagsI(HalfDuplexDriver *sd, t_dflags mask);
t_dflags chHDDGetAndClearFlags(HalfDuplexDriver *sd);
#ifdef __cplusplus
}
#endif
/** @see chHDQGetReceive()*/
#define chHDDGetReceive(sd) \

View File

@ -25,18 +25,19 @@
#ifndef _SLEEP_H_
#define _SLEEP_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CH_USE_SLEEP
void chThdSleep(t_time time);
#ifdef CH_USE_SYSTEMTIME
void chThdSleepUntil(t_time time);
t_time chSysGetTime(void);
#endif /* CH_USE_SYSTEMTIME */
#endif /* CH_USE_SLEEP */
#ifdef __cplusplus
}
#endif
#endif /* _SLEEP_H_ */

View File

@ -186,10 +186,22 @@ static INLINE Thread *list_remove(ThreadsList *tlp) {
/*
* Threads APIs.
*/
#ifdef __cplusplus
extern "C" {
#endif
Thread *chThdCreate(t_prio prio, t_tmode mode, void *workspace,
t_size wsize, t_tfunc pf, void *arg);
void chThdResume(Thread *tp);
void chThdExit(t_msg msg);
#ifdef CH_USE_TERMINATE
void chThdTerminate(Thread *tp);
#endif
#ifdef CH_USE_WAITEXIT
t_msg chThdWait(Thread *tp);
#endif
#ifdef __cplusplus
}
#endif
/** Returns the pointer to the \p Thread currently in execution.*/
#define chThdSelf() currp
@ -200,20 +212,11 @@ void chThdExit(t_msg msg);
/** Verifies if the specified thread is in the \p PREXIT state.*/
#define chThdTerminated(tp) ((tp)->p_state == PREXIT)
#ifdef CH_USE_TERMINATE
/**
* Verifies if the current thread has a termination request pending.
*/
#define chThdShouldTerminate() (currp->p_flags & P_TERMINATE)
void chThdTerminate(Thread *tp);
#endif
#ifdef CH_USE_WAITEXIT
t_msg chThdWait(Thread *tp);
#endif
#ifdef CH_USE_EXIT_EVENT
/**
* Returns the exit event source for the specified thread. The source is
* signaled when the thread terminates.
@ -235,7 +238,6 @@ t_msg chThdWait(Thread *tp);
* option is enabled in \p chconf.h.
*/
#define chThdGetExitEventSource(tp) (&(tp)->p_exitesource)
#endif
#endif /* _THREADS_H_ */

68
src/lib/evtimer.c Normal file
View File

@ -0,0 +1,68 @@
/*
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/>.
*/
/**
* @file evtimer.c
* @{
* Event Timer, this timer generates an event at regular intervals. The
* listening threads can use the event to perform time related activities.
* Multiple threads can listen to the same timer.
*/
#include <ch.h>
#include "evtimer.h"
static void tmrcb(void *p) {
EvTimer *etp = p;
chVTSetI(&etp->et_vt, etp->et_interval, tmrcb, etp);
}
/**
* Starts the timer, if the timer was already running then the function has
* no effect.
* @param etp pointer to an initialized \p EvTimer structure.
*/
void evtStart(EvTimer *etp) {
chSysLock();
if (!etp->et_vt.vt_func)
chVTSetI(&etp->et_vt, etp->et_interval, tmrcb, etp);
chSysUnlock();
}
/**
* Stops the timer, if the timer was already stopped then the function has
* no effect.
* @param etp pointer to an initialized \p EvTimer structure.
*/
void evtStop(EvTimer *etp) {
chSysLock();
if (etp->et_vt.vt_func)
chVTResetI(&etp->et_vt);
chSysUnlock();
}
/** @} */

65
src/lib/evtimer.h Normal file
View File

@ -0,0 +1,65 @@
/*
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/>.
*/
/**
* @file evtimer.h
* @{
* Event Timer definitions.
* @see evtimer.c
*/
#ifndef _EVTIMER_H_
#define _EVTIMER_H_
typedef struct {
VirtualTimer et_vt;
EventSource et_es;
t_time et_interval;
} EvTimer;
#ifdef __cplusplus
extern "C" {
#endif
void evtStart(EvTimer *etp);
void evtStop(EvTimer *etp);
#ifdef __cplusplus
}
#endif
/**
* Initializes an \p EvTimer structure.
*/
#define evtInit(et, i) (chEvtInit(&(etp)->et_es), \
(etp)->et_vt.vt_func = NULL, \
(etp)->et_interval = (i))
/**
* Registers the invoking thread as listener on the timer event.
*/
#define evtRegister(etp, el, eid) chEvtRegister(&(etp)->et_es, el, eid)
/**
* Unregisters the invoking thread as listener on the timer event.
*/
#define evtUnregister(etp, el) chEvtUnregister(&(etp)->et_es, el)
#endif /* _EVTIMER_H_ */
/** @} */

View File

@ -35,7 +35,7 @@ static BYTE8 wsT5[UserStackSize(64)];
static Thread *t1, *t2, *t3, *t4, *t5;
static FullDuplexDriver *comp;
static Semaphore sem1, sem2;
static Semaphore sem1;
static void wait(void) {