?? iekc64_ser.h
字號:
#ifndef _SER_H_
#define _SER_H_
#include <csl_stdinc.h>
#include <csl_mcbsp.h>
#include <csl_edma.h>
#include "iekc64.h"
#include "iekc64_error.h"
#ifdef __cplusplus
extern "C" {
#endif
/*=======================================================================*//*!
\defgroup SER SER - Serial ports manager
\brief This module provides an unified API for serial port : McBSP.
<b> How does it work </b>
The SER - MCBSP module acquires frame according to the configuration defined
in IEKC64_SER structure.
<b> Openning the module</b>
You open the module by calling the SER_open() function. This function
initializes the hardware and the software with the parameters given in the
IEKC64_SER structure that you must fill before the call.
For MCBSP, the parameter FALSE for ConfigMode means that you will use default
configuration structure provided by the library.
The default configuration structure field description is:
<small>
SPCR =
\li MCBSP_SPCR_FREE_YES
\li MCBSP_SPCR_SOFT_NO
\li MCBSP_SPCR_FRST_NO
\li MCBSP_SPCR_GRST_NO
\li MCBSP_SPCR_XINTM_XRDY
\li MCBSP_SPCR_XSYNCERR_NO
\li MCBSP_SPCR_XRST_NO
\li MCBSP_SPCR_DLB_OFF
\li MCBSP_SPCR_RJUST_RZF
\li MCBSP_SPCR_CLKSTP_DISABLE
\li MCBSP_SPCR_DXENA_OFF
\li MCBSP_SPCR_RINTM_RRDY
\li MCBSP_SPCR_RSYNCERR_NO
RCR =
\li MCBSP_RCR_RPHASE_SINGLE
\li MCBSP_RCR_RFRLEN2_OF(0)
\li MCBSP_RCR_RWDLEN2_8BIT //Don't care about, we don't use phase
\li MCBSP_RCR_RCOMPAND_MSB
\li MCBSP_RCR_RFIG_YES
\li MCBSP_RCR_RDATDLY_1BIT
\li MCBSP_RCR_RFRLEN1_OF(0)
\li MCBSP_RCR_RWDLEN1_32BIT
\li MCBSP_RCR_RWDREVRS_DISABLE
XCR =
\li MCBSP_XCR_XPHASE_SINGLE
\li MCBSP_XCR_XFRLEN2_OF(0)
\li MCBSP_XCR_XWDLEN2_8BIT // Not using Phase
\li MCBSP_XCR_XCOMPAND_MSB
\li MCBSP_XCR_XFIG_YES
\li MCBSP_XCR_XDATDLY_1BIT
\li MCBSP_XCR_XFRLEN1_OF(0)
\li MCBSP_XCR_XWDLEN1_32BIT
\li MCBSP_XCR_XWDREVRS_DISABLE
SRGR =
\li MCBSP_SRGR_GSYNC_FREE
\li MCBSP_SRGR_CLKSP_RISING
\li MCBSP_SRGR_CLKSM_INTERNAL
\li MCBSP_SRGR_FSGM_DXR2XSR
\li MCBSP_SRGR_FPER_OF(0)
\li MCBSP_SRGR_FWID_OF(0)
\li MCBSP_SRGR_CLKGDV_OF(7)
MCR = MCBSP_MCR_OF(0)
RCERE0 = MCBSP_RCERE0_DEFAULT
RCERE1 = MCBSP_RCERE1_DEFAULT
RCERE2 = MCBSP_RCERE2_DEFAULT
RCERE3 = MCBSP_RCERE3_DEFAULT
XCERE0 = MCBSP_XCERE0_DEFAULT
XCERE1 = MCBSP_XCERE1_DEFAULT
XCERE2 = MCBSP_XCERE2_DEFAULT
XCERE3 = MCBSP_XCERE3_DEFAULT
PCR =
\li MCBSP_PCR_XIOEN_SP
\li MCBSP_PCR_RIOEN_SP
\li MCBSP_PCR_FSXM_INTERNAL
\li MCBSP_PCR_FSRM_EXTERNAL
\li MCBSP_PCR_CLKXM_OUTPUT
\li MCBSP_PCR_CLKRM_INPUT
\li MCBSP_PCR_CLKSSTAT_0
\li MCBSP_PCR_DXSTAT_0
\li MCBSP_PCR_FSXP_DEFAULT
\li MCBSP_PCR_FSRP_ACTIVEHIGH
\li MCBSP_PCR_CLKXP_RISING
\li MCBSP_PCR_CLKRP_FALLING
dwReceiveEdmaPri = EDMA_OPT_PRI_LOW
dwTransmitEdmaPri =EDMA_OPT_PRI_LOW
</small>
<b> Start serial acquisition/restitution </b>
You start the module by calling the SER_start() function. This function
starts EDMA and interrupt management.
<b> Getting a frame</b>
SER_receive() gives the next frame pointer from the input buffer.
If no new frame is avalable, depending on the timeout value, you will
get an error or wait until the timeout ends or a new frame is captured
<b> Sending a frame</b>
SER_send() sends the current frame pointer to output.
<b> Stop MCBSP </b>
SER_stop() will allow the serial acquisition/restitution to be paused. After a
SER_stop, acquisition/restitution can be re-started with the same parameters
with SER_start().
<b> Close MCBSP </b>
SER_free() closes all channel and interupt used with the MCBSP serial communication
</P>*//*==============================================================*//*@{*/
/*--------------------------------------------------------------------------*/
/*! Defines the MCBSP configuration used for acquisition and restitution
*/
typedef struct
{
/*! Serial port control register value */
Uint32 spcr;
/*! Receive control register value */
Uint32 rcr;
/*! Transmit control register value */
Uint32 xcr;
/*! Sample rate generator register value */
Uint32 srgr;
/*! Multichannel control register value */
Uint32 mcr;
/*! Enhanced receive channel 0 enable register value */
Uint32 rcere0;
/*! Enhanced receive channel 1 enable register value */
Uint32 rcere1;
/*! Enhanced receive channel 2 enable register value */
Uint32 rcere2;
/*! Enhanced receive channel 3 enable register value */
Uint32 rcere3;
/*! Enhanced transmit channel 0 enable register value */
Uint32 xcere0;
/*! Enhanced transmit channel 1 enable register value */
Uint32 xcere1;
/*! Enhanced transmit channel 2 enable register value */
Uint32 xcere2;
/*! Enhanced transmit channel 3 enable register value */
Uint32 xcere3;
/*! Pin control register value */
Uint32 pcr;
/*! This field defines to the receive EDMA priority */
Uint32 dwReceiveEdmaPri;
/*! This field defines to the transmit EDMA priority */
Uint32 dwTransmitEdmaPri;
} IEKC64_SER_CONFIG;
/*--------------------------------------------------------------------------*/
/*! This varaible contains the SER default configuration
*/
extern const IEKC64_SER_CONFIG IEKC64_SER_CONFIG_DEFAULT;
/*--------------------------------------------------------------------------*/
/*! Defines the SERIAL configuration used for acquisition and restitution
All fields have to be set before the call.
*/
typedef struct
{
/*! This field inform the board if you want a default configuration structure
FALSE or if you want to define your MCBSP configuration parameters
via IEKC64_SER_CONFIG structure ( Config = TRUE)
*/
Uint8 ConfigMode;
/*! This field holds the MCBSP configuration used for acquisition and restitution
*/
IEKC64_SER_CONFIG McbspConfig;
} IEKC64_SER;
/*! Module error codes.<br>
If status returned from a module call is negative (or
IEKC64_SUCCESS(return code) is false), the value represents an error
from the list below
*/
enum
{
//! \ MCBSP initialization global error
IEKC64_MCBSP_OPENFAIL = IEKC64_ERR_CODE( IEKC64_VIDEO, 1 ),
//! \ EDMA receive open fail
IEKC64_MCBSP_EDMA_CHA_REVT0_OPENFAIL = IEKC64_ERR_CODE( IEKC64_VIDEO, 2 ),
//! \ EDMA transmit open fail
IEKC64_MCBSP_EDMA_CHA_XEVT0_OPENFAIL = IEKC64_ERR_CODE( IEKC64_VIDEO, 3 ),
//! \ EDMA reload fail
IEKC64_MCBSP_EDMA_RLD_OPENFAIL = IEKC64_ERR_CODE( IEKC64_VIDEO, 4 ),
//! \ EDMA link open fail
IEKC64_SER_UNKNOWN_LINK = IEKC64_ERR_CODE( IEKC64_VIDEO, 5 ),
//! \ EDMA transmit timeout
IEKC64_RS422_XMT_TIMEOUT = IEKC64_ERR_CODE( IEKC64_VIDEO, 6 ),
//! \ EDMA receive timeout
IEKC64_RS422_RCV_TIMEOUT = IEKC64_ERR_CODE( IEKC64_VIDEO, 7 ),
//! \ Bad TCC for EDMA
IEKC64_ERR_SER_BADTCC = IEKC64_ERR_CODE( IEKC64_VIDEO, 10 ),
//! \ Cannot allocate semaphore
IEKC64_ERR_SER_RCV_SEM = IEKC64_ERR_CODE( IEKC64_VIDEO, 11 ),
//! \ Cannot allocate semaphore
IEKC64_ERR_SER_XMT_SEM = IEKC64_ERR_CODE( IEKC64_VIDEO, 12 )
};
/*--------------------------------------------------------------------------*/
/*! Special timeout values for RS422 communication
*/
enum IEKC64_SER_WAIT
{
//! Tell the API no to wait until the function is completed
IEKC64_SER_NO_WAIT = 0,
//! Tell the API to wait until the function completed
IEKC64_SER_WAIT_INFINITE
};
// function prototypes
/*--------------------------------------------------------------------------*/
/*! Initializes the SERIAL module
\param pConfig
Configuration struture
\return An IEKC64_STATUS. If the call succeeds, the value will be IEKC64_OK.
Otherwise it holds an error code. The status code can be tested by
the IEKC64_SUCCESS(return code) macro that is true is the value
represents a successful call.
\b Example:
\verbatim
IEKC64_SER config;
IEKC64_STATUS status;
//board intialisation
...
// configure needed fields
config.McbspConfig = IEKC64_SER_CONFIG_DEFAULT;
config.McbspConfig.dwReceiveEdmaPri = EDMA_OPT_PRI_LOW;
config.McbspConfig.dwTransmitEdmaPri = EDMA_OPT_PRI_LOW;
config.ConfigMode = FALSE;
status = SER_open(&config);
if (!IEKC64_SUCCESS(status))
{
printf("Can't open SER module\n");
}
\endverbatim
*/
IEKC64_STATUS SER_open(IEKC64_SER *pConfig);
/*--------------------------------------------------------------------------*/
/*! Starts the SERIAL module
\return An IEKC64_STATUS. If the call succeeds, the value will be IEKC64_OK.
Otherwise it holds an error code. The status code can be tested by
the IEKC64_SUCCESS(return code) macro that is true is the value
represents a successful call.
*/
IEKC64_STATUS SER_start();
/*--------------------------------------------------------------------------*/
/*! Stops SERIAL module
\return An ATEME_STATUS. If the call succeeds, the value will be IEKC64_OK.
Otherwise it holds an error code. The status code can be tested by
the IEKC64_SUCCESS(return code) macro that is true is the value
represents a successful call.
*/
IEKC64_STATUS SER_stop();
/*--------------------------------------------------------------------------*/
/*! Receives data with the SERIAL module
\param pAddr
A pointer to the next data to be acquired
\param SizeofFrame
Size of the frame to be acquired
\param TimeOut
Time out value
\return An IEKC64_STATUS. If the call succeeds, the value will be IEKC64_OK.
Otherwise it holds an error code. The status code can be tested by
the IEKC64_SUCCESS(return code) macro that is true is the value
represents a successful call.
*/
IEKC64_STATUS SER_receive(Uint32* pAddr, Uint32 SizeofFrame, Uint32 TimeOut);
/*--------------------------------------------------------------------------*/
/*! Sends data with the SERIAL module
\param pAddr
A pointer to the data to be sent
\param SizeofFrame
Size of the frame to be sent
\param TimeOut
Time out value
\return An IEKC64_STATUS. If the call succeeds, the value will be IEKC64_OK.
Otherwise it holds an error code. The status code can be tested by
the IEKC64_SUCCESS(return code) macro that is true is the value
represents a successful call.
*/
IEKC64_STATUS SER_send(Uint32 *pAddr, Uint32 SizeofFrame, Uint32 TimeOut);
/*--------------------------------------------------------------------------*/
/*! Waits end of previous transfert on the SERIAL module
\param TimeOut
Time out value
\return An IEKC64_STATUS. If the call succeeds, the value will be IEKC64_OK.
Otherwise it holds an error code. The status code can be tested by
the IEKC64_SUCCESS(return code) macro that is true is the value
represents a successful call.
*/
/*@}*//* end of group SER */
#ifdef __cplusplus
}
#endif
#endif /* ifndef _IEK_SER_H_ */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -