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

master
gdisirio 2007-11-12 15:02:23 +00:00
parent 48cdf91217
commit a7ad3ace52
26 changed files with 320 additions and 84 deletions

View File

@ -65,9 +65,9 @@ UADEFS =
ASRC = chcore.c main.c buzzer.c mmcsd.c ../../src/lib/evtimer.c ../../test/test.c \ ASRC = chcore.c main.c buzzer.c mmcsd.c ../../src/lib/evtimer.c ../../test/test.c \
../../ports/ARM7-LPC214x/GCC/vic.c ../../ports/ARM7-LPC214x/GCC/lpc214x_serial.c \ ../../ports/ARM7-LPC214x/GCC/vic.c ../../ports/ARM7-LPC214x/GCC/lpc214x_serial.c \
../../ports/ARM7-LPC214x/GCC/lpc214x_ssp.c \ ../../ports/ARM7-LPC214x/GCC/lpc214x_ssp.c \
../../src/chinit.c ../../src/chlists.c ../../src/chdelta.c ../../src/chschd.c \ ../../src/chinit.c ../../src/chdebug.c ../../src/chlists.c ../../src/chdelta.c \
../../src/chthreads.c ../../src/chsem.c ../../src/chevents.c ../../src/chmsg.c \ ../../src/chschd.c ../../src/chthreads.c ../../src/chsem.c ../../src/chevents.c \
../../src/chsleep.c ../../src/chqueues.c ../../src/chserial.c ../../src/chmsg.c ../../src/chsleep.c ../../src/chqueues.c ../../src/chserial.c
# List THUMB-mode C sources here # List THUMB-mode C sources here
# NOTE: If any module is compiled in thumb mode then -mthumb-interwork is # NOTE: If any module is compiled in thumb mode then -mthumb-interwork is

View File

@ -20,9 +20,15 @@
#ifndef _BUZZER_H_ #ifndef _BUZZER_H_
#define _BUZZER_H_ #define _BUZZER_H_
void InitBuzzer(void); #ifdef __cplusplus
void PlaySound(int freq, t_time duration); extern "C" {
void PlaySoundWait(int freq, t_time duration); #endif
void InitBuzzer(void);
void PlaySound(int freq, t_time duration);
void PlaySoundWait(int freq, t_time duration);
#ifdef __cplusplus
}
#endif
extern EventSource BuzzerSilentEventSource; extern EventSource BuzzerSilentEventSource;

View File

@ -156,6 +156,12 @@
*/ */
//#define CH_CURRP_REGISTER_CACHE "r7" //#define CH_CURRP_REGISTER_CACHE "r7"
/** Configuration option: Includes basic debug support to the kernel.
* @note the debug support is port-dependent, it may be not present on some
* targets. In that case stub functions will be included.
*/
#define CH_USE_DEBUG
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */

View File

@ -92,8 +92,9 @@ extern void chSysUnlock(void);
#define chSysUnlock() asm("msr CPSR_c, #0x1F") #define chSysUnlock() asm("msr CPSR_c, #0x1F")
#endif /* THUMB */ #endif /* THUMB */
#define INT_REQUIRED_STACK 0x40 // Must include registers and stack frames. #define chSysPuts(msg) {}
#define INT_REQUIRED_STACK 0x40 // Must include registers and stack frames.
#define UserStackSize(n) (sizeof(Thread) + \ #define UserStackSize(n) (sizeof(Thread) + \
sizeof(struct stackregs) + (n) + (INT_REQUIRED_STACK)) sizeof(struct stackregs) + (n) + (INT_REQUIRED_STACK))
@ -105,6 +106,4 @@ void DefFiqHandler(void);
void DefIrqHandler(void); void DefIrqHandler(void);
void SpuriousHandler(void); void SpuriousHandler(void);
void SetVICVector(void *handler, int vector, int source);
#endif /* _CHCORE_H_ */ #endif /* _CHCORE_H_ */

View File

@ -33,6 +33,7 @@
typedef BYTE8 t_tmode; typedef BYTE8 t_tmode;
typedef BYTE8 t_tstate; typedef BYTE8 t_tstate;
typedef UWORD16 t_tid;
typedef ULONG32 t_prio; typedef ULONG32 t_prio;
typedef LONG32 t_msg; typedef LONG32 t_msg;
typedef LONG32 t_eventid; typedef LONG32 t_eventid;

View File

