USB-BDI
|
00001 /* USB-BDI Used for programming and debugging a MPC555 over USB 00002 * 00003 * Copyright 2005 NTB Interstate University of Applied Sciences of Technology Buchs 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 */ 00015 00024 #include "usb_common.h" 00025 #include "usbpdi_common.h" 00026 #include "usbpdi_main.h" 00027 #include "BDI_555.h" 00028 #include "UART.h" 00029 #include "fx2regs.h" 00030 #include "usbpdi_regs.h" 00031 #include "timer.h" 00032 #include "isr.h" 00033 #include "fx2utils.h" 00034 #include "virtual_com_port.h" 00035 00039 volatile unsigned char timer_count = 0; 00040 00041 #ifdef DEBUG_ON 00042 void write(unsigned char digit) 00043 { 00044 IOA = digit; 00045 } 00046 #endif 00047 00052 void toggleLED() 00053 { 00054 if (timer_count > STATUS_LED_COUNT_LIMIT) { 00055 timer_count = 0; 00056 STATUS_LED1 = !STATUS_LED1; 00057 } 00058 } 00059 00064 void update_speed_led(void){ 00065 //only highspeed available 00066 if(_usb_highspeed_granted){ 00067 STATUS_LED2 = 1; 00068 } 00069 00070 } 00071 00072 00078 static void isr_tick(void) __interrupt{ 00079 EA = 0; 00080 if (exceptionOnTimeout) { 00081 exceptionCount++; 00082 if (exceptionCount > EXCEPTION_COUNT) { 00083 exceptionOnTimeout = FALSE; 00084 usbInBuffer[0] = PACKET_HEADER; // header 00085 usbInBuffer[1] = MTYPE_BDI_555; // type field 00086 usbInBuffer[2] = STYPE_BDI_ERROR_TIMEOUT; 00087 usbInBuffer[3] = 0; // length 00088 usbInBuffer[4] = 0; 00089 usbInBuffer[PACKET_DATA_OFFSET] = PACKET_END; // packet end 00090 EP6BCH = 0; 00091 SYNCDELAY; 00092 EP6BCL = PACKET_MIN_LENGTH; // arm EP6IN 00093 SYNCDELAY; 00094 inBufIndex = 0; // reset inBufIndex 00095 } 00096 } 00097 timer_count++; 00098 00099 clear_timer_irq(); 00100 EA = 1; 00101 } 00102 00111 void main(void) { 00112 00113 EA = 0; //disable all interrupts 00114 00115 initCPU(); 00116 initIOPorts(); 00117 00118 initEndpoint0(); 00119 00120 initTP3465(); 00121 initUART(); 00122 setup_autovectors(); 00123 usb_install_handlers(); 00124 hook_timer_tick((unsigned short) isr_tick); 00125 00126 update_speed_led(); 00127 initBDI(); 00128 initVirtualComPort(); 00129 EA = 1; // global interrupt enable 00130 00131 while (1) { 00132 handelSetupPackages(); 00133 handelBDIPackages(); 00134 handelVirtualComPortPackages(); 00135 toggleLED(); 00136 } 00137 }