Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Committer:
narshu
Date:
Wed Oct 17 22:22:47 2012 +0000
Revision:
26:0995f61cb7b8
Parent:
17:bafcef1c3579
Eurobot 2012 Primary;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
narshu 17:bafcef1c3579 1 #ifndef TSH_H
narshu 17:bafcef1c3579 2 #define TSH_H
narshu 17:bafcef1c3579 3
narshu 17:bafcef1c3579 4 #include "rtos.h"
narshu 17:bafcef1c3579 5
narshu 17:bafcef1c3579 6 //Thread Safe Hardware
narshu 17:bafcef1c3579 7
narshu 17:bafcef1c3579 8 class TSI2C : public I2C {
narshu 17:bafcef1c3579 9 public:
narshu 17:bafcef1c3579 10
narshu 17:bafcef1c3579 11 TSI2C( PinName sda,
narshu 17:bafcef1c3579 12 PinName scl,
narshu 17:bafcef1c3579 13 const char* name=NULL )
narshu 17:bafcef1c3579 14 : I2C(sda, scl, name) { }
narshu 17:bafcef1c3579 15
narshu 17:bafcef1c3579 16
narshu 17:bafcef1c3579 17 int read( int address,
narshu 17:bafcef1c3579 18 char* data,
narshu 17:bafcef1c3579 19 int length,
narshu 17:bafcef1c3579 20 bool repeated = false ) {
narshu 17:bafcef1c3579 21
narshu 17:bafcef1c3579 22 rlock.lock();
narshu 17:bafcef1c3579 23 int retval = I2C::read(address, data, length, repeated);
narshu 17:bafcef1c3579 24 rlock.unlock();
narshu 17:bafcef1c3579 25
narshu 17:bafcef1c3579 26 return retval;
narshu 17:bafcef1c3579 27 }
narshu 17:bafcef1c3579 28
narshu 17:bafcef1c3579 29 int read(int ack) {
narshu 17:bafcef1c3579 30 rlock.lock();
narshu 17:bafcef1c3579 31 int retval = I2C::read(ack);
narshu 17:bafcef1c3579 32 rlock.unlock();
narshu 17:bafcef1c3579 33
narshu 17:bafcef1c3579 34 return retval;
narshu 17:bafcef1c3579 35 }
narshu 17:bafcef1c3579 36
narshu 17:bafcef1c3579 37 int write( int address,
narshu 17:bafcef1c3579 38 const char* data,
narshu 17:bafcef1c3579 39 int length,
narshu 17:bafcef1c3579 40 bool repeated = false ) {
narshu 17:bafcef1c3579 41
narshu 17:bafcef1c3579 42 wlock.lock();
narshu 17:bafcef1c3579 43 int retval = I2C::write(address, data, length, repeated);
narshu 17:bafcef1c3579 44 wlock.unlock();
narshu 17:bafcef1c3579 45
narshu 17:bafcef1c3579 46 return retval;
narshu 17:bafcef1c3579 47 }
narshu 17:bafcef1c3579 48
narshu 17:bafcef1c3579 49 int write(int data) {
narshu 17:bafcef1c3579 50 wlock.lock();
narshu 17:bafcef1c3579 51 int retval = I2C::write(data);
narshu 17:bafcef1c3579 52 wlock.unlock();
narshu 17:bafcef1c3579 53
narshu 17:bafcef1c3579 54 return retval;
narshu 17:bafcef1c3579 55 }
narshu 17:bafcef1c3579 56
narshu 17:bafcef1c3579 57 private:
narshu 17:bafcef1c3579 58 Mutex rlock;
narshu 17:bafcef1c3579 59 Mutex wlock;
narshu 17:bafcef1c3579 60 };
narshu 17:bafcef1c3579 61
narshu 17:bafcef1c3579 62 #endif