Ejemplo n.º 1
0
uint8_t rx_byte (void)
{
	uint8_t data;
	CS_CLEAR();
	data = SPI_ReceiveData8 (SPI1);
	CS_SET();
	return data;
}
Ejemplo n.º 2
0
static int RecursiveMatch (const unsigned char* Source, const unsigned char* Pattern)
/* A recursive pattern matcher */
{

    CharSet CS;

    while (1) {

        if (*Pattern == '\0') {

            /* Reached the end of Pattern, what about Source? */
            return (*Source == '\0') ? 1 : 0;

        } else if (*Pattern == '*') {

            if (*++Pattern == '\0') {
                /* A trailing '*' is always a match */
                return 1;
            }

            /* Check the rest of the string */
            while (*Source) {
                if (RecursiveMatch (Source++, Pattern)) {
                    /* Match! */
                    return 1;
                }
            }

            /* No match... */
            return 0;

        } else if (*Source == '\0') {

            /* End of Source reached, no match */
            return 0;

        } else {

            /* Check a single char. Build a set of all possible characters in
             * CS, then check if the current char of Source is contained in
             * there.
             */
            CS_CLEAR (CS);      /* Clear the character set */

            if (*Pattern == '?') {

                /* All chars are allowed */
                CS_SETALL (CS);
                ++Pattern;                      /* Skip '?' */

            } else if (*Pattern == ESCAPE_CHAR) {

                /* Use the next char as is */
                IncPattern ();
                CS_ADD (CS, *Pattern);
                ++Pattern;                      /* Skip the character */

            } else if (*Pattern == '[') {

                /* A set follows */
                int Invert = 0;
                IncPattern ();
                if (*Pattern == '!') {
                    IncPattern ();
                    Invert = 1;
                }
                while (*Pattern != ']') {

                    int C1;
                    if ((C1 = RealChar (Pattern)) == -1) {
                        return 0;
                    }
                    IncPattern ();
                    if (*Pattern != '-') {
                        CS_ADD (CS, C1);
                    } else {
                        int C2;
                        unsigned char C;
                        IncPattern ();
                        if ((C2 = RealChar (Pattern)) == -1) {
                            return 0;
                        }
                        IncPattern ();
                        for (C = C1; C <= C2; C++) {
                            CS_ADD (CS, C);
                        }
                    }
                }
                /* Skip ']' */
                ++Pattern;
                if (Invert) {
                    /* Reverse all bits in the set */
                    CS_INVERT (CS);
                }

            } else {

                /* Include the char in the charset, then skip it */
                CS_ADD (CS, *Pattern);
                ++Pattern;

            }

            if (!CS_CONTAINS (CS, *Source)) {
                /* No match */
                return 0;
            }
            ++Source;
        }
    }
}
Ejemplo n.º 3
0
void tx_byte (uint8_t data)
{
	CS_CLEAR();
	SPI_SendData8 (SPI1, data);
	CS_SET();
}