Tapton School Project to monitor and log SEN students physiological condition using GSR (conductivity) & Heart Rate and displaying output and logging the data to an SD card

Dependencies:   SMARTGPU2 mbed

Committer:
raheel123
Date:
Fri Feb 09 08:34:23 2018 +0000
Revision:
0:0e26bf847b57
Tapton school SENtinel project

Who changed what in which revision?

UserRevisionLine numberNew contents of line
raheel123 0:0e26bf847b57 1 #include <mbed.h>
raheel123 0:0e26bf847b57 2
raheel123 0:0e26bf847b57 3 // The us ticker is a wrapping uint32_t. We insert interrupts at
raheel123 0:0e26bf847b57 4 // 0, 0x40000000, 0x8000000, and 0xC0000000, rather than just 0 or just 0xFFFFFFFF because there is
raheel123 0:0e26bf847b57 5 // code that calls interrupts that are "very soon" immediately and we don't
raheel123 0:0e26bf847b57 6 // want that. Also because if we only use 0 and 0x80000000 then there is a chance it would
raheel123 0:0e26bf847b57 7 // be considered to be in the past and executed immediately.
raheel123 0:0e26bf847b57 8
raheel123 0:0e26bf847b57 9 class ExtendedClock : public TimerEvent
raheel123 0:0e26bf847b57 10 {
raheel123 0:0e26bf847b57 11 public:
raheel123 0:0e26bf847b57 12 ExtendedClock()
raheel123 0:0e26bf847b57 13 {
raheel123 0:0e26bf847b57 14 // This also starts the us ticker.
raheel123 0:0e26bf847b57 15 insert(0x40000000);
raheel123 0:0e26bf847b57 16 }
raheel123 0:0e26bf847b57 17
raheel123 0:0e26bf847b57 18 float read()
raheel123 0:0e26bf847b57 19 {
raheel123 0:0e26bf847b57 20 return read_us() / 1000000.0f;
raheel123 0:0e26bf847b57 21 }
raheel123 0:0e26bf847b57 22
raheel123 0:0e26bf847b57 23 uint64_t read_ms()
raheel123 0:0e26bf847b57 24 {
raheel123 0:0e26bf847b57 25 return read_us() / 1000;
raheel123 0:0e26bf847b57 26 }
raheel123 0:0e26bf847b57 27
raheel123 0:0e26bf847b57 28 uint64_t read_us()
raheel123 0:0e26bf847b57 29 {
raheel123 0:0e26bf847b57 30 return mTriggers * 0x40000000ull + (ticker_read(_ticker_data) & 0x3FFFFFFF);
raheel123 0:0e26bf847b57 31 }
raheel123 0:0e26bf847b57 32
raheel123 0:0e26bf847b57 33 private:
raheel123 0:0e26bf847b57 34 virtual void handler()
raheel123 0:0e26bf847b57 35 {
raheel123 0:0e26bf847b57 36 ++mTriggers;
raheel123 0:0e26bf847b57 37 // If this is the first time we've been called (at 0x4...)
raheel123 0:0e26bf847b57 38 // then mTriggers now equals 1 and we want to insert at 0x80000000.
raheel123 0:0e26bf847b57 39 insert((mTriggers+1) * 0x40000000);
raheel123 0:0e26bf847b57 40 }
raheel123 0:0e26bf847b57 41
raheel123 0:0e26bf847b57 42 // The number of times the us_ticker has rolled over.
raheel123 0:0e26bf847b57 43 unsigned int mTriggers;
raheel123 0:0e26bf847b57 44 //mTriggers = 0;
raheel123 0:0e26bf847b57 45 };
raheel123 0:0e26bf847b57 46
raheel123 0:0e26bf847b57 47 static ExtendedClock _GlobalClock;
raheel123 0:0e26bf847b57 48
raheel123 0:0e26bf847b57 49 // Return the number of seconds since boot.
raheel123 0:0e26bf847b57 50 float clock_s()
raheel123 0:0e26bf847b57 51 {
raheel123 0:0e26bf847b57 52 return _GlobalClock.read();
raheel123 0:0e26bf847b57 53 }
raheel123 0:0e26bf847b57 54
raheel123 0:0e26bf847b57 55 // Return the number of milliseconds since boot.
raheel123 0:0e26bf847b57 56 uint64_t clock_ms()
raheel123 0:0e26bf847b57 57 {
raheel123 0:0e26bf847b57 58 return _GlobalClock.read_ms();
raheel123 0:0e26bf847b57 59 }
raheel123 0:0e26bf847b57 60
raheel123 0:0e26bf847b57 61 // Return the number of microseconds since boot.
raheel123 0:0e26bf847b57 62 uint64_t clock_us()
raheel123 0:0e26bf847b57 63 {
raheel123 0:0e26bf847b57 64 return _GlobalClock.read_us();
raheel123 0:0e26bf847b57 65 }
raheel123 0:0e26bf847b57 66