void uart_task(void) { #if (UART_RST_SVALE_ENABLED == 1) if(usart_rst_slave_flag != 0) { LED_Off(LED_VBUS); irqflags_t flags = cpu_irq_save(); usart_rst_slave_flag = 0; cpu_irq_restore(flags); timeout_start_singleshot(TIMEOUT_RST_SLAVE, UART_RST_SLAVE_TIMEOUT); gpio_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); gpio_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW); } if(timeout_test_and_clear_expired(TIMEOUT_RST_SLAVE)) { gpio_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_INPUT | IOPORT_PULL_UP); delay_ms(10); gpio_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_PULL_UP); LED_On(LED_VBUS); } #endif if(timeout_test_expired(TIMEOUT_RX)) { LED_Off(LED_RX); } if(timeout_test_expired(TIMEOUT_TX)) { LED_Off(LED_TX); } }
void board_init(void) { gpio_configure_pin(LED0_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(LED1_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); #if defined (CONF_BOARD_AT86RFX) // AT86RFX SPI GPIO options. static gpio_map_t AT86RFX_SPI_GPIO_MAP = { {AT86RFX_SPI_SCK_PIN, AT86RFX_SPI_SCK_FUNCTION }, {AT86RFX_SPI_MISO_PIN, AT86RFX_SPI_MISO_FUNCTION}, {AT86RFX_SPI_MOSI_PIN, AT86RFX_SPI_MOSI_FUNCTION}, {AT86RFX_SPI_NPCS_PIN, AT86RFX_SPI_NPCS_FUNCTION} }; // Assign GPIO to SPI. gpio_enable_module(AT86RFX_SPI_GPIO_MAP, sizeof(AT86RFX_SPI_GPIO_MAP) / sizeof(AT86RFX_SPI_GPIO_MAP[0])); gpio_enable_pin_interrupt(AT86RFX_IRQ_PIN, GPIO_RISING_EDGE); gpio_clear_pin_interrupt_flag(AT86RFX_IRQ_PIN); gpio_configure_pin(AT86RFX_RST_PIN, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(AT86RFX_SLP_PIN, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); #endif }
/** * \brief initialize an I2C interface using given config * * \param[in] hal - opaque ptr to HAL data * \param[in] cfg - interface configuration * * \return ATCA_STATUS */ ATCA_STATUS hal_i2c_init(void *hal, ATCAIfaceCfg *cfg) { // set to default i2c bus if (cfg->atcai2c.bus > MAX_I2C_BUSES - 1) cfg->atcai2c.bus = 0; int bus = cfg->atcai2c.bus; // 0-based logical bus number ATCAHAL_t *phal = (ATCAHAL_t*)hal; if (i2c_bus_ref_ct == 0) // power up state, no i2c buses will have been used for (int i = 0; i < MAX_I2C_BUSES; i++) i2c_hal_data[i] = NULL; i2c_bus_ref_ct++; // total across buses if (bus >= 0 && bus < MAX_I2C_BUSES) { // if this is the first time this bus and interface has been created, do the physical work of enabling it if (i2c_hal_data[bus] == NULL) { i2c_hal_data[bus] = malloc(sizeof(ATCAI2CMaster_t)); i2c_hal_data[bus]->ref_ct = 1; // buses are shared, this is the first instance switch (bus) { case 0: i2c_hal_data[bus]->twi_id = ID_TWI0; i2c_hal_data[bus]->twi_master_instance = TWI0; break; case 1: i2c_hal_data[bus]->twi_id = ID_TWI1; i2c_hal_data[bus]->twi_master_instance = TWI1; // configure TWI1 pins gpio_configure_pin(PIO_PB4_IDX, (PIO_PERIPH_A | PIO_PULLUP)); gpio_configure_pin(PIO_PB5_IDX, (PIO_PERIPH_A | PIO_PULLUP)); // disable JTAG MATRIX->CCFG_SYSIO |= (1 << 4) | (1 << 5); break; } pmc_enable_periph_clk(i2c_hal_data[bus]->twi_id); opt_twi_master.master_clk = sysclk_get_cpu_hz(); opt_twi_master.speed = cfg->atcai2c.baud; opt_twi_master.smbus = 0; twi_master_init(i2c_hal_data[bus]->twi_master_instance, &opt_twi_master); // store this for use during the release phase i2c_hal_data[bus]->bus_index = bus; }else { // otherwise, another interface already initialized the bus, so this interface will share it and any different // cfg parameters will be ignored...first one to initialize this sets the configuration i2c_hal_data[bus]->ref_ct++; } phal->hal_data = i2c_hal_data[bus]; return ATCA_SUCCESS; } return ATCA_COMM_FAIL; }
/** Enables the target's PDI interface, holding the target in reset until PDI mode is exited. */ void XPROGTarget_EnableTargetPDI(void) { IsSending = false; /* Turn on clock */ sysclk_enable_peripheral_clock(USART_PDI_ID); /* Set Tx and XCK as outputs, Rx as input */ gpio_configure_pin(PIN_PDIDTX_GPIO, PIN_PDIDTX_OUT_FLAGS); gpio_configure_pin(PIN_PDIDRX_GPIO, PIN_PDIDRX_FLAGS); gpio_configure_pin(PIN_PDIC_GPIO, PIN_PDIC_OUT_FLAGS); delay_us(50); /* Set DATA line high for at least 90ns to disable /RESET functionality */ gpio_set_pin_high(PIN_PDIDTX_GPIO); delay_us(10); /* Set up the synchronous USART for XMEGA communications - 8 data bits, even parity, 2 stop bits */ const sam_usart_opt_t usart_pdid_settings = { PDI_BAUD_RATE, US_MR_CHRL_8_BIT, US_MR_PAR_EVEN, US_MR_NBSTOP_2_BIT, US_MR_CHMODE_NORMAL }; usart_init_sync_master(USART_PDI, &usart_pdid_settings, sysclk_get_main_hz()); /* Turn on clock */ gpio_configure_pin(PIN_PDIC_GPIO, PIN_PDIC_USART_FLAGS); /* Send two IDLEs of 12 bits each to enable PDI interface (need at least 16 idle bits) */ XPROGTarget_SendIdle(); XPROGTarget_SendIdle(); }
void can_bus_init(int channel, can_stream_config_t config) { // Setup the generic clock for CAN scif_gc_setup(AVR32_SCIF_GCLK_CANIF, CAN_GCLK_SOURCE, CAN_GCLK_DIV_MODE, CAN_GCLK_DIV); // Now enable the generic clock scif_gc_enable(AVR32_SCIF_GCLK_CANIF); // Assign GPIO to CAN. gpio_enable_module_pin(config.can_rx_map.pin, config.can_rx_map.function); gpio_enable_module_pin(config.can_tx_map.pin, config.can_tx_map.function); // activate control pins for CAN transceiver gpio_configure_pin(config.can_shutdown_pin, GPIO_DIR_OUTPUT | GPIO_INIT_LOW); // CAN0 shutdown line gpio_configure_pin(config.can_standby_pin, GPIO_DIR_OUTPUT | GPIO_INIT_LOW); // CAN0 standby line // Initialize channel 0 can_bus_init_hardware(channel, ((uint32_t)&mob_ram_ch[channel][0]), CANIF_CHANNEL_MODE_NORMAL, NULL); CAN_stream_rx[channel]=NULL; CAN_stream_tx[channel]=NULL; }
extern void init_gpio(void) { gpio_enable_gpio_pin(A00); gpio_enable_gpio_pin(A01); gpio_enable_gpio_pin(A02); gpio_enable_gpio_pin(A03); gpio_enable_gpio_pin(A04); gpio_enable_gpio_pin(A05); gpio_enable_gpio_pin(A06); gpio_enable_gpio_pin(A07); gpio_enable_gpio_pin(B08); gpio_enable_gpio_pin(B09); gpio_enable_gpio_pin(B10); gpio_enable_gpio_pin(B11); // loopback for version detection (on new version B00 and B01 are bridged) gpio_enable_gpio_pin(B00); gpio_enable_gpio_pin(B01); gpio_enable_pin_pull_up(B01); gpio_configure_pin(B00, GPIO_DIR_OUTPUT); gpio_set_pin_low(B00); // turn on pull-ups for SDA/SCL // gpio_enable_pin_pull_up(A09); // gpio_enable_pin_pull_up(A10); gpio_enable_gpio_pin(NMI); gpio_configure_pin(B08, GPIO_DIR_OUTPUT); gpio_configure_pin(B09, GPIO_DIR_OUTPUT); gpio_configure_pin(B10, GPIO_DIR_OUTPUT); gpio_configure_pin(B11, GPIO_DIR_OUTPUT); }
/*! \brief Initialize the SPI in slave mode and enable the spi interrupt. */ static void spi_slave_init(volatile void *spi, uint8_t mode) { /* Enable Clock for SPI module */ sysclk_enable_module(POWER_RED_REG0, PRSPI_bm); /* Configure SPI pins for slave */ /* Set MISO as output high, and set MOSI, SS , SCK as input */ gpio_configure_pin(SPI_SCK, IOPORT_DIR_INPUT); gpio_configure_pin(SPI_MOSI, IOPORT_DIR_INPUT); gpio_configure_pin(SPI_SS, IOPORT_DIR_INPUT); gpio_configure_pin(SPI_MISO, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT); /* Set the clock mode */ spi_set_clock_mode(spi, mode); /* Enable SPI as slave */ spi_enable_slave_mode(spi); /* Set the interrupt call back */ spi_set_interrupt_callback(spi_interrupt_callback); /* Enable SPI interrupt */ spi_enable_interrupt(spi); }
void fenix_slave(){ delay_ms(300); gpio_configure_pin(CAN0_TX_PIN, GPIO_DIR_OUTPUT|GPIO_INIT_HIGH); gpio_configure_pin(CAN0_RX_PIN, GPIO_DIR_INPUT|GPIO_INIT_LOW); gpio_configure_pin(CAN1_TX_PIN, GPIO_DIR_OUTPUT|GPIO_INIT_HIGH); gpio_configure_pin(CAN1_RX_PIN, GPIO_DIR_INPUT|GPIO_INIT_LOW); while(gpio_pin_is_low(CAN0_RX_PIN) && gpio_pin_is_low(CAN1_RX_PIN)); while(gpio_pin_is_high(CAN0_RX_PIN) && gpio_pin_is_high(CAN1_RX_PIN)); }
/** * \brief Configure SPI */ void epd_spi_init(void) { sysclk_enable_peripheral_clock(EPD_SPI_ID); gpio_configure_pin(EPD_SPI_MISO_PIN, EPD_SPI_MISO_MUX); ioport_disable_pin(EPD_SPI_MISO_PIN); // Disable IO (but enable peripheral mode) gpio_configure_pin(EPD_SPI_MOSI_PIN, EPD_SPI_MOSI_MUX); ioport_disable_pin(EPD_SPI_MOSI_PIN); // Disable IO (but enable peripheral mode) gpio_configure_pin(EPD_SPI_CLK_PIN, EPD_SPI_CLK_MUX); ioport_disable_pin(EPD_SPI_CLK_PIN); // Disable IO (but enable peripheral mode) gpio_configure_pin(EPD_SPI_SS_PIN, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT); spi_master_init(EPD_SPI_ID); spi_master_setup_device(EPD_SPI_ID, &epd_device_conf, SPI_MODE_0, EPD_SPI_baudrate, 0); spi_enable(EPD_SPI_ID); delay_ms(5); }
static void testerA(void *pvParameters){ const portTickType xDelay = 10 / portTICK_RATE_MS; gpio_configure_pin(RESPONSE_A, GPIO_DIR_OUTPUT | GPIO_INIT_LOW); gpio_configure_pin(TEST_A, GPIO_DIR_INPUT | GPIO_INIT_LOW); gpio_set_pin_high(RESPONSE_A); while (1){ if(!gpio_get_pin_value(TEST_A)){ gpio_set_pin_low(RESPONSE_A); vTaskDelay(xDelay); gpio_set_pin_high(RESPONSE_A); } } }
void vParTestInitialise(void) { #if defined(LED_0_NAME) || defined(LED_1_NAME) || defined(LED_2_NAME) || defined(LED_3_NAME) unsigned long ul; for (ul = 0; ul < partestNUM_LEDS; ul++) { /* Configure the LED, before ensuring it starts in the off state. */ gpio_configure_pin(ulLED[ ul ], (PIO_OUTPUT_1 | PIO_DEFAULT)); vParTestSetLED(ul, xActiveStates[ ul ]); } #endif #ifdef CONF_BOARD_SIM_PWR taskENTER_CRITICAL(); #if (SIM_PWR_IDLE_LEVEL == 0) gpio_set_pin_low(SIM_PWR_GPIO); #else gpio_set_pin_high(SIM_PWR_GPIO); #endif taskEXIT_CRITICAL(); #endif #ifdef CONF_BOARD_SIM_NRESET taskENTER_CRITICAL(); #if (SIM_NRST_IDLE_LEVEL == 0) gpio_set_pin_low(SIM_NRST_GPIO); #else gpio_set_pin_high(SIM_NRST_GPIO); #endif taskEXIT_CRITICAL(); #endif }
/** * \brief The PWM signal starts toggling */ void PWM_start_toggle(void) { uint16_t ra, rc; /** Configure the PMC to enable the Timer/Counter (TC) module. */ sysclk_enable_peripheral_clock(EPD_TC_WAVEFORM_ID); gpio_configure_pin(EPD_TC_WAVEFORM_PIN, EPD_TC_WAVEFORM_PIN_FLAGS); /** TC Configuration structure. */ struct tc_control_reg tc_control_par = { /** TC Compare Output Mode */ .co_mode = CO_SET, /** TC Waveform Generation Mode */ .wg_mode = PWM_Mode11, /** TC Clock Selection, Prescalar select */ .cs_select = EPD_TC_ClockSignalSel }; /** Init TC to waveform mode. */ tc_initc(EPD_TC_WAVEFORM_ID, EPD_TC_WAVEFORM_CHANNEL, &tc_control_par); /** Configure waveform frequency and duty cycle. */ rc = (sysclk_get_peripheral_bus_hz(EPD_TC_TIMER_ID) / EPD_TC_ClockSignalSel) / EPD_TC_WAVEFORM_PWM_FREQUENCY; tc_clear_ic(EPD_TC_WAVEFORM_ID, EPD_TC_WAVEFORM_CHANNEL, 0); tc_write_ic(EPD_TC_WAVEFORM_ID, EPD_TC_WAVEFORM_CHANNEL, rc); ra = (100 - EPD_TC_WAVEFORM_PWM_DUTY_CYCLE) * rc / 100; tc_clear_cc(EPD_TC_WAVEFORM_ID, EPD_TC_WAVEFORM_CHANNEL, 0); tc_write_cc(EPD_TC_WAVEFORM_ID, EPD_TC_WAVEFORM_CHANNEL, ra); /** Enable TC EPD_TC_WAVEFORM_CHANNEL. */ tc_start(EPD_TC_WAVEFORM_ID, &tc_control_par); }
/** * \brief Configure to trigger ADC by TIOA output of timer. */ static void configure_time_trigger(void) { uint32_t ul_div = 0; uint32_t ul_tc_clks = 0; uint32_t ul_sysclk = sysclk_get_cpu_hz(); /* Enable peripheral clock. */ pmc_enable_periph_clk(ID_TC0); /* TIOA configuration */ gpio_configure_pin(PIN_TC0_TIOA0, PIN_TC0_TIOA0_FLAGS); /* Configure TC for a 1Hz frequency and trigger on RC compare. */ tc_find_mck_divisor(1, ul_sysclk, &ul_div, &ul_tc_clks, ul_sysclk); tc_init(TC0, 0, ul_tc_clks | TC_CMR_CPCTRG | TC_CMR_WAVE | TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_SET); TC0->TC_CHANNEL[0].TC_RA = (ul_sysclk / ul_div) / 2; TC0->TC_CHANNEL[0].TC_RC = (ul_sysclk / ul_div) / 1; /* Start the Timer. */ tc_start(TC0, 0); /* Set TIOA0 trigger. */ #if SAM3S || SAM3N || SAM3XA || SAM4S || SAM4C adc_configure_trigger(ADC, ADC_TRIG_TIO_CH_0, 0); #elif SAM3U #ifdef ADC_12B adc12b_configure_trigger(ADC12B, ADC12B_TRIG_TIO_CH_0); #else adc_configure_trigger(ADC, ADC_TRIG_TIO_CH_0); #endif #endif }
void board_init(void) { gpio_configure_pin(LED0_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(LED1_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); #if defined (CONF_BOARD_COM_PORT) // USART GPIO pin configuration. static const gpio_map_t COMPORT_GPIO_MAP = { {USART_RXD_PIN, USART_RXD_FUNCTION }, {USART_TXD_PIN, USART_TXD_FUNCTION } }; gpio_enable_module(COMPORT_GPIO_MAP, sizeof(COMPORT_GPIO_MAP) / sizeof(COMPORT_GPIO_MAP[0])); #endif }
void fenix_master(){ gpio_configure_pin(CAN0_TX_PIN, GPIO_DIR_OUTPUT|GPIO_INIT_LOW); gpio_configure_pin(CAN0_RX_PIN, GPIO_DIR_INPUT|GPIO_INIT_HIGH); gpio_configure_pin(CAN1_TX_PIN, GPIO_DIR_OUTPUT|GPIO_INIT_LOW); gpio_configure_pin(CAN1_RX_PIN, GPIO_DIR_INPUT|GPIO_INIT_HIGH); delay_ms(1000); gpio_set_pin_high(CAN0_TX_PIN); gpio_set_pin_high(CAN1_TX_PIN); /*delay_ms(10); gpio_set_pin_high(CAN0_TX_PIN); gpio_set_pin_high(CAN1_TX_PIN);*/ }
/** Disables the target's PDI interface, exits programming mode and starts the target's application. */ void XPROGTarget_DisableTargetPDI(void) { /* Switch to Rx mode to ensure that all pending transmissions are complete */ if (IsSending) XPROGTarget_SetRxMode(); /* Turn off receiver and transmitter of the USART, clear settings */ usart_disable_rx(USART_PDI); usart_disable_tx(USART_PDI); /* Tristate all pins */ gpio_configure_pin(PIN_PDIC_GPIO, PIN_PDIC_IN_FLAGS); gpio_configure_pin(PIN_PDIDRX_GPIO, PIN_PDIDRX_FLAGS); gpio_configure_pin(PIN_PDIDTX_GPIO, PIN_PDIDTX_IN_FLAGS); /* Turn off USART */ sysclk_disable_peripheral_clock(USART_PDI_ID); }
void board_init(void) { /* This function is meant to contain board-specific initialization code * for, e.g., the I/O pins. The initialization can rely on application- * specific board configuration, found in conf_board.h. */ gpio_enable_gpio_pin(LOCK_LED); gpio_configure_pin(LOCK_LED, GPIO_DIR_OUTPUT); }
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); gpio_configure_pin(GPIO_PUSH_BUTTON_0,IOPORT_DIR_INPUT | IOPORT_PULL_UP); }
void vParTestInitialise( void ) { unsigned long ul; for( ul = 0; ul < partestNUM_LEDS; ul++ ) { /* Configure the LED, before ensuring it starts in the off state. */ gpio_configure_pin( ulLED[ ul ], ( PIO_OUTPUT_1 | PIO_DEFAULT ) ); vParTestSetLED( ul, pdFALSE ); } }
/* Init the CDCE906 chip, set offline */ bool cdce906_init(void) { gpio_configure_pin(PIN_CDCE_SDA, PIN_CDCE_SDA_FLAGS); gpio_configure_pin(PIN_CDCE_SCL, PIN_CDCE_SCL_FLAGS); twi_master_options_t opt = { .speed = 50000, .chip = CDCE906_ADDR }; twi_master_setup(TWI1, &opt); uint8_t data = 0; /* Read addr 0 */ if (cdce906_read(0, &data) == false){ return false; } /* Check vendor ID matches expected */ if ((data & 0x0F) == 0x01){ return true; } return false; } bool cdce906_write(uint8_t addr, uint8_t data) { twi_package_t packet_write = { .addr = {0x80 | addr}, // TWI slave memory address data .addr_length = 1, // TWI slave memory address data size .chip = CDCE906_ADDR, // TWI slave bus address .buffer = &data, // transfer data source buffer .length = 1 // transfer data size (bytes) }; if (twi_master_write(TWI1, &packet_write) == TWI_SUCCESS){ return true; } else { return false; } }
void board_init(void) { gpio_configure_pin(LED0_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(LED1_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(LED2_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(LED3_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(QT1081_TOUCH_SENSOR_ENTER,GPIO_DIR_INPUT); #if defined (CONF_BOARD_AT45DBX) static const gpio_map_t AT45DBX_SPI_GPIO_MAP = { {AT45DBX_SPI_SCK_PIN, AT45DBX_SPI_SCK_FUNCTION}, {AT45DBX_SPI_MISO_PIN, AT45DBX_SPI_MISO_FUNCTION}, {AT45DBX_SPI_MOSI_PIN, AT45DBX_SPI_MOSI_FUNCTION}, # define AT45DBX_ENABLE_NPCS_PIN(npcs, unused) \ {AT45DBX_SPI_NPCS##npcs##_PIN, AT45DBX_SPI_NPCS##npcs##_FUNCTION}, MREPEAT(AT45DBX_MEM_CNT, AT45DBX_ENABLE_NPCS_PIN, ~) # undef AT45DBX_ENABLE_NPCS_PIN };
static void XPROGTarget_SetRxMode(void) { while(usart_is_tx_empty(USART_PDI) == 0); usart_disable_tx(USART_PDI); usart_enable_rx(USART_PDI); gpio_configure_pin(PIN_PDIDTX_GPIO, PIN_PDIDTX_IN_FLAGS); IsSending = false; }
uint8_t twi_init(void){ /*TWI0: - Clock: PA4 (Laranja) - Data: PA3 (Cinza) - Terra: GND (Preta) - VCC: 3V3 (Branco)*/ gpio_configure_pin(TWI0_DATA_GPIO, TWI0_DATA_FLAGS); gpio_configure_pin(TWI0_CLK_GPIO, TWI0_CLK_FLAGS); twi_options_t opt_twi; pmc_enable_periph_clk(ID_TWI0); opt_twi.master_clk = sysclk_get_cpu_hz(); opt_twi.speed = TWI_SPEED; opt_twi.smbus = 0; uint8_t twi_status = twi_master_init(TWI0, &opt_twi); return twi_status; }
int main() { gpio_configure_pin(PIO_P$$com.sysprogs.examples.ledblink.LEDPORT$$$$com.sysprogs.examples.ledblink.LEDBIT$$, PIO_TYPE_PIO_OUTPUT_1 | PIO_DEFAULT); for (;;) { gpio_set_pin_low(PIO_P$$com.sysprogs.examples.ledblink.LEDPORT$$$$com.sysprogs.examples.ledblink.LEDBIT$$); Delay(); gpio_set_pin_high(PIO_P$$com.sysprogs.examples.ledblink.LEDPORT$$$$com.sysprogs.examples.ledblink.LEDBIT$$); Delay(); } }
//initialize the i2c bus int i2c_rtc_init(void){ twi_options_t opt; uint32_t r; //enable peripherial mode on TWI lines gpio_configure_pin(PIO_PA3_IDX,(PIO_PERIPH_A | PIO_DEFAULT)); gpio_configure_pin(PIO_PA4_IDX,(PIO_PERIPH_A | PIO_DEFAULT)); //enable TWI clock pmc_enable_periph_clk(RTC_ID_TWI); //setup up TWI options opt.master_clk = sysclk_get_cpu_hz(); opt.speed = 400000; //400kHz opt.smbus = 0x0; opt.chip = 0x0; if((r=twi_master_init(RTC_BASE_TWI, &opt)) != TWI_SUCCESS){ printf("error setting up I2C for RTC: %d\n",(int)r); return -1; } return 0; }
/** * \brief Configure the ADC for the light sensor. */ static void configure_adc(void) { /* Configure ADC pin for light sensor. */ gpio_configure_pin(LIGHT_SENSOR_GPIO, LIGHT_SENSOR_FLAGS); /* Enable ADC clock. */ pmc_enable_periph_clk(ID_ADC); /* Configure ADC. */ adc_init(ADC, sysclk_get_cpu_hz(), 1000000, ADC_MR_STARTUP_SUT0); adc_enable_channel(ADC, ADC_CHANNEL_4); adc_configure_trigger(ADC, ADC_TRIG_SW, 1); }
/** * \brief initialize pins, watchdog, etc. */ static void init_system(void) { /* Disable the watchdog */ wdt_disable(WDT); /* Initialize the system clock */ sysclk_init(); /* Configure LED pins */ gpio_configure_pin(LED0_GPIO, LED0_FLAGS); gpio_configure_pin(LED1_GPIO, LED1_FLAGS); /* Enable PMC clock for key/slider PIOs */ pmc_enable_periph_clk(ID_PIOA); pmc_enable_periph_clk(ID_PIOC); /* Configure PMC */ pmc_enable_periph_clk(ID_TC0); /* Configure the default TC frequency */ configure_tc(DEFAULT_LED_FREQ); }
static void testerC(void *pvParameters){ const portTickType xDelay = 5 / portTICK_RATE_MS; portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); gpio_configure_pin(RESPONSE_C, GPIO_DIR_OUTPUT | GPIO_INIT_LOW); gpio_configure_pin(TEST_C, GPIO_DIR_INPUT | GPIO_INIT_LOW); gpio_set_pin_high(RESPONSE_C); while (1){ vTaskDelayUntil(&xLastWakeTime, xDelay); if(!gpio_get_pin_value(TEST_C)){ gpio_set_pin_low(RESPONSE_C); vTaskDelay(xDelay); gpio_set_pin_high(RESPONSE_C); } } }
extern void init_gpio(void) { gpio_enable_gpio_pin(A00); gpio_enable_gpio_pin(A01); gpio_enable_gpio_pin(A02); gpio_enable_gpio_pin(A03); gpio_enable_gpio_pin(A04); gpio_enable_gpio_pin(A05); gpio_enable_gpio_pin(A06); gpio_enable_gpio_pin(A07); gpio_enable_gpio_pin(B08); gpio_enable_gpio_pin(B09); gpio_enable_gpio_pin(B10); gpio_enable_gpio_pin(B11); gpio_enable_gpio_pin(NMI); gpio_configure_pin(B08, GPIO_DIR_OUTPUT); gpio_configure_pin(B09, GPIO_DIR_OUTPUT); gpio_configure_pin(B10, GPIO_DIR_OUTPUT); gpio_configure_pin(B11, GPIO_DIR_OUTPUT); }
static void XPROGTarget_SetTxMode(void) { /* Wait for a full cycle of the clock */ while(gpio_pin_is_high(PIN_PDIC_GPIO) && TimeoutTicksRemaining); while(gpio_pin_is_low(PIN_PDIC_GPIO) && TimeoutTicksRemaining); while(gpio_pin_is_high(PIN_PDIC_GPIO) && TimeoutTicksRemaining); usart_disable_rx(USART_PDI); usart_enable_tx(USART_PDI); gpio_configure_pin(PIN_PDIDTX_GPIO, PIN_PDIDTX_USART_FLAGS); IsSending = true; }