CDMS_CODE_samp_23SEP_DMA_flag
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE_samp_23SEP_DMA by
adf.h@71:9193fbdaa3e1, 2016-01-19 (annotated)
- Committer:
- krishanprajapat
- Date:
- Tue Jan 19 10:30:46 2016 +0000
- Revision:
- 71:9193fbdaa3e1
- Parent:
- 53:18db568f1098
Modification of CDMS_sd.h required
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shreeshas95 | 1:a0055b3280c8 | 1 | //without reset feature , with state checks. |
shreeshas95 | 2:2caf2a9a13aa | 2 | InterruptIn IRQ(ADF_IRQ); |
aniruddhv | 52:0bd68655c651 | 3 | //Ticker ticker; |
ee12b079 | 9:e9eaada136c6 | 4 | |
shreeshas95 | 1:a0055b3280c8 | 5 | bool sent_tmfrom_SDcard; |
krishanprajapat | 71:9193fbdaa3e1 | 6 | //bool loop_on; |
shreeshas95 | 1:a0055b3280c8 | 7 | bool ADF_off; |
shreeshas95 | 1:a0055b3280c8 | 8 | bool buffer_state; |
ee12b079 | 9:e9eaada136c6 | 9 | bool finish_write_data; |
shreeshas95 | 1:a0055b3280c8 | 10 | uint8_t signal = 0x00; |
shreeshas95 | 1:a0055b3280c8 | 11 | unsigned char bbram_buffer[66]={0x19,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0xF4,0xC2,0x10,0xC0,0x00,0x30,0x31,0x07,0x00,0x01,0x00,0x7F,0x00,0x0B,0x37,0x00,0x00,0x40,0x0C,0x00,0x05,0x00,0x00,0x18,0x12,0x34,0x56,0x10,0x10,0xC4,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00}; |
ee12b079 | 9:e9eaada136c6 | 12 | |
shreeshas95 | 2:2caf2a9a13aa | 13 | //int initialise_card(); |
shreeshas95 | 2:2caf2a9a13aa | 14 | //int disk_initialize(); |
ee12b079 | 9:e9eaada136c6 | 15 | |
shreeshas95 | 1:a0055b3280c8 | 16 | #define bbram_write {\ |
shreeshas95 | 1:a0055b3280c8 | 17 | SPI_mutex.lock();\ |
shreeshas95 | 1:a0055b3280c8 | 18 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 19 | spi.write(0xB0);\ |
shreeshas95 | 1:a0055b3280c8 | 20 | wait_us(300);\ |
shreeshas95 | 1:a0055b3280c8 | 21 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 22 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 23 | for(int i=0;i<66;i++){\ |
shreeshas95 | 1:a0055b3280c8 | 24 | spi.write(bbram_buffer[i]);\ |
shreeshas95 | 1:a0055b3280c8 | 25 | }\ |
shreeshas95 | 1:a0055b3280c8 | 26 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 27 | SPI_mutex.unlock();\ |
shreeshas95 | 1:a0055b3280c8 | 28 | } |
shreeshas95 | 1:a0055b3280c8 | 29 | //------------------------------------------------------------------------ |
shreeshas95 | 1:a0055b3280c8 | 30 | // state checking functions |
shreeshas95 | 1:a0055b3280c8 | 31 | //bool assrt_phy_off( int, int, int); |
shreeshas95 | 1:a0055b3280c8 | 32 | //bool assrt_phy_on( int,int,int); |
shreeshas95 | 1:a0055b3280c8 | 33 | //bool assrt_phy_tx(int,int,int); |
ee12b079 | 9:e9eaada136c6 | 34 | |
shreeshas95 | 1:a0055b3280c8 | 35 | #define START_ADDRESS 0x020; |
shreeshas95 | 1:a0055b3280c8 | 36 | #define MISO_PIN PTE3 |
shreeshas95 | 1:a0055b3280c8 | 37 | /**************Defining Counter Limits**************/ |
shreeshas95 | 1:a0055b3280c8 | 38 | #define THRS 20 |
shreeshas95 | 1:a0055b3280c8 | 39 | #define STATE_ERR_THRS 20 |
shreeshas95 | 1:a0055b3280c8 | 40 | #define PHY_OFF_EXEC_TIME 300 |
shreeshas95 | 1:a0055b3280c8 | 41 | #define PHY_ON_EXEC_TIME 300 |
shreeshas95 | 1:a0055b3280c8 | 42 | #define PHY_TX_EXEC_TIME 600 |
shreeshas95 | 1:a0055b3280c8 | 43 | /******DEFINING COMMANDS*********/ |
shreeshas95 | 1:a0055b3280c8 | 44 | #define CMD_HW_RESET 0xC8 |
shreeshas95 | 1:a0055b3280c8 | 45 | #define CMD_PHY_ON 0xB1 |
shreeshas95 | 1:a0055b3280c8 | 46 | #define CMD_PHY_OFF 0xB0 |
shreeshas95 | 1:a0055b3280c8 | 47 | #define CMD_PHY_TX 0xB5 |
shreeshas95 | 1:a0055b3280c8 | 48 | #define CMD_CONFIG_DEV 0xBB |
ee12b079 | 9:e9eaada136c6 | 49 | |
shreeshas95 | 1:a0055b3280c8 | 50 | #define check_status {\ |
shreeshas95 | 1:a0055b3280c8 | 51 | unsigned char stat=0;\ |
shreeshas95 | 1:a0055b3280c8 | 52 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 53 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 54 | stat = spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 55 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 56 | status = stat;\ |
shreeshas95 | 1:a0055b3280c8 | 57 | } |
ee12b079 | 9:e9eaada136c6 | 58 | |
shreeshas95 | 1:a0055b3280c8 | 59 | // all three arguments are int |
shreeshas95 | 1:a0055b3280c8 | 60 | #define assrt_phy_off(return_this) {\ |
shreeshas95 | 1:a0055b3280c8 | 61 | int cmd_err_cnt = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 62 | int spi_err_cnt = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 63 | int state_err_cnt = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 64 | for(int i = 0 ; i < 40 ;i++){\ |
shreeshas95 | 1:a0055b3280c8 | 65 | check_status;\ |
shreeshas95 | 1:a0055b3280c8 | 66 | if(status == 0xB1){\ |
shreeshas95 | 1:a0055b3280c8 | 67 | return_this = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 68 | break;\ |
shreeshas95 | 1:a0055b3280c8 | 69 | }\ |
shreeshas95 | 1:a0055b3280c8 | 70 | else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){\ |
shreeshas95 | 1:a0055b3280c8 | 71 | return_this = 1;\ |
shreeshas95 | 1:a0055b3280c8 | 72 | break;\ |
shreeshas95 | 1:a0055b3280c8 | 73 | }\ |
shreeshas95 | 1:a0055b3280c8 | 74 | else if(state_err_cnt>STATE_ERR_THRS){\ |
shreeshas95 | 1:a0055b3280c8 | 75 | return_this = 1;\ |
shreeshas95 | 1:a0055b3280c8 | 76 | break;\ |
shreeshas95 | 1:a0055b3280c8 | 77 | }\ |
shreeshas95 | 1:a0055b3280c8 | 78 | else if( (status & 0xA0) == 0xA0 ){\ |
shreeshas95 | 1:a0055b3280c8 | 79 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 80 | spi.write(CMD_PHY_OFF);\ |
shreeshas95 | 1:a0055b3280c8 | 81 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 82 | wait_us(PHY_OFF_EXEC_TIME);\ |
shreeshas95 | 1:a0055b3280c8 | 83 | state_err_cnt++;\ |
shreeshas95 | 1:a0055b3280c8 | 84 | }\ |
shreeshas95 | 1:a0055b3280c8 | 85 | else if(status&0x80==0x00){\ |
shreeshas95 | 1:a0055b3280c8 | 86 | wait_ms(5);\ |
shreeshas95 | 1:a0055b3280c8 | 87 | spi_err_cnt++;\ |
shreeshas95 | 1:a0055b3280c8 | 88 | }\ |
shreeshas95 | 1:a0055b3280c8 | 89 | else {\ |
shreeshas95 | 1:a0055b3280c8 | 90 | wait_ms(1);\ |
shreeshas95 | 1:a0055b3280c8 | 91 | cmd_err_cnt++;\ |
shreeshas95 | 1:a0055b3280c8 | 92 | }\ |
shreeshas95 | 1:a0055b3280c8 | 93 | }\ |
shreeshas95 | 1:a0055b3280c8 | 94 | } |
ee12b079 | 9:e9eaada136c6 | 95 | |
ee12b079 | 9:e9eaada136c6 | 96 | |
shreeshas95 | 1:a0055b3280c8 | 97 | #define initial_adf_check {\ |
shreeshas95 | 1:a0055b3280c8 | 98 | spi.write(CMD_PHY_OFF);\ |
shreeshas95 | 1:a0055b3280c8 | 99 | int tempReturn = 0;\ |
shreeshas95 | 2:2caf2a9a13aa | 100 | bool flag = false;\ |
shreeshas95 | 1:a0055b3280c8 | 101 | while( hw_reset_err_cnt < 2 ){\ |
shreeshas95 | 1:a0055b3280c8 | 102 | assrt_phy_off( tempReturn);\ |
shreeshas95 | 1:a0055b3280c8 | 103 | if( !tempReturn ){\ |
shreeshas95 | 1:a0055b3280c8 | 104 | bbram_write;\ |
shreeshas95 | 1:a0055b3280c8 | 105 | bbram_flag=1;\ |
shreeshas95 | 2:2caf2a9a13aa | 106 | flag = true;\ |
shreeshas95 | 1:a0055b3280c8 | 107 | break;\ |
shreeshas95 | 1:a0055b3280c8 | 108 | }\ |
shreeshas95 | 1:a0055b3280c8 | 109 | else{\ |
shreeshas95 | 1:a0055b3280c8 | 110 | hardware_reset(0);\ |
shreeshas95 | 1:a0055b3280c8 | 111 | hw_reset_err_cnt++;\ |
shreeshas95 | 2:2caf2a9a13aa | 112 | gPC.puts("Resetting hardware\r\n");\ |
shreeshas95 | 1:a0055b3280c8 | 113 | }\ |
shreeshas95 | 1:a0055b3280c8 | 114 | }\ |
shreeshas95 | 2:2caf2a9a13aa | 115 | if( flag == false ){\ |
shreeshas95 | 2:2caf2a9a13aa | 116 | gPC.puts("Seems to be SPI problem\r\n");\ |
shreeshas95 | 2:2caf2a9a13aa | 117 | }\ |
shreeshas95 | 1:a0055b3280c8 | 118 | assrt_phy_off(tempReturn);\ |
shreeshas95 | 1:a0055b3280c8 | 119 | if(!bbram_flag){\ |
shreeshas95 | 1:a0055b3280c8 | 120 | bcn_flag=1;\ |
shreeshas95 | 1:a0055b3280c8 | 121 | }\ |
shreeshas95 | 1:a0055b3280c8 | 122 | } |
ee12b079 | 9:e9eaada136c6 | 123 | |
shreeshas95 | 1:a0055b3280c8 | 124 | unsigned char status =0; |
shreeshas95 | 1:a0055b3280c8 | 125 | unsigned int cmd_err_cnt=0; |
shreeshas95 | 1:a0055b3280c8 | 126 | unsigned int state_err_cnt=0; |
shreeshas95 | 1:a0055b3280c8 | 127 | unsigned int miso_err_cnt=0; |
shreeshas95 | 1:a0055b3280c8 | 128 | unsigned int hw_reset_err_cnt=0; |
shreeshas95 | 1:a0055b3280c8 | 129 | bool bcn_flag=0; |
shreeshas95 | 1:a0055b3280c8 | 130 | bool bbram_flag=0; |
ee12b079 | 9:e9eaada136c6 | 131 | |
shreeshas95 | 1:a0055b3280c8 | 132 | bool hardware_reset(int bcn_call){ |
shreeshas95 | 1:a0055b3280c8 | 133 | for(int i= 0; i < 20 ; i++){ |
shreeshas95 | 1:a0055b3280c8 | 134 | gCS_ADF=0; |
shreeshas95 | 1:a0055b3280c8 | 135 | spi.write(CMD_HW_RESET); |
shreeshas95 | 1:a0055b3280c8 | 136 | gCS_ADF=1; |
shreeshas95 | 1:a0055b3280c8 | 137 | wait_ms(2);// Typically 1 ms |
shreeshas95 | 1:a0055b3280c8 | 138 | int count=0; |
shreeshas95 | 1:a0055b3280c8 | 139 | int temp_return = 0; |
shreeshas95 | 1:a0055b3280c8 | 140 | while(count<10 && miso_err_cnt<10){ |
shreeshas95 | 1:a0055b3280c8 | 141 | if(MISO_PIN){ |
shreeshas95 | 1:a0055b3280c8 | 142 | assrt_phy_off(temp_return); |
shreeshas95 | 1:a0055b3280c8 | 143 | if(!temp_return){ |
shreeshas95 | 1:a0055b3280c8 | 144 | return 0; |
shreeshas95 | 1:a0055b3280c8 | 145 | } |
shreeshas95 | 1:a0055b3280c8 | 146 | count++; |
shreeshas95 | 1:a0055b3280c8 | 147 | } |
shreeshas95 | 1:a0055b3280c8 | 148 | else{ |
shreeshas95 | 1:a0055b3280c8 | 149 | wait_us(50); |
shreeshas95 | 1:a0055b3280c8 | 150 | miso_err_cnt++; |
shreeshas95 | 1:a0055b3280c8 | 151 | } |
shreeshas95 | 1:a0055b3280c8 | 152 | } |
shreeshas95 | 1:a0055b3280c8 | 153 | } |
shreeshas95 | 1:a0055b3280c8 | 154 | return 1; |
shreeshas95 | 1:a0055b3280c8 | 155 | } |
ee12b079 | 9:e9eaada136c6 | 156 | |
shreeshas95 | 1:a0055b3280c8 | 157 | //for reseting the transmission call assert function after b5 and b1. after b1 assert_phi_on and after b5 assert_phi_tx. |
shreeshas95 | 1:a0055b3280c8 | 158 | //---------------------------------------------------------------------------- |
ee12b079 | 9:e9eaada136c6 | 159 | |
shreeshas95 | 1:a0055b3280c8 | 160 | # define initiate {\ |
shreeshas95 | 1:a0055b3280c8 | 161 | SPI_mutex.lock();\ |
shreeshas95 | 1:a0055b3280c8 | 162 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 163 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 164 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 165 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 166 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 167 | spi.write(0x08);\ |
shreeshas95 | 1:a0055b3280c8 | 168 | spi.write(0x14);\ |
shreeshas95 | 1:a0055b3280c8 | 169 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 170 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 171 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 172 | spi.write(0x08);\ |
shreeshas95 | 1:a0055b3280c8 | 173 | spi.write(0x15);\ |
shreeshas95 | 1:a0055b3280c8 | 174 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 175 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 176 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 177 | spi.write(0x09);\ |
shreeshas95 | 1:a0055b3280c8 | 178 | spi.write(0x24);\ |
shreeshas95 | 1:a0055b3280c8 | 179 | spi.write(0x20);\ |
shreeshas95 | 1:a0055b3280c8 | 180 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 181 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 182 | spi.write(0x09);\ |
shreeshas95 | 1:a0055b3280c8 | 183 | spi.write(0x37);\ |
shreeshas95 | 1:a0055b3280c8 | 184 | spi.write(0xE0);\ |
shreeshas95 | 1:a0055b3280c8 | 185 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 186 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 187 | spi.write(0x09);\ |
shreeshas95 | 1:a0055b3280c8 | 188 | spi.write(0x36);\ |
shreeshas95 | 1:a0055b3280c8 | 189 | spi.write(0x70);\ |
shreeshas95 | 1:a0055b3280c8 | 190 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 191 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 192 | spi.write(0x09);\ |
shreeshas95 | 1:a0055b3280c8 | 193 | spi.write(0x39);\ |
shreeshas95 | 1:a0055b3280c8 | 194 | spi.write(0x10);\ |
shreeshas95 | 1:a0055b3280c8 | 195 | gCS_ADF=1;\ |
ee12b079 | 9:e9eaada136c6 | 196 | gCS_ADF=0;\ |
ee12b079 | 9:e9eaada136c6 | 197 | spi.write(0xBB);\ |
ee12b079 | 9:e9eaada136c6 | 198 | gCS_ADF=1;\ |
ee12b079 | 9:e9eaada136c6 | 199 | gCS_ADF=0;\ |
ee12b079 | 9:e9eaada136c6 | 200 | spi.write(0xFF);\ |
ee12b079 | 9:e9eaada136c6 | 201 | spi.write(0xFF);\ |
ee12b079 | 9:e9eaada136c6 | 202 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 203 | SPI_mutex.unlock();\ |
shreeshas95 | 1:a0055b3280c8 | 204 | } |
ee12b079 | 9:e9eaada136c6 | 205 | |
shreeshas95 | 1:a0055b3280c8 | 206 | #define write_data {\ |
shreeshas95 | 1:a0055b3280c8 | 207 | SPI_mutex.lock();\ |
shreeshas95 | 1:a0055b3280c8 | 208 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 209 | spi.write(0x0B);\ |
shreeshas95 | 1:a0055b3280c8 | 210 | spi.write(0x36);\ |
shreeshas95 | 1:a0055b3280c8 | 211 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 212 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 213 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 214 | if(buffer_state){\ |
shreeshas95 | 1:a0055b3280c8 | 215 | spi.write(0x18);\ |
shreeshas95 | 1:a0055b3280c8 | 216 | spi.write(0x20);\ |
shreeshas95 | 1:a0055b3280c8 | 217 | for(unsigned char i=0; i<112;i++){\ |
shreeshas95 | 1:a0055b3280c8 | 218 | spi.write(buffer_112[i]);\ |
ee12b079 | 53:18db568f1098 | 219 | /*gPC.printf("0x%X,",spi.write(buffer_112[i]));*/\ |
shreeshas95 | 1:a0055b3280c8 | 220 | }\ |
shreeshas95 | 1:a0055b3280c8 | 221 | }\ |
shreeshas95 | 1:a0055b3280c8 | 222 | else{\ |
shreeshas95 | 1:a0055b3280c8 | 223 | spi.write(0x18);\ |
shreeshas95 | 1:a0055b3280c8 | 224 | spi.write(0x90);\ |
shreeshas95 | 1:a0055b3280c8 | 225 | for(unsigned char i=0; i<112;i++){\ |
shreeshas95 | 1:a0055b3280c8 | 226 | spi.write(buffer_112[i]);\ |
ee12b079 | 53:18db568f1098 | 227 | /*gPC.printf("0x%X,",spi.write(buffer_112[i]));*/\ |
shreeshas95 | 1:a0055b3280c8 | 228 | }\ |
shreeshas95 | 1:a0055b3280c8 | 229 | }\ |
shreeshas95 | 1:a0055b3280c8 | 230 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 231 | SPI_mutex.unlock();\ |
shreeshas95 | 1:a0055b3280c8 | 232 | buffer_state = !buffer_state;\ |
shreeshas95 | 1:a0055b3280c8 | 233 | if(last_buffer){\ |
ee12b079 | 9:e9eaada136c6 | 234 | finish_write_data = true;\ |
shreeshas95 | 1:a0055b3280c8 | 235 | gPC.puts("adf_off\r\n");\ |
shreeshas95 | 1:a0055b3280c8 | 236 | }\ |
shreeshas95 | 1:a0055b3280c8 | 237 | } |
shreeshas95 | 1:a0055b3280c8 | 238 | |
aniruddhv | 52:0bd68655c651 | 239 | /* |
shreeshas95 | 1:a0055b3280c8 | 240 | void check(){ |
shreeshas95 | 1:a0055b3280c8 | 241 | if(IRQ){ |
shreeshas95 | 1:a0055b3280c8 | 242 | gCOM_MNG_TMTC_THREAD->signal_set(signal); |
shreeshas95 | 1:a0055b3280c8 | 243 | } |
aniruddhv | 52:0bd68655c651 | 244 | }*/ |
shreeshas95 | 1:a0055b3280c8 | 245 | |
ee12b079 | 9:e9eaada136c6 | 246 | |
shreeshas95 | 1:a0055b3280c8 | 247 | #define send_data {\ |
shreeshas95 | 1:a0055b3280c8 | 248 | if(sent_tmfrom_SDcard){\ |
shreeshas95 | 1:a0055b3280c8 | 249 | send_tm_from_SD_card();\ |
shreeshas95 | 1:a0055b3280c8 | 250 | }else{\ |
shreeshas95 | 1:a0055b3280c8 | 251 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shreeshas95 | 1:a0055b3280c8 | 252 | }\ |
shreeshas95 | 1:a0055b3280c8 | 253 | write_data;\ |
shreeshas95 | 1:a0055b3280c8 | 254 | if(sent_tmfrom_SDcard){\ |
shreeshas95 | 1:a0055b3280c8 | 255 | send_tm_from_SD_card();\ |
shreeshas95 | 1:a0055b3280c8 | 256 | }else{\ |
shreeshas95 | 1:a0055b3280c8 | 257 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shreeshas95 | 1:a0055b3280c8 | 258 | }\ |
shreeshas95 | 1:a0055b3280c8 | 259 | write_data;\ |
shreeshas95 | 1:a0055b3280c8 | 260 | if(sent_tmfrom_SDcard){\ |
shreeshas95 | 1:a0055b3280c8 | 261 | send_tm_from_SD_card();\ |
shreeshas95 | 1:a0055b3280c8 | 262 | }else{\ |
shreeshas95 | 1:a0055b3280c8 | 263 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shreeshas95 | 1:a0055b3280c8 | 264 | }\ |
shreeshas95 | 1:a0055b3280c8 | 265 | SPI_mutex.lock();\ |
shreeshas95 | 1:a0055b3280c8 | 266 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 267 | spi.write(0xB1);\ |
shreeshas95 | 1:a0055b3280c8 | 268 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 269 | wait_us(300);\ |
shreeshas95 | 1:a0055b3280c8 | 270 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 271 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 272 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 273 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 274 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 275 | spi.write(0xB5);\ |
shreeshas95 | 1:a0055b3280c8 | 276 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 277 | wait_us(300);\ |
shreeshas95 | 1:a0055b3280c8 | 278 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 279 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 280 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 281 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 282 | SPI_mutex.unlock();\ |
aniruddhv | 52:0bd68655c651 | 283 | /*ticker.attach_us(&check,32000);*/\ |
shreeshas95 | 1:a0055b3280c8 | 284 | } |
shreeshas95 | 1:a0055b3280c8 | 285 | |
shreeshas95 | 1:a0055b3280c8 | 286 | |
shreeshas95 | 1:a0055b3280c8 | 287 | |
shreeshas95 | 1:a0055b3280c8 | 288 | #define adf_SND_SDCard {\ |
shreeshas95 | 1:a0055b3280c8 | 289 | sent_tmfrom_SDcard = true;\ |
krishanprajapat | 71:9193fbdaa3e1 | 290 | configure_adf;\ |
shreeshas95 | 1:a0055b3280c8 | 291 | signal = COM_MNG_TMTC_SIGNAL_ADF_SD;\ |
shreeshas95 | 1:a0055b3280c8 | 292 | send_data;\ |
shreeshas95 | 1:a0055b3280c8 | 293 | while(loop_on){\ |
shreeshas95 | 2:2caf2a9a13aa | 294 | /*led2=!led2;*/\ |
krishanprajapat | 71:9193fbdaa3e1 | 295 | /*gCOM_MNG_TMTC_THREAD->signal_wait(COM_MNG_TMTC_SIGNAL_ADF_SD);*/\ |
krishanprajapat | 71:9193fbdaa3e1 | 296 | wait_ms(COM_TX_TICKER_LIMIT);\ |
krishanprajapat | 71:9193fbdaa3e1 | 297 | if(IRQ){\ |
krishanprajapat | 71:9193fbdaa3e1 | 298 | if(finish_write_data){\ |
krishanprajapat | 71:9193fbdaa3e1 | 299 | if(ADF_off){\ |
krishanprajapat | 71:9193fbdaa3e1 | 300 | SPI_mutex.lock();\ |
krishanprajapat | 71:9193fbdaa3e1 | 301 | gCS_ADF=0;\ |
krishanprajapat | 71:9193fbdaa3e1 | 302 | spi.write(0xB1);\ |
krishanprajapat | 71:9193fbdaa3e1 | 303 | gCS_ADF=1;\ |
krishanprajapat | 71:9193fbdaa3e1 | 304 | SPI_mutex.unlock();\ |
krishanprajapat | 71:9193fbdaa3e1 | 305 | loop_on = false;\ |
krishanprajapat | 71:9193fbdaa3e1 | 306 | gPC.puts("Transmission done\r\n");\ |
krishanprajapat | 71:9193fbdaa3e1 | 307 | }\ |
krishanprajapat | 71:9193fbdaa3e1 | 308 | else{\ |
krishanprajapat | 71:9193fbdaa3e1 | 309 | ADF_off = true;\ |
krishanprajapat | 71:9193fbdaa3e1 | 310 | }\ |
krishanprajapat | 71:9193fbdaa3e1 | 311 | }else{\ |
krishanprajapat | 71:9193fbdaa3e1 | 312 | write_data;\ |
krishanprajapat | 71:9193fbdaa3e1 | 313 | send_tm_from_SD_card();\ |
krishanprajapat | 71:9193fbdaa3e1 | 314 | }\ |
shreeshas95 | 1:a0055b3280c8 | 315 | }\ |
shreeshas95 | 1:a0055b3280c8 | 316 | }\ |
shreeshas95 | 1:a0055b3280c8 | 317 | } |
shreeshas95 | 1:a0055b3280c8 | 318 | |
krishanprajapat | 71:9193fbdaa3e1 | 319 | //void read_TC(Base_tc* TC_ptr){ |
krishanprajapat | 71:9193fbdaa3e1 | 320 | // gPC.puts("Inside sd card sending\r\n"); |
krishanprajapat | 71:9193fbdaa3e1 | 321 | // unsigned char service_subtype = 0; |
krishanprajapat | 71:9193fbdaa3e1 | 322 | // uint64_t starting_add = 0, ending_add = 0; |
krishanprajapat | 71:9193fbdaa3e1 | 323 | // service_subtype = (TC_ptr->TC_string[2])&0x0f; |
krishanprajapat | 71:9193fbdaa3e1 | 324 | // starting_add = (TC_ptr->TC_string[5]) + ( (TC_ptr->TC_string[4])<<8 ) + ( (TC_ptr->TC_string[3]) <<16); |
krishanprajapat | 71:9193fbdaa3e1 | 325 | // ending_add = (TC_ptr->TC_string[8]) + ( (TC_ptr->TC_string[7])<<8 ) + ( (TC_ptr->TC_string[6]) <<16); |
krishanprajapat | 71:9193fbdaa3e1 | 326 | // starting_add = 10; // for now |
krishanprajapat | 71:9193fbdaa3e1 | 327 | // ending_add = 20; |
krishanprajapat | 71:9193fbdaa3e1 | 328 | //// adf_SND_SDCard(starting_add , ending_add); |
krishanprajapat | 71:9193fbdaa3e1 | 329 | // gPC.puts("sending from sd card\r\n"); |
krishanprajapat | 71:9193fbdaa3e1 | 330 | // adf_SND_SDCard; |
krishanprajapat | 71:9193fbdaa3e1 | 331 | //} |
ee12b079 | 9:e9eaada136c6 | 332 | |
aniruddhv | 52:0bd68655c651 | 333 | #define configure_adf {\ |
aniruddhv | 52:0bd68655c651 | 334 | finish_write_data = false;\ |
aniruddhv | 52:0bd68655c651 | 335 | buffer_state = true;\ |
aniruddhv | 52:0bd68655c651 | 336 | last_buffer = false;\ |
aniruddhv | 52:0bd68655c651 | 337 | loop_on = true;\ |
aniruddhv | 52:0bd68655c651 | 338 | ADF_off = false;\ |
aniruddhv | 52:0bd68655c651 | 339 | initial_adf_check;\ |
aniruddhv | 52:0bd68655c651 | 340 | gPC.puts("initial adf check\r\n");\ |
aniruddhv | 52:0bd68655c651 | 341 | initiate;\ |
aniruddhv | 52:0bd68655c651 | 342 | gPC.puts("adf configured\r\n");\ |
aniruddhv | 52:0bd68655c651 | 343 | gLEDR = !gLEDR;\ |
ee12b079 | 9:e9eaada136c6 | 344 | } |
ee12b079 | 9:e9eaada136c6 | 345 | |
aniruddhv | 52:0bd68655c651 | 346 | #define adf_not_SDcard {\ |
aniruddhv | 52:0bd68655c651 | 347 | sent_tmfrom_SDcard = false;\ |
aniruddhv | 52:0bd68655c651 | 348 | configure_adf;\ |
aniruddhv | 52:0bd68655c651 | 349 | signal = COM_MNG_TMTC_SIGNAL_ADF_NSD;\ |
aniruddhv | 52:0bd68655c651 | 350 | send_data;\ |
aniruddhv | 52:0bd68655c651 | 351 | while(loop_on){\ |
aniruddhv | 52:0bd68655c651 | 352 | wait_ms(COM_TX_TICKER_LIMIT);\ |
aniruddhv | 52:0bd68655c651 | 353 | if(IRQ){\ |
aniruddhv | 52:0bd68655c651 | 354 | if(finish_write_data){\ |
aniruddhv | 52:0bd68655c651 | 355 | if(ADF_off){\ |
aniruddhv | 52:0bd68655c651 | 356 | SPI_mutex.lock();\ |
aniruddhv | 52:0bd68655c651 | 357 | gCS_ADF=0;\ |
aniruddhv | 52:0bd68655c651 | 358 | spi.write(0xB1);\ |
aniruddhv | 52:0bd68655c651 | 359 | gCS_ADF=1;\ |
aniruddhv | 52:0bd68655c651 | 360 | SPI_mutex.unlock();\ |
aniruddhv | 52:0bd68655c651 | 361 | loop_on = false;\ |
aniruddhv | 52:0bd68655c651 | 362 | gPC.puts("Transmission done\r\n");\ |
aniruddhv | 52:0bd68655c651 | 363 | }\ |
aniruddhv | 52:0bd68655c651 | 364 | else{\ |
aniruddhv | 52:0bd68655c651 | 365 | ADF_off = true;\ |
aniruddhv | 52:0bd68655c651 | 366 | }\ |
aniruddhv | 52:0bd68655c651 | 367 | }else{\ |
aniruddhv | 52:0bd68655c651 | 368 | write_data;\ |
aniruddhv | 52:0bd68655c651 | 369 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
aniruddhv | 52:0bd68655c651 | 370 | }\ |
aniruddhv | 52:0bd68655c651 | 371 | }\ |
aniruddhv | 52:0bd68655c651 | 372 | }\ |
aniruddhv | 52:0bd68655c651 | 373 | gPC.puts("after while loop\r\n");\ |
ee12b079 | 53:18db568f1098 | 374 | } |