Skip to content

Commit 2674842

Browse files
committed
initial Release
1 parent 11662b2 commit 2674842

21 files changed

+530
-7
lines changed

.devcontainer/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM wokwi/builder-clang-wasm
2+
3+
USER root
4+
RUN apk add gcompat libc6-compat
5+
6+
# Install arduino-cli:
7+
RUN wget -O /tmp/cli.tar.gz \
8+
https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_64bit.tar.gz && \
9+
tar -C /usr/local/bin -zxvf /tmp/cli.tar.gz && \
10+
rm /tmp/cli.tar.gz
11+
RUN arduino-cli core update-index && arduino-cli core install arduino:avr

.devcontainer/devcontainer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Wokwi-chips clang ",
3+
"dockerFile": "Dockerfile",
4+
"customizations": {
5+
"vscode": {
6+
"extensions": [
7+
"Wokwi.wokwi-vscode",
8+
"ms-vscode.makefile-tools"
9+
]
10+
}
11+
}
12+
}

.github/workflows/build.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Build Chip
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- name: Check out repository
13+
uses: actions/checkout@v3
14+
- name: Build chip
15+
uses: wokwi/wokwi-chip-clang-action@main
16+
with:
17+
sources: "src/main.c"
18+
- name: Copy chip.json
19+
run: sudo cp chip.json dist
20+
- name: 'Upload Artifacts'
21+
uses: actions/upload-artifact@v3
22+
with:
23+
name: chip
24+
path: |
25+
dist/chip.json
26+
dist/chip.wasm
27+
28+
# The release job only runs when you push a tag starting with "v", e.g. v1.0.0
29+
release:
30+
name: Release
31+
needs: build
32+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Download compiled chip
36+
uses: actions/download-artifact@v3
37+
with:
38+
name: chip
39+
path: chip
40+
- name: Create a zip archive
41+
run: cd chip && zip -9 ../chip.zip chip.*
42+
env:
43+
ZIP_VERSION: ${{ github.ref_name }}
44+
- name: Upload release
45+
uses: ncipollo/release-action@v1
46+
with:
47+
artifacts: chip.zip
48+
token: ${{ secrets.GITHUB_TOKEN }}
49+
generateReleaseNotes: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"wokwi.wokwi-vscode",
4+
"ms-vscode.makefile-tools"
5+
6+
]
7+
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"makefile.launchConfigurations": [
3+
{
4+
"cwd": "/workspaces/cd74act00/dist",
5+
"binaryPath": "/workspaces/cd74act00/dist/chip.wasm",
6+
"binaryArgs": []
7+
}
8+
]
9+
}

LICENSE

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2024 wokwi-custom-chips
3+
Copyright (c) 2022 Uri Shaked
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-FileCopyrightText: © 2022 Uri Shaked <uri@wokwi.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
SOURCES = src/main.c
5+
TARGET = dist/chip.wasm
6+
testFileName = logic
7+
testFolderName = test
8+
9+
.PHONY: all
10+
all: $(TARGET) dist/chip.json ; \
11+
12+
.PHONY: clean
13+
clean:
14+
rm -rf dist ; \
15+
rm -rf $(testFolderName) ; \
16+
17+
18+
dist:
19+
mkdir -p dist
20+
21+
$(TARGET): dist $(SOURCES) src/wokwi-api.h
22+
clang --target=wasm32-unknown-wasi --sysroot /opt/wasi-libc -nostartfiles -Wl,--import-memory -Wl,--export-table -Wl,--no-entry -Werror -o $(TARGET) $(SOURCES)
23+
24+
dist/chip.json: dist chip.json
25+
cp chip.json dist
26+
27+
28+
.PHONY: test
29+
test:
30+
mkdir -p $(testFolderName) ; \
31+
cd test && arduino-cli sketch new $(testFileName) && arduino-cli compile -e -b arduino:avr:uno $(testFileName) ; \

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
# sn74ahct1g32
1+
# SINGLE 2-INPUT POSITIVE-OR GATE Chip
2+
3+
Example of a basic custom chip for [Wokwi](https://wokwi.com/).
4+
5+
The actual source code for the chip lives in [src/main.c](src/main.c), and the pins are described in [chip.json](chip.json).
6+
7+
## Building
8+
9+
The easiest way to build the project is to open it inside a Visual Studio Code dev container, and then run the `make` command.
10+
11+
## Testing
12+
13+
You can test this project using the [Wokwi extension for VS Code](https://marketplace.visualstudio.com/items?itemName=wokwi.wokwi-vscode). Open the project with Visual Studio Code, press "F1" and select "Wokwi: Start Simulator".
14+
15+
If you want to make changes to the test project firmware, edit [test/logic/sketch.ino](test/logic/sketch.ino), and then run `make test` to rebuild the .hex file. You'll need the [arduino-cli](https://arduino.github.io/arduino-cli/latest/installation/), which is already installed in the dev container.
16+
17+
## License
18+
19+
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more details.

chip.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": 1,
3+
"license": "MIT",
4+
"docs": "https://github.com/algovoid/sn74ahct1g32/blob/main/docs/README.md",
5+
"name": "sn74ahct1g32",
6+
"author": "Algovoid",
7+
"pins": [
8+
"A",
9+
"B",
10+
"GND",
11+
"Y",
12+
"",
13+
"VCC"
14+
],
15+
"controls" :[]
16+
}

diagram.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": 1,
3+
"author": "Algovoid",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "wokwi-gnd", "id": "gnd1", "top": 172.8, "left": 172.2, "attrs": {} },
7+
{ "type": "wokwi-vcc", "id": "vcc1", "top": 58.36, "left": 278.4, "attrs": {} },
8+
{ "type": "chip-sn74ahct1g32", "id": "chip1", "top": 125.82, "left": 177.6, "attrs": {} },
9+
{
10+
"type": "wokwi-led",
11+
"id": "led1",
12+
"top": 111.6,
13+
"left": 311.4,
14+
"attrs": { "color": "red", "flip": "1" }
15+
},
16+
{ "type": "wokwi-slide-switch", "id": "sw1", "top": 100.4, "left": 108.7, "attrs": {} },
17+
{ "type": "wokwi-slide-switch", "id": "sw2", "top": 100.4, "left": 60.7, "attrs": {} }
18+
],
19+
"connections": [
20+
[ "chip1:VCC", "vcc1:VCC", "red", [ "h0" ] ],
21+
[ "gnd1:GND", "chip1:GND", "black", [ "v0" ] ],
22+
[ "led1:A", "chip1:Y", "green", [ "v0" ] ],
23+
[ "sw1:3", "chip1:A", "green", [ "v0" ] ],
24+
[ "sw2:3", "chip1:B", "green", [ "v0" ] ],
25+
[ "sw1:2", "vcc1:VCC", "green", [ "v19.2", "h-28.7", "v-67.2" ] ],
26+
[ "sw2:2", "vcc1:VCC", "green", [ "v19.2", "h-28.7", "v-76.8" ] ],
27+
[ "led1:C", "gnd1:GND", "green", [ "v0" ] ]
28+
],
29+
"dependencies": {}
30+
}

