RTOS Expt 5 - Mailbox - UME2021922
RTOS Expt 5 - Mailbox - UME2021922
CODE:
/****************************************************************************************
* uCos-II Multitasking Application Code
*****************************************************************************************
*
* Program Name :
* Description : This program creates total four uCos-II tasks; out of which
* main task acts as a parent task and create three child tasks
*
*
* MicroEmbedded Technologies
* Processor : NXP LPC2148
* Board : Micro-A748
*
****************************************************************************************/
#include <includes.h>
#include "func.h"
/***************************************************************************************
* AppTaskStart()
*
* Description : The startup task. The uC/OS-II ticker should only be initialize once multitasking
starts.
*
* Argument(s) : p_arg Argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Note(s) : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is
not
* used. The compiler should not generate any code for this
* statement.
*
* (2) Interrupts are enabled by uCoss-II once the task starts because
* main() has disbled it.
****************************************************************************************/
while(DEF_TRUE)
{
printf(" \r\nMAIN TASK: Created 3 Tasks. Now going to deep sleep...");
printf(" \r\n======================================================");
OSTimeDlyHMSM(1, 0, 0, 0);
}
}
/*
*********************************************************************************************************
* AppTaskCreate()
*
* Description : Create the application tasks.
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
static void AppTaskCreate (void)
{
/* Create User Tasks */
/* Example: OSTaskCreate(AppTask0, // Name of Task
(void *)0, // Pointer to arguments for task execution
(OS_STK *)&AppTask0stk[APP_TASK_STK_SIZE - 1], // Pointer to top-of-stack of
the assigned stack
APP_TASK0_PRIO ); */ // Task priority
OSTaskCreate(AppTask0, // Name of Task
(void *)0, // Pointer to arguments for task execution
(OS_STK *)&AppTask0stk[APP_TASK_STK_SIZE - 1], // Pointer to top-of-stack of
the assigned stack
APP_TASK0_PRIO );
/*******************************************************************************************
* TASK-0 : AppTask0()
*
* Description :
*
* Argument(s) : p_arg Argument passed to 'AppTask0()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Note(s) : (1) The first line of code is used to prevent a compiler warning
* because 'p_arg' is not used. The compiler should not generate
* any code for this statement.
****************************************************************************************/
static void AppTask0 (void *p_arg)
{
p_arg = p_arg; /*Just to avoid compiler Warning */
unsigned char msg[20], temp;
unsigned int i;
while(DEF_TRUE)
{
printf("TASK0: Send a message to TASK0\n\r");
OSTimeDlyHMSM(0,0,0,500);
printf("TASK0:Enter a message from PC keyboard \n\r");
for( i=0;i<16;i++){
temp = UART_GetChar();
if(temp == 0x0D)
break;
UART_PutChar(temp);
msg[i] = temp;
}
msg[i]='\0';
while(UART_GetChar()!=0X0A);
}
}
/*******************************************************************************************
* TASK-1 : AppTask1()
*
* Description :
*
* Argument(s) : p_arg Argument passed to 'AppTask1()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Note(s) : (1) The first line of code is used to prevent a compiler warning
* because 'p_arg' is not used. The compiler should not generate
* any code for this statement.
****************************************************************************************/
while(DEF_TRUE)
{
printf("TASK1: Waiting for message from mailbox \n\r");
msg=(unsigned char*)OSMboxPend(TxMbox,0,&err);
printf("TASK1: message received \n\r\n\r");
LCD_cmd(0x01);
LCD_display(1,1,msg);
OSTimeDlyHMSM(0,0,1,0);
}
}
/*******************************************************************************************
* TASK-2 : AppTask2()
*
* Description :
*
* Argument(s) : p_arg Argument passed to 'AppTask2()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Note(s) : (1) The first line of code is used to prevent a compiler warning
* because 'p_arg' is not used. The compiler should not generate
* any code for this statement.
****************************************************************************************/
while(DEF_TRUE)
{
/* User Code Here */
}
}
/*
*********************************************************************************************************
*********************************************************************************************************
** uC/OS-II APP HOOKS
** (PLEASE IGONRE THE CODE BELOW)
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* TASK DELETION HOOK (APPLICATION)
*
* Description : This function is called when a task is deleted.
*
* Argument(s) : ptcb is a pointer to the task control block of the task being deleted.
*
* Note(s) : (1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* STATISTIC TASK HOOK (APPLICATION)
*
* Description : This function is called by OSTaskStatHook(), which is called every second by
uC/OS-II's
* statistics task. This allows your application to add functionality to the statistics task.
*
* Argument(s) : none.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* TASK SWITCH HOOK (APPLICATION)
*
* Description : This function is called when a task switch is performed. This allows you to
perform other
* operations during a context switch.
*
* Argument(s) : none.
*
* Note(s) : (1) Interrupts are disabled during this call.
*
* (2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the
task that
* will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
* task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* OS_TCBInit() HOOK (APPLICATION)
*
* Description : This function is called by OSTCBInitHook(), which is called by OS_TCBInit() after
setting
* up most of the TCB.
*
* Argument(s) : ptcb is a pointer to the TCB of the task being created.
*
* Note(s) : (1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* TICK HOOK (APPLICATION)
*
* Description : This function is called every tick.
*
* Argument(s) : none.
*
* Note(s) : (1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
OUTPUT: