The following is an example from the FatFs website:
FRESULT set_timestamp (
char *obj, /* Pointer to the file name */
int year,
int month,
int mday,
int hour,
int min,
int sec
)
{
FILINFO fno;
fno.fdate = (WORD)(((year - 1980) * 512U) | month * 32U | mday);
fno.ftime = (WORD)(hour * 2048U | min * 32U | sec / 2U);
return f_utime(obj, &fno);
If I try to use WORD, the compiler throws the following error:
called object 'WORD' is not a function or function pointer
How can I do the typecast WORD?
Thanks you,
Neil
Hi Neil Porven,
If you download the Fatfs source code from its official website:
FatFs - Generic FAT File System Module
You will find a header file named as: integer.h
The content in the integer.h is:
#ifndef _FF_INTEGER
#define _FF_INTEGER
#ifdef _WIN32 /* FatFs development platform */
#include <windows.h>
#include <tchar.h>
typedef unsigned __int64 QWORD;
#else /* Embedded platform */
/* These types MUST be 16-bit or 32-bit */
typedef int INT;
typedef unsigned int UINT;
/* This type MUST be 8-bit */
typedef unsigned char BYTE;
/* These types MUST be 16-bit */
typedef short SHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
/* These types MUST be 32-bit */
typedef long LONG;
typedef unsigned long DWORD;
/* This type MUST be 64-bit (Remove this for C89 compatibility) */
typedef unsigned long long QWORD;
#endif
#endif
So, you can include the integer.h in your set_timestamp function file.
Wish it helps you!
If you still have question, please contact me!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I noticed in FatFS that WORD is some places was actually referring to the WORD size of the micro -- Thats why I gave you a 32 bit value.
Looking at the maximum values for date and time from the equations you could also place the values into unsigned short int (16 bit).
I don't use a realtime clock -- so I fake a date/time based on the number of time tics since the micro started.
Here's my code.
dword xTaskGetTickCount(void);
DWORD get_fattime (void)
{
dword TM = xTaskGetTickCount(); // this is tics
word days, hours, min, sec;
TM *= portTICK_PERIOD_MS; // now have msec
TM /= 1000; // now seconds
days = TM / (60 *60 *24);
TM -= days * (60 * 60 * 24);
hours = TM / (60 * 60);
TM -= hours * (60 * 60);
min = TM / 60;
TM -= min * 60;
sec = TM;
if(sec > 60)
sec = 0;
return ((DWORD)(2016 - 1980) << 25) // Year 2014
| ((DWORD)7 << 21) // Month 7
| ((DWORD)(10+days) << 16) // Mday 10
| ((DWORD)hours << 11) // Hour 16
| ((DWORD)min << 5) // Min 0
| ((DWORD)sec >> 1); // Sec 0
}
The DWORD is from FatFS and is defined as
#define DWORD unsigned long.
Joe