BlinkenArea - GitList
Repositories
Blog
Wiki
mips_sys
Code
Commits
Branches
Tags
Search
Tree:
e5514ed
Branches
Tags
master
mips_sys
fw
main.c
send ethernet packet on center button press
Stefan Schuermans
commited
e5514ed
at 2012-03-07 21:52:08
main.c
Blame
History
Raw
#include "cyc_cnt.h" #include "eth.h" #include "lcd.h" #include "leds.h" #include "uart.h" #include "switches.h" //#define CFG_SIMULATION #define CFG_ETH_RX #define CFG_ETH_TX #define CFG_UART #ifdef CFG_SIMULATION # define CFG_UART_CHK #else # define CFG_DELAY # define CFG_LCD # define CFG_SWITCHES #endif const int myconst = 0x12345678; int myvar = 0x11223344; volatile int data[100]; #ifdef CFG_ETH_TX static const unsigned char example_packet[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* destination MAC */ 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* source MAC */ 0x08, 0x00, /* ethertype: IP */ 0x45, 0x00, 0x00, 0x36, /* IP header: ..., len */ 0x12, 0x34, 0x00, 0x00, /* IP header: ..., not fragmented */ 0x40, 0x11, 0x00, 0x00, /* IP header: ..., UDP, ... */ 0x7F, 0x00, 0x00, 0x01, /* source IP */ 0xFF, 0xFF, 0xFF, 0xFF, /* destination IP */ 0x00, 0x01, 0x00, 0x01, /* UDP: source port, destination port */ 0x00, 0x22, 0x00, 0x00, /* UDP: len, ... */ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; #endif void switches(void) { #ifdef CFG_LCD #ifdef CFG_SWITCHES lcd_chr(1, 0, switches_get_state(sw_0) ? '0' : ' '); lcd_chr(1, 1, switches_get_state(sw_1) ? '1' : ' '); lcd_chr(1, 2, switches_get_state(sw_2) ? '2' : ' '); lcd_chr(1, 3, switches_get_state(sw_3) ? '3' : ' '); lcd_chr(1, 4, switches_get_state(sw_east) ? 'E' : ' '); lcd_chr(1, 5, switches_get_state(sw_north) ? 'N' : ' '); lcd_chr(1, 6, switches_get_state(sw_south) ? 'S' : ' '); lcd_chr(1, 7, switches_get_state(sw_west) ? 'W' : ' '); lcd_chr(1, 8, switches_get_state(sw_center) ? 'C' : ' '); lcd_chr(1, 9, switches_get_state(sw_rot_a) ? 'a' : ' '); lcd_chr(1, 10, switches_get_state(sw_rot_b) ? 'b' : ' '); #endif #endif #ifdef CFG_LCD #ifdef CFG_SWITCHES unsigned int cnt = switches_get_rot_cnt(); lcd_chr(1, 12, '0' + (cnt >> 9 & 0x7)); lcd_chr(1, 13, '0' + (cnt >> 6 & 0x7)); lcd_chr(1, 14, '0' + (cnt >> 3 & 0x7)); lcd_chr(1, 15, '0' + (cnt & 0x7)); #endif #endif } void delay(void) { unsigned int i; #ifdef CFG_ETH_RX void *vptr; unsigned char *ptr; unsigned int sz; #endif for (i = 0; i < 10; ++i) { switches(); #ifdef CFG_ETH_RX while (eth_rx(&vptr, &sz)) { ptr = vptr; #ifdef CFG_UART for ( ; sz > 0; ptr++, sz--) uart_tx(*ptr); #endif } #endif #ifdef CFG_DELAY cyc_cnt_delay_ms(20); #endif } } int main() { unsigned int i; unsigned short chr; unsigned char leds; leds_set_state(0x01); for (i = 0; i < sizeof(data) / sizeof(data[0]); ++i) data[i] = i; leds_set_state(0x02); #ifdef CFG_ETH_RX eth_rx_init(); #endif leds_set_state(0x04); #ifdef CFG_LCD lcd_init(); lcd_str(0, "MIPS I system"); lcd_str(1, ""); #endif leds_set_state(0x08); #ifdef CFG_UART uart_cfg_scale(62); /* 115200 */ uart_cfg_bits(8); uart_cfg_stop(1); uart_tx('M'); uart_tx('I'); uart_tx('P'); uart_tx('S'); uart_tx(' '); uart_tx('I'); uart_tx('\r'); uart_tx('\n'); #ifdef CFG_UART_CHK if (uart_rx() != 'M') while(1); if (uart_rx() != 'I') while(1); if (uart_rx() != 'P') while(1); if (uart_rx() != 'S') while(1); if (uart_rx() != ' ') while(1); if (uart_rx() != 'I') while(1); if (uart_rx() != '\r') while(1); if (uart_rx() != '\n') while(1); #endif #endif leds_set_state(0x10); leds = 0x11; while (1) { #ifdef CFG_UART if (uart_can_rx()) { chr = uart_rx(); if (uart_is_err(chr)) leds = 0; else leds = chr; } #endif leds_set_state(leds); leds = leds << 1 | leds >> 7; delay(); #ifdef CFG_ETH_TX #ifdef CFG_SWITCHES if (switches_get_state(sw_center)) #endif eth_tx(example_packet, sizeof(example_packet)); #endif } return 0; }