-
Notifications
You must be signed in to change notification settings - Fork 1
/
ISO7816_timing_calc_functions.c
93 lines (76 loc) · 1.98 KB
/
ISO7816_timing_calc_functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Universal.h"
#include "iso7816.h"
//#include <math.h>
uint16_t F=372;
uint16_t D=1;
uint16_t ETU =16;
uint8_t IFCS=32;
uint8_t CWI =13;
uint8_t BWI =4 ;
uint8_t WI =10;
uint8_t PSS =1;
uint8_t LRC =1;
uint8_t CRC =0;
float work_ETU;
float WT;
float CWT;
float BWT;
//Default values
//F = 372 ; D = 1 ; I = 50 ; P = 5 ; N = 0
//LRC
void Set_Default_Timing_Params() {
ATR_ETU=372;
F =372;
D =1;
ETU =372;
IFCS=32;
CWI =13;
BWI =4 ;
WI =10;
PSS =1;
LRC =1;
CRC =0;
}
#define INT_CLK 0
uint16_t Calc_Cycles_ETU(uint8_t di, uint8_t fi) {
uint16_t ETU;
if(fi==INT_CLK) {
//work etu = (1/D)*(1/9600) [s]
return 0;
}
else {
//work etu = (1/D)*(F/fs) s
//value= ( 1/Bit_rate_adjustment_factor_D[di] ) * (Clock_rate_conversion_factor_F[fi]/ ISO7816_CLK );
ETU= ( Clock_rate_conversion_factor_F[fi] ) / (Bit_rate_adjustment_factor_D[di] );
Segger_write_string_int("\t Clock_rate_conversion_factor_F:\t", Clock_rate_conversion_factor_F[fi]);
Segger_write_string_int("\t Bit_rate_adjustment_factor_D:\t", Bit_rate_adjustment_factor_D[di]);
Segger_write_string_int("\t Calculated ETU divisor for clock:\t", ETU);
Segger_write_string_int("\t Calculated Baudrate:\t\t\t", ISO7816_CLK/ETU);
return ETU;
}
//baudrate=clock_freq(should fs)/etu
}
uint16_t Calc_Default_Cycles_ETU(void) {
return Calc_Cycles_ETU(1, 1);
}
/*
float Calc_WT_Wait_Time() {
return (float)((float)WI*(float)960*(float)(F/(float)ISO7816_CLK) * work_ETU);
}
float Calc_CWT_Character_Wait_Time() {
return (float)((float)((11 + (float)(pow((float)2, (int) CWI))) * (float) work_ETU));
}
float Calc_BWT_Block_Wait_Time() {
return (float)( 11 * work_ETU + (float)pow((float)2, (int) BWI) * 960 * F/ISO7816_CLK);
}
float Calc_Work_ETU() {
return (float)((float)F*(float)(D / (float) ISO7816_CLK));
return SYSCLK/ETU;
}
*/
void Calc_ALL_Times() {
//work_ETU = Calc_Work_ETU();
//WT = Calc_WT_Wait_Time();
//CWT = Calc_CWT_Character_Wait_Time();
//BWT = Calc_BWT_Block_Wait_Time();
}