source: soft/giet_vm/giet_drivers/cma_driver.c @ 487

Last change on this file since 487 was 456, checked in by alain, 10 years ago

Defining the NIC and CMA drivers (validated by the classif application).
Updating other drivers to comply with the new tty0 common file.

File size: 3.5 KB
Line 
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#include <tty0.h>
12
13#if !defined(SEG_CMA_BASE)
14# error: You must define SEG_CMA_BASE in the hard_config.h file
15#endif
16
17/////////////////////////////////////////////////////
18unsigned int _cma_get_register( unsigned int channel,
19                                unsigned int index )
20{
21    unsigned int* vaddr = (unsigned int*)SEG_CMA_BASE + 
22                           CHBUF_CHANNEL_SPAN*channel + index;
23    return _io_extended_read( vaddr );
24}
25
26/////////////////////////////////////////////
27void _cma_set_register( unsigned int channel,
28                        unsigned int index,
29                        unsigned int value ) 
30{
31    unsigned int* vaddr = (unsigned int*)SEG_CMA_BASE + 
32                           CHBUF_CHANNEL_SPAN*channel + index;
33    _io_extended_write( vaddr, value );
34}
35
36////////////////////////////////////////////////////
37void _cma_channel_start( unsigned int       channel,
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//////////////////////////////////////////////
56void _cma_channel_stop( unsigned int channel )
57{
58    _cma_set_register( channel, CHBUF_RUN, 0 );
59}
60
61//////////////////////////////////////
62void _cma_isr( unsigned int irq_type,
63               unsigned int irq_id,
64               unsigned int channel )
65{
66    // get CMA channel status
67    unsigned int status = _cma_get_register( channel, CHBUF_STATUS );
68
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
75    if (status == CHANNEL_SRC_DESC_ERROR )
76        _puts("impossible access to source chbuf descriptor\n");
77
78    else if (status == CHANNEL_SRC_DATA_ERROR )
79        _puts("impossible access to source data buffer\n");
80
81    else if (status == CHANNEL_DST_DESC_ERROR )
82        _puts("impossible access to destination chbuf descriptor\n");
83
84    else if (status == CHANNEL_DST_DATA_ERROR )
85        _puts("impossible access to destination data buffer\n");
86
87    else
88        _puts("strange, because channel is not blocked...");
89   
90    // acknowledge IRQ and desactivates channel
91    _cma_set_register( channel, CHBUF_RUN, 0 );
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
Note: See TracBrowser for help on using the repository browser.