some question about source code
Posted: Thu May 31, 2018 5:05 am
when i reading the source code ,i have some question about the object oriented in chibios.
the struct BMP085Driver have four members,and there have some methods in the vmt.
so the main.c invoke the macro 'barometerReadRaw'
so these class ,like this
ithink we can get instance throw the macro 'objGetInstance'
so the question is :
1. i can't find the place where invoke the macro
2. the 'barometerReadRaw' is (ip)->vmt->read_raw(ip, dp) but in the BMP085Driver we have three vmt,how it works?
3. where can get the chibios oo model ..
4. maybe the detail of the answer is complicated , give me some advice about learning the oo in c model will be beter.
and thanks for your help.
the struct BMP085Driver have four members,and there have some methods in the vmt.
Code: Select all
static BMP085Driver BMP085D1;
/**
* @brief BMP085 driver structure.
*/
struct BMP085Driver {
/** @brief BaseSensor Virtual Methods Table. */
const struct BaseSensorVMT *vmt_basesensor;
/** @brief BaseBarometer Virtual Methods Table. */
const struct BaseBarometerVMT *vmt_basebarometer;
/** @brief BaseThermometer Virtual Methods Table. */
const struct BaseThermometerVMT *vmt_basethermometer;
_bmp085_data;
};
so the main.c invoke the macro 'barometerReadRaw'
Code: Select all
#define barometerReadRaw(ip, dp) \
(ip)->vmt->read_raw(ip, dp)
typedef struct {
/** @brief Virtual Methods Table.*/
const struct BaseBarometerVMT *vmt;
_base_barometer_data
} BaseBarometer;
so these class ,like this
Code: Select all
struct
{
instance_offset
parent_methods
parent_data
children_methods
children_data
}children
ithink we can get instance throw the macro 'objGetInstance'
Code: Select all
#define objGetInstance(type, ip) \
(type)(((size_t)(ip)) - (ip)->vmt->instance_offset)
so the question is :
1. i can't find the place where invoke the macro
2. the 'barometerReadRaw' is (ip)->vmt->read_raw(ip, dp) but in the BMP085Driver we have three vmt,how it works?
3. where can get the chibios oo model ..
4. maybe the detail of the answer is complicated , give me some advice about learning the oo in c model will be beter.
and thanks for your help.