summaryrefslogtreecommitdiffstats
path: root/uc_str912/prj_blinky_simple_startup/str91x_lib/src/91x_ahbapb.c
blob: 41489ace37cc739949ca38c637eb66ba87ae0d4d (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
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name          : 91x_ahbapb.c
* Author             : MCD Application Team
* Date First Issued  : 05/18/2006 : Version 1.0
* Description        : This file provides all the AHBAPB software functions.
********************************************************************************
* History:
* 05/24/2006 : Version 1.1
* 05/18/2006 : Version 1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "91x_ahbapb.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#define AHBAPB_SplitCounter_Mask 0xFFE0FFFF
#define AHBAPB_SetTimeOut_Mask   0xFFFFFFE0
#define AHBAPB_Address_Mask      0xFEFFFFFF
#define AHBAPB_FLAG_RW_Mask      0x01000000
/*******************************************************************************
* Function Name  : AHBAPB_DeInit
* Description    : Deinitializes the AHBAPBx peripheral registers to their default
*                  reset values.
* Input          : AHBAPBx: where x can be 0 or 1 to select the AHBAPB peripheral.
* Output         : None
* Return         : None
*******************************************************************************/
void AHBAPB_DeInit(AHBAPB_TypeDef* AHBAPBx)
{
  AHBAPBx->BCR = 0x00000000;
  AHBAPBx->BSR = 0x00000000;
}
/*******************************************************************************
* Function Name  : AHBAPB_Init
* Description    : Initializes the AHBAPBx peripheral according to the specified
*                  parameters in the AHBAPB_InitStruct .
* Input          :- AHBAPBx: where x can be 0 or 1 to select the AHBAPB peripheral.
*                 - AHBAPB_InitStruct: pointer to a AHBAPB_InitTypeDef structure that
*                   contains the configuration information for the specified AHBAPB
*                   peripheral.
* Output         : None
* Return         : None
*******************************************************************************/
void AHBAPB_Init(AHBAPB_TypeDef* AHBAPBx, AHBAPB_InitTypeDef* AHBAPB_InitStruct)
{

  if(AHBAPB_InitStruct->AHBAPB_Split == AHBAPB_Split_Enable)
  {
    /* Set SPLITEN bit;*/
    AHBAPBx->BCR |= AHBAPB_Split_Enable;
    /*Split_CNT bits[20:16]*/
    AHBAPBx->BCR &= AHBAPB_SplitCounter_Mask;
    AHBAPBx->BCR |=  (AHBAPB_InitStruct->AHBAPB_SplitCounter)<<16;
  }
  else
  {
    /*/ Clear SPLITEN bit;*/
    AHBAPBx->BCR &= AHBAPB_Split_Disable;
  }
  /*APB Time out*/
  if(AHBAPB_InitStruct->AHBAPB_Error == AHBAPB_Error_Enable)
  {
    /* Set ERREN bit*/
    AHBAPBx->BCR |= AHBAPB_Error_Enable;
    /*Time ouit counter*/
    AHBAPBx->BCR &= AHBAPB_SetTimeOut_Mask;
    AHBAPBx->BCR |= AHBAPB_InitStruct->AHBAPB_SetTimeOut;
  }
  else
  {
    /* Clear ERREN bit*/
    AHBAPBx->BCR &= AHBAPB_Error_Disable;
  }
}

/*******************************************************************************
* Function Name  : AHBAPB_StructInit
* Description    : Initialize the AHBAPB Init Structure parameters
* Input          : AHBAPB_InitStruct : pointer to a AHBAPB_InitTypeDef structure
*                  which will be initialized.
* Output         : None
* Return         : None
*******************************************************************************/
void AHBAPB_StructInit(AHBAPB_InitTypeDef* AHBAPB_InitStruct)
{
  /* Reset AHBAPB init structure parameters values */
  AHBAPB_InitStruct->AHBAPB_Split        = AHBAPB_Split_Enable;
  AHBAPB_InitStruct->AHBAPB_SplitCounter = 0xFF;
  AHBAPB_InitStruct->AHBAPB_Error        = AHBAPB_Error_Enable;
  AHBAPB_InitStruct->AHBAPB_SetTimeOut   = 0xFF;

}

/*******************************************************************************
* Function Name  : AHBAPB_GetFlagStatus
* Description    : Checks whether the specified AHBAPB flag is set or not.
* Input          : - AHBAPB: where x can be 0 or 1 to select the AHBAPB peripheral
*                  - AHBAPB_FLAG: specifies the flag to check.
*                    This parameter can be one of the following values:
*                      - AHBAPB_FLAG_ERROR: error flag
*                      - AHBAPB_FLAG_OUTM : Out of Memory flag
*                      - AHBAPB_FLAG_APBT : APB Time-out flag
*                      - AHBAPB_FLAG_RW   : Access type flag
* Output         : None
* Return         : The new state of AHBAPB_FLAG (SET or RESET).
*******************************************************************************/
FlagStatus AHBAPB_GetFlagStatus(AHBAPB_TypeDef* AHBAPBx, u8 AHBAPB_FLAG)
{
  if(AHBAPB_FLAG == AHBAPB_FLAG_RW)
  {
    if ((AHBAPBx->PAER & AHBAPB_FLAG_RW_Mask) == RESET)
    {
       return RESET;
    }
    else
    {
      return SET;
    }
  }
  else
  {
    if ((AHBAPBx->BSR & AHBAPB_FLAG) == RESET)
    {
      return RESET;
    }
    else
    {
     return SET;
    }
  }
}
/*******************************************************************************
* Function Name  : AHBAPB_ClearFlag
* Description    : Clears the AHBAPBx flags.
* Input          : - AHBAPB: where x can be 0 or 1 to select the AHBAPB peripheral
*                  - AHBAPB_FLAG: flags to clear. This parameter one of the
*                    following values:
*                      - AHBAPB_FLAG_ERROR: error flag
*                      - AHBAPB_FLAG_OUTM : Out of Memory flag
*                      - AHBAPB_FLAG_APBT : APB Time-out flag
* Output         : None
* Return         : None
*******************************************************************************/
void AHBAPB_ClearFlag(AHBAPB_TypeDef* AHBAPBx, u8 AHBAPB_FLAG)
{
  /* Clear the flag */
  AHBAPBx->BSR &= AHBAPB_FLAG;
}
/*******************************************************************************
* Function Name  : AHBAPB_GetPeriphAddrError
* Description    : Gets the AHBAPB error address peripherals.
* Input          : - AHBAPB: where x can be 0 or 1 to select the AHBAPB peripheral
* Output         : None
* Return         : The Peropheral address error
*******************************************************************************/
u32 AHBAPB_GetPeriphAddrError(AHBAPB_TypeDef* AHBAPBx)
{
  u32 AHBAPB_Address = 0x00000000;

  /*Return Oeripheral address without RW bit*/
  AHBAPB_Address = (AHBAPBx->PAER)& AHBAPB_Address_Mask;
  return (AHBAPB_Address);
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
OpenPOWER on IntegriCloud