📄 queue.c
字号:
/**
***************************Start of Header ************************************/
/* Larsen & Toubro Limited, Emsys Division, Powai , MUMBAI,INDIA
*
* Proprietary.
* This code and all features are proprietary to L & T Emsys.
* It shall not be used in any manner detrimental to L &T Emsys
* interests and shall be returned upon request.
Purpose of File: Implements Circular Buffer. Used to store sniffed data with time stamp.
Other files required to build the entire software
with path (and with a brief description of each
file) or Give ref. to a separate file containing
these build files e.g., Compile.doc :
Compiling and linking information (Also refer to
linker file path) Or Give ref. to a separate file
Containing these build files e.g.,Compile.doc :
/**
*******************************************************************************
* Revision History
/*********************************************************************************
* Date ID-DLD/ Revision Description Author
MANTISID/
CR#
**********************************************************************************
* 25-9-2007 1 Initial version SAUD
********************************************************************************/
/**
************************End of Header *****************************************/
#include <lpc22xx.h>
#include <string.h>
#include "tcpip.h"
#include "Queue.h"
#include "interrupt.h"
#include "timer.h"
#include <stdio.h>
/**
**********************Globals********************************************/
CircularBuffDataType g_iCircularBuffer[MAX_CB_SIZE][MAX_ELEMENT_SIZE];
//! Circular Buffer Pointer.
/*! The Circular Buffer Pointer CircularBuffPtr has two members
int value m_uiReadPtr and int value m_uiWritePtr */
typedef struct CircularBuffPtr
{
unsigned int m_uiReadPtr; /*!< unsigned int value m_uiReadPtr */
unsigned int m_uiWritePtr; /*!< unsigned int value m_uiWritePtr */
} CircularBuffPtr;
unsigned int g_uiQueueStatus; /*!< int value g_uiQueueStatus */
unsigned int g_uiLoop; /*!< int value g_uiLoop */
static CircularBuffPtr g_stCBPtr; /*!< CircularBuffPtr value g_stCBPtr */
/** To do :Add #defines,Error handling for queue full,*/
/********************************************************************************
Module Name: InitialiseBuffers
Module ID:
Purpose: Initialise all the circular buffers
Author: Saud
Date Written: 25-9-07
********************************************************************************/
void InitialiseBuffers()
{
g_stCBPtr.m_uiReadPtr = g_stCBPtr.m_uiWritePtr = 0;
g_uiQueueStatus = BUFFER_EMPTY;
}
/**
******************************************************************************
Module Name: ReadData
Module ID:
Purpose: Read SPI sniff data from the circular buffer into transmit buffer
Author: Saud
Date Written: 25-9-07
********************************************************************************/
#if 0
void memcpy1(unsigned short *src,unsigned int *des,unsigned char count)
{
while(count--)
*(unsigned short *)src++=*(unsigned short *)des++;
}
#endif
unsigned int ReadData()
{
unsigned int iLoop, iLoop1, iTemp, iTemp1;
iLoop = 0;
// Buffer empty
if(g_stCBPtr.m_uiReadPtr != g_stCBPtr.m_uiWritePtr)
{
// Loop till maximum size of TCP Buffer is reached.
for(iLoop = 0; iLoop < MAX_ELEMENT_TCP_BUFFER; iLoop ++ )
{
iTemp1 = g_stCBPtr.m_uiReadPtr * MAX_ELEMENT_SIZE_BYTES;
iLoop1 = iLoop * MAX_ELEMENT_SIZE_BYTES;
// Read data from circular buffer into Transmit TCP Buffer
memcpy((TCP_TX_BUF+iLoop1),((unsigned char *)g_iCircularBuffer+iTemp1),20); // MAX_ELEMENT_SIZE_BYTES
// Increment Read Pointer
g_stCBPtr.m_uiReadPtr++;
// Set read pointer to 0. Circular Buffer implementation
if(g_stCBPtr.m_uiReadPtr >= MAX_CB_SIZE)
{
g_stCBPtr.m_uiReadPtr = 0;
}
// If number of data available is less than TCP Buffer size then exit
if(g_stCBPtr.m_uiReadPtr == g_stCBPtr.m_uiWritePtr)
{
iLoop ++;
break;
}
}
// Check amount of data available in circular buffer
iTemp = (g_stCBPtr.m_uiWritePtr - g_stCBPtr.m_uiReadPtr + MAX_CB_SIZE) % MAX_CB_SIZE;
// Check if buffer is empty
if( iTemp == 0 )
g_uiQueueStatus = BUFFER_EMPTY;
// Check if buffer more than half full
else if(iTemp >MAX_CB_SIZE /2 )
g_uiQueueStatus = BUFFER_READY_TO_SEND;
// Buffer is less than half filled.
else
g_uiQueueStatus = BUFFER_AVAILABLE;
return iLoop * MAX_ELEMENT_SIZE_BYTES;
}
else
{ // Set status as Buffer is empty;
g_uiQueueStatus = BUFFER_EMPTY;
return BUFFER_EMPTY;
}
}
/**
******************************************************************************
Module Name: WriteSPIData
Module ID:
Purpose: Write SPI sniffed data into circular buffer
Author: Saud
Date Written: 25-9-07
********************************************************************************/
extern __inline void WriteData() //unsigned short ISR_Name,unsigned short data)
{
// Check if Buffer is full
if(g_stCBPtr.m_uiReadPtr != ((g_stCBPtr.m_uiWritePtr + 1))% MAX_CB_SIZE)
{
g_iCircularBuffer[g_stCBPtr.m_uiWritePtr][0] = T1TC;
g_iCircularBuffer[g_stCBPtr.m_uiWritePtr][1] = T1TC>>16; // Modified Approach 3
// g_iCircularBuffer[g_stCBPtr.m_uiWritePtr][2] = 0;//(CTIME0&MASKSEC);
g_iCircularBuffer[g_stCBPtr.m_uiWritePtr][3] = g_uiMinute;//(CTIME0&MASKMIN)>>8; // Modified Approach 3
g_iCircularBuffer[g_stCBPtr.m_uiWritePtr][4] = g_uiHour;
// g_iCircularBuffer[g_stCBPtr.m_uiWritePtr][5] = 0; //month
// g_iCircularBuffer[g_stCBPtr.m_uiWritePtr][6] = 0; //year
g_iCircularBuffer[g_stCBPtr.m_uiWritePtr][7] = ADDR;
g_iCircularBuffer[g_stCBPtr.m_uiWritePtr][8] = g_ISR_Name; //
g_iCircularBuffer[g_stCBPtr.m_uiWritePtr][9] = g_data; // 0x01;//S1SPDR;
g_stCBPtr.m_uiWritePtr = (g_stCBPtr.m_uiWritePtr+ 1)%MAX_CB_SIZE;
#if 0
g_uiLoop = (g_stCBPtr.m_uiWritePtr - g_stCBPtr.m_uiReadPtr + MAX_CB_SIZE) % MAX_CB_SIZE;
// Check if buffer is more than half filled
if(g_uiLoop >= (MAX_CB_SIZE / 200))
g_uiQueueStatus = BUFFER_READY_TO_SEND;
else
// Buffer is less than half filled.
g_uiQueueStatus = BUFFER_AVAILABLE;
#endif
}
else
{
// set status as Buffer full
g_uiQueueStatus = BUFFER_FULL;
InitialiseBuffers();
//return BUFFER_FULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -