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:
ee12b079
Date:
Sun Sep 04 11:12:00 2016 +0000
Revision:
301:701ac67649b7
Parent:
289:9bd62b69874c
Correcting CDMS_HK

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