Skip to content

Commit

Permalink
Merge pull request #10 from PDXostc/Develop
Browse files Browse the repository at this point in the history
Update master to current release state
  • Loading branch information
smiller6 authored Jul 11, 2017
2 parents 087b3a9 + 96ff40b commit 5adf776
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 536 deletions.
157 changes: 1 addition & 156 deletions V2X_Firmware/src/V2X/V2X_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ extern "C" {
#define V2X_REV (REV_20)

/** Name string macro */
#if V2X_REV == REV_12
#define BOARD_NAME "RVI_V2X_Version_1.2"
#elif V2X_REV >= REV_20
/* REV20: board name change */
#define BOARD_NAME "RVI_V2X_Version_2.0"
#endif
#define BOARD_NAME "RVI_V2X_Version_2.0"
/** @} */

/* Defines for SIMCOM GSM chip on board. Compile time choice.
Expand All @@ -51,44 +47,30 @@ extern "C" {
/** \name 3v3 power pin definition
* Activate to maintain power to CPU
*/
#if V2X_REV >= REV_20
#define PWR_3V3_PIN IOPORT_CREATE_PIN(PORTA,4)
#define PWR_3V3_ACTIVE true
#define PWR_3V3_INACTIVE !PWR_3V3_ACTIVE
#endif

/** \name LED0 definitions
* net: SEQ_LED3 or "PWR" LED
* @{ */
#if V2X_REV <= REV_12
#define LED0_PIN IOPORT_CREATE_PIN(PORTB,0)
#elif V2X_REV >= REV_20
#define LED0_PIN IOPORT_CREATE_PIN(PORTE,2)
#endif
#define LED0_ACTIVE true
#define LED0_INACTIVE !LED0_ACTIVE
/** @} */

/** \name LED1 definitions
* net: SEQ_LED1 or "M2M" LED
* @{ */
#if V2X_REV <= REV_12
#define LED1_PIN IOPORT_CREATE_PIN(PORTA,6)
#elif V2X_REV >= REV_20
#define LED1_PIN IOPORT_CREATE_PIN(PORTE,1)
#endif
#define LED1_ACTIVE true
#define LED1_INACTIVE !LED0_ACTIVE
/** @} */

/** \name LED2 definitions
* net: SEQ_LED2 or "GPS" LED
* @{ */
#if V2X_REV <= REV_12
#define LED2_PIN IOPORT_CREATE_PIN(PORTA,7)
#elif V2X_REV >= REV_20
#define LED2_PIN IOPORT_CREATE_PIN(PORTE,3)
#endif
#define LED2_ACTIVE true
#define LED2_INACTIVE !LED0_ACTIVE
/** @} */
Expand Down Expand Up @@ -177,99 +159,18 @@ extern "C" {

#define BUTTON_COUNT 2


#if V2X_REV == REV_12
/* DELETEME: Quite possibly, the whole buffer switcheroo is not needed anymore,
* can probably eliminate the whole buffer setup
* */
/**
* \name Serial Buffer #0 definitions
*
* Makes Atmel active communicator with ELM/STN device
*
* @{ */
#define BUF_0_NAME "Buffer SEQ Active"
#define BUF_0_PIN BUF0_PIN
#define BUF_0_ACTIVE BUF0_ACTIVE
#define BUF_0_INACTIVE BUF0_INACTIVE
/** @} */

/** \name BUF0 definitions
* @{ */
#define BUF0_PIN IOPORT_CREATE_PIN(PORTB,2)
#define BUF0_ACTIVE true
#define BUF0_INACTIVE !BUF0_ACTIVE
/** @} */

/* Revision 1.2 uses FTDI chip for primary routing. Control must be selected
* specifically by either the FDTI or the Atmel. Revision 2.0 removes the FDTI
* chip.
*/
/**
* \name Serial Buffer #1 definitions
*
* Makes FTDI active communicator with ELM/STN device
*
* @{ */
#define BUF_1_NAME "Buffer FTDI Active"
#define BUF_1_PIN BUF1_PIN
#define BUF_1_ACTIVE BUF1_ACTIVE
#define BUF_1_INACTIVE BUF1_INACTIVE
/** @} */

/** \name BUF1 definitions
* @{ */
#define BUF1_PIN IOPORT_CREATE_PIN(PORTB,3)
#define BUF1_ACTIVE true
#define BUF1_INACTIVE !BUF1_ACTIVE
/** @} */

/** Number of on-board buttons */
/* DELETEME: this can probably just be eliminated */
#define BUFFER_COUNT 2
#define BUFFER_COUNT 1
#endif

/** \name CP0 definitions
* @{ */
#define CP0_PIN IOPORT_CREATE_PIN(PORTA,1)
#define CP0_ACTIVE true
#define CP0_INACTIVE !CP0_ACTIVE
/** @} */

#if V2X_REV <= REV_12
/**
* \name Charge Pump #0 definitions
*
* LED power supply charge pump pin
* must be toggled >10khz to activate blue LED
*
* @{ */
#define CHARGEPUMP_0_NAME "Charge Pump"
#define CHARGEPUMP_0_PIN CP0_PIN
#define CHARGEPUMP_0_ACTIVE CP0_ACTIVE
#define CHARGEPUMP_0_INACTIVE CP0_INACTIVE
/** @} */

/** Number of on-board buttons */
#define CHARGEPUMP_COUNT 1
#endif

/** \name Signal pin definitions
* @{
*/
#if V2X_REV <= REV_12
#define EXT1_PIN_ACL_INT2 IOPORT_CREATE_PIN(PORTA,2)
#define EXT1_PIN_ACL_INT1 IOPORT_CREATE_PIN(PORTA,3)
#elif V2X_REV >= REV_20
#define EXT1_PIN_ACL_INT2 IOPORT_CREATE_PIN(PORTA,1)
#define EXT1_PIN_ACL_INT1 IOPORT_CREATE_PIN(PORTA,2)
#endif
#if V2X_REV <= REV_12
#define EXT1_PIN_HUB_STATUS IOPORT_CREATE_PIN(PORTA,4)
#define EXT1_PIN_HUB_SUSPEND IOPORT_CREATE_PIN(PORTA,5)
/* DELETEME: HUB_STATUS unnecessary without FTDI in the mix */
#endif
#define EXT1_PIN_HUB_STATUS IOPORT_CREATE_PIN(PORTA,3)
#define EXT1_PIN_HOST_SHORT_CIRCUIT IOPORT_CREATE_PIN(PORTB,1)
#define EXT1_PIN_SR_CLEAR IOPORT_CREATE_PIN(PORTC,0)
Expand All @@ -280,14 +181,6 @@ extern "C" {
#define EXT1_PIN_SPI_MOSI IOPORT_CREATE_PIN(PORTC,5)
#define EXT1_PIN_SPI_MISO IOPORT_CREATE_PIN(PORTC,6)
#define EXT1_PIN_SPI_SCK IOPORT_CREATE_PIN(PORTC,7)
#if V2X_REV <= REV_12
#define EXT1_PIN_HUB_SDA IOPORT_CREATE_PIN(PORTE,0)
#define EXT1_PIN_HUB_SCL IOPORT_CREATE_PIN(PORTE,1)
#endif
#if V2X_REV <= REV_12
#define EXT1_PIN_ACL_RXD IOPORT_CREATE_PIN(PORTE,2) //RX SIGNAL (PORT E RXD0) FROM SEQ TO FTDI FOR ACCEL AT INTERFACE
#define EXT1_PIN_ACL_TXD IOPORT_CREATE_PIN(PORTE,3) //TX SIGNAL (PORT E TXD0) FROM SEQ TO FTDI FOR ACCEL AT INTERFACE
#endif
#define EXT1_PIN_SIM_WAKE IOPORT_CREATE_PIN(PORTD,0)
#define EXT1_PIN_SIM_NETWORK IOPORT_CREATE_PIN(PORTD,1)
#define EXT1_PIN_SIM_TXD IOPORT_CREATE_PIN(PORTE,2) //TX SIGNAL (PORT D RXD0) FROM SIM MODULE
Expand All @@ -314,30 +207,6 @@ extern "C" {
#define TWI_DATA_LENGTH 8
/** @} */

#if V2X_REV <= REV_12
/*DELETEME: These are likely superfluous */
/** \name Extension header #1 USART definitions
* @{
*/
#define EXT1_CAN_USART &USARTC0
#define EXT1_SIM_USART &USARTD0
#define EXT1_SEQ_USART &USARTD1
#define EXT1_ACL_USART &USARTE0
/** @} */

/*DELETEME: Doubly superfluous */
/** \name Extension header #1 SPI definitions
* @{
*/
#define EXT1_SPI_MODULE &SPIC

/** @} */
/** \name Extension header #2 SPI definitions
* @{
*/
#define EXT1_SPI_MODULE &SPIC
#endif

/** @} */

/*! \name SPI Connections of external ADXL345 Accelerometer
Expand All @@ -362,29 +231,6 @@ extern "C" {
* This is used for power and reset sequencing
*
*/
#if V2X_REV <= REV_12
/* Revision 1.2 features two shift registers, accommodating a 16 bit field for
* the following power signals. Note: order is relevant!
*/
enum power_sequence_outputs {
ENABLE_3V3 = 0,
ENABLE_3V3B ,
ENABLE_3V3C ,
ENABLE_3V3D ,
ENABLE_4V1 ,
ENABLE_5V0 ,
ENABLE_5V0B ,
ENABLE_SIM_WAKE ,
ENABLE_HUB ,
ENABLE_CAN_SLEEP ,
ENABLE_CAN_RESET ,
ENABLE_SIM_PWR_ON ,
ENABLE_SIM_RESET ,
ENABLE_SIM_RF_OFF ,
ENABLE_SIM_VBUS ,
ENABLE_FTDI_RESET
};
#elif V2X_REV >= REV_20
/* Revision 2.0 uses only a single shift register, accommodating an 8 bit field
* for the following power signals. Note: order is relevant!
*/
Expand All @@ -398,7 +244,6 @@ enum power_sequence_outputs {
, ENABLE_SIM_RESET
, ENABLE_SIM_WAKE
};
#endif

#define SR_SPI &SPIC
//! @}
Expand Down
26 changes: 5 additions & 21 deletions V2X_Firmware/src/V2X/V2X_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void button_service(void) {
menu_send_BTN();
usb_tx_string_P(PSTR("RELEASE:")); // report to CMD interface
menu_print_int(button_delta);
usb_tx_string_P(PSTR("\r\n")); // report to CMD interface
menu_send_n_st();
button_pressed = false; //note the button was released
button_check_flag = true; //flag button for checking
Expand All @@ -43,7 +44,7 @@ void button_service(void) {
pressed_at = time_get(); //store press time
button_pressed = true; //hold button state
menu_send_BTN();
usb_tx_string_P(PSTR("PRESS")); //report press event to CMD
usb_tx_string_P(PSTR("PRESS\r\n")); //report press event to CMD
menu_send_n_st();
break;
}
Expand All @@ -69,39 +70,22 @@ void button_reset_delta(void)
button_delta = 0;
}

#if V2X_REV >= REV_20
void handle_button_check(int sec) {
if (sec >= 5)
{
// do hard power off
usb_tx_string_P(PSTR("Power Off"));
usb_tx_string_P(PSTR("Power Off\r\n"));
PWR_host_stop();
PWR_can_stop();
PWR_gsm_stop();
ACL_set_sample_off();
PWR_shutdown();
} else if (sec >= 3)
{
usb_tx_string_P(PSTR("Power 3v Only"));
// do 3v only
PWR_host_stop();
PWR_5_stop();
ACL_set_sample_off();
PWR_4_stop();
// maybe we'd like to force the leds to update here, just in case...
led_1_off();
led_2_off();
PWR_mode_low();
} else if (sec >= 1)
{
// full power mode
PWR_4_start();
usb_tx_string_P(PSTR("Power Full"));
udd_attach();
ACL_set_sample_on();
GSM_modem_init();
CAN_elm_init();
PWR_host_start();
PWR_mode_high();
}
button_reset_delta();
}
#endif
12 changes: 6 additions & 6 deletions V2X_Firmware/src/V2X/V2X_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void CAN_control_init (char * responce_buffer){
CAN_subsequence_state = CAN_subssequence_2;
CAN_control(responce_buffer);
} else { //if not power it up
usb_tx_string_P(PSTR(">CTL>>>:Power up CAN\r")); //does not need end of string, exits through menu
usb_tx_string_P(PSTR(">CTL>>>:Power up CAN\r\n")); //does not need end of string, exits through menu
PWR_can_start();
CAN_subsequence_state = CAN_subssequence_4;
job_set_timeout(SYS_CAN, 4); //give elm module 3 seconds to start
Expand All @@ -183,12 +183,12 @@ void CAN_control_init (char * responce_buffer){
if (strcmp_P(responce_buffer, PSTR("LV RESET")) == 0) {
CAN_subsequence_state = CAN_subssequence_3;
menu_send_CTL();
usb_tx_string_P(PSTR("CAN Powered\r>"));
usb_tx_string_P(PSTR("CAN Powered\r\n>"));
CAN_control(responce_buffer);
}
if (strcmp_P(responce_buffer, PSTR("ELM327 v1.3a")) == 0) {
menu_send_CTL();
usb_tx_string_P(PSTR("CAN Responding\r>"));
usb_tx_string_P(PSTR("CAN Responding\r\n>"));
CAN_sequence_state = CAN_state_idle;
CAN_in_command = false;
job_clear_timeout(SYS_CAN);
Expand All @@ -201,7 +201,7 @@ void CAN_control_init (char * responce_buffer){
CAN_in_command = false;
job_clear_timeout(SYS_CAN);
menu_send_CTL();
usb_tx_string_P(PSTR("CAN start fail\r>"));
usb_tx_string_P(PSTR("CAN start fail\r\n>"));
break;
}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ void CAN_ee_sequence (char * responce_buffer) {
CAN_sequence_state = CAN_state_idle;
job_clear_timeout(SYS_CAN);
menu_send_CAN();
usb_tx_string_P(PSTR("ERROR: EEPROM sequence fail\r>"));
usb_tx_string_P(PSTR("ERROR: EEPROM sequence fail\r\n>"));
} else if (CAN_subsequence_state != 0) { //not the first state, responce_buffer should have responce
if (strcmp_P(responce_buffer, PSTR("OK")) == 0) { //if responce was OK
eeprom_read_CAN_string(buffer); //get copy of the entire string
Expand All @@ -261,7 +261,7 @@ void CAN_ee_sequence (char * responce_buffer) {
CAN_sequence_state = CAN_state_idle;
job_clear_timeout(SYS_CAN);
menu_send_CAN();
usb_tx_string_P(PSTR("EEPROM sequence complete\r>"));
usb_tx_string_P(PSTR("EEPROM sequence complete\r\n>"));
}
} else { //the response was bad
CAN_subsequence_state == CAN_subssequence_FAIL;
Expand Down
4 changes: 1 addition & 3 deletions V2X_Firmware/src/V2X/V2X_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,11 @@ void job_coordinator (void) {
if (job_check_timeout(SYS_CAN_CTL)) {
CAN_stop_snoop();
}
#if V2X_REV >= REV_20
if (job_check_timeout(SYS_PWR))
{
handle_button_check(button_get_delta());
job_clear_timeout(SYS_PWR);
}
#endif
//more jobs to add
//compare GPS coordinates to trigger alarm/host
//compare ACL data to trigger alarm/host
Expand Down Expand Up @@ -206,7 +204,7 @@ void job_check_fail(uint8_t system) {
menu_send_CAN();
break;
}
usb_tx_string_P(PSTR("Control timeout\r>"));
usb_tx_string_P(PSTR("Control timeout\r\n>"));
job_set_timeout(system, 1);
}
}
Expand Down
Loading

0 comments on commit 5adf776

Please sign in to comment.