Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
Beam Positoning Monitor - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Beam Positoning Monitor - Software
Commits
dd2619cb
Commit
dd2619cb
authored
Apr 17, 2015
by
Lucas Russo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*utils: reference libconvc library for convertion functions
parent
880c000a
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
115 additions
and
133 deletions
+115
-133
dev_io.mk
src/hal/dev_io/dev_io.mk
+0
-2
dev_io_utils.c
src/hal/dev_io/dev_io_utils.c
+6
-6
dev_io_utils.h
src/hal/dev_io/dev_io_utils.h
+0
-0
utils.mk
src/hal/dev_io/utils/utils.mk
+0
-6
ll_io_utils.c
src/hal/ll_io/ll_io_utils.c
+11
-71
ll_io_utils.h
src/hal/ll_io/ll_io_utils.h
+0
-19
ll_io_eth.c
src/hal/ll_io/ops/ll_io_eth.c
+1
-16
ll_io_eth.h
src/hal/ll_io/ops/ll_io_eth.h
+1
-12
ll_io_eth_utils.c
src/hal/ll_io/ops/ll_io_eth_utils.c
+61
-0
ll_io_eth_utils.h
src/hal/ll_io/ops/ll_io_eth_utils.h
+33
-0
ops.mk
src/hal/ll_io/ops/ops.mk
+2
-1
No files found.
src/hal/dev_io/dev_io.mk
View file @
dd2619cb
include $(SRC_DIR)/hal/dev_io/utils/utils.mk
dev_io_DIR = $(SRC_DIR)/hal/dev_io
# Here we call <output_name>_core_OBJS as we need to add
...
...
src/hal/dev_io/
utils/
dev_io_utils.c
→
src/hal/dev_io/dev_io_utils.c
View file @
dd2619cb
...
...
@@ -6,7 +6,7 @@
*/
#include "dev_io_utils.h"
#include "
ll_io_utils
.h"
#include "
convc
.h"
#include "errhand.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
...
...
@@ -34,21 +34,21 @@
/************** Utility functions ****************/
static
const
llio
_types_t
devio_types_map
[]
=
{
static
const
convc
_types_t
devio_types_map
[]
=
{
{.
name
=
BE_DEVIO_STR
,
.
type
=
BE_DEVIO
},
{.
name
=
FE_DEVIO_STR
,
.
type
=
FE_DEVIO
},
{.
name
=
INVALID_DEVIO_STR
,
.
type
=
INVALID_DEVIO
},
{.
name
=
LLIO_TYPE_NAME_END
,
.
type
=
LLIO
_TYPE_END
}
/* End marker */
{.
name
=
CONVC_TYPE_NAME_END
,
.
type
=
CONVC
_TYPE_END
}
/* End marker */
};
devio_type_e
devio_str_to_type
(
const
char
*
type_str
)
{
devio_type_e
ret
=
llio
_str_to_gen_type
(
type_str
,
devio_types_map
);
devio_type_e
ret
=
convc
_str_to_gen_type
(
type_str
,
devio_types_map
);
return
(
ret
==
LLIO
_TYPE_END
)
?
INVALID_DEVIO
:
ret
;
return
(
ret
==
CONVC
_TYPE_END
)
?
INVALID_DEVIO
:
ret
;
}
char
*
devio_type_to_str
(
devio_type_e
type
)
{
return
llio
_gen_type_to_str
(
type
,
devio_types_map
);
return
convc
_gen_type_to_str
(
type
,
devio_types_map
);
}
src/hal/dev_io/
utils/
dev_io_utils.h
→
src/hal/dev_io/dev_io_utils.h
View file @
dd2619cb
File moved
src/hal/dev_io/utils/utils.mk
deleted
100644 → 0
View file @
880c000a
dev_io_utils_DIR = $(SRC_DIR)/hal/dev_io/utils
dev_io_utils_OBJS = $(dev_io_utils_DIR)/dev_io_utils.o
dev_io_utils_INCLUDE_DIRS = $(dev_io_utils_DIR)
src/hal/ll_io/ll_io_utils.c
View file @
dd2619cb
...
...
@@ -9,8 +9,9 @@
#include <string.h>
#include <stdio.h>
#include "ll_io.h"
#include "ll_io
_utils
.h"
#include "errhand.h"
#include "convc.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
...
...
@@ -39,84 +40,23 @@
/************** Utility functions ****************/
static
const
llio
_types_t
llio_dev_types_map
[]
=
{
{.
name
=
GENERIC_DEV_STR
,
.
type
=
GENERIC_DEV
},
{.
name
=
PCIE_DEV_STR
,
.
type
=
PCIE_DEV
},
{.
name
=
ETH_DEV_STR
,
.
type
=
ETH_DEV
},
{.
name
=
INVALID_DEV_STR
,
.
type
=
INVALID_DEV
},
{.
name
=
LLIO_TYPE_NAME_END
,
.
type
=
LLIO
_TYPE_END
}
/* End marker */
static
const
convc
_types_t
llio_dev_types_map
[]
=
{
{.
name
=
GENERIC_DEV_STR
,
.
type
=
GENERIC_DEV
},
{.
name
=
PCIE_DEV_STR
,
.
type
=
PCIE_DEV
},
{.
name
=
ETH_DEV_STR
,
.
type
=
ETH_DEV
},
{.
name
=
INVALID_DEV_STR
,
.
type
=
INVALID_DEV
},
{.
name
=
CONVC_TYPE_NAME_END
,
.
type
=
CONVC
_TYPE_END
}
/* End marker */
};
char
*
llio_gen_type_to_str
(
int
type
,
const
llio_types_t
*
llio_types
)
{
/* Should be large enough for all possible debug levels */
size_t
size
=
LLIO_TYPE_STR_SIZE
;
char
*
str
=
zmalloc
(
size
*
sizeof
(
char
));
ASSERT_ALLOC
(
str
,
err_alloc_str
);
/* Do a simple linear search to look for matching IDs */
uint32_t
i
;
for
(
i
=
0
;
llio_types
[
i
].
type
!=
LLIO_TYPE_END
;
++
i
)
{
if
(
type
==
llio_types
[
i
].
type
)
{
const
char
*
type_str
=
llio_types
[
i
].
name
;
int
errs
=
snprintf
(
str
,
size
,
"%s"
,
type_str
);
ASSERT_TEST
(
errs
>=
0
,
"[ll_io:utils] Could not clone string. Enconding error?
\n
"
,
err_copy_str
);
/* This shouldn't happen. Only when the number of characters written is
* less than the whole buffer, it is guaranteed that the string was
* written successfully */
ASSERT_TEST
((
size_t
)
errs
<
size
,
"[ll_io:utils] Cloned string was truncated
\n
"
,
err_trunc_str
);
break
;
}
}
/* No device found */
if
(
llio_types
[
i
].
type
==
LLIO_TYPE_END
)
{
free
(
str
);
str
=
NULL
;
}
return
str
;
/* Fail miserably for now ... */
err_trunc_str:
err_copy_str:
free
(
str
);
str
=
NULL
;
err_alloc_str:
return
NULL
;
}
char
*
llio_type_to_str
(
llio_type_e
type
)
{
return
llio_gen_type_to_str
(
type
,
llio_dev_types_map
);
}
int
llio_str_to_gen_type
(
const
char
*
type_str
,
const
llio_types_t
*
llio_types
)
{
assert
(
type_str
);
int
type
=
LLIO_TYPE_END
;
/* Not found */
/* Do a simple linear search to look for matching names */
uint32_t
i
;
for
(
i
=
0
;
llio_types
[
i
].
type
!=
LLIO_TYPE_END
;
++
i
)
{
if
(
streq
(
type_str
,
llio_types
[
i
].
name
))
{
type
=
llio_types
[
i
].
type
;
break
;
}
}
return
type
;
return
convc_gen_type_to_str
(
type
,
llio_dev_types_map
);
}
llio_type_e
llio_str_to_type
(
const
char
*
type_str
)
{
llio_type_e
ret
=
llio
_str_to_gen_type
(
type_str
,
llio_dev_types_map
);
llio_type_e
ret
=
convc
_str_to_gen_type
(
type_str
,
llio_dev_types_map
);
return
(
ret
==
LLIO
_TYPE_END
)
?
INVALID_DEV
:
ret
;
return
(
ret
==
CONVC
_TYPE_END
)
?
INVALID_DEV
:
ret
;
}
src/hal/ll_io/ll_io_utils.h
View file @
dd2619cb
...
...
@@ -10,9 +10,6 @@
#include <inttypes.h>
#define LLIO_TYPE_END 0xFFFF
#define LLIO_TYPE_NAME_END ""
/* Device type */
enum
_llio_type_e
{
GENERIC_DEV
=
0
,
...
...
@@ -23,13 +20,6 @@ enum _llio_type_e {
typedef
enum
_llio_type_e
llio_type_e
;
struct
_llio_types_t
{
int
type
;
char
*
name
;
};
typedef
struct
_llio_types_t
llio_types_t
;
#define GENERIC_DEV_STR "generic"
#define PCIE_DEV_STR "pcie"
#define ETH_DEV_STR "eth"
...
...
@@ -37,15 +27,6 @@ typedef struct _llio_types_t llio_types_t;
/************** Utility functions ****************/
/* Generic mapping functions */
/* Converts the LLIO type ID into a string */
char
*
llio_gen_type_to_str
(
int
type
,
const
llio_types_t
*
llio_types
);
/* Converts a string to an LLIO type ID. If no match if found,
* a INVALID_DEV is returned */
int
llio_str_to_gen_type
(
const
char
*
type_str
,
const
llio_types_t
*
llio_types
);
/* Converts the llio_type enumeration into a string */
char
*
llio_type_to_str
(
llio_type_e
type
);
/* Converts a string to the llio_type enumeration. If no match if found,
...
...
src/hal/ll_io/ops/ll_io_eth.c
View file @
dd2619cb
...
...
@@ -60,7 +60,6 @@
#define LLIO_ETH_REGEX_ADDR_HIT 2
#define LLIO_ETH_REGEX_PORT_HIT 3
static
llio_eth_type_e
_llio_str_to_eth_type
(
const
char
*
type_str
);
static
int
_llio_eth_conn
(
int
*
fd
,
llio_eth_type_e
type
,
char
*
hostname
,
char
*
port
);
static
void
*
_get_in_addr
(
struct
sockaddr
*
sa
);
...
...
@@ -82,7 +81,7 @@ llio_dev_eth_t * llio_dev_eth_new (const char *sock_type, const char *hostname,
assert
(
port
);
/* Convert socke type into enum */
llio_eth_type_e
type
=
_
llio_str_to_eth_type
(
sock_type
);
llio_eth_type_e
type
=
llio_str_to_eth_type
(
sock_type
);
ASSERT_TEST
(
type
!=
INVALID_ETH_SOCK
,
"Invalid ethernet socket"
,
err_llio_sock_type
);
...
...
@@ -309,20 +308,6 @@ static ssize_t _eth_write_generic (llio_t *self, uint64_t offs, const uint32_t *
/******************************* Helper Functions *****************************/
const
llio_types_t
llio_eth_types_map
[]
=
{
{.
name
=
TCP_ETH_SOCK_STR
,
.
type
=
TCP_ETH_SOCK
},
{.
name
=
UDP_ETH_SOCK_STR
,
.
type
=
UDP_ETH_SOCK
},
{.
name
=
INVALID_ETH_SOCK_STR
,
.
type
=
INVALID_ETH_SOCK
},
{.
name
=
LLIO_TYPE_NAME_END
,
.
type
=
LLIO_TYPE_END
}
/* End marker */
};
static
llio_eth_type_e
_llio_str_to_eth_type
(
const
char
*
type_str
)
{
llio_eth_type_e
ret
=
llio_str_to_gen_type
(
type_str
,
llio_eth_types_map
);
return
(
ret
==
LLIO_TYPE_END
)
?
INVALID_ETH_SOCK
:
ret
;
}
static
int
_llio_eth_conn
(
int
*
fd
,
llio_eth_type_e
type
,
char
*
hostname
,
char
*
port
)
{
...
...
src/hal/ll_io/ops/ll_io_eth.h
View file @
dd2619cb
...
...
@@ -9,21 +9,10 @@
#define _LL_IO_ETH_H_
#include "ll_io.h"
#include "ll_io_eth_utils.h"
#define LLIO_ETH_HANDLER(self) ((llio_dev_eth_t *) self->dev_handler)
enum
_llio_eth_type_e
{
TCP_ETH_SOCK
=
0
,
UDP_ETH_SOCK
=
1
,
INVALID_ETH_SOCK
};
#define TCP_ETH_SOCK_STR "tcp"
#define UDP_ETH_SOCK_STR "udp"
#define INVALID_ETH_SOCK_STR "invalid"
typedef
enum
_llio_eth_type_e
llio_eth_type_e
;
/* For use by llio_t general structure */
extern
const
llio_ops_t
llio_ops_eth
;
...
...
src/hal/ll_io/ops/ll_io_eth_utils.c
0 → 100644
View file @
dd2619cb
/*
* Copyright (C) 2015 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include "ll_io_eth_utils.h"
#include "errhand.h"
#include "convc.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label,
/* err_core */
...) \
ASSERT_HAL_TEST(test_boolean, LL_IO, "[ll_io:utils]", \
err_str, err_goto_label,
/* err_core */
__VA_ARGS__)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label,
/* err_core */
...) \
ASSERT_HAL_ALLOC(ptr, LL_IO, "[ll_io:utils]", \
llio_err_str(LLIO_ERR_ALLOC), \
err_goto_label,
/* err_core */
__VA_ARGS__)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, LL_IO, "[ll_io:utils]", \
llio_err_str (err_type))
#define LLIO_TYPE_STR_SIZE 16
/************** Utility functions ****************/
const
convc_types_t
llio_eth_types_map
[]
=
{
{.
name
=
TCP_ETH_SOCK_STR
,
.
type
=
TCP_ETH_SOCK
},
{.
name
=
UDP_ETH_SOCK_STR
,
.
type
=
UDP_ETH_SOCK
},
{.
name
=
INVALID_ETH_SOCK_STR
,
.
type
=
INVALID_ETH_SOCK
},
{.
name
=
CONVC_TYPE_NAME_END
,
.
type
=
CONVC_TYPE_END
}
/* End marker */
};
char
*
llio_eth_type_to_str
(
llio_eth_type_e
type
)
{
return
convc_gen_type_to_str
(
type
,
llio_eth_types_map
);
}
llio_eth_type_e
llio_str_to_eth_type
(
const
char
*
type_str
)
{
llio_eth_type_e
ret
=
convc_str_to_gen_type
(
type_str
,
llio_eth_types_map
);
return
(
ret
==
CONVC_TYPE_END
)
?
INVALID_ETH_SOCK
:
ret
;
}
src/hal/ll_io/ops/ll_io_eth_utils.h
0 → 100644
View file @
dd2619cb
/*
* Copyright (C) 2015 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LL_IO_ETH_UTILS_H_
#define _LL_IO_ETH_UTILS_H_
#include <inttypes.h>
enum
_llio_eth_type_e
{
TCP_ETH_SOCK
=
0
,
UDP_ETH_SOCK
=
1
,
INVALID_ETH_SOCK
};
typedef
enum
_llio_eth_type_e
llio_eth_type_e
;
#define TCP_ETH_SOCK_STR "tcp"
#define UDP_ETH_SOCK_STR "udp"
#define INVALID_ETH_SOCK_STR "invalid"
/************** Utility functions ****************/
/* Converts the llio_type enumeration into a string */
char
*
llio_eth_type_to_str
(
llio_eth_type_e
type
);
/* Converts a string to the llio_type enumeration. If no match if found,
* a INVALID_DEV is returned as the llio device */
llio_eth_type_e
llio_str_to_eth_type
(
const
char
*
type_str
);
#endif
src/hal/ll_io/ops/ops.mk
View file @
dd2619cb
ll_io_ops_DIR = $(SRC_DIR)/hal/ll_io/ops
ll_io_ops_OBJS = $(ll_io_ops_DIR)/ll_io_pcie.o \
$(ll_io_ops_DIR)/ll_io_eth.o
$(ll_io_ops_DIR)/ll_io_eth.o \
$(ll_io_ops_DIR)/ll_io_eth_utils.o
ll_io_ops_INCLUDE_DIRS = $(ll_io_ops_DIR)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment