Esempio n. 1
0
/**
   Initialize task memory
*/
static void task_init(task_env *t)
{
	link_init(&t->l, type_hash("task_env"));
	link_init(&t->all, type_hash("task_env"));
	t->heap_pos = 0;
	/* assert(ash_nazg_gimbatul.suc > (linkage*)0x8000000); */
	/* assert(ash_nazg_gimbatul.pred > (linkage*)0x8000000); */
	assert(ash_nazg_gimbatul.type == type_hash("task_env"));
	/* #ifdef __sun */
	/*   mem_watch(&ash_nazg_gimbatul,sizeof(&ash_nazg_gimbatul), 0); */
	/* #endif */
	link_into(&t->all, &ash_nazg_gimbatul); /* Put it in the list of all tasks */
	/* #ifdef __sun */
	/*   mem_watch(&ash_nazg_gimbatul,sizeof(&ash_nazg_gimbatul), WA_WRITE); */
	/* #endif */
	assert(ash_nazg_gimbatul.type == type_hash("task_env"));
	/* assert(ash_nazg_gimbatul.suc > (linkage*)0x8000000); */
	/* assert(ash_nazg_gimbatul.pred > (linkage*)0x8000000); */
	t->terminate = RUN;
	t->refcnt = 0;
	t->taskret = 0;
	t->time = 0.0;
	t->arg = null_arg;
	t->where = t->buf;
	t->stack_top = &t->buf[TASK_POOL_ELEMS-1];
	t->sp = t->stack_top;
	memset(t->buf, 0, TASK_POOL_ELEMS * sizeof(TaskAlign));
}
Esempio n. 2
0
tween_t * tween_new(void *ptr, tween_type_t type, unsigned int total_steps, tween_value_t start, tween_value_t end, 
                                tween_dir_t dir, tween_func_t tween_cb) {
    tween_t *tween = mem_alloc(sizeof(tween_t));
    tween->ptr.ptr = ptr;
    tween->type = type;
    tween->steps = (dir == TWEEN_IN ? 0 : total_steps);
    tween->total_steps = total_steps;
    SET_VAL(tween, tween->current, (dir == TWEEN_IN ? 0 : GET_VAL(tween, start) - GET_VAL(tween, end)));
    SET_VAL(tween, tween->end, (dir == TWEEN_IN ? GET_VAL(tween, end) - GET_VAL(tween, start) : GET_VAL(tween, start) - GET_VAL(tween, end)));
    tween->dir = dir;
    tween->tween_cb = tween_cb;
    link_init(&(tween->all_tweens_link));
    link_init(&(tween->tweens_link));
    return tween;
}
Esempio n. 3
0
File: anytimer.c Progetto: yumm007/C
/* 这个函数是不会被信号干扰的 */
static int init_timer(void) {
	struct sigaction new_act;
	sigset_t new_mask;

	if ((tim_link = link_init(sizeof(struct at_job), ins_cmp, del_cmp, emp_fun)) == NULL)
		return -3;

	/* 确保alarm信号没有被屏蔽 */
	sigemptyset(&new_mask);
	sigaddset(&new_mask, SIGALRM);
	sigprocmask(SIG_UNBLOCK, &new_mask, &old_mask);

	sigemptyset(&blc_alr_mask);
	sigaddset(&blc_alr_mask, SIGALRM);

	/* 安装alarm信号接受函数*/
	new_act.sa_handler = alr_hanlder;
	sigemptyset(&new_act.sa_mask);
	new_act.sa_flags = 0;
	if (sigaction(SIGALRM, &new_act, &old_act) == -1) 
		return -2;

	atexit(restor_hanlder);
	alarm(next_alm);
	return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    int i, ret;
    pthread_t id;

    if (argc != 3)
        exit(1);

    mylinkExtract_init();

    link_init(argv[2]);

    g_basePort = atoi(argv[1]);
    assert(g_basePort > 1024 && g_basePort < 65535);

    for (i = 0; i < 8; i++)
    {
        ret = pthread_create(&id, NULL, (void *) html_produce, NULL);
        if (ret != 0)
        {
            printf("create thr error.\n");
            exit(1);
        }
    }

    pthread_join(id, NULL);

    return 0;
}
Esempio n. 5
0
static gboolean
link_add (NMPlatform *platform, const char *name, NMLinkType type)
{
	NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
	NMFakePlatformLink device;
	LinkAddedInfo *info;

	link_init (&device, priv->links->len, type, name);

	g_array_append_val (priv->links, device);

	if (device.link.ifindex) {
		/* Platform requires LINK_ADDED signal emission from an idle handler */
		info = g_new0 (LinkAddedInfo, 1);
		info->platform = platform;
		info->ifindex = device.link.ifindex;
		info->id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
		                            link_added_emit,
		                            info,
		                            g_free);
		priv->link_added_ids = g_slist_prepend (priv->link_added_ids, GUINT_TO_POINTER (info->id));
	}

	return TRUE;
}
Esempio n. 6
0
/*------------------------------------------------------------
 * Function Name  : BootLink
 * Description    : 上电后联机
 * Input          : None
 * Output         : None
 * Return         : None
 *------------------------------------------------------------*/
void BootLink( void )
{
	uint8_t process = 0;
	uint32_t cnt = 0;
	const uint8_t FONT_SIZE = 16;
	const uint16_t draw_process_x = 360;
	const uint16_t draw_process_y = 350;											
	
	//初始化警告
	InitErr(&GeneralWarning);
	
	link_init();

	lcd_show_image(303,80,LOGO_PIC);	//加载鑫高LOGO
	
	lcd_show_image(draw_process_x-1,draw_process_y-1,PROCESS_PIC);
	
	SetGeneralTimeOut(0);
	
	while ( 1 )
	{
		link_cycle(&process);

		if (GetGeneralTimeOut() == TIMEOUT)		
		{
			SetGeneralTimeOut(10);
			cnt++;
			
			DrawProcess(FONT_SIZE,process,draw_process_x,draw_process_y);
		}
		
		LoadStartMachineWords(cnt);

		if (LINK_SUCCESS == GetLinkStatus())	   //联机成功
		{
			SetLinkStatus(LINK_IDLE);	
			
 			LssuedProtectBit();		//设置系统保护位 			
			PCM_GeneralWarningHandlerProcess(BLACK);				
			break;	
		}

		if (cnt > MIN_CNT_LINK_WAIT)					  //联机时,收到数据等待时间
		{
			if ( process )
			{
				if (cnt > MAX_CNT_LINK_WAIT)
				{
					SetLinkStatus(LINK_UNLINK);	
					break;
				}
			}
			else
			{
				SetLinkStatus(LINK_UNLINK);			
				break;
			}													
		}
	}	
}
Esempio n. 7
0
struct BM *BM_create_sparse(int x, int y)
{
    struct BM *map;
    int i;

    if (NULL == (map = (struct BM *)malloc(sizeof(struct BM))))
	return (NULL);
    map->bytes = (x + 7) / 8;

    if (NULL == (map->data = (unsigned char *)
		 malloc(sizeof(struct BMlink *) * y)))
	return (NULL);

    map->rows = y;
    map->cols = x;
    map->sparse = 1;

    link_set_chunk_size(500);
    map->token = link_init(sizeof(struct BMlink));

    for (i = 0; i < map->rows; i++) {
	((struct BMlink **)(map->data))[i] =
	    (struct BMlink *)link_new(map->token);
	((struct BMlink **)(map->data))[i]->count = x;
	((struct BMlink **)(map->data))[i]->val = 0;
	((struct BMlink **)(map->data))[i]->next = NULL;
    }


    depth++;

