aboutsummaryrefslogtreecommitdiffstats
path: root/src/avr/timer.c
Commit message (Collapse)AuthorAgeFilesLines
* irq: Support sleeping when mcu is idleKevin O'Connor2017-07-171-1/+25
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* build: Use compile_time_request system for init, tasks, and shutdownKevin O'Connor2017-05-261-3/+3
| | | | | | | | Avoid using linker magic to define the init, task, and shutdown functions. Instead, use the compile_time_request system. This simplifies the build and produces more efficient code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Invert diff in timer checksKevin O'Connor2017-04-031-8/+6
| | | | | | Minor optimization on avr. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* timer: Remove dup timer_shutdown codeKevin O'Connor2017-03-311-10/+0
| | | | | | | Commmit a1c61563 renamed timer_shutdown() to timer_reset() but neglected to delete timer_shutdown(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Fix bug causing timer_read_time() to not be in sync with schedulerKevin O'Connor2017-03-311-10/+19
| | | | | | | | | | | | | | | Commit 16e3dbb1 changed the avr implementation of timer_read_time(). Unfortunately, it raised the possibility for timer_read_time() to be out of sync with the scheduler's understanding of the current time. In particular, it was common for the timer irq to overflow the 16bit hardware counter once at startup, and this would lead to timer_read_time() always returning a time ~4ms ahead of the scheduler on 16Mhz chips. This resulted in "Move queue empty" errors. To resolve this issue, only increment timer_high from timer_periodic() and make sure the timer irqs start immediately after timer_init(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Integrate timer_try_set_next() into the irq handlerKevin O'Connor2017-03-301-43/+30
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Move timer dispatch loop to board codeKevin O'Connor2017-03-301-6/+14
| | | | | | | | Rename sched_timer_kick() to sched_timer_dispatch() and move its loop into its callers in the board code. This eliminates the need to export timer_try_set_next() from the board code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* timer: Make sure to reset the timer repeat checks on a shutdownKevin O'Connor2017-03-301-9/+10
| | | | | | | Reset the timer repeat checks on shutdown, otherwise it is possible to get into an infinite shutdown loop. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Remove F_CPU compile time definitionKevin O'Connor2017-03-301-2/+2
| | | | | | | | Directly use the Kconfig defined CONFIG_CLOCK_FREQ in the code and avoid defining F_CPU. Also, remove the unnecessary O2 option - that is already the default from the main makefile. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Minor optimization for timer_read_time() / timer_periodic()Kevin O'Connor2017-03-271-2/+2
| | | | | | Tell the compiler that the TOV1 bit is rarely set. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Be explicit with loading of the waketime variableKevin O'Connor2017-03-261-1/+1
| | | | | | | | | Explicilty load the timer waketime variable into local variables in sched_timer_kick(). Change the optimization level from Os to O2. This helps gcc to avoid unnecessary reloads from memory in the common stepper_event() case. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Introduce optimized timer_is_before()Kevin O'Connor2017-03-261-6/+19
| | | | | | | | | Provide hand-coded assembler for timer_is_before() on AVR as that code is used frequently in the time-critical timer dispatch loop and gcc doesn't do a good job at compiling that comparison code. Remove the no longer needed waketime+1 hack from reschedule_timer(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* timer: Allow board code to define its own timer_is_before implementationKevin O'Connor2017-03-261-0/+9
| | | | | | | | | | | | Move sched_is_before() from sched.c to timer_is_before() in the board specific timer code. This allows the board code to provide its own definition. Also, remove the sched_from_us() and sched_read_time() wrapper functions and change the callers to directly invoke timer_from_us() / timer_read_time(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* timer: Organize timer_try_set_next() with priority for repeat timersKevin O'Connor2017-03-261-19/+26
| | | | | | Organize the code flow to optimize for repeat timers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* generic: Move generic parts of sam3x8e timer.c to generic directoryKevin O'Connor2017-03-111-1/+0
| | | | | | | | Most of sam3x8e/timer.c is going to be platform agnostic for any board with standard irq handling. Move the generic code into a new file generic/timer.c. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Avoid rescheduling the currently active timerKevin O'Connor2017-03-101-30/+12
| | | | | | | | | It's tricky to reschedule the timer irq correctly (due to race conditions with the irq) and in practice it's very rarely needed. Handle the special cases in the generic sched.c code so that the board code doesn't have to handle it. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Optimize 16bit timer upscalingKevin O'Connor2017-03-101-22/+24
| | | | | | | The hardware timer overflow bit can be used to optimize the conversion from 16bit timers to 32bit timers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* build: Define DECL_CONSTANT mechanism for defining exported constantsKevin O'Connor2016-12-231-0/+3
| | | | | | | | | Add a DECL_CONSTANT macro to allow the firmware to define constants that are to be exported to the host during the "identify" phase. This replaces the existing hardcoded mechanism of scanning the Kconfig header file for certain constants. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* timer: Rework AVR timer priority code to use time instead of event countKevin O'Connor2016-10-191-11/+23
| | | | | | | | | Rework the timer prioritization code so that is compares against the current time instead of the number of repeat timers in a given interrupt. This makes the code slightly faster and it should provide better protection against task starvation. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* irq: Allow boards to define the return type of irq_save()Kevin O'Connor2016-06-131-2/+2
| | | | | | | | The AVR wants a uint8_t return type for irq_save(), but other architectures will generally prefer int. Allow the board to configure the size of the flag by introducing an irqstatus_t typedef. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* generic: Move board timer.h files into generic/misc.hKevin O'Connor2016-06-131-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Add config option to clear the CPU prescalerKevin O'Connor2016-06-051-0/+9
| | | | | | | Some AVR chips ship with a 1/8th clock divisor set. Add a compile time option to manually clear this field at startup. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* sched: Change sched_from_ms() to sched_from_us()Kevin O'Connor2016-06-021-5/+5
| | | | | | | Some code may require micro-second precision so update sched_from_ms() to use micro-seconds. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* timer: Move union u32_u16_u from compiler.h to avr/timer.cKevin O'Connor2016-06-011-1/+4
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* Initial commit of source code.Kevin O'Connor2016-05-251-0/+171
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>