Thread: Task creations

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    90

    Task creations

    I need a general idea how to create tasks in C programming for real time operating system which supports preemptive priority based scheduling, the system is configured to generate 1ms time slice.

    My plan is, I should have function in the file tasks.c whose purpose is to create a task. In the main. c file I need to write a section of code that calls a function in task.c to create a task. all tasks must be created with some default priorities. Once the task has been created it should be run.

    If I have missed any information please feel free to ask.

    do you have any idea how you would do this?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2019
    Posts
    90
    No doubt you helped me in my previous threads to understand the scheduling. The programming structure of FreeRTOS is very difficult and it is very difficult to understand.


    The question I asked, do you have any idea about this, how can this be done?

    It will be helpful if you can provide pepseudo code for basic idea only

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It's all in the previous threads.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Nov 2019
    Posts
    90
    I have seen all the threads many times but I have never seen that we have discussed this topic. Please don't compare this question with FreeRTOS. Its architecture is complex to understand the concept

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Why do you want to re-invent the wheel?
    You say you have an RTOS that has task management system; why does that system not fit your needs?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Nov 2019
    Posts
    90
    As I mentioned earlier, the architecture of FreeRTOS is very complex, which I do not understand at all.

    My only question here is how to create a function in which the task can be created

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Sure, why not - let's see how far you can run with this.

    Your very basic task control block needs a few things
    - a task state, see FreeRTOS task states and state transitions described for ideas.
    - a stack
    - a function to call
    - a priority

    Code:
    typedef enum {
      TS_INIT,
      TS_READY,  // just waiting for the CPU
      TS_RUNNING,  // actively running
      TS_BLOCKED, // waiting for something other than the CPU (like sleeping) 
    } taskState_t;
    
    typedef struct {
      unsigned long stack[256];
      unsigned long *sp;
      taskState_t state;
      int priority;
      void (*entrypoint)(void);
    } taskTcb_t;
    taskTcb_t tasks[3];
    int numTasks = 0;
    int currentTask;
    
    void makeTask(void (*fn)(void), int prio) {
      tasks[numTasks].sp = &tasks[numTasks].stack[255];
      tasks[numTasks].state = TS_INIT;
      tasks[numTasks].priority = prio;
      tasks[numTasks].entrypoint = fn;
      numTasks++;
    }
    void resumeTask(int taskId) {  // called from clock ISR
      // asm to move tasks[taskId].sp to stack pointer
      
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My C creations 4
    By jeimyrm in forum Projects and Job Recruitment
    Replies: 4
    Last Post: 07-27-2017, 02:09 AM
  2. My C creations 3
    By jeimyrm in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 07-13-2017, 12:02 AM
  3. My C creations 2
    By jeimyrm in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 07-13-2017, 12:00 AM
  4. My C creations 1
    By jeimyrm in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 07-12-2017, 11:58 PM
  5. Replies: 2
    Last Post: 12-31-2007, 11:40 AM

Tags for this Thread