Changeset 456

Show
Ignore:
Timestamp:
02/19/07 01:32:09 (2 years ago)
Author:
goodea
Message:

oh wow interrupt.c

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/hal/lpc2106-cmucam3/cc3.c

    r455 r456  
    742742bool cc3_button_get_state (void) 
    743743{ 
    744   bool result = !(REG (GPIO_IOPIN) & _CC3_BUTTON); 
     744  if (!_cc3_button_trigger) { 
     745    // button has not been pressed 
     746    return false; 
     747  } 
     748 
     749  // otherwise, it has been pressed, but it's in GPIO mode 
     750  return !(REG (GPIO_IOPIN) & _CC3_BUTTON); 
     751
     752 
     753bool cc3_button_get_and_reset_trigger (void) 
     754
     755  bool result = _cc3_button_trigger; 
     756  _cc3_button_trigger = false; 
     757 
     758  // reset interrupt 
     759  if (result) { 
     760    enable_button_interrupt(); 
     761  } 
     762 
    745763  return result; 
    746764} 
  • trunk/hal/lpc2106-cmucam3/cc3_hal.c

    r455 r456  
    1919#include "cc3_hal.h" 
    2020#include "cc3_pin_defines.h" 
     21#include "interrupt.h" 
    2122#include "serial.h" 
    2223#include <stdio.h> 
     
    5960 
    6061  //REG(PCB_PINSEL1) = 0x1;  // External interrupt 0 
     62 
     63  enable_button_interrupt (); 
    6164 
    6265  // Setup timer0 to count by milliseconds starting from 0 
  • trunk/hal/lpc2106-cmucam3/cc3_pin_defines.h

    r372 r456  
    6969#define _CC3_LED_2              _CC3_SERVO_3  
    7070 
     71// button 
    7172#define _CC3_BUTTON             0x00004000 
     73#define _CC3_BUTTON_PINSEL_MASK 0x30000000 
     74#define _CC3_BUTTON_PINSEL      0x20000000 
    7275 
    7376// SPI 
  • trunk/hal/lpc2106-cmucam3/interrupt.c

    r444 r456  
    2828#include "cc3_hal.h" 
    2929 
     30volatile bool _cc3_button_trigger; 
     31 
    3032void disable_ext_interrupt (void) 
    3133{ 
    32     // Enable bit 14, which is the external interrupt 0... 
     34    // Disable bit 14, which is the external interrupt 0... 
    3335    REG (VICIntEnClr) = 0x4000; 
    34     REG (PCB_PINSEL1) = 0x0;    // Switch from EINT0 mode to GPIO 
    35  
     36    // Switch from EINT0 mode to GPIO 
     37    REG (PCB_PINSEL1) = 0x0; 
     38    // Clear the interrupt 
     39    REG (SYSCON_EXTINT) = 0x1; 
    3640} 
    3741 
     
    3943void enable_ext_interrupt (void) 
    4044{ 
    41     REG (SYSCON_EXTINT) = 0x1; 
     45    // Switch from GPIO to EINT0 mode 
     46    REG (PCB_PINSEL1) = 0x1; 
    4247    // Enable bit 14, which is the external interrupt 0... 
    4348    REG (VICIntEnable) = 0x4000; 
    44     // Clear the interrupt status flag... 
    45     REG (PCB_PINSEL1) = 0x1;    // Switch from GPIO to EIN0 mode 
    4649} 
    4750 
    4851void enable_servo_interrupt (void) 
    4952{ 
    50    //uart0_write("Enable Servo Int\r\n" ); 
     53    //uart0_write("Enable Servo Int\r\n" ); 
    5154    REG (VICIntEnable) = 0x20; 
    52  
    5355} 
    5456 
     
    5658{ 
    5759    REG (VICIntEnClr) = 0x20; 
    58  
    5960} 
    6061 
     62void enable_button_interrupt (void) 
     63{ 
     64  //uart0_write("button int enable\r\n"); 
     65  // pin select 
     66  REG(PCB_PINSEL0) = (REG(PCB_PINSEL0) & 
     67                      ~_CC3_BUTTON_PINSEL_MASK) | _CC3_BUTTON_PINSEL; 
     68 
     69  // vic bit 15: EINT1 
     70  REG (VICIntEnable) = 0x8000; 
     71} 
     72 
     73void disable_button_interrupt (void) 
     74{ 
     75  //uart0_write("button int disable\r\n"); 
     76 
     77  // vic bit 15: EINT1 
     78  REG (VICIntEnClr) = 0x8000; 
     79 
     80  // pin select back to GPIO 
     81  REG(PCB_PINSEL0) = (REG(PCB_PINSEL0) & ~_CC3_BUTTON_PINSEL_MASK); 
     82 
     83  // clear the interrupt 
     84  REG (SYSCON_EXTINT) = 0x2; 
     85} 
    6186 
    6287void interrupt (void) 
     
    6489//asm volatile ( "msr cpsr_c,0x1F" ); // MODE_SYS 
    6590 
     91  //uart0_write_hex(REG(VICRawIntr)); 
    6692    //printf( "Got interrupt: %d\r\n",REG(VICRawIntr) ); 
    6793    if (REG (VICRawIntr) & 0x4000) { 
     94      //uart0_write("vref interrupt\r\n"); 
    6895        // Triggered on VREF telling when a frame is complete. 
    6996        // Simply disable the FIFO once the frame has been captured.  
     
    73100        _cc3_pixbuf_write_rewind (); 
    74101        disable_ext_interrupt (); 
     102    } 
     103 
     104    if (REG (VICRawIntr) & 0x8000) { 
     105      // button press 
     106      //uart0_write("button int\r\n"); 
     107      _cc3_button_trigger = true; 
     108      disable_button_interrupt (); 
    75109    } 
    76110 
  • trunk/hal/lpc2106-cmucam3/interrupt.h

    r302 r456  
    2020#define INTERRUPT_H 
    2121 
     22#include <stdbool.h> 
     23 
     24extern volatile bool _cc3_button_trigger; 
     25 
    2226void enable_ext_interrupt (void); 
    2327void disable_ext_interrupt (void); 
    2428void enable_servo_interrupt (void); 
    2529void disable_servo_interrupt (void); 
     30void enable_button_interrupt (void); 
     31void disable_button_interrupt (void); 
     32 
    2633void interrupt (void); 
    2734 
  • trunk/hal/virtual-cam/cc3.c

    r455 r456  
    760760} 
    761761 
     762bool cc3_button_get_and_reset_trigger (void) 
     763{ 
     764  return 1; 
     765} 
     766 
    762767void cc3_filesystem_init (void) 
    763768{ 
  • trunk/include/cc3.h

    r455 r456  
    415415bool cc3_button_get_state (void); 
    416416 
     417/** 
     418 * Get and reset the trigger functionality of the button. 
     419 * 
     420 * @return \a true if the button has been pressed since the 
     421 * last time this function was called. 
     422 */ 
     423bool cc3_button_get_and_reset_trigger (void); 
    417424 
    418425/** 
  • trunk/projects/cmucam2/cmucam2.c

    r455 r456  
    7474  PACKET_FILTER, 
    7575  CONF_HISTOGRAM, 
     76  GET_BUTTON, 
    7677  CMUCAM2_CMD_END               // Must be last entry so array sizes are correct 
    7778} cmucam2_command_t; 
     
    134135  cmucam2_cmds[GET_INPUT] = "GI"; 
    135136  cmucam2_cmds[SET_INPUT] = "SI";  // new for cmucam3 
    136   //  GB get button 
     137  cmucam2_cmds[GET_BUTTON] = "GB"; 
    137138  cmucam2_cmds[LED_0] = "L0"; 
    138139  //  L1 LED control 
     
    774775        printf("%d\r", cc3_gpio_get_servo_position(arg_list[0])); 
    775776        break; 
    776          
     777 
    777778      case GET_INPUT: 
    778779        if (n != 0) { 
     
    797798        cc3_gpio_set_mode (arg_list[0], CC3_GPIO_MODE_INPUT); 
    798799 
     800        break; 
     801 
     802      case GET_BUTTON: 
     803        if (n != 0) { 
     804          error = true; 
     805          break; 
     806        } 
     807        print_ACK (); 
     808        if (cc3_button_get_and_reset_trigger()) { 
     809          printf("1\r"); 
     810        } else { 
     811          printf("0\r"); 
     812        } 
    799813        break; 
    800814