void echo_test(){ #ifdef USE_FREERTOS for( ;; ){ /* Wait to receive data for echo test */ if( xQueueReceive( echo_queue, &echo_data, portMAX_DELAY )){ /* * The data can be processed here and send back * Since it is simple echo test, the data is sent without * processing */ xQueueSend( OpenAMPInstPtr.send_queue, &echo_data, portMAX_DELAY ); } } #else /* check whether data is received for echo test */ if(pq_qlength(echo_queue) > 0){ echo_data = pq_dequeue(echo_queue); /* * The data can be processed here and send back * Since it is simple echo test, the data is sent without * processing */ pq_enqueue(OpenAMPInstPtr.send_queue, echo_data); } #endif }
/* * low_level_input(): * * Should allocate a pbuf and transfer the bytes of the incoming * packet from the interface into the pbuf. * */ static struct pbuf * low_level_input(struct netif *netif) { struct xemac_s *xemac = (struct xemac_s *)(netif->state); xemacliteif_s *xemacliteif = (xemacliteif_s *)(xemac->state); /* see if there is data to process */ if (pq_qlength(xemacliteif->recv_q) == 0) return NULL; /* return one packet from receive q */ return (struct pbuf *)pq_dequeue(xemacliteif->recv_q); }
/* * low_level_output(): * * Should do the actual transmission of the packet. The packet is * contained in the pbuf that is passed to the function. This pbuf * might be chained. * */ static err_t low_level_output(struct netif *netif, struct pbuf *p) { SYS_ARCH_DECL_PROTECT(lev); struct xemac_s *xemac = (struct xemac_s *)(netif->state); xemacliteif_s *xemacliteif = (xemacliteif_s *)(xemac->state); XEmacLite *instance = xemacliteif->instance; struct pbuf *q; SYS_ARCH_PROTECT(lev); /* check if space is available to send */ if (XEmacLite_TxBufferAvailable(instance) == TRUE) { if (pq_qlength(xemacliteif->send_q)) { /* send backlog */ _unbuffered_low_level_output(instance, (struct pbuf *)pq_dequeue(xemacliteif->send_q)); } else { /* send current */ _unbuffered_low_level_output(instance, p); SYS_ARCH_UNPROTECT(lev); return ERR_OK; } } /* if we cannot send the packet immediately, then make a copy of the whole packet * into a separate pbuf and store it in send_q. We cannot enqueue the pbuf as is * since parts of the pbuf may be modified inside lwIP. */ q = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_POOL); if (!q) { #if LINK_STATS lwip_stats.link.drop++; #endif SYS_ARCH_UNPROTECT(lev); return ERR_MEM; } for (q->len = 0; p; p = p->next) { memcpy(q->payload + q->len, p->payload, p->len); q->len += p->len; } if (pq_enqueue(xemacliteif->send_q, (void *)q) < 0) { #if LINK_STATS lwip_stats.link.drop++; #endif SYS_ARCH_UNPROTECT(lev); return ERR_MEM; } SYS_ARCH_UNPROTECT(lev); return ERR_OK; }
void communication_task(){ int status; rsc_info.rsc_tab = (struct resource_table *)&resources; rsc_info.size = sizeof(resources); zynqMP_r5_gic_initialize(); /* Initialize RPMSG framework */ status = remoteproc_resource_init(&rsc_info, rpmsg_channel_created, rpmsg_channel_deleted, rpmsg_read_cb ,&proc); if (status < 0) { return; } #ifdef USE_FREERTOS comm_queueset = xQueueCreateSet( 2 ); xQueueAddToSet( OpenAMPInstPtr.send_queue, comm_queueset); xQueueAddToSet( OpenAMPInstPtr.lock, comm_queueset); #else env_create_sync_lock(&OpenAMPInstPtr.lock,LOCKED); #endif env_enable_interrupt(VRING1_IPI_INTR_VECT,0,0); while (1) { #ifdef USE_FREERTOS QueueSetMemberHandle_t xActivatedMember; xActivatedMember = xQueueSelectFromSet( comm_queueset, portMAX_DELAY); if( xActivatedMember == OpenAMPInstPtr.lock ) { env_acquire_sync_lock(OpenAMPInstPtr.lock); process_communication(OpenAMPInstPtr); } if (xActivatedMember == OpenAMPInstPtr.send_queue) { xQueueReceive( OpenAMPInstPtr.send_queue, &send_data, 0 ); rpmsg_send(app_rp_chnl, send_data.data, send_data.length); } #else env_acquire_sync_lock(OpenAMPInstPtr.lock); process_communication(OpenAMPInstPtr); echo_test(); /* Wait for the result data on queue */ if(pq_qlength(OpenAMPInstPtr.send_queue) > 0) { send_data = pq_dequeue(OpenAMPInstPtr.send_queue); /* Send the result of echo_test back to master. */ rpmsg_send(app_rp_chnl, send_data->data, send_data->length); } #endif } }
static void xemacif_send_handler(void *arg) { struct xemac_s *xemac = (struct xemac_s *)(arg); xemacliteif_s *xemacliteif = (xemacliteif_s *)(xemac->state); XEmacLite *instance = xemacliteif->instance; struct xtopology_t *xtopologyp = &xtopology[xemac->topology_index]; XIntc_AckIntr(xtopologyp->intc_baseaddr, 1 << xtopologyp->intc_emac_intr); if (pq_qlength(xemacliteif->send_q) && (XEmacLite_TxBufferAvailable(instance) == XTRUE)) { struct pbuf *p = pq_dequeue(xemacliteif->send_q); _unbuffered_low_level_output(instance, p); pbuf_free(p); } }
void matrix_mul(){ #ifdef USE_FREERTOS for( ;; ){ if( xQueueReceive(mat_mul_queue, &mat_array, portMAX_DELAY )){ env_memcpy(matrix_array, mat_array.data, mat_array.length); Matrix_Multiply(&matrix_array[0], &matrix_array[1], &matrix_result); mat_result_array.length = sizeof(matrix); mat_result_array.data = &matrix_result; xQueueSend( OpenAMPInstPtr.send_queue, &mat_result_array, portMAX_DELAY ); } } #else if(pq_qlength(mat_mul_queue) > 0){ mat_array = pq_dequeue(mat_mul_queue); env_memcpy(matrix_array, mat_array->data, mat_array->length); /* Process received data and multiple matrices. */ Matrix_Multiply(&matrix_array[0], &matrix_array[1], &matrix_result); mat_result_array.length = sizeof(matrix); mat_result_array.data = &matrix_result; pq_enqueue(OpenAMPInstPtr.send_queue, &mat_result_array); } #endif }