0
\$\begingroup\$

I don't have much experience with embedded systems and I am trying to check if is possible to determine if a register is made of inputs or outputs or a mix of inputs and outputs.

Let's say I have a 32 bit register like so: "11111111111000000000000000000000"

Is there a possibility to check if this is made of inputs/outputs/both ?

The project that I work on, already does this somehow when run on hardware, but I need to simulate a method that given a register determines what is made of.

\$\endgroup\$
  • 1
    \$\begingroup\$ What? register is a memory element. It has both inputs, to write it and outputs to read it. These are not always accessible to the programmer, but always exist internally. \$\endgroup\$ – Eugene Sh. Jun 23 '17 at 19:42
  • \$\begingroup\$ I don't have much experience with low level programming, but in my code there are 32 bits (unsigned), and I have to check if this unsigned value has all bits as inputs or outputs. Is that even possible ? \$\endgroup\$ – Adrian Jun 23 '17 at 19:46
  • \$\begingroup\$ Are you talking about some kind of GPIO direction control register? Which MCU is it? \$\endgroup\$ – Eugene Sh. Jun 23 '17 at 19:47
  • 1
    \$\begingroup\$ You know it from knowing the hardware. Open the datasheet and see if the register is RO, WO or RW. \$\endgroup\$ – Eugene Sh. Jun 23 '17 at 19:56
  • 1
    \$\begingroup\$ It's a rare case where you can tell the access direction of an arbitrary register programmatically. \$\endgroup\$ – Eugene Sh. Jun 23 '17 at 19:59
2
\$\begingroup\$

How to find out a register contains inputs or outputs or both?

By reading the register reference manual.

If the only thing you can do is read and write registers, there's no way to tell the difference between the following three cases, all of which are reasonably common:

  • a read-only bit that's currently zero
  • a bit that's unused and always reads as zero
  • a bit that's write-only and reads as zero

Worse, writing the wrong values to some registers may have unwanted, and possibly irreversible, effects on the peripheral.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.