docs/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Wokwi sn74ahct1g32 Chip
2+
3+
This is a custom chip for [Wokwi](https://wokwi.com/). It implements the sn74ahct1g32 IC.
4+
5+
## Description
6+
7+
The sn74ahct1g32 contain single 2-input Positive-OR gates. Each gate performs the Boolean function
8+
of Y = (A + B) in positive logic.
9+
10+
## Truth Table
11+
12+
| INPUT A | INPUT B | OUTPUT |
13+
| ------- | ------- | ------- |
14+
| X | H | H |
15+
| H | X | H |
16+
| L | L | L |
17+
18+
## Pin names
19+
20+
| Name | Description |
21+
| ---- | ----------------- |
22+
| A | Input signal A |
23+
| B | Input signal B |
24+
| Y | Output signal |
25+
| GND | Ground |
26+
| VCC | Supply voltage |
27+
28+
29+
## Usage
30+
31+
To use this chip in your project, include it as a dependency in your `diagram.json` file:
32+
33+
```json
34+
"dependencies": {
35+
"chip-sn74ahct1g32": "github:wokwi-custom-chips/sn74ahct1g32@0.1.0"
36+
}
37+
```
38+
39+
Then, add the chip to your circuit by adding a `chip-sn74ahct1g32` item to the `parts` section of diagram.json:
40+
41+
```json
42+
"parts": {
43+
...,
44+
{ "type": "chip-sn74ahct1g32", "id": "chip1" }
45+
},
46+
```
47+
48+
For a complete example, see [The sn74ahct1g32 chip test project](https://wokwi.com/projects/398967433536335873).

src/main.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright 2024 Algovoid
3+
4+
#include "wokwi-api.h"
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
8+
typedef struct {
9+
pin_t pin_A;
10+
pin_t pin_B;
11+
pin_t pin_Y;
12+
13+
} chip_state_t;
14+
15+
static void set_output(chip_state_t *chip) {
16+
pin_write(chip->pin_Y, ( pin_read(chip->pin_A) | pin_read(chip->pin_B) ) );
17+
}
18+
19+
static void chip_pin_change(void *user_data, pin_t pin, uint32_t value) {
20+
chip_state_t *chip = (chip_state_t*)user_data;
21+
22+
set_output(chip);
23+
}
24+
25+
void chip_init() {
26+
printf("Initialize sn74ahct1g32 chip!\n");
27+
chip_state_t *chip = malloc(sizeof(chip_state_t));
28+
29+
chip->pin_A = pin_init("A", INPUT);
30+
chip->pin_B = pin_init("B", INPUT);
31+
chip->pin_Y = pin_init("Y", OUTPUT);
32+
33+
pin_write(chip->pin_A, LOW);
34+
pin_write(chip->pin_B, LOW);
35+
36+
const pin_watch_config_t config = {
37+
.edge = BOTH,
38+
.pin_change = chip_pin_change,
39+
.user_data = chip,
40+
};
41+
42+
pin_watch(chip->pin_A, &config);
43+
pin_watch(chip->pin_B, &config);
44+
45+
set_output(chip);
46+
}

0 commit comments

Comments
 (0)