Skip to content

Instantly share code, notes, and snippets.

View buttercutter's full-sized avatar

Phung Cheng Fei buttercutter

View GitHub Profile
# ----------------------------------------------------------------------
# Copyright (c) 2016, The Regents of the University of California All
# rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
/*
* Filename: circ_buf.h
* Version: 1.0
* Description: A circular buffer using API from
* https://github.com/torvalds/linux/blob/master/Documentation/core-api/circular-buffers.rst
*/
#include <linux/circ_buf.h>
// power-of-2 sized buffers
/*
* Filename: circ_buf.c
* Version: 1.0
* Description: A circular buffer using API from
* https://github.com/torvalds/linux/blob/master/Documentation/core-api/circular-buffers.rst
*/
#include <linux/slab.h>
#include <linux/circ_buf.h>
#include "circ_buf.h"
@buttercutter
buttercutter / predict.py
Last active December 23, 2018 12:54
Python inference code for pruned SqueezeNet model
#Modified from https://github.com/amrit-das/Custom-Model-Training-PyTorch/blob/master/predict.py
import torch
import torch.nn as nn
#from torchvision.models import resnet18
from torchvision.transforms import transforms
import matplotlib.pyplot as plt
import numpy as np
from torch.autograd import Variable
import torch.functional as F
from PIL import Image
@buttercutter
buttercutter / Gm2.net
Last active December 2, 2018 06:15
Asymmetric differential transconductance amplifier for https://github.com/promach/frequency_trap/tree/development
* Asymmetric differential transconductance amplifier
.PARAM V_SUPPLY = 3.3
.PARAM V_BIAS = 1.8
*.PARAM INP_FREQ = '#INP_FREQ#'
*.PARAM INP_PERIOD = '1/INP_FREQ'
*.PARAM NO_PERIODS = '4'
*.PARAM TMEAS_START = '(NO_PERIODS-1)*INP_PERIOD'
*.PARAM TMEAS_STOP = '(NO_PERIODS)*INP_PERIOD'
.PARAM AC_POINTS = 10
@buttercutter
buttercutter / test_SPI.v
Last active December 5, 2018 01:32
SPI flash controller for Winbond W25Q32 flash
module test_SPI(clk, rst, serial_in, serial_out, o_busy_n, rx_error_n, MISO, MOSI);
parameter MOSI_DATA_BITWIDTH = 8 + 24 + 256*8; // to accomodate the maximum bit length for page_program(02h)
parameter MISO_DATA_BITWIDTH = 8;
localparam UART_LENGTH = 8; // 8N1 uart system
localparam NUM_OF_MUX_BIT = 1;
// hex ASCII code
localparam START_CHARACTER = 'h7F; // del character
@buttercutter
buttercutter / SPI.v
Last active November 13, 2018 01:21
SPI flash controller for Winbond W25Q32 flash
module SPI(clk, reset, data_valid, data_MOSI, data_ready, data_MISO, MISO, MOSI, clk_flash, CS_flash);
parameter MOSI_DATA_BITWIDTH = 8 + 24 + 256*8; // for page_program(02h)
parameter MISO_DATA_BITWIDTH = 8;
localparam INSTRUCTION_READ_DATA = 3; // Read Data (03h) instruction
input clk, reset;
input data_valid;
@buttercutter
buttercutter / stap_riffa.log
Created October 15, 2018 12:00
systemtap log for riffa module not found
phung@UbuntuHW15:~$ sudo stap -vvv linetimes.stp 'module("/lib/modules/4.18.6-041806-generic/kernel/drivers/riffa/riffa.ko")' push_circ_queue | gist-paste
Created temporary directory "/tmp/stap8yjk95"
Session arch: x86_64 release: 4.18.6-041806-generic
Parsed kernel "/lib/modules/4.18.6-041806-generic/build/.config", containing 7603 tuples
Parsed kernel "/lib/modules/4.18.6-041806-generic/build/Module.symvers", containing 10232 vmlinux exports
Kernel symbol table /lib/modules/4.18.6-041806-generic/build/System.map unavailable, (No such file or directory)
Parsed kernel "/boot/System.map-4.18.6-041806-generic", containing 53806 symbols
Processing tapset "/usr/local/share/systemtap/tapset/linux/context.stpm"
Processing tapset "/usr/local/share/systemtap/tapset/linux/inet.stpm"
Processing tapset "/usr/local/share/systemtap/tapset/linux/json.stpm"
[*]
[*] GTKWave Analyzer v3.3.86 (w)1999-2017 BSI
[*] Thu Aug 23 07:56:44 2018
[*]
[dumpfile] "./riffa_reorder_queue.vcd"
[dumpfile_mtime] "Thu Aug 2 04:32:15 2018"
[dumpfile_size] 705110
[savefile] "./riffa_reorder_queue.gtkw"
[timestart] 0
[size] 1920 1115
@buttercutter
buttercutter / dmesg
Last active September 13, 2018 04:33
RIFFA dmesg for unexpected failed IRQ interrupt binding from USB3 controller hanging off PCI bus
[ 0.000000] Linux version 4.18.6-041806-generic (kernel@kathleen) (gcc version 8.2.0 (Ubuntu 8.2.0-4ubuntu1)) #201809050847 SMP Wed Sep 5 08:49:36 UTC 2018
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.18.6-041806-generic root=UUID=904591e2-36d9-4436-b533-fbdd0d6abc90 ro quiet splash debug loglevel=7 vt.handoff=1
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Centaur CentaurHauls
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256