[258] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : mwr_driver.c |
---|
[518] | 3 | // Date : 27/02/2015 |
---|
[258] | 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | |
---|
| 8 | #include <giet_config.h> |
---|
[320] | 9 | #include <hard_config.h> |
---|
[518] | 10 | #include <mapping_info.h> |
---|
[258] | 11 | #include <mwr_driver.h> |
---|
| 12 | #include <utils.h> |
---|
[456] | 13 | #include <tty0.h> |
---|
[518] | 14 | #include <io.h> |
---|
[258] | 15 | |
---|
[263] | 16 | #if !defined(X_SIZE) |
---|
| 17 | # error: You must define X_SIZE in the hard_config.h file |
---|
[258] | 18 | #endif |
---|
| 19 | |
---|
[263] | 20 | #if !defined(Y_SIZE) |
---|
| 21 | # error: You must define X_SIZE in the hard_config.h file |
---|
[258] | 22 | #endif |
---|
| 23 | |
---|
[263] | 24 | #if !defined(X_WIDTH) |
---|
| 25 | # error: You must define X_WIDTH in the hard_config.h file |
---|
| 26 | #endif |
---|
| 27 | |
---|
| 28 | #if !defined(Y_WIDTH) |
---|
| 29 | # error: You must define X_WIDTH in the hard_config.h file |
---|
| 30 | #endif |
---|
| 31 | |
---|
[320] | 32 | #if !defined(SEG_MWR_BASE) |
---|
| 33 | # error: You must define SEG_MWR_BASE in the hard_config.h file |
---|
| 34 | #endif |
---|
| 35 | |
---|
[333] | 36 | #if !defined(PERI_CLUSTER_INCREMENT) |
---|
| 37 | # error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file |
---|
[320] | 38 | #endif |
---|
| 39 | |
---|
[518] | 40 | extern unsigned int _coproc_done[X_SIZE*Y_SIZE]; |
---|
| 41 | |
---|
| 42 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 43 | // This function returns the value contained in a private register |
---|
| 44 | // of the coprocessor contained in cluster "cluster_xy". |
---|
| 45 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 46 | unsigned int _mwr_get_coproc_register( unsigned int cluster_xy, // cluster |
---|
| 47 | unsigned int index ) // register |
---|
[258] | 48 | { |
---|
[518] | 49 | unsigned int vaddr = |
---|
| 50 | SEG_MWR_BASE + |
---|
| 51 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
| 52 | (index << 2); |
---|
[258] | 53 | |
---|
[518] | 54 | return ioread32( (void*)vaddr ); |
---|
| 55 | } |
---|
[258] | 56 | |
---|
[518] | 57 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 58 | // This function sets a new value in a private register |
---|
| 59 | // of the coprocessor contained in cluster "clustenr_xy". |
---|
| 60 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 61 | void _mwr_set_coproc_register( unsigned int cluster_xy, // cluster index |
---|
| 62 | unsigned int index, // register index |
---|
| 63 | unsigned int value ) // writte value |
---|
| 64 | { |
---|
| 65 | unsigned int vaddr = |
---|
| 66 | SEG_MWR_BASE + |
---|
| 67 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
| 68 | (index << 2); |
---|
| 69 | |
---|
| 70 | iowrite32( (void*)vaddr, value ); |
---|
| 71 | } |
---|
[258] | 72 | |
---|
[518] | 73 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 74 | // This function returns the value contained in a channel register |
---|
| 75 | // defined by the "index" and "channel" arguments, in the MWMR_DMA component |
---|
| 76 | // contained in cluster "cluster_xy". |
---|
| 77 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 78 | unsigned int _mwr_get_channel_register( unsigned int cluster_xy, // cluster |
---|
| 79 | unsigned int channel, // channel |
---|
| 80 | unsigned int index ) // register |
---|
| 81 | { |
---|
| 82 | unsigned int vaddr = |
---|
| 83 | SEG_MWR_BASE + |
---|
| 84 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
| 85 | ((channel + 1) * (CHANNEL_SPAN << 2)) + |
---|
| 86 | (index << 2); |
---|
[258] | 87 | |
---|
[518] | 88 | return ioread32( (void*)vaddr ); |
---|
| 89 | } |
---|
[258] | 90 | |
---|
[518] | 91 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 92 | // This function sets a new value in a channel register |
---|
| 93 | // defined by the "index" and "channel") arguments, in the MWMR_DMA component |
---|
| 94 | // contained in cluster "cluster_xy". |
---|
| 95 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 96 | void _mwr_set_channel_register( unsigned int cluster_xy, // cluster index |
---|
| 97 | unsigned int channel, // channel index |
---|
| 98 | unsigned int index, // register index |
---|
| 99 | unsigned int value ) // written value |
---|
| 100 | { |
---|
| 101 | unsigned int vaddr = |
---|
| 102 | SEG_MWR_BASE + |
---|
| 103 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
| 104 | ((channel + 1) * (CHANNEL_SPAN << 2)) + |
---|
| 105 | (index << 2); |
---|
| 106 | |
---|
| 107 | iowrite32( (void*)vaddr, value ); |
---|
[258] | 108 | } |
---|
| 109 | |
---|
[518] | 110 | /////////////////////////////////////////////////////// |
---|
| 111 | void _mwr_isr( unsigned int irq_type, // should be HWI |
---|
| 112 | unsigned int irq_id, // index returned by XCU |
---|
| 113 | unsigned int channel ) // MWMR_DMA channel |
---|
| 114 | { |
---|
| 115 | unsigned int gpid = _get_procid(); |
---|
| 116 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
| 117 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 118 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[258] | 119 | |
---|
[518] | 120 | // acknowledge IRQ |
---|
| 121 | _mwr_set_channel_register( cluster_xy, channel, CHANNEL_RUNNING, 0 ); |
---|
| 122 | |
---|
| 123 | // compute coproc_id from cluster coordinates |
---|
| 124 | unsigned int coproc_id = x * Y_SIZE + y; |
---|
| 125 | |
---|
| 126 | // set synchronisation variable |
---|
| 127 | _coproc_done[coproc_id] = 1; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | |
---|
[258] | 132 | // Local Variables: |
---|
| 133 | // tab-width: 4 |
---|
| 134 | // c-basic-offset: 4 |
---|
| 135 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 136 | // indent-tabs-mode: nil |
---|
| 137 | // End: |
---|
| 138 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 139 | |
---|