Skip to content

DD_CC_OS

Pranjal Chanda edited this page Dec 30, 2022 · 4 revisions

Introduction

CC OS (Cyancore Operation System) is a Real Time Operating system supported by cyancore Framework. The OS supports dynamic scheduler selection among the following algorithms:

  1. Round Robin
  2. Priority Driven

CC OS User MACROS

CC_TASK_DEF

This is a Macro that is used to create a static instance of cc_os_task

CC_TASK_DEF(_Name, _Fn, _Args, _Prio, _Stack_len);

CC_GET_TASK_INST

This is a Macro that is used for getting the instance created by CC_TASK_DEF

CC_GET_TASK_INST(_Name);

CC OS User API Reference

/**
 * @brief A Function to add a task to the scheduler
 *
 * @param cc_os_task[in_out]	 pointer to the TASK_instance; use CC_GET_TASK_INST(Name) to get the Defined Task
 * @return status_t
 */
status_t cc_os_add_task(cc_os_task_t *cc_os_task);

/**
 * @brief A function to delete a task from the scheduler by instance
 *
 * @param cc_os_task[in]	pointer to the TASK_instance; use CC_GET_TASK_INST(Name) to get the Defined Task;
 * 				Pass NULL to point to current task
 * @return status_t
 */
status_t cc_os_del_task(cc_os_task_t *cc_os_task);

/**
 * @brief A Function to pause the task until call resume explicitly using its instance
 *
 * @param cc_os_task[in]	pointer to the TASK_instance; use CC_GET_TASK_INST(Name) to get the Defined Task;
 * 				Pass NULL to point to current task
 * @return status_t
 */
status_t cc_os_pause_task(cc_os_task_t *cc_os_task);

/**
 *
 * @brief A Function to resume paused task using its instance
 * @note  Calling this function for already non-waiting task has no effect.
 *
 * @param cc_os_task[in]	pointer to the TASK_instance; use CC_GET_TASK_INST(Name) to get the Defined Task;
 * 				Pass NULL to point to current task
 * @return status_t
 */
status_t cc_os_resume_task(cc_os_task_t *cc_os_task);

/**
 * @brief A Function to pause all the tasks except the current and the IDLE Task
 * @note	To resume all please use cc_os_resume_all_task() call
 *
 * @return status_t
 */
status_t cc_os_pause_all_task(void);

/**
 * @brief A Function to resume all the tasks
 *
 * @return status_t
 */
status_t cc_os_resume_all_task(void);

/**
 * @brief A function to set CC OS scheduler algorithm
 *
 * @param sched_algo[in]	The algorithm that needs to be selected to
 * @return status_t
 */
status_t set_cc_os_sched_algo(cc_sched_algo_t sched_algo);

/**
 * @brief A Function to put the current task to a waiting state and yield
 * @note  To just Yeild set ticks to 0
 *
 * @param ticks[in]		Number of CC_OS Ticks
 * @return None
 */
void cc_os_task_wait(const size_t ticks);

/**
 * @brief A Function to switch to next available task
 *
 * @return None
 */
void cc_os_task_yield(void);

/**
 * @brief A Function to invoke the kernel
 *
 * @return status_t
 */
void cc_os_run(void);

Example:

#include "cc_os.h"

CC_TASK_DEF(
    task1_name,	        /* Name of the instance */
    task1_fn,           /* Function pointer */
    CC_OS_NULL_PTR,   	/* Task Args*/
    10 ,	        /* Task Priority */
    255                 /* Stack Length of IDLE Task */
);

size_t task2_resource;

CC_TASK_DEF( task2_name, task2_fn, &task2_resource, 3, 255 );

void plug()
{
    /* Initialize Drivers */

    /* Create Threads */
    cc_os_add_task(&CC_GET_TASK_INST(task1_name));
    cc_os_add_task(&CC_GET_TASK_INST(task2_name));

    /* Initialize and Run CC_OS*/
    cc_os_run();
}

void play()
{
    /* Do Nothing. Code would not reach here */
}

void task1_fn(os_args args)
{
    /* Task init */
    while(CC_OS_TRUE)
    {
        /* Task Statements */
        cc_os_task_wait(1);
    }
}

void task2_fn(os_args args)
{
    /* Task init */
    size_t task2_res_arg = (size_t*) args;

    while(CC_OS_TRUE)
    {
        /* Task Statements */
        cc_os_task_wait(1);
    }
}