static struct rimage *wait_for_image(struct wthread *wt) { struct rimage *result; result = get_rimg_by_name(wt->snapshot_id, wt->path); if (result != NULL) { if (write_reply_header(wt->fd, 0) < 0) { pr_perror("Error writing reply header for %s:%s", wt->path, wt->snapshot_id); close(wt->fd); return NULL; } return result; } /* The file does not exist and we do not expect new files */ if (finished && !is_receiving()) { pr_info("No image %s:%s.\n", wt->path, wt->snapshot_id); if (write_reply_header(wt->fd, ENOENT) < 0) { pr_perror("Error writing reply header for unexisting image"); return NULL; } close(wt->fd); return NULL; } /* NOTE: at this point, when the thread wakes up, either the image is * already in memory or it will never come (the dump is finished). */ sem_wait(&(wt->wakeup_sem)); result = get_rimg_by_name(wt->snapshot_id, wt->path); if (result != NULL) { if (write_reply_header(wt->fd, 0) < 0) { pr_perror("Error writing reply header for %s:%s", wt->path, wt->snapshot_id); close(wt->fd); return NULL; } return result; } else { pr_info("No image %s:%s.\n", wt->path, wt->snapshot_id); if (write_reply_header(wt->fd, ENOENT) < 0) pr_perror("Error writing reply header for unexisting image"); close(wt->fd); return NULL; } }
/** * The CC1101 interrupt handler: called by the hardware interrupt * handler, which is defined as part of the cc1101-arch interface. */ int cc1101_rx_interrupt(void) { /* NB: This function may be called both from an rx interrupt and from cc1101_process */ uint8_t rxbytes, s; if(radio_on_or_off == OFF) { return 0; } #if DEBUG printf("-"); #endif /* DEBUG */ if(SPI_IS_LOCKED()) { #if DEBUG printf("/%d", spi_locked); #endif /* DEBUG */ process_poll(&cc1101_process); return 1; } LOCK_SPI(); s = state(); if(s == CC1101_STATE_RXFIFO_OVERFLOW) { burst_read(CC1101_RXBYTES, &rxbytes, 1); #if DEBUG printf("irqflush\n"); printf("rxbytes 0x%02x\n", rxbytes); #endif /* DEBUG */ flushrx(); RELEASE_SPI(); return 0; } if(s == CC1101_STATE_TXFIFO_UNDERFLOW) { #if DEBUG printf("irqflushtx\n"); #endif /* DEBUG */ strobe(CC1101_SFTX); strobe(CC1101_SRX); RELEASE_SPI(); return 0; } if(is_receiving() && timer_expired(&rxstate.timer)) { #if DEBUG printf("Packet expired, flushing fifo\n"); #endif /* DEBUG */ flushrx(); RELEASE_SPI(); return 0; } #define RX_OVERFLOW 0x80 /* Read each byte from the RXFIFO and put it into the input_byte() function, which takes care of the reception logic. */ do { uint8_t byte; int i, numbytes; rxbytes = read_rxbytes(); if(rxbytes & RX_OVERFLOW) { #if DEBUG printf("ovf\n"); leds_off(LEDS_GREEN;) #endif /* DEBUG */ flushrx(); process_poll(&cc1101_process); RELEASE_SPI(); return 1; }