#include "allocator.h"
#include "rit_types.h"
#include "types.h"
#include <stdbool.h>
Go to the source code of this file.
◆ RIT_AddJob()
Definition at line 104 of file rit_job.c.
105{
109
110
113
115}
CL_Error CL_ListPushBack(CL_List *const list, const void *const elem)
Adds an element at the end of the list.
_PRIVATE CL_List * jobs
Array of jobs to execute in the RIT interrupt handler.
_DECL_EXTERNALLY u32 base_ival
External variable that stores the base interval between each RIT interrupt.
_USED_EXTERNALLY u32 counter_reset_value
@ RIT_ERR_DURING_PUSHBACK
An error occurred during the push back of the job in the list.
◆ RIT_ClearJobs()
void RIT_ClearJobs |
( |
void |
| ) |
|
Clears the job queue.
Definition at line 175 of file rit_job.c.
176{
179}
void CL_ListClear(CL_List *const list)
Removes all elements from the list.
◆ RIT_Deinit()
De-initializes the RIT, by removing every job and disconnecting power.
Definition at line 43 of file rit.c.
44{
46 NVIC_DisableIRQ(RIT_IRQn);
48}
void POWER_TurnOffPeripheral(u8 bit)
Turns off a peripheral.
_DECL_EXTERNALLY void free_jobs_list(void)
◆ RIT_Disable()
void RIT_Disable |
( |
void |
| ) |
|
Disables the RIT entirely (stops counting).
Definition at line 55 of file rit.c.
56{
58}
#define CLR_BIT(reg, bit)
◆ RIT_DisableJob()
Exclude this job from the RIT handler queue.
Definition at line 85 of file rit_job.c.
86{
88 if (list_job->job == job)
89 {
90 list_job->enabled = false;
91
92
93
94 if (list_job->interval == counter_reset_value)
95 recalculate_reset_value();
96
97 return RIT_ERR_OK;
98 }
99 });
100
102}
#define CL_LIST_FOREACH_PTR(__type, __name, __list,...)
Macro to iterate over the elements of the list with a pointer to the current element.
@ RIT_ERR_JOB_NOT_FOUND
The job specified was not found in the handler queue.
◆ RIT_Enable()
Enables the RIT counting.
Definition at line 50 of file rit.c.
51{
53}
#define SET_BIT(reg, bit)
◆ RIT_EnableJob()
Include this job in the RIT handler queue.
Definition at line 65 of file rit_job.c.
66{
68 if (list_job->job == job)
69 {
70 list_job->enabled = true;
71
72
73
74 if (list_job->interval > counter_reset_value)
75 counter_reset_value = list_job->interval;
76
77 return RIT_ERR_OK;
78 }
79 });
80
81
83}
◆ RIT_GetIntervalMs()
u32 RIT_GetIntervalMs |
( |
void |
| ) |
|
Returns the interval in millis that RIT uses for its interrupts.
Definition at line 65 of file rit.c.
66{
68}
_USED_EXTERNALLY u32 base_ival
◆ RIT_GetJobMultiplierFactor()
Returns the multiplier factor for the given job.
- Parameters
-
job | The job to get the multiplier factor from |
- Returns
- u8 The multiplier factor
Definition at line 143 of file rit_job.c.
144{
146 if (list_job->job == job)
148 })
149
150 return 0;
151}
◆ RIT_GetJobsCount()
u32 RIT_GetJobsCount |
( |
void |
| ) |
|
Returns the number of jobs in the job queue.
Definition at line 138 of file rit_job.c.
139{
141}
u32 CL_ListSize(const CL_List *const list)
Gets the number of elements in the list.
◆ RIT_Init()
Initialize the RIT.
- Parameters
-
alloc | The memory allocator to use for the RIT job list. |
ival_ms | Interval in millis between each RIT interrupt. |
int_priority | Debouncer interrupt priority (0 (highest), 15 (lowest)). If set to INT_PRIO_DEF, the default priority will be used. |
- Note
- The RIT has a fixed number of jobs that can be added to the job queue, defined by RIT_JOBS_COUNT (20 by default) in the peripherals.h file.
- Returns
- RIT_Error The error.
Definition at line 15 of file rit.c.
16{
17
19
23
24 LPC_RIT->RICOMPVAL = (
rit_clk_mhz * ival_ms * 1000);
25 LPC_RIT->RICTRL = 6;
26 LPC_RIT->RICOUNTER = 0;
27
30
32
33
34 NVIC_EnableIRQ(RIT_IRQn);
35
38
39 NVIC_SetPriority(RIT_IRQn, int_priority);
41}
void POWER_TurnOnPeripheral(u8 bit)
Turns on a peripheral.
_DECL_EXTERNALLY u32 counter_reset_value
_PRIVATE const u32 rit_clk_mhz
RIT_CLK frequency in MHz. Can be checked in the RIT GUI in Keil.
_DECL_EXTERNALLY void allocate_jobs_list(MEM_Allocator *const)
@ RIT_ERR_INT_PRIO_INVALID
An invalid priority was specified (must be 0 <= prio <= 15). This is not necessarily an error,...
#define CLR_BITS(reg, value, bit)
#define IS_DEF_PRIORITY(prio)
#define IS_BETWEEN_EQ(value, low, hi)
◆ RIT_IsEnabled()
bool RIT_IsEnabled |
( |
void |
| ) |
|
Returns whether the RIT is counting or not.
Definition at line 60 of file rit.c.
61{
62 return LPC_RIT->RICTRL & (1 << 3);
63}
◆ RIT_RemoveJob()
Removes a job from the RIT interrupt handler job queue.
- Parameters
-
Definition at line 117 of file rit_job.c.
118{
120 {
123 {
124 if (list_job->
job == job)
125 {
128
130 break;
131 }
132 }
133 }
134
136}
CL_Error CL_ListRemoveAt(CL_List *const list, u32 index, void *out_elem)
Removes an element at the specified index.
CL_Error CL_ListGetPtr(const CL_List *const list, u32 index, void **out_elem)
Gets an element at the specified index as a pointer, so the user can modify it.
_PRIVATE void recalculate_reset_value(void)
@ RIT_ERR_DURING_REMOVEAT
An error occurred during the removal of the job from the list.
◆ RIT_SetJobMultiplierFactor()
Sets the multiplier factor for the given job.
- Parameters
-
job | The job to set the multiplier factor for |
multiplier_factor | The new multiplier factor |
- Returns
- RIT_Error The error.
Definition at line 153 of file rit_job.c.
154{
155 if (multiplier_factor == 0)
157
159 if (list_job->job == job)
160 {
161 list_job->interval = base_ival * multiplier_factor;
162
163
164
165 if (list_job->interval == counter_reset_value)
166 recalculate_reset_value();
167
168 return RIT_ERR_OK;
169 }
170 });
171
173}
@ RIT_ERR_INVALID_MULTIPLIER
An invalid multiplier factor was specified (must be > 0).