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

Add startsWith function to HGS language #994

Merged
merged 2 commits into from
Jul 26, 2022
Merged

Conversation

holstvoogd
Copy link
Contributor

@holstvoogd holstvoogd commented Jul 23, 2022

I'm creating a config for a Butterstick board & needed a way to neatly customize some constraints for all ports starting with some prefix.

Example of how I use it:

func pin(name, pin) {
    io_type := "LVCMOS33";
    misc := "";

    if ( startsWith(name, "user_btn") ) { io_type = "SSTL135_I"; }
    if ( startsWith(name, "ulpi_") ) { io_type = "LVCMOS18"; misc="SLEWRATE=FAST"; }
    if ( name = "rst_n" ) { misc = "OPENDRAIN=ON"; }

    config := "LOCATE COMP \""+ name + "\" SITE \""+ pin +"\";";
    config = config + "\nIOBUF PORT \""+ name + "\" IO_TYPE=" + io_type + " " + misc + ";";

    if (name = "clk30") { config = config + "\nFREQUENCY PORT \"clk30\" 30.0 MHz;"; }

    return config + "\n";
}
for (i:=0; i<sizeOf(model.ports); i++) {
    port:=model.ports[i];
    if (port.bits=1) {
        println(pin(port.name, port.pin));
    } else {
        pins := splitString(port.pin);
        for (p:=0;p<sizeOf(pins);p++) {
          println(pin(port.name + "[" + p + "]", pins[p]));
        }
    }
}

It builds & verifies. And I've confirmed it works for generating my constraints file.

Since it seems most trivial functions are not explicitly tested, I didn't add one for this either. Let me know if I should add one though!

@codecov-commenter
Copy link

codecov-commenter commented Jul 23, 2022

Codecov Report

Merging #994 (3e8f43c) into master (e46b2bd) will increase coverage by 0.0%.
The diff coverage is 100.0%.

@@           Coverage Diff            @@
##             master    #994   +/-   ##
========================================
  Coverage      56.6%   56.6%           
- Complexity     6553    6554    +1     
========================================
  Files           679     679           
  Lines         35358   35359    +1     
  Branches       4761    4761           
========================================
+ Hits          20042   20043    +1     
  Misses        14111   14111           
  Partials       1205    1205           
Impacted Files Coverage Δ
.../main/java/de/neemann/digital/hdl/hgs/Context.java 79.5% <100.0%> (+<0.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e46b2bd...3e8f43c. Read the comment docs.

@hneemann hneemann merged commit 751a453 into hneemann:master Jul 26, 2022
miquelt9 pushed a commit to miquelt9/Digital that referenced this pull request Dec 13, 2024
* Add startsWith function to HGS language

* Add test for startsWith()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants