summaryrefslogtreecommitdiffstats
path: root/src/occ_gpe0
diff options
context:
space:
mode:
Diffstat (limited to 'src/occ_gpe0')
-rw-r--r--src/occ_gpe0/apss_init.c28
-rw-r--r--src/occ_gpe0/apss_read.c12
-rw-r--r--src/occ_gpe0/apss_util.c31
-rw-r--r--src/occ_gpe0/gpe0_main.c108
4 files changed, 58 insertions, 121 deletions
diff --git a/src/occ_gpe0/apss_init.c b/src/occ_gpe0/apss_init.c
index ea40cbf..39aeb79 100644
--- a/src/occ_gpe0/apss_init.c
+++ b/src/occ_gpe0/apss_init.c
@@ -22,7 +22,7 @@ uint32_t apss_start_spi_command(initGpioArgs_t * args, uint8_t i_noWait)
uint64_t regValue = 0x8000000000000000;
// Start SPI transaction
- rc = putscom_abs(SPIPSS_P2S_COMMAND_REG, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_COMMAND_REG, regValue);
if (rc)
{
PK_TRACE("apss_start_spi_command: SPIPSS_P2S_COMMAND_REG putscom failed. rc = 0x%08x",
@@ -32,7 +32,7 @@ uint32_t apss_start_spi_command(initGpioArgs_t * args, uint8_t i_noWait)
else
{
- pk_sleep(PK_MICROSECONDS(5));
+ busy_wait(5);
if (!i_noWait)
{
@@ -85,7 +85,7 @@ void apss_init_gpio(ipc_msg_t* cmd, void* arg)
// Setup the control regs
// frame_size=16, out_count=16, in_delay1=never, in_count2=16
regValue = 0x410FC00004000000;
- rc = putscom_abs(SPIPSS_P2S_CTRL_REG0, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_CTRL_REG0, regValue);
if (rc)
{
PK_TRACE("apss_init_gpio: SPIPSS_P2S_CTRL_REG0 putscom failed. rc = 0x%08x", rc);
@@ -94,7 +94,7 @@ void apss_init_gpio(ipc_msg_t* cmd, void* arg)
}
// bridge_enable, clock_divider=7, 2 frames
regValue = 0x8090400000000000;
- rc = putscom_abs(SPIPSS_P2S_CTRL_REG1, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_CTRL_REG1, regValue);
if (rc)
{
PK_TRACE("apss_init_gpio: SPIPSS_P2S_CTRL_REG1 putscom failed. rc = 0x%08x", rc);
@@ -103,7 +103,7 @@ void apss_init_gpio(ipc_msg_t* cmd, void* arg)
}
// inter_frame_delay=50 (5usec)
regValue = 0x0019000000000000;
- rc = putscom_abs(SPIPSS_P2S_CTRL_REG2, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_CTRL_REG2, regValue);
if (rc)
{
PK_TRACE("apss_init_gpio: SPIPSS_P2S_CTRL_REG2 putscom failed. rc = 0x%08x", rc);
@@ -122,7 +122,7 @@ void apss_init_gpio(ipc_msg_t* cmd, void* arg)
regValue |= 0x4000000000000000;
regValue |= (port << 56);
- rc = putscom_abs(SPIPSS_P2S_WDATA_REG, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_WDATA_REG, regValue);
if (rc)
{
PK_TRACE("apss_init_gpio: SPIPSS_P2S_WDATA_REG putscom failed. value:0x%X. rc = 0x%08x",
@@ -147,7 +147,7 @@ void apss_init_gpio(ipc_msg_t* cmd, void* arg)
regValue |= 0x5000000000000000;
regValue |= (port << 56);
- rc = putscom_abs(SPIPSS_P2S_WDATA_REG, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_WDATA_REG, regValue);
if (rc)
{
PK_TRACE("apss_init_gpio: SPIPSS_P2S_WDATA_REG putscom failed. value:0x%X. rc = 0x%08x",
@@ -171,7 +171,7 @@ void apss_init_gpio(ipc_msg_t* cmd, void* arg)
regValue |= 0x6000000000000000;
regValue |= (port << 56);
- rc = putscom_abs(SPIPSS_P2S_WDATA_REG, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_WDATA_REG, regValue);
if (rc)
{
PK_TRACE("apss_init_gpio: SPIPSS_P2S_WDATA_REG putscom failed. value:0x%X. rc = 0x%08x",
@@ -254,7 +254,7 @@ void apss_init_mode(ipc_msg_t* cmd, void* arg)
// Setup the control regs
// frame_size=16, out_count1=16, in_delay1=never, in_count2=16
regValue = 0x4100000000000000;
- rc = putscom_abs(SPIPSS_P2S_CTRL_REG0, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_CTRL_REG0, regValue);
if (rc)
{
PK_TRACE("apss_init_mode: SPIPSS_P2S_CTRL_REG0 putscom failed. rc = 0x%08x", rc);
@@ -264,7 +264,7 @@ void apss_init_mode(ipc_msg_t* cmd, void* arg)
// bridge_enable, clock_divider=7, 1 frames
regValue = 0x8090000000000000;
- rc = putscom_abs(SPIPSS_P2S_CTRL_REG1, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_CTRL_REG1, regValue);
if (rc)
{
PK_TRACE("apss_init_mode: SPIPSS_P2S_CTRL_REG1 putscom failed. rc = 0x%08x", rc);
@@ -273,7 +273,7 @@ void apss_init_mode(ipc_msg_t* cmd, void* arg)
}
// inter_frame_delay=25 (2.5usec)
regValue = 0x0019000000000000;
- rc = putscom_abs(SPIPSS_P2S_CTRL_REG2, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_CTRL_REG2, regValue);
if (rc)
{
PK_TRACE("apss_init_mode: SPIPSS_P2S_CTRL_REG2 putscom failed. rc = 0x%08x", rc);
@@ -306,7 +306,7 @@ void apss_init_mode(ipc_msg_t* cmd, void* arg)
break;
}
- rc = putscom_abs(SPIPSS_P2S_WDATA_REG, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_WDATA_REG, regValue);
if (rc)
{
PK_TRACE("apss_init_mode: SPIPSS_P2S_WDATA_REG putscom to set MODE failed. value:0x%X. rc = 0x%08x",
@@ -317,7 +317,7 @@ void apss_init_mode(ipc_msg_t* cmd, void* arg)
regValue = 0x8000000000000000;
// Start SPI transaction
- rc = putscom_abs(SPIPSS_P2S_COMMAND_REG, &regValue);
+ rc = putscom_abs(SPIPSS_P2S_COMMAND_REG, regValue);
if (rc)
{
PK_TRACE("apss_init_mode: SPIPSS_P2S_COMMAND_REG putscom failed. rc = 0x%08x",
@@ -326,7 +326,7 @@ void apss_init_mode(ipc_msg_t* cmd, void* arg)
}
//Wait 20usec for apss becoming ready to send out the frame of composite mode
- pk_sleep(PK_MICROSECONDS(20));;
+ busy_wait(20);
}while(0);
diff --git a/src/occ_gpe0/apss_read.c b/src/occ_gpe0/apss_read.c
index 6c09717..bf1b960 100644
--- a/src/occ_gpe0/apss_read.c
+++ b/src/occ_gpe0/apss_read.c
@@ -85,7 +85,7 @@ void apss_start_pwr_meas_read(ipc_msg_t* cmd, void* arg)
// frame_size=16, out_count=16, in_count=16
// rc = putscom(0, SPIPSS_ADC_CTRL_REG0, uint64_t 0x4000100000000000);
regValue = 0x4000100000000000;
- rc = putscom_abs(SPIPSS_ADC_CTRL_REG0, &regValue);
+ rc = putscom_abs(SPIPSS_ADC_CTRL_REG0, regValue);
if(rc)
{
PK_TRACE("apss_start_pwr_meas_read: SPIPSS_ADC_CTRL_REG0 putscom failed. rc = 0x%08x",
@@ -98,7 +98,7 @@ void apss_start_pwr_meas_read(ipc_msg_t* cmd, void* arg)
// clock_divider=7, frames=16
// rc = putscom_abs(SPIPSS_ADC_CTRL_REG1, 0x8093c00000000000);
regValue = 0x8093c00000000000;
- rc = putscom_abs(SPIPSS_ADC_CTRL_REG1, &regValue);
+ rc = putscom_abs(SPIPSS_ADC_CTRL_REG1, regValue);
if(rc)
{
PK_TRACE("apss_start_pwr_meas_read: SPIPSS_ADC_CTRL_REG1 putscom failed. rc = 0x%08x",
@@ -111,7 +111,7 @@ void apss_start_pwr_meas_read(ipc_msg_t* cmd, void* arg)
// 5 usec
// rc = putscom_abs(SPIPSS_ADC_CTRL_REG2, 0x0019000000000000);
regValue = 0x0019000000000000;
- rc = putscom_abs(SPIPSS_ADC_CTRL_REG2, &regValue);
+ rc = putscom_abs(SPIPSS_ADC_CTRL_REG2, regValue);
if(rc)
{
PK_TRACE("apss_start_pwr_meas_read: SPIPSS_ADC_CTRL_REG2 putscom failed. rc = 0x%08x",
@@ -124,7 +124,7 @@ void apss_start_pwr_meas_read(ipc_msg_t* cmd, void* arg)
// APSS command to continue previous command
// rc = putscom_abs(SPIPSS_ADC_WDATA_REG, 0x0000000000000000);
regValue = 0x0000000000000000;
- rc = putscom_abs(SPIPSS_ADC_WDATA_REG, &regValue);
+ rc = putscom_abs(SPIPSS_ADC_WDATA_REG, regValue);
if(rc)
{
PK_TRACE("apss_start_pwr_meas_read: SPIPSS_ADC_WDATA_REG putscom failed. rc = 0x%08x",
@@ -137,7 +137,7 @@ void apss_start_pwr_meas_read(ipc_msg_t* cmd, void* arg)
// Start SPI Transaction
// rc = putscom_abs(SPIPSS_ADC_COMMAND_REG, 0x8000000000000000);
regValue = 0x8000000000000000;
- rc = putscom_abs(SPIPSS_ADC_COMMAND_REG, &regValue);
+ rc = putscom_abs(SPIPSS_ADC_COMMAND_REG, regValue);
if(rc)
{
@@ -311,6 +311,7 @@ void apss_complete_pwr_meas_read(ipc_msg_t* cmd, void* arg)
}
// SIMICS Verify: Check proper transfer to the OCC under simics
+/* @TODO - TEMP: APSS TOD register is not defined in simics yet. Commented out until implemented.
rc = getscom_abs(TOD_VALUE_REG, &args->meas_data[3]);
if(rc)
{
@@ -319,6 +320,7 @@ void apss_complete_pwr_meas_read(ipc_msg_t* cmd, void* arg)
apss_set_ffdc(&(args->error), TOD_VALUE_REG, APSS_RC_SCOM_GET_FAILED, rc);
break;
}
+*/
} while(0);
// send back a response, IPC success (even if ffdc/rc are non zeros)
diff --git a/src/occ_gpe0/apss_util.c b/src/occ_gpe0/apss_util.c
index cf210fc..2a78561 100644
--- a/src/occ_gpe0/apss_util.c
+++ b/src/occ_gpe0/apss_util.c
@@ -86,7 +86,7 @@ int wait_spi_completion(GpeErrorStruct *error, uint32_t reg, uint8_t timeout)
}
// sleep for 1 microsecond before retry
- pk_sleep(PK_MICROSECONDS(1));
+ busy_wait(1);
}
}
@@ -100,3 +100,32 @@ int wait_spi_completion(GpeErrorStruct *error, uint32_t reg, uint8_t timeout)
return rc;
}
+
+/*
+ * Function Specification:
+ *
+ * Name: busy_wait
+ *
+ * Description: a counting loop to simulate sleep calls, and is ISR safe.
+ *
+ * Inputs: t_microseconds: time to sleep in microseconds
+ *
+ * return: none
+ *
+ * End Function Specification
+ */
+
+// result based on busy_wait(1) calibration against pk_sleep(1)
+#define BUSY_LOOP_CONSTANT 71
+
+void busy_wait(uint32_t t_microseconds)
+{
+ int j;
+ volatile uint32_t i;
+// ppe42_mullw macro works fine, but compiler parameter settings seems broken, use nested loop instead
+// int loop = t * 100; // Assuming loop iteration takes 6 ppe cycles = 0.01 microseconds
+
+ for(j = 0; j < BUSY_LOOP_CONSTANT; j++)
+ for(i = 0; i < t_microseconds; i++);
+
+}
diff --git a/src/occ_gpe0/gpe0_main.c b/src/occ_gpe0/gpe0_main.c
index ada93fa..2777a70 100644
--- a/src/occ_gpe0/gpe0_main.c
+++ b/src/occ_gpe0/gpe0_main.c
@@ -51,110 +51,15 @@ IPC_MSGQ_CREATE(G_gpe0_test_msgq0);
IPC_MSGQ_MSG_CREATE(G_test_msg, IPC_ST_TEST_FUNC0, &G_gpe0_test_msgq0);
-// Continuously ping each OCC instance
+// Main thread of execution. Currently does nothing
void main_thread(void* arg)
{
- uint8_t instance;
- int rc;
- int func_id;
- ipc_msg_t *test_msg;
+ volatile uint64_t t_ticks = 0;
- PK_TRACE("thread started");
-
- PK_TRACE("Waiting for ping response from all instances");
- for(instance = 0; instance < OCCHW_MAX_INSTANCES; instance++)
- {
- // Wait for each instance (including self) to start accepting IPC commands
- do
- {
- pk_sleep(PK_MILLISECONDS(10));
- rc = ipc_ping(&G_ping_cmd, instance);
- }while(rc == IPC_RC_TARGET_BLOCKED);
-
- if(rc && rc != IPC_RC_TARGET_BLOCKED)
- {
- PK_TRACE("phase 1 ipc_ping(%u) failed with rc = 0x%08x", instance, rc);
- PK_TRACE_BIN("G_ping_cmd:", &G_ping_cmd, sizeof(G_ping_cmd));
- pk_halt();
- }
- PK_TRACE("Ping response received from instance(%d)", instance);
- }
-
- PK_TRACE("Starting infinite loop test");
while(1)
{
- for(instance = 0; instance < OCCHW_MAX_INSTANCES; instance++)
- {
- // Ping each instance (including ourself)
- rc = ipc_ping(&G_ping_cmd, instance);
- if(rc)
- {
- PK_TRACE("phase 2 ipc_ping(%u) failed with rc = 0x%08x", instance, rc);
- PK_TRACE_BIN("G_ping_cmd:", &G_ping_cmd, sizeof(G_ping_cmd));
- pk_halt();
- }
- }
-
- // Send an IPC_ST_TEST_FUNC0 message (to ourselves) if the message
- // isnt' already in-flight.
- if(ipc_is_free(&G_test_msg))
- {
- rc = ipc_send_cmd(&G_test_msg);
- if(rc)
- {
- pk_halt();
- }
- }
-
- // wait for a IPC_ST_TEST_FUNC0 command or response message to arrive
- rc = ipc_msgq_recv(&test_msg, &G_gpe0_test_msgq0, PK_MILLISECONDS(1));
- if(!rc)
- {
- //verify that the command message type is what we expected
- func_id = ipc_get_funcid(test_msg);
- if(func_id != IPC_ST_TEST_FUNC0)
- {
- //unexpected func id
- //(probably caused by a mismatch between function table
- // and function id ordering)
- rc = ipc_send_rsp(test_msg, IPC_RC_CMD_NOT_SUPPORTED);
- }
- else
- {
- //Is this a response to the message we sent to ourselves?
- if(ipc_is_a_response(test_msg))
- {
- //check that the remote end was successful
- if(ipc_get_rc(test_msg) != IPC_RC_SUCCESS)
- {
- pk_halt();
- }
- //free up the message for sending again
- ipc_free_msg(test_msg);
- }
- else
- {
- //successfully recieved the command message.
- //Send a response message back.
- rc = ipc_send_rsp(test_msg, IPC_RC_SUCCESS);
- }
- }
- if(rc)
- {
- //failed to send the response back
- pk_halt();
- }
- }
- else
- {
- //Unless it's a timeout, a non-zero rc is an error
- if(rc != IPC_RC_TIMEOUT)
- {
- //Failure encountered while waiting for a new message
- pk_halt();
- }
- }
- pk_sleep(PK_MILLISECONDS(1));
+ pk_sleep(PK_MICROSECONDS(250));
+ t_ticks++;
}
}
@@ -188,8 +93,9 @@ int main(int argc, char **argv)
pk_halt();
}
+
//Initialize the thread control block for G_main_thread
- pk_thread_create(&G_main_thread,
+ pk_thread_create(&G_main_thread,
(PkThreadRoutine)main_thread,
(void*)NULL,
(PkAddress)G_main_thread_stack,
@@ -206,6 +112,6 @@ int main(int argc, char **argv)
// Start running the highest priority thread.
// This function never returns
pk_start_threads();
-
+
return 0;
}
OpenPOWER on IntegriCloud