void UART0_initTxPolling()
{
  DECL_PAGE;
  SET_PAGE(0x00);
  SCON0_TI = 1;
  RESTORE_PAGE;
}
void UART0_write(uint8_t value)
{
  DECL_PAGE;
  SET_PAGE(0x00);
  SBUF0 = value;
  RESTORE_PAGE;
}
void UART0_initStdio()
{
  DECL_PAGE;
  SET_PAGE(0x00);
  SCON0 |= SCON0_REN__RECEIVE_ENABLED | SCON0_TI__SET;
  RESTORE_PAGE;
}
void UART0_clearIntFlag(uint8_t flag)
{
  DECL_PAGE;
  SET_PAGE(0x00);
  SCON0 &= ~(flag);
  RESTORE_PAGE;
}
void UART0_writeWithExtraBit(uint16_t value)
{
  DECL_PAGE;
  SET_PAGE(0x00);
  SCON0_TB8 = value >> 8;
  SBUF0 = value;
  RESTORE_PAGE;
}
uint16_t UART0_readWithExtraBit(void)
{
  uint16_t val;
  DECL_PAGE;
  SET_PAGE(0x00);
  val = (SBUF0 | ((SCON0 & SCON0_RB8__BMASK) << 6) );
  RESTORE_PAGE;
  return val;
}
uint8_t UART0_read(void)
{
  uint8_t val;
  DECL_PAGE;
  SET_PAGE(0x00);
  val = SBUF0;
  RESTORE_PAGE;
  return val;
}
uint8_t UART0_getIntFlags()
{
  uint8_t val;
  DECL_PAGE;
  SET_PAGE(0x00);
  val = SCON0 & (UART0_TX_IF | UART0_RX_IF);
  RESTORE_PAGE;
  return val;
}
char putchar(char c){
  DECL_PAGE;
  SET_PAGE(0x00);
  while(!SCON0_TI);
  SBUF0 = c;
  SCON0_TI = 0;
  RESTORE_PAGE;
  return c;
}
Exemplo n.º 10
0
void UART0_init(UART0_RxEnable_t rxen, UART0_Width_t width, UART0_Multiproc_t mce)
{
  DECL_PAGE;
  SET_PAGE(0x00);
  SCON0 &= ~(SCON0_SMODE__BMASK
             | SCON0_MCE__BMASK
             | SCON0_REN__BMASK);
  SCON0 = mce | rxen | width;
  RESTORE_PAGE;
}
Exemplo n.º 11
0
char _getkey(){
  char val;
  DECL_PAGE;
  SET_PAGE(0x00);
  while(!SCON0_RI);
  SCON0_RI = 0;

  val = SBUF0;
  RESTORE_PAGE;
  return val;
}
Exemplo n.º 12
0
void UART0_reset()
{
  DECL_PAGE;
  SET_PAGE(0x00);
  SCON0 = SCON0_SMODE__8_BIT
          | SCON0_MCE__MULTI_DISABLED
          | SCON0_REN__RECEIVE_DISABLED
          | SCON0_TB8__NOT_SET
          | SCON0_RB8__NOT_SET
          | SCON0_TI__NOT_SET
          | SCON0_RI__NOT_SET;
  RESTORE_PAGE;
}
Exemplo n.º 13
0
void UART0_writeBuffer(SI_VARIABLE_SEGMENT_POINTER(buffer,
                                                uint8_t,
                                                EFM8PDL_UART0_TX_BUFTYPE),
                       uint8_t length)
{
  DECL_PAGE;
  SET_PAGE(0x00);
  //Init internal data
  txBuffer = buffer+1;
  txRemaining = length-1;

  //Send initial byte
  SBUF0 = *buffer;
  RESTORE_PAGE;
}
Exemplo n.º 14
0
// Save captured track
uint8_t sdc_save_track(void)
{
    FRESULT res;
    BYTE page, i, r = SDCS_OK;
    UINT bw, tbw;
    long bytesleft, trklen_old, addr;


    // fill header struct
    FDR_HDR.sig[0] = 'F';
    FDR_HDR.sig[1] = 'D';
    FDR_HDR.sig[2] = 'R';
    FDR_HDR.sig[3] = '0';
    FDR_HDR.smprate = smp_rates[FDR_INFO.smprate];
    FDR_HDR.track = FDR_INFO.track;
    FDR_HDR.side = FDR_INFO.side;
    FDR_HDR.revs = FDR_INFO.revs;

    // fill trklens
    // hack: DMA puts data by words but lengths are snapshoted in bytes.
    // we have to correct total length to an even value.
    if(FDR_INFO.trklen[FDR_INFO.revs-1] == FDR_INFO.trklen[FDR_INFO.revs])
    {
        // no data in tail - correct also last rev length
        FDR_INFO.trklen[FDR_INFO.revs-1] &= ~1;
    }
    FDR_INFO.trklen[FDR_INFO.revs] &= ~1;

    trklen_old = 0;
    for(i=0; i<=FDR_INFO.revs; i++) //revs+1 for tail
    {
        addr = FDR_INFO.trklen[i];
        // hack: if the whole buffer was filled with the data,
        // trimmed to 0x00000 address was returned, so fix it.
        if(addr==0) addr=0x80000;
        trklen[i] = addr - trklen_old;
        trklen_old = addr;
    }
    bytesleft = FDR_INFO.trklen[FDR_INFO.revs];
    // hack: if the whole buffer was filled with the data,
    // trimmed to 0x00000 address was returned, so fix it.
    if(bytesleft==0) bytesleft=0x80000;

    // open file
    if (!FDR_INFO.single_file)
    {
        res=open_file();
        if (res==FR_EXIST)
            return SDCS_EXIST;
        else if (res!=FR_OK)
            return SDCS_OPEN_ERR;
    }

    // write header
    res=f_write(&fd, &FDR_HDR, sizeof(FDR_HDR), &bw);
    if (res!=FR_OK)
    {
        r = SDCS_WRITE_ERR;
        goto exit;
    }
    res=f_write(&fd, trklen, sizeof(trklen[0])*(FDR_INFO.revs+1), &bw);
    if (res!=FR_OK)
    {
        r = SDCS_WRITE_ERR;
        goto exit;
    }

    // save data
    page=DATA_START_PAGE;
    while(bytesleft)
    {
        if (bytesleft > PAGE_SIZE)
            tbw = PAGE_SIZE;
        else
            tbw = bytesleft;

        SET_PAGE(page);
        res=f_write(&fd, PAGE_START, tbw, &bw);
        if (res!=FR_OK || bw!=tbw)
        {
            r = SDCS_WRITE_ERR;
            break;
        }

        // exit at break
        if(is_break_pressed())
        {
            r = SDCS_BREAK;
            break;
        }

        page++;
        bytesleft -= tbw;
        fdd_keep_alive(); // keep motor on
    }

exit:
    // close file
    if (!FDR_INFO.single_file)
        f_close(&fd);

    // restore default page
    SET_PAGE(PAGE_DEFAULT);
    return r;
}