From 3002000f57484ecadfe4cdcec6a5ce093196e179 Mon Sep 17 00:00:00 2001 From: IFX-Anusha Date: Mon, 7 Oct 2024 13:46:54 +0530 Subject: [PATCH] ports/psoc6: Clock WIP. Signed-off-by: IFX-Anusha --- ports/psoc6/modmachine.c | 28 +++++++++++++++++++++++++++- ports/psoc6/mpconfigport.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ports/psoc6/modmachine.c b/ports/psoc6/modmachine.c index a5d7f33bacbf0..77adbffd80c9d 100644 --- a/ports/psoc6/modmachine.c +++ b/ports/psoc6/modmachine.c @@ -213,10 +213,36 @@ static mp_obj_t mp_machine_get_freq(void) { return MP_OBJ_NEW_SMALL_INT(system_get_cpu_freq()); } +void cm4_set_frequency() { + mp_printf(&mp_plat_print, "Here set the cm4 fz"); +} + +void audio_set_frequency() { + mp_printf(&mp_plat_print, "Here set the audio fz"); +} + +void peripheral_set_frequency() { + mp_printf(&mp_plat_print, "Here set the peripheral fz"); +} + + static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Not implemented!!!\n")); + mp_int_t freq = mp_obj_get_int(args[0]); + if (n_args == 1) { + cm4_set_frequency(freq); + } else if (n_args > 1) { + const char *freq_peri = mp_obj_str_get_str(args[1]); + if (strcmp(freq_peri, "Audio") == 0) { + audio_set_frequency(freq); // audio fz + } else if (strcmp(freq_peri, "Peripheral") == 0) { + peripheral_set_frequency(freq); // cm4 fz + } else { + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid frequency type %s"), freq_peri); + } + } } + // Sleep Modes Not working. Might be because of the REPL always running in background. Need to evaluate static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { // cy_rslt_t result; diff --git a/ports/psoc6/mpconfigport.h b/ports/psoc6/mpconfigport.h index c7b024ba7b103..4c20dd94a533a 100644 --- a/ports/psoc6/mpconfigport.h +++ b/ports/psoc6/mpconfigport.h @@ -109,6 +109,7 @@ #define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) #define MICROPY_PY_TIME_TIME_TIME_NS (1) #define MICROPY_PY_TIME_INCLUDEFILE "ports/psoc6/modtime.c" +#define MICROPY_PY_MACHINE_FREQ_NUM_ARGS_MAX (2) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_RESET (1)