int smd_write(smd_channel_info_t *ch, void *data, uint32_t len, int ch_type) { smd_pkt_hdr smd_hdr; uint32_t size = 0; memset(&smd_hdr, 0, sizeof(smd_pkt_hdr)); if(len + sizeof(smd_hdr) > ch->fifo_size) { dprintf(CRITICAL,"%s: len is greater than fifo sz\n", __func__); return -1; } /* Read the indices from smem */ ch->port_info = smem_get_alloc_entry(SMEM_SMD_BASE_ID + ch->alloc_entry.cid, &size); if(!ch->port_info) { dprintf(CRITICAL,"%s: unable to find index in smem\n", __func__); ASSERT(0); } if(!is_channel_open(ch)) { dprintf(CRITICAL,"%s: channel is not in OPEN state \n", __func__); return -1; } if(!ch->port_info->ch0.DTR_DSR) { dprintf(CRITICAL,"%s: DTR is off\n", __func__); return -1; } /* Clear the data_read flag */ ch->port_info->ch1.data_read = 0; /*copy the local buf to smd buf */ smd_hdr.pkt_size = len; memcpy_to_fifo(ch, (uint32_t *)&smd_hdr, sizeof(smd_hdr)); memcpy_to_fifo(ch, data, len); dsb(); /* Set the necessary flags */ ch->port_info->ch0.data_written = 1; ch->port_info->ch0.mask_recv_intr = 0; dsb(); smd_notify_rpm(); return 0; }
int AsebaUsbBulkRecv(unsigned char *data, unsigned char size) { size_t free = get_free(&AsebaUsb.rx); if(size >= free) return 1; memcpy_to_fifo(&AsebaUsb.rx, data, size); return 0; }
void AsebaSendBuffer(AsebaVMState *vm, const uint8_t *data, uint16_t length) { int flags; // Here we must loop until we can send the data. // BUT if the usb connection is not available, we drop the packet if(!usb_uart_serial_port_open()) return; // Sanity check, should never be true if (length < 2) return; do { USBMaskInterrupts(flags); if(get_free(&AsebaUsb.tx) > length + 4) { length -= 2; memcpy_to_fifo(&AsebaUsb.tx, (unsigned char *) &length, 2); memcpy_to_fifo(&AsebaUsb.tx, (unsigned char *) &vm->nodeId, 2); memcpy_to_fifo(&AsebaUsb.tx, (unsigned char *) data, length + 2); // Will callback AsebaUsbTxReady if (!tx_busy) { tx_busy = 1; USBCDCKickTx(); } length = 0; } // Usb can be disconnected while sending ... if(!usb_uart_serial_port_open()) { fifo_reset(&AsebaUsb.tx); USBUnmaskInterrupts(flags); break; } USBUnmaskInterrupts(flags); } while(length); }