/*
 *            Copyright (c) 1998-2004 by NETsilicon Inc.
 *
 *  This software is copyrighted by and is the sole property of
 *  NETsilicon.  All rights, title, ownership, or other interests
 *  in the software remain the property of NETsilicon.  This
 *  software may only be used in accordance with the corresponding
 *  license agreement.  Any unauthorized use, duplication, transmission,
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice may not be removed or modified without prior
 *  written consent of NETsilicon.
 *
 *  NETsilicon, reserves the right to modify this software
 *  without notice.
 *
 *  NETsilicon
 *  411 Waverley Oaks Road                  USA 781.647.1234
 *  Suite 227                               http://www.netsilicon.com
 *  Waltham, MA 02452                       AmericaSales@netsilicon.com
 *
 * Description:
 *
 *  This file contains the functions for DDI interface
 *
 */

/* Defines */
#define EXIT_SUCCESS    0
#define OK              EXIT_SUCCESS
#define ERROR           (-1)
#define NUM_DMA_SPI_BUF 2               /* set the dma rx buffer number to 2  - arbitary */

/* Externs */
extern int serl_resource_lock[2];
extern volatile SPIBUFFER spiDataBuffer[NUM_NCC_SER_CHAN];
extern volatile SPIBUFFER spiInBuffer[NUM_NCC_SER_CHAN];

extern int GetResource(int *resource, void *owner);
extern int ReleaseResource(int *resource, void *owner);
extern void fmemcpy(void*, void*, int);
extern int chipRevision;

/* spi_eeprom.c */
int sendEEPROMCommand(ONSPI_CHAN *pChan,int request,int * arg);

void spi_set_command(SPIBUFFER volatile *q,char request,int arg);
void spi_copy_reply(SPIBUFFER volatile *q,int *arg);

/* spi_init.c */
void onspiInitChannel (ONSPI_CHAN *, bool initSeq);   /* Hardware initialization of the NCC serial channel. */
void spiResetChannel (const ONSPI_CHAN *pChan, const bool resetPort ); /* Set driver operational mode */
 
/* spi_api.c */
int sendWriteEnable(ONSPI_CHAN *pChan );
void setBitRate(ONSPI_CHAN * pChan);
int setSSport(ONSPI_CHAN* pChan, int * arg); /* Set port for generating "Slave Select" or "Salve active" signal */
int get_baud_div (int baudrate);             /* returns the baud rate divisor  */
int calcNumOfTicks(const int length,const ONSPI_CHAN  *pch);
bool isBufferEmpty (const SPIBUFFER volatile *q);   /* check if buffer is empty */
char * spi_set_io_buffer (SPIBUFFER volatile *q, char *c, int nbytes,ONSPI_CHAN *pChan);
void spi_enable_write (SPIBUFFER volatile *q);	
void spi_copy_io_buffer (SPIBUFFER volatile *q, char *c, int nbytes,ONSPI_CHAN *pChan);
bool waitForCompletion(const SPIBUFFER volatile *q, ONSPI_CHAN  *pch, const int numberOfBytes);

/* spi_ddi.c    DDI functions */
STATUS onspiIoctl (ONSPI_CHAN * pChan, int request, int* arg);  /* sets driver parameters */

/* spi_dma.c DMA functions */
void onspiDmaWr (ONSPI_CHAN * pChan);       /* Dma interrupt function when done with send*/
void onspiDmaRd (ONSPI_CHAN *pChan);        /* Dma interrupt function when done with read*/
int spi_init_tx_dma(ONSPI_CHAN  *pch);      /* set up the dma for transmit and start it */
int spi_init_rx_dma(ONSPI_CHAN  *pch);      /* set up the dma for receive and start it */

/* spi_ioctl.c  Ioctl functions */
void onspiISRforSel(ONSPI_CHAN * pChan);
int setISRforSEL(ONSPI_CHAN* pChan, int * arg); /* Use interrupt on the SEL signal*/

/* spi_fifo.c   Interrupt functions */
void onspiIntWr40 (ONSPI_CHAN * pChan);     /* interrupt function when ready to send*/
void onspiIntWr50 (ONSPI_CHAN * pChan);     /* interrupt function when ready to send*/
void onspiIntRd (ONSPI_CHAN * pChan);       /* interrupt function when ready to read*/
int onspiRxStartup (ONSPI_CHAN* pChan);     /* Call interrupt level character input routine */
int onspiTxStartup (ONSPI_CHAN* pChan);     /* Call interrupt level character output routine */

 
