diff --git a/docs_src/docs/api_guide/components/position_sense/hdsl_exceptions_list.md b/docs_src/docs/api_guide/components/position_sense/hdsl_exceptions_list.md index 9c105d3..4a07901 100644 --- a/docs_src/docs/api_guide/components/position_sense/hdsl_exceptions_list.md +++ b/docs_src/docs/api_guide/components/position_sense/hdsl_exceptions_list.md @@ -159,4 +159,6 @@ Notable exceptions in TI HDSL Solution when compared with SICK HDSL MASTER IP Co 6. Reset values of registers are not same as SICK HDSL MASTER IP Core. 7. As registers are implemented using Data Memory of Programmable Real-Time Unit and Industrial Communication Subsystem (PRU-ICSS), the application has a read-write access for all registers. 8. When safe position is invalid (VPOS bit is set in EVENT_S), 0xFDFDFDFDFD value is not set in fast and safe position registers. +9. For long message offset, only 15-bit wide offset is supported. If offset is enabled, then master will always send 2 bytes of offset. + diff --git a/docs_src/docs/api_guide/components/position_sense/hdsl_registers_list.md b/docs_src/docs/api_guide/components/position_sense/hdsl_registers_list.md index 952ad3c..b18364f 100644 --- a/docs_src/docs/api_guide/components/position_sense/hdsl_registers_list.md +++ b/docs_src/docs/api_guide/components/position_sense/hdsl_registers_list.md @@ -984,7 +984,7 @@ TI HDSL Solution's register map is compatible with SICK HDSL MASTER IP Core rele Bits 9:8 of 10 bit address for a "long message" operation - PC_ADD_H + PC_ADD_L 0x29 Long message address (Low Byte) diff --git a/examples/position_sense/hdsl_diagnostic/hdsl_diagnostic.c b/examples/position_sense/hdsl_diagnostic/hdsl_diagnostic.c index b47e295..ae3818f 100644 --- a/examples/position_sense/hdsl_diagnostic/hdsl_diagnostic.c +++ b/examples/position_sense/hdsl_diagnostic/hdsl_diagnostic.c @@ -30,6 +30,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* ========================================================================== */ +/* Include Files */ +/* ========================================================================== */ + #include #include @@ -71,6 +75,10 @@ #include #include +/* ========================================================================== */ +/* Macros & Typedefs */ +/* ========================================================================== */ + #if (CONFIG_HDSL0_CHANNEL0 + CONFIG_HDSL0_CHANNEL1 > 1) #define HDSL_MULTI_CHANNEL #endif @@ -97,9 +105,12 @@ #define CTR_EN (1 << 3) #define MAX_WAIT 20000 -/*Timeout in micorseconds for short message read/write*/ +/*Timeout in micro-seconds for short message read/write*/ #define SHORT_MSG_TIMEOUT (1000) +/*Timeout in micro-seconds for long message read/write*/ +#define LONG_MSG_TIMEOUT (200000) + /*Register Addresses for Short Messages (Parameter Channel)*/ #define ENCODER_STATUS0_REG_ADDRESS (0x40) @@ -119,6 +130,70 @@ #define HDSL_MEMORY_TRACE_R5F_IRQ_NUM (CSLR_R5FSS0_CORE0_INTR_PRU_ICSSG0_PR1_HOST_INTR_PEND_3) #endif +/* ========================================================================== */ +/* Function Declarations */ +/* ========================================================================== */ + +#if !defined(HDSL_MULTI_CHANNEL) && defined(_DEBUG_) + +void App_udmaEventCb(Udma_EventHandle eventHandle, uint32_t eventType, void *appData); + +static void App_udmaTrpdInit(Udma_ChHandle chHandle, + uint8_t *trpdMem, + const void *destBuf, + const void *srcBuf, + uint32_t length); + +void udma_copy(uint8_t *srcBuf, uint8_t *destBuf, uint32_t length); + +static void HDSL_IsrFxn(); + +#ifndef HDSL_MULTI_CHANNEL +void traces_into_memory(HDSL_Handle hdslHandle); +#endif + +void sync_calculation(HDSL_Handle hdslHandle); + +void process_request(HDSL_Handle hdslHandle,int32_t menu); + +void hdsl_pruss_init(void); + +void hdsl_pruss_init_300m(void); + +void hdsl_pruss_load_run_fw_300m(HDSL_Handle hdslHandle); + +void hdsl_init(void); + +void hdsl_init_300m(void); + +void TC_read_pc_short_msg(HDSL_Handle hdslHandle); + +void TC_write_pc_short_msg(HDSL_Handle hdslHandle); + +static void display_menu(void); + +void direct_read_rid0_length4(HDSL_Handle hdslHandle); + +void direct_read_rid81_length8(HDSL_Handle hdslHandle); + +void direct_read_rid81_length2(HDSL_Handle hdslHandle); + +void indirect_write_rid0_length8_offset0(HDSL_Handle hdslHandle); + +void indirect_write_rid0_length8(HDSL_Handle hdslHandle); + +static int get_menu(void); + +#ifdef HDSL_AM64xE1_TRANSCEIVER +static void hdsl_i2c_io_expander(void *args); +#endif + +uint32_t read_encoder_resolution(HDSL_Handle hdslHandle); + +/* ========================================================================== */ +/* Global Variables */ +/* ========================================================================== */ + HDSL_Handle gHdslHandleCh0; HDSL_Handle gHdslHandleCh1; @@ -165,15 +240,10 @@ HwiP_Object gPRUHwiObject; uint8_t gUdmaTestTrpdMem[UDMA_TEST_TRPD_SIZE] __attribute__((aligned(UDMA_CACHELINE_ALIGNMENT))); #endif -#if !defined(HDSL_MULTI_CHANNEL) && defined(_DEBUG_) +/* ========================================================================== */ +/* Function Definitions */ +/* ========================================================================== */ -void App_udmaEventCb(Udma_EventHandle eventHandle, uint32_t eventType, void *appData); - -static void App_udmaTrpdInit(Udma_ChHandle chHandle, - uint8_t *trpdMem, - const void *destBuf, - const void *srcBuf, - uint32_t length); static void App_udmaTrpdInit(Udma_ChHandle chHandle, uint8_t *trpdMem, @@ -567,8 +637,8 @@ void process_request(HDSL_Handle hdslHandle,int32_t menu) case MENU_PC_SHORT_MSG_READ: TC_read_pc_short_msg(hdslHandle); break; - case MENU_DIRECT_READ_RID0_LENGTH8: - direct_read_rid0_length8(hdslHandle); + case MENU_DIRECT_READ_RID0_LENGTH4: + direct_read_rid0_length4(hdslHandle); break; case MENU_DIRECT_READ_RID81_LENGTH8: direct_read_rid81_length8(hdslHandle); @@ -765,6 +835,7 @@ void hdsl_init(void) HDSL_generate_memory_image(gHdslHandleCh0); } } + void hdsl_init_300m(void) { uint8_t ES; @@ -910,16 +981,16 @@ static void display_menu(void) DebugP_log("\r\n | %2d : RSSI |", MENU_RSSI); DebugP_log("\r\n | %2d : Parameter Channel Short Message Write |", MENU_PC_SHORT_MSG_WRITE); DebugP_log("\r\n | %2d : Parameter Channel Short Message Read |", MENU_PC_SHORT_MSG_READ); - DebugP_log("\r\n | %2d : Parameter Channel Long Message Read |", MENU_DIRECT_READ_RID0_LENGTH8); - DebugP_log("\r\n | Access on RID 0h, direct read access with length 8 |"); + DebugP_log("\r\n | %2d : Parameter Channel Long Message Read |", MENU_DIRECT_READ_RID0_LENGTH4); + DebugP_log("\r\n | Access on RID 0x0, direct read access with length 4 |"); DebugP_log("\r\n | %2d : Parameter Channel Long Message Read |", MENU_DIRECT_READ_RID81_LENGTH8); - DebugP_log("\r\n | Access on RID 81h, direct read access with length 8 |"); + DebugP_log("\r\n | Access on RID 0x81, direct read access with length 8 |"); DebugP_log("\r\n | %2d : Parameter Channel Long Message Read |", MENU_DIRECT_READ_RID81_LENGTH2); - DebugP_log("\r\n | Access on RID 81h, direct read access with length 2 |"); + DebugP_log("\r\n | Access on RID 0x81, direct read access with length 2 and offset 3 |"); DebugP_log("\r\n | %2d : Parameter Channel Long Message Write |", MENU_INDIRECT_WRITE_RID0_LENGTH8_OFFSET0); - DebugP_log("\r\n | Access on RID 0h, indirect write, length 8, with offset 0 |"); + DebugP_log("\r\n | Access on RID 0x0, indirect write, length 8, with offset 0 |"); DebugP_log("\r\n | %2d : Parameter Channel Long Message Write |", MENU_INDIRECT_WRITE_RID0_LENGTH8); - DebugP_log("\r\n | Access on RID 0h; indirect write, length 8, without offset value |"); + DebugP_log("\r\n | Access on RID 0x0; indirect write, length 8, without offset value |"); #if !defined(HDSL_MULTI_CHANNEL) && defined(_DEBUG_) DebugP_log("\r\n | %2d : HDSL registers into Memory |", MENU_HDSL_REG_INTO_MEMORY); #endif @@ -927,242 +998,246 @@ static void display_menu(void) DebugP_log("\r\n Enter value: "); } -void direct_read_rid0_length8(HDSL_Handle hdslHandle) +void direct_read_rid0_length4(HDSL_Handle hdslHandle) { - uint8_t dir = 0x01; + int32_t status = SystemP_FAILURE; - gPc_addrh = 0xec; - gPc_addrl = 0x00; - gPc_offh = 0x80; - gPc_offl = 0x00; + DebugP_log("\r\n Parameter channel long message read : RID 0, Length 4"); - HDSL_set_pc_addr(hdslHandle, gPc_addrh, gPc_addrl, gPc_offh, gPc_offl); + /* Set the parameter channel buffers to 0xff */ + HDSL_write_pc_buffer(hdslHandle, 0, 0xff); + HDSL_write_pc_buffer(hdslHandle, 1, 0xff); + HDSL_write_pc_buffer(hdslHandle, 2, 0xff); + HDSL_write_pc_buffer(hdslHandle, 3, 0xff); - HDSL_set_pc_ctrl(hdslHandle,dir); + status = HDSL_read_pc_long_msg(hdslHandle, 0, HDSL_LONG_MSG_ADDR_WITHOUT_OFFSET, HDSL_LONG_MSG_ADDR_DIRECT, HDSL_LONG_MSG_LENGTH_4, 0, LONG_MSG_TIMEOUT); - ClockP_sleep(1); - - gPc_buf0 = HDSL_read_pc_buffer(hdslHandle,0); - - if(gPc_buf0 == 82) + if(SystemP_SUCCESS != status) { - gPc_buf1 = HDSL_read_pc_buffer(hdslHandle,1); - if(gPc_buf1 == 79) + DebugP_log("\r\n FAIL: HDSL_read_pc_long_msg() did not return success"); + return; + } + + gPc_buf0 = HDSL_read_pc_buffer(hdslHandle, 0); + + if(gPc_buf0 == 'R') + { + gPc_buf1 = HDSL_read_pc_buffer(hdslHandle, 1); + if(gPc_buf1 == 'O') { - gPc_buf2 = HDSL_read_pc_buffer(hdslHandle,2); - if(gPc_buf2 == 79) + gPc_buf2 = HDSL_read_pc_buffer(hdslHandle, 2); + if(gPc_buf2 == 'O') { - gPc_buf3 = HDSL_read_pc_buffer(hdslHandle,3); - if(gPc_buf3 == 84) + gPc_buf3 = HDSL_read_pc_buffer(hdslHandle, 3); + if(gPc_buf3 == 'T') { - DebugP_log("\r\n PASS"); + DebugP_log("\r\n PASS : Read \"ROOT\""); } else { - DebugP_log("\r\n FAIL: gPc_buf3 != T = %u", gPc_buf3); + DebugP_log("\r\n FAIL: PC_BUFFER3 != T (It is %u)", gPc_buf3); } } else { - DebugP_log("\r\n FAIL: gPc_buf2 != O = %u", gPc_buf2); + DebugP_log("\r\n FAIL: PC_BUFFER2 != O (It is %u)", gPc_buf2); } } else { - DebugP_log("\r\n FAIL: gPc_buf1 != O = %u", gPc_buf1); + DebugP_log("\r\n FAIL: PC_BUFFER1 != O (It is %u)", gPc_buf1); } } else { - DebugP_log("\r\n FAIL: gPc_buf0 != R = %u", gPc_buf0); + DebugP_log("\r\n FAIL: PC_BUFFER0 != R (It is %u)", gPc_buf0); } } -void direct_read_rid81_length8(HDSL_Handle hdslHandle) +void direct_read_rid81_length8(HDSL_Handle hdslHandle) { - uint8_t dir = 0x01; - gPc_addrh = 0xec; - gPc_addrl = 0x81; - gPc_offh = 0x80; - gPc_offl = 0x00; + int32_t status = SystemP_FAILURE; - HDSL_set_pc_addr( hdslHandle,gPc_addrh, gPc_addrl, gPc_offh, gPc_offl); + DebugP_log("\r\n Parameter channel long message read : RID 0x81, Length 8"); - HDSL_set_pc_ctrl(hdslHandle,dir); + /* Set the parameter channel buffers to 0xff */ + HDSL_write_pc_buffer(hdslHandle, 0, 0xff); + HDSL_write_pc_buffer(hdslHandle, 1, 0xff); + HDSL_write_pc_buffer(hdslHandle, 2, 0xff); + HDSL_write_pc_buffer(hdslHandle, 3, 0xff); + HDSL_write_pc_buffer(hdslHandle, 4, 0xff); + HDSL_write_pc_buffer(hdslHandle, 5, 0xff); + HDSL_write_pc_buffer(hdslHandle, 6, 0xff); + HDSL_write_pc_buffer(hdslHandle, 7, 0xff); - ClockP_sleep(1); + status = HDSL_read_pc_long_msg(hdslHandle, 0x81, HDSL_LONG_MSG_ADDR_WITHOUT_OFFSET, HDSL_LONG_MSG_ADDR_DIRECT, HDSL_LONG_MSG_LENGTH_8, 0, LONG_MSG_TIMEOUT); - gPc_buf0 = HDSL_read_pc_buffer(hdslHandle,0); - if(gPc_buf0 == 82) + if(SystemP_SUCCESS != status) { - gPc_buf1 = HDSL_read_pc_buffer(hdslHandle,1); - if(gPc_buf1 == 69) + DebugP_log("\r\n FAIL: HDSL_read_pc_long_msg() did not return success"); + return; + } + + gPc_buf0 = HDSL_read_pc_buffer(hdslHandle, 0); + if(gPc_buf0 == 'R') + { + gPc_buf1 = HDSL_read_pc_buffer(hdslHandle, 1); + if(gPc_buf1 == 'E') { - gPc_buf2 = HDSL_read_pc_buffer(hdslHandle,2); - if(gPc_buf2 == 83) + gPc_buf2 = HDSL_read_pc_buffer(hdslHandle, 2); + if(gPc_buf2 == 'S') { - gPc_buf3 = HDSL_read_pc_buffer(hdslHandle,3); - if(gPc_buf3 == 79) + gPc_buf3 = HDSL_read_pc_buffer(hdslHandle, 3); + if(gPc_buf3 == 'O') { - gPc_buf4 = HDSL_read_pc_buffer(hdslHandle,4); - if(gPc_buf4 == 76) + gPc_buf4 = HDSL_read_pc_buffer(hdslHandle, 4); + if(gPc_buf4 == 'L') { - gPc_buf5 = HDSL_read_pc_buffer(hdslHandle,5); - if(gPc_buf5 == 85) + gPc_buf5 = HDSL_read_pc_buffer(hdslHandle, 5); + if(gPc_buf5 == 'U') { - gPc_buf6 = HDSL_read_pc_buffer(hdslHandle,6); - if(gPc_buf6 == 84) + gPc_buf6 = HDSL_read_pc_buffer(hdslHandle, 6); + if(gPc_buf6 == 'T') { - gPc_buf7 = HDSL_read_pc_buffer(hdslHandle,7); - if(gPc_buf7 == 78) + gPc_buf7 = HDSL_read_pc_buffer(hdslHandle, 7); + if(gPc_buf7 == 'N') { - DebugP_log("\r\n PASS "); + DebugP_log("\r\n PASS : Read \"RESOLUTN\""); } else { - DebugP_log("\r\n FAIL: gPc_buf7 != N ", gPc_buf7); + DebugP_log("\r\n FAIL: PC_BUFFER7 != N (It is %u)", gPc_buf7); } } else { - DebugP_log("\r\n FAIL: gPc_buf6 != T ", gPc_buf6); + DebugP_log("\r\n FAIL: PC_BUFFER6 != T (It is %u)", gPc_buf6); } } else { - DebugP_log("\r\n FAIL: gPc_buf5 != U ", gPc_buf5); + DebugP_log("\r\n FAIL: PC_BUFFER5 != U (It is %u)", gPc_buf5); } } else { - DebugP_log("\r\n FAIL: gPc_buf4 != L ", gPc_buf4); + DebugP_log("\r\n FAIL: PC_BUFFER4 != L (It is %u)", gPc_buf4); } } else { - DebugP_log("\r\n FAIL: gPc_buf3 != O ", gPc_buf3); + DebugP_log("\r\n FAIL: PC_BUFFER3 != O (It is %u)", gPc_buf3); } } else { - DebugP_log("\r\n FAIL: gPc_buf2 != S = %u", gPc_buf2); + DebugP_log("\r\n FAIL: PC_BUFFER2 != S (It is %u)", gPc_buf2); } } else { - DebugP_log("\r\n FAIL: gPc_buf1 != E = %u", gPc_buf1); + DebugP_log("\r\n FAIL: PC_BUFFER1 != E (It is %u)", gPc_buf1); } } else { - DebugP_log("\r\n FAIL: gPc_buf0 != R = %u", gPc_buf0); + DebugP_log("\r\n FAIL: PC_BUFFER0 != R (It is %u)", gPc_buf0); } } -void direct_read_rid81_length2(HDSL_Handle hdslHandle) +void direct_read_rid81_length2(HDSL_Handle hdslHandle) { - uint8_t dir = 0x01; + int32_t status = SystemP_FAILURE; - gPc_addrh = 0xe4; - gPc_addrl = 0x81; - gPc_offh = 0x80; - gPc_offl = 0x03; + DebugP_log("\r\n Parameter channel long message read : RID 0x81, Offset 3, Length 2"); - HDSL_set_pc_addr(hdslHandle, gPc_addrh, gPc_addrl, gPc_offh, gPc_offl); + /* Set the parameter channel buffers to 0xaa */ + HDSL_write_pc_buffer(hdslHandle, 0, 0xaa); + HDSL_write_pc_buffer(hdslHandle, 1, 0xaa); - HDSL_set_pc_ctrl(hdslHandle,dir); + status = HDSL_read_pc_long_msg(hdslHandle, 0x81, HDSL_LONG_MSG_ADDR_WITH_OFFSET, HDSL_LONG_MSG_ADDR_DIRECT, HDSL_LONG_MSG_LENGTH_2, 3, LONG_MSG_TIMEOUT); - ClockP_sleep(1); + if(SystemP_SUCCESS != status) + { + DebugP_log("\r\n FAIL: HDSL_read_pc_long_msg() did not return success"); + return; + } - gPc_buf0 = HDSL_read_pc_buffer(hdslHandle,0); + gPc_buf0 = HDSL_read_pc_buffer(hdslHandle, 0); if(gPc_buf0 == 0x00) { - gPc_buf1 = HDSL_read_pc_buffer(hdslHandle,1); + gPc_buf1 = HDSL_read_pc_buffer(hdslHandle, 1); if(gPc_buf1 == 0x0f) { - DebugP_log("\r\n PASS "); - + DebugP_log("\r\n PASS : Read 15"); } else { - DebugP_log("\r\n FAIL: gPc_buf1 != 0x0f = %u", gPc_buf1); + DebugP_log("\r\n FAIL: PC_BUFFER1 != 0x0f (It is %u)", gPc_buf1); } } else { - DebugP_log("\r\n FAIL: gPc_buf0 != 0x00 = %u", gPc_buf0); + DebugP_log("\r\n FAIL: PC_BUFFER0 != 0x00 (It is %u)", gPc_buf0); } } -void indirect_write_rid0_length8_offset0(HDSL_Handle hdslHandle) +void indirect_write_rid0_length8_offset0(HDSL_Handle hdslHandle) { - uint8_t dir = 0x01; + DebugP_log("\r\n Parameter channel long message write : RID 0x0, Offset 0, Length 8"); - gPc_addrh = 0xbc; - gPc_addrl = 0x00; - gPc_offh = 0x80; - gPc_offl = 0x00; + HDSL_write_pc_long_msg(hdslHandle, 0x0, HDSL_LONG_MSG_ADDR_WITH_OFFSET, HDSL_LONG_MSG_ADDR_INDIRECT, HDSL_LONG_MSG_LENGTH_8, 0, LONG_MSG_TIMEOUT); - HDSL_set_pc_addr(hdslHandle, gPc_addrh, gPc_addrl, gPc_offh, gPc_offl); + /*FIXME: Add error check*/ - HDSL_set_pc_ctrl(hdslHandle,dir); - - ClockP_sleep(1); - - gPc_buf0 = HDSL_read_pc_buffer(hdslHandle,0); + gPc_buf0 = HDSL_read_pc_buffer(hdslHandle, 0); if(gPc_buf0 == 0x41) { - gPc_buf1 = HDSL_read_pc_buffer(hdslHandle,1); + gPc_buf1 = HDSL_read_pc_buffer(hdslHandle, 1); if(gPc_buf1 == 0x10) { DebugP_log("\r\n PASS "); } else { - DebugP_log("\r\n FAIL: gPc_buf1 != 0x10 = %u", gPc_buf1); + DebugP_log("\r\n FAIL: PC_BUFFER1 != 0x10 (It is %u)", gPc_buf1); } } else { - DebugP_log("\r\n FAIL: gPc_buf0 != 0x41 = %u", gPc_buf0); + DebugP_log("\r\n FAIL: PC_BUFFER0 != 0x41 (It is %u)", gPc_buf0); } } -void indirect_write_rid0_length8(HDSL_Handle hdslHandle) +void indirect_write_rid0_length8(HDSL_Handle hdslHandle) { - uint8_t dir = 0x01; - gPc_addrh = 0x9c; - gPc_addrl = 0x00; - gPc_offh = 0x80; - gPc_offl = 0x00; + DebugP_log("\r\n Parameter channel long message write : RID 0x0, Length 8"); - HDSL_set_pc_addr(hdslHandle, gPc_addrh, gPc_addrl, gPc_offh, gPc_offl); + HDSL_write_pc_long_msg(hdslHandle, 0x0, HDSL_LONG_MSG_ADDR_WITHOUT_OFFSET, HDSL_LONG_MSG_ADDR_INDIRECT, HDSL_LONG_MSG_LENGTH_8, 0, LONG_MSG_TIMEOUT); - HDSL_set_pc_ctrl(hdslHandle,dir); + /*FIXME: Add error check*/ - ClockP_sleep(1); - - gPc_buf0 = HDSL_read_pc_buffer(hdslHandle,0); + gPc_buf0 = HDSL_read_pc_buffer(hdslHandle, 0); if(gPc_buf0 == 0x41) { - gPc_buf1 = HDSL_read_pc_buffer(hdslHandle,1); + gPc_buf1 = HDSL_read_pc_buffer(hdslHandle, 1); if(gPc_buf1 == 0x10) { DebugP_log("\r\n PASS "); } else { - DebugP_log("\r\n FAIL: gPc_buf1 != 0x10 = %u", gPc_buf1); + DebugP_log("\r\n FAIL: PC_BUFFER1 != 0x10 (It is %u)", gPc_buf1); } } else { - DebugP_log("\r\n FAIL: gPc_buf0 != 0x41 = %u", gPc_buf0); + DebugP_log("\r\n FAIL: PC_BUFFER0 != 0x41 (It is %u)", gPc_buf0); } } @@ -1240,6 +1315,34 @@ static void hdsl_i2c_io_expander(void *args) } #endif +uint32_t read_encoder_resolution(HDSL_Handle hdslHandle) +{ + int32_t status = SystemP_FAILURE; + uint32_t resolution = 0; + + /* Set the parameter channel buffers to 0xff */ + HDSL_write_pc_buffer(hdslHandle, 0, 0xff); + HDSL_write_pc_buffer(hdslHandle, 1, 0xff); + HDSL_write_pc_buffer(hdslHandle, 2, 0xff); + HDSL_write_pc_buffer(hdslHandle, 3, 0xff); + + /* Parameter channel long message read with RID 0x81, Offset 5, Length 4 + * for reading resolution */ + + status = HDSL_read_pc_long_msg(hdslHandle, 0x81, HDSL_LONG_MSG_ADDR_WITHOUT_OFFSET, HDSL_LONG_MSG_ADDR_INDIRECT, HDSL_LONG_MSG_LENGTH_4, 0, LONG_MSG_TIMEOUT); + + DebugP_assert(SystemP_SUCCESS == status); + + gPc_buf0 = HDSL_read_pc_buffer(hdslHandle, 0); + gPc_buf1 = HDSL_read_pc_buffer(hdslHandle, 1); + gPc_buf2 = HDSL_read_pc_buffer(hdslHandle, 2); + gPc_buf3 = HDSL_read_pc_buffer(hdslHandle, 3); + + resolution = log2((gPc_buf0 << 24) | (gPc_buf1 << 16) | (gPc_buf2 << 8) | (gPc_buf3)); + + return resolution; +} + void hdsl_diagnostic_main(void *arg) { uint32_t val, acc_bits, pos_bits; @@ -1328,23 +1431,24 @@ void hdsl_diagnostic_main(void *arg) pos_bits += acc_bits; DebugP_log("\r\n | Encoder ID: 0x%x", val); DebugP_log( "("); - DebugP_log( "Acceleration bits: %u ,", acc_bits); + DebugP_log( "Acceleration bits: %u, ", acc_bits); DebugP_log( "Position bits: %u,", pos_bits); DebugP_log( "%s", val & 0x400 ? " Bipolar position" : " Unipolar position"); DebugP_log(")|"); - DebugP_log("\r\n |-------------------------------------------------------------------------------|"); - DebugP_log("\r\n Enter single turn bits: "); - if((DebugP_scanf("%d\n", &gHdslHandleCh0->res) < 0) || gHdslHandleCh0->res > pos_bits) - { - DebugP_log( "\r| WARNING: invalid single turn bits, assuming single turn encoder\n"); - gHdslHandleCh0->res = pos_bits; - } + gHdslHandleCh0->res = read_encoder_resolution(gHdslHandleCh0); gHdslHandleCh0->multi_turn = pos_bits - gHdslHandleCh0->res; gHdslHandleCh0->mask = pow(2, gHdslHandleCh0->res) - 1; - if (gHdslHandleCh0->multi_turn) + if(gHdslHandleCh0->multi_turn) { - DebugP_log( "\r\n Multi turn bits: %u\n", gHdslHandleCh0->multi_turn); + DebugP_log( "\r\n | Single-turn bits: %u, Multi-turn bits: %u |", pos_bits - gHdslHandleCh0->multi_turn, gHdslHandleCh0->multi_turn); } + else + { + DebugP_log( "\r\n | Single-turn bits: %u |", pos_bits); + } + DebugP_log("\r\n |-------------------------------------------------------------------------------|"); + + #endif #if (CONFIG_HDSL0_CHANNEL1==1) @@ -1379,24 +1483,22 @@ void hdsl_diagnostic_main(void *arg) pos_bits += acc_bits; DebugP_log("\r\n | Encoder ID: 0x%x", val); DebugP_log( "("); - DebugP_log( "Acceleration bits: %u ,", acc_bits); + DebugP_log( "Acceleration bits: %u, ", acc_bits); DebugP_log( "Position bits: %u,", pos_bits); DebugP_log( "%s", val & 0x400 ? " Bipolar position" : " Unipolar position"); DebugP_log(")|"); - DebugP_log("\r\n |-------------------------------------------------------------------------------|"); - - DebugP_log("\r\n Enter single turn bits: "); - if((DebugP_scanf("%d\n", &gHdslHandleCh1->res) < 0) || gHdslHandleCh1->res > pos_bits) - { - DebugP_log( "\r| WARNING: invalid single turn bits, assuming single turn encoder\n"); - gHdslHandleCh1->res = pos_bits; - } + gHdslHandleCh1->res = read_encoder_resolution(gHdslHandleCh1); gHdslHandleCh1->multi_turn = pos_bits - gHdslHandleCh1->res; gHdslHandleCh1->mask = pow(2, gHdslHandleCh1->res) - 1; - if (gHdslHandleCh1->multi_turn) + if(gHdslHandleCh0->multi_turn) { - DebugP_log( "\r\n Multi turn bits: %u\n", gHdslHandleCh1->multi_turn); + DebugP_log( "\r\n | Single-turn bits: %u, Multi-turn bits: %u |", pos_bits - gHdslHandleCh1->multi_turn, gHdslHandleCh1->multi_turn); } + else + { + DebugP_log( "\r\n | Single-turn bits: %u |", pos_bits); + } + DebugP_log("\r\n |-------------------------------------------------------------------------------|"); #endif while(1) diff --git a/examples/position_sense/hdsl_diagnostic/hdsl_diagnostic.h b/examples/position_sense/hdsl_diagnostic/hdsl_diagnostic.h index ab47291..a9821bd 100644 --- a/examples/position_sense/hdsl_diagnostic/hdsl_diagnostic.h +++ b/examples/position_sense/hdsl_diagnostic/hdsl_diagnostic.h @@ -56,26 +56,6 @@ extern "C" { /* UDMA TR packet descriptor memory size - with one TR */ #define UDMA_TEST_TRPD_SIZE (UDMA_GET_TRPD_TR15_SIZE(1U)) -/* ISR for v-frame-reception */ -static void HDSL_IsrFxn(void); -void TC_read_pc_short_msg(); -void TC_write_pc_short_msg(); - -#ifndef HDSL_MULTI_CHANNEL -/* - * @brief It will test copy of traces into memory - * \n Here user will decide how many copies of HDSL_Interface_Register - * \n will be copied into memory - */ -void traces_into_memory(); -#endif - -void direct_read_rid0_length8(); -void direct_read_rid81_length8(); -void direct_read_rid81_length2(); -void indirect_write_rid0_length8(); -void indirect_write_rid0_length8_offset0(); - #ifdef __cplusplus } #endif diff --git a/source/position_sense/hdsl/driver/hdsl_drv.c b/source/position_sense/hdsl/driver/hdsl_drv.c index dbde6a1..95dbf63 100644 --- a/source/position_sense/hdsl/driver/hdsl_drv.c +++ b/source/position_sense/hdsl/driver/hdsl_drv.c @@ -34,6 +34,27 @@ #include #include +#define ONLINE_STATUS_1_L_FRES (1<<0) +#define ONLINE_STATUS_D_L_FREL (1) + +#define PC_ADD_H_LONG_MSG_ENABLE (1<<7) +#define PC_ADD_H_LONG_MSG_WRITE (0<<6) +#define PC_ADD_H_LONG_MSG_READ (1<<6) +#define PC_ADD_H_LONG_MSG_ERROR (1<<5) +#define PC_ADD_H_OFFSET_EN_SHIFT (5) +#define PC_ADD_H_ADDR_TYPE_SHIFT (4) +#define PC_ADD_H_LENGTH_SHIFT (2) +#define PC_ADD_H_ADDR_HIGH_MASK (0x0300) + +#define PC_ADD_L_ADDR_LOW_MASK (0x00FF) + +#define PC_OFF_H_LONG_MSG_ENABLE (1<<7) +#define PC_OFF_H_OFFSET_HIGH_MASK (0x7F00) + +#define PC_OFF_L_OFFSET_LOW_MASK (0x00FF) + +#define PC_CTRL_ENABLE (0x01) + /* Should move the below to sysconfig generated code */ HDSL_Config hdslConfig0; HDSL_Config hdslConfig1; @@ -309,52 +330,228 @@ int32_t HDSL_read_pc_short_msg(HDSL_Handle hdslHandle,uint8_t addr, uint8_t *dat return SystemP_SUCCESS; } +int32_t HDSL_write_pc_long_msg(HDSL_Handle hdslHandle, uint16_t addr, uint8_t offsetEnable, uint8_t addrType, uint8_t length, uint16_t offset, uint64_t timeout) +{ + uint64_t end; + end = ClockP_getTimeUsec() + timeout; + + while(!(hdslHandle->hdslInterface->ONLINE_STATUS_D_L & (1< end) + { + return SystemP_TIMEOUT; + } + } + + /* + Setting PC_ADD_L + Bits 7:0 contain bits 7:0 of 10 bit address for long message + */ + hdslHandle->hdslInterface->PC_ADD_L = (addr & PC_ADD_L_ADDR_LOW_MASK); + + /* + Setting PC_ADD_H + Bit 7 should always be set for long message + Bit 6 is unset for write operation + Bit 5 is to enable/disable offset + Bit 4 is to select direct/indirect addressing + Bits 3:2 define the length of the message + Bits 1:0 contain bits 9:8 of 10 bit address for long message + */ + hdslHandle->hdslInterface->PC_ADD_H = (PC_ADD_H_LONG_MSG_ENABLE) | + (PC_ADD_H_LONG_MSG_WRITE) | + (offsetEnable << PC_ADD_H_OFFSET_EN_SHIFT) | + (addrType << PC_ADD_H_ADDR_TYPE_SHIFT) | + (length << PC_ADD_H_LENGTH_SHIFT) | + ((addr & PC_ADD_H_ADDR_HIGH_MASK) >> 8); + + /* + Setting PC_OFF_L + Bits 7:0 contain bits 7:0 of 15 bit offset value + */ + hdslHandle->hdslInterface->PC_OFF_L = (offset & PC_OFF_L_OFFSET_LOW_MASK); + + /* + Setting PC_OFF_H + Bit 7 should always be set for long message + Bits 6:0 contain bits 14:8 of 15 bit offset value + */ + hdslHandle->hdslInterface->PC_OFF_H = (PC_OFF_H_LONG_MSG_ENABLE) | + ((offset & PC_OFF_H_OFFSET_HIGH_MASK) >> 8); + + /* Setting PC_CTRL */ + hdslHandle->hdslInterface->PC_CTRL = PC_CTRL_ENABLE; + + while((hdslHandle->hdslInterface->ONLINE_STATUS_D_L & (1< end) + { + return SystemP_TIMEOUT; + } + } + + while(!(hdslHandle->hdslInterface->ONLINE_STATUS_D_L & (1< end) + { + return SystemP_TIMEOUT; + } + } + + /* Checking for error */ + if(hdslHandle->hdslInterface->PC_ADD_H & PC_ADD_H_LONG_MSG_ERROR) + { + return SystemP_FAILURE; + } + + return SystemP_SUCCESS; +} + +int32_t HDSL_read_pc_long_msg(HDSL_Handle hdslHandle, uint16_t addr, uint8_t offsetEnable, uint8_t addrType, uint8_t length, uint16_t offset, uint64_t timeout) +{ + uint64_t end; + end = ClockP_getTimeUsec() + timeout; + + while(!(hdslHandle->hdslInterface->ONLINE_STATUS_D_L & (1< end) + { + return SystemP_TIMEOUT; + } + } + + /* + Setting PC_ADD_L + Bits 7:0 contain bits 7:0 of 10 bit address for long message + */ + hdslHandle->hdslInterface->PC_ADD_L = (addr & PC_ADD_L_ADDR_LOW_MASK); + + /* + Setting PC_ADD_H + Bit 7 should always be set for long message + Bit 6 is set for read operation + Bit 5 is to enable/disable offset + Bit 4 is to select direct/indirect addressing + Bits 3:2 define the length of the message + Bits 1:0 contain bits 9:8 of 10 bit address for long message + */ + hdslHandle->hdslInterface->PC_ADD_H = (PC_ADD_H_LONG_MSG_ENABLE) | + (PC_ADD_H_LONG_MSG_READ) | + (offsetEnable << PC_ADD_H_OFFSET_EN_SHIFT) | + (addrType << PC_ADD_H_ADDR_TYPE_SHIFT) | + (length << PC_ADD_H_LENGTH_SHIFT) | + ((addr & PC_ADD_H_ADDR_HIGH_MASK) >> 8); + + /* + Setting PC_OFF_L + Bits 7:0 contain bits 7:0 of 15 bit offset value + */ + hdslHandle->hdslInterface->PC_OFF_L = (offset & PC_OFF_L_OFFSET_LOW_MASK); + + /* + Setting PC_OFF_H + Bit 7 should always be set for long message + Bits 6:0 contain bits 14:8 of 15 bit offset value + */ + hdslHandle->hdslInterface->PC_OFF_H = (PC_OFF_H_LONG_MSG_ENABLE) | + ((offset & PC_OFF_H_OFFSET_HIGH_MASK) >> 8); + + /* Setting PC_CTRL */ + hdslHandle->hdslInterface->PC_CTRL = PC_CTRL_ENABLE; + + while((hdslHandle->hdslInterface->ONLINE_STATUS_D_L & (1< end) + { + return SystemP_TIMEOUT; + } + } + + while(!(hdslHandle->hdslInterface->ONLINE_STATUS_D_L & (1< end) + { + return SystemP_TIMEOUT; + } + } + + /* Checking for error */ + + if(hdslHandle->hdslInterface->PC_ADD_H & PC_ADD_H_LONG_MSG_ERROR) + { + return SystemP_FAILURE; + } + + return SystemP_SUCCESS; +} + +void HDSL_write_pc_buffer(HDSL_Handle hdslHandle, uint8_t buff_off, uint8_t data) +{ + switch(buff_off) + { + case 0: + hdslHandle->hdslInterface->PC_BUFFER0 = data; + break; + case 1: + hdslHandle->hdslInterface->PC_BUFFER1 = data; + break; + case 2: + hdslHandle->hdslInterface->PC_BUFFER2 = data; + break; + case 3: + hdslHandle->hdslInterface->PC_BUFFER3 = data; + break; + case 4: + hdslHandle->hdslInterface->PC_BUFFER4 = data; + break; + case 5: + hdslHandle->hdslInterface->PC_BUFFER5 = data; + break; + case 6: + hdslHandle->hdslInterface->PC_BUFFER6 = data; + break; + case 7: + hdslHandle->hdslInterface->PC_BUFFER7 = data; + break; + default: + break; + } +} + uint8_t HDSL_read_pc_buffer(HDSL_Handle hdslHandle, uint8_t buff_off) { switch(buff_off) { - case 0: - return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER0); - break; - case 1: - return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER1); - break; - case 2: - return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER2); - break; - case 3: - return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER3); - break; - case 4: - return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER4); - break; - case 5: - return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER5); - break; - case 6: - return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER6); - break; - case 7: - return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER7); - break; - default: - return 0; - break; + case 0: + return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER0); + break; + case 1: + return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER1); + break; + case 2: + return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER2); + break; + case 3: + return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER3); + break; + case 4: + return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER4); + break; + case 5: + return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER5); + break; + case 6: + return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER6); + break; + case 7: + return (uint8_t) (hdslHandle->hdslInterface->PC_BUFFER7); + break; + default: + return 0; + break; } } -void HDSL_write_pc_buffer(HDSL_Handle hdslHandle, uint8_t pc_buf0, uint8_t pc_buf1, uint8_t pc_buf2, uint8_t pc_buf3, uint8_t pc_buf4, uint8_t pc_buf5, uint8_t pc_buf6, uint8_t pc_buf7) -{ - hdslHandle->hdslInterface->PC_BUFFER0 = pc_buf0; - hdslHandle->hdslInterface->PC_BUFFER1 = pc_buf1; - hdslHandle->hdslInterface->PC_BUFFER2 = pc_buf2; - hdslHandle->hdslInterface->PC_BUFFER3 = pc_buf3; - hdslHandle->hdslInterface->PC_BUFFER4 = pc_buf4; - hdslHandle->hdslInterface->PC_BUFFER5 = pc_buf5; - hdslHandle->hdslInterface->PC_BUFFER6 = pc_buf6; - hdslHandle->hdslInterface->PC_BUFFER7 = pc_buf7; -} - uint8_t HDSL_get_sync_ctrl(HDSL_Handle hdslHandle) { return (uint8_t) (hdslHandle->hdslInterface->SYNC_CTRL); diff --git a/source/position_sense/hdsl/firmware/datalink.asm b/source/position_sense/hdsl/firmware/datalink.asm index 789d0a3..6380a16 100644 --- a/source/position_sense/hdsl/firmware/datalink.asm +++ b/source/position_sense/hdsl/firmware/datalink.asm @@ -116,7 +116,7 @@ datalink_wait_vsynch: lbco ®_TMP0, MASTER_REGS_CONST, EVENT_S, 2 set REG_TMP0.b0, REG_TMP0.b0, EVENT_S_FRES ;save events - sbco ®_TMP0.w0, MASTER_REGS_CONST, EVENT_S, 1 + sbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 1 qbbc update_events_no_int0, REG_TMP0.b1, EVENT_S_FRES ; generate interrupt ldi r31.w0, PRU0_ARM_IRQ4 @@ -1470,23 +1470,23 @@ is_val_FC: qba adjustment_done is_val_F8: qbne is_val_F0, EXTRA_EDGE_SELF, 0xF8 - sub REG_TMP0, REG_TMP0, 12 + sub REG_TMP0, REG_TMP0, 12 qba adjustment_done is_val_F0: qbne is_val_E0, EXTRA_EDGE_SELF, 0xF0 - sub REG_TMP0, REG_TMP0, 16 + sub REG_TMP0, REG_TMP0, 16 qba adjustment_done is_val_E0: qbne is_val_C0, EXTRA_EDGE_SELF, 0xE0 - sub REG_TMP0, REG_TMP0, 20 + sub REG_TMP0, REG_TMP0, 20 qba adjustment_done is_val_C0: qbne is_val_80, EXTRA_EDGE_SELF, 0xC0 - sub REG_TMP0, REG_TMP0, 24 + sub REG_TMP0, REG_TMP0, 24 qba adjustment_done is_val_80: qbne adjustment_done,EXTRA_EDGE_SELF, 0x80 - sub REG_TMP0, REG_TMP0, 28 + sub REG_TMP0, REG_TMP0, 28 qba adjustment_done adjustment_done: sbco ®_TMP0, MASTER_REGS_CONST, EXTRA_EDGE_TIMESTAMP, 4 @@ -1570,7 +1570,6 @@ log_done1: ;HINT: we have processing time here (~168 cycles) ;check if we reset protocol lbco &FIFO_L, MASTER_REGS_CONST, SYS_CTRL, 1 -;ERROR: qbbc datalink_abort2 is not working, though no compiler error qbbc SYS_CTRL_PRST_cleared,FIFO_L, SYS_CTRL_PRST jmp No_long_short_msg SYS_CTRL_PRST_cleared: @@ -1879,31 +1878,6 @@ datalink_abort_no_wait: lbco ®_TMP0.b0, MASTER_REGS_CONST, NUM_RESETS, 1 add REG_TMP0.b0, REG_TMP0.b0, 1 sbco ®_TMP0.b0, MASTER_REGS_CONST, NUM_RESETS, 1 -; Set EVENT_PRST in EVENT register - lbco ®_TMP0, MASTER_REGS_CONST, EVENT_H, 4 - set REG_TMP0.w0, REG_TMP0.w0, EVENT_PRST -;save events - sbco ®_TMP0.w0, MASTER_REGS_CONST, EVENT_H, 2 - qbbc update_events_no_int2, REG_TMP0.w2, EVENT_PRST -; generate interrupt - ldi r31.w0, PRU0_ARM_IRQ -update_events_no_int2: -; Set EVENT_S_PRST in EVENT_S register - lbco ®_TMP0, MASTER_REGS_CONST, EVENT_S, 2 - set REG_TMP0.b0, REG_TMP0.b0, EVENT_S_PRST -;save events - sbco ®_TMP0.w0, MASTER_REGS_CONST, EVENT_S, 1 - qbbc update_events_no_int18, REG_TMP0.b1, EVENT_S_PRST -; generate interrupt - ldi r31.w0, PRU0_ARM_IRQ4 -update_events_no_int18: - -; Set PRST bits in ONLINE_STATUS registers - lbco ®_TMP0, MASTER_REGS_CONST, ONLINE_STATUS_D_H, 6 - set REG_TMP0.w0, REG_TMP0.w0, ONLINE_STATUS_D_PRST - set REG_TMP0.w2, REG_TMP0.w2, ONLINE_STATUS_1_PRST - set REG_TMP1.w0, REG_TMP1.w0, ONLINE_STATUS_2_PRST - sbco ®_TMP0, MASTER_REGS_CONST, ONLINE_STATUS_D_H, 6 jmp datalink_reset ;-------------------------------------------------------------------------------------------------- ;Function: switch_clk (RET_ADDR1) diff --git a/source/position_sense/hdsl/firmware/datalink_init.asm b/source/position_sense/hdsl/firmware/datalink_init.asm index 4e4f30d..2854f7a 100644 --- a/source/position_sense/hdsl/firmware/datalink_init.asm +++ b/source/position_sense/hdsl/firmware/datalink_init.asm @@ -101,30 +101,48 @@ datalink_reset: ;reset SAFE_CTRL register zero ®_TMP0.b0, 1 sbco ®_TMP0.b0, MASTER_REGS_CONST, SAFE_CTRL, 1 +; Set EVENT_PRST in EVENT_H register + lbco ®_TMP0, MASTER_REGS_CONST, EVENT_H, 4 + set REG_TMP0.w0, REG_TMP0.w0, EVENT_PRST +;save events + sbco ®_TMP0.w0, MASTER_REGS_CONST, EVENT_H, 2 + qbbc update_events_no_int15, REG_TMP0.w2, EVENT_PRST +; generate interrupt + ldi r31.w0, PRU0_ARM_IRQ +update_events_no_int15: +; Set EVENT_S_PRST in EVENT_S register + lbco ®_TMP0, MASTER_REGS_CONST, EVENT_S, 2 + set REG_TMP0.b0, REG_TMP0.b0, EVENT_S_PRST +;save events + sbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 1 + qbbc update_events_no_int22, REG_TMP0.b1, EVENT_S_PRST +; generate interrupt + ldi r31.w0, PRU0_ARM_IRQ4 +update_events_no_int22: ; Initialize ONLINE_STATUS_D, ONLINE_STATUS_1 and ONLINE_STATUS_2 ; In ONLINE_STATUS_D high, bit 2 is FIX0, bit 4 is FIX1 and bit 5 is FIX0 ; In ONLINE_STATUS_D low, bit 0 is FIX0 and bit 3 is FIX0 lbco ®_TMP0.w0, MASTER_REGS_CONST, ONLINE_STATUS_D_H, 2 ; clearing bits ldi REG_TMP0.w0, 0 - ; setting bits with fix1 - or REG_TMP0.w0, REG_TMP0.w0, (1< add 1 to QM - QM_ADD 1 -; NOTE: QM_ADD uses REG_TMP0. Loading REG_TMP0 again here. It can be optimized. +; No QM updates for CRC check success with safe channel 2 lbco ®_TMP0.b0, MASTER_REGS_CONST, ONLINE_STATUS_2_H, 1 ;check for special character: K29.7 is sent in first byte of secondary vertical channel if slave error occured ; assumption: r21.b3 contains the first byte of secondary vertical channel qbne transport_on_v_frame_no_vpos2_error, REG_TMP2.b3, K29_7 ; set VPOS2 bit in ONLINE_STATUS_2 - set REG_TMP0.b0, REG_TMP0.w0, ONLINE_STATUS_2_VPOS2 + set REG_TMP0.b0, REG_TMP0.b0, ONLINE_STATUS_2_VPOS2 sbco ®_TMP0.b0, MASTER_REGS_CONST, ONLINE_STATUS_2_H, 1 qba transport_on_v_frame_vpos2_error_exit transport_on_v_frame_no_vpos2_error: - clr REG_TMP0.b0, REG_TMP0.w0, ONLINE_STATUS_2_VPOS2 + clr REG_TMP0.b0, REG_TMP0.b0, ONLINE_STATUS_2_VPOS2 transport_on_v_frame_vpos2_error_exit: ; store the data from secondary channel @@ -377,26 +375,28 @@ transport_skip_vpos_update: ; generate interrupt ldi r31.w0, PRU0_ARM_IRQ update_events_no_int7: -;set event_s and generate interrupt_s - lbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 2 - set REG_TMP0.b0, REG_TMP0.b0, EVENT_S_SSUM -;save events - sbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 2 - qbbc update_events_no_int17, REG_TMP0.b1, EVENT_S_SSUM -; generate interrupt_s - ldi r31.w0, PRU0_ARM_IRQ4 -update_events_no_int17: summary_no_int: ; Update SUM and SSUM bits in ONLINE_STATUS registers lbco ®_TMP0.b0, MASTER_REGS_CONST, SAFE_SUM, 1 lbco ®_TMP2.b0, MASTER_REGS_CONST, ONLINE_STATUS_D_H, 3 - clr REG_TMP2.b0, REG_TMP2.b0, ONLINE_STATUS_D_SUM - clr REG_TMP2.b2, REG_TMP2.b0, ONLINE_STATUS_1_SSUM qbeq online_status_sum_clear, REG_TMP0.b0, 0x00 set REG_TMP2.b0, REG_TMP2.b0, ONLINE_STATUS_D_SUM - set REG_TMP2.b2, REG_TMP2.b0, ONLINE_STATUS_1_SSUM + set REG_TMP2.b2, REG_TMP2.b2, ONLINE_STATUS_1_SSUM +;set SSUM in EVENT_S and generate interrupt_s + lbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 2 + set REG_TMP0.b0, REG_TMP0.b0, EVENT_S_SSUM +;save events + sbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 1 + qbbc update_events_no_int17, REG_TMP0.b1, EVENT_S_SSUM +; generate interrupt_s + ldi r31.w0, PRU0_ARM_IRQ4 +update_events_no_int17: + qba online_status_sum_save online_status_sum_clear: + clr REG_TMP2.b0, REG_TMP2.b0, ONLINE_STATUS_D_SUM + clr REG_TMP2.b2, REG_TMP2.b2, ONLINE_STATUS_1_SSUM +online_status_sum_save: sbco ®_TMP2.b0, MASTER_REGS_CONST, ONLINE_STATUS_D_H, 3 ;restore REG_FNC.w0 content @@ -554,7 +554,7 @@ transport_layer_received_short_msg: lbco ®_TMP0, MASTER_REGS_CONST, EVENT_S, 2 set REG_TMP0.w0, REG_TMP0.w0, EVENT_S_FRES ;save events - sbco ®_TMP0.w0, MASTER_REGS_CONST, EVENT_S, 1 + sbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 1 qbbc update_events_no_int100, REG_TMP0.b1, EVENT_S_FRES ; generate interrupt ldi r31.w0, PRU0_ARM_IRQ @@ -578,7 +578,7 @@ transport_layer_short_msg_recv_read: lbco ®_TMP0, MASTER_REGS_CONST, EVENT_S, 2 set REG_TMP0.w0, REG_TMP0.w0, EVENT_S_FRES ;save events - sbco ®_TMP0.w0, MASTER_REGS_CONST, EVENT_S, 1 + sbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 1 qbbc update_events_no_int10, REG_TMP0.b1, EVENT_S_FRES ; generate interrupt ldi r31.w0, PRU0_ARM_IRQ @@ -702,7 +702,7 @@ update_events_no_int19: lbco ®_TMP0, MASTER_REGS_CONST, EVENT_S, 2 set REG_TMP0.b0, REG_TMP0.b0, EVENT_S_MIN ;save events - sbco ®_TMP0.w0, MASTER_REGS_CONST, EVENT_S, 1 + sbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 1 qbbc update_events_no_int20, REG_TMP0.b1, EVENT_S_MIN ; generate interrupt ldi r31.w0, PRU0_ARM_IRQ4 @@ -877,12 +877,16 @@ transport_layer_no_short_msg: clr REG_TMP0.b0, REG_TMP0.b0, (ONLINE_STATUS_D_FREL-8) sbco ®_TMP0.b0, MASTER_REGS_CONST, (ONLINE_STATUS_D_L), 1 lbco ®_TMP1, MASTER_REGS_CONST, PC_ADD_H, 4 +; Bit 7 should be set for long message in PC_ADD_H + set REG_TMP1.b0, REG_TMP1.b0, 7 mov SHORT_MSG.addr, REG_TMP1.b0 ldi SHORT_MSG.bits_left, 16 ;using PC_OFF? qbbc transport_layer_assemble_long_msg_no_pc_off, REG_TMP1.b0, LOFF +; Bit 7 should be set for long message in PC_OFF_H + set REG_TMP1.b2, REG_TMP1.b2, 7 add SHORT_MSG.bits_left, SHORT_MSG.bits_left, 16 transport_layer_assemble_long_msg_no_pc_off: ;save ADDR(+OFF) to memory buffer @@ -931,7 +935,7 @@ update_events_no_int3: lbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 2 set REG_TMP0.b0, REG_TMP0.b0, EVENT_S_QMLW ;save events - sbco ®_TMP0.w0, MASTER_REGS_CONST, EVENT_S, 1 + sbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 1 qbbc update_events_no_int16, REG_TMP0.b1, EVENT_S_QMLW ; generate interrupt_s ldi r31.w0, PRU0_ARM_IRQ4 @@ -1144,6 +1148,10 @@ calc_relpos_extend_vel: ; Set POSTX to 2 ldi REG_TMP0.b0, 0x2 sbco ®_TMP0.b0, MASTER_REGS_CONST, POSTX, 1 + +; Store PIPE data + sbco &H_FRAME.pipe, MASTER_REGS_CONST, PIPE_D, 1 + ; signal event mst_intr[0] and PRU0_ARM_IRQ3 ldi r31.w0, 32+0 ldi r31.w0, PRU0_ARM_IRQ3 diff --git a/source/position_sense/hdsl/include/hdsl_drv.h b/source/position_sense/hdsl/include/hdsl_drv.h index 18e2d9c..cdf3878 100644 --- a/source/position_sense/hdsl/include/hdsl_drv.h +++ b/source/position_sense/hdsl/include/hdsl_drv.h @@ -63,6 +63,50 @@ extern "C" { /* Macros & Typedefs */ /* ========================================================================== */ +/** + * \anchor HDSL_LongMessageAddrTypes + * \name HDSL Long Message Addressing Types + * + * + * @{ + */ +/** \brief Direct addressing of long messages */ +#define HDSL_LONG_MSG_ADDR_DIRECT (0U) +/** \brief Indirect addressing of long messages */ +#define HDSL_LONG_MSG_ADDR_INDIRECT (1U) +/** @} */ + +/** + * \anchor HDSL_LongMessageAddrOffsetModes + * \name HDSL Long Message Addressing with/without offset + * + * + * @{ + */ +/** \brief Addressing of long messages without offset */ +#define HDSL_LONG_MSG_ADDR_WITHOUT_OFFSET (0U) +/** \brief Addressing of long messages with offset */ +#define HDSL_LONG_MSG_ADDR_WITH_OFFSET (1U) +/** @} */ + + +/** + * \anchor HDSL_LongMessageLengths + * \name HDSL Long Message Data Lengths + * + * + * @{ + */ +/** \brief No data bytes */ +#define HDSL_LONG_MSG_LENGTH_0 (0U) +/** \brief 2 data bytes */ +#define HDSL_LONG_MSG_LENGTH_2 (1U) +/** \brief 4 data bytes */ +#define HDSL_LONG_MSG_LENGTH_4 (2U) +/** \brief 8 data bytes */ +#define HDSL_LONG_MSG_LENGTH_8 (3U) +/** @} */ + #define MAX_WAIT 20000 #define HDSL_ICSSG0_INST 0U @@ -92,8 +136,6 @@ extern "C" { /* ICSSG0_PR1_EDC1_LATCH0_IN PRU_ICSSG0 (4+(10*4)) */ #define SYNCEVT_RTR_SYNC10_EVT 0x2C -#define ONLINE_STATUS_1_L_FRES (1<<0) - enum { MENU_SAFE_POSITION, MENU_QUALITY_MONITORING, @@ -103,7 +145,7 @@ enum { MENU_RSSI, MENU_PC_SHORT_MSG_WRITE, MENU_PC_SHORT_MSG_READ, - MENU_DIRECT_READ_RID0_LENGTH8, + MENU_DIRECT_READ_RID0_LENGTH4, MENU_DIRECT_READ_RID81_LENGTH8, MENU_DIRECT_READ_RID81_LENGTH2, MENU_INDIRECT_WRITE_RID0_LENGTH8_OFFSET0, @@ -386,7 +428,7 @@ uint8_t HDSL_get_acc_err_cnt(HDSL_Handle hdslHandle); uint8_t HDSL_get_rssi(HDSL_Handle hdslHandle); /** - * \brief Write Response of Short message parameters channel Read for safe1 channel(S_PC_DATA) with gPc_data and Short message control value(SLAVE_REG_CTRL) in hdsl interface + * \brief Trigger a short message write operation using parameters channel * * \param[in] hdslHandle * \param[in] addr Address @@ -396,10 +438,10 @@ uint8_t HDSL_get_rssi(HDSL_Handle hdslHandle); * \return SystemP_SUCCESS in case of success, SystemP_TIMEOUT in case of timeout * */ -int32_t HDSL_write_pc_short_msg(HDSL_Handle hdslHandle,uint8_t addr, uint8_t data, uint64_t timeout); +int32_t HDSL_write_pc_short_msg(HDSL_Handle hdslHandle, uint8_t addr, uint8_t data, uint64_t timeout); /** - * \brief Read Response of Short message parameters channel Read for safe1 channel(S_PC_DATA) and write Short message control value(SLAVE_REG_CTRL) with gPc_addr in hdsl interface + * \brief Trigger a short message read operation using parameters channel * * \param[in] hdslHandle * \param[in] addr Address @@ -409,44 +451,50 @@ int32_t HDSL_write_pc_short_msg(HDSL_Handle hdslHandle,uint8_t addr, uint8_t dat * \return SystemP_SUCCESS in case of success, SystemP_TIMEOUT in case of timeout * */ -int32_t HDSL_read_pc_short_msg(HDSL_Handle hdslHandle,uint8_t addr, uint8_t *data, uint64_t timeout); +int32_t HDSL_read_pc_short_msg(HDSL_Handle hdslHandle, uint8_t addr, uint8_t *data, uint64_t timeout); /** - * \brief Write PC_AAD_L ,PC_ADD_H ,PC_OFF_L,PC_OFF_H and PC_CTRL values in hdsl interface + * \brief Trigger a long message write operation using parameters channel. + * Call \ref HDSL_write_pc_buffer before this to write the data to be sent using long message. * * \param[in] hdslHandle - * \param[in] pc_addrh - * \param[in] pc_addrl - * \param[in] pc_offh - * \param[in] pc_offl + * \param[in] addr 10 bit address for long message + * \param[in] offsetEnable Addressing with offset enable/disable from \ref HDSL_LongMessageAddrOffsetModes + * \param[in] addrType Addressing Type from \ref HDSL_LongMessageAddrTypes + * \param[in] length Length from \ref HDSL_LongMessageLength + * \param[in] offset 15 bit address offset for long message (if offset is enabled in offsetEnable parameter) + * \param[in] timeout Timeout in microseconds + * + * \return SystemP_SUCCESS in case of success, SystemP_FAILURE in case of error, SystemP_TIMEOUT in case of timeout * */ -void HDSL_set_pc_addr(HDSL_Handle hdslHandle, uint8_t pc_addrh, uint8_t pc_addrl, uint8_t pc_offh, uint8_t pc_offl); +int32_t HDSL_write_pc_long_msg(HDSL_Handle hdslHandle, uint16_t addr, uint8_t offsetEnable, uint8_t addrType, uint8_t length, uint16_t offset, uint64_t timeout); /** - * \brief To set the direction read/write for long message communication - * + * \brief Trigger a long message read operation using parameters channel + * If this API returns SystemP_SUCCESS, call \ref HDSL_read_pc_buffer after this to read the data received using long message. * \param[in] hdslHandle - * \param[in] value + * \param[in] addr 10 bit address for long message + * \param[in] offsetEnable Addressing with offset enable/disable from \ref HDSL_LongMessageAddrOffsetModes + * \param[in] addrType Addressing Type from \ref HDSL_LongMessageAddrTypes + * \param[in] length Length from \ref HDSL_LongMessageLength + * \param[in] offset 15 bit address offset for long message + * \param[in] timeout Timeout in microseconds + * + * \return SystemP_SUCCESS in case of success, SystemP_FAILURE in case of error, SystemP_TIMEOUT in case of timeout * */ -void HDSL_set_pc_ctrl(HDSL_Handle hdslHandle, uint8_t value); +int32_t HDSL_read_pc_long_msg(HDSL_Handle hdslHandle, uint16_t addr, uint8_t offsetEnable, uint8_t addrType, uint8_t length, uint16_t offset, uint64_t timeout); /** * \brief Write Parameters channel buffer for different bytes(bytes 0-7) * * \param[in] hdslHandle - * \param[in] pc_buf0 - * \param[in] pc_buf1 - * \param[in] pc_buf2 - * \param[in] pc_buf3 - * \param[in] pc_buf4 - * \param[in] pc_buf5 - * \param[in] pc_buf6 - * \param[in] pc_buf7 + * \param[in] buff_off + * \param[in] data * */ -void HDSL_write_pc_buffer(HDSL_Handle hdslHandle, uint8_t pc_buf0, uint8_t pc_buf1, uint8_t pc_buf2, uint8_t pc_buf3, uint8_t pc_buf4, uint8_t pc_buf5, uint8_t pc_buf6, uint8_t pc_buf7); +void HDSL_write_pc_buffer(HDSL_Handle hdslHandle, uint8_t buff_off, uint8_t data); /** * \brief Returns Parameters channel buffer for different bytes(bytes 0-7)