src/mess/drivers/gp32.c
| r6552 | r6553 | |
| 94 | 94 | break; |
| 95 | 95 | default : |
| 96 | 96 | { |
| 97 | | printf( "bppmode %d not supported\n", bppmode); |
| 97 | logerror( "bppmode %d not supported\n", bppmode); |
| 98 | 98 | } |
| 99 | 99 | break; |
| 100 | 100 | } |
| r6552 | r6553 | |
| 214 | 214 | static WRITE32_HANDLER( s3c240x_irq_w ) |
| 215 | 215 | { |
| 216 | 216 | // logerror( "(IRQ) %08X <- %08X\n", 0x14400000 + (offset << 2), data); |
| 217 | switch (offset) |
| 218 | { |
| 219 | // SRCPND |
| 220 | case 0x00 / 4 : |
| 221 | { |
| 222 | cpu_set_input_line( cputag_get_cpu( space->machine, "maincpu"), ARM7_IRQ_LINE, CLEAR_LINE); |
| 223 | } |
| 224 | break; |
| 225 | } |
| 217 | 226 | COMBINE_DATA(&s3c240x_irq_regs[offset]); |
| 218 | 227 | } |
| 219 | 228 | |
| 220 | 229 | static void s3c240x_request_irq( running_machine *machine, UINT32 int_type) |
| 221 | 230 | { |
| 222 | 231 | // logerror( "request irq %d\n", int_type); |
| 232 | // logerror( "%08X %08X %08X %08X %08X %08X\n", s3c240x_irq_regs[0], s3c240x_irq_regs[1], s3c240x_irq_regs[2], s3c240x_irq_regs[3], s3c240x_irq_regs[4], s3c240x_irq_regs[5]); |
| 223 | 233 | s3c240x_irq_regs[5] = int_type; // INTOFFSET |
| 224 | 234 | cpu_set_input_line( cputag_get_cpu( machine, "maincpu"), ARM7_IRQ_LINE, ASSERT_LINE); |
| 225 | | cpu_set_input_line( cputag_get_cpu( machine, "maincpu"), ARM7_IRQ_LINE, CLEAR_LINE); |
| 235 | // cpu_set_input_line( cputag_get_cpu( machine, "maincpu"), ARM7_IRQ_LINE, CLEAR_LINE); |
| 226 | 236 | } |
| 227 | 237 | |
| 228 | 238 | // PWM TIMER |
| r6552 | r6553 | |
| 270 | 280 | { |
| 271 | 281 | UINT32 prescaler, mux, cnt, cmp; |
| 272 | 282 | double freq, hz; |
| 273 | | logerror( "starting timer %d\n", timer); |
| 283 | // logerror( "starting timer %d\n", timer); |
| 274 | 284 | prescaler = (s3c240x_timer_regs[0] >> prescaler_shift[timer]) & 0xFF; |
| 275 | 285 | mux = (s3c240x_timer_regs[1] >> mux_shift[timer]) & 0x0F; |
| 276 | 286 | freq = s3c240x_get_pclk( MPLLCON) / (prescaler + 1) / mux_table[mux]; |
| r6552 | r6553 | |
| 293 | 303 | } |
| 294 | 304 | else // stopping is easy |
| 295 | 305 | { |
| 296 | | logerror( "stopping timer %d\n", timer); |
| 306 | // logerror( "stopping timer %d\n", timer); |
| 297 | 307 | timer_adjust_oneshot( s3c240x_timers[timer], attotime_never, 0); |
| 298 | 308 | } |
| 299 | 309 | } |
| r6552 | r6553 | |
| 703 | 713 | |
| 704 | 714 | // IIC |
| 705 | 715 | |
| 716 | static emu_timer *s3c240x_iic_timer; |
| 706 | 717 | static UINT32 s3c240x_iic_regs[0x10/4]; |
| 707 | 718 | |
| 719 | static UINT8 iic_read( running_machine *machine, int last) |
| 720 | { |
| 721 | UINT8 data = 0; |
| 722 | /* |
| 723 | int i; |
| 724 | i2cmem_write( machine, 0, I2CMEM_SDA, 1); |
| 725 | for (i=0;i<8;i++) |
| 726 | { |
| 727 | i2cmem_write( machine, 0, I2CMEM_SCL, 1); |
| 728 | data = (data << 1) + (i2cmem_read( machine, 0, I2CMEM_SDA) ? 1 : 0); |
| 729 | i2cmem_write( machine, 0, I2CMEM_SCL, 0); |
| 730 | } |
| 731 | i2cmem_write( machine, 0, I2CMEM_SDA, last); |
| 732 | i2cmem_write( machine, 0, I2CMEM_SCL, 1); |
| 733 | i2cmem_write( machine, 0, I2CMEM_SCL, 0); |
| 734 | */ |
| 735 | return data; |
| 736 | } |
| 737 | |
| 738 | static void iic_write( running_machine *machine, UINT8 data) |
| 739 | { |
| 740 | /* |
| 741 | int i; |
| 742 | for (i=0;i<8;i++) |
| 743 | { |
| 744 | i2cmem_write( machine, 0, I2CMEM_SDA, (data & 0x80) ? 1 : 0); |
| 745 | data = data << 1; |
| 746 | i2cmem_write( machine, 0, I2CMEM_SCL, 1); |
| 747 | i2cmem_write( machine, 0, I2CMEM_SCL, 0); |
| 748 | } |
| 749 | i2cmem_write( machine, 0, I2CMEM_SDA, 1); |
| 750 | i2cmem_write( machine, 0, I2CMEM_SCL, 1); |
| 751 | i2cmem_write( machine, 0, I2CMEM_SCL, 0); |
| 752 | */ |
| 753 | } |
| 754 | |
| 755 | static void iic_start( running_machine *machine) |
| 756 | { |
| 757 | /* |
| 758 | i2cmem_write( machine, 0, I2CMEM_SDA, 1); |
| 759 | i2cmem_write( machine, 0, I2CMEM_SCL, 1); |
| 760 | i2cmem_write( machine, 0, I2CMEM_SDA, 0); |
| 761 | i2cmem_write( machine, 0, I2CMEM_SCL, 0); |
| 762 | */ |
| 763 | } |
| 764 | |
| 765 | static void iic_stop( running_machine *machine) |
| 766 | { |
| 767 | /* |
| 768 | i2cmem_write( machine, 0, I2CMEM_SDA, 0); |
| 769 | i2cmem_write( machine, 0, I2CMEM_SCL, 1); |
| 770 | i2cmem_write( machine, 0, I2CMEM_SDA, 1); |
| 771 | i2cmem_write( machine, 0, I2CMEM_SCL, 0); |
| 772 | */ |
| 773 | } |
| 774 | |
| 708 | 775 | static READ32_HANDLER( s3c240x_iic_r ) |
| 709 | 776 | { |
| 710 | | return s3c240x_iic_regs[offset]; |
| 777 | UINT32 data = s3c240x_iic_regs[offset]; |
| 778 | switch (offset) |
| 779 | { |
| 780 | // IICSTAT |
| 781 | case 0x04 / 4 : |
| 782 | { |
| 783 | data = data & ~0x0000000F; |
| 784 | } |
| 785 | break; |
| 786 | } |
| 787 | // logerror( "(IIC) %08X -> %08X\n", 0x15400000 + (offset << 2), data); |
| 788 | return data; |
| 711 | 789 | } |
| 712 | 790 | |
| 713 | 791 | static WRITE32_HANDLER( s3c240x_iic_w ) |
| 714 | 792 | { |
| 715 | 793 | // logerror( "(IIC) %08X <- %08X\n", 0x15400000 + (offset << 2), data); |
| 716 | 794 | COMBINE_DATA(&s3c240x_iic_regs[offset]); |
| 795 | switch (offset) |
| 796 | { |
| 797 | // ADDR_IICCON |
| 798 | case 0x00 / 4 : |
| 799 | { |
| 800 | int interrupt_pending_flag; |
| 801 | // const int div_table[] = { 16, 512}; |
| 802 | // int enable_interrupt, transmit_clock_value, tx_clock_source_selection |
| 803 | // double clock; |
| 804 | // transmit_clock_value = (data >> 0) & 0xF; |
| 805 | // tx_clock_source_selection = (data >> 6) & 1; |
| 806 | // enable_interrupt = (data >> 5) & 1; |
| 807 | // clock = (double)(s3c240x_get_pclk( MPLLCON) / div_table[tx_clock_source_selection] / (transmit_clock_value + 1)); |
| 808 | interrupt_pending_flag = (data >> 4) & 1; |
| 809 | if (interrupt_pending_flag == 0) |
| 810 | { |
| 811 | int start_stop_condition; |
| 812 | start_stop_condition = (s3c240x_iic_regs[1] >> 5) & 1; |
| 813 | if (start_stop_condition != 0) |
| 814 | { |
| 815 | // logerror( "IIC resume\n"); |
| 816 | timer_adjust_oneshot( s3c240x_iic_timer, ATTOTIME_IN_MSEC( 10), 0); |
| 817 | } |
| 818 | } |
| 819 | } |
| 820 | break; |
| 821 | // IICSTAT |
| 822 | case 0x04 / 4 : |
| 823 | { |
| 824 | int start_stop_condition, mode_selection; |
| 825 | mode_selection = (data >> 6) & 3; |
| 826 | start_stop_condition = (data >> 5) & 1; |
| 827 | if (start_stop_condition != 0) |
| 828 | { |
| 829 | // logerror( "IIC start (mode %d)\n", mode_selection); |
| 830 | iic_start( space->machine); |
| 831 | timer_adjust_oneshot( s3c240x_iic_timer, ATTOTIME_IN_MSEC( 10), 0); |
| 832 | } |
| 833 | else |
| 834 | { |
| 835 | // logerror( "IIC stop\n"); |
| 836 | iic_stop( space->machine); |
| 837 | timer_adjust_oneshot( s3c240x_iic_timer, attotime_never, 0); |
| 838 | } |
| 839 | } |
| 840 | break; |
| 841 | } |
| 717 | 842 | } |
| 718 | 843 | |
| 844 | static TIMER_CALLBACK( s3c240x_iic_timer_exp ) |
| 845 | { |
| 846 | int enable_interrupt, mode_selection; |
| 847 | // logerror( "s3c240x_iic_timer_exp\n"); |
| 848 | mode_selection = (s3c240x_iic_regs[1] >> 6) & 3; |
| 849 | switch (mode_selection) |
| 850 | { |
| 851 | // master receive mode |
| 852 | case 2 : |
| 853 | { |
| 854 | UINT8 data_shift = iic_read( machine, 0); |
| 855 | // logerror( "IIC READ %02X\n", data_shift); |
| 856 | s3c240x_iic_regs[3] = (s3c240x_iic_regs[3] & ~0xFF) | data_shift; |
| 857 | } |
| 858 | break; |
| 859 | // master transmit mode |
| 860 | case 3 : |
| 861 | { |
| 862 | UINT8 data_shift = s3c240x_iic_regs[3] & 0xFF; |
| 863 | // logerror( "IIC WRITE %02X\n", data_shift); |
| 864 | iic_write( machine, data_shift); |
| 865 | } |
| 866 | break; |
| 867 | } |
| 868 | enable_interrupt = (s3c240x_iic_regs[0] >> 5) & 1; |
| 869 | if (enable_interrupt) |
| 870 | { |
| 871 | // logerror( "IIC request irq\n"); |
| 872 | s3c240x_request_irq( machine, INT_IIC); |
| 873 | } |
| 874 | } |
| 875 | |
| 719 | 876 | // IIS |
| 720 | 877 | |
| 721 | 878 | static UINT32 s3c240x_iis_regs[0x14/4]; |
| r6552 | r6553 | |
| 801 | 958 | s3c240x_timers[2] = timer_alloc(machine, s3c240x_timer_exp, (void *)(FPTR)2); |
| 802 | 959 | s3c240x_timers[3] = timer_alloc(machine, s3c240x_timer_exp, (void *)(FPTR)3); |
| 803 | 960 | s3c240x_timers[4] = timer_alloc(machine, s3c240x_timer_exp, (void *)(FPTR)4); |
| 961 | s3c240x_iic_timer = timer_alloc(machine, s3c240x_iic_timer_exp, (void *)(FPTR)0); |
| 804 | 962 | smc_reset(); |
| 805 | 963 | } |
| 806 | 964 | |