git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@95 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
195a9c7951
commit
4fc627f08b
|
@ -52,8 +52,8 @@ void InitBuzzer(void) {
|
||||||
TC *tc = T1Base;
|
TC *tc = T1Base;
|
||||||
StopCounter(tc);
|
StopCounter(tc);
|
||||||
tc->TC_CTCR = 0; // Clock source is PCLK.
|
tc->TC_CTCR = 0; // Clock source is PCLK.
|
||||||
tc->TC_PR = 0; // Prescaler disabled.
|
tc->TC_PR = 0; // Prescaler disabled.
|
||||||
tc->TC_MCR = 2; // Clear TC on match MR0.
|
tc->TC_MCR = 2; // Clear TC on match MR0.
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stop(void *p) {
|
static void stop(void *p) {
|
||||||
|
|
|
@ -140,14 +140,15 @@ void hwinit(void) {
|
||||||
InitBuzzer();
|
InitBuzzer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void chSysPause(void) {
|
/*
|
||||||
|
* System idle thread loop.
|
||||||
chThdSetPriority(IDLEPRIO);
|
*/
|
||||||
|
void _IdleThread(void *p) {
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
// Note, it is disabled because it causes trouble with the JTAG probe.
|
// Note, it is disabled because it causes trouble with the JTAG probe.
|
||||||
// Enable it in the final code only.
|
// Enable it in the final code only.
|
||||||
// PCON = 1; /* Stops CPU clock until next interrupt. */
|
// PCON = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,10 @@ extern void chSysUnlock(void);
|
||||||
#define UserStackSize(n) (sizeof(Thread) + \
|
#define UserStackSize(n) (sizeof(Thread) + \
|
||||||
sizeof(struct stackregs) + (n) + (INT_REQUIRED_STACK))
|
sizeof(struct stackregs) + (n) + (INT_REQUIRED_STACK))
|
||||||
|
|
||||||
|
|
||||||
|
#define IDLE_THREAD_STACK_SIZE 8
|
||||||
|
void _IdleThread(void *p) __attribute__((noreturn));
|
||||||
|
|
||||||
void chSysHalt(void) __attribute__((noreturn));
|
void chSysHalt(void) __attribute__((noreturn));
|
||||||
void chSysPause(void) __attribute__((noreturn));
|
void chSysPause(void) __attribute__((noreturn));
|
||||||
void chSysSwitchI(Context *oldp, Context *newp);
|
void chSysSwitchI(Context *oldp, Context *newp);
|
||||||
|
|
|
@ -25,18 +25,6 @@
|
||||||
#include "buzzer.h"
|
#include "buzzer.h"
|
||||||
#include "evtimer.h"
|
#include "evtimer.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* System Idle Thread, this thread only runs when on other threads in the
|
|
||||||
* system require the CPU.
|
|
||||||
* The role of this thread is to minimize the power consumption when idling
|
|
||||||
* and serve the interrupts.
|
|
||||||
*/
|
|
||||||
static BYTE8 waIdleThread[UserStackSize(16)];
|
|
||||||
static t_msg IdleThread(void *arg) {
|
|
||||||
|
|
||||||
chSysPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Red LEDs blinker thread, times are in milliseconds.
|
* Red LEDs blinker thread, times are in milliseconds.
|
||||||
*/
|
*/
|
||||||
|
@ -138,15 +126,6 @@ int main(int argc, char **argv) {
|
||||||
*/
|
*/
|
||||||
chSysInit();
|
chSysInit();
|
||||||
|
|
||||||
/*
|
|
||||||
* This thread has the lowest priority in the system, its role is just to
|
|
||||||
* execute the chSysPause() and serve interrupts in its context.
|
|
||||||
* In ChibiOS/RT at least one thread in the system *must* execute
|
|
||||||
* chThdPause(), it can be done in a dedicated thread or in the main()
|
|
||||||
* function (that would never exit the call).
|
|
||||||
*/
|
|
||||||
chThdCreate(IDLEPRIO, 0, waIdleThread, sizeof(waIdleThread), IdleThread, NULL);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If a button is pressed during the reset then the blinking leds threads
|
* If a button is pressed during the reset then the blinking leds threads
|
||||||
* are not started in order to make accurate benchmarks.
|
* are not started in order to make accurate benchmarks.
|
||||||
|
@ -163,7 +142,7 @@ int main(int argc, char **argv) {
|
||||||
chThdSetPriority(NORMALPRIO);
|
chThdSetPriority(NORMALPRIO);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Normal main() activity, in this demo it server events incoming from
|
* Normal main() activity, in this demo it serves events generated by
|
||||||
* various sources.
|
* various sources.
|
||||||
*/
|
*/
|
||||||
evtInit(&evt, 500); /* Initializes an event timer object. */
|
evtInit(&evt, 500); /* Initializes an event timer object. */
|
||||||
|
|
|
@ -39,6 +39,13 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet.
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
|
|
||||||
*** 0.4.1 ***
|
*** 0.4.1 ***
|
||||||
|
- Modified the initialization code in order to have a dedicated idle thread in
|
||||||
|
the system, now the main() function behaves like a normal thread after
|
||||||
|
executing chSysInit() and can use all the ChibiOS/RT APIs (it was required
|
||||||
|
to run the idle loop in previous versions).
|
||||||
|
Now it is also possible to use ChibiOS/RT with a single main() thread and
|
||||||
|
just use it for the I/O capabilities, Virtual Timers and events. You don't
|
||||||
|
have to use multiple threads if you don't really need to.
|
||||||
- Cleaned up the LPC2148 demo in main.c, it is now well documented and
|
- Cleaned up the LPC2148 demo in main.c, it is now well documented and
|
||||||
explains everything, I assumed too much stuff to be "obvious".
|
explains everything, I assumed too much stuff to be "obvious".
|
||||||
- Added a spreadsheet in the documentation that describes the advantages
|
- Added a spreadsheet in the documentation that describes the advantages
|
||||||
|
@ -51,7 +58,7 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet.
|
||||||
is bad for a RTOS. This option however increases the code size slightly
|
is bad for a RTOS. This option however increases the code size slightly
|
||||||
because of the alignment gaps.
|
because of the alignment gaps.
|
||||||
- Fine tuning in the scheduler code for improved performance, deeper
|
- Fine tuning in the scheduler code for improved performance, deeper
|
||||||
inlining and small changes.
|
inlining and small changes, about 5% better scheduler performance.
|
||||||
- Increased the default system-mode stack size from 128 to 256 bytes because
|
- Increased the default system-mode stack size from 128 to 256 bytes because
|
||||||
some optimizations and the THUMB mode seem to use more stack space.
|
some optimizations and the THUMB mode seem to use more stack space.
|
||||||
- Included a Makefile in the LPC2148 demo that builds in THUMB mode.
|
- Included a Makefile in the LPC2148 demo that builds in THUMB mode.
|
||||||
|
|
36
src/chinit.c
36
src/chinit.c
|
@ -24,27 +24,17 @@
|
||||||
|
|
||||||
#include <ch.h>
|
#include <ch.h>
|
||||||
|
|
||||||
static Thread idlethread;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ChibiOS/RT initialization. After executing this function the current
|
* ChibiOS/RT initialization. After executing this function the current
|
||||||
* instructions stream becomes the idle thread. The thread must execute the
|
* instructions stream becomes the main thread.
|
||||||
* first user thread and then go to sleep into the \p chSysPause() where it
|
|
||||||
* will just serve the interrupts while keeping the lowest possible power
|
|
||||||
* mode.<br><br>
|
|
||||||
* @code
|
|
||||||
* chSysInit();
|
|
||||||
* chThdCreate(...); // Starts one or more user threads.
|
|
||||||
* chSysPause();
|
|
||||||
* @endcode
|
|
||||||
* @note Interrupts should be still disabled when \p chSysInit() is invoked
|
* @note Interrupts should be still disabled when \p chSysInit() is invoked
|
||||||
* and are internally enabled.
|
* and are internally enabled.
|
||||||
* @note The idle thread has absolute priority when exiting from the
|
* @note The main thread is created with priority \p NORMALPRIO.
|
||||||
* \p chSysInit(), this is done to make sure that all the initializations
|
|
||||||
* performed in the \p main() procedure are completed before any thread
|
|
||||||
* starts. The priority is set to \p IDLEPRIO into the \p chSysPause().
|
|
||||||
*/
|
*/
|
||||||
void chSysInit(void) {
|
void chSysInit(void) {
|
||||||
|
static Thread mainthread;
|
||||||
|
static BYTE8 waIdleThread[UserStackSize(IDLE_THREAD_STACK_SIZE)];
|
||||||
|
|
||||||
chSchInit();
|
chSchInit();
|
||||||
chDbgInit();
|
chDbgInit();
|
||||||
|
@ -52,13 +42,23 @@ void chSysInit(void) {
|
||||||
chVTInit();
|
chVTInit();
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* Now this instructions flow becomes the idle thread.
|
* Now this instructions flow becomes the main thread.
|
||||||
*/
|
*/
|
||||||
_InitThread(ABSPRIO, 0, &idlethread);
|
_InitThread(NORMALPRIO, 0, &mainthread);
|
||||||
idlethread.p_state = PRCURR;
|
mainthread.p_state = PRCURR;
|
||||||
currp = &idlethread;
|
currp = &mainthread;
|
||||||
|
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The idle thread is created using the port-provided implementation.
|
||||||
|
* This thread has the lowest priority in the system, its role is just to
|
||||||
|
* execute the chSysPause() and serve interrupts in its context.
|
||||||
|
* In ChibiOS/RT at least one thread in the system *must* execute
|
||||||
|
* chThdPause(), it can be done in a dedicated thread or in the main()
|
||||||
|
* function (that would never exit the call).
|
||||||
|
*/
|
||||||
|
chThdCreate(IDLEPRIO, 0, waIdleThread, sizeof(waIdleThread), (t_tfunc)_IdleThread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -36,9 +36,7 @@
|
||||||
* The priority is internally set to the minimum system value so that this
|
* The priority is internally set to the minimum system value so that this
|
||||||
* thread is executed only if there are no other ready threads in the system.
|
* thread is executed only if there are no other ready threads in the system.
|
||||||
*/
|
*/
|
||||||
void chSysPause(void) {
|
void _IdleThread(void *p) {
|
||||||
|
|
||||||
chThdSetPriority(IDLEPRIO);
|
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
;
|
;
|
||||||
|
|
|
@ -42,8 +42,20 @@ typedef struct {
|
||||||
{ \
|
{ \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INT_REQUIRED_STACK 0 // Must include registers and stack frames.
|
/**
|
||||||
|
* Stack size for the system idle thread.
|
||||||
|
*/
|
||||||
|
#define IDLE_THREAD_STACK_SIZE 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-thread stack overhead for interrupts servicing.
|
||||||
|
*/
|
||||||
|
#define INT_REQUIRED_STACK 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Macro to be used when allocating stack spaces, it adds the system-specific
|
||||||
|
* overhead.
|
||||||
|
*/
|
||||||
#define UserStackSize(n) (sizeof(Thread) + \
|
#define UserStackSize(n) (sizeof(Thread) + \
|
||||||
sizeof(struct stackregs) + (n) + (INT_REQUIRED_STACK))
|
sizeof(struct stackregs) + (n) + (INT_REQUIRED_STACK))
|
||||||
|
|
||||||
|
@ -74,8 +86,8 @@ typedef struct {
|
||||||
*/
|
*/
|
||||||
#define chSysPuts(msg) {}
|
#define chSysPuts(msg) {}
|
||||||
|
|
||||||
|
void _IdleThread(void *p);
|
||||||
void chSysHalt(void);
|
void chSysHalt(void);
|
||||||
void chSysPause(void);
|
|
||||||
void chSysSwitchI(Context *oldp, Context *newp);
|
void chSysSwitchI(Context *oldp, Context *newp);
|
||||||
|
|
||||||
#endif /* _CHCORE_H_ */
|
#endif /* _CHCORE_H_ */
|
||||||
|
|
Loading…
Reference in New Issue