亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? rs485.c

?? Bacnet protocol stack for linux
?? C
字號(hào):
/**************************************************************************
*
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
* RS-485 initialization on AT91SAM7S inspired by Keil Eletronik serial.c
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/

/* The module handles sending data out the RS-485 port */
/* and handles receiving data from the RS-485 port. */
/* Customize this file for your specific hardware */
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include "timer.h"

/* This file has been customized for use with UART0
   on the AT91SAM7S-EK */
#include "board.h"

/* UART */
static volatile AT91S_USART *RS485_Interface = AT91C_BASE_US0;
/* baud rate */
static int RS485_Baud = 38400;

/* The minimum time after the end of the stop bit of the final octet of a */
/* received frame before a node may enable its EIA-485 driver: 40 bit times. */
/* At 9600 baud, 40 bit times would be about 4.166 milliseconds */
/* At 19200 baud, 40 bit times would be about 2.083 milliseconds */
/* At 38400 baud, 40 bit times would be about 1.041 milliseconds */
/* At 57600 baud, 40 bit times would be about 0.694 milliseconds */
/* At 76800 baud, 40 bit times would be about 0.520 milliseconds */
/* At 115200 baud, 40 bit times would be about 0.347 milliseconds */
/* 40 bits is 4 octets including a start and stop bit with each octet */
#define Tturnaround  (40UL)
/* turnaround_time_milliseconds = (Tturnaround*1000UL)/RS485_Baud; */

/****************************************************************************
* DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
*              receive mode.
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
void RS485_Initialize(
    void)
{
    /* Enable the USART0 clock in the Power Management Controller */
    volatile AT91PS_PMC pPMC = AT91C_BASE_PMC;
    pPMC->PMC_PCER = pPMC->PMC_PCSR | (1 << AT91C_ID_US0);

    /* Disable and clear USART0 interrupt
       in AIC Interrupt Disable Command Register */
    volatile AT91PS_AIC pAIC = AT91C_BASE_AIC;
    pAIC->AIC_IDCR = (1 << AT91C_ID_US0);
    pAIC->AIC_ICCR = (1 << AT91C_ID_US0);

    /* enable the peripheral by disabling the pin in the PIO controller */
    *AT91C_PIOA_PDR = AT91C_PA5_RXD0 | AT91C_PA6_TXD0 | AT91C_PA7_RTS0;

    RS485_Interface->US_CR = AT91C_US_RSTRX |   /* Reset Receiver      */
        AT91C_US_RSTTX |        /* Reset Transmitter   */
        AT91C_US_RSTSTA |       /* Clear status register */
        AT91C_US_RXDIS |        /* Receiver Disable    */
        AT91C_US_TXDIS; /* Transmitter Disable */

    RS485_Interface->US_MR = AT91C_US_USMODE_RS485 |    /* RS-485 Mode - RTS auto assert */
        AT91C_US_CLKS_CLOCK |   /* Clock = MCK */
        AT91C_US_CHRL_8_BITS |  /* 8-bit Data  */
        AT91C_US_PAR_NONE |     /* No Parity   */
        AT91C_US_NBSTOP_1_BIT;  /* 1 Stop Bit  */

    /* set the Time Guard to release RTS after x bit times */
    RS485_Interface->US_TTGR = 1;

    /* Receiver Time-out disabled */
    RS485_Interface->US_RTOR = 0;

    /* baud rate */
    RS485_Interface->US_BRGR = MCK / 16 / RS485_Baud;

    RS485_Interface->US_CR = AT91C_US_RXEN |    /* Receiver Enable     */
        AT91C_US_TXEN;  /* Transmitter Enable  */

    return;
}

void RS485_Cleanup(
    void)
{

}

/****************************************************************************
* DESCRIPTION: Returns the baud rate that we are currently running at
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
uint32_t RS485_Get_Baud_Rate(
    void)
{
    return RS485_Baud;
}

/****************************************************************************
* DESCRIPTION: Sets the baud rate for the chip USART
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
bool RS485_Set_Baud_Rate(
    uint32_t baud)
{
    bool valid = true;

    switch (baud) {
        case 9600:
        case 19200:
        case 38400:
        case 57600:
        case 76800:
        case 115200:
            RS485_Baud = baud;
            RS485_Interface->US_BRGR = MCK / 16 / baud;
            /* FIXME: store the baud rate */
            break;
        default:
            valid = false;
            break;
    }

    return valid;
}

/****************************************************************************
* DESCRIPTION: Waits on the SilenceTimer for 40 bits.
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
void RS485_Turnaround_Delay(
    void)
{
    uint16_t turnaround_time;

    /* delay after reception before trasmitting - per MS/TP spec */
    /* wait a minimum  40 bit times since reception */
    /* at least 1 ms for errors: rounding, clock tick */
    turnaround_time = 1 + ((Tturnaround * 1000UL) / RS485_Baud);
    while (Timer_Silence() < turnaround_time) {
        /* do nothing - wait for timer to increment */
    };
}

