Wiselib
wiselib.testing/external_interface/contiki/contiki_clock.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  ** This file is part of the generic algorithm library Wiselib.           **
00003  ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project.      **
00004  **                                                                       **
00005  ** The Wiselib is free software: you can redistribute it and/or modify   **
00006  ** it under the terms of the GNU Lesser General Public License as        **
00007  ** published by the Free Software Foundation, either version 3 of the    **
00008  ** License, or (at your option) any later version.                       **
00009  **                                                                       **
00010  ** The Wiselib is distributed in the hope that it will be useful,        **
00011  ** but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00012  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00013  ** GNU Lesser General Public License for more details.                   **
00014  **                                                                       **
00015  ** You should have received a copy of the GNU Lesser General Public      **
00016  ** License along with the Wiselib.                                       **
00017  ** If not, see <http://www.gnu.org/licenses/>.                           **
00018  ***************************************************************************/
00019 
00020 
00021 #include "external_interface/contiki/contiki_types.h"
00022 #include "external_interface/contiki/contiki_os.h"
00023 #include "external_interface/contiki/contiki_timer.h"
00024 
00025 //#include <contiki/os.h>
00026 //#include <contiki/timer.h>
00027 //#include <contiki/clock.h>
00028 
00029 extern "C" {
00030 #include "contiki.h"
00031 #include "sys/etimer.h"
00032 #include "sys/timer.h"
00033 #include "sys/clock.h"
00034 }
00035 
00036 namespace wiselib
00037 {
00046    template<typename OsModel_P>
00047    class ContikiClockModel
00048    {
00049    public:
00050       typedef OsModel_P OsModel;
00051 
00052       typedef ContikiClockModel<OsModel> self_type;
00053       typedef self_type* self_pointer_t;
00054 
00055       typedef clock_time_t time_t;
00056 
00057       // --------------------------------------------------------------------
00058       enum ErrorCodes
00059       {
00060          SUCCESS = OsModel::SUCCESS,
00061          ERR_UNSPEC = OsModel::ERR_UNSPEC
00062       };
00063       // --------------------------------------------------------------------
00064       enum
00065       {
00066          READY = OsModel::READY,
00067          NO_VALUE = OsModel::NO_VALUE,
00068          INACTIVE = OsModel::INACTIVE
00069       };
00070       // --------------------------------------------------------------------
00071       enum
00072       {
00073          CLOCKS_PER_SEC = 1000
00074       };
00075       // --------------------------------------------------------------------
00076       ContikiClockModel(  )
00077       {}
00078       // --------------------------------------------------------------------
00079       void init()
00080       {}
00081       // --------------------------------------------------------------------
00082       int state()
00083       {
00084          return READY;
00085       }
00086       // --------------------------------------------------------------------
00087       time_t time()
00088       {
00089          return clock_time();
00090       }
00091       // --------------------------------------------------------------------
00092       int set_time( time_t time )
00093       {
00094          //  timer_set(timer, time);
00095          return SUCCESS;
00096       }
00097       // --------------------------------------------------------------------
00098       uint16_t microseconds( time_t time )
00099       {
00100          return 0;
00101       }
00102       // --------------------------------------------------------------------
00103       uint16_t milliseconds( time_t time )
00104       {
00105          return (uint16_t)(time - int(time)) * 1000;
00106       }
00107       // --------------------------------------------------------------------
00108       uint32_t seconds( time_t time )
00109       {
00110          return CLOCK_SECOND;
00111       }
00112 
00113    private:
00114      struct timer {
00115        time_t start;
00116        time_t interval;
00117      };
00118 
00119    };
00120 }
00121 
00122 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines