Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish between simulation tools with defines #381

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ PROJECT ?= hello_world
# Linker options are 'on_chip' (default),'flash_load','flash_exec','freertos'
LINKER ?= on_chip

# Target options are 'sim' (default) and 'pynq-z2'
TARGET ?= sim
# Target options are 'verilator' (default), 'questasim', 'vcs' and 'pynq-z2'
TARGET ?= verilator
MCU_CFG ?= mcu_cfg.hjson
PAD_CFG ?= pad_cfg.hjson
EXT_PAD_CFG ?=
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ make app
To run any other application, please use the following command with appropiate parameters:

```
app PROJECT=<folder_name_of_the_project_to_be_built> TARGET=sim(default),pynq-z2 LINKER=on_chip(default),flash_load,flash_exec COMPILER=gcc(default),clang COMPILER_PREFIX=riscv32-unknown-(default) ARCH=rv32imc(default),<any RISC-V ISA string supported by the CPU>
app PROJECT=<folder_name_of_the_project_to_be_built> TARGET=verilator(default),questasim,vcs,pynq-z2 LINKER=on_chip(default),flash_load,flash_exec COMPILER=gcc(default),clang COMPILER_PREFIX=riscv32-unknown-(default) ARCH=rv32imc(default),<any RISC-V ISA string supported by the CPU>

Params:
- PROJECT (ex: <folder_name_of_the_project_to_be_built>, hello_world(default))
- TARGET (ex: sim(default),pynq-z2)
- TARGET (ex: verilator(default),questasim,vcs,pynq-z2)
- LINKER (ex: on_chip(default),flash_load,flash_exec)
- COMPILER (ex: gcc(default),clang)
- COMPILER_PREFIX (ex: riscv32-unknown-(default))
Expand Down Expand Up @@ -433,7 +433,7 @@ make app-simulate-all
```
Note that both commands allow the previous parameters to specify compiling or simulation options. E.g.:
```
make app-simulate-all LINKER=on_chip SIMULATOR=questasim COMPILER=clang TIMEOUT=150
make app-simulate-all LINKER=on_chip SIMULATOR=questasim COMPILER=clang TIMEOUT=150
```