    return map;
}
Esempio n. 8
0
File: stat.c Progetto: Daykz/ft_ls
void				display_l_fold(char *param, t_opt *opt)
{
	t_list			*tmp;
	t_list			*list;
	t_list			*rmajfold;
	char			*str;
	int				i;

	i = 0;
	rmajfold = NULL;
	list = NULL;
	list = ft_ls(param, list, opt);
	check_total(param, list, opt);
	tmp = list;
	if (!list)
		return ;
	while (list)
	{
		str = make_path(str, param, list->data);
		if (fold_l(str, param, list, opt))
			list_add_next(&rmajfold, link_init(str));
		list = list->next;
	}
	print_l(tmp, opt);
	if (rmajfold)
		recurs(rmajfold, opt);
}
Esempio n. 9
0
//开机初始化
void All_Init( void )
{
	const uint32_t NewDeviationAddr = 0x4000;
	
	/* BootLoad引导程序时,必须在Main中添加,同时更改“魔术棒--Target选项卡的ROM偏移地址” */
	NVIC_SetVectorTable(NVIC_VectTab_FLASH,NewDeviationAddr);				
	
	/* 外设初始化 */
	lcd_init();   
	rtc_init(); 
	led_init(); 	 
	uart3_init(BAUD_38400);
	print_init();	//波特率19200
	timeout_init();
	TIM5_TimeoutInit();	
	link_init(); 
	tf_init();
	eep_init(); 
	delay_init_t2();
 	beep_init();
	SysTick_Config(SYSTICK_10MS);
	
//	PrintSystemParameter();	//串口打印系统参数信息,用于调试
	
	#ifdef ENABLE_BEEP
		BEEP_START();
	#endif
		
	set_page(system_init);
}
Esempio n. 10
0
PyMODINIT_FUNC
init_spotify(void)
{
    PyObject *m;

    if (PyType_Ready(&SessionType) < 0)
        return;
    if (PyType_Ready(&ArtistType) < 0)
        return;
    if (PyType_Ready(&ArtistBrowserType) < 0)
        return;
    if (PyType_Ready(&LinkType) < 0)
        return;
    if (PyType_Ready(&PlaylistType) < 0)
        return;
    if (PyType_Ready(&PlaylistContainerType) < 0)
        return;
    if (PyType_Ready(&ResultsType) < 0)
        return;
    if (PyType_Ready(&ToplistBrowserType) < 0)
        return;
    if (PyType_Ready(&TrackType) < 0)
        return;
    if (PyType_Ready(&ImageType) < 0)
        return;
    if (PyType_Ready(&UserType) < 0)
        return;

    m = Py_InitModule("_spotify", module_methods);
    if (m == NULL)
        return;

    PyObject *spotify = PyImport_ImportModule("spotify");
    PyObject *d = PyModule_GetDict(spotify);
    PyObject *s = PyUnicode_FromString("SpotifyError");

    SpotifyError = PyDict_GetItem(d, s);
    Py_INCREF(SpotifyError);

    SpotifyApiVersion = Py_BuildValue("i", SPOTIFY_API_VERSION);
    Py_INCREF(SpotifyApiVersion);
    PyModule_AddObject(m, "api_version", SpotifyApiVersion);
    album_init(m);
    albumbrowser_init(m);
    artist_init(m);
    artistbrowser_init(m);
    link_init(m);
    playlist_init(m);
    playlistcontainer_init(m);
    session_init(m);
    search_init(m);
    toplistbrowser_init(m);
    track_init(m);
    image_init(m);
    user_init(m);
}
Esempio n. 11
0
animation_playback_t * animation_playback_new(renderable_t * renderable, animation_t * animation,
                                                unsigned int interval, bool loop) {
    animation_playback_t *playback = mem_alloc(sizeof(animation_playback_t));
    playback->interval = interval;
    playback->total_steps = 0;
    playback->renderable = renderable;
    playback->animation = animation;
    playback->loop = loop;
    link_init(&(playback->animation_playbacks_link));
    
    return playback;
}
Esempio n. 12
0
//开机进行联机
void boot_link( void )
{
	uint8_t process = 0;
	uint32_t cnt = 0;
	
	link_init();

//	GUI_DispStr32At(LCD_X_VALUE/2-14*16,LCD_Y_VALUE/2-16,RED,BLACK,"DTS-2500微电脑试验机测控系统");	
//	lcd_show_image(320,100,"image/logo.bin");	//加载鑫高LOGO
	
	while ( TRUE )
	{
		link_cycle(&process);

		draw_process(process);

		if (SET == tick_10ms)
		{
			tick_10ms = RESET;
			cnt++;
		}
		
		load_title_word(cnt);

		if (LINK_SUCCESS == link_status)	   //联机成功
		{
			link_status_set(LINK_IDLE);	
			
			protect_col_init(smpl_name);			//设置保护位、控制模式
		
			return;	
		}

		if (cnt > MIN_CNT_LINK_WAIT)					  //联机时,收到数据等待时间
		{
			if ( process )
			{
				if (cnt > MAX_CNT_LINK_WAIT)
				{
					return;
				}
			}
			else
			{
				link_status_set(LINK_UNLINK);
			
				return;
			}													
		}
	}		
}
Esempio n. 13
0
void renderable_init(renderable_t *renderable, sprite_t *default_sprite, int x, int y, int depth) {
    list_init(&(renderable->tweens), tween_t, tweens_link);
    renderable->sprite = default_sprite;
    renderable->default_sprite = default_sprite;
    renderable->x = x;
    renderable->y = y;
    renderable->depth = depth;
    renderable->scale = 1.0;
    renderable->angle = 0;
    renderable->center = NULL;
    renderable->flip = SDL_FLIP_NONE;
    renderable->animation_playback = NULL;
    link_init(&(renderable->renderables_link));
}
Esempio n. 14
0
static gboolean
link_add (NMPlatform *platform, const char *name, NMLinkType type, const void *address, size_t address_len)
{
	NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
	NMFakePlatformLink device;

	link_init (&device, priv->links->len, type, name);

	g_array_append_val (priv->links, device);

	if (device.link.ifindex)
		g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, device.link.ifindex, &device, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);

	return TRUE;
}
Esempio n. 15
0
File: client.c Progetto: kismit/SSFS
int main(int argc,char *argv[])
{
    if(argc!=2)
    {
    	printf("Usage:./client 192.168.0.101(serverip)\n");
    	exit(-1);
    }	
    
    strcpy(serverip,argv[1]);
    
    link_init();
    
    menu();
    
    close(sockfd);
    return 0;	
}
Esempio n. 16
0
void l4_thread_list_init(void)
{
	struct l4_thread_list *tlist = &l4_thread_list;

	/* Initialize the head struct */
	memset(tlist, 0, sizeof (*tlist));
	link_init(&tlist->thread_list);
	l4_mutex_init(&tlist->lock);

	/* Initialize a cache of l4_thread_list structs */
	if (!(tlist->thread_cache =
	      mem_cache_init(&l4_thread_list_buf,
			     L4_THREAD_LIST_BUFFER_SIZE,
			     sizeof(struct l4_thread), 0))) {
		printf("FATAL: Could not initialize internal "
		       "thread struct cache.\n");
		BUG();
	}
}
Esempio n. 17
0
status_t
init_stack()
{
    status_t status = init_domains();
    if (status != B_OK)
        return status;

    status = init_interfaces();
    if (status != B_OK)
        goto err1;

    status = init_device_interfaces();
    if (status != B_OK)
        goto err2;

    status = init_timers();
    if (status != B_OK)
        goto err3;

    status = init_notifications();
    if (status < B_OK) {
        // If this fails, it just means there won't be any notifications,
        // it's not a fatal error.
        dprintf("networking stack notifications could not be initialized: %s\n",
                strerror(status));
    }

    module_info* dummy;
    status = get_module(NET_SOCKET_MODULE_NAME, &dummy);
    if (status != B_OK)
        goto err4;

    mutex_init(&sChainLock, "net chains");
    mutex_init(&sInitializeChainLock, "net intialize chains");

    sFamilies = hash_init(10, offsetof(struct family, next),
                          &family::Compare, &family::Hash);
    if (sFamilies == NULL) {
        status = B_NO_MEMORY;
        goto err5;
    }

    sProtocolChains = hash_init(10, offsetof(struct chain, next),
                                &chain::Compare, &chain::Hash);
    if (sProtocolChains == NULL) {
        status = B_NO_MEMORY;
        goto err6;
    }

    sDatalinkProtocolChains = hash_init(10, offsetof(struct chain, next),
                                        &chain::Compare, &chain::Hash);
    if (sDatalinkProtocolChains == NULL) {
        status = B_NO_MEMORY;
        goto err7;
    }

    sReceivingProtocolChains = hash_init(10, offsetof(struct chain, next),
                                         &chain::Compare, &chain::Hash);
    if (sReceivingProtocolChains == NULL) {
        status = B_NO_MEMORY;
        goto err8;
    }

    sInitialized = true;

    link_init();
    scan_modules("network/protocols");
    scan_modules("network/datalink_protocols");

    // TODO: for now!
    register_domain_datalink_protocols(AF_INET, IFT_LOOP,
                                       "network/datalink_protocols/loopback_frame/v1", NULL);
    register_domain_datalink_protocols(AF_INET6, IFT_LOOP,
                                       "network/datalink_protocols/loopback_frame/v1", NULL);
    register_domain_datalink_protocols(AF_INET, IFT_ETHER,
                                       "network/datalink_protocols/arp/v1",
                                       "network/datalink_protocols/ethernet_frame/v1",
                                       NULL);
    register_domain_datalink_protocols(AF_INET6, IFT_ETHER,
                                       "network/datalink_protocols/ipv6_datagram/v1",
                                       "network/datalink_protocols/ethernet_frame/v1",
                                       NULL);

    return B_OK;

err8:
    hash_uninit(sDatalinkProtocolChains);
err7:
    hash_uninit(sProtocolChains);
err6:
    hash_uninit(sFamilies);
err5:
    mutex_destroy(&sInitializeChainLock);
    mutex_destroy(&sChainLock);
err4:
    uninit_timers();
err3:
    uninit_device_interfaces();
err2:
    uninit_interfaces();
err1:
    uninit_domains();
    return status;
}
Esempio n. 18
0
int main(int argc, char **argv)
{
    struct config conf;
    const char*config_filename;
    struct packet pkt = {0,};
    char buf[64] = {0,};
    int16_t crc;
    int default_cfg = 0;
    int bad_pkts_cnt = 0;
    int pkt_cnt = 0;

    if(argc == 2 && !strcmp("--help", argv[1])) {
        puts("Usage: quadcontrol [config_file.cfg]");
        exit(1);
    }

   if(argc == 2)
       config_filename = argv[1];
   else
       config_filename = CONFIG_DEFAULT_FILE;

   if(config_load(config_filename, &conf)) {
        fputs("WARNING: Could not load configuration file. Reverting to defaults.\n", stderr);
        config_default(&conf);
        config_save(CONFIG_DEFAULT_FILE, &conf);
        default_cfg = 1;
   }

   if(signal(SIGINT, sig_handler) == SIG_ERR) {
        fputs("ERROR: Could not set a signal handler.\n", stderr);
        exit(1);
    }

    if(joystick_init(conf.joystick_device)) {
        perror("could not open joystick device");
        exit(1);
    }

    joystick_set_axis_mapping(conf.joystick_mapping);
    joystick_set_axis_calibration(conf.joystick_calibration);

    if(default_cfg) {
        joystick_calibrate(conf.joystick_calibration);
        config_save(CONFIG_DEFAULT_FILE, &conf);
    }

    if(serial_init(conf.serial_device, conf.serial_speed)) {
        perror("could not open serial port");
        exit(1);
    }

    link_init();

    active = 1;
    while(active) {
        // Prepare & send a packet
        memset(&pkt, 0, PACKET_TOTAL_SIZE);

#ifdef REQUEST_REPORTS
        // Report request
        if(pkt_cnt % 2 == 0) {
            pkt.type = PT_REPORT | RPT_IMU;
            /*printf("\nreport request sent\n");*/
        } else
#endif
        {
            pkt.type = PT_JOYSTICK;
            pkt.data.joy.throttle =  joystick_get_control_val(THROTTLE_AXIS);
            pkt.data.joy.yaw      =  joystick_get_control_val(YAW_AXIS);
            pkt.data.joy.pitch    =  joystick_get_control_val(PITCH_AXIS);
            pkt.data.joy.roll     =  joystick_get_control_val(ROLL_AXIS);
            pkt.data.joy.buttons  =  joystick_get_buttons();

#ifdef SHOW_JOY
            printf("\nthrottle: %6d\tyaw:%6d\tpitch:%6d\troll:%6d\tbuttons:%6d",
                    pkt.data.joy.throttle, pkt.data.joy.yaw,
                    pkt.data.joy.pitch, pkt.data.joy.roll,
                    pkt.data.joy.buttons);
#endif
        }

        crc = link_crc(&pkt);
        serial_write((const uint8_t*) &pkt, PACKET_TOTAL_SIZE);
        serial_write((const uint8_t*) &crc, CRC_SIZE);

#ifdef SHOW_SEND_RAW
        printf("\nsent: ");
        for(int i = 0; i < PACKET_TOTAL_SIZE; ++i)
            printf("%.2x ", ((uint8_t*)(&pkt))[i]);

        printf("\tcrc = %.2x", crc);
#endif

        // Show response from the radio
        int cnt = serial_read(buf, sizeof(buf));
        if(cnt > 0) {

#ifdef SHOW_RECV_RAW
            // HEX version
            printf("\treceived: ");
            for(int i = 0; i < cnt; ++i)
                printf("%.2x ", (uint8_t) buf[i]);

            // ASCII version
            printf("  (");
            for(int i = 0; i < cnt; ++i)
                printf("%c", buf[i]);
            printf(")");
#endif

            if(cnt == 1 && buf[0] == 'E')
                printf("\n!!! DRONE IS NOT RESPONDING !!!\n");

            // Parse reports
            if(buf[0] == 'T' && buf[1] == 'R')
            {
                struct packet* pkt = (struct packet*) &buf[2];
                if(pkt->type & PT_REPORT) {
                    int report_type = pkt->type & ~PT_REPORT;

                    switch(report_type) {
                        case RPT_MOTOR:
                            printf("motors = FL: %d FR:%d BL:%d BR:%d\n",
                                    pkt->data.rpt_motor.fl,
                                    pkt->data.rpt_motor.fr,
                                    pkt->data.rpt_motor.bl,
                                    pkt->data.rpt_motor.br);
                            break;

                        case RPT_IMU:
                            printf("imu = yaw: %d pitch:%d roll:%d\n",
                                    pkt->data.rpt_imu.yaw,
                                    pkt->data.rpt_imu.pitch,
                                    pkt->data.rpt_imu.roll);
                            break;

                        default:
                            printf("invalid report type\n");
                            break;
                    }
                }
            }

            memset(buf, 0, sizeof(buf));
            bad_pkts_cnt = 0;
        } else {
            if(++bad_pkts_cnt == 10) {
                printf("\n!!! CONTROLLER IS NOT RESPONDING !!!\n");
                //link_init();
            }
        }

        ++pkt_cnt;

        fflush(stdout);
        usleep(45000);
    }

    serial_close();
    joystick_close();
    config_save(CONFIG_DEFAULT_FILE, &conf);

    return 1;
}
Esempio n. 19
0
struct mem_cache *mem_cache_init(void *start,
				 int cache_size,
				 int struct_size,
				 unsigned int aligned)
{
	struct mem_cache *cache = start;
	unsigned int area_start;
	unsigned int *bitmap;
	int bwords_in_structs;
	int bwords;
	int total;
	int bsize;

	if ((struct_size < 0) || (cache_size < 0) ||
	    ((unsigned long)start == ~(0))) {
		printf("Invalid parameters.\n");
		return 0;
	}

	/* The cache definition itself is at the beginning.
	 * Skipping it to get to start of free memory. i.e. the cache. */
	area_start = (unsigned long)start + sizeof(struct mem_cache);
	cache_size -= sizeof(struct mem_cache);

	if (cache_size < struct_size) {
		printf("Cache too small for given struct_size\n");
		return 0;
	}

	/* Get how much bitmap words occupy */
	total = cache_size / struct_size;
	bwords = total >> 5;	/* Divide by 32 */
	if (total & 0x1F) {	/* Remainder? */
		bwords++;	/* Add one more word for remainder */
	}

	bsize = bwords * 4;

	/* This many structures will be chucked from cache for bitmap space */
	bwords_in_structs = ((bsize) / struct_size) + 1;

	/* Total structs left after deducing bitmaps */
	total = total - bwords_in_structs;
	cache_size -= bsize;

	/* This should always catch too small caches */
	if (total <= 0) {
		printf("Cache too small for given struct_size\n");
		return 0;
	}
	if (cache_size <= 0) {
		printf("Cache too small for given struct_size\n");
		return 0;
	}
	bitmap = (unsigned int *)area_start;
	area_start = (unsigned int)(bitmap + bwords);
	if (aligned) {
		unsigned int addr = area_start;
		unsigned int addr_aligned = align_up(area_start, struct_size);
		unsigned int diff = addr_aligned - addr;

		BUG_ON(diff >= struct_size);
		cache_size -= diff;
		area_start = addr_aligned;
	}

	/* Now recalculate total over cache bytes left */
	total = cache_size / struct_size;

	link_init(&cache->list);
	cache->start = area_start;
	cache->end = area_start + cache_size;
	cache->total = total;
	cache->free = cache->total;
	cache->struct_size = struct_size;
	cache->bitmap = bitmap;

	/* NOTE: If needed, must initialise lock here */
	memset(cache->bitmap, 0, bwords*SZ_WORD);

	return cache;
}
Esempio n. 20
0
int main(int argc, char** argv) {
    unsigned char flags = 0;
    init_cpu();
    hw_init_flags();
    hw_write_flags(0);
    link_init();
    
    POINTER c = (POINTER)(ADDR_BASE_XIL + 0x06);
    *c = 0x100;
    UINT16 len = 0;
    
    /* IP address */
    localmachine.localip = 0xC0A80146 + flags;  /* 192.168.0.*	*/
    /* Default gateway */
    localmachine.defgw   = 0xC0A80101;  /* 192.168.0.1	*/
    /* Subnet mask */
    localmachine.netmask = 0xFFFFFF00;
    /* Ethernet (MAC) address */
    localmachine.localHW[5] = 0x00;
    localmachine.localHW[4] = 0x33;
    localmachine.localHW[3] = 0xCC;
    localmachine.localHW[2] = 0xAB;
    localmachine.localHW[1] = 0xBA;
    localmachine.localHW[0] = 0x11 + flags;

    data_port = UDP_DATA_PORT + flags;
    
    timer_pool_init();
    NE2000Init(&localmachine.localHW[0]);
    arp_init();
    udp_init();
    tcp_init();

    /* Initialize applications	*/
    tcps_init();
    udps_init();

    while(1) {
        if (NETWORK_CHECK_IF_RECEIVED() == TRUE) {
            switch( received_frame.protocol) {
                case PROTOCOL_ARP:
                    process_arp(&received_frame);	
                    break;

                case PROTOCOL_IP:
                    len = process_ip_in(&received_frame);
                    if(len < 0) 
                    break;
                    
                switch(received_ip_packet.protocol){
                    case IP_ICMP:
                        process_icmp_in (&received_ip_packet, len);
                        break;

                    case IP_UDP:
                        process_udp_in (&received_ip_packet,len);
                        break;

                    case IP_TCP:
                        process_tcp_in (&received_ip_packet, len);				
                        break;
                }

                break;
            }

        /* discard received frame */    		
        NETWORK_RECEIVE_END();
    }

        /* Application main loops */
        /* Do not forget this!!! These don't get invoked magically :-) */
    	tcps_run();
        udps_run();
        /* manage arp cache tables */
        arp_manage();
        /* manage opened TCP connections (retransmissions, timeouts,...)*/
        tcp_poll();
    }
    return (EXIT_SUCCESS);
}
Esempio n. 21
0
status_t
init_stack()
{
	status_t status = init_domains();
	if (status != B_OK)
		return status;

	status = init_interfaces();
	if (status != B_OK)
		goto err1;

	status = init_device_interfaces();
	if (status != B_OK)
		goto err2;

	status = init_timers();
	if (status != B_OK)
		goto err3;

	status = init_notifications();
	if (status < B_OK) {
		// If this fails, it just means there won't be any notifications,
		// it's not a fatal error.
		dprintf("networking stack notifications could not be initialized: %s\n",
			strerror(status));
	}

	module_info* dummy;
	status = get_module(NET_SOCKET_MODULE_NAME, &dummy);
	if (status != B_OK)
		goto err4;

	mutex_init(&sChainLock, "net chains");
	mutex_init(&sInitializeChainLock, "net intialize chains");

	sFamilies = new(std::nothrow) FamilyTable();
	if (sFamilies == NULL || sFamilies->Init(10) != B_OK) {
		status = B_NO_MEMORY;
		goto err5;
	}

	sProtocolChains = new(std::nothrow) ChainTable();
	if (sProtocolChains == NULL || sProtocolChains->Init(10) != B_OK) {
		status = B_NO_MEMORY;
		goto err6;
	}

	sDatalinkProtocolChains = new(std::nothrow) ChainTable();
	if (sDatalinkProtocolChains == NULL
			|| sDatalinkProtocolChains->Init(10) != B_OK) {
		status = B_NO_MEMORY;
		goto err7;
	}

	sReceivingProtocolChains = new(std::nothrow) ChainTable();
	if (sReceivingProtocolChains == NULL
			|| sReceivingProtocolChains->Init(10) != B_OK) {
		status = B_NO_MEMORY;
		goto err8;
	}

	sInitialized = true;

	link_init();
	scan_modules("network/protocols");
	scan_modules("network/datalink_protocols");

	// TODO: for now!
	register_domain_datalink_protocols(AF_INET, IFT_LOOP,
		"network/datalink_protocols/loopback_frame/v1", NULL);
#if 0 // PPP is not (currently) included in the build
	register_domain_datalink_protocols(AF_INET, IFT_PPP,
		"network/datalink_protocols/ppp_frame/v1", NULL);
#endif
	register_domain_datalink_protocols(AF_INET6, IFT_LOOP,
		"network/datalink_protocols/loopback_frame/v1", NULL);
	register_domain_datalink_protocols(AF_INET, IFT_ETHER,
		"network/datalink_protocols/arp/v1",
		"network/datalink_protocols/ethernet_frame/v1",
		NULL);
	register_domain_datalink_protocols(AF_INET6, IFT_ETHER,
		"network/datalink_protocols/ipv6_datagram/v1",
		"network/datalink_protocols/ethernet_frame/v1",
		NULL);

	return B_OK;

err8:
	delete sDatalinkProtocolChains;
err7:
	delete sProtocolChains;
err6:
	delete sFamilies;
err5:
	mutex_destroy(&sInitializeChainLock);
	mutex_destroy(&sChainLock);
err4:
	uninit_timers();
err3:
	uninit_device_interfaces();
err2:
	uninit_interfaces();
err1:
	uninit_domains();
	return status;
}