📄 common.c
字号:
/* Common Routines */
#include <stdio.h>
#include "common.h"
#include "ZTypes.h"
#include "ZSysgen.h"
#include "ZThread.h"
#include "ZMessageQ.h"
#include "EtherMgr.h"
//Added for CR#5128 -Start
extern UINT16 IP_MQ_SIZE ;
extern UINT8 IP_Message_Buff[] ;
RZK_MESSAGEQHANDLE_t rxQueueHandle ; /* receive queue handle */
INT _interface_init(void)
{
/* MQ for PKT Rx Can be used by all the interfaces */
rxQueueHandle = RZKCreateQueue( (RZK_NAME_t*)"IP_Q",
IP_MQ_SIZE, IP_Message_Buff,
3, RECV_ORDER_FIFO ) ;
if( rxQueueHandle == NULL )
{
return -1 ;
}
return 0 ;
}
//Added for CR#5128 -End
/* Array to store the incoming packets */
extern PKT_BUFF_t ipRxBuff[] ; /* Statically allocated buffer */
extern UINT MAX_IP_RX_BUFF ;
/*****************************************************************************/
/********Rx Memory management routines *************/
void * AllocPktBuff(void)
{
/* Assuming this call is made from only Rx interrupt thread context
therefore reentrancy issues may not arise. Thus code is not protected */
UINT8 count = 0 ;
PKT_BUFF_t *buffptr = ipRxBuff ;
while(1)
{
if(!buffptr->status)
{
buffptr->status = Rx_BUFF_ALLOCATED ;
return &buffptr->pktBuff ;
}
else
buffptr++ ;
if(++count>=(UINT8)MAX_IP_RX_BUFF)
return NULL ;
}
}
void FreePktBuff(void *ptr)
{
((PKT_BUFF_t* )(((INT8*)ipRxBuff + ((INT8*)ptr - (INT8*)ipRxBuff))-1))->status = Rx_BUFF_FREE ;
}
/*****************************************************************************/
/*****************************************************************************/
/****** Queue management routines *****************/
void PutToQueue(QUEUE_REF_t *refnode, QUEUE_NODE_t *node)
{
node->next = ( QUEUE_NODE_t * ) NULL; // IAR changed
node->previous = refnode->tail;
if( refnode->tail == NULL )
{
refnode->head = node;
refnode->tail = node;
}
else
{
refnode->tail->next = node;
refnode->tail = node;
}
}
QUEUE_NODE_t *GetFromQueue(QUEUE_REF_t * refnode)
{
QUEUE_NODE_t * node ;
node = refnode->head ;
if(node)
{
if(refnode->head != refnode->tail)
{
refnode->head = node->next ;
refnode->head->previous = ( QUEUE_NODE_t * ) NULL ; // IAR changed
}
else
{
refnode->head = ( QUEUE_NODE_t * ) NULL ; // IAR changed
refnode->tail = ( QUEUE_NODE_t * ) NULL ; // IAR changed
}
}
return node ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -