Skip to content

Commit 46e8b78

Browse files
added to utils
1 parent ccfb5a1 commit 46e8b78

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

middleware/include/c_utils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@
3333
*/
3434
#define EXTRACT_BIT(byte, bit_index) ((byte >> (bit_index)) & 0x01)
3535

36+
/**
37+
* Macro for returning the min of two numbers
38+
* @param a first number
39+
* @param b second number
40+
*/
41+
#define min(a, b) \
42+
({ \
43+
__typeof__(a) _a = (a); \
44+
__typeof__(b) _b = (b); \
45+
_a < _b ? _a : _b; \
46+
})
47+
3648
void endian_swap(void *ptr, int size);
3749

3850
/// @brief Reverses the bit order of a byte

threadX/inc/u_mutex.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef __U_MUTEX_H
2+
#define __U_MUTEX_H
3+
4+
#include "tx_api.h"
5+
#include "u_general.h"
6+
#include "u_debug.h"
7+
#include <stdint.h>
8+
#include <stdbool.h>
9+
10+
#define MUTEX_WAIT_TIME TX_WAIT_FOREVER
11+
12+
typedef struct {
13+
/* PUBLIC: Mutex Configuration Settings */
14+
/* Set these when defining an instance of this struct. */
15+
const CHAR *name; /* Name of Mutex */
16+
const UINT priority_inherit; /* Specifies if the mutex supports priority inheritance. See page 55 of the "Azure RTOS ThreadX User Guide". */
17+
18+
/* PRIVATE: Internal implementation - DO NOT ACCESS DIRECTLY */
19+
/* (should only be accessed by functions in u_mutexes.c) */
20+
TX_MUTEX _TX_MUTEX;
21+
} mutex_t;
22+
23+
/* API */
24+
uint8_t mutexes_init(); // Initializes all mutexes set up in u_mutexes.c
25+
uint8_t mutex_get(mutex_t *mutex); // Gets a mutex.
26+
uint8_t mutex_put(mutex_t *mutex); // Puts a mutex.
27+
28+
#endif /* u_mutex.h */

0 commit comments

Comments
 (0)