| [258] | 1 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 2 | // File     : xcu_driver.h | 
|---|
 | 3 | // Date     : 01/11/2013 | 
|---|
 | 4 | // Author   : alain greiner | 
|---|
 | 5 | // Copyright (c) UPMC-LIP6 | 
|---|
 | 6 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 7 | // The xcu_driver.c and xcu_driver.h files are part ot the GIET-VM nano-kernel. | 
|---|
 | 8 | // This driver supports the SoCLib vci_xicu, that is a vectorised interrupt | 
|---|
| [437] | 9 | // controler supporting three types of interrupts: | 
|---|
| [295] | 10 | // | 
|---|
| [437] | 11 | // - HWI : HardWare Interrupts (from hardware peripherals) | 
|---|
 | 12 | // - PTI : Programmable Timer Interrupts (contained in the XCU component) | 
|---|
 | 13 | // - WTI : Write Trigered Interrupts (from software, or from a PIC controller)  | 
|---|
 | 14 | // | 
|---|
| [295] | 15 | // It can exist several interrupt controller unit in the architecture  | 
|---|
| [437] | 16 | // (one per cluster), and each one can contain several channels: | 
|---|
| [295] | 17 | // The number of XICU channels is equal to NB_PROCS_MAX, because there is  | 
|---|
 | 18 | // one private XICU channel per processor in a cluster. | 
|---|
| [437] | 19 | // | 
|---|
| [295] | 20 | // The virtual base address of the segment associated to the component is: | 
|---|
 | 21 | // | 
|---|
| [437] | 22 | //      vbase = SEG_XCU_BASE + cluster_xy * PERI_CLUSTER_INCREMENT | 
|---|
| [295] | 23 | // | 
|---|
| [437] | 24 | // The SEG_XCU_BSE  and PERI_CLUSTER_INCREMENT values must be defined  | 
|---|
 | 25 | // in the hard_config.h file. | 
|---|
| [295] | 26 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
| [258] | 27 |  | 
|---|
 | 28 | #ifndef _GIET_XCU_DRIVER_H_ | 
|---|
 | 29 | #define _GIET_XCU_DRIVER_H_ | 
|---|
 | 30 |  | 
|---|
 | 31 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 32 | // XICU registers offsets | 
|---|
 | 33 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 34 |  | 
|---|
| [320] | 35 | enum Xcu_registers  | 
|---|
| [258] | 36 | { | 
|---|
| [320] | 37 |     XCU_WTI_REG = 0, | 
|---|
 | 38 |     XCU_PTI_PER = 1, | 
|---|
 | 39 |     XCU_PTI_VAL = 2, | 
|---|
 | 40 |     XCU_PTI_ACK = 3, | 
|---|
| [258] | 41 |  | 
|---|
| [320] | 42 |     XCU_MSK_PTI = 4, | 
|---|
 | 43 |     XCU_MSK_PTI_ENABLE = 5, | 
|---|
 | 44 |     XCU_MSK_PTI_DISABLE = 6, | 
|---|
 | 45 |     XCU_PTI_ACTIVE = 6, | 
|---|
| [258] | 46 |  | 
|---|
| [320] | 47 |     XCU_MSK_HWI = 8, | 
|---|
 | 48 |     XCU_MSK_HWI_ENABLE = 9, | 
|---|
 | 49 |     XCU_MSK_HWI_DISABLE = 10, | 
|---|
 | 50 |     XCU_HWI_ACTIVE = 10, | 
|---|
| [258] | 51 |  | 
|---|
| [320] | 52 |     XCU_MSK_WTI = 12, | 
|---|
 | 53 |     XCU_MSK_WTI_ENABLE = 13, | 
|---|
 | 54 |     XCU_MSK_WTI_DISABLE = 14, | 
|---|
 | 55 |     XCU_WTI_ACTIVE = 14, | 
|---|
| [258] | 56 |  | 
|---|
| [320] | 57 |     XCU_PRIO = 15, | 
|---|
| [258] | 58 | }; | 
|---|
 | 59 |  | 
|---|
| [320] | 60 | #define XCU_REG(func, index) (((func)<<5)|(index)) | 
|---|
| [263] | 61 |   | 
|---|
| [437] | 62 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 63 | //                           access functions  | 
|---|
 | 64 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
| [258] | 65 |  | 
|---|
| [437] | 66 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 67 | // This function set the mask register for the IRQ type defined by "irq_type", | 
|---|
 | 68 | // and for the channel identified by the "cluster_xy" and "channel" arguments. | 
|---|
 | 69 | // All '1' bits are set / all '0' bits are not modified. | 
|---|
 | 70 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 71 | extern void _xcu_set_mask( unsigned int cluster_xy, | 
|---|
 | 72 |                            unsigned int channel,   | 
|---|
 | 73 |                            unsigned int mask,  | 
|---|
 | 74 |                            unsigned int irq_type ); | 
