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

master
gdisirio 2007-09-28 18:42:04 +00:00
parent 95b238fc86
commit 9a0ef300bc
11 changed files with 163 additions and 98 deletions

View File

@ -23,7 +23,7 @@
#include "lpc214x_serial.h" #include "lpc214x_serial.h"
#include "buzzer.h" #include "buzzer.h"
static BYTE8 waThread1[UserStackSize(16)]; static BYTE8 waThread1[UserStackSize(32)];
static t_msg Thread1(void *arg) { static t_msg Thread1(void *arg) {
@ -40,7 +40,7 @@ static t_msg Thread1(void *arg) {
return 0; return 0;
} }
static BYTE8 waThread2[UserStackSize(16)]; static BYTE8 waThread2[UserStackSize(32)];
static t_msg Thread2(void *arg) { static t_msg Thread2(void *arg) {
@ -53,7 +53,7 @@ static t_msg Thread2(void *arg) {
return 0; return 0;
} }
static BYTE8 waThread3[UserStackSize(16)]; static BYTE8 waThread3[UserStackSize(32)];
static t_msg Thread3(void *arg) { static t_msg Thread3(void *arg) {

View File

@ -4,7 +4,7 @@
# Project related configuration options # Project related configuration options
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
PROJECT_NAME = ChibiOS/RT PROJECT_NAME = ChibiOS/RT
PROJECT_NUMBER = "0.2.1 alpha" PROJECT_NUMBER = "0.3.0 beta"
OUTPUT_DIRECTORY = . OUTPUT_DIRECTORY = .
CREATE_SUBDIRS = NO CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English OUTPUT_LANGUAGE = English
@ -121,7 +121,7 @@ EXCLUDE_PATTERNS =
EXAMPLE_PATH = EXAMPLE_PATH =
EXAMPLE_PATTERNS = * EXAMPLE_PATTERNS = *
EXAMPLE_RECURSIVE = NO EXAMPLE_RECURSIVE = NO
IMAGE_PATH = IMAGE_PATH = ./img
INPUT_FILTER = INPUT_FILTER =
FILTER_PATTERNS = FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO FILTER_SOURCE_FILES = NO

View File

@ -47,8 +47,77 @@
* memory image.</li> * memory image.</li>
* <li>Almost totally written in C with little ASM code required for ports.</li> * <li>Almost totally written in C with little ASM code required for ports.</li>
* </ul> * </ul>
*
* ChibiOS/RT architecture:<br><br>
* @subpage Concepts
*/ */
/**
* @page Concepts Concepts
* @{
* @section naming Naming Conventions
* ChibiOS/RT APIs are all named following this convention:
* \a ch\<group\>\<action\>\<suffix\>().
* The possible groups are: \a Sys, \a Sch, \a VT, \a Thd, \a Sem, \a Evt,
* \a Msg, \a IQ, \a OQ, \a HQ,\a FDD, \a HDD.
* The suffix is not present for normal APIs but can be one of
* the following: "I" for APIs meant to be invoked from an interrupt handler
* or within the system mutex zone but not from user code, "S" for APIs only
* useable from within the system mutex zone but not from interrupt handlers
* or user code. The APIs without suffix can be invoked only from the user
* code.<br>
* Examples: \p chThdCreate(), \p chSemSignalI(), \p chIQGetTimeout().
*
* @section scheduling Scheduling
* The strategy is very simple the currently ready thread with the highest
* priority is executed. If more than one thread with equal priority are
* eligible for execution then they are executed in a round-robin way, the
* CPU time slice constant is configurable. The ready list is a double linked
* list of threads ordered by priority.
* @image html readylist.png
* Note that the currently running thread is not in the ready list, the list
* only contains the threads ready to be executed but still actually waiting.
*
* @section warea Thread Working Area
* Each thread has its own stack, a Thread structure and a registers dump
* structure. All the structures are allocated into a "Thread working area",
* a thread private heap, usually allocated in a char array declared in your
* code, there is not a central threads table or list, this means you can
* have as many threads you want as long you have enough available RAM
* memory. The threads do not use any memory outside the allocated working
* area.<br>
* @image html workspace.png
* <br>
* Note that the registers dump is only present when the Thread is not
* running, the context switching is done by pushing the registers on the
* stack of the switched-out thread and popping the registers of the
* switched-in thread from its stack.
*
* @section sysmutex System Mutex Zone
* It is the code within the OS that cannot be preempted, this code is
* everything between the \p chSysLock() and \p chSysUnlock() API calls.
* The implementation of the APIs in most cases just enables/disables the
* interrupts. Of course the code in the system mutex zone must be as short
* and efficient possible as it affects the RT performance of the whole
* system. The worst case response time is affected by the longest code
* path in the system mutex zone or interrupt handler.
* @code
* // User code, not critical, preemption possible.
* chSysLock();
* ...
* // System critical code, preemption delayed.
* ...
* chSysUnlock();
* // User code, preemption possible again.
* @endcode
* Applications usually do not need to put code into the system mutex zone
* unless you are implementing device drivers or special synchronization
* primitives, everything else can be implemented by using semaphores,
* messages or events.
*/
/** @} */
/** /**
* @defgroup Kernel Kernel * @defgroup Kernel Kernel
* @{ * @{

BIN
docs/img/readylist.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

BIN
docs/img/workspace.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -32,6 +32,15 @@ LPC214x-GCC - ChibiOS/RT port for ARM7 LPC2148, the demo targets the
*** Releases *** *** Releases ***
***************************************************************************** *****************************************************************************
*** 0.3.0 ***
- ChibiOS/RT goes beta.
- Diet for the threads code, some simple APIs become macros.
- Thread Local Storage implemented as a single API: chThdLS().
The API simply returns a pointer into the thread working area, see the
documentation on the web site.
- Moved some documentation and images from the web site into the Doxigen
generated HTMLs.
*** 0.2.1 *** *** 0.2.1 ***
- Optimizations in the RT semaphores subsystem. The support for this - Optimizations in the RT semaphores subsystem. The support for this
subsystem should still be considered experimental and further changes may subsystem should still be considered experimental and further changes may

View File

@ -62,11 +62,11 @@ t_time chSysGetTime(void) {
* option is enabled in \p chconf.h. * option is enabled in \p chconf.h.
*/ */
void chThdSleepUntil(t_time time) { void chThdSleepUntil(t_time time) {
VirtualTimer t; VirtualTimer vt;
chSysLock(); chSysLock();
chVTSetI(&t, (t_time)(time - stime), (t_vtfunc)chSchReadyI, currp); chVTSetI(&vt, (t_time)(time - stime), (t_vtfunc)chSchReadyI, currp);
chSchGoSleepI(PRSLEEP); chSchGoSleepI(PRSLEEP);
chSysUnlock(); chSysUnlock();

View File

@ -129,17 +129,6 @@ Thread *chThdCreate(t_prio prio, t_tmode mode, void *workspace,
return tp; return tp;
} }
/**
* Verifies if the specified thread is in the \p PREXIT state.
* @param tp the pointer to the thread
* @return \p TRUE if the thread is ended else \p FALSE. \p TRUE ensures that
* a subsequent call to \p chThdWait() would not block.
*/
BOOL chThdTerminated(Thread *tp) {
return tp->p_state == PREXIT;
}
#ifdef CH_USE_RESUME #ifdef CH_USE_RESUME
/** /**
* Resumes a thread created with the \p P_SUSPENDED option. * Resumes a thread created with the \p P_SUSPENDED option.
@ -176,17 +165,6 @@ void chThdTerminate(Thread *tp) {
chSysUnlock(); chSysUnlock();
} }
/**
* Verifies if the current thread has a termination request pending.
* @return \p TRUE if the termination was requested. The thread should terminate
* as soon it is ready to do so.
*/
BOOL chThdShouldTerminate(void) {
return currp->p_flags & P_TERMINATE ? TRUE : FALSE;
}
#endif #endif
/** /**
@ -234,31 +212,4 @@ t_msg chThdWait(Thread *tp) {
} }
#endif /* CH_USE_WAITEXIT */ #endif /* CH_USE_WAITEXIT */
#ifdef CH_USE_EXIT_EVENT
/**
* Returns the exit event source for the specified thread. The source is
* signaled when the thread terminates.
* @param tp the pointer to the thread
* @note When registering on a thread termination make sure the thread
* is still alive, if you do that after the thread termination
* then you would miss the event. There are two ways to ensure
* this:<br>
* <ul>
* <li>Create the thread suspended, register on the event source
* and then resume the thread (recommended).</li>
* <li>Create the thread with a lower priority then register on it.
* This does not work if the hardware is capable of multiple
* physical threads.</li>
* </ul>
* @note You dont need to unregister from a terminated thread because
* the event source becomes inactive.
* @note The function is available only if the \p CH_USE_EXIT_EVENT
* option is enabled in \p chconf.h.
*/
EventSource *chThdGetExitEventSource(Thread *tp) {
return &tp->p_exitesource;
}
#endif /* CH_USE_EXIT_EVENT */
/** @} */ /** @} */

View File

@ -182,19 +182,55 @@ static INLINE void enqueue(Thread *tp, ThreadsQueue *tqp) {
/* /*
* Threads APIs. * Threads APIs.
*/ */
#define chThdSelf() currp
Thread *chThdCreate(t_prio prio, t_tmode mode, void *workspace, Thread *chThdCreate(t_prio prio, t_tmode mode, void *workspace,
t_size wsize, t_tfunc pf, void *arg); t_size wsize, t_tfunc pf, void *arg);
void chThdResume(Thread *tp); void chThdResume(Thread *tp);
void chThdTerminate(Thread *tp);
BOOL chThdShouldTerminate(void);
BOOL chThdTerminated(Thread *tp);
void chThdExit(t_msg msg); void chThdExit(t_msg msg);
/** Returns the pointer to the \p Thread currently in execution.*/
#define chThdSelf() currp
/** Returns the pointer to the \p Thread local storage area, if any.*/
#define chThdLS() (void *)(currp + 1)
/** 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 #ifdef CH_USE_WAITEXIT
t_msg chThdWait(Thread *tp); t_msg chThdWait(Thread *tp);
#endif #endif
#ifdef CH_USE_EXIT_EVENT #ifdef CH_USE_EXIT_EVENT
EventSource *chThdGetExitEventSource(Thread *tp); /**
* Returns the exit event source for the specified thread. The source is
* signaled when the thread terminates.
* @param tp the pointer to the thread
* @note When registering on a thread termination make sure the thread
* is still alive, if you do that after the thread termination
* then you would miss the event. There are two ways to ensure
* this:<br>
* <ul>
* <li>Create the thread suspended, register on the event source
* and then resume the thread (recommended).</li>
* <li>Create the thread with a lower priority then register on it.
* This does not work if the hardware is capable of multiple
* physical threads.</li>
* </ul>
* @note You dont need to unregister from a terminated thread because
* the event source becomes inactive.
* @note The function is available only if the \p CH_USE_EXIT_EVENT
* option is enabled in \p chconf.h.
*/
#define chThdGetExitEventSource(tp) (&(tp)->p_exitesource)
#endif #endif
#endif /* _THREADS_H_ */ #endif /* _THREADS_H_ */

View File

@ -37,7 +37,7 @@
void chSysPause(void) {} void chSysPause(void) {}
/** /**
* Abonormal system termination handler. Invoked by the ChobiOS/RT when an * Abonormal system termination handler. Invoked by the ChibiOS/RT when an
* abnormal unrecoverable condition is met. * abnormal unrecoverable condition is met.
*/ */
void chSysHalt(void) {} void chSysHalt(void) {}

View File

@ -39,7 +39,7 @@ struct stackregs {
} }
/** /**
* Enters the ChobiOS/RT system mutual exclusion zone, the implementation is * Enters the ChibiOS/RT system mutual exclusion zone, the implementation is
* architecture dependent, on single core systems usually this function * architecture dependent, on single core systems usually this function
* just disables the interrupts. * just disables the interrupts.
* @note The code in the system mutual exclusion zone must be as light and * @note The code in the system mutual exclusion zone must be as light and
@ -50,7 +50,7 @@ struct stackregs {
#define chSysLock() #define chSysLock()
/** /**
* Leaves the ChobiOS/RT system mutual exclusion zone, the implementation is * Leaves the ChibiOS/RT system mutual exclusion zone, the implementation is
* architecture dependent, on single core systems usually this function * architecture dependent, on single core systems usually this function
* just enables the interrupts. * just enables the interrupts.
* @note The code in the system mutual exclusion zone must be as light and * @note The code in the system mutual exclusion zone must be as light and