Exemple #1
0
void printButton(int g)
{
  if (GET_GPIO(g)) // !=0 <-> bit is 1 <- port is HIGH=3.3V
    printf("Button pressed!\n");
  else // port is LOW=0V
    printf("Button released!\n");
}
Exemple #2
0
int main(int argc, char **argv)
{
  int g,rep, i;
 
  // Set up gpi pointer for direct register access
  wiringPiSetupGpio ();
  setup_io();
  for (i = 0; i < 28; i++)
  {
	  INP_GPIO(i);
	  printf("%d", GET_GPIO(i));
  }
  printf("\n");
  //exit(0);
  OUT_GPIO(INT); GPIO_SET(INT);
  OUT_GPIO(NMI); GPIO_SET(NMI);
  OUT_GPIO(CLK); GPIO_SET(CLK);
  OUT_GPIO(WAIT); GPIO_SET(WAIT);
  OUT_GPIO(BUSRQ); GPIO_SET(BUSRQ);
  OUT_GPIO(RESET); GPIO_SET(RESET);
  OUT_GPIO(SI); GPIO_SET(SI);
  OUT_GPIO(CP); GPIO_SET(CP);
  OUT_GPIO(CS_16); GPIO_SET(CS_16);
  OUT_GPIO(M); 
  ResetSimulationVars();  
  WriteControlPins();
  DoReset();
  
  while(1)
	  loop();
}
Exemple #3
0
 void msxwriteio(unsigned short  addr, unsigned char byte)
 {
	 GPIO_SET = MSX_CS | MSX_MIO;
	 GPIO_CLR = MSX_MA0 | MSX_MODE;
	 SET_ADDR(addr);
	 GPIO_SET = MSX_RW;
	 GPIO_CLR = MSX_CS;
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_CS;
	 SET_DATA(byte);	 
	 GPIO_SET = MSX_MA0;
	 GPIO_CLR = MSX_CS;
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_CS | MSX_MODE;
	 return;
 }
Exemple #4
0
 int msxreadio(unsigned short  addr)
 {
	 unsigned char byte;
	 GPIO_SET = MSX_CS | MSX_RESET | MSX_MIO;
	 GPIO_CLR = MSX_MA0 | MSX_MODE | MSX_M1;
	 SET_ADDR(addr);
	 GPIO_CLR = MSX_RW;
	 GPIO_CLR = MSX_CS;
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_MA0;
	 setDataIn();	 
	 while(!GET_GPIO(MREADY_PIN));
	 GET_DATA(byte);	 
	 GPIO_SET = MSX_CS | MSX_MODE;
	 return byte;	 
 }
Exemple #5
0
static unsigned char* DigitalRead(struct uState* S, unsigned char* pc, number* res) {
  if (!res) return skip(S, pc);
  number pin;
  pc = eval(S, pc, &pin);
  *res = !!GET_GPIO(pin);
  return pc;
}
Exemple #6
0
 void msxwrite(int slot, unsigned short  addr, unsigned char byte)
 {
	 int i = 0;
	 GPIO_CLR = MSX_MA0 | MSX_MODE;
	 GPIO_SET = MSX_CS | MSX_RESET | MSX_M1 | (slot != 2 ? MSX_SLTSL : 0);
	 SET_ADDR(addr);
	 GPIO_SET = MSX_RW;
	 GPIO_CLR = MSX_CS | MSX_MIO | (slot == 2 ? MSX_SLTSL : 0);
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_CS;
	 SET_DATA(byte);	
	 GPIO_SET = MSX_MA0;
	 GPIO_CLR = MSX_CS;
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_CS | MSX_MODE;
	 return;
 }
