c - 定义 FREERTOS_USED 符号后 Atmel UC3A0512 FAT API 问题

标签 c embedded freertos flash-memory

我正在使用FAT API由ASF提供从flash读取数据,

FAT API 使用全局变量 fs_g_status 来帮助调试问题,但似乎 fs_g_status 需要 无意义的值:

fs_g_status 的可能值:

#define  FS_ERR_HW               (FAIL+0)    //!< Hardware driver error
#define  FS_ERR_NO_FORMAT        (FAIL+1)    //!< The selected drive isn't formated
#define  FS_ERR_NO_PART          (FAIL+2)    //!< The selected partition doesn't existed
#define  FS_ERR_NO_SUPPORT_PART  (FAIL+3)    //!< The selected partition isn't supported
#define  FS_ERR_TOO_FILE_OPEN    (FAIL+4)    //!< The navigation have already opened a file
#define  FS_ERR_END_OF_DRIVE     (FAIL+5)    //!< There are not other driver
#define  FS_ERR_BAD_POS          (FAIL+6)    //!< The position is over the file
#define  FS_ERR_FS               (FAIL+7)    //!< File system error
#define  FS_ERR_NO_FIND          (FAIL+8)    //!< File no found
#define  FS_ERR_ENTRY_EMPTY      (FAIL+9)    //!< File entry empty
#define  FS_ERR_ENTRY_BAD        (FAIL+10)   //!< File entry bad
#define  FS_ERR_ENTRY_BADTYPE    (FAIL+11)   //!< File entry type don't corresponding
#define  FS_ERR_NO_DIR           (FAIL+12)   //!< The selected file isn't a directory
#define  FS_ERR_NO_MOUNT         (FAIL+13)   //!< The partition isn't mounted
#define  FS_ERR_NO_FILE_SEL      (FAIL+14)   //!< There are no selected file
#define  FS_NO_LAST_LFN_ENTRY    (FAIL+15)   //!< The file entry isn't the last long file entry

#define  FS_ERR_ID_FILE          (FAIL+17)   //!< The file identifier is bad
#define  FS_ERR_NO_FILE          (FAIL+18)   //!< The selected file entry isn't a file
#define  FS_LUN_WP               (FAIL+19)   //!< Drive is in read only mode
#define  FS_ERR_READ_ONLY        (FAIL+20)   //!< File is on read access only
#define  FS_ERR_NAME_INCORRECT   (FAIL+21)   //!< The name don't corresponding at the filter name
//...

#define FAIL      1

这是我用来从闪存读取数据的函数

int read_Flash_Data()
{
  /* initialize FSACCESS mutex and navigators */
  if (b_fsaccess_init())
  { 
    usart_write_line((&AVR32_USART0), " b_fsaccess_init return true \r\n");   
  }
  //fs_g_status = 0x00 OK

  /* Try to init data flash */
  if (at45dbx_mem_check())
  {
    /* display message */
    usart_write_line((&AVR32_USART0), " at45dbx_mem_check return true \r\n");
}
else
{
    /* display error message */
    usart_write_line((&AVR32_USART0),"  at45dbx_mem_check return false\r\n");
    return (-1);
}
//fs_g_status = 0x00 OK

if (nav_drive_set(LUN_ID_1) == false)
{
    usart_write_line((&AVR32_USART0)," nav_drive_set return false \r\n");
    return (-1);
}
//fs_g_status = 0x01 ==> Hardware driver error NOK , but the nav_drive_set(LUN_ID_1) return true !!!!

if( !nav_partition_mount() ) 
{
    usart_write_line((&AVR32_USART0),"nav_partition_mount return false \r\n");
    return (-1);
}
//fs_g_status = 0x04 ==> The navigation have already opened a file, but the nav_partition_mount() return true !!!!

if ((ret = open(ACTUAL_CONFIG_FILE_PATH, O_RDONLY)) < 0)
{
    usart_write_line((&AVR32_USART0),"Opening file failed \r\n");
    return (-1);
}
//fs_g_status = 0x10 ==16(decimal) open return true !!!!
//...
}

我认为这不符合逻辑,只有当函数返回 false 时才应设置 fs_g_status。 好吧,假设有一些小问题和大问题导致功能失败并且评论不够好。

现在这个函数在 freeRTOS 任务中使用,我必须在编译中定义符号 FREERTOS_USED 以保护并发访问中的闪存,在上面的描述中没有定义该符号。 现在 nav_partition_mount() 返回 false 和 fs_g_status = 0x01

有人遇到这个问题吗?我似乎找不到调试问题的方法,欢迎提出任何建议。

最佳答案

您忘记初始化ctrl_access_semphr, 您必须使用ctrl_access.c中定义的函数ctrl_access_init

#ifdef FREERTOS_USED

bool ctrl_access_init(void)
{
 // If the handle to the protecting semaphore is not valid,
 if (!ctrl_access_semphr)
 {
   // try to create the semaphore.
   vSemaphoreCreateBinary(ctrl_access_semphr);

   // If the semaphore could not be created, there is no backup solution.
   if (!ctrl_access_semphr) return false;
  }

 return true;
}
#endif

你的函数应该是这样的:

int read_Flash_Data()
{
  /* initialize FSACCESS mutex and navigators */
  if (b_fsaccess_init())
  {   
    usart_write_line((&AVR32_USART0), " b_fsaccess_init return true \r\n");   
  }

  /* initialize ctrl_access semaphore */
  if (ctrl_access_init())
  {
    usart_write_line((&AVR32_USART0), " ctrl_access_init return true \r\n");
  }
  //......

关于c - 定义 FREERTOS_USED 符号后 Atmel UC3A0512 FAT API 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38611527/

相关文章:

c - 用c程序创建目录

c - 如何提高多线程读取文件的性能?

c - 需要以状态机的方式编写算法,但变得非常难读

c - 如何在 IAR 链接描述文件中定义总图像大小或其结束地址的符号?

stack - ISR(中断服务程序)是否有单独的堆栈?

c - 退出子进程

C - 使用 argv 命令

c - FreeRtos 与 nabto windows 32 的移植

security - XXTEA 对于 PIC 单片机来说是一个好的加密算法吗?

c - 多播 UDP 在我的主板上不起作用