DEMO: How to operate on registers

A simple example to illustrate the usage of the FwCcpc framework: It is supposed that a hardware type with two registers (I2C & LBUS) was already created by using the fwHw tool. (http://lhcb-online.web.cern.ch/lhcb-online/ecs/FWHW/default.html) The I2C register has 4 bytes and the LBUS register has 2 words with 4 bytes (= 8 bytes).
The registers have to be subscribed in order to establish the communication with the server. The FwCcpc library has to be used to operate on the registers.

  (...)
   
   dyn_dyn_char data;  
   dyn_dyn_char mask;  
   dyn_string   registers;  
   dyn_int      status;  
   int          i;  

   // ===========================================
   //  SUBSCRIBE TO ALL REGISTERS 
   // ===========================================
   if (fwHw_subscribe("myBoard"))
      DebugTN("All registers from hardware 'myBoard' subscribed!");
   else
      DebugTN("Registers from hardware 'myBoard' could not be subscribed!");

   
  // ===========================================
  //  OPERATE ON REGISTERS 
  // ===========================================
 
  //Both registers are written by applying a mask

   dynAppend(registers, "myBoard.I2Creg");  
   dynAppend(registers, "myBoard.LBUSreg");  
   dynAppend(data,fwCcpc_convertHexToByte("feedbabe"));  
   dynAppend(data, fwCcpc_convertHexToByte("feedbabe" + "feedbabe"));  
   dynAppend(mask,fwCcpc_convertHexToByte("ffff0000"));  //just feed is written
   //dynAppend(mask,makeDynChar());    // this line would lead to undefined behaviour
   dynAppend(mask,fwCcpc_convertHexToByte("ffffffff" + "00000000")); //just the first word is applied 
  
   if (fwCcpc_write(registers, data, mask, status, true))    
       for(i = 1; i <= dynlen(status); i++)  
          DebugTN("Status: " + status[i]);  
    else  
       DebugTN("Error found!");  
    (...)
 
  //Both registers are read:  "feedXXXX" for I2Creg and "feedbabe XXXXXXXX" for LBUSreg

    if (fwCcpc_read(registers, data, status))   // read data from registers 
       for(i = 1; i <= dynlen(status); i++)
       {
          DebugTN("Data: " + fwCcpc_convertByteToHex(data[i]));
          DebugTN("Status: " + status[i]);
       }
    else
      DebugTN("Error found!");
   (...)


  //Both registers are written again by applying no mask and are read back in one go
  //The result is now "feedbabe" for I2Creg and "feedbabe feedbabe" for LBUS reg

    dyn_dyn_char mask2;   //if mask remains empty no masked operation is performed
                          //however the mask has to be passed as no default is defined  


    if (fwCcpc_writeRead(registers, data, mask2, rdata, status))    
      for(i = 1; i <= dynlen(status); i++){  
          DebugTN("Status: " + status[i]);  
          DebugTN("Data: " + fwCcpc_convertByteToHex(rdata[i])); 
       }  
    else  
       DebugTN("Error found!");  
    (...)

/**


Generated on Fri Mar 28 13:15:39 2008 for FwCcpc by  doxygen 1.4.7