Integrator Resources

The official home for NAI Support

Not sure where to start? Try Quick Start Guide or ask a question below!

Toggle Components with Visual Button
JavaScript Form Processing

SER BIT

SER BIT

Explanation

About This Sample Application Code

This C application code is designed for interacting with embedded function modules from North Atlantic Industries (NAI) using the Software Support Kit (SSK). The primary focus of the code is to run built-in tests (BIT) on serial modules. Below is a detailed explanation of how this sample application works:

Included Libraries and Files

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_ser.h"
#include "advanced/nai_ether_adv.h"
  • Standard C Libraries: stdio.h, stdlib.h, string.h, time.h, ctype.h

  • NAI-Specific Libraries:

  • Board Access Headers: naiapp_boardaccess_menu.h, naiapp_boardaccess_query.h, naiapp_boardaccess_access.h, naiapp_boardaccess_display.h, naiapp_boardaccess_utils.h

  • NAI Core Headers: nai.h, naibrd.h

  • Function Headers: naibrd_ser.h, nai_ether_adv.h

These files provide the necessary interfaces to manage NAI boards, query and display information, and run specific functions like Serial BIT.

Configuration

static const int8_t *CONFIG_FILE = (const int8_t *)"default_SER_BIT.txt";

Defines a configuration file named default_SER_BIT.txt, which is used to setup the board.

Function Prototypes

void Run_SER_BIT(int32_t cardIndex, int32_t module, uint32_t moduleID);

Declaration of the function responsible for running the Serial BIT.

Main Function

#if defined (__VXWORKS__)
int32_t SER_BIT_Sample(void)
#else
int32_t main(void)
#endif

This is the entry point of the program. If the operating system is VXWORKS, it uses SER_BIT_Sample(), otherwise, it uses the main() function.

Variables

bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
  • bool_t stop: A flag to indicate if the program should stop.

  • int32_t cardIndex, moduleCnt, module, moduleID: Variables to hold card and module identifiers and count.

  • int8_t inputBuffer[80]: Buffer for user inputs.

  • int32_t inputResponseCnt: Holds the count of user input responses.

Main Logic

if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
    while (stop != TRUE)
    {
        stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
        if (stop != TRUE)
        {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
                moduleID = naibrd_GetModuleID(cardIndex, module);
                if ((moduleID != 0))
                {
                    Run_SER_BIT(cardIndex, module, moduleID);
                }
            }
        }
        printf("\nType Q to quit or Enter key to restart application:\n");
        stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
    }
}

printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();

return 0;
  1. Check Configuration: Calls naiapp_RunBoardMenu with CONFIG_FILE to setup the board.

  2. Main Loop: Continues until stop is TRUE.

    • Query Card Index: Obtains the card index using naiapp_query_CardIndex.

    • Query Module Number: Gets the number of modules using naibrd_GetModuleCount and then queries for a specific module number using naiapp_query_ModuleNumber.

    • Run SER BIT: If the module ID is valid, calls Run_SER_BIT with card index, module number and module ID.

    • User Input for Quit: Prompts the user to quit or restart the application using naiapp_query_ForQuitResponse.

  3. Close Cards: Closes all open card connections using naiapp_access_CloseAllOpenCards.

  4. Exit Program: Displays exit prompt and waits for user response.

Run_SER_BIT Function

void Run_SER_BIT(int32_t cardIndex, int32_t module, uint32_t moduleID)

This function configures a serial module, runs a BIT, and checks the results.

Variables

int32_t chanNum, channelCount;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
  • int32_t chanNum, channelCount: Variables to hold the channel number and count from the module.

  • bool_t bQuit: Flag to decide whether to quit the BIT loop.

  • int8_t inputBuffer[80]: Buffer for user inputs.

  • int32_t inputResponseCnt: Holds the user input response count.

