Skip to content
Snippets Groups Projects
Commit beba5872 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Added a pointer to the associated module in the TMemModule structure.

This new pointer is passed to all callback functions.
parent ad7de303
No related branches found
No related tags found
1 merge request!6Dynamixel manager
......@@ -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);
......
......@@ -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
{
......
......@@ -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)
......
......@@ -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]);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment