void vParTestSetLED(unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue) { #if defined(LED_0_NAME) || defined(LED_1_NAME) || defined(LED_2_NAME) || defined(LED_3_NAME) if (uxLED < partestNUM_LEDS) { if (xValue != pdFALSE) { /* Turn the LED on. */ taskENTER_CRITICAL(); { if (xActiveStates[ uxLED ] == 0) { gpio_set_pin_low(ulLED[ uxLED ]); } else { gpio_set_pin_high(ulLED[ uxLED ]); } } taskEXIT_CRITICAL(); } else { /* Turn the LED off. */ taskENTER_CRITICAL(); { if (xActiveStates[ uxLED ] == 0) { gpio_set_pin_high(ulLED[ uxLED ]); } else { gpio_set_pin_low(ulLED[ uxLED ]); } } taskEXIT_CRITICAL(); } } #endif }
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 Main function. */ int main(void) { sysclk_init(); /* Initialize the board. * The board-specific conf_board.h file contains the configuration of * the board initialization. */ board_init(); spi_master_init(SPI_EXAMPLE); spi_master_setup_device(SPI_EXAMPLE, &SPI_DEVICE_EXAMPLE, SPI_MODE_0, SPI_EXAMPLE_BAUDRATE, 0); spi_enable(SPI_EXAMPLE); status = spi_at45dbx_mem_check(); while (true) { if (status==false) { gpio_set_pin_low(SPI_EXAMPLE_LED_PIN_EXAMPLE_1); gpio_set_pin_high(SPI_EXAMPLE_LED_PIN_EXAMPLE_2); } else { gpio_set_pin_low(SPI_EXAMPLE_LED_PIN_EXAMPLE_1); gpio_set_pin_low(SPI_EXAMPLE_LED_PIN_EXAMPLE_2); } } }
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue ) { if( uxLED < partestNUM_LEDS ) { if( uxLED == partstsINVERTED_LED ) { xValue = !xValue; } if( xValue != pdFALSE ) { /* Turn the LED on. */ taskENTER_CRITICAL(); { gpio_set_pin_low( ulLED[ uxLED ]); } taskEXIT_CRITICAL(); } else { /* Turn the LED off. */ taskENTER_CRITICAL(); { gpio_set_pin_high( ulLED[ uxLED ]); } taskEXIT_CRITICAL(); } } }
uint32_t ksz8851snl_reinit(void) { uint32_t count = 10; uint16_t dev_id = 0; uint8_t id_ok = 0; /* Reset the Micrel in a proper state. */ while( count-- ) { /* Perform hardware reset with respect to the reset timing from the datasheet. */ gpio_set_pin_low(KSZ8851SNL_RSTN_GPIO); vTaskDelay(2); gpio_set_pin_high(KSZ8851SNL_RSTN_GPIO); vTaskDelay(2); /* Init step1: read chip ID. */ dev_id = ksz8851_reg_read(REG_CHIP_ID); if( ( dev_id & 0xFFF0 ) == CHIP_ID_8851_16 ) { id_ok = 1; break; } } if( id_ok != 0 ) { ksz8851snl_set_registers(); } return id_ok ? 1 : -1; }
/** * \brief Initializes a ISO7816 interface device. * * \param p_usart_opt Pointer to an ISO7816 instance. * \param ul_mck USART module input clock frequency. * \param ul_rst_pin_idx Control smart card RST pin index. */ unsigned int iso7816_init(const usart_iso7816_opt_t *p_usart_opt, uint32_t ul_mck, uint32_t ul_rst_pin_idx) { /* Pin RST of ISO7816 initialize. */ gs_ul_rst_pin_idx = ul_rst_pin_idx; #if defined(SMART_CARD_USING_GPIO) gpio_set_pin_low(gs_ul_rst_pin_idx); #elif defined(SMART_CARD_USING_IOPORT) ioport_set_pin_level(gs_ul_rst_pin_idx, IOPORT_PIN_LEVEL_LOW); #endif /* Init the global variable for ISO7816. */ g_ul_clk = ul_mck; if(usart_init_iso7816(ISO7816_USART, p_usart_opt, g_ul_clk)){ return 1; } /* Disable interrupts. */ usart_disable_interrupt(ISO7816_USART, 0xffffffff); /* Write the Timeguard Register. */ usart_set_tx_timeguard(ISO7816_USART, 5); /* Enable TX and RX. */ usart_enable_rx(ISO7816_USART); //usart_enable_tx(ISO7816_USART); return 0; }
static void enable_output(const channel_def_t* channel, int freq) { if (channel->externally_driven) { uint32_t clock = sysclk_get_peripheral_bus_hz(channel->ex.timer) / 32; // clock source is PB / 32 uint32_t rc = clock / freq; // check for over/underflow if (rc > 0xffff) rc = 0xffff; else if (rc < 8) rc = 8; // set up RA, RB, and RC. always use 50% duty cycle (RA = RB = RC/2) tc_write_ra(channel->ex.timer, channel->ex.channel, (uint16_t)rc / 2); tc_write_rb(channel->ex.timer, channel->ex.channel, (uint16_t)rc / 2); tc_write_rc(channel->ex.timer, channel->ex.channel, (uint16_t)rc); tc_start(channel->ex.timer, channel->ex.channel); } else if (channel->in.active_level) { gpio_set_pin_high(channel->in.pin1); } else { gpio_set_pin_low(channel->in.pin1); } }
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 Set the LCD backlight level. * * \param ul_level backlight level. * * \note pin BOARD_AAT31XX_SET_GPIO must be configured before calling aat31xx_set_backlight. */ void aat31xx_set_backlight(uint32_t ul_level) { volatile uint32_t ul_delay; uint32_t i; #ifdef CONF_BOARD_AAT3155 ul_level = AAT31XX_MAX_BACKLIGHT_LEVEL - ul_level + 1; #endif #ifdef CONF_BOARD_AAT3193 ul_level = AAT31XX_MAX_BACKLIGHT_LEVEL - ul_level + 1; #endif /* Ensure valid level */ ul_level = (ul_level > AAT31XX_MAX_BACKLIGHT_LEVEL) ? AAT31XX_MAX_BACKLIGHT_LEVEL : ul_level; ul_level = (ul_level < AAT31XX_MIN_BACKLIGHT_LEVEL) ? AAT31XX_MIN_BACKLIGHT_LEVEL : ul_level; /* Set new backlight level */ for (i = 0; i < ul_level; i++) { gpio_set_pin_low(BOARD_AAT31XX_SET_GPIO); ul_delay = DELAY_PULSE; while (ul_delay--) { } gpio_set_pin_high(BOARD_AAT31XX_SET_GPIO); ul_delay = DELAY_PULSE; while (ul_delay--) { } } ul_delay = DELAY_ENABLE; while (ul_delay--) { } }
void lightshow(void){ for(int i = 0; i < 10; i++){ gpio_set_pin_high(LED_GREEN); _delay_ms(100); gpio_set_pin_low(LED_GREEN); _delay_ms(100); //gpio_set_pin_high(LED_AMBER); _delay_ms(100); //gpio_set_pin_low(LED_AMBER); _delay_ms(100); gpio_set_pin_high(LED_RED); _delay_ms(100); gpio_set_pin_low(LED_RED); _delay_ms(100); } }
static void sim900_power_toggle(void) { gpio_set_pin_high(GPRS_SWITCH); delay_ms(1200); gpio_set_pin_low(GPRS_SWITCH); delay_ms(2500); }
int main (void) { // Insert system clock initialization code here (sysclk_init()). sysclk_init(); board_init(); // Insert application code here, after the board has been initialized. pmc_enable_periph_clk(ID_PIOA); pio_set_input(PIOA, PIO_PA16, PIO_DEFAULT); pio_pull_down(PIOA, (PIO_PA16), ENABLE); pio_handler_set(PIOA, ID_PIOA, PIO_PA16, PIO_IT_RISE_EDGE, pin_riseedge_handler); pio_enable_interrupt(PIOA,PIO_PA16); pio_set_input(PIOA, PIO_PA17, PIO_DEFAULT); pio_pull_down(PIOA, (PIO_PA17), ENABLE); pio_handler_set(PIOA, ID_PIOA, PIO_PA17, PIO_IT_RISE_EDGE, pin_riseedge_handler); pio_enable_interrupt(PIOA,PIO_PA17); NVIC_EnableIRQ(PIOA_IRQn); gpio_set_pin_low(LED0_GPIO); gpio_set_pin_high(LED1_GPIO); while(1){ } }
/********************************************************************* Functions *********************************************************************/ int main (void) { int i; // initialize init(); gpio_configure_pin(RESPONSE_A, GPIO_DIR_OUTPUT | GPIO_INIT_LOW); gpio_configure_pin(TEST_A, GPIO_DIR_INPUT | GPIO_INIT_LOW); gpio_configure_pin(RESPONSE_B, GPIO_DIR_OUTPUT | GPIO_INIT_LOW); gpio_configure_pin(TEST_B, GPIO_DIR_INPUT | GPIO_INIT_LOW); gpio_configure_pin(RESPONSE_C, GPIO_DIR_OUTPUT | GPIO_INIT_LOW); gpio_configure_pin(TEST_C, GPIO_DIR_INPUT | GPIO_INIT_LOW); // start code from here gpio_set_pin_high(RESPONSE_A); gpio_set_pin_high(RESPONSE_B); gpio_set_pin_high(RESPONSE_C); while(1) { if(!gpio_get_pin_value(TEST_A)){ gpio_set_pin_low(RESPONSE_A); busy_delay_us(5); gpio_set_pin_high(RESPONSE_A); } if(!gpio_get_pin_value(TEST_B)){ gpio_set_pin_low(RESPONSE_B); busy_delay_us(5); gpio_set_pin_high(RESPONSE_B); } if(!gpio_get_pin_value(TEST_C)){ gpio_set_pin_low(RESPONSE_C); busy_delay_us(5); gpio_set_pin_high(RESPONSE_C); } //printf("tick\n"); //gpio_toggle_pin(LED0_GPIO); //busy_delay_ms(500); } }
void ioapi_output_low_body( uint8_t pin_number ) { gpio_set_pin_low(pin_number); /* Check that driver is set correctly. */ ERRORH_ASSERT( (ioapi_get_pin_info(pin_number) & IOAPI_GPIO_USED) != 0 ); ERRORH_ASSERT(ioapi_get_pin_info(pin_number) & IOAPI_OUTPUT); }
/** * \brief Update LEDs used for feedback from analog comparator in window mode * * This function will set the LEDs appropriately \a status of the window. See * the \ref example_description section for additional details. * * \param status Analog comparator window status given by a \ref ac_status_t * value */ static void example_ac_update_window_leds(enum ac_status_t status) { gpio_set_pin_high(LED0_GPIO); gpio_set_pin_high(LED1_GPIO); gpio_set_pin_high(LED2_GPIO); gpio_set_pin_high(LED3_GPIO); if (status == AC_STATUS_ABOVE) { gpio_set_pin_low(LED0_GPIO); } else if (status == AC_STATUS_INSIDE) { gpio_set_pin_low(LED1_GPIO); gpio_set_pin_low(LED2_GPIO); } else { gpio_set_pin_low(LED3_GPIO); } }
/** * \brief ISO7816 ICC power off. */ void iso7816_icc_power_off(void) { /* Clear RESET Master Card. */ #if defined(SMART_CARD_USING_GPIO) gpio_set_pin_low(gs_ul_rst_pin_idx); #elif defined(SMART_CARD_USING_IOPORT) ioport_set_pin_level(gs_ul_rst_pin_idx, IOPORT_PIN_LEVEL_LOW); #endif }
void config_timer(void){ //CONFIGURADO PARA 0,1 ms (sysclk_get_cpu_hz() / 10000) if (SysTick_Config(sysclk_get_cpu_hz() / TIMER_CONSTANT)) { puts("-E- Systick configuration error\r"); while (1) { /* Capture error */ gpio_set_pin_low(LED2_GPIO); } } }
/** * \brief Switch off backlight. */ void aat31xx_disable_backlight(void) { volatile uint32_t ul_delay; gpio_set_pin_low(BOARD_AAT31XX_SET_GPIO); ul_delay = DELAY_DISABLE; while (ul_delay--) { } }
void radar_driver_switch_power(int32_t supply1, int32_t supply2) { if (supply1 == 0) { gpio_set_pin_low(RADAR_POWER1_PIN); } else { gpio_set_pin_high(RADAR_POWER1_PIN); } if (supply2 == 0) { gpio_set_pin_low(RADAR_POWER2_PIN); } else { gpio_set_pin_high(RADAR_POWER2_PIN); } }
void debug_green_led(uint8_t state) { if (state) { gpio_set_pin_low(LED0_GPIO); } else { gpio_set_pin_high(LED0_GPIO); } }
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(); } }
/** * \brief Update LEDs used for feedback from analog comparator channel in * single trigger level mode * * This function will set the LEDs appropriately for the \a channel that caused * the interrupt. See the \ref example_description section for additional * details. * * \param channel The analog comparator channel to update status for * \param status Analog comparator channel status given by a \ref ac_status_t * value */ static void example_ac_update_single_leds(uint8_t channel, enum ac_status_t status) { if (channel == 0) { if (status == AC_STATUS_ABOVE) { gpio_set_pin_low(LED0_GPIO); gpio_set_pin_high(LED1_GPIO); } else { gpio_set_pin_high(LED0_GPIO); gpio_set_pin_low(LED1_GPIO); } } else { if (status == AC_STATUS_ABOVE) { gpio_set_pin_low(LED2_GPIO); gpio_set_pin_high(LED3_GPIO); } else { gpio_set_pin_high(LED2_GPIO); gpio_set_pin_low(LED3_GPIO); } } }
void board_start(void){ #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 Turns on the specified LEDs. * * \param led_gpio LED to turn on (LEDx_GPIO). * * \note The pins of the specified LEDs are set to GPIO output mode. */ void LED_On(uint32_t led_gpio) { uint32_t i; for (i = 0; i < BOARD_NUM_OF_LED; i++) { if (led_gpio == LED_DESCRIPTOR[i].ul_port_id) { if (LED_DESCRIPTOR[i].ul_active_level == ACTIVE_LEVEL_IS_HIGH) { gpio_set_pin_high(led_gpio); } else { gpio_set_pin_low(led_gpio); } } } }
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); } } }
int main(){ init(); gpio_configure_pin(TEST_A, GPIO_DIR_INPUT); gpio_configure_pin(RESPONSE_A, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(TEST_B, GPIO_DIR_INPUT); gpio_configure_pin(RESPONSE_B, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(TEST_C, GPIO_DIR_INPUT); gpio_configure_pin(RESPONSE_C, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_enable_pin_interrupt(TEST_A, GPIO_FALLING_EDGE ); gpio_enable_pin_interrupt(TEST_B, GPIO_FALLING_EDGE ); gpio_enable_pin_interrupt(TEST_C, GPIO_FALLING_EDGE ); while(1){ if (A){ A = false; gpio_set_pin_low(RESPONSE_A); busy_delay_us(5); gpio_set_pin_high(RESPONSE_A); } if (B){ B = false; gpio_set_pin_low(RESPONSE_B); busy_delay_us(5); gpio_set_pin_high(RESPONSE_B); } if (C){ C = false; gpio_set_pin_low(RESPONSE_C); busy_delay_us(5); gpio_set_pin_high(RESPONSE_C); } } }
void _e_routine_with_delay () { /* Get enable pin high */ gpio_set_pin_high(LCD_E_PIN); /* Wait for while */ vTaskDelay(1/portTICK_RATE_MS); /* Set enable pin low */ gpio_set_pin_low(LCD_E_PIN); /* Now wait to be sure that lcd device is ready for * new instructions */ vTaskDelay(1/portTICK_RATE_MS); }
void spimem_initialize(void) { uint16_t dumbuf[2], i; uint8_t check; if(INTERNAL_MEMORY_FALLBACK_MODE) return; gpio_set_pin_low(SPI0_MEM1_HOLD); // Turn "holding" off. gpio_set_pin_low(SPI0_MEM1_WP); // Turn write protection off. gpio_set_pin_high(SPI0_MEM2_HOLD); // Turn "holding" off. gpio_set_pin_high(SPI0_MEM2_WP); // Turn write protection off. if(ready_for_command_h(2) != 1) // Check if the chip is ready to receive commands. return; // FAILURE_RECOVERY : CHIP IS BEING BUGGY if(ERASE_SPIMEM_ON_RESET) { if(erase_spimem() < 0) return; // FAILURE_RECOVERY : CHIP ERASE TOOK TOO LONG } if(ready_for_command_h(2) != 1) return; // FAILURE_RECOVERY : CHIP IS BEING BUGGY for (i = 0; i < 128; i++) { spi_bit_map[i] = 0; // Initialize the bitmap } for (i = 0; i < 4096; i++) { spi_mem_buff[i] = 0; // Initialize the memory buffer. } return; }
/** * \brief Read a register value. * * \param reg the register address to modify. * * \return the register value. */ uint16_t ksz8851_reg_read(uint16_t reg) { pdc_packet_t g_pdc_spi_tx_packet; pdc_packet_t g_pdc_spi_rx_packet; uint16_t cmd = 0; uint16_t res = 0; gpio_set_pin_low(KSZ8851SNL_CSN_GPIO); /* Move register address to cmd bits 9-2, make 32-bit address. */ cmd = (reg << 2) & REG_ADDR_MASK; /* Last 2 bits still under "don't care bits" handled with byte enable. */ /* Select byte enable for command. */ if (reg & 2) { /* Odd word address writes bytes 2 and 3 */ cmd |= (0xc << 10); } else { /* Even word address write bytes 0 and 1 */ cmd |= (0x3 << 10); } /* Add command read code. */ cmd |= CMD_READ; tmpbuf[0] = cmd >> 8; tmpbuf[1] = cmd & 0xff; tmpbuf[2] = CONFIG_SPI_MASTER_DUMMY; tmpbuf[3] = CONFIG_SPI_MASTER_DUMMY; /* Prepare PDC transfer. */ g_pdc_spi_tx_packet.ul_addr = (uint32_t) tmpbuf; g_pdc_spi_tx_packet.ul_size = 4; g_pdc_spi_rx_packet.ul_addr = (uint32_t) tmpbuf; g_pdc_spi_rx_packet.ul_size = 4; pdc_disable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS); pdc_tx_init(g_p_spi_pdc, &g_pdc_spi_tx_packet, 0); pdc_rx_init(g_p_spi_pdc, &g_pdc_spi_rx_packet, 0); pdc_enable_transfer(g_p_spi_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN); while (!(spi_read_status(KSZ8851SNL_SPI) & SPI_SR_ENDRX)) ; gpio_set_pin_high(KSZ8851SNL_CSN_GPIO); res = (tmpbuf[3] << 8) | tmpbuf[2]; return res; }
/** * \brief Sets LED pin to low. * @param *pvParameters: */ static void prvTurnOffTask( void *pvParameters ) { TickType_t xLastWakeTime; const TickType_t xTimeToWait = 500; //Number entered here corresponds to the number of ticks we should wait. /* As SysTick will be approx. 1kHz, Num = 1000 * 60 * 60 = 1 hour.*/ // Check the task parameter is as expected. configASSERT( ( ( unsigned long ) pvParameters ) == TurnOff_PARAMETER ); /* @non-terminating@ */ for( ;; ) { gpio_set_pin_low(LED0_GPIO); xLastWakeTime = xTaskGetTickCount(); vTaskDelayUntil(&xLastWakeTime, xTimeToWait); } }