⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 component.h

📁 circuit calculation program
💻 H
字号:
#ifndef __COMPONENT_H__
#define __COMPONENT_H__

#include <stdio.h>
#include "types.h"

/* basic component id */
typedef enum comptype { 
	COMP_RES, COMP_IND, COMP_CAP , COMP_COMP, COMP_LIM
	} comptype_t;

typedef enum comp_pintype {
	COMP_PIN_NONE,
	COMP_PIN_VCC,
	COMP_PIN_GND,
	COMP_PIN_IOPORT 
	} comp_pintype_t;
/* component class defintion */
struct compinfo;

typedef struct compclass {
	/* component class name, such as resistor        */
	char *name;
	/* alloc a new component, and initialize it      */  		
	int (*init) (struct compinfo *comp, void *value);

        /* map a string named pin                         */
	int (*str_to_pin_gid) (struct compinfo *comp,char *s);         
        /* map a digit  named pin                         */
	int (*pin_to_pin_gid) (struct compinfo *comp,int pin); 
	
        /* volatge between pins,return constant item      */
	VA_value_t (*U_eq) (struct compinfo *comp,int pin_gid1,int pin_gid2,void * ); 

        /* current eqation entering pin                   */
	VA_value_t (*I_eq) (struct compinfo *comp,int pin_gid, void * ); 

        /* extra eqations,e.g. a transistor, Ic+Ib=Ie     */
	void (*add_supp_eq) (struct compinfo *comp );		

        /* number of I's, also the number of elements of pin_cur_map */
	int n_curs;		

        /* number of pins, also the number of elements of pin_cur_map */
	int n_pins;	

	/* extra size for component local state              */
	int extra_bytes;
	
	/* enumerates pins falls in a same network           */
	int (*sibling_first) (struct compinfo *comp, int pin_gid );
	int (*sibling_next) (struct compinfo *comp, int pin_gid, int last_gid );
	
	/* whether voltage eq applicable between two pins    */
	int (*voltage_eq_ok) (struct compinfo *comp, int pin_gid1, int pin_gid2 );

	/* update state of the component */
	int (*sync) (struct compinfo *comp );
	
	/* before update state of the component, check whether the new state is valid */
	int (*validate) (struct compinfo *comp );	
	
	/* is the pin a special pin? VCC,GND,IOPORT,...           */
	comp_pintype_t (*pin_type) (struct compinfo *comp, int pin_gid );	
} compclass_t;


compclass_t *get_class (char *); /* checkout a compclass struct  */
int add_class (compclass_t *);   /* checkin  a compclass struct  */

/* a component instance */
typedef struct compinfo {
	compclass_t *class;
	char *label;
	int pins_start;         /* first global net id allocated */
	int vars_start;         /* first global curr id allocated */	
	/* variable parts, intepreted by comp class              */
} comp_t;

comp_t *new_component (compclass_t *class, char *label, void *value ); 
comp_t *new_component_by_name (char *class, char *label, void *value ); 
comp_t *new_basic_component (comptype_t type, char *label, VA_value_t value ); 
comp_t *get_component (char *label);
 
#define CLASS(p) (p->class)
#define VOLTAGE_OK(p,m,n) (!(p)->class->voltage_eq_ok  \
			   || (p)->class->voltage_eq_ok (p,m,n))
 
/* define a structure to help net list construction */
typedef struct comp {
	comptype_t type; 
	union {
		VA_value_t f;
		compclass_t *class;
	}value; 
} comp_def;


#endif      /*    __COMPONENT_H__    */ 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -