/** audio tx put * copies filled pChunk into the TX queue for transmission * if queue is full, then chunk is dropped * Parameters: * @param pThis pointer to own object * * @return Zero on success. * Negative value on failure. */ int audioTx_put(audioTx_t *pThis, chunk_t *pChunk) { chunk_t *pchunk_temp = NULL; if ( NULL == pThis || NULL == pChunk ) { //printf("[Audio TX]: Failed to put \r\n"); return FAIL; } // block if queue is full //while(queue_is_full(&pThis->queue)) { if(queue_is_full(&pThis->queue)) { //printf("[Audio TX]: Queue Full \r\n"); return FAIL; //powerMode_change(PWR_ACTIVE); //asm("idle;"); } //powerMode_change(PWR_FULL_ON); // get free chunk from pool if ( PASS == bufferPool_acquire(pThis->pBuffP, &pchunk_temp) ) { // copy chunk into free buffer for queue chunk_copy(pChunk, pchunk_temp); /* If DMA not running ? */ if ( 0 == pThis->running ) { /* directly put chunk to DMA transfer & enable */ pThis->running = 1; pThis->pPending = pchunk_temp; audioTx_dmaConfig(pThis->pPending); ENABLE_SPORT0_TX(); } else { /* DMA already running add chunk to queue */ if ( PASS != queue_put(&pThis->queue, pchunk_temp) ) { // return chunk to pool if queue is full, effectively dropping the chunk bufferPool_release(pThis->pBuffP, pchunk_temp); return FAIL; } else { return PASS; } } } else { // drop if we don't get free space //printf("[Audio TX]: failed to get buffer \r\n"); return FAIL; } return FAIL; }
/** start audio rx * - start receiving first chunk from DMA * - acqurie chunk from pool * - config DMA * - start DMA + SPORT * Parameters: * @param pThis pointer to own object * * @return Zero on success. * Negative value on failure. */ int uartRx_start(uartRx_t *pThis) { //printf("[UART RX]: uartRx_start: implemented\r\n"); /* prime the system by getting the first buffer filled */ if ( FAIL == bufferPool_acquire(pThis->pBuffP, &pThis->pPending ) ) { //printf("[UART_RX]: Failed to acquire buffer\r\n"); return FAIL; } //*pSIC_IMASK = 0x00000000; //uartRx_dmaConfig(pThis->pPending); uartRx_dmaConfig(sramPending, 3); //*pSIC_IMASK = 0xffffffff; // enable the audio transfer //printf("Enabled XBEE RX\r\n"); //ENABLE_DMA(*pDMA10_CONFIG); return PASS; }
/** uartRx_isr * Parameters: * @param pThisArg pointer to own object * * @return None */ void uartRx_isr(void *pThisArg) { //printf("RX finished\r\n"); // local pThis to avoid constant casting uartRx_t *pThis = (uartRx_t*) pThisArg; if ( *pDMA10_IRQ_STATUS & 0x1 ) { if (pThis->state == UARTRX_WAITING) { unsigned short packet_length = sramPending[2] + 1; if (0x7e == sramPending[0] && 0 < packet_length) { int i; for (i = 0; i < 3; i++) { pThis->pPending->s08_buff[i] = sramPending[i]; } pThis->state = UARTRX_COMPLETING; uartRx_dmaConfig(sramPending, packet_length); } else if (0x7e == sramPending[1]) { sramPending[0] = 0x7e; sramPending[1] = sramPending[2]; uartRx_dmaConfig(sramPending+2, 1); } else if (0x7e == sramPending[2]) { sramPending[0] = 0x7e; uartRx_dmaConfig(sramPending+1, 2); } else { uartRx_dmaConfig(sramPending, 3); } } else if (pThis->state == UARTRX_COMPLETING) { int i; for (i = 0; i < pThis->pPending->s08_buff[2] + 1; i++) { pThis->pPending->s08_buff[i+3] = sramPending[i]; } // chunk is now filled update the length pThis->pPending->bytesUsed = pThis->pPending->s08_buff[2] + 4; //pThis->pPending->size; /* Insert the chunk previously read by the DMA RX on the RX QUEUE and a data is inserted to queue */ if ( FAIL == queue_put(&pThis->queue, pThis->pPending) ) { // reuse the same buffer and overwrite last samples //uartRx_dmaConfig(pThis->pPending); uartRx_dmaConfig(sramPending, 3); //printf("[INT]: RX packet dropped\r\n"); } else { if ( PASS == bufferPool_acquire(pThis->pBuffP, &pThis->pPending ) ) { uartRx_dmaConfig(sramPending, 3); } else { //printf("Buffer pool empty!\r\n"); } } pThis->state = UARTRX_WAITING; } *pDMA10_IRQ_STATUS |= 0x0001; // clear the interrupt } }