コード例 #1
0
static void* SockRead(void* arg)
{
    while (sock != -1) {
        uint8_t buf[3];
        int ret = recv(sock, buf, sizeof(buf), MSG_WAITALL);
        if (ret != 3) {
            AJ_ErrPrintf(("Recv failed - closing socket\n"));
            close(sock);
            sock = -1;
            break;
        }
        if (buf[0] == 'r') {
            memcpy(recvBuf, buf, ret);
            pthread_mutex_lock(&mutex);
            pthread_cond_signal(&cond);
            pthread_mutex_unlock(&mutex);
        } else if (buf[0] == 'i') {
            /*
             * Record which trigger fired
             */
            BIT_SET(trigSet, buf[1] - 1);
            AJ_Net_Interrupt();
        }
    }
    pthread_cond_destroy(&cond);
    pthread_mutex_destroy(&mutex);
    return NULL;
}
コード例 #2
0
void AJS_InterruptFunc(uint8_t pin)
{
    int8_t trigId;
    trigId = findTrigId(pin);
    BIT_SET(trigSet, trigId);
    AJ_Net_Interrupt();
    AJ_Printf("Pin %u fired and interrupt\n", pin);
}
コード例 #3
0
ファイル: io_gpio.c プロジェクト: avernon/asl_distribution
void EXTI0_IRQHandler(void)
{
    int8_t trigId;
    if (EXTI_GetITStatus(EXTI_Line0) != RESET) {
        //Find the trigger ID and set the correct bit
        trigId = findTrigId(EXTI_PinSource0);
        BIT_SET(trigSet, trigId);
        AJ_Net_Interrupt();
        EXTI_ClearITPendingBit(EXTI_Line0);
        EXTI_ClearFlag(EXTI_Line0);
    }
}
コード例 #4
0
ファイル: io_gpio.c プロジェクト: avernon/asl_distribution
static void* TriggerThread(void* arg)
{
    fd_set readFds;
    fd_set exceptFds;

    resetFd = eventfd(0, O_NONBLOCK);  // Use O_NONBLOCK instead of EFD_NONBLOCK due to bug in OpenWrt's uCLibc

    FD_ZERO(&readFds);

    AJ_InfoPrintf(("Started TriggerThread\n"));

    while (TRUE) {
        int ret;
        int i;
        int maxFd = resetFd;

        FD_SET(resetFd, &readFds);
        /*
         * Initialize the except FDs from the trigger list
         */
        FD_ZERO(&exceptFds);
        for (i = 0; i < MAX_TRIGGERS; ++i) {
            if (triggers[i]) {
                FD_SET(triggers[i]->fd, &exceptFds);
                maxFd = max(maxFd, triggers[i]->fd);
            }
        }
        ret = select(maxFd + 1, &readFds, NULL, &exceptFds, NULL);
        if (ret < 0) {
            AJ_ErrPrintf(("Error: select returned %d\n", ret));
            break;
        }
        /*
         * Need to clear the reset event by reading from the file descriptor.
         */
        if (FD_ISSET(resetFd, &readFds)) {
            uint64_t u64;
            read(resetFd, &u64, sizeof(u64));
        }
        /*
         * Figure out which GPIOs were triggered
         */
        pthread_mutex_lock(&mutex);
        for (i = 0; i < MAX_TRIGGERS; ++i) {
            GPIO* gpio = triggers[i];
            if (gpio && FD_ISSET(gpio->fd, &exceptFds)) {
                char buf[2];
                /*
                 * Consume the value
                 */
                pread(gpio->fd, buf, sizeof(buf), 0);
                /*
                 *
                 */
                if (gpio->debounceMillis) {
                    if (!BIT_IS_SET(trigSet, i)) {
                        AJ_InitTimer(&gpio->timer);
                    } else if (AJ_GetElapsedTime(&gpio->timer, TRUE) < gpio->debounceMillis) {
                        continue;
                    }
                }
                AJ_InfoPrintf(("Trigger on pin %d\n", gpio->pinId));
                /*
                 * Record which trigger fired and the leve
                 */
                BIT_SET(trigSet, i);
                if (buf[0] == '0') {
                    BIT_CLR(trigLevel, i);
                } else {
                    BIT_SET(trigLevel, i);
                }
            }
        }
        pthread_mutex_unlock(&mutex);
        if (trigSet) {
            AJ_Net_Interrupt();
        }
    }
    close(resetFd);
    pthread_mutex_destroy(&mutex);
    resetFd = -1;

    return NULL;
}