-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from openwsn-berkeley/develop
REL-1.0
- Loading branch information
Showing
140 changed files
with
287,104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
__pycache__ | ||
/src_python/src/happyserial.egg-info | ||
/src_python/dist | ||
*.emSession | ||
Output/ | ||
*.jlink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# HappySerial | ||
|
||
Implementing a serial protocol is hard. | ||
`happyserial` deals with all the hard parts so you don't need to. | ||
Drop it in your project, both on the C and Python side. | ||
|
||
# Scope | ||
|
||
`happyserial` is useful when you have a Python program running on a computer that needs to send/receive data reliably over a serial port to an embedded device. | ||
`happyserial` is a set of two libraries, one for the Python side, one for the C side. | ||
Your code ends up sending and receiving serial frames through those library, never having to worry about bytes, retries, framing, etc. | ||
|
||
``` | ||
+----------+ +-----------+ | ||
| Python | serial | C | | ||
| software |===========| firmware | | ||
| | | | | ||
|(computer)| | (devices) | | ||
+----------+ +-----------+ | ||
scope of happyserial | ||
<------------------> | ||
``` | ||
|
||
# Features | ||
|
||
- framing of the serial stream | ||
- detect and drop corrupted frames | ||
|
||
# wishlist | ||
|
||
- retransmission when a frame is corrupted | ||
- uses the DMA on the nRF so your firmware routines aren't interrupted by every byte received | ||
|
||
# using `happyserial` | ||
|
||
On the Python side: | ||
|
||
``` | ||
from happyserial import HappySerial | ||
def _happyserial_rx_cb(buf): | ||
print('rx: {}'.format(buf)) | ||
happy = HappySerial.HappySerial( | ||
serialport = 'COM41', | ||
rx_cb = _happyserial_rx_cb, | ||
) | ||
happy.tx([0x01,0x02,0x03]) | ||
``` | ||
|
||
On the C side: | ||
|
||
``` | ||
... | ||
#include "happyserial.h" | ||
int main(void) { | ||
uint8_t buf = {0x00,0x01,0x03}; | ||
happyserial_init(_happyserial_rx_cb); | ||
... | ||
happyserial_tx(buf,sizeof(buf)); | ||
} | ||
void _happyserial_rx_cb(uint8_t* buf, uint8_t bufLen) { | ||
... | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "nrf52840.h" | ||
#include "happyserial.h" | ||
|
||
//=========================== defines ========================================= | ||
|
||
//=========================== prototypes ====================================== | ||
|
||
void _happyserial_rx_cb(uint8_t* buf, uint8_t bufLen); | ||
|
||
//=========================== variables ======================================= | ||
|
||
typedef struct { | ||
uint32_t dummy; | ||
} app_vars_t; | ||
|
||
app_vars_t app_vars; | ||
|
||
typedef struct { | ||
uint32_t dummy; | ||
} app_dbg_t; | ||
|
||
app_dbg_t app_dbg; | ||
|
||
//=========================== main ============================================ | ||
|
||
int main(void) { | ||
|
||
happyserial_init(_happyserial_rx_cb); | ||
|
||
// main loop | ||
while(1) { | ||
|
||
// wait for event | ||
__SEV(); // set event | ||
__WFE(); // wait for event | ||
__WFE(); // wait for event | ||
} | ||
} | ||
|
||
//=========================== interrupt handlers ============================== | ||
|
||
void _happyserial_rx_cb(uint8_t* buf, uint8_t bufLen) { | ||
happyserial_tx(buf,bufLen); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<!DOCTYPE CrossStudio_Project_File> | ||
<solution Name="happyserial" target="8" version="2"> | ||
<project Name="echo"> | ||
<configuration | ||
LIBRARY_IO_TYPE="RTT" | ||
Name="Common" | ||
Target="nRF52840_xxAA" | ||
arm_architecture="v7EM" | ||
arm_compiler_variant="SEGGER" | ||
arm_core_type="Cortex-M4" | ||
arm_endian="Little" | ||
arm_fp_abi="Hard" | ||
arm_fpu_type="FPv4-SP-D16" | ||
arm_linker_heap_size="1024" | ||
arm_linker_process_stack_size="0" | ||
arm_linker_stack_size="2048" | ||
arm_linker_variant="SEGGER" | ||
arm_rtl_variant="SEGGER" | ||
arm_simulator_memory_simulation_parameter="ROM;0x00000000;0x00100000;RAM;0x00800000;0x00040000;ROM;0x12000000;0x08000000;RAM;0x20000000;0x00040000" | ||
arm_target_debug_interface_type="ADIv5" | ||
arm_target_device_name="nRF52840_xxAA" | ||
arm_target_interface_type="SWD" | ||
c_preprocessor_definitions="ARM_MATH_CM4;NRF52840_XXAA;__NRF_FAMILY" | ||
c_user_include_directories="$(ProjectDir)/../../nRF52840-DK/system/CMSIS_5/CMSIS/Core/Include;$(ProjectDir)/../../nRF52840-DK/system/nRF/Device/Include;$(ProjectDir)/../../../happyserial;$(ProjectDir)/../../../ports/;" | ||
debug_register_definition_file="$(ProjectDir)/../../nRF52840-DK/system/nrf52840_Registers.xml" | ||
debug_stack_pointer_start="__stack_end__" | ||
debug_start_from_entry_point_symbol="No" | ||
debug_target_connection="J-Link" | ||
gcc_entry_point="Reset_Handler" | ||
link_linker_script_file="$(ProjectDir)/../../nRF52840-DK/system/nRF_Flash_Variant4.icf" | ||
linker_memory_map_file="$(ProjectDir)/../../nRF52840-DK/system/nRF52840_xxAA_MemoryMap.xml" | ||
macros="DeviceHeaderFile=$(PackagesDir)/../../nRF52840-DK/system/nRF/Device/Include/nrf.h;DeviceSystemFile=$(PackagesDir)/system/nRF/Device/Source/system_nrf52.c;DeviceVectorsFile=$(PackagesDir)/system/nRF/Source/nrf52840_Vectors.s;DeviceFamily=nRF;Target=nRF52840_xxAA" | ||
project_directory="../common/echo" | ||
project_type="Executable" | ||
target_reset_script="Reset();" | ||
target_trace_initialize_script="EnableTrace("$(TraceInterfaceType)")" /> | ||
<folder Name="CMSIS Files"> | ||
<file file_name="../../nRF52840-DK/system/nRF/Device/Include/nrf.h" /> | ||
<file file_name="../../nRF52840-DK/system/nRF/Device/Source/system_nrf52.c"> | ||
<configuration | ||
Name="Common" | ||
default_code_section=".init" | ||
default_const_section=".init_rodata" /> | ||
</file> | ||
</folder> | ||
<folder Name="Script Files"> | ||
<file file_name="../../nRF52840-DK/system/nRF/Scripts/nRF_Target.js"> | ||
<configuration Name="Common" file_type="Reset Script" /> | ||
</file> | ||
</folder> | ||
<folder Name="Source Files"> | ||
<configuration Name="Common" filter="c;cpp;cxx;cc;h;s;asm;inc" /> | ||
<file file_name="echo.c" /> | ||
<folder Name="happyserial"> | ||
<file file_name="../../../happyserial/happyserial.c" /> | ||
<file file_name="../../../happyserial/happyserial.h" /> | ||
<file file_name="../../../happyserial/hdlc.c" /> | ||
<file file_name="../../../happyserial/hdlc.h" /> | ||
<file file_name="../../../happyserial/crc.c" /> | ||
<file file_name="../../../happyserial/crc.h" /> | ||
</folder> | ||
<folder Name="ports"> | ||
<folder Name="nRF52840"> | ||
<file file_name="../../../ports/nRF52840/uart.c" /> | ||
</folder> | ||
<file file_name="../../../ports/uart.h" /> | ||
</folder> | ||
</folder> | ||
<folder Name="System Files"> | ||
<file file_name="../../nRF52840-DK/system/SEGGER_THUMB_Startup.s" /> | ||
<file file_name="../../nRF52840-DK/system/nRF/Source/nRF_Startup.s" /> | ||
<file file_name="../../nRF52840-DK/system/nRF/Source/nrf52840_Vectors.s"> | ||
<configuration Name="Common" file_type="Assembly" /> | ||
</file> | ||
</folder> | ||
</project> | ||
<configuration | ||
Name="Debug" | ||
c_preprocessor_definitions="DEBUG" | ||
gcc_debugging_level="Level 3" | ||
gcc_omit_frame_pointer="Yes" | ||
gcc_optimization_level="None" /> | ||
<configuration | ||
Name="Release" | ||
c_preprocessor_definitions="NDEBUG" | ||
gcc_debugging_level="Level 2" | ||
gcc_omit_frame_pointer="Yes" | ||
gcc_optimization_level="Level 2 balanced" /> | ||
</solution> |
Oops, something went wrong.