Rtimer can meet the needs of precise timing, but there is no common next pointer to hook the subsequent nodes. In order to reduce the rtimer interrupt, it is good to hook up an rtimer structure. Most timers have a bit width of 16 bits, so the frequency of rtimer must be less than 30kHz.
one. Rtimer useThe introduction of rtimer in Contiki system can meet the needs of precise timing. Some time-sensitive modules (such as MAC protocol) depend on rtimer. Unlike the coarse-grained etimer (usually 100Hz), rtimer is a fine-grained (usually 10kHz) timer. According to experience, fine-grained timers are particularly prone to consume CPU resources if interrupts are frequent. For this reason, contiki designs interruptors to reduce interrupts as much as possible. Most applications use read timer counts.
two. data structureThe data structure of Rtimer is shown in Figure 1. The time assignment is the time of the next timer timeout interrupt, func is the callback function of the timer timeout interrupt, and ptr is the data pointer passed to the callback function.
From Figure 1, it is found that rtimer does not have a common next pointer to hook subsequent nodes. Indeed, contiki can only attach an rtimer structure to reduce the burst of rtimer interrupts, as shown in Figure 2. If two or more rtimer structures are attached at the same time, the latest hook is valid, and other rtimer structures will be lost, as explained in Figure 3.
This mechanism of hooking up only one rtimer makes the design very simple, and the hardware timer interrupt only breaks out when needed, greatly reducing the CPU load. Of course, it also brings a limitation, only the interrupt callback function of the rtimer timer can be serially used, that is, there is no queuing function.
three. Rtimer interrupt timingFigure 4 shows the interrupt timing of rtimer. When rtimer_arch_schedule() is called, it sets the interrupt interval duration timeout of the rtimer timer. The interrupt service routine rtimer_irq_handler calls the rtimer-"callback() callback function.
Need to pay special attention to 2 points: interrupts are only allowed to occur once, that is, rtimer_arch_schedule() enables interrupts, and rtimer_irq_handler() disables interrupts; rtimer-"callback() is run in interrupt state, paying special attention to preventing race errors, for example, calling Process_poll() is legal, and process_post() is illegal.
four. Rtimer portingWith the theory of rtimer mentioned above, it is easier to port rtimer, that is, rtimer-arch.c and rtimer-arch.h based on MCU.
It is important to note that most timers (especially 8-bit MCUs) have a bit width of 16 bits, that is, MAX=65535, while the MAC protocol often requires a timing period of more than 1 second, so the frequency of the rtimer must be less than 30 kHz. A good value is 10 kHz, which guarantees better accuracy (100 us intervals) and a full scale of 6.5 seconds, which can be adapted to most applications.
In addition, most applications need to randomly undo and restart rtimer, which can be implemented by adding two functions: rtimer_arch_disable_irq() and rtimer_arch_enable_irq().
With more than 15+ yrs rich MFG experience, you can definitely trust in and cooperate with.
Provide you with the supply of Personal Protective Equipment. to help you safely get back to your daily routine.
Our products include pulse Oximeter Finger, Forehead Thermometer, Automatic foam soap dispenser, etc.
Our strict quality control protocol thoroughly vets every aspect of production, storage, and shipments all the way way to our end customers.
nano spray gun, nano spray gun disinfectant, nano spray machine
TOPNOTCH INTERNATIONAL GROUP LIMITED , https://www.mic11.com