Commit 440787ce authored by Jan Charvát's avatar Jan Charvát

hw/net/can: Tx priority added

Signed-off-by: Jan Charvát's avatarJan Charvat <charvj10@fel.cvut.cz>
parent 8968c253
Pipeline #21336 failed with stage
in 0 seconds
......@@ -231,13 +231,70 @@ void ctucan_hardware_reset(CtuCanCoreState *s)
qemu_irq_lower(s->irq);
}
static void ctucan_send_ready_buffers(CtuCanCoreState *s)
{
qemu_can_frame frame;
uint8_t *pf;
int buff2tx_idx;
uint32_t tx_prio_max;
unsigned int buff_st;
uint32_t buff_st_mask;
if (!s->mode_settings.s.ena) {
return;
}
do {
union ctu_can_fd_int_stat int_stat;
int i;
buff2tx_idx = -1;
tx_prio_max = 0;
for (i = 0; i < CTUCAN_CORE_TXBUF_NUM; i++) {
uint32_t prio;
buff_st_mask = 0xf << (i * 4);
buff_st = (s->tx_status.u32 >> (i * 4)) & 0xf;
if (buff_st != TXT_RDY) {
continue;
}
prio = (s->tx_priority.u32 >> (i * 4)) & 0x7;
if (tx_prio_max < prio) {
tx_prio_max = prio;
buff2tx_idx = i;
}
}
if (buff2tx_idx == -1) {
break;
}
buff_st_mask = 0xf << (buff2tx_idx * 4);
buff_st = (s->tx_status.u32 >> (buff2tx_idx * 4)) & 0xf;
int_stat.u32 = 0;
buff_st = TXT_RDY;
pf = s->tx_buffer[buff2tx_idx].data;
ctucan_buff2frame(pf, &frame);
s->status.s.idle = 0;
s->status.s.txs = 1;
can_bus_client_send(&s->bus_client, &frame, 1);
s->status.s.idle = 1;
s->status.s.txs = 0;
s->tx_fr_ctr.s.tx_fr_ctr_val++;
buff_st = TXT_TOK;
int_stat.s.txi = 1;
int_stat.s.txbhci = 1;
s->int_stat.u32 |= int_stat.u32 & ~s->int_mask.u32;
s->tx_status.u32 = (s->tx_status.u32 & ~buff_st_mask) |
(buff_st << (buff2tx_idx * 4));
} while (1);
}
#define CTUCAN_CORE_TXBUFF_SPAN \
(CTU_CAN_FD_TXTB2_DATA_1 - CTU_CAN_FD_TXTB1_DATA_1)
void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, uint64_t val,
unsigned size)
{
qemu_can_frame frame;
int i;
DPRINTF("write 0x%02llx addr 0x%02x\n",
......@@ -306,11 +363,11 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, uint64_t val,
union ctu_can_fd_tx_command mask;
unsigned int buff_st;
uint32_t buff_st_mask;
uint8_t *pf;
tx_command.u32 = (uint32_t)val;
mask.u32 = 0;
mask.s.txb1 = 1;
for (i = 0; i < CTUCAN_CORE_TXBUF_NUM; i++) {
if (!(tx_command.u32 & (mask.u32 << i))) {
continue;
......@@ -324,23 +381,8 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, uint64_t val,
}
if (tx_command.s.txcr) {
if ((buff_st == TXT_TOK) || (buff_st == TXT_ERR) ||
(buff_st == TXT_ABT) || (buff_st == TXT_ETY)) {
union ctu_can_fd_int_stat int_stat;
int_stat.u32 = 0;
(buff_st == TXT_ABT) || (buff_st == TXT_ETY))
buff_st = TXT_RDY;
pf = s->tx_buffer[i].data;
ctucan_buff2frame(pf, &frame);
s->status.s.idle = 0;
s->status.s.txs = 1;
can_bus_client_send(&s->bus_client, &frame, 1);
s->status.s.idle = 1;
s->status.s.txs = 0;
s->tx_fr_ctr.s.tx_fr_ctr_val++;
buff_st = TXT_TOK;
int_stat.s.txi = 1;
int_stat.s.txbhci = 1;
s->int_stat.u32 |= int_stat.u32 & ~s->int_mask.u32;
}
}
if (tx_command.s.txce) {
if ((buff_st == TXT_TOK) || (buff_st == TXT_ERR) ||
......@@ -350,6 +392,8 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, uint64_t val,
s->tx_status.u32 = (s->tx_status.u32 & ~buff_st_mask) |
(buff_st << (i * 4));
}
ctucan_send_ready_buffers(s);
ctucan_update_txnf(s);
}
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment