Merge pull request #969 from openmv/common_update

Update common macros.
This commit is contained in:
Ibrahim Abd Elkader 2020-11-14 20:40:03 +02:00 committed by GitHub
commit a0d58d0a3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 47 deletions

View File

@ -81,7 +81,7 @@ endif
# Enable debug printf
ifeq ($(DEBUG_PRINTF), 1)
CFLAGS += -DDEBUG_PRINTF
CFLAGS += -DOMV_DEBUG_PRINTF
endif
# Enable stack protection

View File

@ -9,30 +9,32 @@
* Common macros.
*/
#ifndef __OMV_COMMON_H__
#ifndef ALWAYS_INLINE
#define ALWAYS_INLINE inline __attribute__((always_inline))
#endif
#ifndef BREAK
#define BREAK() __asm__ volatile ("BKPT")
#endif
#define OMV_ATTR_ALIGNED(x, a) x __attribute__((aligned(a)))
#define OMV_ATTR_SECTION(x, s) x __attribute__((section(s)))
#define OMV_ATTR_ALWAYS_INLINE inline __attribute__((always_inline))
#define OMV_ATTR_OPTIMIZE(o) __attribute__((optimize(o)))
#ifndef DISABLE_OPT
#define DISABLE_OPT __attribute__((optimize("O0")))
#endif
#define OMG_BREAK() __asm__ volatile ("BKPT")
#ifdef DEBUG_PRINTF
#ifdef OMV_DEBUG_PRINTF
#define debug_printf(fmt, ...) \
do { printf("%s(): " fmt, __func__, ##__VA_ARGS__);} while (0)
#else
#define debug_printf(...)
#endif
#ifndef MIN
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif
#define OMV_MAX(a,b) \
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; \
})
#define OMV_MIN(a,b) \
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; \
})
#endif //__OMV_COMMON_H__

View File

