X2D lib first commit

Committer:
sev2000
Date:
Sun Nov 10 17:03:20 2019 +0000
Revision:
4:844c00dd0366
Parent:
1:265edb6bdd52
Child:
5:dcbebd42186a
Add 7540 init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sev2000 0:9ef8edfe21bc 1 #include "mbed.h"
sev2000 0:9ef8edfe21bc 2 #include "X2D.h"
sev2000 0:9ef8edfe21bc 3
sev2000 0:9ef8edfe21bc 4 #define BUF_SIZE 1000
sev2000 0:9ef8edfe21bc 5 #define BIT_SIZE 145
sev2000 0:9ef8edfe21bc 6
sev2000 0:9ef8edfe21bc 7 int processData(void);
sev2000 0:9ef8edfe21bc 8
sev2000 0:9ef8edfe21bc 9 DigitalOut Reg_Data(PC_1);
sev2000 0:9ef8edfe21bc 10 DigitalOut RxTx(PB_0);
sev2000 0:9ef8edfe21bc 11 DigitalOut Tx(PA_9);
sev2000 0:9ef8edfe21bc 12 DigitalOut UART(PA_0, 1);
sev2000 0:9ef8edfe21bc 13
sev2000 0:9ef8edfe21bc 14 DigitalIn CD(PC_0);
sev2000 0:9ef8edfe21bc 15 //DigitalIn Rx(PB_7);
sev2000 0:9ef8edfe21bc 16 DigitalIn BU(PA_4);
sev2000 0:9ef8edfe21bc 17 DigitalIn CLR(PA_1);
sev2000 0:9ef8edfe21bc 18 DigitalIn RSTO(PC_2);
sev2000 0:9ef8edfe21bc 19
sev2000 4:844c00dd0366 20 InterruptIn Rx(PB_7, PullUp);
sev2000 0:9ef8edfe21bc 21
sev2000 0:9ef8edfe21bc 22 pulse_t timeDiff;
sev2000 0:9ef8edfe21bc 23 CircularBuffer<pulse_t, BUF_SIZE> PulseWidth;
sev2000 0:9ef8edfe21bc 24 bool dataBits[BIT_SIZE]={0}; // 18 Nibbles +1
sev2000 0:9ef8edfe21bc 25
sev2000 0:9ef8edfe21bc 26
sev2000 0:9ef8edfe21bc 27 long startedAt=0;
sev2000 0:9ef8edfe21bc 28 long endedAt=0;
sev2000 0:9ef8edfe21bc 29
sev2000 0:9ef8edfe21bc 30 Timer xTime;
sev2000 0:9ef8edfe21bc 31
sev2000 0:9ef8edfe21bc 32 void getPulseF(void)
sev2000 0:9ef8edfe21bc 33 {
sev2000 0:9ef8edfe21bc 34 endedAt = xTime.read_us(); // set timer end for last pin
sev2000 0:9ef8edfe21bc 35 timeDiff.v = endedAt - startedAt;
sev2000 0:9ef8edfe21bc 36 timeDiff.pin = 1;
sev2000 0:9ef8edfe21bc 37 PulseWidth.push(timeDiff);
sev2000 0:9ef8edfe21bc 38 startedAt= endedAt; // set timer start for this pin
sev2000 0:9ef8edfe21bc 39 }
sev2000 0:9ef8edfe21bc 40
sev2000 0:9ef8edfe21bc 41 void getPulseR(void)
sev2000 0:9ef8edfe21bc 42 {
sev2000 0:9ef8edfe21bc 43 endedAt = xTime.read_us(); // set timer end for last pin
sev2000 0:9ef8edfe21bc 44 timeDiff.v = endedAt - startedAt;
sev2000 0:9ef8edfe21bc 45 timeDiff.pin = 0;
sev2000 0:9ef8edfe21bc 46 PulseWidth.push(timeDiff);
sev2000 0:9ef8edfe21bc 47 startedAt= endedAt; // set timer start for this pin
sev2000 0:9ef8edfe21bc 48 }
sev2000 0:9ef8edfe21bc 49
sev2000 4:844c00dd0366 50 void wait_posedge(void)
sev2000 4:844c00dd0366 51 {
sev2000 4:844c00dd0366 52 if(CLR != 0)
sev2000 4:844c00dd0366 53 {
sev2000 4:844c00dd0366 54 while(CLR != 0) ;
sev2000 4:844c00dd0366 55 }
sev2000 4:844c00dd0366 56 else ;
sev2000 4:844c00dd0366 57 while(CLR == 0) ;
sev2000 4:844c00dd0366 58 }
sev2000 4:844c00dd0366 59
sev2000 4:844c00dd0366 60 void wait_negedge(void)
sev2000 4:844c00dd0366 61 {
sev2000 4:844c00dd0366 62 if(CLR == 0)
sev2000 4:844c00dd0366 63 {
sev2000 4:844c00dd0366 64 while(CLR == 0) ;
sev2000 4:844c00dd0366 65 }
sev2000 4:844c00dd0366 66 else ;
sev2000 4:844c00dd0366 67 while(CLR != 0) ;
sev2000 4:844c00dd0366 68 }
sev2000 4:844c00dd0366 69
sev2000 4:844c00dd0366 70 unsigned long read_ctrl_reg(void)
sev2000 4:844c00dd0366 71 {
sev2000 4:844c00dd0366 72 unsigned long return_value = 0;
sev2000 4:844c00dd0366 73 unsigned long curr_bit = 0 ;
sev2000 4:844c00dd0366 74 int i ;
sev2000 4:844c00dd0366 75
sev2000 4:844c00dd0366 76 RxTx = 1;
sev2000 4:844c00dd0366 77 //Reg_Data = 0;
sev2000 4:844c00dd0366 78 wait_posedge();
sev2000 4:844c00dd0366 79 //wait_ms(10);
sev2000 4:844c00dd0366 80 Reg_Data = 1;
sev2000 4:844c00dd0366 81 RxTx = 1;
sev2000 4:844c00dd0366 82
sev2000 4:844c00dd0366 83 for(i=0;i<=23;i++)
sev2000 4:844c00dd0366 84 {
sev2000 4:844c00dd0366 85 //DBG("i= %d", i);
sev2000 4:844c00dd0366 86 wait_posedge();
sev2000 4:844c00dd0366 87 curr_bit = Rx ;
sev2000 4:844c00dd0366 88 return_value |= ((curr_bit) << (23-i)) ;
sev2000 4:844c00dd0366 89 }
sev2000 4:844c00dd0366 90 //wait_negedge();
sev2000 4:844c00dd0366 91
sev2000 4:844c00dd0366 92 Reg_Data = 0; //clr pin reg_data
sev2000 4:844c00dd0366 93
sev2000 4:844c00dd0366 94 wait(1) ;
sev2000 4:844c00dd0366 95 return return_value ;
sev2000 4:844c00dd0366 96 }
sev2000 4:844c00dd0366 97
sev2000 4:844c00dd0366 98 void write_ctrl_reg(unsigned long write_data)
sev2000 4:844c00dd0366 99 {
sev2000 4:844c00dd0366 100 int i ;
sev2000 4:844c00dd0366 101
sev2000 4:844c00dd0366 102 DBG("Write_reg = %X",write_data);
sev2000 4:844c00dd0366 103 wait_posedge(); //find posedge for Tcr
sev2000 4:844c00dd0366 104 Reg_Data = 1; //set pin reg_data
sev2000 4:844c00dd0366 105 RxTx = 0; //clr pin rxtx
sev2000 4:844c00dd0366 106 // wait_negedge();
sev2000 4:844c00dd0366 107 //delay(50) ; //delay for Tcc
sev2000 4:844c00dd0366 108
sev2000 4:844c00dd0366 109 for(i=0;i<=23;i++) //low code effciency may result in wrong writing
sev2000 4:844c00dd0366 110 {
sev2000 4:844c00dd0366 111 if(((write_data >> (23-i)) & 0x1) == 0)
sev2000 4:844c00dd0366 112 {
sev2000 4:844c00dd0366 113 Tx = 0;
sev2000 4:844c00dd0366 114 //DBGc("0");
sev2000 4:844c00dd0366 115 }
sev2000 4:844c00dd0366 116 else
sev2000 4:844c00dd0366 117 {
sev2000 4:844c00dd0366 118 Tx = 1;
sev2000 4:844c00dd0366 119 //DBGc("1");
sev2000 4:844c00dd0366 120 }
sev2000 4:844c00dd0366 121 wait_posedge();
sev2000 4:844c00dd0366 122 //wait_negedge();
sev2000 4:844c00dd0366 123 //wait_ms(32) ; //give enough hold time
sev2000 4:844c00dd0366 124 }
sev2000 4:844c00dd0366 125 RxTx = 1; //set pin rxtx
sev2000 4:844c00dd0366 126 Reg_Data = 0; //set pin reg_data
sev2000 4:844c00dd0366 127 Tx = 0;
sev2000 4:844c00dd0366 128 wait(0.1);
sev2000 4:844c00dd0366 129 }
sev2000 4:844c00dd0366 130
sev2000 1:265edb6bdd52 131 void SendBit(bool value)
sev2000 1:265edb6bdd52 132 {
sev2000 1:265edb6bdd52 133 // pc.printf("%d ", value);
sev2000 1:265edb6bdd52 134 Tx = !Tx;
sev2000 1:265edb6bdd52 135 if(value)
sev2000 1:265edb6bdd52 136 {
sev2000 1:265edb6bdd52 137 wait_us(800);
sev2000 1:265edb6bdd52 138 // pc.printf("%d, 800|", (int)Tx );
sev2000 1:265edb6bdd52 139 Tx = !Tx;
sev2000 1:265edb6bdd52 140 wait_us(800);
sev2000 1:265edb6bdd52 141 // pc.printf("%d, 800|", (int)Tx);
sev2000 1:265edb6bdd52 142 }
sev2000 1:265edb6bdd52 143 else
sev2000 1:265edb6bdd52 144 {
sev2000 1:265edb6bdd52 145 wait_us(1600);
sev2000 1:265edb6bdd52 146 // pc.printf("%d, 1600|", (int)Tx);
sev2000 1:265edb6bdd52 147 }
sev2000 1:265edb6bdd52 148 }
sev2000 1:265edb6bdd52 149
sev2000 1:265edb6bdd52 150 void SendByte(char value)
sev2000 1:265edb6bdd52 151 {
sev2000 1:265edb6bdd52 152 int i=0;
sev2000 1:265edb6bdd52 153 bool bit;
sev2000 1:265edb6bdd52 154 static char cnt=0;
sev2000 1:265edb6bdd52 155
sev2000 1:265edb6bdd52 156 pc.printf("%0.2X ", value);
sev2000 1:265edb6bdd52 157 for(i=0; i<8; i++)
sev2000 1:265edb6bdd52 158 {
sev2000 1:265edb6bdd52 159 bit = (bool)(0x01 & (value>>i)); // LSB first
sev2000 1:265edb6bdd52 160 SendBit(bit);
sev2000 1:265edb6bdd52 161 if(bit)
sev2000 1:265edb6bdd52 162 cnt++;
sev2000 1:265edb6bdd52 163 else
sev2000 1:265edb6bdd52 164 cnt=0;
sev2000 1:265edb6bdd52 165 if(cnt == 5)
sev2000 1:265edb6bdd52 166 SendBit(0);
sev2000 1:265edb6bdd52 167 }
sev2000 1:265edb6bdd52 168 }
sev2000 1:265edb6bdd52 169
sev2000 1:265edb6bdd52 170 void SendPreamble(void)
sev2000 1:265edb6bdd52 171 {
sev2000 1:265edb6bdd52 172 int i;
sev2000 1:265edb6bdd52 173
sev2000 1:265edb6bdd52 174 pc.printf("\r\n");
sev2000 1:265edb6bdd52 175 Tx=1;
sev2000 1:265edb6bdd52 176 for(i=0; i<17; i++)
sev2000 1:265edb6bdd52 177 SendBit(0);
sev2000 1:265edb6bdd52 178 for(i=0; i<6; i++)
sev2000 1:265edb6bdd52 179 SendBit(1);
sev2000 1:265edb6bdd52 180 SendBit(0);
sev2000 1:265edb6bdd52 181
sev2000 1:265edb6bdd52 182 }
sev2000 1:265edb6bdd52 183
sev2000 1:265edb6bdd52 184 void SendPostamble(void)
sev2000 1:265edb6bdd52 185 {
sev2000 1:265edb6bdd52 186 int i;
sev2000 1:265edb6bdd52 187
sev2000 1:265edb6bdd52 188 for(i=0; i<8; i++) // Send 0xFF
sev2000 1:265edb6bdd52 189 SendBit(1);
sev2000 1:265edb6bdd52 190 for(i=0; i<8; i++)
sev2000 1:265edb6bdd52 191 SendBit(0);
sev2000 1:265edb6bdd52 192
sev2000 1:265edb6bdd52 193 }
sev2000 1:265edb6bdd52 194
sev2000 1:265edb6bdd52 195 void SendFrame(char *data, int length)
sev2000 1:265edb6bdd52 196 {
sev2000 1:265edb6bdd52 197
sev2000 1:265edb6bdd52 198 int i, chksum=0;
sev2000 1:265edb6bdd52 199
sev2000 1:265edb6bdd52 200 RxTx = 0; //set pin rxtx to Tx
sev2000 1:265edb6bdd52 201 wait_ms(1);
sev2000 1:265edb6bdd52 202
sev2000 1:265edb6bdd52 203 SendPreamble();
sev2000 1:265edb6bdd52 204
sev2000 1:265edb6bdd52 205 for(i=0; i<length; i++)
sev2000 1:265edb6bdd52 206 {
sev2000 1:265edb6bdd52 207 SendByte(data[i]);
sev2000 1:265edb6bdd52 208 chksum += data[i];
sev2000 1:265edb6bdd52 209 }
sev2000 1:265edb6bdd52 210 chksum = ~chksum +1;
sev2000 1:265edb6bdd52 211
sev2000 1:265edb6bdd52 212 SendByte((char)(chksum>>8));
sev2000 1:265edb6bdd52 213 SendByte((char)chksum);
sev2000 1:265edb6bdd52 214 SendPostamble();
sev2000 1:265edb6bdd52 215
sev2000 1:265edb6bdd52 216 RxTx = 1; //set pin rxtx to Rx
sev2000 1:265edb6bdd52 217 }
sev2000 1:265edb6bdd52 218
sev2000 1:265edb6bdd52 219 void SendCmd(prog prog, int zone)
sev2000 1:265edb6bdd52 220 {
sev2000 1:265edb6bdd52 221 char tab[8]={0xF1,0xE6,0x01,0x10,0x01,0x00,0x03,0x64}; // Zone1 Sun
sev2000 1:265edb6bdd52 222 char maison[2]={0xF1,0xE6};
sev2000 1:265edb6bdd52 223 char source = 0x01;
sev2000 1:265edb6bdd52 224 char dest = 0;
sev2000 1:265edb6bdd52 225 char trans = 0x01;
sev2000 1:265edb6bdd52 226 int i;
sev2000 1:265edb6bdd52 227
sev2000 1:265edb6bdd52 228 dest = 0x10 + zone-1;
sev2000 1:265edb6bdd52 229 tab[3] = dest;
sev2000 1:265edb6bdd52 230 tab[6] = prog;
sev2000 1:265edb6bdd52 231
sev2000 1:265edb6bdd52 232 RxTx = 0; //set pin rxtx to Tx
sev2000 1:265edb6bdd52 233 wait_ms(1);
sev2000 1:265edb6bdd52 234
sev2000 1:265edb6bdd52 235 for(i=0; i<3; i++)
sev2000 1:265edb6bdd52 236 {
sev2000 1:265edb6bdd52 237 tab[5]=i; //message count
sev2000 1:265edb6bdd52 238 SendFrame(tab, 8);
sev2000 1:265edb6bdd52 239 wait_ms(30);
sev2000 1:265edb6bdd52 240 }
sev2000 1:265edb6bdd52 241
sev2000 1:265edb6bdd52 242 RxTx = 1; //set pin rxtx to Rx
sev2000 1:265edb6bdd52 243 }
sev2000 1:265edb6bdd52 244
sev2000 0:9ef8edfe21bc 245 int detectPreamble(void)
sev2000 0:9ef8edfe21bc 246 {
sev2000 0:9ef8edfe21bc 247 pulse_t pulse;
sev2000 0:9ef8edfe21bc 248 int cnt = 0;
sev2000 0:9ef8edfe21bc 249 char tmp[32]={0};
sev2000 0:9ef8edfe21bc 250 char timing[8*1024]={0};
sev2000 0:9ef8edfe21bc 251 char state=0;
sev2000 0:9ef8edfe21bc 252 char s=0, l=0, bit_ptr=0;
sev2000 0:9ef8edfe21bc 253
sev2000 0:9ef8edfe21bc 254 while (!PulseWidth.empty())
sev2000 0:9ef8edfe21bc 255 {
sev2000 0:9ef8edfe21bc 256 PulseWidth.pop(pulse);
sev2000 0:9ef8edfe21bc 257 sprintf(tmp, "%d, %ld|", pulse.pin, pulse.v);
sev2000 0:9ef8edfe21bc 258 strcat(timing, tmp);
sev2000 0:9ef8edfe21bc 259
sev2000 0:9ef8edfe21bc 260 if ((pulse.v > 700) && (pulse.v < 1000))
sev2000 0:9ef8edfe21bc 261 { // short off detected
sev2000 0:9ef8edfe21bc 262 s++;
sev2000 0:9ef8edfe21bc 263 l=0;
sev2000 0:9ef8edfe21bc 264 }
sev2000 0:9ef8edfe21bc 265 else if ((pulse.v > 1500) && (pulse.v < 1800))
sev2000 0:9ef8edfe21bc 266 { // long off detected
sev2000 0:9ef8edfe21bc 267 l++;
sev2000 0:9ef8edfe21bc 268 s=0;
sev2000 0:9ef8edfe21bc 269 }
sev2000 0:9ef8edfe21bc 270 else
sev2000 0:9ef8edfe21bc 271 {
sev2000 0:9ef8edfe21bc 272 l=0;
sev2000 0:9ef8edfe21bc 273 s=0;
sev2000 0:9ef8edfe21bc 274 bit_ptr=0;
sev2000 0:9ef8edfe21bc 275 state=0;
sev2000 0:9ef8edfe21bc 276 }
sev2000 0:9ef8edfe21bc 277 switch(state)
sev2000 0:9ef8edfe21bc 278 {
sev2000 0:9ef8edfe21bc 279 case 0: // Detect preamble
sev2000 0:9ef8edfe21bc 280 if(s >= 12) // out of 12
sev2000 0:9ef8edfe21bc 281 state=1;
sev2000 0:9ef8edfe21bc 282 //pc.printf("%d ", s);
sev2000 0:9ef8edfe21bc 283 break;
sev2000 0:9ef8edfe21bc 284 case 1: // wait start bit (first long)
sev2000 0:9ef8edfe21bc 285 //pc.printf("OK2");
sev2000 0:9ef8edfe21bc 286 s=0;
sev2000 0:9ef8edfe21bc 287 if (l==1)
sev2000 0:9ef8edfe21bc 288 {
sev2000 0:9ef8edfe21bc 289 state = 2;
sev2000 0:9ef8edfe21bc 290 //bit_ptr++; inculde start bit in payload
sev2000 0:9ef8edfe21bc 291 }
sev2000 0:9ef8edfe21bc 292 l=0;
sev2000 0:9ef8edfe21bc 293 break;
sev2000 0:9ef8edfe21bc 294 case 2:
sev2000 0:9ef8edfe21bc 295 //pc.printf(" %d", pulse.v);
sev2000 0:9ef8edfe21bc 296
sev2000 0:9ef8edfe21bc 297 if (s == 2)
sev2000 0:9ef8edfe21bc 298 {
sev2000 0:9ef8edfe21bc 299 dataBits[bit_ptr] = 1;
sev2000 0:9ef8edfe21bc 300 l=0;
sev2000 0:9ef8edfe21bc 301 s=0;
sev2000 0:9ef8edfe21bc 302 bit_ptr++;
sev2000 0:9ef8edfe21bc 303 }
sev2000 0:9ef8edfe21bc 304 if (l == 1 && s==0)
sev2000 0:9ef8edfe21bc 305 {
sev2000 0:9ef8edfe21bc 306 dataBits[bit_ptr] = 0;
sev2000 0:9ef8edfe21bc 307 l=0;
sev2000 0:9ef8edfe21bc 308 s=0;
sev2000 0:9ef8edfe21bc 309 bit_ptr++;
sev2000 0:9ef8edfe21bc 310 }
sev2000 0:9ef8edfe21bc 311 if(bit_ptr > BIT_SIZE)
sev2000 0:9ef8edfe21bc 312 {
sev2000 0:9ef8edfe21bc 313 state=0;
sev2000 0:9ef8edfe21bc 314 bit_ptr=0;
sev2000 0:9ef8edfe21bc 315 printf("Frame too long ; dropped");
sev2000 0:9ef8edfe21bc 316 }
sev2000 0:9ef8edfe21bc 317
sev2000 0:9ef8edfe21bc 318 break;
sev2000 0:9ef8edfe21bc 319 }
sev2000 0:9ef8edfe21bc 320
sev2000 0:9ef8edfe21bc 321 if(pulse.v > 30000 && cnt>0) // End of frame
sev2000 0:9ef8edfe21bc 322 {
sev2000 0:9ef8edfe21bc 323 processData();
sev2000 0:9ef8edfe21bc 324 //timing[0]=0;
sev2000 0:9ef8edfe21bc 325 state=0;
sev2000 0:9ef8edfe21bc 326 bit_ptr=0;
sev2000 0:9ef8edfe21bc 327 //PulseWidth.reset();
sev2000 0:9ef8edfe21bc 328 // WARN(" Waiting...");
sev2000 0:9ef8edfe21bc 329 }
sev2000 0:9ef8edfe21bc 330
sev2000 0:9ef8edfe21bc 331 cnt++;
sev2000 0:9ef8edfe21bc 332 }
sev2000 0:9ef8edfe21bc 333 if (cnt>0) // if buffer wasn't empty
sev2000 0:9ef8edfe21bc 334 {
sev2000 0:9ef8edfe21bc 335 processData();
sev2000 0:9ef8edfe21bc 336 //pc.printf("%s\r\n", timing);
sev2000 0:9ef8edfe21bc 337 }
sev2000 0:9ef8edfe21bc 338
sev2000 0:9ef8edfe21bc 339 return(0);
sev2000 0:9ef8edfe21bc 340 }
sev2000 0:9ef8edfe21bc 341
sev2000 0:9ef8edfe21bc 342 int processData(void)
sev2000 0:9ef8edfe21bc 343 {
sev2000 0:9ef8edfe21bc 344 int x=0;
sev2000 0:9ef8edfe21bc 345 int i = 0;
sev2000 0:9ef8edfe21bc 346 int j= 0;
sev2000 0:9ef8edfe21bc 347 char nibble[18]={0}, cnt=0;
sev2000 0:9ef8edfe21bc 348 int chksum=0, etx_ptr=16;
sev2000 0:9ef8edfe21bc 349
sev2000 0:9ef8edfe21bc 350 /* pc.printf("\r\n");
sev2000 0:9ef8edfe21bc 351 for (x=0;x<128;x++)
sev2000 0:9ef8edfe21bc 352 {
sev2000 0:9ef8edfe21bc 353 if(x%8==0)
sev2000 0:9ef8edfe21bc 354 pc.printf(" ");
sev2000 0:9ef8edfe21bc 355 pc.printf("%d", dataBits[x]);
sev2000 0:9ef8edfe21bc 356 }
sev2000 0:9ef8edfe21bc 357 */
sev2000 0:9ef8edfe21bc 358 x=0;
sev2000 0:9ef8edfe21bc 359
sev2000 0:9ef8edfe21bc 360 for (i=0; i<etx_ptr; i++)
sev2000 0:9ef8edfe21bc 361 {
sev2000 0:9ef8edfe21bc 362 for (j=0;j<8;j++)
sev2000 0:9ef8edfe21bc 363 {
sev2000 0:9ef8edfe21bc 364 if ( dataBits[x])
sev2000 0:9ef8edfe21bc 365 {
sev2000 0:9ef8edfe21bc 366 nibble[i] |= 1<<j;
sev2000 0:9ef8edfe21bc 367 cnt++;
sev2000 0:9ef8edfe21bc 368 }
sev2000 0:9ef8edfe21bc 369 else
sev2000 0:9ef8edfe21bc 370 {
sev2000 0:9ef8edfe21bc 371 if (cnt == 5)
sev2000 0:9ef8edfe21bc 372 j--;
sev2000 0:9ef8edfe21bc 373 cnt=0;
sev2000 0:9ef8edfe21bc 374 }
sev2000 0:9ef8edfe21bc 375 dataBits[x] =0; // clean variable
sev2000 0:9ef8edfe21bc 376 x++;
sev2000 0:9ef8edfe21bc 377 }
sev2000 0:9ef8edfe21bc 378 if (cnt >= 8) // End of Frame detection
sev2000 0:9ef8edfe21bc 379 etx_ptr=i;
sev2000 0:9ef8edfe21bc 380 }
sev2000 0:9ef8edfe21bc 381
sev2000 0:9ef8edfe21bc 382
sev2000 0:9ef8edfe21bc 383 for (i=0; i<etx_ptr-2; i++) // Calculate Checksum
sev2000 0:9ef8edfe21bc 384 chksum += nibble[i];
sev2000 0:9ef8edfe21bc 385 chksum = ~chksum +1;
sev2000 0:9ef8edfe21bc 386
sev2000 0:9ef8edfe21bc 387 #ifdef __DEBUG__
sev2000 0:9ef8edfe21bc 388 for (i=0; i<etx_ptr; i++)
sev2000 0:9ef8edfe21bc 389 pc.printf("%0.2X ",nibble[i]);
sev2000 0:9ef8edfe21bc 390 if ( (char)(chksum>>8) != nibble[etx_ptr-2] || (char)chksum != nibble[etx_ptr-1] )
sev2000 0:9ef8edfe21bc 391 pc.printf(" CRC Error");
sev2000 0:9ef8edfe21bc 392 pc.printf("\r\n");
sev2000 0:9ef8edfe21bc 393 #endif
sev2000 0:9ef8edfe21bc 394
sev2000 0:9ef8edfe21bc 395 return 0;
sev2000 0:9ef8edfe21bc 396 }
sev2000 0:9ef8edfe21bc 397
sev2000 0:9ef8edfe21bc 398
sev2000 0:9ef8edfe21bc 399 void Init_X2D()
sev2000 0:9ef8edfe21bc 400 {
sev2000 4:844c00dd0366 401 Rx.fall(&getPulseF);
sev2000 4:844c00dd0366 402 Rx.rise(&getPulseR);
sev2000 0:9ef8edfe21bc 403 UART = 1;
sev2000 0:9ef8edfe21bc 404 RxTx = 1; //set pin rxtx to Rx
sev2000 0:9ef8edfe21bc 405 Reg_Data = 0; //set pin reg_data
sev2000 0:9ef8edfe21bc 406 Tx = 0;
sev2000 0:9ef8edfe21bc 407
sev2000 0:9ef8edfe21bc 408 xTime.start();
sev2000 0:9ef8edfe21bc 409 xTime.reset();
sev2000 0:9ef8edfe21bc 410 startedAt = xTime.read_us(); // set initial timer end
sev2000 0:9ef8edfe21bc 411
sev2000 0:9ef8edfe21bc 412 //thread.start(getData);
sev2000 0:9ef8edfe21bc 413 }