Skip to content

Commit

Permalink
ports/psoc6: Clock set check.
Browse files Browse the repository at this point in the history
Signed-off-by: IFX-Anusha <Anusha.TR@infineon.com>
  • Loading branch information
IFX-Anusha committed Oct 28, 2024
1 parent 2176e2c commit 7123b0f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
22 changes: 19 additions & 3 deletions ports/psoc6/machine_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,25 @@ static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *ar
mp_raise_ValueError(MP_ERROR_TEXT("invalid format"));
}

// uint32_t audio_clock_freq_hz;
uint32_t rate = args[ARG_rate].u_int;

if (rate == 8000 ||
rate == 16000 ||
rate == 32000 ||
rate == 48000) {
if (freq_peri != AUDIO_I2S_98_MHZ) {
mp_raise_ValueError(MP_ERROR_TEXT("Invalid clock frequency set for the sample rate/ I2S Clock not set . Set the right clock before initialising I2S"));
}
} else if (rate == 22050 ||
rate == 44100) {
if (freq_peri != AUDIO_I2S_90_MHZ) {
mp_raise_ValueError(MP_ERROR_TEXT("Invalid clock frequency set for the sample rate/ I2S Clock not set. Set the right clock before initialising I2S"));
}
} else {
mp_raise_ValueError(MP_ERROR_TEXT("rate not supported"));
}

// is valid buf size ?
int32_t ring_buffer_len = args[ARG_ibuf].u_int;
if (ring_buffer_len < 0) {
Expand All @@ -343,9 +362,6 @@ static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *ar
self->ring_buffer_storage = m_new(uint8_t, ring_buffer_len);

ringbuf_init(&self->ring_buffer, self->ring_buffer_storage, ring_buffer_len);
if (!clock_set_i2s) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("I2S clock not set. Set the clock before initialising I2S"));
}
i2s_init(self, &audio_clock);
i2s_dma_init(self);
}
Expand Down
15 changes: 2 additions & 13 deletions ports/psoc6/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,8 @@ enum {
MACHINE_SOFT_RESET
};

// enums to hold the frequency constants
enum clock_freq_type {
AUDIO_I2S_98_MHZ = 98000000,
AUDIO_I2S_90_MHZ = 90000000,
AUDIO_PDM_24_576_000_HZ = 24576000,
AUDIO_PDM_22_579_000_HZ = 22579000,
CM4,
CM4_FLL
};

uint32_t reset_cause;
bool clock_set_i2s = false;
bool clock_set_pdm = false;
enum clock_freq_type freq_peri;

// function to return 64-bit silicon ID of given PSoC microcontroller
// A combined 64-bit unique ID. [63:57] - DIE_YEAR [56:56] - DIE_MINOR [55:48] - DIE_SORT [47:40] - DIE_Y [39:32] - DIE_X [31:24] - DIE_WAFER [23:16] - DIE_LOT[2] [15: 8] - DIE_LOT[1] [ 7: 0] - DIE_LOT[0]
Expand Down Expand Up @@ -523,7 +512,7 @@ void audio_pdm_set_frequency(uint32_t freq) {


static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
enum clock_freq_type freq_peri = mp_obj_get_int(args[0]); // Assuming the enum values are used as integers
freq_peri = mp_obj_get_int(args[0]); // Assuming the enum values are used as integers
switch (freq_peri) {
case AUDIO_I2S_90_MHZ:
audio_i2s_set_frequency(freq_peri); // i2s audio fz
Expand Down
12 changes: 12 additions & 0 deletions ports/psoc6/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ extern cyhal_clock_t audio_clock;
extern bool clock_set_i2s;
extern bool clock_set_pdm;

// enums to hold the frequency constants
enum clock_freq_type {
AUDIO_I2S_98_MHZ = 98000000,
AUDIO_I2S_90_MHZ = 90000000,
AUDIO_PDM_24_576_000_HZ = 24576000,
AUDIO_PDM_22_579_000_HZ = 22579000,
CM4,
CM4_FLL
};

extern enum clock_freq_type freq_peri;

#endif // MICROPY_INCLUDED_PSOC6_MODMACHINE_H

0 comments on commit 7123b0f

Please sign in to comment.