Skip to content

Instantly share code, notes, and snippets.

View bradford-hamilton's full-sized avatar

Bradford Lamson-Scribner bradford-hamilton

View GitHub Profile
@bradford-hamilton
bradford-hamilton / Makefile
Last active April 25, 2023 00:50
ATtiny85 Makefile for part 1
# Compile for attiny85 - optimize for size
compile:
avr-gcc -Wall -Os -mmcu=attiny85 src/main.c
# Get the assembly
assembly:
avr-gcc -S -Os -mmcu=attiny85 src/main.c -o assembly.asm
# Dump hex from out file
dump: compile
@bradford-hamilton
bradford-hamilton / main.c
Last active April 24, 2023 22:31
ATtiny85 - enabling global interrupts with the SREG register instead of assembly
...
// Add the SREG register
#define SREG REG(0x3F)
...
int main()
{
...
// Write 1 to bit 7 (I-bit) for Global Interrupt Enable
SREG |= BV_MASK(7);
@bradford-hamilton
bradford-hamilton / main.c
Last active April 24, 2023 23:42
ATtiny85 - final code example for Part 1 of blog
// When addressing I/O Registers as data space using LD and ST
// instrucrutions, 0x20 must be added to these addresses.
#define OFFSET 0x20
// Macro helper for registers
#define REG(addr) *((volatile unsigned char*)(addr+OFFSET))
// Port B Data Direction Register
#define DDRB REG(0x17)
@bradford-hamilton
bradford-hamilton / main.c
Last active April 24, 2023 20:01
ATtiny85 - example of loop for toggling LED
while (1) {
for (unsigned int i = 0; i < 50000; i++) { PORTB |= (1 << 0); }
for (unsigned int i = 0; i < 50000; i++) { PORTB = 0x0; }
}
@bradford-hamilton
bradford-hamilton / main.c
Last active April 24, 2023 19:48
ATtiny85 - Initial LED on example for post
// Port B data direction register 0x17 (+ 0x20 for the special func register offset)
#define DDRB *((volatile unsigned char*)0x37)
// Port B data register 0x18 (+ 0x20 for the special func register offset)
#define PORTB *((volatile unsigned char*)0x38)
int main()
{
// Set data direction for Port B bit 0 (PB0 - pin 5)
DDRB |= (1 << 0);
@bradford-hamilton
bradford-hamilton / main.c
Last active April 24, 2023 19:33
ATtiny85 - Initial LED on
int main()
{
// Set data direction for Port B bit 0 (PB0 - pin 5) to 1 for output
DDRB |= (1 << 0);
// Set data for Port B bit 0 (PB0 - pin 5) to 1 to turn on LED
PORTB |= (1 << 0);
while (1) {}
}
@bradford-hamilton
bradford-hamilton / main.c
Last active April 24, 2023 19:35
ATtiny85 - Initial DDRB & PORTB definition before including the I/O memory offset for SFRs
// Port B data direction register
#define DDRB *((volatile unsigned char*)0x17)
// Port B data register
#define PORTB *((volatile unsigned char*)0x18)
int main() {}
package cache
import (
"container/list"
)
type lru struct {
cap int // max number of items the cache can hold before needing to evict.
ll *list.List // a doubly linked list.
items map[interface{}]*list.Element // map of keys -> doubly linked list elements
package cache
import (
"container/list"
"errors"
"sync"
)
// ErrMinCacheSize is returned when a caller tries to create a new LRU cache with a capacity of less than one
var ErrMinCacheSize = errors.New("please provide an LRU cache capacity greater than or equal to 1")
package dora
import (
"errors"
"fmt"
"strconv"
"github.com/bradford-hamilton/dora/pkg/ast"
)