示例#1
0
extern void ciaaSerialDevices_rxIndication(ciaaDevices_deviceType const * const device, uint32_t const nbyte)
{
   /* get serial device */
   ciaaSerialDevices_deviceType * serialDevice =
      (ciaaSerialDevices_deviceType*) device->layer;
   ciaaLibs_CircBufType * cbuf = &serialDevice->rxBuf;
   uint32_t head = cbuf->head;
   uint32_t rawSpace = ciaaLibs_circBufRawSpace(cbuf, head);
   uint32_t space = ciaaLibs_circBufSpace(cbuf, head);
   uint32_t read = 0;
   TaskType taskID = serialDevice->blocked.taskID;

   read = serialDevice->device->read(device->loLayer, ciaaLibs_circBufWritePos(cbuf), rawSpace);

   /* if rawSpace is full but more space is avaialble */
   if ((read == rawSpace) && (space > rawSpace))
   {
      read += serialDevice->device->read(
            device->loLayer,
            &cbuf->buf[0],
            space - rawSpace);
   }
   else
   {
      if ((read == rawSpace) && (space <= rawSpace))
      {
         /* data may be lost because not place on the receive buffer */
         /* TODO */
      }
      else
      {
         /* read less bytes than provided */
         /* nothing to do */
      }
   }

   /* update tail */
   ciaaLibs_circBufUpdateTail(cbuf, read);

   /* if data has been read */
   if ( (0 < read) && (255 != taskID) &&
         (serialDevice->blocked.fct == (void*) ciaaSerialDevices_read ) )
   {
      /* invalidate task id */
      serialDevice->blocked.taskID = 255; /* TODO add macro */

      /* reset blocked function */
      serialDevice->blocked.fct = NULL;

      /* set task event */
#ifdef POSIXE
      SetEvent(taskID, POSIXE);
#endif
   }
}
示例#2
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 */