#include "../mscbemb.h"#include "temp36_SST_handler.h"Functions | |
| unsigned char | FCS_Step (unsigned int msg, unsigned char fcs) reentrant |
| void | SST_Init (int SST_LINE) |
| void | SST_Clear (int SST_LINE) |
| void | SST_DrvHigh (int SST_LINE) |
| void | SST_DrvLow (int SST_LINE) |
| unsigned char | SST_DrvClientResponse (int SST_LINE) |
| void | SST_WriteByte (unsigned char datByte, int SST_LINE) |
| unsigned char | SST_ReadByte (int SST_LINE) |
Variables | |
| sbit | SST1 = MSCB_SST1 |
| sbit | SST2 = MSCB_SST2 |
| unsigned char code | FCS_data [] |
| unsigned char FCS_Step | ( | unsigned int | msg, | |
| unsigned char | fcs | |||
| ) |
Single calculation for 8-bit cyclic redundancy checksum usually used in FORWARD recursive format (to save code-space) Reentrant function /code
/endcode
| msg | ||
| fcs |
00073 { 00074 return FCS_data[(msg ^ fcs)]; 00075 }
| void SST_Clear | ( | int | SST_LINE | ) |
| unsigned char SST_DrvClientResponse | ( | int | SST_LINE | ) |
Get the comparator bit value (Client response)
00158 { 00159 00160 // Drive SST to logic "0" (high 1/4, low 3/4) to let Client 00161 // drive SST to its desired state 00162 if(SST_LINE==1) 00163 { 00164 SST1 = 1; //Drv high (originator drives SST bus high to toggle client's response 00165 delay_us (1); 00166 SST1 = 0; 00167 00168 delay_us(T_BIT / 2.0); //delay for half of T_BIT time 00169 00170 #if defined(CPU_C8051F120) 00171 SFRPAGE = CPT1_PAGE; 00172 #endif 00173 if(SST_ClientResponse1 == 1) 00174 //if the comparator output is high, then return 1 00175 { 00176 delay_us(2 * T_H0); 00177 return 1; 00178 } 00179 else 00180 //if the comparator output is low, then return 0 00181 { 00182 delay_us(2 * T_H0); 00183 return 0; 00184 } 00185 } 00186 else if(SST_LINE==2) 00187 { 00188 SST2 = 1; //Drv high (originator drives SST bus high to toggle client's response 00189 delay_us (1); 00190 SST2 = 0; 00191 00192 delay_us(T_BIT / 2.0); //delay for half of T_BIT time 00193 00194 #if defined(CPU_C8051F120) 00195 SFRPAGE = CPT0_PAGE; 00196 #endif 00197 if(SST_ClientResponse2 == 1) 00198 //if the comparator output is high, then return 1 00199 { 00200 delay_us(2 * T_H0); 00201 return 1; 00202 } 00203 else 00204 //if the comparator output is low, then return 0 00205 { 00206 delay_us(2 * T_H0); 00207 return 0; 00208 } 00209 } 00210 }
| void SST_DrvHigh | ( | int | SST_LINE | ) |
Drives SST line to a logic "high" or "1", which is defined as driving SST high 3/4 cycle of t_Bit and the rest of it low
00108 { 00109 // Drive high for 0.75 * T_BIT 00110 if(SST_LINE==1) 00111 { 00112 SST1 = 1; 00113 delay_us(T_H1); 00114 SST1 = 0; //drive the rest of T_BIT low 00115 delay_us(T_BIT - T_H1); 00116 } 00117 else if(SST_LINE==2) 00118 { 00119 SST2 = 1; 00120 delay_us(T_H1); 00121 SST2 = 0; //drive the rest of T_BIT low 00122 delay_us(T_BIT - T_H1); 00123 } 00124 00125 00126 }
| void SST_DrvLow | ( | int | SST_LINE | ) |
To drive SST line to a logic "low" or "0", which is defined as driving SST high for 1/4 cycle of t_Bit and the rest of it low.
00134 { 00135 // Drive high for 0.25 * T_BIT 00136 if(SST_LINE==1) 00137 { 00138 SST1 = 1; 00139 delay_us(T_H0); 00140 SST1 = 0; //drive the rest of T_BIT low 00141 delay_us(T_BIT - T_H0); 00142 } 00143 else if(SST_LINE==2) 00144 { 00145 SST2 = 1; 00146 delay_us(T_H0); 00147 SST2 = 0; //drive the rest of T_BIT low 00148 delay_us(T_BIT - T_H0); 00149 } 00150 }
| void SST_Init | ( | int | SST_LINE | ) |
| unsigned char SST_ReadByte | ( | int | SST_LINE | ) |
Read a single byte from the SST device.
00270 { 00271 unsigned char din = 0; 00272 unsigned char dataReceived = 0; 00273 signed char j = 0; 00274 00275 for(j = 7; j >= 0; j--) { 00276 // Get single bit from comparator 00277 din = SST_DrvClientResponse(SST_LINE); 00278 dataReceived |= (din << j); 00279 } 00280 return dataReceived; 00281 }
| void SST_WriteByte | ( | unsigned char | datByte, | |
| int | SST_LINE | |||
| ) |
Write a single byte to the SST device.
| datByte |
00218 { 00219 //declare local variables 00220 unsigned char toBeDrv = 0; 00221 int i = 0; 00222 SST_LINE &= 0xFF; 00223 00224 if(SST_LINE==1) 00225 { 00226 for(i = 7; i >= 0; i--) //8bits in 1 byte 00227 { 00228 toBeDrv = (datByte >> i) & 0x1; 00229 if(toBeDrv == 0) //if the bit to be driven is logic 0 00230 { 00231 SST_DrvLow(SST_LINE); 00232 } 00233 else if(toBeDrv == 1) //if the bit to be driven is logic 1 00234 { 00235 SST_DrvHigh(SST_LINE); 00236 } 00237 else //if the bit to be driven is neither 0 nor 1 00238 { 00239 return; //error 00240 } 00241 } 00242 } 00243 else if(SST_LINE==2) 00244 { 00245 for(i = 7; i >= 0; i--) //8bits in 1 byte 00246 { 00247 toBeDrv = (datByte >> i) & 0x1; 00248 if(toBeDrv == 0) //if the bit to be driven is logic 0 00249 { 00250 SST_DrvLow(SST_LINE); 00251 } 00252 else if(toBeDrv == 1) //if the bit to be driven is logic 1 00253 { 00254 SST_DrvHigh(SST_LINE); 00255 } 00256 else //if the bit to be driven is neither 0 nor 1 00257 { 00258 return; //error 00259 } 00260 } 00261 } 00262 }
| unsigned char code FCS_data[] |
| sbit SST1 = MSCB_SST1 |
| sbit SST2 = MSCB_SST2 |
1.4.7