/****************************************************************************/
/* Copyright 2007 MBARI.                                                    */
/* Monterey Bay Aquarium Research Institute Proprietary Information.        */
/* All rights reserved.       																						  */
/*	 																																				*/
/* SPI.c - handles SPI communications.                                      */
/*																																				  */
/* Rev History:																															*/
/* Initial Creation 11/2007		B.Kieft																	    	*/
/*																																					*/
/*																																					*/
/****************************************************************************/


#include <stdlib.h>

// Purpose: Sends spi string
#SEPARATE
void SPI_strwrite(char *s)
{
	int count = 0;
  while( (*s != 0) && (count < MAX_SPI_CHARS) ) {
  spi_write(*s++);
  count++;
  }
}

// Purpose: Reads spi string with clocks
#SEPARATE
void SPI_strread(char *s)
{
	int spi_char = 0;
	char spi_buff_in[MAX_SPI_CHARS];
	
  while( (s[spi_char] = spi_read(0)) && (spi_char < MAX_SPI_CHARS) ) {
    spi_char++;	
    delay_us(500); 
  }
}

// Purpose: Reads spi string with no clocks
#SEPARATE
void SPI_slave_strread(char *s)
{
	int spi_char = 0;
	char spi_buff_in[MAX_SPI_CHARS];
	
	while(!spi_data_is_in());
  while( (s[spi_char] = spi_read()) && (spi_char < MAX_SPI_CHARS) ) {
    spi_char++;	
    delay_us(50); 
  }
}
