LECTURE 8 I/O ¥Ý¡¼¥È¤ÎÀ©¸æ

¡û ¤Ï¤¸¤á¤Ë

¤³¤³¤Þ¤Ç¤ÎÆâÍƤǤϡ¢¥Ç¥Ð¥¤¥¹¥É¥é¥¤¥Ð¤È¸À¤Ã¤Æ¤â¥½¥Õ¥È¥¦¥§¥¢¤Ç´°·ë¤·¤Æ¤·¤Þ¤¦ÆâÍƤФ«¤ê¤Ç¤·¤¿¡£¤³¤³¤Ç¤Ï¡¢¼ÂºÝ¤Ë¥Ï¡¼¥É¥¦¥§¥¢¤òÀ©¸æ¤·¤Æ¤ß¤ë¤³¤È¤Ç¡¢¥Ç¥Ð¥¤¥¹¥É¥é¥¤¥Ð¤é¤·¤¤ÆâÍƤˤ·¤Æ¤ß¤¿¤¤¤È»×¤¤¤Þ¤¹¡£

¶ñÂÎŪ¤Ë¤Ï¡¢PC ¤ËÉÕ¤¤¤Æ¤¤¤ë ( ºÇ¶á¤Î PC ¤Ç¤Ï̵¤¤¤«¤â¤·¤ì¤Þ¤»¤ó¤¬¡£¡£¡£ ) ¥Ñ¥é¥ì¥ë¥Ý¡¼¥È ( ¥×¥ê¥ó¥¿¥Ý¡¼¥È ) ¤Ë¡¢¼«ºî¤Î´Êñ¤ÊÅŻҲóÏ©¤òÀܳ¤·¤Þ¤¹¡£¤½¤·¤Æ¡¢¤½¤ì¤òÀ©¸æ¤¹¤ë¤¿¤á¤Î¥Ç¥Ð¥¤¥¹¥É¥é¥¤¥Ð¤òºîÀ®¤·¤Þ¤¹¡£

CPU ¤«¤é¼þÊÕµ¡´ï¤òÀ©¸æ¤¹¤ë¾ì¹ç¡¢Ä̾ï¤Î¥á¥â¥ê¶õ´Ö¤Ë I/O ¥Ý¡¼¥È¤¬¥Þ¥Ã¥Ô¥ó¥°¤µ¤ì¤Æ¤ª¤ê¥á¥â¥ê¤È¥Ç¡¼¥¿¤ò¤ä¤ê¤È¤ê¤¹¤ë´¶³Ð¤ÇÀ©¸æ¤¹¤ëÊýË¡¤È¡¢Æþ½ÐÎÏÀìÍѤΥ¢¥É¥ì¥¹¶õ´Ö¤ËÂФ·¤ÆÀìÍѤÎÌ¿Îá¤Ç¥Ç¡¼¥¿¤ò¤ä¤ê¤È¤ê¤¹¤ëÊýË¡¤¬¤¢¤ê¤Þ¤¹¡£¸å¼Ô¤Î¾ì¹ç¡¢Æþ½ÐÎÏÀìÍѤΥ¢¥É¥ì¥¹¶õ´Ö¤ò I/O ¥¢¥É¥ì¥¹¤È¸Æ¤Ó¡¢¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤ÎÀ©¸æ¤Ï¸å¼Ô¤ÎÊýË¡¤Ç¹Ô¤¤¤Þ¤¹¡£

¤³¤Î¥Ú¡¼¥¸¤ÎÆâÍƤϼ«ºî¤ÎÅŻҲóÏ©¤ò·Ò¤°¤È¤¤¤¦À­¼Á¾å¡¢¼ºÇÔ¤¹¤ë¤È¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤ä¥Þ¥¶¡¼¥Ü¡¼¥É¤¬Â»½ý¤¹¤ë²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£Âç¾æÉפÊÍͤ˽ñ¤¤¤Æ¤¤¤ë¤Ä¤â¤ê¤Ç¤Ï¤¤¤Þ¤¹¤¬¡¢É®¼Ô¤ÏÀÕǤ¤òÉ館¤Þ¤»¤ó¤Î¤Ç¡¢¼«¸ÊÀÕǤ¤ò¤È¤ì¤Ê¤¤¾õ¶·¤Ç¤Ï¹Ô¤ï¤Ê¤¤¤Ç¤¯¤À¤µ¤¤¡£¤Þ¤¿¡¢ºÇ°­¤Î¾ì¹ç¤Ç¤â»½ý¤·¤Æ¤Ïº¤¤ëÍÍ¤Ê PC ¤Ç¹Ô¤¦¤Î¤â»ß¤á¤¿Êý¤¬Îɤ¤¤«¤â¤·¤ì¤Þ¤»¤ó¡£

¡û ¥Ñ¥é¥ì¥ë¥Ý¡¼¥È ( ¥×¥ê¥ó¥¿¥Ý¡¼¥È )

PC ¤Î¥Ñ¥é¥ì¥ë¥Ý¡¼¥È ( ¥×¥ê¥ó¥¿¥Ý¡¼¥È ) ¤Ë¤Ä¤¤¤Æ¡¢¤Þ¤ºÀâÌÀ¤·¤Þ¤¹¡£¤¿¤À¤·¡¢¥×¥ê¥ó¥¿¤È¤Î¤ä¤ê¤È¤ê¤ò¹Ô¤¦¤¿¤á¤ÎÀâÌÀ¤Ç¤Ï¤Ê¤¯¡¢Ã±½ã¤Ë I/O À©¸æ¤ò¹Ô¤¦°Ù¤ËɬÍפʻö¹à¤Î¤ßÀâÌÀ¤·¤Þ¤¹¡£

¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤¿¤á¤Î I/O ¥¢¥É¥ì¥¹¤Ï BIOS ¤ÎÀßÄêÅù¤Ë¤è¤Ã¤ÆÊѲ½¤¹¤ë¤Î¤Ç¤¹¤¬¡¢Ä̾ï 0x378 ¤«¤é»Ï¤Þ¤ë 3 ¥Ð¥¤¥È¤Î¥¢¥É¥ì¥¹¶õ´Ö¤Ë¥Þ¥Ã¥Ô¥ó¥°¤µ¤ì¤Æ¤¤¤ë¤È»×¤¤¤Þ¤¹¡£¤³¤Î³«»Ï¥¢¥É¥ì¥¹¤Î¤³¤È¤ò¥Ù¡¼¥¹¥¢¥É¥ì¥¹¤È¸Æ¤Ó¤Þ¤¹¡£

°Ê¹ß¡¢ËÜ Web ¤Ç¤Ï¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î¥Ù¡¼¥¹¥¢¥É¥ì¥¹¤Ï 0x378 ¤Ç¤¢¤ë¤È¤·¤ÆÀâÌÀ¤·¤Þ¤¹¤¬¡¢¤³¤Î 0x378 ¤È¤¤¤¦ÃͤϤª»È¤¤¤Î´Ä¶­¤Ë¤è¤Ã¤ÆÊѤï¤ê¤Þ¤¹¤Î¤Ç¡¢Ãí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£

--- ¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î¥Ô¥óÇÛÃÖ¿Þ ---

¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î¥Ô¥óÇÛÃÖ¿Þ

