Skip to content

Instantly share code, notes, and snippets.

View ra1u's full-sized avatar
💻
Focusing

Luka Rahne ra1u

💻
Focusing
View GitHub Profile
resize2 :: (KnownNat n, KnownNat m) => Signed n -> Signed m
resize2 s
| n <= m = 0
| otherwise = 1
// Automatically generated Verilog-2001
module Tutorial_mealyzm_1(eta_i1
,// clock
system1000
,// asynchronous reset: active low
system1000_rstn
,bodyVar_o);
input [32:0] eta_i1;
input system1000;
input system1000_rstn;
module Tutorial where
import CLaSH.Prelude
type W32 = Signed 32
topEntity :: Signal (Maybe W32) -> Signal W32
topEntity sig = mealy mf 0 sig
where
mf :: W32 -> Maybe W32 -> (W32,W32)
mf s Nothing = (s,s)
module MovingAvg where
import CLaSH.Prelude
windowN :: (Default a,KnownNat n) => SNat (n+1) -> Signal a -> Vec (n + 1) (Signal a)
windowN size = window
movingAvarageNaive size signal = fold (+) <$> bundle (windowN size signal)
topEntity :: Signal (Signed 9) -> Signal (Signed 9)
topEntity = movingAvarageNaive d5
@ra1u
ra1u / pid.hs
Created February 8, 2016 15:15
module Pid where
import CLaSH.Prelude as C
{-# ANN topEntity
(defTop
{ t_name = "pid"
, t_inputs = ["initI","initD","kP","kI","kD","setvalue"]
, t_outputs = ["pidsignal"]
, t_extraIn = [ ("CLOCK", 1)]
, t_clocks = [ clockWizard "clkwiz50" "CLOCK[0]" "~ KEY[0]" ]
{-# LANGUAGE TemplateHaskell #-}
module Cordic where
import CLaSH.Prelude as C
-- one step cordic for first quadrant 1 and 4
cordicQ14 :: (NumSFixedC 2 s, NumSFixedC 2 r)
=> SFixed 2 s-- fixing angle (constant)
-> Int -- shift size
-> (SFixed 2 r,SFixed 2 r) -- (x,y) or cos,sin
arm-unknown-linux-gnueabi-ghc hw.hs -rtsopts -debug -v
Glasgow Haskell Compiler, Version 7.10.1, stage 1 booted by GHC version 7.8.4
Using binary package database: /usr/local/lib/arm-unknown-linux-gnueabi-ghc-7.10.1/package.conf.d/package.cache
Using binary package database: /home/ralu/.ghc/arm-linux-7.10.1/package.conf.d/package.cache
wired-in package ghc-prim mapped to ghc-prim-0.4.0.0-361e8e2c9cf389d2a3e7a0e22f6c7443
wired-in package integer-simple mapped to integer-simple-0.1.1.0-9bd007614b43388e2bb7b2146145b894
wired-in package base mapped to base-4.8.0.0-8d0e6769a75e6a598cebc9657285312b
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.10.0.0-5e6c60df81db6fb5f949b92c4196d6c2
wired-in package ghc not found.
./hw +RTS -M100k -Dg -v -RTS
created capset 0 of type 2
created capset 1 of type 3
cap 0: initialised
assigned cap 0 to capset 0
assigned cap 0 to capset 1
hw: maximum heap size (-M) is smaller than minimum alloc area size (-A)
allocated 1 megablock(s) at 0xb6b00000
----------------------------------------------------------
Gen Max Mut-list Blocks Large Live Slop
$ cabal --with-gcc=arm-linux-gnueabi-gcc-5 --with-ghc=arm-unknown-linux-gnueabi-ghc --with-ghc-pkg=arm-unknown-linux-gnueabi-ghc-pkg --with-ld=arm-linux-gnueabi-ld --with-strip=arm-linux-gnueabi-strip --reinstall -v3 install pipes
/usr/bin/alex --version
/home/ralu/.cabal/bin/c2hs --numeric-version
/usr/bin/arm-linux-gnueabi-gcc-5 -dumpversion
/usr/bin/happy --version
/usr/bin/hpc version
looking for tool hsc2hs near compiler in /usr/local/bin
/usr/bin/hsc2hs --version
/usr/local/bin/arm-unknown-linux-gnueabi-ghc -c /tmp/13362.c -o /tmp/13362.o
/usr/bin/arm-linux-gnueabi-ld -x -r /tmp/13362.o -o /tmp/13363.o
@ra1u
ra1u / timeThread.java
Created May 27, 2015 20:12
thread safe loop performance test
import java.lang.Runnable;
import java.lang.Thread;
import java.lang.InterruptedException;
import java.util.concurrent.atomic.AtomicLong;
class timeThread {
private
static AtomicLong running_ms =
new AtomicLong(0); // atomic is thread safe variable
private