Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hal: telink: update SOC(TL321x) to A2 #146

Draft
wants to merge 4 commits into
base: develop_dual_new
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tlsr9/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ if (NOT (CONFIG_SOC_SERIES_RISCV_TELINK_TLX OR CONFIG_SOC_RISCV_TELINK_TLX))
zephyr_library_sources(drivers/${SOC}/analog.c)
endif()

# analog_user.c reference sources for B92 and TL321X
if (CONFIG_SOC_RISCV_TELINK_B92 OR CONFIG_SOC_RISCV_TELINK_TL321X)
zephyr_library_sources(drivers/${SOC}/analog_user.c)
endif()

# MbedTLS HW acceleration
if(CONFIG_MBEDTLS)
add_subdirectory( crypto/mbedtls )
Expand Down
21 changes: 21 additions & 0 deletions tlsr9/ble/vendor/controller/b9x/b9x_bt_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
#include <zephyr/storage/flash_map.h>
#include <zephyr/drivers/flash.h>

#if CONFIG_SOC_RISCV_TELINK_B92
#define USER_PARA_MAC_OFFSET (0x100)
#define USER_PARTITION user_para_partition
#define USER_PARTITION_DEVICE FIXED_PARTITION_DEVICE(USER_PARTITION)
#define USER_PARTITION_OFFSET FIXED_PARTITION_OFFSET(USER_PARTITION)
#define USER_PARTITION_SIZE FIXED_PARTITION_SIZE(USER_PARTITION)
#endif

#if CONFIG_TL_BLE_CTRL_MAC_TYPE_PUBLIC || CONFIG_TL_BLE_CTRL_MAC_FLASH
static const struct device *flash_device =
DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
Expand Down Expand Up @@ -111,9 +119,22 @@ _attribute_no_inline_ int b9x_bt_blc_mac_init(uint8_t *bt_mac)
err = flash_write(flash_device, FIXED_PARTITION_OFFSET(vendor_partition)
+ B9X_BT_MAC_ADDR_OFFSET, temp_mac, BLE_ADDR_LEN + 3);
#else
#if CONFIG_SOC_RISCV_TELINK_B92
uint8_t dummy_mac[BLE_ADDR_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

/*Get the ramdom mac address from zb which will passed in the user-para sector */
err = flash_read(USER_PARTITION_DEVICE, USER_PARTITION_OFFSET
+ USER_PARA_MAC_OFFSET, bt_mac, BLE_ADDR_LEN);
if(memcmp(bt_mac, dummy_mac, sizeof(dummy_mac)) == 0){
// if mac address is empty, use random instead .
generateRandomNum(BLE_ADDR_LEN, bt_mac);
}
bt_mac[5] |= 0xC0; /* random static by default */
#else
generateRandomNum(BLE_ADDR_LEN, bt_mac);
/* The random static address will be generated on every reboot */
bt_mac[5] |= 0xC0; /* random static by default */
#endif
#endif
#else
#error "Other address types are not supported or need to be set via HCI"
Expand Down
19 changes: 19 additions & 0 deletions tlsr9/ble/vendor/controller/tlx/tlx_bt_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
#include <zephyr/storage/flash_map.h>
#include <zephyr/drivers/flash.h>

#define USER_PARA_MAC_OFFSET (0x100)
#define USER_PARTITION user_para_partition
#define USER_PARTITION_DEVICE FIXED_PARTITION_DEVICE(USER_PARTITION)
#define USER_PARTITION_OFFSET FIXED_PARTITION_OFFSET(USER_PARTITION)
#define USER_PARTITION_SIZE FIXED_PARTITION_SIZE(USER_PARTITION)

#if CONFIG_TL_BLE_CTRL_MAC_TYPE_PUBLIC || CONFIG_TL_BLE_CTRL_MAC_FLASH
static const struct device *flash_device =
DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
Expand Down Expand Up @@ -110,9 +116,22 @@ _attribute_no_inline_ int tlx_bt_blc_mac_init(uint8_t *bt_mac)
err = flash_write(flash_device, FIXED_PARTITION_OFFSET(vendor_partition)
+ TLX_BT_MAC_ADDR_OFFSET, temp_mac, BLE_ADDR_LEN + 3);
#else
#if CONFIG_SOC_RISCV_TELINK_TL321X
uint8_t dummy_mac[BLE_ADDR_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

/*Get the ramdom mac address from zb which will passed in the user-para sector */
err = flash_read(USER_PARTITION_DEVICE, USER_PARTITION_OFFSET
+ USER_PARA_MAC_OFFSET, bt_mac, BLE_ADDR_LEN);
if(memcmp(bt_mac, dummy_mac, sizeof(dummy_mac)) == 0){
// if mac address is empty, use random instead .
generateRandomNum(BLE_ADDR_LEN, bt_mac);
}
bt_mac[5] |= 0xC0; /* random static by default */
#else
generateRandomNum(BLE_ADDR_LEN, bt_mac);
/* The random static address will be generated on every reboot */
bt_mac[5] |= 0xC0; /* random static by default */
#endif
#endif
#else
#error "Other address types are not supported or need to be set via HCI"
Expand Down
56 changes: 56 additions & 0 deletions tlsr9/drivers/B92/analog_user.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/********************************************************************************************************
* @file analog_user.c
*
* @brief This is the source file for TLSR9528
*
* @author Driver Group
* @date 2024
*
* @par Copyright (c) 2024, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
*
* Licensed 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 "analog_user.h"
#include "analog.h"

/**
* @brief This function serves to analog register read by byte.
* @param[in] addr - address need to be read.
* @return the result of read.
*/
_attribute_ram_code_sec_optimize_o2_ unsigned char user_analog_read_reg8(unsigned char addr)
{
return analog_read_reg8(addr);
}

/**
* @brief This function serves to analog register write by byte.
* @param[in] addr - address need to be write.
* @param[in] data - the value need to be write.
* @return none.
*/
_attribute_ram_code_sec_optimize_o2_ int user_analog_write_reg8(unsigned char addr, unsigned char data)
{
if (addr == analog_reg_59 || addr == analog_reg_60)
{
analog_write_reg8(addr, data);
return 0;
}
return -1;
}


_attribute_data_retention_sec_ analog_read_f analog_read = user_analog_read_reg8;
_attribute_data_retention_sec_ analog_write_f analog_write = user_analog_write_reg8;
53 changes: 53 additions & 0 deletions tlsr9/drivers/B92/analog_user.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/********************************************************************************************************
* @file analog_user.h
*
* @brief This is the header file for TLSR9528
*
* @author Driver Group
* @date 2024
*
* @par Copyright (c) 2024, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
*
* Licensed 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.
*
*******************************************************************************************************/

#pragma once

#include "compiler.h"

#define analog_reg_59 (0x3b)
#define analog_reg_60 (0x3c)

/**
* @brief This function serves to analog register read by byte.
* @param[in] addr - address need to be read.
* @return the result of read.
*/
_attribute_ram_code_sec_optimize_o2_ unsigned char user_analog_read_reg8(unsigned char addr);


/**
* @brief This function serves to analog register write by byte.
* @param[in] addr - address need to be write.
* @param[in] data - the value need to be write.
* @return none.
*/
_attribute_ram_code_sec_optimize_o2_ int user_analog_write_reg8(unsigned char addr, unsigned char data);


typedef unsigned char (*analog_read_f)(unsigned char addr);
typedef int (*analog_write_f)(unsigned char addr, unsigned char data);

extern _attribute_data_retention_sec_ analog_read_f analog_read;
extern _attribute_data_retention_sec_ analog_write_f analog_write;
4 changes: 4 additions & 0 deletions tlsr9/drivers/B92/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ static inline unsigned char i2c_master_data_nack_detect(void)
unsigned char i2c_master_write(unsigned char id, unsigned char *data, unsigned int len)
{
i2c_clr_irq_status(I2C_TX_BUF_STATUS);
#if CONFIG_I2C_LED
reg_i2c_id = id; //BIT(0):R:High W:Low
#else
reg_i2c_id = id & (~FLD_I2C_WRITE_READ_BIT); //BIT(0):R:High W:Low
#endif
reg_i2c_sct1 = (FLD_I2C_LS_ID| FLD_I2C_LS_START);
while(i2c_master_busy());
if(i2c_master_id_nack_detect()){
Expand Down
23 changes: 23 additions & 0 deletions tlsr9/drivers/B92/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,26 @@ void pwm_set_tx_dma_add_list_element(dma_chn_e chn,dma_chain_config_t *config_ad
config_addr->dma_chain_llp_ptr=(unsigned int)convert_ram_addr_cpu2bus(llpoint);
}

/**
* @brief This function servers to start the pwm,can have more than one PWM open at the same time.
* @param[in] en - variable of enum to select the pwm.
* @return none.
*/
void pwm_start_t(pwm_en_e en)
{
pwm_start(en);
}

/**
* @brief This function servers to stop the pwm,can have more than one PWM stop at the same time.
* @param[in] en - variable of enum to select the pwm.
* @return none.
*/
void pwm_stop_t(pwm_en_e en)
{
pwm_stop(en);
}

pwm_set_pin_t pwm_set_pinctrl = pwm_set_pin;
pwm_set_start_t pwm_set_start = pwm_start_t;
pwm_set_stop_t pwm_set_stop = pwm_stop_t;
13 changes: 12 additions & 1 deletion tlsr9/drivers/B92/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ static inline void pwm_set_tmax(pwm_id_e id, unsigned short tmax){
* @return none.
*/
static inline void pwm_start(pwm_en_e en){

if(!(reg_pwm_enable & en))
{
reg_pwm_enable|=en;
}
}


Expand Down Expand Up @@ -475,6 +477,15 @@ static inline void pwm_32k_chn_dis(pwm_clk_32k_en_chn_e pwm_32K_en_chn)
{
BM_CLR(reg_pwm_mode32k, pwm_32K_en_chn);
}

typedef void (*pwm_set_pin_t)(gpio_func_pin_e pin, gpio_func_e func);
typedef void (*pwm_set_start_t)(pwm_en_e en);
typedef void (*pwm_set_stop_t)(pwm_en_e id);

extern pwm_set_pin_t pwm_set_pinctrl;
extern pwm_set_start_t pwm_set_start;
extern pwm_set_stop_t pwm_set_stop;

#endif


Expand Down
56 changes: 56 additions & 0 deletions tlsr9/drivers/TL321X/analog_user.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/********************************************************************************************************
* @file analog_user.c
*
* @brief This is the source file for TL321X
*
* @author Driver Group
* @date 2024
*
* @par Copyright (c) 2024, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
*
* Licensed 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 "analog_user.h"
#include "lib/include/analog.h"

/**
* @brief This function serves to analog register read by byte.
* @param[in] addr - address need to be read.
* @return the result of read.
*/
_attribute_ram_code_com_sec_noinline_ unsigned char user_analog_read_reg8(unsigned char addr)
{
return analog_read_reg8(addr);
}

/**
* @brief This function serves to analog register write by byte.
* @param[in] addr - address need to be write.
* @param[in] data - the value need to be write.
* @return none.
*/
_attribute_ram_code_com_sec_noinline_ int user_analog_write_reg8(unsigned char addr, unsigned char data)
{
if (addr == analog_reg_59 || addr == analog_reg_60)
{
analog_write_reg8(addr, data);
return 0;
}
return -1;
}


_attribute_data_retention_sec_ analog_read_f analog_read = user_analog_read_reg8;
_attribute_data_retention_sec_ analog_write_f analog_write = user_analog_write_reg8;
53 changes: 53 additions & 0 deletions tlsr9/drivers/TL321X/analog_user.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/********************************************************************************************************
* @file analog_user.h
*
* @brief This is the header file for TL321X
*
* @author Driver Group
* @date 2024
*
* @par Copyright (c) 2024, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
*
* Licensed 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.
*
*******************************************************************************************************/

#pragma once

#include "compiler.h"

#define analog_reg_59 (0x3b)
#define analog_reg_60 (0x3c)

/**
* @brief This function serves to analog register read by byte.
* @param[in] addr - address need to be read.
* @return the result of read.
*/
_attribute_ram_code_com_sec_noinline_ unsigned char user_analog_read_reg8(unsigned char addr);


/**
* @brief This function serves to analog register write by byte.
* @param[in] addr - address need to be write.
* @param[in] data - the value need to be write.
* @return none.
*/
_attribute_ram_code_com_sec_noinline_ int user_analog_write_reg8(unsigned char addr, unsigned char data);


typedef unsigned char (*analog_read_f)(unsigned char addr);
typedef int (*analog_write_f)(unsigned char addr, unsigned char data);

extern _attribute_data_retention_sec_ analog_read_f analog_read;
extern _attribute_data_retention_sec_ analog_write_f analog_write;
Loading