Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/app_assert/src/fn_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#define XASSERT_UNIT FN_ASSERT
#define XASSERT_ENABLE_ASSERTIONS_FN_ASSERT 1 /* Enable assertions*/
#define XASSERT_ENABLE_DEBUG_FN_ASSERT 1 /* Enable printing debug message when asserting */
#define XASSERT_ENABLE_LINE_NUMBERS 1 /* Enable line numbers in assert messages */

#include <xassert.h>


void fn_assert(int x)
{
assert(x > 5 && msg("assert from fn_assert()"));
Expand Down
13 changes: 13 additions & 0 deletions examples/app_timed_block/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_assert)

set(APP_HW_TARGET XK-EVK-XU316)

include(${CMAKE_CURRENT_LIST_DIR}/../deps.cmake)

set(APP_COMPILER_FLAGS -DXASSERT_ENABLE_ASSERTIONS=0 -DXASSERT_ENABLE_LINE_NUMBERS=1) # Override from source files

set(XMOS_SANDBOX_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../)

XMOS_REGISTER_APP()
19 changes: 19 additions & 0 deletions examples/app_timed_block/src/fn_assert.xc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2024-2025 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

#define XASSERT_UNIT FN_ASSERT
#define XASSERT_ENABLE_TIMING_ASSERTIONS_FN_ASSERT 1 /* Enable timing assertions*/
#define XASSERT_ENABLE_DEBUG_FN_ASSERT 1 /* Enable printing debug message when asserting */

#include <xs1.h>
#include <xassert.h>

void fn_assert()
{
XASSERT_TIMED_BLOCK("test", 1000,
timer t;
unsigned time;
t :> time;
t when timerafter(time + 5000) :> void;
);
}
19 changes: 19 additions & 0 deletions examples/app_timed_block/src/fn_no_assert.xc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2024-2025 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

#define XASSERT_UNIT FN_ASSERT
#define XASSERT_ENABLE_ASSERTIONS_FN_ASSERT 0 /* Disable assertions*/
#define XASSERT_ENABLE_DEBUG_FN_ASSERT 1 /* Enable printing debug message when asserting */

#include <xs1.h>
#include <xassert.h>

void fn_no_assert()
{
XASSERT_TIMED_BLOCK("test", 1000,
timer t;
unsigned time;
t :> time;
t when timerafter(time + 50) :> void;
);
}
11 changes: 11 additions & 0 deletions examples/app_timed_block/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2024-2025 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

extern void fn_no_assert(void);
extern void fn_assert(void);

int main() {
fn_no_assert(); // This shouldn't assert
fn_assert(); // This asserts
return 0;
}
4 changes: 4 additions & 0 deletions examples/app_timed_block/src/xassert_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright 2025 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

#define XASSERT_ENABLE_LINE_NUMBERS 1
13 changes: 13 additions & 0 deletions examples/app_timed_loop/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_assert)

set(APP_HW_TARGET XK-EVK-XU316)

include(${CMAKE_CURRENT_LIST_DIR}/../deps.cmake)

set(APP_COMPILER_FLAGS -DXASSERT_ENABLE_ASSERTIONS=0) # Override from source files

set(XMOS_SANDBOX_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../)

XMOS_REGISTER_APP()
23 changes: 23 additions & 0 deletions examples/app_timed_loop/src/fn_assert.xc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024-2025 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

#define XASSERT_UNIT FN_ASSERT
#define XASSERT_ENABLE_TIMING_ASSERTIONS_FN_ASSERT 1 /* Enable timing assertions*/
#define XASSERT_ENABLE_DEBUG_FN_ASSERT 1 /* Enable printing debug message when asserting */
#define XASSERT_ENABLE_LINE_NUMBERS 1 /* Enable line numbers in assertions */
#include <xs1.h>
#include <xassert.h>

void fn_assert()
{
timer t;
unsigned time;
t :> time;

for(int i = 0; i< 5; i++)
{
time += (i * 5000);
t when timerafter(time) :> void;
xassert_loop_freq("test loop", 10000);
}
}
25 changes: 25 additions & 0 deletions examples/app_timed_loop/src/fn_no_assert.xc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024-2025 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

#define XASSERT_UNIT FN_ASSERT
#define XASSERT_ENABLE_ASSERTIONS_FN_ASSERT 0 /* Enable assertions*/
#define XASSERT_ENABLE_DEBUG_FN_ASSERT 1 /* Enable printing debug message when asserting */

#include <xs1.h>
#include <xassert.h>
#include <print.h>

void fn_no_assert()
{
timer t;
unsigned time;
t :> time;


for(int i = 0; i< 5; i++)
{
time += (i * 5000);
t when timerafter(time) :> void;
xassert_loop_freq("test loop", 10000);
}
}
11 changes: 11 additions & 0 deletions examples/app_timed_loop/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2024-2025 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

extern void fn_no_assert(void);
extern void fn_assert(void);

int main() {
fn_no_assert(); // This shouldn't assert
fn_assert(); // This asserts
return 0;
}
13 changes: 13 additions & 0 deletions examples/app_timing_loop_exception/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_assert)

set(APP_HW_TARGET XK-EVK-XU316)

include(${CMAKE_CURRENT_LIST_DIR}/../deps.cmake)

set(APP_COMPILER_FLAGS -DXASSERT_ENABLE_ASSERTIONS=0) # Override from source files

set(XMOS_SANDBOX_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../)

XMOS_REGISTER_APP()
34 changes: 34 additions & 0 deletions examples/app_timing_loop_exception/src/fn_no_assert.xc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024-2025 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

#define XASSERT_UNIT FN_ASSERT
#define XASSERT_ENABLE_TIMING_ASSERTIONS_FN_ASSERT 1 /* Enable timing assertions*/
#define XASSERT_ENABLE_DEBUG_FN_ASSERT 1 /* Enable printing debug message when asserting */
#define XASSERT_ENABLE_LINE_NUMBERS 1 /* Enable line numbers in assertions */
#include <xs1.h>
#include <xassert.h>

void fn_assert()
{
timer t;
unsigned time;
t :> time;

for(int i = 0; i< 5; i++)
{
int delay = 1000;

xassert_loop_freq("test loop", 10000);

if(i == 3)
{
delay *= 50;

/* Due to this added exception the assertion will not fail */
xassert_loop_exception("test loop");
}

time += delay;
t when timerafter(time) :> void;
}
}
10 changes: 10 additions & 0 deletions examples/app_timing_loop_exception/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024-2025 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

extern void fn_no_assert(void);
extern void fn_assert(void);

int main() {
fn_no_assert(); // This shouldn't assert
return 0;
}
Loading