1.1 --- a/test.c Mon Feb 11 17:48:21 2013 +0000
1.2 +++ b/test.c Mon Feb 11 18:06:28 2013 +0000
1.3 @@ -220,7 +220,7 @@
1.4 return timeout;
1.5 }
1.6
1.7 -uint8_t samplebus()
1.8 +uint8_t samplebusready()
1.9 {
1.10 uint8_t result;
1.11
1.12 @@ -229,6 +229,49 @@
1.13 return !(result & MAX_HCTL_SAMPLEBUS);
1.14 }
1.15
1.16 +void samplebus()
1.17 +{
1.18 + max_write(MAX_REG_HCTL, MAX_HCTL_SAMPLEBUS);
1.19 + while (!samplebusready());
1.20 +}
1.21 +
1.22 +void devicechanged()
1.23 +{
1.24 + uint8_t hrsl, mode;
1.25 +
1.26 + hrsl = max_read(MAX_REG_HRSL, NULL);
1.27 + mode = max_read(MAX_REG_MODE, NULL);
1.28 +
1.29 + if ((hrsl & MAX_HRSL_JSTATUS) && (hrsl & MAX_HRSL_KSTATUS))
1.30 + {
1.31 + printf("Bad device status.\n");
1.32 + }
1.33 + else if (!(hrsl & MAX_HRSL_JSTATUS) && !(hrsl & MAX_HRSL_KSTATUS))
1.34 + {
1.35 + printf("Device disconnected.\n");
1.36 + }
1.37 + else
1.38 + {
1.39 + printf("Device connected.\n");
1.40 +
1.41 + /* Low speed device when J and lowspeed have the same level.
1.42 + Since J and K should have opposing levels, K can be tested when
1.43 + lowspeed is low. */
1.44 +
1.45 + if (((hrsl & MAX_HRSL_JSTATUS) && (mode & MAX_MODE_LOWSPEED)) ||
1.46 + ((hrsl & MAX_HRSL_KSTATUS) && !(mode & MAX_MODE_LOWSPEED)))
1.47 + {
1.48 + printf("Device is low speed.\n");
1.49 + max_write(MAX_REG_MODE, MAX_MODE_HOST | MAX_MODE_SEPIRQ_OFF | MAX_MODE_DMPULLDN | MAX_MODE_DPPULLDN | MAX_MODE_LOWSPEED);
1.50 + }
1.51 + else
1.52 + {
1.53 + printf("Device is full speed.\n");
1.54 + max_write(MAX_REG_MODE, MAX_MODE_HOST | MAX_MODE_SEPIRQ_OFF | MAX_MODE_DMPULLDN | MAX_MODE_DPPULLDN);
1.55 + }
1.56 + }
1.57 +}
1.58 +
1.59 void shutdown(int signum)
1.60 {
1.61 printf("Closing...\n");
1.62 @@ -315,7 +358,7 @@
1.63 status = max_read(MAX_REG_HIRQ, NULL);
1.64
1.65 if (status & MAX_HIRQ_CONDETIRQ)
1.66 - printf("Device connected.\n");
1.67 + devicechanged();
1.68 if (status & MAX_HIRQ_SUSDNIRQ)
1.69 printf("Suspend done.\n");
1.70 if (status & MAX_HIRQ_BUSEVENTIRQ)