int main() { BSP_Config_HW (); uint8_t data1[1],i=0; uint16_t j=0; uint8_t err=1, error=1; uint8_t data_seri[12]; NEXT_MODULE_t* Module; unlink("image.txt"); unlink("image.JPG"); while(1) { error = NEXT_Module_FingerPresent(Module, data1,0x01); printf("Dat ngon tay vao cam bien\n"); BSP_Delay_ms(1000); if (data1[0] < 50) continue; error = NEXT_Module_ScanImage(Module); printf("Da quet dau van tay thanh cong\n"); BSP_Module_Reset_Configure(); break; } bcm2835_spi_end(); bcm2835_close(); return 0; }
int main(int argc, char **argv) { if (!bcm2835_init()) return 1; bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); bcm2835_spi_setDataMode(BCM2835_SPI_MODE1); bcm2835_spi_setClockDivider(2170-200); bcm2835_spi_chipSelect(BCM2835_SPI_CS0); bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); volatile uint32_t* paddr = bcm2835_spi0 + BCM2835_SPI0_CS/4; bcm2835_peri_set_bits(paddr, BCM2835_SPI0_CS_LEN, BCM2835_SPI0_CS_LEN); //make it 9 bit volatile uint32_t* ltoh = bcm2835_spi0+BCM2835_SPI0_LTOH/4; bcm2835_peri_set_bits(ltoh,0b1111,0); unsigned int i='a'; while(1) { for(char c='a';c<='z';c++) { spi_uart_tx(c); spi_uart_tx(' '); } spi_uart_tx('\n'); // bcm2835_delay(10); // printf(" "); } bcm2835_spi_end(); bcm2835_close(); return 0; }
int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO // Use for testing // bcm2835_set_debug(1); if (!bcm2835_init()) { return 1; } bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default int i; for( i = 0; i < 100; i++ ) { // Send a byte to the slave and simultaneously read a byte back from the slave // If you tie MISO to MOSI, you should read back what was sent uint8_t data = bcm2835_spi_transfer(i); printf("Wrote: %02X Read from SPI: %02X\n", i, data); } bcm2835_spi_end(); bcm2835_close(); return 0; }
int main(int argc, char **argv){ if (!bcm2835_init()) return 1; // SPI INIT bcm2835_spi_begin(); bcm2835_spi_setClockDivider(SPI_CLOCK_DIVIDER_26); // 250MHz / 26 = 9.6MHz bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // CPOL = 0, CPHA = 0 bcm2835_spi_chipSelect(BCM2835_SPI_CS1); // chip select 1 HRF_config_FSK(); HRF_wait_for(ADDR_IRQFLAGS1, MASK_MODEREADY, true); // wait until ready after mode switching HRF_clr_fifo(); printf("send LEGACY message:\t"); static bool switchState = false; switchState = !switchState; bcm2835_gpio_write(LEDR, switchState); // THE MAGIC LINE relayState = 0; //0 = s1 on, 1 = s1 off, 2 = s2 on, 3 = s2 off (I think) // END MAGIC LINE HRF_send_OOK_msg(relayState); bcm2835_spi_end(); return 0; }
static PyObject * PyBCM2835_spi_end(PyObject *self, PyObject *args) { bcm2835_spi_end(); Py_RETURN_NONE; }
/* * Function: spi_test * Description: be used to test SPI related functions by using the AT450BXX module * * host slave * MISO < - > MISO * MOSI < - > MOSI * CLK < - > CLK * CE0/1 < - > CS */ void spi_test(void) { int num; unsigned char wBuf = 0x3f; unsigned char rBuf; printf("--------------->Test SPI With AT450BXX<--------------\n"); bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_64); //bcm2835_spi_chipSelect(BCM2835_SPI_CS0); //bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, HIGH); bcm2835_gpio_fsel(PIN_CS, BCM2835_GPIO_FSEL_OUTP); /*set CS, and must be called*/ printf("SPI write 0x%x\n", wBuf); ee_write(0,wBuf); bcm2835_delay(50); rBuf = ee_read(0); printf("SPI read 0x%x\n", rBuf); if(wBuf == rBuf) { printf("SPI interface work well !...\n"); } else { printf("SPI interface work bad !...\n"); } bcm2835_spi_end(); }
void clear_io() { #if 0 bcm2835_spi_end(); #endif bcm2835_close(); }
void SPIClass::end() { if (initialized) { initialized--; } if (!initialized) { // End the SPI bcm2835_spi_end(); } }
int main(int argc, char *argv[]) { bcm2835_init(); if(comparse(argc, argv) == EXIT_FAILURE) return 0; // setting PWM_PIN as pwm from channel 0 in markspace mode with range = RANGE bcm2835_gpio_fsel(PWM_PIN, BCM2835_GPIO_FSEL_ALT5); //ALT5 is pwm mode bcm2835_pwm_set_clock(BCM2835_PWM_CLOCK_DIVIDER_16); // pwm freq = 19.2 / 16 MHz bcm2835_pwm_set_mode(PWM_CHANNEL, 1, 1); // markspace mode bcm2835_pwm_set_range(PWM_CHANNEL, RANGE); bcm2835_gpio_fsel(OE_SHIFTER, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_set_pud(OE_SHIFTER, BCM2835_GPIO_PUD_DOWN); //pull-down for output enable of logic shifters bcm2835_gpio_fsel(MOTOR_D3, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_set_pud(MOTOR_D3, BCM2835_GPIO_PUD_DOWN); //pull-down for motor enable bcm2835_gpio_fsel(PA0, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_set_pud(PA0, BCM2835_GPIO_PUD_UP); bcm2835_gpio_write(PA0, HIGH); bcm2835_gpio_write(OE_SHIFTER, HIGH); bcm2835_gpio_write(MOTOR_D3, LOW); // creating and running threads pthread_t th1, th2, th3, th4, th5, th6, th7; pthread_create(&th1, NULL, (void*)encoder_time_thread, NULL); pthread_create(&th2, NULL, (void*)magnet_time_thread, NULL); pthread_create(&th3, NULL, (void*)encoder_thread, NULL); pthread_create(&th4, NULL, (void*)magnet_thread, NULL); pthread_create(&th5, NULL, (void*)energy_time_thread, NULL); pthread_create(&th6, NULL, (void*)calculate_energy, NULL); pthread_create(&th7, NULL, (void*)calculate_I_ref, NULL); bcm2835_delay(100); // delay to make sure that all threads are initialised and iC-MU is conofigured printf("\nPress enter to start the motor."); getchar(); bcm2835_gpio_write(MOTOR_D3, HIGH); start = 1; printf("Started.\n"); printf("\nPress enter to stop the motor.\n"); getchar(); bcm2835_gpio_write(MOTOR_D3, LOW); bcm2835_spi_end(); bcm2835_close(); return 0; }
SpiPlateformImplementation::~SpiPlateformImplementation() { if( --s_count <=0 ) { s_count = 0; printf("\n SPI DEINIT"); #ifdef TARGET_RASPBERRY_PI bcm2835_spi_end(); #endif } }
/* Name: spi_close Description: De-initialize bcm2835 lib Parameters: Returns: 0 - on success, non-zero - fail */ int spi_close(void) { bcm2835_spi_end(); int r = bcm2835_close(); if (r != 1) { return -1; // can't close } #ifdef _DEBUG_ fprintf(stdout, "BCM2835_SPI.CLOSE: OK.\n"); #endif return r; }
void main(int argc, char* argv) { /* Pour le debugging 1 == Print sur la console les operations des fonctions 0 == Comportement normal du programme */ bcm2835_set_debug(0); /* Initialisation de la librairie */ if(bcm2835_close()) { /* code d'initialisation bcm */ printf("Version de la librairie : %d", bcm2835_version()); if(bcm2835_spi_begin()) { /* Initialisation de la SPI Voir header pour valeurs */ bcm2835_spi_setClockDivider(CLK_SPEED); bcm2835_spi_setDataMode(PI_MODE); bcm2835_spi_setBitOrder(BIT_ORDER); /* Selecte un CS pour le transfert de donnees */ bcm2835_spi_chipSelect(CS_SLAVE); /* Test de transfert avec retour */ uint8_t ret; ret = bcm2835_spi_transfer(5); printf("Retour de l'Arduino : %d", ret); /* Test de transfert sans retour */ bcm2835_spi_transfern("A", 1); bcm2835_spi_end(); } else { printf("Erreur de l'init de SPI\n"); } bcm2835_close(void); /* Libere la memoire et ferme la librairie */ } else { printf("Echec de l'ouverture de la librairie\n"); } }
void ArduiPi_OLED::close(void) { // De-Allocate memory for OLED buffer if any if (poledbuff) free(poledbuff); poledbuff = NULL; // Release Raspberry SPI if ( isSPI() ) bcm2835_spi_end(); // Release Raspberry I2C if ( isI2C() ) bcm2835_i2c_end(); // Release Raspberry I/O control bcm2835_close(); }
int main(int argc, char **argv) { if (!bcm2835_init()) return 1; char buffer[4]; buffer[0] = 50; int i,temp; bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); bcm2835_spi_setDataMode(BCM2835_SPI_MODE3); //SCLK rising edge - clock idle state 1 bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); //set clock frequency bcm2835_spi_chipSelect(BCM2835_SPI_CS1); //use chip select 1 bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS1, LOW); //chip select 0 to activate buffer[0]=buffer[1]=buffer[2]=buffer[3]=0; //bcm2835_spi_transfern(buffer,4); buffer[0] = 0x58; //read the id bcm2835_spi_transfern(buffer,2); printf("id:%02X\n",buffer[1]); while(1) { buffer[0] = 0x50; //read the temp bcm2835_spi_transfern(buffer,3); printf("status %02X %02X\n",buffer[1],buffer[2]); temp = buffer[1]; temp = temp<<8; temp = temp + ( buffer[2] & 0xF8); printf("status %08x\n",temp); temp = temp>>3; temp = temp/16; printf("temp:%d\n",temp); sleep(1); } bcm2835_spi_end(); bcm2835_close(); return 0; }
int main(int argc, char **argv) { if (!bcm2835_init()) { printf("oops, could not init bcm2835\n"); return 1; } else { printf("Initialized"); } bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_1024); // ~ 4 MHz bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default uint8_t mosi[12] = { 0x60, 0x00 }; uint8_t miso[12] = { 0 }; printf("Starting"); int data[30000]; for (int i = 0; i < 30000; i++) { bcm2835_spi_transfernb(mosi, miso, 2); // // printf("%d\n", miso[1] + ((miso[0] & 3) << 8)); // data[i] = miso[1] + ((miso[0] & 3) << 10); data[i] = miso[1] + miso[0]; } bcm2835_spi_end(); bcm2835_close(); FILE *fp=fopen("output2.csv","wr"); for(int i=0;i<30000;i++) { fprintf(fp,"%d,\n",data[i]); } fclose(fp); return 0; }
int mcp3008_adc_read(uint8_t single_diff, uint8_t channel, uint16_t *adcout) { if(single_diff != MCP3008_ADC_SINGLE && single_diff != MCP3008_ADC_DIFF ) return -1; if(channel > ADC_7 ) return -1; bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE3); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_1024); // ~ 4 MHz bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE); // // Active the CS pin MCP3008_CS_CLR; // SleepMs(1); uint8_t tx[10] = { MCP3008_SPI_START_BYTE, (single_diff|channel)<<4 }; uint8_t rx[10] = { 0 }; bcm2835_spi_transfernb(tx, rx, 3); bcm2835_spi_end(); // 0100 aaa r/w MCP3008_CS_SET; *adcout = ((rx[1]&0x03) << 8) | rx[2]; return (EXIT_SUCCESS); }
int main(int argc, char *argv[]) { if (1 == argc) { printf("Enter text as an argument.\n"); return 1; } if (!bcm2835_init()) { printf("Unable to init bcm2835.\n"); return 2; } bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_256); // The default bcm2835_gpio_fsel(Max7219_pinCS, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_write(disp1[0][0],HIGH); Delay_xms(50); Init_MAX7219(); size_t index = 0; while (index < strlen(argv[1])) { // Retrive first letter char letter1 = toupper(argv[1][index]); index++; // Retrieve second letter // If it does not exist use space char letter2 = (index < strlen(argv[1])) ? toupper(argv[1][index]) : (char) 0; led_print(find_char(letter1), find_char(letter2)); Delay_xms(1000); index++; } // Clear screen led_print(36, 36); bcm2835_spi_end(); bcm2835_close(); return 0; }
int main(int argc, char **argv) { if (!bcm2835_init()) { printf("bcm2835_init failed. Are you running as root??\n"); } else if (!bcm2835_spi_begin()) { printf("bcm2835_spi_begin failed\n"); } else { // List of all CS line where module can be connected // GPIO6, GPIO8/CE0, GPIO7/CE1, GPIO26 uint8_t CS_pins[] = {6, 7, 8, 26}; uint8_t i; // Init SPI bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default // We control CS line manually don't assert CEx line! bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE); // Drive all CS line as output and set them High to avoid any conflict for ( i=0; i<sizeof(CS_pins); i++) { bcm2835_gpio_fsel (CS_pins[i], BCM2835_GPIO_FSEL_OUTP ); bcm2835_gpio_write(CS_pins[i], 1 ); } // Now try to detect all modules for ( i=0; i<sizeof(CS_pins); i++) { readModuleVersion( CS_pins[i] ); } bcm2835_spi_end(); } bcm2835_close(); }
void VM205::disconnect() { bcm2835_spi_end(); }
int main(int argc, char **argv) { int16_t ledIndexCounter = 0, scanPasses=0, colourIndex=0; initData(); //Initiate the SPI Data Frame if (!bcm2835_init()) { printf("bcm2835_init failed. Are you running as root??\n"); return 1; } if (!bcm2835_spi_begin()) { printf("bcm2835_spi_begin failedg. Are you running as root??\n"); return 1; } bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default /* BCM2835_SPI_MODE0 CPOL = 0, CPHA = 0 BCM2835_SPI_MODE1 CPOL = 0, CPHA = 1 BCM2835_SPI_MODE2 CPOL = 1, CPHA = 0 BCM2835_SPI_MODE3 CPOL = 1, CPHA = 1 */ bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_16); // The default /* BCM2835_SPI_CLOCK_DIVIDER_65536 65536 = 262.144us = 3.814697260kHz BCM2835_SPI_CLOCK_DIVIDER_32768 32768 = 131.072us = 7.629394531kHz BCM2835_SPI_CLOCK_DIVIDER_16384 16384 = 65.536us = 15.25878906kHz BCM2835_SPI_CLOCK_DIVIDER_8192 8192 = 32.768us = 30/51757813kHz BCM2835_SPI_CLOCK_DIVIDER_4096 4096 = 16.384us = 61.03515625kHz BCM2835_SPI_CLOCK_DIVIDER_2048 2048 = 8.192us = 122.0703125kHz BCM2835_SPI_CLOCK_DIVIDER_1024 1024 = 4.096us = 244.140625kHz BCM2835_SPI_CLOCK_DIVIDER_512 512 = 2.048us = 488.28125kHz BCM2835_SPI_CLOCK_DIVIDER_256 256 = 1.024us = 976.5625kHz BCM2835_SPI_CLOCK_DIVIDER_128 128 = 512ns = = 1.953125MHz BCM2835_SPI_CLOCK_DIVIDER_64 64 = 256ns = 3.90625MHz BCM2835_SPI_CLOCK_DIVIDER_32 32 = 128ns = 7.8125MHz BCM2835_SPI_CLOCK_DIVIDER_16 16 = 64ns = 15.625MHz BCM2835_SPI_CLOCK_DIVIDER_8 8 = 32ns = 31.25MHz BCM2835_SPI_CLOCK_DIVIDER_4 4 = 16ns = 62.5MHz BCM2835_SPI_CLOCK_DIVIDER_2 2 = 8ns = 125MHz, fastest you can get */ bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default for(colourIndex=0; colourIndex<rainbowSize*10; colourIndex+=5) { getColour(colourIndex%rainbowSize, tmpColour); //set 1st Pixel ledDataBlock[8]=255; ledDataBlock[9]=tmpColour[2]; ledDataBlock[10]=tmpColour[1]; ledDataBlock[11]=tmpColour[0]; //push the array for(ledIndexCounter=(spiFrameLength-(endFrameLength*bytesPerLED))-bytesPerLED; ledIndexCounter>8; ledIndexCounter-=bytesPerLED) { ledDataBlock[ledIndexCounter] = ledDataBlock[ledIndexCounter-bytesPerLED]; ledDataBlock[ledIndexCounter+1] = ledDataBlock[ledIndexCounter+1-bytesPerLED]; ledDataBlock[ledIndexCounter+2] = ledDataBlock[ledIndexCounter+2-bytesPerLED]; ledDataBlock[ledIndexCounter+3] = ledDataBlock[ledIndexCounter+3-bytesPerLED]; } //send to LEDs bcm2835_spi_writenb(ledDataBlock, spiFrameLength); bcm2835_delay(5); } //clear and render initData(); bcm2835_spi_writenb(ledDataBlock, spiFrameLength); //close the spi bus bcm2835_spi_end(); bcm2835_close(); return 0; }
/** *@brief Close SPI bus, should not be called if another SPI device is being used *@return none */ void SPI_Close(void) { bcm2835_spi_end(); }
void DIS_close(void){ bcm2835_spi_end(); bcm2835_close(); }
void tearDownSPI() { bcm2835_spi_end(); }
void Rfid::release_rfid(void) { bcm2835_spi_end(); bcm2835_close(); }
//void bcm2835_spi_end(void); /// Call bcm2835_spi_end /// \par Refer /// \par Modify void ope_spi_end(void) { bcm2835_spi_end(); }
int main(int argc, char **argv) { if (!bcm2835_init()) return 1; bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default softReset(); /* printf("status: %d \n", readStatus()); printf("config: %d \n", readConfig()); printf("mode: %d \n", readMode()); printf("gain: %d \n", gainSetting); */ //changeInput(0); //changeGain(AD7794_GAIN_8); //delay(changeInputDelay); //Time to value is ready long fullData; int readAmount = 10; int delayMilis=20; while(1){ long input0 = readAvgValueFromInput(0, readAmount, delayMilis); printf("Value at input %d: %d / %06X\n", currentInput, input0, input0); long input1 = readAvgValueFromInput(1, readAmount, delayMilis); printf("Value at input %d: %d / %06X\n", currentInput, input1, input1); long input2 = readAvgValueFromInput(2, readAmount, delayMilis); printf("Value at input %d: %d / %06X\n", currentInput, input2, input2); long input3 = readAvgValueFromInput(3, readAmount, delayMilis); printf("Value at input %d: %d / %06X\n", currentInput, input3, input3); long avg = (input0 + input1 + input2 + input3) / 4; printf("avg: %d / %06X\n", avg, avg); } int loopc=0; while(1){ fullData = readSingleValue(); printf("Value at input %d: %d / %06X\n", currentInput, fullData, fullData); printf("status: %d \n", readStatus()); ++loopc; if (loopc>=10){ if (currentInput<3){ changeInput(currentInput+1); } else { changeInput(0); } delay(changeInputDelay); loopc=0; } else { delay(delayMilis); } } bcm2835_spi_end(); return 0; }
void bw_spi_dio_end(void) { bcm2835_spi_end(); bcm2835_close(); }
void SPIClass::end() { //End the SPI bcm2835_spi_end(); }
int main(int argc, char **argv) { sem_init(&empty, 0, MAX); sem_init(&full, 0, 0); sem_init(&mutex, 0, 1); //mutal exlusion sem_init(&tx_empty, 0, TX_MAX); sem_init(&tx_full, 0, 0); if (!bcm2835_init()){ printf("init done failed \n"); return 1; } bcm2835_gpio_fsel(RPI_BPLUS_GPIO_J8_40 , BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_write(RPI_BPLUS_GPIO_J8_40, LOW); bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_LSBFIRST); bcm2835_spi_setDataMode(BCM2835_SPI_MODE3); bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_16); bcm2835_spi_chipSelect(BCM2835_SPI_CS0); bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); printf("init done \n"); //audio_init(); pthread_t pid, pid2; pthread_create(&pid, NULL, spiReader, NULL); pthread_create(&pid2, NULL, packetreader, NULL); pthread_create(&pid, NULL, spiWriter, NULL); /* create a UDP socket */ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("cannot create socket\n"); return 0; } struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = TIMEOUT_MS; if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,(char*)&timeout,sizeof(timeout)) < 0) perror("setsockopt failed\n"); /* bind the socket to any valid IP address and a specific port */ memset((char *)&myaddr, 0, sizeof(myaddr)); myaddr.sin_family = AF_INET; myaddr.sin_addr.s_addr = htonl(INADDR_ANY); myaddr.sin_port = htons(SERVICE_PORT); if (bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) { perror("bind failed"); return 0; } runHermesLite(); bcm2835_spi_end(); bcm2835_close(); }
void bw_spi_7fets_end(void) { bcm2835_spi_end(); bcm2835_close(); }