Changeset 1286 for trunk/csctapi/protocol_t1.c
- Timestamp:
- 01/19/10 12:28:04 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/csctapi/protocol_t1.c
r1283 r1286 31 31 32 32 /* 33 * Not exported constants definition34 */35 #define PROTOCOL_T1_DEFAULT_IFSC 3236 #define PROTOCOL_T1_DEFAULT_IFSD 3237 #define PROTOCOL_T1_MAX_IFSC 251 /* Cannot send > 255 buffer */38 #define PROTOCOL_T1_DEFAULT_CWI 1339 #define PROTOCOL_T1_DEFAULT_BWI 440 #define PROTOCOL_T1_EDC_LRC 041 #define PROTOCOL_T1_EDC_CRC 142 43 /*44 33 * Not exported functions declaration 45 34 */ … … 57 46 * Exproted funtions definition 58 47 */ 59 60 int61 Protocol_T1_Init (int selected_protocol)62 {63 BYTE ta, tb, tc, cwi, bwi;64 unsigned long baudrate;65 double work_etu;66 int i;67 68 /* Set IFSC */69 if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TA, &ta) == ATR_NOT_FOUND)70 ifsc = PROTOCOL_T1_DEFAULT_IFSC;71 else if ((ta != 0x00) && (ta != 0xFF))72 ifsc = ta;73 else74 ifsc = PROTOCOL_T1_DEFAULT_IFSC;75 76 /* Towitoko does not allow IFSC > 251 */77 ifsc = MIN (ifsc, PROTOCOL_T1_MAX_IFSC);78 79 /* Set IFSD */80 ifsd = PROTOCOL_T1_DEFAULT_IFSD;81 82 #ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS83 /* Calculate CWI and BWI */84 if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TB, &tb) == ATR_NOT_FOUND)85 {86 #endif87 cwi = PROTOCOL_T1_DEFAULT_CWI;88 bwi = PROTOCOL_T1_DEFAULT_BWI;89 #ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS90 }91 else92 {93 cwi = tb & 0x0F;94 bwi = (tb & 0xF0) >> 4;95 }96 #endif97 98 /* Work etu = (1000 / baudrate) milliseconds */99 ICC_Async_GetBaudrate (&baudrate);100 work_etu = 1000 / (double)baudrate;101 102 /* Set CWT = (2^CWI + 11) work etu */103 cwt = 1;104 105 for (i = 0; i < cwi ; i++)106 cwt *= 2;107 108 cwt = (unsigned short) ((cwt + 11) * work_etu);109 110 /* Set BWT = (2^BWI * 960 + 11) work etu */111 bwt = 1;112 for (i = 0; i < bwi; i++)113 bwt *= 2;114 115 bwt = (unsigned short) ((bwt * 960 + 11) * work_etu);116 117 /* Set BGT = 22 * work etu */118 bgt = (unsigned short) (22 * work_etu);119 120 /* Set the error detection code type */121 if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &tc) == ATR_NOT_FOUND)122 edc = PROTOCOL_T1_EDC_LRC;123 else124 edc = tc & 0x01;125 126 /* Set initial send sequence (NS) */127 ns = 1;128 129 /* Set timings */130 icc_timings.block_timeout = bwt;131 icc_timings.char_timeout = cwt;132 icc_timings.block_delay = bgt;133 ICC_Async_SetTimings ();134 135 #ifdef DEBUG_PROTOCOL136 printf ("Protocol: T=1: IFSC=%d, IFSD=%d, CWT=%d, BWT=%d, BGT=%d, EDC=%s\n",137 ifsc, ifsd, cwt, bwt, t1->bgt,138 (edc == PROTOCOL_T1_EDC_LRC) ? "LRC" : "CRC");139 #endif140 141 return PROTOCOL_T1_OK;142 }143 48 144 49 int
Note:
See TracChangeset
for help on using the changeset viewer.