From 77f68f1c5b8f39a9146f5bd644867dde10b24c14 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 4 Jan 2013 10:26:22 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5030 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ARMCM4-STM32F407-DISCOVERY-G++/main.cpp | 5 +- os/fs/fatfs/fatfs_fsimpl.cpp | 23 ++-- os/fs/fatfs/fatfs_fsimpl.hpp | 18 ++- os/various/cpp_wrappers/ch.cpp | 110 +++++++++++------- os/various/cpp_wrappers/ch.hpp | 55 +++++---- 5 files changed, 133 insertions(+), 78 deletions(-) diff --git a/demos/ARMCM4-STM32F407-DISCOVERY-G++/main.cpp b/demos/ARMCM4-STM32F407-DISCOVERY-G++/main.cpp index 2275d6702..426d2b336 100644 --- a/demos/ARMCM4-STM32F407-DISCOVERY-G++/main.cpp +++ b/demos/ARMCM4-STM32F407-DISCOVERY-G++/main.cpp @@ -151,7 +151,7 @@ static SequencerThread blinker2(LED4_sequence); static SequencerThread blinker3(LED5_sequence); static SequencerThread blinker4(LED6_sequence); -static FatFSWrapper fs(NULL); +static FatFSWrapper fs; /* * Application entry point. @@ -168,6 +168,9 @@ int main(void) { halInit(); System::init(); + fs.mount(); + fs.unmount(); + /* * Activates the serial driver 2 using the driver default configuration. * PA2(TX) and PA3(RX) are routed to USART2. diff --git a/os/fs/fatfs/fatfs_fsimpl.cpp b/os/fs/fatfs/fatfs_fsimpl.cpp index e42c11e50..4fd071f00 100644 --- a/os/fs/fatfs/fatfs_fsimpl.cpp +++ b/os/fs/fatfs/fatfs_fsimpl.cpp @@ -47,9 +47,8 @@ namespace chibios_fatfs { /*------------------------------------------------------------------------* * chibios_fatfs::FatFSWrapper::FatFSServerThread * *------------------------------------------------------------------------*/ - FatFSWrapper::FatFSServerThread::FatFSServerThread(::BaseBlockDevice *blkdev) : - BaseStaticThread(), - blkdev(blkdev) { + FatFSWrapper::FatFSServerThread::FatFSServerThread(void) : + BaseStaticThread() { start(FATFS_THREAD_PRIORITY); } @@ -79,18 +78,28 @@ namespace chibios_fatfs { } } + void FatFSWrapper::FatFSServerThread::stop(void) { + + sendMessage(MSG_TERMINATE); + wait(); + } + /*------------------------------------------------------------------------* * chibios_fatfs::FatFSWrapper * *------------------------------------------------------------------------*/ - FatFSWrapper::FatFSWrapper(::BaseBlockDevice *blkdev) : server(blkdev) { + FatFSWrapper::FatFSWrapper(void) { + + } + + void FatFSWrapper::mount(void) { server.start(FATFS_THREAD_PRIORITY); } -/* FatFSWrapper::~FatFSWrapper() { + void FatFSWrapper::unmount(void) { - server.~FatFSServerThread(); - }*/ + server.stop(); + } uint32_t FatFSWrapper::getAndClearLastError(void) { diff --git a/os/fs/fatfs/fatfs_fsimpl.hpp b/os/fs/fatfs/fatfs_fsimpl.hpp index 8c61c5748..cdb46bc66 100644 --- a/os/fs/fatfs/fatfs_fsimpl.hpp +++ b/os/fs/fatfs/fatfs_fsimpl.hpp @@ -28,7 +28,6 @@ #include "ch.hpp" #include "fs.hpp" -#include "hal.h" #ifndef _FS_FATFS_IMPL_HPP_ #define _FS_FATFS_IMPL_HPP_ @@ -67,16 +66,15 @@ namespace chibios_fatfs { * @brief Class of the internal server thread. */ class FatFSServerThread : public BaseStaticThread { - private: - ::BaseBlockDevice *blkdev; protected: virtual msg_t main(void); public: - FatFSServerThread(::BaseBlockDevice *blkdev); + FatFSServerThread(void); + virtual void stop(void); } server; public: - FatFSWrapper(::BaseBlockDevice *blkdev); + FatFSWrapper(void); virtual uint32_t getAndClearLastError(void); virtual void synchronize(void); virtual void remove(const char *fname); @@ -84,6 +82,16 @@ namespace chibios_fatfs { virtual BaseFileStreamInterface *openForRead(const char *fname); virtual BaseFileStreamInterface *openForWrite(const char *fname); virtual BaseFileStreamInterface *create(const char *fname); + + /** + * @brief Mounts the file system. + */ + void mount(void); + + /** + * @brief Unmounts the file system. + */ + void unmount(void); }; } diff --git a/os/various/cpp_wrappers/ch.cpp b/os/various/cpp_wrappers/ch.cpp index 5191f2748..c971a90aa 100644 --- a/os/various/cpp_wrappers/ch.cpp +++ b/os/various/cpp_wrappers/ch.cpp @@ -97,6 +97,12 @@ namespace chibios_rt { /*------------------------------------------------------------------------* * chibios_rt::ThreadReference * *------------------------------------------------------------------------*/ + + void ThreadReference::stop(void) { + + chDbgPanic("invoked unimplemented method stop()"); + } + msg_t ThreadReference::suspend(void) { msg_t msg; @@ -158,6 +164,10 @@ namespace chibios_rt { void ThreadReference::requestTerminate(void) { + chDbgAssert(thread_ref != NULL, + "ThreadReference, #5", + "not referenced"); + chThdTerminate(thread_ref); } @@ -165,7 +175,7 @@ namespace chibios_rt { msg_t ThreadReference::wait(void) { chDbgAssert(thread_ref != NULL, - "ThreadReference, #5", + "ThreadReference, #6", "not referenced"); msg_t msg = chThdWait(thread_ref); @@ -178,7 +188,7 @@ namespace chibios_rt { msg_t ThreadReference::sendMessage(msg_t msg) { chDbgAssert(thread_ref != NULL, - "ThreadReference, #6", + "ThreadReference, #7", "not referenced"); return chMsgSend(thread_ref, msg); @@ -186,16 +196,28 @@ namespace chibios_rt { bool ThreadReference::isPendingMessage(void) { + chDbgAssert(thread_ref != NULL, + "ThreadReference, #7", + "not referenced"); + return (bool)chMsgIsPendingI(thread_ref); } msg_t ThreadReference::getMessage(void) { + chDbgAssert(thread_ref != NULL, + "ThreadReference, #8", + "not referenced"); + return chMsgGet(thread_ref); } void ThreadReference::releaseMessage(msg_t msg) { + chDbgAssert(thread_ref != NULL, + "ThreadReference, #9", + "not referenced"); + chMsgRelease(thread_ref, msg); } #endif /* CH_USE_MESSAGES */ @@ -203,11 +225,19 @@ namespace chibios_rt { #if CH_USE_EVENTS void ThreadReference::signalEvents(eventmask_t mask) { + chDbgAssert(thread_ref != NULL, + "ThreadReference, #10", + "not referenced"); + chEvtSignal(thread_ref, mask); } void ThreadReference::signalEventsI(eventmask_t mask) { + chDbgAssert(thread_ref != NULL, + "ThreadReference, #11", + "not referenced"); + chEvtSignalI(thread_ref, mask); } #endif /* CH_USE_EVENTS */ @@ -359,66 +389,66 @@ namespace chibios_rt { #if CH_USE_SEMAPHORES /*------------------------------------------------------------------------* - * chibios_rt::Semaphore * + * chibios_rt::CounterSemaphore * *------------------------------------------------------------------------*/ - Semaphore::Semaphore(cnt_t n) { + CounterSemaphore::CounterSemaphore(cnt_t n) { chSemInit(&sem, n); } - void Semaphore::reset(cnt_t n) { + void CounterSemaphore::reset(cnt_t n) { chSemReset(&sem, n); } - void Semaphore::resetI(cnt_t n) { + void CounterSemaphore::resetI(cnt_t n) { chSemResetI(&sem, n); } - msg_t Semaphore::wait(void) { + msg_t CounterSemaphore::wait(void) { return chSemWait(&sem); } - msg_t Semaphore::waitS(void) { + msg_t CounterSemaphore::waitS(void) { return chSemWaitS(&sem); } - msg_t Semaphore::waitTimeout(systime_t time) { + msg_t CounterSemaphore::waitTimeout(systime_t time) { return chSemWaitTimeout(&sem, time); } - msg_t Semaphore::waitTimeoutS(systime_t time) { + msg_t CounterSemaphore::waitTimeoutS(systime_t time) { return chSemWaitTimeoutS(&sem, time); } - void Semaphore::signal(void) { + void CounterSemaphore::signal(void) { chSemSignal(&sem); } - void Semaphore::signalI(void) { + void CounterSemaphore::signalI(void) { chSemSignalI(&sem); } - void Semaphore::addCounterI(cnt_t n) { + void CounterSemaphore::addCounterI(cnt_t n) { chSemAddCounterI(&sem, n); } - cnt_t Semaphore::getCounterI(void) { + cnt_t CounterSemaphore::getCounterI(void) { return chSemGetCounterI(&sem); } #if CH_USE_SEMSW - msg_t Semaphore::signalWait(chibios_rt::Semaphore *ssem, - chibios_rt::Semaphore *wsem) { + msg_t CounterSemaphore::signalWait(CounterSemaphore *ssem, + CounterSemaphore *wsem) { return chSemSignalWait(&ssem->sem, &wsem->sem); } @@ -607,110 +637,108 @@ namespace chibios_rt { #if CH_USE_QUEUES /*------------------------------------------------------------------------* - * chibios_rt::InputQueue * + * chibios_rt::InQueue * *------------------------------------------------------------------------*/ - InputQueue::InputQueue(uint8_t *bp, size_t size, - qnotify_t infy, void *link) { + InQueue::InQueue(uint8_t *bp, size_t size, qnotify_t infy, void *link) { chIQInit(&iq, bp, size, infy, link); } - size_t InputQueue::getFullI(void) { + size_t InQueue::getFullI(void) { return chIQGetFullI(&iq); } - size_t InputQueue::getEmptyI(void) { + size_t InQueue::getEmptyI(void) { return chIQGetEmptyI(&iq); } - bool InputQueue::isEmptyI(void) { + bool InQueue::isEmptyI(void) { return (bool)chIQIsEmptyI(&iq); } - bool InputQueue::isFullI(void) { + bool InQueue::isFullI(void) { return (bool)chIQIsFullI(&iq); } - void InputQueue::resetI(void) { + void InQueue::resetI(void) { chIQResetI(&iq); } - msg_t InputQueue::putI(uint8_t b) { + msg_t InQueue::putI(uint8_t b) { return chIQPutI(&iq, b); } - msg_t InputQueue::get() { + msg_t InQueue::get() { return chIQGet(&iq); } - msg_t InputQueue::getTimeout(systime_t time) { + msg_t InQueue::getTimeout(systime_t time) { return chIQGetTimeout(&iq, time); } - size_t InputQueue::readTimeout(uint8_t *bp, size_t n, systime_t time) { + size_t InQueue::readTimeout(uint8_t *bp, size_t n, systime_t time) { return chIQReadTimeout(&iq, bp, n, time); } /*------------------------------------------------------------------------* - * chibios_rt::OutputQueue * + * chibios_rt::OutQueue * *------------------------------------------------------------------------*/ - OutputQueue::OutputQueue(uint8_t *bp, size_t size, - qnotify_t onfy, void *link) { + OutQueue::OutQueue(uint8_t *bp, size_t size, qnotify_t onfy, void *link) { chOQInit(&oq, bp, size, onfy, link); } - size_t OutputQueue::getFullI(void) { + size_t OutQueue::getFullI(void) { return chOQGetFullI(&oq); } - size_t OutputQueue::getEmptyI(void) { + size_t OutQueue::getEmptyI(void) { return chOQGetEmptyI(&oq); } - bool OutputQueue::isEmptyI(void) { + bool OutQueue::isEmptyI(void) { return (bool)chOQIsEmptyI(&oq); } - bool OutputQueue::isFullI(void) { + bool OutQueue::isFullI(void) { return (bool)chOQIsFullI(&oq); } - void OutputQueue::resetI(void) { + void OutQueue::resetI(void) { chOQResetI(&oq); } - msg_t OutputQueue::put(uint8_t b) { + msg_t OutQueue::put(uint8_t b) { return chOQPut(&oq, b); } - msg_t OutputQueue::putTimeout(uint8_t b, systime_t time) { + msg_t OutQueue::putTimeout(uint8_t b, systime_t time) { return chOQPutTimeout(&oq, b, time); } - msg_t OutputQueue::getI(void) { + msg_t OutQueue::getI(void) { return chOQGetI(&oq); } - size_t OutputQueue::writeTimeout(const uint8_t *bp, size_t n, - systime_t time) { + size_t OutQueue::writeTimeout(const uint8_t *bp, size_t n, + systime_t time) { return chOQWriteTimeout(&oq, bp, n, time); } diff --git a/os/various/cpp_wrappers/ch.hpp b/os/various/cpp_wrappers/ch.hpp index 370b9a3f2..6e41cea6e 100644 --- a/os/various/cpp_wrappers/ch.hpp +++ b/os/various/cpp_wrappers/ch.hpp @@ -225,6 +225,13 @@ namespace chibios_rt { }; + /** + * @brief Stops the thread. + * @note The implementation is left to descendant classes and is + * optional. + */ + virtual void stop(void); + /** * @brief Suspends the current thread on the reference. * @details The suspended thread becomes the referenced thread. It is @@ -752,12 +759,12 @@ namespace chibios_rt { #if CH_USE_SEMAPHORES || defined(__DOXYGEN__) /*------------------------------------------------------------------------* - * chibios_rt::Semaphore * + * chibios_rt::CounterSemaphore * *------------------------------------------------------------------------*/ /** * @brief Class encapsulating a semaphore. */ - class Semaphore { + class CounterSemaphore { public: /** * @brief Embedded @p ::Semaphore structure. @@ -765,7 +772,7 @@ namespace chibios_rt { ::Semaphore sem; /** - * @brief Semaphore constructor. + * @brief CounterSemaphore constructor. * @details The embedded @p ::Semaphore structure is initialized. * * @param[in] n the semaphore counter value, must be greater @@ -773,7 +780,7 @@ namespace chibios_rt { * * @init */ - Semaphore(cnt_t n); + CounterSemaphore(cnt_t n); /** * @brief Performs a reset operation on the semaphore. @@ -930,8 +937,8 @@ namespace chibios_rt { * * @api */ - static msg_t signalWait(chibios_rt::Semaphore *ssem, - chibios_rt::Semaphore *wsem); + static msg_t signalWait(CounterSemaphore *ssem, + CounterSemaphore *wsem); #endif /* CH_USE_SEMSW */ }; /*------------------------------------------------------------------------* @@ -1398,12 +1405,12 @@ namespace chibios_rt { #if CH_USE_QUEUES || defined(__DOXYGEN__) /*------------------------------------------------------------------------* - * chibios_rt::InputQueue * + * chibios_rt::InQueue * *------------------------------------------------------------------------*/ /** * @brief Class encapsulating an input queue. */ - class InputQueue { + class InQueue { private: /** * @brief Embedded @p ::InputQueue structure. @@ -1412,7 +1419,7 @@ namespace chibios_rt { public: /** - * @brief InputQueue constructor. + * @brief InQueue constructor. * * @param[in] bp pointer to a memory area allocated as queue buffer * @param[in] size size of the queue buffer @@ -1422,7 +1429,7 @@ namespace chibios_rt { * * @init */ - InputQueue(uint8_t *bp, size_t size, qnotify_t infy, void *link); + InQueue(uint8_t *bp, size_t size, qnotify_t infy, void *link); /** * @brief Returns the filled space into an input queue. @@ -1551,7 +1558,7 @@ namespace chibios_rt { }; /*------------------------------------------------------------------------* - * chibios_rt::InputQueueBuffer * + * chibios_rt::InQueueBuffer * *------------------------------------------------------------------------*/ /** * @brief Template class encapsulating an input queue and its buffer. @@ -1559,28 +1566,28 @@ namespace chibios_rt { * @param N size of the input queue */ template - class InputQueueBuffer : public InputQueue { + class InQueueBuffer : public InQueue { private: uint8_t iq_buf[N]; public: /** - * @brief InputQueueBuffer constructor. + * @brief InQueueBuffer constructor. * * @init */ - InputQueueBuffer(qnotify_t infy, void *link) : InputQueue(iq_buf, N, - infy, link) { + InQueueBuffer(qnotify_t infy, void *link) : InQueue(iq_buf, N, + infy, link) { } }; /*------------------------------------------------------------------------* - * chibios_rt::OutputQueue * + * chibios_rt::OutQueue * *------------------------------------------------------------------------*/ /** * @brief Class encapsulating an output queue. */ - class OutputQueue { + class OutQueue { private: /** * @brief Embedded @p ::OutputQueue structure. @@ -1589,7 +1596,7 @@ namespace chibios_rt { public: /** - * @brief OutputQueue constructor. + * @brief OutQueue constructor. * * @param[in] bp pointer to a memory area allocated as queue buffer * @param[in] size size of the queue buffer @@ -1599,7 +1606,7 @@ namespace chibios_rt { * * @init */ - OutputQueue(uint8_t *bp, size_t size, qnotify_t onfy, void *link); + OutQueue(uint8_t *bp, size_t size, qnotify_t onfy, void *link); /** * @brief Returns the filled space into an output queue. @@ -1730,7 +1737,7 @@ namespace chibios_rt { }; /*------------------------------------------------------------------------* - * chibios_rt::OutputQueueBuffer * + * chibios_rt::OutQueueBuffer * *------------------------------------------------------------------------*/ /** * @brief Template class encapsulating an output queue and its buffer. @@ -1738,18 +1745,18 @@ namespace chibios_rt { * @param N size of the output queue */ template - class OutputQueueBuffer : public OutputQueue { + class OutQueueBuffer : public OutQueue { private: uint8_t oq_buf[N]; public: /** - * @brief OutputQueueBuffer constructor. + * @brief OutQueueBuffer constructor. * * @init */ - OutputQueueBuffer(qnotify_t onfy, void *link) : InputQueue(oq_buf, N, - onfy, link) { + OutQueueBuffer(qnotify_t onfy, void *link) : OutQueue(oq_buf, N, + onfy, link) { } }; #endif /* CH_USE_QUEUES */