M1760 EEPROM Copy
Edit this on GitLab
M1760 EEPROM Copy Sample Application (SSK 2.x)
Overview
The M1760 EEPROM Copy sample application demonstrates how to copy the current configuration of a MIL-STD-1760 module to its serial EEPROM using the NAI Software Support Kit (SSK 2.x). This allows the module to auto-initialize with the saved configuration on subsequent power-ups, eliminating the need for software reconfiguration at startup.
The application works with FTJ, FTK, and CMR modules that contain the HI-6130/HI-6131 device with EEPROM capability. It optionally resets the device and clears all RAM to zeros before copying, unlocks the EEPROM, initiates the copy by pulsing the EECOPY signal, and polls the device ready bit until the copy completes.
|
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. 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. |
For detailed 1553/1760 protocol specifications, see the FTA-FTF Manual.
For the SSK 1.x version, see M1760 EEPROM Copy (SSK 1.x).
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a 1760 module installed (FTJ, FTK, or CMR).
-
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.
-
The 1760 channel must have been reset at least once via software since power-up (e.g., by running an RT sample on the channel first).
How to Run
Launch the m1760_eeprom_copy executable from your build output directory. On startup the application looks for a configuration file (default_1760_EEPROMCopy.txt). Once connected, the application prompts for channel, logical device number, and whether to zero out all registers before copying. The EEPROM copy may take several seconds; the application polls until the device signals completion.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. |
The main() function follows the standard SSK 2.x startup flow: board menu, card index query, module selection, and module ID retrieval.
|
Important
|
Common Connection Errors
|
Program Structure
Optional RAM Clear
If the user selects "write zeros," the application performs a master reset and clears all device RAM:
naibrd_1760_MasterReset(DevNum);
naibrd_msDelay(100);
/* Write zeros to clear out RAM (0x8000 words) */
memset(zeroArray, 0, sizeof(zeroArray));
iterations = 0x8000 / 1000;
for (i = 0; i < iterations; i++)
{
swResult = naibrd_1760_WriteMem(DevNum, i * 1000, 1000, zeroArray);
}
/* Set RT address to 1 to avoid parity error */
naibrd_1553_RtSetAddr(DevNum, 1);
This clears the device to a known state before saving to EEPROM.
EEPROM Copy Sequence
/* Unlock the EEPROM */
swResult = naibrd_1760_SetEEPROMUnlock(DevNum);
/* Pulse EECOPY high then low */
swResult = naibrd_1760_SetEECOPY(DevNum, NAI_TRUE);
naibrd_msDelay(10);
swResult = naibrd_1760_SetEECOPY(DevNum, NAI_FALSE);
/* Wait for device ready */
do
{
naibrd_msDelay(1000);
swResult = naibrd_1760_GetDeviceReady(DevNum, &ready);
} while (!ready);
-
naibrd_1760_SetEEPROMUnlock()— unlocks the EEPROM for writing. The EEPROM is locked by default to prevent accidental writes. -
naibrd_1760_SetEECOPY()— drives the EECOPY signal. The copy begins on the rising edge and the signal must be held high briefly before being driven low. -
naibrd_1760_GetDeviceReady()— polls the device ready bit. The EEPROM copy may take several seconds.
Troubleshooting Reference
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
Module not supported |
Module is not FTJ, FTK, or CMR |
Only 1760 modules with EEPROM support this operation |
|
Device not reset since power-up |
Run an RT sample on the channel first to trigger a software reset |
Device ready never goes high |
EEPROM hardware fault, copy interrupted |
Power cycle the module and retry |
EEPROM copy produces parity errors on boot |
RAM contained uninitialized data |
Use the "write zeros" option to clear RAM before copying |
|
Channel already open, invalid indices |
Verify indices, ensure no other application holds the channel |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — m1760_eeprom_copy.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/nai.h"
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_1553.h"
#include "nai_libs/naibrd/include/functions/naibrd_1760.h"
/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"
/* Common 1553 Sample Program include files */
#include "nai_sample_apps/naiapp_src/board_modules/1553/m1553_common_utils/m1553_common_utils.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"
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 = NAI_FALSE;
/**************************************************************************************************************/
/** \defgroup M1760_EEPROMCopy
\brief This sample application demonstrates how to copy the current configuration of the module to EEPROM.
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-6130/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. 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 main steps include:
- Querying the user for the card index and module number.
- Reset and clear the memory if prompted by the user.
- Unlocking the EEPROM and initiating the copy.
- Polling the device ready bit to ensure the copy completes.
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t M1760_EEPROM_Copy(void)
#else
int32_t main(void)
#endif
{
bool_t stop = NAI_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) == NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
Run_M1760_EEPROM_Copy(cardIndex, module, moduleID);
}
}
}
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;
}
static bool_t Run_M1760_EEPROM_Copy(int32_t cardIndex, int32_t module, uint32_t modid)
{
/* Variables */
bool_t bQuit = NAI_FALSE;
int16_t DevNum = 0;
int32_t swResult;
int32_t MaxChannel = 2, channel;
bool_t ready;
bool_t bWriteZeros;
static uint32_t zeroArray[1000];
int32_t iterations, remainder;
int32_t i;
if ((modid != NAIBRD_MODULE_ID_FTK) && (modid != NAIBRD_MODULE_ID_FTJ) && (modid != NAIBRD_MODULE_ID_CMR))
{
naiif_printf("This module does not support EEPROM copy capability\r\n");
return NAI_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 = NAI_TRUE;
naiif_printf("Error: naibrd_1553_Open %d", swResult);
return bQuit;
}
if (bWriteZeros)
{
naibrd_1760_MasterReset(DevNum);
naibrd_msDelay(100);
/* Write Zeros to clear out RAM */
memset(zeroArray, 0, sizeof(zeroArray));
iterations = 0x8000 / 1000;
for (i = 0; i < iterations; i++)
{
swResult = naibrd_1760_WriteMem(DevNum, i * 1000, 1000, zeroArray);
}
/* Set RT to 1 in operational status register to avoid parity error */
naibrd_1553_RtSetAddr(DevNum, 1);
}
swResult = naibrd_1760_SetEEPROMUnlock(DevNum);
if (swResult != NAI_SUCCESS)
{
naiif_printf("Error: naibrd_1760_SetEEPROMUnlock %d", swResult);
return NAI_TRUE;
}
naiif_printf("\r\nSerial EEPROM Unlock Successful.");
swResult = naibrd_1760_SetEECOPY(DevNum, NAI_TRUE);
if (swResult != NAI_SUCCESS)
{
naiif_printf("Error: naibrd_1760_SetEECOPY %d", swResult);
}
naiif_printf("\r\nDriving EECOPY input high.");
naibrd_msDelay(10);
swResult = naibrd_1760_SetEECOPY(DevNum, NAI_FALSE);
if (swResult != NAI_SUCCESS)
{
naiif_printf("Error: naibrd_1760_SetEECOPY %d", swResult);
return NAI_TRUE;
}
naiif_printf("\r\nDriving EECOPY input low.");
naiif_printf("\r\nWait until READY output goes high for EEPROM copy completion...");
do
{
naibrd_msDelay(1000);
swResult = naibrd_1760_GetDeviceReady(DevNum, &ready);
} while (!ready);
naiif_printf("Copy Complete\r\n");
return bQuit;
}
bool_t Get1760EEPROMWriteZeros(bool_t defWriteZeros, bool_t* bWriteZeros)
{
bool_t bQuit = NAI_FALSE;
bool_t bValidEntry = NAI_FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiif_printf("\r\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 = NAI_TRUE;
}
else if ((toupper(inputBuffer[0]) != 'Y') && (toupper(inputBuffer[0]) != 'N'))
naiif_printf("\r\nPlease Input Y or N. Zero out all registers? [Default=%s]: ", defWriteZeros ? "Y" : "N");
else
{
*bWriteZeros = (toupper(inputBuffer[0]) == 'Y') ? NAI_TRUE : NAI_FALSE;
bValidEntry = NAI_TRUE;
}
}
}
return bQuit;
}