¾å¤Î¥Ô¥óÇÛÃֿޤǤϡ¢´ØÏ¢¤¹¤ë¥Ô¥ó¤ò¥°¥ë¡¼¥×²½¤·¤Æ¤Þ¤¹ ( ĹÊý·Á¤Ç°Ï¤ó¤Ç¤¢¤ë )¡£³Æ¥°¥ë¡¼¥×¤Î¾ÜºÙ¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£

  • ¥Ç¡¼¥¿¥Ý¡¼¥È ( ¥Ô¥ó 2 - 9 )

    Æþ½ÐÎÏÍѤΥݡ¼¥È¤Ç¤¹¡£I/O ¥¢¥É¥ì¥¹¤Ï ( ¥Ù¡¼¥¹¥¢¥É¥ì¥¹ + 0 ) ¤Ç¤¹¡£ ¤³¤Î 1 ¥Ð¥¤¥ÈÃͤˤª¤±¤ë¥Ô¥ó¤È¥Ó¥Ã¥È¤Î¥Þ¥Ã¥Ô¥ó¥°¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£

    ¥Ó¥Ã¥ÈÈÖ¹æ 7 6 5 4 3 2 1 0
    ¥Ô¥óÈÖ¹æ 9 8 7 6 5 4 3 2
    ¥Ó¥Ã¥ÈÃͤ¬ 1 ¤Î»þ¤ÎÅÅ°µ High High High High High High High High

  • ¥¹¥Æ¡¼¥¿¥¹¥Ý¡¼¥È ( ¥Ô¥ó 10 - 13¡¢15 )

    Æɤ߹þ¤ßÀìÍѤΥݡ¼¥È¤Ç¤¹¡£I/O ¥¢¥É¥ì¥¹¤Ï ( ¥Ù¡¼¥¹¥¢¥É¥ì¥¹ + 1 ) ¤Ç¤¹¡£ ¤³¤Î 1 ¥Ð¥¤¥ÈÃͤˤª¤±¤ë¥Ô¥ó¤È¥Ó¥Ã¥È¤Î¥Þ¥Ã¥Ô¥ó¥°¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£

    ¥Ó¥Ã¥ÈÈÖ¹æ 7 6 5 4 3 2 1 0
    ¥Ô¥óÈÖ¹æ 11 10 12 13 15 - - -
    ̾¾Î -Busy -Acknowledge (-ACK) Paper End (PE) Select (SLCT) -Error -IRQ Status ͽÌó ͽÌó
    ¥Ó¥Ã¥ÈÃͤ¬ 1 ¤Î»þ¤ÎÅÅ°µ Low High High High High - - -

    PC ¥ª¡¼¥×¥ó¡¦¥¢¡¼¥­¥Æ¥¯¥Á¥ã¡¼¿ä¿Ê¶¨µÄ²ñ ¤Î¥Æ¥¯¥Ë¥«¥ë¥ê¥Õ¥¡¥ì¥ó¥¹¤Ë¤è¤ë¤È¡¢¥Ó¥Ã¥È2 ¤Î -IRQ Status ¤Ï 0 ¤Ë¥»¥Ã¥È¤µ¤ì¤ë¤È³ä¤ê¹þ¤ß¤¬ÊÝα¤Ë¤Ê¤ëÍͤǤ¹¡£¤Þ¤¿¡¢¥³¥ó¥È¥í¡¼¥ë¥Ý¡¼¥È¤Î¥Ó¥Ã¥È 4 ¤ò 1 ¤È¤·¤Æ³ä¤ê¹þ¤ß¤òÍ­¸ú¤Ë¤·¤¿¾ì¹ç¥¹¥Æ¡¼¥¿¥¹¥Ý¡¼¥È¤Î¥Ó¥Ã¥È 6 ¤¬ Low ¤«¤é High ¤ËÊѤï¤ëºÝ¤Ë³ä¤ê¹þ¤ß¤¬È¯À¸¤·¤Þ¤¹¤¬¡¢¤³¤Î»þ¤Ë¥¹¥Æ¡¼¥¿¥¹¥Ý¡¼¥È¤Î¥Ó¥Ã¥È 2 -IRQ Status ¤¬ 0 ¤Ë¤Ê¤ëÍͤǤ¹¡£1 ¤Ë¥»¥Ã¥È¤·¤Ê¤¤¤È°Ê¸å¤Î³ä¤ê¹þ¤ß¤¬ÊÝᤵ¤ì¤Æ¤·¤Þ¤¤¤Þ¤¹¡£1 ¤Ë¥»¥Ã¥È¤¹¤ë¤¿¤á¤Ë¤Ï¥¹¥Æ¡¼¥¿¥¹¥Ý¡¼¥È¤ÎÆɤ߽Ф·¤ò¹Ô¤¦É¬Íפ¬¤¢¤ê¤Þ¤¹¡£

    ¢¬2008/08/11 ³Æ¥Ó¥Ã¥È¤Î̾¾Î¤È³ä¤ê¹þ¤ßÊÝα¤Ë¤Ä¤¤¤ÆÄɵ­¤·¤Þ¤·¤¿¡£³ä¤ê¹þ¤ßÊÝα¤Ë¤Ä¤¤¤Æ¡¢ÌÚ¸¶¤µ¤ó¤É¤¦¤â¤¢¤ê¤¬¤È¤¦¤´¤¶¤¤¤Þ¤·¤¿¡£

  • ¥³¥ó¥È¥í¡¼¥ë¥Ý¡¼¥È ( ¥Ô¥ó 1¡¢14¡¢16 - 17 )

    ½ÐÎÏÀìÍѤÎÀ©¸æÍѥݡ¼¥È¤Ç¤¹¡£I/O ¥¢¥É¥ì¥¹¤Ï ( ¥Ù¡¼¥¹¥¢¥É¥ì¥¹ + 2 ) ¤Ç¤¹¡£ ¤³¤³¤Î 1 ¥Ð¥¤¥ÈÃͤˤª¤±¤ë¥Ô¥ó¤È¥Ó¥Ã¥È¤Î¥Þ¥Ã¥Ô¥ó¥°¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£

    ¥Ó¥Ã¥ÈÈÖ¹æ 7 6 5 4 3 2 1 0
    ¥Ô¥óÈÖ¹æ - - - - 17 16 14 1
    ̾¾Î ͽÌó ͽÌó Direction IRQ EN SLCT IN -INIT AUTO FD XT STROBE
    Æõ­»ö¹à - - - ¤³¤³¤ò 1 ¤ËÀßÄꤹ¤ë¤È¡¢10 ¥Ô¥ó(-ACK) ¤¬ Low ¤«¤é High ¤ËÊѲ½¤·¤¿»þ¤Ë³ä¤ê¹þ¤ß¤¬È¯À¸¤¹¤ë - - - -
    ¥Ó¥Ã¥ÈÃͤ¬ 1 ¤Î»þ¤ÎÅÅ°µ - - - - Low High Low Low

    ¢¬2008/08/11 ³Æ¥Ó¥Ã¥È¤Î̾¾Î¤È¡¢Æõ­»ö¹à¤Ë¤Ä¤¤¤ÆÄɵ­¤·¤Þ¤·¤¿¡£

  • GND ( ¥Ô¥ó 18 - 25 )

    GND ¤Ë·Ò¤¬¤ì¤Æ¤¤¤Þ¤¹¡£

¤Ê¤ª¡¢Äê³ÊÅÅ°µ / ÅÅή¤Ë¤Ä¤¤¤Æ¤Ï¡¢ PC ¥ª¡¼¥×¥ó¡¦¥¢¡¼¥­¥Æ¥¯¥Á¥ã¡¼¿ä¿Ê¶¨µÄ²ñ ¤Î¥Æ¥¯¥Ë¥«¥ë¥ê¥Õ¥¡¥ì¥ó¥¹¤ò°úÍѤ¹¤ë¤È

  • ¥Ç¡¼¥¿¥Ý¡¼¥È / ¥¹¥Æ¡¼¥¿¥¹¥Ý¡¼¥È
    ¹àÌÜ̾ ÃÍ
    Sink Current ( Maximum ) 12mA
    Source Current ( Maximum ) 2mA
    High-level Output Voltage ( Minimum ) 2.4V dc
    Low-level Output Voltage ( Maximum ) 0.5V dc

  • ¥³¥ó¥È¥í¡¼¥ë¥Ý¡¼¥È
    ¹àÌÜ̾ ÃÍ
    Sink Current ( Maximum ) 10mA
    Source Current ( Maximum ) 0.2mA
    High-level Output Voltage ( Minimum ) 5.0V dc minus pullup
    Low-level Output Voltage ( Maximum ) 0.5V dc

¤È¤Ê¤Ã¤Æ¤¤¤ë¤ß¤¿¤¤¤Ç¤¹¡£Sink Current ¤Ï¡¢¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î¥Ô¥óÅÅ°µ¤¬ Low ¤Ç³°Éô²óϩü»Ò¤ÎÅÅ°µ¤¬ High ¤Î¾ì¹ç¤Ë¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Ëή¤ì¹þ¤àÅÅή¤Ç¡¢Source Current ¤ÏµÕ¤Ë¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î¥Ô¥óÅÅ°µ¤¬ High ¤Ç³°Éô²óϩü»Ò¤ÎÅÅ°µ¤¬ Low ¤Î¾ì¹ç¤Ë¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤«¤éή¤ì½Ð¤¹ÅÅή¤Î¤³¤È¤Ç¤¹¡£

¡û ¼«ºîÅŻҲóÏ©¤Î¾Ò²ð

ËÜ¥Ú¡¼¥¸¤Ç»ÈÍѤ¹¤ë¡¢¼«ºîÅŻҲóÏ©¤Î²óÏ©¿Þ¤ª¤è¤Ó²èÁü¤ò°Ê²¼¤Ë·ÇºÜ¤·¤Þ¤¹¡£

--- ²óÏ©¿Þ ---

²óÏ©¿Þ

¾å¤Î²óÏ©¿Þ¤Ï¡¢ ¿åµûƲ¤Î²óÏ©¿Þ¥¨¥Ç¥£¥¿ ¤ò»È¤Ã¤Æ½ñ¤¤¤Æ¤ß¤Þ¤·¤¿¡£

¥×¥Ã¥·¥å¥Ü¥¿¥ó¥¹¥¤¥Ã¥Á¤ÎÀܳ¤Ë¤Ä¤¤¤Æ¤Ï¡¢¥Á¥ã¥¿¥ê¥ó¥° ( ¥¹¥¤¥Ã¥Á¤Î ON / OFF »þ¤Ë¿®¹æ¤¬°ÂÄꤻ¤º¡¢Ã»»þ´Ö¤Ë ON / OFF ¤ò·«¤êÊÖ¤·¤¿Íͤʿ®¹æ¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¦¤³¤È ) Âкö¤ò¹Íθ¤·¤Æ¤¤¤Ê¤¤¤¿¤á¡¢¥×¥Ã¥·¥å¥Ü¥¿¥óÁàºî»þ¤ÎÆ°ºî¤ÏÉÔ°ÂÄ꤫¤â¤·¤ì¤Þ¤»¤ó¤¬¡¢¸æλ¾µ¤¯¤À¤µ¤¤¡£

²óÏ©¿ÞÃæ¤ÎÄñ¹³ÃͤòÁª¤ó¤ÀÍýͳ¤Ë¤Ä¤¤¤Æ¡¢´Êñ¤Ë½ñ¤¤¤Æ¤ª¤­¤Þ¤¹¡£R1 - R3 ¤Ï¡¢LED ¤Ëή¤ì¤ëÅÅήÃͤòÀ©¸Â¤¹¤ë¤¿¤á¤Ë LED ¤ËľÎó¤Ë·Ò¤°¤¿¤á¤ÎÄñ¹³¤Ç¤¹¡£LED ¤Ï¤¢¤ëÃͰʾå¤ÎÅÅή¤òή¤·Â³¤±¤ë¤È²õ¤ì¤Æ¤·¤Þ¤¦¤¿¤á¡¢Äñ¹³¤ò·Ò¤²¤ë¤³¤È¤Ç¶¯À©Åª¤Ë¤½¤ì°Ê²¼¤ÎÅÅή¤Ë¤·¤Æ¤¢¤²¤Þ¤¹¡£É®¼Ô¤¬»È¤Ã¤¿ LED ¤ÏºÇÂçÄê³ÊÅÅή¤¬ 30mA ¤Ç¤·¤¿¤Î¤Ç¡¢Í¾Íµ¤ò¸«¤Æ 10mA °Ê²¼¤Ë¤¹¤ë¤³¤È¤Ë¤·¤Þ¤¹¡£

LED ¤¬ÅÀÅô¤¹¤ë¤È 2V Á°¸åÅÅ°µ¤¬¹ß²¼¤¹¤ë¤Î¤Ç¡¢Äñ¹³¤Ë¤«¤«¤ëÅÅ°µ¤ÏºÇÂç¤ÇÌó

  5V ( ¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î High ÅÅ°µ ) - 2 = 3V

ÄøÅ٤Ȥʤë¤Î¤Ç¡¢¥ª¡¼¥à¤Îˡ§¤«¤éÄñ¹³ÃͤÏÌó

  R ( Äñ¹³ ) = E ( ÅÅ°µ ) / I ( ÅÅή ) = 3V / 0.01A = 300 ¦¸

¤È¤Ê¤ê¤Þ¤¹¡£

¡£¡£¡£¤È LED ¤À¤±¹Í¤¨¤ë¤È¤½¤¦¤Ê¤ë¤Î¤Ç¤¹¤¬¡¢¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤ÎÄê³Ê¤ò¹Í¤¨¤ë¤È¤½¤¦¤Ï¤¤¤­¤Þ¤»¤ó¡£Á°½Ò¤ÎÄê³ÊÃͤˤè¤ë¤È¡¢Source Current ¤¬ 2mA ¤È¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¾åµ­¤Î²óÏ©¤Ï¡¢¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î¥Ô¥ó¤¬ High ¤Î¾ì¹ç¤Ë LED ¤ËÅÅή¤¬Î®¤ì¤ë²óÏ©¤Ê¤Î¤Ç¡¢¤³¤Î Source Current ¤ò¼é¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£¤è¤Ã¤Æ¡¢ÅÅή¤ÎÌÜɸÃͤò 2mA °Ê²¼¤ËÀßÄꤷ¤Ê¤ª¤·¤Þ¤¹¡£

2mA ¤È¤¤¤¦ÃͤǤ¹¤¬¡¢PC ¥ª¡¼¥×¥ó¡¦¥¢¡¼¥­¥Æ¥¯¥Á¥ã¡¼¿ä¿Ê¶¨µÄ²ñ ¤Î¥Æ¥¯¥Ë¥«¥ë¥ê¥Õ¥¡¥ì¥ó¥¹¤Ë½¾¤¦¤È 2mA ¤Ç¤¹¤¬¡¢¤¤¤í¤ó¤Ê»ÅÍͤˤè¤Ã¤ÆÃͤ¬°ã¤¦¤ß¤¿¤¤¤Ç¤¹¤·¡¢¼ÂºÝ¤Î¥Ï¡¼¥É¥¦¥§¥¢¤Ë¤è¤Ã¤Æ¤â°Û¤Ê¤ë¤È»×¤¤¤Þ¤¹¡£¤ª»È¤¤¤Î¥Ï¡¼¥É¥¦¥§¥¢¤ÎÄê³Ê¤òÄ´¤Ù¤Æ·×»»¤·¤Ê¤ª¤¹¤³¤È¤ò¤ªÁ¦¤á¤·¤Þ¤¹¡£

  R ( Äñ¹³ ) = E ( ÅÅ°µ ) / I ( ÅÅή ) = 3V / 0.002A = 1.5K¦¸

¤È¤Ê¤ë¤Î¤Ç¡¢¤³¤ì¤è¤êÂ礭¤¤Äñ¹³¤Ç¤¢¤ì¤ÐÅÅή¤¬ 2mA °Ê²¼¤Ë¤Ê¤ë¤³¤È¤¬Ê¬¤«¤ê¤Þ¤¹¡£¤Ç²óÏ©¤ò¹Í¤¨¤¿»þ¤Ë¥«¥¿¥í¥°¤ò¸«¤Æ¤¿¤é¡¢2.2K¦¸ ¤È¤¤¤¦Äñ¹³Ãͤòȯ¸«¤·¤¿¤Î¤Ç¤½¤ÎÃͤòºÎÍѤ·¤Þ¤·¤¿¡£¤³¤Î¾ì¹ç¤ÎÅÅή¤ÏÌó

  I ( ÅÅή ) = E ( ÅÅ°µ ) / R ( Äñ¹³ ) = 3V / 2.2K¦¸ = 1.4mA

¤È¤Ê¤ê¡¢Í¾Íµ¤¬¤¢¤ë¤³¤È¤¬Ê¬¤«¤ê¤Þ¤¹¡£

¤Á¤Ê¤ß¤Ë¡¢LED ¤Ïή¤ì¤ëÅÅή¤Ë¤è¤Ã¤ÆÌÀ¤ë¤µ¤¬ÊѤï¤ê¤Þ¤¹¡£¤Î¤Ç¡¢10mA ¤È 1.4mA ¤Ç¤Ï·ë¹½ÌÀ¤ë¤µ¤¬°Û¤Ê¤ê¡¢°Å¤¯¤Ê¤Ã¤Æ¤·¤Þ¤¤¤Þ¤¹¡£É®¼Ô¤ÏºÇ½é²¿¤â¹Í¤¨¤º¤Ë 10mA ή¤ì¤ëÍͤ˲óÏ©¤òºî¤Ã¤Æ·Ò¤²¤¿¤Î¤Ç¤¹¤¬¡¢¤È¤Æ¤âÌÀ¤ë¤«¤Ã¤¿¤Ç¤¹¡£¤½¤Î¤¿¤á¡¢²óÏ©¤òºî¤ê¤Ê¤ª¤·¤Æ·Ò¤²¤¿»þ¤Ï¾¯¤·¼ä¤·¤«¤Ã¤¿¡£¡£¡£¤·¤«¤·¡¢¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Ï²õ¤ì¤ë¤³¤È̵¤¯Ìµ»ö¤ËÆ°¤¤¤Æ¤¤¤ë¤ß¤¿¤¤¤Ç¤¹¡°¡°¡¨

¼¡¤Ë R4 ¤Ë¤Ä¤¤¤Æ¤Ç¤¹¤¬¡¢¤³¤ÎÄñ¹³¤Ï¥×¥ë¥¢¥Ã¥×Äñ¹³¤È¤¤¤¦ÌòÌܤò»ý¤Ã¤Æ¤¤¤Þ¤¹¡£¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î 10 ÈÖ¥Ô¥ó ( ¥³¥Í¥¯¥¿¤Î 5 ÈÖ¥Ô¥ó ) ¤Ë¥×¥Ã¥·¥å¥Ü¥¿¥ó¥¹¥¤¥Ã¥Á¤òÀܳ¤·¤Æ¤¤¤ë¤Î¤Ç¤¹¤¬¡¢¤½¤ì¤À¤±¤À¤È¥¹¥¤¥Ã¥Á¤¬ OFF ¤Î¾ì¹ç¤ËÆþÎÏÅÅ°µ¤¬ÉÔ°ÂÄê¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¤¤Þ¤¹ ( ¤É¤³¤Ë¤â·Ò¤¬¤Ã¤Æ¤¤¤Ê¤¤¤«¤é )¡£¤½¤Î¤¿¤á¡¢¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î5 ÈÖ¥Ô¥ó ( ¥³¥Í¥¯¥¿¤Î 4 ÈÖ¥Ô¥ó ) ¤ò¡Ê ºîÀ®¤¹¤ë¥×¥í¥°¥é¥à¤Ë¤è¤Ã¤Æ ) ¾ï»þ High ¤Ë¤·¤Æ¤ª¤­¤½¤³¤Ë·Ò¤²¤Æ¤ª¤¯¤³¤È¤Ç¡¢³Î¼Â¤Ë¥¹¥¤¥Ã¥Á OFF ¤Î¾ì¹ç¤Ï High¡¢ON ¤Î¾ì¹ç¤Ï LOW ¤È¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤³¤Î»þ¡¢Ä¾·ë¤¹¤ë¤ÈËÄÂç¤ÊÅÅή¤¬Î®¤ì¤ë¤¿¤á¡¢Å¬Åö¤ÊÄñ¹³¤òÆþ¤ì¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£ÅÅ°µ¤ò°ú¤­¾å¤²¤ëÄñ¹³¤È¤¤¤¦°ÕÌ£¤Ç¡¢¥×¥ë¥¢¥Ã¥×Äñ¹³¤È¸Æ¤Ð¤ì¤Þ¤¹¡£

ɬÍפÊÄñ¹³ÃͤÏ

  R ( Äñ¹³ ) = E ( ÅÅ°µ ) / I ( ÅÅή ) = 5V / 0.002A = 2.5K¦¸

°Ê¾å¤È¤Ê¤ê¤Þ¤¹¡£²óÏ©¤Ç¤Ï 10K¦¸ ¤òºÎÍѤ·¤Þ¤·¤¿¤¬¡¢ÅÅή¤¬¾®¤µ¤¹¤®¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡£ÅÅή¤¬¾®¤µ¤¹¤®¤ë¤È¡¢¥Î¥¤¥º¤Ë¼å¤«¤Ã¤¿¤ê High ¤òÊݤİ٤ÎÅÅή¤ËËþ¤¿¤Ê¤¤²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£¤â¤·¤«¤·¤¿¤é 5K¦¸¤°¤é¤¤¤ÎÊý¤¬¤¤¤¤¤«¤â¤·¤ì¤Þ¤»¤ó¤¬¡¢É®¼Ô¤â¼«¿®¤¬¤¢¤Þ¤ê¤¢¤ê¤Þ¤»¤ó¡°¡°¡¨¤Á¤Ê¤ß¤Ë¼Â¸³»þ¤ÏÌäÂê¤Ê¤¯Æ°¤¤¤Æ¤Þ¤·¤¿¡£

--- ÅŻҲóÏ© ---

ÅŻҲóÏ©

¤³¤ì¤¬É®¼Ô¤¬ºîÀ®¤·¤¿ÅŻҲóÏ©¤Î¼Ì¿¿¤Ç¤¹¡£Äñ¹³¤Î¿ô¤¬Â¿¤¤ ( R1 - R3 ¤Ë 2 ¸Ä¤º¤Ä»È¤Ã¤Æ¤¤¤ë ) ¤Ç¤¹¤¬¡¢¤³¤ì¤Ï 1K¦¸ ¤ÎÄñ¹³¤òľÎó¤Ë·Ò¤¤¤Ç̵ÍýÌðÍý 2K¦¸ ¤Ë¤·¤Æ¤¤¤ë¤«¤é¤Ç¤¹¡£

--- LED ȯ¸÷Ãæ ---

LED ȯ¸÷Ãæ

¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò»È¤Ã¤Æ¡¢LED ¤òÅÀÅô¤µ¤»¤¿¾õÂ֤Ǥ¹¡£º£²ó¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤Ï¡¢¥Ç¥Ð¥¤¥¹¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤ß¤ò¹Ô¤¦Å٤˰ìÈÖ¾å¤Î LED ¤¬ÅÀÅô / ¾ÃÅô¤ò·«¤êÊÖ¤·¡¢¿¿Ãæ¤Î LED ¤¬ 1 ÉÃËè¤ËÅÀÅô / ¾ÃÅô¤ò·«¤êÊÖ¤·¤Þ¤¹¡£¤Þ¤¿¡¢¥Ç¥Ð¥¤¥¹¥Õ¥¡¥¤¥ë¤«¤éÆɤ߹þ¤ß¤ò¹Ô¤¦¤È¡¢¤½¤Î»þ¤Î¥×¥Ã¥·¥å¥Ü¥¿¥ó¥¹¥¤¥Ã¥Á¤Î¾õÂÖ¤¬Ê¬¤«¤ê¤Þ¤¹¡£

¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à

¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤ËÀܳ¤·¤¿¼«ºîÅŻҲóÏ©¤òÀ©¸æ¤¹¤ë¤¿¤á¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à hw_io.h¡¢hw_io.c ¡¢hw_main.c ¤Ç¤¹¡£ ¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤é¡¢ Á´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò ¸Ç¤á¤¿ tar ¥Ü¡¼¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

gcc -DMODULE -D__KERNEL__ -O -c hw_io.c
gcc -DMODULE -D__KERNEL__ -O -c hw_main.c
ld -r -o hw.o hw_main.o hw_io.o

¤È¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¡¿¥ê¥ó¥¯¤ò¹Ô¤¤¤Þ¤¹¡£

insmod ¤ÇÀµ¾ï¤ËÁȤ߹þ¤Þ¤ì¤ë¤È¡¢¿¿Ãæ¤Î LED ¤¬ 1 Éôֳ֤ÇÅÀÅô / ¾ÃÅô¤ò·«¤êÊÖ¤·¤Þ¤¹¡£ /dev/chardev ¤Ë echo Åù¤Ç½ñ¤­¹þ¤ß¤ò¹Ô¤¦ ( ½ñ¤­¹þ¤àÆâÍƤϲ¿¤Ç¤âÎɤ¤ ) ¤È¡¢¤½¤ÎÅÙ¤ËÅÀÅô / ¾ÃÅô¤ò¸ò¸ß¤Ë·«¤êÊÖ¤·¤Þ¤¹¡£¤Þ¤¿¡¢cat Åù¤Ç dev/chardev ¤«¤éÆɤ߹þ¤ß¤ò¹Ô¤¦¤È¡¢¥×¥Ã¥·¥å¥Ü¥¿¥ó¤¬²¡¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï

[Switch] pressed.

¤È¥³¥ó¥½¡¼¥ë¤Ëɽ¼¨¤µ¤ì¡¢²¡¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï

[Switch] NOT pressed.

¤Èɽ¼¨¤µ¤ì¤Þ¤¹¡£

¤Ê¤ª¡¢insmod »þ¤Ë

hw.o : init_module : Device or resource busy

¤ÎÍͤËɽ¼¨¤µ¤ì¤ë¾ì¹ç¤Ï¡¢parport ¥É¥é¥¤¥ÐÅù¤Ë¤è¤Ã¤Æ´û¤Ë¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤¬»ÈÍѤµ¤ì¤Æ¤¤¤Þ¤¹¡£¤½¤Î¾ì¹ç¤Ï¡¢µ¯Æ°»þ¤Ë parport=0 ¤È¤¤¤¦¥«¡¼¥Í¥ë¥ª¥×¥·¥ç¥ó¤òÅϤ·¤Æ parport ¥É¥é¥¤¥Ð¤ò̵¸ú¤Ë¤·¤¿¤ê¤¹¤ëÅù¤·¤Æ¡¢¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤ò̤»ÈÍѾõÂ֤ˤ·¤Æ¤«¤é¼Â¹Ô¤·¤Æ¤¯¤À¤µ¤¤¡£

--- hw_io.h ---

    1    #ifndef ___hw_io_h_included_
    2    #define ___hw_io_h_included_
    3    
    4    
    5    #define IOPORT_BASE     0x378
    6    #define IOPORT_RANGE    3
    7    
    8    #define IOPORT_DATA     ( IOPORT_BASE + 0 )
    9    #define IOPORT_STATUS   ( IOPORT_BASE + 1 )
   10    #define IOPORT_CONTROL  ( IOPORT_BASE + 2 )
   11    
   12    #define DATA_LED_1      0
   13    #define DATA_LED_2      1
   14    #define DATA_LED_3      2
   15    #define DATA_PULLUP     3
   16    #define STATUS_ACK      6
   17    
   18    
   19    void
   20    io_write_or( unsigned short port, unsigned int value );
   21    
   22    void
   23    io_write_xor( unsigned short port, unsigned int value );
   24    
   25    void
   26    io_write_set( unsigned short port, unsigned int value );
   27    
   28    int
   29    io_is_button_pressed();
   30    
   31    
   32    #endif /* ___hw_io_h_included_ */
   33    
   34    /* End of hw_io.h */

--- hw_io.c ---

    1    #include <asm/bitops.h>      /* test_and_set_bit, clear_bit */
    2    #include <asm/io.h>          /* outb(), inb() */
    3    #include <asm/system.h>      /* rmb() */
    4    #include "hw_io.h"
    5    
    6    static int lock;
    7    
    8    
    9    /*
   10     * ¸½ºß¤Î»ØÄê¥Ý¡¼¥È¤ÎÃͤȻØÄêÃͤò or ¤·¤¿·ë²Ì¤ò
   11     * »ØÄê¥Ý¡¼¥È¤Ë½ñ¤­¹þ¤à
   12     */
   13    void
   14    io_write_or( unsigned short port, unsigned int value )
   15    {
   16        unsigned int data;
   17        
   18        if ( test_and_set_bit( 0, ( void* )( &lock ) ) != 0 )
   19            return;
   20    
   21        data  = inb( port );
   22        data |= value;
   23        outb( data, port );
   24    
   25        clear_bit( 0, ( void* )( &lock ) );
   26    }
   27    
   28    
   29    /*
   30     * ¸½ºß¤Î»ØÄê¥Ý¡¼¥È¤ÎÃͤȻØÄêÃͤò xor ¤·¤¿·ë²Ì¤ò
   31     * »ØÄê¥Ý¡¼¥È¤Ë½ñ¤­¹þ¤à ( »ØÄê¥Ó¥Ã¥È¤ÎÃÍȿž )
   32     */
   33    void
   34    io_write_xor( unsigned short port, unsigned int value )
   35    {
   36        unsigned int data;
   37    
   38        if ( test_and_set_bit( 0, ( void* )( &lock ) ) != 0 )
   39            return;
   40    
   41        data  = inb( port );
   42        data ^= value;
   43        outb( data, port );
   44    
   45        clear_bit( 0, ( void* )( &lock ) );
   46    }
   47    
   48    
   49    /*
   50     * »ØÄêÃͤò»ØÄê¥Ý¡¼¥È¤Ë½ñ¤­¹þ¤à
   51     */
   52    void
   53    io_write_set( unsigned short port, unsigned int value )
   54    {
   55        if ( test_and_set_bit( 0, ( void* )( &lock ) ) != 0 )
   56            return;
   57    
   58        outb( value, port );
   59    
   60        clear_bit( 0, ( void* )( &lock ) );
   61    }
   62    
   63    
   64    /*
   65     * ¥¹¥Æ¡¼¥¿¥¹¥Ý¡¼¥È¤ÎÃͤòÆɤ߹þ¤ß¡¢ACK ( 10 ÈÖ¥Ô¥ó )
   66     * ¤¬ LOW ¤«¤É¤¦¤«Ä´¤Ù¤ë¡£
   67     */
   68    int
   69    io_is_button_pressed()
   70    {
   71        unsigned int data;
   72    
   73        data = inb( IOPORT_STATUS );
   74        rmb();
   75
   76        if ( ! ( data & ( 1 << STATUS_ACK ) ) )
   77            return 1;
   78    
   79        return 0;
   80    }
   81    
   82    
   83    /* End of hw_io.c */

--- hw_main.c ---

    1    #include <asm/io.h>          /* outb(), inb() */
    2    #include <asm/uaccess.h>     /* copy_from_user, copy_to_user */
    3    #include <linux/fs.h>        /* inode, file, file_operations, ... */
    4    #include <linux/ioport.h>    /* check_region(), request_region(), release_region() */
    5    #include <linux/kernel.h>    /* printk() */
    6    #include <linux/module.h>
    7    #include <linux/sched.h>     /* task_struct */
    8    #include <linux/timer.h> 
    9    
   10    #include "hw_io.h"
   11    
   12    
   13    MODULE_LICENSE( "GPL" );
   14    
   15    
   16    static int   devmajor = 77;
   17    static char* devname  = "chardev";
   18    static char* msg      = "module [io.o]";
   19    
   20    
   21    /* 100 tick = 1 sec. */
   22    static int timeout = 100; 
   23    MODULE_PARM( timeout, "i" );
   24    
   25    static struct timer_list chardev_timer;
   26    static int timerstop = 0;
   27    
   28    static unsigned int initial_data;
   29    
   30    
   31    static void chardev_timer_handler( unsigned long data );
   32    static void chardev_del_timer();
   33    
   34    
   35    /*
   36     * ¥í¥°½ÐÎÏ¥Õ¥©¡¼¥Þ¥Ã¥ÈÍÑ´Ø¿ô
   37     */
   38    static void 
   39    log_format( char* body )
   40    {
   41        if ( current != NULL ) {
   42            printk( KERN_INFO "%s : PID = %-5i cmdline = \"%-10s\" : %s\n", 
   43                msg, current->pid, current->comm, body );
   44        }
   45        else {
   46            printk( KERN_INFO "%s : %s\n", msg, body );
   47        }
   48    }
   49    
   50    
   51    /* 
   52     * ¥¿¥¤¥Þ¡¼ÅÐÏ¿½èÍý 
   53     */
   54    static void 
   55    chardev_timer_register( void )
   56    {
   57        init_timer( &chardev_timer );
   58    
   59        chardev_timer.expires  = jiffies + timeout;
   60        chardev_timer.data     = ( unsigned long )jiffies;
   61        chardev_timer.function = chardev_timer_handler;
   62    
   63        add_timer( &chardev_timer );
   64    }
   65    
   66    
   67    /*
   68     * ¥¿¥¤¥Þ¡¼ºï½ü´Ø¿ô
   69     * ¥¿¥¤¥ÞÄä»ß¥Õ¥é¥°¤òÀßÄꤷ¡¢del_timer_sync ¤Ç´û¸¤Î¥¿¥¤¥Þ¡¼´Ø¿ô¤ò
   70     * ºï½ü¤¹¤ë¡Ê¼Â¹ÔÃæ¤Î¾ì¹ç¤Ï½ªÎ»¤¹¤ë¤Þ¤ÇÂԤġˡ£
   71     */
   72    static void
   73    chardev_del_timer()
   74    {
   75        timerstop = 1;
   76        del_timer_sync( &chardev_timer );
   77    }
   78    
   79    
   80    /* 
   81     * ¥¿¥¤¥à¥¢¥¦¥È½èÍý 
   82     */
   83    static void 
   84    chardev_timer_handler( unsigned long data )
   85    {
   86        io_write_xor( IOPORT_DATA, ( 1 << DATA_LED_2 ) );
   87    
   88        if ( timerstop ) {
   89            printk( KERN_INFO "%s : Timer is not to be restarted.\n", msg );
   90            return;
   91        }
   92    
   93        chardev_timer_register();
   94    }
   95    
   96    
   97    /*
   98     * open()
   99     */
  100    static int 
  101    chardev_open( struct inode* inode, struct file* filp )
  102    {
  103        log_format( "open()  called" );
  104        return 0;
  105    }
  106    
  107    
  108    /*
  109     * release()
  110     */
  111    static int 
  112    chardev_release( struct inode* inode, struct file* filp )
  113    {
  114        log_format( "close() called" );
  115        return 0;
  116    }
  117    
  118    
  119    /*
  120     * read()
  121     */
  122    static ssize_t 
  123    chardev_read( struct file* filp, char* buf, size_t count, loff_t* pos )
  124    {
  125        char status[32];
  126        int copy_len = 0;
  127        int len = 0;
  128    
  129        log_format( "read()  called" );
  130    
  131        if ( *pos == 0 ) {
  132            if ( io_is_button_pressed() )
  133                len = sprintf( status, "[Switch] pressed.\n" );
  134            else
  135                len = sprintf( status, "[Switch] NOT pressed.\n" );
  136        }
  137    
  138        copy_len = ( len > count ) ? count : len;
  139    
  140        if ( copy_to_user( buf, status, copy_len ) ) {
  141            log_format( "copy_to_user failed\n" );
  142            return -EFAULT;
  143        }
  144    
  145        *pos += copy_len;
  146    
  147        return copy_len;
  148    }
  149    
  150    
  151    /*
  152     * write()
  153     */
  154    static ssize_t 
  155    chardev_write( struct file* filp, const char* buf, size_t count, loff_t* pos )
  156    {
  157        log_format( "write() called" );
  158        io_write_xor( IOPORT_DATA, ( 1 << DATA_LED_1 ) );
  159        return count;
  160    }
  161    
  162    
  163    static struct file_operations chardev_fops = 
  164    {
  165        owner   : THIS_MODULE,
  166        read    : chardev_read,
  167        write   : chardev_write,
  168        open    : chardev_open,
  169        release : chardev_release,
  170    };
  171    
  172    
  173    /*
  174     * ¥â¥¸¥å¡¼¥ë¤Î½é´ü½èÍý
  175     * insmod »þ¤Ë¸Æ¤Ð¤ì¤ë
  176     */
  177    int 
  178    init_module( void )
  179    {
  180        EXPORT_NO_SYMBOLS;
  181    
  182        if ( register_chrdev( devmajor, devname, &chardev_fops ) ) {
  183            log_format( "register_chrdev failed" );
  184            return -EBUSY;
  185        }
  186    
  187    
  188        if ( request_region( IOPORT_BASE, IOPORT_RANGE, devname ) == NULL ) {
  189            log_format( "request_region returned NULL" );
  190            unregister_chrdev( devmajor, devname );
  191            return -EBUSY;
  192        }
  193    
  194        initial_data = inb( IOPORT_DATA );
  195        io_write_or( IOPORT_DATA, ( 1 << DATA_PULLUP ) );
  196        chardev_timer_register();
  197    
  198        log_format( "loaded  into kernel" );
  199        return 0;
  200    }
  201    
  202    
  203    /*
  204     * ¥â¥¸¥å¡¼¥ë¤Î²òÊü½èÍý
  205     * ¥â¥¸¥å¡¼¥ë¤Î»²¾È¿ô¤¬ 0 ¤Ç¤¢¤ì¤Ð¡¢rmmod »þ¤Ë¸Æ¤Ð¤ì¤ë
  206     */
  207    void 
  208    cleanup_module( void )
  209    {
  210        chardev_del_timer();
  211        io_write_set( IOPORT_DATA, initial_data );
  212    
  213        release_region( IOPORT_BASE, IOPORT_RANGE );
  214    
  215        if ( unregister_chrdev( devmajor, devname ) ) {
  216            log_format( "unregister_chrdev failed" );
  217            /* Âкö̵¤· ... */
  218        }
  219    
  220        log_format( "removed from kernel" );
  221    }
  222    
  223    
  224    /* End of hw_main.c */

¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÎÀâÌÀ

¤Ç¤Ï¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤­¤Þ¤¹¡£


--- hw_io.h ---

  • 5 ¡Á 6 ¹ÔÌÜ

    ¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î¥Ù¡¼¥¹¥¢¥É¥ì¥¹¤È I/O ¥¢¥É¥ì¥¹¶õ´Ö¤ÎÂ礭¤µ¤ò¥Þ¥¯¥í ÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£Á°½Ò¤ÎÍͤˡ¢¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î¥Ù¡¼¥¹¥¢¥É¥ì¥¹¤ÎÃÍ¤Ï ¤ª»È¤¤¤Î´Ä¶­¤Ë¤è¤Ã¤Æ°Û¤Ê¤ê¤Þ¤¹¤Î¤Ç¡¢´Ä¶­¤Ë¹ç¤ï¤»¤Æ½ñ¤­´¹¤¨¤Æ²¼¤µ¤¤¡£

  • 8 ¡Á 10 ¹ÔÌÜ

    ¥Ç¡¼¥¿¥Ý¡¼¥È¡¢¥¹¥Æ¡¼¥¿¥¹¥Ý¡¼¥È¡¢¥³¥ó¥È¥í¡¼¥ë¥Ý¡¼¥È¤½¤ì¤¾¤ì¤ÎÀèƬ ¥¢¥É¥ì¥¹¤ò¥Þ¥¯¥íÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£

  • 12 ¡Á 16 ¹ÔÌÜ

    ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç»ÈÍѤ¹¤ëÆþ½ÐÎÏ¥Ô¥ó¤Î¡¢³Æ¥Ý¡¼¥ÈÃͤˤª¤±¤ë¥Ó¥Ã¥È ÈÖ¹æ¤ò¥Þ¥¯¥íÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£DATA_LED1 ¤Ï²óÏ©¿ÞÃæ¤Î°ìÈÖ¾å¤Î LED¡¢ DATA_LED2 ¤Ï¿¿Ãæ¤Î LED¡¢DATA_LED_3 ¤Ï°ìÈÖ²¼¤Î LED ¤òɽ¤·¤Æ¤¤¤Þ¤¹¡£ ¤Þ¤¿¡¢DATA_PULLUP ¤Ï¥×¥ë¥¢¥Ã¥×Äñ¹³ÀܳÀè¤Î¥Ô¥ó¤òɽ¤·¤Æ¤ª¤ê¡¢STATUS_ACK ¤Ï¥×¥Ã¥·¥å¥Ü¥¿¥ó¤ÎÀܳÀè¥Ô¥ó¤òɽ¤·¤Æ¤¤¤Þ¤¹¡£

    Î㤨¤Ð¡¢DATA_LED1 ¤Ï¥Ç¡¼¥¿¥Ý¡¼¥È¤Î 0 ¥Ó¥Ã¥È ( ¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î 2 ÈÖ¥Ô¥ó ) ¤ËÀܳ¤·¤Æ¤¤¤ë¤Î¤Ç 0 ¤ÈÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£¤Þ¤¿¡¢¥×¥Ã¥·¥å¥Ü¥¿¥ó¤ÎÀܳÀè¤Ï ¥¹¥Æ¡¼¥¿¥¹¥Ý¡¼¥È¤Î 6 ¥Ó¥Ã¥È ( ¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î 10 ÈÖ¥Ô¥ó ) ¤ËÀܳ¤·¤Æ¤¤¤ë¤Î¤Ç¡¢ STATUS_ACK ¤ò 6 ¤ÈÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£

  • 19 ¡Á 29 ¹ÔÌÜ

    hw_io.c ¤ÇÄêµÁ¤·¤Æ¤¤¤ë´Ø¿ô¤Î¥×¥í¥È¥¿¥¤¥×Àë¸À¤Ç¤¹¡£


