Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
algovoid committed May 28, 2024
1 parent 960c3e5 commit 2e2a14d
Show file tree
Hide file tree
Showing 21 changed files with 599 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM wokwi/builder-clang-wasm

USER root
RUN apk add gcompat libc6-compat

# Install arduino-cli:
RUN wget -O /tmp/cli.tar.gz \
https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_64bit.tar.gz && \
tar -C /usr/local/bin -zxvf /tmp/cli.tar.gz && \
rm /tmp/cli.tar.gz
RUN arduino-cli core update-index && arduino-cli core install arduino:avr
11 changes: 11 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Wokwi-chips clang ",
"dockerFile": "Dockerfile",
"customizations": {
"vscode": {
"extensions": [
"Wokwi.wokwi-vscode"
]
}
}
}
49 changes: 49 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build Chip

on:
push:
workflow_dispatch:

jobs:
build:
name: Build
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Build chip
uses: wokwi/wokwi-chip-clang-action@main
with:
sources: "src/main.c"
- name: Copy chip.json
run: sudo cp chip.json dist
- name: 'Upload Artifacts'
uses: actions/upload-artifact@v3
with:
name: chip
path: |
dist/chip.json
dist/chip.wasm
# The release job only runs when you push a tag starting with "v", e.g. v1.0.0
release:
name: Release
needs: build
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Download compiled chip
uses: actions/download-artifact@v3
with:
name: chip
path: chip
- name: Create a zip archive
run: cd chip && zip -9 ../chip.zip chip.*
env:
ZIP_VERSION: ${{ github.ref_name }}
- name: Upload release
uses: ncipollo/release-action@v1
with:
artifacts: chip.zip
token: ${{ secrets.GITHUB_TOKEN }}
generateReleaseNotes: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"wokwi.wokwi-vscode",
"ms-vscode.makefile-tools",
"vsciot-vscode.vscode-arduino"
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"makefile.launchConfigurations": [
{
"cwd": "/workspaces/cd74act00/dist",
"binaryPath": "/workspaces/cd74act00/dist/chip.wasm",
"binaryArgs": []
}
]
}
12 changes: 6 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License
The MIT License (MIT)

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

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

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

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SPDX-FileCopyrightText: © 2022 Uri Shaked <uri@wokwi.com>
# SPDX-License-Identifier: MIT

SOURCES = src/main.c
TARGET = dist/chip.wasm
testFileName = logic
testFolderName = test

.PHONY: all
all: $(TARGET) dist/chip.json ; \

.PHONY: clean
clean:
rm -rf dist ; \
rm -rf $(testFolderName) ; \


dist:
mkdir -p dist

$(TARGET): dist $(SOURCES) src/wokwi-api.h
clang --target=wasm32-unknown-wasi --sysroot /opt/wasi-libc -nostartfiles -Wl,--import-memory -Wl,--export-table -Wl,--no-entry -Werror -o $(TARGET) $(SOURCES)

dist/chip.json: dist chip.json
cp chip.json dist


.PHONY: test
test:
mkdir -p $(testFolderName) ; \
cd test && arduino-cli sketch new $(testFileName) && arduino-cli compile -e -b arduino:avr:uno $(testFileName) ; \
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# cd54hct30
# 8-Input NAND Gate Chip

Example of a basic custom chip for [Wokwi](https://wokwi.com/).

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).

## Building

The easiest way to build the project is to open it inside a Visual Studio Code dev container, and then run the `make` command.

## Testing

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".

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.

## License

This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more details.
21 changes: 21 additions & 0 deletions chip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "cd54hct30",
"author": "Algovoid",
"pins": [
"A",
"B",
"C",
"D",
"E",
"F",
"GND",
"YINV",
"NC",
"NC",
"G",
"H",
"NC",
"VCC"
],
"controls": []
}
48 changes: 48 additions & 0 deletions diagram.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"version": 1,
"author": "Algovoid",
"editor": "wokwi",
"parts": [
{ "type": "chip-cd54hct30", "id": "chip1", "top": -18.18, "left": 196.8, "attrs": {} },
{
"type": "wokwi-dip-switch-8",
"id": "sw1",
"top": -3.7,
"left": 87.9,
"rotate": 90,
"attrs": {}
},
{ "type": "wokwi-vcc", "id": "vcc2", "top": -76.04, "left": 192, "attrs": {} },
{ "type": "wokwi-gnd", "id": "gnd1", "top": 134.4, "left": 191.4, "attrs": {} },
{
"type": "wokwi-led",
"id": "led1",
"top": 6,
"left": 359,
"attrs": { "color": "red", "flip": "1" }
}
],
"connections": [
[ "sw1:1a", "sw1:2a", "red", [ "h-38.4", "v9.6" ] ],
[ "sw1:2a", "sw1:3a", "red", [ "h-38.4", "v9.6" ] ],
[ "sw1:4a", "sw1:3a", "red", [ "h-38.4", "v-9.6" ] ],
[ "sw1:5a", "sw1:4a", "red", [ "h-38.4", "v-9.6" ] ],
[ "sw1:8a", "sw1:7a", "red", [ "h-38.4", "v-9.6" ] ],
[ "sw1:6a", "sw1:5a", "red", [ "h-38.4", "v-9.6" ] ],
[ "sw1:7a", "sw1:6a", "red", [ "h-38.4", "v-9.6" ] ],
[ "vcc2:VCC", "chip1:VCC", "red", [ "v0", "h144" ] ],
[ "vcc2:VCC", "sw1:1a", "red", [ "v0", "h-201.6" ] ],
[ "gnd1:GND", "chip1:GND", "black", [ "v0" ] ],
[ "chip1:YINV", "led1:A", "green", [ "v0" ] ],
[ "gnd1:GND", "led1:C", "black", [ "v0", "h182.4" ] ],
[ "sw1:1b", "chip1:A", "green", [ "h0" ] ],
[ "sw1:2b", "chip1:B", "green", [ "h0" ] ],
[ "chip1:C", "sw1:3b", "green", [ "h0" ] ],
[ "sw1:4b", "chip1:D", "green", [ "h0" ] ],
[ "chip1:E", "sw1:5b", "green", [ "h0" ] ],
[ "sw1:6b", "chip1:F", "green", [ "h0" ] ],
[ "sw1:7b", "chip1:G", "green", [ "h38.1", "v19.2", "h124.8", "v-48" ] ],
[ "chip1:H", "sw1:8b", "green", [ "h21.01", "v67.2", "h-144", "v-19.2" ] ]
],
"dependencies": {}
}
62 changes: 62 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Wokwi cd54hct30 Chip

