hal: astyle update

pull/7008/head
Martin Kojtal 2018-06-20 11:24:18 +01:00
parent d10e821272
commit 483427a285
20 changed files with 144 additions and 123 deletions

View File

@ -97,7 +97,7 @@ static int32_t flash_algo_uninit(flash_t *obj, uint32_t address, uint32_t functi
* @param end_addr End address to check. Could be the same as start_addr to just check start_addr * @param end_addr End address to check. Could be the same as start_addr to just check start_addr
* for e.g. flash_erase_sector. * for e.g. flash_erase_sector.
* @return 0 for success, -1 for error * @return 0 for success, -1 for error
*/ */
static int32_t flash_check_nonsecure(flash_t *obj, uint32_t start_addr, uint32_t end_addr) static int32_t flash_check_nonsecure(flash_t *obj, uint32_t start_addr, uint32_t end_addr)
{ {
/* Check if end address wraps around */ /* Check if end address wraps around */
@ -107,14 +107,14 @@ static int32_t flash_check_nonsecure(flash_t *obj, uint32_t start_addr, uint32_t
/* Check if start address is in non-secure flash */ /* Check if start address is in non-secure flash */
if ((start_addr < obj->target_config_ns->flash_start) || if ((start_addr < obj->target_config_ns->flash_start) ||
(start_addr >= (obj->target_config_ns->flash_start + obj->target_config_ns->flash_size))) { (start_addr >= (obj->target_config_ns->flash_start + obj->target_config_ns->flash_size))) {
return -1; return -1;
} }
/* Check if end address is in non-secure flash */ /* Check if end address is in non-secure flash */
if (end_addr != start_addr) { if (end_addr != start_addr) {
if ((end_addr < obj->target_config_ns->flash_start) || if ((end_addr < obj->target_config_ns->flash_start) ||
(end_addr >= (obj->target_config_ns->flash_start + obj->target_config_ns->flash_size))) { (end_addr >= (obj->target_config_ns->flash_start + obj->target_config_ns->flash_size))) {
return -1; return -1;
} }
} }

View File

@ -74,7 +74,7 @@ typedef struct {
uint32_t pc; uint32_t pc;
} args_t; } args_t;
typedef int32_t (*flash_algo_jump_t)(args_t*); typedef int32_t (*flash_algo_jump_t)(args_t *);
// prototypes for flash algo CMSIS API // prototypes for flash algo CMSIS API

View File

@ -57,23 +57,23 @@ typedef void (*can_irq_handler)(uint32_t id, CanIrqType type);
typedef struct can_s can_t; typedef struct can_s can_t;
void can_init (can_t *obj, PinName rd, PinName td); void can_init(can_t *obj, PinName rd, PinName td);
void can_init_freq (can_t *obj, PinName rd, PinName td, int hz); void can_init_freq(can_t *obj, PinName rd, PinName td, int hz);
void can_free (can_t *obj); void can_free(can_t *obj);
int can_frequency (can_t *obj, int hz); int can_frequency(can_t *obj, int hz);
void can_irq_init (can_t *obj, can_irq_handler handler, uint32_t id); void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id);
void can_irq_free (can_t *obj); void can_irq_free(can_t *obj);
void can_irq_set (can_t *obj, CanIrqType irq, uint32_t enable); void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable);
int can_write (can_t *obj, CAN_Message, int cc); int can_write(can_t *obj, CAN_Message, int cc);
int can_read (can_t *obj, CAN_Message *msg, int handle); int can_read(can_t *obj, CAN_Message *msg, int handle);
int can_mode (can_t *obj, CanMode mode); int can_mode(can_t *obj, CanMode mode);
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle); int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle);
void can_reset (can_t *obj); void can_reset(can_t *obj);
unsigned char can_rderror (can_t *obj); unsigned char can_rderror(can_t *obj);
unsigned char can_tderror (can_t *obj); unsigned char can_tderror(can_t *obj);
void can_monitor (can_t *obj, int silent); void can_monitor(can_t *obj, int silent);
#ifdef __cplusplus #ifdef __cplusplus
}; };

