% var module = system.modules['/driverlib/fsirx.js'];
% let Common   = system.getScript("/driverlib/Common.js");
% var nameOfModule = "fsirx";
% var nameOfPeripheral = module.peripheralName;
//*****************************************************************************
//
// FSIRX 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 Rx, reset sequence, clear events
	//
	FSI_performRxInitialization(`instance.$name`_BASE);
	//
	// Setting for requested nWords and nLanes with transfers
	//
	FSI_setRxSoftwareFrameSize(`instance.$name`_BASE, `instance.softwareFrameSize`);
	FSI_setRxDataWidth(`instance.$name`_BASE, `instance.dataWidth`);
		%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_enableRxInterrupt(`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_enableRxInterrupt(`instance.$name`_BASE, `instance.useInterrupts[index]`,
				`interrupts`);
					%}
				%}
			%}
		%}
		% if (instance.pingTimeout)
			%{
	FSI_resetRxModule(`instance.$name`_BASE, FSI_RX_PING_WD_CNT_RESET);
	DEVICE_DELAY_US(1);
	FSI_clearRxModuleReset(`instance.$name`_BASE, FSI_RX_PING_WD_CNT_RESET);
	//
	// Set Recieve module ping timeout
	//
	FSI_setRxPingTimeoutMode(`instance.$name`_BASE, `instance.selectPingMode`);
	FSI_enableRxPingWatchdog(`instance.$name`_BASE, `instance.timeoutDelay`);
			%}
	% if (instance.enableLoopback) {
	//
	// Configure for Internal Loopback
	//
	FSI_enableRxInternalLoopback(`instance.$name`_BASE);
		% } else {
	//
	// Configure for External Loopback
	//
	FSI_disableRxInternalLoopback(`instance.$name`_BASE);
		% }
	% if (instance.useDMARX) {
	//
	// Configure RTDMA event on successful frame reception
	//
	FSI_enableRxDMAEvent(`instance.$name`_BASE);
	% }
	% if (instance.enableTagMatching) {
		% if (instance.frameType == "FSI_FRAME_TYPE_PING") {
	//
	// Configure for Ping Tag Matching
	//
	FSI_setRxPingTagRef(`instance.$name`_BASE, `instance.frameTag`);
	FSI_setRxPingTagMask(`instance.$name`_BASE, `instance.tagMask`);
	FSI_enableRxPingTagCompare(`instance.$name`_BASE);
			% } else {
	//
	// Configure for Frame Tag Matching
	//
	FSI_setRxFrameTagRef(`instance.$name`_BASE, `instance.frameTag`);
	FSI_setRxFrameTagMask(`instance.$name`_BASE, `instance.tagMask`);
	FSI_enableRxFrameTagCompare(`instance.$name`_BASE);
		% }
	% }
		%if (instance.enableRxFrameWd){
	//
	// Performing a reset on frame WD before its usage
	//
	FSI_resetRxModule(`instance.$name`_BASE, FSI_RX_FRAME_WD_CNT_RESET);
	DEVICE_DELAY_US(1);
	FSI_clearRxModuleReset(`instance.$name`_BASE, FSI_RX_FRAME_WD_CNT_RESET);
	FSI_enableRxFrameWatchdog(`instance.$name`_BASE, `instance.rxFrameWdCounter`);
		%}
		%if (instance.enableDelayTap){
	//
	// Configure delay for Rx lines
	//
	FSI_configRxDelayLine(`instance.$name`_BASE, FSI_RX_DELAY_CLK,
					`instance.tapValue1`);
	FSI_configRxDelayLine(`instance.$name`_BASE, FSI_RX_DELAY_D0,
					`instance.tapValue2`);
	FSI_configRxDelayLine(`instance.$name`_BASE, FSI_RX_DELAY_D1,
					`instance.tapValue3`);
		%}
}
	%}
%}