jkjkjkjk

Dependencies:   mbed-rtos mbed

Fork of all_combined_week6 by green rosh

Files at this revision

API Documentation at this revision

Comitter:
viswachaitanya
Date:
Thu Jul 17 11:22:41 2014 +0000
Parent:
6:82153349cc9b
Commit message:
i2c test slave

Changed in this revision

ACS.cpp Show diff for this revision Revisions of this file
ACS.h Show diff for this revision Revisions of this file
HK.cpp Show diff for this revision Revisions of this file
HK.h Show diff for this revision Revisions of this file
beacon.cpp Show diff for this revision Revisions of this file
beacon.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
slave.cpp Show annotated file Show diff for this revision Revisions of this file
slave.h Show annotated file Show diff for this revision Revisions of this file
--- a/ACS.cpp	Tue Jul 15 10:04:38 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-#include "ACS.h"
-
-
-PwmOut PWM1(p6);        //Functions used to generate PWM signal 
-                        //PWM output comes from pins p6
-Serial pc1(USBTX, USBRX);
-
-
-void FUNC_ACS_GENPWM()
- {
-     printf("\nEnterd PWMGEN function\n");
-     double DCx = 0;         //Duty cycle of Moment in x, y, z directions
-     double ix = 0;          //Current sent in x, y, z TR's
-     float timep = 0.02 ;  
-     double Mx=1.5;            //Time period is set to 0.2s  
-                             //Moment in x, y, z directions
-      
-     
-        ix = Mx * 0.3 ;      //Moment and Current always have the linear relationship
-     
-        if( ix>0&& ix < 0.006 )                     //Current and Duty cycle have the linear relationship between 1% and 100%
-         {
-             DCx =  6*1000000*pow(ix,4) - 377291*pow(ix,3) + 4689.6*pow(ix,2) + 149.19*ix - 0.0008;
-             PWM1.period(timep);
-             PWM1 = DCx/100 ;
-         }
-        else if( ix >= 0.006&& ix < 0.0116)
-         { 
-            DCx = 1*100000000*pow(ix,4) - 5*1000000*pow(ix,3) + 62603*pow(ix,2) - 199.29*ix + 0.7648;
-            PWM1.period(timep);
-            PWM1 = DCx/100 ;             
-         }
-        else if (ix >= 0.0116&& ix < 0.0624)
-         {
-              
-            DCx = 212444*pow(ix,4) - 33244*pow(ix,3) + 1778.4*pow(ix,2) + 120.91*ix + 0.3878;
-            PWM1.period(timep);
-            PWM1 = DCx/100 ;            
-         }
-        else if(ix >= 0.0624&& ix < 0.555)
-         {
-            printf("\nACS entered if\n");
-            DCx =  331.15*pow(ix,4) - 368.09*pow(ix,3) + 140.43*pow(ix,2) + 158.59*ix + 0.0338;
-            PWM1.period(timep);
-            PWM1 = DCx/100 ;            
-         }
-         else if(ix==0)
-         {
-             DCx = 0;
-            PWM1.period(timep);
-            PWM1 = DCx/100 ;            
-         }
-         else
-         {
-            // pc.printf("!!!!!!!!!!Error!!!!!!!!!");
-         } 
-              
-    
-printf("\nExited PWMGEN function\n");
-}
-          
\ No newline at end of file
--- a/ACS.h	Tue Jul 15 10:04:38 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-#include "mbed.h"
-
-void  FUNC_ACS_GENPWM(void);
\ No newline at end of file
--- a/HK.cpp	Tue Jul 15 10:04:38 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-#include "HK.h"
- 
-DigitalOut SelectLine3 (p24); // MSB of Select Lines
-DigitalOut SelectLine2 (p23);
-DigitalOut SelectLine1 (p22);
-DigitalOut SelectLine0 (p21); // LSB of Select Lines
- 
-AnalogIn CurrentInput(p15); // Input from Current Multiplexer
-AnalogIn VoltageInput(p16); // Input from Voltage Multiplexer
-AnalogIn TemperatureInput(p17); // input from Temperature Multiplexer
-
-SensorData Sensor; 
-int quantiz(float start,float step,float x)
-{
-    int y=(x-start)/step;
-    if(y<=0)y=0;
-    if(y>=15)y=15;
-    return y;
-}
- 
-void init_beacon(ShortBeacy x){
-    x.Voltage[0]=1;
-    x.AngularSpeed[0]=2;
-    x.AngularSpeed[1]=3;
-    x.SubsystemStatus[0]=145;
-    x.Temp[0]=1;
-    x.Temp[1]=2;
-    x.Temp[2]=3;
-    x.ErrorFlag[0]=3;
-}
- 
-ShortBeacy Shortbeacon; 
-void FUNC_HK_MAIN()
-{
-    printf("\nEntered function  HK MAIN\n");
-    
-    init_beacon(Shortbeacon);
-    
-    int LoopIterator;
- 
-    SelectLine0=0;
-    SelectLine1=0;
-    SelectLine2=0;
-    SelectLine3=0;
- 
-    for(LoopIterator=0; LoopIterator<16; LoopIterator++) {
-        
-        if(LoopIterator%2==0) {
-            Sensor.Current[LoopIterator/2]=quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens)));
-            Sensor.Voltage[LoopIterator/2]=quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37));
-            Sensor.Temperature[LoopIterator/2]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
-        } else {
-            Sensor.Current[(LoopIterator-1)/2]=(Sensor.Current[(LoopIterator-1)/2]<<4)+quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens)));
-            Sensor.Voltage[(LoopIterator-1)/2]=(Sensor.Voltage[(LoopIterator-1)/2]<<4)+quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37));
-            Sensor.Temperature[(LoopIterator-1)/2]=(Sensor.Temperature[(LoopIterator-1)/2]<<4)+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
-        }
-// The following lines are used to iterate the select lines from 0 to 15
-        SelectLine0=!(SelectLine0);
- 
-        if(LoopIterator%2==1)
-            SelectLine1=!(SelectLine1);
- 
-        if(LoopIterator%4==3)
-            SelectLine2=!(SelectLine2);
- 
-        if(LoopIterator%8==7)
-            SelectLine3=!(SelectLine3);
-        
-        wait_us(10.0); //  A delay of 10 microseconds between each sensor output. Can be changed.
- 
-    }
-   for(int i=0;i<8;i++)
-   {
-       printf("\nVoltage %d is %u\n",i,Sensor.Voltage[i]);
-       printf("\nCurrent %d is %u\n",i,Sensor.Current[i]);
-       printf("\nTemperature %d is %u\n",i,Sensor.Temperature[i]);
-    }
-        
- printf("\nExited function HK MAIN\n");
-}
\ No newline at end of file
--- a/HK.h	Tue Jul 15 10:04:38 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-#include "mbed.h"
-#define tstart -40
-#define tstep 8
-#define vstart 3.3
-#define vstep 0.84667
-#define cstart 0.0691
-#define cstep 0.09133
-#define rsens 0.095
- 
-
- 
-struct SensorData {
-    char Voltage[10];
-    char Current[10];
-    char Temperature[10];
-    //float Battery[2];
-};
- 
-typedef struct ShortBeacon {
-    char Voltage[1];
-    char AngularSpeed[2];
-    char SubsystemStatus[1]; 
-    char Temp[3];  
-    char ErrorFlag[1];
-}ShortBeacy;
-
- 
-void FUNC_HK_MAIN();
- 
-int quantiz(float start,float step,float x);
-            
-
--- a/beacon.cpp	Tue Jul 15 10:04:38 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,200 +0,0 @@
-//switch off the sync!!!!!!!
-//switch off the preamble!!!!!!!
-/*for crc in tx:
-regIrq2(0x28) :
-
-regpacketconfig 1(0x37) :
-set crc detection/calc. on : | 0x10
-crcautoclearoff : | 0x08  
-
-for data whitening : regpacketconfig 1(0x37) :| 0x40
-for 
-
-
-
-*/
-// 6CC000 for 435 MHz
-//set all values as FF for checking on spectrum analyzer
-#include "beacon.h"
-#include "HK.h"
-Serial chavan(USBTX, USBRX);           // tx, rx
-SPI spi(p11, p12, p13);               // mosi, miso, sclk
-DigitalOut cs_bar(p8);                 //slave select or chip select
-//InterruptIn button(p9);
-//#define TIMES 16      
-//Timer t;
-
-/*void interrupt_func()
-{
-    chavan.printf("INTERRUPT_FUNC TRIGGERED\n  wait for 3 secs\n"); 
-    wait(3);
-    
-}*/
-
-extern ShortBeacy Shortbeacon;
-void writereg(uint8_t reg,uint8_t val)
-{
-    cs_bar = 0;
-    spi.write(reg | 0x80);      
-    spi.write(val);
-    cs_bar = 1;
-}
-uint8_t readreg(uint8_t reg)
-{
-    uint8_t val;
-    cs_bar = 0;
-    spi.write(reg & ~0x80);        
-    val = spi.write(0);
-    cs_bar = 1;
-    return val;
-}
-        
-void beacon_func() {
-    
-    //button.rise(&interrupt_func);         //interrupt enabled ( rising edge of pin 9)
-    printf("\nBeacon function entered\n");
-    wait(0.02);                             //takes 10 ms for POR event + 10ms for safety                 
-    
-    uint8_t byte_counter = 0;
-    
-    /*struct Short_beacon{
-        uint8_t Voltage[1];
-        uint8_t AngularSpeed[2];
-        uint8_t SubsystemStatus[1];
-        uint8_t Temp[3];
-        uint8_t ErrorFlag[1];
-        }Shortbeacon = { {0x22}, {0x22, 0x33} , {0x00},{0x00,0x00,0x00}, {0xFE} };
-    */
-    //filling hk data
-    //ShortBeacon Shortbeacon;
-    uint8_t short_beacon[] = { 0xAB, 0x8A, 0xE2, 0xBB, 0xB8, 0xA2, 0x8E,Shortbeacon.Voltage[0],Shortbeacon.AngularSpeed[0], Shortbeacon.AngularSpeed[1],Shortbeacon.SubsystemStatus[0],Shortbeacon.Temp[0],Shortbeacon.Temp[1],Shortbeacon.Temp[2],Shortbeacon.ErrorFlag[0]};
-    
-    //mask
-    //uint8_t mask[] = {0x80, 0x40, 0x20,0x10,0x8,0x4,0x2,0x1};
-        
-   /* for(int i = 0; i < 15 ; i++)
-    {
-        chavan.printf("0x%X\n",(short_beacon[i]));    
-    }*/
-    
-    spi.format(8,0);                    
-    spi.frequency(10000000);             //10MHz SCLK frequency(its max for rfm69hcw)
-    cs_bar = 1;                              // Chip must be deselected
-    
-    //initialization
-    //Common configuration registers
-    writereg(0x01,0x04);       //sequencer on,standby mode
-    writereg(0x02,0x08);       //packet-mode used  , ook modultion , no dc-shaping
-    writereg(0x03,0x68);       //1200bps datarate
-    writereg(0x04,0x2B);       //1200bps datarate
-    writereg(0x07,0x6C);       //Frequency MSB
-    writereg(0x08,0xC0);       //Frequency MID
-    writereg(0x09,0x00);       //Frequency LSB        ....6C C0 00 for 435 MHZ   
-    
-    //Transmitter registers
-    // RegPaLevel(default +13 dBm)
-    
-    //IRQ and Pin Mapping Registers
-    //no DIO mapped yet
-    //regirq1(0x27): modeready (8th bit) will be checked for interrupts
-    //regIrq2(0x28): fifothresh (5th bit) ,packetsent(3rd bit) will be checked for interrupts
-    
-    //Packet Engine Registers
-    writereg(0x2C,0x00);        //set preamble
-    writereg(0x2D,0x0A);        //set preamble
-    writereg(0x2E,0x80);        //sync off        
-    writereg(0x2F,0x5E);        //sync word 1               
-    writereg(0x37,0x08 | 0x40);// | 0x10);        //packetconfig1, 0x40 for data whitening (only for testing)                
-    writereg(0x38,0x00);        //payload length = 0 ... unlimited payload mode
-    writereg(0x3C,0xB0);         //fifothresh = 48      because we want it cleared once its 40!!!!
-    //Initialization complete
-    
-    //while(chavan.getc() == 't'){
-    //t.start();  
-    //Filling Data into FIFO 64 BYTES : eff.32 bits = 4bytes                  //fread
-    cs_bar = 0; 
-    spi.write(0x80);//fifo write access
-    for(byte_counter=0 ; byte_counter<4; byte_counter++)
-    {    
-        for(int i=7; i>=0  ; i--)
-        {
-            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!=0)
-            //if((short_beacon[byte_counter] & mask[i]) != 0)
-            {
-                spi.write(0xFF);
-                spi.write(0xFF);
-            }
-    else
-            {
-                spi.write(0x00);
-                spi.write(0x00);
-            }
-        }
-    }
-    cs_bar = 1; //cs_bar
-                
-    //Check for fifoThresh
-    printf("\nfor loop executed\n");
-    while((readreg(0x28) & 0x20) != 0x20);                         
-    printf("\nwhile loop executed\n");
-    //Highpower settings
-    writereg(0x11,0x7F);    //RegPalevel (20db)                //~
-    writereg(0x13,0x0F);    //RegOCP
-    writereg(0x5A,0x5D);    //RegTestPa1
-    writereg(0x5C,0x7C);    //RegTestPa2
-        
-    //Set to Tx mode
-    writereg(0x01,0x0C);
-    
-        printf("\npre 2nd while loop\n");
-        //Check for fifoThresh
-        while((readreg(0x28) & 0x20) != 0x00);  
-        printf("\n2nd while loop executed\n");        
-        while(byte_counter!=15){
-            
-        //writing again
-        cs_bar = 0;
-        spi.write(0x80);   
-        for(int i=7; i>=0 ;i--)
-        {
-            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!=0)
-            //if((short_beacon[byte_counter] & mask[i]) != 0)
-        {
-            spi.write(0xFF);
-            spi.write(0xFF);
-        }
-        else
-        {
-            spi.write(0x00);
-            spi.write(0x00);
-        }
-        }
-        cs_bar = 1;
-        byte_counter++;
-                       
-        //Check for fifoThresh
-        while((readreg(0x28) & 0x20) != 0x00);
-    }
-    printf("\n3rd big while loop executed\n");
-    //wait for packet sent bit to fire
-    while((readreg(0x28) & 0x08) != 0x08);
-    printf("\n4th while loop executed\n");
-    //chavan.printf("packet sent!!! \n");    
-    
-    //Switch back to Standby Mode
-    writereg(0x01,0x04);
-    
-    //Lowpowermode
-    writereg(0x11,0x9F);    //RegPalevel (13db)
-    writereg(0x13,0x1A);    //RegOCP
-    writereg(0x5A,0x55);    //RegTestPa1(setting PA_BOOST on RFIO)
-    writereg(0x5C,0x70);    //RegTestPa2(setting PA_BOOST on RFIO)
-    
-    //wait for modeready
-    while((readreg(0x27)&0x80)!=0x80);
-    
-    //t.stop();
-    //chavan.printf(" time taken to init + transmit = %f \n", t.read()) ;
-    //}
-printf("\nBeacon function exiting\n");
-}
--- a/beacon.h	Tue Jul 15 10:04:38 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#include "mbed.h"
-
-void writereg(uint8_t reg,uint8_t val);
-uint8_t readreg(uint8_t reg);
-void beacon_func();
-/*struct ShortBeacon {
-    char Voltage[1];
-    char AngularSpeed[2];
-    char SubsystemStatus[1]; 
-    char Temp[3];  
-    char ErrorFlag[1];
-}
-Shortbeacon = {{0x22}, {0x22, 0x33} , {0x00},{0x00,0x00,0x00}, {0x01}};*/
\ No newline at end of file
--- a/main.cpp	Tue Jul 15 10:04:38 2014 +0000
+++ b/main.cpp	Thu Jul 17 11:22:41 2014 +0000
@@ -1,328 +1,14 @@
 #include "mbed.h"
