Example #1
0
BOOLEAN_T verify_trans_matrix
  (BOOLEAN_T log_form,    /* Is the transition matrix in log form? */
   int       num_states,  /* Number of states in the (square) matrix. */
   MATRIX_T* trans)       /* The matrix. */
{
  int    i_state;
  PROB_T total;

  for (i_state = 0; i_state < num_states - 1; i_state++) {

    /* Cf. Rabiner, formula (43b), p. 265. */
    if (log_form) {
      total = log_array_total(get_matrix_row(i_state, trans));
      if ((!almost_equal(total, 0.0, SLOP)) &&
	  (!almost_equal(total, 1.0, SLOP)) && // Allow for FIMS.
	  (!almost_equal(EXP2(total), 0.0, SLOP))) { 
	fprintf(stderr,
		"Warning: Row %d of transition matrix differs from 0.0 by %g.\n",
		i_state, EXP2(total));
	return(FALSE);
      }
    } else {
      total = array_total(get_matrix_row(i_state, trans));
      if ((!almost_equal(total, 1.0, SLOP)) &&
	  (!almost_equal(total, 2.0, SLOP)) && // Allow FIMs.
	  (!almost_equal(total, 0.0, SLOP))) { // Allow inaccessible motifs.
	fprintf(stderr,
		"Warning: Row %d of transition matrix differs from 1.0 by %g.\n",
		i_state, 1.0 - total);
	return(FALSE);
      }
    }

    /* All transitions from the end state must be zero. */
    if ((log_form) &&
	(get_matrix_cell(num_states - 1, i_state, trans) > LOG_SMALL)) {
      fprintf(stderr,
	      "Warning: Transition %d from end state is non-zero (%g).\n", 
	      i_state, get_matrix_cell(num_states - 1, i_state, trans));
      return(FALSE);
    } else if (!(log_form) &&
	       (!almost_equal(get_matrix_cell(num_states - 1, i_state, trans), 
			      0.0, SLOP))) {
      fprintf(stderr,
	      "Warning: Transition %d from end state is non-zero (%g).\n", 
	      i_state, get_matrix_cell(num_states - 1, i_state, trans));
      return(FALSE);
    }
  }
  return(TRUE);
}  
Example #2
0
void unlog_array
  (ARRAY_T* array)
{
  int i_item;
  int num_items;

  check_null_array(array);

  num_items = get_array_length(array);
  for (i_item = 0; i_item < num_items; i_item++) {
    set_array_item(i_item, EXP2(get_array_item(i_item, array)), array);
  }
}
Example #3
0
PRIVATE BOOL lcdd_CheckProductId()
{
    UINT16 manufacturer_ID=0;

    g_lcddConfig = &g_tgtLcddCfg;
    g_lcddCsBase = (UINT32) hal_EbcCsOpen(g_lcddConfig->csNum, &g_lcddConfig->csConfig);
    g_lcddCsOffset = EXP2(g_lcddConfig->rsLine+1);
    //manufacturer_ID=LCM_RD_REG(0x00);

      hal_EbcCsClose(g_lcddConfig->csNum);
    // force trace
    LCDD_TRACE(LCDD_INFO_TRC|TSTDOUT, 0,"lcd9320 ebc Id : %x ",manufacturer_ID);
// force true
	return TRUE;
    if((manufacturer_ID&0xFFFF)==LCD_ILI9163C_ID)
        return TRUE;
    else
        return FALSE;

}
Example #4
0
/**************************************************************************
 * Convert a given array to or from logs.
 **************************************************************************/
