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