working version

Dependencies:   mbed mbed-rtos SimpleDMA FreescaleIAP eeprom

Fork of CDMS_CODE_FM_28JAN2017 by samp Srinivasan

Committer:
ee12b079
Date:
Sat Jul 02 14:54:52 2016 +0000
Revision:
209:63e9c8f8b5d2
Parent:
197:1369ef45b49e
Child:
214:6848a51af734
Child:
224:3ac1f91e0ebc
Merging in process

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);
ee12b079 209:63e9c8f8b5d2 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);
ee12b079 209:63e9c8f8b5d2 12
ee12b079 209:63e9c8f8b5d2 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);
ee12b079 209:63e9c8f8b5d2 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);
ee12b079 209:63e9c8f8b5d2 24
ee12b079 209:63e9c8f8b5d2 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
ee12b079 209:63e9c8f8b5d2 29 spi.write(0x80); //enabling stop bit in the seconds register
ee12b079 209:63e9c8f8b5d2 30
aniruddhv 52:0bd68655c651 31 gCS_RTC=1;
aniruddhv 52:0bd68655c651 32 gCS_RTC=0;
aniruddhv 52:0bd68655c651 33 spi.write(0x81);
ee12b079 209:63e9c8f8b5d2 34 spi.write(0x00); //disabling the stop bit to restart the oscillator
ee12b079 209:63e9c8f8b5d2 35
ee12b079 209:63e9c8f8b5d2 36
ee12b079 209:63e9c8f8b5d2 37 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 38 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 39 spi.write(0x80);
ee12b079 209:63e9c8f8b5d2 40 spi.write(0x01); // set milliseconds value to 00
ee12b079 209:63e9c8f8b5d2 41 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 42
ee12b079 209:63e9c8f8b5d2 43 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 44 spi.write(0x81);
ee12b079 209:63e9c8f8b5d2 45 spi.write(0x01); //set seconds value to 00
ee12b079 209:63e9c8f8b5d2 46 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 47
ee12b079 209:63e9c8f8b5d2 48 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 49 spi.write(0x82);
ee12b079 209:63e9c8f8b5d2 50 spi.write(0x01);//set minutes value to 00
ee12b079 209:63e9c8f8b5d2 51 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 52
ee12b079 209:63e9c8f8b5d2 53 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 54 spi.write(0x83);
ee12b079 209:63e9c8f8b5d2 55 spi.write(0x23); //set the hours to 01
ee12b079 209:63e9c8f8b5d2 56 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 57
ee12b079 209:63e9c8f8b5d2 58 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 59 spi.write(0x84);
ee12b079 209:63e9c8f8b5d2 60 spi.write(0x01); //set day of the week to 01
ee12b079 209:63e9c8f8b5d2 61 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 62
ee12b079 209:63e9c8f8b5d2 63 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 64 spi.write(0x85);
ee12b079 209:63e9c8f8b5d2 65 spi.write(0x31); //set date of the month to 01
ee12b079 209:63e9c8f8b5d2 66 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 67
ee12b079 209:63e9c8f8b5d2 68 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 69 spi.write(0x86);
ee12b079 209:63e9c8f8b5d2 70 spi.write(0x12); //set month to 01
ee12b079 209:63e9c8f8b5d2 71 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 72
ee12b079 209:63e9c8f8b5d2 73 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 74 spi.write(0x87);
ee12b079 209:63e9c8f8b5d2 75 spi.write(0x01); //set year to 00(2000)
ee12b079 209:63e9c8f8b5d2 76 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 77 gPC.puts("\r\nrtc initalised\r\n");
ee12b079 209:63e9c8f8b5d2 78 SPI_mutex.unlock();
ee12b079 209:63e9c8f8b5d2 79 }
ee12b079 209:63e9c8f8b5d2 80
ee12b079 209:63e9c8f8b5d2 81 uint64_t FCTN_CDMS_RD_RTC()
ee12b079 209:63e9c8f8b5d2 82 {
ee12b079 209:63e9c8f8b5d2 83 SPI_mutex.lock();
ee12b079 209:63e9c8f8b5d2 84 uint8_t response;
ee12b079 209:63e9c8f8b5d2 85
ee12b079 209:63e9c8f8b5d2 86 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 87 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 88 spi.write(0x0F);
ee12b079 209:63e9c8f8b5d2 89 response = (spi.write(0x00))&0x04;
aniruddhv 52:0bd68655c651 90
aniruddhv 52:0bd68655c651 91 gCS_RTC=1;
aniruddhv 52:0bd68655c651 92 gCS_RTC=0;
ee12b079 209:63e9c8f8b5d2 93 spi.write(0x00); //reading centiseconds register
ee12b079 209:63e9c8f8b5d2 94 response = spi.write(0x00); // read the value by sending dummy byte
ee12b079 209:63e9c8f8b5d2 95 uint8_t centiseconds = ((response&0xF0)>>4)*10+(response&0x0F)*1;
ee12b079 209:63e9c8f8b5d2 96
ee12b079 209:63e9c8f8b5d2 97 response =spi.write(0x00);
ee12b079 209:63e9c8f8b5d2 98 uint8_t seconds = ((response&0x70)>>4)*10+(response&0x0F)*1;
ee12b079 209:63e9c8f8b5d2 99
ee12b079 209:63e9c8f8b5d2 100 response =spi.write(0x00);
ee12b079 209:63e9c8f8b5d2 101 uint8_t minutes = ((response&0x70)>>4)*10+(response&0x0F)*1;
ee12b079 209:63e9c8f8b5d2 102
ee12b079 209:63e9c8f8b5d2 103 response=spi.write(0x00);
ee12b079 209:63e9c8f8b5d2 104 uint8_t hours = ((response&0x30)>>4)*10+(response&0x0F)*1;
ee12b079 209:63e9c8f8b5d2 105
ee12b079 209:63e9c8f8b5d2 106 uint8_t day =spi.write(0x00);
ee12b079 209:63e9c8f8b5d2 107
ee12b079 209:63e9c8f8b5d2 108 response =spi.write(0x00);
ee12b079 209:63e9c8f8b5d2 109 uint8_t date = ((response&0x30)>>4)*10+(response&0x0F)*1;
ee12b079 209:63e9c8f8b5d2 110
ee12b079 209:63e9c8f8b5d2 111 response =spi.write(0x00);
ee12b079 209:63e9c8f8b5d2 112 uint8_t month = ((response&0x10)>>4)*10+(response&0x0F)*1;
ee12b079 209:63e9c8f8b5d2 113
ee12b079 209:63e9c8f8b5d2 114 response =spi.write(0x00);
ee12b079 209:63e9c8f8b5d2 115 uint8_t year = ((response&0xF0)>>4)*10+(response&0x0F)*1;
ee12b079 209:63e9c8f8b5d2 116 year = (year == 17)?0x00:(year == 18)?0x01:(year == 19)?0x02:(year == 20)?0x03:0x00;
aniruddhv 52:0bd68655c651 117 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 118
aniruddhv 52:0bd68655c651 119 uint64_t time;
aniruddhv 52:0bd68655c651 120 time = 0;
aniruddhv 52:0bd68655c651 121 time = time|(((uint64_t)(centiseconds&0x7F)));
aniruddhv 52:0bd68655c651 122 time = time|(((uint64_t)(seconds&0x3F))<<7);
aniruddhv 52:0bd68655c651 123 time = time|(((uint64_t)(minutes&0x3F))<<13);
aniruddhv 52:0bd68655c651 124 time = time|(((uint64_t)(hours&0x1F))<<19);
aniruddhv 52:0bd68655c651 125 time = time|(((uint64_t)(day&0x1F))<<24);
aniruddhv 52:0bd68655c651 126 time = time|(((uint64_t)(month&0x07))<<29);
aniruddhv 52:0bd68655c651 127 time = time|(((uint64_t)(year&0x03))<<33);
aniruddhv 52:0bd68655c651 128 time = (time&0x00000007FFFFFFFF);
ee12b079 209:63e9c8f8b5d2 129
ee12b079 209:63e9c8f8b5d2 130 SPI_mutex.unlock();
ee12b079 209:63e9c8f8b5d2 131 return time;
ee12b079 209:63e9c8f8b5d2 132 }
ee12b079 209:63e9c8f8b5d2 133