# Error Recovery in the Time-Triggered Paradigm with FTT-CAN
## 5 Resource Optimization Process
### LSW Optimization  
The LSW used in the previous algorithms can be optimized, finding a value that makes the system schedulable, when considering all worst case error scenarios. The optimum LSW is then the minimum value that guarantees that the errors are recovered in the following EC, leaving as much bandwidth as possible to the asynchronous traffic. Algorithm 5 carries out this optimization using a binary search approach. The algorithm has as inputs the message set \(M\), \(LEC\), the \(TM\) transmission time (_LTM_), _Guard_, \(\lambda\), and \(\textit{Stop\_criteria}\). _Guard_ is a technology-dependent minimum processing time that must be reserved to allow for nodes to decode and process the _TM_. _Stop_criteria_, expressed as a percentage of \(LEC\), is the desired precision of the final result and allows for stopping the iterative process. The output is the minimum \(LSW\) necessary for making the system schedulable.  
Firstly, the absolute lower (\(LSW_{low}\)) and upper (\(LSW_{HIGH}\)) LSW bounds are computed. These are, respectively, \(C_{MAX}\) and LEC minus the overheads (_LTM_ and _Guard_). Then, in Lines 3-4, the system is tested for feasibility, by giving the maximum time to the LSW. If the test fails, the system is not schedulable. If the system is feasible, the Bisection or Binary Search method is used to find a solution, using as starting point \(LSW_{low}\) and \(LSW_{HIGH}\). As long as the stop criteria are not met (Line 6), the interval is halved (Line 7) and the schedulability assessed using this value as input, using the algorithms 3 and 4 (Line 8). If this test fails the intermediate point becomes the new lower bound for LSW, otherwise it becomes the upper bound (Lines 10 and 11, resp.). Then, the process is iterated using the new bounds.
```
1:\(LSW_{low}\) = CMAX
2:\(LSW_{HIGH}\) = LEC - (_LTM_ +_Guard_)
3:\(Sch\_{high}\) = Test Schedulability using \(LSW_{HIGH}\)
4:if\(Sch\_{high}\) = FALSE then
5: Return -1 end_if
6:while (\(LSW_{HIGH}\) - \(LSW_{low}\) > Stop_criteria \(\times\) LEC) do
7:\(LSW_{tot}\) = (\(LSW_{HIGH}\) + \(LSW_{HIGH}\)) /2
8:\(Sch\_{test}\) = Test Schedulability using \(LSW_{tot}\)
9:if\(Sch\_{test}\) == FALSE then
10:\(LSW_{low}\) = \(LSW_{tot}\) else
11:\(LSW_{HIGH}\) = \(LSW_{tot}\) end_if end_while
12:return\(LSW_{HIGH}\)
```  
**Algorithm 5**_Min_LSW_: Obtain Minimum LSW for schedulable system  
The complexity of this algorithm is basically the one of the classic Response Time Analysis (RTA) iterative method [27]. Since the RTA is repeated for each error scenario (Indirect and Direct Interference) and iterated for each LSW candidate value, the algorithm execution time is the one of RTA, multiplied by the number of error scenarios, and then multiplied by the number of LSW iterations. The number of error scenarios is equal to \(2^{m-1}+2^{m-2}\), when considering \(max\_cycles=max\_cycle=m\) and seven iterations are need to obtain LSW with 1% error (10 iterations for 0.1% acceptable error). This process is executed off-line, the execution time is acceptable, being for instance less than 1 second for the _Updated_SAE_ set. Nevertheless, as this process is computationally intensive, future work will seek to reduce this processing time.