Skip to content

RPC fixes #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/**************************************************************************************
* DEFINE
**************************************************************************************/
#include <stdio.h>

#ifdef DEBUG
#define dbg_printf(...) printf(__VA_ARGS__)
Expand Down
7 changes: 4 additions & 3 deletions libraries/openamp_arduino/src/openamp_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ extern int __OPENAMP_region_end__[];
#endif

#define VRING_RX_ADDRESS SHM_START_ADDRESS
#define VRING_TX_ADDRESS (SHM_START_ADDRESS + 0x400)
#define VRING_BUFF_ADDRESS (SHM_START_ADDRESS + 0x800)
#define VRING_ALIGNMENT 4
#define VRING_TX_ADDRESS (SHM_START_ADDRESS + 0x1000)
#define VRING_BUFF_ADDRESS (SHM_START_ADDRESS + 0x2000)
#define VRING_BUFF_SIZE (SHM_SIZE - 0x2000)
#define VRING_ALIGNMENT 32
#define VRING_NUM_BUFFS 16 /* number of rpmsg buffers */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been updated to 64 buffers.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/* Fixed parameter */
Expand Down
26 changes: 26 additions & 0 deletions src/gpio_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ extern struct IRQ_numbers IRQ_pinmap[];
* FUNCTION DEFINITION
**************************************************************************************/

static void configure_pins_shorted_together(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef* GPIO_InitStruct) {
if (GPIO_InitStruct->Pin == GPIO_PIN_10 && GPIOx == GPIOB) {
GPIO_InitStruct->Mode = GPIO_MODE_INPUT;
GPIO_InitStruct->Pull = GPIO_NOPULL;
GPIO_InitStruct->Pin = GPIO_PIN_7;
HAL_GPIO_Init(GPIOG, GPIO_InitStruct);
}
if (GPIO_InitStruct->Pin == GPIO_PIN_15 && GPIOx == GPIOD) {
GPIO_InitStruct->Mode = GPIO_MODE_INPUT;
GPIO_InitStruct->Pull = GPIO_NOPULL;
GPIO_InitStruct->Pin = GPIO_PIN_6;
HAL_GPIO_Init(GPIOG, GPIO_InitStruct);
}
}

static void write_pins_shorted_together(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState) {
if (GPIO_Pin == GPIO_PIN_10 && GPIOx == GPIOB) {
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_7, PinState);
}
if (GPIO_Pin == GPIO_PIN_15 && GPIOx == GPIOD) {
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6, PinState);
}
}

int gpio_handler(uint8_t const opcode, uint8_t const * data, uint16_t const size)
{
uint16_t const gpio_data = *((uint16_t*)data);
Expand All @@ -66,6 +90,7 @@ int gpio_handler(uint8_t const opcode, uint8_t const * data, uint16_t const size
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIO_pinmap[index].port, &GPIO_InitStruct);
configure_pins_shorted_together(GPIO_pinmap[index].port, &GPIO_InitStruct);
dbg_printf("GPIO%d: CONFIGURE %d\n", index, value);
break;
case IRQ_TYPE:
Expand All @@ -92,6 +117,7 @@ int gpio_handler(uint8_t const opcode, uint8_t const * data, uint16_t const size
break;
case WRITE:
HAL_GPIO_WritePin(GPIO_pinmap[index].port, GPIO_pinmap[index].pin, value);
write_pins_shorted_together(GPIO_pinmap[index].port, GPIO_pinmap[index].pin, value);
dbg_printf("GPIO%d: WRITE %d\n", index, value);
break;
case READ:
Expand Down
8 changes: 2 additions & 6 deletions src/pwm_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@

int pwm_handler(uint8_t const opcode, uint8_t const * data, uint16_t const size)
{
if (opcode == CAPTURE)
if (opcode & CAPTURE)
{
uint8_t const channel = opcode & 0x0F;
if (isValidPwmChannelNumber(channel))
capturePwm(channel);
else
dbg_printf("pwm_handler: invalid PWM channel number provided for mode CAPTURE: %d\n", channel);
}
else if (opcode == CONFIGURE)
else
{
uint8_t const channel = opcode;
struct pwmPacket config = *((struct pwmPacket*)data);
Expand All @@ -49,9 +49,5 @@ int pwm_handler(uint8_t const opcode, uint8_t const * data, uint16_t const size)
else
dbg_printf("pwm_handler: invalid PWM channel number provided for mode PWM: %d\n", channel);
}
else
{
dbg_printf("pwm_handler: error invalid opcode (:%d)\n", opcode);
}
return 0;
}
8 changes: 4 additions & 4 deletions src/rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void new_service_cb(struct rpmsg_device *rdev, const char *name, uint32_t dest)
if (strcmp(name, "raw") == 0) {
OPENAMP_create_endpoint(&rp_endpoints[ENDPOINT_RAW], name, dest, rpmsg_recv_raw_callback, NULL);
}
if (strcmp(name, "response") == 0) {
if (strcmp(name, "rpc") == 0) {
OPENAMP_create_endpoint(&rp_endpoints[ENDPOINT_RESPONSE], name, dest, rpmsg_recv_raw_callback, NULL);
}
}
Expand All @@ -79,7 +79,7 @@ int serial_rpc_begin() {

/* Initialize the rpmsg endpoint to set default addresses to RPMSG_ADDR_ANY */
rpmsg_init_ept(&rp_endpoints[0], "raw", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, NULL, NULL);
rpmsg_init_ept(&rp_endpoints[1], "response", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, NULL, NULL);
rpmsg_init_ept(&rp_endpoints[1], "rpc", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, NULL, NULL);

/*
* The rpmsg service is initiate by the remote processor, on H7 new_service_cb
Expand All @@ -101,8 +101,8 @@ void serial_rpc_available() {
}

void serial_rpc_write(uint8_t const * buf, size_t len) {
// check second byte of the message to split requests and responses
OPENAMP_send(&rp_endpoints[buf[1] == 1], buf, len);
// we'll only get rpc requests from "upstairs"
OPENAMP_send(&rp_endpoints[1], buf, len);
}

void HSEM1_IRQHandler(void)
Expand Down
20 changes: 20 additions & 0 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@ void pwm_timer_config(uint32_t index, uint32_t channel,
HAL_HRTIM_SimplePWMChannelConfig(&hhrtim, index, channel, pSimplePWMChannelCfg);
HAL_HRTIM_SoftwareUpdate(&hhrtim, timers);

GPIO_InitTypeDef GPIO_InitStruct = {0};

if (enable && index == 3) {
GPIO_InitStruct.Pin = GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF2_HRTIM1;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
}

if (enable && index == 5) {
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF2_HRTIM1;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
}

if (enable) {
HAL_HRTIM_SimplePWMStart(&hhrtim, index, channel);
} else {
Expand Down