/* UART initialistaion function */ static void App_UART_Init(LPC_USART_T *pUART) { Board_UART_Init(pUART); Chip_UART_ConfigData(pUART, UART_DATALEN_8, UART_PARITY_NONE, UART_STOPLEN_1); Chip_UART_SetBaudRate(pUART, UART_TEST_DEFAULT_BAUDRATE); Chip_UART_Init(pUART); }
/* Set up and initialize all required blocks and functions related to the board hardware */ void Board_Init(void) { /* Sets up DEBUG UART */ DEBUGINIT(); /* Initializes GPIO */ Chip_GPIO_Init(LPC_GPIO_PORT); Board_GPIOs_Init(); /* Initialize LEDs */ Board_LED_Init(); /* Initialize uarts */ Board_UART_Init(LPC_USART0); //RS 485 Board_UART_Init(LPC_USART3); // rs232 /* Initialize buttons */ Board_Buttons_Init(); /* Initialize DAC */ Board_DAC_Init(); /* Initialize Timers */ Board_TIMER_Init(); /* Initialize ADCs */ Board_ADC_Init(); /* Initialize Keyboard disabled */ Board_KEYBOARD_disable(); /* Initilize EEPROM */ Board_EEPROM_init(); /* Initialize SPI pins */ Board_SSP_Init(); /* Initialize RTC module */ //Board_RTC_Init(); /* Initialize I2C0 module */ Board_I2C_Master_Init(); Chip_ENET_RMIIEnable(LPC_ETHERNET); }
/** * @brief Main UART program body * @return Always returns 1 */ int main(void) { uint8_t key; int bytes; SystemCoreClockUpdate(); Board_Init(); Board_UART_Init(LPC_UARTX); Board_LED_Set(0, false); /* Setup UART for 115.2K8N1 */ Chip_UART_Init(LPC_UARTX); Chip_UART_SetBaud(LPC_UARTX, 115200); Chip_UART_ConfigData(LPC_UARTX, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT)); Chip_UART_SetupFIFOS(LPC_UARTX, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2)); Chip_UART_TXEnable(LPC_UARTX); /* Before using the ring buffers, initialize them using the ring buffer init function */ RingBuffer_Init(&rxring, rxbuff, 1, UART_RRB_SIZE); RingBuffer_Init(&txring, txbuff, 1, UART_SRB_SIZE); /* Reset and enable FIFOs, FIFO trigger level 3 (14 chars) */ Chip_UART_SetupFIFOS(LPC_UARTX, (UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS | UART_FCR_TRG_LEV3)); /* Enable receive data and line status interrupt */ Chip_UART_IntEnable(LPC_UARTX, (UART_IER_RBRINT | UART_IER_RLSINT)); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(UARTx_IRQn, 1); NVIC_EnableIRQ(UARTx_IRQn); /* Send initial messages */ Chip_UART_SendRB(LPC_UARTX, &txring, inst1, sizeof(inst1) - 1); Chip_UART_SendRB(LPC_UARTX, &txring, inst2, sizeof(inst2) - 1); /* Poll the receive ring buffer for the ESC (ASCII 27) key */ key = 0; while (key != 27) { bytes = Chip_UART_ReadRB(LPC_UARTX, &rxring, &key, 1); if (bytes > 0) { /* Wrap value back around */ if (Chip_UART_SendRB(LPC_UARTX, &txring, (const uint8_t *) &key, 1) != 1) { Board_LED_Toggle(0);/* Toggle LED if the TX FIFO is full */ } } } /* DeInitialize UART0 peripheral */ NVIC_DisableIRQ(UARTx_IRQn); Chip_UART_DeInit(LPC_UARTX); return 1; }
/* Initialize debug output via UART for board */ void Board_Debug_Init(void) { #if defined(DEBUG_UART) Board_UART_Init(); Chip_UART_Init(DEBUG_UART); Chip_UART_ConfigData(DEBUG_UART, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1); Chip_UART_SetBaud(DEBUG_UART, 115200); Chip_UART_Enable(DEBUG_UART); Chip_UART_TXEnable(DEBUG_UART); #endif }
/* Initialize debug output via UART for board */ void Board_Debug_Init(void) { #if defined(DEBUG_UART) Board_UART_Init(DEBUG_UART); Chip_UART_ConfigData(DEBUG_UART, UART_DATALEN_8, UART_PARITY_NONE, UART_STOPLEN_1); Chip_UART_SetBaudRate(DEBUG_UART, 115200); Chip_UART_Init(DEBUG_UART); #endif }
/* Initialize debug output via UART for board */ void Board_Debug_Init(void) { #if defined(DEBUG_UART) Board_UART_Init(); Chip_UART_Init(DEBUG_UART); Chip_UART_ConfigData(DEBUG_UART, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1); Chip_Clock_SetUSARTNBaseClockRate((115200 * 16), true); Chip_UART_SetBaud(DEBUG_UART, 115200); Chip_UART_Enable(DEBUG_UART); Chip_UART_TXEnable(DEBUG_UART); #endif }
/* Initialize debug output via UART for board */ void Board_Debug_Init(void) { #if defined(DEBUG_ENABLE) Board_UART_Init(); /* Setup UART for 115.2K8N1 */ Chip_UART_Init(LPC_USART); Chip_UART_SetBaud(LPC_USART, 115200); Chip_UART_ConfigData(LPC_USART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT)); Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2)); Chip_UART_TXEnable(LPC_USART); #endif }
/* Initialize debug output via UART for board */ void Board_Debug_Init(void) { #if defined(DEBUG_UART) Board_UART_Init(DEBUG_UART); Chip_UART_Init(DEBUG_UART); Chip_UART_SetBaudFDR(DEBUG_UART, 115200); Chip_UART_ConfigData(DEBUG_UART, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS); /* Enable UART Transmit */ Chip_UART_TXEnable(DEBUG_UART); #endif }
/* Initialize debug output via UART for board */ void Board_Debug_Init(void) { #if defined(DEBUG_ENABLE) Board_UART_Init(DEBUG_UART); /* Setup UART for 115.2K8N1 */ Chip_UART_Init(DEBUG_UART); Chip_UART_SetBaud(DEBUG_UART, 115200); Chip_UART_ConfigData(DEBUG_UART, UART_DATABIT_8, UART_PARITY_NONE, UART_STOPBIT_1); /* Enable UART Transmit */ Chip_UART_TxCmd(DEBUG_UART, ENABLE); #endif }
/** * @details Initializes board peripherals */ void Init_Board(void) { // ------------------------------------------------ // Board Periph Init Board_LED_Init(); Board_LED_On(); Board_Switch_Init(); Board_Contactors_Init(); // ------------------------------------------------ // Communication Init Board_UART_Init(UART_BAUD); Board_SPI_Init(SPI_BAUD); Board_CCAN_Init(CCAN_BAUD, CAN_rx, CAN_tx, CAN_error); }
void chip_startup_routine(void) { SystemCoreClockUpdate(); // Initialize SysTick Timer to generate millisecond count if (Board_SysTick_Init()) { while(1); // Unrecoverable Error. Hang. } // Initialize UART Communication Board_UART_Init(UART_BAUD_RATE); Board_UART_Println("Started up driver interface!"); // Initialize GPIO and LED as output Board_LEDs_Init(); Board_LED_On(LED0); Board_LED_On(LED1); // Initialize CAN and CAN Ring Buffer RingBuffer_Init(&CAN_rx_buffer, _rx_buffer, sizeof(CCAN_MSG_OBJ_T), BUF_SIZE); RingBuffer_Flush(&CAN_rx_buffer); Board_CAN_Init(CCAN_BAUD_RATE, CAN_rx, CAN_tx, CAN_error); can_error_flag = false; can_error_info = 0; }
int main(void) { //--------------- // Initialize UART Communication Board_UART_Init(UART_BAUD_RATE); Board_UART_Println("Started up"); //--------------- // Initialize SysTick Timer to generate millisecond count if (Board_SysTick_Init()) { Board_UART_Println("Failed to Initialize SysTick. "); // Unrecoverable Error. Hang. while(1); } //--------------- // Initialize GPIO and LED as output Board_LEDs_Init(); Board_LED_On(LED0); //--------------- // Initialize CAN and CAN Ring Buffer RingBuffer_Init(&can_rx_buffer, _rx_buffer, sizeof(CCAN_MSG_OBJ_T), BUFFER_SIZE); RingBuffer_Flush(&can_rx_buffer); Board_CAN_Init(CCAN_BAUD_RATE, CAN_rx, CAN_tx, CAN_error); // For your convenience. // typedef struct CCAN_MSG_OBJ { // uint32_t mode_id; // uint32_t mask; // uint8_t data[8]; // uint8_t dlc; // uint8_t msgobj; // } CCAN_MSG_OBJ_T; msg_obj.msgobj = 1; msg_obj.mode_id = 0x000; msg_obj.mask = 0x000; LPC_CCAN_API->config_rxmsgobj(&msg_obj); can_error_flag = false; can_error_info = 0; uint8_t status_led_state = 1; uint32_t status_led_time = msTicks; while (1) { if (!RingBuffer_IsEmpty(&can_rx_buffer)) { Board_LED_On(LED3); CCAN_MSG_OBJ_T temp_msg; RingBuffer_Pop(&can_rx_buffer, &temp_msg); Board_UART_PrintNum(temp_msg.mode_id, 16, false); Board_UART_Print("\t"); Board_UART_PrintNum(temp_msg.dlc, 10, false); int i = 0; for (i = 0; i < temp_msg.dlc; i++) { Board_UART_Print("\t"); Board_UART_PrintNum(temp_msg.data[i], 16, false); } Board_UART_Println(""); Board_LED_Off(LED3); } if (can_error_flag) { can_error_flag = false; Board_UART_Print("CAN Error: 0b"); Board_UART_PrintNum(can_error_info, 2, true); } if (msTicks - status_led_time > STATUS_LED_PERIOD) { status_led_time = msTicks; status_led_state = 1 - status_led_state; Board_LED_Set(LED0, status_led_state); } } }
int main(void) { if (Board_SysTick_Init()) { while(1); } Board_LEDs_Init(); Board_LED_On(LED0); Board_ADC_Init(); uint16_t tps_data = 0; int16_t tps_error = 0; Board_UART_Init(9600); DEBUG_Print("Started up\n\r"); RingBuffer_Init(&rx_buffer, _rx_buffer, sizeof(CCAN_MSG_OBJ_T), 8); RingBuffer_Flush(&rx_buffer); Board_CAN_Init(TEST_CCAN_BAUD_RATE, CAN_rx, CAN_tx, CAN_error); msg_obj.msgobj = 1; msg_obj.mode_id = 0x301; msg_obj.mask = 0x000; LPC_CCAN_API->config_rxmsgobj(&msg_obj); can_error_flag = false; can_error_info = 0; bool send = false; while (1) { Board_TPS_ADC_Read(&tps_data); // itoa(tps_data,tx_buffer_str,10); // DEBUG_Print("TPS_DATA:"); // DEBUG_Print(tx_buffer_str); // DEBUG_Print("\r\n"); if (!RingBuffer_IsEmpty(&rx_buffer)) { CCAN_MSG_OBJ_T temp_msg; RingBuffer_Pop(&rx_buffer, &temp_msg); DEBUG_Print("Received Message ID: 0x"); itoa(temp_msg.mode_id, str, 16); DEBUG_Print(str); DEBUG_Print("\r\n"); } if (can_error_flag) { can_error_flag = false; DEBUG_Print("CAN Error: 0b"); itoa(can_error_info, str, 2); DEBUG_Print(str); DEBUG_Print("\r\n"); } if (send) { DEBUG_Print("Sending CAN with ID: 0x301\r\n"); msg_obj.msgobj = 2; msg_obj.mode_id = 0x301; msg_obj.dlc = 4; msg_obj.data[0] = tps_data>>2; msg_obj.data[1] = (uint8_t) 0x00; msg_obj.data[2] = (uint8_t) tps_error; LPC_CCAN_API->can_transmit(&msg_obj); Board_UART_PrintNum(msg_obj.data[0],10,true); Board_UART_PrintNum(msg_obj.data[1],10,true); Board_UART_PrintNum(msg_obj.data[2],10,true); } uint8_t count; count = Chip_UART_Read(LPC_USART, uart_rx_buf, UART_RX_BUFFER_SIZE); if (count != 0) { switch (uart_rx_buf[0]) { case 'a': send = true; break; case 'z': send = false; break; case 'r': DEBUG_Print("Sending CAN with ID: 0x301\r\n"); msg_obj.msgobj = 2; msg_obj.mode_id = 0x301; msg_obj.dlc = 2; msg_obj.data[0] = tps_data; msg_obj.data[1] = tps_error; LPC_CCAN_API->can_transmit(&msg_obj); Board_UART_PrintNum(msg_obj.data[0],10,true); Board_UART_PrintNum(msg_obj.data[1],10,true); break; default: DEBUG_Print("Invalid Command\r\n"); break; } } } }
/** * @brief Main UART program body * @return Always returns -1 */ int main(void) { FlagStatus exitflag; uint8_t buffer[10]; int ret = 0; int len; SystemCoreClockUpdate(); Board_Init(); Board_UART_Init(LPC_UART); #if !((defined(CHIP_LPC43XX) && defined(BOARD_KEIL_MCB_18574357) && UARTNum==3) || ((!(defined(CHIP_LPC43XX) && defined(BOARD_KEIL_MCB_18574357))) && UARTNum==0)) Chip_UART_Init(LPC_UART); Chip_UART_SetBaud(LPC_UART, 115200); Chip_UART_ConfigData(LPC_UART, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT); /* Default 8-N-1 */ /* Enable UART Transmit */ Chip_UART_TXEnable(LPC_UART); #endif /* Reset FIFOs, Enable FIFOs and DMA mode in UART */ Chip_UART_SetupFIFOS(LPC_UART, (UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS | UART_FCR_DMAMODE_SEL | UART_FCR_TRG_LEV0)); /* Enable UART End of Auto baudrate & Auto baudrate timeout interrupts */ Chip_UART_IntEnable(LPC_UART, (UART_IER_ABEOINT | UART_IER_ABTOINT)); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(UARTx_IRQn, 1); /* Enable Interrupt for UART0 channel */ NVIC_EnableIRQ(UARTx_IRQn); /* Send UART Autobaud completed message */ Chip_UART_SendBlocking(LPC_UART, uartABStart, sizeof(uartABStart)); /* ---------------------- Auto baud rate section ----------------------- */ /* Start auto baudrate mode */ Chip_UART_ABCmd(LPC_UART, UART_ACR_MODE0, true, ENABLE); /* Loop until auto baudrate mode complete */ while (Chip_UART_GetABEOStatus(LPC_UART) == RESET) {} /* Send UART Autobaud completed message */ Chip_UART_SendBlocking(LPC_UART, uartABComplete, sizeof(uartABComplete)); /* Disable UART Interrupt */ NVIC_DisableIRQ(UARTx_IRQn); /* Print welcome screen */ Print_Menu_Polling(); exitflag = RESET; /* Read some data from the buffer */ while (exitflag == RESET) { len = 0; while (len == 0) { len = Chip_UART_Read(LPC_UART, buffer, 1); } if (buffer[0] == 27) { /* ESC key, set exit flag */ Chip_UART_SendBlocking(LPC_UART, uartPolling_menu3, sizeof(uartPolling_menu3)); ret = -1; exitflag = SET; } else if (buffer[0] == 'c') { Chip_UART_SendBlocking(LPC_UART, uartPolling_menu4, sizeof(uartPolling_menu4)); len = 0; while (len == 0) { len = Chip_UART_Read(LPC_UART, buffer, sizeof(buffer)); if ((buffer[0] != '1') && (buffer[0] != '2') && (buffer[0] != '3')) { len = 0; } } switch (buffer[0]) { case '1': /* Polling Mode */ Chip_UART_SendBlocking(LPC_UART, uartPolling_menu5, sizeof(uartPolling_menu5)); break; case '2': /* Interrupt Mode */ ret = 2; /* Exitflag = SET; */ App_Interrupt_Test(); Print_Menu_Polling(); break; case '3': /* DMA mode */ ret = 3; App_DMA_Test(); Print_Menu_Polling(); break; } } } /* Wait for current transmission complete - THR must be empty */ while (Chip_UART_CheckBusy(LPC_UART) == SET) {} /* DeInitialize UART0 peripheral */ Chip_UART_DeInit(LPC_UART); return ret; }
/** * @brief Main UART program body * @return Always returns -1 */ int main(void) { FlagStatus exitflag; uint8_t buffer[10]; int ret = 0; uint32_t len; /* UART FIFO configuration Struct variable */ UART_FIFO_CFG_T UARTFIFOConfigStruct; /* Auto baudrate configuration structure */ UART_AB_CFG_T ABConfig; Board_Init(); Board_UART_Init(LPC_UART); //#if (UARTNum != 0) Chip_UART_Init(LPC_UART); Chip_UART_SetBaud(LPC_UART, 115200); Chip_UART_ConfigData(LPC_UART, UART_DATABIT_8, UART_PARITY_NONE, UART_STOPBIT_1); /* Default 8-N-1 */ /* Enable UART Transmit */ Chip_UART_TxCmd(LPC_UART, ENABLE); //#endif Chip_UART_Send(LPC_UART, "F**K OFF\n",10, BLOCKING); Chip_UART_FIFOConfigStructInit(LPC_UART, &UARTFIFOConfigStruct); /* Enable DMA mode in UART */ UARTFIFOConfigStruct.FIFO_DMAMode = ENABLE; /* Initialize FIFO for UART0 peripheral */ Chip_UART_FIFOConfig(LPC_UART, &UARTFIFOConfigStruct); /* Enable UART End of Auto baudrate interrupt */ Chip_UART_IntConfig(LPC_UART, UART_INTCFG_ABEO, ENABLE); /* Enable UART Auto baudrate timeout interrupt */ Chip_UART_IntConfig(LPC_UART, UART_INTCFG_ABTO, ENABLE); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(UARTx_IRQn, 1); /* Enable Interrupt for UART0 channel */ NVIC_EnableIRQ(UARTx_IRQn); // /* ---------------------- Auto baud rate section ----------------------- */ // /* Configure Auto baud rate mode */ // ABConfig.ABMode = UART_AUTOBAUD_MODE0; // ABConfig.AutoRestart = ENABLE; // // /* Start auto baudrate mode */ // Chip_UART_ABCmd(LPC_UART, &ABConfig, ENABLE); // // // /* Loop until auto baudrate mode complete */ // while (Chip_UART_GetABEOStatus(LPC_UART) == RESET) {} // // Chip_UART_Send(LPC_UART, uartABComplete, sizeof(uartABComplete), BLOCKING); /* Disable UART Interrupt */ NVIC_DisableIRQ(UARTx_IRQn); /* Print welcome screen */ Print_Menu_Polling(); exitflag = RESET; /* Read some data from the buffer */ while (exitflag == RESET) { len = 0; while (len == 0) { len = Chip_UART_Receive(LPC_UART, buffer, 1, NONE_BLOCKING); } if (buffer[0] == 27) { /* ESC key, set exit flag */ Chip_UART_Send(LPC_UART, uartPolling_menu3, sizeof(uartPolling_menu3), BLOCKING); ret = -1; exitflag = SET; } else if (buffer[0] == 'c') { Chip_UART_Send(LPC_UART, uartPolling_menu4, sizeof(uartPolling_menu4), BLOCKING); len = 0; while (len == 0) { len = Chip_UART_Receive(LPC_UART, buffer, sizeof(buffer), NONE_BLOCKING); if ((buffer[0] != '1') && (buffer[0] != '2') && (buffer[0] != '3')) { len = 0; } } switch (buffer[0]) { case '1': /* Polling Mode */ Chip_UART_Send(LPC_UART, uartPolling_menu5, sizeof(uartPolling_menu5), BLOCKING); break; case '2': /* Interrupt Mode */ ret = 2; /* Exitflag = SET; */ App_Interrupt_Test(); Print_Menu_Polling(); break; case '3': /* DMA mode */ ret = 3; App_DMA_Test(); Print_Menu_Polling(); break; } } } /* Wait for current transmission complete - THR must be empty */ while (Chip_UART_CheckBusy(LPC_UART) == SET) {} /* DeInitialize UART0 peripheral */ Chip_UART_DeInit(LPC_UART); return ret; }
/* Initialize debug output via UART for board */ void Board_Debug_Init(void) { #if defined(DEBUG_UART) Board_UART_Init(); #endif }
int main(void) { //--------------- // Initialize SysTick Timer to generate millisecond count if (Board_SysTick_Init()) { // Unrecoverable Error. Hang. while(1); } //--------------- // Initialize GPIO and LED as output Board_LEDs_Init(); Board_LED_On(LED0); Board_LED_On(LED1); Board_LED_On(LED2); Board_LED_On(LED3); //Initialize I2C Board_I2C_Init(); //--------------- // Initialize UART Communication Board_UART_Init(UART_BAUD_RATE); Board_UART_Println("Started up"); //--------------- // Initialize CAN and CAN Ring Buffer RingBuffer_Init(&can_rx_buffer, _rx_buffer, sizeof(CCAN_MSG_OBJ_T), BUFFER_SIZE); RingBuffer_Flush(&can_rx_buffer); Board_CAN_Init(CCAN_BAUD_RATE, CAN_rx, CAN_tx, CAN_error); // For your convenience. // typedef struct CCAN_MSG_OBJ { // uint32_t mode_id; // uint32_t mask; // uint8_t data[8]; // uint8_t dlc; // uint8_t msgobj; // } CCAN_MSG_OBJ_T; /* [Tutorial] How do filters work? Incoming ID & Mask == Mode_ID for msgobj to accept message Incoming ID : 0xabc Mask: 0xF0F & ----------- 0xa0c mode_id == 0xa0c for msgobj to accept message */ //Set mask to only accept messages from Driver Interface msg_obj.msgobj = 1; msg_obj.mode_id = DI_PACKET__id; msg_obj.mask = 0x555; LPC_CCAN_API->config_rxmsgobj(&msg_obj); can_error_flag = false; can_error_info = 0; lastPrint = msTicks; PDM_STATUS_T pdm_status; int tmp; bool lv_i2c = true, cs_i2c = true, mux_i2c = true; //Board_I2C_Reset(I2C_GG_CONTINUOUS, i2c_tx_buffer); //Open I2C Channel 0 i2c_tx_buffer[0] = I2C_MUX_CHANNEL_0; tmp = Chip_I2C_MasterSend(DEFAULT_I2C, I2C_MUX_SLAVE_ADDRESS, i2c_tx_buffer, 1); Board_UART_Print("Opened Channel 0: "); Board_UART_PrintNum(tmp, 10, true); //Set Gas Gauge 0 to continuous data collection i2c_tx_buffer[0] = I2C_GG_CTRL_REG; i2c_tx_buffer[1] = I2C_GG_CONTINUOUS; tmp = Chip_I2C_MasterSend(DEFAULT_I2C, I2C_GG_SLAVE_ADDRESS, i2c_tx_buffer, 2); Board_UART_Print("Set I2C0 to continuous data collection: "); Board_UART_PrintNum(tmp, 10, true); //Open I2C Channel 1 i2c_tx_buffer[0] = I2C_MUX_CHANNEL_1; tmp = Chip_I2C_MasterSend(DEFAULT_I2C, I2C_MUX_SLAVE_ADDRESS, i2c_tx_buffer, 1); Board_UART_Print("Opened Channel 1: "); Board_UART_PrintNum(tmp, 10, true); //Set Gas Gauge 1 to continuous data collection i2c_tx_buffer[0] = I2C_GG_CTRL_REG; i2c_tx_buffer[1] = I2C_GG_CONTINUOUS; tmp = Chip_I2C_MasterSend(DEFAULT_I2C, I2C_GG_SLAVE_ADDRESS, i2c_tx_buffer, 2); Board_UART_Print("Set I2C1 to continuous data collection: "); Board_UART_PrintNum(tmp, 10, true); while (1) { //Set PDM status based on CAN messages from Driver Interface if (!RingBuffer_IsEmpty(&can_rx_buffer)) { CCAN_MSG_OBJ_T temp_msg; RingBuffer_Pop(&can_rx_buffer, &temp_msg); //Test for DI OFF or SHUTDOWN IMPENDING message if((temp_msg.data[3] << 8 | temp_msg.data[2]) == ____DI_PACKET__DRIVE_STATUS__SHUTDOWN_IMPENDING || (temp_msg.data[3] << 8 | temp_msg.data[2]) == ____DI_PACKET__DRIVE_STATUS__OFF) { if(pdm_status.pdm_on) { pdm_status.pdm_on = false; Board_LED_Off(LED0); Board_I2C_Reset(I2C_GG_SLEEP, i2c_tx_buffer); } } else { if(!(pdm_status.pdm_on)) { pdm_status.pdm_on = true; Board_LED_On(LED0); Board_I2C_Reset(I2C_GG_CONTINUOUS, i2c_tx_buffer); } } } //Reset gas gauge 0 if it has been diconnected and then reconnected to power i2c_tx_buffer[0] = I2C_MUX_CHANNEL_0; tmp = Chip_I2C_MasterSend(DEFAULT_I2C, I2C_MUX_SLAVE_ADDRESS, i2c_tx_buffer, 1); //Open I2C Channel 0 tmp = Chip_I2C_MasterCmdRead(DEFAULT_I2C, I2C_GG_SLAVE_ADDRESS, I2C_GG_CTRL_REG, i2c_rx_buffer, 1); Board_UART_PrintNum(i2c_rx_buffer[0],16,true); if((uint16_t)i2c_rx_buffer[0] == I2C_GG_DEFAULT) { //Test for default values in control register if(pdm_status.pdm_on) { Board_I2C_Reset(I2C_GG_CONTINUOUS, i2c_tx_buffer); } else { Board_I2C_Reset(I2C_GG_SLEEP, i2c_tx_buffer); } //Send a heartbeat with a com error Board_CAN_SendHeartbeat(&pdm_status, &msg_obj, true); } //Reset gas gauge 1 if it has been diconnected and then reconnected to power i2c_tx_buffer[0] = I2C_MUX_CHANNEL_1; tmp = Chip_I2C_MasterSend(DEFAULT_I2C, I2C_MUX_SLAVE_ADDRESS, i2c_tx_buffer, 1); //Open 12C Channel 1 tmp = Chip_I2C_MasterCmdRead(DEFAULT_I2C, I2C_GG_SLAVE_ADDRESS, I2C_MUX_CHANNEL_0, i2c_rx_buffer, 1); Board_UART_PrintNum(i2c_rx_buffer[0],16,true); if((uint16_t)i2c_rx_buffer[0] == I2C_GG_DEFAULT) { //Test for default values in control register if(pdm_status.pdm_on) { Board_I2C_Reset(I2C_GG_CONTINUOUS, i2c_tx_buffer); } else { Board_I2C_Reset(I2C_GG_SLEEP, i2c_tx_buffer); } //Send a heartbeat with a com error Board_CAN_SendHeartbeat(&pdm_status, &msg_obj, true); } /* Update PDM and Debug LED code */ //Attempt to open I2C Channel 0 i2c_tx_buffer[0] = I2C_MUX_CHANNEL_0; mux_i2c = Chip_I2C_MasterSend(DEFAULT_I2C, I2C_MUX_SLAVE_ADDRESS, i2c_tx_buffer, 1); //Attempt to update Critical Systems PDM Struct cs_i2c = Board_PDM_Status_Update(&pdm_status, i2c_rx_buffer, true); //Attempt to open I2C Channel 1 i2c_tx_buffer[0] = I2C_MUX_CHANNEL_1; mux_i2c = Chip_I2C_MasterSend(DEFAULT_I2C, I2C_MUX_SLAVE_ADDRESS, i2c_tx_buffer, 1); //Attempt to update Low Voltage PDM struct lv_i2c = Board_PDM_Status_Update(&pdm_status, i2c_rx_buffer, false); //Run debug logic and update state Board_PDM_Status_Debug(&pdm_status, mux_i2c, cs_i2c, lv_i2c); if(msTicks - lastPrint > FREQ_THRESHOLD){ // 10 times per second lastPrint = msTicks; // Store the current time, to allow the process to be done in another 1/10 seconds Board_CAN_SendHeartbeat(&pdm_status, &msg_obj, false); } } }