Skip to content

Commit

Permalink
Dealing with Millis Documentation and git rebase (#18) (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonBrave authored Oct 29, 2024
2 parents 146a854 + be64ada commit 799ca81
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ The standard embedded firmware library is a common library for Waterloo Rocketry
spi_driver.rst
pwm_driver.rst
adc_driver.rst
millis.rst

main_func.rst
46 changes: 46 additions & 0 deletions doc/millis.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Timer Module Documentation
===========================

Overview
--------
This module provides basic timer functionalities, such as initializing Timer0, handling interrupts, and tracking milliseconds since the timer was started.

.. _timer0_init:

timer0_init
-----------
Initializes Timer0 for time tracking. This function must be called before using any other timer-related functionality.

- Enables Timer0 interrupt.
- Sets the timer to 8-bit mode.
- Driven by a 500 kHz clock.
- Ensures the timer is synchronized to the system clock.

.. code-block:: c
void timer0_init(void);
.. _timer0_handle_interrupt:

timer0_handle_interrupt
------------------------
This function should be called from the main Interrupt Service Routine (ISR) whenever the Timer0 interrupt is triggered. It updates the internal time counter. Note that this function does **not** clear the interrupt flag (`PIR3bits.TMR0IF`); this must be done at the ISR level.

.. code-block:: c
void timer0_handle_interrupt(void);
.. _millis:

millis
------
Returns the number of milliseconds since `timer0_init()` was called. This is a safe function that disables interrupts momentarily to return a consistent value.

.. code-block:: c
uint32_t millis(void);
Definitions and Notes
---------------------
- **ISR Responsibility**: The function `timer0_handle_interrupt()` does not clear the Timer0 interrupt flag. This is the responsibility of the top-level ISR.
- **Time Precision**: The module keeps track of milliseconds, and the value returned by `millis()` reflects the time passed since the timer was initialized.

0 comments on commit 799ca81

Please sign in to comment.