apollo-lhc / cm_mcu

Microcontroller source code for the APOLLO blade for the CMS tracker HL-LHC upgrade.
MIT License
3 stars 2 forks source link

Add semaphore give/take where *apollo_i2c_ctl* is called #151

Closed pkotamnives closed 1 year ago

pkotamnives commented 1 year ago

issue : the semaphore give/take for a right device has not been implemented properly in some modules that rely on apollo_i2c_ctl functions. For instance, the i2c_scan 2 and i2c_scan 4 have gone wild because it has tried to access a semaphore that is already taken by other modules.

% i2c_scan 2
2064034 MONI2C ERR MonitorI2CTask.c:176:PN_BASE read Error ADDR_ACK_ERROR, break (ps=0)
2064079 I2C ERR I2CCommunication.c:198:write fail PERIPHERAL_BUSY
2064079 MONI2C WRN MonitorI2CTask.c:153:Mux write error PERIPHERAL_BUSY, break (instance=CLKR0A,ps=0)
2064080 SRV INF MonitorI2CTask.c:191:stack (CLKR0) = 272(was 280)
2064082 MONI2C WRN MonitorI2CTask.c:153:Mux write error ADDR_ACK_ERROR, break (instance=CLKSI,ps=0)
2064105 MONI2C WRN MonitorI2CTask.c:153:Mux write error ADDR_ACK_ERROR, break (instance=CLKR0A,ps=0)
2064107 MONI2C WRN MonitorI2CTask.c:153:Mux write error ADDR_ACK_ERROR, break (instance=CLKSI,ps=0)
2064130 MONI2C WRN MonitorI2CTask.c:153:Mux write error ADDR_ACK_ERROR, break (instance=CLKR0A,ps=0)
2064145 MONI2C ERR MonitorI2CTask.c:166:SMBUS page failed ADDR_ACK_ERROR
SMBUS command failed  (setting page)
2064192 MONI2C WRN MonitorI2CTask.c:153:Mux write error ADDR_ACK_ERROR, break (instance=CLKR0A,ps=0)
2064194 MONI2C WRN MonitorI2CTask.c:153:Mux write error ADDR_ACK_ERROR, break (instance=CLKSI,ps=0)
2064217 MONI2C WRN MonitorI2CTask.c:153:Mux write error ADDR_ACK_ERROR, break (instance=CLKR0A,ps=0)
2064219 MONI2C WRN MonitorI2CTask.c:153:Mux write error ADDR_ACK_ERROR, break (instance=CLKSI,ps=0)
2064243 MONI2C ERR MonitorI2CTask.c:166:SMBUS page failed ADDR_ACK_ERROR
SMBUS command failed  (setting page)
2064254 MONI2C ERR MonitorI2CTask.c:176:REG_0x0D read Error ADDR_ACK_ERROR, break (ps=0)
2064256 MONI2C WRN MonitorI2CTask.c:153:Mux write error ADDR_ACK_ERROR, break (instance=CLKSI,ps=0)
i2c bus scan, device 2
0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f                                                                                                                                 
00:           3 --  5 -- -- -- -- -- -- -- -- -- --                                                                                                                                 
10: -- -- -- -- -- -- -- -- -- -- -- 1b -- 1d -- --                                                                                                                                 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                                                                                                                                 
30: -- -- -- -- 34 -- 36 37 38 39 -- -- -- -- -- --                                                                                                                                 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                                                                                                                                 
50: 50 -- 52 -- -- -- -- -- -- -- -- -- -- -- -- --                                                                                                                                 
60: -- -- -- -- -- -- -- -- -- 69 6a -- 6c -- -- --                                                                                                                                 
70: 70 -- -- -- -- -- -- 77                                                                                                                                                         
% 

solution: will have to search for all remaining modules that call i2c related functions in order to form a right semaphore pair corresponding to a device that tries to access it. Also, we could have cleaned up the following left-over non-generalized semaphores as well.

[pk568@lnx231 cm_mcu]$ grep -r args.xSem projects/cm_mcu/                                                                                                                           projects/cm_mcu/commands/SensorControl.c:  SemaphoreHandle_t s = ffldaq_f1_args.xSem;
projects/cm_mcu/commands/SensorControl.c:    s = ffldaq_f2_args.xSem;
projects/cm_mcu/commands/SensorControl.c:  SemaphoreHandle_t s = ffldaq_f1_args.xSem;
projects/cm_mcu/commands/SensorControl.c:    s = ffldaq_f2_args.xSem;
projects/cm_mcu/commands/SensorControl.c:  while (xSemaphoreTake(dcdc_args.xSem, (TickType_t)10) == pdFALSE)
projects/cm_mcu/commands/SensorControl.c:  xSemaphoreGive(dcdc_args.xSem);
pwittich commented 1 year ago
% i2c_scan 2
i2c bus scan, device 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- 77

fixed