| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 32 | kaklik | /****************************************************************************** |
| 2 | |||
| 3 | USB Hardware Abstraction Layer (HAL) |
||
| 4 | |||
| 5 | Summary: |
||
| 6 | This file abstracts the hardware interface. The USB stack firmware can be |
||
| 7 | compiled to work on different USB microcontrollers, such as PIC18 and PIC24. |
||
| 8 | The USB related special function registers and bit names are generally very |
||
| 9 | similar between the device families, but small differences in naming exist. |
||
| 10 | |||
| 11 | Description: |
||
| 12 | This file abstracts the hardware interface. The USB stack firmware can be |
||
| 13 | compiled to work on different USB microcontrollers, such as PIC18 and PIC24. |
||
| 14 | The USB related special function registers and bit names are generally very |
||
| 15 | similar between the device families, but small differences in naming exist. |
||
| 16 | |||
| 17 | In order to make the same set of firmware work accross the device families, |
||
| 18 | when modifying SFR contents, a slightly abstracted name is used, which is |
||
| 19 | then "mapped" to the appropriate real name in the usb_hal_picxx.h header. |
||
| 20 | |||
| 21 | Make sure to include the correct version of the usb_hal_picxx.h file for |
||
| 22 | the microcontroller family which will be used. |
||
| 23 | |||
| 24 | This file is located in the "\<Install Directory\>\\Microchip\\Include\\USB" |
||
| 25 | directory. |
||
| 26 | |||
| 27 | When including this file in a new project, this file can either be |
||
| 28 | referenced from the directory in which it was installed or copied |
||
| 29 | directly into the user application folder. If the first method is |
||
| 30 | chosen to keep the file located in the folder in which it is installed |
||
| 31 | then include paths need to be added so that the library and the |
||
| 32 | application both know where to reference each others files. If the |
||
| 33 | application folder is located in the same folder as the Microchip |
||
| 34 | folder (like the current demo folders), then the following include |
||
| 35 | paths need to be added to the application's project: |
||
| 36 | |||
| 37 | . |
||
| 38 | |||
| 39 | ..\\..\\MicrochipInclude |
||
| 40 | |||
| 41 | If a different directory structure is used, modify the paths as |
||
| 42 | required. An example using absolute paths instead of relative paths |
||
| 43 | would be the following: |
||
| 44 | |||
| 45 | C:\\Microchip Solutions\\Microchip\\Include |
||
| 46 | |||
| 47 | C:\\Microchip Solutions\\My Demo Application |
||
| 48 | |||
| 49 | |||
| 50 | *******************************************************************************/ |
||
| 51 | //DOM-IGNORE-BEGIN |
||
| 52 | /****************************************************************************** |
||
| 53 | |||
| 54 | File Description: |
||
| 55 | |||
| 56 | This file defines the interface to the USB hardware abstraction layer. |
||
| 57 | |||
| 58 | Filename: usb_hal_pic24.c |
||
| 59 | Dependancies: none |
||
| 60 | Processor: PIC24F USB Microcontrollers |
||
| 61 | Hardware: PIC24F USB Microcontrollers |
||
| 62 | Compiler: Microchip C30 (for PIC24) |
||
| 63 | Company: Microchip Technology, Inc. |
||
| 64 | |||
| 65 | Software License Agreement: |
||
| 66 | |||
| 67 | The software supplied herewith by Microchip Technology Incorporated |
||
| 68 | (the Company) for its PICmicro® Microcontroller is intended and |
||
| 69 | supplied to you, the Companys customer, for use solely and |
||
| 70 | exclusively on Microchip PICmicro Microcontroller products. The |
||
| 71 | software is owned by the Company and/or its supplier, and is |
||
| 72 | protected under applicable copyright laws. All rights are reserved. |
||
| 73 | Any use in violation of the foregoing restrictions may subject the |
||
| 74 | user to criminal sanctions under applicable laws, as well as to |
||
| 75 | civil liability for the breach of the terms and conditions of this |
||
| 76 | license. |
||
| 77 | |||
| 78 | THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
||
| 79 | WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
||
| 80 | TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
||
| 81 | PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
||
| 82 | IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
||
| 83 | CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
||
| 84 | |||
| 85 | *************************************************************************/ |
||
| 86 | |||
| 87 | //DOM-IGNORE-BEGIN |
||
| 88 | /******************************************************************** |
||
| 89 | Change History: |
||
| 90 | Rev Description |
||
| 91 | ---- ----------- |
||
| 92 | 2.7 Created USBSleepOnSuspend() function to simply process of putting |
||
| 93 | the PIC24F device in the correct state before issuing the sleep |
||
| 94 | instruction and returning the device to the correct state after |
||
| 95 | exiting sleep. |
||
| 96 | |||
| 97 | 2.7a Fixed issue where the USBSleepOnSuspend() function would cause |
||
| 98 | the USB communication to fail after being called when _IPL |
||
| 99 | is equal to 0. |
||
| 100 | ********************************************************************/ |
||
| 101 | //DOM-IGNORE-END |
||
| 102 | |||
| 103 | #ifndef USB_HAL_PIC24F_C |
||
| 104 | #define USB_HAL_PIC24F_C |
||
| 105 | |||
| 106 | #include "USB\usb.h" |
||
| 107 | |||
| 108 | |||
| 109 | /************************************************************************* |
||
| 110 | Function: |
||
| 111 | BOOL USBSleepOnSuspend(void) |
||
| 112 | Summary: |
||
| 113 | Places the PIC24F devices in sleep after enabling the USB activity flag to |
||
| 114 | wake it back up. |
||
| 115 | Conditions: |
||
| 116 | IPL (in the SR register) must be non-zero. |
||
| 117 | Input: |
||
| 118 | None |
||
| 119 | Return: |
||
| 120 | TRUE - if entered sleep successfully |
||
| 121 | FALSE - if there was an error entering sleep |
||
| 122 | Remarks: |
||
| 123 | None |
||
| 124 | *************************************************************************/ |
||
| 125 | BOOL USBSleepOnSuspend(void) |
||
| 126 | { |
||
| 127 | unsigned int U1EIE_save, U1IE_save, U1OTGIE_save; |
||
| 128 | unsigned char USB1IE_save; |
||
| 129 | |||
| 130 | #if defined(USB_POLLING) |
||
| 131 | //If IPL is equal to 0 then there is no way for the USB module to |
||
| 132 | // generate an interrupt to wake up the device. |
||
| 133 | if(_IPL == 0) |
||
| 134 | { |
||
| 135 | return FALSE; |
||
| 136 | } |
||
| 137 | |||
| 138 | //Set the interrupt priority to a level that will wake up the part (>0) |
||
| 139 | // but will not cause a interrupt vector jump (USB1IP<=IPL) |
||
| 140 | _USB1IP = 1; |
||
| 141 | #endif |
||
| 142 | |||
| 143 | //Save the old interrupt and CPU settings |
||
| 144 | U1EIE_save = U1EIE; |
||
| 145 | U1IE_save = U1IE; |
||
| 146 | U1OTGIE_save = U1OTGIE; |
||
| 147 | USB1IE_save = IEC5bits.USB1IE; |
||
| 148 | |||
| 149 | //Disable all USB interrupts |
||
| 150 | U1EIE = 0; |
||
| 151 | U1IE = 0; |
||
| 152 | U1OTGIE = 0; |
||
| 153 | |||
| 154 | //Enable the interrupt |
||
| 155 | IFS5bits.USB1IF = 0; |
||
| 156 | U1OTGIEbits.ACTVIE = 1; |
||
| 157 | USBClearInterruptFlag(USBActivityIFReg,USBActivityIFBitNum); |
||
| 158 | IEC5bits.USB1IE = 1; |
||
| 159 | |||
| 160 | Sleep(); |
||
| 161 | |||
| 162 | #if defined(USB_POLLING) |
||
| 163 | //Disable the interrupt |
||
| 164 | _USB1IP = 0; |
||
| 165 | #endif |
||
| 166 | |||
| 167 | //restore the previous interrupt settings |
||
| 168 | IEC5bits.USB1IE = USB1IE_save; |
||
| 169 | U1EIE = U1EIE_save; |
||
| 170 | U1IE = U1IE_save; |
||
| 171 | U1OTGIE = U1OTGIE_save; |
||
| 172 | |||
| 173 | return TRUE; |
||
| 174 | } |
||
| 175 | |||
| 176 | #endif //USB_HAL_PIC24F_C |
||
| 177 |
Powered by WebSVN v2.8.3