sending message for updating characteristic by application task

8 posts / 0 new
Last post
giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
sending message for updating characteristic by application task

Hi,
I followed SAMPLE128 doc, I modified it adding new characteristics and more.
Now I need to know what message should I send from application task to task profile for updating characteristics (in example characteristic 2).
On the example I see two function for update characteristics 2:

/// Connected State handler definition.
const struct ke_msg_handler sample128_connected[] =
{
{GATTC_WRITE_CMD_IND, (ke_msg_func_t) gattc_write_cmd_ind_handler},
{SAMPLE128_UPD_CHAR2_REQ, (ke_msg_func_t) sample128_upd_char2_req_handler},
};

I presume that GATTC_WRITE_CMD_IND is the correct message to send but I don't understand why there is also SAMPLE128_UPD_CHAR2_REQ where inside there is a check on connection handler:

// Check provided values
if(param->conhdl == gapc_get_conhdl(trelettra_env.con_info.conidx))

How I can set correctly conhdl from application task? Is right use SAMPLE128_UPD_CHAR2_REQ?

Device:
Joacimwe
Offline
Last seen:1年3个月前
Guru
加入:2014-01-14 06:45
SAMPLE128_UPD_CHAR2_REQ is

SAMPLE128_UPD_CHAR2_REQ is the one to use when you want to update the characteristic value. The GATTC_WRITE_CMD_IND (ind for indication) is sent by the system to your profile task when the central sends a write command to the DA14580 over BLE.

giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
Ok. Thanks.

Ok. Thanks.

giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
Can I send message from task

Can I send message from task_app to himself on interrupt routine?
我试着读nsor every 300ms by timer0 interrupt. So I defined a callback function on periph_setup:

timer0_register_callback(timer0_interrupt_function);

For improve system response, sensor reading isn't performed in timer0_interrupt_function. So I decided to send message from TASK_APP to TASK_APP (himself) where a message handler perform the read. Defined in app_myproject.c:

void timer0_interrupt_function(void){
//send message to himself
struct myproject_read * cfm = KE_MSG_ALLOC(MYPROJECT_READ, TASK_APP, TASK_APP, myproject_read);
ke_msg_send(cfm);
}

Handler id declared in app_default_state handler:

{MYPROJECT_READ, (ke_msg_func_t)myproject_read_handler},

And also the message enum is defined in myproject_task.h together with the other messages of the profile.
Also myproject_read_handler is declared and defined in app_myproject_task.
However when I run the debugger system goes in loop on timer0_interrupt_function at KE_MSG_ALLOC row.
可能会出现什么问题?

Joacimwe
Offline
Last seen:1年3个月前
Guru
加入:2014-01-14 06:45
If you send a message without

If you send a message without parameters, you could use the simpler function ke_msg_send_basic:
ke_msg_send_basic(MYPROJECT_READ, TASK_APP, TASK_APP);
In your handler, the "param" parameter should be of type const void*.

If the message sending does not work good in an interrupt, use the following code to wake up the BLE system just before calling ke_msg_send_basic:
if (GetBits16(CLK_RADIO_REG, BLE_ENABLE) == 0) { // BLE clock is off
SetBits16(GP_CONTROL_REG, BLE_WAKEUP_REQ, 1);
}

giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
doesn't work. Loop here

doesn't work. Loop here

0x000009CE 4B0D LDR r3,[pc,#52] ; @0x00000A04
0x000009D0 881A LDRH r2,[r3,#0x00]
0x000009D2 4B0D LDR r3,[pc,#52] ; @0x00000A08
0 x000009d4 0491 lsl r1, r2, # 18
0x000009D6 D402 BMI 0x000009DE
0x000009D8 6858 LDR r0,[r3,#0x04]
0x000009DA 2800 CMP r0,#0x00
0x000009DC D0F7 BEQ 0x000009CE

loop there after I press stop button (I use uVision 5). Run code to breakpoint on the line with ke_msg_send_basic instruction, after that press step one line button and code doesn't stop. I need to press stop button to stop execution. After that the code loop there.

giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
I restart uVision and

I restart uVision and disconnect/riconnect device. Re-execute the code until the breakpoint (ke_msg_send_basic). Now step by step instruction are executed but cursor disappear from C code window, only disassembly window show cursor. Execution continue for some instruction until J-link cortex-M error alert appear:
"Could not stop Cortex-M device! Please check jtag cable"
On command window:
Jlink error can not read register 9
Jlink error can not read register 10
...

giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
I think that the problem is

I think that the problem is send message from interrupt routine that doesn't work. I don't know why.
I rewrote code with a global variable setted by interrupt routine, the global variable is checked on main_func and here message sended to task_app. In this way it works.