Contiki 3.x
uart.c
1 /*
2  * Copyright (C) 2015, Intel Corporation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "uart.h"
32 #include "uart-16x50.h"
33 #include <assert.h>
34 
35 PROT_DOMAINS_ALLOC(uart_16x50_driver_t, quarkX1000_uart0);
36 PROT_DOMAINS_ALLOC(uart_16x50_driver_t, quarkX1000_uart1);
37 
38 /* Divisor setting for 115200 baud from section 18.2.2 of Intel Quark SoC
39  * X1000 Datasheet.
40  */
41 #define QUARK_X1000_UART_DL_115200 24
42 
43 /*---------------------------------------------------------------------------*/
44 /**
45  * \brief Initialize a UART.
46  * \param dev Device to initialize.
47  */
48 void
49 quarkX1000_uart_init(quarkX1000_uart_dev_t dev)
50 {
51  pci_config_addr_t pci_addr;
52  uart_16x50_driver_t ATTR_KERN_ADDR_SPACE *drv;
53 
54  assert((dev == QUARK_X1000_UART_0) || (dev == QUARK_X1000_UART_1));
55 
56  pci_addr.raw = 0;
57 
58  /* PCI addresses from section 18.4 of Intel Quark SoC X1000 Datasheet. */
59  pci_addr.dev = 20;
60  pci_addr.func = (dev == QUARK_X1000_UART_0) ? 1 : 5;
61  pci_addr.reg_off = PCI_CONFIG_REG_BAR0;
62 
63  if(dev == QUARK_X1000_UART_0) {
64  drv = &quarkX1000_uart0;
65  PROT_DOMAINS_INIT_ID(quarkX1000_uart0);
66  } else {
67  drv = &quarkX1000_uart1;
68  PROT_DOMAINS_INIT_ID(quarkX1000_uart1);
69  }
70  uart_16x50_init(drv, pci_addr, QUARK_X1000_UART_DL_115200);
71 }
72 /*---------------------------------------------------------------------------*/
73 /**
74  * \brief Transmit a character via a UART.
75  * \param dev Device to use.
76  * \param c Character to transmit.
77  */
78 void
79 quarkX1000_uart_tx(quarkX1000_uart_dev_t dev, uint8_t c)
80 {
82  assert((dev == QUARK_X1000_UART_0) || (dev == QUARK_X1000_UART_1));
83  prot_domains_copy_dcd(&drv,
84  (dev == QUARK_X1000_UART_0) ?
85  &quarkX1000_uart0 : &quarkX1000_uart1);
86  uart_16x50_tx(drv, c);
87 }
88 /*---------------------------------------------------------------------------*/
uint32_t func
Function number.
Definition: pci.h:89
PCI configuration address.
Definition: pci.h:85
uint32_t dev
Device number.
Definition: pci.h:90
Data associated with each protection domain that is owned by clients of that domain and used to ident...
Definition: prot-domains.h:247
uint32_t reg_off
Register/offset number.
Definition: pci.h:88