aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/hal/src/flexio/fsl_flexio_hal.c
blob: 9d0e28ac9eab77f4df52c7f87bd143acfc085a9b (plain)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * Copyright (c) 2014, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 * of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 * list of conditions and the following disclaimer in the documentation and/or
 * other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "fsl_flexio_hal.h"
#if FSL_FEATURE_SOC_FLEXIO_COUNT

/*FUNCTION****************************************************************
 *
 * Function Name: FLEXIO_HAL_SetTimerStatusIntCmd
 * Description: Enable/disable timer status interrupt
 *
 *END*********************************************************************/
void FLEXIO_HAL_SetTimerStatusIntCmd(FLEXIO_Type * base, uint32_t mask, bool enable)
{
    uint32_t teie = FLEXIO_BRD_TIMIEN_TEIE(base);
    if (enable)
    {
        teie |= mask;
    }
    else
    {
        teie &= ~mask;
    }
    FLEXIO_BWR_TIMIEN_TEIE(base, teie);
}

/*FUNCTION****************************************************************
 *
 * Function Name: FLEXIO_HAL_ConfigureTimer
 * Description: Configure timer related registers: ctl, cfg, cmp
 *
 *END*********************************************************************/
void FLEXIO_HAL_ConfigureTimer(FLEXIO_Type * base, uint32_t timerIdx, const flexio_timer_config_t *timerConfigPtr)
{
    uint32_t cfg = 0U, ctl = 0U, cmp = 0U;

    ctl  = FLEXIO_TIMCTL_TRGSEL(timerConfigPtr->trgsel)
         | FLEXIO_TIMCTL_TRGPOL(timerConfigPtr->trgpol)
         | FLEXIO_TIMCTL_TRGSRC(timerConfigPtr->trgsrc)
         | FLEXIO_TIMCTL_PINCFG(timerConfigPtr->pincfg)
         | FLEXIO_TIMCTL_PINSEL(timerConfigPtr->pinsel)
         | FLEXIO_TIMCTL_PINPOL(timerConfigPtr->pinpol)
         | FLEXIO_TIMCTL_TIMOD(timerConfigPtr->timod);

    cfg = FLEXIO_TIMCFG_TIMOUT(timerConfigPtr->timout)
        | FLEXIO_TIMCFG_TIMDEC(timerConfigPtr->timdec)
        | FLEXIO_TIMCFG_TIMRST(timerConfigPtr->timrst)
        | FLEXIO_TIMCFG_TIMDIS(timerConfigPtr->timdis)
        | FLEXIO_TIMCFG_TIMENA(timerConfigPtr->timena)
        | FLEXIO_TIMCFG_TSTOP(timerConfigPtr->tstop)
        | FLEXIO_TIMCFG_TSTART(timerConfigPtr->tstart);

    cmp = FLEXIO_TIMCMP_CMP(timerConfigPtr->timcmp);

    FLEXIO_WR_TIMCFG(base, timerIdx, cfg);
    FLEXIO_WR_TIMCMP(base, timerIdx, cmp);
    FLEXIO_WR_TIMCTL(base, timerIdx, ctl);
}

/*FUNCTION****************************************************************
 *
 * Function Name: FLEXIO_HAL_ConfigureShifter
 * Description: Configure shifter related registers: ctl, cfg
 *
 *END*********************************************************************/
void FLEXIO_HAL_ConfigureShifter(FLEXIO_Type * base, uint32_t shifterIdx, const flexio_shifter_config_t *shifterConfigPtr)
{
    uint32_t cfg = 0U, ctl = 0U;

    ctl = FLEXIO_SHIFTCTL_TIMSEL(shifterConfigPtr->timsel)
        | FLEXIO_SHIFTCTL_TIMPOL(shifterConfigPtr->timpol)
        | FLEXIO_SHIFTCTL_PINCFG(shifterConfigPtr->pincfg)
        | FLEXIO_SHIFTCTL_PINSEL(shifterConfigPtr->pinsel)
        | FLEXIO_SHIFTCTL_PINPOL(shifterConfigPtr->pinpol)
        | FLEXIO_SHIFTCTL_SMOD(shifterConfigPtr->smode);

    cfg = FLEXIO_SHIFTCFG_INSRC(shifterConfigPtr->insrc)
        | FLEXIO_SHIFTCFG_SSTOP(shifterConfigPtr->sstop)
        | FLEXIO_SHIFTCFG_SSTART(shifterConfigPtr->sstart);

    FLEXIO_WR_SHIFTCFG(base, shifterIdx, cfg);
    FLEXIO_WR_SHIFTCTL(base, shifterIdx, ctl);
}

/*FUNCTION****************************************************************
 *
 * Function Name: FLEXIO_HAL_SetShifterStatusIntCmd
 * Description: Enable/disable shifter status interrupt
 *
 *END*********************************************************************/
void FLEXIO_HAL_SetShifterStatusIntCmd(FLEXIO_Type * base, uint32_t mask, bool enable)
{
    uint32_t ssie = FLEXIO_BRD_SHIFTSIEN_SSIE(base);
    if (enable)
    {
        ssie |= mask;
    }
    else
    {
        ssie &= ~mask;
    }
    FLEXIO_BWR_SHIFTSIEN_SSIE(base, ssie);
}

/*FUNCTION****************************************************************
 *
 * Function Name: FLEXIO_HAL_SetShifterErrorIntCmd
 * Description: Enable/disable shifter error interrupt
 *
 *END*********************************************************************/
void FLEXIO_HAL_SetShifterErrorIntCmd(FLEXIO_Type * base, uint32_t mask, bool enable)
{
    uint32_t seie = FLEXIO_BRD_SHIFTEIEN_SEIE(base);
    if (enable)
    {
        seie |= mask;
    }
    else
    {
        seie &= ~mask;
    }
    FLEXIO_BWR_SHIFTEIEN_SEIE(base, seie);
}

/*FUNCTION****************************************************************
 *
 * Function Name: FLEXIO_HAL_SetShifterStatusDmaCmd
 * Description: Enable/disable shifter DMA transfer signalling
 *
 *END*********************************************************************/
void FLEXIO_HAL_SetShifterStatusDmaCmd(FLEXIO_Type * base, uint32_t mask, bool enable)
{
    uint32_t ssde = FLEXIO_BRD_SHIFTSDEN_SSDE(base);
    if (enable)
    {
        ssde |= mask;
    }
    else
    {
        ssde &= ~mask;
    }
    FLEXIO_BWR_SHIFTSDEN_SSDE(base, ssde);
}

/*FUNCTION****************************************************************
 *
 * Function Name: FLEXIO_HAL_Init
 * Description: Reset the registers of flexio module.
 *
 *END*********************************************************************/
void FLEXIO_HAL_Init(FLEXIO_Type * base)
{
    uint32_t maxShifterCounter, maxTimerCounter /*, maxPinCounter*/;

    FLEXIO_HAL_SetSoftwareResetCmd(base, true);
    maxShifterCounter = FLEXIO_HAL_GetShifterNumber(base);
    maxTimerCounter = FLEXIO_HAL_GetTimerNumber(base);
    FLEXIO_HAL_SetSoftwareResetCmd(base, false);

    FLEXIO_HAL_ClearShifterStatusFlags(base, (1U << maxShifterCounter) - 1U);
    FLEXIO_HAL_ClearShifterErrorFlags(base, (1U << maxShifterCounter) - 1U);
    FLEXIO_HAL_ClearTimerStatusFlags(base, (1U << maxTimerCounter) - 1U);
}
#endif

/******************************************************************************
 * EOF
 *****************************************************************************/