--- hw_io.c ---

  • 1 ¡Á 4 ¹ÔÌÜ

    ɬÍפʥإåÀ¥Õ¥¡¥¤¥ë¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Æ¤¤¤Þ¤¹¡£asm/io.h ¤Ï¡¢I/O ¥Ý¡¼¥È¤È¤ÎÆþ½ÐÎϤò¹Ô¤¦°Ù¤ËɬÍפʴؿô¤Î¥×¥í¥È¥¿¥¤¥×¤ä¥Þ¥¯¥í¤¬ÄêµÁ ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£asm/bitops.h ¤Ï¡¢³ä¤ê¹þ¤Þ¤ì¤º¤Ë¥Ó¥Ã¥ÈÁàºî¤ò ¹Ô¤¦°Ù¤Î´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤¹ ( ¥í¥Ã¥¯½èÍý¤Ë»ÈÍÑ )¡£ ¤Þ¤¿¡¢asm/system.h ¤Ë¤Ï¥á¥â¥ê¥Ð¥ê¥¢´Ø¿ô ( ¸å½Ò ) ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

  • 6 ¹ÔÌÜ

    hw_io.c Æâ¤Ç»ÈÍѤ¹¤ë¥í¥Ã¥¯ÊÑ¿ô¤òÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£I/O ¥Ý¡¼¥È¤È¤Î Æþ½ÐÎϤò¹Ô¤¦ºÝ¤Ë¡¢°ìÅ٥ǡ¼¥¿¤òÆɤ߹þ¤ó¤Ç¤½¤ÎÃͤò²Ã¹©¤·¤Æ¤«¤é½ñ¤­½Ð¤¹ ¤È¤¤¤¦½èÍý¤ò¹Ô¤Ã¤Æ¤¤¤ë¤Î¤Ç¤¹¤¬¡¢¤½¤ÎºÝ¾¤Î¥×¥í¥»¥¹¤ä¥¿¥¤¥à¥¢¥¦¥È ¥Ï¥ó¥É¥é¤Ë³ä¤ê¹þ¤Þ¤ì¤ë¤ÈÅԹ礬°­¤¤¤Î¤Ç¡¢¤Þ¤º¥í¥Ã¥¯¤ò¼èÆÀ¤·¤Æ¤«¤é ½èÍý¤ò¹Ô¤¦Íͤˤ·¤Æ¤¤¤Þ¤¹¡£¤³¤Î¥í¥Ã¥¯¼èÆÀ¤Î¤¿¤á¤Ë»È¤¦ÊÑ¿ô¤Ç¤¹¡£

  • 9 ¡Á 26 ¹ÔÌÜ ( io_write_or )

    ¼Â¹Ô»þ¤Î»ØÄê¥Ý¡¼¥È¤ÎÃͤòÆɤ߹þ¤ß¡¢¤½¤ÎÃͤȰú¿ô¤Î¥Ó¥Ã¥È or ¤ò ·×»»¤·¤Æ¡¢·ë²Ì¤ò»ØÄê¥Ý¡¼¥È¤Ë½ñ¤­¹þ¤à´Ø¿ô¤Ç¤¹¡£1 ¤òÀßÄꤷ¤¿¤¤¥Ô¥ó ¤ËÂбþ¤·¤¿¥Ó¥Ã¥È¤ò 1 ¤È¤·¤¿¥Þ¥¹¥¯¤ò»ØÄꤹ¤ë¤³¤È¤Ç¡¢»ØÄꤷ¤¿¥Ô¥ó¤Ë 1 ¤ò½ñ¤­¹þ¤ß¤½¤Î¾¤Î¥Ô¥ó¤Ï¸½¾õ¤Î¤Þ¤Þ¤Ë¤·¤Æ¤ª¤­¤¿¤¤¾ì¹ç¤Ë»ÈÍѤ·¤Þ¤¹¡£

    test_and_set_bit ¤Ç¥í¥Ã¥¯¤ò¼èÆÀ¤·¡¢I/O Áàºî¤ò¹Ô¤Ã¤¿¸å¤Ë clear_bit ¤Ç¥í¥Ã¥¯¤ò²òÊü¤¹¤ë¤È¤¤¤¦¼ÂÁõ¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¥×¥í¥»¥¹´Ö¤ÎÇÓ¾¤Î¤ß¤Ç¤¢¤ì¤Ð spin_lock ¤ò»È¤¦½ê¤Ê¤Î¤Ç¤¹¤¬¡¢¥×¥í¥»¥¹¤È¤Ï̵´Ø·¸¤Ë¼Â¹Ô¤µ¤ì¤ë¥¿¥¤¥à¥¢¥¦¥È¥Ï¥ó¥É¥é Æâ¤Ç¤Î»ÈÍѤò¹Í¤¨¤ë¤È¡¢1 CPU ¥·¥¹¥Æ¥à¤Ç¤Ï spin_lock ¤¬Ìµ°ÕÌ£¤Ç¤¢¤ë¤³¤È¡¿ ¥×¥í¥»¥¹¥³¥ó¥Æ¥­¥¹¥È¤È¥¿¥¤¥à¥¢¥¦¥È¥Ï¥ó¥É¥é´Ö¤Ç¥Ç¥Ã¥É¥í¥Ã¥¯¤¬È¯À¸¤¹¤ë ²ÄǽÀ­¤¬¤¢¤ë¤³¤È¤«¤é»ß¤á¤Þ¤·¤¿¡£

    ¤Ê¤ª¡¢¥¿¥¤¥à¥¢¥¦¥È¥Ï¥ó¥É¥éÆâ¤Ç¥í¥Ã¥¯¤¬¼èÆÀ¤Ç¤­¤ë¤Þ¤ÇÂԤĤ櫓¤Ë¤â¤¤¤«¤Ê¤¤¤Î¤Ç¡¢ ¼èÆÀ¤Ç¤­¤Ê¤«¤Ã¤¿¤é¤½¤Î»þ¤ÏÄü¤á¤Æ½ªÎ»¤¹¤ë¤È¤¤¤¦¼ÂÁõ¤Ë¤·¤Þ¤·¤¿¡£ ¤­¤Ã¤Á¤êºî¤ë¤Î¤Ç¤¢¤ì¤Ð¡¢¥¿¥¤¥à¥¢¥¦¥È¥Ï¥ó¥É¥é¤È¤Î¶¥¹ç¤¬µ¯¤­¤Ê¤¤ÍͤÊÀ߷פˤ·¤¿¾å¤Ç ¾¤Î²Õ½ê¤ò spin_lock ¤ÇÇÓ¾½èÍý¤¹¤ë¤Î¤¬Îɤ¤¤Î¤«¤Ê¡¢¤È¹Í¤¨¤Æ¤¤¤ë½ê¤Ç¤¹¡£

    test_and_set_bit ¤ª¤è¤Ó clear_bit ¤Ï¡¢ÅÓÃæ¤Ç³ä¤ê¹þ¤Þ¤ì¤ë¤³¤È¤¬Ìµ¤¤ ¥Ó¥Ã¥ÈÁàºîÍѤδؿô¤Ç¡¢°ú¿ô¤Î·¿¤¬¥×¥é¥Ã¥È¥Õ¥©¡¼¥à°Í¸¤È¤Ê¤ê¤Þ¤¹¡£ ¤³¤³¤Ç¤Ï¡¢¤¤¤¯¤Ä¤«¤Î¥Ó¥Ã¥ÈÁàºîÍѤδؿô¤Î i386 ¤Î¥×¥í¥È¥¿¥¤¥×¤ò¼¨¤·¤Þ¤¹¡£

    #include <asm/bitops.h>
    void set_bit( int nr, void* addr );
    void clear_bit( int nr, void* addr );
    int test_and_set_bit( int nr, void* addr );
    int test_and_clear_bit( int nr, void* addr );
    
    

    addr ¤ËÁàºîÂоݥǡ¼¥¿Îΰè¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò»ØÄꤷ¡¢nr ¤ËÁàºî¤¹¤ë¥Ó¥Ã¥ÈÈÖ¹æ¤ò»ØÄꤷ¤Þ¤¹¡£ ³Æ´Ø¿ô¤ÎÆâÍƤϰʲ¼¤ÎÄ̤ê¤Ç¤¹¡£

    ´Ø¿ô̾ ÀâÌÀ
    set_bit »ØÄê¥Ó¥Ã¥È¤ò 1 ¤Ë¤¹¤ë
    clear_bit »ØÄê¥Ó¥Ã¥È¤ò 0 ¤Ë¤¹¤ë
    test_and_set_bit »ØÄê¥Ó¥Ã¥È¤ò 1 ¤Ë¤·¤¿¾å¤Ç¡¢°ÊÁ°¤ÎÃͤòÊÖ¤¹
    test_and_clear_bit »ØÄê¥Ó¥Ã¥È¤ò 0 ¤Ë¤·¤¿¾å¤Ç¡¢°ÊÁ°¤ÎÃͤòÊÖ¤¹

    I/O ¥Ý¡¼¥È¤È¤ÎÆþ½ÐÎϤˤϡ¢asm/io.h ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë´Ø¿ô·² inx / outx ¤ò»È¤¤¤Þ¤¹¡£ ¤³¤Î´Ø¿ô·²¤Ï¥×¥é¥Ã¥È¥Õ¥©¡¼¥à°Í¸¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¦¤¿¤á¡¢ ¥×¥é¥Ã¥È¥Õ¥©¡¼¥àËè¤ËÊÖ¤êÃͤη¿¤ä°ú¿ô¤Î·¿¤¬°Û¤Ê¤ë¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£ ¤³¤³¤Ç¤Ï i386 ¤Ç¤Î¥×¥í¥È¥¿¥¤¥×¤ò¼¨¤·¤Þ¤¹¡£ ¤Ê¤ª¡¢hw_io.c Æâ¤Î´Ø¿ô¤Ë¤Ä¤¤¤Æ¤â¡¢port ¤Ë¤Ä¤¤¤Æ¤Ï i386 ¤Î·¿¤Ë¹ç¤ï¤»¤Æ¤¤¤Þ¤¹¡£

    #include <asm/io.h>
    unsigned char inb( unsigned short port );
    void outb( unsigned char data, unsigned short port );
    unsigned short inw( unsigned short port );
    void outw( unsigned short data, unsigned short port );
    unsigned int inl( unsigned short port );
    void outl( unsigned int data, unsigned short port );
    
    

    port ¤Ë I/O ¥¢¥É¥ì¥¹¤ò»ØÄꤷ¤Æ inx ¤ò¼Â¹Ô¤¹¤ë¤È¡¢¤½¤Î¥¢¥É¥ì¥¹¤Ë¥Þ¥Ã¥Ô¥ó¥° ¤µ¤ì¤Æ¤¤¤ëÈϰϤΥǡ¼¥¿¤¬ b/w/l ¤ËÂбþ¤·¤¿Éý¤ÇÊ֤äÆÍè¤Þ¤¹¡£¤Þ¤¿¡¢ port ¤Ë I/O ¥¢¥É¥ì¥¹¤ò»ØÄꤷ data ¤Ë½ñ¤­¹þ¤ß¤¿¤¤Éý¤Î¥Ç¡¼¥¿¤ò»ØÄꤷ¤Æ outx ¤ò¼Â¹Ô¤¹¤ë¤È¡¢¤½¤Î¥¢¥É¥ì¥¹¤ËÂФ·¤Æ»ØÄꤷ¤¿¥Ç¡¼¥¿¤ËÂбþ¤¹¤ëÅÅ°µ¤¬½ÐÎϤµ¤ì¤Þ¤¹¡£

    ³Æ´Ø¿ô¤È°·¤¦¥Ç¡¼¥¿Éý¤Î´Ø·¸¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£

    ´Ø¿ô̾ ¥Ç¡¼¥¿Éý
    inb / outb 8 ¥Ó¥Ã¥È
    inw / outw 16 ¥Ó¥Ã¥È
    inl / outl 32 ¥Ó¥Ã¥È

  • 29 ¡Á 46 ¹ÔÌÜ ( io_write_xor )

    ¼Â¹Ô»þ¤Î»ØÄê¥Ý¡¼¥È¤ÎÃͤȡ¢»ØÄêÃÍ¤Î¥Ó¥Ã¥È xor ¤ò¹Ô¤¦ÅÀ¤Î¤ß¡¢ io_write_or ¤È°Û¤Ê¤ê¤Þ¤¹¡£xor ¤ò¹Ô¤¦¤³¤È¤Ç¡¢°ú¿ô¤Ë»ØÄꤷ¤¿¥Þ¥¹¥¯Ãæ¤Î 1 ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¥Ó¥Ã¥È¤ËÂбþ¤¹¤ë¥Ô¥ó¤Î¤ß¡¢Ãͤ¬È¿Å¾¤µ¤ì¤Þ¤¹¡£

  • 49 ¡Á 61 ¹ÔÌÜ ( io_write_set )

    ¼Â¹Ô»þ¤Î»ØÄê¥Ý¡¼¥È¤ÎÃͤò̵»ë¤·¤Æ¡¢°ú¿ô¤Ë»ØÄꤷ¤¿Ä̤ê¤Ë¥Ô¥ó¤ÎÃͤòÀßÄꤹ¤ë´Ø¿ô¤Ç¤¹¡£

  • 64 ¡Á 80 ¹ÔÌÜ ( io_is_button_pressed )

    ¼Â¹Ô»þ¤Î¥¹¥Æ¡¼¥¿¥¹¥Ý¡¼¥È¤ÎÃͤòÆɤ߹þ¤ß¡¢6 ÈÖ¥Ó¥Ã¥È ( ¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î 10 ÈÖ¥Ô¥ó ) ¤ÎÃͤòÊÖ¤·¤Þ¤¹¡£¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤Î 10 ÈÖ¥Ô¥ó¤Ï 1 ¤Î¾ì¹ç¤Ë High ¤Ç 0 ¤Î¾ì¹ç¤Ë Low ¤È¤Ê¤ê¤Þ¤¹¤Î¤Ç¡¢0 ¤Ç¤¢¤ì¤Ð¥×¥Ã¥·¥å¥Ü¥¿¥ó¤¬ ²¡¤µ¤ì¤Æ¤ª¤ê¡¢1 ¤Î¾ì¹ç¤Ï¥×¥Ã¥·¥å¥Ü¥¿¥ó¤¬²¡¤µ¤ì¤Æ¤¤¤Ê¤¤¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£

    74 ¹ÔÌÜ¤Ç rmb() ¤È¤¤¤¦´Ø¿ô¤ò¼Â¹Ô¤·¤Æ¤¤¤Þ¤¹¤¬¡¢¤³¤ì¤ÏÆɤ߼è¤êÍѤΠ¥á¥â¥ê¥Ð¥ê¥¢´Ø¿ô¤Ç¤¹¡£¥á¥â¥ê¥Ð¥ê¥¢¤Ë¤Ä¤¤¤Æ¤Ï ¥á¥â¥ê¥Ð¥ê¥¢ ¤Ç¤â¤¦¾¯¤·¾Ü¤·¤¯½ñ¤­¤Þ¤¹¤¬¡¢¤³¤³¤Ç¤Ï¥¹¥Æ¡¼¥¿¥¹¥Ý¡¼¥ÈÃͤÎÆɤ߹þ¤ß¤ò ³Î¼Â¤Ë´°Î»¤µ¤»¤Æ¤¤¤ë¤È¤¤¤¦¤³¤È¤À¤±µ­²±¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£


