TYBLE16 on os5 sample programs

Dependencies:   BME280 TextLCD nRF51_Vdd

Fork of TYBLE16_mbedlized_os5_BASE by Kenji Arai

Please refer following notebook.
/users/kenjiArai/notebook/tyble16-module-as-mbed-os-5-board-mbedlization/

Committer:
kenjiArai
Date:
Sun Apr 15 04:15:18 2018 +0000
Revision:
3:c0010c8ad17f
Parent:
1:9011c83e4178
Separated Uart_Clinent & Uart_Server due to memory overflow

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 1:9011c83e4178 1 /*
kenjiArai 1:9011c83e4178 2 * Mbed Application program
kenjiArai 1:9011c83e4178 3 * SD Card file control function with FatFs on Mbed-os5
kenjiArai 1:9011c83e4178 4 *
kenjiArai 1:9011c83e4178 5 * Copyright (c) 2018 Kenji Arai / JH1PJL
kenjiArai 1:9011c83e4178 6 * http://www.page.sannet.ne.jp/kenjia/index.html
kenjiArai 1:9011c83e4178 7 * https://os.mbed.com/users/kenjiArai/
kenjiArai 1:9011c83e4178 8 * Created: April 4th, 2018
kenjiArai 1:9011c83e4178 9 * Revised: April 14th, 2018 only for TYBLE16
kenjiArai 1:9011c83e4178 10 */
kenjiArai 1:9011c83e4178 11
kenjiArai 1:9011c83e4178 12 //#define EXAMPLE_5_SDCARD
kenjiArai 1:9011c83e4178 13 #ifdef EXAMPLE_5_SDCARD
kenjiArai 1:9011c83e4178 14
kenjiArai 1:9011c83e4178 15 // Include --------------------------------------------------------------------
kenjiArai 1:9011c83e4178 16 #include "mbed.h"
kenjiArai 1:9011c83e4178 17 #include "SDBlockDevice.h"
kenjiArai 1:9011c83e4178 18 #include "FATFileSystem.h"
kenjiArai 1:9011c83e4178 19 #include "mon.h"
kenjiArai 1:9011c83e4178 20 #include "TYBLE16_BASE.h"
kenjiArai 1:9011c83e4178 21 #include <stdlib.h>
kenjiArai 1:9011c83e4178 22
kenjiArai 1:9011c83e4178 23 // Definition -----------------------------------------------------------------
kenjiArai 1:9011c83e4178 24 #define USER_SW_ON 0
kenjiArai 1:9011c83e4178 25
kenjiArai 1:9011c83e4178 26 // Constructor ----------------------------------------------------------------
kenjiArai 1:9011c83e4178 27 DigitalOut led(LED1);
kenjiArai 1:9011c83e4178 28 DigitalIn user_sw(BUTTON1, PullUp);
kenjiArai 1:9011c83e4178 29 Serial pc(USBTX, USBRX, 115200);
kenjiArai 1:9011c83e4178 30 SDBlockDevice sd(D3, D2, D0, D1, 8000000);
kenjiArai 1:9011c83e4178 31 FATFileSystem fs("fs");
kenjiArai 1:9011c83e4178 32
kenjiArai 1:9011c83e4178 33 // RAM ------------------------------------------------------------------------
kenjiArai 1:9011c83e4178 34
kenjiArai 1:9011c83e4178 35 // ROM / Constant data --------------------------------------------------------
kenjiArai 1:9011c83e4178 36 char *const opngmsg =
kenjiArai 1:9011c83e4178 37 "\x1b[2J\x1b[H"__FILE__ "\r\n"__DATE__ " " __TIME__ " (UTC)\r\n""\r\n";
kenjiArai 1:9011c83e4178 38 char *const opening_msg0 = "microSD Card test program";
kenjiArai 1:9011c83e4178 39 char *const opening_msg1 = " -> run on Mbed OS-5\r\n";
kenjiArai 1:9011c83e4178 40
kenjiArai 1:9011c83e4178 41 // Function prototypes --------------------------------------------------------
kenjiArai 1:9011c83e4178 42
kenjiArai 1:9011c83e4178 43 //------------------------------------------------------------------------------
kenjiArai 1:9011c83e4178 44 // Control Program
kenjiArai 1:9011c83e4178 45 //------------------------------------------------------------------------------
kenjiArai 1:9011c83e4178 46 int main()
kenjiArai 1:9011c83e4178 47 {
kenjiArai 1:9011c83e4178 48 time_t seconds;
kenjiArai 1:9011c83e4178 49 uint32_t data0 = 10000U;
kenjiArai 1:9011c83e4178 50 uint32_t data1 = 20000U;
kenjiArai 1:9011c83e4178 51 uint32_t data2 = 30000U;
kenjiArai 1:9011c83e4178 52 uint32_t data3 = 40000U;
kenjiArai 1:9011c83e4178 53 uint32_t data4 = 50000U;
kenjiArai 1:9011c83e4178 54 uint32_t data5 = 60000U;
kenjiArai 1:9011c83e4178 55
kenjiArai 1:9011c83e4178 56 pc.puts(opngmsg);
kenjiArai 1:9011c83e4178 57 // Check TYBLE-16 configuration
kenjiArai 1:9011c83e4178 58 cpu_sys();
kenjiArai 1:9011c83e4178 59 compile_condition();
kenjiArai 1:9011c83e4178 60 if (user_sw == USER_SW_ON) {
kenjiArai 1:9011c83e4178 61 mon();
kenjiArai 1:9011c83e4178 62 }
kenjiArai 1:9011c83e4178 63 //pc.printf("line:%d\r\n", __LINE__);
kenjiArai 1:9011c83e4178 64 /* Init SD CARD reader */
kenjiArai 1:9011c83e4178 65 sd.init();
kenjiArai 1:9011c83e4178 66 fs.mount(&sd);
kenjiArai 1:9011c83e4178 67 FILE* fp = fopen("/fs/mydata.txt", "a");
kenjiArai 1:9011c83e4178 68 if (fp != 0) {
kenjiArai 1:9011c83e4178 69 pc.printf("%s%s", opening_msg0, opening_msg1);
kenjiArai 1:9011c83e4178 70 fprintf(fp,"%s%s", opening_msg0, opening_msg1);
kenjiArai 1:9011c83e4178 71 } else {
kenjiArai 1:9011c83e4178 72 pc.printf("ERROR\r\n");
kenjiArai 1:9011c83e4178 73 }
kenjiArai 1:9011c83e4178 74 fclose(fp);
kenjiArai 1:9011c83e4178 75 while (pc.readable()) {
kenjiArai 1:9011c83e4178 76 char c = pc.getc(); // dummy read
kenjiArai 1:9011c83e4178 77 }
kenjiArai 1:9011c83e4178 78 while (true) {
kenjiArai 1:9011c83e4178 79 uint32_t size = get_disk_freespace();
kenjiArai 1:9011c83e4178 80 pc.printf("free %u ", size);
kenjiArai 1:9011c83e4178 81 fp = fopen("/fs/mydata.txt", "a");
kenjiArai 1:9011c83e4178 82 if(fp != 0) {
kenjiArai 1:9011c83e4178 83 char tmp[64];
kenjiArai 1:9011c83e4178 84 seconds = time(NULL);
kenjiArai 1:9011c83e4178 85 strftime(tmp, 64, "TYBLE16 %H:%M:%S,%Y/%m/%d,", localtime(&seconds));
kenjiArai 1:9011c83e4178 86 pc.printf(tmp);
kenjiArai 1:9011c83e4178 87 fprintf(fp, "%s", tmp);
kenjiArai 1:9011c83e4178 88 pc.printf("%08d;%08d;%08d;%08d;%08d;%08d\r\n",
kenjiArai 1:9011c83e4178 89 ++data0, ++data1, ++data2, ++data3, ++data4, ++data5);
kenjiArai 1:9011c83e4178 90 fprintf(fp, "%08d;%08d;%08d;%08d;%08d;%08d\r\n",
kenjiArai 1:9011c83e4178 91 data0, data1, data2, data3, data4, data5);
kenjiArai 1:9011c83e4178 92 } else {
kenjiArai 1:9011c83e4178 93 pc.printf("ERROR\r\n");
kenjiArai 1:9011c83e4178 94 }
kenjiArai 1:9011c83e4178 95 fclose(fp);
kenjiArai 1:9011c83e4178 96 Thread::wait(100);
kenjiArai 1:9011c83e4178 97 if (user_sw == USER_SW_ON) {
kenjiArai 1:9011c83e4178 98 break;
kenjiArai 1:9011c83e4178 99 }
kenjiArai 1:9011c83e4178 100 if (pc.readable()) {
kenjiArai 1:9011c83e4178 101 mon();
kenjiArai 1:9011c83e4178 102 }
kenjiArai 1:9011c83e4178 103 led = !led;
kenjiArai 1:9011c83e4178 104 }
kenjiArai 1:9011c83e4178 105 while(true) {
kenjiArai 1:9011c83e4178 106 mon();
kenjiArai 1:9011c83e4178 107 NVIC_SystemReset();
kenjiArai 1:9011c83e4178 108 }
kenjiArai 1:9011c83e4178 109 }
kenjiArai 1:9011c83e4178 110
kenjiArai 1:9011c83e4178 111 #endif