请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:LP-CC2652RB 工具/软件:Code Composer Studio
大家好、我正在接收来自另一个微控制器的 UART 数据、并尝试将其写入 SD 卡。 我能够连续接收、但无法写入。 请参阅下面的代码。
#include #include #include #include #include #include #include #include /* POSIX 头文件*/ #include #include #include //#include #include #include #include /* XDC 模块接头*/ #include #include /*驱动程序配置*/ #include "ti_drivers_config.h" static SEM_t sem; static volatile size_t numBytesRead; //文件复制过程中使用的缓冲区大小*/ #ifndef cpy_buy_size #define cpy_buff 2048 #endif /*字符串转换宏*/ #define STR_(n) #n #define STR (n) STR_(n) /*用于 FatFs 的驱动器编号*/ #define DRIVE_NUM 0 const char inputfile[]="fat:"STR (drive_NUM)":input.txt; const char outputfile[]="fat:"espec (drive_NUM)":output.txt; //const char array []="Hello from shivam"; //static Display_Handle display; //将此时间设置为当前的 UNIX 文本时间* .tv_sec = 1469647026、 tv_nsec = 0 }; //此文件系统的文件名前缀,用于 TI C RTS */ char fatfsPrefix[]="fat"; unsigned char cpy_buff [cpy_buff _size]; // *==== callbackFxn ==== // void callbackFxn (UART2_Handle handle、void * buffer、size_t count、 void * userArg, int_fast16_t status) { if (status!= UART2_STATUS_SUCCESS){ /* UART2_READ()中出现 RX 错误*/ while (1); } numBytesRead = count; SEM_POST (&SEM); } /* ==== mainThread ==== // void * mainThread (void * arg0) { 特性 输入; const 字符 回声波峰[]="回声字符:\r\n"; UART2_Handle UART; UART2_Params uartParams; 内部32_t semStatus; uint32_t STATUS = UART2_STATUS_SUCCESS; /*调用驱动程序初始化函数*/ GPIO_init(); /*配置 LED 引脚*/ GPIO_setConfig (CONFIG_GPIO_LED_0、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); /*创建信标*/ semStatus = SEM_INIT (&SEM、0、0); if (semStatus!= 0){ /*创建信标时出错*/ while (1); } /*在回调读取模式下创建 UART */ UART2_Params_init (uartParams); uartParams.readMode = UART2_Mode_callback; uartParams.readCallback = callbackFxn; uartParams.baudrate = 115200; UART = UART2_open (CONFIG_UART2_0、uartParams); if (UART == NULL){ /* UART2_open()失败*/ while (1); } /*打开用户 LED 指示初始化成功*/ GPIO_WRITE (CONFIG_GPIO_LED_0、CONFIG_GPIO_LED_ON); /*对 bytesWritten 传递 NULL,因为它未在本示例中使用*/ UART2_WRITE (UART、echoPrompt、sizeof (echoPrompt)、NULL); /*循环永久回显*/ while (1){ numBytesRead = 0; /*对 bytesRead 传递 NULL,因为它未在本示例中使用*/ STATUS = UART2_READ (UART、INPUT、1、NULL); if (status!= UART2_STATUS_SUCCESS){ /* UART2_READ()失败*/ while (1); } /*在执行读回调之前不要写入*/ SEM_WAIT (SEM); if (numBytesRead > 0){ STATUS = UART2_WRITE (UART、INPUT、1、NULL); if (status!= UART2_STATUS_SUCCESS){ /* UART2_write()失败*/ while (1); } } SDFatFS_Handle sdfatfsHandle; 文件*src; SDFatFS_init(); add_device (fatfsPrefix、_MSA、ffcio_open、ffcio_close、ffcio_read、 ffcio_write、ffcio_lseek、ffcio_unlink、ffcio_rename); /*初始化实时时钟*/ Clock_settime (clock_realtime、&ts); sdfatfsHandle = SDFatFS_open (CONFIG_SDFatFS_0、DRIVE_NUM); /*打开文件进行读取和写入*/ src = fopen (inputfile、"w+"); fseek (src、0、seek_end); fwrite(&INUT, 1, src); /*关闭 inputfile[]*/ fclose (src); /*停止 SDCard */ SDFatFS_Close (sdfatfsHandle); //返回(NULL); } } /* === fatfs_getFatTime === */ int32_t fatfs_getFatTime (void) { time_t 秒; uint32_t fatTime; struct tm *pTime; /* * TI TIME()返回1900年以来经过的秒数,而其他工具则返回 *从1970年起返回秒数。 但是、TI 和 GNU localtime() *将 TM TM_year 设置为1900年以来的年数。 * 秒=时间(空); pTime = localtime (&seconds); /* * localtime()将 pTime->TM_year 设置为年数 *自1900年起、因此从 TM_year 中减去80即可获得 FAT 时间 *自1980年起的偏移量。 * fatTime =((uint32_t)(pTime->TM_year - 80)<< 25)| ((uint32_t)(pTime->TM_mon)<< 21)| ((uint32_t)(pTime->tm_mday)<< 16)| ((uint32_t)(pTime->tm_hour)<< 11)| ((uint32_t)(pTime->TM_min)<< 5)| ((uint32_t)(pTime->TM_sec)>> 1); 返回((int32_t) fatTime); }