Skip to content

Commit

Permalink
Merge pull request COVESA#6 from COVESA/new_api/crf
Browse files Browse the repository at this point in the history
Migrated CRF formats to Open1722 APIs.
  • Loading branch information
nayakned authored Jun 24, 2024
2 parents ea7ff0a + e8d30bb commit 34ba2ff
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 325 deletions.
2 changes: 1 addition & 1 deletion examples/crf/crf-listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
#include <inttypes.h>

#include "avtp.h"
#include "avtp_crf.h"
#include "avtp/Crf.h"
#include "avtp_aaf.h"
#include "common.h"
#include "avtp/CommonHeader.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/crf/crf-talker.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#include <math.h>

#include "avtp.h"
#include "avtp_crf.h"
#include "avtp/Crf.h"
#include "common.h"
#include "avtp/CommonHeader.h"

Expand Down
88 changes: 57 additions & 31 deletions include/avtp_crf.h → include/avtp/Crf.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024, COVESA
* Copyright (c) 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -9,9 +10,9 @@
* * 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.
* * Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* * Neither the name of Intel Corporation, COVESA nor the names of their
* 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
Expand All @@ -23,16 +24,22 @@
* 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.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#pragma once

#include <errno.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif
#include "avtp/Utils.h"

#define AVTP_CRF_HEADER_LEN (5 * AVTP_QUADLET_SIZE)

typedef struct Avtp_Cvf {
uint8_t header[AVTP_CRF_HEADER_LEN];
uint8_t payload[0];
} Avtp_Crf_t;

/* CRF 'type' field values. */
#define AVTP_CRF_TYPE_USER 0x00
Expand All @@ -49,29 +56,50 @@ extern "C" {
#define AVTP_CRF_PULL_MULT_BY_25_OVER_24 0x04
#define AVTP_CRF_PULL_MULT_BY_1_OVER_8 0x05

struct avtp_crf_pdu {
uint32_t subtype_data;
uint64_t stream_id;
uint64_t packet_info;
uint64_t crf_data[0];
} __attribute__ ((__packed__));

enum avtp_crf_field {
typedef enum Avtp_CrfField {
/* CRF header fields */
AVTP_CRF_FIELD_SUBTYPE,
AVTP_CRF_FIELD_SV,
AVTP_CRF_FIELD_VERSION,
AVTP_CRF_FIELD_MR,
AVTP_CRF_FIELD_RESERVED,
AVTP_CRF_FIELD_FS,
AVTP_CRF_FIELD_TU,
AVTP_CRF_FIELD_SEQ_NUM,
AVTP_CRF_FIELD_SEQUENCE_NUM,
AVTP_CRF_FIELD_TYPE,
AVTP_CRF_FIELD_STREAM_ID,
AVTP_CRF_FIELD_PULL,
AVTP_CRF_FIELD_BASE_FREQ,
AVTP_CRF_FIELD_CRF_DATA_LEN,
AVTP_CRF_FIELD_BASE_FREQUENCY,
AVTP_CRF_FIELD_CRF_DATA_LENGTH,
AVTP_CRF_FIELD_TIMESTAMP_INTERVAL,
/* Count number of fields for bound checks */
AVTP_CRF_FIELD_MAX,
};
}Avtp_CrfField_t;

int Avtp_Crf_Init(Avtp_Crf_t* pdu);

int Avtp_Crf_GetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t* value);

/* Get value from CRF AVTPDU field.
int Avtp_Crf_SetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t value);

/******************************************************************************
* Legacy API (deprecated)
*****************************************************************************/

#define AVTP_CRF_FIELD_SEQ_NUM AVTP_CRF_FIELD_SEQUENCE_NUM
#define AVTP_CRF_FIELD_BASE_FREQ AVTP_CRF_FIELD_BASE_FREQUENCY
#define AVTP_CRF_FIELD_CRF_DATA_LEN AVTP_CRF_FIELD_CRF_DATA_LENGTH

struct avtp_crf_pdu {
uint32_t subtype_data;
uint64_t stream_id;
uint64_t packet_info;
uint64_t crf_data[0];
} __attribute__ ((__packed__));

/**
* @deprecated
* Get value from CRF AVTPDU field.
* @pdu: Pointer to PDU struct.
* @field: PDU field to be retrieved.
* @val: Pointer to variable which the retrieved value should be saved.
Expand All @@ -80,10 +108,11 @@ enum avtp_crf_field {
* 0: Success.
* -EINVAL: If any argument is invalid.
*/
int avtp_crf_pdu_get(const struct avtp_crf_pdu *pdu,
enum avtp_crf_field field, uint64_t *val);
int avtp_crf_pdu_get(const void *pdu, Avtp_CrfField_t field, uint64_t *val);

/* Set value from CRF AVTPDU field.
/**
* @deprecated
* Set value from CRF AVTPDU field.
* @pdu: Pointer to PDU struct.
* @field: PDU field to be set.
* @val: Value to be set.
Expand All @@ -92,19 +121,16 @@ int avtp_crf_pdu_get(const struct avtp_crf_pdu *pdu,
* 0: Success.
* -EINVAL: If any argument is invalid.
*/
int avtp_crf_pdu_set(struct avtp_crf_pdu *pdu, enum avtp_crf_field field,
uint64_t val);
int avtp_crf_pdu_set(void *pdu, Avtp_CrfField_t field, uint64_t val);