Logic 1. Get Channel Count: Retrieves the total number of channels using naibrd_SER_GetChannelCount. 2. Query Channel Number: Queries the user for the specific channel number using naiapp_query_ChannelNumber. 3. Channel Operations: For each channel: - Get Channel State: Retrieves the current state of the channel using naibrd_SER_GetChannelEnable. - Disable Channel: Disables the channel since BIT can only run on disabled channels. - BIT for SC3 Modules: Ensures channels are disabled in pairs for SC3 modules. - BIT Execution: Initiates the BIT using naibrd_SER_InitiateBIT and checks the status. - Restore Channel State: Restores the channel’s previous state. 4. User Input: Prompts the user to rerun the BIT or exit using naiapp_query_ForQuitResponse.

In conclusion, this application demonstrates how to interact with NAI embedded function modules, particularly running built-in tests on serial modules. The program guides the user through configuration, card, and module selection, running tests, and interpreting results.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>

/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_ser.h"
#include "advanced/nai_ether_adv.h"

static const int8_t *CONFIG_FILE = (const int8_t *)"default_SER_BIT.txt";

/* Function prototypes */
void Run_SER_BIT(int32_t cardIndex, int32_t module, uint32_t moduleID);

/**************************************************************************************************************/
/** \defgroup SERBIT Serial Built-In-Test
The purpose of the Serial built-in-test sample application is to illustrate the methods to call in the
naibrd library to run the built-in-test on the serial module.
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t SER_BIT_Sample(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               if ((moduleID != 0))
               {
                  Run_SER_BIT(cardIndex, module, moduleID);
               }
            }
         }

         printf("\nType Q to quit or Enter key to restart application:\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   printf("\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();

   return 0;
}

/**************************************************************************************************************/
/** \ingroup SERBIT
Configures a serial module, runs a built-in-test and checks the results.
\param cardIndex (Input) Logical Card Index assigned to connection with the NAI_BOARD (0 - NAI_MAX_CARDS-1).
\param module    (Input) Module Number of the module to access (1 - [max modules for board]).
\param moduleID  (Input) The ID of the module.
*/
/**************************************************************************************************************/
void Run_SER_BIT(int32_t cardIndex, int32_t module, uint32_t moduleID)
{
   int32_t chanNum, channelCount;
   bool_t bQuit = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   channelCount = naibrd_SER_GetChannelCount(moduleID);
   check_status(naiapp_query_ChannelNumber(channelCount, 1, &chanNum));

   printf("\nSerial Channel # %d\n", chanNum);

   do
   {
      bool_t enable = 0;
      nai_status_t status;

      /* Get the state of the channel before BIT is executed.*/
      check_status(naibrd_SER_GetChannelEnable(cardIndex, module, chanNum, &enable));

      /* Disable the channel. Channels MUST be disabled for BIT to run. */
      check_status(naibrd_SER_SetChannelEnable(cardIndex, module, chanNum, 0));

      /* For BIT to run on the SC3 we need to make sure the channels are disabled in pairs (1 & 2, 2 & 3 etc.) */
      if (moduleID == NAI_MODULE_ID_SC3)
      {
         if ((chanNum % 2) == 0)   /* Even channel */
            check_status(naibrd_SER_SetChannelEnable(cardIndex, module, (chanNum - 1), 0));
         else
            check_status(naibrd_SER_SetChannelEnable(cardIndex, module, (chanNum + 1), 0));
      }

      /* Initiate BIT and wait for results */
      status = naibrd_SER_InitiateBIT(cardIndex, module, chanNum, NAI_SER_INITIATE_BIT_WAIT_RESULT);

      if (NAI_SUCCESS == status)
         printf("BIT Passed.\n");
      else
         check_status(status);

      /* Restore the channel's original state. */
      check_status(naibrd_SER_SetChannelEnable(cardIndex, module, chanNum, enable));

      printf("Press ENTER to run BIT again, or '%c' to exit program : ", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);

   } while (TRUE != bQuit);

   return;
}

Help Bot

X