Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Verified Commit 05a836f9 authored by Ayush Singh's avatar Ayush Singh
Browse files

Phasing out gb_operations


In the current architecture, gb operations is only used to track SVC
operations. But it is not particularly useful for that either. So just
removing it for now.

Signed-off-by: default avatarAyush Singh <ayushsingh1325@gmail.com>
parent 2c1a72b5
Branches
1 merge request!2HDLC MR
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
/* Greybus SVC request types */ /* Greybus SVC request types */
#define GB_SVC_TYPE_PING 0x13 #define GB_SVC_TYPE_PING 0x13
#define GB_SVC_TYPE_PROTOCOL_VERSION_RESPONSE 0x81
/* /*
* All operation messages (both requests and responses) begin with * All operation messages (both requests and responses) begin with
......
...@@ -187,9 +187,9 @@ int gb_message_hdlc_send(const struct gb_message *msg) { ...@@ -187,9 +187,9 @@ int gb_message_hdlc_send(const struct gb_message *msg) {
} }
struct gb_connection *gb_create_connection(struct gb_interface *inf_ap, struct gb_connection *gb_create_connection(struct gb_interface *inf_ap,
struct gb_interface *inf_peer, struct gb_interface *inf_peer,
uint16_t ap_cport, uint16_t ap_cport,
uint16_t peer_cport) { uint16_t peer_cport) {
struct gb_connection *conn = k_malloc(sizeof(struct gb_connection)); struct gb_connection *conn = k_malloc(sizeof(struct gb_connection));
if (conn == NULL) { if (conn == NULL) {
LOG_ERR("Failed to create Greybus connection"); LOG_ERR("Failed to create Greybus connection");
...@@ -203,3 +203,32 @@ struct gb_connection *gb_create_connection(struct gb_interface *inf_ap, ...@@ -203,3 +203,32 @@ struct gb_connection *gb_create_connection(struct gb_interface *inf_ap,
return conn; return conn;
} }
static uint16_t new_operation_id() {
atomic_val_t temp = atomic_inc(&operation_id_counter);
if (temp == UINT16_MAX) {
atomic_set(&operation_id_counter, 1);
}
return temp;
}
struct gb_message *gb_message_request_alloc(const void *payload,
size_t payload_len,
uint8_t request_type, bool is_oneshot) {
struct gb_message *msg;
msg = k_malloc(sizeof(struct gb_message) + payload_len);
if (msg == NULL) {
LOG_WRN("Failed to allocate Greybus request message");
return NULL;
}
msg->header.size = sizeof(struct gb_operation_msg_hdr) + payload_len;
msg->header.id = is_oneshot ? 0 : new_operation_id();
msg->header.type = request_type;
msg->header.status = 0;
msg->payload_size = payload_len;
memcpy(msg->payload, payload, msg->payload_size);
return msg;
}
...@@ -182,4 +182,6 @@ struct gb_connection *gb_create_connection(struct gb_interface *, ...@@ -182,4 +182,6 @@ struct gb_connection *gb_create_connection(struct gb_interface *,
struct gb_interface *, uint16_t, struct gb_interface *, uint16_t,
uint16_t); uint16_t);
struct gb_message *gb_message_request_alloc(const void *, size_t, uint8_t, bool);
#endif #endif
...@@ -8,6 +8,30 @@ ...@@ -8,6 +8,30 @@
LOG_MODULE_DECLARE(cc1352_greybus, CONFIG_BEAGLEPLAY_GREYBUS_LOG_LEVEL); LOG_MODULE_DECLARE(cc1352_greybus, CONFIG_BEAGLEPLAY_GREYBUS_LOG_LEVEL);
struct gb_common_version_request {
uint8_t major;
uint8_t minor;
} __packed;
static void gb_common_version_callback(struct gb_message *msg) {
struct gb_common_version_request *response =
(struct gb_common_version_request *)msg->payload;
LOG_DBG("SVC Protocol Version %u.%u", response->major, response->minor);
}
static void gb_handle_msg(struct gb_message *msg) {
switch (msg->header.type) {
case GB_SVC_TYPE_PROTOCOL_VERSION_RESPONSE:
gb_common_version_callback(msg);
break;
default:
LOG_WRN("Handling SVC operation Type %u not supported yet",
msg->header.type);
}
gb_message_dealloc(msg);
}
struct svc_control_data { struct svc_control_data {
struct k_fifo pending_read; struct k_fifo pending_read;
}; };
...@@ -17,22 +41,12 @@ static struct svc_control_data svc_ctrl_data; ...@@ -17,22 +41,12 @@ static struct svc_control_data svc_ctrl_data;
static struct gb_message *svc_inf_read(struct gb_controller *ctrl, static struct gb_message *svc_inf_read(struct gb_controller *ctrl,
uint16_t cport_id) { uint16_t cport_id) {
struct gb_message *msg = k_fifo_get(&svc_ctrl_data.pending_read, K_NO_WAIT); struct gb_message *msg = k_fifo_get(&svc_ctrl_data.pending_read, K_NO_WAIT);
if (msg != NULL) {
msg->operation->request_sent = true;
}
return msg; return msg;
} }
static int svc_inf_write(struct gb_controller *ctrl, struct gb_message *msg, static int svc_inf_write(struct gb_controller *ctrl, struct gb_message *msg,
uint16_t cport_id) { uint16_t cport_id) {
if (gb_message_is_response(msg)) { gb_handle_msg(msg);
// Find associated Greybus operation
gb_operation_set_response(msg);
} else {
// Handle Request
LOG_DBG("Handle Greybus request with ID: %u", msg->header.id);
gb_message_dealloc(msg);
}
return 0; return 0;
} }
...@@ -41,58 +55,31 @@ static struct gb_interface intf = {.id = SVC_INF_ID, ...@@ -41,58 +55,31 @@ static struct gb_interface intf = {.id = SVC_INF_ID,
.write = svc_inf_write, .write = svc_inf_write,
.ctrl_data = &svc_ctrl_data}}; .ctrl_data = &svc_ctrl_data}};
struct gb_common_version_request {
uint8_t major;
uint8_t minor;
} __packed;
static void svc_ping_callback(struct gb_operation *op) { static void svc_ping_callback(struct gb_operation *op) {
LOG_DBG("Received Pong"); LOG_DBG("Received Pong");
} }
static int control_send_request(void *payload, size_t payload_len, static int control_send_request(void *payload, size_t payload_len,
uint8_t request_type, uint8_t request_type) {
greybus_operation_callback_t callback) { struct gb_message *msg;
int ret; msg = gb_message_request_alloc(payload, payload_len, request_type, false);
struct gb_operation *op = gb_operation_alloc(false); if (msg == NULL) {
if (op == NULL) {
return -ENOMEM; return -ENOMEM;
} }
ret = gb_operation_request_alloc(op, payload, payload_len, request_type, k_fifo_put(&svc_ctrl_data.pending_read, msg);
callback);
if (ret < 0) {
LOG_DBG("Failed to allocate Greybus Request");
return ret;
}
k_fifo_put(&svc_ctrl_data.pending_read, op->request);
gb_operation_queue(op);
return SUCCESS; return SUCCESS;
} }
static void gb_common_version_callback(struct gb_operation *op) {
if (op->response == NULL) {
LOG_DBG("Null Response");
return;
}
struct gb_common_version_request *response = (struct gb_common_version_request*)op->response->payload;
LOG_DBG("SVC Protocol Version %u.%u", response->major, response->minor);
}
int svc_send_version() { int svc_send_version() {
struct gb_common_version_request req = {.major = GB_SVC_VERSION_MAJOR, struct gb_common_version_request req = {.major = GB_SVC_VERSION_MAJOR,
.minor = GB_SVC_VERSION_MINOR}; .minor = GB_SVC_VERSION_MINOR};
return control_send_request(&req, sizeof(struct gb_common_version_request), return control_send_request(&req, sizeof(struct gb_common_version_request),
GB_COMMON_TYPE_PROTOCOL_VERSION, GB_COMMON_TYPE_PROTOCOL_VERSION);
gb_common_version_callback);
} }
int svc_send_ping() { int svc_send_ping() { return control_send_request(NULL, 0, GB_SVC_TYPE_PING); }
return control_send_request(NULL, 0, GB_SVC_TYPE_PING, svc_ping_callback);
}
struct gb_interface *svc_init() { struct gb_interface *svc_init() {
k_fifo_init(&svc_ctrl_data.pending_read); k_fifo_init(&svc_ctrl_data.pending_read);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define SVC_H #define SVC_H
#include "operations.h" #include "operations.h"
#define SVC_INF_ID 0 #define SVC_INF_ID 0
/* /*
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment