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

📄 liftmon_snowcon_rpxcllf.c.txt

📁 这是《嵌入式linux-硬件、软件与接口》一书对应的所有linux方面实例的源代码
💻 TXT
📖 第 1 页 / 共 2 页
字号:
 * write_proc and owner, are filled.  Then the I/O controller is configured
 * so PA0 is an output and the memory controller works slowly with /CS5.
 * It 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;


/* get the register base address */
  immap = (immap_t *)(mfspr(IMMR) & 0xFFFF0000);

/* set CS5 for memory at 0x80000000, see 16.4.1 Base Registers (BRx)
 * and 16.4.2 Option Registers (ORx) for slow operation
 */
  immap->im_memctl.memc_br5 = 0x80000401;
  immap->im_memctl.memc_or5 = 0x80000FF6;

/* get the remapped GPIO controller base address register */
  io_base = ioremap_nocache(EXPANSIONPORT, EXPANSIONPORTLEN);

/* initialize snowcondata to 0xFF, all output modules off */
/* output modules invert */
  snowcondata = 0xFF;
  writeb(snowcondata, io_base);

  immap->im_ioport.iop_papar &= ~PA0; /* setting PA0 to general I/O */
  immap->im_ioport.iop_padir |=  PA0; /* make PA0 an output         */
  immap->im_ioport.iop_padat &= ~PA0; /* enable the 74HC574 output  */

  printk("immr    = 0x%08X\n",immap);
  printk("io_base = 0x%08X\n", io_base);
  printk("BR5     = 0x%08X\n",immap->im_memctl.memc_br5);
  printk("OR5     = 0x%08X\n",immap->im_memctl.memc_or5);
  printk("PAPAR   = 0x%04X\n",immap->im_ioport.iop_papar);
  printk("PADIR   = 0x%04X\n",immap->im_ioport.iop_padir);

/* 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 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)
{
  immap->im_ioport.iop_padir &= ~PA0; /* make PA0 an input */

/* release the ioremap */
  iounmap(io_base);

/* 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);

  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 Snowmaking Control for RPX-CLLF");

EXPORT_NO_SYMBOLS;

⌨️ 快捷键说明

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