1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : cma_driver.c |
---|
3 | // Date : 01/03/2014 |
---|
4 | // Author : alain greiner |
---|
5 | // Copyright (c) UPMC-LIP6 |
---|
6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
7 | |
---|
8 | #include <cma_driver.h> |
---|
9 | #include <hard_config.h> |
---|
10 | #include <utils.h> |
---|
11 | |
---|
12 | #if !defined(SEG_CMA_BASE) |
---|
13 | # error: You must define SEG_CMA_BASE in the hard_config.h file |
---|
14 | #endif |
---|
15 | |
---|
16 | ///////////////////////////////////////////////////// |
---|
17 | unsigned int _cma_get_register( unsigned int channel, |
---|
18 | unsigned int index ) |
---|
19 | { |
---|
20 | unsigned int* vaddr = (unsigned int*)SEG_CMA_BASE + |
---|
21 | CHBUF_CHANNEL_SPAN*channel + index; |
---|
22 | return _io_extended_read( vaddr ); |
---|
23 | } |
---|
24 | |
---|
25 | ///////////////////////////////////////////// |
---|
26 | void _cma_set_register( unsigned int channel, |
---|
27 | unsigned int index, |
---|
28 | unsigned int value ) |
---|
29 | { |
---|
30 | unsigned int* vaddr = (unsigned int*)SEG_CMA_BASE + |
---|
31 | CHBUF_CHANNEL_SPAN*channel + index; |
---|
32 | _io_extended_write( vaddr, value ); |
---|
33 | } |
---|
34 | |
---|
35 | //////////////////////////////////////////////////// |
---|
36 | void _cma_channel_start( unsigned int channel, |
---|
37 | unsigned long long src_paddr, |
---|
38 | unsigned int src_nbufs, |
---|
39 | unsigned long long dst_paddr, |
---|
40 | unsigned int dst_nbufs, |
---|
41 | unsigned int buf_length ) |
---|
42 | { |
---|
43 | _cma_set_register( channel, CHBUF_SRC_DESC , (unsigned int)(src_paddr & 0xFFFFFFFF) ); |
---|
44 | _cma_set_register( channel, CHBUF_SRC_EXT , (unsigned int)(src_paddr >> 32) ); |
---|
45 | _cma_set_register( channel, CHBUF_SRC_NBUFS, src_nbufs ); |
---|
46 | _cma_set_register( channel, CHBUF_DST_DESC , (unsigned int)(dst_paddr & 0xFFFFFFFF) ); |
---|
47 | _cma_set_register( channel, CHBUF_DST_EXT , (unsigned int)(dst_paddr >> 32) ); |
---|
48 | _cma_set_register( channel, CHBUF_DST_NBUFS, dst_nbufs ); |
---|
49 | _cma_set_register( channel, CHBUF_BUF_SIZE , buf_length ); |
---|
50 | _cma_set_register( channel, CHBUF_PERIOD , 300 ); |
---|
51 | _cma_set_register( channel, CHBUF_RUN , 1 ); |
---|
52 | } |
---|
53 | |
---|
54 | ////////////////////////////////////////////// |
---|
55 | void _cma_channel_stop( unsigned int channel ) |
---|
56 | { |
---|
57 | _cma_set_register( channel, CHBUF_RUN, 0 ); |
---|
58 | } |
---|
59 | |
---|
60 | ////////////////////////////////////// |
---|
61 | void _cma_isr( unsigned int irq_type, |
---|
62 | unsigned int irq_id, |
---|
63 | unsigned int channel ) |
---|
64 | { |
---|
65 | // get CMA channel status |
---|
66 | unsigned int status = _cma_get_register( channel, CHBUF_STATUS ); |
---|
67 | |
---|
68 | if (status == CHANNEL_SRC_DESC_ERROR ) |
---|
69 | _printf("\n[CMA WARNING] CMA channel %d blocked at cycle %d : " |
---|
70 | "impossible access to source chbuf descriptor\n", |
---|
71 | channel, _get_proctime() ); |
---|
72 | |
---|
73 | else if (status == CHANNEL_SRC_DATA_ERROR ) |
---|
74 | _printf("\n[CMA WARNING] CMA channel %d blocked at cycle %d : " |
---|
75 | "impossible access to source data buffer\n", |
---|
76 | channel, _get_proctime() ); |
---|
77 | |
---|
78 | else if (status == CHANNEL_DST_DESC_ERROR ) |
---|
79 | _printf("\n[CMA WARNING] CMA channel %d blocked at cycle %d : " |
---|
80 | "impossible access to destination chbuf descriptor\n", |
---|
81 | channel, _get_proctime() ); |
---|
82 | |
---|
83 | else if (status == CHANNEL_DST_DATA_ERROR ) |
---|
84 | _printf("\n[CMA WARNING] CMA channel %d blocked at cycle %d : " |
---|
85 | "impossible access to destination data buffer\n", |
---|
86 | channel, _get_proctime() ); |
---|
87 | |
---|
88 | else |
---|
89 | _printf("\n[CMA WARNING] CMA channel %d : " |
---|
90 | "... strange IRQ received, but channel not blocked...", |
---|
91 | channel, _get_proctime() ); |
---|
92 | |
---|
93 | // acknowledge IRQ |
---|
94 | _cma_set_register( channel, CHBUF_RUN, 0 ); |
---|
95 | } |
---|
96 | |
---|
97 | // Local Variables: |
---|
98 | // tab-width: 4 |
---|
99 | // c-basic-offset: 4 |
---|
100 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
101 | // indent-tabs-mode: nil |
---|
102 | // End: |
---|
103 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
104 | |
---|