-
Notifications
You must be signed in to change notification settings - Fork 75
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
Implement get_fattime #160
Conversation
Signed-off-by: Hrushi20 <[email protected]>
Hey, I am using a Mac M1 chip. Is there support for xc-16 compilter. I am not able to compile and check if the build succeeds or not. I tried downloading the xc-16 compiler. The cmake build fails: |
I am unsure how to get this working as I don't use Mac. Here is a Microchip forum thread where some people seem to have at least gotten xc8 working on M1: https://forum.microchip.com/s/topic/a5C3l000000Me63EAC/t384186 CMake uses a cmake-microchip toolchain file to detect xc16. On Mac, it searches in |
Signed-off-by: Hrushi20 <[email protected]>
Thanks!!! I got the compiler working. The build is successful. I forgot to convert bcd back to uint8_t. Need to add wrapper functions. |
I didn't not add parameters to I did not understand the Wrapper functions which are to be added in commands.c file. Can you give me a brief overview of what the commands.c file does? |
The main point of interest in When the host sends a command to the PSLab, the first two bytes are an index into this table (we refer to these bytes as "primary command" and "secondary command"). For example, if the host sends The functions pointed to by Therefore, if we have a function which we want to use both internally within pslab-firmware and over serial from a host, we create a wrapper: response_t do_something(uint8_t a, uint16_t* bp) {
// Do something with a and write the result through bp.
}
response_t do_something_serial(void) {
uint8_t a = UART_Read(); // Read input from host.
uint16_t b = 0;
response_t res = do_something(a, &b);
UART_WriteInt(b); // Write output to host.
return res;
} The wrapper function |
Signed-off-by: Hrushi20 <[email protected]>
Hey, Thanks for the explanation 😄. I've added the wrapper function and updated the commands.c file. What do I return to host after setting time to rtc? Also, while importing the Thanks |
Nothing. The return value (i.e. what is actually
Yes, that is how we handle includes. |
Signed-off-by: Hrushi20 <[email protected]>
Why is the build failing? How do I fix the issue of importing rtc.h header file? |
Ah, sorry, I misunderstood. It fails because (Specifically, the |
Signed-off-by: Hrushi20 <[email protected]>
Signed-off-by: Hrushi20 <[email protected]>
Thanks. I've updated the example using rtc_gettime function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I haven't had time to try this out yet, but here are some general comments.
Signed-off-by: Hrushi20 <[email protected]>
Signed-off-by: Hrushi20 <[email protected]>
Signed-off-by: Hrushi20 <[email protected]>
Signed-off-by: Hrushi20 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there :)
Signed-off-by: Hrushi20 <[email protected]>
I do not have a device to test the correctness of the code. I've updated the code as per code review 😄 |
Signed-off-by: Hrushi20 <[email protected]>
I will test this tonight. Did you get the message I sent you on Matrix? I set up a remote dev environment where you can test your changes on a PSLab. |
I've done some testing on import time
from datetime import datetime
import pslab
def set_time(psl: pslab.ScienceLab, ts: int) -> int:
psl.send_byte(13)
psl.send_byte(1)
psl.write(pslab.protocol.Integer.pack(ts))
return psl.get_byte()
def get_time(psl: pslab.ScienceLab) -> int:
psl.send_byte(13)
psl.send_byte(3)
ts = psl.read(4)
psl.get_ack()
return pslab.protocol.Integer.unpack(ts)[0]
psl = pslab.ScienceLab()
ts_in = int(time.time())
res = set_time(psl, ts)
print(res)
ts_out = get_time(psl)
print(datetime.fromtimestamp(ts_out)) Output is |
I refined the script a bit: import enum
import logging
import time
import pytest
import pslab
class Acknowledge(enum.Enum):
SUCCESS = 1
ARGUMENT_ERROR = 2
FAILURE = 3
logger = logging.getLogger(__name__)
def set_time(psl: pslab.ScienceLab, ts: int) -> Acknowledge:
psl.send_byte(13) # SENSORS
psl.send_byte(1) # RTC_SETTIME
logger.debug("Sent command: RTC_SETTIME")
ser_ts = pslab.protocol.Integer.pack(ts) # Serialize timestamp
logger.debug(f"Serialized timestamp: {ts} -> {list(ser_ts)}")
psl.write(ser_ts) # Send serialized timestamp to PSLab
logger.debug("Wrote timestamp to PSLab")
ack = Acknowledge(psl.get_byte())
logger.debug(f"Got ACK byte: {ack.name}")
return ack
def get_time(psl: pslab.ScienceLab) -> int:
psl.send_byte(13) # SENSORS
psl.send_byte(3) # RTC_GETTIME
logger.debug("Sent command: RTC_GETTIME")
ser_ts = psl.read(4) # Read serialized timestamp from PSLab
logger.debug(f"Got serialized timestamp: {list(ser_ts)}")
ack = Acknowledge(psl.get_ack())
logger.debug(f"Got ACK byte: {ack.name}")
ts = pslab.protocol.Integer.unpack(ser_ts)[0] # Deserialize timestamp
logger.debug(f"Deserialzed timestamp: {list(ser_ts)} -> {ts}")
return ts
def test_rtc():
psl = pslab.ScienceLab()
logger.debug("PSLab connected")
ts_in = int(time.time())
logger.debug(f"Current Unix time: {ts_in}")
# Set current time
logger.debug("Setting time on RTC")
ack = set_time(psl, ts_in)
assert ack == Acknowledge.SUCCESS
# Wait one second
logger.debug("Waiting for one second")
time.sleep(1)
# Readback time
logger.debug("Reading back time from PSLab")
ts_out = get_time(psl)
assert ts_out == ts_in + 1 I've added this script to the remote dev environment. To run it, just run |
Signed-off-by: Hrushi20 <[email protected]>
Signed-off-by: Hrushi20 <[email protected]>
I am able to set the time. I am also able to fetch the time. However, there seems to be an issue with the |
Signed-off-by: Hrushi20 <[email protected]>
I got the test working. Just tested it on the raspberry pi. |
Signed-off-by: Hrushi20 <[email protected]>
Can you review the ff_time code? I changed the logic there based on unix timestamp. |
The RTC test isn't passing for me:
|
I've added another test script, It relies on some recently added SD-card functionality, so you will need to rebase your branch on main to get it to work. You will also need to run cmake with the Right now I'm getting this test result (after locally merging this PR into main):
|
Signed-off-by: Hrushi20 <[email protected]>
Hey, can you flash and try again. Are you using the latest commit? The test is passing for me. |
Signed-off-by: Hrushi20 <[email protected]>
The test_fattime fails. There is an issue with the hours format. I'll debug it during ny free time. |
Now it's working 👍
It was a problem with the test; It didn't take the timezone into account. I've fixed it and both tests are passing. Great work! I'll give this a final look tonight, but it seems ready for merge. |
I'm looking forward to the merge 😁 |
Pr solves Issue #159 by adding logic to write and read time from DS1307 module.
This is done by reading 32-bit unix timestamp from UART1TX register, converting it to bcd format and storing it on RTC chip via I2C protocol.