void init(void) { usart_init(); SETD(BLE_RST); SETP(BLE_RST); SETD(BLE_CTRL); SETP(BLE_CTRL); CLRP(RELAY_PIN0); SETD(RELAY_PIN0); CLRP(RELAY_PIN1); SETD(RELAY_PIN1); sei(); }
void loop() { // cc++; // if (cc>60000) { // status = !status; // if (status) { // SETP(RELAY_PIN); // } else { // CLRP(RELAY_PIN); // } // cc = 0; // } if (usart_chrready()) { char ch = usart_getchr(); switch (ch) { case 'h': { usart_printstr("\n\r" "h - help\n\r" "o - open doors\n\r" "c - close doors\n\r" "s = status\n\r"); break; } case 'o': { SETP(RELAY_PIN); status = 1; break; } case 'c': { CLRP(RELAY_PIN); status = 0; break; } case 's': { if (status) { usart_printstr("1"); } else { usart_printstr("0"); } break; } default: { break; } } usart_printstr("\n\rok\n\r"); } }
/* virtual */ bool IOWorkLoop::runEventSources() { bool res = false; bool traceWL = (gIOKitTrace & kIOTraceWorkLoops) ? true : false; bool traceES = (gIOKitTrace & kIOTraceEventSources) ? true : false; closeGate(); if (ISSETP(&fFlags, kLoopTerminate)) goto abort; if (traceWL) IOTimeStampStartConstant(IODBG_WORKLOOP(IOWL_WORK), (uintptr_t) this); bool more; do { CLRP(&fFlags, kLoopRestart); more = false; IOInterruptState is = IOSimpleLockLockDisableInterrupt(workToDoLock); workToDo = false; IOSimpleLockUnlockEnableInterrupt(workToDoLock, is); /* NOTE: only loop over event sources in eventChain. Bypass "passive" event sources for performance */ for (IOEventSource *evnt = eventChain; evnt; evnt = evnt->getNext()) { if (traceES) IOTimeStampStartConstant(IODBG_WORKLOOP(IOWL_CLIENT), (uintptr_t) this, (uintptr_t) evnt); more |= evnt->checkForWork(); if (traceES) IOTimeStampEndConstant(IODBG_WORKLOOP(IOWL_CLIENT), (uintptr_t) this, (uintptr_t) evnt); if (ISSETP(&fFlags, kLoopTerminate)) goto abort; else if (fFlags & kLoopRestart) { more = true; break; } } } while (more); res = true; if (traceWL) IOTimeStampEndConstant(IODBG_WORKLOOP(IOWL_WORK), (uintptr_t) this); abort: openGate(); return res; }
/* virtual */ bool IOWorkLoop::runEventSources() { bool res = false; closeGate(); if (ISSETP(&fFlags, kLoopTerminate)) goto abort; IOTimeWorkS(); bool more; do { CLRP(&fFlags, kLoopRestart); more = false; IOInterruptState is = IOSimpleLockLockDisableInterrupt(workToDoLock); workToDo = false; IOSimpleLockUnlockEnableInterrupt(workToDoLock, is); for (IOEventSource *evnt = eventChain; evnt; evnt = evnt->getNext()) { IOTimeClientS(); more |= evnt->checkForWork(); IOTimeClientE(); if (ISSETP(&fFlags, kLoopTerminate)) goto abort; else if (fFlags & kLoopRestart) { more = true; break; } } } while (more); res = true; IOTimeWorkE(); abort: openGate(); return res; }
void init(void) { usart_init(); CLRP(RELAY_PIN); SETD(RELAY_PIN); sei(); }