Ejemplo n.º 1
0
int
main (void)
{
	/* Initialize GPIO (sets up clock) */
	GPIOInit ();

	/* Set LED port pin to output */
	GPIOSetDir (LED_PORT, LED_BIT, 1);
	GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);

	/* Init Power Management Routines */
	pmu_init ();

	/* UART setup */
	UARTInit (115200, 0);

	/* CDC USB Initialization */
	init_usbserial ();

	/* Init RFID */
	rfid_init ();

	/* Init emulation triggers */
	trigger_init ();

	/* RUN RFID loop */
	loop_rfid ();

	return 0;
}
Ejemplo n.º 2
0
int
main (void)
{
	uint64_t time_us;

	/* Initialize GPIO (sets up clock) */
	GPIOInit ();

	/* Set eMeter port pin to input/pullup/hysteresis/CAP0 */
	LPC_IOCON->PIO1_5 = 2| 2<<3 | 1<<5;
	GPIOSetDir (EMETER_PORT, EMETER_PIN, 0);
	GPIOSetValue (EMETER_PORT, EMETER_PIN, 0);

	/* Set LED port pin to output */
	GPIOSetDir (LED_PORT, LED_PIN0, 1);
	GPIOSetDir (LED_PORT, LED_PIN1, 1);
	GPIOSetValue (LED_PORT, LED_PIN0, LED_OFF);
	GPIOSetValue (LED_PORT, LED_PIN1, LED_OFF);

	/* Init Power Management Routines */
	pmu_init ();

	/* CDC USB Initialization */
	init_usbserial ();

	/* configure TMR32B0 for capturing eMeter pulse duration in us */
	LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 9);
	LPC_TMR32B0->PR = SYSTEM_CORE_CLOCK/1000000;
	LPC_TMR32B0->TCR = 2;
	LPC_TMR32B0->CCR = 6;

	/* enable TMR32B0 timer IRQ */
	pulse_count = pulse_length = 0;
	timer_old = LPC_TMR32B0->TC;
	NVIC_EnableIRQ(TIMER_32_0_IRQn);

	/* release counter */
	LPC_TMR32B0->TCR = 1;

	time_us=0;
	while(TRUE)
	{
		if(pulse_length)
		{
			time_us+=pulse_length;
			/* print count, time[s], power[mWh] */
			debug_printf (
				"%u,%u,%u\n",
				pulse_count,
				(uint32_t)(time_us/1000000UL),
				(uint32_t)(3600000000000ULL/pulse_length)
			);
			pulse_length = 0;
		}

		/* blink once per second */
		GPIOSetValue (LED_PORT, LED_PIN0, LED_ON);
		pmu_wait_ms(50);
		GPIOSetValue (LED_PORT, LED_PIN0, LED_OFF);
		pmu_wait_ms(950);
	}

	return 0;
}