-
Notifications
You must be signed in to change notification settings - Fork 38
/
hal_ll_pps_port.c
172 lines (151 loc) · 6.96 KB
/
hal_ll_pps_port.c
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
162
163
164
165
166
167
168
169
170
171
172
/****************************************************************************
**
** 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_port.c
* @brief This file contains low level HAL PPS LOW LAYER PORTED function definitions.
*/
#include "hal_ll_pps_connection_defs.h"
/**
* @brief Checks selected pin with available functions.
*
* @param map_index Index of map.
* @param hal_ll_pps_cfg Local map.
*
* @return hal_ll_pps_err_t Error handling
* Returns one of pre-defined values:
* HAL_LL_PPS_SUCCESS -- init success
* HAL_LL_PPS_DIRECTION_ERROR -- direction non-existent
* HAL_LL_PPS_PIN_ERROR -- pin non-existent
* HAL_LL_PPS_MODULE_ERROR -- init failed
*
* @note PIC ONLY
*/
static hal_ll_pps_err_t hal_ll_pps_check_pin_to_function( uint16_t *map_index, hal_ll_pps_hw_specifics_map_t *hal_ll_pps_cfg );
// ---------------------------------------------- PUBLIC FUNCTION DEFINTIONS
hal_ll_pps_err_t hal_ll_pps_map_input( hal_ll_port_name_t port_name, hal_ll_pin_name_t pin_num, hal_ll_pps_functionality_t pps_func, hal_ll_pps_module_index_t module_num, bool hal_ll_state ) {
hal_ll_pps_hw_specifics_map_t hal_ll_pps_cfg;
hal_ll_pin_name_t map_index_num = 0;
hal_ll_pps_cfg.pin_num = pin_num;
hal_ll_pps_cfg.port_num = port_name;
hal_ll_pps_cfg.pin_direction = HAL_LL_GPIO_DIGITAL_INPUT;
hal_ll_pps_cfg.pps_function = pps_func;
hal_ll_pps_cfg.pps_module_num = module_num;
if ( HAL_LL_PPS_SUCCESS != hal_ll_pps_check_pin_to_function( &map_index_num, &hal_ll_pps_cfg ) ) {
return HAL_LL_PPS_PIN_ERROR;
}
switch ( hal_ll_state )
{
case true:
if ( HAL_LL_DEFAULT_PPS_REGISTER_STATE == read_reg( hal_ll_pps_input_map[ map_index_num ].pps_reg_addr ) )
clear_reg( hal_ll_pps_input_map[ map_index_num ].pps_reg_addr );
write_reg_ptr( hal_ll_pps_input_map[ map_index_num ].pps_reg_addr, hal_ll_pps_input_map[ map_index_num ].pps_reg_value );
break;
case false:
clear_reg_ptr( hal_ll_pps_input_map[ map_index_num ].pps_reg_addr, hal_ll_pps_input_map[ map_index_num ].pps_reg_value );
break;
}
return HAL_LL_PPS_SUCCESS;
}
hal_ll_pps_err_t hal_ll_pps_map_output( hal_ll_port_name_t port_name, hal_ll_pin_name_t pin_num, hal_ll_pps_functionality_t pps_func, hal_ll_pps_module_index_t module_num, bool hal_ll_state ) {
hal_ll_pps_hw_specifics_map_t hal_ll_pps_cfg;
uint16_t map_index_num = 0;
hal_ll_pps_cfg.pin_num = pin_num;
hal_ll_pps_cfg.port_num = port_name;
hal_ll_pps_cfg.pin_direction = HAL_LL_GPIO_DIGITAL_OUTPUT;
hal_ll_pps_cfg.pps_function = pps_func;
hal_ll_pps_cfg.pps_module_num = module_num;
if ( HAL_LL_PPS_SUCCESS != hal_ll_pps_check_pin_to_function( &map_index_num, &hal_ll_pps_cfg ) ) {
return HAL_LL_PPS_PIN_ERROR;
}
switch ( hal_ll_state )
{
case true:
if ( HAL_LL_DEFAULT_PPS_REGISTER_STATE == read_reg( hal_ll_pps_output_map[ map_index_num ].pps_reg_addr ) )
clear_reg( hal_ll_pps_output_map[ map_index_num ].pps_reg_addr );
write_reg_ptr( hal_ll_pps_output_map[ map_index_num ].pps_reg_addr, hal_ll_pps_output_map[ map_index_num ].pps_reg_value );
break;
case false:
clear_reg_ptr( hal_ll_pps_output_map[ map_index_num ].pps_reg_addr, hal_ll_pps_output_map[ map_index_num ].pps_reg_value );
break;
}
return HAL_LL_PPS_SUCCESS;
}
// ---------------------------------------------- PRIVATE FUNCTION DEFINITONS
static hal_ll_pps_err_t hal_ll_pps_check_pin_to_function( uint16_t *map_index, hal_ll_pps_hw_specifics_map_t *hal_ll_pps_cfg ) {
uint16_t pps_map_size;
uint16_t hal_ll_pps_index;
hal_ll_pps_pin_map_t map_index_ll;
switch ( hal_ll_pps_cfg->pin_direction )
{
case HAL_LL_GPIO_DIGITAL_INPUT:
map_index_ll = *hal_ll_pps_input_map;
pps_map_size = ( sizeof( hal_ll_pps_input_map ) / sizeof( hal_ll_pps_pin_map_t ) );
break;
case HAL_LL_GPIO_DIGITAL_OUTPUT:
map_index_ll = *hal_ll_pps_output_map;
pps_map_size = ( sizeof( hal_ll_pps_output_map ) / sizeof( hal_ll_pps_pin_map_t ) );
break;
default:
return HAL_LL_PPS_DIRECTION_ERROR;
}
for ( hal_ll_pps_index = 0; hal_ll_pps_index < pps_map_size; hal_ll_pps_index ) {
if ( map_index_ll.pin_num == hal_ll_pps_cfg->pin_num ) {
if ( map_index_ll.port_num == hal_ll_pps_cfg->port_num ) {
if ( map_index_ll.pin_direction == hal_ll_pps_cfg->pin_direction ) {
if ( map_index_ll.pps_function == hal_ll_pps_cfg->pps_function ) {
if ( map_index_ll.pps_module_num == hal_ll_pps_cfg->pps_module_num ) {
*map_index = hal_ll_pps_index;
return HAL_LL_PPS_SUCCESS;
}
}
}
}
}
// Increment pointer to next structure element
if( HAL_LL_GPIO_DIGITAL_INPUT == hal_ll_pps_cfg->pin_direction ) {
map_index_ll = hal_ll_pps_input_map[ ++hal_ll_pps_index ];
} else {
map_index_ll = hal_ll_pps_output_map[ ++hal_ll_pps_index ];
}
}
// If it gets to here, check pin maps for error
return HAL_LL_PPS_MODULE_ERROR;
}
// ------------------------------------------------------------------------- END