Commit 5133db3f authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Used the internal memory structure instead of the global one (no longer available).

parent 0dd2f7df
......@@ -5,6 +5,8 @@
extern "C" {
#endif
#include "memory.h"
#ifndef FB_MAX_BUFFER_LEN
#error "Please, specify the maximum frame buffer length with the FB_MAX_BUFFER_LEN macro"
#endif
......@@ -13,6 +15,7 @@ extern "C" {
typedef struct
{
TMemory *memory;
unsigned short int ram_base_address;
unsigned short int eeprom_base_address;
unsigned short int num_rows;
......@@ -23,7 +26,7 @@ typedef struct
unsigned char pixel_buffer[FB_MAX_BUFFER_LEN];
}TFrameBuffer;
void frame_buffer_init(TFrameBuffer *fb,unsigned short int ram_base_address,unsigned short int eeprom_base_address);
void frame_buffer_init(TFrameBuffer *fb,TMemory *memory,unsigned short int ram_base_address,unsigned short int eeprom_base_address);
void frame_buffer_set_num_rows(TFrameBuffer *fb,unsigned short int rows);
unsigned short int frame_buffer_get_num_rows(TFrameBuffer *fb);
void frame_buffer_set_pixels_per_row(TFrameBuffer *fb,unsigned short int pixels);
......
......@@ -32,6 +32,7 @@ typedef struct TFBControl
TScheduler *scheduler;
sched_channel_t sch_channel;
unsigned short int period_ms;
TMemory *memory;
TMemModule mem_module;
unsigned short int ram_base_address;
unsigned short int eeprom_base_address;
......
......@@ -3,6 +3,7 @@
#include "patterns.h"
#include "frame_buffer_control.h"
#include "memory.h"
#ifndef IMG_MAX_NUM_IMAGES
#error "Please, specify the maximum number of images with the IMG_MAX_NUM_IMAGES macro"
......@@ -20,7 +21,7 @@
extern unsigned char img_pattern_data[IMG_MAX_NUM_IMAGES][IMG_MAX_IMAGE_WIDTH][IMG_MAX_IMAGE_HEIGHT][3];
void img_patterns_init(unsigned short int ram_base_address);
void img_patterns_init(TMemory *memory,unsigned short int ram_base_address);
#pragma pack (push, 1)
typedef struct
......
......@@ -7,12 +7,12 @@ void frame_buffer_compute_free_memory(TFrameBuffer *fb)
{
fb->buffer_size=fb->num_rows*fb->num_pixels_per_row*FB_BYTES_PER_PIXEL;
fb->free_mem=FB_MAX_BUFFER_LEN-fb->buffer_size*fb->num_buffers;
ram_data[fb->ram_base_address+FRAME_BUFFER_CONTROL_FREE_MEMORY_OFFSET]=fb->free_mem&0x00FF;
ram_data[fb->ram_base_address+FRAME_BUFFER_CONTROL_FREE_MEMORY_OFFSET+1]=(fb->free_mem&0xFF00)>>8;
fb->memory->data[fb->ram_base_address+FRAME_BUFFER_CONTROL_FREE_MEMORY_OFFSET]=fb->free_mem&0x00FF;
fb->memory->data[fb->ram_base_address+FRAME_BUFFER_CONTROL_FREE_MEMORY_OFFSET+1]=(fb->free_mem&0xFF00)>>8;
}
// public functions
void frame_buffer_init(TFrameBuffer *fb,unsigned short int ram_base_address,unsigned short int eeprom_base_address)
void frame_buffer_init(TFrameBuffer *fb,TMemory *memory,unsigned short int ram_base_address,unsigned short int eeprom_base_address)
{
unsigned int i;
......@@ -22,6 +22,7 @@ void frame_buffer_init(TFrameBuffer *fb,unsigned short int ram_base_address,unsi
frame_buffer_set_num_buffers(fb,DEFAULT_FRAME_BUFFER_CONTROL_NUM_BUFFERS);
fb->ram_base_address=ram_base_address;
fb->eeprom_base_address=eeprom_base_address;
fb->memory=memory;
for(i=0;i<FB_MAX_BUFFER_LEN;i++)
fb->pixel_buffer[i]=0x00;
......@@ -30,8 +31,8 @@ void frame_buffer_init(TFrameBuffer *fb,unsigned short int ram_base_address,unsi
void frame_buffer_set_num_rows(TFrameBuffer *fb,unsigned short int rows)
{
fb->num_rows=rows;
ram_data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_ROWS_OFFSET]=rows&0x00FF;
ram_data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_ROWS_OFFSET+1]=(rows&0xFF00)>>8;
fb->memory->data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_ROWS_OFFSET]=rows&0x00FF;
fb->memory->data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_ROWS_OFFSET+1]=(rows&0xFF00)>>8;
frame_buffer_compute_free_memory(fb);
}
......@@ -43,8 +44,8 @@ unsigned short int frame_buffer_get_num_rows(TFrameBuffer *fb)
void frame_buffer_set_pixels_per_row(TFrameBuffer *fb,unsigned short int pixels)
{
fb->num_pixels_per_row=pixels;
ram_data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_PIXELS_OFFSET]=pixels&0x00FF;
ram_data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_PIXELS_OFFSET+1]=(pixels&0xFF00)>>8;
fb->memory->data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_PIXELS_OFFSET]=pixels&0x00FF;
fb->memory->data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_PIXELS_OFFSET+1]=(pixels&0xFF00)>>8;
frame_buffer_compute_free_memory(fb);
}
......@@ -56,8 +57,8 @@ unsigned short int frame_buffer_get_pixels_per_row(TFrameBuffer *fb)
void frame_buffer_set_num_buffers(TFrameBuffer *fb,unsigned char num)
{
fb->num_buffers=num;
ram_data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_BUFFERS_OFFSET]=num&0x00FF;
ram_data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_BUFFERS_OFFSET+1]=(num&0xFF00)>>8;
fb->memory->data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_BUFFERS_OFFSET]=num&0x00FF;
fb->memory->data[fb->eeprom_base_address+FRAME_BUFFER_CONTROL_NUM_BUFFERS_OFFSET+1]=(num&0xFF00)>>8;
frame_buffer_compute_free_memory(fb);
}
......
......@@ -161,7 +161,9 @@ void frame_buffer_control_write_cmd(void *module,unsigned short int address,unsi
void frame_buffer_control_read_cmd(void *module,unsigned short int address,unsigned short int length,unsigned char *data)
{
ram_read_table(address,length,data);
TFBControl *control=(TFBControl *)module;
ram_read_table(control->memory,address,length,data);
}
void frame_buffer_control_scheduler(void *data)
......@@ -180,7 +182,7 @@ unsigned char frame_buffer_control_init(TFBControl *control,TMemory *memory,TSch
// initialize internal variables
frame_buffer_control_clear_patterns(control);
frame_buffer_control_clear_copy_functions(control);
frame_buffer_init(&control->frame_buffer,ram_base_address,eeprom_base_address);
frame_buffer_init(&control->frame_buffer,memory,ram_base_address,eeprom_base_address);
control->ram_base_address=ram_base_address;
control->eeprom_base_address=eeprom_base_address;
......@@ -189,13 +191,14 @@ unsigned char frame_buffer_control_init(TFBControl *control,TMemory *memory,TSch
control->scheduler=scheduler;
control->sch_channel=ch;
img_patterns_init(ram_base_address);
img_patterns_init(memory,ram_base_address);
/* initialize memory module */
mem_module_init(&control->mem_module);
control->mem_module.write_cmd=frame_buffer_control_write_cmd;
control->mem_module.read_cmd=frame_buffer_control_read_cmd;
control->mem_module.data=control;
control->memory=memory;
if(!mem_module_add_ram_segment(&control->mem_module,ram_base_address,RAM_FRAME_BUFFER_CONTROL_LENGTH))
return 0x00;
if(!mem_module_add_eeprom_segment(&control->mem_module,eeprom_base_address,EEPROM_FRAME_BUFFER_CONTROL_LENGTH))
......@@ -209,20 +212,20 @@ unsigned char frame_buffer_control_init(TFBControl *control,TMemory *memory,TSch
void frame_buffer_control_start(TFBControl *control)
{
scheduler_enable_channel(control->scheduler,control->sch_channel);
ram_data[control->ram_base_address+FRAME_BUFFER_CONTROL_OFFSET]|=FRAME_BUFFER_CONTROL_RUNNING;
control->memory->data[control->ram_base_address+FRAME_BUFFER_CONTROL_OFFSET]|=FRAME_BUFFER_CONTROL_RUNNING;
}
void frame_buffer_control_stop(TFBControl *control)
{
scheduler_disable_channel(control->scheduler,control->sch_channel);
ram_data[control->ram_base_address+FRAME_BUFFER_CONTROL_OFFSET]&=(~FRAME_BUFFER_CONTROL_RUNNING);
control->memory->data[control->ram_base_address+FRAME_BUFFER_CONTROL_OFFSET]&=(~FRAME_BUFFER_CONTROL_RUNNING);
}
void frame_buffer_control_set_period(TFBControl *control,unsigned short int period_ms)
{
scheduler_change_period(control->scheduler,control->sch_channel,period_ms);
ram_data[control->eeprom_base_address+FRAME_BUFFER_CONTROL_PERIOD_OFFSET]=period_ms&0x00FF;
ram_data[control->eeprom_base_address+FRAME_BUFFER_CONTROL_PERIOD_OFFSET+1]=(period_ms&0xFF00)>>8;
control->memory->data[control->eeprom_base_address+FRAME_BUFFER_CONTROL_PERIOD_OFFSET]=period_ms&0x00FF;
control->memory->data[control->eeprom_base_address+FRAME_BUFFER_CONTROL_PERIOD_OFFSET+1]=(period_ms&0xFF00)>>8;
control->period_ms=period_ms;
}
......@@ -241,22 +244,22 @@ unsigned char frame_buffer_control_add_pattern(TFBControl *control,pattern_func_
num_cols=frame_buffer_get_pixels_per_row(&control->frame_buffer);
if(area->min_row>num_rows || area->max_row>num_rows || area->min_row>area->max_row)
{
ram_data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=0xFF;
control->memory->data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=0xFF;
return 0xFF;
}
if(area->min_col>num_cols || area->max_col>num_cols || area->min_col>area->max_col)
{
ram_data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=0xFF;
control->memory->data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=0xFF;
return 0xFF;
}
if(data_length>FBC_MAX_DATA_PATTERN_LEN)
{
ram_data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=0xFF;
control->memory->data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=0xFF;
return 0xFF;
}
if(buffer_id>=frame_buffer_get_num_buffers(&control->frame_buffer))
{
ram_data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=0xFF;
control->memory->data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=0xFF;
return 0xFF;
}
......@@ -274,13 +277,13 @@ unsigned char frame_buffer_control_add_pattern(TFBControl *control,pattern_func_
control->pat_parameters[j][i]=((unsigned char *)data)[i];
control->pat_functions[j]=function;
control->num_patterns++;
ram_data[control->ram_base_address+FRAME_BUFFER_CONTROL_NUM_PATTERN_OFFSET]=control->num_patterns;
ram_data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=j;
control->memory->data[control->ram_base_address+FRAME_BUFFER_CONTROL_NUM_PATTERN_OFFSET]=control->num_patterns;
control->memory->data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=j;
return j;
}
}
// the pattern could not be added
ram_data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=0xFF;
control->memory->data[control->ram_base_address+FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET]=0xFF;
return 0xFF;
}
......
......@@ -43,12 +43,12 @@ void img_patterns_compute_range(unsigned short int area_min,unsigned short int a
}
// public functions
void img_patterns_init(unsigned short int ram_base_address)
void img_patterns_init(TMemory *memory,unsigned short int ram_base_address)
{
//initialize internal variables (read only variables)
ram_data[ram_base_address+FRAME_BUFFER_CONTROL_IMG_MAX_WIDTH_OFFSET]=IMG_MAX_IMAGE_WIDTH;
ram_data[ram_base_address+FRAME_BUFFER_CONTROL_IMG_MAX_HEIGHT_OFFSET]=IMG_MAX_IMAGE_HEIGHT;
ram_data[ram_base_address+FRAME_BUFFER_CONTROL_IMG_NUM_IMGS_OFFSET]=IMG_MAX_NUM_IMAGES;
memory->data[ram_base_address+FRAME_BUFFER_CONTROL_IMG_MAX_WIDTH_OFFSET]=IMG_MAX_IMAGE_WIDTH;
memory->data[ram_base_address+FRAME_BUFFER_CONTROL_IMG_MAX_HEIGHT_OFFSET]=IMG_MAX_IMAGE_HEIGHT;
memory->data[ram_base_address+FRAME_BUFFER_CONTROL_IMG_NUM_IMGS_OFFSET]=IMG_MAX_NUM_IMAGES;
}
void img_general(TLEDArea *area,TIMGDisplayData *pattern_data,unsigned char buffer_id,unsigned short int period,TFBControl *control)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment