Module Design Guidelines for Real-Time Systems
by David Janik

Example 1:

APPLICATION
-include
  -abc.h
  -xyz.h
  -pdq.h
-ABC
  -abc.c  /* #include "pdq.h"  to use services of module PDQ */
  -abc_appSpec.h
-XYZ
  -xyz.c /* #include "pdq.h"  to use services of module PDQ */
  -xyz_appSpec.h
-PDQ
  -pdq.c
  -pdq_appSpec.h


Example 2:

APPLICATION
-include
  -abc.h
  -xyz.h
  -pdq.h
ABC
  -abc.c
  -abc_appSpec.h
  -abc_map.h
  -abc_internal.c
  -abc_internal.h
-XYZ
  -xyz.c
  -xyz_appSpec.h
-PDQ
  -pdq.c
  -pdq_appSpec.h

Example 3:

APPLICATION
-include
  -abc.h
  -xyz.h
  -pdq.h
ABC
  -abcMessage.c
  -abcControl.c
  -abc_appSpec.h
  -abc_map.h
  -abc_task.c
  -abc_task.h
  -abc_utilities.c
  -abc_utilities.h
-XYZ
  -xyz.c
  -xyz_appSpec.h
-PDQ
  -pdq.c
  -pdq_appSpec.h



Listing One
(a) 
/* Name: abc.c          */
/* Description:         */
/* Developer:           */

#include abc.h
#include abc_appSpec.h
#include pdq.h          /* prototype for pdqAction() */
#include rtos.h         /* prototype for rtosStartTask() */

/*** Protected Data             ***/
typedef
{
   int mode;
   int *device;
}abc_struct

abc_struct abc_data[ABC_INSTANCES];

/*** Internal Functions Prototypes ***/
int abc_instanceCheck(int instance);
int abc_messageCheck(int message);

/*** Internal Functions ***/
int abc_instanceCheck(int instance)
{
   int result = ABC_ERROR;
   if (instance < ABC_INSTANCE)
   {
      result = ABC_OK;
   }
   return (result);
}

