Пример #1
0
void intrrupt_TXIF(void) {
    if (ringbuf_num(&tx_buf) > 0) {
        TXREG1 = ringbuf_pop(&tx_buf);
    } else {
        PIE1bits.TX1IE = 0;
    }
}
void interrupt isr(void) {
    uint8_t i;
    if (PIR1bits.RCIF == 1) {
        PIR1bits.RCIF = 0;
    }
    if (PIR1bits.TXIF & PIE1bits.TXIE) {
        if (ringbuf_num(&tx_buf)) {
            TXREG = ringbuf_pop(&tx_buf);
        } else {
            PIE1bits.TXIE = 0;
        }
    }
    if (PIR1bits.TMR1IF == 1) {
        PIR1bits.TMR1IF = 0;
        button_timer_interrupt(&sh_0, !SH0);
        button_timer_interrupt(&sh_1, !SH1);
        button_timer_interrupt(&sh_2, !SH2);
        button_timer_interrupt(&sw_0, !SW0);
        button_timer_interrupt(&sw_1, !SW1);
        for (i = 0; i < 3; i++) {
            if (auto_cut_ON[i]) {
                v[i] = 2 * adc(i)*4 / 5; // *3/4 tyousetsu

                if (v[i] < CUT_current) { //もし一定電流を下回ったらカウントアップスタート
                    cut[i]++;
                    if (cut[i] >= 30 * CUT_time) { //一定時間たったら、出力シャットアウト
                        cut_flag[i] = 1;
                    }
                } else { //経過時間カウントリセット
                    cut[i] = 0;
                }
            }
        }
    }
    if (INTCONbits.TMR0IF == 1) {
        INTCONbits.TMR0IF = 0;
        cnt0++;
        if (cnt0 == 400) {
            cnt0 = 0;
            lchika();
            display(print_port, print_content);
        }
        cnt1s++;
        if (cnt1s == 1953) {
            cnt1s = 0;
            for (i = 0; i < 3; i++) {
                ss[i] += v[i];
                s[i] = ss[i] / 3600;
                if (s[i] != sp[i]) {
                    change_flag[i] = 1;
                    sp[i] = s[i];
                }
            }
        }
    }
}
Пример #3
0
void USB_CDC_task(void) {
#if defined(USB_POLLING)
    // Interrupt or polling method.  If using polling, must call
    // this function periodically.  This function will take care
    // of processing and responding to SETUP transactions
    // (such as during the enumeration process when you first
    // plug in).  USB hosts require that USB devices should accept
    // and process SETUP packets in a timely fashion.  Therefore,
    // when using polling, this function should be called
    // regularly (such as once every 1.8ms or faster** [see
    // inline code comments in usb_device.c for explanation when
    // "or faster" applies])  In most cases, the USBDeviceTasks()
    // function does not take very long to execute (ex: <100
    // instruction cycles) before it returns.
    USBDeviceTasks();
#endif


    /* If the USB device isn't configured yet, we can't really do anything
     * else since we don't have a host to talk to.  So jump back to the
     * top of the while loop. */
    if (USBGetDeviceState() < CONFIGURED_STATE) {
        /* Jump back to the top of the while loop. */
        return;
    }

    /* If we are currently suspended, then we need to see if we need to
     * issue a remote wakeup.  In either case, we shouldn't process any
     * keyboard commands since we aren't currently communicating to the host
     * thus just continue back to the start of the while loop. */
    if (USBIsDeviceSuspended() == true) {
        /* Jump back to the top of the while loop. */
        return;
    }

    // Tx task
    uint16_t length = 0;
    while (ringbuf_num(&usb_tx)) {
        writeBuffer[length++] = ringbuf_pop(&usb_tx);
        if (length >= CDC_DATA_IN_EP_SIZE) {
            break;
        }
    }
    if (length) {
        USB_CDC_send(length);
    }
    // Rx task
    length = USB_CDC_get();
    if (length) {
        for (uint16_t i = 0; i < length; i++) {
            ringbuf_put(&usb_rx, readBuffer[i]);
        }
    }
}
Пример #4
0
void USB_task(void) {
    char data;
    // rx operation
    while (usb_char_get(&data)) {
        ringbuf_put(&usb_rx, data);
    }
    // tx operation
    while (ringbuf_num(&usb_tx)) {
        data = ringbuf_pop(&usb_tx);
        usb_char_send(data);
    }
    USBDeviceTasks();
}
Пример #5
0
void *write_thread(void *ptr)
{
    struct thread_info *s = (struct thread_info*)ptr;
    int id = s->id;
    int sem_id = s->sem_id;
    struct message_t *msgptr;

    for (;;) {
        while ((msgptr = ringbuf_pop(&buffers[id])) == NULL);

        printf("ID =%d WRITE: OP = %d NICK = %s MSG = %s\n", id, msgptr->op,
               msgptr->nick, msgptr->msg);

        binsem_lock(sem_id, id + SEM_IN_MEM);
        strcpy(chat_shm->users[id].nick, msgptr->nick);
        strcpy(chat_shm->users[id].msg_in, msgptr->msg);
        chat_shm->users[id].op_in = msgptr->op;
        binsem_unlock(sem_id, id + SEM_IN_READY);
        binsem_unlock(sem_id, id + SEM_IN_MEM);
        free(msgptr);
    }
    return NULL;
}