mars/mars_dummy.c

205 lines
4.4 KiB
C
Raw Normal View History

2010-06-14 14:27:40 +00:00
// (c) 2010 Thomas Schoebel-Theuer / 1&1 Internet AG
// Dummy brick (just for demonstration)
2010-07-30 05:46:22 +00:00
//#define BRICK_DEBUGGING
//#define MARS_DEBUGGING
2010-06-14 14:27:40 +00:00
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include "mars.h"
///////////////////////// own type definitions ////////////////////////
2010-06-20 18:55:34 +00:00
#include "mars_dummy.h"
2010-06-14 14:27:40 +00:00
2010-07-07 14:09:16 +00:00
///////////////////////// own helper functions ////////////////////////
2010-06-14 14:27:40 +00:00
////////////////// own brick / input / output operations //////////////////
2011-03-31 16:16:00 +00:00
static
int dummy_get_info(struct dummy_output *output, struct mars_info *info)
2010-06-28 05:53:46 +00:00
{
struct dummy_input *input = output->brick->inputs[0];
2010-07-07 14:09:16 +00:00
return GENERIC_INPUT_CALL(input, mars_get_info, info);
2010-07-05 15:56:58 +00:00
}
2011-03-31 16:16:00 +00:00
static
int dummy_ref_get(struct dummy_output *output, struct mref_object *mref)
2010-07-05 15:56:58 +00:00
{
struct dummy_input *input = output->brick->inputs[0];
2010-12-15 12:13:18 +00:00
return GENERIC_INPUT_CALL(input, mref_get, mref);
2010-07-05 15:56:58 +00:00
}
2011-03-31 16:16:00 +00:00
static
void dummy_ref_put(struct dummy_output *output, struct mref_object *mref)
2010-07-05 15:56:58 +00:00
{
struct dummy_input *input = output->brick->inputs[0];
2010-12-15 12:13:18 +00:00
GENERIC_INPUT_CALL(input, mref_put, mref);
2010-07-05 15:56:58 +00:00
}
2011-03-31 16:16:00 +00:00
static
void dummy_ref_io(struct dummy_output *output, struct mref_object *mref)
2010-07-05 15:56:58 +00:00
{
struct dummy_input *input = output->brick->inputs[0];
2010-12-15 12:13:18 +00:00
GENERIC_INPUT_CALL(input, mref_io, mref);
2010-06-28 05:53:46 +00:00
}
2011-03-31 16:16:00 +00:00
static
int dummy_switch(struct dummy_brick *brick)
2011-02-23 20:48:06 +00:00
{
if (brick->power.button) {
mars_power_led_off((void*)brick, false);
//...
mars_power_led_on((void*)brick, true);
} else {
mars_power_led_on((void*)brick, false);
//...
mars_power_led_off((void*)brick, true);
}
return 0;
}
2011-03-31 16:16:00 +00:00
//////////////// informational / statistics ///////////////
static
char *dummy_statistics(struct dummy_brick *brick, int verbose)
{
return NULL;
}
static
void dummy_reset_statistics(struct dummy_brick *brick)
{
}
2010-06-22 13:21:42 +00:00
//////////////// object / aspect constructors / destructors ///////////////
2011-03-31 16:16:00 +00:00
static
int dummy_mref_aspect_init_fn(struct generic_aspect *_ini)
2010-07-05 15:56:58 +00:00
{
2010-12-15 12:13:18 +00:00
struct dummy_mref_aspect *ini = (void*)_ini;
2010-08-08 09:03:42 +00:00
(void)ini;
2011-02-23 20:48:06 +00:00
//ini->my_own = 0;
2010-07-05 15:56:58 +00:00
return 0;
}
2011-03-31 16:16:00 +00:00
static
void dummy_mref_aspect_exit_fn(struct generic_aspect *_ini)
2010-08-08 09:03:42 +00:00
{
2010-12-15 12:13:18 +00:00
struct dummy_mref_aspect *ini = (void*)_ini;
2010-08-08 09:03:42 +00:00
(void)ini;
}
2010-07-23 11:55:18 +00:00
MARS_MAKE_STATICS(dummy);
2010-06-22 13:21:42 +00:00
////////////////////// brick constructors / destructors ////////////////////
2010-06-14 14:27:40 +00:00
2011-03-31 16:16:00 +00:00
static
int dummy_brick_construct(struct dummy_brick *brick)
2010-06-14 14:27:40 +00:00
{
2011-02-23 20:48:06 +00:00
//brick->my_own = 0;
return 0;
}
2011-03-31 16:16:00 +00:00
static
int dummy_brick_destruct(struct dummy_brick *brick)
2011-02-23 20:48:06 +00:00
{
2010-06-14 14:27:40 +00:00
return 0;
}
2011-03-31 16:16:00 +00:00
static
int dummy_output_construct(struct dummy_output *output)
2010-06-14 14:27:40 +00:00
{
2011-02-23 20:48:06 +00:00
//output->my_own = 0;
return 0;
}
2011-03-31 16:16:00 +00:00
static
int dummy_output_destruct(struct dummy_output *output)
2011-02-23 20:48:06 +00:00
{
2010-06-14 14:27:40 +00:00
return 0;
}
///////////////////////// static structs ////////////////////////
2011-03-31 16:16:00 +00:00
static
struct dummy_brick_ops dummy_brick_ops = {
2011-02-23 20:48:06 +00:00
.brick_switch = dummy_switch,
2011-03-31 16:16:00 +00:00
.brick_statistics = dummy_statistics,
.reset_statistics = dummy_reset_statistics,
2010-06-14 14:27:40 +00:00
};
2011-03-31 16:16:00 +00:00
static
struct dummy_output_ops dummy_output_ops = {
2010-07-07 14:09:16 +00:00
.mars_get_info = dummy_get_info,
2010-12-15 12:13:18 +00:00
.mref_get = dummy_ref_get,
.mref_put = dummy_ref_put,
.mref_io = dummy_ref_io,
2010-06-14 14:27:40 +00:00
};
2010-08-10 17:39:30 +00:00
const struct dummy_input_type dummy_input_type = {
2010-06-14 14:27:40 +00:00
.type_name = "dummy_input",
.input_size = sizeof(struct dummy_input),
};
2011-03-31 16:16:00 +00:00
static
const struct dummy_input_type *dummy_input_types[] = {
2010-06-14 14:27:40 +00:00
&dummy_input_type,
};
2010-08-10 17:39:30 +00:00
const struct dummy_output_type dummy_output_type = {
2010-06-14 14:27:40 +00:00
.type_name = "dummy_output",
.output_size = sizeof(struct dummy_output),
.master_ops = &dummy_output_ops,
.output_construct = &dummy_output_construct,
2011-02-23 20:48:06 +00:00
.output_destruct = &dummy_output_destruct,
2010-06-14 14:27:40 +00:00
};
2011-03-31 16:16:00 +00:00
static
const struct dummy_output_type *dummy_output_types[] = {
2010-06-14 14:27:40 +00:00
&dummy_output_type,
};
2010-07-23 11:55:18 +00:00
const struct dummy_brick_type dummy_brick_type = {
2010-06-14 14:27:40 +00:00
.type_name = "dummy_brick",
.brick_size = sizeof(struct dummy_brick),
.max_inputs = 1,
.max_outputs = 1,
.master_ops = &dummy_brick_ops,
.aspect_types = dummy_aspect_types,
2010-06-14 14:27:40 +00:00
.default_input_types = dummy_input_types,
.default_output_types = dummy_output_types,
.brick_construct = &dummy_brick_construct,
2011-02-23 20:48:06 +00:00
.brick_destruct = &dummy_brick_destruct,
2010-06-14 14:27:40 +00:00
};
EXPORT_SYMBOL_GPL(dummy_brick_type);
////////////////// module init stuff /////////////////////////
2011-03-31 16:16:00 +00:00
static
int __init init_dummy(void)
2010-06-14 14:27:40 +00:00
{
2011-02-23 20:48:06 +00:00
MARS_INF("init_dummy()\n");
2010-06-14 14:27:40 +00:00
return dummy_register_brick_type();
}
2011-03-31 16:16:00 +00:00
static
void __exit exit_dummy(void)
2010-06-14 14:27:40 +00:00
{
2011-02-23 20:48:06 +00:00
MARS_INF("exit_dummy()\n");
2010-06-14 14:27:40 +00:00
dummy_unregister_brick_type();
}
2011-08-25 10:16:32 +00:00
#ifndef CONFIG_MARS_HAVE_BIGMODULE
2010-06-14 14:27:40 +00:00
MODULE_DESCRIPTION("MARS dummy brick");
MODULE_AUTHOR("Thomas Schoebel-Theuer <tst@1und1.de>");
MODULE_LICENSE("GPL");
module_init(init_dummy);
module_exit(exit_dummy);
2011-08-25 10:16:32 +00:00
#endif