int main(int argc, char **argv) { int g,rep; // Set up gpi pointer for direct register access cmgp = setup_io(ARM_PERI_BASE + CMGP_OFFSET); gpio = setup_io(ARM_PERI_BASE + GPIO_OFFSET); // Set Clock Manager to provivede ~1.8432 MHz from 500 MHz source (PLLD) CMGP_REG(CM_GP0CTL) = (0x5A << 24) // Password // Disable | (1); // Src = oscillator usleep(1000); CMGP_REG(CM_GP0CTL) = (0x5A << 24) // Password // Disable | (6); // Src = PLLD CMGP_REG(CM_GP0DIV) = (0x5A << 24) // Password | (271 << 12); // IDIV usleep(1000); CMGP_REG(CM_GP0CTL) = (0x5A << 24) // Password | (1 << 4) // Enable | (6); // Src = PLLD usleep(1000); // Set GCLK function (ALT0) for GPIO 4 (header pin #7) INP_GPIO(4); SET_GPIO_ALT(4, 0x00); return 0; }
int main(void) { unsigned int i = PASS_COUNT; uint32_t start, diff, count, sum=0; printf ("Raspberry Pi native-C GPIO input speed test program\n") ; piHiPri(); if (setup_io() < 0) return -1; INP_GPIO(TEST_INP); for (; i--;) { printf(" Pass: %d: ", i); fflush(stdout); count = FAST_COUNT; start = millis(); for (; count != 0;--count) { if(TEST_INP_LEV) { /* do nothing */} } diff = millis() - start; printf(" %8dmS\n", diff); sum += diff; } uint32_t avg = sum / PASS_COUNT; // <- this calculates wrong w/o fix //printf("%d\n",sum); // fixes O3 to O0-O2 levels (from ~350 million to ~12k) //printf("%d / %d\n",sum, PASS_COUNT); // fixes all cases printf(" Average: %8dmS", avg); // w/o fix this prints ~12k on O0-O2 and ~350 million on O3 printf(": %6d/msec\n", (int)(double)FAST_COUNT / avg); }
// // LED test code // //int main(int argc, char *argv[]) { void ledTest() { int delay; // Set delay for all tests delay = 250; // Prepare IO on the Pi setup_io(); // Enable LED bar and reset values ledBarEnable(); // LED block tests ledBlockSet(ANODE0, RED, delay); ledBlockSet(ANODE1, RED, delay); ledBlockSet(ANODE2, RED, delay); ledBlockSet(ANODE0, GREEN, delay); ledBlockSet(ANODE1, GREEN, delay); ledBlockSet(ANODE2, GREEN, delay); // Scrolling LED test ledScrollSet(delay); // When done, disable the LED bar ledBarDisable(); // return 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(); }
int main(int argc, char *argv[]) { int g, rep; // Setup the gpio pointer setup_io(); // Swtich GPIOs 7 though 11 to output mode for (g = 5; g <= 6; g++) { INP_GPIO(g); OUT_GPIO(g); GPIO_CLR = 1 << g; // SET it LOW } // Toggle the GPIOs for (rep = 0; rep < 5; rep++) { printf("Repetition: %i\n", rep); for (g = 5; g <= 6; g++) { GPIO_SET = 1 << g; printf(" HIGH: %i\n", g); // sleep(1); usleep(500000); GPIO_CLR = 1 << g; printf(" LOW: %i\n", g); // sleep(1); usleep(500000); } } // Ran file return 0; }
int main(int argc, char **argv) { int i, j; long tmp=0; long tmp_avg=0; long tmp_avg2; long offset=0; float filter_low, filter_high; float spread_percent = SPREAD / 100.0 /2.0; int b; int nsamples=N_SAMPLES; long samples[nsamples]; if (argc == 2) { offset = atol(argv[1]); } setHighPri(); setup_io(); setup_gpio(); reset_converter(); j=0; // get the dirty samples and average them for(i=0;i<nsamples;i++) { reset_converter(); samples[i] = read_cnt(0, argc); tmp_avg += samples[i]; } tmp_avg = tmp_avg / nsamples; tmp_avg2 = 0; j=0; filter_low = (float) tmp_avg * (1.0 - spread_percent); filter_high = (float) tmp_avg * (1.0 + spread_percent); // printf("%d %d\n", (int) filter_low, (int) filter_high); for(i=0;i<nsamples;i++) { if ((samples[i] < filter_high && samples[i] > filter_low) || (samples[i] > filter_high && samples[i] < filter_low) ) { tmp_avg2 += samples[i]; j++; } } if (j == 0) { printf("No data to consider\n"); exit(255); } printf("%d", (tmp_avg2 / j) - offset); // printf("average within %f percent: %d from %d samples, original: %d\n", spread_percent*100, (tmp_avg2 / j) - offset, j, tmp_avg - offset); unpull_pins(); restore_io(); }
int main(int argc, char **argv) { int g,rep; setup_io(); // Set GPIO pins 7-11 to output for (g=7; g<=11; g++) { set_out(g); } for (rep=0; rep<10; rep++) { for (g=7; g<=11; g++) { switch_gpio(1, g); sleep(1); } for (g=7; g<=11; g++) { switch_gpio(0, g); sleep(1); } } return 0; } // main
int main (int argc, char **argv) { int opt, flag, n_pin, n_alt; flag=0; while ((opt = getopt (argc, argv, "hp:f:")) != -1) { switch (opt) { case 'h': break; case 'p': n_pin = atoi(optarg); flag |= 0b0001; break; case 'f': n_alt = atoi(optarg); flag |= 0b0010; break; case '?': // getopt() prints error messages, so don't need to repeat them here return 1; default: abort (); } } if (flag != 0b0011) { fprintf (stderr, "Usage:\n$ gpio_alt -p PIN_NUM -f FUNC_NUM\n"); return 1; } setup_io(); // Set up gpi pointer for direct register access INP_GPIO(n_pin); // Always use INP_GPIO(x) before using SET_GPIO_ALT(x,y) SET_GPIO_ALT(n_pin, n_alt); printf("Set pin %i to alternative-function %i\n", n_pin, n_alt); return 0; }
int main(int argc, char **argv) { // Set up gpi pointer for direct register access setup_io(); // set the GPIO pins used for serial comm with shift registers to output setup_shiftreg(); output_int(0b1111111111111111); sleep(1); output_int(0b0); sleep(1); output_int(0b1001001001001000); sleep(1); output_int(0b0); sleep(1); output_int(0b0100100100100100); sleep(1); output_int(0b0); sleep(1); output_int(0b0010010010010010); sleep(1); output_int(0b0); return 0; } // main
/* * Main function initializes registers and memory, then starts the main loop */ int main(int argc, char** argv){ //Local Variables int status; //Initializations initMem(); #ifdef RPI setup_io(); initGPIOs(); #endif //Setup printf("%s starting up...\n", VERSTR); printf("Command line arguments:\n"); printf("~q: Quit, ~pm lower upper: Prints mem between lower and upper\n"); printf("~pr: Prints register contents, ~rm: reset memmory to 0s\n"); printf("~cp: Changes the period of the clock to given number in nano seconds\n"); printf("~in: Prompt for file input\n"); printf("~run <start location>: runs program starting at <Start location>\n"); printf("~step <start location>: runs program starting at <Start location>. Steps through each execution. ~step without an address continues the current execution.\n"); for(int i = 1; i < argc; i++) { if(argv[i] != NULL) { printf(" %s", argv[i]); } } status = mainloop(); return status; }
void gnt_init() { char *filename; const char *locale; if (channel) return; locale = setlocale(LC_ALL, ""); setup_io(); #ifdef NO_WIDECHAR ascii_only = TRUE; #else if (locale && (strstr(locale, "UTF") || strstr(locale, "utf"))) ascii_only = FALSE; else ascii_only = TRUE; #endif initscr(); typeahead(-1); noecho(); curs_set(0); gnt_init_keys(); gnt_init_styles(); filename = g_build_filename(g_get_home_dir(), ".gntrc", NULL); gnt_style_read_configure_file(filename); g_free(filename); gnt_init_colors(); wbkgdset(stdscr, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); refresh(); #ifdef ALL_MOUSE_EVENTS if ((mouse_enabled = gnt_style_get_bool(GNT_STYLE_MOUSE, FALSE))) mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL); #endif wbkgdset(stdscr, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); werase(stdscr); wrefresh(stdscr); #ifdef SIGWINCH org_winch_handler = signal(SIGWINCH, sighandler); #endif signal(SIGCHLD, sighandler); signal(SIGINT, sighandler); signal(SIGPIPE, SIG_IGN); g_type_init(); init_wm(); clipboard = g_object_new(GNT_TYPE_CLIPBOARD, NULL); }
int main (int argc, char **argv) { /* Setup RF-configuration */ setup_io(); setup_fm(); char *fname = argv[1]; if (!fname) { printf("Pass data file as first and only argument\n"); return -1; } printf("Reading signal data from %s\n", fname); //float freq = 433.800; float freq = 433.917; transmit_repeat(fname, freq / 3.0); //transmit_repeat(fname, freq / 4.0); //transmit_repeat(fname, freq / 5.0); //transmit_repeat(fname, freq / 6.0); //transmit_repeat(fname, freq / 8.0); //transmit_repeat(fname, freq / 11.0 + 0.02/11.0); printf("Shutting down transmission\n"); askLow(); return 0; }
int main(int argc, char **argv) { //int rep; // Set up gpi pointer for direct register access setup_io(); // GPIO23 - NTX2 enable INP_GPIO(23); // must use INP_GPIO before we can use OUT_GPIO OUT_GPIO(23); // GPIO18 - NTX2 Data INP_GPIO(18); // must use INP_GPIO before we can use OUT_GPIO OUT_GPIO(18); GPIO_SET = 1<<23; char send[]="I'm growing a beard\n"; //for (rep=0; rep<8; rep++) { int i; for (i=0; i<strlen(send); i++){ domex_txbyte(send[i]); } //} GPIO_CLR = 1<<23; return 0; }
int main(void) { printf ("Traffic light demo\n"); // Map the I/O sections setup_io(); // Set 12 GPIO pins to output mode setup_gpio(); GPIO_CLR0 = ALL_LEDS; //Turn all LEDs off int i = 1; while(i < 4) //Loop forever { printf("Traffic lights loop %d\n", i); GPIO_SET0 = RED_NORTH | GRN_EAST; // Turn on North red. Turn on East green long_wait(80); // Wait a bit GPIO_CLR0 = ALL_LEDS; // Turn led off GPIO_SET0 = RED_NORTH | YEL_EAST; // Turn on North red. Turn on East yellow long_wait(20); // Wait a short bit GPIO_CLR0 = ALL_LEDS; // Turn led off GPIO_SET0 = RED_NORTH | RED_EAST; long_wait(20); GPIO_CLR0 = ALL_LEDS; GPIO_SET0 = YEL_NORTH | RED_EAST; long_wait(20); GPIO_CLR0 = ALL_LEDS; GPIO_SET0 = GRN_NORTH | RED_EAST; long_wait(80); GPIO_CLR0 = ALL_LEDS; GPIO_SET0 = YEL_NORTH | RED_EAST; long_wait(20); GPIO_CLR0 = ALL_LEDS; GPIO_SET0 = RED_NORTH | RED_EAST; long_wait(20); GPIO_CLR0 = ALL_LEDS; GPIO_SET0 = RED_NORTH | YEL_EAST; long_wait(20); GPIO_CLR0 = ALL_LEDS; i++; } GPIO_CLR0 = ALL_LEDS; //Turn all LEDs off restore_io(); } // main
void init(uint8_t dataPin, uint8_t clockPin) { setup_io(); INP_GPIO(dataPin); // must use INP_GPIO before we can use OUT_GPIO OUT_GPIO(dataPin); INP_GPIO(clockPin); // must use INP_GPIO before we can use OUT_GPIO OUT_GPIO(clockPin); }
static void server_io (void) { for (;;) { int client = accept(server, NULL, 0); if (client == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) break; check(client, "accept()"); setup_io(client); clients = ilist_add(clients, client); report("connect (%d)\n", client); } }
int main(int argc, char **argv) { int g,rep; int i=0; int repCount = 10; double dutyCycle = 0.50; time_t waitTime = 1000000*30; // Default 30ms per blink // Wait time in ms if (argc > 1) waitTime=atoi( argv[1] )*1000; // number of reps if (argc > 2) repCount=atoi( argv[2] ); // pulse width duty cycle if (argc > 3) dutyCycle=(double)(atoi(argv[3])/100.0); if (dutyCycle > 1.0) dutyCycle = 1.0; if (dutyCycle < 0.0) dutyCycle = 0.0; // Set up gpi pointer for direct register access setup_io(); struct timespec waitStruct; waitStruct.tv_sec = 0; waitStruct.tv_nsec = (time_t)(waitTime*dutyCycle); struct timespec waitStructLo; waitStructLo.tv_sec = 0; waitStructLo.tv_nsec = (time_t)(waitTime*(1.0-dutyCycle)); for (i=0;i<nPins;i++) { //INP_GPIO( pins[i] ); // must use INP_GPIO before we can use OUT_GPIO //OUT_GPIO( pins[i] ); init_output( pins[i] ); } for (rep=0; rep<repCount; rep++) { for (i = 0; i < nPins; i++) { SET_PIN( pins[i] ); } nanosleep(&waitStruct, NULL); for (i = 0; i < nPins; i++) { CLR_PIN( pins[i] ); } nanosleep(&waitStructLo,NULL); } GPIO_CLR = 1<<pins[0] | 1<<pins[1] | 1<<pins[2]; return 0; } // main
static gboolean io_invoke_error(GIOChannel *source, GIOCondition cond, gpointer data) { int id = GPOINTER_TO_INT(data); g_source_remove(id); g_io_channel_unref(source); channel = NULL; setup_io(); return TRUE; }
int main(void) { setup_io(); sleep_enable(); while (true) { sleep_cpu(); } }
int main (int argc, char **argv) { /* Setup RF-configuration */ setup_io(); setup_fm(); float freq = 27.100; transmit_repeat(freq); printf("Shutting down transmission\n"); askLow(); return 0; }
int main(int argc, char **argv) { int toogle; // Set up gpi pointer for direct register access setup_io(); // Switch GPIO 7 to output mode /************************************************************************\ * 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! * \************************************************************************/ // Set GPIO pins 7 and 10 to output INP_GPIO(7); // must use INP_GPIO before we can use OUT_GPIO //OUT_GPIO(7); INP_GPIO(10); // must use INP_GPIO before we can use OUT_GPIO OUT_GPIO(10); while(1) { while((GPIO_GET & 0x80)==0) { ; } if(toogle==0) { GPIO_SET = 1<<10; toogle=1; printf("hello\n"); } else { GPIO_CLR = 1<<10; toogle=0; printf("hello\n"); } } //for (rep=0; rep<10; rep++) //{ // //printf("%02X\n", (unsigned) gpio); // GPIO_SET = 1<<7; // // sleep(1); // GPIO_CLR = 1<<7; // // sleep(1); //} return 0; } // main
int main(int argc, char **argv) { #ifdef DEMO_ENABLED int g,rep; #endif /* Set up gpi pointer for direct register access */ setup_io(); #ifndef DEMO_ENABLED /* Set GPIO pin 4 to output */ INP_GPIO(pin); OUT_GPIO(pin); #else /* Set all exposed GPIO pins to output */ for (g = 0; g <= 32; g++) { if( ((1<<g) & 0x3e6cf93) != 0) { INP_GPIO(g); OUT_GPIO(g); } } GPIO_CLR = 0x3e6cf93; //clear all output pins #endif #ifdef DEMO_ENABLED while (1) { for (rep = 0; rep < 14; rep++) { GPIO_SET = 1<<pins[rep]; printf("Set pin: %d\n", pins[rep]); sleep(1); GPIO_CLR = 1<<pins[rep]; printf("Clear pin: %d\n", pins[rep]); sleep(1); } } #else while (1) { GPIO_SET = 1<<pin; printf("Set pin: %d\n", pin); sleep(1); GPIO_CLR = 1<<pin; printf("Clear pin: %d\n", pin); sleep(1); } #endif return 0; }
// // Quick play all patterns // int main(void) { int p,r,last; printf ("These are the connections for the LEDs test:\n"); printf ("jumpers in every out location (U3-out-B1, U3-out-B2, etc)\n"); printf ("GP25 in J2 --- B1 in J3\n"); printf ("GP24 in J2 --- B2 in J3\n"); printf ("GP23 in J2 --- B3 in J3\n"); printf ("GP22 in J2 --- B4 in J3\n"); printf ("GP21 in J2 --- B5 in J3\n"); printf ("GP18 in J2 --- B6 in J3\n"); printf ("GP17 in J2 --- B7 in J3\n"); printf ("GP11 in J2 --- B8 in J3\n"); printf ("GP10 in J2 --- B9 in J3\n"); printf ("GP9 in J2 --- B10 in J3\n"); printf ("GP8 in J2 --- B11 in J3\n"); printf ("GP7 in J2 --- B12 in J3\n"); printf ("(If you don't have enough straps and jumpers you can install\n"); printf ("just a few of them, then run again later with the next batch.)\n"); printf ("When ready hit enter.\n"); (void) getchar(); // Map the I/O sections setup_io(); // Set 12 GPIO pins to output mode setup_gpio(); /* for testing purposes... GPIO_SET0 = 0x180; (void) getchar(); GPIO_CLR0 = 0x100; (void) getchar(); */ for (p=0; p<3; p++) { // run pattern several times start_new_pattern(p); for (r=0; r<2; r++) { do { last = led_step(); long_wait(3); } while (!last); } // run the pattern 2 times } // loop over patterns leds_off(); restore_io(); } // main
int main() { int g,rep; setup_io(); /*Direct Register access*/ #if 0 /*Set gpio 7..11 to outpu mode*/ for(g=7; g <= 18; g++) { INP_GPIO(g); OUT_GPIO(g); } #endif INP_GPIO(17); OUT_GPIO(17); while(1) { GPIO_SET = 1 << 17; //delay(500); sleep(1); GPIO_CLR = 1 << 17; //delay(500); sleep(1); } #if 0 for (rep=0; rep=10; rep++) { for(g=7; g <= 11; g++) { GPIO_SET = 1 << g; sleep(1); } for(g=7; g<= 11; g++) { GPIO_CLR = 1 << g; sleep(1); } } #endif }
static void reap_child(GPid pid, gint status, gpointer data) { ChildProcess *cp = data; if (cp->callback) { cp->callback(status, cp->data); } g_free(cp); clean_pid(); wm->mode = GNT_KP_MODE_NORMAL; endwin(); setup_io(); refresh(); refresh_screen(); }
// // Read ADC input 0 and show as horizontal bar // int main(void) { setup_io(); setup_gpio(); while (1) { // short_wait(); GPIO_CLR0 = 0x080; // short_wait(); GPIO_SET0 = 0x080; } return 0; }
int main(int argc, char **argv) { int g,rep; // Set up gpi pointer for direct register access setup_io(); // Switch GPIO 7..11 to output mode /************************************************************************\ * 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! * \************************************************************************/ // // Set GPIO pins 7-11 to output // for (g=7; g<=11; g++) // { // INP_GPIO(g); // must use INP_GPIO before we can use OUT_GPIO // OUT_GPIO(g); // } // Set GPIO7 to output INP_GPIO(7); OUT_GPIO(7); for (rep=0; rep<10; rep++) { // for (g=7; g<=11; g++) // { // GPIO_SET = 1<<g; // sleep(1); // } // for (g=7; g<=11; g++) // { // GPIO_CLR = 1<<g; // sleep(1); // } GPIO_SET = 1<<7; sleep(1); GPIO_CLR = 1<<7; sleep(1); } return 0; } // main
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; }
void execute_subshell_command(command_t c) { pid_t pid = fork(); int status; if (pid == 0) { setup_io(c); execute_command(c->u.subshell_command); _exit(c->u.subshell_command->status); }else if (pid > 0) waitpid(pid, &status, 0); else error(1, 0, "Forked process failed"); c->status = WEXITSTATUS(status); }
int main(int argc, char **argv) { int g,rep; // Set up gpi pointer for direct register access setup_io(); // Switch GPIO 7..11 to output mode /************************************************************************\ * 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! * \************************************************************************/ FILE * fptr = fopen("cookie_lock", "r+"); if (fptr==NULL) { printf("Error opening file\n"); exit(1); } int result = flock(fileno(fptr), LOCK_EX | LOCK_NB); //exclusive lock and dont block if locked if (result!=0) { printf("Would have blocked, no cookie :( \n"); exit(1); } INP_GPIO(18); OUT_GPIO(18); GPIO_SET = 1<<18; //sleep(4); // nanosleep(&tim,&tim2); usleep(1787000); GPIO_CLR = 1<<18; result = flock(fileno(fptr),LOCK_UN); return 0; } // main