static void _controller_HSM() { //----- ISRs. These should be considered the highest priority scheduler functions ----// /* * HI Stepper DDA pulse generation // see stepper.h * HI Stepper load routine SW interrupt // see stepper.h * HI Dwell timer counter // see stepper.h * MED GPIO1 switch port - limits / homing // see gpio.h * MED Serial RX for USB // see xio_usart.h * LO Segment execution SW interrupt // see stepper.h * LO Serial TX for USB & RS-485 // see xio_usart.h * LO Real time clock interrupt // see xmega_rtc.h */ //----- kernel level ISR handlers ----(flags are set in ISRs)-----------// // Order is important: DISPATCH(_reset_handler()); // 1. received software reset request DISPATCH(_bootloader_handler()); // 2. received bootloader request DISPATCH(_limit_switch_handler()); // 3. limit switch has been thrown DISPATCH(_alarm_idler()); // 4. idle in alarm state DISPATCH(_system_assertions()); // 5. system integrity assertions DISPATCH(cm_feedhold_sequencing_callback()); DISPATCH(mp_plan_hold_callback()); // plan a feedhold from line runtime //----- planner hierarchy for gcode and cycles -------------------------// DISPATCH(rpt_status_report_callback()); // conditionally send status report DISPATCH(rpt_queue_report_callback()); // conditionally send queue report DISPATCH(ar_arc_callback()); // arc generation runs behind lines DISPATCH(cm_homing_callback()); // G28.2 continuation //----- command readers and parsers ------------------------------------// DISPATCH(_sync_to_planner()); // ensure there is at least one free buffer in planning queue DISPATCH(_sync_to_tx_buffer()); // sync with TX buffer (pseudo-blocking) DISPATCH(cfg_baud_rate_callback()); // perform baud rate update (must be after TX sync) DISPATCH(_dispatch()); // read and execute next command }
static void _controller_HSM() { //----- kernel level ISR handlers ----(flags are set in ISRs)-----------// // Order is important: DISPATCH(_reset_handler()); // 1. software reset received DISPATCH(_bootloader_handler()); // 2. received ESC char to start bootloader DISPATCH(_limit_switch_handler()); // 3. limit switch has been thrown DISPATCH(_shutdown_idler()); // 4. idle in shutdown state DISPATCH(_system_assertions()); // 5. system integrity assertions DISPATCH(_feedhold_handler()); // 6. feedhold requested DISPATCH(_cycle_start_handler()); // 7. cycle start requested //----- planner hierarchy for gcode and cycles -------------------------// DISPATCH(rpt_status_report_callback()); // conditionally send status report DISPATCH(rpt_queue_report_callback()); // conditionally send queue report DISPATCH(mp_plan_hold_callback()); // plan a feedhold DISPATCH(mp_end_hold_callback()); // end a feedhold DISPATCH(ar_arc_callback()); // arc generation runs behind lines DISPATCH(cm_homing_callback()); // G28.2 continuation //----- command readers and parsers ------------------------------------// DISPATCH(_sync_to_planner()); // ensure there is at least one free buffer in planning queue DISPATCH(_sync_to_tx_buffer()); // sync with TX buffer (pseudo-blocking) DISPATCH(cfg_baud_rate_callback()); // perform baud rate update (must be after TX sync) DISPATCH(_dispatch()); // read and execute next command }
void dispatch(Callable callable) { // N.B. this is compatible with both C++11 lambdas, functors and C function pointers struct _Callback : public Callback { Callable & callable; _Callback(Callable & callable) : callable(callable) { } void operator()(const std::string & message) { callable(message); } }; _Callback callback(callable); _dispatch(callback); }
void dispatch(Callable callable) // For callbacks that accept a string argument. { // N.B. this is compatible with both C++11 lambdas, functors and C function pointers struct _Callback : public Callback_Imp { Callable& callable; _Callback(Callable& callable) : callable(callable) { } void operator()(const std::string& message, WebSocket* ws) { callable(message, ws); } }; _Callback callback(callable); _dispatch(callback); }
void EndpointListener::dispatchMessage(const SIPMessage::Ptr& pRequest) { if (_dispatch) { OSS_LOG_DEBUG(pRequest->createContextId(true) << "EndpointListener::dispatchMessage( " << pRequest->startLine() << " )"); pRequest->setProperty(OSS::PropertyMap::PROP_EndpointName, _endpointName); pRequest->commitData(); _dispatch(pRequest, _pConnection); } else { OSS_LOG_ERROR(pRequest->createContextId(true) << "EndpointListener::dispatchMessage( NULL )"); } }
static void _controller_HSM() { //----- kernel level ISR handlers ----(flags are set in ISRs)-----------// DISPATCH(gpio_switch_handler()); // limit and homing switch handler DISPATCH(_abort_handler()); // abort signal DISPATCH(_feedhold_handler()); // feedhold signal DISPATCH(_cycle_start_handler()); // cycle start signal //----- planner hierarchy for gcode and cycles -------------------------// DISPATCH(rpt_status_report_callback()); // conditionally send status report DISPATCH(rpt_queue_report_callback()); // conditionally send queue report DISPATCH(mp_plan_hold_callback()); // plan a feedhold DISPATCH(mp_end_hold_callback()); // end a feedhold DISPATCH(ar_arc_callback()); // arc generation runs behind lines DISPATCH(cm_homing_callback()); // G28.1 continuation //----- command readers and parsers ------------------------------------// DISPATCH(_sync_to_tx_buffer()); // sync with TX buffer (pseudo-blocking) DISPATCH(_sync_to_planner()); // sync with planning queue DISPATCH(_dispatch()); // read and execute next command }
static void *_brain_thread(void *arg) { ng_netreg_entry_t netreg; ng_pktsnip_t *snip; msg_t msg; netreg.pid = thread_getpid(); netreg.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; ng_netreg_register(NG_NETTYPE_UNDEF, &netreg); while (1) { msg_receive(&msg); if (msg.type == NG_NETAPI_MSG_TYPE_RCV) { snip = (ng_pktsnip_t *)msg.content.ptr; _dispatch(snip->data, snip->size); ng_pktbuf_release(snip); } } /* never reached */ return NULL; }
void dispatch(WSMessageCallback messageCallback, WSErrorCallback errorCallback, void* userData) { _dispatch(messageCallback, errorCallback, userData); }
void _init( void ) { pcb_t *pcb; /* ** BOILERPLATE CODE - taken from basic framework ** ** Initialize interrupt stuff. */ __init_interrupts(); // IDT and PIC initialization // Ignore the 0x2A interrupt which happens when removing or inserting a // flash drive. __install_isr( 0x2A, _ignore_isr ); /* ** Console I/O system. */ c_io_init(); c_clearscreen(); #ifdef ISR_DEBUGGING_CODE c_setscroll( 0, 7, 99, 99 ); c_puts_at( 0, 6, "================================================================================" ); #endif /* ** 20123-SPECIFIC CODE STARTS HERE */ /* ** Initialize various OS modules ** ** Note: the clock, SIO, and syscall modules also install ** their ISRs. */ c_puts( "Module init: " ); _q_init(); // must be first _pcb_init(); _stack_init(); _sio_init(); _sys_init(); _sched_init(); _clock_init(); _pci_init(); _disk_init(); _net_init(); c_puts( "\n" ); c_puts("Launching the shell. Please be patient\n"); __delay(1000); c_clearscreen(); /* ** Create the initial system ESP ** ** This will be the address of the next-to-last ** longword in the system stack. */ _system_esp = ((uint32_t *) ( (&_system_stack) + 1)) - 2; /* ** Create the initial process ** ** Code mostly stolen from _sys_fork(); if that routine ** changes, SO MUST THIS!!! */ // allocate a PCB and stack pcb = _create_process( NULL ); if( pcb == NULL ) { _kpanic( "_init", "init() creation failed", FAILURE ); } // initialize the stack with the standard context pcb->context = _create_stack( pcb->stack ); if( pcb->context == NULL ) { _kpanic( "_init", "init() stack setup failed", FAILURE ); } // define the entry point for init() pcb->context->eip = (uint32_t) init; // set up various PCB fields pcb->pid = pcb->ppid = PID_INIT; // next PID is initially 1 pcb->prio = PRIO_HIGH; pcb->children = 1000; // remember this PCB for use in reparenting orphan processes _init_pcb = pcb; // make it the first process _schedule( pcb ); _dispatch(); /* ** Turn on the SIO receiver (the transmitter will be turned ** on/off as characters are being sent) */ _sio_enable( SIO_RX ); /* ** END OF 20123-SPECIFIC CODE ** ** Finally, report that we're all done. */ c_puts( "System initialization complete.\n" ); }
void _init( void ) { Pcb *pcb; // // BOILERPLATE CODE - taken from basic framework // // Initialize interrupt stuff. // __init_interrupts(); // IDT and PIC initialization // // I/O system. // c_io_init(); c_clearscreen(); c_setscroll( 0, 7, 99, 99 ); c_puts_at( 0, 6, "================================================================================" ); c_puts( "Init: " ); // // 20073-SPECIFIC CODE STARTS HERE // // // Initialize various OS modules // _init_queues(); // must be first _init_memory(); _init_processes(); _init_stacks(); _init_sio(); _init_clock(); _init_syscalls(); c_puts( "\n" ); // // Create the initial process // // Code mostly stolen from _sys_fork() and _sys_exec(); // if either of those routines change, SO MUST THIS!!! // // // First, get a PCB and a stack // pcb = _get_pcb(); if( pcb == 0 ) { _kpanic( "_init - can't allocate first pcb" ); } pcb->stack = _get_stack(); if( pcb->stack == 0 ) { _kpanic( "_init - can't allocate first stack" ); } // // Next, set up various PCB fields // pcb->pid = g_next_pid++; pcb->prio = PRI_NORMAL; // // Set up the initial process context. // // See _sys_exec() for an explanation of how this works. // pcb->context = _setup_stack( pcb->stack, (unsigned int) first_main ); // Initialize memory segment. Equals that of the kernel's in the GDT. pcb->seg.mem.offset = 0x0; pcb->seg.mem.length = 0xFFFFFFFF; // Initialize LDT entries for this PCB // This is a "kernel" process, so we will just copy over the // descriptors from the GDT and stick them into this process' LDT. __copy_gdt_entry( &(pcb->seg.ldt.cseg), (GDT_INDEX(GDT_CODE)) ); __copy_gdt_entry( &(pcb->seg.ldt.dseg), (GDT_INDEX(GDT_DATA)) ); // Allocate a slot in the GDT for the LDT descriptor, // and initialize this PCB's LDT register variable. pcb->seg.ldtr = SEL_SETINDEX(_gdt_alloc()) | SEL_GDT | SEL_RPL(0); // Initialize the LDT descriptor located in the GDT __gdt_set_entry( SEL_GETINDEX(pcb->seg.ldtr), (u32_t)&(pcb->seg.ldt), sizeof(ldt_t), ACC_PRES | ACC_DPL(0) | ACC_SYS | SYS_LDT ); // // Give it to the scheduler. // _schedule( pcb ); // // Do it all again for the idle process. // pcb = _get_pcb(); if( pcb == 0 ) { _kpanic( "_init - can't allocate idle pcb" ); } pcb->stack = _get_stack(); if( pcb->stack == 0 ) { _kpanic( "_init - can't allocate idle stack" ); } pcb->pid = g_next_pid++; pcb->prio = PRI_MINIMUM; pcb->context = _setup_stack( pcb->stack, (unsigned int) idle_main ); pcb->seg.mem.offset = 0x0; pcb->seg.mem.length = 0xFFFFFFFF; __copy_gdt_entry( &(pcb->seg.ldt.cseg), (GDT_INDEX(GDT_CODE)) ); __copy_gdt_entry( &(pcb->seg.ldt.dseg), (GDT_INDEX(GDT_DATA)) ); pcb->seg.ldtr = SEL_SETINDEX(_gdt_alloc()) | SEL_GDT | SEL_RPL(0); __gdt_set_entry( SEL_GETINDEX(pcb->seg.ldtr), (u32_t)&(pcb->seg.ldt), sizeof(ldt_t), ACC_PRES | ACC_DPL(0) | ACC_SYS | SYS_LDT ); _schedule( pcb ); // // Dispatch the initial current process // _dispatch(); // // END OF 20073-SPECIFIC CODE // // Finally, report that we're all done. // c_puts( "System initialization complete.\n" ); }
static void _clock_isr( int vector, int code ) { (void)(vector); (void)(code); pcb_t *pcb; // spin the pinwheel ++_pinwheel; if( _pinwheel == (CLOCK_FREQUENCY / 10) ) { _pinwheel = 0; ++_pindex; c_putchar_at( 79, 0, "|/-\\"[ _pindex & 3 ] ); } // increment the system time ++_system_time; /* ** wake up any sleeper whose time has come ** ** we give awakened processes preference over the ** current process (when it is scheduled again) */ while( !_queue_empty(_sleeping) && (uint32_t) _queue_kpeek(_sleeping) <= _system_time ) { // time to wake up! remove it from the queue pcb = (pcb_t *) _queue_remove( _sleeping ); if( pcb == NULL ) { #ifdef DEBUG _kpanic( "_clock_isr", "NULL from sleep queue remove" ); #else c_puts( "*** _clock_isr: NULL from sleep queue\n" ); break; #endif } // and schedule it for dispatch _schedule( pcb ); } // check the current process to see if it needs to be scheduled // sanity check! _current->quantum -= 1; if( _current->quantum < 1 ) { _schedule( _current ); _dispatch(); } #ifdef DUMP_QUEUES // Approximately every 10 seconds, dump the queues, and // print the contents of the SIO buffers. if( (_system_time % SECONDS_TO_TICKS(10)) == 0 ) { c_printf( "Queue contents @%08x\n", _system_time ); _queue_dump( "ready[0]", _ready[0] ); _queue_dump( "ready[1]", _ready[1] ); _queue_dump( "ready[2]", _ready[2] ); _queue_dump( "ready[3]", _ready[3] ); _queue_dump( "sleep", _sleeping ); _sio_dump(); } #endif // tell the PIC we're done __outb( PIC_MASTER_CMD_PORT, PIC_EOI ); }