Exemple #1
0
/* receive files */
static rt_err_t zrec_files(struct zfile *zf)
{
	rt_uint8_t *rxbuf;
	rt_err_t res = -RT_ERROR;

	zinit_parameter();
	rxbuf = rt_malloc(RX_BUFFER_SIZE*sizeof(rt_uint8_t));
	if (rxbuf == RT_NULL) {
		rt_kprintf("rxbuf: out of memory\r\n");
		return -RT_ERROR;
	}
	rt_kprintf("\r\nrz: ready...\r\n");	   /* here ready to receive things */
	if ((res = zrec_init(rxbuf,zf))!= RT_EOK) {
		rt_kprintf("\b\b\breceive init failed\r\n");
		rt_free(rxbuf);
		return -RT_ERROR;
	}
	res = zrec_file(rxbuf,zf);
	if (res == ZFIN) {
		rt_free(rxbuf);
		return RT_EOK;	     /* if finish session */
	} else if (res == ZCAN) {
		rt_free(rxbuf);
		return ZCAN;        /* cancel by sender */
	} else {
		zsend_can();
		rt_free(rxbuf);
		return res;
	}
}
Exemple #2
0
void player_update_list()
{
	int index;
	struct play_item* item;

	if (music_listitems != RT_NULL)
	{
		for (index = 0; index < music_listitems_size; index ++)
		{
			rt_free(music_listitems[index].name);
		}

		rt_free(music_listitems);
		music_listitems = RT_NULL;
		music_listitems_size = 0;
	}

	music_listitems_size = play_list_items();
	if (music_listitems_size > 0)
	{
		music_listitems = (struct rtgui_listbox_item*) rt_malloc (
			music_listitems_size * sizeof(struct rtgui_listbox_item));
		for (index = 0; index < music_listitems_size; index ++)
		{
			music_listitems[index].image = RT_NULL;
			item = play_list_item(index);
			music_listitems[index].name = rt_strdup(item->title);
		}
	}

	/* re-set listbox items */
	rtgui_listbox_set_items(music_listbox,
		music_listitems, music_listitems_size);
}
Exemple #3
0
RTAI_SYSCALL_MODE int rt_msgq_init(RT_MSGQ *mq, int nmsg, int msg_size)
{
	int i;
	void *p;

	if (!(mq->slots = rt_malloc((msg_size + RT_MSGH_SIZE + sizeof(void *))*nmsg + RT_MSGH_SIZE))) {
		return -ENOMEM;
	}
	mq->nmsg  = nmsg;
	mq->fastsize = msg_size;
	mq->slot = 0;
	p = mq->slots + nmsg;
	for (i = 0; i < nmsg; i++) {
		mq->slots[i] = p;
		((RT_MSGH *)p)->priority = 0;
		p += (msg_size + RT_MSGH_SIZE);
	}
	((RT_MSGH *)(mq->firstmsg = p))->priority = (0xFFFFFFFF/2);
	rt_typed_sem_init(&mq->receivers, 1, RES_SEM);
	rt_typed_sem_init(&mq->senders, 1, RES_SEM);
	rt_typed_sem_init(&mq->received, 0, CNT_SEM);
	rt_typed_sem_init(&mq->freslots, nmsg, CNT_SEM);
	spin_lock_init(&mq->lock);
	return 0;
}
Exemple #4
0
void* dlopen(const char *filename, int flags)
{
	rt_module_t module;
	char *fullpath;
	const char*def_path = MODULE_ROOT_DIR;

	/* check parameters */
	RT_ASSERT(filename != RT_NULL);

	if (filename[0] != '/') /* it's a absolute path, use it directly */
	{
		fullpath = rt_malloc(strlen(def_path) + strlen(filename) + 2);

		/* join path and file name */
		rt_snprintf(fullpath, strlen(def_path) + strlen(filename) + 2, 
			"%s/%s", def_path, filename);
	}
	
	/* find in module list */
	module = rt_module_find(fullpath);
	
	if(module != RT_NULL) module->nref++;
	else module = rt_module_open(fullpath);

	rt_free(fullpath);
	return (void*)module;
}
static void resp_handler(struct spi_wifi_eth *wifi_device, struct spi_wifi_resp *resp)
{
    struct spi_wifi_resp *resp_return;

    switch (resp->cmd)
    {
    case SPI_WIFI_CMD_INIT:
        WIFI_DEBUG("resp_handler SPI_WIFI_CMD_INIT\n");
        resp_return = (struct spi_wifi_resp *)rt_malloc(sizeof(struct spi_wifi_resp)); //TODO:
        memcpy(resp_return, resp, 10);
        rt_mb_send(&wifi_device->spi_wifi_cmd_mb, (rt_uint32_t)resp_return);
        break;

    case SPI_WIFI_CMD_SCAN:
        WIFI_DEBUG("resp_handler SPI_WIFI_CMD_SCAN\n");
        break;

    case SPI_WIFI_CMD_JOIN:
        WIFI_DEBUG("resp_handler SPI_WIFI_CMD_JOIN\n");
        wifi_device->active = 1;
        eth_device_linkchange(&wifi_device->parent, RT_TRUE);
        break;

    default:
        WIFI_DEBUG("resp_handler %d\n", resp->cmd);
        break;
    }

}
Exemple #6
0
int rs485_system_init(void)
{
    rt_err_t result;
    rt_thread_t init_thread;

	rs485_send_mut = rt_mutex_create("rs485mut",RT_IPC_FLAG_FIFO);
		
	rs485_data_init();	
	


    uart1_dev_my = (struct _uart_dev_my*)rt_malloc(sizeof(struct _uart_dev_my));
    if (uart1_dev_my == RT_NULL)
    {
        rt_kprintf("no memory for shell\n");
        return -1;
    }
    memset(uart1_dev_my, 0, sizeof(struct _uart_dev_my));
    rt_sem_init(&(uart1_dev_my->rx_sem), "rs485rx", 0, 0);
	uart1_dev_my->device = RT_NULL;
	uart1_rs485_set_device();

	
	
	
	uart1_sem = rt_sem_create("uart1_sem",0, RT_IPC_FLAG_FIFO);  


		init_thread = rt_thread_create("rs485",rt_rs485_thread_entry, RT_NULL,
                                   4092, 8, 21);
	  if (init_thread != RT_NULL)
        rt_thread_startup(init_thread);

    return 0;
}
AUTH *authnone_create()
{
	register struct authnone_private *ap = authnone_private;
	XDR xdr_stream;
	register XDR *xdrs;
    extern bool_t xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap);

	if (ap == 0) {
		ap = (struct authnone_private *) rt_malloc (sizeof(*ap));
		if (ap == 0) return NULL;
		memset(ap, 0, sizeof(*ap));
		authnone_private = ap;
	}
	if (!ap->mcnt) {
		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
		ap->no_client.ah_ops = &ops;
		xdrs = &xdr_stream;
		xdrmem_create(xdrs, ap->marshalled_client,
					  (unsigned int) MAX_MARSHEL_SIZE, XDR_ENCODE);
		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
		ap->mcnt = XDR_GETPOS(xdrs);
		XDR_DESTROY(xdrs);
	}
	return (&ap->no_client);
}
Exemple #8
0
/**
 * This function will create a thread object and allocate thread object memory
 * and stack.
 *
 * @param name the name of thread, which shall be unique
 * @param entry the entry function of thread
 * @param parameter the parameter of thread enter function
 * @param stack_size the size of thread stack
 * @param priority the priority of thread
 * @param tick the time slice if there are same priority thread
 *
 * @return the created thread object
 */
