3 #include <t_services.h>
4 #include <s_services.h>
10 #define PEEPINGTEST // Define PEEPING test to see the top 4 of FIFO after enabling SPORT RX
13 #define SLEEPDURATION 1000
15 #define SLEEPDURATION 10
18 struct dma_descripter{
19 struct dma_descripter * next_descripter;
20 unsigned int * start_address;
21 unsigned short config;
22 unsigned short x_count;
23 unsigned short x_modify;
26 static struct dma_descripter rx_dma_dsc[2];
28 unsigned int rxif_buffer[2][RXIF_BUFSIZE];
33 void rx_if_task(VP_INT exinf)
36 vmsk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG));
37 syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (INT) exinf);
39 syscall(serial_ctl_por(TASK_PORTID,
40 (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV)));
44 syscall(ena_int(INTNO_SPORT0_RX));
47 0 << 14 | // TCKFE, 0:sample at down edge, 1:sample at up edge
48 0 << 13 | // LATFS, 0:early frame sync, 1:late frame sync
49 0 << 12 | // LTFS, 0:Active high TFS, 1:Active low TFS
50 0 << 11 | // DITFS, 0:data dependent TFS generation, 1:data independent TFS generation
51 0 << 10 | // TFSR, 0:TFS is not required every word, 1:TFS is required every word
52 0 << 9 | // ITFS, 0:external TFS, 1:internal TFS
53 0 << 4 | // TLSBIT, 0:MSB first transmission, 1:LSB first transmission
54 0 << 2 | // TDTYPE 0:normal, 1:reserved, 2:u-law, 3:a-law
55 0 << 1 | // ITCLK, 0:external clock generation, 1:internal clock generation
56 0 << 0 ; // TSPEN 0:Tx disable, 1:Tx enable
59 0 << 10 | // TRFST, 0:left streo ch first, 1:right stereo ch first
60 0 << 9 | // TSFESE, 0:normal frame sync, 1:LR frame clock
61 0 << 8 | // TXSE, 0:secondary ch disable, 1:secondary ch enable
62 0 << 0 ; // SLEN 0-1:not allowed,2-31:Serial word length - 1
66 0 << 14 | // RCKFE, 0:sample at down edge, 1:sample at up edge
67 0 << 13 | // LARFS, 0:early frame sync, 1:late frame sync
68 0 << 12 | // LRFS, 0:Active high RFS, 1:Active low RFS
69 1 << 10 | // RFSR, 0:RFS is not required every word, 1:RFS is required every word
70 0 << 9 | // IRFS, 0:external RFS, 1:internal RFS
71 0 << 4 | // RLSBIT, 0:MSB first transmission, 1:LSB first transmission
72 0 << 2 | // RDTYPE 0:zero fill, 1:sign extend, 2:u-law, 3:a-law
73 0 << 1 | // IRCLK, 0:external clock generation, 1:internal clock generation
74 0 << 0 ; // RSPEN 0:Rx disable, 1:Rx enable
77 0 << 10 | // RRFST, 0:left streo ch first, 1:right stereo ch first
78 0 << 9 | // RSFESE, 0:normal frame sync, 1:LR frame clock
79 1 << 8 | // RXSE, 0:secondary ch disable, 1:secondary ch enable
80 29 << 0 ; // SLEN 0-1:not allowed,2-31:Serial word length - 1
86 rx_dma_dsc[0].next_descripter = &rx_dma_dsc[1];
87 rx_dma_dsc[0].start_address = rxif_buffer[0];
88 rx_dma_dsc[0].x_count = RXIF_BUFSIZE;
89 rx_dma_dsc[0].x_modify = sizeof(rxif_buffer[0][0]);
90 rx_dma_dsc[0].config =
91 FLOW_LARGE | // FLOW, 0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large
92 NDSIZE_7 | // NDSIZE, the # of element of the next descripter to fetch
93 1 << DI_EN_P | // DI_EN, 0:No interrupt at the end, 1:Interrupt at the end
94 0 << DI_SEL_P | // DI_SEL, 0:Interrupt at the end of outer loop, 1:Interrupt at the end of inter loop
95 0 << RESTART_P | // RESTART, 0:Keep DMA FIFO before start, 1:Purge DMA FIFO before start
96 0 << DMA2D_P | // DMA2D, 0:Linear DMA, 1:2D DMA
97 WDSIZE_32 | // WDSIZE, 0:8bit, 1:16bit, 2:32bit,3:reserved
98 1 << WNR_P | // WNR, 0:Read from memory, 1:Write to Memory
99 1 << 0 ; // DMA_EN, 0:Disable DMA, 1:Enable DMA
101 rx_dma_dsc[1].next_descripter = &rx_dma_dsc[0];
102 rx_dma_dsc[1].start_address = rxif_buffer[1];
103 rx_dma_dsc[1].x_count = RXIF_BUFSIZE;
104 rx_dma_dsc[1].x_modify = sizeof(rxif_buffer[1][0]);
105 rx_dma_dsc[1].config =
106 FLOW_LARGE | // FLOW, 0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large
107 NDSIZE_7 | // NDSIZE, the # of element of the next descripter to fetch
108 1 << DI_EN_P | // DI_EN, 0:No interrupt at the end, 1:Interrupt at the end
109 0 << DI_SEL_P | // DI_SEL, 0:Interrupt at the end of outer loop, 1:Interrupt at the end of inter loop
110 0 << RESTART_P | // RESTART, 0:Keep DMA FIFO before start, 1:Purge DMA FIFO before start
111 0 << DMA2D_P | // DMA2D, 0:Linear DMA, 1:2D DMA
112 WDSIZE_32 | // WDSIZE, 0:8bit, 1:16bit, 2:32bit,3:reserved
113 1 << WNR_P | // WNR, 0:Read from memory, 1:Write to Memory
114 1 << 0 ; // DMA_EN, 0:Disable DMA, 1:Enable DMA
117 // ここではDMAをイネーブルにしない。また、バッファクリアする
119 FLOW_LARGE | // FLOW, 0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large
120 NDSIZE_7 | // NDSIZE, the # of element of the next descripter to fetch
121 1 << DI_EN_P | // DI_EN, 0:No interrupt at the end, 1:Interrupt at the end
122 0 << DI_SEL_P | // DI_SEL, 0:Interrupt at the end of outer loop, 1:Interrupt at the end of inter loop
123 1 << RESTART_P | // RESTART, 0:Keep DMA FIFO before start, 1:Purge DMA FIFO before start
124 0 << DMA2D_P | // DMA2D, 0:Linear DMA, 1:2D DMA
125 WDSIZE_32 | // WDSIZE, 0:8bit, 1:16bit, 2:32bit,3:reserved
126 1 << WNR_P | // WNR, 0:Read from memory, 1:Write to Memory
127 0 << 0 ; // DMA_EN, 0:Disable DMA, 1:Enable DMA
128 *pDMA1_NEXT_DESC_PTR = &rx_dma_dsc[0];
132 int count = 0, event = 0;
137 *pDMA1_CONFIG |= DMAEN;
139 *pSPORT0_RCR1 |= RSPEN; // RX SPORT Enable
150 // SPORT0受信DMAがバッファを埋めるのを待つ。
151 syscall(wai_sem(SEM_SPORT0_RX));
154 if ( count > 31500/(RXIF_BUFSIZE/4))
157 // FIFOにデータがたまったはずである。
158 // FIFOデータを読みだして下位2bitのみ表示する
159 rx[0] = rxif_buffer[0][0]; // 下位2bitのみ抽出
160 rx[1] = rxif_buffer[0][1]; // 下位2bitのみ抽出
161 rx[2] = rxif_buffer[0][2]; // 下位2bitのみ抽出
162 rx[3] = rxif_buffer[0][3]; // 下位2bitのみ抽出
164 syslog( LOG_NOTICE, "RX word : %08x,%08x,%08x,%08x", rx[0], rx[1], rx[2], rx[3] );
174 syslog(LOG_NOTICE, "Sample program ends.");
179 void sport0_rx_int_handler(void)
182 *pDMA1_IRQ_STATUS = DMA_DONE;
187 // タスクにSPORT0受信DMAのバッファが埋まったと知らせる。
188 isig_sem(SEM_SPORT0_RX);
193 void sport0_tx_int_handler(void)
195 *pDMA2_IRQ_STATUS = DMA_DONE;
202 void init_peripherals(VP_INT p)