summaryrefslogtreecommitdiff
path: root/gm_platform
diff options
context:
space:
mode:
Diffstat (limited to 'gm_platform')
-rw-r--r--gm_platform/fw/global.h9
-rw-r--r--gm_platform/fw/main.c39
-rw-r--r--gm_platform/fw/serial.c3
3 files changed, 24 insertions, 27 deletions
diff --git a/gm_platform/fw/global.h b/gm_platform/fw/global.h
index 7d33ca6..9c454bc 100644
--- a/gm_platform/fw/global.h
+++ b/gm_platform/fw/global.h
@@ -49,4 +49,13 @@ extern volatile unsigned int sys_time_seconds;
#define UNUSED(var) ((void)var)
+union leds {
+ struct {
+ unsigned int pps, sd_card, usb, ocxo, error, _nc1, _nc2, _nc3;
+ };
+ unsigned int arr[8];
+};
+
+extern volatile union leds leds;
+
#endif/*__GLOBAL_H__*/
diff --git a/gm_platform/fw/main.c b/gm_platform/fw/main.c
index 5741d7c..74f305b 100644
--- a/gm_platform/fw/main.c
+++ b/gm_platform/fw/main.c
@@ -21,17 +21,7 @@
volatile unsigned int sys_time_seconds = 0;
-
-void update_leds() {
-
-}
-
-volatile union {
- struct {
- unsigned int usb, ocxo, error, _nc1, _nc2, _nc3, pps, sd_card;
- };
- unsigned int arr[8];
-} leds;
+volatile union leds leds;
int main(void) {
RCC->CR |= RCC_CR_HSEON;
@@ -79,22 +69,23 @@ int main(void) {
SPI1->CR1 =
SPI_CR1_SSM
| SPI_CR1_SSI
+ | SPI_CR1_CPOL
+ | SPI_CR1_CPHA
| (4<<SPI_CR1_BR_Pos) /* /32 ~1.5MHz */
| SPI_CR1_MSTR;
SPI1->CR2 = (7<<SPI_CR2_DS_Pos);
SPI1->CR1 |= SPI_CR1_SPE;
- NVIC_EnableIRQ(SPI1_IRQn);
- NVIC_SetPriority(SPI1_IRQn, 2<<5);
-
TIM16->CR2 = 0;
- TIM16->DIER = TIM_DIER_UIE;
+ TIM16->DIER = TIM_DIER_UIE | TIM_DIER_CC1IE;
+ TIM16->CCMR1 = 0;
+ TIM16->CCR1 = 32;
TIM16->PSC = 48-1; /* 1us */
TIM16->ARR = 1000-1; /* 1ms */
TIM16->CR1 = TIM_CR1_CEN;
NVIC_EnableIRQ(TIM16_IRQn);
- NVIC_SetPriority(TIM16_IRQn, 2<<5);
+ NVIC_SetPriority(TIM16_IRQn, 3<<5);
adc_configure_scope_mode(1000000);
@@ -108,21 +99,13 @@ int main(void) {
}
}
-void SPI1_IRQHandler(void) {
- if (SPI1->SR & SPI_SR_TXE) {
- /* LED_STB */
- GPIOA->BSRR = 1<<3;
- SPI1->CR2 &= ~SPI_CR2_TXEIE;
- }
-}
-
void TIM16_IRQHandler(void) {
static int leds_update_counter = 0;
if (TIM16->SR & TIM_SR_UIF) {
TIM16->SR &= ~TIM_SR_UIF;
uint8_t bits = 0, mask = 1;
- for (size_t i=0; i<sizeof(leds)/sizeof(leds.arr[0]); i++) {
+ for (int i=0; i<8; i++) {
if (leds.arr[i]) {
leds.arr[i]--;
bits |= mask;
@@ -137,9 +120,11 @@ void TIM16_IRQHandler(void) {
* data register is accessed through a 16-bit write. Unfortunately, the STMCube register defs define DR as an
* uint16_t, so we have to do some magic here to force an 8-bit write. */
*((volatile uint8_t*)&(SPI1->DR)) = bits;
- SPI1->CR2 |= SPI_CR2_TXEIE;
GPIOA->BRR = 1<<3;
}
+ } else {
+ TIM16->SR &= ~TIM_SR_CC1IF;
+ GPIOA->BSRR = 1<<3;
}
}
@@ -166,7 +151,7 @@ void SysTick_Handler(void) {
if (n++ == 10) {
n = 0;
sys_time_seconds++;
- leds.pps = 100; /* ms */
+ leds.pps = 200; /* ms */
}
}
diff --git a/gm_platform/fw/serial.c b/gm_platform/fw/serial.c
index 2c80674..6b3ba00 100644
--- a/gm_platform/fw/serial.c
+++ b/gm_platform/fw/serial.c
@@ -206,6 +206,7 @@ void usart_schedule_dma() {
xfr_len = sizeof(buf->data) - xfr_start;
}
+ leds.error = 250;
}
buf->xfr_start = xfr_start;
@@ -264,6 +265,8 @@ int usart_send_packet_nonblocking(struct ll_pkt *pkt, size_t pkt_len) {
usart_tx_buf.packet_end[usart_tx_buf.wr_idx] = usart_tx_buf.wr_pos;
usart_tx_buf.wr_idx = (usart_tx_buf.wr_idx + 1) % ARRAY_LEN(usart_tx_buf.packet_end);
+ leds.usb = 100;
+
if (!(DMA1_Channel2->CCR & DMA_CCR_EN))
usart_schedule_dma();
return 0;