Skip to content

Instantly share code, notes, and snippets.

@heiher
heiher / epoll.c
Created August 18, 2019 02:02
Why the edge-triggered mode doesn't work for epoll file descriptor itself?
#include <stdio.h>
#include <unistd.h>
#include <sys/epoll.h>
int
main (int argc, char *argv[])
{
int efd[2];
struct epoll_event e;
@heiher
heiher / wdtd.c
Last active March 6, 2020 04:28
Loongson 7A Watchdog Timer Userspace Daemon
#define _GNU_SOURCE
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/types.h>
@heiher
heiher / ecryptfs-mount
Created March 9, 2020 15:18
eCryptfs mounting helper
#!/bin/bash
if [ "$#" -lt 2 ]; then
SRC=$1
DST=$1
else
SRC=$1
DST=$2
fi
@heiher
heiher / mg90s.c
Last active November 16, 2020 03:09
外置硬盘盒电源开关伺服电机控制程序(树莓派init单进程版)
/*
============================================================================
Name : mg90s.c
Author : Heiher <r@hev.cc>
Copyright : Copyright (c) 2020 everyone.
Description : MG90S Motor Controller
============================================================================
*/
#include <poll.h>
@heiher
heiher / switch
Created March 31, 2020 13:40
NAS外置硬盘盒开关程序(NanoPi侧)
#!/bin/bash
if [ ! -e /sys/class/gpio/gpio33 ]; then
echo 33 > /sys/class/gpio/export
sleep 0.1
echo out > /sys/class/gpio/gpio33/direction
fi
if [ ! -e /sys/class/gpio/gpio35 ]; then
echo 35 > /sys/class/gpio/export
@heiher
heiher / sg90.c
Created April 1, 2020 05:39
外置硬盘盒电源开关伺服电机控制程序(NanoPi M4版)
/*
============================================================================
Name : sg90.c
Author : Heiher <r@hev.cc>
Copyright : Copyright (c) 2020 everyone.
Description : SG90 Motor Controller
============================================================================
*/
#include <poll.h>
@heiher
heiher / mg90s-bootauto.c
Created April 1, 2020 11:26
外置硬盘盒电源开关伺服电机控制程序(树莓派开机自动触发,配合继电器)
#include <poll.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
@heiher
heiher / read-read-reorder.c
Last active August 3, 2021 13:28
Test for reads from the same address out of order
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
static volatile unsigned long s;
static void *
write_handler (void *data)
{
for (;;) {
@heiher
heiher / read-read-reorder.c
Last active August 3, 2021 13:58
Test for reads from the same address out of order (5000)
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
static volatile unsigned long s;
static void *
write_handler (void *data)
{
for (;;) {
@heiher
heiher / loongarch64-li-test-gen.c
Last active August 27, 2021 17:17
LoongArch64 load immediate test generator
/*
* li-test-gen.c
* wangrui <wangrui@loongson.cn>
*
* gcc -o li-test-gen li-test-gen.c
* ./li-test-gen
* gcc -o li-test li-test.c li-test.S
* ./li-test
*/