mirror of
https://github.com/halleysfifthinc/Toyota-AVC-LAN
synced 2025-06-07 16:06:12 +00:00
More reorganization [nfc]
This commit is contained in:
parent
9581957eca
commit
b9bae7a65f
114
src/avclandrv.c
114
src/avclandrv.c
@ -215,17 +215,18 @@ void AVC_ReleaseLine() {
|
|||||||
AVC_OUT_DIS();
|
AVC_OUT_DIS();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVCLan_Init() {
|
void AVCLAN_init() {
|
||||||
PORTA.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc; // Disable input buffer;
|
|
||||||
PORTA.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc; // recommended when using AC
|
|
||||||
|
|
||||||
// Pull-ups are disabled by default
|
// Pull-ups are disabled by default
|
||||||
// Set pin 6 and 7 as input
|
// Set pin 6 and 7 as input
|
||||||
PORTA.DIRCLR = (PIN6_bm | PIN7_bm);
|
PORTA.DIRCLR = (PIN6_bm | PIN7_bm);
|
||||||
|
PORTA.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc; // Disable input buffer;
|
||||||
|
PORTA.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc; // recommended when using AC
|
||||||
|
|
||||||
// Analog comparator
|
// Analog comparator config
|
||||||
AC2.CTRLA = AC_OUTEN_bm | AC_HYSMODE_25mV_gc | AC_ENABLE_bm;
|
AC2.CTRLA = AC_OUTEN_bm | AC_HYSMODE_25mV_gc | AC_ENABLE_bm;
|
||||||
PORTB.DIRSET = PIN2_bm; // Enable AC2 OUT for LED
|
|
||||||
|
PORTB.DIRSET = PIN2_bm; // Enable AC2 OUT for LED
|
||||||
|
PORTB.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc; // Output only
|
||||||
|
|
||||||
TCB1.CTRLB = TCB_ASYNC_bm | TCB_CNTMODE_SINGLE_gc;
|
TCB1.CTRLB = TCB_ASYNC_bm | TCB_CNTMODE_SINGLE_gc;
|
||||||
TCB1.EVCTRL = TCB_CAPTEI_bm;
|
TCB1.EVCTRL = TCB_CAPTEI_bm;
|
||||||
@ -653,111 +654,12 @@ uint8_t AVCLAN_sendframe(const AVCLAN_frame_t *frame) {
|
|||||||
AVC_OUT_DIS();
|
AVC_OUT_DIS();
|
||||||
STARTEvent;
|
STARTEvent;
|
||||||
|
|
||||||
if (showLog)
|
if (printAllFrames)
|
||||||
AVCLAN_printframe(frame);
|
AVCLAN_printframe(frame);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// uint8_t AVCLan_SendDataBroadcast() {
|
|
||||||
// uint8_t i;
|
|
||||||
|
|
||||||
// STOPEvent;
|
|
||||||
|
|
||||||
// // wait for free line
|
|
||||||
// uint8_t line_busy = 1;
|
|
||||||
|
|
||||||
// TCB1.CNT = 0;
|
|
||||||
// do {
|
|
||||||
// while (INPUT_IS_CLEAR) {
|
|
||||||
// if (TCB1.CNT >= 900)
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// if (TCB1.CNT > 864)
|
|
||||||
// line_busy = 0;
|
|
||||||
// } while (line_busy);
|
|
||||||
|
|
||||||
// AVC_OUT_EN();
|
|
||||||
|
|
||||||
// AVCLan_Send_StartBit();
|
|
||||||
// uint8_t broadcast_control = 0x0;
|
|
||||||
// AVCLAN_sendbits(&broadcast_control, 1); // broadcast
|
|
||||||
|
|
||||||
// uint8_t parity = 0;
|
|
||||||
// AVCLAN_sendbits(&CD_ID, 12); // CD Changer ID as sender
|
|
||||||
// AVCLan_Send_ParityBit(parity);
|
|
||||||
|
|
||||||
// uint16_t audio_addr = 0x1FF;
|
|
||||||
// AVCLAN_sendbits(&audio_addr, 12); // all audio devices
|
|
||||||
// AVCLan_Send_ParityBit(parity);
|
|
||||||
// AVCLan_Send_Bit1();
|
|
||||||
|
|
||||||
// broadcast_control = 0xF;
|
|
||||||
// AVCLAN_sendbits(&broadcast_control, 4); // 0xf - control -> COMMAND WRITE
|
|
||||||
// AVCLan_Send_ParityBit(parity);
|
|
||||||
// AVCLan_Send_Bit1();
|
|
||||||
|
|
||||||
// AVCLAN_sendbyte(&data_len); // data lenght
|
|
||||||
// AVCLan_Send_ParityBit(parity);
|
|
||||||
// AVCLan_Send_Bit1();
|
|
||||||
|
|
||||||
// for (i = 0; i < data_len; i++) {
|
|
||||||
// AVCLAN_sendbyte(&data[i]); // data uint8_t
|
|
||||||
// AVCLan_Send_ParityBit(parity);
|
|
||||||
// AVCLan_Send_Bit1();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// AVC_OUT_DIS();
|
|
||||||
// STARTEvent;
|
|
||||||
// if (showLog)
|
|
||||||
// ShowOutMessage();
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// uint8_t AVCLan_SendAnswerFrame(const uint8_t *cmd) {
|
|
||||||
// uint8_t i;
|
|
||||||
// uint8_t b;
|
|
||||||
|
|
||||||
// b = *cmd++;
|
|
||||||
// data_control = 0xF;
|
|
||||||
// data_len = *cmd++;
|
|
||||||
// for (i = 0; i < data_len; i++) {
|
|
||||||
// data[i] = *cmd++;
|
|
||||||
// }
|
|
||||||
// if (b)
|
|
||||||
// return AVCLan_SendData();
|
|
||||||
// else
|
|
||||||
// return AVCLan_SendDataBroadcast();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// uint8_t AVCLan_SendMyData(uint8_t *data_tmp, uint8_t s_len) {
|
|
||||||
// uint8_t i;
|
|
||||||
// uint8_t *c;
|
|
||||||
|
|
||||||
// c = data_tmp;
|
|
||||||
|
|
||||||
// data_control = 0xF;
|
|
||||||
// data_len = s_len;
|
|
||||||
// for (i = 0; i < data_len; i++) {
|
|
||||||
// data[i] = *c++;
|
|
||||||
// }
|
|
||||||
// return AVCLan_SendData();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// uint8_t AVCLan_SendMyDataBroadcast(uint8_t *data_tmp, uint8_t s_len) {
|
|
||||||
// uint8_t i;
|
|
||||||
// uint8_t *c;
|
|
||||||
|
|
||||||
// c = data_tmp;
|
|
||||||
|
|
||||||
// data_control = 0xF;
|
|
||||||
// data_len = s_len;
|
|
||||||
// for (i = 0; i < data_len; i++) {
|
|
||||||
// data[i] = *c++;
|
|
||||||
// }
|
|
||||||
// return AVCLan_SendDataBroadcast();
|
|
||||||
// }
|
|
||||||
|
|
||||||
uint8_t AVCLan_SendInitCommands() {
|
uint8_t AVCLan_SendInitCommands() {
|
||||||
uint8_t r;
|
uint8_t r;
|
||||||
AVCLAN_frame_t frame = {.broadcast = BROADCAST,
|
AVCLAN_frame_t frame = {.broadcast = BROADCAST,
|
||||||
|
@ -106,14 +106,13 @@ typedef struct AVCLAN_frame_struct {
|
|||||||
} AVCLAN_frame_t;
|
} AVCLAN_frame_t;
|
||||||
|
|
||||||
uint8_t AVCLAN_readframe();
|
uint8_t AVCLAN_readframe();
|
||||||
void AVCLan_Send_Status();
|
uint8_t AVCLAN_sendframe(const AVCLAN_frame_t *frame);
|
||||||
|
void AVCLAN_printframe(const AVCLAN_frame_t *frame);
|
||||||
|
|
||||||
void AVCLan_Init();
|
void AVCLAN_init();
|
||||||
|
void AVCLan_Send_Status();
|
||||||
void AVCLan_Register();
|
void AVCLan_Register();
|
||||||
uint8_t AVCLan_SendAnswer();
|
uint8_t AVCLan_SendAnswer();
|
||||||
uint8_t AVCLAN_sendframe(const AVCLAN_frame_t *frame);
|
|
||||||
|
|
||||||
void AVCLAN_printframe(const AVCLAN_frame_t *frame);
|
|
||||||
|
|
||||||
uint8_t incBCD(uint8_t data);
|
uint8_t incBCD(uint8_t data);
|
||||||
|
|
||||||
|
@ -34,8 +34,10 @@
|
|||||||
#define EV_STATUS 4
|
#define EV_STATUS 4
|
||||||
|
|
||||||
uint8_t Event;
|
uint8_t Event;
|
||||||
|
uint8_t echoCharacters;
|
||||||
|
|
||||||
void Setup();
|
void Setup();
|
||||||
|
void general_GPIO_init();
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
uint8_t readSeq = 0;
|
uint8_t readSeq = 0;
|
||||||
@ -215,27 +217,7 @@ void Setup() {
|
|||||||
printAllFrames = 1;
|
printAllFrames = 1;
|
||||||
echoCharacters = 1;
|
echoCharacters = 1;
|
||||||
|
|
||||||
// Handle unconnected pins PA3, PB3-5
|
general_GPIO_init();
|
||||||
// Set as inputs
|
|
||||||
PORTA.DIRCLR = PIN3_bm;
|
|
||||||
PORTB.DIRCLR = (PIN3_bm | PIN4_bm | PIN5_bm);
|
|
||||||
|
|
||||||
// Enable pull-up resistor and disable input buffer (reduces any EM caused pin
|
|
||||||
// toggling and saves power)
|
|
||||||
PORTA.PIN3CTRL = PORT_PULLUPEN_bm | PORT_ISC_INPUT_DISABLE_gc;
|
|
||||||
PORTB.PIN3CTRL = PORT_PULLUPEN_bm | PORT_ISC_INPUT_DISABLE_gc;
|
|
||||||
PORTB.PIN4CTRL = PORT_PULLUPEN_bm | PORT_ISC_INPUT_DISABLE_gc;
|
|
||||||
PORTB.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_INPUT_DISABLE_gc;
|
|
||||||
|
|
||||||
// Output only pins: PA4-5, PC0-1, PC3, PB2
|
|
||||||
// TODO: TxD (PA1), RTS (PB0) is output only, test if RxD needs the input
|
|
||||||
// buffer or if the UART peripheral bypasses it
|
|
||||||
PORTA.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc;
|
|
||||||
PORTA.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc;
|
|
||||||
PORTC.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
|
|
||||||
PORTC.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc;
|
|
||||||
PORTC.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc;
|
|
||||||
PORTB.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
|
|
||||||
|
|
||||||
// Setup RTC as 1 sec periodic timer
|
// Setup RTC as 1 sec periodic timer
|
||||||
loop_until_bit_is_clear(RTC_STATUS, RTC_CTRLABUSY_bp);
|
loop_until_bit_is_clear(RTC_STATUS, RTC_CTRLABUSY_bp);
|
||||||
@ -247,12 +229,40 @@ void Setup() {
|
|||||||
|
|
||||||
RS232_Init();
|
RS232_Init();
|
||||||
|
|
||||||
AVCLan_Init();
|
AVCLAN_init();
|
||||||
|
|
||||||
Event = EV_NOTHING;
|
Event = EV_NOTHING;
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Configure pin settings which are not configured by peripherals */
|
||||||
|
void general_GPIO_init() {
|
||||||
|
// Set pins PC2-3, PB0,3-5 as inputs
|
||||||
|
PORTC.DIRCLR = (PIN2_bm | // Unconnected
|
||||||
|
PIN3_bm); // CTS
|
||||||
|
PORTB.DIRCLR = (PIN0_bm | // Unconnected
|
||||||
|
PIN3_bm | // IGN_SENSE
|
||||||
|
PIN4_bm | // Unused, but connected to WOC (PC0)
|
||||||
|
PIN5_bm); // Unused, but connected to WOD (PC1)
|
||||||
|
|
||||||
|
// Enable pull-up resistor and disable input buffer (reduces any EM caused pin
|
||||||
|
// toggling and saves power) for unused and unconnected pins
|
||||||
|
PORTC.PIN2CTRL = PORT_PULLUPEN_bm | PORT_ISC_INPUT_DISABLE_gc;
|
||||||
|
PORTB.PIN0CTRL = PORT_PULLUPEN_bm | PORT_ISC_INPUT_DISABLE_gc;
|
||||||
|
|
||||||
|
// Output only pins: PA3-5, PB1-2,4-5; PC0-1
|
||||||
|
// TODO: TxD (PA1), RTS (PA3) is output only, test if RxD needs the input
|
||||||
|
// buffer or if the UART peripheral bypasses it
|
||||||
|
PORTA.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc; // RTS
|
||||||
|
PORTA.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc; // WOA
|
||||||
|
PORTA.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc; // WOB
|
||||||
|
PORTB.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc; // MIC_CONTROL
|
||||||
|
PORTB.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc; // non-driving WOC
|
||||||
|
PORTB.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc; // non-driving WOD
|
||||||
|
PORTC.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc; // WOC
|
||||||
|
PORTC.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc; // WOD
|
||||||
|
}
|
||||||
|
|
||||||
// Periodic interrupt with a 1 sec period
|
// Periodic interrupt with a 1 sec period
|
||||||
ISR(RTC_PIT_vect) {
|
ISR(RTC_PIT_vect) {
|
||||||
if (CD_Mode == stPlay) {
|
if (CD_Mode == stPlay) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user