You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
2.5 KiB
C++

/*
* ROM.cpp
*
* Author: Aleksey Gerasimenko
* gerasimenko.aleksey.n@gmail.com
*/
#include "FRAM/ROM.h"
namespace FRAM
{
//CONSTRUCTOR
ROM::ROM():
m_mode(FRAM::ROM::UNDEFINED),
m_header(),
m_footer(),
m_int_last_address(0),
m_flt_last_address(0),
_write_float(&FRAM::ROM::_write_float_undef),
_read_float(&FRAM::ROM::_read_float_undef),
_write_int(&FRAM::ROM::_write_int_undef),
_read_int(&FRAM::ROM::_read_int_undef)
{}
//CONSTRUCTOR
//
void ROM::setup(const ROMSetup setup)
{
static bool _status = true;
if(m_mode == FRAM::ROM::UNDEFINED)
{
m_header = setup.header;
m_footer = setup.footer;
//
_status &= m_header.class_id != 0 ? true : false;
_status &= m_header.part_id != 0 ? true : false;
_status &= m_header.rom_size != 0 ? true : false;
_status &= m_header.software_version != 0 ? true : false;
_status &= m_footer.magic != 0 ? true : false;
//
if(_status)
{
m_mode = FRAM::ROM::OPERATIONAL;
//
_write_float = &FRAM::ROM::_write_float_undef;
_read_float = &FRAM::ROM::_read_float_undef;
_write_int = &FRAM::ROM::_write_int_undef;
_read_int = &FRAM::ROM::_read_int_undef;
//
}//if
//
}//if
//
}//
//
FRAM::ROM::mode_t ROM::get_mode()
{
return m_mode;
//
}//
//
bool ROM::compare(FRAM::ROM::mode_t mode)
{
return m_mode == mode;
//
}//
//
void ROM::write_float(float data, int16_t addr)
{
(this->*_write_float)(data, addr);
//
}//
//
float ROM::read_float(int16_t addr)
{
return (this->*_read_float)(addr);
//
}//
//
void ROM::write_int(int16_t data, int16_t addr)
{
(this->*_write_int)(data, addr);
//
}//
//
int16_t ROM::read_int(int16_t addr)
{
return (this->*_read_int)(addr);
//
}//
//
void ROM::_write_float_undef(float data, int16_t addr)
{}//
//
void ROM::_write_float_operate(float data, int16_t addr)
{
writefloat(data, addr);
//
}//
//
float ROM::_read_float_undef(int16_t addr)
{
return (float)0.0;
}//
//
float ROM::_read_float_operate(int16_t addr)
{
return readfloat(addr);
//
}//
//
void ROM::_write_int_undef(int16_t data, int16_t addr)
{}//
//
void ROM::_write_int_operate(int16_t data, int16_t addr)
{
writeint(data, addr);
//
}//
//
int16_t ROM::_read_int_undef(int16_t addr)
{
return 0;
}//
//
int16_t ROM::_read_int_operate(int16_t addr)
{
return readint(addr);
//
}//
//
} /* namespace FRAM */