예제 #1
0
static int __init init(void)
{
    tty = current->signal->tty;

    //printk(KERN_INFO "[simple_keyboard.c] Loading module.\n");
    to_tty_string("[simple_keyboard.c] Loading module.\n\r");

    //keyboard_operations.compat_ioctl = keyboard_ioctl;
    keyboard_operations.unlocked_ioctl = keyboard_ioctl;

    // create proc entry
    proc_entry = create_proc_entry(PROC_ENTRY, 0444, NULL);
    if (!proc_entry)
    {
        // printk(KERN_INFO "[simple_keyboard.c] Error creating /proc entry.\n");
        to_tty_string("[simple_keyboard.c] Error creating /proc entry.\n\r");
        return 1;
    }

    proc_entry->proc_fops = &keyboard_operations;

    init_driver();

    return 0;
}
pjmedia_vid_register_factory(pjmedia_vid_dev_factory_create_func_ptr adf,
                             pjmedia_vid_dev_factory *factory)
{
    pj_bool_t refresh = PJ_FALSE;
    pj_status_t status;

    if (vid_subsys.init_count == 0)
	return PJMEDIA_EVID_INIT;

    vid_subsys.drv[vid_subsys.drv_cnt].create = adf;
    vid_subsys.drv[vid_subsys.drv_cnt].f = factory;

    if (factory) {
        /* Call factory->init() */
        status = factory->op->init(factory);
        if (status != PJ_SUCCESS) {
            factory->op->destroy(factory);
            return status;
        }
        refresh = PJ_TRUE;
    }

    status = init_driver(vid_subsys.drv_cnt, refresh);
    if (status == PJ_SUCCESS) {
	vid_subsys.drv_cnt++;
    } else {
	deinit_driver(vid_subsys.drv_cnt);
    }

    return status;
}
예제 #3
0
/* API: Initialize the video device subsystem. */
PJ_DEF(pj_status_t) pjmedia_vid_dev_subsys_init(pj_pool_factory *pf)
{
    unsigned i;
    pj_status_t status = PJ_SUCCESS;

    /* Allow init() to be called multiple times as long as there is matching
     * number of shutdown().
     */
    if (vid_subsys.init_count++ != 0) {
	return PJ_SUCCESS;
    }

    /* Register error subsystem */
    pj_register_strerror(PJMEDIA_VIDEODEV_ERRNO_START, 
			 PJ_ERRNO_SPACE_SIZE, 
			 &pjmedia_videodev_strerror);

    /* Init */
    vid_subsys.pf = pf;
    vid_subsys.drv_cnt = 0;
    vid_subsys.dev_cnt = 0;

    /* Register creation functions */
#if PJMEDIA_VIDEO_DEV_HAS_ANDROID_CAPTURE
    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_android_cam_factory;
#endif
#if PJMEDIA_VIDEO_DEV_HAS_V4L2
    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_v4l2_factory;
#endif
#if PJMEDIA_VIDEO_DEV_HAS_QT
    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_qt_factory;
#endif
#if PJMEDIA_VIDEO_DEV_HAS_IOS
    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_ios_factory;
#endif
#if PJMEDIA_VIDEO_DEV_HAS_DSHOW
    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_dshow_factory;
#endif
#if PJMEDIA_VIDEO_DEV_HAS_FFMPEG
    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_ffmpeg_factory;
#endif
#if PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC
    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_cbar_factory;
#endif
#if PJMEDIA_VIDEO_DEV_HAS_SDL
    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_sdl_factory;
#endif

    /* Initialize each factory and build the device ID list */
    for (i=0; i<vid_subsys.drv_cnt; ++i) {
	status = init_driver(i, PJ_FALSE);
	if (status != PJ_SUCCESS) {
	    deinit_driver(i);
	    continue;
	}
    }

    return vid_subsys.dev_cnt ? PJ_SUCCESS : status;
}
예제 #4
0
파일: audiodev.c 프로젝트: Jopie64/pjsip
/* API: Initialize the audio subsystem. */
PJ_DEF(pj_status_t) pjmedia_aud_subsys_init(pj_pool_factory *pf)
{
    unsigned i;
    pj_status_t status = PJ_SUCCESS;

    /* Allow init() to be called multiple times as long as there is matching
     * number of shutdown().
     */
    if (aud_subsys.init_count++ != 0) {
	return PJ_SUCCESS;
    }

    /* Register error subsystem */
    pj_register_strerror(PJMEDIA_AUDIODEV_ERRNO_START, 
			 PJ_ERRNO_SPACE_SIZE, 
			 &pjmedia_audiodev_strerror);

    /* Init */
    aud_subsys.pf = pf;
    aud_subsys.drv_cnt = 0;
    aud_subsys.dev_cnt = 0;

    /* Register creation functions */
#if PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_pa_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_WMME
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_wmme_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_symb_vas_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_SYMB_APS
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_aps_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_symb_mda_factory;
#endif

    /* Initialize each factory and build the device ID list */
    for (i=0; i<aud_subsys.drv_cnt; ++i) {
	status = init_driver(i);
	if (status != PJ_SUCCESS) {
	    deinit_driver(i);
	    continue;
	}
    }

    return aud_subsys.dev_cnt ? PJ_SUCCESS : status;
}
예제 #5
0
pjmedia_vid_register_factory(pjmedia_vid_dev_factory_create_func_ptr adf)
{
    pj_status_t status;

    if (vid_subsys.init_count == 0)
	return PJMEDIA_EVID_INIT;

    vid_subsys.drv[vid_subsys.drv_cnt].create = adf;
    status = init_driver(vid_subsys.drv_cnt, PJ_FALSE);
    if (status == PJ_SUCCESS) {
	vid_subsys.drv_cnt++;
    } else {
	deinit_driver(vid_subsys.drv_cnt);
    }

    return status;
}
예제 #6
0
/* API: Refresh the list of video devices installed in the system. */
PJ_DEF(pj_status_t) pjmedia_vid_dev_refresh(void)
{
    unsigned i;
    
    vid_subsys.dev_cnt = 0;
    for (i=0; i<vid_subsys.drv_cnt; ++i) {
	struct driver *drv = &vid_subsys.drv[i];
	
	if (drv->f && drv->f->op->refresh) {
	    pj_status_t status = drv->f->op->refresh(drv->f);
	    if (status != PJ_SUCCESS) {
		PJ_PERROR(4, (THIS_FILE, status, "Unable to refresh device "
						 "list for %s", drv->name));
	    }
	}
	init_driver(i, PJ_TRUE);
    }
    return PJ_SUCCESS;
}
예제 #7
0
static int __init gs_fpgaboot_init(void)
{
	int err, r;

	r = -1;

	pr_info("FPGA DOWNLOAD --->\n");
	pr_info("built at %s UTC\n", __TIMESTAMP__);

	pr_info("FPGA image file name: %s\n", file);

	err = init_driver();
	if (err != 0) {
		pr_err("FPGA DRIVER INIT FAIL!!\n");
		return r;
	}

	err = xl_init_io();
	if (err) {
		pr_err("GPIO INIT FAIL!!\n");
		r = -1;
		goto errout;
	}

	err = gs_fpgaboot();
	if (err) {
		pr_err("FPGA DOWNLOAD FAIL!!\n");
		r = -1;
		goto errout;
	}

	pr_info("FPGA DOWNLOAD DONE <---\n");

	r = 0;
	return r;

errout:
	finish_driver();

	return r;
}
예제 #8
0
파일: main.c 프로젝트: YokoZar/wine
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
    int i = 0;
    TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);

    if(!init_driver()){
        ERR("Driver initialization failed\n");
        return E_FAIL;
    }

    if (ppv == NULL) {
        WARN("invalid parameter\n");
        return E_INVALIDARG;
    }

    *ppv = NULL;

    if (!IsEqualIID(riid, &IID_IClassFactory) &&
        !IsEqualIID(riid, &IID_IUnknown)) {
        WARN("no interface for %s\n", debugstr_guid(riid));
        return E_NOINTERFACE;
    }

    for (i = 0; i < sizeof(MMDEVAPI_CF)/sizeof(MMDEVAPI_CF[0]); ++i)
    {
        if (IsEqualGUID(rclsid, MMDEVAPI_CF[i].rclsid)) {
            IUnknown_AddRef(&MMDEVAPI_CF[i].IClassFactory_iface);
            *ppv = &MMDEVAPI_CF[i];
            return S_OK;
        }
        i++;
    }

    WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
         debugstr_guid(riid), ppv);
    return CLASS_E_CLASSNOTAVAILABLE;
}
예제 #9
0
int main(int argc, char *argv[])
{
        /* Initialize various components. */
        init_common();
        init_driver();

        if (parse_arguments(argc, argv) != OK) {
                printf("usage: %s -d <address> -wmin # -wmax # -l # [-w #] [-p #] [-c #] [-i #] [-o #] [-n #] [-q %%] [-r %%] [-e %%] [-t %%] [-seed #] [-altered 0] [-spread #] [-z]",
                        argv[0]);
#ifdef STANDALONE
#ifdef LIBPQ
                printf(" -z #");
#endif /* LIBPQ */
#endif /* STANDALONE */
                printf("\n\n");
#ifdef STANDALONE
                printf("-dbname <connect_string>\n");
                printf("\tdatabase connect string\n");
#ifdef LIBPQ
                printf("-z #\n");
                printf("\tpostmaster listener port\n");
#endif /* LIBPQ */
#ifdef LIBMYSQL
		printf("-z #\n");
		printf("\tmysql server listener port\n");
#endif /* LIBMYSQL */
#ifdef LIBDRIZZLE
		printf("-z #\n");
		printf("\tdrizzle server listener port\n");
#endif /* LIBDRIZZLE */
#else /* STANDALONE */
                printf("-d <address>\n");
                printf("\tnetwork address where client program is running\n");
                printf("-p #\n");
                printf("\tclient port, default %d\n", CLIENT_PORT);
#endif /* STANDALONE */
                printf("\n");
                printf("-l #\n");
                printf("\tthe duration of the run in seconds\n");
                printf("\n");
                printf("-wmin #\n");
                printf("\tlower warehouse id\n");
                printf("-wmax #\n");
                printf("\tupper warehouse id\n");
                printf("-w #\n");
                printf("\twarehouse cardinality, default 1\n");
                printf("-c #\n");
                printf("\tcustomer cardinality, default %d\n", CUSTOMER_CARDINALITY);
                printf("-i #\n");
                printf("\titem cardinality, default %d\n", ITEM_CARDINALITY);
                printf("-o #\n");
                printf("\torder cardinality, default %d\n", ORDER_CARDINALITY);
                printf("-n #\n");
                printf("\tnew-order cardinality, default %d\n", NEW_ORDER_CARDINALITY);
                printf("\n");
                printf("-q %%\n");
                printf("\tmix percentage of Payment transaction, default %0.2f\n",
                        MIX_PAYMENT);
                printf("-r %%\n");
                printf("\tmix percentage of Order-Status transaction, default %0.2f\n",
                        MIX_ORDER_STATUS);
                printf("-e %%\n");
                printf("\tmix percentage of Delivery transaction, default %0.2f\n",
                        MIX_DELIVERY);
                printf("-t %%\n");
                printf("\tmix percentage of Stock-Level transaction, default %0.2f\n",
                        MIX_STOCK_LEVEL);
                printf("\n");
                printf("-ktd #\n");
                printf("\tdelivery keying time, default %d s\n", KEY_TIME_DELIVERY);
                printf("-ktn #\n");
                printf("\tnew-order keying time, default %d s\n", KEY_TIME_NEW_ORDER);
                printf("-kto #\n");
                printf("\torder-status keying time, default %d s\n",
                        KEY_TIME_ORDER_STATUS);
                printf("-ktp #\n");
                printf("\tpayment keying time, default %d s\n", KEY_TIME_PAYMENT);
                printf("-kts #\n");
                printf("\tstock-level keying time, default %d s\n",
                        KEY_TIME_STOCK_LEVEL);
                printf("-ttd #\n");
                printf("\tdelivery thinking time, default %d ms\n",
                        THINK_TIME_DELIVERY);
                printf("-ttn #\n");
                printf("\tnew-order thinking time, default %d ms\n",
                        THINK_TIME_NEW_ORDER);
                printf("-tto #\n");
                printf("\torder-status thinking time, default %d ms\n",
                        THINK_TIME_ORDER_STATUS);
                printf("-ttp #\n");
                printf("\tpayment thinking time, default %d ms\n", THINK_TIME_PAYMENT);
                printf("-tts #\n");
                printf("\tstock-level thinking time, default %d ms\n",
                        THINK_TIME_STOCK_LEVEL);
                printf("\n");
                printf("-tpw #\n");
                printf("\tterminals started per warehouse, default 10\n");

                printf("\n");
                printf("-seed #\n");
                printf("\trandom number seed\n");
                printf("-altered [0/1]\n");
                printf("\trun with a thread per user, -altered 1\n");
                printf("-sleep #\n");
                printf("\tnumber of milliseconds to sleep between terminal creation\n");
                printf("-spread #\n");
                printf("\tfancy warehouse skipping trick for low i/o runs\n");

                printf("-z #\n");
                printf("\tperform database integrity check\n");
#ifdef STANDALONE
                printf("\nDriver is in STANDALONE mode.\n");
#endif /* STANDALONE */

                return 1;
        }
        create_pid_file();

        if(init_logging() != OK || init_driver_logging() != OK) {
                printf("cannot init driver\n");
                return 1;
        };

        /* Sanity check on the parameters. */
        if (w_id_min > w_id_max) {
                printf("wmin cannot be larger than wmax\n");
                return 1;
        }
        if (w_id_max > table_cardinality.warehouses) {
                printf("wmax cannot be larger than w\n");
                return 1;
        }

        if (recalculate_mix() != OK) {
                printf("invalid transaction mix: -e %0.2f. -r %0.2f. -q %0.2f. -t %0.2f. causes new-order mix of %0.2f.\n",
                        transaction_mix.delivery_actual,
                        transaction_mix.order_status_actual,
                        transaction_mix.payment_actual,
                        transaction_mix.stock_level_actual,
                        transaction_mix.new_order_actual);
                return 1;
        }

        /* Double check database table cardinality. */
        printf("\n");
        printf("database table cardinalities:\n");
        printf("warehouses = %d\n", table_cardinality.warehouses);
        printf("districts = %d\n", table_cardinality.districts);
        printf("customers = %d\n", table_cardinality.customers);
        printf("items = %d\n", table_cardinality.items);
        printf("orders = %d\n", table_cardinality.orders);
        printf("stock = %d\n", table_cardinality.items);
        printf("new-orders = %d\n", table_cardinality.new_orders);
        printf("\n");

        /* Double check the transaction mix. */
        printf("transaction mix:\n");
        printf("new-order mix %0.2f\n", transaction_mix.new_order_actual);
        printf("payment mix %0.2f\n", transaction_mix.payment_actual);
        printf("order-status mix %0.2f\n", transaction_mix.order_status_actual);
        printf("delivery mix %0.2f\n", transaction_mix.delivery_actual);
        printf("stock-level mix %0.2f\n", transaction_mix.stock_level_actual);
        printf("\n");

        /* Double check the transaction threshold. */
        printf("transaction thresholds:\n");
        printf("new-order threshold %0.2f\n",
                transaction_mix.new_order_threshold);
        printf("payment threshold %0.2f\n", transaction_mix.payment_threshold);
        printf("order-status threshold %0.2f\n",
                transaction_mix.order_status_threshold);
        printf("delivery threshold %0.2f\n",
                transaction_mix.delivery_threshold);
        printf("stock-level threshold %0.2f\n",
                transaction_mix.stock_level_threshold);
        printf("\n");

        /* Double check the keying time. */
        printf("delivery keying time %d s\n", key_time.delivery);
        printf("new_order keying time %d s\n", key_time.new_order);
        printf("order-status keying time %d s\n", key_time.order_status);
        printf("payment keying time %d s\n", key_time.payment);
        printf("stock-level keying time %d s\n", key_time.stock_level);
        printf("\n");

        /* Double check the thinking time. */

        printf("delivery thinking time %d ms\n", think_time.delivery);
        printf("new_order thinking time %d ms\n", think_time.new_order);
        printf("order-status thinking time %d ms\n", think_time.order_status);
        printf("payment thinking time %d ms\n", think_time.payment);
        printf("stock-level thinking time %d ms\n", think_time.stock_level);
        printf("\n");

        printf("w_id range %d to %d\n", w_id_min, w_id_max);
        printf("\n");

        printf("%d terminals per warehouse\n", terminals_per_warehouse);
        printf("\n");

        printf("%d second steady state duration\n", duration);
        printf("\n");

        if (perform_integrity_check && integrity_terminal_worker() != OK) {
           printf("You used wrong parameters or something wrong with database.\n");
           return 1;
        }

        start_driver();

        return 0;
}
void SoundDriverList::reset_driver() {
	
	init_driver( current );
}
예제 #11
0
파일: util.c 프로젝트: njutony1991/Nanos
void
init_proc() {
	list_init(&ready);
	list_init(&block);
	list_init(&free);


    int i=0;
    for(;i<PCB_NUM;i++)
        list_add_before(&free,&proc_pool[i].list);

    init_driver();
    init_fm();
    //PCB *ptest = create_kthread(drivertest,0,NULL);
    //wakeup(ptest);
    /**pa = create_kthread(A,0,NULL);
    pb = create_kthread(B,0,NULL);
    pc = create_kthread(C,0,NULL);
    pd = create_kthread(D,0,NULL);
    pe = create_kthread(E,0,NULL);**/
    timertest = create_kthread(timer_test,0,NULL);
    fmtest = create_kthread(fm_test,0,NULL);
    //(fmtest->pool_mutex).pid = fmtest->pid;
    /**wakeup(pa);
    wakeup(pb);
    wakeup(pc);
    wakeup(pd);
    wakeup(pe);**/
    wakeup(timertest);
    wakeup(fmtest);
	/**
    pa = create_kthread(print_ch,'a',&pb);
	printk("pa : %d ,pa->tf : %x\n",pa->pid,pa->tf);
	list_add_before(&ready,&(pa->list));

    printk("ready:\n");
    ListHead *p1;
    list_foreach(p1,&ready)
        printk("id : %d ,tf : %x\n",((PCB *)(list_entry(p1,PCB,list)))->pid,
                                    ((PCB *)(list_entry(p1,PCB,list)))->tf);
    printk("\n-----------\n");

    pb = create_kthread(print_ch,'b',&pc);
	printk("pb : %d ,pb->tf : %x\n",pb->pid,pb->tf);
	list_add_before(&block,&(pb->list));
	pc = create_kthread(print_ch,'c',&pd);
	printk("pc : %d ,pc->tf : %x\n",pc->pid,pc->tf);
	list_add_before(&block,&(pc->list));
    pd = create_kthread(print_ch,'d',&pa);
    printk("pd : %d ,pd->tf : %x\n",pd->pid,pd->tf);
    list_add_before(&block,&(pd->list));
    
    printk("block:\n");
    ListHead *p2;
    list_foreach(p2,&block)
        printk("id : %d ,tf : %x\n",((PCB *)(list_entry(p2,PCB,list)))->pid,
                                    ((PCB *)(list_entry(p2,PCB,list)))->tf);
    printk("\n---------\n");
    **/
    //test_setup();
}
예제 #12
0
/* API: Initialize the audio subsystem. */
PJ_DEF(pj_status_t) pjmedia_aud_subsys_init(pj_pool_factory *pf)
{
    unsigned i;
    pj_status_t status;

    /* Allow init() to be called multiple times as long as there is matching
     * number of shutdown().
     */
    if (aud_subsys.init_count++ != 0) {
	return PJ_SUCCESS;
    }

    /* Register error subsystem */
    status = pj_register_strerror(PJMEDIA_AUDIODEV_ERRNO_START, 
				  PJ_ERRNO_SPACE_SIZE, 
				  &pjmedia_audiodev_strerror);
    pj_assert(status == PJ_SUCCESS);

    /* Init */
    aud_subsys.pf = pf;
    aud_subsys.drv_cnt = 0;
    aud_subsys.dev_cnt = 0;

    /* Register creation functions */
#if PJMEDIA_AUDIO_DEV_HAS_OPENSL
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_opensl_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_ANDROID_JNI
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_android_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_BB10
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_bb10_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_ALSA
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_alsa_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_COREAUDIO
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_coreaudio_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_WMME
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_wmme_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_BDIMAD
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_bdimad_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_symb_vas_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_SYMB_APS
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_aps_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_symb_mda_factory;
#endif
#if PJMEDIA_AUDIO_DEV_HAS_NULL_AUDIO
    aud_subsys.drv[aud_subsys.drv_cnt++].create = &pjmedia_null_audio_factory;
#endif

    /* Initialize audio device observer objects */
    pj_status_t st;
    aud_subsys.dev_observer.pool = pj_pool_create(pf, "aud_dev_observer_pool", 512, 512, NULL);
    if (!aud_subsys.dev_observer.pool) {
        return PJ_ENOMEM;
    }
    st = pj_mutex_create_simple(aud_subsys.dev_observer.pool, "aud_dev_observer_lock", &aud_subsys.dev_observer.lock);
    if (st != PJ_SUCCESS) {
        return st;
    }
    aud_subsys.dev_observer.cb = NULL;

    /* Initialize each factory and build the device ID list */
    for (i=0; i<aud_subsys.drv_cnt; ++i) {
	status = init_driver(i, PJ_FALSE);
	if (status != PJ_SUCCESS) {
	    deinit_driver(i);
	    continue;
	}
    }

    return aud_subsys.dev_cnt ? PJ_SUCCESS : status;
}
예제 #13
0
파일: device.c 프로젝트: mikekap/wine
/* load the .sys module for a device driver */
static BOOL load_driver(void)
{
    static const WCHAR driversW[] = {'\\','d','r','i','v','e','r','s','\\',0};
    static const WCHAR postfixW[] = {'.','s','y','s',0};
    static const WCHAR ntprefixW[] = {'\\','?','?','\\',0};
    static const WCHAR ImagePathW[] = {'I','m','a','g','e','P','a','t','h',0};
    static const WCHAR servicesW[] = {'\\','R','e','g','i','s','t','r','y',
                                      '\\','M','a','c','h','i','n','e',
                                      '\\','S','y','s','t','e','m',
                                      '\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t',
                                      '\\','S','e','r','v','i','c','e','s','\\',0};

    UNICODE_STRING keypath;
    HMODULE module;
    LPWSTR path = NULL, str;
    DWORD type, size;

    str = HeapAlloc( GetProcessHeap(), 0, sizeof(servicesW) + strlenW(driver_name)*sizeof(WCHAR) );
    lstrcpyW( str, servicesW );
    lstrcatW( str, driver_name );

    if (RegOpenKeyW( HKEY_LOCAL_MACHINE, str + 18 /* skip \registry\machine */, &driver_hkey ))
    {
        WINE_ERR( "cannot open key %s, err=%u\n", wine_dbgstr_w(str), GetLastError() );
        HeapFree( GetProcessHeap(), 0, str);
        return FALSE;
    }
    RtlInitUnicodeString( &keypath, str );

    /* read the executable path from memory */
    size = 0;
    if (!RegQueryValueExW( driver_hkey, ImagePathW, NULL, &type, NULL, &size ))
    {
        str = HeapAlloc( GetProcessHeap(), 0, size );
        if (!RegQueryValueExW( driver_hkey, ImagePathW, NULL, &type, (LPBYTE)str, &size ))
        {
            size = ExpandEnvironmentStringsW(str,NULL,0);
            path = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));
            ExpandEnvironmentStringsW(str,path,size);
        }
        HeapFree( GetProcessHeap(), 0, str );
        if (!path) return FALSE;
    }
    else
    {
        /* default is to use the driver name + ".sys" */
        WCHAR buffer[MAX_PATH];
        GetSystemDirectoryW(buffer, MAX_PATH);
        path = HeapAlloc(GetProcessHeap(),0,
          (strlenW(buffer) + strlenW(driversW) + strlenW(driver_name) + strlenW(postfixW) + 1)
          *sizeof(WCHAR));
        lstrcpyW(path, buffer);
        lstrcatW(path, driversW);
        lstrcatW(path, driver_name);
        lstrcatW(path, postfixW);
    }

    /* GameGuard uses an NT-style path name */
    str = path;
    if (!strncmpW( path, ntprefixW, 4 )) str += 4;

    WINE_TRACE( "loading driver %s\n", wine_dbgstr_w(str) );

    module = load_driver_module( str );
    HeapFree( GetProcessHeap(), 0, path );
    if (!module) return FALSE;

    init_driver( module, &keypath );
    return TRUE;
}
예제 #14
0
파일: hwctrl.c 프로젝트: iruka-/ATMEL_AVR
int open_ifport (PORTPROP *pc)
{
	OSVERSIONINFO vinfo = { sizeof(OSVERSIONINFO) };
	LARGE_INTEGER val1;
	BYTE cmdspi[6];
	static const WORD PortsCom[] = { COM1ADR, COM2ADR, COM3ADR, COM4ADR };
	static const WORD PortsLpt[] = { LPT1ADR, LPT2ADR, LPT3ADR };
	char sComm[16];
	DCB dcb = { sizeof(DCB),
				9600, TRUE, FALSE, TRUE, FALSE,
				DTR_CONTROL_DISABLE, FALSE,
				TRUE, FALSE, FALSE, FALSE, FALSE,
				RTS_CONTROL_DISABLE, FALSE, 0, 0,
				10, 10,
				8, NOPARITY, ONESTOPBIT, '\x11', '\x13', '\xFF', '\xFF', 0 };
	COMMTIMEOUTS commtimeouts = { 0, 1, 100, 1, 300};


	/* Check if high resolution timer is supported */
	QueryPerformanceFrequency(&val1);
	if (val1.QuadPart == 0) {
		pc->Info1 = "Incompatible envilonment.\n";
		return 1;
	}

#if AVRSPX
	if (pc->Delay < 0) {				//@@x by t.k
		PortDly = DEFAULT_DELAY_VALUE;	//@@x
	} else {
		PortDly = pc->Delay;	/* I/O delay for direct I/O control */
	}

	if (pc->Baud < 0) {					//@@x by t.k
		if (pc->PortClass == TY_RSCR)
			dcb.BaudRate = 19200;
		else {
			dcb.BaudRate = DEFAULT_BAUDRATE;
		}
	} else {
		dcb.BaudRate = pc->Baud;	/* Bit rate for SPI bridge */
	}
#else
	PortDly = pc->Delay;		/* I/O delay for direct I/O control */
	dcb.BaudRate = pc->Baud;	/* Bit rate for SPI bridge */
#endif

	/* Open direct I/O driver if needed */
	if(GetVersionEx(&vinfo) == FALSE) {
		pc->Info1 = "Incompatible envilonment.\n";
		return 1;
	}
	if((vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
	    && ((pc->PortClass == TY_COMM)||(pc->PortClass == TY_LPT))) {
		if(init_driver()) {
			pc->Info1 = "I/O driver, giveio.sys, is not available due to any reason.\n"
			"To install giveio, type \"move giveio.sys %%windir%%\\system32\" and retry any function.\n";
			return 1;
		}
	}

	/* Use COM port in direct I/O */
	if(pc->PortClass == TY_COMM) {
		if((pc->PortNum < 1)||(pc->PortNum > 4)) {
			pc->Info1 = "Invalid Port#.\n";
			return 1;
		}
		PortBase = PortsCom[pc->PortNum - 1];
		sprintf(str_info, "No COM%u(0x%X) port.\n", pc->PortNum, PortBase);
		pc->Info1 = str_info;
		if(check_comport()) {
			if(vinfo.dwPlatformId != VER_PLATFORM_WIN32_NT) return 1;
			sprintf(sComm, "\\\\.\\COM%u", pc->PortNum);
			hComm = CreateFile(sComm, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
			if(hComm == INVALID_HANDLE_VALUE) return 1;
			if(check_comport()) return 1;
		}

		_outp(COM_IMR, 0x00);		/* Mask interrupts */
		pc->Info1 = NULL;
		PortType = TY_COMM;
#if AVRSPX
		sprintf(str_info, "Use COM%u(0x%X) port in direct I/O.\n", pc->PortNum, PortBase);
		pc->Info1 = str_info;
#endif
		return 0;
	}

#if AVRSPX
	if (pc->PortClass == TY_HIDASP)	{ //@@+ by k-k
		if (hidasp_init(pc->SerialNumber) == HIDASP_MODE_ERROR)	{
			sprintf(str_info, "HIDaspx(%s) not found.\n", pc->SerialNumber);
			pc->Info1 = str_info;
			return 1;
		}
		PortType = TY_HIDASP;
		return 0;
	}
#endif

	/* Use COM port via API */
	if(pc->PortClass == TY_VCOM) {
		sprintf(sComm, "\\\\.\\COM%u", pc->PortNum);
		hComm = CreateFile(sComm, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
		if(hComm == INVALID_HANDLE_VALUE) {
			sprintf(str_info, "%s could not be opened.\n", sComm);
			pc->Info1 = str_info;
			return 1;
		}
#if AVRSPX
		if (SetCommState(hComm, &dcb)==0) {
			sprintf(str_info, "%s (%dbps) parameter error. \n", sComm, (int)dcb.BaudRate);
			pc->Info1 = str_info;
			return 1;
		}
#else
		SetCommState(hComm, &dcb);
#endif
		EscapeCommFunction(hComm, CLRRTS);
		EscapeCommFunction(hComm, CLRDTR);
		PortType = TY_VCOM;
#if AVRSPX
		sprintf(str_info, "Use COM%u port via API.\n", pc->PortNum);
		pc->Info1 = str_info;
#endif
		return 0;
	}

	/* Use SPI bridge attached on COM port */
	if(pc->PortClass == TY_BRIDGE) {
		sprintf(sComm, "\\\\.\\COM%u", pc->PortNum);
		hComm = CreateFile(sComm, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
		if(hComm == INVALID_HANDLE_VALUE) {
			sprintf(str_info, "%s could not be opened.\n", sComm);
			pc->Info1 = str_info;
			return 1;
		}
		dcb.fOutxCtsFlow = TRUE;
		dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
#if AVRSPX
		if (SetCommState(hComm, &dcb)==0) {
			sprintf(str_info, "%s (%dbps) parameter error. \n", sComm, (int)dcb.BaudRate);
			pc->Info1 = str_info;
			return 1;
		}
#else
		SetCommState(hComm, &dcb);
#endif
		SetCommTimeouts(hComm, &commtimeouts);
		EscapeCommFunction(hComm, SETDTR);
		EscapeCommFunction(hComm, CLRDTR);
		delay_ms(10);
		while(read_bridge(cmdspi, sizeof(cmdspi)));
		cmdspi[0] = FLAG-1;
		cmdspi[1] = FLAG; cmdspi[2] = SPI_ENABLE;	/* Enable Bridge */
#if AVRSPX
		cmdspi[3] = FLAG; cmdspi[4] = SPI_SETDLY;
		if (PortDly > 255) {
			cmdspi[5] = 255; /* Set SPI delay */
		} else {
			cmdspi[5] = (BYTE)PortDly; /* Set SPI delay */
		}
#else
		cmdspi[3] = FLAG; cmdspi[4] = SPI_SETDLY; cmdspi[5] = (BYTE)PortDly; /* Set SPI delay */
#endif
		send_bridge(cmdspi, 6);		/* Send bridge initialization commands */
		read_bridge(cmdspi, 2);		/* Check if the commands are accepted */
		if((cmdspi[0] != SPI_ENABLE) || (cmdspi[1] != SPI_SETDLY)) {
			sprintf(str_info, "No SPI bridge on the %s.\n", sComm);
			pc->Info1 = str_info;
			return 1;
		}
#if AVRSPX
		cmdspi[0] = FLAG; cmdspi[1] = SPI_GETREV;
		send_bridge(cmdspi, 2);		/* Send f/w revision commands */
		read_bridge(cmdspi, 1);		/* Check if AVR specific command is supported */
		BridgeRev = (cmdspi[0] == 0xFF) ? 0 : cmdspi[0];
		if (BridgeRev < 4) {
			sprintf(str_info, "*** Use SPI bridge R4+ for fast operation ***\n");
		} else {
			sprintf(str_info, "SPI bridge on the %s (baud=%d).\n", sComm, (int)dcb.BaudRate);
		}
		pc->Info1 = str_info;
#endif
		PortType = TY_BRIDGE;
		return 0;
	}

	/* Use LPT port in direct I/O */
	if(pc->PortClass == TY_LPT) {
		if((pc->PortNum < 1)||(pc->PortNum > 3)) {
			pc->Info1 = "Invalid Port#.\n";
			return 1;
		}
		PortBase = PortsLpt[pc->PortNum - 1];
		if(check_lptport()) {
			sprintf(str_info, "No LPT%u(0x%X) port.\n", pc->PortNum, PortBase);
			pc->Info1 = str_info;
			return 1;
		}

		_outp(LPT_DAT, 0x20);	/* Check if the adapter is ByteBlasterMV (D5-ACK) */
		if(_inp(LPT_STA) & S_ACK) {
			_outp(LPT_DAT, 0);
			if((_inp(LPT_STA) & S_ACK) == 0) {
				_outp(LPT_CTL, BA_ENA);
				pc->Info1 = "Altera ByteBlasterMV was found.\n";
				PortType = TY_ALTERA;
				if(_inp(LPT_STA) & S_ERR) return 0;	/* Check target power */
				pc->Info2 = "But target power is OFF.\n";
				return 1;
			}
		}
		_outp(LPT_DAT, 0x80);	/* Check if the adapter is AVRSP (D7-PE) */
		if(_inp(LPT_STA) & S_PE) {
			_outp(LPT_DAT, 0);
			if((_inp(LPT_STA) & S_PE) == 0) {
				_outp(LPT_DAT, B_ENA);
				pc->Info1 = "AVRSP adapter was found.\n";
				PortType = TY_AVRSP;
				if(_inp(LPT_STA) & S_ERR) return 0;	/* Check target power */
				pc->Info2 = "But target power is OFF.\n";
				return 1;
			}
		}
		_outp(LPT_DAT, 0x40);	/* Check if the adapter is Xilinx JTAG (D6-BUSY-PE) */
		if((_inp(LPT_STA) & (S_PE | S_BUSY)) == S_PE) {
			_outp(LPT_DAT, 0);
			if((_inp(LPT_STA) & (S_PE | S_BUSY)) == S_BUSY) {
				pc->Info1 = "Xilinx JTAG adapter was found.\n";
				PortType = TY_XILINX;
				if(_inp(LPT_STA) & S_ERR) return 0;	/* Check target power */
				pc->Info2 = "But target power is OFF.\n";
				return 1;
			}
		}
		_outp(LPT_DAT, 0x40);	/* Check if the adapter is Lattice ISP (D6-PE) */
		if(_inp(LPT_STA) & S_PE) {
			_outp(LPT_DAT, 0);
			if((_inp(LPT_STA) & S_PE) == 0) {
				pc->Info1 = "Lattice ISP adapter was found.\n";
				PortType = TY_LATTICE;
				if(_inp(LPT_STA) & S_ERR) return 0;	/* Check target power */
				pc->Info2 = "But target power is OFF.\n";
				return 1;
			}
		}
		_outp(LPT_DAT, 0x01);	/* Check if the adapter is STK200 dongle (D0-PE) */
		if(_inp(LPT_STA) & S_PE) {
			_outp(LPT_DAT, 0);
			if((_inp(LPT_STA) & S_PE) == 0) {
				pc->Info1 = "STK200 ISP dongle was found.\n";
				PortType = TY_STK200;
				if(_inp(LPT_STA) & S_ERR) return 0;	/* Check target power */
				pc->Info2 = "But target power is OFF.\n";
				return 1;
			}
		}
		sprintf(str_info, "No ISP adapter on the LPT%u.\n", pc->PortNum);
		pc->Info1 = str_info;
		return 1;
	}
#if AVRSPX
	if (pc->PortClass == TY_USBASP) {	//@@+ by t.k
		if (usbasp_initialize(pc->SerialNumber) != 0) {
			pc->Info1 = "USBasp not fonud.\n";
			return 1;
		}
		PortType = TY_USBASP;
		if (usbasp_connect(pc->Delay) != 0) {
			pc->Info1 = "USBasp connection error!!.\n";
			return 1;
		}
		return 0;
	}

	/* Use COM port via API */
	if (pc->PortClass == TY_RSCR) {	//@@+ by t.k
		sprintf(sComm, "\\\\.\\COM%u", pc->PortNum);
		hComm = CreateFile(sComm, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hComm == INVALID_HANDLE_VALUE) {
			sprintf(str_info, "%s could not be opened.\n", sComm);
			pc->Info1 = str_info;
			return 1;
		}
		dcb.fOutxCtsFlow = FALSE;
		dcb.fOutxDsrFlow = FALSE;
		dcb.fDtrControl  = DTR_CONTROL_DISABLE;
		dcb.fRtsControl  = RTS_CONTROL_DISABLE;
#if AVRSPX
		if (SetCommState(hComm, &dcb)==0) {
			sprintf(str_info, "%s (%dbps) parameter error. \n", sComm, (int)dcb.BaudRate);
			pc->Info1 = str_info;
			return 1;
		}
#else
		SetCommState(hComm, &dcb);
#endif
		EscapeCommFunction(hComm, CLRRTS);
		EscapeCommFunction(hComm, CLRDTR);
		PortType = TY_RSCR;
		rscr_setup(hComm, dcb.BaudRate);
		return 0;
	}

#endif

	pc->Info1 = "Invalid port class.\n";
	return 1;
}
예제 #15
0
int main(int argc, char *argv[])
{
    char c;
    int status = 0;
    
    printf("Hello World, I'm game!\n");
    
    status = init_display();
    if (status != 0)
    {
        printf("Error: Failed to init display\n");
        return status;
    }
    
    status = init_driver();
    if (status != 0)
    {
        printf("Error: Failed to init driver\n");
        destroy_display();
        return status;
    }
    
    status = setup_handler();
    if (status != 0)
    {
        printf("Error: Failed to init signal handler\n");
        destroy_display();
        close(file_gamepad_driver);
        return status;
    }
    time_handler();
    
    /* Intializes random number generator */
    srand((unsigned) time(&t));
    
    sigset_t myset;
    (void) sigemptyset(&myset);

    while(1)
    {
        clear_LCD();       
        draw_game();
        draw_score(p1_score, p2_score);
        redraw();
        
        waitForButton();      
        printf("start game\n");
        
        while((p1_score < 5) && (p2_score < 5))
        {
            random_timer = (rand() % 3) + 2;
            startTimer(random_timer);
            waitForTimer();
            
            random_button = (rand() % 4);
            
            draw_button(random_button, true, RED);
            redraw();
            
            gettimeofday(&time_button_appears, NULL);

            // start timer
            startTimer(3);
            buf = 0;
            while((playerButtonPressed(random_button) == 0) && (timer_expired == false))
            {
                waitForButton(); 
            }
            
            stopTimer();
            if (timer_expired == false)
            {
                time_elapsed = getGameTime();
                draw_time(time_elapsed, BLUE);
                redraw();
            }
      
            if (playerButtonPressed(random_button) == P1)
            {
                p1_score++;
                p1_time += time_elapsed;
                
            }
            else if (playerButtonPressed(random_button) == P2)
            {
                p2_score++;    
                p2_time += time_elapsed;
            }
                
            draw_score(p1_score, p2_score);    
            reset_button(random_button);
            redraw();
            
        }
        // draw winner
        button_pressed = 0;
        if (p1_score == 5)
        {
            winner = P1;
            winner_time = p1_time;
        }
        else if (p2_score == 5)
        {
            winner = P2;
            winner_time = p2_time;
        }
        
        while(button_pressed == 0)
        {
            startTimer(1);
            winner_blink(winner, winner_time);
            waitForTimer();
        }
               
        // print waiting
        waitForButton();
        p1_score = 0;
        p1_time = 0;
        p2_score = 0;
        p2_time = 0;
    }

}
예제 #16
0
S32 user_main(S32 argc, PPS8 argv)
{
    S32 i;
    PS8 eeprom_file_name = (PS8)"./nvs_map.bin";
    PS8 init_file_name = (PS8)"tiwlan.ini";
    PS8 firmware_file_name = (PS8)"firmware.bin";

    /* Parse command line parameters */
    if( argc > 1 )
    {
        i=1;
        if( argv[i][0] != '-' )
        {
            os_strcpy( g_drv_name, argv[i++] );
        }
        for( ;i < argc; i++ )
        {
            if( !os_strcmp(argv[i], (PS8)"-h" ) || !os_strcmp(argv[i], (PS8)"--help") )
                return print_usage();
            else if(!os_strcmp(argv[i], (PS8)"-f" ) )
            {
                firmware_file_name = argv[++i];
            }
            else if(!os_strcmp(argv[i], (PS8)"-e") && (i+1<argc))
            {
                eeprom_file_name = argv[++i];
            }
            else if(!os_strcmp(argv[i], (PS8)"-i") && (i+1<argc))
            {
                init_file_name = argv[++i];
            }
            else if(!os_strcmp(argv[i], (PS8)"-n" ) )
            {
               eeprom_file_name = NULL;
            }
            else
            {
                os_error_printf (CU_MSG_ERROR, (PS8)"Loader: unknow parameter '%s'\n", argv[i]);
#ifdef ANDROID
                check_and_set_property("wlan.driver.status", "failed");
#endif
                return -1;
            }
        }
    }

    if( !g_drv_name[0] )
    {
        os_strcpy(g_drv_name, (PS8)TIWLAN_DRV_NAME "0" );
    }

#ifdef ANDROID
    acquire_wake_lock(PARTIAL_WAKE_LOCK, PROGRAM_NAME);
#endif

    if (init_driver (g_drv_name, eeprom_file_name, init_file_name, firmware_file_name) != 0)
    {
#ifdef ANDROID
        check_and_set_property("wlan.driver.status", "failed");
        release_wake_lock(PROGRAM_NAME);
#endif
        return -1;
    }
#ifdef ANDROID
    check_and_set_property("wlan.driver.status", "ok");
    release_wake_lock(PROGRAM_NAME);
#endif
    return 0;
}
예제 #17
0
파일: main.c 프로젝트: zzt93/os-lab1
void
os_init_cont(void) {
    /* Reset the GDT. Although user processes in Nanos run in Ring 0,
       they have their own virtual address space. Therefore, the
       old GDT located in physical address 0x7C00 cannot be used again. */
    init_segment();

    /* Initialize the serial port. After that, you can use printk() */
    init_serial();

    /* Set up interrupt and exception handlers,
       just as we did in the game. */
    init_idt();

    /* Initialize the intel 8259 PIC. */
    //The Intel 8259 is a Programmable Interrupt Controller (PIC)
    init_intr();

    /**
       initialize kmalloc -- have to initialize it before init
       process, for using it in allocating memory for PCB
    */
    init_kmalloc();
    // make it NOINTR, can receive msg, can schedule
    init_idle();

    NOINTR;

    /**
       init_driver() have to before init_file_system() for FM have
       to send message to `ide` to read file system
     */
    init_driver();
    init_manager();
    NOINTR;
    init_error_msg();
    // init_proc() and init_manager() can replace??
    // solved by split set count_of_lock out of init_proc();

    //more_frequent();
    // init empty thread
    init_proc_test();

    // here is to initialize shell process, which must later
    // than init_manager -- for it will send message to
    // managers
    //ram_user_process();


    // @checked: move from locked state to unlocked state
    init_file_system();

    unlock(); // set interrupt enabled
    INTR;

    /**
       init_file_system() have to before init_proc()
       for init_proc() will using the `default_cwd` which is
       initialized by FM
    */
    /* Initialize the state of process idle, ie the running
       process for set up right lock num to avoid other
       initialization enable the interrupt and cause problem
    */

    // @checked: move from locked state to unlocked state
    welcome();

    user_process();
    // set idle not to using cpu time
    // for it is originally set to sleep when send message
    current->state = SLEEPED;


    /* This context now becomes the idle process. */
    while (1) {
        printk("!");
        wait_intr();
    }
}
예제 #18
0
int open_ifport (PORTPROP *pc)
{
	OSVERSIONINFO vinfo = { sizeof(OSVERSIONINFO) };
	LARGE_INTEGER val1;
	BYTE cmdspi[6];
	static const WORD PortsCom[] = { COM1ADR, COM2ADR, COM3ADR, COM4ADR };
	static const WORD PortsLpt[] = { LPT1ADR, LPT2ADR, LPT3ADR };
	char sComm[16];
	DCB dcb = { sizeof(DCB),
				9600, TRUE, FALSE, TRUE, FALSE,
				DTR_CONTROL_DISABLE, FALSE,
				TRUE, FALSE, FALSE, FALSE, FALSE,
				RTS_CONTROL_DISABLE, FALSE, 0, 0,
				10, 10,
				8, NOPARITY, ONESTOPBIT, '\x11', '\x13', '\xFF', '\xFF', 0 };
	COMMTIMEOUTS commtimeouts = { 0, 1, 100, 1, 300};


	/* Check if high resolution timer is supported */
	QueryPerformanceFrequency(&val1);
	if (val1.QuadPart == 0) {
		pc->Info1 = "Incompatible envilonment.\n";
		return 1;
	}

	PortDly = pc->Delay;		/* I/O delay for direct I/O control */
	dcb.BaudRate = pc->Baud;	/* Bit rate for SPI bridge */

	/* Open direct I/O driver if needed */
	if(GetVersionEx(&vinfo) == FALSE) {
		pc->Info1 = "Incompatible envilonment.\n";
		return 1;
	}
	if((vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
	    && ((pc->PortClass == TY_COMM)||(pc->PortClass == TY_LPT))) {
		if(init_driver()) {
			pc->Info1 = "I/O driver initialization failed.\n";
			return 1;
		}
	}

	/* Use COM port in direct I/O */
	if(pc->PortClass == TY_COMM) {
		if((pc->PortNum < 1)||(pc->PortNum > 4)) {
			pc->Info1 = "Invalid Port#.\n";
			return 1;
		}
		PortBase = PortsCom[pc->PortNum - 1];
		sprintf(str_info, "No COM%u(0x%X) port.\n", pc->PortNum, PortBase);
		pc->Info1 = str_info;
		if(check_comport()) {
			if(vinfo.dwPlatformId != VER_PLATFORM_WIN32_NT) return 1;
			sprintf(sComm, "\\\\.\\COM%u", pc->PortNum);
			hComm = CreateFile(sComm, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
			if(hComm == INVALID_HANDLE_VALUE) return 1;
			if(check_comport()) return 1;
		}

		_outp(COM_IMR, 0x00);		/* Mask interrupts */
		pc->Info1 = NULL;
		PortType = TY_COMM;
		return 0;
	}

	/* Use COM port via API */
	if(pc->PortClass == TY_VCOM) {
		sprintf(sComm, "\\\\.\\COM%u", pc->PortNum);
		hComm = CreateFile(sComm, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
		if(hComm == INVALID_HANDLE_VALUE) {
			sprintf(str_info, "%s could not be opened.\n", sComm);
			pc->Info1 = str_info;
			return 1;
		}
		SetCommState(hComm, &dcb);
		EscapeCommFunction(hComm, CLRRTS);
		EscapeCommFunction(hComm, CLRDTR);
		PortType = TY_VCOM;
		return 0;
	}

	/* Use SPI bridge attached on COM port */
	if(pc->PortClass == TY_BRIDGE) {
		sprintf(sComm, "\\\\.\\COM%u", pc->PortNum);
		hComm = CreateFile(sComm, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
		if(hComm == INVALID_HANDLE_VALUE) {
			sprintf(str_info, "%s could not be opened.\n", sComm);
			pc->Info1 = str_info;
			return 1;
		}
		dcb.fOutxCtsFlow = TRUE;
		dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
		SetCommState(hComm, &dcb);
		SetCommTimeouts(hComm, &commtimeouts);
		EscapeCommFunction(hComm, CLRDTR);
		delay_ms(10);
		while(read_bridge(cmdspi, sizeof(cmdspi)));
		cmdspi[0] = FLAG-1;
		cmdspi[1] = FLAG; cmdspi[2] = SPI_ENABLE;	/* Enable Bridge */
		cmdspi[3] = FLAG; cmdspi[4] = SPI_SETDLY; cmdspi[5] = (BYTE)PortDly; /* Set SPI delay */
		send_bridge(cmdspi, 6);		/* Send bridge initialization commands */
		read_bridge(cmdspi, 2);		/* Check if the commands are accepted */
		if((cmdspi[0] != SPI_ENABLE) || (cmdspi[1] != SPI_SETDLY)) {
			sprintf(str_info, "No SPI bridge on the %s.\n", sComm);
			pc->Info1 = str_info;
			return 1;
		}
		PortType = TY_BRIDGE;
		return 0;
	}

	/* Use LPT port in direct I/O */
	if(pc->PortClass == TY_LPT) {
		if((pc->PortNum < 1)||(pc->PortNum > 3)) {
			pc->Info1 = "Invalid Port#.\n";
			return 1;
		}
		PortBase = PortsLpt[pc->PortNum - 1];
		if(check_lptport()) {
			sprintf(str_info, "No LPT%u(0x%X) port.\n", pc->PortNum, PortBase);
			pc->Info1 = str_info;
			return 1;
		}

		_outp(LPT_DAT, 0x20);	/* Check if the adapter is ByteBlasterMV (D5-ACK) */
		if(_inp(LPT_STA) & S_ACK) {
			_outp(LPT_DAT, 0);
			if((_inp(LPT_STA) & S_ACK) == 0) {
				_outp(LPT_CTL, BA_ENA);
				pc->Info1 = "Altera ByteBlasterMV was found.\n";
				PortType = TY_ALTERA;
				if(_inp(LPT_STA) & S_ERR) return 0;	/* Check target power */
				pc->Info2 = "But target power is OFF.\n";
				return 1;
			}
		}
		_outp(LPT_DAT, 0x80);	/* Check if the adapter is AVRSP (D7-PE) */
		if(_inp(LPT_STA) & S_PE) {
			_outp(LPT_DAT, 0);
			if((_inp(LPT_STA) & S_PE) == 0) {
				_outp(LPT_DAT, B_ENA);
				pc->Info1 = "AVRSP adapter was found.\n";
				PortType = TY_AVRSP;
				if(_inp(LPT_STA) & S_ERR) return 0;	/* Check target power */
				pc->Info2 = "But target power is OFF.\n";
				return 1;
			}
		}
		_outp(LPT_DAT, 0x40);	/* Check if the adapter is Xilinx JTAG (D6-BUSY-PE) */
		if((_inp(LPT_STA) & (S_PE | S_BUSY)) == S_PE) {
			_outp(LPT_DAT, 0);
			if((_inp(LPT_STA) & (S_PE | S_BUSY)) == S_BUSY) {
				pc->Info1 = "Xilinx JTAG adapter was found.\n";
				PortType = TY_XILINX;
				if(_inp(LPT_STA) & S_ERR) return 0;	/* Check target power */
				pc->Info2 = "But target power is OFF.\n";
				return 1;
			}
		}
		_outp(LPT_DAT, 0x40);	/* Check if the adapter is Lattice ISP (D6-PE) */
		if(_inp(LPT_STA) & S_PE) {
			_outp(LPT_DAT, 0);
			if((_inp(LPT_STA) & S_PE) == 0) {
				pc->Info1 = "Lattice ISP adapter was found.\n";
				PortType = TY_LATTICE;
				if(_inp(LPT_STA) & S_ERR) return 0;	/* Check target power */
				pc->Info2 = "But target power is OFF.\n";
				return 1;
			}
		}
		_outp(LPT_DAT, 0x01);	/* Check if the adapter is STK200 dongle (D0-PE) */
		if(_inp(LPT_STA) & S_PE) {
			_outp(LPT_DAT, 0);
			if((_inp(LPT_STA) & S_PE) == 0) {
				pc->Info1 = "STK200 ISP dongle was found.\n";
				PortType = TY_STK200;
				if(_inp(LPT_STA) & S_ERR) return 0;	/* Check target power */
				pc->Info2 = "But target power is OFF.\n";
				return 1;
			}
		}
		sprintf(str_info, "No ISP adapter on the LPT%u.\n", pc->PortNum);
		pc->Info1 = str_info;
		return 1;
	}

	pc->Info1 = "Invalid port class.\n";
	return 1;
}