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