Skip to content

Conversation

@mprse
Copy link
Contributor

@mprse mprse commented Aug 1, 2019

Description

The following PR adds Verilog FPGA Timer implementation: ARMmbed/fpga-ci-test-shield#1 (must be merged before this one).

The intention of FPGA Timer is to have a very accurate timer to measure elapsed time or generate delays. The FPGA timer might be very useful in the timing tests, which are currently quite problematic.

Possible usage of the FPGA Timer:

  • Use FPGA Timer for timing tests which currently uses Time Drift model and communicate with the Host PC. These tests are not very accurate and were causing problems on CI (at the moment all time drift tests are disabled on CI). We can update these tests to use FPGA timer instead Time Drift model and reenable them on CI (e98819b, dd8d8f4).
  • Use FPGA Timer as a reference in Ticker/Timer/Timeout tests. As far as I remember in these tests lp ticker is used to verify us ticker and vice versa. We could improve these tests to use FPGA Timer as a reference.
  • Watchdog tests. With FPGA Timer we can probably check when the watchdog fired.
  • All other timing tests: task scheduling, system tick, event queue, etc.

Example code:

#include "mbed.h"
#include "MbedTester.h"

const PinList *form_factor = pinmap_ff_default_pins();
const PinList *restricted = pinmap_restricted_pins();
MbedTester tester(form_factor, restricted);

void test()
{
    tester.reset();

    tester.timer_init();

    tester.peripherals_reset();

    tester.select_peripheral(MbedTester::PeripheralTimer);

    // FPGA Timer Example - count elapsed time
    tester.timer_set_mode(MbedTester::TimerModeTimer);

    tester.timer_reset();

    tester.timer_start();

    wait_ns(5000000); // 5 ms

    tester.timer_stop();

    printf("FPGA Timer [ns]: %llu \r\n", tester.timer_read_ns());
    printf("FPGA Timer [us]: %lu \r\n", tester.timer_read_us());
    printf("FPGA Timer [ms]: %lu \r\n", tester.timer_read_ms());

    // FPGA Count-Down-Timer Example - perform delay
    tester.timer_set_mode(MbedTester::TimerModeCountDownTimer);

    tester.timer_set_delay_ms(10);

    tester.timer_reset();

    Timer timer;

    timer.start();

    tester.timer_delay();

    timer.stop();

    printf("Mbed Timer [us] : %i \r\n", timer.read_us());
    printf("Mbed Timer [ms] : %i \r\n", timer.read_ms());

    tester.timer_free();
}

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[X] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@c1728p9 @jamesbeyond @fkjagodzinski @maciejbocianski

mprse added 3 commits August 1, 2019 09:05
Example usage:

```

const PinList *form_factor = pinmap_ff_default_pins();
const PinList *restricted = pinmap_restricted_pins();
MbedTester tester(form_factor, restricted);

void test()
{
    tester.reset();

    tester.timer_init();

    tester.peripherals_reset();

    tester.select_peripheral(MbedTester::PeripheralTimer);

    // FPGA Timer Example- count elapsed time
    tester.timer_set_mode(MbedTester::TimerModeTimer);

    tester.timer_reset();

    tester.timer_start();

    wait_ns(5000000); // 5 ms

    tester.timer_stop();

    printf("FPGA Timer [ns]: %llu \r\n", tester.timer_read_ns());
    printf("FPGA Timer [us]: %lu \r\n", tester.timer_read_us());
    printf("FPGA Timer [ms]: %lu \r\n", tester.timer_read_ms());

    // FPGA Count-Down-Timer Example - perform delay
    tester.timer_set_mode(MbedTester::TimerModeCountDownTimer);

    tester.timer_set_delay_ms(10);

    tester.timer_reset();

    Timer timer;

    timer.start();

    tester.timer_delay();

    timer.stop();

    printf("Mbed Timer [us] : %i \r\n", timer.read_us());
    printf("Mbed Timer [ms] : %i \r\n", timer.read_ms());

    tester.timer_free();
}

```
@ciarmcom
Copy link
Member

ciarmcom commented Aug 1, 2019

@mprse, thank you for your changes.
@fkjagodzinski @maciejbocianski @jamesbeyond @c1728p9 @ARMmbed/mbed-os-hal @ARMmbed/mbed-os-test @ARMmbed/mbed-os-maintainers please review.

Copy link
Member

@fkjagodzinski fkjagodzinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. 👍 Just a couple of minor flaws to resolve.

/*
* These are the peripherals internal to the FPGA. A peripheral can be
* selected by calling MbedTester::select_peripheral.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems out of place.

@@ -0,0 +1,129 @@
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current location of this file (TESTS/mbed_hal_fpga_ci_test_shield/basic/main.cpp) is a bit misleading. I think this directory should be renamed to something like rtos-basic.

@@ -0,0 +1,129 @@
/*
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
* Copyright (c) 2013-2019, ARM Limited, All Rights Reserved

Update the date if modified. This also applies for the following files.

uint32_t start, stop;

tester.reset();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of empty lines here.

tester.timer_init();

tester.peripherals_reset();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty lines.


/**
* Execute programed FPGA Count Down Timer delay
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should explicitly state this is a blocking call.

@fkjagodzinski
Copy link
Member

BTW, the example code is missing main(). 🤓

@adbridge
Copy link
Contributor

@mprse what is the status of this PR ?

@mprse
Copy link
Contributor Author

mprse commented Sep 30, 2019

@mprse what is the status of this PR ?

All review comments have been addressed. @fkjagodzinski Thanks for the review.
PR is ready for further review/CI.

Copy link
Member

@fkjagodzinski fkjagodzinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks OK now. But still, I don't see the need to have that many empty lines here and here

@jamesbeyond
Copy link
Contributor

Hi @mprse are these test will require we having a new release of FPGA images? currently we are using
https://github.com/ARMmbed/fpga-ci-test-shield/releases/tag/v0001

@mprse
Copy link
Contributor Author

mprse commented Oct 2, 2019

Yes. The FPGA test shield firmware will need to be updated to run these test.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 18, 2019

The following PR adds Verilog FPGA Timer implementation: ARMmbed/fpga-ci-test-shield#1 (must be merged before this one).

We should make sure that one is in first. I've left a comment there to get it moving again.

@@ -0,0 +1,47 @@
/* mbed Microcontroller Library
* Copyright (c) 2017-2017 ARM Limited
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add SPDX identifiers to new files

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 23, 2019

Two things to do: fix one style error and SPDX identifier for new files

@mprse
Copy link
Contributor Author

mprse commented Oct 25, 2019

Fixed style and added SPDX header. It looks like its ready.
@0xc0170 I will close this one since it requires updated firmware for the FPGA-test-shield. Next year we are planning to add I2C Slave tester and FPGA timer support for the test shield. When both features are ready and new firmware is available I will reopen this PR.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 25, 2019

Closing as requested

@0xc0170 0xc0170 closed this Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants