Page 1 of 1

Application Define

PostPosted: Thu Feb 16, 2006 10:01 am
by zoomcityzoom
Here's a useful way to consolidate the definition and creation of your Salvo environment.

code:

#include "os_define_types.h"

#ifdef OS_USE_SEMAPHORE
#undef OS_USE_SEMAPHORE
#endif

#ifdef OS_USE_BINARY_SEMAPHORE
#undef OS_USE_BINARY_SEMAPHORE
#endif

#ifdef OS_USE_CYCLIC_TIMER
#undef OS_USE_CYCLIC_TIMER
#endif

#ifdef OS_USE_EVENT_FLAG
#undef OS_USE_EVENT_FLAG
#endif

#ifdef OS_USE_MESSAGE
#undef OS_USE_MESSAGE
#endif

#ifdef OS_USE_MESSAGE_QUEUE
#undef OS_USE_MESSAGE_QUEUE
#endif


/* Define the Salvo objects that you use
*/
#define OS_USE_BINARY_SEMAPHORE
#define OS_USE_EVENT_FLAG
#define OS_USE_MESSAGE


/*********************************************************************************
*
* Define Tasks
*
*********************************************************************************
*/
os_task_create_t os_task_create_array[] = {
{ TWI_Master_Task, TWI_MASTER_TASK_P, 4 },
{ Application_Start_Task, APPLICATION_START_TASK_P, 5 },
};


/*********************************************************************************
*
* Define Binary Semaphores
*
*********************************************************************************
*/
#ifdef OS_USE_BINARY_SEMAPHORE
os_binsem_create_t os_binsem_create_array[] = {
{ TWI_INT_BINSEM_P, 0 },
{ TWI_LOCK_BINSEM_P, 1 },
{ TWI_LCD_BINSEM_P, 0},
{ TWI_QWHEEL_BINSEM_P, 0},
{ TWI_UI_POWER_BINSEM_P, 0},
{ TWI_RTC_BINSEM_P, 0},
};
#endif


/*********************************************************************************
*
* Define Cyclic Timers
*
*********************************************************************************
*/
#ifdef OS_USE_CYCLIC_TIMER
os_cyctmr_create_t os_cyctmr_create_array[] = {
};
#endif


/*********************************************************************************
*
* Define Event Flags
*
*********************************************************************************
*/
#ifdef OS_USE_EVENT_FLAG
os_eflag_create_t os_eflag_create_array[] = {
{ BIRTH_EFLAG_P, BIRTH_EFLAG_CB_P, (OStypeEFlag) 0 },

};
#endif


/*********************************************************************************
*
* Define Messages
*
*********************************************************************************
*/
#ifdef OS_USE_MESSAGE
os_msg_create_t os_msg_create_array[] = {
{ TWI_MESSAGE_P, (OStypeMsgP) 0 },
};
#endif


/*********************************************************************************
*
* Define Message Queues
*
*********************************************************************************
*/
#ifdef OS_USE_MESSAGE_QUEUE
os_msgq_create_t os_msgq_create_array[] = {
};
#endif


/*********************************************************************************
*
* Define Semaphores
*
*********************************************************************************
*/
#ifdef OS_USE_SEMAPHORE
os_sem_create_t os_sem_create_array[] = {
};
#endif


