summaryrefslogtreecommitdiffstats
path: root/src/kiro-trb.c
diff options
context:
space:
mode:
authorTimo Dritschler <timo.dritschler@kit.edu>2014-08-29 14:06:44 +0200
committerTimo Dritschler <timo.dritschler@kit.edu>2014-08-29 14:06:44 +0200
commit4dff7a9ffb8355100482c9955bbb6889fe237bb4 (patch)
tree8f3dd0838b9485daa0037c3e3227363f276b489f /src/kiro-trb.c
parentfc283a62d93fb5705cc955919ee109b2e915f912 (diff)
downloadkiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.tar.gz
kiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.tar.bz2
kiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.tar.xz
kiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.zip
Fix #6: Changed coding style to match UFO Project
Diffstat (limited to 'src/kiro-trb.c')
-rw-r--r--src/kiro-trb.c226
1 files changed, 138 insertions, 88 deletions
diff --git a/src/kiro-trb.c b/src/kiro-trb.c
index bb4a769..6737f83 100644
--- a/src/kiro-trb.c
+++ b/src/kiro-trb.c
@@ -27,7 +27,7 @@
*/
#include <stdio.h>
-
+
#include <stdlib.h>
#include <string.h>
#include <glib.h>
@@ -51,10 +51,10 @@ struct _KiroTrbPrivate {
void *mem; // Access to the actual buffer in Memory
void *frame_top; // First byte of the buffer storage
void *current; // Pointer to the current fill state
- uint64_t element_size;
+ uint64_t element_size;
uint64_t max_elements;
uint64_t iteration; // How many times the buffer has wraped around
-
+
/* easy access */
uint64_t buff_size;
};
@@ -63,8 +63,9 @@ struct _KiroTrbPrivate {
G_DEFINE_TYPE (KiroTrb, kiro_trb, G_TYPE_OBJECT);
-KiroTrb*
-kiro_trb_new (void) {
+KiroTrb *
+kiro_trb_new (void)
+{
return g_object_new (KIRO_TYPE_TRB, NULL);
}
@@ -72,111 +73,131 @@ kiro_trb_new (void) {
static
void kiro_trb_init (KiroTrb *self)
{
- KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE(self);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
priv->initialized = 0;
}
static void
kiro_trb_finalize (GObject *object)
{
- KiroTrb *self = KIRO_TRB(object);
- KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->mem)
- free(priv->mem);
+ KiroTrb *self = KIRO_TRB (object);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->mem)
+ free (priv->mem);
}
static void
kiro_trb_class_init (KiroTrbClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = kiro_trb_finalize;
- g_type_class_add_private(klass, sizeof(KiroTrbPrivate));
+ g_type_class_add_private (klass, sizeof (KiroTrbPrivate));
}
/* Privat functions */
-void write_header (KiroTrbPrivate* priv)
+void
+write_header (KiroTrbPrivate *priv)
{
- if(!priv)
+ if (!priv)
return;
- struct KiroTrbInfo* tmp_info = (struct KiroTrbInfo*)priv->mem;
+
+ struct KiroTrbInfo *tmp_info = (struct KiroTrbInfo *)priv->mem;
tmp_info->buffer_size_bytes = priv->buff_size;
tmp_info->element_size = priv->element_size;
tmp_info->offset = (priv->iteration * priv->max_elements) + ((priv->current - priv->frame_top) / priv->element_size);
- memcpy(priv->mem, tmp_info, sizeof(struct KiroTrbInfo));
+ memcpy (priv->mem, tmp_info, sizeof (struct KiroTrbInfo));
}
/* TRB functions */
-uint64_t kiro_trb_get_element_size (KiroTrb* self)
+uint64_t
+kiro_trb_get_element_size (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return 0;
+
return priv->element_size;
}
-uint64_t kiro_trb_get_max_elements (KiroTrb* self)
+uint64_t
+kiro_trb_get_max_elements (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return 0;
+
return priv->max_elements;
}
-uint64_t kiro_trb_get_raw_size (KiroTrb* self)
+uint64_t
+kiro_trb_get_raw_size (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return 0;
+
return priv->buff_size;
}
-void* kiro_trb_get_raw_buffer (KiroTrb* self)
+void *
+kiro_trb_get_raw_buffer (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return NULL;
- write_header(priv);
+
+ write_header (priv);
return priv->mem;
}
-void* kiro_trb_get_element (KiroTrb* self, uint64_t element)
+void *
+kiro_trb_get_element (KiroTrb *self, uint64_t element)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return NULL;
-
- uint64_t relative = 0;
- if(priv->iteration == 0)
+
+ uint64_t relative = 0;
+
+ if (priv->iteration == 0)
relative = element * priv->element_size;
else
- relative = ((priv->current - priv->frame_top) + (priv->element_size * element)) % (priv->buff_size - sizeof(struct KiroTrbInfo));
-
+ relative = ((priv->current - priv->frame_top) + (priv->element_size * element)) % (priv->buff_size - sizeof (struct KiroTrbInfo));
+
return priv->frame_top + relative;
}
-void kiro_trb_flush (KiroTrb *self)
+void
+kiro_trb_flush (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
priv->iteration = 0;
priv->current = priv->frame_top;
- write_header(priv);
+ write_header (priv);
}
-void kiro_trb_purge (KiroTrb* self, gboolean free_memory)
+void
+kiro_trb_purge (KiroTrb *self, gboolean free_memory)
{
- KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE(self);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
priv->iteration = 0;
priv->current = NULL;
priv->initialized = 0;
@@ -184,114 +205,143 @@ void kiro_trb_purge (KiroTrb* self, gboolean free_memory)
priv->buff_size = 0;
priv->frame_top = NULL;
priv->element_size = 0;
- if(free_memory)
- free(priv->mem);
+
+ if (free_memory)
+ free (priv->mem);
+
priv->mem = NULL;
}
-int kiro_trb_is_setup (KiroTrb *self)
+int
+kiro_trb_is_setup (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
return priv->initialized;
}
-int kiro_trb_reshape (KiroTrb *self, uint64_t element_size, uint64_t element_count)
+int
+kiro_trb_reshape (KiroTrb *self, uint64_t element_size, uint64_t element_count)
{
- if(element_size < 1 || element_count < 1)
+ if (element_size < 1 || element_count < 1)
return -1;
- size_t new_size = (element_size * element_count) + sizeof(struct KiroTrbInfo);
- void* newmem = malloc(new_size);
- if(!newmem)
+
+ size_t new_size = (element_size * element_count) + sizeof (struct KiroTrbInfo);
+ void *newmem = malloc (new_size);
+
+ if (!newmem)
return -1;
+
((struct KiroTrbInfo *)newmem)->buffer_size_bytes = new_size;
((struct KiroTrbInfo *)newmem)->element_size = element_size;
((struct KiroTrbInfo *)newmem)->offset = 0;
- kiro_trb_adopt(self, newmem);
+ kiro_trb_adopt (self, newmem);
return 0;
}
-int kiro_trb_push (KiroTrb *self, void *element_in)
+int
+kiro_trb_push (KiroTrb *self, void *element_in)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return -1;
- if((priv->current + priv->element_size) > (priv->mem + priv->buff_size))
+
+ if ((priv->current + priv->element_size) > (priv->mem + priv->buff_size))
return -1;
- memcpy(priv->current, element_in, priv->element_size);
+
+ memcpy (priv->current, element_in, priv->element_size);
priv->current += priv->element_size;
- if(priv->current >= priv->frame_top + (priv->element_size * priv->max_elements))
- {
+
+ if (priv->current >= priv->frame_top + (priv->element_size * priv->max_elements)) {
priv->current = priv->frame_top;
priv->iteration++;
}
- write_header(priv);
- return 0;
+
+ write_header (priv);
+ return 0;
}
-void* kiro_trb_dma_push (KiroTrb *self)
+void *
+kiro_trb_dma_push (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return NULL;
- if((priv->current + priv->element_size) > (priv->mem + priv->buff_size))
+
+ if ((priv->current + priv->element_size) > (priv->mem + priv->buff_size))
return NULL;
+
void *mem_out = priv->current;
priv->current += priv->element_size;
- if(priv->current >= priv->frame_top + (priv->element_size * priv->max_elements))
- {
+
+ if (priv->current >= priv->frame_top + (priv->element_size * priv->max_elements)) {
priv->current = priv->frame_top;
priv->iteration++;
}
- write_header(priv);
- return mem_out;
+
+ write_header (priv);
+ return mem_out;
}
-void kiro_trb_refresh (KiroTrb *self)
+void
+kiro_trb_refresh (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return;
+
struct KiroTrbInfo *tmp = (struct KiroTrbInfo *)priv->mem;
priv->buff_size = tmp->buffer_size_bytes;
priv->element_size = tmp->element_size;
- priv->max_elements = (tmp->buffer_size_bytes - sizeof(struct KiroTrbInfo)) / tmp->element_size;
+ priv->max_elements = (tmp->buffer_size_bytes - sizeof (struct KiroTrbInfo)) / tmp->element_size;
priv->iteration = tmp->offset / priv->max_elements;
- priv->frame_top = priv->mem + sizeof(struct KiroTrbInfo);
+ priv->frame_top = priv->mem + sizeof (struct KiroTrbInfo);
priv->current = priv->frame_top + ((tmp->offset % priv->max_elements) * priv->element_size);
priv->initialized = 1;
}
-void kiro_trb_adopt (KiroTrb *self, void *buff_in)
+void
+kiro_trb_adopt (KiroTrb *self, void *buff_in)
{
- if(!buff_in)
+ if (!buff_in)
return;
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->mem)
- free(priv->mem);
+
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->mem)
+ free (priv->mem);
+
priv->mem = buff_in;
priv->initialized = 1;
- kiro_trb_refresh(self);
+ kiro_trb_refresh (self);
}
-int kiro_trb_clone (KiroTrb *self, void *buff_in)
+int
+kiro_trb_clone (KiroTrb *self, void *buff_in)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
struct KiroTrbInfo *header = (struct KiroTrbInfo *)buff_in;
- void *newmem = malloc(header->buffer_size_bytes);
- if(!newmem)
+ void *newmem = malloc (header->buffer_size_bytes);
+
+ if (!newmem)
return -1;
- memcpy(newmem, buff_in, header->buffer_size_bytes);
- if(priv->mem)
- free(priv->mem);
+
+ memcpy (newmem, buff_in, header->buffer_size_bytes);
+
+ if (priv->mem)
+ free (priv->mem);
+
priv->mem = newmem;
priv->initialized = 1;
- kiro_trb_refresh(self);
+ kiro_trb_refresh (self);
return 0;
}