75 initXgate(); /* Fred is a legend, for good reason as of now */
76#endif
77initInterrupts(); /* still last, reset timers, enable interrupts here TODO move this to inside config in an organised way. Set up the rest of the individual interrupts */
78ATOMIC_END(); /* Re-enable any configured interrupts */
92CLKSEL &= PLLSELOFF; /* Switches to base external OSCCLK to ensure PLL is not being used (off out of reset, but not sure if the monitor turns it on before passing control or not) */
93PLLCTL &= PLLOFF; /* Turn the PLL device off to adjust its speed (on by default out of reset) */
94REFDV = PLLDIVISOR; /* 16MHz / (3 + 1) = 4MHz Bus frequency */
140ATD0CTL4 = 0x73; /* Set the ADC clock and sample period for best accuracy */
141ATD0CTL5 = 0xB0; /* Sets justification to right, multiplex and scan all channels. Writing to this causes conversions to begin */
142
143/* And configure them all for analog input */
144ATD1CTL0 = 0x07; /* TODO bring this out of config based on chip variant variable. Sets wrap on 8th ADC because we can't use the other 8 on 112 pin version */
145//ATD0CTL1 = 0x07/* Trigger and interrupt configuration, unused for now. */
146ATD1CTL2 = 0xC0; /* Turns on the ADC block and sets auto flag clear */
203PORTT = 0x00; // Set all ECT pins to off state, only matters for 2-7, and only if being used. TODO mask this dynamically based on decoder type and configured channels.
204/* AD0PT1 You are out of your mind if you waste this on digital Inputs */
205/* AD1PT1 You are out of your mind if you waste this on digital Inputs */
508 /** @todo TODO Take the configuration from the decoder (as is) and mask it such that it does not affect the 6 other channels.
509 * Take the the number of output channels required from configuration and configure that many as outputs
510 * Configure the balance in whatever way is specified in the GPIO configuration - allow second input to be reused as GPI only.
511 *
512 * This stuff affects:
513 * - TIE = 0x01 or 0x03, only. OC channels enabled as required and IC only for RPM/position.
514 * - TIOS = nope, always 0xFC for 2 IC and 6 OC
515 * - TCTL (1,2,3,4) 4 = 0x0? mask off high 4 bits and allow low 4 to come from decoder config/init
516 * - PORTT = zeros, with balance from config
517 * - DDRT = 0,1 inputs, or if unused by decoder, from config
518 */
519
520
521
522// TODO rearrange the order of this stuff and pull enable and interrupt enable out to the last function call of init.
523
524
525/* Timer channel interrupts */
526TIE = 0x03; /* 0,1 IC interrupts enabled for reading engine position and RPM, 6 OC channels disabled such that no injector switching happens till scheduled */
527TFLG = ONES; /* Clear all the flags such that we are up and running before they first occur */
528TFLGOF = ONES; /* Clear all the flags such that we are up and running before they first occur */
529
530/* TODO Turn the timer on and set the rate and overflow interrupt */
531// DLYCT = 0xFF; /* max noise filtering as experiment for volvo this will come from flash config */ // just hiding a wiring/circuit issue...
532TSCR1 = 0x88; /* 0b_1000_1000 Timer enabled, and precision timer turned on */
533TSCR2 = 0x87; /* 0b_1000_0111 Overflow interrupt enable, divide by 256 if precision turned off */
534// PTPSR = 0x03; /* 4 prescaler gives .1uS resolution and max period of 7ms measured */
535PTPSR = 0x1F; /* 32 prescaler gives 0.8uS resolution and max period of 52.4288ms measured */
536// PTPSR = 0x3F; /* 64 prescaler gives 1.6uS resolution and max period of 105ms measured */
537// PTPSR = 0xFF; /* 256 prescaler gives 6.4uS resolution and max period of 400ms measured */
538// PTPSR = 0x7F; /* 128 prescaler gives 3.2uS resolution and max period of 200ms measured */