/* 
 *  Copyright 2004 by Soos, Antal 
 *  All rights reserved. Property of Soos, Antal. 
 *  Restricted rights to use, duplicate or disclose this code are 
 *  granted through contract.   
 */ 
/***************************************************************************/ 
/*                                                                         */ 
/*     main . cpp                                                          */ 
/*                                                                         */ 
/*    DSP2 -> TMS320C6713 H8_MPC implementation                            */ 
/*                                                                         */ 
/***************************************************************************/ 
/**********************************************************/ 
#define _in_MAIN_CPP_ 
/**********************************************************/ 

#include "mmaccfg.h"
#include <std.h>
#include <csl_cache.h>

#include "global_var.h"
#include "global_def.h"

#include "dsk_lib.h"

using namespace std;

#define N (MPC_H8-1)
 float u[N+1];
 float y[N+1];
 
 
        
 // System identification:    
 //---------------------------------------------------
 // 0th  algorithm:
     FIX_alg obFIX(0.0);
//----------------------------------------------------
  // 1st algorithm:
    RLS_alg obRLS(0.985);
//----------------------------------------------------
  // 2nd algorithm:  
	LMS_alg  obLMS(0.7);
//----------------------------------------------------
 // 3th algorithm:  
     WCE_alg obWCE(1.0);     // 8.0 > x > 0.2
//----------------------------------------------------
 // 4th algorithm:  
     KF_alg obKF(0.2,0.2);   //0.2,0.2
//----------------------------------------------------
// 5th algorithm:  
  	 FQR_RLS_alg obFQR_RLS(0.975);
//----------------------------------------------------
// 6th algorithm:  
     IQR_RLS_alg obIQR_RLS(0.975);
//----------------------------------------------------
// 7th algorithm:  
     QR_LMS_alg obQR_LMS(0.0);
//----------------------------------------------------
 //---------------------------------------------------
 // Control Algorithm:  
    H8MPC_alg obH8MPC(0.0);
//----------------------------------------------------
  
       
/*
 *  ======== main ========
 */
int main()
{

 //---------------------------------------------------------  
    LOG_printf(&trace,  "Trace 1 -->"); 
    
    LOG_printf(&trace2, "Trace 2 -->"); 
    LOG_printf(&trace2, "dc= %d",ARMAX_DC); 
    LOG_printf(&trace2, "a = %d",ARMAX_a); 
    LOG_printf(&trace2, "b = %d",ARMAX_b); 
    LOG_printf(&trace2, "c = %d",ARMAX_c); 
        
    //LOG_printf(&trace3, "Trace 3 -->Sys ID"); 
    //LOG_printf(&trace4, "Trace 4 --> H8 cont"); 


         
    t_n = 0.0;  // reset the time measurement
    
   // Initialize the LOG_event float to Uibt32 conversion
     pfxyz = (F2Xcon *)log_ux;
  
      
        
        
    LOG_printf(&trace, " Pre OBJECTS initializations! \n"); 
       
 // System identification:    
 //---------------------------------------------------------
 // 0th  algorithm:
    LOG_printf(&trace, " FIX_alg:\n"); 
  	pFIX = &obFIX;	
 //---------------------------------------------------------
 // 1st algorithm:
    LOG_printf(&trace, " RLS_alg:\n"); 
    pRLS = &obRLS;
  //--------------------------------------------------------
 // 2nd algorithm:
    LOG_printf(&trace, " LMS_alg:\n"); 
    pLMS = &obLMS;
 //---------------------------------------------------------
 // 3th algorithm:  
    LOG_printf(&trace, " WCE_alg:\n");  
    pWCE = &obWCE;
  //--------------------------------------------------------
 // 4th algorithm:  
    LOG_printf(&trace, " KF_alg:\n"); 
    pKF = &obKF;
 //---------------------------------------------------------
 // 5th algorithm:  
    LOG_printf(&trace, " FQR_RLS_alg:\n"); 
    pFQR_RLS = &obFQR_RLS;
 //---------------------------------------------------------
 // 6th algorithm:  
    LOG_printf(&trace, " IQR_RLS_alg:\n"); 
    pIQR_RLS = &obIQR_RLS;
  //--------------------------------------------------------
 // 7th algorithm:  
    LOG_printf(&trace, " QR_LMS_alg:\n"); 
    pQR_LMS = &obQR_LMS; 
  //-------------------------------------------------------
 //--------------------------------------------------------
 // Control Algorithm:
 //--------------------------------------------------------
    LOG_printf(&trace, " H8ARMAX_alg:\n"); 
    pH8MPC = &obH8MPC;
         
	pH8MPC->weightSet();

   
 //--------------------------------------------------------   
 // Initiate the HW environment:
   // LOG_printf(&trace, " Pre GO DSK13! \n"); 	
    start_DSK();
   
    
  // Initialte DSP2DSP communications:
	rec = (D2D_com *) com_rec;
	tra = (D2D_com *) com_tra;

  
    
    DSK6713_LED_off(0);	
    DSK6713_LED_off(1);
    DSK6713_LED_off(2);  
    DSK6713_LED_off(3);  
	
    LOG_printf(&trace, "MPC upp and runing!"); 
    
      /* fall into DSP/BIOS idle loop */
    return 0;
}

 //-------------------------------------------------------   
 //-------------------------------------------------------   

extern "C" {
Void userInitFun(Void) ;}

Void userInitFun(Void)
{

	LOG_printf(&trace, " Start of userInitFun ! \n");
    DSK6713_init();
    
	DSK6713_LED_on(0);
	DSK6713_LED_on(1);
   	DSK6713_LED_on(2);  
   	DSK6713_LED_on(3);    	
   	
	LOG_printf(&trace, " End of userInitFun ! \n");
}
 //-------------------------------------------------------   