This is a custom chip for [Wokwi](https://wokwi.com/). It implements the cd54hct30 IC.

## Description

The cd54hct30 contain single 2-input Positive-OR gates. Each gate performs the Boolean function
of Y = NOT(A . B . C . D . E . F . G . H) in positive logic.

## Truth Table
| INPUTS | |
| ----------------------------------------------------------------------------- | OUTPUT |
| INPUT A | INPUT B | INPUT C | INPUT D | INPUT E | INPUT F | INPUT G | INPUT H | |
|---------|---------|---------|---------|---------|---------|---------|---------|---------|
| L | X | X | X | X | X | X | X | H |
| X | L | X | X | X | X | X | X | H |
| X | X | L | X | X | X | X | X | H |
| X | X | X | L | X | X | X | X | H |
| X | X | X | X | L | X | X | X | H |
| X | X | X | X | X | L | X | X | H |
| X | X | X | X | X | X | L | X | H |
| X | X | X | X | X | X | X | L | H |
| H | H | H | H | H | H | H | H | L |


## Pin names

| Name | Description |
| ---- | ----------------- |
| A | Input signal A |
| B | Input signal B |
| C | Input signal C |
| D | Input signal D |
| E | Input signal E |
| F | Input signal F |
| G | Input signal G |
| H | Input signal H |
| Y | Output signal |
| GND | Ground |
| VCC | Supply voltage |


## Usage

To use this chip in your project, include it as a dependency in your `diagram.json` file:

```json
"dependencies": {
"chip-cd54hct30": "github:wokwi-custom-chips/cd54hct30@0.1.0"
}
```

Then, add the chip to your circuit by adding a `chip-cd54hct30` item to the `parts` section of diagram.json:

```json
"parts": {
...,
{ "type": "chip-cd54hct30", "id": "chip1" }
},
```

For a complete example, see [The cd54hct30 chip test project](https://wokwi.com/projects/398977400657873921).
79 changes: 79 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: MIT
// Copyright 2024 Algovoid

#include "wokwi-api.h"
#include <stdio.h>
#include <stdlib.h>

typedef struct {
pin_t pin_A;
pin_t pin_B;
pin_t pin_C;
pin_t pin_D;
pin_t pin_E;
pin_t pin_F;
pin_t pin_G;
pin_t pin_H;
pin_t pin_YINV;
} chip_state_t;

static void set_xor(chip_state_t *chip) {
pin_write(chip->pin_YINV, !( pin_read(chip->pin_A) && pin_read(chip->pin_B) && pin_read(chip->pin_C) && pin_read(chip->pin_D) && pin_read(chip->pin_E) && pin_read(chip->pin_F) && pin_read(chip->pin_G) && pin_read(chip->pin_H) ) );
}


static void chip_pin_change(void *user_data, pin_t pin, uint32_t value) {
chip_state_t *chip = (chip_state_t*)user_data;
set_xor(chip);
}

void chip_init() {
printf("Initialize cd54hct30 chip!\n");
chip_state_t *chip = malloc(sizeof(chip_state_t));

chip->pin_A = pin_init("A", INPUT);
chip->pin_B = pin_init("B", INPUT);

chip->pin_C = pin_init("C", INPUT);
chip->pin_D = pin_init("D", INPUT);

chip->pin_E = pin_init("E", INPUT);
chip->pin_F = pin_init("F", INPUT);

chip->pin_G = pin_init("G", INPUT);
chip->pin_H = pin_init("H", INPUT);
chip->pin_YINV = pin_init("YINV", OUTPUT);


pin_write(chip->pin_A, LOW);
pin_write(chip->pin_B, LOW);

pin_write(chip->pin_C, LOW);
pin_write(chip->pin_D, LOW);

pin_write(chip->pin_E, LOW);
pin_write(chip->pin_F, LOW);

pin_write(chip->pin_G, LOW);
pin_write(chip->pin_H, LOW);

const pin_watch_config_t config = {
.edge = BOTH,
.pin_change = chip_pin_change,
.user_data = chip,
};

pin_watch(chip->pin_A, &config);
pin_watch(chip->pin_B, &config);

pin_watch(chip->pin_C, &config);
pin_watch(chip->pin_D, &config);

pin_watch(chip->pin_E, &config);
pin_watch(chip->pin_F, &config);

pin_watch(chip->pin_G, &config);
pin_watch(chip->pin_H, &config);

set_xor(chip);
}
Loading

0 comments on commit 2e2a14d

Please sign in to comment.