rt_thread_t rt_thread_create(const char *name,
                             void (*entry)(void *parameter),
                             void       *parameter,
                             rt_uint32_t stack_size,
                             rt_uint8_t  priority,
                             rt_uint32_t tick)
{
    struct rt_thread *thread;
    void *stack_start;

    thread = (struct rt_thread *)rt_object_allocate(RT_Object_Class_Thread,
                                                    name);
    if (thread == RT_NULL)
        return RT_NULL;

    stack_start = (void *)rt_malloc(stack_size);
    if (stack_start == RT_NULL)
    {
        /* allocate stack failure */
        rt_object_delete((rt_object_t)thread);

        return RT_NULL;
    }

    _rt_thread_init(thread,
                    name,
                    entry,
                    parameter,
                    stack_start,
                    stack_size,
                    priority,
                    tick);

    return thread;
}
Exemple #9
0
/**
 * This function will allocate an object from object system
 *
 * @param type the type of object
 * @param name the object name. In system, the object's name must be unique.
 *
 * @return object
 */
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
{
    struct rt_object* object;
    register rt_base_t temp;
    struct rt_object_information* information;

    RT_DEBUG_NOT_IN_INTERRUPT;

#ifdef RT_USING_MODULE
    /* get module object information, module object should be managed by kernel object container */
    information = (rt_module_self() != RT_NULL && (type != RT_Object_Class_Module)) ?
                  &rt_module_self()->module_object[type] : &rt_object_container[type];
#else
    /* get object information */
    information = &rt_object_container[type];
#endif

    object = (struct rt_object*)rt_malloc(information->object_size);
    if (object == RT_NULL)
    {
        /* no memory can be allocated */
        return RT_NULL;
    }

    /* initialize object's parameters */

    /* set object type */
    object->type = type;

    /* set object flag */
    object->flag = 0;

#ifdef RT_USING_MODULE
    if(rt_module_self() != RT_NULL)
    {
        object->flag |= RT_OBJECT_FLAG_MODULE;
    }
    object->module_id = (void*)rt_module_self();
#endif

    /* copy name */
    for (temp = 0; temp < RT_NAME_MAX; temp ++)
    {
        object->name[temp] = name[temp];
    }

    RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));

    /* lock interrupt */
    temp = rt_hw_interrupt_disable();

    /* insert object into information object list */
    rt_list_insert_after(&(information->object_list), &(object->list));

    /* unlock interrupt */
    rt_hw_interrupt_enable(temp);

    /* return object */
    return object;
}
Exemple #10
0
memp_malloc_fn(memp_t type, const char* file, const int line)
#endif
{
    void* ptr;
    rt_uint32_t size, level;

    size = memp_sizes[type];
    LWIP_DEBUGF(MEMP_DEBUG, ("memp malloc %s, size %d, ", memp_desc[type], memp_sizes[type]));

	level = rt_hw_interrupt_disable();
	if (type == MEMP_TCP_PCB)
	{
		if (tcp_pcbs >= MEMP_NUM_TCP_PCB)
		{
			rt_hw_interrupt_enable(level);
			return RT_NULL;
		}
		else
		{
			/* increased tcp pcb allocated number */
			tcp_pcbs ++;
		}
	}
	rt_hw_interrupt_enable(level);

    ptr = rt_malloc(size);
	LWIP_DEBUGF(MEMP_DEBUG, ("mem 0x%x\n", ptr));

    return ptr;
}
Exemple #11
0
static char *winpath_dirdup(char *des, const char *src)
{
    char *path;
    int i = 0;

    path = rt_malloc(FILE_PATH_MAX);
    if (path == RT_NULL)
        return RT_NULL;

    strcpy(path, des);
    strcat(path, src);

    while (1)
    {
        if (path[i] == 0)
            break;

        if (path[i] == '/')
            path[i] = '\\';

        i++;
    }

    return path;
}
Exemple #12
0
int rt_hw_lcd_init(const char *name)
{
    
    struct lcd_device *dev;
    
    if(rt_device_find(name))
    {
        return -RT_EIO;
    }
    
    dev = rt_malloc(sizeof(struct lcd_device));
    if(!dev)
    {
        return RT_ENOMEM;
    }
    
	dev->rtdev.type         = RT_Device_Class_Graphic;
	dev->rtdev.rx_indicate  = RT_NULL;
	dev->rtdev.init         = rt_lcd_init;
	dev->rtdev.open         = RT_NULL;
	dev->rtdev.close		= RT_NULL;
	dev->rtdev.read 		= RT_NULL;
	dev->rtdev.write        = RT_NULL;
	dev->rtdev.control      = rt_lcd_control;
	dev->rtdev.user_data	= RT_NULL;

    /* initialize mutex */
    rt_mutex_init(&dev->lock, name, RT_IPC_FLAG_FIFO);
    rt_device_register(&dev->rtdev, name, RT_DEVICE_FLAG_RDWR);
    return RT_EOK;
}
void rt_hw_dc_init(void)
{
	rt_device_t dc = rt_malloc(sizeof(struct rt_device));
	if (dc == RT_NULL) 
	{
		rt_kprintf("dc == RT_NULL\n");
		return; /* no memory yet */
	}

	_dc_info.bits_per_pixel = 16;
	_dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
	_dc_info.framebuffer = (rt_uint8_t*)HW_FB_ADDR;
	_dc_info.width = FB_XSIZE;
	_dc_info.height = FB_YSIZE;

	/* init device structure */
	dc->type = RT_Device_Class_Graphic;
	dc->init = rt_dc_init;
	dc->open = RT_NULL;
	dc->close = RT_NULL;
	dc->control = rt_dc_control;
	dc->user_data = (void*)&_dc_info;
	
	/* register Display Controller device to RT-Thread */
	rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR);
}
static void mainmenu_scan_apps(void)
{
    DIR *dir;
    struct dirent *dirent;
    char *path_buf;

    path_buf = rt_malloc(DFS_PATH_MAX);
    if (!path_buf)
        return;

    dir = opendir("/programs/");
    if (dir == RT_NULL)
        goto _ret;

    do
    {
        dirent = readdir(dir);
        if (dirent == RT_NULL)
            break;

        if (strcmp(dirent->d_name, ".") == 0)
            continue;
        /* readdir is not guaranteed to return "..". So we should deal with
         * it specially. */
        if (strcmp(dirent->d_name, "..") == 0)
            continue;

        mainmenu_register_app(dirent->d_name);
    }
    while (dirent != RT_NULL);
    closedir(dir);

_ret:
    rt_free(path_buf);
}
Exemple #15
0
static int _send(RT_MSGQ *mq, void *msg, int msg_size, int msgpri, int space)
{
	unsigned long flags;
	RT_MSG *msg_ptr;
	void *p;

	if (msg_size > mq->fastsize) {
		if (!(p = rt_malloc(msg_size))) {
			rt_sem_signal(&mq->freslots);
			rt_sem_signal(&mq->senders);
			return -ENOMEM;
		}
	} else {
		p = NULL;
	}
	flags = rt_spin_lock_irqsave(&mq->lock);
	msg_ptr = mq->slots[mq->slot++];
	rt_spin_unlock_irqrestore(flags, &mq->lock);
	msg_ptr->hdr.size = msg_size;
	msg_ptr->hdr.priority = msgpri;
	msg_ptr->hdr.malloc = p;
	msg_ptr->hdr.broadcast = 0;
	if (space) {
		memcpy(p ? p : msg_ptr->msg, msg, msg_size);
	} else {
		rt_copy_from_user(p ? p : msg_ptr->msg, msg, msg_size);
	}
	flags = rt_spin_lock_irqsave(&mq->lock);
	enq_msg(mq, &msg_ptr->hdr);
	rt_spin_unlock_irqrestore(flags, &mq->lock);
	rt_sem_signal(&mq->received);
	rt_sem_signal(&mq->senders);
	return 0;
}
Exemple #16
0
/******************************************************************//**
* @brief
*	Initialize all ADC module related hardware and register ADC device to kernel
*
* @details
*
* @note
*
*********************************************************************/
void rt_hw_adc_init(void)
{
	struct efm32_adc_device_t 	*adc;
	ADC_Init_TypeDef 			init = ADC_INIT_DEFAULT;

	// TODO: Fixed oversampling rate?
	init.ovsRateSel	= adcOvsRateSel4096;
	init.timebase 	= ADC_TimebaseCalc(0);
	init.prescale 	= ADC_PrescaleCalc(ADC_CONVERT_FREQUENCY, 0);

	
#ifdef RT_USING_ADC0
	adc = rt_malloc(sizeof(struct efm32_adc_device_t));
	if (adc == RT_NULL)
	{
#ifdef RT_ADC_DEBUG
		rt_kprintf("no memory for ADC driver\n");
#endif
		return;
	}
	adc->adc_device	= ADC0;
	adc->mode 		= ADC_MODE_SINGLE;

	/* Enable clock for ADCn module */
	CMU_ClockEnable(cmuClock_ADC0, true);

	/* Reset */
	 ADC_Reset(ADC0);

	/* Configure ADC */
	ADC_Init(adc->adc_device, &init);

	rt_hw_adc_register(&adc0_device, RT_ADC0_NAME, EFM32_NO_DATA, adc);	
#endif
}
Exemple #17
0
int dfs_elm_rename(struct dfs_filesystem *fs, const char *oldpath, const char *newpath)
{
    FRESULT result;

#if _VOLUMES > 1
    char *drivers_oldfn;
    const char *drivers_newfn;
    int vol;
    extern int elm_get_vol(FATFS * fat);

    /* add path for ELM FatFS driver support */
    vol = elm_get_vol((FATFS *)fs->data);
    if (vol < 0)
        return -DFS_STATUS_ENOENT;

    drivers_oldfn = rt_malloc(256);
    if (drivers_oldfn == RT_NULL)
        return -DFS_STATUS_ENOMEM;
    drivers_newfn = newpath;

    rt_snprintf(drivers_oldfn, 256, "%d:%s", vol, oldpath);
#else
    const char *drivers_oldfn, *drivers_newfn;

    drivers_oldfn = oldpath;
    drivers_newfn = newpath;
#endif

    result = f_rename(drivers_oldfn, drivers_newfn);
#if _VOLUMES > 1
    rt_free(drivers_oldfn);
#endif
    return elm_result_to_dfs(result);
}
Exemple #18
0
err_t
tcpip_input(struct pbuf *p, struct netif *inp)
{
     int i;
     u8_t *pdata;
     if (uip_len)
     {
        uip_arp_out(); 
        if (( pdata =(u8_t*)rt_malloc(1500*sizeof(u8_t))) == RT_NULL)
        {
            pbuf_free(p);
            return 1;
        }
        for (i=0; i < (UIP_LLH_LEN + 40); ++i) // 14+40 =54
        {
            pdata[i] =  uip_buf[i]; /* get dest an src ipaddr */
        }
            // Copy the data portion part  
        for(; i < uip_len; ++i)
        {
                pdata[i] =  uip_appdata[i - UIP_LLH_LEN - 40 ];
        }
        p ->payload = pdata;
        p->len = uip_len;
        inp->linkoutput(inp,p);
        rt_free(pdata);
        return 1;
    }
    else
    {
        pbuf_free(p);
        return 0;
    }  
}
void net_buf_init(rt_size_t size)
{
    rt_thread_t tid;

    /* init net buffer structure */
    _netbuf.read_index = _netbuf.save_index = 0;
    _netbuf.size = size; /* net buffer size */

    /* allocate buffer */
    _netbuf.buffer_data = rt_malloc(_netbuf.size);
	_netbuf.data_length = 0;

	/* set ready and resume water mater */
	_netbuf.ready_wm = _netbuf.size * 90/100;
	_netbuf.resume_wm = _netbuf.size * 80/100;

	/* set init stat */
	_netbuf.stat = NETBUF_STAT_STOPPED;
	rt_kprintf("stat -> stopped\n");

	_netbuf.wait_ready  = rt_sem_create("nready", 0, RT_IPC_FLAG_FIFO);
	_netbuf.wait_resume = rt_sem_create("nresum", 0, RT_IPC_FLAG_FIFO);
	_netbuf.is_wait_ready = RT_FALSE;

	/* crate message queue */
	_netbuf_mq = rt_mq_create("njob", sizeof(struct net_buffer_job),
		4, RT_IPC_FLAG_FIFO);

    /* create net buffer thread */
    tid = rt_thread_create("nbuf",
        net_buf_thread_entry, RT_NULL,
        1024, 22, 5);
    if (tid != RT_NULL)
        rt_thread_startup(tid);
}
Exemple #20
0
int rthw_wifi_scan(scan_callback_fn fun, void *data)
{
    struct scan_user_data *user_data;

    if (fun == RT_NULL)
    {
        rt_kprintf("scan callback fun is null\n");
        return -1;
    }
    user_data = rt_malloc(sizeof(struct scan_user_data));
    if (user_data == RT_NULL)
    {
        rt_kprintf("wifi scan malloc fail\n");
        return -1;
    }
    user_data->fun = fun;
    user_data->data = data;

    if (wifi_scan_networks(rthw_wifi_scan_result_handler, user_data) != RTW_SUCCESS)
    {
        rt_kprintf("ERROR: wifi scan failed\n\r");
        return -1;
    }

    return 0;
}
void calibration_entry(void* parameter)
{
    rt_device_t device;
    struct rtgui_rect rect;
    struct setup_items setup;

    device = rt_device_find("touch");
    if (device == RT_NULL) return; /* no this device */

    calibration_ptr = (struct calibration_session*)
        rt_malloc(sizeof(struct calibration_session));
    rt_memset(calibration_ptr, 0, sizeof(struct calibration_data));
    calibration_ptr->device = device;
    
    rt_device_control(calibration_ptr->device, RT_TOUCH_CALIBRATION, 
        (void*)calibration_data_post);
    
    rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
    
    /* set screen rect */
    calibration_ptr->width = rect.x2;
    calibration_ptr->height = rect.y2;

    calibration_ptr->app = rtgui_app_create("calibration");
    if (calibration_ptr->app != RT_NULL)
    {
        /* create calibration window */
        calibration_ptr->win = rtgui_win_create(RT_NULL,
            "calibration", &rect, 
            RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER | 
            RTGUI_WIN_STYLE_ONTOP | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
        if (calibration_ptr->win != RT_NULL)
        {   			
            rtgui_object_set_event_handler(RTGUI_OBJECT(calibration_ptr->win),
                calibration_event_handler);
            rtgui_win_show(calibration_ptr->win, RT_TRUE);
        }
        
        rtgui_app_destroy(calibration_ptr->app);
    }

    /* set calibration data */
    rt_device_control(calibration_ptr->device, RT_TOUCH_CALIBRATION_DATA, 
        &calibration_ptr->data);

    //save setup
    setup.touch_min_x = calibration_ptr->data.min_x;
    setup.touch_max_x = calibration_ptr->data.max_x;
    setup.touch_min_y = calibration_ptr->data.min_y;
    setup.touch_max_y = calibration_ptr->data.max_y;
    setup_save(&setup);
    
    /* recover to normal */
    rt_device_control(calibration_ptr->device, RT_TOUCH_NORMAL, RT_NULL);

    /* release memory */
    rt_free(calibration_ptr);
    calibration_ptr = RT_NULL;
}
Exemple #22
0
/* Keep old drivers compatible in RT-Thread */
rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_t flags)
{
    struct netif* netif;

    netif = (struct netif*) rt_malloc (sizeof(struct netif));
    if (netif == RT_NULL)
    {
        rt_kprintf("malloc netif failed\n");
        return -RT_ERROR;
    }
    rt_memset(netif, 0, sizeof(struct netif));

    /* set netif */
    dev->netif = netif;
    /* device flags, which will be set to netif flags when initializing */
    dev->flags = flags;
    /* link changed status of device */
    dev->link_changed = 0x00;
    dev->parent.type = RT_Device_Class_NetIf;
    /* register to RT-Thread device manager */
    rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
    rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);

    /* set name */
    netif->name[0] = name[0];
    netif->name[1] = name[1];

    /* set hw address to 6 */
    netif->hwaddr_len 	= 6;
    /* maximum transfer unit */
    netif->mtu			= ETHERNET_MTU;

    /* get hardware MAC address */
    rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);

    /* set output */
    netif->output		= etharp_output;
    netif->linkoutput	= ethernetif_linkoutput;

    /* if tcp thread has been started up, we add this netif to the system */
    if (rt_thread_find("tcpip") != RT_NULL)
    {
        struct ip_addr ipaddr, netmask, gw;

#if !LWIP_DHCP
        IP4_ADDR(&ipaddr, RT_LWIP_IPADDR0, RT_LWIP_IPADDR1, RT_LWIP_IPADDR2, RT_LWIP_IPADDR3);
        IP4_ADDR(&gw, RT_LWIP_GWADDR0, RT_LWIP_GWADDR1, RT_LWIP_GWADDR2, RT_LWIP_GWADDR3);
        IP4_ADDR(&netmask, RT_LWIP_MSKADDR0, RT_LWIP_MSKADDR1, RT_LWIP_MSKADDR2, RT_LWIP_MSKADDR3);
#else
        IP4_ADDR(&ipaddr, 0, 0, 0, 0);
        IP4_ADDR(&gw, 0, 0, 0, 0);
        IP4_ADDR(&netmask, 0, 0, 0, 0);
#endif

        netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input);
    }

    return RT_EOK;
}
void* rt_realloc(void* oldptr, int size)
{

  void* newptr;

  printk("rt_mem.c: reallocating %p with %d bytes\n",oldptr,size);

  if (oldptr==NULL) {
    newptr = rt_malloc(size);
  } else {
    newptr = rt_malloc(size);
    memcpy(newptr,oldptr,size);
    rt_free(oldptr);
  }

  return newptr;
}
Exemple #24
0
/**
 * Init, in kernel space, a tasklet structure to be used in user space.
 *
 * rt_tasklet_init allocate a tasklet structure (struct rt_tasklet_struct) in
 * kernel space to be used for the management of a user space tasklet.
 *
 * This function is to be used only for user space tasklets. In kernel space
 * it is just an empty macro, as the user can, and must  allocate the related
 * structure directly, either statically or dynamically.
 *
 * @return the pointer to the tasklet structure the user space application must
 * use to access all its related services.
 */
