diff --git a/include/sbcp-uc/register.h b/include/sbcp-uc/register.h index f6a078c..2227a30 100644 --- a/include/sbcp-uc/register.h +++ b/include/sbcp-uc/register.h @@ -1,230 +1,230 @@ /* File: register.h Author: tuleu Created on May 22, 2012, 1:37 PM */ #ifndef SBCP_UC_REGISTER_H_ #define SBCP_UC_REGISTER_H_ #include "sbcp-uc_config.h" #include "sbcp_common.h" #include "DEE_Emulation_16-bit.h" #if SBCP_REG_TABLE_SIZE > 255 #error "SBCP_REG_TABLE_SIZE should be <= 255" #endif /** * \defgroup sbcp_register_m SBCP register * * \brief module to manipulate SBCP register * * An SBCP device have a table of register. Some of them are standard * (sbcp_std_registers ) and most of them are device specific. These one are * specified by the user using sbcp_add_register() function inside a * sbcp_init_device_registers_fptr user defined function. * * Registers are always R/W from the device. From the host point of view they * could be SBCP_REG_WRITABLE or SBCP_REG_READABLE. * They are some time SBCP_REG_PERSISTENT, it means that if they are set * externally there value will be written in EEPROM. * * You can define some sbcp_reg_host_wr_callback for a register, i.e. a callback * that will be called every time the register is externally written. * * \ingroup sbcp_m * */ /** * adress of a sbcp_register. A device could have up to 256 registers * \ingroup sbcp_register_m */ typedef uint8_t sbcp_reg_address; /** * Value of a register. A register is always a 16 bits value * \ingroup sbcp_register_m */ typedef union sbcp_reg_val { /// as 16 bit signed int int16_t i; /// as 16 bit unsigned int uint16_t u; /// as an array of char uint8_t c[2]; ///litlle endian architecure struct { /// MSB byte uint8_t lsb; ///LSB byte uint8_t msb; }; } sbcp_reg_val; /** * Write callback of a register. This callback will be called every time the * register is *externally* written. At the time it is called, the register is * not already written, therefore you could access the old value inside the * register. * \ingroup sbcp_register_m * \param address : the address of the written register * \param value : a pointer to the new value that will be written in the * register after the call to the callback. You may change the * value. * \return an sbcp_error code if there is any error. In that case an error * message will be sent to the host */ typedef sbcp_error (*sbcp_reg_host_wr_callback)(sbcp_reg_address address,sbcp_reg_val * new_value); /** * Initialization callback. During a call to sbcp_init() this user providen * callback will be called. User should register the device specific register * using call to sbcp_add_register() and sbcp_add_register_no_callback(). User * should also defines the low latency in and out register using. * sbcp_append_low_latency_in_register() and * sbcp_append_low_latency_out_register() * \ingroup sbcp_register_m */ typedef void(*sbcp_init_device_registers_fptr)(); /** * Available flags for sbcp_register. They should be passed to * sbcp_add_register() and sbcp_add_register_no_callback() * \ingroup sbcp_register_m */ typedef enum sbcp_reg_flags { SBCP_REG_UNIMPLEMENTED = 0, //!< SBCP_REG_UNIMPLEMENTED flags for a non existing sbcp_register SBCP_REG_WRITABLE = 1 << 0, //!< SBCP_REG_WRITABLE specify an externally writable register SBCP_REG_READABLE = 1 << 1, //!< SBCP_REG_READABLE specify an externally readable register SBCP_REG_PERSISTENT = 1 << 2, //!< SBCP_REG_PERSISTENT specify an EEPROM persistent register SBCP_REG_UNLOCKED = 1 << 3, //!< SBCP_REG_PROTECTED specify a protected register (unimplemented) SBCP_REG_LL_READABLE = 1 << 4, //!< SBCP_REG_LL_READABLE specify a register that is readble on low latency instructions } sbcp_reg_flags; -#define SBCP_REG_USER_SETABLE_FLAGS (SBCP_REG_WRITABLE | SBCP_REG_READABLE | SBCP_REG_PERSISTENT) +#define SBCP_REG_USER_SETABLE_FLAGS (SBCP_REG_WRITABLE | SBCP_REG_READABLE | SBCP_REG_PERSISTENT | SBCP_REG_LL_READABLE) /** * Control parameter of a register */ typedef struct sbcp_reg_ctrl_params { ///flags of the register sbcp_reg_flags flags; ///callback of the register sbcp_reg_host_wr_callback callback; } sbcp_reg_ctrl_params; #define SBCP_MY_ID sbcp_reg_lsb(SBCP_REG_ID) #define SBCP_MY_CLASS sbcp_reg_lsb(SBCP_REG_CLASS) #define SBCP_REG_NO_CALLBACK ((void*)0) /** * \name register value accessor * * Use this accessor to access the sbcp_register. * \ingroup sbcp_register_m */ ///@{ /** * Register as an 16 bits signed int. * \param adr the sbcp_reg_address of the register */ #define sbcp_reg_int(adr) (sbcp_reg_table[(adr)].i) /** * Register as an 16 bits unsigned int. * \param adr the sbcp_reg_address of the register */ #define sbcp_reg_uint(adr) (sbcp_reg_table[(adr)].u) /** * MSB byte of the register * \param adr the sbcp_reg_address of the register */ #define sbcp_reg_msb(adr) (sbcp_reg_table[(adr)].msb) /** * LSB byte of the register * \param adr the sbcp_reg_address of the register */ #define sbcp_reg_lsb(adr) (sbcp_reg_table[(adr)].lsb) /** * sbcp_register_flags of the sbcp_register * \param adr the sbcp_reg_address of the register */ #define sbcp_reg_flags(adr) (sbcp_reg_params[(adr)].flags) /** * sbcp_reg_host_wr_callback of the sbcp_register * \param adr the sbcp_reg_address of the register */ #define sbcp_reg_clbck(adr) (sbcp_reg_params[(adr)].callback) ///@} /** * Inits the registers * \internal * @param klass * @param id * @param version * @param device_specific_init */ void sbcp_init_registers(sbcp_class klass, sbcp_id id, sbcp_fw_version version, sbcp_init_device_registers_fptr device_specific_init); /** * Adds a new registers to the list of the device register. * \warning Should be called *only* in user register initialization callback * sbcp_init_device_register_fptr * \ingroup sbcp_register_m * @param address the address of the new register * @param value default value of the register at device startup * @param flags a '|' comnination of sbcp_register_flags * @param clb sbcp_reg_host_wr_callback for this register */ void sbcp_add_register(sbcp_reg_address address, uint16_t value, sbcp_reg_flags flags, sbcp_reg_host_wr_callback clb); /** * Adds a new registers to the list of the device register, whithout callback. * \warning Should be called *only* in user register initialization callback * sbcp_init_device_register_fptr * \ingroup sbcp_register_m * @param address the address of the new register * @param value default value of the register at device startup * @param flags a '|' comnination of sbcp_register_flags * */ void sbcp_add_register_no_callback(sbcp_reg_address address, uint16_t value, sbcp_reg_flags flags); /** * Safely sets a register to a value. If the register is persistent, it also * be saved in EEPROM. * \ingroup sbcp_register_m */ #define sbcp_safe_set_register(address,value) do{ \ if(sbcp_reg_flags(address) & SBCP_REG_PERSISTENT){ \ DataEEWrite(value,address); \ } \ sbcp_reg_uint(address) = value; \ }while(0) /*intern data representation, not part of API*/ extern sbcp_reg_val sbcp_reg_table [SBCP_REG_TABLE_SIZE]; extern sbcp_reg_ctrl_params sbcp_reg_params[SBCP_REG_TABLE_SIZE]; #endif // SBCP_REGISTER_H_ diff --git a/include/sbcp-uc/sbcp-uc_config.h b/include/sbcp-uc/sbcp-uc_config.h index 1017cef..b0ea056 100644 --- a/include/sbcp-uc/sbcp-uc_config.h +++ b/include/sbcp-uc/sbcp-uc_config.h @@ -1,105 +1,105 @@ #ifndef SBCP_UC_CONFIG_H_ #define SBCP_UC_CONFIG_H_ #define SBCP_UC_MAJOR_VERSION 0 #define SBCP_UC_MINOR_VERSION 2 // in order to compile libsbcp-uc one should set a configuration you // can either use a configuration name defined here for all the // settings, or you should define all variable manually and pass them // to the preprocessor. The latter is not recommanded //defaults for the SBCP master on dsPIC33FJ128MC802 #ifdef SBCP_128MC802_MASTER -#define SBCP_REG_TABLE_SIZE 8 +#define SBCP_REG_TABLE_SIZE 16 #define SBCP_INST_TABLE_SIZE 8 #define SBCP_LOW_LATENCY_IN_SIZE 0 #define SBCP_LOW_LATENCY_OUT_SIZE 0 #define SBCP_NO_BUFFER_ALLOCATION #define SBCP_DO_NOT_PROVIDE_MAIN //redefines frame size #define SBCP_FRAME_SIZE 8 #define SBCP_PACKET_SIZE 64 #endif //SBCP_128MC802_MASTER //defaults for the SBCP master on dsPIC33FJ128MC802 #ifdef SBCP_128MC802_SBCP_TEST -#define SBCP_REG_TABLE_SIZE 8 -#define SBCP_INST_TABLE_SIZE 8 +#define SBCP_REG_TABLE_SIZE 16 +#define SBCP_INST_TABLE_SIZE 16 #define SBCP_LOW_LATENCY_IN_SIZE 0 #define SBCP_LOW_LATENCY_OUT_SIZE 0 #define SBCP_BUFFER_ALLOCATION #define SBCP_PROVIDE_MAIN #endif //SBCP_128MC802_SBCP_TEST //defaults for the motordriver boards on dsPIC33FJ128MC804 #ifdef SBCP_128MC804_MDV #define SBCP_REG_TABLE_SIZE 128 -#define SBCP_INST_TABLE_SIZE 8 +#define SBCP_INST_TABLE_SIZE 16 #define SBCP_LOW_LATENCY_IN_SIZE 2 #define SBCP_LOW_LATENCY_OUT_SIZE 10 #define SBCP_BUFFER_ALLOCATION #define SBCP_PROVIDE_MAIN #endif //SBCP_128MC804_MDV //defaults for the Power board on dsPIC33FJ128GP802 #ifdef SBCP_128GP802_PWB -#define SBCP_REG_TABLE_SIZE 16 -#define SBCP_INST_TABLE_SIZE 8 +#define SBCP_REG_TABLE_SIZE 24 +#define SBCP_INST_TABLE_SIZE 10 #define SBCP_LOW_LATENCY_IN_SIZE 2 #define SBCP_LOW_LATENCY_OUT_SIZE 10 #define SBCP_BUFFER_ALLOCATION #define SBCP_PROVIDE_MAIN #endif //SBCP_128GP802_PWB #ifndef SBCP_FRAME_SIZE #define SBCP_FRAME_SIZE 4 #endif //SBCP_FRAME_SIZE #ifndef SBCP_PACKET_SIZE #define SBCP_PACKET_SIZE 128 #endif //SBCP_PACKET_SIZE #if !defined(SBCP_REG_TABLE_SIZE) \ || !defined(SBCP_INST_TABLE_SIZE) \ || !defined(SBCP_LOW_LATENCY_IN_SIZE) \ || !defined(SBCP_LOW_LATENCY_OUT_SIZE) \ || !( defined(SBCP_BUFFER_ALLOCATION) ^ defined(SBCP_NO_BUFFER_ALLOCATION) ) \ || !( defined(SBCP_PROVIDE_MAIN) ^defined(SBCP_DO_NOT_PROVIDE_MAIN) ) \ || !defined(SBCP_FRAME_SIZE) \ || !defined(SBCP_PACKET_SIZE) #error "You did not configured SBCP_UC correctly, please defines all settings like explained in sbcp-uc-config.h" #endif //test config clause #define SBCP_REG_MIN_TABLE_SIZE 8 #define SBCP_INST_MIN_TABLE_SIZE 8 #if SBCP_REG_TABLE_SIZE < SBCP_REG_MIN_TABLE_SIZE #error "Bad configuration, table of register is too small." #endif #if SBCP_INST_TABLE_SIZE < SBCP_INST_MIN_TABLE_SIZE #error "Bad configuration, table of instruction is too small." #endif #endif //SBCP_UC_CONFIG_H_