-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folded platform specific code into master branch
Using branches for ports, while flexible, was debatably a questionable abuse of git branches. The model proved to be unhelpfully annoying to manage and made the codebase unnecessarily distributed.
- Loading branch information
Showing
9 changed files
with
599 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
script: | ||
- git config user.email "test" | ||
- git config user.name "test" | ||
- git fetch origin posix:posix | ||
- git merge posix --no-commit | ||
- make test |
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,102 @@ | ||
#if defined(__MBED__) | ||
|
||
#include "events_tick.h" | ||
#include "events_sema.h" | ||
#include "events_mutex.h" | ||
|
||
#include <stdbool.h> | ||
#include "mbed.h" | ||
#ifdef MBED_CONF_RTOS_PRESENT | ||
#include "rtos.h" | ||
#endif | ||
|
||
|
||
// Ticker operations | ||
static class GlobalTicker { | ||
public: | ||
GlobalTicker() { | ||
_tick = 0; | ||
_timer.start(); | ||
_ticker.attach_us(this, &GlobalTicker::step, (1 << 16) * 1000); | ||
}; | ||
|
||
void step() { | ||
_timer.reset(); | ||
_tick += 1 << 16; | ||
} | ||
|
||
unsigned tick() { | ||
return _tick + (unsigned)_timer.read_ms(); | ||
} | ||
|
||
private: | ||
unsigned _tick; | ||
Timer _timer; | ||
Ticker _ticker; | ||
} gticker; | ||
|
||
unsigned events_tick() { | ||
return gticker.tick(); | ||
} | ||
|
||
|
||
// Mutex operations | ||
int events_mutex_create(events_mutex_t *m) { return 0; } | ||
void events_mutex_destroy(events_mutex_t *m) { } | ||
|
||
void events_mutex_lock(events_mutex_t *m) { | ||
*m = __get_PRIMASK(); | ||
__disable_irq(); | ||
} | ||
|
||
void events_mutex_unlock(events_mutex_t *m) { | ||
__set_PRIMASK(*m); | ||
} | ||
|
||
|
||
// Semaphore operations | ||
#ifdef MBED_CONF_RTOS_PRESENT | ||
|
||
static inline Semaphore *sema(events_sema_t *s) { | ||
return static_cast<Semaphore*>(*s); | ||
} | ||
|
||
int events_sema_create(events_sema_t *s) { | ||
*s = new Semaphore(0); | ||
return sema(s) ? 0 : -1; | ||
} | ||
|
||
void events_sema_destroy(events_sema_t *s) { | ||
delete sema(s); | ||
} | ||
|
||
void events_sema_release(events_sema_t *s) { | ||
sema(s)->release(); | ||
} | ||
|
||
bool events_sema_wait(events_sema_t *s, int ms) { | ||
int t = sema(s)->wait(ms < 0 ? osWaitForever : ms); | ||
return t > 0; | ||
} | ||
|
||
#else | ||
|
||
// Semaphore operations | ||
int events_sema_create(events_sema_t *s) { return 0; } | ||
void events_sema_destroy(events_sema_t *s) {} | ||
void events_sema_release(events_sema_t *s) {} | ||
|
||
static void events_sema_wakeup() {} | ||
|
||
bool events_sema_wait(events_sema_t *s, int ms) { | ||
Timeout timeout; | ||
timeout.attach_us(events_sema_wakeup, ms*1000); | ||
|
||
__WFI(); | ||
|
||
return true; | ||
} | ||
|
||
#endif | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#if defined(__unix__) | ||
|
||
#include "events_tick.h" | ||
#include "events_sema.h" | ||
#include "events_mutex.h" | ||
|
||
#include <time.h> | ||
|
||
|
||
// Tick operations | ||
#ifdef _POSIX_TIMERS | ||
|
||
unsigned events_tick(void) { | ||
struct timespec ts; | ||
clock_gettime(CLOCK_MONOTONIC, &ts); | ||
return (unsigned)(ts.tv_sec*1000 + ts.tv_nsec/1000000); | ||
} | ||
|
||
#else | ||
#include <sys/time.h> | ||
|
||
unsigned events_tick(void) { | ||
struct timeval tv; | ||
gettimeofday(&tv, 0); | ||
return (unsigned)(tv.tv_sec*1000 + tv.tv_usec/1000); | ||
} | ||
|
||
#endif | ||
|
||
|
||
// Mutex operations | ||
int events_mutex_create(events_mutex_t *m) { | ||
return pthread_mutex_init(m, 0); | ||
} | ||
|
||
void events_mutex_destroy(events_mutex_t *m) { | ||
pthread_mutex_destroy(m); | ||
} | ||
|
||
void events_mutex_lock(events_mutex_t *m) { | ||
pthread_mutex_lock(m); | ||
} | ||
|
||
void events_mutex_unlock(events_mutex_t *m) { | ||
pthread_mutex_unlock(m); | ||
} | ||
|
||
|
||
int events_sema_create(events_sema_t *s) { | ||
int err = pthread_mutex_init(&s->mutex, 0); | ||
if (err) { | ||
return err; | ||
} | ||
|
||
err = pthread_cond_init(&s->cond, 0); | ||
if (err) { | ||
return err; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
void events_sema_destroy(events_sema_t *s) { | ||
pthread_mutex_destroy(&s->mutex); | ||
pthread_cond_destroy(&s->cond); | ||
} | ||
|
||
void events_sema_release(events_sema_t *s) { | ||
pthread_cond_signal(&s->cond); | ||
} | ||
|
||
bool events_sema_wait(events_sema_t *s, int ms) { | ||
int err; | ||
pthread_mutex_lock(&s->mutex); | ||
|
||
if (ms < 0) { | ||
err = pthread_cond_wait(&s->cond, &s->mutex); | ||
} else { | ||
ms += events_tick(); | ||
struct timespec ts = { | ||
.tv_sec = ms/1000, | ||
.tv_nsec = ms*1000000, | ||
}; | ||
err = pthread_cond_timedwait(&s->cond, &s->mutex, &ts); | ||
} | ||
|
||
pthread_mutex_unlock(&s->mutex); | ||
return !err; | ||
} | ||
|
||
#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
File renamed without changes.
Oops, something went wrong.