Drone code for Prof. Coode

Dependencies:   C12832_lcd FatFileSystemCpp MMA7660 mbed

Fork of app-board-Bubble-Level by jim hamblen

Committer:
ecleland
Date:
Thu Sep 10 18:22:29 2015 +0000
Revision:
3:6dae4f871cdc
Drone Code for Prof. Cooke

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ecleland 3:6dae4f871cdc 1 /*
ecleland 3:6dae4f871cdc 2 **************************************************************************************************************
ecleland 3:6dae4f871cdc 3 * NXP USB Host Stack
ecleland 3:6dae4f871cdc 4 *
ecleland 3:6dae4f871cdc 5 * (c) Copyright 2008, NXP SemiConductors
ecleland 3:6dae4f871cdc 6 * (c) Copyright 2008, OnChip Technologies LLC
ecleland 3:6dae4f871cdc 7 * All Rights Reserved
ecleland 3:6dae4f871cdc 8 *
ecleland 3:6dae4f871cdc 9 * www.nxp.com
ecleland 3:6dae4f871cdc 10 * www.onchiptech.com
ecleland 3:6dae4f871cdc 11 *
ecleland 3:6dae4f871cdc 12 * File : usbhost_lpc17xx.h
ecleland 3:6dae4f871cdc 13 * Programmer(s) : Ravikanth.P
ecleland 3:6dae4f871cdc 14 * Version :
ecleland 3:6dae4f871cdc 15 *
ecleland 3:6dae4f871cdc 16 **************************************************************************************************************
ecleland 3:6dae4f871cdc 17 */
ecleland 3:6dae4f871cdc 18
ecleland 3:6dae4f871cdc 19 #ifndef USBHOST_LPC17xx_H
ecleland 3:6dae4f871cdc 20 #define USBHOST_LPC17xx_H
ecleland 3:6dae4f871cdc 21
ecleland 3:6dae4f871cdc 22 /*
ecleland 3:6dae4f871cdc 23 **************************************************************************************************************
ecleland 3:6dae4f871cdc 24 * INCLUDE HEADER FILES
ecleland 3:6dae4f871cdc 25 **************************************************************************************************************
ecleland 3:6dae4f871cdc 26 */
ecleland 3:6dae4f871cdc 27
ecleland 3:6dae4f871cdc 28 #include "usbhost_inc.h"
ecleland 3:6dae4f871cdc 29
ecleland 3:6dae4f871cdc 30 /*
ecleland 3:6dae4f871cdc 31 **************************************************************************************************************
ecleland 3:6dae4f871cdc 32 * PRINT CONFIGURATION
ecleland 3:6dae4f871cdc 33 **************************************************************************************************************
ecleland 3:6dae4f871cdc 34 */
ecleland 3:6dae4f871cdc 35
ecleland 3:6dae4f871cdc 36 #define PRINT_ENABLE 1
ecleland 3:6dae4f871cdc 37
ecleland 3:6dae4f871cdc 38 #if PRINT_ENABLE
ecleland 3:6dae4f871cdc 39 #define PRINT_Log(...) printf(__VA_ARGS__)
ecleland 3:6dae4f871cdc 40 #define PRINT_Err(rc) printf("ERROR: In %s at Line %u - rc = %d\n", __FUNCTION__, __LINE__, rc)
ecleland 3:6dae4f871cdc 41
ecleland 3:6dae4f871cdc 42 #else
ecleland 3:6dae4f871cdc 43 #define PRINT_Log(...) do {} while(0)
ecleland 3:6dae4f871cdc 44 #define PRINT_Err(rc) do {} while(0)
ecleland 3:6dae4f871cdc 45
ecleland 3:6dae4f871cdc 46 #endif
ecleland 3:6dae4f871cdc 47
ecleland 3:6dae4f871cdc 48 /*
ecleland 3:6dae4f871cdc 49 **************************************************************************************************************
ecleland 3:6dae4f871cdc 50 * GENERAL DEFINITIONS
ecleland 3:6dae4f871cdc 51 **************************************************************************************************************
ecleland 3:6dae4f871cdc 52 */
ecleland 3:6dae4f871cdc 53
ecleland 3:6dae4f871cdc 54 #define DESC_LENGTH(x) x[0]
ecleland 3:6dae4f871cdc 55 #define DESC_TYPE(x) x[1]
ecleland 3:6dae4f871cdc 56
ecleland 3:6dae4f871cdc 57
ecleland 3:6dae4f871cdc 58 #define HOST_GET_DESCRIPTOR(descType, descIndex, data, length) \
ecleland 3:6dae4f871cdc 59 Host_CtrlRecv(USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR, \
ecleland 3:6dae4f871cdc 60 (descType << 8)|(descIndex), 0, length, data)
ecleland 3:6dae4f871cdc 61
ecleland 3:6dae4f871cdc 62 #define HOST_SET_ADDRESS(new_addr) \
ecleland 3:6dae4f871cdc 63 Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_ADDRESS, \
ecleland 3:6dae4f871cdc 64 new_addr, 0, 0, NULL)
ecleland 3:6dae4f871cdc 65
ecleland 3:6dae4f871cdc 66 #define USBH_SET_CONFIGURATION(configNum) \
ecleland 3:6dae4f871cdc 67 Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_CONFIGURATION, \
ecleland 3:6dae4f871cdc 68 configNum, 0, 0, NULL)
ecleland 3:6dae4f871cdc 69
ecleland 3:6dae4f871cdc 70 #define USBH_SET_INTERFACE(ifNum, altNum) \
ecleland 3:6dae4f871cdc 71 Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE, SET_INTERFACE, \
ecleland 3:6dae4f871cdc 72 altNum, ifNum, 0, NULL)
ecleland 3:6dae4f871cdc 73
ecleland 3:6dae4f871cdc 74 /*
ecleland 3:6dae4f871cdc 75 **************************************************************************************************************
ecleland 3:6dae4f871cdc 76 * OHCI OPERATIONAL REGISTER FIELD DEFINITIONS
ecleland 3:6dae4f871cdc 77 **************************************************************************************************************
ecleland 3:6dae4f871cdc 78 */
ecleland 3:6dae4f871cdc 79
ecleland 3:6dae4f871cdc 80 /* ------------------ HcControl Register --------------------- */
ecleland 3:6dae4f871cdc 81 #define OR_CONTROL_CLE 0x00000010
ecleland 3:6dae4f871cdc 82 #define OR_CONTROL_BLE 0x00000020
ecleland 3:6dae4f871cdc 83 #define OR_CONTROL_HCFS 0x000000C0
ecleland 3:6dae4f871cdc 84 #define OR_CONTROL_HC_OPER 0x00000080
ecleland 3:6dae4f871cdc 85 /* ----------------- HcCommandStatus Register ----------------- */
ecleland 3:6dae4f871cdc 86 #define OR_CMD_STATUS_HCR 0x00000001
ecleland 3:6dae4f871cdc 87 #define OR_CMD_STATUS_CLF 0x00000002
ecleland 3:6dae4f871cdc 88 #define OR_CMD_STATUS_BLF 0x00000004
ecleland 3:6dae4f871cdc 89 /* --------------- HcInterruptStatus Register ----------------- */
ecleland 3:6dae4f871cdc 90 #define OR_INTR_STATUS_WDH 0x00000002
ecleland 3:6dae4f871cdc 91 #define OR_INTR_STATUS_RHSC 0x00000040
ecleland 3:6dae4f871cdc 92 /* --------------- HcInterruptEnable Register ----------------- */
ecleland 3:6dae4f871cdc 93 #define OR_INTR_ENABLE_WDH 0x00000002
ecleland 3:6dae4f871cdc 94 #define OR_INTR_ENABLE_RHSC 0x00000040
ecleland 3:6dae4f871cdc 95 #define OR_INTR_ENABLE_MIE 0x80000000
ecleland 3:6dae4f871cdc 96 /* ---------------- HcRhDescriptorA Register ------------------ */
ecleland 3:6dae4f871cdc 97 #define OR_RH_STATUS_LPSC 0x00010000
ecleland 3:6dae4f871cdc 98 #define OR_RH_STATUS_DRWE 0x00008000
ecleland 3:6dae4f871cdc 99 /* -------------- HcRhPortStatus[1:NDP] Register -------------- */
ecleland 3:6dae4f871cdc 100 #define OR_RH_PORT_CCS 0x00000001
ecleland 3:6dae4f871cdc 101 #define OR_RH_PORT_PRS 0x00000010
ecleland 3:6dae4f871cdc 102 #define OR_RH_PORT_CSC 0x00010000
ecleland 3:6dae4f871cdc 103 #define OR_RH_PORT_PRSC 0x00100000
ecleland 3:6dae4f871cdc 104
ecleland 3:6dae4f871cdc 105
ecleland 3:6dae4f871cdc 106 /*
ecleland 3:6dae4f871cdc 107 **************************************************************************************************************
ecleland 3:6dae4f871cdc 108 * FRAME INTERVAL
ecleland 3:6dae4f871cdc 109 **************************************************************************************************************
ecleland 3:6dae4f871cdc 110 */
ecleland 3:6dae4f871cdc 111
ecleland 3:6dae4f871cdc 112 #define FI 0x2EDF /* 12000 bits per frame (-1) */
ecleland 3:6dae4f871cdc 113 #define DEFAULT_FMINTERVAL ((((6 * (FI - 210)) / 7) << 16) | FI)
ecleland 3:6dae4f871cdc 114
ecleland 3:6dae4f871cdc 115 /*
ecleland 3:6dae4f871cdc 116 **************************************************************************************************************
ecleland 3:6dae4f871cdc 117 * TRANSFER DESCRIPTOR CONTROL FIELDS
ecleland 3:6dae4f871cdc 118 **************************************************************************************************************
ecleland 3:6dae4f871cdc 119 */
ecleland 3:6dae4f871cdc 120
ecleland 3:6dae4f871cdc 121 #define TD_ROUNDING (USB_INT32U) (0x00040000) /* Buffer Rounding */
ecleland 3:6dae4f871cdc 122 #define TD_SETUP (USB_INT32U)(0) /* Direction of Setup Packet */
ecleland 3:6dae4f871cdc 123 #define TD_IN (USB_INT32U)(0x00100000) /* Direction In */
ecleland 3:6dae4f871cdc 124 #define TD_OUT (USB_INT32U)(0x00080000) /* Direction Out */
ecleland 3:6dae4f871cdc 125 #define TD_DELAY_INT(x) (USB_INT32U)((x) << 21) /* Delay Interrupt */
ecleland 3:6dae4f871cdc 126 #define TD_TOGGLE_0 (USB_INT32U)(0x02000000) /* Toggle 0 */
ecleland 3:6dae4f871cdc 127 #define TD_TOGGLE_1 (USB_INT32U)(0x03000000) /* Toggle 1 */
ecleland 3:6dae4f871cdc 128 #define TD_CC (USB_INT32U)(0xF0000000) /* Completion Code */
ecleland 3:6dae4f871cdc 129
ecleland 3:6dae4f871cdc 130 /*
ecleland 3:6dae4f871cdc 131 **************************************************************************************************************
ecleland 3:6dae4f871cdc 132 * USB STANDARD REQUEST DEFINITIONS
ecleland 3:6dae4f871cdc 133 **************************************************************************************************************
ecleland 3:6dae4f871cdc 134 */
ecleland 3:6dae4f871cdc 135
ecleland 3:6dae4f871cdc 136 #define USB_DESCRIPTOR_TYPE_DEVICE 1
ecleland 3:6dae4f871cdc 137 #define USB_DESCRIPTOR_TYPE_CONFIGURATION 2
ecleland 3:6dae4f871cdc 138 #define USB_DESCRIPTOR_TYPE_INTERFACE 4
ecleland 3:6dae4f871cdc 139 #define USB_DESCRIPTOR_TYPE_ENDPOINT 5
ecleland 3:6dae4f871cdc 140 /* ----------- Control RequestType Fields ----------- */
ecleland 3:6dae4f871cdc 141 #define USB_DEVICE_TO_HOST 0x80
ecleland 3:6dae4f871cdc 142 #define USB_HOST_TO_DEVICE 0x00
ecleland 3:6dae4f871cdc 143 #define USB_REQUEST_TYPE_CLASS 0x20
ecleland 3:6dae4f871cdc 144 #define USB_RECIPIENT_DEVICE 0x00
ecleland 3:6dae4f871cdc 145 #define USB_RECIPIENT_INTERFACE 0x01
ecleland 3:6dae4f871cdc 146 /* -------------- USB Standard Requests -------------- */
ecleland 3:6dae4f871cdc 147 #define SET_ADDRESS 5
ecleland 3:6dae4f871cdc 148 #define GET_DESCRIPTOR 6
ecleland 3:6dae4f871cdc 149 #define SET_CONFIGURATION 9
ecleland 3:6dae4f871cdc 150 #define SET_INTERFACE 11
ecleland 3:6dae4f871cdc 151
ecleland 3:6dae4f871cdc 152 /*
ecleland 3:6dae4f871cdc 153 **************************************************************************************************************
ecleland 3:6dae4f871cdc 154 * TYPE DEFINITIONS
ecleland 3:6dae4f871cdc 155 **************************************************************************************************************
ecleland 3:6dae4f871cdc 156 */
ecleland 3:6dae4f871cdc 157
ecleland 3:6dae4f871cdc 158 typedef struct hcEd { /* ----------- HostController EndPoint Descriptor ------------- */
ecleland 3:6dae4f871cdc 159 volatile USB_INT32U Control; /* Endpoint descriptor control */
ecleland 3:6dae4f871cdc 160 volatile USB_INT32U TailTd; /* Physical address of tail in Transfer descriptor list */
ecleland 3:6dae4f871cdc 161 volatile USB_INT32U HeadTd; /* Physcial address of head in Transfer descriptor list */
ecleland 3:6dae4f871cdc 162 volatile USB_INT32U Next; /* Physical address of next Endpoint descriptor */
ecleland 3:6dae4f871cdc 163 } HCED;
ecleland 3:6dae4f871cdc 164
ecleland 3:6dae4f871cdc 165 typedef struct hcTd { /* ------------ HostController Transfer Descriptor ------------ */
ecleland 3:6dae4f871cdc 166 volatile USB_INT32U Control; /* Transfer descriptor control */
ecleland 3:6dae4f871cdc 167 volatile USB_INT32U CurrBufPtr; /* Physical address of current buffer pointer */
ecleland 3:6dae4f871cdc 168 volatile USB_INT32U Next; /* Physical pointer to next Transfer Descriptor */
ecleland 3:6dae4f871cdc 169 volatile USB_INT32U BufEnd; /* Physical address of end of buffer */
ecleland 3:6dae4f871cdc 170 } HCTD;
ecleland 3:6dae4f871cdc 171
ecleland 3:6dae4f871cdc 172 typedef struct hcca { /* ----------- Host Controller Communication Area ------------ */
ecleland 3:6dae4f871cdc 173 volatile USB_INT32U IntTable[32]; /* Interrupt Table */
ecleland 3:6dae4f871cdc 174 volatile USB_INT32U FrameNumber; /* Frame Number */
ecleland 3:6dae4f871cdc 175 volatile USB_INT32U DoneHead; /* Done Head */
ecleland 3:6dae4f871cdc 176 volatile USB_INT08U Reserved[116]; /* Reserved for future use */
ecleland 3:6dae4f871cdc 177 volatile USB_INT08U Unknown[4]; /* Unused */
ecleland 3:6dae4f871cdc 178 } HCCA;
ecleland 3:6dae4f871cdc 179
ecleland 3:6dae4f871cdc 180 /*
ecleland 3:6dae4f871cdc 181 **************************************************************************************************************
ecleland 3:6dae4f871cdc 182 * EXTERN DECLARATIONS
ecleland 3:6dae4f871cdc 183 **************************************************************************************************************
ecleland 3:6dae4f871cdc 184 */
ecleland 3:6dae4f871cdc 185
ecleland 3:6dae4f871cdc 186 extern volatile HCED *EDBulkIn; /* BulkIn endpoint descriptor structure */
ecleland 3:6dae4f871cdc 187 extern volatile HCED *EDBulkOut; /* BulkOut endpoint descriptor structure */
ecleland 3:6dae4f871cdc 188 extern volatile HCTD *TDHead; /* Head transfer descriptor structure */
ecleland 3:6dae4f871cdc 189 extern volatile HCTD *TDTail; /* Tail transfer descriptor structure */
ecleland 3:6dae4f871cdc 190 extern volatile USB_INT08U *TDBuffer; /* Current Buffer Pointer of transfer descriptor */
ecleland 3:6dae4f871cdc 191
ecleland 3:6dae4f871cdc 192 /*
ecleland 3:6dae4f871cdc 193 **************************************************************************************************************
ecleland 3:6dae4f871cdc 194 * FUNCTION PROTOTYPES
ecleland 3:6dae4f871cdc 195 **************************************************************************************************************
ecleland 3:6dae4f871cdc 196 */
ecleland 3:6dae4f871cdc 197
ecleland 3:6dae4f871cdc 198 void Host_Init (void);
ecleland 3:6dae4f871cdc 199
ecleland 3:6dae4f871cdc 200 extern "C" void USB_IRQHandler(void) __irq;
ecleland 3:6dae4f871cdc 201
ecleland 3:6dae4f871cdc 202 USB_INT32S Host_EnumDev (void);
ecleland 3:6dae4f871cdc 203
ecleland 3:6dae4f871cdc 204 USB_INT32S Host_ProcessTD(volatile HCED *ed,
ecleland 3:6dae4f871cdc 205 volatile USB_INT32U token,
ecleland 3:6dae4f871cdc 206 volatile USB_INT08U *buffer,
ecleland 3:6dae4f871cdc 207 USB_INT32U buffer_len);
ecleland 3:6dae4f871cdc 208
ecleland 3:6dae4f871cdc 209 void Host_DelayUS ( USB_INT32U delay);
ecleland 3:6dae4f871cdc 210 void Host_DelayMS ( USB_INT32U delay);
ecleland 3:6dae4f871cdc 211
ecleland 3:6dae4f871cdc 212
ecleland 3:6dae4f871cdc 213 void Host_TDInit (volatile HCTD *td);
ecleland 3:6dae4f871cdc 214 void Host_EDInit (volatile HCED *ed);
ecleland 3:6dae4f871cdc 215 void Host_HCCAInit (volatile HCCA *hcca);
ecleland 3:6dae4f871cdc 216
ecleland 3:6dae4f871cdc 217 USB_INT32S Host_CtrlRecv ( USB_INT08U bm_request_type,
ecleland 3:6dae4f871cdc 218 USB_INT08U b_request,
ecleland 3:6dae4f871cdc 219 USB_INT16U w_value,
ecleland 3:6dae4f871cdc 220 USB_INT16U w_index,
ecleland 3:6dae4f871cdc 221 USB_INT16U w_length,
ecleland 3:6dae4f871cdc 222 volatile USB_INT08U *buffer);
ecleland 3:6dae4f871cdc 223
ecleland 3:6dae4f871cdc 224 USB_INT32S Host_CtrlSend ( USB_INT08U bm_request_type,
ecleland 3:6dae4f871cdc 225 USB_INT08U b_request,
ecleland 3:6dae4f871cdc 226 USB_INT16U w_value,
ecleland 3:6dae4f871cdc 227 USB_INT16U w_index,
ecleland 3:6dae4f871cdc 228 USB_INT16U w_length,
ecleland 3:6dae4f871cdc 229 volatile USB_INT08U *buffer);
ecleland 3:6dae4f871cdc 230
ecleland 3:6dae4f871cdc 231 void Host_FillSetup( USB_INT08U bm_request_type,
ecleland 3:6dae4f871cdc 232 USB_INT08U b_request,
ecleland 3:6dae4f871cdc 233 USB_INT16U w_value,
ecleland 3:6dae4f871cdc 234 USB_INT16U w_index,
ecleland 3:6dae4f871cdc 235 USB_INT16U w_length);
ecleland 3:6dae4f871cdc 236
ecleland 3:6dae4f871cdc 237
ecleland 3:6dae4f871cdc 238 void Host_WDHWait (void);
ecleland 3:6dae4f871cdc 239
ecleland 3:6dae4f871cdc 240
ecleland 3:6dae4f871cdc 241 USB_INT32U ReadLE32U (volatile USB_INT08U *pmem);
ecleland 3:6dae4f871cdc 242 void WriteLE32U (volatile USB_INT08U *pmem,
ecleland 3:6dae4f871cdc 243 USB_INT32U val);
ecleland 3:6dae4f871cdc 244 USB_INT16U ReadLE16U (volatile USB_INT08U *pmem);
ecleland 3:6dae4f871cdc 245 void WriteLE16U (volatile USB_INT08U *pmem,
ecleland 3:6dae4f871cdc 246 USB_INT16U val);
ecleland 3:6dae4f871cdc 247 USB_INT32U ReadBE32U (volatile USB_INT08U *pmem);
ecleland 3:6dae4f871cdc 248 void WriteBE32U (volatile USB_INT08U *pmem,
ecleland 3:6dae4f871cdc 249 USB_INT32U val);
ecleland 3:6dae4f871cdc 250 USB_INT16U ReadBE16U (volatile USB_INT08U *pmem);
ecleland 3:6dae4f871cdc 251 void WriteBE16U (volatile USB_INT08U *pmem,
ecleland 3:6dae4f871cdc 252 USB_INT16U val);
ecleland 3:6dae4f871cdc 253
ecleland 3:6dae4f871cdc 254 #endif