Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
rit.c File Reference
#include "rit.h"
#include "power.h"
#include "types.h"
#include <LPC17xx.h>

Go to the source code of this file.

Functions

_DECL_EXTERNALLY void allocate_jobs_list (MEM_Allocator *const)
 
_DECL_EXTERNALLY void free_jobs_list (void)
 
RIT_Error RIT_Init (MEM_Allocator *const alloc, u32 ival_ms, u16 int_priority)
 Initialize the RIT.
 
void RIT_Deinit (void)
 De-initializes the RIT, by removing every job and disconnecting power.
 
void RIT_Enable (void)
 Enables the RIT counting.
 
void RIT_Disable (void)
 Disables the RIT entirely (stops counting).
 
bool RIT_IsEnabled (void)
 Returns whether the RIT is counting or not.
 
u32 RIT_GetIntervalMs (void)
 Returns the interval in millis that RIT uses for its interrupts.
 

Variables

_PRIVATE const u32 rit_clk_mhz = 100
 RIT_CLK frequency in MHz. Can be checked in the RIT GUI in Keil.
 
_USED_EXTERNALLY u32 base_ival
 
_DECL_EXTERNALLY u32 counter_reset_value
 

Function Documentation

◆ allocate_jobs_list()

_DECL_EXTERNALLY void allocate_jobs_list ( MEM_Allocator * const  alloc)

Definition at line 37 of file rit_job.c.

38{
39 jobs = CL_ListAlloc(alloc, sizeof(JobWrapper));
40 if (!jobs)
41 return;
42}
CL_List * CL_ListAlloc(MEM_Allocator *const alloc, u32 elem_sz)
Initializes a new doubly-linked list with tail, with the allocated memory provided by the user.
Definition cl_list.c:43
_PRIVATE CL_List * jobs
Array of jobs to execute in the RIT interrupt handler.
Definition rit_job.c:26

◆ free_jobs_list()

_DECL_EXTERNALLY void free_jobs_list ( void  )

Definition at line 45 of file rit_job.c.

46{
47 if (jobs)
49}
void CL_ListFree(CL_List *const list)
Frees the memory previously assigned to the list.
Definition cl_list.c:63

◆ RIT_Deinit()

void RIT_Deinit ( void  )

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.
Definition power.c:30
@ POW_PCRIT
Definition power_types.h:21
_DECL_EXTERNALLY void free_jobs_list(void)
Definition rit_job.c:45

◆ RIT_Disable()

void RIT_Disable ( void  )

Disables the RIT entirely (stops counting).

Definition at line 55 of file rit.c.

56{
57 CLR_BIT(LPC_RIT->RICTRL, 3);
58}
#define CLR_BIT(reg, bit)
Definition types.h:27

◆ RIT_Enable()

void RIT_Enable ( void  )

Enables the RIT counting.

Definition at line 50 of file rit.c.

51{
52 SET_BIT(LPC_RIT->RICTRL, 3);
53}
#define SET_BIT(reg, bit)
Definition types.h:26

◆ 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{
67 return base_ival;
68}
_USED_EXTERNALLY u32 base_ival
Definition rit.c:12

◆ RIT_Init()

RIT_Error RIT_Init ( MEM_Allocator *const  alloc,
u32  ival_ms,
u16  int_priority 
)

Initialize the RIT.

Parameters
allocThe memory allocator to use for the RIT job list.
ival_msInterval in millis between each RIT interrupt.
int_priorityDebouncer 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 // Powering up the RIT
19
20 CLR_BITS(LPC_SC->PCLKSEL1, 3, 26); // Clear
21 SET_BIT(LPC_SC->PCLKSEL1, 26); // Set PCLK_RIT to CCLK
22 SET_BIT(LPC_SC->PCONP, 16); // Enable power to RIT
23
24 LPC_RIT->RICOMPVAL = (rit_clk_mhz * ival_ms * 1000);
25 LPC_RIT->RICTRL = 6; // Clear on match + Timer enable for debug
26 LPC_RIT->RICOUNTER = 0;
27
28 base_ival = ival_ms;
29 counter_reset_value = ival_ms;
30
31 allocate_jobs_list(alloc);
32
33 // Enabling interrupts coming from RIT
34 NVIC_EnableIRQ(RIT_IRQn);
35
36 if (!IS_DEF_PRIORITY(int_priority) && IS_BETWEEN_EQ(int_priority, 0, 15))
38
39 NVIC_SetPriority(RIT_IRQn, int_priority);
40 return RIT_ERR_OK;
41}
void POWER_TurnOnPeripheral(u8 bit)
Turns on a peripheral.
Definition power.c:25
_DECL_EXTERNALLY u32 counter_reset_value
Definition rit.c:13
_PRIVATE const u32 rit_clk_mhz
RIT_CLK frequency in MHz. Can be checked in the RIT GUI in Keil.
Definition rit.c:7
_DECL_EXTERNALLY void allocate_jobs_list(MEM_Allocator *const)
Definition rit_job.c:37
@ RIT_ERR_INT_PRIO_INVALID
An invalid priority was specified (must be 0 <= prio <= 15). This is not necessarily an error,...
Definition rit_types.h:21
@ RIT_ERR_OK
No errors.
Definition rit_types.h:13
#define CLR_BITS(reg, value, bit)
Definition types.h:30
#define IS_DEF_PRIORITY(prio)
Definition types.h:42
#define IS_BETWEEN_EQ(value, low, hi)
Definition types.h:23

◆ 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}

Variable Documentation

◆ base_ival

_USED_EXTERNALLY u32 base_ival

Definition at line 12 of file rit.c.

◆ counter_reset_value

_DECL_EXTERNALLY u32 counter_reset_value

Definition at line 13 of file rit.c.

◆ rit_clk_mhz

_PRIVATE const u32 rit_clk_mhz = 100

RIT_CLK frequency in MHz. Can be checked in the RIT GUI in Keil.

Definition at line 7 of file rit.c.