struct rt_tasklet_struct *rt_init_tasklet(void)
{
	struct rt_tasklet_struct *tasklet;
	if ((tasklet = rt_malloc(sizeof(struct rt_tasklet_struct)))) {
		memset(tasklet, 0, sizeof(struct rt_tasklet_struct));
	}
	return tasklet;
}
void MdTcbInit()
{
   StdAirBlock1 = (StdAirDataBase *)rt_malloc(sizeof(StdAirDataBase)); //HeapMemRequire
   rt_memset((uchar *)StdAirBlock1, 0, (sizeof(StdAirDataBase))); //ZeroMemory

   StdMdTcpInit(&MdTcp1);
   StdMdTcpInit(&MdTcp4);
}
Exemple #26
0
void *g_memdup(const void *data, uint_t data_len)
{
	void *p;

	p = rt_malloc(data_len);
	if (p != NULL)
		memcpy(p, data, data_len);
	return p;
}
int cmd_mv(int argc, char** argv)
{
    if (argc != 3)
    {
        rt_kprintf("Usage: mv SOURCE DEST\n");
        rt_kprintf("Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n");
    }
    else
    {
		int fd;
		char *dest = RT_NULL;

        rt_kprintf("%s => %s\n", argv[1], argv[2]);

		fd = open(argv[2], O_DIRECTORY, 0);
		if (fd >= 0)
		{
			char *src;
			
			close(fd);

			/* it's a directory */			
			dest = (char*)rt_malloc(DFS_PATH_MAX);
			if (dest == RT_NULL)
			{
				rt_kprintf("out of memory\n");
				return -RT_ENOMEM;
			}

			src = argv[1] + rt_strlen(argv[1]);
			while (src != argv[1]) 
			{
				if (*src == '/') break;
				src --;
			}

			rt_snprintf(dest, DFS_PATH_MAX - 1, "%s/%s", argv[2], src);
		}
		else
		{
			fd = open(argv[2], O_RDONLY, 0);
			if (fd >= 0)
			{
				close(fd);
				
				unlink(argv[2]);
			}

			dest = argv[2];
		}

		rename(argv[1], dest);
		if (dest != RT_NULL && dest != argv[2]) rt_free(dest);
    }

    return 0;
}
/*
rt_uint8_t exist_dev(dev_t *dev)
{
    rt_int8_t fd;
    rt_uint8_t i;
    struct stat buf;
    dev_t *tmpbuff = RT_NULL;
    if((fd = open(DEV, DFS_O_CREAT|DFS_O_RDWR,0))<0)
    {
        rt_kprintf("%s:%d Open %s failed\n",__func__,__LINE__,DEV);
        list_mem();
        return FAILE;
    }
//rt_kprintf("%s:%d Open %s fd = %d\n",__func__,__LINE__,DEV,fd);
    stat(DEV, &buf);
//rt_kprintf("%s:%d buf.st_size = %d\n",__func__,__LINE__,buf.st_size);
    if(buf.st_size>0)
    {
        tmpbuff = (dev_t*)rt_malloc(buf.st_size);
        rt_memset(tmpbuff,0,buf.st_size);
        if(0==tmpbuff)
        {
            rt_kprintf("%s:%d Memory allocation failure\n",__func__,__LINE__);
            goto failed;
        }
        if(read(fd,tmpbuff,buf.st_size)<buf.st_size)
        {
            rt_kprintf("%s:%d Read %s error\n",__func__,__LINE__,DEV);
            goto failed;
        }
        for(i=0;i<(buf.st_size/sizeof(dev_t));i++)
        {
            if(rt_memcmp((tmpbuff+i)->mac,dev->mac,MAC_LEN)==0)
            {
//                rt_kprintf("%s:%d device amc: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x shortadd = %04x\n",__func__,__LINE__,
//                           dev->mac[0],dev->mac[1],dev->mac[2],dev->mac[3],dev->mac[4],dev->mac[5],dev->mac[6],dev->mac[7],dev->shortadd);
                dev->stat = (tmpbuff+i)->stat;
                dev->shortadd = (tmpbuff+i)->shortadd;
//                rt_kprintf("%s:%d device amc: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x shortadd = %04x\n",__func__,__LINE__,
//                           dev->mac[0],dev->mac[1],dev->mac[2],dev->mac[3],dev->mac[4],dev->mac[5],dev->mac[6],dev->mac[7],dev->shortadd);
                goto success;
				
            }
        }
        rt_kprintf("%s:%d device not find\n",__func__,__LINE__);
    }
   goto failed;
   
success:
	if(tmpbuff)
		rt_free(tmpbuff);
	close(fd);
	return SUCCESS;
	
failed:
	if(tmpbuff)
		rt_free(tmpbuff);
	close(fd);
	return FAILE;

}
*/
rt_uint8_t exist_dev(dev_t *dev,int n)
{
    rt_int8_t fd;
    rt_uint8_t i,j;
    struct stat buf;
    dev_t *tmpbuff = RT_NULL;
    if((fd = open(DEV, DFS_O_CREAT|DFS_O_RDWR,0))<0)
    {
        rt_kprintf("%s:%d Open %s failed\n",__func__,__LINE__,DEV);
        list_mem();
        return FAILE;
    }
//rt_kprintf("%s:%d Open %s fd = %d\n",__func__,__LINE__,DEV,fd);
    stat(DEV, &buf);
//rt_kprintf("%s:%d buf.st_size = %d\n",__func__,__LINE__,buf.st_size);
    if(buf.st_size>0)
    {
        tmpbuff = (dev_t*)rt_malloc(buf.st_size);
        rt_memset(tmpbuff,0,buf.st_size);
        if(0==tmpbuff)
        {
            rt_kprintf("%s:%d Memory allocation failure\n",__func__,__LINE__);
            goto failed;
        }
        if(read(fd,tmpbuff,buf.st_size)<buf.st_size)
        {
            rt_kprintf("%s:%d Read %s error\n",__func__,__LINE__,DEV);
            goto failed;
        }
		for(j=0;j<n;j++)
		{
			for(i=0;i<(buf.st_size/sizeof(dev_t));i++)
	        {
	            if(rt_memcmp((tmpbuff+i)->mac,(dev+j)->mac,MAC_LEN)==0)
	            {
	                (dev+j)->stat = (tmpbuff+i)->stat;
	                (dev+j)->shortadd = (tmpbuff+i)->shortadd;
	            }
	        }
		}
        
    }
   goto failed;
   
success:
	if(tmpbuff)
		rt_free(tmpbuff);
	close(fd);
	return SUCCESS;
	
failed:
	if(tmpbuff)
		rt_free(tmpbuff);
	close(fd);
	return FAILE;

}
/* ethernetif APIs */
rt_err_t eth_device_init(struct eth_device* dev, const char* name)
{
	struct netif* netif;
        uip_ipaddr_t ipaddr;
	netif = (struct netif*) rt_malloc (sizeof(struct netif));
	if (netif == RT_NULL)
	{
		rt_kprintf("malloc netif failed\n");
		return -RT_ERROR;
	}
	rt_memset(netif, 0, sizeof(struct netif));

	/* set netif */
	dev->netif = netif;
	/* register to rt-thread device manager */
	rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
	dev->parent.type = RT_Device_Class_NetIf;
	rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);

	/* set name */
	netif->name[0] = name[0];
	netif->name[1] = name[1];

	/* set hw address to 6 */
	netif->hwaddr_len	= 6;
	/* maximum transfer unit */
	netif->mtu			= ETHERNET_MTU;
	/* broadcast capability */
	netif->flags		= NETIF_FLAG_BROADCAST;
	
