From f3456ea1cfc56ebfa1fcea33be93856c0a71df37 Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Mon, 4 Nov 2013 00:22:17 +0100 Subject: Updated USB Driver, nanite, oscal --- firmware/usbdrv/usbdrvasm.S | 50 ++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'firmware/usbdrv/usbdrvasm.S') diff --git a/firmware/usbdrv/usbdrvasm.S b/firmware/usbdrv/usbdrvasm.S index 45fcf18..b03b709 100644 --- a/firmware/usbdrv/usbdrvasm.S +++ b/firmware/usbdrv/usbdrvasm.S @@ -5,7 +5,6 @@ * Tabsize: 4 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) - * Revision: $Id: usbdrvasm.S 785 2010-05-30 17:57:07Z cs $ */ /* @@ -285,7 +284,7 @@ usbCrc16Append: #if USB_CFG_HAVE_MEASURE_FRAME_LENGTH #ifdef __IAR_SYSTEMS_ASM__ -/* Register assignments for usbMeasureFrameLength on IAR cc */ +/* Register assignments for usbMeasureFrameLengthDecreasing on IAR cc */ /* Calling conventions on IAR: * First parameter passed in r16/r17, second in r18/r19 and so on. * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) @@ -314,33 +313,28 @@ usbCrc16Append: #endif # define cnt16 cnt16L -; extern unsigned usbMeasurePacketLength(void); -; returns time between two idle strobes in multiples of 7 CPU clocks -.global usbMeasureFrameLength -usbMeasureFrameLength: - ldi cntH, 6 ; wait ~ 10 ms for D- == 0 - clr cnt16L - clr cnt16H -usbMFTime16: - dec cntH - breq usbMFTimeout -usbMFWaitStrobe: ; first wait for D- == 0 (idle strobe) - sbiw cnt16, 1 ;[0] [6] - breq usbMFTime16 ;[2] - sbic USBIN, USBMINUS ;[3] - rjmp usbMFWaitStrobe ;[4] -usbMFWaitIdle: ; then wait until idle again +; extern int usbMeasurePacketLengthDecreasing(int); +; input: timer start value +; return: counts down time between two idle strobes in multiples of 5 CPU clocks +.global usbMeasureFrameLengthDecreasing +usbMeasureFrameLengthDecreasing: + +#if resL != cnt16L + mov cnt16L, resL + mov cnt16H, resH +#endif + +usbDFWaitStrobe: ; first wait for D- == 0 (idle strobe) + sbic USBIN, USBMINUS ; + rjmp usbDFWaitStrobe ; +usbDFWaitIdle: ; then wait until idle again sbis USBIN, USBMINUS ;1 wait for D- == 1 - rjmp usbMFWaitIdle ;2 - ldi cnt16L, 1 ;1 represents cycles so far - clr cnt16H ;1 -usbMFWaitLoop: - in cntH, USBIN ;[0] [7] - adiw cnt16, 1 ;[1] - breq usbMFTimeout ;[3] - andi cntH, USBMASK ;[4] - brne usbMFWaitLoop ;[5] -usbMFTimeout: + rjmp usbDFWaitIdle ;2 +usbDFWaitLoop: + sbiw cnt16,1 ;[0] [5] + sbic USBIN, USBMINUS ;[2] + rjmp usbDFWaitLoop ;[3] + #if resL != cnt16L mov resL, cnt16L mov resH, cnt16H -- cgit v1.2.3 From d7360925c1170acbc3a7b98c50e48350ac80fbc7 Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Mon, 4 Nov 2013 05:11:22 +0100 Subject: assembler version of calibrateoscillator - 1952 bytes still needs cleaning up --- firmware/usbdrv/usbdrvasm.S | 200 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 199 insertions(+), 1 deletion(-) (limited to 'firmware/usbdrv/usbdrvasm.S') diff --git a/firmware/usbdrv/usbdrvasm.S b/firmware/usbdrv/usbdrvasm.S index b03b709..29c634a 100644 --- a/firmware/usbdrv/usbdrvasm.S +++ b/firmware/usbdrv/usbdrvasm.S @@ -282,7 +282,81 @@ usbCrc16Append: #undef scratch -#if USB_CFG_HAVE_MEASURE_FRAME_LENGTH +#if USB_CFG_HAVE_MEASURE_FRAME_LENGTHx +#ifdef __IAR_SYSTEMS_ASM__ +/* Register assignments for usbMeasureFrameLength on IAR cc */ +/* Calling conventions on IAR: + * First parameter passed in r16/r17, second in r18/r19 and so on. + * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) + * Result is passed in r16/r17 + * In case of the "tiny" memory model, pointers are only 8 bit with no + * padding. We therefore pass argument 1 as "16 bit unsigned". + */ +# define resL r16 +# define resH r17 +# define cnt16L r30 +# define cnt16H r31 +# define cntH r18 + +#else /* __IAR_SYSTEMS_ASM__ */ +/* Register assignments for usbMeasureFrameLength on gcc */ +/* Calling conventions on gcc: + * First parameter passed in r24/r25, second in r22/23 and so on. + * Callee must preserve r1-r17, r28/r29 + * Result is passed in r24/r25 + */ +# define resL r24 +# define resH r25 +# define cnt16L r24 +# define cnt16H r25 +# define cntH r26 +#endif +# define cnt16 cnt16L + +; extern unsigned usbMeasurePacketLength(void); +; returns time between two idle strobes in multiples of 7 CPU clocks +.global usbMeasureFrameLength +usbMeasureFrameLength: + ldi cntH, 6 ; wait ~ 10 ms for D- == 0 + clr cnt16L + clr cnt16H +usbMFTime16: + dec cntH + breq usbMFTimeout +usbMFWaitStrobe: ; first wait for D- == 0 (idle strobe) + sbiw cnt16, 1 ;[0] [6] + breq usbMFTime16 ;[2] + sbic USBIN, USBMINUS ;[3] + rjmp usbMFWaitStrobe ;[4] +usbMFWaitIdle: ; then wait until idle again + sbis USBIN, USBMINUS ;1 wait for D- == 1 + rjmp usbMFWaitIdle ;2 + ldi cnt16L, 1 ;1 represents cycles so far + clr cnt16H ;1 +usbMFWaitLoop: + in cntH, USBIN ;[0] [7] + adiw cnt16, 1 ;[1] + breq usbMFTimeout ;[3] + andi cntH, USBMASK ;[4] + brne usbMFWaitLoop ;[5] +usbMFTimeout: +#if resL != cnt16L + mov resL, cnt16L + mov resH, cnt16H +#endif + ret + +#undef resL +#undef resH +#undef cnt16 +#undef cnt16L +#undef cnt16H +#undef cntH + +#endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */ + + +#if USB_CFG_HAVE_MEASURE_FRAME_LENGTHx #ifdef __IAR_SYSTEMS_ASM__ /* Register assignments for usbMeasureFrameLengthDecreasing on IAR cc */ /* Calling conventions on IAR: @@ -350,6 +424,130 @@ usbDFWaitLoop: #endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */ + + +#if USB_CFG_HAVE_MEASURE_FRAME_LENGTH +#ifdef __IAR_SYSTEMS_ASM__ +/* Register assignments for usbMeasureFrameLengthDecreasing on IAR cc */ +/* Calling conventions on IAR: + * First parameter passed in r16/r17, second in r18/r19 and so on. + * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) + * Result is passed in r16/r17 + * In case of the "tiny" memory model, pointers are only 8 bit with no + * padding. We therefore pass argument 1 as "16 bit unsigned". + */ + +# define resL r16 +# define resH r17 +# define cnt16L r30 +# define cnt16H r31 +# define cntH r18 + +#else /* __IAR_SYSTEMS_ASM__ */ +/* Register assignments for usbMeasureFrameLength on gcc */ +/* Calling conventions on gcc: + * First parameter passed in r24/r25, second in r22/23 and so on. + * Callee must preserve r1-r17, r28/r29 + * Result is passed in r24/r25 + */ + +# define i r20 +# define opV r19 +# define opD r18 +# define try r27 +# define stp r26 +# define cnt16L r24 +# define cnt16H r25 +#endif +# define cnt16 cnt16L + +; extern void calibrateOscillatorASM(void); + +.global calibrateOscillatorASM +calibrateOscillatorASM: + + cli + ldi i, 10 ; 10 iterations + + ldi opD, 255 + + ldi try, 128 ; calibration start value + ldi stp, 64 ; initial step width + +usbCOloop: + + out OSCCAL, try + nop + + ; Delay values = F_CPU * 999e-6 / 5 + 0.5 + +#if (F_CPU == 16500000) + ldi cnt16L, lo8(3297) + ldi cnt16H, hi8(3297) +#define usbok +#endif + +#if (F_CPU == 12800000) + ldi cnt16L, lo8(2557) + ldi cnt16H, hi8(2557) +#define usbok +#endif + +#ifndef usbok + #error "calibrateOscillatorASM: no delayvalues defined for this F_CPU setting" +#endif +#undef usbok + +usbCOWaitStrobe: ; first wait for D- == 0 (idle strobe) + sbic USBIN, USBMINUS ; + rjmp usbCOWaitStrobe ; +usbCOWaitIdle: ; then wait until idle again + sbis USBIN, USBMINUS ;1 wait for D- == 1 + rjmp usbCOWaitIdle ;2 +usbCOWaitLoop: + sbiw cnt16,1 ;[0] [5] + sbic USBIN, USBMINUS ;[2] + rjmp usbCOWaitLoop ;[3] + + sbrs cnt16H, 7 ;delay overflow? + rjmp usbCOclocktoolow + sub try, stp + neg cnt16L + rjmp usbCOclocktoohigh +usbCOclocktoolow: + add try, stp +usbCOclocktoohigh: + lsr stp + brne usbCOstepnotzero + cp opD, cnt16L + brcs usbCOnoimprovement + in opV, OSCCAL + mov opD, cnt16L +usbCOnoimprovement: + ldi stp, 1 +usbCOstepnotzero: + subi i, 1 + brne usbCOloop + + out OSCCAL, opV + nop + sei + ret + +#undef i +#undef opV +#undef opD +#undef try +#undef stp +#undef cnt16 +#undef cnt16L +#undef cnt16H + + +#endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */ + + + ;---------------------------------------------------------------------------- ; Now include the clock rate specific code ;---------------------------------------------------------------------------- -- cgit v1.2.3 From 0a4f48c2cbcf20f93fc9531b3f57974cb4b6364d Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Mon, 4 Nov 2013 13:57:24 +0100 Subject: source code clean up --- firmware/usbdrv/usbdrvasm.S | 195 +------------------------------------------- 1 file changed, 1 insertion(+), 194 deletions(-) (limited to 'firmware/usbdrv/usbdrvasm.S') diff --git a/firmware/usbdrv/usbdrvasm.S b/firmware/usbdrv/usbdrvasm.S index 29c634a..32ce8ef 100644 --- a/firmware/usbdrv/usbdrvasm.S +++ b/firmware/usbdrv/usbdrvasm.S @@ -282,7 +282,7 @@ usbCrc16Append: #undef scratch -#if USB_CFG_HAVE_MEASURE_FRAME_LENGTHx +#if USB_CFG_HAVE_MEASURE_FRAME_LENGTH #ifdef __IAR_SYSTEMS_ASM__ /* Register assignments for usbMeasureFrameLength on IAR cc */ /* Calling conventions on IAR: @@ -355,199 +355,6 @@ usbMFTimeout: #endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */ - -#if USB_CFG_HAVE_MEASURE_FRAME_LENGTHx -#ifdef __IAR_SYSTEMS_ASM__ -/* Register assignments for usbMeasureFrameLengthDecreasing on IAR cc */ -/* Calling conventions on IAR: - * First parameter passed in r16/r17, second in r18/r19 and so on. - * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) - * Result is passed in r16/r17 - * In case of the "tiny" memory model, pointers are only 8 bit with no - * padding. We therefore pass argument 1 as "16 bit unsigned". - */ -# define resL r16 -# define resH r17 -# define cnt16L r30 -# define cnt16H r31 -# define cntH r18 - -#else /* __IAR_SYSTEMS_ASM__ */ -/* Register assignments for usbMeasureFrameLength on gcc */ -/* Calling conventions on gcc: - * First parameter passed in r24/r25, second in r22/23 and so on. - * Callee must preserve r1-r17, r28/r29 - * Result is passed in r24/r25 - */ -# define resL r24 -# define resH r25 -# define cnt16L r24 -# define cnt16H r25 -# define cntH r26 -#endif -# define cnt16 cnt16L - -; extern int usbMeasurePacketLengthDecreasing(int); -; input: timer start value -; return: counts down time between two idle strobes in multiples of 5 CPU clocks -.global usbMeasureFrameLengthDecreasing -usbMeasureFrameLengthDecreasing: - -#if resL != cnt16L - mov cnt16L, resL - mov cnt16H, resH -#endif - -usbDFWaitStrobe: ; first wait for D- == 0 (idle strobe) - sbic USBIN, USBMINUS ; - rjmp usbDFWaitStrobe ; -usbDFWaitIdle: ; then wait until idle again - sbis USBIN, USBMINUS ;1 wait for D- == 1 - rjmp usbDFWaitIdle ;2 -usbDFWaitLoop: - sbiw cnt16,1 ;[0] [5] - sbic USBIN, USBMINUS ;[2] - rjmp usbDFWaitLoop ;[3] - -#if resL != cnt16L - mov resL, cnt16L - mov resH, cnt16H -#endif - ret - -#undef resL -#undef resH -#undef cnt16 -#undef cnt16L -#undef cnt16H -#undef cntH - -#endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */ - - - -#if USB_CFG_HAVE_MEASURE_FRAME_LENGTH -#ifdef __IAR_SYSTEMS_ASM__ -/* Register assignments for usbMeasureFrameLengthDecreasing on IAR cc */ -/* Calling conventions on IAR: - * First parameter passed in r16/r17, second in r18/r19 and so on. - * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) - * Result is passed in r16/r17 - * In case of the "tiny" memory model, pointers are only 8 bit with no - * padding. We therefore pass argument 1 as "16 bit unsigned". - */ - -# define resL r16 -# define resH r17 -# define cnt16L r30 -# define cnt16H r31 -# define cntH r18 - -#else /* __IAR_SYSTEMS_ASM__ */ -/* Register assignments for usbMeasureFrameLength on gcc */ -/* Calling conventions on gcc: - * First parameter passed in r24/r25, second in r22/23 and so on. - * Callee must preserve r1-r17, r28/r29 - * Result is passed in r24/r25 - */ - -# define i r20 -# define opV r19 -# define opD r18 -# define try r27 -# define stp r26 -# define cnt16L r24 -# define cnt16H r25 -#endif -# define cnt16 cnt16L - -; extern void calibrateOscillatorASM(void); - -.global calibrateOscillatorASM -calibrateOscillatorASM: - - cli - ldi i, 10 ; 10 iterations - - ldi opD, 255 - - ldi try, 128 ; calibration start value - ldi stp, 64 ; initial step width - -usbCOloop: - - out OSCCAL, try - nop - - ; Delay values = F_CPU * 999e-6 / 5 + 0.5 - -#if (F_CPU == 16500000) - ldi cnt16L, lo8(3297) - ldi cnt16H, hi8(3297) -#define usbok -#endif - -#if (F_CPU == 12800000) - ldi cnt16L, lo8(2557) - ldi cnt16H, hi8(2557) -#define usbok -#endif - -#ifndef usbok - #error "calibrateOscillatorASM: no delayvalues defined for this F_CPU setting" -#endif -#undef usbok - -usbCOWaitStrobe: ; first wait for D- == 0 (idle strobe) - sbic USBIN, USBMINUS ; - rjmp usbCOWaitStrobe ; -usbCOWaitIdle: ; then wait until idle again - sbis USBIN, USBMINUS ;1 wait for D- == 1 - rjmp usbCOWaitIdle ;2 -usbCOWaitLoop: - sbiw cnt16,1 ;[0] [5] - sbic USBIN, USBMINUS ;[2] - rjmp usbCOWaitLoop ;[3] - - sbrs cnt16H, 7 ;delay overflow? - rjmp usbCOclocktoolow - sub try, stp - neg cnt16L - rjmp usbCOclocktoohigh -usbCOclocktoolow: - add try, stp -usbCOclocktoohigh: - lsr stp - brne usbCOstepnotzero - cp opD, cnt16L - brcs usbCOnoimprovement - in opV, OSCCAL - mov opD, cnt16L -usbCOnoimprovement: - ldi stp, 1 -usbCOstepnotzero: - subi i, 1 - brne usbCOloop - - out OSCCAL, opV - nop - sei - ret - -#undef i -#undef opV -#undef opD -#undef try -#undef stp -#undef cnt16 -#undef cnt16L -#undef cnt16H - - -#endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */ - - - ;---------------------------------------------------------------------------- ; Now include the clock rate specific code ;---------------------------------------------------------------------------- -- cgit v1.2.3