123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- #include "../dp_usb/usb_stack_globals.h"
- #include "descriptors.h"
- #include "fraisemaster.h"
- #include "stdio.h"
- #ifdef __18CXX
- #define REMAPPED_RESET_VECTOR_ADDRESS 0x800
- #define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x808
- #define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x818
- #endif
- void SetupBoard(void);
- void InterruptHandlerHigh();
- void InterruptHandlerLow();
- void USBSuspend(void);
- int _user_putc(char c)
- {
- putc_cdc(c);
- }
- #pragma udata
- extern BYTE usb_device_state;
- volatile BYTE SofFlag;
- #pragma code
- void SOFHandler(void)
- {
-
-
- SofFlag=1;
- CDCFlushOnTimeout();
- }
- #ifdef PIC_18F
- void main(void)
- #else
- int main(void)
- #endif
- {
- BYTE RecvdByte;
- long int jj;
- stdout = _H_USER;
- initCDC();
- SetupBoard();
- usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS);
- usb_start();
-
- #define EnableUsbHighPriInterrupt() do { RCONbits.IPEN = 1; IPR2bits.USBIP = 1; INTCONbits.GIEH = 1;} while(0)
- #define EnableUsbLowPriInterrupt() do { RCONbits.IPEN = 1; IPR2bits.USBIP = 0; INTCONbits.GIEL = 1;} while(0)
- #if defined USB_INTERRUPTS
- EnableUsbPerifInterrupts(USB_TRN + USB_SOF + USB_UERR + USB_URST);
- #if defined __18CXX
-
- EnableUsbLowPriInterrupt();
- INTCONbits.PEIE = 1;
- INTCONbits.GIE = 1;
- #endif
- EnableUsbGlobalInterrupt();
- #endif
- do {
- #ifndef USB_INTERRUPTS
- usb_handler();
- #endif
- } while (usb_device_state < CONFIGURED_STATE);
- usb_register_sof_handler(SOFHandler);
-
-
- FraiseInit();
- do {
- #ifndef USB_INTERRUPTS
- usb_handler();
- #endif
-
-
- if(!FrGotLineFromUsb) {
- while(poll_getc_cdc(&RecvdByte)) {
- if(RecvdByte=='\n') {
- FrGotLineFromUsb=1;
-
- break;
- }
- else if(LineFromUsbLen<(sizeof(LineFromUsb)-1))
- LineFromUsb[LineFromUsbLen++]=RecvdByte;
- }
- }
- if(SofFlag==1) { FraiseSOF(); SofFlag=0; }
- FraiseService();
-
-
-
-
- } while (1);
- }
- void SetupBoard(void) {
- #if defined (PIEDUSB)
-
- ADCON1 |= 0b1111;
- CVRCON = 0b00000000;
- LATC = 0x00;
- TRISC = 0xFF;
- #endif
- }
- void USBSuspend(void) {}
- #if defined(USB_INTERRUPTS)
- #if defined(__PIC24FJ64GB106__) || defined(__PIC24FJ128GB106__) || defined(__PIC24FJ192GB106__) || defined(__PIC24FJ256GB106__) || defined(__PIC24FJ64GB108__) || defined(__PIC24FJ128GB108__) || defined(__PIC24FJ192GB108__) || defined(__PIC24FJ256GB108__) || defined(__PIC24FJ64GB110__) || defined(__PIC24FJ128GB110__) || defined(__PIC24FJ192GB110__) || defined(__PIC24FJ256GB110__)
- #pragma interrupt _USB1Interrupt
- void __attribute__((interrupt, auto_psv)) _USB1Interrupt() {
-
-
-
-
- usb_handler();
- ClearGlobalUsbInterruptFlag();
- }
- #elif defined (__18CXX)
- #pragma interruptlow InterruptHandlerLow nosave= PROD, PCLATH, PCLATU, TBLPTR, TBLPTRU, TABLAT, section (".tmpdata"), section("MATH_DATA")
- void InterruptHandlerLow(void) {
- usb_handler();
- ClearGlobalUsbInterruptFlag();
-
- }
- #pragma interrupt InterruptHandlerHigh nosave= PROD, PCLATH, PCLATU, TBLPTR, TBLPTRU, TABLAT, section (".tmpdata"), section("MATH_DATA")
- void InterruptHandlerHigh(void) {
-
-
- FraiseISR();
- }
- #pragma code REMAPPED_HIGH_INTERRUPT_VECTOR = REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS
- void Remapped_High_ISR(void) {
- _asm goto InterruptHandlerHigh _endasm
- }
- #pragma code REMAPPED_LOW_INTERRUPT_VECTOR = REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS
- void Remapped_Low_ISR(void) {
- _asm goto InterruptHandlerLow _endasm
- }
- extern void _startup(void);
- #pragma code REMAPPED_RESET_VECTOR = REMAPPED_RESET_VECTOR_ADDRESS
- void _reset(void) {
- _asm goto _startup _endasm
- }
- #if 0
- #pragma code HIGH_INTERRUPT_VECTOR = 0x08
- void High_ISR(void) {
- _asm goto REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS _endasm
- }
- #pragma code LOW_INTERRUPT_VECTOR = 0x18
- void Low_ISR(void) {
- _asm goto REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS _endasm
- }
- #endif
- #endif
- #endif
- #pragma code
|