struct i2c_engine *dal_i2c_sw_engine_dce110_create(
	const struct i2c_sw_engine_dce110_create_arg *arg)
{
	struct i2c_sw_engine_dce110 *engine_dce110;

	if (!arg) {
		ASSERT_CRITICAL(false);
		return NULL;
	}

	engine_dce110 = dm_alloc(sizeof(struct i2c_sw_engine_dce110));

	if (!engine_dce110) {
		ASSERT_CRITICAL(false);
		return NULL;
	}

	if (construct(engine_dce110, arg))
		return &engine_dce110->base.base;

	ASSERT_CRITICAL(false);

	dm_free(engine_dce110);

	return NULL;
}
void dal_logger_open(
		struct dal_logger *logger,
		struct log_entry *entry, /* out */
		enum log_major major,
		enum log_minor minor)
{
	if (!entry) {
		BREAK_TO_DEBUGGER();
		return;
	}

	entry->major = LOG_MAJOR_COUNT;
	entry->minor = 0;
	entry->logger = logger;

	entry->buf = dm_alloc(DAL_LOGGER_BUFFER_MAX_SIZE * sizeof(char));

	entry->buf_offset = 0;
	entry->max_buf_bytes = DAL_LOGGER_BUFFER_MAX_SIZE * sizeof(char);

	logger->open_count++;
	entry->major = major;
	entry->minor = minor;

	log_heading(entry, major, minor);
}
/* audio_dce112 is derived from audio directly, not via dce80  */
struct hw_ctx_audio *dal_hw_ctx_audio_dce112_create(
	struct dc_context *ctx,
	uint32_t azalia_stream_id)
{
	/* allocate memory for struc hw_ctx_audio_dce112 */
	struct hw_ctx_audio_dce112 *hw_ctx_dce112 =
			dm_alloc(sizeof(struct hw_ctx_audio_dce112));

	if (!hw_ctx_dce112) {
		ASSERT_CRITICAL(hw_ctx_dce112);
		return NULL;
	}

	/*return pointer to hw_ctx_audio back to caller  -- audio object */
	if (construct(
			hw_ctx_dce112, azalia_stream_id, ctx))
		return &hw_ctx_dce112->base;

	dal_logger_write(
		ctx->logger,
		LOG_MAJOR_ERROR,
		LOG_MINOR_COMPONENT_AUDIO,
		"Failed to create hw_ctx_audio for DCE11\n");

	dm_free(hw_ctx_dce112);

	return NULL;
}
struct i2c_engine *dal_i2c_sw_engine_create(
	const struct i2c_sw_engine_create_arg *arg)
{
	struct i2c_sw_engine *engine;

	if (!arg) {
		BREAK_TO_DEBUGGER();
		return NULL;
	}

	engine = dm_alloc(sizeof(struct i2c_sw_engine));

	if (!engine) {
		BREAK_TO_DEBUGGER();
		return NULL;
	}

	if (dal_i2c_sw_engine_construct(engine, arg))
		return &engine->base;

	BREAK_TO_DEBUGGER();

	dm_free(engine);

	return NULL;
}
/*
 * dal_asic_capability_create
 *
 * Creates asic capability based on DCE version.
 */
struct asic_capability *dal_asic_capability_create(
	struct hw_asic_id *init,
	struct dc_context *ctx)
{
	struct asic_capability *cap;

	if (!init) {
		BREAK_TO_DEBUGGER();
		return NULL;
	}

	cap = dm_alloc(sizeof(struct asic_capability));

	if (!cap) {
		BREAK_TO_DEBUGGER();
		return NULL;
	}

	if (construct(cap, init, ctx))
		return cap;

	BREAK_TO_DEBUGGER();

	dm_free(cap);

	return NULL;
}
/* ----------- Object init and destruction ----------- */
static bool construct(struct dc_context *ctx, struct dal_logger *logger)
{
	uint32_t i;
	/* malloc buffer and init offsets */

	logger->log_buffer_size = DAL_LOGGER_BUFFER_MAX_SIZE;
	logger->log_buffer = (char *)dm_alloc(logger->log_buffer_size *
		sizeof(char));

	if (!logger->log_buffer)
		return false;

	/* todo: Fill buffer with \0 if not done by dal_alloc */

	/* Initialize both offsets to start of buffer (empty) */
	logger->buffer_read_offset = 0;
	logger->buffer_write_offset = 0;

	logger->write_wrap_count = 0;
	logger->read_wrap_count = 0;
	logger->open_count = 0;

	logger->flags.bits.ENABLE_CONSOLE = 1;
	logger->flags.bits.ENABLE_BUFFER = 0;

	logger->ctx = ctx;

	/* malloc and init minor mask array */
	logger->log_enable_mask_minors =
			(uint32_t *)dm_alloc(NUM_ELEMENTS(log_major_mask_info_tbl)
				* sizeof(uint32_t));
	if (!logger->log_enable_mask_minors)
		return false;

	/* Set default values for mask */
	for (i = 0; i < NUM_ELEMENTS(log_major_mask_info_tbl); i++) {

		uint32_t dflt_mask = log_major_mask_info_tbl[i].default_mask;

		logger->log_enable_mask_minors[i] = dflt_mask;
	}

	return true;
}
struct ddc *dal_gpio_create_ddc(
	struct gpio_service *service,
	uint32_t offset,
	uint32_t mask,
	struct gpio_ddc_hw_info *info)
{
	enum gpio_id id;
	uint32_t en;
	struct ddc *ddc;