@ -186,7 +186,7 @@ void file_buffer_init0()
file_buffer_index = 0;
}
ALWAYS_INLINE static void file_fill(FIL *fp)
OMV_ATTR_ALWAYS_INLINE static void file_fill(FIL *fp)
{
if (file_buffer_index == file_buffer_size) {
file_buffer_pointer -= file_buffer_offset;
@ -202,7 +202,7 @@ ALWAYS_INLINE static void file_fill(FIL *fp)
}
}
ALWAYS_INLINE static void file_flush(FIL *fp)
OMV_ATTR_ALWAYS_INLINE static void file_flush(FIL *fp)
{
if (file_buffer_index == file_buffer_size) {
UINT bytes;

View File

@ -80,39 +80,39 @@ const static float fft_cos_table[512] = {
-0.998795f, -0.999078f, -0.999322f, -0.999529f, -0.999699f, -0.999831f, -0.999925f, -0.999981f
};
ALWAYS_INLINE static float get_cos(int k, int N_pow2) // N=512 -> N=pow2=9
OMV_ATTR_ALWAYS_INLINE static float get_cos(int k, int N_pow2) // N=512 -> N=pow2=9
{
return fft_cos_table[k << (9 - N_pow2)];
}
ALWAYS_INLINE static float get_ai(int k, int N_pow2) // N=512 -> N=pow2=9
OMV_ATTR_ALWAYS_INLINE static float get_ai(int k, int N_pow2) // N=512 -> N=pow2=9
{
return 0.5 * (-get_cos(k, N_pow2));
}
ALWAYS_INLINE static float get_bi(int k, int N_pow2) // N=512 -> N=pow2=9
OMV_ATTR_ALWAYS_INLINE static float get_bi(int k, int N_pow2) // N=512 -> N=pow2=9
{
return 0.5 * (+get_cos(k, N_pow2));
}
ALWAYS_INLINE static float get_a_star_i(int k, int N_pow2) // N=512 -> N=pow2=9
OMV_ATTR_ALWAYS_INLINE static float get_a_star_i(int k, int N_pow2) // N=512 -> N=pow2=9
{
return 0.5 * (+get_cos(k, N_pow2));
}
ALWAYS_INLINE static float get_b_star_i(int k, int N_pow2) // N=512 -> N=pow2=9
OMV_ATTR_ALWAYS_INLINE static float get_b_star_i(int k, int N_pow2) // N=512 -> N=pow2=9
{
return 0.5 * (-get_cos(k, N_pow2));
}
//// For samples 0 to (n/2)-1 --- Note: clog2(n/2) = N_pow2
//ALWAYS_INLINE static float get_hann_l_side(int k, int N_pow2)
//OMV_ATTR_ALWAYS_INLINE static float get_hann_l_side(int k, int N_pow2)
//{
// return 0.5 * (1 - get_cos(k, N_pow2));
//}
//// For samples (n/2) to n-1 --- Note: clog2(n/2) = N_pow2
//ALWAYS_INLINE static float get_hann_r_side(int k, int N_pow2)
//OMV_ATTR_ALWAYS_INLINE static float get_hann_r_side(int k, int N_pow2)
//{
// return 0.5 * (1 - get_cos((2 << N_pow2) - k - 1, N_pow2));
//}
@ -184,27 +184,27 @@ const static float fft_sin_table[512] = {
0.049068f, 0.042938f, 0.036807f, 0.030675f, 0.024541f, 0.018407f, 0.012272f, 0.006136f
};
ALWAYS_INLINE static float get_sin(int k, int N_pow2) // N=512 -> N=pow2=9
OMV_ATTR_ALWAYS_INLINE static float get_sin(int k, int N_pow2) // N=512 -> N=pow2=9
{
return fft_sin_table[k << (9 - N_pow2)];
}
ALWAYS_INLINE static float get_ar(int k, int N_pow2) // N=512 -> N=pow2=9
OMV_ATTR_ALWAYS_INLINE static float get_ar(int k, int N_pow2) // N=512 -> N=pow2=9
{
return 0.5 * (1 - get_sin(k, N_pow2));
}
ALWAYS_INLINE static float get_br(int k, int N_pow2) // N=512 -> N=pow2=9
OMV_ATTR_ALWAYS_INLINE static float get_br(int k, int N_pow2) // N=512 -> N=pow2=9
{
return 0.5 * (1 + get_sin(k, N_pow2));
}
ALWAYS_INLINE static float get_a_star_r(int k, int N_pow2) // N=512 -> N=pow2=9
OMV_ATTR_ALWAYS_INLINE static float get_a_star_r(int k, int N_pow2) // N=512 -> N=pow2=9
{
return 0.5 * (1 - get_sin(k, N_pow2));
}
ALWAYS_INLINE static float get_b_star_r(int k, int N_pow2) // N=512 -> N=pow2=9
OMV_ATTR_ALWAYS_INLINE static float get_b_star_r(int k, int N_pow2) // N=512 -> N=pow2=9
{
return 0.5 * (1 + get_sin(k, N_pow2));
}
@ -281,12 +281,12 @@ static void pack_fft(float *in, float *out, int N_pow2)
///////////////////////////////////////////////////////////////////////////////
ALWAYS_INLINE static int int_flog2(int x) // floor log 2
OMV_ATTR_ALWAYS_INLINE static int int_flog2(int x) // floor log 2
{
return 31 - __CLZ(x);
}
ALWAYS_INLINE static int int_clog2(int x) // ceiling log 2
OMV_ATTR_ALWAYS_INLINE static int int_clog2(int x) // ceiling log 2
{
int y = int_flog2(x);
return (x - (1 << y)) ? (y + 1) : y;
@ -296,19 +296,19 @@ ALWAYS_INLINE static int int_clog2(int x) // ceiling log 2
// Input even numbered index
// Output even numbered index
ALWAYS_INLINE static int bit_reverse(int index, int N_pow2)
OMV_ATTR_ALWAYS_INLINE static int bit_reverse(int index, int N_pow2)
{
return __RBIT(index) >> (30 - N_pow2);
}
ALWAYS_INLINE static void swap(float *a, float *b)
OMV_ATTR_ALWAYS_INLINE static void swap(float *a, float *b)
{
float tmp = *b;
*b = *a;
*a = tmp;
}
//ALWAYS_INLINE static float get_hann(int k, int N_pow2)
//OMV_ATTR_ALWAYS_INLINE static float get_hann(int k, int N_pow2)
//{
// if (k < (1 << N_pow2)) {
// return get_hann_l_side(k, N_pow2);

View File

@ -22,7 +22,7 @@ const float __atanf_lut[4] = {
+0.9997878412794807f //p1
};
float ALWAYS_INLINE fast_sqrtf(float x)
float OMV_ATTR_ALWAYS_INLINE fast_sqrtf(float x)
{
asm volatile (
"vsqrt.f32 %[r], %[x]\n"
@ -31,7 +31,7 @@ float ALWAYS_INLINE fast_sqrtf(float x)
return x;
}
int ALWAYS_INLINE fast_floorf(float x)
int OMV_ATTR_ALWAYS_INLINE fast_floorf(float x)
{
int i;
asm volatile (
@ -41,7 +41,7 @@ int ALWAYS_INLINE fast_floorf(float x)
return i;
}
int ALWAYS_INLINE fast_ceilf(float x)
int OMV_ATTR_ALWAYS_INLINE fast_ceilf(float x)
{
int i;
x += 0.9999f;
@ -52,7 +52,7 @@ int ALWAYS_INLINE fast_ceilf(float x)
return i;
}
int ALWAYS_INLINE fast_roundf(float x)
int OMV_ATTR_ALWAYS_INLINE fast_roundf(float x)
{
int i;
asm volatile (
@ -103,7 +103,7 @@ float fast_cbrtf(float x)
return v.x;
}
float ALWAYS_INLINE fast_fabsf(float x)
float OMV_ATTR_ALWAYS_INLINE fast_fabsf(float x)
{
asm volatile (
"vabs.f32 %[r], %[x]\n"

View File

@ -83,7 +83,7 @@ bool sdcard_is_present(void)
static BYTE spi_send(BYTE out)
{
if (HAL_SPI_TransmitReceive(&SPIHandle, &out, &out, 1, SPI_TIMEOUT) != HAL_OK) {
BREAK();
OMV_BREAK();
}
return out;
}
@ -247,7 +247,7 @@ void sdcard_hw_init(uint32_t baudrate)
/* Initialize the SPI */
if (HAL_SPI_Init(&SPIHandle) != HAL_OK) {
/* Initialization Error */
BREAK();
OMV_BREAK();
} else {
// TODO is this needed ?
uint8_t buf[1];
@ -305,7 +305,7 @@ void sdcard_init(void)
sdcard_hw_init(SPI_BAUDRATEPRESCALER_2);
} else {
/* Initialization failed */
BREAK();
OMV_BREAK();
}
}

View File

@ -853,7 +853,7 @@ int winc_socket_send(int fd, const uint8_t *buf, uint32_t len, uint32_t timeout)
m2m_wifi_handle_events(NULL);
// Split the packet into smaller ones.
int n = MIN((len - bytes), SOCKET_BUFFER_MAX_LENGTH);
int n = OMV_MIN((len - bytes), SOCKET_BUFFER_MAX_LENGTH);
int ret = WINC1500_EXPORT(send)(fd, (uint8_t*)buf + bytes, n, 0);
if (ret == SOCK_ERR_NO_ERROR) {
@ -893,7 +893,7 @@ int winc_socket_recv(int fd, uint8_t *buf, uint32_t len, winc_socket_buf_t *sock
sockbuf->size = recv_bytes;
}
uint32_t bytes = MIN(len, sockbuf->size);
uint32_t bytes = OMV_MIN(len, sockbuf->size);
memcpy(buf, sockbuf->buf+sockbuf->idx, bytes);
sockbuf->idx += bytes;
sockbuf->size -= bytes;
@ -915,7 +915,7 @@ int winc_socket_sendto(int fd, const uint8_t *buf, uint32_t len, sockaddr *addr,
m2m_wifi_handle_events(NULL);
// Split the packet into smaller ones.
int n = MIN((len - bytes), SOCKET_BUFFER_MAX_LENGTH);
int n = OMV_MIN((len - bytes), SOCKET_BUFFER_MAX_LENGTH);
int ret = WINC1500_EXPORT(sendto)(fd, (uint8_t*)buf + bytes, n, 0, addr, sizeof(*addr));
if (ret == SOCK_ERR_NO_ERROR) {