/****************************************************************************
* DESCRIPTION: Enable or disable the transmitter
* RETURN:      none
* ALGORITHM:   none
* NOTES:       The Atmel ARM7 has an automatic enable/disable in RS485 mode.
*****************************************************************************/
void RS485_Transmitter_Enable(
    bool enable)
{
    (void) enable;
}

/****************************************************************************
* DESCRIPTION: Send some data and wait until it is sent
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
void RS485_Send_Data(
    uint8_t * buffer,   /* data to send */
    uint16_t nbytes)
{       /* number of bytes of data */
    /* LED on send */
    volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
    /* LED ON */
    pPIO->PIO_CODR = LED1;
    /* send all the bytes */
    while (nbytes) {
        while (!(RS485_Interface->US_CSR & AT91C_US_TXRDY)) {
            /* do nothing - wait until Tx buffer is empty */
        }
        RS485_Interface->US_THR = *buffer;
        buffer++;
        nbytes--;
    }
    while (!(RS485_Interface->US_CSR & AT91C_US_TXRDY)) {
        /* do nothing - wait until Tx buffer is empty */
    }
    /* per MSTP spec */
    Timer_Silence_Reset();
}

/****************************************************************************
* DESCRIPTION: Return true if a framing or overrun error is present
* RETURN:      true if error
* ALGORITHM:   none
* NOTES:       Clears any error flags.
*****************************************************************************/
bool RS485_ReceiveError(
    void)
{
    bool ReceiveError = false;
    /* LED on send */
    volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;

    /* check for data or error */
    if (RS485_Interface->US_CSR & (AT91C_US_OVRE | AT91C_US_FRAME)) {
        /* clear the error flag */
        RS485_Interface->US_CR = AT91C_US_RSTSTA;
        ReceiveError = true;
        /* LED ON */
        pPIO->PIO_CODR = LED2;
    }

    return ReceiveError;
}

/****************************************************************************
* DESCRIPTION: Return true if data is available 
* RETURN:      true if data is available, with the data in the parameter set
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
bool RS485_DataAvailable(
    uint8_t * DataRegister)
{
    bool DataAvailable = false;
    /* LED on send */
    volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;

    if (RS485_Interface->US_CSR & AT91C_US_RXRDY) {
        /* data is available */
        *DataRegister = RS485_Interface->US_RHR;
        DataAvailable = true;
        /* LED ON */
        pPIO->PIO_CODR = LED2;
    }

    return DataAvailable;
}

