Dependencies:   PinDetect TextLCD mbed mRotaryEncoder

Committer:
cicklaus
Date:
Mon Feb 13 02:11:20 2012 +0000
Revision:
0:afb2650fb49a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cicklaus 0:afb2650fb49a 1 //******************************************************************************
cicklaus 0:afb2650fb49a 2 //*
cicklaus 0:afb2650fb49a 3 //* FULLNAME: Single-Chip Microcontroller Real-Time Operating System
cicklaus 0:afb2650fb49a 4 //*
cicklaus 0:afb2650fb49a 5 //* NICKNAME: scmRTOS
cicklaus 0:afb2650fb49a 6 //*
cicklaus 0:afb2650fb49a 7 //* PURPOSE: User Suport Library Source
cicklaus 0:afb2650fb49a 8 //*
cicklaus 0:afb2650fb49a 9 //* Version: 3.10
cicklaus 0:afb2650fb49a 10 //*
cicklaus 0:afb2650fb49a 11 //* $Revision: 256 $
cicklaus 0:afb2650fb49a 12 //* $Date:: 2010-01-22 #$
cicklaus 0:afb2650fb49a 13 //*
cicklaus 0:afb2650fb49a 14 //* Copyright (c) 2003-2010, Harry E. Zhurov
cicklaus 0:afb2650fb49a 15 //*
cicklaus 0:afb2650fb49a 16 //* Permission is hereby granted, free of charge, to any person
cicklaus 0:afb2650fb49a 17 //* obtaining a copy of this software and associated documentation
cicklaus 0:afb2650fb49a 18 //* files (the "Software"), to deal in the Software without restriction,
cicklaus 0:afb2650fb49a 19 //* including without limitation the rights to use, copy, modify, merge,
cicklaus 0:afb2650fb49a 20 //* publish, distribute, sublicense, and/or sell copies of the Software,
cicklaus 0:afb2650fb49a 21 //* and to permit persons to whom the Software is furnished to do so,
cicklaus 0:afb2650fb49a 22 //* subject to the following conditions:
cicklaus 0:afb2650fb49a 23 //*
cicklaus 0:afb2650fb49a 24 //* The above copyright notice and this permission notice shall be included
cicklaus 0:afb2650fb49a 25 //* in all copies or substantial portions of the Software.
cicklaus 0:afb2650fb49a 26 //*
cicklaus 0:afb2650fb49a 27 //* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cicklaus 0:afb2650fb49a 28 //* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cicklaus 0:afb2650fb49a 29 //* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
cicklaus 0:afb2650fb49a 30 //* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
cicklaus 0:afb2650fb49a 31 //* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
cicklaus 0:afb2650fb49a 32 //* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
cicklaus 0:afb2650fb49a 33 //* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cicklaus 0:afb2650fb49a 34 //*
cicklaus 0:afb2650fb49a 35 //* =================================================================
cicklaus 0:afb2650fb49a 36 //* See http://scmrtos.sourceforge.net for documentation, latest
cicklaus 0:afb2650fb49a 37 //* information, license and contact details.
cicklaus 0:afb2650fb49a 38 //* =================================================================
cicklaus 0:afb2650fb49a 39 //*
cicklaus 0:afb2650fb49a 40 //******************************************************************************
cicklaus 0:afb2650fb49a 41
cicklaus 0:afb2650fb49a 42 #include <usrlib.h>
cicklaus 0:afb2650fb49a 43 #include <commdefs.h>
cicklaus 0:afb2650fb49a 44
cicklaus 0:afb2650fb49a 45 using namespace usr;
cicklaus 0:afb2650fb49a 46
cicklaus 0:afb2650fb49a 47 //------------------------------------------------------------------------------
cicklaus 0:afb2650fb49a 48 //
cicklaus 0:afb2650fb49a 49 /// Circular buffer function-member description
cicklaus 0:afb2650fb49a 50 //
cicklaus 0:afb2650fb49a 51 //
cicklaus 0:afb2650fb49a 52 //
cicklaus 0:afb2650fb49a 53 TCbuf::TCbuf(byte* const Address, const byte Size) :
cicklaus 0:afb2650fb49a 54 buf(Address),
cicklaus 0:afb2650fb49a 55 size(Size),
cicklaus 0:afb2650fb49a 56 count(0),
cicklaus 0:afb2650fb49a 57 first(0),
cicklaus 0:afb2650fb49a 58 last(0)
cicklaus 0:afb2650fb49a 59 {
cicklaus 0:afb2650fb49a 60 }
cicklaus 0:afb2650fb49a 61 //------------------------------------------------------------------------------
cicklaus 0:afb2650fb49a 62 bool TCbuf::write(const byte* data, const byte Count)
cicklaus 0:afb2650fb49a 63 {
cicklaus 0:afb2650fb49a 64 if( Count > (size - count) )
cicklaus 0:afb2650fb49a 65 return false;
cicklaus 0:afb2650fb49a 66
cicklaus 0:afb2650fb49a 67 for(byte i = 0; i < Count; i++)
cicklaus 0:afb2650fb49a 68 push(*(data++));
cicklaus 0:afb2650fb49a 69
cicklaus 0:afb2650fb49a 70 return true;
cicklaus 0:afb2650fb49a 71 }
cicklaus 0:afb2650fb49a 72 //------------------------------------------------------------------------------
cicklaus 0:afb2650fb49a 73 void TCbuf::read(byte* data, const byte Count)
cicklaus 0:afb2650fb49a 74 {
cicklaus 0:afb2650fb49a 75 byte N = Count <= count ? Count : count;
cicklaus 0:afb2650fb49a 76
cicklaus 0:afb2650fb49a 77 for(byte i = 0; i < N; i++)
cicklaus 0:afb2650fb49a 78 data[i] = pop();
cicklaus 0:afb2650fb49a 79 }
cicklaus 0:afb2650fb49a 80 //------------------------------------------------------------------------------
cicklaus 0:afb2650fb49a 81 byte TCbuf::get_byte(const byte index) const
cicklaus 0:afb2650fb49a 82 {
cicklaus 0:afb2650fb49a 83 byte x = first + index;
cicklaus 0:afb2650fb49a 84
cicklaus 0:afb2650fb49a 85 if(x < size)
cicklaus 0:afb2650fb49a 86 return buf[x];
cicklaus 0:afb2650fb49a 87 else
cicklaus 0:afb2650fb49a 88 return buf[x - size];
cicklaus 0:afb2650fb49a 89 }
cicklaus 0:afb2650fb49a 90
cicklaus 0:afb2650fb49a 91 //------------------------------------------------------------------------------
cicklaus 0:afb2650fb49a 92 bool TCbuf::put(const byte item)
cicklaus 0:afb2650fb49a 93 {
cicklaus 0:afb2650fb49a 94 if(count == size)
cicklaus 0:afb2650fb49a 95 return false;
cicklaus 0:afb2650fb49a 96
cicklaus 0:afb2650fb49a 97 push(item);
cicklaus 0:afb2650fb49a 98 return true;
cicklaus 0:afb2650fb49a 99 }
cicklaus 0:afb2650fb49a 100 //------------------------------------------------------------------------------
cicklaus 0:afb2650fb49a 101 byte TCbuf::get()
cicklaus 0:afb2650fb49a 102 {
cicklaus 0:afb2650fb49a 103 if(count)
cicklaus 0:afb2650fb49a 104 return pop();
cicklaus 0:afb2650fb49a 105 else
cicklaus 0:afb2650fb49a 106 return 0;
cicklaus 0:afb2650fb49a 107 }
cicklaus 0:afb2650fb49a 108 //------------------------------------------------------------------------------
cicklaus 0:afb2650fb49a 109 //
cicklaus 0:afb2650fb49a 110 /// \note
cicklaus 0:afb2650fb49a 111 /// For internal purposes.
cicklaus 0:afb2650fb49a 112 /// Use this function with care - it doesn't perform free size check.
cicklaus 0:afb2650fb49a 113 //
cicklaus 0:afb2650fb49a 114 void TCbuf::push(const byte item)
cicklaus 0:afb2650fb49a 115 {
cicklaus 0:afb2650fb49a 116 buf[last] = item;
cicklaus 0:afb2650fb49a 117 last++;
cicklaus 0:afb2650fb49a 118 count++;
cicklaus 0:afb2650fb49a 119
cicklaus 0:afb2650fb49a 120 if(last == size)
cicklaus 0:afb2650fb49a 121 last = 0;
cicklaus 0:afb2650fb49a 122 }
cicklaus 0:afb2650fb49a 123 //------------------------------------------------------------------------------
cicklaus 0:afb2650fb49a 124 //
cicklaus 0:afb2650fb49a 125 /// \note
cicklaus 0:afb2650fb49a 126 /// For internal purposes.
cicklaus 0:afb2650fb49a 127 /// Use this function with care - it doesn't perform free size check.
cicklaus 0:afb2650fb49a 128 //
cicklaus 0:afb2650fb49a 129 byte TCbuf::pop()
cicklaus 0:afb2650fb49a 130 {
cicklaus 0:afb2650fb49a 131 byte item = buf[first];
cicklaus 0:afb2650fb49a 132
cicklaus 0:afb2650fb49a 133 count--;
cicklaus 0:afb2650fb49a 134 first++;
cicklaus 0:afb2650fb49a 135 if(first == size)
cicklaus 0:afb2650fb49a 136 first = 0;
cicklaus 0:afb2650fb49a 137
cicklaus 0:afb2650fb49a 138 return item;
cicklaus 0:afb2650fb49a 139 }
cicklaus 0:afb2650fb49a 140 //------------------------------------------------------------------------------