Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Committer:
chaithanyarss
Date:
Mon Jul 11 14:33:02 2016 +0000
Revision:
255:642ea552ac77
Parent:
245:da9d1bd999da
Child:
282:74a04dec4b95
Integration and Testing is in progress

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