/* This is an entry point for the application. All application specific initialization is performed here. */ int main(void) { int ret = 0; /* Initializes console on UART0 */ ret = wmstdio_init(UART0_ID, 0); if (ret == -WM_FAIL) { wmprintf("Failed to initialize console on uart0\r\n"); return -1; } wmprintf(" LED demo application started\r\n"); wmprintf(" This application demonstrates the" " use of blinking led\r\n"); gpio_led = (board_led_2()).gpio; wmprintf(" LED Pin : %d\r\n", gpio_led); configure_gpios(); while (1) { gpio_led_on(); os_thread_sleep(os_msec_to_ticks(1000)); gpio_led_off(); os_thread_sleep(os_msec_to_ticks(1000)); } return 0; }
/* This function is called when push button is pressed*/ static void pushbutton_cb(int pin, void *data) { if (gpio_led_state) gpio_led_off(); else gpio_led_on(); }
static void prvBlinkLedTask( void *pvParameters ) { while (1) { gpio_led_on(); vTaskDelay(os_msec_to_ticks(1000)); gpio_led_off(); vTaskDelay(os_msec_to_ticks(1000)); } }
static stat_t _alarm_idler(void) { if (cm_get_machine_state() != MACHINE_ALARM) { return (STAT_OK);} if (--tg.led_counter < 0) { tg.led_counter = LED_COUNTER; if (tg.led_state == 0) { gpio_led_on(INDICATOR_LED); tg.led_state = 1; } else { gpio_led_off(INDICATOR_LED); tg.led_state = 0; } } return (STAT_EAGAIN); // EAGAIN prevents any other actions from running }
static uint8_t _shutdown_idler(void) { if (cm_get_machine_state() != MACHINE_SHUTDOWN) { return (TG_OK);} if (--tg.led_counter < 0) { tg.led_counter = LED_COUNTER; if (tg.led_state == 0) { gpio_led_on(INDICATOR_LED); tg.led_state = 1; } else { gpio_led_off(INDICATOR_LED); tg.led_state = 0; } } return (TG_EAGAIN); // EAGAIN prevents any other actions from running }
//function to blink the led the number of times equal to occurence of the word static void gpio_led_on(wcount) //passing the word count { int count=wcount; //setting the counter mdev_t *gpio_dev = gpio_drv_open("MDEV_GPIO"); /* Turn on LED by writing 0 in GPIO register */ gpio_drv_write(gpio_dev, gpio_led, 0); gpio_drv_close(gpio_dev); gpio_led_state = 1; gpio_led_off(); //turning off the led to give the binking effect count=count-1; //decreasing the counter by 1 after glowing led while(count!=1) //recursive function, to be visited till counter becomes 1(not 0 because counter starts from w,not w-1) { gpio_led_on(count); //recursive function } }