
High speed logging example
Dependencies: Adafruit_RTCLib BNO055 SDFileSystem mbed
Revision 2:aaa32a8342ab, committed 2018-01-24
- Comitter:
- bwang
- Date:
- Wed Jan 24 22:06:46 2018 +0000
- Parent:
- 1:27070bac59e5
- Child:
- 3:3bd4a5429b4e
- Commit message:
- working circular buffer code
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jan 23 06:21:12 2018 +0000 +++ b/main.cpp Wed Jan 24 22:06:46 2018 +0000 @@ -4,38 +4,43 @@ #include "DS1307.h" #include "string.h" +/*SD card*/ #define DI D11 #define DO D12 #define SCK D13 #define CS D10 +/*RTC*/ #define I2C1_SDA PB_9 #define I2C1_SCL PB_8 +char fname[255]; +char current_time[64]; + +/*IMU*/ #define I2C2_SDA D5 #define I2C2_SCL D7 +/*Serial buffer*/ #define PAGE_SIZE 4096 #define HEADER_SIZE 10 #define CHUNK_SIZE (PAGE_SIZE-HEADER_SIZE) -#define PACKET_SIZE 8 -#define BAUD_RATE 921600 #define BUF_SIZE (16*PAGE_SIZE) -Serial serial4(D8, D2); -DigitalOut test(PC_8); -DigitalOut test2(PC_6); -int flag=0, flag2=0; - -char fname[255]; -char current_time[64]; - int start = 0, end = 0; unsigned char buf[BUF_SIZE]; unsigned char hdr[HEADER_SIZE] = {0xff, 0xff,'M','A','N','B','L','O','R','T'}; -void printDT(char *pre, DateTime &dt) -{ +/*UART*/ +#define BAUD_RATE 921600 +Serial serial4(D8, D2); + +/*Test pins*/ +DigitalOut test(PC_8); +DigitalOut test2(PC_6); +int flag=0, flag2=0; + +void printDT(char *pre, DateTime &dt) { printf("%s %u/%u/%02u %2u:%02u:%02u\r\n" ,pre ,dt.month(),dt.day(),dt.year() @@ -43,25 +48,15 @@ ); } -bool rtcUpdate(RtcDs1307 &rtc, int32_t bias) // this must be signed -{ bool bUpdated = false; - - // Use the compiled date/time as a basis for setting the clock. - // We assign it to a signed integer so that negative biases work correctly +bool rtcUpdate(RtcDs1307 &rtc, int32_t bias) { + bool bUpdated = false; int64_t compiledTime = DateTime(__DATE__,__TIME__).unixtime(); - // This assumes that the program is run VERY soon after the initial compile. - time_t localt = DateTime(compiledTime + bias).unixtime(); // offset by bias + time_t localt = DateTime(compiledTime + bias).unixtime(); - // If the stored static time stamp does not equal the compiled time stamp, - // then we need to update the RTC clock and the stored time stamp - if(*((time_t *)&rtc[0]) != localt) - { - // Update the RTC time as local time, not GMT/UTC + if(*((time_t *)&rtc[0]) != localt) { rtc.adjust(localt); - // Store the new compiled time statically in the object ram image *((time_t *)&rtc[0]) = localt; - // Push the object ram image to the RTC ram image bUpdated = rtc.commit(); } @@ -77,8 +72,7 @@ } int main() { - test = 0; - + /*init SD card, wait for card insertion*/ SDFileSystem sd(DI, DO, SCK, CS, "sd"); while (sd.disk_status()) { sd.disk_initialize(); @@ -122,7 +116,8 @@ imu.setmode(OPERATION_MODE_NDOF); imu.set_accel_units(MPERSPERS); - + + /*init serial*/ serial4.baud(BAUD_RATE); serial4.attach(rx_callback); @@ -139,6 +134,7 @@ } fflush(fp); start += CHUNK_SIZE; + if (start >= BUF_SIZE) start -= BUF_SIZE; } } }