I am a beginner to Free RTOS. so I have tried to build a simple button led project. When I press the button it should light up the LED. I implemented this similar model in sequential programming. It is successful but in Free rtos I couldnt comprehend where I am going wrong. To check whether a scheduler is working or not, I have written a simple blinky led it is working. How ever button,led tasks couldnt able to run.could some one please help me where I am going wrong?
#include <stdbool.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "bsp.h"
#include "nordic_common.h"
#include "nrf_drv_clock.h"
#include "sdk_errors.h"
#include "app_error.h"
#include "nrf_gpio.h"
#define TASK_DELAY 200
#define led 13
#define button 11
TaskHandle_t led_toggle_task_handle;
#define true 1
#define false 0
#define not_pressed false
#define pressed true
uint8_t button_status_flag=not_pressed;
static void setup_hardware(void)
{
nrf_gpio_cfg_output(led);
nrf_gpio_cfg_input(button,NRF_GPIO_PIN_PULLUP);
nrf_gpio_pin_set(led);
}
static void led_toggle_task_function (void * pvParameter)
{
UNUSED_PARAMETER(pvParameter);
while (true)
{
bsp_board_led_invert(BSP_BOARD_LED_2);
/* Delay a task for a given number of ticks */
vTaskDelay(TASK_DELAY);
/* Tasks must be implemented to never return... */
}
}
static void led_task_handler(void * params)
{
while(1)
{
if(button_status_flag == pressed)
{
nrf_gpio_pin_clear(led);//lights LED.
}
else
{
nrf_gpio_pin_set(led);
}
}
}
static void button_task_handler(void * params)
{
while(1)
{
if(nrf_gpio_pin_read(button))
{
button_status_flag=not_pressed;
}
else
{
button_status_flag=pressed;
}
}
}
int main(void)
{
ret_code_t err_code;
/* Initialize clock driver for better time accuracy in FREERTOS */
err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);
/* Configure LED-pins as outputs */
// bsp_board_init(BSP_INIT_LEDS);
setup_hardware();
bsp_board_init(BSP_INIT_LEDS);
xTaskCreate(led_toggle_task_function, "LED2", configMINIMAL_STACK_SIZE + 200, NULL, 2, &led_toggle_task_handle);
xTaskCreate(led_task_handler,"LED-TASK",configMINIMAL_STACK_SIZE,NULL,1,NULL);
xTaskCreate(button_task_handler,"BUTTON-TASK",configMINIMAL_STACK_SIZE,NULL,1,NULL);
/* Activate deep sleep mode */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
/* Start FreeRTOS scheduler. */
vTaskStartScheduler();
while (true)
{
/* FreeRTOS should not be here... FreeRTOS goes back to the start of stack
* in vTaskStartScheduler function. */
}
}
/**
*@}
**/