Add WDT Device

This commit is contained in:
Rbb666 2022-07-22 10:22:21 +08:00 committed by guo
parent 4f0002525c
commit ac92106a7b
6 changed files with 168 additions and 8 deletions

View File

@ -26,17 +26,20 @@ if GetDepend(['RT_USING_I2C']):
if GetDepend('BSP_USING_HW_I2C3') or GetDepend('BSP_USING_HW_I2C6'):
src += ['drv_i2c.c']
if GetDepend(['RT_USING_PWM']):
if GetDepend(['BSP_USING_SDIO1']):
src += Glob('drv_sdio.c')
if GetDepend(['BSP_USING_PWM']):
src += ['drv_pwm.c']
if GetDepend(['RT_USING_SPI']):
if GetDepend(['BSP_USING_SPI']):
src += ['drv_spi.c']
if GetDepend(['RT_USING_ADC']):
if GetDepend(['BSP_USING_ADC']):
src += ['drv_adc.c']
if GetDepend(['RT_USING_QSPI']):
src += ['drv_qspi.c']
if GetDepend(['RT_USING_WDT']):
src += ['drv_wdt.c']
path = [cwd]
path += [cwd + '/config']

View File

@ -217,7 +217,7 @@ int rt_hw_spi_init(void)
LOG_D("%s bus init done", spi_bus_obj[i].bus_name);
LOG_D("MOSI PIN:[%d], MISO PIN[%d],CLK PIN[%d]\n",
LOG_D("MOSI PIN:[%d], MISO PIN[%d], CLK PIN[%d]\n",
spi_bus_obj[i].mosi_pin, spi_bus_obj[i].miso_pin,
spi_bus_obj[i].sck_pin);
}

View File

@ -0,0 +1,101 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-07-21 Rbb666 first version
*/
#include "drv_wdt.h"
#ifdef RT_USING_WDT
//#define DRV_DEBUG
#define LOG_TAG "drv.wdt"
#include <drv_log.h>
cyhal_wdt_t WDT;
static struct ifx_wdt_cfg wdt_cfg =
{
.name = "wdt",
.WDTx = &WDT,
};
static struct ifx_wdt wdt_drv;
static rt_err_t wdt_init(rt_watchdog_t *wdt)
{
return RT_EOK;
}
static rt_err_t wdt_control(rt_watchdog_t *wdt_device, int cmd, void *arg)
{
RT_ASSERT(wdt_device != RT_NULL);
struct ifx_wdt_cfg *cfg;
cfg = wdt_device->parent.user_data;
rt_uint32_t timeout_ms = 0;
switch (cmd)
{
/* feed the watchdog */
case RT_DEVICE_CTRL_WDT_KEEPALIVE:
cyhal_wdt_kick(cfg->WDTx);
break;
/* set watchdog timeout */
case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
{
timeout_ms = *((rt_uint32_t *)arg) * 1000;
rt_uint32_t max_timeout_ms = cyhal_wdt_get_max_timeout_ms();
if (timeout_ms >= max_timeout_ms)
timeout_ms = max_timeout_ms;
/* Initialize the WDT */
int result = cyhal_wdt_init(cfg->WDTx, (rt_uint32_t)timeout_ms);
/* WDT initialization failed. Stop program execution */
RT_ASSERT(result != RT_ERROR);
}
break;
case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
timeout_ms = cyhal_wdt_get_timeout_ms(cfg->WDTx);
*(rt_uint32_t *)arg = timeout_ms / 1000;
break;
case RT_DEVICE_CTRL_WDT_START:
cyhal_wdt_start(cfg->WDTx);
break;
case RT_DEVICE_CTRL_WDT_STOP:
cyhal_wdt_stop(cfg->WDTx);
break;
default:
LOG_W("This command is not supported.");
return -RT_ERROR;
}
return RT_EOK;
}
const static struct rt_watchdog_ops ifx_wdt_ops =
{
wdt_init,
wdt_control
};
int rt_hw_wdt_init(void)
{
wdt_drv.cfg = &wdt_cfg;
wdt_drv.wdt_device.ops = &ifx_wdt_ops;
if (rt_hw_watchdog_register(&wdt_drv.wdt_device, wdt_drv.cfg->name, RT_DEVICE_FLAG_RDWR, wdt_drv.cfg) != RT_EOK)
{
LOG_E("wdt device register failed.");
return -RT_ERROR;
}
LOG_D("wdt device register success.");
return RT_EOK;
}
INIT_BOARD_EXPORT(rt_hw_wdt_init);
#endif /* RT_USING_WDT */

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2006-2022, Synwit Technology Co.,Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-7-21 Rbb666 first version
*/
#ifndef __DRV_WDT_H__
#define __DRV_WDT_H__
#include <rtthread.h>
#include "board.h"
struct ifx_wdt_cfg
{
const char *name;
cyhal_wdt_t *WDTx;
};
struct ifx_wdt
{
struct ifx_wdt_cfg *cfg;
struct rt_watchdog_device wdt_device;
};
int rt_hw_wdt_init(void);
#endif /* __DRV_WDT_H__ */