View File

@ -145,7 +145,7 @@ extern "C" {
* *
* \return True if running if the polynomial is supported, false if not. * \return True if running if the polynomial is supported, false if not.
*/ */
bool hal_crc_is_supported(const crc_mbed_config_t* config); bool hal_crc_is_supported(const crc_mbed_config_t *config);
/** Initialize the hardware CRC module with the given polynomial /** Initialize the hardware CRC module with the given polynomial
* *
@ -177,7 +177,7 @@ bool hal_crc_is_supported(const crc_mbed_config_t* config);
* hardware CRC module. For example, polynomial and initial seed * hardware CRC module. For example, polynomial and initial seed
* values. * values.
*/ */
void hal_crc_compute_partial_start(const crc_mbed_config_t* config); void hal_crc_compute_partial_start(const crc_mbed_config_t *config);
/** Writes data to the current CRC module. /** Writes data to the current CRC module.
* *

View File

@ -86,7 +86,7 @@ int gpio_read(gpio_t *obj);
* @param gpio The GPIO object * @param gpio The GPIO object
* @param pin The pin name * @param pin The pin name
*/ */
void gpio_init_in(gpio_t* gpio, PinName pin); void gpio_init_in(gpio_t *gpio, PinName pin);
/** Init the input pin and set the mode /** Init the input pin and set the mode
* *
@ -94,7 +94,7 @@ void gpio_init_in(gpio_t* gpio, PinName pin);
* @param pin The pin name * @param pin The pin name
* @param mode The pin mode to be set * @param mode The pin mode to be set
*/ */
void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode); void gpio_init_in_ex(gpio_t *gpio, PinName pin, PinMode mode);
/** Init the output pin as an output, with predefined output value 0 /** Init the output pin as an output, with predefined output value 0
* *
@ -102,7 +102,7 @@ void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode);
* @param pin The pin name * @param pin The pin name
* @return An integer value 1 or 0 * @return An integer value 1 or 0
*/ */
void gpio_init_out(gpio_t* gpio, PinName pin); void gpio_init_out(gpio_t *gpio, PinName pin);
/** Init the pin as an output and set the output value /** Init the pin as an output and set the output value
* *
@ -110,7 +110,7 @@ void gpio_init_out(gpio_t* gpio, PinName pin);
* @param pin The pin name * @param pin The pin name
* @param value The value to be set * @param value The value to be set
*/ */
void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value); void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value);
/** Init the pin to be in/out /** Init the pin to be in/out
* *
@ -120,7 +120,7 @@ void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value);
* @param mode The pin mode to be set * @param mode The pin mode to be set
* @param value The value to be set for an output pin * @param value The value to be set for an output pin
*/ */
void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value); void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value);
/**@}*/ /**@}*/

View File

