示例#1
0
OSStatus platform_mcu_powersave_init(void)
{
#ifndef MICO_DISABLE_MCU_POWERSAVE
    #error Not working currently, uncomment MICO_DISABLE_MCU_POWERSAVE in platform_config.h
    /* Initialise all pins to be input pull-up to save power */
    ioport_enable_port( IOPORT_PIOA,   0xffffffffU );
    ioport_set_port_mode( IOPORT_PIOA, 0xffffffffU, IOPORT_MODE_PULLUP );
    ioport_set_port_dir( IOPORT_PIOA,  0xffffffffU, IOPORT_DIR_INPUT );

    ioport_enable_port( IOPORT_PIOB,   0xffffffffU );
    ioport_set_port_mode( IOPORT_PIOB, 0xffffffffU, IOPORT_MODE_PULLUP );
    ioport_set_port_dir( IOPORT_PIOB,  0xffffffffU, IOPORT_DIR_INPUT );

    NVIC_DisableIRQ( RTT_IRQn );
    NVIC_ClearPendingIRQ( RTT_IRQn );
    NVIC_EnableIRQ( RTT_IRQn );
    pmc_set_fast_startup_input( PMC_FSMR_RTTAL );


    rtt_init( RTT, RTT_CLOCK_PRESCALER );
    rtt_write_alarm_time( RTT, 64000 );
   

#endif /* MICO_DISABLE_MCU_POWERSAVE */

    return kNoErr;
}
示例#2
0
void port_mode(port_t *obj, PinMode mode)
{
    MBED_ASSERT(obj);
    obj->mode = mode;
    switch (mode) {
        case PullNone :
            ioport_set_port_mode(obj->port, obj->mask, IOPORT_MODE_OPEN_DRAIN);
            break;
        case PullUp:
            ioport_set_port_mode(obj->port, obj->mask, IOPORT_MODE_PULLUP);
            break;
        case PullDown:
            ioport_set_port_mode(obj->port, obj->mask, IOPORT_MODE_PULLDOWN);
            break;
    }
}
示例#3
0
int main(void)
{
	/* Use static volatile to make it available in debug watch */
	static volatile ioport_port_mask_t port_val;

	sysclk_init();
	board_init();
	ioport_init();

	delay_init(sysclk_get_cpu_hz());

	/* Set output direction on the given LED IOPORTs */
	ioport_set_port_dir(EXAMPLE_LED_PORT, EXAMPLE_LED_MASK,
			IOPORT_DIR_OUTPUT);

#ifdef EXAMPLE_BUTTON_PORT
	/* Set direction and pullup on the given button IOPORT */
	ioport_set_port_dir(EXAMPLE_BUTTON_PORT, EXAMPLE_BUTTON_MASK,
			IOPORT_DIR_INPUT);
	ioport_set_port_mode(EXAMPLE_BUTTON_PORT, EXAMPLE_BUTTON_MASK,
			IOPORT_MODE_PULLUP);

	/* Set LED IOPORTs high */
	ioport_set_port_level(EXAMPLE_LED_PORT, EXAMPLE_LED_MASK,
			IOPORT_PIN_LEVEL_HIGH);
#endif

	while (true) {
		/* Toggle LED IOPORTs with half a second interval */
		ioport_toggle_port_level(EXAMPLE_LED_PORT, EXAMPLE_LED_MASK);
		delay_ms(500);

#ifdef EXAMPLE_BUTTON_PORT
		/* Get value from button port */
		/* Use watch with debugger to see it */
		port_val = ioport_get_port_level(EXAMPLE_BUTTON_PORT,
				EXAMPLE_BUTTON_MASK);
#endif
	}
}
示例#4
0
void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
{
    MBED_ASSERT(obj);
    if (g_sys_init == 0) {
        sysclk_init();
        system_board_init();
        g_sys_init = 1;
    }
    obj->port = port;
    obj->mask = mask;

    switch (dir) {
        case PIN_INPUT :
            ioport_set_port_dir(port, mask, IOPORT_DIR_INPUT);
            break;
        case PIN_OUTPUT:
            ioport_set_port_dir(port, mask, IOPORT_DIR_OUTPUT);
            break;
        case PIN_INPUT_OUTPUT:
            ioport_set_port_dir(port, mask, IOPORT_DIR_OUTPUT);
            break;
    }
    ioport_set_port_mode(port, mask, IOPORT_MODE_PULLUP);
}
示例#5
0
文件: unit_tests.c 项目: 70year/MICO
/**
 * \brief Test IOPORT port level is getting changed.
 *
 * This function set the direction of CONF_PORT_OUT_PIN_MASK to output mode with
 * pull-up enabled and read the status of pin using CONF_PORT_IN_PIN_MASK which
 * is configured in input mode.
 * The pin CONF_PORT_OUT_PIN_MASK and CONF_PORT_IN_PIN_MASK are shorted using a
 * jumper.
 *
 * \param test Current test case.
 */
