#include <delay.h>
#include <setupdat.h>
+#define SET_ANALOG_MODE() PA7 = 1
+
+/* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */
+#define TOGGLE_CALIBRATION_PIN() PC2 = !PC2
+
+#define LED_CLEAR() PC0 = 1; PC1 = 1;
+#define LED_GREEN() PC0 = 1; PC1 = 0;
+#define LED_RED() PC0 = 0; PC1 = 1;
+
/* Change to support as many interfaces as you need. */
static BYTE altiface = 0;
void timer2_isr(void) __interrupt TF2_ISR
{
- /* Toggle the 1kHz calibration pin, only accurate up to ca 8MHz. */
- PC2 = !PC2;
-
- if (ledcounter) {
- if (--ledcounter == 0) {
- /* Clear LED. */
- PC0 = 1;
- PC1 = 1;
- }
- }
+ TOGGLE_CALIBRATION_PIN();
+
+ if (ledcounter && (--ledcounter == 0))
+ LED_CLEAR();
+
TF2 = 0;
}
{
int i;
- /* Set analog mode. */
- PA7 = 1;
+ SET_ANALOG_MODE();
clear_fifo();
GPIFTCB0 = 0;
GPIFTRIG = (altiface == 0) ? 6 : 4;
- /* Set green LED, don't clear LED. */
+ /* Set green LED, don't clear LED afterwards (ledcounter = 0). */
+ LED_GREEN();
ledcounter = 0;
- PC0 = 1;
- PC1 = 0;
}
static void select_interface(BYTE alt)
/*
* The program for low-speed, e.g. 1 MHz, is:
- * wait 24, CTL2=0, FIFO
- * wait 23, CTL2=1
- * jump 0, CTL2=1
+ * wait 24, CTLx=0, FIFO
+ * wait 23, CTLx=1
+ * jump 0, CTLx=1
*
* The program for 24 MHz is:
- * wait 1, CTL2=0, FIFO
- * jump 0, CTL2=1
+ * wait 1, CTLx=0, FIFO
+ * jump 0, CTLx=1
*
* The program for 30/48 MHz is:
- * jump 0, CTL2=Z, FIFO, LOOP
+ * jump 0, CTLx=Z, FIFO, LOOP
+ *
+ * (CTLx is device-dependent, could be e.g. CTL0 or CTL2.)
*/
/* LENGTH / BRANCH 0-7 */
{
stop_sampling();
- /* Set red LED. */
- PC0 = 0;
- PC1 = 1;
+ /* Set red LED, clear after timeout. */
+ LED_RED();
ledcounter = 1000;
/* Clear EP0BCH/L for each valid command. */
EP4CFG = 0;
EP8CFG = 0;
- /* Set analog mode. */
- PA7 = 1;
+ SET_ANALOG_MODE();
/* In idle mode tristate all outputs. */
GPIFIDLECTL = 0x00; /* Don't enable CTL0-5 outputs. */
RENUMERATE();
+ PORTECFG = 0;
PORTCCFG = 0;
PORTACFG = 0;
+ OEE = 0xff;
OEC = 0xff;
- OEA = 0x80;
+ OEA = 0xff;
while (TRUE) {
if (dosud) {
dosuspend = FALSE;
do {
/* Make sure ext wakeups are cleared. */
- WAKEUPCS |= bmWU|bmWU2;
+ WAKEUPCS |= bmWU | bmWU2;
SUSPEND = 1;
PCON |= 1;
__asm