peary/device/CaribouDevice.hpp

Caribou Device Class. More…

Namespaces

Name
peary
peary::device Forward declaration of CaribouDevice, Board, and Carboard classes.

Classes

Name
class peary::device::CaribouDevice Caribou Device class definition.

Detailed Description

Caribou Device Class.

Copyright: Copyright (c) 2016-2025 CERN and the Peary Caribou authors. This software is distributed under the terms of the LGPL-3.0-only License, copied verbatim in the file “LICENSE.md”. SPDX-License-Identifier: LGPL-3.0-only

Source code

  
#pragma once

#include <any>
#include <cstdint>
#include <string>
#include <vector>

#include "peary/config/configuration.hpp"
#include "peary/hal/Resources.hpp"
#include "peary/utils/constants.hpp"
#include "peary/utils/datatypes.hpp"
#include "peary/utils/dictionary.hpp"

#include "Device.hpp"

namespace peary::device {

    class Board;

    template <typename B, typename SCI, typename DRI = SCI> class CaribouDevice : public Device {

    public:
        CaribouDevice(const config::Configuration& config, const typename SCI::configuration_type& sciConfig);

        CaribouDevice(const config::Configuration config,
                      const typename SCI::configuration_type sciConfig,
                      const typename DRI::configuration_type driConfig);

        std::string getFirmwareVersion() override;

        std::string getName() override { return getType(); };

        std::string getType() override;

        uint8_t getBoardID();

        uint16_t getChipID() { return 0; };

        std::string getDeviceName();

        void powerOn() override;

        virtual void powerUp() = 0;

        void powerOff() override;

        virtual void powerDown() = 0;

        void daqStart() override = 0;

        void daqStop() override = 0;

        void configure() override;

        void setRegister(std::string name, uintptr_t value) override;

        virtual void setSpecialRegister(const std::string&, uintptr_t) {};

        virtual uintptr_t getSpecialRegister(const std::string&) { return 0; };

        uintptr_t getRegister(std::string name) override;

        std::vector<std::pair<std::string, uintptr_t>> getRegisters() override;

        void reset() override;

        void setVoltage(const std::string& name, double voltage) override;

        void setCurrentLimit(const std::string& name, double current_limit) override;

        void setCurrent(const std::string& name, double current, utils::Polarity polarity) override;

        void switchOn(const std::string& name) override { return switch_resource(name, true); };

        void switchOff(const std::string& name) override { return switch_resource(name, false); };

        double getVoltage(const std::string& name) override;

        double getCurrent(const std::string& name) override;

        double getPower(const std::string& name) override;

        bool getAlertStatus(const std::string& name);

        double getTemperature(const std::string& name);

        void configureClock(const std::string& name, const std::any& config) override;

        void disableClock(const std::string& name) override;

        bool isClockLocked(const std::string& name) override;

        void setClockFrequency(const std::string& name, uint64_t frequency) override;

        std::vector<std::string> listMemories() override;

        std::vector<std::string> listRegisters() override;

        std::vector<std::pair<std::string, std::string>> listResources() override;

        utils::pearyRawData getRawData() override;

        utils::pearyRawDataVector getRawData(const unsigned int noFrames) override;

        utils::pearydata getData() override;

        utils::pearydataVector getData(const unsigned int noFrames) override;

        void setMemory(const std::string& name, size_t offset, uintptr_t value) override;

        void setMemory(const std::string& name, uintptr_t value) override;

        template <typename D = uintptr_t> D getMemory(const std::string& name, size_t offset);

        uintptr_t getMemory(const std::string& name, size_t offset) override { return getMemory<uintptr_t>(name, offset); }

        template <typename D = uintptr_t> D getMemory(const std::string& name);

        uintptr_t getMemory(const std::string& name) override { return getMemory<uintptr_t>(name); }

        std::vector<std::pair<std::string, uintptr_t>> getMemories() override;

    protected:
        void register_resource(const std::string& name, const std::string& resource);

        void process_register_write(utils::register_t<typename SCI::reg_type, typename SCI::data_type> reg, uintptr_t value);

        uintptr_t process_register_read(utils::register_t<typename SCI::reg_type, typename SCI::data_type> reg);

        std::shared_ptr<B> _board;

        config::Configuration _config;

        utils::dictionary<utils::register_t<typename SCI::reg_type, typename SCI::data_type>> _registers;

        std::map<std::string, typename SCI::data_type> _register_cache;

        utils::dictionary<hal::Resource> _periphery;

        utils::dictionary<std::pair<utils::memory_map, utils::register_t<std::uintptr_t, std::uintptr_t>>> _memory;

        const typename SCI::configuration_type _sciConfig;

        const typename DRI::configuration_type _driConfig;

        typename SCI::data_type send(const typename SCI::data_type& data);

        typename SCI::dataVector_type send(const std::vector<typename SCI::data_type>& data);

        std::pair<typename SCI::reg_type, typename SCI::data_type>
        send(const std::pair<typename SCI::reg_type, typename SCI::data_type>& data);

        typename SCI::dataVector_type send(const typename SCI::reg_type& reg,
                                           const std::vector<typename SCI::data_type>& data);

        std::vector<std::pair<typename SCI::reg_type, typename SCI::data_type>>
        send(const std::vector<std::pair<typename SCI::reg_type, typename SCI::data_type>>& data);

        typename SCI::dataVector_type receive(const typename SCI::reg_type reg, const unsigned int length = 1);

        typename DRI::dataVector_type receiveData(const unsigned int length = 1);

        typename DRI::dataVector_type receiveData(const typename DRI::reg_type reg, const unsigned int length = 1);

        template <typename reg_type, typename data_type>
        data_type obey_mask_write(utils::register_t<reg_type, data_type> reg, data_type regval, data_type regcurrval) const;

        template <typename reg_type, typename data_type>
        data_type obey_mask_read(utils::register_t<reg_type, data_type> reg, data_type regval) const;

    private:
        bool _is_powered;

        bool _is_configured;

        void switch_resource(const std::string& name, bool enable);

    }; // class CaribouDevice

} // namespace peary::device

#include "CaribouDevice.tcc"
  

Updated on 2025-11-14 at 11:31:23 +0100