Commit adc11ade authored by Adam Wujek's avatar Adam Wujek 💬

Merge branch "rubi-assert"

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parents dec144d5 74aa649b
......@@ -21,6 +21,15 @@ config PRINT_BUFSIZE
int
default 128
config ASSERT
bool "Build assertion checks in the code"
default y
help
Build assertions in the code, to catch unexpected situations.
When an assertion fails the code loops over repeating the
error message every second. OTOH, panic() is always built,
with no Kconfig -- and it does the same, unconditionally.
config RAMSIZE
int
default 65536 if WR_SWITCH
......
......@@ -11,6 +11,7 @@
#include <string.h>
#include <wrc.h>
#include <wrpc.h>
#include <assert.h>
#include "types.h"
#include "board.h"
......@@ -269,8 +270,9 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
minic_txword(WRF_OOB, WRPC_FID);
}
/* Start sending the frame */
/* Start sending the frame, and while we read mcr check for fifo full */
mcr = minic_readl(MINIC_REG_MCR);
assert((mcr & MINIC_MCR_TX_FULL) == 0, "Minic tx fifo full");
minic_writel(MINIC_REG_MCR, mcr | MINIC_MCR_TX_START);
/* wait for the DMA to finish */
......
#ifndef __ASSERT_H__
#define __ASSERT_H__
/*
* Both panic and assert loop over the console, re-printing the
* message, so you can connnect to a paniced node and see the message
* that caused the panic. assert_warn(condition) is once only, like
* warn_on(!condition) in the kernel.
*/
extern void panic(const char *fmt, ...)
__attribute__((format(printf,1,2)));
#define assert(cond, fmt, ...) \
if (CONFIG_HAS_ASSERT && !(cond)) \
__assert(__func__, __LINE__, 1 /* forever */, fmt, ## __VA_ARGS__)
#define assert_warn(cond, fmt, ...) \
if (CONFIG_HAS_ASSERT && !(cond)) \
__assert(__func__, __LINE__, 0 /* once */, fmt, ## __VA_ARGS__)
extern void __assert(const char *func, int line, int forever,
const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
#ifdef CONFIG_ASSERT
# define CONFIG_HAS_ASSERT 1
#else
# define CONFIG_HAS_ASSERT 0
#endif
#endif /* __ASSERT_H__ */
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#include <wrc.h>
#include "ipv4.h"
#ifdef CONFIG_SYSLOG
# define HAS_SYSLOG 1
#else
# define HAS_SYSLOG 0
#endif
void panic(const char *fmt, ...)
{
va_list args;
char message[128];
strcpy(message, "Panic: ");
va_start(args, fmt);
pp_vsprintf(message + 7, fmt, args);
va_end(args);
if (HAS_SYSLOG)
syslog_report(message);
while (1) {
pp_printf(message);
usleep(1000 * 1000);
}
}
void __assert(const char *func, int line, int forever,
const char *fmt, ...)
{
va_list args;
char message[200];
int more = fmt && fmt[0];
pp_sprintf(message, "Assertion failed (%s:%i)%s", func, line,
more ? ": " : "\n");
if (more) {
va_start(args, fmt);
pp_vsprintf(message + strlen(message), fmt, args);
va_end(args);
}
if (HAS_SYSLOG)
syslog_report(message);
while (1) {
pp_printf(message);
if (!forever)
break;
usleep(1000 * 1000);
}
}
......@@ -26,6 +26,8 @@ static int lat_verbose = 1;
static unsigned long prios[] = {7, 6, 0}; /* the prio for the 3 frames */
static int ltest_fake_delay_ns;
/* latency probe: we need to enqueue 3 short frames: 64*3+overhead = 256 */
static uint8_t __latency_queue[256];
static struct wrpc_socket *latency_socket, __static_latency_socket = {
......@@ -213,7 +215,10 @@ static int latency_poll_tx(void)
static uint32_t sequence;
static uint32_t lasts;
/* Send three frames -- lazily in native byte order */
/*
* Send three frames -- lazily in native byte order. Possibly
* subtract a fake delay, to trigger reporting.
*/
memset(&frame, 0, sizeof(frame));
frame.sequence = sequence++;
......@@ -221,16 +226,27 @@ static int latency_poll_tx(void)
latency_socket->prio = prios[0];
ptpd_netif_sendto(latency_socket, &latency_addr, &frame, sizeof(frame),
frame.ts + 0);
frame.ts[0].nsec -= ltest_fake_delay_ns;
if (frame.ts[0].nsec < 0) {
frame.ts[0].nsec += 1000 * 1000 * 1000;
frame.ts[0].sec --;
}
frame.type = 2;
latency_socket->prio = prios[1];
ptpd_netif_sendto(latency_socket, &latency_addr, &frame, sizeof(frame),
frame.ts + 1);
frame.ts[1].nsec -= ltest_fake_delay_ns;
if (frame.ts[1].nsec < 0) {
frame.ts[1].nsec += 1000 * 1000 * 1000;
frame.ts[1].sec --;
}
frame.type = 3;
latency_socket->prio = prios[2];
ptpd_netif_sendto(latency_socket, &latency_addr, &frame, sizeof(frame),
NULL);
ltest_fake_delay_ns = 0;
/* Every 10s remind we are sending ltest */
if (!lasts) {
......@@ -277,6 +293,8 @@ static int cmd_ltest(const char *args[])
lat_verbose = 1;
else if (HAS_SYSLOG && !strcmp(args[0], "quiet"))
lat_verbose = 0;
else if (!strcmp(args[0], "fake"))
fromdec(args[1], &ltest_fake_delay_ns);
else {
fromdec(args[0], &v);
latency_period_ms = v * 1000 + v1;
......
obj-y += lib/util.o
obj-y += lib/assert.o
obj-$(CONFIG_LM32) += \
lib/atoi.o \
......
ppsi @ a563ada9
Subproject commit d6aefd732b984cc4237277938ea183a038b53603
Subproject commit a563ada973ffd5480e13caf906377ecca49bdfc7
......@@ -216,7 +216,7 @@ const char *fromhex(const char *hex, int *v)
{
int o = 0;
for (; *hex; ++hex) {
for (; hex && *hex; ++hex) {
if (*hex >= '0' && *hex <= '9') {
o = (o << 4) + (*hex - '0');
} else if (*hex >= 'A' && *hex <= 'F') {
......@@ -236,7 +236,7 @@ const char *fromdec(const char *dec, int *v)
{
int o = 0;
for (; *dec; ++dec) {
for (; dec && *dec; ++dec) {
if (*dec >= '0' && *dec <= '9') {
o = (o * 10) + (*dec - '0');
} else {
......
......@@ -7,6 +7,7 @@
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <wrc.h>
#include <assert.h>
#include "system_checks.h"
......@@ -14,11 +15,7 @@ extern void _reset_handler(void); /* user to reset again */
void check_stack(void)
{
/* print "Stack overflow!" forever if stack corrupted */
while (_endram != ENDRAM_MAGIC) {
pp_printf("Stack overflow!\n");
timer_delay_ms(1000);
}
assert(_endram == ENDRAM_MAGIC, "Stack overflow! (%x)\n", _endram);
}
#ifdef CONFIG_CHECK_RESET
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment