-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (51 loc) · 1.29 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// https://github.com/usbarmory/tamago-example
//
// Copyright (c) WithSecure Corporation
// https://foundry.withsecure.com
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
//go:build tamago
// +build tamago
package main
import (
"fmt"
"io"
"log"
"os"
"runtime"
"github.com/usbarmory/tamago/soc/nxp/enet"
"github.com/usbarmory/tamago/soc/nxp/usb"
"github.com/usbarmory/tamago-example/cmd"
"github.com/usbarmory/tamago-example/internal/semihosting"
"github.com/usbarmory/tamago-example/network"
)
var Build string
var Revision string
func init() {
log.SetFlags(0)
cmd.Banner = fmt.Sprintf("%s/%s (%s) • %s %s",
runtime.GOOS, runtime.GOARCH, runtime.Version(),
Revision, Build)
cmd.Banner += fmt.Sprintf(" • %s", cmd.Target())
}
func main() {
var usb *usb.USB
var eth *enet.ENET
logFile, _ := os.OpenFile("/tamago-example.log", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
log.SetOutput(io.MultiWriter(os.Stdout, logFile))
hasUSB, hasEth := cmd.HasNetwork()
if hasUSB {
usb = network.StartUSB(cmd.Handler, logFile)
}
if hasEth {
eth = network.StartEth(cmd.Handler, logFile)
}
if hasUSB || hasEth {
network.SetupStaticWebAssets()
network.StartInterruptHandler(usb, eth)
} else {
cmd.SerialConsole()
semihosting.Exit()
}
}