Subversion Repositories HomeAutomation

Rev

Rev 1449 | Rev 1453 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1449 Rev 1452
Line 11... Line 11...
11
        0x1234  // y
11
        0x1234  // y
12
    },
12
    },
13
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
13
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
14
};
14
};
15
#endif
15
#endif
-
 
16
 
-
 
17
// types
-
 
18
typedef enum
-
 
19
{
-
 
20
    SNS_SERIAL_PHYFORMAT_RS232 = 0,
-
 
21
    SNS_SERIAL_PHYFORMAT_RS485 = 1,
-
 
22
    SNS_SERIAL_PHYFORMAT_LOOPBACK = 2
-
 
23
} snsSerialPhyFormat_t;
-
 
24
 
-
 
25
// internal variables
-
 
26
static uint16_t baudRate = 9600;
-
 
27
static snsSerialPhyFormat_t format = SNS_SERIAL_PHYFORMAT_RS232;
16
 
28
 
17
void sns_Serial_Init(void)
29
void sns_Serial_Init(void)
18
{
30
{
19
#ifdef sns_Serial_USEEEPROM
31
#ifdef sns_Serial_USEEEPROM
20
    if (EEDATA_OK)
32
    if (EEDATA_OK)
Line 28... Line 40...
28
      eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
40
      eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
29
      EEDATA_UPDATE_CRC;
41
      EEDATA_UPDATE_CRC;
30
    }
42
    }
31
#endif
43
#endif
32
    ///TODO: Initialize hardware etc here
44
    ///TODO: Initialize hardware etc here
33
    uart_init(UART_BAUD_SELECT(9600, F_CPU));
45
    uart_init(UART_BAUD_SELECT(baudRate, F_CPU));
34
    gpio_set_out(sns_Serial_RXEN);
46
    gpio_set_out(sns_Serial_RXEN);
35
    gpio_set_out(sns_Serial_TXEN);
47
    gpio_set_out(sns_Serial_TXEN);
36
    gpio_set_pin(sns_Serial_RXEN);
48
    gpio_set_pin(sns_Serial_RXEN);
37
    gpio_set_pin(sns_Serial_TXEN);
49
    gpio_set_pin(sns_Serial_TXEN);
38
 
50
 
Line 76... Line 88...
76
        case CAN_MODULE_CMD_SERIAL_SERIALDATA:
88
            case CAN_MODULE_CMD_SERIAL_SERIALDATA:
77
            for (uint8_t i=0; i<rxMsg->Length; i++)
89
                for (uint8_t i=0; i<rxMsg->Length; i++)
78
            {
90
                {
79
                uart_putc(rxMsg->Data[i]);
91
                    uart_putc(rxMsg->Data[i]);
80
            }
92
                }
-
 
93
                break;
-
 
94
            case CAN_MODULE_CMD_SERIAL_SERIALCONFIG:
-
 
95
                baudRate = ((uint16_t)rxMsg->Data[0] << 0) | ((uint16_t)rxMsg->Data[1] << 8);
-
 
96
                format = (snsSerialPhyFormat_t)rxMsg->Data[2];
-
 
97
                uart_init(UART_BAUD_SELECT(baudRate, F_CPU));
81
            break;
98
                break;
82
        }
99
        }
83
    }
100
    }
84
}
101
}
85
 
102