/*********************************************************************************
*
* Function: OSApplicationDefine()
*
* Description: Defines what the initial system looks like.
*
* Arguments: none
*
* Returns : none
*
*********************************************************************************
*/
void OSApplicationDefine(void)
{
uint8_t i, status;

#ifdef OS_USE_BINARY_SEMAPHORE
/* Create all binary semaphores using the initial values in the
* os_binsem_create_array
*/
for (i = 0; i < sizeof(os_binsem_create_array) / sizeof(os_binsem_create_array[0]); ++i) {
status = OSCreateBinSem(os_binsem_create_array[i].ecbP,
os_binsem_create_array[i].binSem);
if (status != OSNOERR)
goto tx_create_error;
}
#endif

#ifdef OS_USE_CYCLIC_TIMER
/* Create all cyclic timers using the initial values in the
* os_cyctmr_create_array
*/
for (i = 0; i < sizeof(os_cyctmr_create_array) / sizeof(os_cyctmr_create_array[0]); ++i) {
status = OSCreateCycTmr(os_cyctmr_create_array[i].tFP,
os_cyctmr_create_array[i].tcbP,
os_cyctmr_create_array[i].delay,
os_cyctmr_create_array[i].period,
os_cyctmr_create_array[i].mode);
if (status != OSNOERR)
goto tx_create_error;
}
#endif

#ifdef OS_USE_EVENT_FLAG
/* Create all event flags using the initial values in the
* os_eflag_create_array
*/
for (i = 0; i < sizeof(os_eflag_create_array) / sizeof(os_eflag_create_array[0]); ++i) {
status = OSCreateEFlag(os_eflag_create_array[i].ecbP,
os_eflag_create_array[i].efcbP,
os_eflag_create_array[i].eFlag);
if (status != OSNOERR)
goto tx_create_error;
}
#endif

#ifdef OS_USE_MESSAGE
/* Create all messages using the initial values in the
* os_msg_create_array
*/
for (i = 0; i < sizeof(os_msg_create_array) / sizeof(os_msg_create_array[0]); ++i) {
status = OSCreateMsg(os_msg_create_array[i].ecbP,
os_msg_create_array[i].msgP);
if (status != OSNOERR)
goto tx_create_error;
}
#endif

#ifdef OS_USE_MESSAGE_QUEUE
/* Create all messages using the initial values in the
* os_msgq_create_array
*/
for (i = 0; i < sizeof(os_msgq_create_array) / sizeof(os_msgq_create_array[0]); ++i) {
status = OSCreateMsgQ(os_msgq_create_array[i].ecbP,
os_msgq_create_array[i].mqcbP,
os_msgq_create_array[i].msgPP,
os_msgq_create_array[i].size);
if (status != OSNOERR)
goto tx_create_error;
}
#endif

#ifdef OS_USE_SEMAPHORE
/* Create all semaphores using the initial values in the
* os_sem_create_array
*/
for (i = 0; i < sizeof(os_sem_create_array) / sizeof(os_sem_create_array[0]); ++i) {
status = OSCreateMsg(os_sem_create_array[i].ecbP,
os_sem_create_array[i].sem);
if (status != OSNOERR)
goto tx_create_error;
}
#endif


/* Create all tasks using the initial values in the
* os_task_create_array
*/
for (i = 0; i < sizeof(os_task_create_array) / sizeof(os_task_create_array[0]); ++i) {
status = OSCreateTask(os_task_create_array[i].tFP,
os_task_create_array[i].tcbP,
os_task_create_array[i].prio);
if (status != OSNOERR)
goto tx_create_error;
}
return;

tx_create_error:
for (; ;);

}


You'll also need this header file.

code:

//================================================================================
//
// File: os_define_types.h
//
// Description: The following types are used in defining the OS services
// utilized for startup.
//
//
//================================================================================

#ifndef __OS_DEFINE_TYPES_H
#define __OS_DEFINE_TYPES_H


typedef struct os_task_create_s {
OStypeTFP tFP;
OStypeTcbP tcbP;
OStypePrio prio;
} os_task_create_t;

typedef struct os_binsem_create_s {
OStypeEcbP ecbP;
OStypeBinSem binSem;
} os_binsem_create_t;

typedef struct os_cyctmr_create_s {
OStypeTFP tFP;
OStypeTcbP tcbP;
OStypeDelay delay;
OStypeDelay period;
OStypeCTMode mode;
} os_cyctmr_create_t;

typedef struct os_eflag_create_s {
OStypeEcbP ecbP;
OStypeEfcbP efcbP;
OStypeEFlag eFlag;
} os_eflag_create_t;

typedef struct os_msg_create_s {
OStypeEcbP ecbP;
OStypeMsgP msgP;
} os_msg_create_t;

typedef struct os_msgq_create_s {
OStypeEcbP ecbP;
OStypeMqcbP mqcbP;
OStypeMsgQPP msgPP;
OStypeMsgQSize size;
} os_msgq_create_t;

typedef struct os_sem_create_s {
OStypeEcbP ecbP;
OStypeSem sem;
} os_sem_create_t;


#endif



In main() after OSInit() call OSApplicationDefine()

Enjoy!


[This message has been edited by zoomcityzoom (edited February 16, 2006).]

[This message has been edited by zoomcityzoom (edited February 16, 2006).]