Skip to content

Commit

Permalink
ports/psoc6: Implementation of machine WDT APIs.
Browse files Browse the repository at this point in the history
Signed-off-by: Ramya Subramanyam <ramya.subramanyam@infineon.com>
  • Loading branch information
ramya-subramanyam committed Apr 22, 2024
1 parent 7efa045 commit d7b1997
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions ports/psoc6/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ MOD_SRC_C += \
machine_pin_phy.c \
machine_pin.c \
machine_rtc.c \
machine_wdt.c \
machine_spi.c \
machine_timer.c \
machine_adc.c \
Expand Down
93 changes: 93 additions & 0 deletions ports/psoc6/machine_wdt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 "Krzysztof Adamski" <k@japko.eu>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

// std includes
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>


// micropython includes
#include "py/nlr.h"
#include "py/obj.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "py/mperrno.h"
#include "shared/timeutils/timeutils.h"
#include "py/misc.h"


// MTB includes
#include "cyhal.h"


// port-specific includes
#include "modmachine.h"

cyhal_wdt_t psoc6_wdt;


typedef struct _machine_wdt_obj_t {
mp_obj_base_t base;
} machine_wdt_obj_t;


// singleton WDT object
static const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}};

/* This function is run from main.c to init the WDT at boot time. This will set the timeout of the WDT to 2ms */
void wdt_init(void) {
uint32_t timeout_ms = 2000;
cy_rslt_t result = cyhal_wdt_init(&psoc6_wdt, timeout_ms);

if (CY_RSLT_SUCCESS != result) {
mp_raise_ValueError(MP_ERROR_TEXT("cyhal_wdt_init failed !"));
}
}

static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) {
if (id != 0) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("WDT(%d) doesn't exist"), id);
}

if (timeout_ms <= 0) {
mp_raise_ValueError(MP_ERROR_TEXT("WDT timeout too low"));
} else if (timeout_ms > cyhal_wdt_get_max_timeout_ms()) {
mp_raise_ValueError(MP_ERROR_TEXT("WDT timeout too high"));
}

cy_rslt_t result = cyhal_wdt_init(&psoc6_wdt, timeout_ms);
if (CY_RSLT_SUCCESS != result) {
mp_raise_ValueError(MP_ERROR_TEXT("cyhal_wdt_init failed !"));
}

return (machine_wdt_obj_t *)&machine_wdt;
}

static void mp_machine_wdt_feed(machine_wdt_obj_t *self) {
cyhal_wdt_kick(&self);
}

0 comments on commit d7b1997

Please sign in to comment.