Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 1 | 3a4 |
| 2 | > #include <stdlib.h>
|
| 3 | 5c6 |
| 4 | < #define CyclesForTick (configCPU_CLOCK_HZ/configTICK_RATE_HZ - 50)
|
| 5 | --- |
| 6 | > #include "debugFlags.h"
|
| 7 | 6a8,10 |
| 8 | > #define CyclesForTick (configCPU_CLOCK_HZ/configTICK_RATE_HZ - 50)
|
| 9 | > //debugging
|
| 10 | > //TODO core to core comms will use this
|
| 11 | 8,10c12,14 |
| 12 | <
|
| 13 | < /*-----------------------------------------------------------*/
|
| 14 | <
|
| 15 | --- |
| 16 | > //---------------------------------------------------
|
| 17 | > int globalDelta;
|
| 18 | > //---------------------------------------------------
|
| 19 | 16d19 |
| 20 | <
|
| 21 | 18d20 |
| 22 | <
|
| 23 | 32c34,35 |
| 24 | < StackType_t *pxStackStart;
|
| 25 | --- |
| 26 | > StackType_t *pxStackStart;
|
| 27 | >
|
| 28 | 34,38c37,40 |
| 29 | <
|
| 30 | < //align to double-word boundary
|
| 31 | < pxStackStart = (StackType_t *)(( StackType_t ) pxTopOfStack & ~(0x4));
|
| 32 | <
|
| 33 | < /* To ensure asserts in tasks.c don't fail, although in this case the assert
|
| 34 | --- |
| 35 | > //align to double-word boundary
|
| 36 | > pxStackStart = (StackType_t *)(( StackType_t ) pxTopOfStack & ~(0x4));
|
| 37 | >
|
| 38 | > /* To ensure asserts in tasks.c don't fail, although in this case the assert
|
| 39 | 40c42 |
| 40 | < pxTopOfStack--;
|
| 41 | --- |
| 42 | > pxTopOfStack--;
|
| 43 | 42,43c44,45 |
| 44 | < /* for alignment */
|
| 45 | < pxTopOfStack--;
|
| 46 | --- |
| 47 | > /* for alignment */
|
| 48 | > pxTopOfStack--;
|
| 49 | 45c47 |
| 50 | < /* Setup the initial stack of the task. The stack is set exactly as
|
| 51 | --- |
| 52 | > /* Setup the initial stack of the task. The stack is set exactly as
|
| 53 | 48c50 |
| 54 | < /* First on the stack is the return address - which in this case is the
|
| 55 | --- |
| 56 | > /* First on the stack is the return address - which in this case is the
|
| 57 | 51,94c53,96 |
| 58 | < *pxTopOfStack = ( StackType_t ) 0xdeadaffe;
|
| 59 | < pxTopOfStack--;
|
| 60 | < pxTopOfStack--;
|
| 61 | < pxTopOfStack--;
|
| 62 | <
|
| 63 | <
|
| 64 | < int i;
|
| 65 | <
|
| 66 | < for(i=63;i>14;i--) {
|
| 67 | < *pxTopOfStack = ( StackType_t ) i<<8; /* higher registers */
|
| 68 | < pxTopOfStack--;
|
| 69 | < }
|
| 70 | <
|
| 71 | <
|
| 72 | < *pxTopOfStack = ( StackType_t ) 0xaaaaaaaa; /* R14 */
|
| 73 | < pxTopOfStack--;
|
| 74 | < *pxTopOfStack = ( StackType_t ) 0x51aac4de; /* Stack used when task starts goes in R13. */
|
| 75 | < pxStackStart = pxTopOfStack;
|
| 76 | < pxTopOfStack--;
|
| 77 | < *pxTopOfStack = ( StackType_t ) 0x12121212; /* R12 */
|
| 78 | < pxTopOfStack--;
|
| 79 | < *pxTopOfStack = ( StackType_t ) 0x11111111; /* R11 */
|
| 80 | < //*pxTopOfStack = ( StackType_t ) pxOriginalTOS; /* frame pointer to stack address. */
|
| 81 | < pxTopOfStack--;
|
| 82 | < *pxTopOfStack = ( StackType_t ) 0x10101010; /* R10 */
|
| 83 | < pxTopOfStack--;
|
| 84 | < *pxTopOfStack = ( StackType_t ) 0x09090909; /* R9 */
|
| 85 | < pxTopOfStack--;
|
| 86 | < *pxTopOfStack = ( StackType_t ) 0x08080808; /* R8 */
|
| 87 | < pxTopOfStack--;
|
| 88 | < *pxTopOfStack = ( StackType_t ) 0x07070707; /* R7 */
|
| 89 | < pxTopOfStack--;
|
| 90 | < *pxTopOfStack = ( StackType_t ) 0x06060606; /* R6 */
|
| 91 | < pxTopOfStack--;
|
| 92 | < *pxTopOfStack = ( StackType_t ) 0x05050505; /* R5 */
|
| 93 | < pxTopOfStack--;
|
| 94 | < *pxTopOfStack = ( StackType_t ) 0x04040404; /* R4 */
|
| 95 | < pxTopOfStack--;
|
| 96 | < *pxTopOfStack = ( StackType_t ) 0x03030303; /* R3 */
|
| 97 | < pxTopOfStack--;
|
| 98 | < *pxTopOfStack = ( StackType_t ) 0x02020202; /* R2 */
|
| 99 | < pxTopOfStack--;
|
| 100 | < *pxTopOfStack = ( StackType_t ) 0x01010101; /* R1 */
|
| 101 | < pxTopOfStack--;
|
| 102 | --- |
| 103 | > *pxTopOfStack = ( StackType_t ) 0xdeadaffe;
|
| 104 | > pxTopOfStack--;
|
| 105 | > pxTopOfStack--;
|
| 106 | > pxTopOfStack--;
|
| 107 | >
|
| 108 | >
|
| 109 | > int i;
|
| 110 | >
|
| 111 | > for(i=63;i>14;i--) {
|
| 112 | > *pxTopOfStack = ( StackType_t ) i<<8; /* higher registers */
|
| 113 | > pxTopOfStack--;
|
| 114 | > }
|
| 115 | >
|
| 116 | >
|
| 117 | > *pxTopOfStack = ( StackType_t ) 0xaaaaaaaa; /* R14 */
|
| 118 | > pxTopOfStack--;
|
| 119 | > *pxTopOfStack = ( StackType_t ) 0x51aac4de; /* Stack used when task starts goes in R13. */
|
| 120 | > pxStackStart = pxTopOfStack;
|
| 121 | > pxTopOfStack--;
|
| 122 | > *pxTopOfStack = ( StackType_t ) 0x12121212; /* R12 */
|
| 123 | > pxTopOfStack--;
|
| 124 | > *pxTopOfStack = ( StackType_t ) 0x11111111; /* R11 */
|
| 125 | > //*pxTopOfStack = ( StackType_t ) pxOriginalTOS; /* frame pointer to stack address. */
|
| 126 | > pxTopOfStack--;
|
| 127 | > *pxTopOfStack = ( StackType_t ) 0x10101010; /* R10 */
|
| 128 | > pxTopOfStack--;
|
| 129 | > *pxTopOfStack = ( StackType_t ) 0x09090909; /* R9 */
|
| 130 | > pxTopOfStack--;
|
| 131 | > *pxTopOfStack = ( StackType_t ) 0x08080808; /* R8 */
|
| 132 | > pxTopOfStack--;
|
| 133 | > *pxTopOfStack = ( StackType_t ) 0x07070707; /* R7 */
|
| 134 | > pxTopOfStack--;
|
| 135 | > *pxTopOfStack = ( StackType_t ) 0x06060606; /* R6 */
|
| 136 | > pxTopOfStack--;
|
| 137 | > *pxTopOfStack = ( StackType_t ) 0x05050505; /* R5 */
|
| 138 | > pxTopOfStack--;
|
| 139 | > *pxTopOfStack = ( StackType_t ) 0x04040404; /* R4 */
|
| 140 | > pxTopOfStack--;
|
| 141 | > *pxTopOfStack = ( StackType_t ) 0x03030303; /* R3 */
|
| 142 | > pxTopOfStack--;
|
| 143 | > *pxTopOfStack = ( StackType_t ) 0x02020202; /* R2 */
|
| 144 | > pxTopOfStack--;
|
| 145 | > *pxTopOfStack = ( StackType_t ) 0x01010101; /* R1 */
|
| 146 | > pxTopOfStack--;
|
| 147 | 96c98 |
| 148 | < /* When the task starts is will expect to find the function parameter in
|
| 149 | --- |
| 150 | > /* When the task starts is will expect to find the function parameter in
|
| 151 | 98,103c100,103 |
| 152 | < *pxTopOfStack-- = ( StackType_t ) pvParameters; /* R0 */
|
| 153 | <
|
| 154 | < // second last thing: program counter, no normal register on epiphany!
|
| 155 | < *pxTopOfStack-- = ( StackType_t ) pxCode; /* Stack used when task starts goes in R13. */
|
| 156 | <
|
| 157 | <
|
| 158 | --- |
| 159 | > *pxTopOfStack-- = ( StackType_t ) pvParameters; /* R0 */
|
| 160 | >
|
| 161 | > // second last thing: program counter, no normal register on epiphany!
|
| 162 | > *pxTopOfStack-- = ( StackType_t ) pxCode; /* Stack used when task starts goes in R13. */
|
| 163 | 105c105,107 |
| 164 | < /* The last thing onto the stack is the status register, which is set for
|
| 165 | --- |
| 166 | >
|
| 167 | >
|
| 168 | > /* The last thing onto the stack is the status register, which is set for
|
| 169 | 107c109,110 |
| 170 | < *pxTopOfStack = ( StackType_t ) 0x03;
|
| 171 | --- |
| 172 | > *pxTopOfStack = ( StackType_t ) 0x03;
|
| 173 | >
|
| 174 | 109d111 |
| 175 | <
|
| 176 | 111c113 |
| 177 | < /* Some optimisation levels use the stack differently to others. This
|
| 178 | --- |
| 179 | > /* Some optimisation levels use the stack differently to others. This
|
| 180 | 115,117c117,119 |
| 181 | < //*pxTopOfStack = 0;
|
| 182 | < //return pxOriginalTOS;
|
| 183 | < return pxTopOfStack;
|
| 184 | --- |
| 185 | > //*pxTopOfStack = 0;
|
| 186 | > //return pxOriginalTOS;
|
| 187 | > return pxTopOfStack;
|
| 188 | 120c122 |
| 189 | <
|
| 190 | --- |
| 191 | > /*-----THE PROBLEM FUNCTION---------------*/
|
| 192 | 122c124 |
| 193 | < unsigned memprotectregister = e_reg_read(E_REG_MEMPROTECT);
|
| 194 | --- |
| 195 | > unsigned memprotectregister = e_reg_read(E_REG_MEMPROTECT);
|
| 196 | 124,127c126,129 |
| 197 | < //clear last 8 bits
|
| 198 | < memprotectregister &= 0xffffff00;
|
| 199 | < //sets it to the specified value
|
| 200 | < memprotectregister |= mask;
|
| 201 | --- |
| 202 | > //clear last 8 bits
|
| 203 | > memprotectregister &= 0xffffff00;
|
| 204 | > //sets it to the specified value
|
| 205 | > memprotectregister |= mask;
|
| 206 | 129c131 |
| 207 | < e_reg_write(E_REG_MEMPROTECT, memprotectregister);
|
| 208 | --- |
| 209 | > e_reg_write(E_REG_MEMPROTECT, memprotectregister);
|
| 210 | 131c133 |
| 211 | <
|
| 212 | --- |
| 213 | > /*-----------------------------------------------------------*/
|
| 214 | 140,141c142,143 |
| 215 | < e_irq_attach(E_USER_INT, handlers[E_USER_INT]);
|
| 216 | < e_irq_mask(E_USER_INT, E_FALSE);
|
| 217 | --- |
| 218 | > e_irq_attach(E_USER_INT, handlers[E_USER_INT]);
|
| 219 | > e_irq_mask(E_USER_INT, E_FALSE);
|
| 220 | 143,144c145,146 |
| 221 | < e_irq_attach(E_TIMER0_INT, handlers[E_TIMER0_INT]);
|
| 222 | < e_irq_mask(E_TIMER0_INT, E_FALSE);
|
| 223 | --- |
| 224 | > e_irq_attach(E_TIMER0_INT, handlers[E_TIMER0_INT]);
|
| 225 | > e_irq_mask(E_TIMER0_INT, E_FALSE);
|
| 226 | 146,147c148,149 |
| 227 | < e_irq_attach(E_MEM_FAULT, handlers[E_MEM_FAULT]);
|
| 228 | < e_irq_mask(E_MEM_FAULT, E_FALSE);
|
| 229 | --- |
| 230 | > e_irq_attach(E_MEM_FAULT, handlers[E_MEM_FAULT]);
|
| 231 | > e_irq_mask(E_MEM_FAULT, E_FALSE);
|
| 232 | 149,150c151,152 |
| 233 | < e_irq_attach(E_SW_EXCEPTION, handlers[E_SW_EXCEPTION]);
|
| 234 | < e_irq_mask(E_SW_EXCEPTION, E_FALSE);
|
| 235 | --- |
| 236 | > e_irq_attach(E_SW_EXCEPTION, handlers[E_SW_EXCEPTION]);
|
| 237 | > e_irq_mask(E_SW_EXCEPTION, E_FALSE);
|
| 238 | 152,153c154,155 |
| 239 | < e_irq_attach(E_MESSAGE_INT, handlers[E_MESSAGE_INT]);
|
| 240 | < e_irq_mask(E_MESSAGE_INT, E_FALSE);
|
| 241 | --- |
| 242 | > e_irq_attach(E_MESSAGE_INT, handlers[E_MESSAGE_INT]);
|
| 243 | > e_irq_mask(E_MESSAGE_INT, E_FALSE);
|
| 244 | 155c157,159 |
| 245 | < setMemprotectMask(0x0f);
|
| 246 | --- |
| 247 | > vSetupTimer();
|
| 248 | > //condition left for debugging
|
| 249 | > if(globalDelta == 0){
|
| 250 | 157c161 |
| 251 | < vSetupTimer();
|
| 252 | --- |
| 253 | > }else{
|
| 254 | 158a163 |
| 255 | > }
|
| 256 | 161d165 |
| 257 | <
|
| 258 | 170c174 |
| 259 | < e_irq_mask(E_TIMER1_INT, E_TRUE);
|
| 260 | --- |
| 261 | > e_irq_mask(E_TIMER1_INT, E_TRUE);
|
| 262 | 180,184c184,188 |
| 263 | < // There seems to be no working software interrupt, so we send a user-interrupt to ourself
|
| 264 | < e_coreid_t thiscore = e_get_coreid();
|
| 265 | < unsigned row, col;
|
| 266 | < e_coords_from_coreid(thiscore, &row, &col);
|
| 267 | < e_irq_set(row,col,E_USER_INT);
|
| 268 | --- |
| 269 | > // There seems to be no working software interrupt, so we send a user-interrupt to ourself
|
| 270 | > e_coreid_t thiscore = e_get_coreid();
|
| 271 | > unsigned row, col;
|
| 272 | > e_coords_from_coreid(thiscore, &row, &col);
|
| 273 | > e_irq_set(row,col,E_USER_INT);
|
| 274 | 193,199c197,208 |
| 275 | < unsigned int cyclesForTick = CyclesForTick;
|
| 276 | < int delta = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_1) - cyclesForTick; //How much off are we this time?
|
| 277 | < e_ctimer_set(E_CTIMER_1, E_CTIMER_MAX);
|
| 278 | <
|
| 279 | < //We are never to early, case is taken on startup
|
| 280 | < if(delta < 0)
|
| 281 | < delta=0;
|
| 282 | --- |
| 283 | > unsigned int cyclesForTick = CyclesForTick;
|
| 284 | > int delta = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_1) - cyclesForTick; //How much off are we this time?
|
| 285 | > e_ctimer_set(E_CTIMER_1, E_CTIMER_MAX);
|
| 286 | >
|
| 287 | > //We are never to early, case is taken on startup
|
| 288 | >
|
| 289 | > //debugging
|
| 290 | > if(delta < 0){
|
| 291 | >
|
| 292 | > delta=0;
|
| 293 | > }
|
| 294 | > globalDelta = delta;
|
| 295 | 201,202c210,211 |
| 296 | < e_ctimer_set(E_CTIMER_0, cyclesForTick-delta);
|
| 297 | < e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
|
| 298 | --- |
| 299 | > e_ctimer_set(E_CTIMER_0, cyclesForTick-delta);
|
| 300 | > e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
|
| 301 | 208,210c217,219 |
| 302 | < volatile int status;
|
| 303 | < volatile int pc;
|
| 304 | < volatile int no[64]; //collection of all the registers as stored onto the stack
|
| 305 | --- |
| 306 | > volatile int status;
|
| 307 | > volatile int pc;
|
| 308 | > volatile int no[64]; //collection of all the registers as stored onto the stack
|
| 309 | 217,224c226,233 |
| 310 | < TaskHandle_t runningTask = xTaskGetCurrentTaskHandle();
|
| 311 | < TCB_t **tcb = runningTask;
|
| 312 | < struct layout* reg = *tcb;
|
| 313 | <
|
| 314 | < int bitmask = 1 << (rand()%32);
|
| 315 | < int failreg = rand()%64;
|
| 316 | < reg->no[failreg] ^= bitmask;
|
| 317 | < M[4]++;
|
| 318 | --- |
| 319 | > TaskHandle_t runningTask = xTaskGetCurrentTaskHandle();
|
| 320 | > TCB_t **tcb = runningTask;
|
| 321 | > struct layout* reg = *tcb;
|
| 322 | >
|
| 323 | > int bitmask = 1 << (rand()%32);
|
| 324 | > int failreg = rand()%64;
|
| 325 | > reg->no[failreg] ^= bitmask;
|
| 326 | > M[4]++;
|
| 327 | 230,251c239,263 |
| 328 | < switch (interrupt_mode) {
|
| 329 | < case E_TIMER0_INT:
|
| 330 | < vSetupTimer();
|
| 331 | < if( xTaskIncrementTick() != pdFALSE ) {
|
| 332 | < vTaskSwitchContext();
|
| 333 | < }
|
| 334 | < break;
|
| 335 | < case E_SW_EXCEPTION: //triggered extrenally for error injection. Must be that high prority
|
| 336 | < injectErrors();
|
| 337 | < break;
|
| 338 | < case E_USER_INT:
|
| 339 | < vTaskSwitchContext();
|
| 340 | < break;
|
| 341 | < case E_MESSAGE_INT: //message, triggered externally for message transmission
|
| 342 | < irqMsg();
|
| 343 | < break;
|
| 344 | < case E_MEM_FAULT: // written to read-only memory
|
| 345 | < while(1);
|
| 346 | < break;
|
| 347 | < default:
|
| 348 | < break;
|
| 349 | < }
|
| 350 | --- |
| 351 | > switch (interrupt_mode) {
|
| 352 | > case E_TIMER0_INT:
|
| 353 | > vSetupTimer();
|
Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 354 | > xTaskIncrementTick();
|
Anand Prakash | f364467 | 2020-08-21 15:11:08 +0200 | [diff] [blame] | 355 | > updateTick(); |
Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 356 | > vTaskSwitchContext();
|
| 357 | > break;
|
| 358 | > case E_SW_EXCEPTION: //triggered extrenally for error injection. Must be that high prority
|
| 359 | > injectErrors();
|
| 360 | > break;
|
| 361 | > case E_USER_INT:
|
| 362 | > vTaskSwitchContext();
|
| 363 | > break;
|
| 364 | > case E_MESSAGE_INT: //message, triggered externally for message transmission
|
| 365 | > //a message received
|
| 366 | > updateDebugFlag(404);
|
| 367 | > //irqMsg();
|
| 368 | > break;
|
| 369 | > case E_MEM_FAULT: // written to read-only memory
|
| 370 | > updateDebugFlag(2222);
|
| 371 | > //while(1);
|
| 372 | > break;
|
| 373 | > default:
|
| 374 | > break;
|
| 375 | > }
|