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