📄 ma_spi.c
字号:
/*
*****************************************************************************
**
** Project : My project
**
** Component : LPC2106 (LPC2106)
**
** Modulename : SPI
**
** Filename : ma_spi.c
**
** Abstract : This file implements a device driver for the SPI
** module.
**
** Compiler : IAR C compiler
**
** Date : 2004-05-24 15:39:23
**
** License no. : 9503-663-863-6224 Ivan
**
** Warning : This file has been automatically generated.
** Do not edit this file if you intend to regenerate it.
**
** This device driver was created by IAR MakeApp version
** 4.02A (Philips LPC210x: 4.00C) for the Philips LPC210x series of
** microcontrollers.
**
** (c)Copyright 2004 IAR Systems.
** Your rights to this file are explained in the IAR MakeApp
** License Agreement. All other rights reserved.
**
*****************************************************************************
*/
/*
**===========================================================================
** 1 GENERAL
** 1.1 Revisions
**
** Please read the IAR MakeApp for Philips LPC210x readme file
**
**
**===========================================================================
*/
/*
**===========================================================================
** 1.2 References
**
** No Identification Name or Description
** == =================== ================================
**
** 1 02/Oct/2003 Philips LPC210x Hardware Manual
**
**===========================================================================
*/
/*
**===========================================================================
** 2. INCLUDE FILES
** 2.1 Standard include files
**===========================================================================
*/
/*
**===========================================================================
** 2.2 Application include files
**===========================================================================
*/
#include "usercode.h" /* Usercode macros (see <template.h>) */
#include "ma_tgt.h" /* Target specific header file */
#include "ma_sfr.h" /* Special function register bitfield macros */
#include "NXP/iolpc210x.h" /* Defines Special function registers */
#include "ma_spi.h" /* Module driver header file */
/*
**===========================================================================
** 3. DECLARATIONS
** 3.1 Internal constants
**===========================================================================
*/
#define MA_SPCR_SPI 0x00000020 /* SPI Control Register */
#define MA_SPCR_SPI_MASK 0x000000F8 /* Used bits */
#define MA_SPDR_SPI 0x00000000 /* SPI Data Register */
#define MA_SPDR_SPI_MASK 0x000000FF /* Used bits */
#define MA_SPCCR_SPI 0x00000008 /* SPI Clock Counter Register */
#define MA_SPCCR_SPI_MASK 0x000000FF /* Used bits */
/*
**===========================================================================
** 3.2 Internal macros
**===========================================================================
*/
/*
**===========================================================================
** 3.3 Internal type definitions
**===========================================================================
*/
/*
**===========================================================================
** 3.4 Global variables (declared as 'extern' in some header file)
**===========================================================================
*/
/*
**===========================================================================
** 3.5 Internal function prototypes (defined in Section 5)
**===========================================================================
*/
/*
**===========================================================================
** 3.6 Internal variables
**===========================================================================
*/
/*
**===========================================================================
** 4. GLOBAL FUNCTIONS (declared as 'extern' in some header file)
**===========================================================================
*/
void MA_Init_SPI( void )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Initialises the SPI module. Only sets those registers with values
** not equal to the power-on reset values.
**
** Parameters:
** None
**
** Returns:
** None
**
**---------------------------------------------------------------------------
*/
{
/*--- Handle user code on function entry ---*/
ENTER_MA_INIT_SPI;
/*--- Initialize registers ---*/
S0SPCCR = ( S0SPCCR & ~MA_SPCCR_SPI_MASK ) | MA_SPCCR_SPI;
S0SPCR = ( S0SPCR & ~MA_SPCR_SPI_MASK ) | MA_SPCR_SPI;
/*--- Handle user code on function exit ---*/
EXIT_MA_INIT_SPI;
} /* MA_Init_SPI */
void MA_Reset_SPI( void )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Resets the SPI module. Sets all registers.
**
** Parameters:
** None
**
** Returns:
** None
**
**---------------------------------------------------------------------------
*/
{
/*--- Handle user code on function entry ---*/
ENTER_MA_RESET_SPI;
/*--- Reset registers ---*/
S0SPCCR = ( S0SPCCR & ~MA_SPCCR_SPI_MASK ) | MA_SPCCR_SPI;
S0SPCR = ( S0SPCR & ~MA_SPCR_SPI_MASK ) | MA_SPCR_SPI;
/*--- Handle user code on function exit ---*/
EXIT_MA_RESET_SPI;
} /* MA_Reset_SPI */
S8 MA_PutChar_SPI( U8 Data )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Sends a character.
**
** Note! Use the function MA_TestChar_SPI() to check that the previous
** transfer is complete before MA_PutChar_SPI() is called again.
**
** Parameters:
** Data The data to send
**
** Returns:
** MA_OK Character written successfully
** MA_ERROR Write data error signalled
**
**---------------------------------------------------------------------------
*/
{
S8 Status;
/*--- Handle user code on function entry ---*/
ENTER_MA_PUTCHAR_SPI;
/*--- Write data ---*/
S0SPDR = Data;
Status = MA_OK;
/*--- Test the SPI Status Register ---*/
if( S0SPSR )
{
/*--- Serial data complete or Write collision flag set ---*/
Status = MA_ERROR;
}
/*--- Handle user code on function exit ---*/
EXIT_MA_PUTCHAR_SPI;
return Status;
} /* MA_PutChar_SPI */
U8 MA_GetChar_SPI( void )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Reads the received character.
**
** Note! Use the function MA_TestChar_SPI() to check that transfer is
** complete before MA_GetChar_SPI() is called.
**
** Parameters:
** None
**
** Returns:
** The read data
**
**---------------------------------------------------------------------------
*/
{
U8 Data;
/*--- Handle user code on function entry ---*/
ENTER_MA_GETCHAR_SPI;
/*--- Read data ---*/
Data = S0SPDR;
/*--- Handle user code on function exit ---*/
EXIT_MA_GETCHAR_SPI;
/*--- Return read data ---*/
return Data;
} /* MA_GetChar_SPI */
S8 MA_TestChar_SPI( void )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Tests if serial transfer is complete.
**
** Parameters:
** None
**
** Returns:
** SPSR status information if Error, bits set.
** SPSR_WCOL Write collission
** SPSR_ROVR Read overrun
** SPSR_MODF Mode fault
** SPSR_ABRT Abort error
** else
** MA_EMPTY Transfer is not complete
** MA_OK Transfer is complete
**
**---------------------------------------------------------------------------
*/
{
S8 Status;
/*--- Handle user code on function entry ---*/
ENTER_MA_TESTCHAR_SPI;
Status = (S8) S0SPSR;
/*--- Check the write collision flag ---*/
if( Status == 0 )
{
/*--- Serial transfer is not complete and no errors ---*/
Status = MA_EMPTY;
}
/*--- Check the error flag ---*/
else if( Status & ( SPSR_WCOL | SPSR_ROVR | SPSR_MODF | SPSR_ABRT ) )
{
/*--- Data containing SPSR status info will be returned ---*/
if( Status & SPSR_MODF )
{
/*--- Clear mode fault flag ---*/
S0SPCR = MA_SPCR_SPI;
}
}
/*--- Check the transfer complete flag ---*/
else if( Status & SPSR_SPIF )
{
Status = MA_OK;
}
/*--- Handle user code on function exit ---*/
EXIT_MA_TESTCHAR_SPI;
return Status;
} /* MA_TestChar_SPI */
S8 MA_SetMode_SPI( U8 Mode )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Selects SPI operation mode.
**
** Parameters:
** Mode MA_MASTER_SPI -> Master mode
** MA_SLAVE_SPI -> Slave mode
**
**
** Returns:
** MA_OK Mode updated
** MA_ERROR Illegal mode
**
**---------------------------------------------------------------------------
*/
{
S8 Status;
Status = MA_OK;
/*--- Handle user code on function entry ---*/
ENTER_MA_SETMODE_SPI;
switch( Mode )
{
case MA_MASTER_SPI:
S0SPCR_bit.MSTR = 1; /* Master mode */
break;
case MA_SLAVE_SPI:
S0SPCR_bit.MSTR = 0; /* Slave mode */
break;
default:
Status = MA_ERROR;
break;
}
/*--- Handle user code on function exit ---*/
EXIT_MA_SETMODE_SPI;
return Status;
} /* MA_SetMode_SPI */
/*
**===========================================================================
** 5. INTERNAL FUNCTIONS (declared in Section 3.5)
**===========================================================================
*/
/*
**===========================================================================
** END OF FILE
**===========================================================================
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -