r_octa_sys.h 15.6 KB
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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
/*
****************************************************************************
PROJECT : OCTA driver
FILE    : $Id: r_octa_sys.h 15447 2017-12-20 00:25:00Z shinobu.uehara $
============================================================================
DESCRIPTION
OCTA support functions
============================================================================
                            C O P Y R I G H T
============================================================================
                           Copyright (c) 2017
                                  by
                       Renesas Electronics (Europe) GmbH.
                           Arcadiastrasse 10
                          D-40472 Duesseldorf
                               Germany
                          All rights reserved.
============================================================================
Purpose: only for testing, not for mass production

DISCLAIMER

LICENSEE has read, understood and accepted the terms and conditions defined in
the license agreement, especially the usage rights. In any case, it is
LICENSEE's responsibility to make sure that any user of the software complies
with the terms and conditions of the signed license agreement.

SAMPLE CODE is not part of the licensed software, as such it must not be used in
mass-production applications. It can only be used for evaluation and
demonstration purposes at customer's premises listed in the signed license
agreement.

****************************************************************************
*/

/***************************************************************************
  Title: OCTA Driver support functions

  OCTA (OctaBus Controller) driver support functions

  The generic OCTA driver uses these functions. They have to be implemented 
  within the driver library for a concrete device. (e.g. D1L, D1M)

  Support functions are functions that are not part of the driver itself 
  but they must be provided to integrate the driver on a particular board.
*/

#ifndef R_OCTA_SYS_H
#define R_OCTA_SYS_H

#ifdef __cplusplus
extern "C" {
#endif


/***************************************************************************
  Section: Global Functions
*/
/***************************************************************************
  Group: OCTA driver Basic interface functions
*/

/***************************************************************************
  Function: R_OCTA_Sys_Init

  Description:
  This function initializes environment-dependent part.
  This function is called from <R_OCTA_Init>.

  This function executes the following processing.
  * Checks whether this LSI supports OCTA function.

  Customizing Points:
  It is NOT necessary to modify this function in general use-case.
  If you want to add the initialization code of environment-depend (e.g. clock control), 
  please implement to this function.

  Parameter:
  Unit - Instance number.

  Return value:
  R_OCTA_ERR_OK               - No error has occurred.
  R_OCTA_ERR_RANGE_UNIT       - Unit number is out of range.
  R_OCTA_ERR_DEVICE           - OCTA driver is not applicable to this LSI.
  R_OCTA_ERR_FATAL_HW         - Fatal error has occurred at H/W.
  
  See <r_octa_Error_t>.
*/
r_octa_Error_t R_OCTA_Sys_Init(const uint32_t Unit);


/***************************************************************************
  Function: R_OCTA_Sys_DeInit

  Description:
  This function de-initializes environment-dependent part.
  This function is called from <R_OCTA_DeInit>.

  This function is empty as default.

  Customizing Points:
  It is NOT necessary to modify this function in general use-case.
  If you want to add the de-initialization code of environment-depend (e.g. clock control), 
  please implement to this function.

  Parameter:
  Unit - Instance number.

  Return value:
  R_OCTA_ERR_OK               - No error has occurred.
  R_OCTA_ERR_RANGE_UNIT       - Unit number is out of range.
  R_OCTA_ERR_FATAL_HW         - Fatal error has occurred at H/W.
  
  See <r_octa_Error_t>.
*/
r_octa_Error_t R_OCTA_Sys_DeInit(const uint32_t Unit);


/***************************************************************************
  Function: R_OCTA_Sys_BaseAddrGet

  Description:
  This function gives back the base address of OCTA H/W macro's register.
  This function is called from several OCTA APIs.

  This function executes the following processing.
  * Returns the register base address of OCTA H/W macro's register.

  Customizing Points:
  It is NOT necessary to modify this function in general use-case.

  Parameter:
  Unit    - Instance number.

  Return value:
  Macro base address.
*/
uint32_t R_OCTA_Sys_BaseAddrGet(const uint32_t Unit);

    
/***************************************************************************
  Function: R_OCTA_Sys_ExternalAddrSpaceBaseAddrGet

  Description:
  This function gives back the base address of external address space.
  This function is called from several OCTA APIs.

  This function executes the following processing.
  * Returns the base address of external address space.

  Customizing Points:
  It is NOT necessary to modify this function in general use-case.

  Parameter:
  Unit    - Instance number.
  Channel - Device Channel number.

  Return value:
  base address of external address space.
*/
uint32_t R_OCTA_Sys_ExternalAddrSpaceBaseAddrGet(const uint32_t Unit,
                                                 const uint32_t Channel);

    
/***************************************************************************
  Function: R_OCTA_Sys_DefaultDummyLengthGet

  Description:
  This function gives back the default dummy length.
  This function is called from several OCTA APIs.

  This function executes the following processing.
  * Returns the value of dummy length according to the device type.

  Customizing Points:
  * This function is sample code for MX65L12A64AA/MX25LW51245G/MX66LM1G45G and JSC64SSU8AGDY.
    If you use other OCTA flash or OCTA RAM, it must be changed according to the connected device
    specification.
  * Changes the return value of dummy length according to the connected device.

  Parameter:
  Unit       - Instance number.
  DeviceType - Control device type. 0:Octa Flash, 1:Octa RAM

  Return value:
  default dummy length.
*/
uint32_t R_OCTA_Sys_DefaultDummyLengthGet(const uint32_t Unit,
                                          const uint32_t Channel,
                                          const uint8_t DeviceType);


/***************************************************************************
  Function: R_OCTA_Sys_BankSizeGet

  Description:
  This function gives back the bank byte-size.
  This function is called from <R_OCTA_DataWriteRWW>.

  This function executes the following processing.
  * Returns the value of bank size of Octa flash memory with supporting RWW.
    The bank size must be power-of-two value (2^n).

  Customizing Points:
  * This function is sample code for MX25LW51245G.
    If you use other OCTA flash, it must be changed according to the connected device
    specification.
  * Changes the return value of bank size of Octa flash memory.

  Parameter:
  None

  Return value:
  bank size.
*/
uint32_t R_OCTA_Sys_BankSizeGet(void);


/***************************************************************************
  Function: R_OCTA_Sys_DummyDataRead

  Description:
  This function executes Dummy Data Read.
  This function is called from <R_OCTA_DataWriteRWW>.

  This function executes the following processing.
  * Read size is 32-bit. 
    If Base address is Bank0, read dummy data to other Bank.
    If Base address is other Bank, read dummy data to Bank0.

  Customizing Points:
  It is NOT necessary to modify this function in general use-case.

  Parameter:
  Base       - Base address of external address space.
  Addr       - Write address with RWW.
  BankSize   - Bank byte-size of connected Octa flash memory.

  Return value:
  None
*/
void R_OCTA_Sys_DummyDataRead(const uint32_t    Base,
                              const uint32_t    Addr,
                              const uint32_t    BankSize);


/***************************************************************************
  Function: R_OCTA_Sys_ConfigRegSet

  Description:
  This function makes the value to set the configuration register.
  This function is called from <R_OCTA_Open>.

  This function executes the following processing.
  * Reflects specified parameter to register value.

  Customizing Points:
  This function is sample code for MX65L12A64AA/MX25LW51245G/MX66LM1G45G and JSC64SSU8AGDY.
  If you use other OCTA flash or OCTA RAM, it must be changed according to the connected device
  specification.

  Parameter:
  Unit    - Instance number.
  Channel - Device Channel number.
  Config  - Pointer to the <r_octa_Config_t> structure.
  RegVal  - Original value of the configuration register.
  Type    - Configuration Type.

  Return value:
  Set value to the configuration register.
*/
uint16_t R_OCTA_Sys_ConfigRegSet(const uint32_t                  Unit,
                                 const uint32_t                  Channel,
                                 const r_octa_Config_t * const   Config,
                                 const uint16_t                  RegVal,
                                 const r_octa_StateType_t        Type);

    
/***************************************************************************
  Function: R_OCTA_Sys_StatusRegCheck

  Description:
  This function checks the value from the status register each Status Type,
  and it returns the result code.
  This function also judges the time out of status polling.
  This function is called from <R_OCTA_Open>, <R_OCTA_DataProtect>, <R_OCTA_DataErase>,
  <R_OCTA_DataWrite> and <R_OCTA_DataWriteRWW>.


  This function executes the following processing.
  * Checks the calling counter. If it reaches to time-out count, returns R_OCTA_ERR_TIMEOUT. 
  * Checks READY bit. If it shows BUSY state, returns R_OCTA_ERR_NOT_ACCEPTABLE. 
  * Checks Erase / Program Status bit. it shows Successful, returns R_OCTA_ERR_OK. 
  
  Customizing Points:
  * This function is sample code for MX65L12A64AA/MX25LW51245G/MX66LM1G45G and JSC64SSU8AGDY.
    If you use other OCTA flash or OCTA RAM, it must be changed according to the connected device
    specification.
  * If you want to change time-out count, please modify the definition R_OCTA_STATUS_TIMEOUT in 
    r_config_octa.h.
  * This function is called from busy wait. Please implement CPU relaxing to avoid blocking. 

  Parameter:
  Unit    - Instance number.
  Channel - Device Channel number.
  RegPos  - Bit position to check in the status register.
  RegVal  - Value of the status register.
  Type    - Status Type.
  Count   - Call counter.

  Return value:
  R_OCTA_ERR_OK               - No error has occurred.
  R_OCTA_ERR_RANGE_UNIT       - Unit number is out of range.
  R_OCTA_ERR_PARAM_INCORRECT  - A parameter is incorrect.
  R_OCTA_ERR_NOT_ACCEPTABLE   - A process is executing.
  R_OCTA_ERR_FATAL_OS         - Fatal error has occurred at OS interface.
  R_OCTA_ERR_PROTECTED        - A process is aborted because of memory protection.
  R_OCTA_ERR_ABORTED          - A process is aborted because of other reason.
  R_OCTA_ERR_TIMEOUT          - Status polling is timeout.
  
  See <r_octa_Error_t>.
*/
r_octa_Error_t R_OCTA_Sys_StatusRegCheck(const uint32_t           Unit, 
                                         const uint32_t           Channel,
                                         const uint16_t           RegPos,
                                         const uint16_t           RegVal,
                                         const r_octa_StateType_t Type,
                                         const uint32_t           Count);

    
/***************************************************************************
  Function: R_OCTA_Sys_StatusRegSet

  Description:
  This function makes the value of status register to set protection mode.

  This function executes the following processing.
  * Makes the value of status register to set protection mode.

  Customizing Points:
  * This function is sample code for MX65L12A64AA/MX25LW51245G/MX66LM1G45G.
    If you use other OCTA flash, it must be changed according to the connected device
    specification.
  * Generates the value of status register which set protection mode according to the connected 
    device specification.

  Parameter:
  Unit    - Instance number.
  Channel - Device Channel number.
  RegPos  - Bit position of the protection mode in the status register.
  RegVal  - Original value of the status register.
  Mode    - Block Protection mode.
            <0> protection mode.
            <1> un-protection mode.

  Return value:
  Set value to the status register.
*/
uint16_t R_OCTA_Sys_StatusRegSet(const uint32_t Unit,
                                 const uint32_t Channel,
                                 const uint16_t RegPos,
                                 const uint16_t RegVal,
                                 const uint8_t  Mode);

    
/***************************************************************************
  Function: R_OCTA_Sys_SyncPeripheral

  Description:
  This function performs synchronization processing to reflect updated
  contents of the control register.
  This function is called from several OCTA APIs.

  This function executes the following processing.
  * SYNCP instruction of RH850 is executed.

  Customizing Points:
  It is NOT necessary to modify this function in general use-case.

  Parameter:
  None

  Return value:
  None
*/
void R_OCTA_Sys_SyncPeripheral(void);

    
/***************************************************************************
  Group: OCTA driver OS interface functions
*/

/***************************************************************************
  Function: R_OCTA_Sys_Lock

  Description:
  This function locks the OCTA driver access to the specified unit from other threads.
  This function is called from several OCTA APIs.
  
  This function is empty as default.
  
  Customizing Points:
  Please implement the lock process by mutex or semaphore if OCTA API is called from 
  multi-thread.

  Parameter:
  Unit - Instance number.

  Return value:
  R_OCTA_ERR_OK               - No error has occurred.
  R_OCTA_ERR_RANGE_UNIT       - Unit number is out of range.
  R_OCTA_ERR_FATAL_OS         - Fatal error has occurred at OS interface.
  
  See <r_octa_Error_t>.
*/
r_octa_Error_t R_OCTA_Sys_Lock(const uint32_t Unit);


/***************************************************************************
  Function: R_OCTA_Sys_Unlock

  Description:
  This function unlocks the OCTA driver access to the specified unit from other threads.
  This function is called from several OCTA APIs.

  This function is empty as default.

  Customizing Points:
  Please implement the unlock process depending on <R_OCTA_Sys_Lock>.

  Parameter:
  Unit - Instance number.

  Return value:
  R_OCTA_ERR_OK               - No error has occurred.
  R_OCTA_ERR_RANGE_UNIT       - Unit number is out of range.
  R_OCTA_ERR_FATAL_OS         - Fatal error has occurred at OS interface.
  
  See <r_octa_Error_t>.
*/
r_octa_Error_t R_OCTA_Sys_Unlock(const uint32_t Unit);


/***************************************************************************
  Function: R_OCTA_Sys_Relax

  Description:
  This function relaxes CPU to avoid blocking.
  This function is called from <R_OCTA_DataErase> and <R_OCTA_DataWrite>.

  This function is empty as default.

  Customizing Points:
  Please implement the relaxing or re-scheduling process if necessary.

  Parameter:
  Unit - Instance number.

  Return value:
  R_OCTA_ERR_OK               - No error has occurred.
  R_OCTA_ERR_RANGE_UNIT       - Unit number is out of range.
  R_OCTA_ERR_FATAL_OS         - Fatal error has occurred at OS interface.
  
  See <r_octa_Error_t>.
*/
r_octa_Error_t R_OCTA_Sys_Relax(const uint32_t Unit);


#ifdef __cplusplus
}
#endif

#endif /* R_OCTA_SYS_H */