KIT Solar Car Project / Mbed 2 deprecated BMS_6804_pb

Dependencies:   mbed INA226

Committer:
takuma1
Date:
Thu Apr 08 10:04:55 2021 +0000
Revision:
5:f07de56debf3
210408_BMS_v1;

Who changed what in which revision?

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