Changeset a78cdcd in mainline


Ignore:
Timestamp:
2019-05-19T14:56:33Z (5 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
967e7a1
Parents:
aeeaf0f
git-author:
Jakub Jermar <jakub@…> (2019-05-19 14:50:47)
git-committer:
Jakub Jermar <jakub@…> (2019-05-19 14:56:33)
Message:

Avoid division by zero when time difference is 0

Sometimes, especially under emulation, the CPU is much faster than the
PIT so that the computed time difference is zero. Adjust to the nearest
possible non-zero value to avoid division by zero.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/src/drivers/i8254.c

    raeeaf0f ra78cdcd  
    143143        o2 |= pio_read_8(CLK_PORT1) << 8;
    144144
     145        uint32_t delta = (t1 - t2) - (o1 - o2);
     146        if (!delta)
     147                delta = 1;
     148
    145149        CPU->delay_loop_const =
    146             ((MAGIC_NUMBER * LOOPS) / 1000) / ((t1 - t2) - (o1 - o2)) +
    147             (((MAGIC_NUMBER * LOOPS) / 1000) % ((t1 - t2) - (o1 - o2)) ? 1 : 0);
     150            ((MAGIC_NUMBER * LOOPS) / 1000) / delta +
     151            (((MAGIC_NUMBER * LOOPS) / 1000) % delta ? 1 : 0);
    148152
    149153        uint64_t clk1 = get_cycle();
Note: See TracChangeset for help on using the changeset viewer.