void interface_check(void)
{
- uint8_t count;
if(serial_read_overrun())
interface_send1(RECEIVE_OVERRUN);
- count = serial_read_available();
+ uint8_t count = serial_read_available();
if(count>0)
{
PORTB |= 0x01;
if(cmd_read_pos<cmd_length)
{
- uint8_t i;
if(cmd_read_pos+count>cmd_length)
count = cmd_length-cmd_read_pos;
- for(i=0; i<count; ++i)
+ for(uint8_t i=0; i<count; ++i)
cmd_buffer[cmd_read_pos++] = serial_read();
if(cmd_read_pos>=cmd_length)
void interface_send(const uint8_t *cmd, uint8_t length)
{
- uint8_t i;
-
serial_write(~length);
- for(i=0; i<length; ++i)
+ for(uint8_t i=0; i<length; ++i)
serial_write(cmd[i]);
}
{
if(cmd_buf[0]==READ_TRACK_CURRENT)
{
- uint8_t reply[3];
-
if(cmd_length!=1)
return LENGTH_ERROR;
uint16_t value = track_current_milliamps();
+ uint8_t reply[3];
reply[0] = TRACK_CURRENT;
reply[1] = value>>8;
reply[2] = value;
}
else if(cmd_buf[0]==READ_INPUT_VOLTAGE)
{
- uint8_t reply[3];
-
if(cmd_length!=1)
return LENGTH_ERROR;
uint16_t value = input_voltage_millivolts();
+ uint8_t reply[3];
reply[0] = INPUT_VOLTAGE;
reply[1] = value>>8;
reply[2] = value;
static OutputPacket *motorola_common_packet(uint8_t addr, uint8_t aux, uint8_t value)
{
- uint8_t i;
-
OutputPacket *packet = output_create_packet();
packet->bit_duration = 2;
packet->length = 18*8;
- for(i=0; i<4; ++i)
+ for(uint8_t i=0; i<4; ++i)
{
uint8_t d = addr%3;
addr /= 3;
packet->data[8] = (aux ? 0x7F : 0x01);
packet->data[9] = packet->data[8];
- for(i=0; i<4; ++i)
+ for(uint8_t i=0; i<4; ++i)
{
packet->data[10+i*2] = ((value&1) ? 0x7F : 0x01);
value >>= 1;
static OutputPacket *motorola_old_packet(uint8_t addr, uint8_t aux, uint8_t value)
{
- uint8_t i;
-
OutputPacket *packet = motorola_common_packet(addr, aux, value);
- for(i=0; i<4; ++i)
+ for(uint8_t i=0; i<4; ++i)
packet->data[11+i*2] = packet->data[10+i*2];
return packet;
void motorola_locomotive_speed_function_packet(uint8_t addr, uint8_t aux, uint8_t speed, uint8_t func, uint8_t state)
{
- uint8_t i;
- uint8_t value;
- OutputPacket *packet;
-
- value = motorola_speed_to_value(speed);
- packet = motorola_common_packet(addr, aux, value);
+ uint8_t value = motorola_speed_to_value(speed);
+ OutputPacket *packet = motorola_common_packet(addr, aux, value);
/*
001 -> 011
if(func==value)
func = ((value&8) ? 2 : 5) | (func&8);
- for(i=0; i<4; ++i)
+ for(uint8_t i=0; i<4; ++i)
{
packet->data[11+i*2] = ((func&1) ? 0x7F : 0x01);
func >>= 1;
if(count>=4 || (count>0 && !s88_read_count))
{
uint8_t reply[10];
- uint8_t i;
reply[0] = S88_DATA;
reply[1] = s88_out_index;
- for(i=0; i<count; ++i)
+ for(uint8_t i=0; i<count; ++i)
reply[2+i] = ringbuffer_pop(s88_buffer);
interface_send(reply, 2+count);
s88_out_index += count;
MCU := atmega328p
CLOCK := 16000000
CC := avr-gcc
-CFLAGS := -Wall -Os -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(CLOCK) $(patsubst %,-D%,$(FEATURES)) -I../common
+CFLAGS := -Wall -std=c99 -Os -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(CLOCK) $(patsubst %,-D%,$(FEATURES)) -I../common
LDFLAGS := -Os -Wl,--gc-sections -mmcu=$(MCU)
AVRDUDE := avrdude
OBJCOPY := avr-objcopy
static void lcd_set_data(uint8_t d)
{
#ifdef LCD_SHIFTREG
- uint8_t i;
- for(i=0; i<8; ++i)
+ for(uint8_t i=0; i<8; ++i)
{
PORTB = (PORTB&~0x04)|((d&1)<<2);
PORTB |= 0x08;
while(1)
{
- uint8_t i;
-
check_input();
- i = load_pos;
+ uint8_t i = load_pos;
if(i!=0xFF)
{
output[i] = latch[i];
void check_input()
{
- uint8_t c;
if(!serial_read_available())
return;
- c = serial_read();
+ uint8_t c = serial_read();
if(rx_fill==0xFF)
{
if(c==':')
{
if(rx_fill>=4)
{
- uint16_t offset;
- uint8_t nibbles;
- uint8_t i;
-
- offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
- nibbles = (offset&3);
+ uint8_t offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
+ uint8_t nibbles = (offset&3);
offset >>= 2;
if(rx_fill>3+nibbles)
{
- for(i=0; i<=nibbles; ++i)
+ for(uint8_t i=0; i<=nibbles; ++i)
{
uint16_t j = offset+nibbles-i;
uint8_t shift = 4*(j&1);
if(lcd_enabled)
{
lcd_gotoxy(19-offset-nibbles, 0);
- for(i=0; i<=nibbles; ++i)
+ for(uint8_t i=0; i<=nibbles; ++i)
lcd_write(rx_buf[3+i]);
}
}
while(1)
{
- uint8_t i, j;
uint16_t input = 0;
uint16_t valid = 0xFFF;
- for(i=0; i<100; ++i)
+ for(uint8_t i=0; i<100; ++i)
{
uint16_t pins = 0;
- for(j=0; j<100; ++j)
+ for(uint8_t j=0; j<100; ++j)
pins |= ~((PIND>>2) | ((PINB&0x3F)<<6));
if(i==0)
void send_state(void)
{
- uint8_t i;
-
serial_write(':');
serial_write(hexdigit(offset>>8));
serial_write(hexdigit(offset>>4));
serial_write(hexdigit(offset|(nibbles-1)));
- for(i=nibbles; i--;)
+ for(uint8_t i=nibbles; i--;)
serial_write(hexdigit(state>>(i*4)));
serial_write('.');