Previous 15994 Revisions Next

r1175 Tuesday 23rd October, 2007 at 10:00:01 UTC by Curt Coder
[MFP68901] Removed duplicate code
[src/mess/machine]68901mfp.c 68901mfp.h

src/mess/machine/68901mfp.c
r1174r1175
44
55   - daisy chaining
66   - 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."
725   
826   - divide serial clock by 16
927   - synchronous mode
r1174r1175
4967
5068static mfp_68901 mfp[MAX_MFP];
5169
52static const int GPIO_MASK[] =
70static const int MFP68901_INT_MASK_GPIO[] =
5371{
5472   MFP68901_IR_GPIP_0, MFP68901_IR_GPIP_1, MFP68901_IR_GPIP_2, MFP68901_IR_GPIP_3,
5573   MFP68901_IR_GPIP_4, MFP68901_IR_GPIP_5, MFP68901_IR_GPIP_6, MFP68901_IR_GPIP_7
5674};
5775
76static 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
81static const int MFP68901_LOOPBACK_TIMER[] =
82{
83   MFP68901_TAO_LOOPBACK, MFP68901_TBO_LOOPBACK, MFP68901_TCO_LOOPBACK, MFP68901_TDO_LOOPBACK
84};
85
86static const int MFP68901_GPIO_TIMER[] =
87{
88   MFP68901_GPIP_4, MFP68901_GPIP_3
89};
90
5891static const int PRESCALER[] = { 0, 4, 10, 16, 50, 64, 100, 200 };
5992
6093static void mfp68901_poll_gpio(int which)
r1174r1175
78111      {
79112         logerror("MFP68901 #%u Edge Transition Detected on GPIO%u\n", which, bit);
80113
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...
82115         {
83116            logerror("MFP68901 #%u Interrupt Pending for GPIO%u\n", which, bit);
84117
85            mfp_p->ipr |= GPIO_MASK[bit]; // set interrupt pending bit
118            mfp_p->ipr |= MFP68901_INT_MASK_GPIO[bit]; // set interrupt pending bit
86119         }
87120      }
88121   }
r1174r1175
542575   case MFP68901_REGISTER_AER:
543576      logerror("MFP68901 #%u Active Edge Register : %x\n", which, data);
544577      mfp_p->aer = data;
545      // check transition and trigger interrupt if necessary
546578      break;
547579
548580   case MFP68901_REGISTER_DDR:
r1174r1175
599631
600632      mfp_p->vr = data & 0xf8;
601633
602      if ((mfp_p->vr & MFP68901_VR_S) == 0)
634      if (mfp_p->vr & MFP68901_VR_S)
603635      {
636         logerror("MFP68901 #%u Software End-Of-Interrupt Mode\n", which);
637      }
638      else
639      {
604640         logerror("MFP68901 #%u Automatic End-Of-Interrupt Mode\n", which);
605641
606642         mfp_p->isr = 0;
607643      }
608      else
609      {
610         logerror("MFP68901 #%u Software End-Of-Interrupt Mode\n", which);
611      }
612644      break;
613645
614646   case MFP68901_REGISTER_TACR:
r1174r1175
633665         logerror("MFP68901 #%u Timer A Delay Mode : %u Prescale\n", which, divisor);
634666         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));
635667         }
668         break;
636669
637670      case MFP68901_TCR_TIMER_EVENT:
638671         logerror("MFP68901 #%u Timer A Event Count Mode\n", which);
r1174r1175
961994   }
962995}
963996
964void mfp68901_timer_count_a(int which)
997void mfp68901_timer_count(int which, int index)
965998{
966999   mfp_68901 *mfp_p = &mfp[which];
9671000
968   if (mfp_p->tmc[MFP68901_TIMER_A] == 0x01)
1001   if (mfp_p->tmc[index] == 0x01)
9691002   {
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;
9711004
972      if (mfp_p->to[MFP68901_TIMER_A])
1005      if (mfp_p->to[index])
9731006      {
974         if (mfp_p->intf->rx_clock == MFP68901_TAO_LOOPBACK)
1007         if (mfp_p->intf->rx_clock == MFP68901_LOOPBACK_TIMER[index])
9751008         {
9761009            mame_timer_adjust(mfp_p->rx_timer, time_zero, which, time_never);
9771010         }
9781011
979         if (mfp_p->intf->tx_clock == MFP68901_TAO_LOOPBACK)
1012         if (mfp_p->intf->tx_clock == MFP68901_LOOPBACK_TIMER[index])
9801013         {
9811014            mame_timer_adjust(mfp_p->tx_timer, time_zero, which, time_never);
9821015         }
r1174r1175
9841017
9851018      if (mfp_p->intf->to_w)
9861019      {
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]);
9881021      }
9891022
990      if (mfp_p->ier & MFP68901_IR_TIMER_A)
1023      if (mfp_p->ier & MFP68901_INT_MASK_TIMER[index])
9911024      {
992         mfp_p->ipr |= MFP68901_IR_TIMER_A;
1025         mfp_p->ipr |= MFP68901_INT_MASK_TIMER[index];
9931026      }
9941027
995      mfp_p->tmc[MFP68901_TIMER_A] = mfp_p->tdr[MFP68901_TIMER_A];
1028      mfp_p->tmc[index] = mfp_p->tdr[index];
9961029   }
9971030   else
9981031   {
999      mfp_p->tmc[MFP68901_TIMER_A]--;
1032      mfp_p->tmc[index]--;
10001033   }
10011034}
10021035
1003void mfp68901_timer_count_b(int which)
1036void mfp68901_ti_w(int which, int index, int value)
10041037{
10051038   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;
10061042
1007   if (mfp_p->tmc[MFP68901_TIMER_B] == 0x01)
1043   switch (cr & 0x0f)
10081044   {
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
1042void 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
1081void 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
1120void mfp68901_tai_w(int which, int value)
1121{
1122   mfp_68901 *mfp_p = &mfp[which];
1123
1124   switch (mfp_p->tacr & 0x0f)
1125   {
11261045   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))
11281047      {
1129         mfp68901_timer_count_a(which);
1048         mfp68901_timer_count(which, index);
11301049      }
1131      mfp_p->ti[MFP68901_TIMER_A] = value;
1050
1051      mfp_p->ti[index] = value;
11321052      break;
11331053
11341054   case MFP68901_TCR_TIMER_PULSE_4:
r1174r1175
11381058   case MFP68901_TCR_TIMER_PULSE_64:
11391059   case MFP68901_TCR_TIMER_PULSE_100:
11401060   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);
11421062
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))
11441064      {
1145         if (mfp_p->ier & MFP68901_IR_GPIP_4)
1065         if (mfp_p->ier & MFP68901_INT_MASK_GPIO[bit])
11461066         {
1147            mfp_p->ipr |= MFP68901_IR_GPIP_4;
1067            mfp_p->ipr |= MFP68901_INT_MASK_GPIO[bit];
11481068         }
11491069      }
11501070
1151      mfp_p->ti[MFP68901_TIMER_A] = value;
1071      mfp_p->ti[index] = value;
11521072      break;
11531073   }
11541074}
11551075
1156void mfp68901_tbi_w(int which, int value)
1076void mfp68901_tai_w(int which, int value)
11571077{
1158   mfp_68901 *mfp_p = &mfp[which];
1078   mfp68901_ti_w(which, MFP68901_TIMER_A, value);
1079}
11591080
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   }
1081void mfp68901_tbi_w(int which, int value)
1082{
1083   mfp68901_ti_w(which, MFP68901_TIMER_B, value);
11901084}
11911085
11921086static TIMER_CALLBACK( timer_a )
11931087{
1194   mfp68901_timer_count_a(param);
1088   mfp68901_timer_count(param, MFP68901_TIMER_A);
11951089}
11961090
11971091static TIMER_CALLBACK( timer_b )
11981092{
1199   mfp68901_timer_count_b(param);
1093   mfp68901_timer_count(param, MFP68901_TIMER_B);
12001094}
12011095
12021096static TIMER_CALLBACK( timer_c )
12031097{
1204   mfp68901_timer_count_c(param);
1098   mfp68901_timer_count(param, MFP68901_TIMER_C);
12051099}
12061100
12071101static TIMER_CALLBACK( timer_d )
12081102{
1209   mfp68901_timer_count_d(param);
1103   mfp68901_timer_count(param, MFP68901_TIMER_D);
12101104}
12111105
12121106void mfp68901_config(int which, const mfp68901_interface *intf)
src/mess/machine/68901mfp.h
r1174r1175
7373
7474enum
7575{
76   MFP68901_GPIP_0 = 0,
77   MFP68901_GPIP_1,
78   MFP68901_GPIP_2,
79   MFP68901_GPIP_3,
80   MFP68901_GPIP_4,
81   MFP68901_GPIP_5,
82   MFP68901_GPIP_6,
83   MFP68901_GPIP_7
84};
85
86enum
87{
7688   MFP68901_TIMER_A = 0,
7789   MFP68901_TIMER_B,
7890   MFP68901_TIMER_C,

Previous 15994 Revisions Next


© 1998-2018 The MESS Team