Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Committer:
ee12b079
Date:
Fri Feb 05 18:33:23 2016 +0000
Revision:
115:2e1144a41d76
Parent:
96:4ca92f9775e0
Child:
187:2c7263530c57
Child:
197:1369ef45b49e
Integrating PMS ... transmitter is to be integrated

Who changed what in which revision?

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