Import Mbed OS hard-float snapshot
This commit is contained in:
74
connectivity/nfc/libraries/stack/platform/nfc_debug.h
Normal file
74
connectivity/nfc/libraries/stack/platform/nfc_debug.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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 MBED_NFC_DEBUG_H
|
||||
#define MBED_NFC_DEBUG_H
|
||||
|
||||
#if NFC_DEBUG && !defined(NDEBUG) && __DEBUG__
|
||||
#ifdef __MODULE__
|
||||
#define __NFC_MODULE__ __MODULE__
|
||||
#else
|
||||
#define __NFC_MODULE__ __FILE__
|
||||
#endif
|
||||
|
||||
#include "stdio.h"
|
||||
#include "stdarg.h"
|
||||
static inline void nfc_dbg_print(const char *type, const char *module, unsigned int line, const char *fmt, ...)
|
||||
{
|
||||
#if !defined(NDEBUG)
|
||||
printf("NFC [%s] %s:%u ", type, module, line);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
printf("\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(NFC_DBG)
|
||||
#define NFC_DBG(...) nfc_dbg_print("DBG", __NFC_MODULE__, __LINE__, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if !defined(NFC_WARN)
|
||||
#define NFC_WARN(...) nfc_dbg_print("WARN", __NFC_MODULE__, __LINE__, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if !defined(NFC_ERR)
|
||||
#define NFC_ERR(...) nfc_dbg_print("ERR", __NFC_MODULE__, __LINE__, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#define NFC_DBG_BLOCK(x) x
|
||||
|
||||
#else
|
||||
|
||||
#if !defined(NFC_DBG)
|
||||
#define NFC_DBG(...)
|
||||
#endif
|
||||
|
||||
#if !defined(NFC_WARN)
|
||||
#define NFC_WARN(...)
|
||||
#endif
|
||||
|
||||
#if !defined(NFC_ERR)
|
||||
#define NFC_ERR(...)
|
||||
#endif
|
||||
|
||||
#define NFC_DBG_BLOCK(x)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
186
connectivity/nfc/libraries/stack/platform/nfc_scheduler.c
Normal file
186
connectivity/nfc/libraries/stack/platform/nfc_scheduler.c
Normal file
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2018, 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.
|
||||
*/
|
||||
/**
|
||||
* \file nfc_scheduler.c
|
||||
* \copyright Copyright (c) ARM Ltd 2015
|
||||
* \author Donatien Garnier
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define __DEBUG__ 0
|
||||
#ifndef __MODULE__
|
||||
#define __MODULE__ "nfc_scheduler.c"
|
||||
#endif
|
||||
|
||||
#include "platform/nfc_scheduler.h"
|
||||
|
||||
void nfc_scheduler_init(nfc_scheduler_t *pScheduler, nfc_scheduler_timer_t *pTimer)
|
||||
{
|
||||
pScheduler->pNext = NULL;
|
||||
pScheduler->pTimer = pTimer;
|
||||
|
||||
//Start timer
|
||||
nfc_scheduler_timer_start(pTimer);
|
||||
}
|
||||
|
||||
#define MAX_TIMEOUT UINT32_MAX
|
||||
|
||||
uint32_t nfc_scheduler_iteration(nfc_scheduler_t *pScheduler, uint32_t events)
|
||||
{
|
||||
while (true) {
|
||||
nfc_task_t *pPrioTask = NULL;
|
||||
nfc_task_t *pPrioTaskPrevious = NULL;
|
||||
uint32_t prioTaskEvent = 0;
|
||||
int64_t timeout;
|
||||
nfc_task_t *pPreviousTask = NULL;
|
||||
nfc_task_t *pTask = pScheduler->pNext;
|
||||
|
||||
if (pTask == NULL) {
|
||||
NFC_DBG("Empty queue, %lu ms elapsed", nfc_scheduler_timer_get(pScheduler->pTimer));
|
||||
//Empty queue, return
|
||||
return MAX_TIMEOUT;
|
||||
}
|
||||
|
||||
//Get timer value
|
||||
uint32_t timeElapsed = nfc_scheduler_timer_get(pScheduler->pTimer);
|
||||
NFC_DBG("%lu ms elapsed", timeElapsed);
|
||||
nfc_scheduler_timer_reset(pScheduler->pTimer);
|
||||
|
||||
do {
|
||||
//Apply timeouts
|
||||
if (pTask->events & EVENT_TIMEOUT) {
|
||||
pTask->timeout -= timeElapsed;
|
||||
}
|
||||
pPreviousTask = pTask;
|
||||
pTask = pTask->pNext;
|
||||
} while (pTask != NULL);
|
||||
|
||||
pTask = pScheduler->pNext;
|
||||
pPreviousTask = NULL;
|
||||
timeout = MAX_TIMEOUT;
|
||||
do {
|
||||
//Check which task should be woken up first
|
||||
if ((events & EVENT_HW_INTERRUPT) && (pTask->events & EVENT_HW_INTERRUPT)) {
|
||||
//Hardware interrupts have prio
|
||||
pPrioTask = pTask;
|
||||
pPrioTaskPrevious = pPreviousTask;
|
||||
timeout = 0;
|
||||
events &= ~EVENT_HW_INTERRUPT; //Only one task gets triggered per event
|
||||
prioTaskEvent = EVENT_HW_INTERRUPT;
|
||||
break;
|
||||
} else if ((pTask->events & EVENT_TIMEOUT) && (pTask->timeout < timeout)) {
|
||||
pPrioTask = pTask;
|
||||
pPrioTaskPrevious = pPreviousTask;
|
||||
timeout = pTask->timeout;
|
||||
prioTaskEvent = EVENT_TIMEOUT;
|
||||
}
|
||||
pPreviousTask = pTask;
|
||||
pTask = pTask->pNext;
|
||||
} while (pTask != NULL);
|
||||
|
||||
if (pPrioTask == NULL) {
|
||||
//No task to wake up, exit
|
||||
NFC_DBG("No task to wake up");
|
||||
return MAX_TIMEOUT;
|
||||
}
|
||||
|
||||
if (timeout > 0) {
|
||||
//No task to wake up yet
|
||||
if (timeout > MAX_TIMEOUT) {
|
||||
NFC_DBG("No task to wake up");
|
||||
return MAX_TIMEOUT;
|
||||
} else {
|
||||
NFC_DBG("No task to wake up, wait %lu ms", timeout);
|
||||
return timeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Dequeue task
|
||||
if (pPrioTaskPrevious == NULL) {
|
||||
pScheduler->pNext = pPrioTask->pNext;
|
||||
} else {
|
||||
pPrioTaskPrevious->pNext = pPrioTask->pNext;
|
||||
}
|
||||
pPrioTask->pNext = NULL;
|
||||
|
||||
//Execute task
|
||||
NFC_DBG("Calling task %p - events %02X", pPrioTask, prioTaskEvent);
|
||||
pPrioTask->fn(prioTaskEvent, pPrioTask->pUserData);
|
||||
events &= ~EVENT_HW_INTERRUPT; //Only one task gets triggered per event
|
||||
}
|
||||
return MAX_TIMEOUT;
|
||||
}
|
||||
|
||||
void nfc_scheduler_queue_task(nfc_scheduler_t *pScheduler, nfc_task_t *pTask)
|
||||
{
|
||||
pTask->timeout = pTask->timeoutInitial + nfc_scheduler_timer_get(pScheduler->pTimer);
|
||||
NFC_DBG("Queuing task %p: events %1X, timeout %lu ms", pTask, pTask->events, pTask->timeout);
|
||||
//Find last task
|
||||
nfc_task_t *pPrevTask = pScheduler->pNext;
|
||||
pTask->pNext = NULL;
|
||||
if (pPrevTask == NULL) {
|
||||
pScheduler->pNext = pTask;
|
||||
return;
|
||||
}
|
||||
while (pPrevTask->pNext != NULL) {
|
||||
pPrevTask = pPrevTask->pNext;
|
||||
}
|
||||
pPrevTask->pNext = pTask;
|
||||
}
|
||||
|
||||
void nfc_scheduler_dequeue_task(nfc_scheduler_t *pScheduler, bool abort, nfc_task_t *pTask)
|
||||
{
|
||||
NFC_DBG("Dequeuing task %p", pTask);
|
||||
//Find task
|
||||
nfc_task_t *pPrevTask = pScheduler->pNext;
|
||||
if (pPrevTask == NULL) {
|
||||
pTask->pNext = NULL;
|
||||
return;
|
||||
}
|
||||
if (pPrevTask == pTask) {
|
||||
if (abort) {
|
||||
pTask->fn(EVENT_ABORTED, pTask->pUserData);
|
||||
}
|
||||
pScheduler->pNext = pTask->pNext;
|
||||
pTask->pNext = NULL;
|
||||
return;
|
||||
}
|
||||
while (pPrevTask->pNext != NULL) {
|
||||
if (pPrevTask->pNext == pTask) {
|
||||
if (abort) {
|
||||
pTask->fn(EVENT_ABORTED, pTask->pUserData);
|
||||
}
|
||||
pPrevTask->pNext = pTask->pNext;
|
||||
pTask->pNext = NULL;
|
||||
return;
|
||||
}
|
||||
pPrevTask = pPrevTask->pNext;
|
||||
}
|
||||
pTask->pNext = NULL;
|
||||
}
|
||||
|
||||
void task_init(nfc_task_t *pTask, uint32_t events, uint32_t timeout, nfc_task_fn fn, void *pUserData)
|
||||
{
|
||||
pTask->events = events;
|
||||
pTask->timeoutInitial = timeout;
|
||||
pTask->fn = fn;
|
||||
pTask->pUserData = pUserData;
|
||||
pTask->pNext = NULL;
|
||||
}
|
||||
122
connectivity/nfc/libraries/stack/platform/nfc_scheduler.h
Normal file
122
connectivity/nfc/libraries/stack/platform/nfc_scheduler.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2018, 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.
|
||||
*/
|
||||
/**
|
||||
* \file nfc_scheduler.h
|
||||
* \copyright Copyright (c) ARM Ltd 2014
|
||||
* \author Donatien Garnier
|
||||
*/
|
||||
/** \addtogroup Core
|
||||
* @{
|
||||
* \name Scheduler
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef NFC_SCHEDULER_H_
|
||||
#define NFC_SCHEDULER_H_
|
||||
|
||||
#include "stack/nfc_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define EVENT_NONE 0
|
||||
#define EVENT_TIMEOUT 1
|
||||
#define EVENT_ABORTED 2
|
||||
#define EVENT_HW_INTERRUPT 4
|
||||
|
||||
struct __nfc_timer;
|
||||
typedef struct __nfc_timer nfc_scheduler_timer_t;
|
||||
|
||||
struct __nfc_task;
|
||||
typedef struct __nfc_task nfc_task_t;
|
||||
|
||||
typedef struct __scheduler {
|
||||
nfc_task_t *pNext;
|
||||
nfc_scheduler_timer_t *pTimer;
|
||||
} nfc_scheduler_t;
|
||||
|
||||
typedef void (*nfc_task_fn)(uint32_t events, void *pUserData);
|
||||
|
||||
struct __nfc_task {
|
||||
uint32_t events;
|
||||
int64_t timeout; //millisecs
|
||||
int64_t timeoutInitial;
|
||||
|
||||
nfc_task_fn fn;
|
||||
void *pUserData;
|
||||
|
||||
nfc_task_t *pNext;
|
||||
};
|
||||
|
||||
void nfc_scheduler_timer_init(nfc_scheduler_timer_t *timer);
|
||||
|
||||
void nfc_scheduler_timer_start(nfc_scheduler_timer_t *timer);
|
||||
|
||||
uint32_t nfc_scheduler_timer_get(nfc_scheduler_timer_t *timer);
|
||||
|
||||
void nfc_scheduler_timer_stop(nfc_scheduler_timer_t *timer);
|
||||
|
||||
void nfc_scheduler_timer_reset(nfc_scheduler_timer_t *timer);
|
||||
|
||||
/** Init scheduler
|
||||
* \param pScheduler scheduler instance to init
|
||||
* \param pTimer timer instance
|
||||
*/
|
||||
void nfc_scheduler_init(nfc_scheduler_t *pScheduler, nfc_scheduler_timer_t *pTimer);
|
||||
|
||||
/** Iterate through all tasks
|
||||
* \param pScheduler scheduler instance
|
||||
* \param events mask of events (except EVENT_TIMEOUT) that have been raised since this function last returned (0 on first call)
|
||||
* \return time after which this function must be called again if no other event arises
|
||||
*/
|
||||
uint32_t nfc_scheduler_iteration(nfc_scheduler_t *pScheduler, uint32_t events);
|
||||
|
||||
/** Queue a task to execute
|
||||
* \param pScheduler scheduler instance
|
||||
* \param pTask task to queue
|
||||
*
|
||||
*/
|
||||
void nfc_scheduler_queue_task(nfc_scheduler_t *pScheduler, nfc_task_t *pTask);
|
||||
|
||||
/** Remove a task to execute
|
||||
* \param pScheduler scheduler instance
|
||||
* \param pTask task to remove
|
||||
* \param abort abort task if queued
|
||||
*/
|
||||
void nfc_scheduler_dequeue_task(nfc_scheduler_t *pScheduler, bool abort, nfc_task_t *pTask);
|
||||
|
||||
/** Initialize task with the following parameters
|
||||
* \param pTask task to initialize
|
||||
* \param events events on which to call task
|
||||
* \param timeout if relevant
|
||||
* \param fn function to be called
|
||||
* \param pUserData data that will be passed to function
|
||||
*/
|
||||
void task_init(nfc_task_t *pTask, uint32_t events, uint32_t timeout, nfc_task_fn fn, void *pUserData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NFC_SCHEDULER_H_ */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* */
|
||||
|
||||
53
connectivity/nfc/libraries/stack/platform/nfc_transport.c
Normal file
53
connectivity/nfc/libraries/stack/platform/nfc_transport.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2018, 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.
|
||||
*/
|
||||
/**
|
||||
* \file nfc_transport.c
|
||||
* \copyright Copyright (c) ARM Ltd 2013-2018
|
||||
* \author Donatien Garnier
|
||||
* \details Transport layer
|
||||
*/
|
||||
|
||||
/** \addtogroup Implementation
|
||||
* @{
|
||||
* \name Transport
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stack/nfc_errors.h"
|
||||
#include "nfc_transport.h"
|
||||
|
||||
/** Initialize transport with a specific implementation
|
||||
* \param pTransport pointer to a nfc_transport_t structure to initialize
|
||||
* \param write transport write function
|
||||
* \param read transport read function
|
||||
* \param pUser parameter that will be passed to any of the above functions
|
||||
*/
|
||||
void nfc_transport_init(nfc_transport_t *pTransport, nfc_transport_write_fn_t write, nfc_transport_read_fn_t read, void *pUser)
|
||||
{
|
||||
pTransport->write = write;
|
||||
pTransport->read = read;
|
||||
pTransport->pUser = pUser;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* */
|
||||
|
||||
84
connectivity/nfc/libraries/stack/platform/nfc_transport.h
Normal file
84
connectivity/nfc/libraries/stack/platform/nfc_transport.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2018, 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.
|
||||
*/
|
||||
/**
|
||||
* \file nfc_transport.h
|
||||
* \copyright Copyright (c) ARM Ltd 2013-2018
|
||||
* \author Donatien Garnier
|
||||
*/
|
||||
|
||||
/** \addtogroup Implementation
|
||||
* @{
|
||||
* \name Transport
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef NFC_TRANSPORT_H_
|
||||
#define NFC_TRANSPORT_H_
|
||||
|
||||
#include "stack/nfc_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** Function called to write a register's value
|
||||
* \param address address of the register to write to
|
||||
* \param outBuf buffer to write
|
||||
* \param outLen buffer's length
|
||||
* \param pUser parameter passed to the nfc_transport_init function
|
||||
*/
|
||||
typedef void (*nfc_transport_write_fn_t)(uint8_t address, const uint8_t *outBuf, size_t outLen, void *pUser);
|
||||
|
||||
/** Function called to read a register's value
|
||||
* \param address address to read packet from
|
||||
* \param outBuf buffer to read
|
||||
* \param outLen buffer's length
|
||||
* \param pUser parameter passed to the nfc_transport_init function
|
||||
*/
|
||||
typedef void (*nfc_transport_read_fn_t)(uint8_t address, uint8_t *inBuf, size_t inLen, void *pUser);
|
||||
|
||||
typedef struct __transport {
|
||||
nfc_transport_write_fn_t write;
|
||||
nfc_transport_read_fn_t read;
|
||||
void *pUser;
|
||||
} nfc_transport_t;
|
||||
|
||||
void nfc_transport_init(nfc_transport_t *pTransport, nfc_transport_write_fn_t write, nfc_transport_read_fn_t read, void *pUser);
|
||||
|
||||
static inline void nfc_transport_write(nfc_transport_t *pTransport, uint8_t address, const uint8_t *outBuf, size_t outLen)
|
||||
{
|
||||
pTransport->write(address, outBuf, outLen, pTransport->pUser);
|
||||
}
|
||||
|
||||
static inline void nfc_transport_read(nfc_transport_t *pTransport, uint8_t address, uint8_t *inBuf, size_t inLen)
|
||||
{
|
||||
pTransport->read(address, inBuf, inLen, pTransport->pUser);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NFC_TRANSPORT_H_ */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* */
|
||||
|
||||
Reference in New Issue
Block a user