	if (!service->translate.funcs->offset_to_id(offset, mask, &id, &en))
		return NULL;

	ddc = dm_alloc(sizeof(struct ddc));

	if (!ddc) {
		BREAK_TO_DEBUGGER();
		return NULL;
	}

	ddc->pin_data = dal_gpio_service_create_gpio_ex(
		service, GPIO_ID_DDC_DATA, en, GPIO_PIN_OUTPUT_STATE_DEFAULT);

	if (!ddc->pin_data) {
		BREAK_TO_DEBUGGER();
		goto failure_1;
	}

	ddc->pin_clock = dal_gpio_service_create_gpio_ex(
		service, GPIO_ID_DDC_CLOCK, en, GPIO_PIN_OUTPUT_STATE_DEFAULT);

	if (!ddc->pin_clock) {
		BREAK_TO_DEBUGGER();
		goto failure_2;
	}

	ddc->hw_info = *info;

	ddc->ctx = service->ctx;

	return ddc;

failure_2:
	dal_gpio_service_destroy_gpio(&ddc->pin_data);

failure_1:
	dm_free(ddc);

	return NULL;
}
struct dal_logger *dal_logger_create(struct dc_context *ctx)
{
	/* malloc struct */
	struct dal_logger *logger = dm_alloc(sizeof(struct dal_logger));

	if (!logger)
		return NULL;
	if (!construct(ctx, logger)) {
		dm_free(logger);
		return NULL;
	}

	return logger;
}
struct irq_service *dal_irq_service_dce110_create(
    struct irq_service_init_data *init_data)
{
    struct irq_service *irq_service = dm_alloc(sizeof(*irq_service));

    if (!irq_service)
        return NULL;

    if (construct(irq_service, init_data))
        return irq_service;

    dm_free(irq_service);
    return NULL;
}
struct stream_encoder *virtual_stream_encoder_create(
	struct dc_context *ctx, struct dc_bios *bp)
{
	struct stream_encoder *enc = dm_alloc(sizeof(*enc));

	if (!enc)
		return NULL;

	if (virtual_stream_encoder_construct(enc, ctx, bp))
		return enc;

	BREAK_TO_DEBUGGER();
	dm_free(enc);
	return NULL;
}
struct display_clock *dal_display_clock_dce110_create(
	struct dc_context *ctx,
	struct adapter_service *as)
{
	struct display_clock_dce110 *dc110;

	dc110 = dm_alloc(sizeof(struct display_clock_dce110));

	if (dc110 == NULL)
		return NULL;

	if (dal_display_clock_dce110_construct(dc110, ctx, as))
		return &dc110->disp_clk_base;

	dm_free(dc110);

	return NULL;
}
struct hw_gpio_pin *dal_hw_hpd_dce110_create(
	struct dc_context *ctx,
	enum gpio_id id,
	uint32_t en)
{
	struct hw_hpd_dce110 *pin = dm_alloc(sizeof(struct hw_hpd_dce110));

	if (!pin) {
		ASSERT_CRITICAL(false);
		return NULL;
	}

	if (construct(pin, id, en, ctx))
		return &pin->base.base.base;

	ASSERT_CRITICAL(false);

	dm_free(pin);

	return NULL;
}
struct gpio *dal_gpio_create(
	struct gpio_service *service,
	enum gpio_id id,
	uint32_t en,
	enum gpio_pin_output_state output_state)
{
	struct gpio *gpio = dm_alloc(sizeof(struct gpio));

	if (!gpio) {
		ASSERT_CRITICAL(false);
		return NULL;
	}

	gpio->service = service;
	gpio->pin = NULL;
	gpio->id = id;
	gpio->en = en;
	gpio->mode = GPIO_MODE_UNKNOWN;
	gpio->output_state = output_state;

