Skip to content

Commit

Permalink
Release v1.0.0 (#2)
Browse files Browse the repository at this point in the history
* Get data from a CSV file
* CLI arguments
* README
* LICENSE
* Makefile
  • Loading branch information
raul-estevez authored Mar 22, 2021
1 parent c479792 commit 78b2d28
Show file tree
Hide file tree
Showing 10 changed files with 674 additions and 113 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
*.eep
*.eeprom

# swap files
*.swp

# Prerequisites
*.d

Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Raúl Estévez Gómez

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CC = gcc
IDIR = include
CFLAGS = -I$(IDIR)

SOURCES = src/main.c include/cliargs.c include/write.c
OBJECTS = main.o cliargs.o write.o

all : eepromIHEX

install :
mkdir /opt/eepromIHEX
cp eepromIHEX /opt/eepromIHEX
ln -f -s /opt/eepromIHEX/eepromIHEX /usr/local/bin

uninstall :
rm /usr/local/bin/eepromIHEX
rm -r /opt/eepromIHEX

eepromIHEX: $(OBJECTS)
$(CC) -o eepromIHEX $(CFLAGS) $^
mkdir obj
mv $(OBJECTS) obj

$(OBJECTS) : $(SOURCES)
$(CC) -c $^

.PHONY: clean

clean :
rm -r obj
93 changes: 88 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,94 @@
# eepromIHEX

Simple program that takes hex data you want to upload to a AVR microcontroller's eeprom and formats it into a Intel HEX.
Takes data from a CSV file and formats it to IHEX. This file is then ready to be uploaded into an avr eeprom using avrdude.

### TODO:
- [Installation](#installation)
- [Uninstall](#uninstall)
- [Usage](#usage)
- [Arguments](#arguments)
- [Examples](#examples)
- [CSV File](#csv-file)
- [Uploading](#uploading)

1. Add error handling
## Installation

2. Get hex data from a file
For installing, clone this repository to your computer, enter in the folder
eepromIHEX and type "make", then "make install" as root.

3. Add terminal interface
```bash
$ git clone https://github.com/SarKing/eepromIHEX
$ cd eepromIHEX
$ make
$ sudo make install
```

By default it's installed in /opt/eepromIHEX

#### Unistall

If you want to uninstall the application enter with your terminal in the folder
that you downloaded and type:

```bash
$ sudo make uninstall
```

## Usage

The basic use of this application just requires a CSV data file.

```bash
$ eepromIHEX data_file
```
And it will generate a file called "a.eep" that contains your data formatted into IHEX.

But you have more customization in the form of arguments.

#### Arguments

-output -o The name of the output file. DEFAULT: a.eep
--datalenght -d Maximum number of bytes per IHEX entry. DEFAULT: 32
--address -a The first address you want to write to. DEFAULT: 0
--verbose -v Prints verbose information
--help -h Prints help page
--version Displays the version message

#### Examples

Get data from data.csv, output IHEX formatted data to eeprom.eep
```bash
$ eepromIHEX -o eeprom.eep data.csv
```

Format IHEX with 8 byte data length instead of the default 32
```bash
$ eepromIHEX -d 8 data.csv
```

Start writing to eeprom address 0xFF instead of the default 0
```bash
$ eepromIHEX -a 255 data.csv
```

#### CSV File
The CSV file used as data source needs to be like this
```bash
00,FF,5D,6E44,62,86,72,D2,55,12,22,4F,FF,00,00,00,23,45,63,56
```
It causes no problem if two or more commas are together, like for example
```bash
00,FF,,6E44,62,86,,,55,12,22,,,,,00,23,45,63,56
```
But by no means data can be more than 1 byte long, so this is prohibited and will cause a malfunction
```bash
00,FFF,545D,6E44,62,86,72FF,D2,55,12,22,4F,FF,00,00,00,23,45,63,56
```

## Uploading

Once you have the .eep file, if you want to upload it to a AVR microcontroller using
avrdude you have to use this command.
```bash
$ avrdude -c "programmer" -p "mmcu" -U eeprom:w:"filename":i
```
Where "programmer" is the programmer you use (USBTiny, USBasp...), "mmcu" is the microcontroller you use (attiny85, atmega328...) and "filename" is the .eep file you just generated, the remaining leave it as is.
174 changes: 174 additions & 0 deletions include/cliargs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
Copyright 2021 Raúl Estévez Gómez
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Written by Raúl Estévez Gómez <estevezgomezraul@gmail.com>
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>

#include "cliargs.h"

// Define cli args flags
unsigned char verbose_flag;
unsigned char help_flag;
unsigned char file_flag;
unsigned char version_flag;
unsigned char dataLength_flag;
unsigned char address_flag;

// Define program variables
unsigned char MAX_DATA_LENGTH;
unsigned short INTIAL_ADDRESS;
char *VERSION ;
char *FILENAME;
char *IN_FILENAME;

// Long and short options
static struct option long_options[] = {
{"output", required_argument, NULL, 'O'},
{"o", required_argument, NULL, 'o'},
{"datalength", required_argument, NULL, 'D'},
{"d", required_argument, NULL, 'd'},
{"address", required_argument, NULL, 'A'},
{"a", required_argument, NULL, 'a'},
{"verbose", no_argument, NULL, 'V'},
{"v", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'H'},
{"h", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'G'},
{0,0,0,0}
};


int handleCLIargs(int argc, char *argv[]){
int option;
while((option = getopt_long_only(argc, argv, "o:O:d:D:a:A:vVhHG",
long_options, NULL)) != -1){
switch(option){
case 'O':
case 'o':
FILENAME = optarg;
file_flag = 1;
break;
case 'D':
case 'd':
dataLength_flag = 1;
MAX_DATA_LENGTH = atoi(optarg);
if(MAX_DATA_LENGTH > 0xFF){
printf("Error, value given to MAX_DATA_LENGTH too big (>0xFF)\n");
exit(EXIT_FAILURE);
}
break;
case 'A':
case 'a':
address_flag = 1;
INTIAL_ADDRESS = atoi(optarg);
if(INTIAL_ADDRESS > 0xFFFF){
printf("Error, value given to INTIAL_ADDRESS too big (>0xFFFF)\n");
exit(EXIT_FAILURE);
}
break;
case 'V':
case 'v':
verbose_flag = 1;
break;
case 'H':
case 'h':
helpHandler();
break;
case 'G':
versionHandler();
break;
case '?':
if(optopt == 'o'){
fprintf (stderr, "Option -%c requires an argument.\n",
optopt);
} else if(optopt == 'd'){
fprintf (stderr, "Option -%c requires an argument.\n",
optopt);
} else if(optopt == 'a'){
fprintf (stderr, "Option -%c requires an argument.\n",
optopt);
}
default:
abort ();
}
}

// Handle the mandatory ouput file argument
if(argv[optind] == NULL){
puts("Error, input file is a mandatory argument");
exit(EXIT_FAILURE);
} else {
IN_FILENAME = argv[optind];
}


// Default output filename
if(!file_flag){
FILENAME = "a.eep";
}
// Default data length
if(!dataLength_flag){
MAX_DATA_LENGTH = 0x20;
}
// Default initial address
if(!address_flag){
INTIAL_ADDRESS = 0;
}
return 0;
}

// The version page
int versionHandler(){
printf("eepromIHEX %s\n", VERSION);
printf("Copyright (C) 2021 Raúl Estévez Gómez\n");
printf("This is free software: you are free to change and redistribute it.\n");
printf("There is NO WARRANTY, to the extent permitted by law.\n");
exit(EXIT_SUCCESS);
}

int helpHandler(){
printf("eepromIHEX\t%s\n\n", VERSION);
printf("USAGE\n\teepromIHEX [options] filename \n");
printf("-----------------------------------------------------");
printf("\nDESCRIPTION\n");
printf("\tTakes data from a CSV file and formats it to IHEX. This file is then ready to be uploaded into an avr eeprom using avrdude.\n");
printf("-----------------------------------------------------");
printf("\nOPTIONS\n");
printf("\t--output\t-o\t\tThe name of the output file. DEFAULT: a.eep\n");
printf("\t--datalenght\t-d\t\tMaximum number of bytes per IHEX entry. DEFAULT: 32\n");
printf("\t--address\t-a\t\tThe first address you want to write to. DEFAULT: 0\n");
printf("\t--verbose\t-v\t\tPrints verbose messages\n");
printf("\t--help\t\t-h\t\tDisplays this information\n");
printf("\t--version\t \t\tDisplays the version message\n");
printf("-----------------------------------------------------");
printf("\nEXAMPLES\n");
printf("\tDefaults, read from data.eep\n");
printf("\t\teepromIHEX data.eep\n\n");
printf("\tOutput to eeprom.eep, datalenght of 8, start writting from address 0xFF\n");
printf("\t\teepromIHEX -o eeprom.eep -d 8 -a 255 data.eep\n");
printf("-----------------------------------------------------");
printf("\nCreated by: Raúl Estévez Gómez <estevezgomezraul@gmail.com>\n\n");
printf("If you encounter any bug, please refer to https://github.com/SarKing/eepromIHEX\n");
exit(EXIT_SUCCESS);
}
38 changes: 38 additions & 0 deletions include/cliargs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2021 Raúl Estévez Gómez
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Written by Raúl Estévez Gómez <estevezgomezraul@gmail.com>
*/
extern unsigned char verbose_flag;
extern unsigned char help_flag;
extern unsigned char file_flag;
extern unsigned char version_flag;
extern unsigned char dataLength_flag;
extern unsigned char address_flag;

extern unsigned char MAX_DATA_LENGTH;
extern unsigned short INTIAL_ADDRESS;
extern char *VERSION ;
extern char *FILENAME;
extern char *IN_FILENAME;

int handleCLIargs(int argc, char *argv[]);
int versionHandler(void);
int helpHandler(void);
Loading

0 comments on commit 78b2d28

Please sign in to comment.