2017-04-13 16:02:32 +00:00
|
|
|
#pragma once
|
2015-11-28 08:39:12 +00:00
|
|
|
#include <stdint.h>
|
2017-02-20 23:17:56 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-04-20 00:31:36 +00:00
|
|
|
#define HAL_CALC_TIME
|
|
|
|
#define HAL_COMP_CALC_TIME
|
2017-07-19 18:27:21 +00:00
|
|
|
//#define HAL_WATCHDOG
|
2017-04-20 00:31:36 +00:00
|
|
|
|
2017-07-17 17:46:46 +00:00
|
|
|
#ifndef HAL_MAX_PINS
|
2017-07-01 03:21:03 +00:00
|
|
|
#define HAL_MAX_PINS 1024
|
2017-07-17 17:46:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAL_MAX_COMPS
|
2017-07-01 03:21:03 +00:00
|
|
|
#define HAL_MAX_COMPS 32
|
2017-07-17 17:46:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAL_MAX_CTX
|
2017-07-01 03:21:03 +00:00
|
|
|
#define HAL_MAX_CTX 16384
|
2017-07-17 17:46:46 +00:00
|
|
|
#endif
|
2017-04-13 16:02:32 +00:00
|
|
|
|
|
|
|
#define HAL_COMP(name)
|
|
|
|
#define HAL_PIN(name)
|
|
|
|
#define HAL_PINA(name, index)
|
|
|
|
|
2017-04-13 16:29:18 +00:00
|
|
|
extern uint32_t hal_get_systick_value();
|
|
|
|
extern uint32_t hal_get_systick_reload();
|
|
|
|
extern uint32_t hal_get_systick_freq();
|
2017-07-19 15:56:24 +00:00
|
|
|
extern void hal_init_watchdog(float time);
|
|
|
|
extern void hal_reset_watchdog();
|
2017-04-13 16:29:18 +00:00
|
|
|
|
2017-04-13 16:02:32 +00:00
|
|
|
typedef char NAME[32];
|
|
|
|
|
|
|
|
typedef NAME const pin_t;
|
|
|
|
|
|
|
|
typedef struct hal_pin_inst_t{
|
2017-06-03 00:33:52 +00:00
|
|
|
volatile float value;
|
2017-04-13 16:02:32 +00:00
|
|
|
volatile struct hal_pin_inst_t * source;
|
|
|
|
} hal_pin_inst_t;
|
|
|
|
|
|
|
|
typedef const struct{
|
|
|
|
NAME name;
|
2017-06-03 00:33:52 +00:00
|
|
|
void (*nrt)(volatile void * ctx_ptr, volatile hal_pin_inst_t * pin_ptr);
|
2017-04-13 16:02:32 +00:00
|
|
|
void (*rt)(float period, volatile void * ctx_ptr, volatile hal_pin_inst_t * pin_ptr);
|
|
|
|
void (*frt)(float period, volatile void * ctx_ptr, volatile hal_pin_inst_t * pin_ptr);
|
|
|
|
|
|
|
|
void (*nrt_init)(volatile void * ctx_ptr, volatile hal_pin_inst_t * pin_ptr);
|
2017-07-01 03:21:03 +00:00
|
|
|
void (*hw_init)(volatile void * ctx_ptr, volatile hal_pin_inst_t * pin_ptr);
|
2017-04-13 16:02:32 +00:00
|
|
|
void (*rt_start)(volatile void * ctx_ptr, volatile hal_pin_inst_t * pin_ptr);
|
|
|
|
void (*frt_start)(volatile void * ctx_ptr, volatile hal_pin_inst_t * pin_ptr);
|
|
|
|
void (*rt_stop)(volatile void * ctx_ptr, volatile hal_pin_inst_t * pin_ptr);
|
|
|
|
void (*frt_stop)(volatile void * ctx_ptr, volatile hal_pin_inst_t * pin_ptr);
|
|
|
|
|
|
|
|
uint32_t ctx_size;
|
|
|
|
uint32_t pin_count;
|
2016-04-30 18:13:50 +00:00
|
|
|
} hal_comp_t;
|
2015-11-25 01:18:50 +00:00
|
|
|
|
2017-04-13 16:02:32 +00:00
|
|
|
typedef struct hal_comp_inst_t{
|
|
|
|
hal_comp_t * comp;
|
|
|
|
uint32_t instance;
|
|
|
|
volatile void * ctx;
|
|
|
|
volatile hal_pin_inst_t * pin_insts;
|
|
|
|
pin_t * pins;
|
2017-06-02 18:44:50 +00:00
|
|
|
uint32_t ctx_size;
|
2017-06-03 00:33:52 +00:00
|
|
|
volatile int32_t rt_ticks;
|
|
|
|
volatile int32_t frt_ticks;
|
|
|
|
volatile int32_t nrt_ticks;
|
|
|
|
|
|
|
|
volatile int32_t rt_max_ticks;
|
|
|
|
volatile int32_t frt_max_ticks;
|
|
|
|
volatile int32_t nrt_max_ticks;
|
2017-07-15 14:02:15 +00:00
|
|
|
|
|
|
|
volatile enum {
|
|
|
|
PRE_INIT,
|
|
|
|
PRE_HW_INIT,
|
|
|
|
STARTED,
|
|
|
|
} state;
|
2017-04-13 16:02:32 +00:00
|
|
|
} hal_comp_inst_t;
|
|
|
|
|
|
|
|
#define PIN(p) (pins->p.source->source->value)
|
|
|
|
#define PINA(p, i) (pins->p[i].source->source->value)
|
|
|
|
|
2017-06-03 01:52:22 +00:00
|
|
|
typedef struct{
|
|
|
|
volatile uint32_t active_rt_func;
|
|
|
|
volatile uint32_t active_frt_func;
|
|
|
|
volatile uint32_t active_nrt_func;
|
|
|
|
volatile enum {
|
|
|
|
HardFault,
|
|
|
|
NMI,
|
|
|
|
MemManage,
|
|
|
|
BusFault,
|
|
|
|
UsageFault,
|
|
|
|
} error_handler;
|
|
|
|
} hal_error_t;
|
|
|
|
|
2017-06-03 00:33:52 +00:00
|
|
|
typedef struct{
|
2017-04-13 16:02:32 +00:00
|
|
|
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,
|
|
|
|
NAN_ERROR,
|
2017-07-15 14:02:15 +00:00
|
|
|
HAL_OK2
|
2017-04-13 16:02:32 +00:00
|
|
|
} hal_state;
|
|
|
|
|
|
|
|
volatile struct hal_comp_inst_t * rt_comps[HAL_MAX_COMPS];
|
|
|
|
volatile struct hal_comp_inst_t * frt_comps[HAL_MAX_COMPS];
|
|
|
|
|
|
|
|
volatile int32_t active_rt_func;
|
|
|
|
volatile int32_t active_frt_func;
|
|
|
|
volatile int32_t active_nrt_func;
|
|
|
|
|
2017-06-03 00:33:52 +00:00
|
|
|
struct hal_comp_inst_t comp_insts[HAL_MAX_COMPS];
|
|
|
|
struct hal_pin_inst_t pin_insts[HAL_MAX_PINS];
|
2017-04-13 16:02:32 +00:00
|
|
|
volatile uint8_t ctxs[HAL_MAX_CTX]; // create runtime ctx print in python based on COMP_ctx_t
|
|
|
|
uint32_t comp_inst_count;
|
|
|
|
uint32_t rt_comp_count;
|
|
|
|
uint32_t frt_comp_count;
|
|
|
|
uint32_t pin_inst_count;
|
|
|
|
uint32_t ctx_count;
|
|
|
|
|
2017-06-03 00:33:52 +00:00
|
|
|
volatile uint32_t rt_ticks;
|
|
|
|
volatile uint32_t frt_ticks;
|
|
|
|
volatile uint32_t nrt_ticks;
|
|
|
|
|
|
|
|
volatile uint32_t rt_max_ticks;
|
|
|
|
volatile uint32_t frt_max_ticks;
|
|
|
|
volatile uint32_t nrt_max_ticks;
|
|
|
|
|
2017-04-13 16:02:32 +00:00
|
|
|
volatile float rt_period;
|
|
|
|
volatile float frt_period;
|
2017-06-03 01:52:22 +00:00
|
|
|
|
|
|
|
hal_error_t error_info;
|
2017-04-13 16:02:32 +00:00
|
|
|
} hal_t;
|
|
|
|
|
|
|
|
extern hal_t hal;
|
|
|
|
|
|
|
|
hal_comp_t * comp_by_name(NAME name);
|
|
|
|
volatile hal_comp_inst_t * comp_inst_by_name(NAME name, uint32_t instance);
|
|
|
|
uint32_t pin_offset_by_comp_name(NAME name);
|
|
|
|
pin_t * pin_by_name(NAME comp_name, NAME pin_name);
|
|
|
|
volatile hal_pin_inst_t * pin_inst_by_name(NAME comp_name, uint32_t instance, NAME pin_name);
|
|
|
|
uint32_t load_comp(hal_comp_t * comp);
|
|
|
|
pin_t * pin_by_pin_inst(volatile hal_pin_inst_t * p);
|
|
|
|
volatile hal_comp_inst_t * comp_inst_by_pin_inst(volatile hal_pin_inst_t * p);
|
2017-04-20 00:31:36 +00:00
|
|
|
void hal_print_pin(volatile hal_pin_inst_t * p);
|
2016-04-30 18:13:50 +00:00
|
|
|
|
2017-06-03 00:33:52 +00:00
|
|
|
void hal_init(float rt_period, float frt_period);
|
2017-07-01 03:21:03 +00:00
|
|
|
// void hal_init_nrt();
|
2016-04-30 18:13:50 +00:00
|
|
|
void hal_start();
|
|
|
|
void hal_stop();
|
2017-04-13 16:02:32 +00:00
|
|
|
void hal_run_rt();
|
|
|
|
void hal_run_frt();
|
|
|
|
void hal_run_nrt();
|
|
|
|
uint32_t hal_parse(char * cmd);
|
2017-06-03 01:52:22 +00:00
|
|
|
void hal_error(uint32_t error_handler);
|
2015-11-25 01:18:50 +00:00
|
|
|
|
2017-04-13 16:02:32 +00:00
|
|
|
#include "hal_tbl.h"
|