Exemple #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;
}
Exemple #2
0
int __init oprofile_arch_init(struct oprofile_operations **ops)
{
	int ret = -ENODEV;

#ifdef CONFIG_CPU_XSCALE
	ret = pmu_init(ops, &op_xscale_spec);
#endif
	return ret;
}
Exemple #3
0
static void
pmu_attach(device_t parent, device_t self, void *aux)
{
	struct confargs *ca = aux;
	struct pmu_softc *sc = device_private(self);
#if notyet
	struct i2cbus_attach_args iba;
#endif
	uint32_t regs[16];
	int irq = ca->ca_intr[0];
	int node, extint_node, root_node;
	int nbat = 1, i, pmnode;
	int type = IST_EDGE;
	uint8_t cmd[2] = {2, 0};
	uint8_t resp[16];
	char name[256];

	extint_node = of_getnode_byname(OF_parent(ca->ca_node), "extint-gpio1");
	if (extint_node) {

		OF_getprop(extint_node, "interrupts", &irq, 4);
		type = IST_LEVEL;
	}

	aprint_normal(" irq %d: ", irq);

	sc->sc_dev = self;
	sc->sc_node = ca->ca_node;
	sc->sc_memt = ca->ca_tag;

	root_node = OF_finddevice("/");

	sc->sc_error = 0;
	sc->sc_autopoll = 0;
	sc->sc_pending_eject = 0;
	sc->sc_brightness = sc->sc_brightness_wanted = 0x80;
	sc->sc_volume = sc->sc_volume_wanted = 0x80;
	sc->sc_flags = 0;
	sc->sc_callback = NULL;
	sc->sc_lid_closed = 0;

	if (bus_space_map(sc->sc_memt, ca->ca_reg[0] + ca->ca_baseaddr,
	    ca->ca_reg[1], 0, &sc->sc_memh) != 0) {
		aprint_error_dev(self, "unable to map registers\n");
		return;
	}
	sc->sc_ih = intr_establish(irq, type, IPL_TTY, pmu_intr, sc);

	pmu_init(sc);

	sc->sc_pmu_ops.cookie = sc;
	sc->sc_pmu_ops.do_command = pmu_send;
	sc->sc_pmu_ops.register_callback = pmu_register_callback;

	if (pmu0 == NULL)
		pmu0 = sc;

	pmu_send(sc, PMU_SYSTEM_READY, 1, cmd, 16, resp);

	/* check what kind of PMU we're talking to */
	if (pmu_send(sc, PMU_GET_VERSION, 0, cmd, 16, resp) > 1)
		aprint_normal(" rev. %d", resp[1]);
	aprint_normal("\n");

	node = OF_child(sc->sc_node);

	while (node != 0) {

		if (OF_getprop(node, "name", name, 256) == 0)
			goto next;

		if (strncmp(name, "pmu-i2c", 8) == 0) {
			aprint_normal_dev(self, "initializing IIC bus\n");
			goto next;
		}
		if (strncmp(name, "adb", 4) == 0) {
			aprint_normal_dev(self, "initializing ADB\n");
			sc->sc_adbops.cookie = sc;
			sc->sc_adbops.send = pmu_adb_send;
			sc->sc_adbops.poll = pmu_adb_poll;
			sc->sc_adbops.autopoll = pmu_autopoll;
			sc->sc_adbops.set_handler = pmu_adb_set_handler;
#if NNADB > 0
			config_found_ia(self, "adb_bus", &sc->sc_adbops,
			    nadb_print);
#endif
			goto next;
		}
		if (strncmp(name, "rtc", 4) == 0) {

			aprint_normal_dev(self, "initializing RTC\n");
			sc->sc_todr.todr_gettime = pmu_todr_get;
			sc->sc_todr.todr_settime = pmu_todr_set;
			sc->sc_todr.cookie = sc;
			todr_attach(&sc->sc_todr);
			goto next;
		}
		if (strncmp(name, "battery", 8) == 0)
			goto next;

		aprint_normal_dev(self, "%s not configured\n", name);
next:
		node = OF_peer(node);
	}

	if (OF_finddevice("/bandit/ohare") != -1) {
		aprint_normal_dev(self, "enabling ohare backlight control\n");
		sc->sc_flags |= PMU_HAS_BACKLIGHT_CONTROL;
		cmd[0] = 0;
		cmd[1] = 0;
		memset(resp, 0, 6);
		if (pmu_send(sc, PMU_READ_BRIGHTNESS, 1, cmd, 16, resp) > 1) {
			sc->sc_brightness_wanted = resp[1];
			pmu_update_brightness(sc);
		}
	}

	/* attach batteries */
	if (of_compatible(root_node, has_legacy_battery) != -1) {

		pmu_attach_legacy_battery(sc);
	} else if (of_compatible(root_node, has_two_smart_batteries) != -1) {

		pmu_attach_smart_battery(sc, 0);
		pmu_attach_smart_battery(sc, 1);
	} else {

		/* check how many batteries we have */
		pmnode = of_getnode_byname(ca->ca_node, "power-mgt");
		if (pmnode == -1)
			goto bat_done;
		if (OF_getprop(pmnode, "prim-info", regs, sizeof(regs)) < 24)
			goto bat_done;
		nbat = regs[6] >> 16;
		for (i = 0; i < nbat; i++)
			pmu_attach_smart_battery(sc, i);
	}
bat_done:

#if notyet
	memset(&iba, 0, sizeof(iba));
	iba.iba_tag = &sc->sc_i2c;
	sc->sc_i2c.ic_cookie = sc;
	sc->sc_i2c.ic_acquire_bus = pmu_i2c_acquire_bus;
	sc->sc_i2c.ic_release_bus = pmu_i2c_release_bus;
	sc->sc_i2c.ic_send_start = NULL;
	sc->sc_i2c.ic_send_stop = NULL;
	sc->sc_i2c.ic_initiate_xfer = NULL;
	sc->sc_i2c.ic_read_byte = NULL;
	sc->sc_i2c.ic_write_byte = NULL;
	sc->sc_i2c.ic_exec = pmu_i2c_exec;
	config_found_ia(sc->sc_dev, "i2cbus", &iba, iicbus_print);
#endif
	
	if (kthread_create(PRI_NONE, 0, NULL, pmu_thread, sc, &sc->sc_thread,
	    "%s", "pmu") != 0) {
		aprint_error_dev(self, "unable to create event kthread\n");
	}

	sc->sc_lidswitch.smpsw_name = "Lid switch";
	sc->sc_lidswitch.smpsw_type = PSWITCH_TYPE_LID;
	if (sysmon_pswitch_register(&sc->sc_lidswitch) != 0)
		aprint_error_dev(self,
		    "unable to register lid switch with sysmon\n");
}
void charger_task(void)
{
	int next_state;
	int wait_time = T1_USEC;
	timestamp_t pre_chg_start = get_time();

	pmu_init();

	/* Enable low current charging */
	pmu_low_current_charging(1);

	/* Enable charger interrupt */
	gpio_enable_interrupt(GPIO_CHARGER_INT_L);

	/*
	 * EC STOP mode support
	 *   The charging loop can be stopped in idle state with AC unplugged.
	 *   Charging loop will be resumed by TPSCHROME interrupt.
	 */
	enable_charging(0);
	disable_sleep(SLEEP_MASK_CHARGING);

	while (1) {
		last_waken = get_time();
		pmu_clear_irq();

#ifdef CONFIG_PMU_TPS65090_CHARGING_LED
		update_battery_led();
#endif
		/*
		 * When battery is extremely low, the internal voltage can not
		 * power on its gas guage IC. Charging loop will enable the
		 * charger and turn on trickle charging. For safty reason,
		 * charger should be disabled if the communication to battery
		 * failed.
		 */
		if (current_state == ST_PRE_CHARGING &&
		    get_time().val - pre_chg_start.val >= PRE_CHARGING_TIMEOUT)
			next_state = ST_CHARGING_ERROR;
		else
			next_state = calc_next_state(current_state);

		if (next_state != current_state) {
			/* Reset state of charge moving average window */
			rsoc_moving_average(-1);

			CPRINTS("batt state %s -> %s",
				state_list[current_state],
				state_list[next_state]);

			current_state = next_state;

			switch (current_state) {
			case ST_PRE_CHARGING:
				pre_chg_start = get_time();
				/* Fall through */
			case ST_CHARGING:
				if (pmu_blink_led(0))
					next_state = ST_CHARGING_ERROR;
				else
					enable_charging(1);
				break;
			case ST_CHARGING_ERROR:
				/*
				 * Enable hardware charging circuit after set
				 * PMU to hardware error state.
				 */
				if (pmu_blink_led(1))
					enable_charging(0);
				else
					enable_charging(1);
				break;
			case ST_IDLE:
			case ST_IDLE0:
			case ST_BAD_COND:
			case ST_DISCHARGING:
				enable_charging(0);
				/* Ignore charger error when discharging */
				pmu_blink_led(0);
				break;
			}
		}

		switch (current_state) {
		case ST_CHARGING:
		case ST_CHARGING_ERROR:
			wait_time = T2_USEC;
			break;
		case ST_DISCHARGING:
			wait_time = T3_USEC;
			break;
		case ST_PRE_CHARGING:
			wait_time = T1_USEC;
			if (get_time().val - pre_chg_start.val >=
			    PRE_CHARGING_TIMEOUT)
				enable_charging(0);
			break;
		default:
			if (extpower_is_present()) {
				wait_time = T1_USEC;
				break;
			} else if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
				wait_time = T1_OFF_USEC;
				enable_sleep(SLEEP_MASK_CHARGING);
			} else if (chipset_in_state(CHIPSET_STATE_SUSPEND)) {
				wait_time = T1_SUSPEND_USEC;
			} else {
				wait_time = T1_USEC;
			}
		}

		if (!has_pending_event) {
			task_wait_event(wait_time);
			disable_sleep(SLEEP_MASK_CHARGING);
		} else {
			has_pending_event = 0;
		}
	}
}
Exemple #5
0
int
main (void)
{
	double t;
	int i, word, x, y;
	const TWordPos *w;
	TRGB color, *p;

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

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

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

	/* setup SPI chipselect pin */
	spi_init ();
	spi_init_pin (SPI_CS_RGB);

	/* transmit image */
	t = 0;
	word = 0;
	while(1)
	{
		/* set background to red */
		memset(g_data, g_cie[0x00], sizeof(g_data));
		for(y=0; y<LED_Y; y++)
			for(x=0; x<LED_X; x++)
			{
				g_data[y][x].r = g_cie[0x16];
				g_data[y][x].g = g_cie[0x0B];
			}

		/* get next word */
		i = g_sentence[word/DELAY];
		word++;
		if(word>=(WORD_COUNT*DELAY))
			word=0;

		if(i>=0)
		{
			w = &g_words[i];

			for(i=0; i<w->length; i++)
			{
				/* word coordinates */
				x = w->x + i;
				y = w->y;

				/* update color */
				color.r = (sin( x*0.1+cos(y*0.1+t))*CIE_MAX_INDEX2)+CIE_MAX_INDEX2;
				color.g = (cos(-y*0.2-sin(x*0.3-t))*CIE_MAX_INDEX2)+CIE_MAX_INDEX2;
				color.b = (cos( x*0.5-cos(y*0.4+t))*CIE_MAX_INDEX2)+CIE_MAX_INDEX2;

				p = &g_data[y][x];
				p->r = g_cie[color.r];
				p->g = g_cie[color.g];
				p->b = g_cie[color.b];
			}
		}
		/* send data */
		update_leds();
		pmu_wait_ms(1);

		t+=0.01;
	}
}
Exemple #6
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;
}
Exemple #7
0
int
main (void)
{
/* accelerometer readings fifo */
		TFifoEntry acc_lowpass;
		TFifoEntry fifo_buf[FIFO_DEPTH];
		int fifo_pos;
		TFifoEntry *fifo;

		uint32_t SSPdiv;
		uint16_t oid_last_seen;
		uint8_t cmd_buffer[64], cmd_pos, c;
		uint8_t volatile *uart;
		int x, y, z, moving;
		volatile int t;
		int i;

		/* wait on boot - debounce */
		for (t = 0; t < 2000000; t++);

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

		/* initialize pins */
		pin_init ();

		/* fire up LED 1 */
		GPIOSetValue (1, 1, 1);

		/* initialize SPI */
		spi_init ();

		/* read device UUID */
		bzero (&device_uuid, sizeof (device_uuid));
		iap_read_uid (&device_uuid);
		tag_id = crc16 ((uint8_t *) & device_uuid, sizeof (device_uuid));
		random_seed =
				device_uuid[0] ^ device_uuid[1] ^ device_uuid[2] ^ device_uuid[3];

		/************ IF Plugged to computer upon reset ? ******************/
		if (GPIOGetValue (0, 3))
		{
			/* wait some time till Bluetooth is off */
			for (t = 0; t < 2000000; t++);

			/* Init 3D acceleration sensor */
			acc_init (1);
			/* Init Flash Storage with USB */
			storage_init (TRUE, tag_id);
			g_storage_items = storage_items ();

			/* Init Bluetooth */
			bt_init (TRUE, tag_id);

			/* switch to LED 2 */
			GPIOSetValue (1, 1, 0);
			GPIOSetValue (1, 2, 1);

			/* set command buffer to empty */
			cmd_pos = 0;

			/* spin in loop */
			while (1)
			{
				/* reset after USB unplug */
				if (!GPIOGetValue (0, 3))
					NVIC_SystemReset ();

				/* if UART rx send to menue */
				if (UARTCount)
				{
					/* blink LED1 upon Bluetooth command */
					GPIOSetValue (1, 1, 1);
					/* execute menue command with last character received */

					/* scan through whole UART buffer */
					uart = UARTBuffer;
					for (i = UARTCount; i > 0; i--)
					{
						UARTCount--;
						c = *uart++;
						if ((c < ' ') && cmd_pos)
						{
							/* if one-character command - execute */
							if (cmd_pos == 1)
								main_menue (cmd_buffer[0]);
							else
							{
								cmd_buffer[cmd_pos] = 0;
								debug_printf
								("Unknown command '%s' - please press H+[Enter] for help\n# ",
										cmd_buffer);
							}

							/* set command buffer to empty */
							cmd_pos = 0;
						}
						else if (cmd_pos < (sizeof (cmd_buffer) - 2))
							cmd_buffer[cmd_pos++] = c;
					}

					/* reset UART buffer */
					UARTCount = 0;
					/* un-blink LED1 */
					GPIOSetValue (1, 1, 0);
				}
			}
		} /* End of if plugged to computer*/


		/***************** IF UNPLUGGED TO PC ........********/

		/* Init Bluetooth */
		bt_init (FALSE, tag_id);

		/* shut down up LED 1 */
		GPIOSetValue (1, 1, 0);

		/* Init Flash Storage without USB */
		storage_init (FALSE, tag_id);

		/* get current FLASH storage write postition */
		g_storage_items = storage_items ();

		/* initialize power management */
		pmu_init ();

		/* blink once to show initialized flash */
		blink (1);

		/* Init 3D acceleration sensor */
		acc_init (0);
		blink (2);

		/* Initialize OpenBeacon nRF24L01 interface */
		if (!nRFAPI_Init(CONFIG_TRACKER_CHANNEL, broadcast_mac, sizeof (broadcast_mac), 0))
			for (;;)
			{
				GPIOSetValue (1, 2, 1);
				pmu_sleep_ms (500);
				GPIOSetValue (1, 2, 0);
				pmu_sleep_ms (500);
			}
		/* set tx power power to high */
		nRFCMD_Power (1);

		/* blink three times to show flash initialized RF interface */
		blink (3);

		/* blink LED for 1s to show readyness */
		GPIOSetValue (1, 1, 0);
		GPIOSetValue (1, 2, 1);
		pmu_sleep_ms (1000);
		GPIOSetValue (1, 2, 0);

		/* disable unused jobs */
		SSPdiv = LPC_SYSCON->SSPCLKDIV;
		i = 0;
		oid_last_seen = 0;

		/* reset proximity buffer */
		prox_head = prox_tail = 0;
		bzero (&prox, sizeof (prox));

		/*initialize FIFO */
		fifo_pos = 0;
		bzero (&acc_lowpass, sizeof (acc_lowpass));
		bzero (&fifo_buf, sizeof (fifo_buf));

		moving = 0;
		g_sequence = 0;

		while (1)
		{
			
			pmu_sleep_ms (500);

			LPC_SYSCON->SSPCLKDIV = SSPdiv;
			acc_power (1);
			pmu_sleep_ms (20);
			acc_xyz_read (&x, &y, &z);
			acc_power (0);

			fifo = &fifo_buf[fifo_pos];
			if (fifo_pos >= (FIFO_DEPTH - 1))
				fifo_pos = 0;
			else
				fifo_pos++;

			acc_lowpass.x += x - fifo->x;
			fifo->x = x;
			acc_lowpass.y += y - fifo->y;
			fifo->y = y;
			acc_lowpass.z += z - fifo->z;
			fifo->z = z;


			nRFAPI_SetRxMode (0);

			bzero (&g_Beacon, sizeof (g_Beacon));
			g_Beacon.pkt.proto = RFBPROTO_BEACONTRACKER_EXT;
			g_Beacon.pkt.flags = moving ? RFBFLAGS_MOVING : 0;
			g_Beacon.pkt.oid = htons (tag_id);
			g_Beacon.pkt.p.tracker.strength = (i & 1) + TX_STRENGTH_OFFSET;
			g_Beacon.pkt.p.tracker.seq = htonl (LPC_TMR32B0->TC);
			g_Beacon.pkt.p.tracker.oid_last_seen = oid_last_seen;
			g_Beacon.pkt.p.tracker.time = htons ((uint16_t)g_sequence++);
			g_Beacon.pkt.p.tracker.battery = 0;
			g_Beacon.pkt.crc = htons (
					crc16(g_Beacon.byte, sizeof (g_Beacon) - sizeof (g_Beacon.pkt.crc))
					);

			nRFCMD_Power (0);
			nRF_tx (g_Beacon.pkt.p.tracker.strength);
			nRFCMD_Power (1);
			nRFAPI_PowerDown ();
			LPC_SYSCON->SSPCLKDIV = 0x00;
			blink (10);
		}
		

	
	return 0;
}
Exemple #8
0
void
setup_output()
{
    char hdr[1024];
    hdr[sizeof(hdr)-1] = 0;

    pmu_init();
    pmu_start();
    for (int i = 0; i < NGBOXES; ++i)
        for (int j = 0; j < 2; ++j)
        {
            prevnreads += pmu_rdctr(i, j, 0);
            prevnwrites += pmu_rdctr(i, j, 1);
        }
    double ibw = (gbl.ncores-1) * 2 * gbl.hz;
    labels[fInst].max = ibw;
    labels[fVPU].max = ibw;
    double vop = (gbl.ncores-1) * 8 * gbl.hz;
    labels[fVpuSP].max = 2*vop;
    labels[fVpuDP].max = vop;

    // order doesn't really matter but we're used to this and it's better
    // for Excel
    hdrLabels[0] = "Time";
    hdrLabels[1] = "Threads";
    hdrIndexes[0] = fTime;
    hdrIndexes[1] = fThreads;
    int j = 2;
    for (int i = 0; i < nfields; ++i)
        if (i != fTime && i != fThreads)
        {
            hdrLabels[j] = labels[i].name;
            hdrIndexes[j] = i;
            ++j;
        }
    hdr[0] = 0;
    hdr[sizeof(hdr)-1] = 0;
    bool first = true;
    for (int i = 0; i < nfields; ++i)
    {
        if (first)
            first = false;
        else
            strncat(hdr, ",", sizeof(hdr)-1);
        strncat(hdr, hdrLabels[i], sizeof(hdr)-1);
    }
    strncat(hdr, "\n", sizeof(hdr)-1);

    if (gbl.server)
    {
        setup_server();
    }
    else if (gbl.outfile)
    {
        outfile = fopen(gbl.outfile, "w");
        if (outfile == NULL)
            err(1, "create %s", gbl.outfile);
    }

    gbl.hdr[0] = 0;
    gbl.hdr[sizeof(gbl.hdr)-1] = 0;
    if (gbl.server)
    {
        for (int i = 0; i < nfields; ++i)
            if (i != fTime)
                snprintf(gbl.hdr+strlen(gbl.hdr), sizeof(gbl.hdr)-1,
                    "%s=%g,%s,%g\n",
                    labels[i].name,
                    labels[i].max,
                    labels[i].units,
                    labels[i].factor);
        strncat(gbl.hdr, hdr, sizeof(gbl.hdr)-1);
    }
    else if (outfile)
    {
        for (int i = 0; i < nfields; ++i)
            if (i != fTime)
                fprintf(outfile, "%s=%g,%s,%g\n",
                    labels[i].name,
                    labels[i].max,
                    labels[i].units,
                    labels[i].factor);
        fprintf(outfile, hdr);
    }
    starttsc = _rdtsc();
}