示例#1
0
文件: main.cpp 项目: tufty/circle
int main (void)
{
	// TODO: implement all destructors used in CKernel, otherwise cannot return from main()

	CKernel Kernel;
	if (!Kernel.Initialize ())
	{
		DisableInterrupts ();
		for (;;);
		return EXIT_HALT;
	}
	
	TShutdownMode ShutdownMode = Kernel.Run ();

	switch (ShutdownMode)
	{
	case ShutdownReboot:
		reboot ();
		return EXIT_REBOOT;

	case ShutdownHalt:
	default:
		DisableInterrupts ();
		for (;;);
		return EXIT_HALT;
	}
}
示例#2
0
// ******** OS_Wait ************
// decrement semaphore and spin/block if less than zero
// input:  pointer to a counting semaphore
// output: none
void OS_Wait(Sema4Type *s){
	DisableInterrupts();
	while( s->Value <= 0){
		//TODO: implement Blocking
		EnableInterrupts();
		DisableInterrupts();
	}
	s->Value--;
	EnableInterrupts();
}
示例#3
0
// ******** OS_bWait ************
// if the semaphore is 0 then spin/block
// if the semaphore is 1, then clear semaphore to 0
// input:  pointer to a binary semaphore
// output: none
void OS_bWait(Sema4Type *semaPt){
	DisableInterrupts();
	while( semaPt->Value  != 1){
		//TODO: implement Blocking
		EnableInterrupts();
		OS_Suspend();
		DisableInterrupts();
	}
	semaPt->Value =0;
	EnableInterrupts();

return;
}
示例#4
0
文件: OS.c 项目: c0lin91/EE445M
// ------------------------- OS_bWait --------------------------------
void OS_bWait(Sema4Type *semaPt){
  DisableInterrupts();
	
	while (semaPt->Value <= 0){
		unlinkTCB(&Actives, RunPt);
		linkTCB(&(semaPt->Blocked), RunPt);
		RunPt->blockSt = semaPt;
		OS_Suspend();
		EnableInterrupts();
	}
	DisableInterrupts();
	(*semaPt).Value = 0;
	EnableInterrupts();
}
示例#5
0
文件: guswave.c 项目: Rockbox/rockbox
static VoiceNode *GUSWAVE_GetVoice
   (
   int handle
   )

   {
   VoiceNode *voice;
   unsigned  flags;

   flags = DisableInterrupts();

   voice = VoiceList.start;

   while( voice != NULL )
      {
      if ( handle == voice->handle )
         {
         break;
         }

      voice = voice->next;
      }

   RestoreInterrupts( flags );

   if ( voice == NULL )
      {
      GUSWAVE_SetErrorCode( GUSWAVE_VoiceNotFound );
      }

   return( voice );
   }
示例#6
0
// ******** OS_SysTick_Handler ************
// Thread Switcher, uses SysTick as periodic timer, calls PendSV to actually switch threads
// Implement Thread Manager implicitly here 
// input: none, uses globals RUNPT and NEXTRUNPT 
// output: none, should switch threads when finished
void OS_SysTick_Handler(void){
	tcbType *i, *j;
	int pri;
	int x;
  
  	DisableInterrupts();
    
	//Thread Scheduler
	if(RRSCHEDULER){
	//ROUND ROBBIN SCHEDULER
		for(i=RUNPT->next; i->sleep>0 || i->blockedOn!=0; i=i->next){
			//OLD SLEEP DECRIMENTER
			//if(i->sleep>0){//decriment sleep counter
			//	i->sleep=i->sleep-1;
			//}
		}
		NEXTRUNPT=i;
	}else if(PRIORITYSCHEDULER){
	//PRIORITY SCHEDULER
		pri=7;
		j=RUNPT->next;
		x=0;
		do{
			x++;
			//find thread with highest priority that isnt sleeping or blocked
			if(j->blockedOn==NULL && j->sleep==0 && j->workingPriority<pri){
				pri=j->workingPriority;
				i=j;	
			}
		
			j=j->next;
		//}while(j!=RUNPT->next);
		}while(x<NUMTHREADS);


	/* 	//Priority Scheduler, failed for case where lowest thread got blocked.
		for(i=RUNPT->next,pri=RUNPT->workingPriority,x=0; i->sleep>0 || i->blockedOn!=NULL || (i->workingPriority > pri); i=i->next, x++){ //Possible ERROR HERE, needs rethought //search for next thread untill you find one that is not sleeping, not blocked, and has a priority equal or less than the current RUNPT
			if(x>=NUMTHREADS && pri<7){
				x=0;
				pri++;
			}
		}
	*/
			//OLD SLEEP DECRIMENTER
			//if(i->sleep>0){//decriment sleep counter
			//	i->sleep=i->sleep-1;
			//}

		NEXTRUNPT=i;
		RUNPT->lastRun=OS_Time();
		RUNPT->workingPriority = RUNPT->realPriority;		
	
	}
	  
  	EnableInterrupts();
  
	//Switch Threads (trigger PendSV)
	NVIC_INT_CTRL_R = 0x10000000;
	//PendSV_Handler();
}
/*
 * This routine will shutdown a serial port; interrupts are disabled, and
 * DTR is dropped if the hangup on close termio flag is on.
 */
