CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches

◆ instr_inizializza_tutto_da_zero_function()

void instr_inizializza_tutto_da_zero_function ( void  )

Start-up function.

Returns
No Parameters
132 uint8_t canale_, trimmer_,dati_letti[4];
133
134
135 // Configurazione del LED
136 // Configure_Led_rosso(); // Viene configurato il Led rosso
137 // Configure_Led_verde(); // Viene configurato il Led verde
138 // Accendi_led_verde(); // Viene acceso il Led verde
139
140
141 // Configurazione del Timer
142 SystemCoreClockUpdate(); // Viene aggiornato il system core clock
143 SysTick_Config(SystemCoreClock/1000); // Viene generato l'interrupt ogni 1 ms
144
145// TIMER0_setup();
146// TIMER1_setup();
147 LED_remote_control=false; //LEDs controlled by micro
148
149 if(rx_data[6]) NVIC_SystemReset();
150
151
153 scheda_su_scheda_giu=0; //.........................................Bisogner\'a specificare per la eprom del solo per il postfrontend, poi
154
155 //Definizione puntatore sitruzioni
157 LPC_SC->PCONP |= 1 <<15 ; //Accensione GPIO
161
162 // Configurazione delle Periferiche
163 // Configure_Bit_Address_for_CAN();
164
165 I2C_1_Initialize(); // Viene inizializzata la periferica I2C_A
166 I2C_0_Initialize(); // Viene inizializzata la periferica I2C_B
167
168 Configure_Reset_I2C_mux(); //< configuration of reset pin of the I2C_mux, reset it an turn into in idle state, waiting to operate
169// ADC_noding_map();
170
171 Configure_Reset_selection_port_analog_mux_ResIn_ADC_buffer(); //< configuration of reset pin of the 8 analog mux, reset it an turn into in idle state, waiting to operate
173
174
176 CAN_Inizialize(); // Viene inizializzata la periferica CAN
177 SPI_Inizialize(); // Viene inizializzata la periferica SPI
178 EPROM_scrittura_M24C32_64( scheda_su_scheda_giu, I2C_mainboard, Canale_Eprom_mainboard, Memory_mainboard_address_fw << 2 , (uint8_t *) &FW_version);
179
180
183
184 //Risoluzione max, lentezza maggiore
185 ADC_scrittura_registro(0 /*0=ADC0, 1=ADC1*/, 0, ADC_channel_conversion_time_FW_ch0_register, ADC_max_resolution);
186 ADC_scrittura_registro(1 /*0=ADC0, 1=ADC1*/, 0, ADC_channel_conversion_time_FW_ch0_register, ADC_max_resolution);
187 ADC_scrittura_registro(0 /*0=ADC0, 1=ADC1*/, 1, ADC_channel_conversion_time_FW_ch0_register, ADC_max_resolution);
188 ADC_scrittura_registro(1 /*0=ADC0, 1=ADC1*/, 1, ADC_channel_conversion_time_FW_ch0_register, ADC_max_resolution);
189
190
192 ADC_selfcal_zero_scale(I2C_mux_Scheda_su); //selfcal manda in sleep
193
194 ADC_sleep_ON_OFF(0 , 2); //Acendiamo gli ADC
195 ADC_sleep_ON_OFF(1 , 2);
196 EPROM_lettura_M24C32_64(0, I2C_postmainboard, Canale_EPROM_postmainboard_down, Memory_postmainboard_ADCs_always_ON_0_powerdown_1 << 2 , dati_letti);
197 ADC_sleep_off =dati_letti[0];
198 ADC_sleep_ON_OFF(0 , 0 + ADC_sleep_off); //Spegnamo gli ADC se non vanno tenuti sempre ON
200
201
202// int risultato;
203// risultato= ADC_lettura_24bit(0, I2C_mux_Scheda_su,1);
204// risultato= ADC_lettura_24bit(1, I2C_mux_Scheda_giu,1);
205// risultato= ADC_lettura_24bit(0, I2C_mux_Scheda_su,3);
206// risultato= ADC_lettura_24bit(1, I2C_mux_Scheda_giu,3);
207// risultato= ADC_lettura_24bit(0, I2C_mux_Scheda_giu,2);
208// risultato= ADC_lettura_24bit(1, I2C_mux_Scheda_su,2);
209//
210// uint8_t ii;
211// for (ii=32; ii<32+8;ii++){
212// Analog_mux_line_to_select_deselect_for_postmainboard ( 1, ii, 1 );
213// Analog_mux_line_to_select_deselect_for_postmainboard ( 1, ii, 0 );
214// }
215// for (ii=40; ii<41+8;ii++){
216// Analog_mux_line_to_select_deselect_for_postmainboard ( 1, ii, 1 );
217// Analog_mux_line_to_select_deselect_for_postmainboard ( 1, ii, 0 );
218// }
219//preamplifier_determina_trimmer_therma_comp( 1, 1, 180, 0);
220//preamplifier_determina_trimmer_therma_comp( 1, 0, 180, 0);
221
222 // The ouputs of the I2C to parallel, the chip selects, mainly, are all set high
224 I2C_to_Parallel_ini_PCA9554( 0, I2C_to_Parallel_name_2 ); //< swithces are active High
225 I2C_to_Parallel_ini_PCA9554( 0, I2C_to_Parallel_name_3 ); //< swithces are active High
227 I2C_to_Parallel_ini_PCA9554( 1, I2C_to_Parallel_name_2 ); //< swithces are active High
228 I2C_to_Parallel_ini_PCA9554( 1, I2C_to_Parallel_name_3 ); //< swithces are active High
229
230 Aspetta_tanti_ms(500);
231
232 // Set the PGA gain at its minimum (pga input stage at gain 1, DAC pre at gain 1)
233 for( canale_=0; canale_ <6; canale_ ++ ){
234// PGA_set_reset_pre_PGA_gain ( 0, canale_, PGA_set_pre_pga_low_gain ) ;
235// PGA_DAC_GAIN_CROSS( 0, canale_ , 1,1);
236 PGA_GAIN_CROSS( 0, canale_, 1 );
237 PGA_GAIN_CROSS( 1, canale_, 1 );
238 }
239
240
241 //Detector Relays Drivers reset
242 I2C_to_Parallel_set_PCA9554_outputs_values( 0, detector_reset_all_relays_driver.I2C_to_parallel_chip_num, \
243 detector_reset_all_relays_driver.I2C_to_parallel_chip__pin_num); // one pin connect all the 6 driver reset inputs and is fired now
244 //to switch off all the ouputs.
245 Aspetta_tanti_ms(10); //wait_for_ADC_setting for stability
246 I2C_to_Parallel_set_PCA9554_outputs_values( 1, detector_reset_all_relays_driver.I2C_to_parallel_chip_num, \
247 I2C_to_Parallel_ini_set[detector_reset_all_relays_driver.I2C_to_parallel_chip_num]); //Te reset pin is put inactive
248
249 //Dis-Connect the detector
250 for( canale_=0; canale_ <6; canale_ ++ ){
253 }
254 //Detector bias at zero
255 for( canale_=0; canale_ <6; canale_ ++ ){
256 for(trimmer_=0; trimmer_<4;trimmer_++){
257 detector_scrittura_lettura_trimmer_bias( 0, canale_, trimmer_, 128, 1);
258 detector_scrittura_lettura_trimmer_bias( 1, canale_, trimmer_, 128, 1);
259 }
260 }
261//Detectro large resistors
262 for( canale_=0; canale_ <6; canale_ ++ ){
265 }
266//Bias diretto e non invertito
267 for( canale_=0; canale_ <6; canale_ ++ ){
270 }
271
272//Trimmer preamplif a met\'a scala
273 for( canale_=0; canale_ <6; canale_ ++ ){
274 for( trimmer_=0; trimmer_ <4; trimmer_ ++ ){
275//void preamplifier_scrittura_lettura_trimmer(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t trimmer, uint8_t valore, uint8_t scrivi_leggi_1_leggi_0 )
278 }
279}
280
281
282//Trimmer based PGA at attenuator 0.5 and gain almost 1
283 for( canale_=0; canale_ <6; canale_ ++ ){
284 PGA_trimmer_gain (scheda_su, canale_); //Done for the first 6 channels
285 PGA_trimmer_gain (scheda_giu, canale_); //Done for the second 6 channels
286 }
287
288//Termometri in shut down
289 for( canale_=0; canale_ <6; canale_ ++ ){
290 termometro_sht_down( 0, canale_ );
291 termometro_sht_down( 1, canale_ );
292 }
293
294 //Inizializzazione parametri pendenza offset, se impostati
295 uint8_t scheda_su_scheda_giu_;
296 for(scheda_su_scheda_giu_=0;scheda_su_scheda_giu_ <2;scheda_su_scheda_giu_++){
297 for (canale_=0; canale_<6;canale_++){
298 EPROM_lettura_M24C32_64(scheda_su_scheda_giu_ ,I2C_mainboard, canale_, (Memory_preamplifier_slope_calibration_ON_0_OFF_ff <<2), dati_letti);
299 if( *(uint32_t *)dati_letti == 0){//Solo se questa cella ha tutti zeri la calibrazione \'e stata fatta
300 EPROM_lettura_M24C32_64(scheda_su_scheda_giu_ ,I2C_mainboard, canale_, (Memory_preamplifier_address_fine_trimmer_slope_offset <<2), dati_letti);
301 preamplifier_fine_step_trimmer[canale_ + scheda_su_scheda_giu_ *6] = *(int32_t *)dati_letti;
302 EPROM_lettura_M24C32_64(scheda_su_scheda_giu_ ,I2C_mainboard, canale_, (Memory_preamplifier_address_coarse_trimmer_slope_offset <<2), dati_letti);
303 preamplifier_coarse_step_trimmer[canale_ + scheda_su_scheda_giu_ *6] = *(int32_t *)dati_letti;
304 }
305
306 }
307 }
308
309 //Restoring of the detector slopes into the preamplifiers EPROM
310 for( canale_=0; canale_ <6; canale_ ++ ){
313 }
314
315 //Punto di lavoro iniziale, eventuale
318
319// GPIO_PinWrite(LED_Red.porta_num, LED_Red.pin_num, 0); //!< now the red LED is switched ON at startup
320// GPIO_PinWrite(LED_Green.porta_num, LED_Green.pin_num, 1); //!< now the red LED is switched ON at startup
321
322 //Questi serviranno solo per la re-imnizializzazione, dopo powerdown--powerup
323 mio_SCS_Val = LPC_SC->SCS;
324 mio_CCLKCFG_Val= LPC_SC->CCLKCFG;
325 mio_PCLKSEL0_Val=LPC_SC->PCLKSEL0;
326 mio_PCLKSEL1_Val=LPC_SC->PCLKSEL1;
327 mio_CLKSRCSEL_Val=LPC_SC->CLKSRCSEL;
328 mio_PLL0CFG_Val=LPC_SC->PLL0CFG;
329 mio_PLL0_SETUP=LPC_SC->PLL0CON;
330
331 //Powerwon da attivare o no
332 EPROM_lettura_M24C32_64(0, I2C_postmainboard, Canale_EPROM_postmainboard_down, Memory_postmainboard_micro_powdown_active_1_alwaysON_0 << 2 , dati_letti);
333 flag_power_down=dati_letti[0];
334 //Lettura wait time per reset micro
335 EPROM_lettura_M24C32_64(0, I2C_postmainboard, Canale_EPROM_postmainboard_down, Memory_postmainboard_micro_PD_wait_time_in_sec << 2 , dati_letti);
336 if ( (dati_letti[0]>0) || (dati_letti[0]<=60)) POWER_DOWN_MAX_ATTESA = dati_letti[0]*1000; //Il default \'e 5000
337// flag_power_down=0;
338}
void ADC_sleep_ON_OFF(uint8_t up_down, uint8_t ADC_ON_1_OFF_0_NOP_GT1)
ADC is set to sleep or awake.
Definition: Adc.c:350
void ADC_Wakeup(uint8_t up_down)
ADC Wakeup and 24 bits reading.
Definition: Adc.c:388
volatile uint8_t ADC_sleep_off
if 0 ADC in sleep when not working, ADC>1 ADC never sleep
Definition: Adc.c:205
void ADC_selfcal_zero_scale(uint8_t up_down)
ADC self-calibration. ADC needs to be pre-selected.
Definition: Adc.c:296
void ADC_scrittura_registro(char ADC_0_o_1, uint8_t up_down, uint8_t indirizzo_registro_ch0, int32_t value_to_write)
This function allows to read a whatver regsiter of the ADC.
Definition: Adc.c:654
volatile uint8_t rx_data[8]
Received data vector.
Definition: Can.c:318
void CAN_Inizialize(void)
The CAN initialization function.
Definition: Can.c:433
void PGA_GAIN_CROSS(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t PGA_gain_to_set)
Here the 2 digital signals from the trimmer are exploited to set the gain of the input stage of the P...
Definition: DAC_PGA.c:109
void Relays_driver_set_reset_channel(uint8_t scheda_su_giu, uint8_t numero_canale, uint8_t valore_da_trasmettere)
Setting the state of the detector realis: pre connected to detector or intrnal resistor,...
#define Detector_prea_to_GND
#define Detector_bias_diretto
#define Detector_large_RLOAD
void LED_pin_configuration(void)
Red and Green LED pin configuration and reset.
Definition: Gpio.c:284
void ADC_pin_configurations(void)
ADc pins are initialized here.
Definition: Gpio.c:362
void Configure_Reset_selection_port_analog_mux_ResIn_ADC_buffer(void)
Set the reset pins of te analog mux's. Take care: reset=0 means output off.
Definition: Gpio.c:308
void Configure_Reset_I2C_mux(void)
Set the reset pins of te I2C mux, reset the I2C mux and put them into operation.
Definition: Gpio.c:244
void Configure_Bit_Address_for_CAN(void)
Switches for the selection of the hw CAN bus address. Pin are set as input with internal pull-up.
Definition: Gpio.c:415
void I2C_0_Initialize(void)
The I2C_0 initialize.
Definition: I2C_0.c:369
void I2C_1_Initialize(void)
The I2C_1 initialize.
Definition: I2C_1.c:106
#define I2C_mux_Scheda_giu
Selection of the I2C1 for lower board (purtroppo \'e contorto)
Definition: I2C_mux.h:16
#define I2C_mux_Scheda_su
Selection of the I2C0 for the upper board (purtroppo \'e contorto)
Definition: I2C_mux.h:15
void termometro_sht_down(uint8_t scheda_su_scheda_giu, uint8_t canale)
void I2C_to_Parallel_set_PCA9554_outputs_values(uint8_t scheda_su_scheda_giu, uint8_t select_PCA, uint8_t value)
The function I2C_to_Parallel_set_PCA9554_outputs_values allow to set the output pin of the I2C to par...
const uint8_t I2C_to_Parallel_ini_set[4]
...
void I2C_to_Parallel_ini_PCA9554(uint8_t scheda_su_scheda_giu, uint8_t select_PCA)
The I2C_to_Parallel_ini_PCA9554 inits the I2C_to_Parallel_ini_PCA9554 chips by setting all the output...
#define I2C_to_Parallel_name_3
the third PCA
#define I2C_to_Parallel_name_1
the first PCA
#define I2C_to_Parallel_name_2
the second PCA
void Setting_of_the_pointer_for_command_parser(void)
The pointer to the instruction functions is constructed here.
Definition: Istruzioni.c:33
void LED_accendi_spegni(uint8_t LED, uint8_t accendi_1_spegni_0)
This function turns ON or OFF any of the selcted LED.
Definition: Led.c:123
#define LED_RED
Definition: Led.h:10
#define spegni
Definition: Led.h:13
#define LED_GREEN
Definition: Led.h:11
#define accendi
Definition: Led.h:12
void EPROM_lettura_M24C32_64(uint8_t scheda_su_scheda_giu_, uint8_t mainboard_postmainboard, uint8_t canale, short indirizzo_memoria, uint8_t *dati_letti)
Read from preamplifier and on-board flashes.
void EPROM_scrittura_M24C32_64(uint8_t scheda_su_scheda_giu, uint8_t mainboard_postmainboard, uint8_t canale, short indirizzo_memoria, uint8_t *dati_da_scrivere)
Wriring the EEPROM.
void EPROM_store_recover_state_M24C32_64(uint8_t scheda_su_scheda_giu, uint8_t canali_da_regolare, uint8_t set_1_store_0, uint8_t startup_1_user_0)
Store the system state or recover and apply the system state.
void EPROM_restore_detector_slopes_in_pream(uint8_t scheda_su_scheda_giu, uint8_t canale)
[fun_EPROM_store_recover_detector_voltage_M24C32_64]
@ Memory_mainboard_address_fw
Mainboard fw version.
@ Memory_postmainboard_ADCs_always_ON_0_powerdown_1
ADCs powerdown ON if 0, always ON if >1.
@ Memory_postmainboard_micro_PD_wait_time_in_sec
wait time before microcontroller power down since last operation
@ Memory_postmainboard_micro_powdown_active_1_alwaysON_0
microntroller aoutopower OFF if true, always ON if false
@ Memory_preamplifier_slope_calibration_ON_0_OFF_ff
slope trimmer active if zero
@ Memory_preamplifier_address_fine_trimmer_slope_offset
fine slope for trimmer offset
@ Memory_preamplifier_address_coarse_trimmer_slope_offset
coarse slope for trimmer offset
void PGA_trimmer_gain(uint8_t scheda_su_scheda_giu, uint8_t canale)
Here the PGA on mainboard implemented with trimmers in feedback is managed.
volatile uint32_t POWER_DOWN_MAX_ATTESA
upper limit for POWER_DOWN_TEMPO_ATTESA
Definition: Power_down.c:118
#define preamplifier_scrivi_il_trimmer
void SPI_Inizialize(void)
SPI is initialized here. Its ise t at 8 bits and 100 KHz, as default.
Definition: Spi.c:205
void Aspetta_tanti_ms(int millisecondi)
The timing function.
Definition: Timer.c:52
void detector_scrittura_lettura_trimmer_bias(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t trimmer, uint8_t valore, uint8_t scrivi_1_leggi_0)
Setting the value of any trimmer for detector biasing, the contents of the trimmers are stored in the...
Definition: Trimmer.c:238
void preamplifier_scrittura_lettura_trimmer(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t trimmer, uint8_t valore, uint8_t scrivi_1_leggi_0)
Setting the value of any trimmer for preamplifier trimmer, the contents of the trimmers are stored in...
Definition: Trimmer.c:283
void instr_inizializza_tutto_da_zero_function(void)
Start-up function.
#define __INT_DATE__
Here the fw version is created that coincides with the date of compilation.
bool flag_power_down
if flag_power_down is true the u-controller goes in power down after a while
unsigned int FW_version
This is where the FW version is stored.
uint8_t I2C_to_parallel_chip_num
This is the I2C to parallel chip to which the driver is connectted, they are 3.
uint8_t I2C_to_parallel_chip__pin_num
This is the outputo pin to enable.

Definition at line 131 of file inizializzazione.c.

References __INT_DATE__, accendi, ADC_pin_configurations(), ADC_scrittura_registro(), ADC_selfcal_zero_scale(), ADC_sleep_off, ADC_sleep_ON_OFF(), ADC_Wakeup(), Aspetta_tanti_ms(), CAN_Inizialize(), Configure_Bit_Address_for_CAN(), Configure_Reset_I2C_mux(), Configure_Reset_selection_port_analog_mux_ResIn_ADC_buffer(), Detector_bias_diretto, Detector_large_RLOAD, Detector_prea_to_GND, detector_scrittura_lettura_trimmer_bias(), EPROM_lettura_M24C32_64(), EPROM_restore_detector_slopes_in_pream(), EPROM_scrittura_M24C32_64(), EPROM_store_recover_state_M24C32_64(), flag_power_down, FW_version, I2C_0_Initialize(), I2C_1_Initialize(), I2C_mux_Scheda_giu, I2C_mux_Scheda_su, chip_select_type::I2C_to_parallel_chip__pin_num, chip_select_type::I2C_to_parallel_chip_num, I2C_to_Parallel_ini_PCA9554(), I2C_to_Parallel_ini_set, I2C_to_Parallel_name_1, I2C_to_Parallel_name_2, I2C_to_Parallel_name_3, I2C_to_Parallel_set_PCA9554_outputs_values(), LED_accendi_spegni(), LED_GREEN, LED_pin_configuration(), LED_RED, Memory_mainboard_address_fw, Memory_postmainboard_ADCs_always_ON_0_powerdown_1, Memory_postmainboard_micro_PD_wait_time_in_sec, Memory_postmainboard_micro_powdown_active_1_alwaysON_0, Memory_preamplifier_address_coarse_trimmer_slope_offset, Memory_preamplifier_address_fine_trimmer_slope_offset, Memory_preamplifier_slope_calibration_ON_0_OFF_ff, PGA_GAIN_CROSS(), PGA_trimmer_gain(), POWER_DOWN_MAX_ATTESA, preamplifier_scrittura_lettura_trimmer(), preamplifier_scrivi_il_trimmer, Relays_driver_set_reset_channel(), rx_data, Setting_of_the_pointer_for_command_parser(), spegni, SPI_Inizialize(), and termometro_sht_down().

Referenced by main(), and Setting_of_the_pointer_for_command_parser().