mirror of
https://github.com/rene-dev/stmbl.git
synced 2026-02-05 18:01:21 +08:00
initial load implementation
This commit is contained in:
@@ -13,16 +13,16 @@ typedef struct {
|
||||
char bla[100];
|
||||
}self_t;
|
||||
|
||||
static void rt_init(void* self, struct hal_pin* pins){
|
||||
static void rt_init(self_t* self, struct hal_pin* pins){
|
||||
//PIN(pin1) = 0.0;
|
||||
pins[pin1].source->source->value = 0.0;
|
||||
|
||||
((self_t*)self)->foo = 0;
|
||||
self->foo = 0;
|
||||
}
|
||||
|
||||
COMP_NEW {
|
||||
.name = TOSTRING(COMP_NAME),
|
||||
.rt_init = rt_init,
|
||||
.rt_init = (void (*)(void*,struct hal_pin*))rt_init,
|
||||
.self_size = sizeof(self_t),
|
||||
};
|
||||
|
||||
|
||||
@@ -13,16 +13,16 @@ typedef struct {
|
||||
char bla[100];
|
||||
}self_t;
|
||||
|
||||
static void rt_init(void* self, struct hal_pin* pins){
|
||||
static void rt_init(self_t* self, struct hal_pin* pins){
|
||||
//PIN(pin1) = 0.0;
|
||||
pins[pin1].source->source->value = 0.0;
|
||||
|
||||
((self_t*)self)->foo = 0;
|
||||
self->foo = 0;
|
||||
}
|
||||
|
||||
COMP_NEW {
|
||||
.name = TOSTRING(COMP_NAME),
|
||||
.rt_init = rt_init,
|
||||
.rt_init = (void (*)(void*,struct hal_pin*))rt_init,
|
||||
.self_size = sizeof(self_t),
|
||||
};
|
||||
|
||||
|
||||
39
src/hal.c
39
src/hal.c
@@ -28,6 +28,45 @@ char* itoa_(int i){
|
||||
return(hal.tmp);
|
||||
}
|
||||
|
||||
int load(HPNAME name){
|
||||
extern const comp_t __comp_tbl_start[];
|
||||
extern const comp_t __comp_tbl_end[];
|
||||
const comp_t *comp = __comp_tbl_start;
|
||||
|
||||
extern const struct hal_pin __pin_tbl_start[];
|
||||
extern const struct hal_pin __pin_tbl_end[];
|
||||
const struct hal_pin *pin = __pin_tbl_start;
|
||||
//TODO: platz für comp,pin,self
|
||||
while (comp < __comp_tbl_end){
|
||||
if(!strcmp(comp->name,name)){
|
||||
comp_instance_t inst;
|
||||
inst.comp = comp;
|
||||
inst.num = 0;
|
||||
inst.mem = malloc(comp->self_size);//TODO: return?
|
||||
for(int i = 0;i<hal_new.instance_count;i++){
|
||||
if(!strcmp(comp->name,name)){
|
||||
inst.num++;
|
||||
}
|
||||
}
|
||||
inst.pin_count = 0;
|
||||
while (pin < __pin_tbl_end){
|
||||
//TODO: platz für pin?
|
||||
if(!strcmp(pin->comp,name)){
|
||||
struct hal_pin p = *pin;
|
||||
p.instance = inst.num;
|
||||
p.source = &hal_new.hal_pins[hal_new.hal_pin_count];
|
||||
hal_new.hal_pins[hal_new.hal_pin_count++] = p;
|
||||
}
|
||||
pin++;
|
||||
}
|
||||
hal_new.instance[hal_new.instance_count++] = inst;
|
||||
break;
|
||||
}
|
||||
comp++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init_hal(){
|
||||
hal.comp_type_count = 0;
|
||||
for(int i = 0; i < MAX_COMP_TYPES; i++){
|
||||
|
||||
80
src/hal.h
80
src/hal.h
@@ -44,14 +44,84 @@ struct hal_pin{
|
||||
typedef struct{
|
||||
HPNAME name;
|
||||
void (*rt_init)(void* self,struct hal_pin* pins);
|
||||
void (*rt_deinit)();
|
||||
void (*nrt_init)();
|
||||
void (*rt)(float period);
|
||||
void (*frt)(float period);
|
||||
void (*nrt)(float period);
|
||||
void (*rt_deinit)(void* self,struct hal_pin* pins);
|
||||
void (*nrt_init)(void* self,struct hal_pin* pins);
|
||||
void (*rt)(void* self,struct hal_pin* pins, float period);
|
||||
void (*frt)(void* self,struct hal_pin* pins, float period);
|
||||
void (*nrt)(void* self,struct hal_pin* pins, float period);
|
||||
uint32_t self_size;
|
||||
}comp_t;
|
||||
|
||||
typedef struct{
|
||||
const comp_t* comp;
|
||||
struct hal_pin* pins;
|
||||
uint32_t num;
|
||||
uint32_t pin_count;
|
||||
void* mem;
|
||||
}comp_instance_t;
|
||||
|
||||
struct hal_struct_new{
|
||||
comp_instance_t instance[MAX_COMPS];
|
||||
uint32_t instance_count;
|
||||
struct hal_pin hal_pins[MAX_HAL_PINS];
|
||||
int hal_pin_count;
|
||||
|
||||
void (*rt_init[MAX_COMPS])(void* self,struct hal_pin* pins);
|
||||
int rt_init_func_count;
|
||||
|
||||
void (*rt_deinit[MAX_COMPS])(void* self,struct hal_pin* pins);
|
||||
int rt_deinit_func_count;
|
||||
|
||||
void (*nrt_init[MAX_COMPS])(void* self,struct hal_pin* pins);
|
||||
int nrt_init_func_count;
|
||||
|
||||
void (*rt[MAX_COMPS])(void* self,struct hal_pin* pins, float period);
|
||||
int rt_func_count;
|
||||
|
||||
void (*nrt[MAX_COMPS])(void* self,struct hal_pin* pins, float period);
|
||||
int nrt_func_count;
|
||||
|
||||
void (*frt[MAX_COMPS])(void* self,struct hal_pin* pins, float period);
|
||||
int frt_func_count;
|
||||
|
||||
// volatile enum{
|
||||
// RT_CALC,
|
||||
// RT_SLEEP,
|
||||
// RT_STOP
|
||||
// } rt_state;
|
||||
//
|
||||
// volatile enum{
|
||||
// FRT_CALC,
|
||||
// FRT_SLEEP,
|
||||
// FRT_STOP
|
||||
// } frt_state;
|
||||
//
|
||||
// volatile enum {
|
||||
// FRT_TOO_LONG,
|
||||
// RT_TOO_LONG,
|
||||
// MISC_ERROR,
|
||||
// MEM_ERROR,
|
||||
// CONFIG_LOAD_ERROR,
|
||||
// CONFIG_ERROR,
|
||||
// HAL_OK
|
||||
// } hal_state;
|
||||
|
||||
volatile int active_rt_func;
|
||||
volatile int active_frt_func;
|
||||
volatile int active_nrt_func;
|
||||
|
||||
uint32_t link_errors;
|
||||
uint32_t pin_errors;
|
||||
uint32_t set_errors;
|
||||
uint32_t get_errors;
|
||||
uint32_t comp_errors;
|
||||
char error_name[MAX_HPNAME];
|
||||
}hal_new;
|
||||
|
||||
int load(HPNAME name);
|
||||
|
||||
|
||||
|
||||
#define HAL_PIN_NEW(name_, value_) \
|
||||
static const struct hal_pin name_##_hal_pin __attribute__((used, section (".pin_tbl."TOSTRING(COMP_NAME)"."#name_))) = {\
|
||||
.comp = TOSTRING(COMP_NAME),\
|
||||
|
||||
Reference in New Issue
Block a user