Skip to content

Instantly share code, notes, and snippets.

View cfelton's full-sized avatar

Christopher Felton cfelton

View GitHub Profile
def rgb2ycbcr(rgb, ycbcr, clock, reset):
""" A RGB to YCbCr converter with reset.
Arguments:
rgb: red, green, blue interface
r: input 8-bit unsigned value in range of 0-255
g: input 8-bit unsigned value in range of 0-255
b: input 8-bit unsigned value in range of 0-255
@cfelton
cfelton / fpga578_snip1.c
Last active December 7, 2015 15:01
code snips for http://www.fpgarelated.com/showarticle/578.php, see link for description.
pix_t median(pix_t window[N])
{
pix_t t[N], z[N];
int ii, k, stage;
// copy locally
for(ii=0; ii<N; ii++) z[ii] = window[ii];
for(stage=1; stage<=N; stage++){
k = (stage%2==1) ? 0 : 1;
@cfelton
cfelton / fpga25_snip1.py
Last active May 11, 2017 06:38
Code snips for http://www.fpgarelated.com/showarticle/25.php, see the link for description
from myhdl import Signal, intbv, always_seq
def shift_reg(clock, reset, y):
shift = Signal(intbv(0)[len(y):])
mask = shift.max - 1
@always_seq(clock.posedge, reset=reset)
@cfelton
cfelton / tristate_ya.py
Created October 26, 2015 12:16
another tri-state example
from random import randint
from myhdl import *
def tristate(tri, tin, tout, en):
""" tristate driver
Ports:
tri: tri-state signal
tin: tri-state input
tout: the signal to drive the tri-state
@cfelton
cfelton / testbench_template.py
Last active June 2, 2016 12:28
A template for MyHDL testbenchds
import myhdl
from myhdl import Signal, intbv, instance, delay, StopSimulation
def testbench_template(args=None):
# any code to extract argument for what is desired to be tested
# instantiate all signals and interface
@cfelton
cfelton / array3.py
Created September 17, 2015 12:30
multidim array simulation only example
from myhdl import *
def array3(clock, reset, sel1, sel2, data_out):
""" simulation only """
# generate an array of constants
aoc = [[cc for cc in range((ii*3)+1, (ii*3)+4)] for ii in range(3)]
@always_seq(clock.posedge, reset=reset)
def rtlreg():
data_out.next = aoc[sel2][sel1]
@cfelton
cfelton / block_buffer.py
Last active August 29, 2015 14:27
a myhdl block buffer input and output example
import os
from random import randint
import myhdl
from myhdl import (Signal, ResetSignal, intbv, always_seq, always,
always_comb, delay, instance, traceSignals,
Simulation, StopSimulation)
@cfelton
cfelton / loi_converts.py
Last active August 29, 2015 14:27
list of interface conversion example
me = 0
class Interface:
def __init__(self):
self.x = Signal(bool(0))
self.y = Signal(bool(0))
def mod_with_interface(intf):
global me
xi = me
from __future__ import division
from __future__ import print_function
from random import shuffle, randint
import myhdl
from myhdl import (Signal, ResetSignal, intbv, always_seq, always,
delay, instance, traceSignals, Simulation)
class DataStream:
from myhdl import *
instance_count = 0
def RAM_byte_enable_user(wdata, waddr, we, rdata, clk):
""" RAM with byte enable writes
"""
global instance_count
assert len(wdata)/8 == len(we)