Skip to content
Permalink
bcafcf8fc3
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
86 lines (70 sloc) 2.62 KB
/*
* 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_obj = {{&machine_wdt_type}};
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_obj;
}
static void mp_machine_wdt_feed(machine_wdt_obj_t *self) {
cyhal_wdt_kick(&psoc6_wdt);
}
void mod_wdt_deinit() {
cyhal_wdt_stop(&psoc6_wdt);
cyhal_wdt_free(&psoc6_wdt);
}