3.4.2. Writing string registers

Writing string registers works differently from writing to an integer or a floating point register, and to reading a string register, because a string register does not have a fixed bitwidth. A CADIRegWrite to a string register using non-zero offset128 could extend, truncate, or update a string. To avoid ambiguity, string updates must allocate an array of n CADIReg_t elements with enough buffer space to store the entire string, including a terminating null character. The offset128 parameter in each CADIReg_t must have the value n and the bytes buffer must contain the nth 16 byte chunk of the string. The caller performs a single CADIRegWrite, updating the string register atomically, if successful.

Example 3.7. Writing string registers

eslapi::CADIReturn_t status;

//"register_info" contains information on a string register

std::string writeString("Pneumonoultramicroscopicsilicovolcanoconiosis");
const char *s = writeString.c_str();
uint32_t bytes  = strlen(s) + 1;
uint32_t chunks = (bytes + 15) / 16; // The number of 128-bit chunks required to hold the null terminated string
uint32_t numRegsWritten = 0;
eslapi::CADIReg_t *regs = new eslapi::CADIReg_t[chunks];

for(uint32_t i = 0; i < chunks; i++)
{
   regs[i].regNumber = register_info.regNumber;
   regs[i].offset128 = i;
   uint32_t remaining = bytes - i*16;
   memset(regs[i].bytes, 0, 16);
   memcpy(regs[i].bytes, &s[i*16], remaining > 16 ? 16 : remaining);
}
status = cadi->CADIRegWrite(chunks, regs, &numRegsWritten, 0); 
delete[] regs;

if (status != eslapi::CADI_STATUS_OK || numRegsWritten != chunks)
{
   printf("ERROR: Writing register failed\n");
   return;
}

Copyright © 2008-2014 ARM. All rights reserved.ARM DUI 0444M
Non-ConfidentialID051314