/*----------------------------------------------------------------------------*/ static void pinInterruptDisable(void *object) { struct PinInterrupt * const interrupt = object; interrupt->enabled = false; disableInterrupt(interrupt); }
void Serial::begin(int baudRate, SerialConfig config) { disableInterrupt(UART_IRQn); LPC_SYSCON->SYSAHBCLKCTRL |= 1 << 12; // Enable UART clock LPC_SYSCON->UARTCLKDIV = 1; // divided by 1 LPC_UART->LCR = 0x80 | config; unsigned int val = SystemCoreClock * LPC_SYSCON->SYSAHBCLKDIV / LPC_SYSCON->UARTCLKDIV / 16 / baudRate; LPC_UART->DLM = val / 256; LPC_UART->DLL = val % 256; LPC_UART->LCR = (int) config; // Configure data bits, parity, stop bits LPC_UART->FCR = 0x07; // Enable and reset TX and RX FIFO. LPC_UART->MCR = 0; // Disable modem controls (DTR, DSR, RTS, CTS) LPC_UART->IER |= UART_IE_RBR; // Enable RX/TX interrupts // Ensure a clean start, no data in either TX or RX FIFO flush(); clearBuffers(); // Drop data from the RX FIFO while (LPC_UART->LSR & LSR_RDR) val = LPC_UART->RBR; enableInterrupt(UART_IRQn); }
void task_addReady( task_t *task ){ task->state = READY; prioExistFlag[task->priority] = TRUE; disableInterrupt(); insert_rear(&ready_list[task->priority], &task->node); enableInterrupt(); }
void gpio_bbb_drv::detachInterrupt (uint8_t gpio) { disableInterrupt(gpio); usrHandler[gpio] = 0; int ret = ioctl(_fd, IOCTL_DETACH_INTERRUPT, gpio); if (ret < 0) { throw gpio_exception("Error in detachInterrupt, ", ret); } }
//------------------------------------------------------------------- cSystem::cSystem( unsigned char disableInterrupts ) { disableWatchdog(); if( disableInterrupts ) { disableInterrupt(); } }
s8int task_delete( task_t *task ){ task->state = CLOSE; task_remove(task); disableInterrupt(); insert_rear(&termination_list, &(task->node) ); enableInterrupt(); return OK; }
s8int task_suspend( task_t *task ){ if( task == current_task ){ task->state = BLOCK; disableInterrupt(); remove_node( &(task->node) ); insert_rear(&blocked_list, &task->node); enableInterrupt(); }else if( task->priority > current_task->priority && task->state == READY ){ task->state = BLOCK; disableInterrupt(); remove_node( &(task->node) ); insert_rear(&blocked_list, &task->node); enableInterrupt(); } return OK; }
void task_remove( task_t *task ){ disableInterrupt(); remove_node( &(task->node) ); enableInterrupt(); if(is_Empty(&ready_list[task->priority])){ prioExistFlag[task->priority] = FALSE; } task_table[task->task_id] = 0; }
static int handleIRQ(std::uint32_t irq) { // Is it PIC interrupt if (irq < 16) { // Does it come from slave PIC if (irq >= 8) { outb(0xA0, 0x20); } outb(0x20, 0x20); } /*switch(irq) { case 0: Clock::tic(); break; case 1: Keyboard::handleInterrupt(); break; default: return 0; }*/ if (_handlers[irq] != nullptr) { if (_handlers[irq]->getFlags().FAST) { (*_handlers[irq])(); } else { enableInterrupt(); (*_handlers[irq])(); disableInterrupt(); } } else { for (auto handler: _sharedHandlers[irq]) { if (handler->getFlags().FAST) { handler[irq](); } else { enableInterrupt(); handler[irq](); disableInterrupt(); } } } return 0; }
/*----------------------------------------------------------------------------*/ static void pinInterruptSetCallback(void *object, void (*callback)(void *), void *argument) { struct PinInterrupt * const interrupt = object; interrupt->callbackArgument = argument; interrupt->callback = callback; if (interrupt->enabled && callback) enableInterrupt(interrupt); else disableInterrupt(interrupt); }
static void pinInterruptDeinit(void *object) { const struct PinInterrupt * const interrupt = object; const uint32_t mask = 1UL << interrupt->pin.offset; /* Disable channel interrupt in the interrupt controller */ disableInterrupt(interrupt); /* Disable interrupt sources */ LPC_GPIO_INT->CIENR = mask; LPC_GPIO_INT->CIENF = mask; resetInstance(interrupt->channel); }
int Serial::read() { bool readFull = readBufferFull(); int ch = BufferedStream::read(); if (readFull && (LPC_UART->LSR & LSR_RDR)) { disableInterrupt(UART_IRQn); interruptHandler(); enableInterrupt(UART_IRQn); } return ch; }
/*! \brief down \param sem target semaphore \author Higepon \date create:2003/01/31 update:2003/03/21 */ int Semaphore::down(semaphore* sem) { uint32_t eflags = get_eflags(); disableInterrupt(); if (*sem) { (*sem)--; set_eflags(eflags); return 0; } else { set_eflags(eflags); return -1; } }
IOReturn IOSharedInterruptController::unregisterInterrupt(IOService *nub, int source) { IOInterruptVectorNumber vectorNumber; IOInterruptVector *vector; IOInterruptState interruptState; for (vectorNumber = 0; vectorNumber < kIOSharedInterruptControllerDefaultVectors; vectorNumber++) { vector = &vectors[vectorNumber]; // Get the lock for this vector. IOLockLock(vector->interruptLock); // Return success if it is not already registered if (!vector->interruptRegistered || (vector->nub != nub) || (vector->source != source)) { IOLockUnlock(vector->interruptLock); continue; } // Soft disable the source and the controller too. disableInterrupt(nub, source); // Clear all the storage for the vector except for interruptLock. vector->interruptActive = 0; vector->interruptDisabledSoft = 0; vector->interruptDisabledHard = 0; vector->interruptRegistered = 0; vector->nub = 0; vector->source = 0; vector->handler = 0; vector->target = 0; vector->refCon = 0; interruptState = IOSimpleLockLockDisableInterrupt(controllerLock); vectorsRegistered--; IOSimpleLockUnlockEnableInterrupt(controllerLock, interruptState); // Move along to the next one. IOLockUnlock(vector->interruptLock); } // Re-enable the controller if all vectors are enabled. if (vectorsEnabled == vectorsRegistered) { controllerDisabled = 0; provider->enableInterrupt(0); } return kIOReturnSuccess; }
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; } }
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){ } }
IOReturn IOSharedInterruptController::unregisterInterrupt(IOService *nub, int source) { IOInterruptSource *interruptSources; long vectorNumber; IOInterruptVector *vector; OSData *vectorData; IOInterruptState interruptState;; interruptSources = nub->_interruptSources; vectorData = interruptSources[source].vectorData; vectorNumber = *(long *)vectorData->getBytesNoCopy(); vector = &vectors[vectorNumber]; // Get the lock for this vector. IOTakeLock(vector->interruptLock); // Return success if it is not already registered if (!vector->interruptRegistered) { IOUnlock(vector->interruptLock); return kIOReturnSuccess; } // Soft disable the source. disableInterrupt(nub, source); // Clear all the storage for the vector except for interruptLock. vector->interruptActive = 0; vector->interruptDisabledSoft = 0; vector->interruptDisabledHard = 0; vector->interruptRegistered = 0; vector->nub = 0; vector->source = 0; vector->handler = 0; vector->target = 0; vector->refCon = 0; interruptState = IOSimpleLockLockDisableInterrupt(controllerLock); vectorsRegistered--; IOSimpleLockUnlockEnableInterrupt(controllerLock, interruptState); IOUnlock(vector->interruptLock); return kIOReturnSuccess; }
/* 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, " "); }
IOReturn IOInterruptController::unregisterInterrupt(IOService *nub, int source) { IOInterruptSource *interruptSources; IOInterruptVectorNumber vectorNumber; IOInterruptVector *vector; OSData *vectorData; interruptSources = nub->_interruptSources; vectorData = interruptSources[source].vectorData; vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy(); vector = &vectors[vectorNumber]; // Get the lock for this vector. IOLockLock(vector->interruptLock); // Return success if it is not already registered if (!vector->interruptRegistered) { IOLockUnlock(vector->interruptLock); return kIOReturnSuccess; } // Soft disable the source. disableInterrupt(nub, source); // Turn the source off at hardware. disableVectorHard(vectorNumber, vector); // Clear all the storage for the vector except for interruptLock. vector->interruptActive = 0; vector->interruptDisabledSoft = 0; vector->interruptDisabledHard = 0; vector->interruptRegistered = 0; vector->nub = 0; vector->source = 0; vector->handler = 0; vector->target = 0; vector->refCon = 0; IOLockUnlock(vector->interruptLock); return kIOReturnSuccess; }
/* 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; }
void InterruptRouter::setInterruptListener(InterruptListener * listener) { disableInterrupt(DATA_INTERRUPT); disableInterrupt(CLOCK_INTERRUPT); this->listener = listener; }
/*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; }
// 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 unhandledInterruptHandler(void){ /* turn it off so it doesn't happen again, and a handy breakpoint */ disableInterrupt(theInterruptController.active - 16); }
Controller_t::Controller_t() { disableInterrupt(); }
void Serial::end() { flush(); disableInterrupt(UART_IRQn); LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 12); // Disable UART clock }