78 lines
1.4 KiB
C
78 lines
1.4 KiB
C
#include <sys/assert.h>
|
|
#include <sys/atomic.h>
|
|
#include <sys/runtime.h>
|
|
|
|
#if defined(DEBUG_ASSERTIONS)
|
|
|
|
extern volatile struct rt_ram rt_ram __attribute((weak));
|
|
|
|
|
|
void _assert(int result,int16_t loc){
|
|
|
|
#if !defined( __DISABLE_ASSERTIONS__ )
|
|
ATOMIC
|
|
|
|
if (!&rt_ram)
|
|
return;
|
|
|
|
if (rt_ram.asserts.next != -1){
|
|
rt_ram.asserts.buffer[ rt_ram.asserts.next ].location = loc;
|
|
rt_ram.asserts.buffer[ rt_ram.asserts.next ].error = result;
|
|
rt_ram.asserts.next++;
|
|
if (rt_ram.asserts.next == ASSERT_BUFFER_LEN){
|
|
rt_ram.asserts.next = 0;
|
|
};
|
|
if (rt_ram.asserts.next == rt_ram.asserts.read){
|
|
rt_ram.asserts.next = -1;
|
|
};
|
|
};
|
|
#endif
|
|
};
|
|
|
|
void _assert_read(void){
|
|
#if !defined( __DISABLE_ASSERTIONS__ )
|
|
ATOMIC
|
|
|
|
if (!&rt_ram)
|
|
return;
|
|
|
|
if (rt_ram.asserts.next != rt_ram.asserts.read){
|
|
|
|
if (rt_ram.asserts.next == -1){
|
|
rt_ram.asserts.next = rt_ram.asserts.read;
|
|
};
|
|
|
|
rt_ram.asserts.read++;
|
|
if (rt_ram.asserts.read == ASSERT_BUFFER_LEN){
|
|
rt_ram.asserts.read = 0;
|
|
};
|
|
};
|
|
#endif
|
|
};
|
|
|
|
int32_t _assert_current(void){
|
|
#if !defined( __DISABLE_ASSERTIONS__ )
|
|
ATOMIC
|
|
|
|
if (!&rt_ram)
|
|
return 0;
|
|
|
|
return rt_ram.asserts.buffer[rt_ram.asserts.read].location | (((int32_t)rt_ram.asserts.read)<<24);
|
|
#endif
|
|
};
|
|
|
|
int32_t _assert_current_error(void){
|
|
#if !defined( __DISABLE_ASSERTIONS__ )
|
|
ATOMIC
|
|
|
|
if (!&rt_ram)
|
|
return 0;
|
|
|
|
if (rt_ram.asserts.read == rt_ram.asserts.next)
|
|
return 0;
|
|
return rt_ram.asserts.buffer[rt_ram.asserts.read].error;
|
|
#endif
|
|
};
|
|
|
|
#endif
|