static void run_ioport_port_test(const struct test_case *test)
{
	static volatile pin_mask_t port_val;

	/* Set direction and pull-up on the given IOPORT */
	ioport_set_port_dir(CONF_PORT, CONF_PORT_IN_PIN_MASK, IOPORT_DIR_INPUT);
	ioport_set_port_mode(CONF_PORT, CONF_PORT_IN_PIN_MASK,
			IOPORT_MODE_PULLUP);

	/* Set output direction on the given IOPORT */
	ioport_set_port_dir(CONF_PORT, CONF_PORT_OUT_PIN_MASK,
			IOPORT_DIR_OUTPUT);

	/* Set  IOPORT as high */
	ioport_set_port_level(CONF_PORT, CONF_PORT_OUT_PIN_MASK,
			IOPORT_PIN_LEVEL_HIGH);
	delay_ms(10);
	port_val = ioport_get_port_level(CONF_PORT, CONF_PORT_IN_PIN_MASK);
	test_assert_true(test, port_val == CONF_PORT_IN_PIN_MASK,
			"IOPORT Set port level high test failed.");

	/* Set  IOPORT as low */
	ioport_set_port_level(CONF_PORT, CONF_PORT_OUT_PIN_MASK,
			IOPORT_PIN_LEVEL_LOW);
	delay_ms(10);
	port_val = ioport_get_port_level(CONF_PORT, CONF_PORT_IN_PIN_MASK);
	test_assert_true(test, port_val == 0,
			"IOPORT Set port level low test failed.");

	/* Toggle  IOPORT */
	ioport_toggle_port_level(CONF_PORT, CONF_PORT_OUT_PIN_MASK);
	delay_ms(10);
	port_val = ioport_get_port_level(CONF_PORT, CONF_PORT_IN_PIN_MASK);
	test_assert_true(test, port_val == CONF_PORT_IN_PIN_MASK,
			"IOPORT Set port level toggle test failed.");
}
示例#6
0
文件: init.c 项目: biddyweb/entropy
void board_init(void)
{
#ifndef CONF_BOARD_KEEP_WATCHDOG_AT_INIT
	struct wdt_dev_inst wdt_inst;
	struct wdt_config   wdt_cfg;

	wdt_get_config_defaults(&wdt_cfg);
	wdt_init(&wdt_inst, WDT, &wdt_cfg);
	wdt_disable(&wdt_inst);
#endif

	/* Initialize IOPORT */
	ioport_init();

	/* Initialize LEDs, turned off */
	ioport_set_port_dir(LED_PORT, LED_MASK, IOPORT_DIR_OUTPUT);
	ioport_set_port_level(LED_PORT, LED_MASK, LED_INACTIVE);
    ioport_set_port_mode(LED_PORT, LED_MASK, IOPORT_MODE_DRIVE_STRENGTH);

	/* Initialize SW0 */
	ioport_set_pin_dir(BUTTON_0_PIN, IOPORT_DIR_INPUT);
	ioport_set_pin_mode(BUTTON_0_PIN, IOPORT_MODE_PULLUP);

#ifdef CONF_BOARD_EIC
	/* Set push button as external interrupt pin */
	ioport_set_pin_peripheral_mode(BUTTON_0_EIC_PIN,
			BUTTON_0_EIC_PIN_MUX | IOPORT_MODE_PULLUP);
#else
	/* Push button as input: already done, it's the default pin state */
#endif

#if defined (CONF_BOARD_COM_PORT)
	ioport_set_pin_peripheral_mode(COM_PORT_RX_PIN, COM_PORT_RX_MUX);
	ioport_set_pin_peripheral_mode(COM_PORT_TX_PIN, COM_PORT_TX_MUX);
#endif

#ifdef CONF_BOARD_TWIMS0
	ioport_set_pin_peripheral_mode(PIN_PA23B_TWIMS0_TWD,
			MUX_PA23B_TWIMS0_TWD);
	ioport_set_pin_peripheral_mode(PIN_PA24B_TWIMS0_TWCK,
			MUX_PA24B_TWIMS0_TWCK);
#endif

#ifdef CONF_BOARD_TWIMS3
	ioport_set_pin_peripheral_mode(PIN_PB14C_TWIMS3_TWD,
			MUX_PB14C_TWIMS3_TWD);
	ioport_set_pin_peripheral_mode(PIN_PB15C_TWIMS3_TWCK,
			MUX_PB15C_TWIMS3_TWCK);
#endif

#ifdef CONF_BOARD_USART0
	ioport_set_pin_peripheral_mode(EXT1_PIN_UART_RX, EXT1_UART_RX_MUX);
	ioport_set_pin_peripheral_mode(EXT1_PIN_UART_TX, EXT1_UART_TX_MUX);
#endif

#if (defined CONF_BOARD_USB_PORT)
	ioport_set_pin_peripheral_mode(PIN_PA25A_USBC_DM, MUX_PA25A_USBC_DM);
	ioport_set_pin_peripheral_mode(PIN_PA26A_USBC_DP, MUX_PA26A_USBC_DP);
# if defined(CONF_BOARD_USB_VBUS_DETECT)
	ioport_set_pin_dir(USB_VBUS_PIN, IOPORT_DIR_INPUT);
# endif
# if defined(CONF_BOARD_USB_ID_DETECT)
	ioport_set_pin_dir(USB_ID_PIN, IOPORT_DIR_INPUT);
# endif
# if defined(CONF_BOARD_USB_VBUS_CONTROL)
	ioport_set_pin_dir(USB_VBOF_PIN, IOPORT_DIR_OUTPUT);
	ioport_set_pin_level(USB_VBOF_PIN, USB_VBOF_INACTIVE_LEVEL);
# endif
#endif

#if defined(CONF_BOARD_SPI) || defined(CONF_BOARD_SD_MMC_SPI)
	ioport_set_pin_peripheral_mode(PIN_PA21A_SPI_MISO, MUX_PA21A_SPI_MISO);
	ioport_set_pin_peripheral_mode(PIN_PA22A_SPI_MOSI, MUX_PA22A_SPI_MOSI);
	ioport_set_pin_peripheral_mode(PIN_PC30B_SPI_SCK, MUX_PC30B_SPI_SCK);

	#ifdef CONF_BOARD_SD_MMC_SPI
		/* Setting SD detection pin */
		ioport_set_pin_dir(SD_MMC_0_CD_GPIO, IOPORT_DIR_INPUT);
		ioport_set_pin_mode(SD_MMC_0_CD_GPIO, IOPORT_MODE_PULLUP);

		/* Setting SD CS pin */
		ioport_set_pin_peripheral_mode(SPI_NPCS0_GPIO, SPI_NPCS0_FLAGS);
	#endif
	#ifdef CONF_BOARD_SPI_NPCS0
		ioport_set_pin_peripheral_mode(PIN_PC03A_SPI_NPCS0,
				MUX_PC03A_SPI_NPCS0);
	#endif
	#ifdef CONF_BOARD_SPI_NPCS1
		ioport_set_pin_peripheral_mode(PIN_PB13B_SPI_NPCS1,
				MUX_PB13B_SPI_NPCS1);
	#endif
	#ifdef CONF_BOARD_SPI_NPCS2
		ioport_set_pin_peripheral_mode(PIN_PB11B_SPI_NPCS2,
				MUX_PB11B_SPI_NPCS2);
	#endif
#endif

#ifdef CONF_BOARD_DACC_VOUT
	ioport_set_pin_peripheral_mode(DACC_VOUT_PIN, DACC_VOUT_MUX);
#endif

#ifdef CONF_BOARD_ACIFC
	ioport_set_pin_peripheral_mode(PIN_PA06E_ACIFC_ACAN0, MUX_PA06E_ACIFC_ACAN0);
	ioport_set_pin_peripheral_mode(PIN_PA07E_ACIFC_ACAP0, MUX_PA07E_ACIFC_ACAP0);
#endif
}