Lines Matching refs:context

35 static void smartcard_emvsim_CompleteSendData(EMVSIM_Type *base, smartcard_context_t *context);
36 static void smartcard_emvsim_StartSendData(EMVSIM_Type *base, smartcard_context_t *context);
37 static void smartcard_emvsim_CompleteReceiveData(EMVSIM_Type *base, smartcard_context_t *context);
38 static void smartcard_emvsim_StartReceiveData(EMVSIM_Type *base, smartcard_context_t *context);
40 smartcard_context_t *context,
77 static void smartcard_emvsim_CompleteSendData(EMVSIM_Type *base, smartcard_context_t *context) in smartcard_emvsim_CompleteSendData() argument
79 assert((NULL != context)); in smartcard_emvsim_CompleteSendData()
91 context->xIsBusy = false; in smartcard_emvsim_CompleteSendData()
92 context->transferState = kSMARTCARD_IdleState; in smartcard_emvsim_CompleteSendData()
94 context->xSize = 0u; in smartcard_emvsim_CompleteSendData()
96 if (NULL != context->transferCallback) in smartcard_emvsim_CompleteSendData()
98 context->transferCallback(context, context->transferCallbackParam); in smartcard_emvsim_CompleteSendData()
108 static void smartcard_emvsim_CompleteReceiveData(EMVSIM_Type *base, smartcard_context_t *context) in smartcard_emvsim_CompleteReceiveData() argument
110 assert((NULL != context)); in smartcard_emvsim_CompleteReceiveData()
116 while (((base->RX_STATUS & EMVSIM_RX_STATUS_RX_CNT_MASK) != 0u) && ((context->xSize) > 0u)) in smartcard_emvsim_CompleteReceiveData()
119 *context->xBuff = (uint8_t)(base->RX_BUF); in smartcard_emvsim_CompleteReceiveData()
120 ++context->xBuff; in smartcard_emvsim_CompleteReceiveData()
121 --context->xSize; in smartcard_emvsim_CompleteReceiveData()
125 context->xIsBusy = false; in smartcard_emvsim_CompleteReceiveData()
127 if (NULL != context->transferCallback) in smartcard_emvsim_CompleteReceiveData()
129 context->transferCallback(context, context->transferCallbackParam); in smartcard_emvsim_CompleteReceiveData()
139 static void smartcard_emvsim_StartSendData(EMVSIM_Type *base, smartcard_context_t *context) in smartcard_emvsim_StartSendData() argument
141 assert((NULL != context)); in smartcard_emvsim_StartSendData()
152 base->TX_GETU = context->cardParams.GTN; in smartcard_emvsim_StartSendData()
174 context->transferState = kSMARTCARD_TransmittingState; in smartcard_emvsim_StartSendData()
175 context->xIsBusy = true; in smartcard_emvsim_StartSendData()
196 static void smartcard_emvsim_StartReceiveData(EMVSIM_Type *base, smartcard_context_t *context) in smartcard_emvsim_StartReceiveData() argument
198 assert((NULL != context)); in smartcard_emvsim_StartReceiveData()
201 context->xIsBusy = true; in smartcard_emvsim_StartReceiveData()
211 if (context->xSize < context->rxFifoThreshold) in smartcard_emvsim_StartReceiveData()
215 rx_thd |= context->xSize; in smartcard_emvsim_StartReceiveData()
220 base->RX_THD = ((base->RX_THD & ~EMVSIM_RX_THD_RDT_MASK) | context->rxFifoThreshold); in smartcard_emvsim_StartReceiveData()
226 if (context->tType == kSMARTCARD_T1Transport) in smartcard_emvsim_StartReceiveData()
241 smartcard_context_t *context, in smartcard_emvsim_SetTransferType() argument
244 assert((NULL != context)); in smartcard_emvsim_SetTransferType()
258 context->cardParams.Fi = 372u; in smartcard_emvsim_SetTransferType()
259 context->cardParams.Di = 1u; in smartcard_emvsim_SetTransferType()
260 context->cardParams.currentD = 1u; in smartcard_emvsim_SetTransferType()
261 context->cardParams.WI = 0x0Au; in smartcard_emvsim_SetTransferType()
262 context->cardParams.GTN = 0x00u; in smartcard_emvsim_SetTransferType()
264 … base->DIVISOR = (((uint32_t)context->cardParams.Fi / context->cardParams.currentD) & 0x1FFu); in smartcard_emvsim_SetTransferType()
267 temp16 = (960u * context->cardParams.currentD * context->cardParams.WI) + in smartcard_emvsim_SetTransferType()
268 (context->cardParams.currentD * 480u) + SMARTCARD_WWT_ADJUSTMENT; in smartcard_emvsim_SetTransferType()
274 base->TX_GETU = context->cardParams.GTN; in smartcard_emvsim_SetTransferType()
286 context->tType = kSMARTCARD_T0Transport; in smartcard_emvsim_SetTransferType()
298 temp16 = (960u * context->cardParams.currentD * context->cardParams.WI) + in smartcard_emvsim_SetTransferType()
299 (context->cardParams.currentD * 480u) + SMARTCARD_WWT_ADJUSTMENT; in smartcard_emvsim_SetTransferType()
306context->cardParams.GTN = (context->cardParams.GTN == 0xFFu) ? 0x00u : context->cardParams.GTN; in smartcard_emvsim_SetTransferType()
307 base->TX_GETU = context->cardParams.GTN; in smartcard_emvsim_SetTransferType()
320 context->tType = kSMARTCARD_T0Transport; in smartcard_emvsim_SetTransferType()
329 …bwiVal = 11u + ((((uint32_t)1u << context->cardParams.BWI) + 1u) * 960u * context->cardParams.curr… in smartcard_emvsim_SetTransferType()
338 if (context->cardParams.currentD == 1u) in smartcard_emvsim_SetTransferType()
341 temp16 = ((uint16_t)1u << context->cardParams.CWI) + 16u; in smartcard_emvsim_SetTransferType()
343 temp16 = ((uint16_t)1u << context->cardParams.CWI) + 15u; in smartcard_emvsim_SetTransferType()
349 temp16 = ((uint16_t)1u << context->cardParams.CWI) + 20u + SMARTCARD_CWT_ADJUSTMENT; in smartcard_emvsim_SetTransferType()
351 temp16 = ((uint16_t)1u << context->cardParams.CWI) + 15u + SMARTCARD_CWT_ADJUSTMENT; in smartcard_emvsim_SetTransferType()
358 context->cardParams.BGI = 22u; in smartcard_emvsim_SetTransferType()
359 base->BGT_VAL = context->cardParams.BGI; in smartcard_emvsim_SetTransferType()
363 base->TX_GETU = context->cardParams.GTN; in smartcard_emvsim_SetTransferType()
373 context->tType = kSMARTCARD_T1Transport; in smartcard_emvsim_SetTransferType()
414 status_t SMARTCARD_EMVSIM_Init(EMVSIM_Type *base, smartcard_context_t *context, uint32_t srcClock_H… in SMARTCARD_EMVSIM_Init() argument
418 if ((NULL == context) || (srcClock_Hz == 0u)) in SMARTCARD_EMVSIM_Init()
432 context->base = base; in SMARTCARD_EMVSIM_Init()
448 smartcard_emvsim_SetTransferType(base, context, kSMARTCARD_SetupATRMode); in SMARTCARD_EMVSIM_Init()
450 context->txFifoEntryCount = in SMARTCARD_EMVSIM_Init()
453 context->rxFifoThreshold = in SMARTCARD_EMVSIM_Init()
455 if ((EMVSIM_RX_THD_RDT_MASK >> EMVSIM_RX_THD_RDT_SHIFT) < context->rxFifoThreshold) in SMARTCARD_EMVSIM_Init()
457 context->rxFifoThreshold = (EMVSIM_RX_THD_RDT_MASK >> EMVSIM_RX_THD_RDT_SHIFT); in SMARTCARD_EMVSIM_Init()
525 status_t SMARTCARD_EMVSIM_TransferNonBlocking(EMVSIM_Type *base, smartcard_context_t *context, smar… in SMARTCARD_EMVSIM_TransferNonBlocking() argument
527 if ((NULL == context) || (NULL == xfer) || (xfer->buff == NULL)) in SMARTCARD_EMVSIM_TransferNonBlocking()
538 if (0 != SMARTCARD_EMVSIM_GetTransferRemainingBytes(base, context)) in SMARTCARD_EMVSIM_TransferNonBlocking()
540 if (kSMARTCARD_Receive == context->direction) in SMARTCARD_EMVSIM_TransferNonBlocking()
550 context->rxtCrossed = false; in SMARTCARD_EMVSIM_TransferNonBlocking()
551 context->txtCrossed = false; in SMARTCARD_EMVSIM_TransferNonBlocking()
552 context->parityError = false; in SMARTCARD_EMVSIM_TransferNonBlocking()
554 context->xBuff = xfer->buff; in SMARTCARD_EMVSIM_TransferNonBlocking()
555 context->xSize = xfer->size; in SMARTCARD_EMVSIM_TransferNonBlocking()
559 context->direction = xfer->direction; in SMARTCARD_EMVSIM_TransferNonBlocking()
560 context->transferState = kSMARTCARD_ReceivingState; in SMARTCARD_EMVSIM_TransferNonBlocking()
562 smartcard_emvsim_StartReceiveData(base, context); in SMARTCARD_EMVSIM_TransferNonBlocking()
566 context->direction = xfer->direction; in SMARTCARD_EMVSIM_TransferNonBlocking()
567 context->transferState = kSMARTCARD_TransmittingState; in SMARTCARD_EMVSIM_TransferNonBlocking()
569 smartcard_emvsim_StartSendData(base, context); in SMARTCARD_EMVSIM_TransferNonBlocking()
592 int32_t SMARTCARD_EMVSIM_GetTransferRemainingBytes(EMVSIM_Type *base, smartcard_context_t *context) in SMARTCARD_EMVSIM_GetTransferRemainingBytes() argument
594 if ((NULL == context)) in SMARTCARD_EMVSIM_GetTransferRemainingBytes()
598 if (context->xIsBusy) in SMARTCARD_EMVSIM_GetTransferRemainingBytes()
600 if (context->direction == kSMARTCARD_Transmit) in SMARTCARD_EMVSIM_GetTransferRemainingBytes()
604 count = context->xSize; in SMARTCARD_EMVSIM_GetTransferRemainingBytes()
608 return (int32_t)context->xSize; in SMARTCARD_EMVSIM_GetTransferRemainingBytes()
625 status_t SMARTCARD_EMVSIM_AbortTransfer(EMVSIM_Type *base, smartcard_context_t *context) in SMARTCARD_EMVSIM_AbortTransfer() argument
627 if ((NULL == context)) in SMARTCARD_EMVSIM_AbortTransfer()
632 context->abortTransfer = true; in SMARTCARD_EMVSIM_AbortTransfer()
635 if ((!context->xIsBusy)) in SMARTCARD_EMVSIM_AbortTransfer()
640 if (kSMARTCARD_Receive == context->direction) in SMARTCARD_EMVSIM_AbortTransfer()
642 smartcard_emvsim_CompleteReceiveData(base, context); in SMARTCARD_EMVSIM_AbortTransfer()
644 else if (kSMARTCARD_Transmit == context->direction) in SMARTCARD_EMVSIM_AbortTransfer()
646 smartcard_emvsim_CompleteSendData(base, context); in SMARTCARD_EMVSIM_AbortTransfer()
662 void SMARTCARD_EMVSIM_IRQHandler(EMVSIM_Type *base, smartcard_context_t *context) in SMARTCARD_EMVSIM_IRQHandler() argument
664 if (NULL == context) in SMARTCARD_EMVSIM_IRQHandler()
692 if (NULL != context->interfaceCallback) in SMARTCARD_EMVSIM_IRQHandler()
694 context->interfaceCallback(context, context->interfaceCallbackParam); in SMARTCARD_EMVSIM_IRQHandler()
704 context->timersState.initCharTimerExpired = true; in SMARTCARD_EMVSIM_IRQHandler()
711 context->transferState = kSMARTCARD_IdleState; in SMARTCARD_EMVSIM_IRQHandler()
713 smartcard_emvsim_CompleteReceiveData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
724 context->timersState.adtExpired = true; in SMARTCARD_EMVSIM_IRQHandler()
726 smartcard_emvsim_CompleteReceiveData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
737 context->parityError = true; in SMARTCARD_EMVSIM_IRQHandler()
744 context->txtCrossed = true; in SMARTCARD_EMVSIM_IRQHandler()
750 smartcard_emvsim_CompleteSendData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
756 context->rxtCrossed = true; in SMARTCARD_EMVSIM_IRQHandler()
759 if (context->xIsBusy) in SMARTCARD_EMVSIM_IRQHandler()
761 smartcard_emvsim_CompleteReceiveData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
775 context->transferState = kSMARTCARD_IdleState; in SMARTCARD_EMVSIM_IRQHandler()
777 if (kSMARTCARD_T0Transport == context->tType) in SMARTCARD_EMVSIM_IRQHandler()
779 context->timersState.wwtExpired = true; in SMARTCARD_EMVSIM_IRQHandler()
783 context->timersState.cwtExpired = true; in SMARTCARD_EMVSIM_IRQHandler()
785 if (context->xIsBusy) in SMARTCARD_EMVSIM_IRQHandler()
787 smartcard_emvsim_CompleteReceiveData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
802 if (kSMARTCARD_T0Transport == context->tType) in SMARTCARD_EMVSIM_IRQHandler()
804 context->timersState.wwtExpired = true; in SMARTCARD_EMVSIM_IRQHandler()
808 context->timersState.bwtExpired = true; in SMARTCARD_EMVSIM_IRQHandler()
811 if (context->wtxRequested) in SMARTCARD_EMVSIM_IRQHandler()
813 (void)SMARTCARD_EMVSIM_Control(base, context, kSMARTCARD_ResetWaitTimeMultiplier, 1u); in SMARTCARD_EMVSIM_IRQHandler()
815 if (context->xIsBusy) in SMARTCARD_EMVSIM_IRQHandler()
817 smartcard_emvsim_CompleteReceiveData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
826 if ((context->tType == kSMARTCARD_T1Transport) && (context->xSize > 0u) && in SMARTCARD_EMVSIM_IRQHandler()
829 context->timersState.cwtExpired = false; in SMARTCARD_EMVSIM_IRQHandler()
845 if (kSMARTCARD_WaitingForTSState == context->transferState) in SMARTCARD_EMVSIM_IRQHandler()
852 context->transferState = kSMARTCARD_InvalidTSDetecetedState; in SMARTCARD_EMVSIM_IRQHandler()
856 context->transferState = kSMARTCARD_ReceivingState; in SMARTCARD_EMVSIM_IRQHandler()
858 context->cardParams.convention = in SMARTCARD_EMVSIM_IRQHandler()
861 if (kSMARTCARD_InvalidTSDetecetedState == context->transferState) in SMARTCARD_EMVSIM_IRQHandler()
865 smartcard_emvsim_CompleteReceiveData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
867 if (kSMARTCARD_ReceivingState == context->transferState) in SMARTCARD_EMVSIM_IRQHandler()
875 smartcard_emvsim_CompleteReceiveData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
881 while (((base->RX_STATUS & EMVSIM_RX_STATUS_RX_CNT_MASK) != 0u) && ((context->xSize) > 0u)) in SMARTCARD_EMVSIM_IRQHandler()
884 *context->xBuff = (uint8_t)(base->RX_BUF); in SMARTCARD_EMVSIM_IRQHandler()
885 ++context->xBuff; in SMARTCARD_EMVSIM_IRQHandler()
886 --context->xSize; in SMARTCARD_EMVSIM_IRQHandler()
890 if (context->xSize == 0u) in SMARTCARD_EMVSIM_IRQHandler()
892 smartcard_emvsim_CompleteReceiveData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
898 if (context->xSize < context->rxFifoThreshold) in SMARTCARD_EMVSIM_IRQHandler()
903 rx_thd |= context->xSize; in SMARTCARD_EMVSIM_IRQHandler()
913 smartcard_emvsim_CompleteSendData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
920 if (context->xSize == 0u) in SMARTCARD_EMVSIM_IRQHandler()
922 smartcard_emvsim_CompleteSendData(base, context); in SMARTCARD_EMVSIM_IRQHandler()
925 if (context->xSize == 1u) in SMARTCARD_EMVSIM_IRQHandler()
933 base->TX_BUF = *(context->xBuff); in SMARTCARD_EMVSIM_IRQHandler()
934 ++context->xBuff; in SMARTCARD_EMVSIM_IRQHandler()
935 --context->xSize; in SMARTCARD_EMVSIM_IRQHandler()
946 … while (((context->txFifoEntryCount - (uint8_t)((base->TX_STATUS & EMVSIM_TX_STATUS_TX_CNT_MASK) >> in SMARTCARD_EMVSIM_IRQHandler()
948 (context->xSize > getu_tail)) in SMARTCARD_EMVSIM_IRQHandler()
951 base->TX_BUF = *(context->xBuff); in SMARTCARD_EMVSIM_IRQHandler()
952 ++context->xBuff; in SMARTCARD_EMVSIM_IRQHandler()
953 --context->xSize; in SMARTCARD_EMVSIM_IRQHandler()
956 if (context->xSize == 0u) in SMARTCARD_EMVSIM_IRQHandler()
982 smartcard_context_t *context, in SMARTCARD_EMVSIM_Control() argument
986 if ((NULL == context)) in SMARTCARD_EMVSIM_Control()
1068 context->transferState = kSMARTCARD_WaitingForTSState; in SMARTCARD_EMVSIM_Control()
1083 … base->DIVISOR = (((uint32_t)context->cardParams.Fi / context->cardParams.currentD) & 0x1FFu); in SMARTCARD_EMVSIM_Control()
1087 smartcard_emvsim_SetTransferType(base, context, kSMARTCARD_SetupATRMode); in SMARTCARD_EMVSIM_Control()
1091 smartcard_emvsim_SetTransferType(base, context, kSMARTCARD_SetupT0Mode); in SMARTCARD_EMVSIM_Control()
1095 smartcard_emvsim_SetTransferType(base, context, kSMARTCARD_SetupT1Mode); in SMARTCARD_EMVSIM_Control()
1122 … (11u + ((((uint32_t)1u << context->cardParams.BWI) + 1u) * 960u * context->cardParams.currentD)); in SMARTCARD_EMVSIM_Control()
1124 temp32 += context->cardParams.currentD * 50; in SMARTCARD_EMVSIM_Control()
1130 context->wtxRequested = true; in SMARTCARD_EMVSIM_Control()
1134 context->wtxRequested = false; in SMARTCARD_EMVSIM_Control()