xref: /btstack/port/renesas-ek-ra6m4a-da14531/e2-project/src/hal_entry.c (revision c30869498fb8e98c1408c9db0e7624f02f483b73)
1 /***********************************************************************************************************************
2  * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates.  All Rights Reserved.
3  *
4  * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products
5  * of Renesas Electronics Corp. and its affiliates ("Renesas").  No other uses are authorized.  Renesas products are
6  * sold pursuant to Renesas terms and conditions of sale.  Purchasers are solely responsible for the selection and use
7  * of Renesas products and Renesas assumes no liability.  No license, express or implied, to any intellectual property
8  * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas
9  * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION
10  * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT
11  * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES
12  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR
13  * DOCUMENTATION.  RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH.  TO THE MAXIMUM
14  * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION
15  * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING,
16  * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS,
17  * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY
18  * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS.
19  **********************************************************************************************************************/
20 
21 #include "hal_data.h"
22 
23 void R_BSP_WarmStart(bsp_warm_start_event_t event);
24 
25 extern bsp_leds_t g_bsp_leds;
26 
27 /*******************************************************************************************************************//**
28  * @brief  Blinky example application
29  *
30  * Blinks all leds at a rate of 1 second using the software delay function provided by the BSP.
31  *
32  **********************************************************************************************************************/
hal_entry(void)33 void hal_entry (void)
34 {
35 #if BSP_TZ_SECURE_BUILD
36 
37     /* Enter non-secure code */
38     R_BSP_NonSecureEnter();
39 #endif
40 
41     // this is a test
42 
43     /* Define the units to be used with the software delay function */
44     const bsp_delay_units_t bsp_delay_units = BSP_DELAY_UNITS_MILLISECONDS;
45 
46     /* Set the blink frequency (must be <= bsp_delay_units */
47     const uint32_t freq_in_hz = 2;
48 
49     /* Calculate the delay in terms of bsp_delay_units */
50     const uint32_t delay = bsp_delay_units / freq_in_hz;
51 
52     /* LED type structure */
53     bsp_leds_t leds = g_bsp_leds;
54 
55     /* If this board has no LEDs then trap here */
56     if (0 == leds.led_count)
57     {
58         while (1)
59         {
60             ;                          // There are no LEDs on this board
61         }
62     }
63 
64     /* Holds level to set for pins */
65     bsp_io_level_t pin_level = BSP_IO_LEVEL_LOW;
66 
67     while (1)
68     {
69         /* Enable access to the PFS registers. If using r_ioport module then register protection is automatically
70          * handled. This code uses BSP IO functions to show how it is used.
71          */
72         R_BSP_PinAccessEnable();
73 
74         /* Update all board LEDs */
75         for (uint32_t i = 0; i < leds.led_count; i++)
76         {
77             /* Get pin to toggle */
78             uint32_t pin = leds.p_leds[i];
79 
80             /* Write to this pin */
81             R_BSP_PinWrite((bsp_io_port_pin_t) pin, pin_level);
82 
83             // RESET
84             R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_15, pin_level);
85 
86             // RTS
87             R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_02_PIN_05, pin_level);
88 
89         }
90 
91         /* Protect PFS registers */
92         R_BSP_PinAccessDisable();
93 
94         /* Toggle level for next write */
95         if (BSP_IO_LEVEL_LOW == pin_level)
96         {
97             pin_level = BSP_IO_LEVEL_HIGH;
98         }
99         else
100         {
101             pin_level = BSP_IO_LEVEL_LOW;
102         }
103 
104         /* Delay */
105         R_BSP_SoftwareDelay(delay, bsp_delay_units);
106     }
107 }
108 
109 /*******************************************************************************************************************//**
110  * This function is called at various points during the startup process.  This implementation uses the event that is
111  * called right before main() to set up the pins.
112  *
113  * @param[in]  event    Where at in the start up process the code is currently at
114  **********************************************************************************************************************/
R_BSP_WarmStart(bsp_warm_start_event_t event)115 void R_BSP_WarmStart (bsp_warm_start_event_t event)
116 {
117     if (BSP_WARM_START_RESET == event)
118     {
119 #if BSP_FEATURE_FLASH_LP_VERSION != 0
120 
121         /* Enable reading from data flash. */
122         R_FACI_LP->DFLCTL = 1U;
123 
124         /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
125          * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
126 #endif
127     }
128 
129     if (BSP_WARM_START_POST_C == event)
130     {
131         /* C runtime environment and system clocks are setup. */
132 
133         /* Configure pins. */
134         R_IOPORT_Open(&g_ioport_ctrl, g_ioport.p_cfg);
135     }
136 }
137