static void shutdown(struct xmb_serial * info)
{
	volatile unsigned int *uartp;
	unsigned long		flags;

	if (!(info->flags & ASYNC_INITIALIZED))
		return;

#ifdef SERIAL_DEBUG_OPEN
	printk("Shutting down serial port %d (irq %d)....\n", info->line,
	       info->irq);
#endif
	
	uartp = (volatile unsigned int *) info->addr;
	save_flags_cli(flags); 		/* Disable interrupts */

	/* Disable interrupts and clear RX FIFO */
	DisableInterrupts(uartp);
	Reset_RX_FIFO(uartp);

	if (info->xmit_buf) {
		free_page((unsigned long) info->xmit_buf);
		info->xmit_buf = 0;
	}

	if (info->tty)
		set_bit(TTY_IO_ERROR, &info->tty->flags);
	
	info->flags &= ~ASYNC_INITIALIZED;
	restore_flags(flags);
}
/*
 *	Based on the line number set up the internal interrupt stuff.
 */
static void xmbrs_irqinit(struct xmb_serial *info)
{
	volatile unsigned int *uartp;

	switch (info->line) {
	case 0:
	case 1:
		break;
	default:
		printk("SERIAL: don't know how to handle UART %d interrupt?\n",
			info->line);
		return;
	}

	uartp = (volatile unsigned int *) info->addr;

	/* Clear mask, so no surprise interrupts. */
	DisableInterrupts(uartp);

	if (request_irq(info->irq, xmbrs_interrupt, SA_INTERRUPT,
	    "Microblaze UARTlite", NULL)) {
		printk("SERIAL: Unable to attach Xilinx UARTlite %d interrupt "
			"vector=%d\n", info->line, info->irq);
	}
	
	/* Populate the fast IRQ lookup table */
	irq_lookup[info->irq] = info;

	/* UART still can't generate interrupts - leave it this way
	   until it is actually opened */

	return;
}
示例#9
0
void EXTI0_IRQHandler(void)
{
   DisableInterrupts(); 
   PressButtom = TRUE;
   EXTI_ClearITPendingBit(EXTI_Line0);
   EnableInterrupts();
}
int main(void){
	DisableInterrupts();
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
	Random_Init(1);
  Nokia5110_Init();
	PF1Init();
  //SysTick_Init(2666666); //Initialize SysTick with 30 Hz interrupts
	SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer
	ADC0_Init();
	Game_Init();
	SwitchLed_Init();
	Sound_Init();
	Timer2_Init(&Sound_Play,7256); //11.025 kHz. 80,000,000/11,025 cycles, which is about 7256
	GameOverFlag = 0;
	EnableInterrupts();
	
  while(1){
		while(Semaphore==0){};
    Semaphore = 0;
		if(GameOverFlag){
			State_GameOver();
		}
		else{
			Draw_GameFrame(); // update the LCD
		}	
		if((GameOverFlag == 0) && (Check_GameOver())){ //just detected game over
			Delay100ms(2);//Delay 200ms
			GameOverFlag = Check_GameOver();
			//SysTick_Init(2666666);//Re-initialize with 30 Hz interrupt
			SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed
		}
	}
}
示例#11
0
文件: guswave.c 项目: Rockbox/rockbox
int GUSWAVE_SetPitch
   (
   int handle,
   int pitchoffset
   )

   {
   VoiceNode *voice;
   unsigned  flags;

   flags = DisableInterrupts();

   voice = GUSWAVE_GetVoice( handle );

   if ( voice == NULL )
      {
      RestoreInterrupts( flags );

      GUSWAVE_SetErrorCode( GUSWAVE_VoiceNotFound );
      return( GUSWAVE_Warning );
      }

   if ( voice->Active )
      {
      voice->PitchScale  = PITCH_GetScale( pitchoffset );
      voice->RateScale   = ( voice->SamplingRate * voice->PitchScale ) >> 16;
      gf1_dig_set_freq( voice->GF1voice, voice->RateScale );
      }
示例#12
0
/*
 * Setup the timer 0 to generate the tick interrupts at the required frequency.
 */
static void prvSetupTimerInterrupt( void )
{
	uint32_t ulCompareMatch;
	

	/* Calculate the match value required for our wanted tick rate. */
	ulCompareMatch = 1000000 / configTICK_RATE_HZ;

	/* Protect against divide by zero.  Using an if() statement still results
	in a warning - hence the #if. */
	#if portPRESCALE_VALUE != 0
	{
		ulCompareMatch /= ( portPRESCALE_VALUE + 1 );
	}
	#endif

	DisableInterrupts();

	pRegs->CTL = 0x003E0000;
	pRegs->LOD = ulCompareMatch;
	pRegs->RLD = ulCompareMatch;
	pRegs->DIV = portTIMER_PRESCALE;
	pRegs->CLI = 0;
	pRegs->CTL = 0x003E00A2;

	RegisterInterrupt(64, vTickISR, NULL);

	EnableInterrupt(64);

	EnableInterrupts();
}
示例#13
0
byte MHD_Bridge_detect(void)
{
    byte temp = 0;
    byte BridgeOn = 0;
    DisableInterrupts();
    msleep(180);
    if(!gpio_get_value(GPIO_ACCESSORY_INT)&& MHD_HW_IsOn())
    {
        temp = ReadIndexedRegister(INDEXED_PAGE_0, 0x09);
        if ((temp & RSEN) == 0x00)
        {
            BridgeOn = FALSE;
            //ReadModifyWriteTPI(0x79, SI_BIT_5 | SI_BIT_4, SI_BIT_4); //force HPD to 0
            ReadModifyWriteIndexedRegister(INDEXED_PAGE_0, 0x79, SI_BIT_5 | SI_BIT_4, SI_BIT_4);
        }
        else
        {
            BridgeOn = TRUE;
            //ReadModifyWriteTPI(0x79, BIT_5 | BIT_4, 0); //back to current state
        }
        printk("[MHD] Bridge detect %x :: HPD %d\n",BridgeOn,gpio_get_value(GPIO_HDMI_HPD));
        //ReadModifyWriteTPI(0x79, SI_BIT_5 | SI_BIT_4, 0); //back to current state
        ReadModifyWriteIndexedRegister(INDEXED_PAGE_0, 0x79, SI_BIT_5 | SI_BIT_4, 0);
    }
    MHD_INT_clear();
    EnableInterrupts();
    printk("[MHD]MHD_Bridge_detect -- \n");
    return BridgeOn;
}
示例#14
0
// gets all events
EventMaskType GetAllEvents()
{
  DisableInterrupts();
  EventMaskType tmpevents = eventmemory;
  EnableInterrupts();
  return tmpevents;
}
示例#15
0
// gets all events which are set in "eventmask" and returns them
EventMaskType GetEvent(EventMaskType eventmask)
{
  DisableInterrupts();
  EventMaskType tmpevents = eventmask & eventmemory;
  EnableInterrupts();
  return tmpevents;
}
示例#16
0
文件: adc.c 项目: c0lin91/EE445M
void Touch_BeginWaitForTouch(void){
    // XP = 1  XN = DIG IN, INT ON FALL EDGE YP = Hi-Z YN = 0
    DisableInterrupts();
    
    // Set XP high
    TOUCH_XP = 0xFF;
    
    // Set YN low
    TOUCH_YN = 0x00;
    
    // Configure XN (PA3) for digital input
    GPIO_PORTA_DIR_R &= ~0x08;
    
    // Configure YP (PE5) for analog Hi-Z
    GPIO_PORTE_DIR_R &= ~0x20;
    GPIO_PORTE_DEN_R &= ~0x20;
   
    // Setup falling edge interrupt on XN (PA3)
    GPIO_PORTA_PUR_R |=  0x08;   // enable weak pull up
    GPIO_PORTA_IS_R  &= ~0x08;     // (d) PF4 is edge-sensitive
    GPIO_PORTA_IBE_R &= ~0x08;    //     PF4 is not both edges
    GPIO_PORTA_IEV_R &= ~0x08;    //     PF4 falling edge event
    GPIO_PORTA_ICR_R  =  0x08;      // (e) clear flag4
    GPIO_PORTA_IM_R  |=  0x08;      // (f) arm interrupt on PF4


    NVIC_PRI0_R = (NVIC_PRI7_R&0xFFFFFF00)|0x000000a0;
    NVIC_EN0_R = NVIC_EN0_INT0;  // (h) enable interrupt 30 in NVIC


    EnableInterrupts();
}
示例#17
0
void PAS_SetSampleBufferCount
   (
   void
   )

   {
   int LoByte;
   int HiByte;
   int count;
   int data;
   unsigned flags;

   flags = DisableInterrupts();

   // Disable the Sample Buffer Count
   data = PAS_State->audiofilt;
   data &= ~SampleBufferCountGateFlag;
   PAS_Write( AudioFilterControl, data );
   PAS_State->audiofilt = data;

   // Select the Sample Buffer Count
   data = SelectSampleBufferCount;
   PAS_Write( LocalTimerControl, data );
   PAS_State->tmrctlr = data;

   count = PAS_TransferLength;

   // Check if we're using a 16-bit DMA channel
   if ( PAS_DMAChannel > 3 )
      {
      count >>= 1;
      }
示例#18
0
void PAS_SetSampleRateTimer
   (
   void
   )

   {
   int LoByte;
   int HiByte;
   int data;
   unsigned flags;

   flags = DisableInterrupts();

   // Disable the Sample Rate Timer
   data = PAS_State->audiofilt;
   data &= ~SampleRateTimerGateFlag;
   PAS_Write( AudioFilterControl, data );
   PAS_State->audiofilt = data;

   // Select the Sample Rate Timer
   data = SelectSampleRateTimer;
   PAS_Write( LocalTimerControl, data );
   PAS_State->tmrctlr = data;

   LoByte = lobyte( PAS_TimeInterval );
   HiByte = hibyte( PAS_TimeInterval );

   // Program the Sample Rate Timer
   PAS_Write( SampleRateTimer, LoByte );
   PAS_Write( SampleRateTimer, HiByte );
   PAS_State->samplerate = PAS_TimeInterval;

   RestoreInterrupts( flags );
   }
示例#19
0
文件: condvar.c 项目: cod5/kielder
void CondBroadcast (struct Cond *cond)
{
	struct Process *proc;
	
	if (current_process == NULL)
		return;
	
	do
	{
		DisableInterrupts();
	
		proc = LIST_HEAD (&cond->blocked_list);
	
		if (proc != NULL)
		{
			LIST_REM_HEAD (&cond->blocked_list, blocked_entry);
			
			proc->state = PROC_STATE_READY;
			SchedReady (proc);
			Reschedule();
		}
		
		proc = LIST_HEAD (&cond->blocked_list);
		EnableInterrupts();

	} while (proc != NULL);
}
示例#20
0
文件: guswave.c 项目: Rockbox/rockbox
int GUSWAVE_VoicesPlaying
   (
   void
   )

   {
   int         index;
   int         NumVoices = 0;
   unsigned    flags;

   flags = DisableInterrupts();

   for( index = 0; index < GUSWAVE_MaxVoices; index++ )
      {
      if ( GUSWAVE_Voices[ index ].Active )
         {
         NumVoices++;
         }
      }

   RestoreInterrupts( flags );

   if ( GUS_Debug )
      {
      DB_printf( "Number of voices = %d.\n", NumVoices );
      }

   return( NumVoices );
   }