@ -58,8 +58,8 @@ typedef struct i2c_s i2c_t;
#endif #endif
enum { enum {
I2C_ERROR_NO_SLAVE = -1, I2C_ERROR_NO_SLAVE = -1,
I2C_ERROR_BUS_BUSY = -2 I2C_ERROR_BUS_BUSY = -2
}; };
#ifdef __cplusplus #ifdef __cplusplus
@ -73,7 +73,7 @@ extern "C" {
/** Initialize the I2C peripheral. It sets the default parameters for I2C /** Initialize the I2C peripheral. It sets the default parameters for I2C
* peripheral, and configures its specifieds pins. * peripheral, and configures its specifieds pins.
* *
* @param obj The I2C object * @param obj The I2C object
* @param sda The sda pin * @param sda The sda pin
* @param scl The scl pin * @param scl The scl pin
@ -117,7 +117,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop);
* @param data The buffer for sending * @param data The buffer for sending
* @param length Number of bytes to write * @param length Number of bytes to write
* @param stop Stop to be generated after the transfer is done * @param stop Stop to be generated after the transfer is done
* @return * @return
* zero or non-zero - Number of written bytes * zero or non-zero - Number of written bytes
* negative - I2C_ERROR_XXX status * negative - I2C_ERROR_XXX status
*/ */

View File

@ -38,15 +38,15 @@ enum {
/** /**
* @brief Target specific initialization function. * @brief Target specific initialization function.
* This function is responsible for initializing and configuring * This function is responsible for initializing and configuring
* the debug clock for the ITM and setting up the SWO pin for * the debug clock for the ITM and setting up the SWO pin for
* debug output. * debug output.
* *
* The only Cortex-M register that should be modified is the clock * The only Cortex-M register that should be modified is the clock
* prescaler in TPI->ACPR. * prescaler in TPI->ACPR.
* *
* The generic mbed_itm_init initialization function will setup: * The generic mbed_itm_init initialization function will setup:
* *
* ITM->LAR * ITM->LAR
* ITM->TPR * ITM->TPR
* ITM->TCR * ITM->TCR
@ -54,7 +54,7 @@ enum {
* TPI->SPPR * TPI->SPPR
* TPI->FFCR * TPI->FFCR
* DWT->CTRL * DWT->CTRL
* *
* for SWO output on stimulus port 0. * for SWO output on stimulus port 0.
*/ */
void itm_init(void); void itm_init(void);

View File

@ -79,7 +79,7 @@ ticker_irq_handler_type set_lp_ticker_irq_handler(ticker_irq_handler_type ticker
* *
* @return The low power ticker data * @return The low power ticker data
*/ */
const ticker_data_t* get_lp_ticker_data(void); const ticker_data_t *get_lp_ticker_data(void);
/** The wrapper for ticker_irq_handler, to pass lp ticker's data /** The wrapper for ticker_irq_handler, to pass lp ticker's data
* *
@ -207,7 +207,7 @@ void lp_ticker_disable_interrupt(void);
void lp_ticker_clear_interrupt(void); void lp_ticker_clear_interrupt(void);
/** Set pending interrupt that should be fired right away. /** Set pending interrupt that should be fired right away.
* *
* Pseudo Code: * Pseudo Code:
* @code * @code
* void lp_ticker_fire_interrupt(void) * void lp_ticker_fire_interrupt(void)
@ -232,7 +232,7 @@ void lp_ticker_fire_interrupt(void);
* } * }
* @endcode * @endcode
*/ */
const ticker_info_t* lp_ticker_get_info(void); const ticker_info_t *lp_ticker_get_info(void);
/**@}*/ /**@}*/

View File

@ -15,7 +15,7 @@
*/ */
#include "hal/gpio_api.h" #include "hal/gpio_api.h"
static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode) static inline void _gpio_init_in(gpio_t *gpio, PinName pin, PinMode mode)
{ {
gpio_init(gpio, pin); gpio_init(gpio, pin);
if (pin != NC) { if (pin != NC) {
@ -24,7 +24,7 @@ static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode)
} }
} }
static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value) static inline void _gpio_init_out(gpio_t *gpio, PinName pin, PinMode mode, int value)
{ {
gpio_init(gpio, pin); gpio_init(gpio, pin);
if (pin != NC) { if (pin != NC) {
@ -34,27 +34,33 @@ static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int v
} }
} }
void gpio_init_in(gpio_t* gpio, PinName pin) { void gpio_init_in(gpio_t *gpio, PinName pin)
{
gpio_init_in_ex(gpio, pin, PullDefault); gpio_init_in_ex(gpio, pin, PullDefault);
} }
void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode) { void gpio_init_in_ex(gpio_t *gpio, PinName pin, PinMode mode)
{
_gpio_init_in(gpio, pin, mode); _gpio_init_in(gpio, pin, mode);
} }
void gpio_init_out(gpio_t* gpio, PinName pin) { void gpio_init_out(gpio_t *gpio, PinName pin)
{
gpio_init_out_ex(gpio, pin, 0); gpio_init_out_ex(gpio, pin, 0);
} }
void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) { void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value)
{
_gpio_init_out(gpio, pin, PullNone, value); _gpio_init_out(gpio, pin, PullNone, value);
} }
void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) { void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value)
{
if (direction == PIN_INPUT) { if (direction == PIN_INPUT) {
_gpio_init_in(gpio, pin, mode); _gpio_init_in(gpio, pin, mode);
if (pin != NC) if (pin != NC) {
gpio_write(gpio, value); // we prepare the value in case it is switched later gpio_write(gpio, value); // we prepare the value in case it is switched later
}
} else { } else {
_gpio_init_out(gpio, pin, mode, value); _gpio_init_out(gpio, pin, mode, value);
} }

View File

@ -21,7 +21,7 @@
#include <stdbool.h> #include <stdbool.h>
#define ITM_ENABLE_WRITE 0xC5ACCE55 #define ITM_ENABLE_WRITE 0xC5ACCE55
#define SWO_NRZ 0x02 #define SWO_NRZ 0x02
#define SWO_STIMULUS_PORT 0x01 #define SWO_STIMULUS_PORT 0x01
@ -56,13 +56,13 @@ void mbed_itm_init(void)
ITM->TPR = 0x0; ITM->TPR = 0x0;
/* Trace Control Register */ /* Trace Control Register */
ITM->TCR = (1 << ITM_TCR_TraceBusID_Pos) | ITM->TCR = (1 << ITM_TCR_TraceBusID_Pos) |
(1 << ITM_TCR_DWTENA_Pos) | (1 << ITM_TCR_DWTENA_Pos) |
(1 << ITM_TCR_SYNCENA_Pos) | (1 << ITM_TCR_SYNCENA_Pos) |
(1 << ITM_TCR_ITMENA_Pos); (1 << ITM_TCR_ITMENA_Pos);
/* Trace Enable Register */ /* Trace Enable Register */
ITM->TER = SWO_STIMULUS_PORT; ITM->TER = SWO_STIMULUS_PORT;
} }
} }
@ -70,8 +70,7 @@ uint32_t mbed_itm_send(uint32_t port, uint32_t data)
{ {
/* Check if ITM and port is enabled */ /* Check if ITM and port is enabled */
if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */ if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */
((ITM->TER & (1UL << port) ) != 0UL) ) /* ITM Port enabled */ ((ITM->TER & (1UL << port)) != 0UL)) { /* ITM Port enabled */
{
/* write data to port */ /* write data to port */
ITM->PORT[port].u32 = data; ITM->PORT[port].u32 = data;

View File

@ -42,7 +42,7 @@ static const ticker_data_t lp_data = {
.queue = &events, .queue = &events,
}; };
const ticker_data_t* get_lp_ticker_data(void) const ticker_data_t *get_lp_ticker_data(void)
{ {
return &lp_data; return &lp_data;
} }

View File

@ -43,7 +43,7 @@ static void init_local()
{ {
MBED_ASSERT(core_util_in_critical_section()); MBED_ASSERT(core_util_in_critical_section());
const ticker_info_t* info = lp_ticker_get_info(); const ticker_info_t *info = lp_ticker_get_info();
if (info->bits >= 32) { if (info->bits >= 32) {
mask = 0xffffffff; mask = 0xffffffff;
} else { } else {

View File

@ -16,9 +16,11 @@
#include "hal/pinmap.h" #include "hal/pinmap.h"
#include "platform/mbed_error.h" #include "platform/mbed_error.h"
void pinmap_pinout(PinName pin, const PinMap *map) { void pinmap_pinout(PinName pin, const PinMap *map)
if (pin == NC) {
if (pin == NC) {
return; return;
}
while (map->pin != NC) { while (map->pin != NC) {
if (map->pin == pin) { if (map->pin == pin) {
@ -32,58 +34,72 @@ void pinmap_pinout(PinName pin, const PinMap *map) {
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "could not pinout", pin); MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "could not pinout", pin);
} }
uint32_t pinmap_merge(uint32_t a, uint32_t b) { uint32_t pinmap_merge(uint32_t a, uint32_t b)
{
// both are the same (inc both NC) // both are the same (inc both NC)
if (a == b) if (a == b) {
return a; return a;
}
// one (or both) is not connected // one (or both) is not connected
if (a == (uint32_t)NC) if (a == (uint32_t)NC) {
return b; return b;
if (b == (uint32_t)NC) }
if (b == (uint32_t)NC) {
return a; return a;
}
// mis-match error case // mis-match error case
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap mis-match", a); MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap mis-match", a);
return (uint32_t)NC; return (uint32_t)NC;
} }
uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map) { uint32_t pinmap_find_peripheral(PinName pin, const PinMap *map)
{
while (map->pin != NC) { while (map->pin != NC) {
if (map->pin == pin) if (map->pin == pin) {
return map->peripheral; return map->peripheral;
}
map++; map++;
} }
return (uint32_t)NC; return (uint32_t)NC;
} }
uint32_t pinmap_peripheral(PinName pin, const PinMap* map) { uint32_t pinmap_peripheral(PinName pin, const PinMap *map)
{
uint32_t peripheral = (uint32_t)NC; uint32_t peripheral = (uint32_t)NC;
if (pin == (PinName)NC) if (pin == (PinName)NC) {
return (uint32_t)NC; return (uint32_t)NC;
}
peripheral = pinmap_find_peripheral(pin, map); peripheral = pinmap_find_peripheral(pin, map);
if ((uint32_t)NC == peripheral) // no mapping available if ((uint32_t)NC == peripheral) { // no mapping available
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap not found for peripheral", peripheral); MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap not found for peripheral", peripheral);
}
return peripheral; return peripheral;
} }
uint32_t pinmap_find_function(PinName pin, const PinMap* map) { uint32_t pinmap_find_function(PinName pin, const PinMap *map)
{
while (map->pin != NC) { while (map->pin != NC) {
if (map->pin == pin) if (map->pin == pin) {
return map->function; return map->function;
}
map++; map++;
} }
return (uint32_t)NC; return (uint32_t)NC;
} }
uint32_t pinmap_function(PinName pin, const PinMap* map) { uint32_t pinmap_function(PinName pin, const PinMap *map)
{
uint32_t function = (uint32_t)NC; uint32_t function = (uint32_t)NC;
if (pin == (PinName)NC) if (pin == (PinName)NC) {
return (uint32_t)NC; return (uint32_t)NC;
}
function = pinmap_find_function(pin, map); function = pinmap_find_function(pin, map);
if ((uint32_t)NC == function) // no mapping available if ((uint32_t)NC == function) { // no mapping available
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap not found for function", function); MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap not found for function", function);
}
return function; return function;
} }

View File

@ -82,7 +82,7 @@ typedef struct sleep_statistic {
static sleep_statistic_t sleep_stats[STATISTIC_COUNT]; static sleep_statistic_t sleep_stats[STATISTIC_COUNT];
static sleep_statistic_t* sleep_tracker_find(const char *const filename) static sleep_statistic_t *sleep_tracker_find(const char *const filename)
{ {
for (int i = 0; i < STATISTIC_COUNT; ++i) { for (int i = 0; i < STATISTIC_COUNT; ++i) {
if (sleep_stats[i].identifier == filename) { if (sleep_stats[i].identifier == filename) {
@ -93,7 +93,7 @@ static sleep_statistic_t* sleep_tracker_find(const char *const filename)
return NULL; return NULL;
} }
static sleep_statistic_t* sleep_tracker_add(const char* const filename) static sleep_statistic_t *sleep_tracker_add(const char *const filename)
{ {
for (int i = 0; i < STATISTIC_COUNT; ++i) { for (int i = 0; i < STATISTIC_COUNT; ++i) {
if (sleep_stats[i].identifier == NULL) { if (sleep_stats[i].identifier == NULL) {
@ -121,7 +121,7 @@ static void sleep_tracker_print_stats(void)
} }
debug("[id: %s, count: %u]\r\n", sleep_stats[i].identifier, debug("[id: %s, count: %u]\r\n", sleep_stats[i].identifier,
sleep_stats[i].count); sleep_stats[i].count);
} }
} }
@ -139,7 +139,7 @@ void sleep_tracker_lock(const char *const filename, int line)
debug("LOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock); debug("LOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock);
} }
void sleep_tracker_unlock(const char* const filename, int line) void sleep_tracker_unlock(const char *const filename, int line)
{ {
sleep_statistic_t *stat = sleep_tracker_find(filename); sleep_statistic_t *stat = sleep_tracker_find(filename);

View File

@ -23,13 +23,13 @@ static void schedule_interrupt(const ticker_data_t *const ticker);
static void update_present_time(const ticker_data_t *const ticker); static void update_present_time(const ticker_data_t *const ticker);
/* /*
* Initialize a ticker instance. * Initialize a ticker instance.
*/ */
static void initialize(const ticker_data_t *ticker) static void initialize(const ticker_data_t *ticker)
{ {
// return if the queue has already been initialized, in that case the // return if the queue has already been initialized, in that case the
// interface used by the queue is already initialized. // interface used by the queue is already initialized.
if (ticker->queue->initialized) { if (ticker->queue->initialized) {
return; return;
} }
@ -57,7 +57,7 @@ static void initialize(const ticker_data_t *ticker)
} }
uint32_t max_delta = 0x7 << (bits - 4); // 7/16th uint32_t max_delta = 0x7 << (bits - 4); // 7/16th
uint64_t max_delta_us = uint64_t max_delta_us =
((uint64_t)max_delta * 1000000 + frequency - 1) / frequency; ((uint64_t)max_delta * 1000000 + frequency - 1) / frequency;
ticker->queue->event_handler = NULL; ticker->queue->event_handler = NULL;
ticker->queue->head = NULL; ticker->queue->head = NULL;
@ -70,13 +70,13 @@ static void initialize(const ticker_data_t *ticker)
ticker->queue->max_delta_us = max_delta_us; ticker->queue->max_delta_us = max_delta_us;
ticker->queue->present_time = 0; ticker->queue->present_time = 0;
ticker->queue->initialized = true; ticker->queue->initialized = true;
update_present_time(ticker); update_present_time(ticker);
schedule_interrupt(ticker); schedule_interrupt(ticker);
} }
/** /**
* Set the event handler function of a ticker instance. * Set the event handler function of a ticker instance.
*/ */
static void set_handler(const ticker_data_t *const ticker, ticker_event_handler handler) static void set_handler(const ticker_data_t *const ticker, ticker_event_handler handler)
{ {
@ -86,18 +86,18 @@ static void set_handler(const ticker_data_t *const ticker, ticker_event_handler
/* /*
* Convert a 32 bit timestamp into a 64 bit timestamp. * Convert a 32 bit timestamp into a 64 bit timestamp.
* *
* A 64 bit timestamp is used as the point of time of reference while the * A 64 bit timestamp is used as the point of time of reference while the
* timestamp to convert is relative to this point of time. * timestamp to convert is relative to this point of time.
* *
* The lower 32 bits of the timestamp returned will be equal to the timestamp to * The lower 32 bits of the timestamp returned will be equal to the timestamp to
* convert. * convert.
* *
* If the timestamp to convert is less than the lower 32 bits of the time * If the timestamp to convert is less than the lower 32 bits of the time
* reference then the timestamp to convert is seen as an overflowed value and * reference then the timestamp to convert is seen as an overflowed value and
* the upper 32 bit of the timestamp returned will be equal to the upper 32 bit * the upper 32 bit of the timestamp returned will be equal to the upper 32 bit
* of the reference point + 1. * of the reference point + 1.
* Otherwise, the upper 32 bit returned will be equal to the upper 32 bit of the * Otherwise, the upper 32 bit returned will be equal to the upper 32 bit of the
* reference point. * reference point.
* *
* @param ref: The 64 bit timestamp of reference. * @param ref: The 64 bit timestamp of reference.
* @param timestamp: The timestamp to convert. * @param timestamp: The timestamp to convert.
@ -107,8 +107,8 @@ static us_timestamp_t convert_timestamp(us_timestamp_t ref, timestamp_t timestam
bool overflow = timestamp < ((timestamp_t) ref) ? true : false; bool overflow = timestamp < ((timestamp_t) ref) ? true : false;
us_timestamp_t result = (ref & ~((us_timestamp_t)UINT32_MAX)) | timestamp; us_timestamp_t result = (ref & ~((us_timestamp_t)UINT32_MAX)) | timestamp;
if (overflow) { if (overflow) {
result += (1ULL<<32); result += (1ULL << 32);
} }
return result; return result;
@ -214,15 +214,15 @@ int _ticker_match_interval_passed(timestamp_t prev_tick, timestamp_t cur_tick, t
} }
/** /**
* Compute the time when the interrupt has to be triggered and schedule it. * Compute the time when the interrupt has to be triggered and schedule it.
* *
* If there is no event in the queue or the next event to execute is in more * If there is no event in the queue or the next event to execute is in more
* than ticker.queue.max_delta ticks from now then the ticker irq will be * than ticker.queue.max_delta ticks from now then the ticker irq will be
* scheduled in ticker.queue.max_delta ticks. Otherwise the irq will be * scheduled in ticker.queue.max_delta ticks. Otherwise the irq will be
* scheduled to happen when the running counter reach the timestamp of the * scheduled to happen when the running counter reach the timestamp of the
* first event in the queue. * first event in the queue.
* *
* @note If there is no event in the queue then the interrupt is scheduled to * @note If there is no event in the queue then the interrupt is scheduled to
* in ticker.queue.max_delta. This is necessary to keep track * in ticker.queue.max_delta. This is necessary to keep track
* of the timer overflow. * of the timer overflow.
*/ */
@ -259,7 +259,7 @@ static void schedule_interrupt(const ticker_data_t *const ticker)
} }
} else { } else {
uint32_t match_tick = uint32_t match_tick =
(queue->tick_last_read + queue->max_delta) & queue->bitmask; (queue->tick_last_read + queue->max_delta) & queue->bitmask;
ticker->interface->set_interrupt(match_tick); ticker->interface->set_interrupt(match_tick);
} }
} }
@ -285,10 +285,10 @@ void ticker_irq_handler(const ticker_data_t *const ticker)
break; break;
} }
// update the current timestamp used by the queue // update the current timestamp used by the queue
update_present_time(ticker); update_present_time(ticker);
if (ticker->queue->head->timestamp <= ticker->queue->present_time) { if (ticker->queue->head->timestamp <= ticker->queue->present_time) {
// This event was in the past: // This event was in the past:
// point to the following one and execute its handler // point to the following one and execute its handler
ticker_event_t *p = ticker->queue->head; ticker_event_t *p = ticker->queue->head;
@ -300,7 +300,7 @@ void ticker_irq_handler(const ticker_data_t *const ticker)
* event handler may have altered the chain of pending events. */ * event handler may have altered the chain of pending events. */
} else { } else {
break; break;
} }
} }
schedule_interrupt(ticker); schedule_interrupt(ticker);
@ -315,13 +315,13 @@ void ticker_insert_event(const ticker_data_t *const ticker, ticker_event_t *obj,
// update the current timestamp // update the current timestamp
update_present_time(ticker); update_present_time(ticker);
us_timestamp_t absolute_timestamp = convert_timestamp( us_timestamp_t absolute_timestamp = convert_timestamp(
ticker->queue->present_time, ticker->queue->present_time,
timestamp timestamp
); );
// defer to ticker_insert_event_us // defer to ticker_insert_event_us
ticker_insert_event_us( ticker_insert_event_us(
ticker, ticker,
obj, absolute_timestamp, id obj, absolute_timestamp, id
); );
@ -352,7 +352,7 @@ void ticker_insert_event_us(const ticker_data_t *const ticker, ticker_event_t *o
prev = p; prev = p;
p = p->next; p = p->next;
} }
/* if we're at the end p will be NULL, which is correct */ /* if we're at the end p will be NULL, which is correct */
obj->next = p; obj->next = p;
@ -378,7 +378,7 @@ void ticker_remove_event(const ticker_data_t *const ticker, ticker_event_t *obj)
schedule_interrupt(ticker); schedule_interrupt(ticker);
} else { } else {
// find the object before me, then drop me // find the object before me, then drop me
ticker_event_t* p = ticker->queue->head; ticker_event_t *p = ticker->queue->head;
while (p != NULL) { while (p != NULL) {
if (p->next == obj) { if (p->next == obj) {
p->next = obj->next; p->next = obj->next;

View File

@ -34,7 +34,7 @@ static const ticker_data_t us_data = {
.queue = &events .queue = &events
}; };
const ticker_data_t* get_us_ticker_data(void) const ticker_data_t *get_us_ticker_data(void)
{ {
return &us_data; return &us_data;
} }

View File

@ -32,14 +32,14 @@ typedef struct {
} PinMap; } PinMap;
void pin_function(PinName pin, int function); void pin_function(PinName pin, int function);
void pin_mode (PinName pin, PinMode mode); void pin_mode(PinName pin, PinMode mode);
uint32_t pinmap_peripheral(PinName pin, const PinMap* map); uint32_t pinmap_peripheral(PinName pin, const PinMap *map);
uint32_t pinmap_function(PinName pin, const PinMap* map); uint32_t pinmap_function(PinName pin, const PinMap *map);
uint32_t pinmap_merge (uint32_t a, uint32_t b); uint32_t pinmap_merge(uint32_t a, uint32_t b);
void pinmap_pinout (PinName pin, const PinMap *map); void pinmap_pinout(PinName pin, const PinMap *map);
uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map); uint32_t pinmap_find_peripheral(PinName pin, const PinMap *map);
uint32_t pinmap_find_function(PinName pin, const PinMap* map); uint32_t pinmap_find_function(PinName pin, const PinMap *map);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -73,7 +73,7 @@ extern "C" {
* The processor can be woken up by any internal peripheral interrupt or external pin interrupt. * The processor can be woken up by any internal peripheral interrupt or external pin interrupt.
* *
* The wake-up time shall be less than 10 us. * The wake-up time shall be less than 10 us.
* *
*/ */
void hal_sleep(void); void hal_sleep(void);

View File

@ -80,7 +80,7 @@ typedef struct {
uint64_t tick_remainder; /**< Ticks that have not been added to base_time */ uint64_t tick_remainder; /**< Ticks that have not been added to base_time */
us_timestamp_t present_time; /**< Store the timestamp used for present time */ us_timestamp_t present_time; /**< Store the timestamp used for present time */
bool initialized; /**< Indicate if the instance is initialized */ bool initialized; /**< Indicate if the instance is initialized */
uint8_t frequency_shifts; /**< If frequency is a value of 2^n, this is n, otherwise 0 */ uint8_t frequency_shifts; /**< If frequency is a value of 2^n, this is n, otherwise 0 */
} ticker_event_queue_t; } ticker_event_queue_t;
/** Ticker's data structure /** Ticker's data structure

View File

@ -102,7 +102,7 @@ extern "C" {
* @ingroup hal_lp_ticker * @ingroup hal_lp_ticker
*/ */
typedef void (*ticker_irq_handler_type)(const ticker_data_t *const); typedef void (*ticker_irq_handler_type)(const ticker_data_t *const);
/** Set ticker IRQ handler /** Set ticker IRQ handler
@ -121,7 +121,7 @@ ticker_irq_handler_type set_us_ticker_irq_handler(ticker_irq_handler_type ticker
* *
* @return The microsecond ticker data * @return The microsecond ticker data
*/ */
const ticker_data_t* get_us_ticker_data(void); const ticker_data_t *get_us_ticker_data(void);
/** The wrapper for ticker_irq_handler, to pass us ticker's data /** The wrapper for ticker_irq_handler, to pass us ticker's data
@ -269,7 +269,7 @@ void us_ticker_fire_interrupt(void);
* } * }
* @endcode * @endcode
*/ */
const ticker_info_t* us_ticker_get_info(void); const ticker_info_t *us_ticker_get_info(void);
/**@}*/ /**@}*/