Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Committer:
chaithanyarss
Date:
Sun Jan 22 04:47:11 2017 +0000
Revision:
351:a89a46894ec0
Parent:
346:204497974293
EERPOM and BCN done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aniruddhv 52:0bd68655c651 1 #define tm_len 134
aniruddhv 52:0bd68655c651 2 #define tc_len 135
aniruddhv 52:0bd68655c651 3 #define tc_test_len 135
aniruddhv 52:0bd68655c651 4
aniruddhv 52:0bd68655c651 5 const int addr = 0x20; //slave address
ee12b079 161:a63672bf4423 6 bool write_ack = false;
ee12b079 161:a63672bf4423 7 bool read_ack = false;
ee12b079 161:a63672bf4423 8 const int addr_pl = 0x20<<1; //PL address
ee12b079 162:48fda0b8d573 9 const int addr_bae = 0x20; ///bae address
ee12b079 209:63e9c8f8b5d2 10 //uint8_t rcv_isr = 0;
aniruddhv 52:0bd68655c651 11
aniruddhv 52:0bd68655c651 12 int count = 0;
aniruddhv 52:0bd68655c651 13
ee12b079 161:a63672bf4423 14 char PL_I2C_DATA[134];//Payload i2c array
ee12b079 161:a63672bf4423 15 uint8_t PL_TM_SIZE;//size of data to bev read from i2c
ee12b079 209:63e9c8f8b5d2 16 uint32_t pdirr1;
ee12b079 209:63e9c8f8b5d2 17 uint32_t pdirw1;
aniruddhv 52:0bd68655c651 18
ee12b079 209:63e9c8f8b5d2 19 void I2C_busreset()
ee12b079 209:63e9c8f8b5d2 20 {
ee12b079 209:63e9c8f8b5d2 21 PORTE->PCR[1] &= 0xfffffffb; //Enabling high slew rates for SDA and SCL lines
ee12b079 209:63e9c8f8b5d2 22 PORTE->PCR[0] &= 0xfffffffb; //Enabling high slew rates for SDA and SCL lines
ee12b079 209:63e9c8f8b5d2 23 I2C0->C1 &= 0x7f; //Disabling I2C module
ee12b079 209:63e9c8f8b5d2 24 SIM->SCGC4 &= 0xffffffbf; //Disabling clock to I2C module
ee12b079 209:63e9c8f8b5d2 25 SIM->SCGC4 |= 0x00000040; //Enabling clock to I2C module
ee12b079 209:63e9c8f8b5d2 26 I2C0->C1 |= 0x80; //Enabling I2C module
ee12b079 209:63e9c8f8b5d2 27 PORTE->PCR[1] |= 0x00000004; //Disabling high slew rates for SDA and SCL lines
ee12b079 209:63e9c8f8b5d2 28 PORTE->PCR[0] |= 0x00000004; //Disabling high slew rates for SDA and SCL lines
ee12b079 209:63e9c8f8b5d2 29 Thread::wait(1); //Wait for all I2C registers to be updates to their their values
ee12b079 209:63e9c8f8b5d2 30 }
ee12b079 209:63e9c8f8b5d2 31 bool FCTN_I2C_READ_PL(char *data,int length) // Returns 0 for success
ee12b079 209:63e9c8f8b5d2 32 {
ee12b079 209:63e9c8f8b5d2 33 PL_I2C_GPIO = 1;
ee12b079 184:d75cea6f5d49 34 read_ack = master.read(addr_pl|1,data,length);
ee12b079 209:63e9c8f8b5d2 35 Thread::wait(1); //as per tests Thread::wait not required on master side. But its safe to give 1ms
ee12b079 209:63e9c8f8b5d2 36 pdirr1=PTE->PDIR;
ee12b079 209:63e9c8f8b5d2 37 uint8_t i2c_count = 0;
ee12b079 209:63e9c8f8b5d2 38 if(read_ack == 0) //if read_ack says success, it may or may not be successful.Hence we check SCL and SDA
ee12b079 209:63e9c8f8b5d2 39 {
ee12b079 209:63e9c8f8b5d2 40 while(((pdirr1 & 0x03000000)!=0x03000000)&& i2c_count<10)//checking SCL and SDA for time=10ms
ee12b079 209:63e9c8f8b5d2 41 {
ee12b079 209:63e9c8f8b5d2 42 Thread::wait(1);
ee12b079 209:63e9c8f8b5d2 43 pdirr1=PTE->PDIR;
ee12b079 209:63e9c8f8b5d2 44 i2c_count++;
ee12b079 209:63e9c8f8b5d2 45 }
ee12b079 209:63e9c8f8b5d2 46 if(((pdirr1 & 0x03000000)==0x03000000))//if SCL and SDA are both high
ee12b079 209:63e9c8f8b5d2 47 {
chaithanyarss 290:3159ff1081a2 48 gPC.printf("\n\rData received from PL");
ee12b079 209:63e9c8f8b5d2 49 }
ee12b079 209:63e9c8f8b5d2 50 else
ee12b079 209:63e9c8f8b5d2 51 {
ee12b079 209:63e9c8f8b5d2 52 I2C_busreset();
ee12b079 209:63e9c8f8b5d2 53 read_ack = 1;
ee12b079 209:63e9c8f8b5d2 54 }
ee12b079 209:63e9c8f8b5d2 55 }
ee12b079 209:63e9c8f8b5d2 56 else if (read_ack == 1)
ee12b079 184:d75cea6f5d49 57 {
chaithanyarss 303:b49b486a7107 58 CDMS_I2C_ERR_SPEED_COUNTER++;
ee12b079 209:63e9c8f8b5d2 59 I2C_busreset();
ee12b079 184:d75cea6f5d49 60 }
samp1234 346:204497974293 61
ee12b079 209:63e9c8f8b5d2 62 PL_I2C_GPIO = 0;
ee12b079 209:63e9c8f8b5d2 63 i2c_count = 0;
ee12b079 209:63e9c8f8b5d2 64 return read_ack;
ee12b079 209:63e9c8f8b5d2 65
samp1234 346:204497974293 66
ee12b079 184:d75cea6f5d49 67 }
ee12b079 209:63e9c8f8b5d2 68 bool FCTN_I2C_WRITE_PL(char *data2,uint8_t tc_len2) // Returns 0 for success
ee12b079 209:63e9c8f8b5d2 69 {
ee12b079 209:63e9c8f8b5d2 70 write_ack = master.write(addr_pl|0x00,data2,tc_len2);//address to be defined in payload
ee12b079 209:63e9c8f8b5d2 71 Thread::wait(1); //As per the tests Thread::wait is not required on master side but its safe to give 1ms
ee12b079 209:63e9c8f8b5d2 72 pdirw1=PTE->PDIR;
ee12b079 209:63e9c8f8b5d2 73 uint8_t i2c_count = 0;
ee12b079 209:63e9c8f8b5d2 74 if(write_ack == 0)
ee12b079 209:63e9c8f8b5d2 75 {
ee12b079 209:63e9c8f8b5d2 76 while(((pdirw1 & 0x03000000)!=0x03000000)&& i2c_count<10)
ee12b079 209:63e9c8f8b5d2 77 {
ee12b079 209:63e9c8f8b5d2 78 Thread::wait(1);
ee12b079 209:63e9c8f8b5d2 79 pdirw1=PTE->PDIR;
ee12b079 209:63e9c8f8b5d2 80 i2c_count++;
ee12b079 209:63e9c8f8b5d2 81 }
ee12b079 209:63e9c8f8b5d2 82 if(((pdirw1 & 0x03000000)==0x03000000))
ee12b079 209:63e9c8f8b5d2 83 {
ee12b079 209:63e9c8f8b5d2 84 gPC.printf("\n\r Data sent");
ee12b079 209:63e9c8f8b5d2 85 }
ee12b079 209:63e9c8f8b5d2 86 else
ee12b079 209:63e9c8f8b5d2 87 {
ee12b079 209:63e9c8f8b5d2 88 I2C_busreset();
ee12b079 209:63e9c8f8b5d2 89 write_ack = 1;
ee12b079 209:63e9c8f8b5d2 90 }
ee12b079 209:63e9c8f8b5d2 91 }
ee12b079 209:63e9c8f8b5d2 92 if (write_ack == 1)
ee12b079 209:63e9c8f8b5d2 93 {
ee12b079 209:63e9c8f8b5d2 94 I2C_busreset();
chaithanyarss 303:b49b486a7107 95 CDMS_I2C_ERR_SPEED_COUNTER++;
ee12b079 209:63e9c8f8b5d2 96 }
ee12b079 209:63e9c8f8b5d2 97 i2c_count = 0;
ee12b079 209:63e9c8f8b5d2 98 return write_ack;
ee12b079 209:63e9c8f8b5d2 99 }
ee12b079 209:63e9c8f8b5d2 100 bool FCTN_I2C_READ(char *data,int length) // Returns 0 for success
ee12b079 162:48fda0b8d573 101 {
samp1234 346:204497974293 102 // gPC.printf("i2C_rd\r\n");
ee12b079 162:48fda0b8d573 103 CDMS_I2C_GPIO = 1;
ee12b079 162:48fda0b8d573 104 read_ack = master.read(addr_bae|1,data,length);
ee12b079 209:63e9c8f8b5d2 105 Thread::wait(1); //as per tests Thread::wait not required on master side. But its safe to give 1ms
ee12b079 209:63e9c8f8b5d2 106 pdirr1=PTE->PDIR;
ee12b079 209:63e9c8f8b5d2 107 uint8_t i2c_count = 0;
ee12b079 209:63e9c8f8b5d2 108 if(read_ack == 0) //if read_ack says success, it may or may not be successful.Hence we check SCL and SDA
ee12b079 162:48fda0b8d573 109 {
ee12b079 209:63e9c8f8b5d2 110 while(((pdirr1 & 0x03000000)!=0x03000000)&& i2c_count<10)//checking SCL and SDA for time=10ms
ee12b079 209:63e9c8f8b5d2 111 {
ee12b079 209:63e9c8f8b5d2 112 Thread::wait(1);
ee12b079 209:63e9c8f8b5d2 113 pdirr1=PTE->PDIR;
ee12b079 209:63e9c8f8b5d2 114 i2c_count++;
ee12b079 209:63e9c8f8b5d2 115 }
ee12b079 209:63e9c8f8b5d2 116 if(((pdirr1 & 0x03000000)==0x03000000))//if SCL and SDA are both high
ee12b079 209:63e9c8f8b5d2 117 {
chaithanyarss 328:2242ebc71be8 118 //gPC.printf("\n\rData received from BAE");
ee12b079 209:63e9c8f8b5d2 119 }
ee12b079 209:63e9c8f8b5d2 120 else
ee12b079 209:63e9c8f8b5d2 121 {
ee12b079 209:63e9c8f8b5d2 122 I2C_busreset();
ee12b079 209:63e9c8f8b5d2 123 read_ack = 1;
ee12b079 209:63e9c8f8b5d2 124 }
ee12b079 162:48fda0b8d573 125 }
ee12b079 209:63e9c8f8b5d2 126 else if (read_ack == 1)
ee12b079 209:63e9c8f8b5d2 127 {
ee12b079 209:63e9c8f8b5d2 128 I2C_busreset();
chaithanyarss 303:b49b486a7107 129 CDMS_I2C_ERR_BAE_COUNTER++;
chaithanyarss 303:b49b486a7107 130
ee12b079 209:63e9c8f8b5d2 131 }
samp1234 346:204497974293 132 // gPC.printf("end_12c_RD_\r\n");
ee12b079 162:48fda0b8d573 133 CDMS_I2C_GPIO = 0;
ee12b079 209:63e9c8f8b5d2 134 i2c_count = 0;
ee12b079 198:17200a427e71 135 return read_ack;
ee12b079 162:48fda0b8d573 136 }
ee12b079 162:48fda0b8d573 137
ee12b079 209:63e9c8f8b5d2 138 bool FCTN_I2C_WRITE(char *data,int tc_len2) // Returns 0 for success
ee12b079 209:63e9c8f8b5d2 139 {
samp1234 346:204497974293 140 // gPC.printf("i2C_wr\r\n");
ee12b079 162:48fda0b8d573 141 CDMS_I2C_GPIO = 1;
ee12b079 209:63e9c8f8b5d2 142 write_ack = master.write(addr_bae|0x00,data,tc_len2);
ee12b079 209:63e9c8f8b5d2 143 Thread::wait(1); //As per the tests Thread::wait is not required on master side but its safe to give 1ms
ee12b079 209:63e9c8f8b5d2 144 pdirw1=PTE->PDIR;
ee12b079 209:63e9c8f8b5d2 145 uint8_t i2c_count = 0;
ee12b079 209:63e9c8f8b5d2 146 if(write_ack == 0)
ee12b079 162:48fda0b8d573 147 {
ee12b079 209:63e9c8f8b5d2 148 while(((pdirw1 & 0x03000000)!=0x03000000)&& i2c_count<10)
ee12b079 209:63e9c8f8b5d2 149 {
ee12b079 209:63e9c8f8b5d2 150 Thread::wait(1);
ee12b079 209:63e9c8f8b5d2 151 pdirw1=PTE->PDIR;
ee12b079 209:63e9c8f8b5d2 152 i2c_count++;
ee12b079 209:63e9c8f8b5d2 153 }
ee12b079 209:63e9c8f8b5d2 154 if(((pdirw1 & 0x03000000)==0x03000000))
ee12b079 209:63e9c8f8b5d2 155 {
chaithanyarss 328:2242ebc71be8 156 //gPC.printf("\n\r Data sent");
ee12b079 209:63e9c8f8b5d2 157 }
ee12b079 209:63e9c8f8b5d2 158 else
ee12b079 209:63e9c8f8b5d2 159 {
ee12b079 209:63e9c8f8b5d2 160 I2C_busreset();
ee12b079 209:63e9c8f8b5d2 161 write_ack = 1;
ee12b079 209:63e9c8f8b5d2 162 }
ee12b079 209:63e9c8f8b5d2 163 }
ee12b079 209:63e9c8f8b5d2 164 if (write_ack == 1)
ee12b079 209:63e9c8f8b5d2 165 {
ee12b079 209:63e9c8f8b5d2 166 I2C_busreset();
chaithanyarss 303:b49b486a7107 167 CDMS_I2C_ERR_BAE_COUNTER++;
ee12b079 162:48fda0b8d573 168 }
samp1234 346:204497974293 169 // gPC.printf("i2C_wr_end\r\n");
ee12b079 162:48fda0b8d573 170 CDMS_I2C_GPIO = 0;
ee12b079 209:63e9c8f8b5d2 171 i2c_count = 0;
ee12b079 209:63e9c8f8b5d2 172 return write_ack;
aniruddhv 52:0bd68655c651 173 }