NCUBE ADCS: Main Page

NCUBE ADCS Documentation

Introduction

This is the software documentation of the Attitude Determination and Control System for the NCUBE student satellite. An overview of the various subsystems in NCUBE is shown below.

Overview of NCUBE subsystems

For more information about NCUBE, visit the official homepage at http://www.rocketrange.no/ncube/.

Overview

The ADCS module is responsible for detumbling of the satellite after it is ejected from the launch pod. Detumbling is necessary in order to reduce angular velocities before the gravity boom is released. Angular velocities are estimated by measuring the rate of change of the local geomagnetic field. Attitude is changed by using magnetorquers.

Installation

The software is developed using AVR-GCC v 3.3.1 and avr-libc v. 0.99.90.20030908. The excelent WinAVR distribution has been used. See http://winavr.sourceforge.net/index.html.

Target hardware is currently an ATMEGA32 microcontroller from ATMEL.

Compilation

A makefile is provided for building the software. Several targets are available. The main targets are:

  • make All. Build software and create hex file for downloading to target.
  • make extcoff. Create extended coff file for debugging with Atmel AVR studio v. >= 4.0
  • make clean. Delete all files created while building the software.

See the file Makefile for more details.

Note:
The code is not directly compatible with other compilers for the AVR ( for instance IAR, CodeVision). However, most of the code is ANSI-C compatible so a port should not be too difficult.

programming

The following important files are generated by the compilator.

  • adcsnode.hex. Binary hex file for mcu programming.
  • adcsnode.eep. EEPROM contents for mcu programming.
  • adcsnode.cof. Binary for use with the AVR studio debugger

All files can be used with AVR studio to program the MCU.

Author:
Kjell Magne Fauske
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: File Index

NCUBE ADCS File List

Here is a list of all files with brief descriptions:
adcshdr.h [code] | Standard include file for all ADCS modules
adcslog.c [code] | Implementation of ADCS data logging
adcslog.h [code] | Logging of ADCS data
adcsnode.c [code] | Implementation of the NCUBE ADCS
adcsnode.h [code] | NCUBE attitude control system
avrutils.h [code] | Various macro utilities for the AVR
coildriver.c [code] | Implementation of the coil driver module
coildriver.h [code] | Magnetic coil driver module
debugutils.c [code] | Implementation of various debug utilities
debugutils.h [code] | Various utility functions for reading and printing data for debugging
eevars.c [code] |
eevars.h [code] | Definition of variables stored in eeprom
iouart.c [code] |
iouart.h [code] | Interrupt driven and buffered UART communication
magnetometer.c [code] | Implementation of the magnetometer module
magnetometer.h [code] | Interface to the HMR2300 Smart Digital Magnetometer from Honeywell Changes: - 2004-09-02 -- Magnetometer mappings are now correct
softi2c.h [code] | Software driven TWI/I2c master interface
SPIeeprom.c [code] | Implementation of M95128E2PROM interface
SPIeeprom.h [code] |
sunsensors.c [code] | Implementation of the sun sensor interface
sunsensors.h [code] | Interface to the LDR sun sensors
telecommands.h [code] | Definition of recognized commands received from the TeleCommand
timingutils.c [code] | Implemenation of timing utilities
timingutils.h [code] | Timing utilities
tnccomm.c [code] | Implementation of the TNC communication module
tnccomm.h [code] | TNC communication module
twislave.c [code] | Implementation of the TWI slave module
twislave.h [code] | Interrupt driven TWI/I2C bus slave interface
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: adcshdr.h File Reference

adcshdr.h File Reference

Detailed Description

Standard include file for all ADCS modules.

Changes: 2003-10-22 -- File created. -- KMF

Definition in file adcshdr.h.

#include <avr/io.h>
#include <stdlib.h>
#include <inttypes.h>
#include <avr/wdt.h>
#include "avrutils.h"

Go to the source code of this file.

Defines

#define | F_CPU 4000000L
MCU clock frequency.

#define | EEPROM_SIGNATURE 232
Signature used to check that the eeprom has been programmed.

Define Documentation

#define EEPROM_SIGNATURE 232

Signature used to check that the eeprom has been programmed.

Definition at line 18 of file adcshdr.h.

Referenced by init_adcs().

#define F_CPU 4000000L

MCU clock frequency.

Definition at line 17 of file adcshdr.h.

Referenced by init_magnetometer_comm().

Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: adcslog.c File Reference

adcslog.c File Reference

Detailed Description

Implementation of ADCS data logging.

Definition in file adcslog.c.

#include "adcslog.h"
#include "SPIeeprom.h"
#include "magnetometer.h"
#include "timingutils.h"
#include "tnccomm.h"
#include "sunsensors.h"
#include "coildriver.h"
#include <avr/eeprom.h>
#include "eevars.h"

Go to the source code of this file.

Functions

void | store_elogstatus (void)
void | init_logging (void)
void | start_logging (uint8_t logflag, uint8_t timestep, uint8_t delay, uint8_t period)
Start logging of data.

void | store_log_exteeprom (void)
Store memorylog in external eeprom.

void | log_intdata (uint8_t log_type, int16_t x, int16_t y, int16_t z)
void | logSunsensors (void)
Store sunsensor data in log.

void | StartSendELog (void)
void | AbortSendELog (void)
void | SendELog (void)
void | log_reset (void)
void | log_data (void)
Log available data and store it in external eeprom.

Variables

uint8_t volatile | logdata_reg = 0
Log data status register.

uint8_t volatile | logdata_rdy_reg
Log data ready register.

uint8_t | logging_enabled
uint8_t | logtimestep = 10
uint8_t | logdelay
uint8_t | logperiod
uint8_t | logging_started = 0
LogEntry | memorylog [MEMORYLOG_SIZE]
uint8_t volatile | memlog_idx
uint8_t | LogCTRL
Internal control flags for external eeprom storage.

uint16_t | EE_ELogCycle
uint8_t | EE_ELogFull
uint16_t | ELogCycle
uint8_t | ELogFull
uint8_t | ELogSendPage
magMeasurement * lastB_p
Latest available magnetometer reading.

magMeasurement * lastBdot_p
Latest avaiable Bdot estimate.

sunMeasurement * | lastSun_p
Latest available sun sensor readings.

dutyStruct lastDuty
Latest available duty cycle output.

Function Documentation

void AbortSendELog ( void )

Definition at line 139 of file adcslog.c.

References LOG_E_SEND_FLAG, LogCTRL, and tnc_putline_P().

Referenced by handle_command().

void init_logging ( void )

Definition at line 48 of file adcslog.c.

References EE_ELogCycle, EE_ELogFull, eeprom_programmed, ELogCycle, ELogFull, LogCTRL, logdata_rdy_reg, logdata_reg, logging_enabled, memlog_idx, and store_elogstatus().

Referenced by init_adcs().

void log_data ( void )

Log available data and store it in external eeprom.

Uses logdata_reg and logdata_rdy_reg to determine which data to store.

Definition at line 175 of file adcslog.c.

References B_LOG, Bdot, BDOT_LOG, DUTY_LOG, dutyStruct::duty_x, dutyStruct::duty_y, dutyStruct::duty_z, lastB_p, lastDuty, log_intdata(), logdata_rdy_reg, logdata_reg, logSunsensors(), magMeasurement::magX, magMeasurement::magY, magMeasurement::magZ, and SUN_LOG.

Referenced by main().

void log_intdata | ( | uint8_t | log_type,
 |  | int16_t | x,
 |  | int16_t | y,
 |  | int16_t | z
 | ) |

Definition at line 91 of file adcslog.c.

References memlog_idx, memorylog, MEMORYLOG_SIZE, store_elogstatus(), store_log_exteeprom(), and UTC_Second.

Referenced by log_data().

void log_reset ( void )

Definition at line 168 of file adcslog.c.

References ELogCycle, ELogFull, store_elogstatus(), and tnc_putline_P().

Referenced by handle_command().

void logSunsensors ( void )

Store sunsensor data in log.

Definition at line 109 of file adcslog.c.

References memlog_idx, memorylog, MEMORYLOG_SIZE, store_elogstatus(), store_log_exteeprom(), SUN_LOG, sun_measurements, SUN_SENSORS, and UTC_Second.

Referenced by log_data().

void SendELog ( void )

Definition at line 149 of file adcslog.c.

References DATA_PR_LOGINTERVAL, ELogCycle, ELogSendPage, EXT_EEPROM_SIZE, LOG_E_SEND_FLAG, LogCTRL, ReadPageExtEeprom(), SPI_DONE_READ, SPI_IDLE, SPIBuf, SPIState, tnc_putchar(), tnc_puthex8(), and tnc_putline().

Referenced by doDownloadState().

void start_logging | ( | uint8_t | logflag,
 |  | uint8_t | timestep,
 |  | uint8_t | delay,
 |  | uint8_t | period
 | ) |

Start logging of data.

Set up timer to set flags when data should be logged.

Parameters:
logflag | What data should be logged.
timestep | Number of seconds between each logging of data.
delay | Minutes to wait before start logging.
period | Number of minutes to do logging.

Definition at line 70 of file adcslog.c.

References enable_timeout(), logdata_reg, logdelay, logging_enabled, logging_started, logperiod, logtimestep, and SEC_TIMER.

void StartSendELog ( void )

Definition at line 127 of file adcslog.c.

References DATA_PR_LOGINTERVAL, EE_ELogCycle, EE_ELogFull, ELogCycle, ELogFull, ELogSendPage, LOG_E_SEND_FLAG, LogCTRL, ReadPageExtEeprom(), and tnc_putline_P().

Referenced by doDownloadState().

void store_elogstatus ( void )

Definition at line 65 of file adcslog.c.

References EE_ELogCycle, EE_ELogFull, ELogCycle, and ELogFull.

Referenced by doDetumblingState(), doMeasuringState(), init_logging(), log_intdata(), log_reset(), and logSunsensors().

void store_log_exteeprom ( void )

Store memorylog in external eeprom.

Definition at line 83 of file adcslog.c.

References DATA_PR_LOGINTERVAL, ELogCycle, ELogFull, EXT_EEPROM_SIZE, memlog_idx, memorylog, and WritePageExtEeprom().

Referenced by log_intdata(), and logSunsensors().

Variable Documentation

uint16_t EE_ELogCycle

Definition at line 35 of file adcslog.c.

Referenced by init_logging(), StartSendELog(), and store_elogstatus().

uint8_t EE_ELogFull

Definition at line 36 of file adcslog.c.

Referenced by init_logging(), StartSendELog(), and store_elogstatus().

uint16_t ELogCycle

Definition at line 37 of file adcslog.c.

Referenced by init_logging(), log_reset(), SendELog(), StartSendELog(), store_elogstatus(), and store_log_exteeprom().

uint8_t ELogFull

Definition at line 38 of file adcslog.c.

Referenced by init_logging(), log_reset(), StartSendELog(), store_elogstatus(), and store_log_exteeprom().

uint8_t ELogSendPage

Definition at line 39 of file adcslog.c.

Referenced by SendELog(), and StartSendELog().

magMeasurement* lastB_p

Latest available magnetometer reading.

Definition at line 41 of file adcslog.c.

Referenced by doMeasuringState(), and log_data().

magMeasurement* lastBdot_p

Latest avaiable Bdot estimate.

Definition at line 42 of file adcslog.c.

Referenced by doMeasuringState().

struct dutyStruct lastDuty

Latest available duty cycle output.

Definition at line 44 of file adcslog.c.

Referenced by log_data(), and setDutyParams().

struct sunMeasurement* lastSun_p

Latest available sun sensor readings.

Definition at line 43 of file adcslog.c.

uint8_t LogCTRL

Internal control flags for external eeprom storage.

Definition at line 34 of file adcslog.c.

Referenced by AbortSendELog(), doDownloadState(), init_logging(), SendELog(), and StartSendELog().

uint8_t volatile logdata_rdy_reg

Log data ready register.

Definition at line 19 of file adcslog.c.

Referenced by doDetumblingState(), doMeasuringState(), init_logging(), and log_data().

uint8_t volatile logdata_reg = 0

Log data status register.

Tells which data should be logged.

Todo:
Should be combinded with LogCTRL

Definition at line 18 of file adcslog.c.

Referenced by doDetumblingState(), doMeasuringState(), handle_command(), init_detumbling(), init_logging(), log_data(), and start_logging().

uint8_t logdelay

Definition at line 24 of file adcslog.c.

Referenced by start_logging().

uint8_t logging_enabled

Definition at line 21 of file adcslog.c.

Referenced by doDetumblingState(), doMeasuringState(), handle_command(), init_detumbling(), init_logging(), main(), and start_logging().

uint8_t logging_started = 0

Definition at line 26 of file adcslog.c.

Referenced by start_logging().

uint8_t logperiod

Definition at line 25 of file adcslog.c.

Referenced by start_logging().

uint8_t logtimestep = 10

Definition at line 23 of file adcslog.c.

Referenced by doMeasuringState(), handle_command(), init_detumbling(), and start_logging().

uint8_t volatile memlog_idx

Definition at line 31 of file adcslog.c.

Referenced by init_logging(), log_intdata(), logSunsensors(), and store_log_exteeprom().

struct LogEntry memorylog[MEMORYLOG_SIZE]

Definition at line 30 of file adcslog.c.

Referenced by log_intdata(), logSunsensors(), and store_log_exteeprom().

Generated on Fri Sep 3 17:21:14 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: adcslog.h File Reference

adcslog.h File Reference

Detailed Description

Logging of ADCS data.

Definition in file adcslog.h.

#include "adcshdr.h"
#include "magnetometer.h"
#include "coildriver.h"

Go to the source code of this file.

Data Structures

struct | LogEntry
Single log entry. More...

Log flags

#define | B_LOG 1
#define | BDOT_LOG 2
#define | DUTY_LOG 3
#define | SUN_LOG 4

Defines

#define | DATA_PR_LOGINTERVAL 9
#define | MEMORYLOG_SIZE 3
#define | LOG_INTERVAL 20
#define | LOGDATA_SIZE 6
#define | LOG_E_FLAG 0x02
#define | LOG_E_SEND_FLAG 0x04

Functions

void | init_logging (void)
void | start_logging (uint8_t logflag, uint8_t timestep, uint8_t delay, uint8_t period)
Start logging of data.

void | log_intdata (uint8_t log_type, int16_t x, int16_t y, int16_t z)
void | logSunsensors (void)
Store sunsensor data in log.

void | log_data (void)
Log available data and store it in external eeprom.

void | StartSendELog (void)
void | AbortSendELog (void)
void | SendELog (void)
void | log_reset (void)
void | store_elogstatus (void)

Variables

magMeasurement * lastB_p
Latest available magnetometer reading.

magMeasurement * lastBdot_p
Latest avaiable Bdot estimate.

sunMeasurement * | lastSun_p
Latest available sun sensor readings.

dutyStruct lastDuty
Latest available duty cycle output.

uint8_t volatile | logdata_reg
Log data status register.

uint8_t volatile | logdata_rdy_reg
Log data ready register.

uint8_t | logging_enabled
uint8_t | logtimestep
uint8_t | LogCTRL
Internal control flags for external eeprom storage.

Define Documentation

#define B_LOG 1

Definition at line 29 of file adcslog.h.

Referenced by doDetumblingState(), doMeasuringState(), and log_data().

#define BDOT_LOG 2

Definition at line 30 of file adcslog.h.

Referenced by doDetumblingState(), doMeasuringState(), and log_data().

#define DATA_PR_LOGINTERVAL 9

Definition at line 15 of file adcslog.h.

Referenced by SendELog(), StartSendELog(), and store_log_exteeprom().

#define DUTY_LOG 3

Definition at line 31 of file adcslog.h.

Referenced by doDetumblingState(), and log_data().

#define LOG_E_FLAG 0x02

Definition at line 20 of file adcslog.h.

#define LOG_E_SEND_FLAG 0x04

Definition at line 21 of file adcslog.h.

Referenced by AbortSendELog(), doDownloadState(), SendELog(), and StartSendELog().

#define LOG_INTERVAL 20

Definition at line 17 of file adcslog.h.

#define LOGDATA_SIZE 6

Definition at line 18 of file adcslog.h.

#define MEMORYLOG_SIZE 3

Definition at line 16 of file adcslog.h.

Referenced by log_intdata(), and logSunsensors().

#define SUN_LOG 4

Definition at line 32 of file adcslog.h.

Referenced by doDetumblingState(), doMeasuringState(), init_detumbling(), log_data(), and logSunsensors().

Function Documentation

void AbortSendELog ( void )

Definition at line 139 of file adcslog.c.

References LOG_E_SEND_FLAG, LogCTRL, and tnc_putline_P().

Referenced by handle_command().

void init_logging ( void )

Definition at line 48 of file adcslog.c.

References EE_ELogCycle, EE_ELogFull, eeprom_programmed, ELogCycle, ELogFull, LogCTRL, logdata_rdy_reg, logdata_reg, logging_enabled, memlog_idx, and store_elogstatus().

Referenced by init_adcs().

void log_data ( void )

Log available data and store it in external eeprom.

Uses logdata_reg and logdata_rdy_reg to determine which data to store.

Definition at line 175 of file adcslog.c.

References B_LOG, Bdot, BDOT_LOG, DUTY_LOG, dutyStruct::duty_x, dutyStruct::duty_y, dutyStruct::duty_z, lastB_p, lastDuty, log_intdata(), logdata_rdy_reg, logdata_reg, logSunsensors(), magMeasurement::magX, magMeasurement::magY, magMeasurement::magZ, and SUN_LOG.

Referenced by main().

void log_intdata | ( | uint8_t | log_type,
 |  | int16_t | x,
 |  | int16_t | y,
 |  | int16_t | z
 | ) |

Definition at line 91 of file adcslog.c.

References memlog_idx, memorylog, MEMORYLOG_SIZE, store_elogstatus(), store_log_exteeprom(), and UTC_Second.

Referenced by log_data().

void log_reset ( void )

Definition at line 168 of file adcslog.c.

References ELogCycle, ELogFull, store_elogstatus(), and tnc_putline_P().

Referenced by handle_command().

void logSunsensors ( void )

Store sunsensor data in log.

Definition at line 109 of file adcslog.c.

References memlog_idx, memorylog, MEMORYLOG_SIZE, store_elogstatus(), store_log_exteeprom(), SUN_LOG, sun_measurements, SUN_SENSORS, and UTC_Second.

Referenced by log_data().

void SendELog ( void )

Definition at line 149 of file adcslog.c.

References DATA_PR_LOGINTERVAL, ELogCycle, ELogSendPage, EXT_EEPROM_SIZE, LOG_E_SEND_FLAG, LogCTRL, ReadPageExtEeprom(), SPI_DONE_READ, SPI_IDLE, SPIBuf, SPIState, tnc_putchar(), tnc_puthex8(), and tnc_putline().

Referenced by doDownloadState().

void start_logging | ( | uint8_t | logflag,
 |  | uint8_t | timestep,
 |  | uint8_t | delay,
 |  | uint8_t | period
 | ) |

Start logging of data.

Set up timer to set flags when data should be logged.

Parameters:
logflag | What data should be logged.
timestep | Number of seconds between each logging of data.
delay | Minutes to wait before start logging.
period | Number of minutes to do logging.

Definition at line 70 of file adcslog.c.

References enable_timeout(), logdata_reg, logdelay, logging_enabled, logging_started, logperiod, logtimestep, and SEC_TIMER.

void StartSendELog ( void )

Definition at line 127 of file adcslog.c.

References DATA_PR_LOGINTERVAL, EE_ELogCycle, EE_ELogFull, ELogCycle, ELogFull, ELogSendPage, LOG_E_SEND_FLAG, LogCTRL, ReadPageExtEeprom(), and tnc_putline_P().

Referenced by doDownloadState().

void store_elogstatus ( void )

Variable Documentation

magMeasurement* lastB_p

Latest available magnetometer reading.

Definition at line 35 of file adcslog.h.

Referenced by doMeasuringState(), and log_data().

magMeasurement* lastBdot_p

Latest avaiable Bdot estimate.

Definition at line 36 of file adcslog.h.

Referenced by doMeasuringState().

struct dutyStruct lastDuty

Latest available duty cycle output.

Definition at line 38 of file adcslog.h.

Referenced by log_data(), and setDutyParams().

struct sunMeasurement* lastSun_p

Latest available sun sensor readings.

Definition at line 37 of file adcslog.h.

uint8_t LogCTRL

Internal control flags for external eeprom storage.

Definition at line 67 of file adcslog.h.

Referenced by AbortSendELog(), doDownloadState(), init_logging(), SendELog(), and StartSendELog().

uint8_t volatile logdata_rdy_reg

Log data ready register.

Definition at line 64 of file adcslog.h.

Referenced by doDetumblingState(), doMeasuringState(), init_logging(), and log_data().

uint8_t volatile logdata_reg

Log data status register.

Tells which data should be logged.

Todo:
Should be combinded with LogCTRL

Definition at line 62 of file adcslog.h.

Referenced by doDetumblingState(), doMeasuringState(), handle_command(), init_detumbling(), init_logging(), log_data(), and start_logging().

uint8_t logging_enabled

Definition at line 65 of file adcslog.h.

Referenced by doDetumblingState(), doMeasuringState(), handle_command(), init_detumbling(), init_logging(), main(), and start_logging().

uint8_t logtimestep

Definition at line 66 of file adcslog.h.

Referenced by doMeasuringState(), handle_command(), init_detumbling(), and start_logging().

Generated on Fri Sep 3 17:21:14 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: adcsnode.c File Reference

adcsnode.c File Reference

Detailed Description

Implementation of the NCUBE ADCS.

Definition in file adcsnode.c.

#include "adcsnode.h"

Go to the source code of this file.

Defines

#define | MEASURE_DTBL_STATE 1
#define | ACTUATE_DTBL_STATE 2
#define | DELAY_DTBL_STATE 3
#define | MAX_DUTY 200

Functions

void | print_int (uint16_t i)
Print an integer throug the UART.

void | print_sint (int16_t i)
Output signed integer.

void | init_adcs (void)
Initialize NCUBE ADCS software.

void | changeState (State nxt_state)
Change main ADCS state.

uint16_t | getParamAddr (uint8_t param_id, uint8_t *param_size)
Return address and size of parameter stored in EEPROM.

void | set_parameter (void)
Set parameter value stored in EEPROM.

void | get_parameter (void)
Query parameter stored in EEPROM.

void | setCoilDuty (void)
void | doMagQuery (void)
void | handle_command (void)
Handle commands received from Telecommand decoder.

void | doVUartState (uint8_t msg)
Virtual uart state.

void | doSleepState (uint8_t msg)
void | doDownloadState (uint8_t msg)
void | doIdleState (uint8_t msg)
IDLE state handler.

void | doErrorState (uint8_t msg)
void | doMeasuringState (uint8_t msg)
void | doWaitState (uint8_t msg)
WAIT state handler.

void | calcBdot (uint8_t i_p, uint8_t i_n)
Calculate Bdot.

void | setDutyParams (int16_t m_x, int16_t m_y, int16_t m_z)
Convert output from controller to duty cycles.

void | doDetumblingState (uint8_t msg)
Detubmling state handler.

uint8_t | init_detumbling (void)
Initialize system for detumbling.

void | sendStatus (uint8_t extended)
Download ADCS status.

int | main (void)
Main program loop.

Variables

uint8_t | mcu_status
MCUCSR storage.

int16_t | k_xy_n
int16_t | k_xy_d
int16_t | k_z_n
int16_t | k_z_d
int16_t | mc_z
uint16_t | measure_period
uint16_t | actuate_period
uint16_t | magdelay_period
uint16_t | bdot_min
uint16_t | m_max
uint8_t | detumbling_period
uint8_t | measuring_period
uint8_t volatile | char_received = 0
State | current_state = IDLE_STATE
State next_state
State prev_state
State after_wait_state
Which state to enter after the WAIT state.

uint8_t | change_state
Tells that state must be changed.

void(* | state_tbl [])(uint8_t msg)=
Table of pointers to state functions.

Define Documentation

#define ACTUATE_DTBL_STATE 2

Definition at line 24 of file adcsnode.c.

Referenced by doDetumblingState().

#define DELAY_DTBL_STATE 3

Definition at line 25 of file adcsnode.c.

Referenced by doDetumblingState().

#define MAX_DUTY 200

Definition at line 27 of file adcsnode.c.

Referenced by setDutyParams().

#define MEASURE_DTBL_STATE 1

Definition at line 23 of file adcsnode.c.

Referenced by doDetumblingState().

Function Documentation

void calcBdot | ( | uint8_t | i_p,
 |  | uint8_t | i_n
 | ) |

Calculate Bdot.

Calculate the numerical derivate of the magnetic field vector using the formula:

 Bdot = ((B[k+1] - B[k-1])*mag_sampling_rate)/2;

Uses samples stored in mag_buffer. Result is stored in Bdot.

Parameters:
i_p | Index to B[k-1] sample in mag_buffer.
i_n | Index to B[k+1] sample in mag_buffer.

Definition at line 646 of file adcsnode.c.

References Bdot, mag_buffer, mag_sampling_rate, magMeasurement::magX, magMeasurement::magY, and magMeasurement::magZ.

Referenced by doDetumblingState(), and doMeasuringState().

void changeState ( State nxt_state )

Change main ADCS state.

Definition at line 145 of file adcsnode.c.

References change_state, and next_state.

Referenced by doDetumblingState(), doDownloadState(), doErrorState(), doIdleState(), doMeasuringState(), doSleepState(), doWaitState(), handle_command(), and main().

void doDetumblingState ( uint8_t msg )

Detubmling state handler.

Definition at line 707 of file adcsnode.c.

References ACTUATE_DTBL_STATE, ACTUATE_PERIOD, B_LOG, Bdot, BDOT_LOG, bdot_min, calcBdot(), changeState(), CoilAll, DELAY_DTBL_STATE, detumbling_period, disable_coil(), disable_timeout(), DUTY_LOG, enable_coil(), enable_timeout(), ERROR_STATE, EXIT_STATE_MSG, FALSE, init_detumbling(), INIT_STATE_MSG, k_xy_d, k_xy_n, k_z_d, k_z_n, logdata_rdy_reg, logdata_reg, logging_enabled, mag_fill_meas_buffer(), mag_start_stream, mag_stop_stream, MAGDELAY_PERIOD, magMeasurement::magX, magMeasurement::magY, magMeasurement::magZ, mc_z, MEASURE_DTBL_STATE, MEASURE_PERIOD, MIN_TIMER, MS_TIMER, sampleSunsensors(), SEC_TIMER, set_bit, set_duty(), setDutyParams(), store_elogstatus(), SUN_LOG, timed_out_ms, and tnc_putline_P().

void doDownloadState ( uint8_t msg )

Definition at line 487 of file adcsnode.c.

References changeState(), EXIT_STATE_MSG, IDLE_STATE, INIT_STATE_MSG, LOG_E_SEND_FLAG, LogCTRL, SendELog(), SPI_DONE_READ, SPIState, StartSendELog(), TNC_BUFFER_FULL_BIT, and TNC_status_reg.

void doErrorState ( uint8_t msg )

Definition at line 523 of file adcsnode.c.

References changeState(), EXIT_STATE_MSG, IDLE_STATE, and INIT_STATE_MSG.

void doIdleState ( uint8_t msg )

IDLE state handler.

In the IDLE state the mcu has nothing to do. If the mcu is idle for a specific period of time, sleep state is entered.

Definition at line 506 of file adcsnode.c.

References changeState(), disable_timeout(), enable_timeout(), EXIT_STATE_MSG, INIT_STATE_MSG, SEC_TIMER, SLEEP_STATE, and timed_out_sec.

void doMagQuery ( void )

Definition at line 289 of file adcsnode.c.

References CR_CHAR, mag_send_command_P(), RX_Counter, tnc_newline, tnc_putchar_n(), tnc_putline_P(), uart_flush_rxbuf(), and uart_getchar().

Referenced by handle_command().

void doMeasuringState ( uint8_t msg )

Definition at line 537 of file adcsnode.c.

References B_LOG, Bdot, BDOT_LOG, calcBdot(), changeState(), clear_bit, disable_timeout(), enable_timeout(), ERROR_STATE, EXIT_STATE_MSG, INIT_STATE_MSG, lastB_p, lastBdot_p, logdata_rdy_reg, logdata_reg, logging_enabled, logtimestep, mag_buffer, mag_fill_meas_buffer(), mag_is_on(), mag_send_command_P(), mag_set_detumbling_params(), mag_start_stream, mag_stop_stream, measuring_period, MIN_TIMER, sampleSunsensors(), SEC_TIMER, set_bit, store_elogstatus(), SUN_LOG, timed_out_sec, tnc_putline_P(), and uart_flush_rxbuf().

void doSleepState ( uint8_t msg )

Definition at line 467 of file adcsnode.c.

References _NOP, changeState(), EXIT_STATE_MSG, IDLE_STATE, and INIT_STATE_MSG.

void doVUartState ( uint8_t msg )

Virtual uart state.

Definition at line 459 of file adcsnode.c.

References RX_Counter, tnc_putchar_n(), and uart_getchar().

void doWaitState ( uint8_t msg )

WAIT state handler.

Wait state is entered before detumbling or measure state. The next state is determined by reading the after_wait_state var.

Definition at line 613 of file adcsnode.c.

References after_wait_state, changeState(), EE_waitstate_delay, EXIT_STATE_MSG, INIT_STATE_MSG, timed_out_min, and TRUE.

void get_parameter ( void )

Query parameter stored in EEPROM.

Called when the GET_PARAMETER_CMD is received. Value sent to tnc.

Definition at line 237 of file adcsnode.c.

References CmdBuf, CMDBUF_DATA, getParamAddr(), print_int(), tnc_put_P(), tnc_putchar(), and tnc_putline().

Referenced by handle_command().

uint16_t getParamAddr | ( | uint8_t | param_id,
 |  | uint8_t * | param_size
 | ) |

Return address and size of parameter stored in EEPROM.

Parameters:
param_id | ID of command. See documentation for SET_PARAMETER_CMD
*param_size | Address of variable to store the parameter size
Returns:
Address and size of parameter.

Definition at line 152 of file adcsnode.c.

References ACTUATE_PERIOD_PAR, BDOT_MIN_PAR, DTMBL_LOGDATA_REG_PAR, DTMBL_LOGTIMESTEP_PAR, EE_actuate_period, EE_bdot_min, EE_dtmbl_logdata_reg, EE_dtmbl_logtimestep, EE_k_xy_d, EE_k_xy_n, EE_k_z_d, EE_k_z_n, EE_m_max, EE_mag_sampling_rate, EE_magdelay_period, EE_mc_z, EE_measure_period, EE_waitstate_delay, K_XY_D_PAR, K_XY_N_PAR, K_Z_D_PAR, K_Z_N_PAR, M_MAX_PAR, MAG_SAMPLINGRATE_PAR, MAGDELAY_PERIOD_PAR, MC_Z_PAR, MEASURE_PERIOD_PAR, and WAITSTATE_DELAY_PAR.

Referenced by get_parameter(), and set_parameter().

void handle_command ( void )

Handle commands received from Telecommand decoder.

Definition at line 315 of file adcsnode.c.

References AbortSendELog(), after_wait_state, changeState(), CHAR_CMD, clear_bit, CMD_NUM_HIGH, CMD_NUM_LOW, CmdBuf, CMDBUF_DATA, CMDBUF_ID, CMDBUF_SIZE, CmdBufRdy, CmdBufSize, CoilAll, CONTINUE_DOWNLOAD_CMD, detumbling_period, DETUMBLING_STATE, disable_coil(), DISABLE_COILS_CMD, doMagQuery(), DOWNLOAD_LOGS_CMD, DOWNLOAD_STATE, EXT_STATUS_CMD, get_parameter(), GET_PARAMETER_CMD, IDLE_STATE, log_reset(), logdata_reg, logging_enabled, logtimestep, MAG_CMD, mag_is_on(), mag_send_command_N(), mag_send_command_P(), mag_stop_stream, MAGQUERY_CMD, MEASURE_STATE, measuring_period, PAUSE_DOWNLOAD_CMD, RESET_CMD, RESETELOG_CMD, sendStatus(), set_bit, set_duty(), set_parameter(), SET_PARAMETER_CMD, setCoilDuty(), SETDUTY_CMD, SLEEP_CMD, SLEEP_STATE, START_DETUMBLING_CMD, START_LOGGING_CMD, STARTMAG_CMD, STATUS_CMD, STOP_DETUMBLING_CMD, STOP_DOWNLOAD_CMD, STOP_LOGGING_CMD, STOPMAG_CMD, TIMEUPDATE_CMD, TNC_BUFFER_FULL_BIT, tnc_putline_P(), TNC_status_reg, uart_putchar(), UTC_Second, VUART_STATE, and WAIT_STATE.

Referenced by main().

void init_adcs ( void )

Initialize NCUBE ADCS software.

Definition at line 116 of file adcsnode.c.

References ADCS_I2C_ADDR, EE_eeprom_signature, eeprom_programmed, EEPROM_SIGNATURE, enable_interrupts, FALSE, init_coils(), init_logging(), init_magnetometer_comm(), Init_SPI(), init_tnc(), init_twi_slave(), TRUE, and UTC_Second.

Referenced by main().

uint8_t init_detumbling ( void )

Initialize system for detumbling.

Check that magnetometer is switched on and that the magnetometer is properly set up by reading the EE_mag_notinitialized parameter.

Returns:
0 if successfull. Otherwise an error code is returned.

Definition at line 809 of file adcsnode.c.

References actuate_period, bdot_min, EE_actuate_period, EE_bdot_min, EE_dtmbl_logdata_reg, EE_dtmbl_logtimestep, EE_k_xy_d, EE_k_xy_n, EE_k_z_d, EE_k_z_n, EE_m_max, EE_magdelay_period, EE_mc_z, EE_measure_period, enable_timeout(), initSunsensors(), k_xy_d, k_xy_n, k_z_d, k_z_n, logdata_reg, logging_enabled, logtimestep, m_max, mag_is_on(), mag_sampling_rate, mag_set_detumbling_params(), magdelay_period, MAGOFF_ERROR, mc_z, measure_period, SEC_TIMER, SUN_LOG, and TRUE.

Referenced by doDetumblingState().

int main ( void )

Main program loop.

Definition at line 869 of file adcsnode.c.

References change_state, changeState(), CmdBufRdy, current_state, EXIT_STATE_MSG, handle_command(), I2C_BUFFER_RDY_BIT, IDLE_STATE, init_adcs(), INIT_STATE_MSG, log_data(), logging_enabled, mcu_status, next_state, restart_timeout(), SEC_TIMER, state_tbl, timed_out_sec, TNC_status_reg, and transmit_12c_buffer().

void print_int ( uint16_t i )

Print an integer throug the UART.

Definition at line 82 of file adcsnode.c.

References print_buf(), tnc_newline, and tnc_put().

Referenced by get_parameter(), print_sint(), and setCoilDuty().

void print_sint ( int16_t i )

Output signed integer.

Definition at line 90 of file adcsnode.c.

References print_int(), and tnc_putchar().

Referenced by sendStatus().

void sendStatus ( uint8_t extended )

Download ADCS status.

Parameters:
extended Set to true to display an extended status report.

Definition at line 849 of file adcsnode.c.

References Bdot, current_state, magMeasurement::magX, magMeasurement::magY, magMeasurement::magZ, mcu_status, print_sint(), tnc_newline, tnc_put_P(), and tnc_puthex8().

Referenced by handle_command().

void set_parameter ( void )

Set parameter value stored in EEPROM.

Definition at line 212 of file adcsnode.c.

References CmdBuf, CMDBUF_DATA, getParamAddr(), tnc_putline(), and tnc_putline_P().

Referenced by handle_command().

void setCoilDuty ( void )

Definition at line 266 of file adcsnode.c.

References CmdBuf, CMDBUF_DATA, CoilAll, disable_coil(), enable_coil(), m_max, print_int(), setDutyParams(), tnc_put_P(), and tnc_putchar().

Referenced by handle_command().

void setDutyParams | ( | int16_t | m_x,
 |  | int16_t | m_y,
 |  | int16_t | m_z
 | ) |

Convert output from controller to duty cycles.

Definition at line 655 of file adcsnode.c.

References CoilX, CoilY, CoilZ, dutyStruct::duty_x, dutyStruct::duty_y, dutyStruct::duty_z, lastDuty, m_max, MAX_DUTY, and set_duty().

Referenced by doDetumblingState(), and setCoilDuty().

Variable Documentation

uint16_t actuate_period

Definition at line 37 of file adcsnode.c.

Referenced by init_detumbling().

State after_wait_state

Which state to enter after the WAIT state.

Definition at line 49 of file adcsnode.c.

Referenced by doWaitState(), and handle_command().

uint16_t bdot_min

Definition at line 39 of file adcsnode.c.

Referenced by doDetumblingState(), and init_detumbling().

uint8_t change_state

Tells that state must be changed.

Definition at line 50 of file adcsnode.c.

Referenced by changeState(), and main().

uint8_t volatile char_received = 0

Definition at line 44 of file adcsnode.c.

State current_state = IDLE_STATE

Definition at line 45 of file adcsnode.c.

Referenced by main(), and sendStatus().

uint8_t detumbling_period

Definition at line 42 of file adcsnode.c.

Referenced by doDetumblingState(), and handle_command().

int16_t k_xy_d

Definition at line 32 of file adcsnode.c.

Referenced by doDetumblingState(), and init_detumbling().

int16_t k_xy_n

Definition at line 31 of file adcsnode.c.

Referenced by doDetumblingState(), and init_detumbling().

int16_t k_z_d

Definition at line 34 of file adcsnode.c.

Referenced by doDetumblingState(), and init_detumbling().

int16_t k_z_n

Definition at line 33 of file adcsnode.c.

Referenced by doDetumblingState(), and init_detumbling().

uint16_t m_max

Definition at line 40 of file adcsnode.c.

Referenced by init_detumbling(), setCoilDuty(), and setDutyParams().

uint16_t magdelay_period

Definition at line 38 of file adcsnode.c.

Referenced by init_detumbling().

int16_t mc_z

Definition at line 35 of file adcsnode.c.

Referenced by doDetumblingState(), and init_detumbling().

uint8_t mcu_status

MCUCSR storage.

Definition at line 29 of file adcsnode.c.

Referenced by main(), and sendStatus().

uint16_t measure_period

Definition at line 36 of file adcsnode.c.

Referenced by init_detumbling().

uint8_t measuring_period

Definition at line 42 of file adcsnode.c.

Referenced by doMeasuringState(), and handle_command().

State next_state

Definition at line 46 of file adcsnode.c.

Referenced by changeState(), and main().

State prev_state

Definition at line 47 of file adcsnode.c.

void(* state_tbl[])(uint8_t msg) =

Table of pointers to state functions.

The state table maps the states defined in the State enum to corresponding functions implementing the states.

The state functions must be on the form

 void name(uint8_t msg)
where msg is a message sent to state when called. Currently two messages are defined:
  • INIT_STATE_MSG. Sent when state is entered
  • EXIT_STATE_MSG. Sent when state is ended.

An example of entering the wait state:

 state_tbl[WAIT_STATE](INIT_STATE_MSG);

Definition at line 72 of file adcsnode.c.

Referenced by main().

Generated on Fri Sep 3 17:21:14 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: adcsnode.h File Reference

adcsnode.h File Reference

Detailed Description

NCUBE attitude control system.

Author:
Kjell Magne Fauske

Definition in file adcsnode.h.

#include <avr/delay.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/sleep.h>
#include <stdlib.h>
#include "adcshdr.h"
#include "telecommands.h"
#include "iouart.h"
#include "twislave.h"
#include "magnetometer.h"
#include "tnccomm.h"
#include "coildriver.h"
#include "SPIeeprom.h"
#include "timingutils.h"
#include "adcslog.h"
#include "eevars.h"
#include "sunsensors.h"

Go to the source code of this file.

Detumbling parameters

#define | MAGOFF_ERROR 1
#define | MEASURE_PERIOD 500
#define | ACTUATE_PERIOD 500
#define | MAGDELAY_PERIOD 500

Defines

#define | INIT_STATE_MSG 254
#define | EXIT_STATE_MSG 255
#define | TWI_SLAVE_ADDR 0x10
#define | ADCS_I2C_ADDR 0x77

Enumerations

enum State {
IDLE_STATE = 0, DETUMBLING_STATE, MEASURE_STATE, VUART_STATE,
DOWNLOAD_STATE, WAIT_STATE, SLEEP_STATE, ERROR_STATE
}
Main ADCS states. More...

Functions

void | spi_master_init (void)
Initialize device as SPI master.

void | init_adcs (void)
Initialize NCUBE ADCS software.

void | changeState (State nxt_state)
Change main ADCS state.

void | handle_command (void)
Handle commands received from Telecommand decoder.

void | doIdleState (uint8_t msg)
IDLE state handler.

void | doDetumblingState (uint8_t msg)
Detubmling state handler.

void | doMeasuringState (uint8_t msg)
void | doVUartState (uint8_t msg)
Virtual uart state.

void | doDownloadState (uint8_t msg)
void | doMagQuery (void)
void | doWaitState (uint8_t msg)
WAIT state handler.

void | doMeasuring (uint8_t msg)
void | doSleepState (uint8_t msg)
void | doErrorState (uint8_t msg)
uint8_t | init_detumbling (void)
Initialize system for detumbling.

void | set_parameter (void)
Set parameter value stored in EEPROM.

void | get_parameter (void)
Query parameter stored in EEPROM.

void | calcBdot (uint8_t i_p, uint8_t i_n)
Calculate Bdot.

uint16_t | getParamAddr (uint8_t param_id, uint8_t *param_size)
Return address and size of parameter stored in EEPROM.

void | setDutyParams (int16_t m_x, int16_t m_y, int16_t m_z)
Convert output from controller to duty cycles.

void | sendStatus (uint8_t extended)
Download ADCS status.

Variables

uint8_t | mcu_status
MCUCSR storage.

Define Documentation

#define ACTUATE_PERIOD 500

Definition at line 60 of file adcsnode.h.

Referenced by doDetumblingState().

#define ADCS_I2C_ADDR 0x77

Definition at line 53 of file adcsnode.h.

Referenced by init_adcs().

#define EXIT_STATE_MSG 255

Definition at line 49 of file adcsnode.h.

Referenced by doDetumblingState(), doDownloadState(), doErrorState(), doIdleState(), doMeasuringState(), doSleepState(), doWaitState(), and main().

#define INIT_STATE_MSG 254

Definition at line 48 of file adcsnode.h.

Referenced by doDetumblingState(), doDownloadState(), doErrorState(), doIdleState(), doMeasuringState(), doSleepState(), doWaitState(), and main().

#define MAGDELAY_PERIOD 500

Definition at line 61 of file adcsnode.h.

Referenced by doDetumblingState().

#define MAGOFF_ERROR 1

Definition at line 58 of file adcsnode.h.

Referenced by init_detumbling().

#define MEASURE_PERIOD 500

Definition at line 59 of file adcsnode.h.

Referenced by doDetumblingState().

#define TWI_SLAVE_ADDR 0x10

Definition at line 51 of file adcsnode.h.

Enumeration Type Documentation

enum State

Main ADCS states.

Enumeration values:
IDLE_STATE | Nothing to do.
DETUMBLING_STATE | Detumbling.
MEASURE_STATE | Measure.
VUART_STATE | Virtual UART.
DOWNLOAD_STATE | Download data.
WAIT_STATE | Wait to start detumbling og measure state.
SLEEP_STATE | Power save mode.
ERROR_STATE | Error state.

Definition at line 34 of file adcsnode.h.

Function Documentation

void calcBdot | ( | uint8_t | i_p,
 |  | uint8_t | i_n
 | ) |

Calculate Bdot.

Calculate the numerical derivate of the magnetic field vector using the formula:

 Bdot = ((B[k+1] - B[k-1])*mag_sampling_rate)/2;

Uses samples stored in mag_buffer. Result is stored in Bdot.

Parameters:
i_p | Index to B[k-1] sample in mag_buffer.
i_n | Index to B[k+1] sample in mag_buffer.

Definition at line 646 of file adcsnode.c.

References Bdot, mag_buffer, mag_sampling_rate, magMeasurement::magX, magMeasurement::magY, and magMeasurement::magZ.

Referenced by doDetumblingState(), and doMeasuringState().

void changeState ( State nxt_state )

Change main ADCS state.

Definition at line 145 of file adcsnode.c.

References change_state, and next_state.

Referenced by doDetumblingState(), doDownloadState(), doErrorState(), doIdleState(), doMeasuringState(), doSleepState(), doWaitState(), handle_command(), and main().

void doDetumblingState ( uint8_t msg )

Detubmling state handler.

Definition at line 707 of file adcsnode.c.

References ACTUATE_DTBL_STATE, ACTUATE_PERIOD, B_LOG, Bdot, BDOT_LOG, bdot_min, calcBdot(), changeState(), CoilAll, DELAY_DTBL_STATE, detumbling_period, disable_coil(), disable_timeout(), DUTY_LOG, enable_coil(), enable_timeout(), ERROR_STATE, EXIT_STATE_MSG, FALSE, init_detumbling(), INIT_STATE_MSG, k_xy_d, k_xy_n, k_z_d, k_z_n, logdata_rdy_reg, logdata_reg, logging_enabled, mag_fill_meas_buffer(), mag_start_stream, mag_stop_stream, MAGDELAY_PERIOD, magMeasurement::magX, magMeasurement::magY, magMeasurement::magZ, mc_z, MEASURE_DTBL_STATE, MEASURE_PERIOD, MIN_TIMER, MS_TIMER, sampleSunsensors(), SEC_TIMER, set_bit, set_duty(), setDutyParams(), store_elogstatus(), SUN_LOG, timed_out_ms, and tnc_putline_P().

void doDownloadState ( uint8_t msg )

Definition at line 487 of file adcsnode.c.

References changeState(), EXIT_STATE_MSG, IDLE_STATE, INIT_STATE_MSG, LOG_E_SEND_FLAG, LogCTRL, SendELog(), SPI_DONE_READ, SPIState, StartSendELog(), TNC_BUFFER_FULL_BIT, and TNC_status_reg.

void doErrorState ( uint8_t msg )

Definition at line 523 of file adcsnode.c.

References changeState(), EXIT_STATE_MSG, IDLE_STATE, and INIT_STATE_MSG.

void doIdleState ( uint8_t msg )

IDLE state handler.

In the IDLE state the mcu has nothing to do. If the mcu is idle for a specific period of time, sleep state is entered.

Definition at line 506 of file adcsnode.c.

References changeState(), disable_timeout(), enable_timeout(), EXIT_STATE_MSG, INIT_STATE_MSG, SEC_TIMER, SLEEP_STATE, and timed_out_sec.

void doMagQuery ( void )

Definition at line 289 of file adcsnode.c.

References CR_CHAR, mag_send_command_P(), RX_Counter, tnc_newline, tnc_putchar_n(), tnc_putline_P(), uart_flush_rxbuf(), and uart_getchar().

Referenced by handle_command().

void doMeasuring ( uint8_t msg )

void doMeasuringState ( uint8_t msg )

Definition at line 537 of file adcsnode.c.

References B_LOG, Bdot, BDOT_LOG, calcBdot(), changeState(), clear_bit, disable_timeout(), enable_timeout(), ERROR_STATE, EXIT_STATE_MSG, INIT_STATE_MSG, lastB_p, lastBdot_p, logdata_rdy_reg, logdata_reg, logging_enabled, logtimestep, mag_buffer, mag_fill_meas_buffer(), mag_is_on(), mag_send_command_P(), mag_set_detumbling_params(), mag_start_stream, mag_stop_stream, measuring_period, MIN_TIMER, sampleSunsensors(), SEC_TIMER, set_bit, store_elogstatus(), SUN_LOG, timed_out_sec, tnc_putline_P(), and uart_flush_rxbuf().

void doSleepState ( uint8_t msg )

Definition at line 467 of file adcsnode.c.

References _NOP, changeState(), EXIT_STATE_MSG, IDLE_STATE, and INIT_STATE_MSG.

void doVUartState ( uint8_t msg )

Virtual uart state.

Definition at line 459 of file adcsnode.c.

References RX_Counter, tnc_putchar_n(), and uart_getchar().

void doWaitState ( uint8_t msg )

WAIT state handler.

Wait state is entered before detumbling or measure state. The next state is determined by reading the after_wait_state var.

Definition at line 613 of file adcsnode.c.

References after_wait_state, changeState(), EE_waitstate_delay, EXIT_STATE_MSG, INIT_STATE_MSG, timed_out_min, and TRUE.

void get_parameter ( void )

Query parameter stored in EEPROM.

Called when the GET_PARAMETER_CMD is received. Value sent to tnc.

Definition at line 237 of file adcsnode.c.

References CmdBuf, CMDBUF_DATA, getParamAddr(), print_int(), tnc_put_P(), tnc_putchar(), and tnc_putline().

Referenced by handle_command().

uint16_t getParamAddr | ( | uint8_t | param_id,
 |  | uint8_t * | param_size
 | ) |

Return address and size of parameter stored in EEPROM.

Parameters:
param_id | ID of command. See documentation for SET_PARAMETER_CMD
*param_size | Address of variable to store the parameter size
Returns:
Address and size of parameter.

Definition at line 152 of file adcsnode.c.

References ACTUATE_PERIOD_PAR, BDOT_MIN_PAR, DTMBL_LOGDATA_REG_PAR, DTMBL_LOGTIMESTEP_PAR, EE_actuate_period, EE_bdot_min, EE_dtmbl_logdata_reg, EE_dtmbl_logtimestep, EE_k_xy_d, EE_k_xy_n, EE_k_z_d, EE_k_z_n, EE_m_max, EE_mag_sampling_rate, EE_magdelay_period, EE_mc_z, EE_measure_period, EE_waitstate_delay, K_XY_D_PAR, K_XY_N_PAR, K_Z_D_PAR, K_Z_N_PAR, M_MAX_PAR, MAG_SAMPLINGRATE_PAR, MAGDELAY_PERIOD_PAR, MC_Z_PAR, MEASURE_PERIOD_PAR, and WAITSTATE_DELAY_PAR.

Referenced by get_parameter(), and set_parameter().

void handle_command ( void )

Handle commands received from Telecommand decoder.

Definition at line 315 of file adcsnode.c.

References AbortSendELog(), after_wait_state, changeState(), CHAR_CMD, clear_bit, CMD_NUM_HIGH, CMD_NUM_LOW, CmdBuf, CMDBUF_DATA, CMDBUF_ID, CMDBUF_SIZE, CmdBufRdy, CmdBufSize, CoilAll, CONTINUE_DOWNLOAD_CMD, detumbling_period, DETUMBLING_STATE, disable_coil(), DISABLE_COILS_CMD, doMagQuery(), DOWNLOAD_LOGS_CMD, DOWNLOAD_STATE, EXT_STATUS_CMD, get_parameter(), GET_PARAMETER_CMD, IDLE_STATE, log_reset(), logdata_reg, logging_enabled, logtimestep, MAG_CMD, mag_is_on(), mag_send_command_N(), mag_send_command_P(), mag_stop_stream, MAGQUERY_CMD, MEASURE_STATE, measuring_period, PAUSE_DOWNLOAD_CMD, RESET_CMD, RESETELOG_CMD, sendStatus(), set_bit, set_duty(), set_parameter(), SET_PARAMETER_CMD, setCoilDuty(), SETDUTY_CMD, SLEEP_CMD, SLEEP_STATE, START_DETUMBLING_CMD, START_LOGGING_CMD, STARTMAG_CMD, STATUS_CMD, STOP_DETUMBLING_CMD, STOP_DOWNLOAD_CMD, STOP_LOGGING_CMD, STOPMAG_CMD, TIMEUPDATE_CMD, TNC_BUFFER_FULL_BIT, tnc_putline_P(), TNC_status_reg, uart_putchar(), UTC_Second, VUART_STATE, and WAIT_STATE.

Referenced by main().

void init_adcs ( void )

Initialize NCUBE ADCS software.

Definition at line 116 of file adcsnode.c.

References ADCS_I2C_ADDR, EE_eeprom_signature, eeprom_programmed, EEPROM_SIGNATURE, enable_interrupts, FALSE, init_coils(), init_logging(), init_magnetometer_comm(), Init_SPI(), init_tnc(), init_twi_slave(), TRUE, and UTC_Second.

Referenced by main().

uint8_t init_detumbling ( void )

Initialize system for detumbling.

Check that magnetometer is switched on and that the magnetometer is properly set up by reading the EE_mag_notinitialized parameter.

Returns:
0 if successfull. Otherwise an error code is returned.

Definition at line 809 of file adcsnode.c.

References actuate_period, bdot_min, EE_actuate_period, EE_bdot_min, EE_dtmbl_logdata_reg, EE_dtmbl_logtimestep, EE_k_xy_d, EE_k_xy_n, EE_k_z_d, EE_k_z_n, EE_m_max, EE_magdelay_period, EE_mc_z, EE_measure_period, enable_timeout(), initSunsensors(), k_xy_d, k_xy_n, k_z_d, k_z_n, logdata_reg, logging_enabled, logtimestep, m_max, mag_is_on(), mag_sampling_rate, mag_set_detumbling_params(), magdelay_period, MAGOFF_ERROR, mc_z, measure_period, SEC_TIMER, SUN_LOG, and TRUE.

Referenced by doDetumblingState().

void sendStatus ( uint8_t extended )

Download ADCS status.

Parameters:
extended Set to true to display an extended status report.

Definition at line 849 of file adcsnode.c.

References Bdot, current_state, magMeasurement::magX, magMeasurement::magY, magMeasurement::magZ, mcu_status, print_sint(), tnc_newline, tnc_put_P(), and tnc_puthex8().

Referenced by handle_command().

void set_parameter ( void )

Set parameter value stored in EEPROM.

Definition at line 212 of file adcsnode.c.

References CmdBuf, CMDBUF_DATA, getParamAddr(), tnc_putline(), and tnc_putline_P().

Referenced by handle_command().

void setDutyParams | ( | int16_t | m_x,
 |  | int16_t | m_y,
 |  | int16_t | m_z
 | ) |

Convert output from controller to duty cycles.

Definition at line 655 of file adcsnode.c.

References CoilX, CoilY, CoilZ, dutyStruct::duty_x, dutyStruct::duty_y, dutyStruct::duty_z, lastDuty, m_max, MAX_DUTY, and set_duty().

Referenced by doDetumblingState(), and setCoilDuty().

void spi_master_init ( void )

Initialize device as SPI master.

Variable Documentation

uint8_t mcu_status

MCUCSR storage.

Definition at line 64 of file adcsnode.h.

Referenced by main(), and sendStatus().

Generated on Fri Sep 3 17:21:14 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: avrutils.h File Reference

avrutils.h File Reference

Detailed Description

Various macro utilities for the AVR.

Definition in file avrutils.h.

Go to the source code of this file.

Bit manipulation macros.

#define | set_bit(reg, bit) reg |= (1 << bit)
Set a single bit in a register.

#define | clear_bit(reg, bit) reg &= ~(1 << bit)
Clear a single bit in a register.

#define | toggle_bit(reg, bit) reg ^= (1 << bit)
Toggle a single bit in a register on or off.

#define | test_bit bit_is_set
Alias for bit_is_set().

#define | assign_bit(reg, bit, val) (val)?(set_bit(reg, bit)):(clear_bit(reg,bit))
Assign a logical value to a specific bit in a register.

Debug utilities.

#define | avr_break() __asm__ __volatile__ ("break" ::)
Insert a break instruction for JTAG debugging.

IAR compatibility macros

Enable interrupts.

#define | __enable_interrupt() sei()
#define | _NOP() __asm__ __volatile__ ("nop" ::)
Insert a no operation opcode.

#define | enable_interrupts() sei();
#define | __disable_interrupt() cli()
Disable interrupts.

#define | disable_interrupts() cli()

Defines

#define | F_CPU 8000000L
#define | EEPROM __attribute__ ((section (".eeprom")))
Minutes to wait before detumbling or measure state.

#define | TRUE 1
#define | FALSE 0

Define Documentation

#define __disable_interrupt ( ) cli()

Disable interrupts.

Definition at line 73 of file avrutils.h.

#define __enable_interrupt ( ) sei()

Definition at line 65 of file avrutils.h.

#define _NOP ( ) __asm__ __volatile__ ("nop" ::)

Insert a no operation opcode.

Definition at line 68 of file avrutils.h.

Referenced by doSleepState(), and EnableWriteExtEeprom().

#define assign_bit | ( | reg,
 |  | bit,
 |  | val | ) | (val)?(set_bit(reg, bit)):(clear_bit(reg,bit))

Assign a logical value to a specific bit in a register.

Definition at line 50 of file avrutils.h.

Referenced by set_duty().

#define avr_break ( ) __asm__ __volatile__ ("break" ::)

Insert a break instruction for JTAG debugging.

Definition at line 58 of file avrutils.h.

#define clear_bit | ( | reg,
 |  | bit | ) | reg &= ~(1 << bit)

Clear a single bit in a register.

Definition at line 35 of file avrutils.h.

Referenced by disable_coil(), disable_timeout(), doMeasuringState(), enable_timeout(), handle_command(), init_coils(), SIGNAL(), and transmit_12c_buffer().

#define disable_interrupts ( ) cli()

Definition at line 75 of file avrutils.h.

Referenced by uart_flush_rxbuf(), and uart_flush_txbuf().

const uint8_t EE_mag_notinitialized EEPROM __attribute__ ((section (".eeprom")))

Minutes to wait before detumbling or measure state.

Warning:
Internal EEPROM must be initialized when program is downloaded. Otherwise value will be non-zero.

Definition at line 14 of file avrutils.h.

#define enable_interrupts ( ) sei();

Definition at line 70 of file avrutils.h.

Referenced by init_adcs(), uart_flush_rxbuf(), and uart_flush_txbuf().

#define F_CPU 8000000L

Definition at line 10 of file avrutils.h.

#define FALSE 0

Definition at line 22 of file avrutils.h.

Referenced by doDetumblingState(), ExtEepromWriteReady(), init_adcs(), and sampleSunsensors().

#define set_bit | ( | reg,
 |  | bit | ) | reg |= (1 << bit)

Set a single bit in a register.

Definition at line 30 of file avrutils.h.

Referenced by doDetumblingState(), doMeasuringState(), enable_coil(), enable_timeout(), handle_command(), init_tnc(), sampleSunsensors(), SIGNAL(), tnc_putchar(), and uart_putchar().

#define test_bit bit_is_set

Alias for bit_is_set().

Definition at line 45 of file avrutils.h.

#define toggle_bit | ( | reg,
 |  | bit | ) | reg ^= (1 << bit)

Toggle a single bit in a register on or off.

Definition at line 40 of file avrutils.h.

#define TRUE 1

Definition at line 18 of file avrutils.h.

Referenced by doWaitState(), ExtEepromWriteReady(), init_adcs(), init_detumbling(), and transmit_12c_buffer().

Generated on Fri Sep 3 17:21:15 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: coildriver.c File Reference

coildriver.c File Reference

Detailed Description

Implementation of the coil driver module.

Definition in file coildriver.c.

#include "coildriver.h"
#include "adcslog.h"

Go to the source code of this file.

Register definitions

#define | COILX_DUTY_REG OCR0
Coil X duty cycle register.

#define | COILY_DUTY_REG OCR1A
Coil Y duty cycle register.

#define | COILZ_DUTY_REG OCR1B
Coil Z duty cycle register.

Functions

void | init_coils (void)
Initialize coils.

void | enable_coil (Coils coil)
Enable coil.

void | disable_coil (Coils coil)
Disable coil.

void | set_duty (uint8_t duty_cycle, uint8_t direction, Coils coil)
Set duty cycle and direction.

Define Documentation

#define COILX_DUTY_REG OCR0

Coil X duty cycle register.

Definition at line 10 of file coildriver.c.

Referenced by set_duty().

#define COILY_DUTY_REG OCR1A

Coil Y duty cycle register.

Definition at line 11 of file coildriver.c.

Referenced by set_duty().

#define COILZ_DUTY_REG OCR1B

Coil Z duty cycle register.

Definition at line 12 of file coildriver.c.

Referenced by set_duty().

Function Documentation

void disable_coil ( Coils coil )

Disable coil.

Disconnect one or all PWM channels from their assgined OCn pin and clear ENABLE.

Parameters:
coil Coil.

Definition at line 66 of file coildriver.c.

References clear_bit, CoilAll, CoilX, COILX_ENABLE_PIN, COILX_ENABLE_PORT, CoilY, COILY_ENABLE_PIN, COILY_ENABLE_PORT, CoilZ, COILZ_ENABLE_PIN, and COILZ_ENABLE_PORT.

Referenced by doDetumblingState(), handle_command(), and setCoilDuty().

void enable_coil ( Coils coil )

Enable coil.

Connect one or all PWM channels to their assigned OCn pin. ENABLE signal is set.

Parameters:
coil Coil.

Definition at line 40 of file coildriver.c.

References CoilAll, CoilX, COILX_ENABLE_PIN, COILX_ENABLE_PORT, CoilY, COILY_ENABLE_PIN, COILY_ENABLE_PORT, CoilZ, COILZ_ENABLE_PIN, COILZ_ENABLE_PORT, and set_bit.

Referenced by doDetumblingState(), and setCoilDuty().

void init_coils ( void )

Initialize coils.

Initialize control pins and PWM channels.

Note:
PWM output pins are not connected. ENABLE and DIRECTION pins are set low.

Definition at line 15 of file coildriver.c.

References clear_bit, COILX_DIR_PIN, COILX_DIR_PORT, COILX_ENABLE_PIN, COILX_ENABLE_PORT, COILX_PWM_PIN, COILY_DIR_PIN, COILY_DIR_PORT, COILY_ENABLE_PIN, COILY_ENABLE_PORT, COILY_PWM_PIN, COILZ_DIR_PIN, COILZ_DIR_PORT, COILZ_ENABLE_PIN, COILZ_ENABLE_PORT, COILZ_PWM_PIN, DIR_DDR, and ENABLE_DDR.

Referenced by init_adcs().

void set_duty | ( | uint8_t | duty_cycle,
 |  | uint8_t | direction,
 |  | Coils | coil
 | ) |

Set duty cycle and direction.

Parameters:
duty_cycle | On time. Ranging from 0 (0%) to 255 (100%)
direction | Direction of current in coil.
coil | Coil.

Definition at line 93 of file coildriver.c.

References assign_bit, CoilAll, CoilX, COILX_DIR_PIN, COILX_DIR_PORT, COILX_DUTY_REG, CoilY, COILY_DIR_PIN, COILY_DIR_PORT, COILY_DUTY_REG, CoilZ, COILZ_DIR_PIN, COILZ_DIR_PORT, and COILZ_DUTY_REG.

Referenced by doDetumblingState(), handle_command(), and setDutyParams().

Generated on Fri Sep 3 17:21:15 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: coildriver.h File Reference

coildriver.h File Reference

Detailed Description

Magnetic coil driver module.

The current through each coil is controlled with a PWM signal. Three MCU PWM channels are used. A H-bridge is used for each coil to control direction. Additionally a signal is used to enable current to flow through a coil.

Pin and timer usage
Timer0 and Timer1 are used for PWM generation. Timer0 is a 8-bit timer, while Timer1 is a 16-bit timer. However, Timer1 is divided into two 8-bit timers. The timers are connected to the OC0, OC1A and OC1B pins, corresponing to CoilX, CoilY and CoilZ respectively.
Changes:
  • 2003-10-22 -- File created
  • 2004-02-18 -- Changed pins according to PCB layout.
  • 2004-09-02 -- Changed pins for coilX and coilY

Definition in file coildriver.h.

#include "adcshdr.h"

Go to the source code of this file.

Data Structures

struct | dutyStruct
Structure for storing duty cycle values. More...

Pin and port definitions

Pins and ports are given symbolic names to ease portability between different MCUs.

Note:
2004-09-02 There is a difference between the X, and Z axes internally and in the schematics. The X_Enable and X_PWM lines in the schematics corresponds to the internal Z axis.

#define | COILX_PWM_PIN PD4
PWM pin for coil X.

#define | COILY_PWM_PIN PD5
PWM pin for coil Y.

#define | COILZ_PWM_PIN PB3
PWM pin for coil Z.

#define | COILX_PWM_PORT PORTD
Port used for coil X PWM pin.

#define | COILY_PWM_PORT PORTD
Port used for coil Y PWM pin.

#define | COILZ_PWM_PORT PORTB
Port used for coil Z PWM pin.

#define | COILX_ENABLE_PIN PB2
Enable pin for coil X.

#define | COILY_ENABLE_PIN PB1
Enable pin for coil Y.

#define | COILZ_ENABLE_PIN PB0
Enable pin for coil Z.

#define | COILX_ENABLE_PORT PORTB
Enable pin port for coil X.

#define | COILY_ENABLE_PORT PORTB
Enable pin port for coil Y.

#define | COILZ_ENABLE_PORT PORTB
Enable pin port for coil Z.

#define | ENABLE_DDR DDRB
Direction port for enable pins.

#define | COILX_DIR_PIN PD7
Direction pin for coil X.

#define | COILY_DIR_PIN PD6
Direction pin for coil Y.

#define | COILZ_DIR_PIN PD3
Direction pin for coil Z.

#define | COILX_DIR_PORT PORTD
Direction pin port for coil X.

#define | COILY_DIR_PORT PORTD
Direction pin port for coil Y.

#define | COILZ_DIR_PORT PORTD
Direction pin portfor coil Z.

#define | DIR_DDR DDRD

Coil parameters

Parameters for calculating the magnetic moments.

Cross sections are given in m*1000

#define | COILX_N 120
Number of windings in coil X.

#define | COILY_N 120
Number of windings in coil Y.

#define | COILZ_N 120
Number of windings in coil Z.

#define | COILX_A 64
Cross section area of coil X.

#define | COILY_A 64
Cross section area of coil Z.

#define | COILZ_A 64
Cross section area of coil Z.

Enumerations

enum | Coils { CoilAll, CoilX, CoilY, CoilZ }
Coil selection. More...

Functions

void | init_coils (void)
Initialize coils.

void | enable_coil (Coils coil)
Enable coil.

void | disable_coil (Coils coil)
Disable coil.

void | set_duty (uint8_t duty_cycle, uint8_t direction, Coils coil)
Set duty cycle and direction.

Define Documentation

#define COILX_A 64

Cross section area of coil X.

Definition at line 77 of file coildriver.h.

#define COILX_DIR_PIN PD7

Direction pin for coil X.

Definition at line 53 of file coildriver.h.

Referenced by init_coils(), and set_duty().

#define COILX_DIR_PORT PORTD

Direction pin port for coil X.

Definition at line 57 of file coildriver.h.

Referenced by init_coils(), and set_duty().

#define COILX_ENABLE_PIN PB2

Enable pin for coil X.

Definition at line 43 of file coildriver.h.

Referenced by disable_coil(), enable_coil(), and init_coils().

#define COILX_ENABLE_PORT PORTB

Enable pin port for coil X.

Definition at line 47 of file coildriver.h.

Referenced by disable_coil(), enable_coil(), and init_coils().

#define COILX_N 120

Number of windings in coil X.

Definition at line 73 of file coildriver.h.

#define COILX_PWM_PIN PD4

PWM pin for coil X.

Definition at line 35 of file coildriver.h.

Referenced by init_coils().

#define COILX_PWM_PORT PORTD

Port used for coil X PWM pin.

Definition at line 39 of file coildriver.h.

#define COILY_A 64

Cross section area of coil Z.

Definition at line 78 of file coildriver.h.

#define COILY_DIR_PIN PD6

Direction pin for coil Y.

Definition at line 54 of file coildriver.h.

Referenced by init_coils(), and set_duty().

#define COILY_DIR_PORT PORTD

Direction pin port for coil Y.

Definition at line 58 of file coildriver.h.

Referenced by init_coils(), and set_duty().

#define COILY_ENABLE_PIN PB1

Enable pin for coil Y.

Definition at line 44 of file coildriver.h.

Referenced by disable_coil(), enable_coil(), and init_coils().

#define COILY_ENABLE_PORT PORTB

Enable pin port for coil Y.

Definition at line 48 of file coildriver.h.

Referenced by disable_coil(), enable_coil(), and init_coils().

#define COILY_N 120

Number of windings in coil Y.

Definition at line 74 of file coildriver.h.

#define COILY_PWM_PIN PD5

PWM pin for coil Y.

Definition at line 36 of file coildriver.h.

Referenced by init_coils().

#define COILY_PWM_PORT PORTD

Port used for coil Y PWM pin.

Definition at line 40 of file coildriver.h.

#define COILZ_A 64

Cross section area of coil Z.

Definition at line 79 of file coildriver.h.

#define COILZ_DIR_PIN PD3

Direction pin for coil Z.

Definition at line 55 of file coildriver.h.

Referenced by init_coils(), and set_duty().

#define COILZ_DIR_PORT PORTD

Direction pin portfor coil Z.

Definition at line 59 of file coildriver.h.

Referenced by init_coils(), and set_duty().

#define COILZ_ENABLE_PIN PB0

Enable pin for coil Z.

Definition at line 45 of file coildriver.h.

Referenced by disable_coil(), enable_coil(), and init_coils().

#define COILZ_ENABLE_PORT PORTB

Enable pin port for coil Z.

Definition at line 49 of file coildriver.h.

Referenced by disable_coil(), enable_coil(), and init_coils().

#define COILZ_N 120

Number of windings in coil Z.

Definition at line 75 of file coildriver.h.

#define COILZ_PWM_PIN PB3

PWM pin for coil Z.

Definition at line 37 of file coildriver.h.

Referenced by init_coils().

#define COILZ_PWM_PORT PORTB

Port used for coil Z PWM pin.

Definition at line 41 of file coildriver.h.

#define DIR_DDR DDRD

Definition at line 61 of file coildriver.h.

Referenced by init_coils().

#define ENABLE_DDR DDRB

Direction port for enable pins.

Definition at line 51 of file coildriver.h.

Referenced by init_coils().

Enumeration Type Documentation

enum Coils

Coil selection.

Used for coil selection.

Enumeration values:
CoilAll | Select all.
CoilX | Select coil X.
CoilY | Select coil Y.
CoilZ | Select coil Z.

Definition at line 87 of file coildriver.h.

Function Documentation

void disable_coil ( Coils coil )

Disable coil.

Disconnect one or all PWM channels from their assgined OCn pin and clear ENABLE.

Parameters:
coil Coil.

Definition at line 66 of file coildriver.c.

References clear_bit, CoilAll, CoilX, COILX_ENABLE_PIN, COILX_ENABLE_PORT, CoilY, COILY_ENABLE_PIN, COILY_ENABLE_PORT, CoilZ, COILZ_ENABLE_PIN, and COILZ_ENABLE_PORT.

Referenced by doDetumblingState(), handle_command(), and setCoilDuty().

void enable_coil ( Coils coil )

Enable coil.

Connect one or all PWM channels to their assigned OCn pin. ENABLE signal is set.

Parameters:
coil Coil.

Definition at line 40 of file coildriver.c.

References CoilAll, CoilX, COILX_ENABLE_PIN, COILX_ENABLE_PORT, CoilY, COILY_ENABLE_PIN, COILY_ENABLE_PORT, CoilZ, COILZ_ENABLE_PIN, COILZ_ENABLE_PORT, and set_bit.

Referenced by doDetumblingState(), and setCoilDuty().

void init_coils ( void )

Initialize coils.

Initialize control pins and PWM channels.

Note:
PWM output pins are not connected. ENABLE and DIRECTION pins are set low.

Definition at line 15 of file coildriver.c.

References clear_bit, COILX_DIR_PIN, COILX_DIR_PORT, COILX_ENABLE_PIN, COILX_ENABLE_PORT, COILX_PWM_PIN, COILY_DIR_PIN, COILY_DIR_PORT, COILY_ENABLE_PIN, COILY_ENABLE_PORT, COILY_PWM_PIN, COILZ_DIR_PIN, COILZ_DIR_PORT, COILZ_ENABLE_PIN, COILZ_ENABLE_PORT, COILZ_PWM_PIN, DIR_DDR, and ENABLE_DDR.

Referenced by init_adcs().

void set_duty | ( | uint8_t | duty_cycle,
 |  | uint8_t | direction,
 |  | Coils | coil
 | ) |

Set duty cycle and direction.

Parameters:
duty_cycle | On time. Ranging from 0 (0%) to 255 (100%)
direction | Direction of current in coil.
coil | Coil.

Definition at line 93 of file coildriver.c.

References assign_bit, CoilAll, CoilX, COILX_DIR_PIN, COILX_DIR_PORT, COILX_DUTY_REG, CoilY, COILY_DIR_PIN, COILY_DIR_PORT, COILY_DUTY_REG, CoilZ, COILZ_DIR_PIN, COILZ_DIR_PORT, and COILZ_DUTY_REG.

Referenced by doDetumblingState(), handle_command(), and setDutyParams().

Generated on Fri Sep 3 17:21:15 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: debugutils.c File Reference

debugutils.c File Reference

Detailed Description

Implementation of various debug utilities.

Author:
Kjell Magne Fauske

Definition in file debugutils.c.

#include "debugutils.h"
#include "adcshdr.h"
#include <stdlib.h>
#include "iouart.h"

Go to the source code of this file.

Functions

void | print_state (uint8_t state)
Print logical value.

int | read_int (void)
Read an integer from UART.

void | print_buf (char *buf)
void | print_int (uint16_t i)
Print an integer throug the UART.

void | debug_P (PGM_P addr)
Print a string stored in FLASH memory.

void | putline_P (PGM_P addr)
Print a string stored in FLASH and append a newline char.

void | put_P (PGM_P addr)
Print a string stored in FLASH.

Function Documentation

void debug_P ( PGM_P addr )

Print a string stored in FLASH memory.

Parameters:
addr pointer to string stored in flash.
Example:
 debug_P(PSTR("This is a string in FLASH\n"));

Definition at line 68 of file debugutils.c.

References uart_putchar_n().

Referenced by print_state(), put_P(), and putline_P().

void print_buf ( char * buf )

Definition at line 51 of file debugutils.c.

References uart_putchar_n().

Referenced by print_int().

void print_int ( uint16_t i )

Print an integer throug the UART.

Definition at line 62 of file debugutils.c.

void print_state ( uint8_t state )

Print logical value.

Prints LOW if input value is 0. Prints HIGH otherwise.

Parameters:
state State variable

Definition at line 14 of file debugutils.c.

References debug_P().

void put_P ( PGM_P addr )

Print a string stored in FLASH.

Parameters:
addr Pointer to string stored in flash. See debug_P() for an example.

Definition at line 80 of file debugutils.c.

References debug_P().

void putline_P ( PGM_P addr )

Print a string stored in FLASH and append a newline char.

Parameters:
addr Pointer to string stored in flash. See debug_P() for an example.

Definition at line 75 of file debugutils.c.

References debug_P(), and uart_putchar_n().

int read_int ( void )

Read an integer from UART.

Read a number from UART. Number is entered as a string, then converted. A CR char is used to indicate end of number.

Returns:
An interger.

Definition at line 31 of file debugutils.c.

References uart_getchar(), and uart_putchar().

Generated on Fri Sep 3 17:21:15 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: debugutils.h File Reference

debugutils.h File Reference

Detailed Description

Various utility functions for reading and printing data for debugging.

Changes:

  • 2003-01-10 File created
  • 2003-01-11 sdfsdf

Author:
Kjell Magne Fauske

Definition in file debugutils.h.

#include "adcshdr.h"
#include <avr/pgmspace.h>

Go to the source code of this file.

Functions

int | read_int (void)
Read an integer from UART.

void | print_state (uint8_t state)
Print logical value.

void | print_buf (char *buf)
void | print_int (uint16_t i)
Print an integer throug the UART.

void | debug_P (PGM_P addr)
Print a string stored in FLASH memory.

void | putline_P (PGM_P addr)
Print a string stored in FLASH and append a newline char.

void | put_P (PGM_P addr)
Print a string stored in FLASH.

Function Documentation

void debug_P ( PGM_P addr )

Print a string stored in FLASH memory.

Parameters:
addr pointer to string stored in flash.
Example:
 debug_P(PSTR("This is a string in FLASH\n"));

Definition at line 68 of file debugutils.c.

References uart_putchar_n().

Referenced by print_state(), put_P(), and putline_P().

void print_buf ( char * buf )

Definition at line 51 of file debugutils.c.

References uart_putchar_n().

Referenced by print_int().

void print_int ( uint16_t i )

Print an integer throug the UART.

Definition at line 62 of file debugutils.c.

References print_buf(), tnc_newline, and tnc_put().

Referenced by get_parameter(), print_sint(), and setCoilDuty().

void print_state ( uint8_t state )

Print logical value.

Prints LOW if input value is 0. Prints HIGH otherwise.

Parameters:
state State variable

Definition at line 14 of file debugutils.c.

References debug_P().

void put_P ( PGM_P addr )

Print a string stored in FLASH.

Parameters:
addr Pointer to string stored in flash. See debug_P() for an example.

Definition at line 80 of file debugutils.c.

References debug_P().

void putline_P ( PGM_P addr )

Print a string stored in FLASH and append a newline char.

Parameters:
addr Pointer to string stored in flash. See debug_P() for an example.

Definition at line 75 of file debugutils.c.

References debug_P(), and uart_putchar_n().

int read_int ( void )

Read an integer from UART.

Read a number from UART. Number is entered as a string, then converted. A CR char is used to indicate end of number.

Returns:
An interger.

Definition at line 31 of file debugutils.c.

References uart_getchar(), and uart_putchar().

Generated on Fri Sep 3 17:21:15 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: eevars.c File Reference

eevars.c File Reference

Detailed Description

Definition in file eevars.c.

#include "eevars.h"
#include <avr/eeprom.h>
#include "adcshdr.h"

Go to the source code of this file.

Variables

const uint8_t EE_eeprom_signature | EEPROM = EEPROM_SIGNATURE
Minutes to wait before detumbling or measure state.

uint8_t | eeprom_programmed
Set if the internal eeprom is programmed.

const int16_t EEPROM | EE_k_xy_n = 0
const int16_t EEPROM | EE_k_xy_d = 0
const int16_t EEPROM | EE_k_z_n = 0
const int16_t EEPROM | EE_k_z_d = 0
const int16_t EEPROM | EE_mc_z = 50
const uint16_t EEPROM | EE_bdot_min = 10
const uint16_t EEPROM | EE_m_max = 255
const uint8_t EEPROM | EE_dtmbl_logdata_reg = 0x0F
const uint8_t EEPROM | EE_dtmbl_logtimestep = 4
const uint16_t | EE_measure_period = 500
MS to measure.

const uint16_t | EE_actuate_period = 500
MS to actuate.

const uint16_t | EE_magdelay_period = 500
MS to wait after actuate period.

Variable Documentation

const uint16_t EE_actuate_period = 500

MS to actuate.

Definition at line 41 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const uint16_t EEPROM EE_bdot_min = 10

Definition at line 35 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const uint8_t EEPROM EE_dtmbl_logdata_reg = 0x0F

Definition at line 37 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const uint8_t EEPROM EE_dtmbl_logtimestep = 4

Definition at line 38 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const int16_t EEPROM EE_k_xy_d = 0

Definition at line 30 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const int16_t EEPROM EE_k_xy_n = 0

Definition at line 29 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const int16_t EEPROM EE_k_z_d = 0

Definition at line 32 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const int16_t EEPROM EE_k_z_n = 0

Definition at line 31 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const uint16_t EEPROM EE_m_max = 255

Definition at line 36 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const uint16_t EE_magdelay_period = 500

MS to wait after actuate period.

Definition at line 42 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const int16_t EEPROM EE_mc_z = 50

Definition at line 33 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const uint16_t EE_measure_period = 500

MS to measure.

Definition at line 40 of file eevars.c.

Referenced by getParamAddr(), and init_detumbling().

const uint8_t EE_mag_notinitialized EEPROM = EEPROM_SIGNATURE

Minutes to wait before detumbling or measure state.

Warning:
Internal EEPROM must be initialized when program is downloaded. Otherwise value will be non-zero.

Definition at line 24 of file eevars.c.

uint8_t eeprom_programmed

Set if the internal eeprom is programmed.

The variable is set during ADCS initalization in init_adcs()

Definition at line 11 of file eevars.c.

Referenced by init_adcs(), and init_logging().

Generated on Fri Sep 3 17:21:15 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: eevars.h File Reference

eevars.h File Reference

Detailed Description

Definition of variables stored in eeprom.

Can be changed using the SET_PARAMETER_CMD tele command.

Definition in file eevars.h.

#include "adcshdr.h"

Go to the source code of this file.

Controller parameters

Various parameters are available for tuning the detumbling controller.

Warning:
Make sure the parameters are properly initialized before starting detumbling.

const int16_t | EE_k_xy_n
const int16_t | EE_k_xy_d
const int16_t | EE_k_z_n
const int16_t | EE_k_z_d
const int16_t | EE_mc_z
const uint16_t | EE_bdot_min
const uint16_t | EE_m_max
const uint16_t | EE_measure_period
MS to measure.

const uint16_t | EE_actuate_period
MS to actuate.

const uint16_t | EE_magdelay_period
MS to wait after actuate period.

Logging parameters

Which data to log, and how often, during detumbling

const uint8_t | EE_dtmbl_logdata_reg
const uint8_t | EE_dtmbl_logtimestep

Variables

const uint8_t | EE_eeprom_signature
Signature used to check that the eeprom has been programmed.

uint8_t | eeprom_programmed
Set if the internal eeprom is programmed.

const uint8_t | EE_mag_sampling_rate
Magnetometer sample rate.

const uint8_t | EE_mag_notinitialized
Cleared if magnetometer has been properly initialized for detumbling.

const uint8_t | EE_waitstate_delay
Minutes to wait before detumbling or measure state.

Variable Documentation

const uint16_t EE_actuate_period

MS to actuate.

Definition at line 63 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const uint16_t EE_bdot_min

Definition at line 59 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const uint8_t EE_dtmbl_logdata_reg

Definition at line 74 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const uint8_t EE_dtmbl_logtimestep

Definition at line 75 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const uint8_t EE_eeprom_signature

Signature used to check that the eeprom has been programmed.

The signature is set to EEPROM_SIGNATURE.

Note:
When the AVR is programmed the internal eeprom is often wiped out and filled with 0xFF. When compiling with avr-gcc a separate eep file is created which can be downloaded to the mcu.

Definition at line 23 of file eevars.h.

Referenced by init_adcs().

const int16_t EE_k_xy_d

Definition at line 54 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const int16_t EE_k_xy_n

Definition at line 53 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const int16_t EE_k_z_d

Definition at line 56 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const int16_t EE_k_z_n

Definition at line 55 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const uint16_t EE_m_max

Definition at line 60 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const uint8_t EE_mag_notinitialized

Cleared if magnetometer has been properly initialized for detumbling.

Definition at line 39 of file eevars.h.

const uint8_t EE_mag_sampling_rate

Magnetometer sample rate.

Sampling rate can be set to 10, 20, 25, 30, 40, 50, 60, 100, 123 or 154 samples/sec.

Definition at line 37 of file eevars.h.

Referenced by getParamAddr().

const uint16_t EE_magdelay_period

MS to wait after actuate period.

Definition at line 64 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const int16_t EE_mc_z

Definition at line 57 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const uint16_t EE_measure_period

MS to measure.

Definition at line 62 of file eevars.h.

Referenced by getParamAddr(), and init_detumbling().

const uint8_t EE_waitstate_delay

Minutes to wait before detumbling or measure state.

Definition at line 40 of file eevars.h.

Referenced by doWaitState(), and getParamAddr().

uint8_t eeprom_programmed

Set if the internal eeprom is programmed.

The variable is set during ADCS initalization in init_adcs()

Definition at line 30 of file eevars.h.

Referenced by init_adcs(), and init_logging().

Generated on Fri Sep 3 17:21:15 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: iouart.c File Reference

iouart.c File Reference

#include "iouart.h"
#include <avr/signal.h>
#include <avr/interrupt.h>
#include "avrutils.h"

Go to the source code of this file.

Defines

#define | RX_BUF_OVERFLOW 0
#define | TX_PRIMEDIT 1
#define | RX_BUFFER_SIZE 200
#define | TX_BUFFER_SIZE 100

Functions

SIGNAL (SIG_UART_RECV)
UART Receiver interrupt service routine.

SIGNAL (SIG_UART_TRANS)
UART transmit interrupt service routine.

uint8_t | uart_getchar (void)
Read a char from the UART receive buffer.

int | uart_putchar (char c)
Send a char to the UART.

void | uart_putchar_n (char c)
Put a char in the transmit buffer.

void | uart_init (uint16_t baud)
Initialize UART and set baud rate.

void | uart_flush_rxbuf (void)
Flush receive buffer.

void | uart_flush_txbuf (void)
Flush transmit buffer.

Variables

uint8_t volatile | BUF_SREG
Receive and transmit status register.

uint8_t | RX_Buffer [RX_BUFFER_SIZE+1]
Receive buffer.

uint8_t volatile | RX_Wr_Index
uint8_t volatile | RX_Rd_Index
uint8_t volatile | RX_Counter
uint8_t | TX_Buffer [TX_BUFFER_SIZE+1]
Transmit buffer.

uint8_t volatile | TX_Rd_Index
uint8_t volatile | TX_Wr_Index
uint8_t volatile | TX_Counter

Define Documentation

#define RX_BUF_OVERFLOW 0

Definition at line 12 of file iouart.c.

Referenced by SIGNAL().

#define RX_BUFFER_SIZE 200

Definition at line 16 of file iouart.c.

Referenced by SIGNAL(), and uart_getchar().

#define TX_BUFFER_SIZE 100

Definition at line 20 of file iouart.c.

Referenced by SIGNAL(), and uart_putchar().

#define TX_PRIMEDIT 1

Definition at line 13 of file iouart.c.

Referenced by SIGNAL(), and uart_putchar().

Function Documentation

SIGNAL ( SIG_UART_TRANS )

UART transmit interrupt service routine.

Definition at line 61 of file iouart.c.

References BUF_SREG, clear_bit, TX_Buffer, TX_BUFFER_SIZE, TX_Counter, TX_PRIMEDIT, and TX_Rd_Index.

SIGNAL ( SIG_UART_RECV )

UART Receiver interrupt service routine.

Definition at line 45 of file iouart.c.

References BUF_SREG, RX_BUF_OVERFLOW, RX_Buffer, RX_BUFFER_SIZE, RX_Counter, RX_Wr_Index, and set_bit.

void uart_flush_rxbuf ( void )

Flush receive buffer.

Set internal counters to zero.

Definition at line 144 of file iouart.c.

References disable_interrupts, enable_interrupts, RX_Counter, RX_Rd_Index, and RX_Wr_Index.

Referenced by doMagQuery(), doMeasuringState(), and mag_is_on().

void uart_flush_txbuf ( void )

Flush transmit buffer.

Set internal counters to zero.

Definition at line 154 of file iouart.c.

References disable_interrupts, enable_interrupts, TX_Counter, TX_Rd_Index, and TX_Wr_Index.

uint8_t uart_getchar ( void )

Read a char from the UART receive buffer.

If buffer is empty, wait for a char to arrive.

Returns:
Received character.

Definition at line 85 of file iouart.c.

References RX_Buffer, RX_BUFFER_SIZE, RX_Counter, and RX_Rd_Index.

Referenced by doMagQuery(), doVUartState(), mag_fill_meas_buffer(), and read_int().

void uart_init ( uint16_t baud )

Initialize UART and set baud rate.

The baud rate is set with the UBRR register. To calculate a the UBBR for a specific baud rate, use the formula:

 UBRR = f_osc/(16*BAUD)-1,
where f_osc is the system oscillator clock frequency and BAUD is the baud rade in bits per second, bps.

Parameters:
baud Value to store in the UBBR register.

Definition at line 134 of file iouart.c.

Referenced by init_magnetometer_comm().

int uart_putchar ( char c )

Send a char to the UART.

Put a char in the transmit buffer. If buffer is full, wait until ready.

Definition at line 102 of file iouart.c.

References BUF_SREG, set_bit, TX_Buffer, TX_BUFFER_SIZE, TX_Counter, TX_PRIMEDIT, and TX_Wr_Index.

Referenced by handle_command(), mag_send_command(), mag_send_command_N(), mag_send_command_P(), read_int(), and uart_putchar_n().

void uart_putchar_n ( char c )

Put a char in the transmit buffer.

Add a char after a
char.

Definition at line 123 of file iouart.c.

References uart_putchar().

Referenced by debug_P(), print_buf(), and putline_P().

Variable Documentation

uint8_t volatile BUF_SREG [static]

Receive and transmit status register.

Definition at line 23 of file iouart.c.

Referenced by SIGNAL(), and uart_putchar().

uint8_t RX_Buffer[RX_BUFFER_SIZE+1] [static]

Receive buffer.

Definition at line 29 of file iouart.c.

Referenced by SIGNAL(), and uart_getchar().

uint8_t volatile RX_Counter

Definition at line 32 of file iouart.c.

Referenced by doMagQuery(), doVUartState(), mag_is_on(), SIGNAL(), uart_flush_rxbuf(), and uart_getchar().

uint8_t volatile RX_Rd_Index [static]

Definition at line 31 of file iouart.c.

Referenced by uart_flush_rxbuf(), and uart_getchar().

uint8_t volatile RX_Wr_Index [static]

Definition at line 30 of file iouart.c.

Referenced by SIGNAL(), and uart_flush_rxbuf().

uint8_t TX_Buffer[TX_BUFFER_SIZE+1] [static]

Transmit buffer.

Definition at line 36 of file iouart.c.

Referenced by SIGNAL(), and uart_putchar().

uint8_t volatile TX_Counter [static]

Definition at line 39 of file iouart.c.

Referenced by SIGNAL(), uart_flush_txbuf(), and uart_putchar().

uint8_t volatile TX_Rd_Index [static]

Definition at line 37 of file iouart.c.

Referenced by SIGNAL(), and uart_flush_txbuf().

uint8_t volatile TX_Wr_Index [static]

Definition at line 38 of file iouart.c.

Referenced by uart_flush_txbuf(), and uart_putchar().

Generated on Fri Sep 3 17:21:15 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: iouart.h File Reference

iouart.h File Reference

Detailed Description

Interrupt driven and buffered UART communication.

Based on code from the book "Embedded C Programming and the Atmel AVR" by Barnett, Cox, & O'Cull.

Note:
Interrupts must be enabled for code to work.

Definition in file iouart.h.

#include <avr/io.h>
#include <inttypes.h>
#include <avr/pgmspace.h>

Go to the source code of this file.

Defines

#define | uart_disable_rx() UCSRB &= ~(1 << RXEN)
#define | uart_enable_rx() UCSRB |= (1 << RXEN)

Functions

int | uart_putchar (char c)
Send a char to the UART.

void | uart_putchar_n (char c)
Put a char in the transmit buffer.

uint8_t | uart_getchar (void)
Read a char from the UART receive buffer.

void | uart_init (uint16_t baud)
Initialize UART and set baud rate.

void | uart_flush_rxbuf (void)
Flush receive buffer.

void | uart_flush_txbuf (void)
Flush transmit buffer.

Variables

uint8_t volatile | RX_Counter

Define Documentation

#define uart_disable_rx ( ) UCSRB &= ~(1 << RXEN)

Definition at line 18 of file iouart.h.

#define uart_enable_rx ( ) UCSRB |= (1 << RXEN)

Definition at line 19 of file iouart.h.

Function Documentation

void uart_flush_rxbuf ( void )

Flush receive buffer.

Set internal counters to zero.

Definition at line 144 of file iouart.c.

References disable_interrupts, enable_interrupts, RX_Counter, RX_Rd_Index, and RX_Wr_Index.

Referenced by doMagQuery(), doMeasuringState(), and mag_is_on().

void uart_flush_txbuf ( void )

Flush transmit buffer.

Set internal counters to zero.

Definition at line 154 of file iouart.c.

References disable_interrupts, enable_interrupts, TX_Counter, TX_Rd_Index, and TX_Wr_Index.

uint8_t uart_getchar ( void )

Read a char from the UART receive buffer.

If buffer is empty, wait for a char to arrive.

Returns:
Received character.

Definition at line 85 of file iouart.c.

References RX_Buffer, RX_BUFFER_SIZE, RX_Counter, and RX_Rd_Index.

Referenced by doMagQuery(), doVUartState(), mag_fill_meas_buffer(), and read_int().

void uart_init ( uint16_t baud )

Initialize UART and set baud rate.

The baud rate is set with the UBRR register. To calculate a the UBBR for a specific baud rate, use the formula:

 UBRR = f_osc/(16*BAUD)-1,
where f_osc is the system oscillator clock frequency and BAUD is the baud rade in bits per second, bps.

Parameters:
baud Value to store in the UBBR register.

Definition at line 134 of file iouart.c.

Referenced by init_magnetometer_comm().

int uart_putchar ( char c )

Send a char to the UART.

Put a char in the transmit buffer. If buffer is full, wait until ready.

Definition at line 102 of file iouart.c.

References BUF_SREG, set_bit, TX_Buffer, TX_BUFFER_SIZE, TX_Counter, TX_PRIMEDIT, and TX_Wr_Index.

Referenced by handle_command(), mag_send_command(), mag_send_command_N(), mag_send_command_P(), read_int(), and uart_putchar_n().

void uart_putchar_n ( char c )

Put a char in the transmit buffer.

Add a char after a
char.

Definition at line 123 of file iouart.c.

References uart_putchar().

Referenced by debug_P(), print_buf(), and putline_P().

Variable Documentation

uint8_t volatile RX_Counter

Definition at line 21 of file iouart.h.

Referenced by doMagQuery(), doVUartState(), mag_is_on(), SIGNAL(), uart_flush_rxbuf(), and uart_getchar().

Generated on Fri Sep 3 17:21:16 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: magnetometer.c File Reference

magnetometer.c File Reference

Detailed Description

Implementation of the magnetometer module.

Definition in file magnetometer.c.

#include "magnetometer.h"
#include "adcshdr.h"
#include "iouart.h"
#include "timingutils.h"
#include <avr/wdt.h>
#include <avr/eeprom.h>
#include "eevars.h"
#include "adcslog.h"

Go to the source code of this file.

Defines

#define | INPUT_RATE_DELAY 20
Input rate delay.

#define | MAG_BAUDRATE 9600
Baudrate for communication with magnetometer.

#define | MAG_TIMEOUT 200
Time in ms to wait for magnetometer to respond.

#define | MAG_MEAS_SIZE 7
Size of a single magnetometer reading in binary mode.

Functions

void | init_magnetometer_comm (void)
Initialize magnetometer communcication.

void | mag_send_command_N (char *cmd, uint8_t length)
Send a command string with a specific lenght to the magnetometer.

void | mag_send_command (char *cmd)
Send a command string to the magnetometer.

void | mag_send_command_P (PGM_P cmd_addr)
Send a command string stored in program memory to the magnetometer.

uint8_t | mag_fill_meas_buffer (uint8_t n)
Fill mag_buffer with n measurements.

uint8_t | mag_is_on (void)
Check that magnetometer is responding.

void | mag_set_detumbling_params (void)
Set magnetometer parameters for detumbling.

void | mag_set_param_P (PGM_P cmd_addr)
Set a parameter in the magnetometer.

Variables

uint8_t | mag_sampling_rate = 20
Magnetometer samplerate.

magMeasurement | mag_buffer [MAGBUF_SIZE]
Magnetometer measurements buffer.

magMeasurement volatile | Bdot
Current estimate of Bdot.

Define Documentation

#define INPUT_RATE_DELAY 20

Input rate delay.

The HMR2300 limits how fast the command bytes can be received, based on the sampling rate. The datasheet is somewhat unclear about this, but it seems like the maximum wait time necessary is 20msec.

Definition at line 25 of file magnetometer.c.

Referenced by mag_send_command(), mag_send_command_N(), and mag_send_command_P().

#define MAG_BAUDRATE 9600

Baudrate for communication with magnetometer.

Definition at line 28 of file magnetometer.c.

Referenced by init_magnetometer_comm().

#define MAG_MEAS_SIZE 7

Size of a single magnetometer reading in binary mode.

Definition at line 36 of file magnetometer.c.

Referenced by mag_fill_meas_buffer().

#define MAG_TIMEOUT 200

Time in ms to wait for magnetometer to respond.

Definition at line 33 of file magnetometer.c.

Referenced by mag_is_on().

Function Documentation

void init_magnetometer_comm ( void )

Initialize magnetometer communcication.

Enable UART and set correct baudrate.

Definition at line 48 of file magnetometer.c.

References F_CPU, MAG_BAUDRATE, mag_stop_stream, and uart_init().

Referenced by init_adcs().

uint8_t mag_fill_meas_buffer ( uint8_t n )

Fill mag_buffer with n measurements.

Todo:
Function will loop forever if magnetometer does not output data. A watchdog reset will then occur.

Definition at line 88 of file magnetometer.c.

References CR_CHAR, mag_buffer, MAG_MEAS_SIZE, MAGBUF_ERROR, magMeasurement::magX, magMeasurement::magY, magMeasurement::magZ, and uart_getchar().

Referenced by doDetumblingState(), and doMeasuringState().

uint8_t mag_is_on ( void )

Check that magnetometer is responding.

Sends a read device command and wait for a respons. Timeout after MAG_TIMEOUT ms.

Returns:
TRUE if magnetometer is responding. FALSE otherwise

Definition at line 135 of file magnetometer.c.

References disable_timeout(), enable_timeout(), mag_send_command_P(), MAG_TIMEOUT, MS_TIMER, RX_Counter, timed_out_ms, and uart_flush_rxbuf().

Referenced by doMeasuringState(), handle_command(), and init_detumbling().

void mag_send_command ( char * cmd )

Send a command string to the magnetometer.

A newline char is automatically added after the command.

Definition at line 65 of file magnetometer.c.

References CR_CHAR, DELAY_MS, INPUT_RATE_DELAY, and uart_putchar().

void mag_send_command_N | ( | char * | cmd,
 |  | uint8_t | length
 | ) |

Send a command string with a specific lenght to the magnetometer.

A newline char is added after the command.

Definition at line 55 of file magnetometer.c.

References CR_CHAR, DELAY_MS, INPUT_RATE_DELAY, and uart_putchar().

Referenced by handle_command().

void mag_send_command_P ( PGM_P cmd_addr )

Send a command string stored in program memory to the magnetometer.

A newline char is automatically added after the command.

Definition at line 73 of file magnetometer.c.

References CR_CHAR, DELAY_MS, INPUT_RATE_DELAY, and uart_putchar().

Referenced by doMagQuery(), doMeasuringState(), handle_command(), mag_is_on(), mag_set_detumbling_params(), and mag_set_param_P().

void mag_set_detumbling_params ( void )

Set magnetometer parameters for detumbling.

Definition at line 149 of file magnetometer.c.

References mag_sampling_rate, mag_send_command_P(), and mag_set_param_P().

Referenced by doMeasuringState(), and init_detumbling().

void mag_set_param_P ( PGM_P cmd_addr )

Set a parameter in the magnetometer.

Similar to mag_send_command(), but sends a *00WE write enable command first.

Parameters:
cmd_addr Address to parameter string stored in flash.

Definition at line 159 of file magnetometer.c.

References mag_send_command_P().

Referenced by mag_set_detumbling_params().

Variable Documentation

magMeasurement volatile Bdot

Current estimate of Bdot.

Definition at line 46 of file magnetometer.c.

Referenced by calcBdot(), doDetumblingState(), doMeasuringState(), log_data(), and sendStatus().

magMeasurement mag_buffer[MAGBUF_SIZE]

Magnetometer measurements buffer.

Holds the N last measurements from the magnetometer. Used for calclulating Bdot.

Definition at line 44 of file magnetometer.c.

Referenced by calcBdot(), doMeasuringState(), and mag_fill_meas_buffer().

uint8_t mag_sampling_rate = 20

Magnetometer samplerate.

Definition at line 41 of file magnetometer.c.

Referenced by calcBdot(), init_detumbling(), and mag_set_detumbling_params().

Generated on Fri Sep 3 17:21:16 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: magnetometer.h File Reference

magnetometer.h File Reference

Detailed Description

Interface to the HMR2300 Smart Digital Magnetometer from Honeywell Changes: - 2004-09-02 -- Magnetometer mappings are now correct.

Note:
Binary magnetometer readings are returned as 2's complement signed integers.

The SET pulse mode is used. See datasheet for details.

Definition in file magnetometer.h.

#include <inttypes.h>
#include <avr/pgmspace.h>

Go to the source code of this file.

Data Structures

struct | magMeasurement
A single magnetometer measurement. More...

Mapping macros

The x, y, z axes of the magnetometer are not the same as the body axes.

The MAG_X, MAG_Y, MAG_Z macros are defined to map magnetometer axes to body axes. Used in calcBdot().

#define | MAG_X magZ
Magnetometer x-axis to body x-axis mapping.

#define | MAG_Y magY
Magnetometer y-axis to body y-axis mapping.

#define | MAG_Z magX
Magnetometer z-axis to body z-axis mapping.

Defines

#define | ESC_CHAR 0x1B
Escape ascii code.

#define | CR_CHAR 0x0D
Carriace return ascii code.

#define | MAGBUF_SIZE 5
Maximum number of entries in measurement buffer.

#define | MAGBUF_ERROR 1
#define | mag_start_stream() mag_send_command_P(PSTR("*00C"))
Start continuous magnetometer reading.

#define | mag_stop_stream() uart_putchar(ESC_CHAR)
Stop magnetometer data stream.

Functions

void | init_magnetometer_comm (void)
Initialize magnetometer communcication.

void | mag_set_detumbling_params (void)
Set magnetometer parameters for detumbling.

void | mag_send_command (char *cmd)
Send a command string to the magnetometer.

void | mag_send_command_P (PGM_P cmd_addr)
Send a command string stored in program memory to the magnetometer.

void | mag_send_command_N (char *cmd, uint8_t length)
Send a command string with a specific lenght to the magnetometer.

uint8_t | mag_fill_meas_buffer (uint8_t n)
Fill mag_buffer with n measurements.

uint8_t | mag_is_on (void)
Check that magnetometer is responding.

void | mag_set_param_P (PGM_P cmd_addr)
Set a parameter in the magnetometer.

Variables

magMeasurement | mag_buffer [MAGBUF_SIZE]
Magnetometer measurements buffer.

magMeasurement volatile | Bdot
Current estimate of Bdot.

uint8_t | mag_sampling_rate
Magnetometer samplerate.

Define Documentation

#define CR_CHAR 0x0D

Carriace return ascii code.

Definition at line 21 of file magnetometer.h.

Referenced by doMagQuery(), mag_fill_meas_buffer(), mag_send_command(), mag_send_command_N(), and mag_send_command_P().

#define ESC_CHAR 0x1B

Escape ascii code.

Definition at line 20 of file magnetometer.h.

#define mag_start_stream ( ) mag_send_command_P(PSTR("*00C"))

Start continuous magnetometer reading.

Definition at line 136 of file magnetometer.h.

Referenced by doDetumblingState(), and doMeasuringState().

#define mag_stop_stream ( ) uart_putchar(ESC_CHAR)

Stop magnetometer data stream.

Stop continuous magnetometer reading by sending an ESC character.

Definition at line 142 of file magnetometer.h.

Referenced by doDetumblingState(), doMeasuringState(), handle_command(), and init_magnetometer_comm().

#define MAG_X magZ

Magnetometer x-axis to body x-axis mapping.

Definition at line 31 of file magnetometer.h.

#define MAG_Y magY

Magnetometer y-axis to body y-axis mapping.

Definition at line 32 of file magnetometer.h.

#define MAG_Z magX

Magnetometer z-axis to body z-axis mapping.

Definition at line 33 of file magnetometer.h.

#define MAGBUF_ERROR 1

Definition at line 36 of file magnetometer.h.

Referenced by mag_fill_meas_buffer().

#define MAGBUF_SIZE 5

Maximum number of entries in measurement buffer.

Definition at line 35 of file magnetometer.h.

Function Documentation

void init_magnetometer_comm ( void )

Initialize magnetometer communcication.

Enable UART and set correct baudrate.

Definition at line 48 of file magnetometer.c.

References F_CPU, MAG_BAUDRATE, mag_stop_stream, and uart_init().

Referenced by init_adcs().

uint8_t mag_fill_meas_buffer ( uint8_t n )

Fill mag_buffer with n measurements.

Todo:
Function will loop forever if magnetometer does not output data. A watchdog reset will then occur.

Definition at line 88 of file magnetometer.c.

References CR_CHAR, mag_buffer, MAG_MEAS_SIZE, MAGBUF_ERROR, magMeasurement::magX, magMeasurement::magY, magMeasurement::magZ, and uart_getchar().

Referenced by doDetumblingState(), and doMeasuringState().

uint8_t mag_is_on ( void )

Check that magnetometer is responding.

Sends a read device command and wait for a respons. Timeout after MAG_TIMEOUT ms.

Returns:
TRUE if magnetometer is responding. FALSE otherwise

Definition at line 135 of file magnetometer.c.

References disable_timeout(), enable_timeout(), mag_send_command_P(), MAG_TIMEOUT, MS_TIMER, RX_Counter, timed_out_ms, and uart_flush_rxbuf().

Referenced by doMeasuringState(), handle_command(), and init_detumbling().

void mag_send_command ( char * cmd )

Send a command string to the magnetometer.

A newline char is automatically added after the command.

Definition at line 65 of file magnetometer.c.

References CR_CHAR, DELAY_MS, INPUT_RATE_DELAY, and uart_putchar().

void mag_send_command_N | ( | char * | cmd,
 |  | uint8_t | length
 | ) |

Send a command string with a specific lenght to the magnetometer.

A newline char is added after the command.

Definition at line 55 of file magnetometer.c.

References CR_CHAR, DELAY_MS, INPUT_RATE_DELAY, and uart_putchar().

Referenced by handle_command().

void mag_send_command_P ( PGM_P cmd_addr )

Send a command string stored in program memory to the magnetometer.

A newline char is automatically added after the command.

Definition at line 73 of file magnetometer.c.

References CR_CHAR, DELAY_MS, INPUT_RATE_DELAY, and uart_putchar().

Referenced by doMagQuery(), doMeasuringState(), handle_command(), mag_is_on(), mag_set_detumbling_params(), and mag_set_param_P().

void mag_set_detumbling_params ( void )

Set magnetometer parameters for detumbling.

Definition at line 149 of file magnetometer.c.

References mag_sampling_rate, mag_send_command_P(), and mag_set_param_P().

Referenced by doMeasuringState(), and init_detumbling().

void mag_set_param_P ( PGM_P cmd_addr )

Set a parameter in the magnetometer.

Similar to mag_send_command(), but sends a *00WE write enable command first.

Parameters:
cmd_addr Address to parameter string stored in flash.

Definition at line 159 of file magnetometer.c.

References mag_send_command_P().

Referenced by mag_set_detumbling_params().

Variable Documentation

magMeasurement volatile Bdot

Current estimate of Bdot.

Definition at line 63 of file magnetometer.h.

Referenced by calcBdot(), doDetumblingState(), doMeasuringState(), log_data(), and sendStatus().

magMeasurement mag_buffer[MAGBUF_SIZE]

Magnetometer measurements buffer.

Holds the N last measurements from the magnetometer. Used for calclulating Bdot.

Definition at line 61 of file magnetometer.h.

Referenced by calcBdot(), doMeasuringState(), and mag_fill_meas_buffer().

uint8_t mag_sampling_rate

Magnetometer samplerate.

Definition at line 65 of file magnetometer.h.

Referenced by calcBdot(), init_detumbling(), and mag_set_detumbling_params().

Generated on Fri Sep 3 17:21:16 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: softi2c.h File Reference

softi2c.h File Reference

Detailed Description

Software driven TWI/I2c master interface.

Implementation of the I2C bus master protocol in software.

Note:
Original code by Chris efstathiou. The original implementation can be found at http://www.avrfreaks.com, in the Academy>User's projects section, under the name 'general peripheral drivers'.

Due to hardware problems, most of the I2C code by Chris Efstathiou has been replaced. Only the timing utilities remain

Changes:
  • 2004-06-06 -- Replaced most of original code
  • 2004-02-17 -- Updated pins to pcb layout.

Definition in file softi2c.h.

#include "adcshdr.h"

Go to the source code of this file.

Defines

#define | F_CPU 8000000L
The cpu clock frequency in Hertz.

#define | I2C_SDA_PORT C
The SDA port. Use capital letter (A,B,C,D... etc.).

#define | SDA_PIN 7
The SDA port pin.

#define | I2C_SCL_PORT C
The SDA port.Use capital letter (A,B,C,D... etc.).

#define | SCL_PIN 6
The SCL port pin.

#define | I2C_CLOCK_IN_HERTZ 50000
I2C clock in Hertz.

#define | I2C_NUMBER_OF_START_ATTEMPTS 10
Number of attempts to issue a succesfull start condition.

#define | I2C_RETRIES 5

Functions

unsigned char | Soft_I2C_Write (unsigned char addr, unsigned char verdi)

Define Documentation

#define F_CPU 8000000L

The cpu clock frequency in Hertz.

Definition at line 43 of file softi2c.h.

#define I2C_CLOCK_IN_HERTZ 50000

I2C clock in Hertz.

Definition at line 59 of file softi2c.h.

#define I2C_NUMBER_OF_START_ATTEMPTS 10

Number of attempts to issue a succesfull start condition.

Definition at line 63 of file softi2c.h.

#define I2C_RETRIES 5

Definition at line 70 of file softi2c.h.

#define I2C_SCL_PORT C

The SDA port.Use capital letter (A,B,C,D... etc.).

Definition at line 53 of file softi2c.h.

#define I2C_SDA_PORT C

The SDA port. Use capital letter (A,B,C,D... etc.).

Definition at line 47 of file softi2c.h.

#define SCL_PIN 6

The SCL port pin.

Definition at line 56 of file softi2c.h.

#define SDA_PIN 7

The SDA port pin.

Definition at line 50 of file softi2c.h.

Function Documentation

unsigned char Soft_I2C_Write | ( | unsigned char | addr,
 |  | unsigned char | verdi
 | ) |

Referenced by transmit_12c_buffer().

Generated on Fri Sep 3 17:21:16 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: SPIeeprom.c File Reference

SPIeeprom.c File Reference

Detailed Description

Implementation of M95128E2PROM interface.

Author:
Eysten Sæther

Definition in file SPIeeprom.c.

#include <avr/io.h>
#include "SPIeeprom.h"
#include "avrutils.h"
#include <avr/signal.h>

Go to the source code of this file.

Defines

#define | EXT_EEPROM_PAGE_MASK (EXT_EEPROM_PAGE_SIZE-1)
#define | SPI_SS PB4
#define | SPI_MOSI PB5
#define | SPI_MISO PB6
#define | SPI_SCK PB7
#define | EXT_EE_WREN 0x06
#define | EXT_EE_WRDI 0x04
#define | EXT_EE_RDSR 0x05
#define | EXT_EE_WRSR 0x01
#define | EXT_EE_READ 0x03
#define | EXT_EE_WRITE 0x02
#define | EXT_EE_WIP 0x01

Functions

uint8_t | ReadStatusExtEeprom (void)
void | EnableWriteExtEeprom (void)
uint8_t | ExtEepromWriteReady (void)
void | WriteStatusExtEeprom (uint8_t status)
void | EepromSelect (void)
void | EepromDeselect (void)
void | Init_SPI (uint8_t prescale)
uint8_t | ReadByteExtEeprom (uint16_t addr)
void | ReadPageExtEeprom (uint16_t addr)
void | WriteByteExtEeprom (uint16_t addr, uint8_t data)
void | WritePageExtEeprom (uint16_t addr, uint8_t *page, uint8_t pagesize, uint8_t firstpage)
SIGNAL (SIG_SPI)

Variables

uint8_t volatile | SPIState = 0
uint8_t | SPIBuf [EXT_EEPROM_PAGE_SIZE+3]
uint8_t volatile | SPIBufSize = 0
uint8_t volatile | SPIBufPos = 0
uint16_t volatile | CSEWaddr = 0

Define Documentation

#define EXT_EE_RDSR 0x05

Definition at line 23 of file SPIeeprom.c.

Referenced by ReadStatusExtEeprom().

#define EXT_EE_READ 0x03

Definition at line 25 of file SPIeeprom.c.

Referenced by ReadByteExtEeprom(), and ReadPageExtEeprom().

#define EXT_EE_WIP 0x01

Definition at line 29 of file SPIeeprom.c.

Referenced by ExtEepromWriteReady().

#define EXT_EE_WRDI 0x04

Definition at line 22 of file SPIeeprom.c.

#define EXT_EE_WREN 0x06

Definition at line 21 of file SPIeeprom.c.

Referenced by EnableWriteExtEeprom().

#define EXT_EE_WRITE 0x02

Definition at line 26 of file SPIeeprom.c.

Referenced by WriteByteExtEeprom(), and WritePageExtEeprom().

#define EXT_EE_WRSR 0x01

Definition at line 24 of file SPIeeprom.c.

Referenced by WriteStatusExtEeprom().

#define EXT_EEPROM_PAGE_MASK (EXT_EEPROM_PAGE_SIZE-1)

Definition at line 14 of file SPIeeprom.c.

Referenced by SIGNAL().

#define SPI_MISO PB6

Definition at line 17 of file SPIeeprom.c.

Referenced by Init_SPI().

#define SPI_MOSI PB5

Definition at line 16 of file SPIeeprom.c.

Referenced by Init_SPI().

#define SPI_SCK PB7

Definition at line 18 of file SPIeeprom.c.

Referenced by Init_SPI().

#define SPI_SS PB4

Definition at line 15 of file SPIeeprom.c.

Referenced by EepromDeselect(), EepromSelect(), and Init_SPI().

Function Documentation

void EepromDeselect ( void )

Definition at line 178 of file SPIeeprom.c.

References SPI_SS.

Referenced by EnableWriteExtEeprom(), Init_SPI(), ReadByteExtEeprom(), ReadStatusExtEeprom(), SIGNAL(), WriteByteExtEeprom(), and WriteStatusExtEeprom().

void EepromSelect ( void )

Definition at line 174 of file SPIeeprom.c.

References SPI_SS.

Referenced by EnableWriteExtEeprom(), ReadByteExtEeprom(), ReadPageExtEeprom(), and ReadStatusExtEeprom().

void EnableWriteExtEeprom ( void )

Definition at line 105 of file SPIeeprom.c.

References _NOP, EepromDeselect(), EepromSelect(), and EXT_EE_WREN.

Referenced by WriteByteExtEeprom(), WritePageExtEeprom(), and WriteStatusExtEeprom().

uint8_t ExtEepromWriteReady ( void )

Definition at line 116 of file SPIeeprom.c.

References EXT_EE_WIP, FALSE, ReadStatusExtEeprom(), and TRUE.

Referenced by WriteByteExtEeprom(), and WritePageExtEeprom().

void Init_SPI ( uint8_t prescale )

Definition at line 46 of file SPIeeprom.c.

References EepromDeselect(), SPI_IDLE, SPI_MISO, SPI_MOSI, SPI_SCK, SPI_SS, and SPIState.

Referenced by init_adcs().

uint8_t ReadByteExtEeprom ( uint16_t addr )

Definition at line 57 of file SPIeeprom.c.

References EepromDeselect(), EepromSelect(), EXT_EE_READ, SPI_IDLE, and SPIState.

void ReadPageExtEeprom ( uint16_t addr )

Definition at line 75 of file SPIeeprom.c.

References EepromSelect(), EXT_EE_READ, SPI_IDLE, SPI_READ, SPIBufPos, SPIBufSize, and SPIState.

Referenced by SendELog(), and StartSendELog().

uint8_t ReadStatusExtEeprom ( void )

Definition at line 93 of file SPIeeprom.c.

References EepromDeselect(), EepromSelect(), EXT_EE_RDSR, SPI_IDLE, and SPIState.

Referenced by ExtEepromWriteReady().

SIGNAL ( SIG_SPI )

Definition at line 183 of file SPIeeprom.c.

References CSEWaddr, EepromDeselect(), EXT_EEPROM_PAGE_MASK, EXT_EEPROM_PAGE_SIZE, SPI_DONE_READ, SPI_IDLE, SPI_READ, SPI_WRITE, SPIBuf, SPIBufPos, SPIBufSize, SPIState, and WritePageExtEeprom().

void WriteByteExtEeprom | ( | uint16_t | addr,
 |  | uint8_t | data
 | ) |

Definition at line 121 of file SPIeeprom.c.

References EepromDeselect(), EnableWriteExtEeprom(), EXT_EE_WRITE, ExtEepromWriteReady(), SPI_IDLE, and SPIState.

void WritePageExtEeprom | ( | uint16_t | addr,
 |  | uint8_t * | page,
 |  | uint8_t | pagesize,
 |  | uint8_t | firstpage
 | ) |

Definition at line 136 of file SPIeeprom.c.

References CSEWaddr, EnableWriteExtEeprom(), EXT_EE_WRITE, ExtEepromWriteReady(), SPI_IDLE, SPI_WRITE, SPIBuf, SPIBufPos, SPIBufSize, and SPIState.

Referenced by SIGNAL(), and store_log_exteeprom().

void WriteStatusExtEeprom ( uint8_t status )

Definition at line 163 of file SPIeeprom.c.

References EepromDeselect(), EnableWriteExtEeprom(), EXT_EE_WRSR, SPI_IDLE, and SPIState.

Variable Documentation

uint16_t volatile CSEWaddr = 0

Definition at line 35 of file SPIeeprom.c.

Referenced by SIGNAL(), and WritePageExtEeprom().

uint8_t SPIBuf[EXT_EEPROM_PAGE_SIZE+3]

Definition at line 32 of file SPIeeprom.c.

Referenced by SendELog(), SIGNAL(), and WritePageExtEeprom().

uint8_t volatile SPIBufPos = 0

Definition at line 34 of file SPIeeprom.c.

Referenced by ReadPageExtEeprom(), SIGNAL(), and WritePageExtEeprom().

uint8_t volatile SPIBufSize = 0

Definition at line 33 of file SPIeeprom.c.

Referenced by ReadPageExtEeprom(), SIGNAL(), and WritePageExtEeprom().

uint8_t volatile SPIState = 0

Definition at line 31 of file SPIeeprom.c.

Referenced by doDownloadState(), Init_SPI(), ReadByteExtEeprom(), ReadPageExtEeprom(), ReadStatusExtEeprom(), SendELog(), SIGNAL(), WriteByteExtEeprom(), WritePageExtEeprom(), and WriteStatusExtEeprom().

Generated on Fri Sep 3 17:21:16 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: SPIeeprom.h File Reference

SPIeeprom.h File Reference

#include <inttypes.h>

Go to the source code of this file.

Defines

#define | EXT_EEPROM_SIZE 0x4000
#define | EXT_EEPROM_PAGE_SIZE 0x0040
#define | SPI_IDLE 0x01
#define | SPI_WRITE 0x02
#define | SPI_READ 0x04
#define | SPI_DONE_READ 0x08
#define | xeeprom_write_byte(addr, data) WriteByteExtEeprom(addr, data)
#define | xeeprom_read_byte(addr) ReadByteExtEeprom(addr)
#define | xeeprom_write_page(addr, page, pagesize, firstpage) WritePageExtEeprom(addr, page, pagesize, firstpage)
#define | xeeprom_read_page(addr) ReadPageExtEeprom(addr)

Functions

void | Init_SPI (uint8_t prescale)
uint8_t | ReadByteExtEeprom (uint16_t addr)
void | ReadPageExtEeprom (uint16_t addr)
void | WriteByteExtEeprom (uint16_t addr, uint8_t data)
void | WritePageExtEeprom (uint16_t addr, uint8_t *page, uint8_t pagesize, uint8_t firstpage)

Variables

uint8_t volatile | SPIState
uint8_t | SPIBuf [EXT_EEPROM_PAGE_SIZE+3]
uint8_t volatile | SPIBufSize
uint8_t volatile | SPIBufPos

Define Documentation

#define EXT_EEPROM_PAGE_SIZE 0x0040

Definition at line 20 of file SPIeeprom.h.

Referenced by SIGNAL().

#define EXT_EEPROM_SIZE 0x4000

Definition at line 19 of file SPIeeprom.h.

Referenced by SendELog(), and store_log_exteeprom().

#define SPI_DONE_READ 0x08

Definition at line 26 of file SPIeeprom.h.

Referenced by doDownloadState(), SendELog(), and SIGNAL().

#define SPI_IDLE 0x01

Definition at line 23 of file SPIeeprom.h.

Referenced by Init_SPI(), ReadByteExtEeprom(), ReadPageExtEeprom(), ReadStatusExtEeprom(), SendELog(), SIGNAL(), WriteByteExtEeprom(), WritePageExtEeprom(), and WriteStatusExtEeprom().

#define SPI_READ 0x04

Definition at line 25 of file SPIeeprom.h.

Referenced by ReadPageExtEeprom(), and SIGNAL().

#define SPI_WRITE 0x02

Definition at line 24 of file SPIeeprom.h.

Referenced by SIGNAL(), and WritePageExtEeprom().

#define xeeprom_read_byte ( addr ) ReadByteExtEeprom(addr)

Definition at line 42 of file SPIeeprom.h.

#define xeeprom_read_page ( addr ) ReadPageExtEeprom(addr)

Definition at line 44 of file SPIeeprom.h.

#define xeeprom_write_byte | ( | addr,
 |  | data | ) | WriteByteExtEeprom(addr, data)

Definition at line 41 of file SPIeeprom.h.

#define xeeprom_write_page | ( | addr,
 |  | page,
 |  | pagesize,
 |  | firstpage | ) | WritePageExtEeprom(addr, page, pagesize, firstpage)

Definition at line 43 of file SPIeeprom.h.

Function Documentation

void Init_SPI ( uint8_t prescale )

Definition at line 46 of file SPIeeprom.c.

References EepromDeselect(), SPI_IDLE, SPI_MISO, SPI_MOSI, SPI_SCK, SPI_SS, and SPIState.

Referenced by init_adcs().

uint8_t ReadByteExtEeprom ( uint16_t addr )

Definition at line 57 of file SPIeeprom.c.

References EepromDeselect(), EepromSelect(), EXT_EE_READ, SPI_IDLE, and SPIState.

void ReadPageExtEeprom ( uint16_t addr )

Definition at line 75 of file SPIeeprom.c.

References EepromSelect(), EXT_EE_READ, SPI_IDLE, SPI_READ, SPIBufPos, SPIBufSize, and SPIState.

Referenced by SendELog(), and StartSendELog().

void WriteByteExtEeprom | ( | uint16_t | addr,
 |  | uint8_t | data
 | ) |

Definition at line 121 of file SPIeeprom.c.

References EepromDeselect(), EnableWriteExtEeprom(), EXT_EE_WRITE, ExtEepromWriteReady(), SPI_IDLE, and SPIState.

void WritePageExtEeprom | ( | uint16_t | addr,
 |  | uint8_t * | page,
 |  | uint8_t | pagesize,
 |  | uint8_t | firstpage
 | ) |

Definition at line 136 of file SPIeeprom.c.

References CSEWaddr, EnableWriteExtEeprom(), EXT_EE_WRITE, ExtEepromWriteReady(), SPI_IDLE, SPI_WRITE, SPIBuf, SPIBufPos, SPIBufSize, and SPIState.

Referenced by SIGNAL(), and store_log_exteeprom().

Variable Documentation

uint8_t SPIBuf[EXT_EEPROM_PAGE_SIZE+3]

Definition at line 29 of file SPIeeprom.h.

Referenced by SendELog(), SIGNAL(), and WritePageExtEeprom().

uint8_t volatile SPIBufPos

Definition at line 31 of file SPIeeprom.h.

Referenced by ReadPageExtEeprom(), SIGNAL(), and WritePageExtEeprom().

uint8_t volatile SPIBufSize

Definition at line 30 of file SPIeeprom.h.

Referenced by ReadPageExtEeprom(), SIGNAL(), and WritePageExtEeprom().

uint8_t volatile SPIState

Definition at line 28 of file SPIeeprom.h.

Referenced by doDownloadState(), Init_SPI(), ReadByteExtEeprom(), ReadPageExtEeprom(), ReadStatusExtEeprom(), SendELog(), SIGNAL(), WriteByteExtEeprom(), WritePageExtEeprom(), and WriteStatusExtEeprom().

Generated on Fri Sep 3 17:21:16 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: sunsensors.c File Reference

sunsensors.c File Reference

Detailed Description

Implementation of the sun sensor interface.

Definition in file sunsensors.c.

#include "sunsensors.h"
#include <avr/signal.h>
#include <avr/interrupt.h>

Go to the source code of this file.

Functions

void | initSunsensors (void)
Initialize ADC.

void | sampleSunsensors (void)
Sample sun sensors.

Variables

uint8_t | sun_measurements [SUN_SENSORS]
Sun measurements storage.

uint8_t volatile | adc_finished

Function Documentation

void initSunsensors ( void )

Initialize ADC.

Definition at line 12 of file sunsensors.c.

Referenced by init_detumbling().

void sampleSunsensors ( void )

Sample sun sensors.

Wait until all sun sensors have been sampled. Results are stored in sun_measurements.

Definition at line 24 of file sunsensors.c.

References adc_finished, FALSE, set_bit, sun_measurements, and SUN_SENSORS.

Referenced by doDetumblingState(), and doMeasuringState().

Variable Documentation

uint8_t volatile adc_finished

Definition at line 11 of file sunsensors.c.

Referenced by sampleSunsensors().

uint8_t sun_measurements[SUN_SENSORS]

Sun measurements storage.

See Ldrs for corresponding panels.

Definition at line 10 of file sunsensors.c.

Referenced by logSunsensors(), and sampleSunsensors().

Generated on Fri Sep 3 17:21:16 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: sunsensors.h File Reference

sunsensors.h File Reference

Detailed Description

Interface to the LDR sun sensors.

The sun sensors are sampled sequently from channel 0 (ADC0) to 5 (ADC5). For the corresponding side panels see Ldrs.

Definition in file sunsensors.h.

#include "adcshdr.h"

Go to the source code of this file.

Defines

#define | _SUNSENSORSH_H_
#define | SUN_SENSORS 6
Number of sun sensors.

Enumerations

enum Ldrs {
LDR_D, LDR_Z, LDR_C, LDR_A,
LDR_B, LDR_N
}

Functions

void | initSunsensors (void)
Initialize ADC.

void | sampleSunsensors (void)
Sample sun sensors.

Variables

uint8_t | sun_measurements []
Sun measurements storage.

Define Documentation

#define _SUNSENSORSH_H_

Definition at line 11 of file sunsensors.h.

#define SUN_SENSORS 6

Number of sun sensors.

Definition at line 15 of file sunsensors.h.

Referenced by logSunsensors(), and sampleSunsensors().

Enumeration Type Documentation

enum Ldrs

Enumeration values:
LDR_D
LDR_Z
LDR_C
LDR_A
LDR_B
LDR_N

Definition at line 17 of file sunsensors.h.

Function Documentation

void initSunsensors ( void )

Initialize ADC.

Definition at line 12 of file sunsensors.c.

Referenced by init_detumbling().

void sampleSunsensors ( void )

Sample sun sensors.

Wait until all sun sensors have been sampled. Results are stored in sun_measurements.

Definition at line 24 of file sunsensors.c.

References adc_finished, FALSE, set_bit, sun_measurements, and SUN_SENSORS.

Referenced by doDetumblingState(), and doMeasuringState().

Variable Documentation

uint8_t sun_measurements[]

Sun measurements storage.

See Ldrs for corresponding panels.

Definition at line 31 of file sunsensors.h.

Referenced by logSunsensors(), and sampleSunsensors().

Generated on Fri Sep 3 17:21:17 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: telecommands.h File Reference

telecommands.h File Reference

Detailed Description

Definition of recognized commands received from the TeleCommand.

Command numbers from 64-127 are reserved for the ADCS system.

Note:
Many of the commands have parameters. Unless noted specificly, all parameters are of type uint8_t.

Definition in file telecommands.h.

Go to the source code of this file.

Tele commands

External commands recognized by the ADCS module.

The commands will be sent from the ground station through the TeleCommand module.

#define | STATUS_CMD 69
Download sytem status.

#define | EXT_STATUS_CMD 123
Download extended system status.

#define | MAG_CMD 65
Send command string to magnetometer.

#define | START_DETUMBLING_CMD 66
Start detumbling.

#define | STOP_DETUMBLING_CMD 67
Stop detumbling.

#define | MAGQUERY_CMD 79
Query magnetometer settings.

#define | DOWNLOAD_LOGS_CMD 68
Start downloading of logs from external EEPROM.

#define | STOP_DOWNLOAD_CMD 72
#define | RESETELOG_CMD 83
Reset external eeprom.

#define | SET_PARAMETER_CMD 124
Set a parameter stored in internal EEPROM.

#define | GET_PARAMETER_CMD 125
Query parameter value stored in internal EEPROM.

#define | START_LOGGING_CMD 90
Enable logging of data.

#define | STOP_LOGGING_CMD 91
Disable logging of data.

#define | SLEEP_CMD 126
Enter sleep mode for power saving.

#define | RESET_CMD 127
Trigger watchdog timer and reset mcu.

Debug commands

Commands for debugging purposes.

Most of these commands will be removed in the final version of the software.

#define | CHAR_CMD 64
#define | STARTMAG_CMD 70
#define | STOPMAG_CMD 71
#define | DISABLE_COILS_CMD 74
#define | SETDUTY_CMD 75
Set duty cycle and direction of coils.

Internal commands

Recognized commands from other subsystems in the satellite.

The commands are used for timing and flow control.

Note:
General call recognition must be enabled in the TWI module in order to receive these commands.

#define | PAUSE_DOWNLOAD_CMD 192
TNC buffer full.

#define | CONTINUE_DOWNLOAD_CMD 193
TNC ready for more data.

#define | TIMEUPDATE_CMD 194
Receive current time from Telecommand.

Parameter id

#define | MAG_SAMPLINGRATE_PAR 1
#define | CONTROLLER_GAIN_PAR 2
#define | WAITSTATE_DELAY_PAR 3
#define | K_XY_N_PAR 4
Id for int16_t EE_k_xy_n.

#define | K_XY_D_PAR 5
Id for int16_t EE_k_xy_d.

#define | K_Z_N_PAR 6
Id for int16_t EE_k_z_n.

#define | K_Z_D_PAR 7
Id for int16_t EE_k_z_d.

#define | MC_Z_PAR 8
Id for int16_t EE_mc_z.

#define | BDOT_MIN_PAR 9
Id for uint16_t EE_bdot_min.

#define | M_MAX_PAR 10
Id for uint16_t EE_m_max.

#define | DTMBL_LOGDATA_REG_PAR 11
Id for #EE_logdata_reg.

#define | DTMBL_LOGTIMESTEP_PAR 12
Id for #EE_logtimestep_par.

#define | MEASURE_PERIOD_PAR 13
Id for EE_measure_period.

#define | ACTUATE_PERIOD_PAR 14
Id for EE_actuate_period.

#define | MAGDELAY_PERIOD_PAR 15
Id for EE_magdelay_period.

Defines

#define | CMD_NUM_LOW 64
Lowest adcs command number.

#define | CMD_NUM_HIGH 127
Highest adcs command number.

Define Documentation

#define ACTUATE_PERIOD_PAR 14

Id for EE_actuate_period.

Definition at line 208 of file telecommands.h.

Referenced by getParamAddr().

#define BDOT_MIN_PAR 9

Id for uint16_t EE_bdot_min.

Definition at line 201 of file telecommands.h.

Referenced by getParamAddr().

#define CHAR_CMD 64

Definition at line 125 of file telecommands.h.

Referenced by handle_command().

#define CMD_NUM_HIGH 127

Highest adcs command number.

Definition at line 13 of file telecommands.h.

Referenced by handle_command().

#define CMD_NUM_LOW 64

Lowest adcs command number.

Definition at line 12 of file telecommands.h.

Referenced by handle_command().

#define CONTINUE_DOWNLOAD_CMD 193

TNC ready for more data.

Definition at line 167 of file telecommands.h.

Referenced by handle_command().

#define CONTROLLER_GAIN_PAR 2

Definition at line 192 of file telecommands.h.

#define DISABLE_COILS_CMD 74

Definition at line 129 of file telecommands.h.

Referenced by handle_command().

#define DOWNLOAD_LOGS_CMD 68

Start downloading of logs from external EEPROM.

Definition at line 48 of file telecommands.h.

Referenced by handle_command().

#define DTMBL_LOGDATA_REG_PAR 11

Id for #EE_logdata_reg.

Definition at line 204 of file telecommands.h.

Referenced by getParamAddr().

#define DTMBL_LOGTIMESTEP_PAR 12

Id for #EE_logtimestep_par.

Definition at line 205 of file telecommands.h.

Referenced by getParamAddr().

#define EXT_STATUS_CMD 123

Download extended system status.

Definition at line 25 of file telecommands.h.

Referenced by handle_command().

#define GET_PARAMETER_CMD 125

Query parameter value stored in internal EEPROM.

Parameters:
parameter_id

Definition at line 87 of file telecommands.h.

Referenced by handle_command().

#define K_XY_D_PAR 5

Id for int16_t EE_k_xy_d.

Definition at line 196 of file telecommands.h.

Referenced by getParamAddr().

#define K_XY_N_PAR 4

Id for int16_t EE_k_xy_n.

Definition at line 195 of file telecommands.h.

Referenced by getParamAddr().

#define K_Z_D_PAR 7

Id for int16_t EE_k_z_d.

Definition at line 198 of file telecommands.h.

Referenced by getParamAddr().

#define K_Z_N_PAR 6

Id for int16_t EE_k_z_n.

Definition at line 197 of file telecommands.h.

Referenced by getParamAddr().

#define M_MAX_PAR 10

Id for uint16_t EE_m_max.

Definition at line 202 of file telecommands.h.

Referenced by getParamAddr().

#define MAG_CMD 65

Send command string to magnetometer.

Definition at line 27 of file telecommands.h.

Referenced by handle_command().

#define MAG_SAMPLINGRATE_PAR 1

Definition at line 191 of file telecommands.h.

Referenced by getParamAddr().

#define MAGDELAY_PERIOD_PAR 15

Id for EE_magdelay_period.

Definition at line 209 of file telecommands.h.

Referenced by getParamAddr().

#define MAGQUERY_CMD 79

Query magnetometer settings.

Definition at line 45 of file telecommands.h.

Referenced by handle_command().

#define MC_Z_PAR 8

Id for int16_t EE_mc_z.

Definition at line 199 of file telecommands.h.

Referenced by getParamAddr().

#define MEASURE_PERIOD_PAR 13

Id for EE_measure_period.

Definition at line 207 of file telecommands.h.

Referenced by getParamAddr().

#define PAUSE_DOWNLOAD_CMD 192

TNC buffer full.

Definition at line 166 of file telecommands.h.

Referenced by handle_command().

#define RESET_CMD 127

Trigger watchdog timer and reset mcu.

Definition at line 113 of file telecommands.h.

Referenced by handle_command().

#define RESETELOG_CMD 83

Reset external eeprom.

Definition at line 50 of file telecommands.h.

Referenced by handle_command().

#define SET_PARAMETER_CMD 124

Set a parameter stored in internal EEPROM.

Parameters:
parameter_id Possible values:
  • MAG_SAMPLINGRATE_PAR
  • CONTROLLER_GAIN_PAR
  • WAITSTATE_DELAY_PAR
  • K_XY_N_PAR
  • K_XY_D_PAR
  • K_Z_N_PAR
  • K_Z_D_PAR
  • MC_Z_PAR
  • MEASURE_PERIOD_PAR
  • ACTUATE_PERIOD_PAR
  • MAGDELAY_PERIOD_PAR
value See the detailed description of the parameters above.
Note:
Negative numbers are represented using 2's complement signed integers. To convert a positive number to a negative one, invert it's bits and add 1. Example:
 a = 123 = 0x7b = 0111 1011
 b = -a = ~a +1 = 1000 0100 + 1 = 1000 0101 = 0x85 = -123

Definition at line 81 of file telecommands.h.

Referenced by handle_command().

#define SETDUTY_CMD 75

Set duty cycle and direction of coils.

Duty cycles must be in the range -255..+255. Negative numbers are in 2's complement form.

Parameters:
duty_x | int16_t
duty_y | int16_t
duty_z | int16_t
Warning:
Setting all duty cylces to 255 consumes a lot of power.

Definition at line 144 of file telecommands.h.

Referenced by handle_command().

#define SLEEP_CMD 126

Enter sleep mode for power saving.

Definition at line 112 of file telecommands.h.

Referenced by handle_command().

#define START_DETUMBLING_CMD 66

Start detumbling.

Parameters:
detumbling_period Number of minutes to detumble. If set to zero, or not specified, detumbling will continue until stopped with the STOP_DETUMBLING_CMD or magnetometer is switched off.
Note:
Befor detumbling is started there is an initial delay. The delay can be set by altering the WAITSTATE_DELAY_PAR parameter using the SET_PARAMETER_CMD command.

Definition at line 42 of file telecommands.h.

Referenced by handle_command().

#define START_LOGGING_CMD 90

Enable logging of data.

Parameters:
logflag | What data should be logged.
timestep | Number of seconds between each logging of data.
log_period | Number of minutes to log. If set to zero or omitted, log until the STOP_LOGGING_CMD is sent.
Note:
Befor logging is started, there is an initial delay. The delay can be set by altering the WAITSTATE_DELAY_PAR parameter using the SET_PARAMETER_CMD command.
To log different measurements set different bits in logflag. Defined bits are B_LOG, BDOT_LOG, DUTY_LOG and SUN_LOG. Example
 logflag  = (1 << B_LOG) | (1<< SUN_LOG);
Note:
(Wait feature disabled during debugging)

Definition at line 108 of file telecommands.h.

Referenced by handle_command().

#define STARTMAG_CMD 70

Definition at line 126 of file telecommands.h.

Referenced by handle_command().

#define STATUS_CMD 69

Download sytem status.

Definition at line 24 of file telecommands.h.

Referenced by handle_command().

#define STOP_DETUMBLING_CMD 67

Stop detumbling.

Definition at line 43 of file telecommands.h.

Referenced by handle_command().

#define STOP_DOWNLOAD_CMD 72

Definition at line 49 of file telecommands.h.

Referenced by handle_command().

#define STOP_LOGGING_CMD 91

Disable logging of data.

Definition at line 109 of file telecommands.h.

Referenced by handle_command().

#define STOPMAG_CMD 71

Definition at line 127 of file telecommands.h.

Referenced by handle_command().

#define TIMEUPDATE_CMD 194

Receive current time from Telecommand.

Definition at line 168 of file telecommands.h.

Referenced by handle_command().

#define WAITSTATE_DELAY_PAR 3

Definition at line 193 of file telecommands.h.

Referenced by getParamAddr().

Generated on Fri Sep 3 17:21:17 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: timingutils.c File Reference

timingutils.c File Reference

Detailed Description

Implemenation of timing utilities.

Definition in file timingutils.c.

#include "timingutils.h"
#include <avr/io.h>
#include <avr/signal.h>
#include "avrutils.h"

Go to the source code of this file.

Defines

#define | TCCR2_VALUE (1 << WGM21) | (1 << CS22)
#define | TCNT2_RELOAD_VALUE 0xc2
#define | OCR2_VALUE 0x3e

Functions

SIGNAL (SIG_OVERFLOW2)
Timer2 interrupt handler.

void | init_timing (void)
Initialize timer.

void | enable_timeout (Timers timer, uint16_t period)
Enable timeout.

void | disable_timeout (Timers timer)
Disable timeout.

void | restart_timeout (Timers timer)
Restart timeout timer.

Variables

uint8_t volatile | timed_out_ms
uint8_t volatile | timed_out_sec
uint8_t volatile | timed_out_min
uint16_t volatile | timeout_counter_ms
uint8_t volatile | timeout_counter_sec
uint8_t volatile | timeout_counter_min
uint8_t volatile | timeout_period_sec
uint8_t volatile | timeout_period_min
uint16_t volatile | timeout_period_ms
uint32_t volatile | UTC_Second
Global second counter.

uint8_t | active_timers
Number of activated timers.

uint8_t | timer_reg
Tells which timers are on.

Define Documentation

#define OCR2_VALUE 0x3e

Definition at line 27 of file timingutils.c.

Referenced by enable_timeout().

#define TCCR2_VALUE (1 << WGM21) | (1 << CS22)

Definition at line 25 of file timingutils.c.

Referenced by enable_timeout().

#define TCNT2_RELOAD_VALUE 0xc2

Definition at line 26 of file timingutils.c.

Referenced by enable_timeout(), and SIGNAL().

Function Documentation

void disable_timeout ( Timers timer )

Disable timeout.

If no timers are active the timer interrupt is switched off.

Parameters:
timer Which timer to disable

Definition at line 145 of file timingutils.c.

References active_timers, ALL_TIMERS, clear_bit, MIN_TIMER, MS_TIMER, SEC_TIMER, and timer_reg.

Referenced by doDetumblingState(), doIdleState(), doMeasuringState(), and mag_is_on().

void enable_timeout | ( | Timers | timer,
 |  | uint16_t | period
 | ) |

Enable timeout.

Start a timer with a specified timeout period. When a timeout occur the timed_out flag is set.

Parameters:
timer | Which timeout to set.
period | Timeout period.
Warning:
If the watchdog timer is enabled it can be triggered by a long timeout loop.

Definition at line 103 of file timingutils.c.

References active_timers, clear_bit, MIN_TIMER, MS_TIMER, OCR2_VALUE, SEC_TIMER, set_bit, TCCR2_VALUE, TCNT2_RELOAD_VALUE, timed_out_min, timed_out_ms, timed_out_sec, timeout_counter_min, timeout_counter_ms, timeout_counter_sec, timeout_period_min, timeout_period_ms, timeout_period_sec, and timer_reg.

Referenced by doDetumblingState(), doIdleState(), doMeasuringState(), init_detumbling(), mag_is_on(), and start_logging().

void init_timing ( void )

Initialize timer.

Uses TIMER2 normal mode.

Definition at line 82 of file timingutils.c.

References active_timers, and timer_reg.

void restart_timeout ( Timers timer )

Restart timeout timer.

Reset the internal counter and start a new period.

Parameters:
timer Which timer to restart.

Definition at line 173 of file timingutils.c.

References MIN_TIMER, MS_TIMER, SEC_TIMER, timed_out_min, timed_out_ms, timed_out_sec, timeout_counter_min, timeout_counter_ms, and timeout_counter_sec.

Referenced by main().

SIGNAL ( SIG_OVERFLOW2 )

Timer2 interrupt handler.

Triggered with a period of 1 ms

Definition at line 57 of file timingutils.c.

References TCNT2_RELOAD_VALUE, timed_out_min, timed_out_ms, timed_out_sec, timeout_counter_min, timeout_counter_ms, timeout_counter_sec, timeout_period_min, timeout_period_ms, timeout_period_sec, and UTC_Second.

Variable Documentation

uint8_t active_timers

Number of activated timers.

Definition at line 49 of file timingutils.c.

Referenced by disable_timeout(), enable_timeout(), and init_timing().

uint8_t volatile timed_out_min

Definition at line 36 of file timingutils.c.

Referenced by doWaitState(), enable_timeout(), restart_timeout(), and SIGNAL().

uint8_t volatile timed_out_ms

Definition at line 34 of file timingutils.c.

Referenced by doDetumblingState(), enable_timeout(), mag_is_on(), restart_timeout(), and SIGNAL().

uint8_t volatile timed_out_sec

Definition at line 35 of file timingutils.c.

Referenced by doIdleState(), doMeasuringState(), enable_timeout(), main(), restart_timeout(), and SIGNAL().

uint8_t volatile timeout_counter_min

Definition at line 41 of file timingutils.c.

Referenced by enable_timeout(), restart_timeout(), and SIGNAL().

uint16_t volatile timeout_counter_ms

Definition at line 39 of file timingutils.c.

Referenced by enable_timeout(), restart_timeout(), and SIGNAL().

uint8_t volatile timeout_counter_sec

Definition at line 40 of file timingutils.c.

Referenced by enable_timeout(), restart_timeout(), and SIGNAL().

uint8_t volatile timeout_period_min

Definition at line 44 of file timingutils.c.

Referenced by enable_timeout(), and SIGNAL().

uint16_t volatile timeout_period_ms

Definition at line 45 of file timingutils.c.

Referenced by enable_timeout(), and SIGNAL().

uint8_t volatile timeout_period_sec

Definition at line 43 of file timingutils.c.

Referenced by enable_timeout(), and SIGNAL().

uint8_t timer_reg

Tells which timers are on.

Definition at line 50 of file timingutils.c.

Referenced by disable_timeout(), enable_timeout(), and init_timing().

uint32_t volatile UTC_Second

Global second counter.

Definition at line 47 of file timingutils.c.

Referenced by handle_command(), init_adcs(), log_intdata(), logSunsensors(), and SIGNAL().

Generated on Fri Sep 3 17:21:17 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: timingutils.h File Reference

timingutils.h File Reference

Detailed Description

Timing utilities.

Various utilites for handling delays and timing. Both loop and timer based.

Todo:
Make it easier to change which mcu timer to use.

Add support for multiple timeouts with different periods.

Definition in file timingutils.h.

#include <inttypes.h>
#include "adcshdr.h"

Go to the source code of this file.

Delay macros.

Delay using loops.

Note:
The code is from the 'general peripheral drivers' library written by Chris Efstathiou
Warning:
If an interrupt occur while running one of the delay macros, the delay will be prolonged with the time it takes to serve the interrupt.

#define | DELAY_L_ACCURATE(x)
#define | TIME_L1_MS ( 1*(F_CPU/6000) )
#define | TIME_L100_US ( 1*(F_CPU/60000) )
#define | DELAY_MS(ms) DELAY_L_ACCURATE( (TIME_L1_MS*ms) )
Delay a specific number of milliseconds.

#define | DELAY_L_US(us) DELAY_L_ACCURATE( (TIME_L100_US*(us/100))+1 )
Delay a specific number of microseconds.

Enumerations

enum | Timers { MS_TIMER, SEC_TIMER, MIN_TIMER, ALL_TIMERS }

Functions

void | init_timing (void)
Initialize timer.

void | enable_timeout (Timers timer, uint16_t period)
Enable timeout.

void | disable_timeout (Timers timer)
Disable timeout.

void | restart_timeout (Timers timer)
Restart timeout timer.

Variables

uint32_t volatile | UTC_Second
Global second counter.

uint8_t volatile | timed_out_ms
uint8_t volatile | timed_out_sec
uint8_t volatile | timed_out_min

Define Documentation

#define DELAY_L_ACCURATE ( x )

Value:

({ unsigned long number_of_loops=(unsigned long)x;   \
                                __asm__ volatile ( "L_%=: \n\t"                   \
                                                   "subi %A0,lo8(-(-1)) \n\t"     \
                                                   "sbci %B0,hi8(-(-1)) \n\t"     \
                                                   "sbci %C0,hlo8(-(-1)) \n\t"    \
                                                   "sbci %D0,hhi8(-(-1)) \n\t"    \
                                                   "brne L_%= \n\t"               \
                                                   :                \
                                                   : "w" (number_of_loops)        \
                                                 );                               \
                             })

Definition at line 39 of file timingutils.h.

#define DELAY_L_US ( us ) DELAY_L_ACCURATE( (TIME_L100_US*(us/100))+1 )

Delay a specific number of microseconds.

Definition at line 59 of file timingutils.h.

#define DELAY_MS ( ms ) DELAY_L_ACCURATE( (TIME_L1_MS*ms) )

Delay a specific number of milliseconds.

Definition at line 57 of file timingutils.h.

Referenced by mag_send_command(), mag_send_command_N(), mag_send_command_P(), and transmit_12c_buffer().

#define TIME_L100_US ( 1*(F_CPU/60000) )

Definition at line 55 of file timingutils.h.

#define TIME_L1_MS ( 1*(F_CPU/6000) )

Definition at line 54 of file timingutils.h.

Enumeration Type Documentation

enum Timers

Enumeration values:
MS_TIMER
SEC_TIMER
MIN_TIMER
ALL_TIMERS

Definition at line 16 of file timingutils.h.

Function Documentation

void disable_timeout ( Timers timer )

Disable timeout.

If no timers are active the timer interrupt is switched off.

Parameters:
timer Which timer to disable

Definition at line 145 of file timingutils.c.

References active_timers, ALL_TIMERS, clear_bit, MIN_TIMER, MS_TIMER, SEC_TIMER, and timer_reg.

Referenced by doDetumblingState(), doIdleState(), doMeasuringState(), and mag_is_on().

void enable_timeout | ( | Timers | timer,
 |  | uint16_t | period
 | ) |

Enable timeout.

Start a timer with a specified timeout period. When a timeout occur the timed_out flag is set.

Parameters:
timer | Which timeout to set.
period | Timeout period.
Warning:
If the watchdog timer is enabled it can be triggered by a long timeout loop.

Definition at line 103 of file timingutils.c.

References active_timers, clear_bit, MIN_TIMER, MS_TIMER, OCR2_VALUE, SEC_TIMER, set_bit, TCCR2_VALUE, TCNT2_RELOAD_VALUE, timed_out_min, timed_out_ms, timed_out_sec, timeout_counter_min, timeout_counter_ms, timeout_counter_sec, timeout_period_min, timeout_period_ms, timeout_period_sec, and timer_reg.

Referenced by doDetumblingState(), doIdleState(), doMeasuringState(), init_detumbling(), mag_is_on(), and start_logging().

void init_timing ( void )

Initialize timer.

Uses TIMER2 normal mode.

Definition at line 82 of file timingutils.c.

References active_timers, and timer_reg.

void restart_timeout ( Timers timer )

Restart timeout timer.

Reset the internal counter and start a new period.

Parameters:
timer Which timer to restart.

Definition at line 173 of file timingutils.c.

References MIN_TIMER, MS_TIMER, SEC_TIMER, timed_out_min, timed_out_ms, timed_out_sec, timeout_counter_min, timeout_counter_ms, and timeout_counter_sec.

Referenced by main().

Variable Documentation

uint8_t volatile timed_out_min

Definition at line 67 of file timingutils.h.

Referenced by doWaitState(), enable_timeout(), restart_timeout(), and SIGNAL().

uint8_t volatile timed_out_ms

Definition at line 65 of file timingutils.h.

Referenced by doDetumblingState(), enable_timeout(), mag_is_on(), restart_timeout(), and SIGNAL().

uint8_t volatile timed_out_sec

Definition at line 66 of file timingutils.h.

Referenced by doIdleState(), doMeasuringState(), enable_timeout(), main(), restart_timeout(), and SIGNAL().

uint32_t volatile UTC_Second

Global second counter.

Definition at line 64 of file timingutils.h.

Referenced by handle_command(), init_adcs(), log_intdata(), logSunsensors(), and SIGNAL().

Generated on Fri Sep 3 17:21:17 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: tnccomm.c File Reference

tnccomm.c File Reference

Detailed Description

Implementation of the TNC communication module.

Definition in file tnccomm.c.

#include "tnccomm.h"
#include "softi2c.h"
#include "timingutils.h"

Go to the source code of this file.

Functions

void | tnc_puthex8 (uint8_t n, uint8_t f)
void | tnc_put (char *buf)
Send a string.

void | tnc_put_P (PGM_P addr)
Send a string stored in program memory.

void | tnc_putline (char *buf)
Send a string and and append a newline character.

void | tnc_putline_P (PGM_P addr)
Send a string stored in program memory and append a newline character.

void | tnc_putchar (char c)
Send a single character.

void | tnc_putchar_n (char c)
Send a single character.

void | init_tnc (void)
Initialize TNC communication.

uint8_t | transmit_12c_buffer (void)
Transmit the contents of the i2c transmit buffer.

Variables

uint8_t | TNC_TXBuf [TNC_TXBUF_SIZE]
TNC transmit buffer.

uint8_t | TNC_TXBufSize = 0
Current size of TNC_TXBuf.

uint8_t | TNC_TX_Rd_Idx
uint8_t | TNC_TX_Wr_Idx
uint8_t | TNC_TX_Counter
uint8_t volatile | TNC_status_reg
TNC status register.

Function Documentation

void init_tnc ( void )

Initialize TNC communication.

Definition at line 135 of file tnccomm.c.

References set_bit, TNC_status_reg, TNC_TX_Rd_Idx, and TNC_TX_Wr_Idx.

Referenced by init_adcs().

void tnc_put ( char * buf )

Send a string.

Todo:
Add overflow detection and handling.

Definition at line 60 of file tnccomm.c.

References tnc_putchar().

Referenced by print_int().

void tnc_put_P ( PGM_P addr )

Send a string stored in program memory.

Parameters:
addr Pointer to string stored in program memory.
Todo:
Add overflow detection and handling.

Definition at line 72 of file tnccomm.c.

References tnc_putchar().

Referenced by get_parameter(), sendStatus(), setCoilDuty(), and tnc_puthex8().

void tnc_putchar ( char c )

Send a single character.

Todo:
Add error handling.

Definition at line 101 of file tnccomm.c.

References I2C_BUFFER_RDY_BIT, set_bit, TNC_status_reg, TNC_TX_Wr_Idx, TNC_TXBuf, TNC_TXBUF_SIZE, and transmit_12c_buffer().

Referenced by get_parameter(), print_sint(), SendELog(), setCoilDuty(), tnc_put(), tnc_put_P(), tnc_putchar_n(), tnc_puthex8(), tnc_putline(), and tnc_putline_P().

void tnc_putchar_n ( char c )

Send a single character.

Add a carriage return char after a nnewline char.

Definition at line 128 of file tnccomm.c.

References tnc_putchar().

Referenced by doMagQuery(), and doVUartState().

void tnc_puthex8 | ( | uint8_t | n,
 |  | uint8_t | f
 | ) |

Definition at line 44 of file tnccomm.c.

References tnc_put_P(), and tnc_putchar().

Referenced by SendELog(), and sendStatus().

void tnc_putline ( char * buf )

Send a string and and append a newline character.

Definition at line 81 of file tnccomm.c.

References tnc_putchar().

Referenced by get_parameter(), SendELog(), and set_parameter().

void tnc_putline_P ( PGM_P addr )

Send a string stored in program memory and append a newline character.

Definition at line 92 of file tnccomm.c.

References tnc_putchar().

Referenced by AbortSendELog(), doDetumblingState(), doMagQuery(), doMeasuringState(), handle_command(), log_reset(), set_parameter(), and StartSendELog().

uint8_t transmit_12c_buffer ( void )

Transmit the contents of the i2c transmit buffer.

Returns:
Error code. 0 if no errors.

Definition at line 153 of file tnccomm.c.

References clear_bit, DELAY_MS, I2C_BUFFER_RDY_BIT, I2C_TNC_ADDR, Soft_I2C_Write(), TNC_BUFFER_FULL_BIT, TNC_status_reg, TNC_TX_Rd_Idx, TNC_TX_Wr_Idx, TNC_TXBuf, and TRUE.

Referenced by main(), and tnc_putchar().

Variable Documentation

uint8_t volatile TNC_status_reg

TNC status register.

  • TNC_BUFFER_FULL_BIT
  • I2C_BUFFER_RDY_BIT

Definition at line 20 of file tnccomm.c.

Referenced by doDownloadState(), handle_command(), init_tnc(), main(), tnc_putchar(), and transmit_12c_buffer().

uint8_t TNC_TX_Counter

Definition at line 17 of file tnccomm.c.

uint8_t TNC_TX_Rd_Idx

Definition at line 15 of file tnccomm.c.

Referenced by init_tnc(), and transmit_12c_buffer().

uint8_t TNC_TX_Wr_Idx

Definition at line 16 of file tnccomm.c.

Referenced by init_tnc(), tnc_putchar(), and transmit_12c_buffer().

uint8_t TNC_TXBuf[TNC_TXBUF_SIZE]

TNC transmit buffer.

Definition at line 12 of file tnccomm.c.

Referenced by tnc_putchar(), and transmit_12c_buffer().

uint8_t TNC_TXBufSize = 0

Current size of TNC_TXBuf.

Definition at line 13 of file tnccomm.c.

Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: tnccomm.h File Reference

tnccomm.h File Reference

Detailed Description

TNC communication module.

Top-level functions for transmitting data to the TNC. The code has a modular design that makes it easy to change the peripheral bus for communication.

Author:
Kjell Magne Fauske

Definition in file tnccomm.h.

#include "adcshdr.h"
#include <avr/pgmspace.h>

Go to the source code of this file.

Defines

#define | TNC_TXBUF_SIZE 100
Size of TNC transmit buffer.

#define | I2C_TNC_ADDR 0x78
Address of the TNC on the I2C bus.

#define | TNC_BUFFER_FULL_BIT 1
Set if TNC buffer is full.

#define | I2C_BUFFER_RDY_BIT 0
#define | I2C_BUF_OVERFLOW_BIT 2
#define | tnc_newline() {tnc_putchar('\n'); tnc_putchar('\r');}

Functions

void | tnc_put (char *buf)
Send a string.

void | tnc_put_P (PGM_P addr)
Send a string stored in program memory.

void | tnc_putline (char *buf)
Send a string and and append a newline character.

void | tnc_putline_P (PGM_P addr)
Send a string stored in program memory and append a newline character.

void | tnc_putchar (char c)
Send a single character.

void | tnc_putchar_n (char c)
Send a single character.

void | init_tnc (void)
Initialize TNC communication.

uint8_t | transmit_12c_buffer (void)
Transmit the contents of the i2c transmit buffer.

void | tnc_puthex8 (uint8_t n, uint8_t f)

Variables

uint8_t volatile | TNC_status_reg
TNC status register.

Define Documentation

#define I2C_BUF_OVERFLOW_BIT 2

Definition at line 25 of file tnccomm.h.

#define I2C_BUFFER_RDY_BIT 0

Definition at line 24 of file tnccomm.h.

Referenced by main(), tnc_putchar(), and transmit_12c_buffer().

#define I2C_TNC_ADDR 0x78

Address of the TNC on the I2C bus.

Definition at line 20 of file tnccomm.h.

Referenced by transmit_12c_buffer().

#define TNC_BUFFER_FULL_BIT 1

Set if TNC buffer is full.

Definition at line 23 of file tnccomm.h.

Referenced by doDownloadState(), handle_command(), and transmit_12c_buffer().

#define tnc_newline ( ) {tnc_putchar('\n'); tnc_putchar('\r');}

Definition at line 87 of file tnccomm.h.

Referenced by doMagQuery(), print_int(), and sendStatus().

#define TNC_TXBUF_SIZE 100

Size of TNC transmit buffer.

Definition at line 19 of file tnccomm.h.

Referenced by tnc_putchar().

Function Documentation

void init_tnc ( void )

Initialize TNC communication.

Definition at line 135 of file tnccomm.c.

References set_bit, TNC_status_reg, TNC_TX_Rd_Idx, and TNC_TX_Wr_Idx.

Referenced by init_adcs().

void tnc_put ( char * buf )

Send a string.

Todo:
Add overflow detection and handling.

Definition at line 60 of file tnccomm.c.

References tnc_putchar().

Referenced by print_int().

void tnc_put_P ( PGM_P addr )

Send a string stored in program memory.

Parameters:
addr Pointer to string stored in program memory.
Todo:
Add overflow detection and handling.

Definition at line 72 of file tnccomm.c.

References tnc_putchar().

Referenced by get_parameter(), sendStatus(), setCoilDuty(), and tnc_puthex8().

void tnc_putchar ( char c )

Send a single character.

Todo:
Add error handling.

Definition at line 101 of file tnccomm.c.

References I2C_BUFFER_RDY_BIT, set_bit, TNC_status_reg, TNC_TX_Wr_Idx, TNC_TXBuf, TNC_TXBUF_SIZE, and transmit_12c_buffer().

Referenced by get_parameter(), print_sint(), SendELog(), setCoilDuty(), tnc_put(), tnc_put_P(), tnc_putchar_n(), tnc_puthex8(), tnc_putline(), and tnc_putline_P().

void tnc_putchar_n ( char c )

Send a single character.

Add a carriage return char after a nnewline char.

Definition at line 128 of file tnccomm.c.

References tnc_putchar().

Referenced by doMagQuery(), and doVUartState().

void tnc_puthex8 | ( | uint8_t | n,
 |  | uint8_t | f
 | ) |

Definition at line 44 of file tnccomm.c.

References tnc_put_P(), and tnc_putchar().

Referenced by SendELog(), and sendStatus().

void tnc_putline ( char * buf )

Send a string and and append a newline character.

Definition at line 81 of file tnccomm.c.

References tnc_putchar().

Referenced by get_parameter(), SendELog(), and set_parameter().

void tnc_putline_P ( PGM_P addr )

Send a string stored in program memory and append a newline character.

Definition at line 92 of file tnccomm.c.

References tnc_putchar().

Referenced by AbortSendELog(), doDetumblingState(), doMagQuery(), doMeasuringState(), handle_command(), log_reset(), set_parameter(), and StartSendELog().

uint8_t transmit_12c_buffer ( void )

Transmit the contents of the i2c transmit buffer.

Returns:
Error code. 0 if no errors.

Definition at line 153 of file tnccomm.c.

References clear_bit, DELAY_MS, I2C_BUFFER_RDY_BIT, I2C_TNC_ADDR, Soft_I2C_Write(), TNC_BUFFER_FULL_BIT, TNC_status_reg, TNC_TX_Rd_Idx, TNC_TX_Wr_Idx, TNC_TXBuf, and TRUE.

Referenced by main(), and tnc_putchar().

Variable Documentation

uint8_t volatile TNC_status_reg

TNC status register.

  • TNC_BUFFER_FULL_BIT
  • I2C_BUFFER_RDY_BIT

Definition at line 32 of file tnccomm.h.

Referenced by doDownloadState(), handle_command(), init_tnc(), main(), tnc_putchar(), and transmit_12c_buffer().

Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: twislave.c File Reference

twislave.c File Reference

Detailed Description

Implementation of the TWI slave module.

Definition in file twislave.c.

#include "twislave.h"
#include "adcshdr.h"
#include <avr/twi.h>
#include <avr/signal.h>

Go to the source code of this file.

Functions

SIGNAL (SIG_2WIRE_SERIAL)
TWI interrupt handler for slave receiver mode.

void | init_twi_slave (uint8_t slave_addr)
Initialize the TWI bus.

Variables

uint8_t | CmdBuf [CMDBUF_MAXSIZE]
Buffer used for receiving commands.

uint8_t | CmdBufSize
Number of bytes in CmdBuf.

uint8_t | CmdBufRdy
Command received.

Function Documentation

void init_twi_slave ( uint8_t slave_addr )

Initialize the TWI bus.

Parameters:
slave_addr Value to load into the TWAR register.
The seven MSB bits of the TWAR register is used to set the slave address. The LSB of the TWAR is set to enable recognition of the general call address ($00).

Note:
Interrupts are noe enabled by init_twi_slave().

Definition at line 69 of file twislave.c.

Referenced by init_adcs().

SIGNAL ( SIG_2WIRE_SERIAL )

TWI interrupt handler for slave receiver mode.

Todo:
Implement better error handling.

Definition at line 21 of file twislave.c.

References CmdBuf, CMDBUF_SIZE, CmdBufRdy, and CmdBufSize.

Variable Documentation

uint8_t CmdBuf[CMDBUF_MAXSIZE]

Buffer used for receiving commands.

It has the following format:

  • cmdbuf[0] - Message id
  • cmdbuf[1] - Message lenght
  • cmdbuf[.] - Message data

Definition at line 13 of file twislave.c.

Referenced by get_parameter(), handle_command(), set_parameter(), setCoilDuty(), and SIGNAL().

uint8_t CmdBufRdy

Command received.

CmdBufRdy must be cleared before a new command can be recieved.

Definition at line 14 of file twislave.c.

Referenced by handle_command(), main(), and SIGNAL().

uint8_t CmdBufSize

Number of bytes in CmdBuf.

Definition at line 14 of file twislave.c.

Referenced by handle_command(), and SIGNAL().

Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: twislave.h File Reference

twislave.h File Reference

Detailed Description

Interrupt driven TWI/I2C bus slave interface.

The slave receives data from the master through the CmdBuf buffer. The variable CmdBufRdy is set to indicate when a command is received. CmdBufRdy must be cleared after the message is read.

Messages in the CmdBuf has the following format:

  • CmdBuf[0] - Message id
  • CmdBuf[1] - Message lenght
  • CmdBuf[.] - Message data

Note:
Interrupts must be enabled before commands can be received

Definition in file twislave.h.

#include "adcshdr.h"

Go to the source code of this file.

Defines

#define | CMDBUF_MAXSIZE 256
Maximum size of command buffer.

#define | CMDBUF_ID 0
Index to #cmdbuf id byte.

#define | CMDBUF_SIZE 1
Index to #cmdbuf size byte.

#define | CMDBUF_DATA 2
Index to first data byte ine #cmdbuf.

Functions

void | init_twi_slave (uint8_t slave_addr)
Initialize the TWI bus.

Variables

uint8_t | CmdBuf []
Buffer used for receiving commands.

uint8_t | CmdBufSize
Number of bytes in CmdBuf.

uint8_t | CmdBufRdy
Command received.

Define Documentation

#define CMDBUF_DATA 2

Index to first data byte ine #cmdbuf.

Definition at line 26 of file twislave.h.

Referenced by get_parameter(), handle_command(), set_parameter(), and setCoilDuty().

#define CMDBUF_ID 0

Index to #cmdbuf id byte.

Definition at line 24 of file twislave.h.

Referenced by handle_command().

#define CMDBUF_MAXSIZE 256

Maximum size of command buffer.

Definition at line 23 of file twislave.h.

#define CMDBUF_SIZE 1

Index to #cmdbuf size byte.

Definition at line 25 of file twislave.h.

Referenced by handle_command(), and SIGNAL().

Function Documentation

void init_twi_slave ( uint8_t slave_addr )

Initialize the TWI bus.

Parameters:
slave_addr Value to load into the TWAR register.
The seven MSB bits of the TWAR register is used to set the slave address. The LSB of the TWAR is set to enable recognition of the general call address ($00).

Note:
Interrupts are noe enabled by init_twi_slave().

Definition at line 69 of file twislave.c.

Referenced by init_adcs().

Variable Documentation

uint8_t CmdBuf[]

Buffer used for receiving commands.

It has the following format:

  • cmdbuf[0] - Message id
  • cmdbuf[1] - Message lenght
  • cmdbuf[.] - Message data

Definition at line 35 of file twislave.h.

Referenced by get_parameter(), handle_command(), set_parameter(), setCoilDuty(), and SIGNAL().

uint8_t CmdBufRdy

Command received.

CmdBufRdy must be cleared before a new command can be recieved.

Definition at line 45 of file twislave.h.

Referenced by handle_command(), main(), and SIGNAL().

uint8_t CmdBufSize

Number of bytes in CmdBuf.

Definition at line 38 of file twislave.h.

Referenced by handle_command(), and SIGNAL().

Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: Annotated Index

NCUBE ADCS Data Structures

Here are the data structures with brief descriptions:
dutyStruct | Structure for storing duty cycle values
LogEntry | Single log entry
magMeasurement | A single magnetometer measurement
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: dutyStruct struct Reference

dutyStruct Struct Reference

#include <coildriver.h>

Detailed Description

Structure for storing duty cycle values.

Note:
Signed 16-bit integers are used to store the duty cycles and directions. However, this is a bit waste of memory.

Definition at line 101 of file coildriver.h.

Data Fields

int16_t | duty_x
int16_t | duty_y
int16_t | duty_z

Field Documentation

int16_t dutyStruct::duty_x

Definition at line 102 of file coildriver.h.

Referenced by log_data(), and setDutyParams().

int16_t dutyStruct::duty_y

Definition at line 103 of file coildriver.h.

Referenced by log_data(), and setDutyParams().

int16_t dutyStruct::duty_z

Definition at line 104 of file coildriver.h.

Referenced by log_data(), and setDutyParams().

The documentation for this struct was generated from the following file:
  • coildriver.h
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: LogEntry struct Reference

LogEntry Struct Reference

#include <adcslog.h>

Detailed Description

Single log entry.

Every entry in the log has a common format.

Definition at line 45 of file adcslog.h.

Data Fields

uint8_t | log_type
uint16_t | time
Time of logging.

union {
uint16_t iarr [LOGDATA_SIZE/2]
uint8_t barr [LOGDATA_SIZE]
} data

Field Documentation

uint8_t LogEntry::barr[LOGDATA_SIZE]

Definition at line 50 of file adcslog.h.

union { ... } LogEntry::data

uint16_t LogEntry::iarr[LOGDATA_SIZE/2]

Definition at line 49 of file adcslog.h.

uint8_t LogEntry::log_type

Definition at line 46 of file adcslog.h.

uint16_t LogEntry::time

Time of logging.

Definition at line 47 of file adcslog.h.

The documentation for this struct was generated from the following file:
  • adcslog.h
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: magMeasurement struct Reference

magMeasurement Struct Reference

#include <magnetometer.h>

Detailed Description

A single magnetometer measurement.

The measurements are given relative to +- 2.0 Gauss. The datasheet states that +-2.0 Gauss gives a reading of +-30000 (0x7530 and 0x8AD0).

Definition at line 44 of file magnetometer.h.

Data Fields

int16_t | magX
int16_t | magY
int16_t | magZ

Field Documentation

int16_t magMeasurement::magX

Definition at line 45 of file magnetometer.h.

Referenced by calcBdot(), doDetumblingState(), log_data(), mag_fill_meas_buffer(), and sendStatus().

int16_t magMeasurement::magY

Definition at line 46 of file magnetometer.h.

Referenced by calcBdot(), doDetumblingState(), log_data(), mag_fill_meas_buffer(), and sendStatus().

int16_t magMeasurement::magZ

Definition at line 47 of file magnetometer.h.

Referenced by calcBdot(), doDetumblingState(), log_data(), mag_fill_meas_buffer(), and sendStatus().

The documentation for this struct was generated from the following file:
  • magnetometer.h
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: Compound Member Index

Here is a list of all struct and union fields with links to the structures/unions they belong to:

  • barr : LogEntry
  • data : LogEntry
  • duty_x : dutyStruct
  • duty_y : dutyStruct
  • duty_z : dutyStruct
  • iarr : LogEntry
  • log_type : LogEntry
  • magX : magMeasurement
  • magY : magMeasurement
  • magZ : magMeasurement
  • time : LogEntry
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: File Member Index

Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- _ -

  • __disable_interrupt : avrutils.h
  • __enable_interrupt : avrutils.h
  • _NOP : avrutils.h
  • _SUNSENSORSH_H_ : sunsensors.h

- a -

  • AbortSendELog() : adcslog.h, adcslog.c
  • active_timers : timingutils.c
  • ACTUATE_DTBL_STATE : adcsnode.c
  • ACTUATE_PERIOD : adcsnode.h
  • actuate_period : adcsnode.c
  • ACTUATE_PERIOD_PAR : telecommands.h
  • adc_finished : sunsensors.c
  • ADCS_I2C_ADDR : adcsnode.h
  • after_wait_state : adcsnode.c
  • ALL_TIMERS : timingutils.h
  • assign_bit : avrutils.h
  • avr_break : avrutils.h

- b -

  • B_LOG : adcslog.h
  • Bdot : magnetometer.h, magnetometer.c
  • BDOT_LOG : adcslog.h
  • bdot_min : adcsnode.c
  • BDOT_MIN_PAR : telecommands.h
  • BUF_SREG : iouart.c

- c -

  • calcBdot() : adcsnode.h, adcsnode.c
  • change_state : adcsnode.c
  • changeState() : adcsnode.h, adcsnode.c
  • CHAR_CMD : telecommands.h
  • char_received : adcsnode.c
  • clear_bit : avrutils.h
  • CMD_NUM_HIGH : telecommands.h
  • CMD_NUM_LOW : telecommands.h
  • CmdBuf : twislave.h, twislave.c
  • CMDBUF_DATA : twislave.h
  • CMDBUF_ID : twislave.h
  • CMDBUF_MAXSIZE : twislave.h
  • CMDBUF_SIZE : twislave.h
  • CmdBufRdy : twislave.h, twislave.c
  • CmdBufSize : twislave.h, twislave.c
  • CoilAll : coildriver.h
  • Coils : coildriver.h
  • CoilX : coildriver.h
  • COILX_A : coildriver.h
  • COILX_DIR_PIN : coildriver.h
  • COILX_DIR_PORT : coildriver.h
  • COILX_DUTY_REG : coildriver.c
  • COILX_ENABLE_PIN : coildriver.h
  • COILX_ENABLE_PORT : coildriver.h
  • COILX_N : coildriver.h
  • COILX_PWM_PIN : coildriver.h
  • COILX_PWM_PORT : coildriver.h
  • CoilY : coildriver.h
  • COILY_A : coildriver.h
  • COILY_DIR_PIN : coildriver.h
  • COILY_DIR_PORT : coildriver.h
  • COILY_DUTY_REG : coildriver.c
  • COILY_ENABLE_PIN : coildriver.h
  • COILY_ENABLE_PORT : coildriver.h
  • COILY_N : coildriver.h
  • COILY_PWM_PIN : coildriver.h
  • COILY_PWM_PORT : coildriver.h
  • CoilZ : coildriver.h
  • COILZ_A : coildriver.h
  • COILZ_DIR_PIN : coildriver.h
  • COILZ_DIR_PORT : coildriver.h
  • COILZ_DUTY_REG : coildriver.c
  • COILZ_ENABLE_PIN : coildriver.h
  • COILZ_ENABLE_PORT : coildriver.h
  • COILZ_N : coildriver.h
  • COILZ_PWM_PIN : coildriver.h
  • COILZ_PWM_PORT : coildriver.h
  • CONTINUE_DOWNLOAD_CMD : telecommands.h
  • CONTROLLER_GAIN_PAR : telecommands.h
  • CR_CHAR : magnetometer.h
  • CSEWaddr : SPIeeprom.c
  • current_state : adcsnode.c

- d -

  • DATA_PR_LOGINTERVAL : adcslog.h
  • debug_P() : debugutils.h, debugutils.c
  • DELAY_DTBL_STATE : adcsnode.c
  • DELAY_L_ACCURATE : timingutils.h
  • DELAY_L_US : timingutils.h
  • DELAY_MS : timingutils.h
  • detumbling_period : adcsnode.c
  • DETUMBLING_STATE : adcsnode.h
  • DIR_DDR : coildriver.h
  • disable_coil() : coildriver.h, coildriver.c
  • DISABLE_COILS_CMD : telecommands.h
  • disable_interrupts : avrutils.h
  • disable_timeout() : timingutils.h, timingutils.c
  • doDetumblingState() : adcsnode.h, adcsnode.c
  • doDownloadState() : adcsnode.h, adcsnode.c
  • doErrorState() : adcsnode.h, adcsnode.c
  • doIdleState() : adcsnode.h, adcsnode.c
  • doMagQuery() : adcsnode.h, adcsnode.c
  • doMeasuring() : adcsnode.h
  • doMeasuringState() : adcsnode.h, adcsnode.c
  • doSleepState() : adcsnode.h, adcsnode.c
  • doVUartState() : adcsnode.h, adcsnode.c
  • doWaitState() : adcsnode.h, adcsnode.c
  • DOWNLOAD_LOGS_CMD : telecommands.h
  • DOWNLOAD_STATE : adcsnode.h
  • DTMBL_LOGDATA_REG_PAR : telecommands.h
  • DTMBL_LOGTIMESTEP_PAR : telecommands.h
  • DUTY_LOG : adcslog.h

- e -

  • EE_actuate_period : eevars.h, eevars.c
  • EE_bdot_min : eevars.h, eevars.c
  • EE_dtmbl_logdata_reg : eevars.h, eevars.c
  • EE_dtmbl_logtimestep : eevars.h, eevars.c
  • EE_eeprom_signature : eevars.h
  • EE_ELogCycle : adcslog.c
  • EE_ELogFull : adcslog.c
  • EE_k_xy_d : eevars.h, eevars.c
  • EE_k_xy_n : eevars.h, eevars.c
  • EE_k_z_d : eevars.h, eevars.c
  • EE_k_z_n : eevars.h, eevars.c
  • EE_m_max : eevars.h, eevars.c
  • EE_mag_notinitialized : eevars.h
  • EE_mag_sampling_rate : eevars.h
  • EE_magdelay_period : eevars.h, eevars.c
  • EE_mc_z : eevars.h, eevars.c
  • EE_measure_period : eevars.h, eevars.c
  • EE_waitstate_delay : eevars.h
  • EEPROM : eevars.c, avrutils.h
  • eeprom_programmed : eevars.h, eevars.c
  • EEPROM_SIGNATURE : adcshdr.h
  • EepromDeselect() : SPIeeprom.c
  • EepromSelect() : SPIeeprom.c
  • ELogCycle : adcslog.c
  • ELogFull : adcslog.c
  • ELogSendPage : adcslog.c
  • enable_coil() : coildriver.h, coildriver.c
  • ENABLE_DDR : coildriver.h
  • enable_interrupts : avrutils.h
  • enable_timeout() : timingutils.h, timingutils.c
  • EnableWriteExtEeprom() : SPIeeprom.c
  • ERROR_STATE : adcsnode.h
  • ESC_CHAR : magnetometer.h
  • EXIT_STATE_MSG : adcsnode.h
  • EXT_EE_RDSR : SPIeeprom.c
  • EXT_EE_READ : SPIeeprom.c
  • EXT_EE_WIP : SPIeeprom.c
  • EXT_EE_WRDI : SPIeeprom.c
  • EXT_EE_WREN : SPIeeprom.c
  • EXT_EE_WRITE : SPIeeprom.c
  • EXT_EE_WRSR : SPIeeprom.c
  • EXT_EEPROM_PAGE_MASK : SPIeeprom.c
  • EXT_EEPROM_PAGE_SIZE : SPIeeprom.h
  • EXT_EEPROM_SIZE : SPIeeprom.h
  • EXT_STATUS_CMD : telecommands.h
  • ExtEepromWriteReady() : SPIeeprom.c

- f -

  • F_CPU : softi2c.h, avrutils.h, adcshdr.h
  • FALSE : avrutils.h

- g -

  • get_parameter() : adcsnode.h, adcsnode.c
  • GET_PARAMETER_CMD : telecommands.h
  • getParamAddr() : adcsnode.h, adcsnode.c

- h -

  • handle_command() : adcsnode.h, adcsnode.c

- i -

  • I2C_BUF_OVERFLOW_BIT : tnccomm.h
  • I2C_BUFFER_RDY_BIT : tnccomm.h
  • I2C_CLOCK_IN_HERTZ : softi2c.h
  • I2C_NUMBER_OF_START_ATTEMPTS : softi2c.h
  • I2C_RETRIES : softi2c.h
  • I2C_SCL_PORT : softi2c.h
  • I2C_SDA_PORT : softi2c.h
  • I2C_TNC_ADDR : tnccomm.h
  • IDLE_STATE : adcsnode.h
  • init_adcs() : adcsnode.h, adcsnode.c
  • init_coils() : coildriver.h, coildriver.c
  • init_detumbling() : adcsnode.h, adcsnode.c
  • init_logging() : adcslog.h, adcslog.c
  • init_magnetometer_comm() : magnetometer.h, magnetometer.c
  • Init_SPI() : SPIeeprom.h, SPIeeprom.c
  • INIT_STATE_MSG : adcsnode.h
  • init_timing() : timingutils.h, timingutils.c
  • init_tnc() : tnccomm.h, tnccomm.c
  • init_twi_slave() : twislave.h, twislave.c
  • initSunsensors() : sunsensors.h, sunsensors.c
  • INPUT_RATE_DELAY : magnetometer.c

- k -

  • k_xy_d : adcsnode.c
  • K_XY_D_PAR : telecommands.h
  • k_xy_n : adcsnode.c
  • K_XY_N_PAR : telecommands.h
  • k_z_d : adcsnode.c
  • K_Z_D_PAR : telecommands.h
  • k_z_n : adcsnode.c
  • K_Z_N_PAR : telecommands.h

- l -

  • lastB_p : adcslog.h, adcslog.c
  • lastBdot_p : adcslog.h, adcslog.c
  • lastDuty : adcslog.h, adcslog.c
  • lastSun_p : adcslog.h, adcslog.c
  • LDR_A : sunsensors.h
  • LDR_B : sunsensors.h
  • LDR_C : sunsensors.h
  • LDR_D : sunsensors.h
  • LDR_N : sunsensors.h
  • LDR_Z : sunsensors.h
  • Ldrs : sunsensors.h
  • log_data() : adcslog.h, adcslog.c
  • LOG_E_FLAG : adcslog.h
  • LOG_E_SEND_FLAG : adcslog.h
  • log_intdata() : adcslog.h, adcslog.c
  • LOG_INTERVAL : adcslog.h
  • log_reset() : adcslog.h, adcslog.c
  • LogCTRL : adcslog.h, adcslog.c
  • logdata_rdy_reg : adcslog.h, adcslog.c
  • logdata_reg : adcslog.h, adcslog.c
  • LOGDATA_SIZE : adcslog.h
  • logdelay : adcslog.c
  • logging_enabled : adcslog.h, adcslog.c
  • logging_started : adcslog.c
  • logperiod : adcslog.c
  • logSunsensors() : adcslog.h, adcslog.c
  • logtimestep : adcslog.h, adcslog.c

- m -

  • m_max : adcsnode.c
  • M_MAX_PAR : telecommands.h
  • MAG_BAUDRATE : magnetometer.c
  • mag_buffer : magnetometer.h, magnetometer.c
  • MAG_CMD : telecommands.h
  • mag_fill_meas_buffer() : magnetometer.h, magnetometer.c
  • mag_is_on() : magnetometer.h, magnetometer.c
  • MAG_MEAS_SIZE : magnetometer.c
  • mag_sampling_rate : magnetometer.h, magnetometer.c
  • MAG_SAMPLINGRATE_PAR : telecommands.h
  • mag_send_command() : magnetometer.h, magnetometer.c
  • mag_send_command_N() : magnetometer.h, magnetometer.c
  • mag_send_command_P() : magnetometer.h, magnetometer.c
  • mag_set_detumbling_params() : magnetometer.h, magnetometer.c
  • mag_set_param_P() : magnetometer.h, magnetometer.c
  • mag_start_stream : magnetometer.h
  • mag_stop_stream : magnetometer.h
  • MAG_TIMEOUT : magnetometer.c
  • MAG_X : magnetometer.h
  • MAG_Y : magnetometer.h
  • MAG_Z : magnetometer.h
  • MAGBUF_ERROR : magnetometer.h
  • MAGBUF_SIZE : magnetometer.h
  • MAGDELAY_PERIOD : adcsnode.h
  • magdelay_period : adcsnode.c
  • MAGDELAY_PERIOD_PAR : telecommands.h
  • MAGOFF_ERROR : adcsnode.h
  • MAGQUERY_CMD : telecommands.h
  • main() : adcsnode.c
  • MAX_DUTY : adcsnode.c
  • mc_z : adcsnode.c
  • MC_Z_PAR : telecommands.h
  • mcu_status : adcsnode.h, adcsnode.c
  • MEASURE_DTBL_STATE : adcsnode.c
  • MEASURE_PERIOD : adcsnode.h
  • measure_period : adcsnode.c
  • MEASURE_PERIOD_PAR : telecommands.h
  • MEASURE_STATE : adcsnode.h
  • measuring_period : adcsnode.c
  • memlog_idx : adcslog.c
  • memorylog : adcslog.c
  • MEMORYLOG_SIZE : adcslog.h
  • MIN_TIMER : timingutils.h
  • MS_TIMER : timingutils.h

- n -

  • next_state : adcsnode.c

- o -

  • OCR2_VALUE : timingutils.c

- p -

  • PAUSE_DOWNLOAD_CMD : telecommands.h
  • prev_state : adcsnode.c
  • print_buf() : debugutils.h, debugutils.c
  • print_int() : adcsnode.c, debugutils.h, debugutils.c
  • print_sint() : adcsnode.c
  • print_state() : debugutils.h, debugutils.c
  • put_P() : debugutils.h, debugutils.c
  • putline_P() : debugutils.h, debugutils.c

- r -

  • read_int() : debugutils.h, debugutils.c
  • ReadByteExtEeprom() : SPIeeprom.h, SPIeeprom.c
  • ReadPageExtEeprom() : SPIeeprom.h, SPIeeprom.c
  • ReadStatusExtEeprom() : SPIeeprom.c
  • RESET_CMD : telecommands.h
  • RESETELOG_CMD : telecommands.h
  • restart_timeout() : timingutils.h, timingutils.c
  • RX_BUF_OVERFLOW : iouart.c
  • RX_Buffer : iouart.c
  • RX_BUFFER_SIZE : iouart.c
  • RX_Counter : iouart.h, iouart.c
  • RX_Rd_Index : iouart.c
  • RX_Wr_Index : iouart.c

- s -

  • sampleSunsensors() : sunsensors.h, sunsensors.c
  • SCL_PIN : softi2c.h
  • SDA_PIN : softi2c.h
  • SEC_TIMER : timingutils.h
  • SendELog() : adcslog.h, adcslog.c
  • sendStatus() : adcsnode.h, adcsnode.c
  • set_bit : avrutils.h
  • set_duty() : coildriver.h, coildriver.c
  • set_parameter() : adcsnode.h, adcsnode.c
  • SET_PARAMETER_CMD : telecommands.h
  • setCoilDuty() : adcsnode.c
  • SETDUTY_CMD : telecommands.h
  • setDutyParams() : adcsnode.h, adcsnode.c
  • SIGNAL() : twislave.c, SPIeeprom.c, timingutils.c, iouart.c
  • SLEEP_CMD : telecommands.h
  • SLEEP_STATE : adcsnode.h
  • Soft_I2C_Write() : softi2c.h
  • SPI_DONE_READ : SPIeeprom.h
  • SPI_IDLE : SPIeeprom.h
  • spi_master_init() : adcsnode.h
  • SPI_MISO : SPIeeprom.c
  • SPI_MOSI : SPIeeprom.c
  • SPI_READ : SPIeeprom.h
  • SPI_SCK : SPIeeprom.c
  • SPI_SS : SPIeeprom.c
  • SPI_WRITE : SPIeeprom.h
  • SPIBuf : SPIeeprom.h, SPIeeprom.c
  • SPIBufPos : SPIeeprom.h, SPIeeprom.c
  • SPIBufSize : SPIeeprom.h, SPIeeprom.c
  • SPIState : SPIeeprom.h, SPIeeprom.c
  • START_DETUMBLING_CMD : telecommands.h
  • start_logging() : adcslog.h, adcslog.c
  • START_LOGGING_CMD : telecommands.h
  • STARTMAG_CMD : telecommands.h
  • StartSendELog() : adcslog.h, adcslog.c
  • State : adcsnode.h
  • state_tbl : adcsnode.c
  • STATUS_CMD : telecommands.h
  • STOP_DETUMBLING_CMD : telecommands.h
  • STOP_DOWNLOAD_CMD : telecommands.h
  • STOP_LOGGING_CMD : telecommands.h
  • STOPMAG_CMD : telecommands.h
  • store_elogstatus() : adcslog.h, adcslog.c
  • store_log_exteeprom() : adcslog.c
  • SUN_LOG : adcslog.h
  • sun_measurements : sunsensors.h, sunsensors.c
  • SUN_SENSORS : sunsensors.h

- t -

  • TCCR2_VALUE : timingutils.c
  • TCNT2_RELOAD_VALUE : timingutils.c
  • test_bit : avrutils.h
  • TIME_L100_US : timingutils.h
  • TIME_L1_MS : timingutils.h
  • timed_out_min : timingutils.h, timingutils.c
  • timed_out_ms : timingutils.h, timingutils.c
  • timed_out_sec : timingutils.h, timingutils.c
  • timeout_counter_min : timingutils.c
  • timeout_counter_ms : timingutils.c
  • timeout_counter_sec : timingutils.c
  • timeout_period_min : timingutils.c
  • timeout_period_ms : timingutils.c
  • timeout_period_sec : timingutils.c
  • timer_reg : timingutils.c
  • Timers : timingutils.h
  • TIMEUPDATE_CMD : telecommands.h
  • TNC_BUFFER_FULL_BIT : tnccomm.h
  • tnc_newline : tnccomm.h
  • tnc_put() : tnccomm.h, tnccomm.c
  • tnc_put_P() : tnccomm.h, tnccomm.c
  • tnc_putchar() : tnccomm.h, tnccomm.c
  • tnc_putchar_n() : tnccomm.h, tnccomm.c
  • tnc_puthex8() : tnccomm.h, tnccomm.c
  • tnc_putline() : tnccomm.h, tnccomm.c
  • tnc_putline_P() : tnccomm.h, tnccomm.c
  • TNC_status_reg : tnccomm.h, tnccomm.c
  • TNC_TX_Counter : tnccomm.c
  • TNC_TX_Rd_Idx : tnccomm.c
  • TNC_TX_Wr_Idx : tnccomm.c
  • TNC_TXBuf : tnccomm.c
  • TNC_TXBUF_SIZE : tnccomm.h
  • TNC_TXBufSize : tnccomm.c
  • toggle_bit : avrutils.h
  • transmit_12c_buffer() : tnccomm.h, tnccomm.c
  • TRUE : avrutils.h
  • TWI_SLAVE_ADDR : adcsnode.h
  • TX_Buffer : iouart.c
  • TX_BUFFER_SIZE : iouart.c
  • TX_Counter : iouart.c
  • TX_PRIMEDIT : iouart.c
  • TX_Rd_Index : iouart.c
  • TX_Wr_Index : iouart.c

- u -

  • uart_disable_rx : iouart.h
  • uart_enable_rx : iouart.h
  • uart_flush_rxbuf() : iouart.h, iouart.c
  • uart_flush_txbuf() : iouart.h, iouart.c
  • uart_getchar() : iouart.h, iouart.c
  • uart_init() : iouart.h, iouart.c
  • uart_putchar() : iouart.h, iouart.c
  • uart_putchar_n() : iouart.h, iouart.c
  • UTC_Second : timingutils.h, timingutils.c

- v -

  • VUART_STATE : adcsnode.h

- w -

  • WAIT_STATE : adcsnode.h
  • WAITSTATE_DELAY_PAR : telecommands.h
  • WriteByteExtEeprom() : SPIeeprom.h, SPIeeprom.c
  • WritePageExtEeprom() : SPIeeprom.h, SPIeeprom.c
  • WriteStatusExtEeprom() : SPIeeprom.c

- x -

  • xeeprom_read_byte : SPIeeprom.h
  • xeeprom_read_page : SPIeeprom.h
  • xeeprom_write_byte : SPIeeprom.h
  • xeeprom_write_page : SPIeeprom.h
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: Page Index

NCUBE ADCS Related Pages

Here is a list of all related documentation pages:
  • Todo List
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: Todo List

Todo List

Global logdata_reg
Should be combinded with LogCTRL

Global mag_fill_meas_buffer (uint8_t n)
Function will loop forever if magnetometer does not output data. A watchdog reset will then occur.

File timingutils.h
Make it easier to change which mcu timer to use.

Add support for multiple timeouts with different periods.

Global tnc_put (char *buf)
Add overflow detection and handling.

Global tnc_put_P (PGM_P addr)
Add overflow detection and handling.

Global tnc_putchar (char c)
Add error handling.

Global tnc_putchar (char c)
Use a function pointer to allow runtime change of communication peripheral.

Global SIGNAL (SIG_2WIRE_SERIAL)
Implement better error handling.
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: adcshdr.h Source File

adcshdr.h

Go to the documentation of this file.
00001 #ifndef _ADCSHDR_H_
00002 #define _ADCSHDR_H_
00003 /**
00004  * @file adcshdr.h
00005  *
00006  * Standard include file for all ADCS modules.
00007  *
00008  *      Changes:
00009  *      2003-10-22 -- File created. -- KMF
00010  *
00011  */
00012 #include <avr/io.h>
00013 #include <stdlib.h>
00014 #include <inttypes.h>
00015 #include <avr/wdt.h>
00016
00017 #define F_CPU 4000000L ///< MCU clock frequency
00018 #define EEPROM_SIGNATURE 232 ///< Signature used to check that the eeprom has been programmed.
00019 #include "avrutils.h"
00020
00021
00022
00023 #endif /* _ADCSHDR_H_ */
00024
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: adcslog.c Source File

adcslog.c

Go to the documentation of this file.
00001 /**
00002  * @file adcslog.c
00003  *
00004  * Implementation of ADCS data logging.
00005  *
00006  */
00007
00008 #include "adcslog.h"
00009 #include "SPIeeprom.h"
00010 #include "magnetometer.h"
00011 #include "timingutils.h"
00012 #include "tnccomm.h"
00013 #include "magnetometer.h"
00014 #include "sunsensors.h"
00015 #include "coildriver.h"
00016 #include <avr/eeprom.h>
00017 #include "eevars.h"
00018 uint8_t volatile logdata_reg = 0;
00019 uint8_t volatile logdata_rdy_reg;
00020
00021 uint8_t logging_enabled;
00022
00023 uint8_t logtimestep = 10;
00024 uint8_t logdelay;
00025 uint8_t logperiod;
00026 uint8_t logging_started = 0;
00027
00028
00029
00030 struct LogEntry memorylog[MEMORYLOG_SIZE];
00031 uint8_t volatile memlog_idx;
00032
00033 // External eeprom storage variables
00034 uint8_t LogCTRL; ///< Internal control flags for external eeprom storage
00035 uint16_t EE_ELogCycle;
00036 uint8_t EE_ELogFull;
00037 uint16_t ELogCycle;
00038 uint8_t ELogFull;
00039 uint8_t ELogSendPage;
00040
00041 magMeasurement *lastB_p;
00042 magMeasurement *lastBdot_p;
00043 struct sunMeasurement *lastSun_p;
00044 struct dutyStruct lastDuty;
00045
00046 void store_elogstatus(void);
00047
00048 void init_logging(void) {
00049         memlog_idx = 0;
00050         LogCTRL = 0;
00051         logging_enabled = 0;
00052         logdata_reg = 0;
00053         logdata_rdy_reg = 0;
00054         if (eeprom_programmed) {
00055                 ELogCycle = eeprom_read_word(&EE_ELogCycle);
00056                 ELogFull = eeprom_read_byte(&EE_ELogFull);
00057         } else {
00058                 ELogCycle = 0;
00059                 ELogFull = 0;
00060                 store_elogstatus();
00061         }
00062
00063 }
00064
00065 void store_elogstatus(void) {
00066         eeprom_write_word((uint16_t*)&EE_ELogCycle, ELogCycle);
00067         eeprom_write_byte((uint8_t *)&EE_ELogFull, ELogFull);
00068 }
00069
00070 void start_logging(uint8_t logflag, uint8_t timestep,
00071         uint8_t delay, uint8_t period) {
00072         logdata_reg = logflag;
00073         logtimestep = timestep;
00074         logdelay = delay;
00075         logperiod = period;
00076         logging_started = 1;
00077         logging_enabled = 1;
00078         enable_timeout(SEC_TIMER, logtimestep);
00079         //enable_timeout(MIN_TIMER, logperiod);
00080 }
00081
00082 /// Store #memorylog in external eeprom.
00083 void store_log_exteeprom(void) {
00084         if ((++ELogCycle)*DATA_PR_LOGINTERVAL>EXT_EEPROM_SIZE) {
00085         ELogCycle = 1;
00086         ELogFull = 1;         //eksternt logg-minne fullt, skriver over eldste data
00087     }
00088     WritePageExtEeprom((uint16_t)((ELogCycle-1)*DATA_PR_LOGINTERVAL), (uint8_t *)(&memorylog[memlog_idx]), DATA_PR_LOGINTERVAL, 1);
00089 }
00090
00091 void log_intdata(uint8_t log_type, int16_t x, int16_t y, int16_t z) {
00092         memlog_idx = 0;
00093         static uint8_t counter = 0;
00094         if (counter >= MEMORYLOG_SIZE) {
00095                 memlog_idx = 0;
00096                 //tnc_putline_P(PSTR("Reset memlog"));
00097                 store_elogstatus();
00098         }
00099         memorylog[memlog_idx].log_type = log_type;
00100         memorylog[memlog_idx].time = (uint16_t)((UTC_Second&0x0000FFFF));
00101         memorylog[memlog_idx].data.iarr[0] = x;
00102         memorylog[memlog_idx].data.iarr[1] = y;
00103         memorylog[memlog_idx].data.iarr[2] = z;
00104         store_log_exteeprom();
00105         counter++;
00106 }
00107
00108
00109 void logSunsensors(void) {
00110         uint8_t i;
00111         memlog_idx = 0;
00112         static uint8_t counter = 0;
00113         if (counter >= MEMORYLOG_SIZE) {
00114                 memlog_idx = 0;
00115                 //tnc_putline_P(PSTR("Reset memlog"));
00116                 store_elogstatus();
00117         }
00118         memorylog[memlog_idx].log_type = SUN_LOG;
00119         memorylog[memlog_idx].time = (uint16_t)((UTC_Second&0x0000FFFF));
00120         for (i=0; i < SUN_SENSORS; i++) {
00121                 memorylog[memlog_idx].data.barr[i] = sun_measurements[i];
00122         }
00123         store_log_exteeprom();
00124         counter++;
00125 }
00126
00127 void StartSendELog(void) {
00128         ELogCycle = eeprom_read_word(&EE_ELogCycle);
00129         ELogFull = eeprom_read_byte(&EE_ELogFull);
00130     tnc_putline_P(PSTR("- Complete log from external eeprom -"));
00131     LogCTRL |= LOG_E_SEND_FLAG;
00132     if (ELogFull) ELogSendPage=ELogCycle;                           //Sender eldste data først
00133     else ELogSendPage=0;
00134     if ((!ELogCycle) && (!ELogFull)) tnc_putline_P(PSTR("\tempty"));
00135     else ReadPageExtEeprom((ELogSendPage)*DATA_PR_LOGINTERVAL);
00136
00137 }
00138
00139 void AbortSendELog(void) {
00140     if (LogCTRL&LOG_E_SEND_FLAG) {
00141         LogCTRL&= ~LOG_E_SEND_FLAG;
00142         tnc_putline_P("- break");
00143     }
00144 }
00145
00146
00147
00148
00149 void SendELog(void) {
00150     unsigned int i;
00151     for (i=0;i<DATA_PR_LOGINTERVAL;i++) {
00152         tnc_puthex8(SPIBuf[i],2);
00153         if (i<DATA_PR_LOGINTERVAL-1) tnc_putchar('-');
00154     }
00155     tnc_putline("");
00156     SPIState&= ~SPI_DONE_READ;
00157     SPIState|=SPI_IDLE;
00158     ELogSendPage++;
00159     i=ELogSendPage*DATA_PR_LOGINTERVAL;
00160     if (i>=EXT_EEPROM_SIZE) ELogSendPage-=(EXT_EEPROM_SIZE/DATA_PR_LOGINTERVAL);
00161     if (ELogSendPage==ELogCycle || !(LogCTRL&LOG_E_SEND_FLAG)) LogCTRL&= ~LOG_E_SEND_FLAG;
00162     else ReadPageExtEeprom(i);
00163
00164 }
00165
00166
00167
00168 void log_reset(void) {
00169     tnc_putline_P(PSTR("Ext. EEPROM reset"));
00170     ELogFull=0;
00171     ELogCycle=0;
00172     store_elogstatus();
00173 }
00174
00175 void log_data(void) {
00176         uint8_t tmp;
00177         tmp = (logdata_reg & logdata_rdy_reg);
00178         if bit_is_set(tmp, B_LOG)  {
00179                 log_intdata(B_LOG, lastB_p->magX, lastB_p->magY, lastB_p->magZ);
00180                 //tnc_putline_P(PSTR("Log B_LOG"));
00181         }
00182         if bit_is_set(tmp, BDOT_LOG) {
00183                 log_intdata(BDOT_LOG, Bdot.magX, Bdot.magY, Bdot.magZ);
00184                 //tnc_putline_P(PSTR("Log BDOT_LOG"));
00185         }
00186         if bit_is_set(tmp, SUN_LOG) {
00187                 //tnc_putline_P(PSTR("Log SUN_LOG"));
00188                 logSunsensors();
00189         }
00190         if bit_is_set(tmp, DUTY_LOG) {
00191                 //tnc_putline_P(PSTR("Log DUTY_LOG"));
00192                 log_intdata(DUTY_LOG, lastDuty.duty_x, lastDuty.duty_y, lastDuty.duty_z);
00193         }
00194         logdata_rdy_reg = 0;
00195         //tnc_put_P(PSTR("Logged "));
00196         //tnc_puthex8(tmp,2);
00197         //tnc_newline();
00198 }
00199
00200
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: adcslog.h Source File

adcslog.h

Go to the documentation of this file.
00001 /**
00002  * @file adcslog.h
00003  *
00004  * Logging of ADCS data.
00005  *
00006  */
00007
00008 #ifndef _ADCSLOG_H_
00009 #define _ADCSLOG_H_
00010
00011 #include "adcshdr.h"
00012 #include "magnetometer.h"
00013 #include "coildriver.h"
00014
00015 #define DATA_PR_LOGINTERVAL 9
00016 #define MEMORYLOG_SIZE          3            //Antall sett med samples som skal logges i minnet (SRAM)
00017 #define LOG_INTERVAL            20            //Antall sekunder mellom hver gang data og samples logges
00018 #define LOGDATA_SIZE            6
00019
00020 #define LOG_E_FLAG                  0x02
00021 #define LOG_E_SEND_FLAG             0x04          //Flagg for å indikere at log fra ekstern eeprom er i ferd med å leses ut og sendes
00022
00023
00024 /**
00025  @name Log flags
00026
00027  @{
00028 */
00029 #define B_LOG                           1
00030 #define BDOT_LOG                        2
00031 #define DUTY_LOG                        3
00032 #define SUN_LOG                         4
00033 //@}
00034
00035 extern magMeasurement *lastB_p; ///< Latest available magnetometer reading
00036 extern magMeasurement *lastBdot_p;      ///< Latest avaiable Bdot estimate
00037 extern struct sunMeasurement *lastSun_p;        ///< Latest available sun sensor readings
00038 extern struct dutyStruct lastDuty;                      ///< Latest available duty cycle output
00039
00040 /**
00041  Single log entry
00042
00043  Every entry in the log has a common format.
00044 */
00045 struct LogEntry {
00046         uint8_t log_type;
00047         uint16_t time;    ///< Time of logging
00048         union {
00049                 uint16_t iarr[LOGDATA_SIZE/2];
00050                 uint8_t barr[LOGDATA_SIZE];
00051         } data;
00052 };
00053
00054
00055 /**
00056  * Log data status register
00057  *
00058  * Tells which data should be logged.
00059  *
00060  * @todo Should be combinded with #LogCTRL
00061  */
00062 extern uint8_t volatile logdata_reg;
00063 /// Log data ready register
00064 extern uint8_t volatile logdata_rdy_reg;
00065 extern uint8_t logging_enabled;
00066 extern uint8_t logtimestep;
00067 extern uint8_t LogCTRL; ///< Internal control flags for external eeprom storage
00068 void init_logging(void);
00069
00070 /**
00071  * Start logging of data.
00072  *
00073  * Set up timer to set flags when data should be logged.
00074  *
00075  * @param logflag What data should be logged.
00076  * @param timestep Number of seconds between each logging of data.
00077  * @param delay Minutes to wait before start logging.
00078  * @param period Number of minutes to do logging.
00079  */
00080 void start_logging(uint8_t logflag, uint8_t timestep, uint8_t delay, uint8_t period);
00081
00082
00083 void log_intdata(uint8_t log_type, int16_t x, int16_t y, int16_t z);
00084
00085 /**
00086  Store sunsensor data in log.
00087 */
00088 void logSunsensors(void);
00089
00090
00091
00092 /**
00093  Log available data and store it in external eeprom
00094
00095  Uses #logdata_reg and #logdata_rdy_reg to determine which data to store.
00096 */
00097 void log_data(void);
00098
00099 void StartSendELog(void);
00100 void AbortSendELog(void);
00101 void SendELog(void);
00102 //void log_download(void);
00103 void log_reset(void);
00104 void store_elogstatus(void);
00105 #endif // _ADCSLOG_H_
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: adcsnode.c Source File

adcsnode.c

Go to the documentation of this file.
00001 /**
00002  * @file adcsnode.c
00003  *
00004  * Implementation of the NCUBE ADCS.
00005  *
00006  */
00007 /* DONE (#1#): Implement measure state */
00008 /* DONE (#1#): Implement LDR interface */
00009 /* DONE (#1#): Implement easy changing of clock frequency
00010  */
00011 /* DONE (#3#): Remove debug putlines */
00012 /* DONE (#1#): Test setting and querying of parameters */
00013 /* DONE (#1#): Add flowcontrol do tnc download */
00014 /* TODO (#2#): Set magnetometer sample rate from memory. */
00015 /* TODO (#1#): Fix bug in log_intdata */
00016 /* DONE (#1#): Combine switch/case in get_parameter and
00017                set_parameter */
00018
00019
00020 #include "adcsnode.h"
00021
00022
00023 #define MEASURE_DTBL_STATE 1
00024 #define ACTUATE_DTBL_STATE 2
00025 #define DELAY_DTBL_STATE 3
00026
00027 #define MAX_DUTY 200
00028
00029 uint8_t mcu_status;
00030
00031 int16_t k_xy_n;
00032 int16_t k_xy_d;
00033 int16_t k_z_n;
00034 int16_t k_z_d;
00035 int16_t mc_z;
00036 uint16_t measure_period;
00037 uint16_t actuate_period;
00038 uint16_t magdelay_period;
00039 uint16_t bdot_min;
00040 uint16_t m_max;
00041
00042 uint8_t detumbling_period, measuring_period;
00043
00044 uint8_t volatile char_received=0;
00045 State current_state = IDLE_STATE;
00046 State next_state;
00047 State prev_state;
00048
00049 State after_wait_state; ///< Which state to enter after the WAIT state.
00050 uint8_t change_state; ///< Tells that state must be changed
00051 /**
00052  Table of pointers to state functions.
00053
00054  The state table maps the states defined in the #State enum to corresponding
00055  functions implementing the states.
00056
00057  The state functions must be on the form
00058  \code
00059  void name(uint8_t msg)
00060  \endcode
00061  where \c msg is a message sent to state when called. Currently two messages
00062  are defined:
00063  - #INIT_STATE_MSG. Sent when state is entered
00064  - #EXIT_STATE_MSG. Sent when state is ended.
00065
00066  An example of entering the wait state:
00067  \code
00068  state_tbl[WAIT_STATE](INIT_STATE_MSG);
00069  \endcode
00070 */
00071
00072 void(*state_tbl[])(uint8_t msg) = {     doIdleState,
00073                                                                         doDetumblingState,
00074                                                                         doMeasuringState,
00075                                                                         doVUartState,
00076                                                                 doDownloadState,
00077                                                         doWaitState,
00078                                                 doSleepState,
00079                                                 doErrorState};
00080
00081
00082 void print_int(uint16_t i) {
00083         uint8_t numbuf[10];
00084         utoa(i, numbuf, 10);
00085         tnc_put(numbuf);
00086         tnc_newline();
00087 }
00088
00089 /// Output signed integer
00090 void print_sint(int16_t i) {
00091         uint16_t tmp;
00092         if (bit_is_set(i, 15)){
00093                 tmp = (~i) + 1;
00094                 tnc_putchar('-');
00095         } else tmp = i;
00096
00097         print_int(tmp);
00098 }
00099
00100 #ifdef MINIMAL
00101 void init_minimal(void) {
00102         // Set ENABLE and DIR low.
00103
00104         //set_bit(COILX_DIR_PORT, COILX_DIR_PIN);
00105         //set_bit(COILY_DIR_PORT, COILY_DIR_PIN);
00106         //set_bit(COILZ_DIR_PORT, COILZ_DIR_PIN);
00107         set_bit(DDRB, COILX_ENABLE_PIN);
00108         set_bit(DDRB, COILY_ENABLE_PIN);
00109         set_bit(DDRB, COILZ_ENABLE_PIN);
00110         clear_bit(COILX_ENABLE_PORT, COILX_ENABLE_PIN);
00111         clear_bit(COILY_ENABLE_PORT, COILY_ENABLE_PIN);
00112         clear_bit(COILZ_ENABLE_PORT, COILZ_ENABLE_PIN);
00113 }
00114 #endif
00115
00116 void init_adcs(void) {
00117         uint8_t eeprom_signature;
00118         init_twi_slave(ADCS_I2C_ADDR);
00119 #ifdef MINIMAL
00120         init_minimal();
00121 #else
00122         // Check that the internale eeprom has been programmed
00123         eeprom_signature =      eeprom_read_byte(&EE_eeprom_signature);
00124         if (eeprom_signature == EEPROM_SIGNATURE) {
00125                 eeprom_programmed = TRUE;
00126         } else {
00127                 eeprom_programmed = FALSE;
00128         }
00129         init_magnetometer_comm();
00130         init_logging();
00131         init_tnc();
00132         init_coils();
00133         Init_SPI(3);
00134
00135         if (!eeprom_programmed) {
00136                 eeprom_write_byte((uint8_t*)&EE_eeprom_signature, EEPROM_SIGNATURE);
00137                 eeprom_programmed = TRUE;
00138         }
00139 #endif
00140         UTC_Second=0;
00141         enable_interrupts();
00142
00143 }
00144
00145 void changeState(State nxt_state) {
00146         next_state = nxt_state;
00147         change_state = 1;
00148 }
00149
00150
00151
00152 uint16_t getParamAddr(uint8_t param_id, uint8_t *param_size) {
00153         uint16_t param_addr;
00154         *param_size = 2;
00155         switch (param_id) {
00156                 case MAG_SAMPLINGRATE_PAR:
00157                         param_addr = (uint16_t)&EE_mag_sampling_rate;
00158                         *param_size = 1;
00159                         break;
00160                 case WAITSTATE_DELAY_PAR:
00161                         param_addr = (uint16_t)&EE_waitstate_delay;
00162                         *param_size = 1;
00163                         break;
00164                 case K_XY_N_PAR:
00165                         param_addr = (uint16_t)&EE_k_xy_n;
00166                         break;
00167                 case K_XY_D_PAR:
00168                         param_addr = (uint16_t)&EE_k_xy_d;
00169                         break;
00170                 case K_Z_N_PAR:
00171                         param_addr = (uint16_t)&EE_k_z_n;
00172                         break;
00173                 case K_Z_D_PAR:
00174                         param_addr = (uint16_t)&EE_k_z_d;
00175                         break;
00176                 case MC_Z_PAR:
00177                         param_addr = (uint16_t)&EE_mc_z;
00178                         break;
00179                 case BDOT_MIN_PAR:
00180                         param_addr = (uint16_t)&EE_bdot_min;
00181                         break;
00182                 case M_MAX_PAR:
00183                         param_addr = (uint16_t)&EE_m_max;
00184                         break;
00185                 case MEASURE_PERIOD_PAR:
00186                         param_addr = (uint16_t)&EE_measure_period;
00187                         break;
00188                 case ACTUATE_PERIOD_PAR:
00189                         param_addr = (uint16_t)&EE_actuate_period;
00190                         break;
00191                 case MAGDELAY_PERIOD_PAR:
00192                         param_addr = (uint16_t)&EE_magdelay_period;
00193                         break;
00194                 case DTMBL_LOGDATA_REG_PAR:
00195                         param_addr = (uint16_t)&EE_dtmbl_logdata_reg;
00196                         *param_size = 1;
00197                         break;
00198                 case DTMBL_LOGTIMESTEP_PAR:
00199                         param_addr = (uint16_t)&EE_dtmbl_logtimestep;
00200                         *param_size = 1;
00201                         break;
00202                 default:
00203                         *param_size = 0xff;
00204                         return 0;
00205                         break;
00206         }
00207         return param_addr;
00208 }
00209 /**
00210  * Set parameter value stored in EEPROM
00211  */
00212 void set_parameter(void) {
00213         uint16_t param_addr; // Parameter address in eeprom
00214         uint8_t param_id, param_size;
00215         uint16_t param_val_int;
00216         //param_size = CmdBuf[CMDBUF_SIZE]-1;
00217         param_id = CmdBuf[CMDBUF_DATA];
00218         param_addr = getParamAddr(param_id, &param_size);
00219         if (param_size == 0xff) {
00220                 tnc_putline(PSTR("Unknown param."));
00221                 return;
00222         }
00223         switch (param_size){
00224                 case 1:
00225                         eeprom_write_byte((uint8_t*)param_addr, CmdBuf[CMDBUF_DATA+1]);
00226                         break;
00227                 case 2:
00228                         param_val_int = ((CmdBuf[CMDBUF_DATA+1] << 8) | CmdBuf[CMDBUF_DATA+2]);
00229                         eeprom_write_word((uint16_t*)param_addr, param_val_int);
00230                         break;
00231                 default:
00232                         break;
00233         }
00234         tnc_putline_P(PSTR("Param. set"));
00235 }
00236
00237 void get_parameter(void) {
00238         uint8_t param_id, param_size;
00239         uint16_t param_addr;
00240         int16_t param_val;
00241         param_id = CmdBuf[CMDBUF_DATA];
00242         param_size = 2;
00243         param_addr = getParamAddr(param_id, &param_size);
00244         if (param_size == 0xff) {
00245                 tnc_putline(PSTR("Unknown param."));
00246                 return;
00247         }
00248
00249         if (param_size == 1) {
00250                 param_val = eeprom_read_byte((uint8_t *)param_addr);
00251         } else if (param_size == 2) {
00252                 param_val = eeprom_read_word((uint16_t *)param_addr);
00253         }
00254         // Send data to TNC
00255         tnc_put_P(PSTR("Param value: "));
00256         if (param_size == 2) {
00257                 if (bit_is_set(param_val, 15)){
00258                         param_val = (~param_val) + 1;
00259                         tnc_putchar('-');
00260                 }
00261         }
00262         print_int(param_val);
00263 }
00264
00265
00266 void setCoilDuty(void) {
00267         int16_t m[3], tmp;
00268         uint8_t n;
00269         disable_coil(CoilAll);
00270         m_max = 255;
00271         m[0] = (CmdBuf[CMDBUF_DATA] << 8) | CmdBuf[CMDBUF_DATA+1];
00272         m[1] = (CmdBuf[CMDBUF_DATA+2] << 8) | CmdBuf[CMDBUF_DATA+1+2];
00273         m[2] = (CmdBuf[CMDBUF_DATA+4] << 8) | CmdBuf[CMDBUF_DATA+1+4];
00274         setDutyParams(m[0], m[1], m[2]);
00275         enable_coil(CoilAll);
00276         for (n = 0; n < 3; n++){
00277                 tmp = m[n];
00278                 tnc_putchar(88+n); // X, Y, Z
00279                 tnc_put_P(PSTR(" duty = "));
00280                 if (bit_is_set(tmp, 15)){
00281                         tmp = (~tmp) + 1;
00282                         tnc_putchar('-');
00283                 }
00284                 print_int(tmp);
00285         }
00286
00287 }
00288
00289 void doMagQuery(void) {
00290         char k = 0;
00291         tnc_putline_P(PSTR("Mag. query:"));
00292         //uart_flush_txbuf();
00293         //uart_flush_rxbuf();
00294         while (k!=CR_CHAR) {
00295                 k = uart_getchar();
00296         }
00297         k = 0;
00298         uart_flush_rxbuf();
00299         mag_send_command_P(PSTR("*00Q"));
00300
00301         while (k!=CR_CHAR) {
00302
00303                 if (RX_Counter) {
00304                         k = uart_getchar();
00305                         tnc_putchar_n(k);
00306                 }
00307         }
00308         tnc_newline();
00309
00310 }
00311
00312 /**
00313  Handle commands received from TeleCommand.
00314 */
00315 void handle_command(void) {
00316         uint8_t i, cmdnum, cmdsize;
00317         //static uint8_t duty = 128;
00318         //static uint8_t dir = 0;
00319         cmdnum = CmdBuf[CMDBUF_ID];
00320         cmdsize = CmdBuf[CMDBUF_SIZE];
00321         switch (cmdnum) {
00322                 case CHAR_CMD:
00323                         uart_putchar(CmdBuf[CMDBUF_DATA]);
00324                         break;
00325                 case MAG_CMD:
00326                         mag_send_command_N(&CmdBuf[CMDBUF_DATA], CmdBuf[CMDBUF_SIZE]);
00327                         tnc_putline_P(PSTR("Mag. command sent."));
00328                         break;
00329                 case MAGQUERY_CMD:
00330                         if (mag_is_on()) {
00331                                 doMagQuery();
00332                         } else{
00333                                 tnc_putline_P(PSTR("Mag. off"));
00334                         }
00335                         break;
00336 /*              case MAGRST_CMD:
00337                         tnc_putline_P(PSTR("ReSet pulse"));
00338                         mag_send_command_P(PSTR("*00]S"));
00339                         break;
00340                 case MAGSET_CMD:
00341                         tnc_putline_P(PSTR("Set pulse"));
00342                         mag_send_command_P(PSTR("*00]R"));
00343                         break;
00344 */
00345                 case STARTMAG_CMD:
00346                         tnc_putline_P(PSTR("Start mag."));
00347                         mag_send_command_P(PSTR("*00C"));
00348                         changeState(VUART_STATE);
00349                         break;
00350                 case STOPMAG_CMD:
00351                         mag_stop_stream();
00352                         tnc_putline_P(PSTR("Stop mag."));
00353                         changeState(IDLE_STATE);
00354                         break;
00355
00356                 case RESET_CMD:
00357                         while(1) {
00358                           ;
00359                          }
00360                         break;
00361 /*              case STARTPWM_CMD:
00362                         set_duty(duty, dir, CoilAll);
00363                         enable_coil(CoilAll);
00364                         tnc_putline_P(PSTR("Coils on"));
00365                         break;
00366                 case TOGGLEDIR_CMD:
00367                         dir = ~dir;
00368                         set_duty(duty, dir, CoilAll);
00369                         tnc_putline_P(PSTR("Direction toggled."));
00370                         break;
00371                 case TOGGLEENABLE_CMD:
00372                         toggle_bit(COILX_ENABLE_PORT, COILX_ENABLE_PIN);
00373                         toggle_bit(COILY_ENABLE_PORT, COILY_ENABLE_PIN);
00374                         toggle_bit(COILZ_ENABLE_PORT, COILZ_ENABLE_PIN);
00375                         tnc_putline_P(PSTR("ENABLE toggled."));
00376                         break;
00377 */
00378                 case SETDUTY_CMD:
00379                         setCoilDuty();
00380                         break;
00381                 case DISABLE_COILS_CMD:
00382                         disable_coil(CoilAll);
00383                         set_duty(0,0,CoilAll);
00384                         tnc_putline_P(PSTR("Coils off"));
00385                         break;
00386                 case SET_PARAMETER_CMD:
00387                         set_parameter();
00388                 break;
00389                 case GET_PARAMETER_CMD:
00390                         get_parameter();
00391                         break;
00392                 case START_DETUMBLING_CMD:
00393                         if (cmdsize == 1) {
00394                                 detumbling_period = CmdBuf[CMDBUF_DATA];
00395                         } else detumbling_period = 0;
00396                         after_wait_state = DETUMBLING_STATE;
00397                         changeState(WAIT_STATE);
00398                         break;
00399                 case STOP_DETUMBLING_CMD:
00400                         changeState(VUART_STATE);
00401                         break;
00402                 case TIMEUPDATE_CMD:
00403                         UTC_Second=0;                        //intern tidssynkronisering (4 byte = long, msByte first)
00404             for (i=CMDBUF_DATA;i<6;i++)
00405                 UTC_Second=UTC_Second*256+CmdBuf[i];
00406
00407             break;
00408         case START_LOGGING_CMD:
00409         /* TODO (#1#): Check correct number of parameters. */
00410                 logdata_reg = CmdBuf[CMDBUF_DATA];
00411                 logtimestep = CmdBuf[CMDBUF_DATA+1];
00412                 if (cmdsize == 3) {
00413                         measuring_period = CmdBuf[CMDBUF_DATA+2];
00414                 } else measuring_period = 0;
00415                 after_wait_state = MEASURE_STATE;
00416                 changeState(WAIT_STATE);
00417                 break;
00418         case STOP_LOGGING_CMD:
00419                 logging_enabled = 0;
00420                 changeState(IDLE_STATE);
00421                 break;
00422
00423         case DOWNLOAD_LOGS_CMD:
00424                 changeState(DOWNLOAD_STATE);
00425                 break;
00426         case STOP_DOWNLOAD_CMD:
00427                 AbortSendELog();
00428                 break;
00429                 case RESETELOG_CMD:
00430                         log_reset();
00431                         break;
00432                 case PAUSE_DOWNLOAD_CMD:
00433                         clear_bit(TNC_status_reg, TNC_BUFFER_FULL_BIT);
00434                         break;
00435                 case CONTINUE_DOWNLOAD_CMD:
00436                         set_bit(TNC_status_reg, TNC_BUFFER_FULL_BIT);
00437                         break;
00438                 case STATUS_CMD:
00439                         sendStatus(0);
00440                         break;
00441                 case EXT_STATUS_CMD:
00442                         sendStatus(1);
00443                         break;
00444                 case SLEEP_CMD:
00445                         changeState(SLEEP_STATE);
00446                         break;
00447                 default:
00448                         // Ignore unknown commands outside the adcs range.
00449                         if ((cmdnum >= CMD_NUM_LOW) && (cmdnum <= CMD_NUM_HIGH)) {
00450                                 tnc_putline_P(PSTR("Unknown ADCS cmd."));
00451                         }
00452                         break;
00453         }
00454         CmdBufRdy=0;
00455     CmdBufSize=0;
00456
00457 }
00458
00459 void doVUartState(uint8_t msg) {
00460         char k;
00461         if (RX_Counter) {
00462                 k = uart_getchar();
00463                 tnc_putchar_n(k);
00464         }
00465 }
00466
00467 void doSleepState(uint8_t msg) {
00468         switch (msg) {
00469                 case INIT_STATE_MSG:
00470                         //tnc_putline_P(PSTR("Entering sleep mode"));
00471                         break;
00472                 case EXIT_STATE_MSG:
00473                         //tnc_putline_P(PSTR("Exiting sleep mode"));
00474                         break;
00475                 default:
00476                         set_sleep_mode(SLEEP_MODE_PWR_DOWN);
00477                         wdt_disable();
00478                         sleep_mode();
00479                         _NOP();
00480                         _NOP();
00481                         wdt_enable(WDTO_1S);
00482                         changeState(IDLE_STATE);
00483                         break;
00484         }
00485 }
00486
00487 void doDownloadState(uint8_t msg) {
00488         switch (msg) {
00489                 case INIT_STATE_MSG:
00490                         StartSendELog();
00491                         break;
00492                 case EXIT_STATE_MSG:
00493                         break;
00494                 default:
00495                         if (!(LogCTRL&LOG_E_SEND_FLAG)) {
00496                                 changeState(IDLE_STATE);
00497                         } else {
00498                                 if bit_is_clear(TNC_status_reg, TNC_BUFFER_FULL_BIT) {
00499                                         if (SPIState&SPI_DONE_READ) SendELog();
00500                                 }
00501                         }
00502                         break;
00503         }
00504 }
00505
00506 void doIdleState(uint8_t msg) {
00507         switch (msg){
00508                 case INIT_STATE_MSG:
00509                         enable_timeout(SEC_TIMER, 5);
00510                         break;
00511                 case EXIT_STATE_MSG:
00512                         disable_timeout(SEC_TIMER);
00513                         break;
00514                 default:
00515                         if (timed_out_sec) {
00516                                 //tnc_putline_P(PSTR("Idle for 10 seconds"));
00517                                 changeState(SLEEP_STATE);
00518                         }
00519                         break;
00520         }
00521 }
00522
00523 void doErrorState(uint8_t msg){
00524         switch (msg){
00525                 case INIT_STATE_MSG:
00526 //                      tnc_putline_P(PSTR("Enter errorstate"));
00527                         break;
00528                 case EXIT_STATE_MSG:
00529                         break;
00530                 default:
00531                         changeState(IDLE_STATE);
00532                         break;
00533         }
00534
00535 }
00536
00537 void doMeasuringState(uint8_t msg) {
00538         uint8_t errorcode;
00539         switch (msg) {
00540                 case INIT_STATE_MSG:
00541                         tnc_putline_P(PSTR("Enter measure state"));
00542                         if (logdata_reg & ((1 << B_LOG) | (1 << BDOT_LOG))) {
00543                                 if (mag_is_on()) {
00544                                         mag_set_detumbling_params();
00545                                         if (bit_is_set(logdata_reg, BDOT_LOG)) {
00546                                                 mag_start_stream();
00547                                         }
00548                                 } else {
00549                                         tnc_putline_P(PSTR("Mag. off"));
00550                                         clear_bit(logdata_reg, B_LOG);
00551                                         clear_bit(logdata_reg, BDOT_LOG);
00552                                         if (logdata_reg == 0) {
00553                                                 changeState(ERROR_STATE);
00554                                                 return;
00555                                         }
00556                                 }
00557                         }
00558                         if (measuring_period) enable_timeout(MIN_TIMER, measuring_period);
00559                         enable_timeout(SEC_TIMER, logtimestep);
00560                         logging_enabled = 0;
00561                         break;
00562                 case EXIT_STATE_MSG:
00563                         if (bit_is_set(logdata_reg, BDOT_LOG)) {
00564                                 mag_stop_stream();
00565                         }
00566                         tnc_putline_P(PSTR("Exit measure state"));
00567                         disable_timeout(SEC_TIMER);
00568                         disable_timeout(MIN_TIMER);
00569                         logging_enabled = 0;
00570                         store_elogstatus();
00571                         break;
00572                 default:
00573                         if(timed_out_sec) {
00574                                 // Get various measurements
00575                                 if (bit_is_set(logdata_reg, BDOT_LOG)) {
00576                                         errorcode = mag_fill_meas_buffer(3);
00577                                         if (errorcode) {
00578                                                 //tnc_putline_P(PSTR("Error"));
00579                                     } else {
00580                                         calcBdot(0,2);
00581                                         lastBdot_p = &Bdot;
00582                                         lastB_p = &mag_buffer[2];
00583                                         set_bit(logdata_rdy_reg, BDOT_LOG);
00584                                         set_bit(logdata_rdy_reg, B_LOG);
00585                                     }
00586
00587                             }
00588                                 if (bit_is_set(logdata_reg, B_LOG) && bit_is_clear(logdata_reg, BDOT_LOG)){
00589                                         uart_flush_rxbuf();
00590                                         mag_send_command_P(PSTR("*00P"));
00591                                         if (!mag_fill_meas_buffer(1)) {
00592                                                 set_bit(logdata_rdy_reg, B_LOG);
00593                                                 lastB_p = &mag_buffer[0];
00594                                         } else {
00595                                                 tnc_putline_P(PSTR("Error"));
00596                                         }
00597
00598
00599                                 }
00600                                 if (bit_is_set(logdata_reg, SUN_LOG)){
00601                                         sampleSunsensors();
00602                                         set_bit(logdata_rdy_reg, SUN_LOG);
00603                                 }
00604
00605                                 //tnc_putline_P(PSTR("Logging"));
00606                                 logging_enabled = 1;
00607                                 //restart_timeout(SEC_TIMER);
00608                         }
00609                 }
00610 }
00611
00612
00613 void doWaitState(uint8_t msg){
00614         uint8_t waitstate_delay;
00615         switch (msg) {
00616                 case INIT_STATE_MSG:
00617                         waitstate_delay = eeprom_read_byte(&EE_waitstate_delay);
00618                         //tnc_putline_P(PSTR("Waiting"));
00619                         //enable_timeout(MIN_TIMER, 1);
00620                         timed_out_min = TRUE;
00621                         break;
00622                 case EXIT_STATE_MSG:
00623                         //disable_timeout(MIN_TIMER);
00624                         break;
00625                 default:
00626                         if (timed_out_min) {
00627                                 changeState(after_wait_state);
00628                         }
00629         }
00630 }
00631
00632
00633 /**
00634  Calculate Bdot
00635
00636  Calculate the numerical derivate of the magnetic field vector using the
00637  formula:
00638  \verbatim
00639  Bdot = ((B[k+1] - B[k-1])*mag_sampling_rate)/2;
00640  \endverbatim
00641
00642  Uses samples stored in #mag_buffer. Result is stored in #Bdot.
00643  @param i_p Index to B[k-1] sample in #mag_buffer.
00644  @param i_n Index to B[k+1] sample in #mag_buffer.
00645 */
00646 void calcBdot(uint8_t i_p, uint8_t i_n) {
00647         Bdot.magX = ((mag_buffer[i_p].MAG_X - mag_buffer[i_n].MAG_X)*mag_sampling_rate)/2;
00648         Bdot.magY = ((mag_buffer[i_p].MAG_Y - mag_buffer[i_n].MAG_Y)*mag_sampling_rate)/2;
00649         Bdot.magZ = ((mag_buffer[i_p].MAG_Z - mag_buffer[i_n].MAG_Z)*mag_sampling_rate)/2;
00650 }
00651
00652 /**
00653  Convert output from controller to duty cycles.
00654 */
00655 void setDutyParams(int16_t m_x, int16_t m_y, int16_t m_z) {
00656     uint8_t dx, dy, dz;
00657     uint8_t dirx, diry, dirz;
00658
00659     // A straight forward conversion form int16_t to uint8_t is potential
00660     // dangerous.
00661     if (abs(m_x) > m_max) {
00662                 dx = MAX_DUTY;
00663         } else {
00664         dx = (uint8_t)abs(m_x);
00665     }
00666
00667     if (abs(m_y) > m_max) {
00668         dy = MAX_DUTY;
00669         } else {
00670         dy = (uint8_t)abs(m_y);
00671     }
00672
00673     if (abs(m_z) > m_max) {
00674         dz = MAX_DUTY;
00675         } else {
00676         dz = (uint8_t)abs(m_z);
00677     }
00678
00679     // Set direction
00680         if (m_x >=0) {
00681                 dirx = 1;
00682                 lastDuty.duty_x = dx;
00683         } else {
00684         dirx = 0;
00685         lastDuty.duty_x = -dx;
00686         }
00687         if (m_y >=0) {
00688                 diry = 1;
00689                 lastDuty.duty_y = dy;
00690         } else {
00691         diry = 0;
00692         lastDuty.duty_y = -dy;
00693         }
00694         if (m_z >=0) {
00695                 dirz = 1;
00696                 lastDuty.duty_z = dz;
00697         } else {
00698         dirz = 0;
00699         lastDuty.duty_z = -dz;
00700         }
00701
00702     set_duty(dx, dirx, CoilX);
00703     set_duty(dy, diry, CoilY);
00704     set_duty(dz, dirz, CoilZ);
00705 }
00706
00707 void doDetumblingState(uint8_t msg) {
00708         uint8_t errorcode;
00709         int16_t m_x, m_y, m_z;
00710         static uint8_t local_state = 0;
00711         switch (msg) {
00712                 case INIT_STATE_MSG:
00713                         tnc_putline_P(PSTR("Start detumbling"));
00714                         errorcode = init_detumbling();
00715                         if (errorcode != 0) {
00716                                 // Set som error variables
00717                                 // log_error(errorcode);
00718                                 tnc_putline_P(PSTR("Mag. off"));
00719                                 //change_mainstate(ERROR_STATE);
00720                                 changeState(ERROR_STATE);
00721                                 return;
00722                         }
00723                         local_state = MEASURE_DTBL_STATE;
00724                         if (detumbling_period) enable_timeout(MIN_TIMER, detumbling_period);
00725                         return;
00726                         break;
00727                 case EXIT_STATE_MSG:
00728                         disable_coil(CoilAll);  // Just in case ...
00729                         set_duty(0,0,CoilAll);
00730                         if (logging_enabled) {
00731                                 disable_timeout(SEC_TIMER);
00732                                 logging_enabled = FALSE;
00733                                 store_elogstatus();
00734                         }
00735                         tnc_putline_P(PSTR("Exit detumbling"));
00736                         local_state = 0;
00737                         disable_timeout(MS_TIMER);
00738                         disable_timeout(MIN_TIMER);
00739                         return;
00740                         break;
00741                 default:
00742                         break;
00743         }
00744         switch (local_state) {
00745                 case MEASURE_DTBL_STATE:
00746                         enable_timeout(MS_TIMER, MEASURE_PERIOD);
00747                         //tnc_putline_P(PSTR("DTBL MEASURE"));
00748                         mag_start_stream();
00749                         while (!timed_out_ms) {
00750                                 errorcode = mag_fill_meas_buffer(3);
00751                                 if (!errorcode) {
00752                                         calcBdot(0,2);
00753                                 } else {
00754                                         continue; //tmp
00755                                 }
00756
00757                         }
00758                         mag_stop_stream();
00759                         //local_state = ACTUATE_DTBL_STATE;
00760                 break;
00761         case ACTUATE_DTBL_STATE:
00762
00763                     //tnc_putline_P(PSTR("DTBL ACTUATE"));
00764                     // Control law
00765                     if (abs(Bdot.magX)>= bdot_min) {
00766                         m_x = -(k_xy_n*Bdot.magX)/k_xy_d;
00767                 } else {
00768                         m_x = 0;
00769                 }
00770                 if (abs(Bdot.magY) >= bdot_min) {
00771                         m_y = -(k_xy_n*Bdot.magY)/k_xy_d;
00772                 } else {
00773                         m_y = 0;
00774                 }
00775                 if (abs(Bdot.magX) >= bdot_min) {
00776                         m_z = -(k_z_n*Bdot.magZ)/k_z_d-mc_z;
00777                 } else {
00778                         m_z = -mc_z;
00779                 }
00780                     setDutyParams(m_x, m_y, m_z);
00781                     enable_coil(CoilAll);
00782                     enable_timeout(MS_TIMER, ACTUATE_PERIOD);
00783                     while (!timed_out_ms) {
00784                         ;
00785                 }
00786                 disable_coil(CoilAll);
00787                         local_state = DELAY_DTBL_STATE;
00788                 break;
00789                 case DELAY_DTBL_STATE:
00790
00791                         //tnc_putline_P(PSTR("DTBL DELAY"));
00792                         enable_timeout(MS_TIMER, MAGDELAY_PERIOD);
00793                         while (!timed_out_ms) {
00794                         ;
00795                 }
00796                         if (bit_is_set(logdata_reg, SUN_LOG)){
00797                                 sampleSunsensors();
00798                                 set_bit(logdata_rdy_reg, SUN_LOG);
00799                         }
00800                         logdata_rdy_reg |= (1 << B_LOG )| (1 << BDOT_LOG) | (1 << DUTY_LOG);
00801                         local_state = MEASURE_DTBL_STATE;
00802                         break;
00803                 default:
00804                 break;
00805     }
00806 }
00807
00808
00809 uint8_t init_detumbling(void) {
00810         uint8_t mag_notinitialized;
00811         if (!mag_is_on()) {
00812                 return MAGOFF_ERROR;
00813         }
00814
00815         // Load controller parameters
00816         k_xy_n = eeprom_read_word(&EE_k_xy_n);
00817         k_xy_d = eeprom_read_word(&EE_k_xy_d);
00818         k_z_n = eeprom_read_word(&EE_k_z_n);
00819         k_z_d = eeprom_read_word(&EE_k_z_d);
00820         mc_z = eeprom_read_word(&EE_mc_z);
00821         bdot_min = eeprom_read_word(&EE_bdot_min);
00822         m_max = eeprom_read_word(&EE_m_max);
00823         measure_period = eeprom_read_word(&EE_measure_period);
00824         actuate_period = eeprom_read_word(&EE_actuate_period);
00825         magdelay_period = eeprom_read_word(&EE_magdelay_period);
00826
00827         // Load log settings
00828         logdata_reg = eeprom_read_byte(&EE_dtmbl_logdata_reg);
00829         if (logdata_reg) {
00830                 logtimestep = eeprom_read_byte(&EE_dtmbl_logtimestep);
00831                 logging_enabled = TRUE;
00832                 if (bit_is_set(logdata_reg, SUN_LOG)) {
00833                         initSunsensors();
00834                 }
00835                 enable_timeout(SEC_TIMER, logtimestep);
00836         }
00837         /*mag_notinitialized = eeprom_read_byte(&EE_mag_notinitialized);
00838         mag_sampling_rate = eeprom_read_byte(&EE_mag_sampling_rate);*/
00839         mag_notinitialized = 1;
00840         mag_sampling_rate = 20;
00841
00842         if (mag_notinitialized) {
00843                 mag_set_detumbling_params();
00844         }
00845         //mag_set_detumbling_params();
00846         return 0;
00847 }
00848
00849 void sendStatus(uint8_t extended) {
00850         tnc_put_P(PSTR("ADCS on. Current state: 0x"));
00851         tnc_puthex8((uint8_t)current_state,2);
00852         tnc_put_P(PSTR(" MCUCSR: 0x"));
00853         tnc_puthex8(mcu_status,2);
00854         tnc_newline();
00855         if (extended) {
00856                 tnc_put_P(PSTR("BdotX "));
00857                 print_sint(Bdot.magX);
00858                 tnc_put_P(PSTR("BdotY "));
00859                 print_sint(Bdot.magY);
00860                 tnc_put_P(PSTR("BdotZ "));
00861                 print_sint(Bdot.magZ);
00862                 //tnc_newline();
00863         }
00864 }
00865
00866 /**
00867  * Main program loop.
00868  */
00869 int main(void) {
00870         mcu_status = MCUCSR; // Read statusregister.
00871         MCUCSR = 0;
00872         wdt_enable(WDTO_2S); // Enable watchodg timer
00873         init_adcs();
00874         //tnc_putline_P(PSTR("ADCS on"));
00875
00876         //----- Start of main program loop -----------------------------
00877         changeState(IDLE_STATE);
00878         while(1) {
00879                 if (CmdBufRdy) handle_command();
00880                 //---- State handling ------------------------------
00881                 if (change_state) {
00882                         change_state = 0;
00883                         state_tbl[current_state](EXIT_STATE_MSG);
00884                         current_state = next_state;
00885                         state_tbl[current_state](INIT_STATE_MSG);
00886                 } else {
00887                         state_tbl[current_state](0);
00888                 }
00889
00890                 if (bit_is_set(TNC_status_reg, I2C_BUFFER_RDY_BIT)) {
00891                         // Transmit data to TNC
00892                         transmit_12c_buffer();
00893
00894                 }
00895
00896                 // Housekeeping
00897                 if (logging_enabled) {
00898                         if (timed_out_sec) { // Periodic logging of data and measurements
00899                                 log_data();
00900                                 restart_timeout(SEC_TIMER);
00901                         }
00902
00903                 }
00904                 wdt_reset(); // reset watchdog timer
00905         }
00906 }
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: adcsnode.h Source File

adcsnode.h

Go to the documentation of this file.
00001 /**
00002  * @file adcsnode.h
00003  * NCUBE attitude control system.
00004  *
00005  * @author Kjell Magne Fauske
00006  */
00007 #ifndef _ADCSNODE_H_
00008 #define _ADCSNODE_H_
00009
00010
00011 // avr-gcc inlcudes
00012 #include <avr/delay.h>
00013 #include <avr/signal.h>
00014 #include <avr/interrupt.h>
00015 #include <avr/pgmspace.h>
00016 #include <avr/eeprom.h>
00017 #include <avr/sleep.h>
00018 #include <stdlib.h>
00019
00020 #include "adcshdr.h"
00021 #include "telecommands.h"
00022 #include "iouart.h"
00023 #include "twislave.h"
00024 #include "magnetometer.h"
00025 #include "tnccomm.h"
00026 #include "coildriver.h"
00027 #include "SPIeeprom.h"
00028 #include "timingutils.h"
00029 #include "adcslog.h"
00030 #include "eevars.h"
00031 #include "sunsensors.h"
00032
00033 /// Main ADCS states
00034 typedef enum{
00035         IDLE_STATE = 0,   ///< Nothing to do
00036         DETUMBLING_STATE, ///< Detumbling
00037         //CONFIG_STATE, ///< Configuration
00038         MEASURE_STATE, ///< Measure
00039         //DEBUG_STATE, ///< Debug
00040         VUART_STATE, ///< Virtual UART
00041         DOWNLOAD_STATE, ///< Download data
00042         WAIT_STATE, ///< Wait to start detumbling og measure state.
00043         SLEEP_STATE,  ///< Power save mode
00044         ERROR_STATE ///< Error state
00045 } State;
00046
00047
00048 #define INIT_STATE_MSG 254
00049 #define EXIT_STATE_MSG 255
00050
00051 #define TWI_SLAVE_ADDR 0x10
00052 //#define ADCS_I2C_ADDR     0x76
00053 #define ADCS_I2C_ADDR     0x77 // General call recognition enabled.
00054
00055
00056 ///@name Detumbling parameters
00057 ///@{
00058 #define MAGOFF_ERROR 1 /// No response from magnetometer.
00059 #define MEASURE_PERIOD 500 /// Magnetometer measure period in ms.
00060 #define ACTUATE_PERIOD 500 /// Actuation period in ms.
00061 #define MAGDELAY_PERIOD 500 /// Delay in ms between actuation and measuring.
00062 ///@}
00063
00064 extern uint8_t mcu_status; ///< MCUCSR storage.
00065
00066 /**
00067  * Initialize device as SPI master.
00068  */
00069 void spi_master_init(void);
00070
00071
00072 /**
00073  * Initialize NCUBE ADCS software.
00074  */
00075 void init_adcs(void);
00076
00077 /// Change main ADCS state.
00078 void changeState(State nxt_state);
00079
00080 /// Handle commands received from Telecommand decoder.
00081 void handle_command(void);
00082
00083 /**
00084  * IDLE state handler.
00085  *
00086  * In the IDLE state the mcu has nothing to do. If the mcu is idle
00087  * for a specific period of time, sleep state is entered.
00088  */
00089 void doIdleState(uint8_t msg);
00090
00091
00092 /**
00093  Detubmling state handler
00094 */
00095 void doDetumblingState(uint8_t msg);
00096 void doMeasuringState(uint8_t msg);
00097 /// Virtual uart state.
00098 void doVUartState(uint8_t msg);
00099 void doDownloadState(uint8_t msg);
00100
00101 void doMagQuery(void);
00102
00103 /**
00104  * WAIT state handler
00105  *
00106  * Wait state is entered before detumbling or measure state. The next state
00107  * is determined by reading the #after_wait_state var.
00108  */
00109 void doWaitState(uint8_t msg);
00110 void doMeasuring(uint8_t msg);
00111 void doSleepState(uint8_t msg);
00112 void doErrorState(uint8_t msg);
00113
00114 /**
00115  Initialize system for detumbling.
00116
00117  Check that magnetometer is switched on and that the magnetometer is properly
00118  set up by reading the #EE_mag_notinitialized parameter.
00119  @return \c 0 if successfull. Otherwise an error code is returned.
00120 */
00121 uint8_t init_detumbling(void);
00122
00123 /**
00124  * Set parameter value stored in EEPROM
00125  */
00126 void set_parameter(void);
00127
00128 /**
00129  * Query parameter stored in EEPROM
00130  *
00131  * Called when the #GET_PARAMETER_CMD is received. Value sent to tnc.
00132  */
00133 void get_parameter(void);
00134
00135 void calcBdot(uint8_t i_p, uint8_t i_n);
00136
00137 /**
00138  Return address and size of parameter stored in EEPROM
00139
00140  @param param_id ID of command. See documentation for #SET_PARAMETER_CMD
00141  @param *param_size Address of variable to store the parameter size
00142  @return Address and size of parameter.
00143 */
00144 uint16_t getParamAddr(uint8_t param_id, uint8_t *param_size);
00145
00146 /**
00147  Convert output from controller to duty cycles.
00148 */
00149 void setDutyParams(int16_t m_x, int16_t m_y, int16_t m_z);
00150
00151
00152 /**
00153  Download ADCS status
00154
00155  @param extended Set to true to display an extended status report.
00156 */
00157 void sendStatus(uint8_t extended);
00158
00159 #endif // _ADCSNODE_H_
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: avrutils.h Source File

avrutils.h

Go to the documentation of this file.
00001 /**
00002  * @file avrutils.h
00003  *
00004  * Various macro utilities for the AVR.
00005  */
00006 #ifndef _AVRUTILS_H_
00007 #define _AVRUTILS_H_
00008
00009 #ifndef F_CPU
00010 #define F_CPU 8000000L
00011 #endif
00012
00013 #ifndef EEPROM
00014 #define EEPROM __attribute__ ((section (".eeprom")))
00015 #endif
00016
00017 #ifndef TRUE
00018 #define TRUE 1
00019 #endif
00020
00021 #ifndef FALSE
00022 #define FALSE 0
00023 #endif
00024
00025 ///@name Bit manipulation macros.
00026 ///@{
00027 /**
00028  * Set a single bit in a register.
00029  */
00030 #define set_bit(reg, bit) reg |= (1 << bit)
00031
00032 /**
00033  * Clear a single bit in a register.
00034  */
00035 #define clear_bit(reg, bit) reg &= ~(1 << bit)
00036
00037 /**
00038  * Toggle a single bit in a register on or off.
00039  */
00040 #define toggle_bit(reg, bit) reg ^= (1 << bit)
00041
00042 /**
00043  * Alias for bit_is_set()
00044  */
00045 #define test_bit bit_is_set
00046
00047 /**
00048  * Assign a logical value to a specific bit in a register.
00049  */
00050 #define assign_bit(reg, bit, val) (val)?(set_bit(reg, bit)):(clear_bit(reg,bit))
00051 ///@}
00052
00053 ///@name Debug utilities.
00054 ///@{
00055 /**
00056  *      Insert a break instruction for JTAG debugging.
00057  */
00058 #define avr_break() __asm__ __volatile__ ("break" ::)
00059 //@}
00060
00061
00062 ///@name IAR compatibility macros
00063 ///@{
00064 ///  Enable interrupts.
00065 #define __enable_interrupt() sei()
00066
00067 /// Insert a no operation opcode
00068 #define _NOP() __asm__ __volatile__ ("nop" ::)
00069
00070 #define enable_interrupts() sei();
00071
00072 /// Disable interrupts.
00073 #define __disable_interrupt() cli()
00074
00075 #define disable_interrupts() cli()
00076 ///@}
00077
00078
00079
00080 #endif // _AVRUTILS_H_
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: coildriver.c Source File

coildriver.c

Go to the documentation of this file.
00001 /**
00002  * @file coildriver.c
00003  *
00004  * Implementation of the coil driver module.
00005  */
00006 #include "coildriver.h"
00007 #include "adcslog.h"
00008  ///@name Register definitions
00009 //@{
00010 #define COILX_DUTY_REG OCR0  ///< Coil X duty cycle register.
00011 #define COILY_DUTY_REG OCR1A ///< Coil Y duty cycle register.
00012 #define COILZ_DUTY_REG OCR1B ///< Coil Z duty cycle register.
00013 //@}
00014
00015 void init_coils(void) {
00016     // Set PWM pins as outputs
00017         DDRB |= (1 << COILX_PWM_PIN);
00018         DDRD |= (1 << COILY_PWM_PIN) | ( 1 << COILZ_PWM_PIN);
00019         PORTB &= ~(1 << COILX_PWM_PIN);
00020         PORTD &= ~((1 << COILY_PWM_PIN) | ( 1 << COILZ_PWM_PIN));
00021
00022         // Timer0 initialization
00023         TCCR0 |= (1 << WGM00); // Select  Phase correct PWM mode
00024         TCCR0 |= (1 << CS00);  // No prescaling
00025         // Timer1 initialization
00026         TCCR1A |= (1 << WGM10); // Set mode 1: PWM, phase correct 8-bit
00027         TCCR1B |= (1 << CS10);  // No prescaling
00028         // Set ENABLE and DIR low.
00029         ENABLE_DDR |= (1 << COILX_ENABLE_PIN) | (1 << COILY_ENABLE_PIN) |(1 << COILZ_ENABLE_PIN);
00030         DIR_DDR |= (1 << COILX_DIR_PIN) | ( 1 << COILY_DIR_PIN)| (1 << COILZ_DIR_PIN);
00031         clear_bit(COILX_ENABLE_PORT, COILX_ENABLE_PIN);
00032         clear_bit(COILY_ENABLE_PORT, COILY_ENABLE_PIN);
00033         clear_bit(COILZ_ENABLE_PORT, COILZ_ENABLE_PIN);
00034         clear_bit(COILX_DIR_PORT, COILX_DIR_PIN);
00035         clear_bit(COILY_DIR_PORT, COILY_DIR_PIN);
00036         clear_bit(COILZ_DIR_PORT, COILZ_DIR_PIN);
00037 }
00038
00039
00040 void enable_coil(Coils coil) {
00041         switch (coil) {
00042                 case CoilAll:
00043                         TCCR0 |= (1 << COM01);
00044                         TCCR1A |= (1 << COM1A1)|(1 << COM1B1);
00045                         set_bit(COILX_ENABLE_PORT, COILX_ENABLE_PIN);
00046                 set_bit(COILY_ENABLE_PORT, COILY_ENABLE_PIN);
00047                 set_bit(COILZ_ENABLE_PORT, COILZ_ENABLE_PIN);
00048                         break;
00049                 case CoilX:
00050                         TCCR0 |= (1 << COM01);
00051                         set_bit(COILX_ENABLE_PORT, COILX_ENABLE_PIN);
00052                         break;
00053                 case CoilY:
00054                         TCCR1A |= (1 << COM1A1);
00055                         set_bit(COILY_ENABLE_PORT, COILY_ENABLE_PIN);
00056                         break;
00057                 case CoilZ:
00058                         TCCR1A |= (1 << COM1B1);
00059                         set_bit(COILZ_ENABLE_PORT, COILZ_ENABLE_PIN);
00060                         break;
00061                 default:
00062                         break;
00063         }
00064 }
00065
00066 void disable_coil(Coils coil) {
00067         switch (coil) {
00068                 case CoilAll:
00069                         TCCR0 &= ~(1 << COM01);
00070                         TCCR1A &= ~((1 << COM1A1)|(1 << COM1B1));
00071                         clear_bit(COILX_ENABLE_PORT, COILX_ENABLE_PIN);
00072                 clear_bit(COILY_ENABLE_PORT, COILY_ENABLE_PIN);
00073                 clear_bit(COILZ_ENABLE_PORT, COILZ_ENABLE_PIN);
00074
00075                         break;
00076                 case CoilX:
00077                         TCCR0 &= (1 << COM01);
00078                         clear_bit(COILX_ENABLE_PORT, COILX_ENABLE_PIN);
00079                         break;
00080                 case CoilY:
00081                         TCCR1A &= (1 << COM1A1);
00082                         clear_bit(COILY_ENABLE_PORT, COILY_ENABLE_PIN);
00083                         break;
00084                 case CoilZ:
00085                         TCCR1A &= (1 << COM1B1);
00086                         clear_bit(COILZ_ENABLE_PORT, COILZ_ENABLE_PIN);
00087                         break;
00088                 default:
00089                         break;
00090         }
00091 }
00092
00093 void set_duty(uint8_t duty_cycle, uint8_t direction, Coils coil) {
00094         switch (coil) {
00095                 case CoilAll:
00096                         COILX_DUTY_REG = duty_cycle;
00097                         COILY_DUTY_REG = duty_cycle;
00098                         COILY_DUTY_REG = duty_cycle;
00099                         assign_bit(COILX_DIR_PORT, COILX_DIR_PIN, direction);
00100                         assign_bit(COILY_DIR_PORT, COILY_DIR_PIN, direction);
00101                         assign_bit(COILZ_DIR_PORT, COILZ_DIR_PIN, direction);
00102                         break;
00103                 case CoilX:
00104                         COILX_DUTY_REG = duty_cycle;
00105                         assign_bit(COILX_DIR_PORT, COILX_DIR_PIN, direction);
00106                         break;
00107                 case CoilY:
00108                         COILY_DUTY_REG = duty_cycle;
00109                         assign_bit(COILY_DIR_PORT, COILY_DIR_PIN, direction);
00110                         break;
00111                 case CoilZ:
00112                         COILZ_DUTY_REG = duty_cycle;
00113                         assign_bit(COILZ_DIR_PORT, COILZ_DIR_PIN, direction);
00114                         break;
00115                 default:
00116                         break;
00117         }
00118 }
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: coildriver.h Source File

coildriver.h

Go to the documentation of this file.
00001 #ifndef _COILDRIVER_H_
00002 #define _COILDRIVER_H_
00003 /**
00004  * @file coildriver.h
00005  * Magnetic coil driver module.
00006  *
00007  * The current through each coil is controlled with a PWM signal.
00008  * Three MCU PWM channels are used. A H-bridge is used for each
00009  * coil to control direction. Additionally a signal is used to enable
00010  * current to flow through a coil.
00011  *
00012  * \par Pin and timer usage
00013  * Timer0 and Timer1 are used for PWM generation. Timer0 is a 8-bit timer,
00014  * while Timer1 is a 16-bit timer. However, Timer1 is divided into two
00015  * 8-bit timers. The timers are connected to the OC0, OC1A and OC1B pins,
00016  * corresponing to CoilX, CoilY and CoilZ respectively.
00017  *
00018  * Changes:
00019  * - 2003-10-22 -- File created
00020  * - 2004-02-18 -- Changed pins according to PCB layout.
00021  * - 2004-09-02 -- Changed pins for coilX and coilY
00022  */
00023 #include "adcshdr.h"
00024
00025 /** @name Pin and port definitions
00026  Pins and ports are given symbolic names to ease portability
00027  between different MCUs.
00028
00029  @note
00030  2004-09-02 There is a difference between the X, and Z axes internally and
00031  in the schematics. The X_Enable and X_PWM lines in the schematics corresponds
00032  to the internal Z axis.
00033 @{
00034 */
00035 #define COILX_PWM_PIN PD4 ///< PWM pin for coil X.
00036 #define COILY_PWM_PIN PD5 ///< PWM pin for coil Y.
00037 #define COILZ_PWM_PIN PB3 ///< PWM pin for coil Z.
00038
00039 #define COILX_PWM_PORT PORTD ///< Port used for coil X PWM pin.
00040 #define COILY_PWM_PORT PORTD ///< Port used for coil Y PWM pin.
00041 #define COILZ_PWM_PORT PORTB ///< Port used for coil Z PWM pin.
00042
00043 #define COILX_ENABLE_PIN PB2 ///< Enable pin for coil X.
00044 #define COILY_ENABLE_PIN PB1 ///< Enable pin for coil Y.
00045 #define COILZ_ENABLE_PIN PB0 ///< Enable pin for coil Z.
00046
00047 #define COILX_ENABLE_PORT PORTB ///< Enable pin port for coil X.
00048 #define COILY_ENABLE_PORT PORTB ///< Enable pin port for coil Y.
00049 #define COILZ_ENABLE_PORT PORTB ///< Enable pin port for coil Z.
00050
00051 #define ENABLE_DDR DDRB ///< Direction port for enable pins
00052
00053 #define COILX_DIR_PIN PD7 ///< Direction pin for coil X.
00054 #define COILY_DIR_PIN PD6 ///< Direction pin for coil Y.
00055 #define COILZ_DIR_PIN PD3 ///< Direction pin for coil Z.
00056
00057 #define COILX_DIR_PORT PORTD ///< Direction pin port for coil X.
00058 #define COILY_DIR_PORT PORTD ///< Direction pin port for coil Y.
00059 #define COILZ_DIR_PORT PORTD ///< Direction pin portfor coil Z.
00060
00061 #define DIR_DDR DDRD
00062
00063
00064 //@}
00065
00066 /**
00067  * @name Coil parameters
00068  * Parameters for calculating the magnetic moments. Cross sections are
00069  * given in m*1000
00070  */
00071
00072 //@{
00073 #define COILX_N 120 ///< Number of windings in coil X
00074 #define COILY_N 120 ///< Number of windings in coil Y
00075 #define COILZ_N 120 ///< Number of windings in coil Z
00076
00077 #define COILX_A 64 ///< Cross section area of coil X.
00078 #define COILY_A 64 ///< Cross section area of coil Z.
00079 #define COILZ_A 64 ///< Cross section area of coil Z.
00080 //@}
00081
00082 /**
00083  * Coil selection.
00084  *
00085  * Used for coil selection.
00086  */
00087 typedef enum {
00088         CoilAll, ///< Select all.
00089         CoilX,   ///< Select coil X.
00090         CoilY,   ///< Select coil Y.
00091         CoilZ    ///< Select coil Z.
00092 } Coils;
00093
00094 /**
00095  Structure for storing duty cycle values.
00096
00097  @note
00098  Signed 16-bit integers are used to store the duty cycles and directions.
00099  However, this is a bit waste of memory.
00100 */
00101 struct dutyStruct {
00102         int16_t duty_x;
00103         int16_t duty_y;
00104         int16_t duty_z;
00105 };
00106
00107 /**
00108  * Initialize coils.
00109  *
00110  * Initialize control pins and PWM channels.
00111  * @note PWM output pins are not connected.
00112  *       ENABLE and DIRECTION pins are set low.
00113  */
00114 void init_coils(void);
00115
00116 /**
00117  * Enable coil.
00118  *
00119  * Connect one or all PWM channels to their assigned OCn pin. ENABLE
00120  * signal is set.
00121  *
00122  * @param coil Coil.
00123  */
00124 void enable_coil(Coils coil);
00125
00126 /**
00127  * Disable coil.
00128  *
00129  * Disconnect one or all PWM channels from their assgined OCn pin and clear
00130  * ENABLE.
00131  * @param coil Coil.
00132  */
00133 void disable_coil(Coils coil);
00134
00135 /**
00136  * Set duty cycle and direction.
00137  *
00138  * @param duty_cycle On time. Ranging from 0 (0%) to 255 (100%)
00139  * @param direction Direction of current in coil.
00140  * @param coil Coil.
00141  */
00142 void set_duty(uint8_t duty_cycle, uint8_t direction, Coils coil);
00143
00144
00145 #endif /* _COILDRIVER_H_ */
00146
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: debugutils.c Source File

debugutils.c

Go to the documentation of this file.
00001 /** @file debugutils.c
00002  * @brief Implementation of various debug utilities.
00003  * @author Kjell Magne Fauske
00004  *
00005  */
00006
00007 #include "debugutils.h"
00008 #include "adcshdr.h"
00009 #include <stdlib.h>
00010
00011 #include "iouart.h"
00012
00013
00014 void print_state(uint8_t state) {
00015         if (state) {
00016                 debug_P(PSTR("HIGH\n"));
00017         } else {
00018                 debug_P(PSTR("LOW\n"));
00019         }
00020 }
00021
00022 /*
00023  *      read_int()
00024  *  tmptmp
00025  *      Read a number from UART. Number is entered as a string, then converted.
00026  *      A CR char is used to indicate end of number.
00027  *      Returns:
00028  *              int
00029  */
00030
00031 int read_int(void) {
00032         uint8_t k, pos;
00033         uint8_t numbuf[10];
00034         int tmp;
00035         pos = 0;
00036         while ((k!=13)) {
00037                 k = uart_getchar();
00038                 uart_putchar(k);
00039                 if (pos < (10-1)) {
00040                         numbuf[pos++] = k;
00041                 } else {
00042                         break;
00043                 }
00044         }
00045         numbuf[pos] = 0;
00046         tmp = atoi(numbuf);
00047         return tmp;
00048 }
00049
00050
00051 void print_buf(char *buf) {
00052         while(*buf) {
00053                 uart_putchar_n(*buf++);
00054         }
00055 }
00056
00057 /*
00058  *      print_int()
00059  *
00060  *      Print an integer throug the UART
00061  */
00062 void print_int(uint16_t i) {
00063         uint8_t numbuf[10];
00064         utoa(i, numbuf, 10);
00065         print_buf(numbuf);
00066 }
00067
00068 void debug_P(PGM_P addr)
00069 {
00070   char c;
00071   while ((c = __LPM((unsigned short)addr++)))
00072     uart_putchar_n(c);
00073 }
00074
00075 void putline_P(PGM_P addr) {
00076         debug_P(addr);
00077         uart_putchar_n('\n');
00078 }
00079
00080 void put_P(PGM_P addr) {
00081         debug_P(addr);
00082 }
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: debugutils.h Source File

debugutils.h

Go to the documentation of this file.
00001 /** @file debugutils.h
00002  * @brief Various utility functions for reading and printing data for debugging.
00003  *
00004  * Changes:
00005  * - 2003-01-10 File created
00006  * - 2003-01-11 sdfsdf
00007  *
00008  * @author Kjell Magne Fauske
00009  *
00010  */
00011 #ifndef _DEBUGUTILS_H_
00012 #define _DEBUGUTILS_H_
00013 #include "adcshdr.h"
00014 #include <avr/pgmspace.h>
00015
00016
00017 /**
00018  * Read an integer from UART.
00019  *
00020  * Read a number from UART. Number is entered as a string, then converted.
00021  * A CR char is used to indicate end of number.
00022  * @return An interger.
00023  */
00024 int read_int(void);
00025
00026 /**
00027  * Print logical value.
00028  *
00029  * Prints LOW if input value is 0. Prints HIGH otherwise.
00030  *
00031  * @param state State variable
00032  */
00033 void print_state(uint8_t state);
00034
00035 void print_buf(char *buf);
00036
00037 /**
00038  * Print an integer throug the UART
00039  */
00040 void print_int(uint16_t i);
00041
00042 /**
00043  * Print a string stored in FLASH memory
00044  * @param addr pointer to string stored in flash.
00045  *
00046  * Example:
00047  * \code
00048  * debug_P(PSTR("This is a string in FLASH\n"));
00049  * \endcode
00050  */
00051 void debug_P(PGM_P addr);
00052
00053 /**
00054  * Print a string stored in FLASH and append a newline char.
00055  *
00056  * @param addr Pointer to string stored in flash. See debug_P() for an example.
00057  */
00058 void putline_P(PGM_P addr);
00059
00060 /**
00061  * Print a string stored in FLASH
00062  *
00063  * @param addr Pointer to string stored in flash. See debug_P() for an example.
00064  */
00065 void put_P(PGM_P addr);
00066 #endif /* _DEBUGUTLS_H_ */
Generated on Fri Sep 3 17:21:12 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: eevars.c Source File

eevars.c

Go to the documentation of this file.
00001 /**
00002  @file eevars.c
00003
00004 */
00005
00006 #include "eevars.h"
00007 #include <avr/eeprom.h>
00008 #include "adcshdr.h"
00009
00010 const uint8_t EE_eeprom_signature EEPROM = EEPROM_SIGNATURE;
00011 uint8_t eeprom_programmed;
00012 const uint8_t EE_waitstate_delay EEPROM = 5; ///< Minutes to wait before detumbling or measure state
00013
00014
00015 const uint8_t EE_mag_sampling_rate EEPROM = 50;
00016
00017 /**
00018  Cleared if magnetometer is initialized for detumbling.
00019
00020  \warning
00021  Internal EEPROM must be initialized when program is downloaded. Otherwise
00022  value will be non-zero.
00023 */
00024 const uint8_t EE_mag_notinitialized EEPROM = 1;
00025
00026
00027
00028 //const int8_t EE_mz_c EEPROM = 30;
00029 const int16_t EEPROM EE_k_xy_n = 0;
00030 const int16_t EEPROM EE_k_xy_d = 0;
00031 const int16_t EEPROM EE_k_z_n = 0;
00032 const int16_t EEPROM EE_k_z_d = 0;
00033 const int16_t EEPROM EE_mc_z = 50;
00034
00035 const uint16_t EEPROM EE_bdot_min = 10;
00036 const uint16_t EEPROM EE_m_max = 255;
00037 const uint8_t EEPROM EE_dtmbl_logdata_reg = 0x0F;
00038 const uint8_t EEPROM EE_dtmbl_logtimestep = 4;
00039
00040 const uint16_t EE_measure_period = 500;  // MS to measure
00041 const uint16_t EE_actuate_period = 500;  // MS to actuate
00042 const uint16_t EE_magdelay_period = 500; // MS to wait after actuate period.
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: eevars.h Source File

eevars.h

Go to the documentation of this file.
00001 /**
00002  @file eevars.h
00003
00004  Definition of variables stored in eeprom.
00005
00006  Can be changed using the #SET_PARAMETER_CMD tele command.
00007
00008 */
00009 #ifndef _EEVARS_H_
00010 #define _EEVARS_H_
00011 #include "adcshdr.h"
00012
00013
00014 /**
00015  Signature used to check that the eeprom has been programmed.
00016
00017  The signature is set to #EEPROM_SIGNATURE.
00018  \note
00019  When the AVR is programmed the internal eeprom is often wiped out and filled
00020  with \c 0xFF. When compiling with avr-gcc a separate eep file is created which
00021  can be downloaded to the mcu.
00022 */
00023 extern const uint8_t EE_eeprom_signature;
00024
00025 /**
00026  Set if the internal eeprom is programmed.
00027
00028  The variable is set during ADCS initalization in #init_adcs()
00029 */
00030 extern uint8_t eeprom_programmed;
00031
00032 /**
00033  Magnetometer sample rate
00034
00035  Sampling rate can be set to 10, 20, 25, 30, 40, 50, 60, 100, 123 or 154 samples/sec.
00036 */
00037 extern const uint8_t EE_mag_sampling_rate;
00038 /// Cleared if  magnetometer has been properly initialized for detumbling
00039 extern const uint8_t EE_mag_notinitialized;
00040 extern const uint8_t EE_waitstate_delay; ///< Minutes to wait before detumbling or measure state
00041
00042 /**
00043  @name Controller parameters
00044
00045  Various parameters are available for tuning the detumbling controller.
00046
00047  @warning
00048  Make sure the parameters are properly initialized before starting detumbling.
00049
00050  @{
00051 */
00052
00053 extern const int16_t EE_k_xy_n;
00054 extern const int16_t EE_k_xy_d;
00055 extern const int16_t EE_k_z_n;
00056 extern const int16_t EE_k_z_d;
00057 extern const int16_t EE_mc_z;
00058
00059 extern const uint16_t EE_bdot_min;
00060 extern const uint16_t EE_m_max;
00061
00062 extern const uint16_t EE_measure_period;  ///< MS to measure
00063 extern const uint16_t EE_actuate_period;  ///< MS to actuate
00064 extern const uint16_t EE_magdelay_period; ///< MS to wait after actuate period.
00065 //@}
00066
00067 /**
00068  @name Logging parameters
00069
00070  Which data to log, and how often, during detumbling
00071
00072  @{
00073 */
00074 extern const uint8_t EE_dtmbl_logdata_reg;
00075 extern const uint8_t EE_dtmbl_logtimestep;
00076 //@}
00077 #endif // _EEVARS_H_
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: Compound Member Index

  • barr : LogEntry
  • data : LogEntry
  • duty_x : dutyStruct
  • duty_y : dutyStruct
  • duty_z : dutyStruct
  • iarr : LogEntry
  • log_type : LogEntry
  • magX : magMeasurement
  • magY : magMeasurement
  • magZ : magMeasurement
  • time : LogEntry
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: File Member Index

- _ -

  • __disable_interrupt : avrutils.h
  • __enable_interrupt : avrutils.h
  • _NOP : avrutils.h
  • _SUNSENSORSH_H_ : sunsensors.h

- a -

  • ACTUATE_DTBL_STATE : adcsnode.c
  • ACTUATE_PERIOD : adcsnode.h
  • ACTUATE_PERIOD_PAR : telecommands.h
  • ADCS_I2C_ADDR : adcsnode.h
  • assign_bit : avrutils.h
  • avr_break : avrutils.h

- b -

  • B_LOG : adcslog.h
  • BDOT_LOG : adcslog.h
  • BDOT_MIN_PAR : telecommands.h

- c -

  • CHAR_CMD : telecommands.h
  • clear_bit : avrutils.h
  • CMD_NUM_HIGH : telecommands.h
  • CMD_NUM_LOW : telecommands.h
  • CMDBUF_DATA : twislave.h
  • CMDBUF_ID : twislave.h
  • CMDBUF_MAXSIZE : twislave.h
  • CMDBUF_SIZE : twislave.h
  • COILX_A : coildriver.h
  • COILX_DIR_PIN : coildriver.h
  • COILX_DIR_PORT : coildriver.h
  • COILX_DUTY_REG : coildriver.c
  • COILX_ENABLE_PIN : coildriver.h
  • COILX_ENABLE_PORT : coildriver.h
  • COILX_N : coildriver.h
  • COILX_PWM_PIN : coildriver.h
  • COILX_PWM_PORT : coildriver.h
  • COILY_A : coildriver.h
  • COILY_DIR_PIN : coildriver.h
  • COILY_DIR_PORT : coildriver.h
  • COILY_DUTY_REG : coildriver.c
  • COILY_ENABLE_PIN : coildriver.h
  • COILY_ENABLE_PORT : coildriver.h
  • COILY_N : coildriver.h
  • COILY_PWM_PIN : coildriver.h
  • COILY_PWM_PORT : coildriver.h
  • COILZ_A : coildriver.h
  • COILZ_DIR_PIN : coildriver.h
  • COILZ_DIR_PORT : coildriver.h
  • COILZ_DUTY_REG : coildriver.c
  • COILZ_ENABLE_PIN : coildriver.h
  • COILZ_ENABLE_PORT : coildriver.h
  • COILZ_N : coildriver.h
  • COILZ_PWM_PIN : coildriver.h
  • COILZ_PWM_PORT : coildriver.h
  • CONTINUE_DOWNLOAD_CMD : telecommands.h
  • CONTROLLER_GAIN_PAR : telecommands.h
  • CR_CHAR : magnetometer.h

- d -

  • DATA_PR_LOGINTERVAL : adcslog.h
  • DELAY_DTBL_STATE : adcsnode.c
  • DELAY_L_ACCURATE : timingutils.h
  • DELAY_L_US : timingutils.h
  • DELAY_MS : timingutils.h
  • DIR_DDR : coildriver.h
  • DISABLE_COILS_CMD : telecommands.h
  • disable_interrupts : avrutils.h
  • DOWNLOAD_LOGS_CMD : telecommands.h
  • DTMBL_LOGDATA_REG_PAR : telecommands.h
  • DTMBL_LOGTIMESTEP_PAR : telecommands.h
  • DUTY_LOG : adcslog.h

- e -

  • EEPROM : eevars.c, avrutils.h
  • EEPROM_SIGNATURE : adcshdr.h
  • ENABLE_DDR : coildriver.h
  • enable_interrupts : avrutils.h
  • ESC_CHAR : magnetometer.h
  • EXIT_STATE_MSG : adcsnode.h
  • EXT_EE_RDSR : SPIeeprom.c
  • EXT_EE_READ : SPIeeprom.c
  • EXT_EE_WIP : SPIeeprom.c
  • EXT_EE_WRDI : SPIeeprom.c
  • EXT_EE_WREN : SPIeeprom.c
  • EXT_EE_WRITE : SPIeeprom.c
  • EXT_EE_WRSR : SPIeeprom.c
  • EXT_EEPROM_PAGE_MASK : SPIeeprom.c
  • EXT_EEPROM_PAGE_SIZE : SPIeeprom.h
  • EXT_EEPROM_SIZE : SPIeeprom.h
  • EXT_STATUS_CMD : telecommands.h

- f -

  • F_CPU : softi2c.h, avrutils.h, adcshdr.h
  • FALSE : avrutils.h

- g -

  • GET_PARAMETER_CMD : telecommands.h

- i -

  • I2C_BUF_OVERFLOW_BIT : tnccomm.h
  • I2C_BUFFER_RDY_BIT : tnccomm.h
  • I2C_CLOCK_IN_HERTZ : softi2c.h
  • I2C_NUMBER_OF_START_ATTEMPTS : softi2c.h
  • I2C_RETRIES : softi2c.h
  • I2C_SCL_PORT : softi2c.h
  • I2C_SDA_PORT : softi2c.h
  • I2C_TNC_ADDR : tnccomm.h
  • INIT_STATE_MSG : adcsnode.h
  • INPUT_RATE_DELAY : magnetometer.c

- k -

  • K_XY_D_PAR : telecommands.h
  • K_XY_N_PAR : telecommands.h
  • K_Z_D_PAR : telecommands.h
  • K_Z_N_PAR : telecommands.h

- l -

  • LOG_E_FLAG : adcslog.h
  • LOG_E_SEND_FLAG : adcslog.h
  • LOG_INTERVAL : adcslog.h
  • LOGDATA_SIZE : adcslog.h

- m -

  • M_MAX_PAR : telecommands.h
  • MAG_BAUDRATE : magnetometer.c
  • MAG_CMD : telecommands.h
  • MAG_MEAS_SIZE : magnetometer.c
  • MAG_SAMPLINGRATE_PAR : telecommands.h
  • mag_start_stream : magnetometer.h
  • mag_stop_stream : magnetometer.h
  • MAG_TIMEOUT : magnetometer.c
  • MAG_X : magnetometer.h
  • MAG_Y : magnetometer.h
  • MAG_Z : magnetometer.h
  • MAGBUF_ERROR : magnetometer.h
  • MAGBUF_SIZE : magnetometer.h
  • MAGDELAY_PERIOD : adcsnode.h
  • MAGDELAY_PERIOD_PAR : telecommands.h
  • MAGOFF_ERROR : adcsnode.h
  • MAGQUERY_CMD : telecommands.h
  • MAX_DUTY : adcsnode.c
  • MC_Z_PAR : telecommands.h
  • MEASURE_DTBL_STATE : adcsnode.c
  • MEASURE_PERIOD : adcsnode.h
  • MEASURE_PERIOD_PAR : telecommands.h
  • MEMORYLOG_SIZE : adcslog.h

- o -

  • OCR2_VALUE : timingutils.c

- p -

  • PAUSE_DOWNLOAD_CMD : telecommands.h

- r -

  • RESET_CMD : telecommands.h
  • RESETELOG_CMD : telecommands.h
  • RX_BUF_OVERFLOW : iouart.c
  • RX_BUFFER_SIZE : iouart.c

- s -

  • SCL_PIN : softi2c.h
  • SDA_PIN : softi2c.h
  • set_bit : avrutils.h
  • SET_PARAMETER_CMD : telecommands.h
  • SETDUTY_CMD : telecommands.h
  • SLEEP_CMD : telecommands.h
  • SPI_DONE_READ : SPIeeprom.h
  • SPI_IDLE : SPIeeprom.h
  • SPI_MISO : SPIeeprom.c
  • SPI_MOSI : SPIeeprom.c
  • SPI_READ : SPIeeprom.h
  • SPI_SCK : SPIeeprom.c
  • SPI_SS : SPIeeprom.c
  • SPI_WRITE : SPIeeprom.h
  • START_DETUMBLING_CMD : telecommands.h
  • START_LOGGING_CMD : telecommands.h
  • STARTMAG_CMD : telecommands.h
  • STATUS_CMD : telecommands.h
  • STOP_DETUMBLING_CMD : telecommands.h
  • STOP_DOWNLOAD_CMD : telecommands.h
  • STOP_LOGGING_CMD : telecommands.h
  • STOPMAG_CMD : telecommands.h
  • SUN_LOG : adcslog.h
  • SUN_SENSORS : sunsensors.h

- t -

  • TCCR2_VALUE : timingutils.c
  • TCNT2_RELOAD_VALUE : timingutils.c
  • test_bit : avrutils.h
  • TIME_L100_US : timingutils.h
  • TIME_L1_MS : timingutils.h
  • TIMEUPDATE_CMD : telecommands.h
  • TNC_BUFFER_FULL_BIT : tnccomm.h
  • tnc_newline : tnccomm.h
  • TNC_TXBUF_SIZE : tnccomm.h
  • toggle_bit : avrutils.h
  • TRUE : avrutils.h
  • TWI_SLAVE_ADDR : adcsnode.h
  • TX_BUFFER_SIZE : iouart.c
  • TX_PRIMEDIT : iouart.c

- u -

  • uart_disable_rx : iouart.h
  • uart_enable_rx : iouart.h

- w -

  • WAITSTATE_DELAY_PAR : telecommands.h

- x -

  • xeeprom_read_byte : SPIeeprom.h
  • xeeprom_read_page : SPIeeprom.h
  • xeeprom_write_byte : SPIeeprom.h
  • xeeprom_write_page : SPIeeprom.h
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: File Member Index

  • Coils : coildriver.h
  • Ldrs : sunsensors.h
  • State : adcsnode.h
  • Timers : timingutils.h
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: File Member Index

  • ALL_TIMERS : timingutils.h
  • CoilAll : coildriver.h
  • CoilX : coildriver.h
  • CoilY : coildriver.h
  • CoilZ : coildriver.h
  • DETUMBLING_STATE : adcsnode.h
  • DOWNLOAD_STATE : adcsnode.h
  • ERROR_STATE : adcsnode.h
  • IDLE_STATE : adcsnode.h
  • LDR_A : sunsensors.h
  • LDR_B : sunsensors.h
  • LDR_C : sunsensors.h
  • LDR_D : sunsensors.h
  • LDR_N : sunsensors.h
  • LDR_Z : sunsensors.h
  • MEASURE_STATE : adcsnode.h
  • MIN_TIMER : timingutils.h
  • MS_TIMER : timingutils.h
  • SEC_TIMER : timingutils.h
  • SLEEP_STATE : adcsnode.h
  • VUART_STATE : adcsnode.h
  • WAIT_STATE : adcsnode.h
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: File Member Index

- a -

  • AbortSendELog() : adcslog.h, adcslog.c

- c -

  • calcBdot() : adcsnode.h, adcsnode.c
  • changeState() : adcsnode.h, adcsnode.c

- d -

  • debug_P() : debugutils.h, debugutils.c
  • disable_coil() : coildriver.h, coildriver.c
  • disable_timeout() : timingutils.h, timingutils.c
  • doDetumblingState() : adcsnode.h, adcsnode.c
  • doDownloadState() : adcsnode.h, adcsnode.c
  • doErrorState() : adcsnode.h, adcsnode.c
  • doIdleState() : adcsnode.h, adcsnode.c
  • doMagQuery() : adcsnode.h, adcsnode.c
  • doMeasuring() : adcsnode.h
  • doMeasuringState() : adcsnode.h, adcsnode.c
  • doSleepState() : adcsnode.h, adcsnode.c
  • doVUartState() : adcsnode.h, adcsnode.c
  • doWaitState() : adcsnode.h, adcsnode.c

- e -

  • EepromDeselect() : SPIeeprom.c
  • EepromSelect() : SPIeeprom.c
  • enable_coil() : coildriver.h, coildriver.c
  • enable_timeout() : timingutils.h, timingutils.c
  • EnableWriteExtEeprom() : SPIeeprom.c
  • ExtEepromWriteReady() : SPIeeprom.c

- g -

  • get_parameter() : adcsnode.h, adcsnode.c
  • getParamAddr() : adcsnode.h, adcsnode.c

- h -

  • handle_command() : adcsnode.h, adcsnode.c

- i -

  • init_adcs() : adcsnode.h, adcsnode.c
  • init_coils() : coildriver.h, coildriver.c
  • init_detumbling() : adcsnode.h, adcsnode.c
  • init_logging() : adcslog.h, adcslog.c
  • init_magnetometer_comm() : magnetometer.h, magnetometer.c
  • Init_SPI() : SPIeeprom.h, SPIeeprom.c
  • init_timing() : timingutils.h, timingutils.c
  • init_tnc() : tnccomm.h, tnccomm.c
  • init_twi_slave() : twislave.h, twislave.c
  • initSunsensors() : sunsensors.h, sunsensors.c

- l -

  • log_data() : adcslog.h, adcslog.c
  • log_intdata() : adcslog.h, adcslog.c
  • log_reset() : adcslog.h, adcslog.c
  • logSunsensors() : adcslog.h, adcslog.c

- m -

  • mag_fill_meas_buffer() : magnetometer.h, magnetometer.c
  • mag_is_on() : magnetometer.h, magnetometer.c
  • mag_send_command() : magnetometer.h, magnetometer.c
  • mag_send_command_N() : magnetometer.h, magnetometer.c
  • mag_send_command_P() : magnetometer.h, magnetometer.c
  • mag_set_detumbling_params() : magnetometer.h, magnetometer.c
  • mag_set_param_P() : magnetometer.h, magnetometer.c
  • main() : adcsnode.c

- p -

  • print_buf() : debugutils.h, debugutils.c
  • print_int() : adcsnode.c, debugutils.h, debugutils.c
  • print_sint() : adcsnode.c
  • print_state() : debugutils.h, debugutils.c
  • put_P() : debugutils.h, debugutils.c
  • putline_P() : debugutils.h, debugutils.c

- r -

  • read_int() : debugutils.h, debugutils.c
  • ReadByteExtEeprom() : SPIeeprom.h, SPIeeprom.c
  • ReadPageExtEeprom() : SPIeeprom.h, SPIeeprom.c
  • ReadStatusExtEeprom() : SPIeeprom.c
  • restart_timeout() : timingutils.h, timingutils.c

- s -

  • sampleSunsensors() : sunsensors.h, sunsensors.c
  • SendELog() : adcslog.h, adcslog.c
  • sendStatus() : adcsnode.h, adcsnode.c
  • set_duty() : coildriver.h, coildriver.c
  • set_parameter() : adcsnode.h, adcsnode.c
  • setCoilDuty() : adcsnode.c
  • setDutyParams() : adcsnode.h, adcsnode.c
  • SIGNAL() : twislave.c, SPIeeprom.c, timingutils.c, iouart.c
  • Soft_I2C_Write() : softi2c.h
  • spi_master_init() : adcsnode.h
  • start_logging() : adcslog.h, adcslog.c
  • StartSendELog() : adcslog.h, adcslog.c
  • store_elogstatus() : adcslog.h, adcslog.c
  • store_log_exteeprom() : adcslog.c

- t -

  • tnc_put() : tnccomm.h, tnccomm.c
  • tnc_put_P() : tnccomm.h, tnccomm.c
  • tnc_putchar() : tnccomm.h, tnccomm.c
  • tnc_putchar_n() : tnccomm.h, tnccomm.c
  • tnc_puthex8() : tnccomm.h, tnccomm.c
  • tnc_putline() : tnccomm.h, tnccomm.c
  • tnc_putline_P() : tnccomm.h, tnccomm.c
  • transmit_12c_buffer() : tnccomm.h, tnccomm.c

- u -

  • uart_flush_rxbuf() : iouart.h, iouart.c
  • uart_flush_txbuf() : iouart.h, iouart.c
  • uart_getchar() : iouart.h, iouart.c
  • uart_init() : iouart.h, iouart.c
  • uart_putchar() : iouart.h, iouart.c
  • uart_putchar_n() : iouart.h, iouart.c

- w -

  • WriteByteExtEeprom() : SPIeeprom.h, SPIeeprom.c
  • WritePageExtEeprom() : SPIeeprom.h, SPIeeprom.c
  • WriteStatusExtEeprom() : SPIeeprom.c
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: File Member Index

- a -

  • active_timers : timingutils.c
  • actuate_period : adcsnode.c
  • adc_finished : sunsensors.c
  • after_wait_state : adcsnode.c

- b -

  • Bdot : magnetometer.h, magnetometer.c
  • bdot_min : adcsnode.c
  • BUF_SREG : iouart.c

- c -

  • change_state : adcsnode.c
  • char_received : adcsnode.c
  • CmdBuf : twislave.h, twislave.c
  • CmdBufRdy : twislave.h, twislave.c
  • CmdBufSize : twislave.h, twislave.c
  • CSEWaddr : SPIeeprom.c
  • current_state : adcsnode.c

- d -

  • detumbling_period : adcsnode.c

- e -

  • EE_actuate_period : eevars.h, eevars.c
  • EE_bdot_min : eevars.h, eevars.c
  • EE_dtmbl_logdata_reg : eevars.h, eevars.c
  • EE_dtmbl_logtimestep : eevars.h, eevars.c
  • EE_eeprom_signature : eevars.h
  • EE_ELogCycle : adcslog.c
  • EE_ELogFull : adcslog.c
  • EE_k_xy_d : eevars.h, eevars.c
  • EE_k_xy_n : eevars.h, eevars.c
  • EE_k_z_d : eevars.h, eevars.c
  • EE_k_z_n : eevars.h, eevars.c
  • EE_m_max : eevars.h, eevars.c
  • EE_mag_notinitialized : eevars.h
  • EE_mag_sampling_rate : eevars.h
  • EE_magdelay_period : eevars.h, eevars.c
  • EE_mc_z : eevars.h, eevars.c
  • EE_measure_period : eevars.h, eevars.c
  • EE_waitstate_delay : eevars.h
  • EEPROM : eevars.c, avrutils.h
  • eeprom_programmed : eevars.h, eevars.c
  • ELogCycle : adcslog.c
  • ELogFull : adcslog.c
  • ELogSendPage : adcslog.c

- k -

  • k_xy_d : adcsnode.c
  • k_xy_n : adcsnode.c
  • k_z_d : adcsnode.c
  • k_z_n : adcsnode.c

- l -

  • lastB_p : adcslog.h, adcslog.c
  • lastBdot_p : adcslog.h, adcslog.c
  • lastDuty : adcslog.h, adcslog.c
  • lastSun_p : adcslog.h, adcslog.c
  • LogCTRL : adcslog.h, adcslog.c
  • logdata_rdy_reg : adcslog.h, adcslog.c
  • logdata_reg : adcslog.h, adcslog.c
  • logdelay : adcslog.c
  • logging_enabled : adcslog.h, adcslog.c
  • logging_started : adcslog.c
  • logperiod : adcslog.c
  • logtimestep : adcslog.h, adcslog.c

- m -

  • m_max : adcsnode.c
  • mag_buffer : magnetometer.h, magnetometer.c
  • mag_sampling_rate : magnetometer.h, magnetometer.c
  • magdelay_period : adcsnode.c
  • mc_z : adcsnode.c
  • mcu_status : adcsnode.h, adcsnode.c
  • measure_period : adcsnode.c
  • measuring_period : adcsnode.c
  • memlog_idx : adcslog.c
  • memorylog : adcslog.c

- n -

  • next_state : adcsnode.c

- p -

  • prev_state : adcsnode.c

- r -

  • RX_Buffer : iouart.c
  • RX_Counter : iouart.h, iouart.c
  • RX_Rd_Index : iouart.c
  • RX_Wr_Index : iouart.c

- s -

  • SPIBuf : SPIeeprom.h, SPIeeprom.c
  • SPIBufPos : SPIeeprom.h, SPIeeprom.c
  • SPIBufSize : SPIeeprom.h, SPIeeprom.c
  • SPIState : SPIeeprom.h, SPIeeprom.c
  • state_tbl : adcsnode.c
  • sun_measurements : sunsensors.h, sunsensors.c

- t -

  • timed_out_min : timingutils.h, timingutils.c
  • timed_out_ms : timingutils.h, timingutils.c
  • timed_out_sec : timingutils.h, timingutils.c
  • timeout_counter_min : timingutils.c
  • timeout_counter_ms : timingutils.c
  • timeout_counter_sec : timingutils.c
  • timeout_period_min : timingutils.c
  • timeout_period_ms : timingutils.c
  • timeout_period_sec : timingutils.c
  • timer_reg : timingutils.c
  • TNC_status_reg : tnccomm.h, tnccomm.c
  • TNC_TX_Counter : tnccomm.c
  • TNC_TX_Rd_Idx : tnccomm.c
  • TNC_TX_Wr_Idx : tnccomm.c
  • TNC_TXBuf : tnccomm.c
  • TNC_TXBufSize : tnccomm.c
  • TX_Buffer : iouart.c
  • TX_Counter : iouart.c
  • TX_Rd_Index : iouart.c
  • TX_Wr_Index : iouart.c

- u -

  • UTC_Second : timingutils.h, timingutils.c
Generated on Fri Sep 3 17:21:18 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: iouart.c Source File

iouart.c

Go to the documentation of this file.
00001 /*
00002  *      iouart.c
00003  *
00004  *      Implementation of the interrupt driven and buffered UART module.
00005  *
00006  */
00007 #include "iouart.h"
00008 #include <avr/signal.h>
00009 #include <avr/interrupt.h>
00010 #include "avrutils.h"
00011
00012 #define RX_BUF_OVERFLOW 0
00013 #define TX_PRIMEDIT 1
00014
00015 #ifndef RX_BUFFER_SIZE
00016 #define RX_BUFFER_SIZE 200
00017 #endif
00018
00019 #ifndef TX_BUFFER_SIZE
00020 #define TX_BUFFER_SIZE 100
00021 #endif
00022
00023 static uint8_t volatile BUF_SREG; ///< Receive and transmit status register
00024
00025 // UART receive buffer
00026
00027
00028
00029 static uint8_t RX_Buffer[RX_BUFFER_SIZE+1]; ///< Receive buffer.
00030 static uint8_t volatile RX_Wr_Index;
00031 static uint8_t volatile RX_Rd_Index;
00032 uint8_t volatile RX_Counter;
00033
00034 // UART Transmit buffer
00035
00036 static uint8_t TX_Buffer[TX_BUFFER_SIZE+1]; ///< Transmit buffer
00037 static uint8_t volatile TX_Rd_Index;
00038 static uint8_t volatile TX_Wr_Index;
00039 static uint8_t volatile TX_Counter;
00040
00041
00042
00043
00044 /// UART Receiver interrupt service routine
00045 SIGNAL(SIG_UART_RECV) {
00046     uint8_t c;
00047     c = UDR;
00048     RX_Buffer[RX_Wr_Index] = c;
00049
00050     if(++RX_Wr_Index > RX_BUFFER_SIZE)
00051         RX_Wr_Index = 0;
00052     if (++RX_Counter > RX_BUFFER_SIZE) {
00053         RX_Counter = RX_BUFFER_SIZE;
00054                 set_bit(BUF_SREG, RX_BUF_OVERFLOW);
00055         //RX_Buffer_Overflow = 1;
00056     }
00057
00058 }
00059
00060 /// UART transmit interrupt service routine.
00061 SIGNAL(SIG_UART_TRANS) {
00062     if(TX_Counter != 0) {
00063         if(bit_is_set(BUF_SREG, TX_PRIMEDIT)) {
00064             //fPrimedIt = 0;
00065                         clear_bit(BUF_SREG, TX_PRIMEDIT);
00066             if(++TX_Rd_Index > TX_BUFFER_SIZE)
00067                 TX_Rd_Index = 0;
00068             TX_Counter--;
00069         }
00070
00071         if (TX_Counter != 0) {
00072             UDR = TX_Buffer[TX_Rd_Index];
00073
00074             if(++TX_Rd_Index > TX_BUFFER_SIZE)
00075                 TX_Rd_Index = 0;
00076             TX_Counter--;
00077         }
00078     }
00079 }
00080
00081
00082 /*
00083  *      uart_getchar()
00084  */
00085 uint8_t uart_getchar(void)
00086 {
00087     uint8_t c;
00088
00089     while(RX_Counter == 0)
00090         ;
00091     c = RX_Buffer[RX_Rd_Index];
00092     if (++RX_Rd_Index > RX_BUFFER_SIZE)
00093         RX_Rd_Index = 0;
00094     if (RX_Counter)
00095         RX_Counter--;
00096     return c;
00097 }
00098
00099 /*
00100  *      uart_putchar()
00101  */
00102 int uart_putchar(char c)
00103 {
00104     uint8_t stuffit = 0;
00105     while(TX_Counter > (TX_BUFFER_SIZE-1))
00106         ;
00107     if(TX_Counter == 0)
00108         stuffit = 1;
00109     TX_Buffer[TX_Wr_Index++]=c;
00110
00111     if(TX_Wr_Index > TX_BUFFER_SIZE)
00112         TX_Wr_Index = 0;
00113
00114     TX_Counter++;
00115     if(stuffit == 1)
00116     {
00117                 set_bit(BUF_SREG, TX_PRIMEDIT);
00118         UDR = c;
00119     }
00120         return c;
00121 }
00122
00123 void uart_putchar_n(char c)
00124 {
00125     if (c == '\n') {
00126                 uart_putchar('\r');
00127     }
00128     uart_putchar(c);
00129 }
00130
00131 /*
00132  *      uart_init()
00133  */
00134 void uart_init(uint16_t baud) {
00135     UBRRH = (uint8_t)(baud >> 8);
00136         UBRRL = (uint8_t)baud;
00137         /* 8 bit character size. 1 stop bit. No clock polarity. */
00138         UCSRC = (1<<URSEL)|(1 << UCSZ1) | (1 << UCSZ0);
00139         /* Enable receiver and trasmitter */
00140         UCSRB = (1 << RXEN) | (1 << TXEN)|(1 << RXCIE)|(1 << TXCIE);
00141 }
00142
00143
00144 void uart_flush_rxbuf(void) {
00145         disable_interrupts();
00146         RX_Wr_Index = 0;
00147         RX_Rd_Index = 0;
00148         RX_Counter = 0;
00149         enable_interrupts();
00150 }
00151
00152
00153
00154 void uart_flush_txbuf(void) {
00155         disable_interrupts();
00156         TX_Wr_Index = 0;
00157         TX_Rd_Index = 0;
00158         TX_Counter = 0;
00159         enable_interrupts();
00160 }
00161
00162
00163
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: iouart.h Source File

iouart.h

Go to the documentation of this file.
00001 #ifndef _IOUART_H_
00002 #define _IOUART_H_
00003 /**
00004  * @file iouart.h
00005  *
00006  * @brief Interrupt driven and buffered UART communication.
00007  *
00008  * Based on code from the book "Embedded C Programming and the Atmel AVR"
00009  * by  Barnett, Cox, & O'Cull.
00010  *
00011  * @note Interrupts must be enabled for code to work.
00012  *
00013  */
00014 #include <avr/io.h>
00015 #include <inttypes.h>
00016 #include <avr/pgmspace.h>
00017
00018 #define uart_disable_rx() UCSRB &= ~(1 << RXEN)
00019 #define uart_enable_rx() UCSRB |= (1 << RXEN)
00020
00021 extern uint8_t volatile RX_Counter;
00022
00023 /**
00024  * @brief Send a char to the UART.
00025  *
00026  * Put a char in the transmit buffer. If buffer is full, wait until ready.
00027  *
00028  */
00029 int uart_putchar(char c);
00030
00031 /**
00032  *      Put a char in the transmit buffer. Add a \r char after a \n char.
00033  */
00034 void uart_putchar_n(char c);
00035
00036 /**
00037  * Read a char from the UART receive buffer.
00038  *
00039  * If buffer is empty, wait for a char to arrive.
00040  * @return Received character.
00041  */
00042 uint8_t uart_getchar(void);
00043
00044 /**
00045  * Initialize UART and set baud rate.
00046  *
00047  * The baud rate is set with the UBRR register. To calculate a the UBBR
00048  * for a specific baud rate, use the formula:
00049  * \verbatim UBRR = f_osc/(16*BAUD)-1, \endverbatim
00050  * where f_osc is the system oscillator clock frequency and BAUD is the
00051  * baud rade in bits per second, bps.
00052  *
00053  * @param baud Value to store in the UBBR register.
00054  *
00055  */
00056 void uart_init(uint16_t baud);
00057
00058
00059 /**
00060  * Flush receive buffer.
00061  *
00062  * Set internal counters to zero.
00063  */
00064 void uart_flush_rxbuf(void);
00065
00066 /**
00067  * Flush transmit buffer.
00068  *
00069  * Set internal counters to zero.
00070  */
00071 void uart_flush_txbuf(void);
00072
00073
00074 #endif /* _IOUART_H_ */
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: magnetometer.c Source File

magnetometer.c

Go to the documentation of this file.
00001 /**
00002  @file magnetometer.c
00003
00004  Implementation of the magnetometer module.
00005
00006 */
00007
00008 #include "magnetometer.h"
00009 #include "adcshdr.h"
00010 #include "iouart.h"
00011 #include "timingutils.h"
00012 #include <avr/wdt.h>
00013 #include <avr/eeprom.h>
00014
00015 #include "eevars.h"
00016 #include "adcslog.h"
00017 /**
00018  * Input rate delay.
00019  *
00020  * The HMR2300 limits how fast the command bytes can be received,
00021  * based on the sampling rate. The datasheet is somewhat unclear
00022  * about this, but it seems like the maximum wait time necessary
00023  * is 20msec.
00024  */
00025 #define INPUT_RATE_DELAY 20
00026
00027 /// Baudrate for communication with magnetometer.
00028 #define MAG_BAUDRATE 9600
00029
00030 /**
00031  * Time in ms to wait for magnetometer to respond.
00032  */
00033 #define MAG_TIMEOUT 200
00034
00035 /// Size of a single magnetometer reading in binary mode.
00036 #define MAG_MEAS_SIZE 7
00037
00038
00039
00040
00041 uint8_t mag_sampling_rate = 20;
00042
00043 //------------- Global datastructures ---------------------
00044 magMeasurement mag_buffer[MAGBUF_SIZE];
00045
00046 magMeasurement volatile Bdot; ///< Current estimate of Bdot
00047
00048 void init_magnetometer_comm(void) {
00049         uint16_t ubrr_value;
00050         ubrr_value = F_CPU/16/MAG_BAUDRATE-1;
00051         uart_init(ubrr_value);
00052         mag_stop_stream();
00053 }
00054
00055 void mag_send_command_N(char *cmd, uint8_t length){
00056         uint8_t i;
00057         for (i=0; i< length;i++) {
00058                 DELAY_MS(INPUT_RATE_DELAY);
00059                 uart_putchar(*cmd++);
00060         }
00061         uart_putchar(CR_CHAR);
00062 }
00063
00064
00065 void mag_send_command(char *cmd) {
00066         while (*cmd) {
00067                 DELAY_MS(INPUT_RATE_DELAY);
00068                 uart_putchar(*cmd++);
00069         }
00070         uart_putchar(CR_CHAR);
00071 }
00072
00073 void mag_send_command_P(PGM_P cmd_addr) {
00074         char c;
00075         while ((c = __LPM((unsigned short)cmd_addr++))) {
00076                 DELAY_MS(INPUT_RATE_DELAY);
00077                 uart_putchar(c);
00078         }
00079         uart_putchar(CR_CHAR);
00080 }
00081
00082
00083 /**
00084  @todo
00085  Function will loop forever if magnetometer does not output data. A watchdog
00086  reset will then occur.
00087 */
00088 uint8_t mag_fill_meas_buffer(uint8_t n) {
00089         uint8_t tmpbuf[MAG_MEAS_SIZE], counter, c, i;
00090         uint8_t magbufpos = 0, errorcount = 0;
00091         int16_t tmp;
00092         // Fill buffer with n measurements.
00093         while (magbufpos < n && errorcount < 5) {
00094                 // Fill temporary buffer with one measurement
00095                 for (i = 0; i < MAG_MEAS_SIZE; i++) {
00096                         tmpbuf[i] = uart_getchar();
00097             }
00098             if (tmpbuf[MAG_MEAS_SIZE-1] == CR_CHAR) { // Is it a correct measurement?
00099                 tmp = tmpbuf[0] << 8;
00100                 tmp |= tmpbuf[1];
00101                 mag_buffer[magbufpos].magX = tmp;
00102                 tmp = tmpbuf[2] << 8;
00103                 tmp |= tmpbuf[3];
00104                 mag_buffer[magbufpos].magY = tmp;
00105                 tmp = tmpbuf[4] << 8;
00106                 tmp |= tmpbuf[5];
00107                 mag_buffer[magbufpos].magZ = tmp;
00108                 magbufpos++;
00109                 /* Debug
00110                 uart_disable_rx();
00111                 uart_flush_rxbuf();
00112                 DELAY_MS(600);
00113                 uart_enable_rx();
00114                 wdt_reset(); // reset watchdog timer             */
00115         } else {
00116                 // Error occured. The buffer is out of sync. with the datastream.
00117                 // Try to synchronize again.
00118                 errorcount++;
00119                 counter = 0;
00120                 while ((counter < 2*MAG_MEAS_SIZE)) {
00121                         c = uart_getchar();
00122                         if (c==CR_CHAR) {
00123                                 break;
00124                                 }
00125                         counter++;
00126                         }
00127             }
00128     }
00129     if (magbufpos == n)
00130         return 0;
00131     else
00132         return MAGBUF_ERROR;
00133 }
00134
00135 uint8_t mag_is_on(void) {
00136         uart_flush_rxbuf();
00137         mag_send_command_P(PSTR("*99ID")); // Read device id.
00138         enable_timeout(MS_TIMER, MAG_TIMEOUT);
00139         while (!timed_out_ms) {
00140                 if (RX_Counter) break;
00141         }
00142         disable_timeout(MS_TIMER);
00143         if (RX_Counter)
00144                 return 1;
00145         else
00146                 return 0;
00147 }
00148
00149 void mag_set_detumbling_params(void){
00150         uint8_t numbuf[3];
00151         utoa(mag_sampling_rate, numbuf, 10);    // Convert to string
00152         mag_set_param_P(PSTR("*00TF"));                 // Set manual S/R pulses
00153         mag_set_param_P(PSTR("*00B"));                  // Set binary mode
00154         mag_set_param_P(PSTR("*00R=20"));               // Set samplerate
00155         mag_set_param_P(PSTR("*00VN"));                 // Averaging on
00156         mag_send_command_P(PSTR("*00]S"));              // Send a SET pulse
00157 }
00158
00159 void mag_set_param_P(PGM_P cmd_addr) {
00160         mag_send_command_P(PSTR("*00WE"));
00161         mag_send_command_P(cmd_addr);
00162 }
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: magnetometer.h Source File

magnetometer.h

Go to the documentation of this file.
00001 #ifndef _MAGNETOMETER_H_
00002 #define _MAGNETOMETER_H_
00003 /**
00004  @file magnetometer.h
00005
00006  Interface to the HMR2300 Smart Digital Magnetometer from Honeywell
00007  Changes:
00008         - 2004-09-02 -- Magnetometer mappings are now correct
00009
00010  @note
00011  Binary magnetometer readings are returned as 2's complement signed integers.
00012  @note
00013  The SET pulse mode is used. See datasheet for details.
00014
00015 */
00016
00017 #include <inttypes.h>
00018 #include <avr/pgmspace.h>
00019
00020 #define ESC_CHAR 0x1B   ///< Escape ascii code.
00021 #define CR_CHAR 0x0D    ///< Carriace return ascii code.
00022
00023 /**
00024  @name Mapping macros
00025
00026  The x, y, z axes of the magnetometer are not the same as the body axes.
00027  The #MAG_X, #MAG_Y, #MAG_Z macros are defined to map magnetometer axes to
00028  body axes. Used in #calcBdot().
00029  @{
00030 */
00031 #define MAG_X magZ ///< Magnetometer x-axis to body x-axis mapping
00032 #define MAG_Y magY ///< Magnetometer y-axis to body y-axis mapping
00033 #define MAG_Z magX ///< Magnetometer z-axis to body z-axis mapping
00034 //@}
00035 #define MAGBUF_SIZE 5   ///< Maximum number of entries in measurement buffer.
00036 #define MAGBUF_ERROR 1
00037
00038 /**
00039  * A single magnetometer measurement.
00040  *
00041  * The measurements are given relative to +- 2.0 Gauss. The datasheet
00042  * states that +-2.0 Gauss gives a reading of +-30000 (0x7530 and 0x8AD0).
00043  */
00044 typedef struct  {
00045         int16_t magX;
00046         int16_t magY;
00047         int16_t magZ;
00048 } magMeasurement;
00049
00050
00051
00052 /// Set to 1 when magnetometer is properly initialized for detumbling.
00053 //extern uint8_t mag_initialized;
00054
00055 /**
00056  * Magnetometer measurements buffer.
00057  *
00058  * Holds the N last measurements from the magnetometer. Used for
00059  * calclulating Bdot.
00060  */
00061 extern magMeasurement mag_buffer[MAGBUF_SIZE];
00062
00063 extern magMeasurement volatile Bdot; ///< Current estimate of Bdot
00064
00065 extern uint8_t mag_sampling_rate; ///< Magnetometer samplerate
00066
00067 /**
00068  * Initialize magnetometer communcication.
00069  *
00070  * Enable UART and set correct baudrate.
00071  */
00072 void init_magnetometer_comm(void);
00073
00074 /**
00075  * Set magnetometer parameters for detumbling
00076  *
00077  */
00078 void mag_set_detumbling_params(void);
00079 /**
00080  * Send a command string to the magnetometer.
00081  *
00082  * A newline char is automatically added after the command.
00083  */
00084 void mag_send_command(char *cmd);
00085
00086 /**
00087  * Send a command string stored in program memory to the magnetometer.
00088  *
00089  * A newline char is automatically added after the command.
00090  */
00091 void mag_send_command_P(PGM_P cmd_addr);
00092
00093 /**
00094  * Send a command string with a specific lenght to the magnetometer.
00095  *
00096  * A newline char is added after the command.
00097  */
00098 void mag_send_command_N(char *cmd, uint8_t length);
00099
00100 /**
00101  * Fill #mag_buffer with \c n measurements.
00102  *
00103  * An output command must be sent to the magnetometer before the function
00104  * is called. The function will try to synchronize itself with stream of
00105  * continous readings. Maximum number of measurements are determinded by
00106  * #MAGBUF_SIZE.
00107  *
00108  * @param n Number of measurements to read from magnetometer.
00109  * @return Returns zero (0) if successful.
00110  */
00111 uint8_t mag_fill_meas_buffer(uint8_t n);
00112
00113 /**
00114  * Check that magnetometer is responding.
00115  *
00116  * Sends a read device command and wait for a respons. Timeout after
00117  * #MAG_TIMEOUT ms.
00118  *
00119  * @return TRUE if magnetometer is responding. FALSE otherwise
00120  */
00121 uint8_t mag_is_on(void);
00122
00123 /**
00124  * Set a parameter in the magnetometer.
00125  *
00126  * Similar to mag_send_command(), but sends a \c *00WE write enable
00127  * command first.
00128  *
00129  * @param cmd_addr Address to parameter string stored in flash.
00130  */
00131 void mag_set_param_P(PGM_P cmd_addr);
00132
00133 /**
00134  * Start continuous magnetometer reading.
00135  */
00136 #define mag_start_stream() mag_send_command_P(PSTR("*00C"))
00137 /**
00138  * Stop magnetometer data stream.
00139  *
00140  * Stop continuous magnetometer reading by sending an ESC character.
00141  */
00142 #define mag_stop_stream() uart_putchar(ESC_CHAR)
00143
00144
00145
00146 #endif /* _MAGNETOMETER_H_ */
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: mainpage.txt.txt File Reference

mainpage.txt.txt File Reference

Generated on Fri Sep 3 17:21:16 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: softi2c.h Source File

softi2c.h

Go to the documentation of this file.
00001 /**
00002  @file softi2c.h
00003  Software driven TWI/I2c master interface.
00004
00005  Implementation of the I2C bus master protocol in software.
00006
00007  @note
00008  Original code by Chris efstathiou. The original implementation can be
00009  found at http://www.avrfreaks.com, in the Academy>User's projects section,
00010  under the name 'general peripheral drivers'.
00011
00012  @note
00013  Due to hardware problems, most of the I2C code by Chris Efstathiou has been
00014  replaced. Only the timing utilities remain
00015
00016  Changes:
00017   - 2004-06-06 -- Replaced most of original code
00018   - 2004-02-17 -- Updated pins to pcb layout.
00019
00020 */
00021
00022
00023
00024 #ifndef _SOFTI2C_H_
00025 #define _SOFTI2C_H_
00026 #include "adcshdr.h"
00027 /*##############################################################################################*/
00028 /*                             START OF CONFIGURATION BLOCK                                     */
00029 /*##############################################################################################*/
00030 /*
00031    The I2C_CLOCK normally is 100 Khz so the delay between level states is
00032    (1/I2C_CLOCK)/2 = ( (1/100000)/2 ) = 5 microseconds.
00033    The use of delay loop for timing is highly accurate due to the use of inline asm code.
00034    There is no need to use a timer but if you insist you have that option.
00035    The I2C_TIMEOUT_TIME_IN_MICROSECONDS is set to whatever is the maximum time you think
00036    your device will take to perform the requested task. After that time the i2c functions
00037    will return a "I2C_ERROR_DEVICE_NOT_RESPONDING" or "I2C_ERROR_DEVICE_BUSY" error code.
00038 */
00039
00040
00041 #ifndef  F_CPU
00042 /// The cpu clock frequency in Hertz.
00043 #define  F_CPU                        8000000L
00044 #endif
00045
00046 /// The SDA port. Use capital letter (A,B,C,D... etc.)
00047 #define I2C_SDA_PORT    C
00048
00049 /// The SDA port pin
00050 #define SDA_PIN 7
00051
00052 /// The SDA port.Use capital letter (A,B,C,D... etc.)
00053 #define I2C_SCL_PORT C
00054
00055 /// The SCL port pin
00056 #define SCL_PIN                       6
00057
00058 /// I2C clock in Hertz.
00059 #define I2C_CLOCK_IN_HERTZ             50000
00060
00061
00062 /// Number of attempts to issue a succesfull start condition.
00063 #define I2C_NUMBER_OF_START_ATTEMPTS  10
00064
00065 /*##############################################################################################*/
00066 /*                              END OF CONFIGURATION BLOCK                                      */
00067 /*##############################################################################################*/
00068
00069
00070 #define I2C_RETRIES                5
00071
00072
00073
00074 unsigned char Soft_I2C_Write(unsigned char addr, unsigned char verdi);
00075
00076 #endif  /*  _SOFTI2C_H_ */
00077
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: SPIeeprom.c Source File

SPIeeprom.c

Go to the documentation of this file.
00001 /**
00002  * @file SPIeeprom.c
00003  *
00004  * Implementation of M95128E2PROM interface.
00005  *
00006  * @author Eysten Sæther
00007  *
00008  */
00009
00010 #include <avr/io.h>
00011 #include  "SPIeeprom.h"
00012 #include "avrutils.h"
00013 #include <avr/signal.h>
00014 #define EXT_EEPROM_PAGE_MASK  (EXT_EEPROM_PAGE_SIZE-1)      //sideskille for sekvensiell skriving
00015 #define SPI_SS                PB4                           //Slave select pin
00016 #define SPI_MOSI              PB5                           //Master out, slave in
00017 #define SPI_MISO              PB6                           //Master in, slave out
00018 #define SPI_SCK               PB7                           //Clock, drevet av master
00019
00020 //EEPROM Instruction Set
00021 #define EXT_EE_WREN           0x06                          //Write Enable
00022 #define EXT_EE_WRDI           0x04                          //Write Disable
00023 #define EXT_EE_RDSR           0x05                          //Read Status Register
00024 #define EXT_EE_WRSR           0x01                          //Write Status Register
00025 #define EXT_EE_READ           0x03                          //Read Data from Memory Array
00026 #define EXT_EE_WRITE          0x02                          //Write Data to Memory Array
00027
00028 //EEPROM Status Register
00029 #define EXT_EE_WIP            0x01                          //Write in progress
00030
00031 uint8_t volatile SPIState = 0;                                   //Flag som settes når SPI-bussen er klar
00032 uint8_t SPIBuf[EXT_EEPROM_PAGE_SIZE+3];
00033 uint8_t volatile SPIBufSize=0;
00034 uint8_t volatile SPIBufPos=0;
00035 uint16_t volatile CSEWaddr=0;
00036
00037
00038 uint8_t ReadStatusExtEeprom(void);
00039 void EnableWriteExtEeprom(void);
00040 uint8_t ExtEepromWriteReady(void);
00041 void WriteStatusExtEeprom(uint8_t status);
00042 void EepromSelect(void);
00043 void EepromDeselect(void);
00044
00045
00046 void Init_SPI(uint8_t prescale) {                    //Initierer serial peripheral interface, n=2 tilsvarer F_SCK=/64 F_cpu
00047         EepromDeselect();
00048     PORTB |= (1<<SPI_SS)|(1<<SPI_MOSI)|(1<<SPI_SCK)|(1<<SPI_MISO);    //default høy, samt pullup på slave out-master inn
00049     DDRB |= (1<<SPI_SS)|(1<<SPI_MOSI)|(1<<SPI_SCK) ;   //Slave-select pin for å styre ekstern eeprom. Data ut og klokke må være utganger
00050
00051     SPCR = (1<<MSTR);
00052     SPCR |= (1<<SPE)|(1<<MSTR)|(0<<CPOL)|(0<<CPHA)|(prescale&0x03);  //Enaber SPI, SPI-avbruddsrutine, og setter mikrokontrolleren i master modus på SPI-bussen
00053                                                   //((MSB først, data valid når klokke går høy, hastighet: n=0: 1Mbit, n=1: 250kbit, n=2: 62.5kbit, n=3: 31.25kbit)
00054     SPIState=SPI_IDLE;
00055 }
00056
00057 uint8_t ReadByteExtEeprom(uint16_t addr) { //rutine for å lese en enkelt byte fra ekstern eeprom
00058     uint8_t tmp;
00059     if (SPIState & SPI_IDLE) {                          //dersom SPI er klar
00060         EepromSelect();
00061         SPDR = EXT_EE_READ;                           //send lese-instruksjon
00062         while (!(SPSR&(1<<SPIF)));                         //vent til instruksjon er sendt
00063         SPDR = (addr>>8);                             //send høy adresse
00064         while (!(SPSR&(1<<SPIF)));                         //vent til øvre adresse er sendt
00065         SPDR = ((uint8_t)addr);                 //send lav adresse
00066         while (!(SPSR&(1<<SPIF)));                         //vent til nedre adresse er sendt
00067         SPDR = 0;                                     //send dummy data for å klokke inn på MISO
00068         while (!(SPSR&(1<<SPIF)));                         //vent til ny byte er klokket inn
00069         tmp = SPDR;
00070         EepromDeselect();
00071         return tmp;
00072     } else return 0;
00073 }
00074
00075 void ReadPageExtEeprom(uint16_t addr) {       //rutine for å lese en hel side fra eeprom, avbruddsbasert
00076     if (SPIState & SPI_IDLE) {                      //dersom SPI er klar
00077         SPIState &= ~SPI_IDLE;               //semafor
00078         SPIState |= SPI_READ;     //først skrive instruksjon og adresse, så lese
00079         EepromSelect();
00080         SPIBufPos=0;SPIBufSize=0;
00081         SPDR = EXT_EE_READ;                           //send lese-instruksjon
00082         while (!(SPSR&(1<<SPIF)));                         //vent til instruksjon er sendt
00083         SPDR = (addr>>8);                             //send høy adresse
00084         while (!(SPSR&(1<<SPIF)));                         //vent til øvre adresse er sendt
00085         SPDR = ((uint8_t)addr);                 //send lav adresse
00086         while (!(SPSR&(1<<SPIF)));                         //vent til nedre adresse er sendt
00087
00088         SPDR = 0;                                 //dummy byte for at SCK skal klokke inn data fra eeprom
00089         SPCR |= (1<<SPIE);                        //skru på avbruddshåndterer
00090     }
00091 }
00092
00093 uint8_t ReadStatusExtEeprom(void) {
00094     if (SPIState & SPI_IDLE) {                          //dersom SPI er klar
00095         EepromSelect();
00096         SPDR = EXT_EE_RDSR;                           //send lese-statusregister-instruksjon
00097         while (!(SPSR&(1<<SPIF)));                         //vent til instruksjon er sendt
00098         SPDR = 0;                                     //send dummy data for å klokke inn på MISO
00099         while (!(SPSR&(1<<SPIF)));                         //vent til statusregisteret er klokket inn
00100         EepromDeselect();
00101         return SPDR;
00102     } else return 0;
00103 }
00104
00105 void EnableWriteExtEeprom(void) {
00106     //EepromDeselect();
00107     //_NOP();
00108     EepromSelect();
00109     SPDR = EXT_EE_WREN;                           //send write-enable-instruksjon
00110     while (!(SPSR & (1<<SPIF)));                         //vent til instruksjon er sendt
00111     EepromDeselect();                             //eeprom må velges bort..
00112     _NOP();                                       //i minst 200 ns
00113     EepromSelect();                               //for å kunne skrives til
00114 }
00115
00116 uint8_t ExtEepromWriteReady(void) {
00117     if (ReadStatusExtEeprom()&EXT_EE_WIP) return FALSE;
00118     else return TRUE;
00119
00120 }
00121 void WriteByteExtEeprom(uint16_t addr, uint8_t data) {
00122     if (SPIState & SPI_IDLE && ExtEepromWriteReady()) {                          //dersom SPI og ekstern EEPROM er klar
00123         EnableWriteExtEeprom();
00124         SPDR = EXT_EE_WRITE;                           //send skrive-instruksjon
00125         while (!(SPSR&(1<<SPIF)));                         //vent til instruksjon er sendt
00126         SPDR = (addr>>8);                             //send høy adresse
00127         while (!(SPSR&(1<<SPIF)));                         //vent til øvre adresse er sendt
00128         SPDR = ((uint8_t)addr);                 //send lav adresse
00129         while (!(SPSR&(1<<SPIF)));                         //vent til nedre adresse er sendt
00130         SPDR = data;
00131         while (!(SPSR&(1<<SPIF)));                         //vent til byte er sendt
00132         EepromDeselect();                             //Velg bort eeprom
00133     }
00134 }
00135
00136 void WritePageExtEeprom(uint16_t addr, uint8_t *page, uint8_t pagesize, uint8_t firstpage) {   //rutine for å skrive en hel side, krever avbruddshåntering
00137     uint8_t i=0;
00138     if (SPIState & SPI_IDLE) {                          //dersom SPI-buss er ledig
00139         while(!ExtEepromWriteReady());                //vent til ekstern eeprom er klar
00140         SPIState &= ~SPI_IDLE;
00141         SPIState |= SPI_WRITE;
00142         SPCR &= ~(1<<SPIE);                        //skru av avbruddshåndterer
00143         EnableWriteExtEeprom();
00144         if (firstpage) {
00145             SPIBufPos=0; SPIBufSize=0;
00146             for (i=0; i<pagesize; i++)
00147               SPIBuf[SPIBufSize++]=page[i];
00148         }
00149
00150         SPDR = EXT_EE_WRITE;                           //send skrive-instruksjon
00151         while (!(SPSR&(1<<SPIF)));                         //vent til instruksjon er sendt
00152         SPDR = (addr>>8);                             //send høy adresse
00153         while (!(SPSR&(1<<SPIF)));                         //vent til øvre adresse er sendt
00154         SPDR = ((uint8_t)addr);                 //send lav adresse
00155         while (!(SPSR&(1<<SPIF)));                         //vent til nedre adresse er sendt
00156
00157         SPDR = SPIBuf[SPIBufPos++];               //fyr løs data
00158         SPCR |= (1<<SPIE);                        //skru på avbruddshåndterer
00159         CSEWaddr=addr+1;
00160     }
00161 }
00162
00163 void WriteStatusExtEeprom(uint8_t status) {
00164     if (SPIState & SPI_IDLE) {                          //dersom SPI er klar
00165         EnableWriteExtEeprom();
00166         SPDR = EXT_EE_WRSR;                           //send skrive-statusregister-instruksjon
00167         while (!(SPSR&(1<<SPIF)));                         //vent til instruksjon er sendt
00168         SPDR = status;                               //skriv status til statusregister
00169         while (!(SPSR&(1<<SPIF)));                         //vent til status er sendt
00170         EepromDeselect();
00171     }
00172 }
00173
00174 void EepromSelect(void) {
00175     PORTB &= ~(1<<SPI_SS);      //Slave select er invertert, så enheten velges når linjen trekkes lav
00176 }
00177
00178 void EepromDeselect(void) {
00179     PORTB |= (1<<SPI_SS);      //Slave select er invertert, så enheten velges bort når linjen trekkes høy
00180 }
00181
00182                       //Avbruddsrutine: en hel byte på SPI-bussen er enten sendt eller mottatt
00183 SIGNAL(SIG_SPI) {
00184     uint8_t tmp;
00185     if (SPIState & SPI_READ) {      //hvis enheten skal leses
00186         tmp=SPDR;
00187         SPIBuf[SPIBufPos++]=tmp;                         //les buffer inn i spi-dataregister
00188         if (SPIBufPos>=EXT_EEPROM_PAGE_SIZE) { //hvis bufferet er fullt eller bare én byte skal leses
00189             SPIState &= ~SPI_READ;                //fjern leseflagg
00190             SPIState |= SPI_DONE_READ;               //marker at bufferet er fylt med en hel side
00191             SPCR &= ~(1<<SPIE);                           //skru av avbrudd
00192             EepromDeselect();
00193             SPIState|=SPI_IDLE;
00194         } else SPDR=0;                               //flere data som skal leses; sender dummy data for å holde klokken gående
00195     }
00196     if (SPIState & SPI_WRITE) {
00197         if (SPIBufPos>=SPIBufSize) {                  //ferdig å skrive
00198             SPCR &= ~(1<<SPIE);                           //skru av avbrudd
00199             SPIState &=~SPI_WRITE;              //fjern skriveflagg
00200             EepromDeselect();                             //velg bort eeprom
00201             SPIState |= SPI_IDLE;
00202         }
00203         else {
00204             if ((CSEWaddr & EXT_EEPROM_PAGE_MASK)==0) {       //dersom vi ønsker å skrive over en ny side i eeprom må skriveinstruksjon sendes på nytt
00205               SPIState|=SPI_IDLE;
00206               EepromDeselect();
00207               //SPCR |= (1<<SPIE);                            //skru på avbruddshåndterer
00208               WritePageExtEeprom(CSEWaddr, SPIBuf, 0, 0);   //fortsett på neste side
00209             }
00210             else {
00211                CSEWaddr++;
00212                SPDR = SPIBuf[SPIBufPos++];                    //skriv fra spi-buffer til spi-dataregister
00213             }
00214         }
00215
00216     }
00217 }
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: SPIeeprom.h Source File

SPIeeprom.h

Go to the documentation of this file.
00001 /**
00002  * @file spieeprom.h
00003  *
00004  * M95128E2PROM interface.
00005  *
00006  * This file contains function declarations and constants for communication
00007  * with an external EEPROM through the SPI (Serial Peripheral Interface).
00008  *
00009  * @author Eysten Sæther
00010  *
00011  * @note Converted from IAR to AVR-GCC by Kjell Magne Fauske
00012  *
00013  */
00014
00015 #ifndef _SPIEEPROM_H_
00016 #define _SPIEEPROM_H_
00017 #include <inttypes.h>
00018
00019 #define EXT_EEPROM_SIZE       0x4000                        //16 kByte minne totalt
00020 #define EXT_EEPROM_PAGE_SIZE  0x0040                        //64 byte sidestørrelse
00021
00022
00023 #define SPI_IDLE              0x01
00024 #define SPI_WRITE             0x02
00025 #define SPI_READ              0x04
00026 #define SPI_DONE_READ         0x08
00027
00028 extern uint8_t volatile SPIState;                                   //Flag som settes når SPI-bussen er klar
00029 extern uint8_t SPIBuf[EXT_EEPROM_PAGE_SIZE+3];
00030 extern uint8_t volatile SPIBufSize;
00031 extern uint8_t volatile SPIBufPos;
00032
00033 void Init_SPI(uint8_t prescale);
00034 uint8_t ReadByteExtEeprom(uint16_t addr);
00035 void ReadPageExtEeprom(uint16_t addr);
00036
00037
00038 void WriteByteExtEeprom(uint16_t addr, uint8_t data);
00039 void WritePageExtEeprom(uint16_t addr, uint8_t *page, uint8_t pagesize, uint8_t firstpage);
00040
00041 #define xeeprom_write_byte(addr, data) WriteByteExtEeprom(addr, data)
00042 #define xeeprom_read_byte(addr) ReadByteExtEeprom(addr)
00043 #define xeeprom_write_page(addr, page, pagesize, firstpage) WritePageExtEeprom(addr, page, pagesize, firstpage)
00044 #define xeeprom_read_page(addr) ReadPageExtEeprom(addr)
00045 #endif // _SPIEEPROM_H_
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: sunsensors.c Source File

sunsensors.c

Go to the documentation of this file.
00001 /**
00002  @file sunsensors.c
00003
00004  Implementation of the sun sensor interface
00005 */
00006
00007 #include "sunsensors.h"
00008 #include <avr/signal.h>
00009 #include <avr/interrupt.h>
00010 uint8_t sun_measurements[SUN_SENSORS];
00011 uint8_t volatile adc_finished;
00012 void initSunsensors(void) {
00013         // Set up ADC register.
00014         ADCSRA = 0;
00015         ADMUX = (1 << ADLAR); // Left adjust result
00016         ADCSRA = (1<<ADPS2)|(1<<ADPS1); // Set prescaler
00017
00018 }
00019 /*
00020 SIGNAL(SIG_ADC) {
00021         adc_finished = TRUE;
00022 }
00023 */
00024 void sampleSunsensors(void){
00025         uint8_t n;
00026 //      ADMUX = 0; // Disable internal Vref and set to channel 0
00027         //set_bit(ADCSRA, ADEN); // Enable ADC
00028         adc_finished = FALSE;
00029         ADCSRA |= (1 << ADEN) |(1<<ADPS2)|(1<<ADPS1);
00030         set_bit(ADCSRA, ADIF);
00031         set_bit(ADCSRA, ADSC);
00032
00033         for (n = 0; n < SUN_SENSORS; n++) {
00034                 ADMUX = (1 << ADLAR) | n;
00035                 ADCSRA |= (1<<ADSC);            //Start konvertering
00036                 //while (!adc_finished)
00037                 //  ;
00038                 loop_until_bit_is_set(ADCSRA, ADIF);
00039                 sun_measurements[n] = ADCH;
00040                 set_bit(ADCSRA, ADIF);
00041                 adc_finished = FALSE;
00042         }
00043         ADCSRA = 0; // Disable ADC
00044 }
00045
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: sunsensors.h Source File

sunsensors.h

Go to the documentation of this file.
00001 /**
00002  @file sunsensors.h
00003
00004  Interface to the LDR sun sensors
00005
00006  The sun sensors are sampled sequently from channel 0 (ADC0) to 5 (ADC5).
00007  For the corresponding side panels see #Ldrs.
00008 */
00009
00010 #ifndef _SUNSENSORS_H_
00011 #define _SUNSENSORSH_H_
00012
00013 #include "adcshdr.h"
00014
00015 #define SUN_SENSORS 6 ///< Number of sun sensors
00016
00017 enum Ldrs {
00018         LDR_D,
00019         LDR_Z,
00020         LDR_C,
00021         LDR_A,
00022         LDR_B,
00023         LDR_N
00024 };
00025
00026 /**
00027  Sun measurements storage
00028
00029  See #Ldrs for corresponding panels.
00030 */
00031 extern uint8_t sun_measurements[];
00032
00033 /// Initialize ADC
00034 void initSunsensors(void);
00035
00036 /**
00037  Sample sun sensors
00038
00039  Wait until all sun sensors have been sampled.
00040  Results are stored in #sun_measurements.
00041 */
00042 void sampleSunsensors(void);
00043
00044 #endif // _SUNSENSORS_H_
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: telecommands.h Source File

telecommands.h

Go to the documentation of this file.
00001 /**
00002  @file telecommands.h
00003
00004  Definition of recognized commands received from the TeleCommand.
00005
00006  Command numbers from 64-127 are reserved for the ADCS system.
00007  @note
00008  Many of the commands have parameters. Unless noted specificly,
00009  all parameters are of type uint8_t.
00010 */
00011
00012 #define CMD_NUM_LOW 64    ///< Lowest adcs command number
00013 #define CMD_NUM_HIGH 127  ///< Highest adcs command number
00014
00015 /**
00016  @name Tele commands
00017  External commands recognized by the ADCS module.
00018
00019  The commands will be sent from the ground station through the TeleCommand
00020  module.
00021  @{
00022 */
00023
00024 #define STATUS_CMD                              69  ///< Download sytem status.
00025 #define EXT_STATUS_CMD                  123 ///< Download extended system status.
00026
00027 #define MAG_CMD                                 65 ///< Send command string to magnetometer.
00028
00029 /**
00030  Start detumbling.
00031
00032  @param detumbling_period
00033    Number of minutes to detumble. If set to zero, or not specified,
00034    detumbling will continue until stopped with the #STOP_DETUMBLING_CMD or
00035    magnetometer is switched off.
00036  @note
00037    Befor detumbling is started there is an initial delay. The delay can
00038    be set by altering the #WAITSTATE_DELAY_PAR parameter using the
00039    #SET_PARAMETER_CMD command.
00040 */
00041
00042 #define START_DETUMBLING_CMD    66
00043 #define STOP_DETUMBLING_CMD     67 ///< Stop detumbling.
00044
00045 #define MAGQUERY_CMD            79 ///< Query magnetometer settings.
00046
00047 /// Start downloading of logs from external EEPROM.
00048 #define DOWNLOAD_LOGS_CMD               68
00049 #define STOP_DOWNLOAD_CMD               72
00050 #define RESETELOG_CMD                   83 ///< Reset external eeprom
00051
00052 /**
00053  Set a parameter stored in internal EEPROM.
00054
00055  @param parameter_id
00056  Possible values:
00057    - #MAG_SAMPLINGRATE_PAR
00058    - #CONTROLLER_GAIN_PAR
00059    - #WAITSTATE_DELAY_PAR
00060    - #K_XY_N_PAR
00061    - #K_XY_D_PAR
00062    - #K_Z_N_PAR
00063    - #K_Z_D_PAR
00064    - #MC_Z_PAR
00065    - #MEASURE_PERIOD_PAR
00066    - #ACTUATE_PERIOD_PAR
00067    - #MAGDELAY_PERIOD_PAR
00068
00069  @param value See the detailed description of the parameters above.
00070
00071  @note
00072  Negative numbers are represented using 2's complement signed integers.
00073  To convert a positive number to a negative one, invert it's bits and add 1.
00074  Example:
00075  \verbatim
00076  a = 123 = 0x7b = 0111 1011
00077  b = -a = ~a +1 = 1000 0100 + 1 = 1000 0101 = 0x85 = -123
00078  \endverbatim
00079
00080 */
00081 #define SET_PARAMETER_CMD               124
00082
00083 /**
00084  Query parameter value stored in internal EEPROM.
00085  @param parameter_id
00086 */
00087 #define GET_PARAMETER_CMD     125
00088
00089 /**
00090  Enable logging of data
00091
00092  @param logflag What data should be logged.
00093  @param timestep Number of seconds between each logging of data.
00094  @param log_period Number of minutes to log. If set to zero or omitted,
00095  log until the #STOP_LOGGING_CMD is sent.
00096  @note
00097    Befor logging is started, there is an initial delay. The delay can
00098    be set by altering the #WAITSTATE_DELAY_PAR parameter using the
00099    #SET_PARAMETER_CMD command.
00100
00101  To log different measurements set different bits in logflag. Defined
00102  bits are #B_LOG, #BDOT_LOG, #DUTY_LOG and #SUN_LOG. Example
00103  \code
00104  logflag  = (1 << B_LOG) | (1<< SUN_LOG);
00105  \endcode
00106  @note (Wait feature disabled during debugging)
00107 */
00108 #define START_LOGGING_CMD               90
00109 #define STOP_LOGGING_CMD                91      ///< Disable logging of data.
00110
00111 //#define GET_DTMBLPARAMS_CMD   92  ///< Print all detumbling parameters
00112 #define SLEEP_CMD                               126 ///< Enter sleep mode for power saving.
00113 #define RESET_CMD                               127 ///< Trigger watchdog timer and reset mcu.
00114
00115 //@}
00116
00117 /**
00118  @name Debug commands
00119
00120  Commands for debugging purposes.
00121
00122  Most of these commands will be removed in the final version of the software.
00123  @{
00124 */
00125 #define CHAR_CMD                                64
00126 #define STARTMAG_CMD                    70
00127 #define STOPMAG_CMD                     71
00128 //#define STARTPWM_CMD                  73
00129 #define DISABLE_COILS_CMD               74
00130
00131 /**
00132  Set duty cycle and direction of coils
00133
00134  Duty cycles must be in the range -255..+255. Negative numbers are in 2's
00135  complement form.
00136
00137  @param duty_x int16_t
00138  @param duty_y int16_t
00139  @param duty_z int16_t
00140
00141  @warning
00142  Setting all duty cylces to 255 consumes a lot of power.
00143 */
00144 #define SETDUTY_CMD                             75
00145
00146
00147 //#define TOGGLEDIR_CMD           76
00148 //#define TOGGLEENABLE_CMD              80
00149 //#define MAGSET_CMD              77
00150 //#define MAGRST_CMD              78
00151 //#define TMP_SENDM_CMD                 87
00152 //@}
00153
00154
00155 /**
00156  @name Internal commands
00157
00158  Recognized commands from other subsystems in the satellite. The
00159  commands are used for timing and flow control.
00160
00161  @note
00162  General call recognition must be enabled in the TWI module in order
00163  to receive these commands.
00164  @{
00165 */
00166 #define PAUSE_DOWNLOAD_CMD              192 ///< TNC buffer full
00167 #define CONTINUE_DOWNLOAD_CMD   193 ///< TNC ready for more data
00168 #define TIMEUPDATE_CMD                  194 ///< Receive current time from Telecommand
00169
00170 //@}
00171
00172 /*
00173 #define START_DETUMBLING_CMD    1 ///< Start detumbling
00174 #define STOP_DETUMBLING_CMD     2 ///< Stop detumbling
00175 #define START_LOGGING_CMD       3
00176 #define STOP_LOGGING_CMD                4 ///< Stop logging
00177 #define DELETE_LOG_CMD          5 ///< Delete log
00178 #define MAGCOMM_CMD                     6 ///< Send a command to magnetometer
00179 #define DOWNLOAD_EXTLOG_CMD     7 ///< Download log
00180 #define SET_PARAMETER_CMD               8 ///< Set an internal parameter
00181 #define RESET_CMD                               9 ///< Reset mcu.
00182 #define
00183 */
00184
00185
00186
00187
00188
00189 ///@name Parameter id
00190 //@{
00191 #define MAG_SAMPLINGRATE_PAR 1
00192 #define CONTROLLER_GAIN_PAR 2
00193 #define WAITSTATE_DELAY_PAR 3
00194
00195 #define K_XY_N_PAR 4 ///< Id for int16_t #EE_k_xy_n
00196 #define K_XY_D_PAR 5 ///< Id for int16_t #EE_k_xy_d
00197 #define K_Z_N_PAR 6  ///< Id for int16_t #EE_k_z_n
00198 #define K_Z_D_PAR 7  ///< Id for int16_t #EE_k_z_d
00199 #define MC_Z_PAR 8   ///< Id for int16_t #EE_mc_z
00200
00201 #define BDOT_MIN_PAR 9 ///< Id for uint16_t #EE_bdot_min
00202 #define M_MAX_PAR 10   ///< Id for uint16_t #EE_m_max
00203
00204 #define DTMBL_LOGDATA_REG_PAR 11 ///< Id for #EE_logdata_reg
00205 #define DTMBL_LOGTIMESTEP_PAR 12 ///< Id for #EE_logtimestep_par
00206
00207 #define MEASURE_PERIOD_PAR 13    ///< Id for #EE_measure_period
00208 #define ACTUATE_PERIOD_PAR 14    ///< Id for #EE_actuate_period
00209 #define MAGDELAY_PERIOD_PAR 15   ///< Id for #EE_magdelay_period
00210
00211
00212 //@}
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: timingutils.c Source File

timingutils.c

Go to the documentation of this file.
00001 /**
00002  * @file timingutils.c
00003  *
00004  * Implemenation of timing utilities.
00005  *
00006  */
00007
00008
00009
00010 #include "timingutils.h"
00011 #include <avr/io.h>
00012 #include <avr/signal.h>
00013 #include "avrutils.h"
00014
00015
00016 #if F_CPU == 8000000L
00017 //      #define TCCR2_VALUE (1 << CS22) | (1 << CS20) // Set prescaler = 128, Normal mode
00018 //      #define TCNT2_RELOAD_VALUE 193
00019 //      #define OCR2_VALUE 0xFF
00020         #define TCCR2_VALUE (1 << WGM21) | (1 << CS22) // Prescaler 64, CTC mode
00021         #define TCNT2_RELOAD_VALUE 0x83
00022         #define OCR2_VALUE 0x7D
00023         #warning 8mhz
00024 #elif F_CPU == 4000000L
00025         #define TCCR2_VALUE (1 << WGM21) | (1 << CS22) //| (1 << CS20) // Prescaler 32, CTC mode
00026         #define TCNT2_RELOAD_VALUE 0xc2
00027         #define OCR2_VALUE 0x3e
00028         #warning 4mhz
00029 #else
00030         #error Unknown frequency
00031 #endif
00032
00033
00034 uint8_t volatile timed_out_ms;
00035 uint8_t volatile timed_out_sec;
00036 uint8_t volatile timed_out_min;
00037
00038
00039 uint16_t volatile timeout_counter_ms;
00040 uint8_t volatile timeout_counter_sec;
00041 uint8_t volatile timeout_counter_min;
00042
00043 uint8_t volatile timeout_period_sec;
00044 uint8_t volatile timeout_period_min;
00045 uint16_t volatile timeout_period_ms;
00046
00047 uint32_t volatile UTC_Second;
00048
00049 uint8_t active_timers; ///< Number of activated timers.
00050 uint8_t timer_reg; ///< Tells which timers are on.
00051
00052 /**
00053  * Timer2 interrupt handler
00054  *
00055  * Triggered with a period of 1 ms
00056  */
00057 SIGNAL(SIG_OVERFLOW2) {
00058         static uint8_t counter_sec = 0;
00059         static uint16_t counter_ms = 0;
00060         if (timeout_counter_ms++ == timeout_period_ms) {
00061                 timed_out_ms = 1;
00062         }
00063         if (++counter_ms == 1000) {
00064                 counter_ms = 0;
00065                 UTC_Second++;
00066                 // check for seconds timeout
00067                 if (++timeout_counter_sec == timeout_period_sec) {
00068                         timed_out_sec = 1;
00069                 }
00070                 if (++counter_sec == 60) {
00071                         counter_sec = 0;
00072                         if (++timeout_counter_min == timeout_period_min) {
00073                                 timed_out_min = 1;
00074
00075                         }
00076
00077                 }
00078         }
00079         TCNT2 = TCNT2_RELOAD_VALUE;
00080 }
00081
00082 void init_timing(void) {
00083         //timed_out = 0;
00084         active_timers = 0;
00085         timer_reg = 0;
00086 }
00087
00088
00089 /*
00090   F_CPU 4Mhz
00091   DIV   OVF8    CMP8
00092   ------------------
00093   16    0x06    0xFA
00094   32    0x83    0x7D
00095
00096   F_CPU 8Mhz
00097   DIV   OVF8    CMP8
00098   ------------------
00099   32    0x06    0xFA
00100   64    0x83    0x7D
00101
00102 */
00103 void enable_timeout(Timers timer , uint16_t period) {
00104         clear_bit(TIMSK, TOIE2); // Disable timer2 overflow interrupt
00105         if (active_timers == 0) {
00106                 TCCR2 = TCCR2_VALUE;
00107                 TCNT2 = TCNT2_RELOAD_VALUE;
00108                 OCR2 = OCR2_VALUE;
00109         }
00110         switch (timer) {
00111                 case MS_TIMER:
00112                         timed_out_ms = 0;
00113                         timeout_period_ms = period;
00114                         timeout_counter_ms = 0;
00115                         if (!bit_is_set(timer_reg, MS_TIMER)) {
00116                                 set_bit(timer_reg, MS_TIMER);
00117                                 active_timers++;
00118                         }
00119                         break;
00120                 case SEC_TIMER:
00121                         timed_out_sec = 0;
00122                         timeout_period_sec = (uint8_t)period;
00123                         timeout_counter_sec = 0;
00124                         if (!bit_is_set(timer_reg, SEC_TIMER)) {
00125                                 set_bit(timer_reg, SEC_TIMER);
00126                                 active_timers++;
00127                         }
00128                         break;
00129                 case MIN_TIMER:
00130                         timed_out_min = 0;
00131                         timeout_period_min = (uint8_t)period;
00132                         timeout_counter_min = 0;
00133                         if (!bit_is_set(timer_reg, MIN_TIMER)) {
00134                                 set_bit(timer_reg, MIN_TIMER);
00135                                 active_timers++;
00136                         }
00137                         break;
00138                 default:
00139                         break;
00140         }
00141
00142         set_bit(TIMSK, TOIE2); // Enable timer2 overflow interrupt
00143 }
00144
00145 void disable_timeout(Timers timer) {
00146         switch (timer){
00147                 case MS_TIMER:
00148                 case SEC_TIMER:
00149                 case MIN_TIMER:
00150                         if (bit_is_set(timer_reg, timer)) {
00151                                 clear_bit(timer_reg, timer);
00152                                 active_timers--;
00153                         }
00154                         break;
00155                 case ALL_TIMERS:
00156                         timer_reg = 0;
00157                         active_timers = 0;
00158                         break;
00159
00160         }
00161         if (active_timers == 0) {
00162                 TCCR2 = 0; // Disconnect timer.
00163                 clear_bit(TIMSK, TOIE2); // Disable timer2 overflow interrupt
00164         }
00165         /*timed_out_ms = 1;
00166         timed_out_sec = 1;
00167         timed_out_min = 1;
00168         timeout_counter_ms = 0;
00169         timeout_counter_sec = 0;
00170         timeout_counter_min = 0;*/
00171 }
00172
00173 void restart_timeout(Timers timer) {
00174         switch (timer) {
00175                 case MS_TIMER:
00176                         timed_out_ms = 0;
00177                         timeout_counter_ms = 0;
00178                         break;
00179                 case SEC_TIMER:
00180                         timed_out_sec = 0;
00181                         timeout_counter_sec = 0;
00182                         break;
00183                 case MIN_TIMER:
00184                         timed_out_min = 0;
00185                         timeout_counter_min = 0;
00186                         break;
00187                 default:
00188                         break;
00189         }
00190
00191 }
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: timingutils.h Source File

timingutils.h

Go to the documentation of this file.
00001 /**
00002  * @file timingutils.h
00003  *
00004  * Timing utilities.
00005  *
00006  * Various utilites for handling delays and timing. Both loop and timer based.
00007  *
00008  * @todo Make it easier to change which mcu timer to use.
00009  * @todo Add support for multiple timeouts with different periods.
00010  */
00011 #ifndef _TIMINGUTILS_H_
00012 #define _TIMINGUTILS_H_
00013 #include <inttypes.h>
00014 #include "adcshdr.h"
00015
00016 typedef enum {
00017         MS_TIMER,
00018         SEC_TIMER,
00019         MIN_TIMER,
00020         ALL_TIMERS
00021 } Timers;
00022
00023
00024 /**@name Delay macros.
00025  * Delay using loops.
00026  *
00027  * @note
00028  * The code is from the 'general peripheral drivers' library written by
00029  * Chris Efstathiou
00030  *
00031  * @warning
00032  * If an interrupt occur while running one of the delay macros, the
00033  * delay will be prolonged with the time it takes to serve the interrupt.
00034  * @{
00035  */
00036 #ifndef DELAY_L_ACCURATE
00037
00038 /* 6 cpu cycles per loop + 3 overhead when a constant is passed. */
00039 #define DELAY_L_ACCURATE(x)  ({ unsigned long number_of_loops=(unsigned long)x;   \
00040                                 __asm__ volatile ( "L_%=: \n\t"                   \
00041                                                    "subi %A0,lo8(-(-1)) \n\t"     \
00042                                                    "sbci %B0,hi8(-(-1)) \n\t"     \
00043                                                    "sbci %C0,hlo8(-(-1)) \n\t"    \
00044                                                    "sbci %D0,hhi8(-(-1)) \n\t"    \
00045                                                    "brne L_%= \n\t"               \
00046                                                    : /* NO OUTPUT */              \
00047                                                    : "w" (number_of_loops)        \
00048                                                  );                               \
00049                              })
00050
00051
00052
00053
00054 #define TIME_L1_MS      ( 1*(F_CPU/6000) )     /* 1 MILLISECOND  */
00055 #define TIME_L100_US    ( 1*(F_CPU/60000) )    /* 100 MICROSECONDS  */
00056 /// Delay a specific number of milliseconds
00057 #define DELAY_MS(ms)    DELAY_L_ACCURATE( (TIME_L1_MS*ms) )
00058 /// Delay a specific number of microseconds
00059 #define DELAY_L_US(us)  DELAY_L_ACCURATE( (TIME_L100_US*(us/100))+1 )
00060
00061 #endif /* #ifndef DELAY_L_ACCURATE */
00062 ///@}
00063
00064 extern uint32_t volatile UTC_Second; ///< Global second counter.
00065 extern uint8_t volatile timed_out_ms;
00066 extern uint8_t volatile timed_out_sec;
00067 extern uint8_t volatile timed_out_min;
00068
00069 /**
00070  * Initialize timer
00071  *
00072  * Uses TIMER2 normal mode.
00073  */
00074 void init_timing(void);
00075
00076 /**
00077  * Enable timeout.
00078  *
00079  * Start a timer with a specified timeout period. When a timeout occur
00080  * the timed_out flag is set.
00081  *
00082  * @param timer Which timeout to set.
00083  * @param period Timeout period.
00084  *
00085  * @warning
00086  * If the watchdog timer is enabled it can be triggered by a long timeout
00087  * loop.
00088  *
00089  */
00090 void enable_timeout(Timers timer, uint16_t period);
00091
00092 /**
00093  * Disable timeout.
00094  *
00095  * If no timers are active the timer interrupt is switched off.
00096  *
00097  * @param timer Which timer to disable
00098  */
00099 void disable_timeout(Timers timer);
00100
00101 /**
00102  * Restart timeout timer.
00103  *
00104  * Reset the internal counter and start a new period.
00105  *
00106  * @param timer Which timer to restart.
00107  */
00108 void restart_timeout(Timers timer);
00109
00110 #endif // _TIMEUTILS_H_
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: tnccomm.c Source File

tnccomm.c

Go to the documentation of this file.
00001 /**
00002  * @file tnccomm.c
00003  *
00004  * Implementation of the TNC communication module.
00005  *
00006  */
00007
00008 #include "tnccomm.h"
00009 #include "softi2c.h"
00010 #include "timingutils.h"
00011
00012 uint8_t TNC_TXBuf[TNC_TXBUF_SIZE]; ///< TNC transmit buffer
00013 uint8_t TNC_TXBufSize = 0; ///< Current size of TNC_TXBuf.
00014
00015 uint8_t TNC_TX_Rd_Idx;
00016 uint8_t TNC_TX_Wr_Idx;
00017 uint8_t TNC_TX_Counter;
00018
00019
00020 uint8_t volatile TNC_status_reg;
00021
00022 //#define DEBUG_ADCS
00023
00024 #ifdef DEBUG_ADCS
00025
00026 #define DDR_SPI DDRB
00027 #define SPI_PORT PORTB
00028 #define SS_PIN PB4
00029 #define MOSI_PIN PB5
00030 #define MISO_PIN PB6
00031 #define SCK_PIN PB7
00032
00033
00034 #define PUTCHAR_CMD 0x11
00035
00036 #define enable_spi() (SPI_PORT &= ~(1 << SS_PIN))
00037 #define disable_spi() (SPI_PORT |= (1 << SS_PIN))
00038
00039 #define enable_spi_slave() (SPI_PORT &= ~(1 << SS_PIN))
00040 #define disable_spi_slave() (SPI_PORT |= (1 << SS_PIN))
00041
00042 #endif // DEBUG_ADCS
00043
00044 void tnc_puthex8(uint8_t n,uint8_t f) {
00045     if (f) {
00046         if (f==1) tnc_put_P(PSTR("0x"));
00047         if (n<16) tnc_put_P(PSTR("0"));
00048     }
00049     if (n/16) tnc_puthex8(n/16,0);
00050     if (n%16>9) tnc_putchar((n % 16) + '7');
00051     else tnc_putchar((n % 16) + '0');
00052 }
00053
00054
00055 /**
00056  * Send a string.
00057  *
00058  * @todo Add overflow detection and handling.
00059  */
00060 void tnc_put(char *buf){
00061         while(*buf) {
00062                 tnc_putchar(*buf++);
00063         }
00064 }
00065
00066 /**
00067  * Send a string stored in program memory.
00068  *
00069  * @param addr Pointer to string stored in program memory.
00070  * @todo Add overflow detection and handling.
00071  */
00072 void tnc_put_P(PGM_P addr) {
00073         char c;
00074         while ((c = __LPM((unsigned short)addr++)))
00075                 tnc_putchar(c);
00076 }
00077
00078 /**
00079  * Send a string and and append a newline character.
00080  */
00081 void tnc_putline(char *buf){
00082         while(*buf) {
00083                 tnc_putchar(*buf++);
00084         }
00085         tnc_putchar('\n');
00086         tnc_putchar('\r');
00087 }
00088
00089 /**
00090  * Send a string stored in program memory and append a newline character.
00091  */
00092 void tnc_putline_P(PGM_P addr){
00093         char c;
00094         while ((c = __LPM((unsigned short)addr++)))
00095                 tnc_putchar(c);
00096         tnc_putchar('\n');
00097         tnc_putchar('\r');
00098 }
00099
00100 /// @todo Add error handling.
00101 void tnc_putchar(char c) {
00102 #ifdef DEBUG_ADCS
00103
00104         enable_spi_slave();
00105         SPDR = PUTCHAR_CMD;
00106         loop_until_bit_is_set(SPSR, SPIF); //
00107         SPDR = c;
00108         loop_until_bit_is_set(SPSR, SPIF); // send char
00109         disable_spi_slave();
00110 #else
00111         if (TNC_TX_Wr_Idx<TNC_TXBUF_SIZE-1){
00112                 TNC_TXBuf[TNC_TX_Wr_Idx++]=c;
00113                 set_bit(TNC_status_reg, I2C_BUFFER_RDY_BIT);
00114         } else {
00115                 transmit_12c_buffer();
00116                 tnc_putchar(c);
00117         }
00118         /*
00119         i2c_start_tx(I2C_TNC_ADDR); // Start transmission
00120     //i2c_put_byte(CHAR_CMD); // Send command ID
00121     //i2c_put_byte(1);          // Send length of data
00122     i2c_put_byte(c);            // Send data
00123     i2c_stop();             // Stop transmission
00124     */
00125 #endif
00126 }
00127
00128 void tnc_putchar_n(char c) {
00129     if (c == '\n') {
00130                 tnc_putchar('\r');
00131     }
00132     tnc_putchar(c);
00133 }
00134
00135 void init_tnc(void) {
00136 #ifdef DEBUG_ADCS
00137 /* Set MOSI,SCK and SS as output */
00138         DDR_SPI = (1 << MOSI_PIN) | (1 << SCK_PIN) | (1 << SS_PIN);
00139         SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR0);
00140         set_bit(SPI_PORT, SS_PIN);  // Disable spi device
00141 #else
00142         TNC_status_reg = 0;
00143         TNC_TX_Rd_Idx = 0;
00144         TNC_TX_Wr_Idx = 0;
00145 #endif
00146 }
00147
00148
00149 /**
00150  * Transmit the contents of the i2c transmit buffer.
00151  * @return Error code. 0 if no errors.
00152  */
00153 uint8_t transmit_12c_buffer(void){
00154         uint8_t error, counter;
00155         counter = 0; error = 0;
00156         while (TNC_TX_Rd_Idx < TNC_TX_Wr_Idx) {
00157                 if (!bit_is_set(TNC_status_reg, TNC_BUFFER_FULL_BIT)) {
00158                         for( counter = 0;counter < 20; counter ++) {
00159                                 //i2c_start();
00160                                 //error |= i2c_get_error();
00161                         //i2c_put_byte(I2C_TNC_ADDR);
00162                         //error |= i2c_get_error();
00163                                 //i2c_start_tx(I2C_TNC_ADDR); // Start transmission
00164                                 //error |= i2c_get_error();
00165                                 error = Soft_I2C_Write(I2C_TNC_ADDR, TNC_TXBuf[TNC_TX_Rd_Idx++]);
00166                                 //i2c_put_byte();               // Send data
00167                                 //error |= i2c_get_error();
00168                                 //i2c_stop();             // Stop transmission
00169                         /*error |= i2c_get_error();
00170
00171                         error |= i2c_get_error();
00172                         */
00173                         if (error) {
00174
00175                                 TNC_TX_Rd_Idx--;
00176                                 //counter++;
00177                                 if (counter == 5) {
00178                                         return error;
00179                                         }
00180                                 DELAY_MS(2);
00181                                 error = 0;
00182                                 continue;
00183
00184                                 }
00185                         break;
00186                 }
00187
00188                 } else {
00189                         return TRUE;
00190                 }
00191         }
00192
00193         clear_bit(TNC_status_reg, I2C_BUFFER_RDY_BIT);
00194         TNC_TX_Rd_Idx = 0;
00195         TNC_TX_Wr_Idx = 0;
00196         return 0;
00197
00198 }
00199
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: tnccomm.h Source File

tnccomm.h

Go to the documentation of this file.
00001 /**
00002  * @file tnccomm.h
00003  *
00004  * TNC communication module.
00005  *
00006  * Top-level functions for transmitting data to the TNC. The code has a
00007  * modular design that makes it easy to change the peripheral bus for
00008  * communication.
00009  *
00010  * @author Kjell Magne Fauske
00011  *
00012  */
00013 #ifndef _TNCCOMM_H_
00014 #define _TNCCOMM_H_
00015
00016 #include "adcshdr.h"
00017 #include <avr/pgmspace.h>
00018
00019 #define TNC_TXBUF_SIZE 100 ///< Size of TNC transmit buffer.
00020 #define I2C_TNC_ADDR 0x78  ///< Address of the TNC on the I2C bus.
00021 //#define SPI_CHAR_CMD 12
00022
00023 #define TNC_BUFFER_FULL_BIT 1 ///< Set if TNC buffer is full
00024 #define I2C_BUFFER_RDY_BIT 0
00025 #define I2C_BUF_OVERFLOW_BIT 2
00026 /**
00027  TNC status register.
00028
00029  - #TNC_BUFFER_FULL_BIT
00030  - #I2C_BUFFER_RDY_BIT
00031 */
00032 extern uint8_t volatile TNC_status_reg;
00033
00034 /**
00035  * Send a string.
00036  */
00037 void tnc_put(char *buf);
00038
00039 /**
00040  * Send a string stored in program memory.
00041  *
00042  * @param addr Pointer to string stored in program memory.
00043  */
00044 void tnc_put_P(PGM_P addr);
00045
00046 /**
00047  * Send a string and and append a newline character.
00048  */
00049 void tnc_putline(char *buf);
00050
00051 /**
00052  * Send a string stored in program memory and append a newline character.
00053  */
00054 void tnc_putline_P(PGM_P addr);
00055
00056 /**
00057  * Send a single character.
00058  *
00059  * Used by the put() and putline() functions. To change communication
00060  * peripheral, only this function need to be changed.
00061  *
00062  * @todo Use a function pointer to allow runtime change of communication
00063  * peripheral.
00064  */
00065 void tnc_putchar(char c);
00066
00067 /**
00068  * Send a single character.
00069  *
00070  * Add a carriage return char after a nnewline char.
00071  *
00072  */
00073 void tnc_putchar_n(char c);
00074
00075
00076 /// Initialize TNC communication
00077 void init_tnc(void);
00078
00079 /**
00080  * Transmit the contents of the i2c transmit buffer.
00081  * @return Error code. 0 if no errors.
00082  */
00083 uint8_t transmit_12c_buffer(void);
00084
00085 void tnc_puthex8(uint8_t n,uint8_t f);
00086
00087 #define tnc_newline() {tnc_putchar('\n'); tnc_putchar('\r');}
00088
00089 #endif /* _TNCCOMM_H_ */
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: twislave.c Source File

twislave.c

Go to the documentation of this file.
00001 /**
00002  * @file twislave.c
00003  *
00004  * Implementation of the TWI slave module.
00005  *
00006  */
00007
00008 #include "twislave.h"
00009 #include "adcshdr.h"
00010 #include <avr/twi.h>
00011 #include <avr/signal.h>
00012
00013 uint8_t CmdBuf[CMDBUF_MAXSIZE];
00014 uint8_t CmdBufSize, CmdBufRdy;
00015
00016 /**
00017  * TWI interrupt handler for slave receiver mode.
00018  *
00019  * @todo Implement better error handling.
00020  */
00021 SIGNAL(SIG_2WIRE_SERIAL) {
00022         uint8_t twistatus = TW_STATUS;
00023         uint8_t rx;   // Received data
00024         switch (twistatus) {
00025         case TW_SR_SLA_ACK:          //address match - send ACK
00026             TWCR |= (1<<TWINT)|(1<<TWEA);
00027             break;
00028         case TW_SR_ARB_LOST_SLA_ACK: //arbitreringsfeil, men adresse match - send ACK
00029             TWCR |= (1<<TWINT);
00030             break;
00031         case TW_SR_GCALL_ACK:        // generall call address, send ACK
00032             TWCR |= (1<<TWINT)|(1<<TWEA);
00033             break;
00034         case TW_SR_DATA_ACK:         // Data received, send ACK
00035                // Fall through
00036         case TW_SR_GCALL_DATA_ACK:   // Data received on general call adresse
00037             TWCR |= (1<<TWINT)|(1<<TWEA);
00038             rx = TWDR;  // Load received data
00039             CmdBuf[CmdBufSize++]=rx;
00040             if ((CmdBufSize>1) & (CmdBufSize-2==CmdBuf[CMDBUF_SIZE]))    //en hel kommando (inkl [CmdBufSize - 2] antall parametre) mottatt
00041                 CmdBufRdy=1;
00042             //CmdBufRdy=1;
00043             break;
00044         case TW_SR_DATA_NACK:                                //siste byte mottatt, nack sendt
00045             TWCR |= (1<<TWINT);
00046             break;
00047         case TW_SR_STOP:                                //stopp eller start betingelse mottatt for tidlig, avbryt
00048             TWCR |= (1<<TWINT)|(1<<TWEA);
00049             //CmdBufRdy=1;
00050                         break;
00051                 case 0xF8: // No relevant state information available
00052                         break;
00053                 case 0x00: // Bus error
00054                         TWCR |= (1<<TWSTO) |(1<<TWINT)|(1<<TWEA);
00055                         break;
00056         default:                                   // feil
00057             //Init_TWI();
00058             TWCR |= (1<<TWINT)|(1<<TWEA)|(1<<TWIE);
00059
00060             break;
00061       }
00062 }
00063
00064
00065
00066 /*
00067  *      init_twi_slave()
00068  */
00069 void init_twi_slave(uint8_t slave_addr) {
00070         TWAR = slave_addr;  // Load slave address.
00071         TWCR = (1<<TWINT)|(1<<TWEA)|(1<<TWEN)|(1<<TWIE); //Enable TWI and interrupts.
00072     DDRC &=~(1<<PC0)|(1<<PC1);  // Set pins as input
00073         PORTC |= (1<<PC0)|(1<<PC1); // enable internal pullup for i2c lines.
00074 }
00075
00076
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5


NCUBE ADCS: twislave.h Source File

twislave.h

Go to the documentation of this file.
00001 /**
00002  * @file twislave.h
00003  *
00004  * Interrupt driven TWI/I2C bus slave interface.
00005  *
00006  * The slave receives data from the master through the #CmdBuf buffer.
00007  * The variable #CmdBufRdy is set to indicate when a command is received.
00008  * #CmdBufRdy must be cleared after the message is read.
00009  *
00010  * Messages in the #CmdBuf has the following format:
00011  *      - CmdBuf[0] - Message id
00012  *      - CmdBuf[1] - Message lenght
00013  *      - CmdBuf[.] - Message data
00014  *
00015  * @note Interrupts must be enabled before commands can be received
00016  */
00017 #ifndef _TWISLAVE_H_
00018 #define _TWISLAVE_H_
00019
00020 #include "adcshdr.h"
00021
00022
00023 #define CMDBUF_MAXSIZE 256      ///<    Maximum size of command buffer.
00024 #define CMDBUF_ID               0       ///< Index to #cmdbuf id byte
00025 #define CMDBUF_SIZE     1       ///< Index to #cmdbuf size byte
00026 #define CMDBUF_DATA     2       ///< Index to first data byte ine #cmdbuf
00027 /**
00028  * Buffer used for receiving commands.
00029  *
00030  * It has the following format:
00031  *      - cmdbuf[0] - Message id
00032  *      - cmdbuf[1] - Message lenght
00033  *      - cmdbuf[.] - Message data
00034  */
00035 extern uint8_t CmdBuf[];
00036
00037 /// Number of bytes in CmdBuf
00038 extern uint8_t CmdBufSize;
00039
00040 /**
00041  * Command received.
00042  *
00043  * CmdBufRdy must be cleared before a new command can be recieved.
00044  */
00045 extern uint8_t CmdBufRdy;
00046
00047 /**
00048  * Initialize the TWI bus.
00049  *
00050  * @param slave_addr Value to load into the TWAR register.
00051  *
00052  * The seven MSB bits of the TWAR register is used to set the slave
00053  * address. The LSB of the TWAR is set to enable recognition of the
00054  * general call address ($00).
00055  *
00056  * @note Interrupts are noe enabled by init_twi_slave().
00057  *
00058  */
00059 void init_twi_slave(uint8_t slave_addr);
00060
00061
00062 #endif /* _TWISLAVE_H_ */
00063
00064
Generated on Fri Sep 3 17:21:13 2004 for NCUBE ADCS by doxygen 1.3.5