--- hw_main.c ---

  • 1 ¡Á 10 ¹ÔÌÜ

    ɬÍפʥإåÀ¥Õ¥¡¥¤¥ë¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Æ¤¤¤Þ¤¹¡£

  • 21 ¡Á 23 ¹ÔÌÜ

    ¿¿Ãæ¤Î LED ¤òÅÀÌǤµ¤»¤ë¤¿¤á¤Î¥¿¥¤¥Þ¡¼´Ö³Ö¤Î½é´üÃͤò¡¢1 ÉäȤ·¤Æ¤¤¤Þ¤¹¡£

  • 28 ¹ÔÌÜ

    ¥â¥¸¥å¡¼¥ëÁȤ߹þ¤ß»þ¤Î¥Ç¡¼¥¿¥Ý¡¼¥È¤ÎÃͤòÊݸ¤¹¤ë¤¿¤á¤ÎÊÑ¿ô¤òÀë¸À¤·¤Æ¤¤¤Þ¤¹¡£ ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤Ï¥Ç¡¼¥¿¥Ý¡¼¥È¤Ø¤Î½ñ¤­¹þ¤ß¤ò¹Ô¤¤¤Þ¤¹¡£¤½¤Î¤¿¤á¡¢init_module ¤Ë¤ª¤¤¤Æ¥Ç¡¼¥¿¥Ý¡¼¥È¤ÎÃͤòÊݸ¤·¤Æ¤ª¤­¡¢cleanup_module ¤Ç¤½¤ÎÃͤò¥Ç¡¼¥¿¥Ý¡¼¥È ¤Ë½ñ¤­Ì᤹¤³¤È¤Ç¡¢½é´ü¾õÂÖ¤ËÌᤷ¤Æ¤¤¤Þ¤¹¡£

  • 80 ¡Á 94 ¹ÔÌÜ ( chardev_timer_handler )

    ¥¿¥¤¥à¥¢¥¦¥È¥Ï¥ó¥É¥é¤Ç¤Ï io_write_xor( IOPORT_DATA, ( 1 << DATA_LED_2 ) ) ¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ç¡¢DATA_LED_2 ( ¿¿Ãæ¤Î LED ) ¤Î¥Ô¥óÃͤòȿž¤·¤Æ¤¤¤Þ¤¹¡£ ¥¿¥¤¥Þ¡¼¤Ï½é´üÃͤξì¹ç 1 Éôֳ֤Ǽ¹Ԥµ¤ì¤Þ¤¹¤Î¤Ç¡¢1 ÉÃËè¤Ë¿¿Ãæ¤Î LED ¤¬ÅÀÅô / ¾ÃÅô¤ò·«¤êÊÖ¤¹¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£

  • 119 ¡Á 148 ¹ÔÌÜ ( chardev_read )

    131 ¡Á 136 ¹ÔÌܤˤª¤¤¤Æ¡¢io_is_button_pressed ¤ò¼Â¹Ô¤·¤Æ¥×¥Ã¥·¥å¥Ü¥¿¥ó ¤Î¾õÂÖ¤òÆɤ߹þ¤ß¡¢¾õÂ֤˱þ¤¸¤Æ¥æ¡¼¥¶¥×¥í¥»¥¹¤ËÊÖ¤¹Ê¸»úÎó¤ò¥Ð¥Ã¥Õ¥¡¤Ë ³ÊǼ¤·¤Æ¤¤¤Þ¤¹¡£if ( *pos == 0 ) ¤ÎȽÄê¤ò¹Ô¤Ã¤Æ¤¤¤ë¤Î¤Ï¡¢*pos ¤¬ 0 ¤Î¾ì¹ç¡¢ ¤Ä¤Þ¤êϢ³¤·¤¿ read ¤ÎºÇ½é¤Î¼Â¹Ô»þ¤Î¤ß¥Ç¡¼¥¿¤òÊÖ¤¹Íͤˤ¹¤ë¤¿¤á¤Ç¤¹¡£ ¤³¤ÎȽÄê¤ò¤»¤º¤ËËè²óʸ»úÎó¤òÊÖ¤·¤Æ¤·¤Þ¤¦¤È¡¢¥æ¡¼¥¶¥×¥í¥»¥¹¤¬ EOF ¤òȽÄê ¤Ç¤­¤Ê¤¤¤¿¤á¤Ë±ä¡¹¤È read ¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¤¤Þ¤¹¡£

  • 151 ¡Á 160 ¹ÔÌÜ ( chardev_write )

    io_write_xor( IOPORT_DATA, ( 1 << DATA_LED_1 ) ) ¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ç¡¢ DATA_LED_1 ( °ìÈÖ¾å¤Î LED ) ¤Î¥Ô¥óÃͤòȿž¤·¤Æ¤¤¤Þ¤¹¡£ ¤Ä¤Þ¤ê¡¢write ¤ò¼Â¹Ô¤¹¤ëÅ٤˰ìÈÖ¾å¤Î LED ¤¬ÅÀÅô / ¾ÃÅô¤ò·«¤êÊÖ¤¹¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£ ¤Ê¤ª¡¢½ñ¤­¹þ¤Þ¤ì¤¿¥Ç¡¼¥¿¤Ï̵»ë¤·¤Æ¤¤¤ë¤¿¤á¡¢²¿¤ò½ñ¤­¹þ¤ó¤Ç¤â¹½¤¤¤Þ¤»¤ó¡£

  • 173 ¡Á 200 ¹ÔÌÜ ( init_module )

    º£²ó¤ÏÊ£¿ô¤Î¥Õ¥¡¥¤¥ë¤Ç¥«¡¼¥Í¥ë¥â¥¸¥å¡¼¥ë¤òºîÀ®¤·¤Æ¤¤¤ë¤¿¤á¡¢180 ¹ÔÌÜ¤Ç EXPORT_NO_SYMBOLS ¥Þ¥¯¥í¤ò¼Â¹Ô¤·¤Æ¤¤¤Þ¤¹¡£EXPORT_NO_SYMBOLS ¥Þ¥¯¥í¤Ë¤Ä¤¤¤Æ¤Ï LECTURE 1 ¥«¡¼¥Í¥ë¥â¥¸¥å¡¼¥ë¤È¤·¤Æ¥Ç¥Ð¥¤¥¹¥É¥é¥¤¥Ð¤òºî¤ë ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£

    ¥«¡¼¥Í¥ëÆ⤫¤é I/O ¥ê¥½¡¼¥¹¤ò»ÈÍѤ¹¤ë¾ì¹ç¤Ï¡¢request_region ¤ò»È¤Ã¤Æ »ÈÍѸ¢¤ò¼èÆÀ¤·¤Ê¤±¤ì¤Ð¤¤¤±¤Þ¤»¤ó¡£

    #include <linux/ioport.h>
    struct resource* request_region( unsigned long start, unsigned long len, char* name );
    
    

    188 ¡Á 192 ¹ÔÌÜ¤Ç request_region ¤ò¼Â¹Ô¤·¡¢IOPORT_BASE ¤«¤é»Ï¤Þ¤ë IOPORT_RANGE ¥Ð¥¤¥È¤Î¥¢¥É¥ì¥¹¶õ´Ö¤Î»ÈÍѤòͽÌ󤷤Ƥ¤¤Þ¤¹¡£»ÈÍѸ¢¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤¿¾ì¹ç¤Ï NULL ¤¬Ê֤äÆÍè¤ë¤¿¤á¡¢¤½¤Î»þ¤Ï¥­¥ã¥é¥¯¥¿¥Ç¥Ð¥¤¥¹ÅÐÏ¿¤òºï½ü¤·¤Æ½ªÎ»¤·¤Æ¤¤¤Þ¤¹¡£

    194 ¹ÔÌܤǥǡ¼¥¿¥Ý¡¼¥È¤ÎÃͤòÊݸ¤·¤Æ¤¤¤Þ¤¹¡£ ¤½¤Î¸å¡¢io_write_or( IOPORT_DATA, ( 1 << DATA_PULLUP ) ) ¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ç¡¢ ¥×¥Ã¥·¥å¥Ü¥¿¥ó¤ÎÀܳÀè¤Î¥Ô¥ó¤ò High ¤Ë¤·¤Æ¤¤¤Þ¤¹¡£

  • 203 ¡Á 221 ¹ÔÌÜ

    ¥¿¥¤¥Þ¡¼¤òÄä»ß¤·¤¿¸å¡¢io_write_set ¤ò¼Â¹Ô¤·¤Æ¥Ç¡¼¥¿¥Ý¡¼¥È¤ò ½é´ü¾õÂÖ¤ËÌᤷ¤Æ¤¤¤Þ¤¹¡£¤½¤Î¸å¡¢release_region ¤ò¼Â¹Ô¤·¤Æ I/O ¥ê¥½¡¼¥¹ ¤ò²òÊü¤·¤Æ¤¤¤Þ¤¹¡£

    #include <linux/ioport.h>
    void release_region( unsigned long start, unsigned long len );
    
    

    I/O ¥ê¥½¡¼¥¹¤Î»ÈÍѤ¬½ª¤ï¤Ã¤¿¤é¡¢release_region ¤ò»È¤Ã¤Æɬ¤º²òÊü¤·¤Æ¤¯¤À¤µ¤¤¡£

