keycard-pro/app/common.h

97 lines
2.6 KiB
C
Raw Normal View History

2023-03-01 14:25:06 +00:00
/*
* This file is part of the OpenMV project.
*
* Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
* Copyright (c) 2013-2021 Kwabena W. Agyeman <kwagyeman@openmv.io>
*
* This work is licensed under the MIT license, see the file LICENSE for details.
*
* Common macros.
*/
2023-03-02 16:34:33 +00:00
#ifndef __APP_COMMON_H__
#define __APP_COMMON_H__
2023-03-01 14:25:06 +00:00
2023-04-28 14:03:37 +00:00
#include <stdint.h>
#include <stddef.h>
2023-05-16 12:52:48 +00:00
#include "hal.h"
2023-04-28 14:03:37 +00:00
2023-07-20 14:28:35 +00:00
typedef struct {
uint8_t* data;
size_t len;
} data_t;
2023-09-08 08:50:17 +00:00
extern const uint8_t FW_SIGNATURE[64];
extern const uint8_t FW_VERSION[4];
2023-03-02 16:34:33 +00:00
#define APP_ALIGNED(x, a) x __attribute__((aligned(a)))
#define APP_SECTION(x, s) x __attribute__((section(s)))
#define APP_ALWAYS_INLINE inline __attribute__((always_inline))
2023-03-17 17:10:40 +00:00
#define APP_WEAK __attribute__((weak))
2023-03-02 16:34:33 +00:00
2023-03-01 14:25:06 +00:00
#define OMG_BREAK() __asm__ volatile ("BKPT")
2023-03-02 16:34:33 +00:00
#define APP_MAX(a,b) \
2023-03-01 14:25:06 +00:00
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; \
})
2023-03-02 16:34:33 +00:00
#define APP_MIN(a,b) \
2023-03-01 14:25:06 +00:00
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; \
})
2023-03-09 11:00:47 +00:00
2023-04-03 11:31:21 +00:00
#define APP_TASK(__NAME__) __NAME__##_task
2023-03-09 11:00:47 +00:00
#define _APP_DEF_TASK(__NAME__, __STACK_SIZE__) \
2023-03-29 12:47:31 +00:00
void __NAME__##_task_entry(void* pvParameters); \
2023-03-09 11:00:47 +00:00
static StaticTask_t __NAME__##_task_memory; \
static StackType_t __NAME__##_task_stack[__STACK_SIZE__]
#define _APP_CREATE_TASK(__NAME__, __PRIO__) \
2023-03-30 11:51:44 +00:00
xTaskCreateStatic(__NAME__##_task_entry, #__NAME__, (sizeof(__NAME__##_task_stack)/sizeof(uint32_t)), NULL, __PRIO__, __NAME__##_task_stack, &__NAME__##_task_memory)
2023-03-09 11:00:47 +00:00
#define APP_DEF_TASK(__NAME__, __STACK_SIZE__) \
2023-03-14 16:51:21 +00:00
_APP_DEF_TASK(__NAME__, __STACK_SIZE__); \
2023-04-03 11:31:21 +00:00
TaskHandle_t APP_TASK(__NAME__)
2023-03-09 11:00:47 +00:00
#define APP_CREATE_TASK(__NAME__, __PRIO__) \
2023-04-03 11:31:21 +00:00
APP_TASK(__NAME__) = _APP_CREATE_TASK(__NAME__, __PRIO__)
2023-03-09 11:00:47 +00:00
#define APP_DEF_CREATE_TASK(__NAME__, __PRIO__, __STACK_SIZE__) \
_APP_DEF_TASK(__NAME__, __STACK_SIZE__); \
_APP_CREATE_TASK(__NAME__, __PRIO__)
2023-03-29 12:47:31 +00:00
#define APP_DEF_EXTERN_TASK(__NAME__) \
2023-04-03 11:31:21 +00:00
extern TaskHandle_t APP_TASK(__NAME__)
2023-03-29 12:47:31 +00:00
2023-03-27 09:41:50 +00:00
static inline uint32_t rev32(uint32_t value) {
__asm__ volatile (
"REV %0, %0 \n"
: "+r" (value)
:
);
return value;
}
static inline uint32_t rev16(uint16_t value) {
__asm__ volatile (
"REV16 %0, %0 \n"
: "+r" (value)
:
);
return value;
}
static inline void rev32_all(uint32_t* out, uint32_t* in, size_t len) {
len >>= 2;
for (int i = 0; i < len; i++) {
out[i] = rev32(in[i]);
}
}
2023-03-02 16:34:33 +00:00
#endif //__APP_COMMON_H__