src/mess/machine/68901mfp.c
| r1174 | r1175 | |
| 4 | 4 | |
| 5 | 5 | - daisy chaining |
| 6 | 6 | - correct irq_timer period |
| 7 | - disable GPIO3/4 interrupts when timer A/B in event count or pulse mode |
| 8 | - spurious interrupt |
| 9 | |
| 10 | If you look at the MFP datasheet it is obvious that it can generate the conditions for a spurious interrupt. |
| 11 | However the fact that they indeed happen in the ST is quite interesting. |
| 12 | |
| 13 | The MFP will generate a spurious interrupt if interrupts are disabled (by changing the IERA/IERB registers) |
| 14 | at the “precise point”. The precise point would be after the system (but not necessarily the CPU, see below) |
| 15 | triggered an MFP interrupt, and before the CPU drives the interrupt acknowledge cycle. |
| 16 | |
| 17 | If the MFP was connected directly to the CPU, spurious interrupts probably couldn’t happen. However in the |
| 18 | ST, GLUE seats in the middle and handles all the interrupt timing. It is possible that GLUE introduces a |
| 19 | delay between detecting a change in the MFP interrupt request signal and actually propagating the change to |
| 20 | the CPU IPL signals (it is even possible that GLUE make some kind of latching). This would create a window |
| 21 | long enough for the “precise point” described above. |
| 22 | |
| 23 | "yes, the spurious interrupt occurs when i mask a timer. i did not notice an occurance of the SPI when changing data and control registers. |
| 24 | if i kill interrupts with the status reg before masking the timer interrupt, then the SPI occurs as soon as the status register is set to re-enable interrupts." |
| 7 | 25 | |
| 8 | 26 | - divide serial clock by 16 |
| 9 | 27 | - synchronous mode |
| r1174 | r1175 | |
| 49 | 67 | |
| 50 | 68 | static mfp_68901 mfp[MAX_MFP]; |
| 51 | 69 | |
| 52 | | static const int GPIO_MASK[] = |
| 70 | static const int MFP68901_INT_MASK_GPIO[] = |
| 53 | 71 | { |
| 54 | 72 | MFP68901_IR_GPIP_0, MFP68901_IR_GPIP_1, MFP68901_IR_GPIP_2, MFP68901_IR_GPIP_3, |
| 55 | 73 | MFP68901_IR_GPIP_4, MFP68901_IR_GPIP_5, MFP68901_IR_GPIP_6, MFP68901_IR_GPIP_7 |
| 56 | 74 | }; |
| 57 | 75 | |
| 76 | static const int MFP68901_INT_MASK_TIMER[] = |
| 77 | { |
| 78 | MFP68901_IR_TIMER_A, MFP68901_IR_TIMER_B, MFP68901_IR_TIMER_C, MFP68901_IR_TIMER_D |
| 79 | }; |
| 80 | |
| 81 | static const int MFP68901_LOOPBACK_TIMER[] = |
| 82 | { |
| 83 | MFP68901_TAO_LOOPBACK, MFP68901_TBO_LOOPBACK, MFP68901_TCO_LOOPBACK, MFP68901_TDO_LOOPBACK |
| 84 | }; |
| 85 | |
| 86 | static const int MFP68901_GPIO_TIMER[] = |
| 87 | { |
| 88 | MFP68901_GPIP_4, MFP68901_GPIP_3 |
| 89 | }; |
| 90 | |
| 58 | 91 | static const int PRESCALER[] = { 0, 4, 10, 16, 50, 64, 100, 200 }; |
| 59 | 92 | |
| 60 | 93 | static void mfp68901_poll_gpio(int which) |
| r1174 | r1175 | |
| 78 | 111 | { |
| 79 | 112 | logerror("MFP68901 #%u Edge Transition Detected on GPIO%u\n", which, bit); |
| 80 | 113 | |
| 81 | | if (mfp_p->ier & GPIO_MASK[bit]) // AND interrupt enabled bit is set... |
| 114 | if (mfp_p->ier & MFP68901_INT_MASK_GPIO[bit]) // AND interrupt enabled bit is set... |
| 82 | 115 | { |
| 83 | 116 | logerror("MFP68901 #%u Interrupt Pending for GPIO%u\n", which, bit); |
| 84 | 117 | |
| 85 | | mfp_p->ipr |= GPIO_MASK[bit]; // set interrupt pending bit |
| 118 | mfp_p->ipr |= MFP68901_INT_MASK_GPIO[bit]; // set interrupt pending bit |
| 86 | 119 | } |
| 87 | 120 | } |
| 88 | 121 | } |
| r1174 | r1175 | |
| 542 | 575 | case MFP68901_REGISTER_AER: |
| 543 | 576 | logerror("MFP68901 #%u Active Edge Register : %x\n", which, data); |
| 544 | 577 | mfp_p->aer = data; |
| 545 | | // check transition and trigger interrupt if necessary |
| 546 | 578 | break; |
| 547 | 579 | |
| 548 | 580 | case MFP68901_REGISTER_DDR: |
| r1174 | r1175 | |
| 599 | 631 | |
| 600 | 632 | mfp_p->vr = data & 0xf8; |
| 601 | 633 | |
| 602 | | if ((mfp_p->vr & MFP68901_VR_S) == 0) |
| 634 | if (mfp_p->vr & MFP68901_VR_S) |
| 603 | 635 | { |
| 636 | logerror("MFP68901 #%u Software End-Of-Interrupt Mode\n", which); |
| 637 | } |
| 638 | else |
| 639 | { |
| 604 | 640 | logerror("MFP68901 #%u Automatic End-Of-Interrupt Mode\n", which); |
| 605 | 641 | |
| 606 | 642 | mfp_p->isr = 0; |
| 607 | 643 | } |
| 608 | | else |
| 609 | | { |
| 610 | | logerror("MFP68901 #%u Software End-Of-Interrupt Mode\n", which); |
| 611 | | } |
| 612 | 644 | break; |
| 613 | 645 | |
| 614 | 646 | case MFP68901_REGISTER_TACR: |
| r1174 | r1175 | |
| 633 | 665 | logerror("MFP68901 #%u Timer A Delay Mode : %u Prescale\n", which, divisor); |
| 634 | 666 | mame_timer_adjust(mfp_p->timer[MFP68901_TIMER_A], MAME_TIME_IN_HZ(mfp_p->intf->timer_clock / divisor), which, MAME_TIME_IN_HZ(mfp_p->intf->timer_clock / divisor)); |
| 635 | 667 | } |
| 668 | break; |
| 636 | 669 | |
| 637 | 670 | case MFP68901_TCR_TIMER_EVENT: |
| 638 | 671 | logerror("MFP68901 #%u Timer A Event Count Mode\n", which); |
| r1174 | r1175 | |
| 961 | 994 | } |
| 962 | 995 | } |
| 963 | 996 | |
| 964 | | void mfp68901_timer_count_a(int which) |
| 997 | void mfp68901_timer_count(int which, int index) |
| 965 | 998 | { |
| 966 | 999 | mfp_68901 *mfp_p = &mfp[which]; |
| 967 | 1000 | |
| 968 | | if (mfp_p->tmc[MFP68901_TIMER_A] == 0x01) |
| 1001 | if (mfp_p->tmc[index] == 0x01) |
| 969 | 1002 | { |
| 970 | | mfp_p->to[MFP68901_TIMER_A] = mfp_p->to[MFP68901_TIMER_A] ? 0 : 1; |
| 1003 | mfp_p->to[index] = mfp_p->to[index] ? 0 : 1; |
| 971 | 1004 | |
| 972 | | if (mfp_p->to[MFP68901_TIMER_A]) |
| 1005 | if (mfp_p->to[index]) |
| 973 | 1006 | { |
| 974 | | if (mfp_p->intf->rx_clock == MFP68901_TAO_LOOPBACK) |
| 1007 | if (mfp_p->intf->rx_clock == MFP68901_LOOPBACK_TIMER[index]) |
| 975 | 1008 | { |
| 976 | 1009 | mame_timer_adjust(mfp_p->rx_timer, time_zero, which, time_never); |
| 977 | 1010 | } |
| 978 | 1011 | |
| 979 | | if (mfp_p->intf->tx_clock == MFP68901_TAO_LOOPBACK) |
| 1012 | if (mfp_p->intf->tx_clock == MFP68901_LOOPBACK_TIMER[index]) |
| 980 | 1013 | { |
| 981 | 1014 | mame_timer_adjust(mfp_p->tx_timer, time_zero, which, time_never); |
| 982 | 1015 | } |
| r1174 | r1175 | |
| 984 | 1017 | |
| 985 | 1018 | if (mfp_p->intf->to_w) |
| 986 | 1019 | { |
| 987 | | mfp_p->intf->to_w(which, MFP68901_TIMER_A, mfp_p->to[MFP68901_TIMER_A]); |
| 1020 | mfp_p->intf->to_w(which, index, mfp_p->to[index]); |
| 988 | 1021 | } |
| 989 | 1022 | |
| 990 | | if (mfp_p->ier & MFP68901_IR_TIMER_A) |
| 1023 | if (mfp_p->ier & MFP68901_INT_MASK_TIMER[index]) |
| 991 | 1024 | { |
| 992 | | mfp_p->ipr |= MFP68901_IR_TIMER_A; |
| 1025 | mfp_p->ipr |= MFP68901_INT_MASK_TIMER[index]; |
| 993 | 1026 | } |
| 994 | 1027 | |
| 995 | | mfp_p->tmc[MFP68901_TIMER_A] = mfp_p->tdr[MFP68901_TIMER_A]; |
| 1028 | mfp_p->tmc[index] = mfp_p->tdr[index]; |
| 996 | 1029 | } |
| 997 | 1030 | else |
| 998 | 1031 | { |
| 999 | | mfp_p->tmc[MFP68901_TIMER_A]--; |
| 1032 | mfp_p->tmc[index]--; |
| 1000 | 1033 | } |
| 1001 | 1034 | } |
| 1002 | 1035 | |
| 1003 | | void mfp68901_timer_count_b(int which) |
| 1036 | void mfp68901_ti_w(int which, int index, int value) |
| 1004 | 1037 | { |
| 1005 | 1038 | mfp_68901 *mfp_p = &mfp[which]; |
| 1039 | int bit = MFP68901_GPIO_TIMER[index]; |
| 1040 | int aer = BIT(mfp_p->aer, bit); |
| 1041 | int cr = index ? mfp_p->tbcr : mfp_p->tacr; |
| 1006 | 1042 | |
| 1007 | | if (mfp_p->tmc[MFP68901_TIMER_B] == 0x01) |
| 1043 | switch (cr & 0x0f) |
| 1008 | 1044 | { |
| 1009 | | mfp_p->to[MFP68901_TIMER_B] = mfp_p->to[MFP68901_TIMER_B] ? 0 : 1; |
| 1010 | | |
| 1011 | | if (mfp_p->to[MFP68901_TIMER_B]) |
| 1012 | | { |
| 1013 | | if (mfp_p->intf->rx_clock == MFP68901_TBO_LOOPBACK) |
| 1014 | | { |
| 1015 | | mame_timer_adjust(mfp_p->rx_timer, time_zero, which, time_never); |
| 1016 | | } |
| 1017 | | |
| 1018 | | if (mfp_p->intf->tx_clock == MFP68901_TBO_LOOPBACK) |
| 1019 | | { |
| 1020 | | mame_timer_adjust(mfp_p->tx_timer, time_zero, which, time_never); |
| 1021 | | } |
| 1022 | | } |
| 1023 | | |
| 1024 | | if (mfp_p->intf->to_w) |
| 1025 | | { |
| 1026 | | mfp_p->intf->to_w(which, MFP68901_TIMER_B, mfp_p->to[MFP68901_TIMER_B]); |
| 1027 | | } |
| 1028 | | |
| 1029 | | if (mfp_p->ier & MFP68901_IR_TIMER_B) |
| 1030 | | { |
| 1031 | | mfp_p->ipr |= MFP68901_IR_TIMER_B; |
| 1032 | | } |
| 1033 | | |
| 1034 | | mfp_p->tmc[MFP68901_TIMER_B] = mfp_p->tdr[MFP68901_TIMER_B]; |
| 1035 | | } |
| 1036 | | else |
| 1037 | | { |
| 1038 | | mfp_p->tmc[MFP68901_TIMER_B]--; |
| 1039 | | } |
| 1040 | | } |
| 1041 | | |
| 1042 | | void mfp68901_timer_count_c(int which) |
| 1043 | | { |
| 1044 | | mfp_68901 *mfp_p = &mfp[which]; |
| 1045 | | |
| 1046 | | if (mfp_p->tmc[MFP68901_TIMER_C] == 0x01) |
| 1047 | | { |
| 1048 | | mfp_p->to[MFP68901_TIMER_C] = mfp_p->to[MFP68901_TIMER_C] ? 0 : 1; |
| 1049 | | |
| 1050 | | if (mfp_p->to[MFP68901_TIMER_C]) |
| 1051 | | { |
| 1052 | | if (mfp_p->intf->rx_clock == MFP68901_TCO_LOOPBACK) |
| 1053 | | { |
| 1054 | | mame_timer_adjust(mfp_p->rx_timer, time_zero, which, time_never); |
| 1055 | | } |
| 1056 | | |
| 1057 | | if (mfp_p->intf->tx_clock == MFP68901_TCO_LOOPBACK) |
| 1058 | | { |
| 1059 | | mame_timer_adjust(mfp_p->tx_timer, time_zero, which, time_never); |
| 1060 | | } |
| 1061 | | } |
| 1062 | | |
| 1063 | | if (mfp_p->intf->to_w) |
| 1064 | | { |
| 1065 | | mfp_p->intf->to_w(which, MFP68901_TIMER_C, mfp_p->to[MFP68901_TIMER_C]); |
| 1066 | | } |
| 1067 | | |
| 1068 | | if (mfp_p->ier & MFP68901_IR_TIMER_C) |
| 1069 | | { |
| 1070 | | mfp_p->ipr |= MFP68901_IR_TIMER_C; |
| 1071 | | } |
| 1072 | | |
| 1073 | | mfp_p->tmc[MFP68901_TIMER_C] = mfp_p->tdr[MFP68901_TIMER_C]; |
| 1074 | | } |
| 1075 | | else |
| 1076 | | { |
| 1077 | | mfp_p->tmc[MFP68901_TIMER_C]--; |
| 1078 | | } |
| 1079 | | } |
| 1080 | | |
| 1081 | | void mfp68901_timer_count_d(int which) |
| 1082 | | { |
| 1083 | | mfp_68901 *mfp_p = &mfp[which]; |
| 1084 | | |
| 1085 | | if (mfp_p->tmc[MFP68901_TIMER_D] == 0x01) |
| 1086 | | { |
| 1087 | | mfp_p->to[MFP68901_TIMER_D] = mfp_p->to[MFP68901_TIMER_D] ? 0 : 1; |
| 1088 | | |
| 1089 | | if (mfp_p->to[MFP68901_TIMER_D]) |
| 1090 | | { |
| 1091 | | if (mfp_p->intf->rx_clock == MFP68901_TDO_LOOPBACK) |
| 1092 | | { |
| 1093 | | mame_timer_adjust(mfp_p->rx_timer, time_zero, which, time_never); |
| 1094 | | } |
| 1095 | | |
| 1096 | | if (mfp_p->intf->tx_clock == MFP68901_TDO_LOOPBACK) |
| 1097 | | { |
| 1098 | | mame_timer_adjust(mfp_p->tx_timer, time_zero, which, time_never); |
| 1099 | | } |
| 1100 | | } |
| 1101 | | |
| 1102 | | if (mfp_p->intf->to_w) |
| 1103 | | { |
| 1104 | | mfp_p->intf->to_w(which, MFP68901_TIMER_D, mfp_p->to[MFP68901_TIMER_D]); |
| 1105 | | } |
| 1106 | | |
| 1107 | | if (mfp_p->ier & MFP68901_IR_TIMER_D) |
| 1108 | | { |
| 1109 | | mfp_p->ipr |= MFP68901_IR_TIMER_D; |
| 1110 | | } |
| 1111 | | |
| 1112 | | mfp_p->tmc[MFP68901_TIMER_D] = mfp_p->tdr[MFP68901_TIMER_D]; |
| 1113 | | } |
| 1114 | | else |
| 1115 | | { |
| 1116 | | mfp_p->tmc[MFP68901_TIMER_D]--; |
| 1117 | | } |
| 1118 | | } |
| 1119 | | |
| 1120 | | void mfp68901_tai_w(int which, int value) |
| 1121 | | { |
| 1122 | | mfp_68901 *mfp_p = &mfp[which]; |
| 1123 | | |
| 1124 | | switch (mfp_p->tacr & 0x0f) |
| 1125 | | { |
| 1126 | 1045 | case MFP68901_TCR_TIMER_EVENT: |
| 1127 | | if (((mfp_p->ti[MFP68901_TIMER_A] ^ BIT(mfp_p->aer, 4)) == 1) && ((value ^ BIT(mfp_p->aer, 4)) == 0)) |
| 1046 | if (((mfp_p->ti[index] ^ aer) == 1) && ((value ^ aer) == 0)) |
| 1128 | 1047 | { |
| 1129 | | mfp68901_timer_count_a(which); |
| 1048 | mfp68901_timer_count(which, index); |
| 1130 | 1049 | } |
| 1131 | | mfp_p->ti[MFP68901_TIMER_A] = value; |
| 1050 | |
| 1051 | mfp_p->ti[index] = value; |
| 1132 | 1052 | break; |
| 1133 | 1053 | |
| 1134 | 1054 | case MFP68901_TCR_TIMER_PULSE_4: |
| r1174 | r1175 | |
| 1138 | 1058 | case MFP68901_TCR_TIMER_PULSE_64: |
| 1139 | 1059 | case MFP68901_TCR_TIMER_PULSE_100: |
| 1140 | 1060 | case MFP68901_TCR_TIMER_PULSE_200: |
| 1141 | | mame_timer_enable(mfp_p->timer[MFP68901_TIMER_A], (BIT(mfp_p->aer, 4) == value) ? 1 : 0); |
| 1061 | mame_timer_enable(mfp_p->timer[index], (value == aer) ? 1 : 0); |
| 1142 | 1062 | |
| 1143 | | if (((mfp_p->ti[MFP68901_TIMER_A] ^ BIT(mfp_p->aer, 4)) == 0) && ((value ^ BIT(mfp_p->aer, 4)) == 1)) |
| 1063 | if (((mfp_p->ti[index] ^ aer) == 0) && ((value ^ aer) == 1)) |
| 1144 | 1064 | { |
| 1145 | | if (mfp_p->ier & MFP68901_IR_GPIP_4) |
| 1065 | if (mfp_p->ier & MFP68901_INT_MASK_GPIO[bit]) |
| 1146 | 1066 | { |
| 1147 | | mfp_p->ipr |= MFP68901_IR_GPIP_4; |
| 1067 | mfp_p->ipr |= MFP68901_INT_MASK_GPIO[bit]; |
| 1148 | 1068 | } |
| 1149 | 1069 | } |
| 1150 | 1070 | |
| 1151 | | mfp_p->ti[MFP68901_TIMER_A] = value; |
| 1071 | mfp_p->ti[index] = value; |
| 1152 | 1072 | break; |
| 1153 | 1073 | } |
| 1154 | 1074 | } |
| 1155 | 1075 | |
| 1156 | | void mfp68901_tbi_w(int which, int value) |
| 1076 | void mfp68901_tai_w(int which, int value) |
| 1157 | 1077 | { |
| 1158 | | mfp_68901 *mfp_p = &mfp[which]; |
| 1078 | mfp68901_ti_w(which, MFP68901_TIMER_A, value); |
| 1079 | } |
| 1159 | 1080 | |
| 1160 | | switch (mfp_p->tbcr & 0x0f) |
| 1161 | | { |
| 1162 | | case MFP68901_TCR_TIMER_EVENT: |
| 1163 | | if (((mfp_p->ti[MFP68901_TIMER_B] ^ BIT(mfp_p->aer, 3)) == 1) && ((value ^ BIT(mfp_p->aer, 3)) == 0)) |
| 1164 | | { |
| 1165 | | mfp68901_timer_count_b(which); |
| 1166 | | } |
| 1167 | | mfp_p->ti[MFP68901_TIMER_B] = value; |
| 1168 | | break; |
| 1169 | | |
| 1170 | | case MFP68901_TCR_TIMER_PULSE_4: |
| 1171 | | case MFP68901_TCR_TIMER_PULSE_10: |
| 1172 | | case MFP68901_TCR_TIMER_PULSE_16: |
| 1173 | | case MFP68901_TCR_TIMER_PULSE_50: |
| 1174 | | case MFP68901_TCR_TIMER_PULSE_64: |
| 1175 | | case MFP68901_TCR_TIMER_PULSE_100: |
| 1176 | | case MFP68901_TCR_TIMER_PULSE_200: |
| 1177 | | mame_timer_enable(mfp_p->timer[MFP68901_TIMER_B], (BIT(mfp_p->aer, 3) == value) ? 1 : 0); |
| 1178 | | |
| 1179 | | if (((mfp_p->ti[MFP68901_TIMER_B] ^ BIT(mfp_p->aer, 3)) == 0) && ((value ^ BIT(mfp_p->aer, 3)) == 1)) |
| 1180 | | { |
| 1181 | | if (mfp_p->ier & MFP68901_IR_GPIP_3) |
| 1182 | | { |
| 1183 | | mfp_p->ipr |= MFP68901_IR_GPIP_3; |
| 1184 | | } |
| 1185 | | } |
| 1186 | | |
| 1187 | | mfp_p->ti[MFP68901_TIMER_B] = value; |
| 1188 | | break; |
| 1189 | | } |
| 1081 | void mfp68901_tbi_w(int which, int value) |
| 1082 | { |
| 1083 | mfp68901_ti_w(which, MFP68901_TIMER_B, value); |
| 1190 | 1084 | } |
| 1191 | 1085 | |
| 1192 | 1086 | static TIMER_CALLBACK( timer_a ) |
| 1193 | 1087 | { |
| 1194 | | mfp68901_timer_count_a(param); |
| 1088 | mfp68901_timer_count(param, MFP68901_TIMER_A); |
| 1195 | 1089 | } |
| 1196 | 1090 | |
| 1197 | 1091 | static TIMER_CALLBACK( timer_b ) |
| 1198 | 1092 | { |
| 1199 | | mfp68901_timer_count_b(param); |
| 1093 | mfp68901_timer_count(param, MFP68901_TIMER_B); |
| 1200 | 1094 | } |
| 1201 | 1095 | |
| 1202 | 1096 | static TIMER_CALLBACK( timer_c ) |
| 1203 | 1097 | { |
| 1204 | | mfp68901_timer_count_c(param); |
| 1098 | mfp68901_timer_count(param, MFP68901_TIMER_C); |
| 1205 | 1099 | } |
| 1206 | 1100 | |
| 1207 | 1101 | static TIMER_CALLBACK( timer_d ) |
| 1208 | 1102 | { |
| 1209 | | mfp68901_timer_count_d(param); |
| 1103 | mfp68901_timer_count(param, MFP68901_TIMER_D); |
| 1210 | 1104 | } |
| 1211 | 1105 | |
| 1212 | 1106 | void mfp68901_config(int which, const mfp68901_interface *intf) |