Repository for CDMS code
Dependencies: SimpleDMA mbed-rtos mbed eeprom
Fork of COM_MNG_TMTC_SIMPLE by
cdms_rtc.h@207:28a07943dded, 2016-07-02 (annotated)
- Committer:
- chaithanyarss
- Date:
- Sat Jul 02 10:48:30 2016 +0000
- Revision:
- 207:28a07943dded
- Parent:
- 206:fba4aeebf004
Except Flash everything else.
Who changed what in which revision?
User | Revision | Line number | New 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); |
chaithanyarss | 206:fba4aeebf004 | 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); |
chaithanyarss | 206:fba4aeebf004 | 12 | |
chaithanyarss | 206:fba4aeebf004 | 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); |
chaithanyarss | 206:fba4aeebf004 | 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); |
chaithanyarss | 206:fba4aeebf004 | 24 | |
chaithanyarss | 206:fba4aeebf004 | 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 |
chaithanyarss | 207:28a07943dded | 29 | spi.write(0x80); //enabling stop bit in the seconds register |
chaithanyarss | 206:fba4aeebf004 | 30 | |
aniruddhv | 52:0bd68655c651 | 31 | gCS_RTC=1; |
aniruddhv | 52:0bd68655c651 | 32 | gCS_RTC=0; |
aniruddhv | 52:0bd68655c651 | 33 | spi.write(0x81); |
chaithanyarss | 207:28a07943dded | 34 | spi.write(0x00); //disabling the stop bit to restart the oscillator |
chaithanyarss | 206:fba4aeebf004 | 35 | |
chaithanyarss | 206:fba4aeebf004 | 36 | |
aniruddhv | 52:0bd68655c651 | 37 | gCS_RTC=1; |
aniruddhv | 52:0bd68655c651 | 38 | gCS_RTC=0; |
chaithanyarss | 206:fba4aeebf004 | 39 | spi.write(0x80); |
aniruddhv | 52:0bd68655c651 | 40 | spi.write(0x01); // set milliseconds value to 00 |
aniruddhv | 52:0bd68655c651 | 41 | gCS_RTC=1; |
chaithanyarss | 206:fba4aeebf004 | 42 | |
aniruddhv | 52:0bd68655c651 | 43 | gCS_RTC=0; |
chaithanyarss | 206:fba4aeebf004 | 44 | spi.write(0x81); |
aniruddhv | 52:0bd68655c651 | 45 | spi.write(0x01); //set seconds value to 00 |
aniruddhv | 52:0bd68655c651 | 46 | gCS_RTC=1; |
chaithanyarss | 206:fba4aeebf004 | 47 | |
aniruddhv | 52:0bd68655c651 | 48 | gCS_RTC=0; |
chaithanyarss | 206:fba4aeebf004 | 49 | spi.write(0x82); |
aniruddhv | 52:0bd68655c651 | 50 | spi.write(0x01);//set minutes value to 00 |
aniruddhv | 52:0bd68655c651 | 51 | gCS_RTC=1; |
chaithanyarss | 206:fba4aeebf004 | 52 | |
aniruddhv | 52:0bd68655c651 | 53 | gCS_RTC=0; |
chaithanyarss | 206:fba4aeebf004 | 54 | spi.write(0x83); |
aniruddhv | 52:0bd68655c651 | 55 | spi.write(0x23); //set the hours to 01 |
aniruddhv | 52:0bd68655c651 | 56 | gCS_RTC=1; |
chaithanyarss | 206:fba4aeebf004 | 57 | |
aniruddhv | 52:0bd68655c651 | 58 | gCS_RTC=0; |
chaithanyarss | 206:fba4aeebf004 | 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; |
chaithanyarss | 206:fba4aeebf004 | 62 | |
aniruddhv | 52:0bd68655c651 | 63 | gCS_RTC=0; |
chaithanyarss | 206:fba4aeebf004 | 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; |
chaithanyarss | 206:fba4aeebf004 | 67 | |
aniruddhv | 52:0bd68655c651 | 68 | gCS_RTC=0; |
chaithanyarss | 206:fba4aeebf004 | 69 | spi.write(0x86); |
aniruddhv | 52:0bd68655c651 | 70 | spi.write(0x12); //set month to 01 |
aniruddhv | 52:0bd68655c651 | 71 | gCS_RTC=1; |
chaithanyarss | 206:fba4aeebf004 | 72 | |
aniruddhv | 52:0bd68655c651 | 73 | gCS_RTC=0; |
chaithanyarss | 206:fba4aeebf004 | 74 | spi.write(0x87); |
aniruddhv | 52:0bd68655c651 | 75 | spi.write(0x01); //set year to 00(2000) |
aniruddhv | 52:0bd68655c651 | 76 | gCS_RTC=1; |
chaithanyarss | 187:2c7263530c57 | 77 | gPC.puts("\r\nrtc initalised\r\n"); |
ee12b079 | 93:4d76de54a699 | 78 | SPI_mutex.unlock(); |
aniruddhv | 52:0bd68655c651 | 79 | } |
chaithanyarss | 206:fba4aeebf004 | 80 | |
aniruddhv | 52:0bd68655c651 | 81 | uint64_t FCTN_CDMS_RD_RTC() |
chaithanyarss | 206:fba4aeebf004 | 82 | { |
chaithanyarss | 206:fba4aeebf004 | 83 | SPI_mutex.lock(); |
chaithanyarss | 206:fba4aeebf004 | 84 | uint8_t response; |
chaithanyarss | 206:fba4aeebf004 | 85 | |
chaithanyarss | 206:fba4aeebf004 | 86 | gCS_RTC=1; |
chaithanyarss | 206:fba4aeebf004 | 87 | gCS_RTC=0; |
chaithanyarss | 206:fba4aeebf004 | 88 | spi.write(0x0F); |
chaithanyarss | 206:fba4aeebf004 | 89 | response = (spi.write(0x00))&0x04; |
chaithanyarss | 207:28a07943dded | 90 | |
chaithanyarss | 206:fba4aeebf004 | 91 | gCS_RTC=1; |
chaithanyarss | 206:fba4aeebf004 | 92 | gCS_RTC=0; |
chaithanyarss | 206:fba4aeebf004 | 93 | spi.write(0x00); //reading centiseconds register |
chaithanyarss | 206:fba4aeebf004 | 94 | response = spi.write(0x00); // read the value by sending dummy byte |
chaithanyarss | 206:fba4aeebf004 | 95 | uint8_t centiseconds = ((response&0xF0)>>4)*10+(response&0x0F)*1; |
chaithanyarss | 187:2c7263530c57 | 96 | |
chaithanyarss | 206:fba4aeebf004 | 97 | response =spi.write(0x00); |
chaithanyarss | 206:fba4aeebf004 | 98 | uint8_t seconds = ((response&0x70)>>4)*10+(response&0x0F)*1; |
chaithanyarss | 187:2c7263530c57 | 99 | |
chaithanyarss | 206:fba4aeebf004 | 100 | response =spi.write(0x00); |
chaithanyarss | 206:fba4aeebf004 | 101 | uint8_t minutes = ((response&0x70)>>4)*10+(response&0x0F)*1; |
chaithanyarss | 187:2c7263530c57 | 102 | |
chaithanyarss | 206:fba4aeebf004 | 103 | response=spi.write(0x00); |
chaithanyarss | 206:fba4aeebf004 | 104 | uint8_t hours = ((response&0x30)>>4)*10+(response&0x0F)*1; |
chaithanyarss | 187:2c7263530c57 | 105 | |
chaithanyarss | 206:fba4aeebf004 | 106 | uint8_t day =spi.write(0x00); |
chaithanyarss | 187:2c7263530c57 | 107 | |
chaithanyarss | 206:fba4aeebf004 | 108 | response =spi.write(0x00); |
chaithanyarss | 206:fba4aeebf004 | 109 | uint8_t date = ((response&0x30)>>4)*10+(response&0x0F)*1; |
chaithanyarss | 187:2c7263530c57 | 110 | |
chaithanyarss | 206:fba4aeebf004 | 111 | response =spi.write(0x00); |
chaithanyarss | 206:fba4aeebf004 | 112 | uint8_t month = ((response&0x10)>>4)*10+(response&0x0F)*1; |
chaithanyarss | 187:2c7263530c57 | 113 | |
chaithanyarss | 206:fba4aeebf004 | 114 | response =spi.write(0x00); |
chaithanyarss | 206:fba4aeebf004 | 115 | uint8_t year = ((response&0xF0)>>4)*10+(response&0x0F)*1; |
chaithanyarss | 206:fba4aeebf004 | 116 | year = (year == 17)?0x00:(year == 18)?0x01:(year == 19)?0x02:(year == 20)?0x03:0x00; |
chaithanyarss | 206:fba4aeebf004 | 117 | gCS_RTC=1; |
chaithanyarss | 187:2c7263530c57 | 118 | |
chaithanyarss | 206:fba4aeebf004 | 119 | uint64_t time; |
chaithanyarss | 206:fba4aeebf004 | 120 | time = 0; |
chaithanyarss | 206:fba4aeebf004 | 121 | time = time|(((uint64_t)(centiseconds&0x7F))); |
chaithanyarss | 206:fba4aeebf004 | 122 | time = time|(((uint64_t)(seconds&0x3F))<<7); |
chaithanyarss | 206:fba4aeebf004 | 123 | time = time|(((uint64_t)(minutes&0x3F))<<13); |
chaithanyarss | 206:fba4aeebf004 | 124 | time = time|(((uint64_t)(hours&0x1F))<<19); |
chaithanyarss | 206:fba4aeebf004 | 125 | time = time|(((uint64_t)(day&0x1F))<<24); |
chaithanyarss | 206:fba4aeebf004 | 126 | time = time|(((uint64_t)(month&0x07))<<29); |
chaithanyarss | 206:fba4aeebf004 | 127 | time = time|(((uint64_t)(year&0x03))<<33); |
chaithanyarss | 206:fba4aeebf004 | 128 | time = (time&0x00000007FFFFFFFF); |
chaithanyarss | 187:2c7263530c57 | 129 | |
chaithanyarss | 206:fba4aeebf004 | 130 | SPI_mutex.unlock(); |
chaithanyarss | 206:fba4aeebf004 | 131 | return time; |
chaithanyarss | 207:28a07943dded | 132 | } |
chaithanyarss | 207:28a07943dded | 133 |