From beba5872f09fbdd8477014b66e93758e0686f6d0 Mon Sep 17 00:00:00 2001 From: Sergi Hernandez Juan <shernand@iri.upc.edu> Date: Wed, 23 Aug 2017 17:15:59 +0200 Subject: [PATCH] Added a pointer to the associated module in the TMemModule structure. This new pointer is passed to all callback functions. --- memory/include/mem_module.h | 5 +++-- memory/include/memory.h | 8 ++++++-- memory/src/mem_module.c | 1 + memory/src/memory.c | 10 +++++----- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/memory/include/mem_module.h b/memory/include/mem_module.h index 50c085e..ae07cc7 100644 --- a/memory/include/mem_module.h +++ b/memory/include/mem_module.h @@ -15,8 +15,9 @@ typedef struct TMemSegment ram_segments[MAX_NUM_SEGMENTS]; unsigned char num_eeprom_segments; TMemSegment eeprom_segments[MAX_NUM_SEGMENTS]; - void (*write_cmd)(unsigned short int address,unsigned short int length,unsigned char *data); - void (*read_cmd)(unsigned short int address,unsigned short int length,unsigned char *data); + void (*write_cmd)(void *module,unsigned short int address,unsigned short int length,unsigned char *data); + void (*read_cmd)(void *module,unsigned short int address,unsigned short int length,unsigned char *data); + void *data; }TMemModule; void mem_module_init(TMemModule *module); diff --git a/memory/include/memory.h b/memory/include/memory.h index 21214c5..1829fee 100644 --- a/memory/include/memory.h +++ b/memory/include/memory.h @@ -4,8 +4,12 @@ #include "mem_module.h" #define MAX_NUM_MEM_MODULES 16 -#define EEPROM_SIZE 32 -#define RAM_SIZE 256 +#ifndef EEPROM_SIZE + #define EEPROM_SIZE 32 +#endif +#ifndef RAM_SIZE + #define RAM_SIZE 256 +#endif typedef struct { diff --git a/memory/src/mem_module.c b/memory/src/mem_module.c index cf158d1..e972388 100644 --- a/memory/src/mem_module.c +++ b/memory/src/mem_module.c @@ -17,6 +17,7 @@ void mem_module_init(TMemModule *module) } module->write_cmd=0x00000000; module->read_cmd=0x00000000; + module->data=0x00000000; } unsigned char mem_module_add_ram_segment(TMemModule *module,unsigned short int start_address, unsigned short int length) diff --git a/memory/src/memory.c b/memory/src/memory.c index c2b2a70..68fbc80 100644 --- a/memory/src/memory.c +++ b/memory/src/memory.c @@ -66,7 +66,7 @@ void mem_initialize_data(TMemory *memory) actual_length=EEPROM_SIZE-mem_module->eeprom_segments[j].start_address; if((actual_address+actual_length)>(mem_module->eeprom_segments[j].start_address+mem_module->eeprom_segments[j].length)) actual_length-=((actual_address+actual_length)-(mem_module->eeprom_segments[j].start_address+mem_module->eeprom_segments[j].length)); - mem_module->write_cmd(actual_address,actual_length,&eeprom_data[actual_address]); + mem_module->write_cmd(mem_module->data,actual_address,actual_length,&eeprom_data[actual_address]); } } } @@ -171,7 +171,7 @@ void mem_do_write(TMemory *memory,unsigned short int start_address,unsigned shor } if((actual_address+actual_length)>(mem_module->ram_segments[j].start_address+mem_module->ram_segments[j].length)) actual_length-=((actual_address+actual_length)-(mem_module->ram_segments[j].start_address+mem_module->ram_segments[j].length)); - mem_module->write_cmd(actual_address,actual_length,&data[actual_address-start_address]); + mem_module->write_cmd(mem_module->data,actual_address,actual_length,&data[actual_address-start_address]); } } } @@ -192,7 +192,7 @@ void mem_do_write(TMemory *memory,unsigned short int start_address,unsigned shor if((actual_address+actual_length)>(mem_module->eeprom_segments[j].start_address+mem_module->eeprom_segments[j].length)) actual_length-=((actual_address+actual_length)-(mem_module->eeprom_segments[j].start_address+mem_module->eeprom_segments[j].length)); if(mem_module->write_cmd!=0x00000000) - mem_module->write_cmd(actual_address,actual_length,&data[actual_address-start_address]); + mem_module->write_cmd(mem_module->data,actual_address,actual_length,&data[actual_address-start_address]); if(memory->eeprom_write_data!=0x00000000) for(k=actual_address;k<(actual_address+actual_length);k++) memory->eeprom_write_data(k,data[k-start_address]); @@ -228,7 +228,7 @@ void mem_do_read(TMemory *memory,unsigned short int start_address,unsigned short } if((actual_address+actual_length)>(mem_module->ram_segments[j].start_address+mem_module->ram_segments[j].length)) actual_length-=((actual_address+actual_length)-(mem_module->ram_segments[j].start_address+mem_module->ram_segments[j].length)); - mem_module->read_cmd(actual_address,actual_length,&data[actual_address-start_address]); + mem_module->read_cmd(mem_module->data,actual_address,actual_length,&data[actual_address-start_address]); } } } @@ -250,7 +250,7 @@ void mem_do_read(TMemory *memory,unsigned short int start_address,unsigned short } if((actual_address+actual_length)>(mem_module->eeprom_segments[j].start_address+mem_module->eeprom_segments[j].length)) actual_length-=((actual_address+actual_length)-(mem_module->eeprom_segments[j].start_address+mem_module->eeprom_segments[j].length)); - mem_module->read_cmd(actual_address,actual_length,&data[actual_address-start_address]); + mem_module->read_cmd(mem_module->data,actual_address,actual_length,&data[actual_address-start_address]); } } } -- GitLab