From a44c4cf5c3598f0669ad51bfc315938619cb59a2 Mon Sep 17 00:00:00 2001 From: Flex Software Development Robot Date: Tue, 26 Apr 2022 16:54:58 +0000 Subject: [PATCH] Release v3.7.0 --- README.md | 7 +- SUPPORTED_SOFTWARE.md | 111 +- ra/board/ra2e2_fpb/board.h | 61 + ra/board/ra2e2_fpb/board_init.c | 62 + ra/board/ra2e2_fpb/board_init.h | 58 + ra/board/ra2e2_fpb/board_leds.c | 70 + ra/board/ra2e2_fpb/board_leds.h | 74 + ra/board/ra6m5_ck/board.h | 62 + ra/board/ra6m5_ck/board_ethernet_phy.h | 60 + ra/board/ra6m5_ck/board_init.c | 62 + ra/board/ra6m5_ck/board_init.h | 58 + ra/board/ra6m5_ck/board_leds.c | 74 + ra/board/ra6m5_ck/board_leds.h | 78 ++ ra/fsp/inc/api/r_rtc_api.h | 8 + ra/fsp/inc/api/r_timer_api.h | 1 + ra/fsp/inc/api/r_usb_basic_api.h | 2 + ra/fsp/inc/api/r_usb_pprn_api.h | 61 + ra/fsp/inc/api/rm_ble_abs_api.h | 7 +- ra/fsp/inc/api/rm_ble_mesh_provision_api.h | 62 +- ra/fsp/inc/api/rm_comms_api.h | 6 +- ra/fsp/inc/api/rm_motor_120_control_api.h | 2 +- ra/fsp/inc/api/rm_motor_120_driver_api.h | 2 +- ra/fsp/inc/api/rm_ob1203_api.h | 651 +++++++++ ra/fsp/inc/fsp_version.h | 6 +- ra/fsp/inc/instances/r_ether_phy.h | 1 + ra/fsp/inc/instances/r_gpt.h | 18 +- ra/fsp/inc/instances/r_i3c.h | 5 + ra/fsp/inc/instances/r_rtc.h | 1 + ra/fsp/inc/instances/rm_ble_mesh_provision.h | 8 + .../inc/instances/rm_cellular_comm_uart_aws.h | 4 +- ra/fsp/inc/instances/rm_comms_i2c.h | 4 +- ra/fsp/inc/instances/rm_filex_levelx_nor.h | 16 +- ra/fsp/inc/instances/rm_hs300x.h | 1 + .../inc/instances/rm_mesh_bearer_platform.h | 34 + ra/fsp/inc/instances/rm_mesh_light_ctl_srv.h | 6 + ra/fsp/inc/instances/rm_mesh_light_hsl_srv.h | 7 + ra/fsp/inc/instances/rm_ob1203.h | 188 +++ .../cmsis/Device/RENESAS/Include/renesas.h | 43 +- ra/fsp/src/bsp/mcu/all/bsp_clocks.c | 35 +- ra/fsp/src/bsp/mcu/all/bsp_common.h | 6 +- ra/fsp/src/bsp/mcu/ra2a1/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra2e1/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra2e2/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra2l1/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra2l1/bsp_power.c | 2 +- ra/fsp/src/bsp/mcu/ra4e1/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra4m1/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra4m2/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra4m3/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra4w1/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra6e1/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra6m1/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra6m2/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra6m3/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra6m4/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra6m5/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra6t1/bsp_feature.h | 5 + ra/fsp/src/bsp/mcu/ra6t2/bsp_feature.h | 5 + ra/fsp/src/r_agt/r_agt.c | 10 + ra/fsp/src/r_canfd/r_canfd.c | 51 +- ra/fsp/src/r_ctsu/r_ctsu.c | 8 +- ra/fsp/src/r_ether_phy/r_ether_phy.c | 59 +- .../DP83620/r_ether_phy_target_dp83620.c | 23 +- .../ICS1894/r_ether_phy_target_ics1894.c | 126 ++ .../KSZ8041/r_ether_phy_target_ksz8041.c | 23 +- .../r_ether_phy_target_ksz8091rnb.c | 23 +- ra/fsp/src/r_flash_hp/r_flash_hp.c | 6 +- ra/fsp/src/r_gpt/r_gpt.c | 36 +- ra/fsp/src/r_i3c/r_i3c.c | 307 +++-- ra/fsp/src/r_iirfa/r_iirfa.c | 2 +- ra/fsp/src/r_kint/r_kint.c | 12 + ra/fsp/src/r_rtc/r_rtc.c | 68 +- .../src/sce9/inc/api/r_sce_api.h | 2 +- .../src/sce9/public/r_sce_tls.c | 2 +- ra/fsp/src/r_usb_basic/r_usb_basic.c | 317 +++-- .../src/driver/inc/r_usb_cstd_rtos.h | 25 +- .../r_usb_basic/src/driver/inc/r_usb_extern.h | 9 +- .../src/driver/inc/r_usb_typedef.h | 32 +- .../r_usb_basic/src/driver/r_usb_cdataio.c | 105 +- .../r_usb_basic/src/driver/r_usb_clibusbip.c | 17 +- .../r_usb_basic/src/driver/r_usb_cstd_rtos.c | 31 + .../r_usb_basic/src/driver/r_usb_hdriver.c | 25 +- .../r_usb_basic/src/driver/r_usb_hlibusbip.c | 12 +- .../r_usb_basic/src/driver/r_usb_hmanager.c | 6 +- .../r_usb_basic/src/driver/r_usb_pdriver.c | 106 +- .../r_usb_basic/src/driver/r_usb_plibusbip.c | 77 +- .../r_usb_basic/src/driver/r_usb_psignal.c | 2 +- .../src/driver/r_usb_pstdfunction.c | 40 +- .../src/driver/r_usb_pstdrequest.c | 34 +- .../r_usb_basic/src/hw/r_usb_creg_access.c | 3 +- .../r_usb_basic/src/hw/r_usb_hreg_access.c | 22 +- ra/fsp/src/r_usb_basic/src/hw/r_usb_mcu.c | 57 +- .../r_usb_phid_phid_descriptor.c.template | 368 +++++ ra/fsp/src/r_usb_phid/src/r_usb_phid_driver.c | 23 +- .../src/r_usb_pmsc/src/r_media_driver_api.c | 2 +- ra/fsp/src/rm_ble_abs/rm_ble_abs.c | 2 +- ra/fsp/src/rm_ble_abs_spp/r_ble_spp_api.c | 301 +++- ra/fsp/src/rm_ble_abs_spp/rm_ble_abs_spp.c | 160 +-- .../rm_cellular_comm_uart_aws.c | 176 ++- .../src/rm_comms_i2c/rm_comms_i2c_driver_ra.c | 10 +- ra/fsp/src/rm_emwin_port/LCDConf.c | 2 +- .../rm_filex_levelx_nor/rm_filex_levelx_nor.c | 2 +- .../rm_guix_port/gx_display_driver_dave2d.c | 2 +- ra/fsp/src/rm_hs300x/rm_hs300x.c | 81 +- .../rm_mcuboot_port/crypto/sce9_image_rsa.c | 292 ++++ ra/fsp/src/rm_mcuboot_port/crypto/sce9_keys.c | 143 +- ra/fsp/src/rm_mcuboot_port/crypto/sce9_keys.h | 16 + ra/fsp/src/rm_mcuboot_port/rm_mcuboot_port.c | 19 - .../light_mode/rm_ob1203_light_mode.c | 603 ++++++++ .../rm_ob1203_light_proximity_mode.c | 827 +++++++++++ .../rm_ob1203/ppg_mode/rm_ob1203_ppg_mode.c | 550 ++++++++ .../proximity_mode/rm_ob1203_proximity_mode.c | 535 +++++++ ra/fsp/src/rm_ob1203/rm_ob1203.c | 1224 +++++++++++++++++ ra/fsp/src/rm_ob1203/rm_ob1203_ra_driver.c | 250 ++++ ra/fsp/src/rm_psa_crypto/rsa_alt_process.c | 1 - ...m_usbx_phid_descriptor_keyboard.c.template | 31 +- ra/fsp/src/rm_usbx_port/rm_usbx_port.c | 118 +- .../rm_usbx_pprn_descriptor.c.template | 274 ++++ ra/fsp/src/rm_usbx_port/ux_port.h | 29 + 119 files changed, 8896 insertions(+), 932 deletions(-) create mode 100644 ra/board/ra2e2_fpb/board.h create mode 100644 ra/board/ra2e2_fpb/board_init.c create mode 100644 ra/board/ra2e2_fpb/board_init.h create mode 100644 ra/board/ra2e2_fpb/board_leds.c create mode 100644 ra/board/ra2e2_fpb/board_leds.h create mode 100644 ra/board/ra6m5_ck/board.h create mode 100644 ra/board/ra6m5_ck/board_ethernet_phy.h create mode 100644 ra/board/ra6m5_ck/board_init.c create mode 100644 ra/board/ra6m5_ck/board_init.h create mode 100644 ra/board/ra6m5_ck/board_leds.c create mode 100644 ra/board/ra6m5_ck/board_leds.h create mode 100644 ra/fsp/inc/api/r_usb_pprn_api.h create mode 100644 ra/fsp/inc/api/rm_ob1203_api.h create mode 100644 ra/fsp/inc/instances/rm_ob1203.h create mode 100644 ra/fsp/src/r_ether_phy/targets/ICS1894/r_ether_phy_target_ics1894.c create mode 100644 ra/fsp/src/r_usb_composite/r_usb_phid_phid_descriptor.c.template create mode 100644 ra/fsp/src/rm_mcuboot_port/crypto/sce9_image_rsa.c create mode 100644 ra/fsp/src/rm_ob1203/light_mode/rm_ob1203_light_mode.c create mode 100644 ra/fsp/src/rm_ob1203/light_proximity_mode/rm_ob1203_light_proximity_mode.c create mode 100644 ra/fsp/src/rm_ob1203/ppg_mode/rm_ob1203_ppg_mode.c create mode 100644 ra/fsp/src/rm_ob1203/proximity_mode/rm_ob1203_proximity_mode.c create mode 100644 ra/fsp/src/rm_ob1203/rm_ob1203.c create mode 100644 ra/fsp/src/rm_ob1203/rm_ob1203_ra_driver.c create mode 100644 ra/fsp/src/rm_usbx_port/rm_usbx_pprn_descriptor.c.template diff --git a/README.md b/README.md index e7a6c3fc8..3da349c3f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ FSP uses an open software ecosystem and provides flexibility in using your prefe ### Current Release -[FSP v3.6.0](https://github.com/renesas/fsp/releases/tag/v3.6.0) +[FSP v3.7.0](https://github.com/renesas/fsp/releases/tag/v3.7.0) ### Supported RA MCU Kits @@ -27,8 +27,10 @@ FSP uses an open software ecosystem and provides flexibility in using your prefe - EK-RA6M3 - EK-RA6M3G - EK-RA6M4 +- CK-RA6M5 - EK-RA6M5 - FPB-RA2E1 +- FPB-RA2E2 - FPB-RA4E1 - FPB-RA6E1 - MCK-RA6T2 @@ -59,12 +61,13 @@ For a list of software modules packaged with FSP, see [Supported Software](SUPPO - FSP versions of 3.2.0 and later require a minimum e² studio version of 2021-07. - FSP versions of 3.4.0 and later require a minimum e² studio version of 2021-10. - FSP versions of 3.6.0 and later require a minimum e² studio version of 2022-01. +- FSP versions of 3.7.0 and later require a minimum e² studio version of 2022-04. If you have already installed a previous FSP release that included e² studio then you can download the packs separately. These are available for download under the Assets section for each release. There is a zipped version, FSP_Packs_\.zip, and an installer version, FSP_Packs_\.exe. #### For new users that are using FSP with e² studio -1. Download the FSP with e² studio Installer from the Assets section of the [current release](https://github.com/renesas/fsp/releases/tag/v3.6.0). +1. Download the FSP with e² studio Installer from the Assets section of the [current release](https://github.com/renesas/fsp/releases/tag/v3.7.0). 2. Run the installer. This will install the e² studio tool, FSP packs, GCC toolchain and other tools required to use this software. No additional installations are required. #### If using RA Smart Configurator (RASC) with IAR Embedded Workbench or Keil MDK #### diff --git a/SUPPORTED_SOFTWARE.md b/SUPPORTED_SOFTWARE.md index 724412ffd..f42023419 100644 --- a/SUPPORTED_SOFTWARE.md +++ b/SUPPORTED_SOFTWARE.md @@ -26,12 +26,11 @@ * [Azure RTOS USBX HCDC](https://docs.microsoft.com/en-us/azure/rtos/usbx/) * [Azure RTOS USBX HHID](https://docs.microsoft.com/en-us/azure/rtos/usbx/) * [Azure RTOS USBX OTG CDC](https://docs.microsoft.com/en-us/azure/rtos/usbx/) - * [Azure RTOS USBX OTG HID](https://docs.microsoft.com/en-us/azure/rtos/usbx/) - * [Azure RTOS USBX OTG MSC](https://docs.microsoft.com/en-us/azure/rtos/usbx/) * [Azure RTOS USBX PAUD](https://docs.microsoft.com/en-us/azure/rtos/usbx/) * [Azure RTOS USBX PCDC](https://docs.microsoft.com/en-us/azure/rtos/usbx/) * [Azure RTOS USBX PHID](https://docs.microsoft.com/en-us/azure/rtos/usbx/) * [Azure RTOS USBX PMSC](https://docs.microsoft.com/en-us/azure/rtos/usbx/) + * [Azure RTOS USBX PPRN](https://docs.microsoft.com/en-us/azure/rtos/usbx/) * [CAN (r_can)](https://renesas.github.io/fsp/group___c_a_n.html) * [CAN FD (r_canfd)](https://renesas.github.io/fsp/group___c_a_n_f_d.html) * [CEC (r_cec)](https://renesas.github.io/fsp/group___c_e_c.html) @@ -136,55 +135,57 @@ * [Azure RTOS NetX Duo Web HTTP/HTTPS Client](https://docs.microsoft.com/en-us/azure/rtos/netx-duo/netx-duo-web-http/chapter1) * [Azure RTOS NetX Duo Web HTTP/HTTPS Server](https://docs.microsoft.com/en-us/azure/rtos/netx-duo/netx-duo-web-http/chapter1) * [BLE Abstraction (rm_ble_abs)](https://renesas.github.io/fsp/group___b_l_e___a_b_s.html) - * [BLE Mesh (rm_ble_mesh)](https://renesas.github.io/fsp/group___b_l_e___m_e_s_h.html) - * [BLE Mesh Access (rm_ble_mesh_access)](https://renesas.github.io/fsp/group___b_l_e___m_e_s_h___a_c_c_e_s_s.html) - * [BLE Mesh Bearer (rm_ble_mesh_bearer)](https://renesas.github.io/fsp/group___b_l_e___m_e_s_h___b_e_a_r_e_r.html) - * [BLE Mesh Bearer Platform (rm_mesh_bearer_platform)](https://renesas.github.io/fsp/group___m_e_s_h___b_e_a_r_e_r___p_l_a_t_f_o_r_m.html) - * [BLE Mesh Config Client (rm_mesh_config_clt)](https://renesas.github.io/fsp/group___m_e_s_h___c_o_n_f_i_g___c_l_t.html) - * [BLE Mesh Config Server (rm_mesh_config_srv)](https://renesas.github.io/fsp/group___m_e_s_h___c_o_n_f_i_g___s_r_v.html) - * [BLE Mesh Lower Trans (rm_ble_mesh_lower_trans)](https://renesas.github.io/fsp/group___b_l_e___m_e_s_h___l_o_w_e_r___t_r_a_n_s.html) - * [BLE Mesh Model Generic Admin Property Server (rm_mesh_generic_admin_prop_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___a_d_m_i_n___p_r_o_p___s_r_v.html) - * [BLE Mesh Model Generic Battery Client (rm_mesh_generic_battery_clt)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___b_a_t_t_e_r_y___c_l_t.html) - * [BLE Mesh Model Generic Battery Server (rm_mesh_generic_battery_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___b_a_t_t_e_r_y___s_r_v.html) - * [BLE Mesh Model Generic Client Property Server (rm_mesh_generic_client_prop_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___c_l_i_e_n_t___p_r_o_p___s_r_v.html) - * [BLE Mesh Model Generic Default Transition Time Client (rm_mesh_generic_dtt_clt)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___d_t_t___c_l_t.html) - * [BLE Mesh Model Generic Default Transition Time Server (rm_mesh_generic_dtt_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___d_t_t___s_r_v.html) - * [BLE Mesh Model Generic Level Client (rm_mesh_generic_level_clt)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___l_e_v_e_l___c_l_t.html) - * [BLE Mesh Model Generic Level Server (rm_mesh_generic_level_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___l_e_v_e_l___s_r_v.html) - * [BLE Mesh Model Generic Location Client (rm_mesh_generic_loc_clt)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___l_o_c___c_l_t.html) - * [BLE Mesh Model Generic Location Server (rm_mesh_generic_loc_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___l_o_c___s_r_v.html) - * [BLE Mesh Model Generic Manufacturer Property Server (rm_mesh_generic_mfr_prop_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___m_f_r___p_r_o_p___s_r_v.html) - * [BLE Mesh Model Generic On Off Client (rm_mesh_generic_on_off_clt)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___o_n___o_f_f___c_l_t.html) - * [BLE Mesh Model Generic On Off Server (rm_mesh_generic_on_off_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___o_n___o_f_f___s_r_v.html) - * [BLE Mesh Model Generic Power Level Client (rm_mesh_generic_pl_clt)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___p_l___c_l_t.html) - * [BLE Mesh Model Generic Power Level Server (rm_mesh_generic_pl_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___p_l___s_r_v.html) - * [BLE Mesh Model Generic Power On Off Client (rm_mesh_generic_poo_clt)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___p_o_o___c_l_t.html) - * [BLE Mesh Model Generic Power On Off Server (rm_mesh_generic_poo_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___p_o_o___s_r_v.html) - * [BLE Mesh Model Generic Property Client (rm_mesh_generic_prop_clt)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___p_r_o_p___c_l_t.html) - * [BLE Mesh Model Generic User Property Server (rm_mesh_generic_user_prop_srv)](https://renesas.github.io/fsp/group___m_e_s_h___g_e_n_e_r_i_c___u_s_e_r___p_r_o_p___s_r_v.html) - * [BLE Mesh Model Health Client (rm_mesh_health_clt)](https://renesas.github.io/fsp/group___m_e_s_h___h_e_a_l_t_h___c_l_t.html) - * [BLE Mesh Model Health Server (rm_mesh_health_srv)](https://renesas.github.io/fsp/group___m_e_s_h___h_e_a_l_t_h___s_r_v.html) - * [BLE Mesh Model Light Control Client (rm_mesh_light_ctl_clt)](https://renesas.github.io/fsp/group___m_e_s_h___l_i_g_h_t___c_t_l___c_l_t.html) - * [BLE Mesh Model Light Control Server (rm_mesh_light_ctl_srv)](https://renesas.github.io/fsp/group___m_e_s_h___l_i_g_h_t___c_t_l___s_r_v.html) - * [BLE Mesh Model Light HSL Client (rm_mesh_light_hsl_clt)](https://renesas.github.io/fsp/group___m_e_s_h___l_i_g_h_t___h_s_l___c_l_t.html) - * [BLE Mesh Model Light HSL Server (rm_mesh_light_hsl_srv)](https://renesas.github.io/fsp/group___m_e_s_h___l_i_g_h_t___h_s_l___s_r_v.html) - * [BLE Mesh Model Light Lightness Client (rm_mesh_light_lightness_clt)](https://renesas.github.io/fsp/group___m_e_s_h___l_i_g_h_t___l_i_g_h_t_n_e_s_s___c_l_t.html) - * [BLE Mesh Model Light Lightness Controller Client (rm_mesh_light_lc_clt)](https://renesas.github.io/fsp/group___m_e_s_h___l_i_g_h_t___l_c___c_l_t.html) - * [BLE Mesh Model Light Lightness Controller Server (rm_mesh_light_lc_srv)](https://renesas.github.io/fsp/group___m_e_s_h___l_i_g_h_t___l_c___s_r_v.html) - * [BLE Mesh Model Light Lightness Server (rm_mesh_light_lightness_srv)](https://renesas.github.io/fsp/group___m_e_s_h___l_i_g_h_t___l_i_g_h_t_n_e_s_s___s_r_v.html) - * [BLE Mesh Model Light XYL Client (rm_mesh_light_xyl_clt)](https://renesas.github.io/fsp/group___m_e_s_h___l_i_g_h_t___x_y_l___c_l_t.html) - * [BLE Mesh Model Light XYL Server (rm_mesh_light_xyl_srv)](https://renesas.github.io/fsp/group___m_e_s_h___l_i_g_h_t___x_y_l___s_r_v.html) - * [BLE Mesh Model Scene Client (rm_mesh_scene_clt)](https://renesas.github.io/fsp/group___m_e_s_h___s_c_e_n_e___c_l_t.html) - * [BLE Mesh Model Scene Server (rm_mesh_scene_srv)](https://renesas.github.io/fsp/group___m_e_s_h___s_c_e_n_e___s_r_v.html) - * [BLE Mesh Model Scheduler Client (rm_mesh_scheduler_clt)](https://renesas.github.io/fsp/group___m_e_s_h___s_c_h_e_d_u_l_e_r___c_l_t.html) - * [BLE Mesh Model Scheduler Server (rm_mesh_scheduler_srv)](https://renesas.github.io/fsp/group___m_e_s_h___s_c_h_e_d_u_l_e_r___s_r_v.html) - * [BLE Mesh Model Sensor Client (rm_mesh_sensor_clt)](https://renesas.github.io/fsp/group___m_e_s_h___s_e_n_s_o_r___c_l_t.html) - * [BLE Mesh Model Sensor Server (rm_mesh_sensor_srv)](https://renesas.github.io/fsp/group___m_e_s_h___s_e_n_s_o_r___s_r_v.html) - * [BLE Mesh Model Time Client (rm_mesh_time_clt)](https://renesas.github.io/fsp/group___m_e_s_h___t_i_m_e___c_l_t.html) - * [BLE Mesh Model Time Server (rm_mesh_time_srv)](https://renesas.github.io/fsp/group___m_e_s_h___t_i_m_e___s_r_v.html) - * [BLE Mesh Network (rm_ble_mesh_network)](https://renesas.github.io/fsp/group___b_l_e___m_e_s_h___n_e_t_w_o_r_k.html) - * [BLE Mesh Provision (rm_ble_mesh_provision)](https://renesas.github.io/fsp/group___b_l_e___m_e_s_h___p_r_o_v_i_s_i_o_n.html) - * [BLE Mesh Upper Trans (rm_ble_mesh_upper_trans)](https://renesas.github.io/fsp/group___b_l_e___m_e_s_h___u_p_p_e_r___t_r_a_n_s.html) + * [BLE Mesh (rm_ble_mesh)](https://renesas.github.io/fsp/group___r_m___b_l_e___m_e_s_h.html) + * [BLE Mesh Access (rm_ble_mesh_access)](https://renesas.github.io/fsp/group___r_m___b_l_e___m_e_s_h___a_c_c_e_s_s.html) + * [BLE Mesh Bearer (rm_ble_mesh_bearer)](https://renesas.github.io/fsp/group___r_m___b_l_e___m_e_s_h___b_e_a_r_e_r.html) + * [BLE Mesh Bearer Platform (rm_mesh_bearer_platform)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___b_e_a_r_e_r___p_l_a_t_f_o_r_m.html) + * [BLE Mesh Config Client (rm_mesh_config_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___c_o_n_f_i_g___c_l_t.html) + * [BLE Mesh Config Server (rm_mesh_config_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___c_o_n_f_i_g___s_r_v.html) + * [BLE Mesh Lower Trans (rm_ble_mesh_lower_trans)](https://renesas.github.io/fsp/group___r_m___b_l_e___m_e_s_h___l_o_w_e_r___t_r_a_n_s.html) + * [BLE Mesh Model Generic Admin Property Server (rm_mesh_generic_admin_prop_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___a_d_m_i_n___p_r_o_p___s_r_v.html) + * [BLE Mesh Model Generic Battery Client (rm_mesh_generic_battery_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___b_a_t_t_e_r_y___c_l_t.html) + * [BLE Mesh Model Generic Battery Server (rm_mesh_generic_battery_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___b_a_t_t_e_r_y___s_r_v.html) + * [BLE Mesh Model Generic Client Property Server (rm_mesh_generic_client_prop_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___c_l_i_e_n_t___p_r_o_p___s_r_v.html) + * [BLE Mesh Model Generic Default Transition Time Client (rm_mesh_generic_dtt_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___d_t_t___c_l_t.html) + * [BLE Mesh Model Generic Default Transition Time Server (rm_mesh_generic_dtt_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___d_t_t___s_r_v.html) + * [BLE Mesh Model Generic Level Client (rm_mesh_generic_level_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___l_e_v_e_l___c_l_t.html) + * [BLE Mesh Model Generic Level Server (rm_mesh_generic_level_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___l_e_v_e_l___s_r_v.html) + * [BLE Mesh Model Generic Location Client (rm_mesh_generic_loc_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___l_o_c___c_l_t.html) + * [BLE Mesh Model Generic Location Server (rm_mesh_generic_loc_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___l_o_c___s_r_v.html) + * [BLE Mesh Model Generic Manufacturer Property Server (rm_mesh_generic_mfr_prop_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___m_f_r___p_r_o_p___s_r_v.html) + * [BLE Mesh Model Generic On Off Client (rm_mesh_generic_on_off_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___o_n___o_f_f___c_l_t.html) + * [BLE Mesh Model Generic On Off Server (rm_mesh_generic_on_off_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___o_n___o_f_f___s_r_v.html) + * [BLE Mesh Model Generic Power Level Client (rm_mesh_generic_pl_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___p_l___c_l_t.html) + * [BLE Mesh Model Generic Power Level Server (rm_mesh_generic_pl_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___p_l___s_r_v.html) + * [BLE Mesh Model Generic Power On Off Client (rm_mesh_generic_poo_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___p_o_o___c_l_t.html) + * [BLE Mesh Model Generic Power On Off Server (rm_mesh_generic_poo_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___p_o_o___s_r_v.html) + * [BLE Mesh Model Generic Property Client (rm_mesh_generic_prop_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___p_r_o_p___c_l_t.html) + * [BLE Mesh Model Generic User Property Server (rm_mesh_generic_user_prop_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___g_e_n_e_r_i_c___u_s_e_r___p_r_o_p___s_r_v.html) + * [BLE Mesh Model Health Client (rm_mesh_health_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___h_e_a_l_t_h___c_l_t.html) + * [BLE Mesh Model Health Server (rm_mesh_health_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___h_e_a_l_t_h___s_r_v.html) + * [BLE Mesh Model Light Control Client (rm_mesh_light_ctl_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___l_i_g_h_t___c_t_l___c_l_t.html) + * [BLE Mesh Model Light Control Server (rm_mesh_light_ctl_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___l_i_g_h_t___c_t_l___s_r_v.html) + * [BLE Mesh Model Light HSL Client (rm_mesh_light_hsl_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___l_i_g_h_t___h_s_l___c_l_t.html) + * [BLE Mesh Model Light HSL Server (rm_mesh_light_hsl_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___l_i_g_h_t___h_s_l___s_r_v.html) + * [BLE Mesh Model Light Lightness Client (rm_mesh_light_lightness_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___l_i_g_h_t___l_i_g_h_t_n_e_s_s___c_l_t.html) + * [BLE Mesh Model Light Lightness Controller Client (rm_mesh_light_lc_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___l_i_g_h_t___l_c___c_l_t.html) + * [BLE Mesh Model Light Lightness Controller Server (rm_mesh_light_lc_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___l_i_g_h_t___l_c___s_r_v.html) + * [BLE Mesh Model Light Lightness Server (rm_mesh_light_lightness_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___l_i_g_h_t___l_i_g_h_t_n_e_s_s___s_r_v.html) + * [BLE Mesh Model Light XYL Client (rm_mesh_light_xyl_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___l_i_g_h_t___x_y_l___c_l_t.html) + * [BLE Mesh Model Light XYL Server (rm_mesh_light_xyl_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___l_i_g_h_t___x_y_l___s_r_v.html) + * [BLE Mesh Model Scene Client (rm_mesh_scene_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___s_c_e_n_e___c_l_t.html) + * [BLE Mesh Model Scene Server (rm_mesh_scene_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___s_c_e_n_e___s_r_v.html) + * [BLE Mesh Model Scheduler Client (rm_mesh_scheduler_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___s_c_h_e_d_u_l_e_r___c_l_t.html) + * [BLE Mesh Model Scheduler Server (rm_mesh_scheduler_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___s_c_h_e_d_u_l_e_r___s_r_v.html) + * [BLE Mesh Model Sensor Client (rm_mesh_sensor_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___s_e_n_s_o_r___c_l_t.html) + * [BLE Mesh Model Sensor Server (rm_mesh_sensor_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___s_e_n_s_o_r___s_r_v.html) + * [BLE Mesh Model Time Client (rm_mesh_time_clt)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___t_i_m_e___c_l_t.html) + * [BLE Mesh Model Time Server (rm_mesh_time_srv)](https://renesas.github.io/fsp/group___r_m___m_e_s_h___t_i_m_e___s_r_v.html) + * [BLE Mesh Network (rm_ble_mesh_network)](https://renesas.github.io/fsp/group___r_m___b_l_e___m_e_s_h___n_e_t_w_o_r_k.html) + * [BLE Mesh Provision (rm_ble_mesh_provision)](https://renesas.github.io/fsp/group___r_m___b_l_e___m_e_s_h___p_r_o_v_i_s_i_o_n.html) + * [BLE Mesh Upper Trans (rm_ble_mesh_upper_trans)](https://renesas.github.io/fsp/group___r_m___b_l_e___m_e_s_h___u_p_p_e_r___t_r_a_n_s.html) + * [BLE SPP Transport on SPI (rm_ble_abs_spp_transport)](https://renesas.github.io/fsp/group___b_l_e___a_b_s.html) + * [BLE SPP Transport on UART (rm_ble_abs_spp_transport)](https://renesas.github.io/fsp/group___b_l_e___a_b_s.html) * [Ethernet (r_ether)](https://renesas.github.io/fsp/group___e_t_h_e_r.html) * [Ethernet (r_ether_phy)](https://renesas.github.io/fsp/group___e_t_h_e_r___p_h_y.html) * [FreeRTOS+TCP](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html) @@ -215,6 +216,7 @@ * Sensor * [FS2012 Flow Sensor (rm_fs2012)](https://renesas.github.io/fsp/group___r_m___f_s2012.html) * [HS300X Temperature/Humidity Sensor (rm_hs300x)](https://renesas.github.io/fsp/group___r_m___h_s300_x.html) + * [OB1203 Light/Proximity/PPG Sensor (rm_ob1203)](https://renesas.github.io/fsp/group___r_m___o_b1203.html) * [ZMOD4XXX Gas Sensor (rm_zmod4xxx)](https://renesas.github.io/fsp/group___r_m___z_m_o_d4_x_x_x.html) * Storage * [Azure RTOS FileX on Block Media](https://docs.microsoft.com/en-us/azure/rtos/filex/) @@ -266,6 +268,8 @@ * [MCUboot sysflash](https://github.com/mcu-tools/mcuboot) * Connectivity * [Azure RTOS USBX HMSC](https://docs.microsoft.com/en-us/azure/rtos/usbx/) + * [Azure RTOS USBX OTG HID](https://docs.microsoft.com/en-us/azure/rtos/usbx/) + * [Azure RTOS USBX OTG MSC](https://docs.microsoft.com/en-us/azure/rtos/usbx/) * [Azure RTOS USBX Port (rm_usbx_port)](https://renesas.github.io/fsp/group___u_s_b_x.html) * [USB (r_usb_basic)](https://renesas.github.io/fsp/group___u_s_b.html) * [USB HCDC (r_usb_hcdc)](https://renesas.github.io/fsp/group___u_s_b___h_c_d_c.html) @@ -274,6 +278,7 @@ * [USB PCDC (r_usb_pcdc_class)](https://renesas.github.io/fsp/group___u_s_b___p_c_d_c.html) * [USB PCDC 2channel (r_usb_pcdc)](https://renesas.github.io/fsp/group___u_s_b___p_c_d_c.html) * [USB PHID (r_usb_phid_class)](https://renesas.github.io/fsp/group___u_s_b___p_h_i_d.html) + * [USB PHID 2channel (r_usb_phid)](https://renesas.github.io/fsp/group___u_s_b___p_h_i_d.html) * [USB PMSC (r_usb_pmsc_class)](https://renesas.github.io/fsp/group___u_s_b___p_m_s_c.html) * [USB Peripheral Vendor class (r_usb_pvnd_class)](https://renesas.github.io/fsp/group___u_s_b___p_v_n_d.html) * Graphics @@ -334,6 +339,10 @@ * [Trusted Firmware-M FreeRTOS Integration](https://tf-m-user-guide.trustedfirmware.org/) * [Trusted Firmware-M Port (rm_tfm_port)](https://tf-m-user-guide.trustedfirmware.org/) * Sensor + * [OB1203 Light Proximity mode (rm_ob1203)](https://renesas.github.io/fsp/group___r_m___o_b1203.html) + * [OB1203 Light mode (rm_ob1203)](https://renesas.github.io/fsp/group___r_m___o_b1203.html) + * [OB1203 PPG mode (rm_ob1203)](https://renesas.github.io/fsp/group___r_m___o_b1203.html) + * [OB1203 Proximity mode (rm_ob1203)](https://renesas.github.io/fsp/group___r_m___o_b1203.html) * [ZMOD4410 IAQ 1st Generation (rm_zmod4xxx)](https://renesas.github.io/fsp/group___r_m___z_m_o_d4_x_x_x.html) * [ZMOD4410 IAQ 2nd Generation (rm_zmod4xxx)](https://renesas.github.io/fsp/group___r_m___z_m_o_d4_x_x_x.html) * [ZMOD4410 IAQ 2nd Generation Ultra Low Power (rm_zmod4xxx)](https://renesas.github.io/fsp/group___r_m___z_m_o_d4_x_x_x.html) diff --git a/ra/board/ra2e2_fpb/board.h b/ra/board/ra2e2_fpb/board.h new file mode 100644 index 000000000..08a72d942 --- /dev/null +++ b/ra/board/ra2e2_fpb/board.h @@ -0,0 +1,61 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @ingroup BOARDS + * @defgroup BOARD_RA2E2_FPB for the RA2E2_FPB board + * @brief BSP for the RA2E2_FPB Board + * + * The RA2E2_FPB is a development kit for the Renesas R7FA2E1A92DFM microcontroller in a LQFP64 package. + * + * @{ + **********************************************************************************************************************/ + +#ifndef BOARD_H +#define BOARD_H + +/*********************************************************************************************************************** + * Includes , "Project Includes" + **********************************************************************************************************************/ + +/* BSP Board Specific Includes. */ +#include "board_init.h" +#include "board_leds.h" + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ +#define BOARD_RA2E2_FPB + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global variables + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global functions (to be accessed by other files) + **********************************************************************************************************************/ + +/** @} (end defgroup BOARD_RA2E2_FPB) */ + +#endif diff --git a/ra/board/ra2e2_fpb/board_init.c b/ra/board/ra2e2_fpb/board_init.c new file mode 100644 index 000000000..102b31d7b --- /dev/null +++ b/ra/board/ra2e2_fpb/board_init.c @@ -0,0 +1,62 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @addtogroup BOARD_RA2E2_FPB + * + * @{ + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Includes , "Project Includes" + **********************************************************************************************************************/ +#include "bsp_api.h" + +#if defined(BOARD_RA2E2_FPB) + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global variables (to be accessed by other files) + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Private global variables and functions + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief Performs any initialization specific to this BSP. + * + * @param[in] p_args Pointer to arguments of the user's choice. + **********************************************************************************************************************/ +void bsp_init (void * p_args) +{ + FSP_PARAMETER_NOT_USED(p_args); +} + +#endif + +/** @} (end addtogroup BOARD_RA2E2_FPB) */ diff --git a/ra/board/ra2e2_fpb/board_init.h b/ra/board/ra2e2_fpb/board_init.h new file mode 100644 index 000000000..0d3f6e64e --- /dev/null +++ b/ra/board/ra2e2_fpb/board_init.h @@ -0,0 +1,58 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @addtogroup BOARD_RA2E2_FPB + * @brief Board specific code for the RA2E2_FPB Board + * + * This include file is specific to the RA2E2_FPB board. + * + * @{ + **********************************************************************************************************************/ + +#ifndef BOARD_INIT_H +#define BOARD_INIT_H + +/** Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_HEADER + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global variables + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global functions (to be accessed by other files) + **********************************************************************************************************************/ +void bsp_init(void * p_args); + +/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ +FSP_FOOTER + +#endif + +/** @} (end addtogroup BOARD_RA2E2_FPB_EK) */ diff --git a/ra/board/ra2e2_fpb/board_leds.c b/ra/board/ra2e2_fpb/board_leds.c new file mode 100644 index 000000000..7ead13115 --- /dev/null +++ b/ra/board/ra2e2_fpb/board_leds.c @@ -0,0 +1,70 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @addtogroup BOARD_RA2E2_FPB_LEDS + * + * @{ + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Includes + **********************************************************************************************************************/ +#include "bsp_api.h" +#if defined(BOARD_RA2E2_FPB) + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Private global variables and functions + **********************************************************************************************************************/ + +/** Array of LED IOPORT pins. */ +static const uint16_t g_bsp_prv_leds[] = +{ + (uint16_t) BSP_IO_PORT_00_PIN_15, ///< LED1 + (uint16_t) BSP_IO_PORT_09_PIN_14, ///< LED2 +}; + +/*********************************************************************************************************************** + * Exported global variables (to be accessed by other files) + **********************************************************************************************************************/ + +/** Structure with LED information for this board. */ + +const bsp_leds_t g_bsp_leds = +{ + .led_count = (uint16_t) ((sizeof(g_bsp_prv_leds) / sizeof(g_bsp_prv_leds[0]))), + .p_leds = &g_bsp_prv_leds[0] +}; + +/*********************************************************************************************************************** + * Exported global variables (to be accessed by other files) + **********************************************************************************************************************/ + +#endif + +/** @} (end addtogroup BOARD_RA2E2_FPB_LEDS) */ diff --git a/ra/board/ra2e2_fpb/board_leds.h b/ra/board/ra2e2_fpb/board_leds.h new file mode 100644 index 000000000..7f2936d38 --- /dev/null +++ b/ra/board/ra2e2_fpb/board_leds.h @@ -0,0 +1,74 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @ingroup BOARD_RA2E2_FPB + * @defgroup BOARD_RA2E2_FPB_LEDS Board LEDs + * @brief LED information for this board. + * + * This is code specific to the EK board. It includes info on the number of LEDs and which pins are they + * are on. + * + * @{ + **********************************************************************************************************************/ + +#ifndef BOARD_LEDS_H +#define BOARD_LEDS_H + +/** Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_HEADER + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/** Information on how many LEDs and what pins they are on. */ +typedef struct st_bsp_leds +{ + uint16_t led_count; ///< The number of LEDs on this board + uint16_t const * p_leds; ///< Pointer to an array of IOPORT pins for controlling LEDs +} bsp_leds_t; + +/** Available user-controllable LEDs on this board. These enums can be can be used to index into the array of LED pins + * found in the bsp_leds_t structure. */ +typedef enum e_bsp_led +{ + BSP_LED_LED1, ///< LED1 + BSP_LED_LED2, ///< LED2 +} bsp_led_t; + +/*********************************************************************************************************************** + * Exported global variables + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Public Functions + **********************************************************************************************************************/ + +/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ +FSP_FOOTER + +#endif + +/** @} (end defgroup BOARD_RA2E2_FPB_LEDS) */ diff --git a/ra/board/ra6m5_ck/board.h b/ra/board/ra6m5_ck/board.h new file mode 100644 index 000000000..25e1d0c67 --- /dev/null +++ b/ra/board/ra6m5_ck/board.h @@ -0,0 +1,62 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @ingroup BOARDS + * @defgroup BOARD_RA6M5_CK for the RA6M5-CK board + * @brief BSP for the RA6M5-CK Board + * + * The RA6M5_CK is a development kit for the Renesas R7FA6M5BH3CFC microcontroller in a LQFP176 package. + * + * @{ + **********************************************************************************************************************/ + +#ifndef BOARD_H +#define BOARD_H + +/*********************************************************************************************************************** + * Includes , "Project Includes" + **********************************************************************************************************************/ + +/* BSP Board Specific Includes. */ +#include "board_init.h" +#include "board_leds.h" +#include "board_ethernet_phy.h" + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ +#define BOARD_RA6M5_CK + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global variables + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global functions (to be accessed by other files) + **********************************************************************************************************************/ + +/** @} (end defgroup BOARD_RA6M5_CK) */ + +#endif diff --git a/ra/board/ra6m5_ck/board_ethernet_phy.h b/ra/board/ra6m5_ck/board_ethernet_phy.h new file mode 100644 index 000000000..62ed2d7a0 --- /dev/null +++ b/ra/board/ra6m5_ck/board_ethernet_phy.h @@ -0,0 +1,60 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @ingroup BOARD_RA6M5_CK + * @defgroup BOARD_RA6M5_CK_ETHERNET_PHY Board Ethernet Phy + * @brief Ethernet Phy information for this board. + * + * This is code specific to the RA6M5_CK board. + * + * @{ + **********************************************************************************************************************/ + +#ifndef BSP_ETHERNET_PHY_H +#define BSP_ETHERNET_PHY_H + +/** Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_HEADER + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ +#define BOARD_PHY_TYPE (4) +#define BOARD_PHY_REF_CLK (1) + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global variables + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Public Functions + **********************************************************************************************************************/ + +/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ +FSP_FOOTER + +#endif + +/** @} (end defgroup BOARD_RA6M5_CK_ETHERNET_PHY) */ diff --git a/ra/board/ra6m5_ck/board_init.c b/ra/board/ra6m5_ck/board_init.c new file mode 100644 index 000000000..1d325d4cc --- /dev/null +++ b/ra/board/ra6m5_ck/board_init.c @@ -0,0 +1,62 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @addtogroup BOARD_RA6M5_CK + * + * @{ + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Includes , "Project Includes" + **********************************************************************************************************************/ +#include "bsp_api.h" + +#if defined(BOARD_RA6M5_CK) + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global variables (to be accessed by other files) + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Private global variables and functions + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief Performs any initialization specific to this BSP. + * + * @param[in] p_args Pointer to arguments of the user's choice. + **********************************************************************************************************************/ +void bsp_init (void * p_args) +{ + FSP_PARAMETER_NOT_USED(p_args); +} + +#endif + +/** @} (end addtogroup BOARD_RA6M5_CK) */ diff --git a/ra/board/ra6m5_ck/board_init.h b/ra/board/ra6m5_ck/board_init.h new file mode 100644 index 000000000..2352848d1 --- /dev/null +++ b/ra/board/ra6m5_ck/board_init.h @@ -0,0 +1,58 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @addtogroup BOARD_RA6M5_CK + * @brief Board specific code for the RA6M5-CK Board + * + * This include file is specific to the RA6M5-CK board. + * + * @{ + **********************************************************************************************************************/ + +#ifndef BOARD_INIT_H +#define BOARD_INIT_H + +/** Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_HEADER + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global variables + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global functions (to be accessed by other files) + **********************************************************************************************************************/ +void bsp_init(void * p_args); + +/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ +FSP_FOOTER + +#endif + +/** @} (end addtogroup BOARD_RA6M5_CK) */ diff --git a/ra/board/ra6m5_ck/board_leds.c b/ra/board/ra6m5_ck/board_leds.c new file mode 100644 index 000000000..cdf567e00 --- /dev/null +++ b/ra/board/ra6m5_ck/board_leds.c @@ -0,0 +1,74 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @addtogroup BOARD_RA6M5_CK_LEDS + * + * @{ + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Includes + **********************************************************************************************************************/ +#include "bsp_api.h" +#if defined(BOARD_RA6M5_CK) + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Private global variables and functions + **********************************************************************************************************************/ + +/** Array of LED IOPORT pins. */ +static const uint16_t g_bsp_prv_leds[] = +{ + (uint16_t) BSP_IO_PORT_06_PIN_10, ///< LED1 RED + (uint16_t) BSP_IO_PORT_06_PIN_09, ///< LED3 GREEN + (uint16_t) BSP_IO_PORT_06_PIN_01, ///< LED4 BLUE + (uint16_t) BSP_IO_PORT_06_PIN_02, ///< LED2_TRI_COLOUR_RED + (uint16_t) BSP_IO_PORT_06_PIN_03, ///< LED2_TRI_COLOUR_GREEN + (uint16_t) BSP_IO_PORT_06_PIN_05, ///< LED2_TRI_COLOUR_BLUE +}; + +/*********************************************************************************************************************** + * Exported global variables (to be accessed by other files) + **********************************************************************************************************************/ + +/** Structure with LED information for this board. */ + +const bsp_leds_t g_bsp_leds = +{ + .led_count = (uint16_t) ((sizeof(g_bsp_prv_leds) / sizeof(g_bsp_prv_leds[0]))), + .p_leds = &g_bsp_prv_leds[0] +}; + +/*********************************************************************************************************************** + * Exported global variables (to be accessed by other files) + **********************************************************************************************************************/ + +#endif + +/** @} (end addtogroup BOARD_RA6M5_CK_LEDS) */ diff --git a/ra/board/ra6m5_ck/board_leds.h b/ra/board/ra6m5_ck/board_leds.h new file mode 100644 index 000000000..ee109f903 --- /dev/null +++ b/ra/board/ra6m5_ck/board_leds.h @@ -0,0 +1,78 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @ingroup BOARD_RA6M5_CK + * @defgroup BOARD_RA6M5_CK_LEDS Board LEDs + * @brief LED information for this board. + * + * This is code specific to the CK board. It includes info on the number of LEDs and which pins are they + * are on. + * + * @{ + **********************************************************************************************************************/ + +#ifndef BOARD_LEDS_H +#define BOARD_LEDS_H + +/** Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_HEADER + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/** Information on how many LEDs and what pins they are on. */ +typedef struct st_bsp_leds +{ + uint16_t led_count; ///< The number of LEDs on this board + uint16_t const * p_leds; ///< Pointer to an array of IOPORT pins for controlling LEDs +} bsp_leds_t; + +/** Available user-controllable LEDs on this board. These enums can be can be used to index into the array of LED pins + * found in the bsp_leds_t structure. */ +typedef enum e_bsp_led +{ + BSP_LED_LED1, ///< LED1 RED + BSP_LED_LED3, ///< LED3 GREEN + BSP_LED_LED4, ///< LED4 BLUE + BSP_LED_LED2_RED, ///< LED2_TRI_COLOUR_RED + BSP_LED_LED2_GREEN, ///< LED2_TRI_COLOUR_GREEN + BSP_LED_LED2_BLUE, ///< LED2_TRI_COLOUR_BLUE +} bsp_led_t; + +/*********************************************************************************************************************** + * Exported global variables + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Public Functions + **********************************************************************************************************************/ + +/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ +FSP_FOOTER + +#endif + +/** @} (end defgroup BOARD_RA6M5_CK_LEDS) */ diff --git a/ra/fsp/inc/api/r_rtc_api.h b/ra/fsp/inc/api/r_rtc_api.h index cf8f6294d..b61e643c6 100644 --- a/ra/fsp/inc/api/r_rtc_api.h +++ b/ra/fsp/inc/api/r_rtc_api.h @@ -199,6 +199,14 @@ typedef struct st_rtc_api */ fsp_err_t (* close)(rtc_ctrl_t * const p_ctrl); + /** Sets the RTC clock source. + * @par Implemented as + * - @ref R_RTC_ClockSourceSet() + * + * @param[in] p_ctrl Pointer to RTC device handle + */ + fsp_err_t (* clockSourceSet)(rtc_ctrl_t * const p_ctrl); + /** Set the calendar time and start the calender counter * @par Implemented as * - @ref R_RTC_CalendarTimeSet() diff --git a/ra/fsp/inc/api/r_timer_api.h b/ra/fsp/inc/api/r_timer_api.h index b008a3a44..57ef0c806 100644 --- a/ra/fsp/inc/api/r_timer_api.h +++ b/ra/fsp/inc/api/r_timer_api.h @@ -108,6 +108,7 @@ typedef enum e_timer_mode TIMER_MODE_PERIODIC, ///< Timer restarts after period elapses. TIMER_MODE_ONE_SHOT, ///< Timer stops after period elapses. TIMER_MODE_PWM, ///< Timer generates saw-wave PWM output. + TIMER_MODE_ONE_SHOT_PULSE, ///< Saw-wave one-shot pulse mode (fixed buffer operation). TIMER_MODE_TRIANGLE_WAVE_SYMMETRIC_PWM = 4U, ///< Timer generates symmetric triangle-wave PWM output. TIMER_MODE_TRIANGLE_WAVE_ASYMMETRIC_PWM = 5U, ///< Timer generates asymmetric triangle-wave PWM output. diff --git a/ra/fsp/inc/api/r_usb_basic_api.h b/ra/fsp/inc/api/r_usb_basic_api.h index 898c6c764..11caed1eb 100644 --- a/ra/fsp/inc/api/r_usb_basic_api.h +++ b/ra/fsp/inc/api/r_usb_basic_api.h @@ -231,7 +231,9 @@ typedef enum e_usb_class USB_CLASS_PCDC2, ///< PCDC2 Class USB_CLASS_PCDCC2, ///< PCDCC2 Class USB_CLASS_PHID, ///< PHID Class + USB_CLASS_PHID2, ///< PHID2 Class USB_CLASS_PAUD, ///< PAUD Class + USB_CLASS_PPRN, ///< PPRN Class USB_CLASS_PVND, ///< PVND Class USB_CLASS_HCDC, ///< HCDC Class USB_CLASS_HCDCC, ///< HCDCC Class diff --git a/ra/fsp/inc/api/r_usb_pprn_api.h b/ra/fsp/inc/api/r_usb_pprn_api.h new file mode 100644 index 000000000..14c9ff893 --- /dev/null +++ b/ra/fsp/inc/api/r_usb_pprn_api.h @@ -0,0 +1,61 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @ingroup RENESAS_INTERFACES + * @defgroup USB_PPRN_API USB PPRN Interface + * @brief Interface for USB PPRN functions. + * + * @section USB_PPRN_API_Summary Summary + * The USB PPRN interface provides USB PPRN functionality. + * + * The USB PPRN interface can be implemented by: + * - @ref USBX + * + * @{ + **********************************************************************************************************************/ + +#ifndef R_USB_PPRN_API_H +#define R_USB_PPRN_API_H + +/****************************************************************************** + * Includes , "Project Includes" + ******************************************************************************/ +#include "r_usb_pprn_cfg.h" + +/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_HEADER + +/****************************************************************************** + * Macro definitions + ******************************************************************************/ + +/******************************************************************************* + * Typedef definitions + *******************************************************************************/ + +/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ + FSP_FOOTER + +#endif /* R_USB_PPRN_API_H */ + +/*******************************************************************************************************************//** + * @} (end addtogroup USB_PPRN_API) + **********************************************************************************************************************/ diff --git a/ra/fsp/inc/api/rm_ble_abs_api.h b/ra/fsp/inc/api/rm_ble_abs_api.h index b27655799..7d8986207 100644 --- a/ra/fsp/inc/api/rm_ble_abs_api.h +++ b/ra/fsp/inc/api/rm_ble_abs_api.h @@ -47,7 +47,8 @@ #include "r_timer_api.h" #else #include "r_uart_api.h" - #include "r_sci_uart.h" + #include "r_spi_api.h" + #include "r_external_irq_api.h" #endif #include "fsp_common_api.h" @@ -789,7 +790,9 @@ typedef struct st_ble_abs_cfg flash_instance_t const * p_flash_instance; ///< Pointer to flash instance. timer_instance_t const * p_timer_instance; ///< Pointer to timer instance. #else - const uart_instance_t * p_uart_instance; ///< SCI UART instance + const uart_instance_t * p_uart_instance; ///< SCI UART instance + const spi_instance_t * p_spi_instance; ///< SPI instance + const external_irq_instance_t * p_irq_instance; ///< IRQ instance #endif void (* p_callback)(ble_abs_callback_args_t * p_args); ///< Callback provided when a BLE ISR occurs. void const * p_context; ///< Placeholder for user data. Passed to the user callback in ble_abs_callback_args_t. diff --git a/ra/fsp/inc/api/rm_ble_mesh_provision_api.h b/ra/fsp/inc/api/rm_ble_mesh_provision_api.h index d9a33009f..c5522b595 100644 --- a/ra/fsp/inc/api/rm_ble_mesh_provision_api.h +++ b/ra/fsp/inc/api/rm_ble_mesh_provision_api.h @@ -500,7 +500,7 @@ typedef struct st_rm_ble_mesh_provision_api * @param [in] info Device information. * @param [in] timeout The time period for which the setup shall be active. * - * @return API_SUCCESS or Error Code on failure + * @return FSP_SUCCESS or Error Code on failure */ fsp_err_t (* setup)(rm_ble_mesh_provision_ctrl_t * const p_ctrl, rm_ble_mesh_provision_role_t role, rm_ble_mesh_provision_device_info_t info, uint16_t timeout); @@ -509,14 +509,16 @@ typedef struct st_rm_ble_mesh_provision_api * @par Implemented as * - @ref RM_BLE_MESH_PROVISION_Bind() * - * @param [in] p_ctrl Pointer to control structure. - * @param [in] info Device information. + * @param [in] p_ctrl Pointer to control structure. + * @param [in] info Device information. + * @param [in] attention The attention duration in seconds to be configured by the device. + * This parameter is dont care if the role is RM_BLE_MESH_PROVISION_ROLE_DEVICE. * @param [out] p_handle Pointer to handle. * * @note This API is for use by the Provisioner application only upon * reception of an Unprovisioned Device Beacon. * - * @return API_SUCCESS or Error Code on failure + * @return FSP_SUCCESS or Error Code on failure */ fsp_err_t (* bind)(rm_ble_mesh_provision_ctrl_t * const p_ctrl, rm_ble_mesh_provision_device_info_t info, uint8_t attention, rm_ble_mesh_provision_handle_t * const p_handle); @@ -533,7 +535,7 @@ typedef struct st_rm_ble_mesh_provision_api * PROV_PDU_TYPE_DATA * @param [in] pdu_data Pointer to the data corresponding to the above PDUs * - * @return API_SUCCESS or Error Code on failure + * @return FSP_SUCCESS or Error Code on failure */ fsp_err_t (* sendPdu)(rm_ble_mesh_provision_ctrl_t * const p_ctrl, rm_ble_mesh_provision_handle_t const * const p_handle, rm_ble_mesh_provision_pdu_type_t type, @@ -545,9 +547,9 @@ typedef struct st_rm_ble_mesh_provision_api * * @param [in] p_ctrl Pointer to control structure. * @param [in] p_handle Pointer to provisioning context to be used. - * @param [in] auth_value Pointer to the Authval (UINT32 *) or (uint8_t *) + * @param [in] auth_value The buffer structure that is stored authentication data and data size. * - * @return API_SUCCESS or Error Code on failure + * @return FSP_SUCCESS or Error Code on failure */ fsp_err_t (* setAuthVal)(rm_ble_mesh_provision_ctrl_t * const p_ctrl, rm_ble_mesh_provision_handle_t const * const p_handle, rm_ble_mesh_buffer_t auth_value); @@ -560,7 +562,7 @@ typedef struct st_rm_ble_mesh_provision_api * @param [in] p_handle Pointer to provisioning context to be used. * @param [in] reason Reason for termination. * - * @return API_SUCCESS or Error Code on failure + * @return FSP_SUCCESS or Error Code on failure */ fsp_err_t (* abort)(rm_ble_mesh_provision_ctrl_t * const p_ctrl, rm_ble_mesh_provision_handle_t const * const p_handle, @@ -575,7 +577,7 @@ typedef struct st_rm_ble_mesh_provision_api * @param [out] public_key To a pointer of uint8_t array of length * @ref RM_BLE_MESH_PROVISION_KEY_NETKEY_SIZE * - * @return API_SUCCESS or Error Code on failure + * @return FSP_SUCCESS or Error Code on failure */ fsp_err_t (* getLocalPublicKey)(rm_ble_mesh_provision_ctrl_t * const p_ctrl, uint8_t * const public_key); @@ -588,9 +590,49 @@ typedef struct st_rm_ble_mesh_provision_api * @param [out] public_key To a pointer of uint8_t array of length * @ref RM_BLE_MESH_PROVISION_KEY_NETKEY_SIZE * - * @return API_SUCCESS or Error Code on failure + * @return FSP_SUCCESS or Error Code on failure */ fsp_err_t (* setLocalPublicKey)(rm_ble_mesh_provision_ctrl_t * const p_ctrl, uint8_t const * const public_key); + + /** Utility API to generate 128bits (16 bytes) randomized number to be used for provisioning. + * @par Implemented as + * - @ref RM_BLE_MESH_PROVISION_GenerateRandomizedNumber() + * + * @param [in] p_ctrl Pointer to control structure. + * + * @param [out] p_key Pointer to buffer to store random number + * + * @return FSP_SUCCESS or Error Code on failure + */ + fsp_err_t (* generateRandomizedNumber)(rm_ble_mesh_provision_ctrl_t * const p_ctrl, uint8_t * const p_key); + + /** Utility API to set device out of band public key for provisioning. + * @par Implemented as + * - @ref RM_BLE_MESH_PROVISION_SetOobPublicKey() + * + * @param [in] p_ctrl Pointer to control structure. + * + * @param [in] p_key Pointer to Public Key + * @param [out] size Size of public key + * + * @return FSP_SUCCESS or Error Code on failure + */ + fsp_err_t (* setOobPublicKey)(rm_ble_mesh_provision_ctrl_t * const p_ctrl, uint8_t const * const p_key, + uint8_t size); + + /** Utility API to set device out of band authentication information for provisioning. + * @par Implemented as + * - @ref RM_BLE_MESH_PROVISION_SetOobAuthInfo() + * + * @param [in] p_ctrl Pointer to control structure. + * + * @param [out] p_auth_info Pointer to authentication information. + * @param [out] size Size of authentication information. + * + * @return FSP_SUCCESS or Error Code on failure + */ + fsp_err_t (* setOobAuthInfo)(rm_ble_mesh_provision_ctrl_t * const p_ctrl, uint8_t const * const p_auth_info, + uint8_t size); } rm_ble_mesh_provision_api_t; /** This structure encompasses everything that is needed to use an instance of this interface. */ diff --git a/ra/fsp/inc/api/rm_comms_api.h b/ra/fsp/inc/api/rm_comms_api.h index 3a7f06f93..c67c87f21 100644 --- a/ra/fsp/inc/api/rm_comms_api.h +++ b/ra/fsp/inc/api/rm_comms_api.h @@ -40,7 +40,7 @@ **********************************************************************************************************************/ #if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) #include "platform.h" -#elif defined(__CCRL__) || defined(__ICCRL__) || defined(__RL78__) +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) #include #include #include "r_cg_macrodriver.h" @@ -50,7 +50,7 @@ #endif #if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) -#elif defined(__CCRL__) || defined(__ICCRL__) || defined(__RL78__) +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) #else /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ @@ -163,7 +163,7 @@ typedef struct st_rm_comms_instance } rm_comms_instance_t; #if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) -#elif defined(__CCRL__) || defined(__ICCRL__) || defined(__RL78__) +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) #else /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ diff --git a/ra/fsp/inc/api/rm_motor_120_control_api.h b/ra/fsp/inc/api/rm_motor_120_control_api.h index 62ea5634d..a2abc35c8 100644 --- a/ra/fsp/inc/api/rm_motor_120_control_api.h +++ b/ra/fsp/inc/api/rm_motor_120_control_api.h @@ -20,7 +20,7 @@ /*******************************************************************************************************************//** * @ingroup RENESAS_INTERFACES - * @defgroup MOTOR_120_CONTROL_API Interface + * @defgroup MOTOR_120_CONTROL_API Motor 120-Degree Control Interface * @brief Interface for motor 120 control functions. * * @section MOTOR_120_CONTROL_API_Summary Summary diff --git a/ra/fsp/inc/api/rm_motor_120_driver_api.h b/ra/fsp/inc/api/rm_motor_120_driver_api.h index e13629d16..ac881909a 100644 --- a/ra/fsp/inc/api/rm_motor_120_driver_api.h +++ b/ra/fsp/inc/api/rm_motor_120_driver_api.h @@ -20,7 +20,7 @@ /*******************************************************************************************************************//** * @ingroup RENESAS_INTERFACES - * @defgroup MOTOR_120_DRIVER_API Interface + * @defgroup MOTOR_120_DRIVER_API Motor 120-Degree Driver Interface * @brief Interface for motor driver functions. * * @section MOTOR_120_DRIVER_API_Summary Summary diff --git a/ra/fsp/inc/api/rm_ob1203_api.h b/ra/fsp/inc/api/rm_ob1203_api.h new file mode 100644 index 000000000..df6da33ae --- /dev/null +++ b/ra/fsp/inc/api/rm_ob1203_api.h @@ -0,0 +1,651 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @ingroup RENESAS_INTERFACES + * @defgroup RM_OB1203_API OB1203 Middleware Interface + * @brief Interface for OB1203 Middleware functions. + * + * @section RM_OB1203_API_Summary Summary + * The OB1203 interface provides OB1203 functionality. + * + * The OB1203 interface can be implemented by: + * - @ref RM_OB1203 + * + * @{ + **********************************************************************************************************************/ + +#ifndef RM_OB1203_API_H_ +#define RM_OB1203_API_H_ + +/*********************************************************************************************************************** + * Includes + **********************************************************************************************************************/ +#if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) + #include + #include "platform.h" + #if BSP_CFG_RTOS_USED == 1 // FreeRTOS + #include "FreeRTOS.h" + #include "task.h" + #include "queue.h" + #include "semphr.h" + #define BSP_CFG_RTOS 2 + #elif BSP_CFG_RTOS_USED == 5 // ThreadX + #define BSP_CFG_RTOS 1 + #else + #define BSP_CFG_RTOS 0 + #endif +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) + #include + #include "r_cg_macrodriver.h" + #include "r_fsp_error.h" +#else + #include "bsp_api.h" + #include "r_external_irq_api.h" + #if BSP_CFG_RTOS == 1 // ThreadX + #include "tx_api.h" + #elif BSP_CFG_RTOS == 2 // FreeRTOS + #include "FreeRTOS.h" + #include "task.h" + #include "queue.h" + #include "semphr.h" + #endif +#endif + +#include "rm_comms_api.h" + +#if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) +#else + +/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_HEADER +#endif + +/********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/** Event in the callback function */ +typedef enum e_rm_ob1203_event +{ + RM_OB1203_EVENT_SUCCESS = 0, + RM_OB1203_EVENT_ERROR, + RM_OB1203_EVENT_MEASUREMENT_COMPLETE, + RM_OB1203_EVENT_OBJECT_NEAR, + RM_OB1203_EVENT_THRESHOLD_CROSSED, +} rm_ob1203_event_t; + +/** Operation mode of OB1203 */ +typedef enum e_rm_ob1203_operation_mode +{ + RM_OB1203_OPERATION_MODE_STANDBY = 0, ///< Standby + RM_OB1203_OPERATION_MODE_LIGHT, ///< Light mode + RM_OB1203_OPERATION_MODE_PROXIMITY, ///< Proximity mode + RM_OB1203_OPERATION_MODE_PPG, ///< PPG mode +} rm_ob1203_operation_mode_t; + +/** Light sensor mode of OB1203 */ +typedef enum e_rm_ob1203_light_sensor_mode +{ + RM_OB1203_LIGHT_SENSOR_MODE_LS = 0x00, ///< Light sensor LS mode (Green, Clear, Comp) + RM_OB1203_LIGHT_SENSOR_MODE_CS = 0x02, ///< Light sensor CS mode (Red, Green, Blue, Clear, Comp) +} rm_ob1203_light_sensor_mode_t; + +/** PPG sensor mode of OB1203 */ +typedef enum e_rm_ob1203_ppg_sensor_mode +{ + RM_OB1203_PPG_SENSOR_MODE_PPG1 = 0x02, ///< PPG sensor PPG1 mode + RM_OB1203_PPG_SENSOR_MODE_PPG2 = 0x04, ///< PPG sensor PPG2 mode +} rm_ob1203_ppg_sensor_mode_t; + +/** Data type of Light */ +typedef enum e_rm_ob1203_light_data_type +{ + RM_OB1203_LIGHT_DATA_TYPE_ALL = 0, ///< Common + RM_OB1203_LIGHT_DATA_TYPE_CLEAR, ///< Common + RM_OB1203_LIGHT_DATA_TYPE_GREEN, ///< Common + RM_OB1203_LIGHT_DATA_TYPE_BLUE, ///< CS mode only + RM_OB1203_LIGHT_DATA_TYPE_RED, ///< CS mode only + RM_OB1203_LIGHT_DATA_TYPE_COMP, ///< Common. Temperature compensation data. +} rm_ob1203_light_data_type_t; + +/** Light gain range. Gain scales the ADC output and noise */ +typedef enum e_rm_ob1203_light_gain +{ + RM_OB1203_LIGHT_GAIN_1 = 0x00, ///< Gain mode 1. + RM_OB1203_LIGHT_GAIN_3 = 0x01, ///< Gain mode 3. + RM_OB1203_LIGHT_GAIN_6 = 0x02, ///< Gain mode 6. +} rm_ob1203_light_gain_t; + +/** PPG and proximity gain range. Gain scales the ADC output and noise */ +typedef enum e_rm_ob1203_ppg_prox_gain +{ + RM_OB1203_PPG_PROX_GAIN_1 = 0x00, ///< Gain mode 1. + RM_OB1203_PPG_PROX_GAIN_1P5 = 0x10, ///< Gain mode 1.5. + RM_OB1203_PPG_PROX_GAIN_2 = 0x20, ///< Gain mode 2. + RM_OB1203_PPG_PROX_GAIN_4 = 0x30, ///< Gain mode 4. +} rm_ob1203_ppg_prox_gain_t; + +/** LED order. Controls which LED is activated (PS, PPG1) or in which order the LEDs are activated (PPG2) */ +typedef enum e_rm_ob1203_led_order +{ + RM_OB1203_LED_IR_FIRST_RED_SECOND = 0x00, ///< First LED : IR LED, second LED : red LED. + RM_OB1203_LED_RED_FIRST_IR_SECOND = 0x08, ///< First LED : red LED, second LED : IR LED. +} rm_ob1203_led_order_t; + +/** Light interrupt type */ +typedef enum e_rm_ob1203_light_interrupt_type +{ + RM_OB1203_LIGHT_INTERRUPT_TYPE_THRESHOLD = 0x00, ///< Light threshold interrupt. + RM_OB1203_LIGHT_INTERRUPT_TYPE_VARIATION = 0x02, ///< Light variation interrupt. +} rm_ob1203_light_interrupt_type_t; + +/** Light interrupt source */ +typedef enum e_rm_ob1203_light_interrupt_source +{ + RM_OB1203_LIGHT_INTERRUPT_SOURCE_CLEAR_CHANNEL = 0x00, ///< Clear channel. + RM_OB1203_LIGHT_INTERRUPT_SOURCE_GREEN_CHANNEL = 0x10, ///< Green channel. + RM_OB1203_LIGHT_INTERRUPT_SOURCE_RED_CHANNEL = 0x20, ///< Red channel. CS mode only. + RM_OB1203_LIGHT_INTERRUPT_SOURCE_BLUE_CHANNEL = 0x30, ///< Blue channel. CS mode only. +} rm_ob1203_light_interrupt_source_t; + +/** Proximity interrupt type */ +typedef enum e_rm_ob1203_prox_interrupt_type +{ + RM_OB1203_PROX_INTERRUPT_TYPE_NORMAL = 0x00, ///< Proximity normal interrupt. + RM_OB1203_PROX_INTERRUPT_TYPE_LOGIC = 0x02, ///< Proximity logic output interrupt. +} rm_ob1203_prox_interrupt_type_t; + +/** PPG interrupt type */ +typedef enum e_rm_ob1203_ppg_interrupt_type +{ + RM_OB1203_PPG_INTERRUPT_TYPE_DATA = 0x10, ///< PPG data interrupt. + RM_OB1203_PPG_INTERRUPT_TYPE_FIFO_AFULL = 0x20, ///< PPG FIFO almost full interrupt. +} rm_ob1203_ppg_interrupt_type_t; + +/** Variance threshold */ +typedef enum e_rm_ob1203_variance_threshold +{ + RM_OB1203_VARIANCE_THRESHOLD_8_COUNTS = 0x00, ///< New LS_DATA varies by ± 8 counts compared to previous result. + RM_OB1203_VARIANCE_THRESHOLD_16_COUNTS = 0x01, ///< New LS_DATA varies by ± 16 counts compared to previous result. + RM_OB1203_VARIANCE_THRESHOLD_32_COUNTS = 0x02, ///< New LS_DATA varies by ± 32 counts compared to previous result. + RM_OB1203_VARIANCE_THRESHOLD_64_COUNTS = 0x03, ///< New LS_DATA varies by ± 64 counts compared to previous result. + RM_OB1203_VARIANCE_THRESHOLD_128_COUNTS = 0x04, ///< New LS_DATA varies by ± 128 counts compared to previous result. + RM_OB1203_VARIANCE_THRESHOLD_256_COUNTS = 0x05, ///< New LS_DATA varies by ± 256 counts compared to previous result. + RM_OB1203_VARIANCE_THRESHOLD_512_COUNTS = 0x06, ///< New LS_DATA varies by ± 512 counts compared to previous result. + RM_OB1203_VARIANCE_THRESHOLD_1024_COUNTS = 0x07, ///< New LS_DATA varies by ± 1024 counts compared to previous result. +} rm_ob1203_variance_threshold_t; + +/** Sleep after interrupt */ +typedef enum e_rm_ob1203_sleep_after_interrupt +{ + RM_OB1203_SLEEP_AFTER_INTERRUPT_DISABLE = 0x00, ///< Disable sleep after interrupt. + RM_OB1203_SLEEP_AFTER_INTERRUPT_ENABLE = 0x08, ///< Stop measurement after an interrupt occurs. After STATUS_0/STATUS_1 register is read, start measurement. +} rm_ob1203_sleep_after_interrupt_t; + +/** Moving average */ +typedef enum e_rm_ob1203_moving_average +{ + RM_OB1203_MOVING_AVERAGE_DISABLE = 0x00, ///< Moving average is disabled for Proximity mode + RM_OB1203_MOVING_AVERAGE_ENABLE = 0x80, ///< Moving average is enabled for Proximity mode. Proximity data is the average of the current and previous measurement. The moving average is applied after digital offset cancellation. +} rm_ob1203_moving_average_t; + +/** Power save mode */ +typedef enum e_rm_ob1203_power_save_mode +{ + RM_OB1203_POWER_SAVE_MODE_DISABLE = 0x00, ///< Power save mode is disabled for PPG mode. + RM_OB1203_POWER_SAVE_MODE_ENABLE = 0x40, ///< Power save mode is enabled for PPG mode. On power save mode, some analog circuitry powers down between individual PPG measurements if the idle time. +} rm_ob1203_power_save_mode_t; + +/** Analog cancellation */ +typedef enum e_rm_ob1203_analog_cancellation +{ + RM_OB1203_ANALOG_CANCELLATION_DISABLE = 0x00, ///< No offset cancellation + RM_OB1203_ANALOG_CANCELLATION_ENABLE = 0x01, ///< 50% offset of the full-scale value +} rm_ob1203_analog_cancellation_t; + +/** Number of LED pulses */ +typedef enum e_rm_rm_ob1203_number_led_pulses +{ + RM_OB1203_NUM_LED_PULSES_1 = 0x00, ///< 1 pulse. + RM_OB1203_NUM_LED_PULSES_2 = 0x08, ///< 2 pulses. + RM_OB1203_NUM_LED_PULSES_4 = 0x10, ///< 4 pulses. + RM_OB1203_NUM_LED_PULSES_8 = 0x18, ///< 8 pulses. + RM_OB1203_NUM_LED_PULSES_16 = 0x20, ///< 16 pulses. + RM_OB1203_NUM_LED_PULSES_32 = 0x28, ///< 32 pulses. +} rm_ob1203_number_led_pulses_t; + +/** Number of averaged samples */ +typedef enum e_rm_ob1203_number_averaged_samples +{ + RM_OB1203_NUM_AVERAGED_SAMPLES_1 = 0x00, ///< 1 (No averaging). + RM_OB1203_NUM_AVERAGED_SAMPLES_2 = 0x10, ///< 2 consecutives samples are averaged. + RM_OB1203_NUM_AVERAGED_SAMPLES_4 = 0x20, ///< 4 consecutives samples are averaged. + RM_OB1203_NUM_AVERAGED_SAMPLES_8 = 0x30, ///< 8 consecutives samples are averaged. + RM_OB1203_NUM_AVERAGED_SAMPLES_16 = 0x40, ///< 16 consecutives samples are averaged. + RM_OB1203_NUM_AVERAGED_SAMPLES_32 = 0x50, ///< 32 consecutives samples are averaged. +} rm_ob1203_number_averaged_samples_t; + +/** Light resolution and measurement period */ +typedef enum e_rm_ob1203_light_resolution_meas_period +{ + RM_OB1203_LIGHT_RESOLUTION_13BIT_PERIOD_25MS = 0x50, ///< Resolution : 13bit, measurement period : 25ms. + RM_OB1203_LIGHT_RESOLUTION_13BIT_PERIOD_50MS = 0x51, ///< Resolution : 13bit, measurement period : 50ms. + RM_OB1203_LIGHT_RESOLUTION_13BIT_PERIOD_100MS = 0x52, ///< Resolution : 13bit, measurement period : 100ms. + RM_OB1203_LIGHT_RESOLUTION_13BIT_PERIOD_200MS = 0x53, ///< Resolution : 13bit, measurement period : 200ms. + RM_OB1203_LIGHT_RESOLUTION_13BIT_PERIOD_500MS = 0x54, ///< Resolution : 13bit, measurement period : 500ms. + RM_OB1203_LIGHT_RESOLUTION_13BIT_PERIOD_1000MS = 0x55, ///< Resolution : 13bit, measurement period : 1000ms. + RM_OB1203_LIGHT_RESOLUTION_13BIT_PERIOD_2000MS = 0x56, ///< Resolution : 13bit, measurement period : 2000ms. + RM_OB1203_LIGHT_RESOLUTION_16BIT_PERIOD_25MS = 0x40, ///< Resolution : 16bit, measurement period : 25ms. + RM_OB1203_LIGHT_RESOLUTION_16BIT_PERIOD_50MS = 0x41, ///< Resolution : 16bit, measurement period : 50ms. + RM_OB1203_LIGHT_RESOLUTION_16BIT_PERIOD_100MS = 0x42, ///< Resolution : 16bit, measurement period : 100ms. + RM_OB1203_LIGHT_RESOLUTION_16BIT_PERIOD_200MS = 0x43, ///< Resolution : 16bit, measurement period : 200ms. + RM_OB1203_LIGHT_RESOLUTION_16BIT_PERIOD_500MS = 0x44, ///< Resolution : 16bit, measurement period : 500ms. + RM_OB1203_LIGHT_RESOLUTION_16BIT_PERIOD_1000MS = 0x45, ///< Resolution : 16bit, measurement period : 1000ms. + RM_OB1203_LIGHT_RESOLUTION_16BIT_PERIOD_2000MS = 0x46, ///< Resolution : 16bit, measurement period : 2000ms. + RM_OB1203_LIGHT_RESOLUTION_17BIT_PERIOD_50MS = 0x31, ///< Resolution : 17bit, measurement period : 50ms. + RM_OB1203_LIGHT_RESOLUTION_17BIT_PERIOD_100MS = 0x32, ///< Resolution : 17bit, measurement period : 100ms. + RM_OB1203_LIGHT_RESOLUTION_17BIT_PERIOD_200MS = 0x33, ///< Resolution : 17bit, measurement period : 200ms. + RM_OB1203_LIGHT_RESOLUTION_17BIT_PERIOD_500MS = 0x34, ///< Resolution : 17bit, measurement period : 500ms. + RM_OB1203_LIGHT_RESOLUTION_17BIT_PERIOD_1000MS = 0x35, ///< Resolution : 17bit, measurement period : 1000ms. + RM_OB1203_LIGHT_RESOLUTION_17BIT_PERIOD_2000MS = 0x36, ///< Resolution : 17bit, measurement period : 2000ms. + RM_OB1203_LIGHT_RESOLUTION_18BIT_PERIOD_100MS = 0x22, ///< Resolution : 18bit, measurement period : 100ms. + RM_OB1203_LIGHT_RESOLUTION_18BIT_PERIOD_200MS = 0x23, ///< Resolution : 18bit, measurement period : 200ms. + RM_OB1203_LIGHT_RESOLUTION_18BIT_PERIOD_500MS = 0x24, ///< Resolution : 18bit, measurement period : 500ms. + RM_OB1203_LIGHT_RESOLUTION_18BIT_PERIOD_1000MS = 0x25, ///< Resolution : 18bit, measurement period : 1000ms. + RM_OB1203_LIGHT_RESOLUTION_18BIT_PERIOD_2000MS = 0x26, ///< Resolution : 18bit, measurement period : 2000ms. + RM_OB1203_LIGHT_RESOLUTION_19BIT_PERIOD_200MS = 0x13, ///< Resolution : 19bit, measurement period : 200ms. + RM_OB1203_LIGHT_RESOLUTION_19BIT_PERIOD_500MS = 0x14, ///< Resolution : 19bit, measurement period : 500ms. + RM_OB1203_LIGHT_RESOLUTION_19BIT_PERIOD_1000MS = 0x15, ///< Resolution : 19bit, measurement period : 1000ms. + RM_OB1203_LIGHT_RESOLUTION_19BIT_PERIOD_2000MS = 0x16, ///< Resolution : 19bit, measurement period : 2000ms. + RM_OB1203_LIGHT_RESOLUTION_20BIT_PERIOD_500MS = 0x04, ///< Resolution : 20bit, measurement period : 500ms. + RM_OB1203_LIGHT_RESOLUTION_20BIT_PERIOD_1000MS = 0x05, ///< Resolution : 20bit, measurement period : 1000ms. + RM_OB1203_LIGHT_RESOLUTION_20BIT_PERIOD_2000MS = 0x06, ///< Resolution : 20bit, measurement period : 2000ms. +} rm_ob1203_light_resolution_meas_period_t; + +/** Proximity pulse width and measurement period */ +typedef enum e_rm_ob1203_prox_pulse_width_meas_period +{ + RM_OB1203_PROX_WIDTH_26US_PERIOD_3P125MS = 0x00, ///< Pulse width : 26us, measurement period : 3.125ms. Except for the number 32 of LED pulses. + RM_OB1203_PROX_WIDTH_26US_PERIOD_6P25MS = 0x01, ///< Pulse width : 26us, measurement period : 6.25ms. + RM_OB1203_PROX_WIDTH_26US_PERIOD_12P5MS = 0x02, ///< Pulse width : 26us, measurement period : 12.5ms. + RM_OB1203_PROX_WIDTH_26US_PERIOD_25MS = 0x03, ///< Pulse width : 26us, measurement period : 25ms. + RM_OB1203_PROX_WIDTH_26US_PERIOD_50MS = 0x04, ///< Pulse width : 26us, measurement period : 50ms. + RM_OB1203_PROX_WIDTH_26US_PERIOD_100MS = 0x05, ///< Pulse width : 26us, measurement period : 100ms. + RM_OB1203_PROX_WIDTH_26US_PERIOD_200MS = 0x06, ///< Pulse width : 26us, measurement period : 200ms. + RM_OB1203_PROX_WIDTH_26US_PERIOD_400MS = 0x07, ///< Pulse width : 26us, measurement period : 400ms. + RM_OB1203_PROX_WIDTH_42US_PERIOD_3P125MS = 0x10, ///< Pulse width : 42us, measurement period : 3.125ms. Except for the number 32 of LED pulses. + RM_OB1203_PROX_WIDTH_42US_PERIOD_6P25MS = 0x11, ///< Pulse width : 42us, measurement period : 6.25ms. + RM_OB1203_PROX_WIDTH_42US_PERIOD_12P5MS = 0x12, ///< Pulse width : 42us, measurement period : 12.5ms. + RM_OB1203_PROX_WIDTH_42US_PERIOD_25MS = 0x13, ///< Pulse width : 42us, measurement period : 25ms. + RM_OB1203_PROX_WIDTH_42US_PERIOD_50MS = 0x14, ///< Pulse width : 42us, measurement period : 50ms. + RM_OB1203_PROX_WIDTH_42US_PERIOD_100MS = 0x15, ///< Pulse width : 42us, measurement period : 100ms. + RM_OB1203_PROX_WIDTH_42US_PERIOD_200MS = 0x16, ///< Pulse width : 42us, measurement period : 200ms. + RM_OB1203_PROX_WIDTH_42US_PERIOD_400MS = 0x17, ///< Pulse width : 42us, measurement period : 400ms. + RM_OB1203_PROX_WIDTH_71US_PERIOD_3P125MS = 0x20, ///< Pulse width : 71us, measurement period : 3.125ms. Except for the number 16 and 32 of LED pulses. + RM_OB1203_PROX_WIDTH_71US_PERIOD_6P25MS = 0x21, ///< Pulse width : 71us, measurement period : 6.25ms. Except for the number 32 of LED pulses. + RM_OB1203_PROX_WIDTH_71US_PERIOD_12P5MS = 0x22, ///< Pulse width : 71us, measurement period : 12.5ms. + RM_OB1203_PROX_WIDTH_71US_PERIOD_25MS = 0x23, ///< Pulse width : 71us, measurement period : 25ms. + RM_OB1203_PROX_WIDTH_71US_PERIOD_50MS = 0x24, ///< Pulse width : 71us, measurement period : 50ms. + RM_OB1203_PROX_WIDTH_71US_PERIOD_100MS = 0x25, ///< Pulse width : 71us, measurement period : 100ms. + RM_OB1203_PROX_WIDTH_71US_PERIOD_200MS = 0x26, ///< Pulse width : 71us, measurement period : 200ms. + RM_OB1203_PROX_WIDTH_71US_PERIOD_400MS = 0x27, ///< Pulse width : 71us, measurement period : 400ms. +} rm_ob1203_prox_pulse_width_meas_period_t; + +/** PPG pulse width and measurement period */ +typedef enum e_rm_ob1203_ppg_pulse_width_meas_period +{ + RM_OB1203_PPG_WIDTH_130US_PERIOD_0P3125MS = 0x30, ///< Pulse width : 130us, measurement period : 0.3125ms. PPG1 mode only. + RM_OB1203_PPG_WIDTH_130US_PERIOD_0P625MS = 0x31, ///< Pulse width : 130us, measurement period : 0.625ms. + RM_OB1203_PPG_WIDTH_130US_PERIOD_1MS = 0x32, ///< Pulse width : 130us, measurement period : 1ms. + RM_OB1203_PPG_WIDTH_130US_PERIOD_1P25MS = 0x33, ///< Pulse width : 130us, measurement period : 1.25ms. + RM_OB1203_PPG_WIDTH_130US_PERIOD_2P5MS = 0x34, ///< Pulse width : 130us, measurement period : 2.5ms. + RM_OB1203_PPG_WIDTH_130US_PERIOD_5MS = 0x35, ///< Pulse width : 130us, measurement period : 5ms. + RM_OB1203_PPG_WIDTH_130US_PERIOD_10MS = 0x36, ///< Pulse width : 130us, measurement period : 10ms. + RM_OB1203_PPG_WIDTH_130US_PERIOD_20MS = 0x37, ///< Pulse width : 130us, measurement period : 20ms. + RM_OB1203_PPG_WIDTH_247US_PERIOD_0P625MS = 0x41, ///< Pulse width : 247us, measurement period : 0.625ms. PPG1 mode only. + RM_OB1203_PPG_WIDTH_247US_PERIOD_1MS = 0x42, ///< Pulse width : 247us, measurement period : 1ms. + RM_OB1203_PPG_WIDTH_247US_PERIOD_1P25MS = 0x43, ///< Pulse width : 247us, measurement period : 1.25ms. + RM_OB1203_PPG_WIDTH_247US_PERIOD_2P5MS = 0x44, ///< Pulse width : 247us, measurement period : 2.5ms. + RM_OB1203_PPG_WIDTH_247US_PERIOD_5MS = 0x45, ///< Pulse width : 247us, measurement period : 5ms. + RM_OB1203_PPG_WIDTH_247US_PERIOD_10MS = 0x46, ///< Pulse width : 247us, measurement period : 10ms. + RM_OB1203_PPG_WIDTH_247US_PERIOD_20MS = 0x47, ///< Pulse width : 247us, measurement period : 20ms. + RM_OB1203_PPG_WIDTH_481US_PERIOD_1MS = 0x52, ///< Pulse width : 481us, measurement period : 1ms. PPG1 mode only. + RM_OB1203_PPG_WIDTH_481US_PERIOD_1P25MS = 0x53, ///< Pulse width : 481us, measurement period : 1.25ms. PPG1 mode only. + RM_OB1203_PPG_WIDTH_481US_PERIOD_2P5MS = 0x54, ///< Pulse width : 481us, measurement period : 2.5ms. + RM_OB1203_PPG_WIDTH_481US_PERIOD_5MS = 0x55, ///< Pulse width : 481us, measurement period : 5ms. + RM_OB1203_PPG_WIDTH_481US_PERIOD_10MS = 0x56, ///< Pulse width : 481us, measurement period : 10ms. + RM_OB1203_PPG_WIDTH_481US_PERIOD_20MS = 0x57, ///< Pulse width : 481us, measurement period : 20ms. + RM_OB1203_PPG_WIDTH_949US_PERIOD_2P5MS = 0x64, ///< Pulse width : 949us, measurement period : 2.5ms. PPG1 mode only. + RM_OB1203_PPG_WIDTH_949US_PERIOD_5MS = 0x65, ///< Pulse width : 949us, measurement period : 5ms. + RM_OB1203_PPG_WIDTH_949US_PERIOD_10MS = 0x66, ///< Pulse width : 949us, measurement period : 10ms. + RM_OB1203_PPG_WIDTH_949US_PERIOD_20MS = 0x67, ///< Pulse width : 949us, measurement period : 20ms. +} rm_ob1203_ppg_pulse_width_meas_period_t; + +/** FIFO Rollover */ +typedef enum e_rm_ob1203_fifo_rollover +{ + RM_OB1203_FIFO_ROLLOVER_DISABLE = 0x00, ///< In the event of a full FIFO, no more samples of PPG data are written into the FIFO; the samples from new measurements are lost. + RM_OB1203_FIFO_ROLLOVER_ENABLE = 0x10, ///< New PPG data will always be written to the FIFO, and the FIFO Write Pointer is incremented (rollover). If the FIFO is full, old data will be overwritten. The FIFO Overflow Counter counts the number of lost (overwritten) and respectively the number of new samples. The FIFO Read Pointer remains unchanged. +} rm_ob1203_fifo_rollover_t; + +#if BSP_CFG_RTOS + +/* Semaphore Structure */ +typedef struct st_rm_ob1203_semaphore +{ + #if BSP_CFG_RTOS == 1 // ThreadX + TX_SEMAPHORE * p_semaphore_handle; + CHAR * p_semaphore_name; + #elif BSP_CFG_RTOS == 2 // FreeRTOS + SemaphoreHandle_t * p_semaphore_handle; + StaticSemaphore_t * p_semaphore_memory; + #else + #endif +} rm_ob1203_semaphore_t; +#endif + +/** OB1203 callback parameter definition */ +typedef struct st_rm_ob1203_callback_args +{ + void const * p_context; + rm_ob1203_event_t event; +} rm_ob1203_callback_args_t; + +/** OB1203 raw data structure */ +typedef struct st_rm_ob1203_raw_data +{ + uint8_t adc_data[96]; ///< Max of PPG data is 96 (3 bytes multiplied by 32 samples) +} rm_ob1203_raw_data_t; + +/** OB1203 light data structure */ +typedef struct st_rm_ob1203_light_data +{ + uint32_t clear_data; ///< Clear channel data (20bits). + uint32_t green_data; ///< Green channel data (20bits). + uint32_t blue_data; ///< Blue channel data (20bits). + uint32_t red_data; ///< Red channel data (20bits). + uint32_t comp_data; ///< Temperature compensation (Comp) channel data (20bits). +} rm_ob1203_light_data_t; + +/** OB1203 proximity data structure */ +typedef struct st_rm_ob1203_prox_data +{ + uint16_t proximity_data; ///< Proximity data. +} rm_ob1203_prox_data_t; + +/** OB1203 PPG data structure */ +typedef struct st_rm_ob1203_ppg_data +{ + uint32_t ppg_data[32]; ///< PPG data (18bits). +} rm_ob1203_ppg_data_t; + +/** OB1203 device interrupt configuration structure */ +typedef struct st_rm_ob1203_device_interrupt_cfg +{ + rm_ob1203_operation_mode_t light_prox_mode; ///< Light Proximity mode only. If Light mode uses IRQ, set RM_OB1203_OPERATION_MODE_LIGHT. If Proximity mode uses IRQ, set RM_OB1203_OPERATION_MODE_PROXIMITY. + rm_ob1203_light_interrupt_type_t light_type; ///< Light mode interrupt type. + rm_ob1203_light_interrupt_source_t light_source; ///< Light mode interrupt source. + rm_ob1203_prox_interrupt_type_t prox_type; ///< Proximity mode interrupt type. + uint8_t persist; ///< The number of similar consecutive Light mode or Proximity interrupt events that must occur before the interrupt is asserted (4bits). + rm_ob1203_ppg_interrupt_type_t ppg_type; ///< PPG mode interrupt type. +} rm_ob1203_device_interrupt_cfg_t; + +/** OB1203 device status */ +typedef struct st_rm_ob1203_device_status +{ + bool power_on_reset_occur; + bool light_interrupt_occur; + bool light_measurement_complete; + bool ts_measurement_complete; + bool fifo_afull_interrupt_occur; ///< FIFO almost full interrupt + bool ppg_measurement_complete; + bool object_near; + bool prox_interrupt_occur; + bool prox_measurement_complete; +} rm_ob1203_device_status_t; + +/** OB1203 Gain structure */ +typedef struct st_rm_ob1203_gain +{ + rm_ob1203_light_gain_t light; ///< Gain for Light mode + rm_ob1203_ppg_prox_gain_t ppg_prox; ///< Gain for PPG mode and Proximity mode +} rm_ob1203_gain_t; + +/** OB1203 LED currents structure */ +typedef struct st_rm_ob1203_led_current +{ + uint16_t ir_led; ///< IR LED current. + uint16_t red_led; ///< Red LED current. +} rm_ob1203_led_current_t; + +/** OB1203 FIFO information structure */ +typedef struct st_rm_ob1203_fifo_info +{ + uint8_t write_index; ///< The FIFO index where the next sample of PPG data will be written in the FIFO. + uint8_t read_index; ///< The index of the next sample to be read from the FIFO_DATA register. + uint8_t overflow_counter; ///< If the FIFO Rollover Enable bit is set, the FIFO overflow counter counts the number of old samples (up to 15) which are overwritten by new data. + uint8_t unread_samples; ///< The number of unread samples calculated from the write index and the read index. +} rm_ob1203_fifo_info_t; + +/** OB1203 Configuration */ +typedef struct st_rm_ob1203_cfg +{ +#if BSP_CFG_RTOS + rm_ob1203_semaphore_t const * p_semaphore; ///< The semaphore to wait for callback. This is used for another data read/write after a communication +#endif + uint32_t semaphore_timeout; ///< timeout for callback. + rm_comms_instance_t const * p_comms_instance; ///< Pointer to Communications Middleware instance. + void const * p_irq_instance; ///< Pointer to IRQ instance. + void const * p_context; ///< Pointer to the user-provided context. + void const * p_extend; ///< Pointer to extended configuration by instance of interface. + void (* p_comms_callback)(rm_ob1203_callback_args_t * p_args); ///< I2C Communications callback + void (* p_irq_callback)(rm_ob1203_callback_args_t * p_args); ///< IRQ callback +} rm_ob1203_cfg_t; + +/** OB1203 control block. Allocate an instance specific control block to pass into the OB1203 API calls. + * @par Implemented as + * - rm_ob1203_instance_ctrl_t + */ +typedef void rm_ob1203_ctrl_t; + +/** OB1203 APIs */ +typedef struct st_rm_ob1203_api +{ + /** Open sensor. + * @par Implemented as + * - @ref RM_OB1203_Open() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] p_cfg Pointer to configuration structure. + */ + fsp_err_t (* open)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_cfg_t const * const p_cfg); + + /** Start measurement. + * @par Implemented as + * - @ref RM_OB1203_MeasurementStart() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] mode Sensor mode. + */ + fsp_err_t (* measurementStart)(rm_ob1203_ctrl_t * const p_ctrl); + + /** Stop measurement. + * @par Implemented as + * - @ref RM_OB1203_MeasurementStop() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] mode Sensor mode. + */ + fsp_err_t (* measurementStop)(rm_ob1203_ctrl_t * const p_ctrl); + + /** Read Light ADC data from OB1203. + * @par Implemented as + * - @ref RM_OB1203_LightRead() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] p_raw_data Pointer to raw data structure. + * @param[in] type Light data type. + */ + fsp_err_t (* lightRead)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type); + + /** Calculate Light data from raw data. + * @par Implemented as + * - @ref RM_OB1203_LightDataCalculate() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] p_raw_data Pointer to raw data structure. + * @param[in] p_ob1203_data Pointer to OB1203 Light data structure. + */ + fsp_err_t (* lightDataCalculate)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data); + + /** Read Proximity ADC data from OB1203. + * @par Implemented as + * - @ref RM_OB1203_ProxRead() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] p_raw_data Pointer to raw data structure. + */ + fsp_err_t (* proxRead)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_raw_data_t * const p_raw_data); + + /** Calculate Proximity data from raw data. + * @par Implemented as + * - @ref RM_OB1203_ProxDataCalculate() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] p_raw_data Pointer to raw data structure. + * @param[in] p_ob1203_data Pointer to OB1203 Proximity data structure. + */ + fsp_err_t (* proxDataCalculate)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data); + + /** Read PPG ADC data from OB1203. + * @par Implemented as + * - @ref RM_OB1203_PpgRead() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] p_raw_data Pointer to raw data structure. + * @param[in] number_of_samples Number of PPG samples. One sample is 3 bytes. + */ + fsp_err_t (* ppgRead)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples); + + /** Calculate PPG data from raw data. + * @par Implemented as + * - @ref RM_OB1203_PpgDataCalculate() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] p_raw_data Pointer to raw data structure. + * @param[in] p_ob1203_data Pointer to OB1203 PPG data structure. + */ + fsp_err_t (* ppgDataCalculate)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data); + + /** Get device status. Read STATUS_0 and STATUS_1 registers. + * @par Implemented as + * - @ref RM_OB1203_DeviceStatusGet() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] p_status Pointer to device status. + */ + fsp_err_t (* deviceStatusGet)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_device_status_t * const p_status); + + /** Set device interrupt configuration. + * @par Implemented as + * - @ref RM_OB1203_DeviceInterruptCfgSet() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] interrupt_cfg Device interrupt configuration. + */ + fsp_err_t (* deviceInterruptCfgSet)(rm_ob1203_ctrl_t * const p_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg); + + /** Set gain. + * @par Implemented as + * - @ref RM_OB1203_GainSet() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] gain Gain configuration. + */ + fsp_err_t (* gainSet)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_gain_t const gain); + + /** Set LED current value. + * @par Implemented as + * - @ref RM_OB1203_LedCurrentSet() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] led_current Current value structure. + */ + fsp_err_t (* ledCurrentSet)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_led_current_t const led_current); + + /** Get FIFO information. + * @par Implemented as + * - @ref RM_OB1203_FifoInfoGet() + * + * @param[in] p_ctrl Pointer to control structure. + * @param[in] p_fifo_info Pointer to FIFO information (write index, read index and overflow counter). + */ + fsp_err_t (* fifoInfoGet)(rm_ob1203_ctrl_t * const p_ctrl, rm_ob1203_fifo_info_t * const p_fifo_info); + + /** Close OB1203. + * @par Implemented as + * - @ref RM_OB1203_Close() + * + * @param[in] p_ctrl Pointer to control structure. + */ + fsp_err_t (* close)(rm_ob1203_ctrl_t * const p_ctrl); +} rm_ob1203_api_t; + +/** OB1203 instance */ +typedef struct st_rm_ob1203_instance +{ + rm_ob1203_ctrl_t * p_ctrl; /**< Pointer to the control structure for this instance */ + rm_ob1203_cfg_t const * p_cfg; /**< Pointer to the configuration structure for this instance */ + rm_ob1203_api_t const * p_api; /**< Pointer to the API structure for this instance */ +} rm_ob1203_instance_t; + +/********************************************************************************************************************** + * Exported global variables + **********************************************************************************************************************/ + +/********************************************************************************************************************** + * Public Function Prototypes + **********************************************************************************************************************/ + +#if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) +#else + +/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_FOOTER +#endif + +#endif /* RM_OB1203_API_H_*/ + +/*******************************************************************************************************************//** + * @} (end addtogroup RM_OB1203_API) + **********************************************************************************************************************/ diff --git a/ra/fsp/inc/fsp_version.h b/ra/fsp/inc/fsp_version.h index a379e2abc..5cf759f12 100644 --- a/ra/fsp/inc/fsp_version.h +++ b/ra/fsp/inc/fsp_version.h @@ -45,7 +45,7 @@ extern "C" { #define FSP_VERSION_MAJOR (3U) /** FSP pack minor version. */ - #define FSP_VERSION_MINOR (6U) + #define FSP_VERSION_MINOR (7U) /** FSP pack patch version. */ #define FSP_VERSION_PATCH (0U) @@ -54,10 +54,10 @@ extern "C" { #define FSP_VERSION_BUILD (0U) /** Public FSP version name. */ - #define FSP_VERSION_STRING ("3.6.0") + #define FSP_VERSION_STRING ("3.7.0") /** Unique FSP version ID. */ - #define FSP_VERSION_BUILD_STRING ("Built with Renesas Advanced Flexible Software Package version 3.6.0") + #define FSP_VERSION_BUILD_STRING ("Built with Renesas Advanced Flexible Software Package version 3.7.0") /********************************************************************************************************************** * Typedef definitions diff --git a/ra/fsp/inc/instances/r_ether_phy.h b/ra/fsp/inc/instances/r_ether_phy.h index 08d7a4dd4..5d9de4061 100644 --- a/ra/fsp/inc/instances/r_ether_phy.h +++ b/ra/fsp/inc/instances/r_ether_phy.h @@ -44,6 +44,7 @@ FSP_HEADER #define ETHER_PHY_CFG_USE_PHY_KSZ8091RNB (1) #define ETHER_PHY_CFG_USE_PHY_KSZ8041 (2) #define ETHER_PHY_CFG_USE_PHY_DP83620 (3) +#define ETHER_PHY_CFG_USE_PHY_ICS1894 (4) /*********************************************************************************************************************** * Typedef definitions diff --git a/ra/fsp/inc/instances/r_gpt.h b/ra/fsp/inc/instances/r_gpt.h index 87220d32d..b45564305 100644 --- a/ra/fsp/inc/instances/r_gpt.h +++ b/ra/fsp/inc/instances/r_gpt.h @@ -46,13 +46,21 @@ FSP_HEADER /** Input/Output pins, used to select which duty cycle to update in R_GPT_DutyCycleSet(). */ typedef enum e_gpt_io_pin { - GPT_IO_PIN_GTIOCA = 0, ///< GTIOCA - GPT_IO_PIN_GTIOCB = 1, ///< GTIOCB - GPT_IO_PIN_GTIOCA_AND_GTIOCB = 2, ///< GTIOCA and GTIOCB - GPT_IO_PIN_TROUGH = 4, ///< Used in @ref R_GPT_DutyCycleSet when Triangle-wave PWM Mode 3 is selected. - GPT_IO_PIN_CREST = 8, ///< Used in @ref R_GPT_DutyCycleSet when Triangle-wave PWM Mode 3 is selected. + GPT_IO_PIN_GTIOCA = 0, ///< GTIOCA + GPT_IO_PIN_GTIOCB = 1, ///< GTIOCB + GPT_IO_PIN_GTIOCA_AND_GTIOCB = 2, ///< GTIOCA and GTIOCB + GPT_IO_PIN_TROUGH = 4, ///< Used in @ref R_GPT_DutyCycleSet when Triangle-wave PWM Mode 3 is selected. + GPT_IO_PIN_CREST = 8, ///< Used in @ref R_GPT_DutyCycleSet when Triangle-wave PWM Mode 3 is selected. + GPT_IO_PIN_ONE_SHOT_LEADING_EDGE = 4, ///< Used in @ref R_GPT_DutyCycleSet to set GTCCRC and GTCCRE registers when One-Shot Pulse mode is selected. + GPT_IO_PIN_ONE_SHOT_TRAILING_EDGE = 8, ///< Used in @ref R_GPT_DutyCycleSet to set GTCCRD and GTCCRF registers when One-Shot Pulse mode is selected. } gpt_io_pin_t; +/** Forced buffer push operation used in One-Sot Pulse mode with R_GPT_DutyCycleSet(). */ +typedef enum e_gpt_buffer_force_push +{ + GPT_BUFFER_FORCE_PUSH = 64, ///< Used in @ref R_GPT_DutyCycleSet to force push the data from GTCCRn registers to temporary buffer A or B when One-Shot Pulse mode is selected. +} gpt_buffer_force_push; + /** Level of GPT pin */ typedef enum e_gpt_pin_level { diff --git a/ra/fsp/inc/instances/r_i3c.h b/ra/fsp/inc/instances/r_i3c.h index a69627428..bcf9f881a 100644 --- a/ra/fsp/inc/instances/r_i3c.h +++ b/ra/fsp/inc/instances/r_i3c.h @@ -38,6 +38,11 @@ FSP_HEADER * Macro definitions **********************************************************************************************************************/ +/** There are two different versions of the RA2E2 MCU and the error recovery procedure is different for each version. */ +#define I3C_ERROR_RECOVERY_VERSION_1 (0U) ///< Support error recovery procedure for chip version 1. +#define I3C_ERROR_RECOVERY_VERSION_2 (1U) ///< Support error recovery procedure for chip version 2. +#define I3C_ERROR_RECOVERY_VERSION_BOTH (2U) ///< Support error recovery procedure for chip version 1 and version 2. + /** Index for selecting the device defined in the extended address table. */ #define I3C_DEVICE_INDEX_EXTENDED_DEVICE (1U << 5U) diff --git a/ra/fsp/inc/instances/r_rtc.h b/ra/fsp/inc/instances/r_rtc.h index 64a78183f..7222c8d48 100644 --- a/ra/fsp/inc/instances/r_rtc.h +++ b/ra/fsp/inc/instances/r_rtc.h @@ -75,6 +75,7 @@ extern const rtc_api_t g_rtc_on_rtc; **********************************************************************************************************************/ fsp_err_t R_RTC_Open(rtc_ctrl_t * const p_ctrl, rtc_cfg_t const * const p_cfg); fsp_err_t R_RTC_Close(rtc_ctrl_t * const p_ctrl); +fsp_err_t R_RTC_ClockSourceSet(rtc_ctrl_t * const p_ctrl); fsp_err_t R_RTC_CalendarTimeSet(rtc_ctrl_t * const p_ctrl, rtc_time_t * const p_time); fsp_err_t R_RTC_CalendarTimeGet(rtc_ctrl_t * const p_ctrl, rtc_time_t * const p_time); fsp_err_t R_RTC_CalendarAlarmSet(rtc_ctrl_t * const p_ctrl, rtc_alarm_time_t * const p_alarm); diff --git a/ra/fsp/inc/instances/rm_ble_mesh_provision.h b/ra/fsp/inc/instances/rm_ble_mesh_provision.h index 190c91b73..50538ef19 100644 --- a/ra/fsp/inc/instances/rm_ble_mesh_provision.h +++ b/ra/fsp/inc/instances/rm_ble_mesh_provision.h @@ -88,6 +88,14 @@ fsp_err_t RM_BLE_MESH_PROVISION_GetLocalPublicKey(rm_ble_mesh_provision_ctrl_t * uint8_t * const public_key); fsp_err_t RM_BLE_MESH_PROVISION_SetLocalPublicKey(rm_ble_mesh_provision_ctrl_t * const p_ctrl, uint8_t const * const public_key); +fsp_err_t RM_BLE_MESH_PROVISION_GenerateRandomizedNumber(rm_ble_mesh_provision_ctrl_t * const p_ctrl, + uint8_t * const p_key); +fsp_err_t RM_BLE_MESH_PROVISION_SetOobPublicKey(rm_ble_mesh_provision_ctrl_t * const p_ctrl, + uint8_t const * const p_key, + uint8_t size); +fsp_err_t RM_BLE_MESH_PROVISION_SetOobAuthInfo(rm_ble_mesh_provision_ctrl_t * const p_ctrl, + uint8_t const * const p_auth_info, + uint8_t size); /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ FSP_FOOTER diff --git a/ra/fsp/inc/instances/rm_cellular_comm_uart_aws.h b/ra/fsp/inc/instances/rm_cellular_comm_uart_aws.h index d503e6586..2865638a9 100644 --- a/ra/fsp/inc/instances/rm_cellular_comm_uart_aws.h +++ b/ra/fsp/inc/instances/rm_cellular_comm_uart_aws.h @@ -57,7 +57,9 @@ typedef struct st_rm_cellular_comm_uart_aws_instance_ctrl { uart_instance_t * p_lower_level_instance; ///< Lower level UART instance uint8_t * p_recv_buffer; ///< Receieve buffer to zero copy to - uint32_t recv_read_length; ///< Length to read to receive buffer + uint32_t remaining_recv_read_length; ///< Length left overall to read to receive buffer + uint32_t current_recv_read_length; ///< Length to read to receive buffer for current cluster of bytes + bool transfer_in_progress; ///< Indicates if transfer is in progress for recv uint8_t rx_buffer[RM_CELLULAR_COMM_UART_AWS_RX_BUFFER_SIZE]; ///< Receive Buffer uint32_t read_count; ///< Number of bytes read into rx_buffer so far StaticSemaphore_t tx_semaphore_buffer; ///< Transmit semaphore buffer diff --git a/ra/fsp/inc/instances/rm_comms_i2c.h b/ra/fsp/inc/instances/rm_comms_i2c.h index 375224f0d..8c30e2bf2 100644 --- a/ra/fsp/inc/instances/rm_comms_i2c.h +++ b/ra/fsp/inc/instances/rm_comms_i2c.h @@ -44,7 +44,7 @@ #else #define BSP_CFG_RTOS 0 #endif -#elif defined(__CCRL__) || defined(__ICCRL__) || defined(__RL78__) +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) #include "r_comms_i2c_rl_config.h" #else #include "r_i2c_master_api.h" @@ -149,7 +149,7 @@ fsp_err_t RM_COMMS_I2C_WriteRead(rm_comms_ctrl_t * const p_api_ctrl, #if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) void rm_comms_i2c_callback(rm_comms_ctrl_t const * p_api_ctrl); -#elif defined(__CCRL__) || defined(__ICCRL__) || defined(__RL78__) +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) void rm_comms_i2c_callback(rm_comms_ctrl_t const * p_api_ctrl, bool aborted); #else diff --git a/ra/fsp/inc/instances/rm_filex_levelx_nor.h b/ra/fsp/inc/instances/rm_filex_levelx_nor.h index 6c653a4d2..ae6bd6778 100644 --- a/ra/fsp/inc/instances/rm_filex_levelx_nor.h +++ b/ra/fsp/inc/instances/rm_filex_levelx_nor.h @@ -44,6 +44,18 @@ FSP_HEADER /********************************************************************************************************************** * Typedef definitions **********************************************************************************************************************/ +#ifndef VOID + #define VOID void +typedef char CHAR; +typedef char BOOL; +typedef unsigned char UCHAR; +typedef int INT; +typedef unsigned int UINT; +typedef long LONG; +typedef unsigned long ULONG; +typedef short SHORT; +typedef unsigned short USHORT; +#endif /** Options for the callback events. */ typedef enum e_rm_filex_levelx_nor_event @@ -78,8 +90,8 @@ typedef struct /** This structure encompasses everything that is needed to use an instance of this interface. */ typedef struct st_rm_filex_levelx_nor_instance { - rm_filex_levelx_nor_instance_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance - rm_filex_levelx_nor_cfg_t * const p_cfg; ///< Pointer to the configuration structure for this instance + rm_filex_levelx_nor_instance_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance + rm_filex_levelx_nor_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance } rm_filex_levelx_nor_instance_t; /********************************************************************************************************************** diff --git a/ra/fsp/inc/instances/rm_hs300x.h b/ra/fsp/inc/instances/rm_hs300x.h index 1c2580356..91fbe8fc8 100644 --- a/ra/fsp/inc/instances/rm_hs300x.h +++ b/ra/fsp/inc/instances/rm_hs300x.h @@ -67,6 +67,7 @@ typedef struct rm_hs300x_instance_ctrl rm_comms_instance_t const * p_comms_i2c_instance; ///< Pointer of I2C Communications Middleware instance structure void const * p_context; ///< Pointer to the user-provided context rm_hs300x_programmnig_mode_params_t programming_mode; ///< Programming mode flag + uint8_t buf[3]; ///< Buffer for I2C communications /* Pointer to callback and optional working memory */ void (* p_callback)(rm_hs300x_callback_args_t * p_args); diff --git a/ra/fsp/inc/instances/rm_mesh_bearer_platform.h b/ra/fsp/inc/instances/rm_mesh_bearer_platform.h index 4df2c7451..72297f312 100644 --- a/ra/fsp/inc/instances/rm_mesh_bearer_platform.h +++ b/ra/fsp/inc/instances/rm_mesh_bearer_platform.h @@ -40,9 +40,43 @@ FSP_HEADER * Macro definitions **********************************************************************************************************************/ +/** GATT Interface Events */ +typedef enum e_rm_mesh_bearer_platform_interface_event +{ + /** The event GATT Bearer BLE Link Layer connected */ + RM_MESH_BEARER_PLATFORM_INTERFACE_EVENT_UP = 0x00, + + /** The event GATT Bearer BLE Link Layer disconnected */ + RM_MESH_BEARER_PLATFORM_INTERFACE_EVENT_DOWN = 0x01, + + /** The event GATT Bearer service enabled for communication */ + RM_MESH_BEARER_PLATFORM_INTERFACE_EVENT_ENABLE = 0x02, + + /** The event GATT Bearer service disabled for communication */ + RM_MESH_BEARER_PLATFORM_INTERFACE_EVENT_DISABLE = 0x03, + + /** The event discovery process is not completed */ + RM_MESH_BEARER_PLATFORM_INTERFACE_EVENT_NOT_FOUND = 0x04, + + /** The event that connectable device having Mesh GATT Service is found*/ + RM_MESH_BEARER_PLATFORM_INTERFACE_EVENT_SCAN = 0x05, + + /** The Event GATT/BLE link layer connection creation is canceled */ + RM_MESH_BEARER_PLATFORM_INTERFACE_EVENT_CANCEL = 0x06, +} rm_mesh_bearer_platform_interface_event_t; + /*********************************************************************************************************************** * Typedef definitions **********************************************************************************************************************/ + +/** + * @brief Callback function for GATT interface event. + * + * @param event_name The event defined by @ref rm_mesh_bearer_platform_interface_event_t + * @param event_param The mode of GATT connection @ref rm_mesh_bearer_platform_gatt_mode_t + * @param conn_hdl The connection handle + * @param peer_addr Pointer to the connected device address + */ typedef void (* rm_mesh_bearer_platform_gatt_iface_cb_t)(uint8_t event_name, uint8_t event_param, uint16_t conn_hdl, st_ble_dev_addr_t * peer_addr); diff --git a/ra/fsp/inc/instances/rm_mesh_light_ctl_srv.h b/ra/fsp/inc/instances/rm_mesh_light_ctl_srv.h index 224f4b1fd..e6437433d 100644 --- a/ra/fsp/inc/instances/rm_mesh_light_ctl_srv.h +++ b/ra/fsp/inc/instances/rm_mesh_light_ctl_srv.h @@ -145,6 +145,12 @@ typedef struct st_rm_mesh_light_ctl_srv_temperature_range_info uint8_t status; } rm_mesh_light_ctl_srv_temperature_range_info_t; +/** BLE mesh light ctl extension for BLE mesh light ctl. */ +typedef struct st_rm_mesh_light_ctl_srv_extended_cfg +{ + rm_ble_mesh_access_instance_t const * p_temperature_access_instance; ///< Pointer to access instance for temperature model. +} rm_mesh_light_ctl_srv_extended_cfg_t; + /** BLE mesh light ctl instance control block. DO NOT INITIALIZE. Initialization occurs when RM_MESH_LIGHT_CTL_SRV_Open() is called. */ typedef struct st_rm_mesh_light_ctl_srv_instance_ctrl { diff --git a/ra/fsp/inc/instances/rm_mesh_light_hsl_srv.h b/ra/fsp/inc/instances/rm_mesh_light_hsl_srv.h index 7863cde2d..35eba506c 100644 --- a/ra/fsp/inc/instances/rm_mesh_light_hsl_srv.h +++ b/ra/fsp/inc/instances/rm_mesh_light_hsl_srv.h @@ -159,6 +159,13 @@ typedef struct st_rm_mesh_light_hsl_srv_range_info uint8_t status; } rm_mesh_light_hsl_srv_range_info_t; +/** BLE mesh light hsl extension for BLE mesh light hsl. */ +typedef struct st_rm_mesh_light_hsl_srv_extended_cfg +{ + rm_ble_mesh_access_instance_t const * p_hue_access_instance; ///< Pointer to access instance for hue model. + rm_ble_mesh_access_instance_t const * p_saturation_access_instance; ///< Pointer to access instance for saturation model. +} rm_mesh_light_hsl_srv_extended_cfg_t; + /** BLE mesh light hsl instance control block. DO NOT INITIALIZE. Initialization occurs when RM_MESH_LIGHT_HSL_SRV_Open() is called. */ typedef struct st_rm_mesh_light_hsl_srv_instance_ctrl { diff --git a/ra/fsp/inc/instances/rm_ob1203.h b/ra/fsp/inc/instances/rm_ob1203.h new file mode 100644 index 000000000..8fd47e555 --- /dev/null +++ b/ra/fsp/inc/instances/rm_ob1203.h @@ -0,0 +1,188 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @addtogroup RM_OB1203 + * @{ + **********************************************************************************************************************/ + +#ifndef RM_OB1203_H +#define RM_OB1203_H + +/*********************************************************************************************************************** + * Includes + **********************************************************************************************************************/ +#include "rm_ob1203_api.h" +#if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) + #include "r_ob1203_rx_config.h" +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) + #include "r_ob1203_rl_config.h" +#else + #include "rm_ob1203_cfg.h" + +/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_HEADER +#endif + +/********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/** OB1203 initialization process block */ +typedef struct st_rm_ob1203_init_process_params +{ + volatile bool communication_finished; ///< Communication flag for blocking. + volatile rm_ob1203_event_t event; ///< Callback event +} rm_ob1203_init_process_params_t; + +/** OB1203 mode extended configuration */ +typedef struct st_rm_ob1203_mode_extended_cfg +{ + // Common + rm_ob1203_api_t const * p_api; ///< Pointer to APIs. + rm_ob1203_operation_mode_t mode_irq; ///< Operation mode using IRQ + rm_ob1203_ppg_prox_gain_t ppg_prox_gain; ///< Proximity gain range + rm_ob1203_led_order_t led_order; ///< LED order + + // Light mode + rm_ob1203_light_sensor_mode_t light_sensor_mode; ///< LS or CS sensor mode + rm_ob1203_light_interrupt_type_t light_interrupt_type; ///< Light mode interrupt type. + rm_ob1203_light_interrupt_source_t light_interrupt_source; ///< Light mode interrupt source. + uint8_t light_interrupt_persist; ///< The number of similar consecutive Light mode interrupt events that must occur before the interrupt is asserted (4bits). + rm_ob1203_sleep_after_interrupt_t light_sleep; ///< Sleep after an interrupt. + rm_ob1203_light_gain_t light_gain; ///< Light gain range + uint32_t light_upper_threshold; ///< Upper threshold for interrupt + uint32_t light_lower_threshold; ///< Lower threshold for interrupt + rm_ob1203_variance_threshold_t light_variance_threshold; ///< variance threshold for interrupt. + rm_ob1203_light_resolution_meas_period_t light_resolution_period; ///< Resolution and measurement period. + rm_ob1203_light_data_type_t light_data_type; ///< Light data type. + + // Proximity mode + rm_ob1203_sleep_after_interrupt_t prox_sleep; ///< Sleep after an interrupt. + rm_ob1203_prox_interrupt_type_t prox_interrupt_type; ///< Proximity mode interrupt type. + uint8_t prox_interrupt_persist; ///< The number of similar consecutive Proximity mode interrupt events that must occur before the interrupt is asserted (4bits). + uint16_t prox_led_current; ///< Proximity LED current. + rm_ob1203_analog_cancellation_t prox_ana_can; ///< Analog cancellation. + uint16_t prox_dig_can; ///< Digital cancellation. + rm_ob1203_number_led_pulses_t prox_num_led_pulses; ///< Number of LED pulses. + uint16_t prox_upper_threshold; ///< Upper threshold for interrupt + uint16_t prox_lower_threshold; ///< Lower threshold for interrupt + rm_ob1203_prox_pulse_width_meas_period_t prox_width_period; ///< Proximity pulse width and measurement period. + rm_ob1203_moving_average_t prox_moving_average; ///< Moving average. + uint8_t prox_hysteresis; ///< Proximity hysteresis threshold (7bits). + + // PPG mode + rm_ob1203_ppg_sensor_mode_t ppg_sensor_mode; ///< PPG1 or PPG2 sensor mode + rm_ob1203_ppg_interrupt_type_t ppg_interrupt_type; ///< PPG mode interrupt type. + uint16_t ppg_ir_led_current; ///< PPG IR LED current. + uint16_t ppg_red_led_current; ///< PPG Red LED current. + rm_ob1203_power_save_mode_t ppg_power_save_mode; ///< PPG power save mode + rm_ob1203_analog_cancellation_t ppg_ir_led_ana_can; ///< IR LED analog cancellations + rm_ob1203_analog_cancellation_t ppg_red_led_ana_can; ///< Red LED analog cancellations + rm_ob1203_number_averaged_samples_t ppg_num_averaged_samples; ///< Number of averaged PPG samples. + rm_ob1203_ppg_pulse_width_meas_period_t ppg_width_period; ///< PPG pulse width and measurement period. + rm_ob1203_fifo_rollover_t ppg_fifo_rollover; ///< FIFO rollover enable. + uint8_t ppg_fifo_empty_num; ///< the number of empty FIFO words when the FIFO almost full interrupt is issued. In PPG2 Mode only even values should be used. (4 bits) + uint8_t ppg_number_of_samples; ///< Number of PPG samples +} rm_ob1203_mode_extended_cfg_t; + +/** OB1203 Control Block */ +typedef struct rm_ob1203_instance_ctrl +{ +#if BSP_CFG_RTOS + rm_ob1203_semaphore_t const * p_semaphore; ///< The semaphore to wait for callback. This is used for another data read/write after a communication +#endif + uint32_t open; ///< Open flag + rm_ob1203_cfg_t const * p_cfg; ///< Pointer to OB1203 Configuration + uint8_t buf[8]; ///< Buffer for I2C communications + rm_ob1203_init_process_params_t init_process_params; ///< For the initialization process. + uint8_t register_address; ///< Register address to access + volatile rm_ob1203_device_status_t * p_device_status; ///< Pointer to device status. + volatile rm_ob1203_fifo_info_t * p_fifo_info; ///< Pointer to FIFO information structure. + volatile bool fifo_reset; ///< Flag for FIFO reset for PPG mode + volatile bool prox_gain_update; ///< Flag for gain update for Proximity mode + volatile bool interrupt_bits_clear; ///< Flag for clearing interrupt bits. + rm_comms_instance_t const * p_comms_i2c_instance; ///< Pointer of I2C Communications Middleware instance structure + rm_ob1203_mode_extended_cfg_t * p_mode; ///< Pointer of OB1203 operation mode extended configuration + void const * p_irq_instance; ///< Pointer to IRQ instance. + void const * p_context; ///< Pointer to the user-provided context + + /* Pointer to callback and optional working memory */ + void (* p_comms_callback)(rm_ob1203_callback_args_t * p_args); ///< I2C Communications callback + void (* p_irq_callback)(rm_ob1203_callback_args_t * p_args); ///< IRQ callback +} rm_ob1203_instance_ctrl_t; + +/********************************************************************************************************************** + * Exported global variables + **********************************************************************************************************************/ + +/** @cond INC_HEADER_DEFS_SEC */ +/** Filled in Interface API structure for this Instance. */ +extern rm_ob1203_api_t const g_ob1203_on_ob1203; + +/** @endcond */ + +/********************************************************************************************************************** + * Public Function Prototypes + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_Open(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_cfg_t const * const p_cfg); +fsp_err_t RM_OB1203_Close(rm_ob1203_ctrl_t * const p_api_ctrl); +fsp_err_t RM_OB1203_MeasurementStart(rm_ob1203_ctrl_t * const p_api_ctrl); +fsp_err_t RM_OB1203_MeasurementStop(rm_ob1203_ctrl_t * const p_api_ctrl); +fsp_err_t RM_OB1203_LightRead(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type); +fsp_err_t RM_OB1203_LightDataCalculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data); +fsp_err_t RM_OB1203_ProxRead(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_raw_data_t * const p_raw_data); +fsp_err_t RM_OB1203_ProxDataCalculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data); +fsp_err_t RM_OB1203_PpgRead(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples); +fsp_err_t RM_OB1203_PpgDataCalculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data); +fsp_err_t RM_OB1203_GainSet(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_gain_t const gain); +fsp_err_t RM_OB1203_LedCurrentSet(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_led_current_t const led_current); +fsp_err_t RM_OB1203_DeviceInterruptCfgSet(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg); +fsp_err_t RM_OB1203_FifoInfoGet(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_fifo_info_t * const p_fifo_info); +fsp_err_t RM_OB1203_DeviceStatusGet(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_device_status_t * const p_status); + +#if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) +#else + +/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ +FSP_FOOTER +#endif + +#endif /* RM_OB1203_H_*/ + +/*******************************************************************************************************************//** + * @} (end addtogroup RM_OB1203) + **********************************************************************************************************************/ diff --git a/ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/renesas.h b/ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/renesas.h index 42fc757c9..9b793eacf 100644 --- a/ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/renesas.h +++ b/ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/renesas.h @@ -14024,8 +14024,14 @@ typedef struct /*!< (@ 0x40078000) R_GPT0 Structure __IOM uint32_t CSELCF : 1; /*!< [21..21] ELC_GPTA Event Source Counter Clear Enable */ __IOM uint32_t CSELCG : 1; /*!< [22..22] ELC_GPTA Event Source Counter Clear Enable */ __IOM uint32_t CSELCH : 1; /*!< [23..23] ELC_GPTA Event Source Counter Clear Enable */ - uint32_t : 7; - __IOM uint32_t CCLR : 1; /*!< [31..31] Software Source Counter Clear Enable */ + __IOM uint32_t CSCMSC : 3; /*!< [26..24] Compare Match/Input Capture/Synchronous counter clearing + * Source Counter Clear Enable. */ + __IOM uint32_t CP1CCE : 1; /*!< [27..27] Complementary PWM mode1 Crest Source Counter Clear + * Enable (This bit is only available in GPT324 to GPT329. + * In GPT320 to GPT323, this bit is read as 0. The write value + * should be 0.) */ + uint32_t : 3; + __IOM uint32_t CCLR : 1; /*!< [31..31] Software Source Counter Clear Enable */ } GTCSR_b; }; @@ -14254,12 +14260,19 @@ typedef struct /*!< (@ 0x40078000) R_GPT0 Structure struct { __IOM uint32_t GTIOA : 5; /*!< [4..0] GTIOCA Pin Function Select */ - uint32_t : 1; + __IOM uint32_t CPSCIR : 1; /*!< [5..5] Complementary PWM Mode Initial Output at Synchronous + * Clear Disable.(This bit is only available in GPT324 to + * GPT329. In GPT320 to GPT323, this bit is read as 0. The + * write value should be 0.) */ __IOM uint32_t OADFLT : 1; /*!< [6..6] GTIOCA Pin Output Value Setting at the Count Stop */ __IOM uint32_t OAHLD : 1; /*!< [7..7] GTIOCA Pin Output Setting at the Start/Stop Count */ __IOM uint32_t OAE : 1; /*!< [8..8] GTIOCA Pin Output Enable */ __IOM uint32_t OADF : 2; /*!< [10..9] GTIOCA Pin Disable Value Setting */ - uint32_t : 2; + __IOM uint32_t OAEOCD : 1; /*!< [11..11] GTCCRA Compare Match Cycle End Output Invalidate.(This + * bit is only available in GPT324 to GPT329. In GPT320 to + * GPT323, this bit is read as 0. The write value should be + * 0.) */ + __IOM uint32_t PSYE : 1; /*!< [12..12] PWM Synchronous output Enable */ __IOM uint32_t NFAEN : 1; /*!< [13..13] Noise Filter A Enable */ __IOM uint32_t NFCSA : 2; /*!< [15..14] Noise Filter A Sampling Clock Select */ __IOM uint32_t GTIOB : 5; /*!< [20..16] GTIOCB Pin Function Select */ @@ -14268,9 +14281,13 @@ typedef struct /*!< (@ 0x40078000) R_GPT0 Structure __IOM uint32_t OBHLD : 1; /*!< [23..23] GTIOCB Pin Output Setting at the Start/Stop Count */ __IOM uint32_t OBE : 1; /*!< [24..24] GTIOCB Pin Output Enable */ __IOM uint32_t OBDF : 2; /*!< [26..25] GTIOCB Pin Disable Value Setting */ - uint32_t : 2; - __IOM uint32_t NFBEN : 1; /*!< [29..29] Noise Filter B Enable */ - __IOM uint32_t NFCSB : 2; /*!< [31..30] Noise Filter B Sampling Clock Select */ + __IOM uint32_t OBEOCD : 1; /*!< [27..27] GTCCRB Compare Match Cycle End Output Invalidate.(This + * bit is only available in GPT324 to GPT329. In GPT320 to + * GPT323, this bit is read as 0. The write value should be + * 0.) */ + uint32_t : 1; + __IOM uint32_t NFBEN : 1; /*!< [29..29] Noise Filter B Enable */ + __IOM uint32_t NFCSB : 2; /*!< [31..30] Noise Filter B Sampling Clock Select */ } GTIOR_b; }; @@ -38657,6 +38674,10 @@ typedef struct /*!< (@ 0x90003000) R_TFU Structure /* ========================================================= GTCSR ========================================================= */ #define R_GPT0_GTCSR_CCLR_Pos (31UL) /*!< CCLR (Bit 31) */ #define R_GPT0_GTCSR_CCLR_Msk (0x80000000UL) /*!< CCLR (Bitfield-Mask: 0x01) */ + #define R_GPT0_GTCSR_CP1CCE_Pos (27UL) /*!< CP1CCE (Bit 27) */ + #define R_GPT0_GTCSR_CP1CCE_Msk (0x8000000UL) /*!< CP1CCE (Bitfield-Mask: 0x01) */ + #define R_GPT0_GTCSR_CSCMSC_Pos (24UL) /*!< CSCMSC (Bit 24) */ + #define R_GPT0_GTCSR_CSCMSC_Msk (0x7000000UL) /*!< CSCMSC (Bitfield-Mask: 0x07) */ #define R_GPT0_GTCSR_CSELC_Pos (16UL) /*!< CSELC (Bit 16) */ #define R_GPT0_GTCSR_CSELC_Msk (0x10000UL) /*!< CSELC (Bitfield-Mask: 0x01) */ #define R_GPT0_GTCSR_CSCBFAH_Pos (15UL) /*!< CSCBFAH (Bit 15) */ @@ -38804,6 +38825,8 @@ typedef struct /*!< (@ 0x90003000) R_TFU Structure #define R_GPT0_GTIOR_NFCSB_Msk (0xc0000000UL) /*!< NFCSB (Bitfield-Mask: 0x03) */ #define R_GPT0_GTIOR_NFBEN_Pos (29UL) /*!< NFBEN (Bit 29) */ #define R_GPT0_GTIOR_NFBEN_Msk (0x20000000UL) /*!< NFBEN (Bitfield-Mask: 0x01) */ + #define R_GPT0_GTIOR_OBEOCD_Pos (27UL) /*!< OBEOCD (Bit 27) */ + #define R_GPT0_GTIOR_OBEOCD_Msk (0x8000000UL) /*!< OBEOCD (Bitfield-Mask: 0x01) */ #define R_GPT0_GTIOR_OBDF_Pos (25UL) /*!< OBDF (Bit 25) */ #define R_GPT0_GTIOR_OBDF_Msk (0x6000000UL) /*!< OBDF (Bitfield-Mask: 0x03) */ #define R_GPT0_GTIOR_OBE_Pos (24UL) /*!< OBE (Bit 24) */ @@ -38818,6 +38841,10 @@ typedef struct /*!< (@ 0x90003000) R_TFU Structure #define R_GPT0_GTIOR_NFCSA_Msk (0xc000UL) /*!< NFCSA (Bitfield-Mask: 0x03) */ #define R_GPT0_GTIOR_NFAEN_Pos (13UL) /*!< NFAEN (Bit 13) */ #define R_GPT0_GTIOR_NFAEN_Msk (0x2000UL) /*!< NFAEN (Bitfield-Mask: 0x01) */ + #define R_GPT0_GTIOR_PSYE_Pos (12UL) /*!< PSYE (Bit 12) */ + #define R_GPT0_GTIOR_PSYE_Msk (0x1000UL) /*!< PSYE (Bitfield-Mask: 0x01) */ + #define R_GPT0_GTIOR_OAEOCD_Pos (11UL) /*!< OAEOCD (Bit 11) */ + #define R_GPT0_GTIOR_OAEOCD_Msk (0x800UL) /*!< OAEOCD (Bitfield-Mask: 0x01) */ #define R_GPT0_GTIOR_OADF_Pos (9UL) /*!< OADF (Bit 9) */ #define R_GPT0_GTIOR_OADF_Msk (0x600UL) /*!< OADF (Bitfield-Mask: 0x03) */ #define R_GPT0_GTIOR_OAE_Pos (8UL) /*!< OAE (Bit 8) */ @@ -38826,6 +38853,8 @@ typedef struct /*!< (@ 0x90003000) R_TFU Structure #define R_GPT0_GTIOR_OAHLD_Msk (0x80UL) /*!< OAHLD (Bitfield-Mask: 0x01) */ #define R_GPT0_GTIOR_OADFLT_Pos (6UL) /*!< OADFLT (Bit 6) */ #define R_GPT0_GTIOR_OADFLT_Msk (0x40UL) /*!< OADFLT (Bitfield-Mask: 0x01) */ + #define R_GPT0_GTIOR_CPSCIR_Pos (5UL) /*!< CPSCIR (Bit 5) */ + #define R_GPT0_GTIOR_CPSCIR_Msk (0x20UL) /*!< CPSCIR (Bitfield-Mask: 0x01) */ #define R_GPT0_GTIOR_GTIOA_Pos (0UL) /*!< GTIOA (Bit 0) */ #define R_GPT0_GTIOR_GTIOA_Msk (0x1fUL) /*!< GTIOA (Bitfield-Mask: 0x1f) */ /* ======================================================== GTINTAD ======================================================== */ diff --git a/ra/fsp/src/bsp/mcu/all/bsp_clocks.c b/ra/fsp/src/bsp/mcu/all/bsp_clocks.c index d89ae2f8e..ba6abf386 100644 --- a/ra/fsp/src/bsp/mcu/all/bsp_clocks.c +++ b/ra/fsp/src/bsp/mcu/all/bsp_clocks.c @@ -369,6 +369,20 @@ static uint8_t bsp_clock_set_prechange(uint32_t requested_freq_hz); static void bsp_clock_set_postchange(uint32_t updated_freq_hz, uint8_t new_rom_wait_state); +#if BSP_CLOCK_CFG_SUBCLOCK_POPULATED + #if defined(__ICCARM__) + +void R_BSP_SubClockStabilizeWait(uint32_t delay_ms); + + #pragma weak R_BSP_SubClockStabilizeWait + + #elif defined(__GNUC__) || defined(__ARMCC_VERSION) + +void R_BSP_SubClockStabilizeWait(uint32_t delay_ms) __attribute__((weak)); + + #endif +#endif + #if !BSP_CFG_USE_LOW_VOLTAGE_MODE static void bsp_prv_operating_mode_opccr_set(uint8_t operating_mode); @@ -976,7 +990,7 @@ void bsp_clock_init (void) #if (BSP_CLOCKS_SOURCE_CLOCK_SUBCLOCK == BSP_CFG_CLOCK_SOURCE) || (BSP_PRV_HOCO_USE_FLL) /* If the subclock is the system clock source OR if FLL is used, wait for stabilization. */ - R_BSP_SoftwareDelay(BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS, BSP_DELAY_UNITS_MILLISECONDS); + R_BSP_SubClockStabilizeWait(BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS); #endif #else R_SYSTEM->SOSCCR = 1U; @@ -1373,6 +1387,25 @@ void bsp_clock_init (void) #endif } +#if BSP_CLOCK_CFG_SUBCLOCK_POPULATED + +/*******************************************************************************************************************//** + * This function is called during SOSC stabilization when Sub-Clock oscillator is populated. + * This function is declared as a weak symbol higher up in this file because it is meant to be overridden by a user + * implemented version. One of the main uses for this function is to update the IWDT/WDT Refresh Register if an + * application starts IWDT/WDT automatically after reset. To use this function just copy this function into your own + * code and modify it to meet your needs. + * + * @param[in] delay_ms Stabilization Time for the clock. + **********************************************************************************************************************/ +void R_BSP_SubClockStabilizeWait (uint32_t delay_ms) +{ + /* Wait for clock to stabilize. */ + R_BSP_SoftwareDelay(delay_ms, BSP_DELAY_UNITS_MILLISECONDS); +} + +#endif + /*******************************************************************************************************************//** * Increases the ROM and RAM wait state settings to the minimum required based on the requested clock change. * diff --git a/ra/fsp/src/bsp/mcu/all/bsp_common.h b/ra/fsp/src/bsp/mcu/all/bsp_common.h index 854fb425a..0deb9c406 100644 --- a/ra/fsp/src/bsp/mcu/all/bsp_common.h +++ b/ra/fsp/src/bsp/mcu/all/bsp_common.h @@ -305,7 +305,7 @@ __STATIC_INLINE uint32_t R_FSP_SciSpiClockHzGet (void) * * @return A pointer to the unique identifier structure **********************************************************************************************************************/ -__STATIC_INLINE bsp_unique_id_t const * R_BSP_UniqueIdGet () +__STATIC_INLINE bsp_unique_id_t const * R_BSP_UniqueIdGet (void) { return (bsp_unique_id_t *) BSP_FEATURE_BSP_UNIQUE_ID_POINTER; } @@ -313,7 +313,7 @@ __STATIC_INLINE bsp_unique_id_t const * R_BSP_UniqueIdGet () /*******************************************************************************************************************//** * Disables the flash cache. **********************************************************************************************************************/ -__STATIC_INLINE void R_BSP_FlashCacheDisable () +__STATIC_INLINE void R_BSP_FlashCacheDisable (void) { #if BSP_FEATURE_BSP_FLASH_CACHE R_FCACHE->FCACHEE = 0U; @@ -329,7 +329,7 @@ __STATIC_INLINE void R_BSP_FlashCacheDisable () /*******************************************************************************************************************//** * Enables the flash cache. **********************************************************************************************************************/ -__STATIC_INLINE void R_BSP_FlashCacheEnable () +__STATIC_INLINE void R_BSP_FlashCacheEnable (void) { #if BSP_FEATURE_BSP_FLASH_CACHE diff --git a/ra/fsp/src/bsp/mcu/ra2a1/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra2a1/bsp_feature.h index a6317ebe1..3e0318a4f 100644 --- a/ra/fsp/src/bsp/mcu/ra2a1/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra2a1/bsp_feature.h @@ -130,6 +130,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -258,6 +259,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x0006U) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0) // Feature not available on this MCU #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0) // Feature not available on this MCU @@ -298,6 +301,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x0U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (BSP_FEATURE_SCI_CHANNELS) #define BSP_FEATURE_SCI_CHANNELS (0x203U) diff --git a/ra/fsp/src/bsp/mcu/ra2e1/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra2e1/bsp_feature.h index db39ce5c2..ddf3d935a 100644 --- a/ra/fsp/src/bsp/mcu/ra2e1/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra2e1/bsp_feature.h @@ -129,6 +129,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) #define BSP_FEATURE_CGC_HAS_FCLK (0U) @@ -257,6 +258,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x0006U) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0) // Feature not available on this MCU #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0) // Feature not available on this MCU @@ -297,6 +300,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x0U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (1U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (BSP_FEATURE_SCI_CHANNELS) #define BSP_FEATURE_SCI_CHANNELS (0x207U) diff --git a/ra/fsp/src/bsp/mcu/ra2e2/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra2e2/bsp_feature.h index 0b6f5d4bf..9b963448a 100644 --- a/ra/fsp/src/bsp/mcu/ra2e2/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra2e2/bsp_feature.h @@ -129,6 +129,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) #define BSP_FEATURE_CGC_HAS_FCLK (0U) @@ -257,6 +258,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x0006U) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0) // Feature not available on this MCU #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0) // Feature not available on this MCU @@ -297,6 +300,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x0U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (BSP_FEATURE_SCI_CHANNELS) #define BSP_FEATURE_SCI_CHANNELS (0x200U) diff --git a/ra/fsp/src/bsp/mcu/ra2l1/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra2l1/bsp_feature.h index d5b54dafa..535a64594 100644 --- a/ra/fsp/src/bsp/mcu/ra2l1/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra2l1/bsp_feature.h @@ -129,6 +129,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) #define BSP_FEATURE_CGC_HAS_FCLK (0U) @@ -257,6 +258,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x0006U) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0) // Feature not available on this MCU #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0) // Feature not available on this MCU @@ -297,6 +300,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x0U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (1U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (BSP_FEATURE_SCI_CHANNELS) #define BSP_FEATURE_SCI_CHANNELS (0x20FU) diff --git a/ra/fsp/src/bsp/mcu/ra2l1/bsp_power.c b/ra/fsp/src/bsp/mcu/ra2l1/bsp_power.c index ca45f239b..f934758f9 100644 --- a/ra/fsp/src/bsp/mcu/ra2l1/bsp_power.c +++ b/ra/fsp/src/bsp/mcu/ra2l1/bsp_power.c @@ -69,7 +69,7 @@ static inline void bsp_power_dcdc_disable (bsp_power_mode_t mode) * This function follows the procedure given in the RA2L1 User's Manual (R01UH0853EJ0100) Section 10.5.1 (3) "Switching * from the High-Speed/Middle-Speed mode (LDO power mode) to the High-speed/Middle speed mode (DCDC power mode)" **********************************************************************************************************************/ -static inline void bsp_power_dcdc_enable () +static inline void bsp_power_dcdc_enable (void) { /* Enable DCDC IO buffer. */ uint8_t dcdcctl = R_SYSTEM->DCDCCTL | R_SYSTEM_DCDCCTL_STOPZA_Msk; diff --git a/ra/fsp/src/bsp/mcu/ra4e1/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra4e1/bsp_feature.h index 887350207..a65d744d2 100644 --- a/ra/fsp/src/bsp/mcu/ra4e1/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra4e1/bsp_feature.h @@ -131,6 +131,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -261,6 +262,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0U) #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x1303F3U) @@ -301,6 +304,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x60000000U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (0x219U) #define BSP_FEATURE_SCI_CHANNELS (0x219U) diff --git a/ra/fsp/src/bsp/mcu/ra4m1/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra4m1/bsp_feature.h index 7f76c5974..0745e0d68 100644 --- a/ra/fsp/src/bsp/mcu/ra4m1/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra4m1/bsp_feature.h @@ -130,6 +130,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) // This MCU does not have a BCLK #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -258,6 +259,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0) // Feature not available on this MCU #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0) // Feature not available on this MCU @@ -298,6 +301,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x0U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (BSP_FEATURE_SCI_CHANNELS) #define BSP_FEATURE_SCI_CHANNELS (0x207U) diff --git a/ra/fsp/src/bsp/mcu/ra4m2/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra4m2/bsp_feature.h index 5afb6314e..1c3fe93a2 100644 --- a/ra/fsp/src/bsp/mcu/ra4m2/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra4m2/bsp_feature.h @@ -132,6 +132,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -261,6 +262,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0U) #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x13DFF3U) @@ -301,6 +304,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x60000000U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (0x219U) #define BSP_FEATURE_SCI_CHANNELS (0x21FU) diff --git a/ra/fsp/src/bsp/mcu/ra4m3/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra4m3/bsp_feature.h index f2ee832ab..13f4bf259 100644 --- a/ra/fsp/src/bsp/mcu/ra4m3/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra4m3/bsp_feature.h @@ -132,6 +132,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -262,6 +263,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0U) #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x13FFFFU) @@ -302,6 +305,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x60000000U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (0x219U) #define BSP_FEATURE_SCI_CHANNELS (0x21FU) diff --git a/ra/fsp/src/bsp/mcu/ra4w1/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra4w1/bsp_feature.h index bf7c9f069..6d1bdc5bf 100644 --- a/ra/fsp/src/bsp/mcu/ra4w1/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra4w1/bsp_feature.h @@ -130,6 +130,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) // This MCU does not have a BCLK #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -258,6 +259,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0) // Feature not available on this MCU #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0) // Feature not available on this MCU @@ -298,6 +301,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x0U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (BSP_FEATURE_SCI_CHANNELS) #define BSP_FEATURE_SCI_CHANNELS (0x213U) diff --git a/ra/fsp/src/bsp/mcu/ra6e1/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra6e1/bsp_feature.h index 363eaf099..fe50cc33f 100644 --- a/ra/fsp/src/bsp/mcu/ra6e1/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra6e1/bsp_feature.h @@ -131,6 +131,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -261,6 +262,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (1U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0U) #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x13DFF3U) @@ -301,6 +304,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x60000000U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (0x219U) #define BSP_FEATURE_SCI_CHANNELS (0x21FU) diff --git a/ra/fsp/src/bsp/mcu/ra6m1/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra6m1/bsp_feature.h index 5e691bd20..2d327f7da 100644 --- a/ra/fsp/src/bsp/mcu/ra6m1/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra6m1/bsp_feature.h @@ -134,6 +134,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (1U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -262,6 +263,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY {{1, 31}, {2, 5}} #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (1U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x00133FFFU) @@ -302,6 +305,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x60000000U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (BSP_FEATURE_SCI_CHANNELS) #define BSP_FEATURE_SCI_CHANNELS (0x31FU) diff --git a/ra/fsp/src/bsp/mcu/ra6m2/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra6m2/bsp_feature.h index 5ca2a63a2..af1da881a 100644 --- a/ra/fsp/src/bsp/mcu/ra6m2/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra6m2/bsp_feature.h @@ -134,6 +134,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (1U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -262,6 +263,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (1U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY {{0, 15}, {1, 31}, {2, 5}} #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (1U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x00133FFFU) @@ -302,6 +305,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x60000000U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (BSP_FEATURE_SCI_CHANNELS) #define BSP_FEATURE_SCI_CHANNELS (0x3FFU) diff --git a/ra/fsp/src/bsp/mcu/ra6m3/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra6m3/bsp_feature.h index 8718126b6..24a82d8e8 100644 --- a/ra/fsp/src/bsp/mcu/ra6m3/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra6m3/bsp_feature.h @@ -134,6 +134,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (1U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -262,6 +263,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (1U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY {{0, 15}, {0, 13}, {1, 31}, {1, 6}, {1, 5}, {1, 4}, {2, 5}} #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (1U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x00137FFFU) @@ -302,6 +305,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x60000000U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (BSP_FEATURE_SCI_CHANNELS) #define BSP_FEATURE_SCI_CHANNELS (0x3FFU) diff --git a/ra/fsp/src/bsp/mcu/ra6m4/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra6m4/bsp_feature.h index 10e24a9c8..2b158e44c 100644 --- a/ra/fsp/src/bsp/mcu/ra6m4/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra6m4/bsp_feature.h @@ -132,6 +132,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (1U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -262,6 +263,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (1U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0U) #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x13FFFFU) @@ -302,6 +305,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x60000000U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (0x3F9U) #define BSP_FEATURE_SCI_CHANNELS (0x3FFU) diff --git a/ra/fsp/src/bsp/mcu/ra6m5/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra6m5/bsp_feature.h index dfd8fe474..2e9ab4bb9 100644 --- a/ra/fsp/src/bsp/mcu/ra6m5/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra6m5/bsp_feature.h @@ -132,6 +132,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (2U) #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (BSP_MCU_FEATURE_SET == 'B') #define BSP_FEATURE_CGC_HAS_BCLK (1U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -262,6 +263,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (1U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0U) #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x13FFFFU) @@ -302,6 +305,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x60000000U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (0x3F9U) #define BSP_FEATURE_SCI_CHANNELS (0x3FFU) diff --git a/ra/fsp/src/bsp/mcu/ra6t1/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra6t1/bsp_feature.h index 21f1a76f2..523a4fbc1 100644 --- a/ra/fsp/src/bsp/mcu/ra6t1/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra6t1/bsp_feature.h @@ -133,6 +133,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (0U) // Feature not available on this MCU #define BSP_FEATURE_CANFD_LITE (0U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (0U) #define BSP_FEATURE_CGC_HAS_BCLK (0U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -261,6 +262,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x001EU) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (0U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY {{1, 31}, {2, 5}} #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (1U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x00131FF3U) @@ -301,6 +304,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x0U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (1U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (BSP_FEATURE_SCI_CHANNELS) #define BSP_FEATURE_SCI_CHANNELS (0x31FU) diff --git a/ra/fsp/src/bsp/mcu/ra6t2/bsp_feature.h b/ra/fsp/src/bsp/mcu/ra6t2/bsp_feature.h index d3439256e..847b3d42a 100644 --- a/ra/fsp/src/bsp/mcu/ra6t2/bsp_feature.h +++ b/ra/fsp/src/bsp/mcu/ra6t2/bsp_feature.h @@ -134,6 +134,7 @@ #define BSP_FEATURE_CANFD_NUM_CHANNELS (1U) #define BSP_FEATURE_CANFD_LITE (1U) +#define BSP_FEATURE_CANFD_FD_SUPPORT (BSP_MCU_FEATURE_SET == 'B') #define BSP_FEATURE_CGC_HAS_BCLK (0U) #define BSP_FEATURE_CGC_HAS_FCLK (1U) @@ -257,6 +258,8 @@ #define BSP_FEATURE_IOPORT_ELC_PORTS (0x7800U) #define BSP_FEATURE_IOPORT_HAS_ETHERNET (0U) +#define BSP_FEATURE_KINT_HAS_MSTP (1U) + #define BSP_FEATURE_LPM_CHANGE_MSTP_ARRAY (0U) #define BSP_FEATURE_LPM_CHANGE_MSTP_REQUIRED (0U) #define BSP_FEATURE_LPM_DPSIEGR_MASK (0x13FFFFU) @@ -297,6 +300,8 @@ #define BSP_FEATURE_QSPI_DEVICE_START_ADDRESS (0x0U) +#define BSP_FEATURE_RTC_HAS_ROPSEL (0U) + #define BSP_FEATURE_SCI_VERSION (2U) #define BSP_FEATURE_SCI_ADDRESS_MATCH_CHANNELS (0U) #define BSP_FEATURE_SCI_CHANNELS (0x21FU) diff --git a/ra/fsp/src/r_agt/r_agt.c b/ra/fsp/src/r_agt/r_agt.c index 2447a4a5d..1b7121112 100644 --- a/ra/fsp/src/r_agt/r_agt.c +++ b/ra/fsp/src/r_agt/r_agt.c @@ -786,6 +786,16 @@ static void r_agt_hardware_cfg (agt_instance_ctrl_t * const p_instance_ctrl, tim uint32_t agtmr1 = (count_source_int | edge) | mode; +#if BSP_FEATURE_RTC_HAS_ROPSEL + if (AGT_CLOCK_SUBCLOCK == p_extend->count_source) + { + /* Clear the RCR4_b.ROPSEL bit if AGT uses Sub-clock. This is necessary as ROPSEL bit is undefined after + * MCU Reset and if it is set to 1, the Sub-clock output to AGT stops in Software Standby mode. */ + R_RTC->RCR4_b.ROPSEL = 0U; + FSP_HARDWARE_REGISTER_WAIT(R_RTC->RCR4_b.ROPSEL, 0U); + } +#endif + /* Configure output settings. */ #if AGT_CFG_OUTPUT_SUPPORT_ENABLE diff --git a/ra/fsp/src/r_canfd/r_canfd.c b/ra/fsp/src/r_canfd/r_canfd.c index e96d9ed56..4a6f1324d 100644 --- a/ra/fsp/src/r_canfd/r_canfd.c +++ b/ra/fsp/src/r_canfd/r_canfd.c @@ -84,14 +84,18 @@ static bool r_canfd_bit_timing_parameter_check(can_bit_timing_cfg_t * p_bit_timi #endif -static void r_canfd_mb_read(uint32_t buffer, can_frame_t * const frame); -static void r_canfd_call_callback(canfd_instance_ctrl_t * p_ctrl, can_callback_args_t * p_args); -static void r_canfd_mode_transition(canfd_instance_ctrl_t * p_ctrl, can_operation_mode_t operation_mode); -static void r_canfd_mode_ctr_set(volatile uint32_t * p_ctr_reg, can_operation_mode_t operation_mode); +#if BSP_FEATURE_CANFD_FD_SUPPORT static uint8_t r_canfd_bytes_to_dlc(uint8_t bytes); -void canfd_error_isr(void); -void canfd_rx_fifo_isr(void); -void canfd_channel_tx_isr(void); + +#endif + +static void r_canfd_mb_read(uint32_t buffer, can_frame_t * const frame); +static void r_canfd_call_callback(canfd_instance_ctrl_t * p_ctrl, can_callback_args_t * p_args); +static void r_canfd_mode_transition(canfd_instance_ctrl_t * p_ctrl, can_operation_mode_t operation_mode); +static void r_canfd_mode_ctr_set(volatile uint32_t * p_ctr_reg, can_operation_mode_t operation_mode); +void canfd_error_isr(void); +void canfd_rx_fifo_isr(void); +void canfd_channel_tx_isr(void); /*********************************************************************************************************************** * ISR prototypes @@ -179,6 +183,8 @@ fsp_err_t R_CANFD_Open (can_ctrl_t * const p_api_ctrl, can_cfg_t const * const p /* Check nominal bit timing parameters for correctness */ FSP_ERROR_RETURN(r_canfd_bit_timing_parameter_check(p_cfg->p_bit_timing), FSP_ERR_CAN_INIT_FAILED); + #if BSP_FEATURE_CANFD_FD_SUPPORT + /* Check that bit timing for FD bitrate switching is present and correct */ can_bit_timing_cfg_t * p_data_timing = p_extend->p_data_timing; FSP_ASSERT(p_data_timing); @@ -192,6 +198,7 @@ fsp_err_t R_CANFD_Open (can_ctrl_t * const p_api_ctrl, can_cfg_t const * const p uint32_t nominal_rate_clocks = p_bit_timing->baud_rate_prescaler * (p_bit_timing->time_segment_1 + p_bit_timing->time_segment_2 + 1U); FSP_ERROR_RETURN(data_rate_clocks <= nominal_rate_clocks, FSP_ERR_CAN_INIT_FAILED); + #endif #else uint32_t channel = p_cfg->channel; @@ -309,6 +316,8 @@ fsp_err_t R_CANFD_Open (can_ctrl_t * const p_api_ctrl, can_cfg_t const * const p ((p_cfg->p_bit_timing->time_segment_2 - 1U) << R_CANFD_CFDC_NCFG_NTSEG2_Pos) | ((p_cfg->p_bit_timing->synchronization_jump_width - 1U) << R_CANFD_CFDC_NCFG_NSJW_Pos); +#if BSP_FEATURE_CANFD_FD_SUPPORT + /* Configure data bitrate for rate switching on FD frames */ R_CANFD->CFDC2[channel].DCFG = (uint32_t) (((p_extend->p_data_timing->baud_rate_prescaler - 1) & R_CANFD_CFDC2_DCFG_DBRP_Msk) << @@ -329,6 +338,7 @@ fsp_err_t R_CANFD_Open (can_ctrl_t * const p_api_ctrl, can_cfg_t const * const p (tdco << R_CANFD_CFDC2_FDCFG_TDCO_Pos) | (uint32_t) (p_extend->delay_compensation << R_CANFD_CFDC2_FDCFG_TDCE_Pos) | R_CANFD_CFDC2_FDCFG_ESIC_Msk | 1U; +#endif /* Write TX message buffer interrupt enable bits */ memcpy((void *) &R_CANFD->CFDTMIEC[channel * CANFD_PRV_CFDTMIEC_LENGTH], @@ -444,7 +454,8 @@ fsp_err_t R_CANFD_Close (can_ctrl_t * const p_api_ctrl) * @retval FSP_ERR_CAN_TRANSMIT_NOT_READY Transmit in progress, cannot write data at this time. * @retval FSP_ERR_INVALID_ARGUMENT Data length or buffer number invalid. * @retval FSP_ERR_INVALID_MODE An FD option was set on a non-FD frame. - * @retval FSP_ERR_ASSERTION Null pointer presented + * @retval FSP_ERR_ASSERTION One or more pointer arguments is NULL. + * @retval FSP_ERR_UNSUPPORTED FD is not supported on this MCU. *****************************************************************************************************************/ fsp_err_t R_CANFD_Write (can_ctrl_t * const p_api_ctrl, uint32_t buffer, can_frame_t * const p_frame) { @@ -466,6 +477,7 @@ fsp_err_t R_CANFD_Write (can_ctrl_t * const p_api_ctrl, uint32_t buffer, can_fra #endif /* Check DLC field */ + #if BSP_FEATURE_CANFD_FD_SUPPORT if (!(p_frame->options & CANFD_FRAME_OPTION_FD)) { FSP_ERROR_RETURN(p_frame->data_length_code <= 8, FSP_ERR_INVALID_ARGUMENT); @@ -481,6 +493,10 @@ fsp_err_t R_CANFD_Write (can_ctrl_t * const p_api_ctrl, uint32_t buffer, can_fra /* Do nothing. */ } + #else + FSP_ERROR_RETURN(p_frame->data_length_code <= 8, FSP_ERR_INVALID_ARGUMENT); + FSP_ERROR_RETURN(p_frame->options == 0, FSP_ERR_UNSUPPORTED); + #endif #else canfd_instance_ctrl_t * p_ctrl = (canfd_instance_ctrl_t *) p_api_ctrl; #endif @@ -491,14 +507,22 @@ fsp_err_t R_CANFD_Write (can_ctrl_t * const p_api_ctrl, uint32_t buffer, can_fra /* Ensure MB is ready */ FSP_ERROR_RETURN(0U == R_CANFD->CFDTMSTS_b[txmb].TMTSTS, FSP_ERR_CAN_TRANSMIT_NOT_READY); - /* Set TX message buffer registers */ + /* Set ID */ R_CANFD->CFDTM[txmb].ID = p_frame->id | ((uint32_t) p_frame->type << R_CANFD_CFDTM_ID_TMRTR_Pos) | ((uint32_t) p_frame->id_mode << R_CANFD_CFDTM_ID_TMIDE_Pos); +#if BSP_FEATURE_CANFD_FD_SUPPORT + + /* Set DLC */ R_CANFD->CFDTM[txmb].PTR = (uint32_t) r_canfd_bytes_to_dlc(p_frame->data_length_code) << R_CANFD_CFDTM_PTR_TMDLC_Pos; /* Set FD bits (ESI, BRS and FDF) */ R_CANFD->CFDTM[txmb].FDCTR = p_frame->options & 7U; +#else + + /* Set DLC */ + R_CANFD->CFDTM[txmb].PTR = (uint32_t) p_frame->data_length_code << R_CANFD_CFDTM_PTR_TMDLC_Pos; +#endif /* Copy data to register buffer */ uint32_t len = p_frame->data_length_code; @@ -809,8 +833,13 @@ static void r_canfd_mb_read (uint32_t buffer, can_frame_t * const frame) /* Get the frame type */ frame->type = (can_frame_type_t) ((id & R_CANFD_CFDRM_ID_RMRTR_Msk) >> R_CANFD_CFDRM_ID_RMRTR_Pos); +#if BSP_FEATURE_CANFD_FD_SUPPORT + /* Get FD status bits (ESI, BRS and FDF) */ frame->options = mb_regs->FDSTS & 7U; +#else + frame->options = 0U; +#endif /* Get the frame ID */ frame->id = id & R_CANFD_CFDRM_ID_RMID_Msk; @@ -1153,6 +1182,8 @@ static void r_canfd_mode_ctr_set (volatile uint32_t * p_ctr_reg, can_operation_m FSP_HARDWARE_REGISTER_WAIT((*p_sts_reg & CANFD_PRV_CTR_MODE_MASK), operation_mode); } +#if BSP_FEATURE_CANFD_FD_SUPPORT + /*******************************************************************************************************************//** * Converts bytes into a DLC value * @param[in] bytes Number of payload bytes @@ -1171,3 +1202,5 @@ static uint8_t r_canfd_bytes_to_dlc (uint8_t bytes) return (uint8_t) (0xDU + ((bytes / 16U) - 2U)); } + +#endif diff --git a/ra/fsp/src/r_ctsu/r_ctsu.c b/ra/fsp/src/r_ctsu/r_ctsu.c index fea7908f6..4c4ae8b89 100644 --- a/ra/fsp/src/r_ctsu/r_ctsu.c +++ b/ra/fsp/src/r_ctsu/r_ctsu.c @@ -1466,9 +1466,11 @@ fsp_err_t R_CTSU_Close (ctsu_ctrl_t * const p_ctrl) * * By setting the third argument to CTSU_SPECIFIC_SELECTED_DATA, * Get bitmap of the frequency values used in majority decision from the second argument. - * The bitch map is shown as follows. - * ||2bit | 1bit | 0bit || - * ||3rd frequency value | 2nd frequency value | 1st frequency value || + * The bitmap is shown as follows. + * + * | 2bit | 1bit | 0bit | + * |---------------------|---------------------|---------------------| + * | 3rd frequency value | 2nd frequency value | 1st frequency value | * * Implements @ref ctsu_api_t::specificDataGet. * diff --git a/ra/fsp/src/r_ether_phy/r_ether_phy.c b/ra/fsp/src/r_ether_phy/r_ether_phy.c index 3bd8401ec..d568b32bc 100644 --- a/ra/fsp/src/r_ether_phy/r_ether_phy.c +++ b/ra/fsp/src/r_ether_phy/r_ether_phy.c @@ -128,6 +128,9 @@ uint32_t ether_phy_read(ether_phy_instance_ctrl_t * p_instance_ctrl, uint32_t reg_addr); void ether_phy_write(ether_phy_instance_ctrl_t * p_instance_ctrl, uint32_t reg_addr, uint32_t data); void ether_phy_targets_initialize(ether_phy_instance_ctrl_t * p_instance_ctrl) __attribute__((weak)); +bool ether_phy_targets_is_support_link_partner_ability(ether_phy_instance_ctrl_t * p_instance_ctrl, + uint32_t line_speed_duplex) __attribute__(( + weak)); /*********************************************************************************************************************** * Private global variables and functions @@ -318,8 +321,10 @@ fsp_err_t R_ETHER_PHY_LinkPartnerAbilityGet (ether_phy_ctrl_t * const p_ctrl, uint32_t * const p_local_pause, uint32_t * const p_partner_pause) { + fsp_err_t err = FSP_SUCCESS; ether_phy_instance_ctrl_t * p_instance_ctrl = (ether_phy_instance_ctrl_t *) p_ctrl; uint32_t reg; + uint32_t line_speed_duplex = ETHER_PHY_LINK_SPEED_NO_LINK; #if (ETHER_PHY_CFG_PARAM_CHECKING_ENABLE) FSP_ASSERT(p_instance_ctrl); @@ -366,27 +371,40 @@ fsp_err_t R_ETHER_PHY_LinkPartnerAbilityGet (ether_phy_ctrl_t * const p_ctrl, } /* Establish the line speed and the duplex */ - if (ETHER_PHY_AN_LINK_PARTNER_10H == (reg & ETHER_PHY_AN_LINK_PARTNER_10H)) + if ((ETHER_PHY_AN_LINK_PARTNER_10H == (reg & ETHER_PHY_AN_LINK_PARTNER_10H)) && + ether_phy_targets_is_support_link_partner_ability(p_instance_ctrl, ETHER_PHY_LINK_SPEED_10H)) { - (*p_line_speed_duplex) = ETHER_PHY_LINK_SPEED_10H; + line_speed_duplex = ETHER_PHY_LINK_SPEED_10H; } - if (ETHER_PHY_AN_LINK_PARTNER_10F == (reg & ETHER_PHY_AN_LINK_PARTNER_10F)) + if ((ETHER_PHY_AN_LINK_PARTNER_10F == (reg & ETHER_PHY_AN_LINK_PARTNER_10F)) && + ether_phy_targets_is_support_link_partner_ability(p_instance_ctrl, ETHER_PHY_LINK_SPEED_10F)) { - (*p_line_speed_duplex) = ETHER_PHY_LINK_SPEED_10F; + line_speed_duplex = ETHER_PHY_LINK_SPEED_10F; } - if (ETHER_PHY_AN_LINK_PARTNER_100H == (reg & ETHER_PHY_AN_LINK_PARTNER_100H)) + if ((ETHER_PHY_AN_LINK_PARTNER_100H == (reg & ETHER_PHY_AN_LINK_PARTNER_100H)) && + ether_phy_targets_is_support_link_partner_ability(p_instance_ctrl, ETHER_PHY_LINK_SPEED_100H)) { - (*p_line_speed_duplex) = ETHER_PHY_LINK_SPEED_100H; + line_speed_duplex = ETHER_PHY_LINK_SPEED_100H; } - if (ETHER_PHY_AN_LINK_PARTNER_100F == (reg & ETHER_PHY_AN_LINK_PARTNER_100F)) + if ((ETHER_PHY_AN_LINK_PARTNER_100F == (reg & ETHER_PHY_AN_LINK_PARTNER_100F)) && + ether_phy_targets_is_support_link_partner_ability(p_instance_ctrl, ETHER_PHY_LINK_SPEED_100F)) { - (*p_line_speed_duplex) = ETHER_PHY_LINK_SPEED_100F; + line_speed_duplex = ETHER_PHY_LINK_SPEED_100F; } - return FSP_SUCCESS; + if (ETHER_PHY_LINK_SPEED_NO_LINK == line_speed_duplex) + { + err = FSP_ERR_ETHER_PHY_ERROR_LINK; + } + else + { + (*p_line_speed_duplex) = line_speed_duplex; + } + + return err; } /* End of function R_ETHER_PHY_LinkPartnerAbilityGet() */ /********************************************************************************************************************//** @@ -795,11 +813,30 @@ static void ether_phy_mii_write0 (ether_phy_instance_ctrl_t * p_instance_ctrl) /*********************************************************************************************************************** * Function Name: ether_phy_targets_initialize * Description : PHY-LSI specific initialization processing - * Arguments : p_ctrl - - * Ethernet channel number + * Arguments : p_instance_ctrl - + * Ethernet control block * Return Value : none ***********************************************************************************************************************/ void ether_phy_targets_initialize (ether_phy_instance_ctrl_t * p_instance_ctrl) { (void) p_instance_ctrl; } /* End of function ether_phy_targets_initialize() */ + +/*********************************************************************************************************************** + * Function Name: ether_phy_targets_is_support_link_partner_ability + * Description : Check if the PHY-LSI connected Ethernet controller supports link ability + * Arguments : p_instance_ctrl - + * Ethernet control block + * line_speed_duplex - + * Line speed duplex of link partner PHY-LSI + * Return Value : bool + ***********************************************************************************************************************/ +bool ether_phy_targets_is_support_link_partner_ability (ether_phy_instance_ctrl_t * p_instance_ctrl, + uint32_t line_speed_duplex) +{ + FSP_PARAMETER_NOT_USED(p_instance_ctrl); + FSP_PARAMETER_NOT_USED(line_speed_duplex); + + /* This PHY-LSI supports half and full duplex mode. */ + return true; +} /* End of function ether_phy_targets_is_support_link_partner_ability() */ diff --git a/ra/fsp/src/r_ether_phy/targets/DP83620/r_ether_phy_target_dp83620.c b/ra/fsp/src/r_ether_phy/targets/DP83620/r_ether_phy_target_dp83620.c index a6fedbc8d..84549abb7 100644 --- a/ra/fsp/src/r_ether_phy/targets/DP83620/r_ether_phy_target_dp83620.c +++ b/ra/fsp/src/r_ether_phy/targets/DP83620/r_ether_phy_target_dp83620.c @@ -47,7 +47,9 @@ /*********************************************************************************************************************** * Exported global function ***********************************************************************************************************************/ -void ether_phy_targets_initialize(ether_phy_instance_ctrl_t * p_instance_ctrl); +void ether_phy_targets_initialize(ether_phy_instance_ctrl_t * p_instance_ctrl); +bool ether_phy_targets_is_support_link_partner_ability(ether_phy_instance_ctrl_t * p_instance_ctrl, + uint32_t line_speed_duplex); extern uint32_t ether_phy_read(ether_phy_instance_ctrl_t * p_instance_ctrl, uint32_t reg_addr); extern void ether_phy_write(ether_phy_instance_ctrl_t * p_instance_ctrl, uint32_t reg_addr, uint32_t data); @@ -86,4 +88,23 @@ void ether_phy_targets_initialize (ether_phy_instance_ctrl_t * p_instance_ctrl) } } /* End of function ether_phy_targets_initialize() */ +/*********************************************************************************************************************** + * Function Name: ether_phy_targets_is_support_link_partner_ability + * Description : Check if the PHY-LSI connected Ethernet controller supports link ability + * Arguments : p_instance_ctrl - + * Ethernet control block + * line_speed_duplex - + * Line speed duplex of link partner PHY-LSI + * Return Value : bool + ***********************************************************************************************************************/ +bool ether_phy_targets_is_support_link_partner_ability (ether_phy_instance_ctrl_t * p_instance_ctrl, + uint32_t line_speed_duplex) +{ + FSP_PARAMETER_NOT_USED(p_instance_ctrl); + FSP_PARAMETER_NOT_USED(line_speed_duplex); + + /* This PHY-LSI supports half and full duplex mode. */ + return true; +} /* End of function ether_phy_targets_is_support_link_partner_ability() */ + #endif /* ETHER_PHY_CFG_USE_PHY == ETHER_PHY_CFG_USE_PHY_DP83620 */ diff --git a/ra/fsp/src/r_ether_phy/targets/ICS1894/r_ether_phy_target_ics1894.c b/ra/fsp/src/r_ether_phy/targets/ICS1894/r_ether_phy_target_ics1894.c new file mode 100644 index 000000000..6df537131 --- /dev/null +++ b/ra/fsp/src/r_ether_phy/targets/ICS1894/r_ether_phy_target_ics1894.c @@ -0,0 +1,126 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Includes , "Project Includes" + ***********************************************************************************************************************/ + +/* Access to peripherals and board defines. */ +#include "bsp_api.h" +#include "r_ether_phy.h" + +#if (ETHER_PHY_CFG_USE_PHY == ETHER_PHY_CFG_USE_PHY_ICS1894) + +/*********************************************************************************************************************** + * Macro definitions + ***********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Typedef definitions + ***********************************************************************************************************************/ + +/* Vendor Specific PHY Registers */ + #define ETHER_PHY_REG_PHY_CONTROL_20 (0x14) + +/*********************************************************************************************************************** + * Exported global variables (to be accessed by other files) + ***********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Exported global function + ***********************************************************************************************************************/ +void ether_phy_targets_initialize(ether_phy_instance_ctrl_t * p_instance_ctrl); +bool ether_phy_targets_is_support_link_partner_ability(ether_phy_instance_ctrl_t * p_instance_ctrl, + uint32_t line_speed_duplex); +extern uint32_t ether_phy_read(ether_phy_instance_ctrl_t * p_instance_ctrl, uint32_t reg_addr); +extern void ether_phy_write(ether_phy_instance_ctrl_t * p_instance_ctrl, uint32_t reg_addr, uint32_t data); + +/*********************************************************************************************************************** + * Private global variables and functions + ***********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Functions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Function Name: ether_phy_targets_initialize + * Description : PHY-LSI specific initialization processing + * Arguments : p_instance_ctrl - + * Ethernet control block + * Return Value : none + ***********************************************************************************************************************/ +void ether_phy_targets_initialize (ether_phy_instance_ctrl_t * p_instance_ctrl) +{ + uint32_t reg; + + /* + * When ICS1894NL of the the Renesas Electronics Corporation. is used, + * the pin that outputs the state of LINK is used combinedly with ACTIVITY in default. + * The setting of the pin is changed so that only the state of LINK is output. + */ + reg = ether_phy_read(p_instance_ctrl, ETHER_PHY_REG_PHY_CONTROL_20); + reg |= 0x0007U; + ether_phy_write(p_instance_ctrl, ETHER_PHY_REG_PHY_CONTROL_20, reg); +} /* End of function ether_phy_targets_initialize() */ + +/*********************************************************************************************************************** + * Function Name: ether_phy_targets_is_support_link_partner_ability + * Description : Check if the PHY-LSI connected Ethernet controller supports link ability + * Arguments : p_instance_ctrl - + * Ethernet control block + * line_speed_duplex - + * Line speed duplex of link partner PHY-LSI + * Return Value : bool + ***********************************************************************************************************************/ +bool ether_phy_targets_is_support_link_partner_ability (ether_phy_instance_ctrl_t * p_instance_ctrl, + uint32_t line_speed_duplex) +{ + FSP_PARAMETER_NOT_USED(p_instance_ctrl); + bool ret = false; + + /* This PHY-LSI only supports full duplex mode. */ + switch (line_speed_duplex) + { + /* 10Mbps full duplex */ + case ETHER_PHY_LINK_SPEED_10F: + { + ret = true; + break; + } + + /* 100Mbps full duplex */ + case ETHER_PHY_LINK_SPEED_100F: + { + ret = true; + break; + } + + /* Half duplex is not supported */ + default: + { + break; + } + } + + return ret; +} /* End of function ether_phy_targets_is_support_link_partner_ability() */ + +#endif /* ETHER_PHY_CFG_USE_PHY == ETHER_PHY_CFG_USE_PHY_ICS1894 */ diff --git a/ra/fsp/src/r_ether_phy/targets/KSZ8041/r_ether_phy_target_ksz8041.c b/ra/fsp/src/r_ether_phy/targets/KSZ8041/r_ether_phy_target_ksz8041.c index 0d53bfecf..ab738746c 100644 --- a/ra/fsp/src/r_ether_phy/targets/KSZ8041/r_ether_phy_target_ksz8041.c +++ b/ra/fsp/src/r_ether_phy/targets/KSZ8041/r_ether_phy_target_ksz8041.c @@ -46,7 +46,9 @@ /*********************************************************************************************************************** * Exported global function ***********************************************************************************************************************/ -void ether_phy_targets_initialize(ether_phy_instance_ctrl_t * p_instance_ctrl); +void ether_phy_targets_initialize(ether_phy_instance_ctrl_t * p_instance_ctrl); +bool ether_phy_targets_is_support_link_partner_ability(ether_phy_instance_ctrl_t * p_instance_ctrl, + uint32_t line_speed_duplex); extern uint32_t ether_phy_read(ether_phy_instance_ctrl_t * p_instance_ctrl, uint32_t reg_addr); extern void ether_phy_write(ether_phy_instance_ctrl_t * p_instance_ctrl, uint32_t reg_addr, uint32_t data); @@ -80,4 +82,23 @@ void ether_phy_targets_initialize (ether_phy_instance_ctrl_t * p_instance_ctrl) ether_phy_write(p_instance_ctrl, ETHER_PHY_REG_PHY_CONTROL_1, reg); } /* End of function ether_phy_targets_initialize() */ +/*********************************************************************************************************************** + * Function Name: ether_phy_targets_is_support_link_partner_ability + * Description : Check if the PHY-LSI connected Ethernet controller supports link ability + * Arguments : p_instance_ctrl - + * Ethernet control block + * line_speed_duplex - + * Line speed duplex of link partner PHY-LSI + * Return Value : bool + ***********************************************************************************************************************/ +bool ether_phy_targets_is_support_link_partner_ability (ether_phy_instance_ctrl_t * p_instance_ctrl, + uint32_t line_speed_duplex) +{ + FSP_PARAMETER_NOT_USED(p_instance_ctrl); + FSP_PARAMETER_NOT_USED(line_speed_duplex); + + /* This PHY-LSI supports half and full duplex mode. */ + return true; +} /* End of function ether_phy_targets_is_support_link_partner_ability() */ + #endif /* ETHER_PHY_CFG_USE_PHY == ETHER_PHY_CFG_USE_PHY_KSZ8041 */ diff --git a/ra/fsp/src/r_ether_phy/targets/KSZ8091RNB/r_ether_phy_target_ksz8091rnb.c b/ra/fsp/src/r_ether_phy/targets/KSZ8091RNB/r_ether_phy_target_ksz8091rnb.c index 109af8e54..125b72ffb 100644 --- a/ra/fsp/src/r_ether_phy/targets/KSZ8091RNB/r_ether_phy_target_ksz8091rnb.c +++ b/ra/fsp/src/r_ether_phy/targets/KSZ8091RNB/r_ether_phy_target_ksz8091rnb.c @@ -52,7 +52,9 @@ /*********************************************************************************************************************** * Exported global function ***********************************************************************************************************************/ -void ether_phy_targets_initialize(ether_phy_instance_ctrl_t * p_instance_ctrl); +void ether_phy_targets_initialize(ether_phy_instance_ctrl_t * p_instance_ctrl); +bool ether_phy_targets_is_support_link_partner_ability(ether_phy_instance_ctrl_t * p_instance_ctrl, + uint32_t line_speed_duplex); extern uint32_t ether_phy_read(ether_phy_instance_ctrl_t * p_instance_ctrl, uint32_t reg_addr); extern void ether_phy_write(ether_phy_instance_ctrl_t * p_instance_ctrl, uint32_t reg_addr, uint32_t data); @@ -97,4 +99,23 @@ void ether_phy_targets_initialize (ether_phy_instance_ctrl_t * p_instance_ctrl) ether_phy_write(p_instance_ctrl, ETHER_PHY_REG_PHY_CONTROL2, reg); } /* End of function ether_phy_targets_initialize() */ +/*********************************************************************************************************************** + * Function Name: ether_phy_targets_is_support_link_partner_ability + * Description : Check if the PHY-LSI connected Ethernet controller supports link ability + * Arguments : p_instance_ctrl - + * Ethernet control block + * line_speed_duplex - + * Line speed duplex of link partner PHY-LSI + * Return Value : bool + ***********************************************************************************************************************/ +bool ether_phy_targets_is_support_link_partner_ability (ether_phy_instance_ctrl_t * p_instance_ctrl, + uint32_t line_speed_duplex) +{ + FSP_PARAMETER_NOT_USED(p_instance_ctrl); + FSP_PARAMETER_NOT_USED(line_speed_duplex); + + /* This PHY-LSI supports half and full duplex mode. */ + return true; +} /* End of function ether_phy_targets_is_support_link_partner_ability() */ + #endif /* ETHER_PHY_CFG_USE_PHY == ETHER_PHY_CFG_USE_PHY_KSZ8091RNB */ diff --git a/ra/fsp/src/r_flash_hp/r_flash_hp.c b/ra/fsp/src/r_flash_hp/r_flash_hp.c index b692f4009..4d9749ef0 100644 --- a/ra/fsp/src/r_flash_hp/r_flash_hp.c +++ b/ra/fsp/src/r_flash_hp/r_flash_hp.c @@ -1922,7 +1922,7 @@ static fsp_err_t flash_hp_df_erase (flash_hp_instance_ctrl_t * p_ctrl, uint32_t * @retval FSP_ERR_PE_FAILURE Failed to exited P/E mode * @retval FSP_ERR_CMD_LOCKED Flash entered command locked state. **********************************************************************************************************************/ -static fsp_err_t flash_hp_pe_mode_exit () +static fsp_err_t flash_hp_pe_mode_exit (void) { /* See "Transition to Read Mode": Section 47.9.3.5 of the RA6M4 manual R01UH0890EJ0100. */ /* FRDY and CMDLK are checked after the previous commands complete and do not need to be checked again. */ @@ -2039,7 +2039,7 @@ static fsp_err_t flash_hp_reset (flash_hp_instance_ctrl_t * p_ctrl) * @retval FSP_ERR_TIMEOUT Timeout executing flash_stop. * @retval FSP_ERR_CMD_LOCKED Peripheral in command locked state. **********************************************************************************************************************/ -static fsp_err_t flash_hp_stop () +static fsp_err_t flash_hp_stop (void) { /* See "Forced Stop Command": Section 47.9.3.13 of the RA6M4 manual R01UH0890EJ0100. If the CMDLK bit * is still set after issuing the force stop command return an error. */ @@ -2071,7 +2071,7 @@ static fsp_err_t flash_hp_stop () * @retval FSP_ERR_TIMEOUT Timeout executing flash_stop.Failed to exited P/E mode * @retval FSP_ERR_CMD_LOCKED Peripheral in command locked state **********************************************************************************************************************/ -static fsp_err_t flash_hp_status_clear () +static fsp_err_t flash_hp_status_clear (void) { /* See "Status Clear Command": Section 47.9.3.12 of the RA6M4 manual R01UH0890EJ0100. */ /* Timeout counter. */ diff --git a/ra/fsp/src/r_gpt/r_gpt.c b/ra/fsp/src/r_gpt/r_gpt.c index 6bdcfc4e1..9f1cf31cb 100644 --- a/ra/fsp/src/r_gpt/r_gpt.c +++ b/ra/fsp/src/r_gpt/r_gpt.c @@ -192,6 +192,7 @@ const timer_api_t g_timer_on_gpt = * callback. * @retval FSP_ERR_INVALID_MODE Triangle wave PWM is only supported if GPT_CFG_OUTPUT_SUPPORT_ENABLE is 2. * Selected channel does not support external count sources. + * External and event count sources not are available in this mode. * @retval FSP_ERR_IP_CHANNEL_NOT_PRESENT The channel requested in the p_cfg parameter is not available on this device. **********************************************************************************************************************/ fsp_err_t R_GPT_Open (timer_ctrl_t * const p_ctrl, timer_cfg_t const * const p_cfg) @@ -213,7 +214,7 @@ fsp_err_t R_GPT_Open (timer_ctrl_t * const p_ctrl, timer_cfg_t const * const p_c #endif #if GPT_PRV_EXTRA_FEATURES_ENABLED != GPT_CFG_OUTPUT_SUPPORT_ENABLE - FSP_ERROR_RETURN(p_cfg->mode <= TIMER_MODE_PWM, FSP_ERR_INVALID_MODE); + FSP_ERROR_RETURN(p_cfg->mode <= TIMER_MODE_ONE_SHOT_PULSE, FSP_ERR_INVALID_MODE); #endif FSP_ERROR_RETURN(GPT_OPEN != p_instance_ctrl->open, FSP_ERR_ALREADY_OPEN); @@ -236,8 +237,14 @@ fsp_err_t R_GPT_Open (timer_ctrl_t * const p_ctrl, timer_cfg_t const * const p_c #if GPT_PRV_EXTRA_FEATURES_ENABLED == GPT_CFG_OUTPUT_SUPPORT_ENABLE + /* Alternate count sources cannot be used in triangle PWM modes */ + FSP_ERROR_RETURN(!((p_cfg->mode >= TIMER_MODE_ONE_SHOT_PULSE) && + (p_extend->count_up_source || p_extend->count_down_source)), + FSP_ERR_INVALID_MODE); + /* Callback is required if underflow interrupt is enabled. */ gpt_extended_pwm_cfg_t const * p_pwm_cfg = p_extend->p_pwm_cfg; + if (NULL != p_pwm_cfg) { if (p_pwm_cfg->trough_irq >= 0) @@ -510,7 +517,8 @@ fsp_err_t R_GPT_DutyCycleSet (timer_ctrl_t * const p_ctrl, uint32_t const duty_c } else { - FSP_ERROR_RETURN(!pwm_mode3_pin, FSP_ERR_INVALID_MODE); + FSP_ERROR_RETURN((!pwm_mode3_pin) || (TIMER_MODE_ONE_SHOT_PULSE == p_instance_ctrl->p_cfg->mode), + FSP_ERR_INVALID_MODE); } FSP_ERROR_RETURN(GPT_OPEN == p_instance_ctrl->open, FSP_ERR_NOT_OPEN); @@ -537,6 +545,10 @@ fsp_err_t R_GPT_DutyCycleSet (timer_ctrl_t * const p_ctrl, uint32_t const duty_c /* * In TIMER_MODE_TRIANGLE_WAVE_ASYMMETRIC_PWM_MODE3, if this is a crest duty cycle, then update the crest * duty cycle register. Otherwise, update the trough duty cycle register. + * Or in case of One-Shot pulse mode, buffer registers are either GTCCRC and GTCCRD for pulses on GTIOCnA pin + * or GTCCRE and GTCCRF for pulses on GTIOCnB pin. + * Hence update registers GTCCRD, GTCCRF for trailing edge dutycycle counts on GTIOCnA, GTIOCnB respectively, otherwise update + * registers GTCCRC,GTCCRE for leading edge dutycycle counts on GTIOCnA, GTIOCnB respectively. */ reg_offset = 4U; } @@ -552,6 +564,12 @@ fsp_err_t R_GPT_DutyCycleSet (timer_ctrl_t * const p_ctrl, uint32_t const duty_c } } + if (0 != (pin & GPT_BUFFER_FORCE_PUSH)) + { + /* Enable the compare match buffer. */ + p_instance_ctrl->p_reg->GTBER |= 1U << R_GPT0_GTBER_CCRSWT_Pos; + } + if (GPT_IO_PIN_GTIOCB != tmp_pin) { /* GTIOCA or both GTIOCA and GTIOCB. */ @@ -823,7 +841,8 @@ fsp_err_t R_GPT_PwmOutputDelaySet (timer_ctrl_t * const p_ctrl, else { uint32_t compare_match; - if (TIMER_MODE_TRIANGLE_WAVE_ASYMMETRIC_PWM_MODE3 == p_instance_ctrl->p_cfg->mode) + if ((TIMER_MODE_TRIANGLE_WAVE_ASYMMETRIC_PWM_MODE3 == p_instance_ctrl->p_cfg->mode) || + (TIMER_MODE_ONE_SHOT_PULSE == p_instance_ctrl->p_cfg->mode)) { /* In TIMER_MODE_TRIANGLE_WAVE_ASYMMETRIC_PWM_MODE3, the trough compare match value is set in * GTCCRD, and GTCCRF. */ @@ -1262,6 +1281,13 @@ static void gpt_hardware_initialize (gpt_instance_ctrl_t * const p_instance_ctrl * Register (GTPR)". The setting passed to the configuration is expected to be half the desired period for * triangle waves. */ uint32_t gtpr = p_cfg->period_counts - 1U; + + /* Set GTCR.MD = 0x001 for TIMER_MODE_ONE_SHOT_PULSE mode. */ + if (TIMER_MODE_ONE_SHOT_PULSE == p_cfg->mode) + { + gtcr |= (1U << R_GPT0_GTCR_MD_Pos); + } + #if GPT_PRV_EXTRA_FEATURES_ENABLED == GPT_CFG_OUTPUT_SUPPORT_ENABLE /* Saw-wave PWM mode is set in GTCR.MD for all modes except TIMER_MODE_TRIANGLE_WAVE_SYMMETRIC_PWM and @@ -1623,6 +1649,10 @@ static uint32_t gpt_gtior_calculate (timer_cfg_t const * const p_cfg, gpt_pin_le gtion = GPT_PRV_GTIO_TOGGLE_COMPARE_MATCH; } #endif + else if (TIMER_MODE_ONE_SHOT_PULSE == p_cfg->mode) + { + gtion = GPT_PRV_GTIO_TOGGLE_COMPARE_MATCH; + } else { /* In one-shot mode, the output pin goes high after the first compare match (one cycle after the timer starts counting). */ diff --git a/ra/fsp/src/r_i3c/r_i3c.c b/ra/fsp/src/r_i3c/r_i3c.c index bdf980465..ea62ff0da 100644 --- a/ra/fsp/src/r_i3c/r_i3c.c +++ b/ra/fsp/src/r_i3c/r_i3c.c @@ -24,12 +24,9 @@ #include "r_i3c.h" #include "r_i3c_cfg.h" -#ifndef I3C_ECO_VERSION - -/* If this is not the version of the IP that has been modified by ECO, then special error recovery operation is - * required. */ - #define I3C_ECO_VERSION (0U) -#endif +/* The address of the MCU Version Register on RA2E2 MCUs. Different error recovery procedures are used depending on the + * version of the MCU (This is only used on RA2E2 devices). */ +#define I3C_A2E2_VERSION (*((uint8_t const *) 0x01001C20U)) /*********************************************************************************************************************** * Typedef definitions @@ -1683,12 +1680,20 @@ void i3c_resp_isr (void) /* Read the remaining byte stored in the FIFO. */ i3c_fifo_read(p_ctrl, bytes_remaining); - /* If the transfer length is less than expected, the driver must perform error recovery defined in - * Figure 25.96 in the RA2E2 manual R01UH0919EJ0100. */ - if (data_length != p_ctrl->read_buffer_descriptor.buffer_size) + #if I3C_ERROR_RECOVERY_VERSION_1 == I3C_CFG_ERROR_RECOVERY_SUPPORT || \ + I3C_ERROR_RECOVERY_VERSION_BOTH == I3C_CFG_ERROR_RECOVERY_SUPPORT + #if I3C_ERROR_RECOVERY_VERSION_BOTH == I3C_CFG_ERROR_RECOVERY_SUPPORT + if (1U == I3C_A2E2_VERSION) + #endif { - error_recovery_case_2 = true; + /* If the transfer length is less than expected, the driver must perform error recovery defined in + * Figure 25.96 in the RA2E2 manual R01UH0919EJ0100. */ + if (data_length != p_ctrl->read_buffer_descriptor.buffer_size) + { + error_recovery_case_2 = true; + } } + #endif /* * For a read transfer, the DATA_LENGTH field in the response descriptor provides the total number of bytes @@ -2005,7 +2010,7 @@ void i3c_rcv_isr (void) uint32_t ntst = p_ctrl->p_reg->NTST; - /* If an error eccurred during the transfer, perform the error recovery operation defined in Figure 25.97 in the RA2E2 manual R01UH0919EJ0100. */ + /* If an error occurred during the transfer, perform the error recovery operation defined in Figure 25.97 in the RA2E2 manual R01UH0919EJ0100. */ if ((0 != (ntst & (R_I3C0_NTST_TEF_Msk | R_I3C0_NTST_TABTF_Msk))) && (0U == p_ctrl->p_reg->NRSQSTLV_b.RSQLV)) { if (I3C_INTERNAL_STATE_SLAVE_IDLE == p_ctrl->internal_state) @@ -2203,123 +2208,152 @@ void i3c_eei_isr (void) **********************************************************************************************************************/ void i3c_master_error_recovery (i3c_instance_ctrl_t * p_ctrl, bool error_recovery_case_2) { - #if !I3C_ECO_VERSION + #if I3C_ERROR_RECOVERY_VERSION_1 == I3C_CFG_ERROR_RECOVERY_SUPPORT || \ + I3C_ERROR_RECOVERY_VERSION_BOTH == I3C_CFG_ERROR_RECOVERY_SUPPORT + #if I3C_ERROR_RECOVERY_VERSION_BOTH == I3C_CFG_ERROR_RECOVERY_SUPPORT - /* Flush the Command, Rx and Tx Buffers. */ - p_ctrl->p_reg->RSTCTL = I3C_RSTCTRL_FIFO_FLUSH_Msk; + /* For A2E2 version that has not been modified by ECO, the following error recovery procedure must be performed. + * See Figure 25.96 in the RA2E2 manual R01UH0919EJ0100. */ + if (1U == I3C_A2E2_VERSION) + #endif + { + /* Flush the Command, Rx and Tx Buffers. */ + p_ctrl->p_reg->RSTCTL = I3C_RSTCTRL_FIFO_FLUSH_Msk; - /* The field will be cleared automatically upon reset completion (See section 25.2.5 in the RA2E2 manual R01UH0919EJ0100). */ - FSP_HARDWARE_REGISTER_WAIT((p_ctrl->p_reg->RSTCTL & I3C_RSTCTRL_FIFO_FLUSH_Msk), 0U); + /* The field will be cleared automatically upon reset completion (See section 25.2.5 in the RA2E2 manual R01UH0919EJ0100). */ + FSP_HARDWARE_REGISTER_WAIT((p_ctrl->p_reg->RSTCTL & I3C_RSTCTRL_FIFO_FLUSH_Msk), 0U); - /* Wait for the bus available condition. */ - while (1) - { - /* If SDA is pulled low, then a slave device started an IBI during error recovery. */ - if (0U == p_ctrl->p_reg->PRSTDBG_b.SDILV) + /* Wait for the bus available condition. */ + while (1) { - break; + /* If SDA is pulled low, then a slave device started an IBI during error recovery. */ + if (0U == p_ctrl->p_reg->PRSTDBG_b.SDILV) + { + break; + } + + /* Check the bus available condition. */ + if (1 == p_ctrl->p_reg->BCST_b.BAVLF) + { + break; + } } - /* Check the bus available condition. */ - if (1 == p_ctrl->p_reg->BCST_b.BAVLF) + if (error_recovery_case_2) { - break; - } - } + /* Disable the IBI Status Buffer Full IRQ. */ + p_ctrl->p_reg->NTIE_b.IBIQEFIE = 0; - if (error_recovery_case_2) - { - /* Disable the IBI Status Buffer Full IRQ. */ - p_ctrl->p_reg->NTIE_b.IBIQEFIE = 0; + /* When recovering from a read operation where the transfer length is less than expected, perform internal + * software reset. */ + p_ctrl->p_reg->RSTCTL = R_I3C0_RSTCTL_INTLRST_Msk; + p_ctrl->p_reg->RSTCTL = 0; - /* When recovering from a read operation where the transfer length is less than expected, perform internal - * software reset. */ - p_ctrl->p_reg->RSTCTL = R_I3C0_RSTCTL_INTLRST_Msk; - p_ctrl->p_reg->RSTCTL = 0; + /* Restore the current master setting. */ + p_ctrl->p_reg->PRSST = (uint32_t) (R_I3C0_PRSST_CRMS_Msk | R_I3C0_PRSST_PRSSTWP_Msk); - /* Restore the current master setting. */ - p_ctrl->p_reg->PRSST = (uint32_t) (R_I3C0_PRSST_CRMS_Msk | R_I3C0_PRSST_PRSSTWP_Msk); + /* After an internal reset, the CRMS bit is cleared which causes the IBI Queue Empty/Full Flag to be set indicating the queue is empty. + * Since the driver is in master mode, this status should be discarded and the flag should be cleared. */ + p_ctrl->p_reg->NTST_b.IBIQEFF = 0; - /* After an internal reset, the CRMS bit is cleared which causes the IBI Queue Empty/Full Flag to be set indicating the queue is empty. - * Since the driver is in master mode, this status should be discarded and the flag should be cleared. */ - p_ctrl->p_reg->NTST_b.IBIQEFF = 0; + /* Enable the IBI Status Buffer Full IRQ. */ + p_ctrl->p_reg->NTIE_b.IBIQEFIE = 1; + } + else + { + /* Resume I3C operation. */ + p_ctrl->p_reg->BCTL_b.RSM = 1; + } - /* Enable the IBI Status Buffer Full IRQ. */ - p_ctrl->p_reg->NTIE_b.IBIQEFIE = 1; - } - else - { - /* Resume I3C operation. */ - p_ctrl->p_reg->BCTL_b.RSM = 1; - } + /* If a slave device started an IBI during error recovery, then it must be NACK'd or SDA will be held low indefinitely. */ + if (0U == p_ctrl->p_reg->PRSTDBG_b.SDILV) + { + /* Calculate the frequency of PCLKD. */ + uint32_t pclkd_frequency = (SystemCoreClock << R_SYSTEM->SCKDIVCR_b.ICK); + pclkd_frequency >>= R_SYSTEM->SCKDIVCR_b.PCKD; - /* If a slave device started an IBI during error recovery, then it must be NACK'd or SDA will be held low indefinitely. */ - if (0U == p_ctrl->p_reg->PRSTDBG_b.SDILV) - { - /* Calculate the frequency of PCLKD. */ - uint32_t pclkd_frequency = (SystemCoreClock << R_SYSTEM->SCKDIVCR_b.ICK); - pclkd_frequency >>= R_SYSTEM->SCKDIVCR_b.PCKD; + i3c_extended_cfg_t * p_extend = (i3c_extended_cfg_t *) p_ctrl->p_cfg->p_extend; + + /* Get the low and high period in PCLKD ticks. */ + uint32_t pclkd_low_period = (p_extend->bitrate_settings.stdbr & R_I3C0_STDBR_SBRLO_Msk) >> + R_I3C0_STDBR_SBRLO_Pos; + uint32_t pclkd_high_period = (p_extend->bitrate_settings.stdbr & R_I3C0_STDBR_SBRHO_Msk) >> + R_I3C0_STDBR_SBRHO_Pos; + + /* Calculate the high and low period for SCL. */ + uint32_t high_frequency = pclkd_frequency / pclkd_high_period; + uint32_t low_frequency = pclkd_frequency / pclkd_low_period; + uint32_t high_delay_us = (1000000U + high_frequency - 1) / high_frequency; // NOLINT(readability-magic-numbers) + uint32_t low_delay_us = (1000000U + low_frequency - 1) / low_frequency; // NOLINT(readability-magic-numbers) + + /* Check if BITCNT is working correctly. */ + bool bcnt_zero = true; + for (uint32_t i = 0; i < 4; i++) + { + R_BSP_SoftwareDelay(high_delay_us + low_delay_us, BSP_DELAY_UNITS_MICROSECONDS); + if (0 != p_ctrl->p_reg->BITCNT_b.BCNT) + { + bcnt_zero = false; + } + } - i3c_extended_cfg_t * p_extend = (i3c_extended_cfg_t *) p_ctrl->p_cfg->p_extend; + /* If BITCNT is not incrementing, then the master is not aware of the IBI. */ + if (bcnt_zero) + { + /* Write SCL low in order to complete the start condition. */ + p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SDOC_Msk | R_I3C0_OUTCTL_SOCWP_Msk; - /* Get the low and high period in PCLKD ticks. */ - uint32_t pclkd_low_period = (p_extend->bitrate_settings.stdbr & R_I3C0_STDBR_SBRLO_Msk) >> - R_I3C0_STDBR_SBRLO_Pos; - uint32_t pclkd_high_period = (p_extend->bitrate_settings.stdbr & R_I3C0_STDBR_SBRHO_Msk) >> - R_I3C0_STDBR_SBRHO_Pos; + R_BSP_SoftwareDelay(low_delay_us, BSP_DELAY_UNITS_MICROSECONDS); - /* Calculate the high and low period for SCL. */ - uint32_t high_frequency = pclkd_frequency / pclkd_high_period; - uint32_t low_frequency = pclkd_frequency / pclkd_low_period; - uint32_t high_delay_us = (1000000U + high_frequency - 1) / high_frequency; // NOLINT(readability-magic-numbers) - uint32_t low_delay_us = (1000000U + low_frequency - 1) / low_frequency; // NOLINT(readability-magic-numbers) + /* Complete 9 SCL clock cycles while holding SDA high in order to NACK the IBI. */ + for (uint32_t i = 0; i < 9; i++) + { + /* Write SCL high. */ + p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SDOC_Msk | R_I3C0_OUTCTL_SCOC_Msk | R_I3C0_OUTCTL_SOCWP_Msk; - /* Check if BITCNT is working correctly. */ - bool bcnt_zero = true; - for (uint32_t i = 0; i < 4; i++) - { - R_BSP_SoftwareDelay(high_delay_us + low_delay_us, BSP_DELAY_UNITS_MICROSECONDS); - if (0 != p_ctrl->p_reg->BITCNT_b.BCNT) - { - bcnt_zero = false; - } - } + R_BSP_SoftwareDelay(high_delay_us, BSP_DELAY_UNITS_MICROSECONDS); - /* If BITCNT is not incrementing, then the master is not aware of the IBI. */ - if (bcnt_zero) - { - /* Write SCL low in order to complete the start condition. */ - p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SDOC_Msk | R_I3C0_OUTCTL_SOCWP_Msk; + /* Write SCL low. */ + p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SDOC_Msk | R_I3C0_OUTCTL_SOCWP_Msk; - R_BSP_SoftwareDelay(low_delay_us, BSP_DELAY_UNITS_MICROSECONDS); + R_BSP_SoftwareDelay(low_delay_us, BSP_DELAY_UNITS_MICROSECONDS); + } + + /* Write SCL and SDA low. */ + p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SOCWP_Msk; + + R_BSP_SoftwareDelay(low_delay_us, BSP_DELAY_UNITS_MICROSECONDS); - /* Complete 9 SCL clock cycles while holding SDA high in order to NACK the IBI. */ - for (uint32_t i = 0; i < 9; i++) - { /* Write SCL high. */ - p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SDOC_Msk | R_I3C0_OUTCTL_SCOC_Msk | R_I3C0_OUTCTL_SOCWP_Msk; + p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SCOC_Msk | R_I3C0_OUTCTL_SOCWP_Msk; R_BSP_SoftwareDelay(high_delay_us, BSP_DELAY_UNITS_MICROSECONDS); - /* Write SCL low. */ - p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SDOC_Msk | R_I3C0_OUTCTL_SOCWP_Msk; - - R_BSP_SoftwareDelay(low_delay_us, BSP_DELAY_UNITS_MICROSECONDS); + /* Write SDA anb SCL high to complete the stop condition. */ + p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SDOC_Msk | R_I3C0_OUTCTL_SCOC_Msk | R_I3C0_OUTCTL_SOCWP_Msk; } + } + } + #endif - /* Write SCL and SDA low. */ - p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SOCWP_Msk; + #if I3C_ERROR_RECOVERY_VERSION_2 == I3C_CFG_ERROR_RECOVERY_SUPPORT || \ + I3C_ERROR_RECOVERY_VERSION_BOTH == I3C_CFG_ERROR_RECOVERY_SUPPORT + #if I3C_ERROR_RECOVERY_VERSION_BOTH == I3C_CFG_ERROR_RECOVERY_SUPPORT - R_BSP_SoftwareDelay(low_delay_us, BSP_DELAY_UNITS_MICROSECONDS); + /* For A2E2 version that has been modified by ECO, simplified error recovery procedure can be performed. */ + if (2U == I3C_A2E2_VERSION) + #endif + { + FSP_PARAMETER_NOT_USED(error_recovery_case_2); - /* Write SCL high. */ - p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SCOC_Msk | R_I3C0_OUTCTL_SOCWP_Msk; + /* Flush the Command, Rx and Tx Buffers. */ + p_ctrl->p_reg->RSTCTL = I3C_RSTCTRL_FIFO_FLUSH_Msk; - R_BSP_SoftwareDelay(high_delay_us, BSP_DELAY_UNITS_MICROSECONDS); + /* The field will be cleared automatically upon reset completion (See section 25.2.5 in the RA2E2 manual R01UH0919EJ0100). */ + FSP_HARDWARE_REGISTER_WAIT((p_ctrl->p_reg->RSTCTL & I3C_RSTCTRL_FIFO_FLUSH_Msk), 0U); - /* Write SDA anb SCL high to complete the stop condition. */ - p_ctrl->p_reg->OUTCTL = R_I3C0_OUTCTL_SDOC_Msk | R_I3C0_OUTCTL_SCOC_Msk | R_I3C0_OUTCTL_SOCWP_Msk; - } + /* Resume I3C operation. */ + p_ctrl->p_reg->BCTL_b.RSM = 1; } #endif } @@ -2333,7 +2367,6 @@ void i3c_master_error_recovery (i3c_instance_ctrl_t * p_ctrl, bool error_recover **********************************************************************************************************************/ void i3c_slave_error_recovery (i3c_instance_ctrl_t * p_ctrl, i3c_slave_error_recovery_type_t recovery_type) { - #if !I3C_ECO_VERSION switch (recovery_type) { case I3C_SLAVE_ERROR_RECOVERY_TYPE_WRITE: @@ -2366,44 +2399,68 @@ void i3c_slave_error_recovery (i3c_instance_ctrl_t * p_ctrl, i3c_slave_error_rec /* The field will be cleared automatically upon reset completion (See section 25.2.5 in the RA2E2 manual R01UH0919EJ0100). */ FSP_HARDWARE_REGISTER_WAIT(p_ctrl->p_reg->RSTCTL, 0U); - /* Wait for Bus Available Condition (See Figure 25.97 in the RA2E2 manual R01UH0919EJ0100). */ - FSP_HARDWARE_REGISTER_WAIT((p_ctrl->p_reg->BCST & R_I3C0_BCST_BAVLF_Msk), R_I3C0_BCST_BAVLF_Msk); + #if I3C_ERROR_RECOVERY_VERSION_1 == I3C_CFG_ERROR_RECOVERY_SUPPORT || \ + I3C_ERROR_RECOVERY_VERSION_BOTH == I3C_CFG_ERROR_RECOVERY_SUPPORT + #if I3C_ERROR_RECOVERY_VERSION_BOTH == I3C_CFG_ERROR_RECOVERY_SUPPORT - /* Wait for start condition to be cleared (See Figure 25.97 in the RA2E2 manual R01UH0919EJ0100).. */ - FSP_HARDWARE_REGISTER_WAIT((p_ctrl->p_reg->BST & R_I3C0_BST_STCNDDF_Msk), 0); + /* For A2E2 version that has not been modified by ECO, the following error recovery procedure must be performed. + * See Figure 25.97 in the RA2E2 manual R01UH0919EJ0100. */ + if (1U == I3C_A2E2_VERSION) + #endif + { + /* Wait for Bus Available Condition (See Figure 25.97 in the RA2E2 manual R01UH0919EJ0100). */ + FSP_HARDWARE_REGISTER_WAIT((p_ctrl->p_reg->BCST & R_I3C0_BCST_BAVLF_Msk), R_I3C0_BCST_BAVLF_Msk); - /* Read the current value of SDDYAD. */ - uint32_t sdatbas0 = p_ctrl->p_reg->SDATBAS0; + /* Wait for start condition to be cleared (See Figure 25.97 in the RA2E2 manual R01UH0919EJ0100).. */ + FSP_HARDWARE_REGISTER_WAIT((p_ctrl->p_reg->BST & R_I3C0_BST_STCNDDF_Msk), 0); - /* Perform internal software reset. */ - p_ctrl->p_reg->RSTCTL = R_I3C0_RSTCTL_INTLRST_Msk; - p_ctrl->p_reg->RSTCTL = 0; + /* Read the current value of SDDYAD. */ + uint32_t sdatbas0 = p_ctrl->p_reg->SDATBAS0; - /* Calculate the frequency of PCLKD. */ - uint32_t pclkd_frequency = (SystemCoreClock << R_SYSTEM->SCKDIVCR_b.ICK); - pclkd_frequency >>= R_SYSTEM->SCKDIVCR_b.PCKD; + /* Perform internal software reset. */ + p_ctrl->p_reg->RSTCTL = R_I3C0_RSTCTL_INTLRST_Msk; + p_ctrl->p_reg->RSTCTL = 0; - /* Wait for the expected amount of time for the Bus Available Condition. */ - uint32_t expected_bus_available_time = (1000000U * p_ctrl->p_reg->BAVLCDT + pclkd_frequency - 1) / pclkd_frequency; // NOLINT(readability-magic-numbers) - R_BSP_SoftwareDelay(expected_bus_available_time, BSP_DELAY_UNITS_MICROSECONDS); + /* Calculate the frequency of PCLKD. */ + uint32_t pclkd_frequency = (SystemCoreClock << R_SYSTEM->SCKDIVCR_b.ICK); + pclkd_frequency >>= R_SYSTEM->SCKDIVCR_b.PCKD; - /* If the Bus is already available then error recovery is complete. */ - if (0 == (p_ctrl->p_reg->BCST & R_I3C0_BCST_BAVLF_Msk)) - { - while (0 == (p_ctrl->p_reg->BST & R_I3C0_BST_STCNDDF_Msk)) + /* Wait for the expected amount of time for the Bus Available Condition. */ + uint32_t expected_bus_available_time = + (1000000U * p_ctrl->p_reg->BAVLCDT + pclkd_frequency - 1) / pclkd_frequency; // NOLINT(readability-magic-numbers) + + R_BSP_SoftwareDelay(expected_bus_available_time, BSP_DELAY_UNITS_MICROSECONDS); + + /* If the Bus is already available then error recovery is complete. */ + if (0 == (p_ctrl->p_reg->BCST & R_I3C0_BCST_BAVLF_Msk)) { - /* Perform internal software reset. */ - p_ctrl->p_reg->RSTCTL = R_I3C0_RSTCTL_INTLRST_Msk; + while (0 == (p_ctrl->p_reg->BST & R_I3C0_BST_STCNDDF_Msk)) + { + /* Perform internal software reset. */ + p_ctrl->p_reg->RSTCTL = R_I3C0_RSTCTL_INTLRST_Msk; - /* Wait for Bus Available Condition (See Figure 25.97 in the RA2E2 manual R01UH0919EJ0100).. */ - FSP_HARDWARE_REGISTER_WAIT((p_ctrl->p_reg->BCST & R_I3C0_BCST_BAVLF_Msk), R_I3C0_BCST_BAVLF_Msk); + /* Wait for Bus Available Condition (See Figure 25.97 in the RA2E2 manual R01UH0919EJ0100).. */ + FSP_HARDWARE_REGISTER_WAIT((p_ctrl->p_reg->BCST & R_I3C0_BCST_BAVLF_Msk), R_I3C0_BCST_BAVLF_Msk); - p_ctrl->p_reg->RSTCTL = 0; + p_ctrl->p_reg->RSTCTL = 0; + } } + + /* Write back value of SDDYAD. */ + p_ctrl->p_reg->SDATBAS0 = sdatbas0; } + #endif + #if I3C_ERROR_RECOVERY_VERSION_2 == I3C_CFG_ERROR_RECOVERY_SUPPORT || \ + I3C_ERROR_RECOVERY_VERSION_BOTH == I3C_CFG_ERROR_RECOVERY_SUPPORT + #if I3C_ERROR_RECOVERY_VERSION_BOTH == I3C_CFG_ERROR_RECOVERY_SUPPORT - /* Write back value of SDDYAD. */ - p_ctrl->p_reg->SDATBAS0 = sdatbas0; + /* For A2E2 version that has been modified by ECO, simplified error recovery procedure can be performed. */ + if (2U == I3C_A2E2_VERSION) + #endif + { + /* Resume I3C operation. */ + p_ctrl->p_reg->BCTL_b.RSM = 1; + } #endif } diff --git a/ra/fsp/src/r_iirfa/r_iirfa.c b/ra/fsp/src/r_iirfa/r_iirfa.c index 22d9647df..8e9b5e998 100644 --- a/ra/fsp/src/r_iirfa/r_iirfa.c +++ b/ra/fsp/src/r_iirfa/r_iirfa.c @@ -111,7 +111,7 @@ fsp_err_t R_IIRFA_Open (iir_ctrl_t * const p_api_ctrl, iir_cfg_t const * const p /******************************************************************************************************************//** * Start a filter operation on the specified data. * - * @retval FSP_SUCCESS Data is successfully written to the D/A Converter. + * @retval FSP_SUCCESS Data has been successfully filtered. * @retval FSP_ERR_ASSERTION One of the provided pointers is NULL. * @retval FSP_ERR_NOT_OPEN Instance is not open. * @retval FSP_ERR_INVALID_ARGUMENT num_samples is zero. diff --git a/ra/fsp/src/r_kint/r_kint.c b/ra/fsp/src/r_kint/r_kint.c index 128996b56..b2804cd81 100644 --- a/ra/fsp/src/r_kint/r_kint.c +++ b/ra/fsp/src/r_kint/r_kint.c @@ -89,6 +89,12 @@ fsp_err_t R_KINT_Open (keymatrix_ctrl_t * const p_api_ctrl, keymatrix_cfg_t cons FSP_ERROR_RETURN(p_cfg->channel_mask <= UINT8_MAX, FSP_ERR_IP_CHANNEL_NOT_PRESENT); #endif +#if BSP_FEATURE_KINT_HAS_MSTP + + /* Clear the Module Stop bit. */ + R_BSP_MODULE_START(FSP_IP_KEY, 0); +#endif + p_ctrl->p_cfg = p_cfg; /* Configure the trigger edge. */ @@ -132,6 +138,12 @@ fsp_err_t R_KINT_Close (keymatrix_ctrl_t * const p_api_ctrl) /** Disable interrupts in the KINT peripheral*/ R_KINT->KRM = 0U; +#if BSP_FEATURE_KINT_HAS_MSTP + + /* Set the Module Stop bit. */ + R_BSP_MODULE_STOP(FSP_IP_KEY, 0); +#endif + /* Mark KINT as un-initialized */ p_ctrl->open = 0; diff --git a/ra/fsp/src/r_rtc/r_rtc.c b/ra/fsp/src/r_rtc/r_rtc.c index 1a49f2c0b..20a1c4406 100644 --- a/ra/fsp/src/r_rtc/r_rtc.c +++ b/ra/fsp/src/r_rtc/r_rtc.c @@ -113,6 +113,7 @@ const rtc_api_t g_rtc_on_rtc = { .open = R_RTC_Open, .close = R_RTC_Close, + .clockSourceSet = R_RTC_ClockSourceSet, .calendarTimeGet = R_RTC_CalendarTimeGet, .calendarTimeSet = R_RTC_CalendarTimeSet, .calendarAlarmGet = R_RTC_CalendarAlarmGet, @@ -227,25 +228,21 @@ fsp_err_t R_RTC_Open (rtc_ctrl_t * const p_ctrl, rtc_cfg_t const * const p_cfg) r_rtc_config_rtc_interrupts(p_instance_ctrl, p_cfg); - /* On a cold-start, force the RTC to be in the stoped state. Some devices power up with the RTC started. */ - /* Checks to see if the PORF bit is set. PORF can be cleared by software if application code handles a POR. */ - if (R_SYSTEM->RSTSR0 == 1) - { - r_rtc_start_bit_update(0U); - } +#if BSP_FEATURE_RTC_HAS_ROPSEL - /* Check if the RTC is already running */ - if (R_RTC->RCR2_b.START == 0) - { - /* Initialize registers. */ - R_RTC->RCR1 = 0U; - R_RTC->RCR2 = 0U; - - /* Set the clock source for RTC. - * The count source must be selected only once before making the initial settings of the RTC registers - * at power on. (see section 26.2.19 RTC Control Register 4 (RCR4) of the RA6M3 manual R01UH0886EJ0100)*/ - r_rtc_set_clock_source(p_instance_ctrl, p_cfg); - } + /* Clear the RCR4_b.ROPSEL bit as it's value is undefined after MCU Reset and if its set to 1, + * the RTC operates in low-consumption clock mode. */ + R_RTC->RCR4_b.ROPSEL = 0U; + FSP_HARDWARE_REGISTER_WAIT(R_RTC->RCR4_b.ROPSEL, 0U); +#endif + +#if RTC_CFG_OPEN_SET_CLOCK_SOURCE + + /* Set the clock source for RTC. + * The count source must be selected only once before making the initial settings of the RTC registers + * at power on. (see section 26.2.19 RTC Control Register 4 (RCR4) of the RA6M3 manual R01UH0886EJ0100)*/ + r_rtc_set_clock_source(p_instance_ctrl, p_cfg); +#endif /** Mark driver as open by initializing it to "RTC" in its ASCII equivalent. */ p_instance_ctrl->open = RTC_OPEN; @@ -300,6 +297,34 @@ fsp_err_t R_RTC_Close (rtc_ctrl_t * const p_ctrl) return FSP_SUCCESS; } +/*******************************************************************************************************************//** + * Sets the RTC clock source. Implements @ref rtc_api_t::clockSourceSet. + * + * Example: + * @snippet r_rtc_example.c R_RTC_ClockSourceSet + * + * @retval FSP_SUCCESS Initialization was successful and RTC has started. + * @retval FSP_ERR_ASSERTION Invalid p_ctrl or p_cfg pointer. + * @retval FSP_ERR_NOT_OPEN Driver is not opened. + **********************************************************************************************************************/ +fsp_err_t R_RTC_ClockSourceSet (rtc_ctrl_t * const p_ctrl) +{ + rtc_instance_ctrl_t * p_instance_ctrl = (rtc_instance_ctrl_t *) p_ctrl; + + /* Parameter checking */ +#if RTC_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_instance_ctrl); + FSP_ERROR_RETURN(RTC_OPEN == p_instance_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Set the clock source for RTC. + * The count source must be selected only once before making the initial settings of the RTC registers + * at power on. (see section 26.2.19 RTC Control Register 4 (RCR4) of the RA6M3 manual R01UH0886EJ0100)*/ + r_rtc_set_clock_source(p_instance_ctrl, p_instance_ctrl->p_cfg); + + return FSP_SUCCESS; +} + /*******************************************************************************************************************//** * Set the calendar time. * @@ -788,6 +813,13 @@ static void r_rtc_software_reset (void) **********************************************************************************************************************/ static void r_rtc_set_clock_source (rtc_instance_ctrl_t * const p_ctrl, rtc_cfg_t const * const p_cfg) { + /* Clear START bit in RCR2 */ + r_rtc_start_bit_update(0U); + + /* Initialize registers. */ + R_RTC->RCR1 = 0U; + R_RTC->RCR2 = 0U; + /* Select the count source (RCKSEL) */ R_RTC->RCR4 = (uint8_t) p_ctrl->p_cfg->clock_source; diff --git a/ra/fsp/src/r_sce_protected/crypto_procedures_protected/src/sce9/inc/api/r_sce_api.h b/ra/fsp/src/r_sce_protected/crypto_procedures_protected/src/sce9/inc/api/r_sce_api.h index 3e546b4d3..60fc6ba00 100644 --- a/ra/fsp/src/r_sce_protected/crypto_procedures_protected/src/sce9/inc/api/r_sce_api.h +++ b/ra/fsp/src/r_sce_protected/crypto_procedures_protected/src/sce9/inc/api/r_sce_api.h @@ -2079,7 +2079,7 @@ typedef struct st_sce_api * @param[in] sce_pre_master_secret pre-master secret value for SCE. * @param[in] client_random random value reported ClientHello. * @param[in] server_random random value reported ServerHello. - * @param[out] sce_master_secret master secret value for SCE. + * @param[out] sce_master_secret master secret value with SCE-specific conversion. * * @retval FSP_SUCCESS Normal termination * @retval FSP_ERR_CRYPTO_SCE_RESOURCE_CONFLICT A resource conflict occurred because a hardware resource needed diff --git a/ra/fsp/src/r_sce_protected/crypto_procedures_protected/src/sce9/public/r_sce_tls.c b/ra/fsp/src/r_sce_protected/crypto_procedures_protected/src/sce9/public/r_sce_tls.c index 7649a5c22..b9fa06223 100644 --- a/ra/fsp/src/r_sce_protected/crypto_procedures_protected/src/sce9/public/r_sce_tls.c +++ b/ra/fsp/src/r_sce_protected/crypto_procedures_protected/src/sce9/public/r_sce_tls.c @@ -193,7 +193,7 @@ fsp_err_t R_SCE_TLS_PreMasterSecretGenerateForRSA2048(uint32_t *sce_pre_master_s * @param[in] sce_pre_master_secret pre-master secret value for SCE. * @param[in] client_random random value reported ClientHello. * @param[in] server_random random value reported ServerHello. - * @param[out] sce_master_secret master secret value for SCE. + * @param[out] sce_master_secret master secret value with SCE-specific conversion. * * @retval FSP_SUCCESS Normal termination * @retval FSP_ERR_CRYPTO_SCE_RESOURCE_CONFLICT A resource conflict occurred because a hardware resource needed diff --git a/ra/fsp/src/r_usb_basic/r_usb_basic.c b/ra/fsp/src/r_usb_basic/r_usb_basic.c index c446a6723..13c80d973 100644 --- a/ra/fsp/src/r_usb_basic/r_usb_basic.c +++ b/ra/fsp/src/r_usb_basic/r_usb_basic.c @@ -78,6 +78,10 @@ #include "r_usb_phid_api.h" #endif /* defined(USB_CFG_PHID_USE) */ +#if defined(USB_CFG_PPRN_USE) + #include "r_usb_pprn_api.h" +#endif /* defined(USB_CFG_PPRN_USE) */ + #if defined(USB_CFG_OTG_USE) #if defined(USB_CFG_PCDC_USE) #include "r_usb_pcdc_api.h" @@ -432,6 +436,7 @@ fsp_err_t R_USB_Open (usb_ctrl_t * const p_api_ctrl, usb_cfg_t const * const p_c case USB_CLASS_INTERNAL_PVND: case USB_CLASS_INTERNAL_PMSC: case USB_CLASS_INTERNAL_PAUD: + case USB_CLASS_INTERNAL_PPRN: { FSP_ERROR_RETURN(USB_MODE_PERI == p_cfg->usb_mode, FSP_ERR_USB_PARAMETER) @@ -815,6 +820,9 @@ fsp_err_t R_USB_Open (usb_ctrl_t * const p_api_ctrl, usb_cfg_t const * const p_c #if defined(USB_CFG_PHID_USE) g_usb_open_class[p_ctrl->module_number] |= (uint16_t) (1 << USB_CLASS_INTERNAL_PHID); + #if ((USB_CFG_PHID_INT_IN2 != USB_NULL) || (USB_CFG_PHID_INT_OUT2 != USB_NULL)) + g_usb_open_class[p_ctrl->module_number] |= (uint16_t) (1 << USB_CLASS_INTERNAL_PHID2); + #endif /* ((USB_CFG_PHID_INT_IN2 != USB_NULL) || (USB_CFG_PHID_INT_OUT2 != USB_NULL)) */ #endif /* defined(USB_CFG_PHID_USE) */ #if defined(USB_CFG_PMSC_USE) @@ -829,6 +837,10 @@ fsp_err_t R_USB_Open (usb_ctrl_t * const p_api_ctrl, usb_cfg_t const * const p_c g_usb_open_class[p_ctrl->module_number] |= (uint16_t) (1 << USB_CLASS_INTERNAL_PVND); #endif /* defined(USB_CFG_PVND_USE) */ +#if defined(USB_CFG_PPRN_USE) + g_usb_open_class[p_ctrl->module_number] |= (uint16_t) (1 << USB_CLASS_INTERNAL_PPRN); +#endif /* defined(USB_CFG_PPRN_USE) */ + #if defined(USB_CFG_OTG_USE) _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_B; (*g_p_otg_callback[p_ctrl->module_number])(UX_OTG_MODE_SLAVE); @@ -876,44 +888,196 @@ fsp_err_t R_USB_Open (usb_ctrl_t * const p_api_ctrl, usb_cfg_t const * const p_c ******************************************************************************/ fsp_err_t R_USB_Close (usb_ctrl_t * const p_api_ctrl) { +#if defined(USB_CFG_OTG_USE) + fsp_err_t ret_code; + usb_instance_ctrl_t * p_ctrl = (usb_instance_ctrl_t *) p_api_ctrl; + uint16_t is_connect = USB_FALSE; + uint8_t class_code = USB_IFCLS_CDC; + usb_utr_t utr; + + #if USB_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(USB_NULL != p_api_ctrl) + + /* Argument Checking */ + FSP_ERROR_RETURN(!((USB_IP0 != p_ctrl->module_number) && (USB_IP1 != p_ctrl->module_number)), FSP_ERR_USB_PARAMETER) + + #if defined(BSP_BOARD_GROUP_RA2A1) + FSP_ERROR_RETURN(USB_IP1 != p_ctrl->module_number, FSP_ERR_USB_PARAMETER) + #endif /* #if defined(BSP_BOARD_GROUP_RA2A1) */ + + _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_IDLE; + g_is_A_device[p_ctrl->module_number] = USB_NO; + + switch ((usb_class_internal_t) p_ctrl->type) + { + case USB_CLASS_INTERNAL_PCDC: + { + class_code = (uint8_t) USB_IFCLS_CDC; + break; + } + + case USB_CLASS_INTERNAL_PHID: + { + class_code = (uint8_t) USB_IFCLS_HID; + break; + } + + case USB_CLASS_INTERNAL_PMSC: + { + class_code = (uint8_t) USB_IFCLS_MAS; + break; + } + + case USB_CLASS_INTERNAL_PVND: + { + class_code = (uint8_t) USB_IFCLS_VEN; + break; + } + + default: + { + return FSP_ERR_ASSERTION; + break; + } + } + #endif /* USB_CFG_PARAM_CHECKING_ENABLE */ + + utr.ip = p_ctrl->module_number; + is_connect = usb_pstd_chk_configured(&utr); + + #if (defined(USB_LDO_REGULATOR_MODULE) && (USB_CFG_LDO_REGULATOR == USB_CFG_ENABLE)) + hw_usb_clear_vdcen(); + #endif /* (defined(USB_LDO_REGULATOR_MODULE) && (USB_CFG_LDO_REGULATOR == USB_CFG_ENABLE)) */ + + ret_code = usb_module_stop(p_ctrl->module_number); + + if (FSP_SUCCESS == ret_code) + { + is_init[p_ctrl->module_number] = USB_NO; + + utr.ip = p_ctrl->module_number; + utr.ipp = usb_hstd_get_usb_ip_adr(utr.ip); + + usb_hstd_driver_release(&utr, class_code); + + usb_hstd_clr_pipe_table(utr.ip, USB_ADDRESS1); + + if ((USB_NO == g_is_usbx_otg_host_class_init[p_ctrl->module_number]) || + (USB_YES == g_is_A_device[p_ctrl->module_number])) + { + if (USB_IP1 == p_ctrl->module_number) + { + #if defined(USB_CFG_HCDC_USE) + ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hcdc_hs", R_USB_HS0_BASE, 0); + #endif /* #if defined(USB_CFG_HCDC_USE) */ + #if defined(USB_CFG_HMSC_USE) + ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hmsc_hs", R_USB_HS0_BASE, 0); + #endif /* #if defined(USB_CFG_HMSC_USE) */ + #if defined(USB_CFG_HHID_USE) + ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hhid_hs", R_USB_HS0_BASE, 0); + #endif /* #if defined(USB_CFG_HHID_USE) */ + usb_host_usbx_uninitialize(R_USB_HS0_BASE); + } + else + { + #if defined(USB_CFG_HCDC_USE) + ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hcdc_fs", R_USB_FS0_BASE, 0); + #endif /* #if defined(USB_CFG_HCDC_USE) */ + #if defined(USB_CFG_HMSC_USE) + ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hmsc_fs", R_USB_FS0_BASE, 0); + #endif /* #if defined(USB_CFG_HMSC_USE) */ + #if defined(USB_CFG_HHID_USE) + ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hhid_fs", R_USB_FS0_BASE, 0); + #endif /* #if defined(USB_CFG_HHID_USE) */ + usb_host_usbx_uninitialize(R_USB_FS0_BASE); + } + + #if defined(USB_CFG_HCDC_USE) + ux_host_stack_class_unregister(ux_host_class_cdc_acm_entry); + #endif /* #if defined(USB_CFG_HCDC_USE) */ + #if defined(USB_CFG_HMSC_USE) + ux_host_stack_class_unregister(ux_host_class_storage_entry); + #endif /* #if defined(USB_CFG_HMSC_USE) */ + #if defined(USB_CFG_HHID_USE) + ux_host_stack_class_unregister(ux_host_class_hid_entry); + #endif /* #if defined(USB_CFG_HHID_USE) */ + } + + g_is_usbx_otg_host_class_init[utr.ip] = USB_NO; + + usb_pstd_driver_release(); /* Clear the information registered in the structure usb_pcdreg_t. */ + usb_pstd_clr_pipe_table(p_ctrl->module_number); + if (USB_TRUE == is_connect) + { + _ux_device_stack_disconnect(); + } + + if (USB_IP1 == p_ctrl->module_number) + { + usb_peri_usbx_uninitialize(R_USB_HS0_BASE); + } + else + { + usb_peri_usbx_uninitialize(R_USB_FS0_BASE); + } + + g_usb_open_class[p_ctrl->module_number] = 0; + + #if defined(USB_CFG_PMSC_USE) + ret_code = usb_peri_usbx_media_close(); + #endif /* defined(USB_CFG_PMSC_USE) */ + usb_rtos_delete(p_ctrl->module_number); + + /* Be sure set 0 to g_usb_usbmode variable after calling usb_rtos_delete function. */ + g_usb_usbmode[p_ctrl->module_number] = 0; + } + else + { + ret_code = FSP_ERR_USB_NOT_OPEN; + } + + #if defined(USB_CFG_PMSC_USE) + g_usb_pmsc_usbip = USB_VALUE_FFH; + #endif /* defined(USB_CFG_PMSC_USE) */ + + g_is_A_device[p_ctrl->module_number] = USB_NO; + + _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_IDLE; + _ux_system_otg->ux_system_otg_slave_role_swap_flag = 0; + + return ret_code; +#else /* defined(USB_CFG_OTG_USE) */ fsp_err_t ret_code; usb_instance_ctrl_t * p_ctrl = (usb_instance_ctrl_t *) p_api_ctrl; -#if (BSP_CFG_RTOS != 0) - #if (USB_NUM_USBIP == 2) - #if !defined(USB_CFG_OTG_USE) + #if (BSP_CFG_RTOS != 0) + #if (USB_NUM_USBIP == 2) uint16_t usb_mode; - #endif /* !defined (USB_CFG_OTG_USE)*/ - #endif /* (USB_NUM_USBIP == 2) */ + #endif /* (USB_NUM_USBIP == 2) */ - #if (BSP_CFG_RTOS == 1) - #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) + #if (BSP_CFG_RTOS == 1) + #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) uint16_t is_connect = USB_FALSE; - #endif /* (USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI */ - #endif /* (BSP_CFG_RTOS == 1) */ -#endif /* (BSP_CFG_RTOS != 0) */ + #endif /* (USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI */ + #endif /* (BSP_CFG_RTOS == 1) */ + #endif /* (BSP_CFG_RTOS != 0) */ -#if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) + #if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) uint8_t class_code = USB_IFCLS_CDC; -#endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ + #endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ -#if USB_CFG_PARAM_CHECKING_ENABLE + #if USB_CFG_PARAM_CHECKING_ENABLE FSP_ASSERT(USB_NULL != p_api_ctrl) /* Argument Checking */ FSP_ERROR_RETURN(!((USB_IP0 != p_ctrl->module_number) && (USB_IP1 != p_ctrl->module_number)), FSP_ERR_USB_PARAMETER) - #if defined(BSP_BOARD_GROUP_RA2A1) + #if defined(BSP_BOARD_GROUP_RA2A1) FSP_ERROR_RETURN(USB_IP1 != p_ctrl->module_number, FSP_ERR_USB_PARAMETER) - #endif /* #if defined(BSP_BOARD_GROUP_RA2A1) */ - - #if defined(USB_CFG_OTG_USE) - _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_IDLE; - g_is_A_device[p_ctrl->module_number] = USB_NO; - #endif /* defined(USB_CFG_OTG_USE) */ + #endif /* #if defined(BSP_BOARD_GROUP_RA2A1) */ if (USB_MODE_HOST == g_usb_usbmode[p_ctrl->module_number]) { - #if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) + #if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) switch ((usb_class_internal_t) p_ctrl->type) { case USB_CLASS_INTERNAL_HCDC: @@ -946,33 +1110,34 @@ fsp_err_t R_USB_Close (usb_ctrl_t * const p_api_ctrl) break; } } - #endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ + #endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ } -#endif /* USB_CFG_PARAM_CHECKING_ENABLE */ + #endif /* USB_CFG_PARAM_CHECKING_ENABLE */ -#if (BSP_CFG_RTOS == 1) + #if (BSP_CFG_RTOS == 1) if (USB_MODE_PERI == g_usb_usbmode[p_ctrl->module_number]) { - #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) + #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) usb_utr_t utr; utr.ip = p_ctrl->module_number; is_connect = usb_pstd_chk_configured(&utr); - #endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ + #endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ } -#endif /* (BSP_CFG_RTOS == 1) */ + #endif /* (BSP_CFG_RTOS == 1) */ -#if (defined(USB_LDO_REGULATOR_MODULE) && (USB_CFG_LDO_REGULATOR == USB_CFG_ENABLE)) + #if (defined(USB_LDO_REGULATOR_MODULE) && (USB_CFG_LDO_REGULATOR == USB_CFG_ENABLE)) hw_usb_clear_vdcen(); -#endif /* (defined(USB_LDO_REGULATOR_MODULE) && (USB_CFG_LDO_REGULATOR == USB_CFG_ENABLE)) */ + #endif /* (defined(USB_LDO_REGULATOR_MODULE) && (USB_CFG_LDO_REGULATOR == USB_CFG_ENABLE)) */ ret_code = usb_module_stop(p_ctrl->module_number); + if (FSP_SUCCESS == ret_code) { is_init[p_ctrl->module_number] = USB_NO; if (USB_MODE_HOST == g_usb_usbmode[p_ctrl->module_number]) { -#if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) + #if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) usb_utr_t utr; utr.ip = p_ctrl->module_number; @@ -982,56 +1147,52 @@ fsp_err_t R_USB_Close (usb_ctrl_t * const p_api_ctrl) usb_hstd_clr_pipe_table(utr.ip, USB_ADDRESS1); - #if (BSP_CFG_RTOS == 1) + #if (BSP_CFG_RTOS == 1) if (USB_IP1 == p_ctrl->module_number) { - #if defined(USB_CFG_HCDC_USE) + #if defined(USB_CFG_HCDC_USE) ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hcdc_hs", R_USB_HS0_BASE, 0); - #endif /* #if defined(USB_CFG_HCDC_USE) */ - #if defined(USB_CFG_HMSC_USE) + #endif /* #if defined(USB_CFG_HCDC_USE) */ + #if defined(USB_CFG_HMSC_USE) ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hmsc_hs", R_USB_HS0_BASE, 0); - #endif /* #if defined(USB_CFG_HMSC_USE) */ - #if defined(USB_CFG_HHID_USE) + #endif /* #if defined(USB_CFG_HMSC_USE) */ + #if defined(USB_CFG_HHID_USE) ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hhid_hs", R_USB_HS0_BASE, 0); - #endif /* #if defined(USB_CFG_HHID_USE) */ + #endif /* #if defined(USB_CFG_HHID_USE) */ usb_host_usbx_uninitialize(R_USB_HS0_BASE); } else { - #if defined(USB_CFG_HCDC_USE) + #if defined(USB_CFG_HCDC_USE) ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hcdc_fs", R_USB_FS0_BASE, 0); - #endif /* #if defined(USB_CFG_HCDC_USE) */ - #if defined(USB_CFG_HMSC_USE) + #endif /* #if defined(USB_CFG_HCDC_USE) */ + #if defined(USB_CFG_HMSC_USE) ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hmsc_fs", R_USB_FS0_BASE, 0); - #endif /* #if defined(USB_CFG_HMSC_USE) */ - #if defined(USB_CFG_HHID_USE) + #endif /* #if defined(USB_CFG_HMSC_USE) */ + #if defined(USB_CFG_HHID_USE) ux_host_stack_hcd_unregister((UCHAR *) "fsp_usbx_hhid_fs", R_USB_FS0_BASE, 0); - #endif /* #if defined(USB_CFG_HHID_USE) */ + #endif /* #if defined(USB_CFG_HHID_USE) */ usb_host_usbx_uninitialize(R_USB_FS0_BASE); } - #if defined(USB_CFG_HCDC_USE) + #if defined(USB_CFG_HCDC_USE) ux_host_stack_class_unregister(ux_host_class_cdc_acm_entry); - #endif /* #if defined(USB_CFG_HCDC_USE) */ - #if defined(USB_CFG_HMSC_USE) + #endif /* #if defined(USB_CFG_HCDC_USE) */ + #if defined(USB_CFG_HMSC_USE) ux_host_stack_class_unregister(ux_host_class_storage_entry); - #endif /* #if defined(USB_CFG_HMSC_USE) */ - #if defined(USB_CFG_HHID_USE) + #endif /* #if defined(USB_CFG_HMSC_USE) */ + #if defined(USB_CFG_HHID_USE) ux_host_stack_class_unregister(ux_host_class_hid_entry); - #endif /* #if defined(USB_CFG_HHID_USE) */ - #endif /* #if (BSP_CFG_RTOS == 1) */ - - #if defined(USB_CFG_OTG_USE) - g_is_usbx_otg_host_class_init[utr.ip] = USB_NO; - #endif -#endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ + #endif /* #if defined(USB_CFG_HHID_USE) */ + #endif /* #if (BSP_CFG_RTOS == 1) */ + #endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ } else { -#if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) + #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) usb_pstd_driver_release(); /* Clear the information registered in the structure usb_pcdreg_t. */ usb_pstd_clr_pipe_table(p_ctrl->module_number); - #if (BSP_CFG_RTOS == 1) + #if (BSP_CFG_RTOS == 1) if (USB_TRUE == is_connect) { _ux_device_stack_disconnect(); @@ -1045,23 +1206,20 @@ fsp_err_t R_USB_Close (usb_ctrl_t * const p_api_ctrl) { usb_peri_usbx_uninitialize(R_USB_FS0_BASE); } - #endif /* #if (BSP_CFG_RTOS == 1) */ -#endif /* (USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI */ + #endif /* #if (BSP_CFG_RTOS == 1) */ + #endif /* (USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI */ } g_usb_open_class[p_ctrl->module_number] = 0; -#if defined(USB_CFG_PMSC_USE) - #if (BSP_CFG_RTOS == 1) + #if defined(USB_CFG_PMSC_USE) + #if (BSP_CFG_RTOS == 1) ret_code = usb_peri_usbx_media_close(); - #else + #else ret_code = r_usb_pmsc_media_close(); - #endif /* (BSP_CFG_RTOS == 1) */ -#endif /* defined(USB_CFG_PMSC_USE) */ -#if (BSP_CFG_RTOS != 0) - #if defined(USB_CFG_OTG_USE) - usb_rtos_delete(p_ctrl->module_number); - #else + #endif /* (BSP_CFG_RTOS == 1) */ + #endif /* defined(USB_CFG_PMSC_USE) */ + #if (BSP_CFG_RTOS != 0) #if (USB_NUM_USBIP == 2) usb_mode = g_usb_usbmode[0]; if (usb_mode != g_usb_usbmode[1]) @@ -1072,8 +1230,7 @@ fsp_err_t R_USB_Close (usb_ctrl_t * const p_api_ctrl) #else /* (USB_NUM_USBIP == 2) */ usb_rtos_delete(p_ctrl->module_number); #endif /* (USB_NUM_USBIP == 2) */ - #endif /* defined(USB_CFG_OTG_USE) */ -#endif /* (BSP_CFG_RTOS != 0) */ + #endif /* (BSP_CFG_RTOS != 0) */ /* Be sure set 0 to g_usb_usbmode variable after calling usb_rtos_delete function. */ g_usb_usbmode[p_ctrl->module_number] = 0; @@ -1083,18 +1240,12 @@ fsp_err_t R_USB_Close (usb_ctrl_t * const p_api_ctrl) ret_code = FSP_ERR_USB_NOT_OPEN; } -#if defined(USB_CFG_PMSC_USE) + #if defined(USB_CFG_PMSC_USE) g_usb_pmsc_usbip = USB_VALUE_FFH; -#endif /* defined(USB_CFG_PMSC_USE) */ - -#if defined(USB_CFG_OTG_USE) - g_is_A_device[p_ctrl->module_number] = USB_NO; - - _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_IDLE; - _ux_system_otg->ux_system_otg_slave_role_swap_flag = 0; -#endif /* defined(USB_CFG_OTG_USE) */ + #endif /* defined(USB_CFG_PMSC_USE) */ return ret_code; +#endif /* defined(USB_CFG_OTG_USE) */ } /**************************************************************************//** @@ -1139,7 +1290,7 @@ fsp_err_t R_USB_Read (usb_ctrl_t * const p_api_ctrl, uint8_t * p_buf, uint32_t s if (USB_MODE_PERI == g_usb_usbmode[p_ctrl->module_number]) { #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) - FSP_ERROR_RETURN(USB_CLASS_END > destination, FSP_ERR_USB_PARAMETER) + FSP_ERROR_RETURN(((USB_CLASS_PCDC <= destination) && (destination < USB_CLASS_END)), FSP_ERR_USB_PARAMETER) #endif /* #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) */ } else @@ -1253,7 +1404,7 @@ fsp_err_t R_USB_Write (usb_ctrl_t * const p_api_ctrl, uint8_t const * const p_bu if (USB_MODE_PERI == g_usb_usbmode[p_ctrl->module_number]) { #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) - FSP_ERROR_RETURN(USB_CLASS_END > destination, FSP_ERR_USB_PARAMETER) + FSP_ERROR_RETURN(((USB_CLASS_PCDC <= destination) && (destination < USB_CLASS_END)), FSP_ERR_USB_PARAMETER) #endif /* #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) */ } else @@ -1353,7 +1504,7 @@ fsp_err_t R_USB_Stop (usb_ctrl_t * const p_api_ctrl, usb_transfer_t direction, u if (USB_MODE_PERI == g_usb_usbmode[p_ctrl->module_number]) { #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) - FSP_ERROR_RETURN(USB_CLASS_END > destination, FSP_ERR_USB_PARAMETER) + FSP_ERROR_RETURN(((USB_CLASS_PCDC <= destination) && (destination < USB_CLASS_END)), FSP_ERR_USB_PARAMETER) #endif /* #if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) */ } else @@ -1682,6 +1833,8 @@ fsp_err_t R_USB_VbusSet (usb_ctrl_t * const p_api_ctrl, uint16_t state) #if defined(USB_CFG_OTG_USE) if (1 == g_is_A_device[utr.ip]) { + usb_cpu_delay_xms((uint16_t) USB_VALUE_50); + syssts = hw_usb_read_syssts(&utr); if (USB_SE0 == (syssts & USB_LNST)) diff --git a/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_cstd_rtos.h b/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_cstd_rtos.h index 949e22c8c..4f1d2ddfb 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_cstd_rtos.h +++ b/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_cstd_rtos.h @@ -107,18 +107,21 @@ typedef uint32_t rtos_time_t; ******************************************************************************/ typedef enum e_usb_rtos_err { - UsbRtos_Success = 0, // Successful - UsbRtos_Err_Init_Mbx, // Failure of Mailbox Creation - UsbRtos_Err_Init_Mpl, // Failure of Memory Pool Creation - UsbRtos_Err_Init_Tsk, // Failure of Task Creation - UsbRtos_Err_Init_Sem, // Failure of Semaphore Creation - UsbRtos_Err_Delete_Mbx, // Failure of Mailbox Delete - UsbRtos_Err_Delete_Mpl, // Failure of Memory Pool Delete - UsbRtos_Err_Delete_Tsk, // Failure of Task Delete + UsbRtos_Success = 0, // Successful + UsbRtos_Err_Init_Mbx, // Failure of Mailbox Creation + UsbRtos_Err_Init_Mpl, // Failure of Memory Pool Creation + UsbRtos_Err_Init_Tsk, // Failure of Task Creation + UsbRtos_Err_Init_Sem, // Failure of Semaphore Creation + UsbRtos_Err_Delete_Mbx, // Failure of Mailbox Delete + UsbRtos_Err_Delete_Mpl, // Failure of Memory Pool Delete + UsbRtos_Err_Delete_Tsk, // Failure of Task Delete #if defined(USB_CFG_OTG_USE) - UsbRtos_Err_Init_OTG_Detach_Tmr, // Failure of OTG Detach Timer Creation - UsbRtos_Err_Delete_OTG_Detach_Tmr, // Failure of OTG Detach Timer Delete - UsbRtos_Err_Init_OTG_Chattering_Tmr, // Failure of OTG Chattering Timer Creation + UsbRtos_Err_Init_OTG_Detach_Tmr, // Failure of OTG Detach Timer Creation + UsbRtos_Err_Delete_OTG_Detach_Tmr, // Failure of OTG Detach Timer Delete + UsbRtos_Err_Init_OTG_Chattering_Tmr, // Failure of OTG Chattering Timer Creation + UsbRtos_Err_Delete_OTG_Chattering_Tmr, // Failure of OTG Chattering Timer Creation + UsbRtos_Err_Init_OTG_HNP_Tmr, // Failure of OTG HNP Timer Creation + UsbRtos_Err_Delete_OTG_HNP_Tmr, // Failure of OTG HNP Timer Delete #endif /* defined(USB_CFG_OTG_USE) */ } usb_rtos_err_t; diff --git a/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_extern.h b/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_extern.h index 57735ca70..7defb6cec 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_extern.h +++ b/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_extern.h @@ -195,6 +195,8 @@ extern TX_TIMER g_usb_otg_detach_timer; #if USB_NUM_USBIP == 2 extern TX_TIMER g_usb2_otg_detach_timer; #endif /* USB_NUM_USBIP == 2 */ +extern volatile uint8_t g_usb_otg_hnp_counter; +extern TX_TIMER g_usb_otg_hnp_timer; #endif /* defined(USB_CFG_OTG_USE) */ /***************************************************************************** @@ -360,7 +362,7 @@ void usb_cstd_clr_pipe_cnfg(usb_utr_t * ptr, uint16_t pipe_no); void usb_cstd_set_nak(usb_utr_t * ptr, uint16_t pipe); uint16_t usb_cstd_get_buf_size(usb_utr_t * ptr, uint16_t pipe); -#if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) +#if ((USB_CFG_MODE &USB_CFG_HOST) == USB_CFG_HOST) uint8_t * usb_hstd_write_fifo(usb_utr_t * ptr, uint16_t count, uint16_t pipemode, uint8_t * write_p); uint8_t * usb_hstd_read_fifo(usb_utr_t * ptr, uint16_t count, uint16_t pipemode, uint8_t * read_p); void usb_hstd_forced_termination(usb_utr_t * ptr, uint16_t pipe, uint16_t status); @@ -369,7 +371,7 @@ void usb_hstd_nrdy_endprocess(usb_utr_t * ptr, uint16_t pipe); #endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ -#if ((USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI) +#if ((USB_CFG_MODE &USB_CFG_PERI) == USB_CFG_PERI) uint8_t * usb_pstd_write_fifo(uint16_t count, uint16_t pipemode, uint8_t * write_p, usb_utr_t * p_utr); uint8_t * usb_pstd_read_fifo(uint16_t count, uint16_t pipemode, uint8_t * read_p, usb_utr_t * p_utr); void usb_pstd_forced_termination(uint16_t pipe, uint16_t status, usb_utr_t * p_utr); @@ -648,7 +650,7 @@ void usb_peri_registration(usb_instance_ctrl_t * ctrl, usb_cfg_t const * con void usb_peri_devdefault(usb_utr_t * ptr, uint16_t mode, uint16_t data2); uint16_t usb_peri_pipe_info(uint8_t * table, uint16_t speed, uint16_t length, usb_utr_t * p_utr); void usb_peri_configured(usb_utr_t * ptr, uint16_t data1, uint16_t data2); -void usb_peri_detach(usb_utr_t * ptr, uint16_t data1, uint16_t data2); +void usb_peri_detach(usb_utr_t * ptr, uint16_t usb_state, uint16_t data2); void usb_peri_suspended(usb_utr_t * ptr, uint16_t data1, uint16_t data2); void usb_peri_resume(usb_utr_t * ptr, uint16_t data1, uint16_t data2); void usb_peri_interface(usb_utr_t * ptr, uint16_t data1, uint16_t data2); @@ -793,6 +795,7 @@ void usb2_otg_irq_callback(external_irq_callback_args_t * p_args); VOID usb_otg_detach_timer(ULONG args); VOID usb2_otg_detach_timer(ULONG args); VOID usb_otg_chattering_timer(ULONG args); +VOID usb_otg_hnp_timer(ULONG args); #endif /* defined(USB_CFG_OTG_USE) */ diff --git a/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_typedef.h b/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_typedef.h index f80a64221..9088e5cd8 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_typedef.h +++ b/ra/fsp/src/r_usb_basic/src/driver/inc/r_usb_typedef.h @@ -231,21 +231,23 @@ typedef struct usb_pipe_reg typedef enum e_usb_class_internal { - USB_CLASS_INTERNAL_PCDC = 0, ///< PCDC Class - USB_CLASS_INTERNAL_PCDCC, ///< PCDCC Class - USB_CLASS_INTERNAL_PCDC2, ///< PCDC2 Class - USB_CLASS_INTERNAL_PCDCC2, ///< PCDCC2 Class - USB_CLASS_INTERNAL_PHID, ///< PHID Class - USB_CLASS_INTERNAL_PAUD, ///< PAUD Class - USB_CLASS_INTERNAL_PVND, ///< PVND Class - USB_CLASS_INTERNAL_HCDC, ///< HCDC Class - USB_CLASS_INTERNAL_HCDCC, ///< HCDCC Class - USB_CLASS_INTERNAL_HHID, ///< HHID Class - USB_CLASS_INTERNAL_HVND, ///< HVND Class - USB_CLASS_INTERNAL_HMSC, ///< HMSC Class - USB_CLASS_INTERNAL_PMSC, ///< PMSC Class - USB_CLASS_INTERNAL_REQUEST, ///< PMSC Class - USB_CLASS_INTERNAL_END ///< USB Class + USB_CLASS_INTERNAL_PCDC = 0, ///< PCDC Class 0 + USB_CLASS_INTERNAL_PCDCC, ///< PCDCC Class 1 + USB_CLASS_INTERNAL_PCDC2, ///< PCDC2 Class 2 + USB_CLASS_INTERNAL_PCDCC2, ///< PCDCC2 Class 3 + USB_CLASS_INTERNAL_PHID, ///< PHID Class 4 + USB_CLASS_INTERNAL_PHID2, ///< PHID2 Class 5 + USB_CLASS_INTERNAL_PAUD, ///< PAUD Class 6 + USB_CLASS_INTERNAL_PPRN, ///< PPRN Class 7 + USB_CLASS_INTERNAL_PVND, ///< PVND Class 8 + USB_CLASS_INTERNAL_HCDC, ///< HCDC Class 9 + USB_CLASS_INTERNAL_HCDCC, ///< HCDCC Class 10 + USB_CLASS_INTERNAL_HHID, ///< HHID Class 11 + USB_CLASS_INTERNAL_HVND, ///< HVND Class 12 + USB_CLASS_INTERNAL_HMSC, ///< HMSC Class 13 + USB_CLASS_INTERNAL_PMSC, ///< PMSC Class 14 + USB_CLASS_INTERNAL_REQUEST, ///< USB Class Request 15 + USB_CLASS_INTERNAL_END ///< USB Class 16 } usb_class_internal_t; /** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_cdataio.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_cdataio.c index 5417988bd..5d585e975 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_cdataio.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_cdataio.c @@ -46,6 +46,9 @@ #endif /* defined(USB_CFG_PCDC_USE) */ #endif /* defined(USB_CFG_OTG_USE) */ +#if defined(USB_CFG_PPRN_USE) + #include "r_usb_pprn_api.h" +#endif /* defined(USB_CFG_PPRN_USE) */ #if defined(USB_CFG_PMSC_USE) #include "r_usb_pmsc_api.h" @@ -108,13 +111,8 @@ static const uint8_t g_usb_pipe_host[] = #endif /* defined(USB_CFG_HCDC_USE) */ #if defined(USB_CFG_HHID_USE) - #if (BSP_CFG_RTOS != 1) USB_CFG_HHID_INT_IN, USB_CFG_HHID_INT_OUT, /* HHID: Address 1 */ USB_CFG_HHID_INT_IN, USB_CFG_HHID_INT_OUT, /* HHID: Address 2 using Hub */ - #else /* (BSP_CFG_RTOS != 1) */ - USB_CFG_HHID_INT_IN, USB_NULL, /* HHID: Address 1 */ - USB_CFG_HHID_INT_IN, USB_NULL, /* HHID: Address 2 using Hub */ - #endif /* (BSP_CFG_RTOS != 1) */ USB_CFG_HHID_INT_IN2, USB_NULL, /* HHID: Address 3 using Hub */ USB_CFG_HHID_INT_IN3, USB_NULL, /* HHID: Address 4 using Hub */ #else /* defined(USB_CFG_HHID_USE) */ @@ -131,32 +129,41 @@ static const uint8_t g_usb_pipe_peri[] = { /* OUT pipe */ /* IN pipe */ #if defined(USB_CFG_PCDC_USE) - USB_CFG_PCDC_BULK_OUT, USB_CFG_PCDC_BULK_IN, /* USB_PCDC */ - USB_NULL, USB_CFG_PCDC_INT_IN, /* USB_PCDCC */ - USB_CFG_PCDC_BULK_OUT2, USB_CFG_PCDC_BULK_IN2, /* USB_PCDC2 */ - USB_NULL, USB_CFG_PCDC_INT_IN2, /* USB_PCDCC2 */ + USB_CFG_PCDC_BULK_OUT, USB_CFG_PCDC_BULK_IN, /* USB_PCDC (0) */ + USB_NULL, USB_CFG_PCDC_INT_IN, /* USB_PCDCC (1) */ + USB_CFG_PCDC_BULK_OUT2, USB_CFG_PCDC_BULK_IN2, /* USB_PCDC2 (2) */ + USB_NULL, USB_CFG_PCDC_INT_IN2, /* USB_PCDCC2 (3) */ #else /* defined(USB_CFG_PCDC_USE) */ USB_NULL, USB_NULL, USB_NULL, USB_NULL, USB_NULL, USB_NULL, USB_NULL, USB_NULL, - #endif /* defined(USB_CFG_PCDC_USE) */ + #endif /* defined(USB_CFG_PCDC_USE) */ #if defined(USB_CFG_PHID_USE) #if (BSP_CFG_RTOS != 1) - USB_CFG_PHID_INT_OUT, USB_CFG_PHID_INT_IN, /* USB_PHID */ + USB_CFG_PHID_INT_OUT, USB_CFG_PHID_INT_IN, /* USB_PHID (4) */ + USB_CFG_PHID_INT_OUT2, USB_CFG_PHID_INT_IN2, /* USB_PHID2 (5) */ #else /* #if (BSP_CFG_RTOS != 1) */ - USB_NULL, USB_CFG_PHID_INT_IN, /* USB_PHID */ + USB_CFG_PHID_INT_OUT, USB_CFG_PHID_INT_IN, /* USB_PHID (4) */ + USB_NULL, USB_NULL, /* USB_PHID2 (5) */ #endif /* #if (BSP_CFG_RTOS != 1) */ - #else /* defined(USB_CFG_PHID_USE) */ + #else /* defined(USB_CFG_PHID_USE) */ + USB_NULL, USB_NULL, USB_NULL, USB_NULL, - #endif /* defined(USB_CFG_PHID_USE) */ + #endif /* defined(USB_CFG_PHID_USE) */ #if defined(USB_CFG_PAUD_USE) - USB_CFG_PAUD_ISO_OUT, USB_CFG_PAUD_ISO_IN, /* USB_PAUD */ - #else /* defined(USB_CFG_PAUD_USE) */ + USB_CFG_PAUD_ISO_OUT, USB_CFG_PAUD_ISO_IN, /* USB_PAUD (6) */ + #else /* defined(USB_CFG_PAUD_USE) */ + USB_NULL, USB_NULL, + #endif /* defined(USB_CFG_PAUD_USE) */ + + #if defined(USB_CFG_PPRN_USE) + USB_CFG_PPRN_BULK_OUT, USB_CFG_PPRN_BULK_IN, /* USB_PPRN (7) */ + #else /* defined(USB_CFG_PPRN_USE) */ USB_NULL, USB_NULL, - #endif /* defined(USB_CFG_PAUD_USE) */ + #endif /* defined(USB_CFG_PPRN_USE) */ }; #endif /* (USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI */ @@ -183,77 +190,83 @@ void (* g_usb_callback[])(usb_utr_t *, uint16_t, uint16_t) = /* PCDC, PCDCC */ #if defined(USB_CFG_PCDC_USE) #if (BSP_CFG_RTOS == 1) - USB_NULL, USB_NULL, /* USB_PCDC (0) */ - USB_NULL, USB_NULL, /* USB_PCDCC (1) */ - USB_NULL, USB_NULL, /* USB_PCDC2 (0) */ - USB_NULL, USB_NULL, /* USB_PCDCC2 (1) */ + USB_NULL, USB_NULL, /* USB_PCDC (0) */ + USB_NULL, USB_NULL, /* USB_PCDCC (1) */ + USB_NULL, USB_NULL, /* USB_PCDC2 (2) */ + USB_NULL, USB_NULL, /* USB_PCDCC2 (3) */ #else /* #if (BSP_CFG_RTOS == 1) */ usb_pcdc_read_complete, usb_pcdc_write_complete, /* USB_PCDC (0) */ - USB_NULL, usb_pcdc_write_complete, /* USB_PCDCC (1) */ - usb_pcdc_read_complete, usb_pcdc_write_complete, /* USB_PCDC2 (0) */ - USB_NULL, usb_pcdc_write_complete, /* USB_PCDCC2 (1) */ + USB_NULL, usb_pcdc_write_complete, /* USB_PCDCC (1) */ + usb_pcdc_read_complete, usb_pcdc_write_complete, /* USB_PCDC2 (2) */ + USB_NULL, usb_pcdc_write_complete, /* USB_PCDCC2 (3) */ #endif /* #if (BSP_CFG_RTOS == 1) */ #else - USB_NULL, USB_NULL, /* USB_PCDC (0) */ - USB_NULL, USB_NULL, /* USB_PCDCC (1) */ - USB_NULL, USB_NULL, /* USB_PCDC2 (0) */ - USB_NULL, USB_NULL, /* USB_PCDCC2 (1) */ + USB_NULL, USB_NULL, /* USB_PCDC (0) */ + USB_NULL, USB_NULL, /* USB_PCDCC (1) */ + USB_NULL, USB_NULL, /* USB_PCDC2 (2) */ + USB_NULL, USB_NULL, /* USB_PCDCC2 (3) */ #endif /* PHID */ #if defined(USB_CFG_PHID_USE) #if (BSP_CFG_RTOS != 1) - usb_phid_read_complete, usb_phid_write_complete, /* USB_PHID (2) */ + usb_phid_read_complete, usb_phid_write_complete, /* USB_PHID (4) */ + usb_phid_read_complete, usb_phid_write_complete, /* USB_PHID2 (5) */ #else /* #if (BSP_CFG_RTOS == 1) */ - USB_NULL, USB_NULL, + USB_NULL, USB_NULL, /* USB_PHID (4) */ + USB_NULL, USB_NULL, /* USB_PHID (5) */ #endif /* #if (BSP_CFG_RTOS == 1) */ #else - USB_NULL, USB_NULL, /* USB_PHID (2) */ + USB_NULL, USB_NULL, /* USB_PHID (4) */ + USB_NULL, USB_NULL, /* USB_PHID (5) */ #endif /* PAUD */ - USB_NULL, USB_NULL, /* USB_PAUD */ + USB_NULL, USB_NULL, /* USB_PAUD (6) */ + + /* PPRN */ + USB_NULL, USB_NULL, /* USB_PPRN (7) */ /* PVND */ - USB_NULL, USB_NULL, /* USB_PVND (3) */ + USB_NULL, USB_NULL, /* USB_PVND (8) */ /* HCDC, HCDCC */ #if defined(USB_CFG_HCDC_USE) #if (BSP_CFG_RTOS == 1) - USB_NULL, USB_NULL, /* USB_HCDC (4) */ - USB_NULL, USB_NULL, /* USB_HCDCC (5) */ + USB_NULL, USB_NULL, /* USB_HCDC (9) */ + USB_NULL, USB_NULL, /* USB_HCDCC (10) */ #else /* #if (BSP_CFG_RTOS == 1) */ - usb_hcdc_read_complete, usb_hcdc_write_complete, /* USB_HCDC (4) */ - usb_hcdc_read_complete, USB_NULL, /* USB_HCDCC (5) */ + usb_hcdc_read_complete, usb_hcdc_write_complete, /* USB_HCDC (9) */ + usb_hcdc_read_complete, USB_NULL, /* USB_HCDCC (10) */ #endif /* #if (BSP_CFG_RTOS == 1) */ #else - USB_NULL, USB_NULL, /* USB_HCDC (4) */ - USB_NULL, USB_NULL, /* USB_HCDCC (5) */ + USB_NULL, USB_NULL, /* USB_HCDC (9) */ + USB_NULL, USB_NULL, /* USB_HCDCC (10) */ #endif /* HHID */ #if defined(USB_CFG_HHID_USE) #if (BSP_CFG_RTOS == 1) - USB_NULL, USB_NULL, + USB_NULL, USB_NULL, /* USB_HHID (11) */ #else /* #if (BSP_CFG_RTOS == 1) */ - usb_hhid_read_complete, usb_hhid_write_complete, /* USB_HHID (6) */ + usb_hhid_read_complete, usb_hhid_write_complete, /* USB_HHID (11) */ #endif /* #if (BSP_CFG_RTOS == 1) */ #else - USB_NULL, USB_NULL, /* USB_HHID (6) */ + USB_NULL, USB_NULL, /* USB_HHID (11) */ #endif /* HVND */ #if defined(USB_CFG_HVND_USE) - usb_hvnd_read_complete, usb_hvnd_write_complete, /* USB_HVND (7) */ + usb_hvnd_read_complete, usb_hvnd_write_complete, /* USB_HVND (12) */ #else - USB_NULL, USB_NULL, /* USB_HVND (7) */ + USB_NULL, USB_NULL, /* USB_HVND (12) */ #endif /* HMSC */ - USB_NULL, USB_NULL, /* USB_HMSC (8) */ + USB_NULL, USB_NULL, /* USB_HMSC (13) */ /* PMSC */ - USB_NULL, USB_NULL, /* USB_PMSC (9) */ + USB_NULL, USB_NULL, /* USB_PMSC (14) */ }; /* const void (g_usb_callback[])(usb_utr_t *, uint16_t, uint16_t) */ #if defined(USB_CFG_PCDC_USE) diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_clibusbip.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_clibusbip.c index cdf63a89e..9701c2320 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_clibusbip.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_clibusbip.c @@ -53,6 +53,11 @@ #endif /* defined(USB_CFG_PCDC_USE) */ +#if defined(USB_CFG_PPRN_USE) + #include "r_usb_pprn_api.h" + +#endif /* defined(USB_CFG_PPRN_USE) */ + #if defined(USB_CFG_PMSC_USE) #include "r_usb_pmsc_api.h" @@ -426,8 +431,7 @@ void usb_set_event (usb_status_t event, usb_instance_ctrl_t * p_ctrl) if (USB_MODE_HOST == g_usb_usbmode[p_ctrl->module_number]) { #if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) - (*g_usb_apl_callback[p_ctrl->module_number])(&g_usb_cstd_event[count], - (usb_hdl_t) p_ctrl->p_data, + (*g_usb_apl_callback[p_ctrl->module_number])(&g_usb_cstd_event[count], (usb_hdl_t) p_ctrl->p_data, USB_OFF); #endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ } @@ -437,15 +441,13 @@ void usb_set_event (usb_status_t event, usb_instance_ctrl_t * p_ctrl) if (0 == p_ctrl->setup.request_length) { /* Processing for USB request has the no data stage */ - (*g_usb_apl_callback[p_ctrl->module_number])(&g_usb_cstd_event[count], - (usb_hdl_t) USB_NULL, + (*g_usb_apl_callback[p_ctrl->module_number])(&g_usb_cstd_event[count], (usb_hdl_t) USB_NULL, USB_OFF); } else { /* Processing for USB request has the data state */ - (*g_usb_apl_callback[p_ctrl->module_number])(&g_usb_cstd_event[count], - (usb_hdl_t) p_ctrl->p_data, + (*g_usb_apl_callback[p_ctrl->module_number])(&g_usb_cstd_event[count], (usb_hdl_t) p_ctrl->p_data, USB_OFF); } #endif /* (USB_CFG_MODE & USB_CFG_PERI) == USB_CFG_PERI */ @@ -583,9 +585,9 @@ void usb_cstd_usb_task (void) usb_class_task(); } } - /* WAIT_LOOP */ while (USB_FALSE != g_drive_search_lock); + #else /* defined(USB_CFG_HMSC_USE) */ usb_cstd_scheduler(); /* Scheduler */ @@ -677,6 +679,7 @@ uint16_t usb_cstd_remote_wakeup (usb_utr_t * p_utr) } else { + // ret_code = FSP_ERR_USB_FAILED; return USB_ERROR; } diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_cstd_rtos.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_cstd_rtos.c index bd07ac1fb..d705cd6bd 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_cstd_rtos.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_cstd_rtos.c @@ -61,6 +61,7 @@ TX_SEMAPHORE g_usb_peri_usbx_sem[USB_MAX_PIPE_NO + 1]; #if defined(USB_CFG_OTG_USE) TX_TIMER g_usb_otg_detach_timer; TX_TIMER g_usb_otg_chattering_timer; +TX_TIMER g_usb_otg_hnp_timer; #if USB_NUM_USBIP == 2 TX_TIMER g_usb2_otg_detach_timer; #endif /* USB_NUM_USBIP == 2 */ @@ -1005,6 +1006,21 @@ usb_rtos_err_t usb_rtos_configuration (usb_mode_t usb_mode) return err; } + ret = tx_timer_create(&g_usb_otg_hnp_timer, /* Pointer to detach timer */ + "USB OTG HNP Timer", /* Detach Timer Name */ + usb_otg_hnp_timer, /* Pointer to detach timer function */ + (ULONG) 0, /* Expiration Input */ + (ULONG) 10, /* Initial Ticks */ + (ULONG) 10, /* Reschedule Ticks */ + TX_NO_ACTIVATE); /* Auto Activate */ + + if (TX_SUCCESS != ret) + { + err = UsbRtos_Err_Init_OTG_HNP_Tmr; + + return err; + } + #if USB_NUM_USBIP == 2 ret = tx_timer_create(&g_usb2_otg_detach_timer, /* Pointer to detach timer */ "USB2 OTG Detach Timer", /* Detach Timer Name */ @@ -1435,6 +1451,21 @@ usb_rtos_err_t usb_rtos_delete (uint8_t module_number) return err; } #endif /* USB_NUM_USBIP == 2 */ + ret = tx_timer_delete(&g_usb_otg_chattering_timer); + if (TX_SUCCESS != ret) + { + err = UsbRtos_Err_Delete_OTG_Chattering_Tmr; + + return err; + } + + ret = tx_timer_delete(&g_usb_otg_hnp_timer); + if (TX_SUCCESS != ret) + { + err = UsbRtos_Err_Delete_OTG_HNP_Tmr; + + return err; + } #endif /* defined (USB_CFG_OTG_USE) */ #endif /* BSP_CFG_RTOS */ diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_hdriver.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_hdriver.c index ef64f5158..bfa0fe5ed 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_hdriver.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_hdriver.c @@ -55,6 +55,11 @@ #endif /* defined(USB_CFG_PCDC_USE) */ +#if defined(USB_CFG_PPRN_USE) + #include "r_usb_pprn_api.h" + +#endif /* defined(USB_CFG_PPRN_USE) */ + #if defined(USB_CFG_PMSC_USE) #include "r_usb_pmsc_api.h" @@ -1041,14 +1046,6 @@ static void usb_hstd_interrupt (usb_utr_t * ptr) usb_hstd_otg_mode_to_peri(ptr); g_usb_usbmode[ptr->ip] = USB_MODE_PERI; - if (USB_YES == g_is_A_device[ptr->ip]) - { - _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_A; - } - else - { - _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_B; - } (*g_p_otg_callback[ptr->ip])(UX_OTG_MODE_SLAVE); @@ -3097,9 +3094,9 @@ void usb_hvnd_read_complete (usb_utr_t * ptr, uint16_t data1, uint16_t data2) usb_instance_ctrl_t ctrl; - ctrl.module_number = ptr->ip; /* Module number setting */ - ctrl.pipe = (uint8_t) ptr->keyword; /* Pipe number setting */ - ctrl.type = USB_CLASS_INTERNAL_HVND; /* Vendor class */ + ctrl.module_number = ptr->ip; /* Module number setting */ + ctrl.pipe = (uint8_t) ptr->keyword; /* Pipe number setting */ + ctrl.type = USB_CLASS_HVND; /* Vendor class */ ctrl.data_size = ptr->read_req_len - ptr->tranlen; ctrl.device_address = (uint8_t) (usb_hstd_get_devsel(ptr, ctrl.pipe) >> 12); @@ -3156,9 +3153,9 @@ void usb_hvnd_write_complete (usb_utr_t * ptr, uint16_t data1, uint16_t data2) usb_instance_ctrl_t ctrl; - ctrl.module_number = ptr->ip; /* Module number setting */ - ctrl.pipe = (uint8_t) ptr->keyword; /* Pipe number setting */ - ctrl.type = USB_CLASS_INTERNAL_HVND; /* Vendor class */ + ctrl.module_number = ptr->ip; /* Module number setting */ + ctrl.pipe = (uint8_t) ptr->keyword; /* Pipe number setting */ + ctrl.type = USB_CLASS_HVND; /* Vendor class */ ctrl.device_address = (uint8_t) (usb_hstd_get_devsel(ptr, ctrl.pipe) >> 12); #if (BSP_CFG_RTOS != 0) ctrl.p_data = (void *) ptr->cur_task_hdl; diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_hlibusbip.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_hlibusbip.c index 045733668..0c0c84bef 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_hlibusbip.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_hlibusbip.c @@ -261,6 +261,7 @@ uint16_t usb_hstd_chk_dev_addr (usb_utr_t * ptr, uint16_t addr) buffer = hw_usb_hread_devadd(ptr, addr); if (USB_ERROR != buffer) { + /* Return Address check result */ return (uint16_t) (buffer & USB_USBSPD); } @@ -289,6 +290,7 @@ uint16_t usb_hstd_get_dev_speed (usb_utr_t * ptr, uint16_t addr) buffer = hw_usb_hread_devadd(ptr, addr); if (USB_ERROR != buffer) { + /* Return device speed */ return (uint16_t) (buffer & USB_USBSPD); } @@ -365,6 +367,7 @@ uint16_t usb_hstd_pipe2fport (usb_utr_t * ptr, uint16_t pipe) { fifo_mode = USB_D0USE; } + #else if (0 != ptr->p_transfer_rx) { @@ -379,6 +382,7 @@ uint16_t usb_hstd_pipe2fport (usb_utr_t * ptr, uint16_t pipe) { fifo_mode = USB_D1USE; } + #else if (0 != ptr->p_transfer_tx) { @@ -612,6 +616,7 @@ uint16_t usb_hstd_write_data (usb_utr_t * ptr, uint16_t pipe, uint16_t pipemode) /* Check error */ if (USB_FIFOERROR == buffer) { + /* FIFO access error */ return USB_FIFOERROR; } @@ -782,6 +787,7 @@ void usb_hstd_receive_start (usb_utr_t * ptr, uint16_t pipe) } #if ((USB_CFG_DTC == USB_CFG_ENABLE) || (USB_CFG_DMA == USB_CFG_ENABLE)) + /* D1FIFO DMA */ case USB_D1USE: @@ -852,6 +858,7 @@ uint16_t usb_hstd_read_data (usb_utr_t * ptr, uint16_t pipe, uint16_t pipemode) buffer = usb_cstd_is_set_frdy(ptr, pipe, pipemode, USB_FALSE); if (USB_FIFOERROR == buffer) { + /* FIFO access error */ return USB_FIFOERROR; } @@ -965,6 +972,7 @@ void usb_hstd_data_end (usb_utr_t * ptr, uint16_t pipe, uint16_t status) } #if ((USB_CFG_DTC == USB_CFG_ENABLE) || (USB_CFG_DMA == USB_CFG_ENABLE)) + /* D0FIFO DMA */ case USB_D0USE: { @@ -1677,9 +1685,7 @@ uint8_t usb_hstd_get_pipe_no (uint16_t ip_no, uint16_t address, uint16_t usb_cla /* Check root port device1 or Hub downport device1 */ if ((1 == address) || (2 == address)) { - #if (BSP_CFG_RTOS != 1) pipe_no = USB_CFG_HHID_INT_OUT; - #endif /* #if (BSP_CFG_RTOS != 1) */ } } } @@ -1693,6 +1699,7 @@ uint8_t usb_hstd_get_pipe_no (uint16_t ip_no, uint16_t address, uint16_t usb_cla if (USB_EP_BULK == type) { #if (BSP_CFG_RTOS != 1) + /* Add USB IP no. for USB Device address */ if (USB_IP1 == ip_no) { @@ -1708,6 +1715,7 @@ uint8_t usb_hstd_get_pipe_no (uint16_t ip_no, uint16_t address, uint16_t usb_cla /* Calculate the pipe number corresponding to the drive number */ pipe_no = (uint8_t) (USB_PIPE1 + side); } + #else /* #if (BSP_CFG_RTOS != 1) */ pipe_no = USB_PIPE1; #endif /* #if (BSP_CFG_RTOS != 1) */ diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_hmanager.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_hmanager.c index 9aad9f5ab..4e9b3d495 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_hmanager.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_hmanager.c @@ -2807,7 +2807,11 @@ void usb_hstd_mgr_task (void * stacd) } else { - _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_IDLE; + syssts = hw_usb_read_syssts(ptr); + if (USB_SE0 == (syssts & USB_LNST)) + { + _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_IDLE; + } } #endif /* defined(USB_CFG_OTG_USE) */ diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_pdriver.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_pdriver.c index a26a3c711..9d00e6974 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_pdriver.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_pdriver.c @@ -51,7 +51,8 @@ * Macro definitions ******************************************************************************/ - #define USB_VALUE_100 (100) + #define USB_VALUE_100 (100) + #define USB_OTG_SE0_BRST (16) /****************************************************************************** * Private global variables and functions @@ -103,6 +104,7 @@ usb_setup_t g_usb_pstd_req_reg; /* Device Request - Requ volatile uint8_t g_usb_is_otg_attach_interrupt[USB_NUM_USBIP]; #if (BSP_CFG_RTOS == 1) +extern bool g_usb_peri_usbx_is_detach[USB_MAX_PIPE_NO + 1]; extern TX_SEMAPHORE g_usb_peri_usbx_sem[USB_MAX_PIPE_NO + 1]; extern UINT usb_host_usbx_initialize(UX_HCD * hcd); @@ -452,13 +454,13 @@ static void usb_pstd_interrupt (usb_utr_t * p_mess) { #if defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) hw_usb_set_cnen(p_mess->ip); - #endif /* defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) */ + #endif /* defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) */ if (USB_ATTACH == usb_pstd_chk_vbsts(p_mess->ip)) { USB_PRINTF0("VBUS int attach\n"); - usb_pstd_attach_process(p_mess); /* USB attach */ + usb_pstd_attach_process(p_mess); /* USB attach */ #if defined(USB_CFG_OTG_USE) - _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_B; + _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_B; /* IDLE --> DEVICE_B */ (*g_p_otg_callback[p_mess->ip])(UX_OTG_MODE_SLAVE); #endif /* defined(USB_CFG_OTG_USE) */ } @@ -479,12 +481,12 @@ static void usb_pstd_interrupt (usb_utr_t * p_mess) /* A device and A cable detach --> Peri mode */ g_is_A_cable_detach[p_mess->ip] = USB_NO; - _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_IDLE; + _ux_system_otg->ux_system_otg_device_type = UX_OTG_DEVICE_IDLE; /* A Device --> IDLE */ (*g_p_otg_callback[p_mess->ip])(UX_OTG_MODE_IDLE); } else { - /* A device and B cable detach --> Host mode */ + /* B cable detach in A device --> Host mode */ p_mess->ipp = usb_hstd_get_usb_ip_adr(p_mess->ip); usb_pstd_otg_mode_to_host(p_mess); if (USB_IP0 == p_mess->ip) @@ -781,12 +783,17 @@ static void usb_pstd_otg_mode_to_host (usb_utr_t * p_utr) static void usb_pstd_otg_hnp_process (usb_utr_t * p_utr) { uint16_t i; + uint16_t usb_reg; + uint8_t is_otg_hnp_possible = USB_NO; p_utr->ipp = (usb_regadr_t) usb_hstd_get_usb_ip_adr(p_utr->ip); /* Get the USB IP base address. */ /* D+ Pullup Off */ hw_usb_pclear_dprpu(p_utr->ip); + g_usb_otg_hnp_counter = 0; + tx_timer_activate(&g_usb_otg_hnp_timer); + /* Change to Host mode */ hw_usb_set_dcfm(p_utr); @@ -813,10 +820,20 @@ static void usb_pstd_otg_hnp_process (usb_utr_t * p_utr) /* Wait 3ms */ usb_cpu_delay_xms((uint16_t) 3); - if ((USB_YES == g_usb_is_otg_attach_interrupt[p_utr->ip]) || - ((USB_YES == g_is_A_device[p_utr->ip]) && (USB_NO == g_is_A_cable_detach[p_utr->ip]))) + g_usb_otg_hnp_counter = 0; + if (g_usb_otg_hnp_counter <= USB_OTG_SE0_BRST) + { + is_otg_hnp_possible = USB_YES; + } + + tx_timer_deactivate(&g_usb_otg_hnp_timer); + + if (((USB_YES == g_usb_is_otg_attach_interrupt[p_utr->ip]) || + ((USB_YES == g_is_A_device[p_utr->ip]) && (USB_NO == g_is_A_cable_detach[p_utr->ip]))) && + (USB_YES == is_otg_hnp_possible)) { g_usb_is_otg_attach_interrupt[p_utr->ip] = USB_NO; + is_otg_hnp_possible = USB_NO; /* USB Peripheral --> USB Host */ @@ -902,7 +919,31 @@ static void usb_pstd_otg_hnp_process (usb_utr_t * p_utr) g_usb_usbmode[p_utr->ip] = USB_MODE_PERI; p_utr->ipp->INTENB0 = (USB_BEMPE | USB_BRDYE | USB_VBSE | USB_DVSE | USB_CTRE); - (*g_p_otg_callback[p_utr->ip])(UX_OTG_MODE_IDLE); + + if (USB_YES == g_is_A_device[p_utr->ip]) + { + usb_reg = hw_usb_read_syssts(p_utr); + if (0 == (usb_reg & USB_IDMON)) + { + (*g_p_otg_callback[p_utr->ip])(UX_OTG_MODE_SLAVE); + } + else + { + (*g_p_otg_callback[p_utr->ip])(UX_OTG_MODE_IDLE); + } + } + else + { + usb_reg = hw_usb_read_intsts(p_utr->ip); + if (USB_VBSTS == (usb_reg & USB_VBSTS)) + { + (*g_p_otg_callback[p_utr->ip])(UX_OTG_MODE_SLAVE); + } + else + { + (*g_p_otg_callback[p_utr->ip])(UX_OTG_MODE_IDLE); + } + } } _ux_utility_thread_resume(&g_hcd_tsk_hdl); @@ -1991,7 +2032,7 @@ void usb_peri_devdefault (usb_utr_t * ptr, uint16_t mode, uint16_t data2) FSP_PARAMETER_NOT_USED(data2); - #if (defined(USB_CFG_PCDC_USE) | defined(USB_CFG_PHID_USE)) + #if (defined(USB_CFG_PCDC_USE) | defined(USB_CFG_PHID_USE) | defined(USB_CFG_PPRN_USE)) usb_instance_ctrl_t ctrl; #if (USB_CFG_DMA == USB_CFG_ENABLE) ctrl.p_transfer_rx = ptr->p_transfer_rx; @@ -1999,7 +2040,7 @@ void usb_peri_devdefault (usb_utr_t * ptr, uint16_t mode, uint16_t data2) #endif #endif - usb_peri_detach(ptr, USB_NULL, USB_NULL); + usb_peri_detach(ptr, USB_DEFAULT, USB_NULL); /* Connect Speed = Hi-Speed? */ if (USB_HSCONNECT == mode) @@ -2050,7 +2091,7 @@ void usb_peri_devdefault (usb_utr_t * ptr, uint16_t mode, uint16_t data2) usb_pstd_clr_pipe_table(ptr->ip); usb_peri_pipe_info(ptable, mode, len, ptr); - #if (defined(USB_CFG_PCDC_USE) | defined(USB_CFG_PHID_USE)) + #if (defined(USB_CFG_PCDC_USE) | defined(USB_CFG_PHID_USE) | defined(USB_CFG_PPRN_USE)) ctrl.module_number = ptr->ip; usb_set_event(USB_STATUS_DEFAULT, &ctrl); #endif @@ -2148,19 +2189,46 @@ void usb_peri_configured (usb_utr_t * ptr, uint16_t data1, uint16_t data2) /****************************************************************************** * Function Name : usb_peri_detach * Description : Peripheral Devices Class close function - * Arguments : usb_utr_t *ptr : Not used - * : uint16_t data1 : Not used - * : uint16_t data2 : Not used + * Arguments : usb_utr_t *ptr : Not used + * : uint16_t usb_state : USB state + * : uint16_t data2 : Not used * Return value : none ******************************************************************************/ -void usb_peri_detach (usb_utr_t * ptr, uint16_t data1, uint16_t data2) +void usb_peri_detach (usb_utr_t * ptr, uint16_t usb_state, uint16_t data2) { usb_instance_ctrl_t ctrl; + #if (BSP_CFG_RTOS == 1) + uint8_t pipe; + uint16_t intsts; + #endif /* #if (BSP_CFG_RTOS == 1) */ FSP_PARAMETER_NOT_USED(*ptr); - FSP_PARAMETER_NOT_USED(data1); FSP_PARAMETER_NOT_USED(data2); + #if (BSP_CFG_RTOS == 1) + intsts = hw_usb_read_intsts(ptr->ip); + if (USB_VBSTS == (intsts & USB_VBSTS)) + { + /* When doing the warm start PC(USB_Host), PC sends the USB Reset. * + * The following code is needed to release the waiting status of the semaphore waiting task * + * before doing the warm start. */ + if (USB_DEFAULT == usb_state) + { + for (pipe = USB_MIN_PIPE_NO; pipe < (USB_MAXPIPE_NUM + 1); pipe++) + { + g_usb_peri_usbx_is_detach[pipe] = USB_NO; + tx_semaphore_put(&g_usb_peri_usbx_sem[pipe]); + tx_semaphore_delete(&g_usb_peri_usbx_sem[pipe]); + } + + _ux_device_stack_disconnect(); + } + } + + #else /* #if (BSP_CFG_RTOS == 1) */ + FSP_PARAMETER_NOT_USED(usb_state); + #endif /* #if (BSP_CFG_RTOS == 1) */ + if (USB_TRUE == g_usb_peri_connected) { g_usb_peri_connected = USB_FALSE; @@ -2271,7 +2339,7 @@ void usb_pvnd_read_complete (usb_utr_t * mess, uint16_t data1, uint16_t data2) /* Set Receive data length */ ctrl.data_size = mess->read_req_len - mess->tranlen; ctrl.pipe = (uint8_t) mess->keyword; /* Pipe number setting */ - ctrl.type = USB_CLASS_INTERNAL_PVND; /* Device class setting */ + ctrl.type = USB_CLASS_PVND; /* Device class setting */ #if (BSP_CFG_RTOS != 0) ctrl.p_data = (void *) mess->cur_task_hdl; #endif /* (BSP_CFG_RTOS != 0) */ @@ -2321,7 +2389,7 @@ void usb_pvnd_write_complete (usb_utr_t * mess, uint16_t data1, uint16_t data2) usb_instance_ctrl_t ctrl; ctrl.pipe = (uint8_t) mess->keyword; /* Pipe number setting */ - ctrl.type = USB_CLASS_INTERNAL_PVND; /* CDC Control class */ + ctrl.type = USB_CLASS_PVND; /* CDC Control class */ if (USB_DATA_NONE == mess->status) { ctrl.status = FSP_SUCCESS; diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_plibusbip.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_plibusbip.c index 3cf74a32b..f84801cde 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_plibusbip.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_plibusbip.c @@ -45,6 +45,10 @@ #endif /* defined(USB_CFG_PCDC_USE) */ #endif /* defined(USB_CFG_OTG_USE) */ +#if defined(USB_CFG_PPRN_USE) + #include "r_usb_pprn_cfg.h" +#endif /* defined(USB_CFG_PPRN_USE) */ + #if defined(USB_CFG_PHID_USE) #include "r_usb_phid_cfg.h" #endif /* defined(USB_CFG_PHID_USE) */ @@ -1381,6 +1385,23 @@ uint8_t usb_pstd_get_pipe_no (uint8_t type, uint8_t dir, usb_utr_t * p_utr, uint } #endif /* defined(USB_CFG_PCDC_USE) */ + #if defined(USB_CFG_PPRN_USE) + if (USB_IFCLS_PRN == class_info) + { + if (USB_EP_BULK == type) + { + if (USB_PIPE_DIR_IN == dir) + { + pipe_no = USB_CFG_PPRN_BULK_IN; + } + else + { + pipe_no = USB_CFG_PPRN_BULK_OUT; + } + } + } + #endif /* defined(USB_CFG_PPRN_USE) */ + #if defined(USB_CFG_PHID_USE) if (USB_IFCLS_HID == class_info) { @@ -1388,13 +1409,39 @@ uint8_t usb_pstd_get_pipe_no (uint8_t type, uint8_t dir, usb_utr_t * p_utr, uint { if (USB_PIPE_DIR_IN == dir) { - pipe_no = USB_CFG_PHID_INT_IN; + if (USB_FALSE == g_usb_pipe_table[p_utr->ip][USB_CFG_PHID_INT_IN].use_flag) + { + pipe_no = USB_CFG_PHID_INT_IN; /* Set Free pipe */ + } + + #if (USB_NULL != USB_CFG_PHID_INT_IN2) + else if (USB_FALSE == g_usb_pipe_table[p_utr->ip][USB_CFG_PHID_INT_IN2].use_flag) + { + pipe_no = USB_CFG_PHID_INT_IN2; /* Set Free pipe */ + } + else + { + /* Error */ + } + #endif /* #if (USB_NULL != USB_CFG_PCDC_INT_IN2) */ } else { - #if (BSP_CFG_RTOS != 1) - pipe_no = USB_CFG_PHID_INT_OUT; - #endif /* #if (BSP_CFG_RTOS != 1) */ + if (USB_FALSE == g_usb_pipe_table[p_utr->ip][USB_CFG_PHID_INT_OUT].use_flag) + { + pipe_no = USB_CFG_PHID_INT_OUT; /* Set Free pipe */ + } + + #if ((USB_NULL != USB_CFG_PHID_INT_OUT2) && (BSP_CFG_RTOS != 1)) + else if (USB_FALSE == g_usb_pipe_table[p_utr->ip][USB_CFG_PHID_INT_OUT2].use_flag) + { + pipe_no = USB_CFG_PHID_INT_OUT2; /* Set Free pipe */ + } + else + { + /* Error */ + } + #endif /* #if ((USB_NULL != USB_CFG_PHID_INT_OUT2) && (BSP_CFG_RTOS != 1)) */ } } } @@ -1546,6 +1593,28 @@ uint16_t usb_pstd_get_pipe_buf_value (uint16_t pipe_no) } #endif /* defined(USB_CFG_PCDC_USE) */ + #if defined(USB_CFG_PPRN_USE) + case USB_CFG_PPRN_BULK_IN: + { + #if USB_CFG_DTC == USB_CFG_ENABLE + pipe_buf = (USB_BUF_SIZE(1024U) | USB_BUF_NUMB(8U)); + #else /* USB_CFG_DTC == USB_CFG_ENABLE */ + pipe_buf = (USB_BUF_SIZE(2048U) | USB_BUF_NUMB(8U)); + #endif /* USB_CFG_DTC == USB_CFG_ENABLE */ + break; + } + + case USB_CFG_PPRN_BULK_OUT: + { + #if USB_CFG_DTC == USB_CFG_ENABLE + pipe_buf = (USB_BUF_SIZE(1024U) | USB_BUF_NUMB(36U)); + #else /* USB_CFG_DTC == USB_CFG_ENABLE */ + pipe_buf = (USB_BUF_SIZE(2048U) | USB_BUF_NUMB(72U)); + #endif /* USB_CFG_DTC == USB_CFG_ENABLE */ + break; + } + #endif /* defined(USB_CFG_PPRN_USE) */ + #if defined(USB_CFG_PMSC_USE) case USB_CFG_PMSC_BULK_IN: { diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_psignal.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_psignal.c index c9c94a6c0..e016b8771 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_psignal.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_psignal.c @@ -187,7 +187,7 @@ void usb_pstd_detach_process (usb_utr_t * p_utr) /* Callback */ if (USB_NULL != g_usb_pstd_driver.devdetach) { - (*g_usb_pstd_driver.devdetach)(p_utr, USB_NO_ARG, USB_NULL); + (*g_usb_pstd_driver.devdetach)(p_utr, USB_POWERED, USB_NULL); } usb_pstd_stop_clock(p_utr->ip); diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_pstdfunction.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_pstdfunction.c index 9c1a5ce8e..17549c079 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_pstdfunction.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_pstdfunction.c @@ -52,7 +52,7 @@ ******************************************************************************/ #if (BSP_CFG_RTOS == 1) -static uint8_t * g_p_usbx_string_table[NUM_STRING_DESC]; +static uint8_t * g_p_usbx_string_table[NUM_STRING_DESC]; usb_descriptor_t g_usbx_descriptor; void usb_pstd_ux_descriptor_to_basic(usb_cfg_t * p_cfg); @@ -211,6 +211,20 @@ void usb_pstd_ux_descriptor_to_basic (usb_cfg_t * p_cfg) break; } + case USB_SOFT_CHANGE: + { + if (USB_SPEED_FS == p_cfg->usb_speed) + { + p_cfg->p_usb_reg->p_config_f = p; + } + else + { + p_cfg->p_usb_reg->p_config_h = p; + } + + break; + } + case USB_DT_OTHER_SPEED_CONF: { if (USB_SPEED_FS == p_cfg->usb_speed) @@ -241,6 +255,30 @@ void usb_pstd_ux_descriptor_to_basic (usb_cfg_t * p_cfg) p = p + length; } + if (USB_SPEED_HS == p_cfg->usb_speed) + { + start_address = (uint8_t *) (_ux_system_slave->ux_system_slave_device_framework_full_speed); + length = _ux_system_slave->ux_system_slave_device_framework_length_full_speed; + + end_address = (start_address + length); + + p = start_address; + if (USB_NULL != p) + { + while (p < end_address) + { + if ((USB_DT_OTHER_SPEED_CONF == *(p + 1)) || (USB_SOFT_CHANGE == *(p + 1))) + { + p_cfg->p_usb_reg->p_config_f = p; + break; + } + + length = *p; + p = p + length; + } + } + } + if (USB_NULL != _ux_system_slave->ux_system_slave_language_id_framework) { g_p_usbx_string_table[0] = _ux_system_slave->ux_system_slave_language_id_framework; diff --git a/ra/fsp/src/r_usb_basic/src/driver/r_usb_pstdrequest.c b/ra/fsp/src/r_usb_basic/src/driver/r_usb_pstdrequest.c index b3f05917a..2682c0aa5 100644 --- a/ra/fsp/src/r_usb_basic/src/driver/r_usb_pstdrequest.c +++ b/ra/fsp/src/r_usb_basic/src/driver/r_usb_pstdrequest.c @@ -447,11 +447,11 @@ static void usb_pstd_get_status1 (usb_utr_t * p_utr) uint16_t buffer; uint16_t pipe; -#if defined (USB_CFG_OTG_USE) + #if defined(USB_CFG_OTG_USE) if ((0 == g_usb_pstd_req_value) && (1 == g_usb_pstd_req_length)) -#else + #else if ((0 == g_usb_pstd_req_value) && (2 == g_usb_pstd_req_length)) -#endif + #endif { tbl[0] = 0; tbl[1] = 0; @@ -1539,24 +1539,35 @@ static void usb_pstd_set_interface3 (usb_utr_t * p_utr) if ((USB_TRUE == usb_pstd_chk_configured(p_utr)) && (USB_INTERFACE == (g_usb_pstd_req_type & USB_BMREQUESTTYPERECIP))) { + #if defined(USB_CFG_PPRN_USE) + if (((1 == usb_pstd_get_interface_num()) && (0 == usb_pstd_get_alternate_num(0))) && + ((0 == g_usb_pstd_req_index) && (0 == g_usb_pstd_req_value))) + { + /* Do nothing about alternate setting */ + usb_cstd_set_buf(p_utr, (uint16_t) USB_PIPE0); + + return; + } + + #else /* defined(USB_CFG_PPRN_USE) */ if ((g_usb_pstd_req_index <= usb_pstd_get_interface_num()) && (0 == g_usb_pstd_req_length)) { if (g_usb_pstd_req_value <= usb_pstd_get_alternate_num(g_usb_pstd_req_index)) { - #ifdef USB_CFG_PAUD_USE + #ifdef USB_CFG_PAUD_USE current_alt_value = g_usb_pstd_alt_num[g_usb_pstd_req_index]; - #endif // USB_CFG_PAUD_USE + #endif // USB_CFG_PAUD_USE g_usb_pstd_alt_num[g_usb_pstd_req_index] = (uint16_t) (g_usb_pstd_req_value & USB_ALT_SET); usb_cstd_set_buf(p_utr, (uint16_t) USB_PIPE0); usb_pstd_clr_eptbl_index(); /* Search endpoint setting */ usb_pstd_set_eptbl_index(g_usb_pstd_req_index, g_usb_pstd_alt_num[g_usb_pstd_req_index]); - #ifndef USB_CFG_PAUD_USE + #ifndef USB_CFG_PAUD_USE usb_pstd_set_pipe_reg(p_utr); - #endif /* USB_CFG_PAUD_USE */ - #if BSP_CFG_RTOS == 1 - #ifdef USB_CFG_PAUD_USE + #endif /* USB_CFG_PAUD_USE */ + #if BSP_CFG_RTOS == 1 + #ifdef USB_CFG_PAUD_USE if (0 == (g_usb_pstd_req_value & USB_ALT_SET)) { if (current_alt_value == 1) @@ -1566,9 +1577,9 @@ static void usb_pstd_set_interface3 (usb_utr_t * p_utr) tx_semaphore_put(&g_usb_peri_usbx_sem[pipe]); } } - #endif // USB_CFG_PAUD_USE + #endif // USB_CFG_PAUD_USE _ux_device_stack_alternate_setting_set((ULONG) g_usb_pstd_req_index, (ULONG) g_usb_pstd_req_value); - #endif + #endif } else { @@ -1576,6 +1587,7 @@ static void usb_pstd_set_interface3 (usb_utr_t * p_utr) usb_pstd_set_stall_pipe0(p_utr); } } + #endif /* defined(USB_CFG_PPRN_USE) */ else { /* Request error */ diff --git a/ra/fsp/src/r_usb_basic/src/hw/r_usb_creg_access.c b/ra/fsp/src/r_usb_basic/src/hw/r_usb_creg_access.c index de82a50e8..da4facc3c 100644 --- a/ra/fsp/src/r_usb_basic/src/hw/r_usb_creg_access.c +++ b/ra/fsp/src/r_usb_basic/src/hw/r_usb_creg_access.c @@ -526,7 +526,8 @@ uint16_t hw_usb_read_dvstctr (usb_utr_t * ptr) else { #if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) - result = (ptr->ipp->DVSTCTR0); + ptr->ipp = usb_hstd_get_usb_ip_adr(ptr->ip); + result = (ptr->ipp->DVSTCTR0); #endif /* (USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST */ } diff --git a/ra/fsp/src/r_usb_basic/src/hw/r_usb_hreg_access.c b/ra/fsp/src/r_usb_basic/src/hw/r_usb_hreg_access.c index f45f4ea3d..6825dfda7 100644 --- a/ra/fsp/src/r_usb_basic/src/hw/r_usb_hreg_access.c +++ b/ra/fsp/src/r_usb_basic/src/hw/r_usb_hreg_access.c @@ -821,8 +821,16 @@ void hw_usb_hmodule_init (uint8_t usb_ip) } } - USB_M0->INTSTS1 &= ((~USB_OVRCRE) & INTSTS1_MASK); - USB_M0->INTENB0 = ((USB_BEMPE | USB_NRDYE) | USB_BRDYE); + /* + * When R_USB_Open function was called immediately after calling R_USB_Close function, + * D+ line keeps High level since VBUS shifts to High level before USB Periheral Device recognizes VBUS Low, + * The Attach interrupt is genrated since D+ line keeps High level. + * When "INTSTS1 = 0" is described code, the Attach interrupt is canceled. "INTSTS1 = 0" is NG. + * The following code(INTSTS1) is correct. + */ + USB_M0->INTSTS1 = ((~USB_OVRCRE) & INTSTS1_MASK); + + USB_M0->INTENB0 = ((USB_BEMPE | USB_NRDYE) | USB_BRDYE); #if !defined(USB_CFG_OTG_USE) USB_M0->INTENB1 = (USB_OVRCRE | USB_ATTCH); #endif /* !defined (USB_CFG_OTG_USE) */ @@ -943,7 +951,15 @@ void hw_usb_hmodule_init (uint8_t usb_ip) } } - USB_M1->INTSTS1 = 0; + /* + * When R_USB_Open function was called immediately after calling R_USB_Close function, + * D+ line keeps High level since VBUS shifts to High level before USB Periheral Device recognizes VBUS Low, + * The Attach interrupt is genrated since D+ line keeps High level. + * When "INTSTS1 = 0" is described code, the Attach interrupt is canceled. "INTSTS1 = 0" is NG. + * The following code(INTSTS1) is correct. + */ + USB_M1->INTSTS1 = (~USB_OVRCRE & INTSTS1_MASK); + USB_M1->INTENB0 = (USB_BEMPE | USB_NRDYE | USB_BRDYE); #if defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) USB_M1->INTENB1 = (USB_OVRCRE | USB_ATTCH); diff --git a/ra/fsp/src/r_usb_basic/src/hw/r_usb_mcu.c b/ra/fsp/src/r_usb_basic/src/hw/r_usb_mcu.c index 1fc1e5d83..9bdb65a26 100644 --- a/ra/fsp/src/r_usb_basic/src/hw/r_usb_mcu.c +++ b/ra/fsp/src/r_usb_basic/src/hw/r_usb_mcu.c @@ -79,11 +79,13 @@ #if !defined(USB_CFG_OTG_USE) #if USB_CFG_MODE == USB_CFG_HOST - #if defined(USB_CFG_PCDC_USE) || defined(USB_CFG_PHID_USE) || defined(USB_CFG_PMSC_USE) || defined(USB_CFG_PVND_USE) - #error Can not enable these definitions(USB_CFG_PCDC_USE/USB_CFG_PHID_USE/USB_CFG_PMSC_USE/USB_CFG_PVND_USE) \ + #if defined(USB_CFG_PCDC_USE) || defined(USB_CFG_PPRN_USE) || defined(USB_CFG_PHID_USE) || \ + defined(USB_CFG_PMSC_USE) || defined(USB_CFG_PVND_USE) + #error \ + Can not enable these definitions(USB_CFG_PCDC_USE/USB_CFG_PPRN_USE/USB_CFG_PHID_USE/USB_CFG_PMSC_USE/USB_CFG_PVND_USE) \ when setting USB_MODE_HOST to USB_CFG_MODE in r_usb_basic_cfg.h. - #endif /* defined(USB_CFG_PCDC_USE || USB_CFG_PHID_USE || USB_CFG_PMSC_USE || USB_CFG_PVND_USE) */ + #endif /* defined(USB_CFG_PCDC_USE || USB_CFG_PPRN_USE || USB_CFG_PHID_USE || USB_CFG_PMSC_USE || USB_CFG_PVND_USE) */ #endif /* USB_CFG_MODE == USB_MODE_HOST */ #if USB_CFG_MODE == USB_CFG_PERI @@ -105,7 +107,12 @@ /****************************************************************************** * Exported global variables (to be accessed by other files) ******************************************************************************/ -usb_cfg_t * host_cfg; +#if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) +static usb_cfg_t * g_p_usb_cfg_ip0; + #if defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) +static usb_cfg_t * g_p_usb_cfg_ip1; + #endif /* defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) */ +#endif /* ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) */ /****************************************************************************** * Private global variables and functions @@ -123,6 +130,7 @@ static usb_utr_t g_usb_irq_otg_msg; static usb_utr_t g_usb_otg_detach_msg; static uint16_t g_usb_otg_frmnum_prev = 0; volatile uint8_t g_usb_otg_chattering_counter = 0; +volatile uint8_t g_usb_otg_hnp_counter = 0; #endif /* defined(USB_CFG_OTG_USE) */ /****************************************************************************** @@ -367,7 +375,10 @@ void usb_cpu_usbint_init (uint8_t ip_type, usb_cfg_t const * const cfg) R_BSP_IrqCfgEnable(cfg->irq_r, cfg->ipl_r, (void *) cfg); /* USBR enable */ R_BSP_IrqCfgEnable(cfg->irq, cfg->ipl, (void *) cfg); /* USBI enable */ - host_cfg = (usb_cfg_t *) cfg; + +#if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) + g_p_usb_cfg_ip0 = (usb_cfg_t *) cfg; +#endif /*((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST)*/ } if (ip_type == USB_IP1) @@ -391,7 +402,9 @@ void usb_cpu_usbint_init (uint8_t ip_type, usb_cfg_t const * const cfg) #endif /* ((USB_CFG_DTC == USB_CFG_ENABLE) || (USB_CFG_DMA == USB_CFG_ENABLE)) */ R_BSP_IrqCfgEnable(cfg->hsirq, cfg->hsipl, (void *) cfg); /* USBIR enable */ - host_cfg = (usb_cfg_t *) cfg; + #if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) + g_p_usb_cfg_ip1 = (usb_cfg_t *) cfg; + #endif /*((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST)*/ #endif /* defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) */ } } @@ -462,7 +475,10 @@ void usb_cpu_int_enable (void) * b6 IEN6 Interrupt enable bit * b7 IEN7 Interrupt enable bit */ - R_BSP_IrqCfgEnable(host_cfg->irq, host_cfg->ipl, host_cfg); /* USBI enable */ + if (USB_MODE_HOST == g_p_usb_cfg_ip0->usb_mode) + { + R_BSP_IrqCfgEnable(g_p_usb_cfg_ip0->irq, g_p_usb_cfg_ip0->ipl, g_p_usb_cfg_ip0); /* USBI enable */ + } #if defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) @@ -476,7 +492,10 @@ void usb_cpu_int_enable (void) * b6 IEN6 Interrupt enable bit * b7 IEN7 Interrupt enable bit */ - R_BSP_IrqCfgEnable(host_cfg->hsirq, host_cfg->hsipl, host_cfg); /* USBIR enable */ + if (USB_MODE_HOST == g_p_usb_cfg_ip1->usb_mode) + { + R_BSP_IrqCfgEnable(g_p_usb_cfg_ip1->hsirq, g_p_usb_cfg_ip1->hsipl, g_p_usb_cfg_ip1); /* USBIR enable */ + } #endif /* defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) */ } @@ -502,7 +521,10 @@ void usb_cpu_int_disable (void) * b6 IEN6 Interrupt enable bit * b7 IEN7 Interrupt enable bit */ - R_BSP_IrqDisable(host_cfg->irq); /* USBI enable */ + if (USB_MODE_HOST == g_p_usb_cfg_ip0->usb_mode) + { + R_BSP_IrqDisable(g_p_usb_cfg_ip0->irq); /* USBI enable */ + } #if defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) @@ -516,7 +538,10 @@ void usb_cpu_int_disable (void) * b6 IEN6 Interrupt enable bit * b7 IEN7 Interrupt enable bit */ - R_BSP_IrqDisable(host_cfg->hsirq); /* USBIR enable */ + if (USB_MODE_HOST == g_p_usb_cfg_ip1->usb_mode) + { + R_BSP_IrqDisable(g_p_usb_cfg_ip1->hsirq); /* USBIR enable */ + } #endif /* defined(BSP_MCU_GROUP_RA6M3) || defined(BSP_MCU_GROUP_RA6M5) */ } @@ -751,6 +776,18 @@ VOID usb_otg_chattering_timer (ULONG args) g_usb_otg_chattering_counter++; } +/******************************************************************************* + * Function Name: usb_otg_hnp_timer (10ms interval) + * Description : The timer to detect that USB B-cable is detached when A device is Peripheral mode for USB IP0 + * Arguments : args : No use + * Return Value : none + *******************************************************************************/ +VOID usb_otg_hnp_timer (ULONG args) +{ + (void) args; + g_usb_otg_hnp_counter++; +} + #if USB_NUM_USBIP == 2 /******************************************************************************* diff --git a/ra/fsp/src/r_usb_composite/r_usb_phid_phid_descriptor.c.template b/ra/fsp/src/r_usb_composite/r_usb_phid_phid_descriptor.c.template new file mode 100644 index 000000000..ce6b975f6 --- /dev/null +++ b/ra/fsp/src/r_usb_composite/r_usb_phid_phid_descriptor.c.template @@ -0,0 +1,368 @@ +/* ${REA_DISCLAIMER_PLACEHOLDER} */ +/****************************************************************************** + Includes , "Project Includes" + ******************************************************************************/ +#include "r_usb_basic_api.h" +#include "r_usb_phid_api.h" + +/****************************************************************************** + Macro definitions + ******************************************************************************/ +#define USB_BCDNUM (0x0200U) /* bcdUSB */ +#define USB_RELEASE (0x0200U) /* Release Number */ +#define USB_CONFIGNUM (1U) /* Configuration number */ +#define USB_DCPMAXP (64U) /* DCP max packet size */ + +#define USB_IFPROTOCOL (USB_IFPRO_KBD) +#define ITEM_LEN (76U) +#define ITEM_LEN2 (50U) + +#define MXPS (8U) +#define NUM_EP (1U) + +/* [Vendor ID & Product ID setting] */ +#define USB_VENDORID (0x0000U) +#define USB_PRODUCTID (0x0013U) + +/* Descriptor length */ +#define NUM_STRING_DESCRIPTOR (6U) +/* Configuration Descriptor Length */ +#define CD_LEN (59U) + +/* Descriptor data Mask */ +#define USB_UCHAR_MAX (0xffU) +#define USB_W_TOTAL_LENGTH_MASK (256U) +#define USB_VALUE_32 (32) +#define USB_VALUE_100 (100) +#define USB_UCHAR_MAX (0xffU) +#define USB_VALUE_22H (0x22U) +#define USB_VALUE_25H (0x25U) +#define USB_VALUE_26H (0x26U) +#define USB_VALUE_29H (0x29U) +#define USB_VALUE_30H (0x30U) +#define USB_VALUE_31H (0x31U) +#define USB_VALUE_65H (0x65U) +#define USB_VALUE_75H (0x75U) +#define USB_VALUE_7FH (0x7FU) +#define USB_VALUE_95H (0x95U) +#define USB_VALUE_81H (0x81U) +#define USB_VALUE_91H (0x91U) +#define USB_VALUE_A1H (0xA1U) +#define USB_VALUE_C0H (0xC0U) +#define USB_VALUE_E7H (0xE7U) +#define USB_VALUE_FFH (0xFFU) + +/************************************************************ + * Device Descriptor * + ************************************************************/ +uint8_t g_apl_device[] = +{ + USB_DD_BLENGTH, /* 0:bLength */ + USB_DT_DEVICE, /* 1:bDescriptorType */ + (uint8_t) ( USB_BCDNUM & (uint8_t) USB_UCHAR_MAX), /* 2:bcdUSB_lo */ + (uint8_t) ((uint8_t) (USB_BCDNUM >> 8) & (uint8_t) USB_UCHAR_MAX), /* 3:bcdUSB_hi */ + 0x00, /* 4:bDeviceClass */ + 0x00, /* 5:bDeviceSubClass */ + 0x00, /* 6:bDeviceProtocol */ + (uint8_t) USB_DCPMAXP, /* 7:bMAXPacketSize(for DCP) */ + (uint8_t) (USB_VENDORID & (uint8_t) USB_UCHAR_MAX), /* 8:idVendor_lo */ + (uint8_t) ((uint8_t) (USB_VENDORID >> 8) & (uint8_t) USB_UCHAR_MAX), /* 9:idVendor_hi */ + (uint8_t) (USB_PRODUCTID & (uint8_t) USB_UCHAR_MAX), /* 10:idProduct_lo */ + (uint8_t) ((uint8_t) (USB_PRODUCTID >> 8) & (uint8_t) USB_UCHAR_MAX),/* 11:idProduct_hi */ + (uint8_t) (USB_RELEASE & (uint8_t) USB_UCHAR_MAX), /* 12:bcdDevice_lo */ + (uint8_t) ((uint8_t) (USB_RELEASE >> 8) & (uint8_t) USB_UCHAR_MAX), /* 13:bcdDevice_hi */ + 1, /* 14:iManufacturer */ + 2, /* 15:iProduct */ + 3, /* 16:iSerialNumber */ + USB_CONFIGNUM, /* 17:bNumConfigurations */ +}; + +/************************************************************ + * Configuration Descriptor * + ************************************************************/ +uint8_t g_apl_configuration[CD_LEN + (CD_LEN % 2)] = +{ + USB_CD_BLENGTH, /* 0:bLength */ + USB_DT_CONFIGURATION, /* 1:bDescriptorType */ + (uint8_t) (CD_LEN % USB_W_TOTAL_LENGTH_MASK), /* 2:wTotalLength(L) */ + (uint8_t) (CD_LEN / USB_W_TOTAL_LENGTH_MASK), /* 3:wTotalLength(H) */ + 2, /* 4:bNumInterfaces */ + 1, /* 5:bConfigurationValue */ + 4, /* 6:iConfiguration */ + (uint8_t) (USB_CF_RESERVED | USB_CF_SELFP | USB_CF_RWUPON), /* 7:bmAttributes */ + (uint8_t) (USB_VALUE_100 / 2), /* 8:bMaxPower (2mA unit) */ + + /* Interface Descriptor */ + USB_ID_BLENGTH, /* 0:bLength */ + USB_DT_INTERFACE, /* 1:bDescriptor */ + 0, /* 2:bInterfaceNumber */ + 0, /* 3:bAlternateSetting */ + NUM_EP, /* 4:bNumEndpoints */ + USB_IFCLS_HID, /* 5:bInterfaceClass(HID) */ + USB_IFSUB_NOBOOT, /* 6:bInterfaceSubClass(NonBOOT) */ + USB_IFPROTOCOL, /* 7:bInterfaceProtocol */ + 0, /* 8:iInterface */ + + /* HID Descriptor */ + 9, /* 0:bLength */ + USB_DT_TYPE_HIDDESCRIPTOR, /* 1:bDescriptor */ + 0x00, /* 2:HID Ver */ + 0x01, /* 3:HID Ver */ + 0x00, /* 4:bCountryCode */ + 0x01, /* 5:bNumDescriptors */ + USB_VALUE_22H, /* 6:bDescriptorType */ + ITEM_LEN, /* 7:wItemLength(L) */ + 0x00, /* 8:wItemLength(H) */ + + /* Endpoint Descriptor 0 */ + USB_ED_BLENGTH, /* 0:bLength */ + USB_DT_ENDPOINT, /* 1:bDescriptorType */ + (uint8_t) (USB_EP_IN | USB_EP1), /* 2:bEndpointAddress */ + USB_EP_INT, /* 3:bmAttribute */ + MXPS, /* 4:wMaxPacketSize_lo */ + 0, /* 5:wMaxPacketSize_hi */ + 0x0A, /* 6:bInterval */ + +/* Human Iterface Device Class2 */ + + /* Interface Descriptor */ + USB_ID_BLENGTH, /* 0:bLength */ + USB_DT_INTERFACE, /* 1:bDescriptor */ + 1, /* 2:bInterfaceNumber */ + 0, /* 3:bAlternateSetting */ + NUM_EP, /* 4:bNumEndpoints */ + USB_IFCLS_HID, /* 5:bInterfaceClass(HID) */ + USB_IFSUB_NOBOOT, /* 6:bInterfaceSubClass(NonBOOT) */ + USB_IFPRO_MSE, /* 7:bInterfaceProtocol */ + 0, /* 8:iInterface */ + + /* HID Descriptor */ + 9, /* 0:bLength */ + USB_DT_TYPE_HIDDESCRIPTOR, /* 1:bDescriptor */ + 0x00, /* 2:HID Ver */ + 0x01, /* 3:HID Ver */ + 0x00, /* 4:bCountryCode */ + 0x01, /* 5:bNumDescriptors */ + USB_VALUE_22H, /* 6:bDescriptorType */ + ITEM_LEN2, /* 7:wItemLength(L) */ + 0x00, /* 8:wItemLength(H) */ + + /* Endpoint Descriptor 1 */ + USB_ED_BLENGTH, /* 0:bLength */ + USB_DT_ENDPOINT, /* 1:bDescriptorType */ + (uint8_t) (USB_EP_IN | USB_EP2), /* 2:bEndpointAddress */ + USB_EP_INT, /* 3:bmAttribute */ + MXPS, /* 4:wMaxPacketSize_lo */ + 0, /* 5:wMaxPacketSize_hi */ + 0x0A, /* 6:bInterval */ +} ; + +/************************************************************ + * String Descriptor 0 * + ************************************************************/ +/* UNICODE 0x0409 English (United States) */ +uint8_t g_apl_string0[] = +{ + 4, /* 0:bLength */ + USB_DT_STRING, /* 1:bDescriptorType */ + 0x09, 0x04 /* 2:wLANGID[0] */ +}; + +/************************************************************ + * String Descriptor 1 * + ************************************************************/ +/* 14:iManufacturer */ +uint8_t g_apl_string1[] = +{ + 16, /* 0:bLength */ + USB_DT_STRING, /* 1:bDescriptorType */ + 'R', 0x00, + 'e', 0x00, + 'n', 0x00, + 'e', 0x00, + 's', 0x00, + 'a', 0x00, + 's', 0x00, +}; + +/************************************************************ + * String Descriptor 2 * + ************************************************************/ +/* 15:iProduct */ + +uint8_t g_apl_string2[] = +{ + USB_VALUE_32, /* 0:bLength */ + USB_DT_STRING, /* 1:bDescriptorType */ + 'U', 0x00, + 'S', 0x00, + 'B', 0x00, + ' ', 0x00, + 'P', 0x00, + 'e', 0x00, + 'r', 0x00, + 'i', 0x00, + ' ', 0x00, + 'H', 0x00, + 'I', 0x00, + 'D', 0x00, + ' ', 0x00, + 'F', 0x00, + 'W', 0x00, +}; + +/************************************************************ + * String Descriptor 3 * + ************************************************************/ +/* 16:iSerialNumber */ +uint8_t g_apl_string3[] = +{ + 10, /* 0:bLength */ + USB_DT_STRING, /* 1:bDescriptorType */ + 'P', 0x00, + '0', 0x00, + '0', 0x00, + '1', 0x00, +}; + +/************************************************************ + * String Descriptor 4(iConfiguration) * + ************************************************************/ +uint8_t g_apl_string4[] = +{ + 18, /* 0:bLength */ + USB_DT_STRING, /* 1:bDescriptorType */ + + /* 2:bString */ + 'K', 0x00, + 'e', 0x00, + 'y', 0x00, + 'B', 0x00, + 'o', 0x00, + 'a', 0x00, + 'r', 0x00, + 'd', 0x00 +}; + +/************************************************************ + * String Descriptor 5(iConfiguration) * + ************************************************************/ +uint8_t g_apl_string5[] = +{ + 12, /* 0:bLength */ + USB_DT_STRING, /* 1:bDescriptorType */ + + /* 2:bString */ + 'M', 0x00, + 'o', 0x00, + 'u', 0x00, + 's', 0x00, + 'e', 0x00, +}; + +/************************************************************ + * String Descriptor Table address * + ************************************************************/ +uint8_t * g_apl_string_table[] = +{ + g_apl_string0, /* UNICODE 0x0409 English (United States) */ + g_apl_string1, /* iManufacturer */ + g_apl_string2, /* iProduct */ + g_apl_string3, /* iSerialNumber */ + g_apl_string4, /* iConfiguration */ + g_apl_string5, /* iConfiguration */ +}; + +/************************************************************ + * HID Report Discriptor for Keyboard * + ************************************************************/ +const uint8_t g_apl_report[] = +{ + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, 0x06, /* Usage (Keyboard) */ + USB_VALUE_A1H, 0x01, /* Collection (Application) */ + 0x05, 0x07, /* Usage Page (Key Codes); */ + 0x19, 0xE0, /* Usage Minimum (224) */ + USB_VALUE_29H, USB_VALUE_E7H, /* Usage Maximum (231) */ + 0x15, 0x00, /* Logical Minimum (0) */ + USB_VALUE_25H, 0x01, /* Logical Maximum (1) */ + USB_VALUE_75H, 0x01, /* Report Size (1) */ + USB_VALUE_95H, 0x08, /* Report Count (8) */ + USB_VALUE_81H, 0x02, /* Input (Data , Variable , Absolute) ;Modifier byte */ + 0x95, 0x01, /* Report Count (1) */ + USB_VALUE_75H, 0x08, /* Report Size (8) */ + USB_VALUE_81H, 0x01, /* Input (Constant) ;Reserved byte */ + USB_VALUE_95H, 0x05, /* Report Count (5) */ + USB_VALUE_75H, 0x01, /* Report Size (1) */ + 0x05, 0x08, /* Usage Page (Page# for LEDs) */ + 0x19, 0x01, /* Usage Minimum (1) */ + USB_VALUE_29H, 0x05, /* Usage Maximum (5) */ + USB_VALUE_91H, 0x02, /* Output (Data , Variable , Absolute) ;LED report */ + USB_VALUE_95H, 0x01, /* Report Count (1) */ + USB_VALUE_75H, 0x03, /* Report Size (3) */ + USB_VALUE_91H, 0x01, /* Output (Constant) ;LED report padding */ + USB_VALUE_95H, 0x06, /* Report Count (6) */ + USB_VALUE_75H, 0x08, /* Report Size (8) */ + 0x15, 0x00, /* Logical Minimum (0) */ + USB_VALUE_25H, USB_VALUE_65H, /* Logical Maximum(101) */ + 0x05, 0x07, /* Usage Page (Key Codes) */ + 0x19, 0x00, /* Usage Minimum (0) */ + USB_VALUE_29H, USB_VALUE_65H, /* Usage Maximum (101) */ + USB_VALUE_81H, 0x00, /* Input (Data , Array) ;Key arrays (6 bytes) */ + + /* *** The OUTPUT REPORT *** */ + 0x09, 0x00, /* Usage ID within this page (Vendor defined)*/ + 0x15, 0x00, /* Logical Min 0 */ + USB_VALUE_26H, USB_VALUE_FFH, 0x00, /* Logical Max 255 */ + USB_VALUE_75H, 0x08, /* Size 8 Bits (Each Field will be 8bits) */ + USB_VALUE_95H, 0x01, /* Count (Number of fields(bytes) in OUTPUT report) */ + USB_VALUE_91H, 0x02, /* Output Report - type variable data */ + 0xC0, /* End Collection */ +}; + +/************************************************************ + * HID Report Discriptor for Mouse * + ************************************************************/ +const uint8_t g_apl_report_mouse[] = +{ + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, 0x02, /* Usage (Mouse) */ + USB_VALUE_A1H, 0x01, /* Collection (Application) */ + 0x09, 0x01, /* Usage (Pointer) */ + USB_VALUE_A1H, 0x00, /* Collection (Physical) */ + 0x05, 0x09, /* Usage Page (Buttons) */ + 0x19, 0x01, /* Usage Minimum (01) */ + USB_VALUE_29H, 0x03, /* Usage Maximun (03) */ + 0x15, 0x00, /* Logical Minimum (0) */ + USB_VALUE_25H, 0x01, /* Logical Maximum (1) */ + USB_VALUE_95H, 0x03, /* Report Count (3) */ + USB_VALUE_75H, 0x01, /* Report Size (1) */ + USB_VALUE_81H, 0x02, /* Input (Data, Variable, Absolute); 3 button bits */ + USB_VALUE_95H, 0x01, /* Report Count (1) */ + USB_VALUE_75H, 0x05, /* Report Size (5) */ + USB_VALUE_81H, 0x01, /* Input (Constant), ;5 bit padding */ + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, USB_VALUE_30H, /* Usage (X) */ + 0x09, USB_VALUE_31H, /* Usage (Y) */ + 0x15, USB_VALUE_81H, /* Logical Minimum (-127) */ + USB_VALUE_25H, USB_VALUE_7FH, /* Logical Maximum (127) */ + USB_VALUE_75H, 0x08, /* Report Size (8) */ + USB_VALUE_95H, 0x02, /* Report Count (2) */ + USB_VALUE_81H, 0x06, /* Input (Data,Variable,Relative): 2position bytes(X & Y) */ + USB_VALUE_C0H, /* End Collection */ + USB_VALUE_C0H, /* End Collection */ +}; + +const usb_descriptor_t g_usb_descriptor = +{ + g_apl_device, /* Pointer to the device descriptor */ + g_apl_configuration, /* Pointer to the configuration descriptor for Full-speed */ + NULL, /* Pointer to the configuration descriptor for Hi-speed */ + NULL, /* Pointer to the qualifier descriptor */ + g_apl_string_table, /* Pointer to the string descriptor table */ + NUM_STRING_DESCRIPTOR +}; + +/****************************************************************************** + End Of File + ******************************************************************************/ diff --git a/ra/fsp/src/r_usb_phid/src/r_usb_phid_driver.c b/ra/fsp/src/r_usb_phid/src/r_usb_phid_driver.c index 7cbd306e1..fc3e09bd9 100644 --- a/ra/fsp/src/r_usb_phid/src/r_usb_phid_driver.c +++ b/ra/fsp/src/r_usb_phid/src/r_usb_phid_driver.c @@ -75,7 +75,17 @@ void usb_phid_write_complete (usb_utr_t * mess, uint16_t data1, uint16_t data2) ctrl.pipe = (uint8_t) mess->keyword; /* Pipe number setting */ ctrl.module_number = mess->ip; - ctrl.type = USB_CLASS_PHID; /* HID Data class */ + +// ctrl.type = USB_CLASS_PHID; /* HID Data class */ + if (USB_CFG_PHID_INT_IN == ctrl.pipe) + { + ctrl.type = USB_CLASS_PHID; /* Device class setting */ + } + else + { + ctrl.type = USB_CLASS_PHID2; /* Device class setting */ + } + if (USB_DATA_NONE == mess->status) { ctrl.status = FSP_SUCCESS; @@ -116,7 +126,16 @@ void usb_phid_read_complete (usb_utr_t * mess, uint16_t data1, uint16_t data2) ctrl.pipe = (uint8_t) mess->keyword; /* Pipe number setting */ ctrl.module_number = mess->ip; - ctrl.type = USB_CLASS_PHID; /* Device class setting */ +// ctrl.type = USB_CLASS_PHID; /* Device class setting */ + if (USB_CFG_PHID_INT_OUT == ctrl.pipe) + { + ctrl.type = USB_CLASS_PHID; /* Device class setting */ + } + else + { + ctrl.type = USB_CLASS_PHID2; /* Device class setting */ + } + switch (mess->status) { case USB_DATA_OK: diff --git a/ra/fsp/src/r_usb_pmsc/src/r_media_driver_api.c b/ra/fsp/src/r_usb_pmsc/src/r_media_driver_api.c index 6d2b63cbc..7a0556dce 100644 --- a/ra/fsp/src/r_usb_pmsc/src/r_media_driver_api.c +++ b/ra/fsp/src/r_usb_pmsc/src/r_media_driver_api.c @@ -301,7 +301,7 @@ void r_usb_pmsc_block_media_event_callback (rm_block_media_callback_args_t * p_a } } -static void r_usb_pmsc_block_media_operation_event () +static void r_usb_pmsc_block_media_operation_event (void) { uint32_t timeout = UINT32_MAX; while (timeout > 0) diff --git a/ra/fsp/src/rm_ble_abs/rm_ble_abs.c b/ra/fsp/src/rm_ble_abs/rm_ble_abs.c index f51809442..979288ca5 100644 --- a/ra/fsp/src/rm_ble_abs/rm_ble_abs.c +++ b/ra/fsp/src/rm_ble_abs/rm_ble_abs.c @@ -4619,7 +4619,7 @@ static void ble_abs_timer_remove_timer (ble_abs_instance_ctrl_t * const p_instan p_instance_ctrl->timer[timer_hdl].status = BLE_TIMER_STATUS_IDLE; } -static void ble_abs_timer_event_cb () +static void ble_abs_timer_event_cb (void) { ble_abs_instance_ctrl_t * p_instance_ctrl = gp_instance_ctrl; diff --git a/ra/fsp/src/rm_ble_abs_spp/r_ble_spp_api.c b/ra/fsp/src/rm_ble_abs_spp/r_ble_spp_api.c index fa476af1b..a41fc5215 100644 --- a/ra/fsp/src/rm_ble_abs_spp/r_ble_spp_api.c +++ b/ra/fsp/src/rm_ble_abs_spp/r_ble_spp_api.c @@ -26,7 +26,6 @@ #include #include "r_ble_api.h" #include "r_ble_spp.h" -#include "r_uart_api.h" #include "qe_ble_profile.h" #if (BSP_CFG_RTOS == 2) #include "FreeRTOS.h" @@ -93,12 +92,22 @@ extern ble_abs_instance_ctrl_t * gp_instance_ctrl; /****************************************************************************** * Static Private Function Definitions ******************************************************************************/ -static void r_ble_spp_api_set_ryz012_communication_mode(ble_abs_spp_comms_transport_mode_t mode); -static fsp_err_t r_ble_spp_api_fsp_callback_open(void * p_context); -static fsp_err_t r_ble_spp_api_fsp_callback_write(void * p_context, uint8_t * p_data, uint32_t len); -static fsp_err_t r_ble_spp_api_fsp_callback_close(void * p_context); +static void r_ble_spp_api_set_ryz012_communication_mode(ble_abs_spp_comms_transport_mode_t mode); +static int r_ble_spp_api_fsp_callback_open(void * p_context); +static int r_ble_spp_api_fsp_callback_write(void * p_context, uint8_t * p_data, uint32_t len); + +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) +static int r_ble_spp_api_fsp_callback_read(void * const p_context, + void const * p_src, + void * p_dest, + uint32_t const len, + uint8_t const bit_width); + +#endif +static int r_ble_spp_api_fsp_callback_close(void * p_context); static void r_ble_spp_api_mw_callback(r_ble_spp_payload_t * p_payload); static ble_status_t r_ble_spp_api_check_return_valid(uint32_t expected_spp_reply); +static void r_ble_spp_api_delay_ms(uint32_t ms); /****************************************************************************** * Static Private Variables @@ -111,7 +120,7 @@ static volatile uint32_t g_spp_cmd_unknown = 0; static volatile uint32_t g_spp_cmd_failed = 0; static volatile uint32_t g_spp_cmd_async = 0; static r_ble_spp_cfg_t r_ble_spp_api_transport_api; -static volatile uint32_t g_spp_tx_data_empty = 0; +static volatile uint32_t g_transfer_complete = 0; static bool g_dynamic_profile_set; ble_gap_app_cb_t g_gap_cb = NULL; @@ -126,12 +135,24 @@ uint32_t ble_version_special = 0; /* LUT used in R_BLE_GAP_SetAdvParam */ static const uint8_t g_ch_map_lut[8] = {0, 0, 1, 0, 2, 0, 1, 3}; +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + +static volatile uint8_t g_data_ready = 0; + +#endif + /****************************************************************************** * Public Function Prototypes ******************************************************************************/ - +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_UART) void rm_ble_spp_callback(uart_callback_args_t * p_args); +#elif defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) +void rm_ble_spp_host_spi_callback(spi_callback_args_t * p_args); +void rm_ble_spp_data_ready_callback(external_irq_callback_args_t * p_args); + +#endif + /****************************************************************************** * Public Functions ******************************************************************************/ @@ -141,24 +162,32 @@ ble_status_t R_BLE_Open (void) #if BLE_ABS_CFG_PARAM_CHECKING_ENABLE FSP_ASSERT(gp_instance_ctrl); FSP_ASSERT(gp_instance_ctrl->p_cfg); + #if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_UART) FSP_ASSERT(gp_instance_ctrl->p_cfg->p_uart_instance); + #elif defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + FSP_ASSERT(gp_instance_ctrl->p_cfg->p_spi_instance); + FSP_ASSERT(gp_instance_ctrl->p_cfg->p_irq_instance); + #endif #endif - r_ble_spp_api_transport_api.p_context = (void *) gp_instance_ctrl->p_cfg->p_uart_instance; - r_ble_spp_api_transport_api.open = (int (*)(void *)) & r_ble_spp_api_fsp_callback_open; - r_ble_spp_api_transport_api.write = (int (*)(void *, uint8_t *, uint32_t)) & r_ble_spp_api_fsp_callback_write; - r_ble_spp_api_transport_api.read = NULL; - r_ble_spp_api_transport_api.close = (int (*)(void *)) & r_ble_spp_api_fsp_callback_close; + r_ble_spp_api_transport_api.p_context = (void *) gp_instance_ctrl->p_cfg; + +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_UART) + r_ble_spp_api_transport_api.config_flag = BLE_SPP_COMMS_UART; +#elif defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + r_ble_spp_api_transport_api.Read = r_ble_spp_api_fsp_callback_read; + r_ble_spp_api_transport_api.config_flag = BLE_SPP_COMMS_SPI; +#endif + r_ble_spp_api_transport_api.open = r_ble_spp_api_fsp_callback_open; + r_ble_spp_api_transport_api.write = r_ble_spp_api_fsp_callback_write; + r_ble_spp_api_transport_api.close = r_ble_spp_api_fsp_callback_close; r_ble_spp_api_transport_api.mw_callback = &r_ble_spp_api_mw_callback; - if (gp_instance_ctrl->p_cfg->p_uart_instance != NULL) - { - r_ble_spp_api_set_ryz012_communication_mode(BLE_SPP_COMMS_UART); - } - else - { - return BLE_ERR_INVALID_PTR; - } +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_UART) + r_ble_spp_api_set_ryz012_communication_mode(BLE_SPP_COMMS_UART); +#elif defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + r_ble_spp_api_set_ryz012_communication_mode(BLE_SPP_COMMS_SPI); +#endif if (R_BLE_SPP_GAP_Open(&r_ble_spp_api_transport_api) == R_BLE_SPP_SUCCESS) { @@ -290,8 +319,6 @@ ble_status_t R_BLE_GAP_SetAdvParam (st_ble_gap_adv_param_t * p_adv_param) { uint8_t chan_map; - BLE_SPP_COMMAND(R_BLE_SPP_GAP_Init(), R_BLE_SPP_EVENT_BLE_INIT); - /* Select lowest configured channel or all three */ chan_map = g_ch_map_lut[p_adv_param->adv_ch_map]; @@ -421,6 +448,8 @@ ble_status_t R_BLE_VS_SetBdAddr (uint8_t area, st_ble_dev_addr_t * p_addr) } } + BLE_SPP_COMMAND(R_BLE_SPP_GAP_Init(), R_BLE_SPP_EVENT_BLE_INIT); + return BLE_SUCCESS; } @@ -659,11 +688,7 @@ static void r_ble_spp_api_set_ryz012_communication_mode (ble_abs_spp_comms_trans R_BSP_PinAccessDisable(); /* hold RYZ012 in reset/allow power to settle */ -#if (BSP_CFG_RTOS == 2) - vTaskDelay(pdMS_TO_TICKS(BLE_MODULE_RESET_TIMEOUT)); -#else - R_BSP_SoftwareDelay(BLE_MODULE_RESET_TIMEOUT, BSP_DELAY_UNITS_MILLISECONDS); -#endif + r_ble_spp_api_delay_ms(BLE_MODULE_RESET_TIMEOUT); R_BSP_PinAccessEnable(); @@ -673,41 +698,115 @@ static void r_ble_spp_api_set_ryz012_communication_mode (ble_abs_spp_comms_trans R_BSP_PinAccessDisable(); /* Allow device to come out of reset and stabilize */ -#if (BSP_CFG_RTOS == 2) - vTaskDelay(pdMS_TO_TICKS(BLE_MODULE_STABILIZE_TIMEOUT)); -#else - R_BSP_SoftwareDelay(BLE_MODULE_STABILIZE_TIMEOUT, BSP_DELAY_UNITS_MILLISECONDS); -#endif + r_ble_spp_api_delay_ms(BLE_MODULE_STABILIZE_TIMEOUT); /* Dynamic profile can now be configured again */ g_dynamic_profile_set = false; } -static fsp_err_t r_ble_spp_api_fsp_callback_open (void * p_context) +static int r_ble_spp_api_fsp_callback_open (void * p_context) { - fsp_err_t err; - uart_instance_t * bkup_context = (uart_instance_t *) p_context; + fsp_err_t err; + ble_abs_cfg_t * bkup_context = (ble_abs_cfg_t *) p_context; +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_UART) + err = bkup_context->p_uart_instance->p_api->open(bkup_context->p_uart_instance->p_ctrl, + bkup_context->p_uart_instance->p_cfg); +#elif defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + err = bkup_context->p_spi_instance->p_api->open(bkup_context->p_spi_instance->p_ctrl, + bkup_context->p_spi_instance->p_cfg); + bkup_context->p_irq_instance->p_api->open(bkup_context->p_irq_instance->p_ctrl, + bkup_context->p_irq_instance->p_cfg); + bkup_context->p_irq_instance->p_api->enable(bkup_context->p_irq_instance->p_ctrl); +#endif - err = R_SCI_UART_Open(bkup_context->p_ctrl, bkup_context->p_cfg); + if (FSP_SUCCESS != err) + { + return R_BLE_SPP_DEVICE_NOT_OPEN; + } - return err; + return R_BLE_SPP_SUCCESS; +} + +static int r_ble_spp_api_fsp_callback_write (void * p_context, uint8_t * p_data, uint32_t len) +{ + fsp_err_t err; + g_transfer_complete = 0; + + ble_abs_cfg_t * bkup_context = (ble_abs_cfg_t *) p_context; +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + #if defined(BLE_ABS_CFG_SSL_PIN) + R_BSP_PinAccessEnable(); + + /* If the software SSL Pin is defined, then assert SSL. */ + R_BSP_PinWrite(BLE_ABS_CFG_SSL_PIN, BSP_IO_LEVEL_LOW); + + R_BSP_PinAccessDisable(); + #endif + err = bkup_context->p_spi_instance->p_api->write(bkup_context->p_spi_instance->p_ctrl, + p_data, + len, + SPI_BIT_WIDTH_8_BITS); +#else + err = bkup_context->p_uart_instance->p_api->write(bkup_context->p_uart_instance->p_ctrl, p_data, len); +#endif + + if (FSP_SUCCESS != err) + { + return R_BLE_APP_TRANSPORT_WRITE_ERROR; + } + + return R_BLE_SPP_SUCCESS; } -static fsp_err_t r_ble_spp_api_fsp_callback_write (void * p_context, uint8_t * p_data, uint32_t len) +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) +static int r_ble_spp_api_fsp_callback_read (void * const p_context, + void const * p_src, + void * p_dest, + uint32_t const len, + uint8_t const bit_width) { - fsp_err_t err; - uart_instance_t * bkup_context = (uart_instance_t *) p_context; - g_spp_tx_data_empty = 0; - err = R_SCI_UART_Write(bkup_context->p_ctrl, p_data, len); + BLE_PARAMETER_NOT_USED(bit_width); + + fsp_err_t err = FSP_SUCCESS; + #if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + #if defined(BLE_ABS_CFG_SSL_PIN) + R_BSP_PinAccessEnable(); + + /* If the software SSL Pin is defined, then assert SSL. */ + R_BSP_PinWrite(BLE_ABS_CFG_SSL_PIN, BSP_IO_LEVEL_LOW); + + R_BSP_PinAccessDisable(); + #endif + + ble_abs_cfg_t * bkup_context = (ble_abs_cfg_t *) p_context; + err = bkup_context->p_spi_instance->p_api->writeRead(bkup_context->p_spi_instance->p_ctrl, + p_src, + p_dest, + len, + SPI_BIT_WIDTH_8_BITS); + #endif + + if (FSP_SUCCESS != err) + { + return R_BLE_APP_TRANSPORT_READ_ERROR; + } + + return R_BLE_SPP_SUCCESS; return err; } -static fsp_err_t r_ble_spp_api_fsp_callback_close (void * p_context) +#endif + +static int r_ble_spp_api_fsp_callback_close (void * p_context) { - fsp_err_t err; - uart_instance_t * bkup_context = (uart_instance_t *) p_context; - err = R_SCI_UART_Close(bkup_context->p_ctrl); + fsp_err_t err = FSP_SUCCESS; + ble_abs_cfg_t * bkup_context = (ble_abs_cfg_t *) p_context; +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_UART) + err = bkup_context->p_uart_instance->p_api->close(bkup_context->p_uart_instance->p_ctrl); +#elif defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + err = bkup_context->p_spi_instance->p_api->close(bkup_context->p_spi_instance->p_ctrl); +#endif return err; } @@ -724,6 +823,23 @@ ble_status_t R_BLE_Execute (void) g_cb_event = NULL; } +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + + /* If an asynchronous command was received then the data ready pin will be asserted. */ + if (!g_data_ready) + { + return status; + } + + g_data_ready = 0; + + /* Read the event data. */ + R_BLE_SPP_SPI_Read(&g_current_spp_payload); + + /* Process the event. */ + r_ble_spp_api_mw_callback(&g_current_spp_payload); +#endif + if (g_spp_cmd_async) { switch (g_current_spp_async_payload.event_id) @@ -868,6 +984,7 @@ static void r_ble_spp_api_mw_callback (r_ble_spp_payload_t * p_payload) } } +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_UART) void rm_ble_spp_callback (uart_callback_args_t * p_args) { switch (p_args->event) @@ -880,7 +997,7 @@ void rm_ble_spp_callback (uart_callback_args_t * p_args) case UART_EVENT_TX_DATA_EMPTY: { - g_spp_tx_data_empty = 1; + g_transfer_complete = 1; break; } @@ -891,48 +1008,112 @@ void rm_ble_spp_callback (uart_callback_args_t * p_args) } } +#endif + +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) +void rm_ble_spp_host_spi_callback (spi_callback_args_t * p_args) +{ + if (p_args->event == SPI_EVENT_TRANSFER_COMPLETE) + { + #if defined(BLE_ABS_CFG_SSL_PIN) + R_BSP_PinAccessEnable(); + + /* If the software SSL Pin is defined, then negate SSL. */ + R_BSP_PinWrite(BLE_ABS_CFG_SSL_PIN, BSP_IO_LEVEL_HIGH); + + R_BSP_PinAccessDisable(); + #endif + + g_transfer_complete = 1; + } +} + +void rm_ble_spp_data_ready_callback (external_irq_callback_args_t * p_args) +{ + BLE_PARAMETER_NOT_USED(p_args); + + g_data_ready = 1; +} + +#endif + static ble_status_t r_ble_spp_api_check_return_valid (uint32_t expected_spp_reply) { uint32_t countdown = BLE_MODULE_RESET_TIMEOUT; - while (countdown && !g_spp_tx_data_empty) + /* Wait for data transmit to complete */ + while (--countdown && !g_transfer_complete) { -#if (BSP_CFG_RTOS == 2) - vTaskDelay(1); -#else - R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS); -#endif - countdown--; + r_ble_spp_api_delay_ms(1); } - while (!g_spp_cmd_ready && countdown && !g_spp_cmd_failed) - { -#if (BSP_CFG_RTOS == 2) - vTaskDelay(1); +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_UART) + + /* Wait for data receive to complete */ + while (--countdown && !g_spp_cmd_ready && !g_spp_cmd_failed) #else - R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS); + + /* Wait for the data ready pin to be asserted. */ + while (--countdown && !g_data_ready) #endif - countdown--; + { + r_ble_spp_api_delay_ms(1); } +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_UART) + + /* Check if the command response is ready. */ if (g_spp_cmd_ready) { + /* Check if the expected response was received. */ if (g_current_spp_payload.event_id != expected_spp_reply) { return BLE_ERR_HC_UNKNOWN_HCI_CMD; } } + /* Check if the command failed. */ else if (g_spp_cmd_failed) { return BLE_ERR_HC_CMD_DISALLOWED; } + +#elif defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + + /* Check if the data ready pin was asserted in response to the command. */ + if (g_data_ready) + { + /* Read the response to the command. */ + R_BLE_SPP_SPI_Read(&g_current_spp_payload); + + /* Check if the expected response was received. */ + if (g_current_spp_payload.event_id != expected_spp_reply) + { + return BLE_ERR_HC_UNKNOWN_HCI_CMD; + } + } +#endif else { + + /* No response was received. */ return BLE_ERR_RSP_TIMEOUT; } +#if defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_UART) g_spp_cmd_ready = 0; g_spp_cmd_failed = 0; +#elif defined(RM_BLE_ABS_SPP_TRANSPORT_INTERFACE_SPI) + g_data_ready = 0; +#endif return BLE_SUCCESS; } + +static void r_ble_spp_api_delay_ms (uint32_t ms) +{ +#if (BSP_CFG_RTOS == 2) + vTaskDelay(pdMS_TO_TICKS(ms)); +#else + R_BSP_SoftwareDelay(ms, BSP_DELAY_UNITS_MILLISECONDS); +#endif +} diff --git a/ra/fsp/src/rm_ble_abs_spp/rm_ble_abs_spp.c b/ra/fsp/src/rm_ble_abs_spp/rm_ble_abs_spp.c index aadb1517e..6c7b4a0f2 100644 --- a/ra/fsp/src/rm_ble_abs_spp/rm_ble_abs_spp.c +++ b/ra/fsp/src/rm_ble_abs_spp/rm_ble_abs_spp.c @@ -84,163 +84,12 @@ typedef enum e_ble_abs_pv_status /*********************************/ /* Define for create connection */ /*********************************/ -/* Scan interval for connection request with 1M & 2M PHY */ -#define BLE_ABS_CONN_SC_INTV_FAST (0x0060) - -/* Scan window for connection request with 1M & 2M PHY */ -#define BLE_ABS_CONN_SC_WINDOW_FAST (0x0030) - -/* Scan interval for connection request with coded PHY */ -#define BLE_ABS_CONN_SC_INTV_SLOW (0x0180) - -/* Scan window for connection request with coded PHY */ -#define BLE_ABS_CONN_SC_WINDOW_SLOW (0x0090) /* Minimum advertising data length */ -#define BLE_ABS_LEGACY_ADV_DATA_LEN (31) -#define BLE_ABS_CONN_EXT_ADV_DATA_LEN (229) - -/* Add magic number value set */ -#define BLE_ABS_GAP_CONNECTION_CE_LENGTH (0xFFFF) -#define BLE_ABS_SET_PAIRING_MAXIMUM_LTK_SIZE (0x10) -#define BLE_ABS_SECURE_DATA_BOND_ADDRESS_FF (0xFF) -#define BLE_ABS_GAP_REMOTE_IRK_AA (0xAA) -#define BLE_ABS_REMOTE_DEVICE_ADDRESS_55 (0x55) -#define BLE_ABS_GAP_EVENT_CONNECTION_TIMEOUT_1000 (1000) - -/* r_ble_sec_data functions added start */ -#if (BLE_ABS_CFG_ENABLE_SECURE_DATA == 1) - #define BLE_SECD_UPD_BN_ADD (0x00) - #define BLE_SECD_UPD_BN_ADD_OVERWR (0x01) - #define BLE_SECD_UPD_BN_DEL (0x02) - #define BLE_SECD_UPD_BN_ALL_DEL (0x03) - #define BLE_ABS_SECURE_DATA_DELETE_LOCAL_FF (0xFF) - #define BLE_ABS_SECURE_DATA_UPDATE_BOND_NUMBER_FF (0xFF) - #define BLE_ABS_SECURE_DATA_REMOTE_BOND_NUMBER_FF (0xFF) - #define BLE_ABS_SECURE_DATA_BOND_ADDRESS_FF (0xFF) - #define BLE_ABS_SECURE_DATA_BOND_CHECK_FF (0xFF) -#endif - -#define BLE_ABS_SECURE_DATA_INVALID_DATA (0xFF) - -#if (BSP_FEATURE_FLASH_HP_DF_BLOCK_SIZE != 0) - #define BLE_DEV_DATA_DF_ADDR _BLE_DF_ADDR(BLE_CFG_DEV_DATA_DF_BLOCK) - #define BLE_ABS_SECURE_DATA_DF_ADDR _BLE_DF_ADDR(BLE_CFG_SECD_DATA_DF_BLOCK) -#elif (BSP_FEATURE_FLASH_LP_DF_BLOCK_SIZE != 0) - #define BLE_DEV_DATA_DF_ADDR _BLE_DF_ADDR(BLE_CFG_DEV_DATA_DF_BLOCK) - #define BLE_ABS_SECURE_DATA_DF_ADDR _BLE_DF_ADDR(BLE_CFG_SECD_DATA_DF_BLOCK) -#endif - -/* RF event notify function pointer */ -#define BLE_EVENT_TYPE_CONN (0x0000U) -#define BLE_EVENT_TYPE_ADV (0x0001U) -#define BLE_EVENT_TYPE_SCAN (0x0002U) -#define BLE_EVENT_TYPE_INITIATOR (0x0003U) - -#define BLE_EVENT_NOTIFY_CONN_START_POS (0) -#define BLE_EVENT_NOTIFY_ADV_START_POS (1) -#define BLE_EVENT_NOTIFY_SCAN_START_POS (2) -#define BLE_EVENT_NOTIFY_INIT_START_POS (3) -#define BLE_EVENT_NOTIFY_CONN_CLOSE_POS (4) -#define BLE_EVENT_NOTIFY_ADV_CLOSE_POS (5) -#define BLE_EVENT_NOTIFY_SCAN_CLOSE_POS (6) -#define BLE_EVENT_NOTIFY_INIT_CLOSE_POS (7) -#define BLE_EVENT_NOTIFY_DS_START_POS (8) -#define BLE_EVENT_NOTIFY_DS_CLOSE_POS (9) - -#define BLE_EVENT_TYPE_RF_DS_START (0x0U) -#define BLE_EVENT_TYPE_RF_DS_CLOSE (0x1U) - -#define BLE_EVENT_NOTIFY_CONN_START_BIT (0x1U << BLE_EVENT_NOTIFY_CONN_START_POS) -#define BLE_EVENT_NOTIFY_ADV_START_BIT (0x1U << BLE_EVENT_NOTIFY_ADV_START_POS) -#define BLE_EVENT_NOTIFY_SCAN_START_BIT (0x1U << BLE_EVENT_NOTIFY_SCAN_START_POS) -#define BLE_EVENT_NOTIFY_INIT_START_BIT (0x1U << BLE_EVENT_NOTIFY_INIT_START_POS) - -#define BLE_EVENT_NOTIFY_CONN_CLOSE_BIT (0x1U << BLE_EVENT_NOTIFY_CONN_CLOSE_POS) -#define BLE_EVENT_NOTIFY_ADV_CLOSE_BIT (0x1U << BLE_EVENT_NOTIFY_ADV_CLOSE_POS) -#define BLE_EVENT_NOTIFY_SCAN_CLOSE_BIT (0x1U << BLE_EVENT_NOTIFY_SCAN_CLOSE_POS) -#define BLE_EVENT_NOTIFY_INIT_CLOSE_BIT (0x1U << BLE_EVENT_NOTIFY_INIT_CLOSE_POS) - -#define BLE_EVENT_NOTIFY_DS_START_BIT (0x1U << BLE_EVENT_NOTIFY_DS_START_POS) -#define BLE_EVENT_NOTIFY_DS_CLOSE_BIT (0x1U << BLE_EVENT_NOTIFY_DS_CLOSE_POS) - -#define BLE_EVENT_NOTIFY_START_MASK ( \ - (BLE_EVENT_NOTIFY_CONN_START_BIT) | \ - (BLE_EVENT_NOTIFY_ADV_START_BIT) | \ - (BLE_EVENT_NOTIFY_SCAN_START_BIT) | \ - (BLE_EVENT_NOTIFY_INIT_START_BIT) | \ - (0x0U)) - -#define BLE_EVENT_NOTIFY_CLOSE_MASK ( \ - (BLE_EVENT_NOTIFY_CONN_CLOSE_BIT) | \ - (BLE_EVENT_NOTIFY_ADV_CLOSE_BIT) | \ - (BLE_EVENT_NOTIFY_SCAN_CLOSE_BIT) | \ - (BLE_EVENT_NOTIFY_INIT_CLOSE_BIT) | \ - (0x0U)) - -#define BLE_EVENT_NOTIFY_DS_MASK ( \ - (BLE_EVENT_NOTIFY_DS_START_BIT) | \ - (BLE_EVENT_NOTIFY_DS_CLOSE_BIT) | \ - (0x0U)) - -#define BLE_HOST_TBL_NUM 8 - -#define BLE_ABS_SECURE_DATA_MAGIC_NUMBER_SIZE (4) -#define BLE_ABS_SECURE_DATA_MAGIC_NUMBER (0x12345678) - -/* Internal data flash base address. */ -#define BLE_ABS_SECURE_DATA_BLOCK_BASE (0x40100000) - -#if (BSP_FEATURE_FLASH_HP_DF_BLOCK_SIZE != 0) - #define BLE_ABS_SECURE_DATA_BLOCK_SIZE (BSP_FEATURE_FLASH_HP_DF_BLOCK_SIZE) -#elif (BSP_FEATURE_FLASH_LP_DF_BLOCK_SIZE != 0) - #define BLE_ABS_SECURE_DATA_BLOCK_SIZE (BSP_FEATURE_FLASH_LP_DF_BLOCK_SIZE) -#endif - -#define BLE_ABS_SECURE_DATA_BONDING_NUMBER_OFFSET BLE_ABS_SECURE_DATA_MAGIC_NUMBER_SIZE -#define BLE_ABS_SECURE_DATA_OUT_BONDING_OFFSET (5) -#define BLE_ABS_SECURE_DATA_SECURITY_INFOMATION_OFFSET (8) -#define BLE_ABS_SECURE_DATA_SECURITY_KEYS_INFOMATION_OFFSET (12) -#define BLE_ABS_SECURE_DATA_SECURITY_KEYS_OFFSET (20) -#define BLE_ABS_SECURE_DATA_SECURITY_REMOTE_OFFSET (48) -#define BLE_ABS_SECURE_DATA_SECURITY_IDENTITY_ADDRESS_OFFSET (62) - -#define BLE_ABS_SECURE_DATA_REMOTE_BONDING_SIZE (88) -#define BLE_ABS_SECURE_DATA_LOCAL_AREA_SIZE (40) -#define BLE_ABS_SECURE_DATA_LOCAL_INFOMATION_SIZE (1) -#define BLE_ABS_SECURE_DATA_BLUETOOTH_DEVICE_ADDRESS_SIZE (7) -#define BLE_ABS_SECURE_DATA_MANEGEMENT_DATA_SIZE (8) -#define BLE_ABS_SECURE_DATA_REMOTE_KEY_ATTRIBUTE_SIZE (6) -#define BLE_ABS_SECURE_DATA_REMOTE_KEYS_SIZE (65) -#define BLE_ABS_SECURE_DATA_REMOTE_KEYS_INFOMATION_SIZE (4) - -#define BLE_ABS_SECURE_DATA_BASE_ADDR (BLE_ABS_SECURE_DATA_BLOCK_BASE + \ - (BLE_ABS_CFG_SECURE_DATA_DATAFLASH_BLOCK * \ - BLE_ABS_SECURE_DATA_BLOCK_SIZE)) -#define BLE_ABS_SECURE_DATA_ADDR_MGN_DATA (BLE_ABS_SECURE_DATA_BASE_ADDR) -#define BLE_ABS_SECURE_DATA_SEC_BOND_NUM (BLE_ABS_SECURE_DATA_ADDR_MGN_DATA + \ - BLE_ABS_SECURE_DATA_MAGIC_NUMBER_SIZE) -#define BLE_ABS_SECURE_DATA_ADDR_LOC_AREA (BLE_ABS_SECURE_DATA_BASE_ADDR + \ - BLE_ABS_SECURE_DATA_MANEGEMENT_DATA_SIZE) -#define BLE_ABS_SECURE_DATA_ADDR_LOC_IRK (BLE_ABS_SECURE_DATA_ADDR_LOC_AREA) -#define BLE_ABS_SECURE_DATA_ADDR_LOC_CSRK (BLE_ABS_SECURE_DATA_ADDR_LOC_IRK + BLE_GAP_IRK_SIZE) -#define BLE_ABS_SECURE_DATA_ADDR_LOC_IDADDR (BLE_ABS_SECURE_DATA_ADDR_LOC_CSRK + BLE_GAP_CSRK_SIZE) -#define BLE_ABS_SECURE_DATA_ADDR_LOC_INFO (BLE_ABS_SECURE_DATA_ADDR_LOC_IDADDR + \ - BLE_ABS_SECURE_DATA_BLUETOOTH_DEVICE_ADDRESS_SIZE) -#define BLE_ABS_SECURE_DATA_ADDR_REM_START (BLE_ABS_SECURE_DATA_ADDR_LOC_INFO + \ - BLE_ABS_SECURE_DATA_LOCAL_INFOMATION_SIZE) -#define BLE_ABS_SECURE_DATA_MAX_SIZE (BLE_ABS_SECURE_DATA_SECURITY_REMOTE_OFFSET + \ - BLE_ABS_SECURE_DATA_REMOTE_BONDING_SIZE * \ - BLE_ABS_CFG_NUMBER_BONDING) -#define BLE_ABS_SECURE_DATA_BLOCK_SIZE_MASK (BLE_ABS_SECURE_DATA_BLOCK_SIZE - 1UL) +#define BLE_ABS_LEGACY_ADV_DATA_LEN (31) /* The invalid timer handle. */ -#define BLE_TIMER_INVALID_HDL (0xFF) - -/* Add magic number value set */ -#define BLE_ABS_TIMER_REMAIN_TIMESHORTEST (0xFFFFFFFF) -#define BLE_ABS_TIMER_DEFAULT_TIMEOUT_MS (1000) -#define BLE_ABS_TIMER_METRIC_PREFIX (1000) +#define BLE_TIMER_INVALID_HDL (0xFF) /*********************************************************************************************************************** * Local Typedef definitions @@ -343,7 +192,7 @@ fsp_err_t RM_BLE_ABS_Open (ble_abs_ctrl_t * const p_ctrl, ble_abs_cfg_t const * FSP_ASSERT(p_instance_ctrl); FSP_ASSERT(p_cfg); FSP_ASSERT(p_cfg->gap_callback); - FSP_ASSERT(p_cfg->p_uart_instance); + FSP_ASSERT(p_cfg->p_uart_instance || (p_cfg->p_spi_instance && p_cfg->p_irq_instance)); #endif FSP_ERROR_RETURN(BLE_ABS_OPEN != p_instance_ctrl->open, FSP_ERR_ALREADY_OPEN); @@ -1395,6 +1244,9 @@ static void ble_abs_gap_callback (uint16_t event_type, ble_status_t event_result case BLE_GAP_EVENT_CONN_IND: { + ble_abs_set_advertising_status(gp_instance_ctrl, BLE_ABS_LEGACY_HDL, 0, + (BLE_ABS_ADV_STATUS_ADV_FAST_START | BLE_ABS_ADV_STATUS_ADV_SLOW_START)); + R_BLE_GAP_StopAdv(0); break; diff --git a/ra/fsp/src/rm_cellular_comm_uart_aws/rm_cellular_comm_uart_aws.c b/ra/fsp/src/rm_cellular_comm_uart_aws/rm_cellular_comm_uart_aws.c index 47e991d4b..a51815011 100644 --- a/ra/fsp/src/rm_cellular_comm_uart_aws/rm_cellular_comm_uart_aws.c +++ b/ra/fsp/src/rm_cellular_comm_uart_aws/rm_cellular_comm_uart_aws.c @@ -76,10 +76,15 @@ void comm_uart_aws_callback (uart_callback_args_t * p_args) { /* Kick off zero-copy transfer */ p_instance_ctrl->p_recv_buffer[0] = data_byte; - p_instance_ctrl->recv_read_length--; + p_instance_ctrl->remaining_recv_read_length--; p_instance_ctrl->p_recv_buffer++; + p_instance_ctrl->current_recv_read_length--; - p_uart_instance->p_api->read(p_uart_instance->p_ctrl, p_instance_ctrl->p_recv_buffer, 1); + p_uart_instance->p_api->read(p_uart_instance->p_ctrl, + p_instance_ctrl->p_recv_buffer, + p_instance_ctrl->current_recv_read_length); + + p_instance_ctrl->transfer_in_progress = true; } break; @@ -87,13 +92,27 @@ void comm_uart_aws_callback (uart_callback_args_t * p_args) case UART_EVENT_RX_COMPLETE: { - p_instance_ctrl->recv_read_length--; + /* Read complete, update remaining length */ + p_instance_ctrl->remaining_recv_read_length = p_instance_ctrl->remaining_recv_read_length - + p_instance_ctrl->current_recv_read_length; - if (p_instance_ctrl->recv_read_length > 0) + if (p_instance_ctrl->remaining_recv_read_length > 0) { + p_instance_ctrl->p_recv_buffer += p_instance_ctrl->current_recv_read_length; + /* Buffer hasn't been filled yet, continue reading */ - p_instance_ctrl->p_recv_buffer++; - p_uart_instance->p_api->read(p_uart_instance->p_ctrl, p_instance_ctrl->p_recv_buffer, 1); + if (p_instance_ctrl->remaining_recv_read_length > RM_CELLULAR_COMM_UART_AWS_RECEIVE_CLUSTER_BYTE_COUNT) + { + p_instance_ctrl->current_recv_read_length = RM_CELLULAR_COMM_UART_AWS_RECEIVE_CLUSTER_BYTE_COUNT; + } + else + { + p_instance_ctrl->current_recv_read_length = p_instance_ctrl->remaining_recv_read_length; + } + + p_uart_instance->p_api->read(p_uart_instance->p_ctrl, + p_instance_ctrl->p_recv_buffer, + p_instance_ctrl->current_recv_read_length); } else { @@ -149,10 +168,11 @@ CellularCommInterfaceError_t RM_CELLULAR_COMM_UART_AWS_Open ( FSP_ERROR_RETURN(NULL != receive_callback, IOT_COMM_INTERFACE_BAD_PARAMETER); #endif - p_instance_ctrl->p_user_data = pUserData; - p_instance_ctrl->receive_callback = receive_callback; - p_instance_ctrl->read_count = 0; - p_instance_ctrl->p_recv_buffer = NULL; + p_instance_ctrl->p_user_data = pUserData; + p_instance_ctrl->receive_callback = receive_callback; + p_instance_ctrl->read_count = 0; + p_instance_ctrl->p_recv_buffer = NULL; + p_instance_ctrl->transfer_in_progress = false; p_uart_instance = p_instance_ctrl->p_lower_level_instance; @@ -264,6 +284,7 @@ CellularCommInterfaceError_t RM_CELLULAR_COMM_UART_AWS_Receive (CellularCommInte { rm_cellular_comm_uart_aws_instance_ctrl_t * p_instance_ctrl = (rm_cellular_comm_uart_aws_instance_ctrl_t *) commInterfaceHandle; + #if RM_CELLULAR_COMM_UART_AWS_PARAM_CHECKING_ENABLE FSP_ERROR_RETURN(NULL != p_instance_ctrl, IOT_COMM_INTERFACE_BAD_PARAMETER); FSP_ERROR_RETURN(NULL != pBuffer, IOT_COMM_INTERFACE_BAD_PARAMETER); @@ -274,66 +295,121 @@ CellularCommInterfaceError_t RM_CELLULAR_COMM_UART_AWS_Receive (CellularCommInte FSP_CRITICAL_SECTION_DEFINE; FSP_CRITICAL_SECTION_ENTER; - p_instance_ctrl->recv_read_length = bufferLength - p_instance_ctrl->read_count; - p_instance_ctrl->p_recv_buffer = pBuffer + p_instance_ctrl->read_count; + if (bufferLength > p_instance_ctrl->read_count) + { + p_instance_ctrl->remaining_recv_read_length = bufferLength - p_instance_ctrl->read_count; + p_instance_ctrl->p_recv_buffer = pBuffer + p_instance_ctrl->read_count; - memcpy(pBuffer, p_instance_ctrl->rx_buffer, p_instance_ctrl->read_count); - p_instance_ctrl->read_count = 0; + if (p_instance_ctrl->remaining_recv_read_length > RM_CELLULAR_COMM_UART_AWS_RECEIVE_CLUSTER_BYTE_COUNT) + { +#if RM_CELLULAR_COMM_UART_AWS_RECEIVE_CLUSTER_BYTE_COUNT > 1 + p_instance_ctrl->current_recv_read_length = RM_CELLULAR_COMM_UART_AWS_RECEIVE_CLUSTER_BYTE_COUNT; +#else - FSP_CRITICAL_SECTION_EXIT; + /* Special case for 1 */ + p_instance_ctrl->current_recv_read_length = RM_CELLULAR_COMM_UART_AWS_RECEIVE_CLUSTER_BYTE_COUNT + 1; +#endif + } + else + { + p_instance_ctrl->current_recv_read_length = p_instance_ctrl->remaining_recv_read_length; + } + + memcpy(pBuffer, p_instance_ctrl->rx_buffer, p_instance_ctrl->read_count); - /* Loop until timeout/transfer complete */ - while (true) + p_instance_ctrl->read_count = 0; + } + else { - /* Wait for UART_EVENT_RX_COMPLETE semaphore */ - if (pdTRUE == xSemaphoreTake(p_instance_ctrl->rx_semaphore_handle, pdMS_TO_TICKS(timeoutMilliseconds))) + /* Amount to store in read buffer is less than or equal to what has been read in rx_buffer, only copy bufferLength */ + memcpy(pBuffer, p_instance_ctrl->rx_buffer, bufferLength); + + if (bufferLength < p_instance_ctrl->read_count) { - if ((0 == p_instance_ctrl->recv_read_length) && (NULL == p_instance_ctrl->p_recv_buffer)) - { - /* Full bufferLength was read */ - *pDataReceivedLength = bufferLength; - break; - } + /* Buffer length is less than read count, move bytes not copied to pBuffer to front of rx_buffer */ + p_instance_ctrl->read_count = p_instance_ctrl->read_count - bufferLength; + + memcpy(p_instance_ctrl->rx_buffer, p_instance_ctrl->rx_buffer + bufferLength, p_instance_ctrl->read_count); } else { - /* Byte read timed out */ - FSP_CRITICAL_SECTION_ENTER; + p_instance_ctrl->read_count = 0; + } + + *pDataReceivedLength = bufferLength; + } - p_instance_ctrl->p_recv_buffer = NULL; + FSP_CRITICAL_SECTION_EXIT; - /* Check for semaphore one more time inside critical section */ - if (pdTRUE != xSemaphoreTake(p_instance_ctrl->rx_semaphore_handle, 0)) + if (NULL != p_instance_ctrl->p_recv_buffer) + { + /* Loop until timeout/transfer complete */ + while (true) + { + /* Wait for UART_EVENT_RX_COMPLETE semaphore */ + if (pdTRUE == xSemaphoreTake(p_instance_ctrl->rx_semaphore_handle, pdMS_TO_TICKS(timeoutMilliseconds))) { - /* Semaphore not posted, continue to abort read */ - uart_instance_t * p_uart_instance = p_instance_ctrl->p_lower_level_instance; - uint32_t remaining_bytes; + if ((0 == p_instance_ctrl->remaining_recv_read_length) && (NULL == p_instance_ctrl->p_recv_buffer)) + { + /* Full bufferLength was read */ + *pDataReceivedLength = bufferLength; + break; + } + } + else + { + /* Byte read timed out */ + FSP_CRITICAL_SECTION_ENTER; - /* No more data received, cancel transfer */ - if (FSP_SUCCESS != p_uart_instance->p_api->readStop(p_uart_instance->p_ctrl, &remaining_bytes)) + p_instance_ctrl->p_recv_buffer = NULL; + + /* Check for semaphore one more time inside critical section */ + if (pdTRUE != xSemaphoreTake(p_instance_ctrl->rx_semaphore_handle, 0)) { - FSP_CRITICAL_SECTION_EXIT; - *pDataReceivedLength = 0; + /* Semaphore not posted, continue to abort read */ + uart_instance_t * p_uart_instance = p_instance_ctrl->p_lower_level_instance; + uint32_t remaining_bytes; + + if (p_instance_ctrl->transfer_in_progress) + { + if (FSP_SUCCESS != p_uart_instance->p_api->readStop(p_uart_instance->p_ctrl, &remaining_bytes)) + { + /* No more data received, cancel transfer */ + FSP_CRITICAL_SECTION_EXIT; + *pDataReceivedLength = 0; + + return IOT_COMM_INTERFACE_DRIVER_ERROR; + } + + /* Get received data length */ + uint32_t current_bytes_read = p_instance_ctrl->current_recv_read_length - remaining_bytes; + uint32_t total_remaining_bytes = p_instance_ctrl->remaining_recv_read_length - + current_bytes_read; + *pDataReceivedLength = bufferLength - total_remaining_bytes; + } + else + { + /* Transfer never started */ + *pDataReceivedLength = bufferLength - p_instance_ctrl->remaining_recv_read_length; + } - return IOT_COMM_INTERFACE_DRIVER_ERROR; + FSP_CRITICAL_SECTION_EXIT; + break; } - /* Get received data length */ - *pDataReceivedLength = bufferLength - p_instance_ctrl->recv_read_length; - FSP_CRITICAL_SECTION_EXIT; - break; - } + if ((0 == p_instance_ctrl->remaining_recv_read_length) && (NULL == p_instance_ctrl->p_recv_buffer)) + { + /* Full bufferLength was read */ + *pDataReceivedLength = bufferLength; + FSP_CRITICAL_SECTION_EXIT; + break; + } - if ((0 == p_instance_ctrl->recv_read_length) && (NULL == p_instance_ctrl->p_recv_buffer)) - { - /* Full bufferLength was read */ - *pDataReceivedLength = bufferLength; FSP_CRITICAL_SECTION_EXIT; - break; } - - FSP_CRITICAL_SECTION_EXIT; } + + p_instance_ctrl->transfer_in_progress = false; } return IOT_COMM_INTERFACE_SUCCESS; diff --git a/ra/fsp/src/rm_comms_i2c/rm_comms_i2c_driver_ra.c b/ra/fsp/src/rm_comms_i2c/rm_comms_i2c_driver_ra.c index 2fff2d2ec..33c1073d4 100644 --- a/ra/fsp/src/rm_comms_i2c/rm_comms_i2c_driver_ra.c +++ b/ra/fsp/src/rm_comms_i2c/rm_comms_i2c_driver_ra.c @@ -105,10 +105,7 @@ fsp_err_t rm_comms_i2c_bus_read (rm_comms_ctrl_t * const p_api_ctrl, uint8_t * c p_ctrl->transfer_data_bytes = 0; /* Use RA I2C driver to read data */ - err = p_driver_instance->p_api->read(p_driver_instance->p_ctrl, - p_dest, - bytes, - false); + err = p_driver_instance->p_api->read(p_driver_instance->p_ctrl, p_dest, bytes, false); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); #if BSP_CFG_RTOS @@ -150,10 +147,7 @@ fsp_err_t rm_comms_i2c_bus_write (rm_comms_ctrl_t * const p_api_ctrl, uint8_t * p_ctrl->transfer_data_bytes = 0; /* Use RA I2C driver to write data */ - err = p_driver_instance->p_api->write(p_driver_instance->p_ctrl, - p_src, - bytes, - false); + err = p_driver_instance->p_api->write(p_driver_instance->p_ctrl, p_src, bytes, false); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); #if BSP_CFG_RTOS diff --git a/ra/fsp/src/rm_emwin_port/LCDConf.c b/ra/fsp/src/rm_emwin_port/LCDConf.c index 78a14d61c..e8b22608a 100644 --- a/ra/fsp/src/rm_emwin_port/LCDConf.c +++ b/ra/fsp/src/rm_emwin_port/LCDConf.c @@ -321,7 +321,7 @@ static void _SetLUTEntry (LCD_COLOR Color, uint8_t Pos) #if (EMWIN_LCD_NUM_FRAMEBUFFERS == 2) -static void vsync_wait () +static void vsync_wait (void) { #if EMWIN_LCD_VSYNC_WAIT #if EMWIN_CFG_RTOS == 2 // FreeRTOS diff --git a/ra/fsp/src/rm_filex_levelx_nor/rm_filex_levelx_nor.c b/ra/fsp/src/rm_filex_levelx_nor/rm_filex_levelx_nor.c index 674e6885c..cb50188eb 100644 --- a/ra/fsp/src/rm_filex_levelx_nor/rm_filex_levelx_nor.c +++ b/ra/fsp/src/rm_filex_levelx_nor/rm_filex_levelx_nor.c @@ -117,7 +117,7 @@ static UINT rm_filex_levelx_nor_driver_request_handler (FX_MEDIA * p_fx_media) (rm_filex_levelx_nor_instance_t *) p_fx_media->fx_media_driver_info; rm_filex_levelx_nor_instance_ctrl_t * p_filex_levelx_nor_ctrl = p_filex_levelx_nor_instance->p_ctrl; - rm_filex_levelx_nor_cfg_t * p_filex_levelx_nor_cfg = p_filex_levelx_nor_instance->p_cfg; + rm_filex_levelx_nor_cfg_t const * p_filex_levelx_nor_cfg = p_filex_levelx_nor_instance->p_cfg; /* Process the driver request specified in the media control block. */ switch (p_fx_media->fx_media_driver_request) diff --git a/ra/fsp/src/rm_guix_port/gx_display_driver_dave2d.c b/ra/fsp/src/rm_guix_port/gx_display_driver_dave2d.c index c39fa2606..49fb649ce 100644 --- a/ra/fsp/src/rm_guix_port/gx_display_driver_dave2d.c +++ b/ra/fsp/src/rm_guix_port/gx_display_driver_dave2d.c @@ -3855,7 +3855,7 @@ static UINT gx_renesas_jpeg_draw_minimum_height_get (jpeg_color_space_t format, * @retval Others See @ref Common_Error_Codes for other possible return codes. This function calls * jpeg_api_t::wait. **********************************************************************************************************************/ -static INT gx_renesas_jpeg_draw_output_streaming_wait () +static INT gx_renesas_jpeg_draw_output_streaming_wait (void) { INT ret; diff --git a/ra/fsp/src/rm_hs300x/rm_hs300x.c b/ra/fsp/src/rm_hs300x/rm_hs300x.c index bf7a6e54f..e05189356 100644 --- a/ra/fsp/src/rm_hs300x/rm_hs300x.c +++ b/ra/fsp/src/rm_hs300x/rm_hs300x.c @@ -88,6 +88,7 @@ extern fsp_err_t rm_hs300x_delay_us(rm_hs300x_instance_ctrl_t * const p_ctrl, ui /*********************************************************************************************************************** * Private global variables **********************************************************************************************************************/ + /*********************************************************************************************************************** * Global variables **********************************************************************************************************************/ @@ -190,7 +191,6 @@ fsp_err_t RM_HS300X_MeasurementStart (rm_hs300x_ctrl_t * const p_api_ctrl) { fsp_err_t err = FSP_SUCCESS; rm_hs300x_instance_ctrl_t * p_ctrl = (rm_hs300x_instance_ctrl_t *) p_api_ctrl; - uint8_t write_data = 0; #if RM_HS300X_CFG_PARAM_CHECKING_ENABLE FSP_ASSERT(NULL != p_ctrl); @@ -198,7 +198,9 @@ fsp_err_t RM_HS300X_MeasurementStart (rm_hs300x_ctrl_t * const p_api_ctrl) #endif /* Write */ - err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &write_data, 0); + p_ctrl->buf[0] = 0; + err = + p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &p_ctrl->buf[0], 0); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); return FSP_SUCCESS; @@ -274,6 +276,7 @@ fsp_err_t RM_HS300X_DataCalculate (rm_hs300x_ctrl_t * const p_api_ctrl, (int16_t) ((tmp_f - (float) p_hs300x_data->humidity.integer_part) * RM_HS300X_CALC_DECIMAL_VALUE_100); #if RM_HS300X_CFG_DATA_BOTH_HUMIDITY_TEMPERATURE + /* Temperature [Celsius] */ tmp_u16 = (uint16_t) ((uint16_t) (p_raw_data->temperature[0]) << 8); tmp_f = @@ -305,7 +308,6 @@ fsp_err_t RM_HS300X_ProgrammingModeEnter (rm_hs300x_ctrl_t * const p_api_ctrl) #if RM_HS300X_CFG_PROGRAMMING_MODE fsp_err_t err = FSP_SUCCESS; rm_hs300x_instance_ctrl_t * p_ctrl = (rm_hs300x_instance_ctrl_t *) p_api_ctrl; - uint8_t write_data[3]; #if RM_HS300X_CFG_PARAM_CHECKING_ENABLE FSP_ASSERT(NULL != p_ctrl); @@ -316,10 +318,11 @@ fsp_err_t RM_HS300X_ProgrammingModeEnter (rm_hs300x_ctrl_t * const p_api_ctrl) p_ctrl->programming_mode.enter = true; /* Write the commands */ - write_data[0] = RM_HS300X_PROGRAMMING_MODE_ENTER; - write_data[1] = 0x00; - write_data[2] = 0x00; - err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &write_data[0], 3); + p_ctrl->buf[0] = RM_HS300X_PROGRAMMING_MODE_ENTER; + p_ctrl->buf[1] = 0x00; + p_ctrl->buf[2] = 0x00; + err = + p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &p_ctrl->buf[0], 3); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); return FSP_SUCCESS; @@ -355,7 +358,6 @@ fsp_err_t RM_HS300X_ResolutionChange (rm_hs300x_ctrl_t * const p_api_ctrl, #if RM_HS300X_CFG_PROGRAMMING_MODE fsp_err_t err = FSP_SUCCESS; rm_hs300x_instance_ctrl_t * p_ctrl = (rm_hs300x_instance_ctrl_t *) p_api_ctrl; - uint8_t transfer_data[3]; uint16_t counter = 0; #if RM_HS300X_CFG_PARAM_CHECKING_ENABLE @@ -367,22 +369,22 @@ fsp_err_t RM_HS300X_ResolutionChange (rm_hs300x_ctrl_t * const p_api_ctrl, /* Set the register address */ if (RM_HS300X_HUMIDITY_DATA == data_type) { - transfer_data[0] = RM_HS300X_HUMIDITY_RESOLUTION_READ; + p_ctrl->buf[0] = RM_HS300X_HUMIDITY_RESOLUTION_READ; } else { - transfer_data[0] = RM_HS300X_TEMPERATURE_RESOLUTION_READ; + p_ctrl->buf[0] = RM_HS300X_TEMPERATURE_RESOLUTION_READ; } - transfer_data[1] = 0x00; - transfer_data[2] = 0x00; + p_ctrl->buf[1] = 0x00; + p_ctrl->buf[2] = 0x00; /* Set the blocking flag */ p_ctrl->programming_mode.blocking = true; /* Write the register address */ p_ctrl->programming_mode.communication_finished = false; - err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &transfer_data[0], 3); + err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &p_ctrl->buf[0], 3); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); /* Wait the callback */ @@ -402,7 +404,7 @@ fsp_err_t RM_HS300X_ResolutionChange (rm_hs300x_ctrl_t * const p_api_ctrl, /* Read the current resolution */ p_ctrl->programming_mode.communication_finished = false; - err = p_ctrl->p_comms_i2c_instance->p_api->read(p_ctrl->p_comms_i2c_instance->p_ctrl, &transfer_data[0], 3); + err = p_ctrl->p_comms_i2c_instance->p_api->read(p_ctrl->p_comms_i2c_instance->p_ctrl, &p_ctrl->buf[0], 3); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); /* Wait the callback */ @@ -415,27 +417,27 @@ fsp_err_t RM_HS300X_ResolutionChange (rm_hs300x_ctrl_t * const p_api_ctrl, /* Check the errors */ FSP_ERROR_RETURN(RM_HS300X_EVENT_SUCCESS == p_ctrl->programming_mode.event, FSP_ERR_ABORTED); - FSP_ERROR_RETURN(RM_HS300X_PROGRAMMING_MODE_SUCCESS_STATUS == transfer_data[0], FSP_ERR_INVALID_MODE); + FSP_ERROR_RETURN(RM_HS300X_PROGRAMMING_MODE_SUCCESS_STATUS == p_ctrl->buf[0], FSP_ERR_INVALID_MODE); /* Set the register address */ if (RM_HS300X_HUMIDITY_DATA == data_type) { - transfer_data[0] = RM_HS300X_HUMIDITY_RESOLUTION_WRITE; + p_ctrl->buf[0] = RM_HS300X_HUMIDITY_RESOLUTION_WRITE; } else { - transfer_data[0] = RM_HS300X_TEMPERATURE_RESOLUTION_WRITE; + p_ctrl->buf[0] = RM_HS300X_TEMPERATURE_RESOLUTION_WRITE; } /* set the next resolution */ - transfer_data[1] &= RM_HS300X_RESOLUTION_CLEAR; // Clear the current resolution - transfer_data[1] |= resolution; // Set the new resolution + p_ctrl->buf[1] &= RM_HS300X_RESOLUTION_CLEAR; // Clear the current resolution + p_ctrl->buf[1] |= resolution; // Set the new resolution /* Clear the blocking flag */ p_ctrl->programming_mode.blocking = false; /* Write the next resolution */ - err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &transfer_data[0], 3); + err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &p_ctrl->buf[0], 3); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); return FSP_SUCCESS; @@ -469,7 +471,6 @@ fsp_err_t RM_HS300X_SensorIdGet (rm_hs300x_ctrl_t * const p_api_ctrl, uint32_t * #if RM_HS300X_CFG_PROGRAMMING_MODE fsp_err_t err = FSP_SUCCESS; rm_hs300x_instance_ctrl_t * p_ctrl = (rm_hs300x_instance_ctrl_t *) p_api_ctrl; - uint8_t transfer_data[3]; uint16_t counter = 0; #if RM_HS300X_CFG_PARAM_CHECKING_ENABLE @@ -480,16 +481,16 @@ fsp_err_t RM_HS300X_SensorIdGet (rm_hs300x_ctrl_t * const p_api_ctrl, uint32_t * #endif /* Set the register address of upper value */ - transfer_data[0] = RM_HS300X_SENSOR_ID_UPPER; - transfer_data[1] = 0x00; - transfer_data[2] = 0x00; + p_ctrl->buf[0] = RM_HS300X_SENSOR_ID_UPPER; + p_ctrl->buf[1] = 0x00; + p_ctrl->buf[2] = 0x00; /* Set the blocking flag */ p_ctrl->programming_mode.blocking = true; /* Write the register address */ p_ctrl->programming_mode.communication_finished = false; - err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &transfer_data[0], 3); + err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &p_ctrl->buf[0], 3); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); /* Wait the callback */ @@ -509,7 +510,7 @@ fsp_err_t RM_HS300X_SensorIdGet (rm_hs300x_ctrl_t * const p_api_ctrl, uint32_t * /* Read the upper value of the sensor ID */ p_ctrl->programming_mode.communication_finished = false; - err = p_ctrl->p_comms_i2c_instance->p_api->read(p_ctrl->p_comms_i2c_instance->p_ctrl, &transfer_data[0], 3); + err = p_ctrl->p_comms_i2c_instance->p_api->read(p_ctrl->p_comms_i2c_instance->p_ctrl, &p_ctrl->buf[0], 3); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); /* Wait the callback */ @@ -522,19 +523,19 @@ fsp_err_t RM_HS300X_SensorIdGet (rm_hs300x_ctrl_t * const p_api_ctrl, uint32_t * /* Check the errors */ FSP_ERROR_RETURN(RM_HS300X_EVENT_SUCCESS == p_ctrl->programming_mode.event, FSP_ERR_ABORTED); - FSP_ERROR_RETURN(RM_HS300X_PROGRAMMING_MODE_SUCCESS_STATUS == transfer_data[0], FSP_ERR_INVALID_MODE); + FSP_ERROR_RETURN(RM_HS300X_PROGRAMMING_MODE_SUCCESS_STATUS == p_ctrl->buf[0], FSP_ERR_INVALID_MODE); /* set the upper value of sensor ID */ - *p_sensor_id = (uint32_t) ((transfer_data[1] << 8) + transfer_data[2]) << 16; + *p_sensor_id = (uint32_t) ((p_ctrl->buf[1] << 8) + p_ctrl->buf[2]) << 16; /* Set the register address of lower value */ - transfer_data[0] = RM_HS300X_SENSOR_ID_LOWER; - transfer_data[1] = 0x00; - transfer_data[2] = 0x00; + p_ctrl->buf[0] = RM_HS300X_SENSOR_ID_LOWER; + p_ctrl->buf[1] = 0x00; + p_ctrl->buf[2] = 0x00; /* Write the register address */ p_ctrl->programming_mode.communication_finished = false; - err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &transfer_data[0], 3); + err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &p_ctrl->buf[0], 3); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); /* Wait the callback */ @@ -554,7 +555,7 @@ fsp_err_t RM_HS300X_SensorIdGet (rm_hs300x_ctrl_t * const p_api_ctrl, uint32_t * /* Read the lower value of the sensor ID */ p_ctrl->programming_mode.communication_finished = false; - err = p_ctrl->p_comms_i2c_instance->p_api->read(p_ctrl->p_comms_i2c_instance->p_ctrl, &transfer_data[0], 3); + err = p_ctrl->p_comms_i2c_instance->p_api->read(p_ctrl->p_comms_i2c_instance->p_ctrl, &p_ctrl->buf[0], 3); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); /* Wait the callback */ @@ -567,10 +568,10 @@ fsp_err_t RM_HS300X_SensorIdGet (rm_hs300x_ctrl_t * const p_api_ctrl, uint32_t * /* Check the errors */ FSP_ERROR_RETURN(RM_HS300X_EVENT_SUCCESS == p_ctrl->programming_mode.event, FSP_ERR_ABORTED); - FSP_ERROR_RETURN(RM_HS300X_PROGRAMMING_MODE_SUCCESS_STATUS == transfer_data[0], FSP_ERR_INVALID_MODE); + FSP_ERROR_RETURN(RM_HS300X_PROGRAMMING_MODE_SUCCESS_STATUS == p_ctrl->buf[0], FSP_ERR_INVALID_MODE); /* set the upper value of sensor ID */ - *p_sensor_id = *p_sensor_id + (uint32_t) ((transfer_data[1] << 8) + transfer_data[2]); + *p_sensor_id = *p_sensor_id + (uint32_t) ((p_ctrl->buf[1] << 8) + p_ctrl->buf[2]); /* Clear the blocking flag */ p_ctrl->programming_mode.blocking = false; @@ -603,7 +604,6 @@ fsp_err_t RM_HS300X_ProgrammingModeExit (rm_hs300x_ctrl_t * const p_api_ctrl) #if RM_HS300X_CFG_PROGRAMMING_MODE fsp_err_t err = FSP_SUCCESS; rm_hs300x_instance_ctrl_t * p_ctrl = (rm_hs300x_instance_ctrl_t *) p_api_ctrl; - uint8_t write_data[3]; #if RM_HS300X_CFG_PARAM_CHECKING_ENABLE FSP_ASSERT(NULL != p_ctrl); @@ -612,10 +612,11 @@ fsp_err_t RM_HS300X_ProgrammingModeExit (rm_hs300x_ctrl_t * const p_api_ctrl) #endif /* Write the commands */ - write_data[0] = RM_HS300X_PROGRAMMING_MODE_EXIT; - write_data[1] = 0x00; - write_data[2] = 0x00; - err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &write_data[0], 3); + p_ctrl->buf[0] = RM_HS300X_PROGRAMMING_MODE_EXIT; + p_ctrl->buf[1] = 0x00; + p_ctrl->buf[2] = 0x00; + err = + p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, &p_ctrl->buf[0], 3); FSP_ERROR_RETURN(FSP_SUCCESS == err, err); /* Clear the flag */ diff --git a/ra/fsp/src/rm_mcuboot_port/crypto/sce9_image_rsa.c b/ra/fsp/src/rm_mcuboot_port/crypto/sce9_image_rsa.c new file mode 100644 index 000000000..e0888e66f --- /dev/null +++ b/ra/fsp/src/rm_mcuboot_port/crypto/sce9_image_rsa.c @@ -0,0 +1,292 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2017-2018 Linaro LTD + * Copyright (c) 2017-2019 JUUL Labs + * Copyright (c) 2020 Arm Limited + * + * Original license: + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include + +#include "mcuboot_config/mcuboot_config.h" + +#include "sce9_keys.h" +#ifdef MCUBOOT_SIGN_RSA + #if defined MCUBOOT_USE_USER_DEFINED_CRYPTO_STACK + #include "bootutil/sign_key.h" + #include "bootutil/crypto/sha256.h" + + #include "bootutil_priv.h" + #include "bootutil/fault_injection_hardening.h" + + #if (MCUBOOT_SIGN_RSA_LEN == 2048) +static sce_rsa2048_public_wrapped_key_t rsa_public_key_installed; + #elif (MCUBOOT_SIGN_RSA_LEN == 3072) +static sce_rsa3072_public_wrapped_key_t rsa_public_key_installed; + #endif + +/* + * Constants for this particular constrained implementation of + * RSA-PSS. In particular, we support RSA 2048, with a SHA256 hash, + * and a 32-byte salt. A signature with different parameters will be + * rejected as invalid. + */ + +/* The size, in octets, of the message. */ +#define PSS_EMLEN (MCUBOOT_SIGN_RSA_LEN / 8) + +/* The size of the hash function. For SHA256, this is 32 bytes. */ +#define PSS_HLEN 32 + +/* Size of the salt, should be fixed. */ +#define PSS_SLEN 32 + +/* The length of the mask: emLen - hLen - 1. */ +#define PSS_MASK_LEN (PSS_EMLEN - PSS_HLEN - 1) + +#define PSS_HASH_OFFSET PSS_MASK_LEN + +/* For the mask itself, how many bytes should be all zeros. */ +#define PSS_MASK_ZERO_COUNT (PSS_MASK_LEN - PSS_SLEN - 1) +#define PSS_MASK_ONE_POS PSS_MASK_ZERO_COUNT + +/* Where the salt starts. */ +#define PSS_MASK_SALT_POS (PSS_MASK_ONE_POS + 1) + +static const uint8_t pss_zeros[8] = {0}; + +typedef fsp_err_t (* r_sce_rsa_modular_exponent_encrypt_private_t)(uint32_t * InData_KeyIndex, uint32_t * InData_Text, + uint32_t * OutData_Text); +r_sce_rsa_modular_exponent_encrypt_private_t p_rsa_modular_exponent_encrypt; + +extern fsp_err_t R_SCE_Rsa2048ModularExponentEncryptPrivate(uint32_t * InData_KeyIndex, + uint32_t * InData_Text, + uint32_t * OutData_Text); +extern fsp_err_t R_SCE_Rsa3072ModularExponentEncryptPrivate(uint32_t * InData_KeyIndex, + uint32_t * InData_Text, + uint32_t * OutData_Text); + +/* + * Compute the RSA-PSS mask-generation function, MGF1. Assumptions + * are that the mask length will be less than 256 * PSS_HLEN, and + * therefore we never need to increment anything other than the low + * byte of the counter. + * + * This is described in PKCS#1, B.2.1. + */ +static void +pss_mgf1(uint8_t *mask, const uint8_t *hash) +{ + bootutil_sha256_context ctx; + uint8_t counter[4] = { 0, 0, 0, 0 }; + uint8_t htmp[PSS_HLEN]; + int count = PSS_MASK_LEN; + int bytes; + + while (count > 0) { + bootutil_sha256_init(&ctx); + bootutil_sha256_update(&ctx, hash, PSS_HLEN); + bootutil_sha256_update(&ctx, counter, 4); + bootutil_sha256_finish(&ctx, htmp); + + counter[3]++; + + bytes = PSS_HLEN; + if (bytes > count) + bytes = count; + + memcpy(mask, htmp, (size_t)bytes); + mask += bytes; + count -= bytes; + } + + bootutil_sha256_drop(&ctx); +} + +/* + * Validate an RSA signature, using RSA-PSS, as described in PKCS #1 + * v2.2, section 9.1.2, with many parameters required to have fixed + * values. + */ +static fih_int +sce9_bootutil_cmp_rsasig(uint8_t * pub_key, uint8_t *hash, uint32_t hlen, + uint8_t *sig) +{ + bootutil_sha256_context shactx; + uint8_t em[PSS_EMLEN]; + uint8_t db_mask[PSS_MASK_LEN]; + uint8_t h2[PSS_HLEN]; + int i; + int rc = 0; + fih_int fih_rc = FIH_FAILURE; + SCE_KEY_INDEX_TYPE key_type = SCE_KEY_INDEX_TYPE_INVALID; + + #if (MCUBOOT_SIGN_RSA_LEN == 2048) + p_rsa_modular_exponent_encrypt = R_SCE_Rsa2048ModularExponentEncryptPrivate; + key_type = SCE_KEY_INDEX_TYPE_RSA2048_PUBLIC; + #elif (MCUBOOT_SIGN_RSA_LEN == 3072) + p_rsa_modular_exponent_encrypt = R_SCE_Rsa3072ModularExponentEncryptPrivate; + key_type = SCE_KEY_INDEX_TYPE_RSA3072_PUBLIC; + #endif + + if (hlen != PSS_HLEN) { + rc = -1; + goto out; + } + sce_rsa_byte_data_t local_data; + sce_rsa_byte_data_t local_cipher; + local_data.pdata = sig; + local_data.data_length = MCUBOOT_SIGN_RSA_LEN; + + local_cipher.pdata = em; + local_cipher.data_length = sizeof(em); + + memcpy((uint8_t *) &rsa_public_key_installed.value, pub_key, sizeof(rsa_public_key_installed.value)); + rsa_public_key_installed.type = key_type; + if (p_rsa_modular_exponent_encrypt((uint32_t *) &rsa_public_key_installed.value, (uint32_t *) local_data.pdata, + (uint32_t *) local_cipher.pdata)) + { + rc = -1; + goto out; + } + + /* + * PKCS #1 v2.2, 9.1.2 EMSA-PSS-Verify + * + * emBits is 2048 + * emLen = ceil(emBits/8) = 256 + * + * The salt length is not known at the beginning. + */ + + /* Step 1. The message is constrained by the address space of a + * 32-bit processor, which is far less than the 2^61-1 limit of + * SHA-256. + */ + + /* Step 2. mHash is passed in as 'hash', with hLen the hlen + * argument. */ + + /* Step 3. if emLen < hLen + sLen + 2, inconsistent and stop. + * The salt length is not known at this point. + */ + + /* Step 4. If the rightmost octet of EM does have the value + * 0xbc, output inconsistent and stop. + */ + if (em[PSS_EMLEN - 1] != 0xbc) { + rc = -1; + goto out; + } + + /* Step 5. Let maskedDB be the leftmost emLen - hLen - 1 octets + * of EM, and H be the next hLen octets. + * + * maskedDB is then the first 256 - 32 - 1 = 0-222 + * H is 32 bytes 223-254 + */ + + /* Step 6. If the leftmost 8emLen - emBits bits of the leftmost + * octet in maskedDB are not all equal to zero, output + * inconsistent and stop. + * + * 8emLen - emBits is zero, so there is nothing to test here. + */ + + /* Step 7. let dbMask = MGF(H, emLen - hLen - 1). */ + pss_mgf1(db_mask, &em[PSS_HASH_OFFSET]); + + /* Step 8. let DB = maskedDB xor dbMask. + * To avoid needing an additional buffer, store the 'db' in the + * same buffer as db_mask. From now, to the end of this function, + * db_mask refers to the unmasked 'db'. */ + for (i = 0; i < PSS_MASK_LEN; i++) { + db_mask[i] ^= em[i]; + } + + /* Step 9. Set the leftmost 8emLen - emBits bits of the leftmost + * octet in DB to zero. + * pycrypto seems to always make the emBits 2047, so we need to + * clear the top bit. */ + db_mask[0] &= 0x7F; + + /* Step 10. If the emLen - hLen - sLen - 2 leftmost octets of DB + * are not zero or if the octet at position emLen - hLen - sLen - + * 1 (the leftmost position is "position 1") does not have + * hexadecimal value 0x01, output "inconsistent" and stop. */ + for (i = 0; i < PSS_MASK_ZERO_COUNT; i++) { + if (db_mask[i] != 0) { + rc = -1; + goto out; + } + } + + if (db_mask[PSS_MASK_ONE_POS] != 1) { + rc = -1; + goto out; + } + + /* Step 11. Let salt be the last sLen octets of DB */ + + /* Step 12. Let M' = 0x00 00 00 00 00 00 00 00 || mHash || salt; */ + + /* Step 13. Let H' = Hash(M') */ + bootutil_sha256_init(&shactx); + bootutil_sha256_update(&shactx, pss_zeros, 8); + bootutil_sha256_update(&shactx, hash, PSS_HLEN); + bootutil_sha256_update(&shactx, &db_mask[PSS_MASK_SALT_POS], PSS_SLEN); + bootutil_sha256_finish(&shactx, h2); + bootutil_sha256_drop(&shactx); + + /* Step 14. If H = H', output "consistent". Otherwise, output + * "inconsistent". */ + FIH_CALL(boot_fih_memequal, fih_rc, h2, &em[PSS_HASH_OFFSET], PSS_HLEN); + +out: + if (rc) { + fih_rc = fih_int_encode(rc); + } + + FIH_RET(fih_rc); +} + +fih_int +bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig, size_t slen, + uint8_t key_id) +{ + fih_int fih_rc = FIH_FAILURE; + uint8_t * pubkey; + + if (slen != RM_MCUBOOT_PORT_BITS_TO_BYTES(MCUBOOT_SIGN_RSA_LEN)) + { + goto out; + } + + pubkey = (uint8_t *) bootutil_keys_wrapped[key_id].key; + FIH_CALL(sce9_bootutil_cmp_rsasig, fih_rc, pubkey, hash, hlen, sig); + +out: + FIH_RET(fih_rc); +} + + #endif /* MCUBOOT_USE_USER_DEFINED_CRYPTO_STACK */ +#endif /* MCUBOOT_SIGN_RSA */ diff --git a/ra/fsp/src/rm_mcuboot_port/crypto/sce9_keys.c b/ra/fsp/src/rm_mcuboot_port/crypto/sce9_keys.c index 49a7dd1c4..ecdb20a15 100644 --- a/ra/fsp/src/rm_mcuboot_port/crypto/sce9_keys.c +++ b/ra/fsp/src/rm_mcuboot_port/crypto/sce9_keys.c @@ -26,70 +26,101 @@ #if defined MCUBOOT_USE_USER_DEFINED_CRYPTO_STACK #if defined(MCUBOOT_SIGN_RSA) #define HAVE_KEYS -const uint8_t g_pub_key[MCUBOOT_SCE9_MAX_RSA_KEY_SIZE_BYTES] BSP_PLACE_IN_SECTION(".mcuboot_sce9_key") = + #if MCUBOOT_SIGN_RSA_LEN == 2048 +const uint8_t g_pub_key[MCUBOOT_SCE9_ALIGNED_RSA_KEY_SIZE_BYTES] BSP_PLACE_IN_SECTION(".mcuboot_sce9_key") = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + #elif MCUBOOT_SIGN_RSA_LEN == 3072 +const uint8_t g_pub_key[MCUBOOT_SCE9_ALIGNED_RSA_KEY_SIZE_BYTES] BSP_PLACE_IN_SECTION(".mcuboot_sce9_key") = +{ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + #endif const unsigned int g_pub_key_len_bytes = sizeof(g_pub_key); #elif defined(MCUBOOT_SIGN_EC256) #define HAVE_KEYS const uint8_t g_pub_key[MCUBOOT_SCE9_ALIGNED_ECC_KEY_SIZE_BYTES] BSP_PLACE_IN_SECTION(".mcuboot_sce9_key") = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; const unsigned int g_pub_key_len_bytes = SCE_OEM_KEY_SIZE_ECCP256_PUBLICK_KEY_INST_DATA_WORD * 4U; diff --git a/ra/fsp/src/rm_mcuboot_port/crypto/sce9_keys.h b/ra/fsp/src/rm_mcuboot_port/crypto/sce9_keys.h index 0fe720d8a..e1253b90d 100644 --- a/ra/fsp/src/rm_mcuboot_port/crypto/sce9_keys.h +++ b/ra/fsp/src/rm_mcuboot_port/crypto/sce9_keys.h @@ -23,8 +23,12 @@ #include "mcuboot_config/mcuboot_config.h" #include +#define MCUBOOT_MIN_FLASH_WRITE_SIZE BSP_FEATURE_FLASH_HP_CF_WRITE_SIZE + extern const struct bootutil_key bootutil_keys_wrapped[]; +#define RM_MCUBOOT_PORT_BITS_TO_BYTES(bits) (((bits) + 7) / 8) + #if defined(MCUBOOT_SIGN_EC256) /* NUM_ECC_BYTES is the size of the P256 private key. @@ -35,6 +39,18 @@ extern const struct bootutil_key bootutil_keys_wrapped[]; * aligned to the flash write size. */ #define MCUBOOT_SCE9_ALIGNED_ECC_KEY_SIZE_BYTES (128U) +#elif defined(MCUBOOT_SIGN_RSA) + #if MCUBOOT_SIGN_RSA_LEN == 2048 + #define MCUBOOT_SCE9_MAX_RSA_KEY_SIZE_BYTES (sizeof(sce_rsa2048_public_wrapped_key_t)) + #elif MCUBOOT_SIGN_RSA_LEN == 3072 + #define MCUBOOT_SCE9_MAX_RSA_KEY_SIZE_BYTES (sizeof(sce_rsa3072_public_wrapped_key_t)) + #endif + +/* The size of the array designated to program the wrapped keys from RFP should + * aligned to the flash write size. */ + #define MCUBOOT_SCE9_ALIGNED_RSA_KEY_SIZE_BYTES (((MCUBOOT_SCE9_MAX_RSA_KEY_SIZE_BYTES + \ + (MCUBOOT_MIN_FLASH_WRITE_SIZE - 1)) / \ + MCUBOOT_MIN_FLASH_WRITE_SIZE) * MCUBOOT_MIN_FLASH_WRITE_SIZE) #endif #endif /* SCE9_KEYS_H */ diff --git a/ra/fsp/src/rm_mcuboot_port/rm_mcuboot_port.c b/ra/fsp/src/rm_mcuboot_port/rm_mcuboot_port.c index 19e6107bb..383a4bf67 100644 --- a/ra/fsp/src/rm_mcuboot_port/rm_mcuboot_port.c +++ b/ra/fsp/src/rm_mcuboot_port/rm_mcuboot_port.c @@ -78,22 +78,3 @@ void RM_MCUBOOT_PORT_BootApp (struct boot_rsp * rsp) { /* Set SP and branch to PC. */ start_app(app_pc, app_sp); } - -#if defined(__ARMCC_VERSION) /* AC6 compiler */ - - #if defined MCUBOOT_SIGN_EC256 && !defined MCUBOOT_USE_MBED_TLS - -/* This function is only used by MCUboot for RSA keys with mbedtls. - * When it's not used, this function should be compiled out, but AC6 has a known issue where unused functions are not compiled out - * so this function is created as a placeholder to get rid of the linker error. */ -int mbedtls_mpi_read_binary (void * X, const unsigned char * buf, size_t buflen) -{ - FSP_PARAMETER_NOT_USED(X); - FSP_PARAMETER_NOT_USED(buf); - FSP_PARAMETER_NOT_USED(buflen); - - return 0; -} - - #endif -#endif diff --git a/ra/fsp/src/rm_ob1203/light_mode/rm_ob1203_light_mode.c b/ra/fsp/src/rm_ob1203/light_mode/rm_ob1203_light_mode.c new file mode 100644 index 000000000..e849a0996 --- /dev/null +++ b/ra/fsp/src/rm_ob1203/light_mode/rm_ob1203_light_mode.c @@ -0,0 +1,603 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/********************************************************************************************************************** + * Includes , "Project Includes" + *********************************************************************************************************************/ +#if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) + #include "r_ob1203_if.h" +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) + #include "r_ob1203_if.h" +#else + #define RM_OB1203_LIGHT_MODE_ENABLE (1) +#endif + +#if RM_OB1203_LIGHT_MODE_ENABLE + #include "rm_ob1203.h" + +/********************************************************************************************************************** + * Macro definitions + *********************************************************************************************************************/ + +/* Definitions of Command */ + #define RM_OB1203_COMMAND_MEASUREMENT_START (0x01) + #define RM_OB1203_COMMAND_INTERRUPT_ENABLE (0x01) + +/* Definitions of Register address */ + #define RM_OB1203_REG_ADDR_LS_CLEAR_DATA_0 (0x04) // LS Clear measurement data, LSB + #define RM_OB1203_REG_ADDR_LS_GREEN_DATA_0 (0x07) // LS Green/LS measurement data, LSB + #define RM_OB1203_REG_ADDR_LS_BLUE_DATA_0 (0x0A) // LS Blue measurement data, LSB + #define RM_OB1203_REG_ADDR_LS_RED_DATA_0 (0x0D) // LS Red measurement data, LSB + #define RM_OB1203_REG_ADDR_COMP_DATA_0 (0x10) // LS Comp measurement data, LSB + #define RM_OB1203_REG_ADDR_LS_RES_PERIOD (0x22) // LS resolution and measurement period setting + #define RM_OB1203_REG_ADDR_LS_GAIN (0x23) // LS analog gain range setting + #define RM_OB1203_REG_ADDR_LS_THRES_UP_0 (0x24) // LS interrupt upper threshold, LSB + +/* Definitions of Mask */ + #define RM_OB1203_MASK_PERSIST (0x0F) + #define RM_OB1203_MASK_DATA (0x0F) + #define RM_OB1203_MASK_8BITS (0x000000FF) + #define RM_OB1203_MASK_THRESHOLD (0x000FFFFF) + +/* Definitions of Calculation */ + #define RM_OB1203_MAX_NUM_LIGHT_SOURCE (5) + +/********************************************************************************************************************** + * Local Typedef definitions + *********************************************************************************************************************/ + +/********************************************************************************************************************** + * Exported global functions + *********************************************************************************************************************/ +extern fsp_err_t rm_ob1203_read(rm_ob1203_ctrl_t * const p_api_ctrl, rm_comms_write_read_params_t write_read_params); +extern fsp_err_t rm_ob1203_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t * const p_src, uint8_t const bytes); +extern fsp_err_t rm_ob1203_main_ctrl_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const main_ctrl_0, + uint8_t const main_ctrl_1); +extern fsp_err_t rm_ob1203_int_cfg_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const int_cfg_0, + uint8_t const int_cfg_1, + uint8_t const int_pst); +extern fsp_err_t rm_ob1203_all_interrupt_bits_clear(rm_ob1203_ctrl_t * const p_api_ctrl); + + #if BSP_CFG_RTOS +extern fsp_err_t rm_ob1203_os_semaphore_acquire(rm_ob1203_semaphore_t const * p_semaphore, uint32_t const timeout); + + #endif + +/********************************************************************************************************************** + * Private (static) variables and functions + *********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_open(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_cfg_t const * const p_cfg); +static fsp_err_t rm_ob1203_light_close(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_light_measurement_start(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_light_measurement_stop(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_light_read(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type); +static fsp_err_t rm_ob1203_light_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_light_prox_read(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data); +static fsp_err_t rm_ob1203_light_prox_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_light_ppg_read(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples); +static fsp_err_t rm_ob1203_light_ppg_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_light_gain_set(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_gain_t const gain); +static fsp_err_t rm_ob1203_light_led_current_set(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_led_current_t const led_current); +static fsp_err_t rm_ob1203_light_device_interrupt_cfg_set(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg); +static fsp_err_t rm_ob1203_light_fifo_info_get(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_fifo_info_t * const p_fifo_info); +static fsp_err_t rm_ob1203_light_device_status_get(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_status_t * const p_status); + +/********************************************************************************************************************** + * Exported global variables + *********************************************************************************************************************/ +rm_ob1203_api_t const g_ob1203_on_ob1203_light = +{ + .open = rm_ob1203_light_open, + .close = rm_ob1203_light_close, + .measurementStart = rm_ob1203_light_measurement_start, + .measurementStop = rm_ob1203_light_measurement_stop, + .lightRead = rm_ob1203_light_read, + .lightDataCalculate = rm_ob1203_light_data_calculate, + .proxRead = rm_ob1203_light_prox_read, + .proxDataCalculate = rm_ob1203_light_prox_data_calculate, + .ppgRead = rm_ob1203_light_ppg_read, + .ppgDataCalculate = rm_ob1203_light_ppg_data_calculate, + .gainSet = rm_ob1203_light_gain_set, + .ledCurrentSet = rm_ob1203_light_led_current_set, + .deviceInterruptCfgSet = rm_ob1203_light_device_interrupt_cfg_set, + .fifoInfoGet = rm_ob1203_light_fifo_info_get, + .deviceStatusGet = rm_ob1203_light_device_status_get, +}; + +/*********************************************************************************************************************** + * Functions + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief Configures the OB1203 Light mode. + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_open (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_cfg_t const * const p_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint32_t threshold_tmp; + uint8_t int_cfg_0 = 0x00; + uint8_t int_pst = 0x00; + + FSP_PARAMETER_NOT_USED(p_cfg); + + /* Set gain */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_LS_GAIN; + p_ctrl->buf[1] = (uint8_t) p_ctrl->p_mode->light_gain; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set resolution and measurement period */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_LS_RES_PERIOD; + p_ctrl->buf[1] = (uint8_t) p_ctrl->p_mode->light_resolution_period; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set thresholds */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_LS_THRES_UP_0; + threshold_tmp = p_ctrl->p_mode->light_upper_threshold & RM_OB1203_MASK_THRESHOLD; + p_ctrl->buf[1] = (uint8_t) (threshold_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) ((threshold_tmp >> 8) & RM_OB1203_MASK_8BITS); + p_ctrl->buf[3] = (uint8_t) ((threshold_tmp >> 16) & RM_OB1203_MASK_8BITS); + threshold_tmp = p_ctrl->p_mode->light_lower_threshold & RM_OB1203_MASK_THRESHOLD; + p_ctrl->buf[4] = (uint8_t) (threshold_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[5] = (uint8_t) ((threshold_tmp >> 8) & RM_OB1203_MASK_8BITS); + p_ctrl->buf[6] = (uint8_t) ((threshold_tmp >> 16) & RM_OB1203_MASK_8BITS); + p_ctrl->buf[7] = (uint8_t) p_ctrl->p_mode->light_variance_threshold; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 8); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set device interrupt configurations */ + if (NULL != p_ctrl->p_irq_instance) + { + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_LIGHT; + int_cfg_0 = (uint8_t) ((uint8_t) p_ctrl->p_mode->light_interrupt_source | + (uint8_t) p_ctrl->p_mode->light_interrupt_type | + RM_OB1203_COMMAND_INTERRUPT_ENABLE); + int_pst = (uint8_t) ((p_ctrl->p_mode->light_interrupt_persist & RM_OB1203_MASK_PERSIST) << 4); + } + else + { + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_STANDBY; + int_cfg_0 = 0x00; + int_pst = 0x00; + } + + err = rm_ob1203_int_cfg_register_write(p_ctrl, int_cfg_0, 0x00, int_pst); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_close (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Start a periodic measurement + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_measurement_start (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t main_ctrl_0; + + /* Start measurement */ + main_ctrl_0 = + (uint8_t) ((uint8_t) p_ctrl->p_mode->light_sleep | (uint8_t) p_ctrl->p_mode->light_sensor_mode | + RM_OB1203_COMMAND_MEASUREMENT_START); + err = rm_ob1203_main_ctrl_register_write(p_ctrl, main_ctrl_0, 0x00); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Stop a periodic measurement + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_measurement_stop (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + if (RM_OB1203_OPERATION_MODE_LIGHT == p_ctrl->p_mode->mode_irq) + { + /* Clear interrupt bits after measurement stop */ + p_ctrl->interrupt_bits_clear = true; + } + + /* Stop measurement */ + err = rm_ob1203_main_ctrl_register_write(p_ctrl, 0x00, 0x00); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + #if BSP_CFG_RTOS + if (RM_OB1203_OPERATION_MODE_LIGHT == p_ctrl->p_mode->mode_irq) + { + /* Acquire a semaphore */ + err = rm_ob1203_os_semaphore_acquire(p_ctrl->p_semaphore, p_ctrl->p_cfg->semaphore_timeout); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Clear all interrupt bits */ + err = rm_ob1203_all_interrupt_bits_clear(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + } + #endif + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Reads light ADC data from OB1203 device. If device interrupt is enabled, interrupt bits are cleared after data read. + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_read (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t reg_addr; + uint8_t bytes = 0; + rm_comms_write_read_params_t write_read_params; + + /* Set light data type */ + p_ctrl->p_mode->light_data_type = type; + + /* Set bytes to read. */ + if (RM_OB1203_LIGHT_DATA_TYPE_ALL != type) + { + bytes = 3; + } + else + { + bytes = 3 * RM_OB1203_MAX_NUM_LIGHT_SOURCE; + } + + /* Set register address */ + switch (type) + { + case RM_OB1203_LIGHT_DATA_TYPE_GREEN: + { + reg_addr = RM_OB1203_REG_ADDR_LS_GREEN_DATA_0; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_BLUE: + { + reg_addr = RM_OB1203_REG_ADDR_LS_BLUE_DATA_0; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_RED: + { + reg_addr = RM_OB1203_REG_ADDR_LS_RED_DATA_0; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_COMP: + { + reg_addr = RM_OB1203_REG_ADDR_COMP_DATA_0; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_ALL: + case RM_OB1203_LIGHT_DATA_TYPE_CLEAR: + default: + { + reg_addr = RM_OB1203_REG_ADDR_LS_CLEAR_DATA_0; + break; + } + } + + if (RM_OB1203_OPERATION_MODE_LIGHT == p_ctrl->p_mode->mode_irq) + { + /* Clear interrupt bits after data read */ + p_ctrl->interrupt_bits_clear = true; + } + + /* Read light data. */ + p_ctrl->register_address = reg_addr; + write_read_params.p_src = &p_ctrl->register_address; + write_read_params.src_bytes = 1; + write_read_params.p_dest = (uint8_t *) p_raw_data; + write_read_params.dest_bytes = bytes; + err = rm_ob1203_read(p_ctrl, write_read_params); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + #if BSP_CFG_RTOS + if (RM_OB1203_OPERATION_MODE_LIGHT == p_ctrl->p_mode->mode_irq) + { + /* Acquire a semaphore */ + err = rm_ob1203_os_semaphore_acquire(p_ctrl->p_semaphore, p_ctrl->p_cfg->semaphore_timeout); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Clear all interrupt bits */ + err = rm_ob1203_all_interrupt_bits_clear(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + } + #endif + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Calculate light data from raw data. + * + * @retval FSP_SUCCESS Successfully results are read. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data) +{ + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t i; + uint32_t * p_light_data; + + /* Set light data */ + switch (p_ctrl->p_mode->light_data_type) + { + case RM_OB1203_LIGHT_DATA_TYPE_GREEN: + { + p_light_data = &p_ob1203_data->green_data; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_BLUE: + { + p_light_data = &p_ob1203_data->blue_data; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_RED: + { + p_light_data = &p_ob1203_data->red_data; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_COMP: + { + p_light_data = &p_ob1203_data->comp_data; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_CLEAR: + case RM_OB1203_LIGHT_DATA_TYPE_ALL: + default: + { + p_light_data = &p_ob1203_data->clear_data; + break; + } + } + + /* Calculate light data */ + for (i = 0; i < RM_OB1203_MAX_NUM_LIGHT_SOURCE; i++) + { + *p_light_data = + (uint32_t) (((p_raw_data->adc_data[3 * i + 2] & RM_OB1203_MASK_DATA) << 16) + + (p_raw_data->adc_data[3 * i + 1] << 8) + + p_raw_data->adc_data[3 * i]); + + if (RM_OB1203_LIGHT_DATA_TYPE_ALL != p_ctrl->p_mode->light_data_type) + { + break; + } + + p_light_data++; + } + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_read (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(p_ob1203_data); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_ppg_read (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(number_of_samples); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_ppg_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(p_ob1203_data); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Set gain. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_gain_set (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_gain_t const gain) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set gain */ + p_ctrl->p_mode->light_gain = gain.light; + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_LS_GAIN; + p_ctrl->buf[1] = (uint8_t) p_ctrl->p_mode->light_gain; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_led_current_set (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_led_current_t const led_current) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(led_current); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Set device interrupt configurations. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_device_interrupt_cfg_set (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t int_cfg_0 = 0x00; + uint8_t int_pst = 0x00; + + /* Set device interrupt configurations */ + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_LIGHT; + p_ctrl->p_mode->light_interrupt_source = interrupt_cfg.light_source; + p_ctrl->p_mode->light_interrupt_type = interrupt_cfg.light_type; + p_ctrl->p_mode->light_interrupt_persist = interrupt_cfg.persist; + int_cfg_0 = (uint8_t) ((uint8_t) p_ctrl->p_mode->light_interrupt_source | + (uint8_t) p_ctrl->p_mode->light_interrupt_type | + RM_OB1203_COMMAND_INTERRUPT_ENABLE); + int_pst = (uint8_t) ((p_ctrl->p_mode->light_interrupt_persist & RM_OB1203_MASK_PERSIST) << 4); + + err = rm_ob1203_int_cfg_register_write(p_ctrl, int_cfg_0, 0x00, int_pst); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_fifo_info_get (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_fifo_info_t * const p_fifo_info) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_fifo_info); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_device_status_get (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_status_t * const p_status) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_status); + + return FSP_ERR_UNSUPPORTED; +} + +#endif diff --git a/ra/fsp/src/rm_ob1203/light_proximity_mode/rm_ob1203_light_proximity_mode.c b/ra/fsp/src/rm_ob1203/light_proximity_mode/rm_ob1203_light_proximity_mode.c new file mode 100644 index 000000000..dd59f0b55 --- /dev/null +++ b/ra/fsp/src/rm_ob1203/light_proximity_mode/rm_ob1203_light_proximity_mode.c @@ -0,0 +1,827 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/********************************************************************************************************************** + * Includes , "Project Includes" + *********************************************************************************************************************/ +#if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) + #include "r_ob1203_if.h" +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) + #include "r_ob1203_if.h" +#else + #define RM_OB1203_LIGHT_PROX_MODE_ENABLE (1) +#endif + +#if RM_OB1203_LIGHT_PROX_MODE_ENABLE + #include "rm_ob1203.h" + +/********************************************************************************************************************** + * Macro definitions + *********************************************************************************************************************/ + +/* Definitions of Command */ + #define RM_OB1203_COMMAND_MEASUREMENT_START (0x01) + #define RM_OB1203_COMMAND_INTERRUPT_ENABLE (0x01) + +/* Definitions of Register address */ + #define RM_OB1203_REG_ADDR_LS_CLEAR_DATA_0 (0x04) // LS Clear measurement data, LSB + #define RM_OB1203_REG_ADDR_LS_GREEN_DATA_0 (0x07) // LS Green/LS measurement data, LSB + #define RM_OB1203_REG_ADDR_LS_BLUE_DATA_0 (0x0A) // LS Blue measurement data, LSB + #define RM_OB1203_REG_ADDR_LS_RED_DATA_0 (0x0D) // LS Red measurement data, LSB + #define RM_OB1203_REG_ADDR_COMP_DATA_0 (0x10) // LS Comp measurement data, LSB + #define RM_OB1203_REG_ADDR_LS_RES_PERIOD (0x22) // LS resolution and measurement period setting + #define RM_OB1203_REG_ADDR_LS_GAIN (0x23) // LS analog gain range setting + #define RM_OB1203_REG_ADDR_LS_THRES_UP_0 (0x24) // LS interrupt upper threshold, LSB + #define RM_OB1203_REG_ADDR_PS_DATA_0 (0x02) // PS measurement data, LSB + #define RM_OB1203_REG_ADDR_PS_LED_CURR_0 (0x17) // PS LED current, LSB + #define RM_OB1203_REG_ADDR_PS_CAN_PULSES (0x19) // PS analog cancellation level and pulse setting + #define RM_OB1203_REG_ADDR_PS_PWIDTH_PERIOD (0x1A) // PS pulse width and measurement period + #define RM_OB1203_REG_ADDR_PS_CAN_DIG_0 (0x1B) // PS digital cancellation level setting, LSB + #define RM_OB1203_REG_ADDR_PS_MOV_AVG_HYS (0x1D) // PS moving average and hysteresis configuration + #define RM_OB1203_REG_ADDR_PS_THRES_UP_0 (0x1E) // PS interrupt upper threshold, LSB + +/* Definitions of Mask */ + #define RM_OB1203_MASK_PERSIST (0x0F) + #define RM_OB1203_MASK_DATA (0x0F) + #define RM_OB1203_MASK_LIGHT_THRESHOLD (0x000FFFFF) + #define RM_OB1203_MASK_LED_CURRENT (0x03FF) + #define RM_OB1203_MASK_8BITS (0xFF) + #define RM_OB1203_MASK_HYSTERESIS (0x7F) + +/* Definitions of Calculation */ + #define RM_OB1203_MAX_NUM_LIGHT_SOURCE (5) + +/********************************************************************************************************************** + * Local Typedef definitions + *********************************************************************************************************************/ + +/********************************************************************************************************************** + * Exported global functions + *********************************************************************************************************************/ +extern fsp_err_t rm_ob1203_read(rm_ob1203_ctrl_t * const p_api_ctrl, rm_comms_write_read_params_t write_read_params); +extern fsp_err_t rm_ob1203_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t * const p_src, uint8_t const bytes); +extern fsp_err_t rm_ob1203_main_ctrl_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const main_ctrl_0, + uint8_t const main_ctrl_1); +extern fsp_err_t rm_ob1203_int_cfg_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const int_cfg_0, + uint8_t const int_cfg_1, + uint8_t const int_pst); +extern fsp_err_t rm_ob1203_ppg_ps_gain_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t const ppg_ps_gain); +extern fsp_err_t rm_ob1203_ppg_ps_cfg_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t const ppg_ps_cfg); +extern fsp_err_t rm_ob1203_all_interrupt_bits_clear(rm_ob1203_ctrl_t * const p_api_ctrl); + + #if BSP_CFG_RTOS +extern fsp_err_t rm_ob1203_os_semaphore_acquire(rm_ob1203_semaphore_t const * p_semaphore, uint32_t const timeout); + + #endif + +/********************************************************************************************************************** + * Private (static) variables and functions + *********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_open(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_cfg_t const * const p_cfg); +static fsp_err_t rm_ob1203_light_prox_close(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_light_prox_measurement_start(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_light_prox_measurement_stop(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_light_prox_light_read(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type); +static fsp_err_t rm_ob1203_light_prox_light_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_light_prox_prox_read(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data); +static fsp_err_t rm_ob1203_light_prox_prox_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_light_prox_ppg_read(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples); +static fsp_err_t rm_ob1203_light_prox_ppg_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_light_prox_gain_set(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_gain_t const gain); +static fsp_err_t rm_ob1203_light_prox_led_current_set(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_led_current_t const led_current); +static fsp_err_t rm_ob1203_light_prox_device_interrupt_cfg_set(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg); +static fsp_err_t rm_ob1203_light_prox_fifo_info_get(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_fifo_info_t * const p_fifo_info); +static fsp_err_t rm_ob1203_light_prox_device_status_get(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_status_t * const p_status); + +static fsp_err_t rm_ob1203_light_configuration(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_prox_configuration(rm_ob1203_ctrl_t * const p_api_ctrl); + +/********************************************************************************************************************** + * Exported global variables + *********************************************************************************************************************/ +rm_ob1203_api_t const g_ob1203_on_ob1203_light_proximity = +{ + .open = rm_ob1203_light_prox_open, + .close = rm_ob1203_light_prox_close, + .measurementStart = rm_ob1203_light_prox_measurement_start, + .measurementStop = rm_ob1203_light_prox_measurement_stop, + .lightRead = rm_ob1203_light_prox_light_read, + .lightDataCalculate = rm_ob1203_light_prox_light_data_calculate, + .proxRead = rm_ob1203_light_prox_prox_read, + .proxDataCalculate = rm_ob1203_light_prox_prox_data_calculate, + .ppgRead = rm_ob1203_light_prox_ppg_read, + .ppgDataCalculate = rm_ob1203_light_prox_ppg_data_calculate, + .gainSet = rm_ob1203_light_prox_gain_set, + .ledCurrentSet = rm_ob1203_light_prox_led_current_set, + .deviceInterruptCfgSet = rm_ob1203_light_prox_device_interrupt_cfg_set, + .fifoInfoGet = rm_ob1203_light_prox_fifo_info_get, + .deviceStatusGet = rm_ob1203_light_prox_device_status_get, +}; + +/*********************************************************************************************************************** + * Functions + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief Configures the OB1203 Light Proximity mode. + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_open (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_cfg_t const * const p_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t int_cfg_0 = 0x00; + uint8_t int_cfg_1 = 0x00; + uint8_t int_pst = 0x00; + + FSP_PARAMETER_NOT_USED(p_cfg); + + /* Light mode configuration */ + err = rm_ob1203_light_configuration(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Proximity mode configuration */ + err = rm_ob1203_prox_configuration(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set device interrupt configurations */ + if (NULL != p_ctrl->p_irq_instance) + { + switch (p_ctrl->p_mode->mode_irq) + { + case RM_OB1203_OPERATION_MODE_LIGHT: + { + int_cfg_0 = (uint8_t) ((uint8_t) p_ctrl->p_mode->light_interrupt_source | + (uint8_t) p_ctrl->p_mode->light_interrupt_type | + RM_OB1203_COMMAND_INTERRUPT_ENABLE); + int_cfg_1 = 0x00; + int_pst = (uint8_t) ((p_ctrl->p_mode->light_interrupt_persist & RM_OB1203_MASK_PERSIST) << 4); + break; + } + + case RM_OB1203_OPERATION_MODE_PROXIMITY: + { + int_cfg_0 = 0x00; + int_cfg_1 = + (uint8_t) ((uint8_t) p_ctrl->p_mode->prox_interrupt_type | RM_OB1203_COMMAND_INTERRUPT_ENABLE); + int_pst = (uint8_t) (p_ctrl->p_mode->prox_interrupt_persist & RM_OB1203_MASK_PERSIST); + break; + } + + default: + { + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_STANDBY; + int_cfg_0 = 0x00; + int_cfg_1 = 0x00; + int_pst = 0x00; + break; + } + } + } + else + { + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_STANDBY; + int_cfg_0 = 0x00; + int_cfg_1 = 0x00; + int_pst = 0x00; + } + + err = rm_ob1203_int_cfg_register_write(p_ctrl, int_cfg_0, int_cfg_1, int_pst); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_close (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Start periodic measurements in both Light mode and Proximity mode + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_measurement_start (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t main_ctrl_0; + uint8_t main_ctrl_1; + + /* Start measurement */ + main_ctrl_0 = + (uint8_t) ((uint8_t) p_ctrl->p_mode->light_sleep | (uint8_t) p_ctrl->p_mode->light_sensor_mode | + RM_OB1203_COMMAND_MEASUREMENT_START); + main_ctrl_1 = (uint8_t) ((uint8_t) p_ctrl->p_mode->prox_sleep | RM_OB1203_COMMAND_MEASUREMENT_START); + err = rm_ob1203_main_ctrl_register_write(p_ctrl, main_ctrl_0, main_ctrl_1); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Stop a periodic measurement + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_measurement_stop (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + if (RM_OB1203_OPERATION_MODE_STANDBY != p_ctrl->p_mode->mode_irq) + { + /* Clear interrupt bits after measurement stop */ + p_ctrl->interrupt_bits_clear = true; + } + + /* Stop measurement */ + err = rm_ob1203_main_ctrl_register_write(p_ctrl, 0x00, 0x00); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + #if BSP_CFG_RTOS + if (RM_OB1203_OPERATION_MODE_STANDBY != p_ctrl->p_mode->mode_irq) + { + /* Acquire a semaphore */ + err = rm_ob1203_os_semaphore_acquire(p_ctrl->p_semaphore, p_ctrl->p_cfg->semaphore_timeout); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Clear all interrupt bits */ + err = rm_ob1203_all_interrupt_bits_clear(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + } + #endif + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Reads light ADC data from OB1203 device. If device interrupt is enabled, interrupt bits are cleared after data read. + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_light_read (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t reg_addr; + uint8_t bytes = 0; + rm_comms_write_read_params_t write_read_params; + + /* Set light data type */ + p_ctrl->p_mode->light_data_type = type; + + /* Set bytes to read. */ + if (RM_OB1203_LIGHT_DATA_TYPE_ALL != type) + { + bytes = 3; + } + else + { + bytes = 3 * RM_OB1203_MAX_NUM_LIGHT_SOURCE; + } + + /* Set register address */ + switch (type) + { + case RM_OB1203_LIGHT_DATA_TYPE_GREEN: + { + reg_addr = RM_OB1203_REG_ADDR_LS_GREEN_DATA_0; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_BLUE: + { + reg_addr = RM_OB1203_REG_ADDR_LS_BLUE_DATA_0; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_RED: + { + reg_addr = RM_OB1203_REG_ADDR_LS_RED_DATA_0; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_COMP: + { + reg_addr = RM_OB1203_REG_ADDR_COMP_DATA_0; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_ALL: + case RM_OB1203_LIGHT_DATA_TYPE_CLEAR: + default: + { + reg_addr = RM_OB1203_REG_ADDR_LS_CLEAR_DATA_0; + break; + } + } + + if (RM_OB1203_OPERATION_MODE_LIGHT == p_ctrl->p_mode->mode_irq) + { + /* Clear interrupt bits after data read */ + p_ctrl->interrupt_bits_clear = true; + } + + /* Read light data. */ + p_ctrl->register_address = reg_addr; + write_read_params.p_src = &p_ctrl->register_address; + write_read_params.src_bytes = 1; + write_read_params.p_dest = (uint8_t *) p_raw_data; + write_read_params.dest_bytes = bytes; + err = rm_ob1203_read(p_ctrl, write_read_params); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + #if BSP_CFG_RTOS + if (RM_OB1203_OPERATION_MODE_LIGHT == p_ctrl->p_mode->mode_irq) + { + /* Acquire a semaphore */ + err = rm_ob1203_os_semaphore_acquire(p_ctrl->p_semaphore, p_ctrl->p_cfg->semaphore_timeout); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Clear all interrupt bits */ + err = rm_ob1203_all_interrupt_bits_clear(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + } + #endif + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Calculate light data from raw data. + * + * @retval FSP_SUCCESS Successfully results are read. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_light_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data) +{ + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t i; + uint32_t * p_light_data; + + /* Set light data */ + switch (p_ctrl->p_mode->light_data_type) + { + case RM_OB1203_LIGHT_DATA_TYPE_GREEN: + { + p_light_data = &p_ob1203_data->green_data; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_BLUE: + { + p_light_data = &p_ob1203_data->blue_data; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_RED: + { + p_light_data = &p_ob1203_data->red_data; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_COMP: + { + p_light_data = &p_ob1203_data->comp_data; + break; + } + + case RM_OB1203_LIGHT_DATA_TYPE_CLEAR: + case RM_OB1203_LIGHT_DATA_TYPE_ALL: + default: + { + p_light_data = &p_ob1203_data->clear_data; + break; + } + } + + /* Calculate light data */ + for (i = 0; i < RM_OB1203_MAX_NUM_LIGHT_SOURCE; i++) + { + *p_light_data = + (uint32_t) (((p_raw_data->adc_data[3 * i + 2] & RM_OB1203_MASK_DATA) << 16) + + (p_raw_data->adc_data[3 * i + 1] << 8) + + p_raw_data->adc_data[3 * i]); + + if (RM_OB1203_LIGHT_DATA_TYPE_ALL != p_ctrl->p_mode->light_data_type) + { + break; + } + + p_light_data++; + } + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Reads proximity ADC data from OB1203 device. If device interrupt is enabled, interrupt bits are cleared after data read. + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_prox_read (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + rm_comms_write_read_params_t write_read_params; + + if (RM_OB1203_OPERATION_MODE_PROXIMITY == p_ctrl->p_mode->mode_irq) + { + /* Clear interrupt bits after data read */ + p_ctrl->interrupt_bits_clear = true; + } + + /* Read proximity data. */ + p_ctrl->register_address = RM_OB1203_REG_ADDR_PS_DATA_0; + write_read_params.p_src = &p_ctrl->register_address; + write_read_params.src_bytes = 1; + write_read_params.p_dest = (uint8_t *) p_raw_data; + write_read_params.dest_bytes = 2; + err = rm_ob1203_read(p_ctrl, write_read_params); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + #if BSP_CFG_RTOS + if (RM_OB1203_OPERATION_MODE_PROXIMITY == p_ctrl->p_mode->mode_irq) + { + /* Acquire a semaphore */ + err = rm_ob1203_os_semaphore_acquire(p_ctrl->p_semaphore, p_ctrl->p_cfg->semaphore_timeout); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Clear all interrupt bits */ + err = rm_ob1203_all_interrupt_bits_clear(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + } + #endif + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Calculate proximity data from raw data. + * + * @retval FSP_SUCCESS Successfully results are read. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_prox_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + + /* Calculate proximity data */ + p_ob1203_data->proximity_data = (uint16_t) ((p_raw_data->adc_data[1] << 8) + p_raw_data->adc_data[0]); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_ppg_read (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(number_of_samples); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_ppg_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(p_ob1203_data); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Set gains for both Light and Proximity. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_gain_set (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_gain_t const gain) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set flag */ + p_ctrl->prox_gain_update = true; + + /* Set gain */ + p_ctrl->p_mode->light_gain = gain.light; + p_ctrl->p_mode->ppg_prox_gain = gain.ppg_prox; + + /* Set Light mode gain */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_LS_GAIN; + p_ctrl->buf[1] = (uint8_t) p_ctrl->p_mode->light_gain; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + #if BSP_CFG_RTOS + + /* Acquire a semaphore */ + err = rm_ob1203_os_semaphore_acquire(p_ctrl->p_semaphore, p_ctrl->p_cfg->semaphore_timeout); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set Proximity mode gain */ + err = rm_ob1203_ppg_ps_gain_register_write(p_ctrl, (uint8_t) p_ctrl->p_mode->ppg_prox_gain); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + #endif + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Set current for Proximity mode. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_led_current_set (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_led_current_t const led_current) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint16_t current_tmp; + + /* Set LED current */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_LED_CURR_0; + if (RM_OB1203_LED_IR_FIRST_RED_SECOND == p_ctrl->p_mode->led_order) + { + p_ctrl->p_mode->prox_led_current = led_current.ir_led & RM_OB1203_MASK_LED_CURRENT; + } + else + { + p_ctrl->p_mode->prox_led_current = led_current.red_led & RM_OB1203_MASK_LED_CURRENT; + } + + current_tmp = p_ctrl->p_mode->prox_led_current; + p_ctrl->buf[1] = (uint8_t) (current_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) (current_tmp >> 8); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 3); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Set device interrupt configurations. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + * @retval FSP_ERR_INVALID_MODE Invalid mode. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_device_interrupt_cfg_set (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t int_cfg_0 = 0x00; + uint8_t int_cfg_1 = 0x00; + uint8_t int_pst = 0x00; + + #if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ERROR_RETURN(((RM_OB1203_OPERATION_MODE_LIGHT == interrupt_cfg.light_prox_mode) || + (RM_OB1203_OPERATION_MODE_PROXIMITY == interrupt_cfg.light_prox_mode)), + FSP_ERR_INVALID_MODE); + #endif + + /* Set device interrupt configurations */ + if (RM_OB1203_OPERATION_MODE_LIGHT == interrupt_cfg.light_prox_mode) + { + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_LIGHT; + p_ctrl->p_mode->light_interrupt_source = interrupt_cfg.light_source; + p_ctrl->p_mode->light_interrupt_type = interrupt_cfg.light_type; + p_ctrl->p_mode->light_interrupt_persist = interrupt_cfg.persist; + int_cfg_0 = (uint8_t) ((uint8_t) p_ctrl->p_mode->light_interrupt_source | + (uint8_t) p_ctrl->p_mode->light_interrupt_type | + RM_OB1203_COMMAND_INTERRUPT_ENABLE); + int_cfg_1 = 0x00; + int_pst = (uint8_t) ((p_ctrl->p_mode->light_interrupt_persist & RM_OB1203_MASK_PERSIST) << 4); + } + else + { + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_PROXIMITY; + p_ctrl->p_mode->prox_interrupt_type = interrupt_cfg.prox_type; + p_ctrl->p_mode->prox_interrupt_persist = interrupt_cfg.persist; + int_cfg_0 = 0x00; + int_cfg_1 = + (uint8_t) ((uint8_t) p_ctrl->p_mode->prox_interrupt_type | RM_OB1203_COMMAND_INTERRUPT_ENABLE); + int_pst = (uint8_t) (p_ctrl->p_mode->prox_interrupt_persist & RM_OB1203_MASK_PERSIST); + } + + err = rm_ob1203_int_cfg_register_write(p_ctrl, int_cfg_0, int_cfg_1, int_pst); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_fifo_info_get (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_fifo_info_t * const p_fifo_info) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_fifo_info); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_prox_device_status_get (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_status_t * const p_status) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_status); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Configures the OB1203 Light mode. + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_light_configuration (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint32_t threshold_tmp; + + /* Set gain */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_LS_GAIN; + p_ctrl->buf[1] = (uint8_t) p_ctrl->p_mode->light_gain; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set resolution and measurement period */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_LS_RES_PERIOD; + p_ctrl->buf[1] = (uint8_t) p_ctrl->p_mode->light_resolution_period; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set thresholds */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_LS_THRES_UP_0; + threshold_tmp = p_ctrl->p_mode->light_upper_threshold & RM_OB1203_MASK_LIGHT_THRESHOLD; + p_ctrl->buf[1] = (uint8_t) (threshold_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) ((threshold_tmp >> 8) & RM_OB1203_MASK_8BITS); + p_ctrl->buf[3] = (uint8_t) ((threshold_tmp >> 16) & RM_OB1203_MASK_8BITS); + threshold_tmp = p_ctrl->p_mode->light_lower_threshold & RM_OB1203_MASK_LIGHT_THRESHOLD; + p_ctrl->buf[4] = (uint8_t) (threshold_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[5] = (uint8_t) ((threshold_tmp >> 8) & RM_OB1203_MASK_8BITS); + p_ctrl->buf[6] = (uint8_t) ((threshold_tmp >> 16) & RM_OB1203_MASK_8BITS); + p_ctrl->buf[7] = (uint8_t) p_ctrl->p_mode->light_variance_threshold; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 8); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Configures the OB1203 Proximity mode. + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_configuration (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint16_t current_tmp; + + /* Set gain */ + err = rm_ob1203_ppg_ps_gain_register_write(p_ctrl, (uint8_t) p_ctrl->p_mode->ppg_prox_gain); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set LED current */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_LED_CURR_0; + current_tmp = p_ctrl->p_mode->prox_led_current & RM_OB1203_MASK_LED_CURRENT; + p_ctrl->buf[1] = (uint8_t) (current_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) (current_tmp >> 8); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 3); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set LED order */ + err = rm_ob1203_ppg_ps_cfg_register_write(p_ctrl, (uint8_t) p_ctrl->p_mode->led_order); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set analog cancellation and the number of LED pulses */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_CAN_PULSES; + p_ctrl->buf[1] = (uint8_t) ((uint8_t) p_ctrl->p_mode->prox_ana_can | (uint8_t) p_ctrl->p_mode->prox_num_led_pulses); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set digital cancellation */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_CAN_DIG_0; + p_ctrl->buf[1] = (uint8_t) (p_ctrl->p_mode->prox_dig_can & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) (p_ctrl->p_mode->prox_dig_can >> 8); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 3); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set pulse width and measurement period */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_PWIDTH_PERIOD; + p_ctrl->buf[1] = (uint8_t) p_ctrl->p_mode->prox_width_period; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set moving average and hysteresis */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_MOV_AVG_HYS; + p_ctrl->buf[1] = + (uint8_t) ((uint8_t) p_ctrl->p_mode->prox_moving_average | + (uint8_t) (p_ctrl->p_mode->prox_hysteresis & RM_OB1203_MASK_HYSTERESIS)); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set thresholds */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_THRES_UP_0; + p_ctrl->buf[1] = (uint8_t) (p_ctrl->p_mode->prox_upper_threshold & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) (p_ctrl->p_mode->prox_upper_threshold >> 8); + p_ctrl->buf[3] = (uint8_t) (p_ctrl->p_mode->prox_lower_threshold & RM_OB1203_MASK_8BITS); + p_ctrl->buf[4] = (uint8_t) (p_ctrl->p_mode->prox_lower_threshold >> 8); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 5); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +#endif diff --git a/ra/fsp/src/rm_ob1203/ppg_mode/rm_ob1203_ppg_mode.c b/ra/fsp/src/rm_ob1203/ppg_mode/rm_ob1203_ppg_mode.c new file mode 100644 index 000000000..e56a390ca --- /dev/null +++ b/ra/fsp/src/rm_ob1203/ppg_mode/rm_ob1203_ppg_mode.c @@ -0,0 +1,550 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/********************************************************************************************************************** + * Includes , "Project Includes" + *********************************************************************************************************************/ +#if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) + #include "r_ob1203_if.h" +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) + #include "r_ob1203_if.h" +#else + #define RM_OB1203_PPG_MODE_ENABLE (1) +#endif + +#if RM_OB1203_PPG_MODE_ENABLE + #include "rm_ob1203.h" + +/********************************************************************************************************************** + * Macro definitions + *********************************************************************************************************************/ + +/* Definitions of Command */ + #define RM_OB1203_COMMAND_MEASUREMENT_START (0x01) + +/* Definitions of Register address */ + #define RM_OB1203_REG_ADDR_PPG_IRLED_CURR_0 (0x30) // PPG IR LED (LED1) current, LSB + #define RM_OB1203_REG_ADDR_PPG_CAN_ANA (0x34) // PPG analog cancellation value + #define RM_OB1203_REG_ADDR_PPG_AVG (0x35) // Number of averaged PPG samples + #define RM_OB1203_REG_ADDR_PPG_PWIDTH_PERIOD (0x36) // PPG pulse width and measurement period + #define RM_OB1203_REG_ADDR_FIFO_CFG (0x37) // FIFO rollover and almost full configuration + #define RM_OB1203_REG_ADDR_FIFO_WR_PTR (0x38) // FIFO write pointer + #define RM_OB1203_REG_ADDR_FIFO_DATA (0x3B) // FIFO mirrored PPG data + #define RM_OB1203_REG_ADDR_DIG_LED1_TRIM (0x42) // Digital trimming for LED1 (IR LED) + +/* Definitions of Mask */ + #define RM_OB1203_MASK_IR_LED_CURRENT (0x03FF) + #define RM_OB1203_MASK_RED_LED_CURRENT (0x01FF) + #define RM_OB1203_MASK_8BITS (0x00FF) + #define RM_OB1203_MASK_FIFO_AFULL (0x0F) + #define RM_OB1203_MASK_FIFO_DATA (0x03) + +/* Definitions of Calculation */ + #define RM_OB1203_REG_DATA_PPG_AVG (0x0A) + #define RM_OB1203_MAX_NUM_OF_SAMPLES (32) + #define RM_OB1203_MAX_NUM_OF_SAMPLE_BYTES (RM_OB1203_MAX_NUM_OF_SAMPLES * 3) // One sample is 3 bytes + +/********************************************************************************************************************** + * Local Typedef definitions + *********************************************************************************************************************/ + +/********************************************************************************************************************** + * Exported global functions + *********************************************************************************************************************/ +extern fsp_err_t rm_ob1203_read(rm_ob1203_ctrl_t * const p_api_ctrl, rm_comms_write_read_params_t write_read_params); +extern fsp_err_t rm_ob1203_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t * const p_src, uint8_t const bytes); +extern fsp_err_t rm_ob1203_main_ctrl_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const main_ctrl_0, + uint8_t const main_ctrl_1); +extern fsp_err_t rm_ob1203_int_cfg_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const int_cfg_0, + uint8_t const int_cfg_1, + uint8_t const int_pst); +extern fsp_err_t rm_ob1203_ppg_ps_gain_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t const ppg_ps_gain); +extern fsp_err_t rm_ob1203_ppg_ps_cfg_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t const ppg_ps_cfg); +extern fsp_err_t rm_ob1203_fifo_info_reset(rm_ob1203_ctrl_t * const p_api_ctrl); + + #if BSP_CFG_RTOS +extern fsp_err_t rm_ob1203_os_semaphore_acquire(rm_ob1203_semaphore_t const * p_semaphore, uint32_t const timeout); + + #endif + +/********************************************************************************************************************** + * Private (static) variables and functions + *********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_open(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_cfg_t const * const p_cfg); +static fsp_err_t rm_ob1203_ppg_close(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_ppg_measurement_start(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_ppg_measurement_stop(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_ppg_light_read(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type); +static fsp_err_t rm_ob1203_ppg_light_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_ppg_prox_read(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_raw_data_t * const p_raw_data); +static fsp_err_t rm_ob1203_ppg_prox_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_ppg_read(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples); +static fsp_err_t rm_ob1203_ppg_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_ppg_gain_set(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_gain_t const gain); +static fsp_err_t rm_ob1203_ppg_led_current_set(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_led_current_t const led_current); +static fsp_err_t rm_ob1203_ppg_device_interrupt_cfg_set(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg); +static fsp_err_t rm_ob1203_ppg_fifo_info_get(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_fifo_info_t * const p_fifo_info); +static fsp_err_t rm_ob1203_ppg_device_status_get(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_status_t * const p_status); + +/********************************************************************************************************************** + * Exported global variables + *********************************************************************************************************************/ +rm_ob1203_api_t const g_ob1203_on_ob1203_ppg = +{ + .open = rm_ob1203_ppg_open, + .close = rm_ob1203_ppg_close, + .measurementStart = rm_ob1203_ppg_measurement_start, + .measurementStop = rm_ob1203_ppg_measurement_stop, + .lightRead = rm_ob1203_ppg_light_read, + .lightDataCalculate = rm_ob1203_ppg_light_data_calculate, + .proxRead = rm_ob1203_ppg_prox_read, + .proxDataCalculate = rm_ob1203_ppg_prox_data_calculate, + .ppgRead = rm_ob1203_ppg_read, + .ppgDataCalculate = rm_ob1203_ppg_data_calculate, + .gainSet = rm_ob1203_ppg_gain_set, + .ledCurrentSet = rm_ob1203_ppg_led_current_set, + .deviceInterruptCfgSet = rm_ob1203_ppg_device_interrupt_cfg_set, + .fifoInfoGet = rm_ob1203_ppg_fifo_info_get, + .deviceStatusGet = rm_ob1203_ppg_device_status_get, +}; + +/*********************************************************************************************************************** + * Functions + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief Configures the OB1203 PPG mode. + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_open (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_cfg_t const * const p_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint16_t current_tmp; + uint8_t int_cfg_1 = 0x00; + + FSP_PARAMETER_NOT_USED(p_cfg); + + /* Set gain */ + err = rm_ob1203_ppg_ps_gain_register_write(p_ctrl, (uint8_t) p_ctrl->p_mode->ppg_prox_gain); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set LED current */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PPG_IRLED_CURR_0; + current_tmp = p_ctrl->p_mode->ppg_ir_led_current & RM_OB1203_MASK_IR_LED_CURRENT; + p_ctrl->buf[1] = (uint8_t) (current_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) (current_tmp >> 8); + current_tmp = p_ctrl->p_mode->ppg_red_led_current & RM_OB1203_MASK_RED_LED_CURRENT; + p_ctrl->buf[3] = (uint8_t) (current_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[4] = (uint8_t) (current_tmp >> 8); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 5); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set power save mode and LED order */ + err = + rm_ob1203_ppg_ps_cfg_register_write(p_ctrl, + (uint8_t) ((uint8_t) p_ctrl->p_mode->ppg_power_save_mode | + (uint8_t) p_ctrl->p_mode->led_order)); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set analog cancellations */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PPG_CAN_ANA; + p_ctrl->buf[1] = + (uint8_t) ((uint8_t) (p_ctrl->p_mode->ppg_ir_led_ana_can << 2) | (uint8_t) p_ctrl->p_mode->ppg_red_led_ana_can); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set number of averaged samples */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PPG_AVG; + p_ctrl->buf[1] = (uint8_t) ((uint8_t) p_ctrl->p_mode->ppg_num_averaged_samples | RM_OB1203_REG_DATA_PPG_AVG); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set pulse width and measurement period */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PPG_PWIDTH_PERIOD; + p_ctrl->buf[1] = (uint8_t) p_ctrl->p_mode->ppg_width_period; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set FIFO configuration */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_FIFO_CFG; + p_ctrl->buf[1] = + (uint8_t) ((uint8_t) p_ctrl->p_mode->ppg_fifo_rollover | + (uint8_t) (p_ctrl->p_mode->ppg_fifo_empty_num & RM_OB1203_MASK_FIFO_AFULL)); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Reset FIFO information */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_FIFO_WR_PTR; + p_ctrl->buf[1] = 0x00; + p_ctrl->buf[2] = 0x00; + p_ctrl->buf[3] = 0x00; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 4); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set device interrupt configurations */ + if (NULL != p_ctrl->p_irq_instance) + { + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_PPG; + int_cfg_1 = (uint8_t) p_ctrl->p_mode->ppg_interrupt_type; + } + else + { + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_STANDBY; + int_cfg_1 = 0; + } + + err = rm_ob1203_int_cfg_register_write(p_ctrl, 0x00, int_cfg_1, 0x00); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set LED digital trimming */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_DIG_LED1_TRIM; + p_ctrl->buf[1] = 0x00; + p_ctrl->buf[2] = 0x00; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 3); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_close (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Start a periodic measurement + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_measurement_start (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t main_ctrl_1; + + /* Start measurement */ + main_ctrl_1 = (uint8_t) ((uint8_t) p_ctrl->p_mode->ppg_sensor_mode | RM_OB1203_COMMAND_MEASUREMENT_START); + err = rm_ob1203_main_ctrl_register_write(p_ctrl, 0x00, main_ctrl_1); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Stop a periodic measurement + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_measurement_stop (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set flag to reset FIFO info. after measurement stop */ + p_ctrl->fifo_reset = true; + + /* Stop measurement */ + err = rm_ob1203_main_ctrl_register_write(p_ctrl, 0x00, 0x00); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + #if BSP_CFG_RTOS + + /* Acquire a semaphore */ + err = rm_ob1203_os_semaphore_acquire(p_ctrl->p_semaphore, p_ctrl->p_cfg->semaphore_timeout); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Reset FIFO info. */ + err = rm_ob1203_fifo_info_reset(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + #endif + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_light_read (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(type); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_light_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(p_ob1203_data); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_prox_read (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_raw_data_t * const p_raw_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Calculate proximity data from raw data. + * + * @retval FSP_SUCCESS Successfully results are read. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_prox_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(p_ob1203_data); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Reads PPG ADC data from OB1203 device. One sample requires three bytes. 0 cannot set to the number of samples. + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + * @retval FSP_ERR_INVALID_ARGUMENT Invalid number. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_read (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t bytes; + rm_comms_write_read_params_t write_read_params; + + #if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ERROR_RETURN(0 != number_of_samples, FSP_ERR_INVALID_ARGUMENT); + #endif + + /* Set number of samples and bytes (one PPG sample is 3 bytes). */ + if (RM_OB1203_MAX_NUM_OF_SAMPLES > number_of_samples) + { + p_ctrl->p_mode->ppg_number_of_samples = number_of_samples; + bytes = number_of_samples * 3; + } + else + { + p_ctrl->p_mode->ppg_number_of_samples = RM_OB1203_MAX_NUM_OF_SAMPLES; + bytes = RM_OB1203_MAX_NUM_OF_SAMPLE_BYTES; + } + + /* Read PPG FIFO data. */ + p_ctrl->register_address = RM_OB1203_REG_ADDR_FIFO_DATA; + write_read_params.p_src = &p_ctrl->register_address; + write_read_params.src_bytes = 1; + write_read_params.p_dest = (uint8_t *) p_raw_data; + write_read_params.dest_bytes = bytes; + err = rm_ob1203_read(p_ctrl, write_read_params); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Calculate PPG data from raw data. + * + * @retval FSP_SUCCESS Successfully results are read. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data) +{ + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t i = 0; + + /* Calculate PPG data */ + for (i = 0; i < p_ctrl->p_mode->ppg_number_of_samples; i++) + { + p_ob1203_data->ppg_data[i] = + (uint32_t) (((p_raw_data->adc_data[3 * i + 2] & RM_OB1203_MASK_FIFO_DATA) << 16) + + (p_raw_data->adc_data[3 * i + 1] << 8) + p_raw_data->adc_data[3 * i]); + } + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Set gain. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_gain_set (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_gain_t const gain) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set gain */ + p_ctrl->p_mode->ppg_prox_gain = gain.ppg_prox; + err = rm_ob1203_ppg_ps_gain_register_write(p_ctrl, (uint8_t) p_ctrl->p_mode->ppg_prox_gain); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Set current. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_led_current_set (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_led_current_t const led_current) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint16_t current_tmp; + + /* Set LED current */ + p_ctrl->p_mode->ppg_ir_led_current = led_current.ir_led; + p_ctrl->p_mode->ppg_red_led_current = led_current.red_led; + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PPG_IRLED_CURR_0; + current_tmp = p_ctrl->p_mode->ppg_ir_led_current & RM_OB1203_MASK_IR_LED_CURRENT; + p_ctrl->buf[1] = (uint8_t) (current_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) (current_tmp >> 8); + current_tmp = p_ctrl->p_mode->ppg_red_led_current & RM_OB1203_MASK_RED_LED_CURRENT; + p_ctrl->buf[3] = (uint8_t) (current_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[4] = (uint8_t) (current_tmp >> 8); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 5); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Set device interrupt configurations. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_device_interrupt_cfg_set (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set device interrupt configurations */ + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_PPG; + p_ctrl->p_mode->ppg_interrupt_type = interrupt_cfg.ppg_type; + + err = rm_ob1203_int_cfg_register_write(p_ctrl, 0x00, (uint8_t) p_ctrl->p_mode->ppg_interrupt_type, 0x00); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Get FIFO information. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_fifo_info_get (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_fifo_info_t * const p_fifo_info) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + rm_comms_write_read_params_t write_read_params; + + p_ctrl->p_fifo_info = p_fifo_info; + p_ctrl->register_address = RM_OB1203_REG_ADDR_FIFO_WR_PTR; + write_read_params.p_src = &p_ctrl->register_address; + write_read_params.src_bytes = 1; + write_read_params.p_dest = &p_ctrl->buf[0]; + write_read_params.dest_bytes = 3; + err = rm_ob1203_read(p_ctrl, write_read_params); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_ppg_device_status_get (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_status_t * const p_status) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_status); + + return FSP_ERR_UNSUPPORTED; +} + +#endif diff --git a/ra/fsp/src/rm_ob1203/proximity_mode/rm_ob1203_proximity_mode.c b/ra/fsp/src/rm_ob1203/proximity_mode/rm_ob1203_proximity_mode.c new file mode 100644 index 000000000..123bc3317 --- /dev/null +++ b/ra/fsp/src/rm_ob1203/proximity_mode/rm_ob1203_proximity_mode.c @@ -0,0 +1,535 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/********************************************************************************************************************** + * Includes , "Project Includes" + *********************************************************************************************************************/ +#if defined(__CCRX__) || defined(__ICCRX__) || defined(__RX__) + #include "r_ob1203_if.h" +#elif defined(__CCRL__) || defined(__ICCRL78__) || defined(__RL78__) + #include "r_ob1203_if.h" +#else + #define RM_OB1203_PROXIMITY_MODE_ENABLE (1) +#endif + +#if RM_OB1203_PROXIMITY_MODE_ENABLE + #include "rm_ob1203.h" + +/********************************************************************************************************************** + * Macro definitions + *********************************************************************************************************************/ + +/* Definitions of Command */ + #define RM_OB1203_COMMAND_MEASUREMENT_START (0x01) + #define RM_OB1203_COMMAND_INTERRUPT_ENABLE (0x01) + +/* Definitions of Register address */ + #define RM_OB1203_REG_ADDR_PS_DATA_0 (0x02) // PS measurement data, LSB + #define RM_OB1203_REG_ADDR_PS_LED_CURR_0 (0x17) // PS LED current, LSB + #define RM_OB1203_REG_ADDR_PS_CAN_PULSES (0x19) // PS analog cancellation level and pulse setting + #define RM_OB1203_REG_ADDR_PS_PWIDTH_PERIOD (0x1A) // PS pulse width and measurement period + #define RM_OB1203_REG_ADDR_PS_CAN_DIG_0 (0x1B) // PS digital cancellation level setting, LSB + #define RM_OB1203_REG_ADDR_PS_MOV_AVG_HYS (0x1D) // PS moving average and hysteresis configuration + #define RM_OB1203_REG_ADDR_PS_THRES_UP_0 (0x1E) // PS interrupt upper threshold, LSB + +/* Definitions of Mask */ + #define RM_OB1203_MASK_LED_CURRENT (0x03FF) + #define RM_OB1203_MASK_8BITS (0x00FF) + #define RM_OB1203_MASK_HYSTERESIS (0x7F) + #define RM_OB1203_MASK_PERSIST (0x0F) + +/********************************************************************************************************************** + * Local Typedef definitions + *********************************************************************************************************************/ + +/********************************************************************************************************************** + * Exported global functions + *********************************************************************************************************************/ +extern fsp_err_t rm_ob1203_read(rm_ob1203_ctrl_t * const p_api_ctrl, rm_comms_write_read_params_t write_read_params); +extern fsp_err_t rm_ob1203_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t * const p_src, uint8_t const bytes); +extern fsp_err_t rm_ob1203_main_ctrl_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const main_ctrl_0, + uint8_t const main_ctrl_1); +extern fsp_err_t rm_ob1203_int_cfg_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const int_cfg_0, + uint8_t const int_cfg_1, + uint8_t const int_pst); +extern fsp_err_t rm_ob1203_ppg_ps_gain_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t const ppg_ps_gain); +extern fsp_err_t rm_ob1203_ppg_ps_cfg_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t const ppg_ps_cfg); +extern fsp_err_t rm_ob1203_all_interrupt_bits_clear(rm_ob1203_ctrl_t * const p_api_ctrl); + + #if BSP_CFG_RTOS +extern fsp_err_t rm_ob1203_os_semaphore_acquire(rm_ob1203_semaphore_t const * p_semaphore, uint32_t const timeout); + + #endif + +/********************************************************************************************************************** + * Private (static) variables and functions + *********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_open(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_cfg_t const * const p_cfg); +static fsp_err_t rm_ob1203_prox_close(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_prox_measurement_start(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_prox_measurement_stop(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_prox_light_read(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type); +static fsp_err_t rm_ob1203_prox_light_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_prox_read(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_raw_data_t * const p_raw_data); +static fsp_err_t rm_ob1203_prox_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_prox_ppg_read(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples); +static fsp_err_t rm_ob1203_prox_ppg_data_calculate(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data); +static fsp_err_t rm_ob1203_prox_gain_set(rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_gain_t const gain); +static fsp_err_t rm_ob1203_prox_led_current_set(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_led_current_t const led_current); +static fsp_err_t rm_ob1203_prox_device_interrupt_cfg_set(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg); +static fsp_err_t rm_ob1203_prox_fifo_info_get(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_fifo_info_t * const p_fifo_info); +static fsp_err_t rm_ob1203_prox_device_status_get(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_status_t * const p_status); + +/********************************************************************************************************************** + * Exported global variables + *********************************************************************************************************************/ +rm_ob1203_api_t const g_ob1203_on_ob1203_proximity = +{ + .open = rm_ob1203_prox_open, + .close = rm_ob1203_prox_close, + .measurementStart = rm_ob1203_prox_measurement_start, + .measurementStop = rm_ob1203_prox_measurement_stop, + .lightRead = rm_ob1203_prox_light_read, + .lightDataCalculate = rm_ob1203_prox_light_data_calculate, + .proxRead = rm_ob1203_prox_read, + .proxDataCalculate = rm_ob1203_prox_data_calculate, + .ppgRead = rm_ob1203_prox_ppg_read, + .ppgDataCalculate = rm_ob1203_prox_ppg_data_calculate, + .gainSet = rm_ob1203_prox_gain_set, + .ledCurrentSet = rm_ob1203_prox_led_current_set, + .deviceInterruptCfgSet = rm_ob1203_prox_device_interrupt_cfg_set, + .fifoInfoGet = rm_ob1203_prox_fifo_info_get, + .deviceStatusGet = rm_ob1203_prox_device_status_get, +}; + +/*********************************************************************************************************************** + * Functions + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief Configures the OB1203 Proximity mode. + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_open (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_cfg_t const * const p_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint16_t current_tmp; + uint8_t int_cfg_1 = 0x00; + uint8_t int_pst = 0x00; + + FSP_PARAMETER_NOT_USED(p_cfg); + + /* Set gain */ + err = rm_ob1203_ppg_ps_gain_register_write(p_ctrl, (uint8_t) p_ctrl->p_mode->ppg_prox_gain); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set LED current */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_LED_CURR_0; + current_tmp = p_ctrl->p_mode->prox_led_current & RM_OB1203_MASK_LED_CURRENT; + p_ctrl->buf[1] = (uint8_t) (current_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) (current_tmp >> 8); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 3); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set LED order */ + err = rm_ob1203_ppg_ps_cfg_register_write(p_ctrl, (uint8_t) p_ctrl->p_mode->led_order); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set analog cancellation and the number of LED pulses */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_CAN_PULSES; + p_ctrl->buf[1] = (uint8_t) ((uint8_t) p_ctrl->p_mode->prox_ana_can | (uint8_t) p_ctrl->p_mode->prox_num_led_pulses); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set digital cancellation */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_CAN_DIG_0; + p_ctrl->buf[1] = (uint8_t) (p_ctrl->p_mode->prox_dig_can & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) (p_ctrl->p_mode->prox_dig_can >> 8); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 3); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set pulse width and measurement period */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_PWIDTH_PERIOD; + p_ctrl->buf[1] = (uint8_t) p_ctrl->p_mode->prox_width_period; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set moving average and hysteresis */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_MOV_AVG_HYS; + p_ctrl->buf[1] = + (uint8_t) ((uint8_t) p_ctrl->p_mode->prox_moving_average | + (uint8_t) (p_ctrl->p_mode->prox_hysteresis & RM_OB1203_MASK_HYSTERESIS)); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set thresholds */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_THRES_UP_0; + p_ctrl->buf[1] = (uint8_t) (p_ctrl->p_mode->prox_upper_threshold & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) (p_ctrl->p_mode->prox_upper_threshold >> 8); + p_ctrl->buf[3] = (uint8_t) (p_ctrl->p_mode->prox_lower_threshold & RM_OB1203_MASK_8BITS); + p_ctrl->buf[4] = (uint8_t) (p_ctrl->p_mode->prox_lower_threshold >> 8); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 5); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set device interrupt configurations */ + if (NULL != p_ctrl->p_irq_instance) + { + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_PROXIMITY; + int_cfg_1 = + (uint8_t) ((uint8_t) p_ctrl->p_mode->prox_interrupt_type | RM_OB1203_COMMAND_INTERRUPT_ENABLE); + int_pst = (uint8_t) (p_ctrl->p_mode->prox_interrupt_persist & RM_OB1203_MASK_PERSIST); + } + else + { + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_STANDBY; + int_cfg_1 = 0x00; + int_pst = 0x00; + } + + err = rm_ob1203_int_cfg_register_write(p_ctrl, 0x00, int_cfg_1, int_pst); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_close (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Start a periodic measurement + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_measurement_start (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t main_ctrl_1; + + /* Start measurement */ + main_ctrl_1 = (uint8_t) ((uint8_t) p_ctrl->p_mode->prox_sleep | RM_OB1203_COMMAND_MEASUREMENT_START); + err = rm_ob1203_main_ctrl_register_write(p_ctrl, 0x00, main_ctrl_1); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Stop a periodic measurement + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_measurement_stop (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + if (RM_OB1203_OPERATION_MODE_PROXIMITY == p_ctrl->p_mode->mode_irq) + { + /* Clear interrupt bits after measurement stop */ + p_ctrl->interrupt_bits_clear = true; + } + + /* Stop measurement */ + err = rm_ob1203_main_ctrl_register_write(p_ctrl, 0x00, 0x00); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + #if BSP_CFG_RTOS + if (RM_OB1203_OPERATION_MODE_PROXIMITY == p_ctrl->p_mode->mode_irq) + { + /* Acquire a semaphore */ + err = rm_ob1203_os_semaphore_acquire(p_ctrl->p_semaphore, p_ctrl->p_cfg->semaphore_timeout); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Clear all interrupt bits */ + err = rm_ob1203_all_interrupt_bits_clear(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + } + #endif + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_light_read (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(type); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_light_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(p_ob1203_data); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Reads proximity ADC data from OB1203 device. If device interrupt is enabled, interrupt bits are cleared after data read. + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_read (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_raw_data_t * const p_raw_data) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + rm_comms_write_read_params_t write_read_params; + + if (RM_OB1203_OPERATION_MODE_PROXIMITY == p_ctrl->p_mode->mode_irq) + { + /* Clear interrupt bits after data read */ + p_ctrl->interrupt_bits_clear = true; + } + + /* Read proximity data. */ + p_ctrl->register_address = RM_OB1203_REG_ADDR_PS_DATA_0; + write_read_params.p_src = &p_ctrl->register_address; + write_read_params.src_bytes = 1; + write_read_params.p_dest = (uint8_t *) p_raw_data; + write_read_params.dest_bytes = 2; + err = rm_ob1203_read(p_ctrl, write_read_params); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + #if BSP_CFG_RTOS + if (RM_OB1203_OPERATION_MODE_PROXIMITY == p_ctrl->p_mode->mode_irq) + { + /* Acquire a semaphore */ + err = rm_ob1203_os_semaphore_acquire(p_ctrl->p_semaphore, p_ctrl->p_cfg->semaphore_timeout); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Clear all interrupt bits */ + err = rm_ob1203_all_interrupt_bits_clear(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + } + #endif + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Calculate proximity data from raw data. + * + * @retval FSP_SUCCESS Successfully results are read. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + + /* Calculate proximity data */ + p_ob1203_data->proximity_data = (uint16_t) ((p_raw_data->adc_data[1] << 8) + p_raw_data->adc_data[0]); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_ppg_read (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(number_of_samples); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_ppg_data_calculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_raw_data); + FSP_PARAMETER_NOT_USED(p_ob1203_data); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Set gain. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_gain_set (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_gain_t const gain) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set gain */ + p_ctrl->p_mode->ppg_prox_gain = gain.ppg_prox; + err = rm_ob1203_ppg_ps_gain_register_write(p_ctrl, (uint8_t) p_ctrl->p_mode->ppg_prox_gain); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Set current. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_led_current_set (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_led_current_t const led_current) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint16_t current_tmp; + + /* Set LED current */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PS_LED_CURR_0; + if (RM_OB1203_LED_IR_FIRST_RED_SECOND == p_ctrl->p_mode->led_order) + { + p_ctrl->p_mode->prox_led_current = led_current.ir_led & RM_OB1203_MASK_LED_CURRENT; + } + else + { + p_ctrl->p_mode->prox_led_current = led_current.red_led & RM_OB1203_MASK_LED_CURRENT; + } + + current_tmp = p_ctrl->p_mode->prox_led_current; + p_ctrl->buf[1] = (uint8_t) (current_tmp & RM_OB1203_MASK_8BITS); + p_ctrl->buf[2] = (uint8_t) (current_tmp >> 8); + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 3); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Set device interrupt configurations. + * + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_device_interrupt_cfg_set (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t int_cfg_1 = 0x00; + uint8_t int_pst = 0x00; + + /* Set device interrupt configurations */ + p_ctrl->p_mode->mode_irq = RM_OB1203_OPERATION_MODE_PROXIMITY; + p_ctrl->p_mode->prox_interrupt_type = interrupt_cfg.prox_type; + p_ctrl->p_mode->prox_interrupt_persist = interrupt_cfg.persist; + int_cfg_1 = (uint8_t) ((uint8_t) p_ctrl->p_mode->prox_interrupt_type | RM_OB1203_COMMAND_INTERRUPT_ENABLE); + int_pst = (uint8_t) (p_ctrl->p_mode->prox_interrupt_persist & RM_OB1203_MASK_PERSIST); + + err = rm_ob1203_int_cfg_register_write(p_ctrl, 0x00, int_cfg_1, int_pst); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_fifo_info_get (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_fifo_info_t * const p_fifo_info) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_fifo_info); + + return FSP_ERR_UNSUPPORTED; +} + +/*******************************************************************************************************************//** + * @brief Unsupported API. + * + * @retval FSP_ERR_UNSUPPORTED Operation mode is not supported. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_prox_device_status_get (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_status_t * const p_status) +{ + FSP_PARAMETER_NOT_USED(p_api_ctrl); + FSP_PARAMETER_NOT_USED(p_status); + + return FSP_ERR_UNSUPPORTED; +} + +#endif diff --git a/ra/fsp/src/rm_ob1203/rm_ob1203.c b/ra/fsp/src/rm_ob1203/rm_ob1203.c new file mode 100644 index 000000000..49f121581 --- /dev/null +++ b/ra/fsp/src/rm_ob1203/rm_ob1203.c @@ -0,0 +1,1224 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Includes + **********************************************************************************************************************/ +#include "rm_ob1203.h" + +/*********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ + +/* Definitions of Open flag */ +#define RM_OB1203_OPEN (0x632A5721UL) // Open state + +/* Definitions of Timeout */ +#define RM_OB1203_TIMEOUT (100) +#define RM_OB1203_10MS (10) + +/* Definitions of Register data */ +#define RM_OB1203_REG_DATA_PPG_PS_GAIN (0x09) + +/* Definitions of Commands */ +#define RM_OB1203_COMMAND_SOFTWARE_RESET (0x80) + +/* Definitions of Register address */ +#define RM_OB1203_REG_ADDR_STATUS_0 (0x00) // Power-on status, LS interrupt, and LS data status +#define RM_OB1203_REG_ADDR_STATUS_1 (0x01) // PPG/PS data status, PS/PPG interrupt status +#define RM_OB1203_REG_ADDR_MAIN_CTRL_0 (0x15) // LS operation mode control, software (SW) reset +#define RM_OB1203_REG_ADDR_MAIN_CTRL_1 (0x16) // PPG/PS operation mode control +#define RM_OB1203_REG_ADDR_INT_CFG_0 (0x2B) // LS interrupt configuration +#define RM_OB1203_REG_ADDR_INT_CFG_1 (0x2C) // PS/PPG interrupt configuration +#define RM_OB1203_REG_ADDR_PPG_PS_GAIN (0x2E) // PPG/PS gain setting +#define RM_OB1203_REG_ADDR_PPG_PS_CFG (0x2F) // PPG power save and LED flip setting +#define RM_OB1203_REG_ADDR_FIFO_WR_PTR (0x38) // FIFO write pointer + +/* Definitions of Mask */ +#define RM_OB1203_MASK_POWER_ON_RESET (0x80) +#define RM_OB1203_MASK_LIGHT_INTERRUPT (0x02) +#define RM_OB1203_MASK_LIGHT_DATA_STATUS (0x01) +#define RM_OB1203_MASK_TS_DATA (0x80) +#define RM_OB1203_MASK_PPG_DATA_STATUS (0x10) +#define RM_OB1203_MASK_FIFO_AFULL_INTERRUPT (0x20) +#define RM_OB1203_MASK_LOGIC_SIGNAL (0x04) +#define RM_OB1203_MASK_PROX_INTERRUPT (0x02) +#define RM_OB1203_MASK_PROX_DATA_STATUS (0x01) + +/* Definitions of FIFO */ +#define RM_OB1203_FIFO_MAX_SAMPLES_32 (32) +#define RM_OB1203_FIFO_MASK_PPG2_0XFE (0xFE) + +/*********************************************************************************************************************** + * Typedef definitions + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Global function prototypes + **********************************************************************************************************************/ +void rm_ob1203_comms_i2c_callback(rm_comms_callback_args_t * p_args); +fsp_err_t rm_ob1203_read(rm_ob1203_ctrl_t * const p_api_ctrl, rm_comms_write_read_params_t write_read_params); +fsp_err_t rm_ob1203_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t * const p_src, uint8_t const bytes); +fsp_err_t rm_ob1203_main_ctrl_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const main_ctrl_0, + uint8_t const main_ctrl_1); +fsp_err_t rm_ob1203_int_cfg_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const int_cfg_0, + uint8_t const int_cfg_1, + uint8_t const int_pst); +fsp_err_t rm_ob1203_ppg_ps_gain_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t const ppg_ps_gain); +fsp_err_t rm_ob1203_ppg_ps_cfg_register_write(rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t const ppg_ps_cfg); +fsp_err_t rm_ob1203_fifo_info_reset(rm_ob1203_ctrl_t * const p_api_ctrl); +fsp_err_t rm_ob1203_all_interrupt_bits_clear(rm_ob1203_ctrl_t * const p_api_ctrl); +extern fsp_err_t rm_ob1203_delay_ms(rm_ob1203_ctrl_t * const p_ctrl, uint32_t const delay_ms); +extern fsp_err_t rm_ob1203_irq_open(rm_ob1203_ctrl_t * const p_api_ctrl); +extern fsp_err_t rm_ob1203_irq_close(rm_ob1203_ctrl_t * const p_api_ctrl); + +#if BSP_CFG_RTOS +extern fsp_err_t rm_ob1203_os_semaphore_create(rm_ob1203_semaphore_t const * p_semaphore); +extern fsp_err_t rm_ob1203_os_semaphore_delete(rm_ob1203_semaphore_t const * p_semaphore); +extern fsp_err_t rm_ob1203_os_semaphore_acquire(rm_ob1203_semaphore_t const * p_semaphore, uint32_t const timeout); +extern fsp_err_t rm_ob1203_os_semaphore_release_from_ISR(rm_ob1203_semaphore_t const * p_semaphore); + +#endif + +/*********************************************************************************************************************** + * Private function prototypes + **********************************************************************************************************************/ +static void rm_ob1203_process_in_callback(rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_callback_args_t * const p_args); +static void rm_ob1203_device_status_check(rm_ob1203_ctrl_t * const p_api_ctrl); +static void rm_ob1203_unread_samples_calculate(rm_ob1203_ctrl_t * const p_api_ctrl); +static fsp_err_t rm_ob1203_software_reset(rm_ob1203_ctrl_t * const p_api_ctrl); + +/*********************************************************************************************************************** + * Private global variables + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Global variables + **********************************************************************************************************************/ +rm_ob1203_api_t const g_ob1203_on_ob1203 = +{ + .open = RM_OB1203_Open, + .close = RM_OB1203_Close, + .measurementStart = RM_OB1203_MeasurementStart, + .measurementStop = RM_OB1203_MeasurementStop, + .lightRead = RM_OB1203_LightRead, + .lightDataCalculate = RM_OB1203_LightDataCalculate, + .proxRead = RM_OB1203_ProxRead, + .proxDataCalculate = RM_OB1203_ProxDataCalculate, + .ppgRead = RM_OB1203_PpgRead, + .ppgDataCalculate = RM_OB1203_PpgDataCalculate, + .gainSet = RM_OB1203_GainSet, + .ledCurrentSet = RM_OB1203_LedCurrentSet, + .deviceInterruptCfgSet = RM_OB1203_DeviceInterruptCfgSet, + .fifoInfoGet = RM_OB1203_FifoInfoGet, + .deviceStatusGet = RM_OB1203_DeviceStatusGet, +}; + +/*******************************************************************************************************************//** + * @addtogroup RM_OB1203 + * @{ + **********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Functions + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief Opens and configures the OB1203 Middle module. Implements @ref rm_ob1203_api_t::open. + * + * Example: + * @snippet rm_ob1203_example.c RM_OB1203_Open + * + * @retval FSP_SUCCESS OB1203 successfully configured. + * @retval FSP_ERR_ASSERTION Null pointer, or one or more configuration options is invalid. + * @retval FSP_ERR_ALREADY_OPEN Module is already open. This module can only be opened once. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_Open (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_cfg_t const * const p_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + rm_ob1203_mode_extended_cfg_t * p_mode; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ASSERT(NULL != p_cfg); + FSP_ASSERT(NULL != p_cfg->p_comms_instance); + FSP_ASSERT(NULL != p_cfg->p_extend); + FSP_ERROR_RETURN(RM_OB1203_OPEN != p_ctrl->open, FSP_ERR_ALREADY_OPEN); +#endif + + p_ctrl->p_cfg = p_cfg; + p_mode = (rm_ob1203_mode_extended_cfg_t *) p_cfg->p_extend; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_mode->p_api); + #if BSP_CFG_RTOS + FSP_ASSERT(NULL != p_ctrl->p_cfg->p_semaphore); + #endif +#endif + + /* Set instances */ + p_ctrl->p_comms_i2c_instance = p_cfg->p_comms_instance; + p_ctrl->p_irq_instance = p_cfg->p_irq_instance; + + /* Set operation mode */ + p_ctrl->p_mode = p_mode; + + /* Set parameters */ + p_ctrl->p_context = p_cfg->p_context; + p_ctrl->p_comms_callback = p_cfg->p_comms_callback; + p_ctrl->p_irq_callback = p_cfg->p_irq_callback; + p_ctrl->p_device_status = NULL; + p_ctrl->p_fifo_info = NULL; + p_ctrl->fifo_reset = false; + p_ctrl->prox_gain_update = false; + p_ctrl->interrupt_bits_clear = false; + + /* Open Communications middleware */ + err = p_ctrl->p_comms_i2c_instance->p_api->open(p_ctrl->p_comms_i2c_instance->p_ctrl, + p_ctrl->p_comms_i2c_instance->p_cfg); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Open IRQ */ + if (NULL != p_ctrl->p_irq_instance) + { + err = rm_ob1203_irq_open(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + } + +#if BSP_CFG_RTOS + + /* Set semaphore */ + p_ctrl->p_semaphore = p_ctrl->p_cfg->p_semaphore; + + /* Create semaphore */ + err = rm_ob1203_os_semaphore_create(p_ctrl->p_semaphore); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); +#endif + + /* Stop previous measurements */ + err = rm_ob1203_main_ctrl_register_write(p_ctrl, 0x00, 0x00); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Software reset */ + err = rm_ob1203_software_reset(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Delay 10ms */ + err = rm_ob1203_delay_ms(p_ctrl, RM_OB1203_10MS); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Clear all interrupt bits */ + err = rm_ob1203_all_interrupt_bits_clear(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Open operation mode */ + err = p_mode->p_api->open(p_ctrl, p_cfg); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set open flag */ + p_ctrl->open = RM_OB1203_OPEN; + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Disables specified OB1203 control block. Implements @ref rm_ob1203_api_t::close. + * + * @retval FSP_SUCCESS Successfully closed. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not open. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_Close (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Close Communications Middleware */ + p_ctrl->p_comms_i2c_instance->p_api->close(p_ctrl->p_comms_i2c_instance->p_ctrl); + + /* Close IRQ */ + if (NULL != p_ctrl->p_irq_instance) + { + rm_ob1203_irq_close(p_ctrl); + } + +#if BSP_CFG_RTOS + + /* delete a semaphore */ + rm_ob1203_os_semaphore_delete(p_ctrl->p_semaphore); +#endif + + /* Clear Open flag */ + p_ctrl->open = 0; + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Start measurement. + * Implements @ref rm_ob1203_api_t::measurementStart + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_MeasurementStart (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Start measurement */ + err = p_ctrl->p_mode->p_api->measurementStart(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Stop measurement. + * If device interrupt is enabled, interrupt bits are cleared after measurement stop. + * If PPG mode, FIFO information is also reset after measurement stop. + * In RTOS and Light/Proximity/Light Proximity mode, if device interrupt is enabled, blocks 2 bytes on the I2C bus. + * In RTOS and PPG mode, if device interrupt is enabled, blocks 6 bytes on the I2C bus. If device interrupt is disabled, + * blocks 4 bytes on the I2C bus. + * Implements @ref rm_ob1203_api_t::measurementStop + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_MeasurementStop (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Stop measurement */ + err = p_ctrl->p_mode->p_api->measurementStop(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Reads Light ADC data from OB1203 device. + * If device interrupt is enabled, interrupt bits are cleared after data read. + * In RTOS and Light mode, if device interrupt is enabled, blocks 2 bytes on the I2C bus. + * Implements @ref rm_ob1203_api_t::lightRead + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_LightRead (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_type_t type) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ASSERT(NULL != p_raw_data); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Read Light raw data */ + err = p_ctrl->p_mode->p_api->lightRead(p_ctrl, p_raw_data, type); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Calculate light data from raw data. + * Implements @ref rm_ob1203_api_t::lightDataCalculate + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_LightDataCalculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_light_data_t * const p_ob1203_data) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ASSERT(NULL != p_raw_data); + FSP_ASSERT(NULL != p_ob1203_data); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Calculate Light data from raw data */ + err = p_ctrl->p_mode->p_api->lightDataCalculate(p_ctrl, p_raw_data, p_ob1203_data); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Reads Proximity ADC data from OB1203 device. + * If device interrupt is enabled, interrupt bits are cleared after data read. + * In RTOS and Proximity mode, if device interrupt is enabled, blocks 2 bytes on the I2C bus. + * Implements @ref rm_ob1203_api_t::proxRead + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_ProxRead (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_raw_data_t * const p_raw_data) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ASSERT(NULL != p_raw_data); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Read Proximity raw data */ + err = p_ctrl->p_mode->p_api->proxRead(p_ctrl, p_raw_data); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Calculate proximity data from raw data. + * Implements @ref rm_ob1203_api_t::proxDataCalculate + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_ProxDataCalculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_prox_data_t * const p_ob1203_data) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ASSERT(NULL != p_raw_data); + FSP_ASSERT(NULL != p_ob1203_data); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Calculate Proximity data from raw data */ + err = p_ctrl->p_mode->p_api->proxDataCalculate(p_ctrl, p_raw_data, p_ob1203_data); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Reads PPG ADC data from OB1203 device. One sample requires three bytes. 0 cannot set to the number of samples. + * Implements @ref rm_ob1203_api_t::ppgRead + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_PpgRead (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + uint8_t const number_of_samples) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ASSERT(NULL != p_raw_data); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Read PPG raw data */ + err = p_ctrl->p_mode->p_api->ppgRead(p_ctrl, p_raw_data, number_of_samples); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Calculate PPG data from raw data. + * Implements @ref rm_ob1203_api_t::ppgDataCalculate + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_PpgDataCalculate (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_raw_data_t * const p_raw_data, + rm_ob1203_ppg_data_t * const p_ob1203_data) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ASSERT(NULL != p_raw_data); + FSP_ASSERT(NULL != p_ob1203_data); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Calculate PPG data from raw data */ + err = p_ctrl->p_mode->p_api->ppgDataCalculate(p_ctrl, p_raw_data, p_ob1203_data); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Set gain. This function should be called after calling RM_OB1203_MeasurementStop(). + * In RTOS and Light Proximity mode, blocks 2 bytes on the I2C bus. + * Implements @ref rm_ob1203_api_t::gainSet + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_GainSet (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_gain_t const gain) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Set PPG and Proximity gain */ + err = p_ctrl->p_mode->p_api->gainSet(p_ctrl, gain); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Set currents. This function should be called after calling RM_OB1203_MeasurementStop(). + * Implements @ref rm_ob1203_api_t::ledCurrentSet + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_LedCurrentSet (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_led_current_t const led_current) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Set LED currents */ + err = p_ctrl->p_mode->p_api->ledCurrentSet(p_ctrl, led_current); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Set device interrupt configurations. This function should be called after calling RM_OB1203_MeasurementStop(). + * Implements @ref rm_ob1203_api_t::deviceInterruptCfgSet + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_DeviceInterruptCfgSet (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_device_interrupt_cfg_t const interrupt_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Set PPG device interrupt configuration */ + err = p_ctrl->p_mode->p_api->deviceInterruptCfgSet(p_ctrl, interrupt_cfg); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Get FIFO information from OB1203 device. + * Implements @ref rm_ob1203_api_t::fifoInfoGet + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_FifoInfoGet (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_fifo_info_t * const p_fifo_info) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ASSERT(NULL != p_fifo_info); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Get PPG FIFO information */ + err = p_ctrl->p_mode->p_api->fifoInfoGet(p_ctrl, p_fifo_info); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Get device status from OB1203 device. Clear all interrupt bits. + * Implements @ref rm_ob1203_api_t::deviceStatusGet + * + * @retval FSP_SUCCESS Successfully results are read. + * @retval FSP_ERR_ASSERTION Null pointer passed as a parameter. + * @retval FSP_ERR_NOT_OPEN Module is not opened configured. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +fsp_err_t RM_OB1203_DeviceStatusGet (rm_ob1203_ctrl_t * const p_api_ctrl, rm_ob1203_device_status_t * const p_status) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + rm_comms_write_read_params_t write_read_params; + +#if RM_OB1203_CFG_PARAM_CHECKING_ENABLE + FSP_ASSERT(NULL != p_ctrl); + FSP_ASSERT(NULL != p_status); + FSP_ERROR_RETURN(RM_OB1203_OPEN == p_ctrl->open, FSP_ERR_NOT_OPEN); +#endif + + /* Set pointer */ + p_ctrl->p_device_status = p_status; + + /* Get status */ + p_ctrl->register_address = RM_OB1203_REG_ADDR_STATUS_0; + write_read_params.p_src = &p_ctrl->register_address; + write_read_params.src_bytes = 1; + write_read_params.p_dest = &p_ctrl->buf[0]; + write_read_params.dest_bytes = 2; + err = rm_ob1203_read(p_ctrl, write_read_params); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @} (end addtogroup RM_OB1203) + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief OB1203 callback function called in the I2C Communications Middleware callback function. + **********************************************************************************************************************/ +void rm_ob1203_comms_i2c_callback (rm_comms_callback_args_t * p_args) +{ +#if BSP_CFG_RTOS == 0 + fsp_err_t err = FSP_SUCCESS; +#endif + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_args->p_context; + rm_ob1203_callback_args_t ob1203_callback_args; + + /* Set context */ + ob1203_callback_args.p_context = p_ctrl->p_context; + + /* Set event */ + switch (p_args->event) + { + case RM_COMMS_EVENT_OPERATION_COMPLETE: + { + ob1203_callback_args.event = RM_OB1203_EVENT_SUCCESS; + break; + } + + case RM_COMMS_EVENT_ERROR: + default: + { + ob1203_callback_args.event = RM_OB1203_EVENT_ERROR; + break; + } + } + + if (RM_OB1203_OPEN != p_ctrl->open) + { + /* Set flag */ + p_ctrl->init_process_params.communication_finished = true; + + /* Set event */ + p_ctrl->init_process_params.event = ob1203_callback_args.event; + } + else + { + if (RM_OB1203_EVENT_SUCCESS == ob1203_callback_args.event) + { + if (NULL != p_ctrl->p_device_status) + { + /* Check device status */ + rm_ob1203_device_status_check(p_ctrl); + + /* Clear pointer */ + p_ctrl->p_device_status = NULL; + + /* Call user callback function */ + rm_ob1203_process_in_callback(p_ctrl, &ob1203_callback_args); + } + else if (NULL != p_ctrl->p_fifo_info) + { + /* Calculate the number of unread FIFO samples */ + rm_ob1203_unread_samples_calculate(p_ctrl); + + /* Clear pointer */ + p_ctrl->p_fifo_info = NULL; + + /* Call user callback function */ + rm_ob1203_process_in_callback(p_ctrl, &ob1203_callback_args); + } + else if (false != p_ctrl->fifo_reset) + { + /* Clear flag */ + p_ctrl->fifo_reset = false; + +#if BSP_CFG_RTOS + + /* Release a semaphore */ + rm_ob1203_os_semaphore_release_from_ISR(p_ctrl->p_semaphore); +#else + + /* Reset FIFO info. */ + err = rm_ob1203_fifo_info_reset(p_ctrl); + if (FSP_SUCCESS != err) + { + /* Set event */ + ob1203_callback_args.event = RM_OB1203_EVENT_ERROR; + + /* Call user callback function */ + rm_ob1203_process_in_callback(p_ctrl, &ob1203_callback_args); + } +#endif + } + else if (false != p_ctrl->prox_gain_update) + { + /* Clear flag */ + p_ctrl->prox_gain_update = false; + +#if BSP_CFG_RTOS + + /* Release a semaphore */ + rm_ob1203_os_semaphore_release_from_ISR(p_ctrl->p_semaphore); +#else + + /* Set Proximity mode gain */ + err = rm_ob1203_ppg_ps_gain_register_write(p_ctrl, (uint8_t) p_ctrl->p_mode->ppg_prox_gain); + if (FSP_SUCCESS != err) + { + /* Set event */ + ob1203_callback_args.event = RM_OB1203_EVENT_ERROR; + + /* Call user callback function */ + rm_ob1203_process_in_callback(p_ctrl, &ob1203_callback_args); + } +#endif + } + else if (false != p_ctrl->interrupt_bits_clear) + { + /* Clear flag */ + p_ctrl->interrupt_bits_clear = false; + +#if BSP_CFG_RTOS + + /* Release a semaphore */ + rm_ob1203_os_semaphore_release_from_ISR(p_ctrl->p_semaphore); +#else + + /* Clear all interrupt bits */ + err = rm_ob1203_all_interrupt_bits_clear(p_ctrl); + if (FSP_SUCCESS != err) + { + /* Set event */ + ob1203_callback_args.event = RM_OB1203_EVENT_ERROR; + + /* Call user callback function */ + rm_ob1203_process_in_callback(p_ctrl, &ob1203_callback_args); + } +#endif + } + else + { + /* Call user callback function */ + rm_ob1203_process_in_callback(p_ctrl, &ob1203_callback_args); + } + } + else + { + /* Call user callback function */ + rm_ob1203_process_in_callback(p_ctrl, &ob1203_callback_args); + } + } +} + +/*******************************************************************************************************************//** + * @brief Read data from OB1203 device. + * + * @retval FSP_SUCCESS Successfully started. + * @retval FSP_ERR_TIMEOUT communication is timeout. + * @retval FSP_ERR_ABORTED communication is aborted. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_read (rm_ob1203_ctrl_t * const p_api_ctrl, rm_comms_write_read_params_t write_read_params) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint16_t counter = 0; + + if (RM_OB1203_OPEN != p_ctrl->open) + { + /* Clear flag */ + p_ctrl->init_process_params.communication_finished = false; + } + + /* WriteRead data */ + err = p_ctrl->p_comms_i2c_instance->p_api->writeRead(p_ctrl->p_comms_i2c_instance->p_ctrl, write_read_params); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + if (RM_OB1203_OPEN != p_ctrl->open) + { + /* Wait callback */ + while (false == p_ctrl->init_process_params.communication_finished) + { + rm_ob1203_delay_ms(p_ctrl, 1); + counter++; + FSP_ERROR_RETURN(RM_OB1203_TIMEOUT >= counter, FSP_ERR_TIMEOUT); + } + + /* Check callback event */ + FSP_ERROR_RETURN(RM_OB1203_EVENT_SUCCESS == p_ctrl->init_process_params.event, FSP_ERR_ABORTED); + } + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Write data to OB1203 device. + * + * @retval FSP_SUCCESS Successfully started. + * @retval FSP_ERR_TIMEOUT communication is timeout. + * @retval FSP_ERR_ABORTED communication is aborted. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_write (rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t * const p_src, uint8_t const bytes) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint16_t counter = 0; + + if (RM_OB1203_OPEN != p_ctrl->open) + { + /* Clear flag */ + p_ctrl->init_process_params.communication_finished = false; + } + + /* Write data */ + err = p_ctrl->p_comms_i2c_instance->p_api->write(p_ctrl->p_comms_i2c_instance->p_ctrl, p_src, (uint32_t) bytes); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + if (RM_OB1203_OPEN != p_ctrl->open) + { + /* Wait callback */ + while (false == p_ctrl->init_process_params.communication_finished) + { + rm_ob1203_delay_ms(p_ctrl, 1); + counter++; + FSP_ERROR_RETURN(RM_OB1203_TIMEOUT >= counter, FSP_ERR_TIMEOUT); + } + + /* Check callback event */ + FSP_ERROR_RETURN(RM_OB1203_EVENT_SUCCESS == p_ctrl->init_process_params.event, FSP_ERR_ABORTED); + } + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Write data to the MAIN_CTRL_0 and MAIN_CTRL_1 registers. + * + * @retval FSP_SUCCESS Successfully started. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_main_ctrl_register_write (rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const main_ctrl_0, + uint8_t const main_ctrl_1) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set the data */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_MAIN_CTRL_0; + p_ctrl->buf[1] = main_ctrl_0; + p_ctrl->buf[2] = main_ctrl_1; + + /* Write data */ + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 3); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Write data to the INT_CFG and INT_PST registers. + * + * @retval FSP_SUCCESS Successfully started. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_int_cfg_register_write (rm_ob1203_ctrl_t * const p_api_ctrl, + uint8_t const int_cfg_0, + uint8_t const int_cfg_1, + uint8_t const int_pst) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set the data */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_INT_CFG_0; + p_ctrl->buf[1] = int_cfg_0; + p_ctrl->buf[2] = int_cfg_1; + p_ctrl->buf[3] = int_pst; + + /* Write data */ + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 4); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Write data to the PPG_PS_GAIN register. + * + * @retval FSP_SUCCESS Successfully started. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_ppg_ps_gain_register_write (rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t const ppg_ps_gain) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set the data */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PPG_PS_GAIN; + p_ctrl->buf[1] = ppg_ps_gain | RM_OB1203_REG_DATA_PPG_PS_GAIN; + + /* Write data */ + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Write data to the PPG_PS_CFG register. + * + * @retval FSP_SUCCESS Successfully started. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_ppg_ps_cfg_register_write (rm_ob1203_ctrl_t * const p_api_ctrl, uint8_t const ppg_ps_cfg) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set the data */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_PPG_PS_CFG; + p_ctrl->buf[1] = ppg_ps_cfg; + + /* Write data */ + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Clear all interrupt bits. + * + * @retval FSP_SUCCESS Successfully started. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_all_interrupt_bits_clear (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + rm_comms_write_read_params_t write_read_params; + + /* Clear all interrupt bits */ + p_ctrl->register_address = RM_OB1203_REG_ADDR_STATUS_0; + write_read_params.p_src = &p_ctrl->register_address; + write_read_params.src_bytes = 1; + write_read_params.p_dest = &p_ctrl->buf[0]; + write_read_params.dest_bytes = 2; + err = rm_ob1203_read(p_ctrl, write_read_params); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Reset FIFO information. + * If device interrupt is enabled, interrupt bits are cleared after measurement stop. + * + * @retval FSP_SUCCESS Successfully started. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_fifo_info_reset (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + if (RM_OB1203_OPERATION_MODE_PPG == p_ctrl->p_mode->mode_irq) + { + /* Clear interrupt bits after FIFO reset */ + p_ctrl->interrupt_bits_clear = true; + } + + /* Reset FIFO information */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_FIFO_WR_PTR; + p_ctrl->buf[1] = 0x00; + p_ctrl->buf[2] = 0x00; + p_ctrl->buf[3] = 0x00; + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 4); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + +#if BSP_CFG_RTOS + if (RM_OB1203_OPERATION_MODE_PPG == p_ctrl->p_mode->mode_irq) + { + /* Acquire a semaphore */ + err = rm_ob1203_os_semaphore_acquire(p_ctrl->p_semaphore, p_ctrl->p_cfg->semaphore_timeout); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Clear all interrupt bits */ + err = rm_ob1203_all_interrupt_bits_clear(p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + } +#endif + + return FSP_SUCCESS; +} + +/*********************************************************************************************************************** + * Private Functions + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * Internal ob1203 private function. + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief Process in callback function. Call user callback. + **********************************************************************************************************************/ +static void rm_ob1203_process_in_callback (rm_ob1203_ctrl_t * const p_api_ctrl, + rm_ob1203_callback_args_t * const p_args) +{ + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + if (NULL != p_ctrl->p_comms_callback) + { + /* Call callback function */ + p_ctrl->p_comms_callback(p_args); + } +} + +/*******************************************************************************************************************//** + * @brief Check device status and set callback event. + **********************************************************************************************************************/ +static void rm_ob1203_device_status_check (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Check if power-on-reset occurs */ + if (0x00 != (p_ctrl->buf[0] & RM_OB1203_MASK_POWER_ON_RESET)) + { + p_ctrl->p_device_status->power_on_reset_occur = true; + } + else + { + p_ctrl->p_device_status->power_on_reset_occur = false; + } + + /* Check if Light mode interrupt condition occurs */ + if (0x00 != (p_ctrl->buf[0] & RM_OB1203_MASK_LIGHT_INTERRUPT)) + { + p_ctrl->p_device_status->light_interrupt_occur = true; + } + else + { + p_ctrl->p_device_status->light_interrupt_occur = false; + } + + /* Check if Light mode measurement is complete */ + if (0x00 != (p_ctrl->buf[0] & RM_OB1203_MASK_LIGHT_DATA_STATUS)) + { + p_ctrl->p_device_status->light_measurement_complete = true; + } + else + { + p_ctrl->p_device_status->light_measurement_complete = false; + } + + /* Check if TS data measurement is complete */ + if (0x00 != (p_ctrl->buf[1] & RM_OB1203_MASK_TS_DATA)) + { + p_ctrl->p_device_status->ts_measurement_complete = true; + } + else + { + p_ctrl->p_device_status->ts_measurement_complete = false; + } + + /* Check if PPG FIFO almost full interrupt condition occurs */ + if (0x00 != (p_ctrl->buf[1] & RM_OB1203_MASK_FIFO_AFULL_INTERRUPT)) + { + p_ctrl->p_device_status->fifo_afull_interrupt_occur = true; + } + else + { + p_ctrl->p_device_status->fifo_afull_interrupt_occur = false; + } + + /* Check if PPG mode measurement is complete */ + if (0x00 != (p_ctrl->buf[1] & RM_OB1203_MASK_PPG_DATA_STATUS)) + { + p_ctrl->p_device_status->ppg_measurement_complete = true; + } + else + { + p_ctrl->p_device_status->ppg_measurement_complete = false; + } + + /* Check if object is near */ + if (0x00 != (p_ctrl->buf[1] & RM_OB1203_MASK_LOGIC_SIGNAL)) + { + p_ctrl->p_device_status->object_near = true; + } + else + { + p_ctrl->p_device_status->object_near = false; + } + + /* Check if Proximity mode interrupt condition occurs */ + if (0x00 != (p_ctrl->buf[1] & RM_OB1203_MASK_PROX_INTERRUPT)) + { + p_ctrl->p_device_status->prox_interrupt_occur = true; + } + else + { + p_ctrl->p_device_status->prox_interrupt_occur = false; + } + + /* Check if Proximity mode measurement is complete */ + if (0x00 != (p_ctrl->buf[1] & RM_OB1203_MASK_PROX_DATA_STATUS)) + { + p_ctrl->p_device_status->prox_measurement_complete = true; + } + else + { + p_ctrl->p_device_status->prox_measurement_complete = false; + } +} + +/*******************************************************************************************************************//** + * @brief Calculate the number of unread FIFO samples. + **********************************************************************************************************************/ +static void rm_ob1203_unread_samples_calculate (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + uint8_t unread_samples = 0; + + /* Calculate the number of unread FIFO samples */ + unread_samples = p_ctrl->buf[0]; + if (p_ctrl->buf[0] < p_ctrl->buf[1]) + { + unread_samples += RM_OB1203_FIFO_MAX_SAMPLES_32; // Number of samples is up to 32. + } + + unread_samples -= p_ctrl->buf[1]; + + if (RM_OB1203_PPG_SENSOR_MODE_PPG2 == p_ctrl->p_mode->ppg_sensor_mode) + { + /* In PPG2 mode, Two samples is one pair. */ + unread_samples &= RM_OB1203_FIFO_MASK_PPG2_0XFE; + } + + /* Set data */ + p_ctrl->p_fifo_info->write_index = p_ctrl->buf[0]; + p_ctrl->p_fifo_info->read_index = p_ctrl->buf[1]; + p_ctrl->p_fifo_info->overflow_counter = p_ctrl->buf[2]; + p_ctrl->p_fifo_info->unread_samples = unread_samples; +} + +/*******************************************************************************************************************//** + * @brief Software reset. + * + * @retval FSP_SUCCESS Successfully started. + * @retval FSP_ERR_TIMEOUT Communication is timeout. + * @retval FSP_ERR_ABORTED Communication is aborted. + **********************************************************************************************************************/ +static fsp_err_t rm_ob1203_software_reset (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + + /* Set the data */ + p_ctrl->buf[0] = RM_OB1203_REG_ADDR_MAIN_CTRL_0; + p_ctrl->buf[1] = RM_OB1203_COMMAND_SOFTWARE_RESET; + + /* Software reset */ + err = rm_ob1203_write(p_ctrl, &p_ctrl->buf[0], 2); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} diff --git a/ra/fsp/src/rm_ob1203/rm_ob1203_ra_driver.c b/ra/fsp/src/rm_ob1203/rm_ob1203_ra_driver.c new file mode 100644 index 000000000..11d1117a2 --- /dev/null +++ b/ra/fsp/src/rm_ob1203/rm_ob1203_ra_driver.c @@ -0,0 +1,250 @@ +/*********************************************************************************************************************** + * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved. + * + * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products + * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are + * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use + * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property + * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas + * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION + * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT + * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR + * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM + * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION + * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING, + * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS, + * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY + * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS. + **********************************************************************************************************************/ + +/********************************************************************************************************************** + * Includes , "Project Includes" + *********************************************************************************************************************/ +#include "rm_ob1203.h" + +/********************************************************************************************************************** + * Macro definitions + *********************************************************************************************************************/ + +/********************************************************************************************************************** + * Local Typedef definitions + *********************************************************************************************************************/ + +/********************************************************************************************************************** + * Exported global variables + *********************************************************************************************************************/ +fsp_err_t rm_ob1203_delay_ms(rm_ob1203_ctrl_t * const p_ctrl, uint32_t const delay_ms); +fsp_err_t rm_ob1203_irq_open(rm_ob1203_ctrl_t * const p_api_ctrl); +fsp_err_t rm_ob1203_irq_close(rm_ob1203_ctrl_t * const p_api_ctrl); +void rm_ob1203_irq_callback(external_irq_callback_args_t * p_args); + +#if BSP_CFG_RTOS +fsp_err_t rm_ob1203_os_semaphore_create(rm_ob1203_semaphore_t const * p_semaphore); +fsp_err_t rm_ob1203_os_semaphore_delete(rm_ob1203_semaphore_t const * p_semaphore); +fsp_err_t rm_ob1203_os_semaphore_acquire(rm_ob1203_semaphore_t const * p_semaphore, uint32_t const timeout); +fsp_err_t rm_ob1203_os_semaphore_release_from_ISR(rm_ob1203_semaphore_t const * p_semaphore); + +#endif + +/********************************************************************************************************************** + * Private (static) variables and functions + *********************************************************************************************************************/ + +/*********************************************************************************************************************** + * Functions + **********************************************************************************************************************/ + +/*******************************************************************************************************************//** + * @brief Delay some milliseconds. + * + * @retval FSP_SUCCESS successfully configured. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_delay_ms (rm_ob1203_ctrl_t * const p_ctrl, uint32_t const delay_ms) +{ + FSP_PARAMETER_NOT_USED(p_ctrl); + + /* Software delay */ + R_BSP_SoftwareDelay(delay_ms, BSP_DELAY_UNITS_MILLISECONDS); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Open IRQ driver and set callback function. + * + * @retval FSP_SUCCESS successfully configured. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_irq_open (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + fsp_err_t err = FSP_SUCCESS; + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + external_irq_instance_t * p_irq_instance = (external_irq_instance_t *) p_ctrl->p_irq_instance; + + /* Open IRQ driver */ + err = p_irq_instance->p_api->open(p_irq_instance->p_ctrl, p_irq_instance->p_cfg); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Set callback function and current control block */ + err = p_irq_instance->p_api->callbackSet(p_irq_instance->p_ctrl, rm_ob1203_irq_callback, p_ctrl, NULL); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + /* Enable IRQ */ + err = p_irq_instance->p_api->enable(p_irq_instance->p_ctrl); + FSP_ERROR_RETURN(FSP_SUCCESS == err, err); + + return FSP_SUCCESS; +} + +/*******************************************************************************************************************//** + * @brief Close IRQ driver. + * + * @retval FSP_SUCCESS successfully configured. + **********************************************************************************************************************/ +fsp_err_t rm_ob1203_irq_close (rm_ob1203_ctrl_t * const p_api_ctrl) +{ + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_api_ctrl; + external_irq_instance_t * p_irq_instance = (external_irq_instance_t *) p_ctrl->p_irq_instance; + + /* Close IRQ driver */ + p_irq_instance->p_api->close(p_irq_instance->p_ctrl); + + return FSP_SUCCESS; +} + +void rm_ob1203_irq_callback (external_irq_callback_args_t * p_args) +{ + rm_ob1203_instance_ctrl_t * p_ctrl = (rm_ob1203_instance_ctrl_t *) p_args->p_context; + rm_ob1203_callback_args_t ob1203_callback_args; + + /* Set context */ + ob1203_callback_args.p_context = p_ctrl->p_context; + + /* Set event */ + switch (p_ctrl->p_mode->mode_irq) + { + case RM_OB1203_OPERATION_MODE_LIGHT: + { + ob1203_callback_args.event = RM_OB1203_EVENT_THRESHOLD_CROSSED; + break; + } + + case RM_OB1203_OPERATION_MODE_PROXIMITY: + { + if (RM_OB1203_PROX_INTERRUPT_TYPE_LOGIC == p_ctrl->p_mode->prox_interrupt_type) + { + ob1203_callback_args.event = RM_OB1203_EVENT_OBJECT_NEAR; + } + else + { + /* RM_OB1203_PROX_INTERRUPT_TYPE_NORMAL */ + ob1203_callback_args.event = RM_OB1203_EVENT_THRESHOLD_CROSSED; + } + + break; + } + + case RM_OB1203_OPERATION_MODE_PPG: + { + ob1203_callback_args.event = RM_OB1203_EVENT_MEASUREMENT_COMPLETE; + break; + } + + default: + { + ob1203_callback_args.event = RM_OB1203_EVENT_ERROR; + break; + } + } + + if (NULL != p_ctrl->p_irq_callback) + { + /* Call callback function */ + p_ctrl->p_irq_callback(&ob1203_callback_args); + } +} + +#if BSP_CFG_RTOS + +/********************************************************************************************************************** + * @brief Create a mutex. + * + * @retval FSP_SUCCESS successfully configured. + * @retval FSP_ERR_INTERNAL RTOS internal error. + *********************************************************************************************************************/ +fsp_err_t rm_ob1203_os_semaphore_create (rm_ob1203_semaphore_t const * p_semaphore) +{ + #if BSP_CFG_RTOS == 1 // AzureOS + UINT status; + status = tx_semaphore_create(p_semaphore->p_semaphore_handle, p_semaphore->p_semaphore_name, (ULONG) 0); + FSP_ERROR_RETURN(TX_SUCCESS == status, FSP_ERR_INTERNAL); + #elif BSP_CFG_RTOS == 2 // FreeRTOS + *(p_semaphore->p_semaphore_handle) = + xSemaphoreCreateCountingStatic((UBaseType_t) 1, (UBaseType_t) 0, p_semaphore->p_semaphore_memory); + #endif + + return FSP_SUCCESS; +} + +/********************************************************************************************************************** + * @brief Create a mutex. + * + * @retval FSP_SUCCESS successfully configured. + * @retval FSP_ERR_INTERNAL RTOS internal error. + *********************************************************************************************************************/ +fsp_err_t rm_ob1203_os_semaphore_delete (rm_ob1203_semaphore_t const * p_semaphore) +{ + #if BSP_CFG_RTOS == 1 // AzureOS + UINT status; + status = tx_semaphore_delete(p_semaphore->p_semaphore_handle); + FSP_ERROR_RETURN(TX_SUCCESS == status, FSP_ERR_INTERNAL); + #elif BSP_CFG_RTOS == 2 // FreeRTOS + vSemaphoreDelete(*(p_semaphore->p_semaphore_handle)); + #endif + + return FSP_SUCCESS; +} + +/********************************************************************************************************************** + * @brief Acquire a semaphore. + * + * @retval FSP_SUCCESS successfully configured. + * @retval FSP_ERR_INTERNAL RTOS internal error. + *********************************************************************************************************************/ +fsp_err_t rm_ob1203_os_semaphore_acquire (rm_ob1203_semaphore_t const * p_semaphore, uint32_t const timeout) +{ + #if BSP_CFG_RTOS == 1 // ThreadX + UINT status; + status = tx_semaphore_get(p_semaphore->p_semaphore_handle, (ULONG) timeout); + FSP_ERROR_RETURN(TX_SUCCESS == status, FSP_ERR_INTERNAL); + #elif BSP_CFG_RTOS == 2 // FreeRTOS + BaseType_t sem_err; + sem_err = xSemaphoreTake(*(p_semaphore->p_semaphore_handle), (TickType_t) timeout); + FSP_ERROR_RETURN(pdTRUE == sem_err, FSP_ERR_INTERNAL); + #endif + + return FSP_SUCCESS; +} + +/********************************************************************************************************************** + * @brief Release a semaphore from an interrupt. + * + * @retval FSP_SUCCESS successfully configured. + * @retval FSP_ERR_INTERNAL RTOS internal error. + *********************************************************************************************************************/ +fsp_err_t rm_ob1203_os_semaphore_release_from_ISR (rm_ob1203_semaphore_t const * p_semaphore) +{ + #if BSP_CFG_RTOS == 1 // ThreadX + UINT status; + status = tx_semaphore_put(p_semaphore->p_semaphore_handle); + FSP_ERROR_RETURN(TX_SUCCESS == status, FSP_ERR_INTERNAL); + #elif BSP_CFG_RTOS == 2 // FreeRTOS + BaseType_t sem_err; + sem_err = xSemaphoreGiveFromISR(*(p_semaphore->p_semaphore_handle), NULL); + FSP_ERROR_RETURN(pdTRUE == sem_err, FSP_ERR_INTERNAL); + #endif + + return FSP_SUCCESS; +} + +#endif diff --git a/ra/fsp/src/rm_psa_crypto/rsa_alt_process.c b/ra/fsp/src/rm_psa_crypto/rsa_alt_process.c index 28b4e70ac..d04e3941d 100644 --- a/ra/fsp/src/rm_psa_crypto/rsa_alt_process.c +++ b/ra/fsp/src/rm_psa_crypto/rsa_alt_process.c @@ -255,7 +255,6 @@ int mbedtls_rsa_public (mbedtls_rsa_context * ctx, const unsigned char * input, hw_sce_rsa_public_encrypt_t p_hw_sce_rsa_public_encrypt; - // TODO: temporary implementation. if (ctx->len == RSA_MODULUS_SIZE_BYTES(RSA_2048_BITS)) { p_hw_sce_rsa_public_encrypt = HW_SCE_RSA_2048PublicKeyEncrypt; diff --git a/ra/fsp/src/rm_usbx_port/rm_usbx_phid_descriptor_keyboard.c.template b/ra/fsp/src/rm_usbx_port/rm_usbx_phid_descriptor_keyboard.c.template index ee0bbd1bb..e10861e36 100644 --- a/ra/fsp/src/rm_usbx_port/rm_usbx_phid_descriptor_keyboard.c.template +++ b/ra/fsp/src/rm_usbx_port/rm_usbx_phid_descriptor_keyboard.c.template @@ -9,6 +9,8 @@ /****************************************************************************** * Macro definitions ******************************************************************************/ +// #define HID_OUT_TRNASFER + #define USB_BCDNUM (0x0200U) /* bcdUSB */ #define USB_RELEASE (0x0200U) /* Release Number */ #define USB_CONFIGNUM (1U) /* Configuration number */ @@ -17,7 +19,12 @@ #define USB_IFPROTOCOL (USB_IFPRO_KBD) #define ITEM_LEN (76U) #define MXPS (8U) + +#ifdef HID_OUT_TRNASFER +#define NUM_EP (2U) +#else /* HID_OUT_TRNASFER */ #define NUM_EP (1U) +#endif /* HID_OUT_TRNASFER */ /* [Vendor ID & Product ID setting] */ #define USB_VENDORID (0x0000U) @@ -27,7 +34,11 @@ #define NUM_STRING_DESCRIPTOR (7U) /* Configuration Descriptor Length */ +#ifdef HID_OUT_TRNASFER +#define CD_LEN (34+7U) +#else /* HID_OUT_TRNASFER */ #define CD_LEN (34U) +#endif /* HID_OUT_TRNASFER */ /* Descriptor data Mask */ #define USB_VALUE_32 (32) @@ -53,7 +64,12 @@ /************************************************************ * Device Descriptor * ************************************************************/ +#ifdef HID_OUT_TRNASFER +#define DEVICE_FRAME_LENGTH_SPEED (59U) +#else /* HID_OUT_TRNASFER */ #define DEVICE_FRAME_LENGTH_SPEED (52U) +#endif /* HID_OUT_TRNASFER */ + uint8_t g_device_framework_full_speed[DEVICE_FRAME_LENGTH_SPEED] = { /* Device Descriptor */ @@ -117,6 +133,17 @@ uint8_t g_device_framework_full_speed[DEVICE_FRAME_LENGTH_SPEED] = MXPS, /* 4:wMaxPacketSize_lo */ 0, /* 5:wMaxPacketSize_hi */ 0x0A, /* 6:bInterval */ + +#ifdef HID_OUT_TRNASFER + /* Endpoint Descriptor 0 */ + USB_ED_BLENGTH, /* 0:bLength */ + USB_DT_ENDPOINT, /* 1:bDescriptorType */ + (uint8_t) (USB_EP_OUT | USB_EP2), /* 2:bEndpointAddress */ + USB_EP_INT, /* 3:bmAttribute */ + 64, /* 4:wMaxPacketSize_lo */ + 0, /* 5:wMaxPacketSize_hi */ + 0x0A, /* 6:bInterval */ +#endif /* HID_OUT_TRNASFER */ }; /************************************************************ @@ -161,7 +188,7 @@ uint8_t g_string_framework[] = '1', /* iConfiguration */ - 0x09, 0x04, 0x3, 11, + 0x09, 0x04, 0x4, 11, 'F', 'S', ' ', @@ -219,7 +246,7 @@ uint8_t g_apl_report[USB_VALUE_76] = USB_VALUE_29H, USB_VALUE_65H, /* Usage Maximum (101) */ USB_VALUE_81H, 0x00, /* Input (Data , Array) ;Key arrays (6 bytes) */ - /* *** The OUTPUR REPORT *** */ + /* *** The OUTPUT REPORT *** */ 0x09, 0x00, /* Usage ID within this page (Vendor defined)*/ 0x15, 0x00, /* Logical Min 0 */ USB_VALUE_26H, USB_UCHAR_MAX, 0x00,/* Logical Max 255 */ diff --git a/ra/fsp/src/rm_usbx_port/rm_usbx_port.c b/ra/fsp/src/rm_usbx_port/rm_usbx_port.c index 99c7d2fd2..5ebf6e0d9 100644 --- a/ra/fsp/src/rm_usbx_port/rm_usbx_port.c +++ b/ra/fsp/src/rm_usbx_port/rm_usbx_port.c @@ -45,6 +45,10 @@ #include "r_usb_hhid_cfg.h" #endif /* defined(USB_CFG_HHID_USE) */ + #if defined(USB_CFG_PHID_USE) + #include "r_usb_phid_cfg.h" + #endif /* defined(USB_CFG_HHID_USE) */ + #if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) #include "ux_host_stack.h" #endif /* #if ((USB_CFG_MODE & USB_CFG_HOST) == USB_CFG_HOST) */ @@ -558,13 +562,41 @@ static UINT usb_peri_usbx_to_basic (UX_SLAVE_DCD * dcd, UINT function, VOID * pa status = (uint32_t) UX_SUCCESS; } + #elif defined(USB_CFG_PHID_USE) + if (USB_CFG_PHID_INT_OUT == pipe) + { + status = (uint32_t) UX_TRANSFER_ERROR; + } + else + { + status = (uint32_t) UX_SUCCESS; + } + #else /* defined(USB_CFG_PMSC_USE) */ status = (uint32_t) UX_SUCCESS; #endif /* define(USB_CFG_PMSC_USE */ } else { + #if defined(USB_CFG_PMSC_USE) + + /* The error code other UX_SUCCESS must be returned than * + * when USB peripheral device status is not CONFIGURED status. */ + uint16_t dvsq; + dvsq = hw_usb_read_intsts(module_number); + + if (USB_DS_CNFG == (dvsq & USB_DVSQ)) + { + status = (uint32_t) UX_SUCCESS; + } + else + { + status = (uint32_t) UX_TRANSFER_ERROR; + } + + #else /* defined(USB_CFG_PMSC_USE) */ status = (uint32_t) UX_SUCCESS; + #endif /* define(USB_CFG_PMSC_USE */ } } else @@ -611,38 +643,50 @@ static UINT usb_peri_usbx_to_basic (UX_SLAVE_DCD * dcd, UINT function, VOID * pa } case (uint32_t) UX_DCD_TRANSFER_ABORT: - { #if defined(USB_CFG_PCDC_USE) - CHAR * name; - ULONG current_value; - TX_THREAD * first_suspended; - ULONG suspended_count; - TX_SEMAPHORE * next_semaphore; - - transfer_request = (UX_SLAVE_TRANSFER *) parameter; - endpoint = transfer_request->ux_slave_transfer_request_endpoint; - endpoint_index = endpoint->ux_slave_endpoint_descriptor.bEndpointAddress; - if (0 != endpoint_index) { - pipe = usb_pstd_epadr2pipe((uint16_t) endpoint_index, &tran_data); - } + CHAR * name; + ULONG current_value; + TX_THREAD * first_suspended; + ULONG suspended_count; + TX_SEMAPHORE * next_semaphore; + + transfer_request = (UX_SLAVE_TRANSFER *) parameter; + endpoint = transfer_request->ux_slave_transfer_request_endpoint; + endpoint_index = endpoint->ux_slave_endpoint_descriptor.bEndpointAddress; + if (0 != endpoint_index) + { + pipe = usb_pstd_epadr2pipe((uint16_t) endpoint_index, &tran_data); + } - tx_semaphore_info_get(&g_usb_peri_usbx_sem[pipe], - &name, - ¤t_value, - &first_suspended, - &suspended_count, - &next_semaphore); + tx_semaphore_info_get(&g_usb_peri_usbx_sem[pipe], + &name, + ¤t_value, + &first_suspended, + &suspended_count, + &next_semaphore); - if (suspended_count == 1) - { - _ux_utility_thread_suspend(first_suspended); - tx_semaphore_put(&g_usb_peri_usbx_sem[pipe]); + if (suspended_count == 1) + { + _ux_utility_thread_suspend(first_suspended); + tx_semaphore_put(&g_usb_peri_usbx_sem[pipe]); + } + + break; } - #endif /* #if defined(USB_CFG_PCDC_USE) */ + #elif defined(USB_CFG_PPRN_USE) /* #if defined(USB_CFG_PCDC_USE) */ + { + for (pipe = USB_MIN_PIPE_NO; pipe < (USB_MAXPIPE_NUM + 1); pipe++) + { + if (USB_TRUE == g_usb_pipe_table[tran_data.ip][pipe].use_flag) + { + usb_pstd_forced_termination(pipe, (uint16_t) USB_DATA_STOP, &tran_data); + } + } - break; - } + break; + } + #endif case (uint32_t) UX_DCD_CREATE_ENDPOINT: { @@ -1372,6 +1416,11 @@ void usb_host_usbx_class_check (usb_utr_t * p_utr, uint16_t ** table) usb_pipe_table_reg_t ep_tbl; #endif /* #if !defined(USB_CFG_HMSC_USE) */ + #if defined(USB_CFG_HHID_USE) + uint8_t num_set_pipe = 0; + uint8_t set_pipe_no[2] = {0, 0}; + #endif /* defined(USB_CFG_HHID_USE) */ + speed = *table[6]; p_config = (uint8_t *) table[1]; length = (uint16_t) (*(p_config + 3) << 8); @@ -1429,13 +1478,17 @@ void usb_host_usbx_class_check (usb_utr_t * p_utr, uint16_t ** table) &ep_tbl); if (USB_NULL != pipe_no) { - usb_hstd_set_pipe_info(p_utr->ip, pipe_no, &ep_tbl); #if defined(USB_CFG_HHID_USE) - if (USB_CFG_HHID_INT_IN == pipe_no) + if ((pipe_no != set_pipe_no[0]) && (pipe_no != set_pipe_no[1]) && (num_set_pipe < 2)) { - break; + set_pipe_no[num_set_pipe] = pipe_no; + num_set_pipe++; + usb_hstd_set_pipe_info(p_utr->ip, pipe_no, &ep_tbl); } - #endif + + #else /* defined(USB_CFG_HHID_USE) */ + usb_hstd_set_pipe_info(p_utr->ip, pipe_no, &ep_tbl); + #endif /* defined(USB_CFG_HHID_USE) */ } else { @@ -1694,7 +1747,10 @@ static void usb_host_usbx_transfer_complete_cb (usb_utr_t * p_utr, uint16_t data #if defined(USB_CFG_HHID_USE) transfer_request->ux_transfer_request_completion_code = UX_SUCCESS; - transfer_request->ux_transfer_request_completion_function(transfer_request); + if (UX_NULL != transfer_request->ux_transfer_request_completion_function) + { + transfer_request->ux_transfer_request_completion_function(transfer_request); + } #endif /* defined(USB_CFG_HHID_USE) */ #if defined(USB_CFG_OTG_USE) diff --git a/ra/fsp/src/rm_usbx_port/rm_usbx_pprn_descriptor.c.template b/ra/fsp/src/rm_usbx_port/rm_usbx_pprn_descriptor.c.template new file mode 100644 index 000000000..46f60d522 --- /dev/null +++ b/ra/fsp/src/rm_usbx_port/rm_usbx_pprn_descriptor.c.template @@ -0,0 +1,274 @@ +/* ${REA_DISCLAIMER_PLACEHOLDER} */ + /****************************************************************************** + Includes , "Project Includes" + ******************************************************************************/ +#include +#include +#include "r_usb_basic_cfg.h" + +/****************************************************************************** + Macro definitions + ******************************************************************************/ +/* bcdUSB */ +#define USB_BCDNUM (0x0200U) +/* Release Number */ +#define USB_RELEASE (0x0200U) +/* DCP max packet size */ +#define USB_DCPMAXP (64U) +/* Configuration number */ +#define USB_CONFIGNUM (1U) +/* Vendor ID */ +#define USB_VENDORID (0x0000U) +/* Product ID */ +#define USB_PRODUCTID (0x0007U) + +/* Descriptor length */ +#define USB_PPRN_QD_LEN (10U) + +/* Descriptor data Mask */ +#define USB_UCHAR_MAX (0xffU) +#define USB_W_TOTAL_LENGTH_MASK (256U) +#define USB_W_MAX_PACKET_SIZE_MASK (64U) + +/* Define device framework. */ +#define DEMO_PROTOCOL (1U) /* 1-Uni-dir, 2-Bi-dir */ + +#define CD_LEN (9+9+7+((DEMO_PROTOCOL > 1) ? 7 : 0)) + + +/****************************************************************************** + Private global variables and functions + ******************************************************************************/ + +/****************************************************************************** + Exported global variables + ******************************************************************************/ + +/****************************************************************************** + Exported global functions (to be accessed by other files) + ******************************************************************************/ +uint8_t g_device_framework_full_speed[] = { + + /* Device descriptor */ + USB_DD_BLENGTH, /* 0:bLength */ + USB_DT_DEVICE, /* 1:bDescriptorType */ + (uint8_t) (USB_BCDNUM & (uint8_t) USB_UCHAR_MAX), /* 2:bcdUSB_lo */ + (uint8_t) ((uint8_t) (USB_BCDNUM >> 8) & (uint8_t) USB_UCHAR_MAX), /* 3:bcdUSB_hi */ + 0x00, /* 4:bDeviceClass */ + 0x00, /* 5:bDeviceSubClass */ + 0x00, /* 6:bDeviceProtocol */ + (uint8_t) USB_DCPMAXP, /* 7:bMAXPacketSize(for DCP) */ + (uint8_t) (USB_VENDORID & (uint8_t) USB_UCHAR_MAX), /* 8:idVendor_lo */ + (uint8_t) ((uint8_t) (USB_VENDORID >> 8) & (uint8_t) USB_UCHAR_MAX), /* 9:idVendor_hi */ + (uint8_t) (USB_PRODUCTID & (uint8_t) USB_UCHAR_MAX), /* 10:idProduct_lo */ + (uint8_t) ((uint8_t) (USB_PRODUCTID >> 8) & (uint8_t) USB_UCHAR_MAX), /* 11:idProduct_hi */ + (uint8_t) (USB_RELEASE & (uint8_t) USB_UCHAR_MAX), /* 12:bcdDevice_lo */ + (uint8_t) ((uint8_t) (USB_RELEASE >> 8) & (uint8_t) USB_UCHAR_MAX), /* 13:bcdDevice_hi */ + 1, /* 14:iManufacturer */ + 2, /* 15:iProduct */ + 3, /* 16:iSerialNumber */ + USB_CONFIGNUM, /* 17:bNumConfigurations */ + + /* Configuration Descriptor */ + USB_CD_BLENGTH, /* 0:bLength */ + USB_SOFT_CHANGE, /* 1:bDescriptorType */ + (uint8_t) (CD_LEN % USB_W_TOTAL_LENGTH_MASK), /* 2:wTotalLength(L) */ + (uint8_t) (CD_LEN / USB_W_TOTAL_LENGTH_MASK), /* 3:wTotalLength(H) */ + 1, /* 4:bNumInterfaces */ + 1, /* 5:bConfigurationValue */ + 0, /* 6:iConfiguration */ + (uint8_t) (USB_CF_RESERVED | USB_CF_SELFP), /* 7:bmAttributes */ + (uint8_t) (10 / 2), /* 8:bMaxPower (2mA unit) */ + + /* Interface Descriptor */ + USB_ID_BLENGTH, /* 0:bLength */ + USB_DT_INTERFACE, /* 1:bDescriptor */ + 0, /* 2:bInterfaceNumber */ + 0, /* 3:bAlternateSetting */ + (DEMO_PROTOCOL > 1) ? 2 : 1, /* 4:bNumEndpoints */ + USB_IFCLS_PRN, /* 5:bInterfaceClass(Printer) */ + 0x01, /* 6:bInterfaceSubClass */ + DEMO_PROTOCOL, /* 7:bInterfaceProtocol */ + 0, /* 8:iInterface */ + + /* Endpoint Descriptor 0 */ + USB_ED_BLENGTH, /* 0:bLength */ + USB_DT_ENDPOINT, /* 1:bDescriptorType */ + (uint8_t) (USB_EP_OUT | USB_EP1), /* 2:bEndpointAddress */ + USB_EP_BULK, /* 3:bmAttribute */ + USB_W_MAX_PACKET_SIZE_MASK, /* 4:wMaxPacketSize_lo */ + 0, /* 5:wMaxPacketSize_hi */ + 0, /* 6:bInterval */ + +#if DEMO_PROTOCOL > 1 + /* Endpoint Descriptor 1 */ + USB_ED_BLENGTH, /* 0:bLength */ + USB_DT_ENDPOINT, /* 1:bDescriptorType */ + (uint8_t) (USB_EP_IN | USB_EP2), /* 2:bEndpointAddress */ + USB_EP_BULK, /* 3:bmAttribute */ + USB_W_MAX_PACKET_SIZE_MASK, /* 4:wMaxPacketSize_lo */ + 0, /* 5:wMaxPacketSize_hi */ + 0, /* 6:bInterval */ +#endif +}; + +uint8_t g_device_framework_hi_speed[] = { + + /* Device descriptor */ + USB_DD_BLENGTH, /* 0:bLength */ + USB_DT_DEVICE, /* 1:bDescriptorType */ + (uint8_t) (USB_BCDNUM & (uint8_t) USB_UCHAR_MAX), /* 2:bcdUSB_lo */ + (uint8_t) ((uint8_t) (USB_BCDNUM >> 8) & (uint8_t) USB_UCHAR_MAX), /* 3:bcdUSB_hi */ + 0x00, /* 4:bDeviceClass */ + 0x00, /* 5:bDeviceSubClass */ + 0x00, /* 6:bDeviceProtocol */ + (uint8_t) USB_DCPMAXP, /* 7:bMAXPacketSize(for DCP) */ + (uint8_t) (USB_VENDORID & (uint8_t) USB_UCHAR_MAX), /* 8:idVendor_lo */ + (uint8_t) ((uint8_t) (USB_VENDORID >> 8) & (uint8_t) USB_UCHAR_MAX), /* 9:idVendor_hi */ + (uint8_t) (USB_PRODUCTID & (uint8_t) USB_UCHAR_MAX), /* 10:idProduct_lo */ + (uint8_t) ((uint8_t) (USB_PRODUCTID >> 8) & (uint8_t) USB_UCHAR_MAX), /* 11:idProduct_hi */ + (uint8_t) (USB_RELEASE & (uint8_t) USB_UCHAR_MAX), /* 12:bcdDevice_lo */ + (uint8_t) ((uint8_t) (USB_RELEASE >> 8) & (uint8_t) USB_UCHAR_MAX), /* 13:bcdDevice_hi */ + 1, /* 14:iManufacturer */ + 2, /* 15:iProduct */ + 3, /* 16:iSerialNumber */ + USB_CONFIGNUM, /* 17:bNumConfigurations */ + + /* Device qualifier descriptor */ + USB_PPRN_QD_LEN, /* 0:bLength */ + USB_DT_DEVICE_QUALIFIER, /* 1:bDescriptorType */ + (USB_BCDNUM & (uint8_t) USB_UCHAR_MAX), /* 2:bcdUSB_lo */ + ((uint8_t) (USB_BCDNUM >> 8) & (uint8_t) USB_UCHAR_MAX), /* 3:bcdUSB_hi */ + 0, /* 4:bDeviceClass */ + 0, /* 5:bDeviceSubClass */ + 0, /* 6:bDeviceProtocol */ + (uint8_t) USB_DCPMAXP, /* 7:bMAXPacketSize(for DCP) */ + USB_CONFIGNUM, /* 8:bNumConfigurations */ + 0, /* 9:bReserved */ + + /* Configuration Descriptor */ + USB_CD_BLENGTH, /* 0:bLength */ + USB_SOFT_CHANGE, /* 1:bDescriptorType */ + (uint8_t) (CD_LEN % USB_W_TOTAL_LENGTH_MASK), /* 2:wTotalLength(L) */ + (uint8_t) (CD_LEN / USB_W_TOTAL_LENGTH_MASK), /* 3:wTotalLength(H) */ + 1, /* 4:bNumInterfaces */ + 1, /* 5:bConfigurationValue */ + 0, /* 6:iConfiguration */ + (uint8_t) (USB_CF_RESERVED | USB_CF_SELFP), /* 7:bmAttributes */ + (uint8_t) (10 / 2), /* 8:bMaxPower (2mA unit) */ + + /* Interface Descriptor */ + USB_ID_BLENGTH, /* 0:bLength */ + USB_DT_INTERFACE, /* 1:bDescriptor */ + 0, /* 2:bInterfaceNumber */ + 0, /* 3:bAlternateSetting */ + (DEMO_PROTOCOL > 1) ? 2 : 1, /* 4:bNumEndpoints */ + USB_IFCLS_PRN, /* 5:bInterfaceClass(Printer) */ + 0x01, /* 6:bInterfaceSubClass */ + DEMO_PROTOCOL, /* 7:bInterfaceProtocol */ + 0, /* 8:iInterface */ + + /* Endpoint Descriptor 0 */ + USB_ED_BLENGTH, /* 0:bLength */ + USB_DT_ENDPOINT, /* 1:bDescriptorType */ + (uint8_t) (USB_EP_OUT | USB_EP1), /* 2:bEndpointAddress */ + USB_EP_BULK, /* 3:bmAttribute */ + 0x00, /* 4:wMaxPacketSize_lo */ + 0x02, /* 5:wMaxPacketSize_hi */ + 0, /* 6:bInterval */ + +#if DEMO_PROTOCOL > 1 + /* Endpoint Descriptor 1 */ + USB_ED_BLENGTH, /* 0:bLength */ + USB_DT_ENDPOINT, /* 1:bDescriptorType */ + (uint8_t) (USB_EP_IN | USB_EP2), /* 2:bEndpointAddress */ + USB_EP_BULK, /* 3:bmAttribute */ + 0x00, /* 4:wMaxPacketSize_lo */ + 0x02, /* 5:wMaxPacketSize_hi */ + 0, /* 6:bInterval */ +#endif +}; + +/* String Device Framework : + Byte 0 and 1 : Word containing the language ID : 0x0904 for US + Byte 2 : Byte containing the index of the descriptor + Byte 3 : Byte containing the length of the descriptor string +*/ +uint8_t g_string_framework[] = { + + /* Manufacturer string descriptor : Index 1 */ + 0x09, 0x04, 0x01, 14, + 'A', + 'z', + 'u', + 'r', + 'e', + ' ', + 'R', + 'T', + 'O', + 'S', + 'U', + 'S', + 'B', + 'X', + + /* Product string descriptor : Index 2 */ + 0x09, 0x04, 0x02, 12, + 'P', + 'r', + 'i', + 'n', + 't', + 'e', + 'r', + ' ', + 'D', + 'e', + 'm', + 'o', + + /* Serial Number string descriptor : Index 3 */ + 0x09, 0x04, 0x03, 15, + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '1', +}; + +/* Multiple languages are supported on the device, to add + a language besides english, the unicode language code must + be appended to the language_id_framework array and the length + adjusted accordingly. */ +uint8_t g_language_id_framework[] = { + + /* English. */ + 0x09, + 0x04 +}; + +/* Device printer device ID. */ +uint8_t printer_device_id[] = +{ + " " /* Will be replaced by length (big endian) */ + "MFG:Generic;" /* manufacturer (case sensitive) */ + "MDL:Generic_/_Text_Only;" /* model (case sensitive) */ + "CMD:1284.4;" /* PDL command set */ + "CLS:PRINTER;" /* class */ + "DES:Generic text only printer;" /* description */ +}; + +/****************************************************************************** + End Of File + ******************************************************************************/ diff --git a/ra/fsp/src/rm_usbx_port/ux_port.h b/ra/fsp/src/rm_usbx_port/ux_port.h index 82db37b14..f46f1ab41 100644 --- a/ra/fsp/src/rm_usbx_port/ux_port.h +++ b/ra/fsp/src/rm_usbx_port/ux_port.h @@ -67,6 +67,33 @@ extern "C" { #endif + #if !defined(UX_STANDALONE) + #include "tx_api.h" + #else + +/* VAR types used in UX, + * if TX still used, expects tx_api.h included before include this. */ + #if !defined(TX_API_H) && !defined(TX_PORT_H) + + #include +typedef void VOID; +typedef char CHAR; +typedef unsigned char UCHAR; +typedef int INT; +typedef unsigned int UINT; +typedef long LONG; +typedef unsigned long ULONG; +typedef short SHORT; +typedef unsigned short USHORT; +typedef uint64_t ULONG64; + + #ifndef ALIGN_TYPE_DEFINED + #define ALIGN_TYPE ULONG + #endif + + #endif + #endif + /* CPU definition for X86 systems without preemptive timer function. * This will make USBX uses the controller for the timer. */ @@ -212,4 +239,6 @@ extern CHAR _ux_version_id[]; #define UX_OTG_SUPPORT #endif + #define UX_HOST_CLASS_HID_INTERRUPT_OUT_SUPPORT + #define UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT #endif