Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BAE_RTOS_test_1 by
main.cpp@2:f26706e0d779, 2015-10-04 (annotated)
- Committer:
- gkumar
- Date:
- Sun Oct 04 07:24:39 2015 +0000
- Revision:
- 2:f26706e0d779
- Parent:
- 1:b8c71afbe6e5
4-10-2015 BAE_RTOS_TEST2
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gkumar | 0:f417d854dc29 | 1 | #include "mbed.h" |
| gkumar | 0:f417d854dc29 | 2 | #include "rtos.h" |
| gkumar | 1:b8c71afbe6e5 | 3 | #include "pin_config.h" |
| gkumar | 1:b8c71afbe6e5 | 4 | //#include "HK.h" |
| gkumar | 1:b8c71afbe6e5 | 5 | #include "ACS.h" |
| gkumar | 1:b8c71afbe6e5 | 6 | //#include "beacon.h" |
| gkumar | 1:b8c71afbe6e5 | 7 | |
| gkumar | 0:f417d854dc29 | 8 | Serial pc(USBTX, USBRX); |
| gkumar | 1:b8c71afbe6e5 | 9 | InterruptIn irpt_4m_mstr(PIN38); //I2c interrupt from CDMS |
| gkumar | 1:b8c71afbe6e5 | 10 | DigitalOut irpt_2_mstr(PIN4); //I2C interrupt to CDMS |
| gkumar | 1:b8c71afbe6e5 | 11 | I2CSlave slave (PIN1,PIN2); |
| gkumar | 1:b8c71afbe6e5 | 12 | const int addr = 0x20; //slave address |
| gkumar | 1:b8c71afbe6e5 | 13 | Thread *ptr_t_i2c; |
| gkumar | 1:b8c71afbe6e5 | 14 | Timer t; // time taken from isr to reach i2c function |
| gkumar | 1:b8c71afbe6e5 | 15 | Timer t1; |
| gkumar | 1:b8c71afbe6e5 | 16 | Timer t_exec; //To know the time of execution each thread |
| gkumar | 1:b8c71afbe6e5 | 17 | |
| gkumar | 1:b8c71afbe6e5 | 18 | Timer t_start; //To know the time of entering of each thread |
| gkumar | 1:b8c71afbe6e5 | 19 | Timer t_i2c_start; //To check the time sync in i2c communication |
| gkumar | 1:b8c71afbe6e5 | 20 | Timer t_i2c_exec; //To know the time taken by i2c read/write function |
| gkumar | 0:f417d854dc29 | 21 | |
| gkumar | 0:f417d854dc29 | 22 | Thread *ptr_t_hk; |
| gkumar | 0:f417d854dc29 | 23 | Thread *ptr_t_acs; |
| gkumar | 0:f417d854dc29 | 24 | Thread *ptr_t_bea; |
| gkumar | 0:f417d854dc29 | 25 | |
| gkumar | 1:b8c71afbe6e5 | 26 | /**************************************************************global variables*********************************************************************************/ |
| gkumar | 1:b8c71afbe6e5 | 27 | char hk_data[25]; |
| gkumar | 1:b8c71afbe6e5 | 28 | |
| gkumar | 1:b8c71afbe6e5 | 29 | /**************************************************************funtion header**********************************************************************************/ |
| gkumar | 1:b8c71afbe6e5 | 30 | |
| gkumar | 1:b8c71afbe6e5 | 31 | void FCTN_HK_DATA_CATENATE(); |
| gkumar | 1:b8c71afbe6e5 | 32 | |
| gkumar | 1:b8c71afbe6e5 | 33 | |
| gkumar | 1:b8c71afbe6e5 | 34 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 35 | //TASK : HK |
| gkumar | 1:b8c71afbe6e5 | 36 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 37 | //extern SensorDataQuantised SensorQuantised; |
| gkumar | 0:f417d854dc29 | 38 | void T_HK(void const *args) |
| gkumar | 0:f417d854dc29 | 39 | { |
| gkumar | 0:f417d854dc29 | 40 | while(1){ |
| gkumar | 1:b8c71afbe6e5 | 41 | Thread::signal_wait(0x2); |
| gkumar | 1:b8c71afbe6e5 | 42 | //SensorQuantised.power_mode='3'; //default power mode(dummy) |
| gkumar | 1:b8c71afbe6e5 | 43 | // printf("\n\rTHIS IS HK %f\n\r",t_start.read()); |
| gkumar | 1:b8c71afbe6e5 | 44 | // t_exec.start(); |
| gkumar | 1:b8c71afbe6e5 | 45 | // FCTN_HK_MAIN(); //Collecting HK data |
| gkumar | 1:b8c71afbe6e5 | 46 | // FCTN_HK_DATA_CATENATE(); //sending HK data to CDMS |
| gkumar | 1:b8c71afbe6e5 | 47 | // t_exec.stop(); |
| gkumar | 1:b8c71afbe6e5 | 48 | // //printf("The time to execute hk_acq is %f seconds\n\r",t_exec.read()); |
| gkumar | 1:b8c71afbe6e5 | 49 | // t_exec.reset(); |
| gkumar | 1:b8c71afbe6e5 | 50 | printf("\n\rTHIS IS HK %f\n\r",t_start.read()); |
| gkumar | 0:f417d854dc29 | 51 | } |
| gkumar | 0:f417d854dc29 | 52 | |
| gkumar | 0:f417d854dc29 | 53 | } |
| gkumar | 1:b8c71afbe6e5 | 54 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 55 | //TASK : ACS data |
| gkumar | 1:b8c71afbe6e5 | 56 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 57 | |
| gkumar | 0:f417d854dc29 | 58 | void T_ACS(void const *args){ |
| gkumar | 1:b8c71afbe6e5 | 59 | |
| gkumar | 1:b8c71afbe6e5 | 60 | float mag_field1[3]; |
| gkumar | 1:b8c71afbe6e5 | 61 | float omega1[3]; |
| gkumar | 1:b8c71afbe6e5 | 62 | //float tauc1[3]; |
| gkumar | 1:b8c71afbe6e5 | 63 | //float moment[3]; |
| gkumar | 1:b8c71afbe6e5 | 64 | //float *mnm_data; |
| gkumar | 1:b8c71afbe6e5 | 65 | while(1) |
| gkumar | 1:b8c71afbe6e5 | 66 | { |
| gkumar | 1:b8c71afbe6e5 | 67 | Thread::signal_wait(0x1); |
| gkumar | 1:b8c71afbe6e5 | 68 | printf("\n\rEntered ACS %f\n",t_start.read()); |
| gkumar | 1:b8c71afbe6e5 | 69 | FCTN_ATS_DATA_ACQ(omega1,mag_field1); //the angular velocity is stored in the first 3 values and magnetic field values in next 3 |
| gkumar | 1:b8c71afbe6e5 | 70 | printf("\n\rmnm gyro values\n"); //printing the angular velocity and magnetic field values |
| gkumar | 1:b8c71afbe6e5 | 71 | for(int i=0; i<3; i++) |
| gkumar | 1:b8c71afbe6e5 | 72 | { |
| gkumar | 1:b8c71afbe6e5 | 73 | printf("%f\t",omega1[i]); |
| gkumar | 1:b8c71afbe6e5 | 74 | } |
| gkumar | 1:b8c71afbe6e5 | 75 | printf("\n\r mnm mag values\n"); |
| gkumar | 1:b8c71afbe6e5 | 76 | for(int i=0; i<3; i++) |
| gkumar | 1:b8c71afbe6e5 | 77 | { |
| gkumar | 1:b8c71afbe6e5 | 78 | printf("%f\t",mag_field1[i]); |
| gkumar | 1:b8c71afbe6e5 | 79 | } |
| gkumar | 1:b8c71afbe6e5 | 80 | t_exec.reset(); |
| gkumar | 1:b8c71afbe6e5 | 81 | |
| gkumar | 1:b8c71afbe6e5 | 82 | } |
| gkumar | 0:f417d854dc29 | 83 | } |
| gkumar | 1:b8c71afbe6e5 | 84 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 85 | //TASK : Beacon |
| gkumar | 1:b8c71afbe6e5 | 86 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 87 | int beac_flag=0; |
| gkumar | 0:f417d854dc29 | 88 | void T_BEA(void const *args){ |
| gkumar | 0:f417d854dc29 | 89 | while(1){ |
| gkumar | 0:f417d854dc29 | 90 | Thread::signal_wait(0x3); |
| gkumar | 1:b8c71afbe6e5 | 91 | printf("\n\rTHIS IS BEACON %f\n\r",t_start.read()); |
| gkumar | 1:b8c71afbe6e5 | 92 | // t_exec.start(); |
| gkumar | 1:b8c71afbe6e5 | 93 | // FCTN_BEA_MAIN(); |
| gkumar | 1:b8c71afbe6e5 | 94 | // if(beac_flag==1) |
| gkumar | 1:b8c71afbe6e5 | 95 | // { |
| gkumar | 1:b8c71afbe6e5 | 96 | // Thread::wait(600000); |
| gkumar | 1:b8c71afbe6e5 | 97 | // beac_flag = 0; |
| gkumar | 1:b8c71afbe6e5 | 98 | // } |
| gkumar | 1:b8c71afbe6e5 | 99 | // printf("The time to execute beacon thread is %f seconds\n\r",t_exec.read()); |
| gkumar | 1:b8c71afbe6e5 | 100 | // t_exec.reset(); |
| gkumar | 1:b8c71afbe6e5 | 101 | } |
| gkumar | 0:f417d854dc29 | 102 | } |
| gkumar | 0:f417d854dc29 | 103 | |
| gkumar | 1:b8c71afbe6e5 | 104 | |
| gkumar | 1:b8c71afbe6e5 | 105 | |
| gkumar | 1:b8c71afbe6e5 | 106 | //extern SensorDataQuantised SensorQuantised; |
| gkumar | 1:b8c71afbe6e5 | 107 | |
| gkumar | 1:b8c71afbe6e5 | 108 | |
| gkumar | 1:b8c71afbe6e5 | 109 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 110 | //TASK : Scheduler |
| gkumar | 1:b8c71afbe6e5 | 111 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 112 | |
| gkumar | 0:f417d854dc29 | 113 | uint8_t schedcount=1; |
| gkumar | 0:f417d854dc29 | 114 | void T_SC(void const *args) |
| gkumar | 0:f417d854dc29 | 115 | { |
| gkumar | 0:f417d854dc29 | 116 | |
| gkumar | 0:f417d854dc29 | 117 | |
| gkumar | 0:f417d854dc29 | 118 | if(schedcount == 4) //to reset the counter |
| gkumar | 0:f417d854dc29 | 119 | { |
| gkumar | 0:f417d854dc29 | 120 | schedcount = 1; |
| gkumar | 0:f417d854dc29 | 121 | } |
| gkumar | 0:f417d854dc29 | 122 | pc.printf("\n\rThe value of i in scheduler is %d\n\r",schedcount); |
| gkumar | 0:f417d854dc29 | 123 | if(schedcount%1==0) |
| gkumar | 0:f417d854dc29 | 124 | { |
| gkumar | 0:f417d854dc29 | 125 | ptr_t_acs -> signal_set(0x1); |
| gkumar | 0:f417d854dc29 | 126 | } |
| gkumar | 0:f417d854dc29 | 127 | |
| gkumar | 0:f417d854dc29 | 128 | if(schedcount%2==0) |
| gkumar | 0:f417d854dc29 | 129 | { |
| gkumar | 0:f417d854dc29 | 130 | ptr_t_hk -> signal_set(0x2); |
| gkumar | 0:f417d854dc29 | 131 | |
| gkumar | 0:f417d854dc29 | 132 | } |
| gkumar | 0:f417d854dc29 | 133 | if(schedcount%3==0) |
| gkumar | 0:f417d854dc29 | 134 | { |
| gkumar | 0:f417d854dc29 | 135 | |
| gkumar | 0:f417d854dc29 | 136 | ptr_t_bea -> signal_set(0x3); |
| gkumar | 0:f417d854dc29 | 137 | |
| gkumar | 0:f417d854dc29 | 138 | } |
| gkumar | 0:f417d854dc29 | 139 | schedcount++; |
| gkumar | 0:f417d854dc29 | 140 | } |
| gkumar | 1:b8c71afbe6e5 | 141 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 142 | //TASK : i2c data |
| gkumar | 1:b8c71afbe6e5 | 143 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 144 | //void FCTN_I2C_READ(char *data,int length); |
| gkumar | 1:b8c71afbe6e5 | 145 | //void FCTN_I2C_WRITE(char *data,int length); |
| gkumar | 0:f417d854dc29 | 146 | |
| gkumar | 0:f417d854dc29 | 147 | |
| gkumar | 1:b8c71afbe6e5 | 148 | bool write_ack = 1; |
| gkumar | 1:b8c71afbe6e5 | 149 | bool read_ack = 1; |
| gkumar | 2:f26706e0d779 | 150 | char data_send[25]; |
| gkumar | 1:b8c71afbe6e5 | 151 | char data_receive[10]; |
| gkumar | 1:b8c71afbe6e5 | 152 | char short_tc[10]; |
| gkumar | 1:b8c71afbe6e5 | 153 | char long_tc[134]; |
| gkumar | 1:b8c71afbe6e5 | 154 | char mstr_cmd = '0'; |
| gkumar | 1:b8c71afbe6e5 | 155 | bool cmd_flag = 1; |
| gkumar | 1:b8c71afbe6e5 | 156 | int length=10; |
| gkumar | 1:b8c71afbe6e5 | 157 | |
| gkumar | 1:b8c71afbe6e5 | 158 | void T_I2C_SLAVE(void const * args) |
| gkumar | 1:b8c71afbe6e5 | 159 | { |
| gkumar | 1:b8c71afbe6e5 | 160 | while(1) |
| gkumar | 1:b8c71afbe6e5 | 161 | { |
| gkumar | 1:b8c71afbe6e5 | 162 | cmd_flag = 1; |
| gkumar | 1:b8c71afbe6e5 | 163 | Thread::signal_wait(0x4); |
| gkumar | 1:b8c71afbe6e5 | 164 | wait_us(100); // can be between 38 to 15700 |
| gkumar | 1:b8c71afbe6e5 | 165 | //printf("\n\r check 1\n"); |
| gkumar | 1:b8c71afbe6e5 | 166 | t.stop(); |
| gkumar | 1:b8c71afbe6e5 | 167 | if( slave.receive() == 0) |
| gkumar | 1:b8c71afbe6e5 | 168 | slave.stop(); |
| gkumar | 1:b8c71afbe6e5 | 169 | if( slave.receive() == 1) // slave writes to master |
| gkumar | 1:b8c71afbe6e5 | 170 | { |
| gkumar | 1:b8c71afbe6e5 | 171 | t1.start(); |
| gkumar | 1:b8c71afbe6e5 | 172 | write_ack=slave.write(data_send,length); |
| gkumar | 1:b8c71afbe6e5 | 173 | t1.stop(); |
| gkumar | 1:b8c71afbe6e5 | 174 | if(write_ack == 0) |
| gkumar | 1:b8c71afbe6e5 | 175 | printf("\n\rData sent to CDMS is %s \n",data_send); |
| gkumar | 1:b8c71afbe6e5 | 176 | slave.stop(); |
| gkumar | 1:b8c71afbe6e5 | 177 | } |
| gkumar | 1:b8c71afbe6e5 | 178 | if( slave.receive()==3 || slave.receive()==2) // slave read |
| gkumar | 1:b8c71afbe6e5 | 179 | { |
| gkumar | 1:b8c71afbe6e5 | 180 | t1.start(); |
| gkumar | 1:b8c71afbe6e5 | 181 | read_ack=slave.read(data_receive,length); |
| gkumar | 1:b8c71afbe6e5 | 182 | t1.stop(); |
| gkumar | 1:b8c71afbe6e5 | 183 | if(read_ack == 0) |
| gkumar | 2:f26706e0d779 | 184 | printf("\n\r Data received from CDMS is %c \n",data_receive); |
| gkumar | 2:f26706e0d779 | 185 | if(strcmp(data_receive,"h")) |
| gkumar | 2:f26706e0d779 | 186 | { strcpy(data_send, "ababababababababababababg"); |
| gkumar | 2:f26706e0d779 | 187 | length=25; |
| gkumar | 2:f26706e0d779 | 188 | write_ack=slave.write(data_send,length); |
| gkumar | 2:f26706e0d779 | 189 | if(write_ack == 0) |
| gkumar | 2:f26706e0d779 | 190 | printf("\n\rData sent to CDMS is %s \n",data_send); |
| gkumar | 2:f26706e0d779 | 191 | slave.stop(); |
| gkumar | 2:f26706e0d779 | 192 | } |
| gkumar | 1:b8c71afbe6e5 | 193 | slave.stop(); |
| gkumar | 1:b8c71afbe6e5 | 194 | } |
| gkumar | 1:b8c71afbe6e5 | 195 | printf("\n \r %d %d\n",t.read_us(),t1.read_us()); |
| gkumar | 1:b8c71afbe6e5 | 196 | t.reset(); |
| gkumar | 1:b8c71afbe6e5 | 197 | t1.reset(); |
| gkumar | 1:b8c71afbe6e5 | 198 | } |
| gkumar | 1:b8c71afbe6e5 | 199 | |
| gkumar | 1:b8c71afbe6e5 | 200 | // if(cmd_flag == 1) |
| gkumar | 1:b8c71afbe6e5 | 201 | // { |
| gkumar | 1:b8c71afbe6e5 | 202 | // t.stop(); |
| gkumar | 1:b8c71afbe6e5 | 203 | // if( slave.receive()==3 || slave.receive()==2) // slave read |
| gkumar | 1:b8c71afbe6e5 | 204 | // { |
| gkumar | 1:b8c71afbe6e5 | 205 | // |
| gkumar | 1:b8c71afbe6e5 | 206 | // t1.start(); |
| gkumar | 1:b8c71afbe6e5 | 207 | // read_ack=slave.read(&mstr_cmd,1); |
| gkumar | 1:b8c71afbe6e5 | 208 | // t1.stop(); |
| gkumar | 1:b8c71afbe6e5 | 209 | // if(read_ack == 0) |
| gkumar | 1:b8c71afbe6e5 | 210 | // { |
| gkumar | 1:b8c71afbe6e5 | 211 | // printf("\n\r Data received from CDMS is %c \n",mstr_cmd); |
| gkumar | 1:b8c71afbe6e5 | 212 | // switch(mstr_cmd) |
| gkumar | 1:b8c71afbe6e5 | 213 | // { |
| gkumar | 1:b8c71afbe6e5 | 214 | // case 's': |
| gkumar | 1:b8c71afbe6e5 | 215 | // length = 11; |
| gkumar | 1:b8c71afbe6e5 | 216 | // cmd_flag = 0; |
| gkumar | 1:b8c71afbe6e5 | 217 | // break; |
| gkumar | 1:b8c71afbe6e5 | 218 | // |
| gkumar | 1:b8c71afbe6e5 | 219 | // case 'l': |
| gkumar | 1:b8c71afbe6e5 | 220 | // length = 135; |
| gkumar | 1:b8c71afbe6e5 | 221 | // cmd_flag = 0; |
| gkumar | 1:b8c71afbe6e5 | 222 | // break; |
| gkumar | 1:b8c71afbe6e5 | 223 | // |
| gkumar | 1:b8c71afbe6e5 | 224 | // case 'h': |
| gkumar | 1:b8c71afbe6e5 | 225 | // length = 25; |
| gkumar | 1:b8c71afbe6e5 | 226 | // cmd_flag = 0; |
| gkumar | 1:b8c71afbe6e5 | 227 | // FCTN_I2C_WRITE(hk_data,length ); |
| gkumar | 1:b8c71afbe6e5 | 228 | // break; |
| gkumar | 1:b8c71afbe6e5 | 229 | // |
| gkumar | 1:b8c71afbe6e5 | 230 | // default: |
| gkumar | 1:b8c71afbe6e5 | 231 | // printf("\n\r invalid command \n"); |
| gkumar | 1:b8c71afbe6e5 | 232 | // //cmd_err = 0; |
| gkumar | 1:b8c71afbe6e5 | 233 | // cmd_flag = 1; |
| gkumar | 1:b8c71afbe6e5 | 234 | // } |
| gkumar | 1:b8c71afbe6e5 | 235 | // } |
| gkumar | 1:b8c71afbe6e5 | 236 | // else |
| gkumar | 1:b8c71afbe6e5 | 237 | // cmd_flag = 1; |
| gkumar | 1:b8c71afbe6e5 | 238 | // } |
| gkumar | 1:b8c71afbe6e5 | 239 | // else |
| gkumar | 1:b8c71afbe6e5 | 240 | // cmd_flag = 1; |
| gkumar | 1:b8c71afbe6e5 | 241 | // } |
| gkumar | 1:b8c71afbe6e5 | 242 | // printf("\n \r %d %d\n",t.read_us(),t1.read_us()); |
| gkumar | 1:b8c71afbe6e5 | 243 | // t.reset(); |
| gkumar | 1:b8c71afbe6e5 | 244 | // t1.reset(); |
| gkumar | 1:b8c71afbe6e5 | 245 | // |
| gkumar | 1:b8c71afbe6e5 | 246 | // |
| gkumar | 1:b8c71afbe6e5 | 247 | // } |
| gkumar | 1:b8c71afbe6e5 | 248 | //} |
| gkumar | 1:b8c71afbe6e5 | 249 | // |
| gkumar | 1:b8c71afbe6e5 | 250 | //void FCTN_I2C_READ(char *data, int length ) |
| gkumar | 1:b8c71afbe6e5 | 251 | //{ |
| gkumar | 1:b8c71afbe6e5 | 252 | // t1.start(); |
| gkumar | 1:b8c71afbe6e5 | 253 | // read_ack=slave.read(data,length); |
| gkumar | 1:b8c71afbe6e5 | 254 | // t1.stop(); |
| gkumar | 1:b8c71afbe6e5 | 255 | // if(read_ack == 0) |
| gkumar | 1:b8c71afbe6e5 | 256 | // printf("\n\rData received from CDMS is %s \n",data); |
| gkumar | 1:b8c71afbe6e5 | 257 | // else |
| gkumar | 1:b8c71afbe6e5 | 258 | // printf("\n\r data not received \n"); |
| gkumar | 1:b8c71afbe6e5 | 259 | //} |
| gkumar | 1:b8c71afbe6e5 | 260 | // |
| gkumar | 1:b8c71afbe6e5 | 261 | //void FCTN_I2C_WRITE(char *data,int length) |
| gkumar | 1:b8c71afbe6e5 | 262 | //{ |
| gkumar | 1:b8c71afbe6e5 | 263 | // t1.start(); |
| gkumar | 1:b8c71afbe6e5 | 264 | // write_ack=slave.write(data,length); |
| gkumar | 1:b8c71afbe6e5 | 265 | // t1.stop(); |
| gkumar | 1:b8c71afbe6e5 | 266 | // if(write_ack == 0) |
| gkumar | 1:b8c71afbe6e5 | 267 | // printf("\n\rData sent to CDMS is %s \n",data); |
| gkumar | 1:b8c71afbe6e5 | 268 | // else |
| gkumar | 1:b8c71afbe6e5 | 269 | // printf("\n\r data not sent\n"); |
| gkumar | 1:b8c71afbe6e5 | 270 | } |
| gkumar | 1:b8c71afbe6e5 | 271 | |
| gkumar | 1:b8c71afbe6e5 | 272 | |
| gkumar | 1:b8c71afbe6e5 | 273 | void FCTN_ISR_I2C() |
| gkumar | 1:b8c71afbe6e5 | 274 | { |
| gkumar | 1:b8c71afbe6e5 | 275 | ptr_t_i2c->signal_set(0x4); |
| gkumar | 1:b8c71afbe6e5 | 276 | t.start(); |
| gkumar | 1:b8c71afbe6e5 | 277 | } |
| gkumar | 1:b8c71afbe6e5 | 278 | //void FCTN_HK_DATA_CATENATE() |
| gkumar | 1:b8c71afbe6e5 | 279 | //{ |
| gkumar | 1:b8c71afbe6e5 | 280 | // strcpy(hk_data,"hk_Data"); |
| gkumar | 1:b8c71afbe6e5 | 281 | // strcat(hk_data,SensorQuantised.Voltage); |
| gkumar | 1:b8c71afbe6e5 | 282 | // strcat(hk_data,SensorQuantised.Current); |
| gkumar | 1:b8c71afbe6e5 | 283 | // strcat(hk_data,SensorQuantised.PanelTemperature); |
| gkumar | 1:b8c71afbe6e5 | 284 | // strcat(hk_data,SensorQuantised.AngularSpeed); |
| gkumar | 1:b8c71afbe6e5 | 285 | // strcat(hk_data,SensorQuantised.Bnewvalue); |
| gkumar | 1:b8c71afbe6e5 | 286 | // char fdata[5] = {SensorQuantised.BatteryTemperature,SensorQuantised.faultpoll,SensorQuantised.faultir,SensorQuantised.power_mode}; |
| gkumar | 1:b8c71afbe6e5 | 287 | // /*strcat(hk_data,sfaultpoll); |
| gkumar | 1:b8c71afbe6e5 | 288 | // strcat(hk_data,sfaultir); |
| gkumar | 1:b8c71afbe6e5 | 289 | // strcat(hk_data,spower_mode);*/ |
| gkumar | 1:b8c71afbe6e5 | 290 | // strcat(hk_data,fdata); |
| gkumar | 1:b8c71afbe6e5 | 291 | // printf("\n\r hk data being sent is %s ",hk_data); |
| gkumar | 1:b8c71afbe6e5 | 292 | //} |
| gkumar | 1:b8c71afbe6e5 | 293 | |
| gkumar | 1:b8c71afbe6e5 | 294 | //----------------------------------------------------------------------------BAE_INIT------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 295 | |
| gkumar | 1:b8c71afbe6e5 | 296 | void FCTN_BAE_INIT() |
| gkumar | 1:b8c71afbe6e5 | 297 | { |
| gkumar | 1:b8c71afbe6e5 | 298 | slave.address(0x20); // setting slave address for BAE for I2C communication |
| gkumar | 1:b8c71afbe6e5 | 299 | FCTN_ACS_INIT(); // Initializing mnm blue |
| gkumar | 1:b8c71afbe6e5 | 300 | //FCTN_BAE_HK_INIT(); |
| gkumar | 1:b8c71afbe6e5 | 301 | //FCTN_BEA_INIT(); |
| gkumar | 1:b8c71afbe6e5 | 302 | } |
| gkumar | 1:b8c71afbe6e5 | 303 | |
| gkumar | 1:b8c71afbe6e5 | 304 | |
| gkumar | 1:b8c71afbe6e5 | 305 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 306 | //TASK : Main |
| gkumar | 1:b8c71afbe6e5 | 307 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
| gkumar | 1:b8c71afbe6e5 | 308 | |
| gkumar | 0:f417d854dc29 | 309 | |
| gkumar | 0:f417d854dc29 | 310 | |
| gkumar | 0:f417d854dc29 | 311 | int main(){ |
| gkumar | 0:f417d854dc29 | 312 | ptr_t_hk = new Thread(T_HK); |
| gkumar | 0:f417d854dc29 | 313 | ptr_t_acs = new Thread(T_ACS); |
| gkumar | 0:f417d854dc29 | 314 | ptr_t_bea = new Thread(T_BEA); |
| gkumar | 1:b8c71afbe6e5 | 315 | ptr_t_i2c= new Thread(T_I2C_SLAVE); |
| gkumar | 0:f417d854dc29 | 316 | |
| gkumar | 0:f417d854dc29 | 317 | ptr_t_acs->set_priority(osPriorityAboveNormal); |
| gkumar | 0:f417d854dc29 | 318 | ptr_t_hk->set_priority(osPriorityAboveNormal); |
| gkumar | 0:f417d854dc29 | 319 | ptr_t_bea->set_priority(osPriorityAboveNormal); |
| gkumar | 1:b8c71afbe6e5 | 320 | ptr_t_i2c->set_priority(osPriorityRealtime); |
| gkumar | 1:b8c71afbe6e5 | 321 | |
| gkumar | 0:f417d854dc29 | 322 | RtosTimer t_sc_timer(T_SC,osTimerPeriodic); // Initiating the scheduler thread |
| gkumar | 1:b8c71afbe6e5 | 323 | t_sc_timer.start(10000); |
| gkumar | 1:b8c71afbe6e5 | 324 | printf("\n\r BAE ACTIVATED\n"); |
| gkumar | 1:b8c71afbe6e5 | 325 | FCTN_BAE_INIT(); |
| gkumar | 1:b8c71afbe6e5 | 326 | //strcpy(data_send,"sakthi"); |
| gkumar | 1:b8c71afbe6e5 | 327 | slave.address(addr); |
| gkumar | 1:b8c71afbe6e5 | 328 | irpt_4m_mstr.enable_irq(); |
| gkumar | 1:b8c71afbe6e5 | 329 | irpt_4m_mstr.rise(&FCTN_ISR_I2C); |
| gkumar | 1:b8c71afbe6e5 | 330 | |
| gkumar | 0:f417d854dc29 | 331 | |
| gkumar | 0:f417d854dc29 | 332 | while(1) //required to prevent main from terminating |
| gkumar | 0:f417d854dc29 | 333 | { |
| gkumar | 0:f417d854dc29 | 334 | ; |
| gkumar | 0:f417d854dc29 | 335 | } |
| gkumar | 0:f417d854dc29 | 336 | } |
