//Main function, the entry point int main(void) { int uart_check = 0,i=0,j=0; char str[]="sunny,sunny day";//inputs are given char w[]="sunny"; //Checking the status of UART uart_check = wmstdio_init(UART0_ID, 0); if (uart_check == -WM_FAIL) { wmprintf("Failed to initialize console on uart0\r\n"); return -1; } wmprintf("entered string is :%s\n",str);//inputs are outputed wmprintf("entered word :%s\n",w); int wcount = count(str,w);//ouputting total words wmprintf("word count : %d\n",wcount); if (wcount>0) { gpio_led_on() } gpio_led = (board_led_2()).gpio; //assigning gpio pin to led gpio_pushbutton = board_button_2(); //assigning gpio pin to push button configure_gpios(); wmprintf("Press push button to reset the program."); while (1) ; return 0; }
/* 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; }
void reset(void) //same function as main() { char str[]="sunny,sunny day";//inputs are given char w[]="sunny"; wmprintf("entered string is :%s\n",str);//inputs are outputed wmprintf("entered word :%s\n",w); int wcount = count(str,w); wmprintf("word count : %d\n",wcount); if (wcount>0) { gpio_led_on() } gpio_led = (board_led_2()).gpio; //assigning gpio pin to led gpio_pushbutton = board_button_2(); //assigning gpio pin to push button configure_gpios(); wmprintf("Press push button to reset the program."); while (1) ; 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 gpio_led_off(void) { mdev_t *gpio_dev = gpio_drv_open("MDEV_GPIO"); /* Turn off LED by writing 1 in GPIO register */ gpio_drv_write(gpio_dev, gpio_led, 1); gpio_drv_close(gpio_dev); gpio_led_state = 0; gpio_led_on(); //giving the control back to the calling function. }
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 } }