##### Manually
Expand All @@ -443,18 +443,19 @@ You can also **SOURCE** the script as
```

*Pay special attention to the first period in the command!*
You will be killing simulations that take too long, if you **EXECUTE** (`./test_all.sh`) this action kills the script.
The script will terminate simulations that take too long (>timeout), if you **EXECUTE** (`./test_all.sh`) this action will also terminate the script.

For both usages (commands or manual), the order of the arguments is irrelevant.

> Note: Be sure to commit all your changes before running the script!

* Applications that fail being built with gcc will not be simulated (skipped).
* Some applications are skipped by default for not being suitable for simulation.
* Some applications can skipped by default for not being suitable for simulation. Open the script and add yours to the `BLACKLIST`.
* If a simulation takes too long (>timeout), it is killed.

* Upon starting, the script will modify the `mcu_cfg.hjson` file to include all peripherals (so the largest number of apps can be run), re-generates the mcu and re-builds the simulation model for the chosen tool.
These changes can be reverted at the end of the execution (default). If changes were not commited, accepting this operation will revert them!
* If you want to re-run a test without re-building the simulation model, add the argument `debug` to the command (only available when sourcing the script).

The success of the script is not required for merging of a PR.

Expand All @@ -468,7 +469,7 @@ Follow the [ExecuteFromFlash](./ExecuteFromFlash.md) guide to exxecute code dire

## Emulation on Xilinx FPGAs

This project offers two different X-HEEP implementetions on the Xilinx FPGAs, called Standalone-FEMU and Linux-FEMU.
This project offers two different X-HEEP implementations on the Xilinx FPGAs, called Standalone-FEMU and Linux-FEMU.

### Standalone-FEMU (Standalone Fpga EMUlation)

Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_ams_peripheral/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "ams_regs.h"
#include "mmio.h"

#ifdef TARGET_PYNQ_Z2
#ifdef TARGET_FPGA
#error ( "This app does NOT work on the FPGA as it relies on the simulator testbench" )
#endif

Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_clock_gating/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
4 changes: 2 additions & 2 deletions sw/applications/example_dma/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down Expand Up @@ -208,7 +208,7 @@ int main(int argc, char *argv[])

#endif // TEST_ADDRESS_MODE

#ifndef TARGET_PYNQ_Z2
#ifndef TARGET_FPGA

#ifdef TEST_ADDRESS_MODE_EXTERNAL_DEVICE

Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_dma_external/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
46 changes: 23 additions & 23 deletions sw/applications/example_freertos_blinky/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@

/* The rate at which data is sent to the queue. The 200ms value is converted
to ticks using the pdMS_TO_TICKS() macro. */
#ifdef TARGET_PYNQ_Z2
#ifdef TARGET_FPGA
#define mainQUEUE_SEND_FREQUENCY_MS pdMS_TO_TICKS( 200 )
#else
#define mainQUEUE_SEND_FREQUENCY_MS pdMS_TO_TICKS( 3 )
Expand Down Expand Up @@ -214,7 +214,7 @@ static rv_timer_t timer_0_1;
/* In case of playing with the Tick Frequency, set it to the desired value
* E.g.: REFERENCE_CLOCK_Hz/configTICK_RATE_HZ --> 100kHz
*/
static const uint64_t kTickFreqHz = (REFERENCE_CLOCK_Hz/configTICK_RATE_HZ);
static const uint64_t kTickFreqHz = (REFERENCE_CLOCK_Hz/configTICK_RATE_HZ);

/* The queue used by both tasks. */
static QueueHandle_t xQueue = NULL;
Expand Down Expand Up @@ -251,7 +251,7 @@ void system_init(void)

gpio_result_t gpio_res;
gpio_cfg_t pin_cfg = {
.pin= GPIO_LD5_R,
.pin= GPIO_LD5_R,
.mode= GpioModeOutPushPull
};
gpio_res = gpio_config(pin_cfg);
Expand All @@ -260,15 +260,15 @@ void system_init(void)
pin_cfg.pin = GPIO_LD5_G;
gpio_res |= gpio_config(pin_cfg);
if (gpio_res != GpioOk) printf("Failed\n;");

gpio_write(GPIO_LD5_R, false);
gpio_write(GPIO_LD5_B, false);
gpio_write(GPIO_LD5_G, false);

// Setup rv_timer_0_1
mmio_region_t timer_0_1_reg = mmio_region_from_addr(RV_TIMER_AO_START_ADDRESS);
rv_timer_init(timer_0_1_reg, (rv_timer_config_t){.hart_count = 2, .comparator_count = 1}, &timer_0_1);

// Just in case you are playing with Tick freq.
//rv_timer_approximate_tick_params(freq_hz, kTickFreqHz, &tick_params);

Expand All @@ -295,16 +295,16 @@ void handler_irq_timer(void)
configASSERT(rv_timer_reset(&timer_0_1)==kRvTimerOk);
configASSERT(rv_timer_irq_enable(&timer_0_1, 0, 0, kRvTimerEnabled) == kRvTimerOk);
configASSERT(rv_timer_arm(&timer_0_1, 0, 0, TICK_COUNT) == kRvTimerOk);

if (xTaskIncrementTick() != 0) {
vTaskSwitchContext();
intr_flag = 1;
}

uint32_t out = 0;
out = xTaskGetTickCountFromISR();
printf( "I %d\r\n",out);

configASSERT(rv_timer_counter_set_enabled(&timer_0_1, 0, kRvTimerEnabled) == kRvTimerOk);
}

Expand Down Expand Up @@ -361,18 +361,18 @@ static void prvQueueSendTask( void *pvParameters )
//printf( "%s\n\r", __func__ );
/* Remove compiler warning about unused parameter. */
( void ) pvParameters;

/* Initialise xNextWakeTime - this only needs to be done once. */
xNextWakeTime = xTaskGetTickCount();

for( ;; )
{
vSendString( "T1\r\n" );

/* Place this task in the blocked state until it is time to run again. */
vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
//vTaskDelay(1);

/* Send to the queue - causing the queue receive task to unblock and
toggle the LED. 0 is used as the block time so the sending operation
will not block - it shouldn't need to block as the queue should always
Expand All @@ -397,16 +397,16 @@ static void prvQueueReceiveTask( void *pvParameters )
//printf( "%s\n\r", __func__ );
/* Remove compiler warning about unused parameter. */
( void ) pvParameters;

for( ;; )
{
vSendString( "T2\r\n" );

/* Wait until something arrives in the queue - this task will block
indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
FreeRTOSConfig.h. */
xQueueReceive( xQueue, &ulReceivedValue, ( TickType_t ) portMAX_DELAY );

/* To get here something must have been received from the queue, but
is it the expected value? If it is, toggle the LED. */
if( ulReceivedValue == ulExpectedValue )
Expand Down Expand Up @@ -437,28 +437,28 @@ static void SetupHardware( void )
void vToggleLED( void )
{
if (intr_blink == 0)
{
{
gpio_write(GPIO_LD5_R, true);
gpio_write(GPIO_LD5_B, false);
gpio_write(GPIO_LD5_G, false);
intr_blink++;
}
else if (intr_blink == 1)
{
{
gpio_write(GPIO_LD5_R, false);
gpio_write(GPIO_LD5_B, true);
gpio_write(GPIO_LD5_G, false);
intr_blink++;
}
else if (intr_blink == 2)
{
{
gpio_write(GPIO_LD5_R, false);
gpio_write(GPIO_LD5_B, false);
gpio_write(GPIO_LD5_G, true);
intr_blink++;
}
else
{
{
gpio_write(GPIO_LD5_R, false);
gpio_write(GPIO_LD5_B, false);
gpio_write(GPIO_LD5_G, false);
Expand Down Expand Up @@ -512,7 +512,7 @@ void vApplicationIdleHook( void )
taskENTER_CRITICAL();
printf("I\r\n");
taskEXIT_CRITICAL();

}
/*-----------------------------------------------------------*/

Expand Down Expand Up @@ -556,7 +556,7 @@ void vApplicationTickHook( void )
int main( void )
{
SetupHardware();

//printf("Going into main_blinky\n\r");

/* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
Expand All @@ -567,10 +567,10 @@ int main( void )
}
#else
{
#error "Full demo is not available in this project.
#error "Full demo is not available in this project.
}
#endif

//should never reach this point
for(;;);
}
Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_gpio_intr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_gpio_toggle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
8 changes: 4 additions & 4 deletions sw/applications/example_i2s/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "i2s_structs.h"


#ifdef TARGET_PYNQ_Z2
#ifdef TARGET_FPGA
#define I2S_TEST_BATCH_SIZE 128
#define I2S_TEST_BATCHES 16
#define I2S_CLK_DIV 8
Expand Down Expand Up @@ -72,7 +72,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down Expand Up @@ -173,7 +173,7 @@ void setup()
int main(int argc, char *argv[]) {
bool success = true;

#ifdef TARGET_PYNQ_Z2
#ifdef TARGET_FPGA
for (uint32_t i = 0; i < 0x10000; i++) asm volatile("nop");
#endif
PRINTF("I2S DEMO\r\n\r");
Expand All @@ -182,7 +182,7 @@ int main(int argc, char *argv[]) {

//PRINTF("Setup done!\r\n\r");

#ifdef TARGET_PYNQ_Z2
#ifdef TARGET_FPGA


for (uint32_t i = 0; i < I2S_WAIT_CYCLES; i++) asm volatile("nop");
Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_matadd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_matfadd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_pdm2pcm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_power_gating_core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_power_gating_external/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_power_gating_periph/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
2 changes: 1 addition & 1 deletion sw/applications/example_power_gating_ram_blocks/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if TARGET_SIM && PRINTF_IN_SIM
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#elif TARGET_PYNQ_Z2 && PRINTF_IN_FPGA
#elif TARGET_FPGA && PRINTF_IN_FPGA
#define PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
#else
#define PRINTF(...)
Expand Down
Loading