#ifdef TEST_RS485
int main(
    void)
{
    unsigned i = 0;
    uint8_t DataRegister;

    RS485_Set_Baud_Rate(38400);
    RS485_Initialize();
    /* receive task */
    for (;;) {
        if (RS485_ReceiveError()) {
            fprintf(stderr, "ERROR ");
        } else if (RS485_DataAvailable(&DataRegister)) {
            fprintf(stderr, "%02X ", DataRegister);
        }
    }
}
#endif

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧洲一区二区三区在线| 国产精品伊人色| 日韩免费电影网站| 久久9热精品视频| 日韩欧美123| 国产精品一区二区无线| ww亚洲ww在线观看国产| 国产自产高清不卡| 国产精品视频一二三区| 色综合天天在线| 99国产精品久久| 一区二区免费在线播放| 色婷婷综合久久久中文字幕| 一区二区三国产精华液| 欧美精品欧美精品系列| 国产一区二区三区国产| 一区二区三区不卡视频在线观看| 欧美伦理影视网| 精品无人码麻豆乱码1区2区| 国产精品午夜在线观看| 91免费看片在线观看| 奇米精品一区二区三区四区| 久久精品视频一区二区| 色综合中文综合网| 欧美tk丨vk视频| 91福利在线免费观看| 国产激情一区二区三区四区| 一区二区三区四区av| 2021国产精品久久精品| 欧美日韩午夜在线视频| 99久久婷婷国产综合精品| 99精品久久久久久| 国产 日韩 欧美大片| 婷婷激情综合网| 亚洲自拍偷拍av| 欧美国产日产图区| 欧美经典一区二区| 久久精品网站免费观看| 精品国产制服丝袜高跟| 日韩美女在线视频| 日韩丝袜情趣美女图片| 日韩一二三四区| 欧美酷刑日本凌虐凌虐| 欧美午夜寂寞影院| 欧美日韩一区久久| 日韩精品一区二| 欧美videossexotv100| 亚洲精品在线观| 久久日一线二线三线suv| 日韩一本二本av| 欧美精品一区二区三区蜜桃视频| 91精品国产综合久久小美女| 日韩欧美国产电影| 欧美极品另类videosde| 亚洲欧美日韩在线不卡| 亚洲国产精品欧美一二99| 日韩激情一区二区| 久久97超碰国产精品超碰| 国产成人午夜精品5599| 色先锋aa成人| 欧美大片一区二区| 亚洲天天做日日做天天谢日日欢| 亚洲一卡二卡三卡四卡无卡久久| 日韩精品高清不卡| 国产乱码一区二区三区| 91色九色蝌蚪| 亚洲人成人一区二区在线观看| 亚洲图片一区二区| 成人激情动漫在线观看| 欧美写真视频网站| 国产精品美日韩| 亚洲sss视频在线视频| 国产jizzjizz一区二区| 色8久久人人97超碰香蕉987| 日韩精品在线看片z| 亚洲欧美在线高清| 精品一区二区三区的国产在线播放| 99久久免费国产| 日韩亚洲欧美成人一区| 亚洲激情成人在线| 国产成+人+日韩+欧美+亚洲| 欧美理论电影在线| 亚洲影视在线播放| 在线观看欧美日本| 亚洲精品久久久久久国产精华液| 国产精一区二区三区| 91精品国产色综合久久不卡电影| 亚洲最新视频在线播放| 色欧美片视频在线观看在线视频| 国产精品嫩草影院av蜜臀| 日韩精品午夜视频| 日韩一区二区电影| 日韩电影在线一区| 欧美久久久一区| 日韩专区在线视频| 91精品国产高清一区二区三区蜜臀| 亚洲综合丝袜美腿| 欧美区一区二区三区| 欧美日韩在线直播| 国产精品久久久久久久蜜臀| 一本久道久久综合中文字幕| 久热成人在线视频| 亚洲综合在线视频| 欧美一区二区二区| 精品制服美女丁香| 欧美激情在线观看视频免费| 成人激情黄色小说| 亚洲女爱视频在线| 欧美日韩国产系列| 久久国产精品露脸对白| 欧美激情在线免费观看| 91亚洲精品一区二区乱码| 夜夜爽夜夜爽精品视频| 欧美一区二区成人| 成人爽a毛片一区二区免费| 亚洲小说春色综合另类电影| 日韩一级高清毛片| 91久久精品一区二区三区| 久久av资源站| 日本午夜精品视频在线观看 | 国产精品久久三| 91精品综合久久久久久| 色综合久久综合网| 国产成人午夜电影网| 青青国产91久久久久久| 亚洲丝袜另类动漫二区| 欧美精品一区在线观看| 欧美一区二区三区四区高清| 欧洲av一区二区嗯嗯嗯啊| hitomi一区二区三区精品| 免费在线观看成人| 久久久久久久电影| 精品成a人在线观看| 精品av综合导航| 国产精品福利一区二区| 亚洲欧美偷拍三级| 偷偷要91色婷婷| 国内久久精品视频| 99视频精品免费视频| www.欧美日韩| 97久久超碰国产精品| 99精品欧美一区二区三区综合在线| 狠狠色丁香婷婷综合久久片| 久久97超碰色| 成人免费的视频| 成人免费看的视频| 91论坛在线播放| 欧美久久高跟鞋激| 久久亚洲二区三区| 国产精品素人一区二区| 亚洲美腿欧美偷拍| 日本怡春院一区二区| 国产露脸91国语对白| 色综合色狠狠综合色| 欧美女孩性生活视频| 久久嫩草精品久久久精品| 亚洲色图一区二区三区| 亚洲精品乱码久久久久久日本蜜臀| 亚洲成人手机在线| 狠狠色丁香九九婷婷综合五月| 成人一级片在线观看| 欧美亚洲国产一区在线观看网站| 日韩欧美国产系列| 自拍视频在线观看一区二区| 亚洲国产一区二区三区青草影视| 美腿丝袜亚洲一区| 91免费国产在线观看| 欧美mv日韩mv国产| 亚洲123区在线观看| 成人理论电影网| 精品入口麻豆88视频| 亚洲午夜精品17c| 91污片在线观看| 中文字幕成人av| 美腿丝袜在线亚洲一区| 欧美三级日韩在线| 亚洲免费毛片网站| 成人精品一区二区三区四区 | 在线国产电影不卡| 国产精品色哟哟网站| 国产一区二区精品久久99| 欧美剧情片在线观看| 亚洲地区一二三色| 欧美日韩精品一区视频| 亚洲一区视频在线观看视频| 91视频免费看| 一区二区三区在线视频观看58| 成人一区二区三区视频在线观看| 精品成a人在线观看| 激情av综合网| 国产精品无遮挡| 成人免费毛片嘿嘿连载视频| 国产精品亲子伦对白| 成人在线视频首页| 自拍偷拍国产亚洲| 欧美日韩精品欧美日韩精品| 日韩国产欧美一区二区三区| 在线成人高清不卡| 国产成人夜色高潮福利影视| 国产精品久久毛片a|