Exemple #7
0
static int palmtt3_udc_is_connected (void){
	int ret = GET_GPIO(GPIO_NR_PALMTT3_USB_DETECT);
	if (ret)
		printk (KERN_INFO "palmtt3_udc: device detected [USB_DETECT: %d]\n",ret);
	else
		printk (KERN_INFO "palmtt3_udc: no device detected [USB_DETECT: %d]\n",ret);

	return ret;
}
Exemple #8
0
//Used for pi as RAM
void* memThread(void* input){

	while(1){
		if(GET_GPIO(WE)){
			readDataFromMem(readAddress());
		}
		else
			writeDataToMem(readAddress());
	}


}
BOOL Button_rstbtn_is_pushed(void)
{
    RETAILMSG(PWR_ZONE_ENTER, (_T("[BTN] ++%s()\n\r"), _T(__FUNCTION__)));

    if (GET_GPIO(g_pGPIOReg, GPNDAT, 1))        // We can read GPDAT pin level when configured as EINT
    {
        return FALSE;    // Low Active Switch (Pull-up switch)
    }
    else
    {
        return TRUE;
    }
}
Exemple #10
0
// Wait for a change in clock level and measure the time it took.
static inline unsigned long waitCLKchange(struct timespec *tp, int currentState)
{
  unsigned long c = 0;

  while (GET_GPIO(PI_CLOCK_IN) == currentState) {
    clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, tp, NULL);
    tp->tv_nsec += INTERVAL;
    tnorm(tp);
    c += INTERVAL;
//printf("cs:%i,c:%lu,t.tv_sec:%lu,t.tv_nsec:%lu\n",currentState,c,tp->tv_sec,tp->tv_nsec);
  }

  return c; // time between change in nanoseconds
} // waitCLKchange
Exemple #11
0
int main(int argc, char **argv)
{
  int g,rep;
 
  // Set up gpi pointer for direct register access
  setup_io();
 
 /************************************************************************\
  * You are about to change the GPIO settings of your computer.          *
  * Mess this up and it will stop working!                               *
  * It might be a good idea to 'sync' before running this program        *
  * so at least you still have your code changes written to the SD-card! *
 \************************************************************************/
 
  // led
  INP_GPIO(26);
  OUT_GPIO(26);
  
  // pir
  INP_GPIO(21);
  
  int paalla = 0;
  int liike = 0;

  // time 20sec
  for (rep=0; rep<200; rep++) {
     if(GET_GPIO(21))
        liike=1;
     else
        liike=0;
    
     if(paalla==0 & liike==1){
        GPIO_SET = 1<<26;
        paalla=1;
        printf("Led On\n");
     }
     if(paalla==1 & liike==0){
        GPIO_CLR = 1<<26;
        paalla=0;
        printf("Led Off\n");
     }
     
     usleep(100000); // 100ms
  }
 
  return 0;
 
}
static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
{
        int button, down;

        for (button = 0; button < ARRAY_SIZE(buttontab); button++)
                if (buttontab[button].irq == irq)
                        break;

        if (likely(button < ARRAY_SIZE(buttontab))) {
                down = GET_GPIO(buttontab[button].gpio) ? 0 : 1;
                input_report_key(buttons_dev, buttontab[button].keyno, down);
                input_sync(buttons_dev);
        }

	return IRQ_HANDLED;
}
Exemple #13
0
int msxread(int slot, unsigned short addr)
 {
	 unsigned char byte, b1;
	 int i;
	 GPIO_CLR = MSX_MA0 | MSX_MODE;
	 GPIO_SET = MSX_CS | MSX_RESET | MSX_M1 | (slot !=2 ? MSX_SLTSL : 0);
	 SET_ADDR(addr);
	 GPIO_CLR = MSX_RW | MSX_MIO | (slot == 2 ? MSX_SLTSL : 0);
	 GPIO_CLR = MSX_CS;
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_MA0;
	 setDataIn();
//	 while(!GET_GPIO(MREADY_PIN));
	 GET_DATA(byte);
	 GPIO_SET = MSX_CS | MSX_MODE;
	 return byte;	 
 }
