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

Jiminy Support for hwrng and at86rfr2 transceiver #8742

Closed
wants to merge 4 commits into from

Conversation

Josar
Copy link
Contributor

@Josar Josar commented Mar 5, 2018

  1. Support for hwrng
  2. Included at86rfr2 support into at86rf2xx driver.

@jnohlgard
Copy link
Member

Could you open a separate PR for the atmega stack pointer commit? It will make review easier and keep this PR focused on one task.

@Josar
Copy link
Contributor Author

Josar commented Mar 6, 2018

@gebart done

@Josar Josar force-pushed the jiminy_master branch 2 times, most recently from 16379c3 to 35917ee Compare March 9, 2018 01:04
@Josar
Copy link
Contributor Author

Josar commented Mar 9, 2018

@PeterKietzmann maybe this is also interresting for you as you have the hardware at hand. ;-)

@Josar
Copy link
Contributor Author

Josar commented Mar 27, 2018

@gebart and @PeterKietzmann just curious if someone has time to review this?

@PeterKietzmann
Copy link
Member

@Josar, currently I don't have time to provide a proper review. I do my best to come back to this soon, but I can't promise anything.

@PeterKietzmann PeterKietzmann self-assigned this Mar 27, 2018
@PeterKietzmann PeterKietzmann added Area: drivers Area: Device drivers Area: boards Area: Board ports labels Mar 27, 2018
Copy link
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

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

There are some unrelated changes in here (code style, whitespace fixes etc) which I think is fine to have in the PR, but they should be in a separate commit before all of the rfr2 additions. There are also a few points in the rfr2 driver where I have some comments, see inline comments below

@@ -5,3 +5,4 @@ include $(RIOTCPU)/atmega_common/Makefile.features

# Various other features (if any)
FEATURES_PROVIDED += periph_cpuid
FEATURES_PROVIDED += periph_hwrng
Copy link
Member

Choose a reason for hiding this comment

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

Missing newline at end of file

#include "od.h"
#endif

#ifdef MODULE_AT86RFR2
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this whole block could go in its own file at86rfr2_isr or something? It's the only CPU dependent functionality in the driver so it makes sense to move it out of the generic parts.


