Commit 3ce341a6 authored by Rafal Babski's avatar Rafal Babski
Browse files

Merge branch 'demo-sat-dev' into 'master'

Demo sat dev

See merge request msp/demo-sat!2
parents b523d9b5 e65a6d21
demo-sat/.cache/
# Ignore whole work directory
demo-sat/work/*
# Except HAL source files
!demo-sat/work/hal
demo-sat/work/hal/*
!demo-sat/work/hal/C
demo-sat/work/hal/C/*
!demo-sat/work/hal/C/src
demo-sat/work/hal/C/src/*
!demo-sat/work/hal/C/src/hal.c
# Except ThermalManager
!demo-sat/work/thermalmanager/
demo-sat/work/thermalmanager/*
!demo-sat/work/thermalmanager/SDL
demo-sat/work/thermalmanager/SDL/*
!demo-sat/work/thermalmanager/SDL/src
demo-sat/work/thermalmanager/SDL/src/*
!demo-sat/work/thermalmanager/SDL/src/thermalmanager.pr
# Except PayloadManager
!demo-sat/work/payloadmanager/
demo-sat/work/payloadmanager/*
!demo-sat/work/payloadmanager/SDL
demo-sat/work/payloadmanager/SDL/*
!demo-sat/work/payloadmanager/SDL/src
demo-sat/work/payloadmanager/SDL/src/*
!demo-sat/work/payloadmanager/SDL/src/payloadmanager.pr
# Except ModeManager
!demo-sat/work/modemanager/
demo-sat/work/modemanager/*
!demo-sat/work/modemanager/SDL
demo-sat/work/modemanager/SDL/*
!demo-sat/work/modemanager/SDL/src
demo-sat/work/modemanager/SDL/src/*
!demo-sat/work/modemanager/SDL/src/modemanager.pr
# Except Housekeeping
!demo-sat/work/housekeeping/
demo-sat/work/housekeeping/*
!demo-sat/work/housekeeping/SDL
demo-sat/work/housekeeping/SDL/*
!demo-sat/work/housekeeping/SDL/src
demo-sat/work/housekeeping/SDL/src/*
!demo-sat/work/housekeeping/SDL/src/housekeeping.pr
# Except CommandDispatcher
!demo-sat/work/commanddispatcher/
demo-sat/work/commanddispatcher/*
!demo-sat/work/commanddispatcher/SDL
demo-sat/work/commanddispatcher/SDL/*
!demo-sat/work/commanddispatcher/SDL/src
demo-sat/work/commanddispatcher/SDL/src/*
!demo-sat/work/commanddispatcher/SDL/src/commanddispatcher.pr
# DemoSat project
## Compilation from commandline
## Oscillators and clocks configuration
### Oscillators
| Oscillator | Frequency |
|------------|-----------|
| DCO | 8 MHz |
| LFXTCLK | 32768 Hz |
### Clocks
| Clock | Source Oscillator | Divider |
|-------|-------------------|---------|
| MCLK | DCO | 1 |
| SMCLK | DCO | 1 |
| ACLK | LFXTCLK | 1 |
### Modules
| Module | Clock | Divider | Description |
|---------------------|-------|--------------------------|-------------------------------------------|
| FreeRTOS tick timer | ACLK | 1000 | FreeRTOS uses this clock for system ticks |
| UART | SMCLK | depends on configuration | |
| I2C | SMCLK | 160 | Standard 100kHz |
| PWM | SMCLK | 8 * 4 | Period 1000 |
## PIN configuration
| Pins | Function | Connection with |
|------|----------|--------------------------------------------|
| P1.3 | ADC | Output of voltage divider near solar panel |
| P1.4 | PWM | pin IN A on BD65496MUV |
| P1.5 | GPIO | pin RES on SDD1306 |
| P1.6 | SDA | pin DIN on SDD1306 and pin SDA on MCP9808 |
| P1.7 | SCL | pin CLK on SDD1306 and pin SCL on MCP9808 |
| P2.0 | UART | - |
| P2.1 | UART | - |
|------|----------|--------------------------------------------|
| GND | Ground | |
| VCC | +3.3V | |
PACKAGE Process_Package_proxy
PUBLIC
WITH Process_Package;
WITH AI;
SYSTEM DeploymentView
EXTENDS Process_Package::DeploymentView
END DeploymentView;
SYSTEM IMPLEMENTATION DeploymentView.final
EXTENDS Process_Package::DeploymentView.final
PROPERTIES
AI::root_system => "SELECTED";
Stack_Size => 1024 bytes APPLIES TO Msp430fr5969_Partition.commanddispatcher_command;
Stack_Size => 512 bytes APPLIES TO Msp430fr5969_Partition.housekeeping_trigger_gather_hk;
Stack_Size => 768 bytes APPLIES TO Msp430fr5969_Partition.modemanager_trigger_gather_mode_hk;
Stack_Size => 512 bytes APPLIES TO Msp430fr5969_Partition.payloadmanager_trigger_gather_payload_hk;
Stack_Size => 512 bytes APPLIES TO Msp430fr5969_Partition.thermalmanager_trigger_check_temp;
END DeploymentView.final;
END Process_Package_proxy;
This diff is collapsed.
TASTE-Dataview DEFINITIONS ::=
BEGIN
IMPORTS T-Int32, T-UInt32, T-Int8, T-UInt8, T-Boolean FROM TASTE-BasicTypes;
END
---------------------------------------------------
-- AADL2.2
-- TASTE type deploymentview
--
-- generated code: do not edit
---------------------------------------------------
PACKAGE deploymentview::DV::EGSE
PUBLIC
WITH ocarina_buses;
WITH ocarina_drivers;
WITH Taste;
WITH Deployment;
WITH TASTE_DV_Properties;
WITH deploymentview::DV;
WITH Memory_Properties;
WITH ARINC653;
PROCESS x86_partition
END x86_partition;
PROCESS IMPLEMENTATION x86_partition.others
END x86_partition.others;
DEVICE linux_serial_minimal
EXTENDS ocarina_drivers::linux_serial
FEATURES
link : REFINED TO REQUIRES BUS ACCESS ocarina_buses::serial.minimal {
Taste::coordinates => "275111 132281";
};
PROPERTIES
Taste::Interface_Coordinates => "238419 168972" APPLIES TO link;
Deployment::Help => "Write your ASN.1 configuration here";
Deployment::Configuration => "{ devname ""/dev/ttyACM1"", speed b19200, bits 8}";
Deployment::Config => "/home/taste/tool-inst/include/ocarina/runtime/polyorb-hi-c/src/drivers/configuration/serial.asn";
Deployment::Version => "0.1beta";
END linux_serial_minimal;
DEVICE IMPLEMENTATION linux_serial_minimal.others
EXTENDS ocarina_drivers::linux_serial.minimal
END linux_serial_minimal.others;
END deploymentview::DV::EGSE;
PACKAGE deploymentview::DV::CubeSat
PUBLIC
WITH ocarina_buses;
WITH ocarina_drivers;
WITH Taste;
WITH Deployment;
WITH TASTE_DV_Properties;
WITH deploymentview::DV;
WITH Memory_Properties;
WITH ARINC653;
PROCESS msp430fr5969_partition
END msp430fr5969_partition;
PROCESS IMPLEMENTATION msp430fr5969_partition.others
END msp430fr5969_partition.others;
DEVICE MSP430_eUSCI_A_serial_minimal
EXTENDS ocarina_drivers::MSP430_eUSCI_A_serial
FEATURES
link : REFINED TO REQUIRES BUS ACCESS ocarina_buses::serial.minimal {
Taste::coordinates => "101572 131807";
};
PROPERTIES
Taste::Interface_Coordinates => "113698 168815" APPLIES TO link;
Deployment::Help => "Write your ASN.1 configuration here";
Deployment::Configuration => "{ devname """", speed b19200, bits 8}";
Deployment::Config => "/home/taste/tool-inst/include/ocarina/runtime/polyorb-hi-c/src/drivers/configuration/serial.asn";
Deployment::Version => "0.1beta";
END MSP430_eUSCI_A_serial_minimal;
DEVICE IMPLEMENTATION MSP430_eUSCI_A_serial_minimal.others
EXTENDS ocarina_drivers::MSP430_eUSCI_A_serial.minimal
END MSP430_eUSCI_A_serial_minimal.others;
END deploymentview::DV::CubeSat;
PACKAGE deploymentview::DV
PUBLIC
WITH interfaceview::IV::MissionControl;
WITH ocarina_processors_x86;
WITH deploymentview::DV::EGSE;
WITH interfaceview::IV::CommandDispatcher;
WITH interfaceview::IV::Housekeeping;
WITH interfaceview::IV::ModeManager;
WITH interfaceview::IV::ThermalManager;
WITH interfaceview::IV::PayloadManager;
WITH interfaceview::IV::HAL;
WITH ocarina_processors_msp430;
WITH deploymentview::DV::CubeSat;
WITH ocarina_buses;
WITH Taste;
WITH Deployment;
WITH interfaceview::IV;
WITH TASTE_DV_Properties;
SYSTEM EGSE
FEATURES
linux_serial_minimal_serial_minimal : REQUIRES BUS ACCESS ocarina_buses::serial.minimal;
END EGSE;
SYSTEM IMPLEMENTATION EGSE.others
SUBCOMPONENTS
IV_MissionControl : SYSTEM interfaceview::IV::MissionControl::MissionControl.others {
Taste::FunctionName => "MissionControl";
};
x86_partition : PROCESS deploymentview::DV::EGSE::x86_partition.others {
Taste::coordinates => "232979 71949 278031 109142";
Deployment::Port_Number => 0;
};
x86_linux : PROCESSOR ocarina_processors_x86::x86.linux {
Taste::coordinates => "227348 61322 283662 114455";
};
linux_serial_minimal : DEVICE deploymentview::DV::EGSE::linux_serial_minimal.others {
Taste::coordinates => "231647 118895 278103 132281";
};
CONNECTIONS
linux_serial_minimal_serial_minimal_link : BUS ACCESS linux_serial_minimal_serial_minimal -> linux_serial_minimal.link;
PROPERTIES
Taste::APLC_Binding => (reference (x86_partition)) APPLIES TO IV_MissionControl;
Actual_Processor_Binding => (reference (x86_linux)) APPLIES TO x86_partition;
Actual_Processor_Binding => (reference (x86_linux)) APPLIES TO linux_serial_minimal;
END EGSE.others;
SYSTEM CubeSat
FEATURES
MSP430_eUSCI_A_serial_minimal_serial_minimal : REQUIRES BUS ACCESS ocarina_buses::serial.minimal;
END CubeSat;
SYSTEM IMPLEMENTATION CubeSat.others
SUBCOMPONENTS
IV_CommandDispatcher : SYSTEM interfaceview::IV::CommandDispatcher::CommandDispatcher.others {
Taste::FunctionName => "CommandDispatcher";
};
IV_Housekeeping : SYSTEM interfaceview::IV::Housekeeping::Housekeeping.others {
Taste::FunctionName => "Housekeeping";
};
IV_ModeManager : SYSTEM interfaceview::IV::ModeManager::ModeManager.others {
Taste::FunctionName => "ModeManager";
};
IV_ThermalManager : SYSTEM interfaceview::IV::ThermalManager::ThermalManager.others {
Taste::FunctionName => "ThermalManager";
};
IV_PayloadManager : SYSTEM interfaceview::IV::PayloadManager::PayloadManager.others {
Taste::FunctionName => "PayloadManager";
};
IV_HAL : SYSTEM interfaceview::IV::HAL::HAL.others {
Taste::FunctionName => "HAL";
};
msp430fr5969_partition : PROCESS deploymentview::DV::CubeSat::msp430fr5969_partition.others {
Taste::coordinates => "89853 61941 129918 96375";
Deployment::Port_Number => 0;
};
msp430fr5969_freertos : PROCESSOR ocarina_processors_msp430::msp430fr5969.freertos {
Taste::coordinates => "87258 52471 181255 115272";
};
MSP430_eUSCI_A_serial_minimal : DEVICE deploymentview::DV::CubeSat::MSP430_eUSCI_A_serial_minimal.others {
Taste::coordinates => "98108 119366 140627 131807";
};
CONNECTIONS
MSP430_eUSCI_A_serial_minimal_serial_minimal_link : BUS ACCESS MSP430_eUSCI_A_serial_minimal_serial_minimal -> MSP430_eUSCI_A_serial_minimal.link;
PROPERTIES
Taste::APLC_Binding => (reference (msp430fr5969_partition)) APPLIES TO IV_CommandDispatcher;
Taste::APLC_Binding => (reference (msp430fr5969_partition)) APPLIES TO IV_Housekeeping;
Taste::APLC_Binding => (reference (msp430fr5969_partition)) APPLIES TO IV_ModeManager;
Taste::APLC_Binding => (reference (msp430fr5969_partition)) APPLIES TO IV_ThermalManager;
Taste::APLC_Binding => (reference (msp430fr5969_partition)) APPLIES TO IV_PayloadManager;
Taste::APLC_Binding => (reference (msp430fr5969_partition)) APPLIES TO IV_HAL;
Actual_Processor_Binding => (reference (msp430fr5969_freertos)) APPLIES TO msp430fr5969_partition;
Actual_Processor_Binding => (reference (msp430fr5969_freertos)) APPLIES TO MSP430_eUSCI_A_serial_minimal;
END CubeSat.others;
SYSTEM deploymentview
END deploymentview;
SYSTEM IMPLEMENTATION deploymentview.others
SUBCOMPONENTS
EGSE : SYSTEM EGSE.others {
Taste::coordinates => "220309 46141 290701 138580";
};
CubeSat : SYSTEM CubeSat.others {
Taste::coordinates => "83620 46140 191334 139366";
};
serial_minimal : BUS ocarina_buses::serial.minimal {
Taste::coordinates => "113698 157477 238419 180310";
};
interfaceview : SYSTEM interfaceview::IV::interfaceview.others;
CONNECTIONS
LinkToCubeSat : BUS ACCESS serial_minimal -> EGSE.linux_serial_minimal_serial_minimal {
Taste::coordinates => "275111 132281 275111 168972 238419 168972";
};
LinkToEGSE : BUS ACCESS serial_minimal -> CubeSat.MSP430_eUSCI_A_serial_minimal_serial_minimal {
Taste::coordinates => "101572 131807 101572 168815 113698 168815";
};
PROPERTIES
Actual_Connection_Binding => (reference (serial_minimal)) APPLIES TO interfaceview.CommandDispatcher_RI_report_MissionControl_PI_report;
Actual_Connection_Binding => (reference (serial_minimal)) APPLIES TO interfaceview.Housekeeping_RI_housekeeping_data_MissionControl_PI_housekeeping_data;
Actual_Connection_Binding => (reference (serial_minimal)) APPLIES TO interfaceview.MissionControl_RI_command_CommandDispatcher_PI_command;
END deploymentview.others;
PROPERTIES
Taste::coordinates => "0 0 297000 210000";
Taste::version => "2.4";
Taste::interfaceView => "InterfaceView.aadl";
Taste::HWLibraries => ("/home/taste/tool-inst/share/ocarina/AADLv2/ocarina_components.aadl");
END deploymentview::DV;
This diff is collapsed.
KAZOO?=kazoo
# Here you can specify folders containing external code you want to
# compile and link for a specific partition.
# Use upper case for the partition name:
# export <PARTITION_NAME>_EXTERNAL_SOURCE_PATH=/absolute/path/1:/....
export MSP430FR5969_PARTITION_EXTERNAL_SOURCE_PATH=/home/taste/projects/demo-sat/demo-sat/libs
all: c
c: work/glue_built
$(MAKE) -C work
skeletons:
$(MAKE) work/skeletons_built
work/skeletons_built: InterfaceView.aadl DataView.aadl
$(KAZOO) --gw -o work
$(MAKE) -C work dataview
touch $@
work/glue_built: InterfaceView.aadl DeploymentView.aadl DataView.aadl
$(KAZOO) -p --glue --gw -o work
touch $@
clean:
rm -rf work/build
rm -f work/glue_built work/skeletons_built
find work -type d -name "wrappers" -exec rm -rf {} +
find work -type d -name "*_GUI" -exec rm -rf {} +
.PHONY: clean skeletons c
--indent-switches
--break-blocks
--pad-oper
--unpad-paren
--add-brackets
--indent=spaces=4
-A1
--formatted
\ No newline at end of file
#!/bin/bash
FILES=(work/hal/C/src/hal.c \
libs/msp430_i2c.h \
libs/msp430_i2c.c \
libs/msp430_adc.h \
libs/msp430_adc.c \
libs/msp430_pwm.h \
libs/msp430_pwm.c \
libs/payload_font.h \
libs/payload_font.c \
libs/oled_sdd1306_driver.h \
libs/oled_sdd1306_driver.c \
libs/mcp9808_driver.h \
libs/mcp9808_driver.c \
)
for file in ${FILES[*]}
do
echo "Formatting $file"
astyle --options=astylerc -n "$file"
done
#include "mcp9808_driver.h"
#include "msp430_i2c.h"
#define THERMOMETER_ADDRESS (0x18)
#define THERMOMETER_REGISTER_RFU (0x00)
#define THERMOMETER_REGISTER_CONFIG (0x01)
#define THERMOMETER_REGISTER_ALERT_UPPER (0x02)
#define THERMOMETER_REGISTER_ALERT_LOWER (0x03)
#define THERMOMETER_REGISTER_CRITICAL_TEMP (0x04)
#define THERMOMETER_REGISTER_TEMPERATURE (0x05)
#define THERMOMETER_REGISTER_MANUFACTURER_ID (0x06)
#define THERMOMETER_REGISTER_DEVICE_ID (0x07)
#define THERMOMETER_REGISTER_RESOLUTION (0x08)
/**
* Mask to access data bits from temperature register.
*
* MCP9808 offers 12 bits of data.
*/
#define THERMOMETER_DATA_MASK 0x0fff
/**
* Mask to access sign bit from temperature register.
*/
#define THERMOMETER_SIGN_MASK 0x1000
/**
* Cofficient used to convert value from temperature register to decimal value.
*
* Thermometer resolution is 0.0625 (power-up default)
*/
#define THERMOMETER_RESOLUTION 16.0
float msp9808_get_temperature(void)
{
// read temperature value register using I2C
uint8_t data[2];
msp430_i2c_read_data(THERMOMETER_ADDRESS, THERMOMETER_REGISTER_TEMPERATURE, data, 2);
// revert bytes of returned value
uint16_t value = (data[0] << 8) + data[1];
// convert to decimal value
// see MCP9808 datasheet for more details about conversion
float temp = 0.0;
if(value & THERMOMETER_SIGN_MASK)
{
// use conversion for negative temperature
temp = 256.0 - (value & THERMOMETER_DATA_MASK) / THERMOMETER_RESOLUTION;
}
else
{
// use conversion for positive temperature
temp = (value & THERMOMETER_DATA_MASK) / THERMOMETER_RESOLUTION;
}
return temp;
}
#ifndef MCP9808_DRIVER_H
#define MCP9808_DRIVER_H
/**
* Get current temperature using MCP9808 thermometer.
*
* @returns Current temperature in Celsius degree.
*/
float msp9808_get_temperature(void);
#endif
#include "msp430_adc.h"
#include <stdint.h>
#include <msp430.h>
#include <FreeRTOS.h>
#include <semphr.h>
/**
* Value used to scale ADC conversion result.
*
* THe value is based on voltage divider used to measure voltage on solar panel.
*/
#define VOLTAGE_DIVIDER_RATIO 3.3
/**
* Reference voltage value used by ADC.
*/
#define REFERENCE_VOLTAGE 2.5
/**
* Precission of MSP430 ADC converter.
*/
#define ADC_PRECISSION_BITS 12
/**
* The internal state of ADC module.
*/
struct MSP430_ADCState
{
/**
* Semaphore used to synchronize function call with ADC interrupt.
*/
SemaphoreHandle_t semaphore;
/**
* Buffer used to static allocation of semaphore.
*/
StaticSemaphore_t semaphore_buffer;
/**
* The value to return result of ADC conversion from ADC interrupt.
*/
volatile uint16_t voltage_raw_value;
};
static __attribute__((persistent))
struct MSP430_ADCState msp430_adc_state = {0};
void setup_adc(void)
{
// Create semaphore
msp430_adc_state.semaphore = xSemaphoreCreateBinaryStatic(&msp430_adc_state.semaphore_buffer);
// Configure P1.3 for ADC
// P1.3 is A3 ADC channel
P1SEL1 |= BIT3;
P1SEL0 |= BIT3;
// By default, REFMSTR=1 => REFCTL is used to configure the internal reference
// If ref generator busy, WAIT
while(REFCTL0 & REFGENBUSY);
// Select internal ref = 2.5V, Internal Reference ON
REFCTL0 |= REFVSEL_2 | REFON;
ADC12CTL0 = ADC12SHT0_2 | ADC12ON;
// ADCCLK = MODOSC; sampling timer
ADC12CTL1 = ADC12SHP;
// 12-bit conversion results
ADC12CTL2 |= ADC12RES_2;
// Enable ADC conv complete interrupt
ADC12IER0 |= ADC12IE0;
// A1 ADC input select (A3 channel will be in ADC12MEM12) Vref+=2.5V; Vref-=AVSS (0.0V)
ADC12MCTL0 |= ADC12INCH_3 | ADC12VRSEL_1;
// Wait for reference generator to settle
while(!(REFCTL0 & REFGENRDY));
}
float adc_get_voltage(void)
{
// start conversion
ADC12CTL0 |= ADC12ENC | ADC12SC;
// wait for interrupt
xSemaphoreTake(msp430_adc_state.semaphore, portMAX_DELAY);
float voltage = (msp430_adc_state.voltage_raw_value * REFERENCE_VOLTAGE)
/ (1 << ADC_PRECISSION_BITS) * VOLTAGE_DIVIDER_RATIO;
return voltage;
}
void __attribute__((interrupt(ADC12_VECTOR))) adc12_ISR(void)
{
BaseType_t higher_priority_task_woken = pdFALSE;
switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
{
case ADC12IV_ADC12IFG0:
msp430_adc_state.voltage_raw_value = ADC12MEM0;
xSemaphoreGiveFromISR(msp430_adc_state.semaphore, &higher_priority_task_woken);
break;
default:
break;
}
portYIELD_FROM_ISR(higher_priority_task_woken);
}
#ifndef MSP430_ADC_H
#define MSP430_ADC_H
/**
* Prepares ADC module to work.
*
* PIN configuration
* P1.3 should be connected to voltage divider output
*
* The reference voltage is 2.5 V.
*/
void setup_adc(void);
/**
* Get current voltage from ADC.
*
* @returns Current voltage in Volts.
*/
float adc_get_voltage(void);
#endif
#include "msp430_i2c.h"
#include <string.h>
#include <msp430.h>
#include <FreeRTOS.h>
#include <semphr.h>
enum MSP430_I2CMode
{
MSP430_I2C_DATA_READ,
MSP430_I2C_DATA_WRITE
};
struct MSP430_I2CState
{