Skip to content

Commit c97f742

Browse files
committed
PSOC6: minor updates to Cypress HAL
1 parent edb944a commit c97f742

File tree

8 files changed

+61
-70
lines changed

8 files changed

+61
-70
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/analogin_api.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const uint32_t SAR_BASE_CLOCK_HZ = 18000000; // 18 MHz or less
4444
CY_SAR_CHAN_SAMPLE_TIME_0 \
4545
)
4646

47-
#define CY_SAR_PORT_9 (9uL)
47+
#define CY_SAR_PORT_9 (9uL)
4848

4949
/** Global SAR configuration data, modified as channels are configured.
5050
*/
@@ -173,11 +173,10 @@ uint16_t analogin_read_u16(analogin_t *obj)
173173
if (CY_SAR_PORT_9 != port) {
174174
/* Connect the SAR Vplus input to the pin directly */
175175
Cy_SAR_SetAnalogSwitch(obj->base, CY_SAR_MUX_SWITCH0, obj->channel_mask, CY_SAR_SWITCH_CLOSE);
176-
}
177-
else {
176+
} else {
178177
/* Connect the SAR Vplus input to the AMUXA bus */
179178
Cy_SAR_SetAnalogSwitch(obj->base, CY_SAR_MUX_SWITCH0, SAR_MUX_SWITCH0_MUX_FW_AMUXBUSA_VPLUS_Msk, CY_SAR_SWITCH_CLOSE);
180-
179+
181180
/* Connect the AMUXA bus to the pin */
182181
Cy_GPIO_SetHSIOM(portPrt, CY_PIN(obj->pin), HSIOM_SEL_AMUXA);
183182
}
@@ -188,15 +187,14 @@ uint16_t analogin_read_u16(analogin_t *obj)
188187
} else {
189188
error("ANALOG IN: measurement failed!");
190189
}
191-
190+
192191
if (CY_SAR_PORT_9 != port) {
193192
/* Disconnect the SAR Vplus input from the pin */
194193
Cy_SAR_SetAnalogSwitch(obj->base, CY_SAR_MUX_SWITCH0, obj->channel_mask, CY_SAR_SWITCH_OPEN);
195-
}
196-
else {
194+
} else {
197195
/* Disconnect the AMUXA bus from the pin */
198196
Cy_GPIO_SetHSIOM(portPrt, CY_PIN(obj->pin), HSIOM_SEL_GPIO);
199-
197+
200198
/* Disconnect the SAR Vplus input from the AMUXA bus */
201199
Cy_SAR_SetAnalogSwitch(obj->base, CY_SAR_MUX_SWITCH0, SAR_MUX_SWITCH0_MUX_FW_AMUXBUSA_VPLUS_Msk, CY_SAR_SWITCH_OPEN);
202200
}

targets/TARGET_Cypress/TARGET_PSOC6/crc_api.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,47 @@
2626

2727
#include "cy_crypto_core_crc.h"
2828

29-
static uint32_t crcWidth = 0;
30-
static uint32_t crcShift = 0;
29+
static uint32_t crcWidth = 0UL;
30+
static uint32_t crcShift = 0UL;
3131
static uint32_t crcXorMask;
3232

33-
/* Cypress CRYPTO HW supports ANY CRC algorithms from CRC-3 to CRC-32 */
33+
/* Cypress CRYPTO hardware supports any CRC algorithms from CRC-3 to CRC-32 */
3434
bool hal_crc_is_supported(const crc_mbed_config_t *config)
3535
{
3636
return (config != NULL);
3737
}
3838

3939
void hal_crc_compute_partial_start(const crc_mbed_config_t *config)
4040
{
41-
uint32_t myMask = 0;
41+
uint32_t myMask = 0UL;
4242

43-
if (!hal_crc_is_supported(config) || (cy_reserve_crypto(CY_CRYPTO_CRC_HW) != 0))
44-
{
43+
if (!hal_crc_is_supported(config) || (cy_reserve_crypto(CY_CRYPTO_CRC_HW) != 0U)) {
4544
return;
4645
}
4746

4847
crcWidth = config->width;
4948

50-
crcShift = (uint32_t)(!config->reflect_out) * (crcWidth & 7u);
51-
if (crcShift) {
52-
crcShift = 8u - crcShift;
53-
for (uint32_t i = 0; i < crcShift; i++) {
54-
myMask |= 1 << i;
49+
crcShift = (uint32_t)(!config->reflect_out) * (crcWidth & 7U);
50+
if (0U != crcShift) {
51+
crcShift = 8U - crcShift;
52+
for (uint32_t i = 0U; i < crcShift; i++) {
53+
myMask |= 1U << i;
5554
}
5655
crcXorMask = config->final_xor & myMask;
5756
}
5857

5958
Cy_Crypto_Core_Crc_CalcInit(CRYPTO, config->width,
6059
config->polynomial,
6160
config->reflect_in,
62-
0,
61+
0U,
6362
config->reflect_out,
6463
config->final_xor >> crcShift,
6564
config->initial_xor);
6665
}
6766

6867
void hal_crc_compute_partial(const uint8_t *data, const size_t size)
6968
{
70-
if ((data == NULL) || (size <= 0) || (crcWidth == 0)) {
69+
if ((data == NULL) || (size <= 0U) || (crcWidth == 0U)) {
7170
return;
7271
}
7372

@@ -76,10 +75,10 @@ void hal_crc_compute_partial(const uint8_t *data, const size_t size)
7675

7776
uint32_t hal_crc_get_result(void)
7877
{
79-
uint32_t result = 0;
78+
uint32_t result = 0UL;
8079

81-
if (crcWidth == 0) {
82-
return 0xffffffffu;
80+
if (crcWidth == 0UL) {
81+
return 0xFFFFFFFFUL;
8382
}
8483

8584
Cy_Crypto_Core_Crc_CalcFinish(CRYPTO, crcWidth, &result);
@@ -89,7 +88,7 @@ uint32_t hal_crc_get_result(void)
8988
result = result ^ crcXorMask;
9089
}
9190

92-
crcWidth = 0;
91+
crcWidth = 0UL;
9392

9493
cy_free_crypto(CY_CRYPTO_CRC_HW);
9594

targets/TARGET_Cypress/TARGET_PSOC6/psoc6_utils.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -360,36 +360,30 @@ static uint8_t crypto_reservations[NUM_CRYPTO_HW] = { 0u };
360360
static int cy_crypto_reserved_status(void)
361361
{
362362
return ((int)(crypto_reservations[CY_CRYPTO_TRNG_HW] |
363-
crypto_reservations[CY_CRYPTO_CRC_HW] |
364-
crypto_reservations[CY_CRYPTO_VU_HW] |
365-
crypto_reservations[CY_CRYPTO_COMMON_HW]));
363+
crypto_reservations[CY_CRYPTO_CRC_HW] |
364+
crypto_reservations[CY_CRYPTO_VU_HW] |
365+
crypto_reservations[CY_CRYPTO_COMMON_HW]));
366366
}
367367

368368

369369
int cy_reserve_crypto(cy_en_crypto_submodule_t module_num)
370370
{
371371
int result = (-1);
372372

373-
if (module_num < NUM_CRYPTO_HW)
374-
{
373+
if (module_num < NUM_CRYPTO_HW) {
375374
core_util_critical_section_enter();
376375

377-
if (cy_crypto_reserved_status() == 0)
378-
{
376+
if (cy_crypto_reserved_status() == 0) {
379377
/* Enable Crypto IP on demand */
380378
Cy_Crypto_Core_Enable(CRYPTO);
381379
}
382380

383-
if (module_num == CY_CRYPTO_COMMON_HW)
384-
{
385-
if (crypto_reservations[module_num] != 1)
386-
{
381+
if (module_num == CY_CRYPTO_COMMON_HW) {
382+
if (crypto_reservations[module_num] != 1) {
387383
crypto_reservations[module_num] = 1;
388384
result = 0;
389385
}
390-
}
391-
else
392-
{
386+
} else {
393387
crypto_reservations[module_num] = 1;
394388
result = 0;
395389
}
@@ -405,16 +399,13 @@ void cy_free_crypto(cy_en_crypto_submodule_t module_num)
405399
{
406400
int result = (-1);
407401

408-
if (module_num < NUM_CRYPTO_HW)
409-
{
402+
if (module_num < NUM_CRYPTO_HW) {
410403
core_util_critical_section_enter();
411404

412-
if (crypto_reservations[module_num] == 1)
413-
{
405+
if (crypto_reservations[module_num] == 1) {
414406
crypto_reservations[module_num] = 0;
415407

416-
if (cy_crypto_reserved_status() == 0)
417-
{
408+
if (cy_crypto_reserved_status() == 0) {
418409
/* Crypto hardware is still in enabled state; to disable:
419410
Cy_Crypto_Core_Disable(CRYPTO) */
420411
}

targets/TARGET_Cypress/TARGET_PSOC6/psoc6_utils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ static inline uint32_t gpio_get_cy_drive_mode(PinDirection dir, PinMode mode)
215215
return cymode;
216216
}
217217

218-
typedef enum
219-
{
218+
typedef enum {
220219
CY_CRYPTO_TRNG_HW,
221220
CY_CRYPTO_CRC_HW,
222221
CY_CRYPTO_VU_HW,

targets/TARGET_Cypress/TARGET_PSOC6/pwmout_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void pwm_start_32b(pwmout_t *obj, uint32_t new_period, uint32_t new_width
7373
Cy_TCPWM_PWM_SetPeriod0(obj->base, obj->counter_id, obj->period - 1);
7474
Cy_TCPWM_PWM_SetCompare0(obj->base, obj->counter_id, obj->pulse_width);
7575
Cy_TCPWM_PWM_Enable(obj->base, obj->counter_id);
76-
Cy_TCPWM_TriggerStart(obj->base, 1UL << obj->counter_id);
76+
Cy_TCPWM_TriggerReloadOrIndex(obj->base, 1UL << obj->counter_id);
7777
}
7878

7979
static void pwm_start_16b(pwmout_t *obj, uint32_t period, uint32_t width)
@@ -101,7 +101,7 @@ static void pwm_start_16b(pwmout_t *obj, uint32_t period, uint32_t width)
101101
Cy_TCPWM_PWM_SetPrescaler(obj->base, obj->counter_id, prescaler);
102102
Cy_TCPWM_PWM_SetCompare0(obj->base, obj->counter_id, width);
103103
Cy_TCPWM_PWM_Enable(obj->base, obj->counter_id);
104-
Cy_TCPWM_TriggerStart(obj->base, 1UL << obj->counter_id);
104+
Cy_TCPWM_TriggerReloadOrIndex(obj->base, 1UL << obj->counter_id);
105105
}
106106

107107
static void pwm_start(pwmout_t *obj, uint32_t new_period, uint32_t new_pulse_width)

targets/TARGET_Cypress/TARGET_PSOC6/serial_api.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,16 @@ static void serial_init_peripheral(serial_obj_t *obj)
383383
}
384384

385385

386+
/*
387+
* Callback function to handle into and out of deep sleep state transitions.
388+
*/
386389
#if DEVICE_SLEEP && DEVICE_LPTICKER && SERIAL_PM_CALLBACK_ENABLED
387-
static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *params)
390+
static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode)
388391
{
389-
serial_obj_t *obj = (serial_obj_t *)params->context;
392+
serial_obj_t *obj = (serial_obj_t *) callbackParams->context;
390393
cy_en_syspm_status_t status = CY_SYSPM_FAIL;
391394

392-
switch (params->mode) {
395+
switch (mode) {
393396
case CY_SYSPM_CHECK_READY:
394397
/* If all data elements are transmitted from the TX FIFO and
395398
* shifter and the RX FIFO is empty: the UART is ready to enter
@@ -432,7 +435,7 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *p
432435

433436
return status;
434437
}
435-
#endif /* (DEVICE_SLEEP && DEVICE_LPTICKER && SERIAL_PM_CALLBACK_ENABLED) */
438+
#endif /* DEVICE_SLEEP && DEVICE_LPTICKER && SERIAL_PM_CALLBACK_ENABLED */
436439

437440

438441
void serial_init(serial_t *obj_in, PinName tx, PinName rx)
@@ -492,16 +495,16 @@ void serial_init(serial_t *obj_in, PinName tx, PinName rx)
492495
#if DEVICE_SLEEP && DEVICE_LPTICKER && SERIAL_PM_CALLBACK_ENABLED
493496
/* Register callback once */
494497
obj->pm_callback_handler.callback = serial_pm_callback;
495-
obj->pm_callback_handler.type = CY_SYSPM_DEEPSLEEP;
498+
obj->pm_callback_handler.type = CY_SYSPM_DEEPSLEEP;
496499
obj->pm_callback_handler.skipMode = 0;
497500
obj->pm_callback_handler.callbackParams = &obj->pm_callback_params;
498-
obj->pm_callback_params.base = obj->base;
501+
obj->pm_callback_params.base = obj->base;
499502
obj->pm_callback_params.context = obj;
500503

501504
if (!Cy_SysPm_RegisterCallback(&obj->pm_callback_handler)) {
502505
error("PM callback registration failed!");
503506
}
504-
#endif /* (DEVICE_SLEEP && DEVICE_LPTICKER && SERIAL_PM_CALLBACK_ENABLED) */
507+
#endif /* DEVICE_SLEEP && DEVICE_LPTICKER && SERIAL_PM_CALLBACK_ENABLED */
505508
}
506509

507510
/* Configure hardware resources */
@@ -666,9 +669,10 @@ void serial_set_flow_control(serial_t *obj_in, FlowControl type, PinName rxflow,
666669
{
667670
serial_obj_t *obj = OBJ_P(obj_in);
668671

669-
/* Do not perform pins reservation second time for the same pins */
670-
if ((obj->pin_rts == rxflow) && (obj->pin_cts == txflow))
672+
/* Do not perform pins reservation second time for the same pins */
673+
if ((obj->pin_rts == rxflow) && (obj->pin_cts == txflow)) {
671674
return;
675+
}
672676

673677
Cy_SCB_UART_Disable(obj->base, NULL);
674678

targets/TARGET_Cypress/TARGET_PSOC6/spi_api.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,16 @@ static void spi_init_peripheral(spi_obj_t *obj)
237237
/* Callback function to handle into and out of deep sleep state transitions.
238238
*
239239
*/
240-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
241-
static cy_en_syspm_status_t spi_pm_callback(cy_stc_syspm_callback_params_t *callback_params)
240+
#if DEVICE_SLEEP && DEVICE_LPTICKER
241+
static cy_en_syspm_status_t spi_pm_callback(cy_stc_syspm_callback_params_t *callback_params, cy_en_syspm_callback_mode_t mode)
242242
{
243243
cy_stc_syspm_callback_params_t params = *callback_params;
244244
spi_obj_t *obj = (spi_obj_t *)params.context;
245245
params.context = &obj->context;
246246

247-
return Cy_SCB_SPI_DeepSleepCallback(&params);
247+
return Cy_SCB_SPI_DeepSleepCallback(&params, mode);
248248
}
249-
#endif /* DEVICE_SLEEP && DEVICE_LOWPOWERTIMER */
249+
#endif /* DEVICE_SLEEP && DEVICE_LPTICKER */
250250

251251

252252
void spi_init(spi_t *obj_in, PinName mosi, PinName miso, PinName sclk, PinName ssel)
@@ -314,7 +314,7 @@ void spi_init(spi_t *obj_in, PinName mosi, PinName miso, PinName sclk, PinName s
314314
obj->div_num = _FLD2VAL(CY_PERI_CLOCK_CTL_DIV_SEL, map);
315315
obj->div_type = (cy_en_divider_types_t) _FLD2VAL(CY_PERI_CLOCK_CTL_TYPE_SEL, map);
316316
} else {
317-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
317+
#if DEVICE_SLEEP && DEVICE_LPTICKER
318318
/* Register callback once */
319319
obj->pm_callback_handler.callback = spi_pm_callback;
320320
obj->pm_callback_handler.type = CY_SYSPM_DEEPSLEEP;
@@ -326,7 +326,7 @@ void spi_init(spi_t *obj_in, PinName mosi, PinName miso, PinName sclk, PinName s
326326
if (!Cy_SysPm_RegisterCallback(&obj->pm_callback_handler)) {
327327
error("PM callback registration failed!");
328328
}
329-
#endif /* DEVICE_SLEEP && DEVICE_LOWPOWERTIMER */
329+
#endif /* DEVICE_SLEEP && DEVICE_LPTICKER */
330330
}
331331

332332
/* Configure hardware resources */

targets/TARGET_Cypress/TARGET_PSOC6/trng_api.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include "cy_crypto_core_trng.h"
2525

2626
/* Initialization polynomial values fro True Random Generator */
27-
#define GARO31_INITSTATE (0x04c11db7u)
28-
#define FIRO31_INITSTATE (0x04c11db7u)
27+
#define GARO31_INITSTATE (0x04c11db7UL)
28+
#define FIRO31_INITSTATE (0x04c11db7UL)
2929

3030
#define MAX_TRNG_BIT_SIZE (32UL)
3131

@@ -47,7 +47,7 @@ void trng_free(trng_t *obj)
4747
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
4848
{
4949
int ret = 0;
50-
*output_length = 0;
50+
*output_length = 0U;
5151

5252
/* temporary random data buffer */
5353
uint32_t random;
@@ -59,13 +59,13 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l
5959
if (Cy_Crypto_Core_Trng(CRYPTO, GARO31_INITSTATE, FIRO31_INITSTATE, MAX_TRNG_BIT_SIZE, &random) != CY_CRYPTO_SUCCESS) {
6060
ret = -1;
6161
} else {
62-
for (uint8_t i = 0; (i < 4) && (*output_length < length) ; i++) {
62+
for (uint8_t i = 0; (i < 4U) && (*output_length < length) ; i++) {
6363
*output++ = ((uint8_t *)&random)[i];
64-
*output_length += 1;
64+
*output_length += 1U;
6565
}
6666
}
6767
}
68-
random = 0uL;
68+
random = 0UL;
6969

7070
return (ret);
7171
}

0 commit comments

Comments
 (0)