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

nai 1553 utils

nai 1553 utils

Explanation

Overview of NAI Sample Application Code

The provided C code is a sample application for interacting with North Atlantic Industries' (NAI) embedded function modules, specifically focusing on the MIL-STD-1553 communication protocol. This application includes various utilities, queries, and configurations necessary for setting up and controlling these modules. Below is a detailed walkthrough explaining the key components and functionality of the sample code.

Include Files

The code includes several header files necessary for its operation:

  • Standard Libraries:

  • stdio.h: Standard Input/Output functions.

  • ctype.h: Character handling functions.

  • stdlib.h: Standard library functions, e.g., for memory allocation, conversion, etc.

  • string.h: String handling functions.

  • Common Sample Program Include Files: These include files specific to the NAI sample program functionalities related to interrupts, Ethernet communication, board access, query processing, display utilities, and MIL-STD-1553 utilities.

  • naiapp_interrupt.h

  • naiapp_interrupt_ether.h

  • naiapp_boardaccess_menu.h

  • naiapp_boardaccess_query.h

  • naiapp_boardaccess_access.h

  • naiapp_boardaccess_display.h

  • naiapp_boardaccess_utils.h

  • nai_1553_utils.h

  • NAI Board Include Files: These include the NAI board-specific functionalities and definitions.

  • nai.h

  • naibrd.h

  • functions/naibrd_1553.h

  • maps/nai_map_1553.h

Global Variables

  • static int32_t g_MenuCmdCnt = 0;

  • A global counter to track the menu command count.

Function Definitions

Configuration and Utility Functions:

  1. Get1553Address

    • This function prompts the user to enter a MIL-STD-1553 address. It validates the entered address against the maximum allowed address (maxaddress). If the user quits (NAI_QUIT_CHAR), the function returns TRUE.

  2. Get1553MTCfg

    • Sets up the Remote Terminal (RT) channel for the specified module by prompting the user to select a channel number. If the module supports SUMMIT1553 or FTx1553, it configures accordingly.

  3. Get1553RTCfg

    • Similar to Get1553MTCfg, this function extends the setup to also include RT address selection.

  4. Get1553BCCfg

    • Configures the Bus Controller (BC) channel for 1553 modules.

  5. IsSUMMIT1553, IsFTx1553, IsFTx1760

    • These functions check if a given module ID supports SUMMIT1553, FTx1553 or FTx1760 functionality by comparing against predefined module IDs.

  6. Get1553LogicalDevNum

    • Prompts the user to select a logical device number and validates the input.

  7. Get1553RTAddressSource

    • Prompts the user to choose the RT address source between software and external inputs.

  8. Get1553BCSoftwareOverride

    • Asks the user whether to override external inputs using software.

  9. Get1553BCAsyncMsgType

    • Allows the user to set the priority type for asynchronous messages.

  10. Get1760EEPROMCopy

    • Prompts if the memory contents should be written to EEPROM.

  11. Get1553RxBufferType

    • Provides options for selecting the Rx Buffer mode and validates the user’s choice.

Menu and Command Handling Functions:

  1. Load1553MenuCommands

    • Loads the provided menu commands into the global NAI_MenuCmds array.

  2. Display1553MenuCommands

    • Displays the list of available menu commands.

  3. Get1553CmdNum

    • Finds the command number corresponding to the user’s input command string.

  4. Menu1553Command

    • Executes the command function that corresponds to the selected command from the menu.

Interaction and Display Functions:

  1. LoadIllegalization, SaveIllegalization

    • Functions to load and save illegalization data from and to files respectively.

  2. M1553_Config_Registers, M1553_Aux_Registers

    • Prompts the user to modify the configuration and auxiliary registers and validates the changes.

  3. DisplayRegisters, DisplayAuxRegisters

    • Displays the current state of configuration and auxiliary registers.

User Input Functions:

  1. GetRTAddress

    • Prompts the user to enter an RT address within a valid range.

  2. GetTxRx

    • Asks whether the message type is to be received or transmitted.

  3. GetSubaddress

    • Prompts the user to enter a subaddress.

  4. GetWordCount

    • Asks the user for the word count value within a specific range.

Memory Test Functions:

  1. MemoryTest, MemoryTestFast

    • Functions to perform memory tests on the specified device/channel and report any errors.

