CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches
I2C_mux.c
Go to the documentation of this file.
1// DOCUMENTAZIONE DOXYGEN
2/// \file
3
4/*! \page I2C_mux_page
5*\brief <span style="color:red;"> <b> The mux which distributes the I2C in the board </b> </span>
6*\tableofcontents
7
8 \b SUMMARY:
9*\arg \ref user_use_of_I2C_mux
10
11
12*\section user_use_of_I2C_mux User use of I2C mux
13<hr width="75%" size="10" align="left">
14\n The managing of this chip is made with only one function, the I2C_mux_select_ch() with input parameters: <i> uint8_t scheda_su_scheda_giu, uint8_t I2C_mainboard, uint8_t canale_da_abilitare</i>
15that allows to select which of the 4 possibile I2C channels has to be used. The scheme od the mux, the \b TCA9546APWR, is as in \ref Figure_I2C_mux. It has a reset
16pin that is set as a first action at the call of the function. The chip has 4 I2C's to which send the input I2C. Thhe outpus can be individually activated or
17can be activated in parallel. Our choice is for the individual selection. Obviously, there is also the possibility to de-activate all the outputs.
18\n The board manages 2 boxes so the first parameter \b scheda_su_scheda_giu is which of the boxes we want consider. \b scheda_su_scheda_giu
19can be \b 0 or \b 1.
20\n The parameter \b canale_da_abilitare allows to select which of the 4 channels is to be enabled:
21 - #I2C_mux_disabilita_tutto , this unset all the channels
22 - #I2C_mux_abilita_0 , this enables channel 0
23 - #I2C_mux_abilita_1 , this enables channel 1
24 - #I2C_mux_abilita_2 , this enables channel 2
25 - #I2C_mux_abilita_3 , this enables channel 3
26
27\n The parameter \b scheda_su_scheda_giu allows to select which of the 2 board to communicate:
28 - #I2C_mux_Scheda_su
29 - #I2C_mux_Scheda_giu
30
31 \n Whenever the I2C is used, the I2C_mux must be set as a first step. Then, the I2C_mux is the last to be idled:
32
33<span style="color:orange;"> <I>
34\code {.c}
35 function_which_set_some_device( I2C_mux_Scheda_su, device_to_set){
36
37 I2C_mux_select_ch( I2C_mux_Scheda_su, I2C_mainboard, I2C_to_enable_for_the_device); //I2C_to_enable_for_the_device is any of the above I2C_mux_abilita_x
38
39 //Now what we need to do
40
41 I2C_mux_select_ch( I2C_mux_Scheda_su, I2C_mainboard, I2C_mux_disabilita_tutto); //Now deselect the chip
42 }
43\endcode
44</I> </span>
45
46\n We set A0 to \b 1 in \ref Figure_I2C_address_of_I2C_mux below and the I2C address of the chip is then (considering that the 3 MSb are fixed to 1) \b 0x71:
47
48*\anchor Figure_I2C_address_of_I2C_mux
49*\image html I2C_address_of_I2C_mux.png "Figure_I2C_address_of_I2C_mux 1: I2C base address of I2C mux" width=30%
50*\image latex I2C_address_of_I2C_mux.png "Figure_I2C_address_of_I2C_mux 1: I2C base address of I2C mux" width=30%
51
52The address set on the mainboard is defined in:
53 - #I2C_mux_address_mainboard.
54
55
56 \n The datasheet of the I2C mux is here: <a href="./File_pdf/tca9546a_multiplexer_i2c.pdf" target=_blank><b>TCA9546A datasheet</b></a> .
57
58 The codes for mamnaging the mux are:
59 - \ref I2C_mux.h
60 - \ref I2C_mux.c.
61
62*\anchor Figure_I2C_mux
63*\image html I2C_mux_TCA9546.png "FigureI2C_mux 2: I2C mux scheme" width=70%
64*\image latex I2C_mux_TCA9546.png "FigureI2C_mux 2: I2C mux scheme" width=70%
65
66
67
68<!-- pappa -->
69
70*/
71
72
73#include "tutti_gli_header.h"
74
75//#define I2C_mux_disabilita_tutto 0
76//#define I2C_mux_abilita_0 1
77//#define I2C_mux_abilita_1 I2C_mux_abilita_0 * 2
78//#define I2C_mux_abilita_2 I2C_mux_abilita_1 * 2
79//#define I2C_mux_abilita_3 I2C_mux_abilita_2 * 2
80
81ARM_DRIVER_I2C * I2C_mux;
82
83
84//Queste 2 andranno cancellate
85uint8_t scheda_su_scheda_giu_provvisorio=I2C_mux_Scheda_giu;
86volatile uint8_t scheda_su_scheda_giu=I2C_mux_Scheda_giu;
87
88
89 /*! \brief The I2C mux
90
91 *\param[in] scheda_su_scheda_giu one of the 2 boards that the postfrontend manages
92 *\param[in] mainboard_postmainboard for selecting the I2C mux on mainboard, if I2C_mainboard,
93 or postmainboard, if I2C_postmainboard
94 *\param[in] canale_da_abilitare the channel of the mux to be enabled
95 *\return No Parameters
96
97 *\snippetlineno I2C_mux.c fun_I2C_mux_select_ch
98 */
99 //! <!-- [fun_I2C_mux_select_ch] -->
100void I2C_mux_select_ch( uint8_t scheda_su_scheda_giu, uint8_t mainboard_postmainboard , uint8_t canale_da_abilitare){
101 tappo=0;
102 if (scheda_su_scheda_giu==I2C_mux_Scheda_giu){ /* Determine which I2C to use for one board or the other */
103 I2C_mux = &Driver_I2C1; //board down
104 GPIO_PinWrite(Reset_I2C_mux_down.porta_num, Reset_I2C_mux_down.pin_num, 0); //Let's reset the mux
105 GPIO_PinWrite(Reset_I2C_mux_postfrontend_down.porta_num, Reset_I2C_mux_postfrontend_down.pin_num, 0); //Let's reset the mux of the postfrontend
107 GPIO_PinWrite(Reset_I2C_mux_down.porta_num, Reset_I2C_mux_down.pin_num, 1);
108 GPIO_PinWrite(Reset_I2C_mux_postfrontend_down.porta_num, Reset_I2C_mux_postfrontend_down.pin_num, 1); //Let's reset the mux of the postfrontend
109 }else if (scheda_su_scheda_giu>=I2C_mux_Scheda_su){
110 I2C_mux = &Driver_I2C0; //board up
111 GPIO_PinWrite(Reset_I2C_mux_up.porta_num, Reset_I2C_mux_up.pin_num, 0); //Let's reset the mux
112 GPIO_PinWrite(Reset_I2C_mux_postfrontend_up.porta_num, Reset_I2C_mux_postfrontend_up.pin_num, 0); //Let's reset the mux of the postfrontend
114 GPIO_PinWrite(Reset_I2C_mux_up.porta_num, Reset_I2C_mux_up.pin_num, 1);
115 GPIO_PinWrite(Reset_I2C_mux_postfrontend_up.porta_num, Reset_I2C_mux_postfrontend_up.pin_num, 1); //Let's reset the mux of the postfrontend
116 }
117
118 //I2C_mux_address
119 if ( (scheda_su_scheda_giu==I2C_mux_Scheda_giu)||(scheda_su_scheda_giu>=I2C_mux_Scheda_su)){
120 if(mainboard_postmainboard==I2C_mainboard){
121 I2C_mux -> MasterTransmit( I2C_mux_address_mainboard, &canale_da_abilitare, 1,false);
122 while( I2C_mux -> GetStatus().busy); // White transmission complete
124 I2C_mux -> MasterReceive( I2C_mux_address_mainboard, &tappo, 1,false); //Read back, not needed
125 while( I2C_mux -> GetStatus().busy);
126 }else if(mainboard_postmainboard==I2C_postmainboard){
127 if(scheda_su_scheda_giu == I2C_mux_Scheda_giu){
128 //! <!-- [error_example] -->
129 I2C_mux -> MasterTransmit( I2C_mux_address_postmainboard_down, &canale_da_abilitare, 1,false);
130 while( I2C_mux -> GetStatus().busy); // White transmission complete
132 //! <!-- [error_example] -->
133 I2C_mux -> MasterReceive( I2C_mux_address_postmainboard_down, &tappo, 1,false); //Read back, not needed
134 while( I2C_mux -> GetStatus().busy);
135 }else{
136 I2C_mux -> MasterTransmit( I2C_mux_address_postmainboard_up, &canale_da_abilitare, 1,false);
137 while( I2C_mux -> GetStatus().busy); // White transmission complete
139 I2C_mux -> MasterReceive( I2C_mux_address_postmainboard_up, &tappo, 1,false); //Read back, not needed
140 while( I2C_mux -> GetStatus().busy);
141 }
142 }
143 }
144
145}
146 //! <!-- [fun_I2C_mux_select_ch] -->
147
148
149
volatile uint32_t Error_bad_operation
exploited to mark the errors
void ERROR_codifica_errore(uint8_t scheda_su_scheda_giu, unsigned char error_addres, unsigned char code_to_shift, uint8_t reset_count_se_0)
If an error is found its flag is codified here.
@ I2C_Error_I2C_mux
Trouble with I2C mux communication.
@ error_address_I2C0
Error register A for I2C0.
const porta_pin_def Reset_I2C_mux_down
location of the reset pin of the I2C_mux of frontend board su or giu
Definition: Gpio.c:109
const porta_pin_def Reset_I2C_mux_up
location of the reset pin of the I2C_mux of frontend board su or giu
Definition: Gpio.c:108
const porta_pin_def Reset_I2C_mux_postfrontend_up
location of the reset pin of the I2C_mux of post-frontend board su or giu
Definition: Gpio.c:158
const porta_pin_def Reset_I2C_mux_postfrontend_down
location of the reset pin of the I2C_mux of post-frontend board su or giu
Definition: Gpio.c:159
void I2C_mux_select_ch(uint8_t scheda_su_scheda_giu, uint8_t mainboard_postmainboard, uint8_t canale_da_abilitare)
The I2C mux.
Definition: I2C_mux.c:100
#define I2C_mux_address_postmainboard_down
I2C 7 bits address of the postmainboard up I2C_mux.
Definition: I2C_mux.h:9
#define I2C_mux_Scheda_giu
Selection of the I2C1 for lower board (purtroppo \'e contorto)
Definition: I2C_mux.h:16
#define I2C_mux_address_postmainboard_up
I2C 7 bits address of the postmainboard down I2C_mux.
Definition: I2C_mux.h:8
#define I2C_mux_address_mainboard
I2C 7 bits address of the mainboard I2C_mux.
Definition: I2C_mux.h:7
#define I2C_mux_Scheda_su
Selection of the I2C0 for the upper board (purtroppo \'e contorto)
Definition: I2C_mux.h:15
void Aspetta_tanti_ms(int millisecondi)
The timing function.
Definition: Timer.c:52