Skip to content

Commit

Permalink
WIP #2
Browse files Browse the repository at this point in the history
  • Loading branch information
lromeraj committed May 31, 2023
1 parent 416405b commit 044b61e
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/at_uart/at_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ at_uart_err_t at_uart_pack_txt_resp(
buf[ buf_li ] = '\0';
}
}

return at_code;
}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ inline at_uart_err_t at_uart_skip_txt_resp(
at_uart_err_t at_uart_write(
at_uart_t *at_uart, const uint8_t *src_buf, uint16_t n_bytes, uint32_t timeout_ms
) {

uint16_t bytes_written = zuart_write(
&at_uart->zuart, src_buf, n_bytes, timeout_ms );

Expand Down
3 changes: 2 additions & 1 deletion lib/iridium/isbd/isbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ void _entry_point( void *v1, void *v2, void *v3 ) {
};

isu_dte_err_t dte_err;


dte_err = isu_set_evt_report(
ISBD_DTE, &evt_report, &g_isbd.sigq, &g_isbd.svca );
Expand All @@ -251,7 +252,7 @@ void _entry_point( void *v1, void *v2, void *v3 ) {
DO_FOREVER {

struct isbd_mo_msg mo_msg;

// sessions will be sent only if the service is currently available
if ( g_isbd.svca && g_isbd.sigq >= g_isbd.cnf.sigq_threshold ) {
if ( k_msgq_get( ISBD_MO_Q, &mo_msg, K_NO_WAIT ) == 0 ) {
Expand Down
33 changes: 28 additions & 5 deletions lib/zuart/zuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ uint16_t zuart_read_poll_proto( zuart_t *zuart, uint8_t *out_buf, uint16_t n_byt
uint8_t byte;
uint16_t total_bytes_read = 0;


if ( timeout_ms == 0 ) {

while ( total_bytes_read < n_bytes
Expand All @@ -106,16 +105,37 @@ uint16_t zuart_read_poll_proto( zuart_t *zuart, uint8_t *out_buf, uint16_t n_byt
zuart->err = ZUART_ERR_TIMEOUT;
break;
}

int ret = uart_poll_in( zuart->dev, &byte );

int ret = uart_poll_in( zuart->dev, &byte );

if ( ret == 0 ) {

if ( out_buf ) {
out_buf[ total_bytes_read ] = byte;
}
total_bytes_read++;

} else if ( ret == -1 ) {

// ! When using polling mode, uart_poll_in() is
// ! non blocking and returns -1 when there are no bytes
// ! available, so in such situation (current code block)
// ! we call k_yield() in order to jump to another threads, but
// ! the problem appears when the thread which calls this function
// ! has a higher priority than other threads (for example, the logging thread)
// ! so after calling k_yield() the kernel immediately resumes this thread
// ! so it does not allow other threads with lower priority to be executed
// !
// ! With this, I want to say that it is very important to configure priorities
// ! correctly in order to avoid such situations, whenever possible use interrupt
// ! mode instead
k_yield();

// ! Another option could consist by adding a little sleep in order to avoid the kernel
// ! to return immediately to the calling thread, but in that case data loss may occur
// ! more easily
// k_msleep( 100 );

} else {
zuart->err = ZUART_ERR;
break;
Expand Down Expand Up @@ -183,15 +203,18 @@ uint16_t zuart_write_poll_proto(
) {

uint16_t bytes_written = 0;
uint64_t ts_old = k_uptime_get();

// uint64_t ts_old = k_uptime_get();

while ( bytes_written < n_bytes ) {

uint64_t ts_now = k_uptime_get();
// uint64_t ts_now = k_uptime_get();

/*
if ( timeout_ms > 0 && ts_now - ts_old >= timeout_ms ) {
return ZUART_ERR_TIMEOUT;
}
*/

uint8_t byte = src_buf[ bytes_written ];

Expand Down
2 changes: 0 additions & 2 deletions samples/isbd_app/dbg.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ CONFIG_SERIAL=y
CONFIG_LOG=y
CONFIG_LOG_MAX_LEVEL=4
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_LOG_BACKEND_SHOW_COLOR=y
CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP=n
8 changes: 7 additions & 1 deletion samples/isbd_app/prj.conf
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
CONFIG_PRINTK=y
CONFIG_IRIDIUM=y
CONFIG_ISBD_THREAD_STACK_SIZE=4096

# Cooperative thread
CONFIG_MAIN_THREAD_PRIORITY=0
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_NEWLIB_LIBC=y
CONFIG_QEMU_ICOUNT=n

# Logging configuration
# Default log configuration
CONFIG_SERIAL=y
CONFIG_LOG=y

# Coopertaive thread
CONFIG_LOG_PROCESS_THREAD_PRIORITY=0
CONFIG_LOG_MAX_LEVEL=3
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_BACKEND_SHOW_COLOR=y
Expand Down
5 changes: 4 additions & 1 deletion samples/isbd_app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ int main(void) {
}
};

LOG_DBG( "%s", "Setting up iridium subscriber unit ..." );
LOG_INF( "%s", "Setting up DTE ..." );

if ( isu_dte_setup( &g_isu_dte, &isu_dte_config ) == ISU_DTE_OK ) {
LOG_INF( "%s", "Modem OK" );
Expand All @@ -137,11 +137,14 @@ int main(void) {
isbd_config_t isbd_config =
ISBD_DEFAULT_CONF( &g_isu_dte );

LOG_INF( "%s", "Setting up Iridium SBD service ..." );

isbd_setup( &isbd_config );

const char *msg = "UCM - MIoT";
isbd_send_mo_msg( msg, strlen( msg ), MO_MSG_RETRIES );


DO_FOREVER {

isbd_evt_t isbd_evt;
Expand Down
10 changes: 5 additions & 5 deletions samples/isbd_cmds/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ int main(void) {
.at_uart = {
.echo = true,
.verbose = true,
// .zuart = ZUART_CONF_POLL( 960x_device ),
.zuart = ZUART_CONF_IRQ( uart_960x_device, rx_buf, sizeof( rx_buf ), tx_buf, sizeof( tx_buf ) ),
// .zuart = ZUART_CONF_MIX_RX_IRQ_TX_POLL( 960x_device, rx_buf, sizeof( rx_buf ) ),
// .zuart = ZUART_CONF_MIX_RX_POLL_TX_IRQ( 960x_device, tx_buf, sizeof( tx_buf ) ),
.zuart = ZUART_CONF_POLL( uart_960x_device ),
// .zuart = ZUART_CONF_IRQ( uart_960x_device, rx_buf, sizeof( rx_buf ), tx_buf, sizeof( tx_buf ) ),
// .zuart = ZUART_CONF_MIX_RX_IRQ_TX_POLL( uart_960x_device, rx_buf, sizeof( rx_buf ) ),
// .zuart = ZUART_CONF_MIX_RX_POLL_TX_IRQ( uart_960x_device, tx_buf, sizeof( tx_buf ) ),
}
};

Expand Down Expand Up @@ -136,7 +136,7 @@ int main(void) {
for ( int i=0; i < len; i++ ) {
printk( "%c", buf[ i ] );
}
printk( "\", len=%d, csum=%04X == %04X",
printk( "\", len=%d, csum=0x%04X, hcsum=0x%04X",
len, csum, isbd_util_compute_checksum( buf, len ) );
}, {}, isu_get_mt, buf, &len, &csum );

Expand Down
2 changes: 1 addition & 1 deletion tests/zuart/src/test_zuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static void* zuart_suite_setup(void) {
zassume_not_null( fixture );

// zuart_config_t zuart_config = ZUART_CONF_POLL( (struct device*)ISBD_UART_DEVICE );

zuart_config_t zuart_config = ZUART_CONF_IRQ(
(struct device*)ISBD_UART_DEVICE,
fixture->rx_buf, sizeof( fixture->rx_buf ),
Expand Down Expand Up @@ -71,7 +72,6 @@ ZTEST_F( zuart_suite, test_overrun ) {

do {

// printk("Waiting for host ... %d\n", ret );
zuart_write( &fixture->zuart, write_buf, write_buf_len, 0 );

// accept any byte as response
Expand Down

0 comments on commit 044b61e

Please sign in to comment.