-#include "rtos.h"
-#include "HK.h"
 #include "slave.h"
-#include "beacon.h"
-#include "ACS.h"
-//watda?
-Serial pc(USBTX, USBRX);
-
-
-
-Timer t;
-Timer t1;
-
-Thread *ptr_t_hk_acq;
-Thread *ptr_t_acs;
-Thread *ptr_t_acs_write2flash;
-Thread *ptr_t_bea;
-Thread *ptr_t_bea_telecommand;
-Thread *ptr_t_fault;
-
-
-//----------------------------------------------HOUSE-KEEPING(HK)------------------------------------------------------------------------------------------
-//void func_hk_mux()
-//{
-//    pc.printf("Something related to mux\n");
-//}
-//
-//void func_hk_adc()
-//{
-//    pc.printf("Converting analog to digital\n");
-//}
-//
-//void func_hk_write2flash()
-//{
-//    pc.printf("Writing the house keeping data to flash\n");
-//}
-//
-//void func_hk_readram()
-//{
-//    pc.printf("Reading hk data from ram\n");
-//}
-
-//void func_hk_send2cdms()
-//{
-//    pc.printf("Send the data to sd card\n");
-//}
-
-void t_hk_send2cdms(void const *args)
-{
-    while(1)
-    {
-        t.start();
-        Thread::signal_wait(0x4);
-        printf("\nEntered t_hk_send2cdms\n");
-        /*printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
-        printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
-        printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
-        printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());*/
-             
-        //FUNC_I2C_SLAVE_MAIN(24);
-        printf("The time to execute send2cdms is %f\n",t.read());
-        t.reset();
-    }
-}
-
-void t_hk_acq(void const *args)
-{
-    Thread thread_2(t_hk_send2cdms);
-    while(1)
-    {
-        Thread::signal_wait(0x2);
-        
-        printf("\nTHIS IS HK    %f\n",t1.read());
-        t.start();
-        
-        FUNC_HK_MAIN();
-        //thread_2.signal_set(0x4);
-        FUNC_I2C_SLAVE_MAIN(24);
-        /*printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
-        printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
-        printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
-        printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());*/
-        t.stop();
-        printf("The time to execute hk_acq is %f seconds\n",t.read());
-        t.reset();
-    }
-}
-
-//---------------------------------------------------------------------------------------------------------------------------------------
-
-typedef struct {
-    float mag_field;
-    float omega;
-    } sensor_data;
-    
-Mail <sensor_data, 16> q_acs;
-    
-void func_acs_readdata(sensor_data *ptr)
-{
-    pc.printf("Reading the data\n");
-    ptr -> mag_field = 10;
-    ptr -> omega = 3;
-}
-
-void func_acs_ctrlalgo()
-{
-    pc.printf("Executing control algo\n");
-}
-
-/*void func_acs_pwmgen()
-{
-    pc.printf("Generating PWM signal\n");
-}*/
-
-void func_acs_write2flash(sensor_data *ptr2)
-{
-    pc.printf("The magnetic field is %.2f T\n\r",ptr2->mag_field);
-    pc.printf("The angular velocity is %.2f rad/s\n\r",ptr2->omega);
-}
 
