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

SUM1553 BC Scheduler

SUM1553 BC Scheduler

Explanation

About the Sample Application Code for NAI 1553 Bus Controller Scheduler

This sample application code, provided by North Atlantic Industries (NAI), demonstrates how to use the NAI Software Support Kit (SSK) to interact with their embedded function modules specifically for configuring a 1553 channel as a Bus Controller (BC) and managing BC-RT and RT-BC scheduled messages.

Code Breakdown

Includes The code includes several standard libraries alongside specific NAI libraries: - #include <stdio.h> - #include <stdlib.h> - #include <string.h> - #include <time.h> - #include <ctype.h> - NAI libraries for board access, query, access, display, utilities, and 1553 utilities.

Static Constants and Variables - CONFIG_FILE is a constant that points to the default configuration file. - Various other constants are defined for default channel indices, RT addresses, subaddresses, etc. - datablock is a 2D array to store data blocks for the BC.

Function Prototypes The functions are declared for configuring and running the Bus Controller and handling data updates and reads: - Run_SUM1553_BC_Scheduler() - Retrieve_SUM1553_RTBCMessages() - Update_SUM1553_BCSAData()

Main Function - The main function starts the program (differently for VXWORKS systems). - It enters a loop, querying the user for the card index and module number to configure the Bus Controller. - For valid queries, it runs the Run_SUM1553_BC_Scheduler function. - It allows the user to quit or restart the application.

Run_SUM1553_BC_Scheduler This function configures a module/channel as the Bus Controller: 1. Sets up the channel. 2. Loads predefined 1553 command blocks for BC-RT and RT-BC messages. 3. Runs the Bus Controller, allowing the user to: - View RT-BC message data. - Update BC-RT data. - Stop the BC execution.

Retrieve_SUM1553_RTBCMessages This function reads the Command Block associated with an RT-BC message. If no error is detected, it reads the associated data block and displays it.

Update_SUM1553_BCSAData This function updates data sent in BC-RT messages. It modifies the data blocks and then reloads them into the Bus Controller.

Key Functions and Definitions - NAI Libraries: The NAI libraries provide essential functions for board and module access, as well as specific utilities for handling 1553 communication protocols. - 1553: A communication protocol used primarily in avionics for communication between various subsystems. - Bus Controller (BC): The central control unit in a 1553 setup that initiates all message transfers.

How It Works The application leverages NAI’s libraries to interact with a specific module configured as a Bus Controller (BC): 1. Configuration Phase: - Users are prompted to select the card index and module. - The selected module is configured as BC using predefined 1553 messages. 2. Execution Phase: - The application runs, allowing the BC to send and receive scheduled messages. - Users can view received messages, update data, or quit the execution. 3. Data Handling: - The application provides utility functions to read RT-BC messages and update BC-RT message data blocks.

Conclusion This application exemplifies configuring a 1553 channel as a Bus Controller, handling both BC-RT and RT-BC messages. It serves as a practical template for developers working with NAI’s 1553 modules and SSK, demonstrating fundamental operations like configuration, data transmission, and reception in a structured and user-interactive manner.

#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_sum1553.h"

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

/* Function prototypes */
static bool_t Run_SUM1553_BC_Scheduler(int32_t cardIndex, int32_t module, uint32_t modid);
static void Retrieve_SUM1553_RTBCMessages(int32_t cardIndex, int32_t module, int32_t bcchan);
static void Update_SUM1553_BCSAData(int32_t cardIndex, int32_t module, int32_t bcchan, uint8_t increment);

static const int32_t DEF_BC_CHANNEL    = 2;
static const uint8_t DEF_RT_ADDR       = 1;
static const uint8_t DEF_RT_SUBADDR    = 2;
static const uint16_t RTBC_WORDCNT     = 32;

static const uint16_t BLOCKA = 0;
static const uint16_t BLOCKB = 1;
static const uint16_t BLOCKC = 2;

static uint16_t datablock[3][32];

