Skip to content

Instantly share code, notes, and snippets.

View vankxr's full-sized avatar
🏠
Working from home

João Silva vankxr

🏠
Working from home
View GitHub Profile
@vankxr
vankxr / SiLabs AAP
Created March 10, 2019 16:44
Notes on ARMv7 Debug access ports
// An AP has max 64 words
// Bits 3:2 (the X in 0b????XX00) of the address are sent within the command, i.e. "SWDReadAP 3" = read from 0b????1100
// Bits 7:4 (the X in 0bXXXX??00) of the address are set in the SELECT register, i.e. "SWDWriteDP 2 0x??0000F?" = read from 0b1111??00
// The AHB-AP is on APSEL = 0
// The AAP is on APSEL = 255
// APSEL is the MSB of the SELECT register, i.e. "SWDWriteDP 2 0xFF0000?0" = set APSEL to 255
// Read the AP IDR
@vankxr
vankxr / setup_updated_sdk.sh
Last active February 25, 2020 17:28
esp-open-sdk updater
#!/bin/sh
xtensa-lx106-elf-objcopy -W Cache_Read_Enable_New sdk/lib/libmain.a sdk/lib/libmain2.a
rm sdk/lib/libmain.a
mv sdk/lib/libmain2.a sdk/lib/libmain.a
cp sdk/lib/*.a xtensa-lx106-elf/xtensa-lx106-elf/sysroot/usr/lib/
rm xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/4.8.5/libgcc.a
cp sdk/lib/libgcc.a xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/4.8.5/
@vankxr
vankxr / main.c
Created August 28, 2019 02:13
Color alpha blending
#include <stdio.h>
#include <stdint.h>
uint32_t blend(uint32_t base, uint32_t new, float alpha)
{
uint8_t base_r = (base >> 16) & 0xFF;
uint8_t base_g = (base >> 8) & 0xFF;
uint8_t base_b = (base >> 0) & 0xFF;
uint8_t new_r = (new >> 16) & 0xFF;
@vankxr
vankxr / install.sh
Last active February 25, 2020 22:39
Install CMSIS Device packs
#!/bin/sh
wget http://packs.download.atmel.com/Atmel.SAME70_DFP.2.4.166.atpack
wget http://packs.download.atmel.com/Atmel.SAMS70_DFP.2.4.134.atpack
wget http://packs.download.atmel.com/Atmel.SAMV70_DFP.2.4.130.atpack
wget http://packs.download.atmel.com/Atmel.SAMV71_DFP.2.4.182.atpack
wget https://www.silabs.com/documents/public/cmsis-packs/SiliconLabs.GeckoPlatform_EFM32JG1B_DFP.2.7.0.pack
wget https://www.silabs.com/documents/public/cmsis-packs/SiliconLabs.GeckoPlatform_EFM32PG1B_DFP.2.7.0.pack
wget https://www.silabs.com/documents/public/cmsis-packs/SiliconLabs.GeckoPlatform_EFM32GG11B_DFP.2.7.0.pack
wget https://www.silabs.com/documents/public/cmsis-packs/SiliconLabs.GeckoPlatform_EFM32GG12B_DFP.2.7.0.pack
@vankxr
vankxr / main.js
Last active January 5, 2022 12:08
Read HP Common slot PSUs via I2C from NodeJS
const I2C = require("i2c-bus");
function psu_calc_checksum(addr, buf)
{
let cs = (addr << 1);
for(let i = 0; i < buf.length - 1; i++)
cs += buf.readUInt8(i);
buf.writeUInt8(((0xFF - cs) + 1) & 0xFF, buf.length - 1);
@vankxr
vankxr / qo-100-wb-pwr-calc.js
Created December 31, 2020 19:33
QO-100 Wideband TPX link budget calculator
const c = 299792458; // Speed of light
const f = 2400e6; // Hz
const lambda = c / f;
////////
const ref_dish_diameter = 1.2; // meters
const ref_dish_efficiency = 0.5;
const ref_dish_gain_db = 10 * Math.log10(ref_dish_efficiency * Math.pow((Math.PI * ref_dish_diameter) / lambda, 2));
const ref_symbol_rate = 250e3; // symbols per second
const ref_rx_ss = 8 - 8; // dBb (dB w.r.t the beacon) as seen by the tpx (0 dBb = 8 dB MER)
const ref_pwr_w = 30; // watts
@vankxr
vankxr / hx_soc_gpio_pull_cfg.c
Last active February 4, 2021 16:27
CLI tool to change the pull-up/down status on an H2+ or H3 SoC, since this functionality is not provided by sysfs gpio
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
// gcc -o hx_soc_gpio_pull_cfg hx_soc_gpio_pull_cfg.c
// Usage: hx_soc_gpio_pull_cfg <pin> <OFF|UP|DOWN>
@vankxr
vankxr / dvb-s2-bw-calc.js
Created February 4, 2021 16:29
DVB-S2 bandwidth calculator
const k = Math.log2(16); // bits/symbol
const sr = 192e3; // Symbol rate
const fec = 4/5; // FEC rate
const ff = 64800; // FEC Frame size (16200 or 64800)
const gse = 3/4; // GSE rate
const rof = 0.20; // RRC roll-off factor
const pilots = false; // Pilots enabled
////////
function isclose(a, b, rel_tol=1e-02, abs_tol=0.0)
{
@vankxr
vankxr / ncpus.c
Created January 9, 2022 00:10
C get number of CPU threads
int ncpus(void) {
FILE *cmd = popen("grep '^processor' /proc/cpuinfo | wc -l", "r");
if (cmd == NULL)
return -1;
unsigned nprocs;
size_t n;
char buff[8];