-void t_acs(void const *args)
-{
-    while(1)
-    {
-        Thread::signal_wait(0x1);
-        printf("\nTHIS IS ACS   %f\n",t1.read());
-        t.start();
-        sensor_data *ptr = q_acs.alloc();
-        func_acs_readdata(ptr);
-        q_acs.put(ptr);
-        func_acs_ctrlalgo();
-        FUNC_ACS_GENPWM();
-        
-        /*printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
-        printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
-        printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
-        printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());
-        printf("The time to execute t_acs is %f seconds\n",t.read());*/
-            //   Thread::wait(10000);
-        t.reset();
-    }
-}
-
-void t_acs_write2flash(void const *args)
-{
-    while(1)
-    {
-        //printf("Writing in the flash\n");
-        osEvent evt = q_acs.get();
-        if(evt.status == osEventMail)
-        {
-            sensor_data *ptr = (sensor_data*)evt.value.p;
-            func_acs_write2flash(ptr);
-            q_acs.free(ptr);
-        }
-        printf("Writing acsd data in the flash\n");
-    }
-}
-
-//---------------------------------------------------BEACON--------------------------------------------------------------------------------------------
-
-int beac_flag=0;
-
-/*void func_bea_readbaeflash()
-{
-        pc.printf("Reading data from beacon flash\n");
-        wait(0.01);
-}
-
-void func_bea_spiwrite()
-{
-    pc.printf("Writing through SPI\n");
-    wait(0.01);
-}
-*/
-void t_bea_telecommand(void const *args)
-{
-    char c = pc.getc();
-    if(c=='a')
-    {
-        pc.printf("Telecommand detected\n");
-        beac_flag=1;
-    }
-}
-
-void t_bea(void const *args)
-{
-    
-    while(1)
-    {
-        Thread::signal_wait(0x3);
-        printf("\nTHIS IS BEACON    %f\n",t1.read());
-        t.start();
-        /*printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
-        printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
-        printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
-        printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());*/
-        if(beac_flag==0)
-        {
-            //func_bea_readbaeflash();
-            //func_bea_spiwrite();
-            beacon_func();
-            //Thread::wait(30000);
-        }
-        else
-        {
-            Thread::wait(600000);
-            beac_flag = 0;
-        }
-        
-        printf("The time to execute beacon thread is %f seconds\n",t.read());
-        t.reset();
-    }
-}
-
-//---------------------------------------------------------------------------------------------------------------------------------------------------
-//TASK 4 : FAULT MANAGEMENT
-//---------------------------------------------------------------------------------------------------------------------------------------------------
-//Dummy fault rectifier functions
-
-Mail<int,16> faults;
-
-void FUNC_FAULT_FUNCT1()
-{
-    pc.printf("\nFault 1 detected... \n");
-}
-
-void FUNC_FAULT_FUNCT2()
-{
-    pc.printf("\nFault 2 detected...\n");
-}
-
-void T_FAULT(void const *args)
-{
-    while(1)
-    {
-        osEvent evt = faults.get();
-        if(evt.status==osEventMail)
-        {
-            int *fault_id= (int *)evt.value.p;
-            switch(*fault_id)
-            {
-                case 1: FUNC_FAULT_FUNCT1();
-                        break;
-                case 2: FUNC_FAULT_FUNCT2();
-                        break;
-            }
-            faults.free(fault_id);
-        }
-    }
-}
-
-//------------------------------------------------------------------------------------------------------------------------------------------------
-//SCHEDULER
-//------------------------------------------------------------------------------------------------------------------------------------------------
-uint16_t schedcount=1;
-void t_sc(void const *args)
-{
-    
-    printf("The value of i in scheduler is %d\n",schedcount);
-    if(schedcount == 65532)                         //to reset the counter
-    {
-        schedcount = 0;
-    }
-    
-    if(schedcount%1==0)
-    {
-        ptr_t_acs -> signal_set(0x1);
-    }
-    if(schedcount%2==0)
-    {
-        ptr_t_hk_acq -> signal_set(0x2);
-    }
-    if(schedcount%3==0)
-    {
-        ptr_t_bea -> signal_set(0x3);
-    }
-    schedcount++;
-}
-    
-//---------------------------------------------------------------------------------------------------------------------------------------------
 
 int main()
 {
-    t1.start();
     
-    ptr_t_hk_acq = new Thread(t_hk_acq);
-    ptr_t_acs = new Thread(t_acs);
-    ptr_t_acs_write2flash = new Thread(t_acs_write2flash);
-    ptr_t_bea = new Thread(t_bea);
-    ptr_t_bea_telecommand = new Thread(t_bea_telecommand);
-    ptr_t_fault = new Thread(T_FAULT);
-    //ptr_t_sc = new Thread(t_sc);
-
-    ptr_t_fault -> set_priority(osPriorityRealtime);
-    ptr_t_acs->set_priority(osPriorityHigh);
-    ptr_t_hk_acq->set_priority(osPriorityNormal);
-    ptr_t_acs_write2flash->set_priority(osPriorityBelowNormal);
-    ptr_t_bea->set_priority(osPriorityAboveNormal);
-    ptr_t_bea_telecommand->set_priority(osPriorityIdle);
-    //ptr_t_sc->set_priority(osPriorityAboveNormal);
-    
-    /*RtosTimer for individual thread-------------------------------------------------------------------------------------------
-    RtosTimer t_hk_acq_timer(t_hk_acq, osTimerPeriodic);
-    RtosTimer t_acs_timer(t_acs, osTimerPeriodic);    
-    RtosTimer t_bea_timer(t_bea, osTimerPeriodic);
-    
-    t_hk_acq_timer.start(20000);
-    t_acs_timer.start(10000);
-    t_bea_timer.start(30000);
-    ----------------------------------------------------------------------------------------------*/    
-    pc.printf("\n T_FAULT priority is %d",ptr_t_fault->get_priority()); 
-    pc.printf("\n T_ACS priority is %d",ptr_t_acs->get_priority());
-    pc.printf("\n T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority());
-    pc.printf("\n T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority());
-    pc.printf("\n T_BEA priority is %d",ptr_t_bea->get_priority());  
-    RtosTimer t_sc_timer(t_sc,osTimerPeriodic);
-    t_sc_timer.start(10000);
-    printf("\n%f\n",t1.read()); 
-        
-    while(1)
+    while(true)
     {
-        Thread::wait(10000);
-        ;
+        wait(0.5);
+        FUNC_I2C_SLAVE_MAIN(24);
+        wait(10);
     }
-    
-}
\ No newline at end of file
+}    
\ No newline at end of file
--- a/slave.cpp	Tue Jul 15 10:04:38 2014 +0000
+++ b/slave.cpp	Thu Jul 17 11:22:41 2014 +0000
@@ -1,13 +1,14 @@
 #include "slave.h"
-#include "HK.h"
- 
-extern struct SensorData Sensor;
+
+ int acknowledge; 
+           int loopvariable4;
+SensorData Sensor; 
 I2CSlave slave(p28,p27);                       //configuring pins p27, p28 as I2Cslave
 Serial screen (USBTX,USBRX);
 void write_to_master(char send)                           //function to write data to master
         {
-           int acknowledge; 
-           int loopvariable4=1;
+            
+           loopvariable4=1;
            while(loopvariable4)
            {
            acknowledge = slave.write(send);    //sending the byte to master
@@ -24,10 +25,21 @@
  
 void FUNC_I2C_SLAVE_MAIN(int iterations)
 {
+    slave.address(slave_address);                           //assigning slave address
+    char Switch_Variable;
+    slave.stop();
+    Sensor.voltage[0]='a';Sensor.current[0]='1';Sensor.temp[0]='k';
+    Sensor.voltage[1]='b';Sensor.current[1]='2';Sensor.temp[1]='l';
+    Sensor.voltage[2]='c';Sensor.current[2]='3';Sensor.temp[2]='m';
+    Sensor.voltage[3]='d';Sensor.current[3]='4';Sensor.temp[3]='n';
+    Sensor.voltage[4]='e';Sensor.current[4]='5';Sensor.temp[4]='o';
+    Sensor.voltage[5]='f';Sensor.current[5]='1';Sensor.temp[5]='p';
+    Sensor.voltage[6]='g';Sensor.current[6]='2';Sensor.temp[6]='q';
+    Sensor.voltage[7]='h';Sensor.current[7]='3';Sensor.temp[7]='r';
     
     screen.printf("\nSlave entered\n");
-    slave.address(slave_address);                           //assigning slave address
-    char Switch_Variable;
+    
+    
     
     
     int loopvariable1=1;
@@ -59,17 +71,17 @@
                       if(loopvariable2%3==0)
                           {
                           screen.printf("\nvoltage%d\n",loopvariable2/3);
-                          write_to_master(Sensor.Voltage[loopvariable2/3]);
+                          write_to_master(Sensor.voltage[loopvariable2/3]);
                           }
                       else if(loopvariable2%3==1)
                           {   
                           screen.printf("\ncurrent%d\n",loopvariable2/3);
-                          write_to_master(Sensor.Current[loopvariable2/3]);
+                          write_to_master(Sensor.current[loopvariable2/3]);
                           }
                       else if(loopvariable2%3==2)
                           {   
                           screen.printf("\ntemp%d\n",loopvariable2/3);
-                          write_to_master(Sensor.Temperature[loopvariable2/3]);
+                          write_to_master(Sensor.temp[loopvariable2/3]);
                           }         
                       loopvariable2++;
                        }//while(loopvariable2<30)
@@ -87,6 +99,7 @@
         }//switch case ends
    }   
 }
+
    screen.printf("\nexited slave function\n");
 }
  
\ No newline at end of file
--- a/slave.h	Tue Jul 15 10:04:38 2014 +0000
+++ b/slave.h	Thu Jul 17 11:22:41 2014 +0000
@@ -3,4 +3,10 @@
 #define ReadAddressed 1
 #define slave_address 0x20
 void write_to_master(char);                    //function to write data to master
-void FUNC_I2C_SLAVE_MAIN(int iterations);
\ No newline at end of file
+void FUNC_I2C_SLAVE_MAIN(int iterations);
+struct SensorData {
+    char voltage[10];
+    char current[10];
+    char temp[10];
+    //float Battery[2];
+};