コード例 #1
0
ファイル: usermode.c プロジェクト: zhouglu/K60F120M
static void privilege_task(uint_32 initial_data) 
{
    _mqx_uint msg[MSG_SIZE];
    _lwmem_pool_id mem_pool_id;
    LWMEM_POOL_STRUCT mem_pool;
    pointer mem_pool_start;
    
    LWMEM_POOL_STRUCT_PTR usr_pool_ptr;
    pointer usr_pool_start;
    
    /* memory pool: Read-Only for User tasks */
    mem_pool_start = _mem_alloc(1024);
    mem_pool_id = _lwmem_create_pool(&mem_pool, mem_pool_start, 1024);
    _mem_set_pool_access(mem_pool_id, POOL_USER_RO_ACCESS);

    /* message queue to communicate between this task and User tasks */
    que = (uint_32*)_mem_alloc_from(mem_pool_id, sizeof(LWMSGQ_STRUCT) + NUM_MESSAGES * MSG_SIZE * sizeof(_mqx_uint));
    _usr_lwmsgq_init((pointer)que, NUM_MESSAGES, MSG_SIZE);

    /* memory pool: Read-Write for user tasks */
    usr_pool_ptr = _usr_mem_alloc(sizeof(LWMEM_POOL_STRUCT));
    usr_pool_start = _mem_alloc(1024);
    usr_pool_id = _lwmem_create_pool(usr_pool_ptr, usr_pool_start, 1024);
    _mem_set_pool_access(usr_pool_id, POOL_USER_RW_ACCESS);

    /* create the user "main" task, whcih then creates the others */
    _task_create(0, USR_MAIN_TASK, USR_TASK_CNT);

    /* receive messages from user tasks and print */
    while (1) {
        _lwmsgq_receive((pointer)que, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 0, 0);
        printf(" %c \n", msg[0]);
    }
}
コード例 #2
0
ファイル: flash_ftfl.c プロジェクト: jewlenchow/MQX_3.8.1
/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    : ftfl_flash_init
* Returned Value   : TRUE if successful, FALSE otherwise
* Comments         :
*   Initialize flash specific information.
*
*END*-----------------------------------------------------------------------*/
boolean ftfl_flash_init
(
    /* [IN] Device instance */
    IO_FLASHX_STRUCT_PTR dev_ptr
)
{
    FTFL_FLASH_INTERNAL_STRUCT_PTR    dev_spec_ptr;
    FTFL_MemMapPtr                    ftfl_ptr;

    if (_bsp_ftfx_io_init(0)) {
        /* Cannot initialize FTF module */
        return FALSE;
    }

    /* allocate internal structure */
    dev_spec_ptr = _mem_alloc(sizeof(FTFL_FLASH_INTERNAL_STRUCT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if( dev_spec_ptr == NULL)
    {
        return FALSE;
    }
#endif
    dev_ptr->DEVICE_SPECIFIC_DATA = dev_spec_ptr;

    /* get the pointer to ftfl registers structure */
    ftfl_ptr = (FTFL_MemMapPtr)_bsp_get_ftfl_address();
    dev_spec_ptr->ftfl_ptr = (vchar_ptr)ftfl_ptr;

    /* save pointer to function in ram */
    dev_spec_ptr->flash_execute_code_ptr = ftfl_init_ram_function ();


    return TRUE;
}
コード例 #3
0
/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    : mcf_52xx_flash_init
* Returned Value   :
* Comments         :
*   Erase a flash memory block
*
*END*----------------------------------------------------------------------*/
bool mcf52xx_flash_init
(
    /* [IN] File pointer */
    IO_FLASHX_STRUCT_PTR dev_ptr
)
{
    MCF52XX_FLASH_INTERNAL_STRUCT_PTR dev_spec_ptr;
#ifdef PSP_HAS_DUAL_FLASH
    uint8_t array;
#endif //PSP_HAS_DUAL_FLASH

    VMCF52XX_CFM_STRUCT_PTR     cfm_ptr;

    dev_spec_ptr = _mem_alloc(sizeof(MCF52XX_FLASH_INTERNAL_STRUCT));
#if MQX_CHECK_FOR_MEMORY_ALLOCATION_ERRORS
    /* test for correct memory allocation */
    if( dev_spec_ptr == NULL) {
        return FALSE;
    }
#endif //MQX_CHECK_FOR_MEMORY_ALLOCATION_ERRORS

    /* get the pointer to cfm registers structure */
    cfm_ptr = _bsp_get_cfm_address();
    dev_spec_ptr->cfm_ptr = (volatile char *)cfm_ptr;
    dev_ptr->DEVICE_SPECIFIC_DATA = dev_spec_ptr;

    /* save pointer to function in ram */
    dev_spec_ptr->flash_execute_code_ptr = mcf52xx_init_ram_function();

    /* set correct clocking for CFM module */
    _mcf52xx_set_cfmclkd();

    return TRUE;
}
コード例 #4
0
ファイル: adc.c プロジェクト: gxliu/MQX_3.8.0
/*FUNCTION*****************************************************************
* 
* Function Name    : _adc_install
* Returned Value   : _mqx_uint a task error code or MQX_OK
* Comments         :
*    Install a adc driver.
*
*END*********************************************************************/
_mqx_uint _io_adc_install
   (
      /* [IN] A string that identifies the device for fopen */
      char_ptr  identifier,
      /* pointer to a HW specific structure */
      pointer   init
   ) 
   
{ /* Body */
   ADC_DRIVER_BUNDLE_PTR adc_driver_bundle;
   _mqx_uint result;

   if (NULL == (adc_driver_bundle = (ADC_DRIVER_BUNDLE_PTR) _mem_alloc(sizeof(ADC_DRIVER_BUNDLE))))
      return ADC_ERROR_ALLOC; /* memory allocation error */

   _mem_zero(adc_driver_bundle, sizeof(ADC_DRIVER_BUNDLE));

   if (IO_OK == (result = _adc_hw_install(identifier, adc_driver_bundle, init)))
      if (IO_OK == (result = _adt_hw_install(identifier, adc_driver_bundle, init)))
         result = _io_dev_install(identifier,
            _adc_open,
            _adc_close,
            _adc_read,
            _adc_write,
            _adc_ioctl,
            adc_driver_bundle);

   if (result != IO_OK)
      _mem_free(adc_driver_bundle); 

   return result;
} /* Endbody */
コード例 #5
0
ファイル: flash_ftfa.c プロジェクト: Vinhuit/Freescale
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : ftfa_flash_init
* Returned Value   : TRUE if successful, FALSE otherwise
* Comments         :
*   Initialize flash specific information.
*
*END*----------------------------------------------------------------------*/
bool ftfa_flash_init 
(
    /* [IN] File pointer */
    IO_FLASHX_STRUCT_PTR dev_ptr
)
{
    FTFA_FLASH_INTERNAL_STRUCT_PTR    dev_spec_ptr;
    FTFA_MemMapPtr                    ftfa_ptr;

    if (_bsp_ftfx_io_init(0)) {
        /* Cannot initialize FTF module */
        return FALSE;
    }

    /* allocate internal structure */
    dev_spec_ptr = _mem_alloc(sizeof(FTFA_FLASH_INTERNAL_STRUCT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (dev_spec_ptr == NULL)
    {
        return FALSE;
    }
#endif
    dev_ptr->DEVICE_SPECIFIC_DATA = dev_spec_ptr;
        
    /* get the pointer to ftfa registers structure */
    ftfa_ptr = _bsp_get_ftfa_address();
    dev_spec_ptr->ftfa_ptr = (volatile char *)ftfa_ptr;
    
    /* save pointer to function in ram */
    dev_spec_ptr->flash_execute_code_ptr = ftfa_init_ram_function((char *)ftfa_ram_function, (char *)ftfa_ram_function_end);
#if PSP_MQX_CPU_IS_KINETIS
    dev_spec_ptr->flash_invalidate_code_ptr = ftfa_init_ram_function((char *)kinetis_flash_invalidate_cache, (char *)kinetis_flash_invalidate_cache_end);
#endif

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (dev_spec_ptr->flash_execute_code_ptr == NULL)
    {
        return FALSE;
    }
#if PSP_MQX_CPU_IS_KINETIS
    if (dev_spec_ptr->flash_invalidate_code_ptr == NULL)
    {
        return FALSE;
    }
#endif
#endif

    /* 
    ** TODO: Currently, MQX FlashX driver for FTFA 
    ** doesn't support chips using FlexNVM so no need to configure FlexRAM 
    ** to traditional RAM when using Programing Acceleration RAM 
    */
        
    return TRUE;    
}
コード例 #6
0
/*
** Function for CGI request processing
**
** IN:
**      HTTPSRV_SESSION_STRUCT* session - session structure pointer.
**      HTTPSRV_STRUCT*         server - pointer to server structure (needed for session parameters).
**      char*                   cgi_name - name of cgi function.
**
** OUT:
**      none
**
** Return Value: 
**      none
*/
void httpsrv_process_cgi(HTTPSRV_STRUCT *server, HTTPSRV_SESSION_STRUCT *session, char* cgi_name)
{
    HTTPSRV_SCRIPT_MSG* msg_ptr;

    msg_ptr = _msg_alloc(server->script_msg_pool);

    if (msg_ptr == NULL)
    {
        /* Out of memory - report server error */
        session->response.status_code = HTTPSRV_CODE_INTERNAL_ERROR;
        return;
    }

    msg_ptr->header.TARGET_QID = server->script_msgq;
    msg_ptr->header.SOURCE_QID = server->script_msgq;
    msg_ptr->header.SIZE = sizeof(HTTPSRV_SCRIPT_MSG);
    msg_ptr->session = session;
    msg_ptr->type = HTTPSRV_CGI_CALLBACK;
    msg_ptr->name = cgi_name;
    msg_ptr->ses_tid = _task_get_id();
    _msgq_send(msg_ptr);
    /* wait until CGI is processed */
    _task_block();

    /*
    ** There is some unread content from client after CGI finished. 
    ** It must be read and discarded if we have keep-alive enabled
    ** so it does not affect next request.
    */
    if (session->request.content_length)
    {
        char *tmp = NULL;

        tmp = _mem_alloc(HTTPSRV_TMP_BUFFER_SIZE);
        if (tmp != NULL)
        {
            uint32_t length = session->request.content_length;

            while(length)
            {
                uint32_t retval;

                retval = httpsrv_read(session, tmp, HTTPSRV_TMP_BUFFER_SIZE);
                if (!retval)
                {
                    break;
                }
                length -= retval;
            }
            _mem_free(tmp);
            session->request.content_length = 0;
        } 
    }
    return;
}
コード例 #7
0
/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    : ftfl_flash_init
* Returned Value   : TRUE if successful, FALSE otherwise
* Comments         :
*   Initialize flash specific information.
*
*END*-----------------------------------------------------------------------*/
bool ftfl_flash_init
(
    /* [IN] Device instance */
    IO_FLASHX_STRUCT_PTR dev_ptr
)
{
    FTFL_FLASH_INTERNAL_STRUCT_PTR    dev_spec_ptr;
    FTFL_MemMapPtr                    ftfl_ptr;

    if (_bsp_ftfx_io_init(0)) {
        /* Cannot initialize FTF module */
        return FALSE;
    }

    /* allocate internal structure */
    dev_spec_ptr = _mem_alloc(sizeof(FTFL_FLASH_INTERNAL_STRUCT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (dev_spec_ptr == NULL)
    {
        return FALSE;
    }
#endif
    dev_ptr->DEVICE_SPECIFIC_DATA = dev_spec_ptr;

    /* get the pointer to ftfl registers structure */
    ftfl_ptr = (FTFL_MemMapPtr)_bsp_get_ftfl_address();
    dev_spec_ptr->ftfl_ptr = (volatile char *)ftfl_ptr;

    /* save pointer to function in ram */
    dev_spec_ptr->flash_execute_code_ptr = ftfl_init_ram_function((char *)ftfl_ram_function, (char *)ftfl_ram_function_end);
#if PSP_MQX_CPU_IS_KINETIS
    dev_spec_ptr->flash_invalidate_code_ptr = ftfl_init_ram_function((char *)kinetis_flash_invalidate_cache, (char *)kinetis_flash_invalidate_cache_end);
#endif

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (dev_spec_ptr->flash_execute_code_ptr == NULL)
    {
        return FALSE;
    }
#if PSP_MQX_CPU_IS_KINETIS
    if (dev_spec_ptr->flash_invalidate_code_ptr == NULL)
    {
        return FALSE;
    }
#endif
#endif

#if BSPCFG_FLASHX_USE_PA_RAM && BSP_INTERNAL_FLEXRAM_BASE
    /* Make sure Programing Acceleration RAM was enabled */
    flexnvm_set_flexram(dev_ptr, (unsigned char)FLEXNVM_FLEXRAM_RAM);
#endif

    return TRUE;
}
コード例 #8
0
ファイル: mfs_misc.c プロジェクト: kylemanna/kinetis-sdk1
/*!
 * \brief
 *
 * \param size
 *
 * \return void *
 */
void *MFS_mem_alloc(_mem_size size)
{
    if (_MFS_pool_id)
    {
        return _mem_alloc_from(_MFS_pool_id, size);
    }
    else
    {
        return _mem_alloc(size);
    }
}
コード例 #9
0
ファイル: mem.c プロジェクト: thatking/sample
void *mem_alloc(int _size)
{
    MEM_T *mem = _mem_alloc(_size);
    if(mem)
    {
        return _mem2void(mem);
    }
    else
    {
        return NULL;
    }
}
コード例 #10
0
ファイル: bmalloc.c プロジェクト: ahamid/sartoris
void *calloc(size_t nelem, size_t elsize)
{
	void *ptr = NULL;
#	ifdef SAFE
	wait_mutex(&malloc_mutex);
#	endif
	ptr =  _mem_alloc(nelem * elsize, 1);
#	ifdef SAFE
	leave_mutex(&malloc_mutex);
#	endif
	return ptr;
}
コード例 #11
0
ファイル: bmalloc.c プロジェクト: ahamid/sartoris
void *malloc(size_t size)
{
	void *ptr = NULL;
#	ifdef SAFE
	wait_mutex(&malloc_mutex);
#	endif
	ptr =  _mem_alloc(size, 0);
#	ifdef SAFE
	leave_mutex(&malloc_mutex);
#	endif
	return ptr;
}
コード例 #12
0
ファイル: flash_mcf51xx.c プロジェクト: mihaSoro/MQX-3.7.0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : mcf51xx_init_ram_function
* Returned Value   : pointer to allocated RAM function
* Comments         :
*   allocate and copy flash RAM function  
*
*END*----------------------------------------------------------------------*/
uchar_ptr mcf51xx_init_ram_function()
{
    uchar_ptr ram_code_ptr;
    
    /* Allocate space on stack to run flash command out of SRAM */
    ram_code_ptr = _mem_alloc((char*)mcf51xx_ram_function_end  - 
        (char*)mcf51xx_ram_function);   
    /* copy code to RAM buffer */
    _mem_copy((void*)mcf51xx_ram_function, ram_code_ptr, 
        (char*)mcf51xx_ram_function_end  - (char*)mcf51xx_ram_function);

    return ram_code_ptr;               
}
コード例 #13
0
ファイル: flash_mcf51mm.c プロジェクト: tsbiberdorf/MqxSrc
/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    : _mcf51_swap_flash_and_reset
* Returned Value   : none
* Comments         :
*    Swap the flash adresses and restart device.
*
*END*----------------------------------------------------------------------*/
void _mcf51_swap_flash_and_reset()
{
    
    uchar_ptr ramcode_ptr = NULL;
    int_32 (*RunInRAM)( VMCF51MM_RTC_STRUCT_PTR );
    VMCF51MM_SIM_STRUCT_PTR sim_ptr = &(((VMCF51MM_STRUCT_PTR)BSP_IPSBAR)->SIM);
    
    /* Allocate space on stack to run flash command out of SRAM */
    ramcode_ptr = _mem_alloc((char*)mcf51mm_swap_flash_ram_end - (char*)mcf51mm_swap_flash_ram); 
    /* copy code to RAM buffer */
    _mem_copy((void*)mcf51mm_swap_flash_ram, ramcode_ptr, (char*)mcf51mm_swap_flash_ram_end  - (char*)mcf51mm_swap_flash_ram);
    *RunInRAM = (int_32(*)( VMCF51MM_SIM_STRUCT_PTR ))ramcode_ptr;   

    /* Run the code from RAM */
    RunInRAM( sim_ptr );
}
コード例 #14
0
ファイル: flash_mcf51xx.c プロジェクト: mihaSoro/MQX-3.7.0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : mcf_51xx_flash_init
* Returned Value   : 
* Comments         :
*   Init flash - store the FSTAT register  
*
*END*----------------------------------------------------------------------*/
boolean mcf_51xx_flash_init( IO_FLASHX_STRUCT_PTR flash_ptr )
{
    VMCF51XX_FTSR_STRUCT_PTR    ftsr_ptr;
    INTERNAL_51XX_STRUCT        dev_spec_struct;
    INTERNAL_51XX_STRUCT_PTR    dev_spec_ptr;
    
    dev_spec_ptr = _mem_alloc(sizeof(dev_spec_struct));
    /* test for correct memory allocation */
    if( dev_spec_ptr == NULL){
        return FALSE;
    }
    /* get the pointer to cfm registers structure */
    ftsr_ptr = _bsp_get_cfm_address( MEMORY_ARRAY_STD );
    dev_spec_ptr->ftsr_ptr = (vuchar_ptr)ftsr_ptr;
    flash_ptr->DEVICE_SPECIFIC_DATA = dev_spec_ptr;
    
    /* save pointer to function in ram - this is the default settings  */
    dev_spec_ptr->flash_execute_code_ptr = mcf51xx_init_ram_function();
    
    return TRUE;
}
コード例 #15
0
ファイル: mem.c プロジェクト: thatking/sample
int mem_test()
{
    #if 0
    _mem_init();
    
    MEM_T *mem = _mem_alloc(32*1024);
    if(mem)
    {
        LOG_INFO("mem->size = %d",mem->size);
        LOG_INFO("mem->phy_addr = %x",mem->phy_addr);
        LOG_INFO("mem->vir_addr = %p",mem->vir_addr);

        _mem_free(mem);
        return 0;
    }
    else
    {
        return -1;
    }
    #else
    mem_init();
    int phy_addr = 0;
    int mem_size = 0;
    void *vir_addr = NULL;
    void *ptr = mem_alloc(64*1024);
    memset(ptr,0,64*1024);
    if(ptr)
    {
        LOG_INFO("ptr is %p\n",ptr);
        vir_addr = ptr - 0x8;
        LOG_INFO("hisi vir_addr is %p\n",vir_addr);
        phy_addr = get_hisi_phy_from_ptr(ptr);
        LOG_INFO("phy_addr is %x\n",phy_addr);
        mem_size = get_mem_size(ptr);
        LOG_INFO("mem_size is %d\n",mem_size);
        mem_free(ptr);
    }
    return 0;
    #endif
}
コード例 #16
0
ファイル: flash_mcf51xx.c プロジェクト: mihaSoro/MQX-3.7.0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : mcf_51xx_flash_array2_init
* Returned Value   : 
* Comments         :
*   Init flash - store the FSTAT register  
*
*END*----------------------------------------------------------------------*/
boolean mcf_51xx_flash_array2_init( IO_FLASHX_STRUCT_PTR flash_ptr )
{
    VMCF51XX_FTSR_STRUCT_PTR    ftsr_ptr;
    INTERNAL_51XX_STRUCT        dev_spec_struct;
    INTERNAL_51XX_STRUCT_PTR    dev_spec_ptr;

    dev_spec_ptr = _mem_alloc(sizeof(dev_spec_struct));
    /* test for correct memory allocation */
    if( dev_spec_ptr == NULL){
        return FALSE;
    }
    /* get the pointer to cfm registers structure */
    /* RTC_CFG_DATA[CFG0] = 0 : FSTR1 => 0x00000000 - see Flash Array Base Address table */
    ftsr_ptr = ( _mcf51_get_rtc_cfg_state() == 1 ) ? _bsp_get_cfm_address( MEMORY_ARRAY_1 ) : 
        _bsp_get_cfm_address( MEMORY_ARRAY_2 );
    dev_spec_ptr->ftsr_ptr = (vuchar_ptr)ftsr_ptr;
    flash_ptr->DEVICE_SPECIFIC_DATA = dev_spec_ptr;
    
    /* save pointer to function in ram - this is the default settings  */
    dev_spec_ptr->flash_execute_code_ptr = mcf51xx_init_ram_function();         
    
    return TRUE;    
}
コード例 #17
0
ファイル: flash_ftfl.c プロジェクト: jewlenchow/MQX_3.8.1
/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    : ftfl_init_ram_function
* Returned Value   : pointer to allocated RAM function
* Comments         :
*   Allocate and copy flash RAM function.
*
*END*-----------------------------------------------------------------------*/
char_ptr ftfl_init_ram_function
(
    void
)
{
    char_ptr ram_code_ptr;
    _mem_size ftfl_ram_function_start;

#if PSP_MQX_CPU_IS_COLDFIRE
    ftfl_ram_function_start = (_mem_size)ftfl_ram_function;
#elif PSP_MQX_CPU_IS_KINETIS
    /* Remove thumb2 flag from the address */
    ftfl_ram_function_start = (_mem_size)ftfl_ram_function & ~1;
#endif

    /* allocate space to run flash command out of RAM */
    ram_code_ptr = _mem_alloc((char_ptr)ftfl_ram_function_end  - (char_ptr)ftfl_ram_function_start);

    /* copy code to RAM buffer */
    _mem_copy ((char_ptr)ftfl_ram_function_start, ram_code_ptr, (char_ptr)ftfl_ram_function_end  - (char_ptr)ftfl_ram_function_start);

    return ram_code_ptr;
}
コード例 #18
0
/*
** Send error page to client
**
** IN:
**      HTTPSRV_SESSION_STRUCT* session - session used for transmission
**      const char*             title - title of error page
**      const char*             text - text displayed on error page
**
** OUT:
**      none
**
** Return Value:
**      none
*/
void httpsrv_send_err_page(HTTPSRV_SESSION_STRUCT *session, const char* title, const char* text)
{
    uint32_t length;
    char* page;
    
    length = snprintf(NULL, 0, ERR_PAGE_FORMAT, title, text);
    length++;
    page = _mem_alloc(length*sizeof(char));

    session->response.content_type = HTTPSRV_CONTENT_TYPE_HTML;

    if (page != NULL)
    {
        snprintf(page, length, ERR_PAGE_FORMAT, title, text);
        httpsrv_sendhdr(session, strlen(page), 1);
        httpsrv_write(session, page, strlen(page));
        httpsrv_ses_flush(session);
        _mem_free(page);
    }
    else
    {
        httpsrv_sendhdr(session, 0, 0);
    }
}
コード例 #19
0
ファイル: httpdsrv.c プロジェクト: gaodebang/eth-com-project
/*TASK*-----------------------------------------------------------------
*
* Function Name  : main_task
* Returned Value : void
* Comments       :
*
*END------------------------------------------------------------------*/
void main_task(uint_32 temp) {
    int_32            error;

    HTTPD_STRUCT                        *server[BSP_ENET_DEVICE_COUNT];
    extern const HTTPD_CGI_LINK_STRUCT  cgi_lnk_tbl[];
    extern const TFS_DIR_ENTRY          tfs_data[];
    HTTPD_PARAMS_STRUCT                 *params[BSP_ENET_DEVICE_COUNT];
    _enet_address                       address[BSP_ENET_DEVICE_COUNT];
    uint_32                             phy_addr[BSP_ENET_DEVICE_COUNT];
    uint_32                             ip_addr[BSP_ENET_DEVICE_COUNT];    
    uint_32                             i = 0;
    char*                               indexes[BSP_ENET_DEVICE_COUNT];
    uint_8 								n_devices = BSP_ENET_DEVICE_COUNT;
#if  DEMOCFG_USE_WIFI   
    ENET_ESSID                          ssid;
    uint_32                             mode;// = DEMOCFG_NW_MODE;
    uint_32                             sectype;// = DEMOCFG_SECURITY;
    ENET_MEDIACTL_PARAM                 param;
#endif
#if RTCSCFG_ENABLE_IP6      
    IPCFG6_GET_ADDR_DATA    data[RTCSCFG_IP6_IF_ADDRESSES_MAX];
    char prn_addr6[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
    uint_32 n = 0;
    uint_32 j = 0;
#endif
    _int_install_unexpected_isr();
    /*---------------- Initialize devices and variables ----------------------*/
    _RTCSPCB_init = 4;
    _RTCSPCB_grow = 2;
    _RTCSPCB_max = 8;
    
    _RTCSTASK_stacksize = 4500;
    /*--------------------------- Init end -----------------------------------*/ 
    
    
    PORT_PCR_REG(PORTC_BASE_PTR, 3) = PORT_PCR_MUX(5);
   // SIM_SOPT2 |= 3<<5; // 1k LPO
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    error = RTCS_create();
    if (error != RTCS_OK) 
    {
        printf("RTCS failed to initialize, error = 0x%X\n", error);
        _task_block();
    }
    _IP_forward = TRUE;
    
    for (i = 0; (i < n_devices) && (n_devices != 0); i++)
    {
        IPCFG_IP_ADDRESS_DATA	ip_data; 
        phy_addr[i] = i;
        ip_addr[i] = IPADDR(A,B,C+i,D);
        ENET_get_mac_address (phy_addr[i], ip_addr[i], address[i]);
        /* Init ENET device */
        error = ipcfg_init_device (phy_addr[i], address[i]);
        if (error != RTCS_OK) 
        {
            printf("IPCFG: Device n.%d init failed. Error = 0x%X\n", i, error);
            _task_set_error(MQX_OK);
            n_devices--;
            i--;
            continue;
        }
#if RTCSCFG_ENABLE_IP4
        ip_data.ip      = ip_addr[i];
        ip_data.mask    = ENET_IPMASK;
        ip_data.gateway = 0;
        /* Bind IPv4 address */
        //error = ipcfg_bind_staticip (phy_addr[i], &ip_data);
        error = ipcfg_bind_autoip (phy_addr[i], &ip_data);
        if (error != RTCS_OK) 
        {
            printf("\nIPCFG: Failed to bind IP address. Error = 0x%X", error);
            _task_block();
        }
#endif /* RTCSCFG_ENABLE_IP4 */
       
        indexes[i] = (char*) _mem_alloc(sizeof("\\index_x.html"));
    }  
   
    error = _io_tfs_install("tfs:", tfs_data);
 
#if DEBUG__MESSAGES 
    printf("Preparing http servers...\n");
#endif
    for (i = 0; i < n_devices; i++)
    {
        params[i] = httpd_default_params(NULL);
        params[i]->af = HTTP_INET_AF;  //IPv4+IPv6, set connection family from config.h
#if RTCSCFG_ENABLE_IP6   
        params[i]->if_scope_id = HTTP_SCOPE_ID;    // set interface number here. 0 is any .
#endif
        if (params[i])
        {
            sprintf(indexes[i], "\\index.html", i);
            params[i]->root_dir = (HTTPD_ROOT_DIR_STRUCT*)root_dir;
            params[i]->index_page = indexes[i];
            printf("Starting http server No.%d on IP", i);
             /*
            ** If there is only one interface listen on any IP address 
            ** so address can change in runtime (DHCP etc.)
            */
            #if RTCSCFG_ENABLE_IP4
            if ((i == 0) && (n_devices == 1))
            {
                params[i]->address = INADDR_ANY;
            }
            else
            {
                params[i]->address = ip_addr[i];
            }
            /* Print active ip addresses */
            printf(" %d.%d.%d.%d", IPBYTES(ip_addr[i]));
            #endif
            #if RTCSCFG_ENABLE_IP6 
            while(!ipcfg6_get_addr_info_n(i, n, &data[n]))
            {
                n++;
            }
            while(j < n)
            {
                if(inet_ntop(AF_INET6, &data[j++].ip_addr, prn_addr6, sizeof(prn_addr6)))
                {
                    /* Print active ip addresses */
                    #if RTCSCFG_ENABLE_IP4
                    printf("%s %s", (HTTP_INET_AF & AF_INET) ? " and" : "", prn_addr6);
                    #else
                    printf(" %s", prn_addr6);
                    #endif
                }
            }
            #endif
#if PSP_MQX_CPU_IS_MCF5223X
            params[i]->max_ses = 1;
#else
            params[i]->max_ses = _RTCS_socket_part_max - 1;
#endif
            server[i] = httpd_init(params[i]);
        }
        HTTPD_SET_PARAM_CGI_TBL(server[i], (HTTPD_CGI_LINK_STRUCT*)cgi_lnk_tbl);
#if HTTPD_SEPARATE_TASK || !HTTPDCFG_POLL_MODE
        printf("...");
        error = httpd_server_run(server[i]);
        if (error)
        {
            printf("[FAIL]\n");
        }
        else
        {
            printf("[OK]\n");
        }
#endif
    }

    /* user stuff come here */
#if HTTPD_SEPARATE_TASK || !HTTPDCFG_POLL_MODE      
    _task_create(0, SHELL_TASK, 0);
    _task_block();
#else
    printf("Servers polling started.\n")
    while (1)
    {
        for (i = 0; i < n_devices; i++)
        {
            httpd_server_poll(server[i], 1);
        }
        /* user stuff come here - only non blocking calls */
    }
#endif
}
コード例 #20
0
ファイル: sh_compare.c プロジェクト: mihaSoro/MQX-3.7.0
int_32  Shell_compare(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean     print_usage, shorthelp = FALSE;
   int_32      size1, size2, return_code = SHELL_EXIT_SUCCESS;
   MQX_FILE_PTR in_fd_1=NULL, in_fd_2=NULL;
   char_ptr    file1=NULL,file2=NULL;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int_32               error = 0;      

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc != 3)  {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } 
      /* check if filesystem is mounted */ 
      else if (NULL == Shell_get_current_filesystem(argv))  
      {
         printf("Error, file system not mounted\n");
         return_code = SHELL_EXIT_ERROR;
      }
      else if (MFS_alloc_path(&file1) != MFS_NO_ERROR) {
         printf("Error, unable to allocate memory for paths\n" );
         return_code = SHELL_EXIT_ERROR;
      } else {
         error = _io_rel2abs(file1,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME);
         if(!error)
         {
            in_fd_1 = fopen(file1, "r");
         }      

         error = _io_rel2abs(file1,shell_ptr->CURRENT_DIR,(char *) argv[2],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME);
         if(!error)
         {
            in_fd_2 = fopen(file1, "r");
         }  

         MFS_free_path(file1);         

         if (in_fd_1 == NULL)  {
             printf("Error, unable to open file %s\n", argv[1] );
             return_code = SHELL_EXIT_ERROR;
         } else  if (in_fd_2 == NULL)  {
             printf("Error, unable to open file %s\n", argv[2] );
             return_code = SHELL_EXIT_ERROR;
         } else {
            file1 = _mem_alloc(COMPARE_BLOCK_SIZE);
            file2 = _mem_alloc(COMPARE_BLOCK_SIZE);
            if ((file1==NULL) || (file2==NULL)) {
               printf("Error, unable to allocate buffer space" );
               return_code = SHELL_EXIT_ERROR;
            } else {
               do {
                  size1 = read(in_fd_1, file1, COMPARE_BLOCK_SIZE);
                  size2 = read(in_fd_2, file2, COMPARE_BLOCK_SIZE);
                  if (size1!=size2) {
                     printf("Compare failed, files have different sizes\n" );
                     return_code = SHELL_EXIT_ERROR;
                  } else if (size1 > 0) {
                     if (memcmp(file1,file2,COMPARE_BLOCK_SIZE)!=0) {
                        printf("Compare failed, files are different\n" );
                        return_code = SHELL_EXIT_ERROR;
                     }                     
                  }
               } while ((size1>0) && (return_code == SHELL_EXIT_SUCCESS));
               if (return_code == SHELL_EXIT_SUCCESS) {
                  printf("The files are identical\n" );
               }
            }
            if (file1) _mem_free(file1);
            if (file2) _mem_free(file2);
         }
         if (in_fd_1) fclose(in_fd_1); 
         if (in_fd_2) fclose(in_fd_2); 
      }
   }
      
      
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <file1> <file2> \n", argv[0]);
      } else  {
         printf("Usage: %s <file1> <file2>\n", argv[0]);
         printf("   <file1> = first file to compare\n");
         printf("   <file2> = second file to compare\n");
      }
   }
   return return_code;
} /* Endbody */
コード例 #21
0
ファイル: sh_i2c.c プロジェクト: gxliu/MQX_3.8.0
int_32  Shell_i2c_read(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean              print_usage, shorthelp = FALSE;
   int_32               result,return_code = SHELL_EXIT_SUCCESS;
   uint_32              addr, bytes,i;
   MQX_FILE_PTR         fd;
   char_ptr             buf;
   
      
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc==4)  {
         if ( Shell_parse_hexnum(argv[2], &addr) && Shell_parse_uint_32(argv[3], &bytes)) {

            fd = fopen(argv[1],0);
            buf = _mem_alloc(bytes);
            if ((fd!=NULL) && (buf !=NULL)) {
               if (I2C_OK != ioctl(fd, IO_IOCTL_I2C_SET_RX_REQUEST, &bytes))
               {
                  printf("ERROR during set rx request\n");
               } else {
                  result = fread(buf, bytes, 1, fd);
                  if (I2C_OK==result) {
                     for (i=0;i<bytes;i++) {
                        printf("%02x ", buf[i]);
                     }
                     printf("\n");
                  } else {
                     printf ("ERROR during read\n");
                  }
                  bytes=0;
                  if (I2C_OK != ioctl(fd, IO_IOCTL_FLUSH_OUTPUT, &bytes)) {
                     printf ("ERROR during flush\n");
                  }
                  if (I2C_OK != ioctl(fd, IO_IOCTL_I2C_STOP, NULL)) {
                     printf ("ERROR during stop\n");
                  }
               }
            }
            if (fd) fclose(fd);
            if (buf) _mem_free(buf);              
         } else {
            printf("Error, invalid parameter\n");
         }         
         
      } else {
         printf("Error, %s invoked with incorrect number of arguments\n", argv[0]);
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <device> <address> <bytes>\n", argv[0]);
      } else  {
         printf("Usage: %s <device> <address> <bytes>\n", argv[0]);
         printf("   <device>   = I2C device name (eg: i2c0:)\n");
         printf("   <address>  = i2c device address in hex\n");
         printf("   <bytes>    = bytes to read (decimal)\n");
      }
   }
   return return_code;
} /* Endbody */
コード例 #22
0
ファイル: cdc_serial.c プロジェクト: BillyZhangZ/wifi
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 */
コード例 #23
0
int32_t  Shell_disect(int32_t argc, char *argv[] )
{ /* Body */
   int32_t            return_code = SHELL_EXIT_SUCCESS;
   bool           print_usage, shorthelp = FALSE;
   uint32_t           sector,num_sectors;
   int32_t            offset=0;
   MQX_FILE_PTR      fd, fs;
   uint32_t           e,i;
   unsigned char         *buffer;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if ((argc < 2) || (argc > 5)) {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else if ( !Shell_parse_uint_32(argv[1], (uint32_t *) &offset ))  {
         printf("Error, invalid length\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         num_sectors = 1;
         
         if (argc >= 3) {
            if ( !Shell_parse_uint_32(argv[2], (uint32_t *) &num_sectors )) {
               num_sectors = 1;
            }
         }      
         if (argc >= 4) {
            fd = fopen(argv[3], "r");
            if (!fd) { 
               printf("Error, unable to open file %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }
         } else {
            fs = Shell_get_current_filesystem(argv);
            _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd);
         }
         
         if (fd)  {
            buffer = _mem_alloc(SECTOR_SIZE);
            if (buffer) {
               for(sector=0;sector<num_sectors;sector++) {
                  if (fseek(fd, offset+sector, IO_SEEK_SET) == IO_ERROR)  {
                     printf("Error, unable to seek to sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else if (_io_read(fd, (char *) buffer, 1) != 1) {
                     printf("Error, unable to read sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else { 
                     printf("\nSector # %d\n",offset+sector);
                     for (e=0;e<16;e++)  {
                        for (i=0;i<32;i++) {
                           printf("%02x ",(uint32_t) buffer[e*32+i]);
                        }
                        printf("\n");
                     }
                  }
               }
               _mem_free(buffer);
            }
         }
         printf("\n");
         if (argc >= 4) {
            fclose(fd);
         }
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <sector> [<device>]\n", argv[0]);
      } else  {
         printf("Usage: %s <sector> [<device>]\n", argv[0]);
         printf("   <sector>     = sector number\n");
         printf("   <device>     = low level device\n");
      }
   }
   
   return return_code;
} /* Endbody */
コード例 #24
0
ファイル: sh_dir.c プロジェクト: Wangwenxue/FutureMove-T-box
int32_t  Shell_dir(int32_t argc, char *argv[] )
{ /* Body */
   bool              print_usage, shorthelp = FALSE;
   int32_t               return_code = SHELL_EXIT_SUCCESS;
   int32_t               len;
   MQX_FILE_PTR         fs_ptr;
   char             *path_ptr, *mode_ptr;
   void                *dir_ptr;
   char             *buffer = NULL;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int32_t               error = 0;


   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc > 3)  {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         path_ptr  ="*.*";
         mode_ptr = "m";
         if (argc >= 2)  {
            path_ptr = argv[1];
            if (argc== 3)  {
               mode_ptr = argv[2];
            }
         }
         
         fs_ptr = Shell_get_current_filesystem(argv);
         /* check if filesystem is mounted */ 
         if (fs_ptr == NULL)  {
             printf("Error, file system not mounted\n");
             return_code = SHELL_EXIT_ERROR;
         } else  {
            buffer = _mem_alloc(BUFFER_SIZE);
            error = ioctl(fs_ptr, IO_IOCTL_CHANGE_CURRENT_DIR, shell_ptr->CURRENT_DIR);
            if (buffer && !error) {
            
               dir_ptr = _io_mfs_dir_open(fs_ptr, path_ptr, mode_ptr );
            
               if (dir_ptr == NULL)  {
                  printf("File not found.\n");
                  return_code = SHELL_EXIT_ERROR;
               } else {
                  while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read(dir_ptr, buffer, BUFFER_SIZE)) > 0) {
                     printf(buffer);
                  } 
                  _io_mfs_dir_close(dir_ptr);
               }
               _mem_free(buffer);
            } else {
               if(buffer == NULL){
                 printf("Error, unable to allocate space.\n" );
               } else {
                 printf("Error, directory does not exist.\n" );
               }
               return_code = SHELL_EXIT_ERROR;
            }
         }
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s [<filespec>] [<attr>]]\n", argv[0]);
      } else  {
         printf("Usage: %s [<filespec> [<attr>]]\n", argv[0]);
         printf("   <filespec>   = files to list\n");
         printf("   <attr>       = attributes of files: adhrsv*\n");
      }
   }
   return return_code;
} /* Endbody */
コード例 #25
0
ファイル: sockio.c プロジェクト: gxliu/MQX_3.8.0
_mqx_int _io_socket_ioctl
   (
      MQX_FILE_PTR fd_ptr,
      _mqx_uint   cmd,
      pointer     param_ptr
   )
{ /* Body */
   IO_SOCKET_PTR  io_ptr;
   _mqx_int       result = IO_ERROR, bytes;
   uint_32        size;

   io_ptr = fd_ptr->DEV_DATA_PTR;
   if (io_ptr != NULL) {
      switch (cmd) {
         case IO_IOCTL_CHAR_AVAIL:
            if (RTCS_selectset(&io_ptr->SOCKET, 1, (uint_32)-1)) {
               *(boolean _PTR_)param_ptr = TRUE;
            } else {
               *(boolean _PTR_)param_ptr = FALSE;
            } /* Endif */
            result=MQX_OK;
            break;         
      
         case IO_IOCTL_FLUSH_OUTPUT:
            if (io_ptr->COUNT) {
               bytes = send(io_ptr->SOCKET, io_ptr->BUFFER, io_ptr->COUNT, 0);
               if (bytes==io_ptr->COUNT) {
                  io_ptr->COUNT = 0;
                  result = MQX_OK;
               }
            } else {
               result = MQX_OK;
            }
            break;
            
         case IO_IOCTL_SET_BLOCK_MODE:
            size = *(uint_32_ptr)param_ptr;
            result=MQX_OK;
            if (size != io_ptr->SIZE) {
               // First, clear out the old buffer
               if (io_ptr->BUFFER) {
                  if (io_ptr->COUNT) {
                     bytes = send(io_ptr->SOCKET, io_ptr->BUFFER, io_ptr->COUNT, 0);
                     io_ptr->COUNT = 0;
                  }
                  _mem_free(io_ptr->BUFFER);
                  io_ptr->BUFFER = NULL;
               }
            
               if (size) {
                  // Size is set, entering block mode
                  if (size < SOCKIO_MIN_BUFFER) {
                     size = SOCKIO_MIN_BUFFER;
                  }
                  if (size > SOCKIO_MAX_BUFFER) {
                     size = SOCKIO_MAX_BUFFER;
                  }

                  io_ptr->BUFFER = _mem_alloc(size);
                  if (io_ptr->BUFFER==NULL) {
                     size = 0;
                     result = IO_ERROR;
                  } else {
                     _io_socket_set_send_push(io_ptr->SOCKET, TRUE);
                  }
                  
               }                     

               io_ptr->SIZE = size;
            }
            break;      
            
         case IO_IOCTL_GET_BLOCK_SIZE:
            result=MQX_OK;
            *(boolean _PTR_)param_ptr = io_ptr->SIZE;
            break;
            
       }      
   }

   return result;

} /* Endbody */
コード例 #26
0
ファイル: sh_di.c プロジェクト: zhouglu/K60F120M
int_32  Shell_di(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   int_32            offset;

   MQX_FILE_PTR      fd, fs;

   uint_32           backup=0;
   uchar_ptr         buffer=NULL;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if ((argc < 2 ) || (argc > 3)) {
         printf("Invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else if ( !Shell_parse_uint_32(argv[1], (uint_32_ptr) &offset ))  {
         printf("Error, invalid length\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         buffer = _mem_alloc(SECTOR_SIZE);
         if (buffer==NULL) {
            printf("Error, unable to allocate sector buffer\n");
            return  SHELL_EXIT_ERROR;
         }

         if (argc==3) {
            fd = fopen(argv[2], "b");
         } else {   
            fs = Shell_get_current_filesystem(argv);
            _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd);
         }
              

         if (fd)  {
            if (fseek(fd, offset, IO_SEEK_SET) == IO_ERROR)  {
               printf("Error, unable to seek to sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) {
               printf("Error, unable to read sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }
            
            if (return_code == SHELL_EXIT_SUCCESS) {
               printf("\n");
               backup = print_bpb(buffer);
               if (backup) {
                  if (fseek(fd, backup, IO_SEEK_SET) == IO_ERROR)  {
                     printf("Error, unable to seek to sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) {
                     printf("Error, unable to read sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  }  
                  if (return_code == SHELL_EXIT_SUCCESS) {
                     printf("\n");
                     print_bpb(buffer);
                  }
               }
            }
            if (fseek(fd, 1, IO_SEEK_SET) == IO_ERROR)  {
               printf("Error, unable to seek to sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) {
               printf("Error, unable to read sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }  
            if (return_code == SHELL_EXIT_SUCCESS) {
               printf("\n");
               print_fsi(buffer);
            }
            if (argc==3) {
               fclose(fd);
            }
         }
         _mem_free(buffer);
      }
   }
   
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <sector> [<device>]\n", argv[0]);
      } else  {
         printf("Usage: %s <sector> [<device>]\n", argv[0]);
         printf("   <sector>     = sector number\n");
         printf("   <device>     = low level device\n");
      }
   }
   return return_code;
} /* Endbody */
コード例 #27
0
ファイル: sh_dirent.c プロジェクト: mihaSoro/MQX-3.7.0
int_32  Shell_dirent(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   uint_32           sector,num_sectors;
   int_32            offset;
   MQX_FILE_PTR      fd, fs;
   uint_32           e;
   uchar_ptr         buffer;
   MFS_DIR_ENTRY_PTR dirents;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if ((argc < 2) || (argc > 4)) {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else if ( !Shell_parse_uint_32(argv[1], (uint_32_ptr) &offset ))  {
         printf("Error, invalid length\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         num_sectors = 1;
         
         if (argc >= 3) {
            if ( !Shell_parse_uint_32(argv[2], (uint_32_ptr) &num_sectors )) {
               num_sectors = 1;
            }
         }      
         if (argc == 4) {
            fd = fopen(argv[3], "r");
            if (!fd) { 
               printf("Error, unable to open file %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }
         } else {
            fs = Shell_get_current_filesystem(argv);
            _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd);
         }

         if (fd)  {
            buffer = _mem_alloc(SECTOR_SIZE);
            if (buffer) {
               for(sector=0;sector<num_sectors;sector++) {
                  if (fseek(fd, offset+sector, IO_SEEK_SET) == IO_ERROR)  {
                     printf("Error, unable to seek to sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else  if (_io_read(fd, (char_ptr) buffer, 1) !=1) {
                     printf("Error, unable to read sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else if (!is_zero(buffer, SECTOR_SIZE)) {
                     printf("\nEntry # %d",offset+sector);
                     dirents = (MFS_DIR_ENTRY_PTR) buffer;

                     for (e=0;e<DIRENTS_PER_SECTOR;e++)  {
                        print_dirent(&dirents[e]);
                     }
                     printf("\n");
                  }
               }
               _mem_free(buffer);
            } else {
               printf("Error, unable to allocate sector buffer.\n" );
               return_code = SHELL_EXIT_ERROR;
            }
            if (argc >= 4) {
               fclose(fd);
            }
         }
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <sector> [<device>]\n", argv[0]);
      } else  {
         printf("Usage: %s <sector> [<device>]\n", argv[0]);
         printf("   <sector>     = sector number\n");
         printf("   <device>     = low level device\n");
      }
   }
   return return_code;
} /* Endbody */
コード例 #28
0
ファイル: hidmouse.c プロジェクト: Gargy007/eGUI
void Mouse_Task( uint32_t param )
{
    USB_STATUS              status = USB_OK;
    TR_INIT_PARAM_STRUCT    tr;
    HID_COMMAND_PTR         hid_com;
    unsigned char               *buffer;
    PIPE_STRUCT_PTR         pipe;
    uint32_t                 e;
    _usb_host_handle        mouse_host_handle = (_usb_host_handle) param;
   
    hid_com = (HID_COMMAND_PTR) _mem_alloc(sizeof(HID_COMMAND));

    /* event for USB callback signaling */
    _lwevent_create(&USB_Mouse_Event, LWEVENT_AUTO_CLEAR);

    printf("\nMQX USB HID Mouse Demo\nWaiting for USB Mouse to be attached...\n");
    fflush(stdout);
   
    /*
    ** Infinite loop, waiting for events requiring action
    */
    for ( ; ; ) {
    
        // Wait for insertion or removal event
        _lwevent_wait_ticks(&USB_Mouse_Event, USB_EVENT_CTRL, FALSE, 0);
        
        switch ( mouse_hid_device.DEV_STATE ) {
            case USB_DEVICE_IDLE:
                break;
            case USB_DEVICE_ATTACHED:
                printf("\nMouse device attached\n");
                fflush(stdout);
                mouse_hid_device.DEV_STATE = USB_DEVICE_SET_INTERFACE_STARTED;
                status = _usb_hostdev_select_interface(mouse_hid_device.DEV_HANDLE, mouse_hid_device.INTF_HANDLE, (void *)&mouse_hid_device.CLASS_INTF);
                if (status != USB_OK) {
                    printf("\nError in _usb_hostdev_select_interface: %x", status);
                    fflush(stdout);
                    _task_block();
                } /* Endif */
                break;
            case USB_DEVICE_SET_INTERFACE_STARTED:
                break;

            case USB_DEVICE_INTERFACED:
                pipe = _usb_hostdev_find_pipe_handle(mouse_hid_device.DEV_HANDLE, mouse_hid_device.INTF_HANDLE, USB_INTERRUPT_PIPE, USB_RECV);
                if (pipe == NULL) {
                    printf("\nError getting interrupt pipe.");
                    fflush(stdout);
                    _task_block();
                }
                _usb_hostdev_get_buffer(mouse_hid_device.DEV_HANDLE, pipe->MAX_PACKET_SIZE, (void **) &buffer);
                if (buffer == NULL) {
                    printf("\nMemory allocation failed. STATUS: %x", status);
                    fflush(stdout);
                    _task_block();
                }

                printf("Mouse interfaced, setting protocol...\n");
                /* now we will set the USB Hid standard boot protocol */
                mouse_hid_device.DEV_STATE = USB_DEVICE_SETTING_PROTOCOL;
            
                hid_com->CLASS_PTR = (CLASS_CALL_STRUCT_PTR)&mouse_hid_device.CLASS_INTF;
                hid_com->CALLBACK_FN = usb_host_hid_mouse_ctrl_callback;
                hid_com->CALLBACK_PARAM = 0;
            
                status = usb_class_hid_set_protocol(hid_com, USB_PROTOCOL_HID_MOUSE);
         
                if (status != USB_STATUS_TRANSFER_QUEUED) {
                      printf("\nError in usb_class_hid_set_protocol: %x", status);
                      fflush(stdout);
                }
                break;
            case USB_DEVICE_INUSE:
                printf("Mouse device ready, try to move the mouse\n");
                while (1) {
                    /******************************************************************
                    Initiate a transfer request on the interrupt pipe
                    ******************************************************************/
                    usb_hostdev_tr_init(&tr, usb_host_hid_mouse_recv_callback, NULL);
                    tr.G.RX_BUFFER = buffer;
                    tr.G.RX_LENGTH = pipe->MAX_PACKET_SIZE;                     
                        
                    status = _usb_host_recv_data(mouse_host_handle, pipe, &tr);
                        
                    if (status != USB_STATUS_TRANSFER_QUEUED) {
                        printf("\nError in _usb_host_recv_data: %x", status);
                        fflush(stdout);
                    }
                    
                    /* Wait untill we get the data from keyboard. */
                    _lwevent_wait_ticks(&USB_Mouse_Event, USB_EVENT_CTRL | USB_EVENT_DATA | USB_EVENT_DATA_CORRUPTED, FALSE, 0);
                        
                    e = _lwevent_get_signalled();
                    if (USB_EVENT_DATA == e) {
                        if(mouse_hid_device.DEV_STATE == USB_DEVICE_INUSE) {
                            process_mouse_buffer((unsigned char *)buffer);
                        }
                    }
                    else if (USB_EVENT_CTRL == e) {
                        /* kick the outer loop again to handle the CTRL event */
                        _lwevent_set(&USB_Mouse_Event, USB_EVENT_CTRL);
                        break;
                    }
                }
                break;
            case USB_DEVICE_DETACHED:
                printf("Going to idle state\n");
                mouse_hid_device.DEV_STATE = USB_DEVICE_IDLE;
                break;
            case USB_DEVICE_OTHER:
                break;
             default:
                printf("Unknown Mouse Device State = %d\n", mouse_hid_device.DEV_STATE);
                fflush(stdout);
                break;
        } /* Endswitch */
    } /* Endfor */
} /* Endbody */
コード例 #29
0
ファイル: sh_search_file_1.c プロジェクト: gxliu/MQX_3.8.0
int_32  Shell_search_file_r(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   int_32               len;
   MQX_FILE_PTR         fs_ptr;
   char_ptr             path_ptr, mode_ptr;
   pointer              dir_ptr;
   char_ptr             buffer = NULL;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int_32               error = 0;
   char_ptr             file_name,source_name; 
   MFS_SEARCH_DATA search_data;
   pointer      search_ptr;
   DIR_STRUCT_PTR dir_file; // wk @130405 -->
   dir_file = _mem_alloc_zero( sizeof( DIR_STRUCT ));  // wk @130405 -->
   
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc > 2)  {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         path_ptr  ="*.*";
         mode_ptr = "m";

         source_name=argv[1];
         
         fs_ptr = Shell_get_current_filesystem(argv);
         /* check if filesystem is mounted */ 
         if (fs_ptr == NULL)  {
             printf("Error, file system not mounted\n");
             return_code = SHELL_EXIT_ERROR;
         } else  {
            buffer = _mem_alloc(BUFFER_SIZE);
            error = ioctl(fs_ptr, IO_IOCTL_CHANGE_CURRENT_DIR, shell_ptr->CURRENT_DIR);
            if (buffer && !error) {
            
               dir_ptr = _io_mfs_dir_open(fs_ptr, path_ptr, mode_ptr );
            
               if (dir_ptr == NULL)  {
                  printf("File not found.\n");
                  return_code = SHELL_EXIT_ERROR;
               } else {
                 
                 
//                  while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read_wk(dir_ptr, buffer, BUFFER_SIZE )) > 0) {  // wk @130405-->old
                  while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read_wk1(dir_ptr, buffer, BUFFER_SIZE,dir_file )) > 0) {
//                    printf ("%-12.12s  %6lu \n"
//                    ,dir_ptr_g->SEARCH_DATA.NAME, dir_ptr_g->SEARCH_DATA.FILE_SIZE);
//                    file_name=dir_ptr_g->SEARCH_DATA.NAME;   // wk @130405-->old                   
                    printf ("%-12.12s  %6lu \n"
                    ,dir_file->SEARCH_DATA.NAME, dir_file->SEARCH_DATA.FILE_SIZE);
//                    file_name=dir_ptr_g->SEARCH_DATA.NAME; // wk @130405-->old
                    file_name=dir_file->SEARCH_DATA.NAME;
                    if(argc==2)
                    {
                      while(*(source_name)!='\0')
                       if(*(file_name++)!= *(source_name++))
                        goto next;
                      
                       error=33;   // WK --> 文件找到
                       break;     
                    }
 next:                 source_name=argv[1];                     
                  } 
                  if(argc==2)
                  printf("error=%d if /t33表示文件找到\n",error);
                  _io_mfs_dir_close(dir_ptr);
               }
               
               _mem_free(buffer);
               _mem_free(dir_file);
            } else {
               if(buffer == NULL){
                 printf("Error, unable to allocate space.\n" );
               } else {
                 printf("Error, directory does not exist.\n" );
               }
               return_code = SHELL_EXIT_ERROR;
            }
         }
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s [<filename>]\n", argv[0]);
      } else  {
         printf("Usage: %s [<filespec> [<attr>]]\n", argv[0]);
         printf("   <filename>   = filename what want to fine\n");
      }
   }
   return return_code;
} /* Endbody */
コード例 #30
0
ファイル: dac_ldd.c プロジェクト: mihaSoro/MQX-3.7.0
LDD_TDeviceDataPtr DAC_Init (
    /* [IN] Pointer to the RTOS device structure. */
    LDD_RTOS_TDeviceDataPtr     RTOSDeviceData
)
{
    DAC_MemMapPtr       DAC_BasePtr;
    DAC_TDeviceDataPtr  DAC_DeviceDataPtr;
    uint_32             DAC_DeviceNumber = RTOSDeviceData->DAC_DEVICE_NUMBER;
    uint_32             i; 
    
    /* Initilize DAC module base address */
    if (NULL == (DAC_BasePtr = _bsp_get_dac_base_address(DAC_DeviceNumber)))   {
        return NULL;      /* No such DAC device */
    }


    if (NULL == (DAC_DeviceDataPtr = _mem_alloc((_mem_size)sizeof(DAC_TDeviceData))))  {
        return NULL;      /* MQX_OUT_OF_MEMORY */
    }

    /* Store the RTOS device structure */
    DAC_DeviceDataPtr->RTOS_DeviceData = *RTOSDeviceData;

    /* Store DAC module base address */
    DAC_DeviceDataPtr->DAC_MODULE_BASE_PTR = DAC_BasePtr;
    
    
    DAC_DeviceDataPrv[DAC_DeviceNumber] = DAC_DeviceDataPtr;
    
    /* Disable device */
    DAC_PDD_DisableDevice(DAC_BasePtr); 


    /* Interrupt vector(s) installation */
    if (NULL == _int_install_isr ( _bsp_get_dac_vector(DAC_DeviceNumber), 
                                  (void (_CODE_PTR_))DAC_BufferInterrupt, 
                                  (pointer)DAC_DeviceDataPtr)) 
    {
        _mem_free(DAC_DeviceDataPtr);    
    
        return NULL;    
    }
    
    
    /* Clear DAC DATA registers */
    for (i = 0; i < 16; i++)    {
        DAC_DAT_REG(DAC_BasePtr, i) = (uint_16)0x0000;
    }

    /* Set buffer upper limit to 16 words */
    DAC_PDD_SetBufferSize(DAC_BasePtr, (DAC_BUFFER_MAX_SIZE - 1)); 
        
    DAC_PDD_EnableBuffer(DAC_BasePtr, PDD_ENABLE);    
    
    /* Select DAC Buffer Work Mode  */
    switch(DAC_DeviceDataPtr->RTOS_DeviceData.DAC_MODE)
    {

        case LDD_DAC_BUFFER_NORMAL_MODE:
            DAC_PDD_SelectBufferMode(DAC_BasePtr, DAC_PDD_BUFFER_NORMAL_MODE);
            break;
                    
        case LDD_DAC_BUFFER_SWING_MODE:
            DAC_PDD_SelectBufferMode(DAC_BasePtr, DAC_PDD_BUFFER_SWING_MODE);
            break;
            
        case LDD_DAC_BUFFER_OTSCAN_MODE:
            DAC_PDD_SelectBufferMode(DAC_BasePtr, DAC_PDD_BUFFER_OTSCAN_MODE);
            break;    

        case LDD_DAC_BUFFER_DISABLED:
        default:
            DAC_PDD_EnableBuffer(DAC_BasePtr, PDD_DISABLE);
            break;
    }
    
    /* DAC reference selection */
    DAC_PDD_SelectReference(DAC_BasePtr, DAC_DeviceDataPtr->RTOS_DeviceData.DAC_REFSEL);
                                                                
    /* DAC trigger selection */
    DAC_PDD_SelectTrigger(DAC_BasePtr, DAC_DeviceDataPtr->RTOS_DeviceData.DAC_TRIGER_MODE);


    /* Clear all interrupt flags */
    DAC_PDD_ClearInterruptFlags(DAC_BasePtr, DAC_AVAILABLE_EVENTS_MASK); 

    /* Check if valid buffer start callback is installed */    
    if (DAC_DeviceDataPtr->RTOS_DeviceData.DAC_PDD_BUFFER_START_CALLBACK != NULL)    {
        /* Enable start buffer interrupt */
        DAC_PDD_EnableInterrupts(DAC_BasePtr, DAC_PDD_BUFFER_START_INT); 
    }    

    /* Check if valid watermark callback is installed */    
    if (DAC_DeviceDataPtr->RTOS_DeviceData.DAC_PDD_BUFFER_WATERMARK_CALLBACK != NULL)   {
        
        /* Enable Watermark interrupt */
        DAC_PDD_EnableInterrupts(DAC_BasePtr, DAC_PDD_BUFFER_WATERMARK_INT); 
    }    

    /* Check if valid buffer end callback is installed */    
    if (DAC_DeviceDataPtr->RTOS_DeviceData.DAC_PDD_BUFFER_END_CALLBACK != NULL)    {
        /* Enable Watermark interrupt */
        DAC_PDD_EnableInterrupts(DAC_BasePtr, DAC_PDD_BUFFER_END_INT);
    }    

    /* Return pointer to the data data structure */
    return (DAC_DeviceDataPtr); 
}