aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-08 15:33:32 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-08 15:36:32 +0900
commite747b5324707ec1eeb3af5793be3aff69ca8d5fd (patch)
tree0a6906a850ba422b8876859d76ba06d9ec9a8260
parenta942b9778456a811e7ab295f9fd7691c770478dc (diff)
downloadlibhinoko-e747b5324707ec1eeb3af5793be3aff69ca8d5fd.tar.gz
fw_iso_ctx_private: add macro for maximum channel and sync code define in IEEE 1394
The maximum value of channel and sy fields in isochronous packet are defined in IEEE 1394. This commit adds macro for constant values. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_ctx_private.c29
-rw-r--r--src/fw_iso_ctx_private.h7
-rw-r--r--src/fw_iso_rx_multiple.c13
-rw-r--r--src/fw_iso_rx_multiple.h2
-rw-r--r--src/fw_iso_rx_single.c10
-rw-r--r--src/fw_iso_rx_single.h3
-rw-r--r--src/fw_iso_tx.c13
-rw-r--r--src/fw_iso_tx.h2
8 files changed, 44 insertions, 35 deletions
diff --git a/src/fw_iso_ctx_private.c b/src/fw_iso_ctx_private.c
index 03ed9dc..f005f03 100644
--- a/src/fw_iso_ctx_private.c
+++ b/src/fw_iso_ctx_private.c
@@ -104,7 +104,7 @@ gboolean fw_iso_ctx_state_allocate(struct fw_iso_ctx_state *state, const char *p
scode == HINOKO_FW_SCODE_S3200, FALSE);
// IEEE 1394 specification supports isochronous channel up to 64.
- g_return_val_if_fail(channel < 64, FALSE);
+ g_return_val_if_fail(channel <= IEEE1394_MAX_CHANNEL, FALSE);
// Headers should be aligned to quadlet.
g_return_val_if_fail(header_size % 4 == 0, FALSE);
@@ -112,7 +112,6 @@ gboolean fw_iso_ctx_state_allocate(struct fw_iso_ctx_state *state, const char *p
if (mode == HINOKO_FW_ISO_CTX_MODE_RX_SINGLE) {
// At least, 1 quadlet is required for iso_header.
g_return_val_if_fail(header_size >= 4, FALSE);
- g_return_val_if_fail(channel < 64, FALSE);
} else if (mode == HINOKO_FW_ISO_CTX_MODE_RX_MULTIPLE) {
// Needless.
g_return_val_if_fail(header_size == 0, FALSE);
@@ -254,7 +253,7 @@ void fw_iso_ctx_state_unmap_buffer(struct fw_iso_ctx_state *state)
* @state: A [struct@FwIsoCtxState].
* @skip: Whether to skip packet transmission or not.
* @tags: The value of tag field for isochronous packet to handle.
- * @sy: The value of sy field for isochronous packet to handle.
+ * @sync_code: The value of sy field in isochronous packet header for packet processing, up to 15.
* @header: (array length=header_length) (element-type guint8): The content of header for IT
* context, nothing for IR context.
* @header_length: The number of bytes for @header.
@@ -265,7 +264,7 @@ void fw_iso_ctx_state_unmap_buffer(struct fw_iso_ctx_state *state)
* Register data on buffer for payload of isochronous context.
*/
gboolean fw_iso_ctx_state_register_chunk(struct fw_iso_ctx_state *state, gboolean skip,
- HinokoFwIsoCtxMatchFlag tags, guint sy,
+ HinokoFwIsoCtxMatchFlag tags, guint sync_code,
const guint8 *header, guint header_length,
guint payload_length, gboolean schedule_interrupt,
GError **error)
@@ -281,7 +280,7 @@ gboolean fw_iso_ctx_state_register_chunk(struct fw_iso_ctx_state *state, gboolea
tags == HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG2 ||
tags == HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG3, FALSE);
- g_return_val_if_fail(sy < 16, FALSE);
+ g_return_val_if_fail(sync_code <= IEEE1394_MAX_SYNC_CODE, FALSE);
if (state->mode == HINOKO_FW_ISO_CTX_MODE_TX) {
if (!skip) {
@@ -295,7 +294,7 @@ gboolean fw_iso_ctx_state_register_chunk(struct fw_iso_ctx_state *state, gboolea
} else if (state->mode == HINOKO_FW_ISO_CTX_MODE_RX_SINGLE ||
state->mode == HINOKO_FW_ISO_CTX_MODE_RX_MULTIPLE) {
g_return_val_if_fail(tags == 0, FALSE);
- g_return_val_if_fail(sy == 0, FALSE);
+ g_return_val_if_fail(sync_code == 0, FALSE);
g_return_val_if_fail(header == NULL, FALSE);
g_return_val_if_fail(header_length == 0, FALSE);
g_return_val_if_fail(payload_length == 0, FALSE);
@@ -332,7 +331,7 @@ gboolean fw_iso_ctx_state_register_chunk(struct fw_iso_ctx_state *state, gboolea
datum->control =
FW_CDEV_ISO_PAYLOAD_LENGTH(payload_length) |
FW_CDEV_ISO_TAG(tags) |
- FW_CDEV_ISO_SY(sy) |
+ FW_CDEV_ISO_SY(sync_code) |
FW_CDEV_ISO_HEADER_LENGTH(header_length);
if (skip)
@@ -442,14 +441,14 @@ gboolean fw_iso_ctx_state_queue_chunks(struct fw_iso_ctx_state *state, GError **
* to start packet processing. The first element should be the second part of
* isochronous cycle, up to 3. The second element should be the cycle part of
* isochronous cycle, up to 7999.
- * @sync: The value of sync field in isochronous header for packet processing, up to 15.
+ * @sync_code: The value of sy field in isochronous packet header for packet processing, up to 15.
* @tags: The value of tag field in isochronous header for packet processing.
* @error: A [struct@GLib.Error].
*
* Start isochronous context.
*/
gboolean fw_iso_ctx_state_start(struct fw_iso_ctx_state *state, const guint16 *cycle_match,
- guint32 sync, HinokoFwIsoCtxMatchFlag tags, GError **error)
+ guint32 sync_code, HinokoFwIsoCtxMatchFlag tags, GError **error)
{
struct fw_cdev_start_iso arg = {0};
gint cycle;
@@ -476,14 +475,14 @@ gboolean fw_iso_ctx_state_start(struct fw_iso_ctx_state *state, const guint16 *c
}
if (state->mode == HINOKO_FW_ISO_CTX_MODE_TX) {
- g_return_val_if_fail(sync == 0, FALSE);
+ g_return_val_if_fail(sync_code == 0, FALSE);
g_return_val_if_fail(tags == 0, FALSE);
} else {
- g_return_val_if_fail(sync < 16, FALSE);
+ g_return_val_if_fail(sync_code <= IEEE1394_MAX_SYNC_CODE, FALSE);
g_return_val_if_fail(tags <= (HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG0 |
- HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG1 |
- HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG2 |
- HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG3), FALSE);
+ HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG1 |
+ HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG2 |
+ HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG3), FALSE);
}
// Not prepared.
@@ -495,7 +494,7 @@ gboolean fw_iso_ctx_state_start(struct fw_iso_ctx_state *state, const guint16 *c
if (!fw_iso_ctx_state_queue_chunks(state, error))
return FALSE;
- arg.sync = sync;
+ arg.sync = sync_code;
arg.cycle = cycle;
arg.tags = tags;
arg.handle = state->handle;
diff --git a/src/fw_iso_ctx_private.h b/src/fw_iso_ctx_private.h
index e25648d..c0688d7 100644
--- a/src/fw_iso_ctx_private.h
+++ b/src/fw_iso_ctx_private.h
@@ -24,6 +24,9 @@ extern const char *const fw_iso_ctx_err_msgs[7];
#define generate_file_error(error, code, format, arg) \
g_set_error(error, G_FILE_ERROR, code, format, arg)
+#define IEEE1394_MAX_CHANNEL 63
+#define IEEE1394_MAX_SYNC_CODE 15
+
struct fw_iso_ctx_state {
int fd;
guint handle;
@@ -72,14 +75,14 @@ gboolean fw_iso_ctx_state_map_buffer(struct fw_iso_ctx_state *state, guint bytes
void fw_iso_ctx_state_unmap_buffer(struct fw_iso_ctx_state *state);
gboolean fw_iso_ctx_state_register_chunk(struct fw_iso_ctx_state *state, gboolean skip,
- HinokoFwIsoCtxMatchFlag tags, guint sy,
+ HinokoFwIsoCtxMatchFlag tags, guint sync_code,
const guint8 *header, guint header_length,
guint payload_length, gboolean schedule_interrupt,
GError **error);
gboolean fw_iso_ctx_state_queue_chunks(struct fw_iso_ctx_state *state, GError **error);
gboolean fw_iso_ctx_state_start(struct fw_iso_ctx_state *state, const guint16 *cycle_match,
- guint32 sync, HinokoFwIsoCtxMatchFlag tags, GError **error);
+ guint32 sync_code, HinokoFwIsoCtxMatchFlag tags, GError **error);
void fw_iso_ctx_state_stop(struct fw_iso_ctx_state *state);
void fw_iso_ctx_state_read_frame(struct fw_iso_ctx_state *state, guint offset, guint length,
diff --git a/src/fw_iso_rx_multiple.c b/src/fw_iso_rx_multiple.c
index 404d85d..047ba18 100644
--- a/src/fw_iso_rx_multiple.c
+++ b/src/fw_iso_rx_multiple.c
@@ -340,7 +340,7 @@ HinokoFwIsoRxMultiple *hinoko_fw_iso_rx_multiple_new(void)
* @self: A [class@FwIsoRxMultiple].
* @path: A path to any Linux FireWire character device.
* @channels: (array length=channels_length) (element-type guint8): an array for channels to listen
- * to.
+ * to. The value of each element should be up to 63.
* @channels_length: The length of channels.
* @error: A [struct@GLib.Error].
*
@@ -363,7 +363,7 @@ gboolean hinoko_fw_iso_rx_multiple_allocate(HinokoFwIsoRxMultiple *self, const c
g_return_val_if_fail(channels_length > 0, FALSE);
for (i = 0; i < channels_length; ++i) {
- g_return_val_if_fail(channels[i] < 64, FALSE);
+ g_return_val_if_fail(channels[i] <= IEEE1394_MAX_CHANNEL, FALSE);
set.channels |= G_GUINT64_CONSTANT(1) << channels[i];
}
@@ -386,7 +386,7 @@ gboolean hinoko_fw_iso_rx_multiple_allocate(HinokoFwIsoRxMultiple *self, const c
}
priv->channels = g_byte_array_new();
- for (i = 0; i < 64; ++i) {
+ for (i = 0; i <= IEEE1394_MAX_CHANNEL; ++i) {
if (set.channels & (G_GUINT64_CONSTANT(1) << i))
g_byte_array_append(priv->channels, (const guint8 *)&i, 1);
}
@@ -440,7 +440,7 @@ gboolean hinoko_fw_iso_rx_multiple_map_buffer(HinokoFwIsoRxMultiple *self, guint
* to start packet processing. The first element should be the second part of
* isochronous cycle, up to 3. The second element should be the cycle part of
* isochronous cycle, up to 7999.
- * @sync: The value of sync field in isochronous header for packet processing, up to 15.
+ * @sync_code: The value of sy field in isochronous packet header for packet processing, up to 15.
* @tags: The value of tag field in isochronous header for packet processing.
* @chunks_per_irq: The number of chunks per interval of interrupt. When 0 is given, application
* should call [method@FwIsoCtx.flush_completions] voluntarily to generate
@@ -450,7 +450,7 @@ gboolean hinoko_fw_iso_rx_multiple_map_buffer(HinokoFwIsoRxMultiple *self, guint
* Start IR context.
*/
gboolean hinoko_fw_iso_rx_multiple_start(HinokoFwIsoRxMultiple *self, const guint16 *cycle_match,
- guint32 sync, HinokoFwIsoCtxMatchFlag tags,
+ guint32 sync_code, HinokoFwIsoCtxMatchFlag tags,
guint chunks_per_irq, GError **error)
{
HinokoFwIsoRxMultiplePrivate *priv;
@@ -458,6 +458,7 @@ gboolean hinoko_fw_iso_rx_multiple_start(HinokoFwIsoRxMultiple *self, const guin
int i;
g_return_val_if_fail(HINOKO_IS_FW_ISO_RX_MULTIPLE(self), FALSE);
+ g_return_val_if_fail(sync_code <= IEEE1394_MAX_SYNC_CODE, FALSE);
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
priv = hinoko_fw_iso_rx_multiple_get_instance_private(self);
@@ -474,7 +475,7 @@ gboolean hinoko_fw_iso_rx_multiple_start(HinokoFwIsoRxMultiple *self, const guin
}
priv->prev_offset = 0;
- return fw_iso_ctx_state_start(&priv->state, cycle_match, sync, tags, error);
+ return fw_iso_ctx_state_start(&priv->state, cycle_match, sync_code, tags, error);
}
/**
diff --git a/src/fw_iso_rx_multiple.h b/src/fw_iso_rx_multiple.h
index e516daa..d113db7 100644
--- a/src/fw_iso_rx_multiple.h
+++ b/src/fw_iso_rx_multiple.h
@@ -34,7 +34,7 @@ gboolean hinoko_fw_iso_rx_multiple_map_buffer(HinokoFwIsoRxMultiple *self, guint
guint chunks_per_buffer, GError **error);
gboolean hinoko_fw_iso_rx_multiple_start(HinokoFwIsoRxMultiple *self, const guint16 *cycle_match,
- guint32 sync, HinokoFwIsoCtxMatchFlag tags,
+ guint32 sync_code, HinokoFwIsoCtxMatchFlag tags,
guint chunks_per_irq, GError **error);
void hinoko_fw_iso_rx_multiple_get_payload(HinokoFwIsoRxMultiple *self, guint index,
diff --git a/src/fw_iso_rx_single.c b/src/fw_iso_rx_single.c
index facdca5..34ecb12 100644
--- a/src/fw_iso_rx_single.c
+++ b/src/fw_iso_rx_single.c
@@ -239,7 +239,7 @@ HinokoFwIsoRxSingle *hinoko_fw_iso_rx_single_new(void)
* hinoko_fw_iso_rx_single_allocate:
* @self: A [class@FwIsoRxSingle].
* @path: A path to any Linux FireWire character device.
- * @channel: An isochronous channel to listen.
+ * @channel: An isochronous channel to listen, up to 63.
* @header_size: The number of bytes for header of IR context.
* @error: A [struct@GLib.Error].
*
@@ -257,6 +257,7 @@ gboolean hinoko_fw_iso_rx_single_allocate(HinokoFwIsoRxSingle *self, const char
HinokoFwIsoRxSinglePrivate *priv;
g_return_val_if_fail(HINOKO_IS_FW_ISO_RX_SINGLE(self), FALSE);
+ g_return_val_if_fail(channel <= IEEE1394_MAX_CHANNEL, FALSE);
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
priv = hinoko_fw_iso_rx_single_get_instance_private(self);
@@ -331,7 +332,7 @@ gboolean hinoko_fw_iso_rx_single_register_packet(HinokoFwIsoRxSingle *self,
* to start packet processing. The first element should be the second part of
* isochronous cycle, up to 3. The second element should be the cycle part of
* isochronous cycle, up to 7999.
- * @sync: The value of sync field in isochronous header for packet processing, up to 15.
+ * @sync_code: The value of sy field in isochronous packet header for packet processing, up to 15.
* @tags: The value of tag field in isochronous header for packet processing.
* @error: A [struct@GLib.Error].
*
@@ -342,18 +343,19 @@ gboolean hinoko_fw_iso_rx_single_register_packet(HinokoFwIsoRxSingle *self,
* Since: 0.7.
*/
gboolean hinoko_fw_iso_rx_single_start(HinokoFwIsoRxSingle *self, const guint16 *cycle_match,
- guint32 sync, HinokoFwIsoCtxMatchFlag tags, GError **error)
+ guint32 sync_code, HinokoFwIsoCtxMatchFlag tags, GError **error)
{
HinokoFwIsoRxSinglePrivate *priv;
g_return_val_if_fail(HINOKO_IS_FW_ISO_RX_SINGLE(self), FALSE);
+ g_return_val_if_fail(sync_code <= IEEE1394_MAX_SYNC_CODE, FALSE);
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
priv = hinoko_fw_iso_rx_single_get_instance_private(self);
priv->chunk_cursor = 0;
- return fw_iso_ctx_state_start(&priv->state, cycle_match, sync, tags, error);
+ return fw_iso_ctx_state_start(&priv->state, cycle_match, sync_code, tags, error);
}
/**
diff --git a/src/fw_iso_rx_single.h b/src/fw_iso_rx_single.h
index 5bbd121..87c2b03 100644
--- a/src/fw_iso_rx_single.h
+++ b/src/fw_iso_rx_single.h
@@ -44,7 +44,8 @@ gboolean hinoko_fw_iso_rx_single_register_packet(HinokoFwIsoRxSingle *self,
gboolean schedule_interrupt, GError **error);
gboolean hinoko_fw_iso_rx_single_start(HinokoFwIsoRxSingle *self, const guint16 *cycle_match,
- guint32 sync, HinokoFwIsoCtxMatchFlag tags, GError **error);
+ guint32 sync_code, HinokoFwIsoCtxMatchFlag tags,
+ GError **error);
void hinoko_fw_iso_rx_single_get_payload(HinokoFwIsoRxSingle *self, guint index,
const guint8 **payload, guint *length);
diff --git a/src/fw_iso_tx.c b/src/fw_iso_tx.c
index c43fac1..698a620 100644
--- a/src/fw_iso_tx.c
+++ b/src/fw_iso_tx.c
@@ -225,7 +225,7 @@ HinokoFwIsoTx *hinoko_fw_iso_tx_new(void)
* @self: A [class@FwIsoTx].
* @path: A path to any Linux FireWire character device.
* @scode: A [enum@FwScode] to indicate speed of isochronous communication.
- * @channel: An isochronous channel to transfer.
+ * @channel: An isochronous channel to transfer, up to 63.
* @header_size: The number of bytes for header of IT context.
* @error: A [struct@GLib.Error].
*
@@ -243,6 +243,7 @@ gboolean hinoko_fw_iso_tx_allocate(HinokoFwIsoTx *self, const char *path, Hinoko
HinokoFwIsoTxPrivate *priv;
g_return_val_if_fail(HINOKO_IS_FW_ISO_TX(self), FALSE);
+ g_return_val_if_fail(channel <= IEEE1394_MAX_CHANNEL, FALSE);
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
priv = hinoko_fw_iso_tx_get_instance_private(self);
@@ -306,7 +307,7 @@ gboolean hinoko_fw_iso_tx_start(HinokoFwIsoTx *self, const guint16 *cycle_match,
* hinoko_fw_iso_tx_register_packet:
* @self: A [class@FwIsoTx].
* @tags: The value of tag field for isochronous packet to register.
- * @sy: The value of sy field for isochronous packet to register.
+ * @sync_code: The value of sync field in isochronous packet header for packet processing, up to 15.
* @header: (array length=header_length)(nullable): The header of IT context for isochronous packet.
* @header_length: The number of bytes for the @header.
* @payload: (array length=payload_length)(nullable): The payload of IT context for isochronous
@@ -324,7 +325,7 @@ gboolean hinoko_fw_iso_tx_start(HinokoFwIsoTx *self, const guint16 *cycle_match,
* Since: 0.7.
*/
gboolean hinoko_fw_iso_tx_register_packet(HinokoFwIsoTx *self, HinokoFwIsoCtxMatchFlag tags,
- guint sy,
+ guint sync_code,
const guint8 *header, guint header_length,
const guint8 *payload, guint payload_length,
gboolean schedule_interrupt, GError **error)
@@ -335,6 +336,7 @@ gboolean hinoko_fw_iso_tx_register_packet(HinokoFwIsoTx *self, HinokoFwIsoCtxMat
gboolean skip;
g_return_val_if_fail(HINOKO_IS_FW_ISO_TX(self), FALSE);
+ g_return_val_if_fail(sync_code <= IEEE1394_MAX_SYNC_CODE, FALSE);
g_return_val_if_fail((header != NULL && header_length > 0) ||
(header == NULL && header_length == 0), FALSE);
g_return_val_if_fail((payload != NULL && payload_length > 0) ||
@@ -347,8 +349,9 @@ gboolean hinoko_fw_iso_tx_register_packet(HinokoFwIsoTx *self, HinokoFwIsoCtxMat
if (header_length == 0 && payload_length == 0)
skip = TRUE;
- if (!fw_iso_ctx_state_register_chunk(&priv->state, skip, tags, sy, header, header_length,
- payload_length, schedule_interrupt, error))
+ if (!fw_iso_ctx_state_register_chunk(&priv->state, skip, tags, sync_code,
+ header, header_length, payload_length,
+ schedule_interrupt, error))
return FALSE;
fw_iso_ctx_state_read_frame(&priv->state, priv->offset, payload_length, &frames,
diff --git a/src/fw_iso_tx.h b/src/fw_iso_tx.h
index b8efb6f..a888bed 100644
--- a/src/fw_iso_tx.h
+++ b/src/fw_iso_tx.h
@@ -41,7 +41,7 @@ gboolean hinoko_fw_iso_tx_map_buffer(HinokoFwIsoTx *self, guint maximum_bytes_pe
gboolean hinoko_fw_iso_tx_start(HinokoFwIsoTx *self, const guint16 *cycle_match, GError **error);
gboolean hinoko_fw_iso_tx_register_packet(HinokoFwIsoTx *self, HinokoFwIsoCtxMatchFlag tags,
- guint sy,
+ guint sync_code,
const guint8 *header, guint header_length,
const guint8 *payload, guint payload_length,
gboolean schedule_interrupt, GError **error);