aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-03-27 12:33:31 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-03-27 12:33:31 +0000
commit165bcc4a0708ff3252fe73156eace36b5980dbf9 (patch)
tree713cd625a9645d3313a773f696e3ad09df58b93b
parentef14f74f92fb52d0028eb36b7b48b7e7c4ef52c4 (diff)
downloadChibiOS-165bcc4a0708ff3252fe73156eace36b5980dbf9.tar.gz
ChibiOS-165bcc4a0708ff3252fe73156eace36b5980dbf9.tar.bz2
ChibiOS-165bcc4a0708ff3252fe73156eace36b5980dbf9.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@249 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--demos/ARM7-LPC214x-G++/Makefile2
-rw-r--r--demos/ARM7-LPC214x-G++/main.cpp52
-rw-r--r--readme.txt10
-rw-r--r--src/chsem.c12
-rw-r--r--src/include/semaphores.h4
-rw-r--r--src/lib/ch.cpp13
-rw-r--r--src/lib/ch.hpp76
-rw-r--r--test/test.h33
8 files changed, 134 insertions, 68 deletions
diff --git a/demos/ARM7-LPC214x-G++/Makefile b/demos/ARM7-LPC214x-G++/Makefile
index 087fa89d9..f2bdcd2ac 100644
--- a/demos/ARM7-LPC214x-G++/Makefile
+++ b/demos/ARM7-LPC214x-G++/Makefile
@@ -90,7 +90,7 @@ TSRC =
ASMSRC = ../../ports/ARM7-LPC214x/crt0.s ../../ports/ARM7/chsys.s
# List all user directories here
-UINCDIR = ../../src/include ../../src/lib \
+UINCDIR = ../../src/include ../../src/lib ../../test \
../../ports/ARM7 ../../ports/ARM7-LPC214x
# List the user directory to look for the libraries here
diff --git a/demos/ARM7-LPC214x-G++/main.cpp b/demos/ARM7-LPC214x-G++/main.cpp
index b3c4f8e45..1d8acfb5e 100644
--- a/demos/ARM7-LPC214x-G++/main.cpp
+++ b/demos/ARM7-LPC214x-G++/main.cpp
@@ -18,7 +18,9 @@
*/
#include <ch.hpp>
+
#include <evtimer.h>
+#include <test.h>
#include <lpc214x.h>
#include <lpc214x_serial.h>
@@ -29,9 +31,10 @@ using namespace chibios_rt;
* LED blinking sequences.
*/
#define SLEEP 0
-#define STOP 1
-#define BITCLEAR 2
-#define BITSET 3
+#define GOTO 1
+#define STOP 2
+#define BITCLEAR 3
+#define BITSET 4
typedef struct {
uint8_t action;
@@ -43,7 +46,8 @@ bitop_t LED1_sequence[] =
{BITCLEAR, 0x00000400},
{SLEEP, 200},
{BITSET, 0x00000400},
- {SLEEP, 1800}
+ {SLEEP, 1800},
+ {GOTO, 0}
};
bitop_t LED2_sequence[] =
@@ -52,7 +56,8 @@ bitop_t LED2_sequence[] =
{BITCLEAR, 0x00000800},
{SLEEP, 200},
{BITSET, 0x00000800},
- {SLEEP, 800}
+ {SLEEP, 1800},
+ {GOTO, 1}
};
bitop_t LED3_sequence[] =
@@ -60,13 +65,14 @@ bitop_t LED3_sequence[] =
{BITCLEAR, 0x80000000},
{SLEEP, 200},
{BITSET, 0x80000000},
- {SLEEP, 300}
+ {SLEEP, 300},
+ {GOTO, 0}
};
/**
- * LED blinker thread class.
+ * Blinker thread class. It can drive LEDs or other output pins.
*/
-class BlinkerThread : chibios_rt::BaseThread {
+class BlinkerThread : BaseThread {
private:
WorkingArea(wa, 64);
bitop_t *base, *curr, *top;
@@ -79,6 +85,9 @@ protected:
case SLEEP:
Sleep(curr->value);
break;
+ case GOTO:
+ curr = &base[curr->value];
+ continue;
case STOP:
return 0;
case BITCLEAR:
@@ -88,23 +97,17 @@ protected:
IO0SET = curr->value;
break;
}
- if (++curr >= top)
- curr = base;
+ curr++;
}
}
public:
- BlinkerThread(bitop_t *sequence, int n) : BaseThread(NORMALPRIO, 0, wa, sizeof wa) {
+ BlinkerThread(bitop_t *sequence) : BaseThread(NORMALPRIO, 0, wa, sizeof wa) {
base = curr = sequence;
- top = sequence + n;
}
};
-extern "C" {
- msg_t TestThread(void *p);
-}
-
/*
* Executed as event handler at 500mS intervals.
*/
@@ -130,11 +133,18 @@ int main(int argc, char **argv) {
evtStart(&evt); /* Starts the event timer. */
chEvtRegister(&evt.et_es, &el0, 0); /* Registers on the timer event source. */
- BlinkerThread blinker1(LED1_sequence, sizeof(LED1_sequence) / sizeof(bitop_t));
- BlinkerThread blinker2(LED2_sequence, sizeof(LED2_sequence) / sizeof(bitop_t));
- BlinkerThread blinker3(LED3_sequence, sizeof(LED3_sequence) / sizeof(bitop_t));
-
- while(1)
+ /*
+ * Starts serveral instances of the BlinkerThread class, each one operating
+ * on a different LED.
+ */
+ BlinkerThread blinker1(LED1_sequence);
+ BlinkerThread blinker2(LED2_sequence);
+ BlinkerThread blinker3(LED3_sequence);
+
+ /*
+ * Serves timer events.
+ */
+ while (true)
Event::Wait(ALL_EVENTS, evhndl);
return 0;
diff --git a/readme.txt b/readme.txt
index 52554c513..f6728df02 100644
--- a/readme.txt
+++ b/readme.txt
@@ -32,6 +32,9 @@ ARM7-LPC214x-GCC - ChibiOS/RT port for ARM7 LPC2148, the demo targets
other boards. The demo can be compiled using YAGARTO
or any other GCC-based ARM toolchain. Full demo.
ARM7-LPC214x-GCC-min - Minimal demo for LPC214X.
+ARM7-LPC214x-G++ - Yet another LPC214X demo but this one is done using
+ G++ in order to provide a C++ template project to the
+ ChibiOS/RT users.
ARM7-AT91SAM7X-GCC - Port for Atmel AT91SAM7X256. The demo program targets
the Olimex SAM7-EX256 board.
ARMCM3-ST32F103-GCC - ARM Cortex-M3 port, work in progress, not complete
@@ -68,12 +71,17 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
- NEW: Added a new LPC2148 demo using the new C++ wrapper, it is a good
example of C++ used for an embedded application. The demo does not use RTTI
nor standard libraries so the resulting code is very compact.
+- Enhanced the chSemSignalWait() API to return the wakeup message just like
+ the other "Wait" semaphore functions.
- Fixed a minor problem in the ARM7 port, the extctx structure definition was
missing one field, the effect was to allocate stacks 4 bytes shorter than
the declared size.
- Fixed a compile time error into the chThdSleepUntil() macro.
- Fixes in various headers to make some macros compatible with both C and C++.
-- More work on the ARM-CM3 port but it is still not complete.
+- Fixed a regression in the LPC214x minimal demo that broke interrupt
+ handling.
+- Some fixes to the doxigen documentation.
+- More work done on the ARM-CM3 port but it is still not complete.
*** 0.6.1 ***
- Removed some redundant checks from the scheduler code: improved threads
diff --git a/src/chsem.c b/src/chsem.c
index 14b8567ad..d1199f072 100644
--- a/src/chsem.c
+++ b/src/chsem.c
@@ -188,10 +188,12 @@ void chSemSignalI(Semaphore *sp) {
* Performs atomic signal and wait operations on two semaphores.
* @param sps pointer to a \p Semaphore structure to be signaled
* @param spw pointer to a \p Semaphore structure to be wait on
- * @note The function is available only if the \p CH_USE_SEMAPHORES
+ * @return the function can return \p RDY_OK or \p RDY_RESET.
+ * @note The function is available only if the \p CH_USE_SEMSW
* option is enabled in \p chconf.h.
*/
-void chSemSignalWait(Semaphore *sps, Semaphore *spw) {
+msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) {
+ msg_t msg;
chSysLock();
@@ -202,11 +204,15 @@ void chSemSignalWait(Semaphore *sps, Semaphore *spw) {
fifo_insert(currp, &spw->s_queue);
currp->p_wtsemp = spw;
chSchGoSleepS(PRWTSEM);
+ msg = currp->p_rdymsg;
}
- else
+ else {
chSchRescheduleS();
+ msg = RDY_OK;
+ }
chSysUnlock();
+ return msg;
}
#endif /* CH_USE_SEMSW */
diff --git a/src/include/semaphores.h b/src/include/semaphores.h
index c894629a4..45486874b 100644
--- a/src/include/semaphores.h
+++ b/src/include/semaphores.h
@@ -51,7 +51,9 @@ extern "C" {
#endif
void chSemSignal(Semaphore *sp);
void chSemSignalI(Semaphore *sp);
- void chSemSignalWait(Semaphore *sps, Semaphore *spw);
+#ifdef CH_USE_SEMSW
+ msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw);
+#endif
#ifdef __cplusplus
}
#endif
diff --git a/src/lib/ch.cpp b/src/lib/ch.cpp
index ad4be5f4d..d1e739915 100644
--- a/src/lib/ch.cpp
+++ b/src/lib/ch.cpp
@@ -70,13 +70,11 @@ namespace chibios_rt {
* chibios_rt::BaseThread *
*------------------------------------------------------------------------*/
static msg_t thdstart(void *arg) {
- BaseThread *btp = (BaseThread *)arg;
- return btp->Main();
+ return ((BaseThread *)arg)->Main();
}
BaseThread::BaseThread(tprio_t prio, tmode_t mode, void *workspace, size_t wsize) {
- msg_t thdstart(void *arg);
thread_ref = chThdCreate(prio, mode, workspace, wsize, thdstart, this);
}
@@ -149,7 +147,7 @@ namespace chibios_rt {
bool BaseThread::IsPendingMessage(void) {
- return chMsgIsPendingI(thread_ref);
+ return chMsgIsPendingI(currp);
}
#endif /* CH_USE_MESSAGES */
@@ -188,6 +186,13 @@ namespace chibios_rt {
chSemSignal(&sem);
}
+
+#ifdef CH_USE_SEMSW
+ msg_t Semaphore::SignalWait(Semaphore *ssem, Semaphore *wsem) {
+
+ return chSemSignalWait(&ssem->sem, &wsem->sem);
+ }
+#endif /* CH_USE_SEMSW */
#endif /* CH_USE_SEMAPHORES */
#ifdef CH_USE_MUTEXES
diff --git a/src/lib/ch.hpp b/src/lib/ch.hpp
index 9f46b757b..d9fffc229 100644
--- a/src/lib/ch.hpp
+++ b/src/lib/ch.hpp
@@ -92,40 +92,6 @@ namespace chibios_rt {
* function /p Main().
*/
class BaseThread {
- protected:
- /**
- * Thread exit.
- */
-// __attribute__((noreturn))
- void Exit(msg_t msg);
-
- /**
- * Change thread priority.
- */
- void SetPriority(tprio_t newprio);
-
-#ifdef CH_USE_MESSAGES
- /**
- * Waits for a message and returns it.
- */
- msg_t WaitMessage(void);
-
- /**
- * Returns an enqueued message or /p NULL.
- */
- msg_t GetMessage(void);
-
- /**
- * Releases the next message in queue with a reply.
- */
- void ReleaseMessage(msg_t msg);
-
- /**
- * Returns true if there is at least one message in queue.
- */
- bool IsPendingMessage(void);
-#endif /* CH_USE_MESSAGES */
-
public:
::Thread *thread_ref;
@@ -134,6 +100,11 @@ namespace chibios_rt {
*/
BaseThread(tprio_t prio, tmode_t mode, void *workspace, size_t wsize);
+ /**
+ * Thread exit.
+ */
+ static void Exit(msg_t msg);
+
#ifdef CH_USE_WAITEXIT
/**
* Synchronization on Thread exit.
@@ -148,6 +119,11 @@ namespace chibios_rt {
void Resume(void);
#endif /* CH_USE_RESUME */
+ /**
+ * Change thread priority.
+ */
+ static void SetPriority(tprio_t newprio);
+
#ifdef CH_USE_TERMINATE
/**
* Requests thread termination.
@@ -159,13 +135,13 @@ namespace chibios_rt {
/**
* Suspends the thread execution for the specified number of system ticks.
*/
- void Sleep(systime_t n);
+ static void Sleep(systime_t n);
#ifdef CH_USE_SYSTEMTIME
/**
* Suspends the thread execution until the specified time arrives.
*/
- void SleepUntil(systime_t time);
+ static void SleepUntil(systime_t time);
#endif /* CH_USE_SYSTEMTIME */
#endif /* CH_USE_SLEEP */
@@ -174,12 +150,31 @@ namespace chibios_rt {
* Sends a message to the thread and returns the answer.
*/
msg_t SendMessage(msg_t msg);
+
+ /**
+ * Waits for a message and returns it.
+ */
+ static msg_t WaitMessage(void);
+
+ /**
+ * Returns an enqueued message or /p NULL.
+ */
+ static msg_t GetMessage(void);
+
+ /**
+ * Releases the next message in queue with a reply.
+ */
+ static void ReleaseMessage(msg_t msg);
+
+ /**
+ * Returns true if there is at least one message in queue.
+ */
+ static bool IsPendingMessage(void);
#endif /* CH_USE_MESSAGES */
/**
* Thread body function.
*/
-// __attribute__((naked))
virtual msg_t Main(void);
};
@@ -217,6 +212,13 @@ namespace chibios_rt {
* Signal operation on the semaphore.
*/
void Signal(void);
+
+#ifdef CH_USE_SEMSW
+ /**
+ * Atomic signal and wait operations.
+ */
+ msg_t SignalWait(Semaphore *ssem, Semaphore *wsem);
+#endif /* CH_USE_SEMSW */
};
#endif /* CH_USE_SEMAPHORES */
diff --git a/test/test.h b/test/test.h
new file mode 100644
index 000000000..b05f9aa61
--- /dev/null
+++ b/test/test.h
@@ -0,0 +1,33 @@
+/*
+ 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>
+
+#ifndef _TEST_H_
+#define _TEST_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ msg_t TestThread(void *p);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _TEST_H_ */