How to deal with a wrapping counter in embedded C

后端 未结 11 868
时光取名叫无心
时光取名叫无心 2021-02-05 14:23

I need to deal with a counter that gives me ticks for my application. The counter is 32bits so what i need to know is how to deal with it when it wraps. for example:

I h

11条回答
  •  一整个雨季
    2021-02-05 15:07

    Assuming you're dealing with unsigned types, you can check for wrapping pretty easily --

    if (timestamp + shifftime < timestamp) 
        it_wrapped();
    

提交回复
热议问题