Skip to content

Commit

Permalink
Essential functionality: read / write / initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
vdudouyt committed Jan 31, 2014
1 parent 3441602 commit 82862ab
Show file tree
Hide file tree
Showing 11 changed files with 237,085 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Makefile
@@ -0,0 +1,19 @@
SOURCES=$(wildcard *.c)
OBJECTS=$(SOURCES:.c=.o)
PROGNAME=minipro
TESTS=$(wildcard tests/test_*.c);
OBJCOPY=objcopy

CFLAGS = `pkg-config --cflags libusb-1.0` -g -O0
LIBS = `pkg-config --libs libusb-1.0`

all: $(OBJECTS)
$(CC) $(LIBS) $(OBJECTS) -o $(PROGNAME)

clean:
rm -f $(OBJECTS) $(PROGNAME)

test: $(TESTS:.c=.stamp)
$(CC) -c -I. $< $(CFLAGS) -DTEST -o $(<:.c=.o)
$(OBJCOPY) --weaken $(<:.c=.o)
$(CC) $(LIBS) $(OBJECTS) $(<:.c=.o) -o $(<:.c=)
18 changes: 18 additions & 0 deletions byte_utils.c
@@ -0,0 +1,18 @@
#include "byte_utils.h"

void format_int(unsigned char *out, unsigned int in, unsigned char length, unsigned char endianess) {
int i, idx;
for(i = 0; i < length; i++) {
idx = endianess == MP_LITTLE_ENDIAN ? i : length - 1 - i;
out[i] = (in & 0xFF << idx*8) >> idx*8;
}
}

int load_int(unsigned char *buf, unsigned char length, unsigned char endianess) {
int i, idx, result = 0;
for(i = 0; i < length; i++) {
idx = endianess == MP_LITTLE_ENDIAN ? i : length - 1 - i;
result |= (buf[i] << idx*8);
}
return(result);
}
10 changes: 10 additions & 0 deletions byte_utils.h
@@ -0,0 +1,10 @@
#ifndef __BYTE_UTILS_H
#define __BYTE_UTILS_H

#define MP_LITTLE_ENDIAN 0
#define MP_BIG_ENDIAN 1

void format_int(unsigned char *out, unsigned int in, unsigned char length, unsigned char endianess);
int load_int(unsigned char *buf, unsigned char length, unsigned char endianess);

#endif
15 changes: 15 additions & 0 deletions database.c
@@ -0,0 +1,15 @@
#include "database.h"
#include <string.h>

device_t devices[] = {
#include "devices.h"
{ .name = NULL },
};

device_t *get_device_by_name(const char *name) {
device_t *device;
for(device = &(devices[0]); device[0].name; device = &(device[1])) {
if(!strcmp(name, device->name))
return(device);
}
}
31 changes: 31 additions & 0 deletions database.h
@@ -0,0 +1,31 @@
#ifndef __DATABASE_H
#define __DATABASE_H

typedef struct device {
const char *name;
unsigned int protocol_id;
unsigned int variant;
unsigned int addressing_mode;
unsigned int read_buffer_size;
unsigned int write_buffer_size;
enum { BYTE, WORD, BIT } word_size;

unsigned int code_memory_size; // Presenting for every device
unsigned int data_memory_size; // Usually MCU's EEPROM
unsigned int data_memory2_size;
unsigned int chip_id; // A vendor-specific chip ID (i.e. 0x1E9502 for ATMEGA48)
unsigned int chip_id_bytes_count : 3;
unsigned int opts1;
unsigned int opts2;
unsigned int opts3;
unsigned int opts4;
unsigned int package_details; // pins count or image ID for some devices
unsigned int write_unlock;
void *config;
} device_t;

extern device_t devices[];

device_t *get_device_by_name(const char *name);

#endif

0 comments on commit 82862ab

Please sign in to comment.