	return gpio;
}
struct gpio_service *dal_gpio_service_create(
	enum dce_version dce_version_major,
	enum dce_version dce_version_minor,
	struct dc_context *ctx)
{
	struct gpio_service *service;

	uint32_t index_of_id;

	service = dm_alloc(sizeof(struct gpio_service));

	if (!service) {
		BREAK_TO_DEBUGGER();
		return NULL;
	}

	if (!dal_hw_translate_init(&service->translate, dce_version_major,
			dce_version_minor)) {
		BREAK_TO_DEBUGGER();
		goto failure_1;
	}

	if (!dal_hw_factory_init(&service->factory, dce_version_major,
			dce_version_minor)) {
		BREAK_TO_DEBUGGER();
		goto failure_1;
	}

	/* allocate and initialize business storage */
	{
		const uint32_t bits_per_uint = sizeof(uint32_t) << 3;

		index_of_id = 0;
		service->ctx = ctx;

		do {
			uint32_t number_of_bits =
				service->factory.number_of_pins[index_of_id];

			uint32_t number_of_uints =
				(number_of_bits + bits_per_uint - 1) /
				bits_per_uint;

			uint32_t *slot;

			if (number_of_bits) {
				uint32_t index_of_uint = 0;

				slot = dm_alloc(number_of_uints * sizeof(uint32_t));

				if (!slot) {
					BREAK_TO_DEBUGGER();
					goto failure_2;
				}

				do {
					slot[index_of_uint] = 0;

					++index_of_uint;
				} while (index_of_uint < number_of_uints);
			} else
				slot = NULL;

			service->busyness[index_of_id] = slot;

			++index_of_id;
		} while (index_of_id < GPIO_ID_COUNT);
	}

	return service;

failure_2:
	while (index_of_id) {
		uint32_t *slot;

		--index_of_id;

		slot = service->busyness[index_of_id];

		if (slot)
			dm_free(slot);
	};

failure_1:
	dm_free(service);

	return NULL;
}
Beispiel #15
0
e_int32 ls_scan(laser_sick_t *ls, char* ptDir, char *grayDir,
		e_uint32 speed_h_delay, const e_float64 start_angle_h,
		const e_float64 end_angle_h, e_uint32 speed_v_hz,
		e_float64 resolution_v, const e_uint32 interlace_v,
		const e_float64 start_angle_v, const e_float64 end_angle_v) {
	e_int32 ret;
	e_assert(ls && ls->state == STATE_IDLE, E_ERROR_INVALID_STATUS);

	ls->state = STATE_WORK;

	ls->on_status_change(ls->ctx, ls->state);

	ret = ls_phrase_config(ls, speed_h_delay, start_angle_h, end_angle_h,
			speed_v_hz, resolution_v, interlace_v, start_angle_v, end_angle_v);
	if (ret <= 0) {
		DMSG((STDOUT, "ls_phrase_config failed!\r\n"));
		ls->state = STATE_IDLE;
		return E_ERROR;
	}

	//创建输出端子
	ls->writer = dm_alloc(ptDir, grayDir, ls->width, ls->height,
			ls->h_w,
			ls->active_sectors.right && ls->active_sectors.left ?
					E_DWRITE : E_WRITE);
	if (ls->writer == 0) {
		DMSG((STDOUT, "dm_alloc failed!\r\n"));
		ls->state = STATE_IDLE;
		return E_ERROR;
	}
	ret = dm_alloc_buffer(ls->writer, DATA_BLOCK_TYPE_COLUMN, &ls->points_polar,
			&ls->points_gray);
	if (e_failed( ret )) {
		DMSG((STDOUT, "dm_alloc_buffer failed!\r\n"));
		ls->state = STATE_IDLE;
		return E_ERROR;
	}
	ls->slip_idx = 0;
	ls->slip_tick = 0;

	DMSG((STDOUT, "scan job routine starting read routine...\r\n"));
	//check priv
	if (ls->thread_work)
		killthread(ls->thread_work);
	ret = createthread("point scan  scan thread",
			(thread_func) &thread_scan_func, ls, NULL, &ls->thread_work);
	if (ret <= 0) {
		DMSG((STDOUT, "create point scan thread failed!\r\n"));
		ls->state = STATE_IDLE;
		return E_ERROR;
	}
	ret = resumethread(ls->thread_work);
	if (ret <= 0) {
		DMSG((STDOUT, "resume point scan  thread failed!\r\n"));
		if (ls->thread_work)
			killthread(ls->thread_work);
		ls->state = STATE_IDLE;
		return E_ERROR;
	}
	DMSG((STDOUT, "point scan job routine start successful.\r\n"));
	return E_OK;
}