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

M1760 EEPROM Copy

M1760 EEPROM Copy

Explanation

About the M1760_EEPROM_Copy Application

This application, "M1760_EEPROM_Copy," demonstrates how to interact with North Atlantic Industries (NAI) embedded function modules to program a serial EEPROM with data from HI-6131 registers and RAM. It specifically supports FTJ and FTK modules and requires several steps involving user interaction and device configuration to function correctly.

Purpose The application showcases the methods provided by the naibrd library to program the EEPROM. To run the application successfully, the device must be reset at least once via software after power-up, which is handled by the naibrd_1760_Initialize() function. The process includes: 1. Configuring the system. 2. Querying user inputs for card and module selections. 3. Executing the EEPROM programming sequence.

Key Files and Definitions Include Files - Standard Libraries: - stdio.h, stdlib.h, string.h, time.h, ctype.h - Sample Program Include Files: - naiapp_boardaccess_menu.h, naiapp_boardaccess_query.h, naiapp_boardaccess_access.h, naiapp_boardaccess_display.h, naiapp_boardaccess_utils.h - Common 1553 Sample Program Include File: - nai_1553_utils.h - NAI Board Include Files: - nai.h, naibrd.h, naibrd_1553.h, naibrd_1760.h

Constants - CONFIG_FILE states the configuration file: "default_1760_EEPROMCopy.txt". - Default settings: DEF_CHANNEL set to 1, DEF_DEV_NUM set to 1, and DEF_WRITE_ZEROS set to FALSE.

Function Prototypes - Run_M1760_EEPROM_Copy: Executes the EEPROM copy routine. - Get1760EEPROMWriteZeros: Queries whether to clear out RAM.

Enumerations and Types - bool_t: A boolean type indicating true/false states. - int8_t, int16_t, int32_t: Integer types of varying bit-lengths.

Main Logic Flow Entry Point: main 1. Initialization: Checks if the application can run the board menu using naiapp_RunBoardMenu(CONFIG_FILE). 2. User Input Loop: - Queries the user for card index and module number. - Retrieves the module ID and calls Run_M1760_EEPROM_Copy with the selected parameters. - Provides an option to quit or restart the application. 3. Exit: Closes all open card handles and exits.

EEPROM Copy Function: Run_M1760_EEPROM_Copy 1. Module ID Check: Ensures only compatible modules are supported. 2. User Interaction: - Queries for channel number and logical device number. - Optionally clears out RAM based on user input. 3. Device Operations: - Opens the card/module/channel handle using naibrd_1553_Open. - Resets the device and optionally writes zeros to RAM. - Unlocks the EEPROM and initiates the EEPROM copy process. - Waits for the device to indicate that the EEPROM copy is complete.

User Query Helpers - naiapp_query_CardIndex, naiapp_query_ModuleNumber: Get user inputs for card index and module number. - naiapp_query_ForQuitResponse: Provides a quitting mechanism where the user can exit or continue. - Get1760EEPROMWriteZeros: Asks whether all registers should be zeroed out before EEPROM writing.

Usage and Configuration Before running the application: 1. Ensure the appropriate configuration file (default_1760_EEPROMCopy.txt) is available. 2. Run the application to interactively select card and module, then initiate the EEPROM programming process.

This comprehensive guide helps users understand and navigate the M1760_EEPROM_Copy application while detailing its functionality, key components, and user interactions.

#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"

/* Common 1553 Sample Program include files */
#include "nai_1553_utils.h"

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

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

/* Function prototypes */
static bool_t Run_M1760_EEPROM_Copy(int32_t cardIndex, int32_t module, uint32_t modid);
bool_t Get1760EEPROMWriteZeros(bool_t defWriteZeros, bool_t* bWriteZeros);

static const int32_t DEF_CHANNEL       = 1;
static const int16_t DEF_DEV_NUM       = 1;
static const bool_t DEF_WRITE_ZEROS    = FALSE;

