Hello
Im trying to send data[3000] using USB, problem is I need to finish transfer within 13ms because after that period new data is ready to be sent.
ISR_DIRECT_DECLARE(trig_cnt_irq_handler)
{
// Half way point
if(SPI_TRIG_COUNTER->EVENTS_COMPARE[0]) {
SPI_TRIG_COUNTER->EVENTS_COMPARE[0] = 0;
m_item_num = LIST_ITEMS / 2;
m_item_index = 0;
k_sem_give(&m_sem_samples_available);
size_t send_target = m_item_num * 3;
printf("Zeljeno %u bajtova\n", (unsigned)send_target);
}
// End of buffer (not including margin)
if(SPI_TRIG_COUNTER->EVENTS_COMPARE[1]) {
SPI_TRIG_COUNTER->EVENTS_COMPARE[1] = 0;
// If there is a risk that this interrupt gets delayed we need to handle the case where more items have been sampled than expected
// trigger a capture on the counter to check how far the count has reached
// TODO: Possibly we would also need to check the state of the timer to check if is just about to trigger another sample, which could lead to a race condition
SPI_TRIG_COUNTER->TASKS_CAPTURE[3] = 1;
m_item_num = SPI_TRIG_COUNTER->CC[3] - (LIST_ITEMS / 2);
m_item_index = LIST_ITEMS / 2;
SPI_MASTER->TXD.PTR = (uint32_t)m_tx_buffer[0];
SPI_MASTER->RXD.PTR = (uint32_t)m_rx_buffer[0];
SPI_TRIG_COUNTER->TASKS_CLEAR = 1;
k_sem_give(&m_sem_samples_available);
size_t send_target = m_item_num * 3;
printf("Zeljeno %u bajtova\n", (unsigned)send_target);
}
ISR_DIRECT_PM();
return 1;
}In this Interrupt Im using first or second half of baffer to be send in main faction main () {
while (1) {
// Wait for the samples available semaphore to be set
k_sem_take(&m_sem_samples_available, K_FOREVER);
communication_send_adc_data((uint8_t *)&m_rx_buffer[m_item_index][0], m_item_num*3);
}
}This is communication_send_adc_data() int communication_send_adc_data(uint8_t *adc_value, size_t length )
{
// Pošalji 3 bajta u ring buffer
ring_buf_put(&ringbuf_tx, adc_value, length);
sent_counter = 0;
uart_irq_tx_enable(usb_uart_device);
}And communication_interrupt_handler for TX static void communication_interrupt_handler(const struct device *dev, void *user_data)
{
ARG_UNUSED(user_data);
while (uart_irq_update(dev) && uart_irq_is_pending(dev)) {
if (uart_irq_tx_ready(dev)) {
int rb_len, send_len;
uint8_t *blk;
// "Zahvati" kontinualni blok iz ring-bufa bez kopiranja
rb_len = ring_buf_get_claim(&ringbuf_tx, &blk, 64);
if (rb_len == 0) {
uart_irq_tx_disable(dev);
printf("Sent bytes: %u\n", (unsigned int)sent_counter);
return; // ili continue;
}
// Pokušaj da pošalješ sve što si claim-ovao
send_len = uart_fifo_fill(dev, blk, rb_len);
// Javi ring-bufu tačno koliko je stvarno poslato
ring_buf_get_finish(&ringbuf_tx, send_len);
sent_counter += send_len;
// Ako nije sve stalo u FIFO, ostalo ostaje claim-ovano za sledeći IRQ,
// pa odmah prekini (driver će te opet pozvati kad FIFO oslobodi mesto)
if (send_len < rb_len) {
return;
}
}
}
}My otput is not synchronized, I should be getting Zeljeno 3000 bajtova/n Sent bytes: 3000/n, but instead Im getting this:Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 300Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3006 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Sent bytes: 3166 Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Sent bytes: 3006 Zeljeno 3000 bajtova Sent bytes: 3000 Zeljeno 3000 bajtova Zeljeno 3006 bajtova Sent bytes: 3000 Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Sent bytes:Zeljeno 3000 bajtova 3000 Zeljeno 3000 bajtova Sent bytes: 3000 Sent bytes: 3000 Zeljeno 3000 bajtova Zeljeno 3000 bajtova Sent bytes: 3000 Zeljeno 3003 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Sent bytes: 3031 Zeljeno 3000 bajtova Zeljeno 3000 bajtova Sent bytes: 3000 Zeljeno 3000 bajtova Sent bytes: 3000 Sent bytesZeljeno 3000 bajtova : 3000 Zeljeno 3000 bajtova Sent bytes: 3000 Zeljeno 3000 bajtova Sent bytes: 3000 Zeljeno 3003 bajtova Sent bytes: 3003 Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova Zeljeno 3000 bajtova SZeljeno 3000 bajtova ent bytes: 3000 Zeljeno 3000 bajtova Zeljeno 3000 bajtova Sent bytes: 3000 Sent bytZeljeno 3000 bajtova es: 3000 Zeljeno 3000 bajtova Sent bytes: 3000 Zeljeno 3000 bajtova Sent bytes: 3000 Zeljeno 3000 bajtova Zeljeno 3000 bajtova Sent bytes: 3000 Zeljeno 3000 bajtova Zeljeno 3003 bajtova Zeljeno 3000 bajtova Zeljeno 3003 bajtova Zeljeno 3000 bajtova Sent bytes: 3003 Zeljeno 3000 bajtovaIs there a faster way to do it, some examples and what Iam doing wrong here.
Thank you.