├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── include ├── arch-atmega │ ├── cxa_atmega_adcChannel.h │ ├── cxa_atmega_gpio.h │ ├── cxa_atmega_i2cSlave.h │ ├── cxa_atmega_led_pwm8.h │ ├── cxa_atmega_timeBase.h │ ├── cxa_atmega_timer.h │ ├── cxa_atmega_timer_icp.h │ ├── cxa_atmega_timer_ocr.h │ ├── cxa_atmega_usart.h │ ├── sys │ │ └── types.h │ └── uart.h ├── arch-bgm │ ├── cxa_bgm_gpio.h │ ├── cxa_bgm_i2cMaster.h │ ├── cxa_bgm_nvsManager.h │ └── cxa_bgm_usart.h ├── arch-common │ ├── cxa_adcChannel.h │ ├── cxa_adcEmaSampler.h │ ├── cxa_batteryCapacityEstimator.h │ ├── cxa_criticalSection.h │ ├── cxa_delay.h │ ├── cxa_gpio.h │ ├── cxa_gpio_debouncer.h │ ├── cxa_gpio_longPressManager.h │ ├── cxa_gpio_simpleCallback.h │ ├── cxa_i2cMaster.h │ ├── cxa_i2cSlave.h │ ├── cxa_led.h │ ├── cxa_led_gpio.h │ ├── cxa_led_runLoop.h │ ├── cxa_lightSensor.h │ ├── cxa_mutex.h │ ├── cxa_nvsManager.h │ ├── cxa_random.h │ ├── cxa_reboot.h │ ├── cxa_rgbLed.h │ ├── cxa_rgbLed_runLoop.h │ ├── cxa_rgbLed_triLed.h │ ├── cxa_sntpClient.h │ ├── cxa_stepperMotorChannel.h │ ├── cxa_tempSensor.h │ ├── cxa_tempSensor_adc.h │ ├── cxa_timeBase.h │ ├── cxa_uniqueId.h │ └── cxa_usart.h ├── arch-dummy │ ├── cxa_dummy_gpio.h │ └── cxa_dummy_usart.h ├── arch-esp32 │ ├── btle │ │ ├── cxa_esp32_btle_central.h │ │ ├── cxa_esp32_btle_module.h │ │ └── cxa_esp32_btle_peripheral.h │ ├── cxa_esp32_adcChannel.h │ ├── cxa_esp32_eventManager.h │ ├── cxa_esp32_gpio.h │ ├── cxa_esp32_i2cMaster.h │ ├── cxa_esp32_nvsManager.h │ ├── cxa_esp32_timeBase.h │ └── cxa_esp32_usart.h ├── arch-pic32 │ └── cxa_pic32_usart.h ├── arch-posix │ ├── cxa_ioStream_file.h │ ├── cxa_mqtt_rpc_node_posixShell.h │ ├── cxa_posix_gpioConsole.h │ ├── cxa_posix_nvsManager.h │ └── cxa_posix_usart.h ├── arch-tiC2K │ ├── cxa_tiC2K_gpio.h │ ├── cxa_tiC2K_usart.h │ └── strtok.h ├── arch-xmega │ ├── cxa_xmega_ccp.h │ ├── cxa_xmega_clockController.h │ ├── cxa_xmega_eventSystem.h │ ├── cxa_xmega_gpio.h │ ├── cxa_xmega_ioStream_toFile.h │ ├── cxa_xmega_pmic.h │ ├── cxa_xmega_timeBase.h │ ├── cxa_xmega_timer16.h │ ├── cxa_xmega_timer16_captureChannel.h │ ├── cxa_xmega_timer32.h │ └── cxa_xmega_usart.h ├── btle │ ├── blueGiga │ │ ├── cxa_blueGiga_btle_client.h │ │ ├── cxa_blueGiga_gpio.h │ │ ├── cxa_blueGiga_i2cMaster.h │ │ ├── cxa_blueGiga_types.h │ │ └── cxa_protocolParser_bgapi.h │ ├── cxa_btle_advPacket.h │ ├── cxa_btle_central.h │ ├── cxa_btle_connection.h │ ├── cxa_btle_connectionManager.h │ ├── cxa_btle_peripheral.h │ ├── cxa_btle_uuid.h │ └── siLabsBgApi │ │ ├── bg_errorcodes.h │ │ ├── bg_gattdb_def.h │ │ ├── bg_types.h │ │ ├── cxa_siLabsBgApi_btle_central.h │ │ ├── cxa_siLabsBgApi_btle_connection.h │ │ ├── cxa_siLabsBgApi_btle_peripheral.h │ │ ├── cxa_siLabsBgApi_module.h │ │ ├── gecko_bglib.h │ │ ├── gecko_configuration.h │ │ └── host_gecko.h ├── collections │ ├── cxa_array.h │ ├── cxa_fixedByteBuffer.h │ ├── cxa_fixedFifo.h │ └── cxa_linkedField.h ├── commandLineParser │ └── cxa_commandLineParser.h ├── console │ └── cxa_console.h ├── consoleMenu │ ├── cxa_consoleMenu.h │ └── cxa_consoleMenu_menu.h ├── fdLineParser │ └── cxa_fdLineParser.h ├── logger │ ├── cxa_logger_header.h │ └── cxa_logger_implementation.h ├── misc │ ├── cxa_assert.h │ ├── cxa_eui48.h │ ├── cxa_numberUtils.h │ ├── cxa_profiler.h │ ├── cxa_stringUtils.h │ └── cxa_uuid128.h ├── mqtt │ ├── cxa_mqtt_client.h │ ├── cxa_mqtt_client_network.h │ ├── cxa_mqtt_connectionManager.h │ ├── cxa_mqtt_messageFactory.h │ ├── cxa_protocolParser_mqtt.h │ ├── messages │ │ ├── cxa_mqtt_message.h │ │ ├── cxa_mqtt_message_connack.h │ │ ├── cxa_mqtt_message_connect.h │ │ ├── cxa_mqtt_message_pingRequest.h │ │ ├── cxa_mqtt_message_pingResponse.h │ │ ├── cxa_mqtt_message_publish.h │ │ ├── cxa_mqtt_message_suback.h │ │ └── cxa_mqtt_message_subscribe.h │ └── rpc │ │ ├── cxa_mqtt_rpc_message.h │ │ ├── cxa_mqtt_rpc_node.h │ │ ├── cxa_mqtt_rpc_node_bridge.h │ │ ├── cxa_mqtt_rpc_node_bridge_multi.h │ │ ├── cxa_mqtt_rpc_node_bridge_single.h │ │ └── cxa_mqtt_rpc_node_root.h ├── net │ ├── cxa_network_ethernetManager.h │ ├── cxa_network_factory.h │ ├── cxa_network_tcpClient.h │ ├── cxa_network_tcpServer.h │ ├── cxa_network_tcpServer_connectedClient.h │ ├── cxa_network_wifiManager.h │ ├── http │ │ └── cxa_network_httpClient.h │ ├── lwipMbedTls │ │ ├── cxa_lwipMbedTls_network_tcpClient.h │ │ ├── cxa_lwipMbedTls_network_tcpServer.h │ │ └── cxa_lwipMbedTls_network_tcpServer_connectedClient.h │ └── wolfSslDialSocket │ │ ├── cxa_wolfSslDialSocket_network_factory.h │ │ └── cxa_wolfSslDialSocket_network_tcpClient.h ├── peripherals │ ├── cxa_lightSensor_ltr329.h │ ├── cxa_ltc2942.h │ ├── cxa_pca9555.h │ ├── cxa_pca9624.h │ ├── cxa_rgbLed_pca9624.h │ ├── cxa_tempRhSensor_si7021.h │ ├── cxa_tempSensor_si7050.h │ └── cxa_ws2812String.h ├── rpc │ ├── cxa_rpc_message.h │ ├── cxa_rpc_messageFactory.h │ ├── cxa_rpc_messageHandler.h │ ├── cxa_rpc_node.h │ └── cxa_rpc_nodeRemote.h ├── runLoop │ ├── cxa_oneShotTimer.h │ ├── cxa_runLoop.h │ └── cxa_softWatchDog.h ├── serial │ ├── cxa_ioStream.h │ ├── cxa_ioStream_bridge.h │ ├── cxa_ioStream_loopback.h │ ├── cxa_ioStream_nullablePassthrough.h │ ├── cxa_ioStream_peekable.h │ ├── cxa_ioStream_pipe.h │ ├── cxa_ioStream_tee.h │ ├── cxa_protocolParser.h │ ├── cxa_protocolParser_cleProto.h │ └── cxa_protocolParser_crlf.h ├── stateMachine │ └── cxa_stateMachine.h └── timeUtils │ ├── cxa_timeDiff.h │ └── cxa_timeUtils.h └── src ├── arch-atmega ├── cxa_atmega_adcChannel.c ├── cxa_atmega_criticalSection.c ├── cxa_atmega_delay.c ├── cxa_atmega_gpio.c ├── cxa_atmega_i2cSlave.c ├── cxa_atmega_led_pwm8.c ├── cxa_atmega_mutex.c ├── cxa_atmega_random.c ├── cxa_atmega_reboot.c ├── cxa_atmega_timeBase.c ├── cxa_atmega_timer.c ├── cxa_atmega_timer_icp.c ├── cxa_atmega_timer_ocr.c ├── cxa_atmega_uniqueId.c ├── cxa_atmega_usart.c └── uart.c ├── arch-bgm ├── cxa_bgm_criticalSection.c ├── cxa_bgm_delay.c ├── cxa_bgm_gpio.c ├── cxa_bgm_i2cMaster.c ├── cxa_bgm_nvsManager.c ├── cxa_bgm_timeBase.c ├── cxa_bgm_uniqueId.c └── cxa_bgm_usart.c ├── arch-common ├── cxa_adcChannel.c ├── cxa_adcEmaSampler.c ├── cxa_batteryCapacityEstimator.c ├── cxa_gpio.c ├── cxa_gpio_debouncer.c ├── cxa_gpio_longPressManager.c ├── cxa_gpio_simpleCallback.c ├── cxa_i2cMaster.c ├── cxa_i2cSlave.c ├── cxa_led.c ├── cxa_led_gpio.c ├── cxa_led_runLoop.c ├── cxa_lightSensor.c ├── cxa_nvsManager.c ├── cxa_rgbLed.c ├── cxa_rgbLed_runLoop.c ├── cxa_rgbLed_triLed.c ├── cxa_stepperMotorChannel.c ├── cxa_tempSensor.c ├── cxa_tempSensor_adc.c └── cxa_usart.c ├── arch-dummy ├── cxa_dummy_delay.c ├── cxa_dummy_gpio.c └── cxa_dummy_usart.c ├── arch-esp32 ├── btle │ ├── cxa_esp32_btle_central.c │ ├── cxa_esp32_btle_module.c │ └── cxa_esp32_btle_peripheral.c ├── cxa_esp32_adcChannel.c ├── cxa_esp32_criticalSection.c ├── cxa_esp32_delay.c ├── cxa_esp32_ethernetManager.c ├── cxa_esp32_eventManager.c ├── cxa_esp32_gpio.c ├── cxa_esp32_i2cMaster.c ├── cxa_esp32_mutex.c ├── cxa_esp32_nvsManager.c ├── cxa_esp32_random.c ├── cxa_esp32_reboot.c ├── cxa_esp32_sntpClient.c ├── cxa_esp32_stepperMotorChannel.c ├── cxa_esp32_timeBase.c ├── cxa_esp32_uniqueId.c ├── cxa_esp32_usart.c └── cxa_esp32_wifiManager.c ├── arch-pic32 ├── cxa_pic32_criticalSection.c ├── cxa_pic32_delay.c ├── cxa_pic32_timeBase.c └── cxa_pic32_usart.c ├── arch-posix ├── cxa_ioStream_file.c ├── cxa_mqtt_rpc_node_posixShell.c ├── cxa_posix_criticalSection.c ├── cxa_posix_delay.c ├── cxa_posix_gpioConsole.c ├── cxa_posix_nvsManager.c ├── cxa_posix_timeBase.c ├── cxa_posix_uniqueId.c └── cxa_posix_usart.c ├── arch-tiC2K ├── cxa_tiC2K_criticalSection.c ├── cxa_tiC2K_delay.c ├── cxa_tiC2K_gpio.c ├── cxa_tiC2K_nvsManager.c ├── cxa_tiC2K_timeBase.c ├── cxa_tiC2K_uniqueId.c ├── cxa_tiC2K_usart.c └── strtok.c ├── arch-xmega ├── cxa_xmega_ccp.s ├── cxa_xmega_clockController.c ├── cxa_xmega_criticalSection.c ├── cxa_xmega_delay.c ├── cxa_xmega_eventSystem.c ├── cxa_xmega_gpio.c ├── cxa_xmega_ioStream_toFile.c ├── cxa_xmega_pmic.c ├── cxa_xmega_timeBase.c ├── cxa_xmega_timer16.c ├── cxa_xmega_timer16_captureChannel.c ├── cxa_xmega_timer32.c └── cxa_xmega_usart.c ├── btle ├── blueGiga │ ├── cxa_blueGiga_btle_client.c │ ├── cxa_blueGiga_gpio.c │ ├── cxa_blueGiga_i2cMaster.c │ └── cxa_protocolParser_bgapi.c ├── cxa_btle_advPacket.c ├── cxa_btle_central.c ├── cxa_btle_connection.c ├── cxa_btle_connectionManager.c ├── cxa_btle_peripheral.c ├── cxa_btle_uuid.c └── siLabsBgApi │ ├── cxa_siLabsBgApi_btle_central.c │ ├── cxa_siLabsBgApi_btle_connection.c │ ├── cxa_siLabsBgApi_btle_peripheral.c │ ├── cxa_siLabsBgApi_module.c │ └── gecko_bglib.c ├── collections ├── cxa_array.c ├── cxa_fixedByteBuffer.c ├── cxa_fixedFifo.c └── cxa_linkedField.c ├── commandLineParser └── cxa_commandLineParser.c ├── console └── cxa_console.c ├── consoleMenu ├── cxa_consoleMenu.c └── cxa_consoleMenu_menu.c ├── fdLineParser └── cxa_fdLineParser.c ├── logger └── cxa_logger.c ├── misc ├── cxa_assert.c ├── cxa_eui48.c ├── cxa_numberUtils.c ├── cxa_profiler.c ├── cxa_stringUtils.c └── cxa_uuid128.c ├── mqtt ├── cxa_mqtt_client.c ├── cxa_mqtt_client_network.c ├── cxa_mqtt_connectionManager.c ├── cxa_mqtt_messageFactory.c ├── cxa_protocolParser_mqtt.c ├── messages │ ├── cxa_mqtt_message.c │ ├── cxa_mqtt_message_connack.c │ ├── cxa_mqtt_message_connect.c │ ├── cxa_mqtt_message_pingRequest.c │ ├── cxa_mqtt_message_pingResponse.c │ ├── cxa_mqtt_message_publish.c │ ├── cxa_mqtt_message_suback.c │ └── cxa_mqtt_message_subscribe.c └── rpc │ ├── cxa_mqtt_rpc_message.c │ ├── cxa_mqtt_rpc_node.c │ ├── cxa_mqtt_rpc_node_bridge.c │ ├── cxa_mqtt_rpc_node_bridge_multi.c │ ├── cxa_mqtt_rpc_node_bridge_single.c │ └── cxa_mqtt_rpc_node_root.c ├── net ├── cxa_network_tcpClient.c ├── cxa_network_tcpServer.c ├── cxa_network_tcpServer_connectedClient.c ├── http │ └── cxa_network_httpClient.c ├── lwipMbedTls │ ├── cxa_lwipMbedTls_network_factory.c │ ├── cxa_lwipMbedTls_network_tcpClient.c │ ├── cxa_lwipMbedTls_network_tcpServer.c │ └── cxa_lwipMbedTls_network_tcpServer_connectedClient.c └── wolfSslDialSocket │ ├── cxa_wolfSslDialSocket_network_factory.c │ └── cxa_wolfSslDialSocket_network_tcpClient.c ├── peripherals ├── cxa_lightSensor_ltr329.c ├── cxa_ltc2942.c ├── cxa_pca9555.c ├── cxa_pca9624.c ├── cxa_rgbLed_pca9624.c ├── cxa_tempRhSensor_si7021.c ├── cxa_tempSensor_si7050.c └── cxa_ws2812String.c ├── rpc ├── cxa_rpc_message.c ├── cxa_rpc_messageFactory.c ├── cxa_rpc_messageHandler.c ├── cxa_rpc_node.c └── cxa_rpc_nodeRemote.c ├── runLoop ├── cxa_oneShotTimer.c ├── cxa_runLoop.c └── cxa_softWatchDog.c ├── serial ├── cxa_ioStream.c ├── cxa_ioStream_bridge.c ├── cxa_ioStream_loopback.c ├── cxa_ioStream_nullablePassthrough.c ├── cxa_ioStream_peekable.c ├── cxa_ioStream_pipe.c ├── cxa_ioStream_tee.c ├── cxa_protocolParser.c ├── cxa_protocolParser_cleProto.c └── cxa_protocolParser_crlf.c ├── stateMachine └── cxa_stateMachine.c └── timeUtils └── cxa_timeDiff.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.d 2 | *.o 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2019 ovrEngineered, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /include/arch-atmega/cxa_atmega_adcChannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ATMEGA_ADCCHANNEL_H_ 8 | #define CXA_ATMEGA_ADCCHANNEL_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | /** 20 | * @public 21 | */ 22 | typedef struct cxa_atmega_adcChannel cxa_atmega_adcChannel_t; 23 | 24 | 25 | /** 26 | * @public 27 | */ 28 | typedef enum 29 | { 30 | CXA_ATM_ADCCHAN_0 = 0, 31 | CXA_ATM_ADCCHAN_1 = 1, 32 | CXA_ATM_ADCCHAN_2 = 2, 33 | CXA_ATM_ADCCHAN_3 = 3, 34 | CXA_ATM_ADCCHAN_4 = 4, 35 | CXA_ATM_ADCCHAN_5 = 5, 36 | CXA_ATM_ADCCHAN_6 = 6, 37 | CXA_ATM_ADCCHAN_7 = 7 38 | }cxa_atmega_adcChannel_id_t; 39 | 40 | 41 | typedef enum 42 | { 43 | CXA_ATM_ADCCHAN_REF_AREF = 0, 44 | CXA_ATM_ADCCHAN_REF_AVCC = 1, 45 | CXA_ATM_ADCCHAN_REF_INTERNAL = 3 46 | }cxa_atmega_adcChannel_reference_t; 47 | 48 | 49 | /** 50 | * @private 51 | */ 52 | struct cxa_atmega_adcChannel 53 | { 54 | cxa_adcChannel_t super; 55 | 56 | cxa_atmega_adcChannel_id_t chanId; 57 | cxa_atmega_adcChannel_reference_t reference; 58 | }; 59 | 60 | 61 | // ******** global function prototypes ******** 62 | /** 63 | * @public 64 | */ 65 | void cxa_atmega_adcChannel_init(cxa_atmega_adcChannel_t* const adcChanIn, const cxa_atmega_adcChannel_id_t chanIdIn, 66 | const cxa_atmega_adcChannel_reference_t referenceIn); 67 | 68 | 69 | #endif /* CXA_ATMEGA_ADCCHANNEL_H_ */ 70 | -------------------------------------------------------------------------------- /include/arch-atmega/cxa_atmega_i2cSlave.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ATMEGA_I2CSLAVE_H_ 8 | #define CXA_ATMEGA_I2CSLAVE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | #ifndef CXA_ATM_I2CSLAVE_MAXWRITE_SIZE_BYTES 20 | #define CXA_ATM_I2CSLAVE_MAXOP_SIZE_BYTES 16 21 | #endif 22 | 23 | 24 | // ******** global type definitions ********* 25 | /** 26 | * @public 27 | */ 28 | typedef struct cxa_atmega_i2cSlave cxa_atmega_i2cSlave_t; 29 | 30 | 31 | /** 32 | * @public 33 | */ 34 | typedef enum 35 | { 36 | CXA_ATM_I2CSLAVE_TWI0, 37 | CXA_ATM_I2CSLAVE_TWI1 38 | }cxa_atmega_i2cSlave_twi_t; 39 | 40 | 41 | /** 42 | * @private 43 | */ 44 | typedef enum 45 | { 46 | CXA_ATM_I2CSLAVE_STATE_IDLE, 47 | CXA_ATM_I2CSLAVE_STATE_WAIT_COMMAND_BYTE, 48 | CXA_ATM_I2CSLAVE_STATE_GOT_COMMAND_BYTE, 49 | CXA_ATM_I2CSLAVE_STATE_RX_BYTES, 50 | CXA_ATM_I2CSLAVE_STATE_TX_BYTES, 51 | CXA_ATM_I2CSLAVE_STATE_NACK_REST, 52 | }cxa_atmega_i2cSlave_state_t; 53 | 54 | 55 | /** 56 | * @private 57 | */ 58 | struct cxa_atmega_i2cSlave 59 | { 60 | cxa_i2cSlave_t super; 61 | 62 | cxa_atmega_i2cSlave_twi_t twiIn; 63 | 64 | cxa_atmega_i2cSlave_state_t state; 65 | uint8_t currCommandByte; 66 | uint8_t currTxByteIndex; 67 | ssize_t expectedNumRxBytes; 68 | 69 | cxa_fixedByteBuffer_t buffer; 70 | uint8_t buffer_raw[CXA_ATM_I2CSLAVE_MAXOP_SIZE_BYTES]; 71 | }; 72 | 73 | 74 | // ******** global function prototypes ******** 75 | void cxa_atmega_i2cSlave_init(cxa_atmega_i2cSlave_t *const i2cIn, 76 | const cxa_atmega_i2cSlave_twi_t twiIn, 77 | uint8_t address_7bitIn); 78 | 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /include/arch-atmega/cxa_atmega_led_pwm8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ATMEGA_LED_PWM8_H_ 8 | #define CXA_ATMEGA_LED_PWM8_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | typedef struct 21 | { 22 | cxa_led_runLoop_t super; 23 | 24 | cxa_atmega_timer_ocr_t* ocr; 25 | }cxa_atmega_led_pwm8_t; 26 | 27 | 28 | // ******** global function prototypes ******** 29 | void cxa_atmega_led_pwm8_init(cxa_atmega_led_pwm8_t *const ledIn, cxa_atmega_timer_ocr_t *const ocrIn, int threadIdIn); 30 | 31 | 32 | #endif /* CXA_ATMEGA_LED_PWM8_H_ */ 33 | -------------------------------------------------------------------------------- /include/arch-atmega/cxa_atmega_timeBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ATMEGA_TIMEBASE_H_ 8 | #define CXA_ATMEGA_TIMEBASE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | 21 | 22 | // ******** global function prototypes ******** 23 | /** 24 | * @public 25 | */ 26 | void cxa_atmega_timeBase_initWithTimer8(cxa_atmega_timer_t *const timerIn); 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/arch-atmega/cxa_atmega_usart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ATMEGA_USART_H_ 8 | #define CXA_ATMEGA_USART_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | // ******** global macro definitions ******** 21 | 22 | 23 | // ******** global type definitions ********* 24 | /** 25 | * @public 26 | * @brief "Forward" declaration of the cxa_atmega_usart_t object 27 | */ 28 | typedef struct cxa_atmega_usart cxa_atmega_usart_t; 29 | 30 | 31 | /** 32 | * @public 33 | */ 34 | typedef enum 35 | { 36 | CXA_ATM_USART_ID_0 37 | }cxa_atmega_usart_id_t; 38 | 39 | 40 | /** 41 | * @private 42 | */ 43 | struct cxa_atmega_usart 44 | { 45 | cxa_usart_t super; 46 | 47 | cxa_atmega_usart_id_t usartId; 48 | }; 49 | 50 | 51 | // ******** global function prototypes ******** 52 | /** 53 | * @public 54 | * @brief Initializes the specified USART for no hardware handshaking using the specified baud rate. 55 | * 56 | * @param[in] usartIn pointer to a pre-allocated USART object 57 | * @param[in] usartIdIn the UARTID specifying the desired UART 58 | * @param[in] baudRate_bpsIn the desired baud rate, in bits-per-second 59 | */ 60 | void cxa_atmega_usart_init_noHH(cxa_atmega_usart_t *const usartIn, cxa_atmega_usart_id_t usartIdIn, const uint32_t baudRate_bpsIn); 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/arch-atmega/sys/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @note This object should work across all architecture-specific implementations 5 | * 6 | * 7 | * #### Example Usage: #### 8 | * 9 | * @code 10 | * @endcode 11 | * 12 | * 13 | * @copyright 2015 opencxa.org 14 | * 15 | * Licensed under the Apache License, Version 2.0 (the "License"); 16 | * you may not use this file except in compliance with the License. 17 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | * @author Christopher Armenio 26 | */ 27 | #ifndef TYPES_H_ 28 | #define TYPES_H_ 29 | 30 | 31 | // ******** includes ******** 32 | 33 | 34 | // ******** global macro definitions ******** 35 | 36 | 37 | // ******** global type definitions ********* 38 | typedef long ssize_t; 39 | 40 | 41 | // ******** global function prototypes ******** 42 | 43 | 44 | #endif /* TYPES_H_ */ 45 | -------------------------------------------------------------------------------- /include/arch-bgm/cxa_bgm_i2cMaster.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_BGM_I2C_MASTER_H_ 8 | #define CXA_BGM_I2C_MASTER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | 20 | 21 | // ******** global type definitions ********* 22 | /** 23 | * @public 24 | * @brief "Forward" declaration of the cxa_bgm_i2cMaster_t object 25 | */ 26 | typedef struct cxa_bgm_i2cMaster cxa_bgm_i2cMaster_t; 27 | 28 | 29 | /** 30 | * @private 31 | */ 32 | typedef struct 33 | { 34 | GPIO_Port_TypeDef port; 35 | unsigned int pinNum; 36 | uint32_t loc; 37 | }cxa_bgm_pinSetup_t; 38 | 39 | 40 | /** 41 | * @private 42 | */ 43 | struct cxa_bgm_i2cMaster 44 | { 45 | cxa_i2cMaster_t super; 46 | 47 | I2C_TypeDef* i2cPort; 48 | 49 | cxa_bgm_pinSetup_t sda; 50 | cxa_bgm_pinSetup_t scl; 51 | }; 52 | 53 | 54 | // ******** global function prototypes ******** 55 | /** 56 | * @protected 57 | */ 58 | void cxa_bgm_i2cMaster_init(cxa_bgm_i2cMaster_t *const i2cIn, I2C_TypeDef *const i2cPortIn, 59 | const GPIO_Port_TypeDef sdaPortNumIn, const unsigned int sdaPinNumIn, uint32_t sdaLocIn, 60 | const GPIO_Port_TypeDef sclPortNumIn, const unsigned int sclPinNumIn, uint32_t sclLocIn); 61 | 62 | 63 | #endif // CXA_BGM_I2C_H_ 64 | -------------------------------------------------------------------------------- /include/arch-bgm/cxa_bgm_nvsManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ovrEngineered, LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is furnished to 9 | * do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 15 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 16 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 17 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 18 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 19 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | * 21 | * @author Christopher Armenio 22 | */ 23 | #ifndef CXA_BGM_NVSMANAGER_H_ 24 | #define CXA_BGM_NVSMANAGER_H_ 25 | 26 | 27 | // ******** includes ******** 28 | #include 29 | #include 30 | 31 | 32 | // ******** global macro definitions ******** 33 | #define CXA_BGM_NVSMANAGER_MAX_KEY_LEN_BYTES 16 34 | 35 | 36 | // ******** global type definitions ********* 37 | /* 38 | * @public 39 | */ 40 | typedef struct 41 | { 42 | uint16_t handle; 43 | const char key[CXA_BGM_NVSMANAGER_MAX_KEY_LEN_BYTES+1]; 44 | }cxa_bgm_nvsManager_keyToHandleMapEntry_t; 45 | 46 | 47 | // ******** global function prototypes ******** 48 | /** 49 | * @public 50 | */ 51 | void cxa_bgm_nvsManager_init(const cxa_bgm_nvsManager_keyToHandleMapEntry_t *const mapIn, size_t numEntriesIn); 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/arch-common/cxa_adcEmaSampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ADCEMASAMPLER_H_ 8 | #define CXA_ADCEMASAMPLER_H_ 9 | 10 | 11 | // Exponential moving average sampler 12 | 13 | 14 | // ******** includes ******** 15 | #include 16 | #include 17 | 18 | 19 | // ******** global macro definitions ******** 20 | 21 | 22 | // ******** global type definitions ********* 23 | /** 24 | * @public 25 | */ 26 | typedef struct cxa_adcEmaSampler cxa_adcEmaSampler_t; 27 | 28 | 29 | /** 30 | * @public 31 | */ 32 | typedef struct 33 | { 34 | float currAverage_v; 35 | float currDerivative_vps; 36 | }cxa_adcEmaSampler_retVal_t; 37 | 38 | 39 | /** 40 | * @private 41 | */ 42 | struct cxa_adcEmaSampler 43 | { 44 | cxa_adcChannel_t* adcChan; 45 | 46 | float smoothingConstant; 47 | float samplePeriod_sec; 48 | 49 | float currVal_v; 50 | float prevVal_v; 51 | }; 52 | 53 | 54 | // ******** global function prototypes ******** 55 | /** 56 | * @public 57 | * 58 | * @param smoothingConstantIn 0.0 (more weight to older values) - 1.0 (more weight to newer values) 59 | */ 60 | void cxa_adcEmaSampler_init(cxa_adcEmaSampler_t *const adcSampIn, cxa_adcChannel_t *const adcChanIn, float smoothingConstantIn, uint32_t samplePeriod_msIn, int threadIdIn); 61 | 62 | 63 | /** 64 | * @public 65 | */ 66 | void cxa_adcEmaSampler_resetAverage(cxa_adcEmaSampler_t *const adcSampIn); 67 | 68 | 69 | /** 70 | * @public 71 | */ 72 | cxa_adcEmaSampler_retVal_t cxa_adcEmaSampler_getCurrentAverage(cxa_adcEmaSampler_t *const adcSampIn); 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /include/arch-common/cxa_batteryCapacityEstimator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_BATTERYCAPACITYESTIMATOR_H_ 8 | #define CXA_BATTERYCAPACITYESTIMATOR_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | /** 20 | * @public 21 | */ 22 | typedef struct cxa_batteryCapacityEstimator cxa_batteryCapacityEstimator_t; 23 | 24 | 25 | /** 26 | * @public 27 | */ 28 | typedef void (*cxa_batteryCapacityEstimator_cb_updatedValue_t)(cxa_batteryCapacityEstimator_t *const cbeIn, bool wasSuccessfulIn, float battPcntIn, void* userVarIn); 29 | 30 | 31 | /** 32 | * @private 33 | */ 34 | struct cxa_batteryCapacityEstimator 35 | { 36 | cxa_adcChannel_t* adc_battVoltage; 37 | 38 | float battVoltMult; 39 | float maxVoltage; 40 | float minVoltage; 41 | 42 | cxa_batteryCapacityEstimator_cb_updatedValue_t cb_updateValue; 43 | void* userVar; 44 | }; 45 | 46 | 47 | // ******** global function prototypes ******** 48 | void cxa_batteryCapacityEstimator_init(cxa_batteryCapacityEstimator_t *const bceIn, cxa_adcChannel_t* adcIn, float battVoltMultIn, float maxVoltageIn, float minVoltageIn); 49 | 50 | bool cxa_batteryCapacityEstimator_getValue_withCallback(cxa_batteryCapacityEstimator_t *const bceIn, cxa_batteryCapacityEstimator_cb_updatedValue_t cbIn, void* userVarIn); 51 | 52 | 53 | #endif /* CXA_BATTERYCAPACITYESTIMATOR_H_ */ 54 | -------------------------------------------------------------------------------- /include/arch-common/cxa_delay.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | 8 | /** 9 | * @file 10 | * This file contains functions for delaying continued execution by a fixed amount of time. 11 | * 12 | * 13 | * #### Example Usage: #### 14 | * 15 | * @code 16 | * // start here @ 0sec 17 | * cxa_delay_ms(1000); 18 | * // reach here @ 1sec 19 | * @endcode 20 | */ 21 | #ifndef CXA_DELAY_H_ 22 | #define CXA_DELAY_H_ 23 | 24 | 25 | // ******** includes ******** 26 | #include 27 | 28 | 29 | // ******** global macro definitions ******** 30 | 31 | 32 | // ******** global type definitions ********* 33 | 34 | 35 | // ******** global function prototypes ******** 36 | /** 37 | * @public 38 | * @brief Delays for a fixed number of milliseconds 39 | * 40 | * @param[in] delay_msIn the number of milliseconds for which to delay 41 | */ 42 | void cxa_delay_ms(uint16_t delay_msIn); 43 | 44 | 45 | /** 46 | * @public 47 | * @brief Delays for a fixed number of microseconds 48 | * 49 | * @param[in] delay_usIn the number of microseconds for which to delay 50 | */ 51 | void cxa_delay_us(uint32_t delay_usIn); 52 | 53 | 54 | #endif // CXA_DELAY_H_ 55 | -------------------------------------------------------------------------------- /include/arch-common/cxa_gpio_debouncer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_GPIO_DEBOUNCER_H_ 8 | #define CXA_GPIO_DEBOUNCER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | #ifndef CXA_GPIO_DEBOUNCER_MAXNUM_LISTENERS 20 | #define CXA_GPIO_DEBOUNCER_MAXNUM_LISTENERS 1 21 | #endif 22 | 23 | 24 | // ******** global type definitions ********* 25 | /** 26 | * @public 27 | */ 28 | typedef struct cxa_gpio_debouncer cxa_gpio_debouncer_t; 29 | 30 | 31 | /** 32 | * @public 33 | */ 34 | typedef void (*cxa_gpio_debouncer_cb_onTransition_t)(bool newVal, void *userVarIn); 35 | 36 | 37 | typedef struct 38 | { 39 | cxa_gpio_debouncer_cb_onTransition_t cb_onTransition; 40 | void *userVar; 41 | }cxa_gpio_debouncer_listenerEntry_t; 42 | 43 | 44 | /** 45 | * @private 46 | */ 47 | struct cxa_gpio_debouncer 48 | { 49 | cxa_timeDiff_t td_debounce; 50 | cxa_gpio_t* gpio; 51 | 52 | bool prevVal; 53 | bool isInTimeoutPeriod; 54 | 55 | cxa_array_t listeners; 56 | cxa_gpio_debouncer_listenerEntry_t listeners_raw[CXA_GPIO_DEBOUNCER_MAXNUM_LISTENERS]; 57 | }; 58 | 59 | 60 | // ******** global function prototypes ******** 61 | void cxa_gpio_debouncer_init(cxa_gpio_debouncer_t *const debounceIn, cxa_gpio_t *const gpioIn, int threadIdIn); 62 | 63 | void cxa_gpio_debouncer_addListener(cxa_gpio_debouncer_t *const debouncerIn, cxa_gpio_debouncer_cb_onTransition_t cb_onTransition, void *userVarIn); 64 | 65 | bool cxa_gpio_debouncer_getCurrentValue(cxa_gpio_debouncer_t *const debouncerIn); 66 | 67 | #endif // CXA_GPIO_DEBOUNCER_H_ 68 | -------------------------------------------------------------------------------- /include/arch-common/cxa_gpio_longPressManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_GPIO_LONGPRESSMANAGER_H_ 8 | #define CXA_GPIO_LONGPRESSMANAGER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | #ifndef CXA_GPIO_LONGPRESSMANAGER_MAXNUM_SEGMENTS 19 | #define CXA_GPIO_LONGPRESSMANAGER_MAXNUM_SEGMENTS 3 20 | #endif 21 | 22 | 23 | // ******** global type definitions ********* 24 | /** 25 | * @public 26 | */ 27 | typedef void (*cxa_gpio_longPressManager_cb_t)(void* userVarIn); 28 | 29 | 30 | /** 31 | * @private 32 | */ 33 | typedef struct 34 | { 35 | uint16_t minHoldTime_msIn; 36 | uint16_t maxHoldTime_msIn; 37 | 38 | cxa_gpio_longPressManager_cb_t cb_segmentEnter; 39 | cxa_gpio_longPressManager_cb_t cb_segmentLeave; 40 | cxa_gpio_longPressManager_cb_t cb_segmentSelected; 41 | 42 | void* userVar; 43 | }cxa_gpio_longPressManager_segment_t; 44 | 45 | 46 | /** 47 | * @private 48 | */ 49 | typedef struct 50 | { 51 | cxa_gpio_t* gpio; 52 | bool gpio_lastVal; 53 | 54 | uint32_t holdStartTime_ms; 55 | cxa_gpio_longPressManager_segment_t* currSegment; 56 | 57 | cxa_array_t segments; 58 | cxa_gpio_longPressManager_segment_t segments_raw[CXA_GPIO_LONGPRESSMANAGER_MAXNUM_SEGMENTS]; 59 | }cxa_gpio_longPressManager_t; 60 | 61 | 62 | // ******** global function prototypes ******** 63 | void cxa_gpio_longPressManager_init(cxa_gpio_longPressManager_t *const lpmIn, cxa_gpio_t *const gpioIn, int threadIdIn); 64 | 65 | bool cxa_gpio_longPressManager_addSegment(cxa_gpio_longPressManager_t *const lpmIn, 66 | uint16_t minHoldTime_msIn, uint16_t maxHoldTime_msIn, 67 | cxa_gpio_longPressManager_cb_t cb_segmentEnterIn, 68 | cxa_gpio_longPressManager_cb_t cb_segmentLeaveIn, 69 | cxa_gpio_longPressManager_cb_t cb_segmentSelectedIn, 70 | void* userVarIn); 71 | 72 | bool cxa_gpio_longPressManager_isPressed(cxa_gpio_longPressManager_t *const lpmIn); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /include/arch-common/cxa_gpio_simpleCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_GPIO_SIMPLECALLBACK_H_ 8 | #define CXA_GPIO_SIMPLECALLBACK_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | /** 20 | * @public 21 | * @brief "Forward" declaration of the cxa_gpio_simpleCallback_t object 22 | */ 23 | typedef struct cxa_gpio_simpleCallback cxa_gpio_simpleCallback_t; 24 | 25 | 26 | /** 27 | @public 28 | */ 29 | typedef bool (*cxa_gpio_simpleCallback_getValue_t)(cxa_gpio_t *const superIn, int userIdIn); 30 | typedef void (*cxa_gpio_simpleCallback_setValue_t)(cxa_gpio_t *const superIn, int userIdIn, bool valueIn); 31 | 32 | 33 | /** 34 | * @private 35 | */ 36 | struct cxa_gpio_simpleCallback 37 | { 38 | cxa_gpio_t super; 39 | 40 | cxa_gpio_polarity_t polarity; 41 | cxa_gpio_direction_t dir; 42 | 43 | int userId; 44 | cxa_gpio_simpleCallback_getValue_t cb_getValue; 45 | cxa_gpio_simpleCallback_setValue_t cb_setValue; 46 | 47 | bool lastVal; 48 | }; 49 | 50 | 51 | // ******** global function prototypes ******** 52 | /** 53 | * @public 54 | * @brief Initializes the simpleCallback GPIO object for immediate use as an input. 55 | * 56 | * @param[in] gpioIn pointer to a pre-allocated pic32 GPIO object 57 | * @param[in] userIdIn pin number describing which pin to use 58 | * @param[in] polarityIn the polarity of the GPIO pin. See @ref cxa_gpio.h for a discussion of polarity. 59 | */ 60 | void cxa_gpio_simpleCallback_init_input(cxa_gpio_simpleCallback_t *const gpioIn, const int userIdIn, 61 | cxa_gpio_simpleCallback_getValue_t cb_getValueIn, 62 | cxa_gpio_simpleCallback_setValue_t cb_setValueIn, 63 | const cxa_gpio_polarity_t polarityIn); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /include/arch-common/cxa_led.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_LED_H_ 8 | #define CXA_LED_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | /** 21 | * @public 22 | */ 23 | typedef struct cxa_led cxa_led_t; 24 | 25 | 26 | /** 27 | * @public 28 | */ 29 | typedef enum 30 | { 31 | CXA_LED_STATE_SOLID, 32 | CXA_LED_STATE_BLINK, 33 | CXA_LED_STATE_FLASH_ONCE 34 | }cxa_led_state_t; 35 | 36 | 37 | /** 38 | * @protected 39 | */ 40 | typedef void (*cxa_led_scm_blink_t)(cxa_led_t *const superIn, uint8_t onBrightness_255In, uint32_t onPeriod_msIn, uint32_t offPeriod_msIn); 41 | 42 | 43 | /** 44 | * @protected 45 | */ 46 | typedef void (*cxa_led_scm_setSolid_t)(cxa_led_t *const superIn, uint8_t brightness_255In); 47 | 48 | 49 | /** 50 | * @protected 51 | */ 52 | typedef void (*cxa_led_scm_flashOnce_t)(cxa_led_t *const superIn, uint8_t brightness_255In, uint32_t period_msIn); 53 | 54 | 55 | struct cxa_led 56 | { 57 | cxa_led_state_t currState; 58 | cxa_led_state_t prevState; 59 | 60 | cxa_led_scm_blink_t scm_blink; 61 | cxa_led_scm_setSolid_t scm_setSolid; 62 | cxa_led_scm_flashOnce_t scm_flashOnce; 63 | }; 64 | 65 | 66 | // ******** global function prototypes ******** 67 | /** 68 | * @protected 69 | */ 70 | void cxa_led_init(cxa_led_t *const ledIn, 71 | cxa_led_scm_setSolid_t scm_setSolidIn, 72 | cxa_led_scm_blink_t scm_blinkIn, 73 | cxa_led_scm_flashOnce_t scm_flashOnceIn); 74 | 75 | void cxa_led_blink(cxa_led_t *const ledIn, uint8_t onBrightness_255In, uint32_t onPeriod_msIn, uint32_t offPeriod_msIn); 76 | void cxa_led_flashOnce(cxa_led_t *const ledIn, uint8_t brightness_255In, uint32_t period_msIn); 77 | void cxa_led_setSolid(cxa_led_t *const ledIn, uint8_t brightness_255In); 78 | 79 | 80 | #endif /* CXA_LED_H_ */ 81 | -------------------------------------------------------------------------------- /include/arch-common/cxa_led_gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_LED_GPIO_H_ 8 | #define CXA_LED_GPIO_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | typedef struct 21 | { 22 | cxa_led_runLoop_t super; 23 | 24 | cxa_gpio_t* gpio; 25 | }cxa_led_gpio_t; 26 | 27 | 28 | // ******** global function prototypes ******** 29 | void cxa_led_gpio_init(cxa_led_gpio_t *const ledIn, cxa_gpio_t *const gpioIn, int threadIdIn); 30 | 31 | 32 | #endif /* CXA_LED_GPIO_H_ */ 33 | -------------------------------------------------------------------------------- /include/arch-common/cxa_led_runLoop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_LED_RUNLOOP_H_ 8 | #define CXA_LED_RUNLOOP_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | /** 22 | * @public 23 | */ 24 | typedef struct cxa_led_runLoop cxa_led_runLoop_t; 25 | 26 | 27 | /** 28 | * @public 29 | */ 30 | typedef void (*cxa_led_runLoop_scm_setBrightness_t)(cxa_led_runLoop_t *const superIn, const uint8_t brightness_255In); 31 | 32 | 33 | /** 34 | * @private 35 | */ 36 | struct cxa_led_runLoop 37 | { 38 | cxa_led_t super; 39 | 40 | cxa_timeDiff_t td_gp; 41 | 42 | struct 43 | { 44 | uint8_t onBrightness_255; 45 | bool wasOn; 46 | uint32_t onPeriod_ms; 47 | uint32_t offPeriod_ms; 48 | }blink; 49 | 50 | struct 51 | { 52 | uint32_t period_ms; 53 | }flash; 54 | 55 | struct 56 | { 57 | uint8_t lastBrightness_255; 58 | }solid; 59 | 60 | struct 61 | { 62 | cxa_led_runLoop_scm_setBrightness_t setBrightness; 63 | }scms; 64 | }; 65 | 66 | 67 | // ******** global function prototypes ******** 68 | /** 69 | * @protected 70 | */ 71 | void cxa_led_runLoop_init(cxa_led_runLoop_t *const ledIn, 72 | cxa_led_runLoop_scm_setBrightness_t scm_setBrightnessIn, 73 | int threadIdIn); 74 | 75 | 76 | #endif /* CXA_LED_RUNLOOP_H_ */ 77 | -------------------------------------------------------------------------------- /include/arch-common/cxa_lightSensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_LIGHTSENSOR_H_ 8 | #define CXA_LIGHTSENSOR_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | /** 21 | * @public 22 | */ 23 | typedef struct cxa_lightSensor cxa_lightSensor_t; 24 | 25 | 26 | /** 27 | * @public 28 | */ 29 | typedef void (*cxa_lightSensor_cb_updatedValue_t)(cxa_lightSensor_t *const lightSnsIn, bool wasSuccessfulIn, bool valueDidChangeIn, uint8_t newLight_255In, void* userVarIn); 30 | 31 | 32 | /** 33 | * @protected 34 | */ 35 | typedef bool (*cxa_lightSensor_scm_requestNewValue_t)(cxa_lightSensor_t *const superIn); 36 | 37 | 38 | /** 39 | * @private 40 | */ 41 | struct cxa_lightSensor 42 | { 43 | cxa_lightSensor_scm_requestNewValue_t scm_requestNewValue; 44 | 45 | bool wasLastReadSuccessful; 46 | uint8_t lastReading_255; 47 | 48 | cxa_lightSensor_cb_updatedValue_t cb_onUpdate; 49 | void* userVar; 50 | }; 51 | 52 | 53 | // ******** global function prototypes ******** 54 | /** 55 | * @protected 56 | */ 57 | void cxa_lightSensor_init(cxa_lightSensor_t *const lightSnsIn, cxa_lightSensor_scm_requestNewValue_t scm_requestNewValIn); 58 | 59 | 60 | /** 61 | * @public 62 | */ 63 | bool cxa_lightSensor_getValue_withCallback(cxa_lightSensor_t *const lightSnsIn, cxa_lightSensor_cb_updatedValue_t cbIn, void* userVarIn); 64 | 65 | 66 | /** 67 | * @public 68 | */ 69 | bool cxa_lightSensor_wasLastReadSuccessful(cxa_lightSensor_t *const lightSnsIn); 70 | 71 | 72 | /** 73 | * @public 74 | */ 75 | uint8_t cxa_lightSensor_getLastValue_255(cxa_lightSensor_t *const lightSnsIn); 76 | 77 | 78 | /** 79 | * @protected 80 | */ 81 | void cxa_lightSensor_notify_updatedValue(cxa_lightSensor_t *const lightSnsIn, bool wasSuccessfulIn, uint8_t newLight_255In); 82 | 83 | 84 | #endif /* CXA_LIGHTSENSOR_H_ */ 85 | -------------------------------------------------------------------------------- /include/arch-common/cxa_mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MUTEX_H_ 8 | #define CXA_MUTEX_H_ 9 | 10 | 11 | // ******** includes ******** 12 | 13 | 14 | // ******** global macro definitions ******** 15 | 16 | 17 | // ******** global type definitions ********* 18 | /** 19 | * @public 20 | */ 21 | typedef struct cxa_mutex cxa_mutex_t; 22 | 23 | 24 | /** 25 | * @private 26 | */ 27 | struct cxa_mutex 28 | { 29 | void* placeholder; 30 | }; 31 | 32 | 33 | // ******** global function prototypes ******** 34 | cxa_mutex_t* cxa_mutex_reserve(void); 35 | 36 | void cxa_mutex_aquire(cxa_mutex_t *const mutexIn); 37 | 38 | void cxa_mutex_release(cxa_mutex_t *const mutexIn); 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/arch-common/cxa_nvsManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_NVS_MANAGER_H_ 8 | #define CXA_NVS_MANAGER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | 22 | 23 | // ******** global function prototypes ******** 24 | bool cxa_nvsManager_doesKeyExist(const char *const keyIn); 25 | 26 | bool cxa_nvsManager_get_cString(const char *const keyIn, char *const valueOut, size_t maxOutputSize_bytes); 27 | void cxa_nvsManager_get_cString_withDefault(const char *const keyIn, char *const valueOut, size_t maxOutputSize_bytes, char *const defaultIn); 28 | bool cxa_nvsManager_set_cString(const char *const keyIn, char *const valueIn); 29 | 30 | bool cxa_nvsManager_get_uint8(const char *const keyIn, uint8_t *const valueOut); 31 | void cxa_nvsManager_get_uint8_withDefault(const char *const keyIn, uint8_t *const valueOut, uint8_t defaultIn); 32 | bool cxa_nvsManager_set_uint8(const char *const keyIn, uint8_t valueIn); 33 | 34 | bool cxa_nvsManager_get_uint32(const char *const keyIn, uint32_t *const valueOut); 35 | void cxa_nvsManager_get_uint32_withDefault(const char *const keyIn, uint32_t *const valueOut, uint32_t defaultIn); 36 | bool cxa_nvsManager_set_uint32(const char *const keyIn, uint32_t valueIn); 37 | 38 | bool cxa_nvsManager_get_float(const char *const keyIn, float *const valueOut); 39 | void cxa_nvsManager_get_float_withDefault(const char *const keyIn, float *const valueOut, float defaultIn); 40 | bool cxa_nvsManager_set_float(const char *const keyIn, float valueIn); 41 | 42 | bool cxa_nvsManager_get_blob(const char *const keyIn, uint8_t *const valueOut, size_t maxOutputSize_bytesIn, size_t *const actualOutputSize_bytesOut); 43 | bool cxa_nvsManager_set_blob(const char *const keyIn, uint8_t *const valueIn, size_t blobSize_bytesIn); 44 | 45 | bool cxa_nvsManager_erase(const char *const keyIn); 46 | bool cxa_nvsManager_eraseAll(void); 47 | 48 | bool cxa_nvsManager_commit(void); 49 | 50 | 51 | #endif /* CXA_NVS_MANAGER_H_ */ 52 | -------------------------------------------------------------------------------- /include/arch-common/cxa_random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_RANDOM_H_ 8 | #define CXA_RANDOM_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | 20 | 21 | // ******** global function prototypes ******** 22 | /** 23 | * @public 24 | * @brief Generates a *random* number between the provided 25 | * lower and upper limit (inclusive) 26 | * 27 | * Random numbers here are provided to the best of the ability 28 | * of the platform / architecture and may not be truly random. 29 | * 30 | * @param[in] lowerLimitIn lower limit of the output 31 | * @param[in] uperLimitIn upper limit of the output 32 | */ 33 | uint32_t cxa_random_numberInRange(uint32_t lowerLimitIn, uint32_t upperLimitIn); 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/arch-common/cxa_reboot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_REBOOT_H_ 8 | #define CXA_REBOOT_H_ 9 | 10 | 11 | // ******** includes ******** 12 | 13 | 14 | // ******** global macro definitions ******** 15 | 16 | 17 | // ******** global type definitions ********* 18 | 19 | 20 | // ******** global function prototypes ******** 21 | void cxa_reboot(void); 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/arch-common/cxa_rgbLed_runLoop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_RGBLED_RUNLOOP_H_ 8 | #define CXA_RGBLED_RUNLOOP_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | /** 22 | * @public 23 | */ 24 | typedef struct cxa_rgbLed_runLoop cxa_rgbLed_runLoop_t; 25 | 26 | 27 | /** 28 | * @public 29 | */ 30 | typedef void (*cxa_rgbLed_runLoop_scm_setRgb_t)(cxa_rgbLed_runLoop_t *const superIn, const uint8_t r_255In, const uint8_t g_255In, const uint8_t b_255In); 31 | 32 | 33 | /** 34 | * @private 35 | */ 36 | typedef struct 37 | { 38 | uint8_t rOn_255; 39 | uint8_t gOn_255; 40 | uint8_t bOn_255; 41 | 42 | uint32_t period_ms; 43 | }cxa_rgbLed_runLoop_altColorEntry_t; 44 | 45 | 46 | /** 47 | * @private 48 | */ 49 | struct cxa_rgbLed_runLoop 50 | { 51 | cxa_rgbLed_t super; 52 | 53 | cxa_timeDiff_t td_gp; 54 | 55 | struct 56 | { 57 | cxa_rgbLed_runLoop_altColorEntry_t colors[2]; 58 | uint8_t lastColorIndex; 59 | }alternate; 60 | 61 | struct 62 | { 63 | uint32_t period_ms; 64 | }flash; 65 | 66 | struct 67 | { 68 | uint8_t lastBrightnessR_255; 69 | uint8_t lastBrightnessG_255; 70 | uint8_t lastBrightnessB_255; 71 | }solid; 72 | 73 | struct 74 | { 75 | cxa_rgbLed_runLoop_scm_setRgb_t setRgb; 76 | }scms; 77 | }; 78 | 79 | 80 | // ******** global function prototypes ******** 81 | void cxa_rgbLed_runLoop_init(cxa_rgbLed_runLoop_t *const ledIn, 82 | cxa_rgbLed_runLoop_scm_setRgb_t scm_setRgbIn, 83 | int threadIdIn); 84 | 85 | 86 | #endif /* CXA_RGBLED_RUNLOOP_H_ */ 87 | -------------------------------------------------------------------------------- /include/arch-common/cxa_rgbLed_triLed.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_RGBLED_TRILED_H_ 8 | #define CXA_RGBLED_TRILED_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | /** 21 | * @public 22 | */ 23 | typedef struct cxa_rgbLed_triLed cxa_rgbLed_triLed_t; 24 | 25 | 26 | /** 27 | * @private 28 | */ 29 | struct cxa_rgbLed_triLed 30 | { 31 | cxa_rgbLed_runLoop_t super; 32 | 33 | cxa_led_t* led_r; 34 | cxa_led_t* led_g; 35 | cxa_led_t* led_b; 36 | }; 37 | 38 | 39 | // ******** global function prototypes ******** 40 | void cxa_rgbLed_triLed_init(cxa_rgbLed_triLed_t *const ledIn, 41 | cxa_led_t *const led_rIn, cxa_led_t *const led_gIn, cxa_led_t *const led_bIn, 42 | int threadIdIn); 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/arch-common/cxa_sntpClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_SNTPCLIENT_H_ 8 | #define CXA_SNTPCLIENT_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | typedef void (*cxa_sntpClient_cb_onInitialTimeSet_t)(void *const userVarIn); 21 | 22 | 23 | // ******** global function prototypes ******** 24 | void cxa_sntpClient_init(void); 25 | void cxa_sntpClient_addListener(cxa_sntpClient_cb_onInitialTimeSet_t cbIn, void *const userVarIn); 26 | bool cxa_sntpClient_isClockSet(void); 27 | 28 | uint32_t cxa_sntpClient_getUnixTimeStamp(void); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/arch-common/cxa_stepperMotorChannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_STEPPERMOTORCHANNEL_H_ 8 | #define CXA_STEPPERMOTORCHANNEL_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | /** 22 | * @public 23 | */ 24 | typedef struct cxa_stepperMotorChannel cxa_stepperMotorChannel_t; 25 | 26 | 27 | /** 28 | * @private 29 | */ 30 | typedef void (*cxa_stepperMotorChannel_timedCallback_t)(void); 31 | 32 | 33 | /** 34 | * @private 35 | */ 36 | struct cxa_stepperMotorChannel 37 | { 38 | cxa_gpio_t* gpio_step; 39 | 40 | int32_t currentStep; 41 | float targetStep; 42 | }; 43 | 44 | 45 | // ******** global function prototypes ******** 46 | /** 47 | * @public 48 | */ 49 | void cxa_stepperMotorChannel_initSubsystem(cxa_gpio_t *const gpioGlobalDirIn, cxa_gpio_t *const gpioGlobalEnableIn); 50 | 51 | 52 | /** 53 | * @public 54 | */ 55 | void cxa_stepperMotorChannel_init(cxa_stepperMotorChannel_t *const stepMtrChanIn, cxa_gpio_t *const gpio_stepIn); 56 | 57 | 58 | /** 59 | * @public 60 | */ 61 | void cxa_stepperMotorChannel_incrementTargetPosition(cxa_stepperMotorChannel_t *const stepMtrChanIn, float incrementStepsIn); 62 | 63 | 64 | /** 65 | * @public 66 | */ 67 | bool cxa_stepperMotorChannel_isStopped(cxa_stepperMotorChannel_t *const stepMtrChanIn); 68 | 69 | 70 | /** 71 | * @public 72 | */ 73 | void cxa_stepperMotorChannel_runContinuous(cxa_stepperMotorChannel_t *const stepMtrChanIn, bool forwardIn); 74 | 75 | 76 | /** 77 | * @public 78 | */ 79 | void cxa_stepperMotorChannel_stopMotion(cxa_stepperMotorChannel_t *const stepMtrChanIn); 80 | 81 | 82 | /** 83 | * @protected 84 | */ 85 | void cxa_stepperMotorChannel_registerTimedCallback(cxa_stepperMotorChannel_timedCallback_t cbIn, uint32_t stepFreq_hzIn); 86 | 87 | 88 | void cxa_stepperMotorChannel_forceEnable(bool forceEnableIn); 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /include/arch-common/cxa_uniqueId.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_UNIQUE_ID_H_ 8 | #define CXA_UNIQUE_ID_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | 22 | 23 | // ******** global function prototypes ******** 24 | void cxa_uniqueId_getBytes(uint8_t** bytesOut, size_t* numBytesOut); 25 | char* cxa_uniqueId_getHexString(void); 26 | 27 | 28 | #endif // CXA_UNIQUE_ID_H_ 29 | -------------------------------------------------------------------------------- /include/arch-dummy/cxa_dummy_gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_DUMMY_GPIO_H_ 8 | #define CXA_DUMMY_GPIO_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | 20 | 21 | // ******** global type definitions ********* 22 | /** 23 | * @public 24 | */ 25 | typedef struct cxa_dummy_gpio cxa_dummy_gpio_t; 26 | 27 | 28 | /** 29 | * @public 30 | */ 31 | struct cxa_dummy_gpio 32 | { 33 | cxa_gpio_t super; 34 | 35 | cxa_gpio_polarity_t polarity; 36 | cxa_gpio_direction_t dir; 37 | 38 | cxa_logger_t logger; 39 | }; 40 | 41 | 42 | // ******** global function prototypes ******** 43 | void cxa_dummy_gpio_init_input(cxa_dummy_gpio_t *const gpioIn, const cxa_gpio_polarity_t polarityIn); 44 | 45 | void cxa_dummy_gpio_init_output(cxa_dummy_gpio_t *const gpioIn, const cxa_gpio_polarity_t polarityIn, const bool initValIn); 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/arch-dummy/cxa_dummy_usart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_DUMMY_USART_H_ 8 | #define CXA_DUMMY_USART_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | // ******** global macro definitions ******** 21 | 22 | 23 | // ******** global type definitions ********* 24 | /** 25 | * @public 26 | * @brief "Forward" declaration of the cxa_dummy_usart_t object 27 | */ 28 | typedef struct cxa_dummy_usart cxa_dummy_usart_t; 29 | 30 | 31 | /** 32 | * @private 33 | */ 34 | struct cxa_dummy_usart 35 | { 36 | cxa_usart_t super; 37 | }; 38 | 39 | 40 | // ******** global function prototypes ******** 41 | /** 42 | * @public 43 | * @brief Initializes the specified USART for no hardware handshaking using the specified baud rate. 44 | * 45 | * @param[in] usartIn pointer to a pre-allocated USART object 46 | * @param[in] baudRate_bpsIn the desired baud rate, in bits-per-second 47 | */ 48 | void cxa_dummy_usart_init_noHH(cxa_dummy_usart_t *const usartIn, const uint32_t baudRate_bpsIn); 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/arch-esp32/btle/cxa_esp32_btle_central.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ESP32_BTLE_CENTRAL_H_ 8 | #define CXA_ESP32_BTLE_CENTRAL_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | #include 17 | 18 | 19 | // ******** global macro definitions ******** 20 | 21 | 22 | // ******** global type definitions ********* 23 | /** 24 | * @public 25 | */ 26 | typedef struct cxa_esp32_btle_central cxa_esp32_btle_central_t; 27 | 28 | 29 | /** 30 | * @private 31 | */ 32 | struct cxa_esp32_btle_central 33 | { 34 | cxa_btle_central_t super; 35 | 36 | bool shouldBeScanning; 37 | esp_ble_scan_type_t currScanType; 38 | 39 | cxa_logger_t logger; 40 | }; 41 | 42 | 43 | // ******** global function prototypes ******** 44 | /** 45 | * @protected 46 | */ 47 | void cxa_esp32_btle_central_init(cxa_esp32_btle_central_t *const btlecIn, int threadIdIn); 48 | 49 | 50 | /** 51 | * @protected 52 | */ 53 | void cxa_esp32_btle_central_handleEvent_gap(cxa_esp32_btle_central_t *const btlecIn, esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/arch-esp32/btle/cxa_esp32_btle_module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ESP32_BTLE_MODULE_H_ 8 | #define CXA_ESP32_BTLE_MODULE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | 21 | 22 | // ******** global function prototypes ******** 23 | /** 24 | * @public 25 | */ 26 | void cxa_esp32_btle_module_init(int threadIdIn); 27 | 28 | 29 | /** 30 | * @public 31 | */ 32 | //cxa_esp32_btle_central_t* cxa_esp32_btle_module_getBtleCentral(void); 33 | 34 | 35 | /** 36 | * @public 37 | */ 38 | cxa_esp32_btle_peripheral_t* cxa_esp32_btle_module_getBtlePeripheral(void); 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/arch-esp32/btle/cxa_esp32_btle_peripheral.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ESP32_BTLE_PERIPHERAL_H_ 8 | #define CXA_ESP32_BTLE_PERIPHERAL_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | #include 17 | #include 18 | #include "esp_gatts_api.h" 19 | 20 | 21 | // ******** global macro definitions ******** 22 | #define CXA_ESP32_BTLE_MAX_NOTIFICATION_LEN_BYTES (ESP_GATT_DEF_BLE_MTU_SIZE-3) 23 | 24 | 25 | // ******** global type definitions ********* 26 | /** 27 | * @public 28 | */ 29 | typedef struct cxa_esp32_btle_peripheral cxa_esp32_btle_peripheral_t; 30 | 31 | 32 | /** 33 | * @private 34 | */ 35 | typedef struct 36 | { 37 | cxa_btle_peripheral_charEntry_t *charEntry; 38 | uint16_t handle_service; 39 | uint16_t handle_char; 40 | }cxa_esp32_btle_handleCharMapEntry_t; 41 | 42 | 43 | /** 44 | * @private 45 | */ 46 | struct cxa_esp32_btle_peripheral 47 | { 48 | cxa_btle_peripheral_t super; 49 | 50 | esp_ble_adv_params_t advParams; 51 | esp_ble_adv_data_t advData; 52 | 53 | cxa_fixedByteBuffer_t fbb_advertData_manSpecific; 54 | uint8_t fbb_advertData_manSpecific_raw[CXA_BTLE_PERIPHERAL_ADVERT_MAX_SIZE_BYTES]; 55 | 56 | cxa_array_t handleCharMap; 57 | cxa_esp32_btle_handleCharMapEntry_t handleCharMap_raw[CXA_BTLE_PERIPHERAL_MAXNUM_CHAR_ENTRIES]; 58 | 59 | size_t currRegisteringCharEntryIndex; 60 | 61 | bool isConnected; 62 | esp_gatt_if_t currGattsIf; 63 | uint16_t currConnId; 64 | }; 65 | 66 | 67 | // ******** global function prototypes ******** 68 | /** 69 | * @protected 70 | */ 71 | void cxa_esp32_btle_peripheral_init(cxa_esp32_btle_peripheral_t *const btlepIn, int threadIdIn); 72 | 73 | 74 | /** 75 | * @protected 76 | */ 77 | void cxa_esp32_btle_peripheral_handleEvent_gap(cxa_esp32_btle_peripheral_t *const btlepIn, esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param); 78 | 79 | 80 | /** 81 | * @protected 82 | */ 83 | void cxa_esp32_btle_peripheral_handleEvent_gatts(cxa_esp32_btle_peripheral_t *const btlepIn, esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param); 84 | 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /include/arch-esp32/cxa_esp32_adcChannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ESP32_ADCCHANNEL_H_ 8 | #define CXA_ESP32_ADCCHANNEL_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include "driver/adc.h" 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | /** 21 | * @public 22 | */ 23 | typedef struct cxa_esp32_adcChannel cxa_esp32_adcChannel_t; 24 | 25 | 26 | /** 27 | * @private 28 | */ 29 | struct cxa_esp32_adcChannel 30 | { 31 | cxa_adcChannel_t super; 32 | 33 | adc_unit_t adcUnit; 34 | 35 | adc1_channel_t chan1; 36 | adc2_channel_t chan2; 37 | }; 38 | 39 | 40 | // ******** global function prototypes ******** 41 | void cxa_esp32_adcChannel_init_unit1(cxa_esp32_adcChannel_t *const adcChanIn, adc1_channel_t chanIn); 42 | void cxa_esp32_adcChannel_init_unit2(cxa_esp32_adcChannel_t *const adcChanIn, adc2_channel_t chanIn); 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/arch-esp32/cxa_esp32_eventManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ESP32_EVENTMANAGER_H_ 8 | #define CXA_ESP32_EVENTMANAGER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include "esp_event.h" 13 | 14 | 15 | // ******** global macro definitions ******** 16 | #ifndef CXA_ESP32_EVENTMGR_MAXNUM_LISTENERS 17 | #define CXA_ESP32_EVENTMGR_MAXNUM_LISTENERS 2 18 | #endif 19 | 20 | 21 | // ******** global type definitions ********* 22 | typedef void (*cxa_esp32_eventManager_cb_t)(system_event_t *eventIn, void *const userVarIn); 23 | 24 | 25 | // ******** global function prototypes ******** 26 | void cxa_esp32_eventManager_init(void); 27 | 28 | void cxa_esp32_eventManager_addListener(cxa_esp32_eventManager_cb_t cb_sta_startIn, 29 | cxa_esp32_eventManager_cb_t cb_sta_stopIn, 30 | cxa_esp32_eventManager_cb_t cb_sta_connectedIn, 31 | cxa_esp32_eventManager_cb_t cb_sta_disconnectedIn, 32 | cxa_esp32_eventManager_cb_t cb_sta_gotIpIn, 33 | cxa_esp32_eventManager_cb_t cb_eth_startIn, 34 | cxa_esp32_eventManager_cb_t cb_eth_stopIn, 35 | cxa_esp32_eventManager_cb_t cb_eth_connectedIn, 36 | cxa_esp32_eventManager_cb_t cb_eth_disconnectedIn, 37 | cxa_esp32_eventManager_cb_t cb_eth_gotIpIn, 38 | void *const userVarIn); 39 | 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/arch-esp32/cxa_esp32_i2cMaster.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ESP32_I2C_MASTER_H_ 8 | #define CXA_ESP32_I2C_MASTER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | #include "driver/i2c.h" 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | /** 22 | * @public 23 | * @brief "Forward" declaration of the cxa_esp32_i2cMaster_t object 24 | */ 25 | typedef struct cxa_esp32_i2cMaster cxa_esp32_i2cMaster_t; 26 | 27 | 28 | /** 29 | * @private 30 | */ 31 | struct cxa_esp32_i2cMaster 32 | { 33 | cxa_i2cMaster_t super; 34 | 35 | i2c_port_t i2cPort; 36 | 37 | i2c_config_t conf; 38 | }; 39 | 40 | 41 | // ******** global function prototypes ******** 42 | /** 43 | * @protected 44 | */ 45 | void cxa_esp32_i2cMaster_init(cxa_esp32_i2cMaster_t *const i2cIn, const i2c_port_t i2cPortIn, 46 | const gpio_num_t pinNum_sdaIn, const gpio_num_t pinNum_sclIn, 47 | const bool enablePullUpsIn, uint32_t busFreq_hzIn); 48 | 49 | 50 | #endif // CXA_BLUEGIGA_I2C_H_ 51 | -------------------------------------------------------------------------------- /include/arch-esp32/cxa_esp32_nvsManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ESP32_NVSMANAGER_H_ 8 | #define CXA_ESP32_NVSMANAGER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include "cxa_nvsManager.h" 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | 20 | 21 | // ******** global function prototypes ******** 22 | void cxa_esp32_nvsManager_init(void); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/arch-esp32/cxa_esp32_timeBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ESP32_TIMEBASE_H_ 8 | #define CXA_ESP32_TIMEBASE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | 21 | 22 | // ******** global function prototypes ******** 23 | /** 24 | * @public 25 | */ 26 | void cxa_esp32_timeBase_init(void); 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/arch-esp32/cxa_esp32_usart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ESP32_USART_H_ 8 | #define CXA_ESP32_USART_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | 23 | // ******** global macro definitions ******** 24 | 25 | 26 | // ******** global type definitions ********* 27 | /** 28 | * @public 29 | * @brief "Forward" declaration of the cxa_esp32_usart_t object 30 | */ 31 | typedef struct cxa_esp32_usart cxa_esp32_usart_t; 32 | 33 | 34 | /** 35 | * @private 36 | */ 37 | struct cxa_esp32_usart 38 | { 39 | cxa_usart_t super; 40 | 41 | uart_port_t uartId; 42 | }; 43 | 44 | 45 | // ******** global function prototypes ******** 46 | /** 47 | * @public 48 | * @brief Initializes the specified USART for no hardware handshaking using the specified baud rate. 49 | * 50 | * @param[in] usartIn pointer to a pre-allocated USART object 51 | * @param[in] uartIdIn the UARTID specifying the desired UART 52 | * @param[in] baudRate_bpsIn the desired baud rate, in bits-per-second 53 | */ 54 | void cxa_esp32_usart_init_noHH(cxa_esp32_usart_t *const usartIn, uart_port_t uartIdIn, const uint32_t baudRate_bpsIn, 55 | const gpio_num_t txPinIn, const gpio_num_t rxPinIn); 56 | 57 | void cxa_esp32_usart_init_HH(cxa_esp32_usart_t *const usartIn, uart_port_t uartIdIn, const uint32_t baudRate_bpsIn, 58 | const gpio_num_t txPinIn, const gpio_num_t rxPinIn, 59 | const gpio_num_t rtsPinIn, const gpio_num_t ctsPinIn); 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/arch-pic32/cxa_pic32_usart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_PIC32_USART_H_ 8 | #define CXA_PIC32_USART_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "system_definitions.h" 19 | 20 | 21 | // ******** global macro definitions ******** 22 | 23 | 24 | // ******** global type definitions ********* 25 | /** 26 | * @public 27 | * @brief "Forward" declaration of the cxa_pic32_usart_t object 28 | */ 29 | typedef struct cxa_pic32_usart cxa_pic32_usart_t; 30 | 31 | 32 | /** 33 | * @private 34 | */ 35 | struct cxa_pic32_usart 36 | { 37 | cxa_usart_t super; 38 | 39 | DRV_HANDLE usartHandle; 40 | }; 41 | 42 | 43 | // ******** global function prototypes ******** 44 | /** 45 | * @public 46 | * @brief Initializes the specified USART for no hardware handshaking using the specified baud rate. 47 | * 48 | * @param[in] usartIn pointer to a pre-allocated USART object 49 | * @param[in] uartHarmonyInstanceIn the Harmony instance of desired UART 50 | */ 51 | void cxa_pic32_usart_init(cxa_pic32_usart_t *const usartIn, int uartHarmonyInstanceIn); 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/arch-posix/cxa_ioStream_file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_IOSTREAM_FILE_H_ 8 | #define CXA_IOSTREAM_FILE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | /** 22 | * @public 23 | * @brief "Forward" declaration of the cxa_ioStream_file_t object 24 | */ 25 | typedef struct cxa_ioStream_file cxa_ioStream_file_t; 26 | 27 | 28 | struct cxa_ioStream_file 29 | { 30 | cxa_ioStream_t super; 31 | 32 | FILE* file; 33 | }; 34 | 35 | 36 | // ******** global function prototypes ******** 37 | void cxa_ioStream_file_init(cxa_ioStream_file_t *const ioStreamIn); 38 | void cxa_ioStream_file_setFile(cxa_ioStream_file_t *const ioStreamIn, FILE *const fileIn); 39 | void cxa_ioStream_file_close(cxa_ioStream_file_t *const ioStreamIn); 40 | 41 | #endif // CXA_IOSTREAM_FILE_H_ 42 | -------------------------------------------------------------------------------- /include/arch-posix/cxa_mqtt_rpc_node_posixShell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_RPC_NODE_POSIXSHELL_H_ 8 | #define CXA_MQTT_RPC_NODE_POSIXSHELL_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | /** 20 | * @public 21 | */ 22 | typedef struct cxa_mqtt_rpc_node_posixShell cxa_mqtt_rpc_node_posixShell_t; 23 | 24 | 25 | /** 26 | * @private 27 | */ 28 | struct cxa_mqtt_rpc_node_posixShell 29 | { 30 | cxa_mqtt_rpc_node_t super; 31 | }; 32 | 33 | 34 | // ******** global function prototypes ******** 35 | void cxa_mqtt_rpc_node_posixShell_init(cxa_mqtt_rpc_node_posixShell_t *const nodeIn, cxa_mqtt_rpc_node_t *const parentNodeIn); 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/arch-posix/cxa_posix_gpioConsole.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_POSIX_GPIOCONSOLE_H_ 8 | #define CXA_POSIX_GPIOCONSOLE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | typedef struct 21 | { 22 | cxa_gpio_t super; 23 | 24 | const char *name; 25 | cxa_gpio_direction_t currDir; 26 | cxa_gpio_polarity_t polarity; 27 | bool currVal; 28 | 29 | cxa_logger_t logger; 30 | }cxa_posix_gpioConsole_t; 31 | 32 | 33 | // ******** global function prototypes ******** 34 | void cxa_posix_gpioConsole_init_input(cxa_posix_gpioConsole_t *const gpioIn, const char *nameIn); 35 | void cxa_posix_gpioConsole_init_output(cxa_posix_gpioConsole_t *const gpioIn, const char *nameIn, const bool initValIn); 36 | void cxa_posix_gpioConsole_init_safe(cxa_posix_gpioConsole_t *const gpioIn, const char *nameIn); 37 | 38 | 39 | #endif // CXA_POSIX_GPIOCONSOLE_H_ 40 | -------------------------------------------------------------------------------- /include/arch-posix/cxa_posix_nvsManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_POSIX_NVSMANAGER_H_ 8 | #define CXA_POSIX_NVSMANAGER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | 13 | 14 | // ******** global macro definitions ******** 15 | 16 | 17 | // ******** global type definitions ********* 18 | 19 | 20 | // ******** global function prototypes ******** 21 | void cxa_posix_nvsManager_init(char *const nvsDirIn); 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/arch-tiC2K/cxa_tiC2K_gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_DUMMY_GPIO_H_ 8 | #define CXA_DUMMY_GPIO_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | // ******** global macro definitions ******** 20 | 21 | 22 | // ******** global type definitions ********* 23 | /** 24 | * @public 25 | */ 26 | typedef struct cxa_tiC2K_gpio cxa_tiC2K_gpio_t; 27 | 28 | 29 | /** 30 | * @public 31 | */ 32 | struct cxa_tiC2K_gpio 33 | { 34 | cxa_gpio_t super; 35 | 36 | cxa_gpio_polarity_t polarity; 37 | cxa_gpio_direction_t dir; 38 | 39 | //TI specific 40 | uint32_t pinConfig; 41 | uint32_t pin; 42 | GPIO_CoreSelect core; 43 | uint32_t pinType; 44 | // uint32_t outVal; 45 | 46 | bool lastVal; 47 | 48 | cxa_logger_t logger; 49 | }; 50 | 51 | 52 | // ******** global function prototypes ******** 53 | void cxa_tiC2K_gpio_init_input(cxa_tiC2K_gpio_t *const gpioIn, const uint32_t pinConfigIn, const uint32_t pinIn, const GPIO_CoreSelect coreIn, const uint32_t pinTypeIn, const cxa_gpio_polarity_t polarityIn); 54 | 55 | void cxa_tiC2K_gpio_init_output(cxa_tiC2K_gpio_t *const gpioIn, const uint32_t pinConfigIn, const uint32_t pinIn, const GPIO_CoreSelect coreIn, const uint32_t pinTypeIn, const cxa_gpio_polarity_t polarityIn, const bool initValIn); 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/arch-tiC2K/cxa_tiC2K_usart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_DUMMY_USART_H_ 8 | #define CXA_DUMMY_USART_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | // ******** global macro definitions ******** 22 | 23 | 24 | // ******** global type definitions ********* 25 | /** 26 | * @public 27 | * @brief "Forward" declaration of the cxa_tiC2K_usart_t object 28 | */ 29 | typedef struct cxa_tiC2K_usart cxa_tiC2K_usart_t; 30 | 31 | 32 | /** 33 | * @private 34 | */ 35 | struct cxa_tiC2K_usart 36 | { 37 | cxa_usart_t super; 38 | }; 39 | 40 | 41 | // ******** global function prototypes ******** 42 | /** 43 | * @public 44 | * @brief Initializes the specified USART for no hardware handshaking using the specified baud rate. 45 | * 46 | * @param[in] usartIn pointer to a pre-allocated USART object 47 | * @param[in] baudRate_bpsIn the desired baud rate, in bits-per-second 48 | */ 49 | void cxa_tiC2K_usart_init_noHH(cxa_tiC2K_usart_t *const usartIn, const uint32_t baudRate_bpsIn, 50 | const uint32_t txPinConfigIn, const uint32_t txPinIn, 51 | const uint32_t rxPinConfigIn, const uint32_t rxPinIn); 52 | 53 | void cxa_tiC2K_usart_init_HH_BT(cxa_tiC2K_usart_t *const usartIn, const uint32_t baudRate_bpsIn, 54 | const uint32_t txPinConfigIn, const uint32_t txPinIn, 55 | const uint32_t rxPinConfigIn, const uint32_t rxPinIn, 56 | const uint32_t ctsPinConfigIn, const uint32_t ctsPinIn); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/arch-tiC2K/strtok.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRTOK_H 2 | #define _STRTOK_H 3 | 4 | char * strtok_r (char *s, const char *delim, char **save_ptr); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/arch-xmega/cxa_xmega_ccp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | 8 | /** 9 | * @file 10 | * This file contains functions for writing to registers which are protected by the Configuration Change Protection (CCP) 11 | * mechanism. In general, these are system-critical registers which require some bit-twiddling and clock-cycle-critical 12 | * write period (things like clock selection, etc). 13 | * 14 | * @note This file contains functionality restricted to the CXA Atmel XMega implementation. 15 | * 16 | * 17 | * #### Example Usage: #### 18 | * 19 | * @code 20 | * // write 0x01 to CLK.CTRL 21 | * cxa_xmega_ccp_writeIo((void*)&CLK.CTRL, 0x01); 22 | * @endcode 23 | */ 24 | #ifndef CXA_XMEGA_CCP_H_ 25 | #define CXA_XMEGA_CCP_H_ 26 | 27 | 28 | // ******** includes ******** 29 | 30 | 31 | // ******** global macro definitions ******** 32 | 33 | 34 | // ******** global type definitions ********* 35 | 36 | 37 | // ******** global function prototypes ******** 38 | /** 39 | * @public 40 | * @brief Use this function to write the given byte to the provided CCP-protected register. 41 | * This function is implemented in assembly language to ensure proper access times after 42 | * triggering the CCP protection bit. 43 | * 44 | * @param[in] addr address of the target register which should be written (after being CCP unlocked) 45 | * @param[in] value the value to write to the target register 46 | */ 47 | extern void cxa_xmega_ccp_writeIo(void *addr, uint8_t value); 48 | 49 | 50 | #endif // CXA_XMEGA_CCP_H_ 51 | -------------------------------------------------------------------------------- /include/arch-xmega/cxa_xmega_ioStream_toFile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_XMEGA_IOSTREAM_TOFILE_H_ 8 | #define CXA_XMEGA_IOSTREAM_TOFILE_H_ 9 | 10 | 11 | /** 12 | * @file 13 | * 14 | * @author Christopher Armenio 15 | */ 16 | 17 | 18 | // ******** includes ******** 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | // ******** global macro definitions ******** 25 | 26 | 27 | // ******** global type definitions ********* 28 | 29 | 30 | // ******** global function prototypes ******** 31 | FILE* cxa_xmega_ioStream_toFile(cxa_ioStream_t *const ioStreamIn); 32 | 33 | #endif // CXA_XMEGA_IOSTREAM_TOFILE_H_ 34 | -------------------------------------------------------------------------------- /include/arch-xmega/cxa_xmega_timeBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | 8 | /** 9 | * @file 10 | * This file contains prototypes and an architecture-specific implementation of a 11 | * timeBase object for the XMega processor. A timeBase object is essentially a 12 | * monotonically increasing counter which can be used to calculate macro-scale, 13 | * relative timeouts (on the order of seconds and minutes). 14 | * 15 | * @note This file contains functionality restricted to the CXA Atmel XMega implementation. 16 | * 17 | * @note This file contains functionality in addition to that already provided in @ref cxa_timeBase.h 18 | * 19 | * 20 | * 21 | * #### Example Usage: #### 22 | * 23 | * @code 24 | * cxa_xmega_timeBase_t myTimeBase; 25 | * // timer: pre-initialized cxa_xmega_timer32_t object 26 | * cxa_xmega_timeBase_init_timer32(&myTimeBase, &timer); 27 | * 28 | * ... 29 | * 30 | * // now use the cxa_timeBase.h common functionality to get the current time 31 | * uint32_t currTime_us = cxa_timeBase_getCount_us(&myTimeBase.super); 32 | * @endcode 33 | */ 34 | #ifndef CXA_XMEGA_TIMEBASE_H_ 35 | #define CXA_XMEGA_TIMEBASE_H_ 36 | 37 | 38 | // ******** includes ******** 39 | #include 40 | #include 41 | 42 | 43 | // ******** global macro definitions ******** 44 | 45 | 46 | // ******** global type definitions ********* 47 | 48 | 49 | // ******** global function prototypes ******** 50 | /** 51 | * @public 52 | * @brief Initializes the timeBase object to use a pre-configured ::cxa_xmega_timer32_t object as a counter. 53 | * The ::cxa_xmega_timer32_t should have already been configured as a free-running timer with a 54 | * sane resolution (eg. such a resolution that the overflow period of the 32-bit timer is signficantly 55 | * longer than the longest time period measured with the timeBase) 56 | * 57 | * @param[in] timerIn pre-configured XMega 32-bit timer 58 | */ 59 | void cxa_xmega_timeBase_init_timer32(cxa_xmega_timer32_t *const timerIn); 60 | 61 | 62 | #endif // CXA_XMEGA_TIMEBASE_H_ 63 | -------------------------------------------------------------------------------- /include/btle/blueGiga/cxa_blueGiga_gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_BLUEGIGA_GPIO_H_ 8 | #define CXA_BLUEGIGA_GPIO_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | /** 22 | * @public 23 | * Forward declaration of blueGiga_btle_client to avoid 24 | * circular reference 25 | */ 26 | typedef struct cxa_blueGiga_btle_client cxa_blueGiga_btle_client_t; 27 | 28 | 29 | /** 30 | * @public 31 | */ 32 | typedef void (*cxa_blueGiga_gpio_cb_onGpiosConfigured_t)(cxa_blueGiga_btle_client_t* btlecIn, bool wasSuccessfulIn); 33 | 34 | 35 | /** 36 | * @private 37 | */ 38 | typedef struct 39 | { 40 | cxa_gpio_t super; 41 | 42 | bool isUsed; 43 | 44 | cxa_blueGiga_btle_client_t* btlec; 45 | uint8_t portNum; 46 | uint8_t chanNum; 47 | 48 | cxa_gpio_polarity_t polarity; 49 | cxa_gpio_direction_t lastDirection; 50 | bool lastOutputVal; 51 | }cxa_blueGiga_gpio_t; 52 | 53 | 54 | // ******** global function prototypes ******** 55 | /** 56 | * @protected 57 | */ 58 | void cxa_blueGiga_gpio_init(cxa_blueGiga_gpio_t *const gpioIn, cxa_blueGiga_btle_client_t* btlecIn, uint8_t portNumIn, uint8_t chanNumIn); 59 | 60 | 61 | /** 62 | * @protected 63 | */ 64 | void cxa_blueGiga_configureGpiosForBlueGiga(cxa_blueGiga_btle_client_t* btlecIn, cxa_blueGiga_gpio_cb_onGpiosConfigured_t cbIn); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /include/btle/blueGiga/cxa_blueGiga_i2cMaster.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_BLUEGIGA_I2C_MASTER_H_ 8 | #define CXA_BLUEGIGA_I2C_MASTER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | /** 20 | * @public 21 | * @brief "Forward" declaration of the cxa_blueGiga_i2cMaster_t object 22 | */ 23 | typedef struct cxa_blueGiga_i2cMaster cxa_blueGiga_i2cMaster_t; 24 | 25 | 26 | /** 27 | * @public 28 | * Forward declaration of blueGiga_btle_client to avoid 29 | * circular reference 30 | */ 31 | typedef struct cxa_blueGiga_btle_client cxa_blueGiga_btle_client_t; 32 | 33 | 34 | /** 35 | * @private 36 | */ 37 | struct cxa_blueGiga_i2cMaster 38 | { 39 | cxa_i2cMaster_t super; 40 | 41 | cxa_blueGiga_btle_client_t* btlec; 42 | 43 | size_t expectedNumBytesToWrite; 44 | }; 45 | 46 | 47 | // ******** global function prototypes ******** 48 | /** 49 | * @protected 50 | */ 51 | void cxa_blueGiga_i2cMaster_init(cxa_blueGiga_i2cMaster_t *const i2cIn, cxa_blueGiga_btle_client_t* btlecIn); 52 | 53 | 54 | #endif // CXA_BLUEGIGA_I2C_H_ 55 | -------------------------------------------------------------------------------- /include/btle/blueGiga/cxa_protocolParser_bgapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_PROTOCOLPARSER_BGAPI_H_ 8 | #define CXA_PROTOCOLPARSER_BGAPI_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | 20 | 21 | // ******** global type definitions ********* 22 | typedef struct 23 | { 24 | cxa_protocolParser_t super; 25 | 26 | cxa_stateMachine_t stateMachine; 27 | 28 | size_t rxByteCounter; 29 | }cxa_protocolParser_bgapi_t; 30 | 31 | 32 | // ******** global function prototypes ******** 33 | void cxa_protocolParser_bgapi_init(cxa_protocolParser_bgapi_t *const ppIn, cxa_ioStream_t *const ioStreamIn, cxa_fixedByteBuffer_t *const buffIn, int threadIdIn); 34 | 35 | size_t cxa_protocolParser_bgapi_getRxByteCounter(cxa_protocolParser_bgapi_t *const ppIn); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/btle/cxa_btle_uuid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_BTLE_UUID_H_ 8 | #define CXA_BTLE_UUID_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | /** 22 | * @public 23 | */ 24 | typedef struct cxa_btle_uuid cxa_btle_uuid_t; 25 | 26 | 27 | typedef enum 28 | { 29 | CXA_BTLE_UUID_TYPE_16BIT, 30 | CXA_BTLE_UUID_TYPE_128BIT 31 | }cxa_btle_uuid_type_t; 32 | 33 | 34 | typedef struct 35 | { 36 | char str[37]; 37 | }cxa_btle_uuid_string_t; 38 | 39 | 40 | /** 41 | * @private 42 | */ 43 | struct cxa_btle_uuid 44 | { 45 | cxa_btle_uuid_type_t type; 46 | 47 | union 48 | { 49 | uint16_t as16Bit; 50 | cxa_uuid128_t as128Bit; 51 | }; 52 | }; 53 | 54 | 55 | // ******** global function prototypes ******** 56 | bool cxa_btle_uuid_init(cxa_btle_uuid_t *const uuidIn, uint8_t *const bytesIn, size_t numBytesIn, bool transposeIn); 57 | bool cxa_btle_uuid_initFromBuffer(cxa_btle_uuid_t *const uuidIn, cxa_fixedByteBuffer_t *const fbbIn, size_t indexIn, size_t numBytesIn, bool transposeIn); 58 | bool cxa_btle_uuid_initFromString(cxa_btle_uuid_t *const uuidIn, const char *const strIn); 59 | void cxa_btle_uuid_initFromUuid(cxa_btle_uuid_t *const targetUuidIn, cxa_btle_uuid_t *const sourceUuidIn, bool transposeIn); 60 | 61 | bool cxa_btle_uuid_isEqual(cxa_btle_uuid_t *const uuid1In, cxa_btle_uuid_t *const uuid2In); 62 | bool cxa_btle_uuid_isEqualToString(cxa_btle_uuid_t *const uuid1In, const char *const strIn); 63 | 64 | void cxa_btle_uuid_toString(cxa_btle_uuid_t *const uuidIn, cxa_btle_uuid_string_t *const strOut); 65 | void cxa_btle_uuid_toShortString(cxa_btle_uuid_t *const uuidIn, cxa_btle_uuid_string_t *const strOut); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /include/btle/siLabsBgApi/cxa_siLabsBgApi_btle_central.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_SILABSBGAPI_BTLE_CENTRAL_H_ 8 | #define CXA_SILABSBGAPI_BTLE_CENTRAL_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #if defined(CXA_SILABSBGAPI_MODE_SOC) || defined(CXA_SILABSBGAPI_MODE_SOC_HIGH_POWER) 14 | #include "bg_types.h" 15 | #include "native_gecko.h" 16 | #include "infrastructure.h" 17 | #else 18 | #include 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | // ******** global macro definitions ******** 29 | #ifndef CXA_SILABSBGAPI_BTLE_CENTRAL_MAXNUM_CONNS 30 | #define CXA_SILABSBGAPI_BTLE_CENTRAL_MAXNUM_CONNS 2 31 | #endif 32 | 33 | 34 | // ******** global type definitions ********* 35 | /** 36 | * @public 37 | */ 38 | typedef struct cxa_siLabsBgApi_btle_central cxa_siLabsBgApi_btle_central_t; 39 | 40 | 41 | /** 42 | * @private 43 | */ 44 | struct cxa_siLabsBgApi_btle_central 45 | { 46 | cxa_btle_central_t super; 47 | 48 | int threadId; 49 | 50 | bool isConnectionInProgress; 51 | 52 | cxa_siLabsBgApi_btle_connection_t conns[CXA_SILABSBGAPI_BTLE_CENTRAL_MAXNUM_CONNS]; 53 | }; 54 | 55 | 56 | // ******** global function prototypes ******** 57 | /** 58 | * @protected 59 | */ 60 | void cxa_siLabsBgApi_btle_central_init(cxa_siLabsBgApi_btle_central_t *const btlecIn, int threadIdIn); 61 | 62 | 63 | /** 64 | * @public 65 | */ 66 | bool cxa_siLabsBgApi_btle_central_setConnectionInterval(cxa_siLabsBgApi_btle_central_t *const btlecIn, cxa_eui48_t *const targetConnectionAddressIn, uint16_t connectionInterval_msIn); 67 | 68 | 69 | /** 70 | * @protected 71 | * 72 | * @return true if this event was handled 73 | */ 74 | bool cxa_siLabsBgApi_btle_central_handleBgEvent(cxa_siLabsBgApi_btle_central_t *const btlecIn, struct gecko_cmd_packet *evt); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /include/btle/siLabsBgApi/cxa_siLabsBgApi_module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_SILABSBGAPI_MODULE_H_ 8 | #define CXA_SILABSBGAPI_MODULE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | 20 | 21 | // ******** global type definitions ********* 22 | /** 23 | * @public 24 | */ 25 | typedef void (*cxa_siLabsBgApi_cb_onTimer_t)(void *const userVarIn); 26 | 27 | 28 | // ******** global function prototypes ******** 29 | #if defined(CXA_SILABSBGAPI_MODE_SOC) || defined(CXA_SILABSBGAPI_MODE_SOC_HIGH_POWER) 30 | /** 31 | * @public 32 | * Used to configure a SiliconLabs BGAPI module in a SOC configuration 33 | */ 34 | void cxa_siLabsBgApi_module_init(void); 35 | #else 36 | /** 37 | * @public 38 | * Used to configure a SiliconLabs BGAPI module in a NCP configuration 39 | */ 40 | void cxa_siLabsBgApi_module_init(cxa_ioStream_t *const ioStreamIn, int threadIdIn); 41 | #endif 42 | 43 | 44 | /** 45 | * @public 46 | */ 47 | cxa_siLabsBgApi_btle_central_t* cxa_siLabsBgApi_module_getBtleCentral(void); 48 | 49 | 50 | /** 51 | * @public 52 | */ 53 | cxa_siLabsBgApi_btle_peripheral_t* cxa_siLabsBgApi_module_getBtlePeripheral(void); 54 | 55 | 56 | /** 57 | * @public 58 | */ 59 | void cxa_siLabsBgApi_module_startSoftTimer_repeat(float period_msIn, cxa_siLabsBgApi_cb_onTimer_t cbIn, void* userVarIn); 60 | 61 | 62 | /** 63 | * @public 64 | */ 65 | void cxa_siLabsBgApi_module_stopSoftTimer(cxa_siLabsBgApi_cb_onTimer_t cbIn, void* userVarIn); 66 | 67 | 68 | /** 69 | * @protected 70 | */ 71 | cxa_btle_central_state_t cxa_siLabsBgApi_module_getState(void); 72 | 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /include/fdLineParser/cxa_fdLineParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_FD_LINEPARSER_H_ 8 | #define CXA_FD_LINEPARSER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | typedef void (*cxa_fdLineParser_lineCb_t)(uint8_t *lineStartIn, size_t numBytesInLineIn, void *userVarIn); 22 | 23 | typedef struct 24 | { 25 | FILE *fd; 26 | bool echoUser; 27 | 28 | cxa_fdLineParser_lineCb_t cb; 29 | void *userVar; 30 | 31 | bool wasLastByteCr; 32 | cxa_array_t lineBuffer; 33 | }cxa_fdLineParser_t; 34 | 35 | 36 | // ******** global function prototypes ******** 37 | void cxa_fdLineParser_init(cxa_fdLineParser_t *const fdlpIn, FILE *fdIn, bool echoUserIn, void *bufferIn, size_t bufferSize_bytesIn, cxa_fdLineParser_lineCb_t cbIn, void *userVarIn); 38 | 39 | bool cxa_fdLineParser_update(cxa_fdLineParser_t *const fdlpIn); 40 | 41 | 42 | #endif // CXA_FD_LINEPARSER_H_ 43 | -------------------------------------------------------------------------------- /include/logger/cxa_logger_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_LOGGER_HDR_H_ 8 | #define CXA_LOGGER_HDR_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | #ifndef CXA_LOGGER_MAX_NAME_LEN_CHARS 18 | #define CXA_LOGGER_MAX_NAME_LEN_CHARS 24 19 | #endif 20 | 21 | 22 | // ******** global type definitions ********* 23 | typedef struct 24 | { 25 | char name[CXA_LOGGER_MAX_NAME_LEN_CHARS+1]; 26 | 27 | #ifdef CXA_LOGGER_CLAMPED_ENABLE 28 | cxa_timeDiff_t td_clamped; 29 | #endif 30 | }cxa_logger_t; 31 | 32 | 33 | // ******** global function prototypes ******** 34 | 35 | 36 | #endif // CXA_LOGGER_HEADER_H_ 37 | -------------------------------------------------------------------------------- /include/misc/cxa_eui48.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_eui48_H_ 8 | #define CXA_eui48_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | typedef struct 22 | { 23 | char str[18]; 24 | }cxa_eui48_string_t; 25 | 26 | 27 | typedef struct 28 | { 29 | uint8_t bytes[6]; 30 | }cxa_eui48_t; 31 | 32 | 33 | // ******** global function prototypes ******** 34 | void cxa_eui48_init(cxa_eui48_t *const uuidIn, uint8_t *const bytesIn); 35 | bool cxa_eui48_initFromBuffer(cxa_eui48_t *const uuidIn, cxa_fixedByteBuffer_t *const fbbIn, size_t indexIn); 36 | bool cxa_eui48_initFromString(cxa_eui48_t *const uuidIn, const char *const stringIn); 37 | void cxa_eui48_initFromEui48(cxa_eui48_t *const targetIn, cxa_eui48_t *const sourceIn); 38 | void cxa_eui48_initRandom(cxa_eui48_t *const uuidIn); 39 | 40 | bool cxa_eui48_isEqual(cxa_eui48_t *const uuid1In, cxa_eui48_t *const uuid2In); 41 | bool cxa_eui48_isEqualToString(cxa_eui48_t *const uuidIn, const char *const uuidStrIn); 42 | 43 | void cxa_eui48_toString(cxa_eui48_t *const uuidIn, cxa_eui48_string_t *const strOut); 44 | void cxa_eui48_toShortString(cxa_eui48_t *const uuidIn, cxa_eui48_string_t *const strOut); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /include/misc/cxa_numberUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_NUMBERUTILS_H_ 8 | #define CXA_NUMBERUTILS_H_ 9 | 10 | 11 | /** 12 | * @file 13 | * This is a file which contains utility functions for manipulating numbers 14 | * 15 | * @author Christopher Armenio 16 | */ 17 | 18 | 19 | // ******** includes ******** 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | // ******** global macro definitions ******** 27 | #define CXA_MAX(x, y) (((x) > (y)) ? (x) : (y)) 28 | #define CXA_MIN(x, y) (((x) < (y)) ? (x) : (y)) 29 | 30 | #define CXA_CLAMP_HIGH(val, max) ((val) = CXA_MIN((val), (max))) 31 | #define CXA_CLAMP_LOW(val, min) ((val) = CXA_MAX((val), (min))) 32 | #define CXA_CLAMP_LOW_HIGH(val, min, max) ((val) = CXA_CLAMP_HIGH(CXA_CLAMP_LOW((val), (min)), (max))) 33 | 34 | #define CXA_INCREMENT_CLAMP_HIGH(val, inc, max) ((val) = (((max) - (val)) >= (inc)) ? ((val) + (inc)) : (max)) 35 | #define CXA_INCREMENT_CLAMP_LOW(val, inc, min) ((val) = (((min) + (val)) >= (fabs(inc))) ? ((val) + (inc)) : (min)) 36 | 37 | 38 | // ******** global type definitions ********* 39 | 40 | 41 | // ******** global function prototypes ******** 42 | uint16_t cxa_numberUtils_crc16_oneShot(void* dataIn, size_t dataLen_bytesIn); 43 | 44 | uint16_t cxa_numberUtils_crc16_step(uint16_t crcIn, uint8_t byteIn); 45 | 46 | 47 | #endif // CXA_NUMBERUTILS_H_ 48 | -------------------------------------------------------------------------------- /include/misc/cxa_profiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_PROFILER_H_ 8 | #define CXA_PROFILER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | #define cxa_profiler_start(profIn) (profIn)->lastTime_us = cxa_timeBase_getCount_us() 18 | #define cxa_profiler_step(profIn) cxa_profiler_step_impl(profIn, __FILE__, __LINE__) 19 | 20 | 21 | // ******** global type definitions ********* 22 | typedef struct { 23 | cxa_logger_t logger; 24 | 25 | uint32_t lastTime_us; 26 | }cxa_profiler_t; 27 | 28 | 29 | // ******** global function prototypes ******** 30 | void cxa_profiler_init(cxa_profiler_t *const profIn, const char *nameIn); 31 | 32 | 33 | /** 34 | * @private 35 | */ 36 | void cxa_profiler_step_impl(cxa_profiler_t *const profIn, const char* fileIn, const int lineNumIn); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/misc/cxa_uuid128.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_UUID128_H_ 8 | #define CXA_UUID128_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | typedef struct 22 | { 23 | char str[37]; 24 | }cxa_uuid128_string_t; 25 | 26 | 27 | typedef struct 28 | { 29 | uint8_t bytes[16]; 30 | }cxa_uuid128_t; 31 | 32 | 33 | // ******** global function prototypes ******** 34 | void cxa_uuid128_init(cxa_uuid128_t *const uuidIn, uint8_t *const bytesIn, bool transposeIn); 35 | bool cxa_uuid128_initFromBuffer(cxa_uuid128_t *const uuidIn, cxa_fixedByteBuffer_t *const fbbIn, size_t indexIn, bool transposeBytesIn); 36 | bool cxa_uuid128_initFromString(cxa_uuid128_t *const uuidIn, const char *const stringIn); 37 | void cxa_uuid128_initFromUuid128(cxa_uuid128_t *const targetIn, cxa_uuid128_t *const sourceIn); 38 | void cxa_uuid128_initRandom(cxa_uuid128_t *const uuidIn); 39 | void cxa_uuid128_initEmpty(cxa_uuid128_t *const uuidIn); 40 | 41 | bool cxa_uuid128_isEmpty(cxa_uuid128_t *const uuidIn); 42 | bool cxa_uuid128_isEqual(cxa_uuid128_t *const uuid1In, cxa_uuid128_t *const uuid2In); 43 | 44 | void cxa_uuid128_toString(cxa_uuid128_t *const uuidIn, cxa_uuid128_string_t *const strOut); 45 | void cxa_uuid128_toShortString(cxa_uuid128_t *const uuidIn, cxa_uuid128_string_t *const strOut); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/mqtt/cxa_mqtt_client_network.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_CLIENT_NETWORK_H_ 8 | #define CXA_MQTT_CLIENT_NETWORK_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | typedef struct cxa_mqtt_client_network cxa_mqtt_client_network_t; 21 | 22 | 23 | /** 24 | * @private 25 | */ 26 | struct cxa_mqtt_client_network 27 | { 28 | cxa_mqtt_client_t super; 29 | 30 | cxa_network_tcpClient_t *netClient; 31 | 32 | char* username; 33 | uint8_t* password; 34 | uint16_t passwordLen_bytes; 35 | }; 36 | 37 | 38 | // ******** global function prototypes ******** 39 | void cxa_mqtt_client_network_init(cxa_mqtt_client_network_t *const clientIn, char *const clientIdIn, int threadIdIn); 40 | 41 | bool cxa_mqtt_client_network_connectToHost(cxa_mqtt_client_network_t *const clientIn, char *const hostNameIn, uint16_t portNumIn, bool useTlsIn, 42 | char *const usernameIn, uint8_t *const passwordIn, uint16_t passwordLen_bytesIn); 43 | 44 | bool cxa_mqtt_client_network_connectToHost_clientCert(cxa_mqtt_client_network_t *const clientIn, char *const hostNameIn, uint16_t portNumIn, 45 | const char* serverRootCertIn, size_t serverRootCertLen_bytesIn, 46 | const char* clientCertIn, size_t clientCertLen_bytesIn, 47 | const char* clientPrivateKeyIn, size_t clientPrivateKeyLen_bytesIn); 48 | 49 | #endif // CXA_MQTT_CLIENT_H_ 50 | -------------------------------------------------------------------------------- /include/mqtt/cxa_mqtt_connectionManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_CONN_MAN_H_ 8 | #define CXA_MQTT_CONN_MAN_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | typedef void (*cxa_mqtt_connManager_enteringStandoffCb_t)(void *const userVarIn); 20 | typedef bool (*cxa_mqtt_connManager_canLeaveStandoffCb_t)(void *const userVarIn); 21 | 22 | 23 | // ******** global function prototypes ******** 24 | void cxa_mqtt_connManager_init(char *const hostNameIn, uint16_t portNumIn, int threadIdIn); 25 | 26 | void cxa_mqtt_connManager_setStandoffManagementCbs(cxa_mqtt_connManager_enteringStandoffCb_t cb_enteringStandoffIn, 27 | cxa_mqtt_connManager_canLeaveStandoffCb_t cb_canLeaveStandoffCbIn, 28 | void *const userVarIn); 29 | 30 | bool cxa_mqtt_connManager_areCredentialsSet(void); 31 | 32 | bool cxa_mqtt_connManager_start(void); 33 | void cxa_mqtt_connManager_stop(void); 34 | 35 | uint32_t cxa_mqtt_connManager_getNumFailedConnects(void); 36 | 37 | cxa_mqtt_client_t* cxa_mqtt_connManager_getMqttClient(void); 38 | 39 | 40 | #endif // CXA_MQTT_MAN_H_ 41 | -------------------------------------------------------------------------------- /include/mqtt/cxa_mqtt_messageFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_MESSAGEFACTORY_H_ 8 | #define CXA_MQTT_MESSAGEFACTORY_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | #ifndef CXA_MQTT_MESSAGEFACTORY_NUM_MESSAGES 19 | #define CXA_MQTT_MESSAGEFACTORY_NUM_MESSAGES 2 20 | #endif 21 | 22 | #ifndef CXA_MQTT_MESSAGEFACTORY_MESSAGE_SIZE_BYTES 23 | #define CXA_MQTT_MESSAGEFACTORY_MESSAGE_SIZE_BYTES 64 24 | #endif 25 | 26 | 27 | // ******** global type definitions ********* 28 | 29 | 30 | // ******** global function prototypes ******** 31 | size_t cxa_mqtt_messageFactory_getNumFreeMessages(void); 32 | cxa_mqtt_message_t* cxa_mqtt_messageFactory_getFreeMessage_empty(void); 33 | 34 | cxa_mqtt_message_t* cxa_mqtt_messageFactory_getMessage_byBuffer(cxa_fixedByteBuffer_t *const fbbIn); 35 | 36 | void cxa_mqtt_messageFactory_incrementMessageRefCount(cxa_mqtt_message_t *const msgIn); 37 | void cxa_mqtt_messageFactory_decrementMessageRefCount(cxa_mqtt_message_t *const msgIn); 38 | uint8_t cxa_mqtt_messageFactory_getReferenceCountForMessage(cxa_mqtt_message_t *const msgIn); 39 | 40 | 41 | #endif /* CXA_MQTT_MESSAGEFACTORY_H_ */ 42 | -------------------------------------------------------------------------------- /include/mqtt/cxa_protocolParser_mqtt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_PROTOCOLPARSER_MQTT_H_ 8 | #define CXA_PROTOCOLPARSER_MQTT_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | typedef struct 22 | { 23 | cxa_protocolParser_t super; 24 | 25 | cxa_stateMachine_t stateMachine; 26 | size_t remainingBytesToReceive; 27 | }cxa_protocolParser_mqtt_t; 28 | 29 | 30 | // ******** global function prototypes ******** 31 | void cxa_protocolParser_mqtt_init(cxa_protocolParser_mqtt_t *const mppIn, cxa_ioStream_t *const ioStreamIn, cxa_fixedByteBuffer_t *const buffIn, int threadIdIn); 32 | 33 | 34 | #endif // CXA_PROTOCOLPARSER_MQTT_H_ 35 | -------------------------------------------------------------------------------- /include/mqtt/messages/cxa_mqtt_message_connack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_MESSAGE_CONNACK_H_ 8 | #define CXA_MQTT_MESSAGE_CONNACK_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | typedef enum 20 | { 21 | CXA_MQTT_CONNACK_RETCODE_ACCEPTED=0, 22 | CXA_MQTT_CONNACK_RETCODE_REFUSED_PROTO=1, 23 | CXA_MQTT_CONNACK_RETCODE_REFUSED_CID=2, 24 | CXA_MQTT_CONNACK_RETCODE_REFUSED_SERVERUNAVAILABLE=3, 25 | CXA_MQTT_CONNACK_RETCODE_REFUSED_BADUSERNAMEPASSWORD=4, 26 | CXA_MQTT_CONNACK_RETCODE_REFUSED_NOTAUTHORIZED=5, 27 | CXA_MQTT_CONNACK_RETCODE_UNKNOWN=255 28 | }cxa_mqtt_connAck_returnCode_t; 29 | 30 | 31 | // ******** global function prototypes ******** 32 | bool cxa_mqtt_message_connack_init(cxa_mqtt_message_t *const msgIn, bool isSessionPresentIn, cxa_mqtt_connAck_returnCode_t retCodeIn); 33 | 34 | bool cxa_mqtt_message_connack_isSessionPresent(cxa_mqtt_message_t *const msgIn, bool *const isSessionPresentOut); 35 | bool cxa_mqtt_message_connack_getReturnCode(cxa_mqtt_message_t *const msgIn, cxa_mqtt_connAck_returnCode_t *const returnCodeOut); 36 | 37 | 38 | /** 39 | * @protected 40 | */ 41 | bool cxa_mqtt_message_connack_validateReceivedBytes(cxa_mqtt_message_t *const msgIn); 42 | 43 | #endif /* CXA_MQTT_MESSAGE_CONNACK_H_ */ 44 | -------------------------------------------------------------------------------- /include/mqtt/messages/cxa_mqtt_message_connect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_MESSAGE_CONNECT_H_ 8 | #define CXA_MQTT_MESSAGE_CONNECT_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | 20 | 21 | // ******** global function prototypes ******** 22 | bool cxa_mqtt_message_connect_init(cxa_mqtt_message_t *const msgIn, char* clientIdIn, 23 | char* usernameIn, uint8_t* passwordIn, uint16_t passwordLen_bytesIn, 24 | cxa_mqtt_qosLevel_t willQosIn, bool willRetainIn, const char* willTopicIn, void *const willPayloadIn, size_t willPayloadLen_bytesIn, 25 | bool cleanSessionIn, uint16_t keepAlive_sIn); 26 | 27 | bool cxa_mqtt_message_connect_hasWill(cxa_mqtt_message_t *const msgIn, bool *const hasWillOut); 28 | bool cxa_mqtt_message_connect_hasUsername(cxa_mqtt_message_t *const msgIn, bool *const hasUsernameOut); 29 | bool cxa_mqtt_message_connect_hasPassword(cxa_mqtt_message_t *const msgIn, bool *const hasPasswordOut); 30 | bool cxa_mqtt_message_connect_cleanSessionRequested(cxa_mqtt_message_t *const msgIn, bool *const cleanSessionRequestedOut); 31 | 32 | bool cxa_mqtt_message_connect_getClientId(cxa_mqtt_message_t *const msgIn, char** clientIdOut, uint16_t* clientIdLen_bytesOut); 33 | bool cxa_mqtt_message_connect_getUsername(cxa_mqtt_message_t *const msgIn, char** usernameOut, uint16_t* usernameLen_bytesOut); 34 | bool cxa_mqtt_message_connect_getPassword(cxa_mqtt_message_t *const msgIn, uint8_t** passwordOut, uint16_t* passwordLen_bytesOut); 35 | 36 | /** 37 | * @protected 38 | */ 39 | bool cxa_mqtt_message_connect_validateReceivedBytes(cxa_mqtt_message_t *const msgIn); 40 | 41 | #endif /* CXA_MQTT_MESSAGE_CONNECT_H_ */ 42 | -------------------------------------------------------------------------------- /include/mqtt/messages/cxa_mqtt_message_pingRequest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_MESSAGE_PING_REQUEST_H_ 8 | #define CXA_MQTT_MESSAGE_PING_REQUEST_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | 20 | 21 | // ******** global function prototypes ******** 22 | 23 | bool cxa_mqtt_message_pingRequest_init(cxa_mqtt_message_t *const msgIn); 24 | 25 | 26 | /** 27 | * @protected 28 | */ 29 | bool cxa_mqtt_message_pingRequest_validateReceivedBytes(cxa_mqtt_message_t *const msgIn); 30 | 31 | #endif /* CXA_MQTT_MESSAGE_PING_REQUEST_H_ */ 32 | -------------------------------------------------------------------------------- /include/mqtt/messages/cxa_mqtt_message_pingResponse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_MESSAGE_PING_RESPONSE_H_ 8 | #define CXA_MQTT_MESSAGE_PING_RESPONSE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | 20 | 21 | // ******** global function prototypes ******** 22 | 23 | bool cxa_mqtt_message_pingResponse_init(cxa_mqtt_message_t *const msgIn); 24 | 25 | 26 | /** 27 | * @protected 28 | */ 29 | bool cxa_mqtt_message_pingResponse_validateReceivedBytes(cxa_mqtt_message_t *const msgIn); 30 | 31 | #endif /* CXA_MQTT_MESSAGE_PING_RESPONSE_H_ */ 32 | -------------------------------------------------------------------------------- /include/mqtt/messages/cxa_mqtt_message_publish.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_MESSAGE_PUBLISH_H_ 8 | #define CXA_MQTT_MESSAGE_PUBLISH_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | 20 | 21 | // ******** global function prototypes ******** 22 | bool cxa_mqtt_message_publish_init(cxa_mqtt_message_t *const msgIn, bool dupIn, cxa_mqtt_qosLevel_t qosIn, bool retainIn, char *const topicNameIn, uint16_t packedIdIn, void *const payloadIn, uint16_t payloadSize_bytesIn); 23 | 24 | bool cxa_mqtt_message_publish_getTopicName(cxa_mqtt_message_t *const msgIn, char** topicNameOut, uint16_t *const topicNameLen_bytesOut); 25 | bool cxa_mqtt_message_publish_getPayload(cxa_mqtt_message_t *const msgIn, cxa_linkedField_t **payloadLfOut); 26 | 27 | bool cxa_mqtt_message_publish_topicName_trimToPointer(cxa_mqtt_message_t *const msgIn, char *const ptrIn); 28 | bool cxa_mqtt_message_publish_topicName_prependCString(cxa_mqtt_message_t *const msgIn, char *const stringIn); 29 | bool cxa_mqtt_message_publish_topicName_prependString_withLength(cxa_mqtt_message_t *const msgIn, char *const stringIn, size_t stringLen_bytesIn); 30 | bool cxa_mqtt_message_publish_topicName_clear(cxa_mqtt_message_t *const msgIn); 31 | 32 | /** 33 | * @protected 34 | */ 35 | bool cxa_mqtt_message_publish_validateReceivedBytes(cxa_mqtt_message_t *const msgIn); 36 | 37 | #endif /* CXA_MQTT_MESSAGE_PUBLISH_H_ */ 38 | -------------------------------------------------------------------------------- /include/mqtt/messages/cxa_mqtt_message_suback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_MESSAGE_SUBACK_H_ 8 | #define CXA_MQTT_MESSAGE_SUBACK_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | typedef enum 20 | { 21 | CXA_MQTT_SUBACK_RETCODE_SUCCESS_MAXQOS0=0, 22 | CXA_MQTT_SUBACK_RETCODE_SUCCESS_MAXQOS1=1, 23 | CXA_MQTT_SUBACK_RETCODE_SUCCESS_MAXQOS2=2, 24 | CXA_MQTT_SUBACK_RETCODE_FAILURE=128, 25 | CXA_MQTT_SUBACK_RETCODE_UNKNOWN=255, 26 | }cxa_mqtt_subAck_returnCode_t; 27 | 28 | 29 | // ******** global function prototypes ******** 30 | bool cxa_mqtt_message_suback_getPacketId(cxa_mqtt_message_t *const msgIn, uint16_t *const packetIdOut); 31 | bool cxa_mqtt_message_suback_getReturnCode(cxa_mqtt_message_t *const msgIn, cxa_mqtt_subAck_returnCode_t *const returnCodeOut); 32 | 33 | 34 | /** 35 | * @protected 36 | */ 37 | bool cxa_mqtt_message_suback_validateReceivedBytes(cxa_mqtt_message_t *const msgIn); 38 | 39 | #endif /* CXA_MQTT_MESSAGE_SUBACK_H_ */ 40 | -------------------------------------------------------------------------------- /include/mqtt/messages/cxa_mqtt_message_subscribe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_MESSAGE_SUBSCRIBE_H_ 8 | #define CXA_MQTT_MESSAGE_SUBSCRIBE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | 20 | 21 | // ******** global function prototypes ******** 22 | bool cxa_mqtt_message_subscribe_init(cxa_mqtt_message_t *const msgIn, uint16_t packetIdIn, char *const topicFilterIn, cxa_mqtt_qosLevel_t qosLevelIn); 23 | 24 | 25 | /** 26 | * @protected 27 | */ 28 | bool cxa_mqtt_message_subscribe_validateReceivedBytes(cxa_mqtt_message_t *const msgIn); 29 | 30 | #endif /* CXA_MQTT_MESSAGE_SUBSCRIBE_H_ */ 31 | -------------------------------------------------------------------------------- /include/mqtt/rpc/cxa_mqtt_rpc_message.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_RPC_MESSAGE_H_ 8 | #define CXA_MQTT_RPC_MESSAGE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | #define CXA_MQTT_RPC_MESSAGE_VERSION "v1" 18 | 19 | 20 | // ******** global type definitions ********* 21 | 22 | 23 | // ******** global function prototypes ******** 24 | bool cxa_mqtt_rpc_message_isActionableResponse(cxa_mqtt_message_t *const msgIn, char** methodNameOut, size_t* methodNameLen_bytesOut, char** idOut, size_t* idLen_bytesOut); 25 | 26 | #endif /* CXA_MQTT_RPC_MESSAGE_H_ */ 27 | -------------------------------------------------------------------------------- /include/mqtt/rpc/cxa_mqtt_rpc_node_bridge_single.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_RPC_NODE_BRIDGE_SINGLE_H_ 8 | #define CXA_MQTT_RPC_NODE_BRIDGE_SINGLE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | // ******** global macro definitions ******** 22 | #ifndef CXA_MQTT_RPC_NODE_BRIDGE_CLIENTID_MAXLEN_BYTES 23 | #define CXA_MQTT_RPC_NODE_BRIDGE_CLIENTID_MAXLEN_BYTES 17 24 | #endif 25 | 26 | 27 | // ******** global type definitions ********* 28 | typedef struct cxa_mqtt_rpc_node_bridge_single cxa_mqtt_rpc_node_bridge_single_t; 29 | 30 | 31 | /** 32 | * @private 33 | */ 34 | struct cxa_mqtt_rpc_node_bridge_single 35 | { 36 | cxa_mqtt_rpc_node_bridge_t super; 37 | 38 | bool hasClientAuthed; 39 | char clientId[CXA_MQTT_RPC_NODE_BRIDGE_CLIENTID_MAXLEN_BYTES+1]; 40 | 41 | cxa_mqtt_rpc_node_bridge_cb_authenticateClient_t cb_localAuth; 42 | void* localAuthUserVar; 43 | }; 44 | 45 | 46 | // ******** global function prototypes ******** 47 | void cxa_mqtt_rpc_node_bridge_single_init(cxa_mqtt_rpc_node_bridge_single_t *const nodeIn, cxa_mqtt_rpc_node_t *const parentNodeIn, 48 | cxa_protocolParser_mqtt_t *const mppIn, const char *nameFmtIn, ...); 49 | 50 | void cxa_mqtt_rpc_node_bridge_single_setAuthCb(cxa_mqtt_rpc_node_bridge_single_t *const nodeIn, cxa_mqtt_rpc_node_bridge_cb_authenticateClient_t authCbIn, void *const userVarIn); 51 | 52 | #endif // CXA_MQTT_RPC_NODEBRIDGE_SINGLE_H_ 53 | -------------------------------------------------------------------------------- /include/mqtt/rpc/cxa_mqtt_rpc_node_root.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_MQTT_RPC_NODE_ROOT_H_ 8 | #define CXA_MQTT_RPC_NODE_ROOT_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | /** 22 | * @private 23 | */ 24 | typedef struct cxa_mqtt_rpc_node_root 25 | { 26 | cxa_mqtt_rpc_node_t super; 27 | 28 | cxa_mqtt_client_t* mqttClient; 29 | bool shouldReportState; 30 | 31 | uint16_t currRequestId; 32 | }cxa_mqtt_rpc_node_root_t; 33 | 34 | 35 | // ******** global function prototypes ******** 36 | /** 37 | * @public 38 | */ 39 | void cxa_mqtt_rpc_node_root_init(cxa_mqtt_rpc_node_root_t *const nodeIn, cxa_mqtt_client_t* const clientIn, 40 | bool reportStateIn, const char *nameFmtIn, ...); 41 | 42 | #endif // CXA_MQTT_RPC_NODE_ROOT_H_ 43 | -------------------------------------------------------------------------------- /include/net/cxa_network_ethernetManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_NETWORK_ETHERNET_MANAGER_H_ 8 | #define CXA_NETWORK_ETHERNET_MANAGER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | #ifndef CXA_NETWORK_ETHMGR_MAXNUM_LISTENERS 19 | #define CXA_NETWORK_ETHMGR_MAXNUM_LISTENERS 2 20 | #endif 21 | 22 | 23 | // ******** global type definitions ********* 24 | typedef enum 25 | { 26 | CXA_NETWORK_ETHSTATE_IDLE, 27 | CXA_NETWORK_ETHSTATE_WAIT_LINK, 28 | CXA_NETWORK_ETHSTATE_WAIT_DHCP, 29 | CXA_NETWORK_ETHSTATE_HAS_ADDRESS_DHCP, 30 | CXA_NETWORK_ETHSTATE_HAS_ADDRESS_AUTOIP 31 | }cxa_network_ethernetManager_state_t; 32 | 33 | 34 | typedef void (*cxa_network_ethernetManager_cb_t)(void* userVarIn); 35 | 36 | 37 | // ******** global function prototypes ******** 38 | void cxa_network_ethernetManager_init(int threadIdIn); 39 | void cxa_network_ethernetManager_addListener(cxa_network_ethernetManager_cb_t cb_idleEnterIn, 40 | cxa_network_ethernetManager_cb_t cb_waitLinkIn, 41 | cxa_network_ethernetManager_cb_t cb_waitDhcpIn, 42 | cxa_network_ethernetManager_cb_t cb_hasAddress_dhcpIn, 43 | cxa_network_ethernetManager_cb_t cb_hasAddress_autoIpIn, 44 | cxa_network_ethernetManager_cb_t cb_hasAddress_staticIpIn, 45 | void *userVarIn); 46 | 47 | void cxa_network_ethernetManager_start(void); 48 | void cxa_network_ethernetManager_stop(void); 49 | 50 | cxa_network_ethernetManager_state_t cxa_network_ethernetManager_getState(void); 51 | 52 | 53 | #endif // CXA_NETWORK_ETHERNET_MANAGER_H_ 54 | -------------------------------------------------------------------------------- /include/net/cxa_network_factory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_NETWORK_FACTORY_H_ 8 | #define CXA_NETWORK_FACTORY_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | 21 | 22 | // ******** global function prototypes ******** 23 | cxa_network_tcpClient_t* cxa_network_factory_reserveTcpClient(int threadIdIn); 24 | void cxa_network_factory_freeTcpClient(cxa_network_tcpClient_t *const clientIn); 25 | 26 | cxa_network_tcpServer_t* cxa_network_factory_reserveTcpServer(int threadIdIn); 27 | void cxa_network_factory_freeTcpServer(cxa_network_tcpServer_t *const serverIn); 28 | 29 | #endif // CXA_NETWORK_FACTORY_H_ 30 | -------------------------------------------------------------------------------- /include/net/cxa_network_wifiManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_NETWORK_WIFI_MANAGER_H_ 8 | #define CXA_NETWORK_WIFI_MANAGER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | #ifndef CXA_NETWORK_WIFIMGR_MAXNUM_LISTENERS 19 | #define CXA_NETWORK_WIFIMGR_MAXNUM_LISTENERS 2 20 | #endif 21 | 22 | 23 | // ******** global type definitions ********* 24 | typedef enum 25 | { 26 | CXA_NETWORK_WIFISTATE_IDLE, 27 | CXA_NETWORK_WIFISTATE_PROVISIONING, 28 | CXA_NETWORK_WIFISTATE_ASSOCIATING, 29 | CXA_NETWORK_WIFISTATE_ASSOCIATED, 30 | }cxa_network_wifiManager_state_t; 31 | 32 | 33 | typedef void (*cxa_network_wifiManager_cb_t)(void* userVarIn); 34 | typedef void (*cxa_network_wifiManager_ssid_cb_t)(const char *const ssidIn, void* userVarIn); 35 | 36 | 37 | // ******** global function prototypes ******** 38 | void cxa_network_wifiManager_init(int threadIdIn); 39 | void cxa_network_wifiManager_addListener(cxa_network_wifiManager_cb_t cb_idleEnterIn, 40 | cxa_network_wifiManager_cb_t cb_provisioningEnterIn, 41 | cxa_network_wifiManager_ssid_cb_t cb_associatingWithSsidIn, 42 | cxa_network_wifiManager_ssid_cb_t cb_associatedWithSsidIn, 43 | cxa_network_wifiManager_cb_t cb_unassociatedIn, 44 | cxa_network_wifiManager_ssid_cb_t cb_associationWithSsidFailedIn, 45 | void *userVarIn); 46 | 47 | void cxa_network_wifiManager_start(void); 48 | void cxa_network_wifiManager_stop(void); 49 | 50 | bool cxa_network_wifiManager_hasStoredCredentials(void); 51 | void cxa_network_wifiManager_clearCredentials(void); 52 | 53 | bool cxa_network_wifiManager_didLastAssociationAttemptFail(void); 54 | cxa_network_wifiManager_state_t cxa_network_wifiManager_getState(void); 55 | 56 | void cxa_network_wifiManager_restart(void); 57 | bool cxa_network_wifiManager_enterProvision(void); 58 | 59 | 60 | #endif // CXA_NETWORK_WIFI_MANAGER_H_ 61 | -------------------------------------------------------------------------------- /include/net/lwipMbedTls/cxa_lwipMbedTls_network_tcpServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_LWIPMBEDTLS_NETWORK_TCPSERVER_H_ 8 | #define CXA_LWIPMBEDTLS_NETWORK_TCPSERVER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | 22 | // ******** global macro definitions ******** 23 | #ifndef CXA_LWIPMBEDTLS_NETWORK_TCPSERVER_MAXCONNECTEDCLIENTS 24 | #define CXA_LWIPMBEDTLS_NETWORK_TCPSERVER_MAXCONNECTEDCLIENTS 2 25 | #endif 26 | 27 | 28 | // ******** global type definitions ********* 29 | /** 30 | * @public 31 | * @brief "Forward" declaration of the cxa_lwipMbedTls_network_tcpServer_t object 32 | */ 33 | typedef struct cxa_lwipMbedTls_network_tcpServer cxa_lwipMbedTls_network_tcpServer_t; 34 | 35 | 36 | /** 37 | * @private 38 | */ 39 | struct cxa_lwipMbedTls_network_tcpServer 40 | { 41 | cxa_network_tcpServer_t super; 42 | 43 | uint16_t portNumber; 44 | int listenSocket; 45 | 46 | cxa_lwipMbedTls_network_tcpServer_connectedClient_t connectedClients[CXA_LWIPMBEDTLS_NETWORK_TCPSERVER_MAXCONNECTEDCLIENTS]; 47 | 48 | cxa_stateMachine_t stateMachine; 49 | }; 50 | 51 | 52 | // ******** global function prototypes ******** 53 | /** 54 | * @protected 55 | */ 56 | void cxa_lwipMbedTls_network_tcpServer_init(cxa_lwipMbedTls_network_tcpServer_t *const netServerIn, int threadIdIn); 57 | 58 | 59 | #endif // CXA_LWIPMBEDTLS_NETWORK_TCPSERVER_H_ 60 | -------------------------------------------------------------------------------- /include/net/lwipMbedTls/cxa_lwipMbedTls_network_tcpServer_connectedClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_LWIPMBEDTLS_NETWORK_TCPSERVER_CONNECTEDCLIENT_H_ 8 | #define CXA_LWIPMBEDTLS_NETWORK_TCPSERVER_CONNECTEDCLIENT_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | 19 | // ******** global macro definitions ******** 20 | 21 | 22 | // ******** global type definitions ********* 23 | /** 24 | * @public 25 | * @brief "Forward" declaration of the cxa_lwipMbedTls_network_tcpServer_t object 26 | */ 27 | typedef struct cxa_lwipMbedTls_network_tcpServer_connectedClient cxa_lwipMbedTls_network_tcpServer_connectedClient_t; 28 | 29 | 30 | /** 31 | * @private 32 | */ 33 | struct cxa_lwipMbedTls_network_tcpServer_connectedClient 34 | { 35 | cxa_network_tcpServer_connectedClient_t super; 36 | 37 | int socket; 38 | char descriptiveString[23]; // "aaa.bbb.ccc.ddd::eeeee" 39 | 40 | cxa_timeDiff_t td_writeTimeout; 41 | }; 42 | 43 | 44 | // ******** global function prototypes ******** 45 | /** 46 | * @protected 47 | */ 48 | void cxa_lwipMbedTls_network_tcpServer_connectedClient_initUnbound(cxa_lwipMbedTls_network_tcpServer_connectedClient_t *const ccIn); 49 | 50 | 51 | /** 52 | * @public 53 | */ 54 | void cxa_lwipMbedTls_network_tcpServer_connectedClient_bindToSocket(cxa_lwipMbedTls_network_tcpServer_connectedClient_t *const ccIn, 55 | int socketIn, 56 | struct sockaddr_in * clientAddressIn); 57 | 58 | 59 | #endif // CXA_LWIPMBEDTLS_NETWORK_TCPSERVER_CONNECTEDCLIENT_H_ 60 | -------------------------------------------------------------------------------- /include/net/wolfSslDialSocket/cxa_wolfSslDialSocket_network_factory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_WOLFSSLDIALSOCKET_NETWORK_FACTORY_H_ 8 | #define CXA_WOLFSSLDIALSOCKET_NETWORK_FACTORY_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include "cxa_network_factory.h" 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | 21 | 22 | // ******** global function prototypes ******** 23 | /** 24 | * @private 25 | */ 26 | void cxa_wolfSslDialSocket_network_factory_setModem(aq_telitTsvgModem_t *const modemIn); 27 | 28 | 29 | #endif // CXA_WOLFSSLDIALSOCKET_NETWORK_FACTORY_H_ 30 | -------------------------------------------------------------------------------- /include/peripherals/cxa_lightSensor_ltr329.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_LIGHTSENSOR_LTR329_H_ 8 | #define CXA_LIGHTSENSOR_LTR329_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | typedef struct 22 | { 23 | cxa_lightSensor_t super; 24 | 25 | cxa_i2cMaster_t* i2c; 26 | 27 | uint16_t readVal; 28 | 29 | cxa_stateMachine_t stateMachine; 30 | }cxa_lightSensor_ltr329_t; 31 | 32 | 33 | // ******** global function prototypes ******** 34 | void cxa_lightSensor_ltr329_init(cxa_lightSensor_ltr329_t *const lightSnsIn, cxa_i2cMaster_t *const i2cIn, int threadIdIn); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/peripherals/cxa_ltc2942.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_LTC2942_H_ 8 | #define CXA_LTC2942_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | #ifndef CXA_LTC2942_MAXNUM_LISTENERS 20 | #define CXA_LTC2942_MAXNUM_LISTENERS 2 21 | #endif 22 | 23 | 24 | // ******** global type definitions ********* 25 | /** 26 | * @public 27 | */ 28 | typedef struct cxa_ltc2942 cxa_ltc2942_t; 29 | 30 | 31 | /** 32 | * @public 33 | */ 34 | typedef void (*cxa_ltc2942_cb_startup_t)(bool wasSuccessfulIn, void *const userVarIn); 35 | 36 | 37 | /** 38 | * @public 39 | */ 40 | typedef void (*cxa_ltc2942_cb_updatedValue_t)(bool wasSuccessfulIn, uint16_t remainingCapacity_mahIn, void *const userVarIn); 41 | 42 | 43 | /** 44 | * @public 45 | */ 46 | typedef struct 47 | { 48 | uint8_t channelIndex; 49 | uint8_t brightness; 50 | }cxa_ltc2942_channelEntry_t; 51 | 52 | 53 | /** 54 | * @private 55 | */ 56 | typedef struct 57 | { 58 | cxa_ltc2942_cb_startup_t cb_onStartup; 59 | cxa_ltc2942_cb_updatedValue_t cb_onUpdatedValue; 60 | 61 | void* userVar; 62 | }cxa_ltc2942_listener_t; 63 | 64 | 65 | /** 66 | * @private 67 | */ 68 | struct cxa_ltc2942 69 | { 70 | cxa_i2cMaster_t* i2c; 71 | 72 | uint16_t batteryInitCap_mah; 73 | bool isInitialized; 74 | 75 | cxa_logger_t logger; 76 | 77 | cxa_array_t listeners; 78 | cxa_ltc2942_listener_t listeners_raw[CXA_LTC2942_MAXNUM_LISTENERS]; 79 | }; 80 | 81 | 82 | // ******** global function prototypes ******** 83 | void cxa_ltc2942_init(cxa_ltc2942_t *const ltcIn, cxa_i2cMaster_t *const i2cIn, uint16_t batteryInitCap_mahIn); 84 | 85 | void cxa_ltc2942_addListener(cxa_ltc2942_t *const ltcIn, cxa_ltc2942_cb_startup_t cb_onStartupIn, cxa_ltc2942_cb_updatedValue_t cb_onUpdatedValue, void *userVarIn); 86 | 87 | void cxa_ltc2942_start(cxa_ltc2942_t *const ltcIn); 88 | 89 | void cxa_ltc2942_requestRemainingCapacityNow(cxa_ltc2942_t *const ltcIn); 90 | 91 | #endif // CXA_LTC2942_H_ 92 | -------------------------------------------------------------------------------- /include/peripherals/cxa_pca9555.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_PCA9555_H_ 8 | #define CXA_PCA9555_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | 20 | 21 | // ******** global type definitions ********* 22 | /** 23 | * @public 24 | */ 25 | typedef struct cxa_pca9555 cxa_pca9555_t; 26 | 27 | 28 | /** 29 | * @private 30 | */ 31 | typedef struct 32 | { 33 | cxa_gpio_t super; 34 | 35 | cxa_pca9555_t* pca; 36 | uint8_t chanNum; 37 | 38 | cxa_gpio_polarity_t polarity; 39 | cxa_gpio_direction_t lastDirection; 40 | bool lastOutputVal; 41 | }cxa_gpio_pca9555_t; 42 | 43 | 44 | /** 45 | * @private 46 | */ 47 | struct cxa_pca9555 48 | { 49 | cxa_logger_t logger; 50 | 51 | cxa_i2cMaster_t* i2c; 52 | uint8_t address; 53 | bool isDeviceResponding; 54 | 55 | bool lastReadWriteStatus; 56 | cxa_fixedByteBuffer_t fbb_readVal; 57 | uint8_t fbb_readVal_raw[1]; 58 | 59 | cxa_gpio_t* gpio_reset; 60 | 61 | cxa_gpio_pca9555_t gpios_port0[8]; 62 | cxa_gpio_pca9555_t gpios_port1[8]; 63 | }; 64 | 65 | 66 | // ******** global function prototypes ******** 67 | void cxa_pca9555_init(cxa_pca9555_t *const pcaIn, cxa_i2cMaster_t *const i2cIn, uint8_t addressIn, cxa_gpio_t *const gpio_resetIn, int threadIdIn); 68 | 69 | cxa_gpio_t* cxa_pca9555_getGpio(cxa_pca9555_t *const pcaIn, uint8_t portNumIn, uint8_t chanNumIn); 70 | 71 | #endif // CXA_PCA9555_H_ 72 | -------------------------------------------------------------------------------- /include/peripherals/cxa_rgbLed_pca9624.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_RGBLED_PCA9624_H_ 8 | #define CXA_RGBLED_PCA9624_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | typedef struct 22 | { 23 | cxa_rgbLed_runLoop_t super; 24 | 25 | cxa_pca9624_t* pca; 26 | 27 | uint8_t maxBrightness; 28 | 29 | uint8_t chanIndex_r; 30 | uint8_t chanIndex_g; 31 | uint8_t chanIndex_b; 32 | }cxa_rgbLed_pca9624_t; 33 | 34 | 35 | // ******** global function prototypes ******** 36 | void cxa_rgbLed_pca9624_init(cxa_rgbLed_pca9624_t *const ledIn, int threadIdIn, 37 | cxa_pca9624_t *const pcaIn, uint8_t maxBrightnessIn, 38 | uint8_t chanIndex_rIn, uint8_t chanIndex_gIn, uint8_t chanIndex_bIn); 39 | 40 | 41 | #endif /* CXA_RGBLED_PCA9624_H_ */ 42 | -------------------------------------------------------------------------------- /include/peripherals/cxa_tempRhSensor_si7021.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_TEMPSENSOR_SI7021_H_ 8 | #define CXA_TEMPSENSOR_SI7021_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | typedef struct 21 | { 22 | cxa_tempSensor_t super; 23 | 24 | cxa_i2cMaster_t* i2c; 25 | }cxa_tempRhSensor_si7021_t; 26 | 27 | 28 | // ******** global function prototypes ******** 29 | void cxa_tempRhSensor_si7021_init(cxa_tempRhSensor_si7021_t *const siIn, cxa_i2cMaster_t *const i2cIn); 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/peripherals/cxa_tempSensor_si7050.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_TEMPSENSOR_SI7050_H_ 8 | #define CXA_TEMPSENSOR_SI7050_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | typedef struct 21 | { 22 | cxa_tempSensor_t super; 23 | 24 | cxa_i2cMaster_t* i2c; 25 | }cxa_tempSensor_si7050_t; 26 | 27 | 28 | // ******** global function prototypes ******** 29 | void cxa_tempSensor_si7050_init(cxa_tempSensor_si7050_t *const siIn, cxa_i2cMaster_t *const i2cIn); 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/rpc/cxa_rpc_messageFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_RPC_MESSAGE_FACTORY_H_ 8 | #define CXA_RPC_MESSAGE_FACTORY_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | #ifndef CXA_RPC_MSGFACTORY_POOL_NUM_MSGS 19 | #define CXA_RPC_MSGFACTORY_POOL_NUM_MSGS 2 20 | #endif 21 | 22 | 23 | // ******** global type definitions ********* 24 | 25 | 26 | // ******** global function prototypes ******** 27 | void cxa_rpc_messageFactory_init(void); 28 | 29 | size_t cxa_rpc_messageFactory_getNumFreeMessages(void); 30 | cxa_rpc_message_t* cxa_rpc_messageFactory_getFreeMessage_empty(void); 31 | 32 | cxa_rpc_message_t* cxa_rpc_messageFactory_getMessage_byBuffer(cxa_fixedByteBuffer_t *const fbbIn); 33 | 34 | void cxa_rpc_messageFactory_incrementMessageRefCount(cxa_rpc_message_t *const msgIn); 35 | void cxa_rpc_messageFactory_decrementMessageRefCount(cxa_rpc_message_t *const msgIn); 36 | uint8_t cxa_rpc_messageFactory_getReferenceCountForMessage(cxa_rpc_message_t *const msgIn); 37 | 38 | #endif // CXA_RPC_NODE_H_ 39 | -------------------------------------------------------------------------------- /include/rpc/cxa_rpc_nodeRemote.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_RPC_NODEREMOTE_H_ 8 | #define CXA_RPC_NODEREMOTE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | 23 | // ******** global macro definitions ******** 24 | #ifndef CXA_RPC_NODEREMOTE_MAXNUM_LINK_LISTENERS 25 | #define CXA_RPC_NODEREMOTE_MAXNUM_LINK_LISTENERS 2 26 | #endif 27 | 28 | 29 | // ******** global type definitions ********* 30 | /** 31 | * @public 32 | */ 33 | typedef void (*cxa_rpc_nodeRemote_cb_linkEstablished_t)(cxa_rpc_nodeRemote_t *const nrIn, void* userVarIn); 34 | 35 | 36 | /** 37 | * @private 38 | */ 39 | typedef struct 40 | { 41 | cxa_rpc_nodeRemote_cb_linkEstablished_t cb_linkEstablished; 42 | void *userVar; 43 | }cxa_rpc_nodeRemote_linkListener_t; 44 | 45 | 46 | /** 47 | * @private 48 | */ 49 | struct cxa_rpc_nodeRemote 50 | { 51 | cxa_rpc_messageHandler_t super; 52 | bool isProvisioned; 53 | 54 | cxa_protocolParser_t protocolParser; 55 | cxa_rpc_node_t *downstreamSubNode; 56 | 57 | cxa_timeDiff_t td_provision; 58 | 59 | cxa_array_t linkListeners; 60 | cxa_rpc_nodeRemote_linkListener_t linkListeners_raw[CXA_RPC_NODEREMOTE_MAXNUM_LINK_LISTENERS]; 61 | }; 62 | 63 | 64 | // ******** global function prototypes ******** 65 | void cxa_rpc_nodeRemote_init_upstream(cxa_rpc_nodeRemote_t *const nrIn, cxa_ioStream_t *const ioStreamIn, cxa_timeBase_t *const timeBaseIn); 66 | bool cxa_rpc_nodeRemote_init_downstream(cxa_rpc_nodeRemote_t *const nrIn, cxa_ioStream_t *const ioStreamIn, cxa_timeBase_t *const timeBaseIn, cxa_rpc_node_t *const subNodeIn); 67 | void cxa_rpc_nodeRemote_deinit(cxa_rpc_nodeRemote_t *const nrIn); 68 | 69 | bool cxa_rpc_nodeRemote_addLinkListener(cxa_rpc_nodeRemote_t *const nrIn, cxa_rpc_nodeRemote_cb_linkEstablished_t cb_linkEstablishedIn, void *const userVarIn); 70 | 71 | void cxa_rpc_nodeRemote_update(cxa_rpc_nodeRemote_t *const nrIn); 72 | 73 | #endif // CXA_RPC_NODEREMOTE_H_ 74 | -------------------------------------------------------------------------------- /include/runLoop/cxa_oneShotTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_ONESHOTTIMER_H_ 8 | #define CXA_ONESHOTTIMER_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | /** 20 | * @public 21 | */ 22 | typedef struct cxa_oneShotTimer cxa_oneShotTimer_t; 23 | 24 | 25 | typedef void (*cxa_oneShotTimer_cb_t)(void *const userVarIn); 26 | 27 | 28 | /** 29 | * @private 30 | */ 31 | struct cxa_oneShotTimer 32 | { 33 | bool isActive; 34 | 35 | cxa_timeDiff_t timeDiff; 36 | uint32_t delay_ms; 37 | 38 | 39 | cxa_oneShotTimer_cb_t cb; 40 | void* userVar; 41 | }; 42 | 43 | 44 | // ******** global function prototypes ******** 45 | void cxa_oneShotTimer_init(cxa_oneShotTimer_t *const ostIn, int threadIdIn); 46 | 47 | void cxa_oneShotTimer_schedule(cxa_oneShotTimer_t *const ostIn, uint32_t delay_msIn, cxa_oneShotTimer_cb_t cbIn, void *const userVarIn); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/runLoop/cxa_runLoop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_RUN_LOOP_H_ 8 | #define CXA_RUN_LOOP_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | #ifndef CXA_RUNLOOP_MAXNUM_ENTRIES 19 | #define CXA_RUNLOOP_MAXNUM_ENTRIES 10 20 | #endif 21 | 22 | #define CXA_RUNLOOP_THREADID_DEFAULT 0 23 | 24 | 25 | // ******** global type definitions ********* 26 | /** 27 | * @public 28 | */ 29 | typedef void (*cxa_runLoop_cb_t)(void* userVarIn); 30 | 31 | 32 | // ******** global function prototypes ******** 33 | void cxa_runLoop_addEntry(int threadIdIn, cxa_runLoop_cb_t startupCbIn, cxa_runLoop_cb_t updateCbIn, void *const userVarIn); 34 | void cxa_runLoop_addTimedEntry(int threadIdIn, uint32_t execPeriod_msIn, cxa_runLoop_cb_t startupCbIn, cxa_runLoop_cb_t updateCbIn, void *const userVarIn); 35 | void cxa_runLoop_clearAllEntries(void); 36 | 37 | void cxa_runLoop_dispatchNextIteration(int threadIdIn, cxa_runLoop_cb_t updateCbIn, void *const userVarIn); 38 | void cxa_runLoop_dispatchAfter(int threadIdIn, uint32_t delay_msIn, cxa_runLoop_cb_t updateCbIn, void *const userVarIn); 39 | 40 | uint32_t cxa_runLoop_iterate(int threadIdIn); 41 | void cxa_runLoop_execute(int threadIdIn); 42 | 43 | 44 | #endif // CXA_RUN_LOOP_H_ 45 | -------------------------------------------------------------------------------- /include/runLoop/cxa_softWatchDog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_SOFTWATCHDOG_H_ 8 | #define CXA_SOFTWATCHDOG_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | #include 15 | 16 | 17 | // ******** global macro definitions ******** 18 | 19 | 20 | // ******** global type definitions ********* 21 | /** 22 | * @public 23 | */ 24 | typedef struct cxa_softWatchDog cxa_softWatchDog_t; 25 | 26 | 27 | /** 28 | * @public 29 | */ 30 | typedef void (*cxa_softWatchDog_cb_t)(void* userVarIn); 31 | 32 | 33 | /** 34 | * @private 35 | */ 36 | struct cxa_softWatchDog 37 | { 38 | cxa_softWatchDog_cb_t cb; 39 | void* userVar; 40 | 41 | bool isPaused; 42 | uint32_t timeoutPeriod_ms; 43 | cxa_timeDiff_t td_timeout; 44 | }; 45 | 46 | 47 | // ******** global function prototypes ******** 48 | void cxa_softWatchDog_init(cxa_softWatchDog_t *const swdIn, uint32_t timeoutPeriod_msIn, int threadIdIn, 49 | cxa_softWatchDog_cb_t cbIn, void *const userVarIn); 50 | void cxa_softWatchDog_kick(cxa_softWatchDog_t *const swdIn); 51 | void cxa_softWatchDog_pause(cxa_softWatchDog_t *const swdIn); 52 | 53 | bool cxa_softWatchDog_isPaused(cxa_softWatchDog_t *const swdIn); 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/serial/cxa_ioStream_bridge.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_IOSTREAM_BRIDGE_H_ 8 | #define CXA_IOSTREAM_BRIDGE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | typedef struct 20 | { 21 | cxa_ioStream_t* stream1; 22 | cxa_ioStream_t* stream2; 23 | }cxa_ioStream_bridge_t; 24 | 25 | 26 | // ******** global function prototypes ******** 27 | void cxa_ioStream_bridge_init(cxa_ioStream_bridge_t *const bridgeIn, 28 | cxa_ioStream_t *const stream1In, 29 | cxa_ioStream_t *const stream2In, 30 | int threadIdIn); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/serial/cxa_ioStream_loopback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_IOSTREAM_LOOPBACK_H_ 8 | #define CXA_IOSTREAM_LOOPBACK_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | #ifndef CXA_IOSTREAM_LOOPBACK_BUFFER_SIZE_BYTES 20 | #define CXA_IOSTREAM_LOOPBACK_BUFFER_SIZE_BYTES 128 21 | #endif 22 | 23 | 24 | // ******** global type definitions ********* 25 | /** 26 | * @public 27 | * @brief "Forward" declaration of the cxa_ioStream_loopback_t object 28 | */ 29 | typedef struct cxa_ioStream_loopback cxa_ioStream_loopback_t; 30 | 31 | 32 | struct cxa_ioStream_loopback 33 | { 34 | cxa_ioStream_t super; 35 | 36 | cxa_fixedFifo_t fifo; 37 | uint8_t fifo_raw[CXA_IOSTREAM_LOOPBACK_BUFFER_SIZE_BYTES]; 38 | }; 39 | 40 | 41 | // ******** global function prototypes ******** 42 | void cxa_ioStream_loopback_init(cxa_ioStream_loopback_t *const ioStreamIn); 43 | 44 | #endif // CXA_IOSTREAM_LOOPBACK_H_ 45 | -------------------------------------------------------------------------------- /include/serial/cxa_ioStream_nullablePassthrough.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_IOSTREAM_NULLABLE_PASSTHROUGH_H_ 8 | #define CXA_IOSTREAM_NULLABLE_PASSTHROUGH_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | 14 | 15 | // ******** global macro definitions ******** 16 | 17 | 18 | // ******** global type definitions ********* 19 | typedef struct 20 | { 21 | cxa_ioStream_t nonnullStream; 22 | cxa_ioStream_t* nullableStream; 23 | 24 | size_t numBytesWritten; 25 | }cxa_ioStream_nullablePassthrough_t; 26 | 27 | 28 | // ******** global function prototypes ******** 29 | void cxa_ioStream_nullablePassthrough_init(cxa_ioStream_nullablePassthrough_t *const npIn); 30 | 31 | cxa_ioStream_t* cxa_ioStream_nullablePassthrough_getNonullStream(cxa_ioStream_nullablePassthrough_t *const npIn); 32 | 33 | cxa_ioStream_t* cxa_ioStream_nullablePassthrough_getNullableStream(cxa_ioStream_nullablePassthrough_t *const npIn); 34 | void cxa_ioStream_nullablePassthrough_setNullableStream(cxa_ioStream_nullablePassthrough_t *const npIn, 35 | cxa_ioStream_t *const ioStreamIn); 36 | 37 | size_t cxa_ioStream_nullablePassthrough_getNumBytesWritten(cxa_ioStream_nullablePassthrough_t *const npIn); 38 | void cxa_ioStream_nullablePassthrough_resetNumByesWritten(cxa_ioStream_nullablePassthrough_t *const npIn); 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/serial/cxa_ioStream_peekable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_IOSTREAM_PEEKABLE_H_ 8 | #define CXA_IOSTREAM_PEEKABLE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | typedef struct 21 | { 22 | cxa_ioStream_t super; 23 | cxa_ioStream_t* underlyingStream; 24 | 25 | bool hasBufferedByte; 26 | uint8_t bufferedByte; 27 | }cxa_ioStream_peekable_t; 28 | 29 | 30 | // ******** global function prototypes ******** 31 | void cxa_ioStream_peekable_init(cxa_ioStream_peekable_t *const ioStreamIn, 32 | cxa_ioStream_t *const underlyingStreamIn); 33 | 34 | cxa_ioStream_readStatus_t cxa_ioStream_peekable_hasBytesAvailable(cxa_ioStream_peekable_t *const ioStreamIn); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/serial/cxa_ioStream_pipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_IOSTREAM_PIPE_H_ 8 | #define CXA_IOSTREAM_PIPE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | #ifndef CXA_IOSTREAM_PIPE_BUFFER_SIZE_BYTES 20 | #define CXA_IOSTREAM_PIPE_BUFFER_SIZE_BYTES 128 21 | #endif 22 | 23 | 24 | // ******** global type definitions ********* 25 | /** 26 | * @public 27 | * @brief "Forward" declaration of the cxa_ioStream_pipe_t object 28 | */ 29 | typedef struct cxa_ioStream_pipe cxa_ioStream_pipe_t; 30 | 31 | 32 | struct cxa_ioStream_pipe 33 | { 34 | cxa_ioStream_t endPoint1; 35 | cxa_ioStream_t endPoint2; 36 | 37 | cxa_fixedFifo_t fifo_ep1Read; 38 | uint8_t fifo_ep1Read_raw[CXA_IOSTREAM_PIPE_BUFFER_SIZE_BYTES]; 39 | 40 | cxa_fixedFifo_t fifo_ep2Read; 41 | uint8_t fifo_ep2Read_raw[CXA_IOSTREAM_PIPE_BUFFER_SIZE_BYTES]; 42 | }; 43 | 44 | 45 | // ******** global function prototypes ******** 46 | void cxa_ioStream_pipe_init(cxa_ioStream_pipe_t *const ioStreamIn); 47 | 48 | cxa_ioStream_t* cxa_ioStream_pipe_getEndpoint1(cxa_ioStream_pipe_t* const ioStreamIn); 49 | cxa_ioStream_t* cxa_ioStream_pipe_getEndpoint2(cxa_ioStream_pipe_t* const ioStreamIn); 50 | 51 | #endif // CXA_IOSTREAM_PIPE_H_ 52 | -------------------------------------------------------------------------------- /include/serial/cxa_ioStream_tee.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_IOSTREAM_TEE_H_ 8 | #define CXA_IOSTREAM_TEE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // ******** global macro definitions ******** 19 | #ifndef CXA_IOSTREAM_TEE_BUFFER_SIZE_BYTES 20 | #define CXA_IOSTREAM_TEE_BUFFER_SIZE_BYTES 128 21 | #endif 22 | 23 | 24 | // ******** global type definitions ********* 25 | /** 26 | * @public 27 | */ 28 | typedef struct 29 | { 30 | cxa_ioStream_t endPoint1; 31 | cxa_ioStream_t endPoint2; 32 | cxa_ioStream_t endPoint3; 33 | 34 | cxa_fixedFifo_t fifo_ep1Read; 35 | uint8_t fifo_ep1Read_raw[CXA_IOSTREAM_TEE_BUFFER_SIZE_BYTES]; 36 | 37 | cxa_fixedFifo_t fifo_ep2Read; 38 | uint8_t fifo_ep2Read_raw[CXA_IOSTREAM_TEE_BUFFER_SIZE_BYTES]; 39 | 40 | cxa_fixedFifo_t fifo_ep3Read; 41 | uint8_t fifo_ep3Read_raw[CXA_IOSTREAM_TEE_BUFFER_SIZE_BYTES]; 42 | }cxa_ioStream_tee_t; 43 | 44 | 45 | // ******** global function prototypes ******** 46 | void cxa_ioStream_tee_init(cxa_ioStream_tee_t *const ioStreamIn); 47 | 48 | cxa_ioStream_t* cxa_ioStream_tee_getEndpoint1(cxa_ioStream_tee_t* const ioStreamIn); 49 | cxa_ioStream_t* cxa_ioStream_tee_getEndpoint2(cxa_ioStream_tee_t* const ioStreamIn); 50 | cxa_ioStream_t* cxa_ioStream_tee_getEndpoint3(cxa_ioStream_tee_t* const ioStreamIn); 51 | 52 | #endif // CXA_IOSTREAM_TEE_H_ 53 | -------------------------------------------------------------------------------- /include/serial/cxa_protocolParser_cleProto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_PROTOCOLPARSER_CLE_H_ 8 | #define CXA_PROTOCOLPARSER_CLE_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | typedef struct cxa_protocolParser_cleProto cxa_protocolParser_cleProto_t; 21 | 22 | 23 | struct cxa_protocolParser_cleProto 24 | { 25 | cxa_protocolParser_t super; 26 | 27 | cxa_stateMachine_t stateMachine; 28 | }; 29 | 30 | 31 | // ******** global function prototypes ******** 32 | void cxa_protocolParser_cleProto_init(cxa_protocolParser_cleProto_t *const clePpIn, cxa_ioStream_t *const ioStreamIn, cxa_fixedByteBuffer_t *const buffIn, int threadIdIn); 33 | 34 | 35 | #endif /* CXA_PROTOCOLPARSER_CLE_H_ */ 36 | -------------------------------------------------------------------------------- /include/serial/cxa_protocolParser_crlf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_PROTOCOLPARSER_CRLF_H_ 8 | #define CXA_PROTOCOLPARSER_CRLF_H_ 9 | 10 | 11 | // ******** includes ******** 12 | #include 13 | #include 14 | 15 | 16 | // ******** global macro definitions ******** 17 | 18 | 19 | // ******** global type definitions ********* 20 | typedef struct cxa_protocolParser_crlf cxa_protocolParser_crlf_t; 21 | 22 | 23 | struct cxa_protocolParser_crlf 24 | { 25 | cxa_protocolParser_t super; 26 | 27 | bool isPaused; 28 | cxa_stateMachine_t stateMachine; 29 | }; 30 | 31 | 32 | // ******** global function prototypes ******** 33 | /** 34 | * Starts in the paused state...must call resume for proper operation 35 | */ 36 | void cxa_protocolParser_crlf_init(cxa_protocolParser_crlf_t *const crlfPpIn, cxa_ioStream_t *const ioStreamIn, cxa_fixedByteBuffer_t *const buffIn, int threadIdIn); 37 | 38 | void cxa_protocolParser_crlf_pause(cxa_protocolParser_crlf_t *const crlfPpIn); 39 | void cxa_protocolParser_crlf_resume(cxa_protocolParser_crlf_t *const crlfPpIn); 40 | 41 | 42 | #endif /* CXA_PROTOCOLPARSER_CRLF_H_ */ 43 | -------------------------------------------------------------------------------- /include/timeUtils/cxa_timeUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #ifndef CXA_TIMEUTILS_H_ 8 | #define CXA_TIMEUTILS_H_ 9 | 10 | 11 | // ******** includes ******** 12 | 13 | 14 | // ******** global macro definitions ******** 15 | #define CXA_TIME_HOURS_TO_MS(hoursIn) ((hoursIn) * 60 * 60 * 1000) 16 | #define CXA_TIME_MINS_TO_MS(minsIn) ((minsIn) * 60 * 1000) 17 | #define CXA_TIME_SECS_TO_MS(secsIn) ((secsIn) * 1000) 18 | 19 | 20 | // ******** global type definitions ********* 21 | 22 | 23 | // ******** global function prototypes ******** 24 | 25 | 26 | #endif // CXA_TIMEUTILS_H_ 27 | -------------------------------------------------------------------------------- /src/arch-atmega/cxa_atmega_criticalSection.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_criticalSection.h" 8 | 9 | 10 | // ******** includes ******** 11 | 12 | 13 | // ******** local macro definitions ******** 14 | 15 | 16 | // ******** local type definitions ******** 17 | 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | void cxa_criticalSection_enter(void) 28 | { 29 | // taskENTER_CRITICAL(); 30 | } 31 | 32 | 33 | void cxa_criticalSection_exit(void) 34 | { 35 | // taskEXIT_CRITICAL(); 36 | } 37 | 38 | 39 | // ******** local function implementations ******** 40 | -------------------------------------------------------------------------------- /src/arch-atmega/cxa_atmega_delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_delay.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | void cxa_delay_ms(uint16_t delay_msIn) 28 | { 29 | uint32_t delay_ticks = (F_CPU / 1000) * delay_msIn; 30 | 31 | while( delay_ticks >= 10000 ) 32 | { 33 | __builtin_avr_delay_cycles(10000); 34 | delay_ticks -= 10000; 35 | } 36 | while( delay_ticks >= 1000 ) 37 | { 38 | __builtin_avr_delay_cycles(1000); 39 | delay_ticks -= 1000; 40 | } 41 | while( delay_ticks >= 100 ) 42 | { 43 | __builtin_avr_delay_cycles(100); 44 | delay_ticks -= 100; 45 | } 46 | while( delay_ticks != 0 ) 47 | { 48 | __builtin_avr_delay_cycles(1); 49 | delay_ticks -= 1; 50 | } 51 | } 52 | 53 | 54 | // ******** local function implementations ******** 55 | -------------------------------------------------------------------------------- /src/arch-atmega/cxa_atmega_led_pwm8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_atmega_led_pwm8.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | #define CXA_LOG_LEVEL CXA_LOG_LEVEL_TRACE 14 | #include 15 | 16 | 17 | // ******** local macro definitions ******** 18 | 19 | 20 | // ******** local type definitions ******** 21 | 22 | 23 | // ******** local function prototypes ******** 24 | static void scm_setBrightness(cxa_led_runLoop_t *const superIn, uint8_t brightness_255In); 25 | 26 | 27 | // ******** local variable declarations ********* 28 | 29 | 30 | // ******** global function implementations ******** 31 | void cxa_atmega_led_pwm8_init(cxa_atmega_led_pwm8_t *const ledIn, cxa_atmega_timer_ocr_t *const ocrIn, int threadIdIn) 32 | { 33 | cxa_assert(ledIn); 34 | cxa_assert(ocrIn); 35 | 36 | // save our references 37 | ledIn->ocr = ocrIn; 38 | 39 | // initialize our super class (since it sets our initial value) 40 | cxa_led_runLoop_init(&ledIn->super, scm_setBrightness, threadIdIn); 41 | } 42 | 43 | 44 | // ******** local function implementations ******** 45 | static void scm_setBrightness(cxa_led_runLoop_t *const superIn, uint8_t brightness_255In) 46 | { 47 | cxa_atmega_led_pwm8_t* ledIn = (cxa_atmega_led_pwm8_t*)superIn; 48 | cxa_assert(ledIn); 49 | 50 | cxa_atmega_timer_ocr_setValue(ledIn->ocr, brightness_255In); 51 | } 52 | -------------------------------------------------------------------------------- /src/arch-atmega/cxa_atmega_mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_mutex.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | 15 | // ******** local macro definitions ******** 16 | 17 | 18 | // ******** local type definitions ******** 19 | typedef struct 20 | { 21 | cxa_mutex_t super; 22 | }cxa_atmega_mutex_t; 23 | 24 | 25 | typedef struct 26 | { 27 | bool isUsed; 28 | cxa_atmega_mutex_t mutex; 29 | }mutexEntry_t; 30 | 31 | 32 | // ******** local function prototypes ******** 33 | static void init(void); 34 | 35 | 36 | // ******** local variable declarations ********* 37 | static bool isInit = false; 38 | static mutexEntry_t mutexEntries[1]; 39 | 40 | 41 | // ******** global function implementations ******** 42 | cxa_mutex_t* cxa_mutex_reserve(void) 43 | { 44 | if( !isInit ) init(); 45 | 46 | for( size_t i = 0; i < sizeof(mutexEntries)/sizeof(*mutexEntries); i++ ) 47 | { 48 | if( !mutexEntries[i].isUsed ) 49 | { 50 | mutexEntries[i].isUsed = true; 51 | return &mutexEntries[i].mutex.super; 52 | } 53 | } 54 | 55 | // no free mutexs 56 | return NULL; 57 | } 58 | 59 | 60 | void cxa_mutex_aquire(cxa_mutex_t *const mutexIn) 61 | { 62 | cxa_assert(mutexIn); 63 | 64 | cli(); 65 | } 66 | 67 | 68 | void cxa_mutex_release(cxa_mutex_t *const mutexIn) 69 | { 70 | cxa_assert(mutexIn); 71 | 72 | sei(); 73 | } 74 | 75 | 76 | // ******** local function implementations ******** 77 | static void init(void) 78 | { 79 | for( size_t i = 0; i < sizeof(mutexEntries)/sizeof(*mutexEntries); i++ ) 80 | { 81 | mutexEntries[i].isUsed = false; 82 | } 83 | 84 | isInit = true; 85 | } 86 | -------------------------------------------------------------------------------- /src/arch-atmega/cxa_atmega_random.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_random.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | 17 | // ******** local macro definitions ******** 18 | 19 | 20 | // ******** local type definitions ******** 21 | 22 | 23 | // ******** local function prototypes ******** 24 | static void init(void); 25 | 26 | 27 | // ******** local variable declarations ********* 28 | static bool isInit = false; 29 | 30 | 31 | // ******** global function implementations ******** 32 | uint32_t cxa_random_numberInRange(uint32_t lowerLimitIn, uint32_t upperLimitIn) 33 | { 34 | if( isInit ) init(); 35 | 36 | // RAND_MAX is 0x7FFF...need to combine at least two of these.... 37 | uint32_t randUint32Range = (((uint32_t)rand()) << 16) | (((uint32_t)rand()) << 0); 38 | 39 | // taken from http://c-faq.com/lib/randrange.html 40 | return lowerLimitIn + randUint32Range / (UINT32_MAX / (upperLimitIn - lowerLimitIn + 1) + 1); 41 | } 42 | 43 | 44 | // ******** local function implementations ******** 45 | static void init(void) 46 | { 47 | // generate a random seed for our random reset period 48 | unsigned randomSeed = 0; 49 | uint8_t* uniqueBytes; 50 | size_t numUniqueBytes; 51 | cxa_uniqueId_getBytes(&uniqueBytes, &numUniqueBytes); 52 | for( size_t i = 0; i < numUniqueBytes; i++ ) 53 | { 54 | randomSeed += uniqueBytes[i]; 55 | } 56 | srand(randomSeed); 57 | 58 | // we're now seeded an initialized 59 | isInit = true; 60 | } 61 | -------------------------------------------------------------------------------- /src/arch-atmega/cxa_atmega_reboot.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_reboot.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | void cxa_reboot(void) 28 | { 29 | wdt_enable(WDTO_15MS); 30 | while(1); 31 | } 32 | 33 | 34 | // required on newer AVRs to disable WDT on reboot 35 | void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3"))); 36 | void wdt_init(void) 37 | { 38 | MCUSR = 0; 39 | wdt_disable(); 40 | 41 | return; 42 | } 43 | 44 | 45 | // ******** local function implementations ******** 46 | -------------------------------------------------------------------------------- /src/arch-atmega/cxa_atmega_timeBase.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include 8 | 9 | // ******** includes ******** 10 | #include 11 | 12 | 13 | // ******** local macro definitions ******** 14 | 15 | 16 | // ******** local type definitions ******** 17 | 18 | 19 | // ******** local function prototypes ******** 20 | static void timer8_cb_onOverflow(cxa_atmega_timer_t *const timerIn, void *userVarIn); 21 | 22 | 23 | // ******** local variable declarations ********* 24 | static cxa_atmega_timer_t* timer = NULL; 25 | static uint32_t numOverflows = 0; 26 | 27 | 28 | // ******** global function implementations ******** 29 | void cxa_atmega_timeBase_initWithTimer8(cxa_atmega_timer_t *const timerIn) 30 | { 31 | cxa_assert(timerIn); 32 | 33 | timer = timerIn; 34 | cxa_atmega_timer_addListener(timer, timer8_cb_onOverflow, NULL); 35 | cxa_atmega_timer_enableInterrupt_overflow(timer); 36 | } 37 | 38 | 39 | uint32_t cxa_timeBase_getCount_us(void) 40 | { 41 | return (timer != NULL) ? (numOverflows * ((uint32_t)(cxa_atmega_timer_getOverflowPeriod_s(timer) * 1.0E6))) : 0; 42 | } 43 | 44 | 45 | uint32_t cxa_timeBase_getMaxCount_us(void) 46 | { 47 | return UINT32_MAX; 48 | } 49 | 50 | 51 | // ******** local function implementations ******** 52 | static void timer8_cb_onOverflow(cxa_atmega_timer_t *const timerIn, void *userVarIn) 53 | { 54 | numOverflows++; 55 | } 56 | -------------------------------------------------------------------------------- /src/arch-atmega/cxa_atmega_uniqueId.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_uniqueId.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | // ******** local macro definitions ******** 17 | 18 | 19 | // ******** local type definitions ******** 20 | 21 | 22 | // ******** local function prototypes ******** 23 | static void init(void); 24 | 25 | 26 | // ******** local variable declarations ********* 27 | static bool isInit = false; 28 | static uint8_t id_bytes[10]; 29 | static char id_str[30]; 30 | 31 | 32 | // ******** global function implementations ******** 33 | void cxa_uniqueId_getBytes(uint8_t** bytesOut, size_t* numBytesOut) 34 | { 35 | if( !isInit ) init(); 36 | 37 | if( bytesOut ) *bytesOut = (uint8_t*)&id_bytes; 38 | if( numBytesOut ) *numBytesOut = sizeof(id_bytes); 39 | } 40 | 41 | 42 | char* cxa_uniqueId_getHexString(void) 43 | { 44 | if( !isInit ) init(); 45 | 46 | return id_str; 47 | } 48 | 49 | 50 | // ******** local function implementations ******** 51 | static void init(void) 52 | { 53 | for( size_t i = 0; i < sizeof(id_bytes); i++ ) 54 | { 55 | id_bytes[i] = boot_signature_byte_get(14+i); 56 | } 57 | 58 | sprintf(id_str, "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", 59 | id_bytes[0], id_bytes[1], id_bytes[2], id_bytes[3], id_bytes[4], 60 | id_bytes[5], id_bytes[6], id_bytes[7], id_bytes[8], id_bytes[9] ); 61 | id_str[sizeof(id_str)-1] = 0; 62 | 63 | isInit = true; 64 | } 65 | -------------------------------------------------------------------------------- /src/arch-bgm/cxa_bgm_criticalSection.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_criticalSection.h" 8 | 9 | 10 | // ******** includes ******** 11 | 12 | 13 | // ******** local macro definitions ******** 14 | 15 | 16 | // ******** local type definitions ******** 17 | 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | void cxa_criticalSection_enter(void) 28 | { 29 | } 30 | 31 | 32 | void cxa_criticalSection_exit(void) 33 | { 34 | } 35 | 36 | 37 | // ******** local function implementations ******** 38 | -------------------------------------------------------------------------------- /src/arch-bgm/cxa_bgm_delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_delay.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | 15 | // ******** local macro definitions ******** 16 | 17 | 18 | // ******** local type definitions ******** 19 | 20 | 21 | // ******** local function prototypes ******** 22 | 23 | 24 | // ******** local variable declarations ********* 25 | static bool isCalibrated = false; 26 | 27 | 28 | // ******** global function implementations ******** 29 | void cxa_delay_ms(uint16_t delay_msIn) 30 | { 31 | if( !isCalibrated ) 32 | { 33 | UDELAY_Calibrate(); 34 | isCalibrated = true; 35 | } 36 | 37 | for( uint16_t i = 0; i < delay_msIn; i++ ) 38 | { 39 | UDELAY_Delay(1000); 40 | } 41 | } 42 | 43 | 44 | // ******** local function implementations ******** 45 | -------------------------------------------------------------------------------- /src/arch-bgm/cxa_bgm_timeBase.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | 8 | 9 | // ******** includes ******** 10 | #include 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | uint32_t cxa_timeBase_getCount_us(void) 28 | { 29 | return (RTCC_CounterGet() / 32768.0) * 1E6; 30 | } 31 | 32 | 33 | uint32_t cxa_timeBase_getMaxCount_us(void) 34 | { 35 | return 131072; 36 | } 37 | 38 | 39 | // ******** local function implementations ******** 40 | -------------------------------------------------------------------------------- /src/arch-bgm/cxa_bgm_uniqueId.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_uniqueId.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | #include 14 | 15 | // Bluetooth stack headers 16 | #include "bg_types.h" 17 | #include "native_gecko.h" 18 | #include "infrastructure.h" 19 | 20 | 21 | // ******** local macro definitions ******** 22 | 23 | 24 | // ******** local type definitions ******** 25 | 26 | 27 | // ******** local function prototypes ******** 28 | static void init(void); 29 | 30 | 31 | // ******** local variable declarations ********* 32 | static bool isInit = false; 33 | static uint8_t id_bytes[6]; 34 | static char id_str[18]; 35 | 36 | 37 | // ******** global function implementations ******** 38 | void cxa_uniqueId_getBytes(uint8_t** bytesOut, size_t* numBytesOut) 39 | { 40 | if( !isInit ) init(); 41 | 42 | if( bytesOut ) *bytesOut = (uint8_t*)&id_bytes; 43 | if( numBytesOut ) *numBytesOut = sizeof(id_bytes); 44 | } 45 | 46 | 47 | char* cxa_uniqueId_getHexString(void) 48 | { 49 | if( !isInit ) init(); 50 | 51 | return id_str; 52 | } 53 | 54 | 55 | // ******** local function implementations ******** 56 | static void init(void) 57 | { 58 | struct gecko_msg_system_get_bt_address_rsp_t* resp = gecko_cmd_system_get_bt_address(); 59 | cxa_assert(resp); 60 | // reverse the bytes to get the right mac address order 61 | for( size_t i = 0; i < sizeof(id_bytes); i++ ) 62 | { 63 | id_bytes[i] = resp->address.addr[sizeof(id_bytes) - i -1]; 64 | } 65 | 66 | sprintf(id_str, "%02X:%02X:%02X:%02X:%02X:%02X", id_bytes[0], id_bytes[1], id_bytes[2], id_bytes[3], id_bytes[4], id_bytes[5]); 67 | id_str[sizeof(id_str)-1] = 0; 68 | 69 | isInit = true; 70 | } 71 | -------------------------------------------------------------------------------- /src/arch-common/cxa_led.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_led.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | #define CXA_LOG_LEVEL CXA_LOG_LEVEL_TRACE 14 | #include 15 | 16 | 17 | // ******** local macro definitions ******** 18 | 19 | 20 | // ******** local type definitions ******** 21 | 22 | 23 | // ******** local function prototypes ******** 24 | 25 | 26 | // ******** local variable declarations ********* 27 | 28 | 29 | // ******** global function implementations ******** 30 | void cxa_led_init(cxa_led_t *const ledIn, 31 | cxa_led_scm_setSolid_t scm_setSolidIn, 32 | cxa_led_scm_blink_t scm_blinkIn, 33 | cxa_led_scm_flashOnce_t scm_flashOnceIn) 34 | { 35 | cxa_assert(ledIn); 36 | cxa_assert(scm_setSolidIn); 37 | 38 | // save our references 39 | ledIn->scm_setSolid = scm_setSolidIn; 40 | ledIn->scm_blink = scm_blinkIn; 41 | ledIn->scm_flashOnce = scm_flashOnceIn; 42 | 43 | // make sure we're initially off 44 | cxa_led_setSolid(ledIn, 0); 45 | } 46 | 47 | 48 | void cxa_led_blink(cxa_led_t *const ledIn, uint8_t onBrightness_255In, uint32_t onPeriod_msIn, uint32_t offPeriod_msIn) 49 | { 50 | cxa_assert(ledIn); 51 | cxa_assert(ledIn->scm_blink); 52 | 53 | ledIn->prevState = ledIn->currState; 54 | ledIn->currState = CXA_LED_STATE_BLINK; 55 | 56 | ledIn->scm_blink(ledIn, onBrightness_255In, onPeriod_msIn, offPeriod_msIn); 57 | } 58 | 59 | 60 | void cxa_led_flashOnce(cxa_led_t *const ledIn, uint8_t brightness_255In, uint32_t period_msIn) 61 | { 62 | cxa_assert(ledIn); 63 | cxa_assert(ledIn->scm_flashOnce); 64 | if( ledIn->currState == CXA_LED_STATE_FLASH_ONCE) return; 65 | 66 | ledIn->prevState = ledIn->currState; 67 | ledIn->currState = CXA_LED_STATE_FLASH_ONCE; 68 | 69 | ledIn->scm_flashOnce(ledIn, brightness_255In, period_msIn); 70 | } 71 | 72 | 73 | void cxa_led_setSolid(cxa_led_t *const ledIn, uint8_t brightness_255In) 74 | { 75 | cxa_assert(ledIn); 76 | 77 | ledIn->prevState = ledIn->currState; 78 | ledIn->currState = CXA_LED_STATE_SOLID; 79 | 80 | ledIn->scm_setSolid(ledIn, brightness_255In); 81 | } 82 | 83 | 84 | // ******** local function implementations ******** 85 | -------------------------------------------------------------------------------- /src/arch-common/cxa_led_gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_led_gpio.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | 15 | // ******** local macro definitions ******** 16 | 17 | 18 | // ******** local type definitions ******** 19 | 20 | 21 | // ******** local function prototypes ******** 22 | static void scm_setBrightness(cxa_led_runLoop_t *const superIn, uint8_t brightness_255In); 23 | 24 | 25 | // ******** local variable declarations ********* 26 | 27 | 28 | // ******** global function implementations ******** 29 | void cxa_led_gpio_init(cxa_led_gpio_t *const ledIn, cxa_gpio_t *const gpioIn, int threadIdIn) 30 | { 31 | cxa_assert(ledIn); 32 | cxa_assert(gpioIn); 33 | 34 | // save our references 35 | ledIn->gpio = gpioIn; 36 | 37 | // initialize our super class (since it sets our initial value) 38 | cxa_led_runLoop_init(&ledIn->super, scm_setBrightness, threadIdIn); 39 | 40 | } 41 | 42 | 43 | // ******** local function implementations ******** 44 | static void scm_setBrightness(cxa_led_runLoop_t *const superIn, uint8_t brightness_255In) 45 | { 46 | cxa_led_gpio_t* ledIn = (cxa_led_gpio_t*)superIn; 47 | cxa_assert(ledIn); 48 | 49 | // don't change any state, just change the brightness 50 | cxa_gpio_setValue(ledIn->gpio, (brightness_255In > 0)); 51 | } 52 | -------------------------------------------------------------------------------- /src/arch-common/cxa_nvsManager.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_nvsManager.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | 15 | // ******** local macro definitions ******** 16 | 17 | 18 | // ******** local type definitions ******** 19 | 20 | 21 | // ******** local function prototypes ******** 22 | 23 | 24 | // ******** local variable declarations ********* 25 | 26 | 27 | // ******** global function implementations ******** 28 | void cxa_nvsManager_get_cString_withDefault(const char *const keyIn, char *const valueOut, size_t maxOutputSize_bytes, char *const defaultIn) 29 | { 30 | if( !cxa_nvsManager_get_cString(keyIn, valueOut, maxOutputSize_bytes) ) 31 | { 32 | cxa_stringUtils_copy(valueOut, defaultIn, maxOutputSize_bytes); 33 | } 34 | } 35 | 36 | 37 | void cxa_nvsManager_get_uint8_withDefault(const char *const keyIn, uint8_t *const valueOut, uint8_t defaultIn) 38 | { 39 | if( !cxa_nvsManager_get_uint8(keyIn, valueOut) ) 40 | { 41 | if( valueOut != NULL ) *valueOut = defaultIn; 42 | } 43 | } 44 | 45 | 46 | void cxa_nvsManager_get_uint32_withDefault(const char *const keyIn, uint32_t *const valueOut, uint32_t defaultIn) 47 | { 48 | if( !cxa_nvsManager_get_uint32(keyIn, valueOut) ) 49 | { 50 | if( valueOut != NULL ) *valueOut = defaultIn; 51 | } 52 | } 53 | 54 | 55 | // ******** local function implementations ******** 56 | -------------------------------------------------------------------------------- /src/arch-common/cxa_rgbLed_triLed.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_rgbLed_triLed.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | #define CXA_LOG_LEVEL CXA_LOG_LEVEL_TRACE 14 | #include 15 | 16 | 17 | // ******** local macro definitions ******** 18 | 19 | 20 | // ******** local type definitions ******** 21 | 22 | 23 | // ******** local function prototypes ******** 24 | static void scm_setRgb(cxa_rgbLed_runLoop_t *const superIn, const uint8_t r_255In, const uint8_t g_255In, const uint8_t b_255In); 25 | 26 | 27 | // ******** local variable declarations ********* 28 | 29 | 30 | // ******** global function implementations ******** 31 | void cxa_rgbLed_triLed_init(cxa_rgbLed_triLed_t *const ledIn, 32 | cxa_led_t *const led_rIn, cxa_led_t *const led_gIn, cxa_led_t *const led_bIn, 33 | int threadIdIn) 34 | { 35 | cxa_assert(ledIn); 36 | cxa_assert(led_rIn); 37 | cxa_assert(led_gIn); 38 | cxa_assert(led_bIn); 39 | 40 | // save our references 41 | ledIn->led_r = led_rIn; 42 | ledIn->led_g = led_gIn; 43 | ledIn->led_b = led_bIn; 44 | 45 | // initialize our superclass 46 | cxa_rgbLed_runLoop_init(&ledIn->super, scm_setRgb, threadIdIn) 47 | ;} 48 | 49 | 50 | // ******** local function implementations ******** 51 | static void scm_setRgb(cxa_rgbLed_runLoop_t *const superIn, const uint8_t r_255In, const uint8_t g_255In, const uint8_t b_255In) 52 | { 53 | cxa_rgbLed_triLed_t *const ledIn = (cxa_rgbLed_triLed_t *const)superIn; 54 | cxa_assert(ledIn); 55 | 56 | cxa_led_setSolid(ledIn->led_r, r_255In); 57 | cxa_led_setSolid(ledIn->led_g, g_255In); 58 | cxa_led_setSolid(ledIn->led_b, b_255In); 59 | } 60 | -------------------------------------------------------------------------------- /src/arch-common/cxa_usart.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_usart.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | 15 | // ******** local macro definitions ******** 16 | 17 | 18 | // ******** local type definitions ******** 19 | 20 | 21 | // ******** local function prototypes ******** 22 | 23 | 24 | // ******** local variable declarations ********* 25 | 26 | 27 | // ******** global function implementations ******** 28 | cxa_ioStream_t* cxa_usart_getIoStream(cxa_usart_t* usartIn) 29 | { 30 | cxa_assert(usartIn); 31 | 32 | return &usartIn->ioStream; 33 | } 34 | 35 | 36 | // ******** local function implementations ******** 37 | -------------------------------------------------------------------------------- /src/arch-dummy/cxa_dummy_delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_delay.h" 8 | 9 | 10 | // ******** includes ******** 11 | 12 | 13 | // ******** local macro definitions ******** 14 | 15 | 16 | // ******** local type definitions ******** 17 | 18 | 19 | // ******** local function prototypes ******** 20 | 21 | 22 | // ******** local variable declarations ********* 23 | 24 | 25 | // ******** global function implementations ******** 26 | void cxa_delay_ms(uint16_t delay_msIn) 27 | { 28 | // TODO: delay here 29 | } 30 | 31 | 32 | // ******** local function implementations ******** 33 | -------------------------------------------------------------------------------- /src/arch-esp32/cxa_esp32_criticalSection.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_criticalSection.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | 17 | // ******** local macro definitions ******** 18 | 19 | 20 | // ******** local type definitions ******** 21 | 22 | 23 | 24 | // ******** local function prototypes ******** 25 | 26 | 27 | // ******** local variable declarations ********* 28 | static portMUX_TYPE myMutex = portMUX_INITIALIZER_UNLOCKED; 29 | 30 | 31 | // ******** global function implementations ******** 32 | void cxa_criticalSection_enter(void) 33 | { 34 | portENTER_CRITICAL(&myMutex); 35 | } 36 | 37 | 38 | void cxa_criticalSection_exit(void) 39 | { 40 | portEXIT_CRITICAL(&myMutex); 41 | } 42 | 43 | 44 | // ******** local function implementations ******** 45 | -------------------------------------------------------------------------------- /src/arch-esp32/cxa_esp32_delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_delay.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | // ******** local macro definitions ******** 17 | #define NOP() asm volatile ("nop") 18 | 19 | 20 | // ******** local type definitions ******** 21 | 22 | 23 | // ******** local function prototypes ******** 24 | static unsigned long micros(); 25 | static void delayMicroseconds(uint32_t us); 26 | 27 | 28 | // ******** local variable declarations ********* 29 | 30 | 31 | // ******** global function implementations ******** 32 | void cxa_delay_ms(uint16_t delay_msIn) 33 | { 34 | vTaskDelay(delay_msIn / portTICK_PERIOD_MS); 35 | } 36 | 37 | 38 | void cxa_delay_us(uint32_t delay_usIn) 39 | { 40 | delayMicroseconds(delay_usIn); 41 | } 42 | 43 | 44 | // ******** local function implementations ******** 45 | // taken from arduino-esp32 core 46 | static unsigned long IRAM_ATTR micros() 47 | { 48 | return (unsigned long) (esp_timer_get_time()); 49 | } 50 | 51 | // taken from arduino-esp32 core 52 | static void IRAM_ATTR delayMicroseconds(uint32_t us) 53 | { 54 | uint32_t m = micros(); 55 | if(us){ 56 | uint32_t e = (m + us); 57 | if(m > e){ //overflow 58 | while(micros() > e){ 59 | NOP(); 60 | } 61 | } 62 | while(micros() < e){ 63 | NOP(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/arch-esp32/cxa_esp32_mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_mutex.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // ******** local macro definitions ******** 19 | #ifndef CXA_ESP32_MAXNUM_MUTEX 20 | #define CXA_ESP32_MAXNUM_MUTEX 2 21 | #endif 22 | 23 | 24 | // ******** local type definitions ******** 25 | typedef struct 26 | { 27 | cxa_mutex_t super; 28 | 29 | SemaphoreHandle_t sem; 30 | }cxa_esp32_mutex_t; 31 | 32 | 33 | typedef struct 34 | { 35 | bool isUsed; 36 | cxa_esp32_mutex_t mutex; 37 | }mutexEntry_t; 38 | 39 | 40 | // ******** local function prototypes ******** 41 | static void init(void); 42 | 43 | 44 | // ******** local variable declarations ********* 45 | static bool isInit = false; 46 | static mutexEntry_t mutexEntries[CXA_ESP32_MAXNUM_MUTEX]; 47 | 48 | 49 | // ******** global function implementations ******** 50 | cxa_mutex_t* cxa_mutex_reserve(void) 51 | { 52 | if( !isInit ) init(); 53 | 54 | for( size_t i = 0; i < sizeof(mutexEntries)/sizeof(*mutexEntries); i++ ) 55 | { 56 | if( !mutexEntries[i].isUsed ) 57 | { 58 | mutexEntries[i].isUsed = true; 59 | return &mutexEntries[i].mutex.super; 60 | } 61 | } 62 | 63 | // no free mutexs 64 | return NULL; 65 | } 66 | 67 | 68 | void cxa_mutex_aquire(cxa_mutex_t *const mutexIn) 69 | { 70 | cxa_assert(mutexIn); 71 | 72 | xSemaphoreTake(((cxa_esp32_mutex_t*)mutexIn)->sem, portMAX_DELAY); 73 | } 74 | 75 | 76 | void cxa_mutex_release(cxa_mutex_t *const mutexIn) 77 | { 78 | cxa_assert(mutexIn); 79 | 80 | xSemaphoreGive(((cxa_esp32_mutex_t*)mutexIn)->sem); 81 | } 82 | 83 | 84 | // ******** local function implementations ******** 85 | static void init(void) 86 | { 87 | for( size_t i = 0; i < sizeof(mutexEntries)/sizeof(*mutexEntries); i++ ) 88 | { 89 | mutexEntries[i].isUsed = false; 90 | mutexEntries[i].mutex.sem = xSemaphoreCreateMutex(); 91 | } 92 | 93 | isInit = true; 94 | } 95 | -------------------------------------------------------------------------------- /src/arch-esp32/cxa_esp32_random.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_random.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | #include 14 | 15 | 16 | // ******** local macro definitions ******** 17 | 18 | 19 | // ******** local type definitions ******** 20 | 21 | 22 | // ******** local function prototypes ******** 23 | 24 | 25 | // ******** local variable declarations ********* 26 | 27 | 28 | // ******** global function implementations ******** 29 | uint32_t cxa_random_numberInRange(uint32_t lowerLimitIn, uint32_t upperLimitIn) 30 | { 31 | cxa_assert(lowerLimitIn < upperLimitIn); 32 | 33 | return lowerLimitIn + (esp_random() / (UINT32_MAX / (upperLimitIn - lowerLimitIn + 1) + 1)); 34 | } 35 | 36 | 37 | // ******** local function implementations ******** 38 | -------------------------------------------------------------------------------- /src/arch-esp32/cxa_esp32_reboot.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_reboot.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include "esp_system.h" 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | void cxa_reboot(void) 28 | { 29 | esp_restart(); 30 | } 31 | 32 | 33 | // ******** local function implementations ******** 34 | -------------------------------------------------------------------------------- /src/arch-esp32/cxa_esp32_stepperMotorChannel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_stepperMotorChannel.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // ******** local macro definitions ******** 19 | 20 | 21 | // ******** local type definitions ******** 22 | 23 | 24 | // ******** local function prototypes ******** 25 | static void periodic_timer_callback(void* arg); 26 | 27 | 28 | // ******** local variable declarations ********* 29 | static bool isTimerRunning = false; 30 | static esp_timer_handle_t periodic_timer; 31 | 32 | static cxa_stepperMotorChannel_timedCallback_t cb = NULL; 33 | 34 | 35 | // ******** global function implementations ******** 36 | void cxa_stepperMotorChannel_registerTimedCallback(cxa_stepperMotorChannel_timedCallback_t cbIn, uint32_t stepFreq_hzIn) 37 | { 38 | cxa_assert(cbIn); 39 | 40 | // save our callback 41 | cb = cbIn; 42 | 43 | // stop our timer (if we're already running) 44 | if( isTimerRunning ) 45 | { 46 | esp_timer_stop(periodic_timer); 47 | } 48 | else 49 | { 50 | // create a new timer 51 | const esp_timer_create_args_t periodic_timer_args = { 52 | .callback = &periodic_timer_callback, 53 | .name = "stepCtrl" 54 | }; 55 | cxa_assert(esp_timer_create(&periodic_timer_args, &periodic_timer) == ESP_OK); 56 | } 57 | 58 | // start the timer 59 | cxa_assert(esp_timer_start_periodic(periodic_timer, (1.0 / ((float)stepFreq_hzIn)) * 1.0E6 ) == ESP_OK); 60 | isTimerRunning = true; 61 | } 62 | 63 | 64 | // ******** local function implementations ******** 65 | 66 | 67 | // ******** interrupt implementations ******** 68 | static void periodic_timer_callback(void* arg) 69 | { 70 | if( cb != NULL ) cb(); 71 | } 72 | -------------------------------------------------------------------------------- /src/arch-esp32/cxa_esp32_timeBase.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | #include 14 | 15 | 16 | // ******** local macro definitions ******** 17 | 18 | 19 | // ******** local type definitions ******** 20 | 21 | 22 | // ******** local function prototypes ******** 23 | 24 | 25 | // ******** local variable declarations ********* 26 | 27 | 28 | // ******** global function implementations ******** 29 | void cxa_esp32_timeBase_init(void) 30 | { 31 | } 32 | 33 | 34 | uint32_t cxa_timeBase_getCount_us(void) 35 | { 36 | return esp_timer_get_time() % UINT32_MAX; 37 | } 38 | 39 | 40 | uint32_t cxa_timeBase_getMaxCount_us(void) 41 | { 42 | return UINT32_MAX; 43 | } 44 | 45 | 46 | // ******** local function implementations ******** 47 | -------------------------------------------------------------------------------- /src/arch-esp32/cxa_esp32_uniqueId.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_uniqueId.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | // ******** local macro definitions ******** 17 | 18 | 19 | // ******** local type definitions ******** 20 | 21 | 22 | // ******** local function prototypes ******** 23 | static void init(void); 24 | 25 | 26 | // ******** local variable declarations ********* 27 | static bool isInit = false; 28 | static uint8_t id_bytes[6]; 29 | static char id_str[18]; 30 | 31 | 32 | // ******** global function implementations ******** 33 | void cxa_uniqueId_getBytes(uint8_t** bytesOut, size_t* numBytesOut) 34 | { 35 | if( !isInit ) init(); 36 | 37 | if( bytesOut ) *bytesOut = (uint8_t*)&id_bytes; 38 | if( numBytesOut ) *numBytesOut = sizeof(id_bytes); 39 | } 40 | 41 | 42 | char* cxa_uniqueId_getHexString(void) 43 | { 44 | if( !isInit ) init(); 45 | 46 | return id_str; 47 | } 48 | 49 | 50 | // ******** local function implementations ******** 51 | static void init(void) 52 | { 53 | cxa_assert(esp_read_mac(id_bytes, ESP_MAC_WIFI_STA) == ESP_OK); 54 | 55 | sprintf(id_str, "%02X:%02X:%02X:%02X:%02X:%02X", id_bytes[0], id_bytes[1], id_bytes[2], id_bytes[3], id_bytes[4], id_bytes[5]); 56 | id_str[sizeof(id_str)-1] = 0; 57 | 58 | isInit = true; 59 | } 60 | -------------------------------------------------------------------------------- /src/arch-pic32/cxa_pic32_criticalSection.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_criticalSection.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include "system_definitions.h" 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | 21 | // ******** local function prototypes ******** 22 | 23 | 24 | // ******** local variable declarations ********* 25 | 26 | 27 | // ******** global function implementations ******** 28 | void cxa_criticalSection_enter(void) 29 | { 30 | // taskENTER_CRITICAL(); 31 | } 32 | 33 | 34 | void cxa_criticalSection_exit(void) 35 | { 36 | // taskEXIT_CRITICAL(); 37 | } 38 | 39 | 40 | // ******** local function implementations ******** 41 | -------------------------------------------------------------------------------- /src/arch-pic32/cxa_pic32_delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_delay.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include "system_definitions.h" 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | void cxa_delay_ms(uint16_t delay_msIn) 28 | { 29 | vTaskDelay(delay_msIn / portTICK_PERIOD_MS); 30 | } 31 | 32 | 33 | // ******** local function implementations ******** 34 | -------------------------------------------------------------------------------- /src/arch-pic32/cxa_pic32_timeBase.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "system_definitions.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | uint32_t cxa_timeBase_getCount_us(void) 28 | { 29 | return xTaskGetTickCount() / configTICK_RATE_HZ * 1E6; 30 | } 31 | 32 | 33 | uint32_t cxa_timeBase_getMaxCount_us(void) 34 | { 35 | return UINT32_MAX; 36 | } 37 | 38 | 39 | // ******** local function implementations ******** 40 | -------------------------------------------------------------------------------- /src/arch-posix/cxa_posix_criticalSection.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_criticalSection.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | 21 | // ******** local function prototypes ******** 22 | 23 | 24 | // ******** local variable declarations ********* 25 | pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 26 | 27 | 28 | // ******** global function implementations ******** 29 | void cxa_criticalSection_enter(void) 30 | { 31 | pthread_mutex_lock( &mutex ); 32 | } 33 | 34 | 35 | void cxa_criticalSection_exit(void) 36 | { 37 | pthread_mutex_unlock( &mutex ); 38 | } 39 | 40 | 41 | // ******** local function implementations ******** 42 | -------------------------------------------------------------------------------- /src/arch-posix/cxa_posix_delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_delay.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | void cxa_delay_ms(uint16_t delay_msIn) 28 | { 29 | usleep(((uint32_t)delay_msIn) * 1000); 30 | } 31 | 32 | 33 | // ******** local function implementations ******** 34 | -------------------------------------------------------------------------------- /src/arch-posix/cxa_posix_timeBase.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef __MACH__ 16 | #include 17 | #include 18 | #endif 19 | 20 | 21 | // ******** local macro definitions ******** 22 | 23 | 24 | // ******** local type definitions ******** 25 | 26 | 27 | // ******** local function prototypes ******** 28 | static void current_utc_time(struct timeval *ts); 29 | 30 | 31 | // ******** local variable declarations ********* 32 | 33 | 34 | // ******** global function implementations ******** 35 | 36 | 37 | uint32_t cxa_timeBase_getCount_us(void) 38 | { 39 | struct timeval ts; 40 | current_utc_time(&ts); 41 | return (1000000 * ts.tv_sec) + (ts.tv_usec); 42 | } 43 | 44 | 45 | uint32_t cxa_timeBase_getMaxCount_us(void) 46 | { 47 | return UINT32_MAX; 48 | } 49 | 50 | 51 | // ******** local function implementations ******** 52 | static void current_utc_time(struct timeval *ts) 53 | { 54 | #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time 55 | clock_serv_t cclock; 56 | mach_timespec_t mts; 57 | host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); 58 | clock_get_time(cclock, &mts); 59 | mach_port_deallocate(mach_task_self(), cclock); 60 | ts->tv_sec = mts.tv_sec; 61 | ts->tv_usec = mts.tv_nsec / 1000; 62 | #else 63 | gettimeofday(ts, NULL); 64 | #endif 65 | } 66 | -------------------------------------------------------------------------------- /src/arch-tiC2K/cxa_tiC2K_criticalSection.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_criticalSection.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | 21 | // ******** local function prototypes ******** 22 | 23 | 24 | // ******** local variable declarations ********* 25 | 26 | 27 | 28 | // ******** global function implementations ******** 29 | void cxa_criticalSection_enter(void) 30 | { 31 | 32 | } 33 | 34 | 35 | void cxa_criticalSection_exit(void) 36 | { 37 | 38 | } 39 | 40 | 41 | // ******** local function implementations ******** 42 | 43 | -------------------------------------------------------------------------------- /src/arch-tiC2K/cxa_tiC2K_delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_delay.h" 8 | 9 | // ******** includes ******** 10 | #include 11 | 12 | // ******** local macro definitions ******** 13 | 14 | 15 | // ******** local type definitions ******** 16 | 17 | 18 | // ******** local function prototypes ******** 19 | 20 | 21 | // ******** local variable declarations ********* 22 | 23 | 24 | // ******** global function implementations ******** 25 | void cxa_delay_ms(uint16_t delay_msIn) 26 | { 27 | /* DEVICEDELAY macro is in microseconds, so multiply 28 | * requested microseconds by 1000 for microseconds. */ 29 | DEVICE_DELAY_US(((uint32_t)delay_msIn) * 1000); 30 | } 31 | 32 | 33 | // ******** local function implementations ******** 34 | -------------------------------------------------------------------------------- /src/arch-tiC2K/cxa_tiC2K_timeBase.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | void cxa_esp32_timeBase_init(void) 28 | { 29 | } 30 | 31 | 32 | uint32_t cxa_timeBase_getCount_us(void) 33 | { 34 | // return esp_timer_get_time() % UINT32_MAX; 35 | return 0; 36 | } 37 | 38 | 39 | uint32_t cxa_timeBase_getMaxCount_us(void) 40 | { 41 | return UINT32_MAX; 42 | } 43 | 44 | 45 | // ******** local function implementations ******** 46 | -------------------------------------------------------------------------------- /src/arch-tiC2K/cxa_tiC2K_uniqueId.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_uniqueId.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | //ESP32 13 | //#include 14 | //#include 15 | 16 | 17 | // ******** local macro definitions ******** 18 | 19 | 20 | // ******** local type definitions ******** 21 | 22 | 23 | // ******** local function prototypes ******** 24 | static void init(void); 25 | 26 | 27 | // ******** local variable declarations ********* 28 | static bool isInit = false; 29 | static uint8_t id_bytes[6]; 30 | static char id_str[18]; 31 | 32 | 33 | // ******** global function implementations ******** 34 | void cxa_uniqueId_getBytes(uint8_t** bytesOut, size_t* numBytesOut) 35 | { 36 | // if( !isInit ) init(); 37 | // 38 | // if( bytesOut ) *bytesOut = (uint8_t*)&id_bytes; 39 | // if( numBytesOut ) *numBytesOut = sizeof(id_bytes); 40 | //TODO: Need TIC2K Implementation 41 | } 42 | 43 | 44 | //char* cxa_uniqueId_getHexString(void) 45 | //{ 46 | // if( !isInit ) init(); 47 | // 48 | // return id_str; 49 | //} 50 | 51 | 52 | // ******** local function implementations ******** 53 | //static void init(void) 54 | //{ 55 | // if( esp_wifi_get_mac(WIFI_IF_STA, id_bytes) != ESP_OK ) 56 | // { 57 | // esp_eth_get_mac(id_bytes); 58 | // } 59 | // 60 | // sprintf(id_str, "%02X:%02X:%02X:%02X:%02X:%02X", id_bytes[0], id_bytes[1], id_bytes[2], id_bytes[3], id_bytes[4], id_bytes[5]); 61 | // id_str[sizeof(id_str)-1] = 0; 62 | // 63 | // isInit = true; 64 | //} 65 | -------------------------------------------------------------------------------- /src/arch-tiC2K/strtok.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * strtok_r (char *s, const char *delim, char **save_ptr) 5 | { 6 | char *end; 7 | 8 | if (s == NULL) 9 | s = *save_ptr; 10 | 11 | if (*s == '\0') 12 | { 13 | *save_ptr = s; 14 | return NULL; 15 | } 16 | 17 | /* Scan leading delimiters. */ 18 | s += strspn (s, delim); 19 | if (*s == '\0') 20 | { 21 | *save_ptr = s; 22 | return NULL; 23 | } 24 | 25 | /* Find the end of the token. */ 26 | end = s + strcspn (s, delim); 27 | if (*end == '\0') 28 | { 29 | *save_ptr = end; 30 | return s; 31 | } 32 | 33 | /* Terminate the token and make *SAVE_PTR point past it. */ 34 | *end = '\0'; 35 | *save_ptr = end + 1; 36 | return s; 37 | } 38 | -------------------------------------------------------------------------------- /src/arch-xmega/cxa_xmega_delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_delay.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | extern void __builtin_avr_delay_cycles(unsigned long); 22 | 23 | 24 | // ******** local variable declarations ********* 25 | 26 | 27 | // ******** global function implementations ******** 28 | void cxa_delay_ms(uint16_t delay_msIn) 29 | { 30 | uint32_t delay_ticks = (cxa_xmega_clockController_getSystemClockFrequency_hz() / 1000) * delay_msIn; 31 | 32 | while( delay_ticks >= 10000 ) 33 | { 34 | __builtin_avr_delay_cycles(10000); 35 | delay_ticks -= 10000; 36 | } 37 | while( delay_ticks >= 1000 ) 38 | { 39 | __builtin_avr_delay_cycles(1000); 40 | delay_ticks -= 1000; 41 | } 42 | while( delay_ticks >= 100 ) 43 | { 44 | __builtin_avr_delay_cycles(100); 45 | delay_ticks -= 100; 46 | } 47 | while( delay_ticks != 0 ) 48 | { 49 | __builtin_avr_delay_cycles(1); 50 | delay_ticks -= 1; 51 | } 52 | } 53 | 54 | 55 | // ******** local function implementations ******** 56 | -------------------------------------------------------------------------------- /src/arch-xmega/cxa_xmega_pmic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_xmega_pmic.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** local macro definitions ******** 18 | 19 | 20 | // ******** local type definitions ******** 21 | 22 | 23 | // ******** local function prototypes ******** 24 | 25 | 26 | // ******** local variable declarations ********* 27 | static bool isInitialized = false; 28 | 29 | 30 | // ******** global function implementations ******** 31 | void cxa_xmega_pmic_init(void) 32 | { 33 | cli(); 34 | PMIC.CTRL = 0; 35 | 36 | isInitialized = true; 37 | } 38 | 39 | 40 | bool cxa_xmega_pmic_hasBeenInitialized(void) 41 | { 42 | return isInitialized; 43 | } 44 | 45 | 46 | void cxa_xmega_pmic_enableInterruptLevel(const cxa_xmega_pmic_interruptLevel_t levelIn) 47 | { 48 | cxa_assert(isInitialized); 49 | 50 | switch( levelIn ) 51 | { 52 | case CXA_XMEGA_PMIC_INTLEVEL_LOW: 53 | PMIC.CTRL |= PMIC_LOLVLEX_bm; 54 | break; 55 | 56 | case CXA_XMEGA_PMIC_INTLEVEL_MED: 57 | PMIC.CTRL |= PMIC_MEDLVLEX_bm; 58 | break; 59 | 60 | case CXA_XMEGA_PMIC_INTLEVEL_HIGH: 61 | PMIC.CTRL |= PMIC_HILVLEX_bm; 62 | break; 63 | } 64 | } 65 | 66 | 67 | void cxa_xmega_pmic_enableGlobalInterrupts(void) 68 | { 69 | cxa_assert(isInitialized); 70 | sei(); 71 | } 72 | 73 | 74 | void cxa_xmega_pmic_disableGlobalInterrupts(void) 75 | { 76 | cxa_assert(isInitialized); 77 | cli(); 78 | } 79 | 80 | 81 | // ******** local function implementations ******** 82 | -------------------------------------------------------------------------------- /src/arch-xmega/cxa_xmega_timeBase.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_xmega_timeBase.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | static cxa_xmega_timer32_t* timer = NULL; 25 | 26 | 27 | // ******** global function implementations ******** 28 | void cxa_xmega_timeBase_init_timer32(cxa_xmega_timer32_t *const timerIn) 29 | { 30 | cxa_assert(timerIn); 31 | 32 | // save our references 33 | timer = timerIn; 34 | } 35 | 36 | 37 | uint32_t cxa_timeBase_getCount_us(void) 38 | { 39 | cxa_assert(timer); 40 | 41 | return cxa_xmega_timer32_getCount(timer) * (1000000 / cxa_xmega_timer32_getResolution_cntsPerS(timer)); 42 | } 43 | 44 | 45 | uint32_t cxa_timeBase_getMaxCount_us(void) 46 | { 47 | cxa_assert(timer); 48 | 49 | return cxa_xmega_timer32_getMaxVal_cnts(timer) * (1000000 / cxa_xmega_timer32_getResolution_cntsPerS(timer)); 50 | } 51 | 52 | 53 | // ******** local function implementations ******** 54 | -------------------------------------------------------------------------------- /src/misc/cxa_numberUtils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_numberUtils.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | uint16_t cxa_numberUtils_crc16_oneShot(void* dataIn, size_t dataLen_bytesIn) 28 | { 29 | uint16_t retVal = 0; 30 | 31 | for( size_t i = 0; i < dataLen_bytesIn; i++ ) 32 | { 33 | retVal = cxa_numberUtils_crc16_step(retVal, ((uint8_t*)dataIn)[i]); 34 | } 35 | 36 | return retVal; 37 | } 38 | 39 | 40 | uint16_t cxa_numberUtils_crc16_step(uint16_t crcIn, uint8_t byteIn) 41 | { 42 | crcIn ^= byteIn; 43 | for( uint8_t i = 0; i < 8; i++ ) 44 | { 45 | crcIn = (crcIn & 0x0001) ? ((crcIn >> 1) ^ 0xA001) : (crcIn >> 1); 46 | } 47 | return crcIn; 48 | } 49 | 50 | 51 | // ******** local function implementations ******** 52 | -------------------------------------------------------------------------------- /src/misc/cxa_profiler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_profiler.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | #define CXA_LOG_LEVEL CXA_LOG_LEVEL_DEBUG 15 | #include 16 | 17 | 18 | // ******** local macro definitions ******** 19 | 20 | 21 | // ******** local type definitions ******** 22 | 23 | 24 | // ******** local function prototypes ******** 25 | 26 | 27 | // ******** local variable declarations ********* 28 | 29 | 30 | // ******** global function implementations ******** 31 | void cxa_profiler_init(cxa_profiler_t *const profIn, const char *nameIn) 32 | { 33 | cxa_assert(profIn); 34 | 35 | cxa_logger_init_formattedString(&profIn->logger, "prof-%s", nameIn); 36 | } 37 | 38 | 39 | void cxa_profiler_step_impl(cxa_profiler_t *const profIn, const char* fileIn, const int lineNumIn) 40 | { 41 | cxa_assert(profIn); 42 | 43 | uint32_t currTime_us = cxa_timeBase_getCount_us(); 44 | 45 | // shorten our file name 46 | char *file_sep = strrchr(fileIn, '/'); 47 | if(file_sep) fileIn = file_sep+1; 48 | else{ 49 | file_sep = strrchr(fileIn, '\\'); 50 | if (file_sep) fileIn = file_sep+1; 51 | } 52 | cxa_logger_debug(&profIn->logger, "%s::%d - %.3fs", fileIn, lineNumIn, ((float)(currTime_us - profIn->lastTime_us)) / 1.0E6); 53 | 54 | profIn->lastTime_us = currTime_us; 55 | } 56 | 57 | 58 | // ******** local function implementations ******** 59 | -------------------------------------------------------------------------------- /src/mqtt/messages/cxa_mqtt_message_pingRequest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_mqtt_message_pingRequest.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | bool cxa_mqtt_message_pingRequest_init(cxa_mqtt_message_t *const msgIn) 28 | { 29 | cxa_assert(msgIn); 30 | 31 | // fixed header 1 32 | if( !cxa_linkedField_initRoot_fixedLen(&msgIn->field_packetTypeAndFlags, msgIn->buffer, 0, 1) || 33 | !cxa_linkedField_append_uint8(&msgIn->field_packetTypeAndFlags, (CXA_MQTT_MSGTYPE_PINGREQ << 4) ) ) return false; 34 | 35 | // remaining length 36 | if( !cxa_linkedField_initChild(&msgIn->field_remainingLength, &msgIn->field_packetTypeAndFlags, 0) ) return false; 37 | 38 | msgIn->areFieldsConfigured = true; 39 | return true; 40 | } 41 | 42 | 43 | bool cxa_mqtt_message_pingRequest_validateReceivedBytes(cxa_mqtt_message_t *const msgIn) 44 | { 45 | cxa_assert(msgIn); 46 | 47 | // @TODO should probably make sure there aren't any following bytes (per spec) 48 | 49 | return true; 50 | } 51 | 52 | 53 | // ******** local function implementations ******** 54 | -------------------------------------------------------------------------------- /src/mqtt/messages/cxa_mqtt_message_pingResponse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_mqtt_message_pingResponse.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | bool cxa_mqtt_message_pingResponse_init(cxa_mqtt_message_t *const msgIn) 28 | { 29 | cxa_assert(msgIn); 30 | 31 | // fixed header 1 32 | if( !cxa_linkedField_initRoot_fixedLen(&msgIn->field_packetTypeAndFlags, msgIn->buffer, 0, 1) || 33 | !cxa_linkedField_append_uint8(&msgIn->field_packetTypeAndFlags, (CXA_MQTT_MSGTYPE_PINGRESP << 4) ) ) return false; 34 | 35 | // remaining length 36 | if( !cxa_linkedField_initChild(&msgIn->field_remainingLength, &msgIn->field_packetTypeAndFlags, 0) ) return false; 37 | 38 | msgIn->areFieldsConfigured = true; 39 | return true; 40 | } 41 | 42 | 43 | bool cxa_mqtt_message_pingResponse_validateReceivedBytes(cxa_mqtt_message_t *const msgIn) 44 | { 45 | cxa_assert(msgIn); 46 | 47 | // @TODO should probably make sure there aren't any following bytes (per spec) 48 | 49 | return true; 50 | } 51 | 52 | 53 | // ******** local function implementations ******** 54 | -------------------------------------------------------------------------------- /src/mqtt/messages/cxa_mqtt_message_suback.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_mqtt_message_suback.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | #define CXA_LOG_LEVEL CXA_LOG_LEVEL_TRACE 14 | #include 15 | 16 | 17 | // ******** local macro definitions ******** 18 | 19 | 20 | // ******** local type definitions ******** 21 | 22 | 23 | // ******** local function prototypes ******** 24 | 25 | 26 | // ******** local variable declarations ********* 27 | 28 | 29 | // ******** global function implementations ******** 30 | bool cxa_mqtt_message_suback_getPacketId(cxa_mqtt_message_t *const msgIn, uint16_t *const packetIdOut) 31 | { 32 | cxa_assert(msgIn); 33 | 34 | if( !msgIn->areFieldsConfigured || (cxa_mqtt_message_getType(msgIn) != CXA_MQTT_MSGTYPE_SUBACK) ) return false; 35 | 36 | uint16_t packetId_lcl; 37 | if( !cxa_linkedField_get_uint16BE(&msgIn->fields_suback.field_packetId, 0, packetId_lcl) ) return false; 38 | 39 | if( packetIdOut != NULL ) *packetIdOut = packetId_lcl; 40 | 41 | return true; 42 | } 43 | 44 | 45 | bool cxa_mqtt_message_suback_getReturnCode(cxa_mqtt_message_t *const msgIn, cxa_mqtt_subAck_returnCode_t *const returnCodeOut) 46 | { 47 | cxa_assert(msgIn); 48 | 49 | if( !msgIn->areFieldsConfigured || (cxa_mqtt_message_getType(msgIn) != CXA_MQTT_MSGTYPE_SUBACK) ) return false; 50 | 51 | uint8_t returnCode_lcl; 52 | if( !cxa_linkedField_get_uint8(&msgIn->fields_suback.field_returnCode, 0, returnCode_lcl) ) return false; 53 | 54 | if( returnCodeOut != NULL ) *returnCodeOut = (cxa_mqtt_subAck_returnCode_t)returnCode_lcl; 55 | 56 | return true; 57 | } 58 | 59 | 60 | bool cxa_mqtt_message_suback_validateReceivedBytes(cxa_mqtt_message_t *const msgIn) 61 | { 62 | cxa_assert(msgIn); 63 | 64 | // packet id 65 | if( !cxa_linkedField_initChild_fixedLen(&msgIn->fields_suback.field_packetId, &msgIn->field_remainingLength, 2) ) return false; 66 | 67 | // return code 68 | if( !cxa_linkedField_initChild_fixedLen(&msgIn->fields_suback.field_returnCode, &msgIn->fields_suback.field_packetId, 1) ) return false; 69 | 70 | return true; 71 | } 72 | 73 | 74 | // ******** local function implementations ******** 75 | -------------------------------------------------------------------------------- /src/rpc/cxa_rpc_messageHandler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_rpc_messageHandler.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | #include 14 | 15 | #define CXA_LOG_LEVEL CXA_LOG_LEVEL_TRACE 16 | #include 17 | 18 | 19 | // ******** local macro definitions ******** 20 | 21 | 22 | // ******** local type definitions ******** 23 | 24 | 25 | // ******** local function prototypes ******** 26 | 27 | 28 | // ******** local variable declarations ********* 29 | 30 | 31 | // ******** global function implementations ******** 32 | void cxa_rpc_messageHandler_init(cxa_rpc_messageHandler_t *const handlerIn, cxa_rpc_messageHandler_cb_handleUpstream_t cb_upstreamIn, cxa_rpc_messageHandler_cb_handleDownstream_t cb_downstreamIn) 33 | { 34 | cxa_assert(handlerIn); 35 | cxa_assert(cb_upstreamIn); 36 | cxa_assert(cb_downstreamIn); 37 | 38 | // save our internal state 39 | handlerIn->cb_upstream = cb_upstreamIn; 40 | handlerIn->cb_downstream = cb_downstreamIn; 41 | handlerIn->parent = NULL; 42 | } 43 | 44 | 45 | // ******** local function implementations ******** 46 | -------------------------------------------------------------------------------- /src/runLoop/cxa_oneShotTimer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_oneShotTimer.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | 15 | // ******** local macro definitions ******** 16 | 17 | 18 | // ******** local type definitions ******** 19 | 20 | 21 | // ******** local function prototypes ******** 22 | static void cb_onRunLoopUpdate(void* userVarIn); 23 | 24 | 25 | // ******** local variable declarations ********* 26 | 27 | 28 | // ******** global function implementations ******** 29 | void cxa_oneShotTimer_init(cxa_oneShotTimer_t *const ostIn, int threadIdIn) 30 | { 31 | cxa_assert(ostIn); 32 | 33 | // set our initial state 34 | ostIn->isActive = false; 35 | cxa_timeDiff_init(&ostIn->timeDiff); 36 | 37 | // register for runLoop updates 38 | cxa_runLoop_addEntry(threadIdIn, NULL, cb_onRunLoopUpdate, (void*)ostIn); 39 | } 40 | 41 | 42 | void cxa_oneShotTimer_schedule(cxa_oneShotTimer_t *const ostIn, uint32_t delay_msIn, cxa_oneShotTimer_cb_t cbIn, void *const userVarIn) 43 | { 44 | cxa_assert(ostIn); 45 | 46 | ostIn->isActive = false; 47 | 48 | ostIn->delay_ms = delay_msIn; 49 | ostIn->cb = cbIn; 50 | ostIn->userVar = userVarIn; 51 | cxa_timeDiff_setStartTime_now(&ostIn->timeDiff); 52 | 53 | ostIn->isActive = true; 54 | } 55 | 56 | 57 | // ******** local function implementations ******** 58 | static void cb_onRunLoopUpdate(void* userVarIn) 59 | { 60 | cxa_oneShotTimer_t* ostIn = (cxa_oneShotTimer_t*)userVarIn; 61 | cxa_assert(ostIn); 62 | 63 | if( ostIn->isActive && cxa_timeDiff_isElapsed_ms(&ostIn->timeDiff, ostIn->delay_ms) ) 64 | { 65 | ostIn->isActive = false; 66 | if( ostIn->cb != NULL ) ostIn->cb(ostIn->userVar); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/runLoop/cxa_softWatchDog.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_softWatchDog.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | #define CXA_LOG_LEVEL CXA_LOG_LEVEL_TRACE 15 | #include 16 | 17 | 18 | // ******** local macro definitions ******** 19 | 20 | 21 | // ******** local type definitions ******** 22 | 23 | 24 | // ******** local function prototypes ******** 25 | static void cb_onRunLoopUpdate(void* userVarIn); 26 | 27 | 28 | // ******** local variable declarations ********* 29 | 30 | 31 | // ******** global function implementations ******** 32 | void cxa_softWatchDog_init(cxa_softWatchDog_t *const swdIn, uint32_t timeoutPeriod_msIn, int threadIdIn, 33 | cxa_softWatchDog_cb_t cbIn, void *const userVarIn) 34 | { 35 | cxa_assert(swdIn); 36 | cxa_assert(cbIn); 37 | 38 | // save our references 39 | swdIn->isPaused = true; 40 | swdIn->cb = cbIn; 41 | swdIn->userVar = userVarIn; 42 | swdIn->timeoutPeriod_ms = timeoutPeriod_msIn; 43 | cxa_timeDiff_init(&swdIn->td_timeout); 44 | 45 | // register for our runloop 46 | cxa_runLoop_addEntry(threadIdIn, NULL, cb_onRunLoopUpdate, (void*)swdIn); 47 | } 48 | 49 | 50 | void cxa_softWatchDog_kick(cxa_softWatchDog_t *const swdIn) 51 | { 52 | cxa_assert(swdIn); 53 | 54 | cxa_timeDiff_setStartTime_now(&swdIn->td_timeout); 55 | swdIn->isPaused = false; 56 | } 57 | 58 | 59 | void cxa_softWatchDog_pause(cxa_softWatchDog_t *const swdIn) 60 | { 61 | cxa_assert(swdIn); 62 | 63 | swdIn->isPaused = true; 64 | } 65 | 66 | 67 | bool cxa_softWatchDog_isPaused(cxa_softWatchDog_t *const swdIn) 68 | { 69 | cxa_assert(swdIn); 70 | 71 | return swdIn->isPaused; 72 | } 73 | 74 | 75 | // ******** local function implementations ******** 76 | static void cb_onRunLoopUpdate(void* userVarIn) 77 | { 78 | cxa_softWatchDog_t* swdIn = (cxa_softWatchDog_t*)userVarIn; 79 | cxa_assert(swdIn); 80 | 81 | if( !swdIn->isPaused && cxa_timeDiff_isElapsed_ms(&swdIn->td_timeout, swdIn->timeoutPeriod_ms) ) 82 | { 83 | // watchdog expired...call our callback once and only once 84 | if( swdIn->cb != NULL) swdIn->cb(swdIn->userVar); 85 | swdIn->isPaused = true; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/serial/cxa_ioStream_bridge.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_ioStream_bridge.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | 14 | 15 | // ******** local macro definitions ******** 16 | 17 | 18 | // ******** local type definitions ******** 19 | 20 | 21 | // ******** local function prototypes ******** 22 | static void cb_onRunLoopUpdate(void* userVarIn); 23 | 24 | 25 | // ******** local variable declarations ********* 26 | 27 | 28 | // ******** global function implementations ******** 29 | void cxa_ioStream_bridge_init(cxa_ioStream_bridge_t *const bridgeIn, 30 | cxa_ioStream_t *const stream1In, 31 | cxa_ioStream_t *const stream2In, 32 | int threadIdIn) 33 | { 34 | cxa_assert(bridgeIn); 35 | cxa_assert(stream1In); 36 | cxa_assert(stream2In); 37 | 38 | // save our references 39 | bridgeIn->stream1 = stream1In; 40 | bridgeIn->stream2 = stream2In; 41 | 42 | // register for run loop execution 43 | cxa_runLoop_addEntry(threadIdIn, NULL, cb_onRunLoopUpdate, (void*)bridgeIn); 44 | } 45 | 46 | 47 | // ******** local function implementations ******** 48 | static void cb_onRunLoopUpdate(void* userVarIn) 49 | { 50 | cxa_ioStream_bridge_t* bridgeIn = (cxa_ioStream_bridge_t*)userVarIn; 51 | 52 | uint8_t rxByte; 53 | if( cxa_ioStream_readByte(bridgeIn->stream1, &rxByte) == CXA_IOSTREAM_READSTAT_GOTDATA ) 54 | { 55 | cxa_ioStream_writeByte(bridgeIn->stream2, rxByte); 56 | } 57 | 58 | if( cxa_ioStream_readByte(bridgeIn->stream2, &rxByte) == CXA_IOSTREAM_READSTAT_GOTDATA ) 59 | { 60 | cxa_ioStream_writeByte(bridgeIn->stream1, rxByte); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/serial/cxa_ioStream_loopback.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_ioStream_loopback.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | // ******** local macro definitions ******** 18 | 19 | 20 | // ******** local type definitions ******** 21 | 22 | 23 | // ******** local function prototypes ******** 24 | static cxa_ioStream_readStatus_t read_cb(uint8_t *const byteOut, void *const userVarIn); 25 | static bool write_cb(void* buffIn, size_t bufferSize_bytesIn, void *const userVarIn); 26 | 27 | 28 | // ******** local variable declarations ********* 29 | 30 | 31 | // ******** global function implementations ******** 32 | void cxa_ioStream_loopback_init(cxa_ioStream_loopback_t *const ioStreamIn) 33 | { 34 | cxa_assert(ioStreamIn); 35 | 36 | // initialize our fifo 37 | cxa_fixedFifo_initStd(&ioStreamIn->fifo, CXA_FF_ON_FULL_DROP, ioStreamIn->fifo_raw); 38 | 39 | // initialize our super class 40 | cxa_ioStream_init(&ioStreamIn->super); 41 | cxa_ioStream_bind(&ioStreamIn->super, read_cb, write_cb, (void*)ioStreamIn); 42 | } 43 | 44 | 45 | // ******** local function implementations ******** 46 | static cxa_ioStream_readStatus_t read_cb(uint8_t *const byteOut, void *const userVarIn) 47 | { 48 | cxa_assert(userVarIn); 49 | cxa_ioStream_loopback_t* ioStreamIn = (cxa_ioStream_loopback_t*)userVarIn; 50 | 51 | return cxa_fixedFifo_dequeue(&ioStreamIn->fifo, byteOut) ? CXA_IOSTREAM_READSTAT_GOTDATA : CXA_IOSTREAM_READSTAT_NODATA; 52 | } 53 | 54 | 55 | static bool write_cb(void* buffIn, size_t bufferSize_bytesIn, void *const userVarIn) 56 | { 57 | cxa_assert(userVarIn); 58 | cxa_ioStream_loopback_t* ioStreamIn = (cxa_ioStream_loopback_t*)userVarIn; 59 | if( buffIn == NULL ) return false; 60 | 61 | for( size_t i = 0; i < bufferSize_bytesIn; i++ ) 62 | { 63 | if( !cxa_fixedFifo_queue(&ioStreamIn->fifo, (void*)&(((uint8_t*)buffIn)[i])) ) return false; 64 | } 65 | 66 | return true; 67 | } 68 | -------------------------------------------------------------------------------- /src/timeUtils/cxa_timeDiff.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is subject to the terms and conditions defined in 3 | * file 'LICENSE', which is part of this source code package. 4 | * 5 | * @author Christopher Armenio 6 | */ 7 | #include "cxa_timeDiff.h" 8 | 9 | 10 | // ******** includes ******** 11 | #include 12 | 13 | 14 | // ******** local macro definitions ******** 15 | 16 | 17 | // ******** local type definitions ******** 18 | 19 | 20 | // ******** local function prototypes ******** 21 | 22 | 23 | // ******** local variable declarations ********* 24 | 25 | 26 | // ******** global function implementations ******** 27 | void cxa_timeDiff_init(cxa_timeDiff_t *const tdIn) 28 | { 29 | cxa_assert(tdIn); 30 | 31 | cxa_timeDiff_setStartTime_now(tdIn); 32 | } 33 | 34 | 35 | void cxa_timeDiff_setStartTime_now(cxa_timeDiff_t *const tdIn) 36 | { 37 | cxa_assert(tdIn); 38 | 39 | tdIn->startTime_us = cxa_timeBase_getCount_us(); 40 | } 41 | 42 | 43 | uint32_t cxa_timeDiff_getElapsedTime_ms(cxa_timeDiff_t *const tdIn) 44 | { 45 | cxa_assert(tdIn); 46 | 47 | uint32_t curr_us = cxa_timeBase_getCount_us(); 48 | uint32_t elapsedTime_us = (curr_us >= tdIn->startTime_us) ? 49 | (curr_us - tdIn->startTime_us) : 50 | ((cxa_timeBase_getMaxCount_us() - tdIn->startTime_us) + curr_us); 51 | return elapsedTime_us / 1000; 52 | } 53 | 54 | 55 | bool cxa_timeDiff_isElapsed_ms(cxa_timeDiff_t *const tdIn, uint32_t msIn) 56 | { 57 | cxa_assert(tdIn); 58 | 59 | return (cxa_timeDiff_getElapsedTime_ms(tdIn) >= msIn); 60 | } 61 | 62 | 63 | bool cxa_timeDiff_isElapsed_recurring_ms(cxa_timeDiff_t *const tdIn, uint32_t msIn) 64 | { 65 | cxa_assert(tdIn); 66 | 67 | bool retVal = cxa_timeDiff_isElapsed_ms(tdIn, msIn); 68 | if( retVal ) cxa_timeDiff_setStartTime_now(tdIn); 69 | 70 | return retVal; 71 | } 72 | 73 | 74 | // ******** local function implementations ******** 75 | --------------------------------------------------------------------------------