Add KSDK and readme.
This commit is contained in:
1763
devices/MK22F51212/utilities/fsl_debug_console.c
Normal file
1763
devices/MK22F51212/utilities/fsl_debug_console.c
Normal file
File diff suppressed because it is too large
Load Diff
189
devices/MK22F51212/utilities/fsl_debug_console.h
Normal file
189
devices/MK22F51212/utilities/fsl_debug_console.h
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Debug console shall provide input and output functions to scan and print formatted data.
|
||||
* o Support a format specifier for PRINTF follows this prototype "%[flags][width][.precision][length]specifier"
|
||||
* - [flags] :'-', '+', '#', ' ', '0'
|
||||
* - [width]: number (0,1...)
|
||||
* - [.precision]: number (0,1...)
|
||||
* - [length]: do not support
|
||||
* - [specifier]: 'd', 'i', 'f', 'F', 'x', 'X', 'o', 'p', 'u', 'c', 's', 'n'
|
||||
* o Support a format specifier for SCANF follows this prototype " %[*][width][length]specifier"
|
||||
* - [*]: is supported.
|
||||
* - [width]: number (0,1...)
|
||||
* - [length]: 'h', 'hh', 'l','ll','L'. ignore ('j','z','t')
|
||||
* - [specifier]: 'd', 'i', 'u', 'f', 'F', 'e', 'E', 'g', 'G', 'a', 'A', 'o', 'c', 's'
|
||||
*/
|
||||
|
||||
#ifndef _FSL_DEBUGCONSOLE_H_
|
||||
#define _FSL_DEBUGCONSOLE_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*
|
||||
* @addtogroup debug_console
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Definition to select sdk or toolchain printf, scanf. */
|
||||
#ifndef SDK_DEBUGCONSOLE
|
||||
#define SDK_DEBUGCONSOLE 1U
|
||||
#endif
|
||||
|
||||
/*! @brief Definition to printf float number. */
|
||||
#ifndef PRINTF_FLOAT_ENABLE
|
||||
#define PRINTF_FLOAT_ENABLE 1U
|
||||
#endif /* PRINTF_FLOAT_ENABLE */
|
||||
|
||||
/*! @brief Definition to scanf float number. */
|
||||
#ifndef SCANF_FLOAT_ENABLE
|
||||
#define SCANF_FLOAT_ENABLE 1U
|
||||
#endif /* SCANF_FLOAT_ENABLE */
|
||||
|
||||
/*! @brief Definition to support advanced format specifier for printf. */
|
||||
#ifndef PRINTF_ADVANCED_ENABLE
|
||||
#define PRINTF_ADVANCED_ENABLE 1U
|
||||
#endif /* PRINTF_ADVANCED_ENABLE */
|
||||
|
||||
/*! @brief Definition to support advanced format specifier for scanf. */
|
||||
#ifndef SCANF_ADVANCED_ENABLE
|
||||
#define SCANF_ADVANCED_ENABLE 1U
|
||||
#endif /* SCANF_ADVANCED_ENABLE */
|
||||
|
||||
#if SDK_DEBUGCONSOLE /* Select printf, scanf, putchar, getchar of SDK version. */
|
||||
#define PRINTF DbgConsole_Printf
|
||||
#define SCANF DbgConsole_Scanf
|
||||
#define PUTCHAR DbgConsole_Putchar
|
||||
#define GETCHAR DbgConsole_Getchar
|
||||
#else /* Select printf, scanf, putchar, getchar of toolchain. */
|
||||
#define PRINTF printf
|
||||
#define SCANF scanf
|
||||
#define PUTCHAR putchar
|
||||
#define GETCHAR getchar
|
||||
#endif /* SDK_DEBUGCONSOLE */
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @name Initialization*/
|
||||
/* @{ */
|
||||
|
||||
/*!
|
||||
* @brief Initialize the the peripheral used for debug messages.
|
||||
*
|
||||
* Call this function to enable debug log messages to be output via the specified peripheral,
|
||||
* frequency of peripheral source clock, base address at the specified baud rate.
|
||||
* After this function has returned, stdout and stdin will be connected to the selected peripheral.
|
||||
*
|
||||
* @param baseAddr Which address of peripheral is used to send debug messages.
|
||||
* @param baudRate The desired baud rate in bits per second.
|
||||
* @param device Low level device type for the debug console, could be one of:
|
||||
* @arg DEBUG_CONSOLE_DEVICE_TYPE_UART,
|
||||
* @arg DEBUG_CONSOLE_DEVICE_TYPE_LPUART,
|
||||
* @arg DEBUG_CONSOLE_DEVICE_TYPE_LPSCI,
|
||||
* @arg DEBUG_CONSOLE_DEVICE_TYPE_USBCDC.
|
||||
* @param clkSrcFreq Frequency of peripheral source clock.
|
||||
*
|
||||
* @return Whether initialization was successful or not.
|
||||
* @retval kStatus_Success Execution successfully
|
||||
* @retval kStatus_Fail Execution failure
|
||||
* @retval kStatus_InvalidArgument Invalid argument existed
|
||||
*/
|
||||
status_t DbgConsole_Init(uint32_t baseAddr, uint32_t baudRate, uint8_t device, uint32_t clkSrcFreq);
|
||||
|
||||
/*!
|
||||
* @brief De-initialize the peripheral used for debug messages.
|
||||
*
|
||||
* Call this function to disable debug log messages to be output via the specified peripheral
|
||||
* base address and at the specified baud rate.
|
||||
*
|
||||
* @return Whether de-initialization was successful or not.
|
||||
*/
|
||||
status_t DbgConsole_Deinit(void);
|
||||
|
||||
#if SDK_DEBUGCONSOLE
|
||||
/*!
|
||||
* @brief Writes formatted output to the standard output stream.
|
||||
*
|
||||
* Call this function to Writes formatted output to the standard output stream.
|
||||
*
|
||||
* @param fmt_s Format control string.
|
||||
* @return Returns the number of characters printed, or a negative value if an error occurs.
|
||||
*/
|
||||
int DbgConsole_Printf(char *fmt_s, ...);
|
||||
|
||||
/*!
|
||||
* @brief Writes a character to stdout.
|
||||
*
|
||||
* Call this function to write a character to stdout.
|
||||
*
|
||||
* @param ch Character to be written.
|
||||
* @return Returns the character written.
|
||||
*/
|
||||
int DbgConsole_Putchar(int ch);
|
||||
|
||||
/*!
|
||||
* @brief Reads formatted data from the standard input stream.
|
||||
*
|
||||
* Call this function to read formatted data from the standard input stream.
|
||||
*
|
||||
* @param fmt_ptr Format control string.
|
||||
* @return Returns the number of fields successfully converted and assigned.
|
||||
*/
|
||||
int DbgConsole_Scanf(char *fmt_ptr, ...);
|
||||
|
||||
/*!
|
||||
* @brief Reads a character from standard input.
|
||||
*
|
||||
* Call this function to read a character from standard input.
|
||||
*
|
||||
* @return Returns the character read.
|
||||
*/
|
||||
int DbgConsole_Getchar(void);
|
||||
|
||||
#endif /* SDK_DEBUGCONSOLE */
|
||||
|
||||
/*! @} */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif /* _FSL_DEBUGCONSOLE_H_ */
|
||||
182
devices/MK22F51212/utilities/fsl_notifier.c
Normal file
182
devices/MK22F51212/utilities/fsl_notifier.c
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_notifier.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
status_t NOTIFIER_CreateHandle(notifier_handle_t *notifierHandle,
|
||||
notifier_user_config_t **configs,
|
||||
uint8_t configsNumber,
|
||||
notifier_callback_config_t *callbacks,
|
||||
uint8_t callbacksNumber,
|
||||
notifier_user_function_t userFunction,
|
||||
void *userData)
|
||||
{
|
||||
/* Check input parameter - at least one configuration is required and userFunction must exist */
|
||||
if ((configs == NULL) || (configsNumber == 0U) || (userFunction == NULL))
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
/* Initialize handle structure */
|
||||
memset(notifierHandle, 0, sizeof(notifier_handle_t));
|
||||
/* Store references to user-defined configurations */
|
||||
notifierHandle->configsTable = configs;
|
||||
notifierHandle->configsNumber = configsNumber;
|
||||
/* Store references to user-defined callback configurations */
|
||||
if (callbacks != NULL)
|
||||
{
|
||||
notifierHandle->callbacksTable = callbacks;
|
||||
notifierHandle->callbacksNumber = callbacksNumber;
|
||||
/* If all callbacks return success, then the errorCallbackIndex is callbacksNumber */
|
||||
notifierHandle->errorCallbackIndex = callbacksNumber;
|
||||
}
|
||||
notifierHandle->userFunction = userFunction;
|
||||
notifierHandle->userData = userData;
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t NOTIFIER_SwitchConfig(notifier_handle_t *notifierHandle, uint8_t configIndex, notifier_policy_t policy)
|
||||
{
|
||||
uint8_t currentStaticCallback = 0U; /* Index to array of statically registered call-backs */
|
||||
status_t returnCode = kStatus_Success; /* Function return */
|
||||
|
||||
notifier_notification_block_t notifyBlock; /* Callback notification block */
|
||||
notifier_callback_config_t *callbackConfig; /* Pointer to callback configuration */
|
||||
|
||||
/* Set errorcallbackindex as callbacksNumber, which means no callback error now */
|
||||
notifierHandle->errorCallbackIndex = notifierHandle->callbacksNumber;
|
||||
|
||||
/* Requested configuration availability check */
|
||||
if (configIndex >= notifierHandle->configsNumber)
|
||||
{
|
||||
return kStatus_OutOfRange;
|
||||
}
|
||||
|
||||
/* Initialization of local variables from the Notifier handle structure */
|
||||
|
||||
notifyBlock.policy = policy;
|
||||
notifyBlock.targetConfig = notifierHandle->configsTable[configIndex];
|
||||
notifyBlock.notifyType = kNOTIFIER_NotifyBefore;
|
||||
|
||||
/* From all statically registered call-backs... */
|
||||
for (currentStaticCallback = 0U; currentStaticCallback < notifierHandle->callbacksNumber; currentStaticCallback++)
|
||||
{
|
||||
callbackConfig = &(notifierHandle->callbacksTable[currentStaticCallback]);
|
||||
/* ...notify only those which asked to be called before the configuration switch */
|
||||
if (((uint32_t)callbackConfig->callbackType) & kNOTIFIER_CallbackBefore)
|
||||
{
|
||||
/* In case that call-back returned error code mark it, store the call-back handle and eventually cancel
|
||||
* the configuration switch */
|
||||
if (callbackConfig->callback(¬ifyBlock, callbackConfig->callbackData) != kStatus_Success)
|
||||
{
|
||||
returnCode = kStatus_NOTIFIER_ErrorNotificationBefore;
|
||||
notifierHandle->errorCallbackIndex = currentStaticCallback;
|
||||
/* If not forcing configuration switch, call all already notified call-backs to revert their state
|
||||
* as the switch is canceled */
|
||||
if (policy != kNOTIFIER_PolicyForcible)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set configuration */
|
||||
|
||||
/* In case that any call-back returned error code and policy doesn't force the configuration set, go to after
|
||||
* switch call-backs */
|
||||
if ((policy == kNOTIFIER_PolicyForcible) || (returnCode == kStatus_Success))
|
||||
{
|
||||
returnCode = notifierHandle->userFunction(notifierHandle->configsTable[configIndex], notifierHandle->userData);
|
||||
if (returnCode != kStatus_Success)
|
||||
{
|
||||
return returnCode;
|
||||
}
|
||||
/* Update current configuration index */
|
||||
notifierHandle->currentConfigIndex = configIndex;
|
||||
notifyBlock.notifyType = kNOTIFIER_NotifyAfter;
|
||||
/* From all statically registered call-backs... */
|
||||
for (currentStaticCallback = 0U; currentStaticCallback < notifierHandle->callbacksNumber;
|
||||
currentStaticCallback++)
|
||||
{
|
||||
callbackConfig = &(notifierHandle->callbacksTable[currentStaticCallback]);
|
||||
/* ...notify only those which asked to be called after the configruation switch */
|
||||
if (((uint32_t)callbackConfig->callbackType) & kNOTIFIER_CallbackAfter)
|
||||
{
|
||||
/* In case that call-back returned error code mark it and store the call-back handle */
|
||||
if (callbackConfig->callback(¬ifyBlock, callbackConfig->callbackData) != kStatus_Success)
|
||||
{
|
||||
returnCode = kStatus_NOTIFIER_ErrorNotificationAfter;
|
||||
notifierHandle->errorCallbackIndex = currentStaticCallback;
|
||||
if (policy != kNOTIFIER_PolicyForcible)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* End of unsuccessful switch */
|
||||
notifyBlock.notifyType = kNOTIFIER_NotifyRecover;
|
||||
while (currentStaticCallback--)
|
||||
{
|
||||
callbackConfig = &(notifierHandle->callbacksTable[currentStaticCallback]);
|
||||
if (((uint32_t)callbackConfig->callbackType) & kNOTIFIER_CallbackBefore)
|
||||
{
|
||||
callbackConfig->callback(¬ifyBlock, callbackConfig->callbackData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
uint8_t NOTIFIER_GetErrorCallbackIndex(notifier_handle_t *notifierHandle)
|
||||
{
|
||||
return notifierHandle->errorCallbackIndex;
|
||||
}
|
||||
259
devices/MK22F51212/utilities/fsl_notifier.h
Normal file
259
devices/MK22F51212/utilities/fsl_notifier.h
Normal file
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_NOTIFIER_H_
|
||||
#define _FSL_NOTIFIER_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
/*!
|
||||
* @addtogroup notifier
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Notifier error codes.
|
||||
*
|
||||
* Used as return value of Notifier functions.
|
||||
*/
|
||||
enum _notifier_status
|
||||
{
|
||||
kStatus_NOTIFIER_ErrorNotificationBefore =
|
||||
MAKE_STATUS(kStatusGroup_NOTIFIER, 0), /*!< Error occurs during send "BEFORE" notification. */
|
||||
kStatus_NOTIFIER_ErrorNotificationAfter =
|
||||
MAKE_STATUS(kStatusGroup_NOTIFIER, 1), /*!< Error occurs during send "AFTER" notification. */
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Notifier policies.
|
||||
*
|
||||
* Defines whether user function execution is forced or not.
|
||||
* For kNOTIFIER_PolicyForcible, the user function is executed regardless of the callback results,
|
||||
* while kNOTIFIER_PolicyAgreement policy is used to exit NOTIFIER_SwitchConfig()
|
||||
* when any of the callbacks returns error code.
|
||||
* See also NOTIFIER_SwitchConfig() description.
|
||||
*/
|
||||
typedef enum _notifier_policy
|
||||
{
|
||||
kNOTIFIER_PolicyAgreement, /*!< NOTIFIER_SwitchConfig() method is exited when any of the callbacks returns error
|
||||
code. */
|
||||
kNOTIFIER_PolicyForcible, /*!< user function is executed regardless of the results. */
|
||||
} notifier_policy_t;
|
||||
|
||||
/*! @brief Notification type. Used to notify registered callbacks */
|
||||
typedef enum _notifier_notification_type
|
||||
{
|
||||
kNOTIFIER_NotifyRecover = 0x00U, /*!< Notify IP to recover to previous work state. */
|
||||
kNOTIFIER_NotifyBefore = 0x01U, /*!< Notify IP that configuration setting is going to change. */
|
||||
kNOTIFIER_NotifyAfter = 0x02U, /*!< Notify IP that configuration setting has been changed. */
|
||||
} notifier_notification_type_t;
|
||||
|
||||
/*!
|
||||
* @brief The callback type, indicates what kinds of notification the callback handles.
|
||||
*
|
||||
* Used in the callback configuration structure (notifier_callback_config_t)
|
||||
* to specify when the registered callback is called during configuration switch initiated by
|
||||
* NOTIFIER_SwitchConfig().
|
||||
* Callback can be invoked in following situations:
|
||||
* - before the configuration switch (Callback return value can affect NOTIFIER_SwitchConfig()
|
||||
* execution. Refer to the NOTIFIER_SwitchConfig() and notifier_policy_t documentation).
|
||||
* - after unsuccessful attempt to switch configuration
|
||||
* - after sucecessful configuration switch
|
||||
*/
|
||||
typedef enum _notifier_callback_type
|
||||
{
|
||||
kNOTIFIER_CallbackBefore = 0x01U, /*!< Callback handles BEFORE notification. */
|
||||
kNOTIFIER_CallbackAfter = 0x02U, /*!< Callback handles AFTER notification. */
|
||||
kNOTIFIER_CallbackBeforeAfter = 0x03U, /*!< Callback handles BEFORE and AFTER notification. */
|
||||
} notifier_callback_type_t;
|
||||
|
||||
/*! @brief notifier user configuration type.
|
||||
*
|
||||
* Reference of user defined configuration is stored in an array, notifer switch between these configurations
|
||||
* based on this array.
|
||||
*/
|
||||
typedef void notifier_user_config_t;
|
||||
|
||||
/*! @brief notifier user function prototype
|
||||
* User can use this function to execute specific operations in configuration switch.
|
||||
* Before and after this function execution, different notification will be sent to registered callbacks.
|
||||
* If this function returns any error code, NOTIFIER_SwitchConfig() will exit.
|
||||
*
|
||||
* @param targetConfig target Configuration.
|
||||
* @param userData Refers to other specific data passed to user function.
|
||||
* @return An error code or kStatus_Success.
|
||||
*/
|
||||
typedef status_t (*notifier_user_function_t)(notifier_user_config_t *targetConfig, void *userData);
|
||||
|
||||
/*! @brief notification block passed to the registered callback function. */
|
||||
typedef struct _notifier_notification_block
|
||||
{
|
||||
notifier_user_config_t *targetConfig; /*!< Pointer to target configuration. */
|
||||
notifier_policy_t policy; /*!< Configure transition policy. */
|
||||
notifier_notification_type_t notifyType; /*!< Configure notification type. */
|
||||
} notifier_notification_block_t;
|
||||
|
||||
/*!
|
||||
* @brief Callback prototype.
|
||||
*
|
||||
* Declaration of callback. It is common for registered callbacks.
|
||||
* Reference to function of this type is part of notifier_callback_config_t callback configuration structure.
|
||||
* Depending on callback type, function of this prototype is called (see NOTIFIER_SwitchConfig())
|
||||
* before configuration switch, after it or in both cases to notify about
|
||||
* the switch progress (see notifier_callback_type_t). When called, type of the notification
|
||||
* is passed as parameter along with reference to the target configuration structure (see notifier_notification_block_t)
|
||||
* and any data passed during the callback registration.
|
||||
* When notified before configuration switch, depending on the configuration switch policy (see
|
||||
* notifier_policy_t) the callback may deny the execution of user function by returning any error code different
|
||||
* from kStatus_Success (see NOTIFIER_SwitchConfig()).
|
||||
*
|
||||
* @param notify Notification block.
|
||||
* @param data Callback data. Refers to the data passed during callback registration. Intended to
|
||||
* pass any driver or application data such as internal state information.
|
||||
* @return An error code or kStatus_Success.
|
||||
*/
|
||||
typedef status_t (*notifier_callback_t)(notifier_notification_block_t *notify, void *data);
|
||||
|
||||
/*!
|
||||
* @brief callback configuration structure
|
||||
*
|
||||
* This structure holds configuration of callbacks.
|
||||
* Callbacks of this type are expected to be statically allocated.
|
||||
* This structure contains following application-defined data:
|
||||
* callback - pointer to the callback function
|
||||
* callbackType - specifies when the callback is called
|
||||
* callbackData - pointer to the data passed to the callback.
|
||||
*/
|
||||
typedef struct _notifier_callback_config
|
||||
{
|
||||
notifier_callback_t callback; /*!< Pointer to the callback function. */
|
||||
notifier_callback_type_t callbackType; /*!< Callback type. */
|
||||
void *callbackData; /*!< Pointer to the data passed to the callback. */
|
||||
} notifier_callback_config_t;
|
||||
|
||||
/*!
|
||||
* @brief Notifier handle structure.
|
||||
*
|
||||
* Notifier handle structure. Contains data necessary for Notifier proper function.
|
||||
* Stores references to registered configurations, callbacks, information about their numbers,
|
||||
* user function, user data and other internal data.
|
||||
* NOTIFIER_CreateHandle() must be called to intialize this handle.
|
||||
*/
|
||||
typedef struct _notifier_handle
|
||||
{
|
||||
notifier_user_config_t **configsTable; /*!< Pointer to configure table. */
|
||||
uint8_t configsNumber; /*!< Number of configurations. */
|
||||
notifier_callback_config_t *callbacksTable; /*!< Pointer to callback table. */
|
||||
uint8_t callbacksNumber; /*!< Maximum number of callback configurations. */
|
||||
uint8_t errorCallbackIndex; /*!< Index of callback returns error. */
|
||||
uint8_t currentConfigIndex; /*!< Index of current configuration. */
|
||||
notifier_user_function_t userFunction; /*!< user function. */
|
||||
void *userData; /*!< user data passed to user function. */
|
||||
} notifier_handle_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Create Notifier handle.
|
||||
*
|
||||
* @param notifierHandle A pointer to notifier handle
|
||||
* @param configs A pointer to an array with references to all configurations which is handled by the Notifier.
|
||||
* @param configsNumber Number of configurations. Size of configs array.
|
||||
* @param callbacks A pointer to an array of callback configurations.
|
||||
* If there are no callbacks to register during Notifier initialization, use NULL value.
|
||||
* @param callbacksNumber Number of registered callbacks. Size of callbacks array.
|
||||
* @param userFunction user function.
|
||||
* @param userData user data passed to user function.
|
||||
* @return An error code or kStatus_Success.
|
||||
*/
|
||||
status_t NOTIFIER_CreateHandle(notifier_handle_t *notifierHandle,
|
||||
notifier_user_config_t **configs,
|
||||
uint8_t configsNumber,
|
||||
notifier_callback_config_t *callbacks,
|
||||
uint8_t callbacksNumber,
|
||||
notifier_user_function_t userFunction,
|
||||
void *userData);
|
||||
|
||||
/*!
|
||||
* @brief Switch configuration according to a pre-defined structure.
|
||||
*
|
||||
* This function sets the system to the target configuration. Before transition,
|
||||
* the Notifier sends notifications to all callbacks registered to the callback table.
|
||||
* Callbacks are invoked in the following order: All registered callbacks are notified
|
||||
* ordered by index in the callbacks array. The same order is used for before and after switch notifications.
|
||||
* The notifications before the configuration switch can be used to obtain confirmation about
|
||||
* the change from registered callbacks. If any registered callback denies the
|
||||
* configuration change, further execution of this function depends on the notifier policy: the
|
||||
* configuration change is either forced (kNOTIFIER_PolicyForcible) or exited (kNOTIFIER_PolicyAgreement).
|
||||
* When configuration change is forced, the result of the before switch notifications are ignored. If
|
||||
* agreement is required, if any callback returns an error code then further notifications
|
||||
* before switch notifications are cancelled and all already notified callbacks are re-invoked
|
||||
* The index of the callback which returned error code during pre-switch notifications is stored
|
||||
* (any error codes during callbacks re-invocation are ignored) and NOTIFIER_GetErrorCallback() can be used to get it.
|
||||
* Regardless of the policies, if any callback returned an error code, an error code denoting in which phase
|
||||
* the error occurred is returned when NOTIFIER_SwitchConfig() exits.
|
||||
* @param notifierHandle pointer to notifier handle
|
||||
* @param configIndex Index of the target configuration.
|
||||
* @param policy Transaction policy, kNOTIFIER_PolicyAgreement or kNOTIFIER_PolicyForcible.
|
||||
*
|
||||
* @return An error code or kStatus_Success.
|
||||
*
|
||||
*/
|
||||
status_t NOTIFIER_SwitchConfig(notifier_handle_t *notifierHandle, uint8_t configIndex, notifier_policy_t policy);
|
||||
|
||||
/*!
|
||||
* @brief This function returns the last failed notification callback.
|
||||
*
|
||||
* This function returns index of the last callback that failed during the configuration switch while
|
||||
* the last NOTIFIER_SwitchConfig() was called. If the last NOTIFIER_SwitchConfig() call ended successfully
|
||||
* value equal to callbacks number is returned. Returned value represents index in the array of
|
||||
* static call-backs.
|
||||
*
|
||||
* @param notifierHandle pointer to notifier handle
|
||||
* @return Callback index of last failed callback or value equal to callbacks count.
|
||||
*/
|
||||
uint8_t NOTIFIER_GetErrorCallbackIndex(notifier_handle_t *notifierHandle);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_NOTIFIER_H_ */
|
||||
66
devices/MK22F51212/utilities/fsl_sbrk.c
Normal file
66
devices/MK22F51212/utilities/fsl_sbrk.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
/*!
|
||||
* @brief Function to override ARMGCC default function _sbrk
|
||||
*
|
||||
* _sbrk is called by malloc. ARMGCC default _sbrk compares "SP" register and
|
||||
* heap end, if heap end is larger than "SP", then _sbrk returns error and
|
||||
* memory allocation failed. This function changes to compare __HeapLimit with
|
||||
* heap end.
|
||||
*/
|
||||
caddr_t _sbrk(int incr)
|
||||
{
|
||||
extern char end __asm("end");
|
||||
extern char heap_limit __asm("__HeapLimit");
|
||||
static char *heap_end;
|
||||
char *prev_heap_end;
|
||||
|
||||
if (heap_end == NULL)
|
||||
heap_end = &end;
|
||||
|
||||
prev_heap_end = heap_end;
|
||||
|
||||
if (heap_end + incr > &heap_limit)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return (caddr_t)-1;
|
||||
}
|
||||
|
||||
heap_end += incr;
|
||||
|
||||
return (caddr_t)prev_heap_end;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user