/** * \brief Test LIN transmit. * * This test initializes the LIN and start a transmit. * * \param test Current test case. */ static void run_lin_test(const struct test_case *test) { st_lin_message lin_desc; /* Enable the peripheral clock in the PMC. */ pmc_enable_periph_clk(ID_USART0); /* Enable LIN transceiver */ gpio_set_pin_high(PIN_USART0_CTS_IDX); gpio_set_pin_high(PIN_USART0_RTS_IDX); /* Node 0: LIN_MASTER_MODE */ lin_init(USART0, true, LIN_MASTER_NODE_NUM, 9600, sysclk_get_cpu_hz()); /* Configure lin_descriptor */ /* Init LIN data Node 0 */ /* Object 0 */ lin_desc.uc_id = LIN_FRAME_ID_12; lin_desc.uc_dlc = sizeof(lin_data_node); lin_desc.lin_cmd = PUBLISH; lin_desc.uc_status = 0; lin_desc.uc_pt_data = lin_data_node; lin_register_descriptor(LIN_MASTER_NODE_NUM, 0, &lin_desc); configure_tc(); /* In case of Master Mode, the timing transmission starts... */ tc_start(TC0, 0); /* Configure and enable interrupt of USART */ NVIC_EnableIRQ(USART0_IRQn); usart_enable_interrupt(USART0, US_IER_LINTC); delay_ms(200); test_assert_true(test, ul_LIN_int_flag, "LIN transmit failed!"); }
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 pin_handler(uint32_t id, uint32_t mask){ if (id == ID_ENC){ switch (mask){ case GPIO_A: if (bFlag){ gpio_toggle_pin(LED0_GPIO); gpio_set_pin_high(LED1_GPIO); round++; } else { aFlag = 1; } break; case GPIO_B: if (aFlag){ gpio_toggle_pin(LED1_GPIO); gpio_set_pin_high(LED0_GPIO); round--; } else { bFlag = 1; } break; case GPIO_C: gpio_toggle_pin(LED2_GPIO); bFlag = 0; aFlag = 0; break; } } }
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 }
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); } } }
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 Main function. * * Initializes the board, and runs the application in an infinite loop. */ int main(void) { /* hardware initialization */ sysclk_init(); board_init(); pmic_init(); timer_init(); rs485_init(); led_init(); adc_init(); #ifdef CONF_BOARD_ENABLE_RS485_XPLAINED // Enable display backlight gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT); #endif // Workaround for known issue: Enable RTC32 sysclk sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC); while (RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm) { // Wait for RTC32 sysclk to become stable } cpu_irq_enable(); /* application initialization */ rs485_baud_rate_set(38400); bacnet_init(); /* run forever - timed tasks */ timer_callback(bacnet_task_timed, 5); for (;;) { bacnet_task(); led_task(); } }
/*! \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); } } }
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); } }
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){ } }
/** * \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--) { } }
/** 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 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(); } } }
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); }
/** * \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); } }
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);*/ }
/** * \brief ISO7816 ICC power on. */ static void iso7816_icc_power_on(void) { /* Set RESET Master Card. */ #if defined(SMART_CARD_USING_GPIO) gpio_set_pin_high(gs_ul_rst_pin_idx); #elif defined(SMART_CARD_USING_IOPORT) ioport_set_pin_level(gs_ul_rst_pin_idx, IOPORT_PIN_LEVEL_HIGH); #endif }
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); } }
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 debug_green_led(uint8_t state) { if (state) { gpio_set_pin_low(LED0_GPIO); } else { gpio_set_pin_high(LED0_GPIO); } }
/*! \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); } } } }
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 }
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); } } }
void ioapi_output_high_body( uint8_t pin_number ) { /* There are functions in GPIO driver which automatically * init ports when they are used. However, they open risk that * another part of program accidently overdrives something it shouldn't. * Now we init all ports in same place, and if port isn't correctly * initialized we raise ASSERT here! */ gpio_set_pin_high(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 ) != 0); }
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; }
/********************************************************************* Functions *********************************************************************/ int main (void) { int i; // initialize init(); // start code from here gpio_set_pin_high(RESPONSE_A); 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); } //printf("tick\n"); //gpio_toggle_pin(LED0_GPIO); //busy_delay_ms(500); } }