背景说明
移植到日本某操作系统。
本文只简单介绍一下移植FatFs的要点。
移植流程
FatFs的源码并不多,需要实现的接口也不多,相对来说还是很好移植的。
系统相关的接口
1、变量类型的定义ff.h
开源代码一般都有这些定义需要实现:
8位有符号,例如char;
8位无符号,例如unsigned char;
16位有符号,例如short;
16位无符号,例如unsigned short;
32位有符号,例如int;
32位无符号,例如unsigned int;
这里要实现的是(已给出参考实现):
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
typedef unsigned char BYTE; /* char must be 8-bit */
typedef unsigned short WORD; /* 16-bit unsigned integer */
typedef unsigned long DWORD; /* 32-bit unsigned integer */
typedef WORD WCHAR; /* UTF-16 character type */
2、一些跟系统相关的常用函数接口ffsystem.c:
内存相关:
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
/* Allocate a memory block */
/*------------------------------------------------------------------------*/
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
UINT msize /* Number of bytes to allocate */
)
{
return malloc(msize); /* Allocate a new memory block with POSIX API */
}
/*------------------------------------------------------------------------*/
/* Free a memory block */
/*------------------------------------------------------------------------*/
void ff_memfree (
void* mblock /* Pointer to the memory block to free (nothing to do if null) */
)
{
free(mblock); /* Free the memory block with POSIX API */
}
#endif
资源互斥:
#if FF_FS_REENTRANT
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
BYTE vol, /* Corresponding volume (logical drive number) */
FF_SYNC_t* sobj /* Pointer to return the created sync object */
);