CAN BasicOps
Edit this on GitLab
CAN BasicOps Sample Application (SSK 2.x)
Overview
The CAN BasicOps sample application demonstrates how to perform basic CAN bus transmit and receive operations using the NAI Software Support Kit (SSK 2.x). It covers channel configuration, protocol selection (CAN A/B and J1939), baud rate setup, Built-In Test (BIT) verification, FIFO-based data transmission, and FIFO-based data reception. This sample provides a practical starting point for integrating CAN bus communication into your own applications.
This sample supports the following CAN module types: CB1, CB2, CB3, CB6, and CB8. The application automatically adapts its behavior based on the detected module — CB1 modules use CAN A/B protocol, CB2 modules use J1939, and CB3/CB6 modules support both protocols with user selection. Refer to the CB1-CB3 Manual for detailed module specifications.
For the SSK 1.x version, see CAN Interactive (SSK 1.x).
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a CAN module installed (CB1, CB2, CB3, CB6, or CB8).
-
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.
How to Run
Launch the can_basic_ops executable from your build output directory. On startup the application looks for a configuration file (default_CANBasicOps.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, the application guides you through selecting transmit and receive channels, choosing a protocol, configuring baud rates, and performing transmit/receive operations.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to CAN. |
The main() function follows a standard SSK 2.x startup flow:
-
Call
naiapp_RunBoardMenu()to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_CANBasicOps.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear. -
Query the user for a card index with
naiapp_query_CardIndex(). -
Query for a module slot with
naiapp_query_ModuleNumber(). -
Retrieve the module ID with
naibrd_GetModuleName()and verify the module supports CAN by checkingnaibrd_CAN_GetChannelCount().
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t naiapp_CAN_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = NAI_FALSE;
int32_t moduleCount;
int32_t channelCount, cardIndex, module;
uint32_t modId;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (stop != NAI_TRUE)
{
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCount));
stop = naiapp_query_ModuleNumber(moduleCount, 1, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &modId));
channelCount = naibrd_CAN_GetChannelCount(modId);
if ((channelCount != 0))
{
naiapp_Run_CAN_BasicOps(cardIndex, module, modId);
}
else
{
naiif_printf(" *** Module selection not recognized as valid module type for this application. ***\r\n\r\n");
}
}
naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
}
naiif_printf("\r\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
Note the SSK 2.x differences from SSK 1.x in this startup sequence:
-
The VxWorks preprocessor guard uses
NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS(SSK 1.x uses__VXWORKS__). -
The module identifier is retrieved with
naibrd_GetModuleName()(SSK 1.x usesnaibrd_GetModuleID()). -
Boolean constants are
NAI_TRUE/NAI_FALSE(SSK 1.x usesTRUE/FALSE). -
Console output uses
naiif_printf()from the platform abstraction layer (SSK 1.x usesprintf()directly).
|
Important
|
Common connection errors you may encounter at this stage:
|
Program Structure
Entry Point
On standard platforms (Petalinux, DEOS) the entry point is main(). On VxWorks the entry point is naiapp_CAN_BasicOps() — the SSK 2.x build system selects the correct variant via a preprocessor guard:
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t naiapp_CAN_BasicOps(void)
#else
int32_t main(void)
#endif
The startup flow is the same in both cases:
-
Attempt to load the saved configuration file via
naiapp_RunBoardMenu(DEF_CONFIG_FILE). -
Enter a loop that queries for card index and module slot.
-
Validate the module supports CAN via
naibrd_CAN_GetChannelCount(). -
Call
naiapp_Run_CAN_BasicOps()to enter the interactive operation flow. -
On exit, close all open board connections with
naiapp_access_CloseAllOpenCards().
Command Loop
Unlike menu-driven samples, the CAN BasicOps application uses a guided sequential flow rather than a command table. The naiapp_Run_CAN_BasicOps() function walks the user through:
-
Selecting a transmit channel
-
Choosing a transmit count
-
Selecting the protocol (CAN A/B or J1939, depending on module type)
-
Running BIT checks on the transmit channel
-
Selecting a receive channel
-
Running BIT checks on the receive channel
-
Configuring CAN timing/baud rate
-
Executing the transmit and receive operations
Channel Configuration and BIT Verification
The naiapp_Run_CAN_BasicOps() function configures both transmit and receive channels. Before data transfer, it performs Power-On BIT (PBIT) verification and Initiated BIT (IBIT) on each channel.
/* Check for PBIT complete Tx channel */
check_status(naibrd_CAN_CheckBITComplete(cardIndex, module, txChannel, &bitComplete));
/* Initiate BIT for Tx Channel */
bitStatus = naibrd_CAN_InitiateBIT(cardIndex, module, txChannel, NAI_TRUE);
/* Set protocol based on module type */
check_status(naibrd_CAN_SetProtocol(cardIndex, module, txChannel, NAIBRD_CAN_PROTOCOL_J1939));
Key API calls:
-
naibrd_CAN_GetChannelCount()— returns the number of CAN channels for the detected module ID. -
naibrd_CAN_CheckBITComplete()— checks whether Power-On BIT has completed for a channel. -
naibrd_CAN_InitiateBIT()— initiates a Built-In Test on the specified channel. -
naibrd_CAN_SetProtocol()— sets the protocol (CAN A/B or J1939) for a channel.
For J1939-capable modules (CB2, CB3, CB6), the application also claims addresses on both Rx and Tx channels using helper functions from the CAN common utilities library.
CAN Transmit
The naiapp_Run_CAN_Tx() function handles data transmission. It determines the protocol type, prompts for a PGN (Parameter Group Number) for J1939, queries the user for payload length, generates test data, and transmits via the FIFO.
naiapp_generateData(txChannel, numOfFramesToTransmit, payload, isJ1939, fifoData);
naiapp_transmitFIFOChannelData_PGN(cardIndex, module, txChannel, pgn, fifoData, numOfFramesToTransmit);
Key API calls (via common utility functions):
-
naiapp_IsCAN_AB()/naiapp_IsCAN_J1939()— determine the active protocol on a channel. -
naiapp_QueryForPGN()— prompts for a J1939 Parameter Group Number. -
naiapp_QueryForPayload()— prompts for payload length (0-8 for CAN A/B, 8-345 for J1939). -
naiapp_generateData()— generates test data frames. -
naiapp_transmitFIFOChannelData_PGN()— transmits FIFO data with optional PGN.
CAN Receive
The naiapp_Run_CAN_Rx() function reads received frames from the Rx channel FIFO. It checks the FIFO frame count, reads the data, and displays the received frames.
check_status(naibrd_CAN_GetRxFIFOFrameCount(cardIndex, module, rxChannel, &channelOutRxCount));
naiapp_getFIFOChannelData(cardIndex, module, rxChannel, fifoData);
naiapp_printFIFOChannelData(rxChannel, fifoData, isJ1939);
Key API calls:
-
naibrd_CAN_GetRxFIFOFrameCount()— returns the number of frames available in the receive FIFO. -
naiapp_getFIFOChannelData()— reads all available frames from the FIFO into the data structure. -
naiapp_printFIFOChannelData()— displays the received data frames.
|
Note
|
A 500 ms delay (naibrd_msDelay(500)) is inserted before checking the Rx FIFO to allow time for transmitted data to propagate and be received, since both Tx and Rx operations run in the same thread.
|
Troubleshooting Reference
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
No board found |
Board not powered or not connected |
Verify power and physical connections; check configuration file |
Module not recognized |
Module is not a CAN type (CB1-CB3, CB6, CB8) |
Verify the correct slot is selected and contains a CAN module |
PBIT not completed |
Module has not finished power-on self-test |
Wait for PBIT to complete; check module health |
IBIT failure |
Channel hardware fault or misconfiguration |
Check physical CAN bus connections and termination |
Rx No Data |
Transmit and receive channels not connected |
Ensure Tx and Rx channels are physically connected via CAN bus |
J1939 address claim failure |
Bus arbitration conflict |
Verify unique addresses; ensure Rx channel is active before Tx claim |
Invalid protocol for module |
Attempting J1939 on CB1 (CAN A/B only) |
Use the correct protocol for your module type |
Payload length error |
Value out of range for the selected protocol |
CAN A/B supports 0-8 bytes; J1939 supports 8-345 bytes |
Baud rate mismatch |
Tx and Rx channels configured at different rates |
Ensure both channels use the same baud rate setting |
FIFO overflow |
Receive FIFO full before data is read |
Increase read frequency or reduce transmit rate |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — can_basic_ops.c (SSK 2.x)
/**************************************************************************************************************/
/**
* <summary>
* The purpose of the CAN_BasicOps is to illustrate the methods to call in the library to perform a CAN Transmit
* on a single channel and a CAN Receive on a single channel.
*
* </summary>
*/
/**************************************************************************************************************/
/* 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"
#include "nai_libs/naibrd/include/functions/naibrd_can.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_utils.h"
/* Common CAN Sample Program include files */
#include "nai_sample_apps/naiapp_src/board_modules/can/can_common_utils/can_common_utils.h"
/*********************/
/* Application Name */
/**********************/
static const int8_t *DEF_CONFIG_FILE = (int8_t *)"default_CANBasicOps.txt";
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t naiapp_Run_CAN_Rx(int32_t cardIndex, int32_t module, int32_t rxChannel, bool_t isJ1939);
static bool_t naiapp_Run_CAN_Tx(int32_t cardIndex, int32_t module, uint32_t modId, int32_t txChannel, bool_t isJ1939, int32_t txCount);
static bool_t naiapp_Run_CAN_BasicOps(int32_t cardIndex, int32_t module, uint32_t modId);
/**************************************************************************************************************/
/**
* <summary>
*
* The main routine assists in gaining access to the board.
*
* The following routines from the nai_sys_cfg.c file are
* called to assist with accessing and configuring the board.
*
* - ConfigDevice
* - DisplayDeviceCfg
* - GetBoardSNModCfg
* - CheckModule
*
* </summary>
*/
/***************************************************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t naiapp_CAN_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = NAI_FALSE;
int32_t moduleCount;
int32_t channelCount, cardIndex, module;
uint32_t modId;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Select Card Index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCount));
/* Select Module */
stop = naiapp_query_ModuleNumber(moduleCount, 1, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &modId));
channelCount = naibrd_CAN_GetChannelCount(modId);
if ((channelCount != 0))
{
naiapp_Run_CAN_BasicOps(cardIndex, module, modId);
}
else
{
naiif_printf(" *** Module selection not recognized as valid module type for this application. ***\r\n\r\n");
}
}
naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
}
naiif_printf("\r\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
/**************************************************************************************************************/
/**
* <summary>
* naiapp_Run_CAN_Rx illustrates the methods to perform a CAN Receive operation.
*
* </summary>
*/
/**************************************************************************************************************/
static bool_t naiapp_Run_CAN_Rx(int32_t cardIndex, int32_t module, int32_t rxChannel, bool_t isJ1939)
{
int32_t channelOutRxCount;
int32_t rxFrmIdx;
bool_t bQuit = NAI_FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* delay may need to be longer or shorter depending on the frame length received, since Tx and Rx operations are being done
in the same application in one thread */
naibrd_msDelay(500);
check_status(naibrd_CAN_GetRxFIFOFrameCount(cardIndex, module, rxChannel, &channelOutRxCount));
fifoData[rxChannel - 1].numOfFramesOnFifo = channelOutRxCount;
if (channelOutRxCount == 0)
{
naiif_printf("\r\nRx No Data channel %d\r\n", rxChannel);
}
while (channelOutRxCount > 0)
{
naiif_printf("\r\nPress Enter to Read Channel Fifos...Or Press Q to quit:\r\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (isJ1939)
{
for (rxFrmIdx = 0; rxFrmIdx < channelOutRxCount; rxFrmIdx++)
memset(fifoData[rxChannel - 1].data[rxFrmIdx].dataJ1939, 0, sizeof(fifoData[rxChannel - 1].data[rxFrmIdx].dataJ1939));
}
else
{
for (rxFrmIdx = 0; rxFrmIdx < channelOutRxCount; rxFrmIdx++)
memset(fifoData[rxChannel - 1].data[rxFrmIdx].dataAB, 0, sizeof(fifoData[rxChannel - 1].data[rxFrmIdx].dataAB));
}
naiapp_getFIFOChannelData(cardIndex, module, rxChannel, fifoData);
naiif_printf("fifo DATA Received\r\n");
naiif_printf("-----------------------");
naiif_printf("\r\n");
naiapp_printFIFOChannelData(rxChannel, fifoData, isJ1939);
naiif_printf("\r\n");
naiif_printf("\r\n");
naibrd_CAN_GetRxFIFOFrameCount(cardIndex, module, rxChannel, &channelOutRxCount);
}
}
return bQuit;
}
/**************************************************************************************************************/
/**
* <summary>
* naiapp_Run_CAN_Tx illustrates the methods to perform a CAN Transmit operation.
*
* </summary>
*/
/**************************************************************************************************************/
static bool_t naiapp_Run_CAN_Tx(int32_t cardIndex, int32_t module, uint32_t modId, int32_t txChannel, bool_t isJ1939, int32_t txCount)
{
int32_t numOfFramesToTransmit = 0;
int32_t payload = 0;
uint32_t pgn = 0;
bool_t bQuit = NAI_FALSE;
int32_t txFrmIdx;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (modId == NAIBRD_MODULE_ID_CB2)
isJ1939 = NAI_TRUE;
else if (modId == NAIBRD_MODULE_ID_CB1)
isJ1939 = NAI_FALSE;
numOfFramesToTransmit = 1;
if (naiapp_IsCAN_AB(cardIndex, module, txChannel))
{
fifoData[txChannel - 1].minLength = 0;
fifoData[txChannel - 1].maxLength = NAIBRD_CAN_AB_MAX_DATA_LEN;
}
else if (naiapp_IsCAN_J1939(cardIndex, module, txChannel))
{
/*prompt user for pgn*/
if (!bQuit)
bQuit = naiapp_QueryForPGN(&pgn);
fifoData[txChannel - 1].minLength = 8;
fifoData[txChannel - 1].maxLength = 345;
}
naiif_printf("\r\n");
if (!bQuit)
{
bQuit = naiapp_QueryForPayload(&payload, fifoData[txChannel - 1].minLength, fifoData[txChannel - 1].maxLength, isJ1939);
}
if (!bQuit)
{
naiif_printf("\r\nPress Enter to Begin Transmission...Or Press Q to quit:\r\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
while (txCount > 0)
{
numOfFramesToTransmit = 1;
naiapp_generateData(txChannel, numOfFramesToTransmit, payload, isJ1939, fifoData);
for (txFrmIdx = 0; txFrmIdx < txCount; txFrmIdx++)
fifoData[txChannel - 1].data[txFrmIdx].length = payload;
txCount--;
naiapp_transmitFIFOChannelData_PGN(cardIndex, module, txChannel, pgn, fifoData, numOfFramesToTransmit);
naiif_printf("fifo DATA Transmitted\r\n");
naiif_printf("-----------------------");
naiif_printf("\r\n");
naiapp_printFIFOChannelData(txChannel, fifoData, isJ1939);
naiif_printf("\r\n");
naiif_printf("\r\n");
}
}
}
return bQuit;
}
/**************************************************************************************************************/
/**
* <summary>
* naiapp_Run_CAN_BasicOps illustrates the methods to configure the Rx and Tx channels and makes calls to
* naiapp_Run_CAN_Tx and naiapp_Run_CAN_Rx to perform the CAN Transmit and Receive respectively.
*
* </summary>
*/
/**************************************************************************************************************/
static bool_t naiapp_Run_CAN_BasicOps(int32_t cardIndex, int32_t module, uint32_t modId)
{
int8_t txOutCount[80];
bool_t bContinue = NAI_TRUE;
bool_t bQuit = NAI_FALSE;
int32_t maxChannel;
int32_t txChannel;
int32_t rxChannel;
int32_t minChannel;
int32_t txCount;
int32_t txFrmIdx;
bool_t isJ1939 = NAI_TRUE;
bool_t bitComplete;
naibrd_can_baud_rate_type_t baudRate = NAIBRD_CAN_BAUD_UNASSIGNED;
nai_status_t bitStatus;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
while (bContinue)
{
maxChannel = naibrd_CAN_GetChannelCount(modId);
minChannel = 1;
naiif_printf("\r\nPlease connect the Transmit channel to a Receive channel and hit Enter to continue or q to quit\r\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiif_printf("\r\nWhich channel would you like to Transmit on ?");
bQuit = naiapp_query_ChannelNumber(maxChannel, minChannel, &txChannel);
if (!bQuit)
{
naiif_printf("\r\nHow many times would you like to Transmit? [default = 1]\r\n");
memset(txOutCount, 0x00, sizeof(txOutCount));
naiapp_fgets_stdin(txOutCount, sizeof(txOutCount));
txCount = atoi((const char *)txOutCount);
if (txCount == 0)
{
txCount = 1;
}
/* query for protocol - for J1939 capable modules only, otherwise no query will occur, and isJ1939 will be set to NAI_FALSE */
bQuit = naiapp_QueryForChannelProtocol(modId, &isJ1939);
if (!bQuit)
{
if (isJ1939)
{
for (txFrmIdx = 0; txFrmIdx < txCount; txFrmIdx++)
memset(fifoData[txChannel - 1].data[txFrmIdx].dataJ1939, 0, sizeof(fifoData[txChannel - 1].data[txFrmIdx].dataJ1939));
/* Check for PBIT complete Tx channel*/
check_status(naibrd_CAN_CheckBITComplete(cardIndex, module, txChannel, &bitComplete));
if (bitComplete)
naiif_printf("\r\nPBIT was completed for Tx channel %d\r\n\r\n", txChannel);
else
naiif_printf("PBIT was not completed for Tx channel %d\r\n\r\n", txChannel);
/* Initiate Bit for Rx and Tx Channels */
bitStatus = naibrd_CAN_InitiateBIT(cardIndex, module, txChannel, NAI_TRUE);
if (bitStatus == NAI_SUCCESS)
{
naiif_printf("IBIT for Tx channel %d passes\r\n\r\n", txChannel);
bQuit = NAI_FALSE;
}
else
{
naiif_printf("IBIT for Tx channel %d Fails with a status of %d\r\n\r\n", txChannel, bitStatus);
bQuit = NAI_TRUE;
}
check_status(naibrd_CAN_SetProtocol(cardIndex, module, txChannel, NAIBRD_CAN_PROTOCOL_J1939));
}
else
{
for (txFrmIdx = 0; txFrmIdx < txCount; txFrmIdx++)
memset(fifoData[txChannel - 1].data[txFrmIdx].dataAB, 0, sizeof(fifoData[txChannel - 1].data[txFrmIdx].dataAB));
/* Check for PBIT complete Tx channel*/
check_status(naibrd_CAN_CheckBITComplete(cardIndex, module, txChannel, &bitComplete));
if (bitComplete)
naiif_printf("\r\nPBIT was completed for Tx channel %d\r\n\r\n", txChannel);
else
naiif_printf("PBIT was not completed for Tx channel %d\r\n\r\n", txChannel);
/* Initiate Bit for Tx Channel */
bitStatus = naibrd_CAN_InitiateBIT(cardIndex, module, txChannel, NAI_TRUE);
if (bitStatus == NAI_SUCCESS)
{
naiif_printf("IBIT for Tx channel %d passes\r\n\r\n", txChannel);
bQuit = NAI_FALSE;
}
else
{
naiif_printf("IBIT for Tx channel %d Fails with a status of %d\r\n\r\n", txChannel, bitStatus);
bQuit = NAI_TRUE;
}
if(!bQuit)
check_status(naibrd_CAN_SetProtocol(cardIndex, module, txChannel, NAIBRD_CAN_PROTOCOL_AB));
}
}
else
{
bContinue = NAI_FALSE;
}
if (!bQuit)
{
naiif_printf("\r\nFor the Receive channel:");
bQuit = naiapp_query_ChannelNumber(maxChannel, 2, &rxChannel);
if (!bQuit)
{
/* Check for PBIT complete Rx channel */
check_status(naibrd_CAN_CheckBITComplete(cardIndex, module, rxChannel, &bitComplete));
if (bitComplete)
naiif_printf("\r\nPBIT was completed for Rx channel %d\r\n\r\n", rxChannel);
else
naiif_printf("\r\nPBIT was not completed for Rx channel %d\r\n\r\n", rxChannel);
/* Initiate Bit for Rx Channel */
bitStatus = naibrd_CAN_InitiateBIT(cardIndex, module, rxChannel, NAI_TRUE);
if (bitStatus == NAI_SUCCESS)
{
naiif_printf("IBIT for Rx channel %d passes\r\n\r\n", rxChannel);
bQuit = NAI_FALSE;
}
else
{
naiif_printf("IBIT for Rx channel %d Fails with a status of %d\r\n\r\n", rxChannel, bitStatus);
bQuit = NAI_TRUE;
}
if (!bQuit)
{
bQuit = naiapp_QueryUserForCANTiming(&baudRate, isJ1939);
if (!bQuit)
{
if (modId == NAIBRD_MODULE_ID_CB3 || modId == NAIBRD_MODULE_ID_CB6)
{
if (isJ1939)
{
naiapp_setChannelToCANJ1939_R(cardIndex, module, modId, rxChannel);
}
else if (!bQuit)
{
naiapp_setChannelToCANAB_R(cardIndex, module, modId, rxChannel);
}
}
else if (modId == NAIBRD_MODULE_ID_CB1)
{
naiapp_setChannelToCANAB_R(cardIndex, module, modId, rxChannel);
}
#if defined (NAIBRD_SSK_MODULE_ID_CB2) || defined (NAIBRD_SSK_MODULE_ID_CB3) || defined (NAIBRD_SSK_MODULE_ID_CB6)
else if (modId == NAIBRD_MODULE_ID_CB2)
{
naiapp_setChannelToCANJ1939_R(cardIndex, module, modId, rxChannel);
}
/* claim addresses for the receive channels first, this is needed so that the Tx channel sees active channels */
/*on the bus to transmit to */
if (naiapp_IsCAN_J1939(cardIndex, module, rxChannel))
{
naibrd_msDelay(250);
naiif_printf("\r\nRx Channel\r\n");
/* Rx addresses */
naiapp_claimAddresses(cardIndex, module, rxChannel);
naiif_printf("\r\n");
naibrd_msDelay(250);
naiif_printf("Tx Channel\r\n");
/* Tx addresses */
naiapp_claimAddresses(cardIndex, module, txChannel);
naiif_printf("\r\n");
}
naiapp_Cfg_Rx_CAN(cardIndex, module, rxChannel, baudRate);
naiapp_Cfg_Tx_CAN(cardIndex, module, txChannel, baudRate);
#endif
}
else
{
bContinue = NAI_FALSE;
}
}
}
else
{
bContinue = NAI_FALSE;
}
if (!bQuit)
{
bQuit = naiapp_Run_CAN_Tx(cardIndex, module, modId, txChannel, isJ1939, txCount);
if (!bQuit)
{
bQuit = naiapp_Run_CAN_Rx(cardIndex, module, rxChannel, isJ1939);
if (bQuit)
bContinue = NAI_FALSE;
}
}
else
{
bContinue = NAI_FALSE;
}
}
else
{
bContinue = NAI_FALSE;
}
}
}
else
{
bContinue = NAI_FALSE;
}
}
return bQuit;
}