This repository has been archived by the owner on Aug 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
5,359 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "event_flag.h" | ||
#include "common_defines.h" | ||
#include "check.h" | ||
|
||
#include <pthread.h> | ||
#include <time.h> | ||
|
||
#define FURI_EVENT_FLAG_MAX_BITS_EVENT_GROUPS 24U | ||
#define FURI_EVENT_FLAG_INVALID_BITS (~((1UL << FURI_EVENT_FLAG_MAX_BITS_EVENT_GROUPS) - 1U)) | ||
|
||
FuriEventFlag* furi_event_flag_alloc() { | ||
uint32_t* flags = malloc(sizeof(uint32_t)); | ||
return (FuriEventFlag*)flags; | ||
} | ||
|
||
void furi_event_flag_free(FuriEventFlag* instance) { | ||
free(instance); | ||
} | ||
|
||
uint32_t furi_event_flag_set(FuriEventFlag* instance, uint32_t flags) { | ||
furi_assert(instance); | ||
|
||
(*instance) = flags; | ||
return flags; | ||
} | ||
|
||
uint32_t furi_event_flag_clear(FuriEventFlag* instance, uint32_t flags) { | ||
furi_assert(instance); | ||
|
||
(*instance) = 0; | ||
return 0; | ||
} | ||
|
||
uint32_t furi_event_flag_get(FuriEventFlag* instance) { | ||
furi_assert(instance); | ||
|
||
return *instance; | ||
} | ||
|
||
bool done; | ||
|
||
typedef struct { | ||
FuriEventFlag* flag; | ||
uint32_t val; | ||
} FuriEventFlagCtx; | ||
|
||
static void* acquire_cb(void* ctx_) { | ||
FuriEventFlagCtx* ctx = ctx_; | ||
while((*ctx->flag) != ctx->val) | ||
furi_delay_tick(1); | ||
done = true; | ||
return NULL; | ||
} | ||
|
||
uint32_t furi_event_flag_wait( | ||
FuriEventFlag* instance, | ||
uint32_t flags, | ||
uint32_t options, | ||
uint32_t timeout) { | ||
UNUSED(options); | ||
|
||
furi_assert(instance); | ||
done = false; | ||
pthread_t thread_id; | ||
FuriEventFlagCtx ctx = { instance, flags }; | ||
pthread_create(&thread_id, NULL, acquire_cb, &ctx); | ||
uint64_t start_time = (uint64_t)time(NULL); | ||
while(true) { | ||
furi_delay_tick(1); | ||
if(done) break; | ||
if((uint64_t)time(NULL) >= start_time + timeout) { | ||
pthread_cancel(thread_id); | ||
return 0; | ||
} | ||
} | ||
return flags; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* @file event_flag.h | ||
* Furi Event Flag | ||
*/ | ||
#pragma once | ||
|
||
#include "base.h" | ||
#include "kernel.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef uint32_t FuriEventFlag; | ||
|
||
/** Allocate FuriEventFlag | ||
* | ||
* @return pointer to FuriEventFlag | ||
*/ | ||
FuriEventFlag* furi_event_flag_alloc(); | ||
|
||
/** Deallocate FuriEventFlag | ||
* | ||
* @param instance pointer to FuriEventFlag | ||
*/ | ||
void furi_event_flag_free(FuriEventFlag* instance); | ||
|
||
/** Set flags | ||
* | ||
* @param instance pointer to FuriEventFlag | ||
* @param[in] flags The flags | ||
* | ||
* @return Resulting flags or error (FuriStatus) | ||
*/ | ||
uint32_t furi_event_flag_set(FuriEventFlag* instance, uint32_t flags); | ||
|
||
/** Clear flags | ||
* | ||
* @param instance pointer to FuriEventFlag | ||
* @param[in] flags The flags | ||
* | ||
* @return Resulting flags or error (FuriStatus) | ||
*/ | ||
uint32_t furi_event_flag_clear(FuriEventFlag* instance, uint32_t flags); | ||
|
||
/** Get flags | ||
* | ||
* @param instance pointer to FuriEventFlag | ||
* | ||
* @return Resulting flags | ||
*/ | ||
uint32_t furi_event_flag_get(FuriEventFlag* instance); | ||
|
||
/** Wait flags | ||
* | ||
* @param instance pointer to FuriEventFlag | ||
* @param[in] flags The flags | ||
* @param[in] options The option flags | ||
* @param[in] timeout The timeout | ||
* | ||
* @return Resulting flags or error (FuriStatus) | ||
*/ | ||
uint32_t furi_event_flag_wait( | ||
FuriEventFlag* instance, | ||
uint32_t flags, | ||
uint32_t options, | ||
uint32_t timeout); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.