Exemple #1
0
/**
 * @brief Plays a tone.
 *
 * @param[in] freq approximated tone frequency
 * @param[in] duration tone duration in systicks
 */
void buzzPlayWait(uint32_t freq, systime_t duration) {
  TC *tc = T1Base;

  StopCounter(tc);
  tc->TC_MR0 = tc->TC_MR1 = (PCLK / (freq * 2));
  StartCounter(tc);
  chThdSleep(duration);
  StopCounter(tc);
}
Exemple #2
0
/**
 * @brief Stops the sound.
 *
 * @param[in] p pointer to the timer
 */
static void stop(void *p) {

  StopCounter((TC *)p);
  chSysLockFromIsr();
  chEvtBroadcastI(&BuzzerSilentEventSource);
  chSysUnlockFromIsr();
}
Exemple #3
0
int StopSampling(void)
{
#ifdef USE_NMI
    int cpuId = smp_processor_id();
    if (cpuId == 0)
    {
        WRITEMSR(INS_FIXED_MSR, 0x08);
    }
#endif
	StopCounter(&counterPackage);
	return 0;	
}
Exemple #4
0
/**
 * @brief Plays a tone asynchronously.
 *
 * @param[in] freq approximated tone frequency
 * @param[in] duration tone duration in systicks
 */
void buzzPlay(uint32_t freq, systime_t duration) {
  static VirtualTimer bvt;
  TC *tc = T1Base;

  chSysLock();

  if (chVTIsArmedI(&bvt)) {             /* If a sound is already being  */
    chVTResetI(&bvt);                   /* played then aborts it.       */
    StopCounter(tc);
  }

  tc->TC_MR0 = tc->TC_MR1 = (PCLK / (freq * 2));
  StartCounter(tc);
  chVTSetI(&bvt, duration, stop, tc);

  chSysUnlock();
}
Exemple #5
0
/**
 * @brief Buzzer driver initialization.
 */
void buzzInit(void) {

  chEvtInit(&BuzzerSilentEventSource);

  /*
   * Switches P0.12 and P0.13 to MAT1.0 and MAT1.1 functions.
   * Enables Timer1 clock.
   */
  PINSEL0 &= 0xF0FFFFFF;
  PINSEL0 |= 0x0A000000;
  PCONP = (PCONP & PCALL) | PCTIM1;

  /*
   * Timer setup.
   */
  TC *tc = T1Base;
  StopCounter(tc);
  tc->TC_CTCR = 0;                      /* Clock source is PCLK.        */
  tc->TC_PR   = 0;                      /* Prescaler disabled.          */
  tc->TC_MCR  = 2;                      /* Clear TC on match MR0.       */
}
Exemple #6
0
/*
void ReadEIP(PEIP_RECORD pRecord)
{
	W32 high, low, i, top;

	rdmsr(0x1da, low, high);
	top = low;
	
	for(i = 0; i < MAX_EIP_NUM; i++)
	{
		top = (top+i) % MAX_EIP_NUM;
		rdmsr(0x680+top, low, high);
		pRecord->eipFrom[i] = ((W64)high << 32) | low;
		rdmsr(0x6c0+top, low, high);
		pRecord->eipTo[i] = ((W64)high << 32) | low;
	}	
}
*/
int CollectSampling(void)
{
	int cpuId;
	//W32 low, high; 
	SAMPLE_RECORD record;
	PROFILING_RECORD profiling;
	unsigned long irqFlags;
#ifdef DBG	
	W32 i;
#endif
	W64 *pointer;
	
	//if (counterPackage.eipNum > 0)
	//{
	//stop branch recording
//	rdmsr(0x1d9, low, high);
//	low &= 0xfffffffe;
//	wrmsr(0x1d9, low, high);
	//
	//}	
	
	cpuId = smp_processor_id();
#ifdef DBG
	printk("collect sampling on core %d\n", cpuId);
#endif
	StopCounter(&counterPackage);
	//rdtsc(low, high);
	//record.sampleHeader.rdtsc = (((W64)high)<<32) | low;
	record.sampleHeader.rdtsc = __native_read_tsc();
	record.sampleHeader.sampleId = sampleId;
	record.sampleHeader.cpuId = cpuId;
	ReadCounter(&counterPackage, &record);

	
#ifdef DBG	
	pointer = (W64*)(current->thread.sp0);
	printk("a-------------------------------------------------------------\n");
	for(i = 0; i < 8; i++)
	{
		//eipRecord.eipFrom[i] = (*pointer);
		printk("Addr %p: %p\n", pointer, (*pointer));
		pointer--;
		//eipRecord.eipTo[i] = (*pointer);
		printk("Addr %p: %p\n", pointer, (*pointer));
		pointer--;
	}
	printk("b-------------------------------------------------------------\n");
	//printk("rsp: %p\n",curThread.rsp);
	//printk("rsp0: %p\n",curThread.rsp0);
#endif
	if (counterPackage.profiling > 0)
	{
		pointer = (W64*)(current->thread.sp0);
		profiling.pid = (W64)current->pid;
		pointer -= 5;
		profiling.eip = (*pointer);
/*		if(sampleId == 0)
		{
		printk("cpuId: %d eip: %p\n", cpuId, profiling.eip);
		printk("pid: %u\n", profiling.pid);
		}
*/	}
	
	spin_lock_irqsave(&buffer_lock, irqFlags);
#ifdef DBG
	printk("%d cpu get spinlock and write %d bytes to buffer\n", cpuId, sizeof(SAMPLE_HEADER) + sizeof(W64) * counterPackage.usedNum);
#endif	
	AddSampleToBuff(&record, sizeof(SAMPLE_HEADER) + sizeof(W64) * counterPackage.usedNum);
	if (counterPackage.profiling > 0)
	{
		AddSampleToBuff(&profiling, sizeof(PROFILING_RECORD));
	}

	spin_unlock_irqrestore(&buffer_lock, irqFlags);
	
	//start branch recording
	//rdmsr(0x1d9, low, high);
	//low |= 1;
	//wrmsr(0x1d9, low, high);
	//
#ifdef USE_NMI
    WRITEMSR(INS_FIXED_COUNTER, COUNTER_OVERFLOW);
#endif
	
	StartCounter(&counterPackage);
	return 0;
}
void CEnvHudCounter::InputStopCounter( inputdata_t &inputdata )
{
	StopCounter();
	m_OnCounterStopped.FireOutput( this, this );
}
void CEnvHudCounter::PauseCounter()
{
	m_flPausedTime = m_flTime;
	m_bPaused = true;
	StopCounter();
}
Exemple #9
0
/**
 * @brief Stops the sound.
 *
 * @param[in] p pointer to the timer
 */
static void stop(void *p) {

  StopCounter((TC *)p);
  chEvtBroadcastI(&BuzzerSilentEventSource);
}