📄 dv-m68hc11sio.c
字号:
{ cpu->ios[M6811_SCSR] &= ~M6811_TDRE; cpu->ios[M6811_SCSR] &= ~M6811_TC; controller->tx_has_char = 0; switch (controller->backend) { case sio_tcp: dv_sockser_write (sd, controller->tx_char); break; case sio_stdio: sim_io_write_stdout (sd, &controller->tx_char, 1); sim_io_flush_stdout (sd); break; default: break; } } if (controller->tx_poll_event) { hw_event_queue_deschedule (me, controller->tx_poll_event); controller->tx_poll_event = 0; } if ((cpu->ios[M6811_SCCR2] & M6811_TE) && ((cpu->ios[M6811_SCSR] & M6811_TC) == 0)) { unsigned long clock_cycle; /* Compute CPU clock cycles to wait for the next character. */ clock_cycle = controller->data_length * controller->baud_cycle; controller->tx_poll_event = hw_event_queue_schedule (me, clock_cycle, m68hc11sio_tx_poll, NULL); } interrupts_update_pending (&cpu->cpu_interrupts);}/* Descriptions of the SIO I/O ports. These descriptions are only used to give information of the SIO device under GDB. */io_reg_desc sccr2_desc[] = { { M6811_TIE, "TIE ", "Transmit Interrupt Enable" }, { M6811_TCIE, "TCIE ", "Transmit Complete Interrupt Enable" }, { M6811_RIE, "RIE ", "Receive Interrupt Enable" }, { M6811_ILIE, "ILIE ", "Idle Line Interrupt Enable" }, { M6811_TE, "TE ", "Transmit Enable" }, { M6811_RE, "RE ", "Receive Enable" }, { M6811_RWU, "RWU ", "Receiver Wake Up" }, { M6811_SBK, "SBRK ", "Send Break" }, { 0, 0, 0 }};io_reg_desc sccr1_desc[] = { { M6811_R8, "R8 ", "Receive Data bit 8" }, { M6811_T8, "T8 ", "Transmit Data bit 8" }, { M6811_M, "M ", "SCI Character length (0=8-bits, 1=9-bits)" }, { M6811_WAKE, "WAKE ", "Wake up method select (0=idle, 1=addr mark" }, { 0, 0, 0 }};io_reg_desc scsr_desc[] = { { M6811_TDRE, "TDRE ", "Transmit Data Register Empty" }, { M6811_TC, "TC ", "Transmit Complete" }, { M6811_RDRF, "RDRF ", "Receive Data Register Full" }, { M6811_IDLE, "IDLE ", "Idle Line Detect" }, { M6811_OR, "OR ", "Overrun Error" }, { M6811_NF, "NF ", "Noise Flag" }, { M6811_FE, "FE ", "Framing Error" }, { 0, 0, 0 }};io_reg_desc baud_desc[] = { { M6811_TCLR, "TCLR ", "Clear baud rate (test mode)" }, { M6811_SCP1, "SCP1 ", "SCI baud rate prescaler select (SCP1)" }, { M6811_SCP0, "SCP0 ", "SCI baud rate prescaler select (SCP0)" }, { M6811_RCKB, "RCKB ", "Baur Rate Clock Check (test mode)" }, { M6811_SCR2, "SCR2 ", "SCI Baud rate select (SCR2)" }, { M6811_SCR1, "SCR1 ", "SCI Baud rate select (SCR1)" }, { M6811_SCR0, "SCR0 ", "SCI Baud rate select (SCR0)" }, { 0, 0, 0 }};static voidm68hc11sio_info (struct hw *me){ SIM_DESC sd; uint16 base = 0; sim_cpu *cpu; struct m68hc11sio *controller; uint8 val; long clock_cycle; sd = hw_system (me); cpu = STATE_CPU (sd, 0); controller = hw_data (me); sim_io_printf (sd, "M68HC11 SIO:\n"); base = cpu_get_io_base (cpu); val = cpu->ios[M6811_BAUD]; print_io_byte (sd, "BAUD ", baud_desc, val, base + M6811_BAUD); sim_io_printf (sd, " (%ld baud)\n", (cpu->cpu_frequency / 4) / controller->baud_cycle); val = cpu->ios[M6811_SCCR1]; print_io_byte (sd, "SCCR1", sccr1_desc, val, base + M6811_SCCR1); sim_io_printf (sd, " (%d bits) (%dN1)\n", controller->data_length, controller->data_length - 2); val = cpu->ios[M6811_SCCR2]; print_io_byte (sd, "SCCR2", sccr2_desc, val, base + M6811_SCCR2); sim_io_printf (sd, "\n"); val = cpu->ios[M6811_SCSR]; print_io_byte (sd, "SCSR ", scsr_desc, val, base + M6811_SCSR); sim_io_printf (sd, "\n"); clock_cycle = controller->data_length * controller->baud_cycle; if (controller->tx_poll_event) { signed64 t; int n; t = hw_event_remain_time (me, controller->tx_poll_event); n = (clock_cycle - t) / controller->baud_cycle; n = controller->data_length - n; sim_io_printf (sd, " Transmit finished in %s (%d bit%s)\n", cycle_to_string (cpu, t, PRINT_TIME | PRINT_CYCLE), n, (n > 1 ? "s" : "")); } if (controller->rx_poll_event) { signed64 t; t = hw_event_remain_time (me, controller->rx_poll_event); sim_io_printf (sd, " Receive finished in %s\n", cycle_to_string (cpu, t, PRINT_TIME | PRINT_CYCLE)); } }static intm68hc11sio_ioctl (struct hw *me, hw_ioctl_request request, va_list ap){ m68hc11sio_info (me); return 0;}/* generic read/write */static unsignedm68hc11sio_io_read_buffer (struct hw *me, void *dest, int space, unsigned_word base, unsigned nr_bytes){ SIM_DESC sd; struct m68hc11sio *controller; sim_cpu *cpu; unsigned8 val; HW_TRACE ((me, "read 0x%08lx %d", (long) base, (int) nr_bytes)); sd = hw_system (me); cpu = STATE_CPU (sd, 0); controller = hw_data (me); switch (base) { case M6811_SCSR: controller->rx_clear_scsr = cpu->ios[M6811_SCSR] & (M6811_RDRF | M6811_IDLE | M6811_OR | M6811_NF | M6811_FE); case M6811_BAUD: case M6811_SCCR1: case M6811_SCCR2: val = cpu->ios[base]; break; case M6811_SCDR: if (controller->rx_clear_scsr) { cpu->ios[M6811_SCSR] &= ~controller->rx_clear_scsr; } val = controller->rx_char; break; default: return 0; } *((unsigned8*) dest) = val; return 1;}static unsignedm68hc11sio_io_write_buffer (struct hw *me, const void *source, int space, unsigned_word base, unsigned nr_bytes){ SIM_DESC sd; struct m68hc11sio *controller; sim_cpu *cpu; unsigned8 val; HW_TRACE ((me, "write 0x%08lx %d", (long) base, (int) nr_bytes)); sd = hw_system (me); cpu = STATE_CPU (sd, 0); controller = hw_data (me); val = *((const unsigned8*) source); switch (base) { case M6811_BAUD: { long divisor; long baud; cpu->ios[M6811_BAUD] = val; switch (val & (M6811_SCP1|M6811_SCP0)) { case M6811_BAUD_DIV_1: divisor = 1 * 16; break; case M6811_BAUD_DIV_3: divisor = 3 * 16; break; case M6811_BAUD_DIV_4: divisor = 4 * 16; break; default: case M6811_BAUD_DIV_13: divisor = 13 * 16; break; } val &= (M6811_SCR2|M6811_SCR1|M6811_SCR0); divisor *= (1 << val); baud = (cpu->cpu_frequency / 4) / divisor; HW_TRACE ((me, "divide rate %ld, baud rate %ld", divisor, baud)); controller->baud_cycle = divisor; } break; case M6811_SCCR1: { if (val & M6811_M) controller->data_length = 11; else controller->data_length = 10; cpu->ios[M6811_SCCR1] = val; } break; case M6811_SCCR2: if ((val & M6811_RE) == 0) { val &= ~(M6811_RDRF|M6811_IDLE|M6811_OR|M6811_NF|M6811_NF); val |= (cpu->ios[M6811_SCCR2] & (M6811_RDRF|M6811_IDLE|M6811_OR|M6811_NF|M6811_NF)); cpu->ios[M6811_SCCR2] = val; break; } /* Activate reception. */ if (controller->rx_poll_event == 0) { long clock_cycle; /* Compute CPU clock cycles to wait for the next character. */ clock_cycle = controller->data_length * controller->baud_cycle; controller->rx_poll_event = hw_event_queue_schedule (me, clock_cycle, m68hc11sio_rx_poll, NULL); } cpu->ios[M6811_SCCR2] = val; interrupts_update_pending (&cpu->cpu_interrupts); break; /* No effect. */ case M6811_SCSR: return 1; case M6811_SCDR: if (!(cpu->ios[M6811_SCSR] & M6811_TDRE)) { return 0; } controller->tx_char = val; controller->tx_has_char = 1; if ((cpu->ios[M6811_SCCR2] & M6811_TE) && controller->tx_poll_event == 0) { m68hc11sio_tx_poll (me, NULL); } return 1; default: return 0; } return nr_bytes;} const struct hw_descriptor dv_m68hc11sio_descriptor[] = { { "m68hc11sio", m68hc11sio_finish }, { "m68hc12sio", m68hc11sio_finish }, { NULL },};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -