AR568 Recv
Edit this on GitLab
AR568 Recv Sample Application (SSK 2.x)
Overview
The AR568 Recv sample application demonstrates how to configure an ARINC 568 channel for message reception using the NAI Software Support Kit (SSK 2.x). The application configures the receiver with FIFO thresholds and an optional bounded FIFO mode, enables the receiver, then polls for incoming messages over a user-specified duration.
ARINC 568 is a variant of the ARINC protocol. This sample supports AR568 module types. It is designed to work with the AR568 Xmit sample application for transmit testing.
This sample is new to SSK 2.x and has no SSK 1.x counterpart.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with an AR568 module installed.
-
SSK 2.x installed on your development host.
-
The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.
-
An ARINC 568 transmitter connected to the receive channel.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. |
The main() function calls naiapp_RunBoardMenu() to load a saved configuration or present the board menu, then calls AR568_Receive_run() in a loop.
Channel Configuration
The AR568_Receive_run() function configures the receiver:
check_status( naibrd_AR568_ChannelReset( cardIndex, module, archan ) );
check_status( naibrd_AR568_SetRxFifoThresholds( cardIndex, module, archan, 250, 750 ) );
bQuit = GetAR568RxBoundedFIFOEnabled(AR_ENABLE, &bRxBoundedFIFOenable);
if (!bQuit)
{
check_status( naibrd_AR568_SetRxFifoBounded( cardIndex, module, archan, bRxBoundedFIFOenable ) );
}
-
Rx FIFO thresholds — Almost Empty at 250 messages, Almost Full at 750 messages.
-
Bounded FIFO — when enabled, the FIFO stops accepting new data when full rather than overwriting old data.
Data Reception
The application clears the Rx FIFO, enables the receiver, and polls for data over a user-specified duration:
check_status( naibrd_AR568_ClearRxFifo( cardIndex, module, channel ) );
check_status( naibrd_AR568_SetRxEnable( cardIndex, module, channel, NAI_TRUE ) );
while ( duration < timeout )
{
status = naibrd_AR568_GetRxFifoCnt( cardIndex, module, channel, &nNumWordsRecv );
if (status == NAI_SUCCESS && nNumWordsRecv > 0)
{
status = naibrd_AR568_ReadRxFifo( cardIndex, module, channel, nNumWordsRecv, RecvData, &nNumMsgsRecv );
for ( i = 0; i < nNumMsgsRecv; i++ )
{
naiif_printf( "Data: 0x%08X\r\n", RecvData[i] );
}
}
duration++;
naiif_msDelay(1000);
}
Each ARINC 568 message is a 32-bit word containing the complete ARINC data.
Troubleshooting Reference
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
No messages received |
Transmitter not running, cable not connected |
Ensure the AR568 Xmit sample or external transmitter is running. |
Rx FIFO overflow |
Messages arriving faster than read rate |
Increase read frequency or enable bounded FIFO mode. |
|
Module not AR568, channel misconfigured |
Verify the module type and channel configuration. |
No board found or connection timeout |
Board not powered, incorrect configuration file |
Verify hardware is powered and connected. |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — ar568_recv.c (SSK 2.x)
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"
/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"
/* Common Sample Program include files */
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_menu.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_query.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_access.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_display.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_utils.h"
/* AD Sample App include files */
#include "nai_sample_apps/naiapp_src/board_modules/ar568/ar568_common_utils/ar568_common_utils.h"
static const int8_t *CONFIG_FILE = (const int8_t *)"default_AR568Recv.txt";
static bool_t AR568_Receive_run();
static bool_t RxAndDisplayFIFOMsgs( int32_t cardIndex, int32_t module, int32_t channel );
/* Default channel selection */
#define DEF_AR_CARD_INDEX 0
#define DEF_AR_MODULE 1
#define DEF_AR_RECV_CHANNEL 1
#define AR_ENABLE 1
/*****************************************************************************/
/**
* <summary>
* The purpose of AR568_Receive is to illustrate the methods to call in the naibrd
* library to configure the ARINC-568 channel to receive ARINC-568 messages and store
* received messages in a receive FIFO.
*
* The following system configuration routines from the nai_sys_cfg.c file are
* called to assist with the configuration setup for this program prior to
* calling the naibrd ARINC routines.
* - ConfigDevice
* - DisplayDeviceCfg
* - GetBoardSNModCfg
* - CheckModule
* </summary>
*/
/*****************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t AR568_Receive(void)
#else
int32_t main(void)
#endif
{
bool_t bQuit = NAI_FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (!bQuit)
{
bQuit = AR568_Receive_run();
}
naiif_printf("Type the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
naiapp_access_CloseAllOpenCards();
return 0;
}
/*****************************************************************************/
/**
* <summary>
* AR568_Receive_run queries the user for the card, module and channel to configure
* the ARINC-568 receiver and enable it to receive ARINC-568 messages.
* </summary>
*/
/*****************************************************************************/
static bool_t AR568_Receive_run()
{
bool_t bQuit = NAI_FALSE;
int32_t archan;
int32_t cardIndex, module;
bool_t bRxBoundedFIFOenable;
bQuit = GetAR568Cfg( DEF_AR_CARD_INDEX, DEF_AR_MODULE, DEF_AR_RECV_CHANNEL, &cardIndex, &module, &archan );
if (!bQuit)
{
/* Reset the channel */
check_status( naibrd_AR568_ChannelReset( cardIndex, module, archan ) );
/* Set the Rx Fifo Almost Empty Threshold to 250 and the Almost Full Threshold to 750 messages. */
/* If the number of messages in the Rx FIFO falls below 250, the Rx FIFO Almost Empty Status will be set */
/* If the number of messages in the Rx FIFO rises above 750, the Rx FIFO Almost Full Status will be set */
check_status( naibrd_AR568_SetRxFifoThresholds( cardIndex, module, archan, 250, 750 ) );
bQuit = GetAR568RxBoundedFIFOEnabled(AR_ENABLE, &bRxBoundedFIFOenable);
if (!bQuit)
{
check_status( naibrd_AR568_SetRxFifoBounded( cardIndex, module, archan, bRxBoundedFIFOenable ) );
}
/* Enable Receiver and Display Data Received in the Rx FIFO */
bQuit = RxAndDisplayFIFOMsgs( cardIndex, module, archan );
}
return bQuit;
}
static bool_t RxAndDisplayFIFOMsgs( int32_t cardIndex, int32_t module, int32_t channel )
{
bool_t bQuit = NAI_FALSE;
bool_t bContinue = NAI_TRUE;
int32_t i;
int32_t nNumWordsRecv;
int32_t nNumMsgsRecv;
uint32_t RecvData[NAIBRD_AR2_MAX_FIFO_COUNT];
int32_t duration;
int32_t timeout;
nai_status_t status;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Clear Rx FIFO to start with an empty buffer */
check_status( naibrd_AR568_ClearRxFifo( cardIndex, module, channel ) );
/* Enable Receiver */
check_status( naibrd_AR568_SetRxEnable( cardIndex, module, channel, NAI_TRUE ) );
bContinue = NAI_TRUE;
while (bContinue)
{
naiif_printf( "\r\nType duration (in seconds) for ARINC-568 receive messages test or %c to quit (default: 5) : ", NAI_QUIT_CHAR );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
duration = 0;
timeout = 5;
if ( inputResponseCnt > 0 )
timeout = (int32_t)atol( (const char*)inputBuffer );
/* Read data */
while ( duration < timeout )
{
/* Get count of received ARINC-568 messages in Rx FIFO */
status = naibrd_AR568_GetRxFifoCnt( cardIndex, module, channel, &nNumWordsRecv );
if (status == NAI_SUCCESS)
{
/* If Rx count is greater than 0, read out as many messages from the Rx FIFO */
if ( nNumWordsRecv > 0 )
{
status = naibrd_AR568_ReadRxFifo( cardIndex, module, channel, nNumWordsRecv, RecvData, &nNumMsgsRecv ); /* read back data */
if (status == NAI_SUCCESS)
{
naiif_printf( "\r\nReading back %d msgs ...\r\n", nNumMsgsRecv );
for ( i = 0; i < nNumMsgsRecv; i++ )
{
naiif_printf( "Data: 0x%08X\r\n", RecvData[i] );
}
}
else
{
naiif_printf("naibrd_AR568_ReadRxFifo status: %s\r\n", naiif_GetStatusString(status));
}
}
}
else
{
naiif_printf("naibrd_AR568_GetRxFifoCnt status: %s\r\n", naiif_GetStatusString(status));
}
duration++;
naiif_msDelay(1000);
}
}
else
bContinue = NAI_FALSE;
}
return bQuit;
}