This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to set up the scheduler on nRF51822

Hello Team,

I want to use scheduler to schedule two tasks i.e task_1 and task_2. The task_1 and task_2 are as follow:

void task_1() {
    printf("Task 1 ran");
}

void task_2() {
    printf("Task 2 ran");
}

Now I want to use the scheduler to schedule this task i.e to schedule task_1 after every 100ms and task_2 after every 200ms.

I am totally new to this topic and have tried to read the scheduler library from Nordic info-center but i am still not clear about how to implement this.

I have also referred the HID example but was not able to implement the above describe task.

If possible if you can provide a example it will be very helpful.

Thanks and Regards,

Juzer.T

Parents
  • Hi,

    The app scheduler included with the SDK is a very basic scheduler (Schedule handling library), and does not support creation and scheduling of tasks/threads. If you need this, I suggest you look at the Freertos examples we have: Heart Rate Application with FreeRTOS

    Best regards,

    Vidar

  • Tools:
    software: keil version 5
    SDK version: SDK8 (available with keil u5, i.e default Nordic SDK available with keil software for nRF51822)

    STEPS:
    I have used the UART example from pack installer and have added the following code to impliment my logic of printing "Task 1 ran" on completing the 15sec timer.

    #define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
    #define APP_TIMER_OP_QUEUE_SIZE 4 /**< Size of timer operation queues. */
    #define SCHED_MAX_EVENT_DATA_SIZE sizeof(app_timer_event_t)
    #define SCHED_QUEUE_SIZE 10

    APP_TIMER_DEF(m_timer_id);

    //void * p_context; /**< General purpose pointer. Will be passed to the timeout handler when the timer expires. */
    static void timer_timeout_handler(void * p_context)

    {
    //Do something
    printf("Task 1 ran\n");
    }

    void function2(void)
    {
    //Stop timer if called
    app_timer_stop(m_timer_id);
    printf("fuction1 running timer stopped.\n");
    }

    void function1(void)
    {
    //Start 15s timer if called
    app_timer_start(m_timer_id, APP_TIMER_TICKS(15000, APP_TIMER_PRESCALER),NULL);
    printf("fuction1 running timer started.\n");
    }

    int main(void)
    {
    APP_TIMER_APPSH_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, true);

    uint8_t err_code = app_timer_create(&m_timer_id,
    APP_TIMER_MODE_SINGLE_SHOT,
    timer_timeout_handler);

    APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
    printf("function1.\n");
    function1();

    while (true)
    {
    app_sched_execute();
    }
    }

    my code compiled successfully and Now when I run the code, on serial monitor I got the following message:
    "function1.
    function1 running timer started."

    That's it
    My timer_timeout_handler is not executed and not printing "Task 1 ran" on serial monitor

    Now what I was thinking that when my timer of 15sec gets over it calls timer_timeout_handler and thus after 15sec it should print "Task 1 ran" but it is not.

    what I am doing wrong can you please explain.

Reply
  • Tools:
    software: keil version 5
    SDK version: SDK8 (available with keil u5, i.e default Nordic SDK available with keil software for nRF51822)

    STEPS:
    I have used the UART example from pack installer and have added the following code to impliment my logic of printing "Task 1 ran" on completing the 15sec timer.

    #define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
    #define APP_TIMER_OP_QUEUE_SIZE 4 /**< Size of timer operation queues. */
    #define SCHED_MAX_EVENT_DATA_SIZE sizeof(app_timer_event_t)
    #define SCHED_QUEUE_SIZE 10

    APP_TIMER_DEF(m_timer_id);

    //void * p_context; /**< General purpose pointer. Will be passed to the timeout handler when the timer expires. */
    static void timer_timeout_handler(void * p_context)

    {
    //Do something
    printf("Task 1 ran\n");
    }

    void function2(void)
    {
    //Stop timer if called
    app_timer_stop(m_timer_id);
    printf("fuction1 running timer stopped.\n");
    }

    void function1(void)
    {
    //Start 15s timer if called
    app_timer_start(m_timer_id, APP_TIMER_TICKS(15000, APP_TIMER_PRESCALER),NULL);
    printf("fuction1 running timer started.\n");
    }

    int main(void)
    {
    APP_TIMER_APPSH_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, true);

    uint8_t err_code = app_timer_create(&m_timer_id,
    APP_TIMER_MODE_SINGLE_SHOT,
    timer_timeout_handler);

    APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
    printf("function1.\n");
    function1();

    while (true)
    {
    app_sched_execute();
    }
    }

    my code compiled successfully and Now when I run the code, on serial monitor I got the following message:
    "function1.
    function1 running timer started."

    That's it
    My timer_timeout_handler is not executed and not printing "Task 1 ran" on serial monitor

    Now what I was thinking that when my timer of 15sec gets over it calls timer_timeout_handler and thus after 15sec it should print "Task 1 ran" but it is not.

    what I am doing wrong can you please explain.

Children
Related