Menu

AtmelSerialDriver.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2010 Thomas Kiebel <kiebel@ivs.cs.uni-magdeburg.de>
00004  *               2010 Karl Fessel <karl.fessel@st.ovgu.de>
00005  * All rights reserved.
00006  *
00007  *    Redistribution and use in source and binary forms, with or without
00008  *    modification, are permitted provided that the following conditions
00009  *    are met:
00010  *
00011  *    * Redistributions of source code must retain the above copyright
00012  *      notice, this list of conditions and the following disclaimer.
00013  *
00014  *    * Redistributions in binary form must reproduce the above copyright
00015  *      notice, this list of conditions and the following disclaimer in
00016  *      the documentation and/or other materials provided with the
00017  *      distribution.
00018  *
00019  *    * Neither the name of the copyright holders nor the names of
00020  *      contributors may be used to endorse or promote products derived
00021  *      from this software without specific prior written permission.
00022  *
00023  *
00024  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00025  *    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026  *    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027  *    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00028  *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00029  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00030  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031  *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00032  *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00033  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  *
00037  * $Id$
00038  *
00039  ******************************************************************************/
00040 #ifndef __ATMEL_SERIAL_DRIVER_h__
00041 #define __ATMEL_SERIAL_DRIVER_h__
00042 
00043 #include "avr-halib/share/cframe.h"
00044 #include "avr-halib/share/delegate.h"
00045 
00046 #include "case/Delegate.h"
00047 #include "devices/nic/serial/SerialFrameDelimiter.h"
00048 #include "debug.h"
00049 
00050 using namespace std;
00051 
00052 namespace device {
00053     namespace nic {
00054         namespace serial {
00067             template <
00068                         class DEV,
00069                         uint8_t PL  = 255,
00070                         uint16_t BR = 19200,
00071                         class SFD   = struct SerialFrameDelimiter
00072                      >
00073             class AtmelSerialDriver : public CFrame< DEV, uint8_t, SFD, PL> {
00074                 public:
00076                     typedef CFrame< DEV, uint8_t, SFD, PL> baseType;
00078                     typedef AtmelSerialDriver<DEV, PL, BR, SFD> type;
00080                     typedef typename baseType::mob_t mob_t;
00082                     struct cfgInfo {
00083                         enum {
00084                             payload = PL
00085                         };
00086                     };
00087                 protected:
00088                     void handleReceive() {
00089                         if (this->onReceive) this->onReceive();
00090                     }
00091                     void handleReady()   {
00092                         if (this->onReady) this->onReady();
00093                     }
00094                 public:
00095                     AtmelSerialDriver() {}
00096                     ~AtmelSerialDriver() {}
00097 
00101                     void init() {
00102                         TRACE_FUNCTION;
00103                         baseType::onReady.template bind< type, &type::handleReady>(this);
00104                         baseType::onReceive.template bind<type, &type::handleReceive>(this);
00105                         baseType::enableonReceive();
00106                     }
00107 
00112                     void recv(mob_t& message) {
00113                         TRACE_FUNCTION;
00114                         baseType::recv(message);
00115                     }
00116 
00121                     void send(const mob_t& message) {
00122                         TRACE_FUNCTION;
00123                         baseType::send(message);
00124                     }
00125 
00127                     famouso::util::Delegate<> onReceive;
00128 
00134                     famouso::util::Delegate<> onReady;
00135             };
00136         } /* namespace armarow */
00137     } /* namespace nic */
00138 } /* namespace device */
00139 
00140 #endif  //__ATMEL_SERIAL_DRIVER_h__