[En-Nut-Discussion] MASK and SPACE support for 9bit frame

power ip powerip at gmail.com
Thu Sep 27 06:16:20 CEST 2007


This Code For Support Custom Protocol and Old Slave Device.
In Fact, Current Code Ignore Receive 9th Bit.That's Enough.

u_long i1=4;
//Set MASK
_ioctl(_fileno(stream), UART_SETPARITY,&i1);
//Send  Address  Data
fwrite(cmdbuf, 1, cnt, stream);

//Process Response

//Switch To SPACE
u_long i1=3;
_ioctl(_fileno(stream), UART_SETPARITY,&i1);
//Send  Data
fwrite(cmdbuf, 1, cnt, stream);

//Process Response
//...


--------------------------------------------------

A Receive Solution,CODE NOT TESTED!

//Read Bit9 State

u_char bit9=bit_is_set(UCSRnB, RXB8);

        /*
         * We read the received character as early as possible to
avoid overflows
         * caused by interrupt latency. However, reading the error
flags must come
         * first, because reading the ATmega128 data register clears the status.
         */
        rx_errors |= inb(UCSRnA);
        ch = inb(UDRn);

----ignore

    if (tx_aframe)
       {
       if (bit9)
          {//Only Rec Mask
            if (tx_aframe!=1) return;
          }  else
          {//Only Rec Space
              if (tx_aframe!=0) return;
          }

       };

    /* Wake up waiting threads if this is the first byte in the buffer. */
        if (cnt++ == 0){
#ifdef UART_READMULTIBYTE
            // we do this later, to get the other bytes in time..
            postEvent = 1;
#else
            NutEventPostFromIrq(&rbf->rbf_que);
#endif
        }



More information about the En-Nut-Discussion mailing list