コード例 #1
0
int mailbox::begin(bool mode, void (*callbackFunction)()) {
	inbox = (char*) malloc(10);
	newMessage = false; //clear new message flags.
	messageIndex = 0;
	receiveCallback = callbackFunction; //set the callback function.
	spiMode = SPI_MASTER; //DSP Shield can only be an SPI Master due to hardware limitation.
	
    SPI_Class::begin(); //initialize SPI
	SPI_Class::setClockDivider(SPI_CLOCK_DIV128);

	pinMode(SPI_RX_SEL, OUTPUT);
    pinMode(ARD_SPI_EN, OUTPUT);
    digitalWrite(SPI_RX_SEL, LOW);
    digitalWrite(ARD_SPI_EN, HIGH);
	
	//attach master select interrupt
	pinMode(MS, INPUT);
    digitalWrite(MS, HIGH);
    //Init external interrupt module
    //initInterrupt(0x0000);

    // Plugin the ISR to vector table and enbale interrupts 	
    //attachInterrupt(INTERRUPT_INT1, (INTERRUPT_IsrPtr)INT1_isr, 0);    
    //enableInterrupt(INTERRUPT_INT1);

    //Init timer interrupt module
    // Open the GPT module for GPT 0 instance 
    Timer.selectTimer(GPT0);

    // Configure GPT period 
    long period = 0x100000;
    Timer.setPeriod(period);

    // Start the Timer 
    Timer.start();
    
    // Init interrupt module
    initInterrupt(0x0000);
    Plugin the ISR to vector table and enbale interrupts 	
    attachInterrupt(INTERRUPT_TINT, (INTERRUPT_IsrPtr)INT1_isr, 0);    
    enableInterrupt(INTERRUPT_TINT);


	if(!digitalRead(MS))
		{
			receive();
		};
	return 1; //""success""
}
コード例 #2
0
ファイル: task.c プロジェクト: herb123456/DIY_Kernel
s8int task_resume( task_t *task ){
	if( task->state == BLOCK ){
		task->state = READY;
		
		disableInterrupt();
		remove_node( &(task->node) );
		enableInterrupt();
		
		task_addReady(task);
		
		return OK;
	}else{
		return ERROR;
	}
}
コード例 #3
0
ファイル: task.c プロジェクト: herb123456/DIY_Kernel
static void task_timeout(void *parameter){
	task_t *task;
	
	task = (task_t *)parameter;
	
	task->state = READY;
	disableInterrupt();
	remove_node( &(task->node) );
	enableInterrupt();
	task_addReady(task);
	
	if(current_task->priority > task->priority){
	
	}
}
コード例 #4
0
void enableKeyIRQ( int keys_to_watch, ptr_to_function newISR )

{

	registerISR( IRQ_KEY, newISR );	
	/* specify which ISR to call with KEY interrupts */

	*pKEY_IRQENABLE = keys_to_watch;
	
	/* Device: to send interrupts for KEY3,KEY2 */

	enableInterrupt( IRQ_KEY );
	
	/* CPU: allow it to receive KEY interrupts */

}
コード例 #5
0
ファイル: Motion.cpp プロジェクト: hradec/sjfw
// Takes the next queued gcode and begins running it.
void Motion::gcode_execute(GCode& gcode)
{
  // Only execute codes that are prepared.
  if(gcode.state < GCode::PREPARED)
    return; // TODO: This should never happen now and is an error.
  // Don't execute codes that are ACTIVE or DONE (ACTIVE get handled by interrupt)
  if(gcode.state > GCode::PREPARED)
    return;

  // Make sure they have configured the axis!
  if(AXES[0].isInvalid())
  {
    Host::Instance(gcode.source).write_P(PSTR("!! AXIS ARE NOT CONFIGURED !!\n"));
    gcode.state = GCode::DONE;
    return;
  }

  if(gcode.movesteps == 0)
  {
    gcode.state = GCode::DONE;
    return;
  }

  // Prepare axis move data -- Invalidate all precomputes if bad data (happens on hitting an endstop)
  for(int ax=0;ax<NUM_AXES;ax++)
  {
    if(!AXES[ax].setupMove(gcode.startpos[ax], gcode.axisdirs[ax], gcode.axismovesteps[ax]))
    {
      GCODES.Invalidate();
      // We'll get back here after the first move is recomputed.
      return;
    }
    deltas[ax] = gcode.axismovesteps[ax];
    errors[ax] = gcode.movesteps >> 1;
  }

  // setup pointer to current move data for interrupt
  gcode.state = GCode::ACTIVE;
  current_gcode = &gcode;

  setInterruptCycles(gcode.currentinterval);
  enableInterrupt();
}
コード例 #6
0
/* Generates a standard page for the boot-up of the program */
void welcomeMessage()
{
	int i = 0;
	//in order to prevent the GUI stuff show up...
	disableInterrupt(IRQ_COUNTER);
	fillScreen(BLUE);
	printStr(12, 11, "Hit the Balloon!");
	printStr(9, 13, "EECE 259 Final Project");
	printStr(10, 17, "By: Navid Fattahi");
	printStr(10, 18, "Shayan Farahbakhsh");
	for(i = 0; i < 40000000; i++);
	//in order to get the GUI stuff show up again!
	enableInterrupt(IRQ_COUNTER);
	printStr(12, 11, "                ");

	printStr(9, 13, "                      ");
	printStr(10, 17, "                 ");
	printStr(10, 18, "                  ");
}
コード例 #7
0
void OpenDeviceClass::begin(DeviceConnection &_deviceConnection) {

	deviceConnection = &_deviceConnection;

	Logger.debug("ModuleName", Config.moduleName);
	Logger.debug("Server", Config.server);

	char version[30];
	strcpy(version, API_VERSION);
	strcat(version, "@");
	strcat(version, FirmwareBuildDate);
	
	Logger.debug("Firmware", version); // from build_defs.h

	for (int i = 0; i < deviceLength; i++) {
		devices[i]->init();
		if(devices[i]->interruptEnabled){
			#if(ENABLE_DEVICE_INTERRUPTION)
				PIN_INTERRUPT = &arduinoInterruptedPin;
				enableInterrupt(devices[i]->pin, &(OpenDeviceClass::onInterruptReceived), devices[i]->interruptMode);
			#endif
		}
	}

	// Load Device(ID) / Value from Storage and set in devices
	loadDevicesFromStorage();

	// Trace restarts using VALUE of board
	devices[0]->currentValue++;

	if(deviceConnection){
		deviceConnection->setDefaultListener(&(OpenDeviceClass::onMessageReceived));
	}

	deviceConnection->begin();

	_afterBegin();

	// ODev.debug("Begin [OK]");

}
コード例 #8
0
/*
 * Initialize the application.
 */
void setup()
{
  dht.DHTInit(PIO2_2, DHT22);       // Use the DHT22 sensor on PIN
  //dht1.DHTInit(PIO0_7, DHT22);      // Use the DHT22 sensor on PIN

  // LED Initialize
	pinMode(PIO2_6, OUTPUT);	// Info LED (yellow)
	pinMode(PIO3_3, OUTPUT);	// Run  LED (green)
	pinMode(PIO2_0, OUTPUT);  // Prog LED (red)

	// LED Set Initial Value (ON|OFF)
	digitalWrite(PIO3_3, 0);  // Info LED (yellow)
	digitalWrite(PIO2_6, 0);  // Run  LED (green)             // Will be toggled with dht function (blink on read success)
	digitalWrite(PIO2_0, 1);  // Prog LED (red)

  enableInterrupt(TIMER_32_0_IRQn);                         // Enable the timer interrupt
  timer32_0.begin();                                        // Begin using the timer
    timer32_0.prescaler((SystemCoreClock / 1000) - 1);      // Let the timer count milliseconds
    timer32_0.matchMode(MAT1, RESET | INTERRUPT);           // On match of MAT1, generate an interrupt and reset the timer
    timer32_0.match(MAT1, READ_TIMER);                      // Match MAT1 when the timer reaches this value (in milliseconds)
  timer32_0.start();                                        // Start now the timer
}
コード例 #9
0
/*
 * Initialize the application.
 */
void setup()
{
#if DBG_RTC
  rtc.Ds3231Init();           // Initialize Ds3231
  // WriteInitTime();         // Comment in, if you want setup the RTC TIME/Calendar
  // SetRTCAlarm();           // Comment in, if you want to set the Alarm1|2
#endif

#if DBG_LUX
  bh.BH1750Init();            // Initialize BH1750
#endif

#if DBG_DHT
  dht.DHTInit(PIO2_2, DHT22); // Use the DHT22 sensor on PIN
#endif

  /*
  if(I2C::Instance()->bI2CIsInitialized) {  // I2CScan
      I2C::Instance()->I2CScan();           // check .I2CScan_State ans .I2CScan_uAdress
  }
  */

  // LED Initialize
	pinMode(PIO2_6, OUTPUT);	 // Info LED (yellow)
	pinMode(PIO3_3, OUTPUT);	 // Run  LED (green)
	pinMode(PIO2_0, OUTPUT);   // Prog LED (red)

	// LED Set Initial Value (ON|OFF)
	digitalWrite(PIO3_3, 0);   // Info LED (yellow)          // Will be toggled with dht function (blink on read success)
	digitalWrite(PIO2_6, 0);   // Run  LED (green)           // Will be toggled with LUX function (off if Lux == 0)
	digitalWrite(PIO2_0, 1);   // Prog LED (red)             // Will be toggled with rtc function

  enableInterrupt(TIMER_32_0_IRQn);                        // Enable the timer interrupt
  timer32_0.begin();                                       // Begin using the timer
    timer32_0.prescaler((SystemCoreClock / 1000) - 1);     // Let the timer count milliseconds
    timer32_0.matchMode(MAT1, RESET | INTERRUPT);          // On match of MAT1, generate an interrupt and reset the timer
    timer32_0.match(MAT1, READ_TIMER);                     // Match MAT1 when the timer reaches this value (in milliseconds)
  timer32_0.start();                                       // Start now the timer
}
コード例 #10
0
ファイル: CurieIMU.cpp プロジェクト: xbed/SMeshStudio_Core
void CurieIMUClass::interrupts(int feature)
{
    enableInterrupt(feature, true);
}
コード例 #11
0
ファイル: CurieIMU.cpp プロジェクト: xbed/SMeshStudio_Core
void CurieIMUClass::noInterrupts(int feature)
{
    enableInterrupt(feature, false);
}
コード例 #12
0
IOReturn IOInterruptController::registerInterrupt(IOService *nub, int source,
						  void *target,
						  IOInterruptHandler handler,
						  void *refCon)
{
  IOInterruptSource *interruptSources;
  IOInterruptVectorNumber vectorNumber;
  IOInterruptVector *vector;
  int               wasDisabledSoft;
  IOReturn          error;
  OSData            *vectorData;
  IOOptionBits      options;
  bool              canBeShared, shouldBeShared, wasAlreadyRegisterd;

  IOService         *originalNub = NULL; // Protected by wasAlreadyRegisterd
  int               originalSource = 0; // Protected by wasAlreadyRegisterd
 

  interruptSources = nub->_interruptSources;
  vectorData = interruptSources[source].vectorData;
  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
  vector = &vectors[vectorNumber];
  
  // Get the lock for this vector.
  IOLockLock(vector->interruptLock);
  
  // Check if the interrupt source can/should be shared.
  canBeShared = vectorCanBeShared(vectorNumber, vector);
  IODTGetInterruptOptions(nub, source, &options);
#if defined(__i386__) || defined(__x86_64__)
  int   interruptType;
  if (OSDynamicCast(IOPlatformDevice, getProvider()) &&
      (getInterruptType(nub, source, &interruptType) == kIOReturnSuccess) &&
      (kIOInterruptTypeLevel & interruptType))
  {
    options |= kIODTInterruptShared;
  }
#endif
  shouldBeShared = canBeShared && (options & kIODTInterruptShared);
  wasAlreadyRegisterd = vector->interruptRegistered;
  
  // If the vector is registered and can not be shared return error.
  if (wasAlreadyRegisterd && !canBeShared) {
    IOLockUnlock(vector->interruptLock);
    return kIOReturnNoResources;
  }
  
  // If this vector is already in use, and can be shared (implied),
  // or it is not registered and should be shared,
  // register as a shared interrupt.
  if (wasAlreadyRegisterd || shouldBeShared) {
    // If this vector is not already shared, break it out.
    if (vector->sharedController == 0) {
      // Make the IOShareInterruptController instance
      vector->sharedController = new IOSharedInterruptController;
      if (vector->sharedController == 0) {
        IOLockUnlock(vector->interruptLock);
        return kIOReturnNoMemory;
      }
      
      if (wasAlreadyRegisterd) {
	// Save the nub and source for the original consumer.
	originalNub = vector->nub;
	originalSource = vector->source;
	
	// Physically disable the interrupt, but mark it as being enabled in the hardware.
	// The interruptDisabledSoft now indicates the driver's request for enablement.
	disableVectorHard(vectorNumber, vector);
	vector->interruptDisabledHard = 0;
      }
      
      // Initialize the new shared interrupt controller.
      error = vector->sharedController->initInterruptController(this, vectorData);
      // If the IOSharedInterruptController could not be initalized,
      // if needed, put the original consumer's interrupt back to normal and
      // get rid of whats left of the shared controller.
      if (error != kIOReturnSuccess) {
	if (wasAlreadyRegisterd) enableInterrupt(originalNub, originalSource);
        vector->sharedController->release();
        vector->sharedController = 0;
        IOLockUnlock(vector->interruptLock);
        return error;
      }
      
      // If there was an original consumer try to register it on the shared controller.
      if (wasAlreadyRegisterd) {
	error = vector->sharedController->registerInterrupt(originalNub,
							    originalSource,
							    vector->target,
							    vector->handler,
							    vector->refCon);
	// If the original consumer could not be moved to the shared controller,
	// put the original consumor's interrupt back to normal and
	// get rid of whats left of the shared controller.
	if (error != kIOReturnSuccess) {
	  // Save the driver's interrupt enablement state.
	  wasDisabledSoft = vector->interruptDisabledSoft;
	  
	  // Make the interrupt really hard disabled.
	  vector->interruptDisabledSoft = 1;
	  vector->interruptDisabledHard = 1;
	  
	  // Enable the original consumer's interrupt if needed.
	  if (!wasDisabledSoft) originalNub->enableInterrupt(originalSource);
	  enableInterrupt(originalNub, originalSource);
	  
	  vector->sharedController->release();
	  vector->sharedController = 0;
	  IOLockUnlock(vector->interruptLock);
	  return error;
	}
      }
      
      // Fill in vector with the shared controller's info.
      vector->handler = (IOInterruptHandler)vector->sharedController->getInterruptHandlerAddress();
      vector->nub     = vector->sharedController;
      vector->source  = 0;
      vector->target  = vector->sharedController;
      vector->refCon  = 0;
      
      // If the interrupt was already registered,
      // save the driver's interrupt enablement state.
      if (wasAlreadyRegisterd) wasDisabledSoft = vector->interruptDisabledSoft;
      else wasDisabledSoft = true;
      
      // Do any specific initalization for this vector if it has not yet been used.
      if (!wasAlreadyRegisterd) initVector(vectorNumber, vector);
      
      // Make the interrupt really hard disabled.
      vector->interruptDisabledSoft = 1;
      vector->interruptDisabledHard = 1;
      vector->interruptRegistered   = 1;
      
      // Enable the original consumer's interrupt if needed.
      // originalNub is protected by wasAlreadyRegisterd here (see line 184).
      if (!wasDisabledSoft) originalNub->enableInterrupt(originalSource);
    }
    
    error = vector->sharedController->registerInterrupt(nub, source, target,
                                                        handler, refCon);
    IOLockUnlock(vector->interruptLock);
    return error;
  }
  
  // Fill in vector with the client's info.
  vector->handler = handler;
  vector->nub     = nub;
  vector->source  = source;
  vector->target  = target;
  vector->refCon  = refCon;
  
  // Do any specific initalization for this vector.
  initVector(vectorNumber, vector);
  
  // Get the vector ready.  It starts hard disabled.
  vector->interruptDisabledHard = 1;
  vector->interruptDisabledSoft = 1;
  vector->interruptRegistered   = 1;
  
  IOLockUnlock(vector->interruptLock);
  return kIOReturnSuccess;
}
コード例 #13
0
ファイル: System.cpp プロジェクト: ThBreuer/EmbSysLib
//-------------------------------------------------------------------
void cSystem::start( void )
{
  enableInterrupt();
}
コード例 #14
0
/*Moves the motors simultaneously the number of steps given in the array.
The motors will start and stop at the same time, no matter the selected
speed and number of steps (the motor that would take the longest is taken
as reference, and the speed of other motors adjusted accordingly).*/
int StepperControl::moveAll(long *stepsE){
	movementCompleted = 0; //Resetting status.
	int exitStatus = 0; //Return value of the external function that can be added to the loop.
	uint16_t mask = 0; //Each bit contains info about what motor will be disabled (1 disabled, 0 enabled).
	
	long steps[motorsCount]; //Local array containing the number of steps to be executed by each motor.
	if(steps != NULL) memcpy(steps, stepsE, motorsCount*sizeof(long));
	else return 2; //End function if the given array is not valid.
	
	long minMovementDuration; //The lowest amount of time the slowest motor (or the one with the most steps to do) will need to complete it's movement.
	long durations[motorsCount]; //Used for calculation of time-dependent values. Has different contents.
	int slowestMotor = 0; //Index of the motor of which the movement will take the longest.
	int dir[motorsCount]; //Contains movement direction of the motors.
	
	totalSteps = 0; //Resetting the number of steps to be done.
	
	int slMin; //Index of the motor with the lowest signalLength value among the active ones.
	unsigned long *slp; //Points to a copy of signalLength.
	slp = (unsigned long*)calloc(motorsCount, sizeof(unsigned long));
	memcpy(slp, signalLength, motorsCount*sizeof(unsigned long)); //Sloppy (signalLength has type long*), but if signalLength contains negative values, there is a bigger problem.
	
	//The direction pins of all motors are set here depending on whether or not the number of steps is negative.
	//The total number of state changes to be done is also calculated here.
	for(int i = 0; i < motorsCount; i++){
		if(steps[i] < 0){
			dir[i] = 1;
			steps[i] = -steps[i];
		}else{
			dir[i] = 0;
		}
		totalSteps += steps[i];
		setDir(i, dir[i]); //Setting the correct values to the direction pins.
		
		durations[i] = movementTime[i] * steps[i];
		
		if(!steps[i]){
			mask |= (1 << i);
			slp[i] = 0; //Causes arrayMin in the next step to ignore the motors that will be inactive.
		}
	}
	totalSteps = totalSteps*2;
	
	//Set starting conditions (without this part the signal polarity can be wrong).
	slMin = arrayMin(slp, motorsCount, 0);
	for(int i = 0; i < motorsCount; i++){
		if(signalLength[i] > signalLength[slMin] && !(mask & (1 << i))){
			stepStatus[i] = 1;
			currentState[i] = 1;
		}else{
			stepStatus[i] = 0;
			currentState[i] = 0;
		}
	}
	free(slp);//We won't need slp any more.

	//Here, the form and duration of the impulses is determined.
	slowestMotor = arrayMax(durations, motorsCount);
	minMovementDuration = durations[slowestMotor];
	for(int i = 0; i < motorsCount; i++){
		durations[i] = minMovementDuration / steps[i];
		if(durations[i] > signalLength[i]) durations[i] -= signalLength[i];
		else durations[i] = 0;
		
		if(durations[i] > 0){
			lowTime[i] = (long)((clockFrequency/(64*(1000000.0/durations[i]))));
			highTime[i] = (long)((clockFrequency/(64*(1000000.0/signalLength[i]))));
		}else{
			lowTime[i] = 0;
			highTime[i] = 0;
		}
	}
	
	//Actual movement starts to happen here.
	//Setting all motors to HIGH at start.
	taskList[3][0] = 0xFFFF;
	fillTaskList(mask);//Preparing the buffer.
	enableInterrupt();//Starting movement.
	while(!movementCompleted){
		//if(idleCounter) Serial.println(idleCounter); //debug
		exitStatus = repeatInLoop(); //External function to be executed during the movement.
		if(exitStatus == 1) break; //If the external function returns 1, the movemen stops.
		fillTaskList(mask);
	}
	disableInterrupt();//Stopping interrupts, so that they won't interfere with the program.
	
	//Movement ended, resetting values.
	stepsCounter = 0;
	stepsCounterCalc = 0;
	movementCompleted = 0;
	executionIndex = 0;
	calculationIndex = 1;
	clearTaskList();
	for(int i = 0; i < motorsCount; i++){
		//individualStepsCounter[i] = 0; //Use resetIndividualStepsCounter() instead.
		currentState[i] = 0;
		stepStatus[i] = 0;
		nextStep[i] = 0;
	}
	
	return exitStatus;
}
コード例 #15
0
ファイル: Motion.cpp プロジェクト: hradec/sjfw
// SJFW's main movement routine in some sense; this is executed by the processor
// for each step of the primary axis in a movement.
void Motion::handleInterrupt()
{
  // This shouldn't be necessary if I've managed things properly, but I doubt I have.
  if(busy)
    return;

#ifdef INTERRUPT_STEPS
  // We typically have this option enabled to allow the comms interrupt
  // to occur while we are doing anything heavy here.
  busy = true;
  //resetTimer();
  disableInterrupt();
  sei();
#endif  

  // interruptOverflow for step intervals > 16bit
  if(interruptOverflow > 0)
  {
    interruptOverflow--;
    enableInterrupt();
    busy=false;
    return;
  }

  if(current_gcode->movesteps == 0)
  {
    disableInterrupt();
    current_gcode->state = GCode::DONE;
    busy=false;
    return;
  }

  current_gcode->movesteps--;

  // Bresenham-style axis alignment algorithm
  for(ax=0;ax<NUM_AXES;ax++)
  {
    if(ax == current_gcode->leading_axis)
    {
      AXES[ax].doStep();
      continue;
    }

    errors[ax] = errors[ax] - deltas[ax];
    if(errors[ax] < 0)
    {
      AXES[ax].doStep();
      errors[ax] = errors[ax] + deltas[current_gcode->leading_axis];
    }
  }


  accelsteps = 0;
  current_gcode->accel_timer += current_gcode->currentinterval;
  // Handle acceleration and deceleration
  while(current_gcode->accel_timer > ACCEL_INC_TIME)
  {
    current_gcode->accel_timer -= ACCEL_INC_TIME;
    accelsteps++;
  }

  if(accelsteps)
  {
    if(current_gcode->movesteps >= current_gcode->accel_until && current_gcode->currentfeed < current_gcode->maxfeed)
    { 
      current_gcode->currentfeed += current_gcode->accel_inc * accelsteps;

      if(current_gcode->currentfeed > current_gcode->maxfeed)
        current_gcode->currentfeed = current_gcode->maxfeed;

      current_gcode->currentinterval = AXES[current_gcode->leading_axis].int_interval_from_feedrate(current_gcode->currentfeed);

      setInterruptCycles(current_gcode->currentinterval);
    }
    else if(current_gcode->movesteps <= current_gcode->decel_from && current_gcode->currentfeed > current_gcode->endfeed)
    { 
      current_gcode->currentfeed -= current_gcode->accel_inc * accelsteps;

      if(current_gcode->currentfeed < current_gcode->endfeed)
        current_gcode->currentfeed = current_gcode->endfeed;

      current_gcode->currentinterval = AXES[current_gcode->leading_axis].int_interval_from_feedrate(current_gcode->currentfeed);

      setInterruptCycles(current_gcode->currentinterval);
    }

  }

  // This check is only important if we hit endstops; lets us know all the involved axis
  // have reached their end early.
  if(!axesAreMoving())
  {
    current_gcode->movesteps = 0;
  }
      
  if(current_gcode->movesteps == 0)
  {
    disableInterrupt();
    current_gcode->state = GCode::DONE;
  }
#ifdef INTERRUPT_STEPS
  else
    enableInterrupt();

  busy = false;
#endif  
}
void main(){ 
	
	Setup_IOports();
	atod_init();
	_delay(200);
	lcd_init();
	Serial_Init();
	Timer1_Init();
	enableInterrupt();

	clr_display();
	printf("Body Temperature ");
	position(2,1);
	printf(" and Heart Rate  ");
	__delay_ms(5000);
		
	clr_display();
	
	while(1){				
		switch (Mode){
			case  0 :			
				a2d_read();				
				__delay_ms(100);
				check_pc();
			break;
			case 1 :			
				Tx_Control = 1;
				Serial_Print( "*#DREQ=123" );
				Serial_NewLine();
				Tx_Control = 0;		
			break;
			case 2 :
				Tx_Control = 1;
				Serial_Print( "*#123=" );				
				Serial_NewLine();				
				Tx_Control = 0;	
			break;
			case 3 :
				Tx_Control = 1;				
				Serial_Print( "*#123=" );							
				Tx_Control = 0;	
				
				position(1,1);
				printf("Data request... ");
				position(2,1);
				printf("                ");
							
			break;
			case 4 :
				Tx_Control = 1;				
				Serial_NewLine();
				Tx_Control = 0;	
								
			case 5 :
				clr_display();			
			break;
			default:
			
			break;
		}	
	}
}
コード例 #17
0
IOReturn IOInterruptController::registerInterrupt(IOService *nub, int source,
						  void *target,
						  IOInterruptHandler handler,
						  void *refCon)
{
  IOInterruptSource *interruptSources;
  long              vectorNumber;
  IOInterruptVector *vector;
  long              wasDisabledSoft;
  IOReturn          error;
  OSData            *vectorData;
  IOService         *originalNub;
  int               originalSource;
  
  interruptSources = nub->_interruptSources;
  vectorData = interruptSources[source].vectorData;
  vectorNumber = *(long *)vectorData->getBytesNoCopy();
  vector = &vectors[vectorNumber];
  
  // Get the lock for this vector.
  IOTakeLock(vector->interruptLock);
  
  // If this vector is already in use, and can be shared,
  // register as a shared interrupt.
  if (vector->interruptRegistered) {
    if (!vectorCanBeShared(vectorNumber, vector)) {
      IOUnlock(vector->interruptLock);
      return kIOReturnNoResources;
    }
    
    // If this vector is not already shared, break it out.
    if (vector->sharedController == 0) {
      // Make the IOShareInterruptController instance
      vector->sharedController = new IOSharedInterruptController;
      if (vector->sharedController == 0) {
        IOUnlock(vector->interruptLock);
        return kIOReturnNoMemory;
      }
      
      // Save the nub and source for the original consumer.
      originalNub = vector->nub;
      originalSource = vector->source;
      
      // Physically disable the interrupt, but mark it as being enables in the hardware.
      // The interruptDisabledSoft now indicates the driver's request for enablement.
      disableVectorHard(vectorNumber, vector);
      vector->interruptDisabledHard = 0;
      
      // Initialize the new shared interrupt controller.
      error = vector->sharedController->initInterruptController(this,
                                                                vectorData);
      // If the IOSharedInterruptController could not be initalized,
      // put the original consumor's interrupt back to normal and
      // get rid of whats left of the shared controller.
      if (error != kIOReturnSuccess) {
        enableInterrupt(originalNub, originalSource);
        vector->sharedController->release();
        vector->sharedController = 0;
        IOUnlock(vector->interruptLock);
        return error;
      }
      
      // Try to register the original consumer on the shared controller.
      error = vector->sharedController->registerInterrupt(originalNub,
                                                          originalSource,
                                                          vector->target,
                                                          vector->handler,
                                                          vector->refCon);
      // If the original consumer could not be moved to the shared controller,
      // put the original consumor's interrupt back to normal and
      // get rid of whats left of the shared controller.
      if (error != kIOReturnSuccess) {
	// Save the driver's interrupt enablement state.
	wasDisabledSoft = vector->interruptDisabledSoft;
	
	// Make the interrupt really hard disabled.
	vector->interruptDisabledSoft = 1;
	vector->interruptDisabledHard = 1;
	
	// Enable the original consumer's interrupt if needed.
	if (!wasDisabledSoft) originalNub->enableInterrupt(originalSource);
        enableInterrupt(originalNub, originalSource);
	
        vector->sharedController->release();
        vector->sharedController = 0;
        IOUnlock(vector->interruptLock);
        return error;
      }
      
      // Fill in vector with the shared controller's info.
      vector->handler = (IOInterruptHandler)vector->sharedController->getInterruptHandlerAddress();
      vector->nub     = vector->sharedController;
      vector->source  = 0;
      vector->target  = vector->sharedController;
      vector->refCon  = 0;
      
      // Save the driver's interrupt enablement state.
      wasDisabledSoft = vector->interruptDisabledSoft;
      
      // Make the interrupt really hard disabled.
      vector->interruptDisabledSoft = 1;
      vector->interruptDisabledHard = 1;
      
      // Enable the original consumer's interrupt if needed.
      if (!wasDisabledSoft) originalNub->enableInterrupt(originalSource);
    }
    
    error = vector->sharedController->registerInterrupt(nub, source, target,
                                                        handler, refCon);
    IOUnlock(vector->interruptLock);
    return error;
  }
  
  // Fill in vector with the client's info.
  vector->handler = handler;
  vector->nub     = nub;
  vector->source  = source;
  vector->target  = target;
  vector->refCon  = refCon;
  
  // Do any specific initalization for this vector.
  initVector(vectorNumber, vector);
  
  // Get the vector ready.  It starts hard disabled.
  vector->interruptDisabledHard = 1;
  vector->interruptDisabledSoft = 1;
  vector->interruptRegistered   = 1;
  
  IOUnlock(vector->interruptLock);
  return kIOReturnSuccess;
}
コード例 #18
0
/* Main Function */
int main( int argc, char *argv[] )
{
	//Color constants' initilizations
	BLACK = makeColour( 0, 0, 0 );
	WHITE = makeColour(63,63,63 );
	RED   = makeColour(63, 0, 0 );
	GREEN = makeColour( 0,63, 0 );
	BLUE  = makeColour( 0, 0,63 );

	//Initializations
	initInterrupts();
	initScreen();
	initChars();

	//Enable Interrupts
	enableBalloonIRQ(1000*ONE_MS, balloonISR );
	int keys_to_watch = 0x04 | 0x02 ;
	enableKeyIRQ( keys_to_watch, keyISR );


//	fillScreen(BLACK);
	int i = 0;
	welcomeMessage();

	mouse_status = resetPS2();

	int left, right;
	int lastTime;

	while(1)
	{
		//in case of losing (past 20 misses)
		if(missed >= MAX_MISS)
		{

			disableInterrupt(IRQ_COUNTER);

			fillScreen(RED);
			emptyScreen();

			printStr(10, 10, "Too many misses...");

			printStr(14, 13, "GAME OVER!");
			printStr(8, 16, "Press KEY2 to restart");
			for(i = 0; i < 30000000; i++);
//			while(missed >= 20);
//			printStr(8, 20, "HOOOOOORAY");
			enableInterrupt(IRQ_COUNTER);
			printStr(10, 10, "                  ");
	
			printStr(14, 13, "          ");
			printStr(8, 16, "                     ");
		}

		drawChar (1, 6, ' ');

		disableInterrupt(IRQ_COUNTER);
		if (*pSWITCH != 0)
		{
			if (*pSWITCH&1)
			{
				increment = 1;
				circleRad = 30;
			}
			else if (*pSWITCH&2)
			{
				increment = 2;
				circleRad = 20;

			}
			else if (*pSWITCH&4)
			{
				increment = 3;
				circleRad = 15;
			}
		}
		else
		{
			increment = 1;
			circleRad = 30;
		}		

		enableInterrupt(IRQ_COUNTER);

		/// MUSIC PLAYER ///
//		drawChar (1, 5, 16);
		if(musicCounter == 0)
		{
			left = 0;
			right = 1;
		}
		if(musicCounter < musicLength/4)
		{
			i = musicCounter;
			for(i; i<musicCounter+200; i++)
			{
				playMusic(music[left], music[right]);
				left+=2;
				right+=2;
			}
			musicCounter += 200;
		}
		else
		{
			musicCounter = 0;
			left = 0;
			right = 1;
		}
		/// MUSIC ///

		if ( mouse_status == PS2_MOUSE ) 
		{
//			drawChar (1, 5, 22);
			if( getMouseMotion( &dxMouse, &dyMouse, &mouse_button ) ) 
			{
				if( mouse_button & MOUSE_BUTTON1 )
				{
					if(getColor(xMouse+1, yMouse) == RED)
					{
						score += increment;
						drawCircle(xCircle, yCircle, 30, BLACK);
						/// SOUND EFFECT ///
						int sleft = 0;
						int sright = 1;
						int i;
						for(i=0; i<effectLength/4; i++)
						{
							playMusic(effect[sleft], effect[sright]);
							sleft+=2;
							sright+=2;
						}
						sleft = 0;
						sright = 1;
						/// SOUND EFFECT ///
					}
					else
					{
						if(time != lastTime)
						{
							missed++;
							time = lastTime;
						}
					}
				}

	/*			if( mouse_button & MOUSE_BUTTON2 )
					fillScreen( BLACK );
	
				if( mouse_button & MOUSE_BUTTON3 )
				{
					printStr(17, 13, "PAUSED!");
					disableInterrupts(IRQ_COUNTER);
					while( 1 )
					{
						if( mouse_button & MOUSE_BUTTON2 )
						{
							enableInterrupts(IRQ_COUNTER);
							printStr(17, 13, "       ");
							break;
						}
					}
				}
	*/


				if(getColor(xMouse+1, yMouse) == RED)
					dragColor = RED;
				else
					dragColor = BLACK;

				drawPixel( xMouse, yMouse, dragColor );

				xMouse += dxMouse;
				yMouse -= dyMouse;
				xMouse = max( 0, min( xMouse, MAX_X_PIXELS-1 ) );
				yMouse = max( 0, min( yMouse, MAX_Y_PIXELS-1 ) );

				drawPixel( xMouse, yMouse, WHITE );
				//drawCursor(xMouse, yMouse);
			}
		}
	}
	
	return 0;
}