mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-02 01:57:48 +00:00
Compare commits
1 Commits
dev
...
gen-device-svd
| Author | SHA1 | Date | |
|---|---|---|---|
| fa79f561ac |
@@ -120,22 +120,22 @@ gen-device-avr:
|
|||||||
@GO111MODULE=off $(GO) fmt ./src/device/avr
|
@GO111MODULE=off $(GO) fmt ./src/device/avr
|
||||||
|
|
||||||
build/gen-device-svd: ./tools/gen-device-svd/*.go
|
build/gen-device-svd: ./tools/gen-device-svd/*.go
|
||||||
$(GO) build -o $@ ./tools/gen-device-svd/
|
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -o $@ ./tools/gen-device-svd/
|
||||||
|
|
||||||
gen-device-esp: build/gen-device-svd
|
gen-device-esp: build/gen-device-svd
|
||||||
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Espressif-Community -interrupts=software lib/cmsis-svd/data/Espressif-Community/ src/device/esp/
|
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Espressif-Community -only-used -interrupts=software lib/cmsis-svd/data/Espressif-Community/ src/device/esp/
|
||||||
GO111MODULE=off $(GO) fmt ./src/device/esp
|
GO111MODULE=off $(GO) fmt ./src/device/esp
|
||||||
|
|
||||||
gen-device-nrf: build/gen-device-svd
|
gen-device-nrf: build/gen-device-svd
|
||||||
./build/gen-device-svd -source=https://github.com/NordicSemiconductor/nrfx/tree/master/mdk lib/nrfx/mdk/ src/device/nrf/
|
./build/gen-device-svd -source=https://github.com/NordicSemiconductor/nrfx/tree/master/mdk -only-used lib/nrfx/mdk/ src/device/nrf/
|
||||||
GO111MODULE=off $(GO) fmt ./src/device/nrf
|
GO111MODULE=off $(GO) fmt ./src/device/nrf
|
||||||
|
|
||||||
gen-device-nxp: build/gen-device-svd
|
gen-device-nxp: build/gen-device-svd
|
||||||
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/NXP lib/cmsis-svd/data/NXP/ src/device/nxp/
|
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/NXP -only-used lib/cmsis-svd/data/NXP/ src/device/nxp/
|
||||||
GO111MODULE=off $(GO) fmt ./src/device/nxp
|
GO111MODULE=off $(GO) fmt ./src/device/nxp
|
||||||
|
|
||||||
gen-device-sam: build/gen-device-svd
|
gen-device-sam: build/gen-device-svd
|
||||||
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Atmel lib/cmsis-svd/data/Atmel/ src/device/sam/
|
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Atmel -only-used lib/cmsis-svd/data/Atmel/ src/device/sam/
|
||||||
GO111MODULE=off $(GO) fmt ./src/device/sam
|
GO111MODULE=off $(GO) fmt ./src/device/sam
|
||||||
|
|
||||||
gen-device-sifive: build/gen-device-svd
|
gen-device-sifive: build/gen-device-svd
|
||||||
@@ -143,11 +143,11 @@ gen-device-sifive: build/gen-device-svd
|
|||||||
GO111MODULE=off $(GO) fmt ./src/device/sifive
|
GO111MODULE=off $(GO) fmt ./src/device/sifive
|
||||||
|
|
||||||
gen-device-kendryte: build/gen-device-svd
|
gen-device-kendryte: build/gen-device-svd
|
||||||
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Kendryte-Community -interrupts=software lib/cmsis-svd/data/Kendryte-Community/ src/device/kendryte/
|
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Kendryte-Community -only-used -interrupts=software lib/cmsis-svd/data/Kendryte-Community/ src/device/kendryte/
|
||||||
GO111MODULE=off $(GO) fmt ./src/device/kendryte
|
GO111MODULE=off $(GO) fmt ./src/device/kendryte
|
||||||
|
|
||||||
gen-device-stm32: build/gen-device-svd
|
gen-device-stm32: build/gen-device-svd
|
||||||
./build/gen-device-svd -source=https://github.com/tinygo-org/stm32-svd lib/stm32-svd/svd src/device/stm32/
|
./build/gen-device-svd -source=https://github.com/tinygo-org/stm32-svd -only-used lib/stm32-svd/svd src/device/stm32/
|
||||||
GO111MODULE=off $(GO) fmt ./src/device/stm32
|
GO111MODULE=off $(GO) fmt ./src/device/stm32
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -13,6 +15,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/tinygo-org/tinygo/builder"
|
||||||
|
"github.com/tinygo-org/tinygo/compileopts"
|
||||||
|
"github.com/tinygo-org/tinygo/goenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var validName = regexp.MustCompile("^[a-zA-Z0-9_]+$")
|
var validName = regexp.MustCompile("^[a-zA-Z0-9_]+$")
|
||||||
@@ -1164,7 +1170,7 @@ Default_Handler:
|
|||||||
return w.Flush()
|
return w.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func generate(indir, outdir, sourceURL, interruptSystem string) error {
|
func generate(indir, outdir, sourceURL, interruptSystem string, onlyUsed bool) error {
|
||||||
if _, err := os.Stat(indir); os.IsNotExist(err) {
|
if _, err := os.Stat(indir); os.IsNotExist(err) {
|
||||||
fmt.Fprintln(os.Stderr, "cannot find input directory:", indir)
|
fmt.Fprintln(os.Stderr, "cannot find input directory:", indir)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -1177,7 +1183,14 @@ func generate(indir, outdir, sourceURL, interruptSystem string) error {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
sort.Strings(infiles)
|
sort.Strings(infiles)
|
||||||
|
|
||||||
|
targets := tinygoTargets()
|
||||||
for _, infile := range infiles {
|
for _, infile := range infiles {
|
||||||
|
if onlyUsed {
|
||||||
|
if !targets[strings.ToLower(strings.TrimSuffix(filepath.Base(infile), filepath.Ext(infile)))] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
fmt.Println(infile)
|
fmt.Println(infile)
|
||||||
device, err := readSVD(infile, sourceURL)
|
device, err := readSVD(infile, sourceURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1202,9 +1215,59 @@ func generate(indir, outdir, sourceURL, interruptSystem string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tinygoTargets() map[string]bool {
|
||||||
|
names := []string{}
|
||||||
|
|
||||||
|
dir := filepath.Join(goenv.Get("TINYGOROOT"), "targets")
|
||||||
|
entries, err := ioutil.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "could not list targets:", err)
|
||||||
|
os.Exit(1)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for _, entry := range entries {
|
||||||
|
if !entry.Mode().IsRegular() || !strings.HasSuffix(entry.Name(), ".json") {
|
||||||
|
// Only inspect JSON files.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
path := filepath.Join(dir, entry.Name())
|
||||||
|
spec, err := compileopts.LoadTarget(path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "could not list target:", err)
|
||||||
|
os.Exit(1)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if spec.FlashMethod == "" && spec.FlashCommand == "" && spec.Emulator == nil {
|
||||||
|
// This doesn't look like a regular target file, but rather like
|
||||||
|
// a parent target (such as targets/cortex-m.json).
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name := entry.Name()
|
||||||
|
name = name[:len(name)-5]
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
tags := map[string]bool{}
|
||||||
|
for _, tgt := range names {
|
||||||
|
options := &compileopts.Options{
|
||||||
|
Target: tgt,
|
||||||
|
}
|
||||||
|
config, err := builder.NewConfig(options)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, tag := range config.BuildTags() {
|
||||||
|
tags[tag] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tags
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
sourceURL := flag.String("source", "<unknown>", "source SVD file")
|
sourceURL := flag.String("source", "<unknown>", "source SVD file")
|
||||||
interruptSystem := flag.String("interrupts", "hardware", "interrupt system in use (software, hardware)")
|
interruptSystem := flag.String("interrupts", "hardware", "interrupt system in use (software, hardware)")
|
||||||
|
onlyUsed := flag.Bool("only-used", false, "generate only what is defined in target")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if flag.NArg() != 2 {
|
if flag.NArg() != 2 {
|
||||||
fmt.Fprintln(os.Stderr, "provide exactly two arguments: input directory (with .svd files) and output directory for generated files")
|
fmt.Fprintln(os.Stderr, "provide exactly two arguments: input directory (with .svd files) and output directory for generated files")
|
||||||
@@ -1213,7 +1276,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
indir := flag.Arg(0)
|
indir := flag.Arg(0)
|
||||||
outdir := flag.Arg(1)
|
outdir := flag.Arg(1)
|
||||||
err := generate(indir, outdir, *sourceURL, *interruptSystem)
|
err := generate(indir, outdir, *sourceURL, *interruptSystem, *onlyUsed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user