/* Manual p. 119 radio transceiver in Basic Operating Mode receive state*/
while (TRX_STATUS != 0x06) {
TRX_STATE = 0x06;
Copy link
Member

Choose a reason for hiding this comment

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

I am worried that this will lead to a race between the radio driver and the hwrng driver

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please eleborate this?

Copy link
Member

Choose a reason for hiding this comment

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

Imagine this scenario:

  • two threads: a low priority thread that uses the hwrng, a high priority thread that reacts to some outside event (e.g. gpio interrupt, or timer)
  • hwrng thread is running and using the hwrng
  • outside event occurs, low priority thread is pre-empted in favor of the high priority thread
  • high priority thread wants to interact with the radio in some way (e.g. Send packet or put the radio to sleep)
  • hwrng has left the transceiver in an unexpected state. <- possible problem
  • high priority thread finishes
  • hwrng restores a state which was saved before, possibly overwriting what the high priority thread did. <- Possible problem.

regVal = regVal >> 5;
regVal = regVal << 2 * i;
rnd |= regVal;
xtimer_usleep(1);
Copy link
Member

Choose a reason for hiding this comment

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

Is this sleep necessary to the hardware timing? It is short enough to be better suited for xtimer_spin.


#ifdef MODULE_AT86RFR2
/* Store device pointer for interrupts */
static_dev = (netdev_t *)dev;
Copy link
Member

Choose a reason for hiding this comment

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

I assume the at86rfr2 only ever has one transceiver in the same CPU

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a SOC and will ever features only one transceiver.
You could also add an additional external transceiver, but this is also not featured with the current implementation. And i do not see why someone would do this.

Copy link
Member

Choose a reason for hiding this comment

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

I guess this would fall under #4876. The static_dev variable is fine since there is only one instance of the rfr2

/* enable interrupts */
at86rf2xx_reg_write(dev, AT86RF2XX_REG__IRQ_MASK,
AT86RF2XX_IRQ_STATUS_MASK__TRX_END);
/* clear interrupt flags */
at86rf2xx_reg_read(dev, AT86RF2XX_REG__IRQ_STATUS);
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated change, please split into its own commit

// dev->idle_state = state;
// }

while (state != AT86RF2XX_STATE_TX_ARET_ON) {
Copy link
Member

Choose a reason for hiding this comment

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

This change is not obvious what it fixes, what was broken before?
It should probably go in a separate commit.

@@ -19,16 +19,18 @@ ifneq (,$(filter at30tse75x,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c
endif

ifneq (,$(filter at86rf2%,$(USEMODULE)))
ifneq (,$(filter at86rf2% at86rfr2,$(USEMODULE)))
USEMODULE += at86rf2xx
USEMODULE += xtimer
USEMODULE += luid
USEMODULE += netif
USEMODULE += ieee802154
USEMODULE += netdev_ieee802154
FEATURES_REQUIRED += periph_gpio
Copy link
Member

Choose a reason for hiding this comment

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

Does the rfr2 need gpio?


#ifdef MODULE_AT86RFR2
/* SOC uses no SPI, but uses memcpy */
#include <string.h>
Copy link
Member

Choose a reason for hiding this comment

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

These should not be indented

#ifdef MODULE_AT86RFR2

/* check if frame buffer protection is active, rx frame was not read jet*/
/* if( ( *(AT86RF2XX_REG__TRX_CTRL_2) &(1<<RX_SAFE_MODE)) != 0)
Copy link
Member

Choose a reason for hiding this comment

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

Dead code

@jnohlgard
Copy link
Member

One more question: does the hwrng driver stand on its own or does it require the at86rf2xx driver to be initialized beforehand?
If it does, then the dependencies need to reflect that in one way or the other.

@Josar
Copy link
Contributor Author

Josar commented Mar 28, 2018

The hwrng is intentional not dependent on the at86rf2xx Module. This maybe lead to a little bit of overhead but i think this is okay.

@jnohlgard
Copy link
Member

Is there any risk that initialization of the hwrng driver will mess up the state of the at86rf2xx driver? They are touching the same hardware after all

@Josar
Copy link
Contributor Author

Josar commented Mar 28, 2018

Yes, there is. And for that all states are saved and set back to previous states.

Reading exactly what you wrote, NO, there is nothing done in initialization.

Everything is done when reading some random numbers and set back afterwards.

@Josar Josar force-pushed the jiminy_master branch 4 times, most recently from 81086d4 to 05e1494 Compare March 28, 2018 16:38
@Josar Josar force-pushed the jiminy_master branch 5 times, most recently from 5306d1a to f60ee90 Compare April 19, 2018 19:20
@Josar
Copy link
Contributor Author

Josar commented Apr 19, 2018

@gebart tried to addressed your requests. Had to rebase as evtimer changes had to be applied for proper function.

@Josar
Copy link
Contributor Author

Josar commented May 8, 2018

@gebart and @PeterKietzmann maybe you could find some time to review this?
Rebased as there where some bigger changes in the atmegas.

Copy link
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

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

hwrng: Some code style issues exist, and I am not sure that xtimer is necessary in the current implementation.
Did not have time to review the radio changes

uint8_t rnd = 0;
for (uint8_t i = 0; i < 4; ++i) {
/* Random value update period 1us p. 47*/
xtimer_spin(wait);
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary?
I imagine that the CPU instructions leading up to this point take at least 1 µs on atmegas?

transition();

/* Manual p. 119 radio transceiver has to be in Basic Operating Mode receive state*/
if ( (TRX_STATUS&0x1f)!= 0x06) {
Copy link
Member

Choose a reason for hiding this comment

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

this 0x1f magic number is used in several places in this file, it should be converted to a define, or if possible, reuse the hardware register bit masks from the radio driver.

RX_SYN &= ~(1 << RX_PDT_DIS);

/* Manual p. 105 RPC/SRT has to be disabled. */
TRX_RPC &= ~(1<<RX_RPC_CTRL1 | 1<<RX_RPC_CTRL0);
Copy link
Member

Choose a reason for hiding this comment

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

uncrustify should be able to fix code style spacing and indentation issues in this file. There is a configuration in the RIOT tree root (uncrustify-riot.cfg)

@Josar
Copy link
Contributor Author

Josar commented May 23, 2018

Closed in favor of #9172

@gebart thread concurrency has to be solved in future releases so i will skip hwrng in favor of the transciever.
#8742 (comment)

@Josar Josar closed this May 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: drivers Area: Device drivers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants