static int mkbp_get_next_event(struct host_cmd_handler_args *args) { static int last; int i, data_size, evt; uint8_t *resp = args->response; const struct mkbp_event_source *src; /* * Find the next event to service. We do this in a round-robin * way to make sure no event gets starved. */ for (i = 0; i < EC_MKBP_EVENT_COUNT; ++i) if (event_is_set((last + i) % EC_MKBP_EVENT_COUNT)) break; if (i == EC_MKBP_EVENT_COUNT) return EC_RES_ERROR; evt = (i + last) % EC_MKBP_EVENT_COUNT; last = evt + 1; /* * Clear the event before retrieving the event data in case the * event source wants to send the same event. */ clear_event(evt); for (src = __mkbp_evt_srcs; src < __mkbp_evt_srcs_end; ++src) if (src->event_type == evt) break; if (src == __mkbp_evt_srcs_end) return EC_RES_ERROR; resp[0] = evt; /* Event type */ data_size = src->get_data(resp + 1); if (data_size < 0) return EC_RES_ERROR; args->response_size = 1 + data_size; if (!events) set_host_interrupt(0); return EC_RES_SUCCESS; }
void on_storage_request_buffers(void* param, unsigned int size) { USB_MSC* msc = (USB_MSC*)param; unsigned int block_size; CRITICAL_ENTER; msc->scsi_requested += size; CRITICAL_LEAVE; if (event_is_set(msc->event)) { event_clear(msc->event); msc->current_buf = queue_allocate_buffer_ms(msc->queue, INFINITE); block_size = msc->scsi_requested - msc->scsi_transferred; if (block_size > msc->block_size) block_size = msc->block_size; msc->scsi_transferred += block_size; usb_read(usbd_get_usb(msc->usbd), EP_OUT(msc->ep_num), msc->current_buf, block_size); } #if (USB_MSC_DEBUG_FLOW) printf("USB_MSC: RX %d\n\r", size); #endif }