/**************************************************************************************************************/
/**
<summary>
The purpose of the SUM1553_BC_Scheduler is to illustrate the methods to call in the naibrd library to configure
the 1553 channel as a Bus Controller and send and receive BC-RT and RT-BC scheduled messages.

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

 Note, the SUM1553_BC_Scheduler can run in conjunction with the SUM1553_RT_PingPong or SUM1553_RT_ProcCtrl
 applications to illustrate BC and RT operations together with the NAI 1553 module.
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t SUM1553_BC_Scheduler(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_SUM1553_BC_Scheduler(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;
}

/**************************************************************************************************************/
/**
<summary>
Run_SUM1553_BC_Scheduler queries the user for the module and channel to configure as the Bus Controller (BC).
After getting the module/channel selection, methods in the naibrd library are invoked to setup this channel
as a BC with the following scheduled predefined 1553 messages:
1) BC-RT message with 32 words of data to the "DEF_RT_ADDR" RT Address and "DEF_RT_SUBADDR" Subaddress
2) RT-BC message for 32 words of data to the "DEF_RT_ADDR" RT Address and "DEF_RT_SUBADDR" Subaddress
1) BC-RT message with 16 words of data to the "DEF_RT_ADDR" RT Address and "DEF_RT_SUBADDR+1" Subaddress

Once the BC is configured and running, the user can:
1) Type the Enter key to view the RT-BC response.
1) Type 'U' to change the data in the BC-RT message.
3) Type 'Q' to quit stop the BC execution and exit the routine.
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_SUM1553_BC_Scheduler(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit;
   bool_t bContinue = TRUE;
   int32_t bcchan = 2;

   const uint16_t FIRST_CMD = 0;
   bool_t resetting;
   uint32_t ncmd = 0;
   int32_t wordcnt = 32;
   uint8_t rtaddr = DEF_RT_ADDR;
   uint8_t rtsubaddr = DEF_RT_SUBADDR;

   uint16_t ctrl;
   uint16_t cmd1, cmd2;
   uint16_t datablocknum;
   uint16_t branchblock;
   uint32_t timerus;
   uint8_t increment = 0;
   int32_t i;

   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   bQuit = Get1553BCCfg(modid, DEF_BC_CHANNEL, &bcchan);
   if (!bQuit)
   {
      /* Reset the channel */
      check_status(naibrd_SUM1553_Reset(cardIndex,module,bcchan));

      /* Wait for channels to reset */
      while(check_status(naibrd_SUM1553_IsResetting(cardIndex,module,bcchan,&resetting)) == NAI_SUCCESS && resetting);

      /* Setup the BC */
      check_status(naibrd_SUM1553_SetMode(cardIndex,module,bcchan,NAI_SUM1553_OPSTATUS_BC_MODE)); /* Configure as BC */

      /* Load commands */
      ncmd = FIRST_CMD;
      /* Load Minor Frame Timers to 100000 us (100 ms) */
      ctrl = NAI_SUM1553_BC_CTRL_WORD(NAI_SUM1553_OPCODE_LOAD_MINOR_FRAME_TIMER,1,1,0,0);
      cmd1 = 0;
      cmd2 = 0;
      datablocknum = 0;
      branchblock = 0;
      timerus = 100000;
      check_status(naibrd_SUM1553_BC_LoadCmdBlock(cardIndex,module,bcchan,ncmd++,ctrl,cmd1,cmd2,datablocknum,branchblock,timerus));

      /* BCRT Message with 32 words to RT SubAddress */
      wordcnt = 32;
      ctrl = NAI_SUM1553_BC_CTRL_WORD(NAI_SUM1553_OPCODE_EXEBLK_CONT,1,1,0,0);
      cmd1 = NAI_SUM1553_COMMAND_WORD(rtaddr,0,rtsubaddr,wordcnt);
      cmd2 = 0;
      datablocknum = BLOCKA;
      branchblock = 0;
      timerus = 0;
      check_status(naibrd_SUM1553_BC_LoadCmdBlock(cardIndex,module,bcchan,ncmd++,ctrl,cmd1,cmd2,datablocknum,branchblock,timerus));
      for (i = 0; i < wordcnt; i++)
         datablock[BLOCKA][i] = (uint16_t)(0xA000 + i);
      check_status(naibrd_SUM1553_BC_LoadDataBlock(cardIndex,module,bcchan,BLOCKA,datablock[BLOCKA]));

      /* RTBC Message with 32 words to RT SubAddress */
      wordcnt = RTBC_WORDCNT;
      ctrl = NAI_SUM1553_BC_CTRL_WORD(NAI_SUM1553_OPCODE_EXEBLK_CONT,1,1,0,0);
      cmd1 = NAI_SUM1553_COMMAND_WORD(rtaddr,1,rtsubaddr,wordcnt);
      cmd2 = 0;
      datablocknum = BLOCKB;
      branchblock = 0;
      timerus = 0;
      check_status(naibrd_SUM1553_BC_LoadCmdBlock(cardIndex,module,bcchan,ncmd++,ctrl,cmd1,cmd2,datablocknum,branchblock,timerus));
      /* Writing to the BLOCKB datablock is not necessary. We initialize so we know that getting the RT transmit messages */
      for (i = 0; i < wordcnt; i++)
      {
         datablock[BLOCKB][i] = (uint16_t)(0xB000 + i);
      }
      check_status(naibrd_SUM1553_BC_LoadDataBlock(cardIndex,module,bcchan,BLOCKB,datablock[BLOCKB]));

      /* BCRT Message with 16 words to RT SubAddress */
      wordcnt = 16;
      ctrl = NAI_SUM1553_BC_CTRL_WORD(NAI_SUM1553_OPCODE_EXEBLK_CONT,1,1,0,0);
      cmd1 = NAI_SUM1553_COMMAND_WORD(rtaddr,0,rtsubaddr+1,wordcnt);
      cmd2 = 0;
      datablocknum = BLOCKC;
      branchblock = 0;
      timerus = 0;
      check_status(naibrd_SUM1553_BC_LoadCmdBlock(cardIndex,module,bcchan,ncmd++,ctrl,cmd1,cmd2,datablocknum,branchblock,timerus));
      for (i = 0; i < wordcnt; i++)
         datablock[BLOCKC][i] = (uint16_t)(0xC000 + i);
      check_status(naibrd_SUM1553_BC_LoadDataBlock(cardIndex,module,bcchan,BLOCKC,datablock[BLOCKC]));

      /* Branch back to beginning of schedule */
      ctrl = NAI_SUM1553_BC_CTRL_WORD(NAI_SUM1553_OPCODE_GOTO,0,0,0,0);
      cmd1 = 0;
      cmd2 = 0;
      datablocknum = 0;
      branchblock = 0;
      timerus = 0;
      check_status(naibrd_SUM1553_BC_LoadCmdBlock(cardIndex,module,bcchan,ncmd++,ctrl,cmd1,cmd2,datablocknum,branchblock,timerus));

      /* Start with the first command */
      check_status(naibrd_SUM1553_BC_SetCmdBlockPtr(cardIndex,module,bcchan,FIRST_CMD));

      /* Run the BC */
      check_status(naibrd_SUM1553_EnableExecution(cardIndex,module,bcchan,1));

      while (bContinue)
      {
         printf("\nType Enter key for RT-BC message, or U to update the subaddress transmit data or %c to quit : ", NAI_QUIT_CHAR);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (toupper(inputBuffer[0]) == 'U')
            {
               increment++;
               Update_SUM1553_BCSAData(cardIndex,module,bcchan,increment);
            }
            else
            {
               Retrieve_SUM1553_RTBCMessages(cardIndex, module, bcchan);
            }
         }
         else
            bContinue = FALSE;
      }

      /* Disable the BC */
      check_status(naibrd_SUM1553_EnableExecution(cardIndex,module,bcchan,0));
   }
   return bQuit;
}

