diff options
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/ch.h | 97 | ||||
| -rw-r--r-- | src/include/delta.h | 83 | ||||
| -rw-r--r-- | src/include/events.h | 95 | ||||
| -rw-r--r-- | src/include/messages.h | 59 | ||||
| -rw-r--r-- | src/include/queues.h | 172 | ||||
| -rw-r--r-- | src/include/scheduler.h | 81 | ||||
| -rw-r--r-- | src/include/semaphores.h | 82 | ||||
| -rw-r--r-- | src/include/serial.h | 154 | ||||
| -rw-r--r-- | src/include/sleep.h | 43 | ||||
| -rw-r--r-- | src/include/threads.h | 203 | 
10 files changed, 1069 insertions, 0 deletions
| diff --git a/src/include/ch.h b/src/include/ch.h new file mode 100644 index 000000000..80204bb2d --- /dev/null +++ b/src/include/ch.h @@ -0,0 +1,97 @@ +/*
 +    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 Initialization
 + * @{
 + */
 +
 +#ifndef _CH_H_
 +#define _CH_H_
 +
 +typedef struct Thread Thread;
 +
 +#ifndef __DOXIGEN__
 +#ifndef _CHCONF_H_
 +#include <chconf.h>
 +#endif
 +
 +#ifndef _CHTYPES_H_
 +#include <chtypes.h>
 +#endif
 +
 +#ifndef _CHCORE_H_
 +#include <chcore.h>
 +#endif
 +#endif /* __DOXIGEN__ */
 +
 +#ifndef _DELTA_H_
 +#include "delta.h"
 +#endif
 +
 +#ifndef _SCHEDULER_H_
 +#include "scheduler.h"
 +#endif
 +
 +#ifndef _EVENTS_H_
 +#include "events.h"
 +#endif
 +
 +#ifndef _MESSAGES_H_
 +#include "messages.h"
 +#endif
 +
 +#ifndef _THREADS_H_
 +#include "threads.h"
 +#endif
 +
 +#ifndef _SLEEP_H_
 +#include "sleep.h"
 +#endif
 +
 +#ifndef _SEMAPHORES_H_
 +#include "semaphores.h"
 +#endif
 +
 +#ifndef _QUEUES_H_
 +#include "queues.h"
 +#endif
 +
 +#ifndef _SERIAL_H_
 +#include "serial.h"
 +#endif
 +
 +/*
 + * Common values.
 + */
 +#ifndef FALSE
 +#define FALSE       0
 +#endif
 +#ifndef TRUE
 +#define TRUE        1
 +#endif
 +#ifndef NULL
 +#define NULL        0
 +#endif
 +
 +void chSysInit(void);
 +
 +#endif /* _CH_H_ */
 +
 +/** @} */
 diff --git a/src/include/delta.h b/src/include/delta.h new file mode 100644 index 000000000..2ae4d887f --- /dev/null +++ b/src/include/delta.h @@ -0,0 +1,83 @@ +/*
 +    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 VirtualTimers
 + * @{
 + */
 +
 +#ifndef _DELTA_H_
 +#define _DELTA_H_
 +
 +#ifdef CH_USE_VIRTUAL_TIMERS
 +
 +/** Virtual Timer callback function.*/
 +typedef void (*t_vtfunc)(void *);
 +
 +typedef struct VirtualTimer VirtualTimer;
 +
 +/**
 + * Virtual Timer descriptor structure.
 + */
 +struct VirtualTimer {
 +    /** Next timer in the delta list.*/
 +    VirtualTimer    *vt_next;
 +    /** Previous timer in the delta list.*/
 +    VirtualTimer    *vt_prev;
 +    /** Time delta before timeout.*/
 +    t_time          vt_dtime;
 +    /** Timer callback function pointer. The pointer is reset to zero after
 +        the callback is invoked.*/
 +    t_vtfunc        vt_func;
 +    /** Timer callback function parameter.*/
 +    void            *vt_par;
 +};
 +
 +/**
 + * Delta List header.
 + * @note The delta list is implemented as a double link bidirectional list in
 + *       order to make the unlink time constant, the reset of a virtual timer
 + *       is often used in the code. An slower implementation using a single
 + *       link list is possible and might be added later with a
 + *       \p CH_OPTIMIZE_SPACE option.
 + */
 +typedef struct {
 +    /** Next timer in the list (the one that will be triggered next).*/
 +    VirtualTimer    *dl_next;
 +    /** Last timer in the list.*/
 +    VirtualTimer    *dl_prev;
 +    /** Not used but it must be set to /p MAXDELTA.*/
 +    t_time          dl_dtime;
 +} DeltaList;
 +
 +
 +extern DeltaList dlist;
 +
 +/*
 + * Virtual Timers APIs.
 + */
 +void chVTInit(void);
 +void chVTSetI(VirtualTimer *vtp, t_time time, t_vtfunc vtfunc, void *par);
 +void chVTResetI(VirtualTimer *vtp);
 +
 +#endif /* CH_USE_VIRTUAL_TIMER */
 +
 +#endif /* _DELTA_H_ */
 +
 +/** @} */
 diff --git a/src/include/events.h b/src/include/events.h new file mode 100644 index 000000000..c5dfe7438 --- /dev/null +++ b/src/include/events.h @@ -0,0 +1,95 @@ +/*
 +    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 Events
 + * @{
 + */
 +
 +#ifndef _EVENTS_H_
 +#define _EVENTS_H_
 +
 +#ifdef CH_USE_EVENTS
 +
 +/** All events allowed mask.*/
 +#define ALL_EVENTS -1
 +
 +typedef struct EventListener EventListener;
 +
 +/**
 + * Event Listener structure.
 + */
 +struct EventListener {
 +  /** Next Event Listener registered on the Event Source.*/
 +  EventListener     *el_next;
 +  /** Thread interested in the Event Source.*/
 +  Thread            *el_listener;
 +  /** Event identifier associated by the thread to the Event Source.*/
 +  t_eventid         el_id;
 +};
 +
 +/**
 + * Event Source structure.
 + */
 +typedef struct EventSource {
 +  /** First Event Listener registered on the Event Source.*/
 +  EventListener     *es_next;
 +} EventSource;
 +
 +/** Returns the event mask from the event identifier.*/
 +#define EventMask(eid) (1 << (eid))
 +
 +/**
 + * Initializes an Event Source.
 + * @param esp pointer to the \p EventSource structure
 + * @note Can be called with interrupts disabled or enabled.
 + */
 +#define chEvtInit(esp) \
 +        ((esp)->es_next = (EventListener *)(esp))
 +
 +/**
 + * Verifies if there is at least one \p EventListener registered on the
 + * \p EventSource.
 + * @param esp pointer to the \p EventSource structure
 + * @note Can be called with interrupts disabled or enabled.
 + */
 +#define chEvtIsListening(esp) \
 +  		((esp) != (EventSource *)(esp)->es_next)
 +
 +
 +/** Event Handler callback function.*/
 +typedef void (*t_evhandler)(t_eventid);
 +
 +void chEvtRegister(EventSource *esp, EventListener *elp, t_eventid eid);
 +void chEvtUnregister(EventSource *esp, EventListener *elp);
 +void chEvtClear(t_eventmask mask);
 +void chEvtSend(EventSource *esp);
 +void chEvtSendI(EventSource *esp);
 +t_eventid chEvtWait(t_eventmask ewmask, t_evhandler handlers[]);
 +#ifdef CH_USE_EVENTS_TIMEOUT
 +t_eventid chEvtWaitTimeout(t_eventmask ewmask,
 +                           t_evhandler handlers[],
 +                           t_time time);
 +#endif
 +
 +#endif /* CH_USE_EVENTS */
 +
 +#endif /* _EVENTS_H_ */
 +
 +/** @} */
 diff --git a/src/include/messages.h b/src/include/messages.h new file mode 100644 index 000000000..a6ce409f3 --- /dev/null +++ b/src/include/messages.h @@ -0,0 +1,59 @@ +/*
 +    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 Messages
 + * @{
 + */
 +
 +#ifndef _MESSAGES_H_
 +#define _MESSAGES_H_
 +
 +#ifdef CH_USE_MESSAGES
 +
 +/**
 + * Evaluates to TRUE if the thread has pending messages.
 + */
 +#define chMsgIsPendingI(tp) \
 +			((tp)->p_msgqueue.p_next != (Thread *)&(tp)->p_msgqueue)
 +
 +/**
 + * Returns the first message in the queue.
 + */
 +#define chMsgGetI(tp) \
 +			((tp)->p_msgqueue.p_next->p_msg)
 +
 +t_msg chMsgSend(Thread *tp, t_msg msg);
 +t_msg chMsgWait(void);
 +t_msg chMsgGet(void);
 +void chMsgRelease(t_msg msg);
 +
 +#ifdef CH_USE_MESSAGES_EVENT
 +t_msg chMsgSendWithEvent(Thread *tp, t_msg msg, EventSource *esp);
 +#endif
 +
 +#ifdef CH_USE_MESSAGES_TIMEOUT
 +t_msg chMsgSendTimeout(Thread *tp, t_msg msg, t_time time);
 +#endif
 +
 +#endif /* CH_USE_MESSAGES */
 +
 +#endif /* _MESSAGES_H_ */
 +
 +/** @} */
 diff --git a/src/include/queues.h b/src/include/queues.h new file mode 100644 index 000000000..117c6e9e8 --- /dev/null +++ b/src/include/queues.h @@ -0,0 +1,172 @@ +/*
 +    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 IOQueues
 + * @{
 + */
 +
 +#ifndef _QUEUES_H_
 +#define _QUEUES_H_
 +
 +/** Queue notification callback type.*/
 +typedef void (*t_qnotify)(void);
 +
 +/** Returned by the queue functions if the operation is successful.*/
 +#define Q_OK        RDY_OK
 +/** Returned by the queue functions if a timeout occurs.*/
 +#define Q_TIMEOUT   RDY_TIMEOUT
 +/** Returned by the queue functions if the queue is reset.*/
 +#define Q_RESET     RDY_RESET
 +/** Returned by the queue functions if the queue is empty.*/
 +#define Q_EMPTY     -3
 +/** Returned by the queue functions if the queue is full.*/
 +#define Q_FULL      -4
 +
 +#ifdef CH_USE_QUEUES
 +/**
 + * I/O queue structure, it is used by both Input and Output Queues,
 + * the difference is on how the semaphore is initialized.
 + */
 +typedef struct {
 +  /** Pointer to the queue buffer.*/
 +  BYTE8             *q_buffer;
 +  /** Pointer to the first location after the buffer.*/
 +  BYTE8             *q_top;
 +  /** Write pointer.*/
 +  BYTE8             *q_wrptr;
 +  /** Read pointer.*/
 +  BYTE8             *q_rdptr;
 +  /** Counter semaphore.*/
 +  Semaphore         q_sem;
 +  /** Data notification callback.*/
 +  t_qnotify         q_notify;
 +} Queue;
 +
 +/** Returns the queue's buffer size.*/
 +#define chQSize(q) \
 +        ((q)->q_top - (q)->q_buffer)
 +
 +/** Returns the used space if used on an Input Queue and the empty space if
 + *  used on an Output Queue.*/
 +#define chQSpace(q) \
 +        ((q)->q_sem.s_cnt)
 +
 +/** Evaluates to TRUE if the specified Input Queue is empty.*/
 +#define chIQIsEmpty(q) \
 +        (chQSpace(q) <= 0)
 +
 +/** Evaluates to TRUE if the specified Input Queue is full.*/
 +#define chIQIsFull(q) \
 +        (chQSpace(q) >= chQSize(q))
 +
 +/** Evaluates to TRUE if the specified Output Queue is empty.*/
 +#define chOQIsEmpty(q) \
 +        (chQSpace(q) >= chQSize(q))
 +
 +/** Evaluates to TRUE if the specified Output Queue is full.*/
 +#define chOQIsFull(q) \
 +        (chQSpace(q) <= 0)
 +
 +/*
 + * Input Queues functions. An Input Queue is usually written into by an
 + * interrupt handler and read from a thread.
 + */
 +void chIQInit(Queue *qp, BYTE8 *buffer, t_size size, t_qnotify inotify);
 +void chIQReset(Queue *qp);
 +t_msg chIQPutI(Queue *qp, BYTE8 b);
 +t_msg chIQGet(Queue *qp);
 +t_size chIQRead(Queue *qp, BYTE8 *buffer, t_size n);
 +#ifdef CH_USE_QUEUES_TIMEOUT
 +t_msg chIQGetTimeout(Queue *qp, t_time time);
 +#endif
 +
 +/*
 + * Output Queues functions. An Output Queue is usually written into by a
 + * thread and read from an interrupt handler.
 + */
 +void chOQInit(Queue *queue, BYTE8 *buffer, t_size size, t_qnotify onotify);
 +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);
 +#endif  /* CH_USE_QUEUES */
 +
 +#ifdef CH_USE_QUEUES_HALFDUPLEX
 +/**
 + * Half duplex queue structure.
 + */
 +typedef struct {
 +  /** Pointer to the queue buffer.*/
 +  BYTE8             *hdq_buffer;
 +  /** Pointer to the first location after the buffer.*/
 +  BYTE8             *hdq_top;
 +  /** Write pointer.*/
 +  BYTE8             *hdq_wrptr;
 +  /** Read pointer.*/
 +  BYTE8             *hdq_rdptr;
 +  /** Input counter semaphore.*/
 +  Semaphore         hdq_isem;
 +  /** Output counter semaphore.*/
 +  Semaphore         hdq_osem;
 +  /** Input data notification callback.*/
 +  t_qnotify         hdq_inotify;
 +  /** Output data notification callback.*/
 +  t_qnotify         hdq_onotify;
 +} HalfDuplexQueue;
 +
 +/** Returns the queue's buffer size.*/
 +#define chHDQSize(q) \
 +        ((q)->hdq_top - (q)->hdq_buffer)
 +
 +/** Returns the queue space when in transmission mode.*/
 +#define chHDQEmptySpace(q) \
 +        ((q)->hdq_osem.s_cnt)
 +
 +/** Returns the number of the bytes in the queue when in receive mode.*/
 +#define chHDQFilledSpace(q) \
 +        ((q)->hdq_isem.s_cnt)
 +
 +/** Evaluates to TRUE if the queue is in transmit mode.*/
 +#define chHDQIsTransmitting(q) \
 +        (chHDQEmptySpace(q) < chHDQSize(q))
 +
 +/** Evaluates to TRUE if the queue is in receive mode.*/
 +#define chHDQIsReceiving(q) \
 +        (chHDQEmptySpaceQ(q) >= chHDQSize(q))
 +
 +/** Evaluates to TRUE if the receive queue is full.*/
 +#define chHDQIsFullReceive(q) \
 +        (chHDQFilledSpace(q) >= chHDQSize(q))
 +
 +void chHDQInit(HalfDuplexQueue *qp, BYTE8 *buffer, t_size size,
 +               t_qnotify inotify, t_qnotify onotify);
 +t_msg chHDQGetReceive(HalfDuplexQueue *qp);
 +void chHDQPutTransmit(HalfDuplexQueue *qp, BYTE8 b);
 +t_msg chHDQGetTransmitI(HalfDuplexQueue *qp);
 +t_msg chHDQPutReceiveI(HalfDuplexQueue *qp, BYTE8 b);
 +#ifdef CH_USE_QUEUES_TIMEOUT
 +t_msg chHDQGetReceiveTimeout(HalfDuplexQueue *qp, t_time time);
 +#endif
 +
 +#endif /* CH_USE_QUEUES_HALFDUPLEX */
 +
 +#endif /* _QUEUES_H_ */
 +
 +/** @} */
 diff --git a/src/include/scheduler.h b/src/include/scheduler.h new file mode 100644 index 000000000..78fbb4a72 --- /dev/null +++ b/src/include/scheduler.h @@ -0,0 +1,81 @@ +/*
 +    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 Scheduler
 + * @{
 + */
 +
 +#ifndef _SCHEDULER_H_
 +#define _SCHEDULER_H_
 +
 +/** Normal \p chSchReadyI() message.*/
 +#define RDY_OK      0
 +/** Returned if the thread was made ready because a timeout.*/
 +#define RDY_TIMEOUT -1
 +/** Returned if the thread was made ready because a reset.*/
 +#define RDY_RESET   -2
 +
 +/**
 + * Ready list header.
 + */
 +typedef struct {
 +  /** Highest priority \p Thread in the list.*/
 +  Thread            *p_next;
 +  /** Lowest priority \p Thread in the list.*/
 +  Thread            *p_prev;
 +  /** Alwas set to \p MAXPRIO.*/
 +  t_prio            p_prio;
 +} ReadyList;
 +
 +/*
 + * Scheduler APIs.
 + */
 +void chSchInit(void);
 +Thread *chSchReadyI(Thread *tp);
 +void chSchGoSleepI(t_tstate newstate);
 +void chSchWakeupI(Thread *tp, t_msg msg);
 +void chSchRescheduleI(void);
 +void chSchDoRescheduleI(void);
 +BOOL chSchRescRequiredI(void);
 +void chSchTimerHandlerI(void);
 +
 +/**
 + * Current thread pointer.
 + * @note Dont use this directly but use the \p chThdSelf()
 + *       instead. Direct use of system global variables is discouraged because
 + *       portability reasons.
 + */
 +#ifdef CH_CURRP_REGISTER_CACHE
 +register Thread *currp asm(CH_CURRP_REGISTER_CACHE);
 +#else
 +extern Thread *currp;
 +#endif
 +
 +/**
 + * System ticks counter.
 + * @note Dont use this directly but use the \p chSysGetTime()
 + *       instead. Direct use of system global variables is discouraged because
 + *       portability reasons.
 + */
 +extern t_time stime;
 +
 +#endif /* _SCHEDULER_H_ */
 +
 +/** @} */
 diff --git a/src/include/semaphores.h b/src/include/semaphores.h new file mode 100644 index 000000000..83d4613de --- /dev/null +++ b/src/include/semaphores.h @@ -0,0 +1,82 @@ +/*
 +    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 Semaphores
 + * @{
 + */
 +
 +#ifndef _SEMAPHORES_H_
 +#define _SEMAPHORES_H_
 +
 +#ifdef CH_USE_SEMAPHORES
 +
 +/**
 + * Semaphore structure.
 + */
 +typedef struct {
 +  /** Queue of the threads sleeping on this Semaphore.*/
 +  ThreadsQueue    s_queue;
 +  /** The Semaphore counter.*/
 +  t_semcnt        s_cnt;
 +} Semaphore;
 +
 +void chSemInit(Semaphore *sp, t_semcnt n);
 +void chSemReset(Semaphore *sp, t_semcnt n);
 +void chSemResetI(Semaphore *sp, t_semcnt n);
 +void chSemWait(Semaphore *sp);
 +void chSemWaitS(Semaphore *sp);
 +t_msg chSemWaitTimeout(Semaphore *sp, t_time time);
 +t_msg chSemWaitTimeoutS(Semaphore *sp, t_time time);
 +void chSemSignal(Semaphore *sp);
 +void chSemSignalI(Semaphore *sp);
 +void chSignalWait(Semaphore *sps, Semaphore *spw);
 +
 +#ifdef CH_USE_RT_SEMAPHORES
 +void chSemRaisePrioWait(Semaphore *sp);
 +void chSemLowerPrioSignal(Semaphore *sp);
 +void chSemRaisePrioSignalWait(Semaphore *sps, Semaphore *spw);
 +void chSemLowerPrioSignalWait(Semaphore *sps, Semaphore *spw);
 +#endif
 +
 +/**
 + * Decreases the semaphore counter, this macro can be used when it is ensured
 + * that the counter would not become negative.
 + */
 +#define chSemFastWaitS(sp) \
 +				((sp)->s_cnt--)
 +
 +/**
 + * Increases the semaphore counter, this macro can be used when the counter is
 + * not negative.
 + */
 +#define chSemFastSignalI(sp) \
 +				((sp)->s_cnt++)
 +
 +/**
 + * Returns the semaphore counter current value.
 + */
 +#define chSemGetCounter(sp) \
 +				((sp)->s_cnt)
 +
 +#endif /* CH_USE_SEMAPHORES */
 +
 +#endif /* _SEM_H_ */
 +
 +/** @} */
 diff --git a/src/include/serial.h b/src/include/serial.h new file mode 100644 index 000000000..3d33975b1 --- /dev/null +++ b/src/include/serial.h @@ -0,0 +1,154 @@ +/*
 +    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 Serial
 + * @{
 + */
 +
 +#ifndef _SERIAL_H_
 +#define _SERIAL_H_
 +
 +/** No pending conditions.*/
 +#define SD_NO_ERROR               0
 +/** Connection happened.*/
 +#define SD_CONNECTED              1
 +/** Disconnection happened.*/
 +#define SD_DISCONNECTED           2
 +/** Parity error happened.*/
 +#define SD_PARITY_ERROR           4
 +/** Framing error happened.*/
 +#define SD_FRAMING_ERROR          8
 +/** Overflow happened.*/
 +#define SD_OVERRUN_ERROR          16
 +/** Break detected.*/
 +#define SD_BREAK_DETECTED         32
 +
 +/** Serial Driver condition flags type.*/
 +typedef UWORD16 t_dflags;
 +
 +#ifdef CH_USE_SERIAL_FULLDUPLEX
 +
 +/**
 + * Full Duplex Serial Driver main structure.
 + */
 +typedef struct {
 +
 +  /** Input queue. Incoming data can be read from this queue by using the
 +   *  queues APIs.*/
 +  Queue             sd_iqueue;
 +  /** Data Available \p EventSource. This event is generated when some incoming
 +   *  data is inserted in the Input \p Queue.*/
 +  EventSource       sd_ievent;
 +
 +  /** Output queue. Outgoing data can be written to this Output \p Queue by
 +   *   using the queues APIs.*/
 +  Queue             sd_oqueue;
 +  /** Data Transmitted \p EventSource. This event is generated when the
 +   *  Output \p Queue is empty.*/
 +  EventSource       sd_oevent;
 +
 +  /** I/O driver status flags. This field should not be read directly but
 +   *  the \p chFDDGetAndClearFlags() funtion should be used instead.*/
 +  t_dflags          sd_flags;
 +  /** Status Change \p EventSource. This event is generated when a
 +   *  condition flag was changed.*/
 +  EventSource       sd_sevent;
 +} FullDuplexDriver;
 +
 +void chFDDInit(FullDuplexDriver *sd,
 +               BYTE8 *ib, t_size isize, t_qnotify inotify,
 +               BYTE8 *ob, t_size osize, t_qnotify onotify);
 +void chFDDIncomingDataI(FullDuplexDriver *sd, BYTE8 b);
 +t_msg chFDDRequestDataI(FullDuplexDriver *sd);
 +void chFDDAddFlagsI(FullDuplexDriver *sd, t_dflags mask);
 +t_dflags chFDDGetAndClearFlags(FullDuplexDriver *sd);
 +
 +/** @see chIQRead()*/
 +#define chFDDRead(sd, b, n) \
 +        chIQRead(&(sd)->sd_iqueue, b, n)
 +
 +/** @see chOQWrite()*/
 +#define chFDDWrite(sd, b, n) \
 +        chOQWrite(&(sd)->sd_oqueue, b, n)
 +
 +/** @see chIQGet()*/
 +#define chFDDGet(sd) \
 +        chIQGet(&(sd)->sd_iqueue)
 +
 +/** @see chIQGetTimeout()*/
 +#define chFDDGetTimeout(sd, t) \
 +        chIQGetTimeout(&(sd)->sd_iqueue, t)
 +
 +/** @see chOQPut()*/
 +#define chFDDPut(sd, b) \
 +        chOQPut(&(sd)->sd_oqueue, b)
 +
 +#endif /* CH_USE_SERIAL_FULLDUPLEX */
 +
 +#ifdef CH_USE_SERIAL_HALFDUPLEX
 +
 +/**
 + * Full Duplex Serial Driver main structure.
 + */
 +typedef struct {
 +
 +  /** Data queue. Transmit/receive \p HalfDuplexQueue.*/
 +  HalfDuplexQueue   sd_queue;
 +  /** Data Available \p EventSource. This event is generated when some
 +   *  incoming data is inserted in the receive queue.*/
 +  EventSource       sd_ievent;
 +  /** Data Transmitted \p EventSource. This event is generated when the
 +   *  transmission queue is empty and the driver can either transmit more
 +   *  data or enter receive mode.*/
 +  EventSource       sd_oevent;
 +
 +  /** I/O driver status flags. This field should not be read directly but
 +   *  the \p chHDDGetAndClearFlags() funtion should be used
 +   *  instead.*/
 +  t_dflags          sd_flags;
 +  /** Status Change Event Source. This event is generated when a condition
 +   *  flag was changed.*/
 +  EventSource       sd_sevent;
 +} HalfDuplexDriver;
 +
 +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);
 +
 +/** @see chHDQGetReceive()*/
 +#define chHDDGetReceive(sd) \
 +        chHDQGetReceive(&(sd)->sd_queue)
 +
 +/** @see chHDQGetReceiveTimeout()*/
 +#define chHDDGetReceiveTimeout(sd, t) \
 +        chHDQGetReceiveTimeout(&(sd)->sd_queue, t)
 +
 +/** @see chHDQPutTransmit()*/
 +#define chHDDPutTransmit(sd, b) \
 +        chHDQPutTransmit(&(sd)->sd_queue, b)
 +
 +#endif /* CH_USE_SERIAL_HALFDUPLEX */
 +
 +#endif /* _SERIAL_H_ */
 +
 +/** @} */
 diff --git a/src/include/sleep.h b/src/include/sleep.h new file mode 100644 index 000000000..265500908 --- /dev/null +++ b/src/include/sleep.h @@ -0,0 +1,43 @@ +/*
 +    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 Time
 + * @{
 + */
 +
 +#ifndef _SLEEP_H_
 +#define _SLEEP_H_
 +
 +#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 */
 +
 +#endif /* _SLEEP_H_ */
 +
 +/** @} */
 diff --git a/src/include/threads.h b/src/include/threads.h new file mode 100644 index 000000000..d8937433f --- /dev/null +++ b/src/include/threads.h @@ -0,0 +1,203 @@ +/*
 +    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 Threads
 + * @{
 + */
 +
 +#ifndef _THREADS_H_
 +#define _THREADS_H_
 +
 +#define isempty(qp)     ((qp)->p_next == (Thread *)(qp))
 +#define notempty(qp)    ((qp)->p_next != (Thread *)(qp))
 +#define firstprio(qp)   ((qp)->p_next->p_prio)
 +#define lastprio(qp)    ((qp)->p_prev->p_prio)
 +
 +/**
 + * Generic threads queue header and element.
 + */
 +typedef struct {
 +  /** First \p Thread in the queue.*/
 +  Thread            *p_next;
 +  /** Last \p Thread in the queue.*/
 +  Thread            *p_prev;
 +} ThreadsQueue;
 +
 +/**
 + * Structure representing a thread.
 + * @note Not all the listed fields are always needed, by switching off some
 + *       not needed ChibiOS/RT subsystems it is possible to save RAM space by
 + *       shrinking the \p Thread structure.
 + */
 +struct Thread {
 +  /** Next \p Thread in the threads list.*/
 +  Thread            *p_next;
 +  /** Previous \p Thread in the threads list.*/
 +  Thread            *p_prev;
 +  /* End of the fields shared with the ThreadsQueue structure. */
 +  /** The thread priority.*/
 +  t_prio            p_prio;
 +  /* End of the fields shared with the ReadyList structure. */
 +  /** Current thread state.*/
 +  t_tstate          p_state;
 +  /** Mode flags.*/
 +  t_tmode           p_flags;
 +  /*
 +   * The following fields are merged in an union because they are all
 +   * state-specific fields. This trick saves some extra space for each
 +   * thread in the system.
 +   */
 +  union {
 +    /** Thread wakeup code, normally set to \p RDY_OK by the \p chSchReadyI()
 +     * (only while in \p PRCURR or \p PRREADY states).*/
 +    t_msg           p_rdymsg;
 +    /** The thread exit code (only while in \p PREXIT state).*/
 +    t_msg           p_exitcode;
 +#ifdef CH_USE_EVENTS
 +    /** Enabled events mask (only while in \p PRWTEVENT state).*/
 +    t_eventmask     p_ewmask;
 +#endif
 +#ifdef CH_USE_MESSAGES
 +    /** Message (only while in \p PRSNDMSG state).*/
 +    t_msg           p_msg;
 +#endif
 +  };
 +  /** Machine dependent processor context.*/
 +  Context                       p_ctx;
 +  /*
 +   * Start of the optional fields. Note, the null thread may also let its
 +   * stack overwrite the following fields since it never uses semaphores,
 +   * events, messages, exit etc, this can save some space on RAM starved
 +   * systems, be caruful in doing so.
 +   */
 +#ifdef CH_USE_WAITEXIT
 +  /** The queue of the threads waiting for this thread termination.*/
 +  ThreadsQueue      p_waiting;
 +#endif
 +#ifdef CH_USE_EXIT_EVENT
 +  /** The thread termination \p EventSource.*/
 +  EventSource       p_exitesource;
 +#endif
 +#ifdef CH_USE_MESSAGES
 +  ThreadsQueue      p_msgqueue;
 +#endif
 +#ifdef CH_USE_EVENTS
 +  /** Pending events mask.*/
 +  t_eventmask       p_epending;
 +#endif
 +#ifdef CH_USE_RT_SEMAPHORES
 +  /** Priority backup after acquiring a RT semaphore.*/
 +  t_prio            p_bakprio;
 +  /** RT semaphores depth counter.*/
 +  WORD16            p_rtcnt;
 +#endif
 +};
 +
 +/** Thread state: Reserved.*/
 +#define PRFREE      0
 +/** Thread state: Current.*/
 +#define PRCURR      1
 +/** Thread state: Thread in the ready list.*/
 +#define PRREADY     2
 +/** Thread state: Thread created in suspended state.*/
 +#define PRSUSPENDED 3
 +/** Thread state: Waiting on a semaphore.*/
 +#define PRWTSEM     4
 +/** Thread state: Waiting in \p chThdSleep() or \p chThdSleepUntil().*/
 +#define PRSLEEP     5
 +/** Thread state: Waiting in \p chThdWait().*/
 +#define PRWAIT      6
 +/** Thread state: Waiting in \p chEvtWait().*/
 +#define PRWTEVENT   7
 +/** Thread state: Waiting in \p chMsgSend().*/
 +#define PRSNDMSG    8
 +/** Thread state: Waiting in \p chMsgWait().*/
 +#define PRWTMSG     9
 +/** Thread state: After termination.*/
 +#define PREXIT      10
 +
 +/** Thread option: Termination requested flag.*/
 +#define P_TERMINATE 1
 +/** Thread option: Create suspended thread.*/
 +#define P_SUSPENDED 2
 +
 +/** Idle thread priority.*/
 +#define IDLEPRIO    0
 +/** Lowest user priority.*/
 +#define LOWPRIO     1
 +/** Normal user priority.*/
 +#define NORMALPRIO  128
 +/** Highest user priority.*/
 +#define HIGHPRIO    255
 +/** Boosted base priority.*/
 +#define MEPRIO      256
 +/** Absolute priority.*/
 +#define ABSPRIO     512
 +
 +/* Not an API, don't use into the application code.*/
 +void _InitThread(t_prio prio, t_tmode mode, Thread *tp);
 +
 +/** Thread function.*/
 +typedef t_msg (*t_tfunc)(void *);
 +
 +/*
 + * Threads Lists functions.
 + */
 +#ifndef CH_OPTIMIZE_SPEED
 +void enqueue(Thread *tp, ThreadsQueue *tqp);
 +Thread *dequeue(Thread *tp);
 +#else
 +static INLINE Thread *dequeue(Thread *tp) {
 +
 +  tp->p_prev->p_next = tp->p_next;
 +  tp->p_next->p_prev = tp->p_prev;
 +  return tp;
 +}
 +
 +static INLINE void enqueue(Thread *tp, ThreadsQueue *tqp) {
 +
 +  tp->p_next = (Thread *)tqp;
 +  tp->p_prev = tqp->p_prev;
 +  tqp->p_prev->p_next = tp;
 +  tqp->p_prev = tp;
 +}
 +#endif
 +
 +/*
 + * Threads APIs.
 + */
 +#define chThdSelf() currp
 +Thread *chThdCreate(t_prio prio, t_tmode mode, void *workspace,
 +                    t_size wsize, t_tfunc pf, void *arg);
 +void chThdResume(Thread *tp);
 +void chThdTerminate(Thread *tp);
 +BOOL chThdShouldTerminate(void);
 +BOOL chThdTerminated(Thread *tp);
 +void chThdExit(t_msg msg);
 +#ifdef CH_USE_WAITEXIT
 +t_msg chThdWait(Thread *tp);
 +#endif
 +#ifdef CH_USE_EXIT_EVENT
 +EventSource *chThdGetExitEventSource(Thread *tp);
 +#endif
 +
 +#endif  /* _THREADS_H_ */
 +
 +/** @} */
 | 
