![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
integrating vr 1.0
Dependencies: SDFileSystem mbed-rtos mbed-src mbed
Revision 0:d6ce3d144be5, committed 2015-05-13
- Comitter:
- sakthipriya
- Date:
- Wed May 13 06:21:49 2015 +0000
- Commit message:
- integrating vr 1.0
Changed in this revision
diff -r 000000000000 -r d6ce3d144be5 SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Wed May 13 06:21:49 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
diff -r 000000000000 -r d6ce3d144be5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 13 06:21:49 2015 +0000 @@ -0,0 +1,399 @@ +#include "mbed.h" +#include "rtos.h" +#include "pin_config.h" +#include "SDFileSystem.h" +#include "string.h" + +const int addr = 0x20; //slave address +I2C master (PIN32,PIN31); //configure pins p27,p28 as I2C master +//I2C master (PIN32,PIN31); +Serial pc (USBTX,USBRX); +DigitalOut interrupt(PIN4); +InterruptIn data_ready(PIN39); +//DigitalOut interrupt(D9); +//InterruptIn data_ready(D10); +int reset; +Timer t; +Timer t1; +Timer t2; +Timer t3; + +void store_data(); + +typedef struct +{ + char data; // To avoid dynamic memory allocation + int length; +}i2c_data; + + + +//Mail<i2c_data,16> i2c_data_receive; +Mail<i2c_data,16> i2c_data_send; + +Thread * ptr_t_i2c; +void FUNC_I2C_MASTER_FSLAVE(char * data,int length) +{ + + + bool ack0 =true; + + interrupt = 1; + t1.start(); + //wait_ms(20); + ack0 = master.read(addr|1,data,length); + t1.stop(); + + + if(!ack0) + { + printf("\n master has read %s from slave\n\r",data); + + } + //master.stop(); + + store_data(); + printf("\n%d\n\r",t1.read_us()); + t1.reset(); + + interrupt=0; + +} + +typedef struct { + char Voltage[9]; + char Current[5]; + char Temperature[2]; + char PanelTemperature[3];//read by the 4 thermistors on solar panels + char BatteryTemperature; //to be populated + char faultpoll; //polled faults + char faultir; //interrupted faults + char power_mode; //power modes + char AngularSpeed[3]; + char Bnewvalue[3]; + + //float magnetometer,gyro=>to be addes +} hk_data; +hk_data decode_data; + +/*void TC_DECODE(char *data_hk) //getting the structure back from hk data sent by bae +{ + for(int i=0;i<=7;i++) + { + decode_data.Voltage[i] = data_hk[i]; + decode_data.Voltage[8] = '\0'; + } + for(int i=0;i<=3;i++) + { + decode_data.Current[i] = data_hk[8+i]; + decode_data.Current[4] = '\0'; + } + decode_data.Temperature[0] = data_hk[12]; + decode_data.Temperature[1] = '\0'; + for(int i=0;i<=1;i++) + { + decode_data.PanelTemperature[i] = data_hk[13+i]; + decode_data.PanelTemperature[2] = '\0'; + } + decode_data.BatteryTemperature = data_hk[15]; + decode_data.faultpoll = data_hk[16]; + decode_data.faultir = data_hk[17]; + decode_data.power_mode = data_hk[18]; + for(int i=0;i<=1;i++) + { + decode_data.AngularSpeed[i] = data_hk[19+i]; + decode_data.AngularSpeed[2] = '\0'; + } + for(int i=0;i<=1;i++) + { + decode_data.Bnewvalue[i] = data_hk[21+i]; + decode_data.Bnewvalue[2] = '\0'; + } + printf("\n voltage %s\n\r",decode_data.Voltage); + printf("\n current %s\n\r",decode_data.Current); + printf("\n faultpoll %c\n\r",decode_data.faultpoll); +}*/ + + +void T_I2C_MASTER_FSLAVE(void const *args) +{ + char data_receive[25]; + //char data_receive; + while(1) + { + Thread::signal_wait(0x1); + + + FUNC_I2C_MASTER_FSLAVE(data_receive,25); + /*i2c_data * i2c_data_r = i2c_data_receive.alloc(); + strcpy(i2c_data_r->data , data_receive); + i2c_data_r->length = 25; + i2c_data_receive.put(i2c_data_r);*/ + printf("\n Data received from slave is %s\n\r",data_receive); + //TC_DECODE(data_receive); + } +} + +void FUNC_INT() +{ + + ptr_t_i2c->signal_set(0x1); + +} + +char writedata; +bool write2slave; +bool master_status_write; +void FUNC_MASTER_WRITE() +{ //wait(1); + write2slave=true; + + + + char data = pc.getc(); + interrupt = 1; + t.start(); + t3.start(); + // wait_ms(20); + i2c_data * i2c_data_s = i2c_data_send.alloc(); + i2c_data_s->data = data; + i2c_data_s->length = 1; + i2c_data_send.put(i2c_data_s); + master_status_write = true; + + // interrupt = 1; + + osEvent evt = i2c_data_send.get(); + if (evt.status == osEventMail) + { + i2c_data *i2c_data_s = (i2c_data*)evt.value.p; + writedata = i2c_data_s -> data; + t.stop(); + //t3.start(); + master_status_write = (bool) master.write(addr|0x00,&writedata,1); + t3.stop(); + if(master_status_write==0) + { + printf("\n\r CDMS has written %c to PAYLOAD\n\r",writedata); + write2slave=false; + } + i2c_data_send.free(i2c_data_s); + printf("\n%d",t.read_us()); + t.reset(); + printf("\n%d\n",t3.read_us()); + t3.reset(); + } + interrupt = 0; +} + +/********************************** Function Prototypes declaration ***********************************/ +int FUNC_CDMS_hex2int(int); // Need to convert the RTC time values to integers +void FUNC_CDMS_Gettime(void); // Function to get the time values from RTC registers +void FUNC_CDMS_init_values(void); // Function to initialize the registers in the RTC + + +/***************** Configure the SPI1 of the CDMS uc as the data bus for the RTC***********************/ +SPI spi(PTE1,PTE3, PTE2); // mosi, miso, sclk +DigitalOut cs(PTE29); // PTE29 is used for chip select + +char ch; +SDFileSystem sd(PTE1, PTE3, PTE2, PTE22, "sd"); // the pinout on the mbed Cool Components workshop board +//Serial pc(USBTX, USBRX); // tx, rx +char time_stamp[15]; + +/***********************Initialization function of the RTC********************************************/ +void FUNC_CDMS_init_values(void) +{ + cs=0; + spi.format(8,3); // Set the data bit with to be of 8 bits, + // data tx mode is 3 + spi.frequency(1000000); // Set Data rate to be 1 MHz + + cs = 0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x80); // Send the address of the Seconds register 0x80 + spi.write(0x00); // Set seconds value to 0 + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x81); // Send the address of the Minutes register 0x81 + spi.write(0x00); // Set minutes value to 0 + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x82); // Send the address of the Hours register 0x82 + spi.write(0x00); // Set hours value to 0 + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x83); // Send the address of the Day register 0x83 + spi.write(0x01); // Set the day to 01 + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x84); // Send the address of the date register 0x84 + spi.write(0x01); // Set date of the month to 01 + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x85); // Send the address of the Month register 0x80 + spi.write(0x01); // Set month to 01 + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x86); // Send the address of the year register 0x80 + spi.write(0x00); // Set year to 00(2000) + cs=1; // Set chip select pin to be 1: DeActivate RTC chip +}// End of INIT Function + + +/*********************************Function to read the RTC registers*********************************/ +void FUNC_CDMS_Gettime() +{ + + spi.format(8,3); // Set the data bit with to be of 8 bits, + // data tx mode is 3 + spi.frequency(1000000); // Set Data rate to be 1 MHz + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x00); // Sending address of seconds register + int seconds = spi.write(0x00); // Read the value by sending dummy byte + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x01); // Sending address of Minutes register + int minutes =spi.write(0x01); // Read the value by sending dummy byte + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x02); // Sending address of hours register + int hours =spi.write(0x01); // Read the value by sending dummy byte + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x03); // Sending address of day register + int day =spi.write(0x01); // Read the value by sending dummy byte + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x04); // Sending address of date register + int date =spi.write(0x01); // Read the value by sending dummy byte + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x05); // Sending address of month register + int month =spi.write(0x01); // Read the value by sending dummy byte + cs=1; // Set chip select pin to be 1: DeActivate RTC chip + + cs=0; // Set chip select pin to be 0: Activate RTC chip + spi.write(0x06); // Sending address of year register + int year =spi.write(0x01); // Read the value by sending dummy byte + cs = 1; // Set chip select pin to be 1: DeActivate RTC chip + + // RTC sends in BCD format.. SO we convert the values generated by RTC to integers + year = FUNC_CDMS_hex2int(year); + month = FUNC_CDMS_hex2int(month); + date = FUNC_CDMS_hex2int(date); + day = FUNC_CDMS_hex2int(day); + hours = FUNC_CDMS_hex2int(hours); + minutes = FUNC_CDMS_hex2int(minutes); + seconds = FUNC_CDMS_hex2int(seconds); + + // Print the obtained Time stamp + //printf("The time is :%d %d %d %d %d %d %d \n\r",seconds,minutes,hours,day,date,month,year); + sprintf(time_stamp,"%02d%02d%02d%02d%02d%02d",year,month,date,hours,minutes,seconds); + printf(" \n\r Received HK data from BAE"); + printf("\n HK_data stored in %s.txt",time_stamp); + //puts(time_stamp); + //printf(".txt"); +}//End of Read Function + +/**************************Function to convert Hex values to Int values*****************************/ +int FUNC_CDMS_hex2int(int a) +{ +a=(a/16)*10+(a%16); //function to convert hex type to int type +return a; +}// End of convert function + + +/******************************************END OF RTC CODE ****************************************/ + +char count = 10; +void store_data() +{ + FUNC_CDMS_Gettime(); + + char hk_data[25]; + count++; + strcpy(hk_data,"hk_Data "); + strcat(hk_data,"!@@#"); + hk_data[10] = count; + //storedata(hk_data); + mkdir("/sd/hk", 0777); + char add[20]; + strcpy(add,"/sd/hk/"); + strcat(add,time_stamp); + strcat(add,".txt"); + + /*FILE *fp = fopen(add, "w"); + if(fp == NULL) { + error("Could not open file for write\n"); + } + else + { + + fprintf(fp, "%s ",hk_data); + fclose(fp); + printf("\n File stored in SD card\n");*/ + //printf("\n Reading from the file .... \n Data is %s\n",hk_data); + + +} + + + +//void create_file() +//{ + + /* + fprintf(fp, "Hello fun SD Card World!\n"); + fclose(fp); + + fp = fopen("/sd/mydir/sdtest.txt", "r"); + if(fp == NULL) { + error("Could not open file for write\n"); + } + //fprintf(fp, "Hello fun SD Card World!"); + // fprintf("The contents of %s file are :\n", "/sd/mydir/sdtest.txt"); + while( ( ch = fgetc(fp) ) != '\n' ) + { + pc.printf("%c",ch); + } + //fprintf(fp); + fclose(fp); + + printf("Jai Mata Di..Goodbye World!\n");*/ +//} + +//Ticker t; + + +int main() +{ + interrupt=0; + ptr_t_i2c = new Thread(T_I2C_MASTER_FSLAVE); + data_ready.rise(&FUNC_INT); + printf("\n\rIITMSAT CDMS EXECUTED\n"); + master.frequency(100000); + + FUNC_CDMS_init_values(); + // t.attach(&store_data, 20.0); + while(1) + { //Thread::wait(9000); + //interrupt = 1; + + FUNC_MASTER_WRITE(); + //interrupt = 0; + ; + } +} \ No newline at end of file
diff -r 000000000000 -r d6ce3d144be5 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Wed May 13 06:21:49 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#13a25134ac60
diff -r 000000000000 -r d6ce3d144be5 mbed-src.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src.lib Wed May 13 06:21:49 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-src/#4dac56e9ae44
diff -r 000000000000 -r d6ce3d144be5 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed May 13 06:21:49 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file
diff -r 000000000000 -r d6ce3d144be5 pin_config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pin_config.h Wed May 13 06:21:49 2015 +0000 @@ -0,0 +1,101 @@ +// 100 LQFP format pin assignment +#define PIN1 PTE0 +#define PIN2 PTE1 +#define PIN3 PTE2 +#define PIN4 PTE3 +#define PIN5 PTE4 +#define PIN6 PTE5 +#define PIN7 PTE6 +//#define 8 +//#define 9 +//#define 10 +//#define 11 +//#define 12 +//#define 13 +#define PIN14 PTE16 +#define PIN15 PTE17 +#define PIN16 PTE18 +#define PIN17 PTE19 +#define PIN18 PTE20 +#define PIN19 PTE21 +#define PIN20 PTE22 +#define PIN21 PTE23 +//#define 22 +//#define 23 +//#define 24 +//#define 25 +#define PIN26 PTE29 +#define PIN27 PTE30 +#define PIN28 PTE31 +//#define 29 +//#define 30 +#define PIN31 PTE24 +#define PIN32 PTE25 +#define PIN33 PTE26 +#define PIN34 PTA0 +#define PIN35 PTA1 +#define PIN36 PTA2 +#define PIN37 PTA3 +#define PIN38 PTA4 +#define PIN39 PTA5 +#define PIN40 PTA6 +#define PIN41 PTA7 +#define PIN42 PTA12 +#define PIN43 PTA13 +#define PIN44 PTA14 +#define PIN45 PTA15 +#define PIN46 PTA16 +#define PIN47 PTA17 +//#define 48 +//#define 49 +#define PIN50 PTA18 +#define PIN51 PTA19 +#define PIN52 PTA20 +#define PIN53 PTB0 +#define PIN54 PTB1 +#define PIN55 PTB2 +#define PIN56 PTB3 +#define PIN57 PTB7 +#define PIN58 PTB8 +#define PIN59 PTB9 +#define PIN60 PTB10 +#define PIN61 PTB11 +#define PIN62 PTB16 +#define PIN63 PTB17 +#define PIN64 PTB18 +#define PIN65 PTB19 +#define PIN66 PTB20 +#define PIN67 PTB21 +#define PIN68 PTB22 +#define PIN69 PTB23 +#define PIN70 PTC0 +#define PIN71 PTC1 +#define PIN72 PTC2 +#define PIN73 PTC3 +//#define 74 +//#define 75 +#define PIN76 PTC20 +#define PIN77 PTC21 +#define PIN78 PTC22 +#define PIN79 PTC23 +#define PIN80 PTC4 +#define PIN81 PTC5 +#define PIN82 PTC6 +#define PIN83 PTC7 +#define PIN84 PTC8 +#define PIN85 PTC9 +#define PIN86 PTC10 +#define PIN87 PTC11 +#define PIN88 PTC12 +#define PIN89 PTC13 +#define PIN90 PTC16 +#define PIN91 PTC17 +#define PIN92 PTC18 +#define PIN93 PTD0 +#define PIN94 PTD1 +#define PIN95 PTD2 +#define PIN96 PTD3 +#define PIN97 PTD4 +#define PIN98 PTD5 +#define PIN99 PTD6 +#define PIN100 PTD7 \ No newline at end of file