Skip to content

Fix handling of isDefault' enumeratedValue's #486

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

Merged

Conversation

smindinvern
Copy link
Contributor

Currently, an enumeratedValue is ignored if (and only if) it's name matches "reserved", and all remaining enumeratedValues are expected to have a value child element. However, the SVD schema allows an enumeratedValue to contain either a value element or an isDefault element. When svd2rust hits an isDefault element that isn't named "reserved", an error is thrown.

In general, filtering these out should be safe, as they don't represent specific values that can be assigned to a field, but rather a range of values. The ability to read and write such arbitrary values is already handled with the bits() method defined on field readers/writers. The one corner case, however, is for fields with only a single enumeratedValue which has an isDefault child element. Attempting to handle these in the usual way results in emitting empty enums which causes compilation failures. Instead, emit a newtype encapsulating the field's base type.

In the case that a register field has only a single `isDefault`
`enumeratedValue` defined in the SVD file, don't emit an `_A` `enum`
(as there are no valid variants to enumerate).  Instead, emit a tuple
struct with a single field which holds the value of the register field.
@smindinvern smindinvern requested a review from a team as a code owner December 7, 2020 20:56
@rust-highfive
Copy link

r? @adamgreig

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools labels Dec 7, 2020
@smindinvern smindinvern changed the title Fix handling of isDefault enumeratedValues Fix handling of isDefault' enumeratedValue's Dec 7, 2020
@Emilgardis
Copy link
Member

Comes initially from #485

@therealprof
Copy link
Contributor

Is there a specific svd file that exhibits this conflict?

@smindinvern
Copy link
Contributor Author

@therealprof: it was mentioned in #485, but specifically it happens with this file. One example is the FSA field in R_FACI_HP.FSADDR:

<register>
  <name>FSADDR</name>
  <description>Flash Start Address</description>
  <addressOffset>0x0030</addressOffset>
  <size>32</size>
  <access>read-write</access>
  <resetValue>0x00000000</resetValue>
  <resetMask>0xFFFFFFFF</resetMask>
  <fields>
    <field>
      <name>FSA</name>
      <description>Start Address of Flash Sequencer Command Target Area
  These bits can be written when FRDY bit of FSTATR register is "1". Writing to these bits in FRDY = "0" is ignored.</description>
      <lsb>0</lsb>
      <msb>31</msb>
      <access>read-write</access>
      <enumeratedValues>
        <enumeratedValue>
          <name>others</name>
          <description>Specifies start address for each command processing.</description>
          <isDefault>true</isDefault>
        </enumeratedValue>
      </enumeratedValues>
    </field>
  </fields>
</register>

@smindinvern
Copy link
Contributor Author

Anything I could do to make this easier/more ready to review?

Copy link
Contributor

@therealprof therealprof left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, LGTM. Thanks a lot.

bors r+

@bors bors bot merged commit 4877d5c into rust-embedded:master Jan 29, 2021
smindinvern added a commit to smindinvern/svd2rust that referenced this pull request Feb 2, 2021
bors bot added a commit that referenced this pull request Feb 3, 2021
490: Update CHANGELOG for #485 and #486 r=burrbull a=smindinvern

As requested in #485 

Co-authored-by: Nickolas Lloyd <smindinvern@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants