Skip to content

Commit

Permalink
Clean and clang-format files in prev commit
Browse files Browse the repository at this point in the history
  • Loading branch information
codecubepi committed Dec 20, 2023
1 parent 40b1507 commit 1c5152a
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 166 deletions.
50 changes: 21 additions & 29 deletions sdk/freertos_app_cpu0/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,12 @@ int main(void)
icc_init(0);
vPortInstallFreeRTOSVectorTable();




//////* BEGIN USER CODE HERE *//////
///////////////////////////////////
////// BEGIN USER CODE HERE //////
/////////////////////////////////

led_init();



const TickType_t x10seconds = pdMS_TO_TICKS(DELAY_10_SECONDS);

xil_printf("CPU0 - Hello from FreeRTOS example main()!\r\n");
Expand Down Expand Up @@ -199,13 +196,9 @@ int main(void)
10 seconds */
xTimerStart(xTimer, 0);


//////* END USER CODE HERE *//////





/////////////////////////////////
////// END USER CODE HERE //////
///////////////////////////////

/* Start the tasks and timer running. */
vTaskStartScheduler();
Expand Down Expand Up @@ -234,19 +227,19 @@ static void prvTxTask(void *pvParameters)

/* Send the next value on the queue. The queue should always be
empty at this point so a block time of 0 is used. */
// xQueueSend(xQueue, /* The queue being written to. */
// HWstring, /* The address of the data being sent. */
// 0UL); /* The block time. */
// xQueueSend(xQueue, /* The queue being written to. */
// HWstring, /* The address of the data being sent. */
// 0UL); /* The block time. */

xil_printf("DEBUG: CPU 0 about to attempt send\r\n");

// Send a message to the other core
size_t bytes_sent = xMessageBufferSend(xCPU0to1MessageBuffer, HWstring, sizeof(HWstring), 0UL);

xil_printf("DEBUG: CPU0 sent %d bytes to ICC buffer\r\n",bytes_sent);
xil_printf("DEBUG: CPU0 sent %d bytes to ICC buffer\r\n", bytes_sent);