Exemple #14
0
void display_input() {
  int row, col;
  getmaxyx(stdscr, row, col);   /* get the screen boundaries */
  int center_x = col / 2;
  int center_y = row / 2;
  int start_y = center_y - 2;

  mvprintw(start_y, center_x - 8, "Input bit status");
  start_y++;
  uint8_t value = GET_GPIO(PIN);

  if (value) {
    mvprintw(center_y, center_x, "1");
  }
  else {
    mvprintw(center_y, center_x, "0");
  }
}
Exemple #15
0
int MeterS0::HWIF_MMAP::status()
{
#define GET_GPIO(g) (*(_gpio+13)&(1<<g)) // 0 if LOW, (1<<g) if HIGH

	return GET_GPIO(_gpiopin)>0 ? 1 : 0;
}
Exemple #16
0
static void handle_gpio(void* irq)
{
	int gpn = (int)irq;
	printk(KERN_ERR "*** GPIO *** %d *** is *** %s ***\n", gpn, GET_GPIO(gpn) ? "high" : "low ");
}
Exemple #17
0
/*** GPIO R/W ***/
static int gpio_get(int id)
{
	return GET_GPIO(id);
}
Exemple #18
0
int main(int argc, char **argv)
{
  #define MAX_BITS (49) // 49-bit word.
  #define MAX_DATA (1*1024) // 1 KB data buffer of 49-bit data words - ~70 seconds @ 1 kHz.
  char data[MAX_DATA*MAX_BITS], word[MAX_BITS];
  //int (*data_ptr)[MAX_DATA][MAX_BITS] = &data, (*bit_ptr)[MAX_BITS] = data;
  int i = 0, j = 0, flag = 0, bit_cnt = 0, data_cnt = 0, zones, cmd;
  int data0,data1,data2,data3,data4,data5,data6;
  char year3[2],year4[2],month[2],day[2],hour[2],minute[2];
  FILE *out_file;
  struct sched_param param;
  struct timespec t, tmark;
  char msg[100] = "", oldMsg[100] = "";
  struct fifo dataFifo;

  /* Declare ourself as a real time task */
  param.sched_priority = MY_PRIORITY;
  if(sched_setscheduler(0, SCHED_FIFO, &param) == -1) {
    perror("sched_setscheduler failed");
    exit(-1);
  }

  /* Lock memory */
  if(mlockall(MCL_CURRENT|MCL_FUTURE) == -1) {
    perror("mlockall failed");
    exit(-2);
  }

  /* Pre-fault our stack */
  stack_prefault();

  for(i = 0; i < MAX_DATA*MAX_BITS; i++)
    data[i] = '0';

  for(i = 0; i < MAX_BITS; i++)
    word[i] = '0';

  // Set up gpio pointer for direct register access
  setup_io();

  // Set up FIFO
  fifo_init(&dataFifo, data, MAX_DATA*MAX_BITS);

  // Set pin direction
  INP_GPIO(PI_DATA_OUT); // must use INP_GPIO before we can use OUT_GPIO
  OUT_GPIO(PI_DATA_OUT);
  INP_GPIO(PI_DATA_IN);
  INP_GPIO(PI_CLOCK_IN);

  // Set PI_DATA_OUT pin low.
  GPIO_CLR = 1<<PI_DATA_OUT;

  clock_gettime(CLOCK_MONOTONIC, &t);
  tmark = t;
  while (1) {
//printf("pi_data:%i,data[%i][%i]:%i\n",GET_GPIO(PI_DATA_IN),data_cnt,bit_cnt,data[data_cnt][bit_cnt]);
    t.tv_nsec += INTERVAL;
    tnorm(&t);
    clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL);
    if (GET_GPIO(PI_CLOCK_IN) == PI_CLOCK_HI) flag = 1;
    else if ((GET_GPIO(PI_CLOCK_IN) == PI_CLOCK_LO) && (flag == 1)) {
      if (ts_diff(&t, &tmark) > 1100000) { // new word
        bit_cnt = 0; // start new word
        fifo_write(&dataFifo, word, MAX_BITS); // write current word to FIFO
/*printf("%04i: wrote ", data_cnt);
for(i=0; i<MAX_BITS; i++) printf("%c", word[i]);
printf(" to dataFifo\n");*/
        data_cnt++;
      }
      tmark = t;
      flag = 0;
      t.tv_nsec += INTERVAL;
      tnorm(&t);
      t.tv_nsec += INTERVAL;
      tnorm(&t);
      t.tv_nsec += INTERVAL;
      tnorm(&t);
      t.tv_nsec += INTERVAL;
      tnorm(&t);
      t.tv_nsec += INTERVAL;
      tnorm(&t);
      /*t.tv_nsec += INTERVAL;
      tnorm(&t);
      t.tv_nsec += INTERVAL;
      tnorm(&t);
      t.tv_nsec += INTERVAL;
      tnorm(&t);
      t.tv_nsec += INTERVAL;
      tnorm(&t);
      t.tv_nsec += INTERVAL;
      tnorm(&t);*/
      clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL); // wait 50 uS for valid data
      word[bit_cnt++] = (GET_GPIO(PI_DATA_IN) == PI_DATA_HI) ? '0' : '1';
    }
    if (data_cnt == MAX_DATA)
      break;
  }

  // decode and write to file
  if ( (out_file = fopen ("data", "w")) == NULL )
    printf ("*** data could not be opened. \n" );
  else
    for ( i = 0; i < MAX_DATA; i++ ) {
      strcpy(msg, "");
      fifo_read(&dataFifo, word, MAX_BITS);
/*printf("%04i: read  ", i);
for(j=0; j<MAX_BITS; j++) printf("%c", word[j]);
printf(" from dataFifo\n");*/
      cmd = getBinaryData(word,0,8);
      if (cmd == 0x05) {
        strcpy(msg, "LED Status: ");
        if (getBinaryData(word,12,1)) strcat(msg, "Error ");
        if (getBinaryData(word,13,1)) strcat(msg, "Bypass ");
        if (getBinaryData(word,14,1)) strcat(msg, "Memory ");
        if (getBinaryData(word,15,1)) strcat(msg, "Armed ");
        if (getBinaryData(word,16,1)) strcat(msg, "Ready ");
      }
      else if (cmd == 0xa5) {
        sprintf(year3, "%d", getBinaryData(word,9,4));
        sprintf(year4, "%d", getBinaryData(word,13,4));
        sprintf(month, "%d", getBinaryData(word,19,4));
        sprintf(day, "%d", getBinaryData(word,23,5));
        sprintf(hour, "%d", getBinaryData(word,28,5));
        sprintf(minute, "%d", getBinaryData(word,33,6));
        strcpy(msg, "Date: 20");
        strcat(msg, year3);
        strcat(msg, year4);
        strcat(msg, "-");
        strcat(msg, month);
        strcat(msg, "-");
        strcat(msg, day);
        strcat(msg, " ");
        strcat(msg, hour);
        strcat(msg, ":");
        strcat(msg, minute);
      }
      else if (cmd == 0x27) {
        strcpy(msg, "Zone1: ");
        zones = getBinaryData(word,41,8);
        if (zones & 1) strcat(msg, "1 ");
        if (zones & 2) strcat(msg, "2 ");
        if (zones & 4) strcat(msg, "3 ");
        if (zones & 8) strcat(msg, "4 ");
        if (zones & 16) strcat(msg, "5 ");
        if (zones & 32) strcat(msg, "6 ");
        if (zones & 64) strcat(msg, "7 ");
        if (zones & 128) strcat(msg, "8 ");
      }
      else if (cmd == 0x2d) {
        strcpy(msg, "Zone2: ");
        zones = getBinaryData(word,41,8);
        if (zones & 1) strcat(msg, "9 ");
        if (zones & 2) strcat(msg, "10 ");
        if (zones & 4) strcat(msg, "11 ");
        if (zones & 8) strcat(msg, "12 ");
        if (zones & 16) strcat(msg, "13 ");
        if (zones & 32) strcat(msg, "14 ");
        if (zones & 64) strcat(msg, "15 ");
        if (zones & 128) strcat(msg, "16 ");
      }
      else if (cmd == 0x34) {
        strcpy(msg, "Zone3: ");
        zones = getBinaryData(word,41,8);
        if (zones & 1) strcat(msg, "9 ");
        if (zones & 2) strcat(msg, "10 ");
        if (zones & 4) strcat(msg, "11 ");
        if (zones & 8) strcat(msg, "12 ");
        if (zones & 16) strcat(msg, "13 ");
        if (zones & 32) strcat(msg, "14 ");
        if (zones & 64) strcat(msg, "15 ");
        if (zones & 128) strcat(msg, "16 ");
      }
      else if (cmd == 0x3e) {
        strcpy(msg, "Zone4: ");
        zones = getBinaryData(word,41,8);
        if (zones & 1) strcat(msg, "9 ");
        if (zones & 2) strcat(msg, "10 ");
        if (zones & 4) strcat(msg, "11 ");
        if (zones & 8) strcat(msg, "12 ");
        if (zones & 16) strcat(msg, "13 ");
        if (zones & 32) strcat(msg, "14 ");
        if (zones & 64) strcat(msg, "15 ");
        if (zones & 128) strcat(msg, "16 ");
      }
      else
        strcpy(msg, "Unknown command.");
      data0 = getBinaryData(word,0,8);  data1 = getBinaryData(word,8,8);
      data2 = getBinaryData(word,16,8); data3 = getBinaryData(word,24,8);
      data4 = getBinaryData(word,32,8); data5 = getBinaryData(word,40,8);
      data6 = getBinaryData(word,48,2);
      if (strcmp(msg, oldMsg) != 0) {
        fprintf (out_file, "data[%i],cmd:0x%02x,%s\n", i, cmd, msg);
        fprintf (out_file, "***data-all: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",data0,data1,data2,data3,data4,data5,data6);
        strcpy(oldMsg, msg);
      }
    }
  fclose (out_file);

  /* Unlock memory */
  if(munlockall() == -1) {
    perror("munlockall failed");
    exit(-2);
  }

  return 0;
} // main
Exemple #19
0
void readRAMChip(int mem){

	printf("WARNING: Memory being overwritten!\n\nReading RAM chip...");

	//Set address lines and WE to output
	OUT_GPIO(WE);
	OUT_GPIO(A0);
	OUT_GPIO(A1);
	OUT_GPIO(A2);
	OUT_GPIO(A3);
	OUT_GPIO(A4);
	OUT_GPIO(A5);
	OUT_GPIO(A6);
	OUT_GPIO(A7);
	OUT_GPIO(A8);
	OUT_GPIO(A9);
	OUT_GPIO(A10);
	OUT_GPIO(A11);
	OUT_GPIO(A12);
	OUT_GPIO(A13);
	OUT_GPIO(A14);
	OUT_GPIO(A15);
	
	//Set data lines to in
	INP_GPIO(D0);
	INP_GPIO(D1);
	INP_GPIO(D2);
	INP_GPIO(D3);
	
	//SET TO READ
	GPIO_SET = 1 << WE;
	
	nibble temp;
	
	for(int  i = 0; i < 65536; i++){
		
		setAddressLines(i);
		
		usleep(10);
		
		
		//Read Data and put in MEM
		if(GET_GPIO(D0))
			temp.data |= 0x1;
		else
			temp.data &= 0xFFFE;
		if(GET_GPIO(D1))
			temp.data |= 0x2;
		else
			temp.data &= 0xFFFD;
		if(GET_GPIO(D2))
			temp.data |= 0x4;
		else
			temp.data &= 0xFFFB;
		if(GET_GPIO(D3))
			temp.data |= 0x8;
		else
			temp.data &= 0xFFF7;


		if(mem == 1)
			SECONDMEM[i] = temp;
		else
			MAINMEM[i] = temp;

		usleep(10);

	}

	puts("\nFinished reading ram chip into MEM");


}
Exemple #20
0
JNIEXPORT jboolean JNICALL Java_javaforce_pi_GPIO_read
  (JNIEnv *env, jclass obj, jint bit)
{
  return GET_GPIO(bit);
}
Exemple #21
0
int check_gpio(int pin)
{
  return GET_GPIO(pin);
} // check_gpio
Exemple #22
0
inline int digitalRead(int g)
{
	return GET_GPIO(g);
}