2 ******************************************************************************
4 * @author MCD Application Team
7 * @brief Interface functions to USB cell registers
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
17 * http://www.st.com/software_license_agreement_liberty_v2
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
25 ******************************************************************************
28 /* Includes ------------------------------------------------------------------*/
31 /* Private typedef -----------------------------------------------------------*/
32 /* Private define ------------------------------------------------------------*/
33 /* Private macro -------------------------------------------------------------*/
34 /* Private variables ---------------------------------------------------------*/
35 /* Extern variables ----------------------------------------------------------*/
36 /* Private function prototypes -----------------------------------------------*/
37 /* Private functions ---------------------------------------------------------*/
39 /*******************************************************************************
40 * Function Name : SetCNTR.
41 * Description : Set the CNTR register value.
42 * Input : wRegValue: new register value.
45 *******************************************************************************/
46 void SetCNTR(uint16_t wRegValue
)
51 /*******************************************************************************
52 * Function Name : GetCNTR.
53 * Description : returns the CNTR register value.
56 * Return : CNTR register Value.
57 *******************************************************************************/
58 uint16_t GetCNTR(void)
63 /*******************************************************************************
64 * Function Name : SetISTR.
65 * Description : Set the ISTR register value.
66 * Input : wRegValue: new register value.
69 *******************************************************************************/
70 void SetISTR(uint16_t wRegValue
)
75 /*******************************************************************************
76 * Function Name : GetISTR
77 * Description : Returns the ISTR register value.
80 * Return : ISTR register Value
81 *******************************************************************************/
82 uint16_t GetISTR(void)
87 /*******************************************************************************
88 * Function Name : GetFNR
89 * Description : Returns the FNR register value.
92 * Return : FNR register Value
93 *******************************************************************************/
99 /*******************************************************************************
100 * Function Name : SetDADDR
101 * Description : Set the DADDR register value.
102 * Input : wRegValue: new register value.
105 *******************************************************************************/
106 void SetDADDR(uint16_t wRegValue
)
108 _SetDADDR(wRegValue
);
111 /*******************************************************************************
112 * Function Name : GetDADDR
113 * Description : Returns the DADDR register value.
116 * Return : DADDR register Value
117 *******************************************************************************/
118 uint16_t GetDADDR(void)
123 /*******************************************************************************
124 * Function Name : SetBTABLE
125 * Description : Set the BTABLE.
126 * Input : wRegValue: New register value.
129 *******************************************************************************/
130 void SetBTABLE(uint16_t wRegValue
)
132 _SetBTABLE(wRegValue
);
135 /*******************************************************************************
136 * Function Name : GetBTABLE.
137 * Description : Returns the BTABLE register value.
140 * Return : BTABLE address.
141 *******************************************************************************/
142 uint16_t GetBTABLE(void)
144 return(_GetBTABLE());
147 /*******************************************************************************
148 * Function Name : SetENDPOINT
149 * Description : Set the Endpoint register value.
150 * Input : bEpNum: Endpoint Number.
154 *******************************************************************************/
155 void SetENDPOINT(uint8_t bEpNum
, uint16_t wRegValue
)
157 _SetENDPOINT(bEpNum
, wRegValue
);
160 /*******************************************************************************
161 * Function Name : GetENDPOINT
162 * Description : Return the Endpoint register value.
163 * Input : bEpNum: Endpoint Number.
165 * Return : Endpoint register value.
166 *******************************************************************************/
167 uint16_t GetENDPOINT(uint8_t bEpNum
)
169 return(_GetENDPOINT(bEpNum
));
172 /*******************************************************************************
173 * Function Name : SetEPType
174 * Description : sets the type in the endpoint register.
175 * Input : bEpNum: Endpoint Number.
176 * wType: type definition.
179 *******************************************************************************/
180 void SetEPType(uint8_t bEpNum
, uint16_t wType
)
182 _SetEPType(bEpNum
, wType
);
185 /*******************************************************************************
186 * Function Name : GetEPType
187 * Description : Returns the endpoint type.
188 * Input : bEpNum: Endpoint Number.
190 * Return : Endpoint Type
191 *******************************************************************************/
192 uint16_t GetEPType(uint8_t bEpNum
)
194 return(_GetEPType(bEpNum
));
197 /*******************************************************************************
198 * Function Name : SetEPTxStatus
199 * Description : Set the status of Tx endpoint.
200 * Input : bEpNum: Endpoint Number.
204 *******************************************************************************/
205 void SetEPTxStatus(uint8_t bEpNum
, uint16_t wState
)
207 _SetEPTxStatus(bEpNum
, wState
);
210 /*******************************************************************************
211 * Function Name : SetEPRxStatus
212 * Description : Set the status of Rx endpoint.
213 * Input : bEpNum: Endpoint Number.
217 *******************************************************************************/
218 void SetEPRxStatus(uint8_t bEpNum
, uint16_t wState
)
220 _SetEPRxStatus(bEpNum
, wState
);
223 /*******************************************************************************
224 * Function Name : SetDouBleBuffEPStall
225 * Description : sets the status for Double Buffer Endpoint to STALL
226 * Input : bEpNum: Endpoint Number.
227 * bDir: Endpoint direction.
230 *******************************************************************************/
231 void SetDouBleBuffEPStall(uint8_t bEpNum
, uint8_t bDir
)
233 uint16_t Endpoint_DTOG_Status
;
234 Endpoint_DTOG_Status
= GetENDPOINT(bEpNum
);
235 if (bDir
== EP_DBUF_OUT
)
236 { /* OUT double buffered endpoint */
237 _SetENDPOINT(bEpNum
, Endpoint_DTOG_Status
& ~EPRX_DTOG1
);
239 else if (bDir
== EP_DBUF_IN
)
240 { /* IN double buffered endpoint */
241 _SetENDPOINT(bEpNum
, Endpoint_DTOG_Status
& ~EPTX_DTOG1
);
245 /*******************************************************************************
246 * Function Name : GetEPTxStatus
247 * Description : Returns the endpoint Tx status.
248 * Input : bEpNum: Endpoint Number.
250 * Return : Endpoint TX Status
251 *******************************************************************************/
252 uint16_t GetEPTxStatus(uint8_t bEpNum
)
254 return(_GetEPTxStatus(bEpNum
));
257 /*******************************************************************************
258 * Function Name : GetEPRxStatus
259 * Description : Returns the endpoint Rx status.
260 * Input : bEpNum: Endpoint Number.
262 * Return : Endpoint RX Status
263 *******************************************************************************/
264 uint16_t GetEPRxStatus(uint8_t bEpNum
)
266 return(_GetEPRxStatus(bEpNum
));
269 /*******************************************************************************
270 * Function Name : SetEPTxValid
271 * Description : Valid the endpoint Tx Status.
272 * Input : bEpNum: Endpoint Number.
275 *******************************************************************************/
276 void SetEPTxValid(uint8_t bEpNum
)
278 _SetEPTxStatus(bEpNum
, EP_TX_VALID
);
281 /*******************************************************************************
282 * Function Name : SetEPRxValid
283 * Description : Valid the endpoint Rx Status.
284 * Input : bEpNum: Endpoint Number.
287 *******************************************************************************/
288 void SetEPRxValid(uint8_t bEpNum
)
290 _SetEPRxStatus(bEpNum
, EP_RX_VALID
);
293 /*******************************************************************************
294 * Function Name : SetEP_KIND
295 * Description : Clear the EP_KIND bit.
296 * Input : bEpNum: Endpoint Number.
299 *******************************************************************************/
300 void SetEP_KIND(uint8_t bEpNum
)
305 /*******************************************************************************
306 * Function Name : ClearEP_KIND
307 * Description : set the EP_KIND bit.
308 * Input : bEpNum: Endpoint Number.
311 *******************************************************************************/
312 void ClearEP_KIND(uint8_t bEpNum
)
314 _ClearEP_KIND(bEpNum
);
316 /*******************************************************************************
317 * Function Name : Clear_Status_Out
318 * Description : Clear the Status Out of the related Endpoint
319 * Input : bEpNum: Endpoint Number.
322 *******************************************************************************/
323 void Clear_Status_Out(uint8_t bEpNum
)
325 _ClearEP_KIND(bEpNum
);
327 /*******************************************************************************
328 * Function Name : Set_Status_Out
329 * Description : Set the Status Out of the related Endpoint
330 * Input : bEpNum: Endpoint Number.
333 *******************************************************************************/
334 void Set_Status_Out(uint8_t bEpNum
)
338 /*******************************************************************************
339 * Function Name : SetEPDoubleBuff
340 * Description : Enable the double buffer feature for the endpoint.
341 * Input : bEpNum: Endpoint Number.
344 *******************************************************************************/
345 void SetEPDoubleBuff(uint8_t bEpNum
)
349 /*******************************************************************************
350 * Function Name : ClearEPDoubleBuff
351 * Description : Disable the double buffer feature for the endpoint.
352 * Input : bEpNum: Endpoint Number.
355 *******************************************************************************/
356 void ClearEPDoubleBuff(uint8_t bEpNum
)
358 _ClearEP_KIND(bEpNum
);
360 /*******************************************************************************
361 * Function Name : GetTxStallStatus
362 * Description : Returns the Stall status of the Tx endpoint.
363 * Input : bEpNum: Endpoint Number.
365 * Return : Tx Stall status.
366 *******************************************************************************/
367 uint16_t GetTxStallStatus(uint8_t bEpNum
)
369 return(_GetTxStallStatus(bEpNum
));
371 /*******************************************************************************
372 * Function Name : GetRxStallStatus
373 * Description : Returns the Stall status of the Rx endpoint.
374 * Input : bEpNum: Endpoint Number.
376 * Return : Rx Stall status.
377 *******************************************************************************/
378 uint16_t GetRxStallStatus(uint8_t bEpNum
)
380 return(_GetRxStallStatus(bEpNum
));
382 /*******************************************************************************
383 * Function Name : ClearEP_CTR_RX
384 * Description : Clear the CTR_RX bit.
385 * Input : bEpNum: Endpoint Number.
388 *******************************************************************************/
389 void ClearEP_CTR_RX(uint8_t bEpNum
)
391 _ClearEP_CTR_RX(bEpNum
);
393 /*******************************************************************************
394 * Function Name : ClearEP_CTR_TX
395 * Description : Clear the CTR_TX bit.
396 * Input : bEpNum: Endpoint Number.
399 *******************************************************************************/
400 void ClearEP_CTR_TX(uint8_t bEpNum
)
402 _ClearEP_CTR_TX(bEpNum
);
404 /*******************************************************************************
405 * Function Name : ToggleDTOG_RX
406 * Description : Toggle the DTOG_RX bit.
407 * Input : bEpNum: Endpoint Number.
410 *******************************************************************************/
411 void ToggleDTOG_RX(uint8_t bEpNum
)
413 _ToggleDTOG_RX(bEpNum
);
415 /*******************************************************************************
416 * Function Name : ToggleDTOG_TX
417 * Description : Toggle the DTOG_TX bit.
418 * Input : bEpNum: Endpoint Number.
421 *******************************************************************************/
422 void ToggleDTOG_TX(uint8_t bEpNum
)
424 _ToggleDTOG_TX(bEpNum
);
426 /*******************************************************************************
427 * Function Name : ClearDTOG_RX.
428 * Description : Clear the DTOG_RX bit.
429 * Input : bEpNum: Endpoint Number.
432 *******************************************************************************/
433 void ClearDTOG_RX(uint8_t bEpNum
)
435 _ClearDTOG_RX(bEpNum
);
437 /*******************************************************************************
438 * Function Name : ClearDTOG_TX.
439 * Description : Clear the DTOG_TX bit.
440 * Input : bEpNum: Endpoint Number.
443 *******************************************************************************/
444 void ClearDTOG_TX(uint8_t bEpNum
)
446 _ClearDTOG_TX(bEpNum
);
448 /*******************************************************************************
449 * Function Name : SetEPAddress
450 * Description : Set the endpoint address.
451 * Input : bEpNum: Endpoint Number.
452 * bAddr: New endpoint address.
455 *******************************************************************************/
456 void SetEPAddress(uint8_t bEpNum
, uint8_t bAddr
)
458 _SetEPAddress(bEpNum
, bAddr
);
460 /*******************************************************************************
461 * Function Name : GetEPAddress
462 * Description : Get the endpoint address.
463 * Input : bEpNum: Endpoint Number.
465 * Return : Endpoint address.
466 *******************************************************************************/
467 uint8_t GetEPAddress(uint8_t bEpNum
)
469 return(_GetEPAddress(bEpNum
));
471 /*******************************************************************************
472 * Function Name : SetEPTxAddr
473 * Description : Set the endpoint Tx buffer address.
474 * Input : bEpNum: Endpoint Number.
475 * wAddr: new address.
478 *******************************************************************************/
479 void SetEPTxAddr(uint8_t bEpNum
, uint16_t wAddr
)
481 _SetEPTxAddr(bEpNum
, wAddr
);
483 /*******************************************************************************
484 * Function Name : SetEPRxAddr
485 * Description : Set the endpoint Rx buffer address.
486 * Input : bEpNum: Endpoint Number.
487 * wAddr: new address.
490 *******************************************************************************/
491 void SetEPRxAddr(uint8_t bEpNum
, uint16_t wAddr
)
493 _SetEPRxAddr(bEpNum
, wAddr
);
495 /*******************************************************************************
496 * Function Name : GetEPTxAddr
497 * Description : Returns the endpoint Tx buffer address.
498 * Input : bEpNum: Endpoint Number.
500 * Return : Rx buffer address.
501 *******************************************************************************/
502 uint16_t GetEPTxAddr(uint8_t bEpNum
)
504 return(_GetEPTxAddr(bEpNum
));
506 /*******************************************************************************
507 * Function Name : GetEPRxAddr.
508 * Description : Returns the endpoint Rx buffer address.
509 * Input : bEpNum: Endpoint Number.
511 * Return : Rx buffer address.
512 *******************************************************************************/
513 uint16_t GetEPRxAddr(uint8_t bEpNum
)
515 return(_GetEPRxAddr(bEpNum
));
517 /*******************************************************************************
518 * Function Name : SetEPTxCount.
519 * Description : Set the Tx count.
520 * Input : bEpNum: Endpoint Number.
521 * wCount: new count value.
524 *******************************************************************************/
525 void SetEPTxCount(uint8_t bEpNum
, uint16_t wCount
)
527 _SetEPTxCount(bEpNum
, wCount
);
529 /*******************************************************************************
530 * Function Name : SetEPCountRxReg.
531 * Description : Set the Count Rx Register value.
532 * Input : *pdwReg: point to the register.
533 * wCount: the new register value.
536 *******************************************************************************/
537 void SetEPCountRxReg(uint32_t *pdwReg
, uint16_t wCount
)
539 _SetEPCountRxReg(dwReg
, wCount
);
541 /*******************************************************************************
542 * Function Name : SetEPRxCount
543 * Description : Set the Rx count.
544 * Input : bEpNum: Endpoint Number.
545 * wCount: the new count value.
548 *******************************************************************************/
549 void SetEPRxCount(uint8_t bEpNum
, uint16_t wCount
)
551 _SetEPRxCount(bEpNum
, wCount
);
553 /*******************************************************************************
554 * Function Name : GetEPTxCount
555 * Description : Get the Tx count.
556 * Input : bEpNum: Endpoint Number.
558 * Return : Tx count value.
559 *******************************************************************************/
560 uint16_t GetEPTxCount(uint8_t bEpNum
)
562 return(_GetEPTxCount(bEpNum
));
564 /*******************************************************************************
565 * Function Name : GetEPRxCount
566 * Description : Get the Rx count.
567 * Input : bEpNum: Endpoint Number.
569 * Return : Rx count value.
570 *******************************************************************************/
571 uint16_t GetEPRxCount(uint8_t bEpNum
)
573 return(_GetEPRxCount(bEpNum
));
575 /*******************************************************************************
576 * Function Name : SetEPDblBuffAddr
577 * Description : Set the addresses of the buffer 0 and 1.
578 * Input : bEpNum: Endpoint Number.
579 * wBuf0Addr: new address of buffer 0.
580 * wBuf1Addr: new address of buffer 1.
583 *******************************************************************************/
584 void SetEPDblBuffAddr(uint8_t bEpNum
, uint16_t wBuf0Addr
, uint16_t wBuf1Addr
)
586 _SetEPDblBuffAddr(bEpNum
, wBuf0Addr
, wBuf1Addr
);
588 /*******************************************************************************
589 * Function Name : SetEPDblBuf0Addr
590 * Description : Set the Buffer 1 address.
591 * Input : bEpNum: Endpoint Number
592 * wBuf0Addr: new address.
595 *******************************************************************************/
596 void SetEPDblBuf0Addr(uint8_t bEpNum
, uint16_t wBuf0Addr
)
598 _SetEPDblBuf0Addr(bEpNum
, wBuf0Addr
);
600 /*******************************************************************************
601 * Function Name : SetEPDblBuf1Addr
602 * Description : Set the Buffer 1 address.
603 * Input : bEpNum: Endpoint Number
604 * wBuf1Addr: new address.
607 *******************************************************************************/
608 void SetEPDblBuf1Addr(uint8_t bEpNum
, uint16_t wBuf1Addr
)
610 _SetEPDblBuf1Addr(bEpNum
, wBuf1Addr
);
612 /*******************************************************************************
613 * Function Name : GetEPDblBuf0Addr
614 * Description : Returns the address of the Buffer 0.
615 * Input : bEpNum: Endpoint Number.
618 *******************************************************************************/
619 uint16_t GetEPDblBuf0Addr(uint8_t bEpNum
)
621 return(_GetEPDblBuf0Addr(bEpNum
));
623 /*******************************************************************************
624 * Function Name : GetEPDblBuf1Addr
625 * Description : Returns the address of the Buffer 1.
626 * Input : bEpNum: Endpoint Number.
628 * Return : Address of the Buffer 1.
629 *******************************************************************************/
630 uint16_t GetEPDblBuf1Addr(uint8_t bEpNum
)
632 return(_GetEPDblBuf1Addr(bEpNum
));
634 /*******************************************************************************
635 * Function Name : SetEPDblBuffCount
636 * Description : Set the number of bytes for a double Buffer
638 * Input : bEpNum,bDir, wCount
641 *******************************************************************************/
642 void SetEPDblBuffCount(uint8_t bEpNum
, uint8_t bDir
, uint16_t wCount
)
644 _SetEPDblBuffCount(bEpNum
, bDir
, wCount
);
646 /*******************************************************************************
647 * Function Name : SetEPDblBuf0Count
648 * Description : Set the number of bytes in the buffer 0 of a double Buffer
650 * Input : bEpNum, bDir, wCount
653 *******************************************************************************/
654 void SetEPDblBuf0Count(uint8_t bEpNum
, uint8_t bDir
, uint16_t wCount
)
656 _SetEPDblBuf0Count(bEpNum
, bDir
, wCount
);
658 /*******************************************************************************
659 * Function Name : SetEPDblBuf1Count
660 * Description : Set the number of bytes in the buffer 0 of a double Buffer
662 * Input : bEpNum, bDir, wCount
665 *******************************************************************************/
666 void SetEPDblBuf1Count(uint8_t bEpNum
, uint8_t bDir
, uint16_t wCount
)
668 _SetEPDblBuf1Count(bEpNum
, bDir
, wCount
);
670 /*******************************************************************************
671 * Function Name : GetEPDblBuf0Count
672 * Description : Returns the number of byte received in the buffer 0 of a double
674 * Input : bEpNum: Endpoint Number.
676 * Return : Endpoint Buffer 0 count
677 *******************************************************************************/
678 uint16_t GetEPDblBuf0Count(uint8_t bEpNum
)
680 return(_GetEPDblBuf0Count(bEpNum
));
682 /*******************************************************************************
683 * Function Name : GetEPDblBuf1Count
684 * Description : Returns the number of data received in the buffer 1 of a double
686 * Input : bEpNum: Endpoint Number.
688 * Return : Endpoint Buffer 1 count.
689 *******************************************************************************/
690 uint16_t GetEPDblBuf1Count(uint8_t bEpNum
)
692 return(_GetEPDblBuf1Count(bEpNum
));
694 /*******************************************************************************
695 * Function Name : GetEPDblBufDir
696 * Description : gets direction of the double buffered endpoint
697 * Input : bEpNum: Endpoint Number.
699 * Return : EP_DBUF_OUT, EP_DBUF_IN,
700 * EP_DBUF_ERR if the endpoint counter not yet programmed.
701 *******************************************************************************/
702 EP_DBUF_DIR
GetEPDblBufDir(uint8_t bEpNum
)
704 if ((uint16_t)(*_pEPRxCount(bEpNum
) & 0xFC00) != 0)
706 else if (((uint16_t)(*_pEPTxCount(bEpNum
)) & 0x03FF) != 0)
711 /*******************************************************************************
712 * Function Name : FreeUserBuffer
713 * Description : free buffer used from the application realizing it to the line
714 toggles bit SW_BUF in the double buffered endpoint register
715 * Input : bEpNum, bDir
718 *******************************************************************************/
719 void FreeUserBuffer(uint8_t bEpNum
, uint8_t bDir
)
721 if (bDir
== EP_DBUF_OUT
)
722 { /* OUT double buffered endpoint */
723 _ToggleDTOG_TX(bEpNum
);
725 else if (bDir
== EP_DBUF_IN
)
726 { /* IN double buffered endpoint */
727 _ToggleDTOG_RX(bEpNum
);
731 /*******************************************************************************
732 * Function Name : ToWord
733 * Description : merge two byte in a word.
734 * Input : bh: byte high, bl: bytes low.
736 * Return : resulted word.
737 *******************************************************************************/
738 uint16_t ToWord(uint8_t bh
, uint8_t bl
)
741 wRet
= (uint16_t)bl
| ((uint16_t)bh
<< 8);
744 /*******************************************************************************
745 * Function Name : ByteSwap
746 * Description : Swap two byte in a word.
747 * Input : wSwW: word to Swap.
749 * Return : resulted word.
750 *******************************************************************************/
751 uint16_t ByteSwap(uint16_t wSwW
)
755 bTemp
= (uint8_t)(wSwW
& 0xff);
756 wRet
= (wSwW
>> 8) | ((uint16_t)bTemp
<< 8);
760 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/