Пример #1
0
/*
 * \brief Write to command channel of codec 0.
 *
 * This routine will not check the DREQ line.
 *
 * \param cmd  Points to the buffer. On entry it contains the data to
 *             send. On exit it will contain the data received from
 *             the chip.
 * \param len  Number of bytes to send and receive.
 */
static int VsCodec0RecvData(void *buf, size_t len)
{
    int rc;
    uint8_t *bp = (uint8_t *) buf;
    const uint8_t cmd[4] = { VS_OPCODE_READ, VS_HDAT0_REG, 0xFF, 0xFF };
    uint8_t rsp[4];

    VsCodecWaitReady(&devSpiVsCodec0, VSCODEC_CMD_TIMEOUT);
    //(*nodeSpiVsCodec0.node_bus->bus_set_rate) (&nodeSpiVsCodec0, 20000000);
    /* Allocate the SPI bus. */
    rc = (*nodeSpiVsCodec0.node_bus->bus_alloc) (&nodeSpiVsCodec0, VSCODEC0_SPIBUS_WAIT);
    if (rc == 0) {
        len >>= 1;
        while (len--) {
            /* Activate chip selects. */
#if defined(VSCODEC0_VSCS_PORT) && defined(VSCODEC0_VSCS_BIT)
            GpioPinSetLow(VSCODEC0_VSCS_PORT, VSCODEC0_VSCS_BIT);
#endif
            GpioPinSetLow(VSCODEC0_XCS_PORT, VSCODEC0_XCS_BIT); /* XCS=PA31 */
            /* Send command bytes and receive response. */
            rc = (*nodeSpiVsCodec0.node_bus->bus_transfer) (&nodeSpiVsCodec0, cmd, rsp, 4);
            /* Deactivate chip selects. */
            GpioPinSetHigh(VSCODEC0_XCS_PORT, VSCODEC0_XCS_BIT);
#if defined(VSCODEC0_VSCS_PORT) && defined(VSCODEC0_VSCS_BIT)
            GpioPinSetHigh(VSCODEC0_VSCS_PORT, VSCODEC0_VSCS_BIT);
#endif
            *bp++ = rsp[2];
            *bp++ = rsp[3];
        }
        /* Release the SPI bus. */
        (*nodeSpiVsCodec0.node_bus->bus_release) (&nodeSpiVsCodec0);
    }
Пример #2
0
void IoPortInit(void)
{
	//Debug LED pin
	GpioPinSetHigh(DEBUG_LED_PORT, DEBUG_LED1);
	GpioPinSetHigh(DEBUG_LED_PORT, DEBUG_LED2);
	GpioPinConfigSet(DEBUG_LED_PORT, DEBUG_LED1, GPIO_CFG_OUTPUT);
	GpioPinConfigSet(DEBUG_LED_PORT, DEBUG_LED2, GPIO_CFG_OUTPUT);
	//Config Pin
	GpioPinSetHigh(AVRPORTF, IO_CONFIG0);
	GpioPinSetHigh(AVRPORTF, IO_CONFIG1);
	GpioPinConfigSet(AVRPORTF, IO_CONFIG0, GPIO_CFG_PULLUP);
	GpioPinConfigSet(AVRPORTF, IO_CONFIG1, GPIO_CFG_PULLUP);

}
Пример #3
0
/*!
 * \brief Set pin level.
 *
 * Trying to set undefined pins is silently ignored.
 *
 * \param bank  GPIO bank/port number.
 * \param bit   Bit number of the specified bank/port.
 * \param value Level, 0 for low or any other value for high.
 */
void GpioPinSet(int bank, int bit, int value)
{
    if (value) {
        GpioPinSetHigh(bank, bit);
    }
    else {
        GpioPinSetLow(bank, bit);
    }
}
Пример #4
0
/*
 * \brief Write to command channel of codec 0.
 *
 * This routine will not check the DREQ line.
 *
 * \param cmd  Points to the buffer. On entry it contains the data to
 *             send. On exit it will contain the data received from
 *             the chip.
 * \param len  Number of bytes to send and receive.
 */
static int VsCodec0SendCmd(void *cmd, size_t len)
{
    int rc;

    /* Allocate the SPI bus. */
    rc = (*nodeSpiVsCodec0.node_bus->bus_alloc) (&nodeSpiVsCodec0, VSCODEC0_SPIBUS_WAIT);
    if (rc == 0) {
        /* Activate chip selects. */
#if defined(VSCODEC0_VSCS_PORT) && defined(VSCODEC0_VSCS_BIT)
        GpioPinSetLow(VSCODEC0_VSCS_PORT, VSCODEC0_VSCS_BIT);
#endif
        GpioPinSetLow(VSCODEC0_XCS_PORT, VSCODEC0_XCS_BIT);
        /* Send command bytes and receive response. */
        rc = (*nodeSpiVsCodec0.node_bus->bus_transfer) (&nodeSpiVsCodec0, cmd, cmd, len);
        /* Dectivate chip selects. */
        GpioPinSetHigh(VSCODEC0_XCS_PORT, VSCODEC0_XCS_BIT);
#if defined(VSCODEC0_VSCS_PORT) && defined(VSCODEC0_VSCS_BIT)
        GpioPinSetHigh(VSCODEC0_VSCS_PORT, VSCODEC0_VSCS_BIT);
#endif
        /* Release the SPI bus. */
        (*nodeSpiVsCodec0.node_bus->bus_release) (&nodeSpiVsCodec0);
    }
    return rc;
}
Пример #5
0
/* Idle clock is high and data is captured on the rising edge. */
static void SpiMode3Transfer(GSPIREG *gspi, CONST uint8_t *txbuf, uint8_t *rxbuf, int xlen)
{
#if defined(SBBI0_SCK_BIT)
    uint_fast8_t mask;

    while (xlen--) {
        for (mask = 0x80; mask; mask >>= 1) {
            NutMicroDelay(gspi->gspi_dly_rate);
            GpioPinSetLow(SBBI0_SCK_PORT, SBBI0_SCK_BIT);
#if defined(SBBI0_MOSI_BIT)
            if (txbuf) {
                GpioPinSet(SBBI0_MOSI_PORT, SBBI0_MOSI_BIT, (*txbuf & mask) != 0);
            }
#endif /* SBBI0_MOSI_BIT */
            NutMicroDelay(gspi->gspi_dly_rate);
            GpioPinSetHigh(SBBI0_SCK_PORT, SBBI0_SCK_BIT);
#if defined(SBBI0_MISO_BIT)
            if (rxbuf) {
                if (GpioPinGet(SBBI0_MISO_PORT, SBBI0_MISO_BIT)) {
                    *rxbuf |= mask;
                }
                else {
                    *rxbuf &= ~mask;
                }
            }
#endif /* SBBI0_MISO_BIT */
        }
        if (txbuf) {
            txbuf++;
        }
        if (rxbuf) {
            rxbuf++;
        }
    }
#endif /* SBBI0_SCK_BIT */
}
Пример #6
0
/*
 * Process client requests.
 */
void ProcessRequests(FILE * stream)
{
    char buff[128];
    char *cp;
    int stat = -1;

    fputs("200 Welcome to portdio. Type help to get help.\r\n", stream);
    for (;;) {
        fflush(stream);

        /*
         * Read a line from the client. Ignore
         * blank lines.
         */
        if (fgets(buff, sizeof(buff), stream) == 0)
            break;
        if ((cp = strchr(buff, '\r')) != 0)
            *cp = 0;
        if ((cp = strchr(buff, '\n')) != 0)
            *cp = 0;
        if (buff[0] == 0)
            continue;

        /*
         * Memory info.
         */
        if (strncmp(buff, "memory", strlen(buff)) == 0) {
            fprintf(stream, "210 %u bytes RAM free\r\n", (unsigned int)NutHeapAvailable());
            continue;
        }

#ifdef OUTBANK
        /*
         * Reset output bit.
         */
        if (strlen(buff) > 1 && strncmp(buff, "reset", strlen(buff) - 1) == 0) {
            int ok = 1;
            switch (buff[strlen(buff) - 1]) {
#ifdef OUTPIN1
            case '1':
                GpioPinSetLow(OUTBANK, OUTPIN1);
                break;
#endif
#ifdef OUTPIN2
            case '2':
                GpioPinSetLow(OUTBANK, OUTPIN2);
                break;
#endif
#ifdef OUTPIN3
            case '3':
                GpioPinSetLow(OUTBANK, OUTPIN3);
                break;
#endif
#ifdef OUTPIN4
            case '4':
                GpioPinSetLow(OUTBANK, OUTPIN4);
                break;
#endif
            default:
                ok = 0;
                break;
            }
            if (ok) {
                fputs("210 OK\r\n", stream);
            } else
                fputs("410 Bad pin\r\n", stream);
            continue;
        }

        /*
         * Set output bit.
         */
        if (strlen(buff) > 1 && strncmp(buff, "set", strlen(buff) - 1) == 0) {
            int ok = 1;
            switch (buff[strlen(buff) - 1]) {
#ifdef OUTPIN1
            case '1':
                GpioPinSetHigh(OUTBANK, OUTPIN1);
                break;
#endif
#ifdef OUTPIN2
            case '2':
                GpioPinSetHigh(OUTBANK, OUTPIN2);
                break;
#endif
#ifdef OUTPIN3
            case '3':
                GpioPinSetHigh(OUTBANK, OUTPIN3);
                break;
#endif
#ifdef OUTPIN4
            case '4':
                GpioPinSetHigh(OUTBANK, OUTPIN4);
                break;
#endif
            default:
                ok = 0;
                break;
            }
            if (ok) {
                fputs("210 OK\r\n", stream);
            } else
                fputs("410 Bad pin\r\n", stream);
            continue;
        }
#endif /* OUTBANK */

#ifdef INBANK
        /*
         * Port status.
         */
        if (strncmp(buff, "query", strlen(buff)) == 0) {
            stat = PortStatus();
            fprintf(stream, "210 %02X\r\n", stat);
            continue;
        }

        /*
         * wait for status change.
         */
        if (strncmp(buff, "wait", strlen(buff)) == 0) {
            while (stat == PortStatus())
                NutThreadYield();
            stat = PortStatus();
            fprintf(stream, "210 %02X\r\n", stat);
            continue;
        }
#endif /* INBANK */

        /*
         * Help.
         */
        fputs("400 List of commands follows\r\n", stream);
        fputs("memory\tQueries number of RAM bytes free\r\n", stream);
#if OUTBANK
        fputs("reset#\tSet output bit 1..4 low\r\n", stream);
        fputs("set#\tSet output bit 1..4 high\r\n", stream);
#endif
#if INBANK
        fputs("query\tQuery digital i/o status\r\n", stream);
        fputs("wait\tWaits for digital i/o change\r\n", stream);
#endif
        fputs(".\r\n", stream);
    }
}