int fx_mantissa(Rational lbd, Rational ubd, Rational small) /*;mantissa*/ { Rational exact_val; int *vnum, *vden, *int_1; int power; lbd = rat_abs(lbd); ubd = rat_abs(ubd); /* find the exact # of values to be represented (aside from 0) */ if (rat_gtr(lbd, ubd)) exact_val = rat_div(lbd, small); else exact_val = rat_div(ubd, small); vnum = num(exact_val); vden = den(exact_val); int_1 = int_fri(1); /* the mantissa is calculated assuming that the bound is 'small away * from a model number, so we subtract one before computing no. of bits */ vnum = int_sub(vnum, int_1); vnum = int_quo(vnum, vden); vden = int_fri(1); power = 1; while (int_gtr(vnum, vden)) { power++; vden = int_add(int_add(vden, vden), int_1); } return power; }
int main(void) { //#define MAX 100 #undef MAX #define MAX 1000 #undef MAX #define MAX 1000 int array[MAX]; int a = 100; int b = 200; int c = 300; int MYCAT(i, 1) = 100; int MYCAT(i, 2) = 200; int MYCAT(int, var) = 100; long MYCAT(long, var) = 10000; DEBUGF(float_add(1.1, 2.2)); DEBUGD(int_add(1, 22)); printf("a = %d\n", a); printf("b = %d\n", b); printf("c = %d\n", c); DEBUG(a); DEBUG(b); DEBUG(c); DEBUG((a+b)); return 0; }
static inline int t_lvar_num_add(t_lvar *res, t_lvar *a, t_lvar *b) { if (a->type == T_INTP && b->type == T_INTP) { if (!(res->val->intp = int_add(a->val->intp, b->val->intp))) return (-1); res->type = T_INTP; } return (1); }
int main(int argc, char *argv[]) { int a, b, c, d; a = int_add(-1, 2); b = int_sub(1, 2); c = int_mul(3, 4); d = int_div(4, -2); return (a + b + c + d) ? 0 : 1; }
int main() { uart_init(JSP_BASE); int_init(); int_add(JSP_IRQ, &uart_interrupt, NULL); /* We can't use printf because in this simple example we don't link C library. */ uart_print_str("Hello World.\n"); report(0xdeaddead); or32_exit(0); }
void mod_inv(BIGINT *a, BIGINT *b, BIGINT *x) { BIGINT m, n, p0, p1, p2, q, r, temp, dummy; ELEMENT check; INDEX sw, i; /* initialize loop variables sw = 1; m = b; n = a; p0 = 1; p1 = m/n; q = p1; r = m % n; */ sw = 1; int_copy( b, &m); int_copy( a, &n); int_null ( &p0); p0.hw[INTMAX] = 1; int_div ( &m, &n, &p1, &r); int_copy ( &p1, &q); /* main loop, compute continued fraction intermediates */ check = 0; INTLOOP (i) check |= r.hw[i]; while (check) { sw = -sw; int_copy( &n, &m); int_copy( &r, &n); int_div( &m, &n, &q, &r); /* p2 = (q * p1 + p0) % b; core operation of routine */ int_mul( &q, &p1, &temp); int_add( &temp, &p0, &temp); int_div( &temp, b, &dummy, &p2); int_copy( &p1, &p0); int_copy( &p2, &p1); check = 0; INTLOOP (i) check |= r.hw[i]; } /* sw keeps track of sign. If sw < 0, add modulus to result */ if (sw < 0) int_sub( b, &p0, x); else int_copy( &p0, x); }
int main() { int uart0_core = 0; int uart1_core = 1; uart0_tx_ctrl.busy = 0; /* Set up interrupt handler */ int_init(); /* Install UART core 0 interrupt handler */ int_add(UART0_IRQ, uart_int_handler,(void*) &uart0_core); /* Install UART core 1 interrupt handler */ //int_add(UART1_IRQ, uart_int_handler,(void*) &uart1_core); /* Enable interrupts in supervisor register */ mtspr (SPR_SR, mfspr (SPR_SR) | SPR_SR_IEE); uart_init(uart0_core); //uart_init(uart1_core); //uart_rxint_enable(uart1_core); uart_rxint_enable(uart0_core); char* teststring = "\n\tHello world from UART 0\n\0"; uart0_tx_buffer(teststring); // Do other things while we transmit float f1, f2, f3; int i; f1 = 0.2382; f2 = 4342.65; f3=0; for(i=0;i<32;i++) f3 += f1*f3 + f2; report(f3); report(0x4aaaaa1f); char* done_calculating = "\tDone with the number crunching!\n\0"; uart0_tx_buffer(done_calculating); // Character '*', which will be received in the interrupt handler and cause // the simulation to exit. char* finish = "*\n\0"; uart0_tx_buffer(finish); while(1); // will exit in the rx interrupt routine }
void _add(){ struct atom *a, *b; a = u_pop_atom(); b = u_pop_atom(); if(a->type != b->type) error("Addition: Numbers need to be of the same type."); if(a->type == FLOAT) float_add(a,b); else int_add(a,b); }
void _sub(){ struct atom *a, *b; a = u_pop_atom(); b = u_pop_atom(); if(a->type != b->type) error("Subtraction: Numbers need to be of the same type."); if(a->type == FLOAT){ a->data.float_t *= -1; float_add(a,b); }else{ a->data.int_t *= -1; int_add(a,b); } }
int main () { int i; /* Initialise handler vector */ int_init(); /* Install ethernet interrupt handler, it is enabled here too */ int_add(ETH0_IRQ, oeth_interrupt, 0); /* Enable interrupts in supervisor register */ cpu_enable_user_interrupts(); ethmac_setup(); /* Configure MAC, TX/RX BDs and enable RX and TX in MODER */ /* clear tx_done, the tx interrupt handler will set it when it's been transmitted */ tx_done = 0; rx_done = 0; ethphy_set_100mbit(0); #ifndef ETH_TX_TEST_LENGTH # define ETH_TX_START_LENGTH 40 # define ETH_TX_TEST_LENGTH 1024 # define ETH_TX_TEST_LENGTH_INCREMENT 21 //# define ETH_TX_TEST_LENGTH OETH_TX_BUFF_SIZE #endif for(i=ETH_TX_START_LENGTH;i<ETH_TX_TEST_LENGTH; i+=ETH_TX_TEST_LENGTH_INCREMENT) fill_and_tx_packet(i); ethphy_set_10mbit(0); for(i=ETH_TX_START_LENGTH;i<ETH_TX_TEST_LENGTH; i+=ETH_TX_TEST_LENGTH_INCREMENT) fill_and_tx_packet(i); exit(0x8000000d); }
int main () { /* Initialise handler vector */ int_init(); /* Install ethernet interrupt handler, it is enabled here too */ int_add(ETH0_IRQ, oeth_interrupt, 0); ethmac_setup(ETH0_PHY, ETH0_BUF); /* Configure MAC, TX/RX BDs and enable RX and TX in MODER */ wprint("Entering loop\n"); while (1) { } ethmac_halt(); exit(0x8000000d); return 0; }
static void gpio_set_up_pushbutton_int(int core) { int_init(); gpio_clear_ints(core, PUSHBUTTON_LINE_NUM); // Install interrupt handler int_add(GPIO0_IRQ, gpio_pushbutton_int, 0); // Enable this interrupt in PIC int_enable(GPIO0_IRQ); gpio_int_enable_line(core, PUSHBUTTON_LINE_NUM, 0); // Falling edge triggered line gpio_enable_ints(core); // Enable interrupts cpu_enable_user_interrupts(); }
int main () { /* Initialise handler vector */ int_init(); /* Install ethernet interrupt handler, it is enabled here too */ int_add(ETH0_IRQ, oeth_interrupt, 0); ethmac_setup(ETH0_PHY, ETH0_BUF); /* Configure MAC, TX/RX BDs and enable RX and TX in MODER */ /* clear tx_done, the tx interrupt handler will set it when it's been transmitted */ while (1) { char buf[120]; memcpy(buf, "Hello world!\n", 12); tx_packet(buf, sizeof(buf)); } exit(0x8000000d); }
int main(int argc, char **argv) { char src1[4096] = "Hello world."; char dst1[4096] = "1111111111111111111111111111111111"; char src2[4096] = "The whole world spread before you."; char dst2[4096] = "2222222222222222222222222222222222"; // Attach the external interrupt handler for 'intr0' int_init(); int_add(0, (void *)interruptHandler, NULL); int_enable(0); // Enable external interrupts Uns32 spr = MFSPR(17); spr |= 0x4; MTSPR(17, spr); writeReg8(DMA_BASE, DMA_CONFIGURATION, BURST_SIZE); /* reset */ LOG("initial dst1 '%s' dst2 '%s'\n", dst1, dst2); /* write to DMAC registers to start burst */ dmaBurst(0, src1, dst1, strlen(src1)+1); dmaBurst(1, src2, dst2, strlen(src2)+1); /* wait for burst to complete */ LOG("Waiting for interrupts\n"); while ( interruptCount < 2 ) ; LOG("%u interrupts received\n", interruptCount); /* check results */ LOG("DMA result dst1 '%s' dst2 '%s'\n", dst1, dst2); return 1; }
int main() { // Configure ISRs int_init(); int_add(29, (void *) int_time_cmp, 0); int_enable(); EER = 0xF0000000; // enable all timer events; IER = 0xF0000000; // enable all timer interrupts /* Setup Timer A */ TOCRA = 0x80; TPRA = 0x3F; // set prescaler, enable interrupts and start timer. while (timer_triggered < 5) { printf("Loop Counter: %d\n", timer_triggered); sleep(); } set_gpio_pin_value(0, 0); int_disable(); print_summary(0); return 0; }
int main ( void ) { int_init(); // This is specific for OpenRISC, you may need to call some other routine here // in order to initialise interrupt support and so on. // We use a serial port console to display informational messages. init_uart( UART1_BASE_ADDR ); uart_print( UART1_BASE_ADDR, "This is the Ethernet example program." EOL ); init_ethernet(); int_add( ETH_IRQ, ð_interrupt, NULL ); // Use an Ethernet sniffer like Wireshark in order to see the test frame sent. uart_print( UART1_BASE_ADDR, "Sending the first test frame (which has invalid protocol contents)..." EOL ); int pos = 0; write_broadcast_mac_addr( ð_tx_packet[ pos ] ); pos += MAC_ADDR_LEN; write_own_mac_addr( ð_tx_packet[ pos ] ); pos += MAC_ADDR_LEN; eth_tx_packet[ pos + 0 ] = 0x10; eth_tx_packet[ pos + 1 ] = 0x20; eth_tx_packet[ pos + 2 ] = 0x30; eth_tx_packet[ pos + 3 ] = 0x40; eth_tx_packet[ pos + 4 ] = 0x50; eth_tx_packet[ pos + 5 ] = 0x60; pos += 6; int fill_to_end = 0; if ( fill_to_end ) { while ( pos < MAX_FRAME_LEN ) { eth_tx_packet[ pos ] = (unsigned char) pos; ++pos; } } start_ethernet_send( pos ); wait_until_frame_was_sent(); uart_print( UART1_BASE_ADDR, "Sending the second test frame (which has invalid protocol contents)..." EOL ); pos = 0; write_broadcast_mac_addr( ð_tx_packet[ pos ] ); pos += MAC_ADDR_LEN; write_own_mac_addr( ð_tx_packet[ pos ] ); pos += MAC_ADDR_LEN; eth_tx_packet[ pos + 0 ] = 0x11; eth_tx_packet[ pos + 1 ] = 0x22; eth_tx_packet[ pos + 2 ] = 0x33; eth_tx_packet[ pos + 3 ] = 0x44; eth_tx_packet[ pos + 4 ] = 0x55; eth_tx_packet[ pos + 5 ] = 0x66; pos += 6; start_ethernet_send( pos ); wait_until_frame_was_sent(); const int dump_all_register_values = 0; if ( dump_all_register_values ) { register_read_test(); } // Main infinite loop. // // Wait for incoming frames, dump their contents and reply to a single type of ARP request. // See the README file for an example on how to generate the right type of APR request with arping. for ( ; ; ) { uart_print( UART1_BASE_ADDR, "Waiting for a frame to be received..." EOL ); REG32( get_bd_ptr_addr( s_current_rx_bd_index ) ) = (unsigned long) eth_rx_packet; uint32_t receive_flags = ETH_RXBD_EMPTY | ETH_RXBD_IRQ; if ( s_current_rx_bd_index == BUFFER_DESCRIPTOR_COUNT - 1 ) receive_flags += ETH_RXBD_WRAP; REG32( get_bd_status_addr( s_current_rx_bd_index ) ) = receive_flags; uint32_t status; for ( ; ; ) { status = REG32( get_bd_status_addr( s_current_rx_bd_index ) ); if ( 0 == ( status & ETH_RXBD_EMPTY ) ) { uart_print( UART1_BASE_ADDR, "Frame received." EOL ); break; } } if ( status & ( ETH_RXBD_OR | ETH_RXBD_IS | ETH_RXBD_DN | ETH_RXBD_TL | ETH_RXBD_SF | ETH_RXBD_CRC | ETH_RXBD_LC ) ) { uart_print( UART1_BASE_ADDR, "Error receiving frame, rx status is: " ); uart_print_hex( UART1_BASE_ADDR, status, 8 ); uart_print( UART1_BASE_ADDR, EOL ); } else { const int eth_rx_len = ( status >> 16 ); const int should_dump_frame_contents = 0; if ( should_dump_frame_contents ) { uart_print( UART1_BASE_ADDR, "Received length: " ); uart_print_int( UART1_BASE_ADDR, eth_rx_len ); uart_print( UART1_BASE_ADDR, EOL ); uart_print( UART1_BASE_ADDR, "Frame data: " ); int i; for ( i = 0; i < eth_rx_len; i++ ) { uart_print_hex( UART1_BASE_ADDR, eth_rx_packet[i], 2 ); uart_print( UART1_BASE_ADDR," " ); } uart_print( UART1_BASE_ADDR, EOL "End of received data." EOL ); } if ( ! process_received_frame( eth_rx_len ) ) { uart_print( UART1_BASE_ADDR, "The received frame has been ignored." EOL ); } } ++s_current_rx_bd_index; if ( s_current_rx_bd_index == BUFFER_DESCRIPTOR_COUNT ) s_current_rx_bd_index = TX_BD_COUNT; } }
int main () { tx_data_pointer = 0; /* Initialise handler vector */ int_init(); /* Install ethernet interrupt handler, it is enabled here too */ int_add(ETH0_IRQ, oeth_interrupt, 0); /* Enable interrupts in supervisor register */ cpu_enable_user_interrupts(); /* Enable CPU timer */ cpu_enable_timer(); ethmac_setup(); /* Configure MAC, TX/RX BDs and enable RX and TX in MODER */ /* clear tx_done, the tx interrupt handler will set it when it's been transmitted */ tx_done = 0; rx_done = 0; ethphy_set_100mbit(0); send_ethmac_rxtx_test_init_packet(0x0); // 0x0 - call response test #define ETH_TX_MIN_PACKET_SIZE 512 #define ETH_TX_NUM_PACKETS 20 //int response_time = 150000; // Response time before response packet it sent // back (should be in nanoseconds). int response_time = 0; unsigned long num_to_check; for(num_to_check=ETH_TX_MIN_PACKET_SIZE; num_to_check<ETH_TX_MIN_PACKET_SIZE + ETH_TX_NUM_PACKETS; num_to_check++) fill_and_tx_call_packet(num_to_check, response_time); // Wait a moment for the RX packet check to complete before switching off RX for(num_to_check=0; num_to_check=1000; num_to_check++); oeth_disable_rx(); // Now for 10mbit mode... ethphy_set_10mbit(0); oeth_enable_rx(); for(num_to_check=ETH_TX_MIN_PACKET_SIZE; num_to_check<ETH_TX_MIN_PACKET_SIZE + ETH_TX_NUM_PACKETS; num_to_check++) fill_and_tx_call_packet(num_to_check, response_time); oeth_disable_rx(); // Go back to 100-mbit mode ethphy_set_100mbit(0); oeth_enable_rx(); for(num_to_check=ETH_TX_MIN_PACKET_SIZE; num_to_check<ETH_TX_NUM_PACKETS; num_to_check++) fill_and_tx_call_packet(num_to_check, response_time); exit(0x8000000d); }
static int set_name(void *data, Char *pathname) { EDITINFO *einf = (EDITINFO *) data; XTextProperty prop_name; Char *name; int namesize; Char *stripname, *nname; if (pathname == NULL) { EDITINFO *tinf; FlexArray istck; int i=0,j; int_init(istck); while (aig(tinf=(EDITINFO*)next_data_with_type(MAINEDITWINDOW, &i))) { if (!Ustrncmp(translate(EMPTYFILE),tinf->filename, Ustrlen(translate(EMPTYFILE)))) { j = Ustrtol(tinf->filename+Ustrlen(translate(EMPTYFILE)), NULL, 10); int_add(istck, j); } i++; } i=1; while (int_contains(istck,i)) i++; int_clear(istck); nname = (Char *) malloc(sizeof(Char)*(Ustrlen(userdir) + Ustrlen(translate("/" EMPTYFILE)) + 5 +Ustrlen(translate(EXTENSION)))); concat_in(nname, userdir, translate("/" EMPTYFILE)); stripname = nname + Ustrlen(nname); { Char sb[40]; Char *s; sb[39]=0; s=Ultostr(i,sb+39); Ustrcat(stripname,s); } Ustrcat(stripname, translate(EXTENSION)); } else nname = pathname; stripname = concat(strip_name(nname),NULL); if (!Ustrcmp(stripname+Ustrlen(stripname)-Ustrlen(translate(EXTENSION)), translate(EXTENSION))) stripname[Ustrlen(stripname)-Ustrlen(translate(EXTENSION))] = 0; namesize = Ustrlen(translate(EDITNAME)) + Ustrlen(stripname) + 1 + (einf->saved ? 0 : Ustrlen(translate(CHANGED))) + (einf->view_mode && !einf->shell ? Ustrlen(translate(VIEWCOM)) : 0) + (einf->shell && !einf->fini ? Ustrlen(translate(RUNCOM)) : 0) + (einf->shell && einf->fini ? Ustrlen(translate(DONECOM)) : 0); name = (Char *) malloc((size_t) namesize*sizeof(Char) ); if (name) { name[0]= '\0'; Ustrcat(name, translate(EDITNAME)); Ustrcat(name, stripname); if (!einf->saved && !einf->shell) Ustrcat(name, translate(CHANGED)); if (einf->view_mode && !einf->shell) Ustrcat(name, translate(VIEWCOM)); if (einf->shell && !einf->fini) Ustrcat(name, translate(RUNCOM)); if (einf->shell && einf->fini) Ustrcat(name, translate(DONECOM)); } { char *n; n= (char*)UstrtoLocale(name); if (!name || !XStringListToTextProperty(&n, 1, &prop_name)) { message(MP_ERROR, translate("No location for editname.")); return 0; } } XSetWMName(display, einf->win_id, &prop_name); free(einf->headername); if (einf->pathname!=nname) free(einf->pathname); free(einf->filename); einf->headername = name; einf->filename = stripname; einf->pathname = nname; { char *icn; icn = (char*)UstrtoLocale(stripname); if (!XStringListToTextProperty(&icn, 1, &prop_name)) { message(MP_ERROR, translate("No location for editicon.")); return 0; } } XSetWMIconName(display, einf->win_id, &prop_name); return 1; }