波形的rstanding Problems

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
6 posts / 0 new
Last post
gert186
Offline
Last seen:1 year 4 months ago
加入:2016-04-21 12:59
波形的rstanding Problems

Hi,

I would like to print out 1000 times something

for(int i=0;i<=1000;i++){
uart_write("a", 16, NULL);}

but it only prints on uart a part of it and then it will be stopped...

I attached thies in DSPS device if I receive something from the host:

int user_sps_server_data_rx_ind_handler(ke_msg_id_t const msgid,
struct sps_server_data_rx_ind const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
for(int i=0;i<=1000;i++){
uart_write("a", 16, NULL);}
user_ble_push((uint8_t *)param->data, param->length);

return (KE_MSG_CONSUMED);
}

I run into a wall :-)

也许有人可以告诉我:-)

Device:
JK_Dialog
Offline
Last seen:2 months 2 weeks ago
Staff
加入:2016-08-22 23:07
Hi Gert,

Hi Gert,

Few things going on here. The uart_write(x) is going to be blocking in your handler. Also, the uart_write() shoudl be handled a little differently than this. uart_write is in ROM, but we can reference uart2_write for the functionality. void uart2_write(uint8_t *bufptr, uint32_t size, void (*callback) (uint8_t)). This is looking for a pointer and a size. So there are a couple different way syou can do this.

1) Create a 1000 character buffer, and pass the pointer along with size = 1000. Then you only need to call it once, and you will get a callback when this is finished. So something like this.

uint8_t buffer[1000] ;

//0x61 Ascii code for 'a'

memset(buffer, 0x61, 1000);

uart_write(&buffer[0], 1000, NULL);

2) You can use the asynchronous method and use the callback. Would be better on memory. uart_write("a", 1, my_callback). Then in my_callback, just increment a counter each time you've printed a character and call uart_write() again.

Jon

gert186
Offline
Last seen:1 year 4 months ago
加入:2016-04-21 12:59
Thanks that helps me to

Thanks that helps me to understand it! Is this also possible for ble sending?
Thanks a lot

JK_Dialog
Offline
Last seen:2 months 2 weeks ago
Staff
加入:2016-08-22 23:07
Yes. user_ble_push is

Yes. user_ble_push is looking for a pointer and a length - similarly. This will pass the data to FIFO buffer and send the data via BLE.

JK

gert186
Offline
Last seen:1 year 4 months ago
加入:2016-04-21 12:59
any length restriction ??

any length restriction ??

JK_Dialog
Offline
Last seen:2 months 2 weeks ago
Staff
加入:2016-08-22 23:07
The length restriction can be

The length restriction can be seen by tracing the code for user_buffer_create(). These are called in user_scheduler_init() and are defined by TX_BUFFER_ITEM_COUNT, and RX_BUFFER_ITEM_COUNT:

if(!user_buffer_initialized(&periph_to_ble_buffer) && !user_buffer_initialized(&ble_to_periph_buffer))
{
//initialize buffers
user_buffer_create(&ble_to_periph_buffer, TX_BUFFER_ITEM_COUNT, TX_BUFFER_LWM, TX_BUFFER_HWM);
user_buffer_create(&periph_to_ble_buffer, RX_BUFFER_ITEM_COUNT, RX_BUFFER_LWM, RX_BUFFER_HWM);
}

#define TX_BUFFER_ITEM_COUNT (int) 1800

#define RX_BUFFER_ITEM_COUNT (int) 1800

user_ble_push, writes to the ble_to_periph_buffer.

void user_ble_push(uint8_t* wrdata, uint16_t write_amount)
{
bool send_flow_off = false;

//write items to buffer;

user_buffer_write_items(&ble_to_periph_buffer, wrdata, write_amount);

//check if buffer is almost full and issue to send a XOFF if so
send_flow_off = user_check_buffer_almost_full(&ble_to_periph_buffer);

//if XOFF must be send, send asap
if(send_flow_off)
{
user_send_ble_flow_ctrl(FLOW_OFF);
}
//start transmitting
__disable_irq();
if(!callbackbusy)
{
callbackbusy = true;
uart_tx_callback(UART_STATUS_INIT);
}
__enable_irq();
}