@ -43,18 +43,24 @@ typedef struct {
extern EventSource MMCInsertEventSource, MMCRemoveEventSource; extern EventSource MMCInsertEventSource, MMCRemoveEventSource;
void InitMMC(void); #ifdef __cplusplus
}
#endif
void InitMMC(void);
BOOL mmcInit(void); BOOL mmcInit(void);
void mmcStartPolling(void); void mmcStartPolling(void);
void mmcStopPolling(void); void mmcStopPolling(void);
BOOL mmcCardInserted (void); BOOL mmcCardInserted (void);
BYTE8 mmcSendCommand(BYTE8 cmd, ULONG32 arg); BYTE8 mmcSendCommand(BYTE8 cmd, ULONG32 arg);
BOOL mmcGetSize(MMCCSD *data); BOOL mmcGetSize(MMCCSD *data);
BOOL mmcRead(BYTE8 *buf, ULONG32 blknum); BOOL mmcRead(BYTE8 *buf, ULONG32 blknum);
BOOL mmcReadMultiple(BYTE8 *buf, ULONG32 blknum, ULONG32 n); BOOL mmcReadMultiple(BYTE8 *buf, ULONG32 blknum, ULONG32 n);
BOOL mmcWrite(BYTE8 *buf, ULONG32 blknum); BOOL mmcWrite(BYTE8 *buf, ULONG32 blknum);
BOOL mmcWriteMultiple(BYTE8 *buf, ULONG32 blknum, ULONG32 n); BOOL mmcWriteMultiple(BYTE8 *buf, ULONG32 blknum, ULONG32 n);
void mmcSynch(void); void mmcSynch(void);
#ifdef __cplusplus
}
#endif
#endif /* _MMCSD_H_*/ #endif /* _MMCSD_H_*/

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.3.4 beta" PROJECT_NUMBER = "0.4.0 beta"
OUTPUT_DIRECTORY = . OUTPUT_DIRECTORY = .
CREATE_SUBDIRS = NO CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English OUTPUT_LANGUAGE = English
@ -243,7 +243,8 @@ PREDEFINED = __JUST_STUBS__ \
CH_USE_MESSAGES \ CH_USE_MESSAGES \
CH_USE_MESSAGES_TIMEOUT \ CH_USE_MESSAGES_TIMEOUT \
CH_USE_MESSAGES_EVENT \ CH_USE_MESSAGES_EVENT \
CH_USE_SEMSW CH_USE_SEMSW \
CH_USE_DEBUG
EXPAND_AS_DEFINED = EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES SKIP_FUNCTION_MACROS = YES
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------

View File

@ -152,6 +152,16 @@
*/ */
/** @} */ /** @} */
/**
* @defgroup Debug Debug
* @{
* Debug APIs and procedures.
* @ingroup Kernel
* @file debug.h Debug macros and structures.
* @file chdebug.c ChibiOS/RT Debug code.
*/
/** @} */
/** /**
* @defgroup Scheduler Scheduler * @defgroup Scheduler Scheduler
* @{ * @{

View File

@ -37,10 +37,16 @@
*/ */
#define SERIAL_BUFFERS_SIZE 128 #define SERIAL_BUFFERS_SIZE 128
void InitSerial(void); #ifdef __cplusplus
void SetUARTI(UART *u, int speed, int lcr, int fcr); }
void UART0IrqHandler(void); #endif
void UART1IrqHandler(void); void InitSerial(void);
void UART0IrqHandler(void);
void UART1IrqHandler(void);
void SetUARTI(UART *u, int speed, int lcr, int fcr);
#ifdef __cplusplus
}
#endif
extern FullDuplexDriver COM1, COM2; extern FullDuplexDriver COM1, COM2;

View File

@ -26,11 +26,17 @@
*/ */
#define SSP_USE_MUTEX #define SSP_USE_MUTEX
void InitSSP(void); #ifdef __cplusplus
void SetSSP(int cpsr, int cr0, int cr1); }
#endif
void InitSSP(void);
void SetSSP(int cpsr, int cr0, int cr1);
void sspAcquireBus(void); void sspAcquireBus(void);
void sspReleaseBus(void); void sspReleaseBus(void);
void sspRW(BYTE8 *in, BYTE8 *out, t_size n); void sspRW(BYTE8 *in, BYTE8 *out, t_size n);
#ifdef __cplusplus
}
#endif
#endif /* _LPC214x_SSP_H_*/ #endif /* _LPC214x_SSP_H_*/

View File

@ -20,7 +20,13 @@
#ifndef _VIC_H_ #ifndef _VIC_H_
#define _VIC_H_ #define _VIC_H_
void InitVIC(void); #ifdef __cplusplus
void SetVICVector(void *handler, int vector, int source); }
#endif
void InitVIC(void);
void SetVICVector(void *handler, int vector, int source);
#ifdef __cplusplus
}
#endif
#endif /* _VIC_H_*/ #endif /* _VIC_H_*/

View File

@ -38,6 +38,17 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet.
*** Releases *** *** Releases ***
***************************************************************************** *****************************************************************************
*** 0.4.0 ***
- Implemented a debug subsystem, it supports debug messages and a context
switch circular trace buffer. The debug code can be enabled/disabled by
using the CH_USE_DEBUG in chconf.h.
The trace buffer is meant to be fetched and decoded by an external tool
(coming soon, it can be accessed using JTAG in the meanwhile).
- Implemented panic messages when CH_USE_DEBUG is enabled.
- Added a thread identifier field to the Thread structure, it is used only
for debug.
- Fixed an harmless warning message in buzzer.c.
*** 0.3.6 *** *** 0.3.6 ***
- Added SSP (SPI1) and ext.interrupts definitions to the lpc214x.h file. - Added SSP (SPI1) and ext.interrupts definitions to the lpc214x.h file.
- Added SSP driver for the LPC2148. - Added SSP driver for the LPC2148.

75
src/chdebug.c Normal file
View File

@ -0,0 +1,75 @@
/*
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>
#ifdef CH_USE_DEBUG
TraceBuffer dbgtb;
char *dbglastmsg;
/**
* Debug subsystem initialization.
*/
void chDbgInit(void) {
dbgtb.tb_size = TRACE_BUFFER_SIZE;
dbgtb.tb_ptr = &dbgtb.tb_buffer[0];
}
/**
* Inserts in the circular debug trace buffer a context switch record.
* @param otp the thread being switched out
* @param ntp the thread to be resumed
*/
void chDbgTrace(Thread *otp, Thread *ntp) {
dbgtb.tb_ptr->cse_slpdata = otp->p_common;
#ifdef CH_USE_SYSTEMTIME
dbgtb.tb_ptr->cse_time = chSysGetTime();
#else
dbgtb.tb_ptr->cse_time = 0;
#endif
dbgtb.tb_ptr->cse_state = otp->p_state;
dbgtb.tb_ptr->cse_tid = ntp->p_tid;
if (++dbgtb.tb_ptr >= &dbgtb.tb_buffer[TRACE_BUFFER_SIZE])
dbgtb.tb_ptr = &dbgtb.tb_buffer[0];
}
/**
* Prints a message on the console/debugger. The latest message pointer
* is retained.
*/
void chDbgPuts(char *msg) {
dbglastmsg = msg;
chSysPuts(msg);
}
/**
* Prints a panic message on the console/debugger and then halts the system.
*/
void chDbgPanic(char *msg) {
chSysPuts("PANIC: ");
chDbgPuts(msg);
chSysHalt();
}
#endif /* CH_USE_DEBUG */

View File

