2015-08-12 02:32:16 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-08-12 02:32:16 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-08-12 02:32:16 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-08-12 02:32:16 +08:00
|
|
|
*/
|
|
|
|
|
2015-12-04 23:09:39 +08:00
|
|
|
/**
|
2015-08-12 02:32:16 +08:00
|
|
|
* @file
|
|
|
|
* @brief Event logger support.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __EVENT_LOGGER_H__
|
|
|
|
#define __EVENT_LOGGER_H__
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-08-12 02:32:16 +08:00
|
|
|
#define EVENT_HEADER_SIZE 1
|
|
|
|
|
2015-08-22 07:56:36 +08:00
|
|
|
#ifndef _ASMLANGUAGE
|
|
|
|
|
|
|
|
#include <nanokernel.h>
|
|
|
|
#include <errno.h>
|
2015-08-28 05:03:15 +08:00
|
|
|
#include <misc/ring_buffer.h>
|
2015-08-12 02:32:16 +08:00
|
|
|
|
|
|
|
struct event_logger {
|
2016-11-08 00:48:39 +08:00
|
|
|
struct k_sem sync_sema;
|
2015-08-28 05:03:15 +08:00
|
|
|
struct ring_buf ring_buf;
|
2015-08-12 02:32:16 +08:00
|
|
|
};
|
|
|
|
|
2016-02-08 02:00:52 +08:00
|
|
|
/**
|
|
|
|
* @brief Event Logger
|
|
|
|
* @defgroup event_logger Event Logger
|
|
|
|
* @{
|
|
|
|
*/
|
2015-08-12 02:32:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize the event logger.
|
|
|
|
*
|
2016-02-08 02:00:52 +08:00
|
|
|
* @details This routine initializes the ring buffer.
|
2015-08-12 02:32:16 +08:00
|
|
|
*
|
|
|
|
* @param logger Logger to be initialized.
|
|
|
|
* @param logger_buffer Pointer to the buffer to be used by the logger.
|
|
|
|
* @param buffer_size Size of the buffer in 32-bit words.
|
|
|
|
*
|
2016-02-08 02:00:52 +08:00
|
|
|
* @return N/A
|
2015-08-12 02:32:16 +08:00
|
|
|
*/
|
|
|
|
void sys_event_logger_init(struct event_logger *logger,
|
2016-11-08 00:48:39 +08:00
|
|
|
uint32_t *logger_buffer, uint32_t buffer_size);
|
2015-08-12 02:32:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Send an event message to the logger.
|
|
|
|
*
|
2016-02-08 02:00:52 +08:00
|
|
|
* @details This routine adds an event message to the ring buffer and signals
|
|
|
|
* the sync semaphore to indicate that event messages are available.
|
2015-08-12 02:32:16 +08:00
|
|
|
*
|
|
|
|
* @param logger Pointer to the event logger used.
|
2016-02-08 02:00:52 +08:00
|
|
|
* @param event_id The profiler event's ID.
|
2015-10-04 22:01:56 +08:00
|
|
|
* @param event_data Pointer to the data of the message.
|
2015-08-12 02:32:16 +08:00
|
|
|
* @param data_size Size of the buffer in 32-bit words.
|
|
|
|
*
|
2016-02-08 02:00:52 +08:00
|
|
|
* @return N/A
|
2015-08-12 02:32:16 +08:00
|
|
|
*/
|
|
|
|
void sys_event_logger_put(struct event_logger *logger, uint16_t event_id,
|
2016-11-08 00:48:39 +08:00
|
|
|
uint32_t *event_data, uint8_t data_size);
|
2015-08-12 02:32:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Retrieve an event message from the logger.
|
|
|
|
*
|
2016-02-08 02:00:52 +08:00
|
|
|
* @details This routine retrieves an event message from the ring buffer and
|
|
|
|
* copies it to the provided buffer. If the provided buffer is smaller
|
|
|
|
* than the message size the function returns -EMSGSIZE. Otherwise, it returns
|
|
|
|
* the number of 32-bit words copied. The function retrieves messages in
|
|
|
|
* FIFO order. If there is no message in the buffer the function returns
|
|
|
|
* immediately. It can only be called from a fiber.
|
2015-08-12 02:32:16 +08:00
|
|
|
*
|
|
|
|
* @param logger Pointer to the event logger used.
|
2016-02-08 02:00:52 +08:00
|
|
|
* @param event_id Pointer to the id of the fetched event.
|
|
|
|
* @param dropped_event_count Pointer to the number of events dropped.
|
|
|
|
* @param buffer Pointer to the buffer for the copied message.
|
2015-08-28 05:03:15 +08:00
|
|
|
* @param buffer_size Size of the buffer in 32-bit words. Updated with the
|
2016-02-08 02:00:52 +08:00
|
|
|
* actual message's size.
|
2015-08-12 02:32:16 +08:00
|
|
|
*
|
2016-02-08 02:00:52 +08:00
|
|
|
* @retval EMSGSIZE If the buffer size is smaller than the message size.
|
|
|
|
* @retval Number of 32-bit words copied.
|
|
|
|
* @retval 0 If no message was already available.
|
2015-08-12 02:32:16 +08:00
|
|
|
*/
|
2015-08-28 05:03:15 +08:00
|
|
|
int sys_event_logger_get(struct event_logger *logger, uint16_t *event_id,
|
|
|
|
uint8_t *dropped_event_count, uint32_t *buffer,
|
|
|
|
uint8_t *buffer_size);
|
2015-08-12 02:32:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Retrieve an event message from the logger, wait if empty.
|
|
|
|
*
|
2016-02-08 02:00:52 +08:00
|
|
|
* @details This routine retrieves an event message from the ring buffer
|
|
|
|
* and copies it to the provided buffer. If the provided buffer is smaller
|
|
|
|
* than the message size the function returns -EMSGSIZE. Otherwise, it
|
|
|
|
* returns the number of 32-bit words copied.
|
|
|
|
*
|
|
|
|
* The function retrieves messages in FIFO order. The caller pends if there is
|
|
|
|
* no message available in the buffer. It can only be called from a fiber.
|
2015-08-12 02:32:16 +08:00
|
|
|
*
|
|
|
|
* @param logger Pointer to the event logger used.
|
2016-02-08 02:00:52 +08:00
|
|
|
* @param event_id Pointer to the ID of the fetched event.
|
|
|
|
* @param dropped_event_count Pointer to the number of dropped events.
|
|
|
|
* @param buffer Pointer to the buffer for the copied messages.
|
2015-08-28 05:03:15 +08:00
|
|
|
* @param buffer_size Size of the buffer in 32-bit words. Updated with the
|
2016-02-08 02:00:52 +08:00
|
|
|
* actual message's size.
|
2015-08-12 02:32:16 +08:00
|
|
|
*
|
2016-02-08 02:00:52 +08:00
|
|
|
* @retval EMSGSIZE If the buffer size is smaller than the message size.
|
|
|
|
* @retval Number of DWORDs copied, otherwise.
|
2015-08-12 02:32:16 +08:00
|
|
|
*/
|
2015-08-28 05:03:15 +08:00
|
|
|
int sys_event_logger_get_wait(struct event_logger *logger, uint16_t *event_id,
|
|
|
|
uint8_t *dropped_event_count, uint32_t *buffer,
|
|
|
|
uint8_t *buffer_size);
|
2015-08-12 02:32:16 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_NANO_TIMEOUTS
|
|
|
|
/**
|
|
|
|
* @brief Retrieve an event message from the logger, wait with a timeout if
|
|
|
|
* empty.
|
|
|
|
*
|
2016-02-08 02:00:52 +08:00
|
|
|
* @details This routine retrieves an event message from the ring buffer and
|
|
|
|
* copies it to the provided buffer. If the provided buffer is smaller than
|
|
|
|
* the message size the routine returns -EMSGSIZE. Otherwise, it returns the
|
|
|
|
* number of dwords copied. The function retrieves messages in FIFO order.
|
|
|
|
* If no message is available in the buffer, the caller pends until a
|
|
|
|
* new message is added or the timeout expires. This routine can only be
|
|
|
|
* called from a fiber.
|
2015-08-12 02:32:16 +08:00
|
|
|
*
|
|
|
|
* @param logger Pointer to the event logger used.
|
2016-02-08 02:00:52 +08:00
|
|
|
* @param event_id Pointer to the ID of the event fetched.
|
|
|
|
* @param dropped_event_count Pointer to the number of dropped events.
|
|
|
|
* @param buffer Pointer to the buffer for the copied message.
|
2015-08-28 05:03:15 +08:00
|
|
|
* @param buffer_size Size of the buffer in 32-bit words. Updated with the
|
2016-02-08 02:00:52 +08:00
|
|
|
* actual message size.
|
2015-08-12 02:32:16 +08:00
|
|
|
* @param timeout Timeout in ticks.
|
|
|
|
*
|
2016-02-08 02:00:52 +08:00
|
|
|
* @retval EMSGSIZE if the buffer size is smaller than the message size.
|
|
|
|
* @retval Number of 32-bit words copied.
|
|
|
|
* @retval 0 If the timeout expired and there was no message already
|
|
|
|
* available.
|
2015-08-12 02:32:16 +08:00
|
|
|
*/
|
|
|
|
int sys_event_logger_get_wait_timeout(struct event_logger *logger,
|
2015-08-28 05:03:15 +08:00
|
|
|
uint16_t *event_id,
|
|
|
|
uint8_t *dropped_event_count,
|
|
|
|
uint32_t *buffer, uint8_t *buffer_size,
|
|
|
|
uint32_t timeout);
|
2016-02-08 02:00:52 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2016-11-08 00:48:39 +08:00
|
|
|
#endif /* CONFIG_NANO_TIMEOUTS */
|
2015-08-12 02:32:16 +08:00
|
|
|
|
2016-11-08 00:48:39 +08:00
|
|
|
#endif /* _ASMLANGUAGE */
|
2016-01-23 01:38:49 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-12 02:32:16 +08:00
|
|
|
#endif /* __EVENT_LOGGER_H__ */
|