//###########################################################################
//
// FILE:    init_loop_mux.c
//
// TITLE:
//
// NOTES:
//  1)
//###########################################################################
//
//  Ver  | dd mmm yyyy | Who  		| Description of changes
// ======|=============|============|========================================
//  00 	   05 04 2015 	 HPCS
//
//  Texas Instruments, Inc
//  Copyright Texas Instruments 2008. All rights reserved.
//###########################################################################
#include "system_defines.h"
#include "cyclone_device.h"
#include "variables.h"
#include "function_definitions.h"
#include "software_interrupts.h"
#include "cyclone_defines.h"
#include "pmbus_common.h"
#include "pmbus_topology.h"
#include "pmbus_constants.h"


void init_loop_mux(void)
{
	/*
	 * Interconnections.
	 */
		LoopMuxRegs.FILTERMUX.bit.FILTER0_FE_SEL = 0; // connect filter 0 to front end 0.
		LoopMuxRegs.FILTERMUX.bit.FILTER1_FE_SEL = 1; // connect filter 1 to front end 1.
		LoopMuxRegs.FILTERMUX.bit.FILTER2_FE_SEL = 2; // connect filter 2 to front end 2.
		LoopMuxRegs.FILTERMUX.bit.FILTER0_PER_SEL =2;// Selects source of switching cycle period for Filter 0 Module. In this case its DPWM2.
		LoopMuxRegs.FILTERMUX.bit.FILTER1_PER_SEL =2;// Selects source of switching cycle period for Filter 1 Module. In this case its DPWM2.
		LoopMuxRegs.FILTERMUX.bit.FILTER2_PER_SEL =2;// Selects source of switching cycle period for Filter 2 Module. In this case its DPWM2.
		LoopMuxRegs.SAMPTRIGCTRL.bit.FE0_TRIG_DPWM2_EN = 1;  // Enables Sample Trigger from DPWM 2 to Front End Control 0
		LoopMuxRegs.SAMPTRIGCTRL.bit.FE1_TRIG_DPWM2_EN = 1;  // Enables Sample Trigger from DPWM 2 to Front End Control 1
		LoopMuxRegs.SAMPTRIGCTRL.bit.FE2_TRIG_DPWM2_EN = 1;  // Enables Sample Trigger from DPWM 2 to Front End Control 2

	/*
	* Configure frame Sync's and sample trigger.
	*/
		LoopMuxRegs.FECTRL0MUX.bit.DPWM2_FRAME_SYNC_EN = 1;  // Enables DPWM Trigger from DPWM2 Frame Sync to Front End Control
		LoopMuxRegs.FECTRL2MUX.bit.DPWM2_FRAME_SYNC_EN = 1;  // Enables DPWM Trigger from DPWM2 Frame Sync to Front End Control
		LoopMuxRegs.FECTRL1MUX.bit.DPWM2_FRAME_SYNC_EN = 1;  // Enables DPWM Trigger from DPWM2 Frame Sync to Front End Control

	 /*
	   * Who is slave and who is master?
	   */
		LoopMuxRegs.DPWMMUX.bit.DPWM2_SYNC_SEL =2; //DPWM2 is a master, sync with itself
		LoopMuxRegs.DPWMMUX.bit.DPWM3_SYNC_SEL =2;// DPWM3 is slave, sync with DPWM2


}
