/******************************************************************************
COPYRIGHT 2002 STMicroelectronics
Source File Name :  spi.h 
Group            : IPSW,CMG-IPDF
Author           : MCD Application Team
Date First Issued: 07/03/2002
********************************Documentation**********************************
General Purpose - Contains prototypes for all the functions of SPI

********************************Revision History*******************************
_______________________________________________________________________________
Date :07/03/2002                  Release:1.0            	  
Date:23/9/2003                    Release:2.0 
Date :28/04/04                    MISRA changes	       		         		        		     
******************************************************************************/
#ifndef SPI_H
#define SPI_H

#include "ST7lib_config.h"
/*----------------------------------ENUMS------------------------------------*/
        /* Parameters for initialisation of SPI control and status registers */
typedef enum {
    SPI_DEFAULT                     = (unsigned char) 0x00,
    SPI_ENABLE                      = (unsigned char) 0x40,
    SPI_ENABLE_IT                   = (unsigned char) 0x80,
    SPI_BAUDRATE_4                  = (unsigned char) 0x20,
    SPI_BAUDRATE_8                  = (unsigned char) 0x00,
    SPI_BAUDRATE_16                 = (unsigned char) 0x01,
    SPI_BAUDRATE_32                 = (unsigned char) 0x22,
    SPI_BAUDRATE_64                 = (unsigned char) 0x02,
    SPI_BAUDRATE_128                = (unsigned char) 0x03,
    SPI_CLK_PP_0                    = (unsigned char) 0x00,
    SPI_CLK_PP_1                    = (unsigned char) 0x04,
    SPI_CLK_PP_2                    = (unsigned char) 0x08,
    SPI_CLK_PP_3                    = (unsigned char) 0x0C 	
    }SPI_Init_Parameter1;

     /* Parameters for selection of SPI mode in control and status registers */	
typedef enum {
    SPI_MSTR_SW                     = (unsigned char) 0x03,
    SPI_SLAVE_SW                    = (unsigned char) 0x02,
    SPI_HW                          = (unsigned char) 0x00	
    }SPI_Init_Parameter2;

                                           /* Transmission status parameters */  
typedef enum {
    SPI_TX_BUFFER_ONGOING           = (unsigned char) 0xFF,
    SPI_TX_STRING_ONGOING           = (unsigned char) 0xFE,
    SPI_TX_WCOL                     = (unsigned char) 0x40,
    SPI_TX_MODF                     = (unsigned char) 0x10,
    SPI_TRANSMIT_OK                 = (unsigned char) 0x00 
    }SPI_TxErrCode_t; 

                                              /* Reception status parameters */	
typedef enum {    
    SPI_RX_BUFFER_ONGOING           = (unsigned char) 0xFF,
    SPI_RX_STRING_ONGOING           = (unsigned char) 0xFE, 
    SPI_RECEIVE_OK                  = (unsigned char) 0x00,
    SPI_RX_OVR                      = (unsigned char) 0x20, 
    SPI_RX_DATA_EMPTY               = (unsigned char) 0xFD,
    SPI_RX_MODF                     = (unsigned char) 0x10		
    }SPI_RxErrCode_t;           

/*---------------------------------MACROS------------------------------------*/
#define SPI_Output_Disable() (SPICSR |= 0x04) 
                            /* Disables the alternate function of SPI output */

/*-----------------------------FUNCTION PROTOTYPES---------------------------*/
                  /* Description of all the functions defined in this module */ 
                                                           /* Initialize SPI */
void SPI_Init( SPI_Init_Parameter1 Init_Value1, SPI_Init_Parameter2 
                                                                 Init_Value2); 
                                                            

void SPI_PutByte (unsigned char Tx_Data) ;  /* Transmits single byte of data */

unsigned char SPI_GetByte (void) ;           /* Receives single byte of data */

                                          /* Returns the transmission status */
SPI_TxErrCode_t SPI_IsTransmitCompleted ( void ) ; 

                                             /* Returns the reception status */
SPI_RxErrCode_t SPI_IsReceptionCompleted( void ) ; 	
	
void SPI_Clear_Flags( void) ;       /* Clears all the error and status flags */

              /* SPI interrupt service function for communication in interrupt 
                                                  driven without buffer mode */
void SPI_IT_Function (void) ;       
	

#ifdef SPI_POLLING_TX
    /* Transmits data bytes continuously and returns the transmission status */
SPI_TxErrCode_t  SPI_PutBuffer (const unsigned char* PtrToBuffer, 
                                                     unsigned char NbOfBytes); 

                /* Transmits data string and returns the transmission status */
SPI_TxErrCode_t  SPI_PutString (const unsigned char* PtrToString); 

#endif

#ifdef SPI_POLLING_RX
             /* Receives bytes continuously and returns the reception status */
SPI_RxErrCode_t SPI_GetBuffer (unsigned char* PtrToBuffer, unsigned char 
                                                                   NbOfBytes) ;

                    /* Receives data string and returns the reception status */
SPI_RxErrCode_t SPI_GetString (unsigned char* PtrToString) ;  

#endif

#ifdef SPI_ITDRV_WITHOUTBUF_TX
                         /* Starts continuous data bytes transmission in ISR */
void SPI_PutBuffer (const unsigned char* PtrToBuffer,unsigned char NbOfBytes);  

                                   /* Starts data string transmission in ISR */
void SPI_PutString (const unsigned char* PtrToString) ; 

#endif

#ifdef SPI_ITDRV_WITHOUTBUF_RX
                            /* Starts continuous data bytes reception in ISR */
void SPI_GetBuffer (unsigned char* PtrToBuffer, unsigned char NbOfBytes) ; 
                                      /* Starts data string reception in ISR */
void SPI_GetString (unsigned char* PtrToString) ; 
#endif	    												

#endif
/**** (c) 2002   STMicroelectronics *************************** END OF FILE **/
