git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5013 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
64e7fd5a53
commit
d51863a353
|
@ -24,7 +24,6 @@
|
||||||
#include "evtimer.h"
|
#include "evtimer.h"
|
||||||
|
|
||||||
using namespace chibios_rt;
|
using namespace chibios_rt;
|
||||||
#if 0
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LED blink sequences.
|
* LED blink sequences.
|
||||||
|
@ -43,43 +42,45 @@ typedef struct {
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
} seqop_t;
|
} seqop_t;
|
||||||
|
|
||||||
// Flashing sequence for LED1.
|
// Flashing sequence for LED4.
|
||||||
static const seqop_t LED1_sequence[] =
|
static const seqop_t LED4_sequence[] =
|
||||||
{
|
{
|
||||||
{BITCLEAR, PAL_PORT_BIT(GPIOD_LED4)},
|
{BITCLEAR, PAL_PORT_BIT(GPIOD_LED4)},
|
||||||
{SLEEP, 200},
|
{SLEEP, 200},
|
||||||
{BITSET, PAL_PORT_BIT(GPIOD_LED4)},
|
{BITSET, PAL_PORT_BIT(GPIOD_LED4)},
|
||||||
{SLEEP, 800},
|
{SLEEP, 1800},
|
||||||
{BITCLEAR, PAL_PORT_BIT(GPIOD_LED4)},
|
|
||||||
{SLEEP, 400},
|
|
||||||
{BITSET, PAL_PORT_BIT(GPIOD_LED4)},
|
|
||||||
{SLEEP, 600},
|
|
||||||
{BITCLEAR, PAL_PORT_BIT(GPIOD_LED4)},
|
|
||||||
{SLEEP, 600},
|
|
||||||
{BITSET, PAL_PORT_BIT(GPIOD_LED4)},
|
|
||||||
{SLEEP, 400},
|
|
||||||
{BITCLEAR, PAL_PORT_BIT(GPIOD_LED4)},
|
|
||||||
{SLEEP, 800},
|
|
||||||
{BITSET, PAL_PORT_BIT(GPIOD_LED4)},
|
|
||||||
{SLEEP, 200},
|
|
||||||
{GOTO, 0}
|
{GOTO, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Flashing sequence for LED3.
|
||||||
|
static const seqop_t LED3_sequence[] =
|
||||||
|
{
|
||||||
|
{SLEEP, 1000},
|
||||||
|
{BITCLEAR, PAL_PORT_BIT(GPIOD_LED3)},
|
||||||
|
{SLEEP, 1800},
|
||||||
|
{BITSET, PAL_PORT_BIT(GPIOD_LED3)},
|
||||||
|
{SLEEP, 200},
|
||||||
|
{GOTO, 1}
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sequencer thread class. It can drive LEDs or other output pins.
|
* Sequencer thread class. It can drive LEDs or other output pins.
|
||||||
* Any sequencer is just an instance of this class, all the details are
|
* Any sequencer is just an instance of this class, all the details are
|
||||||
* totally encapsulated and hidden to the application level.
|
* totally encapsulated and hidden to the application level.
|
||||||
*/
|
*/
|
||||||
class SequencerThread : public EnhancedThread<128> {
|
class SequencerThread : public BaseStaticThread<128> {
|
||||||
private:
|
private:
|
||||||
const seqop_t *base, *curr; // Thread local variables.
|
const seqop_t *base, *curr; // Thread local variables.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual msg_t Main(void) {
|
virtual msg_t Main(void) {
|
||||||
|
|
||||||
|
setName("sequencer");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
switch(curr->action) {
|
switch(curr->action) {
|
||||||
case SLEEP:
|
case SLEEP:
|
||||||
Sleep(curr->value);
|
sleep(curr->value);
|
||||||
break;
|
break;
|
||||||
case GOTO:
|
case GOTO:
|
||||||
curr = &base[curr->value];
|
curr = &base[curr->value];
|
||||||
|
@ -98,7 +99,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SequencerThread(const seqop_t *sequence) : EnhancedThread<128>("sequencer") {
|
SequencerThread(const seqop_t *sequence) : BaseStaticThread<128>() {
|
||||||
|
|
||||||
base = curr = sequence;
|
base = curr = sequence;
|
||||||
}
|
}
|
||||||
|
@ -107,41 +108,30 @@ public:
|
||||||
/*
|
/*
|
||||||
* Tester thread class. This thread executes the test suite.
|
* Tester thread class. This thread executes the test suite.
|
||||||
*/
|
*/
|
||||||
class TesterThread : public EnhancedThread<256> {
|
class TesterThread : public BaseStaticThread<256> {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual msg_t Main(void) {
|
virtual msg_t Main(void) {
|
||||||
|
|
||||||
|
setName("tester");
|
||||||
|
|
||||||
return TestThread(&SD2);
|
return TestThread(&SD2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TesterThread(void) : EnhancedThread<256>("tester") {
|
TesterThread(void) : BaseStaticThread<256>() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/* Static threads instances.*/
|
||||||
* Executed as an event handler at 500mS intervals.
|
static TesterThread tester;
|
||||||
*/
|
static SequencerThread blinker1(LED3_sequence);
|
||||||
static void TimerHandler(eventid_t id) {
|
static SequencerThread blinker2(LED4_sequence);
|
||||||
|
|
||||||
(void)id;
|
|
||||||
if (palReadPad(GPIOA, GPIOA_BUTTON)) {
|
|
||||||
TesterThread tester;
|
|
||||||
tester.Wait();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Application entry point.
|
* Application entry point.
|
||||||
*/
|
*/
|
||||||
int main(void) {
|
int main(void) {
|
||||||
/* static const evhandler_t evhndl[] = {
|
|
||||||
TimerHandler
|
|
||||||
};
|
|
||||||
static EvTimer evt;
|
|
||||||
struct EventListener el0;*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* System initializations.
|
* System initializations.
|
||||||
|
@ -157,22 +147,23 @@ int main(void) {
|
||||||
* Activates the serial driver 2 using the driver default configuration.
|
* Activates the serial driver 2 using the driver default configuration.
|
||||||
*/
|
*/
|
||||||
sdStart(&SD2, NULL);
|
sdStart(&SD2, NULL);
|
||||||
/*
|
|
||||||
evtInit(&evt, 500); // Initializes an event timer.
|
|
||||||
evtStart(&evt); // Starts the event timer.
|
|
||||||
chEvtRegister(&evt.et_es, &el0, 0); // Registers a listener on the source.
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* Starts several instances of the SequencerThread class, each one operating
|
* Starts several instances of the SequencerThread class, each one operating
|
||||||
* on a different LED.
|
* on a different LED.
|
||||||
*/
|
*/
|
||||||
// SequencerThread blinker1(LED1_sequence);
|
blinker1.start(NORMALPRIO + 10);
|
||||||
|
blinker2.start(NORMALPRIO + 10);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Serves timer events.
|
* Serves timer events.
|
||||||
*/
|
*/
|
||||||
// while (true)
|
while (true) {
|
||||||
// Event::Dispatch(evhndl, Event::WaitOne(ALL_EVENTS));
|
if (palReadPad(GPIOA, GPIOA_BUTTON)) {
|
||||||
|
tester.start(NORMALPRIO);
|
||||||
|
tester.wait();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,6 +281,12 @@ namespace chibios_rt {
|
||||||
return chEvtWaitAllTimeout(ewmask, time);
|
return chEvtWaitAllTimeout(ewmask, time);
|
||||||
}
|
}
|
||||||
#endif /* CH_USE_EVENTS_TIMEOUT */
|
#endif /* CH_USE_EVENTS_TIMEOUT */
|
||||||
|
|
||||||
|
void BaseThread::dispatchEvents(const evhandler_t handlers[],
|
||||||
|
eventmask_t mask) {
|
||||||
|
|
||||||
|
chEvtDispatch(handlers, mask);
|
||||||
|
}
|
||||||
#endif /* CH_USE_EVENTS */
|
#endif /* CH_USE_EVENTS */
|
||||||
|
|
||||||
#if CH_USE_SEMAPHORES
|
#if CH_USE_SEMAPHORES
|
||||||
|
@ -384,55 +390,47 @@ namespace chibios_rt {
|
||||||
|
|
||||||
#if CH_USE_EVENTS
|
#if CH_USE_EVENTS
|
||||||
/*------------------------------------------------------------------------*
|
/*------------------------------------------------------------------------*
|
||||||
* chibios_rt::EventListener *
|
* chibios_rt::EvtListener *
|
||||||
*------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------*/
|
||||||
flagsmask_t EventListener::getAndClearFlags(void) {
|
flagsmask_t EvtListener::getAndClearFlags(void) {
|
||||||
|
|
||||||
return chEvtGetAndClearFlags(&ev_listener);
|
return chEvtGetAndClearFlags(&ev_listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*
|
/*------------------------------------------------------------------------*
|
||||||
* chibios_rt::EventSource *
|
* chibios_rt::EvtSource *
|
||||||
*------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------*/
|
||||||
EventSource::EventSource(void) {
|
EvtSource::EvtSource(void) {
|
||||||
|
|
||||||
ev_source.es_next = (::EventListener *)(void *)&ev_source;
|
chEvtInit(&ev_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventSource::registerOne(chibios_rt::EventListener *elp,
|
void EvtSource::registerOne(chibios_rt::EvtListener *elp,
|
||||||
eventid_t eid) {
|
eventid_t eid) {
|
||||||
|
|
||||||
chEvtRegister(&ev_source, &elp->ev_listener, eid);
|
chEvtRegister(&ev_source, &elp->ev_listener, eid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventSource::registerMask(chibios_rt::EventListener *elp,
|
void EvtSource::registerMask(chibios_rt::EvtListener *elp,
|
||||||
eventmask_t emask) {
|
eventmask_t emask) {
|
||||||
|
|
||||||
chEvtRegisterMask(&ev_source, &elp->ev_listener, emask);
|
chEvtRegisterMask(&ev_source, &elp->ev_listener, emask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventSource::unregister(chibios_rt::EventListener *elp) {
|
void EvtSource::unregister(chibios_rt::EvtListener *elp) {
|
||||||
|
|
||||||
chEvtUnregister(&ev_source, &elp->ev_listener);
|
chEvtUnregister(&ev_source, &elp->ev_listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventSource::broadcastFlags(flagsmask_t flags) {
|
void EvtSource::broadcastFlags(flagsmask_t flags) {
|
||||||
|
|
||||||
chEvtBroadcastFlags(&ev_source, flags);
|
chEvtBroadcastFlags(&ev_source, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventSource::broadcastFlagsI(flagsmask_t flags) {
|
void EvtSource::broadcastFlagsI(flagsmask_t flags) {
|
||||||
|
|
||||||
chEvtBroadcastFlagsI(&ev_source, flags);
|
chEvtBroadcastFlagsI(&ev_source, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*
|
|
||||||
* chibios_rt::Event *
|
|
||||||
*------------------------------------------------------------------------*/
|
|
||||||
void Event::dispatch(const evhandler_t handlers[], eventmask_t mask) {
|
|
||||||
|
|
||||||
chEvtDispatch(handlers, mask);
|
|
||||||
}
|
|
||||||
#endif /* CH_USE_EVENTS */
|
#endif /* CH_USE_EVENTS */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -517,6 +517,18 @@ namespace chibios_rt {
|
||||||
static eventmask_t waitAllEventsTimeout(eventmask_t ewmask,
|
static eventmask_t waitAllEventsTimeout(eventmask_t ewmask,
|
||||||
systime_t time);
|
systime_t time);
|
||||||
#endif /* CH_USE_EVENTS_TIMEOUT */
|
#endif /* CH_USE_EVENTS_TIMEOUT */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Invokes the event handlers associated to an event flags mask.
|
||||||
|
*
|
||||||
|
* @param[in] mask mask of the event flags to be dispatched
|
||||||
|
* @param[in] handlers an array of @p evhandler_t. The array must have size
|
||||||
|
* equal to the number of bits in eventmask_t.
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
static void dispatchEvents(const evhandler_t handlers[],
|
||||||
|
eventmask_t mask);
|
||||||
#endif /* CH_USE_EVENTS */
|
#endif /* CH_USE_EVENTS */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -783,15 +795,15 @@ namespace chibios_rt {
|
||||||
|
|
||||||
#if CH_USE_EVENTS || defined(__DOXYGEN__)
|
#if CH_USE_EVENTS || defined(__DOXYGEN__)
|
||||||
/*------------------------------------------------------------------------*
|
/*------------------------------------------------------------------------*
|
||||||
* chibios_rt::EventListener *
|
* chibios_rt::EvtListener *
|
||||||
*------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* @brief Class encapsulating an event listener.
|
* @brief Class encapsulating an event listener.
|
||||||
*/
|
*/
|
||||||
class EventListener {
|
class EvtListener {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Embedded @p ::EventListener structure.
|
* @brief Embedded @p ::EvtListener structure.
|
||||||
*/
|
*/
|
||||||
struct ::EventListener ev_listener;
|
struct ::EventListener ev_listener;
|
||||||
|
|
||||||
|
@ -808,48 +820,48 @@ namespace chibios_rt {
|
||||||
};
|
};
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*
|
/*------------------------------------------------------------------------*
|
||||||
* chibios_rt::EventSource *
|
* chibios_rt::EvtSource *
|
||||||
*------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* @brief Class encapsulating an event source.
|
* @brief Class encapsulating an event source.
|
||||||
*/
|
*/
|
||||||
class EventSource {
|
class EvtSource {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Embedded @p ::EventSource structure.
|
* @brief Embedded @p ::EvtSource structure.
|
||||||
*/
|
*/
|
||||||
struct ::EventSource ev_source;
|
struct ::EventSource ev_source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief EventSource object constructor.
|
* @brief EvtSource object constructor.
|
||||||
* @details The embedded @p ::EventSource structure is initialized.
|
* @details The embedded @p ::EvtSource structure is initialized.
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
EventSource(void);
|
EvtSource(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Registers a listener on the event source.
|
* @brief Registers a listener on the event source.
|
||||||
*
|
*
|
||||||
* @param[in] elp pointer to the @p EventListener object
|
* @param[in] elp pointer to the @p EvtListener object
|
||||||
* @param[in] eid numeric identifier assigned to the Event
|
* @param[in] eid numeric identifier assigned to the Event
|
||||||
* Listener
|
* Listener
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void registerOne(chibios_rt::EventListener *elp, eventid_t eid);
|
void registerOne(chibios_rt::EvtListener *elp, eventid_t eid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Registers an Event Listener on an Event Source.
|
* @brief Registers an Event Listener on an Event Source.
|
||||||
* @note Multiple Event Listeners can specify the same bits to be added.
|
* @note Multiple Event Listeners can specify the same bits to be added.
|
||||||
*
|
*
|
||||||
* @param[in] elp pointer to the @p EventListener object
|
* @param[in] elp pointer to the @p EvtListener object
|
||||||
* @param[in] emask the mask of event flags to be pended to the
|
* @param[in] emask the mask of event flags to be pended to the
|
||||||
* thread when the event source is broadcasted
|
* thread when the event source is broadcasted
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void registerMask(chibios_rt::EventListener *elp, eventmask_t emask);
|
void registerMask(chibios_rt::EvtListener *elp, eventmask_t emask);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unregisters a listener.
|
* @brief Unregisters a listener.
|
||||||
|
@ -860,7 +872,7 @@ namespace chibios_rt {
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void unregister(chibios_rt::EventListener *elp);
|
void unregister(chibios_rt::EvtListener *elp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Broadcasts on an event source.
|
* @brief Broadcasts on an event source.
|
||||||
|
@ -886,25 +898,6 @@ namespace chibios_rt {
|
||||||
*/
|
*/
|
||||||
void broadcastFlagsI(flagsmask_t flags);
|
void broadcastFlagsI(flagsmask_t flags);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class encapsulating an event-related functionalities.
|
|
||||||
*/
|
|
||||||
class Event {
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Invokes the event handlers associated with a mask.
|
|
||||||
*
|
|
||||||
* @param[in] mask mask of the events to be dispatched
|
|
||||||
* @param[in] handlers an array of @p evhandler_t. The array must be
|
|
||||||
* have indexes from zero up the higher registered
|
|
||||||
* event identifier.
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
static void dispatch(const evhandler_t handlers[], eventmask_t mask);
|
|
||||||
};
|
|
||||||
#endif /* CH_USE_EVENTS */
|
#endif /* CH_USE_EVENTS */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue