-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
BMS and PDS currently share a lot of initialization code. Some examples are
line 390 BMS/BMS.c and line 70 PDS_App/AppComm.c
static uint16_t SendTelemetryResponse(uint8_t request)
{
uint8_t bytes[TINYPROTOCOL_MAX_PACKET_SIZE];
uint8_t count = 0;
uint8_t* pbyte = bytes;
while(TINYPROTOCOL_TelemetryBytesLeft() > 0) {
int16_t result = TINYPROTOCOL_ReadNextTelemetryByte(pbyte);
volatile uint8_t byte = *pbyte;
if (result == ETINYPROTOCOL_SUCCESS) {
pbyte++;
count++;
} else {
return result;
}
}
transmitI2C(bytes, count);
return ETINYPROTOCOL_SUCCESS;
} // Initialize clock to 16MHz
// Uses direct register manipulation as per device datasheet
static void initClockTo16MHz()
{
// Configure one FRAM waitstate as required by the device datasheet for MCLK
// operation beyond 8MHz _before_ configuring the clock system.
FRCTL0 = FRCTLPW | NWAITS_1;
// Clock System Setup
CSCTL0_H = CSKEY_H; // Unlock CS registers
CSCTL1 = DCOFSEL_0; // Set DCO to 1MHz
// Set SMCLK = MCLK = DCO, ACLK = LFXTCLK (VLOCLK if unavailable)
CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
// Per Device Errata set divider to 4 before changing frequency to
// prevent out of spec operation from overshoot transient
CSCTL3 = DIVA__4 | DIVS__4 | DIVM__4; // Set all corresponding clk sources to divide by 4 for errata
CSCTL1 = DCOFSEL_4 | DCORSEL; // Set DCO to 16MHz
// Delay by ~10us to let DCO settle. 60 cycles = 20 cycles buffer + (10us / (1/4MHz))
__delay_cycles(60);
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers to 1 for 16MHz operation
CSCTL0_H = 0; // Lock CS registers
}And others the RTC initialization could be refactored as well