/**************************************************************************************************************/
/**
<summary>
The purpose of the M1760_EEPROM_Copy application is to illustrate the methods to call in the naibrd library to
program the serial EEPROM with data from the HI-6131 registers and RAM. Only FTJ/FTK modules are supported in
this application.

NOTE: To run this application and copy to EEPROM successfully after power-up, the device must be reset at least
once via software by setting and resetting the Master Reset bit. This is automatically performed in the call to
naibrd_1760_Initialize(). For instance, running the M1553_RT_Receive sample application on the desired 1760
channel, then running M1760_EEPROM_Copy on the same channel should allow successful programming of the EEPROM.

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 1553 routines.
 - ConfigDevice
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - CheckModule
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t M1760_EEPROM_Copy(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_M1760_EEPROM_Copy(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;
}

static bool_t Run_M1760_EEPROM_Copy(int32_t cardIndex, int32_t module, uint32_t modid)
{
   /* Variables */
   bool_t bQuit = FALSE;
   int16_t DevNum           = 0;
   int32_t swResult;
   int32_t MaxChannel = 2, channel;
   bool_t ready;
   bool_t bWriteZeros;

   if (modid != NAI_MODULE_ID_FTK)
   {
      printf("This module does not support EEPROM copy capability\n");
      return TRUE;
   }

   /* Get Card, Module, Channel Numbers and Open a Handle */
   bQuit = naiapp_query_ChannelNumber(MaxChannel, DEF_CHANNEL, &channel);
   if (bQuit)
   {
      return bQuit;
   }

   /* Get Logical Device # */
   bQuit = Get1553LogicalDevNum(DEF_DEV_NUM, &DevNum);
   if (bQuit)
   {
      return bQuit;
   }

   /* Get from user whether or not to clear out RAM */
   bQuit = Get1760EEPROMWriteZeros(DEF_WRITE_ZEROS, &bWriteZeros);
   if (bQuit)
   {
      return bQuit;
   }

   /* Associate Card, Module and Channel Numbers with the Logical Device # */
   swResult = naibrd_1553_Open(cardIndex, module, channel, DevNum);
   if(swResult)
   {
      bQuit = TRUE;
      printf("Error: naibrd_1553_Open  %d", swResult);
      return bQuit;
   }

   if (bWriteZeros)
   {
      naibrd_1760_MasterReset(DevNum);
      nai_msDelay(100);
      /* Write Zeros to clear out RAM */
      naibrd_WriteZeros32(cardIndex, module, 0x20000*channel, 0x20000);

      /* Set RT to 1 in operational status register to avoid parity error */
      naibrd_1553_RtSetAddress(DevNum, 1);
   }

   swResult = naibrd_1760_SetEEPROMUnlock(DevNum);
   if (swResult != NAI_SUCCESS)
   {
      printf("Error: naibrd_1760_SetEEPROMUnlock  %d", swResult);
      return TRUE;
   }
   printf("\nSerial EEPROM Unlock Successful.");

   swResult = naibrd_1760_SetEECOPY(DevNum, TRUE);
   if (swResult != NAI_SUCCESS)
   {
      printf("Error: naibrd_1760_SetEECOPY  %d", swResult);
   }

   printf("\nDriving EECOPY input high.");

   nai_msDelay(10);

   swResult = naibrd_1760_SetEECOPY(DevNum, FALSE);
   if (swResult != NAI_SUCCESS)
   {
      printf("Error: naibrd_1760_SetEECOPY  %d", swResult);
      return TRUE;
   }

   printf("\nDriving EECOPY input low.");

   printf("\nWait until READY output goes high for EEPROM copy completion...");
   do
   {
      nai_msDelay(1000);
      swResult = naibrd_1760_GetDeviceReady(DevNum, &ready);
   } while (!ready);

   printf("Copy Complete\n");

   return bQuit;
}

bool_t Get1760EEPROMWriteZeros(bool_t defWriteZeros, bool_t* bWriteZeros)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nZero out all registers? (Y or N) [Default=%s]: ", defWriteZeros ? "Y" : "N");
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *bWriteZeros = defWriteZeros;
            bValidEntry = TRUE;
         }
         else if ((toupper(inputBuffer[0]) != 'Y') && (toupper(inputBuffer[0]) != 'N'))
            printf("\nPlease Input Y or N. Zero out all registers? [Default=%s]: ", defWriteZeros ? "Y" : "N");
         else
         {
            *bWriteZeros = (toupper(inputBuffer[0]) == 'Y') ? TRUE : FALSE;
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

Help Bot

X