for checking i2c with integrated bae

Dependencies:   SDFileSystem mbed-rtos mbed

Committer:
viswa_chaitanya
Date:
Mon Sep 15 14:01:49 2014 +0000
Revision:
0:cb112a717428
cdms master(hk runs every 20s)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
viswa_chaitanya 0:cb112a717428 1 #include "mbed.h"
viswa_chaitanya 0:cb112a717428 2 #include "rtos.h"
viswa_chaitanya 0:cb112a717428 3 #include "master.h"
viswa_chaitanya 0:cb112a717428 4
viswa_chaitanya 0:cb112a717428 5 //#include "tmtc.h"
viswa_chaitanya 0:cb112a717428 6 //#include "science.h"
viswa_chaitanya 0:cb112a717428 7 //#include "hk.h"
viswa_chaitanya 0:cb112a717428 8
viswa_chaitanya 0:cb112a717428 9 #define intmax 11999
viswa_chaitanya 0:cb112a717428 10
viswa_chaitanya 0:cb112a717428 11 Thread* t_tmtc;
viswa_chaitanya 0:cb112a717428 12 Thread* t_science_store_sd;
viswa_chaitanya 0:cb112a717428 13 Thread* t_hk_store_sd;
viswa_chaitanya 0:cb112a717428 14
viswa_chaitanya 0:cb112a717428 15 void t_tmtc_main(void const *args);
viswa_chaitanya 0:cb112a717428 16 void t_science_main(void const *args);
viswa_chaitanya 0:cb112a717428 17 void t_hk_main(void const *args);
viswa_chaitanya 0:cb112a717428 18 void scheduler(void const * args);
viswa_chaitanya 0:cb112a717428 19
viswa_chaitanya 0:cb112a717428 20 Timer timer_main;
viswa_chaitanya 0:cb112a717428 21 int schedcount = 1;
viswa_chaitanya 0:cb112a717428 22 Mutex critical;
viswa_chaitanya 0:cb112a717428 23
viswa_chaitanya 0:cb112a717428 24 int main() {
viswa_chaitanya 0:cb112a717428 25 Thread thread_tmtc(t_tmtc_main, NULL, osPriorityIdle);
viswa_chaitanya 0:cb112a717428 26 t_tmtc = &thread_tmtc;
viswa_chaitanya 0:cb112a717428 27 Thread thread_science(t_science_main, NULL, osPriorityLow);
viswa_chaitanya 0:cb112a717428 28 t_science_store_sd = &thread_science;
viswa_chaitanya 0:cb112a717428 29 Thread thread_hk(t_hk_main, NULL, osPriorityBelowNormal);
viswa_chaitanya 0:cb112a717428 30 t_hk_store_sd = &thread_hk;
viswa_chaitanya 0:cb112a717428 31
viswa_chaitanya 0:cb112a717428 32 RtosTimer schedule(scheduler,osTimerPeriodic);
viswa_chaitanya 0:cb112a717428 33 timer_main.start();
viswa_chaitanya 0:cb112a717428 34 schedule.start(5000);
viswa_chaitanya 0:cb112a717428 35 Thread::wait(osWaitForever);
viswa_chaitanya 0:cb112a717428 36 }
viswa_chaitanya 0:cb112a717428 37
viswa_chaitanya 0:cb112a717428 38 void scheduler(void const * args)
viswa_chaitanya 0:cb112a717428 39 {
viswa_chaitanya 0:cb112a717428 40 if(schedcount == intmax+1) //the value is reset at this value so as to ensure smooth flow, 65532 and 0 are divisible by 3 and 2.
viswa_chaitanya 0:cb112a717428 41 {
viswa_chaitanya 0:cb112a717428 42 schedcount =0;
viswa_chaitanya 0:cb112a717428 43 }
viswa_chaitanya 0:cb112a717428 44
viswa_chaitanya 0:cb112a717428 45 if(schedcount%4==0)
viswa_chaitanya 0:cb112a717428 46 {
viswa_chaitanya 0:cb112a717428 47 printf("\nHK signal at %f\n",timer_main.read());
viswa_chaitanya 0:cb112a717428 48 t_hk_store_sd->signal_set(0x01);
viswa_chaitanya 0:cb112a717428 49 }
viswa_chaitanya 0:cb112a717428 50
viswa_chaitanya 0:cb112a717428 51 if(schedcount%3==0)
viswa_chaitanya 0:cb112a717428 52 {
viswa_chaitanya 0:cb112a717428 53 printf("\nScience signal at %f\n",timer_main.read());
viswa_chaitanya 0:cb112a717428 54 t_science_store_sd->signal_set(0x01);
viswa_chaitanya 0:cb112a717428 55 }
viswa_chaitanya 0:cb112a717428 56
viswa_chaitanya 0:cb112a717428 57 if(schedcount==5)
viswa_chaitanya 0:cb112a717428 58 {
viswa_chaitanya 0:cb112a717428 59 printf("\nTMTC signalled");
viswa_chaitanya 0:cb112a717428 60 t_tmtc->signal_set(0x1);
viswa_chaitanya 0:cb112a717428 61 }
viswa_chaitanya 0:cb112a717428 62
viswa_chaitanya 0:cb112a717428 63 schedcount++;
viswa_chaitanya 0:cb112a717428 64 }
viswa_chaitanya 0:cb112a717428 65
viswa_chaitanya 0:cb112a717428 66 void t_science_main(void const *args) {
viswa_chaitanya 0:cb112a717428 67 while (true) {
viswa_chaitanya 0:cb112a717428 68 Thread::signal_wait(0x1);
viswa_chaitanya 0:cb112a717428 69 critical.lock();
viswa_chaitanya 0:cb112a717428 70 printf("science data aquisition started\n");
viswa_chaitanya 0:cb112a717428 71 wait(3);
viswa_chaitanya 0:cb112a717428 72 printf("science data acquisition ended\n");
viswa_chaitanya 0:cb112a717428 73 t_hk_store_sd->signal_set(0x10);
viswa_chaitanya 0:cb112a717428 74 critical.unlock();
viswa_chaitanya 0:cb112a717428 75 wait(3);
viswa_chaitanya 0:cb112a717428 76 printf("Science data written to SD card\n");
viswa_chaitanya 0:cb112a717428 77 }
viswa_chaitanya 0:cb112a717428 78 }
viswa_chaitanya 0:cb112a717428 79
viswa_chaitanya 0:cb112a717428 80 void t_hk_main(void const *args) {
viswa_chaitanya 0:cb112a717428 81 while (true) {
viswa_chaitanya 0:cb112a717428 82 Thread::signal_wait(0x1);
viswa_chaitanya 0:cb112a717428 83 critical.lock();
viswa_chaitanya 0:cb112a717428 84 printf("HK acquisition started\n");
viswa_chaitanya 0:cb112a717428 85 //FUNC_I2C_MASTER_MAIN(1,0x20,24 );
viswa_chaitanya 0:cb112a717428 86 wait(2);
viswa_chaitanya 0:cb112a717428 87 printf("HK acquisition ended\n");
viswa_chaitanya 0:cb112a717428 88 critical.unlock();
viswa_chaitanya 0:cb112a717428 89 wait(2);
viswa_chaitanya 0:cb112a717428 90 printf("HK data written to SD card");
viswa_chaitanya 0:cb112a717428 91 }
viswa_chaitanya 0:cb112a717428 92 }
viswa_chaitanya 0:cb112a717428 93
viswa_chaitanya 0:cb112a717428 94 void t_tmtc_main(void const *args) {
viswa_chaitanya 0:cb112a717428 95 Thread::signal_wait(0x1);
viswa_chaitanya 0:cb112a717428 96 critical.lock();
viswa_chaitanya 0:cb112a717428 97 printf("tmtc started\n");
viswa_chaitanya 0:cb112a717428 98 wait(5);
viswa_chaitanya 0:cb112a717428 99 printf("tmtc ended\n");
viswa_chaitanya 0:cb112a717428 100 critical.unlock();
viswa_chaitanya 0:cb112a717428 101 wait(5);
viswa_chaitanya 0:cb112a717428 102 printf("tmtc executed\n");
viswa_chaitanya 0:cb112a717428 103 }