You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					61 lines
				
				1.9 KiB
			
		
		
			
		
	
	
					61 lines
				
				1.9 KiB
			| 
								 
											6 years ago
										 
									 | 
							
								// WARNING: To stay in compliance with the SIL2 rules laid out in STM UM1840, we should never implement any of the available hardware low power modes.
							 | 
						||
| 
								 | 
							
								// See rule: CoU_3
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								#define POWER_SAVE_STATUS_DISABLED 0
							 | 
						||
| 
								 | 
							
								#define POWER_SAVE_STATUS_ENABLED 1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int power_save_status = POWER_SAVE_STATUS_DISABLED;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void set_power_save_state(int state) {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  bool is_valid_state = (state == POWER_SAVE_STATUS_ENABLED) || (state == POWER_SAVE_STATUS_DISABLED);
							 | 
						||
| 
								 | 
							
								  if (is_valid_state && (state != power_save_status)) {
							 | 
						||
| 
								 | 
							
								    bool enable = false;
							 | 
						||
| 
								 | 
							
								    if (state == POWER_SAVE_STATUS_ENABLED) {
							 | 
						||
| 
								 | 
							
								      puts("enable power savings\n");
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      if (board_has_gps()) {
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								        char UBLOX_SLEEP_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x08\x00\x17\x78";
							 | 
						||
| 
								 | 
							
								        uart_ring *ur = get_ring_by_number(1);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								        for (unsigned int i = 0; i < sizeof(UBLOX_SLEEP_MSG) - 1U; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i]));
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      }
							 | 
						||
| 
								 | 
							
								    } else {
							 | 
						||
| 
								 | 
							
								      puts("disable power savings\n");
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      if (board_has_gps()) {
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								        char UBLOX_WAKE_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x09\x00\x18\x7a";
							 | 
						||
| 
								 | 
							
								        uart_ring *ur = get_ring_by_number(1);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								        for (unsigned int i = 0; i < sizeof(UBLOX_WAKE_MSG) - 1U; i++) while (!putc(ur, UBLOX_WAKE_MSG[i]));
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      }
							 | 
						||
| 
								 | 
							
								      enable = true;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    current_board->enable_can_transcievers(enable);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    // Switch EPS/GPS
							 | 
						||
| 
								 | 
							
								    if (enable) {
							 | 
						||
| 
								 | 
							
								      current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
							 | 
						||
| 
								 | 
							
								    } else {
							 | 
						||
| 
								 | 
							
								      current_board->set_esp_gps_mode(ESP_GPS_DISABLED);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								    if(board_has_gmlan()){
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      // turn on GMLAN
							 | 
						||
| 
								 | 
							
								      set_gpio_output(GPIOB, 14, enable);
							 | 
						||
| 
								 | 
							
								      set_gpio_output(GPIOB, 15, enable);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    if(board_has_lin()){
							 | 
						||
| 
								 | 
							
								      // turn on LIN
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      set_gpio_output(GPIOB, 7, enable);
							 | 
						||
| 
								 | 
							
								      set_gpio_output(GPIOA, 14, enable);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    // Switch off IR and fan when in power saving
							 | 
						||
| 
								 | 
							
								    if(!enable){
							 | 
						||
| 
								 | 
							
								      current_board->set_ir_power(0U);
							 | 
						||
| 
								 | 
							
								      current_board->set_fan_power(0U);
							 | 
						||
| 
								 | 
							
								    }   
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    power_save_status = state;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 |