Eurobot system lib
system.h@0:b35c6c9aad45, 2012-04-26 (annotated)
- Committer:
- narshu
- Date:
- Thu Apr 26 19:40:58 2012 +0000
- Revision:
- 0:b35c6c9aad45
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
narshu | 0:b35c6c9aad45 | 1 | |
narshu | 0:b35c6c9aad45 | 2 | #ifndef SYSTEM_H |
narshu | 0:b35c6c9aad45 | 3 | #define SYSTEM_H |
narshu | 0:b35c6c9aad45 | 4 | |
narshu | 0:b35c6c9aad45 | 5 | #include "globals.h" |
narshu | 0:b35c6c9aad45 | 6 | #include "rtos.h" |
narshu | 0:b35c6c9aad45 | 7 | |
narshu | 0:b35c6c9aad45 | 8 | //Declaring the onboard LED's for everyone to use |
narshu | 0:b35c6c9aad45 | 9 | extern DigitalOut OLED1;//(LED1); |
narshu | 0:b35c6c9aad45 | 10 | extern DigitalOut OLED2;//(LED2); |
narshu | 0:b35c6c9aad45 | 11 | extern DigitalOut OLED3;//(LED3); |
narshu | 0:b35c6c9aad45 | 12 | extern DigitalOut OLED4;//(LED4); |
narshu | 0:b35c6c9aad45 | 13 | |
narshu | 0:b35c6c9aad45 | 14 | //a type which is a pointer to a rtos thread function |
narshu | 0:b35c6c9aad45 | 15 | typedef void (*tfuncptr_t)(void const *argument); |
narshu | 0:b35c6c9aad45 | 16 | |
narshu | 0:b35c6c9aad45 | 17 | //--------------------- |
narshu | 0:b35c6c9aad45 | 18 | //Signal ticker stuff |
narshu | 0:b35c6c9aad45 | 19 | #define SIGTICKARGS(thread, signal) \ |
narshu | 0:b35c6c9aad45 | 20 | (tfuncptr_t) (&Signalsetter::callback), osTimerPeriodic, (void*)(new Signalsetter(thread, signal)) |
narshu | 0:b35c6c9aad45 | 21 | |
narshu | 0:b35c6c9aad45 | 22 | class Signalsetter { |
narshu | 0:b35c6c9aad45 | 23 | public: |
narshu | 0:b35c6c9aad45 | 24 | Signalsetter(Thread& inthread, int insignal) : |
narshu | 0:b35c6c9aad45 | 25 | thread(inthread) { |
narshu | 0:b35c6c9aad45 | 26 | signal = insignal; |
narshu | 0:b35c6c9aad45 | 27 | //pc.printf("ptr saved as %#x \r\n", (int)(&(inthread))); |
narshu | 0:b35c6c9aad45 | 28 | } |
narshu | 0:b35c6c9aad45 | 29 | |
narshu | 0:b35c6c9aad45 | 30 | static void callback(void* thisin) { |
narshu | 0:b35c6c9aad45 | 31 | |
narshu | 0:b35c6c9aad45 | 32 | Signalsetter* fthis = (Signalsetter*)thisin; |
narshu | 0:b35c6c9aad45 | 33 | //pc.printf("callback will signal thread object at %#x \r\n", (int)(&(fthis->thread))); |
narshu | 0:b35c6c9aad45 | 34 | fthis->thread.signal_set(fthis->signal); |
narshu | 0:b35c6c9aad45 | 35 | //delete fthis; //this is useful for single fire tickers! |
narshu | 0:b35c6c9aad45 | 36 | } |
narshu | 0:b35c6c9aad45 | 37 | |
narshu | 0:b35c6c9aad45 | 38 | private: |
narshu | 0:b35c6c9aad45 | 39 | Thread& thread; |
narshu | 0:b35c6c9aad45 | 40 | int signal; |
narshu | 0:b35c6c9aad45 | 41 | }; |
narshu | 0:b35c6c9aad45 | 42 | |
narshu | 0:b35c6c9aad45 | 43 | //--------------------- |
narshu | 0:b35c6c9aad45 | 44 | //cpu usage measurement function |
narshu | 0:b35c6c9aad45 | 45 | extern float cpupercent; |
narshu | 0:b35c6c9aad45 | 46 | void measureCPUidle (void const* arg); |
narshu | 0:b35c6c9aad45 | 47 | |
narshu | 0:b35c6c9aad45 | 48 | #endif |