Conversation
nistath
left a comment
There was a problem hiding this comment.
There are several things missing:
- No support for interrupt user to provide their own frame and timestamp.
- No support for interrupt user to provide their own HAL frame and timestamp and have an automatic conversion.
- Timestamp is not time of unpacking, it's time of reception.
generator/send_receive.py
Outdated
| fw('void CANlib_Handle_{}(Frame *frame)'.format( | ||
| tot_name, tot_name) + ' {\n' + '\tCANlib_Unpack_{}(frame, &CANlib_{}_Input);\n'.format(tot_name, tot_name) + '}\n\n') | ||
| fw('void CANlib_Handle_{}(Timestamped_Frame *ts_frame) {{\n'.format(tot_name, tot_name)) | ||
| fw('\tCANlib_{}_Input.timestamp = HAL_GetTick();\n'.format(tot_name)) |
There was a problem hiding this comment.
This should be coming in as a function parameter. Devices could be buffering frames on their own and have the timestamp be in the past.
src/drivers/src/stm32f4xx.c
Outdated
| } | ||
|
|
||
| void CANlib_ReadFrame(Frame *frame, CANlib_Bus_T bus) { | ||
| bool CANlib_ReadFrame(Frame *frame, CANlib_Bus_T bus) { |
There was a problem hiding this comment.
If it returns anything it should probably be HAL_StatusTypeDef.
There was a problem hiding this comment.
The thing is HAL_CAN_GetRxMessage only returns HAL_OK or HAL_ERROR anyway; and also it could possibly not even be called if both FIFO's are empty
src/driver.h
Outdated
|
|
||
| CANlib_Transmit_Error_T CANlib_TransmitFrame(Frame *frame, CANlib_Bus_T bus); | ||
| void CANlib_ReadFrame(Frame *frame, CANlib_Bus_T bus); | ||
| bool CANlib_ReadFrame(Frame *frame, CANlib_Bus_T bus); |
There was a problem hiding this comment.
Maybe introduce CANlib_Receive_Error_T, idk if we need to mess with this now tho
generator/computers_c.py
Outdated
|
|
||
| for busnm, bus in computer.participation['name']['can'].subscribe.items(): | ||
| fw( | ||
| 'static void CANlib_update_can_{}(void)'.format(busnm) + '{\n' + |
There was a problem hiding this comment.
should be _Update and also missing space before {.
generator/computers_c.py
Outdated
| 'static void CANlib_update_can_{}(void)'.format(busnm) + '{\n' + | ||
| '\tTimestamped_Frame ts_frame;\n' | ||
| ) | ||
| if any(is_multplxd(msg) for msg in bus): |
generator/computers_c.py
Outdated
| fw('\tuint64_t bitstring;\n') | ||
|
|
||
| fw( | ||
| '\tif (CANlib_ReadFrame(&(ts_frame.frame), {})) {{\n'.format(busnm) + |
There was a problem hiding this comment.
You don't set the timestamp so it's initialized with junk. Here you can set it with get tick
generator/computers_c.py
Outdated
| fw('\tCANlib_update_can_{}();\n'.format(busnm)) | ||
| fw('}\n\n') | ||
|
|
||
| fw('void CANlib_HandleFrame(CAN_Raw_Bus_T raw_bus) {\n') |
There was a problem hiding this comment.
How is this different than the update? Where can a user of interrupts provide a timestamped frame and have it accounted for?
| fw('\t}\n}\n\n') | ||
|
|
||
| fw( | ||
| 'CAN_Raw_Bus_T CANlib_GetConceptualBus(CAN_Raw_Bus_T bus) {\n' |
|
Made changes. Example usage in |
|
@equationcrunchor please revisit to resolve conflicts and ping me for review? |
|
@nistath Conflicts resolved. |
| frame_handler, is_multplxd | ||
| from math import ceil | ||
|
|
||
| raw_bus_to_handle = {"CAN_1": "hcan1", "CAN_2": "hcan2", "CAN_3": "hcan3"} |
There was a problem hiding this comment.
This file must work with all drivers, even outside of STM.
There was a problem hiding this comment.
These variables must be inferred from the spec.
| ) | ||
| fw('\t\tdefault:\n\t\t\tUNUSED(frame);\n\t\tbreak;\n') | ||
| fw('\t}\n}\n') | ||
| fw('void CANlib_HandleFrame(TimestampedFrame *ts_frame, time_t stamp, CAN_TypeDef* instance) {\n') |
There was a problem hiding this comment.
Why does this function take a timestamped frame AND a timestamp? Whoever calls it should just assign the stamp. Also use T const * if you don't modify things.
| fw('\t}\n}\n') | ||
| fw('void CANlib_HandleFrame(TimestampedFrame *ts_frame, time_t stamp, CAN_TypeDef* instance) {\n') | ||
| if len(computer.participation['name']['can'].subscribe.keys()) > 0: # check if computer receives messages | ||
| fw('\tts_frame->stamp = stamp;\n') |
| fw('void CANlib_HandleFrame(TimestampedFrame *ts_frame, time_t stamp, CAN_TypeDef* instance) {\n') | ||
| if len(computer.participation['name']['can'].subscribe.keys()) > 0: # check if computer receives messages | ||
| fw('\tts_frame->stamp = stamp;\n') | ||
| fw('\tswitch ((intptr_t)instance) {\n') |
There was a problem hiding this comment.
This is wrong. The function should take a CANlib CAN_x instance. That way the driver can provide it and you don't need the raw_bus_to_instance.
| fw('\t\tdefault:\n\t\t\tUNUSED(frame);\n\t\tbreak;\n') | ||
| fw('\t}\n}\n') | ||
| fw('void CANlib_HandleFrame(TimestampedFrame *ts_frame, time_t stamp, CAN_TypeDef* instance) {\n') | ||
| if len(computer.participation['name']['can'].subscribe.keys()) > 0: # check if computer receives messages |
There was a problem hiding this comment.
It's not this part's job to make a function unusable if nobody subscribes to it. It should be generated and just not be exposed to the user.
|
|
||
| fw('extern CAN_HandleTypeDef hcan1;\n') | ||
| fw('extern CAN_HandleTypeDef hcan2;\n') | ||
| fw('extern CAN_HandleTypeDef hcan3;\n\n') |
|
|
||
| CANlib_Transmit_Error_T CANlib_TransmitFrame(Frame *frame, CANlib_Bus_T bus); | ||
| void CANlib_ReadFrame(Frame *frame, CANlib_Bus_T bus); | ||
| bool HAL_CANlib_ReadFrame(CAN_HandleTypeDef *hcan, Frame* out); |
There was a problem hiding this comment.
Please conform to the format above, making a new type for receive error.
| extern "C" { | ||
| #endif // __cplusplus | ||
|
|
||
| CANlib_Transmit_Error_T CANlib_TransmitFrame(Frame *frame, CANlib_Bus_T bus); |
There was a problem hiding this comment.
This should not be here and driver.h should be included at the bottom.
| @@ -5,6 +5,7 @@ | |||
| #include "driver.h" | |||
There was a problem hiding this comment.
This should include the stm specific driver/inc/xxx.h
| fw = f.write | ||
| fw('#include <time.h>\n') | ||
| fw('#include <stdbool.h>\n') | ||
| fw('#include <stm32f4xx_hal.h>\n') |
Uses HAL_GetTick to put a timestamp on received CAN messages. Includes changes from the
interruptsbranch. Seesensor-node-timestamped-framesbranch in MY19 for example usage in sensor node. If using interrupts, one should pass the correct raw bus toCANlib_HandleFramein the callback. This will break existing code that uses CANlib.