°Ê¾å¤Ç hw_io.h¡¢hw_io.c¡¢hw_main.c ¤Î²òÀâ¤Ï½ª¤ï¤ê¤Ç¤¹¡£´Ä¶­¤¬¤¢¤ëÊý¤Ï¡¢¤¼¤Ò²óÏ©ºî¤Ã¤Æ·Ò¤²¤ÆÆ°¤«¤·¤Æ¤ß¤Æ²¼¤µ¤¤¡ª¥½¥Õ¥È¥¦¥§¥¢¤À¤±¤Ç½ª¤ï¤ë¥×¥í¥°¥é¥ß¥ó¥°¤È¤Ï¤Þ¤¿°ã¤Ã¤¿ÌÌÇò¤µ¤¬ÆÀ¤é¤ì¤ë¤È»×¤¤¤Þ¤¹¤è¡¼¡£

¡û ¥á¥â¥ê¥Ð¥ê¥¢

¥×¥í¥°¥é¥à¼Â¹Ô»þ¤Ë¤Ï CPU ¤È¥á¥â¥ê¤¢¤ë¤¤¤Ï³°Éô I/O µ¡´ï¤È¤Î¤ä¤ê¤È¤ê¤¬È¯À¸¤·¤Þ¤¹¤¬¡¢¥³¥ó¥Ñ¥¤¥é¤Ë¤è¤ëºÇŬ²½¤ä CPU ¤Ë¤è¤ëºÇŬ²½Åù¤Ë¤è¤Ã¤Æ¡¢¤³¤ì¤é¤ÎÌ¿Îá½ç½ø¤¬°Õ¿Þ¤»¤ºÊѹ¹¤µ¤ì¤Æ¤·¤Þ¤¦¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£

Î㤨¤Ð¸ß¤¤¤Ë´³¾Ä¤·¤Ê¤¤¤È¥³¥ó¥Ñ¥¤¥é¤ä CPU ¤¬È½ÃǤ·¤¿Æɤ߽ñ¤­Ì¿ÎáÎó¤Ë¤Ä¤¤¤Æ¡¢°ìµ¤¤Ë¥­¥ã¥Ã¥·¥å¥á¥â¥ê¤ËÆɤ߹þ¤ß¤ò¹Ô¤Ã¤¿¾å¤Ç½ñ¤­¹þ¤ßÌ¿Îá¤ò¼Â¹Ô¤¹¤ë¡¢Åù¤Ç¤¹( ¤³¤Î´Ö¡¢Í½Â¬¤Ë´ð¤Å¤¤¤Æͽ¤áÊ̤Υá¥â¥êÆâÍƤޤǤâÆɤ߹þ¤ó¤À¤ê¤¹¤ë¾ì¹ç¤â¤¢¤ê¤Þ¤¹ )¡£

¤·¤«¤·¡¢ÊÌ¥×¥í¥»¥¹¤È¤ÎÂÔ¤Á¹ç¤ï¤»Åù¤ò¹Ô¤¦É¬Íפ¬¤¢¤Ã¤¿¤ê¡¢I/O µ¡´ï¤ËÂФ·¤Æ½ñ¤­¹þ¤ß¤ò´°Î»¤·¤¿¾å¤ÇÆɤ߹þ¤Þ¤Ê¤±¤ì¤Ð°ÕÌ£¤¬Ìµ¤¤¥Ô¥ó¾õÂÖ¤òÆɤó¤À¤ê¤¹¤ë¾ì¹ç¤Ë¤Ï¡¢¥³¥ó¥Ñ¥¤¥é¤ä CPU ¤Ç¤ÏȽÃǤò´Ö°ã¤¨¤Æ¤·¤Þ¤¦²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£

¤³¤ÎÍͤʾì¹ç¤Ë¡¢Ì¿Îá¤Î¼Â¹Ô½ç¤òÊݾڤ·¤è¤¦¤È¤¹¤ë¤¿¤á¤Ë¥á¥â¥ê¥Ð¥ê¥¢¤¬¤¢¤ê¤Þ¤¹¡£¥á¥â¥ê¥Ð¥ê¥¢¤òÃÖ¤¯¤³¤È¤Ç¡¢¥³¥ó¥Ñ¥¤¥é¤ä CPU ¤ËÂФ·¤Æ¤½¤Î»þÅÀ¤Þ¤Ç¤Î¥á¥â¥ê¥¢¥¯¥»¥¹¤ä I/O ¥¢¥¯¥»¥¹¤ò´°Î»¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¥á¥â¥ê¥Ð¥ê¥¢¤Ë¤Ï¡¢¥³¥ó¥Ñ¥¤¥é¤ËÂФ·¤Æ»Ø¼¨¤¹¤ë¤¿¤á¤Î¤â¤Î¤È¡¢¥Ï¡¼¥É¥¦¥§¥¢¤ËÂФ·¤Æ»Ø¼¨¤¹¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤¹¡£

--- ¥³¥ó¥Ñ¥¤¥é¤ËÂФ¹¤ë¥á¥â¥ê¥Ð¥ê¥¢ ---

#include <linux/kernel.h>
void barrier( void );

--- ¥Ï¡¼¥É¥¦¥§¥¢¤ËÂФ¹¤ë¥á¥â¥ê¥Ð¥ê¥¢ ---

#include <asm/system.h>
void rmb( void );
void wmb( void );
void mb( void );

rmb ¤ÏÆɤ߽Ф·½ç½ø¤Ë´Ø¤¹¤ë¥á¥â¥ê¥Ð¥ê¥¢¤Ç¡¢wmb ¤Ï½ñ¤­¹þ¤ß½ç½ø¤Ë´Ø¤¹¤ë¥á¥â¥ê¥Ð¥ê¥¢¤Ç¤¹¡£mb ¤ÏÆɤ߽ñ¤­Î¾Êý¤ËÂФ¹¤ë¥á¥â¥ê¥Ð¥ê¥¢¤È¤Ê¤ê¤Þ¤¹¡£

¤Ê¤ª¡¢¥¹¥Ô¥ó¥í¥Ã¥¯¤ä¥¢¥È¥ß¥Ã¥¯Áàºî ( ³ä¤ê¹þ¤Þ¤ì¤ë¤³¤È¤¬Ìµ¤¯Áàºî¤ò´°Î»¤Ç¤­¤ë½èÍý¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤¤¤¦¤È test_and_set_bit / clear_bit Åù ) ¤Ï¥á¥â¥ê¥Ð¥ê¥¢¤ÈƱÍͤÎƯ¤­¤ò¤¹¤ëÍͤǤ¹( ¤³¤ÎÊÕ¤ê¤ò¾Ü¤·¤¯ÃΤꤿ¤¤Êý¤Ï¡¢¤½¤ì¤é¤Î´Ø¿ô¤Î¥¤¥ó¥é¥¤¥ó¥¢¥»¥ó¥Ö¥é¤Ë¤è¤ë¼ÂÁõ¤È CPU ¤Î¥Þ¥Ë¥å¥¢¥ë¤ò¸«Èæ¤Ù¤Ê¤¬¤éÄ´¤Ù¤Æ¤ß¤Æ²¼¤µ¤¤¡£É®¼Ô¤â Intel Processor ¤Ë¤Ä¤¤¤ÆÄ´¤Ù¤Æ¤ª¤ª¤Þ¤«¤Ë¤Ïʬ¤«¤ê¤Þ¤·¤¿¤¬¡¢¼ÂÁõ¤Ç¤­¤ëÄø¤Ë¤Ïʬ¤«¤Ã¤Æ¤Ê¤¤¤Î¤Ç½ñ¤±¤Þ¤»¤ó m(__)m )¡£

¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Î¾ì¹ç¡¢hw_io.c ¤Î¤Û¤È¤ó¤É¤Î´Ø¿ô¤Ë¤ª¤¤¤Æ¡¢I/O Áàºî¤¬¥¢¥È¥ß¥Ã¥¯Áàºî¤Î´Ö¤Ë¤¢¤ê¤Þ¤¹¡£¤è¤Ã¤Æ¡¢clear_bit ¤è¤êÁ°¤ÎÁàºî¤Ï´Ø¿ô½ªÎ»»þ¤Ë¤Ï´°Î»¤·¤Æ¤¤¤ë¤³¤È¤¬Êݾڤµ¤ì¤Æ¤¤¤Þ¤¹¡£ÆâÉô¤Î inb / outb ½ç½ø¤Ë¤Ä¤¤¤Æ¤Ï¡¢Æɤ߹þ¤ó¤ÀÃͤò²Ã¹©¤·¤Æ½ñ¤­¹þ¤ó¤Ç¤¤¤ë¤¿¤á´Ö°ã¤¨¤Ê¤¤¤À¤í¤¦¡£¤È»×¤Ã¤Æ²¿¤â¤·¤Æ¤Þ¤»¤ó¡£¡£¡£

¤Ê¤ª¡¢io_is_button_pressed() ¤Ë¤ª¤¤¤Æ rmb() ¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¤¬¡¢¤³¤Î¥¢¥É¥ì¥¹¤ËÂФ·¤Æ¤Ï io_is_button_pressed ¤Ë¤ª¤¤¤ÆƱ¤¸ÊÑ¿ô¤Ø¤ÎÆɤ߹þ¤ß¤·¤«¹Ô¤Ã¤Æ¤¤¤Ê¤¤¤¿¤á¡¢È½ÃǤò¸í¤Ã¤ÆʤÓÂؤ¨Åù¤¬¹Ô¤ï¤ì¤Ê¤¤ÍͤˤÈÇ°¤ò²¡¤·¤Æ¤ë´¶¤¸¤Ç¤¹¡£¤É¤¦Ê¤ÓÂؤ¨¤é¤ì¤ë¤Î¤«¸«Åö¤¬ÉÕ¤«¤Ê¤¤¤Î¤Ç¡¢°ì±þÆþ¤ì¤Æ¤ß¤Æ¤¤¤Þ¤¹¡£