Skip to content

Instantly share code, notes, and snippets.

@makestuff
Created November 29, 2015 17:54
Show Gist options
  • Save makestuff/981439b2263f6f558355 to your computer and use it in GitHub Desktop.
Save makestuff/981439b2263f6f558355 to your computer and use it in GitHub Desktop.
Accept a .bin file from the UMDKv2 logic analyzer, and create a blob of text that can be pasted into http://wavedrom.com/editor.html
#include <stdio.h>
#include <stdint.h>
int main(int argc, const char *argv[]) {
const size_t dataLen = 1024;
uint8_t buffer[dataLen];
size_t i;
int oldVal = -1;
int newVal;
uint8_t values[dataLen];
size_t index = 0;
if ( argc != 2 ) {
fprintf(stderr, "Synopsis: %s <la.bin>\n", argv[0]);
return 1;
}
FILE *f = fopen(argv[1], "rb");
fread(buffer, 1, dataLen, f);
fclose(f);
printf("{\n");
printf(" signal: [\n");
printf(" {name: '/OE', wave: '");
for ( i = 0; i < dataLen; i++ ) {
newVal = (buffer[i] & 0x80) >> 7;
if ( newVal != oldVal ) {
printf("%d", newVal);
oldVal = newVal;
} else {
printf(".");
}
}
printf("'},\n");
printf(" {name: '/LDSW', wave: '");
oldVal = -1;
for ( i = 0; i < dataLen; i++ ) {
newVal = (buffer[i] & 0x40) >> 6;
if ( newVal != oldVal ) {
printf("%d", newVal);
oldVal = newVal;
} else {
printf(".");
}
}
printf("'},\n");
printf(" {name: '/UDSW', wave: '");
oldVal = -1;
for ( i = 0; i < dataLen; i++ ) {
newVal = (buffer[i] & 0x20) >> 5;
if ( newVal != oldVal ) {
printf("%d", newVal);
oldVal = newVal;
} else {
printf(".");
}
}
printf("'},\n");
printf(" {name: 'A[5:1]', wave: '");
oldVal = -1;
for ( i = 0; i < dataLen; i++ ) {
newVal = buffer[i] & 0x1F;
if ( newVal != oldVal ) {
printf("2");
values[index++] = (uint8_t)newVal;
oldVal = newVal;
} else {
printf(".");
}
}
printf("', data: [");
printf("'%02X'", values[0]);
for ( i = 1; i < index; i++ ) {
printf(", '%02X'", 2*values[i]);
}
printf("]}\n");
printf(" ]\n");
//printf(" ],\n");
//printf(" \"config\": {\n");
//printf(" \"hscale\": 2\n");
//printf(" }\n");
printf("}\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment