int main(void) { /* Enable OCP Master Port */ PRUCFG_SYSCFG &= ~SYSCFG_STANDBY_INIT; cxt.magic = FW_MAGIC; while (1) { /* Poll for downcalls */ if(PINTC_SRSR0 & BIT(SYSEV_ARM_TO_PRU0)) { PINTC_SICR = SYSEV_ARM_TO_PRU0; sc_downcall(handle_downcall); } /* Run triggered */ if (state_run == 1) { /* Clear all pending interrupts */ PINTC_SECR0 = 0xFFFFFFFF; resume_other_pru(); run(&cxt, trigger_flags); /* Wait for the previous interrupts to be handled */ while (!(PINTC_SRSR0 & BIT(SYSEV_VR_PRU0_TO_ARM))); while ((PINTC_SRSR0 & BIT(SYSEV_VR_PRU0_TO_ARM))); /* Signal completion */ SIGNAL_EVENT(SYSEV_VR_PRU1_TO_ARM); /* Reset PRU1 and our state */ PCTRL_OTHER(0x0000) &= (u16)~CONTROL_SOFT_RST_N; state_run = 0; trigger_flags = -1; } } }
static int event_thread(struct pt *pt) { static struct pru_vring_elem pvre; static u16 idx, count; static u32 rx_len, len; struct vring_desc *vrd; static char *ptr; PT_BEGIN(pt); for (;;) { /* wait until we get the indication */ PT_WAIT_UNTIL(pt, /* pru_signal() && */ (PINTC_SRSR0 & SYSEV_THIS_PRU_INCOMING_MASK) != 0); /* downcall from the host */ if (PINTC_SRSR0 & BIT(SYSEV_ARM_TO_THIS_PRU)) { PINTC_SICR = SYSEV_ARM_TO_THIS_PRU; PT_WAIT_UNTIL(pt, !(PINTC_SRSR0 & BIT(SYSEV_THIS_PRU_TO_OTHER_PRU))); sc_downcall(handle_downcall); } if (PINTC_SRSR0 & BIT(SYSEV_VR_ARM_TO_THIS_PRU)) { PINTC_SICR = SYSEV_VR_ARM_TO_THIS_PRU; while (pru_vring_pop(&rx_ring, &pvre)) { /* process the incoming buffers (??? not used) */ if ((count = pvre.in_num) > 0) { idx = pvre.in_idx; while (count-- > 0) { vrd = pru_vring_desc(&rx_ring, idx); ptr = pa_to_da(vrd->addr); idx++; } } rx_len = 0; /* process the outgoing buffers (this is our RX) */ if (pvre.out_num > 0) { idx = pvre.out_idx; count = pvre.out_num; while (count-- > 0) { vrd = pru_vring_desc(&rx_ring, idx); ptr = pa_to_da(vrd->addr); len = vrd->len; /* put it in the rx buffer (can yield) */ while (len-- > 0) RX_IN(*ptr++); rx_len += vrd->len; idx++; } } pru_vring_push(&rx_ring, &pvre, rx_len); PT_WAIT_UNTIL(pt, !(PINTC_SRSR0 & BIT(SYSEV_VR_THIS_PRU_TO_ARM))); /* VRING PRU -> ARM */ SIGNAL_EVENT(SYSEV_VR_THIS_PRU_TO_ARM); } } if (PINTC_SRSR0 & BIT(SYSEV_OTHER_PRU_TO_THIS_PRU)) { PINTC_SICR = SYSEV_OTHER_PRU_TO_THIS_PRU; } } /* get around warning */ PT_YIELD(pt); PT_END(pt); }