void context_switch(){ pcb * transition; pcb * temp; atomic_up(); transition = running; transition->frame_ptr = old_fp; if(transition->next_process != NULL){ ready_queue[prio] = ready_queue[prio]->next_process; temp = ready_queue[prio]; while(temp->next_process != NULL){ temp = temp->next_process; } temp->next_process = transition; transition->next_process = NULL; } transition->process_state = READY_STATE; clear_priority(); while(1){ if(ready_queue[prio] != NULL){ if(ready_queue[prio]->process_state == READY_STATE){ running = ready_queue[prio]; running->process_state = RUNNING_STATE; old_fp = running->frame_ptr; atomic_down(); return; } else if(ready_queue[prio]->process_state == NEW_STATE){ running = ready_queue[prio]; running->process_state = RUNNING_STATE; atomic_down(); temp_sp = running->stack_ptr; asm("move.l temp_sp, %d0"); asm("move.l %d0, %a7"); process_bootstrap(running); return; } break; } else { prio = (prio + 1) % 4; } } return; }
/* * Initialize all interrupts associated with UART */ void uart_init() { #ifdef _IO_DEBUG rtx_dbug_outs((CHAR *) "Enter: uart_init\r\n"); #endif UINT32 mask; // Disable all interupts atomic_up(); // Store the serial ISR at user vector #64 asm( "move.l #asm_serial_entry,%d0" ); asm( "move.l %d0,0x10000100" ); SERIAL1_UCR = 0x10; // Reset the entire UART SERIAL1_UCR = 0x20; // Reset the receiver SERIAL1_UCR = 0x30; // Reset the transmitter SERIAL1_UCR = 0x40; // Reset the error condition SERIAL1_ICR = 0x17; // Install the interupt SERIAL1_IVR = 64; // Install the interupt SERIAL1_IMR = 0x02; // enable interrupts on rx only SERIAL1_UBG1 = 0x00;// Set the baud rate #ifdef _CFSERVER_ // add -D_CFSERVER_ for cf-server build SERIAL1_UBG2 = 0x49; // cf-server baud rate 19200 #else SERIAL1_UBG2 = 0x92; // lab board baud rate 9600 #endif SERIAL1_UCSR = 0xDD;// Set clock mode SERIAL1_UMR = 0x13; // Setup the UART (no parity, 8 bits ) SERIAL1_UMR = 0x07; // Setup the rest of the UART (noecho, 1 stop bit) SERIAL1_UCR = 0x05; // Setup for transmit and receive // Enable interupts mask = SIM_IMR; mask &= 0x0003ddff; SIM_IMR = mask; // Enable all interupts atomic_down(); char_in = '!'; char_out = '\0'; }
VOID c_serial_handler( VOID ) { atomic_up(); CharIn = '\0'; BYTE interrupt_status; interrupt_status = SERIAL1_USR; SERIAL1_IMR = 3; if( interrupt_status & 1 ) { CharIn = SERIAL1_RD; CharOut = CharIn; } while (!(interrupt_status & 4)) { interrupt_status = SERIAL1_USR; } SERIAL1_IMR = 2; if ( interrupt_status & 4 ) { switch(CharIn){ case '\r': uprintf(crlfgt); if(command_flag == 1){ store_message((CHAR)'\0'); void * p = request_memory_block(); send_message(KCD_PID,write_message(p, kcd_msg)); command_flag = 0; clear_message(); } break; case '%': SERIAL1_WD = '%'; command_flag = 1; break; case '!': SERIAL1_WD = CharOut; display_queue_all(); sleep(6); break; case '@': SERIAL1_WD = CharOut; task_manager(); sleep(6); break; case '#': display_mailbox(); sleep(6); break; default: if(command_flag == 1){ store_message((CHAR)CharOut); } SERIAL1_WD = CharOut; break; } } atomic_down(); return; }
/* * This function is called by the assembly STUB function */ void uart_handler() { // Disable all interupts atomic_up(); #ifdef _IO_DEBUG rtx_dbug_outs((CHAR *) "Enter: uart_handler\r\n"); rtx_dbug_outs((CHAR *) "Reading data...\r\n"); #endif // irene said this should be enough - would be // very rare if it wasn't ready to read while (!(SERIAL1_UCSR & 1)) { } char_in = SERIAL1_RD; #ifdef _IO_DEBUG rtx_dbug_outs((CHAR *) "Determining what to do with char...\r\n"); #endif struct io_message * msg; switch(char_in) { #ifdef _HOTKEYS_DEBUG case '!': rtx_dbug_outs((CHAR *) "'!' hotkey detected...\r\n"); print_queues(); // print processes on ready queue and priorities break; case '@': rtx_dbug_outs((CHAR *) "'@' hotkey detected...\r\n"); print_mem_blocked(); // print processes on memory blocked queue and priorities break; case '#': rtx_dbug_outs((CHAR *) "'#' hotkey detected...\r\n"); print_msg_blocked(); // print processes on message blocked queue and priorities break; case '$': rtx_dbug_outs((CHAR *) "'$' hotkey detected...\r\n"); print_availible_mem_queue(); // print available memory queue break; case '^': rtx_dbug_outs((CHAR *) "'^' hotkey detected...\r\n"); print_used_mem_queue(); // print used memory queue break; case '&': rtx_dbug_outs((CHAR *) "'&' hotkey detected...\r\n"); output_kcd_buffer(); // print kcd buffer break; case '*': rtx_dbug_outs((CHAR *) "'*' hotkey detected...\r\n"); print_cmds(); // print valid commands break; #endif default: #ifdef _IO_DEBUG rtx_dbug_outs((CHAR *) "Sending message to KCD proc...\r\n"); #endif if (!are_blocks_available()) { atomic_down(); return; } msg = (io_message *)request_memory_block(); // reset tx/rx and send it to kcd msg->tx = UART_PID; msg->rx = KCD_PID; msg->msg[0] = char_in; send_message(KCD_PID, msg); break; } // Enable all interupts atomic_down(); }