Overall, the sample application provides comprehensive utilities for interacting with NAI’s MIL-STD-1553 modules, allowing users to set up, configure, and test these modules effectively. The code is structured to ensure meaningful user interactions and validations during these processes.

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

/* Common Sample Program include files */
#include "include/naiapp_interrupt.h"
#include "include/naiapp_interrupt_ether.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_1553_utils.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_1553.h"
#include "maps/nai_map_1553.h"

static int32_t g_MenuCmdCnt = 0;

bool_t Get1553Address(int32_t maxaddress, int8_t defaddress, uint8_t *address)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (maxaddress > 1)
   {
      while (bContinue)
      {
         printf("\nEnter address [default=%d]: ", defaddress);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt == 0)
               *address = defaddress;
            else
               *address = (uint8_t)atol((const char*)inputBuffer);
            if ((*address < 0) || (*address > maxaddress))
               printf("ERROR: Invalid address value.\n\n");
            else
               bContinue = FALSE;
         }
      }
   }
   else
      *address = 0;
   return bQuit;
}

bool_t Get1553MTCfg(uint32_t modid, int32_t defchan, int32_t *rtchan )
{
   bool_t bQuit = FALSE;
   int32_t MaxChannel;

   if (IsSUMMIT1553(modid))
   {
      /* Get the number of 1553 channels on the module */
      MaxChannel = 2;
      /* Get the RT channel */
      printf("\nRemote Terminal Setup\n");
      printf("---------------------\n");
      printf("1553 RT Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, rtchan);
   }
   else if (IsFTx1553(modid))
   {
      MaxChannel = 4;
      /* Get the RT channel */
      printf("\nRemote Terminal Setup\n");
      printf("---------------------\n");
      printf("1553 RT Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, rtchan);
   }
   else
      printf("ERROR: Module selected does not support 1553 Functionality\n");

   return bQuit;
}

bool_t Get1553RTCfg(uint32_t modid, int32_t defchan, uint8_t defaddr, int32_t *rtchan, uint8_t *rtaddr )
{
   bool_t bQuit = FALSE;
   int32_t MaxChannel;

   if (IsSUMMIT1553(modid))
   {
      /* Get the number of 1553 channels on the module */
      MaxChannel = 2;
      /* Get the RT channel */
      printf("\nRemote Terminal Setup\n");
      printf("---------------------\n");
      printf("1553 RT Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, rtchan);
      if (!bQuit)
      {
         printf("1553 RT Address Selection:");
         bQuit = Get1553Address(31, defaddr, rtaddr);
      }
   }
   else if (IsFTx1553(modid))
   {
      MaxChannel = 4;
      /* Get the RT channel */
      printf("\nRemote Terminal Setup\n");
      printf("---------------------\n");
      printf("1553 RT Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, rtchan);
      if (!bQuit)
      {
         printf("1553 RT Address Selection:");
         bQuit = Get1553Address(31, defaddr, rtaddr);
      }
   }
   else if (IsFTx1760(modid))
   {
      MaxChannel = 4;
      /* Get the RT channel */
      printf("\nRemote Terminal Setup\n");
      printf("---------------------\n");
      printf("1760 RT Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, rtchan);
      if (!bQuit)
      {
         printf("1760 RT Address Selection:");
         bQuit = Get1553Address(31, defaddr, rtaddr);
      }
   }
   else
      printf("ERROR: Module selected does not support 1553 Functionality\n");

   return bQuit;
}

bool_t Get1553BCCfg(uint32_t modid, int32_t defchan, int32_t *bcchan )
{
   bool_t bQuit = FALSE;
   int32_t MaxChannel;

   if (IsSUMMIT1553(modid))
   {
      MaxChannel = 2;

      /* Get the BC channel */
      printf("\nBus Controller Setup:\n");
      printf("---------------------\n");
         printf("1553 BC Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, bcchan);
   }
   else if (IsFTx1553(modid))
   {
      MaxChannel = 4;

      /* Get the BC channel */
      printf("\nBus Controller Setup:\n");
      printf("---------------------\n");
         printf("1553 BC Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, bcchan);
   }
   else
      printf("ERROR: Module selected does not support Summit 1553 Functionality\n");

   return bQuit;
}

bool_t IsSUMMIT1553(uint32_t moduleID)
{
   bool_t bSupportSUM1553Func = FALSE;
   switch (moduleID)
   {
      case NAI_MODULE_ID_N7:
      case NAI_MODULE_ID_N8:
      case NAI_MODULE_ID_NA:
      case NAI_MODULE_ID_NB:
      case NAI_MODULE_ID_NC:
         bSupportSUM1553Func = TRUE;
         break;
      default:
         bSupportSUM1553Func = FALSE;
         break;
   }
   return bSupportSUM1553Func;
}

bool_t IsFTx1553(uint32_t moduleID)
{
   bool_t bSupportFTx1553Func = FALSE;
   switch (moduleID)
   {
      case NAI_MODULE_ID_FT0:
      case NAI_MODULE_ID_FT1:
      case NAI_MODULE_ID_FT2:
      case NAI_MODULE_ID_FT3:
      case NAI_MODULE_ID_FT4:
      case NAI_MODULE_ID_FT5:
      case NAI_MODULE_ID_FT6:
      case NAI_MODULE_ID_FT7:
      case NAI_MODULE_ID_FT8:
      case NAI_MODULE_ID_FT9:
      case NAI_MODULE_ID_FTA:
      case NAI_MODULE_ID_FTB:
      case NAI_MODULE_ID_FTC:
      case NAI_MODULE_ID_FTD:
      case NAI_MODULE_ID_FTE:
      case NAI_MODULE_ID_FTF:
      case NAI_MODULE_ID_FTPIB:
      case NAI_MODULE_ID_FTK:
      case NAI_MODULE_ID_CM1:
      case NAI_MODULE_ID_CM5:
      case NAI_MODULE_ID_CM8:
         bSupportFTx1553Func = TRUE;
         break;
      default:
         bSupportFTx1553Func = FALSE;
         break;
   }
   return bSupportFTx1553Func;
}

bool_t IsFTx1760(uint32_t moduleID)
{
   bool_t bSupportFTx1760Func = FALSE;
   switch (moduleID)
   {
      case NAI_MODULE_ID_FTK:
         bSupportFTx1760Func = TRUE;
         break;
      default:
         bSupportFTx1760Func = FALSE;
         break;
   }
   return bSupportFTx1760Func;
}

bool_t Get1553LogicalDevNum(int16_t defdevnum, int16_t *devnum)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nSelect Logical Device Number (0-31). This must be a unique number specific to this channel/device. [Default=%d]: ", defdevnum);
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *devnum = defdevnum;
            bValidEntry = TRUE;
         }
         else if (atoi((char *)inputBuffer) < 0 || atoi((char *)inputBuffer) > 31)
            printf("\nPlease Select a Valid Logical Device Number (0-31) [Default=%d]: ", defdevnum);
         else
         {
            *devnum = (int16_t)atoi((char *)inputBuffer);
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

bool_t Get1553RTAddressSource(bool_t defSoftware, bool_t *bSoftware)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nSelect RT Address Source (S - Software, E - External Inputs) [Default=%s]: ", defSoftware ? "S" : "E");
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *bSoftware = defSoftware;
            bValidEntry = TRUE;
         }
         else if ((toupper(inputBuffer[0]) != 'S') && (toupper(inputBuffer[0]) != 'E'))
            printf("\nPlease Select a Valid RT Address Source (S - Software, E - External Inputs) [Default=%s]: ", defSoftware ? "S" : "E");
         else
         {
            *bSoftware = (toupper(inputBuffer[0]) == 'S') ? TRUE : FALSE;
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

bool_t Get1553BCSoftwareOverride(bool_t defSoftware, bool_t *bSoftware)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nOverride External Inputs (Y or N)? [Default=%s]: ", defSoftware ? "Y" : "N");
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *bSoftware = defSoftware;
            bValidEntry = TRUE;
         }
         else if ((toupper(inputBuffer[0]) != 'Y') && (toupper(inputBuffer[0]) != 'N'))
            printf("\nPlease Input Y or N. Override External Inputs? [Default=%s]: ", defSoftware ? "Y" : "N");
         else
         {
            *bSoftware = (toupper(inputBuffer[0]) == 'Y') ? TRUE : FALSE;
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

bool_t Get1553BCAsyncMsgType(bool_t defPriorityHigh, bool_t *bHighPriority)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nAsync Message Type High or Low (H or L)? [Default=%s]: ", defPriorityHigh ? "H" : "L");
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *bHighPriority = defPriorityHigh;
            bValidEntry = TRUE;
         }
         else if ((toupper(inputBuffer[0]) != 'H') && (toupper(inputBuffer[0]) != 'L'))
            printf("\nPlease Input H or L. Async Message Type High or Low (H or L)? [Default=%s]: ", defPriorityHigh ? "H" : "L");
         else
         {
            *bHighPriority = (toupper(inputBuffer[0]) == 'H') ? TRUE : FALSE;
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

bool_t Get1760EEPROMCopy(bool_t defCopyToEEPROM, bool_t* bCopyToEEPROM)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nWrite Memory Contents to EEPROM? [Default=%s]: ", defCopyToEEPROM ? "Y" : "N");
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *bCopyToEEPROM = defCopyToEEPROM;
            bValidEntry = TRUE;
         }
         else if ((toupper(inputBuffer[0]) != 'Y') && (toupper(inputBuffer[0]) != 'N'))
            printf("\nPlease Input Y or N. Write Memory Contents to EEPROM? [Default=%s]: ", defCopyToEEPROM ? "Y" : "N");
         else
         {
            *bCopyToEEPROM = (toupper(inputBuffer[0]) == 'Y') ? TRUE : FALSE;
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

bool_t Get1553RxBufferType(uint16_t defrxbuffertype, uint16_t *rxbuffertype)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nSelect Rx Buffer Mode:\n\n");
   printf("Single Buffer                        1-32 (number represents size of buffer)\n");
   printf("Double Buffer                        33\n");
   printf("Circular Buffer - 128 words          34\n");
   printf("Circular Buffer - 256 words          35\n");
   printf("Circular Buffer - 512 words          36\n");
   printf("Circular Buffer - 1024 words         37\n");
   printf("Circular Buffer - 2048 words         38\n");
   printf("Circular Buffer - 4096 words         39\n");
   printf("Circular Buffer - 8192 words         40\n");
   printf("Global Circular Buffer - 128 words   41\n");
   printf("Global Circular Buffer - 256 words   42\n");
   printf("Global Circular Buffer - 512 words   43\n");
   printf("Global Circular Buffer - 1024 words  44\n");
   printf("Global Circular Buffer - 2048 words  45\n");
   printf("Global Circular Buffer - 4096 words  46\n");
   printf("Global Circular Buffer - 8192 words  47\n");
   printf("\n\nEnter a Number between 1 and 47 [Default=%d]: ", defrxbuffertype);
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *rxbuffertype = defrxbuffertype;
            bValidEntry = TRUE;
         }
         else if (atoi((char *)inputBuffer) < 1 || atoi((char *)inputBuffer) > 47)
            printf("\nPlease Enter a valid Number between 1 and 47 [Default=%d]: ", defrxbuffertype);
         else
         {
            *rxbuffertype = (uint16_t)atoi((char *)inputBuffer);
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

/****** Command Tables *******/
static nai_1553_cmdtbl_type NAI_MenuCmds[25];

void Load1553MenuCommands(int32_t menuCmdCnt, nai_1553_cmdtbl_type menuCmds[])
{
   int32_t i;
   g_MenuCmdCnt = menuCmdCnt;
   /* Load the NAI_MenuCmds structure */
   for (i = 0; i < g_MenuCmdCnt; i++)
   {
      strcpy((char *)NAI_MenuCmds[i].cmdstr, (const char *)menuCmds[i].cmdstr);
      strcpy((char *)NAI_MenuCmds[i].menustr, (const char *)menuCmds[i].menustr);
      NAI_MenuCmds[i].cmdnum = menuCmds[i].cmdnum;
      NAI_MenuCmds[i].func = menuCmds[i].func;
   }
}

void Display1553MenuCommands(int8_t *menuTitle)
{
   int32_t i;

   printf("\n\n\n\t\t %s\n ", menuTitle);
   printf("\n ======== Command Selections ===============");
   for (i=0; i < g_MenuCmdCnt && NAI_MenuCmds[i].cmdstr != NULL; i++)
      printf ("\n %-8s \t%s", NAI_MenuCmds[i].cmdstr, NAI_MenuCmds[i].menustr);
   printf("\n");
}

bool_t Get1553CmdNum(int32_t cmdrequestCnt, int8_t *cmdrequest, int32_t* cmdNum)
{
   bool_t bCmdFound = FALSE;
   int32_t i;

   for (i = 0; i < g_MenuCmdCnt; i++)
   {
      if (naiapp_strnicmp(cmdrequest, NAI_MenuCmds[i].cmdstr, cmdrequestCnt) == 0)
      {
         bCmdFound = TRUE;
         *cmdNum = i;
         break;
      }
   }
   return bCmdFound;
}

void Menu1553Command(int32_t cmd, int16_t devnum)
{
   NAI_MenuCmds[cmd].func(devnum);
}

void LoadIllegalization(int16_t devnum, int32_t channel)
{
   uint8_t filename[128];
   FILE* deffile = NULL;
   int8_t buffer[128];
   int8_t *pval;
   uint32_t count = 0;

   sprintf((char *)filename, "illegalizationCh%d.txt", channel);
   deffile = fopen((const char *)filename,"r");
   if (deffile != NULL)
   {
      while (fgets((char*)buffer,sizeof(buffer),deffile) && count < 0x100)
      {
         pval = (int8_t*)strchr((char*)buffer,'\n');
         if (pval)
            *pval = '\0'; /* Remove LF */
         naibrd_1553_WriteMem(devnum, 0x300+count, (uint16_t)atol((const char*)buffer));
         count++;
      }
      fclose(deffile);
   }
}

void SaveIllegalization(int16_t devnum, int32_t channel)
{
   uint8_t filename[128];
   FILE* deffile = NULL;
   int32_t i;

   sprintf((char *)filename, "illegalizationCh%d.txt", channel);
   deffile = fopen((const char *)filename,"w");
   if (deffile != NULL)
   {
      for (i = 0x300; i <= 0x3FF; i++)
      {
         fprintf(deffile, "%d\n", naibrd_1553_ReadMem(devnum, i));
      }
   }
   fclose(deffile);
}

bool_t M1553_Config_Registers(int16_t devnum)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   uint16_t registervalue;
   uint32_t registeraddr;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /* Display current state of registers */
   DisplayRegisters(devnum);

   while (bContinue)
   {
      /* Prompt User to change the value of a particular register */
      printf("\nSelect Register Address (0x00-0x1F) to Set (or Q to quit): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         registeraddr = naiapp_utils_HexStrToDecUInt32((int8_t*)inputBuffer);

         if (registeraddr >= 0 && registeraddr < 32)
         {
            while (bContinue)
            {
               printf("\nEnter the value (0x0000-0xFFFF) to set (or Q to quit): ");
               bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
               if (!bQuit)
               {
                  if (inputResponseCnt > 0)
                  {
                     registervalue = naiapp_utils_HexStrToDecUInt16((int8_t*)inputBuffer);
                     check_status(naibrd_1553_WriteReg(devnum, registeraddr, registervalue));
                     bContinue = FALSE;
                  }
                  else
                     printf("\nInvalid Value. \n");
               }
               else
                  bContinue = FALSE;
            }
         }
         else
            printf("\nInvalid Value. \n");
      }
      else
         bContinue = FALSE;
   }

   return FALSE;
}

bool_t M1553_Aux_Registers(int16_t devnum)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   uint16_t registervalue;
   uint32_t registeraddr;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /* Display current state of aux registers */
   DisplayAuxRegisters(devnum);

   while (bContinue)
   {
      /* Prompt User to change the value of a particular register */
      printf("\nSelect Auxiliary Register Address (0x00-0xF) to Set (or Q to quit): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         registeraddr = naiapp_utils_HexStrToDecUInt32((int8_t*)inputBuffer);

         if (registeraddr >= 0 && registeraddr < 32)
         {
            while (bContinue)
            {
               printf("\nEnter the value (0x0000-0xFFFF) to set (or Q to quit): ");
               bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
               if (!bQuit)
               {
                  if (inputResponseCnt > 0)
                  {
                     registervalue = naiapp_utils_HexStrToDecUInt16((int8_t*)inputBuffer);
                     check_status(naibrd_1553_WriteAuxReg(devnum, registeraddr, registervalue));
                     bContinue = FALSE;
                  }
                  else
                     printf("\nInvalid Value. \n");
               }
               else
                  bContinue = FALSE;
            }
         }
         else
            printf("\nInvalid Value. \n");
      }
      else
         bContinue = FALSE;
   }

   return FALSE;
}

void DisplayRegisters(int16_t devnum)
{
   int32_t i;
   uint16_t registervalue;

   printf("\n\n");
   printf("********** CONFIGURATION REGISTERS **********\n");
   printf("ADDRESS        VALUE                         \n");

   for (i = 0; i < 32; i++)
   {
      registervalue = naibrd_1553_ReadReg(devnum, i);
      printf(" 0x%02X      0x%02X                       \n", i, registervalue);
   }
   printf("\n\n");
}

void DisplayAuxRegisters(int16_t devnum)
{
   int32_t i;
   uint16_t registervalue;

   printf("\n\n");
   printf("********** AUXILLARY REGISTERS **********\n");
   printf("ADDRESS        VALUE                     \n");

   for (i = 0; i < 16; i++)
   {
      registervalue = naibrd_1553_ReadAuxReg(devnum, i);
      printf(" 0x%02X      0x%02X                       \n", i, registervalue);
   }
   printf("\n\n");
}

bool_t GetRTAddress(int32_t* nRTaddress)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int32_t value;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nWhat is the RT Address of the command word (0 to 31)? ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         value = atoi((const char*)inputBuffer);
         if (value >= 0 && value < 32)
         {
            *nRTaddress = value;
            bContinue = FALSE;
         }
         else
            printf("\nInvalid Command.\n");
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

bool_t GetTxRx(bool_t* bTxMsg)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nReceive (R) or Transmit (T) Message? ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (toupper(inputBuffer[0]) == 'R')
         {
            *bTxMsg = FALSE;
            bContinue = FALSE;
         }
         else if (toupper(inputBuffer[0]) == 'T')
         {
            *bTxMsg = TRUE;
            bContinue = FALSE;
         }
         else
            printf("\nInvalid Command.\n");
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

bool_t GetSubaddress(int32_t* nSubaddress)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int32_t value;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nSubaddress (0 to 31)? ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         value = atoi((const char*)inputBuffer);
         if (value >= 0 && value < 32)
         {
            *nSubaddress = value;
            bContinue = FALSE;
         }
         else
            printf("\nInvalid Command.\n");
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

bool_t GetWordCount(int32_t* nWordCount)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int32_t value;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nWord Count (1 to 32)? ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         value = atoi((const char*)inputBuffer);
         if (value > 0 && value <= 32)
         {
            *nWordCount = value;
            bContinue = FALSE;
         }
         else
            printf("\nInvalid Command.\n");
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

int32_t MemoryTest(int16_t devnum)
{
   int32_t counter = 0;
   int32_t ErrCnt = 0;
   uint16_t testValues[6] = {0x0000, 0x5555, 0xAAAA, 0xA5A5, 0x5A5A, 0xFFFF};
   uint16_t readValue;
   int32_t i;

   printf("\nDevNum %d - Memory Test started. Please wait for test to complete...\n\n", devnum);

   while (counter < NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY)
   {
      for (i = 0; i < sizeof(testValues)/sizeof(testValues[0]); i++)
      {
         naibrd_1553_WriteMem(devnum, counter, testValues[i]);
         readValue = naibrd_1553_ReadMem(devnum, counter);
         /* If write/read values do not match */
         if (readValue != testValues[i])
         {
            ErrCnt++;
            printf("\nData Mismatch! Memory Location: 0x%04X, WriteVal: 0x%04X, ReadVal: 0x%04X, ErrCnt: %d\n\n", counter, testValues[i], readValue, ErrCnt);
         }
      }

      counter++;

      /* Display Progress */
      if ((counter % 1000) == 250)
         printf("\\ %d%% Complete\r", (counter*100)/NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY);
      else if ((counter % 1000) == 500)
         printf("| %d%% Complete\r", (counter*100)/NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY);
      else if ((counter % 1000) == 750)
         printf("/ %d%% Complete\r", (counter*100)/NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY);
      else if ((counter % 1000) == 0)
         printf("- %d%% Complete\r", (counter*100)/NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY);
   }

   printf("\nDevNum %d - Memory Test Complete. ErrCnt = %d\n\n", devnum, ErrCnt);

   return ErrCnt;
}

int32_t MemoryTestFast(int16_t cardIndex, int16_t module, int16_t channel)
{
   int32_t ErrCnt = 0;
   uint16_t testValues[6] = {0x0000, 0x5555, 0xAAAA, 0xA5A5, 0xFFFF};
   uint32_t testValues32[6] = {0x00000000, 0x55555555, 0xAAAAAAAA, 0xA5A5A5A5, 0xFFFFFFFF};
   int32_t i,j,testIndex;
   uint16_t data[NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY];
   uint32_t data32[NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY];
   uint16_t readdata[NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY];
   uint32_t readdata32[NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY];
   uint32_t M1553memory[4] = NAI_1553_GEN5_REG_MEMORY_ADD;
   uint32_t M1553memory32[4] = NAI_1553_GEN5_32BIT_REG_MEMORY_ADD;
   uint32_t modid;
   int32_t maxmemorysize;
   uint32_t modprocrev, modfpgarev;

   printf("\nChannel %d - Memory Test started. Please wait for test to complete...\n\n", channel);

   modid = naibrd_GetModuleID(cardIndex, module);
   naibrd_GetModuleRev(cardIndex, module, &modprocrev, &modfpgarev);

   if (modfpgarev >= 0x100)
      memcpy(M1553memory, M1553memory32, sizeof(uint32_t)*4);

   if (modid == NAI_MODULE_ID_FT3 || modid == NAI_MODULE_ID_FT6 || modid == NAI_MODULE_ID_FT9)
      maxmemorysize = NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY / 2;
   else
      maxmemorysize = NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY;

   for (i = 0; i < sizeof(testValues)/sizeof(testValues[0]); i++)
   {
      for (testIndex = 0; testIndex < maxmemorysize; testIndex++)
      {
         if (i == 0)
         {
            data[testIndex] = testValues[i]++;
            if (modfpgarev >= 0x100)
               data32[testIndex] = testValues32[i]++;
            else
               data32[testIndex] = testValues[i]++;
         }
         else
         {
            data[testIndex] = testValues[i];
            if (modfpgarev >= 0x100)
               data32[testIndex] = testValues32[i];
            else
               data32[testIndex] = testValues[i];
         }
      }
      if (i == 0)
         printf("Writing Incremental Data to %d words in RAM\n", maxmemorysize);
      else
      {
         if (modfpgarev >= 0x100)
            printf("Writing 0x%08X to %d words in RAM\n", testValues32[i], maxmemorysize);
         else
            printf("Writing 0x%04X to %d words in RAM\n", testValues[i], maxmemorysize);
      }
      if (modfpgarev >= 20)
         naibrd_Write32(cardIndex, module, M1553memory[channel - 1] << 1, 4, maxmemorysize, NAI_REG32, data32);
      else
         naibrd_Write16(cardIndex, module, M1553memory[channel - 1], 2, maxmemorysize, NAI_REG16, data);
      printf("Reading %d words in RAM\n", maxmemorysize);
      if (modfpgarev >= 20)
         naibrd_Read32(cardIndex, module, M1553memory[channel - 1] << 1, 4, maxmemorysize, NAI_REG32, &readdata32[0]);
      else
         naibrd_Read16(cardIndex, module, M1553memory[channel - 1], 2, maxmemorysize, NAI_REG16, &readdata[0]);
      for (j = 0; j < maxmemorysize; j++)
      {
         /* If write/read values do not match */
         if (modfpgarev >= 20)
         {
            if (readdata32[j] != data32[j])
            {
               ErrCnt++;
               printf("\nData Mismatch! Memory Location: 0x%04X, WriteVal: 0x%04X, ReadVal: 0x%04X, ErrCnt: %d\n\n", j, data32[j], readdata32[j], ErrCnt);
            }
         }
         else
         {
            if (readdata[j] != data[j])
            {
               ErrCnt++;
               printf("\nData Mismatch! Memory Location: 0x%04X, WriteVal: 0x%04X, ReadVal: 0x%04X, ErrCnt: %d\n\n", j, data[j], readdata[j], ErrCnt);
            }
         }
      }
      if (ErrCnt == 0)
      {
         printf("Test Passed\n");
      }
   }

   printf("\nChannel %d - Memory Test Complete. ErrCnt = %d\n\n", channel, ErrCnt);

   return ErrCnt;
}

Help Bot

X