mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
core: uncrustify
This commit is contained in:
parent
f99bc894de
commit
8efe5960aa
@ -272,7 +272,7 @@ TEMPLATE_ATOMIC_OP_FETCH_N(nand, &, 8, ~) /* __atomic_nand_fetch_8 */
|
||||
*/
|
||||
void __atomic_load_c(size_t size, const void *src, void *dest, int memorder)
|
||||
{
|
||||
(void) memorder;
|
||||
(void)memorder;
|
||||
unsigned int mask = irq_disable();
|
||||
memcpy(dest, src, size);
|
||||
irq_restore(mask);
|
||||
@ -288,7 +288,7 @@ void __atomic_load_c(size_t size, const void *src, void *dest, int memorder)
|
||||
*/
|
||||
void __atomic_store_c(size_t size, void *dest, const void *src, int memorder)
|
||||
{
|
||||
(void) memorder;
|
||||
(void)memorder;
|
||||
unsigned int mask = irq_disable();
|
||||
memcpy(dest, src, size);
|
||||
irq_restore(mask);
|
||||
@ -303,9 +303,10 @@ void __atomic_store_c(size_t size, void *dest, const void *src, int memorder)
|
||||
* @param[in] ret put the old value from @p ptr in @p ret
|
||||
* @param[in] memorder memory ordering, ignored in this implementation
|
||||
*/
|
||||
void __atomic_exchange_c(size_t size, void *ptr, void *val, void *ret, int memorder)
|
||||
void __atomic_exchange_c(size_t size, void *ptr, void *val, void *ret,
|
||||
int memorder)
|
||||
{
|
||||
(void) memorder;
|
||||
(void)memorder;
|
||||
unsigned int mask = irq_disable();
|
||||
memcpy(ret, ptr, size);
|
||||
memcpy(ptr, val, size);
|
||||
@ -345,7 +346,8 @@ void __atomic_exchange_c(size_t size, void *ptr, void *val, void *ret, int memor
|
||||
* @return false otherwise
|
||||
*/
|
||||
bool __atomic_compare_exchange_c(size_t len, void *ptr, void *expected,
|
||||
void *desired, bool weak, int success_memorder, int failure_memorder)
|
||||
void *desired, bool weak, int success_memorder,
|
||||
int failure_memorder)
|
||||
{
|
||||
(void)weak;
|
||||
(void)success_memorder;
|
||||
@ -366,7 +368,8 @@ bool __atomic_compare_exchange_c(size_t len, void *ptr, void *expected,
|
||||
#if !defined(__llvm__) && !defined(__clang__)
|
||||
/* Memory barrier helper function, for platforms without barrier instructions */
|
||||
void __sync_synchronize(void) __attribute__((__weak__));
|
||||
void __sync_synchronize(void) {
|
||||
void __sync_synchronize(void)
|
||||
{
|
||||
/* ARMv4, ARMv5 do not have any hardware support for memory barriers,
|
||||
* This is a software only barrier and a no-op, and will likely break on SMP
|
||||
* systems, but we don't support any multi-CPU ARMv5 or ARMv4 boards in RIOT
|
||||
|
@ -63,6 +63,7 @@ unsigned bitarithm_bits_set(unsigned v)
|
||||
uint8_t bitarithm_bits_set_u32(uint32_t v)
|
||||
{
|
||||
uint8_t c;
|
||||
|
||||
for (c = 0; v; c++) {
|
||||
v &= v - 1; /* clear the least significant bit set */
|
||||
}
|
||||
|
@ -58,7 +58,8 @@ static void _cond_signal(cond_t *cond, bool broadcast)
|
||||
uint16_t min_prio = THREAD_PRIORITY_MIN + 1;
|
||||
|
||||
while ((next = list_remove_head(&cond->queue)) != NULL) {
|
||||
thread_t *process = container_of((clist_node_t *)next, thread_t, rq_entry);
|
||||
thread_t *process = container_of((clist_node_t *)next, thread_t,
|
||||
rq_entry);
|
||||
sched_set_status(process, STATUS_PENDING);
|
||||
uint16_t process_priority = process->priority;
|
||||
if (process_priority < min_prio) {
|
||||
|
@ -56,7 +56,7 @@ extern "C" {
|
||||
extern const char assert_crash_message[];
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define assert(ignore)((void) 0)
|
||||
#define assert(ignore)((void)0)
|
||||
#elif defined(DEBUG_ASSERT_VERBOSE)
|
||||
/**
|
||||
* @brief Function to handle failed assertion
|
||||
@ -101,9 +101,11 @@ NORETURN void _assert_failure(const char *file, unsigned line);
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/assert.html
|
||||
*/
|
||||
#define assert(cond) ((cond) ? (void)0 : _assert_failure(RIOT_FILE_RELATIVE, __LINE__))
|
||||
#define assert(cond) ((cond) ? (void)0 : _assert_failure(RIOT_FILE_RELATIVE, \
|
||||
__LINE__))
|
||||
#else
|
||||
#define assert(cond) ((cond) ? (void)0 : core_panic(PANIC_ASSERT_FAIL, assert_crash_message))
|
||||
#define assert(cond) ((cond) ? (void)0 : core_panic(PANIC_ASSERT_FAIL, \
|
||||
assert_crash_message))
|
||||
#endif
|
||||
|
||||
#if !defined __cplusplus
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "cpu_conf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -147,7 +147,8 @@ static inline unsigned bitarithm_lsb(unsigned v)
|
||||
{
|
||||
/* Source: http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
|
||||
extern const uint8_t MultiplyDeBruijnBitPosition[32];
|
||||
return MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27];
|
||||
return MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >>
|
||||
27];
|
||||
}
|
||||
#else
|
||||
{
|
||||
@ -157,7 +158,7 @@ static inline unsigned bitarithm_lsb(unsigned v)
|
||||
while ((v & 0x01) == 0) {
|
||||
v >>= 1;
|
||||
r++;
|
||||
};
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ extern "C" {
|
||||
* between different byte orders at compile time.
|
||||
*/
|
||||
typedef union __attribute__((packed)) {
|
||||
uint16_t u16; /**< 16 bit representation */
|
||||
uint8_t u8[2]; /**< 8 bit representation */
|
||||
uint16_t u16; /**< 16 bit representation */
|
||||
uint8_t u8[2]; /**< 8 bit representation */
|
||||
} le_uint16_t;
|
||||
|
||||
/**
|
||||
@ -48,9 +48,9 @@ typedef union __attribute__((packed)) {
|
||||
* between different byte orders at compile time.
|
||||
*/
|
||||
typedef union __attribute__((packed)) {
|
||||
uint32_t u32; /**< 32 bit representation */
|
||||
uint8_t u8[4]; /**< 8 bit representation */
|
||||
uint16_t u16[2]; /**< 16 bit representation */
|
||||
uint32_t u32; /**< 32 bit representation */
|
||||
uint8_t u8[4]; /**< 8 bit representation */
|
||||
uint16_t u16[2]; /**< 16 bit representation */
|
||||
le_uint16_t l16[2]; /**< little endian 16 bit representation */
|
||||
} le_uint32_t;
|
||||
|
||||
@ -60,10 +60,10 @@ typedef union __attribute__((packed)) {
|
||||
* between different byte orders at compile time.
|
||||
*/
|
||||
typedef union __attribute__((packed)) {
|
||||
uint64_t u64; /**< 64 bit representation */
|
||||
uint8_t u8[8]; /**< 8 bit representation */
|
||||
uint16_t u16[4]; /**< 16 bit representation */
|
||||
uint32_t u32[2]; /**< 32 bit representation */
|
||||
uint64_t u64; /**< 64 bit representation */
|
||||
uint8_t u8[8]; /**< 8 bit representation */
|
||||
uint16_t u16[4]; /**< 16 bit representation */
|
||||
uint32_t u32[2]; /**< 32 bit representation */
|
||||
le_uint16_t l16[4]; /**< little endian 16 bit representation */
|
||||
le_uint32_t l32[2]; /**< little endian 32 bit representation */
|
||||
} le_uint64_t;
|
||||
@ -74,8 +74,8 @@ typedef union __attribute__((packed)) {
|
||||
* between different byte orders at compile time.
|
||||
*/
|
||||
typedef union __attribute__((packed)) {
|
||||
uint16_t u16; /**< 16 bit representation */
|
||||
uint8_t u8[2]; /**< 8 bit representation */
|
||||
uint16_t u16; /**< 16 bit representation */
|
||||
uint8_t u8[2]; /**< 8 bit representation */
|
||||
} be_uint16_t;
|
||||
|
||||
/**
|
||||
@ -84,9 +84,9 @@ typedef union __attribute__((packed)) {
|
||||
* between different byte orders at compile time.
|
||||
*/
|
||||
typedef union __attribute__((packed)) {
|
||||
uint32_t u32; /**< 32 bit representation */
|
||||
uint8_t u8[4]; /**< 8 bit representation */
|
||||
uint16_t u16[2]; /**< 16 bit representation */
|
||||
uint32_t u32; /**< 32 bit representation */
|
||||
uint8_t u8[4]; /**< 8 bit representation */
|
||||
uint16_t u16[2]; /**< 16 bit representation */
|
||||
be_uint16_t b16[2]; /**< big endian 16 bit representation */
|
||||
} be_uint32_t;
|
||||
|
||||
@ -96,10 +96,10 @@ typedef union __attribute__((packed)) {
|
||||
* between different byte orders at compile time.
|
||||
*/
|
||||
typedef union __attribute__((packed)) {
|
||||
uint64_t u64; /**< 64 bit representation */
|
||||
uint8_t u8[8]; /**< 8 bit representation */
|
||||
uint16_t u16[4]; /**< 16 bit representation */
|
||||
uint32_t u32[2]; /**< 32 bit representation */
|
||||
uint64_t u64; /**< 64 bit representation */
|
||||
uint8_t u8[8]; /**< 8 bit representation */
|
||||
uint16_t u16[4]; /**< 16 bit representation */
|
||||
uint32_t u32[2]; /**< 32 bit representation */
|
||||
be_uint16_t b16[4]; /**< big endian 16 bit representation */
|
||||
be_uint32_t b32[2]; /**< big endian 32 bit representation */
|
||||
} be_uint64_t;
|
||||
@ -303,7 +303,7 @@ static inline uint64_t ntohll(uint64_t v);
|
||||
#ifdef HAVE_NO_BUILTIN_BSWAP16
|
||||
static inline unsigned short __builtin_bswap16(unsigned short a)
|
||||
{
|
||||
return (a<<8)|(a>>8);
|
||||
return (a << 8) | (a >> 8);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -333,36 +333,42 @@ static inline uint64_t byteorder_swapll(uint64_t v)
|
||||
static inline be_uint16_t byteorder_ltobs(le_uint16_t v)
|
||||
{
|
||||
be_uint16_t result = { byteorder_swaps(v.u16) };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline be_uint32_t byteorder_ltobl(le_uint32_t v)
|
||||
{
|
||||
be_uint32_t result = { byteorder_swapl(v.u32) };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline be_uint64_t byteorder_ltobll(le_uint64_t v)
|
||||
{
|
||||
be_uint64_t result = { byteorder_swapll(v.u64) };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline le_uint16_t byteorder_btols(be_uint16_t v)
|
||||
{
|
||||
le_uint16_t result = { byteorder_swaps(v.u16) };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline le_uint32_t byteorder_btoll(be_uint32_t v)
|
||||
{
|
||||
le_uint32_t result = { byteorder_swapl(v.u32) };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline le_uint64_t byteorder_btolll(be_uint64_t v)
|
||||
{
|
||||
le_uint64_t result = { byteorder_swapll(v.u64) };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -370,7 +376,7 @@ static inline le_uint64_t byteorder_btolll(be_uint64_t v)
|
||||
* @brief Swaps the byteorder according to the endianness
|
||||
*/
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
# define _byteorder_swap(V, T) (byteorder_swap##T((V)))
|
||||
# define _byteorder_swap(V, T) (byteorder_swap ## T((V)))
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
# define _byteorder_swap(V, T) (V)
|
||||
#else
|
||||
@ -380,18 +386,21 @@ static inline le_uint64_t byteorder_btolll(be_uint64_t v)
|
||||
static inline network_uint16_t byteorder_htons(uint16_t v)
|
||||
{
|
||||
network_uint16_t result = { _byteorder_swap(v, s) };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline network_uint32_t byteorder_htonl(uint32_t v)
|
||||
{
|
||||
network_uint32_t result = { _byteorder_swap(v, l) };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline network_uint64_t byteorder_htonll(uint64_t v)
|
||||
{
|
||||
network_uint64_t result = { _byteorder_swap(v, ll) };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -428,18 +437,21 @@ static inline uint64_t htonll(uint64_t v)
|
||||
static inline uint16_t ntohs(uint16_t v)
|
||||
{
|
||||
network_uint16_t input = { v };
|
||||
|
||||
return byteorder_ntohs(input);
|
||||
}
|
||||
|
||||
static inline uint32_t ntohl(uint32_t v)
|
||||
{
|
||||
network_uint32_t input = { v };
|
||||
|
||||
return byteorder_ntohl(input);
|
||||
}
|
||||
|
||||
static inline uint64_t ntohll(uint64_t v)
|
||||
{
|
||||
network_uint64_t input = { v };
|
||||
|
||||
return byteorder_ntohll(input);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* @ingroup core_util
|
||||
* @{
|
||||
*
|
||||
@ -40,7 +40,7 @@ typedef struct {
|
||||
/**
|
||||
* @brief Initialize cib_t to a given size.
|
||||
*/
|
||||
#define CIB_INIT(SIZE) { 0, 0, (SIZE) - 1 }
|
||||
#define CIB_INIT(SIZE) { 0, 0, (SIZE)-1 }
|
||||
|
||||
/**
|
||||
* @brief Initialize @p cib to 0 and set buffer size to @p size.
|
||||
@ -80,7 +80,7 @@ static inline unsigned int cib_avail(const cib_t *cib)
|
||||
*/
|
||||
static inline unsigned int cib_full(const cib_t *cib)
|
||||
{
|
||||
return ((int) cib_avail(cib)) > ((int) cib->mask);
|
||||
return ((int)cib_avail(cib)) > ((int)cib->mask);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +93,7 @@ static inline unsigned int cib_full(const cib_t *cib)
|
||||
static inline int cib_get(cib_t *__restrict cib)
|
||||
{
|
||||
if (cib_avail(cib)) {
|
||||
return (int) (cib->read_count++ & cib->mask);
|
||||
return (int)(cib->read_count++ & cib->mask);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -109,7 +109,7 @@ static inline int cib_get(cib_t *__restrict cib)
|
||||
static inline int cib_peek(cib_t *__restrict cib)
|
||||
{
|
||||
if (cib_avail(cib)) {
|
||||
return (int) (cib->read_count & cib->mask);
|
||||
return (int)(cib->read_count & cib->mask);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -126,7 +126,7 @@ static inline int cib_peek(cib_t *__restrict cib)
|
||||
*/
|
||||
static inline int cib_get_unsafe(cib_t *cib)
|
||||
{
|
||||
return (int) (cib->read_count++ & cib->mask);
|
||||
return (int)(cib->read_count++ & cib->mask);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,8 +141,8 @@ static inline int cib_put(cib_t *__restrict cib)
|
||||
unsigned int avail = cib_avail(cib);
|
||||
|
||||
/* We use a signed compare, because the mask is -1u for an empty CIB. */
|
||||
if ((int) avail <= (int) cib->mask) {
|
||||
return (int) (cib->write_count++ & cib->mask);
|
||||
if ((int)avail <= (int)cib->mask) {
|
||||
return (int)(cib->write_count++ & cib->mask);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -159,7 +159,7 @@ static inline int cib_put(cib_t *__restrict cib)
|
||||
*/
|
||||
static inline int cib_put_unsafe(cib_t *cib)
|
||||
{
|
||||
return (int) (cib->write_count++ & cib->mask);
|
||||
return (int)(cib->write_count++ & cib->mask);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -91,7 +91,7 @@
|
||||
#include "list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -252,9 +252,11 @@ static inline clist_node_t *clist_rpop(clist_node_t *list)
|
||||
* @returns predecessor of node if found
|
||||
* @returns NULL if node is not a list member
|
||||
*/
|
||||
static inline clist_node_t *clist_find_before(const clist_node_t *list, const clist_node_t *node)
|
||||
static inline clist_node_t *clist_find_before(const clist_node_t *list,
|
||||
const clist_node_t *node)
|
||||
{
|
||||
clist_node_t *pos = list->next;
|
||||
|
||||
if (!pos) {
|
||||
return NULL;
|
||||
}
|
||||
@ -280,9 +282,11 @@ static inline clist_node_t *clist_find_before(const clist_node_t *list, const cl
|
||||
* @returns node if found
|
||||
* @returns NULL if node is not a list member
|
||||
*/
|
||||
static inline clist_node_t *clist_find(const clist_node_t *list, const clist_node_t *node)
|
||||
static inline clist_node_t *clist_find(const clist_node_t *list,
|
||||
const clist_node_t *node)
|
||||
{
|
||||
clist_node_t *tmp = clist_find_before(list, node);
|
||||
|
||||
if (tmp) {
|
||||
return tmp->next;
|
||||
}
|
||||
@ -339,9 +343,12 @@ static inline clist_node_t *clist_remove(clist_node_t *list, clist_node_t *node)
|
||||
* @returns NULL on empty list or full traversal
|
||||
* @returns node that caused @p func(node, arg) to exit non-zero
|
||||
*/
|
||||
static inline clist_node_t *clist_foreach(clist_node_t *list, int(*func)(clist_node_t *, void *), void *arg)
|
||||
static inline clist_node_t *clist_foreach(clist_node_t *list, int (*func)(
|
||||
clist_node_t *,
|
||||
void *), void *arg)
|
||||
{
|
||||
clist_node_t *node = list->next;
|
||||
|
||||
if (node) {
|
||||
do {
|
||||
node = node->next;
|
||||
@ -432,6 +439,7 @@ static inline size_t clist_count(clist_node_t *list)
|
||||
{
|
||||
clist_node_t *node = list->next;
|
||||
size_t cnt = 0;
|
||||
|
||||
if (node) {
|
||||
do {
|
||||
node = node->next;
|
||||
|
@ -45,15 +45,16 @@ extern "C" {
|
||||
#ifdef DEVELHELP
|
||||
#include "cpu_conf.h"
|
||||
#define DEBUG_PRINT(...) \
|
||||
do { \
|
||||
if ((sched_active_thread == NULL) || \
|
||||
(sched_active_thread->stack_size >= THREAD_EXTRA_STACKSIZE_PRINTF)) { \
|
||||
printf(__VA_ARGS__); \
|
||||
} \
|
||||
else { \
|
||||
puts("Cannot debug, stack too small. Consider using DEBUG_PUTS()."); \
|
||||
} \
|
||||
} while (0)
|
||||
do { \
|
||||
if ((sched_active_thread == NULL) || \
|
||||
(sched_active_thread->stack_size >= \
|
||||
THREAD_EXTRA_STACKSIZE_PRINTF)) { \
|
||||
printf(__VA_ARGS__); \
|
||||
} \
|
||||
else { \
|
||||
puts("Cannot debug, stack too small. Consider using DEBUG_PUTS()."); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define DEBUG_PRINT(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* uncrustify gets mightily confused by these macros... */
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define KERNEL_INIT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -36,17 +36,17 @@
|
||||
# ifdef _POSIX_SSIZE_MAX
|
||||
# define SSIZE_MAX _POSIX_SSIZE_MAX
|
||||
# else
|
||||
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
|
||||
# define SSIZE_MAX ((ssize_t)(SIZE_MAX / 2))
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifdef MODULE_MSP430_COMMON
|
||||
typedef signed ssize_t;
|
||||
typedef signed ssize_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@
|
||||
#define LIFO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,7 @@
|
||||
#define LOG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -75,13 +75,13 @@ enum {
|
||||
*/
|
||||
#ifdef __clang__ /* following pragmas required for clang 3.8.0 */
|
||||
#define LOG(level, ...) do { \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wtautological-compare\"") \
|
||||
if ((level) <= LOG_LEVEL) log_write((level), __VA_ARGS__); } while (0U) \
|
||||
_Pragma("clang diagnostic pop")
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wtautological-compare\"") \
|
||||
if ((level) <= LOG_LEVEL) log_write((level), __VA_ARGS__); } while (0U) \
|
||||
_Pragma("clang diagnostic pop")
|
||||
#else
|
||||
#define LOG(level, ...) do { \
|
||||
if ((level) <= LOG_LEVEL) log_write((level), __VA_ARGS__); } while (0U)
|
||||
if ((level) <= LOG_LEVEL) log_write((level), __VA_ARGS__); } while (0U)
|
||||
#endif /* __clang__ */
|
||||
|
||||
/**
|
||||
|
@ -32,8 +32,8 @@ extern "C" {
|
||||
|
||||
/** Static initializer for mbox objects */
|
||||
#define MBOX_INIT(queue, queue_size) { \
|
||||
{0}, {0}, CIB_INIT(queue_size), queue \
|
||||
}
|
||||
{ 0 }, { 0 }, CIB_INIT(queue_size), queue \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Mailbox struct definition
|
||||
@ -59,9 +59,11 @@ enum {
|
||||
* @param[in] queue array of msg_t used as queue
|
||||
* @param[in] queue_size number of msg_t objects in queue
|
||||
*/
|
||||
static inline void mbox_init(mbox_t *mbox, msg_t *queue, unsigned int queue_size)
|
||||
static inline void mbox_init(mbox_t *mbox, msg_t *queue,
|
||||
unsigned int queue_size)
|
||||
{
|
||||
mbox_t m = MBOX_INIT(queue, queue_size);
|
||||
|
||||
*mbox = m;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -102,6 +102,7 @@ int _mutex_lock(mutex_t *mutex, volatile uint8_t *blocking);
|
||||
static inline int mutex_trylock(mutex_t *mutex)
|
||||
{
|
||||
volatile uint8_t blocking = 0;
|
||||
|
||||
return _mutex_lock(mutex, &blocking);
|
||||
}
|
||||
|
||||
@ -113,6 +114,7 @@ static inline int mutex_trylock(mutex_t *mutex)
|
||||
static inline void mutex_lock(mutex_t *mutex)
|
||||
{
|
||||
volatile uint8_t blocking = 1;
|
||||
|
||||
_mutex_lock(mutex, &blocking);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ extern "C" {
|
||||
* Required to use some C++11 headers with g++ on the native board.
|
||||
*/
|
||||
#define __CPU_SETSIZE 1024
|
||||
#define __NCPUBITS (8* sizeof(__cpu_mask))
|
||||
#define __NCPUBITS (8 * sizeof(__cpu_mask))
|
||||
typedef unsigned long int __cpu_mask;
|
||||
typedef struct {
|
||||
__cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "kernel_defines.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -38,18 +38,18 @@ typedef enum {
|
||||
PANIC_ASSERT_FAIL,
|
||||
PANIC_EXPECT_FAIL,
|
||||
#ifdef MODULE_CORTEXM_COMMON
|
||||
PANIC_NMI_HANDLER, /**< non maskable interrupt */
|
||||
PANIC_HARD_FAULT, /**< hard fault */
|
||||
PANIC_NMI_HANDLER, /**< non maskable interrupt */
|
||||
PANIC_HARD_FAULT, /**< hard fault */
|
||||
#if defined(CPU_ARCH_CORTEX_M3) || defined(CPU_ARCH_CORTEX_M4) || \
|
||||
defined(CPU_ARCH_CORTEX_M4F) || defined(CPU_ARCH_CORTEX_M7)
|
||||
PANIC_MEM_MANAGE, /**< memory controller interrupt */
|
||||
PANIC_BUS_FAULT, /**< bus fault */
|
||||
PANIC_USAGE_FAULT, /**< undefined instruction or unaligned access */
|
||||
PANIC_DEBUG_MON, /**< debug interrupt */
|
||||
PANIC_MEM_MANAGE, /**< memory controller interrupt */
|
||||
PANIC_BUS_FAULT, /**< bus fault */
|
||||
PANIC_USAGE_FAULT, /**< undefined instruction or unaligned access */
|
||||
PANIC_DEBUG_MON, /**< debug interrupt */
|
||||
#endif
|
||||
PANIC_DUMMY_HANDLER, /**< unhandled interrupt */
|
||||
PANIC_DUMMY_HANDLER, /**< unhandled interrupt */
|
||||
#endif
|
||||
PANIC_SSP, /**< stack smashing protector failure */
|
||||
PANIC_SSP, /**< stack smashing protector failure */
|
||||
PANIC_UNDEFINED
|
||||
} core_panic_t;
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -56,9 +56,10 @@ typedef struct {
|
||||
* pre-allocated priority_queue_node_t object, must not be NULL.
|
||||
*/
|
||||
static inline void priority_queue_node_init(
|
||||
priority_queue_node_t *priority_queue_node)
|
||||
priority_queue_node_t *priority_queue_node)
|
||||
{
|
||||
priority_queue_node_t qn = PRIORITY_QUEUE_NODE_INIT;
|
||||
|
||||
*priority_queue_node = qn;
|
||||
}
|
||||
|
||||
@ -78,6 +79,7 @@ static inline void priority_queue_node_init(
|
||||
static inline void priority_queue_init(priority_queue_t *priority_queue)
|
||||
{
|
||||
priority_queue_t q = PRIORITY_QUEUE_INIT;
|
||||
|
||||
*priority_queue = q;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ typedef struct {
|
||||
* @param[in] BUF Buffer to use for the ringbuffer. The size is deduced through `sizeof (BUF)`.
|
||||
* @returns The static initializer.
|
||||
*/
|
||||
#define RINGBUFFER_INIT(BUF) { (BUF), sizeof (BUF), 0, 0 }
|
||||
#define RINGBUFFER_INIT(BUF) { (BUF), sizeof(BUF), 0, 0 }
|
||||
|
||||
/**
|
||||
* @brief Initialize a ringbuffer.
|
||||
@ -55,7 +55,8 @@ typedef struct {
|
||||
* @param[in] buffer Buffer to use by rb.
|
||||
* @param[in] bufsize `sizeof (buffer)`
|
||||
*/
|
||||
static inline void ringbuffer_init(ringbuffer_t *__restrict rb, char *buffer, unsigned bufsize)
|
||||
static inline void ringbuffer_init(ringbuffer_t *__restrict rb, char *buffer,
|
||||
unsigned bufsize)
|
||||
{
|
||||
rb->buf = buffer;
|
||||
rb->size = bufsize;
|
||||
@ -84,7 +85,8 @@ int ringbuffer_add_one(ringbuffer_t *__restrict rb, char c);
|
||||
* @param[in] n Maximum number of elements to add.
|
||||
* @returns Number of elements actually added. 0 if rb is full.
|
||||
*/
|
||||
unsigned ringbuffer_add(ringbuffer_t *__restrict rb, const char *buf, unsigned n);
|
||||
unsigned ringbuffer_add(ringbuffer_t *__restrict rb, const char *buf,
|
||||
unsigned n);
|
||||
|
||||
/**
|
||||
* @brief Peek and remove oldest element from the ringbuffer.
|
||||
@ -135,7 +137,8 @@ static inline int ringbuffer_full(const ringbuffer_t *__restrict rb)
|
||||
* @param[in,out] rb Ringbuffer to query.
|
||||
* @returns number of available bytes
|
||||
*/
|
||||
static inline unsigned int ringbuffer_get_free(const ringbuffer_t *__restrict rb)
|
||||
static inline unsigned int ringbuffer_get_free(
|
||||
const ringbuffer_t *__restrict rb)
|
||||
{
|
||||
return rb->size - rb->avail;
|
||||
}
|
||||
@ -154,7 +157,8 @@ int ringbuffer_peek_one(const ringbuffer_t *__restrict rb);
|
||||
* @param[in] n Read at most n elements.
|
||||
* @returns Same as ringbuffer_get()
|
||||
*/
|
||||
unsigned ringbuffer_peek(const ringbuffer_t *__restrict rb, char *buf, unsigned n);
|
||||
unsigned ringbuffer_peek(const ringbuffer_t *__restrict rb, char *buf,
|
||||
unsigned n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "kernel_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -80,6 +80,7 @@ typedef struct rmutex_t {
|
||||
static inline void rmutex_init(rmutex_t *rmutex)
|
||||
{
|
||||
rmutex_t empty_rmutex = RMUTEX_INIT;
|
||||
|
||||
*rmutex = empty_rmutex;
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@
|
||||
#include "clist.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -122,7 +122,7 @@ typedef enum {
|
||||
* @{
|
||||
*/
|
||||
#define STATUS_ON_RUNQUEUE STATUS_RUNNING /**< to check if on run queue:
|
||||
`st >= STATUS_ON_RUNQUEUE` */
|
||||
`st >= STATUS_ON_RUNQUEUE` */
|
||||
#define STATUS_NOT_FOUND ((thread_status_t)-1) /**< Describes an illegal thread status */
|
||||
/** @} */
|
||||
/**
|
||||
|
@ -130,7 +130,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -228,7 +228,8 @@ struct _thread {
|
||||
* @brief Size of the main task's stack in bytes
|
||||
*/
|
||||
#ifndef THREAD_STACKSIZE_MAIN
|
||||
#define THREAD_STACKSIZE_MAIN (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF)
|
||||
#define THREAD_STACKSIZE_MAIN (THREAD_STACKSIZE_DEFAULT + \
|
||||
THREAD_EXTRA_STACKSIZE_PRINTF)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -270,7 +271,7 @@ struct _thread {
|
||||
* @def THREAD_PRIORITY_MIN
|
||||
* @brief Least priority a thread can have
|
||||
*/
|
||||
#define THREAD_PRIORITY_MIN (SCHED_PRIO_LEVELS-1)
|
||||
#define THREAD_PRIORITY_MIN (SCHED_PRIO_LEVELS - 1)
|
||||
|
||||
/**
|
||||
* @def THREAD_PRIORITY_IDLE
|
||||
@ -283,7 +284,8 @@ struct _thread {
|
||||
* @brief Priority of the main thread
|
||||
*/
|
||||
#ifndef THREAD_PRIORITY_MAIN
|
||||
#define THREAD_PRIORITY_MAIN (THREAD_PRIORITY_MIN - (SCHED_PRIO_LEVELS/2))
|
||||
#define THREAD_PRIORITY_MAIN (THREAD_PRIORITY_MIN - \
|
||||
(SCHED_PRIO_LEVELS / 2))
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -308,10 +310,10 @@ struct _thread {
|
||||
*/
|
||||
#define THREAD_CREATE_WOUT_YIELD (4)
|
||||
|
||||
/**
|
||||
* @brief Write markers into the thread's stack to measure stack usage (for
|
||||
* debugging and profiling purposes)
|
||||
*/
|
||||
/**
|
||||
* @brief Write markers into the thread's stack to measure stack usage (for
|
||||
* debugging and profiling purposes)
|
||||
*/
|
||||
#define THREAD_CREATE_STACKTEST (8)
|
||||
/** @} */
|
||||
|
||||
@ -338,14 +340,14 @@ struct _thread {
|
||||
* @return -EINVAL, if @p priority is greater than or equal to
|
||||
* @ref SCHED_PRIO_LEVELS
|
||||
* @return -EOVERFLOW, if there are too many threads running already
|
||||
*/
|
||||
*/
|
||||
kernel_pid_t thread_create(char *stack,
|
||||
int stacksize,
|
||||
uint8_t priority,
|
||||
int flags,
|
||||
thread_task_func_t task_func,
|
||||
void *arg,
|
||||
const char *name);
|
||||
int stacksize,
|
||||
uint8_t priority,
|
||||
int flags,
|
||||
thread_task_func_t task_func,
|
||||
void *arg,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* @brief Retrieve a thread control block by PID.
|
||||
@ -437,6 +439,7 @@ int thread_wakeup(kernel_pid_t pid);
|
||||
static inline kernel_pid_t thread_getpid(void)
|
||||
{
|
||||
extern volatile kernel_pid_t sched_active_pid;
|
||||
|
||||
return sched_active_pid;
|
||||
}
|
||||
|
||||
@ -450,7 +453,8 @@ static inline kernel_pid_t thread_getpid(void)
|
||||
*
|
||||
* @return stack pointer
|
||||
*/
|
||||
char *thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_start, int stack_size);
|
||||
char *thread_stack_init(thread_task_func_t task_func, void *arg,
|
||||
void *stack_start, int stack_size);
|
||||
|
||||
/**
|
||||
* @brief Add thread to list, sorted by priority (internal)
|
||||
|
@ -43,7 +43,9 @@ void lifo_insert(int *array, int i)
|
||||
|
||||
#ifdef DEVELHELP
|
||||
if ((array[index] != -1) && (array[0] != -1)) {
|
||||
LOG_WARNING("lifo_insert: overwriting array[%i] == %i with %i\n\n\n\t\tThe lifo is broken now.\n\n\n", index, array[index], array[0]);
|
||||
LOG_WARNING(
|
||||
"lifo_insert: overwriting array[%i] == %i with %i\n\n\n\t\tThe lifo is broken now.\n\n\n", index,
|
||||
array[index], array[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -63,7 +65,7 @@ int lifo_get(int *array)
|
||||
#ifdef DEVELHELP
|
||||
/* make sure a double insert does not result in an infinite
|
||||
* resource of values */
|
||||
array[head+1] = -1;
|
||||
array[head + 1] = -1;
|
||||
#endif
|
||||
|
||||
DEBUG("lifo_get: returning %i\n", head);
|
||||
|
35
core/mbox.c
35
core/mbox.c
@ -32,8 +32,8 @@ static void _wake_waiter(thread_t *thread, unsigned irqstate)
|
||||
{
|
||||
sched_set_status(thread, STATUS_PENDING);
|
||||
|
||||
DEBUG("mbox: Thread %"PRIkernel_pid": _wake_waiter(): waking up "
|
||||
"%"PRIkernel_pid".\n", sched_active_pid, thread->pid);
|
||||
DEBUG("mbox: Thread %" PRIkernel_pid ": _wake_waiter(): waking up "
|
||||
"%" PRIkernel_pid ".\n", sched_active_pid, thread->pid);
|
||||
|
||||
uint16_t process_priority = thread->priority;
|
||||
irq_restore(irqstate);
|
||||
@ -42,17 +42,17 @@ static void _wake_waiter(thread_t *thread, unsigned irqstate)
|
||||
|
||||
static void _wait(list_node_t *wait_list, unsigned irqstate)
|
||||
{
|
||||
DEBUG("mbox: Thread %"PRIkernel_pid" _wait(): going blocked.\n",
|
||||
sched_active_pid);
|
||||
DEBUG("mbox: Thread %" PRIkernel_pid " _wait(): going blocked.\n",
|
||||
sched_active_pid);
|
||||
|
||||
thread_t *me = (thread_t*) sched_active_thread;
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
sched_set_status(me, STATUS_MBOX_BLOCKED);
|
||||
thread_add_to_list(wait_list, me);
|
||||
irq_restore(irqstate);
|
||||
thread_yield();
|
||||
|
||||
DEBUG("mbox: Thread %"PRIkernel_pid" _wait(): woke up.\n",
|
||||
sched_active_pid);
|
||||
DEBUG("mbox: Thread %" PRIkernel_pid " _wait(): woke up.\n",
|
||||
sched_active_pid);
|
||||
}
|
||||
|
||||
int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking)
|
||||
@ -60,10 +60,12 @@ int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking)
|
||||
unsigned irqstate = irq_disable();
|
||||
|
||||
list_node_t *next = list_remove_head(&mbox->readers);
|
||||
|
||||
if (next) {
|
||||
DEBUG("mbox: Thread %"PRIkernel_pid" mbox 0x%08x: _tryput(): "
|
||||
"there's a waiter.\n", sched_active_pid, (unsigned)mbox);
|
||||
thread_t *thread = container_of((clist_node_t*)next, thread_t, rq_entry);
|
||||
DEBUG("mbox: Thread %" PRIkernel_pid " mbox 0x%08x: _tryput(): "
|
||||
"there's a waiter.\n", sched_active_pid, (unsigned)mbox);
|
||||
thread_t *thread =
|
||||
container_of((clist_node_t *)next, thread_t, rq_entry);
|
||||
*(msg_t *)thread->wait_data = *msg;
|
||||
_wake_waiter(thread, irqstate);
|
||||
return 1;
|
||||
@ -80,8 +82,8 @@ int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking)
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG("mbox: Thread %"PRIkernel_pid" mbox 0x%08x: _tryput(): "
|
||||
"queued message.\n", sched_active_pid, (unsigned)mbox);
|
||||
DEBUG("mbox: Thread %" PRIkernel_pid " mbox 0x%08x: _tryput(): "
|
||||
"queued message.\n", sched_active_pid, (unsigned)mbox);
|
||||
msg->sender_pid = sched_active_pid;
|
||||
/* copy msg into queue */
|
||||
mbox->msg_array[cib_put_unsafe(&mbox->cib)] = *msg;
|
||||
@ -95,13 +97,14 @@ int _mbox_get(mbox_t *mbox, msg_t *msg, int blocking)
|
||||
unsigned irqstate = irq_disable();
|
||||
|
||||
if (cib_avail(&mbox->cib)) {
|
||||
DEBUG("mbox: Thread %"PRIkernel_pid" mbox 0x%08x: _tryget(): "
|
||||
"got queued message.\n", sched_active_pid, (unsigned)mbox);
|
||||
DEBUG("mbox: Thread %" PRIkernel_pid " mbox 0x%08x: _tryget(): "
|
||||
"got queued message.\n", sched_active_pid, (unsigned)mbox);
|
||||
/* copy msg from queue */
|
||||
*msg = mbox->msg_array[cib_get_unsafe(&mbox->cib)];
|
||||
list_node_t *next = list_remove_head(&mbox->writers);
|
||||
if (next) {
|
||||
thread_t *thread = container_of((clist_node_t*)next, thread_t, rq_entry);
|
||||
thread_t *thread = container_of((clist_node_t *)next, thread_t,
|
||||
rq_entry);
|
||||
_wake_waiter(thread, irqstate);
|
||||
}
|
||||
else {
|
||||
@ -110,7 +113,7 @@ int _mbox_get(mbox_t *mbox, msg_t *msg, int blocking)
|
||||
return 1;
|
||||
}
|
||||
else if (blocking) {
|
||||
sched_active_thread->wait_data = (void*)msg;
|
||||
sched_active_thread->wait_data = (void *)msg;
|
||||
_wait(&mbox->readers, irqstate);
|
||||
/* sender has copied message */
|
||||
return 1;
|
||||
|
89
core/msg.c
89
core/msg.c
@ -37,11 +37,13 @@
|
||||
#include "debug.h"
|
||||
|
||||
static int _msg_receive(msg_t *m, int block);
|
||||
static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned state);
|
||||
static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block,
|
||||
unsigned state);
|
||||
|
||||
static int queue_msg(thread_t *target, const msg_t *m)
|
||||
{
|
||||
int n = cib_put(&(target->msg_queue));
|
||||
|
||||
if (n < 0) {
|
||||
DEBUG("queue_msg(): message queue is full (or there is none)\n");
|
||||
return 0;
|
||||
@ -79,7 +81,8 @@ int msg_try_send(msg_t *m, kernel_pid_t target_pid)
|
||||
return _msg_send(m, target_pid, false, irq_disable());
|
||||
}
|
||||
|
||||
static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned state)
|
||||
static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block,
|
||||
unsigned state)
|
||||
{
|
||||
#ifdef DEVELHELP
|
||||
if (!pid_is_valid(target_pid)) {
|
||||
@ -87,7 +90,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned sta
|
||||
}
|
||||
#endif /* DEVELHELP */
|
||||
|
||||
thread_t *target = (thread_t*) sched_threads[target_pid];
|
||||
thread_t *target = (thread_t *)sched_threads[target_pid];
|
||||
|
||||
m->sender_pid = sched_active_pid;
|
||||
|
||||
@ -97,7 +100,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned sta
|
||||
return -1;
|
||||
}
|
||||
|
||||
thread_t *me = (thread_t *) sched_active_thread;
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
|
||||
DEBUG("msg_send() %s:%i: Sending from %" PRIkernel_pid " to %" PRIkernel_pid
|
||||
". block=%i src->state=%i target->state=%i\n", RIOT_FILE_RELATIVE,
|
||||
@ -105,8 +108,9 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned sta
|
||||
block, me->status, target->status);
|
||||
|
||||
if (target->status != STATUS_RECEIVE_BLOCKED) {
|
||||
DEBUG("msg_send() %s:%i: Target %" PRIkernel_pid " is not RECEIVE_BLOCKED.\n",
|
||||
RIOT_FILE_RELATIVE, __LINE__, target_pid);
|
||||
DEBUG(
|
||||
"msg_send() %s:%i: Target %" PRIkernel_pid " is not RECEIVE_BLOCKED.\n",
|
||||
RIOT_FILE_RELATIVE, __LINE__, target_pid);
|
||||
|
||||
if (queue_msg(target, m)) {
|
||||
DEBUG("msg_send() %s:%i: Target %" PRIkernel_pid
|
||||
@ -120,8 +124,9 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned sta
|
||||
}
|
||||
|
||||
if (!block) {
|
||||
DEBUG("msg_send: %" PRIkernel_pid ": Receiver not waiting, block=%u\n",
|
||||
me->pid, block);
|
||||
DEBUG(
|
||||
"msg_send: %" PRIkernel_pid ": Receiver not waiting, block=%u\n",
|
||||
me->pid, block);
|
||||
irq_restore(state);
|
||||
return 0;
|
||||
}
|
||||
@ -129,7 +134,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned sta
|
||||
DEBUG("msg_send: %" PRIkernel_pid ": going send blocked.\n",
|
||||
me->pid);
|
||||
|
||||
me->wait_data = (void*) m;
|
||||
me->wait_data = (void *)m;
|
||||
|
||||
int newstatus;
|
||||
|
||||
@ -140,7 +145,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned sta
|
||||
newstatus = STATUS_SEND_BLOCKED;
|
||||
}
|
||||
|
||||
sched_set_status((thread_t*) me, newstatus);
|
||||
sched_set_status((thread_t *)me, newstatus);
|
||||
|
||||
thread_add_to_list(&(target->msg_waiters), me);
|
||||
|
||||
@ -160,7 +165,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned sta
|
||||
PRIkernel_pid " to %" PRIkernel_pid ".\n",
|
||||
me->pid, thread_getpid(), target_pid);
|
||||
/* copy msg to target */
|
||||
msg_t *target_message = (msg_t*) target->wait_data;
|
||||
msg_t *target_message = (msg_t *)target->wait_data;
|
||||
*target_message = *m;
|
||||
sched_set_status(target, STATUS_PENDING);
|
||||
|
||||
@ -176,7 +181,7 @@ int msg_send_to_self(msg_t *m)
|
||||
unsigned state = irq_disable();
|
||||
|
||||
m->sender_pid = sched_active_pid;
|
||||
int res = queue_msg((thread_t *) sched_active_thread, m);
|
||||
int res = queue_msg((thread_t *)sched_active_thread, m);
|
||||
|
||||
irq_restore(state);
|
||||
return res;
|
||||
@ -190,7 +195,7 @@ int msg_send_int(msg_t *m, kernel_pid_t target_pid)
|
||||
}
|
||||
#endif /* DEVELHELP */
|
||||
|
||||
thread_t *target = (thread_t *) sched_threads[target_pid];
|
||||
thread_t *target = (thread_t *)sched_threads[target_pid];
|
||||
|
||||
if (target == NULL) {
|
||||
DEBUG("msg_send_int(): target thread does not exist\n");
|
||||
@ -204,7 +209,7 @@ int msg_send_int(msg_t *m, kernel_pid_t target_pid)
|
||||
|
||||
|
||||
/* copy msg to target */
|
||||
msg_t *target_message = (msg_t*) target->wait_data;
|
||||
msg_t *target_message = (msg_t *)target->wait_data;
|
||||
*target_message = *m;
|
||||
sched_set_status(target, STATUS_PENDING);
|
||||
|
||||
@ -221,9 +226,9 @@ int msg_send_receive(msg_t *m, msg_t *reply, kernel_pid_t target_pid)
|
||||
{
|
||||
assert(sched_active_pid != target_pid);
|
||||
unsigned state = irq_disable();
|
||||
thread_t *me = (thread_t*) sched_threads[sched_active_pid];
|
||||
thread_t *me = (thread_t *)sched_threads[sched_active_pid];
|
||||
sched_set_status(me, STATUS_REPLY_BLOCKED);
|
||||
me->wait_data = (void*) reply;
|
||||
me->wait_data = (void *)reply;
|
||||
|
||||
/* we re-use (abuse) reply for sending, because wait_data might be
|
||||
* overwritten if the target is not in RECEIVE_BLOCKED */
|
||||
@ -236,12 +241,14 @@ int msg_reply(msg_t *m, msg_t *reply)
|
||||
{
|
||||
unsigned state = irq_disable();
|
||||
|
||||
thread_t *target = (thread_t*) sched_threads[m->sender_pid];
|
||||
thread_t *target = (thread_t *)sched_threads[m->sender_pid];
|
||||
|
||||
assert(target != NULL);
|
||||
|
||||
if (target->status != STATUS_REPLY_BLOCKED) {
|
||||
DEBUG("msg_reply(): %" PRIkernel_pid ": Target \"%" PRIkernel_pid
|
||||
"\" not waiting for reply.", sched_active_thread->pid, target->pid);
|
||||
"\" not waiting for reply.", sched_active_thread->pid,
|
||||
target->pid);
|
||||
irq_restore(state);
|
||||
return -1;
|
||||
}
|
||||
@ -249,7 +256,7 @@ int msg_reply(msg_t *m, msg_t *reply)
|
||||
DEBUG("msg_reply(): %" PRIkernel_pid ": Direct msg copy.\n",
|
||||
sched_active_thread->pid);
|
||||
/* copy msg to target */
|
||||
msg_t *target_message = (msg_t*) target->wait_data;
|
||||
msg_t *target_message = (msg_t *)target->wait_data;
|
||||
*target_message = *reply;
|
||||
sched_set_status(target, STATUS_PENDING);
|
||||
uint16_t target_prio = target->priority;
|
||||
@ -261,15 +268,16 @@ int msg_reply(msg_t *m, msg_t *reply)
|
||||
|
||||
int msg_reply_int(msg_t *m, msg_t *reply)
|
||||
{
|
||||
thread_t *target = (thread_t*) sched_threads[m->sender_pid];
|
||||
thread_t *target = (thread_t *)sched_threads[m->sender_pid];
|
||||
|
||||
if (target->status != STATUS_REPLY_BLOCKED) {
|
||||
DEBUG("msg_reply_int(): %" PRIkernel_pid ": Target \"%" PRIkernel_pid
|
||||
"\" not waiting for reply.", sched_active_thread->pid, target->pid);
|
||||
"\" not waiting for reply.", sched_active_thread->pid,
|
||||
target->pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg_t *target_message = (msg_t*) target->wait_data;
|
||||
msg_t *target_message = (msg_t *)target->wait_data;
|
||||
*target_message = *reply;
|
||||
sched_set_status(target, STATUS_PENDING);
|
||||
sched_context_switch_request = 1;
|
||||
@ -289,10 +297,11 @@ int msg_receive(msg_t *m)
|
||||
static int _msg_receive(msg_t *m, int block)
|
||||
{
|
||||
unsigned state = irq_disable();
|
||||
|
||||
DEBUG("_msg_receive: %" PRIkernel_pid ": _msg_receive.\n",
|
||||
sched_active_thread->pid);
|
||||
|
||||
thread_t *me = (thread_t*) sched_threads[sched_active_pid];
|
||||
thread_t *me = (thread_t *)sched_threads[sched_active_pid];
|
||||
|
||||
int queue_index = -1;
|
||||
|
||||
@ -307,23 +316,26 @@ static int _msg_receive(msg_t *m, int block)
|
||||
}
|
||||
|
||||
if (queue_index >= 0) {
|
||||
DEBUG("_msg_receive: %" PRIkernel_pid ": _msg_receive(): We've got a queued message.\n",
|
||||
sched_active_thread->pid);
|
||||
DEBUG(
|
||||
"_msg_receive: %" PRIkernel_pid ": _msg_receive(): We've got a queued message.\n",
|
||||
sched_active_thread->pid);
|
||||
*m = me->msg_array[queue_index];
|
||||
}
|
||||
else {
|
||||
me->wait_data = (void *) m;
|
||||
me->wait_data = (void *)m;
|
||||
}
|
||||
|
||||
list_node_t *next = list_remove_head(&me->msg_waiters);
|
||||
|
||||
if (next == NULL) {
|
||||
DEBUG("_msg_receive: %" PRIkernel_pid ": _msg_receive(): No thread in waiting list.\n",
|
||||
sched_active_thread->pid);
|
||||
DEBUG(
|
||||
"_msg_receive: %" PRIkernel_pid ": _msg_receive(): No thread in waiting list.\n",
|
||||
sched_active_thread->pid);
|
||||
|
||||
if (queue_index < 0) {
|
||||
DEBUG("_msg_receive(): %" PRIkernel_pid ": No msg in queue. Going blocked.\n",
|
||||
sched_active_thread->pid);
|
||||
DEBUG(
|
||||
"_msg_receive(): %" PRIkernel_pid ": No msg in queue. Going blocked.\n",
|
||||
sched_active_thread->pid);
|
||||
sched_set_status(me, STATUS_RECEIVE_BLOCKED);
|
||||
|
||||
irq_restore(state);
|
||||
@ -339,10 +351,12 @@ static int _msg_receive(msg_t *m, int block)
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
DEBUG("_msg_receive: %" PRIkernel_pid ": _msg_receive(): Waking up waiting thread.\n",
|
||||
sched_active_thread->pid);
|
||||
DEBUG(
|
||||
"_msg_receive: %" PRIkernel_pid ": _msg_receive(): Waking up waiting thread.\n",
|
||||
sched_active_thread->pid);
|
||||
|
||||
thread_t *sender = container_of((clist_node_t*)next, thread_t, rq_entry);
|
||||
thread_t *sender =
|
||||
container_of((clist_node_t *)next, thread_t, rq_entry);
|
||||
|
||||
if (queue_index >= 0) {
|
||||
/* We've already got a message from the queue. As there is a
|
||||
@ -352,7 +366,7 @@ static int _msg_receive(msg_t *m, int block)
|
||||
}
|
||||
|
||||
/* copy msg */
|
||||
msg_t *sender_msg = (msg_t*) sender->wait_data;
|
||||
msg_t *sender_msg = (msg_t *)sender->wait_data;
|
||||
*m = *sender_msg;
|
||||
|
||||
/* remove sender from queue */
|
||||
@ -378,7 +392,7 @@ int msg_avail(void)
|
||||
DEBUG("msg_available: %" PRIkernel_pid ": msg_available.\n",
|
||||
sched_active_thread->pid);
|
||||
|
||||
thread_t *me = (thread_t*) sched_active_thread;
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
|
||||
int queue_index = -1;
|
||||
|
||||
@ -391,7 +405,8 @@ int msg_avail(void)
|
||||
|
||||
void msg_init_queue(msg_t *array, int num)
|
||||
{
|
||||
thread_t *me = (thread_t*) sched_active_thread;
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
|
||||
me->msg_array = array;
|
||||
cib_init(&(me->msg_queue), num);
|
||||
}
|
||||
@ -400,7 +415,7 @@ void msg_queue_print(void)
|
||||
{
|
||||
unsigned state = irq_disable();
|
||||
|
||||
thread_t *thread =(thread_t *)sched_active_thread;
|
||||
thread_t *thread = (thread_t *)sched_active_thread;
|
||||
cib_t *msg_queue = &thread->msg_queue;
|
||||
msg_t *msg_array = thread->msg_array;
|
||||
unsigned int i = msg_queue->read_count & msg_queue->mask;
|
||||
|
10
core/mutex.c
10
core/mutex.c
@ -47,12 +47,12 @@ int _mutex_lock(mutex_t *mutex, volatile uint8_t *blocking)
|
||||
return 1;
|
||||
}
|
||||
else if (*blocking) {
|
||||
thread_t *me = (thread_t*)sched_active_thread;
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
DEBUG("PID[%" PRIkernel_pid "]: Adding node to mutex queue: prio: %"
|
||||
PRIu32 "\n", sched_active_pid, (uint32_t)me->priority);
|
||||
sched_set_status(me, STATUS_MUTEX_BLOCKED);
|
||||
if (mutex->queue.next == MUTEX_LOCKED) {
|
||||
mutex->queue.next = (list_node_t*)&me->rq_entry;
|
||||
mutex->queue.next = (list_node_t *)&me->rq_entry;
|
||||
mutex->queue.next->next = NULL;
|
||||
}
|
||||
else {
|
||||
@ -92,7 +92,7 @@ void mutex_unlock(mutex_t *mutex)
|
||||
|
||||
list_node_t *next = list_remove_head(&mutex->queue);
|
||||
|
||||
thread_t *process = container_of((clist_node_t*)next, thread_t, rq_entry);
|
||||
thread_t *process = container_of((clist_node_t *)next, thread_t, rq_entry);
|
||||
|
||||
DEBUG("mutex_unlock: waking up waiting thread %" PRIkernel_pid "\n",
|
||||
process->pid);
|
||||
@ -119,7 +119,7 @@ void mutex_unlock_and_sleep(mutex_t *mutex)
|
||||
}
|
||||
else {
|
||||
list_node_t *next = list_remove_head(&mutex->queue);
|
||||
thread_t *process = container_of((clist_node_t*)next, thread_t,
|
||||
thread_t *process = container_of((clist_node_t *)next, thread_t,
|
||||
rq_entry);
|
||||
DEBUG("PID[%" PRIkernel_pid "]: waking up waiter.\n", process->pid);
|
||||
sched_set_status(process, STATUS_PENDING);
|
||||
@ -130,7 +130,7 @@ void mutex_unlock_and_sleep(mutex_t *mutex)
|
||||
}
|
||||
|
||||
DEBUG("PID[%" PRIkernel_pid "]: going to sleep.\n", sched_active_pid);
|
||||
sched_set_status((thread_t*)sched_active_thread, STATUS_SLEEPING);
|
||||
sched_set_status((thread_t *)sched_active_thread, STATUS_SLEEPING);
|
||||
irq_restore(irqstate);
|
||||
thread_yield_higher();
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ void __attribute__((weak)) panic_arch(void)
|
||||
NORETURN void core_panic(core_panic_t crash_code, const char *message)
|
||||
{
|
||||
#ifdef NDEBUG
|
||||
(void) crash_code;
|
||||
(void)crash_code;
|
||||
#endif
|
||||
|
||||
if (crashed == 0) {
|
||||
|
@ -28,7 +28,7 @@
|
||||
void priority_queue_remove(priority_queue_t *root_, priority_queue_node_t *node)
|
||||
{
|
||||
/* The strict aliasing rules allow this assignment. */
|
||||
priority_queue_node_t *root = (priority_queue_node_t *) root_;
|
||||
priority_queue_node_t *root = (priority_queue_node_t *)root_;
|
||||
|
||||
while (root->next != NULL) {
|
||||
if (root->next == node) {
|
||||
@ -44,6 +44,7 @@ void priority_queue_remove(priority_queue_t *root_, priority_queue_node_t *node)
|
||||
priority_queue_node_t *priority_queue_remove_head(priority_queue_t *root)
|
||||
{
|
||||
priority_queue_node_t *head = root->first;
|
||||
|
||||
if (head) {
|
||||
root->first = head->next;
|
||||
}
|
||||
@ -53,7 +54,7 @@ priority_queue_node_t *priority_queue_remove_head(priority_queue_t *root)
|
||||
void priority_queue_add(priority_queue_t *root, priority_queue_node_t *new_obj)
|
||||
{
|
||||
/* The strict aliasing rules allow this assignment. */
|
||||
priority_queue_node_t *node = (priority_queue_node_t *) root;
|
||||
priority_queue_node_t *node = (priority_queue_node_t *)root;
|
||||
|
||||
while (node->next != NULL) {
|
||||
/* not trying to add the same node twice */
|
||||
@ -77,12 +78,14 @@ void priority_queue_print(priority_queue_t *root)
|
||||
printf("queue:\n");
|
||||
|
||||
for (priority_queue_node_t *node = root->first; node; node = node->next) {
|
||||
printf("Data: %u Priority: %lu\n", node->data, (unsigned long) node->priority);
|
||||
printf("Data: %u Priority: %lu\n", node->data,
|
||||
(unsigned long)node->priority);
|
||||
}
|
||||
}
|
||||
|
||||
void priority_queue_print_node(priority_queue_node_t *node)
|
||||
{
|
||||
printf("Data: %u Priority: %lu Next: %u\n", (unsigned int) node->data, (unsigned long) node->priority, (unsigned int)node->next);
|
||||
printf("Data: %u Priority: %lu Next: %u\n", (unsigned int)node->data,
|
||||
(unsigned long)node->priority, (unsigned int)node->next);
|
||||
}
|
||||
#endif
|
||||
|
@ -30,6 +30,7 @@
|
||||
static void add_tail(ringbuffer_t *restrict rb, char c)
|
||||
{
|
||||
unsigned pos = rb->start + rb->avail++;
|
||||
|
||||
if (pos >= rb->size) {
|
||||
pos -= rb->size;
|
||||
}
|
||||
@ -46,6 +47,7 @@ static void add_tail(ringbuffer_t *restrict rb, char c)
|
||||
static char get_head(ringbuffer_t *restrict rb)
|
||||
{
|
||||
char result = rb->buf[rb->start];
|
||||
|
||||
if ((--rb->avail == 0) || (++rb->start == rb->size)) {
|
||||
rb->start = 0;
|
||||
}
|
||||
@ -55,6 +57,7 @@ static char get_head(ringbuffer_t *restrict rb)
|
||||
unsigned ringbuffer_add(ringbuffer_t *restrict rb, const char *buf, unsigned n)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (ringbuffer_full(rb)) {
|
||||
break;
|
||||
@ -67,8 +70,9 @@ unsigned ringbuffer_add(ringbuffer_t *restrict rb, const char *buf, unsigned n)
|
||||
int ringbuffer_add_one(ringbuffer_t *restrict rb, char c)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
if (ringbuffer_full(rb)) {
|
||||
result = (unsigned char) get_head(rb);
|
||||
result = (unsigned char)get_head(rb);
|
||||
}
|
||||
add_tail(rb, c);
|
||||
return result;
|
||||
@ -77,7 +81,7 @@ int ringbuffer_add_one(ringbuffer_t *restrict rb, char c)
|
||||
int ringbuffer_get_one(ringbuffer_t *restrict rb)
|
||||
{
|
||||
if (!ringbuffer_empty(rb)) {
|
||||
return (unsigned char) get_head(rb);
|
||||
return (unsigned char)get_head(rb);
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
@ -132,11 +136,14 @@ unsigned ringbuffer_remove(ringbuffer_t *restrict rb, unsigned n)
|
||||
int ringbuffer_peek_one(const ringbuffer_t *restrict rb_)
|
||||
{
|
||||
ringbuffer_t rb = *rb_;
|
||||
|
||||
return ringbuffer_get_one(&rb);
|
||||
}
|
||||
|
||||
unsigned ringbuffer_peek(const ringbuffer_t *restrict rb_, char *buf, unsigned n)
|
||||
unsigned ringbuffer_peek(const ringbuffer_t *restrict rb_, char *buf,
|
||||
unsigned n)
|
||||
{
|
||||
ringbuffer_t rb = *rb_;
|
||||
|
||||
return ringbuffer_get(&rb, buf, n);
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ static int _lock(rmutex_t *rmutex, int trylock)
|
||||
kernel_pid_t owner;
|
||||
|
||||
/* try to lock the mutex */
|
||||
DEBUG("rmutex %" PRIi16" : trylock\n", thread_getpid());
|
||||
DEBUG("rmutex %" PRIi16 " : trylock\n", thread_getpid());
|
||||
if (mutex_trylock(&rmutex->mutex) == 0) {
|
||||
DEBUG("rmutex %" PRIi16" : mutex already held\n", thread_getpid());
|
||||
DEBUG("rmutex %" PRIi16 " : mutex already held\n", thread_getpid());
|
||||
/* Mutex is already held
|
||||
*
|
||||
* Case 1: Mutex is not held by me
|
||||
@ -79,12 +79,13 @@ static int _lock(rmutex_t *rmutex, int trylock)
|
||||
|
||||
/* ensure that owner is read atomically, since I need a consistent value */
|
||||
owner = atomic_load_explicit(&rmutex->owner, memory_order_relaxed);
|
||||
DEBUG("rmutex %" PRIi16" : mutex held by %" PRIi16" \n", thread_getpid(), owner);
|
||||
DEBUG("rmutex %" PRIi16 " : mutex held by %" PRIi16 " \n",
|
||||
thread_getpid(), owner);
|
||||
|
||||
/* Case 1: Mutex is not held by me */
|
||||
if (owner != thread_getpid()) {
|
||||
/* wait for the mutex */
|
||||
DEBUG("rmutex %" PRIi16" : locking mutex\n", thread_getpid());
|
||||
DEBUG("rmutex %" PRIi16 " : locking mutex\n", thread_getpid());
|
||||
|
||||
if (trylock) {
|
||||
return 0;
|
||||
@ -97,15 +98,16 @@ static int _lock(rmutex_t *rmutex, int trylock)
|
||||
/* Note: There is nothing to do for Case 2; refcount is incremented below */
|
||||
}
|
||||
|
||||
DEBUG("rmutex %" PRIi16" : I am now holding the mutex\n", thread_getpid());
|
||||
DEBUG("rmutex %" PRIi16 " : I am now holding the mutex\n", thread_getpid());
|
||||
|
||||
/* I am holding the recursive mutex */
|
||||
DEBUG("rmutex %" PRIi16" : setting the owner\n", thread_getpid());
|
||||
DEBUG("rmutex %" PRIi16 " : setting the owner\n", thread_getpid());
|
||||
|
||||
/* ensure that owner is written atomically, since others need a consistent value */
|
||||
atomic_store_explicit(&rmutex->owner, thread_getpid(), memory_order_relaxed);
|
||||
atomic_store_explicit(&rmutex->owner, thread_getpid(),
|
||||
memory_order_relaxed);
|
||||
|
||||
DEBUG("rmutex %" PRIi16" : increasing refs\n", thread_getpid());
|
||||
DEBUG("rmutex %" PRIi16 " : increasing refs\n", thread_getpid());
|
||||
|
||||
/* increase the refcount */
|
||||
rmutex->refcount++;
|
||||
@ -125,10 +127,11 @@ int rmutex_trylock(rmutex_t *rmutex)
|
||||
|
||||
void rmutex_unlock(rmutex_t *rmutex)
|
||||
{
|
||||
assert(atomic_load_explicit(&rmutex->owner,memory_order_relaxed) == thread_getpid());
|
||||
assert(atomic_load_explicit(&rmutex->owner,
|
||||
memory_order_relaxed) == thread_getpid());
|
||||
assert(rmutex->refcount > 0);
|
||||
|
||||
DEBUG("rmutex %" PRIi16" : decrementing refs refs\n", thread_getpid());
|
||||
DEBUG("rmutex %" PRIi16 " : decrementing refs refs\n", thread_getpid());
|
||||
|
||||
/* decrement refcount */
|
||||
rmutex->refcount--;
|
||||
@ -137,12 +140,13 @@ void rmutex_unlock(rmutex_t *rmutex)
|
||||
if (rmutex->refcount == 0) {
|
||||
/* if not release the mutex */
|
||||
|
||||
DEBUG("rmutex %" PRIi16" : resetting owner\n", thread_getpid());
|
||||
DEBUG("rmutex %" PRIi16 " : resetting owner\n", thread_getpid());
|
||||
|
||||
/* ensure that owner is written only once */
|
||||
atomic_store_explicit(&rmutex->owner, KERNEL_PID_UNDEF, memory_order_relaxed);
|
||||
atomic_store_explicit(&rmutex->owner, KERNEL_PID_UNDEF,
|
||||
memory_order_relaxed);
|
||||
|
||||
DEBUG("rmutex %" PRIi16" : releasing mutex\n", thread_getpid());
|
||||
DEBUG("rmutex %" PRIi16 " : releasing mutex\n", thread_getpid());
|
||||
|
||||
mutex_unlock(&rmutex->mutex);
|
||||
}
|
||||
|
54
core/sched.c
54
core/sched.c
@ -54,9 +54,11 @@ static uint32_t runqueue_bitcache = 0;
|
||||
|
||||
/* Needed by OpenOCD to read sched_threads */
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#define FORCE_USED_SECTION __attribute__((used)) __attribute__((section ("__OPENOCD,__openocd")))
|
||||
#define FORCE_USED_SECTION __attribute__((used)) __attribute__((section( \
|
||||
"__OPENOCD,__openocd")))
|
||||
#else
|
||||
#define FORCE_USED_SECTION __attribute__((used)) __attribute__((section (".openocd")))
|
||||
#define FORCE_USED_SECTION __attribute__((used)) __attribute__((section( \
|
||||
".openocd")))
|
||||
#endif
|
||||
|
||||
FORCE_USED_SECTION
|
||||
@ -70,7 +72,8 @@ const uint8_t _tcb_name_offset = offsetof(thread_t, name);
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_SCHED_CB
|
||||
static void (*sched_cb) (kernel_pid_t active_thread, kernel_pid_t next_thread) = NULL;
|
||||
static void (*sched_cb) (kernel_pid_t active_thread,
|
||||
kernel_pid_t next_thread) = NULL;
|
||||
#endif
|
||||
|
||||
int __attribute__((used)) sched_run(void)
|
||||
@ -83,7 +86,8 @@ int __attribute__((used)) sched_run(void)
|
||||
* since the threading should not be started before at least the idle thread was started.
|
||||
*/
|
||||
int nextrq = bitarithm_lsb(runqueue_bitcache);
|
||||
thread_t *next_thread = container_of(sched_runqueues[nextrq].next->next, thread_t, rq_entry);
|
||||
thread_t *next_thread = container_of(sched_runqueues[nextrq].next->next,
|
||||
thread_t, rq_entry);
|
||||
|
||||
DEBUG(
|
||||
"sched_run: active thread: %" PRIkernel_pid ", next thread: %" PRIkernel_pid "\n",
|
||||
@ -103,8 +107,11 @@ int __attribute__((used)) sched_run(void)
|
||||
}
|
||||
|
||||
#ifdef SCHED_TEST_STACK
|
||||
if (*((uintptr_t *) active_thread->stack_start) != (uintptr_t) active_thread->stack_start) {
|
||||
LOG_WARNING("scheduler(): stack overflow detected, pid=%" PRIkernel_pid "\n", active_thread->pid);
|
||||
if (*((uintptr_t *)active_thread->stack_start) !=
|
||||
(uintptr_t)active_thread->stack_start) {
|
||||
LOG_WARNING(
|
||||
"scheduler(): stack overflow detected, pid=%" PRIkernel_pid "\n",
|
||||
active_thread->pid);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -120,14 +127,14 @@ int __attribute__((used)) sched_run(void)
|
||||
|
||||
next_thread->status = STATUS_RUNNING;
|
||||
sched_active_pid = next_thread->pid;
|
||||
sched_active_thread = (volatile thread_t *) next_thread;
|
||||
sched_active_thread = (volatile thread_t *)next_thread;
|
||||
|
||||
#ifdef MODULE_MPU_STACK_GUARD
|
||||
mpu_configure(
|
||||
2, /* MPU region 2 */
|
||||
(uintptr_t)sched_active_thread->stack_start + 31, /* Base Address (rounded up) */
|
||||
MPU_ATTR(1, AP_RO_RO, 0, 1, 0, 1, MPU_SIZE_32B) /* Attributes and Size */
|
||||
);
|
||||
2, /* MPU region 2 */
|
||||
(uintptr_t)sched_active_thread->stack_start + 31, /* Base Address (rounded up) */
|
||||
MPU_ATTR(1, AP_RO_RO, 0, 1, 0, 1, MPU_SIZE_32B) /* Attributes and Size */
|
||||
);
|
||||
|
||||
mpu_enable();
|
||||
#endif
|
||||
@ -141,16 +148,19 @@ void sched_set_status(thread_t *process, thread_status_t status)
|
||||
{
|
||||
if (status >= STATUS_ON_RUNQUEUE) {
|
||||
if (!(process->status >= STATUS_ON_RUNQUEUE)) {
|
||||
DEBUG("sched_set_status: adding thread %" PRIkernel_pid " to runqueue %" PRIu8 ".\n",
|
||||
process->pid, process->priority);
|
||||
clist_rpush(&sched_runqueues[process->priority], &(process->rq_entry));
|
||||
DEBUG(
|
||||
"sched_set_status: adding thread %" PRIkernel_pid " to runqueue %" PRIu8 ".\n",
|
||||
process->pid, process->priority);
|
||||
clist_rpush(&sched_runqueues[process->priority],
|
||||
&(process->rq_entry));
|
||||
runqueue_bitcache |= 1 << process->priority;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (process->status >= STATUS_ON_RUNQUEUE) {
|
||||
DEBUG("sched_set_status: removing thread %" PRIkernel_pid " from runqueue %" PRIu8 ".\n",
|
||||
process->pid, process->priority);
|
||||
DEBUG(
|
||||
"sched_set_status: removing thread %" PRIkernel_pid " from runqueue %" PRIu8 ".\n",
|
||||
process->pid, process->priority);
|
||||
clist_lpop(&sched_runqueues[process->priority]);
|
||||
|
||||
if (!sched_runqueues[process->priority].next) {
|
||||
@ -164,13 +174,14 @@ void sched_set_status(thread_t *process, thread_status_t status)
|
||||
|
||||
void sched_switch(uint16_t other_prio)
|
||||
{
|
||||
thread_t *active_thread = (thread_t *) sched_active_thread;
|
||||
thread_t *active_thread = (thread_t *)sched_active_thread;
|
||||
uint16_t current_prio = active_thread->priority;
|
||||
int on_runqueue = (active_thread->status >= STATUS_ON_RUNQUEUE);
|
||||
|
||||
DEBUG("sched_switch: active pid=%" PRIkernel_pid" prio=%" PRIu16 " on_runqueue=%i "
|
||||
DEBUG("sched_switch: active pid=%" PRIkernel_pid " prio=%" PRIu16 " on_runqueue=%i "
|
||||
", other_prio=%" PRIu16 "\n",
|
||||
active_thread->pid, current_prio, on_runqueue, other_prio);
|
||||
active_thread->pid, current_prio, on_runqueue,
|
||||
other_prio);
|
||||
|
||||
if (!on_runqueue || (current_prio > other_prio)) {
|
||||
if (irq_is_in()) {
|
||||
@ -189,9 +200,10 @@ void sched_switch(uint16_t other_prio)
|
||||
|
||||
NORETURN void sched_task_exit(void)
|
||||
{
|
||||
DEBUG("sched_task_exit: ending thread %" PRIkernel_pid "...\n", sched_active_thread->pid);
|
||||
DEBUG("sched_task_exit: ending thread %" PRIkernel_pid "...\n",
|
||||
sched_active_thread->pid);
|
||||
|
||||
(void) irq_disable();
|
||||
(void)irq_disable();
|
||||
sched_threads[sched_active_pid] = NULL;
|
||||
sched_num_threads--;
|
||||
|
||||
|
@ -41,6 +41,7 @@ volatile thread_t *thread_get(kernel_pid_t pid)
|
||||
thread_status_t thread_getstatus(kernel_pid_t pid)
|
||||
{
|
||||
volatile thread_t *thread = thread_get(pid);
|
||||
|
||||
return thread ? thread->status : STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
@ -77,7 +78,7 @@ int thread_kill_zombie(kernel_pid_t pid)
|
||||
|
||||
int result = (int)STATUS_NOT_FOUND;
|
||||
|
||||
thread_t *thread = (thread_t *) thread_get(pid);
|
||||
thread_t *thread = (thread_t *)thread_get(pid);
|
||||
|
||||
if (!thread) {
|
||||
DEBUG("thread_kill: Thread does not exist!\n");
|
||||
@ -116,7 +117,7 @@ int thread_wakeup(kernel_pid_t pid)
|
||||
|
||||
unsigned old_state = irq_disable();
|
||||
|
||||
thread_t *thread = (thread_t *) thread_get(pid);
|
||||
thread_t *thread = (thread_t *)thread_get(pid);
|
||||
|
||||
if (!thread) {
|
||||
DEBUG("thread_wakeup: Thread does not exist!\n");
|
||||
@ -143,6 +144,7 @@ void thread_yield(void)
|
||||
{
|
||||
unsigned old_state = irq_disable();
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
|
||||
if (me->status >= STATUS_ON_RUNQUEUE) {
|
||||
clist_lpoprpush(&sched_runqueues[me->priority]);
|
||||
}
|
||||
@ -153,13 +155,14 @@ void thread_yield(void)
|
||||
|
||||
void thread_add_to_list(list_node_t *list, thread_t *thread)
|
||||
{
|
||||
assert (thread->status < STATUS_ON_RUNQUEUE);
|
||||
assert(thread->status < STATUS_ON_RUNQUEUE);
|
||||
|
||||
uint16_t my_prio = thread->priority;
|
||||
list_node_t *new_node = (list_node_t*)&thread->rq_entry;
|
||||
list_node_t *new_node = (list_node_t *)&thread->rq_entry;
|
||||
|
||||
while (list->next) {
|
||||
thread_t *list_entry = container_of((clist_node_t*)list->next, thread_t, rq_entry);
|
||||
thread_t *list_entry = container_of((clist_node_t *)list->next,
|
||||
thread_t, rq_entry);
|
||||
if (list_entry->priority > my_prio) {
|
||||
break;
|
||||
}
|
||||
@ -177,16 +180,18 @@ uintptr_t thread_measure_stack_free(char *stack)
|
||||
|
||||
/* assume that the comparison fails before or after end of stack */
|
||||
/* assume that the stack grows "downwards" */
|
||||
while (*stackp == (uintptr_t) stackp) {
|
||||
while (*stackp == (uintptr_t)stackp) {
|
||||
stackp++;
|
||||
}
|
||||
|
||||
uintptr_t space_free = (uintptr_t) stackp - (uintptr_t) stack;
|
||||
uintptr_t space_free = (uintptr_t)stackp - (uintptr_t)stack;
|
||||
return space_free;
|
||||
}
|
||||
#endif
|
||||
|
||||
kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, int flags, thread_task_func_t function, void *arg, const char *name)
|
||||
kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority,
|
||||
int flags, thread_task_func_t function, void *arg,
|
||||
const char *name)
|
||||
{
|
||||
if (priority >= SCHED_PRIO_LEVELS) {
|
||||
return -EINVAL;
|
||||
@ -195,11 +200,11 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, int fla
|
||||
#ifdef DEVELHELP
|
||||
int total_stacksize = stacksize;
|
||||
#else
|
||||
(void) name;
|
||||
(void)name;
|
||||
#endif
|
||||
|
||||
/* align the stack on a 16/32bit boundary */
|
||||
uintptr_t misalignment = (uintptr_t) stack % ALIGN_OF(void *);
|
||||
uintptr_t misalignment = (uintptr_t)stack % ALIGN_OF(void *);
|
||||
if (misalignment) {
|
||||
misalignment = ALIGN_OF(void *) - misalignment;
|
||||
stack += misalignment;
|
||||
@ -216,22 +221,22 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, int fla
|
||||
DEBUG("thread_create: stacksize is too small!\n");
|
||||
}
|
||||
/* allocate our thread control block at the top of our stackspace */
|
||||
thread_t *thread = (thread_t *) (stack + stacksize);
|
||||
thread_t *thread = (thread_t *)(stack + stacksize);
|
||||
|
||||
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK)
|
||||
if (flags & THREAD_CREATE_STACKTEST) {
|
||||
/* assign each int of the stack the value of it's address */
|
||||
uintptr_t *stackmax = (uintptr_t *) (stack + stacksize);
|
||||
uintptr_t *stackp = (uintptr_t *) stack;
|
||||
uintptr_t *stackmax = (uintptr_t *)(stack + stacksize);
|
||||
uintptr_t *stackp = (uintptr_t *)stack;
|
||||
|
||||
while (stackp < stackmax) {
|
||||
*stackp = (uintptr_t) stackp;
|
||||
*stackp = (uintptr_t)stackp;
|
||||
stackp++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* create stack guard */
|
||||
*(uintptr_t *) stack = (uintptr_t) stack;
|
||||
*(uintptr_t *)stack = (uintptr_t)stack;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -257,7 +262,8 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, int fla
|
||||
thread->pid = pid;
|
||||
thread->sp = thread_stack_init(function, arg, stack, stacksize);
|
||||
|
||||
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) || defined(MODULE_MPU_STACK_GUARD)
|
||||
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) || \
|
||||
defined(MODULE_MPU_STACK_GUARD)
|
||||
thread->stack_start = stack;
|
||||
#endif
|
||||
|
||||
@ -280,7 +286,8 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, int fla
|
||||
|
||||
sched_num_threads++;
|
||||
|
||||
DEBUG("Created thread %s. PID: %" PRIkernel_pid ". Priority: %u.\n", name, thread->pid, priority);
|
||||
DEBUG("Created thread %s. PID: %" PRIkernel_pid ". Priority: %u.\n", name,
|
||||
thread->pid, priority);
|
||||
|
||||
if (flags & THREAD_CREATE_SLEEPING) {
|
||||
sched_set_status(thread, STATUS_SLEEPING);
|
||||
|
@ -26,19 +26,23 @@
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
static thread_flags_t _thread_flags_clear_atomic(thread_t *thread, thread_flags_t mask)
|
||||
static thread_flags_t _thread_flags_clear_atomic(thread_t *thread,
|
||||
thread_flags_t mask)
|
||||
{
|
||||
unsigned state = irq_disable();
|
||||
|
||||
mask &= thread->flags;
|
||||
thread->flags &= ~mask;
|
||||
irq_restore(state);
|
||||
return mask;
|
||||
}
|
||||
|
||||
static void _thread_flags_wait(thread_flags_t mask, thread_t *thread, unsigned threadstate, unsigned irqstate)
|
||||
static void _thread_flags_wait(thread_flags_t mask, thread_t *thread,
|
||||
unsigned threadstate, unsigned irqstate)
|
||||
{
|
||||
DEBUG("_thread_flags_wait: me->flags=0x%08x me->mask=0x%08x. going blocked.\n",
|
||||
(unsigned)thread->flags, (unsigned)mask);
|
||||
DEBUG(
|
||||
"_thread_flags_wait: me->flags=0x%08x me->mask=0x%08x. going blocked.\n",
|
||||
(unsigned)thread->flags, (unsigned)mask);
|
||||
|
||||
thread->wait_data = (void *)(unsigned)mask;
|
||||
sched_set_status(thread, threadstate);
|
||||
@ -48,16 +52,19 @@ static void _thread_flags_wait(thread_flags_t mask, thread_t *thread, unsigned t
|
||||
|
||||
thread_flags_t thread_flags_clear(thread_flags_t mask)
|
||||
{
|
||||
thread_t *me = (thread_t*) sched_active_thread;
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
|
||||
mask = _thread_flags_clear_atomic(me, mask);
|
||||
DEBUG("thread_flags_clear(): pid %"PRIkernel_pid" clearing 0x%08x\n", thread_getpid(), mask);
|
||||
DEBUG("thread_flags_clear(): pid %" PRIkernel_pid " clearing 0x%08x\n",
|
||||
thread_getpid(), mask);
|
||||
return mask;
|
||||
}
|
||||
|
||||
static void _thread_flags_wait_any(thread_flags_t mask)
|
||||
{
|
||||
thread_t *me = (thread_t*) sched_active_thread;
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
unsigned state = irq_disable();
|
||||
|
||||
if (!(me->flags & mask)) {
|
||||
_thread_flags_wait(mask, me, STATUS_FLAG_BLOCKED_ANY, state);
|
||||
}
|
||||
@ -68,7 +75,8 @@ static void _thread_flags_wait_any(thread_flags_t mask)
|
||||
|
||||
thread_flags_t thread_flags_wait_any(thread_flags_t mask)
|
||||
{
|
||||
thread_t *me = (thread_t*) sched_active_thread;
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
|
||||
_thread_flags_wait_any(mask);
|
||||
return _thread_flags_clear_atomic(me, mask);
|
||||
}
|
||||
@ -76,7 +84,7 @@ thread_flags_t thread_flags_wait_any(thread_flags_t mask)
|
||||
thread_flags_t thread_flags_wait_one(thread_flags_t mask)
|
||||
{
|
||||
_thread_flags_wait_any(mask);
|
||||
thread_t *me = (thread_t*) sched_active_thread;
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
thread_flags_t tmp = me->flags & mask;
|
||||
/* clear all but least significant bit */
|
||||
tmp &= (~tmp + 1);
|
||||
@ -86,9 +94,12 @@ thread_flags_t thread_flags_wait_one(thread_flags_t mask)
|
||||
thread_flags_t thread_flags_wait_all(thread_flags_t mask)
|
||||
{
|
||||
unsigned state = irq_disable();
|
||||
thread_t *me = (thread_t*) sched_active_thread;
|
||||
thread_t *me = (thread_t *)sched_active_thread;
|
||||
|
||||
if (!((me->flags & mask) == mask)) {
|
||||
DEBUG("thread_flags_wait_all(): pid %"PRIkernel_pid" waiting for %08x\n", thread_getpid(), (unsigned)mask);
|
||||
DEBUG(
|
||||
"thread_flags_wait_all(): pid %" PRIkernel_pid " waiting for %08x\n",
|
||||
thread_getpid(), (unsigned)mask);
|
||||
_thread_flags_wait(mask, me, STATUS_FLAG_BLOCKED_ALL, state);
|
||||
}
|
||||
else {
|
||||
@ -102,7 +113,8 @@ inline int __attribute__((always_inline)) thread_flags_wake(thread_t *thread)
|
||||
{
|
||||
unsigned wakeup;
|
||||
thread_flags_t mask = (uint16_t)(unsigned)thread->wait_data;
|
||||
switch(thread->status) {
|
||||
|
||||
switch (thread->status) {
|
||||
case STATUS_FLAG_BLOCKED_ANY:
|
||||
wakeup = (thread->flags & mask);
|
||||
break;
|
||||
@ -115,7 +127,8 @@ inline int __attribute__((always_inline)) thread_flags_wake(thread_t *thread)
|
||||
}
|
||||
|
||||
if (wakeup) {
|
||||
DEBUG("_thread_flags_wake(): waking up pid %"PRIkernel_pid"\n", thread->pid);
|
||||
DEBUG("_thread_flags_wake(): waking up pid %" PRIkernel_pid "\n",
|
||||
thread->pid);
|
||||
sched_set_status(thread, STATUS_PENDING);
|
||||
sched_context_switch_request = 1;
|
||||
}
|
||||
@ -125,7 +138,8 @@ inline int __attribute__((always_inline)) thread_flags_wake(thread_t *thread)
|
||||
|
||||
void thread_flags_set(thread_t *thread, thread_flags_t mask)
|
||||
{
|
||||
DEBUG("thread_flags_set(): setting 0x%08x for pid %"PRIkernel_pid"\n", mask, thread->pid);
|
||||
DEBUG("thread_flags_set(): setting 0x%08x for pid %" PRIkernel_pid "\n",
|
||||
mask, thread->pid);
|
||||
unsigned state = irq_disable();
|
||||
thread->flags |= mask;
|
||||
if (thread_flags_wake(thread)) {
|
||||
|
Loading…
Reference in New Issue
Block a user