NavHAL 0.1.0
NAVRobotec's architecture-agnostic HAL for embedded systems.
Loading...
Searching...
No Matches
timer_reg.h
Go to the documentation of this file.
1#ifndef CORTEX_M4_TIMER_REG_H
2#define CORTEX_M4_TIMER_REG_H
3
4#include "common/hal_types.h"
5#include <stdint.h>
6
7typedef struct {
8 __IO uint32_t CR1;
9 __IO uint32_t CR2;
11 __IO uint32_t SMCR;
13 __IO uint32_t DIER;
14 __IO uint32_t SR;
15 __IO uint32_t EGR;
16 __IO uint32_t CCMR1;
18 __IO uint32_t CCMR2;
20 __IO uint32_t CCER;
22 __IO uint32_t CNT;
24 __IO uint32_t PSC;
25 __IO uint32_t ARR;
27 __IO uint32_t RCR;
29 __IO uint32_t CCR1;
31 __IO uint32_t CCR2;
33 __IO uint32_t CCR3;
35 __IO uint32_t CCR4;
37 __IO uint32_t BDTR;
39 __IO uint32_t
41 __IO uint32_t DMAR;
43 __IO uint32_t OR;
46
47#define TIM1_BASE_ADDR 0x40010000
48#define GPTIMx_BASE_ADDR 0x40000000
49#define TIM9_BASE_ADDR 0x40014000
50
51static inline TIMx_Reg_Typedef *GET_TIMx_BASE(uint8_t n) {
52 switch (n) {
53 case 1:
55 case 2:
56 return (TIMx_Reg_Typedef *)(GPTIMx_BASE_ADDR + 0x000);
57 case 3:
58 return (TIMx_Reg_Typedef *)(GPTIMx_BASE_ADDR + 0x400);
59 case 4:
60 return (TIMx_Reg_Typedef *)(GPTIMx_BASE_ADDR + 0x800);
61 case 5:
62 return (TIMx_Reg_Typedef *)(GPTIMx_BASE_ADDR + 0xC00);
63 case 9:
65 case 10:
66 return (TIMx_Reg_Typedef *)(TIM9_BASE_ADDR + 0x400);
67 case 11:
68 return (TIMx_Reg_Typedef *)(TIM9_BASE_ADDR + 0x800);
69 default:
70 return NULL; // unsupported timer
71 }
72}
73
74// CR1
75#define TIMx_CR1_CEN 0x1
76
77// PSC
78#define TIMx_PSC_MASK 0xFFFF
79
80// ARR
81#define TIMx_ARR_MASK 0xFFFF
82#define TIM2_5_ARR_MASK 0xFFFFFFFF
83
84// EGR
85#define TIMx_EGR_UG 0x1
86
87// CNT
88#define TIMx_CNT_MASK 0xFFFF
89#define TIM2_5_CNT_MASK 0xFFFFFFFF
90
91// DIER
92#define TIMx_DIER_UIE 0x1
93
94// SR
95#define TIMx_SR_UIF 0x1
96
97// CCR
98#define TIMx_CCRy_MASK 0xFFFF
99#define TIM2_5_CCRy_MASK 0xFFFFFFFF
100
101// CCER
102#define TIMx_CCER_CCxE_MASK(n) (0x1 << (((n % 4) - 1) * 4))
103
104// CCMRx
105// Use channel 1,2 with CCMR1 and 3,4 with CCMR2
106#define TIMx_CCMRy_OCzPE_Pos(ch) ((ch % 2 == 1) ? 0x3 : 0x11)
107#define TIMx_CCMRy_OCzM_Pos(ch) ((ch % 2 == 1) ? 0x4 : 0x12)
108
109#define TIMx_CCMRy_OCzM_MASK(ch) (0x7 << (TIMx_CCMRy_OCzM_Pos(ch)))
110#define TIMx_CCMRy_OCzM_PWM_MODE1_MASK(ch) \
111 (0x6 << TIMx_CCMRy_OCzM_Pos(ch)) // In upcounting, channel 1 is active as
112 // long as TIMx_CNT<TIMx_CCR1 else
113// inactive. In downcounting, channel 1 is inactive (OC1REF=‘0) as long as
114// TIMx_CNT>TIMx_CCR1 else active (OC1REF=1)
115
116#define TIMx_CCMRy_OCxM_PWM_MODE2_MASK(ch) \
117 (0x7 << TIMx_CCMRy_OCzM_Pos(ch)) // In upcounting, channel 1 is inactive as
118 // long as TIMx_CNT<TIMx_CCR1
119// else active. In downcounting, channel 1 is active as long as
120// TIMx_CNT>TIMx_CCR1 else inactive.
121#define TIMx_CCMRy_OCxPE(ch) (0x1 << TIMx_CCMRy_OCzPE_Pos(ch))
122
123#endif // !CORTEX_M4_TIMER_REG_H
Hardware Abstraction Layer (HAL) common type definitions.
#define NULL
Definition hal_types.h:21
#define __IO
Definition hal_types.h:20
Definition timer_reg.h:7
__IO uint32_t CCR1
Definition timer_reg.h:29
__IO uint32_t OR
Definition timer_reg.h:43
__IO uint32_t CCMR2
Definition timer_reg.h:18
__IO uint32_t CR1
Definition timer_reg.h:8
__IO uint32_t PSC
Definition timer_reg.h:24
__IO uint32_t SMCR
Definition timer_reg.h:11
__IO uint32_t CCER
Definition timer_reg.h:20
__IO uint32_t CCR3
Definition timer_reg.h:33
__IO uint32_t RCR
Definition timer_reg.h:27
__IO uint32_t ARR
Definition timer_reg.h:25
__IO uint32_t CCMR1
Definition timer_reg.h:16
__IO uint32_t CR2
Definition timer_reg.h:9
__IO uint32_t CCR4
Definition timer_reg.h:35
__IO uint32_t EGR
Definition timer_reg.h:15
__IO uint32_t CNT
Definition timer_reg.h:22
__IO uint32_t DMAR
Definition timer_reg.h:41
__IO uint32_t BDTR
Definition timer_reg.h:37
__IO uint32_t SR
Definition timer_reg.h:14
__IO uint32_t CCR2
Definition timer_reg.h:31
__IO uint32_t DCR
Definition timer_reg.h:40
__IO uint32_t DIER
Definition timer_reg.h:13
#define GPTIMx_BASE_ADDR
Definition timer_reg.h:48
#define TIM1_BASE_ADDR
Definition timer_reg.h:47
#define TIM9_BASE_ADDR
Definition timer_reg.h:49