Пример #1
0
/*! \brief Deselect a device on the SPI bus.
 *
 * Deactivates the chip select and unlocks the bus.
 *
 * \param node Specifies the SPI bus node.
 *
 * \return Always 0.
 */
static int Stm32SpiBusDeselect(NUTSPINODE * node)
{
    /* Sanity check. */
    NUTASSERT(node != NULL);
    NUTASSERT(node->node_bus != NULL);

    NutSpiBusWait(node, NUT_WAIT_INFINITE);
    /* Deactivate the node's chip select. */
    Stm32SpiChipSelect(node->node_cs, (node->node_mode & SPI_MODE_CSHIGH) == 0);

    /* Release the bus. */
    NutEventPostAsync(&node->node_bus->bus_mutex);

    return 0;
}
Пример #2
0
/*!
 * \brief Load sector.
 *
 * \param dev  Specifies the file system device.
 * \param sect Sector to load.
 *
 * \return 0 on success, -1 on failures.
 */
static int RawFsSectorLoad(NUTDEVICE * dev, uint32_t sect)
{
    int rc = -1;
    RAWVOLUME *vol;

    NUTASSERT(dev != NULL);
    vol = (RAWVOLUME *) dev->dev_dcb;

    /* Gain mutex access. */
    NUTASSERT(vol != NULL);
    NutEventWait(&vol->vol_iomutex, 0);

    /* Nothing to do if sector is already loaded. */
    if (vol->vol_sect_num == sect) {
        rc = 0;
    }
    /* Make sure that the sector buffer is clean. */
    else if (RawFsSectorFlush(dev) == 0) {
        NUTFILE *blkmnt = dev->dev_icb;
        NUTDEVICE *blkdev = blkmnt->nf_dev;
        BLKPAR_SEEK pars;

        blkmnt = dev->dev_icb;
        NUTASSERT(blkmnt != NULL);
        blkdev = blkmnt->nf_dev;
        NUTASSERT(blkdev != NULL);

        /* Set the block device's sector position. */
        pars.par_nfp = blkmnt;
        pars.par_blknum = sect;
        if ((*blkdev->dev_ioctl) (blkdev, NUTBLKDEV_SEEK, &pars) == 0) {
            /* Read a single block from the device. */
            if ((*blkdev->dev_read) (blkmnt, vol->vol_sect_buf, 1) == 1) {
                vol->vol_sect_num = sect;
                rc = 0;
            }
        }
    }

    /* Release mutex access. */
    NutEventPostAsync(&vol->vol_iomutex);

    return rc;
}
Пример #3
0
/*
 * Timer callback function.
 *
 * Timer callbacks are called during context switch processing. They must
 * return as soon as possible and must not call any potentially blocking
 * function.
 *
 * It would be great to be able to start a thread here, but unfortunately
 * this doesn't work in Nut/OS. :-(
 */
static void TimerCallback(HANDLE timer, void *arg)
{
    NutEventPostAsync(arg);
}