void InitSRAM(void) { ioport_configure_pin(SRAM23Kxx_CS, IOPORT_DIR_OUTPUT |IOPORT_INIT_HIGH); //ioport_configure_pin(SRAM23Kxx_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); //ioport_configure_pin(SRAM23Kxx_MOSI, IOPORT_DIR_OUTPUT |IOPORT_INIT_HIGH); //ioport_configure_pin(SRAM23Kxx_MISO, IOPORT_DIR_INPUT); delay_ms(10); // spi_master_init(SRAM23Kxx_SPI); // spi_master_setup_device(SRAM23Kxx_SPI, &spi_device_conf1, SPI_MODE_0, 1000000, 0); // spi_enable(SRAM23Kxx_SPI); }
void ext_int_pcint_init(ioport_pin_t pin) { /* Disable the interrupt */ ext_int_pcint_disable(pin); /* Enable IRQ pin as input */ /* Enable the pullup for the IRQ pin */ ioport_configure_pin(pin, IOPORT_DIR_INPUT | IOPORT_PULL_UP); /* Clear the PCINTn interrupt flag */ ext_int_pcint_clear_flag(pin); /* Enable the interrupt */ ext_int_pcint_enable(pin); }
int main (void) { sysclk_init(); ioport_init(); ioport_set_pin_dir(LED_BLUE, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_GREEN, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_WHITE, IOPORT_DIR_OUTPUT); ioport_configure_pin(BUTTON_0, IOPORT_PULL_UP); ioport_configure_pin(BUTTON_1, IOPORT_PULL_UP); force_boot_loader(); irq_initialize_vectors(); cpu_irq_enable(); udc_start(); //board_init(); while(1) { ioport_toggle_pin_level(LED_GREEN); delay_ms(100); ioport_set_pin_level(LED_BLUE, ioport_get_pin_level(BUTTON_0)); ioport_set_pin_level(LED_WHITE, ioport_get_pin_level(BUTTON_1)); char usb_in = udi_cdc_getc(); char usb_out [17]= "WHAT YOU TYPED: \r";//udi_cdc_getc(); for (int i=0;i<16;i++) { udi_cdc_putc(usb_out[i]); } udi_cdc_putc(usb_in); udi_cdc_putc('\r'); } }
void ext_int_init(ioport_pin_t pin, enum ioport_sense trigmode) { /* Disable the interrupt */ ext_int_disable(pin); /* Enable IRQ pin as input */ /* Enable the pullup for the IRQ pin */ ioport_configure_pin(pin, IOPORT_DIR_INPUT | IOPORT_PULL_UP); /* Setup interrupt sence control */ ioport_set_pin_sense_mode(pin,trigmode); /* Clear the INTn interrupt flag */ ext_int_clear_flag(pin); /* Enable the interrupt */ ext_int_enable(pin); }
void ui_wakeup_enable(void) { PORT_t *port; // Configure pin change interrupt for asynch. wake-up on button pin. ioport_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_2, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_3, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_4, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_5, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_6, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_7, IOPORT_DIR_INPUT | IOPORT_PULL_UP); port = ioport_pin_to_port(GPIO_PUSH_BUTTON_0); port->INT0MASK = 0xFF; port->INTCTRL = PORT_INT0LVL_LO_gc; }
void board_init(void) { ioport_configure_pin(LCD_CSB_O, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(DIR_RS485_1_O, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); ioport_configure_pin(DIR_RS485_2_O, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); ioport_configure_pin(LCD_DIM_O, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); ioport_configure_pin(LCD_RS_O, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); ioport_configure_pin(LCD_MOSI_O, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LCD_CLK_O, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(RS485_1_ACT_I, IOPORT_DIR_INPUT | IOPORT_PULL_DOWN); ioport_configure_pin(RS485_2_ACT_I, IOPORT_DIR_INPUT | IOPORT_PULL_DOWN); ioport_configure_pin(VUSB_I, IOPORT_DIR_INPUT | IOPORT_PULL_DOWN); ioport_configure_pin(USER_SW_I, IOPORT_DIR_INPUT | IOPORT_PULL_UP); }
void board_init(void) { ioport_configure_pin(PORTA0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(PORTA1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(PORTA2_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); }
/** * \internal * \brief Test XCL Glue Logic module with 3 Inputs XOR * * This tests check the capabilty of the XCL Glue Logic Drivers to hangle * a 3 inputs XOR operation. * * \param test Current test case. */ static void run_xcl_glue_logic_3inputs_xor_test( const struct test_case *test) { port_pin_t in0, in2, in3, out0; bool out; in0 = IOPORT_CREATE_PIN(PORTD, 2); in2 = IOPORT_CREATE_PIN(PORTD, 1); in3 = IOPORT_CREATE_PIN(PORTD, 3); out0 = IOPORT_CREATE_PIN(PORTD, 4); ioport_configure_pin(in0, IOPORT_DIR_OUTPUT); ioport_configure_pin(in2, IOPORT_DIR_OUTPUT); ioport_configure_pin(in3, IOPORT_DIR_OUTPUT); /* Configure the XCL module: * - Asynchronous mode usage (locks Power Down sleep mode) * - Configure XCL to use ATxmega32E5 port D * - Configure LUT in 1 LUTs with 3 differents inputs * - LUT IN0 input on pin 2 of port D * - LUT IN1 input on XCL LUT OUT1 * - LUT OUT0 output on pin 4 of port D * - LUT IN2 input on pin 1 of port D * - LUT IN3 input on pin 3 of port D * - LUT OUT1 output on LUT IN1 * - No time Delay for both LUT0 and LUT1 * - LUT0 performs XOR operation * - LUT1 performs XOR operation */ xcl_enable(XCL_ASYNCHRONOUS); xcl_port(PD); xcl_lut_type(LUT_1LUT3IN); xcl_lut_in0(LUT_IN_PINL); xcl_lut_in1(LUT_IN_XCL); xcl_lut_in2(LUT_IN_PINL); xcl_lut_in3(LUT_IN_PINL); xcl_lut0_output(LUT0_OUT_PIN4); xcl_lut_config_delay(DLY11, LUT_DLY_DISABLE, LUT_DLY_DISABLE); xcl_lut0_truth(XOR); xcl_lut1_truth(XOR); gpio_set_pin_low(in0); gpio_set_pin_low(in2); gpio_set_pin_low(in3); asm("nop"); asm("nop"); /* give two cycles propagation delay to read the port pin */ out = ioport_get_pin_level(out0); test_assert_true(test, out == false, " XCL XOR failure"); gpio_set_pin_high(in0); gpio_set_pin_low(in2); gpio_set_pin_low(in3); asm("nop"); asm("nop"); /* give two cycles propagation delay to read the port pin */ out = ioport_get_pin_level(out0); test_assert_true(test, out == true, " XCL XOR failure"); gpio_set_pin_low(in0); gpio_set_pin_high(in2); gpio_set_pin_low(in3); asm("nop"); asm("nop"); /* give two cycles propagation delay to read the port pin */ out = ioport_get_pin_level(out0); test_assert_true(test, out == true, " XCL XOR failure"); gpio_set_pin_low(in0); gpio_set_pin_low(in2); gpio_set_pin_high(in3); asm("nop"); asm("nop"); /* give two cycles propagation delay to read the port pin */ out = ioport_get_pin_level(out0); test_assert_true(test, out == true, " XCL XOR failure"); gpio_set_pin_low(in0); gpio_set_pin_high(in2); gpio_set_pin_high(in3); asm("nop"); asm("nop"); /* give two cycles propagation delay to read the port pin */ out = ioport_get_pin_level(out0); test_assert_true(test, out == false, " XCL XOR failure"); gpio_set_pin_high(in0); gpio_set_pin_high(in2); gpio_set_pin_high(in3); asm("nop"); asm("nop"); /* give two cycles propagation delay to read the port pin */ out = ioport_get_pin_level(out0); test_assert_true(test, out == true, " XCL XOR failure"); }
void board_init(void) { ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED2_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED3_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW | IOPORT_INV_ENABLED); ioport_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_LEVEL | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_INPUT | IOPORT_LEVEL | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_2, IOPORT_DIR_INPUT | IOPORT_LEVEL | IOPORT_PULL_UP); #ifdef CONF_BOARD_C12832A1Z ioport_configure_pin(NHD_C12832A1Z_SPI_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(NHD_C12832A1Z_SPI_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(NHD_C12832A1Z_CSN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(NHD_C12832A1Z_REGISTER_SELECT, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(NHD_C12832A1Z_RESETN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(NHD_C12832A1Z_BACKLIGHT, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); #endif #ifdef CONF_BOARD_AT45DBX ioport_configure_pin(AT45DBX_MASTER_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(AT45DBX_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif #ifdef CONF_BOARD_ENABLE_MXT143E_XPLAINED ioport_configure_pin(MXT143E_XPLAINED_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(MXT143E_XPLAINED_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(MXT143E_XPLAINED_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(MXT143E_XPLAINED_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(MXT143E_XPLAINED_CHG, IOPORT_DIR_INPUT); ioport_configure_pin(MXT143E_XPLAINED_DC, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); #ifndef MXT143E_XPLAINED_BACKLIGHT_DISABLE ioport_configure_pin(MXT143E_XPLAINED_BACKLIGHT, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); #endif ioport_configure_pin(MXT143E_XPLAINED_LCD_RESET, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); #endif #ifdef CONF_BOARD_ENABLE_AC_PINS ioport_configure_pin(IOPORT_CREATE_PIN(PORTA, 0), IOPORT_DIR_INPUT); ioport_configure_pin(IOPORT_CREATE_PIN(PORTA, 2), IOPORT_DIR_INPUT); ioport_configure_pin(IOPORT_CREATE_PIN(PORTB, 1), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTD0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTE0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 2), IOPORT_DIR_INPUT); #endif #if defined (SENSORS_XPLAINED_BOARD) /* Configure the Xplained Sensor extension board, if any, after * the platform Xplained board has configured basic clock settings, * GPIO pin mapping, interrupt controller options, etc. */ sensor_board_init (); #endif #ifdef CONF_BOARD_AT86RFX ioport_configure_pin(AT86RFX_SPI_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT86RFX_SPI_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT86RFX_SPI_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(AT86RFX_SPI_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); /* Initialize TRX_RST and SLP_TR as GPIO. */ ioport_configure_pin(AT86RFX_RST_PIN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT86RFX_SLP_PIN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif }
void board_init(void) { ioport_configure_pin(GPIO_POWER_VBAT_SENSE, IOPORT_DIR_INPUT); ioport_configure_pin(GPIO_POWER_VUSB_SENSE, IOPORT_DIR_INPUT); ioport_configure_pin(GPIO_POWER_GOOD, IOPORT_DIR_INPUT); ioport_configure_pin(GPIO_POWER_DCDC_ENABLE, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_LED_RED, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_LED_GREEN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_LED_YELLOW, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_LED_ORANGE, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); //ioport_configure_pin(GPIO_SWITCH, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_SWITCH, IOPORT_DIR_INPUT); ioport_configure_pin(GPIO_SENSOR_TEMP, IOPORT_DIR_INPUT); // RF #ifdef CONF_BOARD_ENABLE_ANT ioport_configure_pin(nRF24AP2_TX, IOPORT_DIR_INPUT); ioport_configure_pin(nRF24AP2_RX, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); // configure nRESET for rf... ioport_configure_pin(nRF24AP2_nRESET, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); // configure nSUSPEND for rf... ioport_configure_pin(nRF24AP2_nSUSPEND, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); // configure SLEEP for rf... ioport_configure_pin(nRF24AP2_SLEEP, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); // configure RTS for rf... ioport_configure_pin(nRF24AP2_RTS, IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_BLE ioport_configure_pin(BLE_RESET, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(BLE_ACTIVE, IOPORT_DIR_INPUT); ioport_configure_pin(BLE_RDYN, IOPORT_DIR_INPUT); ioport_configure_pin(BLE_REQN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(BLE_MASTER_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(BLE_MASTER_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(BLE_MASTER_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(BLE_TXD, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(BLE_RXD, IOPORT_DIR_INPUT); #endif }
void board_init(void) { ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED2_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED3_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED4_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED5_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED6_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED7_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_2, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_3, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_4, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_5, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_6, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_7, IOPORT_DIR_INPUT | IOPORT_PULL_UP); #ifdef CONF_BOARD_AT45DBX ioport_configure_pin(AT45DBX_MASTER_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(AT45DBX_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif #ifdef CONF_BOARD_ENABLE_AC_PINS ioport_configure_pin(IOPORT_CREATE_PIN(PORTA, 0), IOPORT_DIR_INPUT); ioport_configure_pin(IOPORT_CREATE_PIN(PORTA, 2), IOPORT_DIR_INPUT); ioport_configure_pin(IOPORT_CREATE_PIN(PORTB, 1), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_SPEAKER ioport_configure_pin(IOPORT_CREATE_PIN(PORTQ, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif #ifdef CONF_BOARD_ENABLE_USARTC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTD0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_DISPLAY_XPLAINED ioport_configure_pin(DISPLAY_XPLAINED_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(DISPLAY_XPLAINED_TE, IOPORT_DIR_INPUT); ioport_configure_pin(DISPLAY_XPLAINED_BACKLIGHT, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); ioport_configure_pin(DISPLAY_XPLAINED_RESET, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); # define CONF_BOARD_ENABLE_USARTD1 /* USARTD1 XCK1 */ ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 5), IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); #endif #ifdef CONF_BOARD_ENABLE_USARTD1 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 7), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 6), IOPORT_DIR_INPUT); #endif }
int main(void) { board_init(); sysclk_init(); ioport_init(); sysclk_enable_peripheral_clock(&TRX_CTRL_0); sleep_set_mode(SLEEP_SMODE_PSAVE); cpu_irq_enable(); /* USART options. */ static usart_rs232_options_t USART_SERIAL_OPTIONS = { .baudrate = USART_SERIAL_BAUDRATE, .charlength = USART_SERIAL_CHAR_LENGTH, .paritytype = USART_SERIAL_PARITY, .stopbits = USART_SERIAL_STOP_BIT }; /* Initialize usart driver in RS232 mode */ usart_init_rs232(USART_SERIAL_PORT, &USART_SERIAL_OPTIONS); /* configure port pins*/ ioport_configure_pin(CMP2_INT_CHK_PIN, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT); ioport_configure_pin(CMP3_INT_CHK_PIN, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT); uint8_t tx_buf[] = "\n\rStarting MAC symbol counter"; for (uint8_t i = 0; i < sizeof(tx_buf); i++) { usart_putchar(USART_SERIAL_PORT, tx_buf[i]); } /* * Enable Symbol Counter */ macsc_enable(); macsc_write_clock_source(SYS_CLK_SRC); macsc_sleep_clk_enable(); /* * Configure interrupts callback functions * overflow interrupt, compare 1,2,3 interrupts */ macsc_set_cmp1_int_cb(example_cmp1_int_cb); macsc_set_cmp2_int_cb(example_cmp2_int_cb); macsc_set_cmp3_int_cb(example_cmp3_int_cb); /* * Configure MACSC to generate compare interrupts from channels 1,2,3 * Set compare mode to absolute,set compare value. */ macsc_enable_manual_bts(); macsc_enable_cmp_int(MACSC_CC3); macsc_use_cmp(COMPARE_MODE, BEACON_INTERVAL, MACSC_CC3); do { /* Go to sleep, everything is handled by interrupts. */ if (sleep) { sleep_enable(); sleep_enter(); } } while (1); }
void board_init(void) { ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED2_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED3_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED4_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED5_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED6_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED7_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_PULL_UP | IOPORT_FORCE_ENABLE); ioport_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_INPUT | IOPORT_PULL_UP | IOPORT_FORCE_ENABLE); ioport_configure_pin(GPIO_PUSH_BUTTON_2, IOPORT_DIR_INPUT | IOPORT_PULL_UP | IOPORT_FORCE_ENABLE); ioport_configure_pin(GPIO_PUSH_BUTTON_3, IOPORT_DIR_INPUT | IOPORT_PULL_UP | IOPORT_FORCE_ENABLE); #ifdef CONF_BOARD_ENABLE_AC_PINS ioport_configure_pin(IOPORT_CREATE_PIN(PORTA, 0), IOPORT_DIR_INPUT); ioport_configure_pin(IOPORT_CREATE_PIN(PORTA, 2), IOPORT_DIR_INPUT); ioport_configure_pin(IOPORT_CREATE_PIN(PORTB, 1), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_AT45DBX ioport_configure_pin(AT45DBX_MASTER_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(AT45DBX_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif #ifdef CONF_BOARD_ENABLE_USARTC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_ENABLE_USARTD0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_ENABLE_USARTC0_ONEWIRE ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTD0_ONEWIRE ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_CLKOUT_PC7 PORTC.DIR |= 0x80; PORTCFG.CLKOUT |= PORTCFG_CLKOUT_PC7_gc; #endif /* XCL OUT0 configurations */ #ifdef CONF_BOARD_XCL_OUT0_PD0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 0), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_XCL_OUT0_PD4 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 4), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_XCL_OUT0_PC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 0), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_XCL_OUT0_PC4 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 4), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_XCL_OUT0_PD0_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 0), IOPORT_DIR_OUTPUT | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_OUT0_PD4_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 4), IOPORT_DIR_OUTPUT | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_OUT0_PC0_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 0), IOPORT_DIR_OUTPUT | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_OUT0_PC4_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 4), IOPORT_DIR_OUTPUT | IOPORT_INV_ENABLED); #endif /* XCL CC0 and CC1 configurations */ #ifdef CONF_BOARD_XCL_CC0_PC2 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_XCL_CC0_PC3 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_XCL_CC0_PD2 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_XCL_CC0_PD3 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_XCL_CC0_PC2_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_OUTPUT | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_CC0_PC3_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_CC0_PD2_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_OUTPUT | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_CC0_PD3_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT | IOPORT_INV_ENABLED); #endif /* XCL IN0 configurations */ #ifdef CONF_BOARD_XCL_IN0_PD2 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN0_PD2_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN0_PD6 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 6), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN0_PD6_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 6), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN0_PC2 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN0_PC2_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN0_PC6 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 6), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN0_PC6_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 6), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif /* XCL IN1 Configurations */ #ifdef CONF_BOARD_XCL_IN1_PD0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 0), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN1_PD0_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 0), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN1_PD4 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 4), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN1_PD4_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 4), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN1_PC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 0), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN1_PC0_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 0), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN1_PC4 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 4), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN1_PC4_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 4), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif /* XCL IN2 Configurations */ #ifdef CONF_BOARD_XCL_IN2_PD1 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 1), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN2_PD1_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 1), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN2_PD5 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 5), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN2_PD5_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 5), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN2_PC1 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 1), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN2_PC1_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 1), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN2_PC5 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 5), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN2_PC5_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 5), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif /* XCL IN3 Configurations */ #ifdef CONF_BOARD_XCL_IN3_PD3 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN3_PD3_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN3_PD7 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 7), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN3_PD7_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 7), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN3_PC3 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN3_PC3_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif #ifdef CONF_BOARD_XCL_IN3_PC7 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 7), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE); #endif #ifdef CONF_BOARD_XCL_IN3_PC7_INV ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 7), IOPORT_DIR_INPUT | IOPORT_FORCE_ENABLE | IOPORT_INV_ENABLED); #endif /* TC45 Output Configurations */ #ifdef CONF_BOARD_TC45_OUT0_PC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 0), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_TC45_OUT0_PC1 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 1), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_TC45_OUT0_PC2 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_TC45_OUT0_PC3 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_TC45_OUT0_PC4 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 4), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_TC45_OUT0_PC5 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 5), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_TC45_OUT0_PC6 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 6), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_TC45_OUT0_PC7 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 7), IOPORT_DIR_OUTPUT); #endif #ifdef CONF_BOARD_TC45_OUT0_PD4 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 4), IOPORT_DIR_OUTPUT); #endif }
/** * \brief Initialize low power mode * * Disconnect all peripherals, enable pull-up on all I/O pins, disable watchdog * timer and brown out detection, and JTAG-interface (if configured in * \ref conf_low_power_demo.h ) */ static void lowpower_init(void) { /* Disable unused modules */ sysclk_disable_peripheral_clock(&AES); sysclk_disable_peripheral_clock(&DMA); sysclk_disable_peripheral_clock(&EVSYS); #if AVR8_PART_IS_DEFINED(ATxmega128A1) sysclk_disable_peripheral_clock(&RTC); sysclk_disable_peripheral_clock(&EBI); #endif /* Disable TWI */ sysclk_disable_peripheral_clock(&TWIC); #if AVR8_PART_IS_DEFINED(ATxmega128A1) sysclk_disable_peripheral_clock(&TWID); #endif sysclk_disable_peripheral_clock(&TWIE); #if AVR8_PART_IS_DEFINED(ATxmega128A1) sysclk_disable_peripheral_clock(&TWIF); #endif /* Disable SPI */ sysclk_disable_peripheral_clock(&SPIC); sysclk_disable_peripheral_clock(&SPID); #if AVR8_PART_IS_DEFINED(ATxmega128A1) sysclk_disable_peripheral_clock(&SPIF); #endif /* Disable USART */ sysclk_disable_peripheral_clock(&USARTC0); sysclk_disable_peripheral_clock(&USARTC1); sysclk_disable_peripheral_clock(&USARTD0); sysclk_disable_peripheral_clock(&USARTD1); sysclk_disable_peripheral_clock(&USARTE0); #if AVR8_PART_IS_DEFINED(ATxmega128A1) sysclk_disable_peripheral_clock(&USARTE1); #endif sysclk_disable_peripheral_clock(&USARTF0); #if AVR8_PART_IS_DEFINED(ATxmega128A1) sysclk_disable_peripheral_clock(&USARTF1); #endif /* Disable timers/counters */ sysclk_disable_peripheral_clock(&TCC0); sysclk_disable_peripheral_clock(&TCC1); sysclk_disable_peripheral_clock(&TCD0); sysclk_disable_peripheral_clock(&TCD1); sysclk_disable_peripheral_clock(&TCE0); sysclk_disable_peripheral_clock(&TCE1); sysclk_disable_peripheral_clock(&TCF0); #if AVR8_PART_IS_DEFINED(ATxmega128A1) sysclk_disable_peripheral_clock(&TCF1); #endif /* Disable HIRES */ sysclk_disable_peripheral_clock(&HIRESC); sysclk_disable_peripheral_clock(&HIRESD); sysclk_disable_peripheral_clock(&HIRESE); sysclk_disable_peripheral_clock(&HIRESF); /* Disable analog modules */ sysclk_disable_peripheral_clock(&ACA); sysclk_disable_peripheral_clock(&ADCA); #if AVR8_PART_IS_DEFINED(ATxmega128A1) sysclk_disable_peripheral_clock(&DACA); #endif sysclk_disable_peripheral_clock(&ACB); sysclk_disable_peripheral_clock(&ADCB); sysclk_disable_peripheral_clock(&DACB); /* Enable pull-up on all I/O pins */ ioport_configure_port_pin(&PORTA, 0xF4, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_port_pin(&PORTA, 0x03, IOPORT_DIR_INPUT | IOPORT_INPUT_DISABLE); ioport_configure_port_pin(&PORTB, 0x7F, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_port_pin(&PORTC, 0xFF, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_port_pin(&PORTD, 0x3F, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_port_pin(&PORTE, 0x0F, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_port_pin(&PORTF, 0xFF, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_port_pin(&PORTR, 0x03, IOPORT_DIR_INPUT | IOPORT_PULL_UP); #if AVR8_PART_IS_DEFINED(ATxmega256A3BU) /* Disable display for A3BU Xplained */ ioport_configure_pin(NHD_C12832A1Z_RESETN, IOPORT_DIR_INPUT); #endif #if AVR8_PART_IS_DEFINED(ATxmega128A1) ioport_configure_port_pin(&PORTH, 0xFF, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_port_pin(&PORTJ, 0xFF, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_port_pin(&PORTK, 0xFF, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_port_pin(&PORTQ, 0x0F, IOPORT_DIR_INPUT | IOPORT_PULL_UP); #endif /* Disable Watchdog timer */ wdt_disable(); /* Enable EEPROM and Flash power reduction mode. */ ccp_write_io((uint8_t *)&NVM.CTRLB, NVM_EPRM_bm | NVM_FPRM_bm); #ifdef NO_JTAG ccp_write_io((uint8_t *)&MCU.MCUCR, MCU_JTAGD_bm); #endif }
void board_init(void) { /* Enable PSoC USB */ //PORTC.OUT = PIN4_bm; //PORTC.DIR = PIN4_bm; //PORTC.OUTCLR = PIN4_bm; // ///* Disable Battery Power Source */ //PORTE.DIRSET = PIN0_bm; //PORTE.OUTCLR = PIN0_bm; /* Disable Battery Power Source */ ioport_configure_pin(BATTERY_INTERFACE, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); /* Enable PSoC USB */ ioport_configure_pin(PSoC_ENABLE, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); /* Configure GPIOs */ ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_LEVEL | IOPORT_PULL_UP); // Always enable Communication Interfaces ioport_configure_pin(SPIC_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(SPIC_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(USARTC0_TXD, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(USARTC0_RXD, IOPORT_DIR_INPUT); // Always enable Chip Select pin of MicroSD // to unselect this component at default ioport_configure_pin(SD_MMC_SPI_0_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(SD_MMC_0_PWR_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(SD_MMC_0_CD_GPIO, IOPORT_DIR_INPUT | IOPORT_LEVEL | IOPORT_PULL_UP); #if (defined CONF_BOARD_SD_MMC_SPI) // Enable common SPI for MicroSD and OLED ioport_configure_pin(SD_MMC_SPI_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(SD_MMC_SPI_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(SD_MMC_SPI_MISO, IOPORT_DIR_INPUT); #endif #if (defined CONF_BOARD_AT86RFX) ioport_configure_pin(AT86RFX_SPI_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT86RFX_SPI_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT86RFX_SPI_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(AT86RFX_SPI_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); /* Initialize TRX_RST and SLP_TR as GPIO. */ ioport_configure_pin(AT86RFX_RST_PIN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT86RFX_SLP_PIN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif }
int main(void) { // Set the sleep mode to initially lock. enum sleepmgr_mode mode = SLEEPMGR_ACTIVE; PORT_t *port; board_init(); sysclk_init(); // Turn on LED to indicate the device is active. ioport_set_pin_low(LED_PIN); // Configure pin change interrupt for asynch. wake-up on button pin. ioport_configure_pin(BUTTON_PIN, IOPORT_DIR_INPUT | IOPORT_PULL_UP | IOPORT_FALLING); port = ioport_pin_to_port(BUTTON_PIN); #if XMEGA_E port->INTMASK = PIN2_bm; port->INTCTRL = PORT_INTLVL_LO_gc; #else port->INT0MASK = PIN2_bm; port->INTCTRL = PORT_INT0LVL_LO_gc; #endif // Enable RTC with ULP as clock source. sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC); CLK.RTCCTRL = CLK_RTCSRC_ULP_gc | CLK_RTCEN_bm; // Configure RTC for wakeup at 1.5 second period (at 256x prescaling). RTC.PER = 6; RTC.INTCTRL = RTC_OVFINTLVL_LO_gc; // Wait until RTC is ready before continuing. do { } while (RTC.STATUS & RTC_SYNCBUSY_bm); // Initialize the sleep manager, lock initial mode. sleepmgr_init(); sleepmgr_lock_mode(mode); // Enable low level interrupts for wakeups to occur. PMIC.CTRL = PMIC_LOLVLEN_bm; do { // Delay for 3 seconds to show the device is awake. mdelay(3000); // Turn off the LED, restart the RTC and go to sleep. ioport_set_pin_high(LED_PIN); RTC.CNT = 0; RTC.CTRL = RTC_PRESCALER_DIV256_gc; do { } while (RTC.STATUS & RTC_SYNCBUSY_bm); sleepmgr_enter_sleep(); // Stop the RTC and turn on the LED. RTC.CTRL = RTC_PRESCALER_OFF_gc; ioport_set_pin_low(LED_PIN); // Unlock current mode, then lock the next one. sleepmgr_unlock_mode(mode); if (++mode < SLEEPMGR_NR_OF_MODES) { sleepmgr_lock_mode(mode); } else { mode = SLEEPMGR_ACTIVE; sleepmgr_lock_mode(mode); } } while (1); }
void board_init(void) { ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED2_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED3_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED4_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED5_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED6_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED7_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_2, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_3, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_4, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_5, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_6, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_7, IOPORT_DIR_INPUT | IOPORT_PULL_UP); #ifdef CONF_BOARD_AT45DBX #warning Check that the DataFlash AT45DB is mounted on your board ioport_configure_pin(AT45DBX_MASTER_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(AT45DBX_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif #ifdef CONF_BOARD_ENABLE_MXT143E_XPLAINED ioport_configure_pin(MXT143E_XPLAINED_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(MXT143E_XPLAINED_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(MXT143E_XPLAINED_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(MXT143E_XPLAINED_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(MXT143E_XPLAINED_CHG, IOPORT_DIR_INPUT); ioport_configure_pin(MXT143E_XPLAINED_DC, IOPORT_DIR_OUTPUT); #ifndef MXT143E_XPLAINED_BACKLIGHT_DISABLE ioport_configure_pin(MXT143E_XPLAINED_BACKLIGHT, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); #endif ioport_configure_pin(MXT143E_XPLAINED_LCD_RESET, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); #endif #ifdef CONF_BOARD_ENABLE_AC_PINS ioport_configure_pin(IOPORT_CREATE_PIN(PORTA, 0), IOPORT_DIR_INPUT); ioport_configure_pin(IOPORT_CREATE_PIN(PORTA, 2), IOPORT_DIR_INPUT); ioport_configure_pin(IOPORT_CREATE_PIN(PORTB, 1), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_LIGHT_SENSOR ioport_configure_pin(LIGHT_SENSOR_SIGNAL_PIN, IOPORT_DIR_INPUT | IOPORT_INPUT_DISABLE); #endif #ifdef CONF_BOARD_ENABLE_TEMPERATURE_SENSOR ioport_configure_pin(TEMPERATURE_SENSOR_SIGNAL_PIN, IOPORT_DIR_INPUT | IOPORT_INPUT_DISABLE); ioport_configure_pin(TEMPERATURE_SENSOR_ENABLE_PIN, IOPORT_DIR_OUTPUT | (TEMPERATURE_SENSOR_ENABLE_LEVEL ? IOPORT_INIT_HIGH : IOPORT_INIT_LOW)); #endif #ifdef CONF_BOARD_ENABLE_SPEAKER ioport_configure_pin(SPEAKER_SIGNAL_PIN, IOPORT_DIR_INPUT | IOPORT_INPUT_DISABLE); ioport_configure_pin(SPEAKER_ENABLE_PIN, IOPORT_DIR_OUTPUT | (SPEAKER_ENABLE_LEVEL ? IOPORT_INIT_HIGH : IOPORT_INIT_LOW)); #endif #ifdef CONF_BOARD_ENABLE_USARTC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTD0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTF0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTF, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTF, 2), IOPORT_DIR_INPUT); #endif #if defined (SENSORS_XPLAINED_BOARD) /* Configure the Xplained Sensor extension board, if any, after * the platform Xplained board has configured basic clock settings, * GPIO pin mapping, interrupt controller options, etc. */ sensor_board_init (); #elif EXT_BOARD == SECURITY_XPLAINED // Only ATSHA204 I2C devices are supported. security_board_init(); #endif }
void board_init(void) { ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED2_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED3_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED4_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED5_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED6_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED7_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_2, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_3, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_4, IOPORT_DIR_INPUT | IOPORT_PULL_UP); #if !(XMEGA_A3B || XMEGA_A3BU) ioport_configure_pin(GPIO_PUSH_BUTTON_5, IOPORT_DIR_INPUT | IOPORT_PULL_UP); #endif ioport_configure_pin(GPIO_PUSH_BUTTON_6, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_7, IOPORT_DIR_INPUT | IOPORT_PULL_UP); #ifdef CONF_BOARD_AT45DBX ioport_configure_pin(AT45DBX_MASTER_SCK,IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MOSI,IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(AT45DBX_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif #ifdef CONF_BOARD_ENABLE_USARTC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTC1 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 7), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 6), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTD0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTD1 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 7), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 6), IOPORT_DIR_INPUT); #endif #if !(XMEGA_B3) # ifdef CONF_BOARD_ENABLE_USARTE0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 2), IOPORT_DIR_INPUT); # endif # ifdef CONF_BOARD_ENABLE_USARTE1 ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 7), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 6), IOPORT_DIR_INPUT); # endif # ifdef CONF_BOARD_ENABLE_USARTF0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTF, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTF, 2), IOPORT_DIR_INPUT); # endif #endif }
int main(void) { static uint8_t ret = 0; uint8_t i = 0; uint8_t ibuf[16] = {0}; static uint8_t test_pattern[PATTERN_TEST_LENGTH]; sensor_data_t sensor_data; twi_master_options_t opt; irq_initialize_vectors(); sysclk_init(); /* Initialize the board. * The board-specific conf_board.h file contains the configuration of * the board initialization. */ board_init(); gfx_mono_init(); ioport_set_pin_high(NHD_C12832A1Z_BACKLIGHT); gfx_mono_draw_string("Reading....\r\n", 0, 0, &sysfont); gfx_mono_generic_draw_filled_rect(0, 8, 128, 8, GFX_PIXEL_CLR); /* configure the pins connected to LEDs as output and set their default * initial state to low (LEDs off). */ ioport_configure_pin(LED_LOW, IOPORT_DIR_OUTPUT); ioport_configure_pin(LED_HIGH, IOPORT_DIR_OUTPUT); ioport_configure_pin(LED_CRIT, IOPORT_DIR_OUTPUT); ioport_configure_pin(LED_NORM, IOPORT_DIR_OUTPUT); ioport_set_pin_low(LED_LOW); ioport_set_pin_low(LED_HIGH); ioport_set_pin_low(LED_CRIT); ioport_set_pin_low(LED_NORM); /* Configure the ALERT/EVENT pin which is * routed to pin 2 of J2 on A3BU Xplained * This pin can be used for polling or interrupt */ ioport_configure_pin(EVENT_PIN, IOPORT_DIR_INPUT); attach_device(EXAMPLE_TS_DEVICE_ADDR, EXAMPLE_TS_DEVICE); opt.chip = EXAMPLE_TS_DEVICE_ADDR; opt.speed = TWI_SPEED; /* Initialize TWI driver with options */ twi_master_setup(TWI_MODULE, &opt); sensor_data.config_reg.value = 0; /* Set configuration register to 12-bis resolution */ sensor_data.config_reg.option.RES = AT30TS7_RES12; if (write_config(sensor_data.config_reg.value) != TWI_SUCCESS) { test_fail_indication(); } /* Set the polarity of ALERT/EVENT pin to low */ if (set_config_option(&sensor_data, AT30TS_POL, AT30TS7_POL_ACTIVE_LOW) != TWI_SUCCESS) { test_fail_indication(); } /* Read the configuration register */ if (read_config(&sensor_data) != TWI_SUCCESS) { test_fail_indication(); } #if defined _AT30TS00_ || defined _AT30TSE002B_ /* Set t_high limit register to +75.0000C */ if (write_tcrit(pos, 75, 0000) != TWI_SUCCESS) { test_fail_indication(); } #endif /* Set t_high limit register to +50.7500C */ if (write_temperature_high(pos, 50, 7500) != TWI_SUCCESS) { test_fail_indication(); } /* Set t_low limit register to -25.2500C */ /* * if (write_temperature_low(neg, 25, 2500)!= TWI_SUCCESS) { * test_fail_indication(); * } */ /* Set t_low limit register to +35.5000C */ if (write_temperature_low(pos, 35, 5000) != TWI_SUCCESS) { test_fail_indication(); } #if defined _AT30TS00_ || defined _AT30TSE002B_ /* Read t_crit register register */ if (read_tcrit(&sensor_data) != TWI_SUCCESS) { test_fail_indication(); } #endif /* Read t_high limit register */ if (read_temperature_high(&sensor_data) != TWI_SUCCESS) { test_fail_indication(); } /* Read t_low register register */ if (read_temperature_low(&sensor_data) != TWI_SUCCESS) { test_fail_indication(); } /* Non volatile register functionality */ #if defined _AT30TS750_ || defined _AT30TSE752_ || \ defined _AT30TSE754_ || defined _AT30TSE758_ /* Copy volatile registers to nonvolatile registers * vol configuration register -> nonvol configuration register * vol t_high register -> nonvol t_high register * vol t_low register -> nonvol t_low register */ ret = ts75_copy_vol_nonvol_register(); if (ret != TWI_SUCCESS) { test_fail_indication(); } /* Read the nonvol configuration register */ if (read_nvconfig(&sensor_data) != TWI_SUCCESS) { test_fail_indication(); } /* Read the nonvol t_high register */ if (read_nvthigh(&sensor_data) != TWI_SUCCESS) { test_fail_indication(); } /* Read the nonvol t_low register */ if (read_nvtlow(&sensor_data) != TWI_SUCCESS) { test_fail_indication(); } /* Clear vol configuration register */ if (write_config(0x0000) != TWI_SUCCESS) { test_fail_indication(); } /* Read the vol configuration register */ if (read_config(&sensor_data) != TWI_SUCCESS) { test_fail_indication(); } /* Copy nonvolatile registers to volatile registers */ if (ts75_copy_nonvol_vol_register() != TWI_SUCCESS) { test_fail_indication(); } /* Read the configuration register */ if (read_config(&sensor_data) != TWI_SUCCESS) { test_fail_indication(); } #endif /* To avoid 'variable unused' warning */ test_pattern[0] = ibuf[0]; ibuf[0] = test_pattern[0]; /* EEPROM Test */ #if defined _AT30TSE002B_ || defined _AT30TSE752_ || \ defined _AT30TSE754_ || defined _AT30TSE758_ /* Generate Test Pattern */ for (i = 0; i < PATTERN_TEST_LENGTH; i++) { test_pattern[i] = 0x41 + i; // 'ABCD...' } /* Perform a write access & check write result */ if ((ret = ts_write_memory(EE_TEST_ADDR, PATTERN_TEST_LENGTH, (void *)test_pattern)) != TWI_SUCCESS) { gfx_mono_draw_string("EE Write Failed ", 0, 24, &sysfont); test_fail_indication(); } /* Allow time for EEPROM to settle */ delay_ms(5); /* Clear test_pattern */ memset(ibuf, 0, sizeof(ibuf)); /* Perform a read access & check read result */ if (ts_read_eeprom(EE_TEST_ADDR, PATTERN_TEST_LENGTH, ibuf) != TWI_SUCCESS) { gfx_mono_draw_string("EE Read Failed ", 0, 24, &sysfont); test_fail_indication(); } /* Check received data against sent data */ for (i = 0; i < PATTERN_TEST_LENGTH; i++) { if (ibuf[i] != test_pattern[i]) { gfx_mono_draw_string("EE Read mismatch ", 0, 24, &sysfont); test_fail_indication(); } } gfx_mono_draw_string("EE Write/Read OK", 0, 24, &sysfont); gfx_mono_draw_string((char const*)ibuf, 0, 16, &sysfont); #endif /* * Temperature reading contained in struct,i.e. * temperature register value = 0x3240 (+50.25C), AT30TSE758 device * sensor_data.temperature.itemp = 50 //!< integer part * sensor_data.temperature.ftemp = 2500 //!< fractional part * sensor_data.temperature.sign = 0 //!< sign (pos(+) = 0, neg(-) = 1) * sensor_data.temperature.raw_value = 0x324 //!< raw data */ char senseData[50] = {0}; while (1) { /* Read temperature */ read_temperature(&sensor_data); sprintf(senseData, "%d.%04d DegC", sensor_data.temperature.itemp, sensor_data.temperature.ftemp); gfx_mono_draw_string(senseData, 0, 8, &sysfont); ioport_set_pin_low(LED_NORM); delay_ms(200); ioport_set_pin_high(LED_NORM); delay_ms(200); } }
void pin_init(void) { ioport_configure_pin(EXT1_PIN_HUB_STATUS , IOPORT_DIR_INPUT ); ioport_configure_pin(EXT1_PIN_HUB_SUSPEND , IOPORT_DIR_INPUT ); //NON_REM[0] USB hub Boot Strapping option, strapped by resistor ioport_configure_pin(EXT1_PIN_HOST_SHORT_CIRCUIT , IOPORT_DIR_INPUT ); ioport_configure_pin(EXT1_PIN_CAN_TXD , IOPORT_DIR_INPUT ); ioport_configure_pin(EXT1_PIN_CAN_RXD , IOPORT_DIR_INPUT ); ioport_configure_pin(EXT1_PIN_SPI_SS , IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH ); //set slave select high ioport_configure_pin(EXT1_PIN_SPI_MOSI , IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH ); ioport_configure_pin(EXT1_PIN_SPI_MISO , IOPORT_DIR_INPUT ); ioport_configure_pin(EXT1_PIN_SPI_SCK , IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH ); ioport_configure_pin(EXT1_PIN_ACL_INT2 , IOPORT_DIR_INPUT | IOPORT_PULL_UP ); ioport_configure_pin(EXT1_PIN_ACL_INT1 , IOPORT_DIR_INPUT | IOPORT_PULL_UP ); ioport_configure_pin(EXT1_PIN_SR_CLEAR , IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH ); ioport_configure_pin(EXT1_PIN_SR_LATCH , IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW ); ioport_configure_pin(EXT1_PIN_HUB_SDA , IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH ); //1 for NON_REM[1] USB hub Boot Strapping option ioport_configure_pin(EXT1_PIN_HUB_SCL , IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW ); //0 for CFG_SEL USB hub Boot Strapping option ioport_configure_pin(EXT1_PIN_ACL_RXD , IOPORT_DIR_INPUT ); ioport_configure_pin(EXT1_PIN_ACL_TXD , IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH ); ioport_configure_pin(EXT1_PIN_SIM_WAKE , IOPORT_DIR_INPUT ); ioport_configure_pin(EXT1_PIN_SIM_NETWORK , IOPORT_DIR_INPUT ); //ioport_configure_pin(EXT1_PIN_SIM_TXD , IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH ); //ioport_configure_pin(EXT1_PIN_SIM_RXD , IOPORT_DIR_INPUT ); ioport_configure_pin(EXT1_PIN_SIM_PWR , IOPORT_DIR_INPUT ); ioport_configure_pin(EXT1_PIN_SEQ_RXD , IOPORT_DIR_INPUT ); ioport_configure_pin(EXT1_PIN_SEQ_TXD , IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH ); ioport_configure_pin(LED_0_PIN , IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW ); ioport_configure_pin(LED_1_PIN , IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW ); ioport_configure_pin(LED_2_PIN , IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW ); ioport_configure_pin(BUTTON_0_PIN , IOPORT_DIR_INPUT ); ioport_configure_pin(BUTTON_1_PIN , IOPORT_DIR_INPUT | IOPORT_PULL_UP ); //NON_REM[1] USB hub Boot Strapping option ioport_configure_pin(BUF0_PIN , IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW ); //blocks atmel serial path to CAN through buffer ioport_configure_pin(BUF1_PIN , IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW ); //enables FTDI serial path to CAN through buffer ioport_configure_pin(CHARGEPUMP_0_PIN , IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW ); }
void board_init(void) { #ifdef ZIGBIT_USB ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif #ifdef ZIGBIT_EXT ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED2_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_LEVEL | IOPORT_PULL_UP); #endif #ifdef CONF_BOARD_ENABLE_USARTE0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTD0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_AT86RFX ioport_configure_pin(AT86RFX_SPI_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT86RFX_SPI_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT86RFX_SPI_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(AT86RFX_SPI_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); /* Initialize TRX_RST and SLP_TR as GPIO. */ ioport_configure_pin(AT86RFX_RST_PIN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT86RFX_SLP_PIN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif }
void board_init(void) { ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT|IOPORT_INIT_LOW|IOPORT_INV_ENABLED); ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT|IOPORT_INIT_LOW|IOPORT_INV_ENABLED); ioport_configure_pin(LED2_GPIO, IOPORT_DIR_OUTPUT|IOPORT_INIT_LOW|IOPORT_INV_ENABLED); ioport_configure_pin(LED3_GPIO, IOPORT_DIR_OUTPUT|IOPORT_INIT_LOW|IOPORT_INV_ENABLED); ioport_configure_pin(BACKLIGHT_GPIO, IOPORT_DIR_OUTPUT|IOPORT_INIT_LOW); ioport_configure_pin(LED_POWER, IOPORT_DIR_OUTPUT|IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_2, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_PUSH_BUTTON_3, IOPORT_DIR_INPUT | IOPORT_PULL_UP); #ifdef CONF_BOARD_AT45DBX ioport_configure_pin(AT45DBX_MASTER_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(AT45DBX_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); // Setting PORT_USART0_bm to one will move the pin location // of USARTC0 (in mode SPI) from Px[3:0] to Px[7:4]. PORTC.REMAP |= PORT_USART0_bm; #endif #ifdef CONF_BOARD_LIGHT_SENSOR ioport_configure_pin(LIGHT_SENSOR_SIGNAL_PIN, IOPORT_DIR_INPUT | IOPORT_INPUT_DISABLE); #endif #ifdef CONF_BOARD_TEMPERATURE_SENSOR ioport_configure_pin(TEMPERATURE_SENSOR_SIGNAL_PIN, IOPORT_DIR_INPUT | IOPORT_INPUT_DISABLE); #endif #ifdef CONF_BOARD_POTENTIOMETER_SENSOR ioport_configure_pin(POTENTIOMETER_SIGNAL_PIN, IOPORT_DIR_INPUT | IOPORT_INPUT_DISABLE); #endif #ifdef CONF_BOARD_ENABLE_MXT143E_XPLAINED ioport_configure_pin(MXT143E_XPLAINED_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(MXT143E_XPLAINED_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(MXT143E_XPLAINED_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(MXT143E_XPLAINED_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(MXT143E_XPLAINED_CHG, IOPORT_DIR_INPUT); ioport_configure_pin(MXT143E_XPLAINED_DC, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); #ifndef MXT143E_XPLAINED_BACKLIGHT_DISABLE ioport_configure_pin(MXT143E_XPLAINED_BACKLIGHT, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); #endif ioport_configure_pin(MXT143E_XPLAINED_LCD_RESET, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); // Setting PORT_USART0_bm to one will move the pin location // of USARTC0 (in mode SPI) from Px[3:0] to Px[7:4]. PORTC.REMAP |= PORT_USART0_bm; #endif #ifdef CONF_BOARD_LCD_BACKLIGHT_PWM backlight_start_pwm(); #endif #ifdef CONF_BOARD_ENABLE_USARTC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTE0 /* Note: this will disable touch buttons 2 and 3 as they share the same * physical pins at the USART E module. */ ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 2), IOPORT_DIR_INPUT); #endif #if defined (SENSORS_XPLAINED_BOARD) /* Configure the Xplained Sensor extension board, if any, after * the platform Xplained board has configured basic clock settings, * GPIO pin mapping, interrupt controller options, etc. */ sensor_board_init (); #endif }
void board_init(void) { ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(GPIO_PCB_LINK, IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(GPIO_CUTDOWN, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); ioport_configure_pin(GPIO_NTX2B_EN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH |IOPORT_INV_ENABLED ); #ifdef CONF_BOARD_ENABLE_USARTC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTC1 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 7), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 6), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTD0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTD1 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 7), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 6), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTE0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTE, 2), IOPORT_DIR_INPUT); #endif }
void board_init(void) { ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED2_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED3_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW | IOPORT_INV_ENABLED); ioport_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_LEVEL | IOPORT_PULL_UP); #ifdef CONF_BOARD_C12832A1Z ioport_configure_pin(NHD_C12832A1Z_SPI_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(NHD_C12832A1Z_SPI_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(NHD_C12832A1Z_CSN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(NHD_C12832A1Z_REGISTER_SELECT, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(NHD_C12832A1Z_RESETN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(NHD_C12832A1Z_BACKLIGHT, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); #endif #ifdef CONF_BOARD_AT45DBX ioport_configure_pin(AT45DBX_MASTER_SCK, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MOSI, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(AT45DBX_MASTER_MISO, IOPORT_DIR_INPUT); ioport_configure_pin(AT45DBX_CS, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); #endif #ifdef CONF_BOARD_ENABLE_AC_PINS ioport_configure_pin(IOPORT_CREATE_PIN(PORTA, 0), IOPORT_DIR_INPUT); ioport_configure_pin(IOPORT_CREATE_PIN(PORTA, 2), IOPORT_DIR_INPUT); ioport_configure_pin(IOPORT_CREATE_PIN(PORTB, 1), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTC0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT); #endif #ifdef CONF_BOARD_ENABLE_USARTD0 ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT); #endif }