CDMS code for testing sbc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Committer:
chaithanyarss
Date:
Mon Jul 04 13:53:20 2016 +0000
Revision:
223:7c802e1ccd30
Parent:
218:c63cdba0550f
All thread added, testing TCs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chaithanyarss 223:7c802e1ccd30 1
aniruddhv 52:0bd68655c651 2 void FCTN_CDMS_INIT_RTC()
chaithanyarss 223:7c802e1ccd30 3 {
chaithanyarss 223:7c802e1ccd30 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 223:7c802e1ccd30 9
chaithanyarss 223:7c802e1ccd30 10 //Kick starting the oscillator
chaithanyarss 223:7c802e1ccd30 11 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 12 spi.write(0x81); //register address with write flag
chaithanyarss 223:7c802e1ccd30 13 spi.write(0x80);//enabling stop bit in the seconds register
chaithanyarss 223:7c802e1ccd30 14 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 15
chaithanyarss 223:7c802e1ccd30 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 223:7c802e1ccd30 21 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 22
chaithanyarss 223:7c802e1ccd30 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 223:7c802e1ccd30 27 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 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);
ee12b079 209:63e9c8f8b5d2 33 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 34
chaithanyarss 223:7c802e1ccd30 35
ee12b079 209:63e9c8f8b5d2 36 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 37 spi.write(0x81);
chaithanyarss 223:7c802e1ccd30 38 spi.write(0x00);//disabling the stop bit to restart the oscillator
chaithanyarss 223:7c802e1ccd30 39 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 40
chaithanyarss 223:7c802e1ccd30 41 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 42 spi.write(0x80);
chaithanyarss 223:7c802e1ccd30 43 spi.write(0x01); // set milliseconds value to 00
chaithanyarss 223:7c802e1ccd30 44 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 45
chaithanyarss 223:7c802e1ccd30 46 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 47 spi.write(0x81);
chaithanyarss 223:7c802e1ccd30 48 spi.write(0x01); //set seconds value to 00
chaithanyarss 223:7c802e1ccd30 49 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 50
chaithanyarss 223:7c802e1ccd30 51 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 52 spi.write(0x82);
chaithanyarss 223:7c802e1ccd30 53 spi.write(0x01);//set minutes value to 00
chaithanyarss 223:7c802e1ccd30 54 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 55
chaithanyarss 223:7c802e1ccd30 56 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 57 spi.write(0x83);
ee12b079 209:63e9c8f8b5d2 58 spi.write(0x23); //set the hours to 01
ee12b079 209:63e9c8f8b5d2 59 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 60
ee12b079 209:63e9c8f8b5d2 61 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 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 223:7c802e1ccd30 65
ee12b079 209:63e9c8f8b5d2 66 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 67 spi.write(0x85);
ee12b079 209:63e9c8f8b5d2 68 spi.write(0x31); //set date of the month to 01
ee12b079 209:63e9c8f8b5d2 69 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 70
ee12b079 209:63e9c8f8b5d2 71 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 72 spi.write(0x86);
ee12b079 209:63e9c8f8b5d2 73 spi.write(0x12); //set month to 01
ee12b079 209:63e9c8f8b5d2 74 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 75
ee12b079 209:63e9c8f8b5d2 76 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 77 spi.write(0x87);
ee12b079 209:63e9c8f8b5d2 78 spi.write(0x01); //set year to 00(2000)
ee12b079 209:63e9c8f8b5d2 79 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 80 gPC.puts("\n\r rtc initalised \n");
ee12b079 209:63e9c8f8b5d2 81 SPI_mutex.unlock();
ee12b079 209:63e9c8f8b5d2 82 }
chaithanyarss 223:7c802e1ccd30 83
ee12b079 209:63e9c8f8b5d2 84 uint64_t FCTN_CDMS_RD_RTC()
chaithanyarss 223:7c802e1ccd30 85 {
chaithanyarss 223:7c802e1ccd30 86 SPI_mutex.lock();
ee12b079 209:63e9c8f8b5d2 87 uint8_t response;
chaithanyarss 216:570251b23c7b 88 uint64_t time = 0;
chaithanyarss 216:570251b23c7b 89
chaithanyarss 223:7c802e1ccd30 90 gCS_RTC = 0;
chaithanyarss 223:7c802e1ccd30 91 spi.write(0x0F);
chaithanyarss 223:7c802e1ccd30 92 response = spi.write(0x00);
chaithanyarss 223:7c802e1ccd30 93 //gPC.printf("0x%02X",response);
chaithanyarss 223:7c802e1ccd30 94 gCS_RTC = 1;
chaithanyarss 223:7c802e1ccd30 95
chaithanyarss 223:7c802e1ccd30 96 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 97 spi.write(0x00); //reading milliseconds register
chaithanyarss 223:7c802e1ccd30 98 response = spi.write(0x00); // read the value by sending dummy byte
chaithanyarss 223:7c802e1ccd30 99 uint8_t centiseconds = (uint8_t(response&0xF0)>>4)*10+uint8_t(response&0x0F)*1;
chaithanyarss 223:7c802e1ccd30 100
ee12b079 209:63e9c8f8b5d2 101 gCS_RTC=1;
ee12b079 209:63e9c8f8b5d2 102 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 103 spi.write(0x01); //reading seconds register
chaithanyarss 223:7c802e1ccd30 104 response =spi.write(0x01);
chaithanyarss 223:7c802e1ccd30 105 uint8_t seconds = ((response&0x70)>>4)*10+(response&0x0F)*1;
chaithanyarss 223:7c802e1ccd30 106
chaithanyarss 223:7c802e1ccd30 107 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 108 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 109 spi.write(0x02); //reading minutes register
chaithanyarss 223:7c802e1ccd30 110 response =spi.write(0x01);
chaithanyarss 223:7c802e1ccd30 111 uint8_t minutes = ((response&0xF0)>>4)*10+(response&0x0F)*1;
aniruddhv 52:0bd68655c651 112
aniruddhv 52:0bd68655c651 113 gCS_RTC=1;
aniruddhv 52:0bd68655c651 114 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 115 spi.write(0x03); //reading hours register
chaithanyarss 223:7c802e1ccd30 116 response=spi.write(0x01);
chaithanyarss 223:7c802e1ccd30 117 uint8_t hours = ((response&0x30)>>4)*10+(response&0x0F)*1;
chaithanyarss 223:7c802e1ccd30 118
chaithanyarss 223:7c802e1ccd30 119 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 120 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 121 spi.write(0x04); //reading day's register
chaithanyarss 223:7c802e1ccd30 122 uint8_t day =spi.write(0x01);
chaithanyarss 223:7c802e1ccd30 123
chaithanyarss 223:7c802e1ccd30 124 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 125 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 126 spi.write(0x05); //reading date register
chaithanyarss 223:7c802e1ccd30 127 response =spi.write(0x01);
chaithanyarss 223:7c802e1ccd30 128 uint8_t date = ((response&0x30)>>4)*10+(response&0x0F)*1;
chaithanyarss 223:7c802e1ccd30 129
chaithanyarss 223:7c802e1ccd30 130 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 131 gCS_RTC=0;
chaithanyarss 223:7c802e1ccd30 132 spi.write(0x06); //reading month registe
chaithanyarss 223:7c802e1ccd30 133 response =spi.write(0x01);
chaithanyarss 223:7c802e1ccd30 134 uint8_t month = ((response&0x10)>>4)*10+(response&0x0F)*1;
chaithanyarss 223:7c802e1ccd30 135
chaithanyarss 223:7c802e1ccd30 136 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 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 223:7c802e1ccd30 140 year = (year == 16)?0x00:(year == 17)?0x01:(year == 18)?0x02:(year == 19)?0x03:0x00;
aniruddhv 52:0bd68655c651 141 gCS_RTC=1;
chaithanyarss 223:7c802e1ccd30 142
chaithanyarss 223:7c802e1ccd30 143 uint8_t Time_stamp[8] = {year, month, date, day, hours, minutes, seconds, centiseconds};
chaithanyarss 223:7c802e1ccd30 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 }