Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Committer:
chaithanyarss
Date:
Sat Jul 30 15:25:21 2016 +0000
Revision:
282:74a04dec4b95
Parent:
257:7d404e9dc9e2
Child:
297:7cc868888d56
Child:
301:701ac67649b7
testing HK thread Indo MIM

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chaithanyarss 224:3ac1f91e0ebc 1
aniruddhv 52:0bd68655c651 2 void FCTN_CDMS_INIT_RTC()
chaithanyarss 224:3ac1f91e0ebc 3 {
chaithanyarss 282:74a04dec4b95 4 if(EN_RTC == 0)
chaithanyarss 282:74a04dec4b95 5 return;
chaithanyarss 224:3ac1f91e0ebc 6 wait_ms(4000);
ee12b079 93:4d76de54a699 7 SPI_mutex.lock();
aniruddhv 52:0bd68655c651 8 gCS_RTC=1;
aniruddhv 52:0bd68655c651 9 spi.format(8,0);
aniruddhv 52:0bd68655c651 10 spi.frequency(1000000);
chaithanyarss 224:3ac1f91e0ebc 11
chaithanyarss 224:3ac1f91e0ebc 12 //Kick starting the oscillator
chaithanyarss 224:3ac1f91e0ebc 13 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 14 spi.write(0x81); //register address with write flag
chaithanyarss 224:3ac1f91e0ebc 15 spi.write(0x80);//enabling stop bit in the seconds register
chaithanyarss 224:3ac1f91e0ebc 16 gCS_RTC=1;
chaithanyarss 257:7d404e9dc9e2 17
chaithanyarss 257:7d404e9dc9e2 18 gCS_RTC=0;
chaithanyarss 257:7d404e9dc9e2 19 spi.write(0x81);
chaithanyarss 257:7d404e9dc9e2 20 spi.write(0x00);//disabling the stop bit to restart the oscillator
chaithanyarss 257:7d404e9dc9e2 21 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 22
chaithanyarss 224:3ac1f91e0ebc 23 //clearing the halt bit
aniruddhv 52:0bd68655c651 24 gCS_RTC=1;
aniruddhv 52:0bd68655c651 25 gCS_RTC=0;
aniruddhv 52:0bd68655c651 26 spi.write(0x8C);
aniruddhv 52:0bd68655c651 27 spi.write(0x00);
chaithanyarss 224:3ac1f91e0ebc 28 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 29
chaithanyarss 224:3ac1f91e0ebc 30 //clearing the OF bit
aniruddhv 52:0bd68655c651 31 gCS_RTC=0;
aniruddhv 52:0bd68655c651 32 spi.write(0x8F);
aniruddhv 52:0bd68655c651 33 spi.write(0x00);
chaithanyarss 224:3ac1f91e0ebc 34 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 35
aniruddhv 52:0bd68655c651 36 //century bits
aniruddhv 52:0bd68655c651 37 gCS_RTC=0;
aniruddhv 52:0bd68655c651 38 spi.write(0x80|0x03);
aniruddhv 52:0bd68655c651 39 spi.write(0x00);
chaithanyarss 224:3ac1f91e0ebc 40 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 41
ee12b079 209:63e9c8f8b5d2 42 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 43 spi.write(0x80);
ee12b079 245:da9d1bd999da 44 spi.write(0x00); // set milliseconds value to 00
ee12b079 209:63e9c8f8b5d2 45 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 46
ee12b079 209:63e9c8f8b5d2 47 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 48 spi.write(0x81);
ee12b079 245:da9d1bd999da 49 spi.write(0x00); //set seconds value to 00
ee12b079 209:63e9c8f8b5d2 50 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 51
ee12b079 209:63e9c8f8b5d2 52 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 53 spi.write(0x82);
ee12b079 245:da9d1bd999da 54 spi.write(0x00);//set minutes value to 00
ee12b079 209:63e9c8f8b5d2 55 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 56
ee12b079 209:63e9c8f8b5d2 57 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 58 spi.write(0x83);
ee12b079 245:da9d1bd999da 59 spi.write(0x00); //set the hours to 01
ee12b079 209:63e9c8f8b5d2 60 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 61
ee12b079 209:63e9c8f8b5d2 62 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 63 spi.write(0x84);
ee12b079 209:63e9c8f8b5d2 64 spi.write(0x01); //set day of the week to 01
ee12b079 209:63e9c8f8b5d2 65 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 66
ee12b079 209:63e9c8f8b5d2 67 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 68 spi.write(0x85);
ee12b079 245:da9d1bd999da 69 spi.write(0x01); //set date of the month to 01
ee12b079 209:63e9c8f8b5d2 70 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 71
ee12b079 209:63e9c8f8b5d2 72 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 73 spi.write(0x86);
ee12b079 245:da9d1bd999da 74 spi.write(0x01); //set month to 01
ee12b079 209:63e9c8f8b5d2 75 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 76
ee12b079 209:63e9c8f8b5d2 77 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 78 spi.write(0x87);
ee12b079 245:da9d1bd999da 79 spi.write(0x00); //set year to 00(2000)
ee12b079 209:63e9c8f8b5d2 80 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 81 gPC.puts("\n\r rtc initalised \n");
ee12b079 209:63e9c8f8b5d2 82 SPI_mutex.unlock();
ee12b079 209:63e9c8f8b5d2 83 }
chaithanyarss 224:3ac1f91e0ebc 84
ee12b079 209:63e9c8f8b5d2 85 uint64_t FCTN_CDMS_RD_RTC()
chaithanyarss 224:3ac1f91e0ebc 86 {
chaithanyarss 282:74a04dec4b95 87 if(EN_RTC == 0)
chaithanyarss 282:74a04dec4b95 88 return 0;
chaithanyarss 224:3ac1f91e0ebc 89 SPI_mutex.lock();
ee12b079 209:63e9c8f8b5d2 90 uint8_t response;
chaithanyarss 224:3ac1f91e0ebc 91 uint64_t time = 0;
chaithanyarss 224:3ac1f91e0ebc 92
chaithanyarss 224:3ac1f91e0ebc 93 gCS_RTC = 0;
chaithanyarss 224:3ac1f91e0ebc 94 spi.write(0x0F);
chaithanyarss 224:3ac1f91e0ebc 95 response = spi.write(0x00);
chaithanyarss 224:3ac1f91e0ebc 96 //gPC.printf("0x%02X",response);
chaithanyarss 224:3ac1f91e0ebc 97 gCS_RTC = 1;
chaithanyarss 224:3ac1f91e0ebc 98
ee12b079 209:63e9c8f8b5d2 99 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 100 spi.write(0x00); //reading milliseconds register
chaithanyarss 224:3ac1f91e0ebc 101 response = spi.write(0x00); // read the value by sending dummy byte
chaithanyarss 224:3ac1f91e0ebc 102 uint8_t centiseconds = (uint8_t(response&0xF0)>>4)*10+uint8_t(response&0x0F)*1;
aniruddhv 52:0bd68655c651 103
aniruddhv 52:0bd68655c651 104 gCS_RTC=1;
aniruddhv 52:0bd68655c651 105 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 106 spi.write(0x01); //reading seconds register
chaithanyarss 224:3ac1f91e0ebc 107 response =spi.write(0x01);
chaithanyarss 224:3ac1f91e0ebc 108 uint8_t seconds = ((response&0x70)>>4)*10+(response&0x0F)*1;
chaithanyarss 224:3ac1f91e0ebc 109
chaithanyarss 224:3ac1f91e0ebc 110 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 111 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 112 spi.write(0x02); //reading minutes register
chaithanyarss 224:3ac1f91e0ebc 113 response =spi.write(0x01);
chaithanyarss 224:3ac1f91e0ebc 114 uint8_t minutes = ((response&0xF0)>>4)*10+(response&0x0F)*1;
chaithanyarss 224:3ac1f91e0ebc 115
chaithanyarss 224:3ac1f91e0ebc 116 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 117 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 118 spi.write(0x03); //reading hours register
chaithanyarss 224:3ac1f91e0ebc 119 response=spi.write(0x01);
chaithanyarss 224:3ac1f91e0ebc 120 uint8_t hours = ((response&0x30)>>4)*10+(response&0x0F)*1;
chaithanyarss 224:3ac1f91e0ebc 121
chaithanyarss 224:3ac1f91e0ebc 122 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 123 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 124 spi.write(0x04); //reading day's register
chaithanyarss 224:3ac1f91e0ebc 125 uint8_t day =spi.write(0x01);
chaithanyarss 224:3ac1f91e0ebc 126
chaithanyarss 224:3ac1f91e0ebc 127 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 128 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 129 spi.write(0x05); //reading date register
chaithanyarss 224:3ac1f91e0ebc 130 response =spi.write(0x01);
chaithanyarss 224:3ac1f91e0ebc 131 uint8_t date = ((response&0x30)>>4)*10+(response&0x0F)*1;
chaithanyarss 224:3ac1f91e0ebc 132
chaithanyarss 224:3ac1f91e0ebc 133 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 134 gCS_RTC=0;
chaithanyarss 224:3ac1f91e0ebc 135 spi.write(0x06); //reading month registe
chaithanyarss 224:3ac1f91e0ebc 136 response =spi.write(0x01);
chaithanyarss 224:3ac1f91e0ebc 137 uint8_t month = ((response&0x10)>>4)*10+(response&0x0F)*1;
chaithanyarss 224:3ac1f91e0ebc 138
chaithanyarss 224:3ac1f91e0ebc 139 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 140 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 141 response =spi.write(0x00);
ee12b079 209:63e9c8f8b5d2 142 uint8_t year = ((response&0xF0)>>4)*10+(response&0x0F)*1;
chaithanyarss 224:3ac1f91e0ebc 143 year = (year == 16)?0x00:(year == 17)?0x01:(year == 18)?0x02:(year == 19)?0x03:0x00;
aniruddhv 52:0bd68655c651 144 gCS_RTC=1;
chaithanyarss 224:3ac1f91e0ebc 145
chaithanyarss 224:3ac1f91e0ebc 146 uint8_t Time_stamp[8] = {year, month, date, day, hours, minutes, seconds, centiseconds};
chaithanyarss 224:3ac1f91e0ebc 147
aniruddhv 52:0bd68655c651 148 time = time|(((uint64_t)(centiseconds&0x7F)));
aniruddhv 52:0bd68655c651 149 time = time|(((uint64_t)(seconds&0x3F))<<7);
aniruddhv 52:0bd68655c651 150 time = time|(((uint64_t)(minutes&0x3F))<<13);
aniruddhv 52:0bd68655c651 151 time = time|(((uint64_t)(hours&0x1F))<<19);
aniruddhv 52:0bd68655c651 152 time = time|(((uint64_t)(day&0x1F))<<24);
aniruddhv 52:0bd68655c651 153 time = time|(((uint64_t)(month&0x07))<<29);
aniruddhv 52:0bd68655c651 154 time = time|(((uint64_t)(year&0x03))<<33);
aniruddhv 52:0bd68655c651 155 time = (time&0x00000007FFFFFFFF);
ee12b079 209:63e9c8f8b5d2 156 SPI_mutex.unlock();
ee12b079 209:63e9c8f8b5d2 157 return time;
ee12b079 209:63e9c8f8b5d2 158 }