View File

@ -19,7 +19,8 @@ src = Split('''
mtb-hal-cat1/source/cyhal_utils_psoc.c
mtb-hal-cat1/source/cyhal_utils.c
mtb-hal-cat1/source/cyhal_lptimer.c
mtb-hal-cat1/source/cyhal_irq_psoc.c
mtb-hal-cat1/source/cyhal_irq_psoc.c
mtb-hal-cat1/include_pvt/cyhal_hw_types.h
mtb-hal-cat1/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_02.c
mtb-hal-cat1/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_124_bga.c
mtb-pdl-cat1/devices/COMPONENT_CAT1A/source/cy_device.c
@ -67,6 +68,10 @@ if GetDepend(['RT_USING_ADC']):
src += ['mtb-pdl-cat1/drivers/source/cy_dmac.c']
src += ['mtb-pdl-cat1/drivers/source/cy_sysanalog.c']
if GetDepend(['RT_USING_SDIO']):
src += ['mtb-hal-cat1/source/cyhal_sdhc.c']
src += ['mtb-pdl-cat1/drivers/source/cy_sd_host.c']
if GetDepend(['RT_USING_QSPI']):
src += ['mtb-hal-cat1/source/cyhal_qspi.c']
src += ['mtb-pdl-cat1/drivers/source/cy_dma.c']
@ -87,10 +92,13 @@ if GetDepend(['RT_USING_SPI']):
src += ['mtb-hal-cat1/source/cyhal_spi.c']
src += ['mtb-pdl-cat1/drivers/source/cy_scb_spi.c']
if GetDepend(['RT_USING_I2C']):
src += ['mtb-hal-cat1/source/cyhal_i2c.c']
if GetDepend(['RT_USING_WDT']):
src += ['mtb-pdl-cat1/drivers/source/cy_wdt.c']
src += ['mtb-hal-cat1/source/cyhal_wdt.c']
path = [cwd + '/capsense',
cwd + '/psoc6cm0p',
cwd + '/retarget-io',

View File

@ -118,6 +118,18 @@ menu "On-chip Peripheral Drivers"
default n
endif
config BSP_USING_SDMMC
bool "Enable SDMMC (sd card)"
default n
select RT_USING_SDIO
select RT_USING_DFS
select RT_USING_DFS_ELMFAT
if BSP_USING_SDMMC
config BSP_USING_SDIO1
bool "Enable SDIO1 (sd card)"
default n
endif
config BSP_USING_QSPI_FLASH
bool "Enable QSPI BUS"
select RT_USING_QSPI
@ -183,6 +195,11 @@ menu "On-chip Peripheral Drivers"
default 106
endif
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"
select RT_USING_WDT
default n
endmenu
menu "Board extended module Drivers"