/** \brief test memcpy
 **
 ** test the function ciaaPOSIX_memcpy
 **
 **/
void test_ciaaPOSIX_memcpy(void) {
   char * from = "hello world";
   char to[1000];
   void * ret;
   uint32_t loopi;

   for(loopi = 0; loopi < sizeof(to); loopi++)
   {
      to[loopi] = 0;
   }

   ret = ciaaPOSIX_memcpy((void*)to, (void*)from, 4);
   TEST_ASSERT_TRUE(0 == strncmp(from, to, 4));
   TEST_ASSERT_TRUE(0 != strncmp(from, to, 5));
   TEST_ASSERT_TRUE(to == ret);

   ret = ciaaPOSIX_memcpy((void*)to, (void*)from, strlen(from)+1);
   TEST_ASSERT_TRUE(0 == strcmp(from, to));
   TEST_ASSERT_TRUE(to == ret);
}
예제 #2
0
extern size_t ciaaLibs_circBufGet(ciaaLibs_CircBufType * cbuf, void * data, size_t nbytes)
{
   size_t rawCount;

   /* the tail of the circular buffer my be changed, therefore it has to be
    * read only once */
   size_t tail = cbuf->tail;

   /* if the users tries to read to much data, only available data will be
    * provided */
   if (nbytes > ciaaLibs_circBufCount(cbuf, tail))
   {
      nbytes = ciaaLibs_circBufCount(cbuf, tail);
   }

   /* check if data to be read */
   if (nbytes > 0)
   {
      rawCount = ciaaLibs_circBufRawCount(cbuf, tail);

      /* check if all data can be read without wrapping */
      if (nbytes <= rawCount)
      {
         ciaaPOSIX_memcpy(data, ciaaLibs_circBufReadPos(cbuf), nbytes);
      }
      else
      {
         ciaaPOSIX_memcpy(data, ciaaLibs_circBufReadPos(cbuf), rawCount);
         ciaaPOSIX_memcpy((void*)((intptr_t)data + rawCount), (void*)(&cbuf->buf[0]), nbytes-rawCount);
      }

      /* calculates new head position */
      ciaaLibs_circBufUpdateHead(cbuf, nbytes);
   }

   return nbytes;
} /* end ciaaLibs_circBufGet */
예제 #3
0
extern size_t ciaaLibs_circBufPut(ciaaLibs_CircBufType * cbuf, void const * data, size_t nbytes)
{
   size_t ret = 0;
   size_t rawSpace;

   /* the head of the circular buffer may be changed, therefore it has to be
    * read only once */
   size_t head = cbuf->head;

   /* check that is enough place */
   if (ciaaLibs_circBufSpace(cbuf, head) >= nbytes)
   {
      rawSpace = ciaaLibs_circBufRawSpace(cbuf, head);

      /* check if wrapping is needed */
      if (rawSpace >= nbytes)
      {
         ciaaPOSIX_memcpy(ciaaLibs_circBufWritePos(cbuf), data, nbytes);
      }
      else
      {
         ciaaPOSIX_memcpy((void*)(&cbuf->buf[cbuf->tail]), data, rawSpace);
         ciaaPOSIX_memcpy((void*)(&cbuf->buf[0]),
               (void*)((intptr_t)data + rawSpace),
               nbytes-rawSpace);
      }

      /* calculate new tail position */
      ciaaLibs_circBufUpdateTail(cbuf, nbytes);

      /* set return value */
      ret = nbytes;
   }

   return ret;
} /* end ciaaLibs_circBufPut */
/*==================[internal functions definition]==========================*/
static int32_t UPDT_slaveSendResponse(
   UPDT_slaveType *slave,
   const uint8_t* payload,
   size_t payload_size,
   uint8_t response_type)
{
   uint8_t *buffer;
   ciaaPOSIX_assert(NULL != slave);
   ciaaPOSIX_assert(NULL != payload);

   buffer = slave->send_buffer;
   UPDT_protocolSetHeader(buffer, response_type, slave->sequence_number, payload_size);

   ciaaPOSIX_memcpy(buffer + UPDT_PROTOCOL_HEADER_SIZE, payload, payload_size);

   return UPDT_protocolSend(slave->transport, buffer, UPDT_PROTOCOL_HEADER_SIZE + payload_size);
}
예제 #5
0
extern ssize_t ciaaDriverAio_read(ciaaDevices_deviceType const * const device, uint8_t * const buffer, size_t const size)
{
   size_t ret = size;

   /* receive the data and forward to upper layer */
   ciaaDriverAio_uartType * uart = device->layer;

   if (size > uart->rxBuffer.length)
   {
      ret = uart->rxBuffer.length;
   }

   /* copy received bytes to upper layer */
   ciaaPOSIX_memcpy(buffer, &uart->rxBuffer.buffer[0], ret);

   return ret;
}
예제 #6
0
extern ssize_t ciaaDriverAio_write(ciaaDevices_deviceType const * const device, uint8_t const * const buffer, size_t const size)
{
   size_t ret = 0;

   /* write data */
   ciaaDriverAio_uartType * uart = device->layer;

   if (0 == uart->txBuffer.length)
   {
      /* copy data */
      ciaaPOSIX_memcpy(&uart->txBuffer.buffer, buffer, size);

      /* return lenght and set 0 for the next */
      ret = size;

      /* set length of the buffer */
      uart->txBuffer.length = size;
   }

   return ret;
}