|---|
| [258] | 75 |  | 
|---|
| [437] | 76 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 77 | // This function returns the index and the type of the highest priority  | 
|---|
 | 78 | // - active PTI (Timer Interrupt), then | 
|---|
 | 79 | // - active HWI (Hardware Interrupt), then | 
|---|
 | 80 | // - active WTI (Software Interrupt) | 
|---|
 | 81 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 82 | extern void _xcu_get_index( unsigned int   cluster_xy,  | 
|---|
 | 83 |                             unsigned int   channel,    | 
|---|
 | 84 |                             unsigned int * index, | 
|---|
 | 85 |                             unsigned int * irq_type ); | 
|---|
| [258] | 86 |  | 
|---|
| [437] | 87 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 88 | // This function writes the "wdata" value in the mailbox defined  | 
|---|
 | 89 | // by the "cluster_xy" and "wti_index" arguments. | 
|---|
 | 90 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 91 | extern void _xcu_send_wti( unsigned int cluster_xy, | 
|---|
 | 92 |                            unsigned int wti_index, | 
|---|
 | 93 |                            unsigned int wdata ); | 
|---|
| [258] | 94 |  | 
|---|
| [437] | 95 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 96 | // This function returns the value contained in a WTI mailbox defined by | 
|---|
 | 97 | // the cluster_xy and "wti_index" arguments. This value is written in | 
|---|
 | 98 | // the "value" argument, and the corresponding WTI is acknowledged. | 
|---|
 | 99 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 100 | extern void _xcu_get_wti_value( unsigned int   cluster_xy, | 
|---|
 | 101 |                                 unsigned int   wti_index, | 
|---|
 | 102 |                                 unsigned int * value ); | 
|---|
| [258] | 103 |  | 
|---|
| [437] | 104 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 105 | // This function returns the address of a WTI mailbox defined by | 
|---|
 | 106 | // the "wti_index" argument, in the unsigned int "address" argument. | 
|---|
 | 107 | // It is used by the GIET to configurate the IOPIC component. | 
|---|
 | 108 | // There is no access to a specific XCU component in a specific cluster. | 
|---|
 | 109 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 110 | extern void _xcu_get_wti_address( unsigned int   wti_index, | 
|---|
 | 111 |                                   unsigned int * address ); | 
|---|
| [258] | 112 |  | 
|---|
| [437] | 113 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 114 | // This function activates a timer contained in XCU by writing in the | 
|---|
 | 115 | // proper register the period value. | 
|---|
 | 116 | //////////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 117 | extern void _xcu_timer_start( unsigned int cluster_xy,  | 
|---|
 | 118 |                               unsigned int pti_index, | 
|---|
 | 119 |                               unsigned int period );  | 
|---|
| [258] | 120 |  | 
|---|
| [437] | 121 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 122 | // This function desactivates a timer in XCU component | 
|---|
 | 123 | // by writing in the proper register. | 
|---|
 | 124 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 125 | extern void _xcu_timer_stop( unsigned int cluster_xy,  | 
|---|
 | 126 |                              unsigned int pti_index );  | 
|---|
| [258] | 127 |  | 
|---|
| [437] | 128 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 129 | // This function acknowlegge a timer interrupt in XCU  | 
|---|
 | 130 | // component by reading in the proper XCU register. | 
|---|
 | 131 | // It can be used by both the isr_switch() for a "system" timer,  | 
|---|
 | 132 | // or by the _isr_timer() for an "user" timer. | 
|---|
 | 133 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
| [320] | 134 | extern unsigned int _xcu_timer_reset_irq( unsigned int cluster_xy,  | 
|---|
 | 135 |                                           unsigned int pti_index ); | 
|---|
| [295] | 136 |  | 
|---|
| [437] | 137 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 138 | // This function resets a timer counter. To do so, we re-write the period | 
|---|
 | 139 | // in the proper register, what causes the count to restart. | 
|---|
 | 140 | // The period value is read from the same (TIMER_PERIOD) register, | 
|---|
 | 141 | // this is why in appearance we do nothing useful (read a value | 
|---|
 | 142 | // from a register and write this value in the same register). | 
|---|
 | 143 | // This function is called during a context switch (user or preemptive) | 
|---|
 | 144 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| [295] | 145 | extern void _xcu_timer_reset_cpt( unsigned int cluster_xy,  | 
|---|
 | 146 |                                   unsigned int pti_index );  | 
|---|
 | 147 |  | 
|---|
| [258] | 148 | #endif | 
|---|
 | 149 |  | 
|---|
 | 150 | // Local Variables: | 
|---|
 | 151 | // tab-width: 4 | 
|---|
 | 152 | // c-basic-offset: 4 | 
|---|
 | 153 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) | 
|---|
 | 154 | // indent-tabs-mode: nil | 
|---|
 | 155 | // End: | 
|---|
 | 156 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
 | 157 |  | 
|---|