Mercurial > public > ostc4
annotate Small_CPU/Src/i2c.c @ 250:822416168585 bm-2
Buelmann: new implementation for ceiling
Since my first functional fix in the ceiling computation in
commit ceecabfddb57, I noticed that the computation used a
linear search, that became rather computational expensive after
that commit. The simple question is: why not a binary search?
So, this commit implements the binary search. But there is a long
story attached to this. Comparing ceiling results from hwOS and this
OSTC4 code were very different. Basically, the original OSTC4
algorithm computed the ceiling using the same GFlow to GFhigh
slope, in such a way, that the ceiling was in sync with the
presented deco stops, where the hwOS code presents a GFhigh
based ceiling.
This said, it is more logical when the OSTC4 and hwOS code give
similar results. This new recursive algorithm gives very similar
results for the ceiling compared to hwOS.
To be complete here, the Buelmann ceiling is the depth to which
you can ascend, so that the leading tissue reaches GFhigh. This
also explains why the deepest deco stop is normally deeper than
the ceiling (unless one dives with GF like 80/80).
The code implemented here is rather straightforward recursion.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Thu, 11 Apr 2019 17:48:48 +0200 |
parents | 2b9775f71e30 |
children | 4fe5400567e7 |
rev | line source |
---|---|
38 | 1 #include "baseCPU2.h" |
2 #include "i2c.h" | |
3 #include "scheduler.h" | |
4 | |
5 /* Private typedef -----------------------------------------------------------*/ | |
6 /* Private define ------------------------------------------------------------*/ | |
7 /* Private macro -------------------------------------------------------------*/ | |
8 | |
9 | |
10 // =============================================================================== | |
11 // I2C addresses - see i2c.h | |
165
e9cce686fe41
Minor: Some documentation for new hardware
heinrichsweikamp
parents:
104
diff
changeset
|
12 // =============================================================================== |
38 | 13 |
14 I2C_HandleTypeDef I2cHandle; | |
15 | |
16 | |
17 /* | |
18 static void I2C_Error_Handler(void) | |
19 { | |
20 while(1) | |
21 { | |
22 } | |
23 } | |
24 */ | |
25 | |
26 GPIO_PinState HAL_I2C_Read_Data_PIN(void) | |
27 { | |
28 return HAL_GPIO_ReadPin(I2Cx_SDA_GPIO_PORT,I2Cx_SDA_PIN); | |
29 } | |
30 | |
31 void HAL_I2C_Send_One_CLOCK(void) | |
32 { | |
33 HAL_GPIO_WritePin(I2Cx_SCL_GPIO_PORT, I2Cx_SCL_PIN, GPIO_PIN_RESET); | |
34 HAL_Delay(10); | |
35 HAL_GPIO_WritePin(I2Cx_SCL_GPIO_PORT, I2Cx_SCL_PIN, GPIO_PIN_SET); | |
36 HAL_Delay(10); | |
37 } | |
38 | |
39 GPIO_PinState MX_I2C1_TestAndClear(void) | |
40 { | |
41 I2C_DeInit(); | |
42 HAL_I2C_ManualControl_MspInit(); | |
43 for(int i=0; i<9;i++) | |
44 { | |
45 if(HAL_I2C_Read_Data_PIN() == GPIO_PIN_RESET) | |
46 HAL_I2C_Send_One_CLOCK(); | |
47 else | |
48 break; | |
49 } | |
50 return HAL_I2C_Read_Data_PIN(); | |
51 } | |
52 | |
53 HAL_StatusTypeDef MX_I2C1_Init(void) | |
54 { | |
55 I2cHandle.Instance = I2Cx; | |
56 I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; | |
104 | 57 I2cHandle.Init.ClockSpeed = 100000;//400000; REDUCED for compatibility with HMC5583L + MMA8452Q |
38 | 58 I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; |
104 | 59 I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2; |
38 | 60 I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; |
61 I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; | |
62 I2cHandle.Init.OwnAddress1 = 0x01; | |
63 | |
64 global.I2C_SystemStatus = HAL_I2C_Init(&I2cHandle); | |
82 | 65 HAL_I2CEx_AnalogFilter_Config(&I2cHandle, I2C_ANALOGFILTER_ENABLED); |
100 | 66 HAL_I2CEx_ConfigDigitalFilter(&I2cHandle,0x0F); |
67 | |
68 if(global.dataSendToSlavePending) | |
69 { | |
70 scheduleSpecial_Evaluate_DataSendToSlave(); | |
71 } | |
241
2b9775f71e30
cleanup: factor out I2C1_Status() and cleanup type
Jan Mulder <jlmulder@xs4all.nl>
parents:
239
diff
changeset
|
72 return global.I2C_SystemStatus; |
38 | 73 } |
74 | |
75 | |
76 void I2C_DeInit(void) | |
77 { | |
78 HAL_I2C_DeInit(&I2cHandle); | |
79 } | |
80 | |
239
e4207f0aaa4b
cleanup: factor out dataSendToSlaveStopEval
Jan Mulder <jlmulder@xs4all.nl>
parents:
238
diff
changeset
|
81 static uint8_t i2c_errors = 0; |
38 | 82 |
83 void I2C_Error_count(void) | |
84 { | |
85 i2c_errors++; | |
86 } | |
87 | |
88 HAL_StatusTypeDef I2C_Master_Transmit( uint16_t DevAddress, uint8_t *pData, uint16_t Size) | |
89 { | |
90 if(global.I2C_SystemStatus != HAL_OK) | |
238
a9d798e8c11f
cleanup, bugfix: do not mask I2C_SystemStatus with local variable
Jan Mulder <jlmulder@xs4all.nl>
parents:
182
diff
changeset
|
91 return global.I2C_SystemStatus; |
38 | 92 |
182 | 93 global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size, 2); |
38 | 94 if(global.I2C_SystemStatus != HAL_OK) |
95 { | |
96 I2C_Error_count(); | |
97 } | |
88 | 98 |
241
2b9775f71e30
cleanup: factor out I2C1_Status() and cleanup type
Jan Mulder <jlmulder@xs4all.nl>
parents:
239
diff
changeset
|
99 return global.I2C_SystemStatus; |
38 | 100 } |
101 | |
102 HAL_StatusTypeDef I2C_Master_Receive( uint16_t DevAddress, uint8_t *pData, uint16_t Size) | |
103 { | |
104 if(global.I2C_SystemStatus != HAL_OK) | |
238
a9d798e8c11f
cleanup, bugfix: do not mask I2C_SystemStatus with local variable
Jan Mulder <jlmulder@xs4all.nl>
parents:
182
diff
changeset
|
105 return global.I2C_SystemStatus; |
38 | 106 |
238
a9d798e8c11f
cleanup, bugfix: do not mask I2C_SystemStatus with local variable
Jan Mulder <jlmulder@xs4all.nl>
parents:
182
diff
changeset
|
107 global.I2C_SystemStatus = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 10); |
a9d798e8c11f
cleanup, bugfix: do not mask I2C_SystemStatus with local variable
Jan Mulder <jlmulder@xs4all.nl>
parents:
182
diff
changeset
|
108 if(global.I2C_SystemStatus != HAL_OK) |
38 | 109 { |
110 I2C_Error_count(); | |
111 } | |
112 | |
238
a9d798e8c11f
cleanup, bugfix: do not mask I2C_SystemStatus with local variable
Jan Mulder <jlmulder@xs4all.nl>
parents:
182
diff
changeset
|
113 return global.I2C_SystemStatus; |
38 | 114 } |