% var module = system.modules['/driverlib/fsitx.js'];
% let Common   = system.getScript("/driverlib/Common.js");
% var nameOfModule = "fsitx";
% var nameOfPeripheral = module.peripheralName;
//*****************************************************************************
//
// FSITX Configurations
//
//*****************************************************************************
void `nameOfPeripheral`_init(){
%   for(var i = 0; i < module.$instances.length; i++) 
%   {
%      var instance = module.$instances[i];
	`instance.$name`_init();
%   }
}

%if (module != null)
%{
	% for(var i = 0; i < module.$instances.length; i++) {
		% var instance = module.$instances[i];
void `instance.$name`_init(){
		% let instancePinmux = instance[nameOfModule];
	//
	// Initialize Tx, reset sequence, clear events
	//
	FSI_performTxInitialization(`instance.$name`_BASE, `instance.clkPres`);
	//
	// Setting for requested nWords and nLanes with transfers
	// and desired frame configurations
	//
	FSI_setTxSoftwareFrameSize(`instance.$name`_BASE, `instance.softwareFrameSize`);
	FSI_setTxDataWidth(`instance.$name`_BASE, `instance.dataWidth`);
	FSI_setTxFrameTag(`instance.$name`_BASE, `instance.frameTag`);
	FSI_setTxFrameType(`instance.$name`_BASE, `instance.frameType`);
	//
	// Configure start of transmission mode
	//
	FSI_setTxStartMode(`instance.$name`_BASE, `instance.startOfTransmissionMode`);
		%if (instance.startOfTransmissionMode == "FSI_TX_START_EXT_TRIG")
		%{
	//
	// Configure external trigger for start of tranmission
	//
	FSI_setTxExtFrameTrigger(`instance.$name`_BASE, 
								`instance.extTriggerSource`);
		%}
		%if (instance.enableInterrupt)
		%{
			%for (var index in instance.useInterrupts){
				%if (instance.useInterrupts[index] == "FSI_INT1"){
					% var interrupts = ""
					% for (var int_index in instance.enabledINT1Interrupts)
					% {
					%	interrupts += ((interrupts == "")?"":" | ") + instance.enabledINT1Interrupts[int_index];
					% }
					%if (interrupts != "")
					%{
	//
	// Configure interrupt for INT1 line 
	//
	FSI_enableTxInterrupt(`instance.$name`_BASE, `instance.useInterrupts[index]`,
				`interrupts`);
					%}
				%}
			%}
		%}
		%if (instance.enableInterrupt)
		%{
			%for (var index in instance.useInterrupts){
				%if (instance.useInterrupts[index] == "FSI_INT2"){
					% var interrupts = ""
					% for (var int_index in instance.enabledINT2Interrupts)
					% {
					%	interrupts += ((interrupts == "")?"":" | ") + instance.enabledINT2Interrupts[int_index];
					% }
					%if (interrupts != "")
					%{
	//
	// Configure interrupt for INT2 line 
	//
	FSI_enableTxInterrupt(`instance.$name`_BASE, `instance.useInterrupts[index]`,
				`interrupts`);
					%}
				%}
			%}
		%}
	% if (instance.useDMATX) {
	//
	// Configure RTDMA event on completion of frame transfer
	//
	FSI_enableTxDMAEvent(`instance.$name`_BASE);
	% }
		% if (instance.pingTimeout)
			%{
	FSI_resetTxModule(`instance.$name`_BASE, FSI_TX_PING_TIMEOUT_CNT_RESET);
	DEVICE_DELAY_US(1);
	FSI_clearTxModuleReset(`instance.$name`_BASE, FSI_TX_PING_TIMEOUT_CNT_RESET);
	//
	// Configure Tx ping timeout mode
	//
	FSI_setTxPingTimeoutMode(`instance.$name`_BASE, `instance.selectPingMode`);
	FSI_enableTxPingTimer(`instance.$name`_BASE, `instance.timeoutDelay`,
				`instance.frameTag`);
		%}
		% if (instance.userCRC)
			%{
	//
	// Configure CRC
	//
	FSI_enableTxUserCRC(`instance.$name`_BASE, `instance.valueCRC`);
		%}
	//
	// Configure compute width for ECC
	//
	FSI_setTxECCComputeWidth(`instance.$name`_BASE, `instance.eccComputeWidth`);
}
	%}
%}