if(bytes_sent == 0){
xil_printf("ERROR: CPU 0 failed to write to ICC buffer\r\n");
if (bytes_sent == 0) {
xil_printf("ERROR: CPU 0 failed to write to ICC buffer\r\n");
}
}
}
Expand All @@ -263,21 +256,20 @@ static void prvRxTask(void *pvParameters)
vTaskSuspend(NULL);
} else {

// /* Block to wait for data arriving on the queue. */
// xQueueReceive(xQueue, /* The queue being read. */
// Rcvdstring, /* Data is read into this address. */
// portMAX_DELAY); /* Wait without a timeout for data. */
// /* Block to wait for data arriving on the queue. */
// xQueueReceive(xQueue, /* The queue being read. */
// Rcvdstring, /* Data is read into this address. */
// portMAX_DELAY); /* Wait without a timeout for data. */

xil_printf("DEBUG: CPU 0 about to attempt rcv\r\n");

size_t bytes_rcvd = xMessageBufferReceive(xCPU1to0MessageBuffer, Rcvdstring, 32, portMAX_DELAY);
size_t bytes_rcvd = xMessageBufferReceive(xCPU1to0MessageBuffer, Rcvdstring, 32, portMAX_DELAY);

xil_printf("DEBUG: CPU0 rcvd %d bytes from ICC buffer\r\n",bytes_rcvd);
xil_printf("DEBUG: CPU0 rcvd %d bytes from ICC buffer\r\n", bytes_rcvd);

if(bytes_rcvd == 0){
xil_printf("CPU 0 failed to receive from ICC buffer\r\n");
}
else{
if (bytes_rcvd == 0) {
xil_printf("CPU 0 failed to receive from ICC buffer\r\n");
} else {
/* Print the received data. */
xil_printf("CPU0 - Rx task received string from CPU1 Tx: %s\r\n", Rcvdstring);
RxtaskCntr++;
Expand Down
67 changes: 32 additions & 35 deletions sdk/freertos_app_cpu0/src/sys/icc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@

void icc_init(uint32_t cpu_num)
{
if (cpu_num == 0){
/* CPU 0 is responsible for:
* 1. Creating its own send and receive tasks which interact with the message buffers */
xil_printf("ICC INIT CPU0\r\n");
}
else if (cpu_num == 1){
/* CPU 1 is responsible for:
* 1. Creating its own send and receive tasks which interact with the message buffers */
xil_printf("ICC INIT CPU1\r\n");
}
else{
// TODO: This should probably throw a proper exception
xil_printf("Invalid CPU number passed to ICC initialization.\r\n");
while(1){}
}
if (cpu_num == 0) {
/* CPU 0 is responsible for:
* 1. Creating its own send and receive tasks which interact with the message buffers */
xil_printf("ICC INIT CPU0\r\n");
} else if (cpu_num == 1) {
/* CPU 1 is responsible for:
* 1. Creating its own send and receive tasks which interact with the message buffers */
xil_printf("ICC INIT CPU1\r\n");
} else {
// TODO: This should probably throw a proper exception
xil_printf("Invalid CPU number passed to ICC initialization.\r\n");
while (1) {
}
}

// MessageBufferHandle_t xMessageBufferCreateStaticWithCallback(
// size_t xBufferSizeBytes,
Expand All @@ -39,21 +38,21 @@ void icc_init(uint32_t cpu_num)
/* Create two message buffers for inter-core communication that use the callback
* functions below as send and receive completed callback functions. */
xCPU0to1MessageBuffer = xMessageBufferCreateStaticWithCallback(ICC_BUFFER_SIZE - 1,
ICC_CPU0to1_BufferBaseAddr,
&xCPU0to1MessageBufferStruct,
vCPU0to1SendCallback,
vCPU0to1ReceiveCallback);
ICC_CPU0to1_BufferBaseAddr,
&xCPU0to1MessageBufferStruct,
vCPU0to1SendCallback,
vCPU0to1ReceiveCallback);

xCPU1to0MessageBuffer = xMessageBufferCreateStaticWithCallback(ICC_BUFFER_SIZE - 1,
ICC_CPU1to0_BufferBaseAddr,
&xCPU1to0MessageBufferStruct,
vCPU1to0SendCallback,
vCPU1to0ReceiveCallback);
ICC_CPU1to0_BufferBaseAddr,
&xCPU1to0MessageBufferStruct,
vCPU1to0SendCallback,
vCPU1to0ReceiveCallback);
}

void vCPU0to1SendCallback(MessageBufferHandle_t xMessageBuffer,
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken)
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken)
{
/* Insert code here which is invoked when a message is written to the message buffer.
* This is useful when a message buffer is used to pass messages between
Expand All @@ -65,8 +64,8 @@ void vCPU0to1SendCallback(MessageBufferHandle_t xMessageBuffer,
}

void vCPU0to1ReceiveCallback(MessageBufferHandle_t xMessageBuffer,
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken)
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken)
{
/* Insert code here which is invoked when a message is read from a message buffer.
* This is useful when a message buffer is used to pass messages between
Expand All @@ -78,8 +77,8 @@ void vCPU0to1ReceiveCallback(MessageBufferHandle_t xMessageBuffer,
}

void vCPU1to0SendCallback(MessageBufferHandle_t xMessageBuffer,
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken)
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken)
{
/* Insert code here which is invoked when a message is written to the message buffer.
* This is useful when a message buffer is used to pass messages between
Expand All @@ -91,8 +90,8 @@ void vCPU1to0SendCallback(MessageBufferHandle_t xMessageBuffer,
}

void vCPU1to0ReceiveCallback(MessageBufferHandle_t xMessageBuffer,
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken)
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken)
{
/* Insert code here which is invoked when a message is read from a message buffer.
* This is useful when a message buffer is used to pass messages between
Expand All @@ -107,18 +106,16 @@ void vCPU1to0ReceiveCallback(MessageBufferHandle_t xMessageBuffer,
* Only available in the correct CPU
* CPU_NUM is defined in each core's FreeRTOSConfig.h */



/*
#if CPU_NUM == 0
void icc_send_cpu0_to_cpu1 (void * data){
size_t size_of_thing = xMessageBufferSend();
size_t size_of_thing = xMessageBufferSend();
}
#endif
#if CPU_NUM == 1
void icc_send_cpu1_to_cpu0 (void * data){
size_t size_of_thing = xMessageBufferSend();
size_t size_of_thing = xMessageBufferSend();
}
#endif
*/
25 changes: 8 additions & 17 deletions sdk/freertos_app_cpu0/src/sys/icc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,11 @@
#define OCM_BASE_ADDR (0xFFFF0000)
#define ICC_BUFFER_SIZE (4 * 1024)

/* Create pointer to the memory that will actually hold the messages within the message
* buffer. Should be one more than the value passed in the xBufferSizeBytes parameter. */
#define ICC_CPU0to1_BufferBaseAddr ((uint8_t *) (OCM_BASE_ADDR + 1024 + (0 * ICC_BUFFER_SIZE)))
#define ICC_CPU1to0_BufferBaseAddr ((uint8_t *) (OCM_BASE_ADDR + 1024 + (1 * ICC_BUFFER_SIZE)))

///* Used to dimension the array used to hold the messages. The available
// * space will actually be one less than this, so 1023. */
//#define STORAGE_SIZE_BYTES 1024

/* Defines the memory that will actually hold the messages within the message
* buffer. Should be one more than the value passed in the xBufferSizeBytes
* parameter. */
//static uint8_t ucCPU0toCPU1MessageBufferStorage[STORAGE_SIZE_BYTES];
//static uint8_t ucCPU1toCPU0MessageBufferStorage[STORAGE_SIZE_BYTES];

// These are the handles for the Message Buffers that need to be used by other tasks
MessageBufferHandle_t xCPU0to1MessageBuffer;
MessageBufferHandle_t xCPU1to0MessageBuffer;
Expand All @@ -61,19 +53,18 @@ MessageBufferHandle_t xCPU1to0MessageBuffer;
StaticMessageBuffer_t xCPU0to1MessageBufferStruct;
StaticMessageBuffer_t xCPU1to0MessageBufferStruct;


void icc_init(uint32_t cpu_num);
void vCPU0to1SendCallback(MessageBufferHandle_t xMessageBuffer,
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken);
void vCPU0to1ReceiveCallback(MessageBufferHandle_t xMessageBuffer,
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken);
void vCPU0to1ReceiveCallback(MessageBufferHandle_t xMessageBuffer,
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken);
void vCPU1to0SendCallback(MessageBufferHandle_t xMessageBuffer,
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken);
void vCPU1to0ReceiveCallback(MessageBufferHandle_t xMessageBuffer,
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken);
void vCPU1to0ReceiveCallback(MessageBufferHandle_t xMessageBuffer,
BaseType_t xIsInsideISR,
BaseType_t *const pxHigherPriorityTaskWoken);

#endif /* ICC_H */
56 changes: 23 additions & 33 deletions sdk/freertos_app_cpu1/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,9 @@ int main(void)
icc_init(1);
vPortInstallFreeRTOSVectorTable();




//////* BEGIN USER CODE HERE *//////




///////////////////////////////////
////// BEGIN USER CODE HERE //////
/////////////////////////////////

const TickType_t x10seconds = pdMS_TO_TICKS(DELAY_10_SECONDS);

Expand Down Expand Up @@ -167,13 +162,9 @@ int main(void)
10 seconds */
xTimerStart(xTimer, 0);



//////* END USER CODE HERE *//////




/////////////////////////////////
////// END USER CODE HERE //////
///////////////////////////////

/* Start the tasks and timer running. */
vTaskStartScheduler();
Expand All @@ -200,21 +191,21 @@ static void prvTxTask(void *pvParameters)
/* Delay for 1 second. */
vTaskDelay(x1second);

/* Send the next value on the queue. The queue should always be
empty at this point so a block time of 0 is used. */
// xQueueSend(xQueue, /* The queue being written to. */
// HWstring, /* The address of the data being sent. */
// 0UL); /* The block time. */
// /* Send the next value on the queue. The queue should always be
// empty at this point so a block time of 0 is used. */
// xQueueSend(xQueue, /* The queue being written to. */
// HWstring, /* The address of the data being sent. */
// 0UL); /* The block time. */

xil_printf("DEBUG: CPU 1 about to attempt send\r\n");

// Send a message to the other core
size_t bytes_sent = xMessageBufferSend(xCPU1to0MessageBuffer, HWstring, sizeof(HWstring), 0UL);

xil_printf("DEBUG: CPU1 sent %d bytes to ICC buffer\r\n",bytes_sent);
xil_printf("DEBUG: CPU1 sent %d bytes to ICC buffer\r\n", bytes_sent);

if(bytes_sent == 0){
xil_printf("ERROR: CPU 1 failed to write to ICC buffer\r\n");
if (bytes_sent == 0) {
xil_printf("ERROR: CPU 1 failed to write to ICC buffer\r\n");
}
}
}
Expand All @@ -231,21 +222,20 @@ static void prvRxTask(void *pvParameters)
vTaskSuspend(NULL);
} else {

// /* Block to wait for data arriving on the queue. */
// xQueueReceive(xQueue, /* The queue being read. */
// Rcvdstring, /* Data is read into this address. */
// portMAX_DELAY); /* Wait without a timeout for data. */
// /* Block to wait for data arriving on the queue. */
// xQueueReceive(xQueue, /* The queue being read. */
// Rcvdstring, /* Data is read into this address. */
// portMAX_DELAY); /* Wait without a timeout for data. */

xil_printf("DEBUG: CPU 1 about to attempt rcv\r\n");

size_t bytes_rcvd = xMessageBufferReceive(xCPU0to1MessageBuffer, Rcvdstring, 32, portMAX_DELAY);
size_t bytes_rcvd = xMessageBufferReceive(xCPU0to1MessageBuffer, Rcvdstring, 32, portMAX_DELAY);

xil_printf("DEBUG: CPU1 rcvd %d bytes from ICC buffer",bytes_rcvd);
xil_printf("DEBUG: CPU1 rcvd %d bytes from ICC buffer", bytes_rcvd);

if(bytes_rcvd == 0){
xil_printf("CPU 1 failed to receive from ICC buffer\r\n");
}
else{
if (bytes_rcvd == 0) {
xil_printf("CPU 1 failed to receive from ICC buffer\r\n");
} else {
/* Print the received data. */
xil_printf("CPU1 - Rx task received string from CPU0 Tx: %s\r\n", Rcvdstring);
RxtaskCntr++;
Expand Down
Loading

0 comments on commit 1c5152a

Please sign in to comment.