void convert_to_from_log_array
  (BOOLEAN_T to_log,
   ARRAY_T*  source_array,
   ARRAY_T*  target_array)
{
  int num_items;
  int i_item;
  ATYPE new_value;

  // If the source is null, just return.
  if (source_array == NULL) 
    return;

  num_items = get_array_length(source_array);
  for (i_item = 0; i_item < num_items; i_item++) {
    if (to_log) {
      new_value = my_log2(get_array_item(i_item, source_array));
    } else {
      new_value = EXP2(get_array_item(i_item, source_array));
    }
    set_array_item(i_item, new_value, target_array);
  }
}
Example #5
0
// ============================================================================
// lcdd_Open
// ----------------------------------------------------------------------------
/// Open the LCDD driver.
/// It must be called before any call to any other function of this driver.
/// This function is to be called only once.
/// @return #LCDD_ERR_NO or #LCDD_ERR_DEVICE_NOT_FOUND.
// ============================================================================
PRIVATE LCDD_ERR_T lcdd_Open(VOID)
{
  g_lcddConfig = &g_tgtLcddCfg;
    g_lcddCsBase     = (UINT32) hal_EbcCsOpen(g_lcddConfig->csNum, &g_lcddConfig->csConfig);
    g_lcddCsOffset = EXP2(g_lcddConfig->rsLine+1);
    
    if (0 == g_lcddCsBase)
    {
        return LCDD_ERR_DEVICE_NOT_FOUND;
    }
    else
    {
        // Turn off backlight so that we don't display anything wrong
        
        hal_SysResetOut(FALSE);


//--************ Start Initial Sequence **********--//
main_Write_COM(0x11); //Exit Sleep
	hal_TimDelay(120 MS_WAITING);



main_Write_COM(0x26); //Set Default Gamma
main_Write_DATA(0x04);

main_Write_COM(0xB1);
main_Write_DATA(0x08);
main_Write_DATA(0x14);

main_Write_COM(0xC0); //Set VRH1[4:0] & VC[2:0] for VCI1 & GVDD
main_Write_DATA(0x08);
main_Write_DATA(0x00);

main_Write_COM(0xC1); //Set BT[2:0] for AVDD & VCL & VGH & VGL
main_Write_DATA(0x05);

main_Write_COM(0xC5); //Set VMH[6:0] & VML[6:0] for VOMH & VCOML
main_Write_DATA(0x46);//0x46
main_Write_DATA(0x40);//0x40

main_Write_COM(0xC7); 
main_Write_DATA(0xBD);  //0xC2




main_Write_COM(0x3a); //Set Color Format
main_Write_DATA(0x05);

main_Write_COM(0x2A); //Set Column Address
main_Write_DATA(0x00);
main_Write_DATA(0x00);
main_Write_DATA(0x00);
main_Write_DATA(0x7F);
main_Write_COM(0x2B); //Set Page Address
main_Write_DATA(0x00);
main_Write_DATA(0x00);
main_Write_DATA(0x00);
main_Write_DATA(0x9F);

main_Write_COM(0xB4); //Set Source Output Direction
main_Write_DATA(0x00);

main_Write_COM(0xf2); //Enable Gamma bit
main_Write_DATA(0x01);


main_Write_COM(0x36); //Set Scanning Direction
main_Write_DATA(0xC8);  //0xc0

main_Write_COM(0xE0);
main_Write_DATA(0x3F);//p1
main_Write_DATA(0x26);//p2
main_Write_DATA(0x23);//p3
main_Write_DATA(0x30);//p4
main_Write_DATA(0x28);//p5
main_Write_DATA(0x10);//p6
main_Write_DATA(0x55);//p7
main_Write_DATA(0xB7);//p8
main_Write_DATA(0x40);//p9
main_Write_DATA(0x19);//p10
main_Write_DATA(0x10);//p11
main_Write_DATA(0x1E);//p12
main_Write_DATA(0x02);//p13
main_Write_DATA(0x01);//p14
main_Write_DATA(0x00);//p15

main_Write_COM(0xE1);
main_Write_DATA(0x00);//p1
main_Write_DATA(0x19);//p2
main_Write_DATA(0x1C);//p3
main_Write_DATA(0x0F);//p4
main_Write_DATA(0x14);//p5
main_Write_DATA(0x0F);//p6
main_Write_DATA(0x2A);//p7
main_Write_DATA(0x48);//p8
main_Write_DATA(0x3F);//p9
main_Write_DATA(0x06);//p10
main_Write_DATA(0x1D);//p11
main_Write_DATA(0x21);//p12
main_Write_DATA(0x3D);//p13
main_Write_DATA(0x3E);//p14
main_Write_DATA(0x3F);//p15

main_Write_COM(0x29); // Display On
        // Allow access 
        g_lcddLock = 1;

        LCDD_TRACE(LCDD_INFO_TRC, 0, "lcdd_Open: LCD Opened");
        return LCDD_ERR_NO;
    }
}
Example #6
0
// ============================================================================
// lcdd_Open
// ----------------------------------------------------------------------------
/// Open the LCDD driver.
/// It must be called before any call to any other function of this driver.
/// This function is to be called only once.
/// @return #LCDD_ERR_NO or #LCDD_ERR_DEVICE_NOT_FOUND.
// ============================================================================
PUBLIC LCDD_ERR_T lcdd_Open(VOID)
{
    g_lcddConfig = tgt_GetLcddConfig();
    g_lcddCsBase     = (UINT32) hal_EbcCsOpen(g_lcddConfig->csNum, &g_lcddConfig->csConfig);
    g_lcddCsOffset = EXP2(g_lcddConfig->rsLine+1);
    
    if (0 == g_lcddCsBase)
    {
        return LCDD_ERR_DEVICE_NOT_FOUND;
    }
    else
    {
        // Turn off backlight so that we don't display anything wrong
        
        hal_SysResetOut(FALSE);

        // Standby Mode OFF
        LCM_WR_CMD(0x2C);  
	    hal_TimDelay(20 MS_WAITING);
        
        // MTP Initial Disable
        LCM_WR_CMD(0xEB);  
	    hal_TimDelay(20 MS_WAITING);

        // Turn ON Oscillator
        LCM_WR_CMD(0x02);  
        LCM_WR_CMD(0x01);  
	    hal_TimDelay(20 MS_WAITING);
    
        // DC-DC Select
        LCM_WR_CMD(0x20);  
        LCM_WR_CMD(0x0A); 
	    hal_TimDelay(20 MS_WAITING);
    
        // DCDC1 ON
        LCM_WR_CMD(0x26);  
        LCM_WR_CMD(0x01); 
	    hal_TimDelay(20 MS_WAITING);

        // AMP ON
        LCM_WR_CMD(0x26);  
        LCM_WR_CMD(0x09); 
	    hal_TimDelay(20 MS_WAITING);
    
        // DCDC2 ON
        LCM_WR_CMD(0x26);  
        LCM_WR_CMD(0x0B); 
	    hal_TimDelay(20 MS_WAITING);
    
        // DCDC3 ON
        LCM_WR_CMD(0x26);  
        LCM_WR_CMD(0x0F); 
	    hal_TimDelay(20 MS_WAITING);
    
        // Temperature Compensation set
        LCM_WR_CMD(0x28);  
        LCM_WR_CMD(0x02);  
    
        // RAM Skip Area set to no skip
        LCM_WR_CMD(0x45);
        LCM_WR_CMD(0x00);
    
        // Driver Output mode set
        LCM_WR_CMD(0x10);
        LCM_WR_CMD(0x25);
    
        // Bias Set
        LCM_WR_CMD(0x22);  
        LCM_WR_CMD(0x11);
    
        // DC/DC Clock Divistion set
        LCM_WR_CMD(0x24);  
        LCM_WR_CMD(0x11);
    
        // Contrast control value (0 to 255)
        LCM_WR_CMD(0x2A);  
        LCM_WR_CMD(0xBE);  
    
        // Contrast control for partial display mode
        LCM_WR_CMD(0x2B);  
        LCM_WR_CMD(0x54);
    
        // Set Addressing mode 65k colors
        LCM_WR_CMD(0x30);
        LCM_WR_CMD(0x05);
    
        // Row Vector mode
        LCM_WR_CMD(0x32); 
        LCM_WR_CMD(0x0E);
    
        // N-block inversion set
        LCM_WR_CMD(0x34);
        LCM_WR_CMD(0x92);
    
        // Frame Frequency control (High Frame Frequ)
        LCM_WR_CMD(0x36);  
        LCM_WR_CMD(0x00);  
    
        // Entry Mode Set (Read Modify Write OFF)
        LCM_WR_CMD(0x40);
        LCM_WR_CMD(0x00);
    
        // X Area Address set 0 -> 159 (160pix)
        LCM_WR_CMD(0x42);
        LCM_WR_CMD(0x00);
        LCM_WR_CMD(0x9F);
    
        // Y Area Address set 4 -> 131 (128pix)
        LCM_WR_CMD(0x43);
        LCM_WR_CMD(0x04);
        LCM_WR_CMD(0x83);
    
        // Specified Display Pattern Set (Normal display)
        LCM_WR_CMD(0x53);
        LCM_WR_CMD(0x00);  
        
        // Partial Display Off
        LCM_WR_CMD(0x55);  
        LCM_WR_CMD(0x00);  
    
        // Scroll Start Line 0
        LCM_WR_CMD(0x5A);       
        LCM_WR_CMD(0x00);   
    
        // Display On
        LCM_WR_CMD(0x51);  
    
        // Allow access 
        g_lcddLock = 1;

        LCDD_TRACE(LCDD_INFO_TRC, 0, "lcdd_Open: LCD Opened");
        return LCDD_ERR_NO;
    }
}
Example #7
0
void eval_direct_yukawa(FmmvHandle *FMMV, Box *target, Box *source)
#endif
{
	DEFINE_IDA_LOCAL_ALIASES(FMMV)
        
        _FLOAT_ beta = FMMV->beta;

        _FLOAT_ beta_r, exp_minus_beta_r_over_r;

	_FLOAT_ x, y, z, one_over_r, r2;
	_FLOAT_ xi,yi,zi, qj;
	#if ((FMM_KIND==FMM_STANDARD)||(FMM_KIND==FMM_GRAD) \
	   ||(FMM_KIND==FMM_DIPOLE)||(FMM_KIND==FMM_DIPOLE_GRAD))
	_FLOAT_ qi;
	#endif
	int i,j,ni,nj,i0,j0,j00,j1;
	#if ((FMM_KIND==FMM_GRAD)||(FMM_KIND==FMM_DIPOLE)||(FMM_KIND==FMM_DIPOLE_GRAD) \
	   ||(FMM_KIND==FMM_ST_GRAD)||(FMM_KIND==FMM_ST_DIPOLE)||(FMM_KIND==FMM_ST_DIPOLE_GRAD))
	_FLOAT_ hh0;
	#endif
	#if ((FMM_KIND==FMM_GRAD)||(FMM_KIND==FMM_DIPOLE_GRAD) \
	   ||(FMM_KIND==FMM_ST_GRAD)||(FMM_KIND==FMM_ST_DIPOLE_GRAD))
	_FLOAT_ hh1;
	#endif
	#if ((FMM_KIND==FMM_DIPOLE_GRAD) \
	   ||(FMM_KIND==FMM_ST_DIPOLE_GRAD))
	_FLOAT_  hh2;
	_FLOAT_ beta2 = beta*beta;	
	#endif
	#if ((FMM_KIND==FMM_DIPOLE)||(FMM_KIND==FMM_DIPOLE_GRAD) \
 	   ||(FMM_KIND==FMM_ST_DIPOLE)||(FMM_KIND==FMM_ST_DIPOLE_GRAD))
	_FLOAT_ mxj, myj, mzj;
	_FLOAT_ m_times_rj;	
	#endif
	#if ((FMM_KIND==FMM_DIPOLE)||(FMM_KIND==FMM_DIPOLE_GRAD)) 
	_FLOAT_ mxi, myi, mzi;
	_FLOAT_ m_times_ri;	
	#endif

	i0 = target->firstTarget;
	ni = target->noOfTargets;
	j0 = source->firstParticle;
	nj = source->noOfParticles;

	#if ((FMM_KIND==FMM_ST_STANDARD)||(FMM_KIND==FMM_ST_GRAD) \
   	   ||(FMM_KIND==FMM_ST_DIPOLE)||(FMM_KIND==FMM_ST_DIPOLE_GRAD))
	j00 =j0;
	FMMV->noOfDirectInteractions += ni*nj;
	#else
	if (i0==j0) {
		FMMV->noOfDirectInteractions += (ni*(ni-1))/2;
	}
	else { 
		FMMV->noOfDirectInteractions += (ni*(ni-1))/2;
	}
	#endif
	j1 = j0+nj;

	for (i=i0; i<i0+ni; i++) {
		#ifdef PERIODIC
		xi = access_tx(i) - dx;
		yi = access_ty(i) - dy;
		zi = access_tz(i) - dz;
		#else
		xi = access_tx(i);
		yi = access_ty(i);
		zi = access_tz(i);
		#endif
		#if ((FMM_KIND==FMM_STANDARD)||(FMM_KIND==FMM_GRAD) \
		   ||(FMM_KIND==FMM_DIPOLE)||(FMM_KIND==FMM_DIPOLE_GRAD))
		qi = access_q(i);
		#endif
		#if ((FMM_KIND==FMM_DIPOLE)||(FMM_KIND==FMM_DIPOLE_GRAD)) 
		mxi = access_mx(i);
		myi = access_my(i);
		mzi = access_mz(i);		
		#endif
		
		#if ((FMM_KIND==FMM_ST_STANDARD)||(FMM_KIND==FMM_ST_GRAD) \
		   ||(FMM_KIND==FMM_ST_DIPOLE)||(FMM_KIND==FMM_ST_DIPOLE_GRAD))
		#else
		j00 = (i<j0 ? j0 : i+1);
		#endif

		for (j=j00; j<j1; j++) {
			x = xi - access_x(j);
			y = yi - access_y(j);
			z = zi - access_z(j);
                        r2 = x*x + y*y + z*z;
			#if (EVAL_DIRECT_ACCURACY==0)
			one_over_r = RECIP_SQRT0(r2); 
			#elif (EVAL_DIRECT_ACCURACY==1)
			one_over_r = RECIP_SQRT1(r2); 
			#elif (EVAL_DIRECT_ACCURACY==2)
			one_over_r = RECIP_SQRT2(r2); 
			#endif
                        beta_r = beta*r2*one_over_r;
			#if (EVAL_DIRECT_ACCURACY==0)
                        exp_minus_beta_r_over_r = EXP0(-beta_r)*one_over_r;
			#elif (EVAL_DIRECT_ACCURACY==1)
                        exp_minus_beta_r_over_r = EXP1(-beta_r)*one_over_r;
			#elif (EVAL_DIRECT_ACCURACY==2)
                        exp_minus_beta_r_over_r = EXP2(-beta_r)*one_over_r;
			#endif


			qj = access_q(j);
			#if ((FMM_KIND==FMM_DIPOLE)||(FMM_KIND==FMM_DIPOLE_GRAD) \
			  ||(FMM_KIND==FMM_ST_DIPOLE)||(FMM_KIND==FMM_ST_DIPOLE_GRAD))
			mxj = access_mx(j);
			myj = access_my(j);
			mzj = access_mz(j);
			m_times_rj = x*mxj + y*myj + z*mzj;
                        hh0 = (1.0+beta_r)*one_over_r*one_over_r*exp_minus_beta_r_over_r;
			access_pot(i) += qj*exp_minus_beta_r_over_r + m_times_rj*hh0;
			#if ((FMM_KIND==FMM_DIPOLE)||(FMM_KIND==FMM_DIPOLE_GRAD)) 
			m_times_ri = x*mxi + y*myi + z*mzi;
			access_pot(j) += qi*exp_minus_beta_r_over_r - m_times_ri*hh0;
			#endif
			#else
			access_pot(i) += qj*exp_minus_beta_r_over_r;
			#if ((FMM_KIND==FMM_STANDARD)||(FMM_KIND==FMM_GRAD)) 
			access_pot(j) += qi*exp_minus_beta_r_over_r;
			#endif
			#endif
			
			#if ((FMM_KIND==FMM_GRAD)||(FMM_KIND==FMM_ST_GRAD))
                        hh0 = (1.0+beta_r)*one_over_r*one_over_r*exp_minus_beta_r_over_r;
                        hh1 = qj*hh0;
			access_gradx(i) -= x*hh1;
			access_grady(i) -= y*hh1;
			access_gradz(i) -= z*hh1;
			#endif
			#if (FMM_KIND==FMM_GRAD)
                        hh1 = qi*hh0;
			access_gradx(j) += x*hh1;
			access_grady(j) += y*hh1;
			access_gradz(j) += z*hh1;
			#endif
			#if ((FMM_KIND==FMM_DIPOLE_GRAD)||(FMM_KIND==FMM_ST_DIPOLE_GRAD))
                        hh1 = one_over_r*one_over_r*m_times_rj;
                        hh2 = (qj + 3.0*hh1)*hh0 + beta2*hh1*exp_minus_beta_r_over_r;
			access_gradx(i) -= x*hh2 - mxj*hh0;
			access_grady(i) -= y*hh2 - myj*hh0;
			access_gradz(i) -= z*hh2 - mzj*hh0;
			#endif
			#if (FMM_KIND==FMM_DIPOLE_GRAD)
                        hh1 = one_over_r*one_over_r*m_times_ri;
                        hh2 = (qi - 3.0*hh1)*hh0 - beta2*hh1*exp_minus_beta_r_over_r;
			access_gradx(j) += x*hh2 + mxi*hh0;
			access_grady(j) += y*hh2 + myi*hh0;
			access_gradz(j) += z*hh2 + mzi*hh0;	
			#endif
		}
	}
}