Skip to content

Commit

Permalink
isla216p: add module.
Browse files Browse the repository at this point in the history
This module isn't fully implemented yet. The intention is to allow
access to its registers from decode-reg to aid development, but no
higher-level functionality has been implemented so far.

Identifying the correct SPI core is implemented the same way it was in
the ad9510 module.
  • Loading branch information
ericonr committed Sep 19, 2024
1 parent 145710e commit f4055d7
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
29 changes: 29 additions & 0 deletions include/modules/isla216p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef ISLA216P_H
#define ISLA216P_H

#include <modules/fmc250m_4ch.h>
#include <modules/spi.h>

namespace isla216p {

class Controller {
spi::Controller spi_regs;

fmc250m_4ch::Core f250_regs;
mutable std::optional<struct sdb_device_info> f250_devinfo;
mutable std::optional<struct sdb_device_info> spi_first_devinfo, spi_second_devinfo;

public:
Controller(struct pcie_bars &);

bool match_devinfo(const struct sdb_device_info &);
void set_devinfo(const struct sdb_device_info &);

bool get_reg(uint8_t, uint8_t &, spi::Channel);
bool set_reg(uint8_t, uint8_t, spi::Channel);
bool set_defaults(spi::Channel);
};

} /* namespace isla216p */

#endif
1 change: 1 addition & 0 deletions include/modules/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ install_headers(
'fofb_cc.h',
'fofb_processing.h',
'fofb_shaper_filt.h',
'isla216p.h',
'lamp.h',
'orbit_intlk.h',
'pos_calc.h',
Expand Down
74 changes: 74 additions & 0 deletions modules/isla216p.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "printer.h"
#include "util.h"
#include "modules/isla216p.h"

namespace isla216p {

Controller::Controller(struct pcie_bars &bars):
spi_regs(bars),
f250_regs(bars)
{
}

bool Controller::match_devinfo(const struct sdb_device_info &match)
{
/* the third SPI core after an FMC250M_4CH core is responsible for
* controlling that FMC's ISLA216P chip, and that's how we locate it */
if (f250_devinfo && spi_first_devinfo && spi_second_devinfo && spi_regs.match_devinfo_lambda(match)) {
/* XXX: should we include a check for the offset between FMC250M_4CH
* and SPI cores? */
f250_devinfo = std::nullopt;
spi_first_devinfo = std::nullopt;
spi_second_devinfo = std::nullopt;
return true;
}

if (f250_devinfo && spi_first_devinfo && spi_regs.match_devinfo_lambda(match)) {
spi_second_devinfo = match;
return false;
}

if (f250_devinfo && spi_regs.match_devinfo_lambda(match)) {
spi_first_devinfo = match;
return false;
}

if (f250_regs.match_devinfo_lambda(match)) {
f250_devinfo = match;
return false;
}

return false;
}

void Controller::set_devinfo(const struct sdb_device_info &new_devinfo)
{
spi_regs.set_devinfo(new_devinfo);
}

bool Controller::get_reg(uint8_t addr, uint8_t &rdata, spi::Channel channel)
{
const unsigned char wdata[] = {
0x80, /* read 1 byte */
addr,
};

return spi_regs.write_read_data(wdata, sizeof wdata, &rdata, sizeof rdata, channel.channel);
}

bool Controller::set_reg(uint8_t addr, uint8_t rdata, spi::Channel channel)
{
const unsigned char wdata[] = {
0x00, /* write 1 byte */
addr,
};

return spi_regs.write_read_data(wdata, sizeof wdata, &rdata, sizeof rdata, channel.channel);
}

bool Controller::set_defaults(spi::Channel)
{
return false;
}

} /* namespace isla216p */
1 change: 1 addition & 0 deletions modules/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ modules_src = [
'fofb_cc.cc',
'fofb_processing.cc',
'fofb_shaper_filt.cc',
'isla216p.cc',
'lamp.cc',
'orbit_intlk.cc',
'pos_calc.cc',
Expand Down

0 comments on commit f4055d7

Please sign in to comment.