TTL BasicOps
Edit this on GitLab
TTL BasicOps Sample Application (SSK 1.x)
Overview
The TTL BasicOps sample application demonstrates how to perform TTL (Transistor-Transistor Logic) digital I/O operations using the NAI Software Support Kit (SSK 1.x). TTL channels are logic-level digital signal lines — each channel can be independently configured as an input (reading external logic states) or an output (driving a logic-high or logic-low level to connected circuitry). This sample covers the core TTL operations you will need in your own application: configuring I/O direction per channel, setting and reading output states, monitoring channel and overcurrent status, resetting overcurrent conditions, and selecting the VCC source for each channel bank.
This sample supports the following TTL module types:
-
D7 — Gen3 16-channel TTL module
-
TL1 through TL8 — Gen5 24-channel TTL modules
No combination (CM) modules currently include TTL functionality.
The sample serves as a practical API reference — each menu command maps directly to one or more naibrd_TTL_*() API calls that you can lift into your own code.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a TTL module installed (D7 or TL1-TL8).
-
SSK 1.x installed on your development host.
-
The sample applications built. Refer to the SSK 1.x build instructions for your platform if you have not already compiled them.
How to Run
Launch the TTL_BasicOps executable from your build output directory. On startup the application looks for a configuration file (default_TTL_BasicOps.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, the application prompts you to select a channel, then presents a six-command menu for exercising TTL operations.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to TTL. For details on board connection configuration, see the First Time Setup Guide. |
The main() function follows a standard SSK 1.x startup flow:
-
Call
naiapp_RunBoardMenu()to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_TTL_BasicOps.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear. -
Query the user for a card index with
naiapp_query_CardIndex(). -
Query for a module slot with
naiapp_query_ModuleNumber(). -
Retrieve the module ID with
naibrd_GetModuleID()so downstream code can adapt to the specific TTL variant installed (Gen3 vs Gen5).
#if defined (__VXWORKS__)
int32_t TTL_BasicOps(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)
{
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_TTL_BasicOps(cardIndex, module, moduleID);
}
}
}
}
}
naiapp_access_CloseAllOpenCards();
return 0;
}
|
Important
|
Common connection errors you may encounter at this stage:
|
Program Structure
Entry Point
On standard platforms the entry point is main(). On VxWorks the entry point is TTL_BasicOps() — the SSK 1.x build system selects the correct variant via a preprocessor guard:
#if defined (__VXWORKS__)
int32_t TTL_BasicOps(void)
#else
int32_t main(void)
#endif
The startup flow is the same in both cases:
-
Attempt to load the saved configuration file via
naiapp_RunBoardMenu(CONFIG_FILE). If the file does not yet exist, the interactive board menu is presented instead. -
Enter a loop that queries for card index and module slot.
-
Validate the module as a TTL type via
naibrd_TTL_GetChannelCount(). -
Call
Cfg_TTL_Channel()to enter the interactive command loop for the selected module. -
On exit, close all open board connections with
naiapp_access_CloseAllOpenCards().
Module Detection
After the user selects a module, Run_TTL_BasicOps() calls naibrd_TTL_GetChannelCount() with the module ID. If the function returns zero, the selected module is not a TTL type and the application prints an error. Otherwise, the channel count is passed to the command loop so it can validate user input:
MaxChannel = naibrd_TTL_GetChannelCount(ModuleID);
if (MaxChannel == 0)
{
printf(" *** Module selection not recognized as TTL module. ***\n\n");
}
else
{
Cfg_TTL_Channel(cardIndex, module, ModuleID, MaxChannel);
}
In your own application, use this same call to verify that the target module supports TTL operations before issuing any naibrd_TTL_*() configuration calls. The D7 module returns 16 channels; TL1 through TL8 return 24 channels.
Application Parameters and Bank Calculation
The Cfg_TTL_Channel() function populates an naiapp_AppParameters_t struct that is passed to every command handler. Your application will need to track these same values to identify which board, module, and channel you are targeting:
naiapp_AppParameters_t ttl_params;
p_naiapp_AppParameters_t ttl_basicops_params = &ttl_params;
ttl_basicops_params->cardIndex = cardIndex;
ttl_basicops_params->module = module;
ttl_basicops_params->channel = chan;
-
cardIndex— identifies which board in a multi-board system. -
module— the slot number where the TTL module is installed. -
channel— the currently selected channel (defaults to 1).
TTL modules organize channels into banks for VCC configuration purposes. The bank number is computed from the channel number and the module’s bank size:
bank = ((chan - 1) / naibrd_TTL_GetVCCBankSize(ModuleID)) + 1;
This bank number determines which group of channels shares a VCC source setting. When you configure VCC (internal vs external), the setting applies to the entire bank, not to individual channels.
Command Loop
Cfg_TTL_Channel() drives the interactive command loop. On each iteration it displays the current channel configuration, prints the command menu, and dispatches the user’s selection to the matching handler function. The menu system is a sample convenience — in your own code, call the naibrd_TTL_*() API functions directly.
The six commands available are:
| Command | Description |
|---|---|
Format |
Set I/O direction (input or output) for the selected channel |
Out |
Set the output state (high or low) on the selected channel |
Stat |
Display status registers for the selected channel |
Reset |
Reset overcurrent condition on all channels (and per-channel on Gen5) |
Clear |
Clear latched status bits for the selected channel |
Config |
Configure VCC source (internal or external) for the channel’s bank |
TTL I/O Configuration
What TTL I/O Means at the Hardware Level
Each TTL channel is a bidirectional digital signal line. When configured as an input, the channel’s driver is tristated (high-impedance) and the module reads the external logic level present on the pin. When configured as an output, the module drives the pin to a defined logic-high or logic-low voltage level. The voltage levels are standard TTL-compatible (referenced to the VCC rail configured for the channel’s bank).
By default, channels typically power up as inputs. You must explicitly configure a channel as an output before you can drive it. Attempting to set an output state on a channel still configured as an input will have no effect on the pin.
Set I/O Format
To configure a channel’s I/O direction in your own application, call naibrd_TTL_SetIOFormat():
/* Configure channel as input */
naibrd_TTL_SetIOFormat(cardIndex, module, chan, NAI_TTL_IOFORMAT_INPUT);
/* Configure channel as output -- use the correct constant for your module generation */
if (ModuleID == NAI_MODULE_ID_D7)
naibrd_TTL_SetIOFormat(cardIndex, module, chan, NAI_TTL_GEN3_IOFORMAT_OUTPUT);
else
naibrd_TTL_SetIOFormat(cardIndex, module, chan, NAI_TTL_GEN5_IOFORMAT_OUTPUT);
API parameters:
-
cardIndex— logical card index (0-based). -
module— module slot number (1-based). -
chan— channel number (1-based, up to 16 for D7 or 24 for TL modules). -
state— the I/O format constant. UseNAI_TTL_IOFORMAT_INPUTfor input mode. For output mode, the correct constant depends on the module generation:NAI_TTL_GEN3_IOFORMAT_OUTPUTfor D7,NAI_TTL_GEN5_IOFORMAT_OUTPUTfor TL1-TL8.
Module-specific behavior: The Gen3 D7 module and Gen5 TL modules use different register values for the output mode setting. The sample detects the module generation using naibrd_GetModuleInfo() and selects the appropriate constant. In your own code, you can also use NAI_TTL_IOFORMAT_OUTPUT as a generation-agnostic alias if your SSK version supports it.
Reading Current I/O Format
To read the current I/O format setting for a channel:
uint32_t ioformat = 0;
naibrd_TTL_GetIOFormat(cardIndex, module, chan, &ioformat);
The returned value will be NAI_TTL_IOFORMAT_INPUT, NAI_TTL_GEN3_IOFORMAT_OUTPUT, or NAI_TTL_GEN5_IOFORMAT_OUTPUT depending on the module type and current configuration.
|
Important
|
Common Errors
|
Output Control and Status
Set Output State
To drive a TTL channel high or low, call naibrd_TTL_SetOutputState(). The channel must already be configured as an output (see I/O Configuration above) — setting the output state on an input channel will write to the output register but the pin will remain in high-impedance and will not drive any voltage.
/* Drive channel output high */
naibrd_TTL_SetOutputState(cardIndex, module, chan, NAI_TTL_STATE_HI);
/* Drive channel output low */
naibrd_TTL_SetOutputState(cardIndex, module, chan, NAI_TTL_STATE_LO);
API parameters:
-
cardIndex,module,chan— same as above. -
outputstate—NAI_TTL_STATE_HI(logic high, typically near VCC) orNAI_TTL_STATE_LO(logic low, near ground).
At the hardware level, setting the output high causes the module’s output driver to pull the pin toward the VCC rail voltage. Setting it low pulls the pin toward ground. The actual voltage depends on the VCC source configuration for the channel’s bank (see VCC Configuration below).
Read Output and Input State
To read back the current output register value and the actual logic level present on the pin:
nai_ttl_state_t outputstate = 0;
nai_ttl_state_t inputstate = 0;
naibrd_TTL_GetOutputState(cardIndex, module, chan, &outputstate);
naibrd_TTL_GetInputState(cardIndex, module, chan, &inputstate);
-
naibrd_TTL_GetOutputState()returns the value currently written to the output register, regardless of whether the channel is configured as an output. -
naibrd_TTL_GetInputState()returns the actual logic state being read on the pin. For an output channel, this reflects the driven state. For an input channel, this reflects the external signal level.
Display Status
The sample’s Display_TTL_Status() function reads four categories of status, each available in latched and (on Gen5 modules) real-time variants:
| Status Type | What It Indicates |
|---|---|
BIT (Built-In Test) |
Whether the channel has detected a logic transition or fault condition |
Overcurrent |
Whether the output driver is drawing excessive current (see below) |
Lo-Hi Transition |
Whether a low-to-high transition has occurred on the channel |
Hi-Lo Transition |
Whether a high-to-low transition has occurred on the channel |
To read a specific status type in your own code:
nai_status_bit_t statusread;
naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_BIT_LATCHED, &statusread);
naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_OVERCURRENT_LATCHED, &statusread);
naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_LO_HI_TRANS_LATCHED, &statusread);
naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_HI_LO_TRANS_LATCHED, &statusread);
Real-time status (Gen5 only): Gen5 TL modules also support real-time status reads (NAI_TTL_STATUS_BIT_REALTIME, NAI_TTL_STATUS_OVERCURRENT_REALTIME, etc.) that reflect the instantaneous state rather than the latched state. On the Gen3 D7 module, these calls return NAI_ERROR_NOT_SUPPORTED.
-
Latched status retains its value once set until explicitly cleared. This is useful for detecting events that may be transient.
-
Real-time status reflects the current instantaneous condition and changes dynamically.
Understanding Overcurrent
An overcurrent condition indicates that a TTL output driver is sourcing or sinking more current than its rated limit. This typically occurs when:
-
The external load impedance is too low (too much current drawn from the output).
-
There is a short circuit on the output pin.
-
Multiple outputs are tied together and driving conflicting states.
When an overcurrent condition is detected, the module sets the overcurrent status bit for the affected channel. The output driver may shut down to protect itself. You should resolve the wiring issue before resetting the overcurrent condition.
Reset Overcurrent
To clear an overcurrent condition and re-enable the output driver, call one of the reset functions:
/* Reset overcurrent on ALL channels in the module */
naibrd_TTL_ResetAll(cardIndex, module, NAI_TTL_RESET_OVERCURRENT);
/* Reset overcurrent on a single channel (Gen5 modules only) */
naibrd_TTL_Reset(cardIndex, module, chan, (nai_ttl_reset_type_t)NAI_TTL_RESET_OVERCURRENT);
-
naibrd_TTL_ResetAll()resets the overcurrent condition across all channels in the module. This is available on both Gen3 and Gen5 modules. -
naibrd_TTL_Reset()resets overcurrent for a single specified channel. This per-channel reset is only available on Gen5 TL modules.
After resetting, verify that the overcurrent status has cleared by reading the status register. If the condition persists, the fault (excessive load, short circuit) is still present and must be resolved at the hardware level.
Clear Latched Status
To clear all latched status bits for a channel, call naibrd_TTL_ClearStatus() for each status type:
naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_BIT_LATCHED);
naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_OVERCURRENT_LATCHED);
naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_LO_HI_TRANS_LATCHED);
naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_HI_LO_TRANS_LATCHED);
Clearing latched status resets the captured event flags so you can detect new events. This does not affect the underlying condition — if a fault or transition is still active, the latched status will set again on the next detection cycle.
|
Important
|
Common Errors
|
VCC Configuration
What VCC Configuration Does
TTL modules provide a selectable voltage rail (VCC) that determines the logic-high output voltage and the input threshold levels for each bank of channels. The VCC source can be set to either:
-
Internal (
NAI_TTL_VCC_INTERNAL) — the module uses its own on-board voltage regulator to supply VCC. This is the typical configuration when your system does not provide an external reference voltage. -
External (
NAI_TTL_VCC_EXTERNAL) — the module uses a VCC voltage supplied externally through the connector. This allows the TTL levels to match the voltage domain of the external system you are interfacing with.
VCC is configured per bank, not per channel. A bank is a group of channels that share a common VCC rail. The bank size depends on the module type — call naibrd_TTL_GetVCCBankSize() to determine how many channels are in each bank.
When to Change VCC Configuration
You would switch to external VCC when the system you are interfacing with operates at a different voltage level than the module’s internal supply, and you need the TTL I/O to match that voltage domain. For example, if your external circuitry runs at 3.3V but the module’s internal VCC is 5V, you would supply 3.3V externally and configure the bank for external VCC.
Consult your module’s manual for the supported internal VCC voltage and the acceptable range for external VCC input.
Set VCC Source
To configure the VCC source for a bank in your own application:
/* Set bank to use internal VCC */
naibrd_TTL_SetBankVCCSource(cardIndex, module, bank, NAI_TTL_VCC_INTERNAL);
/* Set bank to use external VCC */
naibrd_TTL_SetBankVCCSource(cardIndex, module, bank, NAI_TTL_VCC_EXTERNAL);
API parameters:
-
cardIndex— logical card index (0-based). -
module— module slot number (1-based). -
bank— bank number (1-based). Compute from the channel number:bank = chan - 1) / naibrd_TTL_GetVCCBankSize(ModuleID + 1. -
vccCfg—NAI_TTL_VCC_INTERNALorNAI_TTL_VCC_EXTERNAL.
Read VCC Source
To read back the current VCC source setting for a bank:
nai_ttl_vcc_t vccConfig = 0;
naibrd_TTL_GetBankVCCSource(cardIndex, module, bank, &vccConfig);
|
Important
|
Common Errors
|
Troubleshooting Reference
|
Note
|
This section summarizes errors covered in the preceding sections. Consult your module’s manual for hardware-specific diagnostics and specifications. |
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
No board found / connection timeout |
Board not powered, wrong interface configuration, network/firewall blocking Ethernet connection |
Verify power and physical connections. Check IP settings and firewall rules. Confirm the configuration file has correct connection parameters. |
Module not recognized as TTL |
Selected module slot does not contain a TTL module, or the module ID is not in the supported list (D7, TL1-TL8) |
Use the board menu to verify which modules are installed in each slot. Select the correct slot number. |
|
Channel number out of range for the module type (D7 supports 1-16, TL modules support 1-24) |
Check the channel count with |
Output not toggling / pin stays high-impedance |
Channel is still configured as input (default state) |
Call |
Wrong I/O format constant used |
Using |
Check the module ID and select the correct generation-specific output format constant. Use |
Overcurrent status asserted |
Output load impedance too low, short circuit on the output pin, conflicting output drivers tied together |
Remove the fault condition (reduce load, fix short, resolve driver conflicts). Then call |
Overcurrent persists after reset |
The hardware fault is still present; the overcurrent condition re-triggers immediately |
The wiring or load issue must be resolved before the overcurrent reset will stick. Inspect the output circuit and consult the module manual for current ratings. |
Unexpected output voltage levels |
VCC bank is set to external but no external voltage is supplied, or the external voltage is outside the module’s acceptable range |
Verify the VCC configuration with |
|
Attempting to read a real-time status register on a Gen3 D7 module |
Real-time status is only available on Gen5 TL modules. Use latched status registers on Gen3 modules. |
Full Source
Full Source — TTL_BasicOps.c (SSK 1.x)
#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_ttl.h"
#include "advanced/nai_ether_adv.h"
static const int8_t *CONFIG_FILE = (const int8_t *)"default_TTL_BasicOps.txt";
/* Function prototypes */
int32_t Run_TTL_BasicOps(int32_t cardIndex, int32_t module, uint32_t ModuleID);
static void Cfg_TTL_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
static void Display_TTL_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, int32_t bank, uint32_t ModuleID);
static nai_status_t Display_TTL_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Clear_TTL_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_IOFormat(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_OutputState(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_VCCConfig(int32_t paramCount, int32_t* p_params);
static const int32_t DEF_TTL_CHANNEL = 1;
/****** Command Table *******/
enum dt_basicops_commands
{
TTL_BASICOP_CMD_IOFORMAT,
TTL_BASICOP_CMD_OUTPUTSTATE,
TTL_BASICOP_CMD_STATUS,
TTL_BASICOP_CMD_ROC,
TTL_BASICOP_CMD_STATUS_CLEAR,
TTL_BASICOP_CMD_VCC_CFG,
TTL_BASICOP_CMD_COUNT
};
/****** Command Tables *******/
naiapp_cmdtbl_params_t TTL_BasicOpMenuCmds[] = {
{"Format", "TTL Set IO Format", TTL_BASICOP_CMD_IOFORMAT, Configure_TTL_IOFormat},
{"Out", "TTL Set Output State", TTL_BASICOP_CMD_OUTPUTSTATE, Configure_TTL_OutputState},
{"Stat", "TTL Display Status", TTL_BASICOP_CMD_STATUS, Display_TTL_Status},
{"Reset", "TTL Reset Overcurrent", TTL_BASICOP_CMD_ROC, NULL},
{"Clear", "TTL Clear Status", TTL_BASICOP_CMD_STATUS_CLEAR, Clear_TTL_Status},
{"Config", "TTL VCC Configuration", TTL_BASICOP_CMD_VCC_CFG, Configure_TTL_VCCConfig}
};
/**************************************************************************************************************/
/** \defgroup TTL_BasicOps TTL Basic Operations
The purpose of the TTL_BasicOps is to illustrate the naibrd library methods for standard TTL
operations with the module, including configuration setup, controlling drive outputs, and reading the logic
state of the channels.
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t TTL_BasicOps(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_TTL_BasicOps(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 TTL_BasicOps
Prompts the user for the card, module and channel to use for the application and calls
Cfg_TTL_Channel if the card, module, channel is valid for as a discrete module.
\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.
*/
/**************************************************************************************************************/
int32_t Run_TTL_BasicOps(int32_t cardIndex, int32_t module, uint32_t ModuleID)
{
int32_t MaxChannel;
MaxChannel = naibrd_TTL_GetChannelCount(ModuleID);
if (MaxChannel == 0)
{
printf(" *** Module selection not recognized as TTL module. ***\n\n");
}
else
{
Cfg_TTL_Channel(cardIndex, module, ModuleID, MaxChannel);
}
return cardIndex;
}
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Handles calling the Display_TTL_ChannelCfg routine to display the discrete channel configuration
and prompts the user to enter in a menu command from the following:
\verbatim
TTL Set IO Format
> Configure the Input/Outpt configuration for the selected channel.
TTL Set Output State
> Configure the output state (i.e. high, low).
TTL Display Status
> Print TTL modules statuses.
TTL Clear Status
> Clear latched TTL module statuses.
TTL VCC Configuration
> Configure the VCC state (i.e. internal, external).
TTL Reset Overcurrent
> Reset overcurrent status.
\endverbatim
\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.
\param MaxChannel (Input) The maximum number of channels the module has.
*/
/**************************************************************************************************************/
static void Cfg_TTL_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = FALSE;
nai_status_t status = 0;
int32_t chan, defaultchan = 1;
int32_t bank = 0;
int32_t cmd;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiapp_AppParameters_t ttl_params;
p_naiapp_AppParameters_t ttl_basicops_params = &ttl_params;
ttl_basicops_params->cardIndex = cardIndex;
ttl_basicops_params->module = module;
while (bContinue)
{
printf(" \r\n\r\n");
printf("Channel selection \r\n");
printf("================= \r\n");
defaultchan = DEF_TTL_CHANNEL;
bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
ttl_basicops_params->channel = chan;
bank = ((chan - 1) / naibrd_TTL_GetVCCBankSize(ModuleID)) + 1;
naiapp_utils_LoadParamMenuCommands(TTL_BASICOP_CMD_COUNT, TTL_BasicOpMenuCmds);
while (bContinue)
{
Display_TTL_ChannelCfg(cardIndex, module, chan, bank, ModuleID);
naiapp_display_ParamMenuCommands((int8_t *)"TTL Basic Operation Menu");
printf("\nType TTL command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case TTL_BASICOP_CMD_IOFORMAT:
case TTL_BASICOP_CMD_OUTPUTSTATE:
case TTL_BASICOP_CMD_STATUS_CLEAR:
case TTL_BASICOP_CMD_STATUS:
TTL_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ttl_basicops_params);
break;
case TTL_BASICOP_CMD_VCC_CFG:
TTL_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ttl_basicops_params);
break;
case TTL_BASICOP_CMD_ROC:
status = NAI_SUCCESS;
status |= check_status(naibrd_TTL_ResetAll(cardIndex, module, NAI_TTL_RESET_OVERCURRENT)); /*This resets all channels*/
status |= check_status(naibrd_TTL_Reset(cardIndex, module, chan, (nai_ttl_reset_type_t)NAI_TTL_RESET_OVERCURRENT)); /*This alternate function resets channel 1 only on Gen5 modules. */
if (status == NAI_SUCCESS)
printf("Overcurrent condition reset completed \n");
break;
default:
printf("Invalid command entered\n");
break;
}
}
else
printf("Invalid command entered\n");
}
}
else
bContinue = FALSE;
}
}
}
/**************************************************************************************************************/
/**
\ingroup TTL_BasicOps
Display_TTL_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for basic operation.
\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 chan (Input) Channel Number of the channel to access (1 - [max channels for module]).
\param bank (Input) Number of the bank set (1 - [max banks for module]).
\param ModuleID (Input) The ID of the module.
*/
/**************************************************************************************************************/
static void Display_TTL_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, int32_t bank, uint32_t ModuleID)
{
uint32_t ioformat = 0;
nai_ttl_state_t outputstate = 0;
nai_ttl_state_t inputstate = 0;
nai_ttl_vcc_t vccConfig = 0;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
check_status(naibrd_TTL_GetIOFormat(cardIndex, module, chan, &ioformat));
check_status(naibrd_TTL_GetOutputState(cardIndex, module, chan, &outputstate));
check_status(naibrd_TTL_GetInputState(cardIndex, module, chan, &inputstate));
check_status(naibrd_TTL_GetBankVCCSource(cardIndex, module, bank, &vccConfig));
printf("\n === Channel %d ===\n\n", chan);
printf(" IOFormat Output Input Bank VCCConfig\n");
printf(" --------- ------ ----- ----- ---------\n");
if (ModuleID == NAI_MODULE_ID_D7)
{
/*For all Gen3 and prior modules, I/O output mode configuration control setting is different.*/
switch (ioformat)
{
case NAI_TTL_IOFORMAT_INPUT:
printf(" Input ");
break;
case NAI_TTL_GEN3_IOFORMAT_OUTPUT:
printf(" Output ");
break;
default:
printf(" Unknown ");
break;
}
}
else
{
switch (ioformat)
{
case NAI_TTL_IOFORMAT_INPUT:
printf(" Input ");
break;
case NAI_TTL_GEN5_IOFORMAT_OUTPUT:
printf(" Output ");
break;
default:
printf(" Unknown ");
break;
}
}
if (ioformat != NAI_TTL_IOFORMAT_INPUT)
{
switch (outputstate)
{
case NAI_TTL_STATE_LO:
printf(" Low ");
break;
case NAI_TTL_STATE_HI:
printf(" High");
break;
/* undefined value read back */
default:
printf(" UNK ");
break;
}
}
else
printf(" --- ");
printf(" %3i ", inputstate);
printf(" %2i ", bank);
switch (vccConfig)
{
case NAI_TTL_VCC_INTERNAL:
printf("Internal");
break;
case NAI_TTL_VCC_EXTERNAL:
printf("External");
break;
default:
printf("Unknown ");
break;
}
}
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Display_TTL_Status illustrate the methods to call in the naibrd library to retrieve the status states.
\param paramCount (Input) Number of parameter variables in p_params.
\param p_params (Input) Pointer to a naiapp_AppParameters struct containing information about the card and module.
*/
/**************************************************************************************************************/
static nai_status_t Display_TTL_Status(int32_t paramCount, int32_t* p_params)
{
nai_status_bit_t statusread;
nai_status_t status = 0;
p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ttl_params->cardIndex;
int32_t module = p_ttl_params->module;
int32_t chan = p_ttl_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* Available statusread:
NAI_TTL_STATUS_BIT_LATCHED,
NAI_TTL_STATUS_BIT_REALTIME, (GEN5 only)
NAI_TTL_STATUS_OVERCURRENT_LATCHED,
NAI_TTL_STATUS_OVERCURRENT_REALTIME, (GEN5 only)
NAI_TTL_STATUS_LO_HI_TRANS_LATCHED,
NAI_TTL_STATUS_LO_HI_TRANS_REALTIME, (GEN5 only)
NAI_TTL_STATUS_HI_LO_TRANS_LATCHED,
NAI_TTL_STATUS_HI_LO_TRANS_REALTIME, (GEN5 only)
*/
printf("\n");
printf(" ------------------------- Status ----------------------------\n");
printf(" | BIT | OC | Lo-Hi Trans | Hi-Lo Trans |\n");
printf(" Latch RT Latch RT Latch RT Latch RT \n");
printf(" -------------- --------------- -------------- ---------------\n");
status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_BIT_LATCHED, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else
printf(" Err %3i", status);
status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_BIT_REALTIME, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
printf(" N/A "); /*not available*/
else
printf(" Err %3i", status);
status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_OVERCURRENT_LATCHED, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else
printf(" Err %3i", status);
status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_OVERCURRENT_REALTIME, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
printf(" N/A "); /*not available*/
else
printf(" Err %3i", status);
status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_LO_HI_TRANS_LATCHED, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else
printf(" Err %3i", status);
status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_LO_HI_TRANS_REALTIME, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
printf(" N/A "); /*not available*/
else
printf(" Err %3i", status);
status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_HI_LO_TRANS_LATCHED, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else
printf(" Err %3i", status);
status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_HI_LO_TRANS_REALTIME, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
printf(" N/A "); /*not available*/
else
printf(" Err %3i", status);
printf("\n\n");
return NAI_ERROR_UNKNOWN;
}
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Clear_TTL_Status illustrate the methods to call in the naibrd library to clear the latched status states.
\param paramCount (Input) Number of parameter variables in p_params.
\param p_params (Input) Pointer to a naiapp_AppParameters struct containing information about the card and module.
*/
/**************************************************************************************************************/
static nai_status_t Clear_TTL_Status(int32_t paramCount, int32_t* p_params)
{
nai_status_t status = 0;
p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ttl_params->cardIndex;
int32_t module = p_ttl_params->module;
int32_t chan = p_ttl_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* Available status:
NAI_TTL_STATUS_BIT_LATCHED,
NAI_TTL_STATUS_OVERCURRENT_LATCHED,
NAI_TTL_STATUS_LO_HI_TRANS_LATCHED,
NAI_TTL_STATUS_HI_LO_TRANS_LATCHED,
*/
/*Clear latched status - move this to separate operator option selection */
status |= check_status(naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_BIT_LATCHED));
status |= check_status(naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_OVERCURRENT_LATCHED));
status |= check_status(naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_LO_HI_TRANS_LATCHED));
status |= check_status(naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_HI_LO_TRANS_LATCHED));
if (status == NAI_SUCCESS)
printf("Latched Status cleared \n\n");
return NAI_ERROR_UNKNOWN;
}
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Configure_TTL_IOFormat handles the user request to configure the Input/Output configuration for the selected
channel and calls the method in the naibrd library to set the Input/Output mode.
\param paramCount (Input) Number of parameter variables in p_params.
\param p_params (Input) Pointer to a naiapp_AppParameters struct containing information about the card and module.
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_IOFormat(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bUpdateIOCfg = FALSE;
uint32_t state = 0;
int8_t iofmtreq;
uint32_t ModuleID;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ttl_params->cardIndex;
int32_t module = p_ttl_params->module;
int32_t chan = p_ttl_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
/* Set I/O format configuration for channel. Available configurations include:
NAI_TTL_IOFORMAT_INPUT
NAI_TTL_GEN3_IOFORMAT_OUTPUT
NAI_TTL_GEN5_IOFORMAT_OUTPUT
NAI_TTL_IOFORMAT_OUTPUT
*/
printf("Type the desired IO configuration ");
printf("(I=Input, Out=Output): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
iofmtreq = (int8_t)toupper(inputBuffer[0]);
if (iofmtreq == 'I')
{
state = NAI_TTL_IOFORMAT_INPUT;
bUpdateIOCfg = TRUE;
}
else if (iofmtreq == 'O')
{
if (ModuleID == NAI_MODULE_ID_D7)
state = NAI_TTL_GEN3_IOFORMAT_OUTPUT;
else
state = NAI_TTL_GEN5_IOFORMAT_OUTPUT;
bUpdateIOCfg = TRUE;
}
else
{
printf("ERROR: Invalid selection\n");
}
}
if (!bQuit)
{
if (bUpdateIOCfg)
check_status(naibrd_TTL_SetIOFormat(cardIndex, module, chan, state));
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Configure_TTL_OutputState handles the user request to set the Output state for the selected
channel and calls the method in the naibrd library to set the Output state.
\param paramCount (Input) Number of parameter variables in p_params.
\param p_params (Input) Pointer to a naiapp_AppParameters struct containing information about the card and module.
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_OutputState(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bUpdateOutput = FALSE;
nai_ttl_state_t outputstate = 0;
uint32_t ModuleID;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ttl_params->cardIndex;
int32_t module = p_ttl_params->module;
int32_t chan = p_ttl_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
/* Set the output state (high or low) on output channels.
This is not applicable for channels configured as inputs.
*/
printf("\nEnter the desired output state ");
printf("(L=low output, H=high output): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
switch (toupper(inputBuffer[0]))
{
case 'L':
outputstate = 0;
bUpdateOutput = TRUE;
break;
case 'H':
outputstate = 1;
bUpdateOutput = TRUE;
break;
default:
printf("ERROR: Invalid Output State Format Entry\n");
break;
}
}
}
if (!bQuit)
{
if (bUpdateOutput)
check_status(naibrd_TTL_SetOutputState(cardIndex, module, chan, outputstate));
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Configure_TTL_VCCConfig handles the user request to set the VCC configuration for the selected
bank and calls the method in the naibrd library to set the configuration to external or internal.
\param paramCount (Input) Number of parameter variables in p_params.
\param p_params (Input) Pointer to a naiapp_AppParameters struct containing information about the card and module.
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_VCCConfig(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bUpdateVccCfg = FALSE;
nai_ttl_vcc_t vccCfg = 0;
uint32_t ModuleID;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ttl_params->cardIndex;
int32_t module = p_ttl_params->module;
int32_t bank = p_ttl_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
/* Set the vcc config (external or internal) on bank.*/
printf("\nEnter the desired VCC configuration ");
printf("(E=external, I=internal): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
switch (toupper(inputBuffer[0]))
{
case 'E':
vccCfg = NAI_TTL_VCC_EXTERNAL;
bUpdateVccCfg = TRUE;
break;
case 'I':
vccCfg = NAI_TTL_VCC_INTERNAL;
bUpdateVccCfg = TRUE;
break;
default:
printf("ERROR: Invalid VCC Configuration Entry\n");
break;
}
}
}
if (!bQuit)
{
if (bUpdateVccCfg)
check_status(naibrd_TTL_SetBankVCCSource(cardIndex, module, bank, vccCfg));
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}