Master Slave


Q&A

  • Master Slave: how do they communicate?
    • ModuleA (master)<—-> (slave) ModuleB (master) <—-> (slave) ModuleC
    • Master controls the communication: do the put/get things by calling slave’s interface method. Slave will be waiting for being called and receive the data;
    • One has Slave interface will also have a Master interface in order to pass this data to the Slave interface of next module.
    • Right?

See Bluespec basics for connectable interfaces [/en/arch/basics/bluespec/packages/connectable/client-server/]

Master

// cherilibs/trunk/MasterSlave.bsv

interface Master#(type req_t, type rsp_t);
    interface CheckedGet#(req_t) request;  // interface to send request out
    interface CheckedPut#(rsp_t) response; // interface to get a response in
endinterface

Master-Slave

Master# is used as client interface and Slave# is used as server interface.

Master.request.get() –> Slave.request.put() // Master send a request ot Master.response.put() <– Slave.response.get() // Master receive a new response from Slave.

// file: cherilibs/trunk/MasterSlave.bsv

// Slave to Server: A Server# interface with request and response
function Server#(req_t,rsp_t) slaveToServer (Slave#(req_t, rsp_t) s) =
    interface Server#(req_t, rsp_t);
        interface request  = toPut(s.request); // A Put# interface, allow others to send request into this server;
        interface response = toGet(s.response); // A Get# interface, allow others to get responses froms this server;
    endinterface;

// Master to Client: A client# interface with request and response
function Client#(req_t,rsp_t) masterToClient (Master#(req_t, rsp_t) m) =
    interface Client#(req_t, rsp_t);
        interface request  = toGet(m.request); // a Get#(req_t) interface, allow the client to send out request out; 
        interface response = toPut(m.response); // a Put#(rsp_t), allow the client to receive a new repsonse from outside;
    endinterface;

// Master as client and Slave as server
instance Connectable#(Master#(req_t, rsp_t), Slave#(req_t, rsp_t));
    module mkConnection#(Master#(req_t, rsp_t) m, Slave#(req_t, rsp_t) s)(Empty);
        mkConnection(masterToClient(m), slaveToServer(s));
    endmodule
endinstance



function Server#(req_t,rsp_t) slaveToServer (Slave#(req_t, rsp_t) s) =
    interface Server#(req_t, rsp_t);
        interface request  = toPut(s.request);
        interface response = toGet(s.response);
    endinterface;

instance Connectable#(Slave#(req_t, rsp_t), Master#(req_t, rsp_t));
    module mkConnection#(Slave#(req_t, rsp_t) s, Master#(req_t, rsp_t) m)(Empty);
        mkConnection(masterToClient(m), slaveToServer(s));
    endmodule
endinstance

ToCheckedGet

// cherilibs/trunk/MasterSlave.bsv

instance ToCheckedGet#(FIFOF#(data_t), data_t);
    function CheckedGet#(data_t) toCheckedGet (FIFOF#(data_t) f) =
        interface CheckedGet#(data_t);
            method canGet = f.notEmpty;
            method data_t peek if (f.notEmpty);
              return f.first;
            endmethod
            method ActionValue#(data_t) get if (f.notEmpty);
              f.deq; 
              return f.first;
            endmethod
        endinterface;
endinstance

Reference 1


  1. reference ↩
Created May 6, 2020 // Last Updated May 18, 2021

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?