1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00
LibrePilot/flight/Libraries/ahrs_spi_program_master.c
les b2d56ca34c AHRS: Added UAVObject based SPI communication between AHRS and OP.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1830 ebee16cc-31ac-478f-84a7-5cbb03baadba
2010-10-01 17:31:13 +00:00

27 lines
739 B
C

#include "ahrs_program_master.h"
#include "ahrs_program.h"
#include "pios_spi.h"
char connectTxBuf[SPI_PROGRAM_REQUEST_LENGTH] = {SPI_PROGRAM_REQUEST};
char connectRxBuf[SPI_PROGRAM_REQUEST_LENGTH];
#define MAX_CONNECT_TRIES 10
uint32_t AhrsProgramConnect( void )
{
memset( connectRxBuf, 0, SPI_PROGRAM_REQUEST_LENGTH );
for( int ct = 0; ct < MAX_CONNECT_TRIES; ct++ ) {
uint32_t res = PIOS_SPI_TransferBlock( PIOS_SPI_OP, ( uint8_t * )&connectTxBuf,
( uint8_t * )&connectRxBuf, SPI_PROGRAM_REQUEST_LENGTH, NULL );
if( res == 0 && memcmp( connectRxBuf, SPI_PROGRAM_ACK, SPI_PROGRAM_REQUEST_LENGTH ) == 0 ) {
return( 0 );
}
vTaskDelay( 1 / portTICK_RATE_MS );
}
return( -1 );
}