Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Essential functionality: read / write / initialize
- Loading branch information
Showing
11 changed files
with
237,085 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.