Пример #1
0
/*!
 * \brief This function de-initializes the Multi Core Communication subsystem for a given node.
 *
 * The function frees all resources of the node. Deletes all endpoints and frees any buffers that may have been queued there.
 *
 * \param[in] node Node number to be deinitialized.
 *
 * \return MCC_SUCCESS
 * \return MCC_ERR_SEMAPHORE (semaphore handling error)
 *
 * \see mcc_initialize
 */
int mcc_destroy(MCC_NODE node)
{
    int i = 0, return_value;

#if (MCC_OS_USED == MCC_MQX)
    for(i=0; i<MCC_MQX_LWEVENT_COMPONENTS_COUNT; i++) {
        _lwevent_destroy(&lwevent_buffer_queued[i]);
    }
    _lwevent_destroy(&lwevent_buffer_freed);
#endif

    /* Semaphore-protected section start */
    return_value = mcc_get_semaphore();
    if(return_value != MCC_SUCCESS)
        return return_value;

    /* All endpoints of the particular node have to be removed from the endpoint table */
    MCC_DCACHE_INVALIDATE_MLINES(&bookeeping_data->endpoint_table[0], MCC_ATTR_MAX_RECEIVE_ENDPOINTS * sizeof(MCC_ENDPOINT_MAP_ITEM));
    for(i = 0; i < MCC_ATTR_MAX_RECEIVE_ENDPOINTS; i++) {
        if (bookeeping_data->endpoint_table[i].endpoint.node == node) {
            /* Remove the endpoint from the table */
            mcc_remove_endpoint(bookeeping_data->endpoint_table[i].endpoint);
        }
    }

    /* Semaphore-protected section end */
    return_value = mcc_release_semaphore();
    if(return_value != MCC_SUCCESS)
        return return_value;

    /* Deinitialize synchronization module */
    mcc_deinit_semaphore(MCC_SHMEM_SEMAPHORE_NUMBER);

    return return_value;
}
Пример #2
0
uint32_t OS_Event_destroy(os_event_handle handle)
{
    LWEVENT_STRUCT *event = (LWEVENT_STRUCT*)handle;
    if (_lwevent_destroy(event) != MQX_OK)
    {
        _mem_free((void*)event);
        return (uint32_t)OS_EVENT_ERROR;
    }
    _mem_free((void*)event);
    return OS_EVENT_OK; 
}
Пример #3
0
static int sample_timer_deinit()
{
    VQPIT_REG_STRUCT_PTR  qpit_ptr = sample_qpit_ptr;

    /* Stop the timer */
    qpit_ptr->TIMERS[SAMPLE_PIT_CH].TCTRL &= (~ QPIT_TCTRL_TIE);

    _bsp_int_disable(SAMPLE_INT);

    if(_lwevent_destroy(&sample_event) != MQX_OK) {
        return -1;
    }

    return 0;
}
Пример #4
0
void Main_Task ( uint_32 param )
{ /* Body */
   USB_STATUS           status = USB_OK;
   uint_32              i = 0;
   _usb_host_handle     host_handle;
   boolean              ch_avail;
   
   if (NULL == (device_registered = _mem_alloc(sizeof(*device_registered))))
   {
       printf("\nMemory allocation failed");
      _task_block();
   }
   if (USB_OK != _lwevent_create(device_registered, LWEVENT_AUTO_CLEAR))
   {
       printf("\nlwevent create failed");
      _task_block();
   }
   if (MQX_OK != _lwevent_create(&acm_device.acm_event, LWEVENT_AUTO_CLEAR)) {
       printf("\nlwevent create failed");
      _task_block();
   }
   if (MQX_OK != _lwevent_create(&data_device.data_event, LWEVENT_AUTO_CLEAR)) {
       printf("\nlwevent create failed");
      _task_block();
   }
   
   /* _usb_otg_init needs to be done with interrupts disabled */
   _int_disable();

   _int_install_unexpected_isr();
   if (MQX_OK != _usb_host_driver_install(USBCFG_DEFAULT_HOST_CONTROLLER)) {
      printf("\n Driver installation failed");
      _task_block();
   }

   /*
   ** It means that we are going to act like host, so we initialize the
   ** host stack. This call will allow USB system to allocate memory for
   ** data structures, it uses later (e.g pipes etc.).
   */
   status = _usb_host_init (USBCFG_DEFAULT_HOST_CONTROLLER, &host_handle);

   if (status != USB_OK) 
   {
      printf("\nUSB Host Initialization failed. STATUS: %x", status);
      _int_enable();
      _task_block();
   }

   /*
   ** since we are going to act as the host driver, register the driver
   ** information for wanted class/subclass/protocols
   */
   status = _usb_host_driver_info_register (
                                    host_handle,
                                    DriverInfoTable
                                    );
   if (status != USB_OK) {
      printf("\nDriver Registration failed. STATUS: %x", status);
      _int_enable();
      _task_block();
   }
          
   _int_enable();
   
   if (NULL == (f_uart = fopen("ittyb:", (pointer) (IO_SERIAL_XON_XOFF | IO_SERIAL_TRANSLATION) ))) {
      printf("\nError opening ittyb:", status);
      _task_block(); /* internal error occured */
   }

   printf("\nInitialization passed. Plug-in CDC device to USB port first.\n");
   printf("Use ttyb: as the in/out port for CDC device data.\n");
   printf("This example requires that the CDC device uses HW flow.\n");
   printf("If your device does not support HW flow, then set \n");
   printf("CDC_EXAMPLE_USE_HW_FLOW in cdc_serial.h to zero and rebuild example project.\n");

   while (1) {
      uart2usb_num = usb2uart_num = 0; /* reset number of bytes in buffers */
      
      _lwevent_wait_ticks(device_registered, 0x01, TRUE, 0);
   
      if (NULL == (f_usb = fopen(device_name, (pointer) &usb_open_param))) {
          printf("\nInternal error occured");
          _task_block(); /* internal error occured */
      }
      
      while (1) {
         /* due to the fact that uart driver blocks task, we will check if char is available and then we read it */
         do {
            if (IO_OK != ioctl(f_uart, IO_IOCTL_CHAR_AVAIL, &ch_avail)) {
                printf("\nUnexpected error occured");
                _task_block(); /* unexpected error occured */
            }
            if (ch_avail == TRUE) {
               /* read data from UART */
               num_done = fread(uart2usb + uart2usb_num, sizeof(uart2usb[0]), 1, f_uart); /* read max. 1 character from UART */
               if (IO_ERROR == num_done)
               {
                  printf("\nUnexpected error occured");
                  _task_block(); /* unexpected error occured */
               }
               uart2usb_num += num_done;
            }
         } while ( (ch_avail == TRUE) && (uart2usb_num < (sizeof(uart2usb) / sizeof(uart2usb[0]))) );

         /* write them to USB */
         if (uart2usb_num) 
         {
            num_done = fwrite(uart2usb, sizeof(uart2usb[0]), uart2usb_num, f_usb);
            if (IO_ERROR == num_done) 
            {
               if (ferror(f_usb) != USBERR_NO_INTERFACE)
               {
                  printf("\nUnexpected error occured");
                  _task_block(); /* unexpected error occured */
               }
               break; /* device was detached */
            }
            for (i = num_done; i < uart2usb_num; i++) /* move buffer data, remove the written ones */
               uart2usb[i - num_done] = uart2usb[i];
            uart2usb_num -= num_done;
         }

         /* read data from USB */
         num_done = fread(usb2uart + usb2uart_num, 1, sizeof(uart2usb) / sizeof(uart2usb[0]) - usb2uart_num, f_usb); /* read characters from USB */
         if (IO_ERROR == num_done) 
         {
            if (ferror(f_usb) != USBERR_NO_INTERFACE)
            {
               printf("\nUnexpected error occured");
               _task_block(); /* unexpected error occured */
            }
            break; /* device was detached */
         }
         usb2uart_num += num_done;
         /* write them to UART */
         if (usb2uart_num) 
         {
            num_done = fwrite(usb2uart, sizeof(usb2uart[0]), usb2uart_num, f_uart);
            if (IO_ERROR == num_done)
            {
               printf("\nUnexpected error occured");
               _task_block(); /* unexpected error occured */
            }
            for (i = num_done; i < usb2uart_num; i++) /* move buffer data, remove the read ones */
               usb2uart[i - num_done] = usb2uart[i];
            usb2uart_num -= num_done;
         }
      }
   }
   _lwevent_destroy(&data_device.data_event);
   _lwevent_destroy(&acm_device.acm_event);
} /* Endbody */