CDMS code for testing sbc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Committer:
ee12b079
Date:
Sun Jul 10 13:47:26 2016 +0000
Revision:
245:da9d1bd999da
Parent:
224:3ac1f91e0ebc
Child:
256:642ea552ac77
Making integrated code of CDMS

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