[528] | 1 | /////////////////////////////////////////////////////////////////////////// |
---|
[258] | 2 | // File : irq_handler.c |
---|
| 3 | // Date : 01/04/2012 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
[528] | 6 | /////////////////////////////////////////////////////////////////////////// |
---|
[258] | 7 | |
---|
| 8 | #include <giet_config.h> |
---|
| 9 | #include <irq_handler.h> |
---|
| 10 | #include <sys_handler.h> |
---|
| 11 | #include <ctx_handler.h> |
---|
| 12 | #include <tim_driver.h> |
---|
| 13 | #include <xcu_driver.h> |
---|
[528] | 14 | #include <pic_driver.h> |
---|
[258] | 15 | #include <tty_driver.h> |
---|
[294] | 16 | #include <nic_driver.h> |
---|
| 17 | #include <cma_driver.h> |
---|
[297] | 18 | #include <mmc_driver.h> |
---|
[294] | 19 | #include <bdv_driver.h> |
---|
[547] | 20 | #include <hba_driver.h> |
---|
[258] | 21 | #include <dma_driver.h> |
---|
[547] | 22 | #include <sdc_driver.h> |
---|
[528] | 23 | #include <mwr_driver.h> |
---|
[281] | 24 | #include <mapping_info.h> |
---|
[258] | 25 | #include <utils.h> |
---|
[459] | 26 | #include <tty0.h> |
---|
[258] | 27 | |
---|
[528] | 28 | ///////////////////////////////////////////////////////////////////////// |
---|
| 29 | // Global variables |
---|
| 30 | ///////////////////////////////////////////////////////////////////////// |
---|
[258] | 31 | |
---|
[528] | 32 | // array of external IRQ indexes for each (isr/channel) couple |
---|
| 33 | __attribute__((section(".kdata"))) |
---|
| 34 | unsigned char _ext_irq_index[GIET_ISR_TYPE_MAX][GIET_ISR_CHANNEL_MAX]; |
---|
| 35 | |
---|
| 36 | // WTI mailbox allocators for external IRQ routing (3 allocators per proc) |
---|
| 37 | __attribute__((section(".kdata"))) |
---|
| 38 | unsigned char _wti_alloc_one[X_SIZE][Y_SIZE][NB_PROCS_MAX]; |
---|
| 39 | __attribute__((section(".kdata"))) |
---|
| 40 | unsigned char _wti_alloc_two[X_SIZE][Y_SIZE][NB_PROCS_MAX]; |
---|
| 41 | __attribute__((section(".kdata"))) |
---|
| 42 | unsigned char _wti_alloc_ter[X_SIZE][Y_SIZE][NB_PROCS_MAX]; |
---|
| 43 | |
---|
[519] | 44 | ///////////////////////////////////////////////////////////////////////// |
---|
[528] | 45 | // this array is allocated in the boot.c or kernel_init.c |
---|
| 46 | ///////////////////////////////////////////////////////////////////////// |
---|
| 47 | |
---|
| 48 | extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX]; |
---|
| 49 | |
---|
| 50 | ///////////////////////////////////////////////////////////////////////// |
---|
[519] | 51 | // These ISR_TYPE names for display must be consistent with values in |
---|
| 52 | // irq_handler.h / mapping.py / xml_driver.c |
---|
| 53 | ///////////////////////////////////////////////////////////////////////// |
---|
[547] | 54 | |
---|
[494] | 55 | __attribute__((section(".kdata"))) |
---|
[547] | 56 | char* _isr_type_str[] = { "DEFAULT", |
---|
| 57 | "TICK" , |
---|
| 58 | "TTY_RX" , |
---|
| 59 | "TTY_TX" , |
---|
| 60 | "BDV" , |
---|
| 61 | "TIMER" , |
---|
| 62 | "WAKUP" , |
---|
| 63 | "NIC_RX" , |
---|
| 64 | "NIC_TX" , |
---|
| 65 | "CMA" , |
---|
| 66 | "MMC" , |
---|
| 67 | "DMA" , |
---|
| 68 | "SPI" , |
---|
| 69 | "MWR" , |
---|
| 70 | "HBA" }; |
---|
[528] | 71 | |
---|
[547] | 72 | __attribute__((section(".kdata"))) |
---|
| 73 | char* _irq_type_str[] = { "HWI", |
---|
| 74 | "WTI", |
---|
| 75 | "PTI" }; |
---|
| 76 | |
---|
[528] | 77 | //////////////////// |
---|
| 78 | void _ext_irq_init() |
---|
| 79 | { |
---|
| 80 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
| 81 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
| 82 | mapping_periph_t* periph = _get_periph_base(header); |
---|
| 83 | mapping_irq_t* irq = _get_irq_base(header); |
---|
| 84 | unsigned int periph_id; // peripheral index in mapping_info |
---|
| 85 | unsigned int irq_id; // irq index in mapping_info |
---|
| 86 | |
---|
| 87 | // get cluster_io index in mapping |
---|
| 88 | unsigned int x_io = header->x_io; |
---|
| 89 | unsigned int y_io = header->y_io; |
---|
| 90 | unsigned int cluster_io = (x_io * Y_SIZE) + y_io; |
---|
| 91 | mapping_periph_t* pic = NULL; |
---|
| 92 | |
---|
[547] | 93 | // scan external peripherals to find PIC |
---|
[528] | 94 | unsigned int min = cluster[cluster_io].periph_offset ; |
---|
| 95 | unsigned int max = min + cluster[cluster_io].periphs ; |
---|
| 96 | |
---|
| 97 | for ( periph_id = min ; periph_id < max ; periph_id++ ) |
---|
| 98 | { |
---|
| 99 | if ( periph[periph_id].type == PERIPH_TYPE_PIC ) |
---|
| 100 | { |
---|
| 101 | pic = &periph[periph_id]; |
---|
| 102 | break; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | if ( pic == NULL ) |
---|
| 107 | { |
---|
| 108 | _printf("\n[GIET ERROR] in _ext_irq_init() : No PIC component found\n"); |
---|
| 109 | _exit(); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | // scan PIC IRQS defined in mapping |
---|
| 113 | for ( irq_id = pic->irq_offset ; |
---|
| 114 | irq_id < pic->irq_offset + pic->irqs ; |
---|
| 115 | irq_id++ ) |
---|
| 116 | { |
---|
| 117 | unsigned int type = irq[irq_id].srctype; |
---|
| 118 | unsigned int srcid = irq[irq_id].srcid; |
---|
| 119 | unsigned int isr = irq[irq_id].isr; |
---|
| 120 | unsigned int channel = irq[irq_id].channel; |
---|
| 121 | |
---|
| 122 | if ( (type != IRQ_TYPE_HWI) || |
---|
| 123 | (srcid > 31) || |
---|
| 124 | (isr >= GIET_ISR_TYPE_MAX) || |
---|
| 125 | (channel >= GIET_ISR_CHANNEL_MAX) ) |
---|
| 126 | { |
---|
| 127 | _printf("\n[GIET ERROR] in _ext_irq_init() : Bad PIC IRQ\n" |
---|
| 128 | " type = %d / srcid = %d / isr = %d / channel = %d\n", |
---|
| 129 | type , srcid , isr , channel ); |
---|
| 130 | _exit(); |
---|
| 131 | } |
---|
| 132 | _ext_irq_index[isr][channel] = srcid; |
---|
| 133 | } |
---|
| 134 | } // end _ext_irq_init() |
---|
| 135 | |
---|
| 136 | //////////////////////////////////////////// |
---|
| 137 | void _ext_irq_alloc( unsigned int isr_type, |
---|
| 138 | unsigned int isr_channel, |
---|
| 139 | unsigned int* wti_index ) |
---|
| 140 | { |
---|
| 141 | unsigned int wti_id; // allocated WTI mailbox index in XCU |
---|
| 142 | unsigned int irq_id; // external IRQ index in PIC (input) |
---|
| 143 | unsigned int wti_addr; // WTI mailbox physical address (32 lsb bits) |
---|
| 144 | |
---|
| 145 | // check arguments |
---|
| 146 | if ( isr_type >= GIET_ISR_TYPE_MAX ) |
---|
| 147 | { |
---|
| 148 | _printf("\n[GIET ERROR] in _ext_irq_alloc() : illegal ISR type\n"); |
---|
| 149 | _exit(); |
---|
| 150 | } |
---|
| 151 | if ( isr_channel >= GIET_ISR_CHANNEL_MAX ) |
---|
| 152 | { |
---|
| 153 | _printf("\n[GIET ERROR] in _ext_irq_alloc() : illegal ISR channel\n"); |
---|
| 154 | _exit(); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | // get processor coordinates [x,y,p] |
---|
| 158 | unsigned int gpid = _get_procid(); |
---|
| 159 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
| 160 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 161 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
| 162 | unsigned int p = gpid & ((1<<P_WIDTH)-1); |
---|
| 163 | |
---|
| 164 | // allocate a WTI mailbox to proc[x,y,p] (blocking until success) |
---|
| 165 | while ( 1 ) |
---|
| 166 | { |
---|
| 167 | if ( _wti_alloc_one[x][y][p] == 0 ) |
---|
| 168 | { |
---|
| 169 | _wti_alloc_one[x][y][p] = 1; |
---|
| 170 | wti_id = p + NB_PROCS_MAX; |
---|
| 171 | break; |
---|
| 172 | } |
---|
| 173 | if ( _wti_alloc_two[x][y][p] == 0 ) |
---|
| 174 | { |
---|
| 175 | _wti_alloc_two[x][y][p] = 1; |
---|
| 176 | wti_id = p + 2*NB_PROCS_MAX; |
---|
| 177 | break; |
---|
| 178 | } |
---|
| 179 | if ( _wti_alloc_ter[x][y][p] == 0 ) |
---|
| 180 | { |
---|
| 181 | _wti_alloc_ter[x][y][p] = 1; |
---|
| 182 | wti_id = p + 3*NB_PROCS_MAX; |
---|
| 183 | break; |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | *wti_index = wti_id; |
---|
| 187 | |
---|
| 188 | // register the mailbox physical address in IOPIC |
---|
| 189 | irq_id = _ext_irq_index[isr_type][isr_channel]; |
---|
| 190 | _xcu_get_wti_address( wti_id , &wti_addr ); |
---|
| 191 | _pic_init( irq_id , wti_addr, cluster_xy ); |
---|
| 192 | |
---|
[547] | 193 | // initializes the WTI interrupt vector entry for target XCU |
---|
| 194 | static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); |
---|
| 195 | psched->wti_vector[wti_id] = isr_channel<<16 | isr_type; |
---|
[528] | 196 | |
---|
[547] | 197 | #if GIET_DEBUG_IRQS |
---|
| 198 | _printf("\n[DEBUG IRQS] _ext_irq_alloc() for P[%d,%d,%d] at cycle %d\n" |
---|
| 199 | " wti_id = %d / isr_type = %s / channel = %d / pic_input = %d\n", |
---|
| 200 | x , y , p , _get_proctime() , |
---|
| 201 | wti_id , _isr_type_str[isr_type] , isr_channel , irq_id ); |
---|
| 202 | #endif |
---|
| 203 | |
---|
[528] | 204 | } // end ext_irq_alloc() |
---|
| 205 | |
---|
| 206 | //////////////////////////////////////////// |
---|
| 207 | void _ext_irq_release( unsigned int isr_type, |
---|
[697] | 208 | unsigned int isr_channel ) |
---|
[528] | 209 | { |
---|
[697] | 210 | unsigned int wti_id; // allocated WTI mailbox index in XCU |
---|
[528] | 211 | unsigned int irq_id; // external IRQ index in PIC (input) |
---|
| 212 | |
---|
| 213 | // get processor coordinates [x,y,p] |
---|
| 214 | unsigned int gpid = _get_procid(); |
---|
| 215 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
| 216 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 217 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
| 218 | unsigned int p = gpid & ((1<<P_WIDTH)-1); |
---|
| 219 | |
---|
| 220 | // check arguments |
---|
| 221 | if ( isr_type >= GIET_ISR_TYPE_MAX ) |
---|
| 222 | { |
---|
| 223 | _printf("\n[GIET ERROR] in _ext_irq_release() illegal ISR type\n"); |
---|
| 224 | _exit(); |
---|
| 225 | } |
---|
| 226 | if ( isr_channel >= GIET_ISR_CHANNEL_MAX ) |
---|
| 227 | { |
---|
| 228 | _printf("\n[GIET ERROR] in _ext_irq_release() : illegal ISR channel\n"); |
---|
| 229 | _exit(); |
---|
| 230 | } |
---|
| 231 | |
---|
[697] | 232 | // find WTI index |
---|
| 233 | static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); |
---|
| 234 | for ( wti_id = 0 ; wti_id < 32 ; wti_id++ ) |
---|
| 235 | { |
---|
| 236 | if ( psched->wti_vector[wti_id] == (isr_channel<<16 | isr_type) ) |
---|
| 237 | break; |
---|
| 238 | } |
---|
| 239 | if ( wti_id == 32 ) |
---|
| 240 | { |
---|
| 241 | _printf("\n[GIET ERROR] in _ext_irq_release() : isr not found\n"); |
---|
| 242 | return; |
---|
| 243 | } |
---|
| 244 | |
---|
[528] | 245 | // desactivates dynamically allocated PIC entry |
---|
| 246 | irq_id = _ext_irq_index[isr_type][isr_channel]; |
---|
| 247 | _pic_set_register( irq_id , IOPIC_MASK , 0 ); |
---|
| 248 | |
---|
| 249 | // releases dynamically allocated WTI mailbox |
---|
[697] | 250 | if ( wti_id == p + NB_PROCS_MAX ) _wti_alloc_one[x][y][p] = 0; |
---|
| 251 | else if ( wti_id == p + 2*NB_PROCS_MAX ) _wti_alloc_two[x][y][p] = 0; |
---|
| 252 | else if ( wti_id == p + 3*NB_PROCS_MAX ) _wti_alloc_ter[x][y][p] = 0; |
---|
[528] | 253 | else |
---|
| 254 | { |
---|
| 255 | _printf("\n[GIET ERROR] in _ext_irq_release() : illegal WTI index\n"); |
---|
| 256 | _exit(); |
---|
| 257 | } |
---|
| 258 | } // end ext_irq_release() |
---|
| 259 | |
---|
[440] | 260 | ///////////////// |
---|
[258] | 261 | void _irq_demux() |
---|
| 262 | { |
---|
[294] | 263 | unsigned int gpid = _get_procid(); |
---|
[428] | 264 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[294] | 265 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 266 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[648] | 267 | unsigned int p = gpid & ((1<<P_WIDTH)-1); |
---|
[258] | 268 | unsigned int irq_id; |
---|
[294] | 269 | unsigned int irq_type; |
---|
[258] | 270 | |
---|
| 271 | // get the highest priority active IRQ index |
---|
[648] | 272 | unsigned int icu_out_index = p * IRQ_PER_PROCESSOR; |
---|
[258] | 273 | |
---|
[294] | 274 | _xcu_get_index( cluster_xy, icu_out_index, &irq_id, &irq_type ); |
---|
[258] | 275 | |
---|
| 276 | if (irq_id < 32) |
---|
| 277 | { |
---|
[294] | 278 | static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); |
---|
[346] | 279 | unsigned int entry = 0; |
---|
[294] | 280 | unsigned int isr_type; |
---|
| 281 | unsigned int channel; |
---|
[258] | 282 | |
---|
[294] | 283 | if (irq_type == IRQ_TYPE_HWI) entry = psched->hwi_vector[irq_id]; |
---|
| 284 | else if (irq_type == IRQ_TYPE_PTI) entry = psched->pti_vector[irq_id]; |
---|
| 285 | else if (irq_type == IRQ_TYPE_WTI) entry = psched->wti_vector[irq_id]; |
---|
| 286 | else |
---|
[258] | 287 | { |
---|
[294] | 288 | _printf("\n[GIET ERROR] illegal irq_type in irq_demux()\n"); |
---|
| 289 | _exit(); |
---|
[258] | 290 | } |
---|
[294] | 291 | |
---|
| 292 | isr_type = (entry ) & 0x0000FFFF; |
---|
| 293 | channel = (entry>>16) & 0x00007FFF; |
---|
| 294 | |
---|
[547] | 295 | #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlocks |
---|
| 296 | _nolock_printf("\n[DEBUG IRQS] _irq_demux() Processor[%d,%d,%d] enters at cycle %d\n" |
---|
| 297 | " irq_type = %s / irq_id = %d / isr_type = %s / channel = %d\n", |
---|
[648] | 298 | x , y , p , _get_proctime() , |
---|
[547] | 299 | _irq_type_str[irq_type] , irq_id , _isr_type_str[isr_type] , channel ); |
---|
[294] | 300 | #endif |
---|
| 301 | |
---|
| 302 | // ISR call |
---|
| 303 | if ( isr_type == ISR_TICK ) _isr_tick ( irq_type, irq_id, channel ); |
---|
| 304 | else if ( isr_type == ISR_TTY_RX ) _tty_rx_isr ( irq_type, irq_id, channel ); |
---|
| 305 | else if ( isr_type == ISR_TTY_TX ) _tty_tx_isr ( irq_type, irq_id, channel ); |
---|
[547] | 306 | else if ( isr_type == ISR_BDV ) _bdv_isr ( irq_type, irq_id, channel ); |
---|
| 307 | else if ( isr_type == ISR_TIMER ) _timer_isr ( irq_type, irq_id, channel ); |
---|
| 308 | else if ( isr_type == ISR_WAKUP ) _isr_wakup ( irq_type, irq_id, channel ); |
---|
[294] | 309 | else if ( isr_type == ISR_NIC_RX ) _nic_rx_isr ( irq_type, irq_id, channel ); |
---|
| 310 | else if ( isr_type == ISR_NIC_TX ) _nic_tx_isr ( irq_type, irq_id, channel ); |
---|
[547] | 311 | else if ( isr_type == ISR_CMA ) _cma_isr ( irq_type, irq_id, channel ); |
---|
[297] | 312 | else if ( isr_type == ISR_MMC ) _mmc_isr ( irq_type, irq_id, channel ); |
---|
[322] | 313 | else if ( isr_type == ISR_DMA ) _dma_isr ( irq_type, irq_id, channel ); |
---|
[547] | 314 | else if ( isr_type == ISR_SDC ) _sdc_isr ( irq_type, irq_id, channel ); |
---|
[519] | 315 | else if ( isr_type == ISR_MWR ) _mwr_isr ( irq_type, irq_id, channel ); |
---|
[547] | 316 | else if ( isr_type == ISR_HBA ) _hba_isr ( irq_type, irq_id, channel ); |
---|
[294] | 317 | else |
---|
[258] | 318 | { |
---|
[310] | 319 | _printf("\n[GIET ERROR] in _irq_demux() :" |
---|
| 320 | " illegal ISR type on processor[%d,%d,%d] at cycle %d\n" |
---|
[547] | 321 | " - irq_type = %s\n" |
---|
[310] | 322 | " - irq_id = %d\n" |
---|
[547] | 323 | " - isr_type = %s\n", |
---|
[648] | 324 | x, y, p, _get_proctime(), |
---|
[547] | 325 | _irq_type_str[irq_type] , irq_id , _isr_type_str[isr_type] ); |
---|
| 326 | _exit(); |
---|
[258] | 327 | } |
---|
| 328 | } |
---|
[294] | 329 | else // no interrupt active |
---|
| 330 | { |
---|
| 331 | _isr_default(); |
---|
| 332 | } |
---|
[258] | 333 | } |
---|
| 334 | |
---|
[440] | 335 | /////////////////// |
---|
[294] | 336 | void _isr_default() |
---|
[258] | 337 | { |
---|
[294] | 338 | unsigned int gpid = _get_procid(); |
---|
[428] | 339 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[294] | 340 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 341 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[648] | 342 | unsigned int p = gpid & ((1<<P_WIDTH)-1); |
---|
[258] | 343 | |
---|
[322] | 344 | _printf("\n[GIET WARNING] IRQ handler called but no active IRQ " |
---|
| 345 | "on processor[%d,%d,%d] at cycle %d\n", |
---|
[648] | 346 | x, y, p, _get_proctime() ); |
---|
[258] | 347 | } |
---|
| 348 | |
---|
| 349 | |
---|
[440] | 350 | //////////////////////////////////////////////////////////// |
---|
[294] | 351 | void _isr_wakup( unsigned int irq_type, // HWI / WTI / PTI |
---|
| 352 | unsigned int irq_id, // index returned by ICU |
---|
| 353 | unsigned int channel ) // unused |
---|
[258] | 354 | { |
---|
[428] | 355 | unsigned int gpid = _get_procid(); |
---|
| 356 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[294] | 357 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 358 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[528] | 359 | unsigned int p = gpid & ((1<<P_WIDTH)-1); |
---|
[428] | 360 | |
---|
[528] | 361 | unsigned int value; // WTI mailbox value |
---|
| 362 | unsigned int save_sr; // save SR value in pre-empted task stack |
---|
[258] | 363 | |
---|
[528] | 364 | unsigned int ltid = _get_current_task_id(); |
---|
| 365 | |
---|
[294] | 366 | if ( irq_type != IRQ_TYPE_WTI ) |
---|
[258] | 367 | { |
---|
[528] | 368 | _printf("[GIET ERROR] P[%d,%d,%d] enters _isr_wakup() at cycle %d\n" |
---|
| 369 | " but not called by a WTI interrupt\n", |
---|
| 370 | x , y , p , _get_proctime() ); |
---|
[294] | 371 | _exit(); |
---|
[258] | 372 | } |
---|
| 373 | |
---|
[294] | 374 | // get mailbox value and acknowledge WTI |
---|
| 375 | _xcu_get_wti_value( cluster_xy, irq_id, &value ); |
---|
| 376 | |
---|
[528] | 377 | #if GIET_DEBUG_SWITCH |
---|
| 378 | _printf("\n[DEBUG SWITCH] P[%d,%d,%d] enters _isr_wakup() at cycle %d\n" |
---|
| 379 | " WTI index = %d / current ltid = %d / mailbox value = %x\n", |
---|
| 380 | x , y , p , _get_proctime() , irq_id , ltid , value ); |
---|
[258] | 381 | #endif |
---|
| 382 | |
---|
[528] | 383 | // enter critical section and swich context (if required) |
---|
| 384 | if ( (ltid == IDLE_TASK_INDEX) || (value != 0) ) |
---|
| 385 | { |
---|
| 386 | _it_disable( &save_sr ); |
---|
| 387 | _ctx_switch(); |
---|
| 388 | _it_restore( &save_sr ); |
---|
| 389 | } |
---|
| 390 | |
---|
[440] | 391 | } // end _isr_wakup |
---|
[258] | 392 | |
---|
[440] | 393 | /////////////////////////////////////////////////////////// |
---|
[294] | 394 | void _isr_tick( unsigned int irq_type, // HWI / WTI / PTI |
---|
| 395 | unsigned int irq_id, // index returned by ICU |
---|
| 396 | unsigned int channel ) // channel index if HWI |
---|
[258] | 397 | { |
---|
[428] | 398 | unsigned int gpid = _get_procid(); |
---|
| 399 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[440] | 400 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 401 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[528] | 402 | unsigned int p = gpid & ((1<<P_WIDTH)-1); |
---|
[258] | 403 | |
---|
[528] | 404 | unsigned int save_sr; // save SR value in pre-empted task stack |
---|
| 405 | |
---|
[440] | 406 | if ( irq_type != IRQ_TYPE_PTI ) |
---|
| 407 | { |
---|
[528] | 408 | _printf("[GIET ERROR] P[%d,%d,%d] enters _isr_tick() at cycle %d\n" |
---|
| 409 | " but not called by a PTI interrupt\n", |
---|
| 410 | x , y , p , _get_proctime() ); |
---|
[440] | 411 | _exit(); |
---|
| 412 | } |
---|
[258] | 413 | |
---|
[440] | 414 | // acknowledge PTI |
---|
| 415 | _xcu_timer_reset_irq( cluster_xy, irq_id ); |
---|
| 416 | |
---|
[702] | 417 | #if (GIET_DEBUG_SWITCH & 0x1) |
---|
[528] | 418 | unsigned int ltid = _get_current_task_id(); |
---|
[702] | 419 | if ( _get_proctime() > GIET_DEBUG_SWITCH ) |
---|
[528] | 420 | _printf("\n[DEBUG SWITCH] P[%d,%d,%d] enters _isr_tick() at cycle %d\n" |
---|
| 421 | " WTI index = %d / current ltid = %d\n", |
---|
| 422 | x , y , p , _get_proctime() , irq_id , ltid ); |
---|
[258] | 423 | #endif |
---|
| 424 | |
---|
[528] | 425 | // enter critical section and switch context |
---|
| 426 | _it_disable( &save_sr ); |
---|
[258] | 427 | _ctx_switch(); |
---|
[528] | 428 | _it_restore( &save_sr ); |
---|
| 429 | |
---|
[440] | 430 | } // end _isr_tick |
---|
[258] | 431 | |
---|
| 432 | |
---|
| 433 | // Local Variables: |
---|
| 434 | // tab-width: 4 |
---|
| 435 | // c-basic-offset: 4 |
---|
| 436 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 437 | // indent-tabs-mode: nil |
---|
| 438 | // End: |
---|
| 439 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 440 | |
---|