コード例 #1
0
/** \brief test strlen
 **
 ** test the function ciaaPOSIX_strlen
 **
 **/
void test_ciaaPOSIX_strlen(void) {
   size_t ret;

   ret = ciaaPOSIX_strlen("/dev/serial");
   TEST_ASSERT_TRUE(11 == ret);

   ret = ciaaPOSIX_strlen("");
   TEST_ASSERT_TRUE(0 == ret);

   ret = ciaaPOSIX_strlen("/");
   TEST_ASSERT_TRUE(1 == ret);

   ret = ciaaPOSIX_strlen("/dev/s");
   TEST_ASSERT_TRUE(6 == ret);
}
コード例 #2
0
/** \brief UART initialization
 **
 ** \param[in] baudrate baud rate for uart usb
 ** \param[in] fifolevel fifo trigger level for uart usb
 **/
static void uart_init(int32_t baudrate, int32_t fifolevel)
{
   /* change baud rate for uart usb */
   ciaaPOSIX_ioctl(fd_uart1, ciaaPOSIX_IOCTL_SET_BAUDRATE, (void *)baudrate);

   /* change FIFO TRIGGER LEVEL for uart usb */
   ciaaPOSIX_ioctl(fd_uart1, ciaaPOSIX_IOCTL_SET_FIFO_TRIGGER_LEVEL, (void *)fifolevel);

   /* Send to UART controller configuration */
   char tempMaxascii[10];
   convert_temp_to_ascii((TEMP_MAX)*10, tempMaxascii);
   char tempMinascii[10];
   convert_temp_to_ascii((TEMP_MIN)*10, tempMinascii);

   const char message[] = "------ Temperature Controller ------\r\n\n";
   ciaaPOSIX_write(fd_uart1, message, ciaaPOSIX_strlen(message));

   const char message2[] = "Maximum Temperature:\r\n";
   ciaaPOSIX_write(fd_uart1, message2, ciaaPOSIX_strlen(message2));

   ciaaPOSIX_write(fd_uart1, tempMaxascii, ciaaPOSIX_strlen(tempMaxascii));

   const char message3[] = "\nMinimum Temperature:\r\n";
   ciaaPOSIX_write(fd_uart1, message3, ciaaPOSIX_strlen(message3));

   ciaaPOSIX_write(fd_uart1, tempMinascii, ciaaPOSIX_strlen(tempMinascii));

   const char message4[] = "\n\nActual Temperature:\r\n";
   ciaaPOSIX_write(fd_uart1, message4, ciaaPOSIX_strlen(message4));
}
コード例 #3
0
/** \brief Send Temperature to UART
 **
 ** \param[in] tempNow temperature to send multiplied by 10
 **/
static void sendTemp_Uart(uint32_t tempNow)
{
   char data_to_send[10];
   uint8_t outputs;

   convert_temp_to_ascii(tempNow, data_to_send);

   ciaaPOSIX_write(fd_uart1, data_to_send, ciaaPOSIX_strlen(data_to_send));

   /* Toggle LED 1 */
   ciaaPOSIX_read(fd_out, &outputs, 1);
   outputs ^= LED1;
   ciaaPOSIX_write(fd_out, &outputs, 1);
}
コード例 #4
0
extern void ciaaBlockDevices_addDriver(ciaaDevices_deviceType * driver)
{
   ciaaDevices_deviceType * newDevice;
   char * newDeviceName;
   uint8_t length;
   uint8_t position;

   /* enter critical section */
   /* not needed, only 1 task running */

   /* check if more drivers can be added */
   if (ciaaBlockDevices_MAXDEVICES > ciaaBlockDevices.position) {

      /* get position for next device */
      position = ciaaBlockDevices.position;

      /* increment position for next device */
      ciaaBlockDevices.position++;

      /* exit critical section */
      /* not needed, only 1 task running */

      /* add driver */
      ciaaBlockDevices.devstr[position].device = driver;

      /* initial flags */
      ciaaBlockDevices.devstr[position].flags = 0;

      /* allocate memory for new device */
      newDevice = (ciaaDevices_deviceType*) ciaak_malloc(sizeof(ciaaDevices_deviceType));

      /* set functions for this device */
      newDevice->open = ciaaBlockDevices_open;
      newDevice->close = ciaaBlockDevices_close;
      newDevice->ioctl = ciaaBlockDevices_ioctl;
      newDevice->read = ciaaBlockDevices_read;
      newDevice->write = ciaaBlockDevices_write;
      newDevice->lseek = ciaaBlockDevices_lseek;

      /* store layers information information */
      newDevice->layer = (void *) &ciaaBlockDevices.devstr[position];
      newDevice->loLayer = (void *) driver;

      /* store newDevice layer information in the lower layer */
      driver->upLayer = newDevice;

      /* create path string for this device */
      length = ciaaPOSIX_strlen(driver->path);
      length += ciaaPOSIX_strlen(ciaaBlockDevices_prefix);
      length += 2; /* for the / and the termination null */

      /* create path for the new device */
      newDeviceName = (char *) ciaak_malloc(length);

      /* start a new string */
      *newDeviceName = 0;

      /* add prefix, / and the device name */
      ciaaPOSIX_strcat(newDeviceName, ciaaBlockDevices_prefix);
      ciaaPOSIX_strcat(newDeviceName, "/");
      ciaaPOSIX_strcat(newDeviceName, driver->path);
      /* add path to device structure */
      newDevice->path = newDeviceName;

      /* add device */
      ciaaDevices_addDevice(newDevice);
   }
   else
   {
      /* exit critical section */
      /* not needed, only 1 task running */
   }
}