// print out the queue void print_queue(queue * q) { if (is_empty_q(q)) { printf("Queue empty"); } queue_node *n = q->front; while (n != NULL) { fprintf(stdout, "%d", n->w_id); n = n->next; } fprintf(stdout, "\n"); }
int transmit_m(void * data, size_t size) { push_m(transmit_fifo, data, size); while(!is_empty_q(transmit_fifo) && transmitter_is_ready(transmit_port)){ if(sys_outb(transmit_port+TRANSMITTER_HOLDING_REG, front(transmit_fifo)) != OK) { printf("Error writing TRANSMITTER_HOLDING_REG\n"); return 1; } pop(transmit_fifo); } return 0; }
int transmit_b(unsigned char byte) { push(transmit_fifo, byte); while(!is_empty_q(transmit_fifo) && transmitter_is_ready(transmit_port)){ if(sys_outb(transmit_port+TRANSMITTER_HOLDING_REG, front(transmit_fifo)) != OK) { printf("Error writing TRANSMITTER_HOLDING_REG\n"); return 1; } pop(transmit_fifo); } return 0; }
// check for number of workers int workers_available(queue * q) { int available = 0; if (is_empty_q(q)) { return available; } queue_node *n = q->front; while (n != NULL) { available++; n = n->next; } return available; }
int receive_b(unsigned char* received) { while(receiver_is_ready(receiver_port)) { if(sys_inb(receiver_port+RECEIVER_BUF_REG, &received_char) != OK) { printf("Error reading RECEIVER_BUF_REG\n"); return 1; } push(receive_fifo, received_char); } if(is_empty_q(receive_fifo)) return 1; *received = front(receive_fifo); pop(receive_fifo); return 0; }
int ser_ih(unsigned long ser_port) { unsigned long iir; if(sys_inb(ser_port + INT_ID_REG, &iir)) { printf("ser_ih() failed\n"); return 1; } if((iir & INT_STATUS) == 0) { switch(iir & INT_ORIGIN) { case RECEIVED_DATA_AVAILABLE_INT: while(receiver_is_ready(ser_port)) { if(sys_inb(ser_port+RECEIVER_BUF_REG, &received_char) != OK) { printf("Error reading RECEIVER_BUF_REG\n"); return 1; } push(receive_fifo, received_char); } break; case TRANSMITTER_EMPTY_INT: while(!is_empty_q(transmit_fifo) && transmitter_is_ready(ser_port)){ if(sys_outb(ser_port+TRANSMITTER_HOLDING_REG, front(transmit_fifo)) != OK) { printf("Error writing TRANSMITTER_HOLDING_REG\n"); return 1; } pop(transmit_fifo); } break; case CHAR_TIMEOUT_INT: return 1; break; case LINE_STATUS_INT: return 1; break; } } return 0; }
int transmit_protocol(void* data, signal_type_t signal_type, size_t size) { transmit_b((unsigned char) signal_type); switch(signal_type) { case TYPE_INT: transmit_m(data, sizeof(int)); break; case TYPE_SHORT: transmit_m(data, sizeof(short)); break; case TYPE_CHAR: transmit_b(*(unsigned char*)data); break; case TYPE_STRING: transmit_m(&size, sizeof(size_t)); transmit_m(data, size); break; case TYPE_MESSAGE: transmit_b(*(unsigned char*)data); break; case TYPE_FLOAT: transmit_m(data, sizeof(float)); break; case TYPE_DOUBLE: transmit_m(data, sizeof(double)); break; } while(!is_empty_q(transmit_fifo) && transmitter_is_ready(transmit_port)){ if(sys_outb(transmit_port+TRANSMITTER_HOLDING_REG, front(transmit_fifo)) != OK) { printf("Error writing TRANSMITTER_HOLDING_REG\n"); return 1; } pop(transmit_fifo); } return 0; }