?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik /*! \file satmb.c \brief Satellite Motherboard Driver Functions. */
2 //*****************************************************************************
3 //
4 // File Name : 'satmb.c'
5 // Title : Satellite Motherboard Driver Functions
6 // Author : Pascal Stang - Copyright (C) 2004
7 // Created : 2004.10.13
8 // Revised : 2004.10.13
9 // Version : 0.1
10 // Target MCU : Atmel AVR series
11 // Editor Tabs : 4
12 //
13 // This code is distributed under the GNU Public License
14 // which can be found at http://www.gnu.org/licenses/gpl.txt
15 //
16 //*****************************************************************************
17  
18 //----- Include Files ---------------------------------------------------------
19 #include <avr/io.h> // include I/O definitions (port names, pin names, etc)
20 #include <avr/interrupt.h> // include interrupt support
21  
22 #include "global.h" // include our global settings
23 #include "dallas.h"
24 #include "ds2450.h"
25 #include "satmb.h"
26 #include "dallasids.h"
27  
28 // globals
29  
30 // functions
31 void satmbInit(void)
32 {
33 // preset serial port power to on
34 satmbSetSerialPortPower(1);
35 }
36  
37 void satmbSetSerialPortPower(u08 on)
38 {
39 // set I/O control line to output
40 sbi(SATMB_SER_PWR_DDR, SATMB_SER_PWR_PIN);
41 // set serial port power state
42 if(on)
43 sbi(SATMB_SER_PWR_PORT, SATMB_SER_PWR_PIN);
44 else
45 cbi(SATMB_SER_PWR_PORT, SATMB_SER_PWR_PIN);
46 }
47  
48 void satmbSerialRtsCtsInit(void)
49 {
50 // initialize RTS/CTS lines for operation
51 // RTS is input, set pullup
52 cbi(SATMB_SER_RTS_DDR, SATMB_SER_RTS_PIN);
53 sbi(SATMB_SER_RTS_PORT, SATMB_SER_RTS_PIN);
54 // CTS is output, init low
55 sbi(SATMB_SER_CTS_DDR, SATMB_SER_CTS_PIN);
56 cbi(SATMB_SER_CTS_PORT, SATMB_SER_CTS_PIN);
57 }
58  
59 u08 satmbSerialRtsCheck(void)
60 {
61 if(inb(SATMB_SER_RTS_PORTIN) & (1<<SATMB_SER_RTS_PIN))
62 return TRUE;
63 else
64 return FALSE;
65 }
66  
67 void satmbSerialCtsSet(u08 state)
68 {
69 if(state)
70 sbi(SATMB_SER_CTS_PORT, SATMB_SER_CTS_PIN);
71 else
72 cbi(SATMB_SER_CTS_PORT, SATMB_SER_CTS_PIN);
73 }
74  
75 u16 satmbV1GetCurrent(DallasSubsysId* targetSubsysId)
76 {
77 u16 value;
78 // setup A/D for 5V 16-bit conversion
79 ds2450SetupAll(&targetSubsysId->S, 16, DS2450_RANGE_5V);
80 // read current-level A/D
81 ds2450StartAndResult(&targetSubsysId->S, 'A', &value);
82 // calculate milliamp value
83 // ma = 1000*(((value/65536)*5.12V)/(50*R))
84 // for R=0.47/2 ohms
85 // return result
86 return value/150;
87 }
88  
89 u16 satmbV2GetCurrent(DallasSubsysId* targetSubsysId)
90 {
91 u16 value;
92 // setup A/D for 5V 16-bit conversion
93 ds2450SetupAll(&targetSubsysId->S, 16, DS2450_RANGE_5V);
94 // read current-level A/D
95 ds2450StartAndResult(&targetSubsysId->S, 'C', &value);
96 // calculate milliamp value
97 // ma = 1000*(((value/65536)*5.12V)/(50*R))
98 // for R=0.1/2 ohms
99 // return result
100 return value/32;
101 }
102  
103 u08 satmbV1GetOverCurrent(DallasSubsysId* targetSubsysId)
104 {
105 u16 value;
106 // setup A/D for 5V 16-bit conversion
107 ds2450SetupAll(&targetSubsysId->S, 16, DS2450_RANGE_5V);
108 // read overcurrent state A/D
109 ds2450StartAndResult(&targetSubsysId->S, 'B', &value);
110 // return result
111 return (value>0x8000);
112 }
113  
114 u08 satmbV2GetOverCurrent(DallasSubsysId* targetSubsysId)
115 {
116 u16 value;
117 // setup A/D for 5V 16-bit conversion
118 ds2450SetupAll(&targetSubsysId->S, 16, DS2450_RANGE_5V);
119 // read overcurrent state A/D
120 ds2450StartAndResult(&targetSubsysId->S, 'D', &value);
121 // return result
122 return (value>0x8000);
123 }
124  
125 void satmbV1SetPowerState(DallasSubsysId* targetSubsysId, u08 state)
126 {
127 satmbSetPowerState(&targetSubsysId->V1, state);
128 }
129  
130 void satmbV2SetPowerState(DallasSubsysId* targetSubsysId, u08 state)
131 {
132 satmbSetPowerState(&targetSubsysId->V2, state);
133 }
134  
135 void satmbSetPowerState(dallas_rom_id_T* targetRomId, u08 state)
136 {
137 if(state)
138 {
139 // reset overcurrent flag
140 ds2450DigitalOut(targetRomId, 'B', DIGOUT_LOW);
141 ds2450DigitalOut(targetRomId, 'B', DIGOUT_OC);
142 // assert enable
143 ds2450DigitalOut(targetRomId, 'A', DIGOUT_LOW);
144 }
145 // pulse clock line
146 ds2450DigitalOut(targetRomId, 'C', DIGOUT_OC);
147 ds2450DigitalOut(targetRomId, 'C', DIGOUT_LOW);
148 ds2450DigitalOut(targetRomId, 'C', DIGOUT_OC);
149 // release enable
150 ds2450DigitalOut(targetRomId, 'A', DIGOUT_OC);
151 }
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3