-
Notifications
You must be signed in to change notification settings - Fork 38
/
hal_ll_pps_defines.h
161 lines (148 loc) · 6.85 KB
/
hal_ll_pps_defines.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/****************************************************************************
**
** Copyright (C) ${COPYRIGHT_YEAR} MikroElektronika d.o.o.
** Contact: https://www.mikroe.com/contact
**
** This file is part of the mikroSDK package
**
** Commercial License Usage
**
** Licensees holding valid commercial NECTO compilers AI licenses may use this
** file in accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The MikroElektronika Company.
** For licensing terms and conditions see
** https://www.mikroe.com/legal/software-license-agreement.
** For further information use the contact form at
** https://www.mikroe.com/contact.
**
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used for
** non-commercial projects under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
****************************************************************************/
/*!
* @file hal_ll_pps_defines.h
* @brief This file contains supporting macros and enums for HAL LOW LEVEL PPS implementation.
*/
#ifndef _HAL_LL_PPS_DEFINES_H_
#define _HAL_LL_PPS_DEFINES_H_
#ifdef __cplusplus
extern "C"{
#endif
#include "stdint.h"
#include "mcu_definitions.h"
/*!< @brief Enum defining pps module index */
typedef enum
{
HAL_LL_PPS_MODULE_INDEX_1 = 0,
HAL_LL_PPS_MODULE_INDEX_2,
HAL_LL_PPS_MODULE_INDEX_3,
HAL_LL_PPS_MODULE_INDEX_4,
HAL_LL_PPS_MODULE_INDEX_5,
HAL_LL_PPS_MODULE_INDEX_6,
HAL_LL_PPS_MODULE_INDEX_7,
HAL_LL_PPS_MODULE_INDEX_8,
HAL_LL_PPS_MODULE_INDEX_9,
HAL_LL_PPS_MODULE_INDEX_10
} hal_ll_pps_module_index_t;
/*!< @brief Enum defining pps functionalities */
typedef enum
{
HAL_LL_PPS_FUNCTIONALITY_UART = 0, // UART/USART module
HAL_LL_PPS_FUNCTIONALITY_I2C_SCL, // I2C module
HAL_LL_PPS_FUNCTIONALITY_I2C_SDA, // I2C module
HAL_LL_PPS_FUNCTIONALITY_SPI_SCK, // SPI module
HAL_LL_PPS_FUNCTIONALITY_SPI_MISO, // SPI module
HAL_LL_PPS_FUNCTIONALITY_SPI_MOSI, // SPI module
HAL_LL_PPS_FUNCTIONALITY_PWM, // TIM/PWM module
HAL_LL_PPS_FUNCTIONALITY_IVT, // Interrupt mapping
HAL_LL_PPS_FUNCTIONALITY_CAN, // CAN module
HAL_LL_PPS_FUNCTIONALITY_NONE = 0xFF
} hal_ll_pps_functionality_t;
/*!< @brief Enum defining pps return values */
typedef enum
{
HAL_LL_PPS_SUCCESS = 0,
HAL_LL_PPS_DIRECTION_ERROR,
HAL_LL_PPS_PIN_ERROR,
HAL_LL_PPS_MODULE_ERROR
} hal_ll_pps_err_t;
#define HAL_LL_DEFAULT_PPS_REGISTER_STATE 0x3F3F
#define reg_addr_ptr(reg_addr) *(uint16_t *)reg_addr
#define write_reg_ptr(reg_addr,reg_val) reg_addr_ptr(reg_addr)|=reg_val
#define clear_reg_ptr(reg_addr,reg_val) reg_addr_ptr(reg_addr)&=~reg_val
#ifdef __GB610_FAMILY__
#ifdef HAL_LL_OSCCON_REG_ADDRESS
/*!< @brief All dsPIC chips have the same unlock sequence */
#define HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_FIRST #0x46
#define HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_SECOND #0x57
#define HAL_LL_PPS_UNLOCK 0
#define HAL_LL_PPS_LOCK 1
#define HAL_LL_PPS_UNLOCK_LOCK_BIT #6
#define LOCK_BIT_REG_ADDRESS #0x0100
#define LOCK_UNLOCK_BIT_MASK 6
/*!< @brief Macro defining lock/unlock for PPS */
#define hal_ll_pps_lock_unlock(value) if ( HAL_LL_PPS_UNLOCK == value ) { \
asm { MOV LOCK_BIT_REG_ADDRESS, W3 } \
asm { MOV HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_FIRST, W4 } \
asm { MOV HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_SECOND, W5 } \
asm { MOV.B W4, [W3] } \
asm { MOV.B W5, [W3] } \
asm { BCLR 0x0100, HAL_LL_PPS_UNLOCK_LOCK_BIT } \
} else {\
asm { MOV LOCK_BIT_REG_ADDRESS, W3 } \
asm { MOV HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_FIRST, W4 } \
asm { MOV HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_SECOND, W5 } \
asm { MOV.B W4, [W3] } \
asm { MOV.B W5, [W3] } \
asm { BSET 0x0100, HAL_LL_PPS_UNLOCK_LOCK_BIT } \
}
#endif
#else
#ifdef HAL_LL_OSCCON_REG_ADDRESS
/*!< @brief All dsPIC chips have the same unlock sequence */
#define HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_FIRST #0x46
#define HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_SECOND #0x57
#define HAL_LL_PPS_UNLOCK 0
#define HAL_LL_PPS_LOCK 1
#define HAL_LL_PPS_UNLOCK_LOCK_BIT #6
#define LOCK_BIT_REG_ADDRESS #0x0742
#define LOCK_UNLOCK_BIT_MASK 6
#define hal_ll_pps_lock_unlock(value) if ( HAL_LL_PPS_UNLOCK == value ) { \
asm { MOV LOCK_BIT_REG_ADDRESS, W3 } \
asm { MOV HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_FIRST, W4 } \
asm { MOV HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_SECOND, W5 } \
asm { MOV.B W4, [W3] } \
asm { MOV.B W5, [W3] } \
asm { BCLR 0x0742, HAL_LL_PPS_UNLOCK_LOCK_BIT } \
} else {\
asm { MOV LOCK_BIT_REG_ADDRESS, W3 } \
asm { MOV HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_FIRST, W4 } \
asm { MOV HAL_LL_PPS_LOCK_UNLOCK_SEQUENCE_KEY_SECOND, W5 } \
asm { MOV.B W4, [W3] } \
asm { MOV.B W5, [W3] } \
asm { BSET 0x0742, HAL_LL_PPS_UNLOCK_LOCK_BIT } \
}
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif // _HAL_LL_PPS_DEFINES_H_
// ------------------------------------------------------------------------- END