Skip to content Skip to navigation

Connexions

You are here: Home » Content » Lab 8: Writing a process scheduler

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • TI MSP430 display tagshide tags

    This module is included inLens: Texas Instruments MSP430
    By: Texas Instruments

    Comments:

    "A how-to document for writing a process scheduler for a microcontroller in C."

    Click the "TI MSP430" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

Lab 8: Writing a process scheduler

Module by: adrian valenzuela. E-mail the author

User rating (How does the rating system work?)
Ratings

Ratings allow you to judge the quality of modules. If other users have ranked the module then its average rating is displayed below. Ratings are calculated on a scale from one star (Poor) to five stars (Excellent).

How to rate a module

Hover over the star that corresponds to the rating you wish to assign. Click on the star to add your rating. Your rating should be based on the quality of the content. You must have an account and be logged in to rate content.

:
(0 ratings)

Summary: In this lab you will write your own task scheduler for the MSP430.

Exercise 1

Write a simple scheduler in C for a microcontroller. The scheduler should be cooperative and event driven. When the scheduler is executes, it should hand over processor control by calling the primary function of the process which:

  1. is waiting for attention
  2. has the highest priority of the waiting programs
  3. has been waiting the longest in case of a tie above

This behavior may result in lower priority processes never receiving attention from the processor. It is up to the programmer of the individual processes to ensure that the process returns to the scheduler in a timely matter.

The scheduler should maintain a list of all processes, in order of priority. For each process, the following information should be kept:

  • the priority number,
  • the process id number (an identifier unique to that process,
  • a pointer to the function itself, and
  • the status (waiting for attention or waiting for an event).
The order of the list should reflect the order in which processes should be called.

The scheduler should support the following functions to facilitate scheduling. The processes the scheduler managed can be known and created at compile time. Extra credit will be provided for implementing the functions that allow for dynamic process creation [hint: this requires the use of function pointers]. While the processes are known at compile time, the creation and use of semaphores and the setting of priorities should be possible at runtime.

Most of the functions are related to setting up the relationship between processes (priorities, semaphores, etc). None of these methods should be called from inside an interrupt because the interaction of interrupts with the scheduler data structure cannot be guaranteed. More advanced discussions of operating systems will explain atomic instructions and how they handle this impasse.

create_new_process

unsigned int create_new_process(void (*f)(void), unsigned int priority) [fact check how to pass function names as pointers]

parameters:

  • pointer to the process function parameter
  • priority of the process
returns:
  • process id
This function is only necessary if dynamic process creation is implemented. If dynamic allocation is used, the create_new_process method will generate the unique identifier for each process. If static process creation is used, then the identifier may be added into the code. #define may be useful for making these process_ids human readable. One process_id should be reserved as an error code if something goes wrong. For example 0x0000 might be returned if the maximum number of processes has already been reached.

create_binary_semaphore

unsigned intcreate_binary_semaphore(unsigned int process, unsigned int state)

parameters:

  • process id
  • initial state of the semaphore
returns:
  • semapore id
Semaphore creation will add a new semaphore to the process specified. The integer returned is the identifier for the semaphore that is unique to each process (rather unique to all processes). Each process should be allowed at least 8 semaphores. A process will not be allowed to run unless all of its created semaphores are ready.

set_semaphore

void set_semaphore(unsigned int process, unsigned int semaphore, unsigned int state)

parameters:

  • process id
  • priority of the process
  • new state of the semaphore
Sets the state of a certain created semaphore of a certain process. The states are ready and waiting.

set_priority

void set_priority(unsigned int process, unsigned int new_priority)

parameters:

  • process id
  • new priority of the process

schedule

void schedule(void)

The main() function calls schedule once the system has been set up. Schedule then handles all further negotiation of the processes. More advanced schedulers will actually adjust the stack pointer and the context data of each function call to allow seemless transition between processes. This process requires writing part of the scheduler in assembly to avoid the automatic adjustments C will make on its own. In this case, you need only call each function normally from inside schedule().

Content actions

Give Feedback:

E-mail the module author | Rate module ( How does the rating system work?)

Rating system

Ratings

Ratings allow you to judge the quality of modules. If other users have ranked the module then its average rating is displayed below. Ratings are calculated on a scale from one star (Poor) to five stars (Excellent).

How to rate a module

Hover over the star that corresponds to the rating you wish to assign. Click on the star to add your rating. Your rating should be based on the quality of the content. You must have an account and be logged in to rate content.

(0 ratings)

Download:

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.

| A lens (?)

Definition of a lens

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks