Skip to content

Commit

Permalink
Merge pull request #3 from drizzi-novalabs/chibios16
Browse files Browse the repository at this point in the history
Ported to Chibios 16
  • Loading branch information
mabl authored Jul 8, 2017
2 parents 3d78ebe + 0f9b5f4 commit 2fc2cf9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
37 changes: 24 additions & 13 deletions fatfsWrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ struct wrapper_msg_base {
_wrapper_msg_base
};

struct wrapper_msg_pFATFSpTCHARvBYTE {
_wrapper_msg_base

FATFS* fatfsp;
TCHAR* string;
BYTE byte;
};

struct wrapper_msg_vBYTEpFATFS {
_wrapper_msg_base
Expand Down Expand Up @@ -286,17 +293,20 @@ struct wrapper_msg_pTCHARvINTpFILpTCHAR {
/**
* @brief Pointer to worker thread for synchronous communication.
*/
static Thread* workerThread = NULL;
static thread_t* workerThread = NULL;
static bool running = FALSE;

static WORKING_AREA(waFatFSWorkerThread, FATFS_WRP_WORKER_SIZE);
static THD_WORKING_AREA(waFatFSWorkerThread, FATFS_WRP_WORKER_SIZE);

static msg_t ThreadFatFSWorker(void *arg) {
static void ThreadFatFSWorker(void *arg) {
(void)arg;

Thread* p;
running = TRUE;

thread_t* p;

chRegSetThreadName("fatfsWorker");
while (!chThdShouldTerminate()) {
while (!chThdShouldTerminateX()) {

/* Wait for msg with work to do. */
p = chMsgWait();
Expand All @@ -314,9 +324,9 @@ static msg_t ThreadFatFSWorker(void *arg) {

#if HAS_MOUNT
case eFMOUNT: {
const struct wrapper_msg_vBYTEpFATFS* exmsg = \
(const struct wrapper_msg_vBYTEpFATFS*) msg;
msg->result = f_mount(exmsg->byte, exmsg->fatfsp);
const struct wrapper_msg_pFATFSpTCHARvBYTE* exmsg = \
(const struct wrapper_msg_pFATFSpTCHARvBYTE*) msg;
msg->result = f_mount(exmsg->fatfsp, exmsg->string, exmsg->byte);
break;
}
#endif /* HAS_MOUNT */
Expand Down Expand Up @@ -552,11 +562,11 @@ static msg_t ThreadFatFSWorker(void *arg) {
chMsgRelease(p, 0);
}

return 0;
running = FALSE;
}


Thread* wf_init (tprio_t priority) {
thread_t* wf_init (tprio_t priority) {
workerThread = chThdCreateStatic(waFatFSWorkerThread,
sizeof(waFatFSWorkerThread),
priority, ThreadFatFSWorker, NULL);
Expand Down Expand Up @@ -584,12 +594,13 @@ void wf_terminate (void) {
* @param fs Pointer to new file system object (NULL for unmount).
* @return
*/
FRESULT wf_mount (BYTE vol, FATFS* fs) {
struct wrapper_msg_vBYTEpFATFS msg;
FRESULT wf_mount (FATFS* fs, const TCHAR* path, BYTE opt) {
struct wrapper_msg_pFATFSpTCHARvBYTE msg;

msg.action = eFMOUNT;
msg.byte = vol;
msg.fatfsp = fs;
msg.string = (TCHAR*) path;
msg.byte = opt;

chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
Expand Down
5 changes: 3 additions & 2 deletions fatfsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
extern "C" {
#endif

Thread* wf_init (tprio_t priority);
thread_t* wf_init (tprio_t priority);
bool wf_is_running(void); /* Checks if the wrapper thread is running */
void wf_terminate (void);

FRESULT wf_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
FRESULT wf_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
FRESULT wf_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */
FRESULT wf_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
FRESULT wf_lseek (FIL*, DWORD); /* Move file pointer of a file object */
Expand Down

0 comments on commit 2fc2cf9

Please sign in to comment.