Skip to content

Commit

Permalink
Added format reader interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
Milo-D committed Aug 12, 2021
1 parent 0df6607 commit b722f96
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

# Unreleased

- added format reader interface (reader/reader.c)
- reader for different file formats can be now added to reader/format/
- for example reader/format/ihex.c to read the intel hex format

# v.0.8.12 - 2021-08-10

- reduction of heap usage and overall memory usage
Expand Down
12 changes: 12 additions & 0 deletions engine/include/reader/fmt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* File Format Enumeration Header */

#ifndef VMCU_FMT_H
#define VMCU_FMT_H

typedef enum {

VMCU_FMT_IHEX

} VMCU_FMT;

#endif
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Intel Hex Reader Header */

#ifndef VMCU_IHEX_READER_H
#define VMCU_IHEX_READER_H
#ifndef VMCU_IHEX_H
#define VMCU_IHEX_H

// C Headers
#include <inttypes.h>
Expand Down
16 changes: 16 additions & 0 deletions engine/include/reader/reader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Format Reader Header */

#ifndef VMCU_READER_H
#define VMCU_READER_H

// C Headers
#include <inttypes.h>

// Project Headers
#include "engine/include/reader/fmt.h"

typedef struct vmcu_binary_buffer vmcu_binary_buffer_t;

extern vmcu_binary_buffer_t* vmcu_read_format(const VMCU_FMT fmt, const char *file, uint32_t *size);

#endif
4 changes: 2 additions & 2 deletions engine/src/decoder/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Project Headers (engine, readers)
#include "engine/include/reader/binary_buffer.h"
#include "engine/include/reader/ihex_reader.h"
#include "engine/include/reader/reader.h"

// Project Headers (engine utilities)
#include "engine/include/misc/bitmanip.h"
Expand Down Expand Up @@ -62,7 +62,7 @@ vmcu_instr_t* vmcu_decode_ihex(const char *hex_file, uint32_t *size, vmcu_model_
vmcu_instr_t *result;
vmcu_binary_buffer_t *bb;

if((bb = vmcu_read_ihex(hex_file, size)) == NULL)
if((bb = vmcu_read_format(VMCU_FMT_IHEX, hex_file, size)) == NULL)
return NULL;

if((result = decode_binary_buffer(bb, size)) == NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
#include <stdbool.h>

// Project Headers (engine, readers)
#include "engine/include/reader/ihex_reader.h"
#include "engine/include/reader/format/ihex.h"
#include "engine/include/reader/binary_buffer.h"

// Project Headers (engine utilities)
#include "engine/include/misc/filemanip.h"
#include "engine/include/misc/bitmanip.h"
#include "engine/include/misc/stringmanip.h"

#define RECORD 8
Expand Down
23 changes: 23 additions & 0 deletions engine/src/reader/reader.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Format Reader Implementation */

// C Headers
#include <stddef.h>

// Project Headers (engine)
#include "engine/include/reader/reader.h"

// Project Headers (engine, formats)
#include "engine/include/reader/format/ihex.h"

vmcu_binary_buffer_t* vmcu_read_format(const VMCU_FMT fmt, const char *file, uint32_t *size) {

vmcu_binary_buffer_t *bb;

switch(fmt) {

case VMCU_FMT_IHEX: bb = vmcu_read_ihex(file, size); break;
default: bb = NULL; break;
}

return bb;
}

0 comments on commit b722f96

Please sign in to comment.