static void LED_disable_intern(led_t led) { led_shift.current_led &= ~led; led_shift.dirty = TRUE; if (led & LED_SPI_FLASH) { GPIO_disable(GPIOD, GPIO_Pin_13); } }
BOOTLOADER_TEXT void b_spif_write(u32_t addr, u8_t *b, u16_t len) { GPIO_disable(SPI_FLASH_GPIO_PORT, SPI_FLASH_GPIO_PIN); b_spi_txrx(0x06); // write enable GPIO_enable(SPI_FLASH_GPIO_PORT, SPI_FLASH_GPIO_PIN); volatile int a = 0x100; while (a--) ; GPIO_disable(SPI_FLASH_GPIO_PORT, SPI_FLASH_GPIO_PIN); b_spi_txrx(0x02); // write b_spi_txrx((addr >> 16) & 0xff); b_spi_txrx((addr >> 8) & 0xff); b_spi_txrx((addr >> 0) & 0xff); // write data while (len--) { b_spi_txrx(*b++); } GPIO_enable(SPI_FLASH_GPIO_PORT, SPI_FLASH_GPIO_PIN); }
BOOTLOADER_TEXT void b_spif_read(u32_t addr, u8_t *b, u16_t len) { GPIO_disable(SPI_FLASH_GPIO_PORT, SPI_FLASH_GPIO_PIN); b_spi_txrx(0x03); // read b_spi_txrx((addr >> 16) & 0xff); b_spi_txrx((addr >> 8) & 0xff); b_spi_txrx((addr >> 0) & 0xff); // get data while (len--) { *b++ = b_spi_txrx(0xff); } GPIO_enable(SPI_FLASH_GPIO_PORT, SPI_FLASH_GPIO_PIN); }
// Main server program. This is polled by the client so the client controls the // update speed. // int main(void) { struct sockaddr_in si_me, si_other; int Accel; unsigned int slen = sizeof(si_other); int s, i, recv_len; char buf[BUFLEN]; if(sizeof(buf) < sizeof(Msg)) die("\nmain: Fatal build error"); //create a UDP socket if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { die("\nsocket()"); } // zero out the structure memset((char *) &si_me, 0, sizeof(si_me)); si_me.sin_family = AF_INET; si_me.sin_port = htons(PORT); si_me.sin_addr.s_addr = htonl(INADDR_ANY); //bind socket to port if( bind(s , (struct sockaddr*)&si_me, sizeof(si_me) ) == -1){ die("bind()"); } //Start alarm signal(SIGALRM, sigalrm_handler); alarm(1); PiBlast_init(); GPIO_disable(); Accel_init(); //PiBlast(17,0.15); //usleep(1000000); //keep listening for data while(1) { //printf("Waiting for data..."); //fflush(stdout); //try to receive some data, this is a blocking call @@@@@@ WAIT UDP @@@@@@@@ if ((recv_len = recvfrom(s, buf /*(void *)Msg*/, sizeof(buf), 0, (struct sockaddr *) &si_other, &slen)) == -1) { die("recvfrom()"); } AlarmMsgEn = 1; memcpy(&Msg,buf,sizeof(Msg)); Accel_read(&Msg.Accel); GPIO_drive(Msg.Fore,Msg.Port,Msg.Wdog); //print details of the client/peer and the data received //printf("\nReceived packet %x from %s:%d - A%d",Msg.Wdog, inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port),Msg.Accel); //printf("Data: %s\n" , buf); memcpy(buf,&Msg,sizeof(Msg)); //now reply the client with the same data if (sendto(s, buf, recv_len, 0, (struct sockaddr*) &si_other, slen) == -1) { die("sendto()"); } //kick alarm alarm(1); }//END while close(s); return 0; }// End main
// sigalrm_handler, called if we don't get UDP comms // void sigalrm_handler(int sig) { //printf("\nsigalrm_handler: ALARM!"); GPIO_disable(); alarm(1); }//END sigalrm_handler
void gpio_disable(gpio_port port, gpio_pin pin) { GPIO_disable(io_ports[port], io_pins[pin]); }