Import Mbed OS hard-float snapshot
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef EVENTOS_CALLBACK_TIMER_H_
|
||||
#define EVENTOS_CALLBACK_TIMER_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "ns_types.h"
|
||||
|
||||
extern int8_t eventOS_callback_timer_register(void (*timer_interrupt_handler)(int8_t, uint16_t));
|
||||
extern int8_t eventOS_callback_timer_unregister(int8_t ns_timer_id);
|
||||
|
||||
extern int8_t eventOS_callback_timer_stop(int8_t ns_timer_id);
|
||||
extern int8_t eventOS_callback_timer_start(int8_t ns_timer_id, uint16_t slots);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EVENTOS_CALLBACK_TIMER_H_ */
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef EVENTOS_EVENT_H_
|
||||
#define EVENTOS_EVENT_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ns_types.h"
|
||||
#include "ns_list.h"
|
||||
|
||||
/**
|
||||
* \enum arm_library_event_priority_e
|
||||
* \brief Event Priority level.
|
||||
*/
|
||||
typedef enum arm_library_event_priority_e {
|
||||
ARM_LIB_HIGH_PRIORITY_EVENT = 0, /**< High Priority Event (Function CB) */
|
||||
ARM_LIB_MED_PRIORITY_EVENT = 1, /**< Medium Priority (Timer) */
|
||||
ARM_LIB_LOW_PRIORITY_EVENT = 2, /*!*< Normal Event and ECC / Security */
|
||||
} arm_library_event_priority_e;
|
||||
|
||||
/**
|
||||
* \struct arm_event_s
|
||||
* \brief Event structure.
|
||||
*/
|
||||
typedef struct arm_event_s {
|
||||
int8_t receiver; /**< Event handler Tasklet ID */
|
||||
int8_t sender; /**< Event sender Tasklet ID */
|
||||
uint8_t event_type; /**< This will be typecast arm_library_event_type_e, arm_internal_event_type_e or application specific define */
|
||||
uint8_t event_id; /**< Timer ID, NWK interface ID or application specific ID */
|
||||
void *data_ptr; /**< Application could share data pointer tasklet to tasklet */
|
||||
arm_library_event_priority_e priority;
|
||||
uintptr_t event_data;
|
||||
} arm_event_t;
|
||||
|
||||
/* Backwards compatibility */
|
||||
typedef arm_event_t arm_event_s;
|
||||
|
||||
/**
|
||||
* \struct arm_event_storage
|
||||
* \brief Event structure storage, including list link.
|
||||
|
||||
@startuml
|
||||
|
||||
partition "Event loop" {
|
||||
(*) -->[event created] "UNQUEUED"
|
||||
"UNQUEUED" -->[event_core_write()] "QUEUED"
|
||||
"QUEUED" -->[event_core_read()] "RUNNING"
|
||||
"RUNNING" ->[event_core_free_push()] "UNQUEUED"
|
||||
}
|
||||
|
||||
partition "system_timer.c" {
|
||||
"UNQUEUED:timer" -->[eventOS_event_send_timer_allocated()] "QUEUED"
|
||||
}
|
||||
@enduml
|
||||
|
||||
*/
|
||||
typedef struct arm_event_storage {
|
||||
arm_event_s data;
|
||||
enum {
|
||||
ARM_LIB_EVENT_STARTUP_POOL,
|
||||
ARM_LIB_EVENT_DYNAMIC,
|
||||
ARM_LIB_EVENT_USER,
|
||||
ARM_LIB_EVENT_TIMER,
|
||||
} allocator;
|
||||
enum {
|
||||
ARM_LIB_EVENT_UNQUEUED,
|
||||
ARM_LIB_EVENT_QUEUED,
|
||||
ARM_LIB_EVENT_RUNNING,
|
||||
} state;
|
||||
ns_list_link_t link;
|
||||
} arm_event_storage_t;
|
||||
|
||||
/**
|
||||
* \brief Send event to event scheduler.
|
||||
*
|
||||
* \param event pointer to pushed event.
|
||||
*
|
||||
* Event data is copied by the call, and this copy persists until the
|
||||
* recipient's callback function returns. The callback function is passed
|
||||
* a pointer to a copy of the data, not the original pointer.
|
||||
*
|
||||
* \return 0 Event push OK
|
||||
* \return -1 Memory allocation Fail
|
||||
*/
|
||||
extern int8_t eventOS_event_send(const arm_event_t *event);
|
||||
|
||||
/* Alternate names for timer function from eventOS_event_timer.h;
|
||||
* implementations may one day merge */
|
||||
#define eventOS_event_send_at(event, at) eventOS_event_timer_request_at(event, at)
|
||||
#define eventOS_event_send_in(event, in) eventOS_event_timer_request_in(event, in)
|
||||
#define eventOS_event_send_after(event, after) eventOS_event_timer_request_after(event, after)
|
||||
#define eventOS_event_send_every(event, every) eventOS_event_timer_request_every(event, every)
|
||||
|
||||
/**
|
||||
* \brief Send user-allocated event to event scheduler.
|
||||
*
|
||||
* \param event pointer to pushed event storage.
|
||||
*
|
||||
* The event structure is not copied by the call, the event system takes
|
||||
* ownership and it is threaded directly into the event queue. This avoids the
|
||||
* possibility of event sending failing due to memory exhaustion.
|
||||
*
|
||||
* event->data must be filled in on entry - the rest of the structure (link and
|
||||
* allocator) need not be.
|
||||
*
|
||||
* The structure must remain valid until the recipient is called - the
|
||||
* event system passes ownership to the receiving event handler, who may then
|
||||
* invalidate it, or send it again.
|
||||
*
|
||||
* The recipient receives a pointer to the arm_event_t data member of the
|
||||
* event - it can use NS_CONTAINER_OF() to get a pointer to the original
|
||||
* event passed to this call, or to its outer container.
|
||||
*
|
||||
* It is a program error to send a user-allocated event to a non-existent task.
|
||||
*/
|
||||
extern void eventOS_event_send_user_allocated(arm_event_storage_t *event);
|
||||
|
||||
/**
|
||||
* \brief Event handler callback register
|
||||
*
|
||||
* Function will register and allocate unique event id handler
|
||||
*
|
||||
* \param handler_func_ptr function pointer for event handler
|
||||
* \param init_event_type generated event type for init purpose
|
||||
*
|
||||
* \return >= 0 Unique event ID for this handler
|
||||
* \return < 0 Register fail
|
||||
*
|
||||
* */
|
||||
extern int8_t eventOS_event_handler_create(void (*handler_func_ptr)(arm_event_t *), uint8_t init_event_type);
|
||||
|
||||
/**
|
||||
* Cancel an event.
|
||||
*
|
||||
* Queued events are removed from the event-loop queue and/or the timer queue.
|
||||
*
|
||||
* Passing a NULL pointer is allowed, and does nothing.
|
||||
*
|
||||
* Event pointers are valid from the time they are queued until the event
|
||||
* has finished running or is cancelled.
|
||||
*
|
||||
* Cancelling a currently-running event is only useful to stop scheduling
|
||||
* it if it is on a periodic timer; it has no other effect.
|
||||
*
|
||||
* Cancelling an already-cancelled or already-run single-shot event
|
||||
* is undefined behaviour.
|
||||
*
|
||||
* \param event Pointer to event handle or NULL.
|
||||
*/
|
||||
extern void eventOS_cancel(arm_event_storage_t *event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* EVENTOS_EVENT_H_ */
|
||||
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef EVENTOS_EVENT_TIMER_H_
|
||||
#define EVENTOS_EVENT_TIMER_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "ns_types.h"
|
||||
#include "eventOS_event.h"
|
||||
|
||||
struct arm_event_s;
|
||||
typedef struct sys_timer_struct_s sys_timer_struct_t;
|
||||
|
||||
/* 100 Hz ticker, so 10 milliseconds per tick */
|
||||
#define EVENTOS_EVENT_TIMER_HZ 100
|
||||
|
||||
static inline uint32_t eventOS_event_timer_ticks_to_ms(uint32_t ticks)
|
||||
{
|
||||
NS_STATIC_ASSERT(1000 % EVENTOS_EVENT_TIMER_HZ == 0, "Assuming whole number of ms per tick")
|
||||
return ticks * (1000 / EVENTOS_EVENT_TIMER_HZ);
|
||||
}
|
||||
|
||||
/* Convert ms to ticks, rounding up (so 9ms = 1 tick, 10ms = 1 tick, 11ms = 2 ticks) */
|
||||
static inline uint32_t eventOS_event_timer_ms_to_ticks(uint32_t ms)
|
||||
{
|
||||
NS_STATIC_ASSERT(1000 % EVENTOS_EVENT_TIMER_HZ == 0, "Assuming whole number of ms per tick")
|
||||
return (ms + (1000 / EVENTOS_EVENT_TIMER_HZ) - 1) / (1000 / EVENTOS_EVENT_TIMER_HZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read current timer tick count.
|
||||
*
|
||||
* Can be used as a monotonic time source, and to schedule events with
|
||||
* eventOS_event_timer_send.
|
||||
*
|
||||
* Note that the value will wrap, so take care on comparisons.
|
||||
*
|
||||
* \return tick count.
|
||||
*/
|
||||
extern uint32_t eventOS_event_timer_ticks(void);
|
||||
|
||||
/* Comparison macros handling wrap efficiently (assuming a conventional compiler
|
||||
* which converts 0x80000000 to 0xFFFFFFFF to negative when casting to int32_t).
|
||||
*/
|
||||
#define TICKS_AFTER(a, b) ((int32_t) ((a)-(b)) > 0)
|
||||
#define TICKS_BEFORE(a, b) ((int32_t) ((a)-(b)) < 0)
|
||||
#define TICKS_AFTER_OR_AT(a, b) ((int32_t) ((a)-(b)) >= 0)
|
||||
#define TICKS_BEFORE_OR_AT(a, b) ((int32_t) ((a)-(b)) <= 0)
|
||||
|
||||
/**
|
||||
* Send an event after time expired (in milliseconds)
|
||||
*
|
||||
* Note that the current implementation has the "feature" that rounding
|
||||
* varies depending on the precise timing requested:
|
||||
* 0-20 ms => 2 x 10ms tick
|
||||
* 21-29 ms => 3 x 10ms tick
|
||||
* 30-39 ms => 4 x 10ms tick
|
||||
* 40-49 ms => 5 x 10ms tick
|
||||
* ... etc
|
||||
*
|
||||
* For improved flexibility on the event, and for more control of time,
|
||||
* you should use eventOS_event_timer_request_at().
|
||||
*
|
||||
* \param event_id event_id for event
|
||||
* \param event_type event_type for event
|
||||
* \param tasklet_id receiver for event
|
||||
* \param time time to sleep in milliseconds
|
||||
*
|
||||
* \return 0 on success
|
||||
* \return -1 on error (invalid tasklet_id or allocation failure)
|
||||
*
|
||||
* */
|
||||
extern int8_t eventOS_event_timer_request(uint8_t event_id, uint8_t event_type, int8_t tasklet_id, uint32_t time);
|
||||
|
||||
/**
|
||||
* Send an event at specified time
|
||||
*
|
||||
* The event will be sent when eventOS_event_timer_ticks() reaches the
|
||||
* specified value.
|
||||
*
|
||||
* If the specified time is in the past (ie "at" is before or at the current
|
||||
* tick value), the event will be sent immediately.
|
||||
*
|
||||
* Can also be invoked using the eventOS_event_send_at() macro in eventOS_event.h
|
||||
*
|
||||
* \param event event to send
|
||||
* \param at absolute tick time to run event at
|
||||
*
|
||||
* \return pointer to timer structure on success
|
||||
* \return NULL on error (invalid tasklet_id or allocation failure)
|
||||
*
|
||||
*/
|
||||
extern arm_event_storage_t *eventOS_event_timer_request_at(const struct arm_event_s *event, uint32_t at);
|
||||
|
||||
/**
|
||||
* Send an event in a specified time
|
||||
*
|
||||
* The event will be sent in the specified number of ticks - to
|
||||
* be precise, it is equivalent to requesting an event at
|
||||
*
|
||||
* eventOS_event_timer_ticks() + ticks
|
||||
*
|
||||
* Because of timer granularity, the elapsed time between issuing the request
|
||||
* and it running may be up to 1 tick less than the specified time.
|
||||
*
|
||||
* eg requesting 2 ticks will cause the event to be sent on the second tick from
|
||||
* now. If requested just after a tick, the delay will be nearly 2 ticks, but if
|
||||
* requested just before a tick, the delay will be just over 1 tick.
|
||||
*
|
||||
* If `in` is <= 0, the event will be sent immediately.
|
||||
*
|
||||
* Can also be invoked using the eventOS_event_send_in() macro in eventOS_event.h
|
||||
*
|
||||
* \param event event to send
|
||||
* \param in tick delay for event
|
||||
*
|
||||
* \return pointer to timer structure on success
|
||||
* \return NULL on error (invalid tasklet_id or allocation failure)
|
||||
*
|
||||
*/
|
||||
extern arm_event_storage_t *eventOS_event_timer_request_in(const struct arm_event_s *event, int32_t in);
|
||||
|
||||
/**
|
||||
* Send an event after a specified time
|
||||
*
|
||||
* The event will be sent after the specified number of ticks - to
|
||||
* be precise, it is equivalent to requesting an event at
|
||||
*
|
||||
* eventOS_event_timer_ticks() + ticks + 1
|
||||
*
|
||||
* Because of timer granularity, the elapsed time between issuing the request
|
||||
* and it running may be up to 1 tick more than the specified time.
|
||||
*
|
||||
* eg requesting 2 ticks will cause the event to be sent on the third tick from
|
||||
* now. If requested just after a tick, the delay will be nearly 3 ticks, but if
|
||||
* requested just before a tick, the delay will be just over 2 ticks.
|
||||
*
|
||||
* If `after` is < 0, the event will be sent immediately. If it is 0, the event
|
||||
* is sent on the next tick.
|
||||
*
|
||||
* Can also be invoked using the eventOS_event_send_after() macro in eventOS_event.h
|
||||
*
|
||||
* \param event event to send
|
||||
* \param after tick delay for event
|
||||
*
|
||||
* \return pointer to timer structure on success
|
||||
* \return NULL on error (invalid tasklet_id or allocation failure)
|
||||
*
|
||||
*/
|
||||
#define eventOS_event_timer_request_after(event, after) \
|
||||
eventOS_event_timer_request_in(event, (after) + 1)
|
||||
|
||||
/**
|
||||
* Send an event periodically
|
||||
*
|
||||
* The event will be sent repeatedly using the specified ticks period.
|
||||
*
|
||||
* The first call is sent at
|
||||
*
|
||||
* eventOS_event_timer_ticks() + ticks
|
||||
*
|
||||
* Subsequent events will be sent at N*ticks from the initial time.
|
||||
*
|
||||
* Period will be maintained while the device is awake, regardless of delays to
|
||||
* event scheduling. If an event has not been delivered and completed by the
|
||||
* next scheduled time, the next event will be sent immediately when it
|
||||
* finishes. This could cause a continuous stream of events if unable to keep
|
||||
* up with the period.
|
||||
*
|
||||
* Can also be invoked using the eventOS_event_send_every() macro in eventOS_event.h
|
||||
*
|
||||
* \param event event to send
|
||||
* \param period period for event
|
||||
*
|
||||
* \return pointer to timer structure on success
|
||||
* \return NULL on error (invalid tasklet_id or allocation failure)
|
||||
*
|
||||
*/
|
||||
extern arm_event_storage_t *eventOS_event_timer_request_every(const struct arm_event_s *event, int32_t period);
|
||||
|
||||
/**
|
||||
* Cancel an event timer
|
||||
*
|
||||
* This cancels a pending timed event, matched by event_id and tasklet_id.
|
||||
*
|
||||
* \param event_id event_id for event
|
||||
* \param tasklet_id receiver for event
|
||||
*
|
||||
* \return 0 on success
|
||||
* \return -1 on error (event not found)
|
||||
*
|
||||
* */
|
||||
extern int8_t eventOS_event_timer_cancel(uint8_t event_id, int8_t tasklet_id);
|
||||
|
||||
/**
|
||||
* System Timer shortest time in milli seconds
|
||||
*
|
||||
* \param ticks Time in 10 ms resolution
|
||||
*
|
||||
* \return none
|
||||
*
|
||||
* */
|
||||
extern uint32_t eventOS_event_timer_shortest_active_timer(void);
|
||||
|
||||
|
||||
/** Timeout structure. Not to be modified by user */
|
||||
typedef struct timeout_entry_t timeout_t;
|
||||
|
||||
/** Request timeout callback.
|
||||
*
|
||||
* Create timeout request for specific callback.
|
||||
*
|
||||
* \param ms timeout in milliseconds. Maximum range is same as for eventOS_event_timer_request().
|
||||
* \param callback function to call after timeout
|
||||
* \param arg arquement to pass to callback
|
||||
* \return pointer to timeout structure or NULL on errors
|
||||
*/
|
||||
timeout_t *eventOS_timeout_ms(void (*callback)(void *), uint32_t ms, void *arg);
|
||||
|
||||
/** Request periodic callback.
|
||||
*
|
||||
* Create timeout request for specific callback. Called periodically until eventOS_timeout_cancel() is called.
|
||||
*
|
||||
* \param every period in milliseconds. Maximum range is same as for eventOS_event_timer_request().
|
||||
* \param callback function to call after timeout
|
||||
* \param arg arquement to pass to callback
|
||||
* \return pointer to timeout structure or NULL on errors
|
||||
*/
|
||||
timeout_t *eventOS_timeout_every_ms(void (*callback)(void *), uint32_t every, void *arg);
|
||||
|
||||
/** Cancell timeout request.
|
||||
*
|
||||
* \param t timeout request id.
|
||||
*/
|
||||
void eventOS_timeout_cancel(timeout_t *t);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EVENTOS_EVENT_TIMER_H_ */
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef EVENTOS_SCHEDULER_H_
|
||||
#define EVENTOS_SCHEDULER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "ns_types.h"
|
||||
|
||||
/* Compatibility with older ns_types.h */
|
||||
#ifndef NS_NORETURN
|
||||
#define NS_NORETURN
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Initialise event scheduler.
|
||||
*
|
||||
*/
|
||||
extern void eventOS_scheduler_init(void);
|
||||
|
||||
/**
|
||||
* Process one event from event queue.
|
||||
* Do not call this directly from application. Requires to be public so that simulator can call this.
|
||||
* Use eventOS_scheduler_run() or eventOS_scheduler_run_until_idle().
|
||||
* \return true If there was event processed, false if the event queue was empty.
|
||||
*/
|
||||
bool eventOS_scheduler_dispatch_event(void);
|
||||
|
||||
/**
|
||||
* \brief Process events until no more events to process.
|
||||
*/
|
||||
extern void eventOS_scheduler_run_until_idle(void);
|
||||
|
||||
/**
|
||||
* \brief Start Event scheduler.
|
||||
* Loops forever processing events from the queue.
|
||||
* Calls eventOS_scheduler_idle() whenever event queue is empty.
|
||||
*/
|
||||
NS_NORETURN extern void eventOS_scheduler_run(void);
|
||||
/**
|
||||
* \brief Disable Event scheduler Timers
|
||||
*
|
||||
* \return 0 Timer Stop OK
|
||||
* \return -1 Timer Stop Fail
|
||||
*
|
||||
* */
|
||||
int eventOS_scheduler_timer_stop(void);
|
||||
|
||||
/**
|
||||
* \brief Synch Event scheduler timer after sleep
|
||||
*
|
||||
* \param sleep_ticks time in milli seconds
|
||||
*
|
||||
* \return 0 Timer Synch OK
|
||||
* \return -1 Timer Synch & Start Fail
|
||||
*
|
||||
* */
|
||||
int eventOS_scheduler_timer_synch_after_sleep(uint32_t sleep_ticks);
|
||||
|
||||
/**
|
||||
* \brief Read current active Tasklet ID
|
||||
*
|
||||
* This function not return valid information called inside interrupt
|
||||
*
|
||||
* \return curret active tasklet id
|
||||
*
|
||||
* */
|
||||
extern int8_t eventOS_scheduler_get_active_tasklet(void);
|
||||
|
||||
/**
|
||||
* \brief Set manually Active Tasklet ID
|
||||
*
|
||||
* \param tasklet requested tasklet ID
|
||||
*
|
||||
* */
|
||||
extern void eventOS_scheduler_set_active_tasklet(int8_t tasklet);
|
||||
|
||||
/**
|
||||
* \brief Event scheduler loop idle Callback.
|
||||
|
||||
* Note! This method is called only by eventOS_scheduler_run, needs to be
|
||||
* ported for the platform only if you are using eventOS_scheduler_run().
|
||||
*/
|
||||
extern void eventOS_scheduler_idle(void);
|
||||
|
||||
/**
|
||||
* \brief This function will be called when stack enter idle state and start
|
||||
* waiting signal.
|
||||
*
|
||||
* Note! This method is called only by reference implementation of idle. Needs
|
||||
* to be ported for the platform only if you are using reference implementation.
|
||||
*/
|
||||
extern void eventOS_scheduler_wait(void);
|
||||
|
||||
/**
|
||||
* \brief This function will be called when stack receives an event.
|
||||
*/
|
||||
extern void eventOS_scheduler_signal(void);
|
||||
|
||||
/**
|
||||
* \brief This function will be called when stack can enter deep sleep state in detected time.
|
||||
*
|
||||
* Note! This method is called only by reference implementation of idle. Needs to be
|
||||
* ported for the platform only if you are using reference implementation.
|
||||
*
|
||||
* \param sleep_time_ms Time in milliseconds to sleep
|
||||
* \return time slept in milliseconds
|
||||
*/
|
||||
extern uint32_t eventOS_scheduler_sleep(uint32_t sleep_time_ms);
|
||||
|
||||
/**
|
||||
* \brief Lock a thread against the event loop thread
|
||||
*
|
||||
* This method can be provided by multi-threaded platforms to allow
|
||||
* mutual exclusion with the event loop thread, for cases where
|
||||
* code wants to work with both the event loop and other threads.
|
||||
*
|
||||
* A typical platform implementation would claim the same mutex
|
||||
* before calling eventOS_scheduler_run() or
|
||||
* eventOS_scheduler_dispatch(), and release it during
|
||||
* eventOS_scheduler_idle().
|
||||
*
|
||||
* The mutex must count - nested calls from one thread return
|
||||
* immediately. Thus calling this from inside an event callback
|
||||
* is harmless.
|
||||
*/
|
||||
extern void eventOS_scheduler_mutex_wait(void);
|
||||
|
||||
/**
|
||||
* \brief Release the event loop mutex
|
||||
*
|
||||
* Release the mutex claimed with eventOS_scheduler_mutex_wait(),
|
||||
* allowing the event loop to continue processing.
|
||||
*/
|
||||
extern void eventOS_scheduler_mutex_release(void);
|
||||
|
||||
/**
|
||||
* \brief Check if the current thread owns the event mutex
|
||||
*
|
||||
* Check if the calling thread owns the scheduler mutex.
|
||||
* This allows the ownership to be asserted if a function
|
||||
* requires the mutex to be locked externally.
|
||||
*
|
||||
* The function is only intended as a debugging aid for
|
||||
* users of eventOS_scheduler_mutex_wait() - it is not
|
||||
* used by the event loop core itself.
|
||||
*
|
||||
* If the underlying mutex system does not support it,
|
||||
* this may be implemented to always return true.
|
||||
*
|
||||
* \return true if the current thread owns the mutex
|
||||
*/
|
||||
extern bool eventOS_scheduler_mutex_am_owner(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EVENTOS_SCHEDULER_H_ */
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef ARM_HAL_TIMER_H_
|
||||
#define ARM_HAL_TIMER_H_
|
||||
|
||||
#include "eventloop_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef NS_EXCLUDE_HIGHRES_TIMER
|
||||
/**
|
||||
* \brief This function perform timer init.
|
||||
*/
|
||||
extern void platform_timer_enable(void);
|
||||
|
||||
/**
|
||||
* \brief This function is API for set Timer interrupt handler for stack
|
||||
*
|
||||
* \param new_fp Function pointer for stack giving timer handler
|
||||
*
|
||||
*/
|
||||
typedef void (*platform_timer_cb)(void);
|
||||
extern void platform_timer_set_cb(platform_timer_cb new_fp);
|
||||
|
||||
/**
|
||||
* \brief This function is API for stack timer start
|
||||
*
|
||||
* \param slots define how many 50us slot time period will be started
|
||||
*
|
||||
*/
|
||||
extern void platform_timer_start(uint16_t slots);
|
||||
|
||||
/**
|
||||
* \brief This function is API for stack timer stop
|
||||
*
|
||||
*/
|
||||
extern void platform_timer_disable(void);
|
||||
|
||||
/**
|
||||
* \brief This function is API for stack timer to read active timer remaining slot count
|
||||
*
|
||||
* \return 50us time slot remaining
|
||||
*/
|
||||
extern uint16_t platform_timer_get_remaining_slots(void);
|
||||
|
||||
#endif // NS_EXCLUDE_HIGHRES_TIMER
|
||||
|
||||
#ifdef NS_EVENTLOOP_USE_TICK_TIMER
|
||||
/**
|
||||
* \brief This function is API for registering low resolution tick timer callback. Also does
|
||||
* any necessary initialization of the tick timer.
|
||||
*
|
||||
* \return -1 for failure, success otherwise
|
||||
*/
|
||||
extern int8_t platform_tick_timer_register(void (*tick_timer_cb_handler)(void));
|
||||
|
||||
/**
|
||||
* \brief This function is API for starting the low resolution tick timer. The callback
|
||||
* set with platform_tick_timer_register gets called periodically until stopped
|
||||
* by calling platform_tick_timer_stop.
|
||||
*
|
||||
* \param period_ms define how many milliseconds time period will be started
|
||||
* \return -1 for failure, success otherwise
|
||||
*/
|
||||
extern int8_t platform_tick_timer_start(uint32_t period_ms);
|
||||
|
||||
/**
|
||||
* \brief This function is API for stopping the low resolution tick timer
|
||||
*
|
||||
* \return -1 for failure, success otherwise
|
||||
*/
|
||||
extern int8_t platform_tick_timer_stop(void);
|
||||
|
||||
#endif // NS_EVENTLOOP_USE_TICK_TIMER
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ARM_HAL_TIMER_H_ */
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef EVENTLOOP_CONFIG_H_
|
||||
#define EVENTLOOP_CONFIG_H_
|
||||
|
||||
/*
|
||||
* Options can be picked up from mbed-cli JSON configuration or from
|
||||
* a user configuration file - see below.
|
||||
*
|
||||
* Undefine all internal flags before evaluating the configuration.
|
||||
*/
|
||||
|
||||
/* Use platform-provided low-resolution tick timer for eventloop (requires "platform_tick_timer" API) */
|
||||
#undef NS_EVENTLOOP_USE_TICK_TIMER
|
||||
/* Exclude high resolution timer from build (removes need for "platform_timer" API) */
|
||||
#undef NS_EXCLUDE_HIGHRES_TIMER
|
||||
|
||||
/*
|
||||
* mbedOS 5 specific configuration flag mapping to internal flags
|
||||
*/
|
||||
#ifdef MBED_CONF_NANOSTACK_EVENTLOOP_USE_PLATFORM_TICK_TIMER
|
||||
#define NS_EVENTLOOP_USE_TICK_TIMER 1
|
||||
#endif
|
||||
|
||||
#ifdef MBED_CONF_NANOSTACK_EVENTLOOP_EXCLUDE_HIGHRES_TIMER
|
||||
#define NS_EXCLUDE_HIGHRES_TIMER 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Include the user config file if defined
|
||||
*/
|
||||
#ifdef NS_EVENTLOOP_USER_CONFIG_FILE
|
||||
#include NS_EVENTLOOP_USER_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#endif /* EVENTLOOP_CONFIG_H_ */
|
||||
Reference in New Issue
Block a user