Programme d'une sonde de température DHT 11 associée à de la sauvegarde de données sur clé USB et à l'affichage de ces données sur afficheur LCD

Dependencies:   FatFileSystemCpp mbed

Committer:
Fanta025
Date:
Tue Jun 02 14:19:54 2015 +0000
Revision:
0:ed0b4e66d2ad
Programme d'une sonde de temp?rature DHT 11 associ?e ? de la sauvegarde de donn?es sur USB et un affichage sur ?cran LCD

Who changed what in which revision?

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