/*** ***/
int abc_messageCheck(int message)
{
   int result = ABC_ERROR;
   if (message == ABC_MESSAGE_1 || message == ABC_MESSAGE_2)
   {
      result = ABC_OK;
   }
   return (result);

/*** External Functions ***/
int abcInit()
{
   int i;

   for (i=0; i<ABC_INSTANCES; i++)
   {
      abc_data[i].mode   = 0;
      abc_data[i].device = (int *)(ABC_BASE_ADDRESS + (0x100 * i);
   }

   rtosStartTask(abc_task, ABC_PRIORITY);

   return (ABC_OK);
}

/***  ***/
int abcModeGet(int instance, int *mode)
{
   int result = ABC_ERROR;
   if (abc_instanceCheck(instance) == ABC_OK)
   {
      *mode = abc_data[instance].mode;
      if (*mode == 1)
      {
         pdqAction(*abc_data[instance].device);
         abc_data[instance].mode = 0;
      }
      result = ABC_OK;
   }
   return (result);
}

/*** ***/
int abcMessageSend(int instance, int message)
{
   int result = ABC_ERROR;
   if (abc_instanceCheck(instance) == ABC_OK)
   {
      if (abc_messageCheck(message) == ABC_OK)
      {
         *abc_data[instance].device = message;
         result = ABC_OK;
      }
   }
   return (result);
}

(b) 
/* Name: abc.h          */
/* Description:         */
/* Developer:           */

#define ABC_ERROR       1
#define ABC_OK          0

#define ABC_MESSAGE_1   1
#define ABC_MESSAGE_2   2

int abcInit(void);
int abcModeGet(int instance, int *mode);
int abcMessageSend(int instance, int message);

(c)  
/* Name: abc_appSpec..h            */
/* Description:                    */
/* Developer:                      */

#define ABC_INSTANCES      10
#define ABC_BASE_ADDRESS   0x1230
#define ABC_IRQ            7
#define ABC_PRIORITY       5
#define ABC_PAUSE          100 /* 1 second */


Listing Two
(a) 
/* Name: abc.c          */
/* Description:         */
/* Developer:           */

#include abc.h
#include abc_appSpec.h
#include abc_internal.h
#include abc_map.h
#include pdq.h          /* prototype for pdqAction() */
#include rtos.h         /* prototype for rtosStartTask() */

/*** Protected Data             ***/
abc_struct abc_data[ABC_INSTANCES];   /* declare Protected Data Structure */

/*** External Functions ***/
int abcInit()
{
   int i;

   for (i=0; i<ABC_INSTANCES; i++)
   {
      abc_data[i].mode   = 0;
      abc_data[i].device = (int *)(ABC_BASE_ADDRESS + (0x100 * i);
   }

   rtosStartTask(abc_task, ABC_PRIORITY);

   return (ABC_OK);
}

/***  ***/
int abcModeGet(int instance, int *mode)
{
   int result = ABC_ERROR;
   if (abc_instanceCheck(instance) == ABC_OK)
   {
      *mode = abc_data[instance].mode;
      if (*mode == 1)
      {
         pdqAction(*abc_data[instance].device);
         abc_data[instance].mode = 0;
      }
      result = ABC_OK;
   }
   return (result);
}

/*** ***/
int abcMessageSend(int instance, int message)
{
   int result = ABC_ERROR;
   if (abc_instanceCheck(instance) == ABC_OK)
   {
      if (abc_messageCheck(message) == ABC_OK)
      {
         *abc_data[instance].device = message;
         result = ABC_OK;
      }
   }
   return (result);
}

(b) 
/* Name: abc_internal.c     */
/* Description:             */
/* Developer:               */

#include abc_appSpec.h
#include abc_internal.h
#include abc_map.h
#include rtos.h         /* prototype for rtosPause() */

/*** Internal Functions ***/

int abc_instanceCheck(int instance)
{
   int result = ABC_ERROR;
   if (instance < ABC_INSTANCE)
   {
      result = ABC_OK;
   }
   return (result);
}

/*** ***/
int abc_messageCheck(int message)
{
   int result = ABC_ERROR;
   if (message == ABC_MESSAGE_1 || message == ABC_MESSAGE_2)
   {
      result = ABC_OK;
   }
   return (result);
}

/*** ***/
int abc_task()
{
   int instance = 0;

   for(;;)
   {
      rtosPause(ABC_PAUSE);
      if (*abc_data[instance].device != 0)
      {
         abc_data[instance].mode = 1;
      }
      instance++;
      if (instance >= ABC_INSTANCE)
      {
         instance = 0;
      }
   }
}

(c) 
/* Name: abc_internal.h     */
/* Description:             */
/* Developer:               */

/*** Internal Functions ***/
int abc_instanceCheck(int instance);
int abc_messageCheck(int message);
int abc_task(void);

(d) 
/* Name: abc_map.h      */
/* Description:         */
/* Developer:           */

/*** Protected Data             ***/
typedef
{
   int mode;
   int *device;
}abc_struct

extern abc_struct abc_data[ABC_INSTANCES];

(e) 
/* Name: abc.h          */
/* Description:         */
/* Developer:           */

#define ABC_ERROR       1
#define ABC_OK          0

#define ABC_MESSAGE_1   1
#define ABC_MESSAGE_2   2

int abcInit(void);
int abcModeGet(int instance, int *mode);
int abcMessageSend(int instance, int message);

(f)  
/* Name: abc_appSpec..h    */
/* Description:            */
/* Developer:              */

#define ABC_INSTANCES      10
#define ABC_BASE_ADDRESS   0x1230
#define ABC_IRQ            7
#define ABC_PRIORITY       5
#define ABC_PAUSE          100 /* 1 second */


Listing Three

(a) 
/* Name: abcControl.c       */
/* Description:             */
/* Developer:               */

#include abc.h
#include abc_appSpec.h
#include abc_utilities.h
#include abc_map.h
#include abc_task.h
#include pdq.h          /* prototype for pdqAction() */
#include rtos.h         /* prototype for rtosStartTask() */

/*** Protected Data             ***/
abc_struct abc_data[ABC_INSTANCES];   /* declare Protected Data Structure */

/*** External Functions ***/
int abcInit()
{
   int i;

   for (i=0; i<ABC_INSTANCES; i++)
   {
      abc_data[i].mode   = 0;
      abc_data[i].device = (int *)(ABC_BASE_ADDRESS + (0x100 * i);
   }

   rtosStartTask(abc_task, ABC_PRIORITY);

   return (ABC_OK);
}

/***  ***/
int abcModeGet(int instance, int *mode)
{
   int result = ABC_ERROR;
   if (abc_instanceCheck(instance) == ABC_OK)
   {
      *mode = abc_data[instance].mode;
      if (*mode == 1)
      {
         pdqAction(*abc_data[instance].device);
         abc_data[instance].mode = 0;
      }
      result = ABC_OK;
   }
   return (result);
}

(b) 
/* Name: abcMessage.c       */
/* Description:             */
/* Developer:               */

#include abc.h
#include abc_appSpec.h
#include abc_utilities.h
#include abc_map.h

/*** External Functions ***/
int abcMessageSend(int instance, int message)
{
   int result = ABC_ERROR;
   if (abc_instanceCheck(instance) == ABC_OK)
   {
      if (abc_messageCheck(message) == ABC_OK)
      {
         *abc_data[instance].device = message;
         result = ABC_OK;
      }
   }
   return (result);
}

(c) 
/* Name: abc.h          */
/* Description:         */
/* Developer:           */

#define ABC_ERROR       1
#define ABC_OK          0

#define ABC_MESSAGE_1   1
#define ABC_MESSAGE_2   2

int abcInit(void);
int abcModeGet(int instance, int *mode);
int abcMessageSend(int instance, int message);

(d) 
/* Name: abc_utilities.c   */
/* Description:            */
/* Developer:              */

#include abc_utilities.h
#include abc_appSpec.h
#include abc_map.h

/*** Internal Functions ***/
int abc_instanceCheck(int instance)
{
   int result = ABC_ERROR;
   if (instance < ABC_INSTANCE)
   {
      result = ABC_OK;
   }
   return (result);
}

/*** ***/
int abc_messageCheck(int message)
{
   int result = ABC_ERROR;
   if (message == ABC_MESSAGE_1 || message == ABC_MESSAGE_2)
   {
      result = ABC_OK;
   }
   return (result);
}

(e) 
/* Name: abc_utilities.h        */
/* Description:                 */
/* Developer:                   */

/*** Internal Functions ***/
int abc_instanceCheck(int instance);
int abc_messageCheck(int message);

(f) 
/* Name: abc_task.c     */
/* Description:         */
/* Developer:           */

#include abc_task.h
#include abc_appSpec.h
#include abc_map.h
#include rtos.h         /* prototype for rtosPause() */

/*** Internal Functions ***/
int abc_task()
{
   int instance = 0;

   for(;;)
   {
      rtosPause(ABC_PAUSE);
      if (*abc_data[instance].device != 0)
      {
         abc_data[instance].mode = 1;
      }
      instance++;
      if (instance >= ABC_INSTANCE)
      {
         instance = 0;
      }
   }
}

(g) 
/* Name: abc_task.h     */
/* Description:         */
/* Developer:           */

/*** Internal Functions ***/
int abc_task(void);

(h) 
/* Name: abc_map.h      */
/* Description:         */
/* Developer:           */

/*** Protected Data             ***/
typedef
{
   int mode;
   int *device;
}abc_struct

extern abc_struct abc_data[ABC_INSTANCES];

(i)  
/* Name: abc_appSpec..h    */
/* Description:            */
/* Developer:              */

#define ABC_INSTANCES      10
#define ABC_BASE_ADDRESS   0x1230
#define ABC_IRQ            7
#define ABC_PRIORITY       5
#define ABC_PAUSE          100 /* 1 second */




10

