| 158 | } |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | * @brief Computes the sum of two cycle values |
---|
| 162 | * |
---|
| 163 | * This function computes a sum between cycles |
---|
| 164 | * such that it respects wrapping (at 8000 cycles). |
---|
| 165 | * |
---|
| 166 | * The passed arguments are assumed to be valid cycle numbers, |
---|
| 167 | * i.e. they should be wrapped at 8000 cycles |
---|
| 168 | * |
---|
| 169 | * See addTicks |
---|
| 170 | * |
---|
| 171 | * @param x First cycle value |
---|
| 172 | * @param y Second cycle value |
---|
| 173 | * @return the sum x+y, wrapped |
---|
| 174 | */ |
---|
| 175 | static inline unsigned int addCycles(unsigned int x, unsigned int y) { |
---|
| 176 | unsigned int sum = x + y; |
---|
| 177 | #ifdef DEBUG |
---|
| 178 | if (x >= CYCLES_PER_SECOND || y >= CYCLES_PER_SECOND ) { |
---|
| 179 | debugWarning("At least one argument not wrapped correctly: x=%u, y=%u\n",x,y); |
---|
| 180 | } |
---|
| 181 | #endif |
---|
| 182 | |
---|
| 183 | // since both x and y are < CYCLES_PER_SECOND this should be enough to unwrap |
---|
| 184 | if (sum > CYCLES_PER_SECOND) sum -= CYCLES_PER_SECOND; |
---|
| 185 | return sum; |
---|