publishing to check changes in cdms code

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA_flag by samp Srinivasan

Committer:
chaithanyarss
Date:
Sun Jul 03 09:33:33 2016 +0000
Revision:
214:6848a51af734
Parent:
209:63e9c8f8b5d2
Child:
218:c63cdba0550f
Reset CDMS added;

Who changed what in which revision?

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