PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
simple
serial_open.c
1
/*
2
* @file serial_open.c
3
* Opens a serial module.
4
*
5
* Copyright (c) 2013, Parallax Inc.
6
* Written by Steve Denson
7
*/
8
#include <stdlib.h>
9
#include <propeller.h>
10
#include "serial.h"
11
12
extern
HUBDATA
terminal
*dport_ptr;
13
14
serial
*serial_open(
int
rxpin,
int
txpin,
int
mode,
int
baudrate)
15
{
16
Serial_t
*serptr;
17
18
/* can't use array instead of malloc because it would go out of scope. */
19
text_t
* text = (
text_t
*) malloc(
sizeof
(
text_t
));
20
21
/* set pins first for boards that can misbehave intentionally like the Quickstart */
22
if
(txpin >= SERIAL_MIN_PIN && txpin <= SERIAL_MAX_PIN) {
23
DIRA |= (1<<txpin);
24
OUTA |= (1<<txpin);
25
}
26
if
(rxpin >= SERIAL_MIN_PIN && rxpin <= SERIAL_MAX_PIN) {
27
DIRA &= ~(1<<rxpin);
28
}
29
30
//memset(text, 0, sizeof(text_t));
31
serptr = (
Serial_t
*) malloc(
sizeof
(
Serial_t
));
32
text->
devst
= serptr;
33
memset((
char
*)serptr, 0,
sizeof
(
Serial_t
));
34
35
text->
txChar
= serial_txChar;
/* required for terminal to work */
36
text->
rxChar
= serial_rxChar;
/* required for terminal to work */
37
38
serptr->
rx_pin
= rxpin;
/* recieve pin */
39
serptr->
tx_pin
= txpin;
/* transmit pin*/
40
serptr->
mode
= mode;
41
serptr->
baud
= baudrate;
42
serptr->
ticks
= CLKFREQ/baudrate;
/* baud from clkfreq (cpu clock typically 80000000 for 5M*pll16x) */
43
44
return
text;
45
}
46
47
/*
48
+--------------------------------------------------------------------
49
| TERMS OF USE: MIT License
50
+--------------------------------------------------------------------
51
Permission is hereby granted, free of charge, to any person obtaining
52
a copy of this software and associated documentation files
53
(the "Software"), to deal in the Software without restriction,
54
including without limitation the rights to use, copy, modify, merge,
55
publish, distribute, sublicense, and/or sell copies of the Software,
56
and to permit persons to whom the Software is furnished to do so,
57
subject to the following conditions:
58
59
The above copyright notice and this permission notice shall be
60
included in all copies or substantial portions of the Software.
61
62
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
63
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
64
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
65
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
66
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
67
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
68
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
69
+--------------------------------------------------------------------
70
*/
text_struct::rxChar
int(* rxChar)(struct text_struct *p)
Definition:
simpletext.h:73
serial_info::mode
int mode
Definition:
serial.h:59
text_struct::txChar
int(* txChar)(struct text_struct *p, int ch)
Definition:
simpletext.h:75
serial_info::tx_pin
int tx_pin
Definition:
serial.h:58
text_struct::devst
volatile void * devst
Definition:
simpletext.h:79
serial_info::baud
int baud
Definition:
serial.h:60
serial_info::rx_pin
int rx_pin
Definition:
serial.h:57
text_struct
Structure that contains data used by simple text device libraries.
Definition:
simpletext.h:70
serial_info::ticks
int ticks
Definition:
serial.h:61
serial_info
Defines serial interface structure of 9 contiguous int variables.
Definition:
serial.h:55
Generated on Sat Aug 27 2016 00:58:09 for PropWare by
1.8.12