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

📄 liftmon_snowcon.c

📁 《嵌入式Linux-硬件
💻 C
📖 第 1 页 / 共 2 页
字号:
                                 int count, int *eof, void *data){  struct liftmon_snowcon_data_t *liftmon_snowcon_data =                                 (struct liftmon_snowcon_data_t *)data;/* mask the snowcondata value based on the mask. Each mask is different  * depending which /proc/trailblazer file was read. */  if ( snowcondata & liftmon_snowcon_data->mask )    page[0] = '1';  else    page[0] = '0';/* return the length */  return 1;}/* init - init_liftmon_snowcon * init_liftmon_snowcon creates the /proc entry files and obtains * their pointers. For each file, the fields, data, read_proc,  * write_proc and owner, are filled.  init_liftmon_snowcon  * initializes the output modules in the off state then * completes by writing an entry to the system log using printk. */static int __init init_liftmon_snowcon(void){  int rv = 0;/* Create the trailblazer /proc entry */  tb_dir = proc_mkdir("trailblazer", NULL);  if(tb_dir == NULL) {    rv = -ENOMEM;    goto out;  }  tb_dir->owner = THIS_MODULE;/* Create liftacmains and make it readable by all - 0444 */  liftacmains_file = create_proc_entry("liftacmains", 0444, tb_dir);  if(liftacmains_file == NULL) {    rv = -ENOMEM;    goto no_liftacmains;  }  liftacmains_data.mask = LIFTACMAINS;  liftacmains_file->data = &liftacmains_data;  liftacmains_file->read_proc = &proc_read_liftmon;  liftacmains_file->write_proc = NULL;  liftacmains_file->owner = THIS_MODULE;/* Create liftmotorcontroller and make it readable by all - 0444 */  liftmotorcontroller_file = create_proc_entry("liftmotorcontroller",                                                 0444, tb_dir);  if(liftmotorcontroller_file == NULL) {    rv = -ENOMEM;    goto no_liftmotorcontroller;  }  liftmotorcontroller_data.mask = LIFTMOTORCONTROLLER;  liftmotorcontroller_file->data = &liftmotorcontroller_data;  liftmotorcontroller_file->read_proc = &proc_read_liftmon;  liftmotorcontroller_file->write_proc = NULL;  liftmotorcontroller_file->owner = THIS_MODULE;/* Create liftslowspeed and make it readable by all - 0444 */  liftslowspeed_file = create_proc_entry("liftslowspeed", 0444, tb_dir);  if(liftslowspeed_file == NULL) {    rv = -ENOMEM;    goto no_liftslowspeed;  }  liftslowspeed_data.mask = LIFTSLOWSPEED;  liftslowspeed_file->data = &liftslowspeed_data;  liftslowspeed_file->read_proc = &proc_read_liftmon;  liftslowspeed_file->write_proc = NULL;  liftslowspeed_file->owner = THIS_MODULE;/* Create lifthighspeed and make it readable by all - 0444 */  lifthighspeed_file = create_proc_entry("lifthighspeed", 0444, tb_dir);  if(lifthighspeed_file == NULL) {    rv = -ENOMEM;    goto no_lifthighspeed;  }  lifthighspeed_data.mask = LIFTHIGHSPEED;  lifthighspeed_file->data = &lifthighspeed_data;  lifthighspeed_file->read_proc = &proc_read_liftmon;  lifthighspeed_file->write_proc = NULL;  lifthighspeed_file->owner = THIS_MODULE;/* Create liftoperatorswitchbase and make it readable by all - 0444 */  liftoperatorswitchbase_file = create_proc_entry("liftoperatorswitchbase",                                                   0444, tb_dir);  if(liftoperatorswitchbase_file == NULL) {    rv = -ENOMEM;    goto no_liftoperatorswitchbase;  }  liftoperatorswitchbase_data.mask = LIFTOPERATORSWITCHBASE;  liftoperatorswitchbase_file->data = &liftoperatorswitchbase_data;  liftoperatorswitchbase_file->read_proc = &proc_read_liftmon;  liftoperatorswitchbase_file->write_proc = NULL;  liftoperatorswitchbase_file->owner = THIS_MODULE;/* Create liftoperatorswitchtop and make it readable by all - 0444 */  liftoperatorswitchtop_file = create_proc_entry("liftoperatorswitchtop",                                                  0444, tb_dir);  if(liftoperatorswitchtop_file == NULL) {    rv = -ENOMEM;    goto no_liftoperatorswitchtop;  }  liftoperatorswitchtop_data.mask = LIFTOPERATORSWITCHTOP;  liftoperatorswitchtop_file->data = &liftoperatorswitchtop_data;  liftoperatorswitchtop_file->read_proc = &proc_read_liftmon;  liftoperatorswitchtop_file->write_proc = NULL;  liftoperatorswitchtop_file->owner = THIS_MODULE;/* Create snowwatervalve1 and make it root writeable, readable by all-0644 */  snowwatervalve1_file = create_proc_entry("snowwatervalve1", 0644, tb_dir);  if(snowwatervalve1_file == NULL) {    rv = -ENOMEM;    goto no_snowwatervalve1;  }  snowwatervalve1_data.mask = SNOWWATERVALVE1;  snowwatervalve1_file->data = &snowwatervalve1_data;  snowwatervalve1_file->read_proc = &proc_read_snowcondata;  snowwatervalve1_file->write_proc = &proc_write_snowcondata;  snowwatervalve1_file->owner = THIS_MODULE;/* Create snowwatervalve2 and make it root writeable, readable by all-0644 */  snowwatervalve2_file = create_proc_entry("snowwatervalve2", 0644, tb_dir);  if(snowwatervalve2_file == NULL) {    rv = -ENOMEM;    goto no_snowwatervalve2;  }  snowwatervalve2_data.mask = SNOWWATERVALVE2;  snowwatervalve2_file->data = &snowwatervalve2_data;  snowwatervalve2_file->read_proc = &proc_read_snowcondata;  snowwatervalve2_file->write_proc = &proc_write_snowcondata;  snowwatervalve2_file->owner = THIS_MODULE;/* Create snowwatervalve3 and make it root writeable, readable by all-0644 */  snowwatervalve3_file = create_proc_entry("snowwatervalve3", 0644, tb_dir);  if(snowwatervalve3_file == NULL) {    rv = -ENOMEM;    goto no_snowwatervalve3;  }  snowwatervalve3_data.mask = SNOWWATERVALVE3;  snowwatervalve3_file->data = &snowwatervalve3_data;  snowwatervalve3_file->read_proc = &proc_read_snowcondata;  snowwatervalve3_file->write_proc = &proc_write_snowcondata;  snowwatervalve3_file->owner = THIS_MODULE;/* Create snowheater1 and make it root writeable, readable by all-0644 */  snowheater1_file = create_proc_entry("snowheater1", 0644, tb_dir);  if(snowheater1_file == NULL) {    rv = -ENOMEM;    goto no_snowheater1;  }  snowheater1_data.mask = SNOWHEATER1;  snowheater1_file->data = &snowheater1_data;  snowheater1_file->read_proc = &proc_read_snowcondata;  snowheater1_file->write_proc = &proc_write_snowcondata;  snowheater1_file->owner = THIS_MODULE;/* initialize snowcondata to 0, all output modules off */  snowcondata = 0;/* initialize the control port to know value 0 */   outb(0, SPPCONTROLPORT);/* put snowcondata on the data bus */   outb(snowcondata, SPPDATAPORT);/* latch it first before we turn on the output modules */  outb(OUTPUTLATCH, SPPCONTROLPORT);/* turn on the latch output to drive the output modules */  outb(OUTPUTENABLE,SPPCONTROLPORT); /* everything initialized */  printk(KERN_INFO "%s %s initialized\n", MODULE_NAME, MODULE_VERSION);  return 0;/* this removes /proc entries if we have an error along the way */no_snowheater1:  remove_proc_entry("snowwatervalve3", tb_dir);no_snowwatervalve3:  remove_proc_entry("snowwatervalve2", tb_dir);no_snowwatervalve2:  remove_proc_entry("snowwatervalve1", tb_dir);no_snowwatervalve1:  remove_proc_entry("liftoperatorswitchtop", tb_dir);no_liftoperatorswitchtop:  remove_proc_entry("liftoperatorswitchbase", tb_dir);no_liftoperatorswitchbase:  remove_proc_entry("lifthighspeed", tb_dir);no_lifthighspeed:  remove_proc_entry("liftslowspeed", tb_dir);no_liftslowspeed:  remove_proc_entry("liftmotorcontroller", tb_dir);no_liftmotorcontroller:  remove_proc_entry("liftacmains", tb_dir);no_liftacmains:  remove_proc_entry("trailblazer", NULL);out:  return rv;}/* exit - cleanup_liftmon_snowcon * cleanup_liftmon_snowcon turns off the output modules and * deasserts the OUTPUT_ENABLE signal. It removes the /proc entry files * prints a message to the system log. */static void __exit cleanup_liftmon_snowcon(void){/* this turns off all the output modules */  outb(0, SPPCONTROLPORT);  outb(0, SPPDATAPORT);  outb(OUTPUTLATCH, SPPCONTROLPORT);  outb(0,SPPCONTROLPORT);/* removing the /proc entries */  remove_proc_entry("liftacmains", tb_dir);  remove_proc_entry("liftmotorcontroller", tb_dir);  remove_proc_entry("liftslowspeed", tb_dir);  remove_proc_entry("lifthighspeed", tb_dir);  remove_proc_entry("liftoperatorswitchbase", tb_dir);  remove_proc_entry("liftoperatorswitchtop", tb_dir);  remove_proc_entry("snowwatervalve1", tb_dir);  remove_proc_entry("snowwatervalve2", tb_dir);  remove_proc_entry("snowwatervalve3", tb_dir);  remove_proc_entry("snowheater1", tb_dir);  remove_proc_entry("trailblazer", NULL);/* we're done */  printk(KERN_INFO "%s %s removed\n", MODULE_NAME, MODULE_VERSION);}module_init(init_liftmon_snowcon);module_exit(cleanup_liftmon_snowcon);MODULE_AUTHOR("Craig Hollabaugh");MODULE_DESCRIPTION("Trailblazer Lift Monitor and Snow-making Control");EXPORT_NO_SYMBOLS;

⌨️ 快捷键说明

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