📄 msgsystem.h
字号:
/************************************************************************************
* This header file is provided as part of the interface to the Freescale 802.15.4
* MAC and PHY layer.
*
* The file covers the interface to the Memory and Message Manager..
*
* Author(s): BPPED1
*
* (c) Copyright 2005, Freescale, Inc. All rights reserved.
*
* Freescale Confidential Proprietary
* Digianswer Confidential
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale.
*
************************************************************************************/
#ifndef _MSG_SYSTEM_H_
#define _MSG_SYSTEM_H_
#include "NwkMacInterface.h"
#include "AppToMacPhyConfig.h"
#include "FunctionLib.h"
/************************************************************************************
*************************************************************************************
* Public macros - see description of functionality in the public prototypes section.
*************************************************************************************
************************************************************************************/
// Free a message
#define MSG_Free(msg) MM_Free(msg)
// Put a message in a queue at the head.
#define MSG_QueueHead(anchor, element) List_AddHead((anchor), (element))
// Get a message from a queue. Returns NULL if no messages in queue.
#define MSG_DeQueue(anchor) List_RemoveHead(anchor)
// Check if a message is pending in a queue. Returns
// TRUE if any pending messages, and FALSE otherwise.
#define MSG_Pending(anchor) ((anchor)->pHead != 0)
#define MSG_InitQueue(anchor) List_ClearAnchor(anchor)
// Allocate a message of a certain type
#define MSG_AllocType(type) MM_Alloc(sizeof(type))
// Allocate a message of a certain size
#define MSG_Alloc(size) MM_Alloc(size)
// Put a message in a queue.
#define MSG_Queue(anchor, element) List_AddTail((anchor), (element))
// Sending a message is equal to calling a Service Access Point function
// If the sap argument is e.g. MLME, then a function called MLME_SapHandler
// must exist that takes a message pointer as argument.
#define MSG_Send(sap, msg) (sap##_SapHandler((void *)(msg)))
/************************************************************************************
*************************************************************************************
* Public type definitions
*************************************************************************************
************************************************************************************/
// This struct is used privately but must be declared
// here in order for the anchor_t struct to work.
// The struct is used in memory blocks for linking them
// in single chained lists. The struct is embedded in
// list elements, and transparent to the user.
typedef struct listHeader_tag {
struct listHeader_tag *pNext;
struct pools_tag *pParentPool;
} listHeader_t;
// List anchor with head and tail elements. Used
// for both memory pools and message queues.
typedef struct anchor_tag {
listHeader_t *pHead;
listHeader_t *pTail;
} anchor_t, msgQueue_t;
// Buffer pool handle. An array of this type is filled
// in by MM_Init(), and used by MM_AllocPool().
typedef struct pools_tag {
anchor_t anchor; // MUST be first element in pools_t struct
uint8_t nextBlockSize;
uint8_t blockSize;
} pools_t;
// Buffer pool description. Used by MM_Init()
// for creating the buffer pools.
typedef struct poolInfo_tag {
uint8_t poolSize;
uint8_t blockSize;
uint8_t nextBlockSize;
} poolInfo_t;
/************************************************************************************
*************************************************************************************
* Public prototypes
*************************************************************************************
************************************************************************************/
/************************************************************************************
* Allocate a block from the specified memory pool. The function uses the size
* argument to look up a pool with adequate block sizes.
*
* Interface assumptions:
* None
*
* Return value:
* Pointer to the allocated memory block or NULL if no blocks available.
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 160305 BPP Created
*
************************************************************************************/
void *MM_AllocPool
(
pools_t *pPools, // IN: Pool array to allocate from
uint8_t numBytes // IN: Minimum number of bytes to allocate
);
/************************************************************************************
* Allocate a block from the MAC memory pool. The function uses the size argument to
* look up a pool with adequate block sizes.
*
* Interface assumptions:
* None
*
* Return value:
* Pointer to the allocated memory block or NULL if no blocks available.
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 311003 BPP Created
*
************************************************************************************/
void *MM_Alloc
(
uint8_t numBytes // IN: Minimum number of bytes to allocate
);
/************************************************************************************
* Deallocate a memory block by putting it in the corresponding pool of free blocks.
*
* Interface assumptions:
* None
*
* Return value:
* None.
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 311003 BPP Created
*
************************************************************************************/
void MM_Free
(
void *pBlock // IN: Block of memory to free
);
/************************************************************************************
* This function initializes the message module private variables. Must be
* called at boot time, or if device is reset. Currently the module supports
* up to 4 memory pools, but pools may be added or removed. The following
* constants control the memory pool layout:
*
* gMmPoolSize0_c, gMmBlockSize0_c
* gMmPoolSize1_c, gMmBlockSize1_c
* gMmPoolSize2_c, gMmBlockSize2_c
* gMmPoolSize3_c, gMmBlockSize3_c
*
* The gMmPoolSize*_c constants determine the number of blocks in a pool, and
* gMmBlockSize*_c is the number of bytes in each block for the corresponding pool.
* The number of bytes is rounded up to a value so that each block is aligned to
* a machine dependant boundary in order to avoid bus errors during pool access.
*
* The total amount of heap required is given by the constant mMmTotalPoolSize_c.
*
* Interface assumptions:
* None
*
* Return value:
* None
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 311003 BPP Created
*
************************************************************************************/
void MM_Init
(
uint8_t *pHeap, // IN: Memory heap. Caller must be sure to make this big enough
const poolInfo_t *pPoolInfo, // IN: Memory layout information
pools_t *pPools // OUT: Will be initialized with requested memory pools.
);
/************************************************************************************
* This function can be used to add a memory block to the specified pool during
* runtime. The following example shows how to add two buffers to the MAC buffer
* pool:
*
* // Declare an array with two buffers
* uint8_t myExtraMacBuffers[2][sizeof(listHeader_t) + gMaxPacketBufferSize_c];
* // Get a pointer to the MAC pools. The size must be correct.
* pools_t *macDataBufferPool = MM_GetMacPool(gMaxPacketBufferSize_c);
* // Add the two extra buffers to the MAC buffer pool.
* MM_AddToPool(macDataBufferPool, myExtraMacBuffers[0]);
* MM_AddToPool(macDataBufferPool, myExtraMacBuffers[1]);
*
* Interface assumptions:
* None
*
* Return value:
* None
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 260405 BPP Created
*
************************************************************************************/
void MM_AddToPool
(
pools_t *pPool,
void *pBlock
);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -