filename | src/sh4/scif.c |
changeset | 1077:136fc24d17ef |
prev | 975:007bf7eb944f |
next | 1078:d8f1cf224e7e |
author | nkeynes |
date | Wed Oct 07 17:53:56 2009 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Create a host attachment for the SCIF serial port. By default, uses /dev/console Add general fd listening to netutil, and rename to ioutil Add SCIF update on port read/write - fixes KOS timing problems but needs to be redone properly. |
file | annotate | diff | log | raw |
1.1 --- a/src/sh4/scif.c Mon Jan 26 07:26:24 2009 +00001.2 +++ b/src/sh4/scif.c Wed Oct 07 17:53:56 2009 +10001.3 @@ -28,7 +28,7 @@1.4 #include "serial.h"1.6 void SCIF_set_break(void);1.7 -1.8 +void SCIF_run_to(uint32_t nanosecs);1.9 /************************* External serial interface ************************/1.11 /**1.12 @@ -55,17 +55,41 @@1.13 serial_data_block_t serial_recvq_head = NULL, serial_recvq_tail = NULL;1.14 serial_device_t serial_device = NULL;1.16 -void serial_attach_device( serial_device_t dev )1.17 +serial_device_t serial_get_device( )1.18 {1.19 + return serial_device;1.20 +}1.21 +1.22 +serial_device_t serial_attach_device( serial_device_t dev )1.23 +{1.24 + serial_device_t olddev = serial_device;1.25 if( serial_device != NULL )1.26 serial_detach_device();1.27 serial_device = dev;1.28 + if( serial_device != NULL && serial_device->attach != NULL )1.29 + serial_device->attach(serial_device);1.30 + return olddev;1.31 }1.34 -void serial_detach_device( void )1.35 +serial_device_t serial_detach_device( void )1.36 {1.37 + serial_device_t dev = serial_device;1.38 + if( serial_device != NULL && serial_device->detach != NULL ) {1.39 + serial_device->detach(serial_device);1.40 + }1.41 serial_device = NULL;1.42 + return dev;1.43 +}1.44 +1.45 +void serial_destroy_device( serial_device_t dev )1.46 +{1.47 + if( dev != NULL ) {1.48 + if( serial_device == dev )1.49 + serial_detach_device();1.50 + if( dev->destroy )1.51 + dev->destroy(dev);1.52 + }1.53 }1.55 /**1.56 @@ -174,6 +198,7 @@1.58 uint32_t SCIF_tick_period = 0;1.59 uint32_t SCIF_tick_remainder = 0;1.60 +uint32_t SCIF_slice_cycle = 0;1.62 void SCIF_save_state( FILE *f )1.63 {1.64 @@ -445,7 +470,7 @@1.65 int baudrate = sh4_peripheral_freq / (32 * mult * (bbr+1) );1.67 if( serial_device != NULL && serial_device->set_line_speed != NULL )1.68 - serial_device->set_line_speed( baudrate );1.69 + serial_device->set_line_speed( serial_device, baudrate );1.71 SCIF_tick_period = sh4_peripheral_period * (32 * mult * (bbr+1));1.73 @@ -457,6 +482,7 @@1.75 MMIO_REGION_READ_FN( SCIF, reg )1.76 {1.77 + SCIF_run_to(sh4r.slice_cycle);1.78 reg &= 0xFFF;1.79 switch( reg ) {1.80 case SCFRDR2: /* Receive data */1.81 @@ -470,6 +496,7 @@1.83 MMIO_REGION_WRITE_FN( SCIF, reg, val )1.84 {1.85 + SCIF_run_to(sh4r.slice_cycle);1.86 uint32_t tmp;1.87 reg &= 0xFFF;1.88 switch( reg ) {1.89 @@ -482,7 +509,7 @@1.90 */1.91 val &= 0x007B;1.92 if( serial_device != NULL ) {1.93 - serial_device->set_line_params( val );1.94 + serial_device->set_line_params( serial_device, val );1.95 }1.96 tmp = MMIO_READ( SCIF, SCSMR2 );1.97 if( (tmp & 0x03) != (val & 0x03) ) {1.98 @@ -597,7 +624,7 @@1.99 int val = SCIF_sendq_dequeue();1.100 if( val != -1 && serial_device != NULL &&1.101 serial_device->receive_data != NULL ) {1.102 - serial_device->receive_data( val );1.103 + serial_device->receive_data( serial_device, val );1.104 }1.105 }1.107 @@ -632,11 +659,17 @@1.108 SCIF_update_line_speed();1.109 }1.111 -void SCIF_run_slice( uint32_t nanosecs )1.112 +void SCIF_run_to( uint32_t nanosecs )1.113 {1.114 - SCIF_tick_remainder += nanosecs;1.115 + SCIF_tick_remainder += nanosecs - SCIF_slice_cycle;1.116 while( SCIF_tick_remainder >= SCIF_tick_period ) {1.117 SCIF_tick_remainder -= SCIF_tick_period;1.118 SCIF_clock_tick();1.119 }1.120 }1.121 +1.122 +void SCIF_run_slice( uint32_t nanosecs )1.123 +{1.124 + SCIF_run_to(nanosecs);1.125 + SCIF_slice_cycle = 0;1.126 +}
.