publishing to check changes in cdms code
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE_samp_23SEP_DMA_flag by
Diff: cdms_rtc.h
- Revision:
- 187:2c7263530c57
- Parent:
- 115:2e1144a41d76
- Child:
- 206:fba4aeebf004
diff -r ccc21cc163f8 -r 2c7263530c57 cdms_rtc.h --- a/cdms_rtc.h Wed May 25 15:28:32 2016 +0000 +++ b/cdms_rtc.h Wed Jun 29 13:59:21 2016 +0000 @@ -74,79 +74,64 @@ spi.write(0x87); spi.write(0x01); //set year to 00(2000) gCS_RTC=1; - gPC.puts("\n\r rtc initalised \n"); + gPC.puts("\r\nrtc initalised\r\n"); SPI_mutex.unlock(); } uint64_t FCTN_CDMS_RD_RTC() { - SPI_mutex.lock(); - uint8_t response; - //printf("\n\r Entered rtc\n"); - gCS_RTC=1; - gCS_RTC=0; - spi.write(0x00); //reading milliseconds register - response = spi.write(0x00); // read the value by sending dummy byte - uint8_t centiseconds = (uint8_t(response&0xF0)>>4)*10+uint8_t(response&0x0F)*1; - - gCS_RTC=1; - gCS_RTC=0; - spi.write(0x01); //reading seconds register - response =spi.write(0x01); - uint8_t seconds = ((response&0x70)>>4)*10+(response&0x0F)*1; - - gCS_RTC=1; - gCS_RTC=0; - spi.write(0x02); //reading minutes register - response =spi.write(0x01); - uint8_t minutes = ((response&0xF0)>>4)*10+(response&0x0F)*1; - - gCS_RTC=1; - gCS_RTC=0; - spi.write(0x03); //reading hours register - response=spi.write(0x01); - uint8_t hours = ((response&0x30)>>4)*10+(response&0x0F)*1; - - gCS_RTC=1; - gCS_RTC=0; - spi.write(0x04); //reading day's register - uint8_t day =spi.write(0x01); - - gCS_RTC=1; - gCS_RTC=0; - spi.write(0x05); //reading date register - response =spi.write(0x01); - uint8_t date = ((response&0x30)>>4)*10+(response&0x0F)*1; - - gCS_RTC=1; - gCS_RTC=0; - spi.write(0x06); //reading month registe - response =spi.write(0x01); - uint8_t month = ((response&0x10)>>4)*10+(response&0x0F)*1; - - gCS_RTC=1; - gCS_RTC=0; - spi.write(0x07); //reading year's registe - response =spi.write(0x01); - uint8_t year = ((response&0xF0)>>4)*10+(response&0x0F)*1; - gCS_RTC=1; - //sprintf(Time_stamp,"%02d%02d%02d%02d%02d%02d%02d%02d",year, month, date, day, hours, minutes, seconds, milliseconds ); - uint8_t Time_stamp[8] = {year, month, date, day, hours, minutes, seconds, centiseconds}; - for(int i= 0; i<8;i++); - //printf("%d\t",Time_stamp[i]); - //printf("read\r\n"); - uint64_t time; - time = 0; - time = time|(((uint64_t)(centiseconds&0x7F))); - time = time|(((uint64_t)(seconds&0x3F))<<7); - time = time|(((uint64_t)(minutes&0x3F))<<13); - time = time|(((uint64_t)(hours&0x1F))<<19); - time = time|(((uint64_t)(day&0x1F))<<24); - time = time|(((uint64_t)(month&0x07))<<29); - time = time|(((uint64_t)(year&0x03))<<33); - time = (time&0x00000007FFFFFFFF); - //printf("\n\r%x%x", (int)(time >> 32), (int)(time)); - //printf("\n\r0x%016llx\n\r", time); - return time; - SPI_mutex.unlock(); + SPI_mutex.lock(); + uint8_t response; + + gCS_RTC=1; + gCS_RTC=0; + spi.write(0x0F); + response = (spi.write(0x00))&0x04; +/* if(response =! 0x00) + { + time = 0x0000000000000000; + return time; + }*/ + + gCS_RTC=1; + gCS_RTC=0; + spi.write(0x00); //reading centiseconds register + response = spi.write(0x00); // read the value by sending dummy byte + uint8_t centiseconds = ((response&0xF0)>>4)*10+(response&0x0F)*1; + + response =spi.write(0x00); + uint8_t seconds = ((response&0x70)>>4)*10+(response&0x0F)*1; + + response =spi.write(0x00); + uint8_t minutes = ((response&0x70)>>4)*10+(response&0x0F)*1; + + response=spi.write(0x00); + uint8_t hours = ((response&0x30)>>4)*10+(response&0x0F)*1; + + uint8_t day =spi.write(0x00); + + response =spi.write(0x00); + uint8_t date = ((response&0x30)>>4)*10+(response&0x0F)*1; + + response =spi.write(0x00); + uint8_t month = ((response&0x10)>>4)*10+(response&0x0F)*1; + + response =spi.write(0x00); + uint8_t year = ((response&0xF0)>>4)*10+(response&0x0F)*1; + year = (year == 17)?0x00:(year == 18)?0x01:(year == 19)?0x02:(year == 20)?0x03:0x00; + gCS_RTC=1; + + uint64_t time; + time = 0; + time = time|(((uint64_t)(centiseconds&0x7F))); + time = time|(((uint64_t)(seconds&0x3F))<<7); + time = time|(((uint64_t)(minutes&0x3F))<<13); + time = time|(((uint64_t)(hours&0x1F))<<19); + time = time|(((uint64_t)(day&0x1F))<<24); + time = time|(((uint64_t)(month&0x07))<<29); + time = time|(((uint64_t)(year&0x03))<<33); + time = (time&0x00000007FFFFFFFF); + + SPI_mutex.unlock(); + return time; } \ No newline at end of file