source: rtems/bsps/arm/altera-cyclone-v/contrib/hwlib/src/hwmgr/alt_reset_manager.c @ 9d41fca

5
Last change on this file since 9d41fca was 9d41fca, checked in by Sebastian Huber <sebastian.huber@…>, on 02/27/19 at 10:39:29

bsp/altera-cyclone-v: Adjust Doxygen file groups

Update #3707.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSBSPsARMCycVContrib
5 */
6
7
8/******************************************************************************
9*
10* alt_reset_manager.c - API for the Altera SoC FPGA reset manager.
11*
12******************************************************************************/
13
14/******************************************************************************
15*
16* Copyright 2013 Altera Corporation. All Rights Reserved.
17*
18* Redistribution and use in source and binary forms, with or without
19* modification, are permitted provided that the following conditions are met:
20*
21* 1. Redistributions of source code must retain the above copyright notice,
22* this list of conditions and the following disclaimer.
23*
24* 2. Redistributions in binary form must reproduce the above copyright notice,
25* this list of conditions and the following disclaimer in the documentation
26* and/or other materials provided with the distribution.
27*
28* 3. The name of the author may not be used to endorse or promote products
29* derived from this software without specific prior written permission.
30*
31* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR
32* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO
34* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
36* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
39* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
40* OF SUCH DAMAGE.
41*
42******************************************************************************/
43
44#include <bsp/alt_reset_manager.h>
45#include <bsp/socal/socal.h>
46#include <bsp/socal/hps.h>
47#include <bsp/socal/alt_rstmgr.h>
48
49/////
50
51
52uint32_t alt_reset_event_get(void)
53{
54    return alt_read_word(ALT_RSTMGR_STAT_ADDR);
55}
56
57ALT_STATUS_CODE alt_reset_event_clear(uint32_t event_mask)
58{
59    alt_write_word(ALT_RSTMGR_STAT_ADDR, event_mask);
60    return ALT_E_SUCCESS;
61}
62
63ALT_STATUS_CODE alt_reset_cold_reset(void)
64{
65    alt_write_word(ALT_RSTMGR_CTL_ADDR, ALT_RSTMGR_CTL_SWCOLDRSTREQ_SET_MSK);
66    return ALT_E_SUCCESS;
67}
68
69ALT_STATUS_CODE alt_reset_warm_reset(uint32_t warm_reset_delay,
70                                     uint32_t nRST_pin_clk_assertion,
71                                     bool sdram_refresh_enable,
72                                     bool fpga_mgr_handshake,
73                                     bool scan_mgr_handshake,
74                                     bool fpga_handshake,
75                                     bool etr_stall)
76{
77    // Cached register values
78    uint32_t ctrl_reg   = ALT_RSTMGR_CTL_SWWARMRSTREQ_SET_MSK;
79    uint32_t counts_reg = 0;
80
81    /////
82
83    // Validate warm_reset_delay is above 16 and below the field width
84    if ((warm_reset_delay < 16) || (warm_reset_delay >= (1 << ALT_RSTMGR_COUNTS_WARMRSTCYCLES_WIDTH)))
85    {
86        return ALT_E_BAD_ARG;
87    }
88
89    // Validate nRST_pin_clk_assertion delay is non-zero and below the field width
90    if (!nRST_pin_clk_assertion)
91    {
92        return ALT_E_ERROR;
93    }
94    if (nRST_pin_clk_assertion >= (1 << ALT_RSTMGR_COUNTS_NRSTCNT_WIDTH))
95    {
96        return ALT_E_BAD_ARG;
97    }
98
99    // Update counts register with warm_reset_delay information
100    counts_reg |= ALT_RSTMGR_COUNTS_WARMRSTCYCLES_SET(warm_reset_delay);
101
102    // Update counts register with nRST_pin_clk_assertion information
103    counts_reg |= ALT_RSTMGR_COUNTS_NRSTCNT_SET(nRST_pin_clk_assertion);
104
105    /////
106
107    // Update ctrl register with the specified option flags
108
109    if (sdram_refresh_enable)
110    {
111        ctrl_reg |= ALT_RSTMGR_CTL_SDRSELFREFEN_SET_MSK;
112    }
113
114    if (fpga_mgr_handshake)
115    {
116        ctrl_reg |= ALT_RSTMGR_CTL_FPGAMGRHSEN_SET_MSK;
117    }
118
119    if (scan_mgr_handshake)
120    {
121        ctrl_reg |= ALT_RSTMGR_CTL_SCANMGRHSEN_SET_MSK;
122    }
123
124    if (fpga_handshake)
125    {
126        ctrl_reg |= ALT_RSTMGR_CTL_FPGAHSEN_SET_MSK;
127    }
128
129    if (etr_stall)
130    {
131        ctrl_reg |= ALT_RSTMGR_CTL_ETRSTALLEN_SET_MSK;
132    }
133
134    /////
135
136    // Commit registers to hardware
137    alt_write_word(ALT_RSTMGR_COUNTS_ADDR, counts_reg);
138    alt_write_word(ALT_RSTMGR_CTL_ADDR,    ctrl_reg);
139
140    return ALT_E_SUCCESS;
141}
Note: See TracBrowser for help on using the repository browser.