Пример #1
0
static int aon_timer_qmsi_set_alarm(struct device *dev,
				    counter_callback_t callback,
				    u32_t count, void *user_data)
{
	qm_aonpt_config_t qmsi_cfg;
	int result = 0;

	/* Check if timer has been started */
	if (QM_AONC[QM_AONC_0]->aonpt_cfg == 0) {
		return -ENOTSUP;
	}

	user_cb = callback;

	qmsi_cfg.callback = aonpt_int_callback;
	qmsi_cfg.int_en = true;
	qmsi_cfg.count = count;
	qmsi_cfg.callback_data = user_data;

	if (IS_ENABLED(CONFIG_AON_API_REENTRANCY)) {
		k_sem_take(RP_GET(dev), K_FOREVER);
	}

	if (qm_aonpt_set_config(QM_AONC_0, &qmsi_cfg)) {
		user_cb = NULL;
		result = -EIO;
	}

	if (IS_ENABLED(CONFIG_AON_API_REENTRANCY)) {
		k_sem_give(RP_GET(dev));
	}

	return result;
}
Пример #2
0
static int aon_timer_qmsi_start(struct device *dev)
{
	qm_aonpt_config_t qmsi_cfg;
	int result = 0;

	user_cb = NULL;

	qmsi_cfg.callback = NULL;
	qmsi_cfg.int_en = false;
	/* AONPT is a countdown timer. So, set the initial value to
	 * the maximum value.
	 */
	qmsi_cfg.count = 0xffffffff;
	qmsi_cfg.callback_data = NULL;

	if (IS_ENABLED(CONFIG_AON_API_REENTRANCY)) {
		k_sem_take(RP_GET(dev), K_FOREVER);
	}

	if (qm_aonpt_set_config(QM_AONC_0, &qmsi_cfg)) {
		result = -EIO;
	}

	if (IS_ENABLED(CONFIG_AON_API_REENTRANCY)) {
		k_sem_give(RP_GET(dev));
	}

	return result;
}
Пример #3
0
Файл: main.c Проект: jeez/qmsi
int main(void)
{
	uint32_t c_val = 0, pt_val = 0;
	qm_aonpt_config_t cfg;

	QM_PUTS("Starting: Always-on Counter");

	/* Always-on Counter enable and read value. */
	qm_aonc_enable(QM_AONC_0);

	if (qm_aonc_get_value(QM_AONC_0, &c_val) == 0) {
		QM_PRINTF("Always-on Counter value: %u\n", c_val);
	} else {
		QM_PUTS("Error: Could not read aonc value.");
	}

	/* Request an IRQ and write the Always-on Periodic Timer config. */
	cfg.count = 0x1000; /* 0.125 seconds. */
	cfg.int_en = true;  /* Interrupts enabled. */
	cfg.callback = aonpt_example_callback;

	qm_irq_request(QM_IRQ_AONPT_0_INT, qm_aonpt_0_isr);

	qm_aonpt_set_config(QM_AONC_0, &cfg);

	/* Wait for the defined number of callbacks be invoked. */
	while (NUM_CALLBACKS > callback_count)
		;

	QM_PRINTF("Periodic Timer callback fired %d times.\n", callback_count);

	/* Get the value of the Always-on Periodic Timer. */
	if (qm_aonpt_get_value(QM_AONC_0, &c_val) == 0) {
		QM_PRINTF("Always-on Periodic Timer value: %u\n", pt_val);
	} else {
		QM_PUTS("Error: Could not read Periodic timer value");
	}

	/* Disable the always-on periodic timer interrupt. */
	cfg.int_en = false;
	qm_aonpt_set_config(QM_AONC_0, &cfg);

	QM_PUTS("Finished: Always-on counter");

	return 0;
}
Пример #4
0
int main(void)
{
	volatile uint32_t delay;
	uint32_t c_val = 0, pt_val = 0;
	qm_aonpt_config_t cfg;

	QM_PUTS("\nAlways-on Counter example app\n");

	/* Always-on Counter enable, disable and read value */
	qm_aonc_disable(QM_SCSS_AON_0);
	qm_aonc_enable(QM_SCSS_AON_0);

	c_val = qm_aonc_get_value(QM_SCSS_AON_0);
	if (c_val) {
		QM_PRINTF("Always-on Counter value: %lu\n", c_val);
	} else {
		QM_PRINTF("ERROR: Could not read aonc value\n");
	}

	/* Request an IRQ and write the Always-on Periodic Timer config */
	cfg.count = 0x10000;
	cfg.int_en = true;
	cfg.callback = aonpt_example_callback;

	qm_irq_request(QM_IRQ_AONPT_0, qm_aonpt_isr_0);

	qm_aonpt_set_config(QM_SCSS_AON_0, &cfg);

	/* The AON Periodic Timer runs from the RTC clock at 32KHz (rather than
	 * the system clock which is 32MHz) so we need to spin for a few cycles
	 * allow the register change to propagate */
	for (delay = 500; delay--;) {
	}

	/* Get the value of the Always-on Periodic Timer */
	pt_val = qm_aonpt_get_value(QM_SCSS_AON_0);
	if (pt_val) {
		QM_PRINTF("Always-on Periodic Timer value: %lu\n", pt_val);
	} else {
		QM_PRINTF("ERROR: Could not read Periodic timer value\n\n");
	}

	QM_PUTS("Always-on counter example app complete\n");
	return 0;
}
Пример #5
0
static int aon_timer_qmsi_stop(struct device *dev)
{
	qm_aonpt_config_t qmsi_cfg;

	qmsi_cfg.callback = NULL;
	qmsi_cfg.int_en = false;
	qmsi_cfg.count = 0;
	qmsi_cfg.callback_data = NULL;

	if (IS_ENABLED(CONFIG_AON_API_REENTRANCY)) {
		k_sem_take(RP_GET(dev), K_FOREVER);
	}

	qm_aonpt_set_config(QM_AONC_0, &qmsi_cfg);

	if (IS_ENABLED(CONFIG_AON_API_REENTRANCY)) {
		k_sem_give(RP_GET(dev));
	}

	return 0;
}