@@ -3412,6 +3412,361 @@ const char * FreeRTOS_strerror_r( BaseType_t xErrnum,
34123412}
34133413/*-----------------------------------------------------------*/
34143414
3415+ /**
3416+ * @brief Get the highest value of two int32's.
3417+ * @param[in] a: the first value.
3418+ * @param[in] b: the second value.
3419+ * @return The highest of the two values.
3420+ */
3421+ int32_t FreeRTOS_max_int32 ( int32_t a ,
3422+ int32_t b )
3423+ {
3424+ return ( a >= b ) ? a : b ;
3425+ }
3426+ /*-----------------------------------------------------------*/
3427+
3428+ /**
3429+ * @brief Get the highest value of two uint32_t's.
3430+ * @param[in] a: the first value.
3431+ * @param[in] b: the second value.
3432+ * @return The highest of the two values.
3433+ */
3434+ uint32_t FreeRTOS_max_uint32 ( uint32_t a ,
3435+ uint32_t b )
3436+ {
3437+ return ( a >= b ) ? a : b ;
3438+ }
3439+ /*-----------------------------------------------------------*/
3440+
3441+ /**
3442+ * @brief Get the lowest value of two int32_t's.
3443+ * @param[in] a: the first value.
3444+ * @param[in] b: the second value.
3445+ * @return The lowest of the two values.
3446+ */
3447+ int32_t FreeRTOS_min_int32 ( int32_t a ,
3448+ int32_t b )
3449+ {
3450+ return ( a <= b ) ? a : b ;
3451+ }
3452+ /*-----------------------------------------------------------*/
3453+
3454+ /**
3455+ * @brief Get the lowest value of two uint32_t's.
3456+ * @param[in] a: the first value.
3457+ * @param[in] b: the second value.
3458+ * @return The lowest of the two values.
3459+ */
3460+ uint32_t FreeRTOS_min_uint32 ( uint32_t a ,
3461+ uint32_t b )
3462+ {
3463+ return ( a <= b ) ? a : b ;
3464+ }
3465+ /*-----------------------------------------------------------*/
3466+
3467+ /**
3468+ * @brief Round-up a number to a multiple of 'd'.
3469+ * @param[in] a: the first value.
3470+ * @param[in] d: the second value.
3471+ * @return A multiple of d.
3472+ */
3473+ uint32_t FreeRTOS_round_up ( uint32_t a ,
3474+ uint32_t d )
3475+ {
3476+ return d * ( ( a + d - 1U ) / d );
3477+ }
3478+ /*-----------------------------------------------------------*/
3479+
3480+ /**
3481+ * @brief Round-down a number to a multiple of 'd'.
3482+ * @param[in] a: the first value.
3483+ * @param[in] d: the second value.
3484+ * @return A multiple of d.
3485+ */
3486+ uint32_t FreeRTOS_round_down ( uint32_t a ,
3487+ uint32_t d )
3488+ {
3489+ return d * ( a / d );
3490+ }
3491+ /*-----------------------------------------------------------*/
3492+
3493+ /**
3494+ * @defgroup CastingMacroFunctions Utility casting functions
3495+ * @brief These functions are used to cast various types of pointers
3496+ * to other types. A major use would be to map various
3497+ * headers/packets on to the incoming byte stream.
3498+ *
3499+ * @param[in] pvArgument: Pointer to be casted to another type.
3500+ *
3501+ * @retval Casted pointer will be returned without violating MISRA
3502+ * rules.
3503+ * @{
3504+ */
3505+
3506+ /**
3507+ * @brief Cast a given pointer to EthernetHeader_t type pointer.
3508+ */
3509+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( EthernetHeader_t )
3510+ {
3511+ return ( EthernetHeader_t * ) pvArgument ;
3512+ }
3513+ /*-----------------------------------------------------------*/
3514+
3515+ /**
3516+ * @brief Cast a given constant pointer to EthernetHeader_t type pointer.
3517+ */
3518+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( EthernetHeader_t )
3519+ {
3520+ return ( const EthernetHeader_t * ) pvArgument ;
3521+ }
3522+ /*-----------------------------------------------------------*/
3523+
3524+ /**
3525+ * @brief Cast a given pointer to IPHeader_t type pointer.
3526+ */
3527+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( IPHeader_t )
3528+ {
3529+ return ( IPHeader_t * ) pvArgument ;
3530+ }
3531+ /*-----------------------------------------------------------*/
3532+
3533+ /**
3534+ * @brief Cast a given constant pointer to IPHeader_t type pointer.
3535+ */
3536+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( IPHeader_t )
3537+ {
3538+ return ( const IPHeader_t * ) pvArgument ;
3539+ }
3540+ /*-----------------------------------------------------------*/
3541+
3542+ /**
3543+ * @brief Cast a given pointer to ICMPHeader_t type pointer.
3544+ */
3545+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( ICMPHeader_t )
3546+ {
3547+ return ( ICMPHeader_t * ) pvArgument ;
3548+ }
3549+ /*-----------------------------------------------------------*/
3550+
3551+ /**
3552+ * @brief Cast a given constant pointer to ICMPHeader_t type pointer.
3553+ */
3554+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( ICMPHeader_t )
3555+ {
3556+ return ( const ICMPHeader_t * ) pvArgument ;
3557+ }
3558+ /*-----------------------------------------------------------*/
3559+
3560+ /**
3561+ * @brief Cast a given pointer to ARPPacket_t type pointer.
3562+ */
3563+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( ARPPacket_t )
3564+ {
3565+ return ( ARPPacket_t * ) pvArgument ;
3566+ }
3567+ /*-----------------------------------------------------------*/
3568+
3569+ /**
3570+ * @brief Cast a given constant pointer to ARPPacket_t type pointer.
3571+ */
3572+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( ARPPacket_t )
3573+ {
3574+ return ( const ARPPacket_t * ) pvArgument ;
3575+ }
3576+ /*-----------------------------------------------------------*/
3577+
3578+ /**
3579+ * @brief Cast a given pointer to IPPacket_t type pointer.
3580+ */
3581+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( IPPacket_t )
3582+ {
3583+ return ( IPPacket_t * ) pvArgument ;
3584+ }
3585+ /*-----------------------------------------------------------*/
3586+
3587+ /**
3588+ * @brief Cast a given constant pointer to IPPacket_t type pointer.
3589+ */
3590+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( IPPacket_t )
3591+ {
3592+ return ( const IPPacket_t * ) pvArgument ;
3593+ }
3594+ /*-----------------------------------------------------------*/
3595+
3596+ /**
3597+ * @brief Cast a given pointer to ICMPPacket_t type pointer.
3598+ */
3599+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( ICMPPacket_t )
3600+ {
3601+ return ( ICMPPacket_t * ) pvArgument ;
3602+ }
3603+ /*-----------------------------------------------------------*/
3604+
3605+ /**
3606+ * @brief Cast a given pointer to UDPPacket_t type pointer.
3607+ */
3608+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( UDPPacket_t )
3609+ {
3610+ return ( UDPPacket_t * ) pvArgument ;
3611+ }
3612+ /*-----------------------------------------------------------*/
3613+
3614+ /**
3615+ * @brief Cast a given constant pointer to UDPPacket_t type pointer.
3616+ */
3617+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( UDPPacket_t )
3618+ {
3619+ return ( const UDPPacket_t * ) pvArgument ;
3620+ }
3621+ /*-----------------------------------------------------------*/
3622+
3623+ /**
3624+ * @brief Cast a given pointer to TCPPacket_t type pointer.
3625+ */
3626+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( TCPPacket_t )
3627+ {
3628+ return ( TCPPacket_t * ) pvArgument ;
3629+ }
3630+ /*-----------------------------------------------------------*/
3631+
3632+ /**
3633+ * @brief Cast a given constant pointer to TCPPacket_t type pointer.
3634+ */
3635+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( TCPPacket_t )
3636+ {
3637+ return ( const TCPPacket_t * ) pvArgument ;
3638+ }
3639+ /*-----------------------------------------------------------*/
3640+
3641+ /**
3642+ * @brief Cast a given pointer to ProtocolPacket_t type pointer.
3643+ */
3644+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( ProtocolPacket_t )
3645+ {
3646+ return ( ProtocolPacket_t * ) pvArgument ;
3647+ }
3648+ /*-----------------------------------------------------------*/
3649+
3650+ /**
3651+ * @brief Cast a given constant pointer to ProtocolPacket_t type pointer.
3652+ */
3653+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( ProtocolPacket_t )
3654+ {
3655+ return ( const ProtocolPacket_t * ) pvArgument ;
3656+ }
3657+ /*-----------------------------------------------------------*/
3658+
3659+ /**
3660+ * @brief Cast a given pointer to ProtocolHeaders_t type pointer.
3661+ */
3662+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( ProtocolHeaders_t )
3663+ {
3664+ return ( ProtocolHeaders_t * ) pvArgument ;
3665+ }
3666+ /*-----------------------------------------------------------*/
3667+
3668+ /**
3669+ * @brief Cast a given constant pointer to ProtocolHeaders_t type pointer.
3670+ */
3671+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( ProtocolHeaders_t )
3672+ {
3673+ return ( const ProtocolHeaders_t * ) pvArgument ;
3674+ }
3675+ /*-----------------------------------------------------------*/
3676+
3677+ /**
3678+ * @brief Cast a given pointer to FreeRTOS_Socket_t type pointer.
3679+ */
3680+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( FreeRTOS_Socket_t )
3681+ {
3682+ return ( FreeRTOS_Socket_t * ) pvArgument ;
3683+ }
3684+ /*-----------------------------------------------------------*/
3685+
3686+ /**
3687+ * @brief Cast a given constant pointer to FreeRTOS_Socket_t type pointer.
3688+ */
3689+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( FreeRTOS_Socket_t )
3690+ {
3691+ return ( const FreeRTOS_Socket_t * ) pvArgument ;
3692+ }
3693+ /*-----------------------------------------------------------*/
3694+
3695+ #if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
3696+
3697+ /**
3698+ * @brief Cast a given pointer to SocketSelect_t type pointer.
3699+ */
3700+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( SocketSelect_t )
3701+ {
3702+ return ( SocketSelect_t * ) pvArgument ;
3703+ }
3704+ /*-----------------------------------------------------------*/
3705+
3706+ /**
3707+ * @brief Cast a given constant pointer to SocketSelect_t type pointer.
3708+ */
3709+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( SocketSelect_t )
3710+ {
3711+ return ( const SocketSelect_t * ) pvArgument ;
3712+ }
3713+ /*-----------------------------------------------------------*/
3714+
3715+ /**
3716+ * @brief Cast a given pointer to SocketSelectMessage_t type pointer.
3717+ */
3718+ ipDECL_CAST_PTR_FUNC_FOR_TYPE ( SocketSelectMessage_t )
3719+ {
3720+ return ( SocketSelectMessage_t * ) pvArgument ;
3721+ }
3722+ /*-----------------------------------------------------------*/
3723+
3724+ /**
3725+ * @brief Cast a given constant pointer to SocketSelectMessage_t type pointer.
3726+ */
3727+ ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE ( SocketSelectMessage_t )
3728+ {
3729+ return ( const SocketSelectMessage_t * ) pvArgument ;
3730+ }
3731+ /*-----------------------------------------------------------*/
3732+ #endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */
3733+ /** @} */
3734+
3735+ /**
3736+ * @brief Convert character array (of size 4) to equivalent 32-bit value.
3737+ * @param[in] pucPtr: The character array.
3738+ * @return 32-bit equivalent value extracted from the character array.
3739+ *
3740+ * @note Going by MISRA rules, these utility functions should not be defined
3741+ * if they are not being used anywhere. But their use depends on the
3742+ * application and hence these functions are defined unconditionally.
3743+ */
3744+ uint32_t ulChar2u32 ( const uint8_t * pucPtr )
3745+ {
3746+ return ( ( ( uint32_t ) pucPtr [ 0 ] ) << 24 ) |
3747+ ( ( ( uint32_t ) pucPtr [ 1 ] ) << 16 ) |
3748+ ( ( ( uint32_t ) pucPtr [ 2 ] ) << 8 ) |
3749+ ( ( ( uint32_t ) pucPtr [ 3 ] ) );
3750+ }
3751+ /*-----------------------------------------------------------*/
3752+
3753+ /**
3754+ * @brief Convert character array (of size 2) to equivalent 16-bit value.
3755+ * @param[in] pucPtr: The character array.
3756+ * @return 16-bit equivalent value extracted from the character array.
3757+ *
3758+ * @note Going by MISRA rules, these utility functions should not be defined
3759+ * if they are not being used anywhere. But their use depends on the
3760+ * application and hence these functions are defined unconditionally.
3761+ */
3762+ uint16_t usChar2u16 ( const uint8_t * pucPtr )
3763+ {
3764+ return ( uint16_t )
3765+ ( ( ( ( uint32_t ) pucPtr [ 0 ] ) << 8 ) |
3766+ ( ( ( uint32_t ) pucPtr [ 1 ] ) ) );
3767+ }
3768+ /*-----------------------------------------------------------*/
3769+
34153770/* Provide access to private members for verification. */
34163771#ifdef FREERTOS_TCP_ENABLE_VERIFICATION
34173772 #include "aws_freertos_ip_verification_access_ip_define.h"
0 commit comments