Skip to content

Instantly share code, notes, and snippets.

@heiher
heiher / read-read-reorder.c
Last active Jan 25, 2021
read/read reorder at same address test
View read-read-reorder.c
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
static volatile unsigned long s;
static void *
write_handler (void *data)
{
for (;;) {
@heiher
heiher / mg90s-bootauto.c
Created Apr 1, 2020
外置硬盘盒电源开关伺服电机控制程序(树莓派开机自动触发,配合继电器)
View mg90s-bootauto.c
#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 / sg90.c
Created Apr 1, 2020
外置硬盘盒电源开关伺服电机控制程序(NanoPi M4版)
View sg90.c
/*
============================================================================
Name : sg90.c
Author : Heiher <r@hev.cc>
Copyright : Copyright (c) 2020 everyone.
Description : SG90 Motor Controller
============================================================================
*/
#include <poll.h>
@heiher
heiher / switch
Created Mar 31, 2020
NAS外置硬盘盒开关程序(NanoPi侧)
View switch
#!/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 / mg90s.c
Last active Nov 16, 2020
外置硬盘盒电源开关伺服电机控制程序(树莓派init单进程版)
View mg90s.c
/*
============================================================================
Name : mg90s.c
Author : Heiher <r@hev.cc>
Copyright : Copyright (c) 2020 everyone.
Description : MG90S Motor Controller
============================================================================
*/
#include <poll.h>
@heiher
heiher / ecryptfs-mount
Created Mar 9, 2020
eCryptfs mounting helper
View ecryptfs-mount
#!/bin/bash
if [ "$#" -lt 2 ]; then
SRC=$1
DST=$1
else
SRC=$1
DST=$2
fi
@heiher
heiher / wdtd.c
Last active Mar 6, 2020
Loongson 7A Watchdog Timer Userspace Daemon
View wdtd.c
#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 / epoll.c
Created Aug 18, 2019
Why the edge-triggered mode doesn't work for epoll file descriptor itself?
View epoll.c
#include <stdio.h>
#include <unistd.h>
#include <sys/epoll.h>
int
main (int argc, char *argv[])
{
int efd[2];
struct epoll_event e;