green rosh
/
RTOS_BAE_IITMSAT
Rtos code for BAE microcontroller, IITMSAT
main.cpp@3:307c56629df0, 2014-07-09 (annotated)
- Committer:
- greenroshks
- Date:
- Wed Jul 09 09:03:11 2014 +0000
- Revision:
- 3:307c56629df0
- Parent:
- 2:1792c9cda669
updated with pranoy's hk
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
greenroshks | 0:f1f148215d00 | 1 | #include "rtos.h" |
greenroshks | 2:1792c9cda669 | 2 | #include "HK.h" |
greenroshks | 2:1792c9cda669 | 3 | #include "slave.h" |
greenroshks | 0:f1f148215d00 | 4 | |
greenroshks | 3:307c56629df0 | 5 | #define _bool uint8_t |
greenroshks | 3:307c56629df0 | 6 | #define intmax 65531 //to allow smooth functioning of scheduler |
greenroshks | 0:f1f148215d00 | 7 | Serial pc(USBTX,USBRX); |
greenroshks | 0:f1f148215d00 | 8 | Timer t; |
greenroshks | 0:f1f148215d00 | 9 | Thread *t_acs; |
greenroshks | 0:f1f148215d00 | 10 | Thread *t_bea; |
greenroshks | 0:f1f148215d00 | 11 | Thread *t_hk_acq; |
greenroshks | 0:f1f148215d00 | 12 | Thread *t_acs_write2flash; |
greenroshks | 0:f1f148215d00 | 13 | Thread *t_hk_write2cdms; |
greenroshks | 2:1792c9cda669 | 14 | Thread *t_fault; |
greenroshks | 0:f1f148215d00 | 15 | |
greenroshks | 1:5a364ac20fa4 | 16 | |
greenroshks | 1:5a364ac20fa4 | 17 | |
greenroshks | 3:307c56629df0 | 18 | _bool beac_flag = 0; //for detecting keypress from computer |
greenroshks | 0:f1f148215d00 | 19 | |
greenroshks | 0:f1f148215d00 | 20 | |
greenroshks | 0:f1f148215d00 | 21 | /*---------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:f1f148215d00 | 22 | TASK 1:ACS |
greenroshks | 0:f1f148215d00 | 23 | ----------------------------------------------------------------------------------------------------------------------------------------------------*/ |
greenroshks | 0:f1f148215d00 | 24 | typedef struct |
greenroshks | 0:f1f148215d00 | 25 | { |
greenroshks | 0:f1f148215d00 | 26 | int B; |
greenroshks | 0:f1f148215d00 | 27 | int omega; |
greenroshks | 0:f1f148215d00 | 28 | }sens_data; |
greenroshks | 0:f1f148215d00 | 29 | |
greenroshks | 1:5a364ac20fa4 | 30 | void FUNC_ACS_READDATA(sens_data * s); |
greenroshks | 1:5a364ac20fa4 | 31 | |
greenroshks | 0:f1f148215d00 | 32 | Mail <sens_data,16> q_sensor; |
greenroshks | 1:5a364ac20fa4 | 33 | /*---------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 1:5a364ac20fa4 | 34 | Definitions of functions for thread T_ACS_MAIN begin here |
greenroshks | 1:5a364ac20fa4 | 35 | -----------------------------------------------------------------------------------------------------------------------------------------------------*/ |
greenroshks | 1:5a364ac20fa4 | 36 | //This function is called only once after the microcontroller is reset. |
greenroshks | 1:5a364ac20fa4 | 37 | void FUNC_ACS_SENSORINIT() |
greenroshks | 1:5a364ac20fa4 | 38 | { |
greenroshks | 1:5a364ac20fa4 | 39 | /* |
greenroshks | 1:5a364ac20fa4 | 40 | |
greenroshks | 1:5a364ac20fa4 | 41 | Lines of code to be given by Shruti and Jahnavi |
greenroshks | 1:5a364ac20fa4 | 42 | |
greenroshks | 1:5a364ac20fa4 | 43 | */ |
greenroshks | 1:5a364ac20fa4 | 44 | pc.printf("\nInitializing the sensors.. \n"); |
greenroshks | 1:5a364ac20fa4 | 45 | } |
greenroshks | 0:f1f148215d00 | 46 | |
greenroshks | 0:f1f148215d00 | 47 | void FUNC_ACS_READDATA(sens_data * s) |
greenroshks | 0:f1f148215d00 | 48 | { |
greenroshks | 1:5a364ac20fa4 | 49 | /* |
greenroshks | 1:5a364ac20fa4 | 50 | |
greenroshks | 1:5a364ac20fa4 | 51 | Lines of code to be given by Shruti and Jahnavi |
greenroshks | 1:5a364ac20fa4 | 52 | |
greenroshks | 1:5a364ac20fa4 | 53 | Request sensor data |
greenroshks | 1:5a364ac20fa4 | 54 | |
greenroshks | 1:5a364ac20fa4 | 55 | */ |
greenroshks | 1:5a364ac20fa4 | 56 | |
greenroshks | 1:5a364ac20fa4 | 57 | |
greenroshks | 1:5a364ac20fa4 | 58 | // this is the dummy data |
greenroshks | 0:f1f148215d00 | 59 | s->B=10; |
greenroshks | 0:f1f148215d00 | 60 | s->omega=100; |
greenroshks | 1:5a364ac20fa4 | 61 | |
greenroshks | 1:5a364ac20fa4 | 62 | pc.printf("\nReceived sensor data\n"); |
greenroshks | 0:f1f148215d00 | 63 | } |
greenroshks | 0:f1f148215d00 | 64 | |
greenroshks | 1:5a364ac20fa4 | 65 | float FUNC_ACS_CONTROLALGO(sens_data * s) |
greenroshks | 0:f1f148215d00 | 66 | { |
greenroshks | 1:5a364ac20fa4 | 67 | /* |
greenroshks | 1:5a364ac20fa4 | 68 | |
greenroshks | 1:5a364ac20fa4 | 69 | Lines of code to be given by Shruti and Jahnavi |
greenroshks | 1:5a364ac20fa4 | 70 | |
greenroshks | 1:5a364ac20fa4 | 71 | Control algorithm implementation |
greenroshks | 1:5a364ac20fa4 | 72 | |
greenroshks | 1:5a364ac20fa4 | 73 | */ |
greenroshks | 1:5a364ac20fa4 | 74 | float m; |
greenroshks | 1:5a364ac20fa4 | 75 | s->B=10 *10; |
greenroshks | 1:5a364ac20fa4 | 76 | s->omega=100*10; |
greenroshks | 1:5a364ac20fa4 | 77 | m = 10; |
greenroshks | 1:5a364ac20fa4 | 78 | pc.printf("\nImplemented control algo\n"); |
greenroshks | 1:5a364ac20fa4 | 79 | |
greenroshks | 1:5a364ac20fa4 | 80 | return(m); |
greenroshks | 0:f1f148215d00 | 81 | } |
greenroshks | 0:f1f148215d00 | 82 | |
greenroshks | 1:5a364ac20fa4 | 83 | void FUNC_ACS_PWMGEN(float m) |
greenroshks | 0:f1f148215d00 | 84 | { |
greenroshks | 1:5a364ac20fa4 | 85 | float dc; |
greenroshks | 1:5a364ac20fa4 | 86 | dc = m*2; |
greenroshks | 1:5a364ac20fa4 | 87 | |
greenroshks | 1:5a364ac20fa4 | 88 | /* |
greenroshks | 1:5a364ac20fa4 | 89 | |
greenroshks | 1:5a364ac20fa4 | 90 | Lines of code to be given by Kumar and Karthik |
greenroshks | 1:5a364ac20fa4 | 91 | |
greenroshks | 1:5a364ac20fa4 | 92 | PWM implementation |
greenroshks | 1:5a364ac20fa4 | 93 | |
greenroshks | 1:5a364ac20fa4 | 94 | */ |
greenroshks | 1:5a364ac20fa4 | 95 | |
greenroshks | 1:5a364ac20fa4 | 96 | |
greenroshks | 0:f1f148215d00 | 97 | pc.printf("\nGenerating pwm signal\n"); |
greenroshks | 1:5a364ac20fa4 | 98 | |
greenroshks | 1:5a364ac20fa4 | 99 | |
greenroshks | 0:f1f148215d00 | 100 | } |
greenroshks | 0:f1f148215d00 | 101 | |
greenroshks | 1:5a364ac20fa4 | 102 | // Definitions of functions for thread T_ACS_MAIN end here |
greenroshks | 1:5a364ac20fa4 | 103 | //---------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 1:5a364ac20fa4 | 104 | |
greenroshks | 1:5a364ac20fa4 | 105 | |
greenroshks | 1:5a364ac20fa4 | 106 | |
greenroshks | 1:5a364ac20fa4 | 107 | // Definitions of functions for thread T_ACS_WRITE2FLASH starts here |
greenroshks | 1:5a364ac20fa4 | 108 | //---------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 1:5a364ac20fa4 | 109 | |
greenroshks | 0:f1f148215d00 | 110 | void FUNC_ACS_WRITE2FLASH(sens_data *s1) |
greenroshks | 0:f1f148215d00 | 111 | { |
greenroshks | 0:f1f148215d00 | 112 | pc.printf("\nWritng ACS data to BAE flash\n"); |
greenroshks | 0:f1f148215d00 | 113 | pc.printf("\nB :%d",s1->B); |
greenroshks | 0:f1f148215d00 | 114 | pc.printf("\nomega :%d",s1->omega); |
greenroshks | 0:f1f148215d00 | 115 | |
greenroshks | 0:f1f148215d00 | 116 | } |
greenroshks | 0:f1f148215d00 | 117 | |
greenroshks | 1:5a364ac20fa4 | 118 | // Definitions of functions for thread T_ACS_WRITE2FLASH end here |
greenroshks | 1:5a364ac20fa4 | 119 | //---------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 1:5a364ac20fa4 | 120 | |
greenroshks | 1:5a364ac20fa4 | 121 | // This is the main thread of ACS |
greenroshks | 1:5a364ac20fa4 | 122 | |
greenroshks | 1:5a364ac20fa4 | 123 | void T_ACS_MAIN(void const * args) |
greenroshks | 0:f1f148215d00 | 124 | { |
greenroshks | 2:1792c9cda669 | 125 | FUNC_ACS_SENSORINIT(); //Initializing sensors |
greenroshks | 0:f1f148215d00 | 126 | while(1) |
greenroshks | 0:f1f148215d00 | 127 | { |
greenroshks | 1:5a364ac20fa4 | 128 | |
greenroshks | 1:5a364ac20fa4 | 129 | float m; |
greenroshks | 2:1792c9cda669 | 130 | Thread::signal_wait(0x1); // waiting for signal from scheduler every ten seconds |
greenroshks | 0:f1f148215d00 | 131 | printf("\nACS :%fn",t.read()); |
greenroshks | 2:1792c9cda669 | 132 | printf("\nACS thread state is %d\n",t_acs->get_state()); |
greenroshks | 2:1792c9cda669 | 133 | printf("\nBeacon thread state :%d\n",t_bea->get_state()); |
greenroshks | 2:1792c9cda669 | 134 | printf("\nACS_WRITE2FLASH thread state is %d\n",t_acs_write2flash->get_state()); |
greenroshks | 2:1792c9cda669 | 135 | printf("\nHK_ACQ thread state is %d\n",t_hk_acq->get_state()); |
greenroshks | 2:1792c9cda669 | 136 | printf("\nHK_WRITE2CDMS thread state is %d\n",t_hk_write2cdms->get_state()); |
greenroshks | 0:f1f148215d00 | 137 | |
greenroshks | 2:1792c9cda669 | 138 | sens_data * s = q_sensor.alloc(); |
greenroshks | 1:5a364ac20fa4 | 139 | |
greenroshks | 0:f1f148215d00 | 140 | FUNC_ACS_READDATA(s); |
greenroshks | 0:f1f148215d00 | 141 | q_sensor.put(s); |
greenroshks | 1:5a364ac20fa4 | 142 | m=FUNC_ACS_CONTROLALGO(s); |
greenroshks | 1:5a364ac20fa4 | 143 | FUNC_ACS_PWMGEN(m); |
greenroshks | 0:f1f148215d00 | 144 | pc.printf("\nTorque rods actuated\n"); |
greenroshks | 0:f1f148215d00 | 145 | //Thread::wait(9899); |
greenroshks | 1:5a364ac20fa4 | 146 | } |
greenroshks | 0:f1f148215d00 | 147 | } |
greenroshks | 0:f1f148215d00 | 148 | |
greenroshks | 0:f1f148215d00 | 149 | void T_ACS_WRITE2FLASH(void const * args) |
greenroshks | 0:f1f148215d00 | 150 | { |
greenroshks | 0:f1f148215d00 | 151 | while(1) |
greenroshks | 0:f1f148215d00 | 152 | { |
greenroshks | 0:f1f148215d00 | 153 | |
greenroshks | 0:f1f148215d00 | 154 | osEvent evt=q_sensor.get(); |
greenroshks | 0:f1f148215d00 | 155 | if(evt.status==osEventMail) |
greenroshks | 0:f1f148215d00 | 156 | { |
greenroshks | 2:1792c9cda669 | 157 | printf("\nACS thread status is %d\n",t_acs->get_state()); |
greenroshks | 2:1792c9cda669 | 158 | printf("\nBeacon thread status :%d\n",t_bea->get_state()); |
greenroshks | 2:1792c9cda669 | 159 | printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state()); |
greenroshks | 2:1792c9cda669 | 160 | printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state()); |
greenroshks | 2:1792c9cda669 | 161 | printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state()); |
greenroshks | 1:5a364ac20fa4 | 162 | sens_data *s1 =(sens_data *)evt.value.p;// please see |
greenroshks | 0:f1f148215d00 | 163 | FUNC_ACS_WRITE2FLASH(s1); |
greenroshks | 1:5a364ac20fa4 | 164 | |
greenroshks | 1:5a364ac20fa4 | 165 | q_sensor.free(s1); |
greenroshks | 0:f1f148215d00 | 166 | } |
greenroshks | 0:f1f148215d00 | 167 | } |
greenroshks | 0:f1f148215d00 | 168 | } |
greenroshks | 0:f1f148215d00 | 169 | |
greenroshks | 0:f1f148215d00 | 170 | /*----------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:f1f148215d00 | 171 | TASK 2 : HK |
greenroshks | 0:f1f148215d00 | 172 | ------------------------------------------------------------------------------------------------------------------------------------------------------*/ |
greenroshks | 1:5a364ac20fa4 | 173 | |
greenroshks | 1:5a364ac20fa4 | 174 | //Functions for the thread T_HK_ACQ begins here |
greenroshks | 1:5a364ac20fa4 | 175 | //---------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 2:1792c9cda669 | 176 | extern void FUNC_HK_MAIN(); // declared in HK.h |
greenroshks | 0:f1f148215d00 | 177 | |
greenroshks | 1:5a364ac20fa4 | 178 | //Functions of the thread T_HK_SEND2CDMS starts here. |
greenroshks | 1:5a364ac20fa4 | 179 | //---------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 1:5a364ac20fa4 | 180 | |
greenroshks | 2:1792c9cda669 | 181 | extern void FUNC_I2C_SLAVE_MAIN(); |
greenroshks | 1:5a364ac20fa4 | 182 | |
greenroshks | 1:5a364ac20fa4 | 183 | //---------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 1:5a364ac20fa4 | 184 | // Defintion of thread for sending data to CDMS |
greenroshks | 1:5a364ac20fa4 | 185 | //---------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:f1f148215d00 | 186 | void T_HK_SEND2CDMS(void const * args) |
greenroshks | 0:f1f148215d00 | 187 | { |
greenroshks | 2:1792c9cda669 | 188 | |
greenroshks | 0:f1f148215d00 | 189 | while(1) |
greenroshks | 0:f1f148215d00 | 190 | { |
greenroshks | 1:5a364ac20fa4 | 191 | Thread::signal_wait(0x1); // Waiting for signal from T_HK_ACQ |
greenroshks | 0:f1f148215d00 | 192 | printf("\nACS thread status is %d\n",t_acs->get_state()); |
greenroshks | 0:f1f148215d00 | 193 | printf("\nBeacon thread status :%d\n",t_bea->get_state()); |
greenroshks | 0:f1f148215d00 | 194 | printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state()); |
greenroshks | 0:f1f148215d00 | 195 | printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state()); |
greenroshks | 0:f1f148215d00 | 196 | printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state()); |
greenroshks | 2:1792c9cda669 | 197 | FUNC_I2C_SLAVE_MAIN(); |
greenroshks | 0:f1f148215d00 | 198 | } |
greenroshks | 0:f1f148215d00 | 199 | } |
greenroshks | 0:f1f148215d00 | 200 | |
greenroshks | 1:5a364ac20fa4 | 201 | //---------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 1:5a364ac20fa4 | 202 | //Definition for the thread to collect HK data and store to flash memory |
greenroshks | 1:5a364ac20fa4 | 203 | //---------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 1:5a364ac20fa4 | 204 | |
greenroshks | 0:f1f148215d00 | 205 | void T_HK_ACQ(void const *args) |
greenroshks | 0:f1f148215d00 | 206 | { |
greenroshks | 0:f1f148215d00 | 207 | //t_hk_write2cdms = new Thread(T_HK_SEND2CDMS); |
greenroshks | 1:5a364ac20fa4 | 208 | //t_hk_write2cdms->set_priority(osPriorityLow); |
greenroshks | 0:f1f148215d00 | 209 | while(1) |
greenroshks | 0:f1f148215d00 | 210 | { |
greenroshks | 1:5a364ac20fa4 | 211 | |
greenroshks | 2:1792c9cda669 | 212 | Thread::signal_wait(0x1); //Waiting for the signal from sceduler every 20 seconds |
greenroshks | 0:f1f148215d00 | 213 | printf("\n\nHK :%f\n",t.read()); |
greenroshks | 2:1792c9cda669 | 214 | printf("\nACS thread status is %d\n",t_acs->get_state()); |
greenroshks | 0:f1f148215d00 | 215 | printf("\nBeacon thread status :%d\n",t_bea->get_state()); |
greenroshks | 0:f1f148215d00 | 216 | printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state()); |
greenroshks | 0:f1f148215d00 | 217 | printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state()); |
greenroshks | 2:1792c9cda669 | 218 | printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state()); |
greenroshks | 0:f1f148215d00 | 219 | |
greenroshks | 2:1792c9cda669 | 220 | FUNC_HK_MAIN(); |
greenroshks | 0:f1f148215d00 | 221 | t_hk_write2cdms->signal_set(0x1); |
greenroshks | 0:f1f148215d00 | 222 | //Thread::wait(19925); |
greenroshks | 0:f1f148215d00 | 223 | } |
greenroshks | 1:5a364ac20fa4 | 224 | |
greenroshks | 0:f1f148215d00 | 225 | } |
greenroshks | 0:f1f148215d00 | 226 | |
greenroshks | 0:f1f148215d00 | 227 | /*-------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 2:1792c9cda669 | 228 | TASK 3 : BEACON |
greenroshks | 0:f1f148215d00 | 229 | -----------------------------------------------------------------------------------------------------------------------------------------------------*/ |
greenroshks | 1:5a364ac20fa4 | 230 | |
greenroshks | 1:5a364ac20fa4 | 231 | |
greenroshks | 2:1792c9cda669 | 232 | void FUNC_BEA_READBAERAM() |
greenroshks | 0:f1f148215d00 | 233 | { |
greenroshks | 1:5a364ac20fa4 | 234 | /* |
greenroshks | 1:5a364ac20fa4 | 235 | Code to be given by Nathaniel |
greenroshks | 1:5a364ac20fa4 | 236 | */ |
greenroshks | 1:5a364ac20fa4 | 237 | |
greenroshks | 2:1792c9cda669 | 238 | pc.printf("\nReading HK data from BAE RAM\n"); |
greenroshks | 0:f1f148215d00 | 239 | } |
greenroshks | 0:f1f148215d00 | 240 | |
greenroshks | 0:f1f148215d00 | 241 | void FUNC_BEA_WRITE2SPI() |
greenroshks | 0:f1f148215d00 | 242 | { |
greenroshks | 1:5a364ac20fa4 | 243 | /* |
greenroshks | 1:5a364ac20fa4 | 244 | Code to be given by Nathaniel |
greenroshks | 1:5a364ac20fa4 | 245 | */ |
greenroshks | 1:5a364ac20fa4 | 246 | |
greenroshks | 0:f1f148215d00 | 247 | pc.printf("\nSending data through SPI\n"); |
greenroshks | 0:f1f148215d00 | 248 | } |
greenroshks | 0:f1f148215d00 | 249 | |
greenroshks | 0:f1f148215d00 | 250 | |
greenroshks | 0:f1f148215d00 | 251 | void T_BEA(void const * args) |
greenroshks | 0:f1f148215d00 | 252 | { |
greenroshks | 2:1792c9cda669 | 253 | extern SensorData Sensor; //Defined in HK.h |
greenroshks | 0:f1f148215d00 | 254 | while(1) |
greenroshks | 0:f1f148215d00 | 255 | { |
greenroshks | 1:5a364ac20fa4 | 256 | |
greenroshks | 2:1792c9cda669 | 257 | Thread::signal_wait(0x1); //waiting for signal from scheduler every 30 seconds. |
greenroshks | 0:f1f148215d00 | 258 | pc.printf("\nBEACON :%f\n",t.read()); |
greenroshks | 0:f1f148215d00 | 259 | printf("\nACS thread status is %d\n",t_acs->get_state()); |
greenroshks | 0:f1f148215d00 | 260 | printf("\nBeacon thread status :%d\n",t_bea->get_state()); |
greenroshks | 0:f1f148215d00 | 261 | printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state()); |
greenroshks | 0:f1f148215d00 | 262 | printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state()); |
greenroshks | 0:f1f148215d00 | 263 | printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state()); |
greenroshks | 0:f1f148215d00 | 264 | |
greenroshks | 3:307c56629df0 | 265 | if(beac_flag==0) |
greenroshks | 0:f1f148215d00 | 266 | { |
greenroshks | 0:f1f148215d00 | 267 | |
greenroshks | 2:1792c9cda669 | 268 | FUNC_BEA_READBAERAM(); |
greenroshks | 0:f1f148215d00 | 269 | FUNC_BEA_WRITE2SPI(); |
greenroshks | 1:5a364ac20fa4 | 270 | // Thread::wait(30000); |
greenroshks | 0:f1f148215d00 | 271 | } |
greenroshks | 0:f1f148215d00 | 272 | else |
greenroshks | 0:f1f148215d00 | 273 | { |
greenroshks | 0:f1f148215d00 | 274 | //led=1; |
greenroshks | 0:f1f148215d00 | 275 | Thread::wait(60000); |
greenroshks | 0:f1f148215d00 | 276 | |
greenroshks | 3:307c56629df0 | 277 | beac_flag=0; |
greenroshks | 0:f1f148215d00 | 278 | //myled=0; |
greenroshks | 0:f1f148215d00 | 279 | } |
greenroshks | 1:5a364ac20fa4 | 280 | } |
greenroshks | 1:5a364ac20fa4 | 281 | |
greenroshks | 0:f1f148215d00 | 282 | } |
greenroshks | 0:f1f148215d00 | 283 | |
greenroshks | 0:f1f148215d00 | 284 | void keypress(void const *args) |
greenroshks | 0:f1f148215d00 | 285 | { |
greenroshks | 0:f1f148215d00 | 286 | |
greenroshks | 0:f1f148215d00 | 287 | while(1) |
greenroshks | 0:f1f148215d00 | 288 | { |
greenroshks | 0:f1f148215d00 | 289 | if(pc.getc()=='s') |
greenroshks | 0:f1f148215d00 | 290 | { |
greenroshks | 0:f1f148215d00 | 291 | pc.printf("\nTime of telecommand %f",t.read()); |
greenroshks | 3:307c56629df0 | 292 | beac_flag=1; |
greenroshks | 0:f1f148215d00 | 293 | } |
greenroshks | 0:f1f148215d00 | 294 | } |
greenroshks | 0:f1f148215d00 | 295 | } |
greenroshks | 0:f1f148215d00 | 296 | |
greenroshks | 1:5a364ac20fa4 | 297 | |
greenroshks | 2:1792c9cda669 | 298 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 2:1792c9cda669 | 299 | //TASK 4 : FAULT MANAGEMENT |
greenroshks | 2:1792c9cda669 | 300 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 2:1792c9cda669 | 301 | //Dummy fault rectifier functions |
greenroshks | 2:1792c9cda669 | 302 | |
greenroshks | 2:1792c9cda669 | 303 | Mail<int,16> faults; |
greenroshks | 2:1792c9cda669 | 304 | |
greenroshks | 2:1792c9cda669 | 305 | void FUNC_FAULT_FUNCT1() |
greenroshks | 2:1792c9cda669 | 306 | { |
greenroshks | 2:1792c9cda669 | 307 | pc.printf("\nFault 1 detected... \n"); |
greenroshks | 2:1792c9cda669 | 308 | } |
greenroshks | 2:1792c9cda669 | 309 | |
greenroshks | 2:1792c9cda669 | 310 | void FUNC_FAULT_FUNCT2() |
greenroshks | 2:1792c9cda669 | 311 | { |
greenroshks | 2:1792c9cda669 | 312 | pc.printf("\nFault 2 detected...\n"); |
greenroshks | 2:1792c9cda669 | 313 | } |
greenroshks | 2:1792c9cda669 | 314 | |
greenroshks | 2:1792c9cda669 | 315 | void T_FAULT(void const *args) |
greenroshks | 2:1792c9cda669 | 316 | { |
greenroshks | 2:1792c9cda669 | 317 | while(1) |
greenroshks | 2:1792c9cda669 | 318 | { |
greenroshks | 2:1792c9cda669 | 319 | osEvent evt = faults.get(); |
greenroshks | 2:1792c9cda669 | 320 | if(evt.status==osEventMail) |
greenroshks | 2:1792c9cda669 | 321 | { |
greenroshks | 2:1792c9cda669 | 322 | int *fault_id= (int *)evt.value.p; |
greenroshks | 2:1792c9cda669 | 323 | switch(*fault_id) |
greenroshks | 2:1792c9cda669 | 324 | { |
greenroshks | 2:1792c9cda669 | 325 | case 1: FUNC_FAULT_FUNCT1(); |
greenroshks | 2:1792c9cda669 | 326 | break; |
greenroshks | 2:1792c9cda669 | 327 | case 2: FUNC_FAULT_FUNCT2(); |
greenroshks | 2:1792c9cda669 | 328 | break; |
greenroshks | 2:1792c9cda669 | 329 | } |
greenroshks | 2:1792c9cda669 | 330 | faults.free(fault_id); |
greenroshks | 2:1792c9cda669 | 331 | } |
greenroshks | 2:1792c9cda669 | 332 | } |
greenroshks | 2:1792c9cda669 | 333 | } |
greenroshks | 2:1792c9cda669 | 334 | |
greenroshks | 2:1792c9cda669 | 335 | //---------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 2:1792c9cda669 | 336 | //Scheduler |
greenroshks | 2:1792c9cda669 | 337 | //---------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 3:307c56629df0 | 338 | uint16_t schedcount=1; //the value will reset to 0 after reaching 65535 which again will reset to 0. |
greenroshks | 1:5a364ac20fa4 | 339 | void scheduler(void const * args) |
greenroshks | 1:5a364ac20fa4 | 340 | { |
greenroshks | 3:307c56629df0 | 341 | 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. |
greenroshks | 3:307c56629df0 | 342 | { |
greenroshks | 3:307c56629df0 | 343 | schedcount =0; |
greenroshks | 3:307c56629df0 | 344 | } |
greenroshks | 2:1792c9cda669 | 345 | if(schedcount == 7) |
greenroshks | 2:1792c9cda669 | 346 | { |
greenroshks | 2:1792c9cda669 | 347 | int * fault_id = faults.alloc(); |
greenroshks | 2:1792c9cda669 | 348 | *fault_id = 1; |
greenroshks | 2:1792c9cda669 | 349 | faults.put(fault_id); |
greenroshks | 2:1792c9cda669 | 350 | } |
greenroshks | 1:5a364ac20fa4 | 351 | t_acs->signal_set(0x1); |
greenroshks | 1:5a364ac20fa4 | 352 | |
greenroshks | 1:5a364ac20fa4 | 353 | if(schedcount%2==0) |
greenroshks | 1:5a364ac20fa4 | 354 | { |
greenroshks | 2:1792c9cda669 | 355 | //pc.printf("\nHK signal at %f",t.read()); |
greenroshks | 1:5a364ac20fa4 | 356 | t_hk_acq->signal_set(0x1); |
greenroshks | 1:5a364ac20fa4 | 357 | |
greenroshks | 1:5a364ac20fa4 | 358 | } |
greenroshks | 1:5a364ac20fa4 | 359 | if(schedcount%3==0) |
greenroshks | 1:5a364ac20fa4 | 360 | { |
greenroshks | 2:1792c9cda669 | 361 | //pc.printf("\nBeacon signal at %f",t.read()); |
greenroshks | 1:5a364ac20fa4 | 362 | t_bea->signal_set(0x1); |
greenroshks | 1:5a364ac20fa4 | 363 | |
greenroshks | 1:5a364ac20fa4 | 364 | } |
greenroshks | 1:5a364ac20fa4 | 365 | schedcount++; |
greenroshks | 1:5a364ac20fa4 | 366 | } |
greenroshks | 1:5a364ac20fa4 | 367 | |
greenroshks | 0:f1f148215d00 | 368 | |
greenroshks | 0:f1f148215d00 | 369 | /*----------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:f1f148215d00 | 370 | MAIN |
greenroshks | 0:f1f148215d00 | 371 | -----------------------------------------------------------------------------------------------------------------------------------------------------*/ |
greenroshks | 0:f1f148215d00 | 372 | int main() |
greenroshks | 0:f1f148215d00 | 373 | { |
greenroshks | 0:f1f148215d00 | 374 | t.start(); |
greenroshks | 2:1792c9cda669 | 375 | |
greenroshks | 1:5a364ac20fa4 | 376 | t_acs = new Thread(T_ACS_MAIN); |
greenroshks | 0:f1f148215d00 | 377 | t_bea = new Thread(T_BEA); |
greenroshks | 0:f1f148215d00 | 378 | t_hk_acq = new Thread(T_HK_ACQ); |
greenroshks | 0:f1f148215d00 | 379 | t_acs_write2flash = new Thread(T_ACS_WRITE2FLASH); |
greenroshks | 0:f1f148215d00 | 380 | Thread key(keypress); |
greenroshks | 2:1792c9cda669 | 381 | t_fault = new Thread(T_FAULT); |
greenroshks | 2:1792c9cda669 | 382 | t_hk_write2cdms = new Thread(T_HK_SEND2CDMS); |
greenroshks | 1:5a364ac20fa4 | 383 | |
greenroshks | 2:1792c9cda669 | 384 | t_fault->set_priority(osPriorityRealtime); |
greenroshks | 2:1792c9cda669 | 385 | t_acs->set_priority(osPriorityHigh); |
greenroshks | 0:f1f148215d00 | 386 | t_bea->set_priority(osPriorityAboveNormal); |
greenroshks | 0:f1f148215d00 | 387 | t_hk_acq->set_priority(osPriorityNormal); |
greenroshks | 0:f1f148215d00 | 388 | t_acs_write2flash->set_priority(osPriorityBelowNormal); |
greenroshks | 2:1792c9cda669 | 389 | |
greenroshks | 0:f1f148215d00 | 390 | key.set_priority(osPriorityIdle); |
greenroshks | 0:f1f148215d00 | 391 | |
greenroshks | 2:1792c9cda669 | 392 | |
greenroshks | 1:5a364ac20fa4 | 393 | /*RtosTimer t_hk_timer(T_HK_ACQ,osTimerPeriodic); |
greenroshks | 1:5a364ac20fa4 | 394 | RtosTimer t_bea_timer(T_BEA,osTimerPeriodic); |
greenroshks | 1:5a364ac20fa4 | 395 | RtosTimer t_acs_timer(T_ACS_MAIN,osTimerPeriodic); |
greenroshks | 1:5a364ac20fa4 | 396 | |
greenroshks | 1:5a364ac20fa4 | 397 | t_hk_timer.start(10000); |
greenroshks | 1:5a364ac20fa4 | 398 | t_bea_timer.start(20000); |
greenroshks | 1:5a364ac20fa4 | 399 | t_acs_timer.start(30000);*/ |
greenroshks | 1:5a364ac20fa4 | 400 | |
greenroshks | 1:5a364ac20fa4 | 401 | RtosTimer schedule(scheduler,osTimerPeriodic); |
greenroshks | 1:5a364ac20fa4 | 402 | schedule.start(10000); |
greenroshks | 1:5a364ac20fa4 | 403 | t_hk_write2cdms->set_priority(osPriorityLow); |
greenroshks | 1:5a364ac20fa4 | 404 | pc.printf("\n T_HK_SEND2CDMS priority is %d",t_hk_write2cdms->get_priority()); |
greenroshks | 2:1792c9cda669 | 405 | pc.printf("\n T_ACS priority is %d",t_acs->get_priority()); |
greenroshks | 2:1792c9cda669 | 406 | pc.printf("\n T_FAULTS priority is %d",t_fault->get_priority()); |
greenroshks | 2:1792c9cda669 | 407 | |
greenroshks | 0:f1f148215d00 | 408 | while(1) |
greenroshks | 0:f1f148215d00 | 409 | { |
greenroshks | 1:5a364ac20fa4 | 410 | /*if(i%10==0) |
greenroshks | 0:f1f148215d00 | 411 | { |
greenroshks | 0:f1f148215d00 | 412 | t_acs->signal_set(0x1); |
greenroshks | 0:f1f148215d00 | 413 | pc.printf("Priority of t_hk_write2cdms is %d and t_acs_write2flash is %d",t_hk_write2cdms->get_priority(),t_acs_write2flash->get_priority()); |
greenroshks | 0:f1f148215d00 | 414 | } |
greenroshks | 0:f1f148215d00 | 415 | if(i%20==0) |
greenroshks | 0:f1f148215d00 | 416 | t_hk_acq->signal_set(0x1); |
greenroshks | 0:f1f148215d00 | 417 | if(i%30==0) |
greenroshks | 0:f1f148215d00 | 418 | t_bea->signal_set(0x1); |
greenroshks | 1:5a364ac20fa4 | 419 | |
greenroshks | 1:5a364ac20fa4 | 420 | i++;*/ |
greenroshks | 1:5a364ac20fa4 | 421 | Thread::wait(1000); |
greenroshks | 2:1792c9cda669 | 422 | |
greenroshks | 2:1792c9cda669 | 423 | // pc.printf("\n%f\n",t.read()); |
greenroshks | 0:f1f148215d00 | 424 | } |
greenroshks | 0:f1f148215d00 | 425 | } |