/**************************************************************************************************************/
/**
<summary>
Retrieve_SUM1553_RTBCMessages reads the Command Block associated with the RT-BC message sent to the "DEF_RT_ADDR"
RT Address and "DEF_RT_SUBADDR" Subaddress. If the BAME (Block Access Message Error) bit is clear, indicating
no error, the Data block associated with the RT-BC message for RT Address and Subaddress is read.
</summary>
*/
/**************************************************************************************************************/
static void Retrieve_SUM1553_RTBCMessages(int32_t cardIndex, int32_t module, int32_t bcchan)
{
   uint16_t ctrl;
   uint16_t cmd1, cmd2;
   uint16_t status1, status2;
   uint16_t branchblock;
   uint32_t timerus;
   uint16_t *dataptr = NULL;
   uint16_t rxdatablock[32];
   uint16_t rxwordcnt = RTBC_WORDCNT;
   int32_t i;

   check_status(naibrd_SUM1553_BC_ReadCmdBlock(cardIndex,module,bcchan,BLOCKB,&ctrl,&cmd1,&cmd2,dataptr,&status1,&status2,&branchblock,&timerus));
   if ((ctrl & NAI_SUM1553_BC_CNTL_BAME) == 0)
   {
      /* Read the data from the RT */
      naibrd_SUM1553_BC_ReadDataBlock(cardIndex,module,bcchan,BLOCKB,rxdatablock);
      printf ("Status1=%04X Status2=%04X WordCnt = %d: Data=", status1, status2, rxwordcnt);
      for (i=0; i < rxwordcnt; i++)
      {
         if (i != 0)
            printf (",");
         printf ("%04X", rxdatablock[i]);
      }
      printf("\n");
   }
}

/**************************************************************************************************************/
/**
<summary>
Update_SUM1553_BCSAData changes the data that is sent in the BC-RT messages sent to the "DEF_RT_ADDR"
RT Address and "DEF_RT_SUBADDR" and "DEF_RT_SUBADDR+1" Subaddresses.
</summary>
*/
/**************************************************************************************************************/
static void Update_SUM1553_BCSAData(int32_t cardIndex, int32_t module, int32_t bcchan, uint8_t increment)
{
   int32_t wordcnt = 32;
   uint8_t msb, lsb;
   int32_t i;

   msb = (uint8_t)(0xA0 | (increment & 0x0F)); /* upper byte (subaddress=upper 4 bits | increment=lower 4 bits)) */
   lsb = 0;
   for (i = 0; i < wordcnt; i++)
   {
      datablock[BLOCKA][i] = (msb << 8) | (uint8_t)(lsb + i);     /* incremental data */
   }
   check_status(naibrd_SUM1553_BC_LoadDataBlock(cardIndex,module,bcchan,BLOCKA,datablock[BLOCKA]));

   msb = (uint8_t)(0xC0 | (increment & 0x0F)); /* upper byte (subaddress=upper 4 bits | increment=lower 4 bits)) */
   lsb = 0;
   for (i = 0; i < wordcnt; i++)
   {
      datablock[BLOCKC][i] = (msb << 8) | (uint8_t)(lsb + i);     /* incremental data */
   }
   check_status(naibrd_SUM1553_BC_LoadDataBlock(cardIndex,module,bcchan,BLOCKC,datablock[BLOCKC]));
}

Help Bot

X