#include #include #include #include #include #include #include #include #include #include #include #include /* Driver configuration */ #include "ti_drivers_config.h" /* Driver configuration */ #include "ti_drivers_config.h" /* String conversion macro */ #define STR_(n) #n #define STR(n) STR_(n) /* Drive number used for FatFs */ #define DRIVE_NUM 0 const char inputfile[] = "fat:"STR(DRIVE_NUM)":input.txt"; const char outputfile[] = "fat:"STR(DRIVE_NUM)":output.txt"; const char textarray[] = \ "***********************************************************************\n" "0 1 2 3 4 5 6 7\n" "01234567890123456789012345678901234567890123456789012345678901234567890\n" "This is some text to be inserted into the inputfile if there isn't\n" "already an existing file located on the media.\n" "If an inputfile already exists, or if the file was already once\n" "generated, then the inputfile will NOT be modified.\n" "***********************************************************************\n"; char fatfsPrefix[] = "fat"; /* * ======== mainThread ======== */ void *mainThread(void *arg0) { UART_Handle handle; UART_Params params; SDFatFS_Handle sdfatfsHandle; FILE *src; char rxBuf[250]; // Receive buffer /* Call driver init functions */ GPIO_init(); UART_init(); SDFatFS_init(); /* Configure the LED pin */ GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); add_device(fatfsPrefix, _MSA, ffcio_open, ffcio_close, ffcio_read, ffcio_write, ffcio_lseek, ffcio_unlink, ffcio_rename); /* Mount and register the SD Card */ sdfatfsHandle = SDFatFS_open(CONFIG_SDFatFS_0, DRIVE_NUM); // Init UART and specify non-default parameters UART_Params_init(¶ms); params.baudRate = 115200; params.writeDataMode = UART_DATA_BINARY; // Open the UART and do the read handle = UART_open(CONFIG_UART_0, ¶ms); if (handle == NULL) { /* UART_open() failed */ while (1); } /* Turn on user LED to indicate successful initialization */ while(1) { GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF); int rxBytes = UART_read(handle, rxBuf, 200); UART_write(handle, rxBuf, 200); src = fopen(inputfile, "w+"); fwrite(textarray, 1, strlen(textarray), src); fflush(src); rewind(src); fclose(src); SDFatFS_close(sdfatfsHandle); } } /* * ======== fatfs_getFatTime ======== */ int32_t fatfs_getFatTime(void) { /* * FatFs uses this API to get the current time in FatTime format. User's * must implement this function based on their system's timekeeping * mechanism. See FatFs documentation for details on FatTime format. */ /* Jan 1 2017 00:00:00 */ return (0x4A210000); }