Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
rit.c
Go to the documentation of this file.
1#include "rit.h"
2#include "power.h"
3#include "types.h"
4#include <LPC17xx.h>
5
8
11
14
15RIT_Error RIT_Init(MEM_Allocator *const alloc, u32 ival_ms, u16 int_priority)
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}
42
43void RIT_Deinit(void)
44{
46 NVIC_DisableIRQ(RIT_IRQn);
48}
49
50void RIT_Enable(void)
51{
52 SET_BIT(LPC_RIT->RICTRL, 3);
53}
54
55void RIT_Disable(void)
56{
57 CLR_BIT(LPC_RIT->RICTRL, 3);
58}
59
60bool RIT_IsEnabled(void)
61{
62 return LPC_RIT->RICTRL & (1 << 3);
63}
64
66{
67 return base_ival;
68}
void POWER_TurnOffPeripheral(u8 bit)
Turns off a peripheral.
Definition power.c:30
void POWER_TurnOnPeripheral(u8 bit)
Turns on a peripheral.
Definition power.c:25
@ POW_PCRIT
Definition power_types.h:21
_DECL_EXTERNALLY void free_jobs_list(void)
Definition rit_job.c:45
_USED_EXTERNALLY u32 base_ival
Definition rit.c:12
_DECL_EXTERNALLY u32 counter_reset_value
Definition rit.c:13
void RIT_Deinit(void)
De-initializes the RIT, by removing every job and disconnecting power.
Definition rit.c:43
void RIT_Disable(void)
Disables the RIT entirely (stops counting).
Definition rit.c:55
bool RIT_IsEnabled(void)
Returns whether the RIT is counting or not.
Definition rit.c:60
_PRIVATE const u32 rit_clk_mhz
RIT_CLK frequency in MHz. Can be checked in the RIT GUI in Keil.
Definition rit.c:7
void RIT_Enable(void)
Enables the RIT counting.
Definition rit.c:50
RIT_Error RIT_Init(MEM_Allocator *const alloc, u32 ival_ms, u16 int_priority)
Initialize the RIT.
Definition rit.c:15
_DECL_EXTERNALLY void allocate_jobs_list(MEM_Allocator *const)
Definition rit_job.c:37
u32 RIT_GetIntervalMs(void)
Returns the interval in millis that RIT uses for its interrupts.
Definition rit.c:65
RIT_Error
Definition rit_types.h:11
@ 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 CLR_BIT(reg, bit)
Definition types.h:27
#define SET_BIT(reg, bit)
Definition types.h:26
#define IS_DEF_PRIORITY(prio)
Definition types.h:42
#define _PRIVATE
Definition types.h:37
#define IS_BETWEEN_EQ(value, low, hi)
Definition types.h:23
uint16_t u16
Definition types.h:7
#define _USED_EXTERNALLY
Definition types.h:35
#define _DECL_EXTERNALLY
Definition types.h:36
uint32_t u32
Definition types.h:6