#if LWIP_IGMP
	/* igmp support */
	netif->flags |= NETIF_FLAG_IGMP;
#endif

	/* get hardware address */
	rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);

	/* set output */
	netif->output		= ethernetif_output;
	netif->linkoutput	= ethernetif_linkoutput;

	/* add netif to lwip */
        
	if (netif_add(netif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev,
		eth_init, eth_input) == RT_NULL)
	{
		/* failed, unregister device and free netif */
		rt_device_unregister(&(dev->parent));
		rt_free(netif);
		return -RT_ERROR;
	}
        
	netif_set_default(netif);
	return RT_EOK;
}
Exemple #30
0
int getForwardReply(int index,char* from, char* to,char* msg,int msgLen,send_data_t* sptr)
{
	int len=0,dlen=0;
	char* p=NULL;
	//dlen = 2*MAX_NAME_LEN+strlen(fdReplyStr)+msgLen;
	dlen = 2*MAX_NAME_LEN+msgLen;
	len = 1+2+2+4+4+1+dlen;
	
	if((len>sptr->data_len) || sptr->data_ptr==NULL)
	{
		p = (char*)rt_malloc(len);
		if(p==NULL)
		{
			return -1;
		}
		sptr->data_ptr = p;
		sptr->data_len = len;

		rt_memset(p,0,len);
	}
	else 
	{
		p = sptr->data_ptr;
		rt_memset(p,0,sptr->data_len);
	}
	
	*p = 0x02;
	p++;
	make_net16(p,0x0001);
	p+=2;
	make_net16(p,0x0004);
	p+=2;

	make_net32(p,index);
	p+=4;

	make_net32(p,dlen);
	p+=4;

	strcpy(p,to);
	p+=MAX_NAME_LEN;

	strcpy(p,from);
	p+=MAX_NAME_LEN;

/*	strcpy(p,fdReplyStr);
	p+=strlen(fdReplyStr);
*/
//	strcpy(p,msg);
	rt_memcpy(p,msg,msgLen);
	p+=msgLen;

	*p = 0x03;

	return len;
}