📄 mbc.c
字号:
/*************************************************************************//* *//* Copyright Mentor Graphics Corporation 2002 *//* All Rights Reserved. *//* *//* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS *//* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS *//* SUBJECT TO LICENSE TERMS. *//* *//*************************************************************************//*************************************************************************//* *//* FILE NAME VERSION *//* *//* mbc.c Nucleus PLUS 1.14 *//* *//* COMPONENT *//* *//* MB - Mailbox Management *//* *//* DESCRIPTION *//* *//* This file contains the core routines for the Mailbox management *//* component. *//* *//* DATA STRUCTURES *//* *//* None *//* *//* FUNCTIONS *//* *//* MBC_Create_Mailbox Create a mailbox *//* MBC_Delete_Mailbox Delete a mailbox *//* MBC_Send_To_Mailbox Send a mailbox message *//* MBC_Receive_From_Mailbox Receive a mailbox message *//* MBC_Cleanup Cleanup on timeout or a *//* terminate condition *//* *//* DEPENDENCIES *//* *//* cs_extr.h Common Service functions *//* tc_extr.h Thread Control functions *//* mb_extr.h Mailbox functions *//* hi_extr.h History functions *//* *//* HISTORY *//* *//* DATE REMARKS *//* *//* 03-01-1993 Created initial version 1.0 *//* 04-19-1993 Verified version 1.0 *//* 08-09-1993 Corrected pointer retrieval *//* loop, resulting in version 1.0a *//* 08-09-1993 Verified version 1.0a *//* 03-01-1994 Moved non-core functions into *//* supplemental files, changed *//* function interfaces to match *//* those in prototype, added *//* register options, changed *//* protection logic to reduce *//* overhead, resulting in *//* version 1.1 *//* *//* 03-18-1994 Verified version 1.1 *//* 04-17-1996 updated to version 1.2 *//* 03-24-1998 Released version 1.3 *//* 03-26-1999 Released 1.11m (new release *//* numbering scheme) *//* 04-17-2002 Released version 1.13m *//* 11-07-2002 Released version 1.14 *//*************************************************************************/#define NU_SOURCE_FILE#include "cs_extr.h" /* Common service functions */#include "tc_extr.h" /* Thread control functions */#include "mb_extr.h" /* Mailbox functions */#include "hi_extr.h" /* History functions */#include "profiler.h" /* ProView interface *//* Define external inner-component global data references. */extern CS_NODE *MBD_Created_Mailboxes_List;extern UNSIGNED MBD_Total_Mailboxes;extern TC_PROTECT MBD_List_Protect;/* Define internal component function prototypes. */VOID MBC_Cleanup(VOID *information);/*************************************************************************//* *//* FUNCTION *//* *//* MBC_Create_Mailbox *//* *//* DESCRIPTION *//* *//* This function creates a mailbox and then places it on the list *//* of created mailboxes. *//* *//* CALLED BY *//* *//* Application *//* MBCE_Create_Mailbox Error checking shell *//* *//* CALLS *//* *//* CSC_Place_On_List Add node to linked-list *//* [HIC_Make_History_Entry] Make entry in history log *//* [TCT_Check_Stack] Stack checking function *//* TCT_Protect Data structure protect *//* TCT_Unprotect Un-protect data structure *//* *//* INPUTS *//* *//* mailbox_ptr Mailbox control block pointer*//* name Mailbox name *//* suspend_type Suspension type *//* *//* OUTPUTS *//* *//* NU_SUCCESS *//* *//* HISTORY *//* *//* DATE REMARKS *//* *//* 03-01-1993 Created initial version 1.0 *//* 04-19-1993 Verified version 1.0 *//* 03-01-1994 Changed function interface to *//* match the prototype, added *//* register variable logic, *//* resulting in version 1.1 *//* *//* 03-18-1994 Verified version 1.1 *//* *//*************************************************************************/STATUS MBC_Create_Mailbox(NU_MAILBOX *mailbox_ptr, CHAR *name, OPTION suspend_type){R1 MB_MCB *mailbox; /* Mailbox control block ptr */INT i; /* Working index variable */NU_SUPERV_USER_VARIABLES /* Switch to supervisor mode */ NU_SUPERVISOR_MODE(); /* Move input mailbox pointer into internal pointer. */ mailbox = (MB_MCB *) mailbox_ptr;#ifdef NU_ENABLE_STACK_CHECK /* Call stack checking function to check for an overflow condition. */ TCT_Check_Stack();#endif#ifdef NU_ENABLE_HISTORY /* Make an entry that corresponds to this function in the system history log. */ HIC_Make_History_Entry(NU_CREATE_MAILBOX_ID, (UNSIGNED) mailbox, (UNSIGNED) name, (UNSIGNED) suspend_type);#endif /* First, clear the mailbox ID just in case it is an old Mailbox Control Block. */ mailbox -> mb_id = 0; /* Fill in the mailbox name. */ for (i = 0; i < NU_MAX_NAME; i++) mailbox -> mb_name[i] = name[i]; /* Clear the message present flag- initial it to "no message present." */ mailbox -> mb_message_present = NU_FALSE; /* Setup the mailbox suspension type. */ if (suspend_type == NU_FIFO) /* FIFO suspension is selected, setup the flag accordingly. */ mailbox -> mb_fifo_suspend = NU_TRUE; else /* Priority suspension is selected. */ mailbox -> mb_fifo_suspend = NU_FALSE; /* Clear the suspension list pointer. */ mailbox -> mb_suspension_list = NU_NULL; /* Clear the number of tasks waiting on the mailbox counter. */ mailbox -> mb_tasks_waiting = 0; /* Initialize link pointers. */ mailbox -> mb_created.cs_previous = NU_NULL; mailbox -> mb_created.cs_next = NU_NULL; /* Protect against access to the list of created mailboxes. */ TCT_Protect(&MBD_List_Protect); /* At this point the mailbox is completely built. The ID can now be set and it can be linked into the created mailbox list. */ mailbox -> mb_id = MB_MAILBOX_ID; /* Link the mailbox into the list of created mailboxes and increment the total number of mailboxes in the system. */ CSC_Place_On_List(&MBD_Created_Mailboxes_List, &(mailbox -> mb_created)); MBD_Total_Mailboxes++;#ifdef INCLUDE_PROVIEW _RTProf_DumpMailBox(RT_PROF_CREATE_MAILBOX,mailbox,RT_PROF_OK);#endif /* INCLUDE_PROVIEW */ /* Release protection against access to the list of created mailboxes. */ TCT_Unprotect(); /* Return to user mode */ NU_USER_MODE(); /* Return successful completion. */ return(NU_SUCCESS);}/*************************************************************************//* *//* FUNCTION *//* *//* MBC_Delete_Mailbox *//* *//* DESCRIPTION *//* *//* This function deletes a mailbox and removes it from the list of *//* created mailboxes. All tasks suspended on the mailbox are *//* resumed. Note that this function does not free the memory *//* associated with the mailbox control block. *//* *//* CALLED BY *//* *//* Application *//* MBCE_Delete_Mailbox Error checking shell *//* *//* CALLS *//* *//* CSC_Remove_From_List Remove node from list */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -