//  DSP 1 <=> TMS320C6711
/************************************************************************/ 
#define _in_RT_CONTROL_CPP_ 
/************************************************************************/ 

#include "mmaccfg.h"
#include "global_var.h"
#include "A2D2A.h"
#include "dsk_lib.h"
#include <cstdlib>

extern "C"
{Void RT_Control() ;}

extern "C"
{Void RT_Calculus() ;}

//--------------------------------------------------------------------------------
Void RT_Control(Void)  // <-- Sample time interrupt 0.025s
{ // This is a hardware eqwivalent interupt call a softwer interupt:
    
   SWI_post(&RT_Calculations); // calles the baground H8 weight calculations  
}								// SW_Interrupt 1st level priority
//--------------------------------------------------------------------------------

Void RT_Calculus(Void)  // <-- Sample time interrupt 0.025s
{
  //static int callH8c=3; 
      
  
    //for (int i=0; i<SCR_BLOCK_SZ; i++) com_tra[i] = 1+com_rec[i];
    
   
    //Resinchronize the McBSP and EDMA if it is out of sinc:   
  if(com_rec[0] == McBSP_MARKER) 
  		{
  				IRQ_reset(IRQ_EVT_RINT1);			/*Reset McBSP interrupt 		*/
    			IRQ_disable(IRQ_EVT_RINT1);
    			IRQ_clear(IRQ_EVT_RINT1);
  				IRQ_disable(IRQ_EVT_RINT1);
  				com_rec[0] = McBSP_MARKER+5;
  				LED_toggle(2);
  		 }		 
  else  
  		{
  				IRQ_enable(IRQ_EVT_RINT1);
  		 		LED_on(2);
  		 }
  			
  com_tra[15] = 1+com_rec[0];  // Send the sync confirm marker
  com_tra[0] = McBSP_MARKER;  // Send the sync marker
      
   
    // CACHE_flush(CACHE_L2,da_buffer,DA_BLOCK_SZ);
 
   // AVR signaling:
   //----------------------------------------------------------------  
   
  if( Switch_isOn(SWITCH_1)) 
 	{
 		if(!(xflag & XF_ExVoReStChP)) LED_toggle(LED_A2D2A_Y);
 		else LED_off(LED_A2D2A_Y);
 		if(!(xflag & XF_ExVoReStChN)) LED_toggle(LED_A2D2A_R);
 		else LED_off(LED_A2D2A_R);
 	}
 
  //-----------------------------------------------------------------
   
 #if 0
  The next lewel of interrupt isnot implemented in this version!!
  callH8c--;
  if(callH8c<=0){
   SWI_post(&H8_Calculations); // SW_Interrupt 2nd level priority
   callH8c = 4;
   }
 #endif   
  
}
//--------------------------------------------------------------------------------
