Пример #1
0
int tilib_api_init(void)
{
	int ret;

	lib_handle = dynload_open(tilib_filename);
	if (!lib_handle) {
		printc_err("tilib_api: can't find %s: %s\n",
			   tilib_filename, dynload_error());
		return -1;
	}

	if (dynload_sym(lib_handle, "MSP430_HIL_MEMAP")) {
		printc_dbg("Using new (SLAC460L+) API\n");
		ret = init_new_api();
	} else {
		printc_dbg("Using old API\n");
		ret = init_old_api();
	}

	if (ret < 0) {
		dynload_close(lib_handle);
		return -1;
	}

	return 0;
}
Пример #2
0
static device_t tilib_open(const struct device_args *args)
{
	struct tilib_device *dev;

	if (!(args->flags & DEVICE_FLAG_TTY)) {
		printc_err("This driver does not support raw USB access.\n");
		return NULL;
	}

	dev = malloc(sizeof(*dev));
	if (!dev) {
		printc_err("tilib: can't allocate memory: %s\n",
			   last_error());
		return NULL;
	}

	memset(dev, 0, sizeof(*dev));
	dev->base.type = &device_tilib;

	dev->hnd = dynload_open(tilib_filename);
	if (!dev->hnd) {
		printc_err("tilib: can't find %s: %s\n",
			   tilib_filename, dynload_error());
		free(dev);
		return NULL;
	}

	if (get_all_funcs(dev) < 0) {
		dynload_close(dev->hnd);
		free(dev);
		return NULL;
	}

	if (do_init(dev, args) < 0) {
		printc_err("tilib: device initialization failed\n");
		dynload_close(dev->hnd);
		free(dev);
		return NULL;
	}

	return (device_t)dev;
}
Пример #3
0
static void tilib_destroy(device_t dev_base)
{
	struct tilib_device *dev = (struct tilib_device *)dev_base;

	printc_dbg("MSP430_Run\n");
	if (dev->MSP430_Run(FREE_RUN, 1) < 0)
		report_error(dev, "MSP430_Run");

	printc_dbg("MSP430_Close\n");
	dev->MSP430_Close(0);
	dynload_close(dev->hnd);
	threads_lock_destroy(&dev->mb_lock);
	free(dev);
}
Пример #4
0
void tilib_api_exit(void)
{
	dynload_close(lib_handle);
}