/* Initialize CRF AVTPDU. All AVTPDU fields are initialized with zero except
/**
* @deprecated
* Initialize CRF AVTPDU. All AVTPDU fields are initialized with zero except
* 'subtype' (which is set to AVTP_SUBTYPE_CRF) and 'sv' (which is set to 1).
* @pdu: Pointer to PDU struct.
*
* Return values:
* 0: Success.
* -EINVAL: If any argument is invalid.
*/
int avtp_crf_pdu_init(struct avtp_crf_pdu *pdu);

#ifdef __cplusplus
}
#endif
int avtp_crf_pdu_init(void *pdu);
5 changes: 3 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ avtp_lib = library(
[
'src/avtp.c',
'src/avtp_aaf.c',
'src/avtp_crf.c',
'src/avtp_cvf.c',
'src/avtp_ieciidc.c',
'src/avtp_stream.c',
Expand All @@ -26,7 +25,8 @@ avtp_lib = library(
'src/avtp/acf/Sensor.c',
'src/avtp/acf/SensorBrief.c',
'src/avtp/Udp.c',
'src/avtp/Rvf.c'
'src/avtp/Rvf.c',
'src/avtp/Crf.c',
],
version: meson.project_version(),
include_directories: include_directories('include'),
Expand All @@ -45,6 +45,7 @@ install_headers(
'include/avtp/Udp.h',
'include/avtp/Utils.h',
'include/avtp/Rvf.h',
'include/avtp/Crf.h',
subdir : 'avtp'
)

Expand Down
99 changes: 99 additions & 0 deletions src/avtp/Crf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2024, COVESA
* Copyright (c) 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Intel Corporation, COVESA nor the names of their
* 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 OWNER 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.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <string.h>
#include <errno.h>

#include "avtp/Crf.h"
#include "avtp/Utils.h"
#include "avtp/CommonHeader.h"

/**
* This table maps all IEEE 1722 Clock Reference Format (CRF) specific header fields
* to a descriptor.
*/
static const Avtp_FieldDescriptor_t Avtp_CrfFieldDescriptors[AVTP_CRF_FIELD_MAX] =
{
[AVTP_CRF_FIELD_SUBTYPE] = { .quadlet = 0, .offset = 0, .bits = 8 },
[AVTP_CRF_FIELD_SV] = { .quadlet = 0, .offset = 8, .bits = 1 },
[AVTP_CRF_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 },
[AVTP_CRF_FIELD_MR] = { .quadlet = 0, .offset = 12, .bits = 1 },
[AVTP_CRF_FIELD_RESERVED] = { .quadlet = 0, .offset = 13, .bits = 1 },
[AVTP_CRF_FIELD_FS] = { .quadlet = 0, .offset = 14, .bits = 1 },
[AVTP_CRF_FIELD_TU] = { .quadlet = 0, .offset = 15, .bits = 1 },
[AVTP_CRF_FIELD_SEQUENCE_NUM] = { .quadlet = 0, .offset = 16, .bits = 8 },
[AVTP_CRF_FIELD_TYPE] = { .quadlet = 0, .offset = 24, .bits = 8 },
[AVTP_CRF_FIELD_STREAM_ID] = { .quadlet = 1, .offset = 0, .bits = 64 },
[AVTP_CRF_FIELD_PULL] = { .quadlet = 3, .offset = 0, .bits = 3 },
[AVTP_CRF_FIELD_BASE_FREQUENCY] = { .quadlet = 3, .offset = 3, .bits = 29 },
[AVTP_CRF_FIELD_CRF_DATA_LENGTH] = { .quadlet = 4, .offset = 0, .bits = 16 },
[AVTP_CRF_FIELD_TIMESTAMP_INTERVAL] = { .quadlet = 4, .offset = 16, .bits = 16 },
};

int Avtp_Crf_Init(Avtp_Crf_t* pdu) {

if (pdu == NULL) {
return -EINVAL;
}

memset(pdu, 0, sizeof(Avtp_Crf_t));
Avtp_Crf_SetField(pdu, AVTP_CRF_FIELD_SUBTYPE, AVTP_SUBTYPE_CRF);
Avtp_Crf_SetField(pdu, AVTP_CRF_FIELD_SV, 1);

return 0;

}

int Avtp_Crf_GetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t* value) {
return Avtp_GetField(Avtp_CrfFieldDescriptors, AVTP_CRF_FIELD_MAX, (uint8_t*)pdu, field, value);
}

int Avtp_Crf_SetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t value) {
return Avtp_SetField(Avtp_CrfFieldDescriptors, AVTP_CRF_FIELD_MAX, (uint8_t*)pdu, field, value);
}

/******************************************************************************
* Legacy API
*****************************************************************************/

int avtp_crf_pdu_get(const void *pdu, Avtp_CrfField_t field, uint64_t *val)
{
return Avtp_Crf_GetField((Avtp_Crf_t*)pdu, field, val);
}

int avtp_crf_pdu_set(void *pdu, Avtp_CrfField_t field, uint64_t val)
{
return Avtp_Crf_SetField((Avtp_Crf_t*)pdu, field, val);
}

int avtp_crf_pdu_init(void *pdu)
{
return Avtp_Crf_Init((Avtp_Crf_t*)pdu);
}
Loading

0 comments on commit 34ba2ff

Please sign in to comment.