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

Merge staging into main #15

Draft
wants to merge 57 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
162d5c2
Add clean script, update install.md (#14)
gcohler Sep 19, 2024
ac4ee27
Simplify logic to handle 32-bit RTC wrapping (#16)
gcohler Sep 20, 2024
b0840c7
Bug in ticker.stop fixed (#19)
gcohler Sep 20, 2024
b78e019
Add microsecond methods to OneShot (#20)
biosbob Sep 21, 2024
03a77d4
Change to more robust Alarm ring logic (#25)
gcohler Sep 22, 2024
4bceb97
Add combo example and fixes AlarmMgr (#21)
gcohler Sep 23, 2024
ec4ccac
EpochTime.getCurrent() doesn't appear to return valid subSeconds valu…
biosbob Sep 23, 2024
3a71ddc
Rename stuff and add ms to timestamp printout (#27)
gcohler Sep 23, 2024
298f100
Remove extra alarm prop (#28)
gcohler Sep 23, 2024
799d233
expand epoch time printout (#30)
gcohler Sep 24, 2024
07dd011
Improve console logging for easier usage (#31)
gcohler Sep 24, 2024
21bf32a
Fix conversion error from sub_seconds (#29)
gcohler Sep 24, 2024
f40a064
Issue Improve zls-em "dot" completion (#33)
biosbob Sep 26, 2024
42253ab
Print time in quasi-iso format (#34)
gcohler Sep 28, 2024
60f0c62
Major refactor to remove use namespace (#37)
biosbob Oct 4, 2024
1be5f0c
Update timer operations with new time type (secs24p8) (#39)
biosbob Oct 7, 2024
c61ad84
add em.coremark bucket (#40)
biosbob Oct 11, 2024
a4d493b
general refactoring (#41)
biosbob Oct 13, 2024
a3e9f4b
vscode-zigem 0.0.2 patch update (#43)
biosbob Oct 14, 2024
208943c
zigem publish (#44)
biosbob Oct 20, 2024
b33f2bd
infrastructure features (#45)
biosbob Nov 5, 2024
426affa
infrastructure changes (#46)
biosbob Nov 11, 2024
e9d64c0
Fix filename typos
gcohler Nov 13, 2024
3591f68
Fix bad filename
gcohler Nov 13, 2024
de594ab
Add test script - and fix nit in BlinkerDbgP printout
gcohler Nov 13, 2024
2e4a65a
Move scripts to utils folder and break into pieces
gcohler Nov 13, 2024
a13b1cd
zigem publish enhancements (#48)
biosbob Nov 13, 2024
2fb339a
zigem publish fixes (#50)
biosbob Nov 14, 2024
5fcce63
Improve testing: Add -b (build only) and -p (promptBetweenTests) swi…
gcohler Nov 14, 2024
bb60803
Fix missing path
gcohler Nov 15, 2024
d4d97c3
Clean up tests, add some color
gcohler Nov 15, 2024
bae5660
Add publish script to utils / full_test
gcohler Nov 15, 2024
01da3d8
Check for zig & make as part of install
gcohler Nov 15, 2024
c36e147
Check for input on Windows
gcohler Nov 16, 2024
ff8a260
...
gcohler Nov 16, 2024
67f1e95
...
gcohler Nov 16, 2024
9084f39
Publisher: nit + re-publish (#51)
biosbob Nov 16, 2024
e22e2bb
Add publish changes
gcohler Nov 16, 2024
b953af5
Revert "Add publish changes"
gcohler Nov 16, 2024
d84beb2
fix logic on autocrlf checking
gcohler Nov 16, 2024
a37092f
Add make to install.md
gcohler Nov 16, 2024
3c1ae82
zigem {markdown,parse} enhancements (#52)
biosbob Nov 17, 2024
48812e3
zigem markdown: retry (#53)
biosbob Nov 18, 2024
3441301
Add new script to build all programs and generate md table of results
gcohler Nov 18, 2024
dccb672
Add chips / setups to test loops
gcohler Nov 18, 2024
268548e
add flash setup (#55)
biosbob Nov 19, 2024
4e41007
vscode-zigem deployment (#56)
biosbob Nov 19, 2024
8068e50
Install extension from vscode hub (cloud)
gcohler Nov 19, 2024
aec0fbf
Fix nit in table printout
gcohler Nov 19, 2024
e7d81bf
zls-em => zigem-zls (#57)
biosbob Nov 20, 2024
f4a62a3
zigem render: //#region zigem fix (#58)
biosbob Nov 21, 2024
b924548
Change -b switch on utils to -l for load (default false)
gcohler Nov 22, 2024
e9ae20f
build in release=safe mode and show summary when done
gcohler Nov 23, 2024
272c141
em.used operator (#59)
biosbob Nov 23, 2024
5a2eef5
Add comparison with last results
gcohler Nov 26, 2024
25ddf6b
Add -c switch for compare
gcohler Dec 1, 2024
d5f8103
Add -m to use most recent for compare
gcohler Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ workspace/zigem
workspace/.gen
workspace/.out
workspace/.main-*.zig
workspace/.zigem-main.zig
workspace/.zigem-*.zig
utils/*.log
utils/*.log~
44 changes: 36 additions & 8 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
# Installation

## Pre-requisites
These installation instructions contain example commands used in an Ubuntu Linux environment. Similar operations will work for Windows / MacOS, and we will add them here over time.

### Required PC Hardware / Operating System
ZigEm is focused on low-power, small-code operation. As such, we run it on a tiny wireless chip (the Texas Instruments CC2340) to demonstrate its effectiveness. Programs written are cross-compiled for the CC2340, and loaded onto the CC2340 chip for operation. We use a TI LaunchPad for the CC2340 chip as the evaluation hardware. The LaunchPad includes the CC2340 along with a Bluetooth 5.0 radio, a serial UART, two LEDs (red and green), and a push-button. ZigEm uses these devices in addition to the processor itself.

Please visit the ZigEm blog: https://blog.zigem.tech/ for much more information and insight.

## Pre-requisite Requirements

### PC Hardware / Operating System

ZigEm requires one of three different PC / Operating Systems for development, compilation, etc. Only 64-bit x86 architectures are supported. And only Ubuntu, MacOS and Windows are supported.

### Required Embedded Hardware
### Make

ZigEm requires make to be installed and in the path. On Windows, you'll need to download and install make (https://gnuwin32.sourceforge.net/packages/make.htm).

### Git

If using a Windows PC, you'll need to download and install `Git for Windows` (https://git-scm.com/download/win) and use a `git bash` window to do the below.

For MacOS or Linux, bash is included, but you'll need to be sure that `git` is installed.

### Embedded Hardware

ZigEm requires that you purchase the following two items from Texas Instruments (or one of their distributors e.g. Arrow, DigiKey, Mouser).

In the future we may support additional hardware. But for now, the only way to run ZigEm programs is on the hardware specified below.

Note: If you already own an XDS110 Debugger, it may be configured to work with the LaunchPad. We are suggesting the XDS110ET because it is the simplest connection and best suited to this job.
Note: The XDS110-style debugger called out below is available in other forms; sometimes as part of a different LaunchPad board, and sometimes stand-alone. If you already own an XDS110 Debugger, it may be configured to work with the CC2340R5 LaunchPad. We are suggesting the XDS110ET model because it is the simplest connection. Using another XDS110 debugger can be done but will likely require jumper wires rather than the simple connector used herein.

| Item | TI part number | Price (approx) | Links to purchase from TI |
| ------------------------------ | -------------- | -------------- | -------------------------------------- |
| TI CC2340R5 LauncPad board | LP-EM-CC2340R5 | $30 | https://www.ti.com/tool/LP-EM-CC2340R5 |
| TI XDS110ET LaunchPad debugger | LP-XDS110ET | $50 | https://www.ti.com/tool/LP-XDS110ET |
| TI CC2340R5 LaunchPad board | LP-EM-CC2340R5 | $30 | https://www.ti.com/tool/LP-EM-CC2340R5 |
| TI XDS110ET debugger | LP-XDS110ET | $50 | https://www.ti.com/tool/LP-XDS110ET |

These two pieces of hardware are the only two things that need to be purchased. Everything else needed for ZigEm is available at no cost.

Expand All @@ -42,8 +58,6 @@ source $HOME/.bashrc

- Clone the ZigEm repo into a folder

Note: Under Windows OS, you'll need to install `Git for Windows` (https://git-scm.com/download/win) and use a `git bash` window to do the below.

An example on Ubuntu; yours may vary:

``` bash
Expand Down Expand Up @@ -78,6 +92,8 @@ The ZigEm VScode Extension is not yet available in the VScode marketplace. As a
- In lower left: Settings => Command Pallette... => Extensions: Install from vsix...
- In file explorer pop-up, navigate to the `zig-out/tools` folder and select the supplied `vscode-zigem-<version>.vsix` file

Note: Because the extension is supplied as a .vsix file (rather than from the marketplace), it will not automatically prompt when an update comes out. We don't expect there to be frequent updates. However, every now and then you may want to check the `zig-out/tools` folder and repeat the above procedure if a newer version comes available.

## Install the Texas Instruments LaunchPad hardware

- Connect the CC2340R5 LaunchPad to the XDS110ET Debugger (via 2x10 connector)
Expand Down Expand Up @@ -128,3 +144,15 @@ zigem compile --load --file em.core/em.examples.basic/BlinkerP.em.zig
There are about a dozen additional example programs that can be run now as well.

Please consult additional ZigEm documentation and see https://blog.zigem.tech/ for more information.

## Just in case you want to clean out the installation

ZigEm and Zig maintain caches of previously downloaded / installed / built items. This allows for speedy operation.

If however for whatever reason you would like to "clean out" the caches, we have provided a bash script that will either do a _shallow_ or a _deep_ clean.

Usage: `clean.sh [-d, --deep]`

Without the `-d` or `--deep` option, the clean script will clean the workspace folder only; removing remnants of prior `zigem compile` commands.

With the deep cleaning option, the clean script will also clean out the remants of the prior `zig build` command.
11 changes: 4 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub fn build(b: *std.Build) void {
exe.root_module.addImport(name, dep.module(name));
}

exe.root_module.addImport("zls", b.dependency("zigem-zls", .{}).module("zls"));

const chmod_step = b.addSystemCommand(&.{ "chmod", "-R", "777", "zig-out/tools" });
exe.step.dependOn(&chmod_step.step);

Expand All @@ -34,17 +36,12 @@ pub fn build(b: *std.Build) void {
}
}

b.installDirectory(.{
.source_dir = b.dependency("vscode-zigem", .{}).path("."),
.install_dir = std.Build.InstallDir{ .custom = "tools" },
.install_subdir = "",
});
b.installArtifact(b.dependency("zls-em", .{}).artifact("zls-em"));
b.installArtifact(b.dependency("zigem-zls", .{}).artifact("zigem-zls"));
b.installArtifact(exe);

const verify_exe = b.addRunArtifact(exe);
verify_exe.setCwd(std.Build.LazyPath{ .src_path = .{ .owner = b, .sub_path = "workspace" } });
verify_exe.addArgs(&.{ "compile", "-f", "em.core/em.examples.basic/BlinkerP.em.zig" });
verify_exe.addArgs(&.{ "compile", "-f", "em.core/em.examples.basic/Ex02_BlinkerP.em.zig" });
const verify_step = b.step("verify", "Verify ZigEM");
verify_step.dependOn(&verify_exe.step);

Expand Down
16 changes: 6 additions & 10 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,19 @@
.hash = "12205de1eef9492a1cbee4461db6d9db803f14b32e5309ee4a036ac5a3d2a7640902",
.lazy = true,
},
.@"ti-uniflash-macos-x86_64" = .{
.url = "https://github.com/em-foundation/tools-pkg/releases/download/ti-uniflash-8.7.0/ti-uniflash-macos-x86_64.tar.gz",
.hash = "12203b87852ad433493c47cb209df32a3090d1b5605526c7d85bb3d980db079d5f31",
.@"ti-uniflash-macos-x86_64" = .{ // dummy
.url = "https://github.com/em-foundation/tools-pkg/releases/download/ti-uniflash-8.7.0/ti-uniflash-linux-x86_64.zip",
.hash = "12205de1eef9492a1cbee4461db6d9db803f14b32e5309ee4a036ac5a3d2a7640902",
.lazy = true,
},
.@"arm-binutils-macos-x86_64" = .{
.url = "https://github.com/em-foundation/tools-pkg/releases/download/arm-binutils-2.37/arm-binutils-macos-x86_64.tar.gz",
.hash = "1220e083de87e1aadeb0c0446c301d4214b2eebb2632389eb650556462c80ec9b71d",
.lazy = true,
},
.@"zls-em" = .{
.url = "https://github.com/em-foundation/zls-em/archive/refs/tags/v0.0.1.tar.gz",
.hash = "12201b80d7156dfba486ba255f282e67ee3e84f782b6816d93fcd68466f9193be267",
},
.@"vscode-zigem" = .{
.url = "https://github.com/em-foundation/vscode-zigem/releases/download/v0.0.2.202409131250/vscode-zigem.zip",
.hash = "1220291e6f88b53eb17dbd6c47ef8f45eb8bae0a7181e51b1a3158bbe414862c110b",
.@"zigem-zls" = .{
.url = "https://github.com/em-foundation/zigem-zls/archive/refs/tags/v0.0.3.tar.gz",
.hash = "122050bf95425972f281a2018b48fa4ff04f4e0b2fece8e1ea1be33a75317244f264",
},
},
}
162 changes: 162 additions & 0 deletions src/AstUtils.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
const std = @import("std");

const Fs = @import("Fs.zig");
const Heap = @import("Heap.zig");

const Ast = std.zig.Ast;

pub const NodeIter = struct {
ast: *const Ast,
root_decls: []const Ast.Node.Index,
root_idx: usize,
loc: std.ArrayList(NodeLoc),

const NodeLoc = struct {
idx: Ast.Node.Index,
// 0 self, 1..n, n
// node.children.len + 1
last_step: u32,
};

const WalkDir = enum {
down,
up,
};

const Output = struct {
idx: Ast.Node.Index,
direction: WalkDir,
};

pub fn init(ast: *const Ast) NodeIter {
return .{
.ast = ast,
.root_decls = ast.rootDecls(),
.root_idx = 0,
.loc = std.ArrayList(NodeLoc).init(Heap.get()),
};
}

pub fn deinit(self: *NodeIter) void {
self.loc.deinit();
}

fn append(self: *NodeIter, idx: Ast.Node.Index) !Output {
try self.loc.append(.{
.idx = idx,
.last_step = 0,
});

return .{
.idx = idx,
.direction = WalkDir.down,
};
}

// NOTE: When calling this externally on WalkDir.up, this will pop the
// parent of the node that was returned. This should probably only be
// called on WalkDir.down
pub fn pop(self: *NodeIter) Output {
const loc = self.loc.pop();
return .{
.idx = loc.idx,
.direction = WalkDir.up,
};
}

fn resolveChildNodeId(self: *NodeIter, node_idx: Ast.Node.Index, num_children_walked: u32) ?Ast.Node.Index {
const node = self.ast.nodes.get(node_idx);
switch (node.tag) {
.simple_var_decl,
.fn_decl,
.fn_proto_multi,
.fn_proto_simple,
.builtin_call_two,
.number_literal,
.string_literal,
.container_decl_two,
.container_field_init,
.block_two_semicolon,
.identifier,
=> {
switch (num_children_walked) {
0 => return node.data.lhs,
1 => return node.data.rhs,
else => return null,
}
},
.container_decl => {
const idx = node.data.lhs + num_children_walked;
if (idx >= node.data.rhs) {
return null;
}
return self.ast.extra_data[idx];
},
else => {
std.log.err("Unhandled tag: {any}", .{node.tag});
return null;
},
}
}

pub fn next(self: *NodeIter) !?Output {
while (true) {
if (self.loc.items.len == 0) {
if (self.root_idx >= self.root_decls.len) {
return null;
}

defer self.root_idx += 1;
return try self.append(self.root_decls[self.root_idx]);
}

const loc = &self.loc.items[self.loc.items.len - 1];

while (self.resolveChildNodeId(loc.idx, loc.last_step)) |node_idx| {
defer loc.last_step += 1;
if (node_idx == 0) {
continue;
}
return try self.append(node_idx);
}

return self.pop();
}
}
};

pub fn parse(path: []const u8) !Ast {
const norm = try Fs.normalize(path);
const source = Fs.readFileZ(norm);
const ast = try Ast.parse(Heap.get(), source, .zig);
return ast;
}

pub fn printTree(ast: Ast) void {
std.debug.print(
\\printTree:
\\nodes tag lhs rhs ln col tok
\\-----------------------------------------------------------------------------
\\
, .{});
for (ast.nodes.items(.tag), ast.nodes.items(.data), ast.nodes.items(.main_token), 0..) |tag, data, main_token, i| {
const loc = ast.tokenLocation(0, main_token);
std.debug.print(
" {d:<3} {s:<30} {d:<11} {d:<11} {d:<4} {d:<5} {d:<5} {s}\n",
.{ i, @tagName(tag), data.lhs, data.rhs, loc.line + 1, loc.column + 1, main_token, ast.tokenSlice(main_token) },
);
}

std.debug.print(
\\
\\tokens tag start
\\----------------------------------
\\
, .{});
for (ast.tokens.items(.tag), ast.tokens.items(.start), 0..) |tag, start, i| {
std.debug.print(
" {d:<3} {s:<20} {d:<}\n",
.{ i, @tagName(tag), start },
);
}
}
12 changes: 7 additions & 5 deletions src/Fs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const fs = std.fs;

const Heap = @import("./Heap.zig");

const MAX_BYTES = 100_000;

pub fn basename(path: []const u8) []const u8 {
return fs.path.basename(path);
}
Expand Down Expand Up @@ -46,31 +48,31 @@ pub fn normalize(path: []const u8) ![]const u8 {
}

pub fn openDir(path: []const u8) fs.Dir {
const dir = fs.openDirAbsolute(path, .{ .iterate = true }) catch fatal("Path.openDir: {s}", .{path});
const dir = fs.openDirAbsolute(path, .{ .iterate = true }) catch fatal("Fs.openDir: {s}", .{path});
return dir;
}

pub fn openFile(path: []const u8) fs.File {
const file = fs.openFileAbsolute(path, .{ .mode = .read_only }) catch fatal("Path.openFile: {s}", .{path});
const file = fs.openFileAbsolute(path, .{ .mode = .read_only }) catch fatal("Fs.openFile: {s}", .{path});
return file;
}

pub fn readFile(path: []const u8) []const u8 {
const file = openFile(path);
defer file.close();
const buf = file.readToEndAlloc(Heap.get(), 1000) catch fatal("Path.readFile: {s}", .{path});
const buf = file.readToEndAlloc(Heap.get(), MAX_BYTES) catch fatal("Fs.readFile: {s}", .{path});
return buf;
}

pub fn readFileZ(path: []const u8) [:0]const u8 {
const file = openFile(path);
defer file.close();
const buf = file.readToEndAllocOptions(Heap.get(), 1000, null, @alignOf(u8), 0) catch fatal("Path.readFile", .{});
const buf = file.readToEndAllocOptions(Heap.get(), MAX_BYTES, null, @alignOf(u8), 0) catch fatal("Fs.readFile", .{});
return buf;
}

pub fn slashify(path: []const u8) []const u8 {
const dupe = Heap.get().dupe(u8, path) catch fatal("Path.slashify: {s}", .{path});
const dupe = Heap.get().dupe(u8, path) catch fatal("Fs.slashify: {s}", .{path});
std.mem.replaceScalar(u8, dupe, '\\', '/');
return dupe;
}
Loading