Skip to content

Commit

Permalink
Fixes Issue 3
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Feb 12, 2023
1 parent c9c519e commit 08d10d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 64 deletions.
18 changes: 4 additions & 14 deletions c-examples/com-monolithic/com_monolithic.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// TAB C Example COM Monolithic
//
// Written by Bradley Denby
// Other contributors: None
// Other contributors: Abhishek Anand
//
// See the top-level LICENSE file for the license.

Expand All @@ -18,20 +18,10 @@

// Main
int main(void) {
// MCU initialization

// Clock initialization
init_clock();
init_uart();
// TAB initialization
rx_cmd_buff_t rx_cmd_buff = {.size=CMD_MAX_LEN};
clear_rx_cmd_buff(&rx_cmd_buff);
tx_cmd_buff_t tx_cmd_buff = {.size=CMD_MAX_LEN};
clear_tx_cmd_buff(&tx_cmd_buff);
// TAB loop
while(1) {
rx_usart1(&rx_cmd_buff); // Collect command bytes
reply(&rx_cmd_buff, &tx_cmd_buff); // Command reply logic
tx_usart1(&tx_cmd_buff); // Send a response if any
}

// Should never reach this point
return 0;
}
47 changes: 6 additions & 41 deletions c-examples/com-monolithic/support/com.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
// COM board support implementation file
//
// Written by Bradley Denby
// Other contributors: None
// Other contributors: Abhishek Anand
//
// See the top-level LICENSE file for the license.

// Standard library headers
#include <stdint.h> // uint8_t

// libopencm3 library
//#include <libopencm3/stm32/flash.h> // used in init_clock
//#include <libopencm3/stm32/gpio.h> // used in init_gpio
//#include <libopencm3/stm32/rcc.h> // used in init_clock, init_rtc
//#include <libopencm3/stm32/usart.h> // used in init_uart
#include <libopencm3/nrf/51/clock.h>

// Board-specific header
#include <com.h> // COM header
Expand All @@ -38,40 +35,8 @@ int handle_common_data(common_data_t common_data_buff_i) {
// Board initialization functions

void init_clock(void) {
// TODO
}

void init_uart(void) {
// TODO
}

clock_set_xtal_freq(CLOCK_XTAL_FREQ_16MHZ);
clock_start_lfclk (true);

// Feature functions

void rx_usart1(rx_cmd_buff_t* rx_cmd_buff_o) {
/*while( // while
usart_get_flag(USART1,USART_ISR_RXNE) && // USART1 RX not empty AND
rx_cmd_buff_o->state!=RX_CMD_BUFF_STATE_COMPLETE // Command not complete
) { //
uint8_t b = usart_recv(USART1); // Receive byte from RX pin
push_rx_cmd_buff(rx_cmd_buff_o, b); // Push byte to buffer
}*/ //
}

void reply(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o) {
/*if( // if
rx_cmd_buff_o->state==RX_CMD_BUFF_STATE_COMPLETE && // rx_cmd is valid AND
tx_cmd_buff_o->empty // tx_cmd is empty
) { //
write_reply(rx_cmd_buff_o, tx_cmd_buff_o); // execute cmd and reply
}*/ //
}

void tx_usart1(tx_cmd_buff_t* tx_cmd_buff_o) {
/*while( // while
usart_get_flag(USART1,USART_ISR_TXE) && // USART1 TX empty AND
!(tx_cmd_buff_o->empty) // TX buffer not empty
) { //
uint8_t b = pop_tx_cmd_buff(tx_cmd_buff_o); // Pop byte from TX buffer
usart_send(USART1,b); // Send byte to TX pin
}*/ //
}
}
11 changes: 2 additions & 9 deletions c-examples/com-monolithic/support/com.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,21 @@
// COM board support header file
//
// Written by Bradley Denby
// Other contributors: None
// Other contributors: Abhishek Anand
//
// See the top-level LICENSE file for the license.

#ifndef COM_H
#define COM_H

// TAB header
#include <tab.h> // rx_cmd_buff_t, tx_cmd_buff_t, common_data_t
#include <tab.h>

// Functions required by TAB
int handle_common_data(common_data_t common_data_buff_i);

// Board initialization functions

void init_clock(void);
void init_uart(void);

// Feature functions

void rx_usart1(rx_cmd_buff_t* rx_cmd_buff_o);
void reply(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o);
void tx_usart1(tx_cmd_buff_t* tx_cmd_buff_o);

#endif

0 comments on commit 08d10d6

Please sign in to comment.