@ -160,10 +160,11 @@ t_eventid chEvtWait(t_eventmask ewmask,
} }
#ifdef CH_USE_EVENTS_TIMEOUT #ifdef CH_USE_EVENTS_TIMEOUT
static void unwait(void *p) { static void wakeup(void *p) {
#ifdef CH_USE_DEBUG
// Test removed, it should never happen. if (((Thread *)p)->p_state != PRWTEVENT)
// if (((Thread *)p)->p_state == PRWTEVENT) chDbgPanic("chevents.c, wakeup()\r\n");
#endif
chSchReadyI(p)->p_rdymsg = RDY_TIMEOUT; chSchReadyI(p)->p_rdymsg = RDY_TIMEOUT;
} }
@ -200,7 +201,7 @@ t_eventid chEvtWaitTimeout(t_eventmask ewmask,
if ((currp->p_epending & ewmask) == 0) { if ((currp->p_epending & ewmask) == 0) {
VirtualTimer vt; VirtualTimer vt;
chVTSetI(&vt, time, unwait, currp); chVTSetI(&vt, time, wakeup, currp);
currp->p_ewmask = ewmask; currp->p_ewmask = ewmask;
chSchGoSleepS(PRWTEVENT); chSchGoSleepS(PRWTEVENT);
if (!chVTIsArmedI(&vt)) { if (!chVTIsArmedI(&vt)) {

View File

@ -47,6 +47,7 @@ static Thread idlethread;
void chSysInit(void) { void chSysInit(void) {
chSchInit(); chSchInit();
chDbgInit();
#ifdef CH_USE_VIRTUAL_TIMERS #ifdef CH_USE_VIRTUAL_TIMERS
chVTInit(); chVTInit();
#endif #endif

View File

@ -80,10 +80,12 @@ t_msg chMsgSendWithEvent(Thread *tp, t_msg msg, EventSource *esp) {
#endif #endif
#ifdef CH_USE_MESSAGES_TIMEOUT #ifdef CH_USE_MESSAGES_TIMEOUT
static void unsend(void *p) { static void wakeup(void *p) {
// Test removed, it should never happen. #ifdef CH_USE_DEBUG
// if (((Thread *)p)->p_state == PRSNDMSG) if (((Thread *)p)->p_state != PRSNDMSG)
chDbgPanic("chmsg.c, wakeup()\r\n");
#endif
chSchReadyI(dequeue(p))->p_rdymsg = RDY_TIMEOUT; chSchReadyI(dequeue(p))->p_rdymsg = RDY_TIMEOUT;
} }
@ -108,7 +110,7 @@ t_msg chMsgSendTimeout(Thread *tp, t_msg msg, t_time time) {
chSysLock(); chSysLock();
chVTSetI(&vt, time, unsend, currp); chVTSetI(&vt, time, wakeup, currp);
fifo_insert(currp, &tp->p_msgqueue); fifo_insert(currp, &tp->p_msgqueue);
if (tp->p_state == PRWTMSG) if (tp->p_state == PRWTMSG)
chSchReadyI(tp); chSchReadyI(tp);

View File

@ -86,6 +86,9 @@ static void nextready(void) {
(currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR;
preempt = CH_TIME_QUANTUM; preempt = CH_TIME_QUANTUM;
#ifdef CH_USE_DEBUG
chDbgTrace(otp, currp);
#endif
chSysSwitchI(&otp->p_ctx, &currp->p_ctx); chSysSwitchI(&otp->p_ctx, &currp->p_ctx);
} }
@ -125,6 +128,9 @@ void chSchWakeupS(Thread *tp, t_msg msg) {
(currp = tp)->p_state = PRCURR; (currp = tp)->p_state = PRCURR;
tp->p_rdymsg = msg; tp->p_rdymsg = msg;
preempt = CH_TIME_QUANTUM; preempt = CH_TIME_QUANTUM;
#ifdef CH_USE_DEBUG
chDbgTrace(ctp, tp);
#endif
chSysSwitchI(&ctp->p_ctx, &tp->p_ctx); chSysSwitchI(&ctp->p_ctx, &tp->p_ctx);
} }
} }

View File

@ -112,10 +112,11 @@ void chSemWaitS(Semaphore *sp) {
} }
#ifdef CH_USE_SEMAPHORES_TIMEOUT #ifdef CH_USE_SEMAPHORES_TIMEOUT
static void unwait(void *p) { static void wakeup(void *p) {
#ifdef CH_USE_DEBUG
// Test removed, it should never happen. if (((Thread *)p)->p_state != PRWTSEM)
// if (((Thread *)p)->p_state == PRWTSEM) chDbgPanic("chsem.c, wakeup()\r\n");
#endif
chSemFastSignalI(((Thread *)p)->p_semp); chSemFastSignalI(((Thread *)p)->p_semp);
chSchReadyI(dequeue(p))->p_rdymsg = RDY_TIMEOUT; chSchReadyI(dequeue(p))->p_rdymsg = RDY_TIMEOUT;
} }
@ -134,7 +135,7 @@ t_msg chSemWaitTimeout(Semaphore *sp, t_time time) {
if (--sp->s_cnt < 0) { if (--sp->s_cnt < 0) {
VirtualTimer vt; VirtualTimer vt;
chVTSetI(&vt, time, unwait, currp); chVTSetI(&vt, time, wakeup, currp);
fifo_insert(currp, &sp->s_queue); fifo_insert(currp, &sp->s_queue);
currp->p_semp = sp; currp->p_semp = sp;
chSchGoSleepS(PRWTSEM); chSchGoSleepS(PRWTSEM);
@ -165,7 +166,7 @@ t_msg chSemWaitTimeoutS(Semaphore *sp, t_time time) {
if (--sp->s_cnt < 0) { if (--sp->s_cnt < 0) {
VirtualTimer vt; VirtualTimer vt;
chVTSetI(&vt, time, unwait, currp); chVTSetI(&vt, time, wakeup, currp);
fifo_insert(currp, &sp->s_queue); fifo_insert(currp, &sp->s_queue);
currp->p_semp = sp; currp->p_semp = sp;
chSchGoSleepS(PRWTSEM); chSchGoSleepS(PRWTSEM);

View File

@ -28,7 +28,9 @@
* Initializes a thread structure. * Initializes a thread structure.
*/ */
void _InitThread(t_prio prio, t_tmode mode, Thread *tp) { void _InitThread(t_prio prio, t_tmode mode, Thread *tp) {
static t_tid nextid = 0;
tp->p_tid = nextid++;
tp->p_flags = mode; tp->p_flags = mode;
tp->p_prio = prio; tp->p_prio = prio;
tp->p_rdymsg = RDY_OK; tp->p_rdymsg = RDY_OK;

View File

@ -83,6 +83,10 @@
#include "serial.h" #include "serial.h"
#endif #endif
#ifndef _DEBUG_H_
#include "debug.h"
#endif
/* /*
* Common values. * Common values.
*/ */

70
src/include/debug.h Normal file
View File

@ -0,0 +1,70 @@
/*
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 Debug
* @{
*/
#ifndef _DEBUG_H_
#define _DEBUG_H_
#ifdef CH_USE_DEBUG
#define TRACE_BUFFER_SIZE 1024
typedef struct {
void *cse_slpdata;
t_time cse_time;
UWORD16 cse_state: 4;
UWORD16 cse_tid: 12;
} CtxSwcEvent;
typedef struct {
t_size tb_size;
CtxSwcEvent *tb_ptr;
CtxSwcEvent tb_buffer[TRACE_BUFFER_SIZE];
} TraceBuffer;
extern CtxSwcEvent *dbgnext;
extern TraceBuffer dbgtb;
extern char *dbglastmsg;
#ifdef __cplusplus
extern "C" {
#endif
void chDbgInit(void);
void chDbgTrace(Thread *otp, Thread *ntp);
void chDbgPuts(char *msg);
void chDbgPanic(char *msg);
#ifdef __cplusplus
}
#endif
#else /* CH_USE_DEBUG */
#define chDbgInit()
#define chDbgPuts(msg) {}
#define chDbgPanic(msg) {}
#endif /* CH_USE_DEBUG */
#endif /* _DEBUG_H_ */
/** @} */

View File

@ -41,6 +41,8 @@ struct Thread {
/** The thread priority.*/ /** The thread priority.*/
t_prio p_prio; t_prio p_prio;
/* End of the fields shared with the ReadyList structure. */ /* End of the fields shared with the ReadyList structure. */
/** Thread identifier. */
t_tid p_tid;
/** Current thread state.*/ /** Current thread state.*/
t_tstate p_state; t_tstate p_state;
/** Mode flags.*/ /** Mode flags.*/
@ -68,6 +70,8 @@ struct Thread {
/** Message (only while in \p PRSNDMSG state).*/ /** Message (only while in \p PRSNDMSG state).*/
t_msg p_msg; t_msg p_msg;
#endif #endif
/** Generic way to access the union.*/
void *p_common;
}; };
/** Machine dependent processor context.*/ /** Machine dependent processor context.*/
Context p_ctx; Context p_ctx;

View File

@ -157,6 +157,12 @@
*/ */
//#define CH_CURRP_REGISTER_CACHE "reg" //#define CH_CURRP_REGISTER_CACHE "reg"
/** Configuration option: Includes basic debug support to the kernel.
* @note the debug support is port-dependent, it may be not present on some
* targets. In that case stub functions will be included.
*/
#define CH_USE_DEBUG
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */

View File

@ -69,6 +69,11 @@ typedef struct {
*/ */
#define chSysUnlock() #define chSysUnlock()
/**
* Prints a message on the system console (if any).
*/
#define chSysPuts(msg) {}
void chSysHalt(void); void chSysHalt(void);
void chSysPause(void); void chSysPause(void);
void chSysSwitchI(Context *oldp, Context *newp); void chSysSwitchI(Context *oldp, Context *newp);

View File

@ -38,6 +38,7 @@
typedef BYTE8 t_tmode; /* Thread mode flags, BYTE8 is ok. */ typedef BYTE8 t_tmode; /* Thread mode flags, BYTE8 is ok. */
typedef BYTE8 t_tstate; /* Thread state, BYTE8 is ok. */ typedef BYTE8 t_tstate; /* Thread state, BYTE8 is ok. */
typedef UWORD16 t_tid; /* Thread id. */
typedef ULONG32 t_prio; /* Priority, use the fastest unsigned type. */ typedef ULONG32 t_prio; /* Priority, use the fastest unsigned type. */
typedef LONG32 t_msg; /* Message, use signed pointer equivalent.*/ typedef LONG32 t_msg; /* Message, use signed pointer equivalent.*/
typedef LONG32 t_eventid; /* Event Id, use fastest signed.*/ typedef LONG32 t_eventid; /* Event Id, use fastest signed.*/