示例#1
0
文件: io_pipe.c 项目: gxliu/MQX_3.8.0
_mqx_int _io_pipe_close
   (
      /* [IN] the file handle for the device being closed */
      FILE_DEVICE_STRUCT_PTR fd_ptr
   )
{ /* Body */
   IO_PIPE_INFO_STRUCT_PTR         io_pipe_info_ptr;
   int_32                          result = MQX_OK;

   io_pipe_info_ptr = fd_ptr->DEV_DATA_PTR;

   /* Destroy the mutexes - doesn't free memory*/

    _mutex_destroy(&io_pipe_info_ptr->READ_MUTEX);
    _mutex_destroy(&io_pipe_info_ptr->WRITE_MUTEX);
    _mutex_destroy(&io_pipe_info_ptr->ACCESS_MUTEX);
                                 
   /* Start CR 2237 */
   /* Derstroy the lightweight semaphores */
   _lwsem_destroy(&io_pipe_info_ptr->FULL_SEM);
   _lwsem_destroy(&io_pipe_info_ptr->EMPTY_SEM);
   /* End CR 2237 */

   /* Free Pipe data structures */
   _mem_free(io_pipe_info_ptr->QUEUE);
   _mem_free(io_pipe_info_ptr);

   return(result);

} /* Endbody */
示例#2
0
void RTCS_msgqueue_close
   (
      _rtcs_msgqueue  *msgq
   )
{ /* Body */

   _lwsem_destroy(&msgq->FULL);
   _lwsem_destroy(&msgq->EMPTY);

} /* Endbody */
示例#3
0
文件: usbmfs.c 项目: gxliu/MQX_3.8.0
int_32 _io_usb_mfs_uninstall_internal
   (
       /* [IN] The device to uninstall */            
      IO_DEVICE_STRUCT_PTR   io_dev_ptr
   )
{ 
  IO_USB_MFS_STRUCT_PTR info_ptr = (IO_USB_MFS_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR;
   _lwsem_destroy(&info_ptr->COMMAND_DONE);
   _lwsem_destroy(&info_ptr->LWSEM);
   USB_mem_free(info_ptr);
   return MQX_OK;
}
示例#4
0
_mqx_int _io_pcb_shm_close
    (
        /* [IN] the file handle */
        FILE_DEVICE_STRUCT_PTR fd_ptr
    )
{
    IO_PCB_SHM_INFO_STRUCT_PTR  info_ptr;
    IO_PCB_STRUCT_PTR           pcb_ptr;
    IO_PCB_SHM_INIT_STRUCT_PTR  init_ptr;

#if MQX_CHECK_ERRORS
    if (!(fd_ptr->FLAGS & IO_FLAG_IS_PCB_DEVICE)) {
        fd_ptr->ERROR = IO_PCB_NOT_A_PCB_DEVICE;
        return(IO_ERROR);
    }
#endif
    info_ptr = (IO_PCB_SHM_INFO_STRUCT_PTR)fd_ptr->DEV_DATA_PTR;
    init_ptr = &info_ptr->INIT;

    if (!_int_install_isr(init_ptr->RX_VECTOR,
        info_ptr->RX_OLDISR_PTR, info_ptr->RX_OLDISR_DATA))
    {
        return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED;
    }

    if (init_ptr->TX_VECTOR) {
        if (!_int_install_isr(init_ptr->TX_VECTOR, info_ptr->TX_OLDISR_PTR,
            info_ptr->TX_OLDISR_DATA))
        {
            return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED;
        }
    }

    _lwsem_destroy(&info_ptr->READ_LWSEM);
    _lwsem_destroy(&info_ptr->WRITE_LWSEM);

    while (_queue_get_size(&info_ptr->WRITE_QUEUE)) {
        pcb_ptr = (IO_PCB_STRUCT_PTR)
            ((pointer)_queue_dequeue(&info_ptr->WRITE_QUEUE));
        _io_pcb_free(pcb_ptr);
    }

    while (_queue_get_size(&info_ptr->READ_QUEUE)) {
        pcb_ptr = (IO_PCB_STRUCT_PTR)
            ((pointer)_queue_dequeue(&info_ptr->READ_QUEUE));
        _io_pcb_free(pcb_ptr);
    }

    return(MQX_OK);

}
示例#5
0
_mqx_int _io_pcb_mqxa_close
   (
      /* [IN] the file handle */
      FILE_DEVICE_STRUCT_PTR fd_ptr
   )
{ /* Body */
   IO_PCB_MQXA_INFO_STRUCT_PTR info_ptr;
   IO_PCB_STRUCT_PTR           pcb_ptr;

#if MQX_CHECK_ERRORS
   if (!(fd_ptr->FLAGS & IO_FLAG_IS_PCB_DEVICE)) {
      fd_ptr->ERROR = IO_PCB_NOT_A_PCB_DEVICE;
      return(IO_ERROR);
   }/* Endif */
#endif
   info_ptr = (IO_PCB_MQXA_INFO_STRUCT_PTR)fd_ptr->DEV_DATA_PTR;
   if (info_ptr->FD) {
      fclose(info_ptr->FD);
      info_ptr->FD = NULL;
   }/* Endif */
   if (info_ptr->INPUT_TASK) {
#if MQX_TASK_DESTRUCTION   
      _task_destroy(info_ptr->INPUT_TASK);
#endif      
      info_ptr->INPUT_TASK = 0;
   }/* Endif */
   if (info_ptr->OUTPUT_TASK ) {
#if MQX_TASK_DESTRUCTION   
      _task_destroy(info_ptr->OUTPUT_TASK);
#endif
      info_ptr->OUTPUT_TASK = 0;
   }/* Endif */
   _lwsem_destroy(&info_ptr->READ_LWSEM);
   _lwsem_destroy(&info_ptr->WRITE_LWSEM);

   while (_queue_get_size(&info_ptr->WRITE_QUEUE)) {
      pcb_ptr = (IO_PCB_STRUCT_PTR)
         ((pointer)_queue_dequeue(&info_ptr->WRITE_QUEUE));
      _io_pcb_free(pcb_ptr);
   } /* Endwhile */

   while (_queue_get_size(&info_ptr->READ_QUEUE)) {
      pcb_ptr = (IO_PCB_STRUCT_PTR)
         ((pointer)_queue_dequeue(&info_ptr->READ_QUEUE));
      _io_pcb_free(pcb_ptr);
   } /* Endwhile */

   return(MQX_OK);
   
} /* Endbody */
示例#6
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name    : btnled_deinit
* Returned Value   : MQX_OK or an error code
* Comments         :
*   This function deallocates used memory.
*
*END*--------------------------------------------------------------------*/
uint_32 btnled_deinit(HMI_CLIENT_STRUCT_PTR handle)
{
    BTNLED_CONTEXT_STRUCT_PTR   context;
    uint_32                     result = MQX_OK;

    /* destroy callbacks and a semaphore */
    context = (BTNLED_CONTEXT_STRUCT_PTR) (handle)->CONTEXT_PTR;

    if(context->CLBREG != NULL)
    {
        do
        {
            btnled_remove_clb(handle, context->CLBREG);
        }
        while(context->CLBREG->NEXT_CALLBACK != NULL);
    }

    _lwsem_destroy(&context->LOCK_BTNLED_SEM);

    result =_mem_free(handle->PROVIDER_TABLE);
    if(result != MQX_OK)
    {
        return result;
    }
    result =_mem_free((handle)->CONTEXT_PTR);
    if(result != MQX_OK)
    {
        return result;
    }
    handle = NULL;
    return result;
}
示例#7
0
/** De-Initialise the Uart.
 *
 * BLEUART_Deinit()
 *	This function is called by the BLE stack (TRANSPORT layer) to de-initialise
 *	the UART layer. Eventual thread shall be terminated here.
 *	When this function succeed, the UART layer shall be fully de-initialised
 *
 *	This function is called during the BLESTCK_Deinit() process, failure here 
 *	will issue a failure in BLESTCK_Deinit()
 *
 * @todo implement this function
 *
 * @see BLESTCK_Deinit()
 *
 * @return The status of the operation:
 *	- BLESTATUS_SUCCESS indicates to the BLE stack that the UART have been
 *		successfully initialized
 *	- BLESTATUS_FAILED indicates to the BLE stack that the UART could not be
 *		initialized
 *	
 * @author Alexandre GIMARD
 */
BleStatus BLEUART_Deinit(void){
	// Add here specific code to execute during Stack De-Initialisation
	// in order to de-initialise the transport drivers
	//>
	/*close spi interface*/
    if(MQX_OK != fclose(spi_dev))
    {
    #ifdef LOCAL_LOG
        SYSTEM_Log("Unable to close communication channel\n");
    #endif        
        return BLESTATUS_FAILED;
    }
    /*power off em9301 from 74HC595*/
    if(MQX_OK != mux_74hc595_clear_bit(BSP_74HC595_0, BSP_74HC595_VBLE_3V3))
    {
    	return BLESTATUS_FAILED;
    }
    /*disable pin IRQ, destroy spi read task, semaphore*/
    _bsp_int_disable(lwgpio_int_get_vector(&SPI_IRQ_PIN));
    _int_install_isr(lwgpio_int_get_vector(&SPI_IRQ_PIN), _int_get_default_isr(), NULL);
    if(MQX_OK != _task_destroy(_task_get_id_from_name("SPI_READ")))
    {
    	return BLESTATUS_FAILED;
    }

    if(MQX_OK != _lwsem_destroy(&IRQ_SEM))
    {
    	return BLESTATUS_FAILED;
    }
    	//<
	return BLESTATUS_SUCCESS;
}
/*FUNCTION****************************************************************
*
* Function Name    : _dspi_dma_deinit
* Returned Value   : MQX error code
* Comments         :
*    This function de-initializes the SPI module
*
*END*********************************************************************/
static _mqx_int _dspi_dma_deinit
    (
        /* [IN] the address of the device specific information */
        void                          *io_info_ptr
    )
{
    DSPI_DMA_INFO_STRUCT_PTR           dspi_info_ptr = (DSPI_DMA_INFO_STRUCT_PTR)io_info_ptr;

    if (NULL == dspi_info_ptr)
    {
        return SPI_ERROR_DEINIT_FAILED;
    }

    /* Release DMA channels */
    dma_channel_release(dspi_info_ptr->DMA_RX_CHANNEL);
    dma_channel_release(dspi_info_ptr->DMA_TX_CHANNEL);

    /* Free buffers */
    if (dspi_info_ptr->RX_BUF) {
        _mem_free(dspi_info_ptr->RX_BUF);
    }

    _lwsem_destroy(&dspi_info_ptr->EVENT_IO_FINISHED);

    _dspi_deinit_low(dspi_info_ptr->DSPI_PTR);

    _mem_free(dspi_info_ptr);

    return SPI_OK;
}
示例#9
0
/*FUNCTION****************************************************************
*
* Function Name    : _dspi_deinit
* Returned Value   : MQX error code
* Comments         :
*    This function de-initializes the SPI module
*
*END*********************************************************************/
static _mqx_int _dspi_deinit
    (
        /* [IN] the address of the device specific information */
        void                          *io_info_ptr
    )
{
    DSPI_INFO_STRUCT_PTR               dspi_info_ptr = (DSPI_INFO_STRUCT_PTR)io_info_ptr;

    const uint32_t                     *vectors;
    int                                num_vectors;
    int                                i;

    if (NULL == dspi_info_ptr)
    {
        return SPI_ERROR_DEINIT_FAILED;
    }

    _dspi_deinit_low(dspi_info_ptr->DSPI_PTR);

    /* Uninstall interrupt service routines */
    num_vectors = _bsp_get_dspi_vectors(dspi_info_ptr->CHANNEL, &vectors);

    for (i=0; i<num_vectors; i++)
    {
        /* Disable interrupt on vector */
        _bsp_int_disable(vectors[i]);
        /* Install default isr routine */
        _int_install_isr(vectors[i], _int_get_default_isr(), NULL);
    }

    _lwsem_destroy(&dspi_info_ptr->EVENT_IO_FINISHED);

    _mem_free(dspi_info_ptr);
    return SPI_OK;
}
示例#10
0
文件: io_pcb2.c 项目: gxliu/MQX_3.8.0
_mqx_uint _io_pcb_destroy_pool
   (
      /* The PCB pool to destroy */
      _io_pcb_pool_id pool
   )
{ /* Body */
   KERNEL_DATA_STRUCT_PTR kernel_data;
   IO_PCB_POOL_STRUCT_PTR pool_ptr = IO_PCB_GET_POOL_PTR(pool);
   _mqx_uint              result;
   
#if MQX_CHECK_VALIDITY
   if (pool_ptr->VALID != IO_PCB_VALID) {
      return(IO_PCB_POOL_INVALID);
   }/* Endif */
#endif

   pool_ptr->VALID = 0;
  
   result = _partition_destroy(pool_ptr->PARTITION);
   if (result != MQX_OK ) {
      return(result);
   }/* Endif */

  _lwsem_destroy(&pool_ptr->PCB_LWSEM);
   _GET_KERNEL_DATA(kernel_data);
  _queue_unlink((QUEUE_STRUCT_PTR)(&kernel_data->IO_PCB_POOLS), 
     &pool_ptr->QUEUE);
  return(_mem_free(pool_ptr));

} /* Endbody */
示例#11
0
文件: spi.c 项目: BillyZhangZ/wifi
/*FUNCTION****************************************************************
*
* Function Name    : _io_spi_uninstall
* Returned Value   : MQX error code
* Comments         :
*    Uninstalls SPI device.
*
*END**********************************************************************/
static _mqx_int _io_spi_uninstall
    (
        /* [IN] The IO device structure for the device */
        IO_DEVICE_STRUCT_PTR           io_dev_ptr
    )
{
    SPI_DRIVER_DATA_STRUCT_PTR driver_data;

    _mqx_int error_code = MQX_OK;

    driver_data = (SPI_DRIVER_DATA_STRUCT_PTR)(io_dev_ptr->DRIVER_INIT_PTR);

    /* deinitialize low level driver */
    if (driver_data->DEVIF->DEINIT)
        error_code = driver_data->DEVIF->DEINIT(driver_data->DEVIF_DATA);

    if (error_code != MQX_OK)
    {
        return error_code;
    }

    _lwsem_destroy(&driver_data->BUS_LOCK);
    _mem_free(driver_data);

    return MQX_OK;
}
示例#12
0
文件: sh_ppp.c 项目: zhouglu/K60F120M
/*FUNCTION*------------------------------------------------
*
* Function Name: shell_ppp_stop
* Comments     : Shell command "ppp stop" is calling this function to stop PPP connection.
*
*END*-----------------------------------------------------*/
int_32 shell_ppp_stop(SHELL_PPP_LINK_PTR local_ppp)
{
    uint_32           error;

   /* Check if PPP is alive. */
    if(!local_ppp->PPP_HANDLE)
    {
      printf("Can not stop PPP.It is not started\n");
    }
   /* Cleanup PPP connection. */

   /* Unbind interface. */
    error = RTCS_if_unbind(local_ppp->PPP_IF_HANDLE, IPCP_get_local_addr(local_ppp->PPP_IF_HANDLE));
    if(default_ppp.PPP_HANDLE)
    {
       /* Send connection terminate request to remote server and close PPP connection. */
        error = PPP_close(local_ppp->PPP_HANDLE);

       /* Clean up all PPP structure. */
        error = PPP_shutdown(local_ppp->PPP_HANDLE);
        local_ppp->PPP_HANDLE =NULL;
    }
   /* Destroing the semafor. */
    error = _lwsem_destroy(&local_ppp->PPP_SEM);
    if(local_ppp->PPP_IF_HANDLE)
    {
       /* Unregister PPP interface. */
        error = RTCS_if_remove(local_ppp->PPP_IF_HANDLE);
        local_ppp->PPP_IF_HANDLE=0;
    }
    if(local_ppp->PPP_IO_DRIVER_HANDLE)
    {
       /* Closing PPP driver. */
        error = _iopcb_close(local_ppp->PPP_IO_DRIVER_HANDLE);
    }
    if(local_ppp->PPP_DEV_HANDLE)
    {
        /* Close PPP driver. */
         error = fclose(default_ppp.PPP_DEV_HANDLE);
    }
    if(local_ppp->PPP_CON_DEV_HANDLE)
    {
       /* Close Close PPP_DEVICE. */
        error = fclose(default_ppp.PPP_CON_DEV_HANDLE);
    }
    local_ppp->PPP_HANDLE = NULL;
   /* We need remove route. */
    RTCS_gate_remove(local_ppp->PPP_GATE_ADDR, INADDR_ANY, INADDR_ANY);
    if(error)
    {
      printf("\nSome error happend during closing PPP connection.\n");
      return RTCS_ERROR;
    }
    else
    {
      printf("PPP connection closed\n");
      return RTCS_OK;
    }
}
示例#13
0
uint32_t OS_Sem_destroy(os_sem_handle sem)
{
    uint32_t result = _lwsem_destroy((LWSEM_STRUCT_PTR)sem);
    _mem_free(sem);
    if (result == MQX_OK)
    {
        return (uint32_t)OS_SEM_OK;
    }
    else
    {
        return (uint32_t)OS_SEM_ERROR;
    }
}
示例#14
0
_mqx_int _io_dun_close
   (
      /* [IN] the file handle for the device being closed */
      MQX_FILE_PTR fd_ptr
   )
{ /* Body */
   IODUN_STRUCT_PTR ras_ptr = fd_ptr->DEV_DATA_PTR;

   _lwsem_destroy(&ras_ptr->LWSEM);
   _mem_free(ras_ptr);

   return(MQX_OK);

} /* Endbody */
示例#15
0
/*
 * Close sockets, release memory, etc.
 */
int32_t ftpsrv_destroy_server(FTPSRV_STRUCT* server)
{
    uint32_t n = 0;
    bool wait = FALSE;

    if (server->sock_v4)
    {
        closesocket(server->sock_v4);
    }
    if (server->sock_v6)
    {
        closesocket(server->sock_v6);
    }
    /* Invalidate sessions (this is signal for session tasks to end them) */
    while(n < server->params.max_ses)
    {
        if (server->session[n])
        {
            server->session[n]->connected = FALSE;
        }
        n++;
    }
    /* Wait until all session tasks end */
    do
    {
        wait = FALSE;
        for (n = 0; n < server->params.max_ses; n++)
        {
            if (server->ses_tid[n])
            {
                wait = TRUE;
            }
        }
        _sched_yield();
    }while(wait);

    _lwsem_destroy(&server->tid_sem);
    
    /* Free memory */
    _mem_free(server->ses_tid);
    server->ses_tid = NULL;
    _mem_free(server->session);
    server->session = NULL;
    if (server->params.root_dir)
    {
        _mem_free(server->params.root_dir);
    }
    return(RTCS_OK);
}
uint32_t _ki2c_int_deinit
   (
      /* [IN] the initialization information for the device being opened */
      IO_I2C_INT_DEVICE_STRUCT_PTR int_io_dev_ptr,

      /* [IN] the address of the device specific information */
      VKI2C_INFO_STRUCT_PTR        io_info_ptr
   )
{ /* Body */
   I2C_MemMapPtr                   i2c_ptr;
      
   if ((NULL == io_info_ptr) || (NULL == int_io_dev_ptr)) 
   {
      return I2C_ERROR_INVALID_PARAMETER;
   }

   i2c_ptr = io_info_ptr->I2C_PTR;
   if (i2c_ptr->S & I2C_S_BUSY_MASK) 
   {
      return I2C_ERROR_DEVICE_BUSY;
   }

#if BSPCFG_ENABLE_LEGACY_II2C_SLAVE
   /* Disable Stop detection */
   _bsp_int_disable(io_info_ptr->PORT_VECTOR);
   
   /* Install original vectors */
   _int_install_isr(io_info_ptr->PORT_VECTOR, io_info_ptr->OLD_PORT_ISR, io_info_ptr->OLD_PORT_ISR_DATA);
#endif
   
   /* Disable the I2C */
   i2c_ptr->C1 = 0x00;

   /* Clear the I2C events */
   i2c_ptr->S = 0xFF; 
 
   /* Install original vectors */
   _int_install_isr (io_info_ptr->VECTOR, io_info_ptr->OLD_ISR, io_info_ptr->OLD_ISR_DATA);
   
   _lwsem_destroy((LWSEM_STRUCT_PTR)(&(io_info_ptr->LWSEM)));
   
   /* Free info struct */
   _mem_free (int_io_dev_ptr->DEV_INFO_PTR);
   int_io_dev_ptr->DEV_INFO_PTR = NULL;

   return I2C_OK;
} /* Endbody */
示例#17
0
_mqx_int _io_mem_uninstall
    (
        /* [IN] The devices context */
        IO_DEVICE_STRUCT_PTR  io_dev_ptr
    )
{
    IO_MEM_STRUCT_PTR     handle_ptr = (IO_MEM_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR;

    _lwsem_destroy(&handle_ptr->LWSEM);

    if (handle_ptr->TYPE == MEM_TYPE_DYNAMIC) {
        _mem_free(handle_ptr->BASE_ADDR);
    }
    _mem_free(handle_ptr);

    return(MQX_OK);
}
示例#18
0
/*!
 * \brief Deallocates drive context structure.
 *
 * \param drive_ptr
 *
 * \return _mfs_error
 */
_mfs_error MFS_Destroy_drive(
    MFS_DRIVE_STRUCT_PTR drive_ptr)
{
    if (drive_ptr->DEV_OPEN)
    {
        return MFS_SHARING_VIOLATION;
    }

#if MFSCFG_USE_MUTEX
    _mutex_destroy(&drive_ptr->MUTEX);
#else
    _lwsem_destroy(&drive_ptr->LWSEM);
#endif

    MFS_mem_free(drive_ptr);

    return MFS_NO_ERROR;
}
示例#19
0
_mqx_int _io_sai_dma_uninstall
(
    /* [IN] The IO device structure for the device */
    IO_DEVICE_STRUCT_PTR    io_dev_ptr
)
{ /* Body */
    IO_SAI_DEVICE_STRUCT_PTR io_sai_dev_ptr = io_dev_ptr->DRIVER_INIT_PTR;

    if ((io_sai_dev_ptr->READ_COUNT == 0) && (io_sai_dev_ptr->WRITE_COUNT == 0))
    {
        _lwsem_destroy(&io_sai_dev_ptr->LWSEM);
        _mem_free (io_sai_dev_ptr);
        io_dev_ptr->DRIVER_INIT_PTR = NULL;
        return IO_OK;
    } else {
        return IO_ERROR_DEVICE_BUSY;
    }
} /* Endbody */
示例#20
0
文件: name.c 项目: afbcom/ceng455
/*!
 * \cond DOXYGEN_PRIVATE
 * \private
 * 
 * \brief This function completely removes the specified name table.
 * 
 * \param[in] name_handle The name data structure pointer.
 * 
 * \return MQX_OK
 * \return MQX_COMPONENT_DOES_NOT_EXIST (Name component is not created.)
 * \return MQX_INVALID_COMPONENT_BASE (Name component data is not valid.)
 */ 
_mqx_uint _name_destroy_handle_internal
(
    void   *name_handle
)
{ /* Body */
    register NAME_COMPONENT_STRUCT_PTR name_manager_ptr;
    register NAME_COMPONENT_STRUCT_PTR next_ptr;

    name_manager_ptr = (NAME_COMPONENT_STRUCT_PTR) name_handle;
#if MQX_CHECK_ERRORS
    if (name_manager_ptr == NULL)
    {
        return (MQX_COMPONENT_DOES_NOT_EXIST);
    } /* Endif */
#endif /* MQX_CHECK_ERRORS */

    _int_disable();
#if MQX_CHECK_VALIDITY
    if (name_manager_ptr->VALID != NAME_VALID)
    {
        _int_enable();
        return (MQX_INVALID_COMPONENT_BASE);
    } /* Endif */
#endif /* MQX_CHECK_VALIDITY */
    _lwsem_wait((LWSEM_STRUCT_PTR) (&name_manager_ptr->SEM));
    name_manager_ptr->VALID = 0;
    _int_enable();

    _lwsem_destroy((LWSEM_STRUCT_PTR) (&name_manager_ptr->SEM));

    while (name_manager_ptr)
    {
        next_ptr = name_manager_ptr->NEXT_TABLE;
        name_manager_ptr->VALID = 0;
        _mem_free(name_manager_ptr);
        name_manager_ptr = next_ptr;
    } /* Endwhile */

    return (MQX_OK);

} /* Endbody */
示例#21
0
_mqx_int _io_serial_int_uninstall
   (
      /* [IN] The IO device structure for the device */
      IO_DEVICE_STRUCT_PTR   io_dev_ptr
   )
{ /* Body */
   IO_SERIAL_INT_DEVICE_STRUCT_PTR int_dev_ptr = io_dev_ptr->DRIVER_INIT_PTR;

   if (int_dev_ptr->COUNT == 0) {
      if (int_dev_ptr->DEV_DEINIT) {

#if MQX_ENABLE_LOW_POWER          
         _lwsem_wait (&(int_dev_ptr->LPM_INFO.LOCK));
#endif
         (*int_dev_ptr->DEV_DEINIT)(int_dev_ptr->DEV_INIT_DATA_PTR,
            int_dev_ptr->DEV_INFO_PTR);
#if MQX_ENABLE_LOW_POWER          
         _lwsem_post (&(int_dev_ptr->LPM_INFO.LOCK));
#endif
          
      } /* Endif */
      _mem_free(int_dev_ptr->IN_QUEUE);
      _mem_free(int_dev_ptr->OUT_QUEUE);
      _taskq_destroy(int_dev_ptr->IN_WAITING_TASKS);
      _taskq_destroy(int_dev_ptr->OUT_WAITING_TASKS);
      
#if MQX_ENABLE_LOW_POWER
      _lpm_unregister_driver (int_dev_ptr->LPM_INFO.REGISTRATION_HANDLE);
      _lwsem_destroy (&(int_dev_ptr->LPM_INFO.LOCK));
#endif
      
      _mem_free(int_dev_ptr);
      return(IO_OK);
   } else {
      return(IO_ERROR_DEVICE_BUSY);
   } /* Endif */

} /* Endbody */
示例#22
0
void ftpsrv_server_task(void* init_ptr, void* creator)
{
    FTPSRV_STRUCT* server = (FTPSRV_STRUCT*) init_ptr;
    _mqx_uint      res;

    /* Task init start */
    if (server == NULL)
    {
        RTCS_task_resume_creator(creator, (uint32_t)RTCS_ERROR);
    }

    server->server_tid = _task_get_id();

    res = _lwsem_create(&server->ses_cnt, server->params.max_ses);
    if (res != MQX_OK)
    {
        server->server_tid = 0;
        RTCS_task_resume_creator(creator, (uint32_t)RTCS_ERROR);
    }

    RTCS_task_resume_creator(creator, RTCS_OK);
    /* Task init end */

    while (server->run)
    {
        uint32_t  conn_sock = 0;
        uint32_t  new_sock = 0;
    
        _lwsem_wait(&server->ses_cnt);

        while (!conn_sock && server->run)
        {
            conn_sock = RTCS_selectset(&(server->sock_v4), 2, 250);
        }

        if (server->run)
        {
            unsigned short length = 0;
            struct sockaddr remote_addr;

            new_sock = accept(conn_sock, (sockaddr*) &remote_addr, &length);
        }
        else
        {
            break;
        }

        if (new_sock != RTCS_SOCKET_ERROR)
        {
            FTPSRV_SESSION_PARAM ses_param;

            ses_param.sock = new_sock;
            ses_param.server = server;

            /* Try to create task for session */
            res = RTCS_task_create("ftpsrv session", server->params.server_prio, FTPSRV_SESSION_STACK_SIZE, ftpsrv_session_task, &ses_param);
            if (MQX_OK != res)
            {
                shutdown(new_sock, FLAG_ABORT_CONNECTION);
                _lwsem_post(&server->ses_cnt);
            }
        }
        else
        {
            _lwsem_post(&server->ses_cnt);
            /* We probably run out of sockets. Wait some arbitrary
             * time and then try again to prevent session tasks resource starvation.
             */
            _time_delay(150);
        }
    }
    _lwsem_destroy(&server->ses_cnt);
    server->server_tid = 0;
} 
示例#23
0
文件: sh_ppp.c 项目: zhouglu/K60F120M
/*FUNCTION*------------------------------------------------
*
* Function Name: Shell_ppp
* Comments     : Shell command "ppp" is starting or stopping PPP connection.
*
*END*-----------------------------------------------------*/
int_32 Shell_ppp(int_32 argc, char_ptr argv[] )
{
    uint_32           error;
    uint_32           i=1;
    boolean           print_usage, shorthelp = FALSE;

   default_ppp.LOCAL_NAME     = NULL;
   default_ppp.LOCAL_PASSWORD = NULL;

   /* Check for help. */
    print_usage = Shell_check_help_request(argc, argv, &shorthelp );
    if (!print_usage)
    {
        if (argc >= 2)
        {  /* If we have more args, we need parce them. */
            while(i<argc)
            {
                switch (i)
                {
                    case (1):
                        /* If "stop" start shell_ppp_stop. */
                        if( strcmp(argv[i],"stop")==0)
                        {
                            return(shell_ppp_stop(&default_ppp));
                        }
                        else if(strcmp(argv[i],"client")==0)
                        {
                            default_ppp.SERVER_FLAG=0;
                        }
                        else if(strcmp(argv[i],"server")==0)
                        {
                            default_ppp.SERVER_FLAG=1;
                            /* In case of "server" we need have min 7 arg : ppp server ittyX: rlogin rpassword boardip clientip */
                            if(argc <=6)
                            {
                                print_usage = TRUE;
                            }
                        }
                        else
                        {
                            print_usage = TRUE;
                        }
                        break;
                    case (2):
                        if( strstr(argv[i],"itty") !=0)
                        {
                            default_ppp.PPP_CONNECTION_DEVICE = argv[i];
                        }
                         else
                        {
                            printf("Incorrect ittyX: device name.\n");
                            print_usage = TRUE;
                        }
                        break;
                    case (3):
                        if(default_ppp.SERVER_FLAG==0)
                        {
                            default_ppp.LOCAL_NAME = argv[i];
                        }
                        else
                        {
                            default_ppp.REMOTE_NAME = argv[i];
                        }
                        break;
                    case (4):
                        if(default_ppp.SERVER_FLAG==0)
                        {
                            default_ppp.LOCAL_PASSWORD = argv[i];
                        }
                        else
                        {
                            default_ppp.REMOTE_PASSWORD = argv[i];
                        }
                        break;
                    case (5):
                        if(default_ppp.SERVER_FLAG==1)
                        {  /* It is valid only for server mode.*/
                          if( inet_pton(AF_INET, argv[i],&default_ppp.PPP_LOCAL_ADDRESS,sizeof(default_ppp.PPP_LOCAL_ADDRESS)) == (uint_32)RTCS_ERROR)
                            {
                                print_usage = TRUE;
                            }
                        }
                        else
                        {
                            print_usage = TRUE;
                        }
                        break;
                    case (6):
                        if(default_ppp.SERVER_FLAG==1)
                        {  /* It is valid only for server mode.*/
                            if( inet_pton(AF_INET, argv[i],&default_ppp.PPP_REMOTE_ADDRESS,sizeof(default_ppp.PPP_REMOTE_ADDRESS)) ==(uint_32)RTCS_ERROR)
                            {
                                print_usage = TRUE;
                            }
                        }
                        else
                        {
                            print_usage = TRUE;
                        }
                        break;
                    default:
                        error = 0;
                        break;
                }
                i++;
            }
        }
        else
        {
            print_usage = TRUE;
        }
    }

    if (print_usage)
    {
        if (shorthelp)
        {
            printf(" %s - Start PPP connection. \n", argv[0]);
            return RTCS_OK;
        }
        else
        {
            printf(" Usage: %s\n", argv[0]);
            printf(" [param] [device name] [login] [password] [localIPaddress ] [remoteIPaddress]\n");
            printf(" [param]           - is \"server\", \"client\" \"stop\"\n");
            printf(" [device name]     - is system name of interrupting device,\n");
            printf("                     suitable for your board, like  ittyX: \n");
            printf(" [login] and\n");
            printf(" [password]        - is \"login\" and \"password\" for PPP PAP.\n");
            printf("                     For \"server\" login and pass should be defined. \n");
            printf("                     For \"server\" and \"client\" the device name is requered.\n");
            printf(" [localIPaddress]  - is IP addres of your board(server mode).\n");
            printf(" [remoteIPaddress] - is IP addres for  client of your board(server mode).\n");
            printf("\n Examples:\n");
            printf("    To start PPP client using \"ittyd:\" you need type:\n");
            printf("        shell> ppp client ittyd: \n");
            printf("    or using PPP PAP client:\n");
            printf("        shell> ppp client ittyd: yourlogin yourpassword \n");
            printf("\n    To start PPP PAP server using \"ittyd:\":\n");
            printf("        shell> ppp server ittyd: yrlog yrpass brd_ip_addr cl_ip_addr\n");
            printf("        shell> ppp server ittyd: guest anon 192.168.0.1 192.168.0.217\n");
            printf("\n    To stop PPP connection you need type \"ppp stop\":\n");
            printf("        shell> ppp stop\n\n");
            return RTCS_OK;
        }
    }
   /* Check if PPP already started. */
    if(default_ppp.PPP_HANDLE)
    {
        printf("\n PPP already started. Stop it first.\n");
        return RTCS_OK;
    }
   /* Start connection:   */
   /* Open serial device. */
    default_ppp.PPP_CON_DEV_HANDLE = fopen(default_ppp.PPP_CONNECTION_DEVICE, NULL);

   /* Open suitable ppp device. */
    if(default_ppp.SERVER_FLAG==0)
    {
        /* Open PPP like client. */
        default_ppp.PPP_DEV_HANDLE = fopen("dcn:", (char_ptr)default_ppp.PPP_CON_DEV_HANDLE);
        /* Checking, does it open ? */
        if(default_ppp.PPP_DEV_HANDLE == NULL)
        {
            if(default_ppp.PPP_CON_DEV_HANDLE)
            {
                /* Close PPP_DEVICE. */
                fclose(default_ppp.PPP_CON_DEV_HANDLE);
            }
            printf("\n ERROR: Can not open \"dcn\" PPP driver.\n");
            return RTCS_ERROR;
        }
    }
    else
    {
        /* Open PPP like server. */
        default_ppp.PPP_DEV_HANDLE = fopen("dun:", (char_ptr)default_ppp.PPP_CON_DEV_HANDLE);
        /* Checking, does it open ? */
        if(default_ppp.PPP_DEV_HANDLE == NULL)
        {
            /* Checking, was driver installed or not. */
            if(default_ppp.PPP_CON_DEV_HANDLE)
            {
                /* Close Close PPP_DEVICE. */
                fclose(default_ppp.PPP_CON_DEV_HANDLE);
            }
            printf("\n ERROR: Can not open \"dun\" PPP driver.\n");
            return RTCS_ERROR;
        }
    }

    if(default_ppp.SERVER_FLAG==0)
    {
       /* Send invitation string to Windows PPP server. */
        _io_fputs("CLIENTCLIENT", default_ppp.PPP_DEV_HANDLE);
        fflush(default_ppp.PPP_DEV_HANDLE);
       /* Start connection procedure. */
        default_ppp.PPP_GATE_ADDR = IPADDR(192,168,0,1);
    }
    else
    {
        default_ppp.PPP_GATE_ADDR = default_ppp.PPP_LOCAL_ADDRESS;
        /* Fill  rsecrets[] array here. */
         default_ppp.rsecrets[0].PPP_ID_LENGTH = strlen(default_ppp.REMOTE_NAME);
         default_ppp.rsecrets[0].PPP_PW_LENGTH = strlen(default_ppp.REMOTE_PASSWORD);
         default_ppp.rsecrets[0].PPP_ID_PTR    = default_ppp.REMOTE_NAME;
         default_ppp.rsecrets[0].PPP_PW_PTR    = default_ppp.REMOTE_PASSWORD;
         default_ppp.rsecrets[1].PPP_ID_LENGTH = 0;
         default_ppp.rsecrets[1].PPP_PW_LENGTH = 0;
         default_ppp.rsecrets[1].PPP_ID_PTR    = NULL;
         default_ppp.rsecrets[1].PPP_PW_PTR    = NULL;
    }

    shell_ppp_start(&default_ppp);
    /* shell_ppp_start() must get PPP_HANDLE */
    if(default_ppp.PPP_HANDLE)
    {
        return RTCS_OK;
    }
    else
    {  /* Remove all created elements. */
        printf("\n Error: The connection attemp failed because the modem (or other connecting device) on the remote computer is out of order \n");
        /* Destroy semafor. */
        error = _lwsem_destroy(&default_ppp.PPP_SEM);
        if(default_ppp.PPP_IF_HANDLE)
        {
           /* Unregister PPP interface. */
            error = RTCS_if_remove(default_ppp.PPP_IF_HANDLE);
        }
        if(default_ppp.PPP_IO_DRIVER_HANDLE)
        {
           /* Close PPP driver. */
            error = _iopcb_close(default_ppp.PPP_IO_DRIVER_HANDLE);
        }
        if(default_ppp.PPP_DEV_HANDLE)
        {
            /* Close PPP driver. */
            error = fclose(default_ppp.PPP_DEV_HANDLE);
        }
        if(default_ppp.PPP_CON_DEV_HANDLE)
        {
            /* Close Close PPP_DEVICE. */
            error = fclose(default_ppp.PPP_CON_DEV_HANDLE);
        }
        if(error)
        {
          printf("\nSome error happend during closing PPP connection.\n");
        }
        else
        {
          printf("\nPPP connection closed.\n");
        }
        return RTCS_ERROR;
    }
}
示例#24
0
void local_player_task(uint_32 para) 
{
	_mqx_int return_code, res;
	my_audio_format_t format;
	FILE_PTR stream_ptr = NULL, stream_ptr1 = NULL;      //device_ptr = NULL, 
	uint_32 mclk_freq, fs_freq, bit_width = 0;
	I2S_STATISTICS_STRUCT stats;
	int32_t numberOfSamples =0, sampleProduced, bufOut;
	file_meta_data_t * metadata = NULL;
	audio_stream_type_t stream_type;
	char_ptr mem_ptr = NULL;
	boolean shell_cmd = FALSE;
        CCI_Ctx ctx;
	int32_t strLen, i;
	uint32_t file_extension=0;
	
	_task_id pcm_flush_id = MQX_NULL_TASK_ID;
	uint_32 cnt = 0;
	int32_t max_audio_buf_size = 0;
	lp_param_t *  lpp_param =  (lp_param_t *)para;
        TASK_TEMPLATE_STRUCT task_template;

	printf("local_player_task.. Enter 1\n");
	if (msi_snd_init_with_periodbuffer(1024, 18) != 0) /* for SPI sd card play FLAC, 18K buffer is at least! */
	{
		LOCALPLAY_LOG("  Error: Unable to open the device \"%s\".\n",
				AUDIO_DIVECE_NAME_STR);
		return;
	}
	
	/* create semaphore must before pcm_flush_task */
	if(MQX_OK != _lwsem_create(&pcm_decoded_sem, 0))
	{
		LOCALPLAY_LOG("\n Error - Unable to creat lwsem: pcm_decoded_sem\n");
	}
	
	
        LOCALPLAY_LOG("Creating pcm flush task.........\n");

        task_template.TASK_TEMPLATE_INDEX  = 0;
        task_template.TASK_ADDRESS         = pcm_flush_task;
        task_template.TASK_STACKSIZE       = 2000;
        task_template.TASK_PRIORITY        = 12;
        task_template.TASK_NAME            = "pcm_flush";
        task_template.TASK_ATTRIBUTES      = 0;
        task_template.CREATION_PARAMETER   = 0;
        task_template.DEFAULT_TIME_SLICE   = 0;

        pcm_flush_id = _task_create_blocked(0, 0, (uint_32)&task_template);

        if (pcm_flush_id  == MQX_NULL_TASK_ID)
        {
            printf("local_player_task create pcm_flush_task failed \n");
            goto clean_up;
        }
        else{
            gPcmFlushTaskFinish = 0;
            _task_ready(_task_get_td(pcm_flush_id));
            _lwevent_set(&player_event, PLAYER_EVENT_MSK_SONG_RESUME);
        }


	metadata = (file_meta_data_t *) _mem_alloc_system_zero(sizeof(file_meta_data_t));
	if (NULL == metadata) 
	{
		LOCALPLAY_LOG("\n Failed to allocate memory for metadata.\n");
		return;
	}

        decoding = TRUE;
	
	while (1) {

#ifndef  USB_ACCESSORY_PLAY		
		_lwevent_wait_ticks(
				&player_event,
				PLAYER_EVENT_MSK_SONG_READY | PLAYER_EVENT_MSK_SD_FS_UNMOUNTED
						| PLAYER_EVENT_MSK_SHELL_COMMAND, FALSE, 0);
#else
_lwevent_wait_ticks(
				&player_event,
				PLAYER_EVENT_MSK_SONG_READY | PLAYER_EVENT_MSK_SD_FS_UNMOUNTED
						| PLAYER_EVENT_MSK_SHELL_COMMAND | PLAYER_EVENT_MSK_USB_ATTACHED, FALSE, 0);		
#endif
		shell_cmd = FALSE;


#ifdef USB_ACCESSORY_PLAY
		if (player_event.VALUE & PLAYER_EVENT_MSK_USB_ATTACHED) {
					_lwevent_clear(&player_event, PLAYER_EVENT_MSK_USB_ATTACHED);
					//LOCALPLAY_LOG("__guoyifang__: sd_player_task PLAYER_EVENT_MSK_USB_ACC_ATTACHED \n");
					break;
				}
#endif

		if (player_event.VALUE & PLAYER_EVENT_MSK_SD_FS_UNMOUNTED) {
			_lwevent_clear(&player_event, PLAYER_EVENT_MSK_SD_FS_UNMOUNTED);
			//LOCALPLAY_LOG("__guoyifang__: sd_player_task PLAYER_EVENT_MSK_SD_FS_UNMOUNTED \n");
			break;
		}	

		if (player_event.VALUE & PLAYER_EVENT_MSK_SONG_READY) {
			_lwevent_clear(&player_event, PLAYER_EVENT_MSK_SONG_READY);
		}

		if (player_event.VALUE & PLAYER_EVENT_MSK_SHELL_COMMAND) {
			_lwevent_clear(&player_event, PLAYER_EVENT_MSK_SHELL_COMMAND);
			shell_cmd = TRUE;
		}

		LOCALPLAY_LOG(" --------------------------------------------------------------\n");

	    printf("play lock umount at %d\n",lpp_param->lp_type);
	    _lwsem_wait(lpp_param->mfs_io_sem);
	    /******************decoding is a critical value, assume decoding is TRUE every time.*******************/    
	    printf("SET decoding.\n");
	    decoding = TRUE; // next/prev btn ISR may clear decoding to 0
	    /*******************************************/
		/*config the audio subsystem according metadata*/
		        		printf(
		        				"  Open stream file %s\n", full_path);
		        		stream_ptr = fopen(full_path, "r");
		        		if (stream_ptr == NULL) {
		        			printf("  Unable to open the file: %s\n", full_path);
		        			goto clean_up;
		        		}

		        		stream_ptr1 = fopen(full_path, "r");
		        		if (stream_ptr1 == NULL) {
		        			printf("  Unable to open the file: %s\n", full_path);
		        			goto clean_up;
		        		}
		        		
		                /* Determine the extension of the file */ 
		                i=0;
		                strLen= strlen((const char *)full_path);

		                if(strLen > 4){
		                    /* find the '.' */
		                    while(strLen--){
		                        if(full_path[i]=='.')
		                            break;
		                        i++;
		                    }
		                    if(strLen){
		                        char *p;
		                        /* Copy out the extension : 8.3 filename */
		                        memcpy(&file_extension, full_path+i+1, 3);
		                        p = (char *) (&file_extension);
		                        for(i = 0; i < 4; i++, p++){
		                            if((*p >= 'a') && (*p <= 'z')){
		                                *p -= ('a' - 'A');
		                            }
		                        }
		                    } 

		                    ctx.user_data = (void*) stream_ptr;
		                    ctx.cci_dec_read = get_file_data;;
		                    ctx.cci_dec_seek = seek_file_data;
		                    ctx.cci_dec_tell = get_file_position;

		                    /* Check if metadata was found. */
		                    return_code = cci_extract_meta_data(file_extension, metadata, &ctx);        
		        		    if (return_code != 0) {
		        			    printf("\n Metadata not found\n");
		        			    goto clean_up;
		        		    }

		        		    print_metadata(metadata); //todo

		                } else {
		        			printf("\n Metadata not found\n");
		        			goto clean_up;
		                }
		                if ( metadata->stream_type == STREAM_TYPE_MP3 ) {
		                	/* Seek from the beginning of the file */ 
		                    seek_file_data(0, metadata->start_pos, 0, stream_ptr);
		                } else {
		                	/* Seek from the beginning of the file */
		                	seek_file_data(0, 0, 0, stream_ptr);
		        		}
		        
		        
		        stream_type = metadata->stream_type;

#if 0	
		format.audio_format.ENDIAN = AUDIO_LITTLE_ENDIAN;
		format.audio_format.ALIGNMENT = AUDIO_ALIGNMENT_LEFT;
		if((streamType == kCodecStreamTypePcm) ||	// bitsPerSample Value is 8/16/24
				/*
				 * The demo not support kCodecStreamTypeImaAdpcm/kCodecStreamTypeMsAdpcm currently.
				 */
				(streamType == kCodecStreamTypeImaAdpcm) || // bitsPerSample Value is 4
				(streamType == kCodecStreamTypeMsAdpcm))	// bitsPerSample Value is 4
		{	
			format.audio_format.BITS = metadata->i32BitsPerSample;
		}else{
			format.audio_format.BITS = 16; 
		}
		
		// Currently, the wave decoder output 16bits only for kCodecStreamTypePcm.
		format.audio_format.BITS = 16;
		
		format.audio_format.SIZE = (format.audio_format.BITS + 7)/8;

		
		format.audio_format.CHANNELS = metadata->i32NumChannels;
		format.fs_freq = metadata->u32SampleRate;

		fs_freq = format.fs_freq;
		mclk_freq = fs_freq * CLK_MULT;
		// Setup audio data format in device 
		if (ioctl(device_ptr, IO_IOCTL_AUDIO_SET_IO_DATA_FORMAT,
				&format.audio_format) != I2S_OK) {
			LOCALPLAY_LOG("  Error: Input data format not supported.\n");
			goto clean_up;
		}
		// Setup rest of parameters - master clock, valid data bits and sampling frequency 
		if ((ioctl(device_ptr, IO_IOCTL_I2S_SET_MCLK_FREQ, &mclk_freq) != I2S_OK)
				|| (ioctl(device_ptr, IO_IOCTL_I2S_SET_DATA_BITS,
						&format.audio_format.BITS) != I2S_OK)
				|| (ioctl(device_ptr, IO_IOCTL_I2S_SET_FS_FREQ, &fs_freq)
						!= I2S_OK)) {
			LOCALPLAY_LOG("  Error: Unable to setup \"%s\" device driver.\n",
					AUDIO_DIVECE_NAME_STR);
			goto clean_up;
		}

		// Setup audio codec 
		return_code = SetupCodec(device_ptr);
		if (return_code != 0) {
			LOCALPLAY_LOG("  Audio codec configuration failed. Error 0x%X.\n",
					return_code);
			goto clean_up;
		}

		ioctl(device_ptr, IO_IOCTL_I2S_GET_FS_FREQ, &fs_freq);
		ioctl(device_ptr, IO_IOCTL_I2S_GET_DATA_BITS, &bit_width);
		LOCALPLAY_LOG("  Playback information\n");
		LOCALPLAY_LOG("  Sampling frequency:     %d Hz\n", fs_freq);
		LOCALPLAY_LOG("  Bit depth:              %d bits\n", (uint_8)bit_width);
		LOCALPLAY_LOG("  Channels:               ");
		
		if (format.audio_format.CHANNELS == 1) {
			LOCALPLAY_LOG("mono\n");
		} else {
			LOCALPLAY_LOG("stereo\n");
		}
#else
		if((stream_type == STREAM_TYPE_PCM) ||	// bitsPerSample Value is 8/16/24
		/*
		 * The demo not support kCodecStreamTypeImaAdpcm/kCodecStreamTypeMsAdpcm currently.
		 */
		(stream_type == STREAM_TYPE_IMAADPCM) || // bitsPerSample Value is 4
		(stream_type == STREAM_TYPE_MSADPCM))	// bitsPerSample Value is 4
		{	
			format.audio_format.BITS = metadata->bits_per_sample;
		}else{
			format.audio_format.BITS = 16; 
		}
		
		format.audio_format.CHANNELS = metadata->num_channels;
		// Currently, the wave decoder output 16bits only for kCodecStreamTypePcm.
		format.audio_format.BITS = 16;
#if 0
		if(audio_ioctl(setChNum, format.audio_format.CHANNELS)!= I2S_OK)
        {
		  LOCALPLAY_LOG("  Error: audio_ioctl setChNum failed.\n");
		  goto clean_up;
        }
		if(audio_ioctl(setBitWidth, format.audio_format.BITS)!= I2S_OK)
		{

		  LOCALPLAY_LOG("  Error: audio_ioctl setBitWidth failed.\n");
		  goto clean_up;
		}
#endif
		
		format.fs_freq = metadata->sample_rate;
		
#if 0
		if(audio_ioctl(setSamplerate, format.fs_freq)!= I2S_OK)
	    {
		  LOCALPLAY_LOG("  Error: audio_ioctl setSamplerate failed.\n");
		  goto clean_up;
	    }
#endif
		msi_snd_set_format(format.fs_freq, format.audio_format.BITS, format.audio_format.CHANNELS);
	

#endif

		mem_ptr = (char_ptr) _mem_alloc_system_zero(codec_get_mem_info(stream_type));
		if (NULL == mem_ptr) {
			LOCALPLAY_LOG("Failed to allocate memory for the decoder.\n");
			goto clean_up;
		}

		// MP4 decoder need two fd
		g_userData[0] = (int) stream_ptr;
		g_userData[1] = (int) stream_ptr1;
		if (metadata->audio_sub_type == MEDIA_SUBTYPE_ADTS)
			g_userData[2] = 1;
		else if (metadata->audio_sub_type == MEDIA_SUBTYPE_M4A)
			g_userData[2] = 2;
		else if ( metadata->stream_type == STREAM_TYPE_OPUS )
		{
			g_userData[2] = metadata->sample_rate;
			g_userData[3] = metadata->num_channels;
	    }
		else
			g_userData[2] = 0; 

		g_callbackFunctionArray[0] = (int32_t *) &get_file_data;
		g_callbackFunctionArray[1] = (int32_t *) &seek_file_data;
		g_callbackFunctionArray[2] = (int32_t *) &get_file_position;

		while (1) {
			res = codec_init(stream_type, (long **)&mem_ptr,g_callbackFunctionArray,
								&g_userData[0]);
			if (res == CODEC_INIT_ERROR) {
				LOCALPLAY_LOG("\n  Codec Init Failed with error code %d\n", res);
				decoding = FALSE; 
				goto clean_up;
			}
			if (res == CODEC_MORE_DATA_REQUIRED) {
				LOCALPLAY_LOG("\n  More Data Processing Required for Init \n");
			}
			if (res == CODEC_SUCCESS) {
				LOCALPLAY_LOG("\n  Codec Init Done Successfully \n\n");
				break;
			}
			else {
				printf("codec init other err\n");
				decoding = FALSE;
				goto clean_up;
			}
		}

		if (res == CODEC_SUCCESS) {
			LOCALPLAY_LOG("  Playing %s...\n\n", full_path);
		//	ioctl(device_ptr, IO_IOCTL_I2S_CLEAR_STATISTICS, NULL);
			/* Reset variables before every song's playbacking */
			
			//printf("SET decoding.\n");
			//decoding = TRUE; // next/prev btn ISR may clear decoding to 0
			cnt = 0;

			max_audio_buf_size = 0;
			g_audio_buf_ptr = NULL;
			//_lwevent_clear(&player_event, PLAYER_EVENT_MSK_AUDIO_BUF_FILLED);
			/* Clear pcm_decoded_sem for play next song */
			_lwsem_poll(&pcm_decoded_sem);
			_lwsem_poll(&pcm_decoded_sem);  
					
			if(MQX_OK != _lwsem_create(&pcm_flush_sem, AUDIO_BUF_CNT))
			{
				LOCALPLAY_LOG("\n Error - Unable to create lwsem: pcm_flush_sem\n");
			}
			
			/*
			 * umute
			 */
			msi_snd_umute();
			//sai_dma_output_init();
			
			while (decoding) {
				/*
				 * For FLAC decoder, it produced more than 18K bytes per frame, and takes about 30ms. 
				 * While take 44.1K/16bit/2ch/4Kbytes DMA buffer as example, the margin time is 4K/4/2/44100~=10ms. 
				 * We need bigger DMA buffer, or decode in a ping-pong way.
				 */		
				res = codec_decode(stream_type, (long **)&mem_ptr, &sampleProduced,
										&bufOut);
              
				if (res == CODEC_END_OF_DECODE) {					
					printf("\n  End of Decode \n");
					break;
				}
				else if (res == CODEC_DECODE_ERROR) {
					printf("\n  Codec Decode Failed \n");
					break;
				}
				else if(res != CODEC_SUCCESS){
					printf("codec_decode else err %d\n",res);
						break;
				}
				
				cnt += sampleProduced;
				
				while (decoding) 
				 {
					numberOfSamples = codec_get_pcm_samples(stream_type,
											(long **)&mem_ptr, &sampleProduced, &bufOut);
					if (numberOfSamples == 0)
						break;
					
#if 1
					if (max_audio_buf_size < sampleProduced) { //More bigger buffer needed
						max_audio_buf_size = sampleProduced;
						if (NULL != g_audio_buf_ptr) {
							LOCALPLAY_LOG(" Bigger buffer needed.\n");
							_mem_free(g_audio_buf_ptr);
						}
						g_audio_buf_ptr = (uchar_ptr) _mem_alloc_system_zero(max_audio_buf_size);
						if (NULL == g_audio_buf_ptr) {
							LOCALPLAY_LOG(" Failed to allocate g_audio_buf_ptr. max_audio_buf_size %d \n", max_audio_buf_size);
							decoding = 0;
							break;
						}	
#if 1
						//sai_dma_buffer_adjust(sampleProduced);			
#endif
					}
#endif
					
				    if (MQX_OK != _lwsem_wait(&pcm_flush_sem))
				    {
					  LOCALPLAY_LOG("\n Error: Wait for pcm_flush_sem failed.\n");
					 // _task_set_error(res);
				    }
				    
					_mem_copy((void *)bufOut, g_audio_buf_ptr, sampleProduced);
                                        //g_audio_buf_ptr = bufOut;
					g_buf_bytes_to_flush = sampleProduced;
		
					if (_lwsem_post(&pcm_decoded_sem) != MQX_OK)
					 {
					   LOCALPLAY_LOG("\n  pcm_flush : Error - Unable to set pcm_decoded_sem.");
					 }

					if (numberOfSamples == sampleProduced)
						sampleProduced = 0;
				 }//end while decoding
	 	  }//end while decoding
		}//end if res==kCodeSuccess
		
		#if 0
		fflush(device_ptr);
		#else
		msi_snd_mute();

                if (MQX_OK != _lwsem_wait(&pcm_flush_sem))
                    LOCALPLAY_LOG("\n Error: Wait for latest pcm_flush_sem failed.\n");
		msi_snd_flush();
		#endif
		
#if 1
		//sai_dma_output_stop();
#endif	
#if 0
		/* Print transfer statistics */
		if (ioctl(device_ptr, IO_IOCTL_I2S_GET_STATISTICS, &stats) != I2S_OK) {
			LOCALPLAY_LOG("  Error: Cannot read I2S statistics.\n");
		} else {
			LOCALPLAY_LOG("\n  Playback stats\n");
			LOCALPLAY_LOG("  Total interrupts:              %d\n", stats.INTERRUPTS);
			LOCALPLAY_LOG("  Bytes requested for transmit:  %d\n",
					stats.PACKETS_REQUESTED * format.audio_format.SIZE);
			LOCALPLAY_LOG("  Bytes transmitted:             %d\n",
					stats.TX_PACKETS * format.audio_format.SIZE);
			LOCALPLAY_LOG("  Underruns of hardware FIFO:    %d\n", stats.FIFO_ERROR);
			LOCALPLAY_LOG("  Software buffer empty:         %d\n", stats.BUFFER_ERROR);
		}
#endif
	        LOCALPLAY_LOG("\n  DONE\n");
			
		clean_up:
		printf("done to clean up,decoding %d \n",decoding);		
		/* Clean up for next song */
		if (NULL != mem_ptr) {
			_mem_free(mem_ptr);
			mem_ptr = NULL;
		}
		if (NULL != g_audio_buf_ptr) {
			_mem_free(g_audio_buf_ptr);
			g_audio_buf_ptr = NULL;
		}
		if (NULL != stream_ptr) {
			res = fclose(stream_ptr);
			if ((res != MQX_OK)&&(res != MFS_DISK_IS_WRITE_PROTECTED)) {
				/*LOCALPLAY_LOG*/printf("  Error: Unable to close file 0x%x.\n", res);
			}
			stream_ptr = NULL;
		}
		if (NULL != stream_ptr1) {
			res = fclose(stream_ptr1);
			if ((res != MQX_OK)&&(res != MFS_DISK_IS_WRITE_PROTECTED)) {
				/*LOCALPLAY_LOG*/printf("  Error: Unable to close file 0x%x.\n", res);
			}
			stream_ptr1 = NULL;
		}
		
		if(MQX_OK != _lwsem_destroy(&pcm_flush_sem))
		  {
			LOCALPLAY_LOG("\n Error - Unable to destroy lwsem: pcm_flush_sem\n");
		  }

		if (decoding == TRUE) { // playback finished in normal way, ie, next/prev not pressed
			if (!shell_cmd) { 	// and was not triggered by Shell
				// just like next btn being pressed
				_lwevent_set(&player_event, PLAYER_EVENT_MSK_NEXT_BTN_PRESSED);
			}
		}
		
	    /* if exit this task ,must route this point ! */
	    printf("play unlock umount at %d\n",lpp_param->lp_type);
	    _lwsem_post(lpp_param->mfs_io_sem);
	}//end while(1)
#if 0
	// clean up further
	if (NULL != device_ptr) {	
		if (fclose(device_ptr) != MQX_OK) {
			LOCALPLAY_LOG("  Error: Unable to close \"%s\" device driver.\n",
					full_path);
		}
	}
#else	
	msi_snd_deinit();
#endif
			
	if (NULL != metadata)
		_mem_free(metadata);	

	if (MQX_NULL_TASK_ID != pcm_flush_id)
	  {
            gPcmFlushTaskFinish = 1;
	    _lwsem_post(&pcm_decoded_sem);
            while(gPcmFlushTaskFinish == 1){
                _sched_yield();
            }

            //_task_destroy(pcm_flush_id);
	    pcm_flush_id = MQX_NULL_TASK_ID;
	    ///*LOCALPLAY_LOG*/printf(" pcm flush task destoryed \n");
	  }
	
	if(MQX_OK != _lwsem_destroy(&pcm_decoded_sem))
		  {
			LOCALPLAY_LOG("\n Error - Unable to destroy lwsem: pcm_decoded_sem\n");
		  }
	
  //printf("__guoyifang__: sd_player_task %d set PLAYER_TASK_KILLED.\n",lpp_param->lp_type);
  _lwevent_set(&player_event, PLAYER_EVENT_MSK_PLAYER_TASK_KILLED);
  
  printf("sd_player_task  exit.\n");
  //_task_block(); //wait for being destroyed
  
}
示例#25
0
文件: spi.c 项目: BillyZhangZ/wifi
/*FUNCTION****************************************************************
*
* Function Name    : _io_spi_install
* Returned Value   : MQX error code
* Comments         :
*    Installs SPI device.
*
*END**********************************************************************/
_mqx_int _io_spi_install
    (
        /* [IN] A string that identifies the device for fopen */
        char                       *identifier,

        /* [IN] Pointer to driver initialization data */
        SPI_INIT_STRUCT_CPTR           init_data_ptr
    )
{
    SPI_DRIVER_DATA_STRUCT_PTR driver_data;

    _mqx_int error_code = MQX_OK;

    if ((init_data_ptr->DEVIF->SETPARAM == NULL) || (init_data_ptr->DEVIF->TX_RX == NULL))
    {
        /* Missing mandatory low level driver function */
        return IO_ERROR_DEVICE_INVALID;
    }

    driver_data = (SPI_DRIVER_DATA_STRUCT_PTR)_mem_alloc_system_zero((_mem_size)sizeof(SPI_DRIVER_DATA_STRUCT));
    if (driver_data == NULL)
    {
        return MQX_OUT_OF_MEMORY;
    }
    _mem_set_type(driver_data, MEM_TYPE_IO_SPI_POLLED_DEVICE_STRUCT);

    driver_data->CS_CALLBACK = init_data_ptr->CS_CALLBACK;
    driver_data->CS_USERDATA= init_data_ptr->CS_USERDATA;
    driver_data->PARAMS = init_data_ptr->PARAMS;
    driver_data->DEVIF = init_data_ptr->DEVIF;

    /* initialize low level driver */
    if (driver_data->DEVIF->INIT)
        error_code = driver_data->DEVIF->INIT(init_data_ptr->DEVIF_INIT, &(driver_data->DEVIF_DATA));

    if (error_code != MQX_OK)
    {
        _mem_free(driver_data);
        return error_code;
    }

    _lwsem_create(&driver_data->BUS_LOCK, 1);
/********************************************/
	/*special for em9301 IRQ*/
	_lwsem_create(&driver_data->IRQ_SEM, 0);
	lwgpio_init(&driver_data->SPI_IRQ_PIN, BSP_EM9301_IRQ_PIN, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);
    lwgpio_set_functionality(&driver_data->SPI_IRQ_PIN, BSP_EM9301_IRQ_MUX_IRQ);
    lwgpio_set_attribute(&driver_data->SPI_IRQ_PIN, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE);
    lwgpio_int_init(&driver_data->SPI_IRQ_PIN, LWGPIO_INT_MODE_RISING);
    _int_install_isr(lwgpio_int_get_vector(&driver_data->SPI_IRQ_PIN), _dspi_em9301_isr, driver_data);
    _bsp_int_init(lwgpio_int_get_vector(&driver_data->SPI_IRQ_PIN), BSP_DSPI_INT_LEVEL, 0, TRUE);
    lwgpio_int_enable(&driver_data->SPI_IRQ_PIN, TRUE);
/********************************************/
    error_code = _io_dev_install_ext(identifier,
        _io_spi_open, _io_spi_close,
        _io_spi_read, _io_spi_write,
        _io_spi_ioctl,
        _io_spi_uninstall,
        (void *)driver_data);

    if (error_code)
    {
        /* deinitialize low level driver */
        if (driver_data->DEVIF->DEINIT)
            driver_data->DEVIF->DEINIT(driver_data->DEVIF_DATA);

        _lwsem_destroy(&driver_data->BUS_LOCK);
        _mem_free(driver_data);
        return error_code;
    }

    return MQX_OK;
}
示例#26
0
uint32_t ENET_initialize_ex
   (
         /* [IN] optional parameters */
      const ENET_PARAM_STRUCT *   param_ptr,
         /* [IN] the local Ethernet address */
      _enet_address           address,
         /* [OUT] the Ethernet state structure */
      _enet_handle       *handle
   )
{
   ENET_CONTEXT_STRUCT_PTR enet_ptr = NULL;//, other_enet_ptr;
   uint32_t                 result;
   bool                 vlan;
   
   if (param_ptr == NULL)
      return ENETERR_INVALID_DEVICE;

   if (param_ptr->NUM_RX_BUFFERS < param_ptr->NUM_RX_ENTRIES) 
      return ENETERR_INVALID_INIT_PARAM;
   
   enet_ptr = _mqx_get_io_component_handle(IO_ENET_COMPONENT);
   
   while (enet_ptr) {
      if (enet_ptr->PARAM_PTR->ENET_IF->MAC_NUMBER == param_ptr->ENET_IF->MAC_NUMBER)
         break;
      
      enet_ptr = enet_ptr->NEXT;
   }
   
   if (enet_ptr) {
      *handle = enet_ptr;
   
      return ENETERR_INITIALIZED_DEVICE;
   }
   else
      *handle = NULL;

   /* Allocate the Enet context structure.*/
   enet_ptr = _mem_alloc_system_zero(sizeof(ENET_CONTEXT_STRUCT));
   if (NULL==enet_ptr)
      return ENETERR_ALLOC_CFG;
      
   _mem_set_type((void *)enet_ptr, MEM_TYPE_IO_ENET_CONTEXT_STRUCT);

   /* Initialize the Enet context structure.*/
   eaddrcpy(enet_ptr->ADDRESS, address);
   enet_ptr->PARAM_PTR = param_ptr;
   vlan = (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_VLAN) == ENET_OPTION_VLAN;
   enet_ptr->MaxTxFrameSize = ENET_max_framesize(enet_ptr->PARAM_PTR->TX_BUFFER_SIZE,0,vlan);
   enet_ptr->MaxRxFrameSize = ENET_max_framesize(enet_ptr->PARAM_PTR->RX_BUFFER_SIZE,enet_ptr->PARAM_PTR->NUM_LARGE_BUFFERS,vlan);
   _lwsem_create(&enet_ptr->CONTEXT_LOCK, 1);
    
   /* Initialize the MAC.*/
   result = (*param_ptr->ENET_IF->MAC_IF->INIT)(enet_ptr);
   
    if (ENET_OK == result)
    {
        // Link the driver into the kernel component list
        _mqx_link_io_component_handle(IO_ENET_COMPONENT,enet_ptr, (void **)&enet_ptr->NEXT);

        *handle = enet_ptr;
    } 
    else
    {
        _lwsem_destroy(&enet_ptr->CONTEXT_LOCK);
        _mem_free(enet_ptr);
        *handle = NULL;
    }
   
    return result;
}   
示例#27
0
void main_task
   (
      uint_32 dummy
   )
{
   MQX_FILE_PTR         fd;
   uint_32                        i, j;
   _mqx_int                     param, result;
   I2C_STATISTICS_STRUCT        stats;
   uchar_ptr                    buffer;

   /* I2C transaction lock */
   _lwsem_create (&lock, 1);
   
   /* Allocate receive buffer */
   buffer = _mem_alloc_zero (BUFFER_SIZE);
   if (buffer == NULL) 
   {
      printf ("ERROR getting receive buffer!\n");
      _task_block ();
   }

   
   printf ("\n\n-------------- Polled I2C master example --------------\n\n");

   /* Open the I2C driver */         
   fd = fopen (I2C_DEVICE_POLLED, NULL);
   if (fd == NULL) 
   {
      printf ("ERROR opening the I2C driver!\n");
      _task_block ();
   }

   /* Test ioctl commands */
   param = 100000;
   printf ("Set current baud rate to %d ... ", param);
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_BAUD, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current baud rate ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_BAUD, &param))
   {
      printf ("%d\n", param);
   } else {
      printf ("ERROR\n");
   }

   printf ("Set master mode ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_MASTER_MODE, NULL))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current mode ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_MODE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x60;
   printf ("Set station address to 0x%02x ... ", param);
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_STATION_ADDRESS, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x00;
   printf ("Get station address ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATION_ADDRESS, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }

   printf ("Clear statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_CLEAR_STATISTICS, NULL))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   printf ("Get statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATISTICS, (pointer)&stats))
   {
      printf ("OK\n  Interrupts:  %d\n", stats.INTERRUPTS);
      printf ("  Rx packets:  %d\n", stats.RX_PACKETS);
      printf ("  Tx packets:  %d\n", stats.TX_PACKETS);
      printf ("  Tx lost arb: %d\n", stats.TX_LOST_ARBITRATIONS);
      printf ("  Tx as slave: %d\n", stats.TX_ADDRESSED_AS_SLAVE);
      printf ("  Tx naks:     %d\n", stats.TX_NAKS);
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current state ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   param = I2C_EEPROM_BUS_ADDRESS;
   printf ("Set destination address to 0x%02x ... ", param);
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x00;
   printf ("Get destination address ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_DESTINATION_ADDRESS, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   /* Test EEPROM communication */
   i2c_write_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, (uchar_ptr)TEST_STRING, 0);
   i2c_read_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, buffer, 0);

   i2c_write_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, (uchar_ptr)TEST_STRING, 1);
   i2c_read_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, buffer, 1);
   printf ("Received: %c (0x%02x)\n", buffer[0], buffer[0]);
   if (buffer[0] != TEST_STRING[0])
   {
      printf ("ERROR\n");
      _task_block ();
   }

   _mem_zero (buffer, BUFFER_SIZE);
   i2c_write_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, buffer, sizeof(TEST_STRING));
   i2c_read_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, buffer, sizeof(TEST_STRING));
   for (result = 0; result < BUFFER_SIZE; result++)
   {
      if (0 != buffer[result])
      {
         printf ("\nERROR during memory clearing\n");
         _task_block ();
      }
   }
   
   i2c_write_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, (uchar_ptr)TEST_STRING, sizeof(TEST_STRING));
   i2c_read_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, buffer, sizeof(TEST_STRING));
   printf ("Received: ");
   for (result = 0; result < sizeof(TEST_STRING); result++)
   {
      printf ("%c", buffer[result]);
      if (buffer[result] != TEST_STRING[result])
      {
         printf ("\nERROR\n");
         _task_block ();
      }
   }
   printf ("\n");
   
   /* Test special cases: write 1 byte (address pointer), read 1 byte (dump memory) */
   _lwsem_wait (&lock);
   buffer[0] = 0;
   buffer[1] = 0;
   fwrite (buffer, 1, I2C_EEPROM_MEMORY_WIDTH, fd);
   if (I2C_OK != ioctl (fd, IO_IOCTL_FLUSH_OUTPUT, NULL))
   {
      printf ("\nERROR during flush\n");
   }
   if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_STOP, NULL))
   {
      printf ("\nERROR during stop\n");
   }
   
   printf ("\nMemory dump:\n");
   for (i = 0; i < 16; i++)
   {
      for (j = 0; j < 16; j++)
      {
         _time_delay (1);
         param = 1;
         if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_SET_RX_REQUEST, &param))
         {
            printf ("\nERROR during set rx request\n");
         }
         fread (&(buffer[j]), 1, 1, fd);
         if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_STOP, NULL))
         {
            printf ("\nERROR during stop\n");
         }
      }
      printf ("0x%02x: ", i * 16);
      for (j = 0; j < 16; j++)
      {
         printf ("%02x ", buffer[j]);
      }
      for (j = 0; j < 16; j++)
      {
         if ((32 <= buffer[j]) && (buffer[j] <= 128))
         {
            printf ("%c", buffer[j]);
         }
         else
         {
            printf (".");
         }
      }
      printf ("\n");
   }
   _lwsem_post (&lock);
   
   printf ("\nGet statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATISTICS, (pointer)&stats))
   {
      printf ("OK\n  Interrupts:  %d\n", stats.INTERRUPTS);
      printf ("  Rx packets:  %d\n", stats.RX_PACKETS);
      printf ("  Tx packets:  %d\n", stats.TX_PACKETS);
      printf ("  Tx lost arb: %d\n", stats.TX_LOST_ARBITRATIONS);
      printf ("  Tx as slave: %d\n", stats.TX_ADDRESSED_AS_SLAVE);
      printf ("  Tx naks:     %d\n", stats.TX_NAKS);
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current state ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }

   /* Close the driver */
   result = fclose (fd);
   if (result) 
   {
      printf ("ERROR during close, returned: %d\n", result);
   }

   
#if ENABLE_I2C_INTERRUPT

   printf ("\n\n-------------- Interrupt I2C master example --------------\n\n");
  
   /* Open the I2C driver */         
   fd = fopen (I2C_DEVICE_INTERRUPT, NULL);
   if (fd == NULL) 
   {
      printf ("Failed to open the I2C driver!\n");
      _task_block ();
   }

   /* Test ioctl commands */
   printf ("Get current baud rate ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_BAUD, &param))
   {
      printf ("%d\n", param);
   } else {
      printf ("ERROR\n");
   }

   printf ("Set master mode ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_MASTER_MODE, NULL))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   printf ("Get current mode ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_MODE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x60;
   printf ("Set station address to 0x%02x ... ", param);
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_STATION_ADDRESS, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x00;
   printf ("Get station address ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATION_ADDRESS, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }

   printf ("Clear statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_CLEAR_STATISTICS, NULL))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   printf ("Get statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATISTICS, (pointer)&stats))
   {
      printf ("OK\n  Interrupts:  %d\n", stats.INTERRUPTS);
      printf ("  Rx packets:  %d\n", stats.RX_PACKETS);
      printf ("  Tx packets:  %d\n", stats.TX_PACKETS);
      printf ("  Tx lost arb: %d\n", stats.TX_LOST_ARBITRATIONS);
      printf ("  Tx as slave: %d\n", stats.TX_ADDRESSED_AS_SLAVE);
      printf ("  Tx naks:     %d\n", stats.TX_NAKS);
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current state ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   param = I2C_EEPROM_BUS_ADDRESS;
   printf ("Set destination address to 0x%02x ... ", param);
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x00;
   printf ("Get destination address ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_DESTINATION_ADDRESS, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   /* Test EEPROM communication */
   i2c_write_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, (uchar_ptr)TEST_STRING, 0);
   i2c_read_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, buffer, 0);

   i2c_write_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, (uchar_ptr)TEST_STRING, 1);
   i2c_read_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, buffer, 1);
   printf ("Received: %c (0x%02x)\n", buffer[0], buffer[0]);
   if (buffer[0] != TEST_STRING[0])
   {
      printf ("ERROR\n");
      _task_block ();
   }
   
   _mem_zero (buffer, BUFFER_SIZE);
   i2c_write_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, buffer, sizeof(TEST_STRING));
   i2c_read_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, buffer, sizeof(TEST_STRING));
   for (result = 0; result < BUFFER_SIZE; result++)
   {
      if (0 != buffer[result])
      {
         printf ("\nERROR during memory clearing\n");
         _task_block ();
      }
   }
      
   i2c_write_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, (uchar_ptr)TEST_STRING, sizeof(TEST_STRING));
   i2c_read_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, buffer, sizeof(TEST_STRING));
   printf ("Received: ");
   for (result = 0; result < sizeof(TEST_STRING); result++)
   {
      printf ("%c", buffer[result]);
      if (buffer[result] != TEST_STRING[result])
      {
         printf ("\nERROR\n");
         _task_block ();
      }
   }
   printf ("\n");

   /* Test special cases: write 1 byte (address pointer), read 1 byte (dump memory) */
   _lwsem_wait (&lock);
   buffer[0] = 0;
   buffer[1] = 0;
   fwrite (buffer, 1, I2C_EEPROM_MEMORY_WIDTH, fd);
   if (I2C_OK != ioctl (fd, IO_IOCTL_FLUSH_OUTPUT, NULL))
   {
      printf ("\nERROR during flush\n");
   }
   if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_STOP, NULL))
   {
      printf ("\nERROR during stop\n");
   }
   
   printf ("\nMemory dump:\n");
   for (i = 0; i < 16; i++)
   {
      for (j = 0; j < 16; j++)
      {
         _time_delay (1);
         param = 1;
         if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_SET_RX_REQUEST, &param))
         {
            printf ("\nERROR during set rx request\n");
         }
         do 
         {
            result = fread (&(buffer[j]), 1, 1, fd);
         } while (0 == result);
         if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_STOP, NULL))
         {
            printf ("\nERROR during stop\n");
         }
      }
      printf ("0x%02x: ", i * 16);
      for (j = 0; j < 16; j++)
      {
         printf ("%02x ", buffer[j]);
      }
      for (j = 0; j < 16; j++)
      {
         if ((32 <= buffer[j]) && (buffer[j] <= 128))
         {
            printf ("%c", buffer[j]);
         }
         else
         {
            printf (".");
         }
      }
      printf ("\n");
   }
   _lwsem_post (&lock);
   
   printf ("\nGet statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATISTICS, (pointer)&stats))
   {
      printf ("OK\n  Interrupts:  %d\n", stats.INTERRUPTS);
      printf ("  Rx packets:  %d\n", stats.RX_PACKETS);
      printf ("  Tx packets:  %d\n", stats.TX_PACKETS);
      printf ("  Tx lost arb: %d\n", stats.TX_LOST_ARBITRATIONS);
      printf ("  Tx as slave: %d\n", stats.TX_ADDRESSED_AS_SLAVE);
      printf ("  Tx naks:     %d\n", stats.TX_NAKS);
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current state ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }

   /* Close the driver */
   result = fclose (fd);
   if (result) 
   {
      printf ("ERROR during close, returned: %d\n", result);
   }

#endif

   
   /* Free transation lock */
   _lwsem_destroy (&lock);

   /* Free buffer */
   _mem_free (buffer);
   printf("Example finished.\n");
   _task_block();
 
} /* Endbody */
示例#28
0
/*FUNCTION*-------------------------------------------------------------
*
* Function Name   :  PPP_init_fail
* Returned Value  :  none
* Comments        :
*     Do cleanup when initialization fails.
*
*END*-----------------------------------------------------------------*/
void PPP_init_fail(PPP_CFG_PTR ppp_ptr, int stage)
{
    if (stage > 0)
    {
        fclose(ppp_ptr->IOPCB_DEVICE);
        _mem_free(ppp_ptr->DEVICE_NAME);
        ppp_ptr->DEVICE_NAME = NULL;
    }
    if (stage > 1)
    {
        _lwsem_destroy(&ppp_ptr->MUTEX);
    }
    if (stage > 2)
    {
        LCP_destroy(ppp_ptr);
    }
    if (stage > 3)
    {
       // CCP_close(ppp_ptr);
       // CCP_destroy(ppp_ptr);
    }
    if (stage > 5)
    {
        LWSEM_STRUCT sem;

        RTCS_sem_init(&sem);
        PPP_send_shutdown(ppp_ptr, &sem);
        RTCS_sem_wait(&sem);
        RTCS_sem_destroy(&sem);
    }
    /* Message pool must be destroyed after we send shutdown message to TX task */
    if (stage > 4)
    {
        RTCS_msgpool_destroy(ppp_ptr->MSG_POOL);
    }
    if (stage > 6)
    {
        uint32_t        wait_time  = 50; 
        uint32_t        delay_time = 100;

        ppp_ptr->STOP_RX = TRUE;
        while(ppp_ptr->STOP_RX)  
        {  
            _time_delay(delay_time);
            wait_time--;
            if(!wait_time)
            {
                RTCS_task_destroy(ppp_ptr->RX_TASKID);
                break;
            }
        }
    }
    if (stage > 7)
    {
        _iopcb_close(ppp_ptr->DEVICE);
    }
    if (stage > 8)
    {
        RTCS_if_unbind(ppp_ptr->IF_HANDLE, IPCP_get_local_addr(ppp_ptr->IF_HANDLE));
        RTCS_if_remove(ppp_ptr->IF_HANDLE);
    }
    _mem_free(ppp_ptr);
}
示例#29
0
/*FUNCTION****************************************************************
*
* Function Name    : _io_spi_install
* Returned Value   : MQX error code
* Comments         :
*    Installs SPI device.
*
*END**********************************************************************/
_mqx_int _io_spi_install
    (
        /* [IN] A string that identifies the device for fopen */
        char                       *identifier,

        /* [IN] Pointer to driver initialization data */
        SPI_INIT_STRUCT_CPTR           init_data_ptr
    )
{
    SPI_DRIVER_DATA_STRUCT_PTR driver_data;

    _mqx_int error_code = MQX_OK;

    if ((init_data_ptr->DEVIF->SETPARAM == NULL) || (init_data_ptr->DEVIF->TX_RX == NULL))
    {
        /* Missing mandatory low level driver function */
        return IO_ERROR_DEVICE_INVALID;
    }

    driver_data = (SPI_DRIVER_DATA_STRUCT_PTR)_mem_alloc_system_zero((_mem_size)sizeof(SPI_DRIVER_DATA_STRUCT));
    if (driver_data == NULL)
    {
        return MQX_OUT_OF_MEMORY;
    }
    _mem_set_type(driver_data, MEM_TYPE_IO_SPI_POLLED_DEVICE_STRUCT);

    driver_data->CS_CALLBACK = init_data_ptr->CS_CALLBACK;
    driver_data->CS_USERDATA= init_data_ptr->CS_USERDATA;
    driver_data->PARAMS = init_data_ptr->PARAMS;
    driver_data->DEVIF = init_data_ptr->DEVIF;

    /* initialize low level driver */
    if (driver_data->DEVIF->INIT)
        error_code = driver_data->DEVIF->INIT(init_data_ptr->DEVIF_INIT, &(driver_data->DEVIF_DATA));

    if (error_code != MQX_OK)
    {
        _mem_free(driver_data);
        return error_code;
    }

    _lwsem_create(&driver_data->BUS_LOCK, 1);

    error_code = _io_dev_install_ext(identifier,
        _io_spi_open, _io_spi_close,
        _io_spi_read, _io_spi_write,
        _io_spi_ioctl,
        _io_spi_uninstall,
        (void *)driver_data);

    if (error_code)
    {
        /* deinitialize low level driver */
        if (driver_data->DEVIF->DEINIT)
            driver_data->DEVIF->DEINIT(driver_data->DEVIF_DATA);

        _lwsem_destroy(&driver_data->BUS_LOCK);
        _mem_free(driver_data);
        return error_code;
    }

    return MQX_OK;
}